@fiddle-digital/string-tune 0.0.65 → 1.0.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.ts CHANGED
@@ -1,323 +1,1581 @@
1
- declare class StringObject {
2
- el: HTMLElement;
3
- id: string;
4
- key: string;
5
- keys: string;
6
- connects: Array<HTMLElement>;
7
- private properties;
8
- private modules;
9
- onEnter: () => void;
10
- onLeave: () => void;
11
- setProperty<T>(key: string, value: T): void;
12
- getProperty<T>(key: string): T;
13
- constructor(element: HTMLElement);
14
- enter(): void;
15
- leave(): void;
16
- show(): void;
17
- hide(): void;
18
- connect(module: IStringModule): void;
1
+ /**
2
+ * Represents a map of configurable settings for the StringTune system.
3
+ * Each key corresponds to a setting name (e.g. 'offset-top', 'parallax', etc.).
4
+ *
5
+ * These settings can be used as:
6
+ * - Global fallbacks via `setupSettings`
7
+ * - Module-specific overrides via `use(MyModule, settings)`
8
+ *
9
+ * The values are typically string-based, but can also be numbers or booleans.
10
+ */
11
+ interface StringSettings {
12
+ [key: string]: string | number | boolean;
13
+ }
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
+ /**
24
+ * Subscribes to an event.
25
+ * Optionally appends an `id` to the event name for namespacing.
26
+ *
27
+ * @param eventName The base event name (e.g. "scroll", "update").
28
+ * @param callback The function to call when the event is emitted.
29
+ * @param id Optional unique identifier to scope the event (e.g. element ID).
30
+ */
31
+ on<T = any>(eventName: string, callback: EventCallback<T>, id?: string): void;
32
+ /**
33
+ * Unsubscribes from a specific event listener.
34
+ * Must match the original `eventName`, `callback`, and optional `id`.
35
+ *
36
+ * @param eventName The base event name to unsubscribe from.
37
+ * @param callback The callback function to remove.
38
+ * @param id Optional identifier used when subscribing.
39
+ */
40
+ off<T = any>(eventName: string, callback: EventCallback<T>, id?: string): void;
41
+ /**
42
+ * Emits an event with an optional payload.
43
+ * All matching listeners will be called.
44
+ *
45
+ * @param eventName The full event name (must include `id` if used).
46
+ * @param payload Optional data passed to event listeners.
47
+ */
48
+ emit<T = any>(eventName: string, payload?: T): void;
49
+ /**
50
+ * Subscribes to a per-object progress event.
51
+ * @param id The object ID.
52
+ * @param callback The callback to handle progress value.
53
+ */
54
+ onProgress(id: string, callback: EventCallback<number>): void;
55
+ /**
56
+ * Emits a per-object progress event.
57
+ * @param id The object ID.
58
+ * @param value The progress value.
59
+ */
60
+ emitProgress(id: string, value: number): void;
61
+ /**
62
+ * Subscribes to a per-object in-view event.
63
+ * @param id The object ID.
64
+ * @param callback The callback to handle visibility.
65
+ */
66
+ onInview(id: string, callback: EventCallback<boolean>): void;
67
+ /**
68
+ * Emits a per-object in-view event.
69
+ * @param id The object ID.
70
+ * @param visible Whether the object is visible.
71
+ */
72
+ emitInview(id: string, visible: boolean): void;
73
+ /**
74
+ * Subscribes to the global scroll event.
75
+ * @param callback The callback to handle scroll value.
76
+ */
77
+ onScroll(callback: EventCallback<number>): void;
78
+ /**
79
+ * Emits the global scroll event.
80
+ * @param value The scroll value.
81
+ */
82
+ emitScroll(value: number): void;
83
+ /**
84
+ * Subscribes to the global update event.
85
+ * @param callback The callback to handle update.
86
+ */
87
+ onUpdate(callback: EventCallback<void>): void;
88
+ /**
89
+ * Emits the global update event.
90
+ */
91
+ emitUpdate(): void;
92
+ /**
93
+ * Clears all listeners for a specific event.
94
+ *
95
+ * @param eventName The full event name (including optional `id`).
96
+ */
97
+ clear(eventName: string): void;
98
+ /**
99
+ * Clears all registered events.
100
+ */
101
+ clearAll(): void;
102
+ }
103
+
104
+ /**
105
+ * Reactive cursor data for raw, target, smoothed and step deltas.
106
+ */
107
+ declare class CursorState {
108
+ /**
109
+ * Target X position of the cursor (e.g., from `mousemove`)
110
+ */
111
+ targetX: number;
112
+ /**
113
+ * Target Y position of the cursor.
114
+ */
115
+ targetY: number;
116
+ /**
117
+ * Smoothed X position after applying lerp.
118
+ */
119
+ smoothedX: number;
120
+ /**
121
+ * Smoothed Y position after applying lerp.
122
+ */
123
+ smoothedY: number;
124
+ /**
125
+ * Delta step between current and target X (used internally for lerp).
126
+ */
127
+ stepX: number;
128
+ /**
129
+ * Delta step between current and target Y.
130
+ */
131
+ stepY: number;
19
132
  }
20
133
 
134
+ /**
135
+ * Global Three.js or rendering context reference.
136
+ */
137
+ declare class RenderState {
138
+ /** Instance of Three.js or another render context */
139
+ threeInstance: any;
140
+ }
141
+
142
+ type ScrollDirection = 'vertical' | 'horizontal';
143
+ type ScrollMode = 'smooth' | 'disable' | 'default';
144
+ /**
145
+ * Describes current scroll-related state for all calculations and modules.
146
+ */
147
+ declare class ScrollState {
148
+ /** Target scroll value — where we want to scroll to (used in smooth scroll) */
149
+ target: number;
150
+ /** Current scroll value (actual scroll position) */
151
+ current: number;
152
+ /** Transformed current scroll value (with transform by scroll container) */
153
+ transformedCurrent: number;
154
+ /** Delta between frames (used for animation / velocity) */
155
+ delta: number;
156
+ /** Interpolated scroll value for smooth transitions */
157
+ lerped: number;
158
+ /** Displacement value (similar to lerped, but used for other animations) */
159
+ displacement: number;
160
+ /** Whether scroll direction is downward */
161
+ isScrollingDown: boolean;
162
+ /** Top screen scroll position */
163
+ topPosition: number;
164
+ /** Bottom screen scroll position */
165
+ bottomPosition: number;
166
+ /** Scroll direction (vertical / horizontal) */
167
+ direction: ScrollDirection;
168
+ /** Scroll container element */
169
+ elementContainer: HTMLElement;
170
+ /** Scroll container element */
171
+ scrollContainer: HTMLElement | Window;
172
+ /** Scroll container element */
173
+ container: HTMLElement;
174
+ /**
175
+ * Currently active scroll mode.
176
+ * Can be 'smooth', 'default', or 'disable'.
177
+ */
178
+ mode: ScrollMode;
179
+ /**
180
+ * Scroll mode to use on mobile devices.
181
+ * Can be 'smooth', 'default', or 'disable'.
182
+ */
183
+ modeMobile: ScrollMode;
184
+ /**
185
+ * Scroll mode to use on desktop devices.
186
+ * Can be 'smooth', 'default', or 'disable'.
187
+ */
188
+ modeDesktop: ScrollMode;
189
+ /**
190
+ * Base scroll speed used for calculating smooth scrolling.
191
+ * Typically a small value between 0 and 1.
192
+ */
193
+ speed: number;
194
+ /**
195
+ * Acceleration factor used for scroll easing or velocity-based animations.
196
+ * Also typically a value between 0 and 1.
197
+ */
198
+ speedAccelerate: number;
199
+ }
200
+
201
+ /**
202
+ * Represents the time-related state of the current and previous animation frames.
203
+ *
204
+ * Useful for calculating delta time, total elapsed time, and implementing
205
+ * time-based animations or physics.
206
+ */
207
+ declare class TimeState {
208
+ /**
209
+ * Timestamp of the current animation frame in milliseconds.
210
+ * This value is typically obtained via `performance.now()`.
211
+ */
212
+ now: number;
213
+ /**
214
+ * Timestamp of the previous animation frame in milliseconds.
215
+ */
216
+ previous: number;
217
+ /**
218
+ * Time difference between the current and previous frames in milliseconds.
219
+ * Commonly used to calculate animation progress.
220
+ */
221
+ delta: number;
222
+ /**
223
+ * Total time elapsed since the start of the animation or system in milliseconds.
224
+ */
225
+ elapsed: number;
226
+ }
227
+
228
+ /**
229
+ * Describes current viewport size and scaling.
230
+ */
231
+ declare class ViewportState {
232
+ /** Width of the visible window */
233
+ windowWidth: number;
234
+ /** Height of the visible window */
235
+ windowHeight: number;
236
+ /** Full scroll width (content width inside scroll container) */
237
+ contentWidth: number;
238
+ /** Full scroll height (content height inside scroll container) */
239
+ contentHeight: number;
240
+ /** Screen scale ratio for width (e.g. device pixel ratio or zoom level) */
241
+ scaleWidth: number;
242
+ /** Screen scale ratio for height */
243
+ scaleHeight: number;
244
+ transformScale: number;
245
+ baseRem: number;
246
+ }
247
+
248
+ /**
249
+ * Container for global dynamic state used throughout the string-tune system.
250
+ * Provides access to live scroll, viewport, cursor, and render states,
251
+ * which are updated each frame and shared across modules and tools.
252
+ */
21
253
  declare class StringData {
22
- three: any;
23
- t: number;
24
- c: number;
25
- d: number;
26
- v: number;
27
- dV: number;
28
- sDB: boolean;
29
- bS: number;
30
- cF: number;
31
- wS: number;
32
- hnwS: number;
33
- psW: number;
34
- psH: number;
35
- cL: any;
36
- scsW: number;
37
- scsH: number;
38
- sD: 'vertical' | 'horizontal';
39
- sC: any;
40
- sM: 'smooth' | 'disable' | 'default';
254
+ /**
255
+ * Scroll-related state object.
256
+ * Contains live values like `target`, `current`, `delta`, `direction`, and more.
257
+ * Used for scroll-based animations, transitions, and effects.
258
+ */
259
+ scroll: ScrollState;
260
+ /**
261
+ * Viewport-related state object.
262
+ * Holds dimensions like window size, content size, aspect ratios, and more.
263
+ * Useful for layout calculations, unit parsing, and element positioning.
264
+ */
265
+ viewport: ViewportState;
266
+ /**
267
+ * Cursor-related state object.
268
+ * Tracks cursor position, velocity, movement, and derived values.
269
+ * Can be used for pointer interactions, proximity effects, and hover states.
270
+ */
271
+ cursor: CursorState;
272
+ /**
273
+ * Render-related state object.
274
+ * Stores data related to rendering context (e.g. WebGL, Three.js),
275
+ * such as shared materials, textures, or active render frame data.
276
+ */
277
+ render: RenderState;
278
+ /**
279
+ * Time-related state object.
280
+ * Tracks frame timings, including current timestamp, delta between frames,
281
+ * and total elapsed time since animation start.
282
+ * Useful for time-based animations, easing, frame consistency, and syncing logic.
283
+ */
284
+ time: TimeState;
41
285
  }
42
286
 
