@plitzi/sdk-elements 0.38.2 → 0.38.3

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/CHANGELOG.md CHANGED
@@ -1,5 +1,138 @@
1
1
  # @plitzi/sdk-elements
2
2
 
3
+ ## 0.38.3
4
+
5
+ ### Patch Changes
6
+
7
+ - e047e1d: ## `plitzi upgrade`: a project brought up to its CLI
8
+
9
+ A project written by an older CLI had no way up but `plitzi create` in a scratch folder and a file-by-file comparison:
10
+ `skills update` brought the skills and nothing else, so the `check` and `shot` scripts they teach did not exist.
11
+ `plitzi upgrade` (also `update`) shows what this CLI writes today for what is the CLI's in the project, and `--write`
12
+ makes it. One part or several: `plitzi upgrade skills`, `plitzi upgrade files packages`.
13
+
14
+ - **`files`:** the CLI's machinery — `author.ts`, `main.ts`, the Playwright, TypeScript and lint configs, AGENTS.md. One
15
+ nobody changed since the CLI wrote it is replaced, a missing one added; one the project made its own is shown as a
16
+ diff and left, until `--take <file>` (or `all`). `plitzi create` now records what it wrote, by digest, in
17
+ `.plitzi/scaffold.json`; a project made before that sees every file that differs as its own.
18
+ - **`packages`:** `package.json` merged, never replaced — the scripts and dependencies it lacks added, `@plitzi/*`
19
+ raised to this version, then the install (`--no-install` to leave it). A script of the project's own stays.
20
+ - **`skills`:** `.claude/skills/plitzi-*` from the packages installed, each replaced whole, and the ones a newer CLI
21
+ writes added. `plitzi skills update` is `plitzi upgrade skills --write`.
22
+ - **`renames`:** a name a version renamed with no alias, at its file and line — `canTemplate` → `canSnippet`,
23
+ `authorTemplate` → `authorSnippet` and its kin (renamed only where imported from `@plitzi/sdk-authoring`) — renamed
24
+ with `--write`.
25
+
26
+ `npm run author` says when the skills or the CLI's files are older than the SDK installed, and `plitzi --version`
27
+ prints the CLI's.
28
+
29
+ ## Page checks that can be the definition of done
30
+
31
+ `inspectPage`, `plitzi check` and the scaffold's visual test failed pages that were whole, so an agent learnt to ignore
32
+ them:
33
+
34
+ - **A breakpoint hiding an element on purpose** — the desktop navigation on a phone, a bottom bar only a phone shows —
35
+ is no longer "not visible": an element whose `display` or `visibility` a breakpoint rule sets is checked at the width
36
+ it shows at.
37
+ - **A lazy image out of sight** waits whichever side it is out of: below the fold, as before, or beside the screen in a
38
+ carousel's track — cut off by any ancestor that clips, as the browser decides when to fetch it.
39
+ - **A plugin that draws nothing** says so: `drawsNothing: true` in its declaration (a clock that fires a flow), and its
40
+ handle is `boxless`, so no check waits for it on screen.
41
+
42
+ `plitzi check --json` and `PageReport` carry `issues` beside `problems`: each with its `code` (`element-hidden`,
43
+ `image-not-loaded`, `sideways-scroll`…), the `elementId` it is about and, in `check`, the `width`.
44
+
45
+ ## Authoring
46
+ - **A link's `content` names it.** `control-without-name` read only a link's `label`, so applying the
47
+ `content-attribute` suggestion as written turned every link into a warning.
48
+ - **`plitzi fix` writes `content-attribute`** where it has one reading: a button's or link's children that are only
49
+ `text(…)` and `fontAwesome({ icon })` become its own `content` and `icon` — the words kept as written, an import left
50
+ unused taken out. A child with an id, options or a class of the space's own stays, and is said. `npm run author`'s
51
+ `[fix]` line counts these too.
52
+ - **The recipes, the skill's examples and the catalog template** hold to the suggestions as well as the warnings, and
53
+ their tests say so: six recipes and the template wrote a link's or a button's words as a child.
54
+
55
+ ## Declared motion — in code, in the builder and over MCP
56
+
57
+ An element says how it arrives and whether it keeps moving with `motion`, and the SDK's stylesheet plays it — no
58
+ keyframes to write: `{ enter: 'fade-up', on: 'view' }` arrives as it scrolls into view, `{ enter: 'scale', stagger:
59
+ 60 }` brings its children one by one (a grid, a list's rows), `{ loop: 'float' }` keeps it moving. Enters: `fade`,
60
+ `fade-up`, `fade-down`, `slide-left`, `slide-right`, `scale`; loops: `float`, `pulse`, `spin`, `sway`; `duration`,
61
+ `delay`, `stagger` in ms. Opacity and the transforms only — an arrival on `translate`/`scale`, so it composes with an
62
+ element's own `transform` — a loop held until the page is live (`data-hydrated`), and none of it for a visitor who asked
63
+ for less motion. `view` follows the scroll where the browser has scroll timelines and plays on load where not.
64
+
65
+ - **Authoring:** `motion` on any factory; refused where it cannot play (`motion-invalid`, `motion-no-tag`), and carried
66
+ by `specFromSpace` and `compareSpaces`.
67
+ - **Builder:** a **Motion** tab in an element's tools: the presets as chips, a stage that plays the one pointed at (a
68
+ loop shown stronger than the page plays it, and saying so), when and how long, children one by one, and the choices
69
+ read back as a sentence — laid out side by side once the sidebar is wide enough. The canvas holds motion still while
70
+ editing; **▶** in the header (or **Play on the canvas** in the tab) plays it from the start, restarting what already
71
+ played, and an arrival tied to the scroll plays by the clock there, where it is usually in view already.
72
+ - **MCP:** `motion` on `upsertElement` and `patchElement`, checked the same way; the guide names the presets.
73
+ - **Schema:** `definition.motion` (`ElementMotion`, `@plitzi/sdk-shared/schema/motion` — the presets, `motionProblems`,
74
+ `motionAttributes`, `isMotionAnimation`, and each preset's frames, which the stylesheet is tested against), in both
75
+ init queries. **The platform's GraphQL schema has to declare `SpaceElementMotion`
76
+ before this version's builder or SDK queries it.**
77
+
78
+ ## Dev tools QA: x-ray and motion
79
+
80
+ The **QA** tab gains an **X-ray**: every element the document wires something to — bound to data, shown on a condition,
81
+ running a flow, moving, behind a flag — outlined in its colour and named on the page, read from the space's document by
82
+ the element's name; its legend counts each kind on the page and picks one to show alone. Beside **Pause**, **Slow**
83
+ plays every animation at a quarter of its speed and **Replay** plays the declared motion again from the start, without
84
+ reloading the page.
85
+
86
+ ## Plugins that draw
87
+
88
+ `useCanvas2d`, `useWebGL`, `useWebGL2` and `useAnimationFrame` (`@plitzi/plitzi-sdk`): a canvas sized to the device (at
89
+ most 2×), followed as it resizes, animating only while somebody can see it move — a live page, no reduced motion, the
90
+ tab in front, the canvas on screen — and one still frame otherwise (the builder included). `createShaderProgram`
91
+ compiles and links, and a shader that fails throws a `ShaderError` with the driver's log, printed as
92
+ `[plugin <type> "<id>"] fragment shader failed: …` instead of an empty canvas; `error` and `ready` say where it is.
93
+ `useReducedMotion` for the rest.
94
+
95
+ ## A space re-authored without a restart
96
+
97
+ A project's `npm run start:dev` restarts for its server code and its plugins only: a save to the space is re-authored
98
+ in a process of its own and every open page loads again (`server.reloadPages()` over an SSE endpoint, on with
99
+ `createServer({ devReload: true })` — never by `devMode` alone, since every open page holds a connection for it); an
100
+ edit authoring refuses is printed and the page keeps the last space that authored. A shutdown also ends WebSockets at
101
+ once (`1001`, going away) rather than waiting out the grace — the ten seconds a restart used to wait on an open page.
102
+
103
+ ## Checks and authoring, from the stripe.com experiment
104
+ - **A component's instance** is found by its own name: its root carries `data-plitzi-instance`, and the instance's
105
+ handle selects it — `inspectPage` no longer reports every named instance as missing.
106
+ - **Hidden at this width on purpose** — the burger on a desktop, the desktop menu on a phone — is listed apart
107
+ (`hiddenAtWidth`, and a dim line under `plitzi check`'s ✓) rather than as a problem.
108
+ - **An element whose every child is conditional** — four flyouts in one list, each opening on the state that names
109
+ it — is conditional too: at rest it shows nothing, and that is it working.
110
+ - **A carousel that scrolls by itself** (`overflow-x: auto`) is not the page scrolling sideways; the page's own pane
111
+ still is.
112
+ - **Templates:** `{{ state.faq ?? -1 }}` — a sign on the right of `??` — reads.
113
+ - **A plugin attribute named as an element field** (`variant`, `class`, `id`…) is warned about
114
+ (`plugin-attribute-reserved`): a factory never hands it to the plugin. A `variant` no class or type style declares is
115
+ `unknown-variant`.
116
+ - **Lists:** a list with `items` renders as the `<ul>` (or `<ol>`) its `subType` says — it was a `<div>` — with no
117
+ markers and the same spacing, so a page looks as it did; the builder offers the list type for it too. Its rows are
118
+ `<li>`s: `list-row-not-li` warns of one that is not — a plain container is made one by `fixSpace`, a link or a button
119
+ is wrapped — and the recipes, the catalog template and the docs write rows as `listItem`.
120
+ - **CSS:** `mask-size`, `mask-position`, `mask-repeat`, `mask-composite`, `-webkit-mask-image`,
121
+ `-webkit-background-clip`, `box-decoration-break` and `-webkit-box-decoration-break`.
122
+ - **`plitzi shot`:** `--clip <element>`, `--scroll-to <element>` and `--viewport`; `--frames` takes the same framing.
123
+ - **SVG from files:** `svgFile` and `svgFiles` (`@plitzi/sdk-authoring/node`) read a logo or a folder of them,
124
+ compacted (`compactSvg`, also on the main entry), instead of strings in the space's source.
125
+ - The plugin scaffolds say that an inline `style` on `RootElement` outranks the element's classes.
126
+
127
+ - Updated dependencies [e047e1d]
128
+ - @plitzi/sdk-auth@0.38.3
129
+ - @plitzi/sdk-dev-tools@0.38.3
130
+ - @plitzi/sdk-event-bridge@0.38.3
131
+ - @plitzi/sdk-interactions@0.38.3
132
+ - @plitzi/sdk-navigation@0.38.3
133
+ - @plitzi/sdk-schema@0.38.3
134
+ - @plitzi/sdk-shared@0.38.3
135
+
3
136
  ## 0.38.2
4
137
 
5
138
  ### Patch Changes
@@ -4,67 +4,75 @@ import n from "./helpers/renderStaticTag.mjs";
4
4
  import r from "./hooks/useRootElementInteractions.mjs";
5
5
  import { useMemo as i } from "react";
6
6
  import a from "@plitzi/sdk-shared/hooks/usePlitziServiceContext";
7
+ import { motionAttributes as o } from "@plitzi/sdk-shared/schema/motion";
7
8
  //#region src/Element/RootElement.tsx
8
- var o = ({ ref: o, children: s, tag: c = "div", className: l = "", interactionTriggers: u, interactionCallbacks: d, style: f, ...p }) => {
9
- let m = i(() => t(f), [f]), h = e(), g = a(), _ = g.settings.previewMode ?? !0, v = !!g.settings.debugMode;
10
- if (h.plitziJsxSkipHOC) return n({
11
- tag: c,
12
- refProp: o,
13
- style: m,
14
- className: l,
15
- otherProps: p,
16
- children: s
9
+ var s = ({ ref: s, children: c, tag: l = "div", className: u = "", interactionTriggers: d, interactionCallbacks: f, style: p, ...m }) => {
10
+ let h = i(() => t(p), [p]), g = e(), _ = a(), v = _.settings.previewMode ?? !0, y = !!_.settings.debugMode;
11
+ if (g.plitziJsxSkipHOC) return n({
12
+ tag: l,
13
+ refProp: s,
14
+ style: h,
15
+ className: u,
16
+ otherProps: m,
17
+ children: c
17
18
  });
18
- let { root: { baseElementId: y }, contexts: b } = g, x = b.InteractionsContext, { id: S, rootId: C, style: w, definition: { type: T, label: E, runtime: D, anchor: O } } = h, k = D === "server" ? { "data-rsc-id": S } : void 0, A = g.settings.testAttributes === !1 ? void 0 : { "data-plitzi-el": S }, j = !v && (_ || !T || C !== y) ? {} : {
19
- "data-id": S,
20
- "data-name": E || T || "unknown",
21
- "data-root-id": C,
22
- "data-type": T || "unknown",
19
+ let { root: { baseElementId: b }, contexts: x } = _, S = x.InteractionsContext, { id: C, rootId: w, style: T, plitziElementLayout: E, definition: { type: D, label: O, runtime: k, anchor: A, parentId: j, motion: M } } = g, N = o(M), P = k === "server" ? { "data-rsc-id": C } : void 0, F = E?.type === "component" && !j && E.rootId !== C ? E.rootId : void 0, I = _.settings.testAttributes === !1 ? void 0 : {
20
+ "data-plitzi-el": C,
21
+ ...F === void 0 ? {} : { "data-plitzi-instance": F }
22
+ }, L = !y && (v || !D || w !== b) ? {} : {
23
+ "data-id": C,
24
+ "data-name": O || D || "unknown",
25
+ "data-root-id": w,
26
+ "data-type": D || "unknown",
23
27
  "data-root-render-element": !0
24
28
  };
25
- if (!x) return n({
26
- tag: c,
27
- refProp: o,
29
+ if (!S) return n({
30
+ tag: l,
31
+ refProp: s,
28
32
  style: {
29
- ...w,
30
- ...m
33
+ ...T,
34
+ ...h,
35
+ ...N.style
31
36
  },
32
- className: l,
33
- otherProps: p,
34
- anchor: O,
35
- params: j,
36
- serverMarker: k,
37
- testMarker: A,
38
- children: s
37
+ className: u,
38
+ otherProps: m,
39
+ anchor: A,
40
+ params: L,
41
+ serverMarker: P,
42
+ motion: N.attributes,
43
+ testMarker: I,
44
+ children: c
39
45
  });
40
- let M = r({
41
- elementContext: h,
42
- InteractionsContext: x,
43
- previewMode: _,
44
- debugMode: v,
45
- baseElementId: y,
46
- className: l,
47
- interactionTriggers: u,
48
- interactionCallbacks: d,
49
- otherProps: p,
50
- ref: o
46
+ let R = r({
47
+ elementContext: g,
48
+ InteractionsContext: S,
49
+ previewMode: v,
50
+ debugMode: y,
51
+ baseElementId: b,
52
+ className: u,
53
+ interactionTriggers: d,
54
+ interactionCallbacks: f,
55
+ otherProps: m,
56
+ ref: s
51
57
  });
52
58
  return n({
53
- tag: c,
54
- refProp: M.nodeRef,
59
+ tag: l,
60
+ refProp: R.nodeRef,
55
61
  style: {
56
- ...w,
57
- ...m
62
+ ...T,
63
+ ...h,
64
+ ...N.style
58
65
  },
59
- className: M.className,
60
- otherProps: p,
61
- anchor: O,
62
- params: j,
63
- serverMarker: k,
64
- testMarker: A,
65
- events: M.events,
66
- children: s
66
+ className: R.className,
67
+ otherProps: m,
68
+ anchor: A,
69
+ params: L,
70
+ serverMarker: P,
71
+ motion: N.attributes,
72
+ testMarker: I,
73
+ events: R.events,
74
+ children: c
67
75
  });
68
76
  };
69
77
  //#endregion
70
- export { o as RootElement, o as default };
78
+ export { s as RootElement, s as default };
@@ -12,12 +12,18 @@ export type StaticTagProps = {
12
12
  serverMarker?: {
13
13
  'data-rsc-id': string;
14
14
  };
15
- /** What an end-to-end test addresses this element by. Last in the spread: nothing may shadow it. */
15
+ /** The element's declared motion, as the `data-motion-*` the SDK's stylesheet plays (`motionAttributes`). */
16
+ motion?: Record<string, string>;
17
+ /**
18
+ * What an end-to-end test addresses this element by — and, on a component instance's root, the instance. Last in the
19
+ * spread: nothing may shadow it.
20
+ */
16
21
  testMarker?: {
17
22
  'data-plitzi-el': string;
23
+ 'data-plitzi-instance'?: string;
18
24
  };
19
25
  events?: Record<string, unknown>;
20
26
  children?: ReactNode;
21
27
  };
22
- declare const renderStaticTag: ({ tag, refProp, style, className, otherProps, anchor, params, serverMarker, testMarker, events, children }: StaticTagProps) => ReactElement;
28
+ declare const renderStaticTag: ({ tag, refProp, style, className, otherProps, anchor, params, serverMarker, motion, testMarker, events, children }: StaticTagProps) => ReactElement;
23
29
  export default renderStaticTag;
@@ -1,15 +1,16 @@
1
1
  import { createElement as e } from "react";
2
2
  //#region src/Element/helpers/renderStaticTag.ts
3
- var t = ({ tag: t = "div", refProp: n, style: r, className: i, otherProps: a, anchor: o, params: s, serverMarker: c, testMarker: l, events: u, children: d }) => t === "" ? d : e(t, {
3
+ var t = ({ tag: t = "div", refProp: n, style: r, className: i, otherProps: a, anchor: o, params: s, serverMarker: c, motion: l, testMarker: u, events: d, children: f }) => t === "" ? f : e(t, {
4
4
  ref: n,
5
5
  style: r,
6
6
  className: i,
7
7
  ...a,
8
8
  ...o ? { id: o } : {},
9
9
  ...s,
10
- ...u,
10
+ ...l,
11
+ ...d,
11
12
  ...c,
12
- ...l
13
- }, d);
13
+ ...u
14
+ }, f);
14
15
  //#endregion
15
16
  export { t as default };
@@ -0,0 +1,6 @@
1
+ export { createShaderProgram, ShaderError } from './shaders';
2
+ export { default as useAnimationFrame } from './useAnimationFrame';
3
+ export { useCanvas2d, useWebGL, useWebGL2 } from './useCanvas';
4
+ export { default as useReducedMotion } from './useReducedMotion';
5
+ export type { AnimationFrameOptions, Frame } from './useAnimationFrame';
6
+ export type { CanvasHandle, CanvasOptions, CanvasSize } from './useCanvas';
@@ -0,0 +1,5 @@
1
+ import { ShaderError as e, createShaderProgram as t } from "./shaders.mjs";
2
+ import n from "./useReducedMotion.mjs";
3
+ import r from "./useAnimationFrame.mjs";
4
+ import { useCanvas2d as i, useWebGL as a, useWebGL2 as o } from "./useCanvas.mjs";
5
+ export { e as ShaderError, t as createShaderProgram, r as useAnimationFrame, i as useCanvas2d, n as useReducedMotion, a as useWebGL, o as useWebGL2 };
@@ -0,0 +1,16 @@
1
+ /** A shader that did not compile, or a program that did not link: what WebGL said, and which stage said it. */
2
+ export declare class ShaderError extends Error {
3
+ readonly stage: 'vertex' | 'fragment' | 'link';
4
+ readonly log: string;
5
+ constructor(stage: ShaderError['stage'], log: string);
6
+ }
7
+ /**
8
+ * A vertex and a fragment shader, compiled and linked into a program — or a `ShaderError` carrying what the driver
9
+ * said. WebGL itself fails a shader in silence: `compileShader` returns nothing, the program draws nothing, and the
10
+ * canvas stays empty with no word of why (`rgb(196, 214, 255)` — integers, where GLSL ES 1.0 wants `196.0`). Thrown
11
+ * inside `useCanvas`, the error is printed with the element it belongs to and the loop stops.
12
+ */
13
+ export declare const createShaderProgram: (gl: WebGLRenderingContext | WebGL2RenderingContext, { vertex, fragment }: {
14
+ vertex: string;
15
+ fragment: string;
16
+ }) => WebGLProgram;
@@ -0,0 +1,25 @@
1
+ //#region src/canvas/shaders.ts
2
+ var e = class extends Error {
3
+ stage;
4
+ log;
5
+ constructor(e, t) {
6
+ super(`${e === "link" ? "program failed to link" : `${e} shader failed`}: ${t.trim() || "no log given"}`), this.name = "ShaderError", this.stage = e, this.log = t;
7
+ }
8
+ }, t = (t, n, r) => {
9
+ let i = t.createShader(n === "vertex" ? t.VERTEX_SHADER : t.FRAGMENT_SHADER);
10
+ if (!i) throw new e(n, "the context made no shader (it is lost)");
11
+ if (t.shaderSource(i, r), t.compileShader(i), t.getShaderParameter(i, t.COMPILE_STATUS) !== !0) {
12
+ let r = t.getShaderInfoLog(i) ?? "";
13
+ throw t.deleteShader(i), new e(n, r);
14
+ }
15
+ return i;
16
+ }, n = (n, { vertex: r, fragment: i }) => {
17
+ let a = t(n, "vertex", r), o = t(n, "fragment", i), s = n.createProgram();
18
+ if (n.attachShader(s, a), n.attachShader(s, o), n.linkProgram(s), n.deleteShader(a), n.deleteShader(o), n.getProgramParameter(s, n.LINK_STATUS) !== !0) {
19
+ let t = n.getProgramInfoLog(s) ?? "";
20
+ throw n.deleteProgram(s), new e("link", t);
21
+ }
22
+ return s;
23
+ };
24
+ //#endregion
25
+ export { e as ShaderError, n as createShaderProgram };
@@ -0,0 +1,27 @@
1
+ import { RefObject } from 'react';
2
+ /** One frame: how long the animation has run, in ms — only while it ran — the time since the last frame, and its count. */
3
+ export interface Frame {
4
+ time: number;
5
+ delta: number;
6
+ frame: number;
7
+ }
8
+ export interface AnimationFrameOptions {
9
+ /** Held still — bound to a hover, a state, a setting. */
10
+ paused?: boolean;
11
+ /** At most this many frames a second; every frame the screen draws when left out. */
12
+ fps?: number;
13
+ /** The element whose being on screen decides whether it runs: out of sight, nobody sees it move. */
14
+ target?: RefObject<Element | null>;
15
+ }
16
+ /**
17
+ * `onFrame` on every frame the screen draws — but only while somebody can see it move: on a page that is live (not
18
+ * edited in the builder, where a plugin is inert), for a visitor who did not ask for less motion, with the tab in front
19
+ * and the `target` on screen, and not `paused`. Everything a canvas plugin wrote by hand, each its own way, and the
20
+ * reason a hero animation kept a laptop's fan on behind a closed tab.
21
+ *
22
+ * `running` says which it is, so a plugin can draw one still frame when it is not.
23
+ */
24
+ declare const useAnimationFrame: (onFrame: (frame: Frame) => void, { paused, fps, target }?: AnimationFrameOptions) => {
25
+ running: boolean;
26
+ };
27
+ export default useAnimationFrame;
@@ -0,0 +1,42 @@
1
+ import e from "./useReducedMotion.mjs";
2
+ import { useEffect as t, useRef as n, useState as r, useSyncExternalStore as i } from "react";
3
+ import a from "@plitzi/sdk-shared/hooks/usePlitziServiceContext";
4
+ //#region src/canvas/useAnimationFrame.ts
5
+ var o = (e) => (document.addEventListener("visibilitychange", e), () => document.removeEventListener("visibilitychange", e)), s = () => document.visibilityState !== "hidden", c = (e) => {
6
+ let [n, i] = r(!0);
7
+ return t(() => {
8
+ let t = e?.current;
9
+ if (!t || typeof IntersectionObserver > "u") return;
10
+ let n = new IntersectionObserver((e) => i(e.some((e) => e.isIntersecting)));
11
+ return n.observe(t), () => n.disconnect();
12
+ }, [e]), n;
13
+ }, l = (r, { paused: l = !1, fps: u, target: d } = {}) => {
14
+ let f = a().settings.previewMode ?? !0, p = e(), m = i(o, s, () => !1), h = c(d), g = f && !p && !l && m && h, _ = n(r);
15
+ t(() => {
16
+ _.current = r;
17
+ }, [r]);
18
+ let v = n({
19
+ time: 0,
20
+ frame: 0
21
+ });
22
+ return t(() => {
23
+ if (!g) return;
24
+ let e = u && u > 0 ? 1e3 / u : 0, t = 0, n, r = 0, i = (a) => {
25
+ let o = n === void 0 ? 0 : a - n;
26
+ if (n = a, r += o, r >= e) {
27
+ let t = e > 0 ? r : o;
28
+ r = e > 0 ? r % e : 0, v.current = {
29
+ time: v.current.time + t,
30
+ frame: v.current.frame + 1
31
+ }, _.current({
32
+ ...v.current,
33
+ delta: t
34
+ });
35
+ }
36
+ t = requestAnimationFrame(i);
37
+ };
38
+ return t = requestAnimationFrame(i), () => cancelAnimationFrame(t);
39
+ }, [g, u]), { running: g };
40
+ };
41
+ //#endregion
42
+ export { l as default };
@@ -0,0 +1,51 @@
1
+ import { AnimationFrameOptions, Frame } from './useAnimationFrame';
2
+ /** The canvas as it is laid out, in CSS pixels, and how many device pixels each of those holds. */
3
+ export interface CanvasSize {
4
+ width: number;
5
+ height: number;
6
+ pixelRatio: number;
7
+ }
8
+ export interface CanvasOptions<C, S> extends Omit<AnimationFrameOptions, 'target'> {
9
+ /**
10
+ * Once per context — and again after a lost WebGL context comes back: buffers, programs, gradients. What it returns
11
+ * is handed to every `draw`. A `ShaderError` (see `createShaderProgram`) or anything else it throws is printed with
12
+ * the element it belongs to, and nothing is drawn.
13
+ */
14
+ setup?: (context: C, size: CanvasSize) => S;
15
+ /** One frame, in CSS pixels: a 2D context is already scaled to the device's pixels, a WebGL viewport set to them. */
16
+ draw: (context: C, frame: Frame & CanvasSize & {
17
+ state: S;
18
+ }) => void;
19
+ /** The most device pixels per CSS pixel drawn — a phone at 3 draws nine times a 1× screen's work for little to see. */
20
+ maxPixelRatio?: number;
21
+ }
22
+ export interface CanvasHandle {
23
+ /** For the `<canvas>`: `<canvas ref={ref} />`, inside the plugin's `RootElement`. */
24
+ ref: (canvas: HTMLCanvasElement | null) => void;
25
+ /** Whether a frame was drawn — until then, what the server rendered (a still image) is what to show. */
26
+ ready: boolean;
27
+ /** What failed — setup, a draw, a shader — when something did; the loop is stopped. */
28
+ error: string | undefined;
29
+ /** Whether it is animating, or holding the one still frame it drew. */
30
+ running: boolean;
31
+ }
32
+ type Canvas2dOptions<S> = CanvasOptions<CanvasRenderingContext2D, S> & {
33
+ attributes?: CanvasRenderingContext2DSettings;
34
+ };
35
+ type WebGLOptions<C, S> = CanvasOptions<C, S> & {
36
+ attributes?: WebGLContextAttributes;
37
+ };
38
+ /**
39
+ * A 2D canvas that animates: `draw(ctx, { time, width, height })` in CSS pixels, every frame it should.
40
+ *
41
+ * ```tsx
42
+ * const { ref } = useCanvas2d({ draw: (ctx, { time, width, height }) => { ctx.clearRect(0, 0, width, height); … } });
43
+ * return <RootElement className={className}><canvas ref={ref} /></RootElement>;
44
+ * ```
45
+ */
46
+ export declare const useCanvas2d: <S = undefined>({ attributes, ...options }: Canvas2dOptions<S>) => CanvasHandle;
47
+ /** A WebGL (1) canvas that animates; `setup` compiles with `createShaderProgram`, which says why a shader failed. */
48
+ export declare const useWebGL: <S = undefined>({ attributes, ...options }: WebGLOptions<WebGLRenderingContext, S>) => CanvasHandle;
49
+ /** The same over WebGL 2 — GLSL ES 3.00, where the browser has it; `error` says so where it does not. */
50
+ export declare const useWebGL2: <S = undefined>({ attributes, ...options }: WebGLOptions<WebGL2RenderingContext, S>) => CanvasHandle;
51
+ export {};
@@ -0,0 +1,133 @@
1
+ import e from "../Element/ElementContext.mjs";
2
+ import t from "./useAnimationFrame.mjs";
3
+ import { use as n, useCallback as r, useEffect as i, useRef as a, useState as o } from "react";
4
+ //#region src/canvas/useCanvas.ts
5
+ var s = (e) => `[plugin ${e?.definition?.type ?? "canvas"}${e?.id ? ` "${e.id}"` : ""}]`, c = (c, { setup: l, draw: u, maxPixelRatio: d = 2, paused: f, fps: p }) => {
6
+ let m = s(n(e)), h = a(null), [g, _] = o(null), [v, y] = o({
7
+ width: 0,
8
+ height: 0,
9
+ pixelRatio: 1
10
+ }), [b, x] = o(), [S, C] = o(!1), [w, T] = o(0), E = a(null), D = a({
11
+ acquire: c,
12
+ setup: l,
13
+ draw: u
14
+ });
15
+ i(() => {
16
+ D.current = {
17
+ acquire: c,
18
+ setup: l,
19
+ draw: u
20
+ };
21
+ }, [
22
+ c,
23
+ l,
24
+ u
25
+ ]);
26
+ let O = r((e) => {
27
+ let t = e instanceof Error ? e.message : String(e);
28
+ console.error(`${m} ${t}`), x(t);
29
+ }, [m]), k = r((e) => {
30
+ h.current = e, _(e);
31
+ }, []);
32
+ i(() => {
33
+ if (!g) return;
34
+ let e = () => {
35
+ let e = g.getBoundingClientRect(), t = Math.min(window.devicePixelRatio || 1, d);
36
+ g.width = Math.max(1, Math.round(e.width * t)), g.height = Math.max(1, Math.round(e.height * t)), y({
37
+ width: e.width,
38
+ height: e.height,
39
+ pixelRatio: t
40
+ });
41
+ };
42
+ if (e(), typeof ResizeObserver > "u") return;
43
+ let t = new ResizeObserver(e);
44
+ return t.observe(g), () => t.disconnect();
45
+ }, [g, d]), i(() => {
46
+ if (!g) return;
47
+ let e = (e) => {
48
+ e.preventDefault(), E.current = null, C(!1);
49
+ }, t = () => T((e) => e + 1);
50
+ return g.addEventListener("webglcontextlost", e), g.addEventListener("webglcontextrestored", t), () => {
51
+ g.removeEventListener("webglcontextlost", e), g.removeEventListener("webglcontextrestored", t);
52
+ };
53
+ }, [g]), i(() => {
54
+ if (g && v.width !== 0 && b === void 0) try {
55
+ let e = D.current.acquire(g);
56
+ if (!e) {
57
+ O(/* @__PURE__ */ Error("the browser gave no drawing context (WebGL may be off)"));
58
+ return;
59
+ }
60
+ e.prepare(v);
61
+ let t = D.current.setup ? D.current.setup(e.context, v) : void 0;
62
+ E.current = {
63
+ handle: e,
64
+ state: t
65
+ };
66
+ } catch (e) {
67
+ O(e);
68
+ }
69
+ }, [
70
+ g,
71
+ v,
72
+ w,
73
+ b,
74
+ O
75
+ ]);
76
+ let A = r((e) => {
77
+ let t = E.current;
78
+ if (t && b === void 0) try {
79
+ t.handle.prepare(v), D.current.draw(t.handle.context, {
80
+ ...e,
81
+ ...v,
82
+ state: t.state
83
+ }), C(!0);
84
+ } catch (e) {
85
+ E.current = null, O(e);
86
+ }
87
+ }, [
88
+ v,
89
+ b,
90
+ O
91
+ ]), { running: j } = t(A, {
92
+ paused: f || b !== void 0,
93
+ fps: p,
94
+ target: h
95
+ });
96
+ return i(() => {
97
+ !j && v.width > 0 && A({
98
+ time: 0,
99
+ delta: 0,
100
+ frame: 0
101
+ });
102
+ }, [
103
+ j,
104
+ v,
105
+ w,
106
+ A
107
+ ]), {
108
+ ref: k,
109
+ ready: S,
110
+ error: b,
111
+ running: j
112
+ };
113
+ }, l = ({ attributes: e, ...t }) => c(r((t) => {
114
+ let n = t.getContext("2d", e);
115
+ return n && {
116
+ context: n,
117
+ prepare: ({ pixelRatio: e }) => n.setTransform(e, 0, 0, e, 0, 0)
118
+ };
119
+ }, [e]), t), u = ({ attributes: e, ...t }) => c(r((t) => {
120
+ let n = t.getContext("webgl", e);
121
+ return n && {
122
+ context: n,
123
+ prepare: () => n.viewport(0, 0, t.width, t.height)
124
+ };
125
+ }, [e]), t), d = ({ attributes: e, ...t }) => c(r((t) => {
126
+ let n = t.getContext("webgl2", e);
127
+ return n && {
128
+ context: n,
129
+ prepare: () => n.viewport(0, 0, t.width, t.height)
130
+ };
131
+ }, [e]), t);
132
+ //#endregion
133
+ export { l as useCanvas2d, u as useWebGL, d as useWebGL2 };
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Whether the visitor asked for less motion: their system's setting, or the QA tab's switch. What the CSS of a space
3
+ * already honours, for the motion a plugin draws itself. False on the server, which draws no motion either way.
4
+ */
5
+ declare const useReducedMotion: () => boolean;
6
+ export default useReducedMotion;
@@ -0,0 +1,15 @@
1
+ import { useSyncExternalStore as e } from "react";
2
+ //#region src/canvas/useReducedMotion.ts
3
+ var t = "(prefers-reduced-motion: reduce)", n = "plitzi-reduced-motion", r = () => typeof window.matchMedia == "function" && window.matchMedia(t).matches || document.documentElement.classList.contains(n), i = (e) => {
4
+ let n = typeof window.matchMedia == "function" ? window.matchMedia(t) : void 0;
5
+ n?.addEventListener("change", e);
6
+ let r = new MutationObserver(e);
7
+ return r.observe(document.documentElement, {
8
+ attributes: !0,
9
+ attributeFilter: ["class"]
10
+ }), () => {
11
+ n?.removeEventListener("change", e), r.disconnect();
12
+ };
13
+ }, a = () => e(i, r, () => !1);
14
+ //#endregion
15
+ export { a as default };
@@ -8,6 +8,7 @@ var i = ({ ref: e, className: i = "", subType: a = "ul", children: o, items: s =
8
8
  case "controlled": return /* @__PURE__ */ r(n, {
9
9
  ref: e,
10
10
  className: i,
11
+ subType: a,
11
12
  items: s,
12
13
  itemKey: l,
13
14
  children: o
@@ -29,7 +29,7 @@ var a = ({ subType: a = "ul", source: o = "none", itemKey: s = "", onUpdate: c }
29
29
  title: "The field of each item that names it, so a row stays with its item when the list is filtered.",
30
30
  onChange: l("itemKey")
31
31
  }),
32
- o === "none" && /* @__PURE__ */ n(i, {
32
+ /* @__PURE__ */ n(i, {
33
33
  label: "List Type",
34
34
  value: a,
35
35
  onChange: l("subType"),
@@ -16,7 +16,7 @@ var n = e()({
16
16
  definition: {
17
17
  label: "List",
18
18
  type: "list",
19
- description: "Repeats a template (its listItem/link child) once per entry of a data array — the way to render a dynamic collection. Bind its items to a data source (e.g. an apiContainer response).",
19
+ description: "Repeats a template (its row: a listItem, or a container with subType \"li\") once per entry of a data array — the way to render a dynamic collection, as a <ul> (subType \"ol\" for a numbered one). Bind its items to a data source (e.g. an apiContainer response).",
20
20
  items: [],
21
21
  bindings: {},
22
22
  styleSelectors: { base: "" },
@@ -2,9 +2,11 @@ import { ReactNode, RefObject } from 'react';
2
2
  export type ListControlledProps<T = unknown> = {
3
3
  ref?: RefObject<HTMLElement>;
4
4
  className: string;
5
+ /** The list's own tag: a list of data is a list, and each row — an `<li>` — renders straight into it. */
6
+ subType?: 'ul' | 'ol';
5
7
  children: ReactNode;
6
8
  items: T[];
7
9
  itemKey?: string;
8
10
  };
9
- declare const ListControlled: ({ ref, className, children, items, itemKey }: ListControlledProps) => import('react').JSX.Element;
11
+ declare const ListControlled: ({ ref, className, subType, children, items, itemKey }: ListControlledProps) => import('react').JSX.Element;
10
12
  export default ListControlled;
@@ -13,27 +13,28 @@ import m from "clsx";
13
13
  import h from "@plitzi/sdk-shared/dataSource/helpers/getSourceName";
14
14
  import g from "@plitzi/sdk-shared/dataSource/hooks/useRegisterSource";
15
15
  //#region src/elements/structure/List/modes/ListControlled/ListControlled.tsx
16
- var _ = ({ ref: _, className: v = "", children: y, items: b = [], itemKey: x }) => {
17
- let { id: S, definition: { label: C } } = e(), w = h(i.sourceType, S), { settings: { previewMode: T } } = s(), E = o(() => Array.isArray(b) ? b : [], [b]), D = o(() => n(E, x), [E, x]), O = a(() => d({
18
- item: c(E, "0", {}),
16
+ var _ = ({ ref: _, className: v = "", subType: y = "ul", children: b, items: x = [], itemKey: S }) => {
17
+ let { id: C, definition: { label: w } } = e(), T = h(i.sourceType, C), { settings: { previewMode: E } } = s(), D = o(() => Array.isArray(x) ? x : [], [x]), O = o(() => n(D, S), [D, S]), k = a(() => d({
18
+ item: c(D, "0", {}),
19
19
  index: 0
20
20
  }).reduce((e, t) => [...e, {
21
21
  path: t,
22
22
  name: t
23
- }], []), [E]), k = o(() => w ? { runtime: { sources: { [w]: { items: E } } } } : u, [w, E]);
23
+ }], []), [D]), A = o(() => T ? { runtime: { sources: { [T]: { items: D } } } } : u, [T, D]);
24
24
  return g({
25
- id: S,
26
- source: w,
27
- name: C || `List - ${S}`,
28
- fields: O
25
+ id: C,
26
+ source: T,
27
+ name: w || `List - ${C}`,
28
+ fields: k
29
29
  }), /* @__PURE__ */ p(t, {
30
30
  ref: _,
31
- className: m("plitzi-component__controlled-list", v, { "controlled-list--build-mode": !T }),
31
+ tag: y,
32
+ className: m("plitzi-component__controlled-list", v, { "controlled-list--build-mode": !E }),
32
33
  children: [/* @__PURE__ */ f(l, {
33
34
  inherit: "live",
34
- name: `List:${S}`,
35
- value: k,
36
- children: E.map((e, t) => !y || Array.isArray(y) && y.length === 0 ? /* @__PURE__ */ f("div", {
35
+ name: `List:${C}`,
36
+ value: A,
37
+ children: D.map((e, t) => !b || Array.isArray(b) && b.length === 0 ? /* @__PURE__ */ f("div", {
37
38
  className: "plitzi-component__controlled-list-item controlled-list--empty",
38
39
  children: /* @__PURE__ */ f("div", {
39
40
  className: "controlled-list-item__counter",
@@ -41,12 +42,12 @@ var _ = ({ ref: _, className: v = "", children: y, items: b = [], itemKey: x })
41
42
  })
42
43
  }, t) : /* @__PURE__ */ f(r, {
43
44
  index: t,
44
- isTemplate: t !== 0 && !T,
45
+ isTemplate: t !== 0 && !E,
45
46
  record: e,
46
- source: w,
47
- children: y
48
- }, D[t]))
49
- }), !T && E.length === 0 && /* @__PURE__ */ f("div", {
47
+ source: T,
48
+ children: b
49
+ }, O[t]))
50
+ }), !E && D.length === 0 && /* @__PURE__ */ f("div", {
50
51
  className: "controlled-list controlled-list--empty",
51
52
  children: "This list does not contain any items"
52
53
  })]
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plitzi/sdk-elements",
3
- "version": "0.38.2",
3
+ "version": "0.38.3",
4
4
  "license": "AGPL-3.0",
5
5
  "files": [
6
6
  "dist"
@@ -162,6 +162,30 @@
162
162
  "types": "./dist/Element/hooks/useScrollInteractions.d.ts",
163
163
  "import": "./dist/Element/hooks/useScrollInteractions.mjs"
164
164
  },
165
+ "./canvas": {
166
+ "types": "./dist/canvas/index.d.ts",
167
+ "import": "./dist/canvas/index.mjs"
168
+ },
169
+ "./canvas/index": {
170
+ "types": "./dist/canvas/index.d.ts",
171
+ "import": "./dist/canvas/index.mjs"
172
+ },
173
+ "./canvas/shaders": {
174
+ "types": "./dist/canvas/shaders.d.ts",
175
+ "import": "./dist/canvas/shaders.mjs"
176
+ },
177
+ "./canvas/useAnimationFrame": {
178
+ "types": "./dist/canvas/useAnimationFrame.d.ts",
179
+ "import": "./dist/canvas/useAnimationFrame.mjs"
180
+ },
181
+ "./canvas/useCanvas": {
182
+ "types": "./dist/canvas/useCanvas.d.ts",
183
+ "import": "./dist/canvas/useCanvas.mjs"
184
+ },
185
+ "./canvas/useReducedMotion": {
186
+ "types": "./dist/canvas/useReducedMotion.d.ts",
187
+ "import": "./dist/canvas/useReducedMotion.mjs"
188
+ },
165
189
  "./components/ElementAdvancedEditor": {
166
190
  "types": "./dist/components/ElementAdvancedEditor.d.ts",
167
191
  "import": "./dist/components/ElementAdvancedEditor.mjs"
@@ -1270,13 +1294,13 @@
1270
1294
  "dependencies": {
1271
1295
  "@plitzi/nexus": "^1.4.0",
1272
1296
  "@plitzi/plitzi-ui": "^1.6.29",
1273
- "@plitzi/sdk-auth": "0.38.2",
1274
- "@plitzi/sdk-dev-tools": "0.38.2",
1275
- "@plitzi/sdk-event-bridge": "0.38.2",
1276
- "@plitzi/sdk-interactions": "0.38.2",
1277
- "@plitzi/sdk-navigation": "0.38.2",
1278
- "@plitzi/sdk-schema": "0.38.2",
1279
- "@plitzi/sdk-shared": "0.38.2",
1297
+ "@plitzi/sdk-auth": "0.38.3",
1298
+ "@plitzi/sdk-dev-tools": "0.38.3",
1299
+ "@plitzi/sdk-event-bridge": "0.38.3",
1300
+ "@plitzi/sdk-interactions": "0.38.3",
1301
+ "@plitzi/sdk-navigation": "0.38.3",
1302
+ "@plitzi/sdk-schema": "0.38.3",
1303
+ "@plitzi/sdk-shared": "0.38.3",
1280
1304
  "clsx": "^2.1.1",
1281
1305
  "immer": "^11.1.21"
1282
1306
  },