@wcstack/view-transition 1.31.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,310 @@
1
+ /**
2
+ * Global key the arbiter installs itself under. `Symbol.for` so independently
3
+ * loaded copies of this file (two CDN bundles on one page) still agree.
4
+ */
5
+ declare const TRANSITION_RUNNER_KEY: unique symbol;
6
+ /** Who is asking. Backs the arbiter's `for=` participant gate. */
7
+ type TransitionSource = "router" | "state";
8
+ /** `view-transition-name` assignment policy the arbiter declares for participants. */
9
+ type TransitionNaming = "manual" | "auto";
10
+ interface IWcsTransitionRunOptions {
11
+ /** Participant id, for the `for=` gate and for diagnostics. */
12
+ readonly source?: string;
13
+ /** Transition types, where the environment supports `startViewTransition({ types })`. */
14
+ readonly types?: readonly string[];
15
+ }
16
+ interface IWcsTransitionRunner {
17
+ readonly protocol: "wcs-transition-runner";
18
+ /** Integer protocol version. All versions >= 1 are participant-compatible. */
19
+ readonly version: number;
20
+ /** `"auto"` licenses a participant to assign `view-transition-name` itself. */
21
+ readonly naming: TransitionNaming;
22
+ /** Upper bound on auto-assigned names; past it a participant stops naming. */
23
+ readonly namingLimit: number;
24
+ /** Whether this participant animates at all. */
25
+ accepts(source: string): boolean;
26
+ /**
27
+ * Invoke `mutate` inside a view transition when one is possible.
28
+ *
29
+ * Contract (docs/view-transition-design.md §4):
30
+ * - `mutate` is invoked exactly once, whatever happens to the transition.
31
+ * - The promise resolves once `mutate` has run — never waits for the animation.
32
+ * - When no transition is started, `mutate` runs synchronously inside `run()`.
33
+ * - It rejects only if `mutate` threw.
34
+ */
35
+ run(mutate: () => void, options?: IWcsTransitionRunOptions): Promise<void>;
36
+ }
37
+ /**
38
+ * The installed arbiter, or null when there is none, it speaks a version this
39
+ * reader does not, or it does not accept this participant.
40
+ *
41
+ * Looked up on every call rather than cached: the tag can be added, removed, or
42
+ * reconfigured at any point in a page's life, and a stale cache would either
43
+ * animate what the author just switched off or miss what they switched on.
44
+ */
45
+ declare function getTransitionRunner(source: string): IWcsTransitionRunner | null;
46
+ /**
47
+ * Run `mutate` under the installed arbiter, or directly when there is none.
48
+ *
49
+ * Returns `undefined` in the no-arbiter case instead of a resolved promise: the
50
+ * state drain calls this on every batch, and awaiting is a caller's choice, not
51
+ * an allocation the common path should pay for. `await` accepts both.
52
+ */
53
+ declare function runTransition(source: string, mutate: () => void, types?: readonly string[]): Promise<void> | undefined;
54
+
55
+ /**
56
+ * Observation semantics of a `properties` entry.
57
+ *
58
+ * "state" — current value. A snapshot may cache it, and equality-based dedupe is safe.
59
+ * "event" — occurrence. Repeated identical payloads are distinct occurrences; never dedupe.
60
+ * "handle" — live / opaque resource with its own lifecycle (e.g. MediaStream). Not
61
+ * snapshot-safe and not necessarily serializable; consumers need an explicit
62
+ * ref / callback surface rather than a value slot.
63
+ */
64
+ type WcBindableSemantics = "state" | "event" | "handle";
65
+ interface IWcBindableProperty {
66
+ readonly name: string;
67
+ readonly event: string;
68
+ readonly getter?: (event: Event) => any;
69
+ /**
70
+ * Optional, additive, forward-compatible. An absent value means **unspecified**, NOT
71
+ * "state": a reader that finds no `semantics` MUST keep the behavior it had before this
72
+ * field existed (deliver the update as-is; do not start deduping, caching or serializing
73
+ * on assumption). Only an explicit value licenses a reader to change its handling.
74
+ */
75
+ readonly semantics?: WcBindableSemantics;
76
+ }
77
+ interface IWcBindableInput {
78
+ readonly name: string;
79
+ readonly attribute?: string;
80
+ }
81
+ interface IWcBindableCommand {
82
+ readonly name: string;
83
+ readonly async?: boolean;
84
+ }
85
+ interface IWcBindable {
86
+ readonly protocol: "wc-bindable";
87
+ /** Integer protocol version. All versions >= 1 are core-compatible. */
88
+ readonly version: number;
89
+ readonly properties: readonly IWcBindableProperty[];
90
+ readonly inputs?: readonly IWcBindableInput[];
91
+ readonly commands?: readonly IWcBindableCommand[];
92
+ }
93
+
94
+ interface ITagNames {
95
+ readonly viewTransition: string;
96
+ }
97
+ interface IWritableTagNames {
98
+ viewTransition?: string;
99
+ }
100
+ interface IConfig {
101
+ readonly tagNames: ITagNames;
102
+ }
103
+ interface IWritableConfig {
104
+ tagNames?: IWritableTagNames;
105
+ }
106
+
107
+ /**
108
+ * What happens when a transition request arrives while one is already running.
109
+ * The vocabulary is the exclusion vocabulary of docs/async-execution-model.md,
110
+ * reused rather than reinvented.
111
+ *
112
+ * "latest" — skip the running transition and animate the newcomer (default).
113
+ * "queue" — chain: the newcomer starts once the running one has finished.
114
+ * "exhaust" — apply the newcomer's mutation immediately, without animating it.
115
+ *
116
+ * In every mode the mutation is applied exactly once. `exhaust` drops the
117
+ * *animation*, never the DOM update.
118
+ */
119
+ type TransitionMode = "latest" | "queue" | "exhaust";
120
+ /** Whether `prefers-reduced-motion: reduce` suppresses transitions. */
121
+ type ReducedMotionPolicy = "skip" | "animate";
122
+ /**
123
+ * Value types for ViewTransitionCore (headless) — the observable state properties.
124
+ */
125
+ interface WcsViewTransitionCoreValues {
126
+ /** Whether a view transition is running right now. */
127
+ active: boolean;
128
+ /** The last failure to start a transition, or `null` while none. */
129
+ error: Error | null;
130
+ }
131
+ /** Value types for the Shell (`<wcs-view-transition>`) — identical to the Core. */
132
+ type WcsViewTransitionValues = WcsViewTransitionCoreValues;
133
+ interface WcsViewTransitionInputs {
134
+ /** Inert arbiter: every request applies synchronously, without a transition. */
135
+ disabled: boolean;
136
+ /** Exclusion policy. */
137
+ mode: TransitionMode;
138
+ /** `view-transition-name` assignment policy handed to participants. */
139
+ naming: TransitionNaming;
140
+ /** Upper bound on auto-assigned names. */
141
+ namingLimit: number;
142
+ /** `prefers-reduced-motion` policy. */
143
+ reducedMotion: ReducedMotionPolicy;
144
+ /** Transition types, where `startViewTransition({ types })` is supported. */
145
+ types: readonly string[];
146
+ /** Participants allowed to animate (`router`, `state`). */
147
+ participants: readonly string[];
148
+ }
149
+ interface WcsViewTransitionCoreCommands {
150
+ /**
151
+ * Finish the running transition immediately. The DOM update is never skipped —
152
+ * only the animation is. A no-op when nothing is running.
153
+ */
154
+ skip(): void;
155
+ }
156
+ type WcsViewTransitionCommands = WcsViewTransitionCoreCommands;
157
+
158
+ declare function bootstrapViewTransition(userConfig?: IWritableConfig, registry?: CustomElementRegistry): void;
159
+
160
+ declare function getConfig(): IConfig;
161
+
162
+ /**
163
+ * Headless view-transition arbiter — the single place on a page that decides
164
+ * whether a DOM mutation animates, and what happens when two of them collide.
165
+ *
166
+ * It is not an I/O node: nothing is read from a device and there is no data to
167
+ * bind. It is a *policy* node. Participants (`@wcstack/router`, `@wcstack/state`)
168
+ * never import it; they find it through the transition-runner protocol on a
169
+ * well-known global symbol and hand it a mutation to run
170
+ * (docs/view-transition-design.md §4).
171
+ *
172
+ * The one invariant everything else is subordinate to: **a mutation handed to
173
+ * `run()` is applied exactly once**, whatever is decided about animating it. An
174
+ * unsupported browser, a hidden tab, reduced motion, a colliding transition and a
175
+ * `startViewTransition` that throws all end in the mutation running — the page
176
+ * must never be left showing stale DOM because an animation could not be played.
177
+ */
178
+ declare class ViewTransitionCore extends EventTarget {
179
+ static wcBindable: IWcBindable;
180
+ private _target;
181
+ private _mode;
182
+ private _naming;
183
+ private _namingLimit;
184
+ private _reducedMotion;
185
+ private _types;
186
+ private _disabled;
187
+ private _participants;
188
+ private _active;
189
+ private _error;
190
+ /** Requests waiting for the microtask flush that starts a transition. */
191
+ private _pending;
192
+ private _flushScheduled;
193
+ /**
194
+ * The batch handed to the running transition while its update callback has not
195
+ * fired yet. Non-null means "capturing": a request arriving now still joins this
196
+ * batch, which is both the coalescing window and the only ordering guarantee
197
+ * that keeps a later `exhaust`/`latest` request from applying ahead of it.
198
+ */
199
+ private _batch;
200
+ private _transition;
201
+ private _queue;
202
+ constructor(target?: EventTarget);
203
+ get protocol(): "wcs-transition-runner";
204
+ get version(): number;
205
+ get naming(): TransitionNaming;
206
+ set naming(value: TransitionNaming);
207
+ get namingLimit(): number;
208
+ set namingLimit(value: number);
209
+ accepts(source: string): boolean;
210
+ /**
211
+ * Install this core as the page's arbiter. Returns false (and warns) when
212
+ * another one already holds the slot — two arbiters would each think they own
213
+ * the exclusion, which is precisely the thing an arbiter exists to prevent.
214
+ */
215
+ install(): boolean;
216
+ /** Release the arbiter slot, but only if it is still ours. */
217
+ uninstall(): void;
218
+ get mode(): TransitionMode;
219
+ set mode(value: TransitionMode);
220
+ get reducedMotion(): ReducedMotionPolicy;
221
+ set reducedMotion(value: ReducedMotionPolicy);
222
+ get types(): readonly string[];
223
+ set types(value: readonly string[] | string);
224
+ get disabled(): boolean;
225
+ set disabled(value: boolean);
226
+ get participants(): readonly string[];
227
+ set participants(value: readonly string[] | string);
228
+ get active(): boolean;
229
+ get error(): Error | null;
230
+ /**
231
+ * Finish the running transition now. Per spec the update callback still runs if
232
+ * it has not yet, so skipping loses the animation and never the DOM update.
233
+ */
234
+ skip(): void;
235
+ run(mutate: () => void, _options?: IWcsTransitionRunOptions): Promise<void>;
236
+ dispose(): void;
237
+ private _canTransition;
238
+ private _applyNow;
239
+ private _settle;
240
+ private _schedule;
241
+ private _flush;
242
+ private _start;
243
+ private _onFinished;
244
+ private _setActive;
245
+ private _setError;
246
+ private _dispatch;
247
+ }
248
+
249
+ /**
250
+ * `<wcs-view-transition>` — the page's view-transition policy node.
251
+ *
252
+ * It renders nothing and binds no data. It declares *how* the DOM changes that
253
+ * `@wcstack/router` and `@wcstack/state` make should animate, and it is the single
254
+ * arbiter that decides what happens when two of those changes collide. Dropping
255
+ * the tag on a page is the opt-in; removing it restores the framework's original
256
+ * synchronous behavior exactly (docs/view-transition-design.md §3, G1/G2).
257
+ *
258
+ * ```html
259
+ * <wcs-view-transition for="router" mode="latest"></wcs-view-transition>
260
+ * ```
261
+ *
262
+ * The animation itself is written in CSS against `::view-transition-*`. This tag
263
+ * starts and arbitrates transitions; it never describes one.
264
+ */
265
+ declare class WcsViewTransition extends HTMLElement {
266
+ static observedAttributes: string[];
267
+ static wcBindable: IWcBindable;
268
+ private _core;
269
+ private _internals;
270
+ private _installed;
271
+ constructor();
272
+ /** The headless arbiter, for direct (non-DOM) use. */
273
+ get core(): ViewTransitionCore;
274
+ get debugStates(): string[];
275
+ private _initInternals;
276
+ private _wireStates;
277
+ get disabled(): boolean;
278
+ set disabled(value: boolean);
279
+ get mode(): TransitionMode;
280
+ set mode(value: TransitionMode);
281
+ get naming(): TransitionNaming;
282
+ set naming(value: TransitionNaming);
283
+ get namingLimit(): number;
284
+ set namingLimit(value: number);
285
+ get reducedMotion(): ReducedMotionPolicy;
286
+ set reducedMotion(value: ReducedMotionPolicy);
287
+ get types(): readonly string[];
288
+ set types(value: readonly string[] | string);
289
+ get participants(): readonly string[];
290
+ set participants(value: readonly string[] | string);
291
+ get active(): boolean;
292
+ get error(): Error | null;
293
+ skip(): void;
294
+ connectedCallback(): void;
295
+ disconnectedCallback(): void;
296
+ attributeChangedCallback(name: string, oldValue: string | null, newValue: string | null): void;
297
+ /**
298
+ * Apply the attributes present at connect time. Absent ones are deliberately
299
+ * skipped rather than applied as null: a property assigned before upgrade
300
+ * (Angular's `[prop]`, Lit's `.prop=`, or plain `el.mode = ...`) has just been
301
+ * replayed through the setter by `upgradeProperties`, and re-applying a missing
302
+ * attribute would immediately reset it to the default. Removing an attribute
303
+ * still resets, via `attributeChangedCallback`.
304
+ */
305
+ private _syncAllAttributes;
306
+ private _applyAttribute;
307
+ }
308
+
309
+ export { TRANSITION_RUNNER_KEY, ViewTransitionCore, WcsViewTransition, bootstrapViewTransition, getConfig, getTransitionRunner, runTransition };
310
+ export type { IWcsTransitionRunOptions, IWcsTransitionRunner, IWritableConfig, IWritableTagNames, ReducedMotionPolicy, TransitionMode, TransitionNaming, TransitionSource, WcsViewTransitionCommands, WcsViewTransitionCoreCommands, WcsViewTransitionCoreValues, WcsViewTransitionInputs, WcsViewTransitionValues };