@react-native-motion-kit/text-motion 0.0.0-stage → 0.1.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/CHANGELOG.md +14 -0
- package/LICENSE +20 -0
- package/README.ko.md +104 -0
- package/README.md +103 -2
- package/lib/module/accessibility/index.js +4 -0
- package/lib/module/accessibility/index.js.map +1 -0
- package/lib/module/accessibility/policies.js +39 -0
- package/lib/module/accessibility/policies.js.map +1 -0
- package/lib/module/controls/brand.js +4 -0
- package/lib/module/controls/brand.js.map +1 -0
- package/lib/module/controls/controls.js +28 -0
- package/lib/module/controls/controls.js.map +1 -0
- package/lib/module/controls/descriptors.js +55 -0
- package/lib/module/controls/descriptors.js.map +1 -0
- package/lib/module/controls/index.js +4 -0
- package/lib/module/controls/index.js.map +1 -0
- package/lib/module/effects/compose.js +48 -0
- package/lib/module/effects/compose.js.map +1 -0
- package/lib/module/effects/fade.js +15 -0
- package/lib/module/effects/fade.js.map +1 -0
- package/lib/module/effects/index.js +12 -0
- package/lib/module/effects/index.js.map +1 -0
- package/lib/module/effects/lineReveal.js +17 -0
- package/lib/module/effects/lineReveal.js.map +1 -0
- package/lib/module/effects/pulse.js +14 -0
- package/lib/module/effects/pulse.js.map +1 -0
- package/lib/module/effects/rise.js +14 -0
- package/lib/module/effects/rise.js.map +1 -0
- package/lib/module/effects/scale.js +15 -0
- package/lib/module/effects/scale.js.map +1 -0
- package/lib/module/effects/shake.js +14 -0
- package/lib/module/effects/shake.js.map +1 -0
- package/lib/module/effects/slide.js +15 -0
- package/lib/module/effects/slide.js.map +1 -0
- package/lib/module/effects/typewriter.js +19 -0
- package/lib/module/effects/typewriter.js.map +1 -0
- package/lib/module/effects/validation.js +10 -0
- package/lib/module/effects/validation.js.map +1 -0
- package/lib/module/index.js +10 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/module/presets/index.js +35 -0
- package/lib/module/presets/index.js.map +1 -0
- package/lib/module/recipe/component.js +60 -0
- package/lib/module/recipe/component.js.map +1 -0
- package/lib/module/recipe/defineTextMotion.js +9 -0
- package/lib/module/recipe/defineTextMotion.js.map +1 -0
- package/lib/module/recipe/descriptors.js +60 -0
- package/lib/module/recipe/descriptors.js.map +1 -0
- package/lib/module/recipe/index.js +5 -0
- package/lib/module/recipe/index.js.map +1 -0
- package/lib/module/recipe/recipe.js +163 -0
- package/lib/module/recipe/recipe.js.map +1 -0
- package/lib/module/renderers/index.js +5 -0
- package/lib/module/renderers/index.js.map +1 -0
- package/lib/module/renderers/nativeText.js +494 -0
- package/lib/module/renderers/nativeText.js.map +1 -0
- package/lib/module/renderers/nativeTextControls.js +96 -0
- package/lib/module/renderers/nativeTextControls.js.map +1 -0
- package/lib/module/renderers/nativeTextLineLayout.js +290 -0
- package/lib/module/renderers/nativeTextLineLayout.js.map +1 -0
- package/lib/module/renderers/nativeTextPlayback.js +91 -0
- package/lib/module/renderers/nativeTextPlayback.js.map +1 -0
- package/lib/module/renderers/overlayText.js +543 -0
- package/lib/module/renderers/overlayText.js.map +1 -0
- package/lib/module/renderers/overlayTextLayout.js +182 -0
- package/lib/module/renderers/overlayTextLayout.js.map +1 -0
- package/lib/module/renderers/rendererMotion.js +264 -0
- package/lib/module/renderers/rendererMotion.js.map +1 -0
- package/lib/module/split/createToken.js +19 -0
- package/lib/module/split/createToken.js.map +1 -0
- package/lib/module/split/custom.js +57 -0
- package/lib/module/split/custom.js.map +1 -0
- package/lib/module/split/graphemes.js +25 -0
- package/lib/module/split/graphemes.js.map +1 -0
- package/lib/module/split/index.js +7 -0
- package/lib/module/split/index.js.map +1 -0
- package/lib/module/split/lines.js +43 -0
- package/lib/module/split/lines.js.map +1 -0
- package/lib/module/split/segmenter.js +74 -0
- package/lib/module/split/segmenter.js.map +1 -0
- package/lib/module/split/words.js +28 -0
- package/lib/module/split/words.js.map +1 -0
- package/lib/module/timeline/index.js +7 -0
- package/lib/module/timeline/index.js.map +1 -0
- package/lib/module/timeline/parallel.js +21 -0
- package/lib/module/timeline/parallel.js.map +1 -0
- package/lib/module/timeline/sequence.js +18 -0
- package/lib/module/timeline/sequence.js.map +1 -0
- package/lib/module/timeline/stagger.js +43 -0
- package/lib/module/timeline/stagger.js.map +1 -0
- package/lib/module/timeline/validation.js +24 -0
- package/lib/module/timeline/validation.js.map +1 -0
- package/lib/module/timeline/wave.js +25 -0
- package/lib/module/timeline/wave.js.map +1 -0
- package/lib/module/types/index.js +4 -0
- package/lib/module/types/index.js.map +1 -0
- package/lib/module/types/recipe.js +4 -0
- package/lib/module/types/recipe.js.map +1 -0
- package/lib/module/types/renderer.js +27 -0
- package/lib/module/types/renderer.js.map +1 -0
- package/lib/module/types/token.js +2 -0
- package/lib/module/types/token.js.map +1 -0
- package/lib/typescript/package.json +1 -0
- package/lib/typescript/src/accessibility/index.d.ts +2 -0
- package/lib/typescript/src/accessibility/index.d.ts.map +1 -0
- package/lib/typescript/src/accessibility/policies.d.ts +13 -0
- package/lib/typescript/src/accessibility/policies.d.ts.map +1 -0
- package/lib/typescript/src/controls/brand.d.ts +2 -0
- package/lib/typescript/src/controls/brand.d.ts.map +1 -0
- package/lib/typescript/src/controls/controls.d.ts +28 -0
- package/lib/typescript/src/controls/controls.d.ts.map +1 -0
- package/lib/typescript/src/controls/descriptors.d.ts +14 -0
- package/lib/typescript/src/controls/descriptors.d.ts.map +1 -0
- package/lib/typescript/src/controls/index.d.ts +3 -0
- package/lib/typescript/src/controls/index.d.ts.map +1 -0
- package/lib/typescript/src/effects/compose.d.ts +11 -0
- package/lib/typescript/src/effects/compose.d.ts.map +1 -0
- package/lib/typescript/src/effects/fade.d.ts +10 -0
- package/lib/typescript/src/effects/fade.d.ts.map +1 -0
- package/lib/typescript/src/effects/index.d.ts +10 -0
- package/lib/typescript/src/effects/index.d.ts.map +1 -0
- package/lib/typescript/src/effects/lineReveal.d.ts +11 -0
- package/lib/typescript/src/effects/lineReveal.d.ts.map +1 -0
- package/lib/typescript/src/effects/pulse.d.ts +8 -0
- package/lib/typescript/src/effects/pulse.d.ts.map +1 -0
- package/lib/typescript/src/effects/rise.d.ts +8 -0
- package/lib/typescript/src/effects/rise.d.ts.map +1 -0
- package/lib/typescript/src/effects/scale.d.ts +10 -0
- package/lib/typescript/src/effects/scale.d.ts.map +1 -0
- package/lib/typescript/src/effects/shake.d.ts +8 -0
- package/lib/typescript/src/effects/shake.d.ts.map +1 -0
- package/lib/typescript/src/effects/slide.d.ts +10 -0
- package/lib/typescript/src/effects/slide.d.ts.map +1 -0
- package/lib/typescript/src/effects/typewriter.d.ts +13 -0
- package/lib/typescript/src/effects/typewriter.d.ts.map +1 -0
- package/lib/typescript/src/effects/validation.d.ts +2 -0
- package/lib/typescript/src/effects/validation.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +15 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/lib/typescript/src/presets/index.d.ts +10 -0
- package/lib/typescript/src/presets/index.d.ts.map +1 -0
- package/lib/typescript/src/recipe/component.d.ts +3 -0
- package/lib/typescript/src/recipe/component.d.ts.map +1 -0
- package/lib/typescript/src/recipe/defineTextMotion.d.ts +4 -0
- package/lib/typescript/src/recipe/defineTextMotion.d.ts.map +1 -0
- package/lib/typescript/src/recipe/descriptors.d.ts +15 -0
- package/lib/typescript/src/recipe/descriptors.d.ts.map +1 -0
- package/lib/typescript/src/recipe/index.d.ts +4 -0
- package/lib/typescript/src/recipe/index.d.ts.map +1 -0
- package/lib/typescript/src/recipe/recipe.d.ts +67 -0
- package/lib/typescript/src/recipe/recipe.d.ts.map +1 -0
- package/lib/typescript/src/renderers/index.d.ts +3 -0
- package/lib/typescript/src/renderers/index.d.ts.map +1 -0
- package/lib/typescript/src/renderers/nativeText.d.ts +13 -0
- package/lib/typescript/src/renderers/nativeText.d.ts.map +1 -0
- package/lib/typescript/src/renderers/nativeTextControls.d.ts +16 -0
- package/lib/typescript/src/renderers/nativeTextControls.d.ts.map +1 -0
- package/lib/typescript/src/renderers/nativeTextLineLayout.d.ts +84 -0
- package/lib/typescript/src/renderers/nativeTextLineLayout.d.ts.map +1 -0
- package/lib/typescript/src/renderers/nativeTextPlayback.d.ts +21 -0
- package/lib/typescript/src/renderers/nativeTextPlayback.d.ts.map +1 -0
- package/lib/typescript/src/renderers/overlayText.d.ts +13 -0
- package/lib/typescript/src/renderers/overlayText.d.ts.map +1 -0
- package/lib/typescript/src/renderers/overlayTextLayout.d.ts +36 -0
- package/lib/typescript/src/renderers/overlayTextLayout.d.ts.map +1 -0
- package/lib/typescript/src/renderers/rendererMotion.d.ts +53 -0
- package/lib/typescript/src/renderers/rendererMotion.d.ts.map +1 -0
- package/lib/typescript/src/split/createToken.d.ts +11 -0
- package/lib/typescript/src/split/createToken.d.ts.map +1 -0
- package/lib/typescript/src/split/custom.d.ts +17 -0
- package/lib/typescript/src/split/custom.d.ts.map +1 -0
- package/lib/typescript/src/split/graphemes.d.ts +4 -0
- package/lib/typescript/src/split/graphemes.d.ts.map +1 -0
- package/lib/typescript/src/split/index.d.ts +5 -0
- package/lib/typescript/src/split/index.d.ts.map +1 -0
- package/lib/typescript/src/split/lines.d.ts +4 -0
- package/lib/typescript/src/split/lines.d.ts.map +1 -0
- package/lib/typescript/src/split/segmenter.d.ts +18 -0
- package/lib/typescript/src/split/segmenter.d.ts.map +1 -0
- package/lib/typescript/src/split/words.d.ts +4 -0
- package/lib/typescript/src/split/words.d.ts.map +1 -0
- package/lib/typescript/src/timeline/index.d.ts +5 -0
- package/lib/typescript/src/timeline/index.d.ts.map +1 -0
- package/lib/typescript/src/timeline/parallel.d.ts +4 -0
- package/lib/typescript/src/timeline/parallel.d.ts.map +1 -0
- package/lib/typescript/src/timeline/sequence.d.ts +4 -0
- package/lib/typescript/src/timeline/sequence.d.ts.map +1 -0
- package/lib/typescript/src/timeline/stagger.d.ts +11 -0
- package/lib/typescript/src/timeline/stagger.d.ts.map +1 -0
- package/lib/typescript/src/timeline/validation.d.ts +4 -0
- package/lib/typescript/src/timeline/validation.d.ts.map +1 -0
- package/lib/typescript/src/timeline/wave.d.ts +11 -0
- package/lib/typescript/src/timeline/wave.d.ts.map +1 -0
- package/lib/typescript/src/types/index.d.ts +6 -0
- package/lib/typescript/src/types/index.d.ts.map +1 -0
- package/lib/typescript/src/types/recipe.d.ts +123 -0
- package/lib/typescript/src/types/recipe.d.ts.map +1 -0
- package/lib/typescript/src/types/renderer.d.ts +51 -0
- package/lib/typescript/src/types/renderer.d.ts.map +1 -0
- package/lib/typescript/src/types/token.d.ts +35 -0
- package/lib/typescript/src/types/token.d.ts.map +1 -0
- package/package.json +117 -3
- package/src/accessibility/index.ts +7 -0
- package/src/accessibility/policies.ts +60 -0
- package/src/controls/brand.ts +3 -0
- package/src/controls/controls.ts +41 -0
- package/src/controls/descriptors.ts +83 -0
- package/src/controls/index.ts +2 -0
- package/src/effects/compose.ts +98 -0
- package/src/effects/fade.ts +22 -0
- package/src/effects/index.ts +9 -0
- package/src/effects/lineReveal.ts +28 -0
- package/src/effects/pulse.ts +19 -0
- package/src/effects/rise.ts +19 -0
- package/src/effects/scale.ts +22 -0
- package/src/effects/shake.ts +19 -0
- package/src/effects/slide.ts +22 -0
- package/src/effects/typewriter.ts +16 -0
- package/src/effects/validation.ts +9 -0
- package/src/index.tsx +46 -0
- package/src/presets/index.ts +42 -0
- package/src/recipe/component.tsx +88 -0
- package/src/recipe/defineTextMotion.ts +6 -0
- package/src/recipe/descriptors.ts +158 -0
- package/src/recipe/index.ts +3 -0
- package/src/recipe/recipe.ts +359 -0
- package/src/renderers/index.ts +2 -0
- package/src/renderers/nativeText.tsx +813 -0
- package/src/renderers/nativeTextControls.ts +131 -0
- package/src/renderers/nativeTextLineLayout.ts +495 -0
- package/src/renderers/nativeTextPlayback.ts +204 -0
- package/src/renderers/overlayText.tsx +945 -0
- package/src/renderers/overlayTextLayout.ts +312 -0
- package/src/renderers/rendererMotion.ts +483 -0
- package/src/split/createToken.ts +26 -0
- package/src/split/custom.ts +92 -0
- package/src/split/graphemes.ts +27 -0
- package/src/split/index.ts +9 -0
- package/src/split/lines.ts +35 -0
- package/src/split/segmenter.ts +111 -0
- package/src/split/words.ts +28 -0
- package/src/timeline/index.ts +4 -0
- package/src/timeline/parallel.ts +30 -0
- package/src/timeline/sequence.ts +29 -0
- package/src/timeline/stagger.ts +60 -0
- package/src/timeline/validation.ts +29 -0
- package/src/timeline/wave.ts +34 -0
- package/src/types/index.ts +34 -0
- package/src/types/recipe.ts +195 -0
- package/src/types/renderer.ts +91 -0
- package/src/types/token.ts +39 -0
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const GEOMETRY_NOISE_STEP = 0.01;
|
|
4
|
+
const BAND_OVERLAP_TOLERANCE = 0.5;
|
|
5
|
+
function isRecord(value) {
|
|
6
|
+
return typeof value === 'object' && value !== null;
|
|
7
|
+
}
|
|
8
|
+
function isFallbackResult(value) {
|
|
9
|
+
return 'kind' in value;
|
|
10
|
+
}
|
|
11
|
+
function readPayloadRecord(payload) {
|
|
12
|
+
if (!isRecord(payload)) {
|
|
13
|
+
return undefined;
|
|
14
|
+
}
|
|
15
|
+
if ('lines' in payload) {
|
|
16
|
+
return payload;
|
|
17
|
+
}
|
|
18
|
+
const nestedPayload = payload.nativeEvent;
|
|
19
|
+
if (!isRecord(nestedPayload)) {
|
|
20
|
+
return payload;
|
|
21
|
+
}
|
|
22
|
+
return 'lines' in nestedPayload ? nestedPayload : readPayloadRecord(nestedPayload);
|
|
23
|
+
}
|
|
24
|
+
function normalizeFloat(value) {
|
|
25
|
+
const normalized = Math.round(value / GEOMETRY_NOISE_STEP) * GEOMETRY_NOISE_STEP;
|
|
26
|
+
return Object.is(normalized, -0) ? 0 : normalized;
|
|
27
|
+
}
|
|
28
|
+
function parseNativeLine(value) {
|
|
29
|
+
if (!isRecord(value)) {
|
|
30
|
+
return undefined;
|
|
31
|
+
}
|
|
32
|
+
return {
|
|
33
|
+
height: value.height,
|
|
34
|
+
text: value.text,
|
|
35
|
+
width: value.width,
|
|
36
|
+
x: value.x,
|
|
37
|
+
y: value.y
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
function parseNativeLines(values) {
|
|
41
|
+
const lines = values.map(parseNativeLine);
|
|
42
|
+
return lines.every(line => Boolean(line)) ? lines : undefined;
|
|
43
|
+
}
|
|
44
|
+
function readFiniteNumber(value) {
|
|
45
|
+
return typeof value === 'number' && Number.isFinite(value) ? normalizeFloat(value) : undefined;
|
|
46
|
+
}
|
|
47
|
+
function createGeometrySignature(lines) {
|
|
48
|
+
return JSON.stringify(lines.map(line => [line.index, line.x, line.y, line.width, line.height]));
|
|
49
|
+
}
|
|
50
|
+
function createTopologySignature(lines) {
|
|
51
|
+
return JSON.stringify(lines.map(line => [line.index, line.text, line.isStructuralBlank]));
|
|
52
|
+
}
|
|
53
|
+
function createReadyLayout(sourceText, lines) {
|
|
54
|
+
const motionLines = lines.filter(line => typeof line.motionIndex === 'number');
|
|
55
|
+
const geometrySignature = createGeometrySignature(lines);
|
|
56
|
+
const topologySignature = createTopologySignature(lines);
|
|
57
|
+
const playbackSignature = JSON.stringify([sourceText, topologySignature]);
|
|
58
|
+
return {
|
|
59
|
+
geometrySignature,
|
|
60
|
+
kind: 'ready',
|
|
61
|
+
lines,
|
|
62
|
+
motionCount: motionLines.length,
|
|
63
|
+
motionLines,
|
|
64
|
+
playbackSignature,
|
|
65
|
+
signature: `${topologySignature}::${geometrySignature}`,
|
|
66
|
+
topologySignature
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
function isMeaningfullyUnordered(previous, current) {
|
|
70
|
+
return Boolean(previous && current.y + BAND_OVERLAP_TOLERANCE < previous.y);
|
|
71
|
+
}
|
|
72
|
+
function isMeaningfullyOverlapping(previous, current) {
|
|
73
|
+
if (!previous) {
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
return current.y < previous.y + previous.height - BAND_OVERLAP_TOLERANCE;
|
|
77
|
+
}
|
|
78
|
+
export function compareOverlayTextLayouts(previous, next) {
|
|
79
|
+
if (!previous) {
|
|
80
|
+
return 'topology';
|
|
81
|
+
}
|
|
82
|
+
if (previous.signature === next.signature) {
|
|
83
|
+
return 'identical';
|
|
84
|
+
}
|
|
85
|
+
if (previous.topologySignature === next.topologySignature) {
|
|
86
|
+
return 'geometry';
|
|
87
|
+
}
|
|
88
|
+
return 'topology';
|
|
89
|
+
}
|
|
90
|
+
export function createOverlayTextLayout(source, payload) {
|
|
91
|
+
if (source.trim().length === 0) {
|
|
92
|
+
return {
|
|
93
|
+
kind: 'static',
|
|
94
|
+
reason: 'empty-source'
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
const payloadRecord = readPayloadRecord(payload);
|
|
98
|
+
if (!payloadRecord || !Array.isArray(payloadRecord.lines)) {
|
|
99
|
+
return {
|
|
100
|
+
kind: 'fallback',
|
|
101
|
+
reason: 'malformed-payload'
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
const parsedLines = parseNativeLines(payloadRecord.lines);
|
|
105
|
+
if (!parsedLines) {
|
|
106
|
+
return {
|
|
107
|
+
kind: 'fallback',
|
|
108
|
+
reason: 'malformed-payload'
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
const initial = {
|
|
112
|
+
lines: [],
|
|
113
|
+
motionIndex: 0
|
|
114
|
+
};
|
|
115
|
+
const normalized = parsedLines.reduce((accumulator, line, index) => {
|
|
116
|
+
if (isFallbackResult(accumulator)) {
|
|
117
|
+
return accumulator;
|
|
118
|
+
}
|
|
119
|
+
if (typeof line.text !== 'string') {
|
|
120
|
+
return {
|
|
121
|
+
kind: 'fallback',
|
|
122
|
+
reason: 'missing-line-text'
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
const x = readFiniteNumber(line.x);
|
|
126
|
+
const y = readFiniteNumber(line.y);
|
|
127
|
+
const width = readFiniteNumber(line.width);
|
|
128
|
+
const height = readFiniteNumber(line.height);
|
|
129
|
+
if (typeof x !== 'number' || typeof y !== 'number' || typeof width !== 'number' || typeof height !== 'number') {
|
|
130
|
+
return {
|
|
131
|
+
kind: 'fallback',
|
|
132
|
+
reason: 'non-finite-geometry'
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
const isStructuralBlank = line.text.trim().length === 0;
|
|
136
|
+
if (!isStructuralBlank && height <= 0) {
|
|
137
|
+
return {
|
|
138
|
+
kind: 'fallback',
|
|
139
|
+
reason: 'non-positive-visible-height'
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
const previous = accumulator.lines[accumulator.lines.length - 1];
|
|
143
|
+
const current = {
|
|
144
|
+
height,
|
|
145
|
+
index,
|
|
146
|
+
isStructuralBlank,
|
|
147
|
+
motionIndex: isStructuralBlank ? undefined : accumulator.motionIndex,
|
|
148
|
+
text: line.text,
|
|
149
|
+
width,
|
|
150
|
+
x,
|
|
151
|
+
y
|
|
152
|
+
};
|
|
153
|
+
if (isMeaningfullyUnordered(previous, current)) {
|
|
154
|
+
return {
|
|
155
|
+
kind: 'fallback',
|
|
156
|
+
reason: 'unordered-bands'
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
if (isMeaningfullyOverlapping(previous, current)) {
|
|
160
|
+
return {
|
|
161
|
+
kind: 'fallback',
|
|
162
|
+
reason: 'overlapping-bands'
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
return {
|
|
166
|
+
lines: [...accumulator.lines, current],
|
|
167
|
+
motionIndex: isStructuralBlank ? accumulator.motionIndex : accumulator.motionIndex + 1
|
|
168
|
+
};
|
|
169
|
+
}, initial);
|
|
170
|
+
if (isFallbackResult(normalized)) {
|
|
171
|
+
return normalized;
|
|
172
|
+
}
|
|
173
|
+
const ready = createReadyLayout(source, normalized.lines);
|
|
174
|
+
if (ready.motionCount > 0) {
|
|
175
|
+
return ready;
|
|
176
|
+
}
|
|
177
|
+
return {
|
|
178
|
+
kind: 'fallback',
|
|
179
|
+
reason: 'missing-visible-lines'
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
//# sourceMappingURL=overlayTextLayout.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["GEOMETRY_NOISE_STEP","BAND_OVERLAP_TOLERANCE","isRecord","value","isFallbackResult","readPayloadRecord","payload","undefined","nestedPayload","nativeEvent","normalizeFloat","normalized","Math","round","Object","is","parseNativeLine","height","text","width","x","y","parseNativeLines","values","lines","map","every","line","Boolean","readFiniteNumber","Number","isFinite","createGeometrySignature","JSON","stringify","index","createTopologySignature","isStructuralBlank","createReadyLayout","sourceText","motionLines","filter","motionIndex","geometrySignature","topologySignature","playbackSignature","kind","motionCount","length","signature","isMeaningfullyUnordered","previous","current","isMeaningfullyOverlapping","compareOverlayTextLayouts","next","createOverlayTextLayout","source","trim","reason","payloadRecord","Array","isArray","parsedLines","initial","reduce","accumulator","ready"],"sourceRoot":"../../../src","sources":["renderers/overlayTextLayout.ts"],"mappings":";;AA+DA,MAAMA,mBAAmB,GAAG,IAAI;AAChC,MAAMC,sBAAsB,GAAG,GAAG;AAElC,SAASC,QAAQA,CAACC,KAAc,EAAoC;EAClE,OAAO,OAAOA,KAAK,KAAK,QAAQ,IAAIA,KAAK,KAAK,IAAI;AACpD;AAEA,SAASC,gBAAgBA,CACvBD,KAAyD,EACrB;EACpC,OAAO,MAAM,IAAIA,KAAK;AACxB;AAEA,SAASE,iBAAiBA,CAACC,OAAgB,EAAuC;EAChF,IAAI,CAACJ,QAAQ,CAACI,OAAO,CAAC,EAAE;IACtB,OAAOC,SAAS;EAClB;EAEA,IAAI,OAAO,IAAID,OAAO,EAAE;IACtB,OAAOA,OAAO;EAChB;EAEA,MAAME,aAAa,GAAGF,OAAO,CAACG,WAAW;EAEzC,IAAI,CAACP,QAAQ,CAACM,aAAa,CAAC,EAAE;IAC5B,OAAOF,OAAO;EAChB;EAEA,OAAO,OAAO,IAAIE,aAAa,GAAGA,aAAa,GAAGH,iBAAiB,CAACG,aAAa,CAAC;AACpF;AA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C;IACH;IAEA,IAAIN,yBAAyB,CAACF,QAAQ,EAAEC,OAAO,CAAC,EAAE;MAChD,OAAO;QACLN,IAAI,EAAE,UAAU;QAChBa,MAAM,EAAE;MACV,CAAC;IACH;IAEA,OAAO;MACLnC,KAAK,EAAE,CAAC,GAAG0C,WAAW,CAAC1C,KAAK,EAAE4B,OAAO,CAAC;MACtCV,WAAW,EAAEL,iBAAiB,GAAG6B,WAAW,CAACxB,WAAW,GAAGwB,WAAW,CAACxB,WAAW,GAAG;IACvF,CAAC;EACH,CAAC,EACDsB,OACF,CAAC;EAED,IAAI5D,gBAAgB,CAACO,UAAU,CAAC,EAAE;IAChC,OAAOA,UAAU;EACnB;EAEA,MAAMwD,KAAK,GAAG7B,iBAAiB,CAACmB,MAAM,EAAE9C,UAAU,CAACa,KAAK,CAAC;EAEzD,IAAI2C,KAAK,CAACpB,WAAW,GAAG,CAAC,EAAE;IACzB,OAAOoB,KAAK;EACd;EAEA,OAAO;IACLrB,IAAI,EAAE,UAAU;IAChBa,MAAM,EAAE;EACV,CAAC;AACH","ignoreList":[]}
|
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { ReduceMotion, withDelay, withSpring, withTiming } from 'react-native-reanimated';
|
|
4
|
+
import { flattenTextMotionEffectDescriptors, readTextMotionTimelineDescriptor } from "../recipe/descriptors.js";
|
|
5
|
+
export const TEXT_MOTION_CONTROLLED_ITEM_TIMELINE_SPAN = 1;
|
|
6
|
+
const DEFAULT_STYLE_STATE = {
|
|
7
|
+
opacity: 1,
|
|
8
|
+
scale: 1,
|
|
9
|
+
translateX: 0,
|
|
10
|
+
translateY: 0
|
|
11
|
+
};
|
|
12
|
+
const REDUCE_MOTION_CONFIG_BY_POLICY = {
|
|
13
|
+
'final-state': ReduceMotion.Never,
|
|
14
|
+
system: ReduceMotion.System
|
|
15
|
+
};
|
|
16
|
+
const preserveStyleState = state => state;
|
|
17
|
+
const preserveNumber = value => value;
|
|
18
|
+
const effectStyleStateResolvers = {
|
|
19
|
+
typewriter() {
|
|
20
|
+
return {
|
|
21
|
+
revealOnStart: true
|
|
22
|
+
};
|
|
23
|
+
},
|
|
24
|
+
fade(effect) {
|
|
25
|
+
return {
|
|
26
|
+
initial: setStyleNumber('opacity', numberOption(effect.options, 'from', 0)),
|
|
27
|
+
target: setStyleNumber('opacity', numberOption(effect.options, 'to', 1))
|
|
28
|
+
};
|
|
29
|
+
},
|
|
30
|
+
lineReveal(effect) {
|
|
31
|
+
return {
|
|
32
|
+
initial: composeStyleTransforms(setStyleNumber('opacity', numberOption(effect.options, 'fromOpacity', 0)), mapStyleNumber('translateY', translateY => translateY + numberOption(effect.options, 'y', 16))),
|
|
33
|
+
target: preserveStyleState
|
|
34
|
+
};
|
|
35
|
+
},
|
|
36
|
+
pulse(effect) {
|
|
37
|
+
return {
|
|
38
|
+
pulseScale: scale => scale * numberOption(effect.options, 'scale', 1.04)
|
|
39
|
+
};
|
|
40
|
+
},
|
|
41
|
+
rise(effect) {
|
|
42
|
+
return {
|
|
43
|
+
initial: mapStyleNumber('translateY', translateY => translateY + numberOption(effect.options, 'y', 12)),
|
|
44
|
+
target: preserveStyleState
|
|
45
|
+
};
|
|
46
|
+
},
|
|
47
|
+
scale(effect) {
|
|
48
|
+
return {
|
|
49
|
+
initial: mapStyleNumber('scale', scale => scale * numberOption(effect.options, 'from', 0.96)),
|
|
50
|
+
target: mapStyleNumber('scale', scale => scale * numberOption(effect.options, 'to', 1))
|
|
51
|
+
};
|
|
52
|
+
},
|
|
53
|
+
shake(effect) {
|
|
54
|
+
return {
|
|
55
|
+
initial: mapStyleNumber('translateX', translateX => translateX + numberOption(effect.options, 'x', 4)),
|
|
56
|
+
target: preserveStyleState
|
|
57
|
+
};
|
|
58
|
+
},
|
|
59
|
+
slide(effect) {
|
|
60
|
+
return {
|
|
61
|
+
initial: composeStyleTransforms(mapStyleNumber('translateX', translateX => translateX + numberOption(effect.options, 'x', 0)), mapStyleNumber('translateY', translateY => translateY + numberOption(effect.options, 'y', 12))),
|
|
62
|
+
target: preserveStyleState
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
const overlayFrameEffectStyleStateResolvers = {
|
|
67
|
+
...effectStyleStateResolvers,
|
|
68
|
+
lineReveal(effect) {
|
|
69
|
+
return {
|
|
70
|
+
initial: setStyleNumber('opacity', numberOption(effect.options, 'fromOpacity', 0)),
|
|
71
|
+
target: preserveStyleState
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
const overlayRevealContentEffectStyleStateResolvers = {
|
|
76
|
+
fade: preserveEffectStyleState,
|
|
77
|
+
lineReveal(effect) {
|
|
78
|
+
return {
|
|
79
|
+
initial: mapStyleNumber('translateY', translateY => translateY + numberOption(effect.options, 'y', 16)),
|
|
80
|
+
target: preserveStyleState
|
|
81
|
+
};
|
|
82
|
+
},
|
|
83
|
+
pulse: preserveEffectStyleState,
|
|
84
|
+
rise: preserveEffectStyleState,
|
|
85
|
+
scale: preserveEffectStyleState,
|
|
86
|
+
shake: preserveEffectStyleState,
|
|
87
|
+
slide: preserveEffectStyleState
|
|
88
|
+
};
|
|
89
|
+
function numberOption(options, key, fallback) {
|
|
90
|
+
const value = options?.[key];
|
|
91
|
+
if (value === undefined) {
|
|
92
|
+
return fallback;
|
|
93
|
+
}
|
|
94
|
+
if (typeof value === 'number' && Number.isFinite(value)) {
|
|
95
|
+
return value;
|
|
96
|
+
}
|
|
97
|
+
throw new Error(`@react-native-motion-kit/text-motion effect option "${key}" must be a finite number.`);
|
|
98
|
+
}
|
|
99
|
+
function validateDelaySeconds(delay) {
|
|
100
|
+
if (Number.isFinite(delay) && delay >= 0) {
|
|
101
|
+
return delay;
|
|
102
|
+
}
|
|
103
|
+
throw new Error('@react-native-motion-kit/text-motion timeline delay must be a finite number greater than or equal to 0.');
|
|
104
|
+
}
|
|
105
|
+
function createDelayMs(delaySeconds) {
|
|
106
|
+
const delayMs = Math.round(delaySeconds * 1000);
|
|
107
|
+
if (Number.isSafeInteger(delayMs)) {
|
|
108
|
+
return delayMs;
|
|
109
|
+
}
|
|
110
|
+
throw new Error('@react-native-motion-kit/text-motion timeline delay must convert to a safe integer millisecond value.');
|
|
111
|
+
}
|
|
112
|
+
function createDefaultStyleStatePair() {
|
|
113
|
+
return {
|
|
114
|
+
initial: {
|
|
115
|
+
...DEFAULT_STYLE_STATE
|
|
116
|
+
},
|
|
117
|
+
pulseScale: 1,
|
|
118
|
+
target: {
|
|
119
|
+
...DEFAULT_STYLE_STATE
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
function mapStyleNumber(key, mapValue) {
|
|
124
|
+
return state => {
|
|
125
|
+
const nextState = {
|
|
126
|
+
...state
|
|
127
|
+
};
|
|
128
|
+
nextState[key] = mapValue(state[key]);
|
|
129
|
+
return nextState;
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
function setStyleNumber(key, value) {
|
|
133
|
+
return mapStyleNumber(key, () => value);
|
|
134
|
+
}
|
|
135
|
+
function composeStyleTransforms(...transforms) {
|
|
136
|
+
return state => transforms.reduce((current, transform) => transform(current), state);
|
|
137
|
+
}
|
|
138
|
+
function preserveEffectStyleState() {
|
|
139
|
+
return {};
|
|
140
|
+
}
|
|
141
|
+
function resolveEffectStyleStateChange(effect, unsupportedEffectSubject, resolvers = effectStyleStateResolvers) {
|
|
142
|
+
const resolver = resolvers[effect.name];
|
|
143
|
+
if (resolver) {
|
|
144
|
+
return resolver(effect);
|
|
145
|
+
}
|
|
146
|
+
throw new Error(`${unsupportedEffectSubject} does not implement the "${effect.name}" effect. Use a built-in style-transform effect or a renderer that handles this effect.`);
|
|
147
|
+
}
|
|
148
|
+
function applyResolvedEffectStyleStateChange(styleState, effectStyleStateChange) {
|
|
149
|
+
const initial = effectStyleStateChange.initial ?? preserveStyleState;
|
|
150
|
+
const pulseScale = effectStyleStateChange.pulseScale ?? preserveNumber;
|
|
151
|
+
const target = effectStyleStateChange.target ?? preserveStyleState;
|
|
152
|
+
return {
|
|
153
|
+
...styleState,
|
|
154
|
+
...(effectStyleStateChange.revealOnStart ? {
|
|
155
|
+
revealOnStart: true
|
|
156
|
+
} : {}),
|
|
157
|
+
initial: initial(styleState.initial),
|
|
158
|
+
pulseScale: pulseScale(styleState.pulseScale),
|
|
159
|
+
target: target(styleState.target)
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
function applyDelay(animation, delayMs, reduceMotion) {
|
|
163
|
+
return delayMs > 0 ? withDelay(delayMs, animation, reduceMotion) : animation;
|
|
164
|
+
}
|
|
165
|
+
export function createTextMotionStyleTransformStatePair(effects, unsupportedEffectSubject = 'style-transform renderer') {
|
|
166
|
+
return createResolvedTextMotionStyleTransformStatePair(effects, unsupportedEffectSubject, effectStyleStateResolvers);
|
|
167
|
+
}
|
|
168
|
+
function createResolvedTextMotionStyleTransformStatePair(effects, unsupportedEffectSubject, resolvers) {
|
|
169
|
+
return flattenTextMotionEffectDescriptors(effects).reduce((styleState, effect) => applyResolvedEffectStyleStateChange(styleState, resolveEffectStyleStateChange(effect, unsupportedEffectSubject, resolvers)), createDefaultStyleStatePair());
|
|
170
|
+
}
|
|
171
|
+
export function createOverlayTextStyleTransformStatePair(effects) {
|
|
172
|
+
return {
|
|
173
|
+
frame: createResolvedTextMotionStyleTransformStatePair(effects, 'overlayText()', overlayFrameEffectStyleStateResolvers),
|
|
174
|
+
revealContent: createResolvedTextMotionStyleTransformStatePair(effects, 'overlayText()', overlayRevealContentEffectStyleStateResolvers)
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
export function createTextMotionDelaySecondsByItemIndex(recipe, count) {
|
|
178
|
+
const timeline = recipe.timeline ? readTextMotionTimelineDescriptor(recipe.timeline) : undefined;
|
|
179
|
+
return Array.from({
|
|
180
|
+
length: count
|
|
181
|
+
}, (_, index) => validateDelaySeconds(timeline?.delayFor(index, count) ?? 0));
|
|
182
|
+
}
|
|
183
|
+
export function createTextMotionItemMotion(recipe, styleState, delaySeconds) {
|
|
184
|
+
return {
|
|
185
|
+
...styleState,
|
|
186
|
+
delayMs: createDelayMs(delaySeconds),
|
|
187
|
+
motion: recipe.motion,
|
|
188
|
+
reducedMotion: recipe.accessibility?.reducedMotion ?? 'system'
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
export function createTextMotionControlledProgressPlan(itemIndex, delaySecondsByItemIndex, totalTimelineSpan) {
|
|
192
|
+
return {
|
|
193
|
+
itemDelaySeconds: delaySecondsByItemIndex[itemIndex] ?? 0,
|
|
194
|
+
totalTimelineSpan
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
export function clampTextMotionProgress(progress) {
|
|
198
|
+
'worklet';
|
|
199
|
+
|
|
200
|
+
if (!Number.isFinite(progress)) {
|
|
201
|
+
return 0;
|
|
202
|
+
}
|
|
203
|
+
return Math.min(1, Math.max(0, progress));
|
|
204
|
+
}
|
|
205
|
+
export function createTextMotionControlledTimelineSpan(delaySecondsByItemIndex) {
|
|
206
|
+
const maxDelaySeconds = delaySecondsByItemIndex.reduce((maxDelay, delaySeconds) => Math.max(maxDelay, delaySeconds), 0);
|
|
207
|
+
return maxDelaySeconds + TEXT_MOTION_CONTROLLED_ITEM_TIMELINE_SPAN;
|
|
208
|
+
}
|
|
209
|
+
export function mapTextMotionControlledProgressToItemProgress({
|
|
210
|
+
progress,
|
|
211
|
+
itemDelaySeconds,
|
|
212
|
+
totalTimelineSpan
|
|
213
|
+
}) {
|
|
214
|
+
'worklet';
|
|
215
|
+
|
|
216
|
+
const virtualTime = clampTextMotionProgress(progress) * totalTimelineSpan;
|
|
217
|
+
const itemProgress = (virtualTime - itemDelaySeconds) / TEXT_MOTION_CONTROLLED_ITEM_TIMELINE_SPAN;
|
|
218
|
+
return clampTextMotionProgress(itemProgress);
|
|
219
|
+
}
|
|
220
|
+
export function resolveTextMotionReduceMotionConfig(reducedMotion) {
|
|
221
|
+
return REDUCE_MOTION_CONFIG_BY_POLICY[reducedMotion];
|
|
222
|
+
}
|
|
223
|
+
export function shouldRenderTextMotionFinalState(reducedMotionEnabled, reducedMotion) {
|
|
224
|
+
return reducedMotionEnabled && reducedMotion !== 'system';
|
|
225
|
+
}
|
|
226
|
+
export function createTextMotionProgressAnimation({
|
|
227
|
+
delayMs,
|
|
228
|
+
motion,
|
|
229
|
+
reducedMotion
|
|
230
|
+
}) {
|
|
231
|
+
const reduceMotion = resolveTextMotionReduceMotionConfig(reducedMotion);
|
|
232
|
+
if (motion?.kind === 'spring') {
|
|
233
|
+
const animation = withSpring(1, {
|
|
234
|
+
...motion.options,
|
|
235
|
+
reduceMotion
|
|
236
|
+
});
|
|
237
|
+
return applyDelay(animation, delayMs, reduceMotion);
|
|
238
|
+
}
|
|
239
|
+
const timingOptions = motion?.kind === 'timing' ? motion.options : undefined;
|
|
240
|
+
const animation = withTiming(1, {
|
|
241
|
+
duration: 300,
|
|
242
|
+
...timingOptions,
|
|
243
|
+
reduceMotion
|
|
244
|
+
});
|
|
245
|
+
return applyDelay(animation, delayMs, reduceMotion);
|
|
246
|
+
}
|
|
247
|
+
export function readTextMotionProgressForAnimatedStyle({
|
|
248
|
+
controlledProgressPlan,
|
|
249
|
+
progress,
|
|
250
|
+
renderFinalState
|
|
251
|
+
}) {
|
|
252
|
+
'worklet';
|
|
253
|
+
|
|
254
|
+
const rawProgress = renderFinalState ? 1 : progress.value;
|
|
255
|
+
if (!controlledProgressPlan) {
|
|
256
|
+
return Number.isFinite(rawProgress) ? rawProgress : 0;
|
|
257
|
+
}
|
|
258
|
+
return mapTextMotionControlledProgressToItemProgress({
|
|
259
|
+
progress: rawProgress,
|
|
260
|
+
itemDelaySeconds: controlledProgressPlan.itemDelaySeconds,
|
|
261
|
+
totalTimelineSpan: controlledProgressPlan.totalTimelineSpan
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
//# sourceMappingURL=rendererMotion.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["ReduceMotion","withDelay","withSpring","withTiming","flattenTextMotionEffectDescriptors","readTextMotionTimelineDescriptor","TEXT_MOTION_CONTROLLED_ITEM_TIMELINE_SPAN","DEFAULT_STYLE_STATE","opacity","scale","translateX","translateY","REDUCE_MOTION_CONFIG_BY_POLICY","Never","system","System","preserveStyleState","state","preserveNumber","value","effectStyleStateResolvers","typewriter","revealOnStart","fade","effect","initial","setStyleNumber","numberOption","options","target","lineReveal","composeStyleTransforms","mapStyleNumber","pulse","pulseScale","rise","shake","slide","overlayFrameEffectStyleStateResolvers","overlayRevealContentEffectStyleStateResolvers","preserveEffectStyleState","key","fallback","undefined","Number","isFinite","Error","validateDelaySeconds","delay","createDelayMs","delaySeconds","delayMs","Math","round","isSafeInteger","createDefaultStyleStatePair","mapValue","nextState","transforms","reduce","current","transform","resolveEffectStyleStateChange","unsupportedEffectSubject","resolvers","resolver","name","applyResolvedEffectStyleStateChange","styleState","effectStyleStateChange","applyDelay","animation","reduceMotion","createTextMotionStyleTransformStatePair","effects","createResolvedTextMotionStyleTransformStatePair","createOverlayTextStyleTransformStatePair","frame","revealContent","createTextMotionDelaySecondsByItemIndex","recipe","count","timeline","Array","from","length","_","index","delayFor","createTextMotionItemMotion","motion","reducedMotion","accessibility","createTextMotionControlledProgressPlan","itemIndex","delaySecondsByItemIndex","totalTimelineSpan","itemDelaySeconds","clampTextMotionProgress","progress","min","max","createTextMotionControlledTimelineSpan","maxDelaySeconds","maxDelay","mapTextMotionControlledProgressToItemProgress","virtualTime","itemProgress","resolveTextMotionReduceMotionConfig","shouldRenderTextMotionFinalState","reducedMotionEnabled","createTextMotionProgressAnimation","kind","timingOptions","duration","readTextMotionProgressForAnimatedStyle","controlledProgressPlan","renderFinalState","rawProgress"],"sourceRoot":"../../../src","sources":["renderers/rendererMotion.ts"],"mappings":";;AAAA,SACEA,YAAY,EACZC,SAAS,EACTC,UAAU,EACVC,UAAU,QAEL,yBAAyB;AAUhC,SACEC,kCAAkC,EACl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zC,SAAS,GAAGrE,UAAU,CAAC,CAAC,EAAE;MAC9B,GAAGwF,MAAM,CAAC9D,OAAO;MACjB4C;IACF,CAAC,CAAC;IAEF,OAAOF,UAAU,CAACC,SAAS,EAAEpB,OAAO,EAAEqB,YAAY,CAAC;EACrD;EAEA,MAAMyC,aAAa,GAAGvB,MAAM,EAAEsB,IAAI,KAAK,QAAQ,GAAGtB,MAAM,CAAC9D,OAAO,GAAGe,SAAS;EAC5E,MAAM4B,SAAS,GAAGpE,UAAU,CAAC,CAAC,EAAE;IAC9B+G,QAAQ,EAAE,GAAG;IACb,GAAGD,aAAa;IAChBzC;EACF,CAAC,CAAC;EAEF,OAAOF,UAAU,CAACC,SAAS,EAAEpB,OAAO,EAAEqB,YAAY,CAAC;AACrD;AAEA,OAAO,SAAS2C,sCAAsCA,CAAC;EACrDC,sBAAsB;EACtBjB,QAAQ;EACRkB;AAKF,CAAC,EAAU;EACT,SAAS;;EAET,MAAMC,WAAW,GAAGD,gBAAgB,GAAG,CAAC,GAAGlB,QAAQ,CAAChF,KAAK;EAEzD,IAAI,CAACiG,sBAAsB,EAAE;IAC3B,OAAOxE,MAAM,CAACC,QAAQ,CAACyE,WAAW,CAAC,GAAGA,WAAW,GAAG,CAAC;EACvD;EAEA,OAAOb,6CAA6C,CAAC;IACnDN,QAAQ,EAAEmB,WAAW;IACrBrB,gBAAgB,EAAEmB,sBAAsB,CAACnB,gBAAgB;IACzDD,iBAAiB,EAAEoB,sBAAsB,CAACpB;EAC5C,CAAC,CAAC;AACJ","ignoreList":[]}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
export function createTextMotionToken({
|
|
4
|
+
index,
|
|
5
|
+
metadata,
|
|
6
|
+
sourceRange,
|
|
7
|
+
text,
|
|
8
|
+
unit
|
|
9
|
+
}) {
|
|
10
|
+
return {
|
|
11
|
+
id: `${unit}-${index}-${sourceRange.start}-${sourceRange.end}`,
|
|
12
|
+
index,
|
|
13
|
+
metadata,
|
|
14
|
+
sourceRange,
|
|
15
|
+
text,
|
|
16
|
+
unit
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=createToken.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["createTextMotionToken","index","metadata","sourceRange","text","unit","id","start","end"],"sourceRoot":"../../../src","sources":["split/createToken.ts"],"mappings":";;AAUA,OAAO,SAASA,qBAAqBA,CAAmC;EACtEC,KAAK;EACLC,QAAQ;EACRC,WAAW;EACXC,IAAI;EACJC;AACsB,CAAC,EAAyB;EAChD,OAAO;IACLC,EAAE,EAAE,GAAGD,IAAI,IAAIJ,KAAK,IAAIE,WAAW,CAACI,KAAK,IAAIJ,WAAW,CAACK,GAAG,EAAE;IAC9DP,KAAK;IACLC,QAAQ;IACRC,WAAW;IACXC,IAAI;IACJC;EACF,CAAC;AACH","ignoreList":[]}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { createTextMotionSplitterHandle } from "../recipe/descriptors.js";
|
|
4
|
+
import { createTextMotionToken } from "./createToken.js";
|
|
5
|
+
|
|
6
|
+
/** Token object returned by a custom splitter when source metadata matters. */
|
|
7
|
+
|
|
8
|
+
/** Result item returned by a custom splitter. */
|
|
9
|
+
|
|
10
|
+
/** Custom split function used by {@link custom}. */
|
|
11
|
+
|
|
12
|
+
function findSourceRange(input, text, cursor) {
|
|
13
|
+
const start = input.indexOf(text, cursor);
|
|
14
|
+
const safeStart = start >= 0 ? start : cursor;
|
|
15
|
+
return {
|
|
16
|
+
end: safeStart + text.length,
|
|
17
|
+
start: safeStart
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
function normalizeCustomSplitResult(input, result, index, cursor) {
|
|
21
|
+
const text = typeof result === 'string' ? result : result.text;
|
|
22
|
+
const sourceRange = typeof result === 'string' || !result.sourceRange ? findSourceRange(input, text, cursor) : result.sourceRange;
|
|
23
|
+
return {
|
|
24
|
+
cursor: sourceRange.end,
|
|
25
|
+
token: createTextMotionToken({
|
|
26
|
+
index,
|
|
27
|
+
metadata: typeof result === 'string' ? undefined : result.metadata,
|
|
28
|
+
sourceRange,
|
|
29
|
+
text,
|
|
30
|
+
unit: 'custom'
|
|
31
|
+
})
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** Build a splitter from an app-defined split function. */
|
|
36
|
+
export function custom(split) {
|
|
37
|
+
return createTextMotionSplitterHandle({
|
|
38
|
+
kind: 'custom',
|
|
39
|
+
split(input, context) {
|
|
40
|
+
const initialAccumulator = {
|
|
41
|
+
cursor: 0,
|
|
42
|
+
tokens: []
|
|
43
|
+
};
|
|
44
|
+
return split(input, context).reduce((accumulator, result, index) => {
|
|
45
|
+
const normalized = normalizeCustomSplitResult(input, result, index, accumulator.cursor);
|
|
46
|
+
|
|
47
|
+
// Keep the token accumulator mutable so custom split normalization stays linear.
|
|
48
|
+
accumulator.tokens.push(normalized.token);
|
|
49
|
+
return {
|
|
50
|
+
cursor: normalized.cursor,
|
|
51
|
+
tokens: accumulator.tokens
|
|
52
|
+
};
|
|
53
|
+
}, initialAccumulator).tokens;
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=custom.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["createTextMotionSplitterHandle","createTextMotionToken","findSourceRange","input","text","cursor","start","indexOf","safeStart","end","length","normalizeCustomSplitResult","result","index","sourceRange","token","metadata","undefined","unit","custom","split","kind","context","initialAccumulator","tokens","reduce","accumulator","normalized","push"],"sourceRoot":"../../../src","sources":["split/custom.ts"],"mappings":";;AAOA,SAASA,8BAA8B,QAAQ,0BAAuB;AACtE,SAASC,qBAAqB,QAAQ,kBAAe;;AAErD;;AAUA;;AAGA;;AAWA,SAASC,eAAeA,CAACC,KAAa,EAAEC,IAAY,EAAEC,MAAc,EAAE;EACpE,M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AAK,EAAES,MAAM,EAAEC,KAAK,EAAEa,WAAW,CAACrB,MAAM,CAAC;;QAEvF;QACAqB,WAAW,CAACF,MAAM,CAACI,IAAI,CAACD,UAAU,CAACZ,KAAK,CAAC;QAEzC,OAAO;UACLV,MAAM,EAAEsB,UAAU,CAACtB,MAAM;UACzBmB,MAAM,EAAEE,WAAW,CAACF;QACtB,CAAC;MACH,CAAC,EAAED,kBAAkB,CAAC,CAACC,MAAM;IAC/B;EACF,CAAC,CAAC;AACJ","ignoreList":[]}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { createTextMotionSplitterHandle } from "../recipe/descriptors.js";
|
|
4
|
+
import { createTextMotionToken } from "./createToken.js";
|
|
5
|
+
import { createSegmenter } from "./segmenter.js";
|
|
6
|
+
|
|
7
|
+
/** Split text into grapheme-aware tokens for character-level motion. */
|
|
8
|
+
export function graphemes() {
|
|
9
|
+
return createTextMotionSplitterHandle({
|
|
10
|
+
kind: 'grapheme',
|
|
11
|
+
split(input, context) {
|
|
12
|
+
const segmenter = createSegmenter('grapheme', context?.locale);
|
|
13
|
+
return Array.from(segmenter.segment(input), (segment, index) => createTextMotionToken({
|
|
14
|
+
index,
|
|
15
|
+
sourceRange: {
|
|
16
|
+
start: segment.index,
|
|
17
|
+
end: segment.index + segment.segment.length
|
|
18
|
+
},
|
|
19
|
+
text: segment.segment,
|
|
20
|
+
unit: 'grapheme'
|
|
21
|
+
}));
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=graphemes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["createTextMotionSplitterHandle","createTextMotionToken","createSegmenter","graphemes","kind","split","input","context","segmenter","locale","Array","from","segment","index","sourceRange","start","end","length","text","unit"],"sourceRoot":"../../../src","sources":["split/graphemes.ts"],"mappings":";;AAEA,SAASA,8BAA8B,QAAQ,0BAAuB;AACtE,SAASC,qBAAqB,QAAQ,kBAAe;AACrD,SAASC,eAAe,QAAQ,gBAAa;;AAE7C;AACA,OAAO,SAASC,SAASA,CAAA,EAAmC;EAC1D,OAAOH,8BAA8B,CAAC;IACpCI,IAAI,EAAE,UAAU;IAChBC,KAAKA,CAACC,KAAK,EAAEC,OAAO,EAAE;MACpB,MAAMC,SAAS,GAAGN,eAAe,CAAC,UAAU,EAAEK,OAAO,EAAEE,MAAM,CAAC;MAE9D,OAAOC,KAAK,CAACC,IAAI,CAACH,SAAS,CAACI,OAAO,CAACN,KAAK,CAAC,EAAE,CAACM,OAAO,EAAEC,KAAK,KACzDZ,qBAAqB,CAAC;QACpBY,KAAK;QACLC,WAAW,EAAE;UACXC,KAAK,EAAEH,OAAO,CAACC,KAAK;UACpBG,GAAG,EAAEJ,OAAO,CAACC,KAAK,GAAGD,OAAO,CAACA,OAAO,CAACK;QACvC,CAAC;QACDC,IAAI,EAAEN,OAAO,CAACA,OAAO;QACrBO,IAAI,EAAE;MACR,CAAC,CACH,CAAC;IACH;EACF,CAAC,CAAC;AACJ","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["custom","graphemes","lines","words"],"sourceRoot":"../../../src","sources":["split/index.ts"],"mappings":";;AAAA,SACEA,MAAM,QAID,aAAU;AACjB,SAASC,SAAS,QAAQ,gBAAa;AACvC,SAASC,KAAK,QAAQ,YAAS;AAC/B,SAASC,KAAK,QAAQ,YAAS","ignoreList":[]}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { createTextMotionSplitterHandle } from "../recipe/descriptors.js";
|
|
4
|
+
import { createTextMotionToken } from "./createToken.js";
|
|
5
|
+
const LINE_SEGMENT_PATTERN = /[^\n]*\n|[^\n]+/g;
|
|
6
|
+
function lineParts(input) {
|
|
7
|
+
if (input.length === 0) {
|
|
8
|
+
return [{
|
|
9
|
+
start: 0,
|
|
10
|
+
text: ''
|
|
11
|
+
}];
|
|
12
|
+
}
|
|
13
|
+
return Array.from(input.matchAll(LINE_SEGMENT_PATTERN), match => ({
|
|
14
|
+
start: match.index ?? 0,
|
|
15
|
+
text: match[0] ?? ''
|
|
16
|
+
}));
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** Split on newline boundaries. This is experimental and does not measure rendered line wraps. */
|
|
20
|
+
export function lines() {
|
|
21
|
+
return createTextMotionSplitterHandle({
|
|
22
|
+
kind: 'line',
|
|
23
|
+
split(input) {
|
|
24
|
+
return lineParts(input).map(({
|
|
25
|
+
start,
|
|
26
|
+
text
|
|
27
|
+
}, index) => createTextMotionToken({
|
|
28
|
+
index,
|
|
29
|
+
metadata: {
|
|
30
|
+
experimental: true,
|
|
31
|
+
mapping: 'newline-only'
|
|
32
|
+
},
|
|
33
|
+
sourceRange: {
|
|
34
|
+
start,
|
|
35
|
+
end: start + text.length
|
|
36
|
+
},
|
|
37
|
+
text,
|
|
38
|
+
unit: 'line'
|
|
39
|
+
}));
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=lines.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["createTextMotionSplitterHandle","createTextMotionToken","LINE_SEGMENT_PATTERN","lineParts","input","length","start","text","Array","from","matchAll","match","index","lines","kind","split","map","metadata","experimental","mapping","sourceRange","end","unit"],"sourceRoot":"../../../src","sources":["split/lines.ts"],"mappings":";;AAEA,SAASA,8BAA8B,QAAQ,0BAAuB;AACtE,SAASC,qBAAqB,QAAQ,kBAAe;AAErD,MAAMC,oBAAoB,GAAG,kBAAkB;AAE/C,SAASC,SAASA,CAACC,KAAa,EAAE;EAChC,IAAIA,KAAK,CAACC,MAAM,KAAK,CAAC,EAAE;IACtB,OAAO,CAAC;MAAEC,KAAK,EAAE,CAAC;MAAEC,IAAI,EAAE;IAAG,CAAC,CAAC;EACjC;EAEA,OAAOC,KAAK,CAACC,IAAI,CAACL,KAAK,CAACM,QAAQ,CAACR,oBAAoB,CAAC,EAAGS,KAAK,KAAM;IAClEL,KAAK,EAAEK,KAAK,CAACC,KAAK,IAAI,CAAC;IACvBL,IAAI,EAAEI,KAAK,CAAC,CAAC,CAAC,IAAI;EACpB,CAAC,CAAC,CAAC;AACL;;AAEA;AACA,OAAO,SAASE,KAAKA,CAAA,EAA+B;EAClD,OAAOb,8BAA8B,CAAC;IACpCc,IAAI,EAAE,MAAM;IACZC,KAAKA,CAACX,KAAK,EAAsC;MAC/C,OAAOD,SAAS,CAACC,KAAK,CAAC,CAACY,GAAG,CAAC,CAAC;QAAEV,KAAK;QAAEC;MAAK,CAAC,EAAEK,KAAK,KACjDX,qBAAqB,CAAC;QACpBW,KAAK;QACLK,QAAQ,EAAE;UAAEC,YAAY,EAAE,IAAI;UAAEC,OAAO,EAAE;QAAe,CAAC;QACzDC,WAAW,EAAE;UAAEd,KAAK;UAAEe,GAAG,EAAEf,KAAK,GAAGC,IAAI,CAACF;QAAO,CAAC;QAChDE,IAAI;QACJe,IAAI,EAAE;MACR,CAAC,CACH,CAAC;IACH;EACF,CAAC,CAAC;AACJ","ignoreList":[]}
|