@fiddle-digital/string-tune 1.1.49 → 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.mts CHANGED
@@ -71,7 +71,8 @@ declare class RenderState {
71
71
  }
72
72
 
73
73
  type ScrollDirection = 'vertical' | 'horizontal';
74
- type ScrollMode = 'smooth' | 'disable' | 'default' | (string & {});
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
  */
@@ -455,6 +456,30 @@ declare class StringObject {
455
456
  * Internal key-value store of dynamic object properties (like offsets, progress, etc.).
456
457
  */
457
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;
458
483
  /**
459
484
  * Modules currently connected to this object.
460
485
  */
@@ -465,6 +490,12 @@ declare class StringObject {
465
490
  */
466
491
  events: EventManager;
467
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;
468
499
  /**
469
500
  * Stores a property value for this object.
470
501
  * @param key - Property name
@@ -505,7 +536,7 @@ declare class StringObject {
505
536
  * Connects a module to this object if not already connected.
506
537
  * @param module - The module to connect
507
538
  */
508
- connect(module: IStringModule): void;
539
+ connect(module: IStringModule): boolean;
509
540
  addMirror(mirror: StringMirrorObject): void;
510
541
  removeMirror(id: string): void;
511
542
  get mirrorObjects(): StringMirrorObject[];
@@ -542,6 +573,32 @@ interface ISettingsChangeData {
542
573
  scrollHeightChanged: boolean;
543
574
  }
544
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
+
545
602
  /**
546
603
  * Base interface for injectable core tools in the String system.
547
604
  * Each tool takes input and returns output (transform, extract, calculate).
@@ -1075,7 +1132,8 @@ declare class ValidationTool implements IStringTool<ValidateInput, ValidationRes
1075
1132
  }
1076
1133
 
1077
1134
  /**
1078
- * Interface describing all available tools used inside modules.
1135
+ * Container holding references to all essential tools used within the library.
1136
+ * Dependency injection.
1079
1137
  */
1080
1138
  interface StringToolsContainer {
1081
1139
  /** Tool for reading DOM attributes (including data-*). */
@@ -1136,6 +1194,7 @@ interface StringToolsContainer {
1136
1194
  transformScaleParser: TransformScaleParserTool;
1137
1195
  optionsParser: SplitOptionsParserTool;
1138
1196
  ruleParser: RuleParserTool;
1197
+ styleTxn: typeof styleTxn;
1139
1198
  }
1140
1199
 
1141
1200
  type AttributeType = "string" | "number" | "boolean" | "json" | "dimension" | "breakpoint-dimension" | "tuple" | "easing" | "color" | {
@@ -1186,6 +1245,17 @@ declare class StringModule implements IStringModule {
1186
1245
  * Example: ["offset-top", "offset-bottom"]
1187
1246
  */
1188
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
+ }>;
1189
1259
  /**
1190
1260
  * A map that associates string keys with `StringObject` instances.
1191
1261
  * This map is used to manage and track `StringObject` instances on a page.
@@ -1358,6 +1428,26 @@ declare class StringModule implements IStringModule {
1358
1428
  * @param applyFn The function that receives an HTMLElement and performs any update.
1359
1429
  */
1360
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;
1361
1451
  /**
1362
1452
  * Cleans up internal state and detaches the module from the system.
1363
1453
  */
@@ -1438,7 +1528,7 @@ declare class ModuleManager {
1438
1528
  get core(): IStringModule[];
1439
1529
  get ui(): IStringModule[];
1440
1530
  private callAll;
1441
- private callLifecycle;
1531
+ private callLifecycleStrict;
1442
1532
  private rebuildAllModules;
1443
1533
  }
1444
1534
 
@@ -1449,6 +1539,7 @@ declare class ObjectManager {
1449
1539
  private tools;
1450
1540
  private objects;
1451
1541
  private connectQueue;
1542
+ private connectableModulesBuffer;
1452
1543
  private mirrors;
1453
1544
  private mirrorId;
1454
1545
  private globalId;
@@ -1462,6 +1553,7 @@ declare class ObjectManager {
1462
1553
  private inviewIndexDirty;
1463
1554
  private lastInviewScrollPos;
1464
1555
  private intersectionObserverEnabled;
1556
+ private domObserver;
1465
1557
  constructor(data: StringData, modules: ModuleManager, events: EventManager, tools: StringToolsContainer);
1466
1558
  /**
1467
1559
  * Returns the object map (read-only).
@@ -1542,6 +1634,8 @@ declare class ObjectManager {
1542
1634
  private updateInviewWindow;
1543
1635
  private rebuildInviewIndex;
1544
1636
  private upperBound;
1637
+ private splitPipeAndTrim;
1638
+ destroy(): void;
1545
1639
  }
1546
1640
 
1547
1641
  /**
@@ -1637,6 +1731,7 @@ declare class StringCursor extends StringModule {
1637
1731
  private bindGlobalLifecycleListeners;
1638
1732
  private unbindGlobalLifecycleListeners;
1639
1733
  private setMouseCoordinates;
1734
+ private writePortalVars;
1640
1735
  private parseCursorVars;
1641
1736
  private getFrameAdjustedLerp;
1642
1737
  private getObjectDimensions;
@@ -1666,6 +1761,7 @@ declare class StringImpulse extends StringModule {
1666
1761
  */
1667
1762
  private getRotationOriginFromRect;
1668
1763
  onFrame(_: StringData): void;
1764
+ onMutate(): void;
1669
1765
  }
1670
1766
 
1671
1767
  declare class StringMasonry extends StringModule {
@@ -1694,6 +1790,7 @@ declare class StringMagnetic extends StringModule {
1694
1790
  initializeObject(globalId: number, object: StringObject, element: HTMLElement, attributes: Record<string, any>): void;
1695
1791
  onMouseMove(e: MouseEvent): void;
1696
1792
  onFrame(data: StringData): void;
1793
+ onMutate(): void;
1697
1794
  }
1698
1795
 
1699
1796
  declare abstract class CursorReactiveModule extends StringModule {
@@ -1716,11 +1813,13 @@ declare abstract class CursorReactiveModule extends StringModule {
1716
1813
  }
1717
1814
 
1718
1815
  declare class StringSpotlight extends CursorReactiveModule {
1816
+ private readonly stepResult;
1719
1817
  constructor(context: any);
1720
1818
  initializeObject(id: number, obj: StringObject, el: HTMLElement, attrs: Record<string, any>): void;
1721
1819
  onMutate(data: StringData): void;
1722
1820
  protected onCursorScrollUpdate(): void;
1723
1821
  private updateSpotlightState;
1822
+ private writeSpotlightVars;
1724
1823
  }
1725
1824
 
1726
1825
  declare class StringLazy extends StringModule {
@@ -1793,6 +1892,7 @@ declare class StringGlide extends StringModule {
1793
1892
  private negativeVelocityMultiplier;
1794
1893
  private maxDisplacementValue;
1795
1894
  constructor(context: StringContext);
1895
+ initializeObject(globalId: number, object: StringObject, element: HTMLElement, attributes: Record<string, any>): void;
1796
1896
  private setupItem;
1797
1897
  private onUpdateDesktopEvent;
1798
1898
  private onUpdateMobileEvent;
@@ -1804,6 +1904,9 @@ declare class StringGlide extends StringModule {
1804
1904
  onScrollStart(): void;
1805
1905
  onScrollStop(): void;
1806
1906
  onFrame(data: StringData): void;
1907
+ onMutate(): void;
1908
+ private applyPendingGlideStyles;
1909
+ private flushPendingGlideStyles;
1807
1910
  }
1808
1911
 
1809
1912
  /**
@@ -1849,9 +1952,15 @@ declare class StringLerp extends StringModule {
1849
1952
 
1850
1953
  declare class StringProgress extends StringModule {
1851
1954
  protected updateScheduled: boolean;
1955
+ private batchStarts;
1956
+ private batchDiffs;
1957
+ private batchOut;
1852
1958
  constructor(context: StringContext);
1853
1959
  initializeObject(globalId: number, object: StringObject, element: HTMLElement, attributes: Record<string, any>): void;
1960
+ private sanitizeRawProgress;
1961
+ private applyRawProgress;
1854
1962
  private recomputeProgress;
1963
+ private ensureBatchCapacity;
1855
1964
  calculatePositions(object: StringObject, windowSize: number): void;
1856
1965
  onScroll(data: StringData): void;
1857
1966
  onObjectConnected(object: StringObject): void;
@@ -1896,6 +2005,7 @@ declare class StringScrollbar extends StringModule {
1896
2005
  private scrollbarState;
1897
2006
  private scrollbarStateHorizontal;
1898
2007
  private scrollbarStateVertical;
2008
+ private requestScrollTo;
1899
2009
  constructor(context: StringContext);
1900
2010
  destructor(): void;
1901
2011
  onInit(): void;
@@ -2309,6 +2419,95 @@ declare class StringScroller extends StringModule {
2309
2419
  onObjectDisconnected(object: StringObject): void;
2310
2420
  }
2311
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
+
2312
2511
  declare class StringProgressPart extends StringModule {
2313
2512
  constructor(context: StringContext);
2314
2513
  onObjectConnected(object: StringObject): void;
@@ -2322,26 +2521,11 @@ declare class FrameDOM {
2322
2521
  private scheduled;
2323
2522
  measure(fn: Job): void;
2324
2523
  mutate(fn: Job): void;
2325
- private schedule;
2524
+ schedule(): void;
2525
+ flush(): void;
2326
2526
  }
2327
2527
  declare const frameDOM: FrameDOM;
2328
2528
 
2329
- type StyleValue = string | number;
2330
- type StyleVars = Record<string, StyleValue>;
2331
- type StyleProps = Record<string, StyleValue>;
2332
- declare class StyleTxn {
2333
- private pendingVars;
2334
- private pendingProps;
2335
- private isOpen;
2336
- begin(): void;
2337
- setVars(el: Element, vars: StyleVars): void;
2338
- setProps(el: Element, props: StyleProps): void;
2339
- run(fn: () => void): void;
2340
- commit(): void;
2341
- cancel(): void;
2342
- }
2343
- declare const styleTxn: StyleTxn;
2344
-
2345
2529
  declare class StringRandom extends StringModule {
2346
2530
  constructor(context: StringContext);
2347
2531
  onObjectConnected(object: StringObject): void;
@@ -2373,6 +2557,10 @@ declare class ScrollController {
2373
2557
  protected isBottomScrollDirection: boolean | null;
2374
2558
  protected isLastBottomScrollDirection: boolean;
2375
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;
2376
2564
  /**
2377
2565
  * Sets scroll direction and updates internal scroll logic.
2378
2566
  * @param scrollDirection Either 'vertical' or 'horizontal'.
@@ -2422,10 +2610,30 @@ declare class ScrollController {
2422
2610
  onScroll(e: any): void;
2423
2611
  disableScrollEvents(): void;
2424
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;
2425
2633
  protected triggerScrollRules(): void;
2426
2634
  addScrollMark(rule: ScrollMarkRule): void;
2427
2635
  removeScrollMark(id: string): void;
2428
- scrollTo(position: number): void;
2636
+ scrollTo(position: number, immediate?: boolean): void;
2429
2637
  }
2430
2638
 
2431
2639
  interface ModuleBatchContext {
@@ -2476,10 +2684,14 @@ declare class StringTune {
2476
2684
  private onMouseMoveBind;
2477
2685
  /** Bound scroll to handler */
2478
2686
  private onScrollToBind;
2687
+ private onDOMChangedBind;
2479
2688
  private onContainerTransitionEndBind;
2480
2689
  private onResizeObserverBind;
2481
2690
  private pendingScroll;
2482
2691
  private lastScrollEmitted;
2692
+ private observerContainerMutation;
2693
+ private pendingResizeRaf;
2694
+ private pendingResizeForce;
2483
2695
  /** Singleton instance of StringTune */
2484
2696
  private static i;
2485
2697
  /** Root scrollable element (typically <body>) */
@@ -2598,7 +2810,7 @@ declare class StringTune {
2598
2810
  *
2599
2811
  * Example:
2600
2812
  * ```ts
2601
- * stringTune.registerScrollMode("lenis", (context) => new LenisAdapter(context));
2813
+ * stringTune.registerScrollMode("custom", (context) => new CustomAdapter(context));
2602
2814
  * ```
2603
2815
  */
2604
2816
  registerScrollMode(name: string, factory: ((context: StringContext) => ScrollController) | (new (context: StringContext) => ScrollController)): void;
@@ -2664,6 +2876,9 @@ declare class StringTune {
2664
2876
  setupSettings(settings: StringSettings): void;
2665
2877
  private onResizeObserverEvent;
2666
2878
  private onContainerTransitionEnd;
2879
+ private onDOMChanged;
2880
+ private observeContainerMutations;
2881
+ private queueResize;
2667
2882
  /**
2668
2883
  * Handles mouse move event and dispatches it to cursor and modules.
2669
2884
  * @param e Native mouse move event.
@@ -2713,8 +2928,11 @@ declare class StringTune {
2713
2928
  */
2714
2929
  onResize(force?: boolean): void;
2715
2930
  invalidateCenter(id: string): void;
2716
- scrollTo(position: number): void;
2931
+ scrollTo(value: number | {
2932
+ position: number;
2933
+ immediate?: boolean;
2934
+ }): void;
2717
2935
  destroy(): void;
2718
2936
  }
2719
2937
 
2720
- 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, 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 };