@fiddle-digital/string-tune 1.1.26 → 1.1.28

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/dist/index.d.mts CHANGED
@@ -12,96 +12,16 @@ interface StringSettings {
12
12
  [key: string]: string | number | boolean;
13
13
  }
14
14
 
15
- type EventCallback<T = any> = (payload: T) => void;
16
-
17
- /**
18
- * Manages custom event subscriptions and dispatching.
19
- * Allows multiple listeners per event and supports optional `id` suffixing.
20
- */
21
- declare class EventManager {
22
- private listeners;
23
- private stateEvents;
24
- private lastPayloads;
25
- constructor();
26
- /**
27
- * Subscribes to an event.
28
- * Optionally appends an `id` to the event name for namespacing.
29
- *
30
- * @param eventName The base event name (e.g. "scroll", "update").
31
- * @param callback The function to call when the event is emitted.
32
- * @param id Optional unique identifier to scope the event (e.g. element ID).
33
- */
34
- on<T = any>(eventName: string, callback: EventCallback<T>, id?: string | null): void;
35
- /**
36
- * Unsubscribes from a specific event listener.
37
- * Must match the original `eventName`, `callback`, and optional `id`.
38
- *
39
- * @param eventName The base event name to unsubscribe from.
40
- * @param callback The callback function to remove.
41
- * @param id Optional identifier used when subscribing.
42
- */
43
- off<T = any>(eventName: string, callback: EventCallback<T>, id?: string): void;
44
- /**
45
- * Emits an event with an optional payload.
46
- * All matching listeners will be called.
47
- *
48
- * @param eventName The full event name (must include `id` if used).
49
- * @param payload Optional data passed to event listeners.
50
- */
51
- emit<T = any>(eventName: string, payload?: T): void;
52
- /**
53
- * Subscribes to a per-object progress event.
54
- * @param id The object ID.
55
- * @param callback The callback to handle progress value.
56
- */
57
- onProgress(id: string, callback: EventCallback<number>): void;
58
- /**
59
- * Emits a per-object progress event.
60
- * @param id The object ID.
61
- * @param value The progress value.
62
- */
63
- emitProgress(id: string, value: number): void;
64
- /**
65
- * Subscribes to a per-object in-view event.
66
- * @param id The object ID.
67
- * @param callback The callback to handle visibility.
68
- */
69
- onInview(id: string, callback: EventCallback<boolean>): void;
70
- /**
71
- * Emits a per-object in-view event.
72
- * @param id The object ID.
73
- * @param visible Whether the object is visible.
74
- */
75
- emitInview(id: string, visible: boolean): void;
76
- /**
77
- * Subscribes to the global scroll event.
78
- * @param callback The callback to handle scroll value.
79
- */
80
- onScroll(callback: EventCallback<number>): void;
81
- /**
82
- * Emits the global scroll event.
83
- * @param value The scroll value.
84
- */
85
- emitScroll(value: number): void;
86
- /**
87
- * Subscribes to the global update event.
88
- * @param callback The callback to handle update.
89
- */
90
- onUpdate(callback: EventCallback<void>): void;
91
- /**
92
- * Emits the global update event.
93
- */
94
- emitUpdate(): void;
95
- /**
96
- * Clears all listeners for a specific event.
97
- *
98
- * @param eventName The full event name (including optional `id`).
99
- */
100
- clear(eventName: string): void;
101
- /**
102
- * Clears all registered events.
103
- */
104
- clearAll(): void;
15
+ interface ModuleLifecyclePermissionsItem {
16
+ rebuild: {
17
+ width: boolean;
18
+ height: boolean;
19
+ scrollHeight: boolean;
20
+ };
21
+ }
22
+ declare class ModuleLifecyclePermissions {
23
+ desktop: ModuleLifecyclePermissionsItem;
24
+ mobile: ModuleLifecyclePermissionsItem;
105
25
  }
106
26
 
107
27
  /**
@@ -132,6 +52,14 @@ declare class CursorState {
132
52
  * Delta step between current and target Y.
133
53
  */
134
54
  stepY: number;
55
+ /**
56
+ * Velocity in X direction, calculated from smoothed position.
57
+ */
58
+ velocityX: number;
59
+ /**
60
+ * Velocity in Y direction, calculated from smoothed position.
61
+ */
62
+ velocityY: number;
135
63
  }
136
64
 
137
65
  /**
@@ -201,6 +129,11 @@ declare class ScrollState {
201
129
  speedAccelerate: number;
202
130
  }
203
131
 
132
+ declare class SystemState {
133
+ fpsTracker: boolean;
134
+ positionTracker: boolean;
135
+ }
136
+
204
137
  /**
205
138
  * Represents the time-related state of the current and previous animation frames.
206
139
  *
@@ -255,36 +188,339 @@ declare class ViewportState {
255
188
  */
