markdown-up 1.9.1 → 2.0.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.
- package/README.md +9 -9
- package/lib/app.js +14 -15
- package/lib/script.js +3 -3
- package/lib/scriptLibrary.js +122 -117
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -90,13 +90,13 @@ markdownPrint( \
|
|
|
90
90
|
|
|
91
91
|
# Render many hellos
|
|
92
92
|
ixHello = 0
|
|
93
|
-
while ixHello < helloCount
|
|
93
|
+
while ixHello < helloCount:
|
|
94
94
|
# Render the hello title
|
|
95
95
|
helloTitle = 'Hello #' + (ixHello + 1)
|
|
96
96
|
markdownPrint('', '## ' + helloTitle)
|
|
97
97
|
|
|
98
98
|
# Render the hello drawing
|
|
99
|
-
|
|
99
|
+
drawNew(width, height)
|
|
100
100
|
drawStyle('red', borderSize, 'blue')
|
|
101
101
|
drawRect(0.5 * borderSize, 0.5 * borderSize, width - borderSize, height - borderSize)
|
|
102
102
|
drawTextStyle(0.67 * height, 'white', true)
|
|
@@ -116,7 +116,7 @@ MarkdownUp provides some additional functionality that can be included at runtim
|
|
|
116
116
|
following example with the unit test include library:
|
|
117
117
|
|
|
118
118
|
~~~
|
|
119
|
-
include
|
|
119
|
+
include <unittest.mds>
|
|
120
120
|
|
|
121
121
|
function testSanity()
|
|
122
122
|
unittestEquals(1 + 1, 2)
|
|
@@ -133,17 +133,17 @@ documentation for more information on the available include libraries.
|
|
|
133
133
|
|
|
134
134
|
### Debug Mode
|
|
135
135
|
|
|
136
|
-
Debug mode
|
|
137
|
-
|
|
136
|
+
Debug mode logs the script runtime duration and runs the CalcScript linter, which performs static
|
|
137
|
+
code analysis on your code and reports warnings for any issues found.
|
|
138
|
+
|
|
139
|
+
Debug mode also enables debug logging using the
|
|
140
|
+
[consoleLogDebug function](https://craigahobbs.github.io/calc-script/library/#var.vName='consoleLogDebug').
|
|
138
141
|
For example:
|
|
139
142
|
|
|
140
143
|
~~~ calcscript
|
|
141
|
-
|
|
144
|
+
consoleLogDebug('Hello debug')
|
|
142
145
|
~~~
|
|
143
146
|
|
|
144
|
-
Debug mode also enables the CalcScript linter, which performs static code analysis on your code and
|
|
145
|
-
reports warnings for any issues found.
|
|
146
|
-
|
|
147
147
|
To turn on debug mode, click the debug button in the MarkdownUp menu in the upper-right of the page.
|
|
148
148
|
|
|
149
149
|
|
package/lib/app.js
CHANGED
|
@@ -81,6 +81,7 @@ enum MarkdownUpView
|
|
|
81
81
|
* @property {number} [lineHeight = 1.2] - The line height, in em
|
|
82
82
|
* @property {?string} [markdownText = null] - The default Markdown text
|
|
83
83
|
* @property {boolean} [menu = true] - If true, show the menu
|
|
84
|
+
* @property {string} [systemPrefix] - The markdown-script system include prefix
|
|
84
85
|
* @property {string} [url = 'README.md'] - The default resource URL
|
|
85
86
|
*/
|
|
86
87
|
|
|
@@ -106,6 +107,7 @@ export class MarkdownUp {
|
|
|
106
107
|
this.lineHeight = (options !== null ? options.lineHeight : null) ?? 1.2;
|
|
107
108
|
this.markdownText = (options !== null ? options.markdownText : null) ?? null;
|
|
108
109
|
this.menu = (options !== null ? options.menu : null) ?? true;
|
|
110
|
+
this.systemPrefix = (options !== null ? options.systemPrefix : null) ?? 'https://craigahobbs.github.io/markdown-up/include/';
|
|
109
111
|
this.url = (options !== null ? options.url : null) ?? 'README.md';
|
|
110
112
|
this.runtimeWindowResize = null;
|
|
111
113
|
this.runtimeTimeoutId = null;
|
|
@@ -284,19 +286,19 @@ export class MarkdownUp {
|
|
|
284
286
|
({markdownText} = this);
|
|
285
287
|
|
|
286
288
|
// Log Markdown render begin
|
|
287
|
-
if ('logFn' in scriptOptions) {
|
|
289
|
+
if ('logFn' in scriptOptions && scriptOptions.debug) {
|
|
288
290
|
timeBegin = performance.now();
|
|
289
291
|
scriptOptions.logFn('MarkdownUp: ===== Rendering Markdown text');
|
|
290
292
|
}
|
|
291
293
|
} else {
|
|
292
294
|
// Log Markdown render begin
|
|
293
|
-
if ('logFn' in scriptOptions) {
|
|
295
|
+
if ('logFn' in scriptOptions && scriptOptions.debug) {
|
|
294
296
|
scriptOptions.logFn(`MarkdownUp: ===== Rendering Markdown document "${url}"`);
|
|
295
297
|
}
|
|
296
298
|
|
|
297
299
|
// Log Markdown fetch begin
|
|
298
300
|
let fetchBegin;
|
|
299
|
-
if ('logFn' in scriptOptions) {
|
|
301
|
+
if ('logFn' in scriptOptions && scriptOptions.debug) {
|
|
300
302
|
fetchBegin = performance.now();
|
|
301
303
|
scriptOptions.logFn(`MarkdownUp: Fetching "${url}" ...`);
|
|
302
304
|
}
|
|
@@ -316,7 +318,7 @@ export class MarkdownUp {
|
|
|
316
318
|
markdownText = await response.text();
|
|
317
319
|
|
|
318
320
|
// Log Markdown fetch end with timing
|
|
319
|
-
if ('logFn' in scriptOptions) {
|
|
321
|
+
if ('logFn' in scriptOptions && scriptOptions.debug) {
|
|
320
322
|
const fetchEnd = performance.now();
|
|
321
323
|
timeBegin = performance.now();
|
|
322
324
|
scriptOptions.logFn(`MarkdownUp: Fetch completed in ${(fetchEnd - fetchBegin).toFixed(1)} milliseconds`);
|
|
@@ -381,7 +383,7 @@ export class MarkdownUp {
|
|
|
381
383
|
scriptOptions.runtime.reset();
|
|
382
384
|
|
|
383
385
|
// Log Markdown render end
|
|
384
|
-
if ('logFn' in scriptOptions) {
|
|
386
|
+
if ('logFn' in scriptOptions && scriptOptions.debug) {
|
|
385
387
|
const timeEnd = performance.now();
|
|
386
388
|
scriptOptions.logFn(`MarkdownUp: Markdown rendered in ${(timeEnd - timeBegin).toFixed(1)} milliseconds`);
|
|
387
389
|
}
|
|
@@ -391,24 +393,21 @@ export class MarkdownUp {
|
|
|
391
393
|
|
|
392
394
|
|
|
393
395
|
createScriptOptions(resourceURL) {
|
|
396
|
+
const logFn = (text) => {
|
|
397
|
+
this.window.console.log(text);
|
|
398
|
+
};
|
|
394
399
|
const scriptOptions = {
|
|
400
|
+
'debug': 'debug' in this.paramsSession,
|
|
395
401
|
// eslint-disable-next-line require-await
|
|
396
402
|
'fetchFn': async (fetchURL, options) => this.window.fetch(fetchURL, options),
|
|
397
403
|
'fontSize': this.paramsLocal.fontSize ?? this.fontSize,
|
|
404
|
+
logFn,
|
|
398
405
|
'params': this.params,
|
|
406
|
+
'systemPrefix': this.systemPrefix,
|
|
399
407
|
'urlFn': (url) => this.modifyURL(url, resourceURL),
|
|
400
408
|
'window': this.window
|
|
401
409
|
};
|
|
402
410
|
|
|
403
|
-
// Add log function, if debugging
|
|
404
|
-
let logFn = null;
|
|
405
|
-
if ('debug' in this.paramsSession) {
|
|
406
|
-
logFn = (text) => {
|
|
407
|
-
this.window.console.log(text);
|
|
408
|
-
};
|
|
409
|
-
scriptOptions.logFn = logFn;
|
|
410
|
-
}
|
|
411
|
-
|
|
412
411
|
// Add hash parameter variables, if any
|
|
413
412
|
if ('var' in this.params) {
|
|
414
413
|
scriptOptions.variables = {};
|
|
@@ -417,7 +416,7 @@ export class MarkdownUp {
|
|
|
417
416
|
try {
|
|
418
417
|
scriptOptions.variables[varName] = evaluateExpression(parseExpression(varExprStr), scriptOptions.variables);
|
|
419
418
|
} catch ({message}) {
|
|
420
|
-
if (logFn !== null) {
|
|
419
|
+
if (logFn !== null && scriptOptions.debug) {
|
|
421
420
|
logFn(`MarkdownUp: Error evaluating variable "${varName}" expression "${varExprStr}": ${message}`);
|
|
422
421
|
}
|
|
423
422
|
}
|
package/lib/script.js
CHANGED
|
@@ -51,7 +51,7 @@ export async function markdownScriptCodeBlock(codeBlock, options) {
|
|
|
51
51
|
|
|
52
52
|
// Log script execution begin
|
|
53
53
|
let timeBegin;
|
|
54
|
-
if ('logFn' in options) {
|
|
54
|
+
if ('logFn' in options && options.debug) {
|
|
55
55
|
timeBegin = performance.now();
|
|
56
56
|
options.logFn(`MarkdownUp: Executing script at line number ${codeBlock.startLineNumber + 1} ...`);
|
|
57
57
|
}
|
|
@@ -63,7 +63,7 @@ export async function markdownScriptCodeBlock(codeBlock, options) {
|
|
|
63
63
|
const script = parseScript(codeBlock.lines, codeBlock.startLineNumber + 1);
|
|
64
64
|
|
|
65
65
|
// Run the calc-script linter?
|
|
66
|
-
if ('logFn' in options) {
|
|
66
|
+
if ('logFn' in options && options.debug) {
|
|
67
67
|
const warnings = lintScript(script);
|
|
68
68
|
const warningPrefix = `MarkdownUp: Script static analysis...`;
|
|
69
69
|
if (warnings.length === 0) {
|
|
@@ -83,7 +83,7 @@ export async function markdownScriptCodeBlock(codeBlock, options) {
|
|
|
83
83
|
}
|
|
84
84
|
|
|
85
85
|
// Log script execution end with timing
|
|
86
|
-
if ('logFn' in options) {
|
|
86
|
+
if ('logFn' in options && options.debug) {
|
|
87
87
|
const timeEnd = performance.now();
|
|
88
88
|
options.logFn(`MarkdownUp: Script executed in ${(timeEnd - timeBegin).toFixed(1)} milliseconds`);
|
|
89
89
|
}
|
package/lib/scriptLibrary.js
CHANGED
|
@@ -146,118 +146,55 @@ export const markdownScriptFunctions = {
|
|
|
146
146
|
// Document functions
|
|
147
147
|
//
|
|
148
148
|
|
|
149
|
-
// $function:
|
|
150
|
-
// $group: Document
|
|
151
|
-
// $doc: Fix-up relative URLs
|
|
152
|
-
// $arg url: The URL
|
|
153
|
-
// $return: The fixed-up URL
|
|
154
|
-
'documentURL': ([url], options) => options.urlFn(url),
|
|
155
|
-
|
|
156
|
-
// $function: getDocumentFontSize
|
|
149
|
+
// $function: documentFontSize
|
|
157
150
|
// $group: Document
|
|
158
151
|
// $doc: Get the document font size
|
|
159
152
|
// $return: The document font size, in pixels
|
|
160
|
-
'
|
|
153
|
+
'documentFontSize': (unused, options) => options.fontSize * pixelsPerPoint,
|
|
161
154
|
|
|
162
|
-
// $function:
|
|
155
|
+
// $function: documentInputValue
|
|
163
156
|
// $group: Document
|
|
164
157
|
// $doc: Get an input element's value
|
|
165
158
|
// $arg id: The input element ID
|
|
166
159
|
// $return: The input element value or null if the element does not exist
|
|
167
|
-
'
|
|
160
|
+
'documentInputValue': ([id], options) => {
|
|
168
161
|
const element = options.window.document.getElementById(id) ?? null;
|
|
169
162
|
return (element !== null ? (element.value ?? null) : null);
|
|
170
163
|
},
|
|
171
164
|
|
|
172
|
-
// $function:
|
|
173
|
-
// $group: Document
|
|
174
|
-
// $doc: Get the browser window's height
|
|
175
|
-
// $return: The browser window's height
|
|
176
|
-
'getWindowHeight': (unused, options) => options.window.innerHeight,
|
|
177
|
-
|
|
178
|
-
// $function: getWindowWidth
|
|
179
|
-
// $group: Document
|
|
180
|
-
// $doc: Get the browser window's width
|
|
181
|
-
// $return: The browser window's width
|
|
182
|
-
'getWindowWidth': (unused, options) => options.window.innerWidth,
|
|
183
|
-
|
|
184
|
-
// $function: setDocumentFocus
|
|
165
|
+
// $function: documentSetFocus
|
|
185
166
|
// $group: Document
|
|
186
167
|
// $doc: Set focus to an element
|
|
187
168
|
// $arg id: The element ID
|
|
188
|
-
'
|
|
169
|
+
'documentSetFocus': ([id], options) => {
|
|
189
170
|
const {runtime} = options;
|
|
190
171
|
runtime.documentFocus = id;
|
|
191
172
|
},
|
|
192
173
|
|
|
193
|
-
// $function:
|
|
174
|
+
// $function: documentSetReset
|
|
194
175
|
// $group: Document
|
|
195
176
|
// $doc: Set the document reset element
|
|
196
177
|
// $arg id: The element ID
|
|
197
|
-
'
|
|
178
|
+
'documentSetReset': ([id], options) => {
|
|
198
179
|
const {runtime} = options;
|
|
199
180
|
runtime.documentReset = id;
|
|
200
181
|
},
|
|
201
182
|
|
|
202
|
-
// $function:
|
|
183
|
+
// $function: documentSetTitle
|
|
203
184
|
// $group: Document
|
|
204
185
|
// $doc: Set the document title
|
|
205
186
|
// $arg title: The document title string
|
|
206
|
-
'
|
|
187
|
+
'documentSetTitle': ([title], options) => {
|
|
207
188
|
const {runtime} = options;
|
|
208
189
|
runtime.documentTitle = title;
|
|
209
190
|
},
|
|
210
191
|
|
|
211
|
-
// $function:
|
|
212
|
-
// $group: Document
|
|
213
|
-
// $doc: Navigate the browser window to a location URL
|
|
214
|
-
// $arg url: The new location URL
|
|
215
|
-
'setWindowLocation': ([location], options) => {
|
|
216
|
-
const {runtime} = options;
|
|
217
|
-
runtime.windowLocation = options.urlFn(location);
|
|
218
|
-
},
|
|
219
|
-
|
|
220
|
-
// $function: setWindowResize
|
|
221
|
-
// $group: Document
|
|
222
|
-
// $doc: Set the browser window resize event handler
|
|
223
|
-
// $arg callback: The window resize callback function
|
|
224
|
-
'setWindowResize': ([callback], options) => {
|
|
225
|
-
const {runtime} = options;
|
|
226
|
-
runtime.windowResize = async () => {
|
|
227
|
-
options.statementCount = 0;
|
|
228
|
-
try {
|
|
229
|
-
await callback([], options);
|
|
230
|
-
} catch ({message}) {
|
|
231
|
-
if ('logFn' in options) {
|
|
232
|
-
options.logFn(`MarkdownUp: Error executing setWindowResize callback: ${message}`);
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
options.runtimeUpdateFn();
|
|
236
|
-
};
|
|
237
|
-
},
|
|
238
|
-
|
|
239
|
-
// $function: setWindowTimeout
|
|
192
|
+
// $function: documentURL
|
|
240
193
|
// $group: Document
|
|
241
|
-
// $doc:
|
|
242
|
-
// $arg
|
|
243
|
-
// $
|
|
244
|
-
'
|
|
245
|
-
const {runtime} = options;
|
|
246
|
-
runtime.windowTimeout = [
|
|
247
|
-
async () => {
|
|
248
|
-
options.statementCount = 0;
|
|
249
|
-
try {
|
|
250
|
-
await callback([], options);
|
|
251
|
-
} catch ({message}) {
|
|
252
|
-
if ('logFn' in options) {
|
|
253
|
-
options.logFn(`MarkdownUp: Error executing setWindowTimeout callback: ${message}`);
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
options.runtimeUpdateFn();
|
|
257
|
-
},
|
|
258
|
-
delay
|
|
259
|
-
];
|
|
260
|
-
},
|
|
194
|
+
// $doc: Fix-up relative URLs
|
|
195
|
+
// $arg url: The URL
|
|
196
|
+
// $return: The fixed-up URL
|
|
197
|
+
'documentURL': ([url], options) => options.urlFn(url),
|
|
261
198
|
|
|
262
199
|
|
|
263
200
|
//
|
|
@@ -350,6 +287,12 @@ export const markdownScriptFunctions = {
|
|
|
350
287
|
runtime.drawingPath.push(`H ${x.toFixed(svgPrecision)}`);
|
|
351
288
|
},
|
|
352
289
|
|
|
290
|
+
// $function: drawHeight
|
|
291
|
+
// $group: Drawing
|
|
292
|
+
// $doc: Get the current drawing's height
|
|
293
|
+
// $return: The current drawing's height
|
|
294
|
+
'drawHeight': (unused, options) => options.runtime.drawingHeight,
|
|
295
|
+
|
|
353
296
|
// $function: drawImage
|
|
354
297
|
// $group: Drawing
|
|
355
298
|
// $doc: Draw an image
|
|
@@ -395,6 +338,18 @@ export const markdownScriptFunctions = {
|
|
|
395
338
|
runtime.drawingPath.push(`M ${x.toFixed(svgPrecision)} ${y.toFixed(svgPrecision)}`);
|
|
396
339
|
},
|
|
397
340
|
|
|
341
|
+
// $function: drawNew
|
|
342
|
+
// $group: Drawing
|
|
343
|
+
// $doc: Create a new drawing
|
|
344
|
+
// $arg width: The width of the drawing
|
|
345
|
+
// $arg height: The height of the drawing
|
|
346
|
+
'drawNew': ([width, height], options) => {
|
|
347
|
+
const {runtime} = options;
|
|
348
|
+
runtime.drawingWidth = width;
|
|
349
|
+
runtime.drawingHeight = height;
|
|
350
|
+
runtime.setDrawing(true);
|
|
351
|
+
},
|
|
352
|
+
|
|
398
353
|
// $function: drawOnClick
|
|
399
354
|
// $group: Drawing
|
|
400
355
|
// $doc: Set the most recent drawing object's on-click event handler
|
|
@@ -411,7 +366,7 @@ export const markdownScriptFunctions = {
|
|
|
411
366
|
try {
|
|
412
367
|
await callback([event.clientX - boundingRect.left, event.clientY - boundingRect.top], options);
|
|
413
368
|
} catch ({message}) {
|
|
414
|
-
if ('logFn' in options) {
|
|
369
|
+
if ('logFn' in options && options.debug) {
|
|
415
370
|
options.logFn(`MarkdownUp: Error executing drawOnClick callback: ${message}`);
|
|
416
371
|
}
|
|
417
372
|
}
|
|
@@ -523,6 +478,14 @@ export const markdownScriptFunctions = {
|
|
|
523
478
|
});
|
|
524
479
|
},
|
|
525
480
|
|
|
481
|
+
// $function: drawTextHeight
|
|
482
|
+
// $group: Drawing
|
|
483
|
+
// $doc: Compute the text's height to fit the width
|
|
484
|
+
// $arg text: The text
|
|
485
|
+
// $arg width: The width of the text. If 0, the default font size (in pixels) is returned.
|
|
486
|
+
// $return: The text's height
|
|
487
|
+
'drawTextHeight': ([text, width], options) => (width > 0 ? width / (fontWidthRatio * text.length) : options.runtime.drawingFontSizePx),
|
|
488
|
+
|
|
526
489
|
// $function: drawTextStyle
|
|
527
490
|
// $group: Drawing
|
|
528
491
|
// $doc: Set the current text drawing styles
|
|
@@ -540,6 +503,14 @@ export const markdownScriptFunctions = {
|
|
|
540
503
|
runtime.drawingFontFamily = (fontFamily !== null ? fontFamily : defaultFontFamily);
|
|
541
504
|
},
|
|
542
505
|
|
|
506
|
+
// $function: drawTextWidth
|
|
507
|
+
// $group: Drawing
|
|
508
|
+
// $doc: Compute the text's width
|
|
509
|
+
// $arg text: The text
|
|
510
|
+
// $arg fontSizePx: The text font size, in pixels
|
|
511
|
+
// $return: The text's width
|
|
512
|
+
'drawTextWidth': ([text, fontSizePx]) => fontWidthRatio * fontSizePx * text.length,
|
|
513
|
+
|
|
543
514
|
// $function: drawVLine
|
|
544
515
|
// $group: Drawing
|
|
545
516
|
// $doc: Draw a vertical line from the current point to the end point
|
|
@@ -550,45 +521,11 @@ export const markdownScriptFunctions = {
|
|
|
550
521
|
runtime.drawingPath.push(`V ${y.toFixed(svgPrecision)}`);
|
|
551
522
|
},
|
|
552
523
|
|
|
553
|
-
// $function:
|
|
554
|
-
// $group: Drawing
|
|
555
|
-
// $doc: Get the current drawing's height
|
|
556
|
-
// $return: The current drawing's height
|
|
557
|
-
'getDrawingHeight': (unused, options) => options.runtime.drawingHeight,
|
|
558
|
-
|
|
559
|
-
// $function: getDrawingWidth
|
|
524
|
+
// $function: drawWidth
|
|
560
525
|
// $group: Drawing
|
|
561
526
|
// $doc: Get the current drawing's width
|
|
562
527
|
// $return: The current drawing's width
|
|
563
|
-
'
|
|
564
|
-
|
|
565
|
-
// $function: getTextHeight
|
|
566
|
-
// $group: Drawing
|
|
567
|
-
// $doc: Compute the text's height to fit the width
|
|
568
|
-
// $arg text: The text
|
|
569
|
-
// $arg width: The width of the text. If 0, the default font size (in pixels) is returned.
|
|
570
|
-
// $return: The text's height
|
|
571
|
-
'getTextHeight': ([text, width], options) => (width > 0 ? width / (fontWidthRatio * text.length) : options.runtime.drawingFontSizePx),
|
|
572
|
-
|
|
573
|
-
// $function: getTextWidth
|
|
574
|
-
// $group: Drawing
|
|
575
|
-
// $doc: Compute the text's width
|
|
576
|
-
// $arg text: The text
|
|
577
|
-
// $arg fontSizePx: The text font size, in pixels
|
|
578
|
-
// $return: The text's width
|
|
579
|
-
'getTextWidth': ([text, fontSizePx]) => fontWidthRatio * fontSizePx * text.length,
|
|
580
|
-
|
|
581
|
-
// $function: setDrawingSize
|
|
582
|
-
// $group: Drawing
|
|
583
|
-
// $doc: Set the current drawing's size
|
|
584
|
-
// $arg width: The width of the drawing
|
|
585
|
-
// $arg height: The height of the drawing
|
|
586
|
-
'setDrawingSize': ([width, height], options) => {
|
|
587
|
-
const {runtime} = options;
|
|
588
|
-
runtime.drawingWidth = width;
|
|
589
|
-
runtime.drawingHeight = height;
|
|
590
|
-
runtime.setDrawing(true);
|
|
591
|
-
},
|
|
528
|
+
'drawWidth': (unused, options) => options.runtime.drawingWidth,
|
|
592
529
|
|
|
593
530
|
|
|
594
531
|
//
|
|
@@ -734,7 +671,75 @@ export const markdownScriptFunctions = {
|
|
|
734
671
|
// $group: Session Storage
|
|
735
672
|
// $doc: Remove a browser session storage key
|
|
736
673
|
// $arg key: The key string
|
|
737
|
-
'sessionStorageRemove': ([key], options) => options.window.sessionStorage.removeItem(key)
|
|
674
|
+
'sessionStorageRemove': ([key], options) => options.window.sessionStorage.removeItem(key),
|
|
675
|
+
|
|
676
|
+
|
|
677
|
+
//
|
|
678
|
+
// Window functions
|
|
679
|
+
//
|
|
680
|
+
|
|
681
|
+
// $function: windowHeight
|
|
682
|
+
// $group: Window
|
|
683
|
+
// $doc: Get the browser window's height
|
|
684
|
+
// $return: The browser window's height
|
|
685
|
+
'windowHeight': (unused, options) => options.window.innerHeight,
|
|
686
|
+
|
|
687
|
+
// $function: windowSetLocation
|
|
688
|
+
// $group: Window
|
|
689
|
+
// $doc: Navigate the browser window to a location URL
|
|
690
|
+
// $arg url: The new location URL
|
|
691
|
+
'windowSetLocation': ([location], options) => {
|
|
692
|
+
const {runtime} = options;
|
|
693
|
+
runtime.windowLocation = options.urlFn(location);
|
|
694
|
+
},
|
|
695
|
+
|
|
696
|
+
// $function: windowSetResize
|
|
697
|
+
// $group: Window
|
|
698
|
+
// $doc: Set the browser window resize event handler
|
|
699
|
+
// $arg callback: The window resize callback function
|
|
700
|
+
'windowSetResize': ([callback], options) => {
|
|
701
|
+
const {runtime} = options;
|
|
702
|
+
runtime.windowResize = async () => {
|
|
703
|
+
options.statementCount = 0;
|
|
704
|
+
try {
|
|
705
|
+
await callback([], options);
|
|
706
|
+
} catch ({message}) {
|
|
707
|
+
if ('logFn' in options && options.debug) {
|
|
708
|
+
options.logFn(`MarkdownUp: Error executing windowSetResize callback: ${message}`);
|
|
709
|
+
}
|
|
710
|
+
}
|
|
711
|
+
options.runtimeUpdateFn();
|
|
712
|
+
};
|
|
713
|
+
},
|
|
714
|
+
|
|
715
|
+
// $function: windowSetTimeout
|
|
716
|
+
// $group: Window
|
|
717
|
+
// $doc: Set the browser window timeout event handler
|
|
718
|
+
// $arg callback: The window timeout callback function
|
|
719
|
+
// $arg delay: The delay, in milliseconds, to ellapse before calling the timeout
|
|
720
|
+
'windowSetTimeout': ([callback, delay], options) => {
|
|
721
|
+
const {runtime} = options;
|
|
722
|
+
runtime.windowTimeout = [
|
|
723
|
+
async () => {
|
|
724
|
+
options.statementCount = 0;
|
|
725
|
+
try {
|
|
726
|
+
await callback([], options);
|
|
727
|
+
} catch ({message}) {
|
|
728
|
+
if ('logFn' in options && options.debug) {
|
|
729
|
+
options.logFn(`MarkdownUp: Error executing windowSetTimeout callback: ${message}`);
|
|
730
|
+
}
|
|
731
|
+
}
|
|
732
|
+
options.runtimeUpdateFn();
|
|
733
|
+
},
|
|
734
|
+
delay
|
|
735
|
+
];
|
|
736
|
+
},
|
|
737
|
+
|
|
738
|
+
// $function: windowWidth
|
|
739
|
+
// $group: Window
|
|
740
|
+
// $doc: Get the browser window's width
|
|
741
|
+
// $return: The browser window's width
|
|
742
|
+
'windowWidth': (unused, options) => options.window.innerWidth
|
|
738
743
|
};
|
|
739
744
|
|
|
740
745
|
|
|
@@ -787,7 +792,7 @@ function elementModelWrapCallbacks(elements, options) {
|
|
|
787
792
|
try {
|
|
788
793
|
await elementEventCallback(eventArgs, options);
|
|
789
794
|
} catch ({message}) {
|
|
790
|
-
if ('logFn' in options) {
|
|
795
|
+
if ('logFn' in options && options.debug) {
|
|
791
796
|
options.logFn(`MarkdownUp: Error executing elementModelRender callback: ${message}`);
|
|
792
797
|
}
|
|
793
798
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"type": "module",
|
|
3
3
|
"name": "markdown-up",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "2.0.1",
|
|
5
5
|
"description": "MarkdownUp is a Markdown viewer",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"markdown",
|
|
@@ -22,16 +22,16 @@
|
|
|
22
22
|
"test": "node --test test/"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"calc-script": "~
|
|
25
|
+
"calc-script": "~2.0",
|
|
26
26
|
"element-model": "~1.1",
|
|
27
27
|
"markdown-model": "~1.8",
|
|
28
28
|
"schema-markdown": "~1.2",
|
|
29
29
|
"schema-markdown-doc": "~1.6"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"c8": "~
|
|
33
|
-
"eslint": "~8.
|
|
32
|
+
"c8": "~8.0",
|
|
33
|
+
"eslint": "~8.44",
|
|
34
34
|
"jsdoc": "~4.0",
|
|
35
|
-
"jsdom": "~22.
|
|
35
|
+
"jsdom": "~22.1"
|
|
36
36
|
}
|
|
37
37
|
}
|