@fiddle-digital/string-tune 1.1.27 → 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
@@ -129,6 +129,11 @@ declare class ScrollState {
129
129
  speedAccelerate: number;
130
130
  }
131
131
 
132
+ declare class SystemState {
133
+ fpsTracker: boolean;
134
+ positionTracker: boolean;
135
+ }
136
+
132
137
  /**
133
138
  * Represents the time-related state of the current and previous animation frames.
134
139
  *
@@ -207,12 +212,13 @@ declare class StringData {
207
212
  */
208
213
  render: RenderState;
209
214
  /**
210
- * Time-related state object.
211
- * Tracks frame timings, including current timestamp, delta between frames,
212
- * and total elapsed time since animation start.
213
- * Useful for time-based animations, easing, frame consistency, and syncing logic.
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
+ */
215
220
  time: TimeState;
221
+ system: SystemState;
216
222
  }
217
223
 
218
224
  /**
@@ -390,6 +396,30 @@ declare class EventManager {
390
396
  clearAll(): void;
391
397
  }
392
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
+
393
423
  /**
394
424
  * Internal class representing a DOM-bound interactive object.
395
425
  * Connected to modules and holds its own internal state.
@@ -408,9 +438,9 @@ declare class StringObject {
408
438
  */
409
439
  keys: string[];
410
440
  /**
411
- * A list of elements that should be affected in sync with this one.
441
+ * Mirror objects linked via `string-copy-from`.
412
442
  */
413
- connects: HTMLElement[];
443
+ private mirrors;
414
444
  /**
415
445
  * Internal key-value store of dynamic object properties (like offsets, progress, etc.).
416
446
  */
@@ -466,6 +496,10 @@ declare class StringObject {
466
496
  * @param module - The module to connect
467
497
  */
468
498
  connect(module: IStringModule): void;
499
+ addMirror(mirror: StringMirrorObject): void;
500
+ removeMirror(id: string): void;
501
+ get mirrorObjects(): StringMirrorObject[];
502
+ get connects(): HTMLElement[];
469
503
  }
470
504
 
