markdown-up 3.3.2 → 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/scriptLibrary.js +82 -0
- package/package.json +2 -2
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
|
|
@@ -1085,7 +1164,10 @@ function windowWidth(unusedArgs, options) {
|
|
|
1085
1164
|
export const markdownScriptFunctions = {
|
|
1086
1165
|
dataLineChart,
|
|
1087
1166
|
dataTable,
|
|
1167
|
+
documentElementClick,
|
|
1088
1168
|
documentFontSize,
|
|
1169
|
+
documentInputFileText,
|
|
1170
|
+
documentInputFileURL,
|
|
1089
1171
|
documentInputValue,
|
|
1090
1172
|
documentSetFocus,
|
|
1091
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
|
}
|