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,311 @@
|
|
|
1
|
+
const SUN_HDR_PEAK = 4.9;
|
|
2
|
+
const SUN_HDR_RESTARTS = 3;
|
|
3
|
+
const SUN_HDR_RESTART_MS = 600;
|
|
4
|
+
const FPI = 8;
|
|
5
|
+
const START_CAPACITY = 1024;
|
|
6
|
+
const FORMAT = "rgba16float";
|
|
7
|
+
const WGSL = (
|
|
8
|
+
/* wgsl */
|
|
9
|
+
`
|
|
10
|
+
struct Frame { size: vec2f, dot: f32, pad: f32 };
|
|
11
|
+
@group(0) @binding(0) var<uniform> frame: Frame;
|
|
12
|
+
struct In { @location(0) cell: vec4f, @location(1) colour: vec4f };
|
|
13
|
+
struct Out { @builtin(position) pos: vec4f, @location(0) colour: vec4f };
|
|
14
|
+
@vertex fn vs(@builtin(vertex_index) vi: u32, inst: In) -> Out {
|
|
15
|
+
let corners = array<vec2f, 6>(vec2f(0, 0), vec2f(1, 0), vec2f(0, 1), vec2f(0, 1), vec2f(1, 0), vec2f(1, 1));
|
|
16
|
+
let p = inst.cell.xy + corners[vi] * frame.dot;
|
|
17
|
+
var o: Out;
|
|
18
|
+
o.pos = vec4f(p.x / frame.size.x * 2.0 - 1.0, 1.0 - p.y / frame.size.y * 2.0, 0.0, 1.0);
|
|
19
|
+
o.colour = inst.colour;
|
|
20
|
+
return o;
|
|
21
|
+
}
|
|
22
|
+
// a hard square at the pre-encoded colour; nothing else
|
|
23
|
+
@fragment fn fs(o: Out) -> @location(0) vec4f { return vec4f(o.colour.rgb, 1.0); }
|
|
24
|
+
`
|
|
25
|
+
);
|
|
26
|
+
const LINEAR = new Float32Array(256);
|
|
27
|
+
for (let i = 0; i < 256; i++) {
|
|
28
|
+
const c = i / 255;
|
|
29
|
+
LINEAR[i] = c <= 0.04045 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4;
|
|
30
|
+
}
|
|
31
|
+
function srgbToLinear(c8) {
|
|
32
|
+
return LINEAR[Math.min(255, Math.max(0, Math.round(c8)))];
|
|
33
|
+
}
|
|
34
|
+
function encodeExt(v) {
|
|
35
|
+
return v <= 31308e-7 ? 12.92 * v : 1.055 * Math.pow(v, 1 / 2.4) - 0.055;
|
|
36
|
+
}
|
|
37
|
+
function encodeGlowChannel(c8, glow) {
|
|
38
|
+
const g = Math.min(SUN_HDR_PEAK, Math.max(0, glow));
|
|
39
|
+
return encodeExt(srgbToLinear(c8) * g);
|
|
40
|
+
}
|
|
41
|
+
function sunHdrAvailable() {
|
|
42
|
+
try {
|
|
43
|
+
if (typeof navigator === "undefined" || typeof window === "undefined") return false;
|
|
44
|
+
if (!navigator.gpu) return false;
|
|
45
|
+
return typeof window.matchMedia === "function" && window.matchMedia("(dynamic-range: high)").matches;
|
|
46
|
+
} catch {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
function hdrCapacityFor(n) {
|
|
51
|
+
let c = START_CAPACITY;
|
|
52
|
+
while (c < n) c *= 2;
|
|
53
|
+
return c;
|
|
54
|
+
}
|
|
55
|
+
function createSunHdrSquares() {
|
|
56
|
+
let data = new Float32Array(START_CAPACITY * FPI);
|
|
57
|
+
let n = 0;
|
|
58
|
+
return {
|
|
59
|
+
get n() {
|
|
60
|
+
return n;
|
|
61
|
+
},
|
|
62
|
+
get data() {
|
|
63
|
+
return data;
|
|
64
|
+
},
|
|
65
|
+
clear() {
|
|
66
|
+
n = 0;
|
|
67
|
+
},
|
|
68
|
+
push(px, py, rgb, glow) {
|
|
69
|
+
if (!(glow > 0) || rgb < 0) return;
|
|
70
|
+
if ((n + 1) * FPI > data.length) {
|
|
71
|
+
const next = new Float32Array(hdrCapacityFor(n + 1) * FPI);
|
|
72
|
+
next.set(data);
|
|
73
|
+
data = next;
|
|
74
|
+
}
|
|
75
|
+
const o = n * FPI;
|
|
76
|
+
data[o] = px;
|
|
77
|
+
data[o + 1] = py;
|
|
78
|
+
data[o + 2] = 0;
|
|
79
|
+
data[o + 3] = 0;
|
|
80
|
+
data[o + 4] = encodeGlowChannel(rgb >> 16 & 255, glow);
|
|
81
|
+
data[o + 5] = encodeGlowChannel(rgb >> 8 & 255, glow);
|
|
82
|
+
data[o + 6] = encodeGlowChannel(rgb & 255, glow);
|
|
83
|
+
data[o + 7] = 1;
|
|
84
|
+
n++;
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
let shared = null;
|
|
89
|
+
const PIPELINES = /* @__PURE__ */ new WeakMap();
|
|
90
|
+
function acquire(gpu) {
|
|
91
|
+
if (!shared) {
|
|
92
|
+
const s = { device: Promise.resolve(null), refs: 0, onLost: /* @__PURE__ */ new Set() };
|
|
93
|
+
s.device = (async () => {
|
|
94
|
+
const adapter = await gpu.requestAdapter();
|
|
95
|
+
if (!adapter) return null;
|
|
96
|
+
const device = await adapter.requestDevice();
|
|
97
|
+
void device.lost.then(() => {
|
|
98
|
+
if (shared === s) shared = null;
|
|
99
|
+
for (const fn of [...s.onLost]) fn();
|
|
100
|
+
s.onLost.clear();
|
|
101
|
+
});
|
|
102
|
+
return device;
|
|
103
|
+
})().catch(() => null);
|
|
104
|
+
shared = s;
|
|
105
|
+
}
|
|
106
|
+
shared.refs++;
|
|
107
|
+
return shared;
|
|
108
|
+
}
|
|
109
|
+
function release(s) {
|
|
110
|
+
s.refs--;
|
|
111
|
+
if (s.refs > 0) return;
|
|
112
|
+
if (shared === s) shared = null;
|
|
113
|
+
s.onLost.clear();
|
|
114
|
+
void s.device.then((d) => d?.destroy());
|
|
115
|
+
}
|
|
116
|
+
function pipelineFor(device) {
|
|
117
|
+
let p = PIPELINES.get(device);
|
|
118
|
+
if (p) return p;
|
|
119
|
+
const module = device.createShaderModule({ code: WGSL });
|
|
120
|
+
p = device.createRenderPipeline({
|
|
121
|
+
layout: "auto",
|
|
122
|
+
vertex: {
|
|
123
|
+
module,
|
|
124
|
+
entryPoint: "vs",
|
|
125
|
+
buffers: [
|
|
126
|
+
{
|
|
127
|
+
arrayStride: FPI * 4,
|
|
128
|
+
stepMode: "instance",
|
|
129
|
+
attributes: [
|
|
130
|
+
{ shaderLocation: 0, offset: 0, format: "float32x4" },
|
|
131
|
+
{ shaderLocation: 1, offset: 16, format: "float32x4" }
|
|
132
|
+
]
|
|
133
|
+
}
|
|
134
|
+
]
|
|
135
|
+
},
|
|
136
|
+
fragment: {
|
|
137
|
+
module,
|
|
138
|
+
entryPoint: "fs",
|
|
139
|
+
targets: [
|
|
140
|
+
{
|
|
141
|
+
format: FORMAT,
|
|
142
|
+
blend: {
|
|
143
|
+
color: { srcFactor: "one", dstFactor: "one", operation: "max" },
|
|
144
|
+
alpha: { srcFactor: "one", dstFactor: "one", operation: "max" }
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
]
|
|
148
|
+
},
|
|
149
|
+
primitive: { topology: "triangle-list" }
|
|
150
|
+
});
|
|
151
|
+
PIPELINES.set(device, p);
|
|
152
|
+
return p;
|
|
153
|
+
}
|
|
154
|
+
async function startSunHdr(canvas) {
|
|
155
|
+
if (!sunHdrAvailable()) return null;
|
|
156
|
+
const gpu = navigator.gpu;
|
|
157
|
+
if (!gpu) return null;
|
|
158
|
+
const s = acquire(gpu);
|
|
159
|
+
let held = true;
|
|
160
|
+
const drop = () => {
|
|
161
|
+
if (held) {
|
|
162
|
+
held = false;
|
|
163
|
+
release(s);
|
|
164
|
+
}
|
|
165
|
+
};
|
|
166
|
+
try {
|
|
167
|
+
const device = await s.device;
|
|
168
|
+
if (!device) {
|
|
169
|
+
drop();
|
|
170
|
+
return null;
|
|
171
|
+
}
|
|
172
|
+
const context = canvas.getContext("webgpu");
|
|
173
|
+
if (!context) {
|
|
174
|
+
drop();
|
|
175
|
+
return null;
|
|
176
|
+
}
|
|
177
|
+
context.configure({
|
|
178
|
+
device,
|
|
179
|
+
format: FORMAT,
|
|
180
|
+
alphaMode: "premultiplied",
|
|
181
|
+
colorSpace: "srgb",
|
|
182
|
+
toneMapping: { mode: "extended" }
|
|
183
|
+
});
|
|
184
|
+
let extended = false;
|
|
185
|
+
try {
|
|
186
|
+
const applied = context.getConfiguration?.();
|
|
187
|
+
extended = applied?.toneMapping?.mode === "extended";
|
|
188
|
+
} catch {
|
|
189
|
+
extended = false;
|
|
190
|
+
}
|
|
191
|
+
if (!extended) {
|
|
192
|
+
try {
|
|
193
|
+
context.unconfigure();
|
|
194
|
+
} catch {
|
|
195
|
+
}
|
|
196
|
+
drop();
|
|
197
|
+
return null;
|
|
198
|
+
}
|
|
199
|
+
const pipeline = pipelineFor(device);
|
|
200
|
+
const uniform = device.createBuffer({
|
|
201
|
+
size: 16,
|
|
202
|
+
usage: GPUBufferUsage.UNIFORM | GPUBufferUsage.COPY_DST
|
|
203
|
+
});
|
|
204
|
+
const uniformData = new Float32Array(4);
|
|
205
|
+
const bindGroup = device.createBindGroup({
|
|
206
|
+
layout: pipeline.getBindGroupLayout(0),
|
|
207
|
+
entries: [{ binding: 0, resource: { buffer: uniform } }]
|
|
208
|
+
});
|
|
209
|
+
const sink = createSunHdrSquares();
|
|
210
|
+
let capacity = START_CAPACITY;
|
|
211
|
+
let instances = device.createBuffer({
|
|
212
|
+
size: capacity * FPI * 4,
|
|
213
|
+
usage: GPUBufferUsage.VERTEX | GPUBufferUsage.COPY_DST
|
|
214
|
+
});
|
|
215
|
+
let destroyed = false;
|
|
216
|
+
let count = 0;
|
|
217
|
+
let resolveLost = () => {
|
|
218
|
+
};
|
|
219
|
+
const lost = new Promise((r) => {
|
|
220
|
+
resolveLost = r;
|
|
221
|
+
});
|
|
222
|
+
const onLost = () => {
|
|
223
|
+
destroyed = true;
|
|
224
|
+
resolveLost();
|
|
225
|
+
};
|
|
226
|
+
s.onLost.add(onLost);
|
|
227
|
+
const layer = {
|
|
228
|
+
sink,
|
|
229
|
+
get lost() {
|
|
230
|
+
return lost;
|
|
231
|
+
},
|
|
232
|
+
get count() {
|
|
233
|
+
return count;
|
|
234
|
+
},
|
|
235
|
+
render(width, height, size) {
|
|
236
|
+
if (destroyed || width <= 0 || height <= 0) return;
|
|
237
|
+
if (canvas.width !== width) canvas.width = width;
|
|
238
|
+
if (canvas.height !== height) canvas.height = height;
|
|
239
|
+
const k = sink.n;
|
|
240
|
+
if (k > capacity) {
|
|
241
|
+
capacity = hdrCapacityFor(k);
|
|
242
|
+
instances.destroy();
|
|
243
|
+
instances = device.createBuffer({
|
|
244
|
+
size: capacity * FPI * 4,
|
|
245
|
+
usage: GPUBufferUsage.VERTEX | GPUBufferUsage.COPY_DST
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
count = k;
|
|
249
|
+
uniformData[0] = width;
|
|
250
|
+
uniformData[1] = height;
|
|
251
|
+
uniformData[2] = size;
|
|
252
|
+
uniformData[3] = 0;
|
|
253
|
+
try {
|
|
254
|
+
device.queue.writeBuffer(uniform, 0, uniformData);
|
|
255
|
+
if (k) device.queue.writeBuffer(instances, 0, sink.data, 0, k * FPI);
|
|
256
|
+
const encoder = device.createCommandEncoder();
|
|
257
|
+
const pass = encoder.beginRenderPass({
|
|
258
|
+
colorAttachments: [
|
|
259
|
+
{
|
|
260
|
+
view: context.getCurrentTexture().createView(),
|
|
261
|
+
clearValue: { r: 0, g: 0, b: 0, a: 0 },
|
|
262
|
+
loadOp: "clear",
|
|
263
|
+
storeOp: "store"
|
|
264
|
+
}
|
|
265
|
+
]
|
|
266
|
+
});
|
|
267
|
+
if (k) {
|
|
268
|
+
pass.setPipeline(pipeline);
|
|
269
|
+
pass.setBindGroup(0, bindGroup);
|
|
270
|
+
pass.setVertexBuffer(0, instances);
|
|
271
|
+
pass.draw(6, k);
|
|
272
|
+
}
|
|
273
|
+
pass.end();
|
|
274
|
+
device.queue.submit([encoder.finish()]);
|
|
275
|
+
} catch {
|
|
276
|
+
}
|
|
277
|
+
},
|
|
278
|
+
destroy() {
|
|
279
|
+
if (destroyed && !held) return;
|
|
280
|
+
destroyed = true;
|
|
281
|
+
s.onLost.delete(onLost);
|
|
282
|
+
try {
|
|
283
|
+
context.unconfigure();
|
|
284
|
+
} catch {
|
|
285
|
+
}
|
|
286
|
+
try {
|
|
287
|
+
uniform.destroy();
|
|
288
|
+
instances.destroy();
|
|
289
|
+
} catch {
|
|
290
|
+
}
|
|
291
|
+
drop();
|
|
292
|
+
}
|
|
293
|
+
};
|
|
294
|
+
return layer;
|
|
295
|
+
} catch {
|
|
296
|
+
drop();
|
|
297
|
+
return null;
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
export {
|
|
301
|
+
SUN_HDR_PEAK,
|
|
302
|
+
SUN_HDR_RESTARTS,
|
|
303
|
+
SUN_HDR_RESTART_MS,
|
|
304
|
+
createSunHdrSquares,
|
|
305
|
+
encodeExt,
|
|
306
|
+
encodeGlowChannel,
|
|
307
|
+
hdrCapacityFor,
|
|
308
|
+
srgbToLinear,
|
|
309
|
+
startSunHdr,
|
|
310
|
+
sunHdrAvailable
|
|
311
|
+
};
|
|
@@ -1,11 +1,30 @@
|
|
|
1
1
|
import type { HTMLAttributes } from "vue";
|
|
2
2
|
export interface TracingBeamProps {
|
|
3
|
-
/** Additional CSS classes */
|
|
3
|
+
/** Additional CSS classes for the outer wrapper */
|
|
4
4
|
class?: HTMLAttributes["class"];
|
|
5
|
+
/**
|
|
6
|
+
* Colour of the lamp, its trail and the lit markers. Any CSS colour.
|
|
7
|
+
* Unset, it follows the theme's `--primary` token and falls back to a
|
|
8
|
+
* soft violet when no theme is present. Also settable from CSS via
|
|
9
|
+
* `--tracing-beam-accent`.
|
|
10
|
+
*/
|
|
11
|
+
accent?: string;
|
|
12
|
+
/**
|
|
13
|
+
* Where the reader's eye is assumed to be, as a fraction of the viewport
|
|
14
|
+
* height from the top. The lamp sits on that line, clamped to the content.
|
|
15
|
+
*/
|
|
16
|
+
readingLine?: number;
|
|
17
|
+
/**
|
|
18
|
+
* Draw a marker on the rail for every heading (`h1`–`h4`) inside the
|
|
19
|
+
* content — or, when there is none, for every direct child. Markers light
|
|
20
|
+
* up as the lamp passes them.
|
|
21
|
+
*/
|
|
22
|
+
markers?: boolean;
|
|
5
23
|
}
|
|
6
24
|
declare const _default: typeof __VLS_export;
|
|
7
25
|
export default _default;
|
|
8
26
|
declare const __VLS_export: __VLS_WithSlots<import("vue").DefineComponent<TracingBeamProps, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<TracingBeamProps> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>, {
|
|
27
|
+
/** Long-form content the beam reads alongside */
|
|
9
28
|
default?(): unknown;
|
|
10
29
|
}>;
|
|
11
30
|
type __VLS_WithSlots<T, S> = T & {
|
|
@@ -1,166 +1,7 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
import
|
|
4
|
-
const
|
|
5
|
-
const _hoisted_2 = ["viewBox", "height"];
|
|
6
|
-
const _hoisted_3 = ["d"];
|
|
7
|
-
const _hoisted_4 = ["d", "stroke"];
|
|
8
|
-
const _hoisted_5 = ["y1", "y2"];
|
|
9
|
-
function mapRange(value, inMin, inMax, outMin, outMax) {
|
|
10
|
-
return (value - inMin) * (outMax - outMin) / (inMax - inMin) + outMin;
|
|
11
|
-
}
|
|
12
|
-
const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
13
|
-
...{ name: "TracingBeam", inheritAttrs: false },
|
|
14
|
-
__name: "TracingBeam",
|
|
15
|
-
props: {
|
|
16
|
-
class: { type: [Boolean, null, String, Object, Array], default: "" }
|
|
17
|
-
},
|
|
18
|
-
setup(__props) {
|
|
19
|
-
const gradientId = `${useFancyId()}-gradient`;
|
|
20
|
-
const tracingBeamRef = useTemplateRef("tracingBeamRef");
|
|
21
|
-
const contentRef = useTemplateRef("contentRef");
|
|
22
|
-
const svgHeight = ref(0);
|
|
23
|
-
const scrollYProgress = ref(0);
|
|
24
|
-
const scrollPercentage = ref(0);
|
|
25
|
-
const springY1 = ref(0);
|
|
26
|
-
const springY2 = ref(0);
|
|
27
|
-
let springVelY1 = 0;
|
|
28
|
-
let springVelY2 = 0;
|
|
29
|
-
const targetY1 = computed(
|
|
30
|
-
() => mapRange(scrollYProgress.value, 0, 0.8, scrollYProgress.value, svgHeight.value) * (1.4 - scrollPercentage.value)
|
|
31
|
-
);
|
|
32
|
-
const targetY2 = computed(
|
|
33
|
-
() => mapRange(scrollYProgress.value, 0, 1, scrollYProgress.value, svgHeight.value - 500) * (1.4 - scrollPercentage.value)
|
|
34
|
-
);
|
|
35
|
-
const circleHasShadow = computed(() => scrollYProgress.value <= 0);
|
|
36
|
-
const circleBg = computed(() => scrollYProgress.value > 0 ? "bg-white" : "bg-emerald-500");
|
|
37
|
-
const circleBorder = computed(
|
|
38
|
-
() => scrollYProgress.value > 0 ? "border-neutral-300" : "border-emerald-600"
|
|
39
|
-
);
|
|
40
|
-
const svgPath = computed(
|
|
41
|
-
() => `M 1 0V -36 l 18 24 V ${svgHeight.value * 0.8} l -18 24V ${svgHeight.value}`
|
|
42
|
-
);
|
|
43
|
-
let rafId = 0;
|
|
44
|
-
function updateSpring() {
|
|
45
|
-
const tension = 80;
|
|
46
|
-
const friction = 26;
|
|
47
|
-
const precision = 0.01;
|
|
48
|
-
const forceY1 = tension * (targetY1.value - springY1.value);
|
|
49
|
-
springVelY1 = (springVelY1 + forceY1 * 1e-3) * (1 - friction * 1e-3);
|
|
50
|
-
springY1.value += springVelY1;
|
|
51
|
-
const forceY2 = tension * (targetY2.value - springY2.value);
|
|
52
|
-
springVelY2 = (springVelY2 + forceY2 * 1e-3) * (1 - friction * 1e-3);
|
|
53
|
-
springY2.value += springVelY2;
|
|
54
|
-
const settled = Math.abs(springVelY1) < precision && Math.abs(targetY1.value - springY1.value) < precision && Math.abs(springVelY2) < precision && Math.abs(targetY2.value - springY2.value) < precision;
|
|
55
|
-
if (!settled) {
|
|
56
|
-
rafId = requestAnimationFrame(updateSpring);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
function updateScrollProgress() {
|
|
60
|
-
const el = tracingBeamRef.value;
|
|
61
|
-
if (!el) return;
|
|
62
|
-
const rect = el.getBoundingClientRect();
|
|
63
|
-
const windowHeight = window.innerHeight;
|
|
64
|
-
const elementHeight = rect.height;
|
|
65
|
-
scrollPercentage.value = (windowHeight - rect.top) / (windowHeight + elementHeight);
|
|
66
|
-
scrollYProgress.value = rect.y / windowHeight * -1;
|
|
67
|
-
cancelAnimationFrame(rafId);
|
|
68
|
-
rafId = requestAnimationFrame(updateSpring);
|
|
69
|
-
}
|
|
70
|
-
function updateSVGHeight() {
|
|
71
|
-
const el = contentRef.value;
|
|
72
|
-
if (!el) return;
|
|
73
|
-
svgHeight.value = el.offsetHeight;
|
|
74
|
-
}
|
|
75
|
-
let resizeObserver;
|
|
76
|
-
onMounted(() => {
|
|
77
|
-
window.addEventListener("scroll", updateScrollProgress, { passive: true });
|
|
78
|
-
window.addEventListener("resize", updateScrollProgress, { passive: true });
|
|
79
|
-
updateScrollProgress();
|
|
80
|
-
resizeObserver = new ResizeObserver(updateSVGHeight);
|
|
81
|
-
if (contentRef.value) {
|
|
82
|
-
resizeObserver.observe(contentRef.value);
|
|
83
|
-
}
|
|
84
|
-
updateSVGHeight();
|
|
85
|
-
});
|
|
86
|
-
onBeforeUnmount(() => {
|
|
87
|
-
cancelAnimationFrame(rafId);
|
|
88
|
-
window.removeEventListener("scroll", updateScrollProgress);
|
|
89
|
-
window.removeEventListener("resize", updateScrollProgress);
|
|
90
|
-
resizeObserver?.disconnect();
|
|
91
|
-
});
|
|
92
|
-
return (_ctx, _cache) => {
|
|
93
|
-
return openBlock(), createElementBlock("div", {
|
|
94
|
-
ref_key: "tracingBeamRef",
|
|
95
|
-
ref: tracingBeamRef,
|
|
96
|
-
class: normalizeClass(unref(cn)("relative mx-auto h-full w-full max-w-4xl", __props.class))
|
|
97
|
-
}, [
|
|
98
|
-
createElementVNode("div", _hoisted_1, [
|
|
99
|
-
createElementVNode("div", {
|
|
100
|
-
class: "ml-[27px] flex size-4 items-center justify-center rounded-full border border-neutral-200 shadow-sm",
|
|
101
|
-
style: normalizeStyle({ boxShadow: circleHasShadow.value ? "rgba(0, 0, 0, 0.24) 0px 3px 8px" : "none" })
|
|
102
|
-
}, [
|
|
103
|
-
createElementVNode("div", {
|
|
104
|
-
class: normalizeClass(unref(cn)("size-2 rounded-full border", circleBg.value, circleBorder.value))
|
|
105
|
-
}, null, 2)
|
|
106
|
-
], 4),
|
|
107
|
-
(openBlock(), createElementBlock("svg", {
|
|
108
|
-
viewBox: `0 0 20 ${svgHeight.value}`,
|
|
109
|
-
width: "20",
|
|
110
|
-
height: svgHeight.value,
|
|
111
|
-
class: "ml-4 block",
|
|
112
|
-
"aria-hidden": "true"
|
|
113
|
-
}, [
|
|
114
|
-
createElementVNode("path", {
|
|
115
|
-
d: svgPath.value,
|
|
116
|
-
fill: "none",
|
|
117
|
-
stroke: "#9091A0",
|
|
118
|
-
"stroke-opacity": "0.16"
|
|
119
|
-
}, null, 8, _hoisted_3),
|
|
120
|
-
createElementVNode("path", {
|
|
121
|
-
d: svgPath.value,
|
|
122
|
-
fill: "none",
|
|
123
|
-
stroke: `url(#${gradientId})`,
|
|
124
|
-
"stroke-width": "1.25",
|
|
125
|
-
class: "motion-reduce:hidden"
|
|
126
|
-
}, null, 8, _hoisted_4),
|
|
127
|
-
createElementVNode("defs", null, [
|
|
128
|
-
createElementVNode("linearGradient", {
|
|
129
|
-
id: gradientId,
|
|
130
|
-
gradientUnits: "userSpaceOnUse",
|
|
131
|
-
x1: "0",
|
|
132
|
-
x2: "0",
|
|
133
|
-
y1: springY1.value,
|
|
134
|
-
y2: springY2.value
|
|
135
|
-
}, [..._cache[0] || (_cache[0] = [
|
|
136
|
-
createElementVNode("stop", {
|
|
137
|
-
"stop-color": "#18CCFC",
|
|
138
|
-
"stop-opacity": "0"
|
|
139
|
-
}, null, -1),
|
|
140
|
-
createElementVNode("stop", { "stop-color": "#18CCFC" }, null, -1),
|
|
141
|
-
createElementVNode("stop", {
|
|
142
|
-
offset: "0.325",
|
|
143
|
-
"stop-color": "#6344F5"
|
|
144
|
-
}, null, -1),
|
|
145
|
-
createElementVNode("stop", {
|
|
146
|
-
offset: "1",
|
|
147
|
-
"stop-color": "#AE48FF",
|
|
148
|
-
"stop-opacity": "0"
|
|
149
|
-
}, null, -1)
|
|
150
|
-
])], 8, _hoisted_5)
|
|
151
|
-
])
|
|
152
|
-
], 8, _hoisted_2))
|
|
153
|
-
]),
|
|
154
|
-
createElementVNode("div", {
|
|
155
|
-
ref_key: "contentRef",
|
|
156
|
-
ref: contentRef
|
|
157
|
-
}, [
|
|
158
|
-
renderSlot(_ctx.$slots, "default")
|
|
159
|
-
], 512)
|
|
160
|
-
], 2);
|
|
161
|
-
};
|
|
162
|
-
}
|
|
163
|
-
});
|
|
1
|
+
import _sfc_main from "./TracingBeam.vue2.js";
|
|
2
|
+
/* empty css */
|
|
3
|
+
import _export_sfc from "../../_virtual/_plugin-vue_export-helper.js";
|
|
4
|
+
const TracingBeam = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-297de2d4"]]);
|
|
164
5
|
export {
|
|
165
|
-
|
|
6
|
+
TracingBeam as default
|
|
166
7
|
};
|
|
@@ -1,4 +1,171 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { defineComponent, useTemplateRef, ref, onMounted, onBeforeUnmount, watch, createElementBlock, openBlock, normalizeStyle, normalizeClass, unref, createElementVNode, Fragment, renderList, renderSlot } from "vue";
|
|
2
|
+
import { cn } from "../../utils.js";
|
|
3
|
+
import { rafThrottle } from "../../internals/motion/raf.js";
|
|
4
|
+
import { useReducedMotion } from "../../internals/motion/use-media-query.js";
|
|
5
|
+
const _hoisted_1 = ["data-motion"];
|
|
6
|
+
const _hoisted_2 = {
|
|
7
|
+
class: "tb-gutter",
|
|
8
|
+
"aria-hidden": "true"
|
|
9
|
+
};
|
|
10
|
+
const _hoisted_3 = ["data-lit"];
|
|
11
|
+
const _hoisted_4 = ["data-ready"];
|
|
12
|
+
const TENSION = 120;
|
|
13
|
+
const FRICTION = 22;
|
|
14
|
+
const PRECISION = 0.05;
|
|
15
|
+
const MAX_DT = 1 / 30;
|
|
16
|
+
const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
17
|
+
...{ name: "TracingBeam", inheritAttrs: false },
|
|
18
|
+
__name: "TracingBeam",
|
|
19
|
+
props: {
|
|
20
|
+
class: { type: [Boolean, null, String, Object, Array], default: "" },
|
|
21
|
+
accent: {},
|
|
22
|
+
readingLine: { default: 0.38 },
|
|
23
|
+
markers: { type: Boolean, default: true }
|
|
24
|
+
},
|
|
25
|
+
setup(__props) {
|
|
26
|
+
const reduced = useReducedMotion();
|
|
27
|
+
const contentRef = useTemplateRef("contentRef");
|
|
28
|
+
const height = ref(0);
|
|
29
|
+
const ticks = ref([]);
|
|
30
|
+
const head = ref(0);
|
|
31
|
+
const ready = ref(false);
|
|
32
|
+
let target = 0;
|
|
33
|
+
let velocity = 0;
|
|
34
|
+
let rafId = 0;
|
|
35
|
+
let lastTime = 0;
|
|
36
|
+
function isLit(offset) {
|
|
37
|
+
return offset <= head.value + 0.5;
|
|
38
|
+
}
|
|
39
|
+
function clamp(value, min, max) {
|
|
40
|
+
return Math.min(max, Math.max(min, value));
|
|
41
|
+
}
|
|
42
|
+
function localScale(el, rect) {
|
|
43
|
+
const layout = el.offsetHeight;
|
|
44
|
+
if (layout <= 0 || rect.height <= 0 || Math.abs(rect.height - layout) < 1) return 1;
|
|
45
|
+
return rect.height / layout;
|
|
46
|
+
}
|
|
47
|
+
function step(time) {
|
|
48
|
+
const dt = Math.min(MAX_DT, (time - lastTime) / 1e3 || 0);
|
|
49
|
+
lastTime = time;
|
|
50
|
+
const force = TENSION * (target - head.value) - FRICTION * velocity;
|
|
51
|
+
velocity += force * dt;
|
|
52
|
+
head.value += velocity * dt;
|
|
53
|
+
if (Math.abs(velocity) < PRECISION && Math.abs(target - head.value) < PRECISION) {
|
|
54
|
+
head.value = target;
|
|
55
|
+
velocity = 0;
|
|
56
|
+
rafId = 0;
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
rafId = requestAnimationFrame(step);
|
|
60
|
+
}
|
|
61
|
+
function place() {
|
|
62
|
+
const el = contentRef.value;
|
|
63
|
+
if (!el) return;
|
|
64
|
+
const rect = el.getBoundingClientRect();
|
|
65
|
+
const scale = localScale(el, rect);
|
|
66
|
+
const line = window.innerHeight * clamp(__props.readingLine, 0, 1);
|
|
67
|
+
target = clamp((line - rect.top) / scale, 0, Math.max(0, rect.height / scale));
|
|
68
|
+
ready.value = true;
|
|
69
|
+
if (reduced.value) {
|
|
70
|
+
cancelAnimationFrame(rafId);
|
|
71
|
+
rafId = 0;
|
|
72
|
+
velocity = 0;
|
|
73
|
+
head.value = target;
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
if (!rafId) {
|
|
77
|
+
lastTime = performance.now();
|
|
78
|
+
rafId = requestAnimationFrame(step);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
function measure() {
|
|
82
|
+
const el = contentRef.value;
|
|
83
|
+
if (!el) return;
|
|
84
|
+
const rect = el.getBoundingClientRect();
|
|
85
|
+
const scale = localScale(el, rect);
|
|
86
|
+
height.value = rect.height / scale;
|
|
87
|
+
if (__props.markers) {
|
|
88
|
+
const headings = el.querySelectorAll("h1, h2, h3, h4");
|
|
89
|
+
const anchors = headings.length ? [...headings] : [...el.children];
|
|
90
|
+
ticks.value = anchors.filter((node) => node instanceof HTMLElement).map((node) => {
|
|
91
|
+
const box = node.getBoundingClientRect();
|
|
92
|
+
return (box.top + box.height / 2 - rect.top) / scale;
|
|
93
|
+
});
|
|
94
|
+
} else {
|
|
95
|
+
ticks.value = [];
|
|
96
|
+
}
|
|
97
|
+
place();
|
|
98
|
+
}
|
|
99
|
+
onMounted(() => {
|
|
100
|
+
const onScroll = rafThrottle(place);
|
|
101
|
+
const onResize = rafThrottle(measure);
|
|
102
|
+
const resizeObserver = new ResizeObserver(() => onResize());
|
|
103
|
+
if (contentRef.value) resizeObserver.observe(contentRef.value);
|
|
104
|
+
window.addEventListener("scroll", onScroll, { passive: true });
|
|
105
|
+
window.addEventListener("resize", onResize, { passive: true });
|
|
106
|
+
measure();
|
|
107
|
+
onBeforeUnmount(() => {
|
|
108
|
+
onScroll.cancel();
|
|
109
|
+
onResize.cancel();
|
|
110
|
+
cancelAnimationFrame(rafId);
|
|
111
|
+
rafId = 0;
|
|
112
|
+
resizeObserver.disconnect();
|
|
113
|
+
window.removeEventListener("scroll", onScroll);
|
|
114
|
+
window.removeEventListener("resize", onResize);
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
watch(
|
|
118
|
+
() => [__props.markers, __props.readingLine, reduced.value],
|
|
119
|
+
() => {
|
|
120
|
+
if (contentRef.value) queueMicrotask(measure);
|
|
121
|
+
},
|
|
122
|
+
{ flush: "post" }
|
|
123
|
+
);
|
|
124
|
+
return (_ctx, _cache) => {
|
|
125
|
+
return openBlock(), createElementBlock("div", {
|
|
126
|
+
class: normalizeClass(unref(cn)("tb-root relative mx-auto w-full max-w-4xl", __props.class)),
|
|
127
|
+
style: normalizeStyle({
|
|
128
|
+
"--tracing-beam-accent": __props.accent,
|
|
129
|
+
"--tb-progress": `${head.value}px`,
|
|
130
|
+
"--tb-height": `${height.value}px`
|
|
131
|
+
}),
|
|
132
|
+
"data-motion": unref(reduced) ? "reduced" : "full",
|
|
133
|
+
"data-tracing-beam": ""
|
|
134
|
+
}, [
|
|
135
|
+
createElementVNode("div", _hoisted_2, [
|
|
136
|
+
_cache[1] || (_cache[1] = createElementVNode("div", { class: "tb-rail" }, [
|
|
137
|
+
createElementVNode("span", { class: "tb-hair" }),
|
|
138
|
+
createElementVNode("span", { class: "tb-trail" })
|
|
139
|
+
], -1)),
|
|
140
|
+
(openBlock(true), createElementBlock(Fragment, null, renderList(ticks.value, (offset, index) => {
|
|
141
|
+
return openBlock(), createElementBlock("span", {
|
|
142
|
+
key: index,
|
|
143
|
+
class: "tb-tick",
|
|
144
|
+
style: normalizeStyle({ top: `${offset}px` }),
|
|
145
|
+
"data-tracing-beam-marker": "",
|
|
146
|
+
"data-lit": String(isLit(offset))
|
|
147
|
+
}, null, 12, _hoisted_3);
|
|
148
|
+
}), 128)),
|
|
149
|
+
createElementVNode("div", {
|
|
150
|
+
class: "tb-head",
|
|
151
|
+
"data-tracing-beam-head": "",
|
|
152
|
+
"data-ready": String(ready.value)
|
|
153
|
+
}, [..._cache[0] || (_cache[0] = [
|
|
154
|
+
createElementVNode("span", { class: "tb-spill" }, null, -1),
|
|
155
|
+
createElementVNode("span", { class: "tb-lamp" }, null, -1)
|
|
156
|
+
])], 8, _hoisted_4)
|
|
157
|
+
]),
|
|
158
|
+
createElementVNode("div", {
|
|
159
|
+
ref_key: "contentRef",
|
|
160
|
+
ref: contentRef,
|
|
161
|
+
class: "tb-content"
|
|
162
|
+
}, [
|
|
163
|
+
renderSlot(_ctx.$slots, "default", {}, void 0, true)
|
|
164
|
+
], 512)
|
|
165
|
+
], 14, _hoisted_1);
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
});
|
|
2
169
|
export {
|
|
3
170
|
_sfc_main as default
|
|
4
171
|
};
|