markdown-up 1.7.2 → 1.7.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/app.js CHANGED
@@ -21,13 +21,11 @@ import {validateType} from 'schema-markdown/lib/schema.js';
21
21
  // The application's hash parameter type model
22
22
  const markdownUpTypesSmd = `\
23
23
  #
24
- # **markdown-up** is a Markdown viewer application. Click the following link to learn more.
25
- #
26
- # [markdown-up](https://github.com/craigahobbs/markdown-up#readme)
24
+ # [MarkdownUp](https://craigahobbs.github.io/markdown-up/) is a Markdown viewer application.
27
25
  #
28
26
  # ## Hash Parameters
29
27
  #
30
- # The markdown-up application recognizes the following hash parameters:
28
+ # MarkdownUp recognizes the following hash parameters:
31
29
  #
32
30
  struct MarkdownUp
33
31
 
@@ -37,7 +35,7 @@ struct MarkdownUp
37
35
  # Optional command
38
36
  optional Command cmd
39
37
 
40
- # The menu visibility (default is hidden)
38
+ # The menu visibility (default is collapsed)
41
39
  optional int(== 1) menu
42
40
 
43
41
  # The font size
@@ -53,20 +51,20 @@ struct MarkdownUp
53
51
  optional int(== 1) debug
54
52
 
55
53
 
56
- # Application command union
54
+ # A MarkdownUp application command
57
55
  union Command
58
56
 
59
- # Display the application's hash parameter documentation
57
+ # Display the hash parameters documentation
60
58
  int(== 1) help
61
59
 
62
- # Show the URL's Markdown text
60
+ # Show the resource's Markdown text
63
61
  int(== 1) markdown
64
62
  `;
65
63
  const markdownUpTypes = new SchemaMarkdownParser(markdownUpTypesSmd).types;
66
64
 
67
65
 
68
66
  /**
69
- * A markdown-up application options object
67
+ * The MarkdownUp application options
70
68
  *
71
69
  * @typedef {Object} MarkdownUpOptions
72
70
  * @param {number} [fontSize = 12] - The font size, in points
@@ -87,14 +85,14 @@ const markdownUpTypes = new SchemaMarkdownParser(markdownUpTypesSmd).types;
87
85
  * @property {string} markdownText - The markdown text
88
86
  * @property {boolean} menu - If true, show the menu
89
87
  * @property {string} url - The resource URL
90
- * @property {?number} setNavigateTimeoutId - The navigate timeout ID
88
+ * @property {?number} runtimeTimeoutId - The runtime-set timeout ID
91
89
  */
