@stacksjs/components 0.2.854 → 0.2.857
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/dist/CodeEditor-jg4w7e15.stx +497 -0
- package/dist/ContextMenu-43g3w5tp.stx +188 -0
- package/dist/DataGrid-7rt7v865.stx +376 -0
- package/dist/GraphView-0t3t9mec.stx +320 -0
- package/dist/JsonTree-satc4010.stx +317 -0
- package/dist/PreviewFrame-erbgvzj8.stx +257 -0
- package/dist/SplitPane-7sqfdwqa.stx +159 -0
- package/dist/code-editor/editor.js +2166 -0
- package/dist/component-api/component-api.js +36 -0
- package/dist/components/CodeBlock.d.ts +12 -5
- package/dist/context-menu/context-menu.js +575 -0
- package/dist/data-grid/data-grid.js +1244 -0
- package/dist/graph-view/graph-view.js +1408 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +34 -15
- package/dist/json-tree/json-tree.js +1121 -0
- package/dist/preview-frame/preview-frame.js +356 -0
- package/dist/split-pane/split-pane.js +364 -0
- package/dist/ui/code-editor/CodeEditor.d.ts +46 -0
- package/dist/ui/code-editor/controller.d.ts +103 -0
- package/dist/ui/code-editor/core/commands.d.ts +55 -0
- package/dist/ui/code-editor/core/completion.d.ts +40 -0
- package/dist/ui/code-editor/core/editor.d.ts +69 -0
- package/dist/ui/code-editor/core/highlight.d.ts +61 -0
- package/dist/ui/code-editor/core/history.d.ts +27 -0
- package/dist/ui/code-editor/core/index.d.ts +13 -0
- package/dist/ui/code-editor/core/keymap.d.ts +38 -0
- package/dist/ui/code-editor/core/selection.d.ts +30 -0
- package/dist/ui/code-editor/core/text.d.ts +64 -0
- package/dist/ui/code-editor/editor.d.ts +15 -0
- package/dist/ui/code-editor/index.d.ts +29 -0
- package/dist/ui/code-editor/tokenizer.d.ts +18 -0
- package/dist/ui/code-editor/view.d.ts +59 -0
- package/dist/ui/context-menu/ContextMenu.d.ts +14 -0
- package/dist/ui/context-menu/context-menu.d.ts +8 -0
- package/dist/ui/context-menu/core.d.ts +74 -0
- package/dist/ui/context-menu/index.d.ts +11 -0
- package/dist/ui/context-menu/view.d.ts +36 -0
- package/dist/ui/data-grid/DataGrid.d.ts +30 -0
- package/dist/ui/data-grid/core.d.ts +141 -0
- package/dist/ui/data-grid/data-grid.d.ts +9 -0
- package/dist/ui/data-grid/index.d.ts +20 -0
- package/dist/ui/data-grid/view.d.ts +56 -0
- package/dist/ui/graph-view/GraphView.d.ts +21 -0
- package/dist/ui/graph-view/core/edges.d.ts +34 -0
- package/dist/ui/graph-view/core/force.d.ts +10 -0
- package/dist/ui/graph-view/core/graph.d.ts +83 -0
- package/dist/ui/graph-view/core/index.d.ts +5 -0
- package/dist/ui/graph-view/core/layered.d.ts +24 -0
- package/dist/ui/graph-view/core/viewport.d.ts +34 -0
- package/dist/ui/graph-view/graph-view.d.ts +9 -0
- package/dist/ui/graph-view/index.d.ts +21 -0
- package/dist/ui/graph-view/view.d.ts +51 -0
- package/dist/ui/json-tree/JsonTree.d.ts +18 -0
- package/dist/ui/json-tree/core.d.ts +108 -0
- package/dist/ui/json-tree/index.d.ts +18 -0
- package/dist/ui/json-tree/json-tree.d.ts +10 -0
- package/dist/ui/json-tree/tinker.d.ts +84 -0
- package/dist/ui/json-tree/view.d.ts +59 -0
- package/dist/ui/preview-frame/PreviewFrame.d.ts +44 -0
- package/dist/ui/preview-frame/core.d.ts +81 -0
- package/dist/ui/preview-frame/index.d.ts +19 -0
- package/dist/ui/preview-frame/preview-frame.d.ts +8 -0
- package/dist/ui/preview-frame/view.d.ts +37 -0
- package/dist/ui/split-pane/SplitPane.d.ts +18 -0
- package/dist/ui/split-pane/core.d.ts +58 -0
- package/dist/ui/split-pane/index.d.ts +15 -0
- package/dist/ui/split-pane/split-pane.d.ts +8 -0
- package/dist/ui/split-pane/view.d.ts +27 -0
- package/dist/ui/virtual-table/index.d.ts +6 -0
- package/dist/utils/component-api.d.ts +4 -0
- package/dist/utils/highlighter.d.ts +19 -1
- package/dist/utils/highlighter.js +24 -7
- package/dist/utils/syntax-theme.d.ts +44 -0
- package/package.json +44 -4
- package/src/components/CodeBlock.stx +195 -17
- package/src/index.ts +10 -0
- package/src/ui/code-editor/CodeEditor.stx +497 -0
- package/src/ui/code-editor/README.md +135 -0
- package/src/ui/code-editor/controller.ts +517 -0
- package/src/ui/code-editor/core/commands.ts +381 -0
- package/src/ui/code-editor/core/completion.ts +212 -0
- package/src/ui/code-editor/core/editor.ts +319 -0
- package/src/ui/code-editor/core/highlight.ts +203 -0
- package/src/ui/code-editor/core/history.ts +190 -0
- package/src/ui/code-editor/core/index.ts +14 -0
- package/src/ui/code-editor/core/keymap.ts +125 -0
- package/src/ui/code-editor/core/selection.ts +104 -0
- package/src/ui/code-editor/core/text.ts +252 -0
- package/src/ui/code-editor/editor.ts +16 -0
- package/src/ui/code-editor/index.ts +46 -0
- package/src/ui/code-editor/tokenizer.ts +74 -0
- package/src/ui/code-editor/view.ts +1066 -0
- package/src/ui/context-menu/ContextMenu.stx +188 -0
- package/src/ui/context-menu/README.md +117 -0
- package/src/ui/context-menu/context-menu.ts +8 -0
- package/src/ui/context-menu/core.ts +250 -0
- package/src/ui/context-menu/index.ts +16 -0
- package/src/ui/context-menu/view.ts +540 -0
- package/src/ui/data-grid/DataGrid.stx +376 -0
- package/src/ui/data-grid/README.md +204 -0
- package/src/ui/data-grid/core.ts +813 -0
- package/src/ui/data-grid/data-grid.ts +9 -0
- package/src/ui/data-grid/index.ts +34 -0
- package/src/ui/data-grid/view.ts +806 -0
- package/src/ui/graph-view/GraphView.stx +320 -0
- package/src/ui/graph-view/README.md +210 -0
- package/src/ui/graph-view/core/edges.ts +180 -0
- package/src/ui/graph-view/core/force.ts +237 -0
- package/src/ui/graph-view/core/graph.ts +277 -0
- package/src/ui/graph-view/core/index.ts +5 -0
- package/src/ui/graph-view/core/layered.ts +256 -0
- package/src/ui/graph-view/core/viewport.ts +141 -0
- package/src/ui/graph-view/graph-view.ts +9 -0
- package/src/ui/graph-view/index.ts +35 -0
- package/src/ui/graph-view/view.ts +809 -0
- package/src/ui/json-tree/JsonTree.stx +317 -0
- package/src/ui/json-tree/README.md +193 -0
- package/src/ui/json-tree/core.ts +588 -0
- package/src/ui/json-tree/index.ts +28 -0
- package/src/ui/json-tree/json-tree.ts +10 -0
- package/src/ui/json-tree/tinker.ts +349 -0
- package/src/ui/json-tree/view.ts +665 -0
- package/src/ui/preview-frame/PreviewFrame.stx +257 -0
- package/src/ui/preview-frame/README.md +107 -0
- package/src/ui/preview-frame/core.ts +195 -0
- package/src/ui/preview-frame/index.ts +31 -0
- package/src/ui/preview-frame/preview-frame.ts +8 -0
- package/src/ui/preview-frame/view.ts +336 -0
- package/src/ui/split-pane/README.md +87 -0
- package/src/ui/split-pane/SplitPane.stx +159 -0
- package/src/ui/split-pane/core.ts +200 -0
- package/src/ui/split-pane/index.ts +24 -0
- package/src/ui/split-pane/split-pane.ts +8 -0
- package/src/ui/split-pane/view.ts +305 -0
- package/src/ui/virtual-table/index.ts +6 -0
- package/src/utils/component-api.ts +72 -0
- package/src/utils/highlighter.ts +121 -218
- package/src/utils/syntax-theme.ts +144 -0
|
@@ -0,0 +1,356 @@
|
|
|
1
|
+
// src/ui/preview-frame/core.ts
|
|
2
|
+
var VIEWPORT_PRESETS = [
|
|
3
|
+
{ name: "phone", label: "Phone", width: 390, height: 844 },
|
|
4
|
+
{ name: "tablet", label: "Tablet", width: 820, height: 1180 },
|
|
5
|
+
{ name: "desktop", label: "Desktop", width: 1280, height: 800 }
|
|
6
|
+
];
|
|
7
|
+
function positive(value) {
|
|
8
|
+
const number = typeof value === "string" ? Number.parseFloat(value) : value;
|
|
9
|
+
return typeof number === "number" && Number.isFinite(number) && number > 0 ? Math.round(number) : null;
|
|
10
|
+
}
|
|
11
|
+
function resolveViewport(name, options = {}) {
|
|
12
|
+
const width = positive(options.width);
|
|
13
|
+
const height = positive(options.height);
|
|
14
|
+
const landscape = Boolean(options.landscape);
|
|
15
|
+
if (width && height)
|
|
16
|
+
return { name: "custom", size: { width, height }, landscape: false };
|
|
17
|
+
const preset = VIEWPORT_PRESETS.find((entry) => entry.name === name);
|
|
18
|
+
if (!preset)
|
|
19
|
+
return { name: "fill", size: null, landscape: false };
|
|
20
|
+
const turn = landscape && preset.height > preset.width;
|
|
21
|
+
return {
|
|
22
|
+
name: preset.name,
|
|
23
|
+
size: turn ? { width: preset.height, height: preset.width } : { width: preset.width, height: preset.height },
|
|
24
|
+
landscape: turn
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
function fitScale(viewport, available, padding = 0) {
|
|
28
|
+
const width = available.width - padding * 2;
|
|
29
|
+
const height = available.height - padding * 2;
|
|
30
|
+
if (width <= 0 || height <= 0 || viewport.width <= 0 || viewport.height <= 0)
|
|
31
|
+
return 1;
|
|
32
|
+
return Math.min(1, width / viewport.width, height / viewport.height);
|
|
33
|
+
}
|
|
34
|
+
function describeViewport(viewport, scale = 1) {
|
|
35
|
+
if (!viewport.size)
|
|
36
|
+
return "Fills the frame";
|
|
37
|
+
const size = `${viewport.size.width} × ${viewport.size.height}`;
|
|
38
|
+
return scale < 0.995 ? `${size} at ${Math.round(scale * 100)}%` : size;
|
|
39
|
+
}
|
|
40
|
+
function normalizeScheme(value) {
|
|
41
|
+
return value === "light" || value === "dark" ? value : "auto";
|
|
42
|
+
}
|
|
43
|
+
var FORBIDDEN_SANDBOX_TOKENS = [
|
|
44
|
+
"allow-same-origin",
|
|
45
|
+
"allow-top-navigation",
|
|
46
|
+
"allow-top-navigation-by-user-activation",
|
|
47
|
+
"allow-top-navigation-to-custom-protocols",
|
|
48
|
+
"allow-popups",
|
|
49
|
+
"allow-popups-to-escape-sandbox",
|
|
50
|
+
"allow-modals",
|
|
51
|
+
"allow-downloads",
|
|
52
|
+
"allow-pointer-lock",
|
|
53
|
+
"allow-presentation",
|
|
54
|
+
"allow-storage-access-by-user-activation"
|
|
55
|
+
];
|
|
56
|
+
function sandboxValue(options = {}) {
|
|
57
|
+
const tokens = [];
|
|
58
|
+
if (options.scripts)
|
|
59
|
+
tokens.push("allow-scripts");
|
|
60
|
+
if (options.forms)
|
|
61
|
+
tokens.push("allow-forms");
|
|
62
|
+
return tokens.join(" ");
|
|
63
|
+
}
|
|
64
|
+
function isIsolatingSandbox(value) {
|
|
65
|
+
const tokens = value.toLowerCase().split(/\s+/).filter(Boolean);
|
|
66
|
+
return !tokens.some((token) => FORBIDDEN_SANDBOX_TOKENS.includes(token));
|
|
67
|
+
}
|
|
68
|
+
var HAS_DOCUMENT = /<!doctype\s|<html[\s>]/i;
|
|
69
|
+
var HEAD_OPEN = /<head(?:\s[^>]*)?>/i;
|
|
70
|
+
var HTML_OPEN = /<html(?:\s[^>]*)?>/i;
|
|
71
|
+
var HAS_BASE = /<base[\s>]/i;
|
|
72
|
+
var HAS_COLOR_SCHEME = /<meta[^>]+name\s*=\s*["']?color-scheme/i;
|
|
73
|
+
function escapeHtml(text) {
|
|
74
|
+
return text.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
75
|
+
}
|
|
76
|
+
function buildDocument(html, options = {}) {
|
|
77
|
+
const source = html == null ? "" : String(html);
|
|
78
|
+
const base = '<base target="_blank">';
|
|
79
|
+
if (!HAS_DOCUMENT.test(source)) {
|
|
80
|
+
const title = options.title ? `<title>${escapeHtml(options.title)}</title>` : "";
|
|
81
|
+
return `<!doctype html><html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><meta name="color-scheme" content="light dark">${base}${title}</head><body>${source}</body></html>`;
|
|
82
|
+
}
|
|
83
|
+
if (HAS_BASE.test(source))
|
|
84
|
+
return source;
|
|
85
|
+
if (HEAD_OPEN.test(source))
|
|
86
|
+
return source.replace(HEAD_OPEN, (match) => match + base);
|
|
87
|
+
if (HTML_OPEN.test(source))
|
|
88
|
+
return source.replace(HTML_OPEN, (match) => `${match}<head>${base}</head>`);
|
|
89
|
+
return base + source;
|
|
90
|
+
}
|
|
91
|
+
function declaresColorScheme(html) {
|
|
92
|
+
return HAS_COLOR_SCHEME.test(html);
|
|
93
|
+
}
|
|
94
|
+
function stepViewport(name, direction) {
|
|
95
|
+
const order = ["fill", ...VIEWPORT_PRESETS.map((preset) => preset.name)];
|
|
96
|
+
const index = order.indexOf(name);
|
|
97
|
+
return order[((index < 0 ? 0 : index) + direction + order.length) % order.length];
|
|
98
|
+
}
|
|
99
|
+
// src/ui/preview-frame/view.ts
|
|
100
|
+
var STAGE_PADDING = 16;
|
|
101
|
+
|
|
102
|
+
class PreviewFrameView {
|
|
103
|
+
root;
|
|
104
|
+
callbacks;
|
|
105
|
+
html;
|
|
106
|
+
viewportName;
|
|
107
|
+
frameWidth;
|
|
108
|
+
frameHeight;
|
|
109
|
+
landscape;
|
|
110
|
+
scheme;
|
|
111
|
+
scripts;
|
|
112
|
+
forms;
|
|
113
|
+
title;
|
|
114
|
+
viewport;
|
|
115
|
+
scale = 1;
|
|
116
|
+
frame = null;
|
|
117
|
+
stage;
|
|
118
|
+
device;
|
|
119
|
+
observer = null;
|
|
120
|
+
pending = 0;
|
|
121
|
+
disposers = [];
|
|
122
|
+
constructor(root, options = {}, callbacks = {}) {
|
|
123
|
+
this.root = root;
|
|
124
|
+
this.callbacks = callbacks;
|
|
125
|
+
this.html = options.html ?? "";
|
|
126
|
+
this.viewportName = options.viewport || "fill";
|
|
127
|
+
this.frameWidth = options.frameWidth ?? null;
|
|
128
|
+
this.frameHeight = options.frameHeight ?? null;
|
|
129
|
+
this.landscape = Boolean(options.landscape);
|
|
130
|
+
this.scheme = normalizeScheme(options.scheme);
|
|
131
|
+
this.scripts = Boolean(options.scripts);
|
|
132
|
+
this.forms = Boolean(options.forms);
|
|
133
|
+
this.title = options.title || "Preview";
|
|
134
|
+
this.viewport = this.resolve();
|
|
135
|
+
this.stage = this.part("stage");
|
|
136
|
+
this.device = this.part("device");
|
|
137
|
+
const onClick = (event) => this.onToolbarClick(event);
|
|
138
|
+
const onKey = (event) => this.onToolbarKey(event);
|
|
139
|
+
this.root.addEventListener("click", onClick);
|
|
140
|
+
this.root.addEventListener("keydown", onKey);
|
|
141
|
+
this.disposers.push(() => this.root.removeEventListener("click", onClick), () => this.root.removeEventListener("keydown", onKey));
|
|
142
|
+
if (typeof ResizeObserver !== "undefined") {
|
|
143
|
+
this.observer = new ResizeObserver(() => {
|
|
144
|
+
cancelAnimationFrame(this.pending);
|
|
145
|
+
this.pending = requestAnimationFrame(() => this.layout());
|
|
146
|
+
});
|
|
147
|
+
this.observer.observe(this.stage);
|
|
148
|
+
}
|
|
149
|
+
this.load();
|
|
150
|
+
this.reflect();
|
|
151
|
+
this.root.setAttribute("data-preview-ready", "");
|
|
152
|
+
}
|
|
153
|
+
getState() {
|
|
154
|
+
return {
|
|
155
|
+
viewport: this.viewport.name,
|
|
156
|
+
width: this.viewport.size?.width ?? null,
|
|
157
|
+
height: this.viewport.size?.height ?? null,
|
|
158
|
+
landscape: this.viewport.landscape,
|
|
159
|
+
scale: this.scale,
|
|
160
|
+
scheme: this.scheme,
|
|
161
|
+
effectiveScheme: this.effectiveScheme()
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
setHtml(html) {
|
|
165
|
+
const next = html == null ? "" : String(html);
|
|
166
|
+
if (next === this.html)
|
|
167
|
+
return;
|
|
168
|
+
this.html = next;
|
|
169
|
+
this.load();
|
|
170
|
+
}
|
|
171
|
+
setViewport(name, options = {}) {
|
|
172
|
+
this.viewportName = name || "fill";
|
|
173
|
+
if ("landscape" in options)
|
|
174
|
+
this.landscape = Boolean(options.landscape);
|
|
175
|
+
if ("width" in options)
|
|
176
|
+
this.frameWidth = options.width ?? null;
|
|
177
|
+
if ("height" in options)
|
|
178
|
+
this.frameHeight = options.height ?? null;
|
|
179
|
+
const before = JSON.stringify(this.viewport);
|
|
180
|
+
this.viewport = this.resolve();
|
|
181
|
+
this.layout();
|
|
182
|
+
this.reflect();
|
|
183
|
+
if (JSON.stringify(this.viewport) !== before)
|
|
184
|
+
this.callbacks.onViewport?.(this.getState());
|
|
185
|
+
}
|
|
186
|
+
setScheme(scheme) {
|
|
187
|
+
const next = normalizeScheme(scheme);
|
|
188
|
+
if (next === this.scheme)
|
|
189
|
+
return;
|
|
190
|
+
this.scheme = next;
|
|
191
|
+
this.applyScheme();
|
|
192
|
+
this.reflect();
|
|
193
|
+
this.callbacks.onScheme?.(this.getState());
|
|
194
|
+
}
|
|
195
|
+
setPermissions(options) {
|
|
196
|
+
const scripts = options.scripts ?? this.scripts;
|
|
197
|
+
const forms = options.forms ?? this.forms;
|
|
198
|
+
if (scripts === this.scripts && forms === this.forms)
|
|
199
|
+
return;
|
|
200
|
+
this.scripts = scripts;
|
|
201
|
+
this.forms = forms;
|
|
202
|
+
this.load();
|
|
203
|
+
}
|
|
204
|
+
reload() {
|
|
205
|
+
this.load();
|
|
206
|
+
this.callbacks.onReload?.(this.getState());
|
|
207
|
+
}
|
|
208
|
+
destroy() {
|
|
209
|
+
this.observer?.disconnect();
|
|
210
|
+
cancelAnimationFrame(this.pending);
|
|
211
|
+
for (const dispose of this.disposers)
|
|
212
|
+
dispose();
|
|
213
|
+
this.frame?.remove();
|
|
214
|
+
this.frame = null;
|
|
215
|
+
this.root.removeAttribute("data-preview-ready");
|
|
216
|
+
}
|
|
217
|
+
part(name) {
|
|
218
|
+
const found = this.root.querySelector(`[data-pf="${name}"]`);
|
|
219
|
+
if (!found)
|
|
220
|
+
throw new Error(`PreviewFrame: the template has no ${name} part`);
|
|
221
|
+
return found;
|
|
222
|
+
}
|
|
223
|
+
resolve() {
|
|
224
|
+
return resolveViewport(this.viewportName, { width: this.frameWidth, height: this.frameHeight, landscape: this.landscape });
|
|
225
|
+
}
|
|
226
|
+
effectiveScheme() {
|
|
227
|
+
if (this.scheme !== "auto")
|
|
228
|
+
return this.scheme;
|
|
229
|
+
if (this.root.closest(".dark"))
|
|
230
|
+
return "dark";
|
|
231
|
+
if (this.root.closest(".light"))
|
|
232
|
+
return "light";
|
|
233
|
+
return typeof matchMedia === "function" && matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
|
|
234
|
+
}
|
|
235
|
+
load() {
|
|
236
|
+
const frame = document.createElement("iframe");
|
|
237
|
+
frame.setAttribute("sandbox", sandboxValue({ scripts: this.scripts, forms: this.forms }));
|
|
238
|
+
frame.setAttribute("referrerpolicy", "no-referrer");
|
|
239
|
+
frame.setAttribute("title", this.title);
|
|
240
|
+
frame.setAttribute("data-pf", "frame");
|
|
241
|
+
frame.className = "stx-preview-frame";
|
|
242
|
+
frame.addEventListener("load", () => {
|
|
243
|
+
if (frame === this.frame)
|
|
244
|
+
this.callbacks.onLoad?.(this.getState());
|
|
245
|
+
});
|
|
246
|
+
frame.srcdoc = buildDocument(this.html, { title: this.title });
|
|
247
|
+
this.frame?.remove();
|
|
248
|
+
this.frame = frame;
|
|
249
|
+
this.applyScheme();
|
|
250
|
+
this.device.appendChild(frame);
|
|
251
|
+
this.layout();
|
|
252
|
+
}
|
|
253
|
+
applyScheme() {
|
|
254
|
+
const scheme = this.effectiveScheme();
|
|
255
|
+
this.root.setAttribute("data-scheme", scheme);
|
|
256
|
+
if (this.frame)
|
|
257
|
+
this.frame.style.colorScheme = scheme;
|
|
258
|
+
}
|
|
259
|
+
layout() {
|
|
260
|
+
const frame = this.frame;
|
|
261
|
+
if (!frame)
|
|
262
|
+
return;
|
|
263
|
+
const size = this.viewport.size;
|
|
264
|
+
this.root.setAttribute("data-viewport", this.viewport.name);
|
|
265
|
+
if (!size) {
|
|
266
|
+
this.scale = 1;
|
|
267
|
+
this.device.style.width = "";
|
|
268
|
+
this.device.style.height = "";
|
|
269
|
+
frame.style.width = "";
|
|
270
|
+
frame.style.height = "";
|
|
271
|
+
frame.style.transform = "";
|
|
272
|
+
} else {
|
|
273
|
+
const box = this.stage.getBoundingClientRect();
|
|
274
|
+
this.scale = fitScale(size, { width: box.width, height: box.height }, STAGE_PADDING);
|
|
275
|
+
this.device.style.width = `${size.width * this.scale}px`;
|
|
276
|
+
this.device.style.height = `${size.height * this.scale}px`;
|
|
277
|
+
frame.style.width = `${size.width}px`;
|
|
278
|
+
frame.style.height = `${size.height}px`;
|
|
279
|
+
frame.style.transform = this.scale === 1 ? "" : `scale(${this.scale})`;
|
|
280
|
+
}
|
|
281
|
+
const readout = this.root.querySelector('[data-pf="size"]');
|
|
282
|
+
if (readout)
|
|
283
|
+
readout.textContent = describeViewport(this.viewport, this.scale);
|
|
284
|
+
}
|
|
285
|
+
reflect() {
|
|
286
|
+
for (const button of this.root.querySelectorAll("[data-pf-viewport]")) {
|
|
287
|
+
const chosen = button.getAttribute("data-pf-viewport") === this.viewport.name;
|
|
288
|
+
button.setAttribute("aria-checked", String(chosen));
|
|
289
|
+
button.tabIndex = chosen ? 0 : -1;
|
|
290
|
+
}
|
|
291
|
+
if (!this.root.querySelector('[data-pf-viewport][tabindex="0"]'))
|
|
292
|
+
this.root.querySelector("[data-pf-viewport]")?.setAttribute("tabindex", "0");
|
|
293
|
+
const dark = this.effectiveScheme() === "dark";
|
|
294
|
+
const scheme = this.root.querySelector('[data-pf-action="scheme"]');
|
|
295
|
+
if (scheme) {
|
|
296
|
+
scheme.setAttribute("aria-pressed", String(dark));
|
|
297
|
+
const text = scheme.querySelector('[data-pf="scheme-text"]');
|
|
298
|
+
if (text)
|
|
299
|
+
text.textContent = dark ? "Dark" : "Light";
|
|
300
|
+
}
|
|
301
|
+
const rotate = this.root.querySelector('[data-pf-action="rotate"]');
|
|
302
|
+
if (rotate) {
|
|
303
|
+
const size = resolveViewport(this.viewportName, { width: this.frameWidth, height: this.frameHeight }).size;
|
|
304
|
+
rotate.disabled = !size || this.viewport.name === "custom" || size.height <= size.width;
|
|
305
|
+
rotate.setAttribute("aria-pressed", String(this.viewport.landscape));
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
onToolbarClick(event) {
|
|
309
|
+
const target = event.target instanceof Element ? event.target.closest("[data-pf-viewport], [data-pf-action]") : null;
|
|
310
|
+
if (!target || !this.root.contains(target))
|
|
311
|
+
return;
|
|
312
|
+
const viewport = target.getAttribute("data-pf-viewport");
|
|
313
|
+
if (viewport) {
|
|
314
|
+
this.setViewport(viewport, { width: null, height: null });
|
|
315
|
+
return;
|
|
316
|
+
}
|
|
317
|
+
switch (target.getAttribute("data-pf-action")) {
|
|
318
|
+
case "scheme":
|
|
319
|
+
this.setScheme(this.effectiveScheme() === "dark" ? "light" : "dark");
|
|
320
|
+
break;
|
|
321
|
+
case "rotate":
|
|
322
|
+
this.setViewport(this.viewportName, { landscape: !this.landscape });
|
|
323
|
+
break;
|
|
324
|
+
case "reload":
|
|
325
|
+
this.reload();
|
|
326
|
+
break;
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
onToolbarKey(event) {
|
|
330
|
+
const target = event.target instanceof Element ? event.target.closest("[data-pf-viewport]") : null;
|
|
331
|
+
if (!target)
|
|
332
|
+
return;
|
|
333
|
+
const direction = event.key === "ArrowRight" || event.key === "ArrowDown" ? 1 : event.key === "ArrowLeft" || event.key === "ArrowUp" ? -1 : 0;
|
|
334
|
+
if (direction === 0)
|
|
335
|
+
return;
|
|
336
|
+
event.preventDefault();
|
|
337
|
+
const current = target.getAttribute("data-pf-viewport") || "fill";
|
|
338
|
+
const next = stepViewport(current, direction);
|
|
339
|
+
this.setViewport(next, { width: null, height: null });
|
|
340
|
+
this.root.querySelector(`[data-pf-viewport="${next}"]`)?.focus();
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
export {
|
|
344
|
+
FORBIDDEN_SANDBOX_TOKENS,
|
|
345
|
+
PreviewFrameView,
|
|
346
|
+
VIEWPORT_PRESETS,
|
|
347
|
+
buildDocument,
|
|
348
|
+
declaresColorScheme,
|
|
349
|
+
describeViewport,
|
|
350
|
+
fitScale,
|
|
351
|
+
isIsolatingSandbox,
|
|
352
|
+
normalizeScheme,
|
|
353
|
+
resolveViewport,
|
|
354
|
+
sandboxValue,
|
|
355
|
+
stepViewport
|
|
356
|
+
};
|