@perkyzz/emvb 0.3.0 → 0.5.0
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 +22 -4
- package/THIRD_PARTY_NOTICES.md +1 -1
- package/package.json +5 -2
- package/src/admin/access/role.ts +9 -3
- package/src/admin/agents-api.ts +39 -0
- package/src/admin/api.ts +17 -7
- package/src/admin/content-api.ts +7 -51
- package/src/admin/content-item.ts +22 -0
- package/src/admin/design-api.ts +30 -0
- package/src/admin/editor/A11yCopilot.tsx +1 -1
- package/src/admin/editor/CommandPalette.tsx +43 -2
- package/src/admin/editor/Editor.tsx +133 -332
- package/src/admin/editor/EditorOverlay.tsx +3 -1
- package/src/admin/editor/PerfMeter.tsx +1 -1
- package/src/admin/editor/ShortcutsDialog.tsx +4 -1
- package/src/admin/editor/Timeline.tsx +124 -9
- package/src/admin/editor/canvas/CanvasFrame.tsx +51 -368
- package/src/admin/editor/canvas/DeviceBar.tsx +4 -1
- package/src/admin/editor/canvas/SelectionOverlay.tsx +86 -46
- package/src/admin/editor/canvas/canvas-scale.ts +20 -0
- package/src/admin/editor/canvas/drop-line.ts +24 -0
- package/src/admin/editor/canvas/use-canvas-dnd.ts +207 -0
- package/src/admin/editor/canvas/use-canvas-session.ts +216 -0
- package/src/admin/editor/collection-previews.ts +28 -5
- package/src/admin/editor/editor-chrome.tsx +346 -0
- package/src/admin/editor/editor-commands.ts +360 -0
- package/src/admin/editor/editor-css.ts +4 -0
- package/src/admin/editor/element-chrome.ts +89 -0
- package/src/admin/editor/feature-css.ts +37 -18
- package/src/admin/editor/host.ts +33 -0
- package/src/admin/editor/icons/IconLibraryDialog.tsx +64 -218
- package/src/admin/editor/icons/library.ts +29 -19
- package/src/admin/editor/icons/use-icon-library.ts +315 -0
- package/src/admin/editor/palette-items.ts +36 -5
- package/src/admin/editor/palette.ts +9 -4
- package/src/admin/editor/panels/AddPanel.tsx +2 -67
- package/src/admin/editor/panels/ColorControl.tsx +21 -18
- package/src/admin/editor/panels/ElementPanel.tsx +40 -99
- package/src/admin/editor/panels/LayersPanel.tsx +34 -62
- package/src/admin/editor/panels/SettingsPanel.tsx +1 -0
- package/src/admin/editor/panels/SiteStylesDrawer.tsx +16 -10
- package/src/admin/editor/panels/TokenScales.tsx +4 -2
- package/src/admin/editor/panels/VariableSection.tsx +1 -10
- package/src/admin/editor/panels/color-space.ts +12 -1
- package/src/admin/editor/panels/inline-error.tsx +11 -0
- package/src/admin/editor/panels/settings/AdvancedFields.tsx +143 -1
- package/src/admin/editor/panels/settings/AudienceEditor.tsx +115 -7
- package/src/admin/editor/panels/settings/DraftTextField.tsx +42 -9
- package/src/admin/editor/panels/settings/FieldControl.tsx +6 -0
- package/src/admin/editor/panels/settings/FormBindControl.tsx +8 -4
- package/src/admin/editor/panels/settings/IconPicker.tsx +21 -1
- package/src/admin/editor/panels/settings/ImageSourcesField.tsx +111 -0
- package/src/admin/editor/panels/settings/ItemList.tsx +34 -1
- package/src/admin/editor/panels/settings/MediaPicker.tsx +2 -3
- package/src/admin/editor/panels/settings/QueryStyleRows.tsx +178 -0
- package/src/admin/editor/panels/settings/StyleRow.tsx +14 -2
- package/src/admin/editor/panels/settings/advanced-rules.ts +3 -0
- package/src/admin/editor/panels/settings/form-names.ts +7 -11
- package/src/admin/editor/panels/settings/length-units.ts +15 -4
- package/src/admin/editor/panels/settings/link-rules.ts +19 -0
- package/src/admin/editor/panels/settings/number-input.ts +11 -0
- package/src/admin/editor/panels/settings/query-style.ts +65 -0
- package/src/admin/editor/panels/settings/style-sections.ts +5 -1
- package/src/admin/editor/panels/style-target.ts +105 -0
- package/src/admin/editor/panels/variable-values.ts +4 -2
- package/src/admin/editor/remote-change.ts +67 -0
- package/src/admin/editor/section-templates.ts +43 -21
- package/src/admin/editor/shortcuts.ts +4 -0
- package/src/admin/editor/store.ts +10 -1
- package/src/admin/editor/useClipboardActions.ts +1 -1
- package/src/admin/editor/useEditorCommands.ts +61 -13
- package/src/admin/editor/useEditorData.ts +7 -1
- package/src/admin/editor/useEditorShortcuts.ts +23 -15
- package/src/admin/editor/useNodeActions.ts +6 -1
- package/src/admin/forms-api.ts +17 -6
- package/src/admin/icon-uploads-api.ts +18 -0
- package/src/admin/index.tsx +3 -1
- package/src/admin/media-api.ts +20 -0
- package/src/admin/pages/AgentsPage.tsx +274 -0
- package/src/admin/theme-api.ts +5 -18
- package/src/admin/ui.ts +28 -0
- package/src/astro/content-port.ts +24 -0
- package/src/astro/floats/runtime.ts +10 -0
- package/src/astro/forms/EmVBFormsClient.astro +11 -0
- package/src/astro/forms/EmVBFormsRuntime.astro +6 -7
- package/src/astro/forms/client.ts +1 -0
- package/src/astro/forms-definitions.ts +24 -11
- package/src/astro/index.ts +1 -0
- package/src/astro/popups/runtime.ts +15 -0
- package/src/astro/render-session.ts +85 -0
- package/src/astro/request-data.ts +20 -8
- package/src/astro/resolve-theme.ts +166 -76
- package/src/astro/resolve.ts +57 -16
- package/src/astro/tabs/runtime.ts +60 -1
- package/src/astro/theme-posts.ts +16 -5
- package/src/astro/visitor.ts +67 -5
- package/src/constants.ts +1 -1
- package/src/core/a11y/audit.ts +202 -26
- package/src/core/arrange.ts +71 -38
- package/src/core/audience/rules.ts +22 -2
- package/src/core/canvas-styles.ts +24 -0
- package/src/core/clipboard.ts +11 -32
- package/src/core/css/generate.ts +18 -1
- package/src/core/css/print.ts +12 -0
- package/src/core/css/scope.ts +3 -3
- package/src/core/css-keywords.ts +83 -0
- package/src/core/data/bindings.ts +4 -6
- package/src/core/design/classes.ts +13 -15
- package/src/core/design/diff.ts +55 -0
- package/src/core/design/merge.ts +127 -0
- package/src/core/design/variables.ts +25 -21
- package/src/core/elements/dynamic-elements.ts +30 -0
- package/src/core/elements/form-elements.ts +20 -3
- package/src/core/elements/index.ts +211 -7
- package/src/core/forms/binding.ts +4 -13
- package/src/core/index.ts +10 -0
- package/src/core/local-style.ts +27 -0
- package/src/core/migrate/index.ts +9 -4
- package/src/core/nesting.ts +4 -23
- package/src/core/perf/scripts.ts +9 -6
- package/src/core/record.ts +3 -0
- package/src/core/render/context.ts +2 -0
- package/src/core/render/dynamic-post.ts +22 -7
- package/src/core/render/form.ts +145 -15
- package/src/core/render/index.ts +195 -14
- package/src/core/render/pagination.ts +21 -2
- package/src/core/render/vnode.ts +12 -2
- package/src/core/sanitize/css.ts +90 -77
- package/src/core/sanitize/embed-url.ts +7 -1
- package/src/core/sanitize/href.ts +13 -1
- package/src/core/sanitize/svg.ts +8 -3
- package/src/core/sanitize/url.ts +10 -1
- package/src/core/schema/descriptors.ts +4 -1
- package/src/core/schema/design.ts +5 -7
- package/src/core/schema/layout.ts +160 -181
- package/src/core/schema/style.ts +53 -63
- package/src/core/share/link.ts +72 -29
- package/src/core/tabs/presence.ts +7 -17
- package/src/core/theme/dynamic.ts +205 -39
- package/src/core/theme/float.ts +1 -1
- package/src/core/tree-ops.ts +57 -0
- package/src/index.ts +14 -2
- package/src/mcp/errors.ts +44 -0
- package/src/mcp/index.ts +4 -0
- package/src/mcp/ports.ts +78 -0
- package/src/mcp/prompts.ts +76 -0
- package/src/mcp/publish.ts +60 -0
- package/src/mcp/queue.ts +19 -0
- package/src/mcp/rate-limit.ts +80 -0
- package/src/mcp/read.ts +419 -0
- package/src/mcp/refs.ts +84 -0
- package/src/mcp/settings.ts +18 -0
- package/src/mcp/tools.ts +265 -0
- package/src/mcp/write.ts +582 -0
- package/src/server/agent-settings.ts +134 -0
- package/src/server/design-routes.ts +75 -18
- package/src/server/icon-routes.ts +72 -16
- package/src/server/mcp-routes.ts +265 -0
- package/src/server/plugin.ts +40 -4
- package/src/admin/editor/icons/sets/fontawesome.json +0 -1
- package/src/admin/editor/icons/sets/lucide.json +0 -1
- package/src/admin/editor/icons/sets/remix.json +0 -1
- package/src/admin/editor/icons/sets/tabler.json +0 -1
package/src/core/schema/style.ts
CHANGED
|
@@ -1,4 +1,25 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
+
import {
|
|
3
|
+
ALIGN_ITEMS,
|
|
4
|
+
BACKGROUND_POSITIONS,
|
|
5
|
+
BACKGROUND_REPEATS,
|
|
6
|
+
BACKGROUND_SIZES,
|
|
7
|
+
BORDER_STYLES,
|
|
8
|
+
CURSORS,
|
|
9
|
+
FLEX_DIRECTIONS,
|
|
10
|
+
FLEX_WRAPS,
|
|
11
|
+
HEX_COLOR,
|
|
12
|
+
JUSTIFY_CONTENT,
|
|
13
|
+
LENGTH_UNITS,
|
|
14
|
+
OBJECT_FITS,
|
|
15
|
+
OVERFLOWS,
|
|
16
|
+
POSITIONS,
|
|
17
|
+
TEXT_ALIGNS,
|
|
18
|
+
TEXT_DECORATIONS,
|
|
19
|
+
TEXT_TRANSFORMS,
|
|
20
|
+
TRANSITION_EASINGS,
|
|
21
|
+
TRANSITION_PROPERTIES,
|
|
22
|
+
} from "../css-keywords.ts";
|
|
2
23
|
import { isSafeFontStack } from "../sanitize/css.ts";
|
|
3
24
|
import { sanitizeMediaUrl } from "../sanitize/media-url.ts";
|
|
4
25
|
import { POPUP_DEVICES } from "../theme/popup-rules.ts";
|
|
@@ -10,13 +31,13 @@ export const VariableRef = z.strictObject({
|
|
|
10
31
|
from: z.enum(["color", "font", "fontSize", "spacing"]).optional(),
|
|
11
32
|
});
|
|
12
33
|
|
|
13
|
-
const HEX_COLOR = /^#(?:[0-9a-f]{3}|[0-9a-f]{4}|[0-9a-f]{6}|[0-9a-f]{8})$/i;
|
|
14
34
|
export const ColorValue = z.union([
|
|
15
35
|
z.string().regex(HEX_COLOR, "Use a hex color such as #1a2b3c"),
|
|
16
36
|
VariableRef,
|
|
17
37
|
]);
|
|
18
38
|
|
|
19
|
-
|
|
39
|
+
/** `ch` since W-331: the width of a "0", for readable line lengths such as 65ch. */
|
|
40
|
+
const LengthUnit = z.enum(LENGTH_UNITS);
|
|
20
41
|
|
|
21
42
|
export const Length = z.strictObject({
|
|
22
43
|
value: z.number().finite().min(0).max(10_000),
|
|
@@ -29,7 +50,10 @@ export const LengthValue = z.union([Length, VariableRef]);
|
|
|
29
50
|
/** Width, height and margins may also be `auto` (W-088). */
|
|
30
51
|
const SizeValue = z.union([Length, VariableRef, z.literal("auto")]);
|
|
31
52
|
|
|
32
|
-
/**
|
|
53
|
+
/**
|
|
54
|
+
* Top, right, bottom and left may be negative, `auto` or a spacing variable (W-088); so may
|
|
55
|
+
* margins since W-331, to pull an element over its neighbour.
|
|
56
|
+
*/
|
|
33
57
|
const OffsetValue = z.union([
|
|
34
58
|
z.strictObject({ value: z.number().finite().min(-10_000).max(10_000), unit: LengthUnit }),
|
|
35
59
|
VariableRef,
|
|
@@ -73,43 +97,45 @@ const Filter = z
|
|
|
73
97
|
const Transition = z.strictObject({
|
|
74
98
|
duration: z.number().int().min(0).max(2000),
|
|
75
99
|
delay: z.number().int().min(0).max(2000).optional(),
|
|
76
|
-
easing: z.enum(
|
|
77
|
-
property: z.enum(
|
|
100
|
+
easing: z.enum(TRANSITION_EASINGS),
|
|
101
|
+
property: z.enum(TRANSITION_PROPERTIES),
|
|
78
102
|
});
|
|
79
103
|
|
|
80
104
|
/** Style properties for layout and text elements (W-017 / R-012). Unknown keys are rejected. */
|
|
81
105
|
export const StyleProps = z.strictObject({
|
|
82
|
-
flexDirection: z.enum(
|
|
83
|
-
flexWrap: z.enum(
|
|
84
|
-
justifyContent: z
|
|
85
|
-
|
|
86
|
-
.optional(),
|
|
87
|
-
alignItems: z.enum(["stretch", "flex-start", "flex-end", "center", "baseline"]).optional(),
|
|
106
|
+
flexDirection: z.enum(FLEX_DIRECTIONS).optional(),
|
|
107
|
+
flexWrap: z.enum(FLEX_WRAPS).optional(),
|
|
108
|
+
justifyContent: z.enum(JUSTIFY_CONTENT).optional(),
|
|
109
|
+
alignItems: z.enum(ALIGN_ITEMS).optional(),
|
|
88
110
|
gap: LengthValue.optional(),
|
|
89
111
|
/** How many grid columns this element spans (1–12). */
|
|
90
112
|
gridColumnSpan: z.number().int().min(1).max(12).optional(),
|
|
91
113
|
/** How many grid rows this element spans (1–12). */
|
|
92
114
|
gridRowSpan: z.number().int().min(1).max(12).optional(),
|
|
115
|
+
/** First column line (1–13). With a span, emits `start / span n`. */
|
|
116
|
+
gridColumnStart: z.number().int().min(1).max(13).optional(),
|
|
117
|
+
/** First row line (1–13). With a span, emits `start / span n`. */
|
|
118
|
+
gridRowStart: z.number().int().min(1).max(13).optional(),
|
|
93
119
|
width: SizeValue.optional(),
|
|
94
120
|
minWidth: LengthValue.optional(),
|
|
95
121
|
maxWidth: LengthValue.optional(),
|
|
96
122
|
height: SizeValue.optional(),
|
|
97
123
|
minHeight: LengthValue.optional(),
|
|
98
124
|
maxHeight: LengthValue.optional(),
|
|
99
|
-
overflow: z.enum(
|
|
125
|
+
overflow: z.enum(OVERFLOWS).optional(),
|
|
100
126
|
aspectRatio: z
|
|
101
127
|
.union([z.literal("auto"), z.string().regex(ASPECT_RATIO, "Use a ratio such as 16/9")])
|
|
102
128
|
.optional(),
|
|
103
|
-
objectFit: z.enum(
|
|
129
|
+
objectFit: z.enum(OBJECT_FITS).optional(),
|
|
104
130
|
paddingTop: LengthValue.optional(),
|
|
105
131
|
paddingRight: LengthValue.optional(),
|
|
106
132
|
paddingBottom: LengthValue.optional(),
|
|
107
133
|
paddingLeft: LengthValue.optional(),
|
|
108
|
-
marginTop:
|
|
109
|
-
marginRight:
|
|
110
|
-
marginBottom:
|
|
111
|
-
marginLeft:
|
|
112
|
-
position: z.enum(
|
|
134
|
+
marginTop: OffsetValue.optional(),
|
|
135
|
+
marginRight: OffsetValue.optional(),
|
|
136
|
+
marginBottom: OffsetValue.optional(),
|
|
137
|
+
marginLeft: OffsetValue.optional(),
|
|
138
|
+
position: z.enum(POSITIONS).optional(),
|
|
113
139
|
top: OffsetValue.optional(),
|
|
114
140
|
right: OffsetValue.optional(),
|
|
115
141
|
bottom: OffsetValue.optional(),
|
|
@@ -146,10 +172,10 @@ export const StyleProps = z.strictObject({
|
|
|
146
172
|
VariableRef,
|
|
147
173
|
])
|
|
148
174
|
.optional(),
|
|
149
|
-
textAlign: z.enum(
|
|
150
|
-
textTransform: z.enum(
|
|
175
|
+
textAlign: z.enum(TEXT_ALIGNS).optional(),
|
|
176
|
+
textTransform: z.enum(TEXT_TRANSFORMS).optional(),
|
|
151
177
|
/** W-113. A button sets `none` in its base CSS, so it is not underlined unless a style says so. */
|
|
152
|
-
textDecoration: z.enum(
|
|
178
|
+
textDecoration: z.enum(TEXT_DECORATIONS).optional(),
|
|
153
179
|
color: ColorValue.optional(),
|
|
154
180
|
backgroundColor: ColorValue.optional(),
|
|
155
181
|
/** http(s) or a site path. Spaces, quotes and parentheses are refused so the URL can sit inside `url("")`. */
|
|
@@ -162,21 +188,9 @@ export const StyleProps = z.strictObject({
|
|
|
162
188
|
"Use an http(s) URL or a site path, with no spaces or parentheses",
|
|
163
189
|
)
|
|
164
190
|
.optional(),
|
|
165
|
-
backgroundSize: z.enum(
|
|
166
|
-
backgroundPosition: z
|
|
167
|
-
|
|
168
|
-
"center",
|
|
169
|
-
"top",
|
|
170
|
-
"bottom",
|
|
171
|
-
"left",
|
|
172
|
-
"right",
|
|
173
|
-
"top left",
|
|
174
|
-
"top right",
|
|
175
|
-
"bottom left",
|
|
176
|
-
"bottom right",
|
|
177
|
-
])
|
|
178
|
-
.optional(),
|
|
179
|
-
backgroundRepeat: z.enum(["no-repeat", "repeat", "repeat-x", "repeat-y"]).optional(),
|
|
191
|
+
backgroundSize: z.enum(BACKGROUND_SIZES).optional(),
|
|
192
|
+
backgroundPosition: z.enum(BACKGROUND_POSITIONS).optional(),
|
|
193
|
+
backgroundRepeat: z.enum(BACKGROUND_REPEATS).optional(),
|
|
180
194
|
/** Video behind the element. Same URL rules as a background image (W-110). */
|
|
181
195
|
backgroundVideo: z
|
|
182
196
|
.string()
|
|
@@ -195,19 +209,7 @@ export const StyleProps = z.strictObject({
|
|
|
195
209
|
.strictObject({
|
|
196
210
|
type: z.enum(["linear", "radial", "conic"]),
|
|
197
211
|
angle: z.number().int().min(0).max(360).optional(),
|
|
198
|
-
position: z
|
|
199
|
-
.enum([
|
|
200
|
-
"center",
|
|
201
|
-
"top",
|
|
202
|
-
"bottom",
|
|
203
|
-
"left",
|
|
204
|
-
"right",
|
|
205
|
-
"top left",
|
|
206
|
-
"top right",
|
|
207
|
-
"bottom left",
|
|
208
|
-
"bottom right",
|
|
209
|
-
])
|
|
210
|
-
.optional(),
|
|
212
|
+
position: z.enum(BACKGROUND_POSITIONS).optional(),
|
|
211
213
|
stops: z
|
|
212
214
|
.array(
|
|
213
215
|
z.strictObject({
|
|
@@ -232,7 +234,7 @@ export const StyleProps = z.strictObject({
|
|
|
232
234
|
borderRightWidth: LengthValue.optional(),
|
|
233
235
|
borderBottomWidth: LengthValue.optional(),
|
|
234
236
|
borderLeftWidth: LengthValue.optional(),
|
|
235
|
-
borderStyle: z.enum(
|
|
237
|
+
borderStyle: z.enum(BORDER_STYLES).optional(),
|
|
236
238
|
borderColor: ColorValue.optional(),
|
|
237
239
|
borderRadius: LengthValue.optional(),
|
|
238
240
|
/** Per-corner radii (W-138, D-044), after `borderRadius`. */
|
|
@@ -243,19 +245,7 @@ export const StyleProps = z.strictObject({
|
|
|
243
245
|
opacity: z.number().finite().min(0).max(1).optional(),
|
|
244
246
|
boxShadow: BoxShadow.optional(),
|
|
245
247
|
filter: Filter.optional(),
|
|
246
|
-
cursor: z
|
|
247
|
-
.enum([
|
|
248
|
-
"default",
|
|
249
|
-
"pointer",
|
|
250
|
-
"text",
|
|
251
|
-
"move",
|
|
252
|
-
"grab",
|
|
253
|
-
"not-allowed",
|
|
254
|
-
"help",
|
|
255
|
-
"crosshair",
|
|
256
|
-
"zoom-in",
|
|
257
|
-
])
|
|
258
|
-
.optional(),
|
|
248
|
+
cursor: z.enum(CURSORS).optional(),
|
|
259
249
|
transition: Transition.optional(),
|
|
260
250
|
/**
|
|
261
251
|
* Icon element glyph styling (W-237). Emitted as custom properties on the icon's wrapper, so
|
package/src/core/share/link.ts
CHANGED
|
@@ -40,38 +40,78 @@ function fromBase64Url(text: string): Uint8Array {
|
|
|
40
40
|
return bytes;
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
|
|
43
|
+
type ByteWriter = {
|
|
44
|
+
write(chunk?: BufferSource): Promise<void>;
|
|
45
|
+
close(): Promise<void>;
|
|
46
|
+
};
|
|
47
|
+
type ByteReader = {
|
|
48
|
+
read(): Promise<ReadableStreamReadResult<Uint8Array>>;
|
|
49
|
+
cancel(): Promise<void>;
|
|
50
|
+
};
|
|
51
|
+
type BytePipe = {
|
|
52
|
+
readable: { getReader(): ByteReader };
|
|
53
|
+
writable: { getWriter(): ByteWriter };
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Copies bytes through a compression stream. Reading runs alongside the write, and a writer
|
|
58
|
+
* failure rejects even when the reader would wait forever.
|
|
59
|
+
*/
|
|
60
|
+
export async function pipeBytes(
|
|
44
61
|
bytes: Uint8Array,
|
|
45
|
-
stream:
|
|
62
|
+
stream: BytePipe,
|
|
46
63
|
max: number,
|
|
47
|
-
) {
|
|
64
|
+
): Promise<Uint8Array> {
|
|
48
65
|
const writer = stream.writable.getWriter();
|
|
49
|
-
void writer
|
|
50
|
-
.write(bytes as Uint8Array<ArrayBuffer>)
|
|
51
|
-
.then(() => writer.close())
|
|
52
|
-
.catch(() => {});
|
|
53
66
|
const reader = stream.readable.getReader();
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
67
|
+
let writerError: unknown;
|
|
68
|
+
const writerFailed = new Promise<unknown>((resolve) => {
|
|
69
|
+
writer
|
|
70
|
+
.write(bytes as Uint8Array<ArrayBuffer>)
|
|
71
|
+
.then(() => writer.close())
|
|
72
|
+
.then(
|
|
73
|
+
() => undefined,
|
|
74
|
+
(error: unknown) => {
|
|
75
|
+
writerError = error;
|
|
76
|
+
resolve(error);
|
|
77
|
+
},
|
|
78
|
+
);
|
|
79
|
+
});
|
|
80
|
+
try {
|
|
81
|
+
const parts: Uint8Array[] = [];
|
|
82
|
+
let size = 0;
|
|
83
|
+
for (;;) {
|
|
84
|
+
// Read in order; stop early so a tiny link can't unpack into something huge.
|
|
85
|
+
// oxlint-disable-next-line no-await-in-loop
|
|
86
|
+
const next = await Promise.race([
|
|
87
|
+
reader.read().then(
|
|
88
|
+
(chunk) => ({ kind: "chunk" as const, chunk }),
|
|
89
|
+
(error: unknown) => ({ kind: "failed" as const, error }),
|
|
90
|
+
),
|
|
91
|
+
writerFailed.then((error) => ({ kind: "failed" as const, error })),
|
|
92
|
+
]);
|
|
93
|
+
if (next.kind === "failed") throw next.error;
|
|
94
|
+
const { done, value } = next.chunk;
|
|
95
|
+
if (done) break;
|
|
96
|
+
size += value.byteLength;
|
|
97
|
+
if (size > max) {
|
|
98
|
+
void reader.cancel().catch(() => {});
|
|
99
|
+
throw new Error("too big");
|
|
100
|
+
}
|
|
101
|
+
parts.push(value);
|
|
65
102
|
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
103
|
+
if (writerError !== undefined) throw writerError;
|
|
104
|
+
const out = new Uint8Array(size);
|
|
105
|
+
let at = 0;
|
|
106
|
+
for (const part of parts) {
|
|
107
|
+
out.set(part, at);
|
|
108
|
+
at += part.byteLength;
|
|
109
|
+
}
|
|
110
|
+
return out;
|
|
111
|
+
} catch (error) {
|
|
112
|
+
void reader.cancel().catch(() => {});
|
|
113
|
+
throw error;
|
|
73
114
|
}
|
|
74
|
-
return out;
|
|
75
115
|
}
|
|
76
116
|
|
|
77
117
|
/**
|
|
@@ -84,7 +124,7 @@ export async function encodeSharedPage(page: SharedPage): Promise<string> {
|
|
|
84
124
|
l: page.layout,
|
|
85
125
|
...(page.design ? { d: page.design } : {}),
|
|
86
126
|
});
|
|
87
|
-
const packed = await
|
|
127
|
+
const packed = await pipeBytes(
|
|
88
128
|
new TextEncoder().encode(json),
|
|
89
129
|
new CompressionStream("deflate-raw"),
|
|
90
130
|
Number.MAX_SAFE_INTEGER,
|
|
@@ -111,13 +151,16 @@ export async function decodeSharedPage(encoded: string): Promise<ShareRead> {
|
|
|
111
151
|
const text = encoded.trim();
|
|
112
152
|
if (!text) return { ok: false, reason: "empty" };
|
|
113
153
|
if (text.length > MAX_LINK_CHARS) return { ok: false, reason: "too-long" };
|
|
114
|
-
const [version,
|
|
154
|
+
const [version, raw] = text.split(".", 2);
|
|
155
|
+
// W-437: mail clients wrap long links and chat apps take a closing ")" or "." into them; none
|
|
156
|
+
// of those characters is base64url, so line breaks inside and trailing punctuation are dropped.
|
|
157
|
+
const body = raw?.replace(/\s+/g, "").replace(/[^A-Za-z0-9_-]+$/, "");
|
|
115
158
|
if (version !== VERSION || !body || !/^[A-Za-z0-9_-]+$/.test(body)) {
|
|
116
159
|
return { ok: false, reason: "unreadable" };
|
|
117
160
|
}
|
|
118
161
|
let parsed: unknown;
|
|
119
162
|
try {
|
|
120
|
-
const bytes = await
|
|
163
|
+
const bytes = await pipeBytes(
|
|
121
164
|
fromBase64Url(body),
|
|
122
165
|
new DecompressionStream("deflate-raw"),
|
|
123
166
|
MAX_UNPACKED_BYTES,
|
|
@@ -1,25 +1,15 @@
|
|
|
1
|
-
import { isTabsNode, type Layout
|
|
2
|
-
import { nodeChildren } from "../tree-ops.ts";
|
|
3
|
-
|
|
4
|
-
function walk(node: LayoutNode, visit: (node: LayoutNode) => void): void {
|
|
5
|
-
visit(node);
|
|
6
|
-
for (const child of nodeChildren(node)) walk(child, visit);
|
|
7
|
-
}
|
|
1
|
+
import { isTabsNode, type Layout } from "../schema/layout.ts";
|
|
2
|
+
import { nodeChildren, someNode } from "../tree-ops.ts";
|
|
8
3
|
|
|
9
4
|
/** True when the layout includes at least one Tabs element (optional public runtime). */
|
|
10
5
|
export function layoutHasTabs(layout: Layout): boolean {
|
|
11
|
-
|
|
12
|
-
walk(layout.root, (node) => {
|
|
13
|
-
if (isTabsNode(node)) found = true;
|
|
14
|
-
});
|
|
15
|
-
return found;
|
|
6
|
+
return someNode(layout.root, (node) => isTabsNode(node));
|
|
16
7
|
}
|
|
17
8
|
|
|
18
9
|
/** A Menu with a dropdown, so hosts load the Escape-to-close menu script (W-197). */
|
|
19
10
|
export function layoutHasMenuDropdown(layout: Layout): boolean {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
return found;
|
|
11
|
+
return someNode(
|
|
12
|
+
layout.root,
|
|
13
|
+
(node) => node.type === "menu-item" && nodeChildren(node).length > 0,
|
|
14
|
+
);
|
|
25
15
|
}
|