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.
- package/README.md +9 -6
- package/dist/components/magnetic-field/MagnetPuck.vue.d.ts +51 -0
- package/dist/components/magnetic-field/MagnetPuck.vue.js +7 -0
- package/dist/components/magnetic-field/MagnetPuck.vue2.js +191 -0
- package/dist/components/magnetic-field/MagneticField.vue.d.ts +39 -0
- package/dist/components/magnetic-field/MagneticField.vue.js +7 -0
- package/dist/components/magnetic-field/MagneticField.vue2.js +157 -0
- package/dist/components/magnetic-field/MagneticItem.vue.d.ts +28 -0
- package/dist/components/magnetic-field/MagneticItem.vue.js +7 -0
- package/dist/components/magnetic-field/MagneticItem.vue2.js +72 -0
- package/dist/components/magnetic-field/index.d.ts +10 -0
- package/dist/components/magnetic-field/magnetic-field-core.d.ts +163 -0
- package/dist/components/magnetic-field/magnetic-field-core.js +534 -0
- package/dist/components/magnetic-field/magnetic-field-source.d.ts +58 -0
- package/dist/components/magnetic-field/magnetic-field-source.js +58 -0
- package/dist/components/magnetic-field/types.d.ts +14 -0
- package/dist/components/magnetic-field/types.js +5 -0
- package/dist/components/pixel-scene/PixelScene.vue.d.ts +60 -0
- package/dist/components/pixel-scene/PixelScene.vue.js +184 -0
- package/dist/components/pixel-scene/PixelScene.vue2.js +4 -0
- package/dist/components/pixel-scene/index.d.ts +4 -0
- package/dist/components/pixel-scene/pixel-scene-core.d.ts +256 -0
- package/dist/components/pixel-scene/pixel-scene-core.js +878 -0
- package/dist/components/pixel-scene/pixel-scene-hdr.d.ts +68 -0
- package/dist/components/pixel-scene/pixel-scene-hdr.js +312 -0
- package/dist/components/pixel-scene/pixel-scene-scenes.d.ts +31 -0
- package/dist/components/pixel-scene/pixel-scene-scenes.js +1074 -0
- package/dist/components/story-thread/StoryNode.vue.d.ts +11 -0
- package/dist/components/story-thread/StoryNode.vue.js +7 -0
- package/dist/components/story-thread/StoryNode.vue2.js +23 -0
- package/dist/components/story-thread/StoryThread.vue.d.ts +56 -0
- package/dist/components/story-thread/StoryThread.vue.js +7 -0
- package/dist/components/story-thread/StoryThread.vue2.js +103 -0
- package/dist/components/story-thread/index.d.ts +5 -0
- package/dist/components/story-thread/story-thread-core.d.ts +119 -0
- package/dist/components/story-thread/story-thread-core.js +491 -0
- package/dist/components/story-thread/types.d.ts +1 -0
- package/dist/components/sun-switch/SunSwitch.vue.d.ts +61 -0
- package/dist/components/sun-switch/SunSwitch.vue.js +7 -0
- package/dist/components/sun-switch/SunSwitch.vue2.js +559 -0
- package/dist/components/sun-switch/index.d.ts +4 -0
- package/dist/components/sun-switch/pixel-wave-core.d.ts +82 -0
- package/dist/components/sun-switch/pixel-wave-core.js +508 -0
- package/dist/components/sun-switch/sun-switch-core.d.ts +251 -0
- package/dist/components/sun-switch/sun-switch-core.js +546 -0
- package/dist/components/sun-switch/sun-switch-hdr.d.ts +70 -0
- package/dist/components/sun-switch/sun-switch-hdr.js +311 -0
- package/dist/components/tracing-beam/TracingBeam.vue.d.ts +20 -1
- package/dist/components/tracing-beam/TracingBeam.vue.js +5 -164
- package/dist/components/tracing-beam/TracingBeam.vue2.js +168 -1
- package/dist/index.d.ts +4 -0
- package/dist/index.js +190 -164
- package/dist/styles.css +499 -0
- package/package.json +1 -1
|
@@ -0,0 +1,491 @@
|
|
|
1
|
+
const STORY_THREAD_DEFAULTS = {
|
|
2
|
+
layout: "auto",
|
|
3
|
+
lead: 0.7,
|
|
4
|
+
tension: 0.55,
|
|
5
|
+
dash: "dotted",
|
|
6
|
+
head: true
|
|
7
|
+
};
|
|
8
|
+
const STORY_THREAD_HORIZONTAL_QUERY = "(min-width: 900px) and (min-height: 520px)";
|
|
9
|
+
const SVG_NS = "http://www.w3.org/2000/svg";
|
|
10
|
+
const NO_DRAG = "a, button, input, textarea, select, label, [contenteditable], [data-no-drag]";
|
|
11
|
+
const OWNS_ARROWS = [
|
|
12
|
+
"input",
|
|
13
|
+
"textarea",
|
|
14
|
+
"select",
|
|
15
|
+
"[contenteditable]",
|
|
16
|
+
"button",
|
|
17
|
+
"a[href]",
|
|
18
|
+
"[tabindex]",
|
|
19
|
+
...[
|
|
20
|
+
"tab",
|
|
21
|
+
"menuitem",
|
|
22
|
+
"menuitemcheckbox",
|
|
23
|
+
"menuitemradio",
|
|
24
|
+
"radio",
|
|
25
|
+
"option",
|
|
26
|
+
"slider",
|
|
27
|
+
"spinbutton",
|
|
28
|
+
"scrollbar",
|
|
29
|
+
"gridcell",
|
|
30
|
+
"treeitem",
|
|
31
|
+
"listbox",
|
|
32
|
+
"combobox",
|
|
33
|
+
"textbox"
|
|
34
|
+
].map((role) => `[role="${role}"]`)
|
|
35
|
+
].join(", ");
|
|
36
|
+
const SAMPLE_STEP = 6;
|
|
37
|
+
function clamp(n, lo, hi) {
|
|
38
|
+
return Math.max(lo, Math.min(hi, n));
|
|
39
|
+
}
|
|
40
|
+
function curvePath(pts, axis, tension = 0.55) {
|
|
41
|
+
const first = pts[0];
|
|
42
|
+
if (!first || pts.length < 2) return "";
|
|
43
|
+
const r = (n) => Math.round(n * 100) / 100;
|
|
44
|
+
let d = `M ${r(first.x)} ${r(first.y)}`;
|
|
45
|
+
let q = first;
|
|
46
|
+
for (const p of pts.slice(1)) {
|
|
47
|
+
if (axis === "x") {
|
|
48
|
+
const dx = (p.x - q.x) * tension;
|
|
49
|
+
d += ` C ${r(q.x + dx)} ${r(q.y)} ${r(p.x - dx)} ${r(p.y)} ${r(p.x)} ${r(p.y)}`;
|
|
50
|
+
} else {
|
|
51
|
+
const dy = (p.y - q.y) * tension;
|
|
52
|
+
d += ` C ${r(q.x)} ${r(q.y + dy)} ${r(p.x)} ${r(p.y - dy)} ${r(p.x)} ${r(p.y)}`;
|
|
53
|
+
}
|
|
54
|
+
q = p;
|
|
55
|
+
}
|
|
56
|
+
return d;
|
|
57
|
+
}
|
|
58
|
+
function resolveSegments(segments, order, points) {
|
|
59
|
+
const source = segments.length > 0 ? segments : [{ nodes: order }];
|
|
60
|
+
const out = [];
|
|
61
|
+
for (const seg of source) {
|
|
62
|
+
const ids = [];
|
|
63
|
+
const pts = [];
|
|
64
|
+
for (const id of seg.nodes) {
|
|
65
|
+
const pt = points[id];
|
|
66
|
+
if (!pt) continue;
|
|
67
|
+
ids.push(id);
|
|
68
|
+
pts.push(pt);
|
|
69
|
+
}
|
|
70
|
+
if (ids.length < 2) continue;
|
|
71
|
+
out.push({ ids, points: pts, color: seg.color });
|
|
72
|
+
}
|
|
73
|
+
return out;
|
|
74
|
+
}
|
|
75
|
+
function segmentSpan(points, axis) {
|
|
76
|
+
const first = points[0];
|
|
77
|
+
const last = points[points.length - 1];
|
|
78
|
+
return first && last ? [first[axis], last[axis]] : [0, 0];
|
|
79
|
+
}
|
|
80
|
+
function spanProgress(tip, span) {
|
|
81
|
+
return clamp((tip - span[0]) / Math.max(1, span[1] - span[0]), 0, 1);
|
|
82
|
+
}
|
|
83
|
+
function tipPosition(pos, viewport, lead) {
|
|
84
|
+
return pos + viewport * clamp(lead, 0, 1);
|
|
85
|
+
}
|
|
86
|
+
function panTip(pan, maxPan, viewportWidth, trackWidth, lead) {
|
|
87
|
+
if (maxPan <= 0) return trackWidth;
|
|
88
|
+
const start = viewportWidth * clamp(lead, 0, 1);
|
|
89
|
+
return start + clamp(pan, 0, maxPan) / maxPan * (trackWidth - start);
|
|
90
|
+
}
|
|
91
|
+
function spacerHeight(trackWidth, viewportWidth, viewportHeight) {
|
|
92
|
+
return Math.max(0, trackWidth - viewportWidth) + viewportHeight;
|
|
93
|
+
}
|
|
94
|
+
function clampPan(scrolled, trackWidth, viewportWidth) {
|
|
95
|
+
return clamp(scrolled, 0, Math.max(0, trackWidth - viewportWidth));
|
|
96
|
+
}
|
|
97
|
+
function keyStep(viewportWidth, dir) {
|
|
98
|
+
return dir * viewportWidth * 0.85;
|
|
99
|
+
}
|
|
100
|
+
function dashPattern(dash) {
|
|
101
|
+
if (dash === "dashed") return "10 12";
|
|
102
|
+
if (dash === "dotted") return "0.5 11";
|
|
103
|
+
return null;
|
|
104
|
+
}
|
|
105
|
+
function reachedIds(points, tip, axis) {
|
|
106
|
+
const out = /* @__PURE__ */ new Set();
|
|
107
|
+
for (const [id, pt] of Object.entries(points)) if (pt[axis] <= tip) out.add(id);
|
|
108
|
+
return out;
|
|
109
|
+
}
|
|
110
|
+
function lengthAtAxis(samples, at) {
|
|
111
|
+
const first = samples[0];
|
|
112
|
+
const last = samples[samples.length - 1];
|
|
113
|
+
if (!first || !last) return 0;
|
|
114
|
+
if (at <= first[1]) return first[0];
|
|
115
|
+
if (at >= last[1]) return last[0];
|
|
116
|
+
let lo = 0;
|
|
117
|
+
let hi = samples.length - 1;
|
|
118
|
+
while (hi - lo > 1) {
|
|
119
|
+
const mid = lo + hi >> 1;
|
|
120
|
+
if ((samples[mid]?.[1] ?? Infinity) <= at) lo = mid;
|
|
121
|
+
else hi = mid;
|
|
122
|
+
}
|
|
123
|
+
const [l0, a0] = samples[lo] ?? first;
|
|
124
|
+
const [l1, a1] = samples[hi] ?? last;
|
|
125
|
+
return a1 === a0 ? l0 : l0 + (at - a0) / (a1 - a0) * (l1 - l0);
|
|
126
|
+
}
|
|
127
|
+
let instances = 0;
|
|
128
|
+
function scrollParent(el) {
|
|
129
|
+
let node = el.parentElement;
|
|
130
|
+
while (node && node !== document.body && node !== document.documentElement) {
|
|
131
|
+
const oy = getComputedStyle(node).overflowY;
|
|
132
|
+
if (oy === "auto" || oy === "scroll" || oy === "overlay") return node;
|
|
133
|
+
node = node.parentElement;
|
|
134
|
+
}
|
|
135
|
+
return null;
|
|
136
|
+
}
|
|
137
|
+
function createStoryThread(root, viewport, track, svg, initial = {}) {
|
|
138
|
+
const opts = {
|
|
139
|
+
layout: STORY_THREAD_DEFAULTS.layout,
|
|
140
|
+
segments: [],
|
|
141
|
+
lead: STORY_THREAD_DEFAULTS.lead,
|
|
142
|
+
tension: STORY_THREAD_DEFAULTS.tension,
|
|
143
|
+
dash: STORY_THREAD_DEFAULTS.dash,
|
|
144
|
+
head: STORY_THREAD_DEFAULTS.head,
|
|
145
|
+
reducedMotion: false,
|
|
146
|
+
...initial
|
|
147
|
+
};
|
|
148
|
+
const uid = `st${++instances}`;
|
|
149
|
+
const win = root.ownerDocument.defaultView ?? window;
|
|
150
|
+
const scroller = scrollParent(root);
|
|
151
|
+
const query = win.matchMedia ? win.matchMedia(STORY_THREAD_HORIZONTAL_QUERY) : null;
|
|
152
|
+
let axis = "y";
|
|
153
|
+
let nodes = {};
|
|
154
|
+
let points = {};
|
|
155
|
+
let drawn = [];
|
|
156
|
+
let threaded = {};
|
|
157
|
+
let reached = /* @__PURE__ */ new Set();
|
|
158
|
+
let primed = false;
|
|
159
|
+
let frame = 0;
|
|
160
|
+
let measureFrame = 0;
|
|
161
|
+
let pan = -1;
|
|
162
|
+
let maxPan = 0;
|
|
163
|
+
let viewW = 0;
|
|
164
|
+
let viewH = 0;
|
|
165
|
+
let trackLength = 0;
|
|
166
|
+
let destroyed = false;
|
|
167
|
+
const horizontal = () => opts.layout === "horizontal" || opts.layout === "auto" && (query?.matches ?? false);
|
|
168
|
+
function scrollerBox() {
|
|
169
|
+
if (!scroller) return { top: 0, height: win.innerHeight, width: win.innerWidth };
|
|
170
|
+
const r = scroller.getBoundingClientRect();
|
|
171
|
+
return {
|
|
172
|
+
top: r.top + scroller.clientTop,
|
|
173
|
+
height: scroller.clientHeight,
|
|
174
|
+
width: scroller.clientWidth
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
function scrollBy(dy, smooth = false) {
|
|
178
|
+
const behavior = smooth && !opts.reducedMotion ? "smooth" : "auto";
|
|
179
|
+
if (scroller) scroller.scrollBy({ top: dy, behavior });
|
|
180
|
+
else win.scrollBy({ top: dy, behavior });
|
|
181
|
+
}
|
|
182
|
+
function el(name, attrs) {
|
|
183
|
+
const node = root.ownerDocument.createElementNS(SVG_NS, name);
|
|
184
|
+
for (const [k, v] of Object.entries(attrs)) node.setAttribute(k, v);
|
|
185
|
+
return node;
|
|
186
|
+
}
|
|
187
|
+
function measure() {
|
|
188
|
+
measureFrame = 0;
|
|
189
|
+
if (destroyed) return;
|
|
190
|
+
const isH = horizontal();
|
|
191
|
+
axis = isH ? "x" : "y";
|
|
192
|
+
root.dataset.layout = isH ? "horizontal" : "vertical";
|
|
193
|
+
const box = scrollerBox();
|
|
194
|
+
root.style.setProperty("--st-vh", `${box.height}px`);
|
|
195
|
+
track.style.transform = "";
|
|
196
|
+
const trackRect = track.getBoundingClientRect();
|
|
197
|
+
const trackW = track.offsetWidth;
|
|
198
|
+
const trackH = track.offsetHeight;
|
|
199
|
+
viewW = isH ? viewport.clientWidth || box.width : box.width;
|
|
200
|
+
viewH = box.height;
|
|
201
|
+
maxPan = isH ? Math.max(0, trackW - viewW) : 0;
|
|
202
|
+
trackLength = trackW;
|
|
203
|
+
root.style.height = isH ? `${spacerHeight(trackW, viewW, viewH)}px` : "";
|
|
204
|
+
nodes = {};
|
|
205
|
+
points = {};
|
|
206
|
+
const order = [];
|
|
207
|
+
for (const node of Array.from(track.querySelectorAll("[data-story-node]"))) {
|
|
208
|
+
const id = node.dataset.storyNode;
|
|
209
|
+
if (!id || nodes[id]) continue;
|
|
210
|
+
const r = node.getBoundingClientRect();
|
|
211
|
+
nodes[id] = node;
|
|
212
|
+
points[id] = {
|
|
213
|
+
x: r.left - trackRect.left + r.width / 2,
|
|
214
|
+
y: r.top - trackRect.top + r.height / 2
|
|
215
|
+
};
|
|
216
|
+
order.push(id);
|
|
217
|
+
}
|
|
218
|
+
svg.setAttribute("viewBox", `0 0 ${Math.max(1, trackW)} ${Math.max(1, trackH)}`);
|
|
219
|
+
svg.setAttribute("width", String(Math.max(1, trackW)));
|
|
220
|
+
svg.setAttribute("height", String(Math.max(1, trackH)));
|
|
221
|
+
while (svg.firstChild) svg.removeChild(svg.firstChild);
|
|
222
|
+
const defs = el("defs", {});
|
|
223
|
+
svg.appendChild(defs);
|
|
224
|
+
const ghosts = el("g", { class: "st-ghosts" });
|
|
225
|
+
const brights = el("g", { class: "st-brights" });
|
|
226
|
+
const heads = el("g", { class: "st-heads" });
|
|
227
|
+
svg.append(ghosts, brights, heads);
|
|
228
|
+
const dash = dashPattern(opts.dash);
|
|
229
|
+
drawn = resolveSegments(opts.segments, order, points).map((seg, i) => {
|
|
230
|
+
const d = curvePath(seg.points, axis, opts.tension);
|
|
231
|
+
const colour = seg.color ? { style: `--st-seg: ${seg.color}` } : {};
|
|
232
|
+
const ghost = el("path", {
|
|
233
|
+
class: "st-ghost",
|
|
234
|
+
d,
|
|
235
|
+
...dash ? { "stroke-dasharray": dash } : {}
|
|
236
|
+
});
|
|
237
|
+
const maskId = `${uid}-m${i}`;
|
|
238
|
+
const mask = el("mask", { id: maskId, maskUnits: "userSpaceOnUse" });
|
|
239
|
+
const maskPath = el("path", { class: "st-mask", d });
|
|
240
|
+
mask.appendChild(maskPath);
|
|
241
|
+
defs.appendChild(mask);
|
|
242
|
+
const bright = el("path", {
|
|
243
|
+
class: "st-bright",
|
|
244
|
+
d,
|
|
245
|
+
mask: `url(#${maskId})`,
|
|
246
|
+
...dash ? { "stroke-dasharray": dash } : {},
|
|
247
|
+
...colour
|
|
248
|
+
});
|
|
249
|
+
const glowId = `${uid}-g${i}`;
|
|
250
|
+
const glow = el("radialGradient", { id: glowId, class: "st-glow", ...colour });
|
|
251
|
+
glow.append(
|
|
252
|
+
el("stop", { class: "st-glow-core", offset: "0" }),
|
|
253
|
+
el("stop", { class: "st-glow-edge", offset: "1" })
|
|
254
|
+
);
|
|
255
|
+
defs.appendChild(glow);
|
|
256
|
+
const head = el("g", { class: "st-head", ...colour });
|
|
257
|
+
head.append(
|
|
258
|
+
el("circle", { class: "st-head-glow", r: "18", fill: `url(#${glowId})` }),
|
|
259
|
+
el("circle", { class: "st-head-dot", r: "3.5" })
|
|
260
|
+
);
|
|
261
|
+
ghosts.appendChild(ghost);
|
|
262
|
+
brights.appendChild(bright);
|
|
263
|
+
heads.appendChild(head);
|
|
264
|
+
const length = typeof bright.getTotalLength === "function" ? bright.getTotalLength() : 0;
|
|
265
|
+
const samples = [];
|
|
266
|
+
if (length > 0 && typeof bright.getPointAtLength === "function") {
|
|
267
|
+
const n = Math.max(2, Math.ceil(length / SAMPLE_STEP));
|
|
268
|
+
let prev = -Infinity;
|
|
269
|
+
for (let k = 0; k <= n; k++) {
|
|
270
|
+
const l = length * k / n;
|
|
271
|
+
prev = Math.max(prev, bright.getPointAtLength(l)[axis]);
|
|
272
|
+
samples.push([l, prev]);
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
maskPath.setAttribute("stroke-dasharray", `${length} ${length + 1}`);
|
|
276
|
+
maskPath.setAttribute("stroke-dashoffset", String(length));
|
|
277
|
+
return {
|
|
278
|
+
ids: seg.ids,
|
|
279
|
+
span: segmentSpan(seg.points, axis),
|
|
280
|
+
length,
|
|
281
|
+
samples,
|
|
282
|
+
mask: maskPath,
|
|
283
|
+
head,
|
|
284
|
+
headX: NaN,
|
|
285
|
+
headY: NaN,
|
|
286
|
+
shown: false,
|
|
287
|
+
drawn: -1
|
|
288
|
+
};
|
|
289
|
+
});
|
|
290
|
+
threaded = {};
|
|
291
|
+
for (const seg of drawn) {
|
|
292
|
+
for (const id of seg.ids) {
|
|
293
|
+
const pt = points[id];
|
|
294
|
+
if (pt) threaded[id] = pt;
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
pan = -1;
|
|
298
|
+
primed = false;
|
|
299
|
+
paint();
|
|
300
|
+
}
|
|
301
|
+
function paint() {
|
|
302
|
+
frame = 0;
|
|
303
|
+
if (destroyed) return;
|
|
304
|
+
const box = scrollerBox();
|
|
305
|
+
let tip;
|
|
306
|
+
if (axis === "x") {
|
|
307
|
+
const scrolled = box.top - root.getBoundingClientRect().top;
|
|
308
|
+
const next2 = clampPan(scrolled, maxPan + viewW, viewW);
|
|
309
|
+
if (next2 !== pan) {
|
|
310
|
+
pan = next2;
|
|
311
|
+
track.style.transform = `translate3d(${-pan}px, 0, 0)`;
|
|
312
|
+
}
|
|
313
|
+
tip = panTip(pan, maxPan, viewW, trackLength, opts.lead);
|
|
314
|
+
} else {
|
|
315
|
+
if (track.style.transform) track.style.transform = "";
|
|
316
|
+
const pos = box.top - track.getBoundingClientRect().top;
|
|
317
|
+
tip = tipPosition(pos, viewH, opts.lead);
|
|
318
|
+
}
|
|
319
|
+
for (const seg of drawn) {
|
|
320
|
+
const p = spanProgress(tip, seg.span);
|
|
321
|
+
const len = p >= 1 ? seg.length : p <= 0 ? 0 : lengthAtAxis(seg.samples, tip);
|
|
322
|
+
if (Math.abs(len - seg.drawn) > 0.25) {
|
|
323
|
+
seg.drawn = len;
|
|
324
|
+
seg.mask.setAttribute("stroke-dashoffset", String(seg.length - len));
|
|
325
|
+
}
|
|
326
|
+
const show = opts.head && p > 0 && p < 1 && seg.length > 0;
|
|
327
|
+
if (show !== seg.shown) {
|
|
328
|
+
seg.shown = show;
|
|
329
|
+
seg.head.toggleAttribute("data-visible", show);
|
|
330
|
+
}
|
|
331
|
+
if (show) {
|
|
332
|
+
const pt = seg.mask.getPointAtLength(len);
|
|
333
|
+
if (pt.x !== seg.headX || pt.y !== seg.headY) {
|
|
334
|
+
seg.headX = pt.x;
|
|
335
|
+
seg.headY = pt.y;
|
|
336
|
+
seg.head.setAttribute("transform", `translate(${pt.x} ${pt.y})`);
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
const next = reachedIds(threaded, tip, axis);
|
|
341
|
+
for (const [id, node] of Object.entries(nodes)) {
|
|
342
|
+
const was = reached.has(id);
|
|
343
|
+
const now = next.has(id);
|
|
344
|
+
if (was === now && primed) continue;
|
|
345
|
+
node.toggleAttribute("data-reached", now);
|
|
346
|
+
if (now && !was && primed) opts.onReach?.(id);
|
|
347
|
+
}
|
|
348
|
+
reached = next;
|
|
349
|
+
primed = true;
|
|
350
|
+
}
|
|
351
|
+
function schedulePaint() {
|
|
352
|
+
if (!frame && !destroyed) frame = win.requestAnimationFrame(paint);
|
|
353
|
+
}
|
|
354
|
+
function scheduleMeasure() {
|
|
355
|
+
if (measureFrame || destroyed) return;
|
|
356
|
+
if (frame) {
|
|
357
|
+
win.cancelAnimationFrame(frame);
|
|
358
|
+
frame = 0;
|
|
359
|
+
}
|
|
360
|
+
measureFrame = win.requestAnimationFrame(measure);
|
|
361
|
+
}
|
|
362
|
+
function onWheel(e) {
|
|
363
|
+
if (axis !== "x" || e.ctrlKey) return;
|
|
364
|
+
if (Math.abs(e.deltaX) <= Math.abs(e.deltaY)) return;
|
|
365
|
+
const atStart = pan <= 0 && e.deltaX < 0;
|
|
366
|
+
const atEnd = pan >= maxPan && e.deltaX > 0;
|
|
367
|
+
if (atStart || atEnd) return;
|
|
368
|
+
e.preventDefault();
|
|
369
|
+
scrollBy(e.deltaX);
|
|
370
|
+
}
|
|
371
|
+
let drag = null;
|
|
372
|
+
function onPointerDown(e) {
|
|
373
|
+
if (axis !== "x" || e.pointerType !== "mouse" || e.button !== 0) return;
|
|
374
|
+
if (e.target?.closest?.(NO_DRAG)) return;
|
|
375
|
+
drag = { x: e.clientX, id: e.pointerId, moved: false };
|
|
376
|
+
}
|
|
377
|
+
function onPointerMove(e) {
|
|
378
|
+
if (!drag || e.pointerId !== drag.id) return;
|
|
379
|
+
if (e.buttons === 0) return endDrag();
|
|
380
|
+
const dx = e.clientX - drag.x;
|
|
381
|
+
if (!drag.moved && Math.abs(dx) < 3) return;
|
|
382
|
+
if (!drag.moved) {
|
|
383
|
+
drag.moved = true;
|
|
384
|
+
root.dataset.dragging = "";
|
|
385
|
+
root.setPointerCapture?.(e.pointerId);
|
|
386
|
+
}
|
|
387
|
+
drag.x = e.clientX;
|
|
388
|
+
scrollBy(-dx);
|
|
389
|
+
}
|
|
390
|
+
function endDrag() {
|
|
391
|
+
if (drag && root.hasPointerCapture?.(drag.id)) root.releasePointerCapture(drag.id);
|
|
392
|
+
drag = null;
|
|
393
|
+
delete root.dataset.dragging;
|
|
394
|
+
}
|
|
395
|
+
function onKeyDown(e) {
|
|
396
|
+
if (axis !== "x" || e.altKey || e.ctrlKey || e.metaKey || e.shiftKey) return;
|
|
397
|
+
if (e.key !== "ArrowRight" && e.key !== "ArrowLeft") return;
|
|
398
|
+
if (e.defaultPrevented) return;
|
|
399
|
+
const owner = e.target?.closest?.(OWNS_ARROWS);
|
|
400
|
+
if (owner && owner !== root && owner !== viewport && owner !== track) return;
|
|
401
|
+
e.preventDefault();
|
|
402
|
+
scrollBy(keyStep(viewW, e.key === "ArrowRight" ? 1 : -1), true);
|
|
403
|
+
}
|
|
404
|
+
function onFocusIn(e) {
|
|
405
|
+
if (axis !== "x") return;
|
|
406
|
+
const t = e.target;
|
|
407
|
+
if (!t || t === root || t === viewport) return;
|
|
408
|
+
const r = t.getBoundingClientRect();
|
|
409
|
+
const v = viewport.getBoundingClientRect();
|
|
410
|
+
if (r.left >= v.left && r.right <= v.right) return;
|
|
411
|
+
const at = r.left - track.getBoundingClientRect().left;
|
|
412
|
+
const target = clampPan(at - viewW * 0.1, maxPan + viewW, viewW);
|
|
413
|
+
viewport.scrollLeft = 0;
|
|
414
|
+
scrollBy(target - pan);
|
|
415
|
+
}
|
|
416
|
+
const scrollTarget = scroller ?? win;
|
|
417
|
+
scrollTarget.addEventListener("scroll", schedulePaint, { passive: true });
|
|
418
|
+
win.addEventListener("resize", scheduleMeasure);
|
|
419
|
+
root.addEventListener("wheel", onWheel, { passive: false });
|
|
420
|
+
root.addEventListener("pointerdown", onPointerDown);
|
|
421
|
+
root.addEventListener("pointermove", onPointerMove);
|
|
422
|
+
root.addEventListener("pointerup", endDrag);
|
|
423
|
+
root.addEventListener("pointercancel", endDrag);
|
|
424
|
+
root.addEventListener("keydown", onKeyDown);
|
|
425
|
+
root.addEventListener("focusin", onFocusIn);
|
|
426
|
+
query?.addEventListener?.("change", scheduleMeasure);
|
|
427
|
+
const resize = typeof ResizeObserver === "function" ? new ResizeObserver(scheduleMeasure) : null;
|
|
428
|
+
resize?.observe(track);
|
|
429
|
+
if (scroller) resize?.observe(scroller);
|
|
430
|
+
const moves = (r) => r.type !== "attributes" || r.attributeName === "data-story-node" || r.target.hasAttribute?.("data-story-node");
|
|
431
|
+
const mutations = typeof MutationObserver === "function" ? new MutationObserver((records) => {
|
|
432
|
+
if (records.some((r) => !svg.contains(r.target) && moves(r))) scheduleMeasure();
|
|
433
|
+
}) : null;
|
|
434
|
+
mutations?.observe(track, {
|
|
435
|
+
childList: true,
|
|
436
|
+
subtree: true,
|
|
437
|
+
attributeFilter: ["data-story-node", "class", "style"]
|
|
438
|
+
});
|
|
439
|
+
void root.ownerDocument.fonts?.ready?.then(scheduleMeasure);
|
|
440
|
+
measure();
|
|
441
|
+
return {
|
|
442
|
+
update(next) {
|
|
443
|
+
const geometry = next.layout !== void 0 && next.layout !== opts.layout || next.tension !== void 0 && next.tension !== opts.tension || next.dash !== void 0 && next.dash !== opts.dash || next.segments !== void 0 && next.segments !== opts.segments;
|
|
444
|
+
Object.assign(opts, next);
|
|
445
|
+
if (geometry) scheduleMeasure();
|
|
446
|
+
else schedulePaint();
|
|
447
|
+
},
|
|
448
|
+
refresh: scheduleMeasure,
|
|
449
|
+
destroy() {
|
|
450
|
+
destroyed = true;
|
|
451
|
+
if (frame) win.cancelAnimationFrame(frame);
|
|
452
|
+
if (measureFrame) win.cancelAnimationFrame(measureFrame);
|
|
453
|
+
scrollTarget.removeEventListener("scroll", schedulePaint);
|
|
454
|
+
win.removeEventListener("resize", scheduleMeasure);
|
|
455
|
+
root.removeEventListener("wheel", onWheel);
|
|
456
|
+
root.removeEventListener("pointerdown", onPointerDown);
|
|
457
|
+
root.removeEventListener("pointermove", onPointerMove);
|
|
458
|
+
root.removeEventListener("pointerup", endDrag);
|
|
459
|
+
root.removeEventListener("pointercancel", endDrag);
|
|
460
|
+
root.removeEventListener("keydown", onKeyDown);
|
|
461
|
+
root.removeEventListener("focusin", onFocusIn);
|
|
462
|
+
query?.removeEventListener?.("change", scheduleMeasure);
|
|
463
|
+
resize?.disconnect();
|
|
464
|
+
mutations?.disconnect();
|
|
465
|
+
while (svg.firstChild) svg.removeChild(svg.firstChild);
|
|
466
|
+
track.style.transform = "";
|
|
467
|
+
root.style.height = "";
|
|
468
|
+
root.style.removeProperty("--st-vh");
|
|
469
|
+
delete root.dataset.layout;
|
|
470
|
+
delete root.dataset.dragging;
|
|
471
|
+
for (const node of Object.values(nodes)) node.removeAttribute("data-reached");
|
|
472
|
+
}
|
|
473
|
+
};
|
|
474
|
+
}
|
|
475
|
+
export {
|
|
476
|
+
STORY_THREAD_DEFAULTS,
|
|
477
|
+
STORY_THREAD_HORIZONTAL_QUERY,
|
|
478
|
+
clampPan,
|
|
479
|
+
createStoryThread,
|
|
480
|
+
curvePath,
|
|
481
|
+
dashPattern,
|
|
482
|
+
keyStep,
|
|
483
|
+
lengthAtAxis,
|
|
484
|
+
panTip,
|
|
485
|
+
reachedIds,
|
|
486
|
+
resolveSegments,
|
|
487
|
+
segmentSpan,
|
|
488
|
+
spacerHeight,
|
|
489
|
+
spanProgress,
|
|
490
|
+
tipPosition
|
|
491
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type { StoryThreadSegment, StoryThreadLayout, StoryThreadDash, } from "./story-thread-core.js";
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type { HTMLAttributes } from "vue";
|
|
2
|
+
import type { SunPalette } from "./sun-switch-core.js";
|
|
3
|
+
export interface SunSwitchProps {
|
|
4
|
+
/** Day (true) or night (false). Two-way through `v-model:checked`. */
|
|
5
|
+
checked?: boolean;
|
|
6
|
+
/** Called with the new value from inside the view transition's update callback. */
|
|
7
|
+
onCheckedChange?: (checked: boolean) => void;
|
|
8
|
+
/** Sun radius in cells. The canvas is 2 × radius + 1 cells square. */
|
|
9
|
+
radius?: number;
|
|
10
|
+
/** Grid pitch in CSS pixels, shared by the sun, the wave front and its halo. */
|
|
11
|
+
cell?: number;
|
|
12
|
+
/** Size of each square dot in CSS pixels (at most `cell`). */
|
|
13
|
+
dot?: number;
|
|
14
|
+
/** Four colours from the top of the sun to the bottom. */
|
|
15
|
+
palette?: SunPalette;
|
|
16
|
+
/** Monochrome colour of the scene outside the lens. */
|
|
17
|
+
ink?: string;
|
|
18
|
+
/** Opacity of the ink sun at night. */
|
|
19
|
+
nightAlpha?: number;
|
|
20
|
+
/** Draws a few sparse rows of dots under the sun for the lens to reveal. */
|
|
21
|
+
horizon?: boolean;
|
|
22
|
+
/** On hover, a soft circular lens shows the true colours under the pointer. */
|
|
23
|
+
lens?: boolean;
|
|
24
|
+
/** Lens radius in cells. */
|
|
25
|
+
lensRadius?: number;
|
|
26
|
+
/** `document`: view transition over the page. `contained`: painted over `scope`. */
|
|
27
|
+
mode?: "document" | "contained";
|
|
28
|
+
/** The element the wave covers in contained mode. */
|
|
29
|
+
scope?: HTMLElement | null;
|
|
30
|
+
/** Colour of the old-state sheet in the fallback and contained paths. */
|
|
31
|
+
fill?: string;
|
|
32
|
+
/** Duration of the wave in milliseconds. */
|
|
33
|
+
duration?: number;
|
|
34
|
+
/** Thickness of the dithered halo leading the wave front, in cells. */
|
|
35
|
+
haloCells?: number;
|
|
36
|
+
/** On HDR displays, the sun and the wave halo glow above SDR white (WebGPU). */
|
|
37
|
+
hdr?: boolean;
|
|
38
|
+
/** Plays the toggle cue through the sound controller. */
|
|
39
|
+
sound?: boolean;
|
|
40
|
+
/** Accessible name of the switch. */
|
|
41
|
+
label?: string;
|
|
42
|
+
/** Blocks interaction. */
|
|
43
|
+
disabled?: boolean;
|
|
44
|
+
/** Additional CSS classes on the button. */
|
|
45
|
+
class?: HTMLAttributes["class"];
|
|
46
|
+
}
|
|
47
|
+
declare const _default: typeof __VLS_export;
|
|
48
|
+
export default _default;
|
|
49
|
+
declare const __VLS_export: import("vue").DefineComponent<SunSwitchProps & {
|
|
50
|
+
/** Day (true) or night (false). */
|
|
51
|
+
checked?: boolean;
|
|
52
|
+
}, {
|
|
53
|
+
ref: Readonly<import("vue").ShallowRef<HTMLButtonElement | null>>;
|
|
54
|
+
}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
|
|
55
|
+
"update:checked": (value: boolean) => any;
|
|
56
|
+
}, string, import("vue").PublicProps, Readonly<SunSwitchProps & {
|
|
57
|
+
/** Day (true) or night (false). */
|
|
58
|
+
checked?: boolean;
|
|
59
|
+
}> & Readonly<{
|
|
60
|
+
"onUpdate:checked"?: ((value: boolean) => any) | undefined;
|
|
61
|
+
}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import _sfc_main from "./SunSwitch.vue2.js";
|
|
2
|
+
/* empty css */
|
|
3
|
+
import _export_sfc from "../../_virtual/_plugin-vue_export-helper.js";
|
|
4
|
+
const SunSwitch = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-28e3a9f7"]]);
|
|
5
|
+
export {
|
|
6
|
+
SunSwitch as default
|
|
7
|
+
};
|