markdown-up 1.7.4 → 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 +4 -2
- package/lib/app.js +85 -79
- package/lib/barChart.js +5 -2
- package/lib/csv.js +9 -0
- package/lib/data.js +19 -12
- package/lib/dataTable.js +5 -2
- package/lib/lineChart.js +7 -3
- package/lib/script.js +72 -392
- package/lib/scriptLibrary.js +441 -0
- package/lib/util.js +1 -28
- package/package.json +6 -6
package/lib/script.js
CHANGED
|
@@ -3,43 +3,70 @@
|
|
|
3
3
|
|
|
4
4
|
/** @module lib/script */
|
|
5
5
|
|
|
6
|
-
import {encodeMarkdownText, getMarkdownTitle, parseMarkdown} from 'markdown-model/lib/parser.js';
|
|
7
|
-
import {markdownElements, markdownHeaderId} from 'markdown-model/lib/elements.js';
|
|
8
|
-
import {validateType, validateTypeModel} from 'schema-markdown/lib/schema.js';
|
|
9
|
-
import {SchemaMarkdownParser} from 'schema-markdown/lib/parser.js';
|
|
10
6
|
import {encodeQueryString} from 'schema-markdown/lib/encode.js';
|
|
11
7
|
import {executeScriptAsync} from 'calc-script/lib/runtimeAsync.js';
|
|
8
|
+
import {markdownElements} from 'markdown-model/lib/elements.js';
|
|
9
|
+
import {parseMarkdown} from 'markdown-model/lib/parser.js';
|
|
12
10
|
import {parseScript} from 'calc-script/lib/parser.js';
|
|
13
11
|
import {schemaMarkdownDoc} from 'schema-markdown-doc/lib/schemaMarkdownDoc.js';
|
|
14
|
-
import {typeModel} from 'schema-markdown/lib/typeModel.js';
|
|
15
12
|
import {validateElements} from 'element-model/lib/elementModel.js';
|
|
16
13
|
|
|
17
14
|
|
|
15
|
+
/* eslint-disable id-length, max-len */
|
|
16
|
+
|
|
17
|
+
|
|
18
18
|
/**
|
|
19
|
-
* markdown-script code block function
|
|
19
|
+
* The markdown-script code block function options (based on
|
|
20
|
+
* [calc-script's options]{@link https://craigahobbs.github.io/calc-script/module-lib_runtime.html#~ExecuteScriptOptions}).
|
|
21
|
+
*
|
|
22
|
+
* @typedef {Object} MarkdownScriptOptions
|
|
23
|
+
* @property {number} fontSize - The font size, in points
|
|
24
|
+
* @property {Object} params - The hash parameters object
|
|
25
|
+
* @property {Object} runtime - The [markdown-script runtime state]{@link module:lib/script.MarkdownScriptRuntime}
|
|
26
|
+
* @property {Object} [variables] - The map of variable name to variable value
|
|
27
|
+
* @property {Object} window - The web browser window object
|
|
28
|
+
* @property {function} runtimeUpdateFn - The [runtime update callback function]{@link module:lib/util~MarkdownScriptRuntimeUpdateFn}
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* A runtime update callback function
|
|
33
|
+
*
|
|
34
|
+
* @callback MarkdownScriptRuntimeUpdateFn
|
|
35
|
+
*/
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* A URL modifier function
|
|
39
|
+
*
|
|
40
|
+
* @callback URLFn
|
|
41
|
+
* @param {string} url - The URL
|
|
42
|
+
* @returns {string} The modified URL
|
|
43
|
+
*/
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* The markdown-script code block function
|
|
20
48
|
*
|
|
21
49
|
* @async
|
|
22
50
|
* @param {object} codeBlock - The code block model
|
|
23
|
-
* @param {Object} options - The [markdown-script options]{@link module:lib/
|
|
51
|
+
* @param {Object} options - The [markdown-script options]{@link module:lib/script~MarkdownScriptOptions}
|
|
24
52
|
* @returns {Object} The generated element model
|
|
25
53
|
*/
|
|
26
54
|
export async function markdownScriptCodeBlock(codeBlock, options) {
|
|
27
55
|
// Add the options variables to the runtime's globals
|
|
28
|
-
const {runtime} = options;
|
|
29
56
|
if ('variables' in options) {
|
|
30
|
-
Object.assign(
|
|
57
|
+
Object.assign(options.globals, options.variables);
|
|
31
58
|
}
|
|
32
59
|
|
|
33
60
|
// Execute the calculation script
|
|
34
61
|
let errorMessage = null;
|
|
35
62
|
try {
|
|
36
|
-
await executeScriptAsync(parseScript(codeBlock.lines, codeBlock.startLineNumber + 1),
|
|
63
|
+
await executeScriptAsync(parseScript(codeBlock.lines, codeBlock.startLineNumber + 1), options);
|
|
37
64
|
} catch ({message}) {
|
|
38
65
|
errorMessage = message;
|
|
39
66
|
}
|
|
40
67
|
|
|
41
68
|
// Reset the runtime
|
|
42
|
-
let elements = runtime.resetElements();
|
|
69
|
+
let elements = options.runtime.resetElements();
|
|
43
70
|
|
|
44
71
|
// If an error occurred, render the error message
|
|
45
72
|
if (errorMessage !== null) {
|
|
@@ -53,23 +80,17 @@ export async function markdownScriptCodeBlock(codeBlock, options) {
|
|
|
53
80
|
// markdown-script runtime constants
|
|
54
81
|
const defaultDrawingWidth = 300;
|
|
55
82
|
const defaultDrawingHeight = 200;
|
|
56
|
-
const svgPrecision = 8;
|
|
57
|
-
const fontWidthRatio = 0.6;
|
|
58
|
-
const pixelsPerPoint = 4 / 3;
|
|
59
83
|
const defaultFontFamily = 'Arial, Helvetica, sans-serif';
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
// Line-splitting regex
|
|
63
|
-
const rLineSplit = /\r?\n/;
|
|
84
|
+
const pixelsPerPoint = 4 / 3;
|
|
85
|
+
const svgPrecision = 8;
|
|
64
86
|
|
|
65
87
|
|
|
66
88
|
/**
|
|
67
|
-
* markdown-script runtime state
|
|
89
|
+
* The markdown-script runtime state
|
|
68
90
|
*
|
|
69
|
-
* @property {Object}
|
|
70
|
-
* @property {Object} options - The [markdown-script options]{@link module:lib/util~MarkdownScriptOptions}
|
|
91
|
+
* @property {Object} options - The [markdown-script options]{@link module:lib/script~MarkdownScriptOptions}
|
|
71
92
|
* @property {?Object[]} elements - The runtime-generated element model
|
|
72
|
-
* @property {?string} documentFocus - The the runtime-set
|
|
93
|
+
* @property {?string} documentFocus - The the runtime-set element ID to set input focus
|
|
73
94
|
* @property {?string} documentTitle - The the runtime-set document title
|
|
74
95
|
* @property {boolean} isDocumentReset - If true, the runtime requested a document-reset
|
|
75
96
|
* @property {?string} windowLocation - The the runtime-set document location
|
|
@@ -77,11 +98,10 @@ const rLineSplit = /\r?\n/;
|
|
|
77
98
|
*/
|
|
78
99
|
export class MarkdownScriptRuntime {
|
|
79
100
|
/**
|
|
80
|
-
* @param {Object} options - The [markdown-script options]{@link module:lib/
|
|
101
|
+
* @param {Object} options - The [markdown-script options]{@link module:lib/script~MarkdownScriptOptions}
|
|
81
102
|
*/
|
|
82
103
|
constructor(options) {
|
|
83
104
|
this.options = options;
|
|
84
|
-
this.globals = this.createGlobals();
|
|
85
105
|
this.elements = null;
|
|
86
106
|
this.documentFocus = null;
|
|
87
107
|
this.documentTitle = null;
|
|
@@ -113,290 +133,6 @@ export class MarkdownScriptRuntime {
|
|
|
113
133
|
}
|
|
114
134
|
|
|
115
135
|
|
|
116
|
-
createGlobals() {
|
|
117
|
-
return {
|
|
118
|
-
//
|
|
119
|
-
// Document functions
|
|
120
|
-
//
|
|
121
|
-
|
|
122
|
-
// $function: documentReset
|
|
123
|
-
// $group: Document
|
|
124
|
-
// $doc: Reset the document. This is useful to call within callback functions that re-render the document.
|
|
125
|
-
'documentReset': () => this.documentReset(),
|
|
126
|
-
|
|
127
|
-
// $function: documentURL
|
|
128
|
-
// $group: Document
|
|
129
|
-
// $doc: TODO
|
|
130
|
-
'documentURL': ([url]) => this.options.urlFn(url),
|
|
131
|
-
|
|
132
|
-
// $function: getDocumentInputValue
|
|
133
|
-
// $group: Document
|
|
134
|
-
// $doc: TODO
|
|
135
|
-
'getDocumentInputValue': ([id]) => this.options.window.document.getElementById(id).value,
|
|
136
|
-
|
|
137
|
-
// $function: getDocumentFontSize
|
|
138
|
-
// $group: Document
|
|
139
|
-
// $doc: TODO
|
|
140
|
-
'getDocumentFontSize': () => this.options.fontSize * pixelsPerPoint,
|
|
141
|
-
|
|
142
|
-
// $function: getWindowHeight
|
|
143
|
-
// $group: Document
|
|
144
|
-
// $doc: TODO
|
|
145
|
-
'getWindowHeight': () => this.options.window.innerHeight,
|
|
146
|
-
|
|
147
|
-
// $function: getWindowWidth
|
|
148
|
-
// $group: Document
|
|
149
|
-
// $doc: TODO
|
|
150
|
-
'getWindowWidth': () => this.options.window.innerWidth,
|
|
151
|
-
|
|
152
|
-
// $function: setDocumentFocus
|
|
153
|
-
// $group: Document
|
|
154
|
-
// $doc: TODO
|
|
155
|
-
'setDocumentFocus': ([id]) => this.setDocumentFocus(id),
|
|
156
|
-
|
|
157
|
-
// $function: setDocumentTitle
|
|
158
|
-
// $group: Document
|
|
159
|
-
// $doc: TODO
|
|
160
|
-
'setDocumentTitle': ([title]) => this.setDocumentTitle(title),
|
|
161
|
-
|
|
162
|
-
// $function: setWindowLocation
|
|
163
|
-
// $group: Document
|
|
164
|
-
// $doc: TODO
|
|
165
|
-
'setWindowLocation': ([location]) => this.setWindowLocation(location),
|
|
166
|
-
|
|
167
|
-
// $function: setWindowResize
|
|
168
|
-
// $group: Document
|
|
169
|
-
// $doc: TODO
|
|
170
|
-
'setWindowResize': ([callback]) => this.setWindowResize(callback),
|
|
171
|
-
|
|
172
|
-
// $function: setWindowTimeout
|
|
173
|
-
// $group: Document
|
|
174
|
-
// $doc: TODO
|
|
175
|
-
'setWindowTimeout': ([callback, delay]) => this.setWindowTimeout(callback, delay),
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
//
|
|
179
|
-
// Drawing functions
|
|
180
|
-
//
|
|
181
|
-
|
|
182
|
-
// $function: drawArc
|
|
183
|
-
// $group: Drawing
|
|
184
|
-
// $doc: TODO
|
|
185
|
-
'drawArc': (args) => this.drawArc(...args),
|
|
186
|
-
|
|
187
|
-
// $function: drawCircle
|
|
188
|
-
// $group: Drawing
|
|
189
|
-
// $doc: TODO
|
|
190
|
-
'drawCircle': (args) => this.drawCircle(...args),
|
|
191
|
-
|
|
192
|
-
// $function: drawClose
|
|
193
|
-
// $group: Drawing
|
|
194
|
-
// $doc: TODO
|
|
195
|
-
'drawClose': () => this.drawClose(),
|
|
196
|
-
|
|
197
|
-
// $function: drawEllipse
|
|
198
|
-
// $group: Drawing
|
|
199
|
-
// $doc: TODO
|
|
200
|
-
'drawEllipse': (args) => this.drawEllipse(...args),
|
|
201
|
-
|
|
202
|
-
// $function: drawHLine
|
|
203
|
-
// $group: Drawing
|
|
204
|
-
// $doc: TODO
|
|
205
|
-
'drawHLine': (args) => this.drawHLine(...args),
|
|
206
|
-
|
|
207
|
-
// $function: drawImage
|
|
208
|
-
// $group: Drawing
|
|
209
|
-
// $doc: TODO
|
|
210
|
-
'drawImage': (args) => this.drawImage(...args),
|
|
211
|
-
|
|
212
|
-
// $function: drawLine
|
|
213
|
-
// $group: Drawing
|
|
214
|
-
// $doc: TODO
|
|
215
|
-
'drawLine': (args) => this.drawLine(...args),
|
|
216
|
-
|
|
217
|
-
// $function: drawMove
|
|
218
|
-
// $group: Drawing
|
|
219
|
-
// $doc: TODO
|
|
220
|
-
'drawMove': (args) => this.drawMove(...args),
|
|
221
|
-
|
|
222
|
-
// $function: drawOnClick
|
|
223
|
-
// $group: Drawing
|
|
224
|
-
// $doc: TODO
|
|
225
|
-
'drawOnClick': (args) => this.drawOnClick(...args),
|
|
226
|
-
|
|
227
|
-
// $function: drawRect
|
|
228
|
-
// $group: Drawing
|
|
229
|
-
// $doc: TODO
|
|
230
|
-
'drawRect': (args) => this.drawRect(...args),
|
|
231
|
-
|
|
232
|
-
// $function: drawStyle
|
|
233
|
-
// $group: Drawing
|
|
234
|
-
// $doc: TODO
|
|
235
|
-
'drawStyle': (args) => this.drawStyle(...args),
|
|
236
|
-
|
|
237
|
-
// $function: drawText
|
|
238
|
-
// $group: Drawing
|
|
239
|
-
// $doc: TODO
|
|
240
|
-
'drawText': (args) => this.drawText(...args),
|
|
241
|
-
|
|
242
|
-
// $function: drawTextStyle
|
|
243
|
-
// $group: Drawing
|
|
244
|
-
// $doc: TODO
|
|
245
|
-
'drawTextStyle': (args) => this.drawTextStyle(...args),
|
|
246
|
-
|
|
247
|
-
// $function: drawVLine
|
|
248
|
-
// $group: Drawing
|
|
249
|
-
// $doc: TODO
|
|
250
|
-
'drawVLine': (args) => this.drawVLine(...args),
|
|
251
|
-
|
|
252
|
-
// $function: getDrawingHeight
|
|
253
|
-
// $group: Drawing
|
|
254
|
-
// $doc: TODO
|
|
255
|
-
'getDrawingHeight': () => this.drawingHeight,
|
|
256
|
-
|
|
257
|
-
// $function: getDrawingWidth
|
|
258
|
-
// $group: Drawing
|
|
259
|
-
// $doc: TODO
|
|
260
|
-
'getDrawingWidth': () => this.drawingWidth,
|
|
261
|
-
|
|
262
|
-
// $function: getTextHeight
|
|
263
|
-
// $group: Drawing
|
|
264
|
-
// $doc: TODO
|
|
265
|
-
'getTextHeight': (args) => this.drawTextHeight(...args),
|
|
266
|
-
|
|
267
|
-
// $function: getTextWidth
|
|
268
|
-
// $group: Drawing
|
|
269
|
-
// $doc: TODO
|
|
270
|
-
'getTextWidth': (args) => this.drawTextWidth(...args),
|
|
271
|
-
|
|
272
|
-
// $function: setDrawingSize
|
|
273
|
-
// $group: Drawing
|
|
274
|
-
// $doc: TODO
|
|
275
|
-
'setDrawingSize': (args) => this.setDrawingSize(...args),
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
//
|
|
279
|
-
// Element Model functions
|
|
280
|
-
//
|
|
281
|
-
|
|
282
|
-
// $function: elementModelRender
|
|
283
|
-
// $group: Element Model
|
|
284
|
-
// $doc: TODO
|
|
285
|
-
'elementModelRender': ([elements]) => this.elementModelRender(elements),
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
//
|
|
289
|
-
// Local storage functions
|
|
290
|
-
//
|
|
291
|
-
|
|
292
|
-
// $function: localStorageGet
|
|
293
|
-
// $group: Local Storage
|
|
294
|
-
// $doc: TODO
|
|
295
|
-
'localStorageGet': ([key]) => this.options.window.localStorage.getItem(key),
|
|
296
|
-
|
|
297
|
-
// $function: localStorageSet
|
|
298
|
-
// $group: Local Storage
|
|
299
|
-
// $doc: TODO
|
|
300
|
-
'localStorageSet': ([key, value]) => this.options.window.localStorage.setItem(key, value),
|
|
301
|
-
|
|
302
|
-
// $function: localStorageRemove
|
|
303
|
-
// $group: Local Storage
|
|
304
|
-
// $doc: TODO
|
|
305
|
-
'localStorageRemove': ([key]) => this.options.window.localStorage.removeItem(key),
|
|
306
|
-
|
|
307
|
-
// $function: localStorageClear
|
|
308
|
-
// $group: Local Storage
|
|
309
|
-
// $doc: TODO
|
|
310
|
-
'localStorageClear': () => this.options.window.localStorage.clear(),
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
//
|
|
314
|
-
// Markdown functions
|
|
315
|
-
//
|
|
316
|
-
|
|
317
|
-
// $function: markdownEncode
|
|
318
|
-
// $group: Markdown
|
|
319
|
-
// $doc: TODO
|
|
320
|
-
'markdownEncode': (args) => encodeMarkdownText(...args),
|
|
321
|
-
|
|
322
|
-
// $function: markdownHeaderId
|
|
323
|
-
// $group: Markdown
|
|
324
|
-
// $doc: TODO
|
|
325
|
-
'markdownHeaderId': ([text]) => markdownHeaderId(text),
|
|
326
|
-
|
|
327
|
-
// $function: markdownParse
|
|
328
|
-
// $group: Markdown
|
|
329
|
-
// $doc: TODO
|
|
330
|
-
'markdownParse': (lines) => parseMarkdown(MarkdownScriptRuntime.flattenAndSplitLines(lines)),
|
|
331
|
-
|
|
332
|
-
// $function: markdownPrint
|
|
333
|
-
// $group: Markdown
|
|
334
|
-
// $doc: TODO
|
|
335
|
-
'markdownPrint': (lines) => this.markdownPrint(lines),
|
|
336
|
-
|
|
337
|
-
// $function: markdownTitle
|
|
338
|
-
// $group: Markdown
|
|
339
|
-
// $doc: TODO
|
|
340
|
-
'markdownTitle': ([markdownModel]) => getMarkdownTitle(markdownModel),
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
//
|
|
344
|
-
// Schema functions
|
|
345
|
-
//
|
|
346
|
-
|
|
347
|
-
// $function: schemaParse
|
|
348
|
-
// $group: Schema
|
|
349
|
-
// $doc: TODO
|
|
350
|
-
'schemaParse': (lines) => MarkdownScriptRuntime.schemaParse(lines),
|
|
351
|
-
|
|
352
|
-
// $function: schemaTypeModel
|
|
353
|
-
// $group: Schema
|
|
354
|
-
// $doc: TODO
|
|
355
|
-
'schemaTypeModel': () => typeModel,
|
|
356
|
-
|
|
357
|
-
// $function: schemaValidate
|
|
358
|
-
// $group: Schema
|
|
359
|
-
// $doc: TODO
|
|
360
|
-
'schemaValidate': ([types, typeName, value]) => this.schemaValidate(types, typeName, value),
|
|
361
|
-
|
|
362
|
-
// $function: schemaValidateTypeModel
|
|
363
|
-
// $group: Schema
|
|
364
|
-
// $doc: TODO
|
|
365
|
-
'schemaValidateTypeModel': ([types]) => this.schemaValidateTypeModel(types),
|
|
366
|
-
|
|
367
|
-
// $function: schemaPrint
|
|
368
|
-
// $group: Schema
|
|
369
|
-
// $doc: TODO
|
|
370
|
-
'schemaPrint': ([types, typeName, actionURLs]) => this.schemaPrint(types, typeName, actionURLs),
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
//
|
|
374
|
-
// Session storage functions
|
|
375
|
-
//
|
|
376
|
-
|
|
377
|
-
// $function: sessionStorageGet
|
|
378
|
-
// $group: Session Storage
|
|
379
|
-
// $doc: TODO
|
|
380
|
-
'sessionStorageGet': ([key]) => this.options.window.sessionStorage.getItem(key),
|
|
381
|
-
|
|
382
|
-
// $function: sessionStorageSet
|
|
383
|
-
// $group: Session Storage
|
|
384
|
-
// $doc: TODO
|
|
385
|
-
'sessionStorageSet': ([key, value]) => this.options.window.sessionStorage.setItem(key, value),
|
|
386
|
-
|
|
387
|
-
// $function: sessionStorageRemove
|
|
388
|
-
// $group: Session Storage
|
|
389
|
-
// $doc: TODO
|
|
390
|
-
'sessionStorageRemove': ([key]) => this.options.window.sessionStorage.removeItem(key),
|
|
391
|
-
|
|
392
|
-
// $function: sessionStorageClear
|
|
393
|
-
// $group: Session Storage
|
|
394
|
-
// $doc: TODO
|
|
395
|
-
'sessionStorageClear': () => this.options.window.sessionStorage.clear()
|
|
396
|
-
};
|
|
397
|
-
}
|
|
398
|
-
|
|
399
|
-
|
|
400
136
|
reset() {
|
|
401
137
|
this.documentFocus = null;
|
|
402
138
|
this.documentTitle = null;
|
|
@@ -549,16 +285,16 @@ export class MarkdownScriptRuntime {
|
|
|
549
285
|
//
|
|
550
286
|
|
|
551
287
|
|
|
552
|
-
drawArc(rx, ry,
|
|
288
|
+
drawArc(rx, ry, angle, largeArcFlag, sweepFlag, x, y) {
|
|
553
289
|
this.setDrawingPath();
|
|
554
290
|
this.drawingPath.push(
|
|
555
|
-
`A ${rx.toFixed(svgPrecision)} ${ry.toFixed(svgPrecision)} ${
|
|
556
|
-
`${largeArcFlag ? 1 : 0} ${sweepFlag ? 1 : 0} ${
|
|
291
|
+
`A ${rx.toFixed(svgPrecision)} ${ry.toFixed(svgPrecision)} ${angle.toFixed(svgPrecision)} ` +
|
|
292
|
+
`${largeArcFlag ? 1 : 0} ${sweepFlag ? 1 : 0} ${x.toFixed(svgPrecision)} ${y.toFixed(svgPrecision)}`
|
|
557
293
|
);
|
|
558
294
|
}
|
|
559
295
|
|
|
560
296
|
|
|
561
|
-
drawCircle(cx, cy,
|
|
297
|
+
drawCircle(cx, cy, r) {
|
|
562
298
|
const svg = this.setDrawing();
|
|
563
299
|
svg.elem.push({
|
|
564
300
|
'svg': 'circle',
|
|
@@ -569,7 +305,7 @@ export class MarkdownScriptRuntime {
|
|
|
569
305
|
'stroke-dasharray': this.drawingPathStrokeDashArray,
|
|
570
306
|
'cx': cx,
|
|
571
307
|
'cy': cy,
|
|
572
|
-
'r':
|
|
308
|
+
'r': r
|
|
573
309
|
}
|
|
574
310
|
});
|
|
575
311
|
}
|
|
@@ -599,19 +335,19 @@ export class MarkdownScriptRuntime {
|
|
|
599
335
|
}
|
|
600
336
|
|
|
601
337
|
|
|
602
|
-
drawHLine(
|
|
338
|
+
drawHLine(x) {
|
|
603
339
|
this.setDrawingPath();
|
|
604
|
-
this.drawingPath.push(`H ${
|
|
340
|
+
this.drawingPath.push(`H ${x.toFixed(svgPrecision)}`);
|
|
605
341
|
}
|
|
606
342
|
|
|
607
343
|
|
|
608
|
-
drawImage(
|
|
344
|
+
drawImage(x, y, width, height, href) {
|
|
609
345
|
const svg = this.setDrawing();
|
|
610
346
|
svg.elem.push({
|
|
611
347
|
'svg': 'image',
|
|
612
348
|
'attr': {
|
|
613
|
-
'x':
|
|
614
|
-
'y':
|
|
349
|
+
'x': x,
|
|
350
|
+
'y': y,
|
|
615
351
|
'width': width,
|
|
616
352
|
'height': height,
|
|
617
353
|
'href': this.options.urlFn(href)
|
|
@@ -620,15 +356,15 @@ export class MarkdownScriptRuntime {
|
|
|
620
356
|
}
|
|
621
357
|
|
|
622
358
|
|
|
623
|
-
drawLine(
|
|
359
|
+
drawLine(x, y) {
|
|
624
360
|
this.setDrawingPath();
|
|
625
|
-
this.drawingPath.push(`L ${
|
|
361
|
+
this.drawingPath.push(`L ${x.toFixed(svgPrecision)} ${y.toFixed(svgPrecision)}`);
|
|
626
362
|
}
|
|
627
363
|
|
|
628
364
|
|
|
629
|
-
drawMove(
|
|
365
|
+
drawMove(x, y) {
|
|
630
366
|
this.setDrawingPath();
|
|
631
|
-
this.drawingPath.push(`M ${
|
|
367
|
+
this.drawingPath.push(`M ${x.toFixed(svgPrecision)} ${y.toFixed(svgPrecision)}`);
|
|
632
368
|
}
|
|
633
369
|
|
|
634
370
|
|
|
@@ -646,7 +382,7 @@ export class MarkdownScriptRuntime {
|
|
|
646
382
|
}
|
|
647
383
|
|
|
648
384
|
|
|
649
|
-
drawRect(
|
|
385
|
+
drawRect(x, y, width, height, rx = null, ry = null) {
|
|
650
386
|
const svg = this.setDrawing();
|
|
651
387
|
const element = {
|
|
652
388
|
'svg': 'rect',
|
|
@@ -655,8 +391,8 @@ export class MarkdownScriptRuntime {
|
|
|
655
391
|
'stroke': this.drawingPathStroke,
|
|
656
392
|
'stroke-width': this.drawingPathStrokeWidth.toFixed(svgPrecision),
|
|
657
393
|
'stroke-dasharray': this.drawingPathStrokeDashArray,
|
|
658
|
-
'x':
|
|
659
|
-
'y':
|
|
394
|
+
'x': x,
|
|
395
|
+
'y': y,
|
|
660
396
|
'width': width,
|
|
661
397
|
'height': height
|
|
662
398
|
}
|
|
@@ -684,7 +420,7 @@ export class MarkdownScriptRuntime {
|
|
|
684
420
|
}
|
|
685
421
|
|
|
686
422
|
|
|
687
|
-
drawText(text,
|
|
423
|
+
drawText(text, x, y, textAnchor = 'middle', dominantBaseline = 'middle') {
|
|
688
424
|
const svg = this.setDrawing();
|
|
689
425
|
svg.elem.push({
|
|
690
426
|
'svg': 'text',
|
|
@@ -696,36 +432,26 @@ export class MarkdownScriptRuntime {
|
|
|
696
432
|
'dominant-baseline': dominantBaseline,
|
|
697
433
|
'font-weight': (this.drawingFontBold ? 'bold' : 'normal'),
|
|
698
434
|
'font-style': (this.drawingFontItalic ? 'italic' : 'normal'),
|
|
699
|
-
'x':
|
|
700
|
-
'y':
|
|
435
|
+
'x': x,
|
|
436
|
+
'y': y
|
|
701
437
|
},
|
|
702
438
|
'elem': {'text': text}
|
|
703
439
|
});
|
|
704
440
|
}
|
|
705
441
|
|
|
706
442
|
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
}
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
drawTextStyle(fontSizePx = null, textFill = 'black', bold = false, italic = false, fontFamily = defaultFontFamily) {
|
|
713
|
-
this.drawingFontSizePx = (fontSizePx !== null ? fontSizePx : this.options.fontSize);
|
|
443
|
+
drawTextStyle(fontSizePx = null, textFill = 'black', bold = false, italic = false, fontFamily = null) {
|
|
444
|
+
this.drawingFontSizePx = (fontSizePx !== null ? fontSizePx : this.options.fontSize * pixelsPerPoint);
|
|
714
445
|
this.drawingFontFill = textFill;
|
|
715
446
|
this.drawingFontBold = bold;
|
|
716
447
|
this.drawingFontItalic = italic;
|
|
717
|
-
this.drawingFontFamily = fontFamily;
|
|
718
|
-
}
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
drawTextWidth(text) {
|
|
722
|
-
return fontWidthRatio * this.drawiingFontSizePx * text.length;
|
|
448
|
+
this.drawingFontFamily = (fontFamily !== null ? fontFamily : defaultFontFamily);
|
|
723
449
|
}
|
|
724
450
|
|
|
725
451
|
|
|
726
|
-
drawVLine(
|
|
452
|
+
drawVLine(y) {
|
|
727
453
|
this.setDrawingPath();
|
|
728
|
-
this.drawingPath.push(`V ${
|
|
454
|
+
this.drawingPath.push(`V ${y.toFixed(svgPrecision)}`);
|
|
729
455
|
}
|
|
730
456
|
|
|
731
457
|
|
|
@@ -761,9 +487,7 @@ export class MarkdownScriptRuntime {
|
|
|
761
487
|
// Element callback attribute must be map of event => callback
|
|
762
488
|
if ('callback' in elements) {
|
|
763
489
|
const elementEvents = elements.callback;
|
|
764
|
-
if (typeof elementEvents
|
|
765
|
-
elements.callback = null;
|
|
766
|
-
} else {
|
|
490
|
+
if (elementEvents !== null && typeof elementEvents === 'object') {
|
|
767
491
|
// Wrap the event handler function
|
|
768
492
|
elements.callback = (element) => {
|
|
769
493
|
// On element render, add a listener for each event
|
|
@@ -795,7 +519,7 @@ export class MarkdownScriptRuntime {
|
|
|
795
519
|
|
|
796
520
|
markdownPrint(lines) {
|
|
797
521
|
this.setMarkdown();
|
|
798
|
-
this.markdown.push(...
|
|
522
|
+
this.markdown.push(...lines.flat());
|
|
799
523
|
}
|
|
800
524
|
|
|
801
525
|
|
|
@@ -804,50 +528,6 @@ export class MarkdownScriptRuntime {
|
|
|
804
528
|
//
|
|
805
529
|
|
|
806
530
|
|
|
807
|
-
static schemaParse(lines) {
|
|
808
|
-
const parser = new SchemaMarkdownParser();
|
|
809
|
-
parser.parse(MarkdownScriptRuntime.flattenAndSplitLines(lines));
|
|
810
|
-
return parser.types;
|
|
811
|
-
}
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
schemaValidate(types, typeName, value) {
|
|
815
|
-
try {
|
|
816
|
-
return validateType(types, typeName, value);
|
|
817
|
-
} catch ({message}) {
|
|
818
|
-
if ('logFn' in this.options) {
|
|
819
|
-
this.options.logFn(`Error: schemaValidate failed for type "${typeName}" with error: ${message}`);
|
|
820
|
-
}
|
|
821
|
-
return null;
|
|
822
|
-
}
|
|
823
|
-
}
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
schemaValidateTypeModel(types) {
|
|
827
|
-
try {
|
|
828
|
-
return validateTypeModel(types);
|
|
829
|
-
} catch ({message}) {
|
|
830
|
-
if ('logFn' in this.options) {
|
|
831
|
-
this.options.logFn(
|
|
832
|
-
`Error: schemaValidateTypeModel failed with error: ${message}`
|
|
833
|
-
);
|
|
834
|
-
}
|
|
835
|
-
return null;
|
|
836
|
-
}
|
|
837
|
-
}
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
static flattenAndSplitLines(lines) {
|
|
841
|
-
return lines.flat().reduce(
|
|
842
|
-
(result, line) => {
|
|
843
|
-
result.push(...line.split(rLineSplit));
|
|
844
|
-
return result;
|
|
845
|
-
},
|
|
846
|
-
[]
|
|
847
|
-
);
|
|
848
|
-
}
|
|
849
|
-
|
|
850
|
-
|
|
851
531
|
schemaPrint(types, typeName, actionURLs = null) {
|
|
852
532
|
const params = encodeQueryString(this.options.params);
|
|
853
533
|
const options = {params};
|
|
@@ -855,6 +535,6 @@ export class MarkdownScriptRuntime {
|
|
|
855
535
|
options.actionURLs = actionURLs;
|
|
856
536
|
}
|
|
857
537
|
this.setElements();
|
|
858
|
-
this.elements.push(schemaMarkdownDoc(types, typeName,
|
|
538
|
+
this.elements.push(schemaMarkdownDoc(types, typeName, options));
|
|
859
539
|
}
|
|
860
540
|
}
|