@snowcone-app/loaders 0.0.0-stage → 0.3.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.
@@ -0,0 +1,137 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import { Rect, LoaderProps } from '../index.cjs';
3
+ import 'react';
4
+
5
+ /**
6
+ * The beam, framework-free: a soft line of light that glides back and forth over the part of the picture that is
7
+ * changing while a render is on the way, then makes one last pass across and fades once the picture has caught up.
8
+ *
9
+ * `BeamMotion` is the timing (pure: give it a clock, read the beam's place and opacity). `BeamEngine` draws it into
10
+ * a 2D canvas, cut to a soft mask of the changing part (or the whole frame when none is known yet).
11
+ */
12
+
13
+ /** The beam fades in over this long. */
14
+ declare const BEAM_FADE_IN_MS = 450;
15
+ /** One sweep from one side to the other while loading. */
16
+ declare const BEAM_SWEEP_MS = 1150;
17
+ /** The last pass, once the picture has caught up. */
18
+ declare const BEAM_PASS_MS = 380;
19
+ /** The fade after the last pass. */
20
+ declare const BEAM_TAIL_MS = 150;
21
+ /** The longest dash to the nearer edge before the last pass (from the middle). */
22
+ declare const BEAM_RUSH_MAX_MS = 190;
23
+ /** Caught up → gone, at most: the dash, the last pass, the tail. A host's fallback timer should wait this long. */
24
+ declare const BEAM_FINISH_MS: number;
25
+ /** A newly learned area replaces the old one over this long (never a jump). */
26
+ declare const REGION_FADE_MS = 300;
27
+ /** The looks from the 1 Dec prototype: `beam` = "Just the beam" (light only, the default); `soft` = "Soft laser"
28
+ * (a faint haze and a trail, painted on); `prism` = the beam with thin rainbow fringes trailing it. */
29
+ type BeamLook = "beam" | "soft" | "prism";
30
+ /** The light's colour: `auto` = a light version of the colour of the part that changes (cool white until known). */
31
+ type BeamTone = "auto" | "cool" | "warm" | `${number},${number},${number}`;
32
+ interface BeamPosition {
33
+ /** Where the beam is across the area, 0 (left edge) to 1 (right edge). */
34
+ s: number;
35
+ /** Which way it moves. */
36
+ dir: 1 | -1;
37
+ /** Overall opacity, 0–1. */
38
+ alpha: number;
39
+ finishing: boolean;
40
+ /** The exit is over: nothing to draw, the host may unmount. */
41
+ done: boolean;
42
+ }
43
+ /** The beam's timing. Times are milliseconds on any monotonic clock (`performance.now()`). */
44
+ declare class BeamMotion {
45
+ private t0;
46
+ private ph0;
47
+ /** When the beam started (its fade-in runs from here). */
48
+ readonly bornAt: number;
49
+ private fin;
50
+ constructor(now: number);
51
+ get finishing(): boolean;
52
+ private loading;
53
+ private fadeIn;
54
+ at(now: number): BeamPosition;
55
+ /** The picture has caught up: dash to the nearer edge, one pass across, fade. Repeated calls change nothing. */
56
+ finish(now: number): void;
57
+ /** Behind again before the exit ended: carry on gliding from where the beam is, the way it was going. */
58
+ resume(now: number): void;
59
+ }
60
+ /** The part of the picture the beam stays on. */
61
+ interface BeamRegion {
62
+ /** Alpha mask in picture space (alpha = changes), drawn over the picture's rect; `null` = the whole frame. */
63
+ mask: CanvasImageSource | null;
64
+ /** The mask's box in picture space (0–1); `null` with no mask. */
65
+ box: {
66
+ x: number;
67
+ y: number;
68
+ w: number;
69
+ h: number;
70
+ } | null;
71
+ /** The colour of the changing part, `"r,g,b"`, for `tone: "auto"`. */
72
+ tone?: string;
73
+ /** How light the surface under the area is: `light` (a white cup) gets a painted coloured beam, `dark` light only. */
74
+ surface?: "light" | "dark";
75
+ }
76
+ interface BeamEngineOptions {
77
+ look?: BeamLook;
78
+ tone?: BeamTone;
79
+ /** `prefers-reduced-motion`: no gliding line, a still soft glow over the area instead. */
80
+ reducedMotion?: boolean;
81
+ }
82
+ /** Draws the beam into a 2D canvas the size of the frame. */
83
+ declare class BeamEngine {
84
+ readonly motion: BeamMotion;
85
+ readonly look: BeamLook;
86
+ private readonly tone;
87
+ private readonly reduced;
88
+ private prev;
89
+ private next;
90
+ private regionAt;
91
+ private maskLayer;
92
+ constructor(opts: BeamEngineOptions, now: number);
93
+ /** On a light surface the beam is painted (a coloured line); on a dark one it is light. Only once the area is known:
94
+ * over the whole frame (the first edit of a scene) a painted line would cross the background too, so it stays light. */
95
+ get onLight(): boolean;
96
+ /** How the canvas should blend over the picture: light only adds (`screen`), the soft laser and any beam on a
97
+ * light surface paint on. */
98
+ get blendMode(): "screen" | "normal";
99
+ /** A new area to stay on; the old one fades into it over {@link REGION_FADE_MS}. While the beam is still fading in
100
+ * from the whole frame, it takes the area at once: no glimpse of a beam across the whole picture first. */
101
+ setRegion(region: BeamRegion | null, now: number): void;
102
+ finish(now: number): void;
103
+ resume(now: number): void;
104
+ private mixWeight;
105
+ private rgb;
106
+ /** The beam's area in frame pixels: the region's box over the picture, or the picture's visible part. */
107
+ private area;
108
+ /**
109
+ * Draws one frame. `place` is where the picture lands in the frame (`fitRect`), `dpr` the device pixel ratio.
110
+ * Returns `true` once the exit is over (the canvas is cleared).
111
+ */
112
+ draw(ctx: CanvasRenderingContext2D, W: number, H: number, place: Rect, now: number, dpr?: number): boolean;
113
+ private maskOf;
114
+ }
115
+
116
+ /** How often the picture is compared with its first look while loading. */
117
+ declare const LEARN_EVERY_MS = 250;
118
+ interface BeamLoaderProps extends LoaderProps {
119
+ /** `"beam"` (default): light only. `"soft"`: a faint haze and a trail, painted on. `"prism"`: rainbow fringes. */
120
+ look?: BeamLook;
121
+ /** The light's colour. `"auto"` (default): a light version of the colour of the part that changes. */
122
+ tone?: BeamTone;
123
+ }
124
+ /**
125
+ * The beam loader: a soft line of light gliding over the part of the picture that is changing, while its next
126
+ * render is on the way; one last pass across and a fade once it has caught up.
127
+ *
128
+ * Fills its positioned parent (put it over the picture's `<img>`). It finds the part that changes by itself: give it
129
+ * `picture` (the `<img>` on screen) and a `maskKey` (the mockup id) and it compares frames, remembering the area per
130
+ * scene, so the next edit starts on the right part at once. Until it knows, it covers the whole picture.
131
+ *
132
+ * Machine-readable state: `data-sc-loader="beam"`, `data-sc-loader-phase` (`loading` | `finishing`),
133
+ * `data-sc-loader-mask` (`whole` | `learned` | `given`).
134
+ */
135
+ declare function BeamLoader({ visible, onExited, picture, maskKey, fit, mask, look, tone, className, style, }: BeamLoaderProps): react_jsx_runtime.JSX.Element;
136
+
137
+ export { BEAM_FADE_IN_MS, BEAM_FINISH_MS, BEAM_PASS_MS, BEAM_RUSH_MAX_MS, BEAM_SWEEP_MS, BEAM_TAIL_MS, BeamEngine, type BeamEngineOptions, BeamLoader, type BeamLoaderProps, type BeamLook, BeamMotion, type BeamPosition, type BeamRegion, type BeamTone, LEARN_EVERY_MS, REGION_FADE_MS };
@@ -0,0 +1,137 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import { Rect, LoaderProps } from '../index.js';
3
+ import 'react';
4
+
5
+ /**
6
+ * The beam, framework-free: a soft line of light that glides back and forth over the part of the picture that is
7
+ * changing while a render is on the way, then makes one last pass across and fades once the picture has caught up.
8
+ *
9
+ * `BeamMotion` is the timing (pure: give it a clock, read the beam's place and opacity). `BeamEngine` draws it into
10
+ * a 2D canvas, cut to a soft mask of the changing part (or the whole frame when none is known yet).
11
+ */
12
+
13
+ /** The beam fades in over this long. */
14
+ declare const BEAM_FADE_IN_MS = 450;
15
+ /** One sweep from one side to the other while loading. */
16
+ declare const BEAM_SWEEP_MS = 1150;
17
+ /** The last pass, once the picture has caught up. */
18
+ declare const BEAM_PASS_MS = 380;
19
+ /** The fade after the last pass. */
20
+ declare const BEAM_TAIL_MS = 150;
21
+ /** The longest dash to the nearer edge before the last pass (from the middle). */
22
+ declare const BEAM_RUSH_MAX_MS = 190;
23
+ /** Caught up → gone, at most: the dash, the last pass, the tail. A host's fallback timer should wait this long. */
24
+ declare const BEAM_FINISH_MS: number;
25
+ /** A newly learned area replaces the old one over this long (never a jump). */
26
+ declare const REGION_FADE_MS = 300;
27
+ /** The looks from the 1 Dec prototype: `beam` = "Just the beam" (light only, the default); `soft` = "Soft laser"
28
+ * (a faint haze and a trail, painted on); `prism` = the beam with thin rainbow fringes trailing it. */
29
+ type BeamLook = "beam" | "soft" | "prism";
30
+ /** The light's colour: `auto` = a light version of the colour of the part that changes (cool white until known). */
31
+ type BeamTone = "auto" | "cool" | "warm" | `${number},${number},${number}`;
32
+ interface BeamPosition {
33
+ /** Where the beam is across the area, 0 (left edge) to 1 (right edge). */
34
+ s: number;
35
+ /** Which way it moves. */
36
+ dir: 1 | -1;
37
+ /** Overall opacity, 0–1. */
38
+ alpha: number;
39
+ finishing: boolean;
40
+ /** The exit is over: nothing to draw, the host may unmount. */
41
+ done: boolean;
42
+ }
43
+ /** The beam's timing. Times are milliseconds on any monotonic clock (`performance.now()`). */
44
+ declare class BeamMotion {
45
+ private t0;
46
+ private ph0;
47
+ /** When the beam started (its fade-in runs from here). */
48
+ readonly bornAt: number;
49
+ private fin;
50
+ constructor(now: number);
51
+ get finishing(): boolean;
52
+ private loading;
53
+ private fadeIn;
54
+ at(now: number): BeamPosition;
55
+ /** The picture has caught up: dash to the nearer edge, one pass across, fade. Repeated calls change nothing. */
56
+ finish(now: number): void;
57
+ /** Behind again before the exit ended: carry on gliding from where the beam is, the way it was going. */
58
+ resume(now: number): void;
59
+ }
60
+ /** The part of the picture the beam stays on. */
61
+ interface BeamRegion {
62
+ /** Alpha mask in picture space (alpha = changes), drawn over the picture's rect; `null` = the whole frame. */
63
+ mask: CanvasImageSource | null;
64
+ /** The mask's box in picture space (0–1); `null` with no mask. */
65
+ box: {
66
+ x: number;
67
+ y: number;
68
+ w: number;
69
+ h: number;
70
+ } | null;
71
+ /** The colour of the changing part, `"r,g,b"`, for `tone: "auto"`. */
72
+ tone?: string;
73
+ /** How light the surface under the area is: `light` (a white cup) gets a painted coloured beam, `dark` light only. */
74
+ surface?: "light" | "dark";
75
+ }
76
+ interface BeamEngineOptions {
77
+ look?: BeamLook;
78
+ tone?: BeamTone;
79
+ /** `prefers-reduced-motion`: no gliding line, a still soft glow over the area instead. */
80
+ reducedMotion?: boolean;
81
+ }
82
+ /** Draws the beam into a 2D canvas the size of the frame. */
83
+ declare class BeamEngine {
84
+ readonly motion: BeamMotion;
85
+ readonly look: BeamLook;
86
+ private readonly tone;
87
+ private readonly reduced;
88
+ private prev;
89
+ private next;
90
+ private regionAt;
91
+ private maskLayer;
92
+ constructor(opts: BeamEngineOptions, now: number);
93
+ /** On a light surface the beam is painted (a coloured line); on a dark one it is light. Only once the area is known:
94
+ * over the whole frame (the first edit of a scene) a painted line would cross the background too, so it stays light. */
95
+ get onLight(): boolean;
96
+ /** How the canvas should blend over the picture: light only adds (`screen`), the soft laser and any beam on a
97
+ * light surface paint on. */
98
+ get blendMode(): "screen" | "normal";
99
+ /** A new area to stay on; the old one fades into it over {@link REGION_FADE_MS}. While the beam is still fading in
100
+ * from the whole frame, it takes the area at once: no glimpse of a beam across the whole picture first. */
101
+ setRegion(region: BeamRegion | null, now: number): void;
102
+ finish(now: number): void;
103
+ resume(now: number): void;
104
+ private mixWeight;
105
+ private rgb;
106
+ /** The beam's area in frame pixels: the region's box over the picture, or the picture's visible part. */
107
+ private area;
108
+ /**
109
+ * Draws one frame. `place` is where the picture lands in the frame (`fitRect`), `dpr` the device pixel ratio.
110
+ * Returns `true` once the exit is over (the canvas is cleared).
111
+ */
112
+ draw(ctx: CanvasRenderingContext2D, W: number, H: number, place: Rect, now: number, dpr?: number): boolean;
113
+ private maskOf;
114
+ }
115
+
116
+ /** How often the picture is compared with its first look while loading. */
117
+ declare const LEARN_EVERY_MS = 250;
118
+ interface BeamLoaderProps extends LoaderProps {
119
+ /** `"beam"` (default): light only. `"soft"`: a faint haze and a trail, painted on. `"prism"`: rainbow fringes. */
120
+ look?: BeamLook;
121
+ /** The light's colour. `"auto"` (default): a light version of the colour of the part that changes. */
122
+ tone?: BeamTone;
123
+ }
124
+ /**
125
+ * The beam loader: a soft line of light gliding over the part of the picture that is changing, while its next
126
+ * render is on the way; one last pass across and a fade once it has caught up.
127
+ *
128
+ * Fills its positioned parent (put it over the picture's `<img>`). It finds the part that changes by itself: give it
129
+ * `picture` (the `<img>` on screen) and a `maskKey` (the mockup id) and it compares frames, remembering the area per
130
+ * scene, so the next edit starts on the right part at once. Until it knows, it covers the whole picture.
131
+ *
132
+ * Machine-readable state: `data-sc-loader="beam"`, `data-sc-loader-phase` (`loading` | `finishing`),
133
+ * `data-sc-loader-mask` (`whole` | `learned` | `given`).
134
+ */
135
+ declare function BeamLoader({ visible, onExited, picture, maskKey, fit, mask, look, tone, className, style, }: BeamLoaderProps): react_jsx_runtime.JSX.Element;
136
+
137
+ export { BEAM_FADE_IN_MS, BEAM_FINISH_MS, BEAM_PASS_MS, BEAM_RUSH_MAX_MS, BEAM_SWEEP_MS, BEAM_TAIL_MS, BeamEngine, type BeamEngineOptions, BeamLoader, type BeamLoaderProps, type BeamLook, BeamMotion, type BeamPosition, type BeamRegion, type BeamTone, LEARN_EVERY_MS, REGION_FADE_MS };