256
189
  declare class StringData {
257
190
  /**
258
- * Scroll-related state object.
259
- * Contains live values like `target`, `current`, `delta`, `direction`, and more.
260
- * Used for scroll-based animations, transitions, and effects.
191
+ * Scroll-related state object.
192
+ * Contains live values like `target`, `current`, `delta`, `direction`, and more.
193
+ * Used for scroll-based animations, transitions, and effects.
194
+ */
195
+ scroll: ScrollState;
196
+ /**
197
+ * Viewport-related state object.
198
+ * Holds dimensions like window size, content size, aspect ratios, and more.
199
+ * Useful for layout calculations, unit parsing, and element positioning.
200
+ */
201
+ viewport: ViewportState;
202
+ /**
203
+ * Cursor-related state object.
204
+ * Tracks cursor position, velocity, movement, and derived values.
205
+ * Can be used for pointer interactions, proximity effects, and hover states.
206
+ */
207
+ cursor: CursorState;
208
+ /**
209
+ * Render-related state object.
210
+ * Stores data related to rendering context (e.g. WebGL, Three.js),
211
+ * such as shared materials, textures, or active render frame data.
212
+ */
213
+ render: RenderState;
214
+ /**
215
+ * Time-related state object.
216
+ * Tracks frame timings, including current timestamp, delta between frames,
217
+ * and total elapsed time since animation start.
218
+ * Useful for time-based animations, easing, frame consistency, and syncing logic.
219
+ */
220
+ time: TimeState;
221
+ system: SystemState;
222
+ }
223
+
224
+ /**
225
+ * Base interface for scroll/interaction modules in the StringScroll system.
226
+ */
227
+ interface IStringModule {
228
+ permissions: ModuleLifecyclePermissions;
229
+ /** Cleans up all internal state and detaches from the system. */
230
+ destroy(): void;
231
+ /** Called once when the module is initialized. */
232
+ onInit(): void;
233
+ /** Called on each frame with current scroll and state data. */
234
+ onFrame(data: StringData): void;
235
+ /** Called when the window or layout is resized. */
236
+ onResize(): void;
237
+ /** Called when the layout is resize width. */
238
+ onResizeWidth(): void;
239
+ /** Called when the system rebuilds the DOM (e.g. after mutations). */
240
+ onDOMRebuild(): void;
241
+ /** Called when scroll position changes. */
242
+ onScroll(data: StringData): void;
243
+ /** Called when scroll change diraction. */
244
+ onDirectionChange(): void;
245
+ /** Called when scrolling starts (user begins scroll). */
246
+ onScrollStart(): void;
247
+ /** Called when scrolling ends (user stops scroll). */
248
+ onScrollStop(): void;
249
+ /** Called when scroll direction changes (e.g. up → down). */
250
+ onScrollDirectionChange(): void;
251
+ /** Called when overall scroll axis changes (vertical ↔ horizontal). */
252
+ onAxisChange(): void;
253
+ /** Called when device type changes (e.g. desktop ↔ mobile). */
254
+ onDeviceChange(): void;
255
+ /** Called when scroll-related system settings or params are updated. */
256
+ onScrollConfigChange(): void;
257
+ /**
258
+ * Called when global system settings are updated via `setupSettings`.
259
+ * Modules can override this to re-read default values, refresh configs,
260
+ * or reapply any cached parameters that depend on settings.
261
+ *
262
+ * This method is triggered after global fallback settings are merged into context.
263
+ *
264
+ * Example use cases:
265
+ * - Recalculating default lerp, anchor, radius, etc.
266
+ * - Updating internal thresholds or animation values.
267
+ * - Reacting to system-wide design changes.
268
+ */
269
+ onSettingsChange(): void;
270
+ /** Called on mouse move (for interaction-based modules). */
271
+ onMouseMove(event: MouseEvent): void;
272
+ /** Called on wheel scroll (separate from general scroll). */
273
+ onWheel(event: WheelEvent): void;
274
+ /**
275
+ * Called when the DOM mutates — useful for detecting new or removed elements.
276
+ */
277
+ onDOMMutate(added: NodeList, removed: NodeList): void;
278
+ /**
279
+ * Triggered when an object was successfully connected.
280
+ */
281
+ onObjectConnected(object: StringObject): void;
282
+ /**
283
+ * Called when a DOM element is detected as a potential interactive object.
284
+ */
285
+ initializeObject(globalId: number, object: StringObject, element: HTMLElement, attributes: Record<string, any>): void;
286
+ calculatePositions(object: StringObject, windowSize: number): void;
287
+ /**
288
+ * Check if a module should connect to a given object.
289
+ */
290
+ canConnect(object: StringObject): boolean;
291
+ /**
292
+ * Called to connect this module to the object.
293
+ */
294
+ connectObject(object: StringObject): void;
295
+ /**
296
+ * Called when the cursor or interaction enters an object's area.
297
+ */
298
+ enterObject(id: string, object: StringObject): void;
299
+ /**
300
+ * Called when the interaction leaves the object's area.
301
+ */
302
+ exitObject(id: string): void;
303
+ addObject(id: string, object: StringObject): void;
304
+ removeObject(id: string): void;
305
+ }
306
+
307
+ type EventCallback<T = any> = (payload: T) => void;
308
+
309
+ /**
310
+ * Manages custom event subscriptions and dispatching.
311
+ * Allows multiple listeners per event and supports optional `id` suffixing.
312
+ */
313
+ declare class EventManager {
314
+ private listeners;
315
+ private stateEvents;
316
+ private lastPayloads;
317
+ constructor();
318
+ /**
319
+ * Subscribes to an event.
320
+ * Optionally appends an `id` to the event name for namespacing.
321
+ *
322
+ * @param eventName The base event name (e.g. "scroll", "update").
323
+ * @param callback The function to call when the event is emitted.
324
+ * @param id Optional unique identifier to scope the event (e.g. element ID).
325
+ */
326
+ on<T = any>(eventName: string, callback: EventCallback<T>, id?: string | null): void;
327
+ /**
328
+ * Unsubscribes from a specific event listener.
329
+ * Must match the original `eventName`, `callback`, and optional `id`.
330
+ *
331
+ * @param eventName The base event name to unsubscribe from.
332
+ * @param callback The callback function to remove.
333
+ * @param id Optional identifier used when subscribing.
334
+ */
335
+ off<T = any>(eventName: string, callback: EventCallback<T>, id?: string): void;
336
+ /**
337
+ * Emits an event with an optional payload.
338
+ * All matching listeners will be called.
339
+ *
340
+ * @param eventName The full event name (must include `id` if used).
341
+ * @param payload Optional data passed to event listeners.
342
+ */
343
+ emit<T = any>(eventName: string, payload?: T): void;
344
+ /**
345
+ * Subscribes to a per-object progress event.
346
+ * @param id The object ID.
347
+ * @param callback The callback to handle progress value.
348
+ */
349
+ onProgress(id: string, callback: EventCallback<number>): void;
350
+ /**
351
+ * Emits a per-object progress event.
352
+ * @param id The object ID.
353
+ * @param value The progress value.
354
+ */
355
+ emitProgress(id: string, value: number): void;
356
+ /**
357
+ * Subscribes to a per-object in-view event.
358
+ * @param id The object ID.
359
+ * @param callback The callback to handle visibility.
360
+ */
361
+ onInview(id: string, callback: EventCallback<boolean>): void;
362
+ /**
363
+ * Emits a per-object in-view event.
364
+ * @param id The object ID.
365
+ * @param visible Whether the object is visible.
366
+ */
367
+ emitInview(id: string, visible: boolean): void;
368
+ /**
369
+ * Subscribes to the global scroll event.
370
+ * @param callback The callback to handle scroll value.
371
+ */
372
+ onScroll(callback: EventCallback<number>): void;
373
+ /**
374
+ * Emits the global scroll event.
375
+ * @param value The scroll value.
376
+ */
377
+ emitScroll(value: number): void;
378
+ /**
379
+ * Subscribes to the global update event.
380
+ * @param callback The callback to handle update.
381
+ */
382
+ onUpdate(callback: EventCallback<void>): void;
383
+ /**
384
+ * Emits the global update event.
385
+ */
386
+ emitUpdate(): void;
387
+ /**
388
+ * Clears all listeners for a specific event.
389
+ *
390
+ * @param eventName The full event name (including optional `id`).
391
+ */
392
+ clear(eventName: string): void;
393
+ /**
394
+ * Clears all registered events.
395
+ */
396
+ clearAll(): void;
397
+ }
398
+
399
+ type MirrorEasingFn = (value: number) => number;
400
+ /**
401
+ * Lightweight wrapper that mirrors a primary StringObject while keeping
402
+ * its own easing and state. Intended for elements linked via
403
+ * `[string-copy-from]`.
404
+ */
405
+ declare class StringMirrorObject {
406
+ private parent;
407
+ readonly id: string;
408
+ readonly htmlElement: HTMLElement;
409
+ private properties;
410
+ private easingFn?;
411
+ constructor(id: string, element: HTMLElement, parent: StringObject);
412
+ get parentObject(): StringObject;
413
+ setProperty<T>(key: string, value: T): void;
414
+ getProperty<T>(key: string): T;
415
+ setEasing(easing: MirrorEasingFn | null | undefined): void;
416
+ getEasing(): MirrorEasingFn | undefined;
417
+ /**
418
+ * Returns eased progress using mirror easing (if set) or fallback.
419
+ */
420
+ applyProgress(rawProgress: number, fallback?: MirrorEasingFn): number;
421
+ }
422
+
423
+ /**
424
+ * Internal class representing a DOM-bound interactive object.
425
+ * Connected to modules and holds its own internal state.
426
+ */
427
+ declare class StringObject {
428
+ /**
429
+ * The DOM element this object wraps.
430
+ */
431
+ htmlElement: HTMLElement;
432
+ /**
433
+ * Unique global ID assigned by the system.
434
+ */
435
+ id: string;
436
+ /**
437
+ * Space-separated list of all attribute keys associated with this object.
438
+ */
439
+ keys: string[];
440
+ /**
441
+ * Mirror objects linked via `string-copy-from`.
442
+ */
443
+ private mirrors;
444
+ /**
445
+ * Internal key-value store of dynamic object properties (like offsets, progress, etc.).
446
+ */
447
+ private properties;
448
+ /**
449
+ * Modules currently connected to this object.
450
+ */
451
+ private modules;
452
+ /**
453
+ * Manages and handles events for the object.
454
+ * Provides functionality to register, trigger, and manage event listeners.
455
+ */
456
+ events: EventManager;
457
+ constructor(id: string, element: HTMLElement);
458
+ /**
459
+ * Stores a property value for this object.
460
+ * @param key - Property name
461
+ * @param value - Value to store
462
+ */
463
+ setProperty<T>(key: string, value: T): void;
464
+ /**
465
+ * Retrieves a previously stored property value.
466
+ * @param key - Property name
467
+ * @returns The value or null if not set
468
+ */
469
+ getProperty<T>(key: string): T;
470
+ /**
471
+ * Marks this object as "active" (usually on intersection/scroll enter).
261
472
  */
262
- scroll: ScrollState;
473
+ enter(): void;
263
474
  /**
264
- * Viewport-related state object.
265
- * Holds dimensions like window size, content size, aspect ratios, and more.
266
- * Useful for layout calculations, unit parsing, and element positioning.
475
+ * Marks this object as "inactive" (usually on intersection/scroll leave).
267
476
  */
268
- viewport: ViewportState;
477
+ leave(): void;
269
478
  /**
270
- * Cursor-related state object.
271
- * Tracks cursor position, velocity, movement, and derived values.
272
- * Can be used for pointer interactions, proximity effects, and hover states.
479
+ * Removes the current object by iterating through all associated modules
480
+ * and invoking their `removeObject` method with the object's ID.
481
+ *
482
+ * This method ensures that the object is properly removed from all
483
+ * modules it is associated with.
273
484
  */
274
- cursor: CursorState;
485
+ remove(): void;
275
486
  /**
276
- * Render-related state object.
277
- * Stores data related to rendering context (e.g. WebGL, Three.js),
278
- * such as shared materials, textures, or active render frame data.
487
+ * Shows the object, applies visual class and notifies connected modules.
279
488
  */
280
- render: RenderState;
489
+ show(): void;
281
490
  /**
282
- * Time-related state object.
283
- * Tracks frame timings, including current timestamp, delta between frames,
284
- * and total elapsed time since animation start.
285
- * Useful for time-based animations, easing, frame consistency, and syncing logic.
286
- */
287
- time: TimeState;
491
+ * Hides the object, removes visual class (if repeat is enabled), and notifies modules.
492
+ */
493
+ hide(): void;
494
+ /**
495
+ * Connects a module to this object if not already connected.
496
+ * @param module - The module to connect
497
+ */
498
+ connect(module: IStringModule): void;
499
+ addMirror(mirror: StringMirrorObject): void;
500
+ removeMirror(id: string): void;
501
+ get mirrorObjects(): StringMirrorObject[];
502
+ get connects(): HTMLElement[];
503
+ }
504
+
505
+ declare class CenterCache {
506
+ private map;
507
+ private all;
508
+ attach(obj: StringObject): void;
509
+ detach(obj: StringObject): void;
510
+ invalidateAll(): void;
511
+ getCenter(obj: StringObject): {
512
+ cx: number;
513
+ cy: number;
514
+ };
515
+ }
516
+
517
+ declare class HoverTracker {
518
+ private active;
519
+ private subs;
520
+ track(obj: StringObject): void;
521
+ untrack(obj: StringObject): void;
522
+ isActive(obj: StringObject): boolean;
523
+ activeObjects(): StringObject[];
288
524
  }
