markdown-up 3.9.0 → 3.10.1

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.
Files changed (2) hide show
  1. package/lib/app.js +72 -15
  2. package/package.json +3 -3
package/lib/app.js CHANGED
@@ -37,10 +37,10 @@ struct MarkdownUpLocal
37
37
  optional bool darkMode
38
38
 
39
39
  # The font size
40
- optional int(>= 8, <= 18) fontSize
40
+ optional int(>= 2, <= 100) fontSize
41
41
 
42
42
  # The line height
43
- optional float(>= 1, <= 2) lineHeight
43
+ optional float(>= 1, <= 10) lineHeight
44
44
 
45
45
 
46
46
  # The MarkdownUp session storage JSON schema
@@ -100,7 +100,7 @@ export class MarkdownUp {
100
100
  (this.window.matchMedia && this.window.matchMedia('(prefers-color-scheme: dark)').matches);
101
101
  this.fontSize = (options !== null ? options.fontSize : null) ?? 12;
102
102
  this.globals = (options !== null ? options.globals : null) ?? null;
103
- this.helpURL = (options !== null ? options.helpURL : null) ?? 'https://craigahobbs.github.io/markdown-up';
103
+ this.helpURL = (options !== null ? options.helpURL : null) ?? 'https://craigahobbs.github.io/markdown-up-py/';
104
104
  this.lineHeight = (options !== null ? options.lineHeight : null) ?? 1.2;
105
105
  this.markdownText = (options !== null ? options.markdownText : null) ?? null;
106
106
  this.menu = (options !== null ? options.menu : null) ?? true;
@@ -182,7 +182,25 @@ export class MarkdownUp {
182
182
  // Set the document keydown handler?
183
183
  if ('keyDown' in result) {
184
184
  this.runtimeDocumentKeyDown = result.keyDown;
185
- this.window.document.addEventListener('keydown', result.keyDown);
185
+ this.window.document.addEventListener('keydown', async (event) => {
186
+ // Is the active element something that wants this event?
187
+ const {activeElement} = this.window.document;
188
+ if (activeElement instanceof this.window.HTMLElement &&
189
+ (activeElement.tagName === 'INPUT' ||
190
+ activeElement.tagName === 'TEXTAREA' ||
191
+ activeElement.tagName === 'SELECT' ||
192
+ activeElement.isContentEditable ||
193
+ activeElement.getAttribute('role') === 'textbox' ||
194
+ activeElement.getAttribute('role') === 'combobox' ||
195
+ activeElement.getAttribute('role') === 'searchbox'
196
+ )
197
+ ) {
198
+ return;
199
+ }
200
+
201
+ // Call the document keydown handler
202
+ await result.keyDown(event);
203
+ });
186
204
  }
187
205
 
188
206
  // Render the element model
@@ -555,11 +573,11 @@ export class MarkdownUp {
555
573
  this.menuDarkModeToggle({
556
574
  'path': 'M16,3 A10,10,0,1,1,3,18 A14,14,0,0,0,17,3'
557
575
  }),
558
- this.menuValueCycle('fontSize', this.fontSize, 2, {
559
- 'path': 'M4,22 L10,2 L14,2 L20,22 M6,14 L18,14',
576
+ this.menuValueCycle('fontSize', 12, [8, 10, 12, 14, 18, 24], (value) => `${value}pt`, {
577
+ 'path': 'M4,22 L10,2 L14,2 L20,22 M6,12.5 L18,12.5',
560
578
  'strokeWidth': 4
561
579
  }),
562
- this.menuValueCycle('lineHeight', this.lineHeight, 0.2, {
580
+ this.menuValueCycle('lineHeight', 1.2, [1.2, 1.4, 1.6, 1.8, 2.0], null, {
563
581
  'path2': 'M2,3 L22,3 M2,9 L22,9 M2,15 L22,15 M2,21 L22,21'
564
582
  }),
565
583
  this.menuValueToggle('debug', {
@@ -641,14 +659,16 @@ export class MarkdownUp {
641
659
  }
642
660
 
643
661
 
644
- menuValueCycle(valueName, valueDefault, valueDelta, icon) {
662
+ menuValueCycle(valueName, valueDefault, values, textFn, icon) {
663
+ const valueCurrent = this.paramsLocal[valueName] ?? valueDefault;
664
+ let ixNew = values.indexOf(valueCurrent) + 1;
665
+ if (ixNew >= values.length) {
666
+ ixNew = 0;
667
+ }
668
+ const valueNew = values[ixNew];
669
+ icon.text = (textFn !== null ? textFn(valueCurrent) : valueCurrent);
645
670
  return this.menuButton(
646
671
  () => {
647
- const {attr} = markdownUpTypes.MarkdownUpLocal.struct.members.find((member) => member.name === valueName);
648
- let valueNew = (this.paramsLocal[valueName] ?? valueDefault) + valueDelta;
649
- if (valueNew > attr.lte) {
650
- valueNew = attr.gte;
651
- }
652
672
  this.paramsLocal[valueName] = valueNew;
653
673
  this.window.localStorage.setItem('MarkdownUp', JSON.stringify(this.paramsLocal));
654
674
  this.render(true);
@@ -658,11 +678,23 @@ export class MarkdownUp {
658
678
  }
659
679
 
660
680
 
661
- menuButton(onClick, {checked = false, noCheck = false, path = null, path2 = null, strokeWidth = 3, size = 48}) {
681
+ menuButton(onClick, {checked = false, noCheck = false, path = null, path2 = null, strokeWidth = 3, size = 48, text = null}) {
662
682
  const isDarkMode = this.paramsLocal.darkMode ?? this.darkMode;
663
683
  const stroke = (isDarkMode ? (checked && !noCheck ? 'black' : 'white') : (checked && !noCheck ? 'white' : 'black'));
684
+ const background = (stroke === 'black' ? 'white' : 'black');
664
685
  const borderSize = (0.125 * size).toFixed(3);
665
686
  const innerSize = (0.75 * size).toFixed(3);
687
+
688
+ // Compute the text block geometry
689
+ const textStrokeWidth = Math.round(1000 * 0.05 * size) / 1000;
690
+ const textLeft = 0.5 * textStrokeWidth;
691
+ const textRight = 12.5 * textStrokeWidth;
692
+ const textTop = size - 6.5 * textStrokeWidth;
693
+ const textBottom = size - 0.5 * textStrokeWidth;
694
+ const textBoxX = 0.5 * (textLeft + textRight);
695
+ const textBoxY = 0.5 * (textTop + textBottom);
696
+ const textBoxSize = (textBottom - textTop) - 1.75 * textStrokeWidth;
697
+
666
698
  return {
667
699
  'html': 'div',
668
700
  'attr': {'style': 'cursor: pointer; user-select: none;'},
@@ -691,7 +723,32 @@ export class MarkdownUp {
691
723
  }
692
724
  ]
693
725
  }
694
- }
726
+ },
727
+ (text === null ? null : {
728
+ 'svg': 'rect',
729
+ 'attr': {
730
+ 'fill': background,
731
+ 'stroke': stroke,
732
+ 'stroke-width': textStrokeWidth,
733
+ 'x': textLeft.toFixed(3),
734
+ 'y': textTop.toFixed(3),
735
+ 'width': (textRight - textLeft).toFixed(3),
736
+ 'height': (textBottom - textTop).toFixed(3)
737
+ }
738
+ }),
739
+ (text === null ? null : {
740
+ 'svg': 'text',
741
+ 'attr': {
742
+ 'fill': stroke,
743
+ 'x': textBoxX.toFixed(3),
744
+ 'y': textBoxY.toFixed(3),
745
+ 'text-anchor': 'middle',
746
+ 'dominant-baseline': 'middle',
747
+ 'font-size': `${textBoxSize.toFixed(3)}px`,
748
+ 'font-weight': 'bold'
749
+ },
750
+ 'elem': {'text': text}
751
+ })
695
752
  ]
696
753
  },
697
754
  'callback': (element) => {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "markdown-up",
4
- "version": "3.9.0",
4
+ "version": "3.10.1",
5
5
  "description": "MarkdownUp is a Markdown viewer",
6
6
  "keywords": [
7
7
  "markdown",
@@ -22,7 +22,7 @@
22
22
  "test": "node --test test/"
23
23
  },
24
24
  "dependencies": {
25
- "bare-script": "~3.5",
25
+ "bare-script": "~3.6",
26
26
  "element-model": "~1.2",
27
27
  "markdown-model": "~2.2",
28
28
  "schema-markdown": "~1.2",
@@ -30,7 +30,7 @@
30
30
  },
31
31
  "devDependencies": {
32
32
  "c8": "~10.1",
33
- "eslint": "~9.35",
33
+ "eslint": "~9.36",
34
34
  "jsdoc": "~4.0",
35
35
  "jsdom": "~27.0"
36
36
  }