@3driseai/3drise-core 1.0.17 → 1.0.19

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.
@@ -1,114 +1,14 @@
1
- import type { AnimationSequence, TransitionStep, AnimationPlaybackOptions, PathConfig } from "../types/animations";
1
+ import type { PathConfig } from "../types/animations";
2
2
  import type { Vector3Array } from "../types/scene3d";
3
- export type AnimationEventType = 'sequenceStart' | 'sequenceEnd' | 'stepStart' | 'stepEnd';
4
- export interface AnimationEvent {
5
- type: AnimationEventType;
6
- sequenceId: string;
7
- sequence: AnimationSequence;
8
- step?: TransitionStep;
9
- stepIndex?: number;
10
- }
11
- type AnimationEventListener = (event: AnimationEvent) => void;
12
3
  /**
13
- * AnimationsManager
14
- * Execution-only manager for animation playback.
15
- * Sequence data lives in Redux - this class only handles execution.
4
+ * AnimationsManager — the path registry (PathCreator, path animation) and the
5
+ * progress helpers per-object animations use.
6
+ *
7
+ * Sequence playback moved to Animations V2 (viewer `animationsV2/ClipsRuntime`);
8
+ * the V1 sequence player, its GSAP timelines and its step events are gone.
16
9
  */
17
10
  declare class AnimationsManager {
18
- private activeSequences;
19
11
  private paths;
20
- private timelines;
21
- private eventListeners;
22
- constructor();
23
- /**
24
- * Add an event listener
25
- */
26
- on(eventType: AnimationEventType, listener: AnimationEventListener): void;
27
- /**
28
- * Remove an event listener
29
- */
30
- off(eventType: AnimationEventType, listener: AnimationEventListener): void;
31
- /**
32
- * Emit an event
33
- */
34
- private emit;
35
- /**
36
- * @deprecated Sequences are now managed in Redux. Use playSequence(sequence) directly.
37
- * This method is kept for backwards compatibility during migration.
38
- */
39
- addSequence(sequence: AnimationSequence): AnimationSequence;
40
- /**
41
- * @deprecated Sequences are now managed in Redux.
42
- */
43
- removeSequence(sequenceId: string): void;
44
- /**
45
- * Get an actively playing sequence's runtime state
46
- */
47
- getSequence(sequenceId: string): AnimationSequence | undefined;
48
- /**
49
- * @deprecated Sequences are now managed in Redux. Use Redux selectors instead.
50
- */
51
- getAllSequences(): AnimationSequence[];
52
- /**
53
- * Execute a single animation step with multiple transitions
54
- * Returns a GSAP timeline for this step
55
- */
56
- private executeStep;
57
- /**
58
- * Play an animation sequence
59
- * @param sequenceOrId - Either a full AnimationSequence object or a sequence ID (for backwards compat)
60
- * @param options - Playback options
61
- */
62
- playSequence(sequenceOrId: AnimationSequence | string, options?: AnimationPlaybackOptions): Promise<void>;
63
- /**
64
- * Pause an animation sequence
65
- */
66
- pauseSequence(sequenceId: string): void;
67
- /**
68
- * Resume a paused animation sequence
69
- */
70
- resumeSequence(sequenceId: string): void;
71
- /**
72
- * Stop an animation sequence
73
- */
74
- stopSequence(sequenceId: string): void;
75
- /**
76
- * Stop all animation sequences
77
- */
78
- stopAllSequences(): void;
79
- /**
80
- * @deprecated Use Redux to update sequences. This only affects runtime state.
81
- */
82
- updateSequence(sequenceId: string, updates: Partial<AnimationSequence>): void;
83
- /**
84
- * Check if a sequence is playing
85
- */
86
- isSequencePlaying(sequenceId: string): boolean;
87
- /**
88
- * Check if a sequence is paused
89
- */
90
- isSequencePaused(sequenceId: string): boolean;
91
- /**
92
- * Seek to a specific progress point in the animation (0-1)
93
- */
94
- seekToProgress(sequenceId: string, progress: number): void;
95
- /**
96
- * Go to the start of the animation
97
- */
98
- goToStart(sequenceId: string): void;
99
- /**
100
- * Go to the end of the animation
101
- */
102
- goToEnd(sequenceId: string): void;
103
- /**
104
- * Get the current progress of a sequence (0-1)
105
- */
106
- getProgress(sequenceId: string): number;
107
- /**
108
- * Clear all active sequences and timelines
109
- */
110
- clear(): void;
111
- reverseSteps(sequence: AnimationSequence): AnimationSequence;
112
12
  /**
113
13
  * Get progress based on start time and duration (uses wall-clock time like GSAP)
114
14
  * @param startTime - The timestamp when animation started (from performance.now() or Date.now())
@@ -1 +1 @@
1
- {"version":3,"file":"AnimationsManager.d.ts","sourceRoot":"","sources":["../../src/services/AnimationsManager.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE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AM;IAM7E;;OAEG;IACH,UAAU,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,aAAa,GAAE,YAAY,EAAO,GAAG,MAAM;IAUrE;;OAEG;IACH,OAAO,CAAC,YAAY,EAAE,UAAU,GAAG,IAAI;IAGvC;;OAEG;IACH,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,UAAU,GAAG,SAAS;IAG/C;;OAEG;IACH,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,YAAY,EAAE,GAAG,SAAS;IAGzD;;OAEG;IACH,WAAW,IAAI,UAAU,EAAE;IAG3B;;OAEG;IACH,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,CAAC,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC,GAAG,IAAI;IAM1E;;OAEG;IACH,gBAAgB,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,YAAY,EAAE,GAAG,IAAI;IAM9D;;OAEG;IACH,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,YAAY,GAAG,IAAI;IAMzD;;OAEG;IACH,mBAAmB,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI;IAMxD;;OAEG;IACH,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAGhC;;OAEG;IACH,aAAa,IAAI,IAAI;CAGxB;;AAED,wBAAuC"}
@@ -1,399 +1,13 @@
1
- import gsap from 'gsap';
2
1
  import { applyEasing, gsapEasingMap } from '../utils/easingUtils.js';
3
2
  /**
4
- * AnimationsManager
5
- * Execution-only manager for animation playback.
6
- * Sequence data lives in Redux - this class only handles execution.
3
+ * AnimationsManager — the path registry (PathCreator, path animation) and the
4
+ * progress helpers per-object animations use.
5
+ *
6
+ * Sequence playback moved to Animations V2 (viewer `animationsV2/ClipsRuntime`);
7
+ * the V1 sequence player, its GSAP timelines and its step events are gone.
7
8
  */
8
9
  class AnimationsManager {
9
- // Runtime state for actively playing sequences
10
- activeSequences = new Map();
11
10
  paths = new Map([]);
12
- timelines = new Map();
13
- eventListeners = new Map();
14
- constructor() {
15
- // Initialize event listener sets
16
- this.eventListeners.set('sequenceStart', new Set());
17
- this.eventListeners.set('sequenceEnd', new Set());
18
- this.eventListeners.set('stepStart', new Set());
19
- this.eventListeners.set('stepEnd', new Set());
20
- }
21
- /**
22
- * Add an event listener
23
- */
24
- on(eventType, listener) {
25
- const listeners = this.eventListeners.get(eventType);
26
- if (listeners) {
27
- listeners.add(listener);
28
- }
29
- }
30
- /**
31
- * Remove an event listener
32
- */
33
- off(eventType, listener) {
34
- const listeners = this.eventListeners.get(eventType);
35
- if (listeners) {
36
- listeners.delete(listener);
37
- }
38
- }
39
- /**
40
- * Emit an event
41
- */
42
- emit(event) {
43
- const listeners = this.eventListeners.get(event.type);
44
- if (listeners) {
45
- listeners.forEach(listener => {
46
- try {
47
- listener(event);
48
- }
49
- catch (error) {
50
- console.error(`Error in animation event listener for ${event.type}:`, error);
51
- }
52
- });
53
- }
54
- }
55
- /**
56
- * @deprecated Sequences are now managed in Redux. Use playSequence(sequence) directly.
57
- * This method is kept for backwards compatibility during migration.
58
- */
59
- addSequence(sequence) {
60
- console.warn('AnimationsManager.addSequence is deprecated. Sequences are managed in Redux.');
61
- // Store for backwards compatibility
62
- this.activeSequences.set(sequence.id, {
63
- ...sequence,
64
- currentStep: 0,
65
- isPlaying: false,
66
- isPaused: false,
67
- progress: 0,
68
- });
69
- return this.activeSequences.get(sequence.id);
70
- }
71
- /**
72
- * @deprecated Sequences are now managed in Redux.
73
- */
74
- removeSequence(sequenceId) {
75
- console.warn('AnimationsManager.removeSequence is deprecated. Sequences are managed in Redux.');
76
- this.stopSequence(sequenceId);
77
- this.activeSequences.delete(sequenceId);
78
- this.timelines.delete(sequenceId);
79
- }
80
- /**
81
- * Get an actively playing sequence's runtime state
82
- */
83
- getSequence(sequenceId) {
84
- return this.activeSequences.get(sequenceId);
85
- }
86
- /**
87
- * @deprecated Sequences are now managed in Redux. Use Redux selectors instead.
88
- */
89
- getAllSequences() {
90
- console.warn('AnimationsManager.getAllSequences is deprecated. Use Redux selectors.');
91
- return Array.from(this.activeSequences.values());
92
- }
93
- // updateSequence(sequenceId: string, updates: Partial<AnimationSequence>): void {
94
- // const sequence = this.sequences.get(sequenceId);
95
- // if (sequence) {
96
- // Object.assign(sequence, updates);
97
- // }
98
- // }
99
- /**
100
- * Execute a single animation step with multiple transitions
101
- * Returns a GSAP timeline for this step
102
- */
103
- executeStep(step, stepTimeline, sequence, stepIndex) {
104
- const { duration, ease = 'power2.out' } = step;
105
- const stagger = step.stagger || 0;
106
- // Total GSAP timeline duration must cover the last staggered transition finishing.
107
- // last object starts at (n-1)*stagger, runs for `duration` seconds.
108
- const totalDuration = duration + (step.transitions.length > 1 ? (step.transitions.length) * stagger : 0);
109
- // Emit step start event with step data
110
- stepTimeline.call(() => {
111
- this.emit({
112
- type: 'stepStart',
113
- sequenceId: sequence.id,
114
- sequence,
115
- step,
116
- stepIndex,
117
- });
118
- }, undefined, 0); // Call at the start of the step timeline
119
- // console.log('Executing step', stepIndex, 'of sequence', sequence.id, 'with duration', duration, 'stagger', stagger, 'totalDuration', totalDuration);
120
- stepTimeline.to({}, { duration: totalDuration, ease: ease });
121
- // Emit step end event
122
- stepTimeline.call(() => {
123
- this.emit({
124
- type: 'stepEnd',
125
- sequenceId: sequence.id,
126
- sequence,
127
- step,
128
- stepIndex,
129
- });
130
- if (step.onComplete) {
131
- step.onComplete();
132
- }
133
- });
134
- }
135
- /**
136
- * Play an animation sequence
137
- * @param sequenceOrId - Either a full AnimationSequence object or a sequence ID (for backwards compat)
138
- * @param options - Playback options
139
- */
140
- async playSequence(sequenceOrId, options = {}) {
141
- // Support both sequence object and ID for backwards compatibility
142
- let sequence;
143
- let originalSequence; // Keep original for yoyo/loop callbacks
144
- let sequenceId;
145
- if (typeof sequenceOrId === 'string') {
146
- // ID passed - look up in activeSequences (backwards compat)
147
- const found = this.activeSequences.get(sequenceOrId);
148
- if (!found) {
149
- console.warn(`Animation sequence with ID ${sequenceOrId} not found. Pass sequence data directly.`);
150
- return;
151
- }
152
- originalSequence = found;
153
- sequence = options.reverse ? this.reverseSteps(found) : found;
154
- sequenceId = sequenceOrId;
155
- }
156
- else {
157
- // Sequence object passed directly (preferred)
158
- originalSequence = sequenceOrId;
159
- sequence = options.reverse ? this.reverseSteps(sequenceOrId) : sequenceOrId;
160
- sequenceId = sequence.id;
161
- }
162
- // console.log('Playing sequence:', sequenceId, options);
163
- // Stop existing timeline if any
164
- this.stopSequence(sequenceId);
165
- // Store in activeSequences for runtime state tracking
166
- const runtimeSequence = {
167
- ...sequence,
168
- isPlaying: true,
169
- isPaused: false,
170
- currentStep: options.startStep || 0,
171
- progress: 0,
172
- };
173
- this.activeSequences.set(sequenceId, runtimeSequence);
174
- // console.log({sequence});
175
- // Create main timeline
176
- // When yoyo is enabled, we handle looping manually via callbacks
177
- // When yoyo is disabled, we can use GSAP's repeat for loop
178
- const useGsapRepeat = originalSequence.loop && !originalSequence.yoyo;
179
- const mainTimeline = gsap.timeline({
180
- paused: false,
181
- repeat: useGsapRepeat ? -1 : 0,
182
- onStart: () => {
183
- // Emit sequence start event
184
- this.emit({
185
- type: 'sequenceStart',
186
- sequenceId,
187
- sequence: runtimeSequence,
188
- });
189
- },
190
- onUpdate: () => {
191
- const progress = mainTimeline.progress();
192
- // console.log(progress);
193
- runtimeSequence.progress = progress;
194
- },
195
- onComplete: () => {
196
- runtimeSequence.isPlaying = false;
197
- runtimeSequence.currentStep = 0;
198
- runtimeSequence.progress = 1;
199
- // Emit sequence end event
200
- this.emit({
201
- type: 'sequenceEnd',
202
- sequenceId,
203
- sequence: runtimeSequence,
204
- });
205
- if (originalSequence.yoyo) {
206
- if (!options._isYoyoReturn) {
207
- // Just finished the first pass, play the return leg (reversed)
208
- this.playSequence(originalSequence, {
209
- ...options,
210
- reverse: true,
211
- _isYoyoReturn: true,
212
- });
213
- }
214
- else if (originalSequence.loop) {
215
- // Finished the return leg and loop is true, start fresh (forward)
216
- this.playSequence(originalSequence, {
217
- ...options,
218
- reverse: false,
219
- _isYoyoReturn: false,
220
- });
221
- }
222
- // If _isYoyoReturn and loop is false, we're done (no replay)
223
- }
224
- if (options.onComplete) {
225
- options.onComplete();
226
- }
227
- },
228
- });
229
- // Add forward steps to timeline
230
- for (let i = 0; i < sequence.steps.length; i++) {
231
- const step = sequence.steps[i];
232
- const delay = step.delay || 0;
233
- // Create a nested timeline for each step
234
- const stepTimeline = gsap.timeline({
235
- onStart: () => {
236
- runtimeSequence.currentStep = i;
237
- }
238
- });
239
- // Execute the step (this will add tweens to stepTimeline and emit events)
240
- this.executeStep(step, stepTimeline, sequence, i);
241
- // Add the step timeline to the main timeline
242
- if (delay > 0) {
243
- mainTimeline.add(stepTimeline, `+=${delay}`);
244
- }
245
- else {
246
- mainTimeline.add(stepTimeline);
247
- }
248
- }
249
- // Apply speed multiplier if provided
250
- if (options.speed !== undefined && options.speed > 0) {
251
- mainTimeline.timeScale(options.speed);
252
- }
253
- this.timelines.set(sequenceId, mainTimeline);
254
- }
255
- /**
256
- * Pause an animation sequence
257
- */
258
- pauseSequence(sequenceId) {
259
- const timeline = this.timelines.get(sequenceId);
260
- const sequence = this.activeSequences.get(sequenceId);
261
- if (timeline && sequence) {
262
- timeline.pause();
263
- sequence.isPaused = true;
264
- sequence.isPlaying = false;
265
- }
266
- }
267
- /**
268
- * Resume a paused animation sequence
269
- */
270
- resumeSequence(sequenceId) {
271
- const timeline = this.timelines.get(sequenceId);
272
- const sequence = this.activeSequences.get(sequenceId);
273
- if (timeline && sequence) {
274
- timeline.resume();
275
- sequence.isPaused = false;
276
- sequence.isPlaying = true;
277
- }
278
- }
279
- /**
280
- * Stop an animation sequence
281
- */
282
- stopSequence(sequenceId) {
283
- const timeline = this.timelines.get(sequenceId);
284
- const sequence = this.activeSequences.get(sequenceId);
285
- if (timeline) {
286
- timeline.kill();
287
- this.timelines.delete(sequenceId);
288
- }
289
- if (sequence) {
290
- sequence.isPlaying = false;
291
- sequence.isPaused = false;
292
- sequence.currentStep = 0;
293
- sequence.progress = 0;
294
- // Clean up from activeSequences when stopped
295
- this.activeSequences.delete(sequenceId);
296
- }
297
- }
298
- /**
299
- * Stop all animation sequences
300
- */
301
- stopAllSequences() {
302
- this.activeSequences.forEach((_, sequenceId) => {
303
- this.stopSequence(sequenceId);
304
- });
305
- }
306
- /**
307
- * @deprecated Use Redux to update sequences. This only affects runtime state.
308
- */
309
- updateSequence(sequenceId, updates) {
310
- console.warn('AnimationsManager.updateSequence is deprecated. Use Redux.');
311
- const sequence = this.activeSequences.get(sequenceId);
312
- if (sequence) {
313
- Object.assign(sequence, updates);
314
- }
315
- }
316
- /**
317
- * Check if a sequence is playing
318
- */
319
- isSequencePlaying(sequenceId) {
320
- const sequence = this.activeSequences.get(sequenceId);
321
- return sequence?.isPlaying || false;
322
- }
323
- /**
324
- * Check if a sequence is paused
325
- */
326
- isSequencePaused(sequenceId) {
327
- const sequence = this.activeSequences.get(sequenceId);
328
- return sequence?.isPaused || false;
329
- }
330
- /**
331
- * Seek to a specific progress point in the animation (0-1)
332
- */
333
- seekToProgress(sequenceId, progress) {
334
- const timeline = this.timelines.get(sequenceId);
335
- const sequence = this.activeSequences.get(sequenceId);
336
- if (timeline && sequence) {
337
- const clampedProgress = Math.max(0, Math.min(1, progress));
338
- timeline.progress(clampedProgress);
339
- sequence.progress = clampedProgress;
340
- }
341
- }
342
- /**
343
- * Go to the start of the animation
344
- */
345
- goToStart(sequenceId) {
346
- this.seekToProgress(sequenceId, 0);
347
- }
348
- /**
349
- * Go to the end of the animation
350
- */
351
- goToEnd(sequenceId) {
352
- this.seekToProgress(sequenceId, 1);
353
- }
354
- /**
355
- * Get the current progress of a sequence (0-1)
356
- */
357
- getProgress(sequenceId) {
358
- const timeline = this.timelines.get(sequenceId);
359
- return timeline?.progress() || 0;
360
- }
361
- /**
362
- * Clear all active sequences and timelines
363
- */
364
- clear() {
365
- this.stopAllSequences();
366
- this.activeSequences.clear();
367
- this.timelines.clear();
368
- }
369
- reverseSteps(sequence) {
370
- // Create a deep copy of the sequence
371
- const reversedSequence = {
372
- ...sequence,
373
- id: sequence.id,
374
- steps: [...sequence.steps].reverse().map(step => {
375
- // Deep copy the step
376
- const reversedStep = {
377
- ...step,
378
- transitions: step.transitions.map(transition => {
379
- // Deep copy the transition
380
- const { properties } = transition;
381
- // Ensure we maintain the correct structure with from and to properties
382
- const reversedProperties = {
383
- from: properties.to || {},
384
- to: properties.from || {},
385
- };
386
- return {
387
- ...transition,
388
- properties: reversedProperties,
389
- };
390
- }),
391
- };
392
- return reversedStep;
393
- }),
394
- };
395
- return reversedSequence;
396
- }
397
11
  /**
398
12
  * Get progress based on start time and duration (uses wall-clock time like GSAP)
399
13
  * @param startTime - The timestamp when animation started (from performance.now() or Date.now())
@@ -402,6 +16,10 @@ class AnimationsManager {
402
16
  * @returns Eased progress value from 0 to 1
403
17
  */
404
18
  getProgressFromTime(startTime, duration, ease = 'linear') {
19
+ // Zero-length steps (actions) are complete immediately. Without this, elapsed/0 is
20
+ // NaN on the first frame (elapsed 0) and every lerp downstream goes NaN.
21
+ if (!(duration > 0))
22
+ return 1;
405
23
  const elapsed = (performance.now() - startTime) / 1000; // Convert ms to seconds
406
24
  const linearProgress = Math.min(Math.max(elapsed / duration, 0), 1);
407
25
  // Convert GSAP ease string to easing function name if needed
@@ -0,0 +1,57 @@
1
+ import type { ActionSequence } from '../types/actions';
2
+ import { type SettingsPatch } from '../utils/settingsPatch';
3
+ type Listener = () => void;
4
+ export type SceneActionsEvent =
5
+ /** `reapplied`: it was already applied (patches moved to the top). `runEffects`: false for a patch-only preview. */
6
+ {
7
+ type: 'applied';
8
+ actionId: string;
9
+ action: ActionSequence;
10
+ reapplied: boolean;
11
+ runEffects: boolean;
12
+ } | {
13
+ type: 'reverted';
14
+ actionId: string;
15
+ action: ActionSequence;
16
+ }
17
+ /** `actions`: those that were applied until now. */
18
+ | {
19
+ type: 'reset';
20
+ actions: ActionSequence[];
21
+ };
22
+ export interface ApplyActionOptions {
23
+ /** Run the action's effects (default true). The editor previews patches only. */
24
+ effects?: boolean;
25
+ }
26
+ declare class SceneActions {
27
+ private stacks;
28
+ private merged;
29
+ /** Applied actions, by id — the definition as it was applied (for revert events). */
30
+ private applied;
31
+ private stateListeners;
32
+ private eventListeners;
33
+ private version;
34
+ /** Apply an action. Re-applying moves its patches to the top of each stack. */
35
+ applyAction(action: ActionSequence, options?: ApplyActionOptions): void;
36
+ /** Remove an action's patches from every element it touched. */
37
+ revertAction(actionOrId: ActionSequence | string): void;
38
+ /** Apply when not applied, revert when applied. Returns true when it applied. */
39
+ toggleAction(action: ActionSequence): boolean;
40
+ isActionApplied(actionId: string): boolean;
41
+ getAppliedActionIds(): string[];
42
+ /** Drop every patch (project load, "reset" in the editor). */
43
+ reset(): void;
44
+ /** The merged patch for one element — stable identity until it changes. */
45
+ getPatch(state: string | undefined | null): SettingsPatch | undefined;
46
+ /** Subscribe to one element's patch. Returns the unsubscribe. */
47
+ subscribe(state: string, listener: Listener): () => void;
48
+ /** Subscribe to apply / revert / reset events (UI badges, the component API). */
49
+ onEvent(listener: (event: SceneActionsEvent) => void): () => void;
50
+ /** Monotonic counter, bumped on every change (a cheap useSyncExternalStore snapshot). */
51
+ getVersion(): number;
52
+ private removeEntries;
53
+ private commit;
54
+ }
55
+ declare const sceneActions: SceneActions;
56
+ export default sceneActions;
57
+ //# sourceMappingURL=SceneActions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SceneActions.d.ts","sourceRoot":"","sources":["../../src/services/SceneActions.ts"],"names":[],"mappings":"AA6BA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,EAA0B,KAAK,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAEpF,KAAK,QAAQ,GAAG,MAAM,IAAI,CAAC;AAE3B,MAAM,MAAM,iBAAiB;AACzB,oHAAoH;A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