markdown-up 1.8.3 → 1.8.5

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
@@ -37,6 +37,9 @@ struct MarkdownUp
37
37
  # The MarkdownUp local storage JSON schema
38
38
  struct MarkdownUpLocal
39
39
 
40
+ # If set, dark mode is enabled
41
+ optional int(== 1) darkMode
42
+
40
43
  # The font size
41
44
  optional int(>= 8, <= 18) fontSize
42
45
 
@@ -50,10 +53,10 @@ struct MarkdownUpSession
50
53
  # Optional command
51
54
  optional MarkdownUpView view
52
55
 
53
- # The menu visibility (default is collapsed)
56
+ # If set, the menu is expanded (default is collapsed)
54
57
  optional int(== 1) menu
55
58
 
56
- # If true, enable debug behavior
59
+ # If set, enable debug behavior
57
60
  optional int(== 1) debug
58
61
 
59
62
 
@@ -72,6 +75,7 @@ enum MarkdownUpView
72
75
  * The MarkdownUp application options
73
76
  *
74
77
  * @typedef {Object} MarkdownUpOptions
78
+ * @property {boolean} [darkMode = false] - If true, use dark mode by default
75
79
  * @property {number} [fontSize = 12] - The font size, in points
76
80
  * @property {number} [lineHeight = 1.2] - The line height, in em
77
81
  * @property {?string} [markdownText = null] - The default Markdown text
@@ -95,6 +99,7 @@ export class MarkdownUp {
95
99
  this.params = null;
96
100
  this.paramsLocal = null;
97
101
  this.paramsSession = null;
102
+ this.darkMode = (options !== null ? options.darkMode : null) ?? false;
98
103
  this.fontSize = (options !== null ? options.fontSize : null) ?? 12;
99
104
  this.lineHeight = (options !== null ? options.lineHeight : null) ?? 1.2;
100
105
  this.markdownText = (options !== null ? options.markdownText : null) ?? null;
@@ -141,6 +146,10 @@ export class MarkdownUp {
141
146
  result = await this.main();
142
147
  }
143
148
 
149
+ // Set the colors
150
+ const isDarkMode = this.paramsLocal.darkMode ?? this.darkMode;
151
+ this.window.document.documentElement.style.setProperty('--markdown-model-dark-mode', isDarkMode ? '1' : '0');
152
+
144
153
  // Set the font size
145
154
  const fontSize = this.paramsLocal.fontSize ?? this.fontSize;
146
155
  this.window.document.documentElement.style.setProperty('--markdown-model-font-size', `${fontSize}pt`);
@@ -453,7 +462,11 @@ export class MarkdownUp {
453
462
  {
454
463
  'html': 'div',
455
464
  'attr': {'class': 'menu-burger'},
456
- 'elem': this.menuValueToggle('menu', menuSVGElements, 'Menu')
465
+ 'elem': this.menuValueToggle('menu', {
466
+ 'size': 32,
467
+ 'noCheck': true,
468
+ 'path': 'M3,5 L21,5 M3,12 L21,12 M3,19 L21,19'
469
+ })
457
470
  },
458
471
 
459
472
  // Popup menu
@@ -461,73 +474,124 @@ export class MarkdownUp {
461
474
  'html': 'div',
462
475
  'attr': {'class': 'menu'},
463
476
  'elem': [
464
- this.menuViewToggle('markdown', markdownSVGElements, 'Show Markdown'),
465
- this.menuValueCycle('fontSize', fontSizeSVGElements, 'Cycle font size', this.fontSize, 2),
466
- this.menuValueCycle('lineHeight', lineHeightSVGElements, 'Cycle line height', this.lineHeight, 0.2),
467
- this.menuValueToggle('debug', debugSVGElements, 'Debug'),
468
- this.menuViewToggle('help', helpSVGElements, 'Help')
477
+ this.menuViewToggle('markdown', {
478
+ 'path': 'M4,2 L20,2 L20,22 L4,22 Z',
479
+ 'path2': 'M7,7.5 L17,7.5 M7,12 L17,12 M7,16.5 L17,16.5'
480
+ }),
481
+ this.menuValueToggle('darkMode', {
482
+ 'path': 'M16,3 A10,10,0,1,1,3,18 A14,14,0,0,0,17,3'
483
+ }, true),
484
+ this.menuValueCycle('fontSize', this.fontSize, 2, {
485
+ 'path': 'M4,22 L10,2 L14,2 L20,22 M6,14 L18,14',
486
+ 'strokeWidth': 4
487
+ }),
488
+ this.menuValueCycle('lineHeight', this.lineHeight, 0.2, {
489
+ 'path2': 'M2,3 L22,3 M2,9 L22,9 M2,15 L22,15 M2,21 L22,21'
490
+ }),
491
+ this.menuValueToggle('debug', {
492
+ 'path': 'M12,5 A4,7,0,1,0,12,19 A4,7,0,1,0,12,5 M9,9 L15,9 M9,9 L4,6 M9,12 L3,12 M9,15 L4,18 ' +
493
+ 'M15,9 L20,6 M15,12 L21,12 M15,15 L20,18'
494
+ }),
495
+ this.menuViewToggle('help', {
496
+ 'path': 'M7,9 L7,4 L17,4 L17,12 L12,12 L12,16 M12,19 L12,22'
497
+ })
469
498
  ]
470
499
  }
471
500
  ];
472
501
  }
