fancy-ui-vue 0.3.0 → 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.
Files changed (54) hide show
  1. package/README.md +9 -6
  2. package/dist/components/magnetic-field/MagnetPuck.vue.d.ts +51 -0
  3. package/dist/components/magnetic-field/MagnetPuck.vue.js +7 -0
  4. package/dist/components/magnetic-field/MagnetPuck.vue2.js +191 -0
  5. package/dist/components/magnetic-field/MagneticField.vue.d.ts +39 -0
  6. package/dist/components/magnetic-field/MagneticField.vue.js +7 -0
  7. package/dist/components/magnetic-field/MagneticField.vue2.js +157 -0
  8. package/dist/components/magnetic-field/MagneticItem.vue.d.ts +28 -0
  9. package/dist/components/magnetic-field/MagneticItem.vue.js +7 -0
  10. package/dist/components/magnetic-field/MagneticItem.vue2.js +72 -0
  11. package/dist/components/magnetic-field/index.d.ts +10 -0
  12. package/dist/components/magnetic-field/magnetic-field-core.d.ts +163 -0
  13. package/dist/components/magnetic-field/magnetic-field-core.js +534 -0
  14. package/dist/components/magnetic-field/magnetic-field-source.d.ts +58 -0
  15. package/dist/components/magnetic-field/magnetic-field-source.js +58 -0
  16. package/dist/components/magnetic-field/types.d.ts +14 -0
  17. package/dist/components/magnetic-field/types.js +5 -0
  18. package/dist/components/pixel-scene/PixelScene.vue.d.ts +60 -0
  19. package/dist/components/pixel-scene/PixelScene.vue.js +184 -0
  20. package/dist/components/pixel-scene/PixelScene.vue2.js +4 -0
  21. package/dist/components/pixel-scene/index.d.ts +4 -0
  22. package/dist/components/pixel-scene/pixel-scene-core.d.ts +256 -0
  23. package/dist/components/pixel-scene/pixel-scene-core.js +878 -0
  24. package/dist/components/pixel-scene/pixel-scene-hdr.d.ts +68 -0
  25. package/dist/components/pixel-scene/pixel-scene-hdr.js +312 -0
  26. package/dist/components/pixel-scene/pixel-scene-scenes.d.ts +31 -0
  27. package/dist/components/pixel-scene/pixel-scene-scenes.js +1074 -0
  28. package/dist/components/story-thread/StoryNode.vue.d.ts +11 -0
  29. package/dist/components/story-thread/StoryNode.vue.js +7 -0
  30. package/dist/components/story-thread/StoryNode.vue2.js +23 -0
  31. package/dist/components/story-thread/StoryThread.vue.d.ts +56 -0
  32. package/dist/components/story-thread/StoryThread.vue.js +7 -0
  33. package/dist/components/story-thread/StoryThread.vue2.js +103 -0
  34. package/dist/components/story-thread/index.d.ts +5 -0
  35. package/dist/components/story-thread/story-thread-core.d.ts +119 -0
  36. package/dist/components/story-thread/story-thread-core.js +491 -0
  37. package/dist/components/story-thread/types.d.ts +1 -0
  38. package/dist/components/sun-switch/SunSwitch.vue.d.ts +61 -0
  39. package/dist/components/sun-switch/SunSwitch.vue.js +7 -0
  40. package/dist/components/sun-switch/SunSwitch.vue2.js +559 -0
  41. package/dist/components/sun-switch/index.d.ts +4 -0
  42. package/dist/components/sun-switch/pixel-wave-core.d.ts +82 -0
  43. package/dist/components/sun-switch/pixel-wave-core.js +508 -0
  44. package/dist/components/sun-switch/sun-switch-core.d.ts +251 -0
  45. package/dist/components/sun-switch/sun-switch-core.js +546 -0
  46. package/dist/components/sun-switch/sun-switch-hdr.d.ts +70 -0
  47. package/dist/components/sun-switch/sun-switch-hdr.js +311 -0
  48. package/dist/components/tracing-beam/TracingBeam.vue.d.ts +20 -1
  49. package/dist/components/tracing-beam/TracingBeam.vue.js +5 -164
  50. package/dist/components/tracing-beam/TracingBeam.vue2.js +168 -1
  51. package/dist/index.d.ts +4 -0
  52. package/dist/index.js +190 -164
  53. package/dist/styles.css +499 -0
  54. package/package.json +1 -1
