@perkyzz/emvb 0.2.1 → 0.4.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 +4 -2
- package/THIRD_PARTY_NOTICES.md +1 -1
- package/package.json +3 -1
- package/src/admin/access/role.ts +9 -3
- 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 +126 -0
- package/src/admin/editor/CommandPalette.tsx +118 -0
- package/src/admin/editor/Editor.tsx +188 -152
- package/src/admin/editor/EditorOverlay.tsx +9 -1
- package/src/admin/editor/PerfMeter.tsx +121 -0
- package/src/admin/editor/ShareLink.tsx +164 -0
- package/src/admin/editor/ShortcutsDialog.tsx +4 -1
- package/src/admin/editor/Timeline.tsx +287 -0
- package/src/admin/editor/TopBar.tsx +4 -0
- package/src/admin/editor/canvas/CanvasFrame.tsx +62 -370
- package/src/admin/editor/canvas/DeviceBar.tsx +4 -1
- package/src/admin/editor/canvas/SelectionOverlay.tsx +87 -47
- 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 +114 -0
- 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 +5 -3
- package/src/admin/editor/element-chrome.ts +89 -0
- package/src/admin/editor/feature-css.ts +105 -0
- package/src/admin/editor/host.ts +35 -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/live-data.tsx +71 -0
- package/src/admin/editor/palette-items.ts +136 -0
- package/src/admin/editor/palette.ts +68 -0
- package/src/admin/editor/panels/AddPanel.tsx +48 -68
- package/src/admin/editor/panels/ClassesSection.tsx +5 -1
- package/src/admin/editor/panels/ColorControl.tsx +2 -10
- package/src/admin/editor/panels/ElementPanel.tsx +74 -102
- package/src/admin/editor/panels/LayersPanel.tsx +72 -63
- package/src/admin/editor/panels/LeftPanel.tsx +4 -1
- package/src/admin/editor/panels/SettingsPanel.tsx +13 -0
- package/src/admin/editor/panels/SiteStylesDrawer.tsx +18 -10
- package/src/admin/editor/panels/TokenScales.tsx +168 -0
- package/src/admin/editor/panels/VariableSection.tsx +10 -14
- package/src/admin/editor/panels/inline-error.tsx +11 -0
- package/src/admin/editor/panels/settings/AdvancedFields.tsx +87 -1
- package/src/admin/editor/panels/settings/AudienceEditor.tsx +285 -0
- package/src/admin/editor/panels/settings/BindingsEditor.tsx +221 -0
- package/src/admin/editor/panels/settings/ClassChipInput.tsx +1 -1
- package/src/admin/editor/panels/settings/DraftTextField.tsx +4 -0
- package/src/admin/editor/panels/settings/EffectsControls.tsx +2 -2
- package/src/admin/editor/panels/settings/FormBindControl.tsx +8 -4
- package/src/admin/editor/panels/settings/ItemList.tsx +34 -1
- package/src/admin/editor/panels/settings/MotionControl.tsx +252 -0
- package/src/admin/editor/panels/settings/StateSwitcher.tsx +1 -1
- package/src/admin/editor/panels/settings/StyleRow.tsx +26 -2
- package/src/admin/editor/panels/settings/StyleSources.tsx +94 -0
- package/src/admin/editor/panels/settings/VariableBinding.tsx +1 -1
- package/src/admin/editor/panels/settings/VariantEditor.tsx +83 -0
- package/src/admin/editor/panels/settings/form-names.ts +7 -11
- package/src/admin/editor/panels/settings/length-units.ts +16 -5
- package/src/admin/editor/panels/settings/style-sections.ts +7 -2
- package/src/admin/editor/panels/style-target.ts +105 -0
- package/src/admin/editor/section-templates.ts +43 -21
- package/src/admin/editor/shortcuts.ts +6 -1
- 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 +30 -14
- package/src/admin/editor/useNodeActions.ts +44 -16
- package/src/admin/forms-api.ts +17 -6
- package/src/admin/icon-uploads-api.ts +18 -0
- package/src/admin/theme-api.ts +5 -18
- package/src/admin/ui.ts +4 -4
- package/src/astro/content-port.ts +24 -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/render-session.ts +85 -0
- package/src/astro/request-data.ts +109 -0
- package/src/astro/resolve-theme.ts +184 -64
- package/src/astro/resolve.ts +63 -16
- package/src/astro/theme-posts.ts +48 -5
- package/src/astro/visitor.ts +204 -0
- package/src/constants.ts +1 -1
- package/src/core/a11y/audit.ts +282 -0
- package/src/core/arrange.ts +150 -34
- package/src/core/audience/rules.ts +124 -0
- package/src/core/audience/variants.ts +51 -0
- package/src/core/canvas-styles.ts +24 -0
- package/src/core/clipboard.ts +11 -32
- package/src/core/css/generate.ts +29 -2
- package/src/core/css/print.ts +12 -0
- package/src/core/css/scope.ts +3 -3
- package/src/core/css/trace.ts +169 -0
- package/src/core/css-keywords.ts +83 -0
- package/src/core/data/bindings.ts +255 -0
- 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/tokens.ts +127 -0
- package/src/core/design/variables.ts +25 -21
- package/src/core/elements/dynamic-elements.ts +117 -2
- package/src/core/elements/form-elements.ts +1 -0
- package/src/core/elements/index.ts +185 -7
- package/src/core/forms/binding.ts +4 -13
- package/src/core/history/diff.ts +152 -0
- package/src/core/index.ts +121 -0
- package/src/core/local-style.ts +27 -0
- package/src/core/migrate/index.ts +12 -4
- package/src/core/nesting.ts +4 -22
- package/src/core/perf/meter.ts +160 -0
- package/src/core/perf/scripts.ts +61 -0
- package/src/core/recipes/index.ts +433 -0
- package/src/core/record.ts +3 -0
- package/src/core/render/context.ts +2 -0
- package/src/core/render/dynamic-post.ts +1 -2
- package/src/core/render/form.ts +133 -10
- package/src/core/render/index.ts +206 -17
- package/src/core/render/loop.ts +54 -7
- package/src/core/render/pagination.ts +9 -1
- package/src/core/render/vnode.ts +12 -2
- package/src/core/sanitize/css.ts +129 -80
- package/src/core/sanitize/motion.ts +129 -0
- package/src/core/sanitize/svg.ts +8 -3
- package/src/core/sanitize/url.ts +10 -1
- package/src/core/schema/design.ts +29 -8
- package/src/core/schema/layout.ts +291 -169
- package/src/core/schema/motion.ts +14 -0
- package/src/core/schema/style.ts +101 -66
- package/src/core/share/link.ts +187 -0
- package/src/core/tabs/presence.ts +7 -17
- package/src/core/theme/dynamic.ts +242 -32
- package/src/core/theme/float.ts +1 -1
- package/src/core/theme/pagination.ts +56 -0
- package/src/core/tree-ops.ts +57 -0
- package/src/index.ts +14 -2
- package/src/server/design-routes.ts +4 -1
- package/src/server/icon-routes.ts +68 -16
- package/src/server/plugin.ts +8 -2
- 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
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** Scroll motion effects (W-319). */
|
|
2
|
+
export const MOTION_EFFECTS = ["fade", "move-x", "move-y", "scale", "rotate", "blur"] as const;
|
|
3
|
+
export type MotionEffect = (typeof MOTION_EFFECTS)[number];
|
|
4
|
+
/**
|
|
5
|
+
* Allowed `from`/`to` per effect: opacity %, px offsets, scale %, degrees, blur px (W-319).
|
|
6
|
+
*/
|
|
7
|
+
export const MOTION_LIMITS: Record<MotionEffect, readonly [number, number]> = {
|
|
8
|
+
fade: [0, 100],
|
|
9
|
+
"move-x": [-1000, 1000],
|
|
10
|
+
"move-y": [-1000, 1000],
|
|
11
|
+
scale: [0, 400],
|
|
12
|
+
rotate: [-720, 720],
|
|
13
|
+
blur: [0, 50],
|
|
14
|
+
};
|
package/src/core/schema/style.ts
CHANGED
|
@@ -1,7 +1,29 @@
|
|
|
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";
|
|
26
|
+
import { MOTION_EFFECTS, MOTION_LIMITS } from "./motion.ts";
|
|
5
27
|
|
|
6
28
|
/** Colour refs omit `from` (legacy). Length/font refs set `from` (W-028). */
|
|
7
29
|
export const VariableRef = z.strictObject({
|
|
@@ -9,13 +31,13 @@ export const VariableRef = z.strictObject({
|
|
|
9
31
|
from: z.enum(["color", "font", "fontSize", "spacing"]).optional(),
|
|
10
32
|
});
|
|
11
33
|
|
|
12
|
-
const HEX_COLOR = /^#(?:[0-9a-f]{3}|[0-9a-f]{4}|[0-9a-f]{6}|[0-9a-f]{8})$/i;
|
|
13
34
|
export const ColorValue = z.union([
|
|
14
35
|
z.string().regex(HEX_COLOR, "Use a hex color such as #1a2b3c"),
|
|
15
36
|
VariableRef,
|
|
16
37
|
]);
|
|
17
38
|
|
|
18
|
-
|
|
39
|
+
/** `ch` since W-331: the width of a "0", for readable line lengths such as 65ch. */
|
|
40
|
+
const LengthUnit = z.enum(LENGTH_UNITS);
|
|
19
41
|
|
|
20
42
|
export const Length = z.strictObject({
|
|
21
43
|
value: z.number().finite().min(0).max(10_000),
|
|
@@ -28,7 +50,10 @@ export const LengthValue = z.union([Length, VariableRef]);
|
|
|
28
50
|
/** Width, height and margins may also be `auto` (W-088). */
|
|
29
51
|
const SizeValue = z.union([Length, VariableRef, z.literal("auto")]);
|
|
30
52
|
|
|
31
|
-
/**
|
|
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
|
+
*/
|
|
32
57
|
const OffsetValue = z.union([
|
|
33
58
|
z.strictObject({ value: z.number().finite().min(-10_000).max(10_000), unit: LengthUnit }),
|
|
34
59
|
VariableRef,
|
|
@@ -72,43 +97,45 @@ const Filter = z
|
|
|
72
97
|
const Transition = z.strictObject({
|
|
73
98
|
duration: z.number().int().min(0).max(2000),
|
|
74
99
|
delay: z.number().int().min(0).max(2000).optional(),
|
|
75
|
-
easing: z.enum(
|
|
76
|
-
property: z.enum(
|
|
100
|
+
easing: z.enum(TRANSITION_EASINGS),
|
|
101
|
+
property: z.enum(TRANSITION_PROPERTIES),
|
|
77
102
|
});
|
|
78
103
|
|
|
79
104
|
/** Style properties for layout and text elements (W-017 / R-012). Unknown keys are rejected. */
|
|
80
105
|
export const StyleProps = z.strictObject({
|
|
81
|
-
flexDirection: z.enum(
|
|
82
|
-
flexWrap: z.enum(
|
|
83
|
-
justifyContent: z
|
|
84
|
-
|
|
85
|
-
.optional(),
|
|
86
|
-
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(),
|
|
87
110
|
gap: LengthValue.optional(),
|
|
88
111
|
/** How many grid columns this element spans (1–12). */
|
|
89
112
|
gridColumnSpan: z.number().int().min(1).max(12).optional(),
|
|
90
113
|
/** How many grid rows this element spans (1–12). */
|
|
91
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(),
|
|
92
119
|
width: SizeValue.optional(),
|
|
93
120
|
minWidth: LengthValue.optional(),
|
|
94
121
|
maxWidth: LengthValue.optional(),
|
|
95
122
|
height: SizeValue.optional(),
|
|
96
123
|
minHeight: LengthValue.optional(),
|
|
97
124
|
maxHeight: LengthValue.optional(),
|
|
98
|
-
overflow: z.enum(
|
|
125
|
+
overflow: z.enum(OVERFLOWS).optional(),
|
|
99
126
|
aspectRatio: z
|
|
100
127
|
.union([z.literal("auto"), z.string().regex(ASPECT_RATIO, "Use a ratio such as 16/9")])
|
|
101
128
|
.optional(),
|
|
102
|
-
objectFit: z.enum(
|
|
129
|
+
objectFit: z.enum(OBJECT_FITS).optional(),
|
|
103
130
|
paddingTop: LengthValue.optional(),
|
|
104
131
|
paddingRight: LengthValue.optional(),
|
|
105
132
|
paddingBottom: LengthValue.optional(),
|
|
106
133
|
paddingLeft: LengthValue.optional(),
|
|
107
|
-
marginTop:
|
|
108
|
-
marginRight:
|
|
109
|
-
marginBottom:
|
|
110
|
-
marginLeft:
|
|
111
|
-
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(),
|
|
112
139
|
top: OffsetValue.optional(),
|
|
113
140
|
right: OffsetValue.optional(),
|
|
114
141
|
bottom: OffsetValue.optional(),
|
|
@@ -145,10 +172,10 @@ export const StyleProps = z.strictObject({
|
|
|
145
172
|
VariableRef,
|
|
146
173
|
])
|
|
147
174
|
.optional(),
|
|
148
|
-
textAlign: z.enum(
|
|
149
|
-
textTransform: z.enum(
|
|
175
|
+
textAlign: z.enum(TEXT_ALIGNS).optional(),
|
|
176
|
+
textTransform: z.enum(TEXT_TRANSFORMS).optional(),
|
|
150
177
|
/** W-113. A button sets `none` in its base CSS, so it is not underlined unless a style says so. */
|
|
151
|
-
textDecoration: z.enum(
|
|
178
|
+
textDecoration: z.enum(TEXT_DECORATIONS).optional(),
|
|
152
179
|
color: ColorValue.optional(),
|
|
153
180
|
backgroundColor: ColorValue.optional(),
|
|
154
181
|
/** http(s) or a site path. Spaces, quotes and parentheses are refused so the URL can sit inside `url("")`. */
|
|
@@ -161,21 +188,9 @@ export const StyleProps = z.strictObject({
|
|
|
161
188
|
"Use an http(s) URL or a site path, with no spaces or parentheses",
|
|
162
189
|
)
|
|
163
190
|
.optional(),
|
|
164
|
-
backgroundSize: z.enum(
|
|
165
|
-
backgroundPosition: z
|
|
166
|
-
|
|
167
|
-
"center",
|
|
168
|
-
"top",
|
|
169
|
-
"bottom",
|
|
170
|
-
"left",
|
|
171
|
-
"right",
|
|
172
|
-
"top left",
|
|
173
|
-
"top right",
|
|
174
|
-
"bottom left",
|
|
175
|
-
"bottom right",
|
|
176
|
-
])
|
|
177
|
-
.optional(),
|
|
178
|
-
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(),
|
|
179
194
|
/** Video behind the element. Same URL rules as a background image (W-110). */
|
|
180
195
|
backgroundVideo: z
|
|
181
196
|
.string()
|
|
@@ -194,19 +209,7 @@ export const StyleProps = z.strictObject({
|
|
|
194
209
|
.strictObject({
|
|
195
210
|
type: z.enum(["linear", "radial", "conic"]),
|
|
196
211
|
angle: z.number().int().min(0).max(360).optional(),
|
|
197
|
-
position: z
|
|
198
|
-
.enum([
|
|
199
|
-
"center",
|
|
200
|
-
"top",
|
|
201
|
-
"bottom",
|
|
202
|
-
"left",
|
|
203
|
-
"right",
|
|
204
|
-
"top left",
|
|
205
|
-
"top right",
|
|
206
|
-
"bottom left",
|
|
207
|
-
"bottom right",
|
|
208
|
-
])
|
|
209
|
-
.optional(),
|
|
212
|
+
position: z.enum(BACKGROUND_POSITIONS).optional(),
|
|
210
213
|
stops: z
|
|
211
214
|
.array(
|
|
212
215
|
z.strictObject({
|
|
@@ -231,7 +234,7 @@ export const StyleProps = z.strictObject({
|
|
|
231
234
|
borderRightWidth: LengthValue.optional(),
|
|
232
235
|
borderBottomWidth: LengthValue.optional(),
|
|
233
236
|
borderLeftWidth: LengthValue.optional(),
|
|
234
|
-
borderStyle: z.enum(
|
|
237
|
+
borderStyle: z.enum(BORDER_STYLES).optional(),
|
|
235
238
|
borderColor: ColorValue.optional(),
|
|
236
239
|
borderRadius: LengthValue.optional(),
|
|
237
240
|
/** Per-corner radii (W-138, D-044), after `borderRadius`. */
|
|
@@ -242,19 +245,7 @@ export const StyleProps = z.strictObject({
|
|
|
242
245
|
opacity: z.number().finite().min(0).max(1).optional(),
|
|
243
246
|
boxShadow: BoxShadow.optional(),
|
|
244
247
|
filter: Filter.optional(),
|
|
245
|
-
cursor: z
|
|
246
|
-
.enum([
|
|
247
|
-
"default",
|
|
248
|
-
"pointer",
|
|
249
|
-
"text",
|
|
250
|
-
"move",
|
|
251
|
-
"grab",
|
|
252
|
-
"not-allowed",
|
|
253
|
-
"help",
|
|
254
|
-
"crosshair",
|
|
255
|
-
"zoom-in",
|
|
256
|
-
])
|
|
257
|
-
.optional(),
|
|
248
|
+
cursor: z.enum(CURSORS).optional(),
|
|
258
249
|
transition: Transition.optional(),
|
|
259
250
|
/**
|
|
260
251
|
* Icon element glyph styling (W-237). Emitted as custom properties on the icon's wrapper, so
|
|
@@ -287,6 +278,45 @@ export const StyleProps = z.strictObject({
|
|
|
287
278
|
z.strictObject({ type: z.literal("none") }),
|
|
288
279
|
])
|
|
289
280
|
.optional(),
|
|
281
|
+
/**
|
|
282
|
+
* Scroll motion (W-319): effects tied to the element's trip through the screen (or the page's
|
|
283
|
+
* scroll), with CSS scroll-driven animations. Browsers without them, and visitors who prefer
|
|
284
|
+
* reduced motion, see the element still. `{ type: "none" }` stops motion a wider device sets.
|
|
285
|
+
*/
|
|
286
|
+
scrollMotion: z
|
|
287
|
+
.union([
|
|
288
|
+
z.strictObject({
|
|
289
|
+
effects: z
|
|
290
|
+
.array(
|
|
291
|
+
z.strictObject({
|
|
292
|
+
type: z.enum(MOTION_EFFECTS),
|
|
293
|
+
from: z.number().min(-1000).max(1000),
|
|
294
|
+
to: z.number().min(-1000).max(1000),
|
|
295
|
+
}),
|
|
296
|
+
)
|
|
297
|
+
.min(1)
|
|
298
|
+
.max(MOTION_EFFECTS.length)
|
|
299
|
+
.superRefine((effects, ctx) => {
|
|
300
|
+
const seen = new Set<string>();
|
|
301
|
+
for (const effect of effects) {
|
|
302
|
+
const [min, max] = MOTION_LIMITS[effect.type];
|
|
303
|
+
if ([effect.from, effect.to].some((n) => n < min || n > max)) {
|
|
304
|
+
ctx.addIssue({
|
|
305
|
+
code: "custom",
|
|
306
|
+
message: `${effect.type} goes from ${min} to ${max}`,
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
if (seen.has(effect.type)) {
|
|
310
|
+
ctx.addIssue({ code: "custom", message: `${effect.type} is set twice` });
|
|
311
|
+
}
|
|
312
|
+
seen.add(effect.type);
|
|
313
|
+
}
|
|
314
|
+
}),
|
|
315
|
+
range: z.enum(["enter", "cross", "exit", "page"]),
|
|
316
|
+
}),
|
|
317
|
+
z.strictObject({ type: z.literal("none") }),
|
|
318
|
+
])
|
|
319
|
+
.optional(),
|
|
290
320
|
/**
|
|
291
321
|
* Plays once (W-101, W-107). `delay` waits before it starts. `view` starts as the element
|
|
292
322
|
* scrolls into view, using CSS scroll-driven animations, and falls back to playing on load.
|
|
@@ -306,10 +336,15 @@ export type StyleProps = z.infer<typeof StyleProps>;
|
|
|
306
336
|
|
|
307
337
|
/**
|
|
308
338
|
* `states` on a node or class (D-032, W-089): hover, focus (`:focus-visible`) and active, each with
|
|
309
|
-
* the same keys and limits as `style` except `transition`, `entrance
|
|
310
|
-
* states are refused.
|
|
339
|
+
* the same keys and limits as `style` except `transition`, `entrance`, `iconAnimation` and
|
|
340
|
+
* `scrollMotion`. Unknown states are refused.
|
|
311
341
|
*/
|
|
312
|
-
const StateStyle = StyleProps.omit({
|
|
342
|
+
const StateStyle = StyleProps.omit({
|
|
343
|
+
transition: true,
|
|
344
|
+
entrance: true,
|
|
345
|
+
iconAnimation: true,
|
|
346
|
+
scrollMotion: true,
|
|
347
|
+
});
|
|
313
348
|
|
|
314
349
|
export const StyleStates = z.strictObject({
|
|
315
350
|
hover: StateStyle.optional(),
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
import { MAX_DESIGN_BYTES, MAX_LAYOUT_BYTES } from "../limits.ts";
|
|
2
|
+
import type { DesignSystem } from "../schema/design.ts";
|
|
3
|
+
import type { Layout } from "../schema/layout.ts";
|
|
4
|
+
import { validateDesign, validateLayout } from "../validate.ts";
|
|
5
|
+
|
|
6
|
+
/** Where shared pages open (W-321). */
|
|
7
|
+
export const PLAYGROUND_URL = "https://emvb.dev/playground/";
|
|
8
|
+
/** `#p=` holds the page, so it never reaches a server log. */
|
|
9
|
+
const SHARE_HASH_KEY = "p";
|
|
10
|
+
/** Format tag, so a later encoding can be told apart. */
|
|
11
|
+
const VERSION = "1";
|
|
12
|
+
/** Past this, some chat apps and browsers cut the link (W-321). */
|
|
13
|
+
export const LONG_LINK_CHARS = 8000;
|
|
14
|
+
/** A link longer than this is refused outright. */
|
|
15
|
+
const MAX_LINK_CHARS = 200_000;
|
|
16
|
+
const MAX_TITLE = 120;
|
|
17
|
+
/** Unpacked text: a layout and a design at their limits, plus a little JSON. */
|
|
18
|
+
const MAX_UNPACKED_BYTES = MAX_LAYOUT_BYTES + MAX_DESIGN_BYTES + 4096;
|
|
19
|
+
|
|
20
|
+
export type SharedPage = { title: string; layout: Layout; design?: DesignSystem };
|
|
21
|
+
|
|
22
|
+
export type ShareRead =
|
|
23
|
+
| { ok: true; page: SharedPage }
|
|
24
|
+
| { ok: false; reason: "empty" | "too-long" | "unreadable" | "invalid"; detail?: string };
|
|
25
|
+
|
|
26
|
+
function toBase64Url(bytes: Uint8Array): string {
|
|
27
|
+
let binary = "";
|
|
28
|
+
const CHUNK = 0x8000;
|
|
29
|
+
for (let i = 0; i < bytes.length; i += CHUNK) {
|
|
30
|
+
binary += String.fromCharCode(...bytes.subarray(i, i + CHUNK));
|
|
31
|
+
}
|
|
32
|
+
return btoa(binary).replaceAll("+", "-").replaceAll("/", "_").replace(/=+$/, "");
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function fromBase64Url(text: string): Uint8Array {
|
|
36
|
+
const b64 = text.replaceAll("-", "+").replaceAll("_", "/");
|
|
37
|
+
const binary = atob(b64 + "=".repeat((4 - (b64.length % 4)) % 4));
|
|
38
|
+
const bytes = new Uint8Array(binary.length);
|
|
39
|
+
for (let i = 0; i < binary.length; i += 1) bytes[i] = binary.charCodeAt(i);
|
|
40
|
+
return bytes;
|
|
41
|
+
}
|
|
42
|
+
|
|
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(
|
|
61
|
+
bytes: Uint8Array,
|
|
62
|
+
stream: BytePipe,
|
|
63
|
+
max: number,
|
|
64
|
+
): Promise<Uint8Array> {
|
|
65
|
+
const writer = stream.writable.getWriter();
|
|
66
|
+
const reader = stream.readable.getReader();
|
|
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);
|
|
102
|
+
}
|
|
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;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* The page and (optionally) Site styles packed for a link (W-321): JSON, deflated, base64url,
|
|
119
|
+
* prefixed with a version.
|
|
120
|
+
*/
|
|
121
|
+
export async function encodeSharedPage(page: SharedPage): Promise<string> {
|
|
122
|
+
const json = JSON.stringify({
|
|
123
|
+
t: page.title.slice(0, MAX_TITLE),
|
|
124
|
+
l: page.layout,
|
|
125
|
+
...(page.design ? { d: page.design } : {}),
|
|
126
|
+
});
|
|
127
|
+
const packed = await pipeBytes(
|
|
128
|
+
new TextEncoder().encode(json),
|
|
129
|
+
new CompressionStream("deflate-raw"),
|
|
130
|
+
Number.MAX_SAFE_INTEGER,
|
|
131
|
+
);
|
|
132
|
+
return `${VERSION}.${toBase64Url(packed)}`;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/** The full link: the playground with the page in its hash. */
|
|
136
|
+
export const shareUrl = (encoded: string, base: string = PLAYGROUND_URL): string =>
|
|
137
|
+
`${base}#${SHARE_HASH_KEY}=${encoded}`;
|
|
138
|
+
|
|
139
|
+
/** The packed page in a location hash (`#p=…`), if any. */
|
|
140
|
+
export function sharedFromHash(hash: string): string | null {
|
|
141
|
+
const params = new URLSearchParams(hash.replace(/^#/, ""));
|
|
142
|
+
const value = params.get(SHARE_HASH_KEY);
|
|
143
|
+
return value ? value.trim() : null;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Unpacks and checks a shared page (W-321). Everything goes through the same validation as a
|
|
148
|
+
* saved page, with the same size limits, so a link can't carry anything a page couldn't.
|
|
149
|
+
*/
|
|
150
|
+
export async function decodeSharedPage(encoded: string): Promise<ShareRead> {
|
|
151
|
+
const text = encoded.trim();
|
|
152
|
+
if (!text) return { ok: false, reason: "empty" };
|
|
153
|
+
if (text.length > MAX_LINK_CHARS) return { ok: false, reason: "too-long" };
|
|
154
|
+
const [version, body] = text.split(".", 2);
|
|
155
|
+
if (version !== VERSION || !body || !/^[A-Za-z0-9_-]+$/.test(body)) {
|
|
156
|
+
return { ok: false, reason: "unreadable" };
|
|
157
|
+
}
|
|
158
|
+
let parsed: unknown;
|
|
159
|
+
try {
|
|
160
|
+
const bytes = await pipeBytes(
|
|
161
|
+
fromBase64Url(body),
|
|
162
|
+
new DecompressionStream("deflate-raw"),
|
|
163
|
+
MAX_UNPACKED_BYTES,
|
|
164
|
+
);
|
|
165
|
+
parsed = JSON.parse(new TextDecoder().decode(bytes));
|
|
166
|
+
} catch {
|
|
167
|
+
return { ok: false, reason: "unreadable" };
|
|
168
|
+
}
|
|
169
|
+
if (typeof parsed !== "object" || parsed === null) return { ok: false, reason: "unreadable" };
|
|
170
|
+
const { t, l, d } = parsed as { t?: unknown; l?: unknown; d?: unknown };
|
|
171
|
+
const layout = validateLayout(l);
|
|
172
|
+
if (!layout.ok) {
|
|
173
|
+
return { ok: false, reason: "invalid", detail: layout.issues[0]?.message ?? "Bad layout" };
|
|
174
|
+
}
|
|
175
|
+
const page: SharedPage = {
|
|
176
|
+
title: typeof t === "string" && t.trim() ? t.trim().slice(0, MAX_TITLE) : "Shared page",
|
|
177
|
+
layout: layout.layout,
|
|
178
|
+
};
|
|
179
|
+
if (d !== undefined) {
|
|
180
|
+
const design = validateDesign(d);
|
|
181
|
+
if (!design.ok) {
|
|
182
|
+
return { ok: false, reason: "invalid", detail: design.issues[0]?.message ?? "Bad styles" };
|
|
183
|
+
}
|
|
184
|
+
page.design = design.design;
|
|
185
|
+
}
|
|
186
|
+
return { ok: true, page };
|
|
187
|
+
}
|
|
@@ -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
|
}
|