289
525
 
290
526
  /**
@@ -460,7 +696,7 @@ declare class UnitParserTool implements IStringTool<UnitParserInput, number> {
460
696
  /**
461
697
  * @returns Numeric value in pixels (positive or negative).
462
698
  */
463
- process({ value, element, viewportHeight, baseRem, boundingRect, }: UnitParserInput): number;
699
+ process({ value, element, viewportHeight, baseRem, boundingRect }: UnitParserInput): number;
464
700
  }
465
701
 
466
702
  /**
@@ -871,182 +1107,17 @@ interface StringContext {
871
1107
  * Centralized event emitter and listener system.
872
1108
  */
873
1109
  events: EventManager;
874
- }
875
-
876
- interface ModuleLifecyclePermissionsItem {
877
- rebuild: {
878
- width: boolean;
879
- height: boolean;
880
- scrollHeight: boolean;
881
- };
882
- }
883
- declare class ModuleLifecyclePermissions {
884
- desktop: ModuleLifecyclePermissionsItem;
885
- mobile: ModuleLifecyclePermissionsItem;
886
- }
887
-
888
- /**
889
- * Internal class representing a DOM-bound interactive object.
890
- * Connected to modules and holds its own internal state.
891
- */
892
- declare class StringObject {
893
- /**
894
- * The DOM element this object wraps.
895
- */
896
- htmlElement: HTMLElement;
897
- /**
898
- * Unique global ID assigned by the system.
899
- */
900
- id: string;
901
- /**
902
- * Space-separated list of all attribute keys associated with this object.
903
- */
904
- keys: string[];
905
- /**
906
- * A list of elements that should be affected in sync with this one.
907
- */
908
- connects: HTMLElement[];
909
- /**
910
- * Internal key-value store of dynamic object properties (like offsets, progress, etc.).
911
- */
912
- private properties;
913
- /**
914
- * Modules currently connected to this object.
915
- */
916
- private modules;
917
- /**
918
- * Manages and handles events for the object.
919
- * Provides functionality to register, trigger, and manage event listeners.
920
- */
921
- events: EventManager;
922
- constructor(id: string, element: HTMLElement);
923
- /**
924
- * Stores a property value for this object.
925
- * @param key - Property name
926
- * @param value - Value to store
927
- */
928
- setProperty<T>(key: string, value: T): void;
929
- /**
930
- * Retrieves a previously stored property value.
931
- * @param key - Property name
932
- * @returns The value or null if not set
933
- */
934
- getProperty<T>(key: string): T;
935
- /**
936
- * Marks this object as "active" (usually on intersection/scroll enter).
937
- */
938
- enter(): void;
939
- /**
940
- * Marks this object as "inactive" (usually on intersection/scroll leave).
941
- */
942
- leave(): void;
943
- /**
944
- * Removes the current object by iterating through all associated modules
945
- * and invoking their `removeObject` method with the object's ID.
946
- *
947
- * This method ensures that the object is properly removed from all
948
- * modules it is associated with.
949
- */
950
- remove(): void;
951
- /**
952
- * Shows the object, applies visual class and notifies connected modules.
953
- */
954
- show(): void;
955
- /**
956
- * Hides the object, removes visual class (if repeat is enabled), and notifies modules.
957
- */
958
- hide(): void;
959
- /**
960
- * Connects a module to this object if not already connected.
961
- * @param module - The module to connect
962
- */
963
- connect(module: IStringModule): void;
964
- }
965
-
966
- /**
967
- * Base interface for scroll/interaction modules in the StringScroll system.
968
- */
969
- interface IStringModule {
970
- permissions: ModuleLifecyclePermissions;
971
- /** Cleans up all internal state and detaches from the system. */
972
- destroy(): void;
973
- /** Called once when the module is initialized. */
974
- onInit(): void;
975
- /** Called on each frame with current scroll and state data. */
976
- onFrame(data: StringData): void;
977
- /** Called when the window or layout is resized. */
978
- onResize(): void;
979
- /** Called when the layout is resize width. */
980
- onResizeWidth(): void;
981
- /** Called when the system rebuilds the DOM (e.g. after mutations). */
982
- onDOMRebuild(): void;
983
- /** Called when scroll position changes. */
984
- onScroll(data: StringData): void;
985
- /** Called when scroll change diraction. */
986
- onDirectionChange(): void;
987
- /** Called when scrolling starts (user begins scroll). */
988
- onScrollStart(): void;
989
- /** Called when scrolling ends (user stops scroll). */
990
- onScrollStop(): void;
991
- /** Called when scroll direction changes (e.g. up → down). */
992
- onScrollDirectionChange(): void;
993
- /** Called when overall scroll axis changes (vertical ↔ horizontal). */
994
- onAxisChange(): void;
995
- /** Called when device type changes (e.g. desktop ↔ mobile). */
996
- onDeviceChange(): void;
997
- /** Called when scroll-related system settings or params are updated. */
998
- onScrollConfigChange(): void;
999
- /**
1000
- * Called when global system settings are updated via `setupSettings`.
1001
- * Modules can override this to re-read default values, refresh configs,
1002
- * or reapply any cached parameters that depend on settings.
1003
- *
1004
- * This method is triggered after global fallback settings are merged into context.
1005
- *
1006
- * Example use cases:
1007
- * - Recalculating default lerp, anchor, radius, etc.
1008
- * - Updating internal thresholds or animation values.
1009
- * - Reacting to system-wide design changes.
1010
- */
1011
- onSettingsChange(): void;
1012
- /** Called on mouse move (for interaction-based modules). */
1013
- onMouseMove(event: MouseEvent): void;
1014
- /** Called on wheel scroll (separate from general scroll). */
1015
- onWheel(event: WheelEvent): void;
1016
- /**
1017
- * Called when the DOM mutates — useful for detecting new or removed elements.
1018
- */
1019
- onDOMMutate(added: NodeList, removed: NodeList): void;
1020
- /**
1021
- * Triggered when an object was successfully connected.
1022
- */
1023
- onObjectConnected(object: StringObject): void;
1024
- /**
1025
- * Called when a DOM element is detected as a potential interactive object.
1026
- */
1027
- initializeObject(globalId: number, object: StringObject, element: HTMLElement, attributes: Record<string, any>): void;
1028
- calculatePositions(object: StringObject, windowSize: number): void;
1029
- /**
1030
- * Check if a module should connect to a given object.
1031
- */
1032
- canConnect(object: StringObject): boolean;
1033
- /**
1034
- * Called to connect this module to the object.
1035
- */
1036
- connectObject(object: StringObject): void;
1037
1110
  /**
1038
- * Called when the cursor or interaction enters an object's area.
1111
+ * Caches the center positions of string objects.
1039
1112
  */
1040
- enterObject(id: string, object: StringObject): void;
1113
+ centers: CenterCache;
1041
1114
  /**
1042
- * Called when the interaction leaves the object's area.
1115
+ * Tracks hover states of string objects.
1043
1116
  */
1044
- exitObject(id: string): void;
1045
- addObject(id: string, object: StringObject): void;
1046
- removeObject(id: string): void;
1117
+ hover: HoverTracker;
1047
1118
  }
