@fiddle-digital/string-tune 1.1.41 → 1.1.42-fix.1

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
@@ -737,15 +737,50 @@ interface OriginInput {
737
737
  /** Raw origin string, e.g. `'center'` or `'random(top, bottom)'`. */
738
738
  value: string;
739
739
  }
740
+ /**
741
+ * Input for parsing origin to normalized coordinates.
742
+ * Supports formats like `'left top'`, `'center center'`, `'50% 50%'`, `'35% 76%'`.
743
+ */
744
+ interface OriginToNormalizedInput {
745
+ /** Raw origin string, e.g. `'left top'`, `'center'`, `'50% 25%'`. */
746
+ value: string;
747
+ }
748
+ /**
749
+ * Output: normalized origin coordinates (0-1 range).
750
+ */
751
+ interface NormalizedOrigin {
752
+ /** Normalized X coordinate (0 = left, 0.5 = center, 1 = right). */
753
+ x: number;
754
+ /** Normalized Y coordinate (0 = top, 0.5 = center, 1 = bottom). */
755
+ y: number;
756
+ }
740
757
  /**
741
758
  * Tool that parses origin strings.
742
759
  * Allows static values like `'center'`, or expressions like `'random(...)'` to select one randomly.
760
+ * Also provides `toNormalized()` method to convert origin strings to `{ x, y }` coordinates.
743
761
  */
744
762
  declare class OriginParserTool implements IStringTool<OriginInput, string> {
745
763
  /**
746
764
  * @returns Parsed string value (static or randomly chosen).
747
765
  */
748
766
  process({ value }: OriginInput): string;
767
+ /**
768
+ * Parses an origin string to normalized `{ x, y }` coordinates (0-1 range).
769
+ *
770
+ * Supported formats:
771
+ * - Single keyword: `'center'`, `'top'`, `'left'`, etc.
772
+ * - Two keywords: `'left top'`, `'right bottom'`, `'center center'`
773
+ * - Percentages: `'50% 50%'`, `'0% 100%'`, `'35% 76%'`
774
+ * - Mixed: `'left 25%'`, `'50% top'`
775
+ *
776
+ * @param input - The origin string to parse.
777
+ * @returns Normalized `{ x, y }` coordinates.
778
+ */
779
+ toNormalized({ value }: OriginToNormalizedInput): NormalizedOrigin;
780
+ /**
781
+ * Parses a single value (keyword or percentage) to a normalized number.
782
+ */
783
+ private parseValue;
749
784
  }
750
785
 
