markdown-up 1.7.2 → 1.7.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/README.md +46 -27
- package/lib/app.js +333 -227
- package/lib/barChart.js +8 -6
- package/lib/csv.js +9 -0
- package/lib/data.js +44 -41
- package/lib/dataTable.js +8 -6
- package/lib/lineChart.js +10 -7
- package/lib/model.js +5 -11
- package/lib/script.js +329 -251
- package/lib/scriptLibrary.js +441 -0
- package/lib/util.js +8 -39
- package/package.json +9 -9
|
@@ -0,0 +1,441 @@
|
|
|
1
|
+
// Licensed under the MIT License
|
|
2
|
+
// https://github.com/craigahobbs/markdown-up/blob/main/LICENSE
|
|
3
|
+
|
|
4
|
+
import {escapeMarkdownLinkURL, escapeMarkdownText, markdownHeaderId} from 'markdown-model/lib/elements.js';
|
|
5
|
+
import {getMarkdownTitle, parseMarkdown} from 'markdown-model/lib/parser.js';
|
|
6
|
+
import {validateType, validateTypeModel} from 'schema-markdown/lib/schema.js';
|
|
7
|
+
import {SchemaMarkdownParser} from 'schema-markdown/lib/parser.js';
|
|
8
|
+
import {typeModel} from 'schema-markdown/lib/typeModel.js';
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
/* eslint-disable id-length, max-len */
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
// Constants
|
|
15
|
+
const fontWidthRatio = 0.6;
|
|
16
|
+
const pixelsPerPoint = 4 / 3;
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
// Helper function to flatten and line-split nested arrays of strings
|
|
20
|
+
function flattenAndSplitLines(lines) {
|
|
21
|
+
return lines.flat().reduce(
|
|
22
|
+
(result, line) => {
|
|
23
|
+
result.push(...line.split(rLineSplit));
|
|
24
|
+
return result;
|
|
25
|
+
},
|
|
26
|
+
[]
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const rLineSplit = /\r?\n/;
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
// markdown-script library functions
|
|
34
|
+
export const markdownScriptFunctions = {
|
|
35
|
+
//
|
|
36
|
+
// Document functions
|
|
37
|
+
//
|
|
38
|
+
|
|
39
|
+
// $function: documentReset
|
|
40
|
+
// $group: Document
|
|
41
|
+
// $doc: Reset the document. This is useful within callback functions that re-render the document.
|
|
42
|
+
'documentReset': (unused, options) => options.runtime.documentReset(),
|
|
43
|
+
|
|
44
|
+
// $function: documentURL
|
|
45
|
+
// $group: Document
|
|
46
|
+
// $doc: Fix-up relative URLs
|
|
47
|
+
// $arg url: The URL
|
|
48
|
+
// $return: The fixed-up URL
|
|
49
|
+
'documentURL': ([url], options) => options.urlFn(url),
|
|
50
|
+
|
|
51
|
+
// $function: getDocumentFontSize
|
|
52
|
+
// $group: Document
|
|
53
|
+
// $doc: Get the document font size
|
|
54
|
+
// $return: The document font size, in pixels
|
|
55
|
+
'getDocumentFontSize': (unused, options) => options.fontSize * pixelsPerPoint,
|
|
56
|
+
|
|
57
|
+
// $function: getDocumentInputValue
|
|
58
|
+
// $group: Document
|
|
59
|
+
// $doc: Get an input element's value
|
|
60
|
+
// $arg id: The input element ID
|
|
61
|
+
// $return: The input element value or null if the element does not exist
|
|
62
|
+
'getDocumentInputValue': ([id], options) => {
|
|
63
|
+
const element = options.window.document.getElementById(id) ?? null;
|
|
64
|
+
return (element !== null ? (element.value ?? null) : null);
|
|
65
|
+
},
|
|
66
|
+
|
|
67
|
+
// $function: getWindowHeight
|
|
68
|
+
// $group: Document
|
|
69
|
+
// $doc: Get the browser window's height
|
|
70
|
+
// $return: The browser window's height
|
|
71
|
+
'getWindowHeight': (unused, options) => options.window.innerHeight,
|
|
72
|
+
|
|
73
|
+
// $function: getWindowWidth
|
|
74
|
+
// $group: Document
|
|
75
|
+
// $doc: Get the browser window's width
|
|
76
|
+
// $return: The browser window's width
|
|
77
|
+
'getWindowWidth': (unused, options) => options.window.innerWidth,
|
|
78
|
+
|
|
79
|
+
// $function: setDocumentFocus
|
|
80
|
+
// $group: Document
|
|
81
|
+
// $doc: Set focus to an element
|
|
82
|
+
// $arg id: The element ID
|
|
83
|
+
'setDocumentFocus': ([id], options) => options.runtime.setDocumentFocus(id),
|
|
84
|
+
|
|
85
|
+
// $function: setDocumentTitle
|
|
86
|
+
// $group: Document
|
|
87
|
+
// $doc: Set the document title
|
|
88
|
+
// $arg title: The document title string
|
|
89
|
+
'setDocumentTitle': ([title], options) => options.runtime.setDocumentTitle(title),
|
|
90
|
+
|
|
91
|
+
// $function: setWindowLocation
|
|
92
|
+
// $group: Document
|
|
93
|
+
// $doc: Navigate the browser window to a location URL
|
|
94
|
+
// $arg url: The new location URL
|
|
95
|
+
'setWindowLocation': ([location], options) => options.runtime.setWindowLocation(location),
|
|
96
|
+
|
|
97
|
+
// $function: setWindowResize
|
|
98
|
+
// $group: Document
|
|
99
|
+
// $doc: Set the browser window resize event handler
|
|
100
|
+
// $arg callback: The window resize callback function
|
|
101
|
+
'setWindowResize': ([callback], options) => options.runtime.setWindowResize(callback),
|
|
102
|
+
|
|
103
|
+
// $function: setWindowTimeout
|
|
104
|
+
// $group: Document
|
|
105
|
+
// $doc: Set the browser window timeout event handler
|
|
106
|
+
// $arg callback: The window timeout callback function
|
|
107
|
+
// $arg delay: The delay, in milliseconds, to ellapse before calling the timeout
|
|
108
|
+
'setWindowTimeout': ([callback, delay], options) => options.runtime.setWindowTimeout(callback, delay),
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
//
|
|
112
|
+
// Drawing functions
|
|
113
|
+
//
|
|
114
|
+
|
|
115
|
+
// $function: drawArc
|
|
116
|
+
// $group: Drawing
|
|
117
|
+
// $doc: Draw an arc curve from the current point to the end point
|
|
118
|
+
// $arg rx: The arc ellipse's x-radius
|
|
119
|
+
// $arg ry: The arc ellipse's y-radius
|
|
120
|
+
// $arg angle: The rotation (in degrees) of the ellipse relative to the x-axis
|
|
121
|
+
// $arg largeArcFlag: Either large arc (1) or small arc (0)
|
|
122
|
+
// $arg sweepFlag: Either clockwise turning arc (1) or counterclockwise turning arc (0)
|
|
123
|
+
// $arg x: The x-coordinate of the end point
|
|
124
|
+
// $arg y: The y-coordinate of the end point
|
|
125
|
+
'drawArc': ([rx, ry, angle, largeArcFlag, sweepFlag, x, y], options) => (
|
|
126
|
+
options.runtime.drawArc(rx, ry, angle, largeArcFlag, sweepFlag, x, y)
|
|
127
|
+
),
|
|
128
|
+
|
|
129
|
+
// $function: drawCircle
|
|
130
|
+
// $group: Drawing
|
|
131
|
+
// $doc: Draw a circle
|
|
132
|
+
// $arg cx: The x-coordinate of the center of the circle
|
|
133
|
+
// $arg cy: The y-coordinate of the center of the circle
|
|
134
|
+
// $arg r: The radius of the circle
|
|
135
|
+
'drawCircle': ([cx, cy, r], options) => options.runtime.drawCircle(cx, cy, r),
|
|
136
|
+
|
|
137
|
+
// $function: drawClose
|
|
138
|
+
// $group: Drawing
|
|
139
|
+
// $doc: Close the current drawing path
|
|
140
|
+
'drawClose': (unused, options) => options.runtime.drawClose(),
|
|
141
|
+
|
|
142
|
+
// $function: drawEllipse
|
|
143
|
+
// $group: Drawing
|
|
144
|
+
// $doc: Draw an ellipse
|
|
145
|
+
// $arg cx: The x-coordinate of the center of the ellipse
|
|
146
|
+
// $arg cy: The y-coordinate of the center of the ellipse
|
|
147
|
+
// $arg rx: The x-radius of the ellipse
|
|
148
|
+
// $arg ry: The y-radius of the ellipse
|
|
149
|
+
'drawEllipse': ([cx, cy, rx, ry], options) => options.runtime.drawEllipse(cx, cy, rx, ry),
|
|
150
|
+
|
|
151
|
+
// $function: drawHLine
|
|
152
|
+
// $group: Drawing
|
|
153
|
+
// $doc: Draw a horizontal line from the current point to the end point
|
|
154
|
+
// $arg x: The x-coordinate of the end point
|
|
155
|
+
'drawHLine': ([x], options) => options.runtime.drawHLine(x),
|
|
156
|
+
|
|
157
|
+
// $function: drawImage
|
|
158
|
+
// $group: Drawing
|
|
159
|
+
// $doc: Draw an image
|
|
160
|
+
// $arg x: The x-coordinate of the center of the image
|
|
161
|
+
// $arg y: The y-coordinate of the center of the image
|
|
162
|
+
// $arg width: The width of the image
|
|
163
|
+
// $arg height: The height of the image
|
|
164
|
+
// $arg href: The image resource URL
|
|
165
|
+
'drawImage': ([x, y, width, height, href], options) => options.runtime.drawImage(x, y, width, height, href),
|
|
166
|
+
|
|
167
|
+
// $function: drawLine
|
|
168
|
+
// $group: Drawing
|
|
169
|
+
// $doc: Draw a line from the current point to the end point
|
|
170
|
+
// $arg x: The x-coordinate of the end point
|
|
171
|
+
// $arg y: The y-coordinate of the end point
|
|
172
|
+
'drawLine': ([x, y], options) => options.runtime.drawLine(x, y),
|
|
173
|
+
|
|
174
|
+
// $function: drawMove
|
|
175
|
+
// $group: Drawing
|
|
176
|
+
// $doc: Move the path's drawing point
|
|
177
|
+
// $arg x: The x-coordinate of the new drawing point
|
|
178
|
+
// $arg y: The y-coordinate of the new drawing point
|
|
179
|
+
'drawMove': ([x, y], options) => options.runtime.drawMove(x, y),
|
|
180
|
+
|
|
181
|
+
// $function: drawOnClick
|
|
182
|
+
// $group: Drawing
|
|
183
|
+
// $doc: Set the most recent drawing object's on-click event handler
|
|
184
|
+
// $arg callback: The on-click event callback function (x, y)
|
|
185
|
+
'drawOnClick': ([callback], options) => options.runtime.drawOnClick(callback),
|
|
186
|
+
|
|
187
|
+
// $function: drawRect
|
|
188
|
+
// $group: Drawing
|
|
189
|
+
// $doc: Draw a rectangle
|
|
190
|
+
// $arg x: The x-coordinate of the top-left of the rectangle
|
|
191
|
+
// $arg y: The y-coordinate of the top-left of the rectangle
|
|
192
|
+
// $arg width: The width of the rectangle
|
|
193
|
+
// $arg height: The height of the rectangle
|
|
194
|
+
// $arg rx: Optional (default is null). The horizontal corner radius of the rectangle.
|
|
195
|
+
// $arg ry: Optional (default is null). The vertical corner radius of the rectangle.
|
|
196
|
+
'drawRect': ([x, y, width, height, rx = null, ry = null], options) => options.runtime.drawRect(x, y, width, height, rx, ry),
|
|
197
|
+
|
|
198
|
+
// $function: drawStyle
|
|
199
|
+
// $group: Drawing
|
|
200
|
+
// $doc: Set the current drawing styles
|
|
201
|
+
// $arg stroke: Optional (default is 'black'). The stroke color.
|
|
202
|
+
// $arg strokeWidth: Optional (default is 1). The stroke width.
|
|
203
|
+
// $arg fill: Optional (default is 'none'). The fill color.
|
|
204
|
+
// $arg strokeDashArray: Optional (default is 'none'). The stroke
|
|
205
|
+
// $arg strokeDashArray: [dash array](https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/stroke-dasharray#usage_notes).
|
|
206
|
+
'drawStyle': ([stroke = 'black', strokeWidth = 1, fill = 'none', strokeDashArray = 'none'], options) => (
|
|
207
|
+
options.runtime.drawStyle(stroke, strokeWidth, fill, strokeDashArray)
|
|
208
|
+
),
|
|
209
|
+
|
|
210
|
+
// $function: drawText
|
|
211
|
+
// $group: Drawing
|
|
212
|
+
// $doc: Draw text
|
|
213
|
+
// $arg text: The text to draw
|
|
214
|
+
// $arg x: The x-coordinate of the text
|
|
215
|
+
// $arg y: The y-coordinate of the text
|
|
216
|
+
// $arg textAnchor: Optional (default is 'middle'). The
|
|
217
|
+
// $arg textAnchor: [text anchor](https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/text-anchor#usage_notes) style.
|
|
218
|
+
// $arg dominantBaseline: Optional (default is 'middle'). The
|
|
219
|
+
// $arg dominantBaseline: [dominant baseline](https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/dominant-baseline#usage_notes) style.
|
|
220
|
+
'drawText': ([text, x, y, textAnchor = 'middle', dominantBaseline = 'middle'], options) => (
|
|
221
|
+
options.runtime.drawText(text, x, y, textAnchor, dominantBaseline)
|
|
222
|
+
),
|
|
223
|
+
|
|
224
|
+
// $function: drawTextStyle
|
|
225
|
+
// $group: Drawing
|
|
226
|
+
// $doc: Set the current text drawing styles
|
|
227
|
+
// $arg fontSizePx: Optional (default is null, the default font size). The text font size, in pixels.
|
|
228
|
+
// $arg textFill: Optional (default is 'black'). The text fill color.
|
|
229
|
+
// $arg bold: Optional (default is false). If true, text is bold.
|
|
230
|
+
// $arg italic: Optional (default is false). If true, text is italic.
|
|
231
|
+
// $arg fontFamily: Optional (default is null, the default font family). The text font family.
|
|
232
|
+
'drawTextStyle': ([fontSizePx = null, textFill = 'black', bold = false, italic = false, fontFamily = null], options) => (
|
|
233
|
+
options.runtime.drawTextStyle(fontSizePx, textFill, bold, italic, fontFamily)
|
|
234
|
+
),
|
|
235
|
+
|
|
236
|
+
// $function: drawVLine
|
|
237
|
+
// $group: Drawing
|
|
238
|
+
// $doc: Draw a vertical line from the current point to the end point
|
|
239
|
+
// $arg y: The y-coordinate of the end point
|
|
240
|
+
'drawVLine': ([y], options) => options.runtime.drawVLine(y),
|
|
241
|
+
|
|
242
|
+
// $function: getDrawingHeight
|
|
243
|
+
// $group: Drawing
|
|
244
|
+
// $doc: Get the current drawing's height
|
|
245
|
+
// $return: The current drawing's height
|
|
246
|
+
'getDrawingHeight': (unused, options) => options.runtime.drawingHeight,
|
|
247
|
+
|
|
248
|
+
// $function: getDrawingWidth
|
|
249
|
+
// $group: Drawing
|
|
250
|
+
// $doc: Get the current drawing's width
|
|
251
|
+
// $return: The current drawing's width
|
|
252
|
+
'getDrawingWidth': (unused, options) => options.runtime.drawingWidth,
|
|
253
|
+
|
|
254
|
+
// $function: getTextHeight
|
|
255
|
+
// $group: Drawing
|
|
256
|
+
// $doc: Compute the text's height to fit the width
|
|
257
|
+
// $arg text: The text
|
|
258
|
+
// $arg width: The width of the text. If 0, the default font size (in pixels) is returned.
|
|
259
|
+
// $return: The text's height
|
|
260
|
+
'getTextHeight': ([text, width], options) => (width > 0 ? width / (fontWidthRatio * text.length) : options.runtime.drawingFontSizePx),
|
|
261
|
+
|
|
262
|
+
// $function: getTextWidth
|
|
263
|
+
// $group: Drawing
|
|
264
|
+
// $doc: Compute the text's width
|
|
265
|
+
// $arg text: The text
|
|
266
|
+
// $arg fontSizePx: The text font size, in pixels
|
|
267
|
+
// $return: The text's width
|
|
268
|
+
'getTextWidth': ([text, fontSizePx]) => fontWidthRatio * fontSizePx * text.length,
|
|
269
|
+
|
|
270
|
+
// $function: setDrawingSize
|
|
271
|
+
// $group: Drawing
|
|
272
|
+
// $doc: Set the current drawing's size
|
|
273
|
+
// $arg width: The width of the drawing
|
|
274
|
+
// $arg height: The height of the drawing
|
|
275
|
+
'setDrawingSize': ([width, height], options) => options.runtime.setDrawingSize(width, height),
|
|
276
|
+
|
|
277
|
+
|
|
278
|
+
//
|
|
279
|
+
// Element Model functions
|
|
280
|
+
//
|
|
281
|
+
|
|
282
|
+
// $function: elementModelRender
|
|
283
|
+
// $group: Element Model
|
|
284
|
+
// $doc: Render an [element model](https://github.com/craigahobbs/element-model#readme)
|
|
285
|
+
// $arg element: The [element model](https://github.com/craigahobbs/element-model#readme)
|
|
286
|
+
'elementModelRender': ([elements], options) => options.runtime.elementModelRender(elements),
|
|
287
|
+
|
|
288
|
+
|
|
289
|
+
//
|
|
290
|
+
// Local storage functions
|
|
291
|
+
//
|
|
292
|
+
|
|
293
|
+
// $function: localStorageClear
|
|
294
|
+
// $group: Local Storage
|
|
295
|
+
// $doc: Clear all keys from the browser's local storage
|
|
296
|
+
'localStorageClear': (unused, options) => options.window.localStorage.clear(),
|
|
297
|
+
|
|
298
|
+
// $function: localStorageGet
|
|
299
|
+
// $group: Local Storage
|
|
300
|
+
// $doc: Get a browser local storage key's value
|
|
301
|
+
// $arg key: The key string
|
|
302
|
+
// $return: The local storage value string or null if the key does not exist
|
|
303
|
+
'localStorageGet': ([key], options) => options.window.localStorage.getItem(key),
|
|
304
|
+
|
|
305
|
+
// $function: localStorageSet
|
|
306
|
+
// $group: Local Storage
|
|
307
|
+
// $doc: Set a browser local storage key's value
|
|
308
|
+
// $arg key: The key string
|
|
309
|
+
// $arg value: The value string
|
|
310
|
+
'localStorageSet': ([key, value], options) => options.window.localStorage.setItem(key, value),
|
|
311
|
+
|
|
312
|
+
// $function: localStorageRemove
|
|
313
|
+
// $group: Local Storage
|
|
314
|
+
// $doc: Remove a browser local storage key
|
|
315
|
+
// $arg key: The key string
|
|
316
|
+
'localStorageRemove': ([key], options) => options.window.localStorage.removeItem(key),
|
|
317
|
+
|
|
318
|
+
|
|
319
|
+
//
|
|
320
|
+
// Markdown functions
|
|
321
|
+
//
|
|
322
|
+
|
|
323
|
+
// $function: markdownEscape
|
|
324
|
+
// $group: Markdown
|
|
325
|
+
// $doc: Escape text for inclusion in Markdown text
|
|
326
|
+
// $arg text: The text to escape
|
|
327
|
+
// $return: The escaped text
|
|
328
|
+
'markdownEscape': ([text]) => escapeMarkdownText(text),
|
|
329
|
+
|
|
330
|
+
// $function: markdownEscapeLinkURL
|
|
331
|
+
// $group: Markdown
|
|
332
|
+
// $doc: Escape a URL for inclusion in a Markdown link
|
|
333
|
+
// $arg text: The URL to escape
|
|
334
|
+
// $return: The escaped URL
|
|
335
|
+
'markdownEscapeLinkURL': ([url]) => escapeMarkdownLinkURL(url),
|
|
336
|
+
|
|
337
|
+
// $function: markdownHeaderId
|
|
338
|
+
// $group: Markdown
|
|
339
|
+
// $doc: Compute the Markdown header element ID for some text
|
|
340
|
+
// $arg text: The text
|
|
341
|
+
// $return: The header element ID
|
|
342
|
+
'markdownHeaderId': ([text]) => markdownHeaderId(text),
|
|
343
|
+
|
|
344
|
+
// $function: markdownParse
|
|
345
|
+
// $group: Markdown
|
|
346
|
+
// $doc: Parse Markdown text
|
|
347
|
+
// $arg lines: The Markdown text lines (may contain nested arrays of un-split lines)
|
|
348
|
+
// $return: The [Markdown model](https://craigahobbs.github.io/markdown-model/model/#var.vName='Markdown')
|
|
349
|
+
'markdownParse': (lines) => parseMarkdown(lines.flat()),
|
|
350
|
+
|
|
351
|
+
// $function: markdownPrint
|
|
352
|
+
// $group: Markdown
|
|
353
|
+
// $doc: Render Markdown text
|
|
354
|
+
// $arg lines: The Markdown text lines (may contain nested arrays of un-split lines)
|
|
355
|
+
'markdownPrint': (lines, options) => options.runtime.markdownPrint(lines),
|
|
356
|
+
|
|
357
|
+
// $function: markdownTitle
|
|
358
|
+
// $group: Markdown
|
|
359
|
+
// $doc: Compute the title of a [Markdown model](https://craigahobbs.github.io/markdown-model/model/#var.vName='Markdown')
|
|
360
|
+
// $arg markdownModel: The [Markdown model](https://craigahobbs.github.io/markdown-model/model/#var.vName='Markdown')
|
|
361
|
+
// $return: The Markdown title or null if there is no title
|
|
362
|
+
'markdownTitle': ([markdownModel]) => getMarkdownTitle(markdownModel),
|
|
363
|
+
|
|
364
|
+
|
|
365
|
+
//
|
|
366
|
+
// Schema functions
|
|
367
|
+
//
|
|
368
|
+
|
|
369
|
+
// $function: schemaParse
|
|
370
|
+
// $group: Schema
|
|
371
|
+
// $doc: Parse the [Schema Markdown](https://craigahobbs.github.io/schema-markdown/schema-markdown.html) text
|
|
372
|
+
// $arg lines: The [Schema Markdown](https://craigahobbs.github.io/schema-markdown/schema-markdown.html)
|
|
373
|
+
// $arg lines: text lines (may contain nested arrays of un-split lines)
|
|
374
|
+
// $return: The schema's [type model](https://craigahobbs.github.io/schema-markdown-doc/doc/#var.vName='Types')
|
|
375
|
+
'schemaParse': (lines) => {
|
|
376
|
+
const parser = new SchemaMarkdownParser();
|
|
377
|
+
parser.parse(flattenAndSplitLines(lines));
|
|
378
|
+
return parser.types;
|
|
379
|
+
},
|
|
380
|
+
|
|
381
|
+
// $function: schemaPrint
|
|
382
|
+
// $group: Schema
|
|
383
|
+
// $doc: Render a schema type's documentation
|
|
384
|
+
// $arg types: The [type model](https://craigahobbs.github.io/schema-markdown-doc/doc/#var.vName='Types')
|
|
385
|
+
// $arg typeName: The type name
|
|
386
|
+
// $arg actionURLs: Optional (default is null). The
|
|
387
|
+
// $arg actionURLs: [action URL overrides](https://craigahobbs.github.io/schema-markdown-doc/doc/#var.vName='ActionURL').
|
|
388
|
+
'schemaPrint': ([types, typeName, actionURLs = null], options) => options.runtime.schemaPrint(types, typeName, actionURLs),
|
|
389
|
+
|
|
390
|
+
// $function: schemaTypeModel
|
|
391
|
+
// $group: Schema
|
|
392
|
+
// $doc: Get the [Schema Markdown Type Model](https://craigahobbs.github.io/schema-markdown-doc/doc/#var.vName='Types')
|
|
393
|
+
// $return: The [Schema Markdown Type Model](https://craigahobbs.github.io/schema-markdown-doc/doc/#var.vName='Types')
|
|
394
|
+
'schemaTypeModel': () => typeModel,
|
|
395
|
+
|
|
396
|
+
// $function: schemaValidate
|
|
397
|
+
// $group: Schema
|
|
398
|
+
// $doc: Validate an object to a schema type
|
|
399
|
+
// $arg types: The [type model](https://craigahobbs.github.io/schema-markdown-doc/doc/#var.vName='Types')
|
|
400
|
+
// $arg typeName: The type name
|
|
401
|
+
// $arg value: The object to validate
|
|
402
|
+
// $return: The validated object or null if validation fails
|
|
403
|
+
'schemaValidate': ([types, typeName, value]) => validateType(types, typeName, value),
|
|
404
|
+
|
|
405
|
+
// $function: schemaValidateTypeModel
|
|
406
|
+
// $group: Schema
|
|
407
|
+
// $doc: Validate a [Schema Markdown Type Model](https://craigahobbs.github.io/schema-markdown-doc/doc/#var.vName='Types')
|
|
408
|
+
// $arg types: The [type model](https://craigahobbs.github.io/schema-markdown-doc/doc/#var.vName='Types') to validate
|
|
409
|
+
// $return: The validated [type model](https://craigahobbs.github.io/schema-markdown-doc/doc/#var.vName='Types')
|
|
410
|
+
'schemaValidateTypeModel': ([types]) => validateTypeModel(types),
|
|
411
|
+
|
|
412
|
+
|
|
413
|
+
//
|
|
414
|
+
// Session storage functions
|
|
415
|
+
//
|
|
416
|
+
|
|
417
|
+
// $function: sessionStorageClear
|
|
418
|
+
// $group: Session Storage
|
|
419
|
+
// $doc: Clear all keys from the browser's session storage
|
|
420
|
+
'sessionStorageClear': (unused, options) => options.window.sessionStorage.clear(),
|
|
421
|
+
|
|
422
|
+
// $function: sessionStorageGet
|
|
423
|
+
// $group: Session Storage
|
|
424
|
+
// $doc: Get a browser session storage key's value
|
|
425
|
+
// $arg key: The key string
|
|
426
|
+
// $return: The session storage value string or null if the key does not exist
|
|
427
|
+
'sessionStorageGet': ([key], options) => options.window.sessionStorage.getItem(key),
|
|
428
|
+
|
|
429
|
+
// $function: sessionStorageSet
|
|
430
|
+
// $group: Session Storage
|
|
431
|
+
// $doc: Set a browser session storage key's value
|
|
432
|
+
// $arg key: The key string
|
|
433
|
+
// $arg value: The value string
|
|
434
|
+
'sessionStorageSet': ([key, value], options) => options.window.sessionStorage.setItem(key, value),
|
|
435
|
+
|
|
436
|
+
// $function: sessionStorageRemove
|
|
437
|
+
// $group: Session Storage
|
|
438
|
+
// $doc: Remove a browser session storage key
|
|
439
|
+
// $arg key: The key string
|
|
440
|
+
'sessionStorageRemove': ([key], options) => options.window.sessionStorage.removeItem(key)
|
|
441
|
+
};
|
package/lib/util.js
CHANGED
|
@@ -7,38 +7,7 @@ import {decodeQueryString} from 'schema-markdown/lib/encode.js';
|
|
|
7
7
|
import {renderElements} from 'element-model/lib/elementModel.js';
|
|
8
8
|
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* The markdown script code block function options (based on
|
|
14
|
-
* [calc-script's options]{@link https://craigahobbs.github.io/calc-script/module-lib_runtime.html#~ExecuteScriptOptions}).
|
|
15
|
-
*
|
|
16
|
-
* @typedef {Object} MarkdownScriptOptions
|
|
17
|
-
* @property {number} [fontSize] - The chart font size, in points
|
|
18
|
-
* @property {Object} [localStorage] - The localStorage object
|
|
19
|
-
* @property {module:lib/util~NavigateTimeoutFn} [navigateTimeoutFn] - The navigate timeout function
|
|
20
|
-
* @property {Object} [params] - The hash parameters object
|
|
21
|
-
* @property {module:lib/script.MarkdownScriptRuntime} [runtime] - The markdown-script runtime state
|
|
22
|
-
* @property {Object} [sessionStorage] - The sessionStorage object
|
|
23
|
-
* @property {module:lib/util~URLFn} [urlFn] - The URL modifier function
|
|
24
|
-
* @property {Object} [variables] - The map of variable name to chart variable value
|
|
25
|
-
*/
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* A URL modifier function
|
|
29
|
-
*
|
|
30
|
-
* @callback URLFn
|
|
31
|
-
* @param {string} url - The URL
|
|
32
|
-
* @returns {string} The modified URL
|
|
33
|
-
*/
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* A navigate timeout function
|
|
37
|
-
*
|
|
38
|
-
* @callback NavigateTimeoutFn
|
|
39
|
-
* @param {string} url - The URL to navigate to
|
|
40
|
-
* @param {number} delay - The navigation delay, in milliseconds
|
|
41
|
-
*/
|
|
10
|
+
/* c8 ignore start */
|
|
42
11
|
|
|
43
12
|
|
|
44
13
|
// The categorical color palette
|
|
@@ -132,11 +101,11 @@ export function parameterValue(param, minValue, maxValue) {
|
|
|
132
101
|
|
|
133
102
|
|
|
134
103
|
// Generic code block helper function
|
|
135
|
-
export function chartCodeBlock(
|
|
104
|
+
export function chartCodeBlock(codeBlock, options, validationFn, renderFn) {
|
|
136
105
|
// Decode and validate the chart model
|
|
137
|
-
let
|
|
106
|
+
let chart;
|
|
138
107
|
try {
|
|
139
|
-
|
|
108
|
+
chart = validationFn(decodeChartLines(codeBlock.lines));
|
|
140
109
|
} catch ({message}) {
|
|
141
110
|
return {'html': 'p', 'elem': {'html': 'pre', 'elem': {'text': `Error: ${message}`}}};
|
|
142
111
|
}
|
|
@@ -144,15 +113,15 @@ export function chartCodeBlock(language, lines, options, validationFn, renderFn)
|
|
|
144
113
|
// Render the chart asynchronously
|
|
145
114
|
return {
|
|
146
115
|
'html': 'p',
|
|
147
|
-
'elem': !('width' in
|
|
116
|
+
'elem': !('width' in chart) ? null : {
|
|
148
117
|
'svg': 'svg',
|
|
149
118
|
'attr': {
|
|
150
|
-
'width':
|
|
151
|
-
'height':
|
|
119
|
+
'width': chart.width,
|
|
120
|
+
'height': chart.height
|
|
152
121
|
}
|
|
153
122
|
},
|
|
154
123
|
'callback': (parent) => {
|
|
155
|
-
renderFn(
|
|
124
|
+
renderFn(chart, options).
|
|
156
125
|
then((elements) => {
|
|
157
126
|
renderElements(parent, elements);
|
|
158
127
|
}).
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"type": "module",
|
|
3
3
|
"name": "markdown-up",
|
|
4
|
-
"version": "1.7.
|
|
5
|
-
"description": "
|
|
4
|
+
"version": "1.7.5",
|
|
5
|
+
"description": "MarkdownUp is a Markdown viewer",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"markdown",
|
|
8
8
|
"viewer"
|
|
@@ -22,17 +22,17 @@
|
|
|
22
22
|
"test": "ava -v test/"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"calc-script": "~
|
|
25
|
+
"calc-script": "~1.1",
|
|
26
26
|
"element-model": "~1.1",
|
|
27
|
-
"markdown-model": "~1.
|
|
27
|
+
"markdown-model": "~1.6",
|
|
28
28
|
"schema-markdown": "~1.1",
|
|
29
|
-
"schema-markdown-doc": "~1.
|
|
29
|
+
"schema-markdown-doc": "~1.5"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"ava": "~4.
|
|
33
|
-
"c8": "~7.
|
|
34
|
-
"eslint": "~8.
|
|
32
|
+
"ava": "~4.3",
|
|
33
|
+
"c8": "~7.12",
|
|
34
|
+
"eslint": "~8.21",
|
|
35
35
|
"jsdoc": "~3.6",
|
|
36
|
-
"jsdom": "~
|
|
36
|
+
"jsdom": "~20.0"
|
|
37
37
|
}
|
|
38
38
|
}
|