@graview/guest 0.1.8 → 0.1.10
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 +301 -2
- package/client.js +2 -0
- package/dist/channel.d.ts +11 -3
- package/dist/channel.d.ts.map +1 -1
- package/dist/channel.js +5 -1
- package/dist/channel.js.map +1 -1
- package/dist/cli.d.ts +16 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +75 -0
- package/dist/cli.js.map +1 -0
- package/dist/client-script.d.ts +3 -0
- package/dist/client-script.d.ts.map +1 -0
- package/dist/client-script.js +21 -0
- package/dist/client-script.js.map +1 -0
- package/dist/client.d.ts +2 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.generated.d.ts +4 -0
- package/dist/client.generated.d.ts.map +1 -0
- package/dist/client.generated.js +9 -0
- package/dist/client.generated.js.map +1 -0
- package/dist/client.js +12 -0
- package/dist/client.js.map +1 -0
- package/dist/headless/describe.d.ts +19 -0
- package/dist/headless/describe.d.ts.map +1 -0
- package/dist/headless/describe.js +255 -0
- package/dist/headless/describe.js.map +1 -0
- package/dist/headless/draw.d.ts +17 -0
- package/dist/headless/draw.d.ts.map +1 -0
- package/dist/headless/draw.js +25 -0
- package/dist/headless/draw.js.map +1 -0
- package/dist/headless/index.d.ts +99 -0
- package/dist/headless/index.d.ts.map +1 -0
- package/dist/headless/index.js +143 -0
- package/dist/headless/index.js.map +1 -0
- package/dist/headless/judge.d.ts +16 -0
- package/dist/headless/judge.d.ts.map +1 -0
- package/dist/headless/judge.js +52 -0
- package/dist/headless/judge.js.map +1 -0
- package/dist/headless/node.d.ts +8 -0
- package/dist/headless/node.d.ts.map +1 -0
- package/dist/headless/node.js +80 -0
- package/dist/headless/node.js.map +1 -0
- package/dist/headless/protocol.d.ts +71 -0
- package/dist/headless/protocol.d.ts.map +1 -0
- package/dist/headless/protocol.js +14 -0
- package/dist/headless/protocol.js.map +1 -0
- package/dist/headless/runtime.d.ts +2 -0
- package/dist/headless/runtime.d.ts.map +1 -0
- package/dist/headless/runtime.generated.d.ts +2 -0
- package/dist/headless/runtime.generated.d.ts.map +1 -0
- package/dist/headless/runtime.generated.js +8 -0
- package/dist/headless/runtime.generated.js.map +1 -0
- package/dist/headless/runtime.js +171 -0
- package/dist/headless/runtime.js.map +1 -0
- package/dist/headless/tree.d.ts +54 -0
- package/dist/headless/tree.d.ts.map +1 -0
- package/dist/headless/tree.js +128 -0
- package/dist/headless/tree.js.map +1 -0
- package/dist/host/css.d.ts +118 -0
- package/dist/host/css.d.ts.map +1 -0
- package/dist/host/css.js +963 -0
- package/dist/host/css.js.map +1 -0
- package/dist/host/draw-budget.d.ts +10 -0
- package/dist/host/draw-budget.d.ts.map +1 -0
- package/dist/host/draw-budget.js +29 -0
- package/dist/host/draw-budget.js.map +1 -0
- package/dist/host/frame.d.ts +19 -1
- package/dist/host/frame.d.ts.map +1 -1
- package/dist/host/frame.js +21 -2
- package/dist/host/frame.js.map +1 -1
- package/dist/host/index.d.ts +4 -3
- package/dist/host/index.d.ts.map +1 -1
- package/dist/host/index.js +7 -1
- package/dist/host/index.js.map +1 -1
- package/dist/host/kit.d.ts +6 -2
- package/dist/host/kit.d.ts.map +1 -1
- package/dist/host/kit.js +12 -5
- package/dist/host/kit.js.map +1 -1
- package/dist/host/links.d.ts +24 -0
- package/dist/host/links.d.ts.map +1 -0
- package/dist/host/links.js +35 -0
- package/dist/host/links.js.map +1 -0
- package/dist/host/manifest.d.ts +50 -0
- package/dist/host/manifest.d.ts.map +1 -0
- package/dist/host/manifest.js +103 -0
- package/dist/host/manifest.js.map +1 -0
- package/dist/host/open-draw.d.ts +44 -0
- package/dist/host/open-draw.d.ts.map +1 -0
- package/dist/host/open-draw.js +108 -0
- package/dist/host/open-draw.js.map +1 -0
- package/dist/host/open-judge.d.ts +53 -0
- package/dist/host/open-judge.d.ts.map +1 -0
- package/dist/host/open-judge.js +95 -0
- package/dist/host/open-judge.js.map +1 -0
- package/dist/host/open-render.d.ts +32 -0
- package/dist/host/open-render.d.ts.map +1 -0
- package/dist/host/open-render.js +262 -0
- package/dist/host/open-render.js.map +1 -0
- package/dist/host/press.d.ts +15 -0
- package/dist/host/press.d.ts.map +1 -0
- package/dist/host/press.js +156 -0
- package/dist/host/press.js.map +1 -0
- package/dist/host/react.d.ts +15 -2
- package/dist/host/react.d.ts.map +1 -1
- package/dist/host/react.js +13 -5
- package/dist/host/react.js.map +1 -1
- package/dist/host/session.d.ts +94 -1
- package/dist/host/session.d.ts.map +1 -1
- package/dist/host/session.js +103 -14
- package/dist/host/session.js.map +1 -1
- package/dist/host/theme.d.ts +14 -0
- package/dist/host/theme.d.ts.map +1 -0
- package/dist/host/theme.js +51 -0
- package/dist/host/theme.js.map +1 -0
- package/dist/host/view-runtime.generated.d.ts +2 -0
- package/dist/host/view-runtime.generated.d.ts.map +1 -0
- package/dist/host/view-runtime.generated.js +7 -0
- package/dist/host/view-runtime.generated.js.map +1 -0
- package/dist/host/view-source.d.ts +5 -0
- package/dist/host/view-source.d.ts.map +1 -0
- package/dist/host/view-source.js +39 -0
- package/dist/host/view-source.js.map +1 -0
- package/dist/host/view.d.ts +134 -0
- package/dist/host/view.d.ts.map +1 -0
- package/dist/host/view.js +381 -0
- package/dist/host/view.js.map +1 -0
- package/dist/host/views.d.ts +10 -0
- package/dist/host/views.d.ts.map +1 -0
- package/dist/host/views.js +15 -0
- package/dist/host/views.js.map +1 -0
- package/dist/host/worker-react.d.ts +51 -0
- package/dist/host/worker-react.d.ts.map +1 -0
- package/dist/host/worker-react.js +123 -0
- package/dist/host/worker-react.js.map +1 -0
- package/dist/host/worker-start.d.ts +49 -0
- package/dist/host/worker-start.d.ts.map +1 -0
- package/dist/host/worker-start.js +122 -0
- package/dist/host/worker-start.js.map +1 -0
- package/dist/host/worker.d.ts +17 -12
- package/dist/host/worker.d.ts.map +1 -1
- package/dist/host/worker.js +58 -117
- package/dist/host/worker.js.map +1 -1
- package/dist/host/writes.d.ts +49 -0
- package/dist/host/writes.d.ts.map +1 -0
- package/dist/host/writes.js +76 -0
- package/dist/host/writes.js.map +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/open-kit.d.ts +148 -0
- package/dist/open-kit.d.ts.map +1 -0
- package/dist/open-kit.js +321 -0
- package/dist/open-kit.js.map +1 -0
- package/dist/protocol.d.ts +109 -3
- package/dist/protocol.d.ts.map +1 -1
- package/dist/protocol.js +13 -0
- package/dist/protocol.js.map +1 -1
- package/dist/worker/harden.d.ts +13 -2
- package/dist/worker/harden.d.ts.map +1 -1
- package/dist/worker/harden.js +10 -4
- package/dist/worker/harden.js.map +1 -1
- package/dist/worker/natives.d.ts +1 -0
- package/dist/worker/natives.d.ts.map +1 -1
- package/dist/worker/natives.js +4 -0
- package/dist/worker/natives.js.map +1 -1
- package/dist/worker/view-global.d.ts +70 -0
- package/dist/worker/view-global.d.ts.map +1 -0
- package/dist/worker/view-global.js +264 -0
- package/dist/worker/view-global.js.map +1 -0
- package/dist/worker/view.d.ts +14 -0
- package/dist/worker/view.d.ts.map +1 -0
- package/dist/worker/view.js +64 -0
- package/dist/worker/view.js.map +1 -0
- package/package.json +30 -4
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* A HEADLESS RUN'S RUNTIME (FR-95): what runs INSIDE the isolate a host
|
|
3
|
+
* picked, in front of the view.
|
|
4
|
+
*
|
|
5
|
+
* Bundled into one classic script (headless/runtime.generated.ts, by
|
|
6
|
+
* scripts/guest-view-runtime.mjs), which `headlessScript(source)` puts in
|
|
7
|
+
* front of a view's own source. Loaded into an isolate — a worker thread's
|
|
8
|
+
* fresh context, a workerd isolate with no outbound network, a browser
|
|
9
|
+
* worker — the script first makes the isolate the worker's: the same
|
|
10
|
+
* `graview` global a worker's runtime makes (worker/view-global.ts), over a
|
|
11
|
+
* transcript rather than a port; a console that writes to the transcript;
|
|
12
|
+
* timers that never fire; and then everything outside the worker's
|
|
13
|
+
* allowlist taken from the global (worker/harden.ts). Only then is the view
|
|
14
|
+
* read, and its top line run. The script leaves one entry:
|
|
15
|
+
*
|
|
16
|
+
* graviewHeadless(input) the run: JSON text in (HeadlessInput), JSON text out (HeadlessOutcome)
|
|
17
|
+
*
|
|
18
|
+
* which pushes the view what it is shown, once, and holds what it sent to
|
|
19
|
+
* its limits and manifest, drawn by the open kit's own renderer into a tree
|
|
20
|
+
* of plain objects and said as a place is said (judge.ts).
|
|
21
|
+
*
|
|
22
|
+
* Nothing here reaches a network, and the isolate is what keeps the view
|
|
23
|
+
* from one: the hardening is a second wall, not the first. A view can lie
|
|
24
|
+
* to its own check — patch what the runtime reads after it, draw one thing
|
|
25
|
+
* here and another in a page — so the host judges the transcript again in
|
|
26
|
+
* its own context, and the check says what the view drew, never that it is
|
|
27
|
+
* honest. What it may reach is the page's to hold, as it always is.
|
|
28
|
+
*/
|
|
29
|
+
import "@remote-dom/core/polyfill";
|
|
30
|
+
import { harden } from "../worker/harden.js";
|
|
31
|
+
import { createViewRuntime } from "../worker/view-global.js";
|
|
32
|
+
import { judgeTranscript } from "./judge.js";
|
|
33
|
+
import { HEADLESS_ENTRY, HEADLESS_VIEW } from "./protocol.js";
|
|
34
|
+
/* Taken before a line of the view runs: what the run builds with stays as it found it. */
|
|
35
|
+
const scope = globalThis;
|
|
36
|
+
const then = Promise.prototype.then;
|
|
37
|
+
const settled = Promise.resolve();
|
|
38
|
+
const microtask = (task) => void then.call(settled, task);
|
|
39
|
+
const performance = scope["performance"];
|
|
40
|
+
const clock = performance && typeof performance.now === "function" ? performance.now.bind(performance) : Date.now;
|
|
41
|
+
const stringify = JSON.stringify;
|
|
42
|
+
const parse = JSON.parse;
|
|
43
|
+
const define = Object.defineProperty;
|
|
44
|
+
const say = (error) => (error instanceof Error ? `${error.name}: ${error.message}` : String(error)).slice(0, 500);
|
|
45
|
+
/** Plain data for the transcript: what the view passed, with nothing of its that runs. */
|
|
46
|
+
const plain = (value) => {
|
|
47
|
+
try {
|
|
48
|
+
return parse(stringify(value ?? null));
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
const transcript = { renders: [], asked: [], went: [], ms: 0, logs: [], messages: 0 };
|
|
55
|
+
let failure;
|
|
56
|
+
const fail = (reason, detail) => {
|
|
57
|
+
failure ??= { reason, detail };
|
|
58
|
+
};
|
|
59
|
+
const log = (text) => {
|
|
60
|
+
if (transcript.logs.length < 50)
|
|
61
|
+
transcript.logs.push(text.slice(0, 500));
|
|
62
|
+
};
|
|
63
|
+
let hardened = { removed: [], stuck: [], sealed: false };
|
|
64
|
+
const runtime = createViewRuntime({
|
|
65
|
+
send(request) {
|
|
66
|
+
transcript.messages += 1;
|
|
67
|
+
if (request.type === "render")
|
|
68
|
+
transcript.renders.push(plain(request.records));
|
|
69
|
+
else if (request.type === "style")
|
|
70
|
+
transcript.css = String(request.css);
|
|
71
|
+
else if (request.type === "navigate" && "place" in request)
|
|
72
|
+
transcript.went.push({ place: String(request.place) });
|
|
73
|
+
},
|
|
74
|
+
act(name, args) {
|
|
75
|
+
transcript.messages += 1;
|
|
76
|
+
transcript.asked.push({ name: String(name), args: plain(args) });
|
|
77
|
+
return Promise.resolve({ type: "answer", id: transcript.asked.length, ok: false, reason: "refused", message: "Nothing is applied in a headless run." });
|
|
78
|
+
},
|
|
79
|
+
navigate(to) {
|
|
80
|
+
transcript.messages += 1;
|
|
81
|
+
transcript.went.push({ record: String(to) });
|
|
82
|
+
},
|
|
83
|
+
microtask,
|
|
84
|
+
now: clock,
|
|
85
|
+
threw: (error) => fail("error", `It threw: ${say(error)}`),
|
|
86
|
+
warn: log,
|
|
87
|
+
hardening: () => hardened,
|
|
88
|
+
});
|
|
89
|
+
let ran = false;
|
|
90
|
+
let viewed = false;
|
|
91
|
+
/** The view, run at once: its top line, timed, with anything it throws caught and said. */
|
|
92
|
+
function view(fn) {
|
|
93
|
+
if (viewed || typeof fn !== "function")
|
|
94
|
+
return;
|
|
95
|
+
viewed = true;
|
|
96
|
+
if (failure)
|
|
97
|
+
return;
|
|
98
|
+
const began = clock();
|
|
99
|
+
try {
|
|
100
|
+
fn.call(undefined, runtime.view);
|
|
101
|
+
}
|
|
102
|
+
catch (error) {
|
|
103
|
+
fail("error", `It threw: ${say(error)}`);
|
|
104
|
+
}
|
|
105
|
+
transcript.ms += clock() - began;
|
|
106
|
+
}
|
|
107
|
+
async function run(text) {
|
|
108
|
+
if (ran)
|
|
109
|
+
return stringify({ ok: false, reason: "refused", detail: "A headless script runs one view, once: something called its entry before the host did." });
|
|
110
|
+
ran = true;
|
|
111
|
+
let input;
|
|
112
|
+
try {
|
|
113
|
+
input = parse(String(text));
|
|
114
|
+
}
|
|
115
|
+
catch {
|
|
116
|
+
return stringify({ ok: false, reason: "isolate", detail: "The run was not handed its input as JSON." });
|
|
117
|
+
}
|
|
118
|
+
if (!viewed && !failure)
|
|
119
|
+
return stringify({ ok: false, reason: "isolate", detail: "The script held no view." });
|
|
120
|
+
/* One push of what it is shown, timed with its top line. */
|
|
121
|
+
const began = clock();
|
|
122
|
+
if (!failure)
|
|
123
|
+
runtime.hear({ type: "props", props: input.props, push: 1 });
|
|
124
|
+
transcript.ms += clock() - began;
|
|
125
|
+
if (transcript.ms >= input.limits.pushMs)
|
|
126
|
+
fail("slow", `It took longer than ${input.limits.pushMs.toLocaleString("en-US")} ms to draw what it was shown.`);
|
|
127
|
+
/* What it drew goes in microtasks: let them run, and anything it chained on them, a bounded number of turns. */
|
|
128
|
+
for (let turn = 0; turn < 64 && !failure; turn += 1)
|
|
129
|
+
await new Promise((resolve) => microtask(resolve));
|
|
130
|
+
if (failure)
|
|
131
|
+
return stringify({ ok: false, ...failure, transcript });
|
|
132
|
+
const judged = judgeTranscript(transcript, input);
|
|
133
|
+
if (!judged.ok)
|
|
134
|
+
return stringify({ ok: false, reason: judged.reason, detail: judged.detail, transcript });
|
|
135
|
+
return stringify({ ok: true, transcript, drawn: { parts: judged.parts, problems: judged.problems }, hardening: { removed: hardened.removed.length, sealed: hardened.sealed } });
|
|
136
|
+
}
|
|
137
|
+
/*
|
|
138
|
+
* THE ISOLATE, MADE THE WORKER'S, before the view's script is read. The
|
|
139
|
+
* console writes to the transcript; timers never fire, since a headless run
|
|
140
|
+
* is one push and what it drew; `graview` is the view's one global, beside
|
|
141
|
+
* the two the script leaves; and then everything outside the worker's
|
|
142
|
+
* allowlist goes and what is left stays as it is. Hardening comes first so
|
|
143
|
+
* that a view whose text closes its own wrapper early runs after it all the
|
|
144
|
+
* same. A name that will not go stops the run, and the view never runs.
|
|
145
|
+
*/
|
|
146
|
+
const console = Object.freeze({
|
|
147
|
+
log: (...said) => log(said.map(String).join(" ")),
|
|
148
|
+
info: (...said) => log(said.map(String).join(" ")),
|
|
149
|
+
debug: (...said) => log(said.map(String).join(" ")),
|
|
150
|
+
warn: (...said) => log(said.map(String).join(" ")),
|
|
151
|
+
error: (...said) => log(said.map(say).join(" ")),
|
|
152
|
+
});
|
|
153
|
+
let timer = 0;
|
|
154
|
+
const never = () => (timer += 1);
|
|
155
|
+
const own = [
|
|
156
|
+
["console", console],
|
|
157
|
+
["setTimeout", never],
|
|
158
|
+
["setInterval", never],
|
|
159
|
+
["clearTimeout", () => { }],
|
|
160
|
+
["clearInterval", () => { }],
|
|
161
|
+
["queueMicrotask", microtask],
|
|
162
|
+
["graview", runtime.view],
|
|
163
|
+
[HEADLESS_VIEW, view],
|
|
164
|
+
[HEADLESS_ENTRY, (text) => run(text)],
|
|
165
|
+
];
|
|
166
|
+
for (const [name, value] of own)
|
|
167
|
+
define(scope, name, { value, writable: true, enumerable: false, configurable: true });
|
|
168
|
+
hardened = harden(globalThis, ["graview", HEADLESS_VIEW, HEADLESS_ENTRY], { primitivesStay: true });
|
|
169
|
+
if (hardened.stuck.length > 0)
|
|
170
|
+
fail("refused", `This isolate could not be hardened: ${hardened.stuck.join(", ")} would not go.`);
|
|
171
|
+
//# sourceMappingURL=runtime.js.map
|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AC;IACzB,CAAC,aAAa,EAAE,IAAI,CAAC;IACrB,CAAC,cAAc,EAAE,CAAC,IAAY,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;CAC9C,CAAC;AACF,KAAK,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,GAAG;IAAE,MAAM,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE,UAAU,EAAE,KAAK,EAAE,YAAY,EAAE,IAAI,EAAE,CAAC,CAAC;AACvH,QAAQ,GAAG,MAAM,CAAC,UAAU,EAAE,CAAC,SAAS,EAAE,aAAa,EAAE,cAAc,CAAC,EAAE,EAAE,cAAc,EAAE,IAAI,EAAE,CAAC,CAAC;AACpG,IAAI,QAAQ,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC;IAAE,IAAI,CAAC,SAAS,EAAE,uCAAuC,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
export declare const HTML_NAMESPACE = "http://www.w3.org/1999/xhtml";
|
|
2
|
+
export declare abstract class TreeNode {
|
|
3
|
+
readonly ownerDocument: TreeDocument | null;
|
|
4
|
+
abstract readonly nodeType: 1 | 3 | 8 | 9;
|
|
5
|
+
parentNode: TreeElement | TreeDocument | null;
|
|
6
|
+
readonly childNodes: TreeNode[];
|
|
7
|
+
constructor(ownerDocument: TreeDocument | null);
|
|
8
|
+
get firstChild(): TreeNode | null;
|
|
9
|
+
get parentElement(): TreeElement | null;
|
|
10
|
+
get textContent(): string;
|
|
11
|
+
insertBefore<T extends TreeNode>(child: T, before: TreeNode | null): T;
|
|
12
|
+
appendChild<T extends TreeNode>(child: T): T;
|
|
13
|
+
removeChild<T extends TreeNode>(child: T): T;
|
|
14
|
+
}
|
|
15
|
+
export declare class TreeText extends TreeNode {
|
|
16
|
+
data: string;
|
|
17
|
+
readonly nodeType: 3;
|
|
18
|
+
constructor(owner: TreeDocument, data: string);
|
|
19
|
+
get textContent(): string;
|
|
20
|
+
}
|
|
21
|
+
export declare class TreeComment extends TreeNode {
|
|
22
|
+
readonly nodeType: 8;
|
|
23
|
+
get textContent(): string;
|
|
24
|
+
}
|
|
25
|
+
export declare class TreeElement extends TreeNode {
|
|
26
|
+
readonly namespaceURI: string;
|
|
27
|
+
readonly localName: string;
|
|
28
|
+
readonly nodeType: 1;
|
|
29
|
+
readonly attributes: Map<string, string>;
|
|
30
|
+
value: string;
|
|
31
|
+
checked: boolean;
|
|
32
|
+
selected: boolean;
|
|
33
|
+
constructor(owner: TreeDocument, namespaceURI: string, localName: string);
|
|
34
|
+
setAttribute(name: string, value: string): void;
|
|
35
|
+
removeAttribute(name: string): void;
|
|
36
|
+
getAttribute(name: string): string | null;
|
|
37
|
+
hasAttribute(name: string): boolean;
|
|
38
|
+
/** The nearest element by local name, this one or above: all the renderer asks of `closest`. */
|
|
39
|
+
closest(name: string): TreeElement | null;
|
|
40
|
+
}
|
|
41
|
+
export declare class TreeDocument extends TreeNode {
|
|
42
|
+
readonly nodeType: 9;
|
|
43
|
+
constructor();
|
|
44
|
+
createElementNS(namespace: string, name: string): TreeElement;
|
|
45
|
+
createElement(name: string): TreeElement;
|
|
46
|
+
createTextNode(data: string): TreeText;
|
|
47
|
+
createComment(_data: string): TreeComment;
|
|
48
|
+
}
|
|
49
|
+
/** A document of its own, and the element a view's drawing is drawn under. */
|
|
50
|
+
export declare function createTree(): {
|
|
51
|
+
readonly document: TreeDocument;
|
|
52
|
+
readonly root: TreeElement;
|
|
53
|
+
};
|
|
54
|
+
//# sourceMappingURL=tree.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tree.d.ts","sourceRoot":"","sources":["../../src/headless/tree.ts"],"names":[],"mappings":"AAYA,eAAO,MAAM,cAAc,iCAAiC,CAAC;AAE7D,8BAAsB,QAAQ;IAIhB,QAAQ,CAAC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;gBAEf,KAAK,EAAE,YAAY,EACV,YAAY,EAAE,MAAM,EACpB,SAAS,EAAE,MAAM;IAI5B,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI;IAG/C,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAGnC,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI;IAGzC,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAGnC,gGAAgG;IAChG,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,WAAW,GAAG,IAAI;CAI1C;AAED,qBAAa,YAAa,SAAQ,QAAQ;IACxC,QAAQ,CAAC,QAAQ,EAAG,CAAC,CAAU;;IAI/B,eAAe,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,WAAW;IAG7D,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,WAAW;IAGxC,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,QAAQ;IAGtC,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,WAAW;CAG1C;AAED,8EAA8E;AAC9E,wBAAgB,UAAU,IAAI;IAAE,QAAQ,CAAC,QAAQ,EAAE,YAAY,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAA;CAAE,CAM5F"}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* A TREE WITH NO DOM (FR-95).
|
|
3
|
+
*
|
|
4
|
+
* What the open kit's renderer (host/open-render.ts) draws into, when there
|
|
5
|
+
* is no page: the handful of DOM calls it makes — createElementNS,
|
|
6
|
+
* createTextNode, createComment, setAttribute, removeAttribute,
|
|
7
|
+
* insertBefore, appendChild, removeChild — over plain objects, and what a
|
|
8
|
+
* describer reads back: each element's name, namespace, attributes and
|
|
9
|
+
* children, and a field's live value. Nothing here runs anything, loads
|
|
10
|
+
* anything, or lays anything out.
|
|
11
|
+
*/
|
|
12
|
+
export const HTML_NAMESPACE = "http://www.w3.org/1999/xhtml";
|
|
13
|
+
export class TreeNode {
|
|
14
|
+
ownerDocument;
|
|
15
|
+
parentNode = null;
|
|
16
|
+
childNodes = [];
|
|
17
|
+
constructor(ownerDocument) {
|
|
18
|
+
this.ownerDocument = ownerDocument;
|
|
19
|
+
}
|
|
20
|
+
get firstChild() {
|
|
21
|
+
return this.childNodes[0] ?? null;
|
|
22
|
+
}
|
|
23
|
+
get parentElement() {
|
|
24
|
+
return this.parentNode instanceof TreeElement ? this.parentNode : null;
|
|
25
|
+
}
|
|
26
|
+
get textContent() {
|
|
27
|
+
return this.childNodes.map((child) => child.textContent).join("");
|
|
28
|
+
}
|
|
29
|
+
insertBefore(child, before) {
|
|
30
|
+
if (child.parentNode)
|
|
31
|
+
child.parentNode.removeChild(child);
|
|
32
|
+
const at = before ? this.childNodes.indexOf(before) : -1;
|
|
33
|
+
if (at < 0)
|
|
34
|
+
this.childNodes.push(child);
|
|
35
|
+
else
|
|
36
|
+
this.childNodes.splice(at, 0, child);
|
|
37
|
+
child.parentNode = this;
|
|
38
|
+
return child;
|
|
39
|
+
}
|
|
40
|
+
appendChild(child) {
|
|
41
|
+
return this.insertBefore(child, null);
|
|
42
|
+
}
|
|
43
|
+
removeChild(child) {
|
|
44
|
+
const at = this.childNodes.indexOf(child);
|
|
45
|
+
if (at >= 0)
|
|
46
|
+
this.childNodes.splice(at, 1);
|
|
47
|
+
child.parentNode = null;
|
|
48
|
+
return child;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
export class TreeText extends TreeNode {
|
|
52
|
+
data;
|
|
53
|
+
nodeType = 3;
|
|
54
|
+
constructor(owner, data) {
|
|
55
|
+
super(owner);
|
|
56
|
+
this.data = data;
|
|
57
|
+
}
|
|
58
|
+
get textContent() {
|
|
59
|
+
return this.data;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
export class TreeComment extends TreeNode {
|
|
63
|
+
nodeType = 8;
|
|
64
|
+
get textContent() {
|
|
65
|
+
return "";
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
export class TreeElement extends TreeNode {
|
|
69
|
+
namespaceURI;
|
|
70
|
+
localName;
|
|
71
|
+
nodeType = 1;
|
|
72
|
+
attributes = new Map();
|
|
73
|
+
/* A field's live state, as a page keeps it beside its attributes. */
|
|
74
|
+
value = "";
|
|
75
|
+
checked = false;
|
|
76
|
+
selected = false;
|
|
77
|
+
constructor(owner, namespaceURI, localName) {
|
|
78
|
+
super(owner);
|
|
79
|
+
this.namespaceURI = namespaceURI;
|
|
80
|
+
this.localName = localName;
|
|
81
|
+
}
|
|
82
|
+
setAttribute(name, value) {
|
|
83
|
+
this.attributes.set(name, String(value));
|
|
84
|
+
}
|
|
85
|
+
removeAttribute(name) {
|
|
86
|
+
this.attributes.delete(name);
|
|
87
|
+
}
|
|
88
|
+
getAttribute(name) {
|
|
89
|
+
return this.attributes.get(name) ?? null;
|
|
90
|
+
}
|
|
91
|
+
hasAttribute(name) {
|
|
92
|
+
return this.attributes.has(name);
|
|
93
|
+
}
|
|
94
|
+
/** The nearest element by local name, this one or above: all the renderer asks of `closest`. */
|
|
95
|
+
closest(name) {
|
|
96
|
+
for (let at = this; at; at = at.parentElement)
|
|
97
|
+
if (at.localName === name)
|
|
98
|
+
return at;
|
|
99
|
+
return null;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
export class TreeDocument extends TreeNode {
|
|
103
|
+
nodeType = 9;
|
|
104
|
+
constructor() {
|
|
105
|
+
super(null);
|
|
106
|
+
}
|
|
107
|
+
createElementNS(namespace, name) {
|
|
108
|
+
return new TreeElement(this, namespace, name);
|
|
109
|
+
}
|
|
110
|
+
createElement(name) {
|
|
111
|
+
return new TreeElement(this, HTML_NAMESPACE, name);
|
|
112
|
+
}
|
|
113
|
+
createTextNode(data) {
|
|
114
|
+
return new TreeText(this, data);
|
|
115
|
+
}
|
|
116
|
+
createComment(_data) {
|
|
117
|
+
return new TreeComment(this);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
/** A document of its own, and the element a view's drawing is drawn under. */
|
|
121
|
+
export function createTree() {
|
|
122
|
+
const document = new TreeDocument();
|
|
123
|
+
const root = document.createElement("div");
|
|
124
|
+
root.setAttribute("data-graview-view-root", "");
|
|
125
|
+
document.appendChild(root);
|
|
126
|
+
return { document, root };
|
|
127
|
+
}
|
|
128
|
+
//# sourceMappingURL=tree.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tree.js","sourceRoot":"","sources":["../../src/headless/tree.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,MAAM,CAAC,MAAM,cAAc,GAAG,8BAA8B,CAAC;AAE7D,MAAM,OAAgB,QAAQ;IAIP;IAFrB,UAAU,GAAsC,IAAI,CAAC;IAC5C,UAAU,GAAe,EAAE,CAAC;IACrC,YAAqB,aAAkC;QAAlC,kBAAa,GAAb,aAAa,CAAqB;IAAG,CAAC;IAE3D,IAAI,UAAU;QACZ,OAAO,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC;IACpC,CAAC;IACD,IAAI,aAAa;QACf,OAAO,IAAI,CAAC,UAAU,YAAY,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC;IACzE,CAAC;IACD,IAAI,WAAW;QACb,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACpE,CAAC;IAED,YAAY,CAAqB,KAAQ,EAAE,MAAuB;QAChE,IAAI,KAAK,CAAC,UAAU;YAAE,KAAK,CAAC,UAAU,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;QAC1D,MAAM,EAAE,GAAG,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,MAA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c,EAAE,IAAI,CAAC,CAAC;IACrD,CAAC;IACD,cAAc,CAAC,IAAY;QACzB,OAAO,IAAI,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IAClC,CAAC;IACD,aAAa,CAAC,KAAa;QACzB,OAAO,IAAI,WAAW,CAAC,IAAI,CAAC,CAAC;IAC/B,CAAC;CACF;AAED,8EAA8E;AAC9E,MAAM,UAAU,UAAU;IACxB,MAAM,QAAQ,GAAG,IAAI,YAAY,EAAE,CAAC;IACpC,MAAM,IAAI,GAAG,QAAQ,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;IAC3C,IAAI,CAAC,YAAY,CAAC,wBAAwB,EAAE,EAAE,CAAC,CAAC;IAChD,QAAQ,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;IAC3B,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;AAC5B,CAAC"}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
export type Token = {
|
|
2
|
+
readonly type: "whitespace";
|
|
3
|
+
} | {
|
|
4
|
+
readonly type: "ident";
|
|
5
|
+
readonly value: string;
|
|
6
|
+
} | {
|
|
7
|
+
readonly type: "function";
|
|
8
|
+
readonly value: string;
|
|
9
|
+
} | {
|
|
10
|
+
readonly type: "at-keyword";
|
|
11
|
+
readonly value: string;
|
|
12
|
+
} | {
|
|
13
|
+
readonly type: "hash";
|
|
14
|
+
readonly value: string;
|
|
15
|
+
readonly id: boolean;
|
|
16
|
+
} | {
|
|
17
|
+
readonly type: "string";
|
|
18
|
+
readonly value: string;
|
|
19
|
+
} | {
|
|
20
|
+
readonly type: "bad-string";
|
|
21
|
+
} | {
|
|
22
|
+
readonly type: "url";
|
|
23
|
+
readonly value: string;
|
|
24
|
+
} | {
|
|
25
|
+
readonly type: "bad-url";
|
|
26
|
+
} | {
|
|
27
|
+
readonly type: "delim";
|
|
28
|
+
readonly value: string;
|
|
29
|
+
} | {
|
|
30
|
+
readonly type: "number";
|
|
31
|
+
readonly repr: string;
|
|
32
|
+
} | {
|
|
33
|
+
readonly type: "percentage";
|
|
34
|
+
readonly repr: string;
|
|
35
|
+
} | {
|
|
36
|
+
readonly type: "dimension";
|
|
37
|
+
readonly repr: string;
|
|
38
|
+
readonly unit: string;
|
|
39
|
+
} | {
|
|
40
|
+
readonly type: "CDO";
|
|
41
|
+
} | {
|
|
42
|
+
readonly type: "CDC";
|
|
43
|
+
} | {
|
|
44
|
+
readonly type: ":" | ";" | "," | "[" | "]" | "(" | ")" | "{" | "}";
|
|
45
|
+
};
|
|
46
|
+
/** CSS Syntax §4: the tokens of a stylesheet, a declaration list or a value. Comments are consumed and dropped. */
|
|
47
|
+
export declare function tokenize(input: string): Token[];
|
|
48
|
+
export type ComponentValue = Token | {
|
|
49
|
+
readonly type: "func";
|
|
50
|
+
readonly name: string;
|
|
51
|
+
readonly value: ComponentValue[];
|
|
52
|
+
} | {
|
|
53
|
+
readonly type: "block";
|
|
54
|
+
readonly open: "{" | "[" | "(";
|
|
55
|
+
readonly value: ComponentValue[];
|
|
56
|
+
};
|
|
57
|
+
export type Rule = {
|
|
58
|
+
readonly type: "at-rule";
|
|
59
|
+
readonly name: string;
|
|
60
|
+
readonly prelude: ComponentValue[];
|
|
61
|
+
readonly block?: ComponentValue[];
|
|
62
|
+
} | {
|
|
63
|
+
readonly type: "qualified";
|
|
64
|
+
readonly prelude: ComponentValue[];
|
|
65
|
+
readonly block: ComponentValue[];
|
|
66
|
+
};
|
|
67
|
+
export interface Declaration {
|
|
68
|
+
readonly type: "declaration";
|
|
69
|
+
readonly name: string;
|
|
70
|
+
readonly value: ComponentValue[];
|
|
71
|
+
readonly important: boolean;
|
|
72
|
+
}
|
|
73
|
+
/** CSSOM's "serialize an identifier". */
|
|
74
|
+
export declare function serializeIdent(value: string): string;
|
|
75
|
+
/** A string, quoted, with nothing in it that could end the quote, the line or a `<style>`. */
|
|
76
|
+
export declare function serializeString(value: string): string;
|
|
77
|
+
/** Component values as text, with whitespace runs made one space and a comment wherever two tokens would run together. */
|
|
78
|
+
export declare function serializeValues(values: readonly ComponentValue[]): string;
|
|
79
|
+
/** Why part of a view's CSS was not kept. */
|
|
80
|
+
export type CssRefusalReason =
|
|
81
|
+
/** An at-rule outside `CSS_AT_RULES` (`@import`, `@font-face`, `@namespace`, …). */
|
|
82
|
+
"at-rule"
|
|
83
|
+
/** A property outside `CSS_PROPERTIES`. */
|
|
84
|
+
| "property"
|
|
85
|
+
/** A `url()` that is not `url(#id)` on a paint. */
|
|
86
|
+
| "url"
|
|
87
|
+
/** A function outside `CSS_FUNCTIONS` (`image-set()`, `attr()`, `expression()`, …). */
|
|
88
|
+
| "function"
|
|
89
|
+
/** A value a property held to keywords may not take (`position: fixed`). */
|
|
90
|
+
| "value"
|
|
91
|
+
/** A selector that reaches past the view's own tree (`:host`, `::slotted`). */
|
|
92
|
+
| "selector"
|
|
93
|
+
/** Something the parser could not read: a bad string or url, a rule with no block, nesting past its depth. */
|
|
94
|
+
| "unreadable"
|
|
95
|
+
/** More CSS than a view may give. */
|
|
96
|
+
| "size";
|
|
97
|
+
export interface CssRefusal {
|
|
98
|
+
readonly reason: CssRefusalReason;
|
|
99
|
+
/** The at-rule, property, function or selector refused. */
|
|
100
|
+
readonly name?: string;
|
|
101
|
+
}
|
|
102
|
+
export interface SanitizedCss {
|
|
103
|
+
/** What may be drawn, written afresh from what was judged. */
|
|
104
|
+
readonly css: string;
|
|
105
|
+
/** What was not kept, in the order it was met. */
|
|
106
|
+
readonly refused: readonly CssRefusal[];
|
|
107
|
+
}
|
|
108
|
+
/** A VIEW'S STYLESHEET, judged: what may be drawn of it, and what was refused. */
|
|
109
|
+
export declare function sanitizeStylesheet(css: string, maxLength?: number): SanitizedCss;
|
|
110
|
+
/** A `style` attribute, judged: declarations only. */
|
|
111
|
+
export declare function sanitizeDeclarations(css: string, maxLength?: number): SanitizedCss;
|
|
112
|
+
/** One value for one property (an SVG presentation attribute), judged. */
|
|
113
|
+
export declare function sanitizeValue(property: string, value: string): {
|
|
114
|
+
readonly value: string;
|
|
115
|
+
} | {
|
|
116
|
+
readonly refused: CssRefusal;
|
|
117
|
+
};
|
|
118
|
+
//# sourceMappingURL=css.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"css.d.ts","sourceRoot":"","sources":["../../src/host/css.ts"],"names":[],"mappings":"AAyCA,MAAM,MAAM,KAAK,GACb;IAAE,QAAQ,CAAC,IAAI,EAAE,YAAY,CAAA;CAAE,GAC/B;IAAE,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GAClD;IAAE,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GACrD;IAAE,QAAQ,CAAC,IAAI,EAAE,YAAY,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GACvD;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,EAAE,OAAO,CAAA;CAAE,GACvE;IAAE,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GACnD;IAAE,QAAQ,CAAC,IAAI,EAAE,YAAY,CAAA;CAAE,GAC/B;IAAE,QAAQ,CAAC,IAAI,EAAE,KAAK,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GAChD;IAAE,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAA;CAAE,GAC5B;IAAE,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GAClD;IAAE,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;IAAC,QAAQ,CAAC,IAAI,EA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