markdown-up 3.3.1 → 3.3.3
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/lib/lineChart.js +3 -3
- package/lib/script.js +8 -0
- package/lib/scriptLibrary.js +102 -16
- package/package.json +2 -2
package/lib/lineChart.js
CHANGED
|
@@ -61,10 +61,10 @@ struct LineChartAxisTicks
|
|
|
61
61
|
optional int(>= 0) count
|
|
62
62
|
|
|
63
63
|
# The value of the first tick mark. Default is the minimum axis value.
|
|
64
|
-
optional
|
|
64
|
+
optional any start
|
|
65
65
|
|
|
66
66
|
# The value of the last tick mark. Default is the maximum axis value.
|
|
67
|
-
optional
|
|
67
|
+
optional any end
|
|
68
68
|
|
|
69
69
|
# The number of tick mark labels to skip after a rendered label
|
|
70
70
|
optional int(> 0) skip
|
|
@@ -74,7 +74,7 @@ struct LineChartAxisTicks
|
|
|
74
74
|
struct LineChartAxisAnnotation
|
|
75
75
|
|
|
76
76
|
# The axis value
|
|
77
|
-
|
|
77
|
+
any value
|
|
78
78
|
|
|
79
79
|
# The annotation label
|
|
80
80
|
optional string label
|
package/lib/script.js
CHANGED
|
@@ -134,6 +134,7 @@ export class MarkdownScriptRuntime {
|
|
|
134
134
|
this.windowLocation = null;
|
|
135
135
|
this.windowResize = null;
|
|
136
136
|
this.windowTimeout = null;
|
|
137
|
+
this.eventQueue = Promise.resolve();
|
|
137
138
|
|
|
138
139
|
// Drawing-path and Markdown function state
|
|
139
140
|
this.drawingPath = null;
|
|
@@ -170,6 +171,13 @@ export class MarkdownScriptRuntime {
|
|
|
170
171
|
}
|
|
171
172
|
|
|
172
173
|
|
|
174
|
+
// Handle a runtime event
|
|
175
|
+
eventHandle(callback) {
|
|
176
|
+
this.eventQueue = this.eventQueue.then(callback);
|
|
177
|
+
return this.eventQueue;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
|
|
173
181
|
// Reset the runtime elements
|
|
174
182
|
resetElements() {
|
|
175
183
|
let elements = null;
|
package/lib/scriptLibrary.js
CHANGED
|
@@ -75,6 +75,23 @@ const dataTableArgs = valueArgsModel([
|
|
|
75
75
|
//
|
|
76
76
|
|
|
77
77
|
|
|
78
|
+
// $function: documentElementClick
|
|
79
|
+
// $group: Document
|
|
80
|
+
// $doc: Click an element
|
|
81
|
+
// $arg id: The element ID
|
|
82
|
+
function documentElementClick(args, options) {
|
|
83
|
+
const [id] = valueArgsValidate(documentElementClickArgs, args);
|
|
84
|
+
const element = options.window.document.getElementById(id) ?? null;
|
|
85
|
+
if (element !== null) {
|
|
86
|
+
element.click();
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const documentElementClickArgs = valueArgsModel([
|
|
91
|
+
{'name': 'id', 'type': 'string'}
|
|
92
|
+
]);
|
|
93
|
+
|
|
94
|
+
|
|
78
95
|
// $function: documentFontSize
|
|
79
96
|
// $group: Document
|
|
80
97
|
// $doc: Get the document font size
|
|
@@ -84,6 +101,68 @@ function documentFontSize(unusedArgs, options) {
|
|
|
84
101
|
}
|
|
85
102
|
|
|
86
103
|
|
|
104
|
+
// $function: documentInputFileText
|
|
105
|
+
// $group: Document
|
|
106
|
+
// $doc: Read files as text from a file input element
|
|
107
|
+
// $arg id: The input element ID
|
|
108
|
+
// $return: The array of file text, or null if the element does not exist
|
|
109
|
+
async function documentInputFileText(args, options) {
|
|
110
|
+
const [id] = valueArgsValidate(documentInputFileTextArgs, args);
|
|
111
|
+
const element = options.window.document.getElementById(id) ?? null;
|
|
112
|
+
if (element === null) {
|
|
113
|
+
return null;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// Read the files
|
|
117
|
+
const files = [];
|
|
118
|
+
for (const file of element.files) {
|
|
119
|
+
const reader = new options.window.FileReader();
|
|
120
|
+
const text = await new Promise((resolve, reject) => {
|
|
121
|
+
reader.onload = () => resolve(reader.result);
|
|
122
|
+
reader.onerror = () => reject(reader.error);
|
|
123
|
+
reader.readAsText(file);
|
|
124
|
+
});
|
|
125
|
+
files.push(text);
|
|
126
|
+
}
|
|
127
|
+
return files;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
const documentInputFileTextArgs = valueArgsModel([
|
|
131
|
+
{'name': 'id', 'type': 'string'}
|
|
132
|
+
]);
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
// $function: documentInputFileURL
|
|
136
|
+
// $group: Document
|
|
137
|
+
// $doc: Read files as data URLs from a file input element
|
|
138
|
+
// $arg id: The input element ID
|
|
139
|
+
// $return: The array of file data URL strings, or null if the element does not exist
|
|
140
|
+
async function documentInputFileURL(args, options) {
|
|
141
|
+
const [id] = valueArgsValidate(documentInputFileURLArgs, args);
|
|
142
|
+
const element = options.window.document.getElementById(id) ?? null;
|
|
143
|
+
if (element === null) {
|
|
144
|
+
return null;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// Read the files
|
|
148
|
+
const files = [];
|
|
149
|
+
for (const file of element.files) {
|
|
150
|
+
const reader = new options.window.FileReader();
|
|
151
|
+
const dataURL = await new Promise((resolve, reject) => {
|
|
152
|
+
reader.onload = () => resolve(reader.result);
|
|
153
|
+
reader.onerror = () => reject(reader.error);
|
|
154
|
+
reader.readAsDataURL(file);
|
|
155
|
+
});
|
|
156
|
+
files.push(dataURL);
|
|
157
|
+
}
|
|
158
|
+
return files;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
const documentInputFileURLArgs = valueArgsModel([
|
|
162
|
+
{'name': 'id', 'type': 'string'}
|
|
163
|
+
]);
|
|
164
|
+
|
|
165
|
+
|
|
87
166
|
// $function: documentInputValue
|
|
88
167
|
// $group: Document
|
|
89
168
|
// $doc: Get an input element's value
|
|
@@ -1021,15 +1100,17 @@ function windowSetResize(args, options) {
|
|
|
1021
1100
|
const [callback] = valueArgsValidate(windowSetResizeArgs, args);
|
|
1022
1101
|
const {runtime} = options;
|
|
1023
1102
|
runtime.windowResize = async () => {
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
options.
|
|
1103
|
+
await runtime.eventHandle(async () => {
|
|
1104
|
+
options.statementCount = 0;
|
|
1105
|
+
try {
|
|
1106
|
+
await callback([], options);
|
|
1107
|
+
} catch ({message}) {
|
|
1108
|
+
if (options.debug) {
|
|
1109
|
+
options.logFn(`MarkdownUp: Error executing windowSetResize callback: ${message}`);
|
|
1110
|
+
}
|
|
1030
1111
|
}
|
|
1031
|
-
|
|
1032
|
-
|
|
1112
|
+
options.runtimeUpdateFn();
|
|
1113
|
+
});
|
|
1033
1114
|
};
|
|
1034
1115
|
}
|
|
1035
1116
|
|
|
@@ -1048,15 +1129,17 @@ function windowSetTimeout(args, options) {
|
|
|
1048
1129
|
const {runtime} = options;
|
|
1049
1130
|
runtime.windowTimeout = [
|
|
1050
1131
|
async () => {
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
options.
|
|
1132
|
+
await runtime.eventHandle(async () => {
|
|
1133
|
+
options.statementCount = 0;
|
|
1134
|
+
try {
|
|
1135
|
+
await callback([], options);
|
|
1136
|
+
} catch ({message}) {
|
|
1137
|
+
if (options.debug) {
|
|
1138
|
+
options.logFn(`MarkdownUp: Error executing windowSetTimeout callback: ${message}`);
|
|
1139
|
+
}
|
|
1057
1140
|
}
|
|
1058
|
-
|
|
1059
|
-
|
|
1141
|
+
options.runtimeUpdateFn();
|
|
1142
|
+
});
|
|
1060
1143
|
},
|
|
1061
1144
|
delay
|
|
1062
1145
|
];
|
|
@@ -1081,7 +1164,10 @@ function windowWidth(unusedArgs, options) {
|
|
|
1081
1164
|
export const markdownScriptFunctions = {
|
|
1082
1165
|
dataLineChart,
|
|
1083
1166
|
dataTable,
|
|
1167
|
+
documentElementClick,
|
|
1084
1168
|
documentFontSize,
|
|
1169
|
+
documentInputFileText,
|
|
1170
|
+
documentInputFileURL,
|
|
1085
1171
|
documentInputValue,
|
|
1086
1172
|
documentSetFocus,
|
|
1087
1173
|
documentSetReset,
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"type": "module",
|
|
3
3
|
"name": "markdown-up",
|
|
4
|
-
"version": "3.3.
|
|
4
|
+
"version": "3.3.3",
|
|
5
5
|
"description": "MarkdownUp is a Markdown viewer",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"markdown",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"c8": "~10.1",
|
|
33
|
-
"eslint": "~9.
|
|
33
|
+
"eslint": "~9.16",
|
|
34
34
|
"jsdoc": "~4.0",
|
|
35
35
|
"jsdom": "~25.0"
|
|
36
36
|
}
|