@motion.page/sdk 1.0.4 → 1.0.6

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.
@@ -35,8 +35,9 @@ interface DrawSVGParserFunctions {
35
35
  interface TextSplitterFunctions {
36
36
  split: (element: Element, type: SplitType, options?: {
37
37
  mask?: boolean;
38
+ consumer?: object;
38
39
  }) => HTMLElement[];
39
- revert: (element: Element) => boolean;
40
+ revert: (element: Element, consumer?: object) => boolean;
40
41
  isSplit: (element: Element) => boolean;
41
42
  }
42
43
  interface StyleResetFunctions {
@@ -166,9 +166,12 @@ export declare class PinManager {
166
166
  * Auto-detection rules (when pinSpacing is undefined or true):
167
167
  * - Body pin: scroll room is handled via documentElement height, not a spacer.
168
168
  * Return false so the (non-existent) spacer gets no extra padding/margin.
169
- * - Flex parent: GSAP parity — a flex container reflows automatically around a
170
- * fixed child via the spacer's dimensions; extra padding would double-count.
171
169
  * - Everything else: default to 'padding' (adds pinDistance as padding-bottom).
170
+ * Works reliably in both flex and non-flex contexts with content-box sizing.
171
+ *
172
+ * Flex-aware behavior is handled separately in setup() by adding flex-shrink: 0
173
+ * to the spacer when inside a flex container, preventing the flex algorithm from
174
+ * collapsing the spacer below its needed size (GSAP-compatible).
172
175
  */
173
176
  private _resolvePinSpacing;
174
177
  /**
@@ -15,12 +15,21 @@
15
15
  *
16
16
  * Revert:
17
17
  * TextSplitter.revert(element);
18
+ * TextSplitter.revert(element, consumer); // reference-counted
18
19
  */
19
20
  import type { SplitType } from '../types';
20
21
  export type { SplitType };
21
22
  export interface SplitOptions {
22
23
  /** Wrap each split element in a parent with overflow:hidden for clip-reveal effects */
23
24
  mask?: boolean;
25
+ /**
26
+ * Opaque token identifying the caller (e.g. an AnimationBuilder instance).
27
+ * When provided, splits are reference-counted: the DOM is only reverted once
28
+ * all registered consumers release their claim via revert(element, consumer).
29
+ * A second consumer on the same element triggers a smart DOM upgrade (nesting)
30
+ * rather than destroying the first consumer's spans.
31
+ */
32
+ consumer?: object;
24
33
  }
25
34
  interface SplitResult {
26
35
  chars: HTMLElement[];
@@ -30,9 +39,45 @@ interface SplitResult {
30
39
  }
31
40
  export declare class TextSplitter {
32
41
  /**
33
- * Split text content into animatable elements
42
+ * Split text content into animatable elements.
43
+ *
44
+ * When `options.consumer` is provided the split is reference-counted.
45
+ * A second consumer on the same element will have the DOM upgraded
46
+ * (chars nested inside existing word spans, or word-wraps promoted to
47
+ * word spans) rather than reverted and rebuilt, so the first consumer's
48
+ * DOM references remain valid.
49
+ *
50
+ * Without a consumer token the function behaves exactly like before:
51
+ * any existing split is reverted and a fresh split is performed.
34
52
  */
35
53
  static split(element: Element, type: SplitType, options?: SplitOptions): HTMLElement[];
54
+ /**
55
+ * Attempt to upgrade an existing split to satisfy a new type request without
56
+ * destroying existing DOM references.
57
+ *
58
+ * Returns the appropriate span array on success, or null if the upgrade is
59
+ * not possible (caller must fall back to a full revert + re-split).
60
+ */
61
+ private static _tryUpgrade;
62
+ /**
63
+ * Return the appropriate span array from a SplitResult for the requested type.
64
+ * Chars have highest priority, then words, then lines.
65
+ */
66
+ private static _getSpansForType;
67
+ /**
68
+ * Build a combined data-split attribute value from existing and requested types,
69
+ * ordered as: lines, words, chars (broadest → most granular).
70
+ */
71
+ private static _buildTypeString;
72
+ /**
73
+ * Walk a word span's text nodes and replace them with individual char spans,
74
+ * appending each new span to the provided `chars` array.
75
+ *
76
+ * Used when upgrading an existing 'words' split to include 'chars'.
77
+ * The word span itself is NOT moved or recreated — only its text node
78
+ * children are swapped out, so existing references to the word span remain valid.
79
+ */
80
+ private static _nestCharsInElement;
36
81
  /**
37
82
  * Split text nodes into word spans, preserving existing element wrappers.
38
83
  * Recurses into child elements so `<span class="accent">word</span>` keeps
@@ -76,9 +121,17 @@ export declare class TextSplitter {
76
121
  */
77
122
  private static _propagateGradientText;
78
123
  /**
79
- * Revert element to original content
124
+ * Revert element to original content.
125
+ *
126
+ * When `consumer` is provided the revert is reference-counted: the DOM is
127
+ * only restored once all registered consumers have released via this method.
128
+ * If the consumer is the last one (or no consumer tracking is active), the
129
+ * element's innerHTML is restored to the pre-split original immediately.
130
+ *
131
+ * Without `consumer` (legacy / forced revert), the DOM is restored regardless
132
+ * of how many consumers are still registered. All consumer refs are cleared.
80
133
  */
81
- static revert(element: Element): boolean;
134
+ static revert(element: Element, consumer?: object): boolean;
82
135
  /**
83
136
  * Check if element has been split
84
137
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@motion.page/sdk",
3
- "version": "1.0.4",
3
+ "version": "1.0.6",
4
4
  "description": "High-performance CSS animation SDK with scroll, hover, gesture, and cursor triggers",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",