473
502
 
474
503
 
475
- menuValueToggle(value, svgElements, ariaLabel) {
476
- return {
477
- 'html': 'a',
478
- 'attr': {'style': 'cursor: pointer; user-select: none;', 'aria-label': ariaLabel},
479
- 'elem': svgElements(value in this.paramsSession),
480
- 'callback': (element) => {
481
- element.addEventListener('click', () => {
482
- if (value in this.paramsSession) {
483
- delete this.paramsSession[value];
484
- } else {
485
- this.paramsSession[value] = 1;
486
- }
487
- this.window.sessionStorage.setItem('MarkdownUp', JSON.stringify(this.paramsSession));
488
- this.render(true);
489
- });
490
- }
491
- };
504
+ menuValueToggle(valueName, icon, isLocal = false) {
505
+ const params = (isLocal ? this.paramsLocal : this.paramsSession);
506
+ icon.checked = valueName in params;
507
+ return this.menuButton(
508
+ () => {
509
+ if (valueName in params) {
510
+ delete params[valueName];
511
+ } else {
512
+ params[valueName] = 1;
513
+ }
514
+ const storage = (isLocal ? this.window.localStorage : this.window.sessionStorage);
515
+ storage.setItem('MarkdownUp', JSON.stringify(params));
516
+ this.render(true);
517
+ },
518
+ icon
519
+ );
492
520
  }
493
521
 
494
522
 
495
- menuViewToggle(value, svgElements, ariaLabel) {
496
- return {
497
- 'html': 'a',
498
- 'attr': {'style': 'cursor: pointer; user-select: none;', 'aria-label': ariaLabel},
499
- 'elem': svgElements(this.paramsSession.view === value),
500
- 'callback': (element) => {
501
- element.addEventListener('click', () => {
502
- if (this.paramsSession.view === value) {
503
- delete this.paramsSession.view;
504
- } else {
505
- this.paramsSession.view = value;
506
- }
507
- this.window.sessionStorage.setItem('MarkdownUp', JSON.stringify(this.paramsSession));
508
- this.render(true);
509
- });
510
- }
511
- };
523
+ menuViewToggle(viewValue, icon) {
524
+ icon.checked = this.paramsSession.view === viewValue;
525
+ return this.menuButton(
526
+ () => {
527
+ if (this.paramsSession.view === viewValue) {
528
+ delete this.paramsSession.view;
529
+ } else {
530
+ this.paramsSession.view = viewValue;
531
+ }
532
+ this.window.sessionStorage.setItem('MarkdownUp', JSON.stringify(this.paramsSession));
533
+ this.render(true);
534
+ },
535
+ icon
536
+ );
512
537
  }
513
538
 
514
539
 
515
- menuValueCycle(valueName, svgElements, ariaLabel, valueDefault, valueDelta) {
540
+ menuValueCycle(valueName, valueDefault, valueDelta, icon) {
541
+ return this.menuButton(
542
+ () => {
543
+ const {attr} = markdownUpTypes.MarkdownUpLocal.struct.members.find((member) => member.name === valueName);
544
+ let valueNew = (this.paramsLocal[valueName] ?? valueDefault) + valueDelta;
545
+ if (valueNew > attr.lte) {
546
+ valueNew = attr.gte;
547
+ }
548
+ this.paramsLocal[valueName] = valueNew;
549
+ this.window.localStorage.setItem('MarkdownUp', JSON.stringify(this.paramsLocal));
550
+ this.render(true);
551
+ },
552
+ icon
553
+ );
554
+ }
555
+
556
+
557
+ menuButton(onClick, {checked = false, noCheck = false, path = null, path2 = null, strokeWidth = 3, size = 48}) {
558
+ const isDarkMode = this.paramsLocal.darkMode ?? this.darkMode;
559
+ const stroke = (isDarkMode ? (checked && !noCheck ? 'black' : 'white') : (checked && !noCheck ? 'white' : 'black'));
560
+ const borderSize = (0.125 * size).toFixed(3);
561
+ const innerSize = (0.75 * size).toFixed(3);
516
562
  return {
517
- 'html': 'a',
518
- 'attr': {'style': 'cursor: pointer; user-select: none;', 'aria-label': ariaLabel},
519
- 'elem': svgElements(),
520
- 'callback': (element) => {
521
- element.addEventListener('click', () => {
522
- const {attr} = markdownUpTypes.MarkdownUpLocal.struct.members.find((member) => member.name === valueName);
523
- let valueNew = (this.paramsLocal[valueName] ?? valueDefault) + valueDelta;
524
- if (valueNew > attr.lte) {
525
- valueNew = attr.gte;
563
+ 'html': 'div',
564
+ 'attr': {'style': 'cursor: pointer; user-select: none;'},
565
+ 'elem': {
566
+ 'svg': 'svg',
567
+ 'attr': {'width': size, 'height': size},
568
+ 'elem': [
569
+ !checked || noCheck ? null : {
570
+ 'svg': 'rect',
571
+ 'attr': {'fill': (isDarkMode ? 'white' : 'black'), 'stroke': 'none', 'width': size, 'height': size}
572
+ },
573
+ {
574
+ 'svg': 'g',
575
+ 'attr': {'transform': `translate(${borderSize}, ${borderSize})`},
576
+ 'elem': {
577
+ 'svg': 'svg',
578
+ 'attr': {'width': innerSize, 'height': innerSize, 'viewBox': '0 0 24 24'},
579
+ 'elem': [
580
+ path === null ? null : {
581
+ 'svg': 'path',
582
+ 'attr': {'fill': 'none', 'stroke': stroke, 'stroke-width': strokeWidth, 'd': path}
583
+ },
584
+ path2 === null ? null : {
585
+ 'svg': 'path',
586
+ 'attr': {'fill': 'none', 'stroke': stroke, 'stroke-width': strokeWidth - 1, 'd': path2}
587
+ }
588
+ ]
589
+ }
526
590
  }
527
- this.paramsLocal[valueName] = valueNew;
528
- this.window.localStorage.setItem('MarkdownUp', JSON.stringify(this.paramsLocal));
529
- this.render(true);
530
- });
591
+ ]
592
+ },
593
+ 'callback': (element) => {
594
+ element.addEventListener('click', onClick);
531
595
  }
532
596
  };
533
597
  }
@@ -541,58 +605,3 @@ function getHashID(url) {
541
605
  }
542
606
 
543
607
  const rHashId = /[#&]([^=]+)$/;
544
-
545
-
546
- // Menu icons
547
- const menuSVGElements = () => menuSVGHelper('M3,5 L21,5 M3,12 L21,12 M3,19 L21,19', false, 3, null, 32);
548
- const debugSVGElements = (isChecked) => menuSVGHelper(
549
- 'M12,5 A4,7,0,1,0,12,19 A4,7,0,1,0,12,5 M9,9 L15,9 M9,9 L4,6 M9,12 L3,12 M9,15 L4,18 M15,9 L20,6 M15,12 L21,12 M15,15 L20,18',
550
- isChecked
551
- );
552
- const fontSizeSVGElements = () => menuSVGHelper('M4,22 L10,2 L14,2 L20,22 M6,14 L18,14', false, 4);
553
- const helpSVGElements = (isChecked) => menuSVGHelper('M7,9 L7,4 L17,4 L17,12 L12,12 L12,16 M12,19 L12,22', isChecked);
554
- const lineHeightSVGElements = () => menuSVGHelper('M2,3 L22,3 M2,9 L22,9 M2,15 L22,15 M2,21 L22,21', false, 2);
555
- const markdownSVGElements = (isChecked) => (
556
- menuSVGHelper('M4,2 L20,2 L20,22 L4,22 Z', isChecked, 3, 'M7,7.5 L17,7.5 M7,12 L17,12 M7,16.5 L17,16.5')
557
- );
558
-
559
-
560
- // Menu SVG helper function
561
- function menuSVGHelper(pathD, isChecked = false, strokeWidth = 3, pathD2 = null, iconSize = 48) {
562
- const borderSize = (0.125 * iconSize).toFixed(3);
563
- const innerSize = (0.75 * iconSize).toFixed(3);
564
- const iconElems = [
565
- {
566
- 'svg': 'path',
567
- 'attr': {'fill': 'none', 'stroke': (isChecked ? 'white' : 'black'), 'stroke-width': strokeWidth, 'd': pathD}
568
- }
569
- ];
570
- const svg = {
571
- 'svg': 'svg',
572
- 'attr': {'width': iconSize, 'height': iconSize},
573
- 'elem': [
574
- {
575
- 'svg': 'g',
576
- 'attr': {'transform': `translate(${borderSize}, ${borderSize})`},
577
- 'elem': {
578
- 'svg': 'svg',
579
- 'attr': {'width': innerSize, 'height': innerSize, 'viewBox': '0 0 24 24'},
580
- 'elem': iconElems
581
- }
582
- }
583
- ]
584
- };
585
- if (isChecked) {
586
- svg.elem.unshift({
587
- 'svg': 'rect',
588
- 'attr': {'fill': 'black', 'stroke': 'none', 'width': iconSize, 'height': iconSize}
589
- });
590
- }
591
- if (pathD2 !== null) {
592
- iconElems.push({
593
- 'svg': 'path',
594
- 'attr': {'fill': 'none', 'stroke': (isChecked ? 'white' : 'black'), 'stroke-width': strokeWidth - 1, 'd': pathD2}
595
- });
596
- }
597
- return svg;
598
- }
@@ -8,11 +8,8 @@ import {dataTableElements, validateDataTable} from './dataTable.js';
8
8
  import {escapeMarkdownText, markdownHeaderId} from 'markdown-model/lib/elements.js';
9
9
  import {getMarkdownTitle, parseMarkdown} from 'markdown-model/lib/parser.js';
10
10
  import {lineChartElements, validateLineChart} from './lineChart.js';
11
- import {validateType, validateTypeModel} from 'schema-markdown/lib/schema.js';
12
11
  import {encodeQueryString} from 'schema-markdown/lib/encode.js';
13
- import {parseSchemaMarkdown} from 'schema-markdown/lib/parser.js';
14
12
  import {schemaMarkdownDoc} from 'schema-markdown-doc/lib/schemaMarkdownDoc.js';
15
- import {typeModel} from 'schema-markdown/lib/typeModel.js';
16
13
  import {validateElements} from 'element-model/lib/elementModel.js';
17
14
 
18
15
 
@@ -648,54 +645,23 @@ export const markdownScriptFunctions = {
648
645
  // Schema functions
649
646
  //
650
647
 
651
- // $function: schemaParse
652
- // $group: Schema
653
- // $doc: Parse the [Schema Markdown](https://craigahobbs.github.io/schema-markdown/schema-markdown.html) text
654
- // $arg lines: The [Schema Markdown](https://craigahobbs.github.io/schema-markdown/schema-markdown.html)
655
- // $arg lines: text lines (may contain nested arrays of un-split lines)
656
- // $return: The schema's [type model](https://craigahobbs.github.io/schema-markdown-doc/doc/#var.vName='Types')
657
- 'schemaParse': (lines) => parseSchemaMarkdown(lines),
658
-
659
- // $function: schemaPrint
648
+ // $function: schemaElements
660
649
  // $group: Schema
661
650
  // $doc: Render a schema type's documentation
662
651
  // $arg types: The [type model](https://craigahobbs.github.io/schema-markdown-doc/doc/#var.vName='Types')
663
652
  // $arg typeName: The type name
664
653
  // $arg actionURLs: Optional (default is null). The
665
654
  // $arg actionURLs: [action URL overrides](https://craigahobbs.github.io/schema-markdown-doc/doc/#var.vName='ActionURL').
666
- 'schemaPrint': ([types, typeName, actionURLs = null], options) => {
667
- const {runtime} = options;
655
+ // $return: The schema type's documentation [element model](https://github.com/craigahobbs/element-model#readme)
656
+ 'schemaElements': ([types, typeName, actionURLs = null], options) => {
668
657
  const params = encodeQueryString(options.params);
669
658
  const schemaOptions = {params};
670
659
  if (actionURLs !== null) {
671
660
  schemaOptions.actionURLs = actionURLs;
672
661
  }
673
- runtime.setElements();
674
- runtime.addElements(schemaMarkdownDoc(types, typeName, schemaOptions));
662
+ return schemaMarkdownDoc(types, typeName, schemaOptions);
675
663
  },
676
664
 
677
- // $function: schemaTypeModel
678
- // $group: Schema
679
- // $doc: Get the [Schema Markdown Type Model](https://craigahobbs.github.io/schema-markdown-doc/doc/#var.vName='Types')
680
- // $return: The [Schema Markdown Type Model](https://craigahobbs.github.io/schema-markdown-doc/doc/#var.vName='Types')
681
- 'schemaTypeModel': () => typeModel,
682
-
683
- // $function: schemaValidate
684
- // $group: Schema
685
- // $doc: Validate an object to a schema type
686
- // $arg types: The [type model](https://craigahobbs.github.io/schema-markdown-doc/doc/#var.vName='Types')
687
- // $arg typeName: The type name
688
- // $arg value: The object to validate
689
- // $return: The validated object or null if validation fails
690
- 'schemaValidate': ([types, typeName, value]) => validateType(types, typeName, value),
691
-
692
- // $function: schemaValidateTypeModel
693
- // $group: Schema
694
- // $doc: Validate a [Schema Markdown Type Model](https://craigahobbs.github.io/schema-markdown-doc/doc/#var.vName='Types')
695
- // $arg types: The [type model](https://craigahobbs.github.io/schema-markdown-doc/doc/#var.vName='Types') to validate
696
- // $return: The validated [type model](https://craigahobbs.github.io/schema-markdown-doc/doc/#var.vName='Types')
697
- 'schemaValidateTypeModel': ([types]) => validateTypeModel(types),
698
-
699
665
 
700
666
  //
701
667
  // Session storage functions
@@ -734,7 +700,7 @@ function elementModelWrapCallbacks(elements, options) {
734
700
  for (const childElements of elements) {
735
701
  elementModelWrapCallbacks(childElements, options);
736
702
  }
737
- } else if (typeof elements === 'object') {
703
+ } else if (elements !== null && typeof elements === 'object') {
738
704
  if ('elem' in elements) {
739
705
  elementModelWrapCallbacks(elements.elem, options);
740
706
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "markdown-up",
4
- "version": "1.8.3",
4
+ "version": "1.8.5",
5
5
  "description": "MarkdownUp is a Markdown viewer",
6
6
  "keywords": [
7
7
  "markdown",