92
90
  export class MarkdownUp {
93
91
  /**
94
92
  * Create an application instance
95
93
  *
96
94
  * @param {Object} window - The web browser window object
97
- * @property {module:lib/app~MarkdownUpOptions} [options] - The markdown-up application options
95
+ * @property {Object} [options] - The [application options]{@link module:lib/app~MarkdownUpOptions}
98
96
  */
99
97
  constructor(window, {fontSize = 12, lineHeight = 1.2, markdownText = null, menu = true, url = 'README.md'} = {}) {
100
98
  this.window = window;
@@ -104,9 +102,11 @@ export class MarkdownUp {
104
102
  this.markdownText = markdownText;
105
103
  this.menu = menu;
106
104
  this.url = url;
107
- this.setNavigateTimeoutId = null;
105
+ this.runtimeWindowResize = null;
106
+ this.runtimeTimeoutId = null;
108
107
  }
109
108
 
109
+
110
110
  /**
111
111
  * Run the application. This method calls render and subscribes to any hash parameter changes to
112
112
  * re-render on any hash parameter change.
@@ -116,14 +116,21 @@ export class MarkdownUp {
116
116
  this.window.addEventListener('hashchange', () => this.render(), false);
117
117
  }
118
118
 
119
+
119
120
  /**
120
- * ElementApplication.render override to clear the navigate timeout
121
+ * Render the application
121
122
  */
122
123
  async render() {
123
- // Clear the navigate timeout ID, if one is set
124
- if (this.setNavigateTimeoutId !== null) {
125
- this.window.clearTimeout(this.setNavigateTimeoutId);
126
- this.setNavigateTimeoutId = null;
124
+ // Clear the runtime timeout ID, if one is set
125
+ if (this.runtimeTimeoutId !== null) {
126
+ this.window.clearTimeout(this.runtimeTimeoutId);
127
+ this.runtimeTimeoutId = null;
128
+ }
129
+
130
+ // Clear the window resize event handler
131
+ if (this.runtimeWindowResize !== null) {
132
+ this.window.removeEventListener('resize', this.runtimeWindowResize);
133
+ this.runtimeWindowResize = null;
127
134
  }
128
135
 
129
136
  // Parse the hash parameters and render the application element model
@@ -146,18 +153,23 @@ export class MarkdownUp {
146
153
  isError = true;
147
154
  }
148
155
 
149
- // Navigate?
150
- if ('location' in result && result.location !== null) {
151
- this.window.location.href = result.location;
152
- return;
153
- }
154
-
155
156
  // Set the window title
156
157
  const title = result.title ?? null;
157
158
  if (title !== null) {
158
159
  this.window.document.title = title;
159
160
  }
160
161
 
162
+ // Timeout?
163
+ if ('timeout' in result) {
164
+ this.runtimeTimeoutId = this.window.setTimeout(...result.timeout);
165
+ }
166
+
167
+ // Window resize event handler?
168
+ if ('resize' in result) {
169
+ this.runtimeWindowResize = result.resize;
170
+ this.window.addEventListener('resize', result.resize);
171
+ }
172
+
161
173
  // Set the font size
162
174
  const fontSize = this.params !== null && 'fontSize' in this.params ? this.params.fontSize : this.fontSize;
163
175
  this.window.document.documentElement.style.setProperty('--markdown-model-font-size', `${fontSize}pt`);
@@ -169,6 +181,25 @@ export class MarkdownUp {
169
181
  // Render the element model
170
182
  renderElements(this.window.document.body, result.elements);
171
183
 
184
+ // Focus?
185
+ if ('focus' in result) {
186
+ const element = this.window.document.getElementById(result.focus);
187
+ if (element !== null) {
188
+ element.focus();
189
+ if ('selectionStart' in element) {
190
+ element.selectionStart = element.value.length;
191
+ element.selectionEnd = element.value.length;
192
+ }
193
+ }
194
+ }
195
+
196
+ // Navigate?
197
+ // Note: This is done after render since it may have no effect (in which case we want to render).
198
+ if ('location' in result && result.location !== null) {
199
+ this.window.location.href = result.location;
200
+ return;
201
+ }
202
+
172
203
  // If there is a URL hash ID, re-navigate to go there since it was just rendered. After the
173
204
  // first render, re-render is short-circuited by the unchanged hash param check above.
174
205
  if (!isError && getHashID(this.window.location.hash) !== null) {
@@ -176,6 +207,7 @@ export class MarkdownUp {
176
207
  }
177
208
  }
178
209
 
210
+
179
211
  /**
180
212
  * Parse and validate the hash parameters
181
213
  *
@@ -192,139 +224,127 @@ export class MarkdownUp {
192
224
  this.params = validateType(markdownUpTypes, 'MarkdownUp', params);
193
225
  }
194
226
 
227
+
195
228
  /**
196
- * The [Element Application main entry point]{@link
197
- * https://craigahobbs.github.io/element-app/module-lib_app.ElementApplication.html#main}.
229
+ * The application's main entry point
198
230
  *
199
- * @override
200
- * @returns {Object} [MainResult]{@link https://craigahobbs.github.io/element-app/module-lib_app.html#~MainResult}
231
+ * @returns {Object}
201
232
  */
202
233
  async main() {
203
- // Load the text resource
234
+ // Help?
235
+ if ('cmd' in this.params && 'help' in this.params.cmd) {
236
+ return {
237
+ 'title': 'MarkdownUp',
238
+ 'elements': [
239
+ schemaMarkdownDoc(markdownUpTypes, 'MarkdownUp', {'params': encodeQueryString(this.params)}),
240
+ this.burgerElements()
241
+ ]
242
+ };
243
+ }
244
+
245
+ // Get the Markdown text
204
246
  const urlOverride = 'url' in this.params && this.params.url !== '';
205
247
  const url = urlOverride ? this.params.url : this.url;
206
248
  let markdownText = null;
207
- let markdownModel = null;
208
- let markdownTitle = null;
209
- if (!('cmd' in this.params) || 'markdown' in this.params.cmd) {
210
- if (this.markdownText !== null && !urlOverride) {
211
- ({markdownText} = this);
212
- } else {
213
- const response = await this.window.fetch(url);
214
- if (!response.ok) {
215
- const status = response.statusText;
216
- throw new Error(`Could not fetch "${url}"${status === '' ? '' : `, ${JSON.stringify(status)}`}`);
217
- }
218
- markdownText = await response.text();
249
+ if (this.markdownText !== null && !urlOverride) {
250
+ ({markdownText} = this);
251
+ } else {
252
+ // Fetch the Markdown text resource URL
253
+ const response = await this.window.fetch(url);
254
+ if (!response.ok) {
255
+ const status = response.statusText;
256
+ return {
257
+ 'title': 'MarkdownUp',
258
+ 'elements': {
259
+ 'html': 'p',
260
+ 'elem': {'text': `Error: Could not fetch "${url}"${status === '' ? '' : ` - ${JSON.stringify(status)}`}`}
261
+ }
262
+ };
219
263
  }
220
- markdownModel = parseMarkdown(markdownText);
221
- markdownTitle = getMarkdownTitle(markdownModel);
264
+ markdownText = await response.text();
222
265
  }
223
266
 
224
- // Command?
225
- let cmdElements = null;
226
- if ('cmd' in this.params) {
227
- // Display markdown?
228
- if ('markdown' in this.params.cmd) {
229
- cmdElements = {'html': 'div', 'attr': {'class': 'markdown'}, 'elem': {'text': markdownText}};
230
-
231
- // Help
232
- } else {
233
- cmdElements = schemaMarkdownDoc(markdownUpTypes, 'MarkdownUp', {'params': encodeQueryString(this.params)});
234
- }
267
+ // Parse the Markdown and get the title
268
+ const markdownModel = parseMarkdown(markdownText);
269
+ const markdownTitle = getMarkdownTitle(markdownModel);
270
+
271
+ // Display the Markdown?
272
+ if ('cmd' in this.params && 'markdown' in this.params.cmd) {
273
+ return {
274
+ 'title': markdownTitle,
275
+ 'elements': [
276
+ {'html': 'div', 'attr': {'class': 'markdown'}, 'elem': {'text': markdownText}},
277
+ this.burgerElements()
278
+ ]
279
+ };
235
280
  }
236
281
 
237
- // Helper function to create a cycle link
238
- const linkCycle = (paramName, defaultValue, delta, fixed = null) => {
239
- const value = paramName in this.params ? this.params[paramName] : defaultValue;
240
- const {attr} = markdownUpTypes.MarkdownUp.struct.members.find((member) => member.name === paramName);
241
- let valueNew = value + delta;
242
- if (valueNew > attr.lte) {
243
- valueNew = attr.gte;
244
- }
245
- valueNew = Math.max(attr.gte, Math.min(attr.lte, valueNew));
246
- const params = {...this.params};
247
- params[paramName] = fixed === null ? `${valueNew}` : `${valueNew.toFixed(fixed)}`;
248
- return `#${encodeQueryString(params)}`;
249
- };
282
+ // Render the Markdown
283
+ const scriptOptions = this.createScriptOptions(url);
284
+ const result = {
285
+ 'title': markdownTitle,
286
+ 'elements': [
287
+ // Add a top hash ID, if necessary
288
+ Object.keys(this.params).length === 0
289
+ ? null : {'html': 'div', 'attr': {'id': encodeQueryString(this.params), 'style': 'display=none'}},
250
290
 
251
- // Helper function to create a toggle link
252
- const linkCommandToggle = (command, value) => {
253
- const params = {...this.params};
254
- if ('cmd' in this.params && command in this.params.cmd) {
255
- delete params.cmd;
256
- } else {
257
- params.cmd = {};
258
- params.cmd[command] = `${value}`;
259
- }
260
- return `#${encodeQueryString(params)}`;
261
- };
291
+ // Render the markdown
292
+ await markdownElementsAsync(markdownModel, {
293
+ 'codeBlocks': {
294
+ 'bar-chart': (codeBlock) => barChartCodeBlock(codeBlock, scriptOptions),
295
+ 'data-table': (codeBlock) => dataTableCodeBlock(codeBlock, scriptOptions),
296
+ 'line-chart': (codeBlock) => lineChartCodeBlock(codeBlock, scriptOptions),
297
+ 'markdown-script': (codeBlock) => markdownScriptCodeBlock(codeBlock, scriptOptions)
298
+ },
299
+ 'urlFn': (urlRaw) => this.modifyURL(urlRaw, url),
300
+ 'headerIds': true
301
+ }),
262
302
 
263
- // Helper function to create a value-toggle link
264
- const linkValueToggle = (name, value) => {
265
- const params = {...this.params};
266
- if (!(name in this.params)) {
267
- params[name] = value;
268
- } else {
269
- delete params[name];
270
- }
271
- return `#${encodeQueryString(params)}`;
303
+ // Popup menu burger
304
+ this.burgerElements()
305
+ ]
272
306
  };
273
307
 
274
- // The URL modifier function
275
- const urlFn = (rawURL) => {
276
- // Hash URL?
277
- if (rawURL.startsWith('#')) {
278
- // Fixup the "url" param if its relative
279
- const hashParams = decodeQueryString(rawURL.slice(1));
280
- if ('url' in hashParams && hashParams.url !== '' && isRelativeURL(hashParams.url)) {
281
- hashParams.url = `${getBaseURL(url)}${hashParams.url}`;
282
- }
308
+ // Set any runtime side-effects
309
+ if (scriptOptions.runtime.windowLocation !== null) {
310
+ result.location = scriptOptions.runtime.windowLocation;
311
+ }
312
+ if (scriptOptions.runtime.documentFocus !== null) {
313
+ result.focus = scriptOptions.runtime.documentFocus;
314
+ }
315
+ if (scriptOptions.runtime.documentTitle !== null) {
316
+ result.title = scriptOptions.runtime.documentTitle;
317
+ }
318
+ if (scriptOptions.runtime.windowTimeout !== null) {
319
+ result.timeout = scriptOptions.runtime.windowTimeout;
320
+ }
321
+ if (scriptOptions.runtime.windowResize !== null) {
322
+ result.resize = scriptOptions.runtime.windowResize;
323
+ }
283
324
 
284
- // Return the combined hash URL
285
- return encodeHashID({...this.params, ...hashParams}, getHashID(rawURL));
286
- }
325
+ return result;
326
+ }
287
327
 
288
- // Relative URL?
289
- if (isRelativeURL(rawURL)) {
290
- return `${getBaseURL(url)}${rawURL}`;
291
- }
292
328
 
293
- return rawURL;
329
+ createScriptOptions(resourceURL) {
330
+ // Create the script options object
331
+ const scriptOptions = {
332
+ // eslint-disable-next-line require-await
333
+ 'fetchFn': async (fetchURL, init) => this.window.fetch(fetchURL, init),
334
+ 'fontSize': this.params !== null && 'fontSize' in this.params ? this.params.fontSize : this.fontSize,
335
+ 'params': this.params,
336
+ 'urlFn': (url) => this.modifyURL(url, resourceURL),
337
+ 'window': this.window
294
338
  };
295
339
 
296
- // The log function
297
- const logFn = (text) => {
298
- if ('debug' in this.params) {
340
+ // Add log function, if debugging
341
+ if ('debug' in this.params) {
342
+ scriptOptions.logFn = (text) => {
299
343
  this.window.console.log(text);
300
- }
301
- };
302
-
303
- // The fetch function
304
- // eslint-disable-next-line require-await
305
- const fetchFn = async (fetchURL, init) => this.window.fetch(urlFn(fetchURL), init);
306
-
307
- // The navigate timeout function
308
- const navigateTimeoutFn = (navigateURL, delay) => {
309
- const timeoutCallback = () => {
310
- this.window.location.href = urlFn(navigateURL);
311
344
  };
312
- this.setNavigateTimeoutId = this.window.setTimeout(timeoutCallback, delay);
313
- };
314
- // eslint-disable-next-line lines-around-comment
345
+ }
315
346
 
316
- // Render the text as Markdown
317
- const fontSize = 0.9 * (this.params !== null && 'fontSize' in this.params ? this.params.fontSize : this.fontSize);
318
- const scriptOptions = {
319
- fetchFn,
320
- fontSize,
321
- 'localStorage': this.window.localStorage,
322
- logFn,
323
- navigateTimeoutFn,
324
- 'params': this.params,
325
- 'sessionStorage': this.window.sessionStorage,
326
- urlFn
327
- };
347
+ // Add hash parameter variables, if any
328
348
  if ('var' in this.params) {
329
349
  scriptOptions.variables = {};
330
350
  for (const varName of Object.keys(this.params.var)) {
@@ -332,84 +352,171 @@ export class MarkdownUp {
332
352
  scriptOptions.variables[varName] = evaluateExpression(varExpr, scriptOptions.variables);
333
353
  }
334
354
  }
335
- scriptOptions.runtime = new MarkdownScriptRuntime(scriptOptions);
336
- const result = {
337
- 'title': markdownTitle,
338
- 'elements': [
339
- // Command?
340
- cmdElements !== null ? cmdElements : null,
341
355
 
342
- // Add a top hash ID, if necessary
343
- cmdElements !== null || Object.keys(this.params).length === 0
344
- ? null : {'html': 'div', 'attr': {'id': encodeQueryString(this.params), 'style': 'display=none'}},
356
+ // Create the markdown-script runtime
357
+ const runtime = new MarkdownScriptRuntime(scriptOptions);
358
+ scriptOptions.runtime = runtime;
359
+ scriptOptions.runtimeUpdateFn = () => {
360
+ // Did script set the document title?
361
+ if (runtime.documentTitle !== null) {
362
+ this.window.document.title = runtime.documentTitle;
363
+ }
345
364
 
346
- // Render the markdown
347
- cmdElements !== null ? null : await markdownElementsAsync(markdownModel, {
348
- 'codeBlocks': {
349
- 'bar-chart': (language, lines) => barChartCodeBlock(language, lines, scriptOptions),
350
- 'data-table': (language, lines) => dataTableCodeBlock(language, lines, scriptOptions),
351
- 'line-chart': (language, lines) => lineChartCodeBlock(language, lines, scriptOptions),
352
- 'markdown-script': (language, lines) => markdownScriptCodeBlock(language, lines, scriptOptions)
353
- },
354
- urlFn,
355
- 'headerIds': true
356
- }),
365
+ // Did the script set a timeout?
366
+ if (runtime.windowTimeout !== null) {
367
+ if (this.runtimeTimeoutId !== null) {
368
+ this.window.clearTimeout(this.runtimeTimeoutId);
369
+ }
370
+ this.runtimeTimeoutId = this.window.setTimeout(...runtime.windowTimeout);
371
+ }
357
372
 
358
- // Popup menu burger
359
- !this.menu ? null : {
360
- 'html': 'div',
361
- 'attr': {'class': 'menu-burger'},
362
- 'elem': [
363
- {
364
- 'html': 'a',
365
- 'attr': {'href': linkValueToggle('menu', '1'), 'aria-label': 'Menu'},
366
- 'elem': menuSVGElements
367
- }
368
- ]
369
- },
370
-
371
- // Popup menu
372
- !this.menu || !('menu' in this.params) ? null : {
373
- 'html': 'div',
374
- 'attr': {'class': 'menu'},
375
- 'elem': [
376
- {
377
- 'html': 'a',
378
- 'attr': {'href': linkCommandToggle('markdown', '1'), 'aria-label': 'Show Markdown'},
379
- 'elem': markdownSVGElements
380
- },
381
- {
382
- 'html': 'a',
383
- 'attr': {'href': linkCycle('fontSize', this.fontSize, 2), 'aria-label': 'Font size'},
384
- 'elem': fontSizeSVGElements
385
- },
386
- {
387
- 'html': 'a',
388
- 'attr': {'href': linkCycle('lineHeight', this.lineHeight, 0.2, 1), 'aria-label': 'Line height'},
389
- 'elem': lineHeightSVGElements
390
- },
391
- {
392
- 'html': 'a',
393
- 'attr': {'href': linkCommandToggle('help', '1'), 'aria-label': 'Help'},
394
- 'elem': helpSVGElements
395
- }
396
- ]
373
+ // Reset the runtime
374
+ const {isDocumentReset} = runtime;
375
+ const {windowLocation} = runtime;
376
+ const documentElements = runtime.reset();
377
+
378
+ // Render the elment model
379
+ renderElements(
380
+ this.window.document.body,
381
+ [
382
+ documentElements,
383
+ isDocumentReset ? this.burgerElements() : null
384
+ ],
385
+ isDocumentReset
386
+ );
387
+
388
+ // Focus?
389
+ if (runtime.documentFocus !== null) {
390
+ const element = this.window.document.getElementById(runtime.documentFocus);
391
+ if (element !== null) {
392
+ element.focus();
393
+ if ('selectionStart' in element) {
394
+ element.selectionStart = element.value.length;
395
+ element.selectionEnd = element.value.length;
396
+ }
397
397
  }
398
- ]
398
+ }
399
+
400
+ // Navigate?
401
+ // Note: This is done after render since it may have no effect (in which case we want to render).
402
+ if (windowLocation !== null) {
403
+ this.window.location.href = windowLocation;
404
+ }
399
405
  };
400
406
 
401
- // Set document title?
402
- if (scriptOptions.runtime.documentTitle !== null) {
403
- result.title = scriptOptions.runtime.documentTitle;
407
+ return scriptOptions;
408
+ }
409
+
410
+
411
+ modifyURL(url, resourceURL) {
412
+ // Hash URL?
413
+ if (url.startsWith('#')) {
414
+ // Fixup the "url" param if its relative
415
+ const hashParams = decodeQueryString(url.slice(1));
416
+ if ('url' in hashParams && hashParams.url !== '' && isRelativeURL(hashParams.url)) {
417
+ hashParams.url = `${getBaseURL(resourceURL)}${hashParams.url}`;
418
+ }
419
+
420
+ // Encode hash parameters with a hash ID
421
+ const paramString = encodeQueryString({...this.params, ...hashParams});
422
+ const hashID = getHashID(url);
423
+ return `#${paramString}${hashID !== null && paramString !== '' ? '&' : ''}${hashID !== null ? hashID : ''}`;
404
424
  }
405
425
 
406
- return result;
426
+ // Relative URL?
427
+ if (isRelativeURL(url)) {
428
+ return `${getBaseURL(resourceURL)}${url}`;
429
+ }
430
+
431
+ return url;
432
+ }
433
+
434
+
435
+ burgerElements() {
436
+ return !this.menu ? null : [
437
+ {
438
+ 'html': 'div',
439
+ 'attr': {'class': 'menu-burger'},
440
+ 'elem': [
441
+ {
442
+ 'html': 'a',
443
+ 'attr': {'href': this.linkValueToggle('menu', '1'), 'aria-label': 'Menu'},
444
+ 'elem': menuSVGElements
445
+ }
446
+ ]
447
+ },
448
+
449
+ // Popup menu
450
+ !('menu' in this.params) ? null : {
451
+ 'html': 'div',
452
+ 'attr': {'class': 'menu'},
453
+ 'elem': [
454
+ {
455
+ 'html': 'a',
456
+ 'attr': {'href': this.linkCommandToggle('markdown', '1'), 'aria-label': 'Show Markdown'},
457
+ 'elem': markdownSVGElements
458
+ },
459
+ {
460
+ 'html': 'a',
461
+ 'attr': {'href': this.linkCycle('fontSize', this.fontSize, 2), 'aria-label': 'Font size'},
462
+ 'elem': fontSizeSVGElements
463
+ },
464
+ {
465
+ 'html': 'a',
466
+ 'attr': {'href': this.linkCycle('lineHeight', this.lineHeight, 0.2, 1), 'aria-label': 'Line height'},
467
+ 'elem': lineHeightSVGElements
468
+ },
469
+ {
470
+ 'html': 'a',
471
+ 'attr': {'href': this.linkCommandToggle('help', '1'), 'aria-label': 'Help'},
472
+ 'elem': helpSVGElements
473
+ }
474
+ ]
475
+ }
476
+ ];
477
+ }
478
+
479
+
480
+ linkCycle(paramName, defaultValue, delta, fixed = null) {
481
+ const value = paramName in this.params ? this.params[paramName] : defaultValue;
482
+ const {attr} = markdownUpTypes.MarkdownUp.struct.members.find((member) => member.name === paramName);
483
+ let valueNew = value + delta;
484
+ if (valueNew > attr.lte) {
485
+ valueNew = attr.gte;
486
+ }
487
+ valueNew = Math.max(attr.gte, Math.min(attr.lte, valueNew));
488
+ const params = {...this.params};
489
+ params[paramName] = fixed === null ? `${valueNew}` : `${valueNew.toFixed(fixed)}`;
490
+ return `#${encodeQueryString(params)}`;
491
+ }
492
+
493
+
494
+ linkCommandToggle(command, value) {
495
+ const params = {...this.params};
496
+ if ('cmd' in this.params && command in this.params.cmd) {
497
+ delete params.cmd;
498
+ } else {
499
+ params.cmd = {};
500
+ params.cmd[command] = `${value}`;
501
+ }
502
+ return `#${encodeQueryString(params)}`;
503
+ }
504
+
505
+
506
+ linkValueToggle(name, value) {
507
+ const params = {...this.params};
508
+ if (!(name in this.params)) {
509
+ params[name] = value;
510
+ } else {
511
+ delete params[name];
512
+ }
513
+ return `#${encodeQueryString(params)}`;
407
514
  }
408
515
  }
409
516
 
410
517
 
411
518
  // Get a URL's hash ID
412
- export function getHashID(url) {
519
+ function getHashID(url) {
413
520
  const matchId = url.match(rHashId);
414
521
  return matchId !== null ? matchId[1] : null;
415
522
  }
@@ -417,13 +524,6 @@ export function getHashID(url) {
417
524
  const rHashId = /[#&]([^=]+)$/;
418
525
 
419
526
 
420
- // Encode hash parameters with a hash ID
421
- export function encodeHashID(params, hashID) {
422
- const paramString = encodeQueryString(params);
423
- return `#${paramString}${hashID !== null && paramString !== '' ? '&' : ''}${hashID !== null ? hashID : ''}`;
424
- }
425
-
426
-
427
527
  // Icon sizes
428
528
  const burgerSize = '24';
429
529
  const iconSize = '36';