43
- interface IStringModule {
44
- destructor(): void;
45
- onStart(): void;
46
- onUpdate(data: StringData): void;
47
- onConnect(object: StringObject): void;
48
- onResize(): void;
49
- onRebuild(): void;
50
- onScroll(data: StringData): void;
51
- onScrollStop(): void;
52
- onScrollStart(): void;
53
- onChangeDirection(): void;
54
- onMouseMove(e: MouseEvent): void;
55
- onWheel(e: WheelEvent): void;
56
- onChangeDevice(): void;
57
- onChangeScrollDirection(): void;
58
- onMutationObserver(added: NodeList, removed: NodeList): void;
59
- onChangeScrollParams(): void;
60
- initObject(globalId: number, object: StringObject, el: HTMLElement, attributes: Record<string, any>): void;
61
- tryConnect(object: StringObject): boolean;
62
- connect(object: StringObject): void;
63
- enterObject(id: string, object: StringObject): void;
64
- leaveObject(id: string): void;
65
- }
66
-
67
- declare class StringVirtualCursor {
68
- private _lF;
69
- private lerp;
70
- private _x;
71
- private _y;
72
- private _lerpX;
73
- private _lerpY;
74
- private targetX;
75
- private targetY;
76
- get x(): number;
77
- get y(): number;
78
- get smoothX(): number;
79
- get smoothY(): number;
80
- get lerpX(): number;
81
- get lerpY(): number;
82
- set mouseLerp(value: number);
83
- constructor(mouseLerp?: number);
84
- onMouseMove(e: MouseEvent): void;
85
- onUpdate(): void;
287
+ /**
288
+ * Base interface for injectable core tools in the String system.
289
+ * Each tool takes input and returns output (transform, extract, calculate).
290
+ */
291
+ interface IStringTool<Input = any, Output = any> {
292
+ /**
293
+ * Process input and return result.
294
+ * Can be a transformation, extraction, interpolation, etc.
295
+ *
296
+ * @param input - Any input relevant to the tool.
297
+ * @returns Output result from the tool.
298
+ */
299
+ process(input: Input): Output;
86
300
  }
87
301
 
88
- declare class StringFPS {
89
- private isAnimationStarted;
90
- private fpsInterval;
91
- private then;
92
- private requestAnimationId;
93
- private onFrameCallback;
94
- private animate;
95
- start(fps: number): void;
96
- stop(): void;
97
- setOnFrame(callback: () => void): void;
302
+ /**
303
+ * Input for `BoundingClientRectTool`.
304
+ */
305
+ interface BoundingClientRectInput {
306
+ /** The DOM element to retrieve bounding rect from. */
307
+ element: HTMLElement;
308
+ }
309
+ /**
310
+ * Tool for accessing `getBoundingClientRect()` in a consistent, testable way.
311
+ */
312
+ declare class BoundingClientRectTool implements IStringTool<BoundingClientRectInput, DOMRect> {
313
+ /**
314
+ * @returns The bounding client rect of the provided element.
315
+ */
316
+ process({ element }: BoundingClientRectInput): DOMRect;
98
317
  }
99
318
 
100
- declare class StringAttribute {
101
- process(e: any, n: string, d?: any): any;
319
+ interface DOMAttributeInput {
320
+ element: HTMLElement;
321
+ key: string;
322
+ fallback?: string | null;
323
+ }
324
+ declare class DOMAttributeTool implements IStringTool<DOMAttributeInput, string | null> {
325
+ /**
326
+ * Retrieves the value of either `string-${key}` or `data-string-${key}` attribute.
327
+ *
328
+ * @example key = "offset-tom" → tries:
329
+ * - element.getAttribute("string-offset-tom")
330
+ * - element.getAttribute("data-string-offset-tom")
331
+ */
332
+ process({ element, key, fallback }: DOMAttributeInput): string | null;
102
333
  }
103
334
 
104
- declare class StringBoundingClientRect {
105
- process(e: any): any;
335
+ /**
336
+ * Input for retrieving a value from a key-value object or dataset-like structure.
337
+ */
338
+ interface RecordAttributeInput {
339
+ /** Source object to read from (e.g. dataset or plain record). */
340
+ record: Record<string, any>;
341
+ /** Key to look up (without `"data-"` prefix). */
342
+ name: string;
343
+ /** Fallback value if both keys are missing. */
344
+ fallback?: any;
345
+ }
346
+ /**
347
+ * Retrieves a value from an object or dataset-like structure.
348
+ * Tries `record[name]` first, then `record["data-" + name]`, or returns fallback.
349
+ */
350
+ declare class RecordAttributeTool implements IStringTool<RecordAttributeInput, any> {
351
+ /**
352
+ * @returns Value from the record or fallback.
353
+ */
354
+ process({ record, name, fallback }: RecordAttributeInput): any;
106
355
  }
107
356
 
108
- declare class StringDefaultSettings {
109
- stringOffsetStart: string;
110
- stringOffsetEnd: string;
111
- stringEnterEl: string;
112
- stringExitEl: string;
113
- stringEnterVp: string;
114
- stringExitVp: string;
115
- stringInviewTop: string;
116
- stringInviewBottom: string;
117
- stringKey: string;
118
- stringStrength: number;
119
- stringRadius: number;
120
- stringLerp: number;
121
- stringParallaxBias: number;
122
- stringParallax: number;
357
+ /**
358
+ * Input for removing transform effects from an element's bounding box.
359
+ */
360
+ interface TransformNullifyInput {
361
+ /** The DOM element whose CSS transform should be nullified. */
362
+ element: HTMLElement;
363
+ }
364
+ /**
365
+ * Output with corrected bounding box values.
366
+ */
367
+ interface TransformNullifyOutput {
368
+ /** Top position without transform effects. */
369
+ top: number;
370
+ /** Left position without transform effects. */
371
+ left: number;
372
+ /** Width without transform scaling. */
373
+ width: number;
374
+ /** Height without transform scaling. */
375
+ height: number;
376
+ }
377
+ /**
378
+ * Computes the true bounding box of a DOM element,
379
+ * nullifying CSS `transform: matrix(...)` effects.
380
+ */
381
+ declare class TransformNullifyTool implements IStringTool<TransformNullifyInput, TransformNullifyOutput> {
382
+ /**
383
+ * @returns Element position and size without transform influence.
384
+ */
385
+ process({ element }: TransformNullifyInput): TransformNullifyOutput;
123
386
  }
124
387
 
125
- declare class StringEvent {
126
- private eventsByKey;
127
- private events;
128
- on(id: string, event: Function): void;
129
- has(id: string): boolean;
130
- emit(id: string, value: any): void;
131
- off(id: string, event: Function): void;
132
- all(value: any): void;
133
- private updateAllEvents;
388
+ /**
389
+ * Input for calculating the position of an element relative to a container.
390
+ */
391
+ interface RelativePositionInput {
392
+ /** The DOM element whose position should be calculated. */
393
+ element: HTMLElement;
394
+ /** Optional container to measure against. Defaults to `document.body`. */
395
+ container?: HTMLElement;
396
+ }
397
+ /**
398
+ * Output: relative position in pixels.
399
+ */
400
+ interface RelativePositionOutput {
401
+ /** Distance from the top of the container. */
402
+ top: number;
403
+ /** Distance from the left of the container. */
404
+ left: number;
405
+ }
406
+ /**
407
+ * Calculates an element's position relative to a container.
408
+ * Uses `TransformNullifyTool` to account for CSS transforms.
409
+ */
410
+ declare class RelativePositionTool implements IStringTool<RelativePositionInput, RelativePositionOutput> {
411
+ /** Optional tool for CSS transform-neutral measurements. */
412
+ private transformTool;
413
+ constructor(
414
+ /** Optional tool for CSS transform-neutral measurements. */
415
+ transformTool?: TransformNullifyTool);
416
+ /**
417
+ * @returns Relative top/left position of element within container.
418
+ */
419
+ process({ element, container }: RelativePositionInput): RelativePositionOutput;
420
+ }
421
+
422
+ interface LerpInput {
423
+ /** Starting value of the interpolation. */
424
+ from: number;
425
+ /** Target value to interpolate towards. */
426
+ to: number;
427
+ /** Interpolation progress between 0 (start) and 1 (end). */
428
+ progress: number;
429
+ }
430
+ declare class LerpTool implements IStringTool<LerpInput, number> {
431
+ /**
432
+ * Calculates the linear interpolation between two values.
433
+ * @returns Interpolated value.
434
+ */
435
+ process({ from, to, progress }: LerpInput): number;
134
436
  }
135
437
 
136
- declare class StringLerpCalc {
137
- process(current: number, target: number, amt: number): number;
438
+ /**
439
+ * Input for parsing unit-based strings into numeric pixel values.
440
+ */
441
+ interface UnitParserInput {
442
+ /** Unit string, e.g. `"20px"`, `"50%"`, `"1.5rem"`, or `"selfHeight"` */
443
+ value: string;
444
+ /** DOM element used for `"selfHeight"` calculation */
445
+ element: HTMLElement;
446
+ /** Viewport height in pixels (for percentage conversion) */
447
+ viewportHeight: number;
448
+ /** Root font size in pixels (for rem conversion) */
449
+ baseRem: number;
450
+ }
451
+ /**
452
+ * Converts unit-based strings to numeric pixel values.
453
+ * Supports `px`, `%`, `rem`, and `"selfHeight"` keyword. Handles negatives.
454
+ */
455
+ declare class UnitParserTool implements IStringTool<UnitParserInput, number> {
456
+ /**
457
+ * @returns Numeric value in pixels (positive or negative).
458
+ */
459
+ process({ value, element, viewportHeight, baseRem }: UnitParserInput): number;
460
+ }
461
+
462
+ /**
463
+ * Input for adaptive lerp factor calculation.
464
+ * Maps a speed-like value to a lerp factor, where:
465
+ * - lower speed ⇒ slower smoothing (higher lerp factor)
466
+ * - higher speed ⇒ faster response (lower lerp factor)
467
+ */
468
+ interface AdaptiveLerpInput {
469
+ /** Current value (e.g., speed or delta). */
470
+ value: number;
471
+ /** Minimum input threshold (default: 0.1) */
472
+ inMin?: number;
473
+ /** Maximum input threshold (default: 1.0) */
474
+ inMax?: number;
475
+ /** Output when input is at minimum (default: 0.65) */
476
+ outMax?: number;
477
+ /** Output when input is at maximum (default: 0.05) */
478
+ outMin?: number;
479
+ }
480
+ /**
481
+ * Converts a numeric input (like velocity) into an adaptive lerp factor.
482
+ * Useful for scroll or speed-based smoothing effects.
483
+ */
484
+ declare class AdaptiveLerpTool implements IStringTool<AdaptiveLerpInput, number> {
485
+ /**
486
+ * @returns A remapped lerp factor from `outMax` to `outMin`.
487
+ */
488
+ process({ value, inMin, inMax, outMin, outMax }: AdaptiveLerpInput): number;
138
489
  }
139
490
 
140
- declare class StringParser {
141
- parseSingle(v: string, element: any, wH: any, baseRem: number): number;
491
+ /**
492
+ * Input for origin parser.
493
+ * Supports static values or `random(...)` expressions.
494
+ */
495
+ interface OriginInput {
496
+ /** Raw origin string, e.g. `'center'` or `'random(top, bottom)'`. */
497
+ value: string;
498
+ }
499
+ /**
500
+ * Tool that parses origin strings.
501
+ * Allows static values like `'center'`, or expressions like `'random(...)'` to select one randomly.
502
+ */
503
+ declare class OriginParserTool implements IStringTool<OriginInput, string> {
504
+ /**
505
+ * @returns Parsed string value (static or randomly chosen).
506
+ */
507
+ process({ value }: OriginInput): string;
508
+ }
509
+
510
+ interface StringColor {
511
+ r: number;
512
+ g: number;
513
+ b: number;
514
+ a: number;
515
+ }
516
+
517
+ /**
518
+ * Input for parsing color strings into RGBA format.
519
+ */
520
+ interface ColorParserInput {
521
+ /** Color string in hex, rgb[a], or hsl[a] format. */
522
+ value: string;
523
+ }
524
+ /**
525
+ * Parses a CSS color string (`#fff`, `rgb(...)`, `hsl(...)`, etc.)
526
+ * into an object with `r`, `g`, `b`, `a` values.
527
+ */
528
+ declare class ColorParserTool implements IStringTool<ColorParserInput, StringColor> {
529
+ /**
530
+ * @returns RGBA object parsed from color string.
531
+ */
532
+ process({ value }: ColorParserInput): StringColor;
533
+ private hslToRgb;
534
+ }
535
+
536
+ type ValidationErrorCode = "required" | "invalid-email" | "too-short" | "too-long";
537
+ type ValidationRule = "required" | "email" | {
538
+ type: "minLength";
539
+ value: number;
540
+ } | {
541
+ type: "maxLength";
542
+ value: number;
543
+ };
544
+ interface ValidationInput {
545
+ /** Value to validate. */
546
+ value: string;
547
+ /** List of rules to apply. */
548
+ rules: ValidationRule[];
549
+ /**
550
+ * Optional message map: key = errorCode, value = string or function returning a message.
551
+ */
552
+ messages?: Partial<Record<ValidationErrorCode, string | ((args: {
553
+ value: string;
554
+ rule: ValidationRule;
555
+ }) => string)>>;
556
+ }
557
+ interface ValidationOutput {
558
+ /** `true` if valid, `false` if error found. */
559
+ valid: boolean;
560
+ /** One of the known error codes (or null if no error). */
561
+ error: ValidationErrorCode | null;
562
+ /** Final message (either default or user-defined). */
563
+ message: string | null;
564
+ }
565
+ /**
566
+ * Tool for validating strings using rules like `required`, `minLength`, etc.
567
+ * Allows custom error messages (as string or generator function).
568
+ */
569
+ declare class ValidationTool implements IStringTool<ValidationInput, ValidationOutput> {
570
+ /**
571
+ * Validates input value and returns error code + message.
572
+ */
573
+ process({ value, rules, messages }: ValidationInput): ValidationOutput;
574
+ private defaultMessage;
575
+ }
576
+
577
+ /**
578
+ * Input parameters for EasingFunctionTool.
579
+ */
580
+ interface EasingFunctionInput {
581
+ /**
582
+ * The easing string.
583
+ * Can be: 'linear', 'ease', 'ease-in', 'ease-out', 'ease-in-out', or 'cubic-bezier(...)'
584
+ */
585
+ easing: string;
586
+ }
587
+ /**
588
+ * Output of the easing function: receives t in [0,1] and returns eased value.
589
+ */
590
+ type EasingFunctionOutput = (t: number) => number;
591
+ /**
592
+ * Tool for parsing easing strings into easing functions.
593
+ * Supports standard keywords (`ease-in`, `ease-out`, etc.) and `cubic-bezier(...)` expressions.
594
+ */
595
+ declare class EasingFunctionTool implements IStringTool<EasingFunctionInput, EasingFunctionOutput> {
596
+ private namedCurves;
597
+ /**
598
+ * Parses an easing string and returns a corresponding easing function.
599
+ */
600
+ process({ easing }: EasingFunctionInput): EasingFunctionOutput;
601
+ /**
602
+ * Generates a cubic-bezier easing function.
603
+ * Ported from https://github.com/gre/bezier-easing (MIT)
604
+ */
605
+ private cubicBezier;
606
+ }
607
+
608
+ /**
609
+ * Input parameters for calculating magnetic pull factor.
610
+ */
611
+ interface MagneticPullInput {
612
+ /** Distance between pointer and element center (px). */
613
+ distance: number;
614
+ /** Max distance within which magnetic pull is active. */
615
+ radius: number;
616
+ /** Strength of the magnetic pull (0–1 recommended). */
617
+ strength: number;
618
+ }
619
+ /**
620
+ * Output: factor to multiply by direction vector (dx/dy) to get magnetic offset.
621
+ */
622
+ type MagneticPullOutput = number;
623
+ /**
624
+ * Tool for calculating magnetic attraction based on distance to element.
625
+ * Returns a scalar value (0..strength) depending on proximity.
626
+ */
627
+ declare class MagneticPullTool implements IStringTool<MagneticPullInput, MagneticPullOutput> {
628
+ /**
629
+ * Returns a pull factor based on distance to target within a radius.
630
+ * @param input - Magnetic pull parameters.
631
+ * @returns A multiplier (typically < 1) to apply to dx/dy.
632
+ */
633
+ process({ distance, radius, strength }: MagneticPullInput): number;
142
634
  }
143
635
 
144
- declare class StringPosition {
145
- process(e: any, container?: any): {
146
- top: number;
147
- left: number;
636
+ /**
637
+ * Input parameters for `LerpColorTool`.
638
+ */
639
+ interface LerpColorInput {
640
+ /**
641
+ * Starting color as an object `{ r, g, b, a }` where each value is in the range `0–1`.
642
+ */
643
+ from: StringColor;
644
+ /**
645
+ * Target color as an object `{ r, g, b, a }` where each value is in the range `0–1`.
646
+ */
647
+ to: StringColor;
648
+ /**
649
+ * Interpolation progress from `0` (start) to `1` (end).
650
+ */
651
+ progress: number;
652
+ }
653
+ /**
654
+ * Tool for linearly interpolating between two RGBA colors using `StringColor` format.
655
+ * Each channel (`r`, `g`, `b`, `a`) is interpolated independently.
656
+ * Returns a new `StringColor` with the interpolated values.
657
+ */
658
+ declare class LerpColorTool implements IStringTool<LerpColorInput, StringColor> {
659
+ /**
660
+ * Performs linear interpolation between two `StringColor` values.
661
+ *
662
+ * @param input.from - The starting color `{ r, g, b, a }`.
663
+ * @param input.to - The target color `{ r, g, b, a }`.
664
+ * @param input.progress - A number from `0` to `1` indicating interpolation progress.
665
+ * @returns Interpolated color as a new `StringColor`.
666
+ */
667
+ process({ from, to, progress }: LerpColorInput): StringColor;
668
+ }
669
+
670
+ interface StringVector {
671
+ x: number;
672
+ y: number;
673
+ }
674
+
675
+ /**
676
+ * Input parameters for LerpVector2Tool.
677
+ */
678
+ interface LerpVector2Input {
679
+ /**
680
+ * Starting vector value `{ x, y }`.
681
+ */
682
+ from: StringVector;
683
+ /**
684
+ * Target vector value `{ x, y }`.
685
+ */
686
+ to: StringVector;
687
+ /**
688
+ * Interpolation progress from `0` (start) to `1` (end).
689
+ */
690
+ progress: number;
691
+ }
692
+ /**
693
+ * Tool for linearly interpolating between two 2D vectors.
694
+ * Useful for cursor smoothing, UI element animations, and motion blending.
695
+ */
696
+ declare class LerpVector2Tool implements IStringTool<LerpVector2Input, StringVector> {
697
+ /**
698
+ * Calculates the interpolated vector between `from` and `to`.
699
+ *
700
+ * @param input.from - The starting vector `{ x, y }`.
701
+ * @param input.to - The target vector `{ x, y }`.
702
+ * @param input.progress - Interpolation progress from `0` (start) to `1` (end).
703
+ * @returns Interpolated vector `{ x, y }`.
704
+ */
705
+ process({ from, to, progress }: LerpVector2Input): {
706
+ x: number;
707
+ y: number;
148
708
  };
149
709
  }
150
710
 
151
- declare class StringModule implements IStringModule {
152
- lerp: StringLerpCalc;
153
- attribute: StringAttribute;
154
- boundingClientRect: StringBoundingClientRect;
155
- position: StringPosition;
156
- events: StringEvent;
157
- data: StringData;
158
- virtualCursor: StringVirtualCursor;
159
- loop: StringFPS;
160
- settings: any;
161
- parser: StringParser;
162
- protected defaultSettings: StringDefaultSettings;
163
- protected objectsMap: Map<string, StringObject>;
164
- protected objects: Array<StringObject>;
165
- protected htmlKey: string;
166
- protected _type: number;
167
- get type(): number;
168
- constructor(visitor: any, settings?: any);
169
- initObject(globalId: number, object: StringObject, el: HTMLElement, attributes: Record<string, any>): void;
170
- onScrollStart(): void;
171
- onScrollStop(): void;
172
- onChangeDirection(): void;
173
- destructor(): void;
174
- onChangeScrollParams(): void;
175
- tryConnect(object: StringObject): boolean;
176
- connect(object: StringObject): void;
177
- enterObject(id: string, object: StringObject): void;
178
- leaveObject(id: string): void;
179
- onStart(): void;
180
- onUpdate(data: StringData): void;
181
- onResize(): void;
182
- onConnect(object: StringObject): void;
183
- onRebuild(): void;
184
- onScroll(data: StringData): void;
185
- onMouseMove(e: MouseEvent): void;
186
- onWheel(e: WheelEvent): void;
187
- onChangeDevice(): void;
188
- onChangeScrollDirection(): void;
189
- onMutationObserver(added: NodeList, removed: NodeList): void;
711
+ /**
712
+ * Input for parsing the transform string to extract scale.
713
+ */
714
+ interface TransformParserInput {
715
+ /** CSS transform string (e.g., "matrix(0.5, 0, 0, 0.5, 10, 20)", "scale(0.5)", "none"). */
716
+ value: string;
717
+ }
718
+ /**
719
+ * Parses a CSS transform string to extract the primary scale factor.
720
+ * Assumes uniform scale or extracts the X-axis scale factor from matrix/scale functions.
721
+ */
722
+ declare class TransformScaleParserTool implements IStringTool<TransformParserInput, number> {
723
+ /**
724
+ * Processes the transform string and extracts the scale factor.
725
+ * @returns Numeric scale factor (defaults to 1 if no scale transform is found or parsing fails).
726
+ */
727
+ process({ value }: TransformParserInput): number;
190
728
  }
191
729
 
192
- declare class StringBase extends StringModule {
193
- private oldLerp;
194
- constructor(visitor: any, settings?: any);
195
- initObject(globalId: number, object: StringObject, el: HTMLElement, attributes: Record<string, any>): void;
730
+ /**
731
+ * Represents a single parsed option item definition
732
+ * (e.g., the result of parsing '[center]' or '[random(0,10)|abs]').
733
+ */
734
+ interface ISplitOptionItem {
735
+ /** The alignment type ('start', 'center', 'end', 'random'). */
736
+ align: string;
737
+ /** Optional parameters for random alignment. */
738
+ random?: {
739
+ min: number;
740
+ max: number;
741
+ };
742
+ /** Flag indicating if the absolute value should be used. */
743
+ abs?: boolean;
196
744
  }
197
745
 
198
- declare class StringLazy extends StringBase {
199
- private isStartLoaded;
200
- private imageLoadingCount;
201
- constructor(visitor: any);
202
- onStart(): void;
203
- onConnect(object: StringObject): void;
204
- private load;
205
- private getImageSize;
746
+ /**
747
+ * Represents the fully parsed options from the string-split attribute.
748
+ * Holds arrays of option definitions for each split type.
749
+ */
750
+ interface ISplitOptions {
751
+ line?: ISplitOptionItem[];
752
+ word?: ISplitOptionItem[];
753
+ char?: ISplitOptionItem[];
754
+ charLine?: ISplitOptionItem[];
755
+ charWord?: ISplitOptionItem[];
756
+ wordLine?: ISplitOptionItem[];
206
757
  }
207
758
 
208
- declare class StringLoading extends StringModule {
209
- loadingTimeout: number;
210
- constructor(visitor: any, settings?: any);
211
- onStart(): void;
759
+ /**
760
+ * Represents a single word identified during layout calculation.
761
+ */
762
+ interface LayoutWord {
763
+ /** The text content of the word. */
764
+ text: string;
212
765
  }
213
766
 
214
- declare class StringVideoAutoplay extends StringModule {
215
- private static isInternetSpeedCheckStarted;
216
- private static internetSpeed;
217
- private static intervalId;
218
- constructor(visitor: any);
219
- initObject(globalId: number, object: StringObject, el: HTMLElement, attributes: Record<string, any>): void;
220
- onStart(): void;
221
- onConnect(object: StringObject): Promise<void>;
222
- private selectQuality;
223
- private getQualityLevel;
224
- private testInternetSpeed;
225
- private startGlobalSpeedCheck;
226
- private tryPlay;
767
+ /**
768
+ * Represents a line of text as determined by layout calculations.
769
+ */
770
+ interface LayoutLine {
771
+ /** The full text content of the line as a single string. */
772
+ text: string;
773
+ /** An array of word objects that make up this line. */
774
+ words: LayoutWord[];
775
+ }
776
+
777
+ /**
778
+ * Holds the final calculated numerical value resulting from applying
779
+ * a specific ISplitOptionItem rule to a word or character, along with
780
+ * context about the rule itself (type, alignment).
781
+ * This is used by the SplitDomBuilderTool to set CSS variables.
782
+ */
783
+ interface CalculatedValue {
784
+ /**
785
+ * The final numerical result after applying the alignment ('start', 'center', 'end', 'random')
786
+ * and absolute value ('abs') logic based on the specific option rule.
787
+ * This is the value that will be set for the CSS variable.
788
+ */
789
+ value: number;
790
+ /**
791
+ * Indicates which type of split option definition this value originated from.
792
+ * Crucial for generating the correct CSS variable name prefix (e.g., '--word-', '--charLine-').
793
+ */
794
+ type: 'line' | 'word' | 'char' | 'wordLine' | 'charLine' | 'charWord';
795
+ /**
796
+ * Stores the specific alignment ('start', 'center', 'end', 'random')
797
+ * defined in the option rule that produced this value.
798
+ * Used for generating the CSS variable name suffix (e.g., '-center', '-end').
799
+ */
800
+ align: string;
801
+ }
802
+
803
+ /**
804
+ * Represents a processed word, containing its text, contextual indices
805
+ * (global, line, word-in-line), and an array of calculated values
806
+ * based on the applicable 'word' and 'wordLine' options.
807
+ */
808
+ interface ProcessedWord {
809
+ /** The text content of the word. */
810
+ text: string;
811
+ /** The zero-based index of the word across all words in all lines. */
812
+ globalIndex: number;
813
+ /** The zero-based index of the line this word belongs to. */
814
+ lineIndex: number;
815
+ /** The zero-based index of this word within its line. */
816
+ wordIndexInLine: number;
817
+ /** An array of calculated values based on ISplitOptions ('word', 'wordLine'). */
818
+ calculatedValues: CalculatedValue[];
819
+ }
820
+
821
+ /**
822
+ * Input for the CharIndexerTool.
823
+ */
824
+ interface CharIndexerInput {
825
+ /** The array of processed words from WordIndexerTool. */
826
+ processedWords: ProcessedWord[];
827
+ /** The array of layout lines (needed to calculate total line characters). */
828
+ lines: LayoutLine[];
829
+ /** The parsed split options relevant for characters ('char', 'charLine', 'charWord'). */
830
+ options: Pick<ISplitOptions, 'char' | 'charLine' | 'charWord'>;
831
+ /** The total number of non-whitespace characters in the original text. */
832
+ totalChars: number;
833
+ }
834
+
835
+ /**
836
+ * Represents a processed character, containing its text, contextual indices
837
+ * (global, line, word, plus parent info), and an array of calculated values
838
+ * based on the applicable 'char', 'charLine', and 'charWord' options.
839
+ */
840
+ interface ProcessedChar {
841
+ /** The character itself. */
842
+ text: string;
843
+ /** The zero-based index of the character across all non-whitespace characters. */
844
+ globalCharIndex: number;
845
+ /** The zero-based index of the character within its line (excluding spaces between words). */
846
+ lineCharIndex: number;
847
+ /** The zero-based index of the character within its word. */
848
+ wordCharIndex: number;
849
+ /** Index of the parent word across all words. */
850
+ parentGlobalWordIndex: number;
851
+ /** Index of the line this character belongs to. */
852
+ parentLineIndex: number;
853
+ /** Index of the parent word within its line. */
854
+ parentWordIndexInLine: number;
855
+ /** An array of calculated index values based on ISplitOptions ('char', 'charLine', 'charWord'). */
856
+ calculatedValues: CalculatedValue[];
227
857
  }
228
858
 
229
- declare class StringProgress extends StringBase {
230
- constructor(visitor: any);
231
- initObject(globalId: number, object: StringObject, el: HTMLElement, attributes: Record<string, any>): void;
859
+ /**
860
+ * Tool to process words split by layout, breaking them into characters
861
+ * and assigning relevant indices (global, line, word) for each character.
862
+ * Calculates index values based on ISplitOptions for characters ('char', 'charLine', 'charWord').
863
+ * Produces an array of ProcessedChar objects.
864
+ */
865
+ declare class CharIndexerTool implements IStringTool<CharIndexerInput, ProcessedChar[]> {
866
+ /**
867
+ * Iterates through processed words, splits them into characters, assigns
868
+ * global, line, and word character indices, and calculates index values
869
+ * based on the provided character options ('char', 'charLine', 'charWord').
870
+ *
871
+ * @param input.processedWords - Array of ProcessedWord objects from WordIndexerTool.
872
+ * @param input.lines - Array of LayoutLine objects (needed for calculating total characters per line).
873
+ * @param input.options - The relevant ISplitOptions ('char', 'charLine', 'charWord').
874
+ * @param input.totalChars - Total number of non-whitespace characters in the original text.
875
+ * @returns An array of ProcessedChar objects, ready for DOM building/styling.
876
+ */
877
+ process({ processedWords, lines, options, totalChars }: CharIndexerInput): ProcessedChar[];
878
+ /**
879
+ * Calculates the final numerical index value based on alignment options, context indices, and parent length.
880
+ * (Identical helper function as in WordIndexerTool - could be extracted to a common utility).
881
+ *
882
+ * @param option - The specific option item definition ({ align, random, abs }).
883
+ * @param primaryIndex - The main index used for calculation (global, line, or word char index).
884
+ * @param localIndex - The secondary index (e.g., index within word).
885
+ * @param parentLength - The total count in the relevant context (total chars, line chars, or word chars).
886
+ * @returns The calculated numerical index value.
887
+ */
888
+ private calculateIndex;
889
+ }
890
+
891
+ /**
892
+ * Input interface for the LayoutLineSplitterTool.
893
+ * Requires both the text and the element it will be rendered within.
894
+ */
895
+ interface LayoutSplitInput {
896
+ /** The raw text content to be split into lines based on layout. */
897
+ text: string;
898
+ /** The HTML element whose width and styles determine line breaks. */
899
+ targetElement: HTMLElement;
900
+ }
901
+
902
+ /**
903
+ * Tool to split a text string into structured lines and words based on how
904
+ * the text would visually wrap within a given target HTML element.
905
+ * This simulates browser rendering by measuring word widths.
906
+ * Returns an array of LayoutLine objects.
907
+ */
908
+ declare class LayoutLineSplitterTool implements IStringTool<LayoutSplitInput, LayoutLine[]> {
909
+ /**
910
+ * Processes the input text and splits it into lines containing words,
911
+ * simulating word wrapping within the boundaries of the targetElement.
912
+ *
913
+ * @param input.text - The text content to split.
914
+ * @param input.targetElement - The HTMLElement used as a reference for width and font styles.
915
+ * @returns An array of LayoutLine objects, each containing the line's text and an array of its words.
916
+ * Returns an empty array on error or invalid input.
917
+ */
918
+ process({ text, targetElement }: LayoutSplitInput): LayoutLine[];
919
+ /**
920
+ * Measures the width of a given text string using the provided temporary span.
921
+ * @param text - The text to measure.
922
+ * @param tempSpan - The pre-styled temporary span element used for measurement.
923
+ * @returns The width of the text in pixels.
924
+ */
925
+ private measureWidth;
926
+ /**
927
+ * Decodes basic HTML entities (currently just &amp;).
928
+ * Can be expanded if more entities need handling.
929
+ * @param str - The string potentially containing HTML entities.
930
+ * @returns The string with '&amp;' decoded to '&'.
931
+ */
932
+ private decodeHtmlEntity;
933
+ }
934
+
935
+ /**
936
+ * Defines the input structure required by the SplitDomBuilderTool.
937
+ */
938
+ interface DomBuilderInput {
939
+ /** Array of lines determined by layout. */
940
+ lines: LayoutLine[];
941
+ /** Array of words with calculated indices and values. */
942
+ words: ProcessedWord[];
943
+ /** Array of characters with calculated indices and values. */
944
+ chars: ProcessedChar[];
945
+ /** The original parsed split options. */
946
+ options: ISplitOptions;
947
+ }
948
+
949
+ /**
950
+ * Tool to build the final innerHTML string with nested spans (-s-line, -s-word, -s-char)
951
+ * and apply calculated CSS variables based on processed data from indexer tools.
952
+ * Implements the IStringTool interface.
953
+ */
954
+ declare class SplitDomBuilderTool implements IStringTool<DomBuilderInput, string> {
955
+ /**
956
+ * Generates the innerHTML string for the split text by creating nested spans
957
+ * (-s-line, -s-word, -s-char) and applying styles based on calculated index values.
958
+ *
959
+ * @param input An object containing layout lines, processed words, processed characters, and the original split options.
960
+ * @returns The generated HTML string representing the split content.
961
+ */
962
+ process({ lines, words, chars, options }: DomBuilderInput): string;
963
+ /**
964
+ * Checks if any line-level splitting options (line, wordLine, charLine) are present.
965
+ * This determines if `-s-line` container spans are required in the output HTML.
966
+ * @param options - The ISplitOptions object parsed from the element's attribute.
967
+ * @returns True if any line-level options exist and have definitions, false otherwise.
968
+ */
969
+ private hasLineOptions;
970
+ /**
971
+ * Checks if any character-level splitting options (char, charLine, charWord) are present.
972
+ * This determines if individual `-s-char` spans should be generated inside word spans.
973
+ * @param options - The ISplitOptions object parsed from the element's attribute.
974
+ * @returns True if any character-level options exist and have definitions, false otherwise.
975
+ */
976
+ private hasCharOptions;
977
+ /**
978
+ * Applies the pre-calculated index values as CSS custom properties (variables)
979
+ * to the provided HTML element's style attribute.
980
+ * @param span - The HTMLElement (line, word, or char span) to apply styles to.
981
+ * @param calculatedValues - An array of calculated values derived from the ISplitOptions
982
+ * by the corresponding indexer tool (WordIndexerTool or CharIndexerTool).
983
+ */
984
+ private applyStyles;
985
+ /**
986
+ * Generates a CSS custom property name (variable name) based on the split type and alignment option.
987
+ * Example: type='word', align='center' -> '--word-center'.
988
+ * (Current simplified version assumes one variable per type/align combination).
989
+ * @param type - The type of split element ('line', 'word', 'char', 'wordLine', 'charLine', 'charWord').
990
+ * @param align - The alignment option ('start', 'center', 'end', 'random').
991
+ * @returns The generated CSS variable name string.
992
+ */
993
+ private generateVariableName;
994
+ }
995
+
996
+ /**
997
+ * Input for the WordIndexerTool.
998
+ */
999
+ interface WordIndexerInput {
1000
+ /** The array of layout lines produced by LayoutLineSplitterTool. */
1001
+ lines: LayoutLine[];
1002
+ /** The parsed split options relevant for words ('word', 'wordLine'). */
1003
+ options: Pick<ISplitOptions, 'word' | 'wordLine'>;
1004
+ }
1005
+
1006
+ /**
1007
+ * Tool to process layout lines and words, assigning relevant indices
1008
+ * and calculating index values based on ISplitOptions ('word', 'wordLine').
1009
+ * Produces an array of ProcessedWord objects.
1010
+ */
1011
+ declare class WordIndexerTool implements IStringTool<WordIndexerInput, ProcessedWord[]> {
1012
+ /**
1013
+ * Iterates through lines and words, assigning global and local indices,
1014
+ * and calculating index values based on the provided options ('word', 'wordLine').
1015
+ *
1016
+ * @param input.lines - Array of LayoutLine objects from LayoutLineSplitterTool.
1017
+ * @param input.options - The relevant ISplitOptions ('word', 'wordLine').
1018
+ * @returns An array of ProcessedWord objects, each containing word text, indices,
1019
+ * and an array of calculated values based on options.
1020
+ */
1021
+ process({ lines, options }: WordIndexerInput): ProcessedWord[];
1022
+ /**
1023
+ * Calculates the final numerical index value based on alignment options, context indices, and parent length.
1024
+ * This logic determines the value eventually set as a CSS variable.
1025
+ *
1026
+ * @param option - The specific option item definition ({ align, random, abs }).
1027
+ * @param primaryIndex - The main index used for calculation (global index for 'word', index within line for 'wordLine').
1028
+ * @param localIndex - The secondary index (e.g., index within the line), potentially useful for some alignment logic.
1029
+ * @param parentLength - The total count in the relevant context (total words for 'word', words in the current line for 'wordLine').
1030
+ * @returns The calculated numerical index value.
1031
+ */
1032
+ private calculateIndex;
1033
+ }
1034
+
1035
+ /**
1036
+ * Input interface for the SplitOptionsParserTool.
1037
+ */
1038
+ interface SplitOptionsParserInput {
1039
+ /**
1040
+ * The raw string value from the 'string-split' attribute (or similar).
1041
+ * Can be null if the attribute is not present.
1042
+ */
1043
+ attributeValue: string | null;
1044
+ }
1045
+
1046
+ /**
1047
+ * Tool responsible for parsing the string value of a split attribute
1048
+ * (e.g., "line[center]|char[random(0,10)|abs]") into a structured
1049
+ * ISplitOptions object.
1050
+ * Implements the IStringTool interface.
1051
+ */
1052
+ declare class SplitOptionsParserTool implements IStringTool<SplitOptionsParserInput, ISplitOptions> {
1053
+ /**
1054
+ * Parses the attribute string into an ISplitOptions object.
1055
+ * Handles splitting by '|', parsing prefixes (word-, char-), main types (line, word, char),
1056
+ * and parameters within brackets (align, random, abs).
1057
+ *
1058
+ * @param input - An object containing the attributeValue string (can be null).
1059
+ * @returns An ISplitOptions object representing the parsed rules.
1060
+ * Returns an object with empty arrays if the attributeValue is null or empty.
1061
+ */
1062
+ process({ attributeValue }: SplitOptionsParserInput): ISplitOptions;
1063
+ /**
1064
+ * Parses an array of string parameters (extracted from within brackets `[...]`).
1065
+ * Determines alignment, random settings, and absolute flag.
1066
+ * Example input: ['center'], ['random(0, 10)', 'abs']
1067
+ *
1068
+ * @param params - An array of string parameters.
1069
+ * @returns An ISplitOptionItem object representing the parsed parameters.
1070
+ */
1071
+ private parseParamsArray;
1072
+ }
1073
+
1074
+ /**
1075
+ * Interface describing all available tools used inside modules.
1076
+ */
1077
+ interface StringToolsContainer {
1078
+ /** Tool for reading DOM attributes (including data-*). */
1079
+ domAttribute: DOMAttributeTool;
1080
+ /** Tool for reading attributes from a plain JS object or dataset. */
1081
+ recordAttribute: RecordAttributeTool;
1082
+ /** Tool for calculating the relative position between two elements. */
1083
+ relativePosition: RelativePositionTool;
1084
+ /** Tool that nullifies the effect of CSS transform matrix. */
1085
+ transformNullify: TransformNullifyTool;
1086
+ /** Tool that wraps getBoundingClientRect with consistent output. */
1087
+ boundingClientRect: BoundingClientRectTool;
1088
+ /** Tool for parsing string-based values like '50%', '2rem', 'selfHeight'. */
1089
+ unitParser: UnitParserTool;
1090
+ /** Tool for performing linear interpolation (lerp). */
1091
+ lerp: LerpTool;
1092
+ /**
1093
+ * Tool for adaptive interpolation based on dynamic input value.
1094
+ * Useful when smoothing cursor speed, scroll velocity, etc.
1095
+ */
1096
+ adaptiveLerp: AdaptiveLerpTool;
1097
+ /**
1098
+ * Tool for parsing origin strings.
1099
+ * Supports values like `'top'`, `'center'`, or random expressions like `'random(top, bottom)'`.
1100
+ */
1101
+ originParser: OriginParserTool;
1102
+ /**
1103
+ * Tool for parsing CSS color strings into { r, g, b, a } format.
1104
+ * Supports `#hex`, `rgb[a](...)`, `hsl[a](...)` inputs.
1105
+ */
1106
+ colorParser: ColorParserTool;
1107
+ /**
1108
+ * Tool for validating strings using rules like `required`, `minLength`, `email`, etc.
1109
+ * Returns validation status, error code, and optional message.
1110
+ */
1111
+ validation: ValidationTool;
1112
+ /**
1113
+ * Tool for parsing CSS-like easing strings into easing functions.
1114
+ * Supports keywords like `'ease'`, `'linear'`, and full `cubic-bezier(...)` expressions.
1115
+ */
1116
+ easingFunction: EasingFunctionTool;
1117
+ /**
1118
+ * Tool for calculating magnetic offset strength based on proximity to pointer.
1119
+ */
1120
+ magneticPull: MagneticPullTool;
1121
+ /**
1122
+ * Tool for interpolating between two RGBA colors.
1123
+ * Accepts `from` and `to` colors as `{ r, g, b, a }`, and a `progress` value from `0` to `1`.
1124
+ * Returns an interpolated `StringColor` object.
1125
+ */
1126
+ lerpColor: LerpColorTool;
1127
+ /**
1128
+ * Tool for interpolating between two 2D vectors.
1129
+ * Accepts `{ x, y }` objects and a `progress` value between `0` and `1`.
1130
+ * Returns a new `{ x, y }` vector.
1131
+ */
1132
+ lerpVector: LerpVector2Tool;
1133
+ transformScaleParser: TransformScaleParserTool;
1134
+ layoutSplitter: LayoutLineSplitterTool;
1135
+ wordIndexer: WordIndexerTool;
1136
+ charIndexer: CharIndexerTool;
1137
+ domBuilder: SplitDomBuilderTool;
1138
+ optionsParser: SplitOptionsParserTool;
1139
+ }
1140
+
1141
+ /**
1142
+ * Shared context object passed to all modules and core controllers.
1143
+ *
1144
+ * Provides access to shared tools, data, settings, and event handling.
1145
+ */
1146
+ interface StringContext {
1147
+ /**
1148
+ * Collection of utility tools (e.g. lerp, dom parser, unit converter).
1149
+ */
1150
+ tools: StringToolsContainer;
1151
+ /**
1152
+ * Reactive state container including scroll, viewport, cursor, etc.
1153
+ */
1154
+ data: StringData;
1155
+ /**
1156
+ * Global configuration settings for modules and system behavior.
1157
+ */
1158
+ settings: StringSettings;
1159
+ /**
1160
+ * Centralized event emitter and listener system.
1161
+ */
1162
+ events: EventManager;
1163
+ }
1164
+
1165
+ /**
1166
+ * Internal class representing a DOM-bound interactive object.
1167
+ * Connected to modules and holds its own internal state.
1168
+ */
1169
+ declare class StringObject {
1170
+ /**
1171
+ * The DOM element this object wraps.
1172
+ */
1173
+ htmlElement: HTMLElement;
1174
+ /**
1175
+ * Unique global ID assigned by the system.
1176
+ */
1177
+ id: string;
1178
+ /**
1179
+ * Space-separated list of all attribute keys associated with this object.
1180
+ */
1181
+ keys: string[];
1182
+ /**
1183
+ * A list of elements that should be affected in sync with this one.
1184
+ */
1185
+ connects: HTMLElement[];
1186
+ /**
1187
+ * Internal key-value store of dynamic object properties (like offsets, progress, etc.).
1188
+ */
1189
+ private properties;
1190
+ /**
1191
+ * Modules currently connected to this object.
1192
+ */
1193
+ private modules;
1194
+ /**
1195
+ * Manages and handles events for the object.
1196
+ * Provides functionality to register, trigger, and manage event listeners.
1197
+ */
1198
+ events: EventManager;
1199
+ constructor(id: string, element: HTMLElement);
1200
+ /**
1201
+ * Stores a property value for this object.
1202
+ * @param key - Property name
1203
+ * @param value - Value to store
1204
+ */
1205
+ setProperty<T>(key: string, value: T): void;
1206
+ /**
1207
+ * Retrieves a previously stored property value.
1208
+ * @param key - Property name
1209
+ * @returns The value or null if not set
1210
+ */
1211
+ getProperty<T>(key: string): T;
1212
+ /**
1213
+ * Marks this object as "active" (usually on intersection/scroll enter).
1214
+ */
1215
+ enter(): void;
1216
+ /**
1217
+ * Marks this object as "inactive" (usually on intersection/scroll leave).
1218
+ */
1219
+ leave(): void;
1220
+ /**
1221
+ * Shows the object, applies visual class and notifies connected modules.
1222
+ */
1223
+ show(): void;
1224
+ /**
1225
+ * Hides the object, removes visual class (if repeat is enabled), and notifies modules.
1226
+ */
1227
+ hide(): void;
1228
+ /**
1229
+ * Connects a module to this object if not already connected.
1230
+ * @param module - The module to connect
1231
+ */
1232
+ connect(module: IStringModule): void;
1233
+ }
1234
+
1235
+ /**
1236
+ * Base interface for scroll/interaction modules in the StringScroll system.
1237
+ */
1238
+ interface IStringModule {
1239
+ /** Cleans up all internal state and detaches from the system. */
1240
+ destroy(): void;
1241
+ /** Called once when the module is initialized. */
1242
+ onInit(): void;
1243
+ /** Called on each frame with current scroll and state data. */
1244
+ onFrame(data: StringData): void;
1245
+ /** Called when the window or layout is resized. */
1246
+ onResize(): void;
1247
+ /** Called when the system rebuilds the DOM (e.g. after mutations). */
1248
+ onDOMRebuild(): void;
1249
+ /** Called when scroll position changes. */
232
1250
  onScroll(data: StringData): void;
233
- onConnect(object: StringObject): void;
234
- private setUpObject;
235
- private applyProgress;
236
- private calculatePositions;
1251
+ /** Called when scroll change diraction. */
1252
+ onDirectionChange(): void;
1253
+ /** Called when scrolling starts (user begins scroll). */
1254
+ onScrollStart(): void;
1255
+ /** Called when scrolling ends (user stops scroll). */
1256
+ onScrollStop(): void;
1257
+ /** Called when scroll direction changes (e.g. up → down). */
1258
+ onScrollDirectionChange(): void;
1259
+ /** Called when overall scroll axis changes (vertical ↔ horizontal). */
1260
+ onAxisChange(): void;
1261
+ /** Called when device type changes (e.g. desktop ↔ mobile). */
1262
+ onDeviceChange(): void;
1263
+ /** Called when scroll-related system settings or params are updated. */
1264
+ onScrollConfigChange(): void;
1265
+ /**
1266
+ * Called when global system settings are updated via `setupSettings`.
1267
+ * Modules can override this to re-read default values, refresh configs,
1268
+ * or reapply any cached parameters that depend on settings.
1269
+ *
1270
+ * This method is triggered after global fallback settings are merged into context.
1271
+ *
1272
+ * Example use cases:
1273
+ * - Recalculating default lerp, anchor, radius, etc.
1274
+ * - Updating internal thresholds or animation values.
1275
+ * - Reacting to system-wide design changes.
1276
+ */
1277
+ onSettingsChange(): void;
1278
+ /** Called on mouse move (for interaction-based modules). */
1279
+ onMouseMove(event: MouseEvent): void;
1280
+ /** Called on wheel scroll (separate from general scroll). */
1281
+ onWheel(event: WheelEvent): void;
1282
+ /**
1283
+ * Called when the DOM mutates — useful for detecting new or removed elements.
1284
+ */
1285
+ onDOMMutate(added: NodeList, removed: NodeList): void;
1286
+ /**
1287
+ * Triggered when an object was successfully connected.
1288
+ */
1289
+ onObjectConnected(object: StringObject): void;
1290
+ /**
1291
+ * Called when a DOM element is detected as a potential interactive object.
1292
+ */
1293
+ initializeObject(globalId: number, object: StringObject, element: HTMLElement, attributes: Record<string, any>): void;
1294
+ calculatePositions(object: StringObject, windowSize: number): void;
1295
+ /**
1296
+ * Check if a module should connect to a given object.
1297
+ */
1298
+ canConnect(object: StringObject): boolean;
1299
+ /**
1300
+ * Called to connect this module to the object.
1301
+ */
1302
+ connectObject(object: StringObject): void;
1303
+ /**
1304
+ * Called when the cursor or interaction enters an object's area.
1305
+ */
1306
+ enterObject(id: string, object: StringObject): void;
1307
+ /**
1308
+ * Called when the interaction leaves the object's area.
1309
+ */
1310
+ exitObject(id: string): void;
237
1311
  }
238
1312
 
239
- declare class StringSVG extends StringProgress {
240
- constructor(visitor: any);
241
- initObject(globalId: number, object: StringObject, el: HTMLElement, attributes: Record<string, any>): Promise<void>;
1313
+ type AttributeType = "string" | "number" | "boolean" | "json" | "dimension" | "tuple" | "easing" | "color" | {
1314
+ type: "enum";
1315
+ values: string[];
1316
+ };
1317
+
1318
+ /**
1319
+ * Represents the fallback value for an attribute mapping.
1320
+ * It can either be a static value or a function that dynamically
1321
+ * computes a value based on the element, object, and its bounding rectangle.
1322
+ */
1323
+ type AttributeFallback = any | ((context: {
1324
+ element: HTMLElement;
1325
+ object: StringObject;
1326
+ boundingRect: DOMRect;
1327
+ }) => any);
1328
+ /**
1329
+ * Describes how a specific attribute should be mapped from an HTML element
1330
+ * to internal module data. Each mapping defines the attribute key, its expected type,
1331
+ * an optional fallback value, and an optional transformation function.
1332
+ */
1333
+ type AttributeMapping = {
1334
+ /** Attribute name (without `string-` prefix). */
1335
+ key: string;
1336
+ /** The type used for parsing this attribute (e.g., 'number', 'boolean', 'tuple'). */
1337
+ type: AttributeType;
1338
+ /**
1339
+ * Optional fallback value if the attribute is not present on the element.
1340
+ * Can be a static value or a dynamic function.
1341
+ */
1342
+ fallback?: AttributeFallback;
1343
+ /**
1344
+ * Optional transformation function to apply to the parsed attribute value.
1345
+ * Useful for converting parsed data into a more usable format.
1346
+ */
1347
+ transform?: (value: any) => any;
1348
+ };
1349
+
1350
+ /**
1351
+ * Base class for a module used in the string-tune system.
1352
+ * Extend this class to create custom modules that respond to scroll, resize, input, etc.
1353
+ */
1354
+ declare class StringModule implements IStringModule {
1355
+ /**
1356
+ * List of attribute names this module should automatically read
1357
+ * from the DOM element and assign to the object properties.
1358
+ * Example: ["offset-top", "offset-bottom"]
1359
+ */
1360
+ protected attributesToMap: AttributeMapping[];
1361
+ /**
1362
+ * A map of all entered objects by their unique ID.
1363
+ */
1364
+ protected objectMap: Map<string, StringObject>;
1365
+ /**
1366
+ * A flat array of all connected objects.
1367
+ */
1368
+ protected objects: StringObject[];
1369
+ /**
1370
+ * The HTML attribute key that identifies objects this module is responsible for.
1371
+ */
1372
+ protected htmlKey: string;
1373
+ /**
1374
+ * Module type ID used internally to categorize module behavior.
1375
+ */
1376
+ protected _type: number;
1377
+ /**
1378
+ * Returns the type of the module.
1379
+ * Type 1 = core module, type 2 = UI module.
1380
+ */
1381
+ get type(): number;
1382
+ /**
1383
+ * Tools container providing utilities for attribute parsing, unit conversion, etc.
1384
+ * Acts as a dependency injection hub for core IStringTool implementations.
1385
+ */
1386
+ protected tools: StringToolsContainer;
1387
+ /**
1388
+ * Shared global data object containing scroll state, viewport info, cursor position, etc.
1389
+ * Used for calculations within lifecycle hooks like `onScroll`, `onFrame`, and `onResize`.
1390
+ */
1391
+ protected data: StringData;
1392
+ /**
1393
+ * Configuration object specific to the current module.
1394
+ * Passed in during module registration or initialization.
1395
+ */
1396
+ protected settings: Record<string, any>;
1397
+ /**
1398
+ * Event hub for communication between modules or systems.
1399
+ * Supports custom event emitting, listening, and unsubscription.
1400
+ */
1401
+ protected events: EventManager;
1402
+ constructor(context: StringContext);
1403
+ /**
1404
+ * Called when a DOM element is detected as a potential interactive object.
1405
+ */
1406
+ initializeObject(globalId: number, object: StringObject, element: HTMLElement, attributes: Record<string, any>): void;
1407
+ /**
1408
+ * Calculates object-specific positions or metrics based on the current layout or scroll state.
1409
+ * This method is intended to be overridden in subclasses if the module needs to precompute
1410
+ * layout-dependent values (e.g. parallax offsets, trigger zones, distances).
1411
+ *
1412
+ * @param object The `StringObject` instance whose positions are being calculated.
1413
+ * @param windowSize The current window height or width (depending on scroll axis).
1414
+ */
1415
+ calculatePositions(object: StringObject, windowSize: number): void;
1416
+ /**
1417
+ * Parses a raw DOM attribute value into the correct type based on mapping.
1418
+ * Handles fallback resolution, transformation, and special units.
1419
+ *
1420
+ * @param value Raw attribute string from DOM.
1421
+ * @param type The expected attribute type (e.g. number, boolean, dimension).
1422
+ * @param context Optional helper values like element or viewport size.
1423
+ * @returns The parsed and transformed value.
1424
+ */
1425
+ protected parseAttribute(value: string | null, type: AttributeType, context?: {
1426
+ element?: HTMLElement;
1427
+ viewportHeight?: number;
1428
+ baseRem?: number;
1429
+ }): any;
1430
+ /**
1431
+ * Determines whether the module should attach to a given object,
1432
+ * based on the presence of the module's `htmlKey` in the object keys.
1433
+ *
1434
+ * @param object The target object to test.
1435
+ * @returns `true` if the module can connect, `false` otherwise.
1436
+ */
1437
+ canConnect(object: StringObject): boolean;
1438
+ /**
1439
+ * Registers the module on a given object, adds the object to internal list,
1440
+ * and triggers connection logic.
1441
+ *
1442
+ * @param object The object to connect to.
1443
+ */
1444
+ connectObject(object: StringObject): void;
1445
+ /**
1446
+ * Registers the object internally when it enters the module’s scope.
1447
+ */
1448
+ enterObject(id: string, object: StringObject): void;
1449
+ /**
1450
+ * Unregisters the object when it leaves the module’s scope.
1451
+ */
1452
+ exitObject(id: string): void;
1453
+ /**
1454
+ * Called when an object is connected. Can be overridden to apply initial styles or logic.
1455
+ * @param object The connected object.
1456
+ */
1457
+ onObjectConnected(object: StringObject): void;
1458
+ /**
1459
+ * Applies a style or callback to both the main element and all its connected elements.
1460
+ *
1461
+ * @param object The object whose elements to update.
1462
+ * @param applyFn The function that receives an HTMLElement and performs any update.
1463
+ */
1464
+ protected applyToElementAndConnects(object: StringObject, applyFn: (el: HTMLElement) => void): void;
1465
+ /**
1466
+ * Cleans up internal state and detaches the module from the system.
1467
+ */
1468
+ destroy(): void;
1469
+ /** Called once when the module is initialized. */
1470
+ onInit(): void;
1471
+ /** Called on each frame with current scroll and state data. */
1472
+ onFrame(data: StringData): void;
1473
+ /** Called when the window or layout is resized. */
1474
+ onResize(): void;
1475
+ /** Called when scroll position changes. */
242
1476
  onScroll(data: StringData): void;
243
- private loadSVG;
244
- private morphPath;
245
- private interpolatePaths;
246
- private parsePathCommands;
1477
+ /** Called when user changed scroll diraction. */
1478
+ onDirectionChange(): void;
1479
+ /** Called when user starts scrolling. */
1480
+ onScrollStart(): void;
1481
+ /** Called when user stops scrolling. */
1482
+ onScrollStop(): void;
1483
+ /** Called when scroll direction changes (e.g., up ↔ down). */
1484
+ onScrollDirectionChange(): void;
1485
+ /** Called when scroll axis changes (vertical ↔ horizontal). */
1486
+ onAxisChange(): void;
1487
+ /** Called when device type changes (e.g., desktop ↔ mobile). */
1488
+ onDeviceChange(): void;
1489
+ /** Called when scroll-related system settings or parameters change. */
1490
+ onScrollConfigChange(): void;
1491
+ /** Called when scroll-related system settings or parameters change. */
1492
+ onSettingsChange(): void;
1493
+ /** Called when the DOM is rebuilt, such as after a major mutation. */
1494
+ onDOMRebuild(): void;
1495
+ /** Called on every mouse movement. */
1496
+ onMouseMove(event: MouseEvent): void;
1497
+ /** Called on wheel input (independent of scroll). */
1498
+ onWheel(event: WheelEvent): void;
1499
+ /**
1500
+ * Called when DOM elements are added or removed.
1501
+ */
1502
+ onDOMMutate(added: NodeList, removed: NodeList): void;
247
1503
  }
248
1504
 
249
- declare class StringCursor extends StringBase {
250
- private oldX;
251
- private oldY;
1505
+ declare class StringCursor extends StringModule {
252
1506
  protected enterObjectsMap: Map<string, StringObject>;
253
1507
  protected enterObjects: Array<StringObject>;
254
1508
  cursor: any;
255
1509
  cursorContent: any;
256
1510
  overCount: number;
257
- constructor(visitor: any, settings?: any);
258
- onStart(): void;
259
- initObject(globalId: number, object: StringObject, el: HTMLElement, attributes: Record<string, any>): void;
260
- onUpdate(data: StringData): void;
261
- onConnect(object: StringObject): void;
1511
+ constructor(context: StringContext);
1512
+ initializeObject(globalId: number, object: StringObject, element: HTMLElement, attributes: Record<string, any>): void;
1513
+ onFrame(data: StringData): void;
1514
+ onObjectConnected(object: StringObject): void;
1515
+ getCursorClass(object: StringObject): string | null;
1516
+ onMouseEnter(object: StringObject): void;
1517
+ onMouseLeave(object: StringObject): void;
1518
+ private onEnterObject;
1519
+ private onLeaveObject;
262
1520
  private setMouseCoordinates;
263
1521
  private calculateOffset;
264
1522
  }
265
1523
 
266
- declare class StringMagnetic extends StringBase {
267
- constructor(visitor: any);
268
- initObject(globalId: number, object: StringObject, el: HTMLElement, attributes: Record<string, any>): void;
269
- onConnect(object: StringObject): void;
1524
+ declare class StringMagnetic extends StringModule {
1525
+ constructor(context: StringContext);
1526
+ initializeObject(globalId: number, object: StringObject, element: HTMLElement, attributes: Record<string, any>): void;
270
1527
  onMouseMove(e: MouseEvent): void;
271
- onUpdate(data: StringData): void;
1528
+ onFrame(data: StringData): void;
1529
+ }
1530
+
1531
+ /**
1532
+ * Module that handles lazy-loading of images with `string-lazy` attribute.
1533
+ * Automatically loads and applies aspect-ratio once image is loaded.
1534
+ */
1535
+ declare class StringLazy extends StringModule {
1536
+ private isStartLoaded;
1537
+ private loadingCount;
1538
+ constructor(context: StringContext);
1539
+ /**
1540
+ * Called on module start — preloads all <img string-lazy> in DOM.
1541
+ */
1542
+ onInit(): void;
1543
+ /**
1544
+ * Called when an image becomes a managed object.
1545
+ */
1546
+ onObjectConnected(object: StringObject): void;
1547
+ /**
1548
+ * Loads image and sets aspect-ratio based on real dimensions.
1549
+ */
1550
+ private loadImage;
1551
+ /**
1552
+ * Loads image data to extract real dimensions and apply aspect-ratio style.
1553
+ */
1554
+ private setAspectRatio;
1555
+ }
1556
+
1557
+ declare class StringLoading extends StringModule {
1558
+ loadingTimeout: number;
1559
+ constructor(context: StringContext);
1560
+ onInit(): void;
272
1561
  }
273
1562
 
274
1563
  declare class StringResponsive extends StringModule {
275
1564
  private queries;
276
1565
  private matchMedias;
277
- constructor(visitor: any, settings: any);
1566
+ constructor(context: StringContext);
278
1567
  onConnect(): void;
279
- onStart(): void;
1568
+ onInit(): void;
280
1569
  onResize(): void;
281
1570
  private updateElements;
282
1571
  }
283
1572
 
284
- declare class StringScrollbar extends StringModule {
285
- private scrollbar;
286
- private thumb;
287
- private scrollTimeout;
288
- private isDragging;
289
- private scrollMode;
290
- private mouseUpEventBind;
291
- private mouseDownEventBind;
292
- private mouseMoveEventBind;
293
- private scrollbarState;
294
- private scrollbarStateHorizontal;
295
- private scrollbarStateVertical;
296
- constructor(visitor: any);
297
- destructor(): void;
298
- onStart(): void;
299
- onScroll(data: StringData): void;
300
- onResize(): void;
301
- onChangeScrollParams(): void;
302
- onChangeScrollDirection(): void;
303
- private addCustomStyles;
304
- private createScrollbar;
305
- private updateThumb;
306
- private mouseDownEvent;
307
- private mouseMoveEvent;
308
- private mouseUpEvent;
309
- private showScrollbar;
310
- private hideScrollbar;
311
- }
312
-
313
- declare class StringAnchor extends StringBase {
314
- constructor(visitor: any);
315
- initObject(globalId: number, object: StringObject, el: HTMLElement, attributes: Record<string, any>): void;
316
- onConnect(object: StringObject): void;
317
- private parseOrig;
1573
+ declare class StringAnchor extends StringModule {
1574
+ constructor(context: StringContext);
1575
+ onObjectConnected(object: StringObject): void;
318
1576
  }
319
1577
 
320
- declare class StringGlide extends StringBase {
1578
+ declare class StringGlide extends StringModule {
321
1579
  private previousLerp;
322
1580
  private displacement;
323
1581
  private acceleration;
@@ -326,14 +1584,8 @@ declare class StringGlide extends StringBase {
326
1584
  private baseVelocityMultiplier;
327
1585
  private reducedVelocityMultiplier;
328
1586
  private negativeVelocityMultiplier;
329
- private readonly ACCELERATION_STEP;
330
- private readonly MIN_DISPLACEMENT;
331
- private readonly MAX_DISPLACEMENT;
332
- private readonly MIN_VELOCITY;
333
- private readonly MAX_VELOCITY;
334
1587
  private maxDisplacementValue;
335
- constructor(visitor: any, settings?: any);
336
- initObject(globalId: number, object: StringObject, el: HTMLElement, attributes: Record<string, any>): void;
1588
+ constructor(context: StringContext);
337
1589
  private setupItem;
338
1590
  private onUpdateDesktopEvent;
339
1591
  private onUpdateMobileEvent;
@@ -344,217 +1596,466 @@ declare class StringGlide extends StringBase {
344
1596
  private resetState;
345
1597
  onScrollStart(): void;
346
1598
  onScrollStop(): void;
347
- onUpdate(data: StringData): void;
1599
+ onFrame(data: StringData): void;
348
1600
  }
349
1601
 
350
- declare class StringLerp extends StringBase {
351
- constructor(visitor: any);
1602
+ /**
1603
+ * Module that updates the `--lerp` CSS variable on elements
1604
+ * based on current scroll velocity.
1605
+ */
1606
+ declare class StringLerp extends StringModule {
1607
+ constructor(context: StringContext);
1608
+ /**
1609
+ * Resets the `--lerp` value to 0 when scroll stops.
1610
+ */
352
1611
  onScrollStop(): void;
1612
+ /**
1613
+ * Updates `--lerp` value for each connected object during scroll.
1614
+ */
1615
+ onFrame(data: StringData): void;
1616
+ /**
1617
+ * Sets the `--lerp` CSS variable on the object.
1618
+ */
1619
+ private setLerpValue;
1620
+ }
1621
+
1622
+ declare class StringProgress extends StringModule {
1623
+ constructor(context: StringContext);
1624
+ /**
1625
+ * Called when an object is initialized.
1626
+ */
1627
+ initializeObject(globalId: number, object: StringObject, element: HTMLElement, attributes: Record<string, any>): void;
1628
+ /**
1629
+ * Called on scroll.
1630
+ */
353
1631
  onScroll(data: StringData): void;
1632
+ onObjectConnected(object: StringObject): void;
1633
+ private setUpObject;
1634
+ calculatePositions(object: StringObject, windowSize: number): void;
354
1635
  }
355
1636
 
356
1637
  declare class StringParallax extends StringProgress {
357
- constructor(visitor: any);
358
- initObject(globalId: number, object: StringObject, el: HTMLElement, attributes: Record<string, any>): void;
359
- private setupParallax;
360
- private onScrollDesktopEvent;
361
- private onScrollMobileEvent;
362
- private onScrollEvent;
1638
+ constructor(context: StringContext);
1639
+ /**
1640
+ * Called when an object is initialized.
1641
+ */
1642
+ initializeObject(globalId: number, object: StringObject, element: HTMLElement, attributes: Record<string, any>): void;
1643
+ /**
1644
+ * Called on scroll.
1645
+ */
363
1646
  onScroll(data: StringData): void;
1647
+ /**
1648
+ * Called on resize.
1649
+ */
364
1650
  onResize(): void;
1651
+ private handleScrollDesktop;
1652
+ private handleScrollMobile;
1653
+ private scrollHandler;
365
1654
  }
366
1655
 
367
- interface ISplitOptions {
368
- line?: Array<{
369
- align: string;
370
- random?: {
371
- min: number;
372
- max: number;
373
- };
374
- abs?: boolean;
375
- }>;
376
- word?: Array<{
377
- align: string;
378
- random?: {
379
- min: number;
380
- max: number;
381
- };
382
- abs?: boolean;
383
- }>;
384
- char?: Array<{
385
- align: string;
386
- random?: {
387
- min: number;
388
- max: number;
389
- };
390
- abs?: boolean;
391
- }>;
392
- charLine?: Array<{
393
- align: string;
394
- random?: {
395
- min: number;
396
- max: number;
397
- };
398
- abs?: boolean;
399
- }>;
400
- charWord?: Array<{
401
- align: string;
402
- random?: {
403
- min: number;
404
- max: number;
405
- };
406
- abs?: boolean;
407
- }>;
408
- wordLine?: Array<{
409
- align: string;
410
- random?: {
411
- min: number;
412
- max: number;
413
- };
414
- abs?: boolean;
415
- }>;
416
- }
417
- declare class StringSplit extends StringBase {
418
- constructor(visitor: any);
419
- onStart(): void;
1656
+ declare class StringScrollbar extends StringModule {
1657
+ private scrollbar;
1658
+ private thumb;
1659
+ private scrollTimeout;
1660
+ private isDragging;
1661
+ private scrollMode;
1662
+ private mouseUpEventBind;
1663
+ private mouseDownEventBind;
1664
+ private mouseMoveEventBind;
1665
+ private scrollbarState;
1666
+ private scrollbarStateHorizontal;
1667
+ private scrollbarStateVertical;
1668
+ constructor(context: StringContext);
1669
+ destructor(): void;
1670
+ onInit(): void;
1671
+ onScroll(data: StringData): void;
420
1672
  onResize(): void;
421
- onConnect(object: StringObject): void;
422
- private parseSplitOptions;
423
- private parseParam;
424
- split(options: ISplitOptions, elementRoot: any): any;
425
- private appendVirtualLineToDOM;
426
- private applyOptions;
427
- private createSpaceSpan;
428
- private decodeHtmlEntity;
429
- private calculateIndex;
430
- private generateVariableName;
1673
+ private addCustomStyles;
1674
+ private createScrollbar;
1675
+ private updateThumb;
1676
+ private mouseDownEvent;
1677
+ private mouseMoveEvent;
1678
+ private mouseUpEvent;
1679
+ private showScrollbar;
1680
+ private hideScrollbar;
1681
+ }
1682
+
1683
+ /**
1684
+ * StringModule responsible for splitting text within HTML elements
1685
+ * into lines, words, and characters based on layout and attributes,
1686
+ * and applying CSS variables for animation purposes.
1687
+ * Uses a tool-based approach for modularity.
1688
+ */
1689
+ declare class StringSplit extends StringModule {
1690
+ /**
1691
+ * Initializes the StringSplit module and its tools.
1692
+ * @param context - The global StringContext.
1693
+ */
1694
+ constructor(context: StringContext);
1695
+ /**
1696
+ * Called when the module initializes.
1697
+ * Processes elements already present in the DOM on load.
1698
+ */
1699
+ onInit(): void;
1700
+ /**
1701
+ * Called when the window is resized.
1702
+ * Re-processes already split elements as their layout might have changed.
1703
+ */
1704
+ onResize(): void;
1705
+ /**
1706
+ * Called when a new StringObject associated with this module connects.
1707
+ * Processes the newly connected element.
1708
+ * @param object - The StringObject representing the connected element.
1709
+ */
1710
+ onObjectConnected(object: StringObject): void;
1711
+ /**
1712
+ * Central method to process splitting for a given HTML element.
1713
+ * Orchestrates the use of various tools: parsing options, calculating layout,
1714
+ * indexing words and characters, building the final HTML, and updating the DOM.
1715
+ * Includes error handling.
1716
+ * @param element - The HTMLElement to process.
1717
+ */
1718
+ private processElement;
431
1719
  }
432
1720
 
1721
+ /**
1722
+ * Visual tracker that plots scroll displacement (velocity) in real time.
1723
+ * Useful for debugging and tuning smoothing behavior.
1724
+ */
433
1725
  declare class StringDelayLerpTracker extends StringModule {
434
1726
  private canvas;
435
1727
  private context;
436
- private positionHistory;
437
- private maxHistory;
438
- private currentPosition;
439
- private targetPosition;
440
- private canvasHeight;
441
- constructor(visitor: any);
442
- onStart(): void;
1728
+ private history;
1729
+ private maxPoints;
1730
+ private height;
1731
+ private value;
1732
+ private target;
1733
+ constructor(context: StringContext);
1734
+ /**
1735
+ * Called when the module starts — sets up canvas.
1736
+ */
1737
+ onInit(): void;
1738
+ /**
1739
+ * Called on scroll — stores current displacement and redraws.
1740
+ */
443
1741
  onScroll(data: StringData): void;
444
- drawGraph(): void;
445
- setTargetPosition(position: number): void;
1742
+ /**
1743
+ * Draws the displacement graph to canvas.
1744
+ */
1745
+ private draw;
1746
+ /**
1747
+ * Creates and styles the tracking canvas.
1748
+ */
1749
+ private initCanvas;
1750
+ /**
1751
+ * Optional method to update external comparison target.
1752
+ */
1753
+ setTarget(position: number): void;
1754
+ /**
1755
+ * Removes the canvas from DOM and resets.
1756
+ */
1757
+ clear(): void;
446
1758
  }
447
1759
 
1760
+ /**
1761
+ * FPS Tracker Module.
1762
+ * Displays how many times `onFrame()` is called per second.
1763
+ * Useful for debugging rendering performance or vsync issues.
1764
+ */
448
1765
  declare class StringFPSTracker extends StringModule {
449
- private callCount;
450
- private intervalId;
451
1766
  private displayElement;
452
- constructor(visitor: any);
1767
+ private intervalId;
1768
+ private frameCount;
1769
+ constructor(context: StringContext);
1770
+ /**
1771
+ * Initializes the visual FPS counter and update interval.
1772
+ */
1773
+ onInit(): void;
1774
+ /**
1775
+ * Increments the frame counter each frame.
1776
+ */
1777
+ onFrame(_data: StringData): void;
1778
+ /**
1779
+ * Cleans up DOM and interval.
1780
+ */
1781
+ destroy(): void;
1782
+ /**
1783
+ * Creates and styles the floating FPS display.
1784
+ */
453
1785
  private createDisplayElement;
454
- onStart(): void;
455
- onUpdate(data: StringData): void;
456
- destructor(): void;
457
1786
  }
458
1787
 
1788
+ /**
1789
+ * Visual tracker that plots lerped scroll velocity (v) in real time.
1790
+ * Useful for analyzing smooth scroll interpolation behavior.
1791
+ */
459
1792
  declare class StringLerpTracker extends StringModule {
460
1793
  private canvas;
461
1794
  private context;
462
- private positionHistory;
463
- private maxHistory;
464
- private currentPosition;
465
- private targetPosition;
466
- constructor(visitor: any);
467
- onStart(): void;
1795
+ private history;
1796
+ private maxPoints;
1797
+ private canvasHeight;
1798
+ private currentValue;
1799
+ private targetValue;
1800
+ constructor(context: StringContext);
1801
+ /**
1802
+ * Called on start — sets up canvas overlay.
1803
+ */
1804
+ onInit(): void;
1805
+ /**
1806
+ * Called on scroll — reads smoothed scroll velocity (v).
1807
+ */
468
1808
  onScroll(data: StringData): void;
469
- drawGraph(): void;
470
- setTargetPosition(position: number): void;
1809
+ /**
1810
+ * Draws the current graph line based on v-history.
1811
+ */
1812
+ private draw;
1813
+ /**
1814
+ * Creates the canvas overlay and applies style.
1815
+ */
1816
+ private initCanvas;
1817
+ /**
1818
+ * Optional external target value for debugging.
1819
+ */
1820
+ setTarget(position: number): void;
1821
+ /**
1822
+ * Removes canvas from DOM and clears history.
1823
+ */
1824
+ clear(): void;
471
1825
  }
472
1826
 
1827
+ /**
1828
+ * Tracker module that shows current scroll position and direction.
1829
+ * Displays a fixed label in the corner of the screen for debugging.
1830
+ */
473
1831
  declare class StringPositionTracker extends StringModule {
474
- private callCount;
475
- private intervalId;
476
1832
  private displayElement;
477
- constructor(visitor: any);
478
- private createDisplayElement;
479
- onStart(): void;
1833
+ constructor(context: StringContext);
1834
+ /**
1835
+ * Called on start — creates the DOM element for position display.
1836
+ */
1837
+ onInit(): void;
1838
+ /**
1839
+ * Called on scroll — updates scroll position and direction symbol.
1840
+ */
480
1841
  onScroll(data: StringData): void;
481
- onUpdate(data: StringData): void;
482
- destructor(): void;
1842
+ /**
1843
+ * Removes display element from DOM.
1844
+ */
1845
+ destroy(): void;
1846
+ /**
1847
+ * Creates and styles the floating position indicator.
1848
+ */
1849
+ private createDisplayElement;
1850
+ }
1851
+
1852
+ declare class StringVideoAutoplay extends StringModule {
1853
+ constructor(context: StringContext);
1854
+ onObjectConnected(object: StringObject): void;
1855
+ private onEnterObject;
1856
+ private onLeaveObject;
1857
+ private tryPlay;
483
1858
  }
484
1859
 
485
1860
  declare class StringTune {
486
- private static i;
487
- private modules;
488
- private modulesUI;
489
- private events;
490
- private loop;
1861
+ /** Bound handler for the scroll start event */
1862
+ private onScrollStartBind;
1863
+ /** Bound handler for the scroll stop event */
1864
+ private onScrollStopBind;
1865
+ /** Bound handler for the scroll direction change event */
1866
+ private onDirectionChangeBind;
1867
+ /** Bound wheel event handler */
491
1868
  private onWheelBind;
1869
+ /** Bound scroll event handler */
492
1870
  private onScrollBind;
1871
+ /** Bound resize event handler */
493
1872
  private onResizeBind;
1873
+ /** Bound mouse move handler */
494
1874
  private onMouseMoveBind;
495
- private wW;
496
- private wH;
1875
+ /** Singleton instance of StringTune */
1876
+ private static i;
1877
+ /** Root scrollable element (typically <body>) */
497
1878
  private root;
1879
+ /** Window object (used for event bindings and dimensions) */
498
1880
  private window;
499
- private _virtualCursor;
500
- private _lerp;
501
- private _attribute;
502
- private _boundingClientRect;
503
- private _position;
504
- private _defaultSettings;
505
- private sEn;
506
- private sEnSmooth;
507
- private sEnDefault;
508
- private sEnDisable;
509
- private settings;
1881
+ /** Previous window width for resize diff check */
1882
+ private prevWidth;
1883
+ /** Previous window height for resize diff check */
1884
+ private prevHeight;
1885
+ /** Manages all modules registered in the system */
1886
+ private moduleManager;
1887
+ /** Manages scroll modes and active scroll engine */
1888
+ private scrollManager;
1889
+ /** Manages all interactive objects (elements with `string-*` attributes) */
1890
+ private objectManager;
1891
+ /** Central event manager for internal pub-sub logic */
1892
+ private eventManager;
1893
+ /** Handles custom cursor logic (if enabled) */
1894
+ private cursorController;
1895
+ /** Provides default utility tools (parsers, interpolation, etc.) */
1896
+ private tools;
1897
+ /** Main loop used for frame updates (with fixed FPS) */
1898
+ private loop;
1899
+ /** Global reactive data store (scroll, viewport, etc.) */
510
1900
  private data;
511
- protected objects: Map<string, StringObject>;
512
- protected connectQueue: Array<any>;
513
- private globalId;
514
- private _parser;
515
- private isStarted;
516
- private fps;
517
- get scrollDirection(): 'vertical' | 'horizontal';
518
- set scrollDirection(scrollDirection: 'vertical' | 'horizontal');
519
- get speedAccelerate(): number;
520
- set speedAccelerate(speed: number);
521
- get speed(): number;
522
- set speed(speed: number);
523
- get scrollPosition(): number;
524
- set scrollPosition(scrollPosition: number);
1901
+ /** Context shared across all modules (events, data, tools, settings) */
1902
+ private context;
1903
+ /**
1904
+ * Sets the scroll position manually.
1905
+ * This overrides all internal scroll states including target and lerped values.
1906
+ * Useful for programmatic jumps or syncing scroll externally.
1907
+ *
1908
+ * @param value The new scroll position in pixels.
1909
+ */
1910
+ set scrollPosition(value: number);
1911
+ /**
1912
+ * Configures the container element(s) used for scroll tracking.
1913
+ * Accepts either the `Window` object or an `HTMLElement`.
1914
+ * Determines the appropriate internal element references based on the input type
1915
+ * and triggers a resize calculation.
1916
+ *
1917
+ * @param {Window | HTMLElement | any} container The target window or HTML element to associate with scrolling.
1918
+ * Handles `Window`, `HTMLElement`, and potentially other types via fallback.
1919
+ */
525
1920
  set scrollContainer(container: any);
526
- private scrollMode;
527
- private mMode;
528
- set scrollMobileMode(mobileMode: 'disable' | 'default');
529
- private dMode;
530
- set scrollDesktopMode(desktopMode: 'smooth' | 'disable' | 'default');
531
- private updateModeParams;
1921
+ /**
1922
+ * Gets the current scroll position in pixels.
1923
+ * This is typically updated every frame.
1924
+ */
1925
+ get speed(): number;
1926
+ /**
1927
+ * Sets the base scroll speed for smooth scrolling.
1928
+ * Typically a value between 0 and 1.
1929
+ */
1930
+ set speed(value: number);
1931
+ /**
1932
+ * Sets the scroll acceleration using a normalized value from 0 to 1.
1933
+ * Internally maps it to a real acceleration value between 0.1 and 0.5.
1934
+ *
1935
+ * @param speed A normalized acceleration factor (0 to 1).
1936
+ */
1937
+ set speedAccelerate(speed: number);
1938
+ /**
1939
+ * Sets the scroll mode for desktop devices.
1940
+ * Can be 'smooth', 'default', or 'disable'.
1941
+ */
1942
+ set scrollDesktopMode(mode: ScrollMode);
1943
+ /**
1944
+ * Sets the scroll mode for mobile devices.
1945
+ * Can be 'smooth', 'default', or 'disable'.
1946
+ */
1947
+ set scrollMobileMode(mode: ScrollMode);
1948
+ private debouncedResize;
532
1949
  private constructor();
1950
+ /**
1951
+ * Returns the singleton instance of StringTune.
1952
+ * If not already created, initializes it.
1953
+ */
533
1954
  static getInstance(): StringTune;
1955
+ /**
1956
+ * Finds and returns an existing module by its class.
1957
+ * Useful for reusing a module instance without re-registering.
1958
+ *
1959
+ * @template T The type of the module to retrieve.
1960
+ * @param type The module class constructor.
1961
+ * @returns The module instance if found, otherwise undefined.
1962
+ */
534
1963
  reuse<T>(type: new (...args: any[]) => T): T | undefined;
1964
+ /**
1965
+ * Instantiates and registers a new module.
1966
+ * Accepts optional per-instance settings that override global settings.
1967
+ *
1968
+ * @param objectClass The module class to instantiate.
1969
+ * @param settings Optional settings specific to this module.
1970
+ */
535
1971
  use(objectClass: typeof StringModule, settings?: any): void;
1972
+ /**
1973
+ * Subscribes to a global event within the system.
1974
+ *
1975
+ * @param eventName The name of the event to listen for.
1976
+ * @param callback The function to call when the event is triggered.
1977
+ * @param id Optional subscription ID (for easier management).
1978
+ */
1979
+ on(eventName: string, callback: EventCallback<any>, id?: string): void;
1980
+ /**
1981
+ * Unsubscribes from a global event.
1982
+ *
1983
+ * @param eventName The name of the event.
1984
+ * @param callback The previously registered callback.
1985
+ * @param id Optional ID used during subscription.
1986
+ */
1987
+ off(eventName: string, callback: EventCallback<any>, id?: string): void;
1988
+ /**
1989
+ * Starts the scroll engine and initializes all listeners, observers, and modules.
1990
+ *
1991
+ * @param fps Desired frames per second for the update loop.
1992
+ */
536
1993
  start(fps: number): void;
537
- private onChangeScrollParams;
1994
+ /**
1995
+ * Initializes all DOM elements with `string` or `string-copy-from` attributes.
1996
+ * Registers them with the object manager and triggers resize/scroll/frame hooks.
1997
+ */
538
1998
  private initObjects;
539
- destroy(): void;
540
- private eventMap;
541
- on(key: keyof typeof this.eventMap, event: any, id?: string): void;
542
- off(key: keyof typeof this.eventMap, event: any, id?: string): void;
543
- setupSettings(settings: any): void;
544
- protected setupObject(el: HTMLElement, object: StringObject): void;
545
- private getAllAttributes;
546
- addObject(el: HTMLElement): void;
547
- removeObject(id: string): void;
1999
+ /**
2000
+ * Sets global fallback settings for all modules.
2001
+ * These can be overridden by module-specific settings during `use(...)`.
2002
+ *
2003
+ * @param settings A key-value map of default settings (e.g. 'offset-top': '-10%').
2004
+ */
2005
+ setupSettings(settings: StringSettings): void;
2006
+ /**
2007
+ * Handles mouse move event and dispatches it to cursor and modules.
2008
+ * @param e Native mouse move event.
2009
+ */
548
2010
  private onMouseMoveEvent;
2011
+ /**
2012
+ * Handles wheel scroll event and passes it to the scroll engine and modules.
2013
+ * @param e Native wheel event.
2014
+ */
549
2015
  private onWheelEvent;
2016
+ /**
2017
+ * Called when scrolling begins.
2018
+ * Triggers module scroll start lifecycle hook.
2019
+ */
550
2020
  private onScrollStart;
2021
+ /**
2022
+ * Called when scrolling ends.
2023
+ * Triggers module scroll stop lifecycle hook.
2024
+ */
551
2025
  private onScrollStop;
552
- private onChangeDirection;
2026
+ /**
2027
+ * Called when scrolling ends.
2028
+ * Triggers module scroll stop lifecycle hook.
2029
+ */
2030
+ private onDirectionChange;
2031
+ /**
2032
+ * Called when global or module settings are updated.
2033
+ * Notifies all managers and modules to re-read new settings.
2034
+ */
2035
+ private onSettingsChange;
2036
+ /**
2037
+ * Handles native scroll event.
2038
+ * Prevents default behavior and triggers internal scroll logic and event emissions.
2039
+ *
2040
+ * @param e The native scroll event.
2041
+ */
553
2042
  private onScrollEvent;
2043
+ /**
2044
+ * Called every frame by the update loop.
2045
+ * Triggers scroll engine, modules, and global `update` event.
2046
+ */
554
2047
  private onUpdateEvent;
2048
+ /**
2049
+ * Handles resize events from scroll container or window.
2050
+ * Ignores height-only changes on mobile to prevent layout jumps.
2051
+ * Rebuilds layout and triggers module resize if size really changed.
2052
+ */
555
2053
  onResize(): void;
556
- private initMutationObserver;
557
- private rebuild;
2054
+ /**
2055
+ * Cleans up the system, removes all event listeners, stops the loop,
2056
+ * and destroys modules and event subscriptions.
2057
+ */
2058
+ destroy(): void;
558
2059
  }
559
2060
 
560
- export { StringAnchor, StringCursor, StringData, StringDelayLerpTracker, StringFPSTracker, StringGlide, StringLazy, StringLerp, StringLerpTracker, StringLoading, StringMagnetic, StringModule, StringObject, StringParallax, StringPositionTracker, StringProgress, StringResponsive, StringSVG, StringScrollbar, StringSplit, StringTune, StringVideoAutoplay, StringTune as default };
2061
+ export { StringAnchor, type StringContext, StringCursor, StringData, StringDelayLerpTracker, StringFPSTracker, StringGlide, StringLazy, StringLerp, StringLerpTracker, StringLoading, StringMagnetic, StringModule, StringObject, StringParallax, StringPositionTracker, StringProgress, StringResponsive, StringScrollbar, StringSplit, StringTune, StringVideoAutoplay, StringTune as default };