1048
1119
 
1049
- type AttributeType = "string" | "number" | "boolean" | "json" | "dimension" | "tuple" | "easing" | "color" | {
1120
+ type AttributeType = "string" | "number" | "boolean" | "json" | "dimension" | "breakpoint-dimension" | "tuple" | "easing" | "color" | {
1050
1121
  type: "enum";
1051
1122
  values: string[];
1052
1123
  };
@@ -1145,6 +1216,14 @@ declare class StringModule implements IStringModule {
1145
1216
  * Supports custom event emitting, listening, and unsubscription.
1146
1217
  */
1147
1218
  protected events: EventManager;
1219
+ /**
1220
+ * Cache for storing and managing object centers.
1221
+ */
1222
+ protected centers: CenterCache;
1223
+ /**
1224
+ * Tracker for managing hover states of objects.
1225
+ */
1226
+ protected hover: HoverTracker;
1148
1227
  permissions: ModuleLifecyclePermissions;
1149
1228
  constructor(context: StringContext);
1150
1229
  /**
@@ -1242,13 +1321,18 @@ declare class StringModule implements IStringModule {
1242
1321
  * @param object The connected object.
1243
1322
  */
1244
1323
  onObjectConnected(object: StringObject): void;
1324
+ /**
1325
+ * Called when an object is disconnected. Can be overridden to clean up styles or logic.
1326
+ * @param object The disconnected object.
1327
+ */
1328
+ onObjectDisconnected(object: StringObject): void;
1245
1329
  /**
1246
1330
  * Applies a style or callback to both the main element and all its connected elements.
1247
1331
  *
1248
1332
  * @param object The object whose elements to update.
1249
1333
  * @param applyFn The function that receives an HTMLElement and performs any update.
1250
1334
  */
1251
- protected applyToElementAndConnects(object: StringObject, applyFn: (el: HTMLElement) => void): void;
1335
+ protected applyToElementAndConnects(object: StringObject, applyFn: (el: HTMLElement) => void, copyFn?: (el: HTMLElement, mirror?: StringMirrorObject) => void): void;
1252
1336
  /**
1253
1337
  * Cleans up internal state and detaches the module from the system.
1254
1338
  */
@@ -1257,6 +1341,9 @@ declare class StringModule implements IStringModule {
1257
1341
  onInit(): void;
1258
1342
  /** Called on each frame with current scroll and state data. */
1259
1343
  onFrame(data: StringData): void;
1344
+ onMutate(data: StringData): void;
1345
+ onScrollMeasure(data: StringData): void;
1346
+ onMouseMoveMeasure(data: StringData): void;
1260
1347
  /** Called when the window or layout is resized. */
1261
1348
  onResize(): void;
1262
1349
  /** Called when the layout is resized width. */
@@ -1297,9 +1384,10 @@ declare class StringCursor extends StringModule {
1297
1384
  cursor: any;
1298
1385
  cursorContent: any;
1299
1386
  overCount: number;
1387
+ private cursorPrev;
1300
1388
  constructor(context: StringContext);
1301
1389
  initializeObject(globalId: number, object: StringObject, element: HTMLElement, attributes: Record<string, any>): void;
1302
- onFrame(data: StringData): void;
1390
+ onMutate(data: StringData): void;
1303
1391
  onObjectConnected(object: StringObject): void;
1304
1392
  getCursorClass(object: StringObject): string | null;
1305
1393
  onMouseEnter(object: StringObject): void;
@@ -1310,6 +1398,15 @@ declare class StringCursor extends StringModule {
1310
1398
  private calculateOffset;
1311
1399
  }
1312
1400
 
1401
+ declare class StringImpulse extends StringModule {
1402
+ constructor(context: StringContext);
1403
+ onObjectConnected(object: StringObject): void;
1404
+ onObjectDisconnected(object: StringObject): void;
1405
+ onMouseMove(_e?: MouseEvent): void;
1406
+ private getElementsAtPoint;
1407
+ onFrame(_: StringData): void;
1408
+ }
1409
+
1313
1410
  declare class StringMagnetic extends StringModule {
1314
1411
  constructor(context: StringContext);
1315
1412
  initializeObject(globalId: number, object: StringObject, element: HTMLElement, attributes: Record<string, any>): void;
@@ -1317,6 +1414,38 @@ declare class StringMagnetic extends StringModule {
1317
1414
  onFrame(data: StringData): void;
1318
1415
  }
1319
1416
 
1417
+ declare abstract class CursorReactiveModule extends StringModule {
1418
+ protected nearOnly: boolean;
1419
+ protected useAllObjects: boolean;
1420
+ protected maxDistanceMultiplier: number;
1421
+ protected updateThreshold: number;
1422
+ private objectDeltaData;
1423
+ constructor(context: StringContext);
1424
+ onObjectConnected(object: StringObject): void;
1425
+ removeObject(id: string): void;
1426
+ onScroll(): void;
1427
+ onMouseMoveMeasure(data: StringData): void;
1428
+ onMutate(data: StringData): void;
1429
+ protected getCursorTargets(): StringObject[];
1430
+ protected refreshPointerState(target?: StringObject): void;
1431
+ private scrollUpdateScheduled;
1432
+ protected scheduleCursorUpdate(): void;
1433
+ protected onCursorScrollUpdate(): void;
1434
+ }
1435
+
1436
+ declare class StringSpotlight extends CursorReactiveModule {
1437
+ protected onCursorFrame(data: StringData, frame: number): void;
1438
+ private updateScheduledSpotlight;
1439
+ constructor(context: any);
1440
+ initializeObject(id: number, obj: StringObject, el: HTMLElement, attrs: Record<string, any>): void;
1441
+ protected onPointerDelta(obj: StringObject, dx: number, dy: number, dist: number): void;
1442
+ onMouseMoveMeasure(data: StringData): void;
1443
+ onMutate(data: StringData): void;
1444
+ private ensurePointerState;
1445
+ private updateSpotlightState;
1446
+ protected onCursorScrollUpdate(): void;
1447
+ }
1448
+
1320
1449
  /**
1321
1450
  * Module that handles lazy-loading of images with `string-lazy` attribute.
1322
1451
  * It loads the image only once, calculates its aspect-ratio to prevent layout shift,
@@ -1419,23 +1548,21 @@ declare class StringLerp extends StringModule {
1419
1548
  private setLerpValue;
1420
1549
  }
1421
1550
 
1422
- /**
1423
- * The `StringProgress` class extends the `StringModule` class and is responsible for
1424
- * managing progress-based behavior for elements during scroll events. It maps specific
1425
- * attributes, initializes objects, and updates their progress based on scroll data.
1426
- */
1427
1551
  declare class StringProgress extends StringModule {
1552
+ protected updateScheduled: boolean;
1553
+ private static readonly PROGRESS_EPSILON;
1428
1554
  constructor(context: StringContext);
1429
- /**
1430
- * Called when an object is initialized.
1431
- */
1432
1555
  initializeObject(globalId: number, object: StringObject, element: HTMLElement, attributes: Record<string, any>): void;
1433
- /**
1434
- * Called on scroll.
1435
- */
1556
+ private recomputeProgress;
1557
+ private applyProgressValue;
1558
+ calculatePositions(object: StringObject, windowSize: number): void;
1436
1559
  onScroll(data: StringData): void;
1437
1560
  onObjectConnected(object: StringObject): void;
1438
- private setUpObject;
1561
+ onScrollMeasure(data: StringData): void;
1562
+ onMutate(): void;
1563
+ private updateObjectProgress;
1564
+ private hasProgressChanged;
1565
+ onObjectDisconnected(object: StringObject): void;
1439
1566
  }
1440
1567
 
1441
1568
  /**
@@ -1445,22 +1572,20 @@ declare class StringProgress extends StringModule {
1445
1572
  * necessary transformations based on scroll progress and viewport size.
1446
1573
  */
1447
1574
  declare class StringParallax extends StringProgress {
1575
+ private updateScheduledTransform;
1576
+ private calculateParallaxForObject;
1448
1577
  constructor(context: StringContext);
1449
1578
  /**
1450
1579
  * Called when an object is initialized.
1451
1580
  */
1452
1581
  initializeObject(globalId: number, object: StringObject, element: HTMLElement, attributes: Record<string, any>): void;
1453
- /**
1454
- * Called on scroll.
1455
- */
1582
+ calculatePositions(object: StringObject, windowSize: number): void;
1456
1583
  onScroll(data: StringData): void;
1457
- /**
1458
- * Called on resize.
1459
- */
1460
1584
  onResize(): void;
1461
- private handleScrollDesktop;
1462
- private handleScrollMobile;
1463
- private scrollHandler;
1585
+ onScrollMeasure(data: StringData): void;
1586
+ onMutate(): void;
1587
+ private calculateDesktopParallax;
1588
+ private calculateMobileParallax;
1464
1589
  }
1465
1590
 
1466
1591
  declare class StringScrollbar extends StringModule {
@@ -1501,6 +1626,7 @@ declare class StringSplit extends StringModule {
1501
1626
  split(element: HTMLElement, options: ISplitOptions): {
1502
1627
  fragment: DocumentFragment;
1503
1628
  result: DocumentFragment;
1629
+ extraProps: Map<string, string>;
1504
1630
  };
1505
1631
  /**
1506
1632
  * Computes a numeric value based on the provided split option, index, and total count.
@@ -1775,6 +1901,45 @@ declare class StringForm extends StringModule {
1775
1901
  getFieldValue(field: HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement): any;
1776
1902
  }
1777
1903
 
1904
+ declare class StringScroller extends StringModule {
1905
+ constructor(context: StringContext);
1906
+ onObjectConnected(object: StringObject): void;
1907
+ onObjectDisconnected(object: StringObject): void;
1908
+ }
1909
+
1910
+ declare class StringProgressPart extends StringModule {
1911
+ constructor(context: StringContext);
1912
+ onObjectConnected(object: StringObject): void;
1913
+ onObjectDisconnected(object: StringObject): void;
1914
+ }
1915
+
1916
+ type Job = () => void;
1917
+ declare class FrameDOM {
1918
+ private measureQueue;
1919
+ private mutateQueue;
1920
+ private scheduled;
1921
+ measure(fn: Job): void;
1922
+ mutate(fn: Job): void;
1923
+ private schedule;
1924
+ }
1925
+ declare const frameDOM: FrameDOM;
1926
+
1927
+ type StyleValue = string | number;
1928
+ type StyleVars = Record<string, StyleValue>;
1929
+ type StyleProps = Record<string, StyleValue>;
1930
+ declare class StyleTxn {
1931
+ private pendingVars;
1932
+ private pendingProps;
1933
+ private isOpen;
1934
+ begin(): void;
1935
+ setVars(el: Element, vars: StyleVars): void;
1936
+ setProps(el: Element, props: StyleProps): void;
1937
+ run(fn: () => void): void;
1938
+ commit(): void;
1939
+ cancel(): void;
1940
+ }
1941
+ declare const styleTxn: StyleTxn;
1942
+
1778
1943
  declare class StringTune {
1779
1944
  /** Bound handler for the scroll start event */
1780
1945
  private onScrollStartBind;
@@ -1790,6 +1955,8 @@ declare class StringTune {
1790
1955
  private onResizeBind;
1791
1956
  /** Bound mouse move handler */
1792
1957
  private onMouseMoveBind;
1958
+ private onContainerTransitionEndBind;
1959
+ private onResizeObserverBind;
1793
1960
  /** Singleton instance of StringTune */
1794
1961
  private static i;
1795
1962
  /** Root scrollable element (typically <body>) */
@@ -1818,6 +1985,11 @@ declare class StringTune {
1818
1985
  private data;
1819
1986
  /** Context shared across all modules (events, data, tools, settings) */
1820
1987
  private context;
1988
+ /** Caches the center positions of string objects. */
1989
+ private centers;
1990
+ /** Tracks hover states of string objects. */
1991
+ private hoverManager;
1992
+ private observerContainerResize;
1821
1993
  /**
1822
1994
  * Sets the scroll position manually.
1823
1995
  * This overrides all internal scroll states including target and lerped values.
@@ -1840,7 +2012,7 @@ declare class StringTune {
1840
2012
  * Gets the current scroll position in pixels.
1841
2013
  * This is typically updated every frame.
1842
2014
  */
1843
- get speed(): number;
2015
+ get scrollPosition(): number;
1844
2016
  /**
1845
2017
  * Sets the base scroll speed for smooth scrolling.
1846
2018
  * Typically a value between 0 and 1.
@@ -1947,6 +2119,8 @@ declare class StringTune {
1947
2119
  * @param settings A key-value map of default settings (e.g. 'offset-top': '-10%').
1948
2120
  */
1949
2121
  setupSettings(settings: StringSettings): void;
2122
+ private onResizeObserverEvent;
2123
+ private onContainerTransitionEnd;
1950
2124
  /**
1951
2125
  * Handles mouse move event and dispatches it to cursor and modules.
1952
2126
  * @param e Native mouse move event.
@@ -2005,6 +2179,12 @@ declare class StringTune {
2005
2179
  * @param offset - Optional. The number of pixels to offset from the target element's top position. Defaults to 0.
2006
2180
  */
2007
2181
  scrollToElement(selector: string, offset?: number): void;
2182
+ scrollTo(position: number): void;
2183
+ /**
2184
+ * Forces center cache recalculation for all tracked objects.
2185
+ * Useful when DOM geometry changes outside of StringTune's control.
2186
+ */
2187
+ invalidateCenters(): void;
2008
2188
  /**
2009
2189
  * Cleans up the system, removes all event listeners, stops the loop,
2010
2190
  * and destroys modules and event subscriptions.
@@ -2012,4 +2192,4 @@ declare class StringTune {
2012
2192
  destroy(): void;
2013
2193
  }
2014
2194
 
2015
- export { type ScrollMarkRule as ScrollTriggerRule, StringAnchor, type StringContext, StringCursor, StringData, StringDelayLerpTracker, StringFPSTracker, StringForm, StringGlide, StringLazy, StringLerp, StringLerpTracker, StringLoading, StringMagnetic, StringModule, StringObject, StringParallax, StringPositionTracker, StringProgress, StringResponsive, StringScrollbar, StringSequence, StringSplit, StringTune, StringVideoAutoplay, StringTune as default };
2195
+ export { CursorReactiveModule, type ScrollMarkRule as ScrollTriggerRule, StringAnchor, type StringContext, StringCursor, StringData, StringDelayLerpTracker, StringFPSTracker, StringForm, StringGlide, StringImpulse, StringLazy, StringLerp, StringLerpTracker, StringLoading, StringMagnetic, StringModule, StringObject, StringParallax, StringPositionTracker, StringProgress, StringProgressPart, StringResponsive, StringScrollbar, StringScroller, StringSequence, StringSplit, StringSpotlight, StringTune, StringVideoAutoplay, StringTune as default, frameDOM, styleTxn };