751
786
  interface StringColor {
@@ -1464,11 +1499,25 @@ declare class StringCursor extends StringModule {
1464
1499
  }
1465
1500
 
1466
1501
  declare class StringImpulse extends StringModule {
1502
+ private originObservers;
1467
1503
  constructor(context: StringContext);
1468
1504
  onObjectConnected(object: StringObject): void;
1469
1505
  onObjectDisconnected(object: StringObject): void;
1470
1506
  onMouseMove(_e?: MouseEvent): void;
1471
- private getElementsAtPoint;
1507
+ /**
1508
+ * Parses and caches the rotation origin for an object.
1509
+ * Called once on object connection and when attribute changes.
1510
+ */
1511
+ private cacheRotationOrigin;
1512
+ /**
1513
+ * Observes changes to the rotation-origin attribute and re-caches when changed.
1514
+ */
1515
+ private observeRotationOrigin;
1516
+ /**
1517
+ * Calculates the rotation origin point using cached normalized values and provided rect.
1518
+ * Avoids re-parsing origin string and extra getBoundingClientRect calls.
1519
+ */
1520
+ private getRotationOriginFromRect;
1472
1521
  onFrame(_: StringData): void;
1473
1522
  }
1474
1523
 
@@ -1776,16 +1825,22 @@ declare class StringDelayLerpTracker extends StringModule {
1776
1825
 
1777
1826
  /**
1778
1827
  * FPS Tracker Module.
1779
- * Displays how many times `onFrame()` is called per second.
1780
- * Useful for debugging rendering performance or vsync issues.
1828
+ * Broadcasts frame rate to elements with `data-fps` attribute.
1829
+ * Also creates an optional debug display element.
1781
1830
  */
1782
1831
  declare class StringFPSTracker extends StringModule {
1783
1832
  private displayElement;
1784
1833
  private intervalId;
1785
1834
  private frameCount;
1835
+ /** Cached elements with data-fps attribute */
1836
+ private fpsElements;
1837
+ /** MutationObserver for DOM changes */
1838
+ private observer;
1839
+ /** Last known FPS to avoid redundant updates */
1840
+ private lastFps;
1786
1841
  constructor(context: StringContext);
1787
1842
  /**
1788
- * Initializes the visual FPS counter and update interval.
1843
+ * Initializes the visual FPS counter, scans for elements, and starts interval.
1789
1844
  */
1790
1845
  onInit(): void;
1791
1846
  /**
@@ -1793,9 +1848,29 @@ declare class StringFPSTracker extends StringModule {
1793
1848
  */
1794
1849
  onFrame(_data: StringData): void;
1795
1850
  /**
1796
- * Cleans up DOM and interval.
1851
+ * Cleans up DOM, observer, and interval.
1797
1852
  */
1798
1853
  destroy(): void;
1854
+ /**
1855
+ * Handles visibility toggle from external API.
1856
+ */
1857
+ private onVisibilityChange;
1858
+ /**
1859
+ * Removes the display element and its styles.
1860
+ */
1861
+ private removeDisplayElement;
1862
+ /**
1863
+ * Updates all tracked elements with current FPS.
1864
+ */
1865
+ private updateFPS;
1866
+ /**
1867
+ * Scans document for elements with data-fps attribute.
1868
+ */
1869
+ private scanElements;
1870
+ /**
1871
+ * Observes DOM for added/removed elements with data-fps attribute.
1872
+ */
1873
+ private observeDOM;
1799
1874
  /**
1800
1875
  * Creates and styles the floating FPS display.
1801
1876
  */
@@ -1842,24 +1917,55 @@ declare class StringLerpTracker extends StringModule {
1842
1917
  }
1843
1918
 
1844
1919
  /**
1845
- * Tracker module that shows current scroll position and direction.
1846
- * Displays a fixed label in the corner of the screen for debugging.
1920
+ * Tracker module that broadcasts scroll position to elements with data attributes.
1921
+ * Elements with `data-val`, `data-val-pct`, or `data-dir` will receive updates.
1922
+ * Also creates an optional debug display element.
1847
1923
  */
1848
1924
  declare class StringPositionTracker extends StringModule {
1849
1925
  private displayElement;
1926
+ /** Cached elements by attribute type */
1927
+ private valElements;
1928
+ private valPctElements;
1929
+ private dirElements;
1930
+ /** MutationObserver for DOM changes */
1931
+ private observer;
1932
+ /** Last known values to avoid redundant updates */
1933
+ private lastVal;
1934
+ private lastValPct;
1935
+ private lastDir;
1850
1936
  constructor(context: StringContext);
1851
1937
  /**
1852
- * Called on start — creates the DOM element for position display.
1938
+ * Called on start — creates debug element and scans for tracked elements.
1853
1939
  */
1854
1940
  onInit(): void;
1855
1941
  /**
1856
- * Called on scroll — updates scroll position and direction symbol.
1942
+ * Called on scroll — updates all tracked elements with position data.
1857
1943
  */
1858
1944
  onScroll(data: StringData): void;
1859
1945
  /**
1860
- * Removes display element from DOM.
1946
+ * Cleans up DOM observer and display element.
1861
1947
  */
1862
1948
  destroy(): void;
1949
+ /**
1950
+ * Handles visibility toggle from external API.
1951
+ */
1952
+ private onVisibilityChange;
1953
+ /**
1954
+ * Removes the display element.
1955
+ */
1956
+ private removeDisplayElement;
1957
+ /**
1958
+ * Scans document for elements with tracking attributes.
1959
+ */
1960
+ private scanElements;
1961
+ /**
1962
+ * Observes DOM for added/removed elements with tracking attributes.
1963
+ */
1964
+ private observeDOM;
1965
+ /**
1966
+ * Checks if element has any tracking attribute.
1967
+ */
1968
+ private hasTrackingAttr;
1863
1969
  /**
1864
1970
  * Creates and styles the floating position indicator.
1865
1971
  */
@@ -2125,6 +2231,8 @@ declare class StringTune {
2125
2231
  * Can be 'smooth', 'default', or 'disable'.
2126
2232
  */
2127
2233
  set scrollMobileMode(mode: ScrollMode);
2234
+ set FPSTrackerVisible(visible: boolean);
2235
+ set PositionTrackerVisible(visible: boolean);
2128
2236
  private debouncedResize;
2129
2237
  private constructor();
2130
2238
  /**
package/dist/index.d.ts CHANGED
@@ -737,15 +737,50 @@ interface OriginInput {
737
737
  /** Raw origin string, e.g. `'center'` or `'random(top, bottom)'`. */
738
738
  value: string;
739
739
  }
740
+ /**
741
+ * Input for parsing origin to normalized coordinates.
742
+ * Supports formats like `'left top'`, `'center center'`, `'50% 50%'`, `'35% 76%'`.
743
+ */
744
+ interface OriginToNormalizedInput {
745
+ /** Raw origin string, e.g. `'left top'`, `'center'`, `'50% 25%'`. */
746
+ value: string;
747
+ }
748
+ /**
749
+ * Output: normalized origin coordinates (0-1 range).
750
+ */
751
+ interface NormalizedOrigin {
752
+ /** Normalized X coordinate (0 = left, 0.5 = center, 1 = right). */
753
+ x: number;
754
+ /** Normalized Y coordinate (0 = top, 0.5 = center, 1 = bottom). */
755
+ y: number;
756
+ }
740
757
  /**
741
758
  * Tool that parses origin strings.
742
759
  * Allows static values like `'center'`, or expressions like `'random(...)'` to select one randomly.
760
+ * Also provides `toNormalized()` method to convert origin strings to `{ x, y }` coordinates.
743
761
  */
744
762
  declare class OriginParserTool implements IStringTool<OriginInput, string> {
745
763
  /**
746
764
  * @returns Parsed string value (static or randomly chosen).
747
765
  */
748
766
  process({ value }: OriginInput): string;
767
+ /**
768
+ * Parses an origin string to normalized `{ x, y }` coordinates (0-1 range).
769
+ *
770
+ * Supported formats:
771
+ * - Single keyword: `'center'`, `'top'`, `'left'`, etc.
772
+ * - Two keywords: `'left top'`, `'right bottom'`, `'center center'`
773
+ * - Percentages: `'50% 50%'`, `'0% 100%'`, `'35% 76%'`
774
+ * - Mixed: `'left 25%'`, `'50% top'`
775
+ *
776
+ * @param input - The origin string to parse.
777
+ * @returns Normalized `{ x, y }` coordinates.
778
+ */
779
+ toNormalized({ value }: OriginToNormalizedInput): NormalizedOrigin;
780
+ /**
781
+ * Parses a single value (keyword or percentage) to a normalized number.
782
+ */
783
+ private parseValue;
749
784
  }
750
785
 
751
786
  interface StringColor {
@@ -1464,11 +1499,25 @@ declare class StringCursor extends StringModule {
1464
1499
  }
1465
1500
 
1466
1501
  declare class StringImpulse extends StringModule {
1502
+ private originObservers;
1467
1503
  constructor(context: StringContext);
1468
1504
  onObjectConnected(object: StringObject): void;
1469
1505
  onObjectDisconnected(object: StringObject): void;
1470
1506
  onMouseMove(_e?: MouseEvent): void;
1471
- private getElementsAtPoint;
1507
+ /**
1508
+ * Parses and caches the rotation origin for an object.
1509
+ * Called once on object connection and when attribute changes.
1510
+ */
1511
+ private cacheRotationOrigin;
1512
+ /**
1513
+ * Observes changes to the rotation-origin attribute and re-caches when changed.
1514
+ */
1515
+ private observeRotationOrigin;
1516
+ /**
1517
+ * Calculates the rotation origin point using cached normalized values and provided rect.
1518
+ * Avoids re-parsing origin string and extra getBoundingClientRect calls.
1519
+ */
1520
+ private getRotationOriginFromRect;
1472
1521
  onFrame(_: StringData): void;
1473
1522
  }
1474
1523
 
@@ -1776,16 +1825,22 @@ declare class StringDelayLerpTracker extends StringModule {
1776
1825
 
1777
1826
  /**
1778
1827
  * FPS Tracker Module.
1779
- * Displays how many times `onFrame()` is called per second.
1780
- * Useful for debugging rendering performance or vsync issues.
1828
+ * Broadcasts frame rate to elements with `data-fps` attribute.
1829
+ * Also creates an optional debug display element.
1781
1830
  */
1782
1831
  declare class StringFPSTracker extends StringModule {
1783
1832
  private displayElement;
1784
1833
  private intervalId;
1785
1834
  private frameCount;
1835
+ /** Cached elements with data-fps attribute */
1836
+ private fpsElements;
1837
+ /** MutationObserver for DOM changes */
1838
+ private observer;
1839
+ /** Last known FPS to avoid redundant updates */
1840
+ private lastFps;
1786
1841
  constructor(context: StringContext);
1787
1842
  /**
1788
- * Initializes the visual FPS counter and update interval.
1843
+ * Initializes the visual FPS counter, scans for elements, and starts interval.
1789
1844
  */
1790
1845
  onInit(): void;
1791
1846
  /**
@@ -1793,9 +1848,29 @@ declare class StringFPSTracker extends StringModule {
1793
1848
  */
1794
1849
  onFrame(_data: StringData): void;
1795
1850
  /**
1796
- * Cleans up DOM and interval.
1851
+ * Cleans up DOM, observer, and interval.
1797
1852
  */
1798
1853
  destroy(): void;
1854
+ /**
1855
+ * Handles visibility toggle from external API.
1856
+ */
1857
+ private onVisibilityChange;
1858
+ /**
1859
+ * Removes the display element and its styles.
1860
+ */
1861
+ private removeDisplayElement;
1862
+ /**
1863
+ * Updates all tracked elements with current FPS.
1864
+ */
1865
+ private updateFPS;
1866
+ /**
1867
+ * Scans document for elements with data-fps attribute.
1868
+ */
1869
+ private scanElements;
1870
+ /**
1871
+ * Observes DOM for added/removed elements with data-fps attribute.
1872
+ */
1873
+ private observeDOM;
1799
1874
  /**
1800
1875
  * Creates and styles the floating FPS display.
1801
1876
  */
@@ -1842,24 +1917,55 @@ declare class StringLerpTracker extends StringModule {
1842
1917
  }
1843
1918
 
1844
1919
  /**
1845
- * Tracker module that shows current scroll position and direction.
1846
- * Displays a fixed label in the corner of the screen for debugging.
1920
+ * Tracker module that broadcasts scroll position to elements with data attributes.
1921
+ * Elements with `data-val`, `data-val-pct`, or `data-dir` will receive updates.
1922
+ * Also creates an optional debug display element.
1847
1923
  */
1848
1924
  declare class StringPositionTracker extends StringModule {
1849
1925
  private displayElement;
1926
+ /** Cached elements by attribute type */
1927
+ private valElements;
1928
+ private valPctElements;
1929
+ private dirElements;
1930
+ /** MutationObserver for DOM changes */
1931
+ private observer;
1932
+ /** Last known values to avoid redundant updates */
1933
+ private lastVal;
1934
+ private lastValPct;
1935
+ private lastDir;
1850
1936
  constructor(context: StringContext);
1851
1937
  /**
1852
- * Called on start — creates the DOM element for position display.
1938
+ * Called on start — creates debug element and scans for tracked elements.
1853
1939
  */
1854
1940
  onInit(): void;
1855
1941
  /**
1856
- * Called on scroll — updates scroll position and direction symbol.
1942
+ * Called on scroll — updates all tracked elements with position data.
1857
1943
  */
1858
1944
  onScroll(data: StringData): void;
1859
1945
  /**
1860
- * Removes display element from DOM.
1946
+ * Cleans up DOM observer and display element.
1861
1947
  */
1862
1948
  destroy(): void;
1949
+ /**
1950
+ * Handles visibility toggle from external API.
1951
+ */
1952
+ private onVisibilityChange;
1953
+ /**
1954
+ * Removes the display element.
1955
+ */
1956
+ private removeDisplayElement;
1957
+ /**
1958
+ * Scans document for elements with tracking attributes.
1959
+ */
1960
+ private scanElements;
1961
+ /**
1962
+ * Observes DOM for added/removed elements with tracking attributes.
1963
+ */
1964
+ private observeDOM;
1965
+ /**
1966
+ * Checks if element has any tracking attribute.
1967
+ */
1968
+ private hasTrackingAttr;
1863
1969
  /**
1864
1970
  * Creates and styles the floating position indicator.
1865
1971
  */
@@ -2125,6 +2231,8 @@ declare class StringTune {
2125
2231
  * Can be 'smooth', 'default', or 'disable'.
2126
2232
  */
2127
2233
  set scrollMobileMode(mode: ScrollMode);
2234
+ set FPSTrackerVisible(visible: boolean);
2235
+ set PositionTrackerVisible(visible: boolean);
2128
2236
  private debouncedResize;
2129
2237
  private constructor();
2130
2238
  /**