@plasius/learning-runtime 0.0.0-stage → 0.1.2
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/LICENSE +203 -0
- package/README.md +169 -2
- package/dist/chunk-2YWUDCGJ.js +189 -0
- package/dist/chunk-2YWUDCGJ.js.map +1 -0
- package/dist/chunk-XDTWUCFP.js +213 -0
- package/dist/chunk-XDTWUCFP.js.map +1 -0
- package/dist/cpp.cjs +563 -0
- package/dist/cpp.cjs.map +1 -0
- package/dist/cpp.d.cts +33 -0
- package/dist/cpp.d.ts +33 -0
- package/dist/cpp.js +535 -0
- package/dist/cpp.js.map +1 -0
- package/dist/index.cjs +244 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +17 -0
- package/dist/index.js.map +1 -0
- package/dist/javascript.cjs +226 -0
- package/dist/javascript.cjs.map +1 -0
- package/dist/javascript.d.cts +45 -0
- package/dist/javascript.d.ts +45 -0
- package/dist/javascript.js +13 -0
- package/dist/javascript.js.map +1 -0
- package/dist/javascript.worker.cjs +252 -0
- package/dist/javascript.worker.cjs.map +1 -0
- package/dist/javascript.worker.d.cts +2 -0
- package/dist/javascript.worker.d.ts +2 -0
- package/dist/javascript.worker.js +50 -0
- package/dist/javascript.worker.js.map +1 -0
- package/dist/maze.cjs +242 -0
- package/dist/maze.cjs.map +1 -0
- package/dist/maze.d.cts +85 -0
- package/dist/maze.d.ts +85 -0
- package/dist/maze.js +17 -0
- package/dist/maze.js.map +1 -0
- package/dist/server.cjs +232 -0
- package/dist/server.cjs.map +1 -0
- package/dist/server.d.cts +25 -0
- package/dist/server.d.ts +25 -0
- package/dist/server.js +149 -0
- package/dist/server.js.map +1 -0
- package/dist/web.cjs +600 -0
- package/dist/web.cjs.map +1 -0
- package/dist/web.d.cts +80 -0
- package/dist/web.d.ts +80 -0
- package/dist/web.js +513 -0
- package/dist/web.js.map +1 -0
- package/package.json +115 -4
package/dist/web.cjs
ADDED
|
@@ -0,0 +1,600 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/web.ts
|
|
21
|
+
var web_exports = {};
|
|
22
|
+
__export(web_exports, {
|
|
23
|
+
WEB_PROJECT_LIMITS: () => WEB_PROJECT_LIMITS,
|
|
24
|
+
WebProjectError: () => WebProjectError,
|
|
25
|
+
createWebProject: () => createWebProject
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(web_exports);
|
|
28
|
+
|
|
29
|
+
// src/javascript.ts
|
|
30
|
+
var JAVASCRIPT_PROJECT_LIMITS = Object.freeze({
|
|
31
|
+
sourceCharacters: 64e3,
|
|
32
|
+
jsonCharacters: 64e3,
|
|
33
|
+
memoryBytes: 16 * 1024 * 1024,
|
|
34
|
+
stackBytes: 256 * 1024,
|
|
35
|
+
executionMs: 100,
|
|
36
|
+
maximumExecutionMs: 500,
|
|
37
|
+
calls: 1e4,
|
|
38
|
+
arguments: 8,
|
|
39
|
+
jsonDepth: 20,
|
|
40
|
+
jsonNodes: 4096
|
|
41
|
+
});
|
|
42
|
+
var JavaScriptProjectRuntimeError = class extends Error {
|
|
43
|
+
constructor(code) {
|
|
44
|
+
super(`Learning project: ${code}`);
|
|
45
|
+
this.code = code;
|
|
46
|
+
this.name = "JavaScriptProjectRuntimeError";
|
|
47
|
+
}
|
|
48
|
+
code;
|
|
49
|
+
};
|
|
50
|
+
var invalid = () => {
|
|
51
|
+
throw new JavaScriptProjectRuntimeError("INVALID_INPUT");
|
|
52
|
+
};
|
|
53
|
+
function serializeProjectJson(value) {
|
|
54
|
+
const seen = /* @__PURE__ */ new Set();
|
|
55
|
+
let nodes = 0;
|
|
56
|
+
function visit(value2, depth) {
|
|
57
|
+
if (++nodes > JAVASCRIPT_PROJECT_LIMITS.jsonNodes || depth > JAVASCRIPT_PROJECT_LIMITS.jsonDepth) return invalid();
|
|
58
|
+
if (value2 === null || typeof value2 === "boolean") return;
|
|
59
|
+
if (typeof value2 === "string") {
|
|
60
|
+
if (value2.length > JAVASCRIPT_PROJECT_LIMITS.jsonCharacters) return invalid();
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
if (typeof value2 === "number") {
|
|
64
|
+
if (!Number.isFinite(value2)) return invalid();
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
if (typeof value2 !== "object" || seen.has(value2)) return invalid();
|
|
68
|
+
const array = Array.isArray(value2);
|
|
69
|
+
const prototype = Object.getPrototypeOf(value2);
|
|
70
|
+
if (prototype !== (array ? Array.prototype : Object.prototype) && prototype !== null) return invalid();
|
|
71
|
+
seen.add(value2);
|
|
72
|
+
const descriptors = Object.getOwnPropertyDescriptors(value2);
|
|
73
|
+
const keys = Object.keys(descriptors);
|
|
74
|
+
if (Object.getOwnPropertySymbols(value2).length || keys.length > JAVASCRIPT_PROJECT_LIMITS.jsonNodes) return invalid();
|
|
75
|
+
if (array && (value2.length > JAVASCRIPT_PROJECT_LIMITS.jsonNodes || keys.length !== value2.length + 1)) return invalid();
|
|
76
|
+
for (const key of keys) {
|
|
77
|
+
if (array && key === "length") continue;
|
|
78
|
+
const descriptor = descriptors[key];
|
|
79
|
+
if (key.length > 160 || descriptor.get || descriptor.set || !descriptor.enumerable) return invalid();
|
|
80
|
+
if (array && !/^(0|[1-9][0-9]*)$/u.test(key)) return invalid();
|
|
81
|
+
visit(descriptor.value, depth + 1);
|
|
82
|
+
}
|
|
83
|
+
seen.delete(value2);
|
|
84
|
+
}
|
|
85
|
+
visit(value, 0);
|
|
86
|
+
const json = JSON.stringify(value);
|
|
87
|
+
if (json.length > JAVASCRIPT_PROJECT_LIMITS.jsonCharacters) return invalid();
|
|
88
|
+
return json;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// src/web-html.ts
|
|
92
|
+
var import_parse5 = require("parse5");
|
|
93
|
+
|
|
94
|
+
// src/web-model.ts
|
|
95
|
+
var WEB_PROJECT_LIMITS = Object.freeze({
|
|
96
|
+
htmlCharacters: 24e3,
|
|
97
|
+
cssCharacters: 16e3,
|
|
98
|
+
templateNodes: 256,
|
|
99
|
+
templateDepth: 20,
|
|
100
|
+
attributes: 16,
|
|
101
|
+
attributeCharacters: 240,
|
|
102
|
+
cssNodes: 2048,
|
|
103
|
+
cssDepth: 16,
|
|
104
|
+
repeatedItems: 50,
|
|
105
|
+
projectedNodes: 768,
|
|
106
|
+
outputCharacters: 64e3
|
|
107
|
+
});
|
|
108
|
+
var WebProjectError = class extends Error {
|
|
109
|
+
constructor(code) {
|
|
110
|
+
super(`Web project: ${code}`);
|
|
111
|
+
this.code = code;
|
|
112
|
+
this.name = "WebProjectError";
|
|
113
|
+
}
|
|
114
|
+
code;
|
|
115
|
+
};
|
|
116
|
+
var WEB_TAGS = /* @__PURE__ */ new Set([
|
|
117
|
+
"main",
|
|
118
|
+
"section",
|
|
119
|
+
"article",
|
|
120
|
+
"aside",
|
|
121
|
+
"header",
|
|
122
|
+
"footer",
|
|
123
|
+
"nav",
|
|
124
|
+
"div",
|
|
125
|
+
"span",
|
|
126
|
+
"p",
|
|
127
|
+
"h1",
|
|
128
|
+
"h2",
|
|
129
|
+
"h3",
|
|
130
|
+
"h4",
|
|
131
|
+
"h5",
|
|
132
|
+
"h6",
|
|
133
|
+
"strong",
|
|
134
|
+
"em",
|
|
135
|
+
"small",
|
|
136
|
+
"code",
|
|
137
|
+
"pre",
|
|
138
|
+
"blockquote",
|
|
139
|
+
"ul",
|
|
140
|
+
"ol",
|
|
141
|
+
"li",
|
|
142
|
+
"dl",
|
|
143
|
+
"dt",
|
|
144
|
+
"dd",
|
|
145
|
+
"table",
|
|
146
|
+
"caption",
|
|
147
|
+
"thead",
|
|
148
|
+
"tbody",
|
|
149
|
+
"tfoot",
|
|
150
|
+
"tr",
|
|
151
|
+
"th",
|
|
152
|
+
"td",
|
|
153
|
+
"form",
|
|
154
|
+
"fieldset",
|
|
155
|
+
"legend",
|
|
156
|
+
"label",
|
|
157
|
+
"input",
|
|
158
|
+
"textarea",
|
|
159
|
+
"select",
|
|
160
|
+
"option",
|
|
161
|
+
"button",
|
|
162
|
+
"output",
|
|
163
|
+
"progress",
|
|
164
|
+
"meter",
|
|
165
|
+
"br",
|
|
166
|
+
"hr",
|
|
167
|
+
"details",
|
|
168
|
+
"summary"
|
|
169
|
+
]);
|
|
170
|
+
var WEB_VOID_TAGS = /* @__PURE__ */ new Set(["input", "br", "hr"]);
|
|
171
|
+
var WEB_CONTROLS = /* @__PURE__ */ new Set(["input", "textarea", "select", "button"]);
|
|
172
|
+
var WEB_INPUT_TYPES = /* @__PURE__ */ new Set(["text", "number", "range", "checkbox"]);
|
|
173
|
+
var WEB_BINDINGS = /* @__PURE__ */ new Set(["text", "value", "checked", "disabled", "pressed", "invalid", "label", "if"]);
|
|
174
|
+
var forbiddenNames = /* @__PURE__ */ new Set(["__proto__", "prototype", "constructor"]);
|
|
175
|
+
function webIdentifier(value) {
|
|
176
|
+
return /^[a-zA-Z][a-zA-Z0-9_-]{0,47}$/u.test(value) && !forbiddenNames.has(value);
|
|
177
|
+
}
|
|
178
|
+
function webPath(value) {
|
|
179
|
+
const parts = value.split(".");
|
|
180
|
+
return value.length <= 128 && parts.length <= 4 && parts.every((part) => /^[a-zA-Z][a-zA-Z0-9_]{0,31}$/u.test(part) && !forbiddenNames.has(part));
|
|
181
|
+
}
|
|
182
|
+
var webSourceError = () => {
|
|
183
|
+
throw new WebProjectError("INVALID_SOURCE");
|
|
184
|
+
};
|
|
185
|
+
var webLimitError = () => {
|
|
186
|
+
throw new WebProjectError("LIMIT_EXCEEDED");
|
|
187
|
+
};
|
|
188
|
+
var webViewError = () => {
|
|
189
|
+
throw new WebProjectError("INVALID_VIEW");
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
// src/web-html.ts
|
|
193
|
+
var globalText = /* @__PURE__ */ new Set(["title", "aria-label", "aria-description"]);
|
|
194
|
+
var references = /* @__PURE__ */ new Set(["for", "aria-labelledby", "aria-describedby", "aria-controls"]);
|
|
195
|
+
var booleanAttributes = /* @__PURE__ */ new Set(["hidden", "disabled", "checked", "required", "readonly", "selected", "open", "novalidate"]);
|
|
196
|
+
var numericAttributes = /* @__PURE__ */ new Set(["min", "max", "step", "value", "maxlength", "rows", "cols", "colspan", "rowspan"]);
|
|
197
|
+
var roles = /* @__PURE__ */ new Set(["status", "alert", "group", "region", "list", "listitem", "note", "progressbar", "presentation", "none"]);
|
|
198
|
+
function attributes(tag, values) {
|
|
199
|
+
if (values.length > WEB_PROJECT_LIMITS.attributes) return webLimitError();
|
|
200
|
+
const output = {};
|
|
201
|
+
for (const { name, value, namespace } of values) {
|
|
202
|
+
if (namespace || Object.hasOwn(output, name) || value.length > WEB_PROJECT_LIMITS.attributeCharacters || [...value].some((character) => character.charCodeAt(0) < 32 && ![9, 10, 13].includes(character.charCodeAt(0)))) return webSourceError();
|
|
203
|
+
if (name.startsWith("data-")) {
|
|
204
|
+
const key = name.slice(5);
|
|
205
|
+
if (key === "action") {
|
|
206
|
+
if (!webIdentifier(value) || tag !== "button" && tag !== "form") return webSourceError();
|
|
207
|
+
} else if (key === "repeat" || key === "id" || WEB_BINDINGS.has(key)) {
|
|
208
|
+
if (!webPath(value)) return webSourceError();
|
|
209
|
+
if (key === "checked" && tag !== "input") return webSourceError();
|
|
210
|
+
if (key === "disabled" && !WEB_CONTROLS.has(tag)) return webSourceError();
|
|
211
|
+
if (key === "invalid" && !["input", "textarea", "select"].includes(tag)) return webSourceError();
|
|
212
|
+
if (key === "pressed" && tag !== "button") return webSourceError();
|
|
213
|
+
if (key === "value" && !["input", "textarea", "select", "progress", "meter", "output"].includes(tag)) return webSourceError();
|
|
214
|
+
if ((key === "text" || key === "repeat") && WEB_VOID_TAGS.has(tag)) return webSourceError();
|
|
215
|
+
} else return webSourceError();
|
|
216
|
+
} else if (name === "id" || name === "name") {
|
|
217
|
+
if (!webIdentifier(value) || name === "name" && !["input", "textarea", "select"].includes(tag)) return webSourceError();
|
|
218
|
+
} else if (name === "class") {
|
|
219
|
+
const names = value.trim().split(/\s+/u);
|
|
220
|
+
if (names.length > 16 || !names.every(webIdentifier)) return webSourceError();
|
|
221
|
+
} else if (globalText.has(name)) {
|
|
222
|
+
if (!value.trim()) return webSourceError();
|
|
223
|
+
} else if (references.has(name)) {
|
|
224
|
+
if (!value.split(/\s+/u).every(webIdentifier) || name === "for" && tag !== "label") return webSourceError();
|
|
225
|
+
} else if (booleanAttributes.has(name)) {
|
|
226
|
+
if (value !== "" && value !== name) return webSourceError();
|
|
227
|
+
if (["disabled", "required", "readonly"].includes(name) && !WEB_CONTROLS.has(tag)) return webSourceError();
|
|
228
|
+
if (name === "checked" && tag !== "input") return webSourceError();
|
|
229
|
+
if (name === "selected" && tag !== "option") return webSourceError();
|
|
230
|
+
if (name === "open" && tag !== "details") return webSourceError();
|
|
231
|
+
if (name === "novalidate" && tag !== "form") return webSourceError();
|
|
232
|
+
} else if (name === "type") {
|
|
233
|
+
if (tag === "input" ? !WEB_INPUT_TYPES.has(value) : tag !== "button" || !["button", "submit"].includes(value)) return webSourceError();
|
|
234
|
+
} else if (name === "value" && ["input", "option"].includes(tag)) {
|
|
235
|
+
} else if (numericAttributes.has(name)) {
|
|
236
|
+
if (!/^-?(?:0|[1-9]\d{0,3})(?:\.\d{1,3})?$/u.test(value) || Math.abs(Number(value)) > 1e3) return webSourceError();
|
|
237
|
+
} else if (name === "placeholder" && ["input", "textarea"].includes(tag)) {
|
|
238
|
+
if (value.length > 160) return webSourceError();
|
|
239
|
+
} else if (name === "role") {
|
|
240
|
+
if (!roles.has(value)) return webSourceError();
|
|
241
|
+
} else if (name === "aria-live") {
|
|
242
|
+
if (!["polite", "assertive", "off"].includes(value)) return webSourceError();
|
|
243
|
+
} else if (["aria-atomic", "aria-pressed", "aria-expanded", "aria-hidden", "aria-required", "aria-invalid"].includes(name)) {
|
|
244
|
+
if (!["true", "false"].includes(value)) return webSourceError();
|
|
245
|
+
} else if (name === "tabindex") {
|
|
246
|
+
if (value !== "0" && value !== "-1") return webSourceError();
|
|
247
|
+
} else if (name === "scope" && tag === "th") {
|
|
248
|
+
if (!["row", "col", "rowgroup", "colgroup"].includes(value)) return webSourceError();
|
|
249
|
+
} else return webSourceError();
|
|
250
|
+
output[name] = value;
|
|
251
|
+
}
|
|
252
|
+
if (output["data-id"] && !output["data-action"]) return webSourceError();
|
|
253
|
+
if ((output.checked !== void 0 || output["data-checked"]) && output.type !== "checkbox") return webSourceError();
|
|
254
|
+
if (tag === "button" && output["data-action"] && output.type !== "button") return webSourceError();
|
|
255
|
+
return output;
|
|
256
|
+
}
|
|
257
|
+
function parseWebHtml(html, checkOpen) {
|
|
258
|
+
const parser = import_parse5.Parser.getFragmentParser(null, { scriptingEnabled: false, onParseError: webSourceError });
|
|
259
|
+
const start = parser.onStartTag.bind(parser);
|
|
260
|
+
const end = parser.onEndTag.bind(parser);
|
|
261
|
+
let tokens = 0;
|
|
262
|
+
parser.onStartTag = (token) => {
|
|
263
|
+
checkOpen();
|
|
264
|
+
if (++tokens > WEB_PROJECT_LIMITS.templateNodes) return webLimitError();
|
|
265
|
+
if (!WEB_TAGS.has(token.tagName)) return webSourceError();
|
|
266
|
+
attributes(token.tagName, token.attrs);
|
|
267
|
+
start(token);
|
|
268
|
+
};
|
|
269
|
+
parser.onEndTag = (token) => {
|
|
270
|
+
checkOpen();
|
|
271
|
+
if (!WEB_TAGS.has(token.tagName)) return webSourceError();
|
|
272
|
+
end(token);
|
|
273
|
+
};
|
|
274
|
+
parser.onDoctype = webSourceError;
|
|
275
|
+
parser.tokenizer.write(html, true);
|
|
276
|
+
const ids = /* @__PURE__ */ new Set();
|
|
277
|
+
let count = 0;
|
|
278
|
+
function convert(node, depth, repeating) {
|
|
279
|
+
checkOpen();
|
|
280
|
+
if (++count > WEB_PROJECT_LIMITS.templateNodes || depth > WEB_PROJECT_LIMITS.templateDepth) return webLimitError();
|
|
281
|
+
if (node.nodeName === "#comment") return [];
|
|
282
|
+
if ("value" in node) return [{ kind: "text", text: node.value }];
|
|
283
|
+
if (!("tagName" in node) || node.namespaceURI !== "http://www.w3.org/1999/xhtml" || !WEB_TAGS.has(node.tagName)) return webSourceError();
|
|
284
|
+
const attrs = attributes(node.tagName, node.attrs);
|
|
285
|
+
const repeat = attrs["data-repeat"];
|
|
286
|
+
if (attrs.id) {
|
|
287
|
+
if (repeating || repeat || ids.has(attrs.id)) return webSourceError();
|
|
288
|
+
ids.add(attrs.id);
|
|
289
|
+
}
|
|
290
|
+
const bindings = {};
|
|
291
|
+
for (const binding of WEB_BINDINGS) if (attrs[`data-${binding}`]) bindings[binding] = attrs[`data-${binding}`];
|
|
292
|
+
const action = attrs["data-action"] ? { type: attrs["data-action"], ...attrs["data-id"] ? { idPath: attrs["data-id"] } : {} } : void 0;
|
|
293
|
+
const field = attrs.name ? { name: attrs.name, type: node.tagName === "input" ? attrs.type ?? "text" : node.tagName } : void 0;
|
|
294
|
+
const safeAttributes = Object.fromEntries(Object.entries(attrs).filter(([name]) => !name.startsWith("data-")));
|
|
295
|
+
return [{
|
|
296
|
+
kind: "element",
|
|
297
|
+
tag: node.tagName,
|
|
298
|
+
attributes: safeAttributes,
|
|
299
|
+
bindings,
|
|
300
|
+
children: node.childNodes.flatMap((child) => convert(child, depth + 1, repeating || !!repeat)),
|
|
301
|
+
...repeat ? { repeat } : {},
|
|
302
|
+
...action ? { action } : {},
|
|
303
|
+
...field ? { field } : {}
|
|
304
|
+
}];
|
|
305
|
+
}
|
|
306
|
+
return parser.getFragment().childNodes.flatMap((node) => convert(node, 1, false));
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
// src/web-css.ts
|
|
310
|
+
var import_css_tree = require("css-tree");
|
|
311
|
+
var properties = /* @__PURE__ */ new Set([
|
|
312
|
+
"display",
|
|
313
|
+
"gap",
|
|
314
|
+
"row-gap",
|
|
315
|
+
"column-gap",
|
|
316
|
+
"grid-template-columns",
|
|
317
|
+
"grid-template-rows",
|
|
318
|
+
"grid-column",
|
|
319
|
+
"grid-row",
|
|
320
|
+
"align-items",
|
|
321
|
+
"align-content",
|
|
322
|
+
"justify-items",
|
|
323
|
+
"justify-content",
|
|
324
|
+
"flex",
|
|
325
|
+
"flex-direction",
|
|
326
|
+
"flex-wrap",
|
|
327
|
+
"flex-grow",
|
|
328
|
+
"flex-shrink",
|
|
329
|
+
"flex-basis",
|
|
330
|
+
"order",
|
|
331
|
+
"width",
|
|
332
|
+
"min-width",
|
|
333
|
+
"max-width",
|
|
334
|
+
"height",
|
|
335
|
+
"min-height",
|
|
336
|
+
"max-height",
|
|
337
|
+
"margin",
|
|
338
|
+
"margin-top",
|
|
339
|
+
"margin-right",
|
|
340
|
+
"margin-bottom",
|
|
341
|
+
"margin-left",
|
|
342
|
+
"margin-inline",
|
|
343
|
+
"margin-block",
|
|
344
|
+
"padding",
|
|
345
|
+
"padding-top",
|
|
346
|
+
"padding-right",
|
|
347
|
+
"padding-bottom",
|
|
348
|
+
"padding-left",
|
|
349
|
+
"padding-inline",
|
|
350
|
+
"padding-block",
|
|
351
|
+
"box-sizing",
|
|
352
|
+
"border",
|
|
353
|
+
"border-width",
|
|
354
|
+
"border-style",
|
|
355
|
+
"border-color",
|
|
356
|
+
"border-radius",
|
|
357
|
+
"border-collapse",
|
|
358
|
+
"border-spacing",
|
|
359
|
+
"color",
|
|
360
|
+
"background-color",
|
|
361
|
+
"font-family",
|
|
362
|
+
"font-size",
|
|
363
|
+
"font-weight",
|
|
364
|
+
"font-style",
|
|
365
|
+
"line-height",
|
|
366
|
+
"letter-spacing",
|
|
367
|
+
"text-align",
|
|
368
|
+
"text-decoration",
|
|
369
|
+
"text-transform",
|
|
370
|
+
"white-space",
|
|
371
|
+
"overflow-wrap",
|
|
372
|
+
"word-break",
|
|
373
|
+
"vertical-align",
|
|
374
|
+
"list-style-type",
|
|
375
|
+
"outline",
|
|
376
|
+
"outline-width",
|
|
377
|
+
"outline-style",
|
|
378
|
+
"outline-color",
|
|
379
|
+
"outline-offset",
|
|
380
|
+
"opacity",
|
|
381
|
+
"visibility",
|
|
382
|
+
"overflow",
|
|
383
|
+
"overflow-x",
|
|
384
|
+
"overflow-y",
|
|
385
|
+
"cursor",
|
|
386
|
+
"transition-property",
|
|
387
|
+
"transition-duration",
|
|
388
|
+
"transition-timing-function"
|
|
389
|
+
]);
|
|
390
|
+
var functions = /* @__PURE__ */ new Set(["rgb", "rgba", "hsl", "hsla", "var", "min", "max", "clamp", "calc", "repeat", "minmax", "fit-content", "steps", "cubic-bezier"]);
|
|
391
|
+
var pseudoClasses = /* @__PURE__ */ new Set([
|
|
392
|
+
"root",
|
|
393
|
+
"hover",
|
|
394
|
+
"focus",
|
|
395
|
+
"focus-visible",
|
|
396
|
+
"focus-within",
|
|
397
|
+
"active",
|
|
398
|
+
"checked",
|
|
399
|
+
"disabled",
|
|
400
|
+
"enabled",
|
|
401
|
+
"first-child",
|
|
402
|
+
"last-child",
|
|
403
|
+
"nth-child",
|
|
404
|
+
"nth-of-type",
|
|
405
|
+
"empty",
|
|
406
|
+
"not"
|
|
407
|
+
]);
|
|
408
|
+
var units = /* @__PURE__ */ new Set(["px", "em", "rem", "ch", "fr", "s", "ms", "deg"]);
|
|
409
|
+
function parseWebCss(css, checkOpen) {
|
|
410
|
+
checkOpen();
|
|
411
|
+
const ast = (0, import_css_tree.parse)(css, { positions: false, parseCustomProperty: true, onParseError: webSourceError });
|
|
412
|
+
let nodes = 0;
|
|
413
|
+
let depth = 0;
|
|
414
|
+
const declarations = [];
|
|
415
|
+
(0, import_css_tree.walk)(ast, {
|
|
416
|
+
enter(node) {
|
|
417
|
+
checkOpen();
|
|
418
|
+
if (++nodes > WEB_PROJECT_LIMITS.cssNodes || ++depth > WEB_PROJECT_LIMITS.cssDepth) return webLimitError();
|
|
419
|
+
if (["Raw", "Url"].includes(node.type)) return webSourceError();
|
|
420
|
+
if (node.type === "Atrule") {
|
|
421
|
+
if (node.name !== "media" || !node.prelude || !node.block) return webSourceError();
|
|
422
|
+
const query = (0, import_css_tree.generate)(node.prelude).replace(/\s+/gu, "");
|
|
423
|
+
if (!/^\((?:min-width|max-width):\d{1,4}(?:px|rem)\)$/u.test(query) && !/^\(prefers-reduced-motion:(?:reduce|no-preference)\)$/u.test(query) && !/^\(prefers-color-scheme:(?:light|dark)\)$/u.test(query)) return webSourceError();
|
|
424
|
+
}
|
|
425
|
+
if (node.type === "Declaration") {
|
|
426
|
+
if (node.important) return webSourceError();
|
|
427
|
+
const custom = /^--[a-z][a-z0-9-]{0,31}$/u.test(node.property);
|
|
428
|
+
if (!custom && !properties.has(node.property)) return webSourceError();
|
|
429
|
+
if (!custom) declarations.push(node);
|
|
430
|
+
}
|
|
431
|
+
if (node.type === "Function" && !functions.has(node.name)) return webSourceError();
|
|
432
|
+
if (node.type === "PseudoClassSelector" && !pseudoClasses.has(node.name)) return webSourceError();
|
|
433
|
+
if (node.type === "PseudoElementSelector") return webSourceError();
|
|
434
|
+
if (node.type === "AttributeSelector") {
|
|
435
|
+
const name = node.name.name;
|
|
436
|
+
const value = node.value?.type === "String" ? node.value.value : node.value?.name;
|
|
437
|
+
if (node.matcher !== "=" || node.flags || typeof value !== "string" || !["aria-pressed", "aria-expanded", "aria-invalid", "aria-required"].includes(name) && name !== "type" || !(name === "type" ? ["text", "number", "range", "checkbox", "button", "submit"].includes(value) : ["true", "false"].includes(value))) return webSourceError();
|
|
438
|
+
}
|
|
439
|
+
if (node.type === "Dimension" || node.type === "Number" || node.type === "Percentage") {
|
|
440
|
+
const value = Number(node.value);
|
|
441
|
+
if (!Number.isFinite(value) || Math.abs(value) > 4096) return webSourceError();
|
|
442
|
+
if (node.type === "Dimension" && (!units.has(node.unit) || node.unit === "s" && (value < 0 || value > 2) || node.unit === "ms" && (value < 0 || value > 2e3))) return webSourceError();
|
|
443
|
+
}
|
|
444
|
+
if (node.type === "Function" && node.name === "repeat") {
|
|
445
|
+
const first = node.children.first;
|
|
446
|
+
if (!first || (first.type === "Number" ? !Number.isInteger(Number(first.value)) || Number(first.value) < 1 || Number(first.value) > 12 : first.type !== "Identifier" || !["auto-fit", "auto-fill"].includes(first.name))) return webSourceError();
|
|
447
|
+
}
|
|
448
|
+
},
|
|
449
|
+
leave() {
|
|
450
|
+
depth -= 1;
|
|
451
|
+
}
|
|
452
|
+
});
|
|
453
|
+
for (const declaration of declarations) {
|
|
454
|
+
checkOpen();
|
|
455
|
+
let variable = false;
|
|
456
|
+
(0, import_css_tree.walk)(declaration.value, (candidate) => {
|
|
457
|
+
if (candidate.type === "Function" && candidate.name === "var") variable = true;
|
|
458
|
+
});
|
|
459
|
+
if (!variable && !import_css_tree.lexer.matchProperty(declaration.property, declaration.value).matched) return webSourceError();
|
|
460
|
+
}
|
|
461
|
+
checkOpen();
|
|
462
|
+
const result = (0, import_css_tree.generate)(ast);
|
|
463
|
+
if (result.length > WEB_PROJECT_LIMITS.cssCharacters) return webLimitError();
|
|
464
|
+
return result;
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
// src/web.ts
|
|
468
|
+
function ownPath(value, path) {
|
|
469
|
+
let current = value;
|
|
470
|
+
for (const key of path.split(".")) {
|
|
471
|
+
if (current === null || typeof current !== "object" || Array.isArray(current) || !Object.hasOwn(current, key)) return webViewError();
|
|
472
|
+
current = current[key];
|
|
473
|
+
}
|
|
474
|
+
return current;
|
|
475
|
+
}
|
|
476
|
+
var scalarText = (value) => typeof value === "string" || typeof value === "number" || typeof value === "boolean" ? String(value) : webViewError();
|
|
477
|
+
var bool = (value) => typeof value === "boolean" ? value : webViewError();
|
|
478
|
+
function createWebProject(source, options = {}) {
|
|
479
|
+
let snapshot;
|
|
480
|
+
try {
|
|
481
|
+
snapshot = JSON.parse(serializeProjectJson(source));
|
|
482
|
+
} catch {
|
|
483
|
+
return webSourceError();
|
|
484
|
+
}
|
|
485
|
+
if (!snapshot || typeof snapshot !== "object" || Array.isArray(snapshot) || Object.keys(snapshot).length !== 2 || typeof snapshot.html !== "string" || typeof snapshot.css !== "string" || (snapshot.html + snapshot.css).includes("\0")) return webSourceError();
|
|
486
|
+
if (snapshot.html.length > WEB_PROJECT_LIMITS.htmlCharacters || snapshot.css.length > WEB_PROJECT_LIMITS.cssCharacters) return webLimitError();
|
|
487
|
+
if (!options || typeof options !== "object" || Array.isArray(options) || Object.getPrototypeOf(options) !== Object.prototype && Object.getPrototypeOf(options) !== null || Object.getOwnPropertySymbols(options).length) return webSourceError();
|
|
488
|
+
const descriptors = Object.getOwnPropertyDescriptors(options);
|
|
489
|
+
if (Object.entries(descriptors).some(([key, descriptor]) => key !== "signal" || descriptor.get || descriptor.set || !descriptor.enumerable)) return webSourceError();
|
|
490
|
+
const signal = descriptors.signal?.value;
|
|
491
|
+
if (signal !== void 0 && !(signal instanceof AbortSignal)) return webSourceError();
|
|
492
|
+
let closed = signal?.aborted === true;
|
|
493
|
+
const checkOpen = () => {
|
|
494
|
+
if (closed || signal?.aborted) throw new WebProjectError("CLOSED");
|
|
495
|
+
};
|
|
496
|
+
let template = [];
|
|
497
|
+
let css = "";
|
|
498
|
+
const dispose = () => {
|
|
499
|
+
closed = true;
|
|
500
|
+
template = [];
|
|
501
|
+
css = "";
|
|
502
|
+
signal?.removeEventListener("abort", dispose);
|
|
503
|
+
};
|
|
504
|
+
try {
|
|
505
|
+
checkOpen();
|
|
506
|
+
template = parseWebHtml(snapshot.html, checkOpen);
|
|
507
|
+
css = parseWebCss(snapshot.css, checkOpen);
|
|
508
|
+
} catch (error) {
|
|
509
|
+
dispose();
|
|
510
|
+
if (error instanceof WebProjectError) throw error;
|
|
511
|
+
return webSourceError();
|
|
512
|
+
}
|
|
513
|
+
signal?.addEventListener("abort", dispose, { once: true });
|
|
514
|
+
return {
|
|
515
|
+
get closed() {
|
|
516
|
+
return closed;
|
|
517
|
+
},
|
|
518
|
+
get template() {
|
|
519
|
+
checkOpen();
|
|
520
|
+
return structuredClone(template);
|
|
521
|
+
},
|
|
522
|
+
dispose,
|
|
523
|
+
render(value) {
|
|
524
|
+
checkOpen();
|
|
525
|
+
try {
|
|
526
|
+
let project2 = function(node, context, skipRepeat = false) {
|
|
527
|
+
checkOpen();
|
|
528
|
+
if (++nodes > WEB_PROJECT_LIMITS.projectedNodes) return webLimitError();
|
|
529
|
+
if (node.kind === "text") return [{ ...node }];
|
|
530
|
+
if (node.repeat && !skipRepeat) {
|
|
531
|
+
const items = ownPath(context, node.repeat);
|
|
532
|
+
if (!Array.isArray(items)) return webViewError();
|
|
533
|
+
if (items.length > WEB_PROJECT_LIMITS.repeatedItems) return webLimitError();
|
|
534
|
+
const ids = /* @__PURE__ */ new Set();
|
|
535
|
+
return items.flatMap((item) => {
|
|
536
|
+
const id = ownPath(item, "id");
|
|
537
|
+
if (typeof id !== "string" || !id.trim() || id.length > 128 || ids.has(id)) return webViewError();
|
|
538
|
+
ids.add(id);
|
|
539
|
+
return project2(node, item, true);
|
|
540
|
+
});
|
|
541
|
+
}
|
|
542
|
+
if (node.bindings.if && !bool(ownPath(context, node.bindings.if))) return [];
|
|
543
|
+
const attributes2 = { ...node.attributes };
|
|
544
|
+
for (const [binding, path] of Object.entries(node.bindings)) {
|
|
545
|
+
if (["text", "if"].includes(binding)) continue;
|
|
546
|
+
const data = ownPath(context, path);
|
|
547
|
+
if (binding === "disabled" || binding === "checked") {
|
|
548
|
+
if (bool(data)) attributes2[binding] = "";
|
|
549
|
+
else delete attributes2[binding];
|
|
550
|
+
} else if (binding === "pressed" || binding === "invalid") attributes2[`aria-${binding}`] = String(bool(data));
|
|
551
|
+
else if (binding === "label") {
|
|
552
|
+
const label = scalarText(data);
|
|
553
|
+
if (!label.trim() || label.length > WEB_PROJECT_LIMITS.attributeCharacters) return webViewError();
|
|
554
|
+
attributes2["aria-label"] = label;
|
|
555
|
+
} else {
|
|
556
|
+
const value2 = scalarText(data);
|
|
557
|
+
if (value2.length > 2e3) return webLimitError();
|
|
558
|
+
attributes2.value = value2;
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
if (node.bindings.text && ++nodes > WEB_PROJECT_LIMITS.projectedNodes) return webLimitError();
|
|
562
|
+
const children = node.bindings.text ? [{ kind: "text", text: scalarText(ownPath(context, node.bindings.text)) }] : node.children.flatMap((child) => project2(child, context));
|
|
563
|
+
const action = actionFor(node, context);
|
|
564
|
+
return [{
|
|
565
|
+
kind: "element",
|
|
566
|
+
tag: node.tag,
|
|
567
|
+
attributes: attributes2,
|
|
568
|
+
children,
|
|
569
|
+
...action ? { action } : {},
|
|
570
|
+
...node.field ? { field: { ...node.field } } : {}
|
|
571
|
+
}];
|
|
572
|
+
};
|
|
573
|
+
var project = project2;
|
|
574
|
+
const view = JSON.parse(serializeProjectJson(value));
|
|
575
|
+
if (view === null || typeof view !== "object" || Array.isArray(view)) return webViewError();
|
|
576
|
+
let nodes = 0;
|
|
577
|
+
const result = { nodes: template.flatMap((node) => project2(node, view)), css };
|
|
578
|
+
if (JSON.stringify(result).length > WEB_PROJECT_LIMITS.outputCharacters) return webLimitError();
|
|
579
|
+
return result;
|
|
580
|
+
} catch (error) {
|
|
581
|
+
if (error instanceof WebProjectError) throw error;
|
|
582
|
+
return webViewError();
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
};
|
|
586
|
+
}
|
|
587
|
+
function actionFor(node, context) {
|
|
588
|
+
if (!node.action) return void 0;
|
|
589
|
+
if (!node.action.idPath) return { type: node.action.type };
|
|
590
|
+
const id = ownPath(context, node.action.idPath);
|
|
591
|
+
if (typeof id !== "string" || !id.trim() || id.length > 128) return webViewError();
|
|
592
|
+
return { type: node.action.type, id };
|
|
593
|
+
}
|
|
594
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
595
|
+
0 && (module.exports = {
|
|
596
|
+
WEB_PROJECT_LIMITS,
|
|
597
|
+
WebProjectError,
|
|
598
|
+
createWebProject
|
|
599
|
+
});
|
|
600
|
+
//# sourceMappingURL=web.cjs.map
|