@@ -0,0 +1,58 @@
1
+ /**
2
+ * MagneticField input adapters — framework-free, byte-identical in the Svelte,
3
+ * React and Vue trees (listed explicitly in shared-cores.json).
4
+ *
5
+ * The core (`magnetic-field-core.ts`) never listens to anything: it is fed a
6
+ * magnet position per channel and told when the layout may have moved. This
7
+ * module owns the two listener sets that do the feeding:
8
+ *
9
+ * - `attachPointerSource` turns a mouse or pen anywhere on the page into the
10
+ * `"pointer"` channel. It listens on the DOCUMENT, not the field root: the
11
+ * pull reaches `radius` px beyond every item, so most of the approach
12
+ * happens outside the root's box. The component gates the attachment with an
13
+ * in-view observer whose margin is that radius, so an off-screen field costs
14
+ * nothing.
15
+ * - `attachLayoutInvalidation` tells the core that rects may be stale after a
16
+ * scroll (of the page or of any scrolling ancestor) or a window resize.
17
+ *
18
+ * Handlers never compute anything: they store the latest client position in
19
+ * the core, which coalesces to at most one target pass per frame.
20
+ *
21
+ * Both functions return their own teardown and are safe to call during SSR
22
+ * (they attach nothing and return a no-op). No browser global is touched at
23
+ * import time.
24
+ */
25
+ import type { MagneticFieldCore } from "./magnetic-field-core.js";
26
+ /**
27
+ * Feeds the core's `"pointer"` channel from a mouse or pen moving anywhere on
28
+ * `target` (the current document by default).
29
+ *
30
+ * - Touch is ignored: a finger has no hover, and a tap would yank the items
31
+ * toward it for one frame and drop them. Touch users drive the field with a
32
+ * `MagnetPuck` instead.
33
+ * - Only the primary pointer counts, so a second pen or mouse cannot fight the
34
+ * first.
35
+ * - A pointer over a `MagnetPuck` (hovering it, or dragging it with pointer
36
+ * capture) clears the channel instead of feeding it: the puck is the magnet
37
+ * there. Otherwise, letting go of a puck would release nothing, since the
38
+ * cursor resting on it would take over at the very same point. The channel
39
+ * comes back as soon as the pointer moves off the puck. With a `root`, only
40
+ * a puck inside it counts: another field's puck is that field's magnet.
41
+ * - The channel is cleared when the pointer leaves the page (to the browser
42
+ * chrome, another window, or a pen lifted out of hover range), when the
43
+ * window loses focus (a keyboard tab switch moves no pointer), and when the
44
+ * page is hidden. Without these, the last pull would freeze on screen until
45
+ * the pointer came back.
46
+ */
47
+ export declare function attachPointerSource(core: Pick<MagneticFieldCore, "setClientSource" | "clearSource">, target?: Document, root?: Element): () => void;
48
+ /**
49
+ * Calls `core.invalidate()` whenever the field may have moved on screen
50
+ * without resizing: a scroll of the page or of any scrolling ancestor
51
+ * (captured on the window, since `scroll` does not bubble), or a window
52
+ * resize. Size changes of the root and the items themselves are the core's
53
+ * own `ResizeObserver`'s job.
54
+ *
55
+ * `invalidate()` only marks the cached rects dirty and wakes the loop when
56
+ * something is engaged, so a fast scroll costs one rect read per frame at most.
57
+ */
58
+ export declare function attachLayoutInvalidation(core: Pick<MagneticFieldCore, "invalidate">): () => void;
@@ -0,0 +1,58 @@
1
+ const NOOP = () => {
2
+ };
3
+ const PUCK_SELECTOR = ".ft-magnet-puck";
4
+ function attachPointerSource(core, target, root) {
5
+ const doc = target ?? (typeof document === "undefined" ? void 0 : document);
6
+ if (!doc) return NOOP;
7
+ const win = doc.defaultView;
8
+ const clear = () => core.clearSource("pointer");
9
+ const onMove = (event) => {
10
+ if (event.pointerType === "touch" || !event.isPrimary) return;
11
+ const target2 = event.target;
12
+ const puck = typeof target2?.closest === "function" ? target2.closest(PUCK_SELECTOR) : null;
13
+ if (puck && (!root || root.contains(puck))) {
14
+ clear();
15
+ return;
16
+ }
17
+ core.setClientSource(event.clientX, event.clientY, "pointer");
18
+ };
19
+ const onOut = (event) => {
20
+ if (event.pointerType === "touch" || !event.isPrimary) return;
21
+ if (event.relatedTarget === null) clear();
22
+ };
23
+ const onLeave = (event) => {
24
+ if (event.pointerType === "touch" || !event.isPrimary) return;
25
+ clear();
26
+ };
27
+ const onVisibility = () => {
28
+ if (doc.visibilityState === "hidden") clear();
29
+ };
30
+ doc.addEventListener("pointermove", onMove, { passive: true });
31
+ doc.addEventListener("pointerout", onOut, { passive: true });
32
+ doc.addEventListener("pointerleave", onLeave, { passive: true });
33
+ doc.addEventListener("visibilitychange", onVisibility);
34
+ win?.addEventListener("blur", clear);
35
+ return () => {
36
+ doc.removeEventListener("pointermove", onMove);
37
+ doc.removeEventListener("pointerout", onOut);
38
+ doc.removeEventListener("pointerleave", onLeave);
39
+ doc.removeEventListener("visibilitychange", onVisibility);
40
+ win?.removeEventListener("blur", clear);
41
+ clear();
42
+ };
43
+ }
44
+ function attachLayoutInvalidation(core) {
45
+ if (typeof window === "undefined") return NOOP;
46
+ const win = window;
47
+ const onChange = () => core.invalidate();
48
+ win.addEventListener("scroll", onChange, { capture: true, passive: true });
49
+ win.addEventListener("resize", onChange, { passive: true });
50
+ return () => {
51
+ win.removeEventListener("scroll", onChange, { capture: true });
52
+ win.removeEventListener("resize", onChange);
53
+ };
54
+ }
55
+ export {
56
+ attachLayoutInvalidation,
57
+ attachPointerSource
58
+ };
@@ -0,0 +1,14 @@
1
+ /**
2
+ * The contract between a `MagneticField` and the `MagneticItem`s and
3
+ * `MagnetPuck`s inside it.
4
+ *
5
+ * The context value is the field's registration hub (see
6
+ * `createMagneticFieldHub` in `magnetic-field-core.ts`): a stable object,
7
+ * created once per field, that buffers registrations until the field's core
8
+ * exists and replays them into it. Children only ever see these three methods.
9
+ */
10
+ import { type InternalContext } from "../../internals/dom/context.js";
11
+ import type { MagneticFieldHub } from "./magnetic-field-core.js";
12
+ /** What a field publishes to its items and pucks. */
13
+ export type MagneticFieldContext = Pick<MagneticFieldHub, "register" | "updateItem" | "setSource">;
14
+ export declare const MAGNETIC_FIELD_KEY: InternalContext<MagneticFieldContext>;
@@ -0,0 +1,5 @@
1
+ import { createInternalContext } from "../../internals/dom/context.js";
2
+ const MAGNETIC_FIELD_KEY = createInternalContext("MagneticFieldContext");
3
+ export {
4
+ MAGNETIC_FIELD_KEY
5
+ };
@@ -0,0 +1,60 @@
1
+ import type { HTMLAttributes } from "vue";
2
+ import type { PixelSceneName } from "./pixel-scene-scenes.js";
3
+ import type { PixelSceneHdrLook } from "./pixel-scene-hdr.js";
4
+ export type { PixelSceneName };
5
+ /**
6
+ * PixelScene — an animated pixel-art landscape on a dot grid.
7
+ *
8
+ * At rest only sparse ink dots and the lit cells show; a round lens that
9
+ * follows the pointer reveals the picture in full colour, with a dithered
10
+ * rim. Day and night are two complete palettes. On HDR displays the lit
11
+ * cells (sun, moon, windows, stars, fireflies, the lens field) are redrawn
12
+ * as hard squares brighter than SDR white in a WebGPU layer.
13
+ *
14
+ * The engine, the scenes and the HDR layer live in three framework-free
15
+ * cores; this file owns the markup and pushes props into the engine. The
16
+ * engine owns its observers, the reduced-motion query and the pointer
17
+ * listeners.
18
+ */
19
+ export interface PixelSceneProps {
20
+ /** Which landscape to paint */
21
+ scene?: PixelSceneName;
22
+ /** Night palette (stars, moon, lit windows) instead of day. Never changed by the component. */
23
+ night?: boolean;
24
+ /** Grid pitch in CSS px (clamped 4–32; grows on very large boxes) */
25
+ cell?: number;
26
+ /** Square dot edge in CSS px, at most `cell` */
27
+ dot?: number;
28
+ /** Show full colour under a round lens that follows the pointer */
29
+ lens?: boolean;
30
+ /** Lens radius in cells */
31
+ lensRadius?: number;
32
+ /** On HDR displays, draw lit cells brighter than SDR white in a WebGPU layer */
33
+ hdr?: boolean;
34
+ /** HDR rendering: `calibrated` (glow 1 = the SDR dot, sRGB) or `vivid` (the prototype's hotter, display-p3 look) */
35
+ hdrLook?: PixelSceneHdrLook;
36
+ /** Colour of the resting dots; any CSS colour, `currentColor` resolved on the host */
37
+ ink?: string;
38
+ /** Freeze the scene's animations (the lens still follows the pointer) */
39
+ paused?: boolean;
40
+ /** Animate a change of `night` as a dithered wave from the sun (never under reduced motion) */
41
+ wave?: boolean;
42
+ /** `[day, night]` background painted by the scene itself; the wave carries it. Default: transparent */
43
+ surfaces?: readonly [day: string, night: string];
44
+ /** `[day, night]` dot colours, swapped by the wave; overrides `ink` */
45
+ inks?: readonly [day: string, night: string];
46
+ /** Additional classes on the host — give it a height */
47
+ class?: HTMLAttributes["class"];
48
+ }
49
+ declare const _default: typeof __VLS_export;
50
+ export default _default;
51
+ declare const __VLS_export: __VLS_WithSlots<import("vue").DefineComponent<PixelSceneProps, {
52
+ ref: Readonly<import("vue").ShallowRef<HTMLDivElement | null>>;
53
+ }, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<PixelSceneProps> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>, {
54
+ default?(): unknown;
55
+ }>;
56
+ type __VLS_WithSlots<T, S> = T & {
57
+ new (): {
58
+ $slots: S;
59
+ };
60
+ };
@@ -0,0 +1,184 @@
1
+ import { defineComponent, useAttrs, useTemplateRef, ref, onMounted, onBeforeUnmount, watch, createElementBlock, openBlock, mergeProps, unref, createElementVNode, createCommentVNode, renderSlot } from "vue";
2
+ import { cn } from "../../utils.js";
3
+ import { createPixelScene } from "./pixel-scene-core.js";
4
+ import { getScenePainter } from "./pixel-scene-scenes.js";
5
+ import { pixelSceneHdrAvailable, startPixelSceneHdr, PIXEL_SCENE_HDR_RESTARTS, PIXEL_SCENE_HDR_RESTART_MS } from "./pixel-scene-hdr.js";
6
+ const _hoisted_1 = ["data-scene", "data-night", "data-hdr"];
7
+ const _hoisted_2 = {
8
+ ref: "canvas",
9
+ class: "pointer-events-none absolute inset-0 block h-full w-full",
10
+ "aria-hidden": "true"
11
+ };
12
+ const _hoisted_3 = {
13
+ key: 1,
14
+ class: "pixel-scene__content relative z-[1] h-full w-full"
15
+ };
16
+ const _sfc_main = /* @__PURE__ */ defineComponent({
17
+ ...{ name: "PixelScene", inheritAttrs: false },
18
+ __name: "PixelScene",
19
+ props: {
20
+ scene: { default: "alpine" },
21
+ night: { type: Boolean, default: false },
22
+ cell: { default: 5 },
23
+ dot: { default: 4 },
24
+ lens: { type: Boolean, default: true },
25
+ lensRadius: { default: 21 },
26
+ hdr: { type: Boolean, default: true },
27
+ hdrLook: { default: "calibrated" },
28
+ ink: { default: "currentColor" },
29
+ paused: { type: Boolean, default: false },
30
+ wave: { type: Boolean, default: true },
31
+ surfaces: {},
32
+ inks: {},
33
+ class: { type: [Boolean, null, String, Object, Array] }
34
+ },
35
+ setup(__props, { expose: __expose }) {
36
+ const attrs = useAttrs();
37
+ const hostEl = useTemplateRef("host");
38
+ const canvasEl = useTemplateRef("canvas");
39
+ const hdrCanvas = useTemplateRef("hdrCanvas");
40
+ const mounted = ref(false);
41
+ const hdrCapable = ref(false);
42
+ const hdrOn = ref(false);
43
+ const hdrRun = ref(0);
44
+ let hdrRestarts = 0;
45
+ const engineReady = ref(false);
46
+ let engine = null;
47
+ __expose({ ref: hostEl });
48
+ onMounted(() => {
49
+ mounted.value = true;
50
+ hdrCapable.value = __props.hdr && pixelSceneHdrAvailable();
51
+ const host = hostEl.value;
52
+ const canvas = canvasEl.value;
53
+ if (!host || !canvas) return;
54
+ engine = createPixelScene(
55
+ { host, canvas },
56
+ {
57
+ painter: getScenePainter(__props.scene),
58
+ night: __props.night,
59
+ cell: __props.cell,
60
+ dot: __props.dot,
61
+ lens: __props.lens,
62
+ lensRadius: __props.lensRadius,
63
+ ink: __props.ink,
64
+ paused: __props.paused,
65
+ wave: __props.wave,
66
+ surfaces: __props.surfaces ?? null,
67
+ inks: __props.inks ?? null
68
+ }
69
+ );
70
+ engineReady.value = engine !== null;
71
+ });
72
+ onBeforeUnmount(() => {
73
+ engine?.destroy();
74
+ engine = null;
75
+ engineReady.value = false;
76
+ mounted.value = false;
77
+ });
78
+ watch(
79
+ () => ({ painter: getScenePainter(__props.scene), night: __props.night }),
80
+ (next) => engine?.setOptions(next),
81
+ { flush: "post" }
82
+ );
83
+ watch(
84
+ () => ({ cell: __props.cell, dot: __props.dot }),
85
+ (next) => engine?.setOptions(next),
86
+ { flush: "post" }
87
+ );
88
+ watch(
89
+ () => ({
90
+ lens: __props.lens,
91
+ lensRadius: __props.lensRadius,
92
+ ink: __props.ink,
93
+ paused: __props.paused,
94
+ wave: __props.wave,
95
+ surfaces: __props.surfaces ?? null,
96
+ inks: __props.inks ?? null
97
+ }),
98
+ (next) => engine?.setOptions(next),
99
+ { flush: "post" }
100
+ );
101
+ watch(
102
+ () => __props.hdr,
103
+ (on) => {
104
+ hdrCapable.value = mounted.value && on && pixelSceneHdrAvailable();
105
+ }
106
+ );
107
+ watch(
108
+ [hdrCanvas, engineReady, hdrCapable, hdrRun, () => __props.hdrLook],
109
+ ([canvas, ready, capable], _old, onCleanup) => {
110
+ if (!canvas || !ready || !capable) return;
111
+ let cancelled = false;
112
+ let stop = null;
113
+ let retry = null;
114
+ const restart = () => {
115
+ if (hdrRestarts >= PIXEL_SCENE_HDR_RESTARTS) {
116
+ hdrCapable.value = false;
117
+ return;
118
+ }
119
+ hdrRestarts++;
120
+ retry = setTimeout(() => {
121
+ retry = null;
122
+ hdrRun.value++;
123
+ }, PIXEL_SCENE_HDR_RESTART_MS * hdrRestarts);
124
+ };
125
+ void startPixelSceneHdr(canvas, __props.hdrLook).then((layer) => {
126
+ if (cancelled || !engine) {
127
+ layer?.destroy();
128
+ return;
129
+ }
130
+ if (!layer) {
131
+ if (hdrRestarts === 0) hdrCapable.value = false;
132
+ else restart();
133
+ return;
134
+ }
135
+ const target = engine;
136
+ target.setOptions({ onFrame: (frame) => layer.render(frame) });
137
+ hdrOn.value = true;
138
+ stop = () => {
139
+ target.setOptions({ onFrame: null });
140
+ layer.destroy();
141
+ hdrOn.value = false;
142
+ };
143
+ void layer.lost.then(() => {
144
+ if (cancelled) return;
145
+ stop?.();
146
+ stop = null;
147
+ restart();
148
+ });
149
+ });
150
+ onCleanup(() => {
151
+ cancelled = true;
152
+ stop?.();
153
+ stop = null;
154
+ if (retry !== null) clearTimeout(retry);
155
+ });
156
+ },
157
+ { flush: "post" }
158
+ );
159
+ return (_ctx, _cache) => {
160
+ return openBlock(), createElementBlock("div", mergeProps({
161
+ ref: "host",
162
+ class: unref(cn)("pixel-scene relative overflow-hidden", __props.class),
163
+ "data-scene": __props.scene,
164
+ "data-night": __props.night ? "" : void 0,
165
+ "data-hdr": hdrOn.value ? "" : void 0
166
+ }, unref(attrs)), [
167
+ createElementVNode("canvas", _hoisted_2, null, 512),
168
+ hdrCapable.value ? (openBlock(), createElementBlock("canvas", {
169
+ key: 0,
170
+ ref_key: "hdrCanvas",
171
+ ref: hdrCanvas,
172
+ class: "pixel-scene__hdr pointer-events-none absolute inset-0 block h-full w-full",
173
+ "aria-hidden": "true"
174
+ }, null, 512)) : createCommentVNode("", true),
175
+ _ctx.$slots.default ? (openBlock(), createElementBlock("div", _hoisted_3, [
176
+ renderSlot(_ctx.$slots, "default")
177
+ ])) : createCommentVNode("", true)
178
+ ], 16, _hoisted_1);
179
+ };
180
+ }
181
+ });
182
+ export {
183
+ _sfc_main as default
184
+ };
@@ -0,0 +1,4 @@
1
+ import _sfc_main from "./PixelScene.vue.js";
2
+ export {
3
+ _sfc_main as default
4
+ };
@@ -0,0 +1,4 @@
1
+ export { default as PixelScene } from "./PixelScene.vue";
2
+ export type { PixelSceneProps, PixelSceneName } from "./PixelScene.vue";
3
+ export { PIXEL_SCENES } from "./pixel-scene-scenes.js";
4
+ export type { PixelSceneHdrLook } from "./pixel-scene-hdr.js";
@@ -0,0 +1,256 @@
1
+ /**
2
+ * PixelScene core — the framework-free engine, byte-identical in the Svelte,
3
+ * React and Vue trees (see shared-cores.json).
4
+ *
5
+ * A picture is a grid of square cells. Every frame a scene painter fills the
6
+ * grid through `writeCell` (the `put()` grammar below), `pixelHalos` adds the
7
+ * dithered light cells around emitters, and `paintGrid` draws one square dot
8
+ * per cell into a 2D canvas: sparse ink dots outside the lens, full colour
9
+ * under it, lit cells in colour everywhere. Cells with `glow > 0` are handed
10
+ * to the optional HDR layer through `onFrame`.
11
+ *
12
+ * First the pure helpers (hash, Bayer, noise, packed colours), then the grid,
13
+ * the lens, the painter, and `createPixelScene`, the engine that owns the
14
+ * canvas, the rAF loop, the pointer listeners and every observer. No
15
+ * framework imports, and nothing touches `window` or `document` at module
16
+ * scope, so the file is safe to import on the server.
17
+ *
18
+ * Colours are packed `0xRRGGBB` integers (`-1` = empty cell). Scenes may still
19
+ * pass `"#hex"` literals; `parseColour` caches them. No CSS string is built
20
+ * per cell.
21
+ *
22
+ * Compiles under `noUncheckedIndexedAccess`. The `!` assertions are in bounds
23
+ * by construction (indices come from loops over the arrays' own sizes).
24
+ */
25
+ /** 4×4 ordered-dither thresholds, centred in (0, 1). */
26
+ export declare const BAYER: readonly number[];
27
+ /** Ordered-dither threshold of a cell, one of 16 levels in (0, 1). */
28
+ export declare function bayer(x: number, y: number): number;
29
+ /** Deterministic hash of a cell and a seed, in [0, 1). */
30
+ export declare function hash(x: number, y: number, s?: number): number;
31
+ export declare function clamp(v: number, a: number, b: number): number;
32
+ /** Smoothstep on [0, 1], clamped. */
33
+ export declare function smooth(t: number): number;
34
+ /** 1D value noise in [0, 1). */
35
+ export declare function noise1(x: number, seed: number): number;
36
+ /** Two octaves of value noise: a ridge line `amp` tall over `scale` cells. */
37
+ export declare function ridge(x: number, seed: number, scale: number, amp: number): number;
38
+ /** A colour as scenes write it: a `"#hex"` / `rgb()` string or a packed int. */
39
+ export type Colour = string | number;
40
+ /** `#rgb`, `#rrggbb` or `rgb()` → `0xRRGGBB`; a packed int passes through; anything else → -1. */
41
+ export declare function parseColour(c: Colour): number;
42
+ /** Linear mix of two colours, channels truncated as the prototype's `rgb()` did. */
43
+ export declare function mixHex(a: Colour, b: Colour, t: number): number;
44
+ /** Gradient through `[position, colour]` stops at `t` in [0, 1]. */
45
+ export declare function grad(stops: readonly (readonly [number, Colour])[], t: number): number;
46
+ /** Packed colour → cached `#rrggbb`. */
47
+ export declare function cssOf(c: number): string;
48
+ /** sRGB channel 0–255 → linear light 0–1 (lookup table). */
49
+ export declare function srgbToLinear(c8: number): number;
50
+ /** Linear light → extended-sRGB encoded value; keeps going above 1 for HDR. */
51
+ export declare function encodeExt(v: number): number;
52
+ export interface PixelGrid {
53
+ cols: number;
54
+ rows: number;
55
+ /** -1 = empty, else 0xRRGGBB — what the lens shows. */
56
+ color: Int32Array;
57
+ /** Dot alpha outside the lens (0 = no dot). */
58
+ inkA: Float32Array;
59
+ /** 1 = colour shown outside the lens too. */
60
+ lit: Uint8Array;
61
+ /** HDR multiple of SDR white, 0 = SDR only. */
62
+ glow: Float32Array;
63
+ /** Emitter halo radius in cells (0 = not an emitter). */
64
+ halo: Float32Array;
65
+ /** Halo colour override for the HDR layer, -1 = none. */
66
+ hcol: Int32Array;
67
+ /**
68
+ * Soft golden halo radius in cells, HDR only (0 = none). The one exception to
69
+ * the hard-square rule, kept for the lit windows of houses.
70
+ */
71
+ soft: Float32Array;
72
+ /** Flat `[x, y, colour, glow, haloCells] × n`. */
73
+ emitters: number[];
74
+ /**
75
+ * The copy corner, in cells from the top-left (0 = none): lens cells inside
76
+ * it are not boosted, so text over the picture keeps SDR contrast. Set by
77
+ * the painter each frame.
78
+ */
79
+ copyW: number;
80
+ copyH: number;
81
+ /** Centre of the sun (or moon) in cells, -1 when the frame has none. Set by the painter. */
82
+ sunX: number;
83
+ sunY: number;
84
+ }
85
+ export declare const INK_ALPHA_NIGHT = 0.6;
86
+ export declare const INK_ALPHA_DAY = 0.85;
87
+ /** Glow of every cell revealed by the lens. */
88
+ export declare const LENS_BOOST = 1.6;
89
+ /** Glow of a cell written with `l = true`. */
90
+ export declare const LIT_GLOW = 1.5;
91
+ /** Highest glow a cell may carry (≈ 1000 nits over a 203-nit SDR white). */
92
+ export declare const GLOW_PEAK = 4.9;
93
+ export declare const MAX_CELLS = 72000;
94
+ export declare const MAX_DPR = 2;
95
+ /** Backing-store budget per canvas, device px (2048²): past it the backing drops to DPR 1. */
96
+ export declare const MAX_BACKING_PX = 4200000;
97
+ export declare const MIN_CELL = 4;
98
+ export declare const MAX_CELL = 32;
99
+ export declare function createGrid(cols: number, rows: number): PixelGrid;
100
+ export declare function clearGrid(g: PixelGrid): void;
101
+ /**
102
+ * The prototype's `put()`. `a` is the dot alpha outside the lens. `l`: false =
103
+ * plain cell, true = lit (colour outside the lens, glow {@link LIT_GLOW}),
104
+ * number = lit and HDR at that multiple of SDR white (clamped to
105
+ * {@link GLOW_PEAK}). `hl > 0` with a numeric `l` registers an emitter whose
106
+ * dithered halo `pixelHalos` adds. Out-of-bounds cells are ignored.
107
+ */
108
+ export declare function writeCell(g: PixelGrid, x: number, y: number, c: Colour, a?: number, l?: boolean | number, hl?: number): void;
109
+ /**
110
+ * Around every emitter, light neighbouring cells as hard squares, Bayer
111
+ * dithered so density and brightness fall with distance. No blur anywhere.
112
+ */
113
+ export declare function pixelHalos(g: PixelGrid): void;
114
+ /** Duration of a day / night wave, ms (ease in-out cubic). */
115
+ export declare const WAVE_MS = 1300;
116
+ /** Thickness of the dithered halo that leads the wave front, in cells. */
117
+ export declare const WAVE_HALO_CELLS = 9;
118
+ /** Width of the dithered HDR glow on each side of the halo band, in cells. */
119
+ export declare const WAVE_GLOW_CELLS = 7;
120
+ /** Halo colours from the sparse outer fringe to the dense inner rim. */
121
+ export declare const WAVE_PALETTE: readonly number[];
122
+ export declare function easeInOutCubic(t: number): number;
123
+ /** Glow of a halo cell at depth D (1 = inner rim, 0 = outer fringe). */
124
+ export declare function waveGlow(D: number): number;
125
+ /**
126
+ * Glow of a cell in the band around the halo, `d` in [0, 1) from the halo edge
127
+ * outward, or 0 when the Bayer threshold leaves it dark: density `(1 − d)^1.7`.
128
+ */
129
+ export declare function waveBandGlow(x: number, y: number, d: number, inner: boolean): number;
130
+ /** Radius (cells) at which a front from (ox, oy) has passed every cell, halo included. */
131
+ export declare function waveCover(ox: number, oy: number, cols: number, rows: number): number;
132
+ /**
133
+ * Composites one wave frame into `cur` (the old picture): cells the front has
134
+ * passed (`dist < R − halo`) take `next`'s content, the halo band is
135
+ * Bayer-dithered with `D^0.7` and lit at {@link waveGlow} (SDR inside the copy
136
+ * corner), the rest keeps the old picture. Emitters follow their side.
137
+ * `side[i]` is set to 1 for cells on the new side, 0 elsewhere.
138
+ */
139
+ export declare function composeWave(cur: PixelGrid, next: PixelGrid, side: Uint8Array, ox: number, oy: number, R: number): void;
140
+ export interface Lens {
141
+ x: number;
142
+ y: number;
143
+ tx: number;
144
+ ty: number;
145
+ r: number;
146
+ tr: number;
147
+ }
148
+ export declare function createLens(): Lens;
149
+ /**
150
+ * Moves the lens toward its target, frame-rate independent (`k = 1 − 0.6^(dt/16.667)`;
151
+ * the radius opens 1.3× and closes 0.7× as fast). `snap` jumps to the target.
152
+ * Returns whether it is still moving.
153
+ */
154
+ export declare function stepLens(l: Lens, dt: number, snap: boolean): boolean;
155
+ /** Whether a cell is revealed: inside the radius, with a Bayer-dithered rim. */
156
+ export declare function inLens(l: Lens, x: number, y: number): boolean;
157
+ export interface PaintParams {
158
+ /** Grid pitch in CSS px. */
159
+ cell: number;
160
+ /** Dot edge in CSS px. */
161
+ dot: number;
162
+ dpr: number;
163
+ /** Resting dot colour, any canvas colour string. */
164
+ ink: string;
165
+ night: boolean;
166
+ /** During a wave: cells with `side[i] === 1` use `sideInk` at the ink alpha of `sideNight`. */
167
+ side?: Uint8Array | null;
168
+ sideNight?: boolean;
169
+ sideInk?: string;
170
+ /** Fills the canvas before the dots (the scene owns its background); null = transparent. */
171
+ surface?: string | null;
172
+ /** During a wave: whole cells on the new side are filled with it (a grid-aligned staircase). */
173
+ sideSurface?: string | null;
174
+ /** Backing-store size to clear, device px (defaults to `ctx.canvas`). */
175
+ width?: number;
176
+ height?: number;
177
+ }
178
+ /** Device-pixel origin of cell `x` (or row `y`); the HDR layer uses the same expression. */
179
+ export declare function cellOrigin(x: number, cell: number, dpr: number): number;
180
+ /**
181
+ * One 2D pass over the grid. Raises the glow of lens cells to at least
182
+ * {@link LENS_BOOST} (mutates `g.glow`, as the HDR layer reads it next),
183
+ * except inside the copy corner (`g.copyW × g.copyH`).
184
+ */
185
+ export declare function paintGrid(ctx: CanvasRenderingContext2D, g: PixelGrid, lens: Lens, p: PaintParams): void;
186
+ /**
187
+ * Clamps `cell` to [4, 32] and `dot` to [1, cell], then grows the cell on big
188
+ * boxes so the grid stays under {@link MAX_CELLS}; the dot keeps its ratio.
189
+ */
190
+ export declare function effectiveCell(cssW: number, cssH: number, cell: number, dot: number): {
191
+ cell: number;
192
+ dot: number;
193
+ };
194
+ /**
195
+ * The backing-store DPR for a box: the device DPR (already capped at
196
+ * {@link MAX_DPR}), or 1 when that would exceed {@link MAX_BACKING_PX}. The
197
+ * canvas is then upscaled with `image-rendering: pixelated`, so the squares
198
+ * stay hard.
199
+ */
200
+ export declare function backingDpr(cssW: number, cssH: number, deviceDpr: number): number;
201
+ /** Paints one frame of a scene into the grid. Must be synchronous. */
202
+ export type ScenePainter = (t: number, g: PixelGrid, night: boolean) => void;
203
+ /** What the HDR layer reads after each painted frame (device px, live views — read synchronously). */
204
+ export interface PixelSceneFrame {
205
+ cols: number;
206
+ rows: number;
207
+ /** Backing-store size, device px. */
208
+ width: number;
209
+ height: number;
210
+ /** `cell × dpr`; a cell's origin is `round(x · cellCss · dpr)`. */
211
+ pitch: number;
212
+ /** Dot edge, device px: `round(dot · dpr)`. */
213
+ size: number;
214
+ cellCss: number;
215
+ dpr: number;
216
+ /** True when the backing is below the device resolution (see {@link backingDpr}). */
217
+ pixelated?: boolean;
218
+ color: Int32Array;
219
+ glow: Float32Array;
220
+ hcol: Int32Array;
221
+ /** Soft halo radius per cell, in cells (see {@link PixelGrid.soft}). */
222
+ soft: Float32Array;
223
+ }
224
+ export interface PixelSceneElements {
225
+ host: HTMLElement;
226
+ canvas: HTMLCanvasElement;
227
+ }
228
+ export interface PixelSceneOptions {
229
+ painter: ScenePainter;
230
+ night?: boolean;
231
+ cell?: number;
232
+ dot?: number;
233
+ lens?: boolean;
234
+ lensRadius?: number;
235
+ ink?: string;
236
+ paused?: boolean;
237
+ /** Animate a change of `night` as a wave from the sun (default true; never under reduced motion). */
238
+ wave?: boolean;
239
+ /** `[day, night]` background painted by the canvas; null = transparent (the host shows). */
240
+ surfaces?: readonly [string, string] | null;
241
+ /** `[day, night]` dot colours; null = `ink`. */
242
+ inks?: readonly [string, string] | null;
243
+ /** Override for tests; default = the live `prefers-reduced-motion` query. */
244
+ reducedMotion?: boolean;
245
+ /** HDR hook; a throwing callback is dropped and the 2D picture keeps going. */
246
+ onFrame?: ((f: PixelSceneFrame) => void) | null;
247
+ }
248
+ export interface PixelSceneEngine {
249
+ /** Absent or undefined keys are left untouched; `onFrame: null` clears the hook. */
250
+ setOptions(next: Partial<PixelSceneOptions>): void;
251
+ resize(): void;
252
+ destroy(): void;
253
+ }
254
+ export declare function normalizeLensRadius(r: number | undefined): number;
255
+ /** null when there is no 2D context (server, jsdom) — the component then keeps an inert canvas. */
256
+ export declare function createPixelScene(el: PixelSceneElements, options: PixelSceneOptions): PixelSceneEngine | null;