471
505
  declare class CenterCache {
@@ -1298,7 +1332,7 @@ declare class StringModule implements IStringModule {
1298
1332
  * @param object The object whose elements to update.
1299
1333
  * @param applyFn The function that receives an HTMLElement and performs any update.
1300
1334
  */
1301
- 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;
1302
1336
  /**
1303
1337
  * Cleans up internal state and detaches the module from the system.
1304
1338
  */
@@ -1307,6 +1341,9 @@ declare class StringModule implements IStringModule {
1307
1341
  onInit(): void;
1308
1342
  /** Called on each frame with current scroll and state data. */
1309
1343
  onFrame(data: StringData): void;
1344
+ onMutate(data: StringData): void;
1345
+ onScrollMeasure(data: StringData): void;
1346
+ onMouseMoveMeasure(data: StringData): void;
1310
1347
  /** Called when the window or layout is resized. */
1311
1348
  onResize(): void;
1312
1349
  /** Called when the layout is resized width. */
@@ -1347,9 +1384,10 @@ declare class StringCursor extends StringModule {
1347
1384
  cursor: any;
1348
1385
  cursorContent: any;
1349
1386
  overCount: number;
1387
+ private cursorPrev;
1350
1388
  constructor(context: StringContext);
1351
1389
  initializeObject(globalId: number, object: StringObject, element: HTMLElement, attributes: Record<string, any>): void;
1352
- onFrame(data: StringData): void;
1390
+ onMutate(data: StringData): void;
1353
1391
  onObjectConnected(object: StringObject): void;
1354
1392
  getCursorClass(object: StringObject): string | null;
1355
1393
  onMouseEnter(object: StringObject): void;
@@ -1360,6 +1398,15 @@ declare class StringCursor extends StringModule {
1360
1398
  private calculateOffset;
1361
1399
  }
1362
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
+
1363
1410
  declare class StringMagnetic extends StringModule {
1364
1411
  constructor(context: StringContext);
1365
1412
  initializeObject(globalId: number, object: StringObject, element: HTMLElement, attributes: Record<string, any>): void;
@@ -1367,6 +1414,38 @@ declare class StringMagnetic extends StringModule {
1367
1414
  onFrame(data: StringData): void;
1368
1415
  }
1369
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
+
1370
1449
  /**
1371
1450
  * Module that handles lazy-loading of images with `string-lazy` attribute.
1372
1451
  * It loads the image only once, calculates its aspect-ratio to prevent layout shift,
@@ -1469,23 +1548,21 @@ declare class StringLerp extends StringModule {
1469
1548
  private setLerpValue;
1470
1549
  }
1471
1550
 
1472
- /**
1473
- * The `StringProgress` class extends the `StringModule` class and is responsible for
1474
- * managing progress-based behavior for elements during scroll events. It maps specific
1475
- * attributes, initializes objects, and updates their progress based on scroll data.
1476
- */
1477
1551
  declare class StringProgress extends StringModule {
1552
+ protected updateScheduled: boolean;
1553
+ private static readonly PROGRESS_EPSILON;
1478
1554
  constructor(context: StringContext);
1479
- /**
1480
- * Called when an object is initialized.
1481
- */
1482
1555
  initializeObject(globalId: number, object: StringObject, element: HTMLElement, attributes: Record<string, any>): void;
1483
- /**
1484
- * Called on scroll.
1485
- */
1556
+ private recomputeProgress;
1557
+ private applyProgressValue;
1558
+ calculatePositions(object: StringObject, windowSize: number): void;
1486
1559
  onScroll(data: StringData): void;
1487
1560
  onObjectConnected(object: StringObject): void;
1488
- private setUpObject;
1561
+ onScrollMeasure(data: StringData): void;
1562
+ onMutate(): void;
1563
+ private updateObjectProgress;
1564
+ private hasProgressChanged;
1565
+ onObjectDisconnected(object: StringObject): void;
1489
1566
  }
1490
1567
 
1491
1568
  /**
@@ -1495,22 +1572,20 @@ declare class StringProgress extends StringModule {
1495
1572
  * necessary transformations based on scroll progress and viewport size.
1496
1573
  */
1497
1574
  declare class StringParallax extends StringProgress {
1575
+ private updateScheduledTransform;
1576
+ private calculateParallaxForObject;
1498
1577
  constructor(context: StringContext);
1499
1578
  /**
1500
1579
  * Called when an object is initialized.
1501
1580
  */
1502
1581
  initializeObject(globalId: number, object: StringObject, element: HTMLElement, attributes: Record<string, any>): void;
1503
- /**
1504
- * Called on scroll.
1505
- */
1582
+ calculatePositions(object: StringObject, windowSize: number): void;
1506
1583
  onScroll(data: StringData): void;
1507
- /**
1508
- * Called on resize.
1509
- */
1510
1584
  onResize(): void;
1511
- private handleScrollDesktop;
1512
- private handleScrollMobile;
1513
- private scrollHandler;
1585
+ onScrollMeasure(data: StringData): void;
1586
+ onMutate(): void;
1587
+ private calculateDesktopParallax;
1588
+ private calculateMobileParallax;
1514
1589
  }
1515
1590
 
1516
1591
  declare class StringScrollbar extends StringModule {
@@ -1551,6 +1626,7 @@ declare class StringSplit extends StringModule {
1551
1626
  split(element: HTMLElement, options: ISplitOptions): {
1552
1627
  fragment: DocumentFragment;
1553
1628
  result: DocumentFragment;
1629
+ extraProps: Map<string, string>;
1554
1630
  };
1555
1631
  /**
1556
1632
  * Computes a numeric value based on the provided split option, index, and total count.
@@ -1825,41 +1901,45 @@ declare class StringForm extends StringModule {
1825
1901
  getFieldValue(field: HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement): any;
1826
1902
  }
1827
1903
 
1828
- declare abstract class CursorReactiveModule extends StringModule {
1829
- protected nearOnly: boolean;
1830
- protected emitEveryN: number;
1831
- protected updateThreshold: number;
1832
- private rafFrame;
1833
- constructor(context: StringContext);
1834
- onObjectConnected(object: StringObject): void;
1835
- removeObject(id: string): void;
1836
- onScroll(): void;
1837
- onMouseMove(e: MouseEvent): void;
1838
- onFrame(data: StringData): void;
1839
- protected abstract onPointerDelta(obj: StringObject, dx: number, dy: number, dist: number): void;
1840
- protected abstract onCursorFrame(data: StringData, frame: number): void;
1841
- }
1842
-
1843
1904
  declare class StringScroller extends StringModule {
1844
1905
  constructor(context: StringContext);
1845
1906
  onObjectConnected(object: StringObject): void;
1846
1907
  onObjectDisconnected(object: StringObject): void;
1847
1908
  }
1848
1909
 
1849
- declare class StringImpulse extends StringModule {
1850
- constructor(context: StringContext);
1851
- onObjectConnected(object: StringObject): void;
1852
- onObjectDisconnected(object: StringObject): void;
1853
- onMouseMove(_e?: MouseEvent): void;
1854
- onFrame(_: StringData): void;
1855
- }
1856
-
1857
1910
  declare class StringProgressPart extends StringModule {
1858
1911
  constructor(context: StringContext);
1859
1912
  onObjectConnected(object: StringObject): void;
1860
1913
  onObjectDisconnected(object: StringObject): void;
1861
1914
  }
1862
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
+
1863
1943
  declare class StringTune {
1864
1944
  /** Bound handler for the scroll start event */
1865
1945
  private onScrollStartBind;
@@ -1876,6 +1956,7 @@ declare class StringTune {
1876
1956
  /** Bound mouse move handler */
1877
1957
  private onMouseMoveBind;
1878
1958
  private onContainerTransitionEndBind;
1959
+ private onResizeObserverBind;
1879
1960
  /** Singleton instance of StringTune */
1880
1961
  private static i;
1881
1962
  /** Root scrollable element (typically <body>) */
@@ -1908,6 +1989,7 @@ declare class StringTune {
1908
1989
  private centers;
1909
1990
  /** Tracks hover states of string objects. */
1910
1991
  private hoverManager;
1992
+ private observerContainerResize;
1911
1993
  /**
1912
1994
  * Sets the scroll position manually.
1913
1995
  * This overrides all internal scroll states including target and lerped values.
@@ -1930,7 +2012,7 @@ declare class StringTune {
1930
2012
  * Gets the current scroll position in pixels.
1931
2013
  * This is typically updated every frame.
1932
2014
  */
1933
- get speed(): number;
2015
+ get scrollPosition(): number;
1934
2016
  /**
1935
2017
  * Sets the base scroll speed for smooth scrolling.
1936
2018
  * Typically a value between 0 and 1.
@@ -2037,6 +2119,7 @@ declare class StringTune {
2037
2119
  * @param settings A key-value map of default settings (e.g. 'offset-top': '-10%').
2038
2120
  */
2039
2121
  setupSettings(settings: StringSettings): void;
2122
+ private onResizeObserverEvent;
2040
2123
  private onContainerTransitionEnd;
2041
2124
  /**
2042
2125
  * Handles mouse move event and dispatches it to cursor and modules.
@@ -2096,6 +2179,12 @@ declare class StringTune {
2096
2179
  * @param offset - Optional. The number of pixels to offset from the target element's top position. Defaults to 0.
2097
2180
  */
2098
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;
2099
2188
  /**
2100
2189
  * Cleans up the system, removes all event listeners, stops the loop,
2101
2190
  * and destroys modules and event subscriptions.
@@ -2103,4 +2192,4 @@ declare class StringTune {
2103
2192
  destroy(): void;
2104
2193
  }
2105
2194
 
2106
- 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, 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 };