@fiddle-digital/string-tune 1.1.48 → 1.1.50

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.ts CHANGED
@@ -71,7 +71,8 @@ declare class RenderState {
71
71
  }
72
72
 
73
73
  type ScrollDirection = 'vertical' | 'horizontal';
74
- type ScrollMode = 'smooth' | 'disable' | 'default';
74
+ type BuiltInScrollMode = 'smooth' | 'disable' | 'default';
75
+ type ScrollMode = BuiltInScrollMode | string;
75
76
  /**
76
77
  * Describes current scroll-related state for all calculations and modules.
77
78
  */
@@ -132,6 +133,7 @@ declare class ScrollState {
132
133
  declare class SystemState {
133
134
  fpsTracker: boolean;
134
135
  positionTracker: boolean;
136
+ suppressMasonryResize: boolean;
135
137
  }
136
138
 
137
139
  /**
@@ -230,6 +232,10 @@ interface IStringModule {
230
232
  destroy(): void;
231
233
  /** Called once when the module is initialized. */
232
234
  onInit(): void;
235
+ /** Called once when the module is registered and can subscribe to events. */
236
+ onSubscribe(): void;
237
+ /** Called once when the module is being removed and should unsubscribe. */
238
+ onUnsubscribe(): void;
233
239
  /** Called on each frame with current scroll and state data. */
234
240
  onFrame(data: StringData): void;
235
241
  /** Called when the window or layout is resized. */
@@ -240,7 +246,7 @@ interface IStringModule {
240
246
  onDOMRebuild(): void;
241
247
  /** Called when scroll position changes. */
242
248
  onScroll(data: StringData): void;
243
- /** Called when scroll change diraction. */
249
+ /** Called when scroll change direction. */
244
250
  onDirectionChange(): void;
245
251
  /** Called when scrolling starts (user begins scroll). */
246
252
  onScrollStart(): void;
@@ -450,6 +456,30 @@ declare class StringObject {
450
456
  * Internal key-value store of dynamic object properties (like offsets, progress, etc.).
451
457
  */
452
458
  private properties;
459
+ private eventNameCache;
460
+ private eventNameSuffixCache;
461
+ /**
462
+ * Direct properties for extremely hot, per-frame accessed metrics
463
+ * to avoid going through the Map and incurring overhead.
464
+ */
465
+ progress: number;
466
+ progressRaw: number;
467
+ startPosition: number;
468
+ differencePosition: number;
469
+ transformValue: {
470
+ transform: string;
471
+ } | null;
472
+ eventProgressName: string | null;
473
+ lerp: number;
474
+ glide: number;
475
+ isMagneting: boolean;
476
+ magneticX: number;
477
+ magneticY: number;
478
+ magneticTargetX: number;
479
+ magneticTargetY: number;
480
+ eventLerpName: string | null;
481
+ eventGlideName: string | null;
482
+ eventMagneticName: string | null;
453
483
  /**
454
484
  * Modules currently connected to this object.
455
485
  */
@@ -460,6 +490,12 @@ declare class StringObject {
460
490
  */
461
491
  events: EventManager;
462
492
  constructor(id: string, element: HTMLElement);
493
+ /**
494
+ * Returns a cached event name in one of these forms:
495
+ * - `${prefix}:${id}`
496
+ * - `${prefix}:${id}:${suffix}`
497
+ */
498
+ getScopedEventName(prefix: string, suffix?: string): string;
463
499
  /**
464
500
  * Stores a property value for this object.
465
501
  * @param key - Property name
@@ -500,7 +536,7 @@ declare class StringObject {
500
536
  * Connects a module to this object if not already connected.
501
537
  * @param module - The module to connect
502
538
  */
503
- connect(module: IStringModule): void;
539
+ connect(module: IStringModule): boolean;
504
540
  addMirror(mirror: StringMirrorObject): void;
505
541
  removeMirror(id: string): void;
506
542
  get mirrorObjects(): StringMirrorObject[];
@@ -529,6 +565,40 @@ declare class HoverTracker {
529
565
  activeObjects(): StringObject[];
530
566
  }
531
567
 
568
+ interface ISettingsChangeData {
569
+ isDesktop: boolean;
570
+ isForceRebuild: boolean;
571
+ widthChanged: boolean;
572
+ heightChanged: boolean;
573
+ scrollHeightChanged: boolean;
574
+ }
575
+
576
+ type StyleValue = string | number;
577
+ type StyleVars = Record<string, StyleValue>;
578
+ type StyleProps = Record<string, StyleValue>;
579
+ declare class StyleTxn {
580
+ pendingVars: Map<Element, StyleVars>;
581
+ pendingProps: Map<Element, StyleProps>;
582
+ isOpen: boolean;
583
+ private canUseTypedOM;
584
+ private writeVar;
585
+ begin(): void;
586
+ setVars(el: Element, vars: StyleVars): void;
587
+ setVar(el: Element, key: string, value: StyleValue): void;
588
+ /**
589
+ * Directly sets a CSS custom property (variable) on an element using CSS Typed OM
590
+ * for improved performance. Falls back to string-based assignment if not supported.
591
+ * Note: This writes immediately. Use `begin()`, `setVar()`, `commit()` for batched writes.
592
+ */
593
+ setVarDirect(el: Element, key: string, value: StyleValue): void;
594
+ setProps(el: Element, props: StyleProps): void;
595
+ setProp(el: Element, key: string, value: StyleValue): void;
596
+ run(fn: () => void): void;
597
+ commit(): void;
598
+ cancel(): void;
599
+ }
600
+ declare const styleTxn: StyleTxn;
601
+
532
602
  /**
533
603
  * Base interface for injectable core tools in the String system.
534
604
  * Each tool takes input and returns output (transform, extract, calculate).
@@ -1062,7 +1132,8 @@ declare class ValidationTool implements IStringTool<ValidateInput, ValidationRes
1062
1132
  }
1063
1133
 
1064
1134
  /**
1065
- * Interface describing all available tools used inside modules.
1135
+ * Container holding references to all essential tools used within the library.
1136
+ * Dependency injection.
1066
1137
  */
1067
1138
  interface StringToolsContainer {
1068
1139
  /** Tool for reading DOM attributes (including data-*). */
@@ -1123,38 +1194,7 @@ interface StringToolsContainer {
1123
1194
  transformScaleParser: TransformScaleParserTool;
1124
1195
  optionsParser: SplitOptionsParserTool;
1125
1196
  ruleParser: RuleParserTool;
1126
- }
1127
-
1128
- /**
1129
- * Shared context object passed to all modules and core controllers.
1130
- *
1131
- * Provides access to shared tools, data, settings, and event handling.
1132
- */
1133
- interface StringContext {
1134
- /**
1135
- * Collection of utility tools (e.g. lerp, dom parser, unit converter).
1136
- */
1137
- tools: StringToolsContainer;
1138
- /**
1139
- * Reactive state container including scroll, viewport, cursor, etc.
1140
- */
1141
- data: StringData;
1142
- /**
1143
- * Global configuration settings for modules and system behavior.
1144
- */
1145
- settings: StringSettings;
1146
- /**
1147
- * Centralized event emitter and listener system.
1148
- */
1149
- events: EventManager;
1150
- /**
1151
- * Caches the center positions of string objects.
1152
- */
1153
- centers: CenterCache;
1154
- /**
1155
- * Tracks hover states of string objects.
1156
- */
1157
- hover: HoverTracker;
1197
+ styleTxn: typeof styleTxn;
1158
1198
  }
1159
1199
 
1160
1200
  type AttributeType = "string" | "number" | "boolean" | "json" | "dimension" | "breakpoint-dimension" | "tuple" | "easing" | "color" | {
@@ -1205,6 +1245,17 @@ declare class StringModule implements IStringModule {
1205
1245
  * Example: ["offset-top", "offset-bottom"]
1206
1246
  */
1207
1247
  protected attributesToMap: AttributeMapping[];
1248
+ /**
1249
+ * Defines CSS Custom Properties (Houdini) strictly required by this module.
1250
+ * ModuleManager will automatically register these properties on initialization
1251
+ * for Typed Object Model hardware acceleration.
1252
+ */
1253
+ cssProperties: Array<{
1254
+ name: string;
1255
+ syntax: string;
1256
+ initialValue: string;
1257
+ inherits: boolean;
1258
+ }>;
1208
1259
  /**
1209
1260
  * A map that associates string keys with `StringObject` instances.
1210
1261
  * This map is used to manage and track `StringObject` instances on a page.
@@ -1264,6 +1315,10 @@ declare class StringModule implements IStringModule {
1264
1315
  * Tracker for managing hover states of objects.
1265
1316
  */
1266
1317
  protected hover: HoverTracker;
1318
+ /**
1319
+ * Object manager for layout refreshes and in-view recalculation.
1320
+ */
1321
+ protected objectManager: ObjectManager;
1267
1322
  permissions: ModuleLifecyclePermissions;
1268
1323
  constructor(context: StringContext);
1269
1324
  /**
@@ -1373,12 +1428,36 @@ declare class StringModule implements IStringModule {
1373
1428
  * @param applyFn The function that receives an HTMLElement and performs any update.
1374
1429
  */
1375
1430
  protected applyToElementAndConnects(object: StringObject, applyFn: (el: HTMLElement) => void, copyFn?: (el: HTMLElement, mirror?: StringMirrorObject) => void): void;
1431
+ /**
1432
+ * Directly applies a CSS variable to the object's element without closures.
1433
+ */
1434
+ protected applyVarToElement(object: StringObject, key: string, value: string | number): void;
1435
+ /**
1436
+ * Directly applies a standard CSS property to the object's element without closures.
1437
+ */
1438
+ protected applyPropToElement(object: StringObject, key: string, value: string | number): void;
1439
+ /**
1440
+ * Directly applies a CSS variable to all connected mirrors without closures.
1441
+ */
1442
+ protected applyVarToConnects(object: StringObject, key: string, value: string | number): void;
1443
+ /**
1444
+ * Directly applies a standard CSS property to all connected mirrors without closures.
1445
+ */
1446
+ protected applyPropToConnects(object: StringObject, key: string, value: string | number): void;
1447
+ /**
1448
+ * Returns a cached per-object event name to avoid building strings in hot paths.
1449
+ */
1450
+ protected getObjectEventName(object: StringObject, prefix: string, suffix?: string): string;
1376
1451
  /**
1377
1452
  * Cleans up internal state and detaches the module from the system.
1378
1453
  */
1379
1454
  destroy(): void;
1380
1455
  /** Called once when the module is initialized. */
1381
1456
  onInit(): void;
1457
+ /** Called once when the module is registered and can subscribe to events. */
1458
+ onSubscribe(): void;
1459
+ /** Called once when the module is being removed and should unsubscribe. */
1460
+ onUnsubscribe(): void;
1382
1461
  /** Called on each frame with current scroll and state data. */
1383
1462
  onFrame(data: StringData): void;
1384
1463
  onMutate(data: StringData): void;
@@ -1390,7 +1469,7 @@ declare class StringModule implements IStringModule {
1390
1469
  onResizeWidth(): void;
1391
1470
  /** Called when scroll position changes. */
1392
1471
  onScroll(data: StringData): void;
1393
- /** Called when user changed scroll diraction. */
1472
+ /** Called when user changed scroll direction. */
1394
1473
  onDirectionChange(): void;
1395
1474
  /** Called when user starts scrolling. */
1396
1475
  onScrollStart(): void;
@@ -1418,6 +1497,183 @@ declare class StringModule implements IStringModule {
1418
1497
  onDOMMutate(added: NodeList, removed: NodeList): void;
1419
1498
  }
1420
1499
 
1500
+ declare class ModuleManager {
1501
+ private data;
1502
+ private modules;
1503
+ private uiModules;
1504
+ private allModules;
1505
+ constructor(data: StringData);
1506
+ register(module: StringModule): void;
1507
+ find<T>(type: new (...args: any[]) => T): T | undefined;
1508
+ onInit(): void;
1509
+ onFrame(): void;
1510
+ onMutate(): void;
1511
+ onScrollMeasure(): void;
1512
+ onMouseMoveMeasure(): void;
1513
+ onScroll(): void;
1514
+ onResizeWidth(): void;
1515
+ onResize(): void;
1516
+ onMouseMove(e: MouseEvent): void;
1517
+ onWheel(e: WheelEvent): void;
1518
+ onDirectionChange(): void;
1519
+ onScrollStart(): void;
1520
+ onScrollStop(): void;
1521
+ onAxisChange(): void;
1522
+ onDeviceChange(): void;
1523
+ onScrollConfigChange(): void;
1524
+ onSettingsChange(_data: ISettingsChangeData): void;
1525
+ onDOMMutate(added: NodeList, removed: NodeList): void;
1526
+ destroy(): void;
1527
+ get all(): IStringModule[];
1528
+ get core(): IStringModule[];
1529
+ get ui(): IStringModule[];
1530
+ private callAll;
1531
+ private callLifecycleStrict;
1532
+ private rebuildAllModules;
1533
+ }
1534
+
1535
+ declare class ObjectManager {
1536
+ private data;
1537
+ private modules;
1538
+ private events;
1539
+ private tools;
1540
+ private objects;
1541
+ private connectQueue;
1542
+ private connectableModulesBuffer;
1543
+ private mirrors;
1544
+ private mirrorId;
1545
+ private globalId;
1546
+ private domBatcher;
1547
+ private domBatcherEnabled;
1548
+ private inviewStarts;
1549
+ private inviewEnds;
1550
+ private inviewActive;
1551
+ private inviewStartIdx;
1552
+ private inviewEndIdx;
1553
+ private inviewIndexDirty;
1554
+ private lastInviewScrollPos;
1555
+ private intersectionObserverEnabled;
1556
+ private domObserver;
1557
+ constructor(data: StringData, modules: ModuleManager, events: EventManager, tools: StringToolsContainer);
1558
+ /**
1559
+ * Returns the object map (read-only).
1560
+ */
1561
+ get all(): ReadonlyMap<string, StringObject>;
1562
+ /**
1563
+ * Adds a new object from an element.
1564
+ */
1565
+ add(el: HTMLElement): void;
1566
+ setDOMBatcherEnabled(enabled: boolean): void;
1567
+ setIntersectionObserverEnabled(enabled: boolean): void;
1568
+ invalidateInviewIndex(): void;
1569
+ refreshLayoutForRoot(root: HTMLElement): void;
1570
+ /**
1571
+ * Removes an object by its id.
1572
+ */
1573
+ remove(id: string): void;
1574
+ /**
1575
+ * Add an element that will connect later.
1576
+ */
1577
+ enqueueConnection(id: string, element: HTMLElement): void;
1578
+ linkMirror(id: string, element: HTMLElement): void;
1579
+ private attachMirrorToObject;
1580
+ private detachMirrorByElement;
1581
+ private detachMirrorById;
1582
+ private getMirrorIds;
1583
+ private setMirrorIds;
1584
+ private clearMirrorIds;
1585
+ /**
1586
+ * Retrieves all attributes of a given HTML element and returns them as a record.
1587
+ *
1588
+ * @param el - The HTML element from which to extract attributes.
1589
+ * @returns A record where the keys are attribute names and the values are attribute values.
1590
+ */
1591
+ private getAllAttributes;
1592
+ /**
1593
+ * Initializes IntersectionObservers for a given object and its associated HTML element.
1594
+ *
1595
+ * This method sets up observer:
1596
+ * - A "progress" observer to track when the object enters or leaves the viewport.
1597
+ *
1598
+ * The observers are configured with custom root margins and thresholds based on the object's properties.
1599
+ * Existing observers, if any, are disconnected before creating new ones.
1600
+ *
1601
+ * @param obj - The `StringObject` instance containing properties and methods for interaction.
1602
+ * @param el - The `HTMLElement` to observe for intersection changes.
1603
+ */
1604
+ private initObservers;
1605
+ /**
1606
+ * Observes DOM mutations to auto-add/remove elements with [string] attribute.
1607
+ * Should be called once after DOM is ready.
1608
+ */
1609
+ observeDOM(): void;
1610
+ /**
1611
+ * Removes an object and its observers.
1612
+ */
1613
+ private handleRemoved;
1614
+ /**
1615
+ * Re-applies module initialization logic to all managed objects after settings change.
1616
+ *
1617
+ * This method should be called when `StringSettings` are updated at runtime,
1618
+ * especially if the new settings affect how modules calculate offsets,
1619
+ * easing, origins, or custom configuration.
1620
+ *
1621
+ * Internally, it re-runs `initializeObject`, `calculatePositions`, and `connectObject`
1622
+ * for each core module that can connect to the object.
1623
+ *
1624
+ * This is useful for supporting dynamic configuration updates without requiring
1625
+ * a full DOM rebuild or reinitialization.
1626
+ */
1627
+ onSettingsChange(data: ISettingsChangeData): void;
1628
+ /**
1629
+ * Checks whether the element is marked as fixed (not managed).
1630
+ */
1631
+ private isFixed;
1632
+ checkInview(): void;
1633
+ private checkInviewForObject;
1634
+ private updateInviewWindow;
1635
+ private rebuildInviewIndex;
1636
+ private upperBound;
1637
+ private splitPipeAndTrim;
1638
+ destroy(): void;
1639
+ }
1640
+
1641
+ /**
1642
+ * Shared context object passed to all modules and core controllers.
1643
+ *
1644
+ * Provides access to shared tools, data, settings, and event handling.
1645
+ */
1646
+ interface StringContext {
1647
+ /**
1648
+ * Collection of utility tools (e.g. lerp, dom parser, unit converter).
1649
+ */
1650
+ tools: StringToolsContainer;
1651
+ /**
1652
+ * Reactive state container including scroll, viewport, cursor, etc.
1653
+ */
1654
+ data: StringData;
1655
+ /**
1656
+ * Global configuration settings for modules and system behavior.
1657
+ */
1658
+ settings: StringSettings;
1659
+ /**
1660
+ * Centralized event emitter and listener system.
1661
+ */
1662
+ events: EventManager;
1663
+ /**
1664
+ * Caches the center positions of string objects.
1665
+ */
1666
+ centers: CenterCache;
1667
+ /**
1668
+ * Tracks hover states of string objects.
1669
+ */
1670
+ hover: HoverTracker;
1671
+ /**
1672
+ * Manages all interactive objects (elements with `string-*` attributes).
1673
+ */
1674
+ objectManager: ObjectManager;
1675
+ }
1676
+
1421
1677
  /**
1422
1678
  * StringCursor Module
1423
1679
  *
@@ -1475,6 +1731,7 @@ declare class StringCursor extends StringModule {
1475
1731
  private bindGlobalLifecycleListeners;
1476
1732
  private unbindGlobalLifecycleListeners;
1477
1733
  private setMouseCoordinates;
1734
+ private writePortalVars;
1478
1735
  private parseCursorVars;
1479
1736
  private getFrameAdjustedLerp;
1480
1737
  private getObjectDimensions;
@@ -1504,6 +1761,28 @@ declare class StringImpulse extends StringModule {
1504
1761
  */
1505
1762
  private getRotationOriginFromRect;
1506
1763
  onFrame(_: StringData): void;
1764
+ onMutate(): void;
1765
+ }
1766
+
1767
+ declare class StringMasonry extends StringModule {
1768
+ private states;
1769
+ constructor(context: StringContext);
1770
+ private parseEasing;
1771
+ onObjectConnected(object: StringObject): void;
1772
+ onFrame(data: StringData): void;
1773
+ onResize(): void;
1774
+ cleanupObject(object: StringObject): void;
1775
+ private createState;
1776
+ private handleAnimationEnd;
1777
+ private scheduleLayout;
1778
+ /**
1779
+ * Performs the layout calculation and application synchronously.
1780
+ * Optimizes for batched DOM reads and writes via `styleTxn`.
1781
+ */
1782
+ private performSyncLayout;
1783
+ private getGridSettings;
1784
+ private attachImgLoaders;
1785
+ private cleanupImgListeners;
1507
1786
  }
1508
1787
 
1509
1788
  declare class StringMagnetic extends StringModule {
@@ -1511,6 +1790,7 @@ declare class StringMagnetic extends StringModule {
1511
1790
  initializeObject(globalId: number, object: StringObject, element: HTMLElement, attributes: Record<string, any>): void;
1512
1791
  onMouseMove(e: MouseEvent): void;
1513
1792
  onFrame(data: StringData): void;
1793
+ onMutate(): void;
1514
1794
  }
1515
1795
 
1516
1796
  declare abstract class CursorReactiveModule extends StringModule {
@@ -1533,11 +1813,13 @@ declare abstract class CursorReactiveModule extends StringModule {
1533
1813
  }
1534
1814
 
1535
1815
  declare class StringSpotlight extends CursorReactiveModule {
1816
+ private readonly stepResult;
1536
1817
  constructor(context: any);
1537
1818
  initializeObject(id: number, obj: StringObject, el: HTMLElement, attrs: Record<string, any>): void;
1538
1819
  onMutate(data: StringData): void;
1539
1820
  protected onCursorScrollUpdate(): void;
1540
1821
  private updateSpotlightState;
1822
+ private writeSpotlightVars;
1541
1823
  }
1542
1824
 
1543
1825
  declare class StringLazy extends StringModule {
@@ -1610,6 +1892,7 @@ declare class StringGlide extends StringModule {
1610
1892
  private negativeVelocityMultiplier;
1611
1893
  private maxDisplacementValue;
1612
1894
  constructor(context: StringContext);
1895
+ initializeObject(globalId: number, object: StringObject, element: HTMLElement, attributes: Record<string, any>): void;
1613
1896
  private setupItem;
1614
1897
  private onUpdateDesktopEvent;
1615
1898
  private onUpdateMobileEvent;
@@ -1621,6 +1904,9 @@ declare class StringGlide extends StringModule {
1621
1904
  onScrollStart(): void;
1622
1905
  onScrollStop(): void;
1623
1906
  onFrame(data: StringData): void;
1907
+ onMutate(): void;
1908
+ private applyPendingGlideStyles;
1909
+ private flushPendingGlideStyles;
1624
1910
  }
1625
1911
 
1626
1912
  /**
@@ -1666,9 +1952,15 @@ declare class StringLerp extends StringModule {
1666
1952
 
1667
1953
  declare class StringProgress extends StringModule {
1668
1954
  protected updateScheduled: boolean;
1955
+ private batchStarts;
1956
+ private batchDiffs;
1957
+ private batchOut;
1669
1958
  constructor(context: StringContext);
1670
1959
  initializeObject(globalId: number, object: StringObject, element: HTMLElement, attributes: Record<string, any>): void;
1960
+ private sanitizeRawProgress;
1961
+ private applyRawProgress;
1671
1962
  private recomputeProgress;
1963
+ private ensureBatchCapacity;
1672
1964
  calculatePositions(object: StringObject, windowSize: number): void;
1673
1965
  onScroll(data: StringData): void;
1674
1966
  onObjectConnected(object: StringObject): void;
@@ -1713,6 +2005,7 @@ declare class StringScrollbar extends StringModule {
1713
2005
  private scrollbarState;
1714
2006
  private scrollbarStateHorizontal;
1715
2007
  private scrollbarStateVertical;
2008
+ private requestScrollTo;
1716
2009
  constructor(context: StringContext);
1717
2010
  destructor(): void;
1718
2011
  onInit(): void;
@@ -2031,6 +2324,11 @@ interface ScrollMarkRule {
2031
2324
  */
2032
2325
  className: string;
2033
2326
  };
2327
+ /**
2328
+ * Internal state tracking whether the rule is currently active.
2329
+ * prevents redundant callbacks and class toggles.
2330
+ */
2331
+ isActive?: boolean;
2034
2332
  }
2035
2333
 
2036
2334
  declare class StringSequence extends StringModule {
@@ -2121,6 +2419,95 @@ declare class StringScroller extends StringModule {
2121
2419
  onObjectDisconnected(object: StringObject): void;
2122
2420
  }
2123
2421
 
2422
+ /**
2423
+ * Module that provides smooth scrolling behavior for isolated containers.
2424
+ * Allows nested elements to have independent smooth scroll physics similar to the main window.
2425
+ *
2426
+ * Usage:
2427
+ * Add `string="scroll-container"` to any block element.
2428
+ * Optional: `string-lerp="0.1"` to controls the smoothing factor.
2429
+ */
2430
+ declare class StringScrollContainer extends StringModule {
2431
+ /**
2432
+ * WeakMap storing the state for each managed HTMLElement.
2433
+ */
2434
+ private states;
2435
+ /**
2436
+ * Initializes the StringScrollContainer module.
2437
+ * Registers the `lerp` attribute configuration.
2438
+ *
2439
+ * @param context The shared StringTune context.
2440
+ */
2441
+ constructor(context: StringContext);
2442
+ /**
2443
+ * Called when a new object with `string="scroll-container"` is initialized.
2444
+ * Sets up initial state, event listeners, and default styles.
2445
+ *
2446
+ * @param object The StringObject instance being connected.
2447
+ */
2448
+ onObjectConnected(object: StringObject): void;
2449
+ /**
2450
+ * Called when an object is removed from the DOM or disconnected.
2451
+ * Cleans up the state associated with the element.
2452
+ *
2453
+ * @param object The StringObject instance being disconnected.
2454
+ */
2455
+ onObjectDisconnected(object: StringObject): void;
2456
+ /**
2457
+ * Main animation loop for the module.
2458
+ * Updates the scroll position of active containers based on their target state.
2459
+ *
2460
+ * @param data Global frame data including time deltas.
2461
+ */
2462
+ onFrame(data: StringData): void;
2463
+ /**
2464
+ * Called when the window or layout is resized.
2465
+ * Recalculates scroll boundaries for all managed containers.
2466
+ */
2467
+ onResize(): void;
2468
+ /**
2469
+ * Recalculates the maximum scrollable distance for a container.
2470
+ *
2471
+ * @param el The scroll container element.
2472
+ * @param state The state object associated with the element.
2473
+ */
2474
+ private measure;
2475
+ /**
2476
+ * Handles the mouse wheel event to apply custom scroll physics.
2477
+ * Intercepts the event to prevent native scrolling and updates the target position.
2478
+ * Allows event propagation if scrolling past the boundaries (scroll chaining).
2479
+ *
2480
+ * @param e The WheelEvent triggered by the user.
2481
+ * @param el The target scroll container element.
2482
+ * @param state The state object associated with the element.
2483
+ */
2484
+ private handleWheel;
2485
+ /**
2486
+ * Placeholder for global wheel handler if needed by generic StringModule interface.
2487
+ * Specific handling is done via local event listeners in `handleWheel`.
2488
+ *
2489
+ * @param e Global WheelEvent.
2490
+ */
2491
+ onWheel(e: WheelEvent): void;
2492
+ /**
2493
+ * Handles native scroll events (dragbars, keyboard, touch).
2494
+ * Syncs the internal state with the native scroll position if the custom animation is not active.
2495
+ *
2496
+ * @param e The Scroll event.
2497
+ * @param el The target scroll container element.
2498
+ * @param state The state object associated with the element.
2499
+ */
2500
+ private onNativeScroll;
2501
+ /**
2502
+ * Updates the element's scrollTop property by interpolating towards the target.
2503
+ * Stops the animation if the difference is negligible.
2504
+ *
2505
+ * @param el The scroll container element.
2506
+ * @param state The state object associated with the element.
2507
+ */
2508
+ private updateScroll;
2509
+ }
2510
+
2124
2511
  declare class StringProgressPart extends StringModule {
2125
2512
  constructor(context: StringContext);
2126
2513
  onObjectConnected(object: StringObject): void;
@@ -2134,25 +2521,120 @@ declare class FrameDOM {
2134
2521
  private scheduled;
2135
2522
  measure(fn: Job): void;
2136
2523
  mutate(fn: Job): void;
2137
- private schedule;
2524
+ schedule(): void;
2525
+ flush(): void;
2138
2526
  }
2139
2527
  declare const frameDOM: FrameDOM;
2140
2528
 
2141
- type StyleValue = string | number;
2142
- type StyleVars = Record<string, StyleValue>;
2143
- type StyleProps = Record<string, StyleValue>;
2144
- declare class StyleTxn {
2145
- private pendingVars;
2146
- private pendingProps;
2147
- private isOpen;
2148
- begin(): void;
2149
- setVars(el: Element, vars: StyleVars): void;
2150
- setProps(el: Element, props: StyleProps): void;
2151
- run(fn: () => void): void;
2152
- commit(): void;
2153
- cancel(): void;
2529
+ declare class StringRandom extends StringModule {
2530
+ constructor(context: StringContext);
2531
+ onObjectConnected(object: StringObject): void;
2532
+ }
2533
+
2534
+ /**
2535
+ * Base class for managing scroll behavior in the system.
2536
+ * Handles abstract scroll state and updates, intended for extension.
2537
+ */
2538
+ declare class ScrollController {
2539
+ /** Shared context containing data and tools */
2540
+ protected context: StringContext;
2541
+ /** Reference to the document object */
2542
+ protected document: Document;
2543
+ /** Name of the scroll mode (e.g. 'default', 'smooth', etc.) */
2544
+ name: string;
2545
+ /** Whether the system is in programmatic scroll mode */
2546
+ isProg: boolean;
2547
+ /** Whether parallax-related logic should be active */
2548
+ isParallaxEnabled: boolean;
2549
+ /** Scroll direction: vertical or horizontal */
2550
+ protected _scrollDirection: "vertical" | "horizontal";
2551
+ /**
2552
+ * Current scroll direction.
2553
+ * - `true` — scrolling down
2554
+ * - `false` — scrolling up
2555
+ * - `null` — unknown (initial state)
2556
+ */
2557
+ protected isBottomScrollDirection: boolean | null;
2558
+ protected isLastBottomScrollDirection: boolean;
2559
+ protected scrollTriggerRules: Array<ScrollMarkRule>;
2560
+ /** Tracks whether this controller is currently active */
2561
+ protected isActive: boolean;
2562
+ /** Last direction applied to DOM classes (for global-class toggles) */
2563
+ protected lastAppliedDirection: boolean | null;
2564
+ /**
2565
+ * Sets scroll direction and updates internal scroll logic.
2566
+ * @param scrollDirection Either 'vertical' or 'horizontal'.
2567
+ */
2568
+ set scrollDirection(scrollDirection: "vertical" | "horizontal");
2569
+ /**
2570
+ * Creates a new ScrollController instance.
2571
+ * @param context Shared context containing data and settings.
2572
+ */
2573
+ constructor(context: StringContext);
2574
+ /**
2575
+ * Called when scroll direction changes (up ↔ down).
2576
+ * Override this callback in subclasses or instances.
2577
+ */
2578
+ onChangeDirection: () => void;
2579
+ /**
2580
+ * Called when scroll starts (user input).
2581
+ * Override this callback in subclasses or instances.
2582
+ */
2583
+ onScrollStart: () => void;
2584
+ /**
2585
+ * Called when scroll ends.
2586
+ * Override this callback in subclasses or instances.
2587
+ */
2588
+ onScrollStop: () => void;
2589
+ /**
2590
+ * Scroll-to function called on each frame.
2591
+ * This will be reassigned depending on scroll direction.
2592
+ */
2593
+ onCalcUpdate: () => void;
2594
+ /**
2595
+ * Called every animation frame.
2596
+ * Intended to be overridden in subclasses.
2597
+ */
2598
+ onFrame(): void;
2599
+ /**
2600
+ * Called when wheel event is fired.
2601
+ * Override to implement custom scroll interaction.
2602
+ * @param e Wheel event.
2603
+ */
2604
+ onWheel(e: any): void;
2605
+ /**
2606
+ * Called when native scroll event is fired.
2607
+ * Override to track native scroll position.
2608
+ * @param e Scroll event.
2609
+ */
2610
+ onScroll(e: any): void;
2611
+ disableScrollEvents(): void;
2612
+ enableScrollEvents(): void;
2613
+ /**
2614
+ * Called when this controller becomes the active scroll engine.
2615
+ * Ensures event bindings are attached only once.
2616
+ */
2617
+ activate(): void;
2618
+ /**
2619
+ * Called when this controller is deactivated.
2620
+ * Ensures event bindings are detached only once.
2621
+ */
2622
+ deactivate(): void;
2623
+ /**
2624
+ * Allows controllers to clean up resources on global destroy.
2625
+ */
2626
+ destroy(): void;
2627
+ /**
2628
+ * Updates scroll direction state, emits events, and toggles global classes.
2629
+ * Intended for reuse by custom scroll adapters.
2630
+ */
2631
+ protected updateScrollDirection(newDirection: boolean): void;
2632
+ protected clearScrollingClasses(): void;
2633
+ protected triggerScrollRules(): void;
2634
+ addScrollMark(rule: ScrollMarkRule): void;
2635
+ removeScrollMark(id: string): void;
2636
+ scrollTo(position: number, immediate?: boolean): void;
2154
2637
  }
2155
- declare const styleTxn: StyleTxn;
2156
2638
 
2157
2639
  interface ModuleBatchContext {
2158
2640
  module: StringModule;
@@ -2200,10 +2682,16 @@ declare class StringTune {
2200
2682
  private onResizeBind;
2201
2683
  /** Bound mouse move handler */
2202
2684
  private onMouseMoveBind;
2685
+ /** Bound scroll to handler */
2686
+ private onScrollToBind;
2687
+ private onDOMChangedBind;
2203
2688
  private onContainerTransitionEndBind;
2204
2689
  private onResizeObserverBind;
2205
2690
  private pendingScroll;
2206
2691
  private lastScrollEmitted;
2692
+ private observerContainerMutation;
2693
+ private pendingResizeRaf;
2694
+ private pendingResizeForce;
2207
2695
  /** Singleton instance of StringTune */
2208
2696
  private static i;
2209
2697
  /** Root scrollable element (typically <body>) */
@@ -2313,6 +2801,19 @@ declare class StringTune {
2313
2801
  * @param settings Optional settings specific to this module.
2314
2802
  */
2315
2803
  use(objectClass: typeof StringModule, settings?: any): void;
2804
+ /**
2805
+ * Registers a new scroll mode (provider) to the system.
2806
+ * Allows integrating custom scroll implementations (e.g. Lenis, Locomotive).
2807
+ *
2808
+ * @param name The unique name for this scroll mode (e.g. 'smooth', 'lenis').
2809
+ * @param factory A function that receives the StringContext and returns a ScrollController instance, OR a ScrollController class constructor.
2810
+ *
2811
+ * Example:
2812
+ * ```ts
2813
+ * stringTune.registerScrollMode("custom", (context) => new CustomAdapter(context));
2814
+ * ```
2815
+ */
2816
+ registerScrollMode(name: string, factory: ((context: StringContext) => ScrollController) | (new (context: StringContext) => ScrollController)): void;
2316
2817
  /**
2317
2818
  * Subscribes to a global event within the system.
2318
2819
  *
@@ -2375,6 +2876,9 @@ declare class StringTune {
2375
2876
  setupSettings(settings: StringSettings): void;
2376
2877
  private onResizeObserverEvent;
2377
2878
  private onContainerTransitionEnd;
2879
+ private onDOMChanged;
2880
+ private observeContainerMutations;
2881
+ private queueResize;
2378
2882
  /**
2379
2883
  * Handles mouse move event and dispatches it to cursor and modules.
2380
2884
  * @param e Native mouse move event.
@@ -2423,28 +2927,12 @@ declare class StringTune {
2423
2927
  * Rebuilds layout and triggers module resize if size really changed.
2424
2928
  */
2425
2929
  onResize(force?: boolean): void;
2426
- /**
2427
- * Scrolls the container to the specified element identified by a CSS selector, applying an optional offset.
2428
- *
2429
- * Calculates the vertical position of the target element relative to the scroll container and updates the scroll delta accordingly.
2430
- * If the element is not found, a warning is logged to the console.
2431
- *
2432
- * @param selector - The CSS selector string used to identify the target element.
2433
- * @param offset - Optional. The number of pixels to offset from the target element's top position. Defaults to 0.
2434
- */
2435
- scrollToElement(selector: string, offset?: number): void;
2436
- scrollTo(position: number): void;
2437
2930
  invalidateCenter(id: string): void;
2438
- /**
2439
- * Forces center cache recalculation for all tracked objects.
2440
- * Useful when DOM geometry changes outside of StringTune's control.
2441
- */
2442
- invalidateCenters(): void;
2443
- /**
2444
- * Cleans up the system, removes all event listeners, stops the loop,
2445
- * and destroys modules and event subscriptions.
2446
- */
2931
+ scrollTo(value: number | {
2932
+ position: number;
2933
+ immediate?: boolean;
2934
+ }): void;
2447
2935
  destroy(): void;
2448
2936
  }
2449
2937
 
2450
- export { CursorReactiveModule, DOMBatcher, 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 };
2938
+ export { CursorReactiveModule, DOMBatcher, ScrollController, type ScrollMarkRule as ScrollTriggerRule, StringAnchor, type StringContext, StringCursor, StringData, StringDelayLerpTracker, StringFPSTracker, StringForm, StringGlide, StringImpulse, StringLazy, StringLerp, StringLerpTracker, StringLoading, StringMagnetic, StringMasonry, StringModule, StringObject, StringParallax, StringPositionTracker, StringProgress, StringProgressPart, StringRandom, StringResponsive, StringScrollContainer, StringScrollbar, StringScroller, StringSequence, StringSplit, StringSpotlight, StringTune, StringVideoAutoplay, StringTune as default, frameDOM, styleTxn };