rtl-text-transform 0.0.0-stage → 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.
@@ -0,0 +1,261 @@
1
+ type EasingFunction = (t: number) => number;
2
+ /** Linear fallback, useful as an explicit opt-out. */
3
+ declare function linear(t: number): number;
4
+ /**
5
+ * CSS-style cubic-bezier easing.
6
+ *
7
+ * X control points are clamped to 0..1 so the curve remains a function of time.
8
+ * Y values are left untouched for the caller to clamp if its property needs it.
9
+ */
10
+ declare function cubicBezier(x1: number, y1: number, x2: number, y2: number): EasingFunction;
11
+ /** Smooth symmetric curve for the overall morph. */
12
+ declare const easeInOutCubic: EasingFunction;
13
+ /** Decelerating curve for entering and exiting hunks. */
14
+ declare const easeOutCubic: EasingFunction;
15
+
16
+ type MorphDirection = "rtl" | "ltr" | "auto";
17
+ type RiseFlow = "up" | "down" | "left" | "right";
18
+ interface RiseFlowHunk {
19
+ /** Stable id for the changed chunk. */
20
+ id: string;
21
+ /** Added text enters; removed text exits. */
22
+ kind: "add" | "remove";
23
+ text: string;
24
+ /** Source offset in the side's text. */
25
+ start: number;
26
+ end: number;
27
+ /** Length of the side's text. */
28
+ length: number;
29
+ /** 0 at the start of the line, 1 at the end. */
30
+ position: number;
31
+ }
32
+ interface RiseFlowContext {
33
+ from: string;
34
+ to: string;
35
+ dir: MorphDirection;
36
+ rtl: boolean;
37
+ hunk: RiseFlowHunk;
38
+ }
39
+ type RiseFlowResolver = (context: RiseFlowContext) => RiseFlow;
40
+ type RiseFlowValue = RiseFlow | RiseFlowResolver;
41
+ type PresetName = "numbers" | "wordsHorizontal" | "wordsUp" | "wordsDown";
42
+ type MotionName = "default" | "smooth" | "snappy" | "gentle";
43
+ type MorphCallback = (from: string, to: string) => void;
44
+ interface GooEffectOptions {
45
+ /** Blur strength in em, scaled by the host's computed font size. */
46
+ blur?: number;
47
+ /** Alpha threshold T in "0 0 0 255 -T". Clamped to 0–255. */
48
+ threshold?: number;
49
+ /** Keep the SVG filter mounted while the text is at rest. */
50
+ atRest?: boolean;
51
+ }
52
+ interface RiseEffectOptions {
53
+ /** Motion blur strength in em. Applied on top of the goo blur. */
54
+ blur?: number;
55
+ /** Vertical travel in em. */
56
+ travel?: number;
57
+ /** Scale at the start of an entering hunk. */
58
+ scale?: number;
59
+ /** Delay between neighbouring hunks, in milliseconds. */
60
+ stagger?: number;
61
+ /** Fraction of the entering window that overlaps the outgoing hunk. */
62
+ overlap?: number;
63
+ /** Timing curve for each hunk's enter and exit progress. */
64
+ easing?: EasingFunction;
65
+ /**
66
+ * Direction of travel. `up`: outgoing hunks leave upward and new hunks
67
+ * arrive from below. `left`: outgoing hunks leave left and new hunks arrive
68
+ * from the right. A function resolves the direction per changed hunk.
69
+ */
70
+ flow?: RiseFlowValue;
71
+ /** Matched runs shorter than this are treated as changed text. */
72
+ minChunk?: number;
73
+ /** Treat Arabic/Persian kaf/yeh as the same letter for diffing. */
74
+ normalizeVariants?: boolean;
75
+ /** Do not let combining marks prevent a match. */
76
+ ignoreDiacritics?: boolean;
77
+ }
78
+ interface MorphEffects {
79
+ /** Defaults to enabled with the standard goo settings. */
80
+ goo?: boolean | GooEffectOptions;
81
+ /** Defaults to disabled. */
82
+ rise?: boolean | RiseEffectOptions;
83
+ }
84
+ interface MorphOptions {
85
+ /** Optional auto-cycling list. The first entry is shown immediately. */
86
+ words?: string[];
87
+ /** Length of one morph, in seconds. */
88
+ morphTime?: number;
89
+ /** Rest between automatic morphs, in seconds. */
90
+ restTime?: number;
91
+ effects?: MorphEffects;
92
+ /** Content preset. See `presets`. */
93
+ preset?: PresetName;
94
+ /** Motion preset. Defaults to `default` when a content preset is used. */
95
+ motion?: MotionName;
96
+ dir?: MorphDirection;
97
+ lang?: string;
98
+ /** Start cycling `words` automatically. Defaults to true. */
99
+ autoplay?: boolean;
100
+ /** Wrap around at the end of `words`. Defaults to true. */
101
+ loop?: boolean;
102
+ /**
103
+ * Timing curve for the overall morph and matched-text FLIP. Defaults to
104
+ * ease-in-out cubic. Pass `t => t` for linear motion.
105
+ */
106
+ easing?: EasingFunction;
107
+ onMorphStart?: MorphCallback;
108
+ onMorphEnd?: MorphCallback;
109
+ }
110
+ interface Morph {
111
+ /** Morph from the current visual state to a new string. */
112
+ setText(text: string): Promise<void>;
113
+ /** Advance to the next entry in `words`. */
114
+ next(): Promise<void>;
115
+ setWords(words: string[]): void;
116
+ play(): void;
117
+ pause(): void;
118
+ destroy(): void;
119
+ update(partialOptions: Partial<MorphOptions>): void;
120
+ }
121
+
122
+ /**
123
+ * Create a unified RTL text morph attached to `el`.
124
+ *
125
+ * The host is treated as a dedicated container. Its children are replaced by
126
+ * two aria-hidden layers and one visually hidden live region; original content
127
+ * is restored by `destroy()`.
128
+ */
129
+ declare function createMorph(el: HTMLElement, options?: MorphOptions): Morph;
130
+
131
+ /**
132
+ * Normalise Persian, Arabic-Indic and Latin digits, then return the first
133
+ * numeric value in the string. Used by the numbers preset.
134
+ */
135
+ declare function firstNumber(value: string): number | undefined;
136
+ /**
137
+ * Numbers: up when the value increases, down when it decreases. Equal or
138
+ * unparseable values fall back to up.
139
+ */
140
+ declare function flowByNumberChange(context: RiseFlowContext): RiseFlow;
141
+ /**
142
+ * Words: move every changed hunk toward the edge it belongs to. The exact
143
+ * centre belongs to the end side. RTL flips the physical left/right mapping.
144
+ */
145
+ declare function flowByHunkPosition(context: RiseFlowContext): RiseFlow;
146
+ declare const presets: {
147
+ numbers: {
148
+ effects: {
149
+ goo: {
150
+ blur: number;
151
+ threshold: number;
152
+ atRest: boolean;
153
+ };
154
+ rise: {
155
+ blur: number;
156
+ travel: number;
157
+ scale: number;
158
+ flow: typeof flowByNumberChange;
159
+ };
160
+ };
161
+ };
162
+ wordsHorizontal: {
163
+ effects: {
164
+ goo: {
165
+ blur: number;
166
+ threshold: number;
167
+ atRest: boolean;
168
+ };
169
+ rise: {
170
+ flow: typeof flowByHunkPosition;
171
+ blur: number;
172
+ travel: number;
173
+ scale: number;
174
+ };
175
+ };
176
+ };
177
+ wordsUp: {
178
+ effects: {
179
+ goo: {
180
+ blur: number;
181
+ threshold: number;
182
+ atRest: boolean;
183
+ };
184
+ rise: {
185
+ flow: "up";
186
+ blur: number;
187
+ travel: number;
188
+ scale: number;
189
+ };
190
+ };
191
+ };
192
+ wordsDown: {
193
+ effects: {
194
+ goo: {
195
+ blur: number;
196
+ threshold: number;
197
+ atRest: boolean;
198
+ };
199
+ rise: {
200
+ flow: "down";
201
+ blur: number;
202
+ travel: number;
203
+ scale: number;
204
+ };
205
+ };
206
+ };
207
+ };
208
+ declare const motions: {
209
+ default: {
210
+ morphTime: number;
211
+ easing: EasingFunction;
212
+ effects: {
213
+ rise: {
214
+ easing: EasingFunction;
215
+ stagger: number;
216
+ overlap: number;
217
+ };
218
+ };
219
+ };
220
+ smooth: {
221
+ morphTime: number;
222
+ easing: EasingFunction;
223
+ effects: {
224
+ rise: {
225
+ easing: EasingFunction;
226
+ stagger: number;
227
+ overlap: number;
228
+ };
229
+ };
230
+ };
231
+ snappy: {
232
+ morphTime: number;
233
+ easing: EasingFunction;
234
+ effects: {
235
+ rise: {
236
+ easing: EasingFunction;
237
+ stagger: number;
238
+ overlap: number;
239
+ };
240
+ };
241
+ };
242
+ gentle: {
243
+ morphTime: number;
244
+ easing: EasingFunction;
245
+ effects: {
246
+ rise: {
247
+ easing: EasingFunction;
248
+ stagger: number;
249
+ overlap: number;
250
+ };
251
+ };
252
+ };
253
+ };
254
+ declare const presetNames: PresetName[];
255
+ declare const motionNames: MotionName[];
256
+ /**
257
+ * Resolve a named content preset with optional motion and inline overrides.
258
+ */
259
+ declare function resolvePreset(name: PresetName, overrides?: MorphOptions): MorphOptions;
260
+
261
+ export { type EasingFunction, type GooEffectOptions, type Morph, type MorphCallback, type MorphDirection, type MorphEffects, type MorphOptions, type MotionName, type PresetName, type RiseEffectOptions, type RiseFlow, type RiseFlowContext, type RiseFlowHunk, type RiseFlowResolver, type RiseFlowValue, createMorph, cubicBezier, easeInOutCubic, easeOutCubic, firstNumber, flowByHunkPosition, flowByNumberChange, linear, motionNames, motions, presetNames, presets, resolvePreset };
@@ -0,0 +1,261 @@
1
+ type EasingFunction = (t: number) => number;
2
+ /** Linear fallback, useful as an explicit opt-out. */
3
+ declare function linear(t: number): number;
4
+ /**
5
+ * CSS-style cubic-bezier easing.
6
+ *
7
+ * X control points are clamped to 0..1 so the curve remains a function of time.
8
+ * Y values are left untouched for the caller to clamp if its property needs it.
9
+ */
10
+ declare function cubicBezier(x1: number, y1: number, x2: number, y2: number): EasingFunction;
11
+ /** Smooth symmetric curve for the overall morph. */
12
+ declare const easeInOutCubic: EasingFunction;
13
+ /** Decelerating curve for entering and exiting hunks. */
14
+ declare const easeOutCubic: EasingFunction;
15
+
16
+ type MorphDirection = "rtl" | "ltr" | "auto";
17
+ type RiseFlow = "up" | "down" | "left" | "right";
18
+ interface RiseFlowHunk {
19
+ /** Stable id for the changed chunk. */
20
+ id: string;
21
+ /** Added text enters; removed text exits. */
22
+ kind: "add" | "remove";
23
+ text: string;
24
+ /** Source offset in the side's text. */
25
+ start: number;
26
+ end: number;
27
+ /** Length of the side's text. */
28
+ length: number;
29
+ /** 0 at the start of the line, 1 at the end. */
30
+ position: number;
31
+ }
32
+ interface RiseFlowContext {
33
+ from: string;
34
+ to: string;
35
+ dir: MorphDirection;
36
+ rtl: boolean;
37
+ hunk: RiseFlowHunk;
38
+ }
39
+ type RiseFlowResolver = (context: RiseFlowContext) => RiseFlow;
40
+ type RiseFlowValue = RiseFlow | RiseFlowResolver;
41
+ type PresetName = "numbers" | "wordsHorizontal" | "wordsUp" | "wordsDown";
42
+ type MotionName = "default" | "smooth" | "snappy" | "gentle";
43
+ type MorphCallback = (from: string, to: string) => void;
44
+ interface GooEffectOptions {
45
+ /** Blur strength in em, scaled by the host's computed font size. */
46
+ blur?: number;
47
+ /** Alpha threshold T in "0 0 0 255 -T". Clamped to 0–255. */
48
+ threshold?: number;
49
+ /** Keep the SVG filter mounted while the text is at rest. */
50
+ atRest?: boolean;
51
+ }
52
+ interface RiseEffectOptions {
53
+ /** Motion blur strength in em. Applied on top of the goo blur. */
54
+ blur?: number;
55
+ /** Vertical travel in em. */
56
+ travel?: number;
57
+ /** Scale at the start of an entering hunk. */
58
+ scale?: number;
59
+ /** Delay between neighbouring hunks, in milliseconds. */
60
+ stagger?: number;
61
+ /** Fraction of the entering window that overlaps the outgoing hunk. */
62
+ overlap?: number;
63
+ /** Timing curve for each hunk's enter and exit progress. */
64
+ easing?: EasingFunction;
65
+ /**
66
+ * Direction of travel. `up`: outgoing hunks leave upward and new hunks
67
+ * arrive from below. `left`: outgoing hunks leave left and new hunks arrive
68
+ * from the right. A function resolves the direction per changed hunk.
69
+ */
70
+ flow?: RiseFlowValue;
71
+ /** Matched runs shorter than this are treated as changed text. */
72
+ minChunk?: number;
73
+ /** Treat Arabic/Persian kaf/yeh as the same letter for diffing. */
74
+ normalizeVariants?: boolean;
75
+ /** Do not let combining marks prevent a match. */
76
+ ignoreDiacritics?: boolean;
77
+ }
78
+ interface MorphEffects {
79
+ /** Defaults to enabled with the standard goo settings. */
80
+ goo?: boolean | GooEffectOptions;
81
+ /** Defaults to disabled. */
82
+ rise?: boolean | RiseEffectOptions;
83
+ }
84
+ interface MorphOptions {
85
+ /** Optional auto-cycling list. The first entry is shown immediately. */
86
+ words?: string[];
87
+ /** Length of one morph, in seconds. */
88
+ morphTime?: number;
89
+ /** Rest between automatic morphs, in seconds. */
90
+ restTime?: number;
91
+ effects?: MorphEffects;
92
+ /** Content preset. See `presets`. */
93
+ preset?: PresetName;
94
+ /** Motion preset. Defaults to `default` when a content preset is used. */
95
+ motion?: MotionName;
96
+ dir?: MorphDirection;
97
+ lang?: string;
98
+ /** Start cycling `words` automatically. Defaults to true. */
99
+ autoplay?: boolean;
100
+ /** Wrap around at the end of `words`. Defaults to true. */
101
+ loop?: boolean;
102
+ /**
103
+ * Timing curve for the overall morph and matched-text FLIP. Defaults to
104
+ * ease-in-out cubic. Pass `t => t` for linear motion.
105
+ */
106
+ easing?: EasingFunction;
107
+ onMorphStart?: MorphCallback;
108
+ onMorphEnd?: MorphCallback;
109
+ }
110
+ interface Morph {
111
+ /** Morph from the current visual state to a new string. */
112
+ setText(text: string): Promise<void>;
113
+ /** Advance to the next entry in `words`. */
114
+ next(): Promise<void>;
115
+ setWords(words: string[]): void;
116
+ play(): void;
117
+ pause(): void;
118
+ destroy(): void;
119
+ update(partialOptions: Partial<MorphOptions>): void;
120
+ }
121
+
122
+ /**
123
+ * Create a unified RTL text morph attached to `el`.
124
+ *
125
+ * The host is treated as a dedicated container. Its children are replaced by
126
+ * two aria-hidden layers and one visually hidden live region; original content
127
+ * is restored by `destroy()`.
128
+ */
129
+ declare function createMorph(el: HTMLElement, options?: MorphOptions): Morph;
130
+
131
+ /**
132
+ * Normalise Persian, Arabic-Indic and Latin digits, then return the first
133
+ * numeric value in the string. Used by the numbers preset.
134
+ */
135
+ declare function firstNumber(value: string): number | undefined;
136
+ /**
137
+ * Numbers: up when the value increases, down when it decreases. Equal or
138
+ * unparseable values fall back to up.
139
+ */
140
+ declare function flowByNumberChange(context: RiseFlowContext): RiseFlow;
141
+ /**
142
+ * Words: move every changed hunk toward the edge it belongs to. The exact
143
+ * centre belongs to the end side. RTL flips the physical left/right mapping.
144
+ */
145
+ declare function flowByHunkPosition(context: RiseFlowContext): RiseFlow;
146
+ declare const presets: {
147
+ numbers: {
148
+ effects: {
149
+ goo: {
150
+ blur: number;
151
+ threshold: number;
152
+ atRest: boolean;
153
+ };
154
+ rise: {
155
+ blur: number;
156
+ travel: number;
157
+ scale: number;
158
+ flow: typeof flowByNumberChange;
159
+ };
160
+ };
161
+ };
162
+ wordsHorizontal: {
163
+ effects: {
164
+ goo: {
165
+ blur: number;
166
+ threshold: number;
167
+ atRest: boolean;
168
+ };
169
+ rise: {
170
+ flow: typeof flowByHunkPosition;
171
+ blur: number;
172
+ travel: number;
173
+ scale: number;
174
+ };
175
+ };
176
+ };
177
+ wordsUp: {
178
+ effects: {
179
+ goo: {
180
+ blur: number;
181
+ threshold: number;
182
+ atRest: boolean;
183
+ };
184
+ rise: {
185
+ flow: "up";
186
+ blur: number;
187
+ travel: number;
188
+ scale: number;
189
+ };
190
+ };
191
+ };
192
+ wordsDown: {
193
+ effects: {
194
+ goo: {
195
+ blur: number;
196
+ threshold: number;
197
+ atRest: boolean;
198
+ };
199
+ rise: {
200
+ flow: "down";
201
+ blur: number;
202
+ travel: number;
203
+ scale: number;
204
+ };
205
+ };
206
+ };
207
+ };
208
+ declare const motions: {
209
+ default: {
210
+ morphTime: number;
211
+ easing: EasingFunction;
212
+ effects: {
213
+ rise: {
214
+ easing: EasingFunction;
215
+ stagger: number;
216
+ overlap: number;
217
+ };
218
+ };
219
+ };
220
+ smooth: {
221
+ morphTime: number;
222
+ easing: EasingFunction;
223
+ effects: {
224
+ rise: {
225
+ easing: EasingFunction;
226
+ stagger: number;
227
+ overlap: number;
228
+ };
229
+ };
230
+ };
231
+ snappy: {
232
+ morphTime: number;
233
+ easing: EasingFunction;
234
+ effects: {
235
+ rise: {
236
+ easing: EasingFunction;
237
+ stagger: number;
238
+ overlap: number;
239
+ };
240
+ };
241
+ };
242
+ gentle: {
243
+ morphTime: number;
244
+ easing: EasingFunction;
245
+ effects: {
246
+ rise: {
247
+ easing: EasingFunction;
248
+ stagger: number;
249
+ overlap: number;
250
+ };
251
+ };
252
+ };
253
+ };
254
+ declare const presetNames: PresetName[];
255
+ declare const motionNames: MotionName[];
256
+ /**
257
+ * Resolve a named content preset with optional motion and inline overrides.
258
+ */
259
+ declare function resolvePreset(name: PresetName, overrides?: MorphOptions): MorphOptions;
260
+
261
+ export { type EasingFunction, type GooEffectOptions, type Morph, type MorphCallback, type MorphDirection, type MorphEffects, type MorphOptions, type MotionName, type PresetName, type RiseEffectOptions, type RiseFlow, type RiseFlowContext, type RiseFlowHunk, type RiseFlowResolver, type RiseFlowValue, createMorph, cubicBezier, easeInOutCubic, easeOutCubic, firstNumber, flowByHunkPosition, flowByNumberChange, linear, motionNames, motions, presetNames, presets, resolvePreset };
package/dist/index.js ADDED
@@ -0,0 +1,3 @@
1
+ export { createMorph, cubicBezier, easeInOutCubic, easeOutCubic, firstNumber, flowByHunkPosition, flowByNumberChange, linear, motionNames, motions, presetNames, presets, resolvePreset } from './chunk-QDWUKRPS.js';
2
+ //# sourceMappingURL=index.js.map
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}