nitro-screen-choreography 0.0.0-stage → 0.0.1-alpha.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/LICENSE +21 -0
- package/README.md +19 -2
- package/dist/clock.d.ts +29 -0
- package/dist/clock.d.ts.map +1 -0
- package/dist/clock.js +131 -0
- package/dist/clock.js.map +1 -0
- package/dist/context.d.ts +38 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +98 -0
- package/dist/context.js.map +1 -0
- package/dist/geometry.d.ts +28 -0
- package/dist/geometry.d.ts.map +1 -0
- package/dist/geometry.js +65 -0
- package/dist/geometry.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -0
- package/dist/registry.d.ts +44 -0
- package/dist/registry.d.ts.map +1 -0
- package/dist/registry.js +119 -0
- package/dist/registry.js.map +1 -0
- package/dist/types.d.ts +76 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +66 -4
- package/src/clock.ts +183 -0
- package/src/context.tsx +165 -0
- package/src/geometry.ts +107 -0
- package/src/index.ts +48 -0
- package/src/registry.ts +161 -0
- package/src/types.ts +92 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Dorian Mazur
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,20 @@
|
|
|
1
|
-
#
|
|
1
|
+
# nitro-screen-choreography
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Choreographed multi-element shared transitions for [NitroUI](https://github.com/margelo/nitro-ui).
|
|
4
|
+
|
|
5
|
+
> **Early Alpha (`0.0.1-alpha.0`)** — Core registration, group-scoped pair matching, synchronous window-frame measurement, frame interpolation, and a main-thread progress clock are implemented. Native overlay window hosting and `nitro-ui-navigation` stack integration are under active development.
|
|
6
|
+
|
|
7
|
+
## Why NitroUI?
|
|
8
|
+
|
|
9
|
+
Because NitroUI runs Hermes and React synchronously on the native UI thread and exposes direct `View.getFrameInWindow()` measurement and native view mutations, multi-element choreography does not need Fabric shadow-tree observers, JS-to-UI bridges, or worklet serialization.
|
|
10
|
+
|
|
11
|
+
## Included in this alpha
|
|
12
|
+
|
|
13
|
+
- `ChoreographyRegistry` — compound `(screenId, groupId, id)` registration, group-scoped pair discovery, and synchronous frame capture via `view.getFrameInWindow()`.
|
|
14
|
+
- `ProgressClock` — interruptible `0 -> 1` progress clock driven by `requestAnimationFrame` with spring and eased timing curves, plus manual scrubbing (`setProgress`).
|
|
15
|
+
- Geometry & visibility helpers — `interpolateFrame`, `deriveTransformFromFrames`, and direction-agnostic `deriveScreenOpacity`.
|
|
16
|
+
- React primitives — `ChoreographyProvider`, `useChoreography`, `useChoreographyProgress`, and `useSharedElement`.
|
|
17
|
+
|
|
18
|
+
## License
|
|
19
|
+
|
|
20
|
+
MIT
|
package/dist/clock.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { ProgressListener, SpringOptions, TimingOptions } from './types.js';
|
|
2
|
+
export interface FrameScheduler {
|
|
3
|
+
now(): number;
|
|
4
|
+
requestFrame(cb: (timestampMs: number) => void): number;
|
|
5
|
+
cancelFrame(handle: number): void;
|
|
6
|
+
}
|
|
7
|
+
export declare function easeOutCubic(t: number): number;
|
|
8
|
+
/**
|
|
9
|
+
* Synchronous main-thread progress clock (`0` = collapsed, `1` = expanded).
|
|
10
|
+
* Designed for NitroUI where Hermes runs directly on the UI thread, enabling
|
|
11
|
+
* interruptible timing/spring choreography and manual gesture scrubbing.
|
|
12
|
+
*/
|
|
13
|
+
export declare class ProgressClock {
|
|
14
|
+
private value;
|
|
15
|
+
private velocity;
|
|
16
|
+
private activeHandle;
|
|
17
|
+
private readonly listeners;
|
|
18
|
+
private readonly scheduler;
|
|
19
|
+
constructor(initialValue?: number, scheduler?: FrameScheduler);
|
|
20
|
+
get progress(): number;
|
|
21
|
+
get isRunning(): boolean;
|
|
22
|
+
subscribe(listener: ProgressListener): () => void;
|
|
23
|
+
setProgress(nextValue: number): void;
|
|
24
|
+
stop(): void;
|
|
25
|
+
animateTo(target: number, options?: TimingOptions, onComplete?: (finished: boolean) => void): void;
|
|
26
|
+
animateSpringTo(target: number, options?: SpringOptions, onComplete?: (finished: boolean) => void): void;
|
|
27
|
+
private emit;
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=clock.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clock.d.ts","sourceRoot":"","sources":["../src/clock.ts"],"names":[],"mappings":"AAA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.performance ? g.performance.now() : Date.now());
|
|
4
|
+
if (typeof g.requestAnimationFrame === 'function' && typeof g.cancelAnimationFrame === 'function') {
|
|
5
|
+
const raf = g.requestAnimationFrame.bind(g);
|
|
6
|
+
const caf = g.cancelAnimationFrame.bind(g);
|
|
7
|
+
return {
|
|
8
|
+
now,
|
|
9
|
+
requestFrame: (cb) => raf(cb),
|
|
10
|
+
cancelFrame: (id) => caf(id),
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
return {
|
|
14
|
+
now,
|
|
15
|
+
requestFrame: (cb) => Number(g.setTimeout(() => cb(now()), 16)),
|
|
16
|
+
cancelFrame: (id) => g.clearTimeout(id),
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
export function easeOutCubic(t) {
|
|
20
|
+
const inv = 1 - Math.min(1, Math.max(0, t));
|
|
21
|
+
return 1 - inv * inv * inv;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Synchronous main-thread progress clock (`0` = collapsed, `1` = expanded).
|
|
25
|
+
* Designed for NitroUI where Hermes runs directly on the UI thread, enabling
|
|
26
|
+
* interruptible timing/spring choreography and manual gesture scrubbing.
|
|
27
|
+
*/
|
|
28
|
+
export class ProgressClock {
|
|
29
|
+
value;
|
|
30
|
+
velocity = 0;
|
|
31
|
+
activeHandle = null;
|
|
32
|
+
listeners = new Set();
|
|
33
|
+
scheduler;
|
|
34
|
+
constructor(initialValue = 0, scheduler) {
|
|
35
|
+
this.value = initialValue;
|
|
36
|
+
this.scheduler = scheduler ?? getDefaultScheduler();
|
|
37
|
+
}
|
|
38
|
+
get progress() {
|
|
39
|
+
return this.value;
|
|
40
|
+
}
|
|
41
|
+
get isRunning() {
|
|
42
|
+
return this.activeHandle !== null;
|
|
43
|
+
}
|
|
44
|
+
subscribe(listener) {
|
|
45
|
+
this.listeners.add(listener);
|
|
46
|
+
return () => {
|
|
47
|
+
this.listeners.delete(listener);
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
setProgress(nextValue) {
|
|
51
|
+
this.stop();
|
|
52
|
+
this.velocity = 0;
|
|
53
|
+
this.emit(nextValue);
|
|
54
|
+
}
|
|
55
|
+
stop() {
|
|
56
|
+
if (this.activeHandle !== null) {
|
|
57
|
+
this.scheduler.cancelFrame(this.activeHandle);
|
|
58
|
+
this.activeHandle = null;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
animateTo(target, options = {}, onComplete) {
|
|
62
|
+
this.stop();
|
|
63
|
+
const durationMs = options.durationMs ?? 320;
|
|
64
|
+
const easing = options.easing ?? easeOutCubic;
|
|
65
|
+
const startValue = this.value;
|
|
66
|
+
if (durationMs <= 0 || Math.abs(target - startValue) === 0) {
|
|
67
|
+
this.velocity = 0;
|
|
68
|
+
this.emit(target);
|
|
69
|
+
onComplete?.(true);
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
const startTime = this.scheduler.now();
|
|
73
|
+
const step = (timestamp) => {
|
|
74
|
+
const elapsed = Math.max(0, timestamp - startTime);
|
|
75
|
+
const rawT = Math.min(1, elapsed / durationMs);
|
|
76
|
+
const eased = easing(rawT);
|
|
77
|
+
const next = startValue + (target - startValue) * eased;
|
|
78
|
+
this.emit(next);
|
|
79
|
+
if (rawT >= 1) {
|
|
80
|
+
this.activeHandle = null;
|
|
81
|
+
this.velocity = 0;
|
|
82
|
+
this.emit(target);
|
|
83
|
+
onComplete?.(true);
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
this.activeHandle = this.scheduler.requestFrame(step);
|
|
87
|
+
};
|
|
88
|
+
this.activeHandle = this.scheduler.requestFrame(step);
|
|
89
|
+
}
|
|
90
|
+
animateSpringTo(target, options = {}, onComplete) {
|
|
91
|
+
this.stop();
|
|
92
|
+
const stiffness = options.stiffness ?? 260;
|
|
93
|
+
const damping = options.damping ?? 28;
|
|
94
|
+
const mass = options.mass ?? 1;
|
|
95
|
+
const restDisplacement = options.restDisplacementThreshold ?? 0.001;
|
|
96
|
+
const restSpeed = options.restSpeedThreshold ?? 0.001;
|
|
97
|
+
if (options.initialVelocity !== undefined) {
|
|
98
|
+
this.velocity = options.initialVelocity;
|
|
99
|
+
}
|
|
100
|
+
let lastTime = this.scheduler.now();
|
|
101
|
+
const step = (timestamp) => {
|
|
102
|
+
// Cap dt at 32ms to keep integration stable across dropped frames.
|
|
103
|
+
const dt = Math.min(0.032, Math.max(0.001, (timestamp - lastTime) / 1000));
|
|
104
|
+
lastTime = timestamp;
|
|
105
|
+
const displacement = this.value - target;
|
|
106
|
+
const springForce = -stiffness * displacement;
|
|
107
|
+
const dampingForce = -damping * this.velocity;
|
|
108
|
+
const acceleration = (springForce + dampingForce) / mass;
|
|
109
|
+
this.velocity += acceleration * dt;
|
|
110
|
+
const next = this.value + this.velocity * dt;
|
|
111
|
+
this.emit(next);
|
|
112
|
+
if (Math.abs(target - next) <= restDisplacement &&
|
|
113
|
+
Math.abs(this.velocity) <= restSpeed) {
|
|
114
|
+
this.activeHandle = null;
|
|
115
|
+
this.velocity = 0;
|
|
116
|
+
this.emit(target);
|
|
117
|
+
onComplete?.(true);
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
this.activeHandle = this.scheduler.requestFrame(step);
|
|
121
|
+
};
|
|
122
|
+
this.activeHandle = this.scheduler.requestFrame(step);
|
|
123
|
+
}
|
|
124
|
+
emit(nextValue) {
|
|
125
|
+
this.value = nextValue;
|
|
126
|
+
for (const listener of this.listeners) {
|
|
127
|
+
listener(nextValue);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
//# sourceMappingURL=clock.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clock.js","sourceRoot":"","sources":["../src/clock.ts"],"names":[],"mappings":"AAQA,SAAS,mBAAmB;IAC1B,MAAM,CAAC,GAAG,UAMT,CAAC;IAEF,MAAM,GAAG,GAAG,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,C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AAM,GAAG,IAAI,CAAC,IAAI,gBAAgB;gBAC3C,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,SAAS,EACpC,CAAC;gBACD,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC;gBACzB,IAAI,CAAC,QAAQ,GAAG,CAAC,CAAC;gBAClB,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;gBAClB,UAAU,EAAE,CAAC,IAAI,CAAC,CAAC;gBACnB,OAAO;YACT,CAAC;YAED,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;QACxD,CAAC,CAAC;QAEF,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;IACxD,CAAC;IAEO,IAAI,CAAC,SAAiB;QAC5B,IAAI,CAAC,KAAK,GAAG,SAAS,CAAC;QACvB,KAAK,MAAM,QAAQ,IAAI,IAAI,CAAC,SAAS,EAAE,CAAC;YACtC,QAAQ,CAAC,SAAS,CAAC,CAAC;QACtB,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import React, { type ReactNode, type RefObject } from 'react';
|
|
2
|
+
import { ProgressClock } from './clock.js';
|
|
3
|
+
import { ChoreographyRegistry } from './registry.js';
|
|
4
|
+
import type { ElementPresentation, NitroViewLike, TransitionDirection, TransitionSession } from './types.js';
|
|
5
|
+
export interface ChoreographyActions {
|
|
6
|
+
readonly registry: ChoreographyRegistry;
|
|
7
|
+
readonly clock: ProgressClock;
|
|
8
|
+
startSession(options: {
|
|
9
|
+
sourceScreenId: string;
|
|
10
|
+
targetScreenId: string;
|
|
11
|
+
direction: TransitionDirection;
|
|
12
|
+
groupId?: string;
|
|
13
|
+
}): TransitionSession | null;
|
|
14
|
+
endSession(): void;
|
|
15
|
+
}
|
|
16
|
+
export interface ChoreographyProviderProps {
|
|
17
|
+
children: ReactNode;
|
|
18
|
+
}
|
|
19
|
+
export declare function ChoreographyProvider({ children }: ChoreographyProviderProps): React.JSX.Element;
|
|
20
|
+
export declare function useChoreographyActions(): ChoreographyActions;
|
|
21
|
+
export declare function useChoreographySession(): TransitionSession | null;
|
|
22
|
+
/**
|
|
23
|
+
* Subscribes to the provider's shared `0 -> 1` transition progress.
|
|
24
|
+
*/
|
|
25
|
+
export declare function useChoreographyProgress(): number;
|
|
26
|
+
export interface UseSharedElementOptions {
|
|
27
|
+
id: string;
|
|
28
|
+
screenId: string;
|
|
29
|
+
groupId?: string;
|
|
30
|
+
ref: RefObject<NitroViewLike | null>;
|
|
31
|
+
presentation?: ElementPresentation;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Registers a NitroUI view ref stably by `(screenId, groupId, id)`.
|
|
35
|
+
* Presentation updates are read through a ref so registration never churns on re-render.
|
|
36
|
+
*/
|
|
37
|
+
export declare function useSharedElement({ id, screenId, groupId, ref, presentation, }: UseSharedElementOptions): void;
|
|
38
|
+
//# sourceMappingURL=context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../src/context.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAQZ,KAAK,SAAS,EACd,KAAK,SAAS,EACf,MAAM,OAAO,CAAC;AACf,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAC3C,OAAO,EAAE,oBAAoB,EAAoB,MAAM,eAAe,CAAC;AACvE,OAAO,KAAK,EACV,mBAAmB,EACnB,aAAa,EACb,mBAAmB,EACnB,iBAAiB,EAClB,MAAM,YAAY,CAAC;AAEpB,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,QAAQ,EAAE,oBAAoB,CAAC;IACxC,QAAQ,CAAC,KAAK,EAAE,aAAa,CAAC;IAC9B,YAAY,CAAC,OAAO,EAAE;QACpB,cAAc,EAAE,MAAM,CAAC;QACvB,cAAc,EAAE,MAAM,CAAC;QACvB,SAAS,EAAE,mBAAmB,CAAC;QAC/B,OAAO,CAAC,EAAE,MAAM,CAAC;KAClB,GAAG,iBAAiB,GAAG,IAAI,CAAC;IAC7B,UAAU,IAAI,IAAI,CAAC;CACpB;AAKD,MAAM,WAAW,yBAAyB;IACxC,QAAQ,EAAE,SAAS,CAAC;CACrB;AAED,wBAAgB,oBAAoB,CAAC,EAAE,QAAQ,EAAE,EAAE,yBAAyB,qBAmE3E;AAED,wBAAgB,sBAAsB,IAAI,mBAAmB,CAM5D;AAED,wBAAgB,sBAAsB,IAAI,iBAAiB,GAAG,IAAI,CAEjE;AAED;;GAEG;AACH,wBAAgB,uBAAuB,IAAI,MAAM,CAOhD;AAED,MAAM,WAAW,uBAAuB;IACtC,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,GAAG,EAAE,SAAS,CAAC,aAAa,GAAG,IAAI,CAAC,CAAC;IACrC,YAAY,CAAC,EAAE,mBAAmB,CAAC;CACpC;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,EAC/B,EAAE,EACF,QAAQ,EACR,OAA0B,EAC1B,GAAG,EACH,YAAY,GACb,EAAE,uBAAuB,GAAG,IAAI,CAchC"}
|
package/dist/context.js
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { createContext, useContext, useEffect, useMemo, useRef, useState, useSyncExternalStore, } from 'react';
|
|
3
|
+
import { ProgressClock } from './clock.js';
|
|
4
|
+
import { ChoreographyRegistry, DEFAULT_GROUP_ID } from './registry.js';
|
|
5
|
+
const ChoreographyActionsContext = createContext(null);
|
|
6
|
+
const ChoreographySessionContext = createContext(null);
|
|
7
|
+
export function ChoreographyProvider({ children }) {
|
|
8
|
+
const registryRef = useRef(null);
|
|
9
|
+
if (!registryRef.current) {
|
|
10
|
+
registryRef.current = new ChoreographyRegistry();
|
|
11
|
+
}
|
|
12
|
+
const clockRef = useRef(null);
|
|
13
|
+
if (!clockRef.current) {
|
|
14
|
+
clockRef.current = new ProgressClock(0);
|
|
15
|
+
}
|
|
16
|
+
const sessionCounterRef = useRef(0);
|
|
17
|
+
const [session, setSession] = useState(null);
|
|
18
|
+
const actions = useMemo(() => {
|
|
19
|
+
const registry = registryRef.current;
|
|
20
|
+
const clock = clockRef.current;
|
|
21
|
+
return {
|
|
22
|
+
registry,
|
|
23
|
+
clock,
|
|
24
|
+
startSession({ sourceScreenId, targetScreenId, direction, groupId }) {
|
|
25
|
+
const resolvedGroup = groupId ?? DEFAULT_GROUP_ID;
|
|
26
|
+
const pairs = registry.resolvePairs({
|
|
27
|
+
sourceScreenId,
|
|
28
|
+
targetScreenId,
|
|
29
|
+
groupId: resolvedGroup,
|
|
30
|
+
});
|
|
31
|
+
if (pairs.length === 0) {
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
sessionCounterRef.current += 1;
|
|
35
|
+
const nextSession = {
|
|
36
|
+
id: `session-${sessionCounterRef.current}`,
|
|
37
|
+
groupId: resolvedGroup,
|
|
38
|
+
direction,
|
|
39
|
+
phase: 'active',
|
|
40
|
+
sourceScreenId,
|
|
41
|
+
targetScreenId,
|
|
42
|
+
pairs,
|
|
43
|
+
};
|
|
44
|
+
setSession(nextSession);
|
|
45
|
+
return nextSession;
|
|
46
|
+
},
|
|
47
|
+
endSession() {
|
|
48
|
+
clock.stop();
|
|
49
|
+
setSession(null);
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
}, []);
|
|
53
|
+
useEffect(() => {
|
|
54
|
+
const clock = clockRef.current;
|
|
55
|
+
const registry = registryRef.current;
|
|
56
|
+
return () => {
|
|
57
|
+
clock.stop();
|
|
58
|
+
registry.clear();
|
|
59
|
+
};
|
|
60
|
+
}, []);
|
|
61
|
+
return (_jsx(ChoreographyActionsContext.Provider, { value: actions, children: _jsx(ChoreographySessionContext.Provider, { value: session, children: children }) }));
|
|
62
|
+
}
|
|
63
|
+
export function useChoreographyActions() {
|
|
64
|
+
const actions = useContext(ChoreographyActionsContext);
|
|
65
|
+
if (!actions) {
|
|
66
|
+
throw new Error('useChoreographyActions must be used inside a ChoreographyProvider.');
|
|
67
|
+
}
|
|
68
|
+
return actions;
|
|
69
|
+
}
|
|
70
|
+
export function useChoreographySession() {
|
|
71
|
+
return useContext(ChoreographySessionContext);
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Subscribes to the provider's shared `0 -> 1` transition progress.
|
|
75
|
+
*/
|
|
76
|
+
export function useChoreographyProgress() {
|
|
77
|
+
const { clock } = useChoreographyActions();
|
|
78
|
+
return useSyncExternalStore((onStoreChange) => clock.subscribe(onStoreChange), () => clock.progress, () => 0);
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Registers a NitroUI view ref stably by `(screenId, groupId, id)`.
|
|
82
|
+
* Presentation updates are read through a ref so registration never churns on re-render.
|
|
83
|
+
*/
|
|
84
|
+
export function useSharedElement({ id, screenId, groupId = DEFAULT_GROUP_ID, ref, presentation, }) {
|
|
85
|
+
const { registry } = useChoreographyActions();
|
|
86
|
+
const presentationRef = useRef(presentation ?? {});
|
|
87
|
+
presentationRef.current = presentation ?? {};
|
|
88
|
+
useEffect(() => {
|
|
89
|
+
return registry.register({
|
|
90
|
+
id,
|
|
91
|
+
screenId,
|
|
92
|
+
groupId,
|
|
93
|
+
getView: () => ref.current,
|
|
94
|
+
getPresentation: () => presentationRef.current,
|
|
95
|
+
});
|
|
96
|
+
}, [registry, id, screenId, groupId, ref]);
|
|
97
|
+
}
|
|
98
|
+
//# sourceMappingURL=context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.js","sourceRoot":"","sources":["../src/context.tsx"],"names":[],"mappings":";AAAA,OAAc,EACZ,aAAa,EACb,UAAU,EACV,SAAS,EACT,OAAO,EACP,MAAM,EACN,QAAQ,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ED,MAAM,UAAU,sBAAsB;IACpC,OAAO,UAAU,CAAC,0BAA0B,CAAC,CAAC;AAChD,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,uBAAuB;IACrC,MAAM,EAAE,KAAK,EAAE,GAAG,sBAAsB,EAAE,CAAC;IAC3C,OAAO,oBAAoB,CACzB,CAAC,aAAa,EAAE,EAAE,CAAC,KAAK,CAAC,SAAS,CAAC,aAAa,CAAC,EACjD,GAAG,EAAE,CAAC,KAAK,CAAC,QAAQ,EACpB,GAAG,EAAE,CAAC,CAAC,CACR,CAAC;AACJ,CAAC;AAUD;;;GAGG;AACH,MAAM,UAAU,gBAAgB,CAAC,EAC/B,EAAE,EACF,QAAQ,EACR,OAAO,GAAG,gBAAgB,EAC1B,GAAG,EACH,YAAY,GACY;IACxB,MAAM,EAAE,QAAQ,EAAE,GAAG,sBAAsB,EAAE,CAAC;IAC9C,MAAM,eAAe,GAAG,MAAM,CAAsB,YAAY,IAAI,EAAE,CAAC,CAAC;IACxE,eAAe,CAAC,OAAO,GAAG,YAAY,IAAI,EAAE,CAAC;IAE7C,SAAS,CAAC,GAAG,EAAE;QACb,OAAO,QAAQ,CAAC,QAAQ,CAAC;YACvB,EAAE;YACF,QAAQ;YACR,OAAO;YACP,OAAO,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,OAAO;YAC1B,eAAe,EAAE,GAAG,EAAE,CAAC,eAAe,CAAC,OAAO;SAC/C,CAAC,CAAC;IACL,CAAC,EAAE,CAAC,QAAQ,EAAE,EAAE,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,CAAC,CAAC,CAAC;AAC7C,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { ElementFrame, ScreenRole, TransitionDirection, TransitionPhase, TransitionSession } from './types.js';
|
|
2
|
+
export declare function clamp(value: number, min: number, max: number): number;
|
|
3
|
+
export declare function lerp(from: number, to: number, progress: number): number;
|
|
4
|
+
/**
|
|
5
|
+
* Linearly interpolates window frames between two endpoints.
|
|
6
|
+
*/
|
|
7
|
+
export declare function interpolateFrame(from: ElementFrame, to: ElementFrame, progress: number): ElementFrame;
|
|
8
|
+
export interface FrameTransform {
|
|
9
|
+
readonly translateX: number;
|
|
10
|
+
readonly translateY: number;
|
|
11
|
+
readonly scaleX: number;
|
|
12
|
+
readonly scaleY: number;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Computes center-anchored translation + scale that maps `base` onto `current`.
|
|
16
|
+
* Suitable for NitroUI's `view.setTranslation(...)` and `view.setScale(...)`.
|
|
17
|
+
*/
|
|
18
|
+
export declare function deriveTransformFromFrames(base: ElementFrame, current: ElementFrame): FrameTransform;
|
|
19
|
+
export interface ScreenFadeConfig {
|
|
20
|
+
readonly during: readonly [number, number];
|
|
21
|
+
}
|
|
22
|
+
export declare function getScreenRole(session: TransitionSession | null, screenId: string): ScreenRole;
|
|
23
|
+
/**
|
|
24
|
+
* Direction-agnostic screen opacity derivation matching screen-choreography's
|
|
25
|
+
* collapsed (0) <-> expanded (1) progress semantics.
|
|
26
|
+
*/
|
|
27
|
+
export declare function deriveScreenOpacity(direction: TransitionDirection, role: ScreenRole, phase: TransitionPhase, progress: number, screenFade?: ScreenFadeConfig): number;
|
|
28
|
+
//# sourceMappingURL=geometry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"geometry.d.ts","sourceRoot":"","sources":["../src/geometry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,YAAY,EACZ,UAAU,EACV,mBAAmB,EACnB,eAAe,EACf,iBAAiB,EAClB,MAAM,YAAY,CAAC;AAEpB,wBAAgB,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAErE;AAED,wBAAgB,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAEvE;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAC9B,IAAI,EAAE,YAAY,EAClB,EAAE,EAAE,YAAY,EAChB,QAAQ,EAAE,MAAM,GACf,YAAY,CAOd;AAED,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB;AAED;;;GAGG;AACH,wBAAgB,yBAAyB,CACvC,IAAI,EAAE,YAAY,EAClB,OAAO,EAAE,YAAY,GACpB,cAAc,CAYhB;AAED,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,MAAM,EAAE,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC5C;AAED,wBAAgB,aAAa,CAC3B,OAAO,EAAE,iBAAiB,GAAG,IAAI,EACjC,QAAQ,EAAE,MAAM,GACf,UAAU,CAKZ;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CACjC,SAAS,EAAE,mBAAmB,EAC9B,IAAI,EAAE,UAAU,EAChB,KAAK,EAAE,eAAe,EACtB,QAAQ,EAAE,MAAM,EAChB,UAAU,CAAC,EAAE,gBAAgB,GAC5B,MAAM,CAsBR"}
|
package/dist/geometry.js
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
export function clamp(value, min, max) {
|
|
2
|
+
return Math.min(max, Math.max(min, value));
|
|
3
|
+
}
|
|
4
|
+
export function lerp(from, to, progress) {
|
|
5
|
+
return from + (to - from) * progress;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Linearly interpolates window frames between two endpoints.
|
|
9
|
+
*/
|
|
10
|
+
export function interpolateFrame(from, to, progress) {
|
|
11
|
+
return {
|
|
12
|
+
x: lerp(from.x, to.x, progress),
|
|
13
|
+
y: lerp(from.y, to.y, progress),
|
|
14
|
+
width: Math.max(0, lerp(from.width, to.width, progress)),
|
|
15
|
+
height: Math.max(0, lerp(from.height, to.height, progress)),
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Computes center-anchored translation + scale that maps `base` onto `current`.
|
|
20
|
+
* Suitable for NitroUI's `view.setTranslation(...)` and `view.setScale(...)`.
|
|
21
|
+
*/
|
|
22
|
+
export function deriveTransformFromFrames(base, current) {
|
|
23
|
+
const baseCenterX = base.x + base.width / 2;
|
|
24
|
+
const baseCenterY = base.y + base.height / 2;
|
|
25
|
+
const currentCenterX = current.x + current.width / 2;
|
|
26
|
+
const currentCenterY = current.y + current.height / 2;
|
|
27
|
+
return {
|
|
28
|
+
translateX: currentCenterX - baseCenterX,
|
|
29
|
+
translateY: currentCenterY - baseCenterY,
|
|
30
|
+
scaleX: base.width > 0 ? current.width / base.width : 1,
|
|
31
|
+
scaleY: base.height > 0 ? current.height / base.height : 1,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
export function getScreenRole(session, screenId) {
|
|
35
|
+
if (!session)
|
|
36
|
+
return 'inactive';
|
|
37
|
+
if (session.sourceScreenId === screenId)
|
|
38
|
+
return 'source';
|
|
39
|
+
if (session.targetScreenId === screenId)
|
|
40
|
+
return 'target';
|
|
41
|
+
return 'inactive';
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Direction-agnostic screen opacity derivation matching screen-choreography's
|
|
45
|
+
* collapsed (0) <-> expanded (1) progress semantics.
|
|
46
|
+
*/
|
|
47
|
+
export function deriveScreenOpacity(direction, role, phase, progress, screenFade) {
|
|
48
|
+
if (role === 'inactive' ||
|
|
49
|
+
phase === 'idle' ||
|
|
50
|
+
phase === 'completing' ||
|
|
51
|
+
phase === 'cancelling') {
|
|
52
|
+
return 1;
|
|
53
|
+
}
|
|
54
|
+
if (phase === 'preparing') {
|
|
55
|
+
if (role === 'target') {
|
|
56
|
+
return direction === 'backward' ? 1 : 0;
|
|
57
|
+
}
|
|
58
|
+
return 1;
|
|
59
|
+
}
|
|
60
|
+
const isExpandedScreen = direction === 'forward' ? role === 'target' : role === 'source';
|
|
61
|
+
const [start, end] = screenFade?.during ?? [0, 0.4];
|
|
62
|
+
const expandedOpacity = clamp((progress - start) / (end - start), 0, 1);
|
|
63
|
+
return isExpandedScreen ? expandedOpacity : 1 - expandedOpacity;
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=geometry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"geometry.js","sourceRoot":"","sources":["../src/geometry.ts"],"names":[],"mappings":"AAQA,MAAM,UAAU,KAAK,CAAC,KAAa,EAAE,GAAW,EAAE,GAAW;IAC3D,OAAO,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC,CAAC;AAC7C,CAAC;AAED,MAAM,UAAU,IAAI,CAAC,IAAY,EAAE,EAAU,EAAE,QAAgB;IAC7D,OAAO,IAAI,GAAG,CAAC,EAAE,GAAG,IAAI,CAAC,GAAG,QAAQ,CAAC;AACvC,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAC9B,IAAkB,EAClB,EAAgB,EAChB,QAAgB;IAEhB,OAAO;QACL,CAAC,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,QAAQ,CAAC;QAC/B,CAAC,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,QAAQ,CAAC;QAC/B,KAAK,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;QACxD,MAAM,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,EAAE,QAAQ,CA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AK,KAAK,MAAM;QAChB,KAAK,KAAK,YAAY;QACtB,KAAK,KAAK,YAAY,EACtB,CAAC;QACD,OAAO,CAAC,CAAC;IACX,CAAC;IAED,IAAI,KAAK,KAAK,WAAW,EAAE,CAAC;QAC1B,IAAI,IAAI,KAAK,QAAQ,EAAE,CAAC;YACtB,OAAO,SAAS,KAAK,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QAC1C,CAAC;QACD,OAAO,CAAC,CAAC;IACX,CAAC;IAED,MAAM,gBAAgB,GACpB,SAAS,KAAK,SAAS,CAAC,CAAC,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,KAAK,QAAQ,CAAC;IAClE,MAAM,CAAC,KAAK,EAAE,GAAG,CAAC,GAAG,UAAU,EAAE,MAAM,IAAI,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;IACpD,MAAM,eAAe,GAAG,KAAK,CAAC,CAAC,QAAQ,GAAG,KAAK,CAAC,GAAG,CAAC,GAAG,GAAG,KAAK,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;IACxE,OAAO,gBAAgB,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,GAAG,eAAe,CAAC;AAClE,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { ProgressClock, easeOutCubic, type FrameScheduler, } from './clock.js';
|
|
2
|
+
export { ChoreographyProvider, useChoreographyActions, useChoreographyProgress, useChoreographySession, useSharedElement, type ChoreographyActions, type ChoreographyProviderProps, type UseSharedElementOptions, } from './context.js';
|
|
3
|
+
export { clamp, deriveScreenOpacity, deriveTransformFromFrames, getScreenRole, interpolateFrame, lerp, type FrameTransform, type ScreenFadeConfig, } from './geometry.js';
|
|
4
|
+
export { ChoreographyRegistry, DEFAULT_GROUP_ID, isValidFrame, makeElementKey, measureNitroView, type RegisterElementInput, } from './registry.js';
|
|
5
|
+
export type { ElementFrame, ElementPresentation, FrozenEndpoint, MatchedPair, NitroViewLike, ProgressListener, RegisteredElement, ScreenRole, SpringOptions, TimingOptions, TransitionDirection, TransitionPhase, TransitionSession, } from './types.js';
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,YAAY,EACZ,KAAK,cAAc,GACpB,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,oBAAoB,EACpB,sBAAsB,EACtB,uBAAuB,EACvB,sBAAsB,EACtB,gBAAgB,EAChB,KAAK,mBAAmB,EACxB,KAAK,yBAAyB,EAC9B,KAAK,uBAAuB,GAC7B,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,KAAK,EACL,mBAAmB,EACnB,yBAAyB,EACzB,aAAa,EACb,gBAAgB,EAChB,IAAI,EACJ,KAAK,cAAc,EACnB,KAAK,gBAAgB,GACtB,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,oBAAoB,EACpB,gBAAgB,EAChB,YAAY,EACZ,cAAc,EACd,gBAAgB,EAChB,KAAK,oBAAoB,GAC1B,MAAM,eAAe,CAAC;AACvB,YAAY,EACV,YAAY,EACZ,mBAAmB,EACnB,cAAc,EACd,WAAW,EACX,aAAa,EACb,gBAAgB,EAChB,iBAAiB,EACjB,UAAU,EACV,aAAa,EACb,aAAa,EACb,mBAAmB,EACnB,eAAe,EACf,iBAAiB,GAClB,MAAM,YAAY,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { ProgressClock, easeOutCubic, } from './clock.js';
|
|
2
|
+
export { ChoreographyProvider, useChoreographyActions, useChoreographyProgress, useChoreographySession, useSharedElement, } from './context.js';
|
|
3
|
+
export { clamp, deriveScreenOpacity, deriveTransformFromFrames, getScreenRole, interpolateFrame, lerp, } from './geometry.js';
|
|
4
|
+
export { ChoreographyRegistry, DEFAULT_GROUP_ID, isValidFrame, makeElementKey, measureNitroView, } from './registry.js';
|
|
5
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,YAAY,GAEb,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,oBAAoB,EACpB,sBAAsB,EACtB,uBAAuB,EACvB,sBAAsB,EACtB,gBAAgB,GAIjB,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,KAAK,EACL,mBAAmB,EACnB,yBAAyB,EACzB,aAAa,EACb,gBAAgB,EAChB,IAAI,GAGL,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,oBAAoB,EACpB,gBAAgB,EAChB,YAAY,EACZ,cAAc,EACd,gBAAgB,GAEjB,MAAM,eAAe,CAAC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { ElementFrame, ElementPresentation, FrozenEndpoint, MatchedPair, NitroViewLike, RegisteredElement } from './types.js';
|
|
2
|
+
export declare const DEFAULT_GROUP_ID = "default";
|
|
3
|
+
export declare function makeElementKey(screenId: string, groupId: string, id: string): string;
|
|
4
|
+
export declare function isValidFrame(frame: ElementFrame | null | undefined): frame is ElementFrame;
|
|
5
|
+
/**
|
|
6
|
+
* Measures a NitroUI view synchronously in window coordinates.
|
|
7
|
+
*/
|
|
8
|
+
export declare function measureNitroView(view: NitroViewLike | null): ElementFrame | null;
|
|
9
|
+
export interface RegisterElementInput {
|
|
10
|
+
id: string;
|
|
11
|
+
screenId: string;
|
|
12
|
+
groupId?: string;
|
|
13
|
+
getView: () => NitroViewLike | null;
|
|
14
|
+
getPresentation?: () => ElementPresentation;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Compound-keyed registry for NitroUI shared elements.
|
|
18
|
+
* Registrations are keyed by `(screenId, groupId, id)` and pair discovery is
|
|
19
|
+
* scoped to the requested group.
|
|
20
|
+
*/
|
|
21
|
+
export declare class ChoreographyRegistry {
|
|
22
|
+
private readonly elements;
|
|
23
|
+
register(input: RegisterElementInput): () => void;
|
|
24
|
+
get(screenId: string, id: string, groupId?: string): RegisteredElement | undefined;
|
|
25
|
+
getScreenElements(screenId: string, groupId?: string): RegisteredElement[];
|
|
26
|
+
/**
|
|
27
|
+
* Captures a frozen snapshot of all valid element frames for a screen/group.
|
|
28
|
+
* Useful before navigation if the source screen may detach or move.
|
|
29
|
+
*/
|
|
30
|
+
captureScreen(screenId: string, groupId?: string): Map<string, FrozenEndpoint>;
|
|
31
|
+
/**
|
|
32
|
+
* Resolves matching pairs between `sourceScreenId` and `targetScreenId` within `groupId`.
|
|
33
|
+
* Accepts an optional pre-navigation source snapshot.
|
|
34
|
+
*/
|
|
35
|
+
resolvePairs(options: {
|
|
36
|
+
sourceScreenId: string;
|
|
37
|
+
targetScreenId: string;
|
|
38
|
+
groupId?: string;
|
|
39
|
+
capturedSource?: ReadonlyMap<string, FrozenEndpoint>;
|
|
40
|
+
}): MatchedPair[];
|
|
41
|
+
clear(): void;
|
|
42
|
+
get size(): number;
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=registry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../src/registry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,YAAY,EACZ,mBAAmB,EACnB,cAAc,EACd,WAAW,EACX,aAAa,EACb,iBAAiB,EAClB,MAAM,YAAY,CAAC;AAEpB,eAAO,MAAM,gBAAgB,YAAY,CAAC;AAE1C,wBAAgB,cAAc,CAC5B,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,MAAM,EACf,EAAE,EAAE,MAAM,GACT,MAAM,CAER;AAED,wBAAgB,YAAY,CAAC,KAAK,EAAE,YAAY,GAAG,IAAI,GAAG,SAAS,GAAG,KAAK,IAAI,YAA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