@@ -12,6 +12,9 @@ const pixelsPerMillimeter = 96 / 25.4;
1212
1313const inputCompileDelay = 1000 ;
1414
15+ // All the features supported in the 'features' config key.
16+ const allFeatures = [ 'zoom' , 'pan' ] ;
17+
1518// Encapsulate a single simulator HTML node. Handles starting/stopping the
1619// worker, refresh the schematic as needed, etc.
1720class Simulator {
@@ -22,6 +25,7 @@ class Simulator {
2225 this . firmwareButton = config . firmwareButton ;
2326 this . baseURL = config . baseURL || document . baseURI ;
2427 this . apiURL = config . apiURL ;
28+ this . features = new Set ( config . features || allFeatures ) ;
2529 this . schematicURL = config . schematicURL || new URL ( './worker/webworker.js' , this . baseURL ) ;
2630 this . runnerURL = config . runnerURL || new URL ( './worker/runner.js' , this . baseURL ) ;
2731 this . saveState = config . saveState || ( ( ) => { } ) ;
@@ -179,41 +183,45 @@ class Simulator {
179183 } ) ;
180184 } ) ;
181185
182- // Zoom using the scroll wheel.
183- // Disable the default wheel event: this would result in a bounce effect on
184- // Safari and make the scrolling a lot less smooth.
185- // TODO: pinch to zoom? (e.g. with a trackpad)
186- this . schematicElement . addEventListener ( 'wheel' , e => {
187- e . preventDefault ( ) ;
188- let [ positionX , positionY ] = this . schematic . cursorPosition ( e ) ;
189- let factor = 1 + ( e . deltaY * - 0.0005 ) ;
190- this . schematic . zoom ( factor , positionX , positionY ) ;
191- } , { passive : false } ) ;
192-
193- // Pan using the secondary (usually right) mouse button.
194- this . schematicElement . addEventListener ( 'contextmenu' , e => {
195- // The default action is a context menu, which we don't want.
196- // Firefox allows overriding this using shift (which is good, we don't
197- // want to prevent the context menu entirely) while Chromium doesn't.
198- e . preventDefault ( ) ;
199- } )
200- this . schematicElement . addEventListener ( 'mousedown' , e => {
201- if ( e . buttons === 2 ) {
202- // Secondary button pressed (only). Start panning (dragging).
203- let [ cursorX , cursorY ] = this . schematic . cursorPosition ( e ) ;
204- schematicPan = {
205- schematic : this . schematic ,
206- initialCursorX : cursorX ,
207- initialCursorY : cursorY ,
208- initialTranslateX : this . schematic . translateX ,
209- initialTranslateY : this . schematic . translateY ,
210- } ;
211- }
212- } )
213- this . schematicElement . addEventListener ( 'mouseup' , e => {
214- // Stop panning the schematic (no matter which way it ended).
215- schematicPan = null ;
216- } )
186+ if ( this . features . has ( 'zoom' ) ) {
187+ // Zoom using the scroll wheel.
188+ // Disable the default wheel event: this would result in a bounce effect
189+ // on Safari and make the scrolling a lot less smooth.
190+ // TODO: pinch to zoom? (e.g. with a trackpad)
191+ this . schematicElement . addEventListener ( 'wheel' , e => {
192+ e . preventDefault ( ) ;
193+ let [ positionX , positionY ] = this . schematic . cursorPosition ( e ) ;
194+ let factor = 1 + ( e . deltaY * - 0.0005 ) ;
195+ this . schematic . zoom ( factor , positionX , positionY ) ;
196+ } , { passive : false } ) ;
197+ }
198+
199+ if ( this . features . has ( 'pan' ) ) {
200+ // Pan using the secondary (usually right) mouse button.
201+ this . schematicElement . addEventListener ( 'contextmenu' , e => {
202+ // The default action is a context menu, which we don't want.
203+ // Firefox allows overriding this using shift (which is good, we don't
204+ // want to prevent the context menu entirely) while Chromium doesn't.
205+ e . preventDefault ( ) ;
206+ } )
207+ this . schematicElement . addEventListener ( 'mousedown' , e => {
208+ if ( e . buttons === 2 ) {
209+ // Secondary button pressed (only). Start panning (dragging).
210+ let [ cursorX , cursorY ] = this . schematic . cursorPosition ( e ) ;
211+ schematicPan = {
212+ schematic : this . schematic ,
213+ initialCursorX : cursorX ,
214+ initialCursorY : cursorY ,
215+ initialTranslateX : this . schematic . translateX ,
216+ initialTranslateY : this . schematic . translateY ,
217+ } ;
218+ }
219+ } )
220+ this . schematicElement . addEventListener ( 'mouseup' , e => {
221+ // Stop panning the schematic (no matter which way it ended).
222+ schematicPan = null ;
223+ } )
224+ }
217225
218226 // Listen for keyboard events, to simulate button presses.
219227 this . schematicElement . addEventListener ( 'keydown' , e => {
0 commit comments