markdown-up 2.4.1 → 3.1.0
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 +2 -2
- package/lib/app.js +12 -14
- package/lib/dataTable.js +2 -2
- package/lib/dataUtil.js +16 -13
- package/lib/lineChart.js +2 -2
- package/lib/scriptLibrary.js +1022 -630
- package/package.json +7 -7
package/lib/scriptLibrary.js
CHANGED
|
@@ -4,8 +4,9 @@
|
|
|
4
4
|
import {dataTableElements, validateDataTable} from './dataTable.js';
|
|
5
5
|
import {escapeMarkdownText, getMarkdownTitle, parseMarkdown} from 'markdown-model/lib/parser.js';
|
|
6
6
|
import {lineChartElements, validateLineChart} from './lineChart.js';
|
|
7
|
+
import {valueArgsModel, valueArgsValidate} from 'bare-script/lib/value.js';
|
|
7
8
|
import {encodeQueryString} from 'schema-markdown/lib/encode.js';
|
|
8
|
-
import {markdownHeaderId} from 'markdown-model/lib/elements.js';
|
|
9
|
+
import {markdownHeaderId as markdownModelHeaderId} from 'markdown-model/lib/elements.js';
|
|
9
10
|
import {schemaMarkdownDoc} from 'schema-markdown-doc/lib/schemaMarkdownDoc.js';
|
|
10
11
|
import {validateElements} from 'element-model/lib/elementModel.js';
|
|
11
12
|
|
|
@@ -20,647 +21,651 @@ const pixelsPerPoint = 4 / 3;
|
|
|
20
21
|
const svgPrecision = 8;
|
|
21
22
|
|
|
22
23
|
|
|
23
|
-
//
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
'
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
},
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
// $arg href: The image resource URL
|
|
219
|
-
'drawImage': ([x, y, width, height, href], options) => {
|
|
220
|
-
const {runtime} = options;
|
|
221
|
-
const svg = runtime.setDrawing();
|
|
222
|
-
svg.elem.push({
|
|
223
|
-
'svg': 'image',
|
|
224
|
-
'attr': {
|
|
225
|
-
'x': x,
|
|
226
|
-
'y': y,
|
|
227
|
-
'width': width,
|
|
228
|
-
'height': height,
|
|
229
|
-
'href': options.urlFn(href)
|
|
230
|
-
}
|
|
231
|
-
});
|
|
232
|
-
},
|
|
233
|
-
|
|
234
|
-
// $function: drawLine
|
|
235
|
-
// $group: Drawing
|
|
236
|
-
// $doc: Draw a line from the current point to the end point
|
|
237
|
-
// $arg x: The x-coordinate of the end point
|
|
238
|
-
// $arg y: The y-coordinate of the end point
|
|
239
|
-
'drawLine': ([x, y], options) => {
|
|
240
|
-
const {runtime} = options;
|
|
241
|
-
runtime.setDrawingPath();
|
|
242
|
-
runtime.drawingPath.push(`L ${x.toFixed(svgPrecision)} ${y.toFixed(svgPrecision)}`);
|
|
243
|
-
},
|
|
244
|
-
|
|
245
|
-
// $function: drawMove
|
|
246
|
-
// $group: Drawing
|
|
247
|
-
// $doc: Move the path's drawing point
|
|
248
|
-
// $arg x: The x-coordinate of the new drawing point
|
|
249
|
-
// $arg y: The y-coordinate of the new drawing point
|
|
250
|
-
'drawMove': ([x, y], options) => {
|
|
251
|
-
const {runtime} = options;
|
|
252
|
-
runtime.setDrawingPath();
|
|
253
|
-
runtime.drawingPath.push(`M ${x.toFixed(svgPrecision)} ${y.toFixed(svgPrecision)}`);
|
|
254
|
-
},
|
|
255
|
-
|
|
256
|
-
// $function: drawNew
|
|
257
|
-
// $group: Drawing
|
|
258
|
-
// $doc: Create a new drawing
|
|
259
|
-
// $arg width: The width of the drawing
|
|
260
|
-
// $arg height: The height of the drawing
|
|
261
|
-
'drawNew': ([width, height], options) => {
|
|
262
|
-
const {runtime} = options;
|
|
263
|
-
runtime.drawingWidth = width;
|
|
264
|
-
runtime.drawingHeight = height;
|
|
265
|
-
runtime.setDrawing(true);
|
|
266
|
-
},
|
|
267
|
-
|
|
268
|
-
// $function: drawOnClick
|
|
269
|
-
// $group: Drawing
|
|
270
|
-
// $doc: Set the most recent drawing object's on-click event handler
|
|
271
|
-
// $arg callback: The on-click event callback function (x, y)
|
|
272
|
-
'drawOnClick': ([callback], options) => {
|
|
273
|
-
const {runtime} = options;
|
|
274
|
-
const svg = runtime.setDrawing();
|
|
275
|
-
const clickElement = (svg.elem.length === 0 ? svg : svg.elem[svg.elem.length - 1]);
|
|
276
|
-
clickElement.attr.style = 'cursor: pointer;';
|
|
277
|
-
clickElement.callback = (element) => {
|
|
278
|
-
element.addEventListener('click', async (event) => {
|
|
279
|
-
const boundingRect = event.target.ownerSVGElement.getBoundingClientRect();
|
|
280
|
-
options.statementCount = 0;
|
|
281
|
-
try {
|
|
282
|
-
await callback([event.clientX - boundingRect.left, event.clientY - boundingRect.top], options);
|
|
283
|
-
} catch ({message}) {
|
|
284
|
-
if ('logFn' in options && options.debug) {
|
|
285
|
-
options.logFn(`MarkdownUp: Error executing drawOnClick callback: ${message}`);
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
options.runtimeUpdateFn();
|
|
289
|
-
});
|
|
290
|
-
};
|
|
291
|
-
},
|
|
292
|
-
|
|
293
|
-
// $function: drawPathRect
|
|
294
|
-
// $group: Drawing
|
|
295
|
-
// $doc: Draw a rectangle as a path
|
|
296
|
-
// $arg x: The x-coordinate of the top-left of the rectangle
|
|
297
|
-
// $arg y: The y-coordinate of the top-left of the rectangle
|
|
298
|
-
// $arg width: The width of the rectangle
|
|
299
|
-
// $arg height: The height of the rectangle
|
|
300
|
-
'drawPathRect': ([x, y, width, height], options) => {
|
|
301
|
-
const {runtime} = options;
|
|
302
|
-
runtime.setDrawingPath();
|
|
303
|
-
runtime.drawingPath.push(`M ${x.toFixed(svgPrecision)} ${y.toFixed(svgPrecision)}`);
|
|
304
|
-
runtime.drawingPath.push(`H ${(x + width).toFixed(svgPrecision)}`);
|
|
305
|
-
runtime.drawingPath.push(`V ${(y + height).toFixed(svgPrecision)}`);
|
|
306
|
-
runtime.drawingPath.push(`H ${x.toFixed(svgPrecision)}`);
|
|
307
|
-
runtime.drawingPath.push('Z');
|
|
308
|
-
},
|
|
309
|
-
|
|
310
|
-
// $function: drawRect
|
|
311
|
-
// $group: Drawing
|
|
312
|
-
// $doc: Draw a rectangle
|
|
313
|
-
// $arg x: The x-coordinate of the top-left of the rectangle
|
|
314
|
-
// $arg y: The y-coordinate of the top-left of the rectangle
|
|
315
|
-
// $arg width: The width of the rectangle
|
|
316
|
-
// $arg height: The height of the rectangle
|
|
317
|
-
// $arg rx: Optional (default is null). The horizontal corner radius of the rectangle.
|
|
318
|
-
// $arg ry: Optional (default is null). The vertical corner radius of the rectangle.
|
|
319
|
-
'drawRect': ([x, y, width, height, rx = null, ry = null], options) => {
|
|
320
|
-
const {runtime} = options;
|
|
321
|
-
const svg = runtime.setDrawing();
|
|
322
|
-
const element = {
|
|
323
|
-
'svg': 'rect',
|
|
324
|
-
'attr': {
|
|
325
|
-
'fill': runtime.drawingPathFill,
|
|
326
|
-
'stroke': runtime.drawingPathStroke,
|
|
327
|
-
'stroke-width': runtime.drawingPathStrokeWidth.toFixed(svgPrecision),
|
|
328
|
-
'stroke-dasharray': runtime.drawingPathStrokeDashArray,
|
|
329
|
-
'x': x,
|
|
330
|
-
'y': y,
|
|
331
|
-
'width': width,
|
|
332
|
-
'height': height
|
|
333
|
-
}
|
|
334
|
-
};
|
|
335
|
-
if (rx !== null) {
|
|
336
|
-
element.attr.rx = rx;
|
|
337
|
-
}
|
|
338
|
-
if (ry !== null) {
|
|
339
|
-
element.attr.ry = ry;
|
|
24
|
+
//
|
|
25
|
+
// Data functions
|
|
26
|
+
//
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
// $function: dataLineChart
|
|
30
|
+
// $group: Data
|
|
31
|
+
// $doc: Draw a line chart
|
|
32
|
+
// $arg data: The data array
|
|
33
|
+
// $arg lineChart: The [line chart model](model.html#var.vName='LineChart')
|
|
34
|
+
function dataLineChart(args, options) {
|
|
35
|
+
const [data, lineChart] = valueArgsValidate(dataLineChartArgs, args);
|
|
36
|
+
const {runtime} = options;
|
|
37
|
+
|
|
38
|
+
// Render the line chart
|
|
39
|
+
const elements = lineChartElements(data, validateLineChart(lineChart), options);
|
|
40
|
+
runtime.setElements();
|
|
41
|
+
runtime.addElements({'html': 'p', 'elem': elements});
|
|
42
|
+
|
|
43
|
+
// Set the drawing size (the chart is now the active drawing)
|
|
44
|
+
runtime.drawingWidth = elements.attr.width;
|
|
45
|
+
runtime.drawingHeight = elements.attr.height;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const dataLineChartArgs = valueArgsModel([
|
|
49
|
+
{'name': 'data', 'type': 'array'},
|
|
50
|
+
{'name': 'lineChart', 'type': 'object'}
|
|
51
|
+
]);
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
// $function: dataTable
|
|
55
|
+
// $group: Data
|
|
56
|
+
// $doc: Draw a data table
|
|
57
|
+
// $arg data: The data array
|
|
58
|
+
// $arg dataTable: Optional (default is null). The [data table model](model.html#var.vName='DataTable').
|
|
59
|
+
function dataTable(args, options) {
|
|
60
|
+
const [data, dataTableModel] = valueArgsValidate(dataTableArgs, args);
|
|
61
|
+
const {runtime} = options;
|
|
62
|
+
runtime.setElements();
|
|
63
|
+
const dataTableValidated = (dataTableModel !== null ? validateDataTable(dataTableModel, options) : null);
|
|
64
|
+
runtime.addElements(dataTableElements(data, dataTableValidated, options));
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const dataTableArgs = valueArgsModel([
|
|
68
|
+
{'name': 'data', 'type': 'array'},
|
|
69
|
+
{'name': 'dataTable', 'type': 'object', 'nullable': true}
|
|
70
|
+
]);
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
//
|
|
74
|
+
// Document functions
|
|
75
|
+
//
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
// $function: documentFontSize
|
|
79
|
+
// $group: Document
|
|
80
|
+
// $doc: Get the document font size
|
|
81
|
+
// $return: The document font size, in pixels
|
|
82
|
+
function documentFontSize(unusedArgs, options) {
|
|
83
|
+
return options.fontSize * pixelsPerPoint;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
// $function: documentInputValue
|
|
88
|
+
// $group: Document
|
|
89
|
+
// $doc: Get an input element's value
|
|
90
|
+
// $arg id: The input element ID
|
|
91
|
+
// $return: The input element value or null if the element does not exist
|
|
92
|
+
function documentInputValue(args, options) {
|
|
93
|
+
const [id] = valueArgsValidate(documentInputValueArgs, args);
|
|
94
|
+
const element = options.window.document.getElementById(id) ?? null;
|
|
95
|
+
return (element !== null ? (element.value ?? null) : null);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const documentInputValueArgs = valueArgsModel([
|
|
99
|
+
{'name': 'id', 'type': 'string'}
|
|
100
|
+
]);
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
// $function: documentSetFocus
|
|
104
|
+
// $group: Document
|
|
105
|
+
// $doc: Set focus to an element
|
|
106
|
+
// $arg id: The element ID
|
|
107
|
+
function documentSetFocus(args, options) {
|
|
108
|
+
const [id] = valueArgsValidate(documentSetFocusArgs, args);
|
|
109
|
+
const {runtime} = options;
|
|
110
|
+
runtime.documentFocus = id;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
const documentSetFocusArgs = valueArgsModel([
|
|
114
|
+
{'name': 'id', 'type': 'string'}
|
|
115
|
+
]);
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
// $function: documentSetReset
|
|
119
|
+
// $group: Document
|
|
120
|
+
// $doc: Set the document reset element
|
|
121
|
+
// $arg id: The element ID
|
|
122
|
+
function documentSetReset(args, options) {
|
|
123
|
+
const [id] = valueArgsValidate(documentSetResetArgs, args);
|
|
124
|
+
const {runtime} = options;
|
|
125
|
+
runtime.documentReset = id;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
const documentSetResetArgs = valueArgsModel([
|
|
129
|
+
{'name': 'id', 'type': 'string'}
|
|
130
|
+
]);
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
// $function: documentSetTitle
|
|
134
|
+
// $group: Document
|
|
135
|
+
// $doc: Set the document title
|
|
136
|
+
// $arg title: The document title string
|
|
137
|
+
function documentSetTitle(args, options) {
|
|
138
|
+
const [title] = valueArgsValidate(documentSetTitleArgs, args);
|
|
139
|
+
const {runtime} = options;
|
|
140
|
+
runtime.documentTitle = title;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
const documentSetTitleArgs = valueArgsModel([
|
|
144
|
+
{'name': 'title', 'type': 'string'}
|
|
145
|
+
]);
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
// $function: documentURL
|
|
149
|
+
// $group: Document
|
|
150
|
+
// $doc: Fix-up relative URLs
|
|
151
|
+
// $arg url: The URL
|
|
152
|
+
// $return: The fixed-up URL
|
|
153
|
+
function documentURL(args, options) {
|
|
154
|
+
const [url] = valueArgsValidate(documentURLArgs, args);
|
|
155
|
+
return options.urlFn(url);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
const documentURLArgs = valueArgsModel([
|
|
159
|
+
{'name': 'url', 'type': 'string'}
|
|
160
|
+
]);
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
//
|
|
164
|
+
// Drawing functions
|
|
165
|
+
//
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
// $function: drawArc
|
|
169
|
+
// $group: Drawing
|
|
170
|
+
// $doc: Draw an arc curve from the current point to the end point
|
|
171
|
+
// $arg rx: The arc ellipse's x-radius
|
|
172
|
+
// $arg ry: The arc ellipse's y-radius
|
|
173
|
+
// $arg angle: The rotation (in degrees) of the ellipse relative to the x-axis
|
|
174
|
+
// $arg largeArcFlag: Either large arc (1) or small arc (0)
|
|
175
|
+
// $arg sweepFlag: Either clockwise turning arc (1) or counterclockwise turning arc (0)
|
|
176
|
+
// $arg x: The x-coordinate of the end point
|
|
177
|
+
// $arg y: The y-coordinate of the end point
|
|
178
|
+
function drawArc(args, options) {
|
|
179
|
+
const [rx, ry, angle, largeArcFlag, sweepFlag, x, y] = valueArgsValidate(drawArcArgs, args);
|
|
180
|
+
const {runtime} = options;
|
|
181
|
+
runtime.setDrawingPath();
|
|
182
|
+
runtime.drawingPath.push(
|
|
183
|
+
`A ${rx.toFixed(svgPrecision)} ${ry.toFixed(svgPrecision)} ${angle.toFixed(svgPrecision)} ` +
|
|
184
|
+
`${largeArcFlag ? 1 : 0} ${sweepFlag ? 1 : 0} ${x.toFixed(svgPrecision)} ${y.toFixed(svgPrecision)}`
|
|
185
|
+
);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
const drawArcArgs = valueArgsModel([
|
|
189
|
+
{'name': 'rx', 'type': 'number'},
|
|
190
|
+
{'name': 'ry', 'type': 'number'},
|
|
191
|
+
{'name': 'angle', 'type': 'number'},
|
|
192
|
+
{'name': 'largeArcFlag', 'type': 'boolean'},
|
|
193
|
+
{'name': 'sweepFlag', 'type': 'boolean'},
|
|
194
|
+
{'name': 'x', 'type': 'number'},
|
|
195
|
+
{'name': 'y', 'type': 'number'},
|
|
196
|
+
]);
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
// $function: drawCircle
|
|
200
|
+
// $group: Drawing
|
|
201
|
+
// $doc: Draw a circle
|
|
202
|
+
// $arg cx: The x-coordinate of the center of the circle
|
|
203
|
+
// $arg cy: The y-coordinate of the center of the circle
|
|
204
|
+
// $arg r: The radius of the circle
|
|
205
|
+
function drawCircle(args, options) {
|
|
206
|
+
const [cx, cy, r] = valueArgsValidate(drawCircleArgs, args);
|
|
207
|
+
const {runtime} = options;
|
|
208
|
+
const svg = runtime.setDrawing();
|
|
209
|
+
svg.elem.push({
|
|
210
|
+
'svg': 'circle',
|
|
211
|
+
'attr': {
|
|
212
|
+
'fill': runtime.drawingPathFill,
|
|
213
|
+
'stroke': runtime.drawingPathStroke,
|
|
214
|
+
'stroke-width': runtime.drawingPathStrokeWidth.toFixed(svgPrecision),
|
|
215
|
+
'stroke-dasharray': runtime.drawingPathStrokeDashArray,
|
|
216
|
+
'cx': cx,
|
|
217
|
+
'cy': cy,
|
|
218
|
+
'r': r
|
|
340
219
|
}
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
const drawCircleArgs = valueArgsModel([
|
|
224
|
+
{'name': 'cx', 'type': 'number'},
|
|
225
|
+
{'name': 'cy', 'type': 'number'},
|
|
226
|
+
{'name': 'r', 'type': 'number'}
|
|
227
|
+
]);
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
// $function: drawClose
|
|
231
|
+
// $group: Drawing
|
|
232
|
+
// $doc: Close the current drawing path
|
|
233
|
+
function drawClose(unusedArgs, options) {
|
|
234
|
+
const {runtime} = options;
|
|
235
|
+
runtime.setDrawingPath();
|
|
236
|
+
runtime.drawingPath.push('Z');
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
|
|
240
|
+
// $function: drawEllipse
|
|
241
|
+
// $group: Drawing
|
|
242
|
+
// $doc: Draw an ellipse
|
|
243
|
+
// $arg cx: The x-coordinate of the center of the ellipse
|
|
244
|
+
// $arg cy: The y-coordinate of the center of the ellipse
|
|
245
|
+
// $arg rx: The x-radius of the ellipse
|
|
246
|
+
// $arg ry: The y-radius of the ellipse
|
|
247
|
+
function drawEllipse(args, options) {
|
|
248
|
+
const [cx, cy, rx, ry] = valueArgsValidate(drawEllipseArgs, args);
|
|
249
|
+
const {runtime} = options;
|
|
250
|
+
const svg = runtime.setDrawing();
|
|
251
|
+
svg.elem.push({
|
|
252
|
+
'svg': 'ellipse',
|
|
253
|
+
'attr': {
|
|
254
|
+
'fill': runtime.drawingPathFill,
|
|
255
|
+
'stroke': runtime.drawingPathStroke,
|
|
256
|
+
'stroke-width': runtime.drawingPathStrokeWidth.toFixed(svgPrecision),
|
|
257
|
+
'stroke-dasharray': runtime.drawingPathStrokeDashArray,
|
|
258
|
+
'cx': cx,
|
|
259
|
+
'cy': cy,
|
|
260
|
+
'rx': rx,
|
|
261
|
+
'ry': ry
|
|
362
262
|
}
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
},
|
|
420
|
-
|
|
421
|
-
// $function: drawTextWidth
|
|
422
|
-
// $group: Drawing
|
|
423
|
-
// $doc: Compute the text's width
|
|
424
|
-
// $arg text: The text
|
|
425
|
-
// $arg fontSizePx: The text font size, in pixels
|
|
426
|
-
// $return: The text's width, in pixels
|
|
427
|
-
'drawTextWidth': ([text, fontSizePx]) => fontWidthRatio * fontSizePx * text.length,
|
|
428
|
-
|
|
429
|
-
// $function: drawVLine
|
|
430
|
-
// $group: Drawing
|
|
431
|
-
// $doc: Draw a vertical line from the current point to the end point
|
|
432
|
-
// $arg y: The y-coordinate of the end point
|
|
433
|
-
'drawVLine': ([y], options) => {
|
|
434
|
-
const {runtime} = options;
|
|
435
|
-
runtime.setDrawingPath();
|
|
436
|
-
runtime.drawingPath.push(`V ${y.toFixed(svgPrecision)}`);
|
|
437
|
-
},
|
|
438
|
-
|
|
439
|
-
// $function: drawWidth
|
|
440
|
-
// $group: Drawing
|
|
441
|
-
// $doc: Get the current drawing's width
|
|
442
|
-
// $return: The current drawing's width
|
|
443
|
-
'drawWidth': (unused, options) => options.runtime.drawingWidth,
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
//
|
|
447
|
-
// Element Model functions
|
|
448
|
-
//
|
|
449
|
-
|
|
450
|
-
// $function: elementModelRender
|
|
451
|
-
// $group: Element Model
|
|
452
|
-
// $doc: Render an [element model](https://github.com/craigahobbs/element-model#readme)
|
|
453
|
-
// $doc:
|
|
454
|
-
// $doc: **Note:** Element model "callback" members are a map of event name (e.g., "click") to
|
|
455
|
-
// $doc: event callback function. The following events have callback arguments:
|
|
456
|
-
// $doc: - **keydown** - keyCode
|
|
457
|
-
// $doc: - **keypress** - keyCode
|
|
458
|
-
// $doc: - **keyup** - keyCode
|
|
459
|
-
// $arg element: The [element model](https://github.com/craigahobbs/element-model#readme)
|
|
460
|
-
'elementModelRender': ([elements], options) => {
|
|
461
|
-
const {runtime} = options;
|
|
462
|
-
runtime.setElements();
|
|
463
|
-
elementModelWrapCallbacks(elements, options);
|
|
464
|
-
runtime.addElements(validateElements(elements));
|
|
465
|
-
},
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
//
|
|
469
|
-
// Local storage functions
|
|
470
|
-
//
|
|
471
|
-
|
|
472
|
-
// $function: localStorageClear
|
|
473
|
-
// $group: Local Storage
|
|
474
|
-
// $doc: Clear all keys from the browser's local storage
|
|
475
|
-
'localStorageClear': (unused, options) => options.window.localStorage.clear(),
|
|
476
|
-
|
|
477
|
-
// $function: localStorageGet
|
|
478
|
-
// $group: Local Storage
|
|
479
|
-
// $doc: Get a browser local storage key's value
|
|
480
|
-
// $arg key: The key string
|
|
481
|
-
// $return: The local storage value string or null if the key does not exist
|
|
482
|
-
'localStorageGet': ([key], options) => options.window.localStorage.getItem(key),
|
|
483
|
-
|
|
484
|
-
// $function: localStorageRemove
|
|
485
|
-
// $group: Local Storage
|
|
486
|
-
// $doc: Remove a browser local storage key
|
|
487
|
-
// $arg key: The key string
|
|
488
|
-
'localStorageRemove': ([key], options) => options.window.localStorage.removeItem(key),
|
|
489
|
-
|
|
490
|
-
// $function: localStorageSet
|
|
491
|
-
// $group: Local Storage
|
|
492
|
-
// $doc: Set a browser local storage key's value
|
|
493
|
-
// $arg key: The key string
|
|
494
|
-
// $arg value: The value string
|
|
495
|
-
'localStorageSet': ([key, value], options) => options.window.localStorage.setItem(key, value),
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
//
|
|
499
|
-
// Markdown functions
|
|
500
|
-
//
|
|
501
|
-
|
|
502
|
-
// $function: markdownEscape
|
|
503
|
-
// $group: Markdown
|
|
504
|
-
// $doc: Escape text for inclusion in Markdown text
|
|
505
|
-
// $arg text: The text
|
|
506
|
-
// $return: The escaped text
|
|
507
|
-
'markdownEscape': ([text]) => escapeMarkdownText(text),
|
|
508
|
-
|
|
509
|
-
// $function: markdownHeaderId
|
|
510
|
-
// $group: Markdown
|
|
511
|
-
// $doc: Compute the Markdown header element ID for some text
|
|
512
|
-
// $arg text: The text
|
|
513
|
-
// $return: The header element ID
|
|
514
|
-
'markdownHeaderId': ([text]) => markdownHeaderId(text),
|
|
515
|
-
|
|
516
|
-
// $function: markdownParse
|
|
517
|
-
// $group: Markdown
|
|
518
|
-
// $doc: Parse Markdown text
|
|
519
|
-
// $arg lines...: The Markdown text lines (may contain nested arrays of un-split lines)
|
|
520
|
-
// $return: The [Markdown model](https://craigahobbs.github.io/markdown-model/model/#var.vName='Markdown')
|
|
521
|
-
'markdownParse': (lines) => parseMarkdown(lines.flat()),
|
|
522
|
-
|
|
523
|
-
// $function: markdownPrint
|
|
524
|
-
// $group: Markdown
|
|
525
|
-
// $doc: Render Markdown text
|
|
526
|
-
// $arg lines...: The Markdown text lines (may contain nested arrays of un-split lines)
|
|
527
|
-
'markdownPrint': (lines, options) => {
|
|
528
|
-
const {runtime} = options;
|
|
529
|
-
runtime.setMarkdown();
|
|
530
|
-
runtime.addMarkdown(lines);
|
|
531
|
-
},
|
|
532
|
-
|
|
533
|
-
// $function: markdownTitle
|
|
534
|
-
// $group: Markdown
|
|
535
|
-
// $doc: Compute the title of a [Markdown model](https://craigahobbs.github.io/markdown-model/model/#var.vName='Markdown')
|
|
536
|
-
// $arg markdownModel: The [Markdown model](https://craigahobbs.github.io/markdown-model/model/#var.vName='Markdown')
|
|
537
|
-
// $return: The Markdown title or null if there is no title
|
|
538
|
-
'markdownTitle': ([markdownModel]) => getMarkdownTitle(markdownModel),
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
//
|
|
542
|
-
// Schema functions
|
|
543
|
-
//
|
|
544
|
-
|
|
545
|
-
// $function: schemaElements
|
|
546
|
-
// $group: Schema
|
|
547
|
-
// $doc: Get a schema type's documentation [element model](https://github.com/craigahobbs/element-model#readme).
|
|
548
|
-
// $doc: Render the element model with the [elementModelRender](#var.vName='elementModelRender') function.
|
|
549
|
-
// $arg types: The [type model](https://craigahobbs.github.io/schema-markdown-doc/doc/#var.vName='Types')
|
|
550
|
-
// $arg typeName: The type name
|
|
551
|
-
// $arg actionURLs: Optional (default is null). The
|
|
552
|
-
// $arg actionURLs: [action URL overrides](https://craigahobbs.github.io/schema-markdown-doc/doc/#var.vName='ActionURL').
|
|
553
|
-
// $return: The schema type's documentation [element model](https://github.com/craigahobbs/element-model#readme)
|
|
554
|
-
'schemaElements': ([types, typeName, actionURLs = null], options) => {
|
|
555
|
-
const params = encodeQueryString(options.params);
|
|
556
|
-
const schemaOptions = {params};
|
|
557
|
-
if (actionURLs !== null) {
|
|
558
|
-
schemaOptions.actionURLs = actionURLs;
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
const drawEllipseArgs = valueArgsModel([
|
|
267
|
+
{'name': 'cx', 'type': 'number'},
|
|
268
|
+
{'name': 'cy', 'type': 'number'},
|
|
269
|
+
{'name': 'rx', 'type': 'number'},
|
|
270
|
+
{'name': 'ry', 'type': 'number'}
|
|
271
|
+
]);
|
|
272
|
+
|
|
273
|
+
|
|
274
|
+
// $function: drawHLine
|
|
275
|
+
// $group: Drawing
|
|
276
|
+
// $doc: Draw a horizontal line from the current point to the end point
|
|
277
|
+
// $arg x: The x-coordinate of the end point
|
|
278
|
+
function drawHLine(args, options) {
|
|
279
|
+
const [x] = valueArgsValidate(drawHLineArgs, args);
|
|
280
|
+
const {runtime} = options;
|
|
281
|
+
runtime.setDrawingPath();
|
|
282
|
+
runtime.drawingPath.push(`H ${x.toFixed(svgPrecision)}`);
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
const drawHLineArgs = valueArgsModel([
|
|
286
|
+
{'name': 'x', 'type': 'number'}
|
|
287
|
+
]);
|
|
288
|
+
|
|
289
|
+
|
|
290
|
+
// $function: drawHeight
|
|
291
|
+
// $group: Drawing
|
|
292
|
+
// $doc: Get the current drawing's height
|
|
293
|
+
// $return: The current drawing's height
|
|
294
|
+
function drawHeight(unusedArgs, options) {
|
|
295
|
+
return options.runtime.drawingHeight;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
|
|
299
|
+
// $function: drawImage
|
|
300
|
+
// $group: Drawing
|
|
301
|
+
// $doc: Draw an image
|
|
302
|
+
// $arg x: The x-coordinate of the center of the image
|
|
303
|
+
// $arg y: The y-coordinate of the center of the image
|
|
304
|
+
// $arg width: The width of the image
|
|
305
|
+
// $arg height: The height of the image
|
|
306
|
+
// $arg href: The image resource URL
|
|
307
|
+
function drawImage(args, options) {
|
|
308
|
+
const [x, y, width, height, href] = valueArgsValidate(drawImageArgs, args);
|
|
309
|
+
const {runtime} = options;
|
|
310
|
+
const svg = runtime.setDrawing();
|
|
311
|
+
svg.elem.push({
|
|
312
|
+
'svg': 'image',
|
|
313
|
+
'attr': {
|
|
314
|
+
'x': x,
|
|
315
|
+
'y': y,
|
|
316
|
+
'width': width,
|
|
317
|
+
'height': height,
|
|
318
|
+
'href': options.urlFn(href)
|
|
559
319
|
}
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
'
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
320
|
+
});
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
const drawImageArgs = valueArgsModel([
|
|
324
|
+
{'name': 'x', 'type': 'number'},
|
|
325
|
+
{'name': 'y', 'type': 'number'},
|
|
326
|
+
{'name': 'width', 'type': 'number'},
|
|
327
|
+
{'name': 'height', 'type': 'number'},
|
|
328
|
+
{'name': 'href', 'type': 'string'}
|
|
329
|
+
]);
|
|
330
|
+
|
|
331
|
+
|
|
332
|
+
// $function: drawLine
|
|
333
|
+
// $group: Drawing
|
|
334
|
+
// $doc: Draw a line from the current point to the end point
|
|
335
|
+
// $arg x: The x-coordinate of the end point
|
|
336
|
+
// $arg y: The y-coordinate of the end point
|
|
337
|
+
function drawLine(args, options) {
|
|
338
|
+
const [x, y] = valueArgsValidate(drawLineArgs, args);
|
|
339
|
+
const {runtime} = options;
|
|
340
|
+
runtime.setDrawingPath();
|
|
341
|
+
runtime.drawingPath.push(`L ${x.toFixed(svgPrecision)} ${y.toFixed(svgPrecision)}`);
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
const drawLineArgs = valueArgsModel([
|
|
345
|
+
{'name': 'x', 'type': 'number'},
|
|
346
|
+
{'name': 'y', 'type': 'number'}
|
|
347
|
+
]);
|
|
348
|
+
|
|
349
|
+
|
|
350
|
+
// $function: drawMove
|
|
351
|
+
// $group: Drawing
|
|
352
|
+
// $doc: Move the path's drawing point
|
|
353
|
+
// $arg x: The x-coordinate of the new drawing point
|
|
354
|
+
// $arg y: The y-coordinate of the new drawing point
|
|
355
|
+
function drawMove(args, options) {
|
|
356
|
+
const [x, y] = valueArgsValidate(drawMoveArgs, args);
|
|
357
|
+
const {runtime} = options;
|
|
358
|
+
runtime.setDrawingPath();
|
|
359
|
+
runtime.drawingPath.push(`M ${x.toFixed(svgPrecision)} ${y.toFixed(svgPrecision)}`);
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
const drawMoveArgs = valueArgsModel([
|
|
363
|
+
{'name': 'x', 'type': 'number'},
|
|
364
|
+
{'name': 'y', 'type': 'number'}
|
|
365
|
+
]);
|
|
366
|
+
|
|
367
|
+
|
|
368
|
+
// $function: drawNew
|
|
369
|
+
// $group: Drawing
|
|
370
|
+
// $doc: Create a new drawing
|
|
371
|
+
// $arg width: The width of the drawing
|
|
372
|
+
// $arg height: The height of the drawing
|
|
373
|
+
function drawNew(args, options) {
|
|
374
|
+
const [width, height] = valueArgsValidate(drawNewArgs, args);
|
|
375
|
+
const {runtime} = options;
|
|
376
|
+
runtime.drawingWidth = width;
|
|
377
|
+
runtime.drawingHeight = height;
|
|
378
|
+
runtime.setDrawing(true);
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
const drawNewArgs = valueArgsModel([
|
|
382
|
+
{'name': 'width', 'type': 'number'},
|
|
383
|
+
{'name': 'height', 'type': 'number'}
|
|
384
|
+
]);
|
|
385
|
+
|
|
386
|
+
|
|
387
|
+
// $function: drawOnClick
|
|
388
|
+
// $group: Drawing
|
|
389
|
+
// $doc: Set the most recent drawing object's on-click event handler
|
|
390
|
+
// $arg callback: The on-click event callback function (x, y)
|
|
391
|
+
function drawOnClick(args, options) {
|
|
392
|
+
const [callback] = valueArgsValidate(drawOnClickArgs, args);
|
|
393
|
+
const {runtime} = options;
|
|
394
|
+
const svg = runtime.setDrawing();
|
|
395
|
+
const clickElement = (svg.elem.length === 0 ? svg : svg.elem[svg.elem.length - 1]);
|
|
396
|
+
clickElement.attr.style = 'cursor: pointer;';
|
|
397
|
+
clickElement.callback = (element) => {
|
|
398
|
+
element.addEventListener('click', async (event) => {
|
|
399
|
+
const boundingRect = event.target.ownerSVGElement.getBoundingClientRect();
|
|
620
400
|
options.statementCount = 0;
|
|
621
401
|
try {
|
|
622
|
-
await callback([], options);
|
|
402
|
+
await callback([event.clientX - boundingRect.left, event.clientY - boundingRect.top], options);
|
|
623
403
|
} catch ({message}) {
|
|
624
404
|
if ('logFn' in options && options.debug) {
|
|
625
|
-
options.logFn(`MarkdownUp: Error executing
|
|
405
|
+
options.logFn(`MarkdownUp: Error executing drawOnClick callback: ${message}`);
|
|
626
406
|
}
|
|
627
407
|
}
|
|
628
408
|
options.runtimeUpdateFn();
|
|
629
|
-
};
|
|
630
|
-
}
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
'
|
|
660
|
-
}
|
|
409
|
+
});
|
|
410
|
+
};
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
const drawOnClickArgs = valueArgsModel([
|
|
414
|
+
{'name': 'callback', 'type': 'function'}
|
|
415
|
+
]);
|
|
416
|
+
|
|
417
|
+
|
|
418
|
+
// $function: drawPathRect
|
|
419
|
+
// $group: Drawing
|
|
420
|
+
// $doc: Draw a rectangle as a path
|
|
421
|
+
// $arg x: The x-coordinate of the top-left of the rectangle
|
|
422
|
+
// $arg y: The y-coordinate of the top-left of the rectangle
|
|
423
|
+
// $arg width: The width of the rectangle
|
|
424
|
+
// $arg height: The height of the rectangle
|
|
425
|
+
function drawPathRect(args, options) {
|
|
426
|
+
const [x, y, width, height] = valueArgsValidate(drawPathRectArgs, args);
|
|
427
|
+
const {runtime} = options;
|
|
428
|
+
runtime.setDrawingPath();
|
|
429
|
+
runtime.drawingPath.push(`M ${x.toFixed(svgPrecision)} ${y.toFixed(svgPrecision)}`);
|
|
430
|
+
runtime.drawingPath.push(`H ${(x + width).toFixed(svgPrecision)}`);
|
|
431
|
+
runtime.drawingPath.push(`V ${(y + height).toFixed(svgPrecision)}`);
|
|
432
|
+
runtime.drawingPath.push(`H ${x.toFixed(svgPrecision)}`);
|
|
433
|
+
runtime.drawingPath.push('Z');
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
const drawPathRectArgs = valueArgsModel([
|
|
437
|
+
{'name': 'x', 'type': 'number'},
|
|
438
|
+
{'name': 'y', 'type': 'number'},
|
|
439
|
+
{'name': 'width', 'type': 'number'},
|
|
440
|
+
{'name': 'height', 'type': 'number'}
|
|
441
|
+
]);
|
|
442
|
+
|
|
443
|
+
|
|
444
|
+
// $function: drawRect
|
|
445
|
+
// $group: Drawing
|
|
446
|
+
// $doc: Draw a rectangle
|
|
447
|
+
// $arg x: The x-coordinate of the top-left of the rectangle
|
|
448
|
+
// $arg y: The y-coordinate of the top-left of the rectangle
|
|
449
|
+
// $arg width: The width of the rectangle
|
|
450
|
+
// $arg height: The height of the rectangle
|
|
451
|
+
// $arg rx: Optional (default is null). The horizontal corner radius of the rectangle.
|
|
452
|
+
// $arg ry: Optional (default is null). The vertical corner radius of the rectangle.
|
|
453
|
+
function drawRect(args, options) {
|
|
454
|
+
const [x, y, width, height, rx = null, ry = null] = valueArgsValidate(drawRectArgs, args);
|
|
455
|
+
const {runtime} = options;
|
|
456
|
+
const svg = runtime.setDrawing();
|
|
457
|
+
const element = {
|
|
458
|
+
'svg': 'rect',
|
|
459
|
+
'attr': {
|
|
460
|
+
'fill': runtime.drawingPathFill,
|
|
461
|
+
'stroke': runtime.drawingPathStroke,
|
|
462
|
+
'stroke-width': runtime.drawingPathStrokeWidth.toFixed(svgPrecision),
|
|
463
|
+
'stroke-dasharray': runtime.drawingPathStrokeDashArray,
|
|
464
|
+
'x': x,
|
|
465
|
+
'y': y,
|
|
466
|
+
'width': width,
|
|
467
|
+
'height': height
|
|
468
|
+
}
|
|
469
|
+
};
|
|
470
|
+
if (rx !== null) {
|
|
471
|
+
element.attr.rx = rx;
|
|
472
|
+
}
|
|
473
|
+
if (ry !== null) {
|
|
474
|
+
element.attr.ry = ry;
|
|
475
|
+
}
|
|
476
|
+
svg.elem.push(element);
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
const drawRectArgs = valueArgsModel([
|
|
480
|
+
{'name': 'x', 'type': 'number'},
|
|
481
|
+
{'name': 'y', 'type': 'number'},
|
|
482
|
+
{'name': 'width', 'type': 'number'},
|
|
483
|
+
{'name': 'height', 'type': 'number'},
|
|
484
|
+
{'name': 'rx', 'type': 'number', 'nullable': true},
|
|
485
|
+
{'name': 'ry', 'type': 'number', 'nullable': true}
|
|
486
|
+
]);
|
|
487
|
+
|
|
488
|
+
|
|
489
|
+
// $function: drawStyle
|
|
490
|
+
// $group: Drawing
|
|
491
|
+
// $doc: Set the current drawing styles
|
|
492
|
+
// $arg stroke: Optional (default is 'black'). The stroke color.
|
|
493
|
+
// $arg strokeWidth: Optional (default is 1). The stroke width.
|
|
494
|
+
// $arg fill: Optional (default is 'none'). The fill color.
|
|
495
|
+
// $arg strokeDashArray: Optional (default is 'none'). The stroke
|
|
496
|
+
// $arg strokeDashArray: [dash array](https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/stroke-dasharray#usage_notes).
|
|
497
|
+
function drawStyle(args, options) {
|
|
498
|
+
const [stroke, strokeWidth, fill, strokeDashArray] = valueArgsValidate(drawStyleArgs, args);
|
|
499
|
+
const {runtime} = options;
|
|
500
|
+
if (stroke !== runtime.drawingPathStroke || strokeWidth !== runtime.drawingPathStrokeWidth ||
|
|
501
|
+
strokeDashArray !== runtime.drawingPathStrokeDashArray || fill !== runtime.drawingPathFill
|
|
502
|
+
) {
|
|
503
|
+
runtime.setDrawing();
|
|
504
|
+
runtime.drawingPathStroke = stroke;
|
|
505
|
+
runtime.drawingPathStrokeWidth = strokeWidth;
|
|
506
|
+
runtime.drawingPathStrokeDashArray = strokeDashArray;
|
|
507
|
+
runtime.drawingPathFill = fill;
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
const drawStyleArgs = valueArgsModel([
|
|
512
|
+
{'name': 'stroke', 'type': 'string', 'default': 'black'},
|
|
513
|
+
{'name': 'strokeWidth', 'type': 'number', 'default': 1},
|
|
514
|
+
{'name': 'fill', 'type': 'string', 'default': 'none'},
|
|
515
|
+
{'name': 'strokeDashArray', 'type': 'string', 'default': 'none'}
|
|
516
|
+
]);
|
|
517
|
+
|
|
518
|
+
|
|
519
|
+
// $function: drawText
|
|
520
|
+
// $group: Drawing
|
|
521
|
+
// $doc: Draw text
|
|
522
|
+
// $arg text: The text to draw
|
|
523
|
+
// $arg x: The x-coordinate of the text
|
|
524
|
+
// $arg y: The y-coordinate of the text
|
|
525
|
+
// $arg textAnchor: Optional (default is 'middle'). The
|
|
526
|
+
// $arg textAnchor: [text anchor](https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/text-anchor#usage_notes) style.
|
|
527
|
+
// $arg dominantBaseline: Optional (default is 'middle'). The
|
|
528
|
+
// $arg dominantBaseline: [dominant baseline](https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/dominant-baseline#usage_notes)
|
|
529
|
+
// $arg dominantBaseline: style.
|
|
530
|
+
function drawText(args, options) {
|
|
531
|
+
const [text, x, y, textAnchor, dominantBaseline] = valueArgsValidate(drawTextArgs, args);
|
|
532
|
+
const {runtime} = options;
|
|
533
|
+
const svg = runtime.setDrawing();
|
|
534
|
+
svg.elem.push({
|
|
535
|
+
'svg': 'text',
|
|
536
|
+
'attr': {
|
|
537
|
+
'fill': runtime.drawingFontFill,
|
|
538
|
+
'font-family': runtime.drawingFontFamily,
|
|
539
|
+
'font-size': runtime.drawingFontSizePx.toFixed(svgPrecision),
|
|
540
|
+
'text-anchor': textAnchor,
|
|
541
|
+
'dominant-baseline': dominantBaseline,
|
|
542
|
+
'font-weight': (runtime.drawingFontBold ? 'bold' : 'normal'),
|
|
543
|
+
'font-style': (runtime.drawingFontItalic ? 'italic' : 'normal'),
|
|
544
|
+
'x': x,
|
|
545
|
+
'y': y
|
|
546
|
+
},
|
|
547
|
+
'elem': {'text': text}
|
|
548
|
+
});
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
const drawTextArgs = valueArgsModel([
|
|
552
|
+
{'name': 'text', 'type': 'string'},
|
|
553
|
+
{'name': 'x', 'type': 'number'},
|
|
554
|
+
{'name': 'y', 'type': 'number'},
|
|
555
|
+
{'name': 'textAnchor', 'type': 'string', 'default': 'middle'},
|
|
556
|
+
{'name': 'dominantBaseline', 'type': 'string', 'default': 'middle'}
|
|
557
|
+
]);
|
|
558
|
+
|
|
559
|
+
|
|
560
|
+
// $function: drawTextHeight
|
|
561
|
+
// $group: Drawing
|
|
562
|
+
// $doc: Compute the text's height to fit the width
|
|
563
|
+
// $arg text: The text
|
|
564
|
+
// $arg width: The width of the text. If 0, the default font size (in pixels) is returned.
|
|
565
|
+
// $return: The text's height, in pixels
|
|
566
|
+
function drawTextHeight(args, options) {
|
|
567
|
+
const [text, width] = valueArgsValidate(drawTextHeightArgs, args);
|
|
568
|
+
return width > 0 ? width / (fontWidthRatio * text.length) : options.runtime.drawingFontSizePx;
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
const drawTextHeightArgs = valueArgsModel([
|
|
572
|
+
{'name': 'text', 'type': 'string'},
|
|
573
|
+
{'name': 'width', 'type': 'number'},
|
|
574
|
+
]);
|
|
575
|
+
|
|
576
|
+
|
|
577
|
+
// $function: drawTextStyle
|
|
578
|
+
// $group: Drawing
|
|
579
|
+
// $doc: Set the current text drawing styles
|
|
580
|
+
// $arg fontSizePx: Optional (default is null, the default font size). The text font size, in pixels.
|
|
581
|
+
// $arg textFill: Optional (default is 'black'). The text fill color.
|
|
582
|
+
// $arg bold: Optional (default is false). If true, text is bold.
|
|
583
|
+
// $arg italic: Optional (default is false). If true, text is italic.
|
|
584
|
+
// $arg fontFamily: Optional (default is null, the default font family). The text font family.
|
|
585
|
+
function drawTextStyle(args, options) {
|
|
586
|
+
const [fontSizePx, textFill, bold, italic, fontFamily] = valueArgsValidate(drawTextStyleArgs, args);
|
|
587
|
+
const {runtime} = options;
|
|
588
|
+
runtime.drawingFontSizePx = (fontSizePx !== null ? fontSizePx : options.fontSize * pixelsPerPoint);
|
|
589
|
+
runtime.drawingFontFill = textFill;
|
|
590
|
+
runtime.drawingFontBold = bold;
|
|
591
|
+
runtime.drawingFontItalic = italic;
|
|
592
|
+
runtime.drawingFontFamily = fontFamily;
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
const drawTextStyleArgs = valueArgsModel([
|
|
596
|
+
{'name': 'fontSizePx', 'type': 'number', 'nullable': true},
|
|
597
|
+
{'name': 'textFill', 'type': 'string', 'default': 'black'},
|
|
598
|
+
{'name': 'bold', 'type': 'boolean', 'default': false},
|
|
599
|
+
{'name': 'italic', 'type': 'boolean', 'default': false},
|
|
600
|
+
{'name': 'fontFamily', 'type': 'string', 'default': defaultFontFamily},
|
|
601
|
+
]);
|
|
602
|
+
|
|
603
|
+
|
|
604
|
+
// $function: drawTextWidth
|
|
605
|
+
// $group: Drawing
|
|
606
|
+
// $doc: Compute the text's width
|
|
607
|
+
// $arg text: The text
|
|
608
|
+
// $arg fontSizePx: The text font size, in pixels
|
|
609
|
+
// $return: The text's width, in pixels
|
|
610
|
+
function drawTextWidth(args) {
|
|
611
|
+
const [text, fontSizePx] = valueArgsValidate(drawTextWidthArgs, args);
|
|
612
|
+
return fontWidthRatio * fontSizePx * text.length;
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
const drawTextWidthArgs = valueArgsModel([
|
|
616
|
+
{'name': 'text', 'type': 'string'},
|
|
617
|
+
{'name': 'fontSizePx', 'type': 'number'}
|
|
618
|
+
]);
|
|
619
|
+
|
|
620
|
+
|
|
621
|
+
// $function: drawVLine
|
|
622
|
+
// $group: Drawing
|
|
623
|
+
// $doc: Draw a vertical line from the current point to the end point
|
|
624
|
+
// $arg y: The y-coordinate of the end point
|
|
625
|
+
function drawVLine(args, options) {
|
|
626
|
+
const [y] = valueArgsValidate(drawVLineArgs, args);
|
|
627
|
+
const {runtime} = options;
|
|
628
|
+
runtime.setDrawingPath();
|
|
629
|
+
runtime.drawingPath.push(`V ${y.toFixed(svgPrecision)}`);
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
const drawVLineArgs = valueArgsModel([
|
|
633
|
+
{'name': 'y', 'type': 'number'}
|
|
634
|
+
]);
|
|
635
|
+
|
|
636
|
+
|
|
637
|
+
// $function: drawWidth
|
|
638
|
+
// $group: Drawing
|
|
639
|
+
// $doc: Get the current drawing's width
|
|
640
|
+
// $return: The current drawing's width
|
|
641
|
+
function drawWidth(unusedArgs, options) {
|
|
642
|
+
return options.runtime.drawingWidth;
|
|
643
|
+
}
|
|
644
|
+
|
|
645
|
+
|
|
646
|
+
//
|
|
647
|
+
// Element Model functions
|
|
648
|
+
//
|
|
649
|
+
|
|
650
|
+
|
|
651
|
+
// $function: elementModelRender
|
|
652
|
+
// $group: Element Model
|
|
653
|
+
// $doc: Render an [element model](https://github.com/craigahobbs/element-model#readme)
|
|
654
|
+
// $doc:
|
|
655
|
+
// $doc: **Note:** Element model "callback" members are a map of event name (e.g., "click") to
|
|
656
|
+
// $doc: event callback function. The following events have callback arguments:
|
|
657
|
+
// $doc: - **keydown** - keyCode
|
|
658
|
+
// $doc: - **keypress** - keyCode
|
|
659
|
+
// $doc: - **keyup** - keyCode
|
|
660
|
+
// $arg element: The [element model](https://github.com/craigahobbs/element-model#readme)
|
|
661
|
+
function elementModelRender([elements = null], options) {
|
|
662
|
+
const {runtime} = options;
|
|
663
|
+
runtime.setElements();
|
|
664
|
+
elementModelWrapCallbacks(elements, options);
|
|
665
|
+
runtime.addElements(validateElements(elements));
|
|
666
|
+
}
|
|
661
667
|
|
|
662
668
|
|
|
663
|
-
// Helper function for elementModelRender function
|
|
664
669
|
function elementModelWrapCallbacks(elements, options) {
|
|
665
670
|
// Ignore non-objects
|
|
666
671
|
if (elements === null || typeof elements !== 'object') {
|
|
@@ -712,3 +717,390 @@ function elementModelWrapCallbacks(elements, options) {
|
|
|
712
717
|
}
|
|
713
718
|
}
|
|
714
719
|
}
|
|
720
|
+
|
|
721
|
+
|
|
722
|
+
//
|
|
723
|
+
// Local storage functions
|
|
724
|
+
//
|
|
725
|
+
|
|
726
|
+
|
|
727
|
+
// $function: localStorageClear
|
|
728
|
+
// $group: Local Storage
|
|
729
|
+
// $doc: Clear all keys from the browser's local storage
|
|
730
|
+
function localStorageClear(unusedArgs, options) {
|
|
731
|
+
options.window.localStorage.clear();
|
|
732
|
+
}
|
|
733
|
+
|
|
734
|
+
|
|
735
|
+
// $function: localStorageGet
|
|
736
|
+
// $group: Local Storage
|
|
737
|
+
// $doc: Get a browser local storage key's value
|
|
738
|
+
// $arg key: The key string
|
|
739
|
+
// $return: The local storage value string or null if the key does not exist
|
|
740
|
+
function localStorageGet(args, options) {
|
|
741
|
+
const [key] = valueArgsValidate(localStorageGetArgs, args);
|
|
742
|
+
return options.window.localStorage.getItem(key);
|
|
743
|
+
}
|
|
744
|
+
|
|
745
|
+
const localStorageGetArgs = valueArgsModel([
|
|
746
|
+
{'name': 'key', 'type': 'string'}
|
|
747
|
+
]);
|
|
748
|
+
|
|
749
|
+
|
|
750
|
+
// $function: localStorageRemove
|
|
751
|
+
// $group: Local Storage
|
|
752
|
+
// $doc: Remove a browser local storage key
|
|
753
|
+
// $arg key: The key string
|
|
754
|
+
function localStorageRemove(args, options) {
|
|
755
|
+
const [key] = valueArgsValidate(localStorageRemoveArgs, args);
|
|
756
|
+
return options.window.localStorage.removeItem(key);
|
|
757
|
+
}
|
|
758
|
+
|
|
759
|
+
const localStorageRemoveArgs = valueArgsModel([
|
|
760
|
+
{'name': 'key', 'type': 'string'}
|
|
761
|
+
]);
|
|
762
|
+
|
|
763
|
+
|
|
764
|
+
// $function: localStorageSet
|
|
765
|
+
// $group: Local Storage
|
|
766
|
+
// $doc: Set a browser local storage key's value
|
|
767
|
+
// $arg key: The key string
|
|
768
|
+
// $arg value: The value string
|
|
769
|
+
function localStorageSet(args, options) {
|
|
770
|
+
const [key, value] = valueArgsValidate(localStorageSetArgs, args);
|
|
771
|
+
return options.window.localStorage.setItem(key, value);
|
|
772
|
+
}
|
|
773
|
+
|
|
774
|
+
const localStorageSetArgs = valueArgsModel([
|
|
775
|
+
{'name': 'key', 'type': 'string'},
|
|
776
|
+
{'name': 'value'}
|
|
777
|
+
]);
|
|
778
|
+
|
|
779
|
+
|
|
780
|
+
//
|
|
781
|
+
// Markdown functions
|
|
782
|
+
//
|
|
783
|
+
|
|
784
|
+
|
|
785
|
+
// $function: markdownEscape
|
|
786
|
+
// $group: Markdown
|
|
787
|
+
// $doc: Escape text for inclusion in Markdown text
|
|
788
|
+
// $arg text: The text
|
|
789
|
+
// $return: The escaped text
|
|
790
|
+
function markdownEscape(args) {
|
|
791
|
+
const [text] = valueArgsValidate(markdownEscapeArgs, args);
|
|
792
|
+
return escapeMarkdownText(text);
|
|
793
|
+
}
|
|
794
|
+
|
|
795
|
+
const markdownEscapeArgs = valueArgsModel([
|
|
796
|
+
{'name': 'text', 'type': 'string'}
|
|
797
|
+
]);
|
|
798
|
+
|
|
799
|
+
|
|
800
|
+
// $function: markdownHeaderId
|
|
801
|
+
// $group: Markdown
|
|
802
|
+
// $doc: Compute the Markdown header element ID for some text
|
|
803
|
+
// $arg text: The text
|
|
804
|
+
// $return: The header element ID
|
|
805
|
+
function markdownHeaderId(args) {
|
|
806
|
+
const [text] = valueArgsValidate(markdownHeaderIdArgs, args);
|
|
807
|
+
return markdownModelHeaderId(text);
|
|
808
|
+
}
|
|
809
|
+
|
|
810
|
+
const markdownHeaderIdArgs = valueArgsModel([
|
|
811
|
+
{'name': 'text', 'type': 'string'}
|
|
812
|
+
]);
|
|
813
|
+
|
|
814
|
+
|
|
815
|
+
// $function: markdownParse
|
|
816
|
+
// $group: Markdown
|
|
817
|
+
// $doc: Parse Markdown text
|
|
818
|
+
// $arg lines...: The Markdown text lines (may contain nested arrays of un-split lines)
|
|
819
|
+
// $return: The [Markdown model](https://craigahobbs.github.io/markdown-model/model/#var.vName='Markdown')
|
|
820
|
+
function markdownParse(lines) {
|
|
821
|
+
return parseMarkdown(lines.flat());
|
|
822
|
+
}
|
|
823
|
+
|
|
824
|
+
|
|
825
|
+
// $function: markdownPrint
|
|
826
|
+
// $group: Markdown
|
|
827
|
+
// $doc: Render Markdown text
|
|
828
|
+
// $arg lines...: The Markdown text lines (may contain nested arrays of un-split lines)
|
|
829
|
+
function markdownPrint(lines, options) {
|
|
830
|
+
const {runtime} = options;
|
|
831
|
+
runtime.setMarkdown();
|
|
832
|
+
runtime.addMarkdown(lines);
|
|
833
|
+
}
|
|
834
|
+
|
|
835
|
+
|
|
836
|
+
// $function: markdownTitle
|
|
837
|
+
// $group: Markdown
|
|
838
|
+
// $doc: Compute the title of a [Markdown model](https://craigahobbs.github.io/markdown-model/model/#var.vName='Markdown')
|
|
839
|
+
// $arg markdownModel: The [Markdown model](https://craigahobbs.github.io/markdown-model/model/#var.vName='Markdown')
|
|
840
|
+
// $return: The Markdown title or null if there is no title
|
|
841
|
+
function markdownTitle(args) {
|
|
842
|
+
const [markdownModel] = valueArgsValidate(markdownTitleArgs, args);
|
|
843
|
+
return getMarkdownTitle(markdownModel);
|
|
844
|
+
}
|
|
845
|
+
|
|
846
|
+
const markdownTitleArgs = valueArgsModel([
|
|
847
|
+
{'name': 'markdownModel', 'type': 'object'},
|
|
848
|
+
]);
|
|
849
|
+
|
|
850
|
+
|
|
851
|
+
//
|
|
852
|
+
// Schema functions
|
|
853
|
+
//
|
|
854
|
+
|
|
855
|
+
|
|
856
|
+
// $function: schemaElements
|
|
857
|
+
// $group: Schema
|
|
858
|
+
// $doc: Get a schema type's documentation [element model](https://github.com/craigahobbs/element-model#readme).
|
|
859
|
+
// $doc: Render the element model with the [elementModelRender](#var.vName='elementModelRender') function.
|
|
860
|
+
// $arg types: The [type model](https://craigahobbs.github.io/schema-markdown-doc/doc/#var.vName='Types')
|
|
861
|
+
// $arg typeName: The type name
|
|
862
|
+
// $arg actionURLs: Optional (default is null). The
|
|
863
|
+
// $arg actionURLs: [action URL overrides](https://craigahobbs.github.io/schema-markdown-doc/doc/#var.vName='ActionURL').
|
|
864
|
+
// $return: The schema type's documentation [element model](https://github.com/craigahobbs/element-model#readme)
|
|
865
|
+
function schemaElements(args, options) {
|
|
866
|
+
const [types, typeName, actionURLs = null] = valueArgsValidate(schemaElementsArgs, args);
|
|
867
|
+
const params = encodeQueryString(options.params);
|
|
868
|
+
const schemaOptions = {params};
|
|
869
|
+
if (actionURLs !== null) {
|
|
870
|
+
schemaOptions.actionURLs = actionURLs;
|
|
871
|
+
}
|
|
872
|
+
return schemaMarkdownDoc(types, typeName, schemaOptions);
|
|
873
|
+
}
|
|
874
|
+
|
|
875
|
+
const schemaElementsArgs = valueArgsModel([
|
|
876
|
+
{'name': 'types', 'type': 'object'},
|
|
877
|
+
{'name': 'typeName', 'type': 'string'},
|
|
878
|
+
{'name': 'actionURLs', 'type': 'array', 'nullable': true}
|
|
879
|
+
]);
|
|
880
|
+
|
|
881
|
+
|
|
882
|
+
//
|
|
883
|
+
// Session storage functions
|
|
884
|
+
//
|
|
885
|
+
|
|
886
|
+
|
|
887
|
+
// $function: sessionStorageClear
|
|
888
|
+
// $group: Session Storage
|
|
889
|
+
// $doc: Clear all keys from the browser's session storage
|
|
890
|
+
function sessionStorageClear(unusedArgs, options) {
|
|
891
|
+
return options.window.sessionStorage.clear();
|
|
892
|
+
}
|
|
893
|
+
|
|
894
|
+
|
|
895
|
+
// $function: sessionStorageGet
|
|
896
|
+
// $group: Session Storage
|
|
897
|
+
// $doc: Get a browser session storage key's value
|
|
898
|
+
// $arg key: The key string
|
|
899
|
+
// $return: The session storage value string or null if the key does not exist
|
|
900
|
+
function sessionStorageGet(args, options) {
|
|
901
|
+
const [key] = valueArgsValidate(sessionStorageGetArgs, args);
|
|
902
|
+
return options.window.sessionStorage.getItem(key);
|
|
903
|
+
}
|
|
904
|
+
|
|
905
|
+
const sessionStorageGetArgs = valueArgsModel([
|
|
906
|
+
{'name': 'key', 'type': 'string'}
|
|
907
|
+
]);
|
|
908
|
+
|
|
909
|
+
|
|
910
|
+
// $function: sessionStorageRemove
|
|
911
|
+
// $group: Session Storage
|
|
912
|
+
// $doc: Remove a browser session storage key
|
|
913
|
+
// $arg key: The key string
|
|
914
|
+
function sessionStorageRemove(args, options) {
|
|
915
|
+
const [key] = valueArgsValidate(sessionStorageRemoveArgs, args);
|
|
916
|
+
return options.window.sessionStorage.removeItem(key);
|
|
917
|
+
}
|
|
918
|
+
|
|
919
|
+
const sessionStorageRemoveArgs = valueArgsModel([
|
|
920
|
+
{'name': 'key', 'type': 'string'}
|
|
921
|
+
]);
|
|
922
|
+
|
|
923
|
+
|
|
924
|
+
// $function: sessionStorageSet
|
|
925
|
+
// $group: Session Storage
|
|
926
|
+
// $doc: Set a browser session storage key's value
|
|
927
|
+
// $arg key: The key string
|
|
928
|
+
// $arg value: The value string
|
|
929
|
+
function sessionStorageSet(args, options) {
|
|
930
|
+
const [key, value] = valueArgsValidate(sessionStorageSetArgs, args);
|
|
931
|
+
return options.window.sessionStorage.setItem(key, value);
|
|
932
|
+
}
|
|
933
|
+
|
|
934
|
+
const sessionStorageSetArgs = valueArgsModel([
|
|
935
|
+
{'name': 'key', 'type': 'string'},
|
|
936
|
+
{'name': 'value'}
|
|
937
|
+
]);
|
|
938
|
+
|
|
939
|
+
|
|
940
|
+
//
|
|
941
|
+
// URL functions
|
|
942
|
+
//
|
|
943
|
+
|
|
944
|
+
|
|
945
|
+
// $function: urlObjectCreate
|
|
946
|
+
// $group: URL
|
|
947
|
+
// $doc: Create an object URL (i.e. a file download URL)
|
|
948
|
+
// $arg data: The object data string
|
|
949
|
+
// $arg contentType: Optional (default is "text/plain"). The object content type.
|
|
950
|
+
// $return: The object URL string
|
|
951
|
+
function urlObjectCreate(args, options) {
|
|
952
|
+
const [data, contentType] = valueArgsValidate(urlObjectCreateArgs, args);
|
|
953
|
+
return options.window.URL.createObjectURL(new Blob([data], {'type': contentType}));
|
|
954
|
+
}
|
|
955
|
+
|
|
956
|
+
const urlObjectCreateArgs = valueArgsModel([
|
|
957
|
+
{'name': 'data', 'type': 'string'},
|
|
958
|
+
{'name': 'contentType', 'type': 'string', 'default': 'text/plain'}
|
|
959
|
+
]);
|
|
960
|
+
|
|
961
|
+
|
|
962
|
+
//
|
|
963
|
+
// Window functions
|
|
964
|
+
//
|
|
965
|
+
|
|
966
|
+
|
|
967
|
+
// $function: windowHeight
|
|
968
|
+
// $group: Window
|
|
969
|
+
// $doc: Get the browser window's height
|
|
970
|
+
// $return: The browser window's height
|
|
971
|
+
function windowHeight(unusedArgs, options) {
|
|
972
|
+
return options.window.innerHeight;
|
|
973
|
+
}
|
|
974
|
+
|
|
975
|
+
|
|
976
|
+
// $function: windowSetLocation
|
|
977
|
+
// $group: Window
|
|
978
|
+
// $doc: Navigate the browser window to a location URL
|
|
979
|
+
// $arg url: The new location URL
|
|
980
|
+
function windowSetLocation(args, options) {
|
|
981
|
+
const [location] = valueArgsValidate(windowSetLocationArgs, args);
|
|
982
|
+
const {runtime} = options;
|
|
983
|
+
runtime.windowLocation = options.urlFn(location);
|
|
984
|
+
}
|
|
985
|
+
|
|
986
|
+
const windowSetLocationArgs = valueArgsModel([
|
|
987
|
+
{'name': 'url', 'type': 'string'}
|
|
988
|
+
]);
|
|
989
|
+
|
|
990
|
+
|
|
991
|
+
// $function: windowSetResize
|
|
992
|
+
// $group: Window
|
|
993
|
+
// $doc: Set the browser window resize event handler
|
|
994
|
+
// $arg callback: The window resize callback function
|
|
995
|
+
function windowSetResize(args, options) {
|
|
996
|
+
const [callback] = valueArgsValidate(windowSetResizeArgs, args);
|
|
997
|
+
const {runtime} = options;
|
|
998
|
+
runtime.windowResize = async () => {
|
|
999
|
+
options.statementCount = 0;
|
|
1000
|
+
try {
|
|
1001
|
+
await callback([], options);
|
|
1002
|
+
} catch ({message}) {
|
|
1003
|
+
if ('logFn' in options && options.debug) {
|
|
1004
|
+
options.logFn(`MarkdownUp: Error executing windowSetResize callback: ${message}`);
|
|
1005
|
+
}
|
|
1006
|
+
}
|
|
1007
|
+
options.runtimeUpdateFn();
|
|
1008
|
+
};
|
|
1009
|
+
}
|
|
1010
|
+
|
|
1011
|
+
const windowSetResizeArgs = valueArgsModel([
|
|
1012
|
+
{'name': 'callback', 'type': 'function'}
|
|
1013
|
+
]);
|
|
1014
|
+
|
|
1015
|
+
|
|
1016
|
+
// $function: windowSetTimeout
|
|
1017
|
+
// $group: Window
|
|
1018
|
+
// $doc: Set the browser window timeout event handler
|
|
1019
|
+
// $arg callback: The window timeout callback function
|
|
1020
|
+
// $arg delay: The delay, in milliseconds, to ellapse before calling the timeout
|
|
1021
|
+
function windowSetTimeout(args, options) {
|
|
1022
|
+
const [callback, delay] = valueArgsValidate(windowSetTimeoutArgs, args);
|
|
1023
|
+
const {runtime} = options;
|
|
1024
|
+
runtime.windowTimeout = [
|
|
1025
|
+
async () => {
|
|
1026
|
+
options.statementCount = 0;
|
|
1027
|
+
try {
|
|
1028
|
+
await callback([], options);
|
|
1029
|
+
} catch ({message}) {
|
|
1030
|
+
if ('logFn' in options && options.debug) {
|
|
1031
|
+
options.logFn(`MarkdownUp: Error executing windowSetTimeout callback: ${message}`);
|
|
1032
|
+
}
|
|
1033
|
+
}
|
|
1034
|
+
options.runtimeUpdateFn();
|
|
1035
|
+
},
|
|
1036
|
+
delay
|
|
1037
|
+
];
|
|
1038
|
+
}
|
|
1039
|
+
|
|
1040
|
+
const windowSetTimeoutArgs = valueArgsModel([
|
|
1041
|
+
{'name': 'callback', 'type': 'function'},
|
|
1042
|
+
{'name': 'delay', 'type': 'number'}
|
|
1043
|
+
]);
|
|
1044
|
+
|
|
1045
|
+
|
|
1046
|
+
// $function: windowWidth
|
|
1047
|
+
// $group: Window
|
|
1048
|
+
// $doc: Get the browser window's width
|
|
1049
|
+
// $return: The browser window's width
|
|
1050
|
+
function windowWidth(unusedArgs, options) {
|
|
1051
|
+
return options.window.innerWidth;
|
|
1052
|
+
}
|
|
1053
|
+
|
|
1054
|
+
|
|
1055
|
+
// markdown-script library functions
|
|
1056
|
+
export const markdownScriptFunctions = {
|
|
1057
|
+
dataLineChart,
|
|
1058
|
+
dataTable,
|
|
1059
|
+
documentFontSize,
|
|
1060
|
+
documentInputValue,
|
|
1061
|
+
documentSetFocus,
|
|
1062
|
+
documentSetReset,
|
|
1063
|
+
documentSetTitle,
|
|
1064
|
+
documentURL,
|
|
1065
|
+
drawArc,
|
|
1066
|
+
drawCircle,
|
|
1067
|
+
drawClose,
|
|
1068
|
+
drawEllipse,
|
|
1069
|
+
drawHLine,
|
|
1070
|
+
drawHeight,
|
|
1071
|
+
drawImage,
|
|
1072
|
+
drawLine,
|
|
1073
|
+
drawMove,
|
|
1074
|
+
drawNew,
|
|
1075
|
+
drawOnClick,
|
|
1076
|
+
drawPathRect,
|
|
1077
|
+
drawRect,
|
|
1078
|
+
drawStyle,
|
|
1079
|
+
drawText,
|
|
1080
|
+
drawTextHeight,
|
|
1081
|
+
drawTextStyle,
|
|
1082
|
+
drawTextWidth,
|
|
1083
|
+
drawVLine,
|
|
1084
|
+
drawWidth,
|
|
1085
|
+
elementModelRender,
|
|
1086
|
+
localStorageClear,
|
|
1087
|
+
localStorageGet,
|
|
1088
|
+
localStorageRemove,
|
|
1089
|
+
localStorageSet,
|
|
1090
|
+
markdownEscape,
|
|
1091
|
+
markdownHeaderId,
|
|
1092
|
+
markdownParse,
|
|
1093
|
+
markdownPrint,
|
|
1094
|
+
markdownTitle,
|
|
1095
|
+
schemaElements,
|
|
1096
|
+
sessionStorageClear,
|
|
1097
|
+
sessionStorageGet,
|
|
1098
|
+
sessionStorageRemove,
|
|
1099
|
+
sessionStorageSet,
|
|
1100
|
+
urlObjectCreate,
|
|
1101
|
+
windowHeight,
|
|
1102
|
+
windowSetLocation,
|
|
1103
|
+
windowSetResize,
|
|
1104
|
+
windowSetTimeout,
|
|
1105
|
+
windowWidth
|
|
1106
|
+
};
|