@motion.page/sdk 0.1.0
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/README.md +817 -0
- package/dist/core/Animation.d.ts +230 -0
- package/dist/core/AnimationBuilder.d.ts +125 -0
- package/dist/core/Engine.d.ts +140 -0
- package/dist/core/Motion.d.ts +56 -0
- package/dist/core/PropTween.d.ts +81 -0
- package/dist/core/Ticker.d.ts +107 -0
- package/dist/core/Timeline.d.ts +294 -0
- package/dist/easing/index.d.ts +65 -0
- package/dist/fit/FitResolver.d.ts +12 -0
- package/dist/index.cjs +34 -0
- package/dist/index.cjs.map +52 -0
- package/dist/index.d.ts +25 -0
- package/dist/index.js +34 -0
- package/dist/index.js.map +52 -0
- package/dist/memory/AnimationPool.d.ts +14 -0
- package/dist/memory/ObjectPool.d.ts +37 -0
- package/dist/memory/PropTweenPool.d.ts +14 -0
- package/dist/registries/SDKRegistry.d.ts +69 -0
- package/dist/render/CSSRenderer.d.ts +33 -0
- package/dist/render/PathRenderer.d.ts +24 -0
- package/dist/render/RenderBatch.d.ts +27 -0
- package/dist/render/TransformCache.d.ts +54 -0
- package/dist/stagger/StaggerResolver.d.ts +28 -0
- package/dist/triggers/BaseTrigger.d.ts +61 -0
- package/dist/triggers/CursorTrigger.d.ts +86 -0
- package/dist/triggers/EventTrigger.d.ts +48 -0
- package/dist/triggers/GestureTrigger.d.ts +137 -0
- package/dist/triggers/MarkerManager.d.ts +42 -0
- package/dist/triggers/MouseMoveTrigger.d.ts +49 -0
- package/dist/triggers/PageExitTrigger.d.ts +74 -0
- package/dist/triggers/PageLoadTrigger.d.ts +37 -0
- package/dist/triggers/PinManager.d.ts +131 -0
- package/dist/triggers/ScrollTrigger.d.ts +103 -0
- package/dist/triggers/TriggerManager.d.ts +133 -0
- package/dist/types/index.d.ts +355 -0
- package/dist/types/public.d.ts +7 -0
- package/dist/utils/ColorParser.d.ts +23 -0
- package/dist/utils/DrawSVGParser.d.ts +62 -0
- package/dist/utils/FilterParser.d.ts +49 -0
- package/dist/utils/MotionUtils.d.ts +136 -0
- package/dist/utils/PathParser.d.ts +89 -0
- package/dist/utils/PositionParser.d.ts +24 -0
- package/dist/utils/PropertyParser.d.ts +159 -0
- package/dist/utils/QuickSetter.d.ts +16 -0
- package/dist/utils/ScrollPositionParser.d.ts +19 -0
- package/dist/utils/StyleReset.d.ts +73 -0
- package/dist/utils/TargetResolver.d.ts +23 -0
- package/dist/utils/TextSplitter.d.ts +90 -0
- package/dist/utils/executeTimelineAction.d.ts +18 -0
- package/dist/utils/getLayoutRect.d.ts +10 -0
- package/package.json +56 -0
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PathParser - Parse and animate elements along SVG paths
|
|
3
|
+
*
|
|
4
|
+
* Handles:
|
|
5
|
+
* - CSS selector to existing <path> element
|
|
6
|
+
* - Direct Element reference
|
|
7
|
+
* - Raw SVG path data string (starting with M/m)
|
|
8
|
+
* - Position and angle calculation along path
|
|
9
|
+
* - Alignment offset calculation
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* Point on a path with position and angle
|
|
13
|
+
*/
|
|
14
|
+
export interface PathPoint {
|
|
15
|
+
x: number;
|
|
16
|
+
y: number;
|
|
17
|
+
angle: number;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Parsed path data ready for animation
|
|
21
|
+
*/
|
|
22
|
+
export interface ParsedPathData {
|
|
23
|
+
pathData: string;
|
|
24
|
+
length: number;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Check if a string is raw SVG path data (starts with M or m command)
|
|
28
|
+
*/
|
|
29
|
+
export declare function isPathData(value: string): boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Resolve path target to path data string
|
|
32
|
+
*
|
|
33
|
+
* @param target - CSS selector, Element, or raw path data
|
|
34
|
+
* @returns Path data string or null if not found
|
|
35
|
+
*/
|
|
36
|
+
export declare function resolvePathData(target: string | Element): string | null;
|
|
37
|
+
/**
|
|
38
|
+
* Get the total length of a path
|
|
39
|
+
* Results are cached per path data string
|
|
40
|
+
*/
|
|
41
|
+
export declare function getPathLength(pathData: string): number;
|
|
42
|
+
/**
|
|
43
|
+
* Clear the path length cache
|
|
44
|
+
* Call when path data changes dynamically
|
|
45
|
+
*/
|
|
46
|
+
export declare function clearPathLengthCache(): void;
|
|
47
|
+
/**
|
|
48
|
+
* Get a point on the path at a given progress (0-1)
|
|
49
|
+
*
|
|
50
|
+
* @param pathData - SVG path data string
|
|
51
|
+
* @param progress - Position on path (0-1)
|
|
52
|
+
* @param calculateAngle - Whether to calculate rotation angle
|
|
53
|
+
* @returns Point with x, y, and angle
|
|
54
|
+
*/
|
|
55
|
+
export declare function getPointAtProgress(pathData: string, progress: number, calculateAngle?: boolean): PathPoint;
|
|
56
|
+
/**
|
|
57
|
+
* Calculate the offset for the animated element itself
|
|
58
|
+
* This is used to position the element's center (or specified origin) on the path
|
|
59
|
+
*
|
|
60
|
+
* @param element - The element being animated (selector, Element, or undefined)
|
|
61
|
+
* @param alignAt - Origin point as [x%, y%], default [50, 50] (center)
|
|
62
|
+
* @returns Offset to subtract from path position
|
|
63
|
+
*/
|
|
64
|
+
export declare function calculateElementOffset(element: string | Element | undefined, alignAt?: [number, number]): {
|
|
65
|
+
x: number;
|
|
66
|
+
y: number;
|
|
67
|
+
};
|
|
68
|
+
/**
|
|
69
|
+
* Calculate offset to position path relative to an align element
|
|
70
|
+
* The path's first point (M command) will be positioned at the align element's center
|
|
71
|
+
*
|
|
72
|
+
* @param align - Element or selector to align the path to
|
|
73
|
+
* @param pathData - SVG path data string
|
|
74
|
+
* @param animatedElement - The element being animated (to calculate relative offset)
|
|
75
|
+
* @returns Offset to add to path coordinates
|
|
76
|
+
*/
|
|
77
|
+
export declare function calculatePathAlignOffset(align: string | Element | undefined, pathData: string, animatedElement?: Element): {
|
|
78
|
+
x: number;
|
|
79
|
+
y: number;
|
|
80
|
+
};
|
|
81
|
+
/**
|
|
82
|
+
* Parse a path configuration and prepare it for animation
|
|
83
|
+
*/
|
|
84
|
+
export declare function parsePath(target: string | Element, align?: string | Element, alignAt?: [number, number]): ParsedPathData | null;
|
|
85
|
+
/**
|
|
86
|
+
* Cleanup function - removes hidden SVG from DOM
|
|
87
|
+
* Call when SDK is destroyed or for testing cleanup
|
|
88
|
+
*/
|
|
89
|
+
export declare function cleanupPathParser(): void;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PositionParser - Parse timeline position parameters
|
|
3
|
+
*
|
|
4
|
+
* Supports:
|
|
5
|
+
* - Number: absolute time (e.g., 2)
|
|
6
|
+
* - "+=0.5": relative to current end (0.5s after)
|
|
7
|
+
* - "-=0.5": relative to current end (0.5s before, overlap)
|
|
8
|
+
* - "<": start of previous animation
|
|
9
|
+
* - ">": end of previous animation
|
|
10
|
+
* - "<0.5" or "<+0.5": start of previous + offset
|
|
11
|
+
* - "<-0.5": start of previous - offset
|
|
12
|
+
* - ">0.5" or ">+0.5": end of previous + offset
|
|
13
|
+
* - ">-0.5": end of previous - offset
|
|
14
|
+
*/
|
|
15
|
+
export declare class PositionParser {
|
|
16
|
+
/**
|
|
17
|
+
* Parse position parameter and return absolute time
|
|
18
|
+
* @param position Position parameter (string or number)
|
|
19
|
+
* @param currentEnd Current end time of timeline
|
|
20
|
+
* @param previousStart Start time of previous child
|
|
21
|
+
* @param previousEnd End time of previous child
|
|
22
|
+
*/
|
|
23
|
+
static parse(position: string | number | undefined, currentEnd: number, previousStart: number, previousEnd: number): number;
|
|
24
|
+
}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PropertyParser - Parse and normalize animation properties
|
|
3
|
+
*
|
|
4
|
+
* Handles:
|
|
5
|
+
* - Transform shortcuts (x, y, rotate, scale, etc.)
|
|
6
|
+
* - Relative values (+=, -=, *=, /=)
|
|
7
|
+
* - Unit parsing and defaulting
|
|
8
|
+
* - Color parsing (hex, rgb, hsl, named, CSS variables) - OPTIONAL
|
|
9
|
+
* - Filter parsing (blur, brightness, contrast, etc.) - OPTIONAL
|
|
10
|
+
* - DrawSVG parsing (SVG stroke animations) - OPTIONAL
|
|
11
|
+
*
|
|
12
|
+
* Optional parsers are loaded conditionally via SDKRegistry.
|
|
13
|
+
* If a parser is not loaded, those property types will be skipped.
|
|
14
|
+
*/
|
|
15
|
+
import type { AnimationTarget } from '../types';
|
|
16
|
+
import type { ParsedFilterFunction } from './FilterParser';
|
|
17
|
+
import type { ParsedDrawSVG } from './DrawSVGParser';
|
|
18
|
+
/**
|
|
19
|
+
* Valid property value types for animation
|
|
20
|
+
*/
|
|
21
|
+
export type PropertyValue = number | string;
|
|
22
|
+
/**
|
|
23
|
+
* Base fields shared by all parsed property types
|
|
24
|
+
*/
|
|
25
|
+
interface ParsedPropertyBase {
|
|
26
|
+
property: string;
|
|
27
|
+
isTransform: boolean;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Scalar property (numbers with units)
|
|
31
|
+
*/
|
|
32
|
+
interface ParsedScalarProperty extends ParsedPropertyBase {
|
|
33
|
+
type: 'scalar';
|
|
34
|
+
startValue: number;
|
|
35
|
+
endValue: number;
|
|
36
|
+
unit: string;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Color property (RGBA values)
|
|
40
|
+
*/
|
|
41
|
+
interface ParsedColorProperty extends ParsedPropertyBase {
|
|
42
|
+
type: 'color';
|
|
43
|
+
startColor: Float32Array;
|
|
44
|
+
endColor: Float32Array;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Filter property (CSS filters)
|
|
48
|
+
*/
|
|
49
|
+
interface ParsedFilterProperty extends ParsedPropertyBase {
|
|
50
|
+
type: 'filter';
|
|
51
|
+
startFilters: ParsedFilterFunction[];
|
|
52
|
+
endFilters: ParsedFilterFunction[];
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* DrawSVG property (SVG stroke animation)
|
|
56
|
+
*/
|
|
57
|
+
interface ParsedDrawSVGProperty extends ParsedPropertyBase {
|
|
58
|
+
type: 'drawSVG';
|
|
59
|
+
startDraw: ParsedDrawSVG;
|
|
60
|
+
endDraw: ParsedDrawSVG;
|
|
61
|
+
length: number;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Path property (motion along SVG path)
|
|
65
|
+
*/
|
|
66
|
+
interface ParsedPathProperty extends ParsedPropertyBase {
|
|
67
|
+
type: 'path';
|
|
68
|
+
pathData: string;
|
|
69
|
+
pathLength: number;
|
|
70
|
+
startProgress: number;
|
|
71
|
+
endProgress: number;
|
|
72
|
+
rotate: boolean;
|
|
73
|
+
alignOffset: {
|
|
74
|
+
x: number;
|
|
75
|
+
y: number;
|
|
76
|
+
};
|
|
77
|
+
pathOffset: {
|
|
78
|
+
x: number;
|
|
79
|
+
y: number;
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Discriminated union of all parsed property types
|
|
84
|
+
*/
|
|
85
|
+
export type ParsedProperty = ParsedScalarProperty | ParsedColorProperty | ParsedFilterProperty | ParsedDrawSVGProperty | ParsedPathProperty;
|
|
86
|
+
/**
|
|
87
|
+
* Check if a property is a transform property
|
|
88
|
+
*/
|
|
89
|
+
export declare function isTransformProp(prop: string): boolean;
|
|
90
|
+
/**
|
|
91
|
+
* Check if a property is a color property
|
|
92
|
+
*/
|
|
93
|
+
export declare function isColorProp(prop: string): boolean;
|
|
94
|
+
/**
|
|
95
|
+
* Check if a property is the filter property
|
|
96
|
+
*/
|
|
97
|
+
export declare function isFilterProp(prop: string): boolean;
|
|
98
|
+
/**
|
|
99
|
+
* Check if a property is the drawSVG property
|
|
100
|
+
*/
|
|
101
|
+
export declare function isDrawSVGProp(prop: string): boolean;
|
|
102
|
+
/**
|
|
103
|
+
* Check if a property is the path property (motion path)
|
|
104
|
+
*/
|
|
105
|
+
export declare function isPathProp(prop: string): boolean;
|
|
106
|
+
/**
|
|
107
|
+
* Check if a property is a CSS variable (custom property)
|
|
108
|
+
*/
|
|
109
|
+
export declare function isCSSVariable(prop: string): boolean;
|
|
110
|
+
/**
|
|
111
|
+
* Check if a value looks like a color (for CSS variable type detection)
|
|
112
|
+
*/
|
|
113
|
+
export declare function looksLikeColor(value: PropertyValue): boolean;
|
|
114
|
+
/**
|
|
115
|
+
* Parse a property value and extract numeric value and unit
|
|
116
|
+
*/
|
|
117
|
+
export declare function parseValue(value: PropertyValue): {
|
|
118
|
+
value: number;
|
|
119
|
+
unit: string;
|
|
120
|
+
};
|
|
121
|
+
/**
|
|
122
|
+
* Get the default unit for a property
|
|
123
|
+
*/
|
|
124
|
+
export declare function getDefaultUnit(prop: string): string;
|
|
125
|
+
/**
|
|
126
|
+
* Get the current computed value of a property from a target
|
|
127
|
+
* Handles both DOM Elements and plain objects
|
|
128
|
+
*/
|
|
129
|
+
export declare function getCurrentValue(target: AnimationTarget, prop: string): number;
|
|
130
|
+
/**
|
|
131
|
+
* Get the original CSS value AND unit of a property (excluding inline styles)
|
|
132
|
+
* Returns both value and unit to preserve the original CSS unit (%, rem, em, vh, etc.)
|
|
133
|
+
*/
|
|
134
|
+
export declare function getOriginalCSSValueWithUnit(target: Element, prop: string): {
|
|
135
|
+
value: number;
|
|
136
|
+
unit: string;
|
|
137
|
+
};
|
|
138
|
+
/**
|
|
139
|
+
* Convert camelCase to kebab-case
|
|
140
|
+
*/
|
|
141
|
+
export declare function camelToKebab(str: string): string;
|
|
142
|
+
/**
|
|
143
|
+
* Check if a value is relative (+=, -=, *=, /=)
|
|
144
|
+
*/
|
|
145
|
+
export declare function isRelativeValue(value: PropertyValue): boolean;
|
|
146
|
+
/**
|
|
147
|
+
* Get relative operator from value string
|
|
148
|
+
*/
|
|
149
|
+
export declare function getRelativeOperator(value: string): '+=' | '-=' | '*=' | '/=' | null;
|
|
150
|
+
/**
|
|
151
|
+
* Calculate relative end value
|
|
152
|
+
*/
|
|
153
|
+
export declare function calculateRelativeValue(startValue: number, relativeValue: number, operator: '+=' | '-=' | '*=' | '/='): number;
|
|
154
|
+
/**
|
|
155
|
+
* Parse a property for animation
|
|
156
|
+
* Handles both DOM Elements and plain objects
|
|
157
|
+
*/
|
|
158
|
+
export declare function parseProperty(target: AnimationTarget, prop: string, targetValue: PropertyValue, fromValue?: PropertyValue): ParsedProperty;
|
|
159
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* QuickSetter - High-performance property setter for per-frame updates
|
|
3
|
+
*
|
|
4
|
+
* Bypasses the full animation pipeline for maximum speed.
|
|
5
|
+
* Used by CursorTrigger for smooth position tracking.
|
|
6
|
+
*/
|
|
7
|
+
export type QuickSetterFn = (value: number) => void;
|
|
8
|
+
/**
|
|
9
|
+
* Create a high-performance property setter for per-frame updates.
|
|
10
|
+
* Returns a function that sets the value directly without animation overhead.
|
|
11
|
+
*
|
|
12
|
+
* @param target - The element to animate
|
|
13
|
+
* @param property - CSS property name (camelCase)
|
|
14
|
+
* @param unit - Unit to append (default: 'px' for transforms, '' for others)
|
|
15
|
+
*/
|
|
16
|
+
export declare function createQuickSetter(target: Element, property: string, unit?: string): QuickSetterFn;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ScrollPositionParser
|
|
3
|
+
*
|
|
4
|
+
* Shared utility for parsing scroll trigger position values.
|
|
5
|
+
* Used by ScrollTrigger and MarkerManager.
|
|
6
|
+
*
|
|
7
|
+
* Supports:
|
|
8
|
+
* - Keywords: top, center, bottom
|
|
9
|
+
* - Keywords with offsets: top+100px, center-50%, bottom+20vh
|
|
10
|
+
* - Units: px, %, vh, vw
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* Parse a position value into pixels
|
|
14
|
+
* @param value - Position string (e.g., "top", "center", "50%", "100px", "top+100px")
|
|
15
|
+
* @param referenceSize - Reference size for percentage calculations (element height)
|
|
16
|
+
* @param viewportHeight - Viewport height for vh calculations
|
|
17
|
+
* @param viewportWidth - Viewport width for vw calculations (optional)
|
|
18
|
+
*/
|
|
19
|
+
export declare function parseScrollPosition(value: string, referenceSize: number, viewportHeight: number, viewportWidth?: number): number;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* StyleReset - Clear animation-related inline styles from elements
|
|
3
|
+
*
|
|
4
|
+
* Only clears styles that our SDK has animated or set for pinning,
|
|
5
|
+
* preserving user's original inline styles.
|
|
6
|
+
* Uses registries to track which CSS properties have been set by the SDK.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Register that a CSS property has been animated on an element.
|
|
10
|
+
* Call this when setting inline styles during animation.
|
|
11
|
+
*/
|
|
12
|
+
export declare function registerAnimatedProp(element: Element, prop: string): void;
|
|
13
|
+
/**
|
|
14
|
+
* Register multiple animated properties at once.
|
|
15
|
+
*/
|
|
16
|
+
export declare function registerAnimatedProps(element: Element, props: string[]): void;
|
|
17
|
+
/**
|
|
18
|
+
* Get all CSS properties that have been animated on an element.
|
|
19
|
+
*/
|
|
20
|
+
export declare function getAnimatedProps(element: Element): Set<string>;
|
|
21
|
+
/**
|
|
22
|
+
* Clear tracking for an element (called after Motion.reset).
|
|
23
|
+
*/
|
|
24
|
+
export declare function clearAnimatedPropsRegistry(element: Element): void;
|
|
25
|
+
/**
|
|
26
|
+
* Clear specific animation properties from an element's inline styles.
|
|
27
|
+
* Only clears the properties specified, preserving other inline styles.
|
|
28
|
+
*
|
|
29
|
+
* @param element - The element to clear styles from
|
|
30
|
+
* @param props - Animation property names to clear (e.g., 'x', 'opacity', 'backgroundColor')
|
|
31
|
+
*/
|
|
32
|
+
export declare function clearAnimationStylesForProps(element: Element, props: string[]): void;
|
|
33
|
+
/**
|
|
34
|
+
* Clear all animation-related inline styles that our SDK has set on an element.
|
|
35
|
+
* Only clears properties tracked in the registry, preserving user's original inline styles.
|
|
36
|
+
*/
|
|
37
|
+
export declare function clearAnimationStyles(element: Element): void;
|
|
38
|
+
/**
|
|
39
|
+
* Clear animation styles and remove from registry (full reset).
|
|
40
|
+
* Use this for Motion.reset() to completely clean up.
|
|
41
|
+
*/
|
|
42
|
+
export declare function clearAnimationStylesAndUnregister(element: Element): void;
|
|
43
|
+
/**
|
|
44
|
+
* Clear animation styles from multiple elements
|
|
45
|
+
*/
|
|
46
|
+
export declare function clearAnimationStylesAll(elements: Element[]): void;
|
|
47
|
+
/**
|
|
48
|
+
* Register that a pin-related CSS property has been set on an element.
|
|
49
|
+
* Call this when PinManager sets styles during pinning.
|
|
50
|
+
*/
|
|
51
|
+
export declare function registerPinnedProp(element: Element, prop: string): void;
|
|
52
|
+
/**
|
|
53
|
+
* Register multiple pinned properties at once.
|
|
54
|
+
*/
|
|
55
|
+
export declare function registerPinnedProps(element: Element, props: string[]): void;
|
|
56
|
+
/**
|
|
57
|
+
* Get all pin-related CSS properties that have been set on an element.
|
|
58
|
+
*/
|
|
59
|
+
export declare function getPinnedProps(element: Element): Set<string>;
|
|
60
|
+
/**
|
|
61
|
+
* Clear tracking for pinned properties on an element.
|
|
62
|
+
*/
|
|
63
|
+
export declare function clearPinnedPropsRegistry(element: Element): void;
|
|
64
|
+
/**
|
|
65
|
+
* Clear pin-related inline styles that our SDK has set on an element.
|
|
66
|
+
* Only clears properties tracked in the pin registry.
|
|
67
|
+
*/
|
|
68
|
+
export declare function clearPinStyles(element: Element): void;
|
|
69
|
+
/**
|
|
70
|
+
* Clear pin styles and remove from registry.
|
|
71
|
+
* Use this for Motion.reset() to completely clean up pin styles.
|
|
72
|
+
*/
|
|
73
|
+
export declare function clearPinStylesAndUnregister(element: Element): void;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TargetResolver - Convert various target formats to AnimationTarget array
|
|
3
|
+
*
|
|
4
|
+
* Supports both DOM elements and plain JS objects for universal animation.
|
|
5
|
+
*/
|
|
6
|
+
import type { AnimationTarget, TargetInput } from '../types';
|
|
7
|
+
/**
|
|
8
|
+
* Execute callback when DOM is ready
|
|
9
|
+
* If DOM is already ready, executes immediately
|
|
10
|
+
*/
|
|
11
|
+
export declare function whenDOMReady(callback: () => void): void;
|
|
12
|
+
/**
|
|
13
|
+
* Check if a resolved target is a DOM Element
|
|
14
|
+
* Used for caching _isElement flag in PropTween
|
|
15
|
+
* Also recognizes mock elements (objects with 'style' property) in test environments
|
|
16
|
+
*/
|
|
17
|
+
export declare function isElement(target: AnimationTarget): target is Element;
|
|
18
|
+
/**
|
|
19
|
+
* Resolve animation targets to an array of AnimationTargets
|
|
20
|
+
* @param targets - CSS selector, string[], Element, NodeList, Element[], plain object, or object array
|
|
21
|
+
* @returns Array of resolved AnimationTargets (Element or ObjectTarget)
|
|
22
|
+
*/
|
|
23
|
+
export declare function resolveTargets(targets: TargetInput): AnimationTarget[];
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TextSplitter - Split text into animatable elements
|
|
3
|
+
*
|
|
4
|
+
* Splits text content into chars, words, or lines wrapped in spans.
|
|
5
|
+
* Supports nested splitting (e.g., 'chars,words' = words containing char spans).
|
|
6
|
+
*
|
|
7
|
+
* Preserves existing element structure — inline elements like
|
|
8
|
+
* `<span class="accent">word</span>` keep their wrapper and styling.
|
|
9
|
+
* Only text nodes are replaced with split spans.
|
|
10
|
+
*
|
|
11
|
+
* Usage:
|
|
12
|
+
* const elements = TextSplitter.split(element, 'chars');
|
|
13
|
+
* const elements = TextSplitter.split(element, 'words');
|
|
14
|
+
* const elements = TextSplitter.split(element, 'chars,words');
|
|
15
|
+
*
|
|
16
|
+
* Revert:
|
|
17
|
+
* TextSplitter.revert(element);
|
|
18
|
+
*/
|
|
19
|
+
import type { SplitType } from '../types';
|
|
20
|
+
export type { SplitType };
|
|
21
|
+
export interface SplitOptions {
|
|
22
|
+
/** Wrap each split element in a parent with overflow:hidden for clip-reveal effects */
|
|
23
|
+
mask?: boolean;
|
|
24
|
+
}
|
|
25
|
+
interface SplitResult {
|
|
26
|
+
chars: HTMLElement[];
|
|
27
|
+
words: HTMLElement[];
|
|
28
|
+
lines: HTMLElement[];
|
|
29
|
+
elements: HTMLElement[];
|
|
30
|
+
}
|
|
31
|
+
export declare class TextSplitter {
|
|
32
|
+
/**
|
|
33
|
+
* Split text content into animatable elements
|
|
34
|
+
*/
|
|
35
|
+
static split(element: Element, type: SplitType, options?: SplitOptions): HTMLElement[];
|
|
36
|
+
/**
|
|
37
|
+
* Split text nodes into word spans, preserving existing element wrappers.
|
|
38
|
+
* Recurses into child elements so `<span class="accent">word</span>` keeps
|
|
39
|
+
* its wrapper and the text inside is split within it.
|
|
40
|
+
*/
|
|
41
|
+
private static _splitWordsDom;
|
|
42
|
+
/**
|
|
43
|
+
* Split text nodes into character spans, preserving existing element wrappers.
|
|
44
|
+
*/
|
|
45
|
+
private static _splitCharsDom;
|
|
46
|
+
/**
|
|
47
|
+
* Split text nodes into word spans containing character spans.
|
|
48
|
+
* Preserves existing element wrappers.
|
|
49
|
+
*/
|
|
50
|
+
private static _splitWordsWithCharsDom;
|
|
51
|
+
/**
|
|
52
|
+
* Split with line detection (requires layout measurement).
|
|
53
|
+
*
|
|
54
|
+
* Strategy:
|
|
55
|
+
* 1. DOM-walk to split into word spans (preserving element wrappers)
|
|
56
|
+
* 2. Measure each word span's vertical position to group into lines
|
|
57
|
+
* 3. Wrap each line group in a line span
|
|
58
|
+
*/
|
|
59
|
+
private static _splitWithLinesDom;
|
|
60
|
+
/**
|
|
61
|
+
* Wrap each split element in a parent with overflow:hidden for clip-reveal.
|
|
62
|
+
* The wrapper clips content so animating y:'100%' creates a reveal effect.
|
|
63
|
+
*/
|
|
64
|
+
private static _applyMaskWrappers;
|
|
65
|
+
/**
|
|
66
|
+
* Revert element to original content
|
|
67
|
+
*/
|
|
68
|
+
static revert(element: Element): boolean;
|
|
69
|
+
/**
|
|
70
|
+
* Check if element has been split
|
|
71
|
+
*/
|
|
72
|
+
static isSplit(element: Element): boolean;
|
|
73
|
+
/**
|
|
74
|
+
* Get split result for an element
|
|
75
|
+
*/
|
|
76
|
+
static getResult(element: Element): SplitResult | undefined;
|
|
77
|
+
/**
|
|
78
|
+
* Get the chain of wrapper elements between a word span and the root element.
|
|
79
|
+
* Returns outermost-first order (root's direct child → … → word's parent).
|
|
80
|
+
*/
|
|
81
|
+
private static _getWrapperChain;
|
|
82
|
+
/**
|
|
83
|
+
* Serialize an element's opening tag, preserving all attributes (class, style, data-*, etc).
|
|
84
|
+
*/
|
|
85
|
+
private static _openTag;
|
|
86
|
+
/**
|
|
87
|
+
* Escape HTML special characters
|
|
88
|
+
*/
|
|
89
|
+
private static _escapeHtml;
|
|
90
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Minimal interface for timeline playback control.
|
|
3
|
+
* Using an interface instead of importing Timeline directly to avoid circular dependencies
|
|
4
|
+
* (utils/ never imports from core/).
|
|
5
|
+
*/
|
|
6
|
+
export interface PlaybackTarget {
|
|
7
|
+
play(): unknown;
|
|
8
|
+
pause(): unknown;
|
|
9
|
+
reverse(): unknown;
|
|
10
|
+
restart(): unknown;
|
|
11
|
+
progress(value: number): unknown;
|
|
12
|
+
}
|
|
13
|
+
export type TimelineAction = 'play' | 'pause' | 'resume' | 'reverse' | 'restart' | 'reset' | 'complete' | 'none';
|
|
14
|
+
/**
|
|
15
|
+
* Execute a GSAP-compatible timeline action. Maps action strings to method calls.
|
|
16
|
+
* Covers all 8 GSAP toggleActions keywords.
|
|
17
|
+
*/
|
|
18
|
+
export declare function executeTimelineAction(action: TimelineAction, timeline: PlaybackTarget): void;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns the element's bounding rect as if no CSS transform were applied.
|
|
3
|
+
* Temporarily strips the inline transform, measures, then restores it.
|
|
4
|
+
* This gives us the "layout" position in the document flow.
|
|
5
|
+
*
|
|
6
|
+
* Used by ScrollTrigger and MarkerManager to compute trigger positions and
|
|
7
|
+
* marker placements relative to the element's original layout position,
|
|
8
|
+
* regardless of any animation transforms currently applied.
|
|
9
|
+
*/
|
|
10
|
+
export declare function getLayoutRect(element: Element): DOMRect;
|
package/package.json
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@motion.page/sdk",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "High-performance CSS animation SDK with scroll, hover, gesture, and cursor triggers",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"module": "dist/index.js",
|
|
8
|
+
"types": "dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.js",
|
|
13
|
+
"require": "./dist/index.cjs"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist"
|
|
18
|
+
],
|
|
19
|
+
"scripts": {
|
|
20
|
+
"build": "rm -rf dist && tsc -p tsconfig.build.json && bun build src/index.ts --outdir dist --minify --sourcemap=linked && mkdir -p dist/.cjs-tmp && bun build src/index.ts --outdir dist/.cjs-tmp --format=cjs --minify --sourcemap=linked && mv dist/.cjs-tmp/index.js dist/index.cjs && mv dist/.cjs-tmp/index.js.map dist/index.cjs.map && rm -rf dist/.cjs-tmp",
|
|
21
|
+
"test": "bun test",
|
|
22
|
+
"test:parity": "bun test tests/parity",
|
|
23
|
+
"test:bench": "bun test --bench",
|
|
24
|
+
"typecheck": "tsc --noEmit"
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"@happy-dom/global-registrator": "^15.0.0",
|
|
28
|
+
"@types/bun": "latest",
|
|
29
|
+
"@types/jsdom": "^27.0.0",
|
|
30
|
+
"esbuild": "^0.27.2",
|
|
31
|
+
"jsdom": "^27.3.0",
|
|
32
|
+
"typescript": "^5.3.0"
|
|
33
|
+
},
|
|
34
|
+
"peerDependencies": {},
|
|
35
|
+
"keywords": [
|
|
36
|
+
"animation",
|
|
37
|
+
"gsap",
|
|
38
|
+
"tween",
|
|
39
|
+
"timeline",
|
|
40
|
+
"motion",
|
|
41
|
+
"css",
|
|
42
|
+
"transform"
|
|
43
|
+
],
|
|
44
|
+
"author": "Motion.page",
|
|
45
|
+
"license": "SEE LICENSE IN LICENSE",
|
|
46
|
+
"repository": {
|
|
47
|
+
"type": "git",
|
|
48
|
+
"url": "https://github.com/nicDamours/motion.page",
|
|
49
|
+
"directory": "packages/sdk"
|
|
50
|
+
},
|
|
51
|
+
"homepage": "https://motion.page",
|
|
52
|
+
"engines": {
|
|
53
|
+
"node": ">=18"
|
|
54
|
+
},
|
|
55
|
+
"sideEffects": true
|
|
56
|
+
}
|