@rohal12/spindle 0.64.26 → 0.64.28
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/pkg/format.js +1 -1
- package/dist/pkg/headless.js +369 -37
- package/package.json +1 -1
- package/src/action-registry.ts +5 -1
- package/src/components/macros/PassageDisplay.tsx +3 -3
- package/src/components/macros/Type.tsx +1 -0
- package/src/index.tsx +2 -2
- package/src/markup/render.tsx +3 -2
- package/src/markup/svg-names.ts +69 -0
- package/src/observe/observable-text.ts +77 -9
- package/src/observe/svg-instances.ts +210 -0
- package/src/saves/save-manager.ts +25 -9
- package/src/store.ts +16 -2
- package/src/story-init.ts +6 -1
- package/src/utils/element-visibility.ts +110 -11
- package/src/utils/type-reveal.ts +55 -0
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { composedElements, composedParent } from './element-visibility';
|
|
2
|
+
|
|
3
|
+
/** Remaining revealed characters at this node, across nested typewriters. */
|
|
4
|
+
function revealedCharacters(node: Node): number {
|
|
5
|
+
let available = Infinity;
|
|
6
|
+
const element = node.nodeType === 1 ? (node as Element) : node.parentElement;
|
|
7
|
+
for (let at = element; at; at = composedParent(at)) {
|
|
8
|
+
const count = at.getAttribute('data-type-revealed');
|
|
9
|
+
if (count === null) continue;
|
|
10
|
+
let left = Number(count);
|
|
11
|
+
if (!Number.isFinite(left)) continue;
|
|
12
|
+
// The visual clip counts DOM text, including text hidden by other CSS.
|
|
13
|
+
// Shadow content has no measured range until its containing type finishes.
|
|
14
|
+
if (!at.contains(node)) return 0;
|
|
15
|
+
for (let child = node; child !== at; child = child.parentNode!) {
|
|
16
|
+
for (
|
|
17
|
+
let sibling = child.previousSibling;
|
|
18
|
+
sibling;
|
|
19
|
+
sibling = sibling.previousSibling
|
|
20
|
+
) {
|
|
21
|
+
if (sibling.nodeType === 1 || sibling.nodeType === 3)
|
|
22
|
+
left -= sibling.textContent?.length ?? 0;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
available = Math.min(available, Math.max(0, left));
|
|
26
|
+
}
|
|
27
|
+
return available;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** Only the prefix that every containing typewriter has revealed. */
|
|
31
|
+
export function revealedText(node: Text): string {
|
|
32
|
+
return node.data.slice(0, revealedCharacters(node));
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** Offer a control once its entire label is revealed, avoiding label spoilers.
|
|
36
|
+
* Controls without DOM text have no measured clip boxes; wait for completion.
|
|
37
|
+
*/
|
|
38
|
+
export function isFullyRevealed(el: Element): boolean {
|
|
39
|
+
const available = revealedCharacters(el);
|
|
40
|
+
if (
|
|
41
|
+
available !== Infinity &&
|
|
42
|
+
(!el.textContent || available < el.textContent.length)
|
|
43
|
+
)
|
|
44
|
+
return false;
|
|
45
|
+
// Custom controls may wrap a typewriter in their label. An enclosing
|
|
46
|
+
// typewriter finishing does not reveal a slower one inside the control.
|
|
47
|
+
for (const child of composedElements(el)) {
|
|
48
|
+
if (
|
|
49
|
+
child.hasAttribute('data-type-revealed') &&
|
|
50
|
+
revealedCharacters(child) < (child.textContent?.length ?? 0)
|
|
51
|
+
)
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
return true;
|
|
55
|
+
}
|