vultus-core 0.5.6 → 0.5.8

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.
Files changed (95) hide show
  1. package/README.md +232 -9
  2. package/dist/Components.d.ts +41 -0
  3. package/dist/Components.d.ts.map +1 -1
  4. package/dist/Components.js.map +1 -1
  5. package/dist/argStore.d.ts +9 -0
  6. package/dist/argStore.d.ts.map +1 -1
  7. package/dist/argStore.js.map +1 -1
  8. package/dist/changes/ChangeMark.d.ts +85 -0
  9. package/dist/changes/ChangeMark.d.ts.map +1 -0
  10. package/dist/changes/ChangeMark.js +113 -0
  11. package/dist/changes/ChangeMark.js.map +1 -0
  12. package/dist/changes/ChangingText.d.ts +20 -0
  13. package/dist/changes/ChangingText.d.ts.map +1 -0
  14. package/dist/changes/ChangingText.js +31 -0
  15. package/dist/changes/ChangingText.js.map +1 -0
  16. package/dist/changes/FallbackMark.d.ts +20 -0
  17. package/dist/changes/FallbackMark.d.ts.map +1 -0
  18. package/dist/changes/FallbackMark.js +53 -0
  19. package/dist/changes/FallbackMark.js.map +1 -0
  20. package/dist/changes/blocks.d.ts +15 -0
  21. package/dist/changes/blocks.d.ts.map +1 -0
  22. package/dist/changes/blocks.js +24 -0
  23. package/dist/changes/blocks.js.map +1 -0
  24. package/dist/changes/changeDurations.d.ts +21 -0
  25. package/dist/changes/changeDurations.d.ts.map +1 -0
  26. package/dist/changes/changeDurations.js +18 -0
  27. package/dist/changes/changeDurations.js.map +1 -0
  28. package/dist/changes/changesIn.d.ts +88 -0
  29. package/dist/changes/changesIn.d.ts.map +1 -0
  30. package/dist/changes/changesIn.js +470 -0
  31. package/dist/changes/changesIn.js.map +1 -0
  32. package/dist/changes/readText.d.ts +45 -0
  33. package/dist/changes/readText.d.ts.map +1 -0
  34. package/dist/changes/readText.js +99 -0
  35. package/dist/changes/readText.js.map +1 -0
  36. package/dist/changes/rehypeChanges.d.ts +81 -0
  37. package/dist/changes/rehypeChanges.d.ts.map +1 -0
  38. package/dist/changes/rehypeChanges.js +268 -0
  39. package/dist/changes/rehypeChanges.js.map +1 -0
  40. package/dist/changes/useTextChanges.d.ts +93 -0
  41. package/dist/changes/useTextChanges.d.ts.map +1 -0
  42. package/dist/changes/useTextChanges.js +154 -0
  43. package/dist/changes/useTextChanges.js.map +1 -0
  44. package/dist/changes/visibleBlocks.d.ts +42 -0
  45. package/dist/changes/visibleBlocks.d.ts.map +1 -0
  46. package/dist/changes/visibleBlocks.js +104 -0
  47. package/dist/changes/visibleBlocks.js.map +1 -0
  48. package/dist/changes.d.ts +9 -0
  49. package/dist/changes.d.ts.map +1 -0
  50. package/dist/changes.js +10 -0
  51. package/dist/changes.js.map +1 -0
  52. package/dist/field.d.ts +15 -2
  53. package/dist/field.d.ts.map +1 -1
  54. package/dist/field.js +8 -1
  55. package/dist/field.js.map +1 -1
  56. package/dist/index.d.ts +3 -1
  57. package/dist/index.d.ts.map +1 -1
  58. package/dist/index.js.map +1 -1
  59. package/dist/kindHooks.d.ts +1 -1
  60. package/dist/kinds.d.ts +12 -5
  61. package/dist/kinds.d.ts.map +1 -1
  62. package/dist/kinds.js.map +1 -1
  63. package/dist/useArg.d.ts +9 -2
  64. package/dist/useArg.d.ts.map +1 -1
  65. package/dist/useArg.js +4 -2
  66. package/dist/useArg.js.map +1 -1
  67. package/dist/useFieldGroup.d.ts +2 -1
  68. package/dist/useFieldGroup.d.ts.map +1 -1
  69. package/dist/useFieldGroup.js +5 -2
  70. package/dist/useFieldGroup.js.map +1 -1
  71. package/dist/useStoredField.d.ts +14 -5
  72. package/dist/useStoredField.d.ts.map +1 -1
  73. package/dist/useStoredField.js +20 -7
  74. package/dist/useStoredField.js.map +1 -1
  75. package/package.json +13 -1
  76. package/src/Components.tsx +45 -0
  77. package/src/argStore.ts +7 -0
  78. package/src/changes/ChangeMark.tsx +165 -0
  79. package/src/changes/ChangingText.tsx +46 -0
  80. package/src/changes/FallbackMark.tsx +59 -0
  81. package/src/changes/blocks.ts +25 -0
  82. package/src/changes/changeDurations.ts +31 -0
  83. package/src/changes/changesIn.ts +479 -0
  84. package/src/changes/readText.ts +123 -0
  85. package/src/changes/rehypeChanges.ts +302 -0
  86. package/src/changes/useTextChanges.ts +239 -0
  87. package/src/changes/visibleBlocks.ts +121 -0
  88. package/src/changes.ts +14 -0
  89. package/src/field.ts +23 -3
  90. package/src/index.ts +4 -0
  91. package/src/kindHooks.ts +1 -1
  92. package/src/kinds.ts +17 -7
  93. package/src/useArg.ts +11 -3
  94. package/src/useFieldGroup.ts +5 -2
  95. package/src/useStoredField.ts +21 -8
package/README.md CHANGED
@@ -36,10 +36,14 @@ npm install vultus-core
36
36
  `useInternalLink` / `InternalLinkComponent`, `MessageSinkContext` /
37
37
  `useMessageSink` / `MessageSink`, and `VultusComponentsContext` /
38
38
  `useVultusComponents` / `SpinnerScope` / `useSpinnerKey` /
39
- `VultusComponents` / `SpinnerProps` / `SpinnerComponent`.
39
+ `VultusComponents` / `SpinnerProps` / `SpinnerComponent` /
40
+ `ChangeMarkVariant` / `ChangeMarkProps` / `ChangeMarkComponent`.
40
41
  - `./link` — `InternalLinkContext`, `useInternalLink`, and the
41
42
  `InternalLinkComponent` type on their own, for consumers that only need the
42
43
  link-injection seam.
44
+ - `./changes` — text changes (see Text changes, below): `useTextChanges`,
45
+ `ChangingText`, `changesIn`, `readText`, `changeDurations` and their types.
46
+ Only this entry loads `diff-match-patch`.
43
47
 
44
48
  ## Actions report messages
45
49
 
@@ -68,6 +72,16 @@ and where the value lives:
68
72
  `messages`; afterwards it shows whatever `value` the caller passes. `confirmation` may
69
73
  depend on the requested value.
70
74
 
75
+ A field can also be pending for a reason of the app's, in any storage mode (a stored field
76
+ group's included): `pending` (a boolean, or a function of the field context) makes it pending
77
+ while it says so, exactly as during a commit: widgets lock it (those with a spinner show it),
78
+ and `setValue` refuses a request with a warning. With `commit`, a running commit makes it
79
+ pending too. E.g. a filter whose last change the page has not shown yet:
80
+ `pending: (ctx) => ctx.settling.has('variant')`. A locked widget keeps the keyboard focus and
81
+ is said to be unavailable, but a change (a click, a key, typing, a drag) does nothing. An input
82
+ being typed into stays focused and keeps a draft not yet requested; it is read-only until
83
+ pending ends.
84
+
71
85
  The returned controls (`value`, `setValue`, `toggle`, `pending`, `enabled`, `whyDisabled`,
72
86
  `description`, `valueDescription`, `messages`, `confirmationFor(next)`, ...) are what widgets
73
87
  render: vultus-antd's `BoolSwitch` and `BoolCheckbox` take the same field.
@@ -366,9 +380,10 @@ initialValueOf(definitions[0], {}); // false
366
380
  ## Arguments
367
381
 
368
382
  Storage outside a field hook — a URL, localStorage — lives in vultus-core as
369
- its own layer (ported from moxb's `url-arg`, without mobx), independent of
370
- the field hooks: an argument is `{ key, valueType, default }`, kept in
371
- whatever `ArgStore` is nearest.
383
+ its own layer (ported from stellar-router's `url-arg`, without mobx),
384
+ independent of the field hooks: an argument is `{ key, valueType, default }`,
385
+ optionally `permanent` (see Permanence, below), kept in whatever `ArgStore` is
386
+ nearest.
372
387
 
373
388
  **Value types** (`ValueType<T>`: `parse(raw)`, `format(value)`, `isEqual(a,
374
389
  b)`) say how a value is kept as a string and compared; equality is the
@@ -389,7 +404,8 @@ the default (or is dropped from a list), with a `console.warn`.
389
404
 
390
405
  **Stores.** `ArgStore` is `read(key)`, `write(changes, method)` (`method`:
391
406
  `'push'` or `'replace'`; a store without history ignores it),
392
- `subscribe(listener)`, and optionally `hrefFor(changes)`. vultus-core ships
407
+ `subscribe(listener)`, and optionally `hrefFor(changes)` and
408
+ `declare(key, facts)` (see Permanence, below). vultus-core ships
393
409
  `memoryStore()` (tests, demos) and `localStorageStore(prefix)` (keys
394
410
  namespaced as `${prefix}.${key}`, guarded for SSR so creating one outside a
395
411
  browser is a safe no-op; where the browser blocks storage or refuses a
@@ -440,6 +456,31 @@ element, and the object while no entry changed) and `resetAll(method)` (one
440
456
  write for every field). Being a summary, it never warns — only `useStoredField` on the
441
457
  field itself does.
442
458
 
459
+ **Permanence.** `permanent?: boolean` (default false), on an `ArgDefinition` and on a
460
+ `FieldDefinition`, says that the argument stays when its store goes somewhere else: a URL
461
+ store does, when a path token changes (vultus-react-router's README has the rule). It is said
462
+ only there. No kind's hook reads it, `argOf` carries it over, and a render site cannot give it:
463
+ vultus-antd's `<Field permanent>` is a type error and throws, with or without `stored`.
464
+
465
+ The store learns it from the hooks. `useArg` (so `useStoredField`), `useStoredFields` and
466
+ `useFieldGroup(definitions, { stored: true })` call the store's optional
467
+ `declare(key, { permanent })` as they render, for every definition, hidden ones too. It is
468
+ idempotent and notifies nobody. A store that never drops a key omits it, as `memoryStore` and
469
+ `localStorageStore` do, and the hooks then skip it. `useArgWriter` does not declare, as it sees a
470
+ definition only when it writes one: an argument only ever written that way, with no hook on it,
471
+ stays undeclared.
472
+
473
+ A wrapper store (one that hands its calls to another: a step's own view of the URL, say) should
474
+ forward it, in one line:
475
+
476
+ ```ts
477
+ declare: (key, facts) => inner.declare?.(key, facts),
478
+ ```
479
+
480
+ If it does not, the store it wraps is told nothing of the keys used through the wrapper, and to a
481
+ URL store a query key never declared is one to keep. So no query key is dropped: no value is lost,
482
+ but a filter meant to go with the old place stays in the URL.
483
+
443
484
  **Links.** Every kind's hook gives its controls `hrefFor(value)`: the link that requesting `value`
444
485
  amounts to, or `undefined` where nothing gives one. With `value` + `onChange` or `value` +
445
486
  `commit`, the caller passes it; inside the field it is always `undefined` (an `hrefFor` passed
@@ -591,10 +632,12 @@ it). The group then keeps the value and re-renders, so every option is computed
591
632
  ## Components
592
633
 
593
634
  `VultusComponentsContext` (default `{}`) / `useVultusComponents()` is how an app lends its own
594
- UI to vultus/optio in place of their native indicators — today just `Spinner` (`SpinnerProps`:
595
- `spinnerKey`, `size?`, `label?`; `VultusComponents.Spinner?: SpinnerComponent`). vultus-antd's
596
- `VultusProvider` merges a `components` prop into the outer context value; without one, the
597
- outer value (or this default) applies, as `linkComponent` does today.
635
+ UI to vultus/optio in place of their native indicators — today `Spinner` (`SpinnerProps`:
636
+ `spinnerKey`, `size?`, `label?`; `VultusComponents.Spinner?: SpinnerComponent`) and
637
+ `ChangeMark`, the marks of text changes (`VultusComponents.ChangeMark?: ChangeMarkComponent`;
638
+ see Text changes, below). vultus-antd's `VultusProvider` merges a `components` prop into the
639
+ outer context value; without one, the outer value (or this default) applies, as `linkComponent`
640
+ does today.
598
641
 
599
642
  Every call site that may render a lent `Spinner` asks for its key through `useSpinnerKey(localKey)`
600
643
  rather than hardcoding it, so an app can scope a whole subtree's keys to one instance:
@@ -603,6 +646,186 @@ rather than hardcoding it, so an app can scope a whole subtree's keys to one ins
603
646
  Library-local keys are namespaced (`vultus:...`, `optio:...`) so they never collide with an
604
647
  app's own keys.
605
648
 
649
+ ## Text changes
650
+
651
+ What changed between two versions of a text, found and lit up: when a text switches to a related
652
+ version (another spelling, an edit), its changed words and letters are marked for a moment, then
653
+ the marks go. It lives at `vultus-core/changes`, so the main entry stays light: only an app that
654
+ shows text changes loads `diff-match-patch`.
655
+
656
+ vultus decides what changed and which mark goes where; the look comes from whoever lends the
657
+ `ChangeMark` (a style library's provider, say). vultus has no stylesheet for the marks: without a
658
+ lent mark, it draws static ones in inline styles (the fallback, below).
659
+
660
+ ### The API
661
+
662
+ - **`useTextChanges(text, options)`** returns `{ rehypePlugin, components, part(name), active }`
663
+ for a Markdown renderer (react-markdown, vultus-antd's `Markdown`): `rehypePlugin` goes into its
664
+ `rehypePlugins`, and `components` (one `ins` entry, drawing the marks) is merged into its
665
+ `components`. `text` is the whole content, all its parts.
666
+ - **`key`** (required) is the content's identity: the app decides which changes are related,
667
+ and the hook never guesses. Same key, new text: a switch, which animates. A new key: the text
668
+ appears plainly, and a running switch stops at once. Same key, same text (a reload, a
669
+ refetch): nothing. The key carries everything that makes content unrelated (the UI language,
670
+ a data generation), or a language change lights the whole text. The first render has nothing
671
+ before it, so nothing animates.
672
+ - **`animate: false`** swaps plainly once, under the same key too (a live edit), and replaces
673
+ the reading, so the next related change starts from this text.
674
+ - **`near`** limits the marks to the blocks near the screen: a function of the block number, or
675
+ `{ container, blocks, rootMargin? }`, the innermost blocks crossing `container` (the scrolling
676
+ pane, through an IntersectionObserver) as a switch starts, `blocks` more each way. It is frozen
677
+ for the switch. Without `near`, or with no range yet, everything is marked. A ref object as
678
+ `container` is read once, after mount: a pane that mounts later or is replaced is given as the
679
+ element (a callback ref kept in state).
680
+ - **`skip(element)`** names what the reading leaves out (footnote marks, KaTeX's output), besides
681
+ elements carrying `data-vultus-change-skip`; it gets the hast `Element` the plugin visits.
682
+ - **`blockAttribute`** names an existing block numbering (`'data-block'`) for `near`; without it
683
+ the plugin numbers the blocks itself, as `data-vultus-block`.
684
+ - **`speed`**: `'slow'`, `'normal'` (the default) or `'fast'`, the lent mark's `speed`. It is
685
+ taken as a switch starts and held for it, marks and timer alike; a new speed counts from the
686
+ next switch and parses nothing.
687
+ - **`part(name)`** gives one tree's `{ rehypePlugin, components }`, for a text drawn as several
688
+ trees (a heading in a title slot, the body below); the result's own are the default part's.
689
+ Each part diffs its own previous reading, and the parts share one switch: one number, one
690
+ timer, one timeline.
691
+ - **`active`** is true while a switch's marks are shown.
692
+ - **Identities.** `components` never changes; `rehypePlugin` and each part keep theirs while
693
+ nothing changes (they change as a switch starts and ends, and with a plain swap), so a
694
+ memoised Markdown parses again only then: keep the plugin list memoised on `rehypePlugin`.
695
+ Inline `skip` and `near` change nothing.
696
+ - **Plugin order.** `rehypePlugin` goes after the plugins that shape the text it reads (with
697
+ `blockAttribute`, the one that numbers the blocks), and before those that add search marks,
698
+ which must skip `[data-change=removed]`.
699
+ - **`<ChangingText changeKey>{string}</ChangingText>`** does the same for a plain string, with the
700
+ same key rules, `animate` and `speed`, rendered as it is, with no wrapper.
701
+ - **`changesIn(from, to)`**, the diff of two plain texts (`Change[]`: `word` and `letters` spans of
702
+ `to`, and `removed` ones of no width at their place, carrying the old letters as `text`), and
703
+ **`readText(tree, options?)`**, the reading of a hast tree that both sides use, are exported for
704
+ an app's own use.
705
+ - **`changeDurations(element?, speed?, mark?)`** gives `{ plain, removals }`, in ms, when a
706
+ switch's marks may go: `mark.durations(element, speed)`, else vultus's defaults (below). The hook
707
+ times each switch with it, with the lent mark, at `near`'s container (else none) and the
708
+ switch's speed.
709
+
710
+ ### The lent mark
711
+
712
+ The marks are drawn by the `ChangeMark` in `VultusComponents` (with vultus-antd,
713
+ `<VultusProvider components={{ ChangeMark }}>`; without it, a `VultusComponentsContext.Provider`).
714
+ It is a component drawing one mark, nested as the changes are (letters inside their word), with
715
+ these props (`ChangeMarkProps`):
716
+
717
+ - `variant` (`ChangeMarkVariant`): `change`, a changed word, lightly; `change-strong`, its changed
718
+ letters inside it, more strongly (a switch with no removed letters); on a switch with removed
719
+ letters, `change-removed`, the old letters that went, at their place, and `change-added`, the
720
+ new ones; `change-replaced`, a replacement, around exactly one `change-removed` and one
721
+ `change-added` (old and new letters at one place);
722
+ - `timeline`: `'removals'` on a word while the switch is on the removals timeline, so that it
723
+ waits with the removed and added letters;
724
+ - `speed`: the switch's (none: normal);
725
+ - `data-change`: the change's level (`word`, `letters`, `removed`, `replaced`), for the element
726
+ the mark draws;
727
+ - `children`.
728
+
729
+ Each switch's marks are new elements (vultus keys them by the switch), so a look timed from its
730
+ element's insertion starts again with each switch. Removed letters are not the page's text: a mark
731
+ keeps them away from assistive technology, the tab order and a selection (`aria-hidden`, `inert`,
732
+ `user-select: none`).
733
+
734
+ Its timings travel with it, as they belong to its look (its CSS): a static
735
+ **`durations(element, speed)`** gives `{ plain, removals }`, when its marks may go on each
736
+ timeline, in ms from the commit that shows the new text, at `speed`, read at `element` (`near`'s
737
+ container, else `undefined`). A lent mark without `durations` gets vultus's defaults. The types its
738
+ props and timings name (`ChangeLevel`, `ChangeSpeed`, `ChangeDurations`) come from `vultus-core`
739
+ too, as types only.
740
+
741
+ The hook times a switch by the mark lent where the hook is called, and the marks are drawn by the
742
+ one lent where they render: keep both under one provider, so that the look and its timings agree.
743
+
744
+ ```tsx
745
+ import { version } from 'react';
746
+ import type { ChangeMarkComponent, ChangeMarkProps } from 'vultus-core';
747
+
748
+ // `inert` as this React takes it: a boolean from 19 on; 18 needs '', which 19 reads as false.
749
+ const INERT = (Number.parseInt(version, 10) >= 19 ? { inert: true } : { inert: '' }) as { inert?: boolean };
750
+
751
+ const FadeMark: ChangeMarkComponent = Object.assign(
752
+ ({ variant, 'data-change': change, children }: ChangeMarkProps) => {
753
+ const removed = variant === 'change-removed' ? { 'aria-hidden': true, ...INERT } : {};
754
+ return <mark className={`fade-${variant}`} data-change={change} {...removed}>{children}</mark>;
755
+ },
756
+ { durations: () => ({ plain: 1500, removals: 2500 }) }, // when fade.css's animations end
757
+ );
758
+
759
+ <VultusProvider components={{ ChangeMark: FadeMark }}>{app}</VultusProvider>
760
+ ```
761
+
762
+ ### Without a lent mark
763
+
764
+ vultus's fallback is static marks in inline styles, with no stylesheet and no animation, each a
765
+ `mark` carrying `data-change`: `change`, `change-strong` and `change-added` a translucent green
766
+ background; `change-removed` a translucent red one, struck through (and `aria-hidden`, `inert`,
767
+ `user-select: none`); `change-replaced` drawn as its new letters (the old ones in it not
768
+ displayed). The colours are fixed and translucent, so they read on a light and a dark background
769
+ alike. Its timings are vultus's defaults: the marks go 1.55 s after the switch on the plain
770
+ timeline and 2.3 s after it on removals, at every speed, so a switch still ends.
771
+
772
+ ### Example
773
+
774
+ A task page shaped like Praeceptor's: one Markdown content drawn as two trees (its leading
775
+ heading in the title slot, the body below), over the app's own block numbering and leave-outs.
776
+ `TaskTextProps`, `rehypeBlocks`, `rehypeSearch` and `leadingHeading` stand for the app's own.
777
+
778
+ ```tsx
779
+ import { useMemo } from 'react';
780
+ import type { Element } from 'hast';
781
+ import { Markdown } from 'vultus-antd';
782
+ import { useTextChanges } from 'vultus-core/changes';
783
+
784
+ /** What the reader does not read as text: a footnote's link back, KaTeX's output. */
785
+ const skip = (element: Element) =>
786
+ String(element.properties.className ?? '').includes('katex')
787
+ || (element.tagName === 'a' && element.properties.dataFootnoteBackref !== undefined);
788
+
789
+ function TaskText({ task, markdown, lang, pane }: TaskTextProps) {
790
+ const changes = useTextChanges(markdown, {
791
+ // textOf: the text this task is a version of. Another version of the same text, in the same
792
+ // language, lights up; anything else shows plainly.
793
+ key: `${task.textOf ?? task.id}/${lang}`,
794
+ near: pane ? { container: pane, blocks: 3 } : undefined, // the blocks in view, 3 more each way
795
+ blockAttribute: 'data-block', // rehypeBlocks numbers them already
796
+ skip,
797
+ });
798
+ const heading = changes.part('heading');
799
+ const body = changes.part('body');
800
+ const { title, rest } = leadingHeading(markdown);
801
+ // Memoised on the plugin: a new list every render would make Markdown parse every render.
802
+ const headingPlugins = useMemo(() => [heading.rehypePlugin], [heading.rehypePlugin]);
803
+ const bodyPlugins = useMemo(() => [rehypeBlocks, body.rehypePlugin, rehypeSearch], [body.rehypePlugin]);
804
+ return (
805
+ <>
806
+ <h2><Markdown inline rehypePlugins={headingPlugins} components={heading.components}>{title}</Markdown></h2>
807
+ <Markdown rehypePlugins={bodyPlugins} components={body.components}>{rest}</Markdown>
808
+ </>
809
+ );
810
+ }
811
+ ```
812
+
813
+ An app with components of its own merges the hook's over them, memoised:
814
+ `useMemo(() => ({ ...mine, ...body.components }), [body.components])`.
815
+
816
+ ### Known gaps
817
+
818
+ Known and not fixed yet, all in what is marked and where, not in how a mark looks:
819
+
820
+ - A word removed altogether right beside a changed word is drawn inside that word's mark (whose
821
+ span runs from white space to white space), not as a removal of its own.
822
+ - Punctuation replaced by other punctuation is not drawn as a replacement: the old and the new
823
+ show side by side.
824
+ - A removed run that starts with a word and touches punctuation, where the new text keeps a space
825
+ at that place, shows after that space.
826
+ - With `near` as the blocks on screen, which go by the innermost blocks, the first lines of an
827
+ outer block in a deeply nested outline can fall outside the range, and are not marked.
828
+
606
829
  ## Distribution
607
830
 
608
831
  This package ships compiled ESM (`dist/`) with TypeScript declarations to
@@ -1,4 +1,6 @@
1
1
  import { type ComponentType, type ReactNode } from 'react';
2
+ import type { ChangeDurations, ChangeSpeed } from './changes/changeDurations.js';
3
+ import type { ChangeLevel } from './changes/changesIn.js';
2
4
  /** A spinner an app lends to vultus/optio, rendered in place of their native loading indicators. */
3
5
  export interface SpinnerProps {
4
6
  /** The spinner's identity: stable across re-renders and remounts, unique on the page (after scoping). */
@@ -9,9 +11,48 @@ export interface SpinnerProps {
9
11
  label?: string;
10
12
  }
11
13
  export type SpinnerComponent = ComponentType<SpinnerProps>;
14
+ /**
15
+ * What a change mark draws (`vultus-core/changes`): `change`, a changed word, lightly;
16
+ * `change-strong`, its changed letters inside it, more strongly (a switch with no removed letters);
17
+ * on a switch with removed letters, `change-removed`, the old letters that went, at their place,
18
+ * and `change-added`, the new ones; `change-replaced`, a replacement, around exactly one
19
+ * `change-removed` and one `change-added` (old and new letters at one place).
20
+ */
21
+ export type ChangeMarkVariant = 'change' | 'change-strong' | 'change-removed' | 'change-added' | 'change-replaced';
22
+ /**
23
+ * A change mark's props, as vultus's text changes give them, one mark per change, nested as the
24
+ * changes are (letters inside their word). Each switch's marks are new elements (vultus keys them
25
+ * by the switch), so a look timed from its element's insertion starts with each switch.
26
+ */
27
+ export interface ChangeMarkProps {
28
+ variant: ChangeMarkVariant;
29
+ /** On a word (`change`), while the switch is on the removals timeline: it waits with the
30
+ * removed and added letters, holding them or not. */
31
+ timeline?: 'removals';
32
+ /** How fast the switch's marks run, the same for every mark of it; none: normal. */
33
+ speed?: ChangeSpeed;
34
+ /** The change's level, for the element the mark draws (`[data-change]`). */
35
+ 'data-change': ChangeLevel;
36
+ children?: ReactNode;
37
+ }
38
+ /**
39
+ * A change mark an app lends to vultus's text changes: a component drawing one mark, and, as a
40
+ * static property, `durations`: when a switch's marks may go, in ms from the commit that shows the
41
+ * new text, at `speed`, read at `element` (the near container, else none). The timings belong to
42
+ * the look, so they travel with it. Without `durations`, vultus's defaults; without a lent mark,
43
+ * vultus's fallback: static marks, inline styles.
44
+ *
45
+ * A mark keeps removed letters away from assistive technology, the tab order and a selection
46
+ * (`aria-hidden`, `inert`, `user-select: none`): they are not the page's text.
47
+ */
48
+ export type ChangeMarkComponent = ComponentType<ChangeMarkProps> & {
49
+ durations?(element: Element | undefined, speed: ChangeSpeed): ChangeDurations;
50
+ };
12
51
  /** Components an app lends to the libraries. */
13
52
  export interface VultusComponents {
14
53
  Spinner?: SpinnerComponent;
54
+ /** The change marks of `vultus-core/changes`. */
55
+ ChangeMark?: ChangeMarkComponent;
15
56
  }
16
57
  /**
17
58
  * The components an app lends to vultus/optio in place of their own UI. Default is `{}`
@@ -1 +1 @@
1
- {"version":3,"file":"Components.d.ts","sourceRoot":"","sources":["../src/Components.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAsC,KAAK,aAAa,EAAE,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAE/F,oGAAoG;AACpG,MAAM,WAAW,YAAY;IAC3B,yGAAyG;IACzG,UAAU,EAAE,MAAM,CAAC;IACnB,4EAA4E;IAC5E,IAAI,CAAC,EAAE,OAAO,GAAG,SAAS,GAAG,OAAO,GAAG,MAAM,CAAC;IAC9C,gEAAgE;IAChE,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AACD,MAAM,MAAM,gBAAgB,GAAG,aAAa,CAAC,YAAY,CAAC,CAAC;AAE3D,gDAAgD;AAChD,MAAM,WAAW,gBAAgB;IAC/B,OAAO,CAAC,EAAE,gBAAgB,CAAC;CAC5B;AAED;;;;GAIG;AACH,eAAO,MAAM,uBAAuB,2CAAsC,CAAC;AAE3E,wBAAgB,mBAAmB,IAAI,gBAAgB,CAEtD;AAKD,+EAA+E;AAC/E,wBAAgB,YAAY,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,SAAS,CAAA;CAAE,+BAOtF;AAED,iGAAiG;AACjG,wBAAgB,aAAa,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAGtD"}
1
+ {"version":3,"file":"Components.d.ts","sourceRoot":"","sources":["../src/Components.tsx"],"names":[],"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B,CAAC,CAAC;IAC9C,OAAO,CAAC,GAAG,KAAK,EAAE,QAAQ,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AACxC,CAAC"}
1
+ {"version":3,"file":"Components.js","sourceRoot":"","sources":["../src/Components.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,OAAO,EAAsC,MAAM,OAAO,CAAC;AA+D/F;;;;GAIG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,aAAa,CAAmB,EAAE,CAAC,CAAC;AAE3E,MAAM,UAAU,mBAAmB;IACjC,OAAO,UAAU,CAAC,uBAAuB,CAAC,CAAC;AAC7C,CAAC;AAED,qGAAqG;AACrG,MAAM,mBAAmB,GAAG,aAAa,CAAW,EAAE,CAAC,CAAC;AAExD,+EAA+E;AAC/E,MAAM,UAAU,YAAY,CAAC,EAAE,IAAI,EAAE,QAAQ,EAA0C;IACrF,MAAM,KAAK,GAAG,UAAU,CAAC,mBAAmB,CAAC,CAAC;IAC9C,uFAAuF;IACvF,uFAAuF;IACvF,2DAA2D;IAC3D,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC,GAAG,KAAK,EAAE,IAAI,CAAC,EAAE,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC;IAC7D,OAAO,KAAC,mBAAmB,CAAC,QAAQ,IAAC,KAAK,EAAE,KAAK,YAAG,QAAQ,GAAgC,CAAC;AAC/F,CAAC;AAED,iGAAiG;AACjG,MAAM,UAAU,aAAa,CAAC,QAAgB;IAC5C,MAAM,KAAK,GAAG,UAAU,CAAC,mBAAmB,CAAC,CAAC;IAC9C,OAAO,CAAC,GAAG,KAAK,EAAE,QAAQ,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AACxC,CAAC"}
@@ -18,6 +18,15 @@ export interface ArgStore {
18
18
  subscribe(listener: () => void): () => void;
19
19
  /** The href a write of `changes` would produce, where the store has one (a URL store); omitted otherwise. */
20
20
  hrefFor?(changes: RawChange[]): string;
21
+ /**
22
+ * What a hook using an argument knows of it, told as the hook renders, on every render, so
23
+ * idempotent; it notifies nobody. `permanent`: the key stays when the store goes somewhere else
24
+ * (a URL store, when a path token changes). A store that never drops a key omits this; a wrapper
25
+ * store forwards it, or the store it wraps is told nothing.
26
+ */
27
+ declare?(key: string, facts: {
28
+ permanent: boolean;
29
+ }): void;
21
30
  }
22
31
  /** An ArgStore over a plain object, for tests and demos. `snapshot()` is a copy, for assertions. */
23
32
  export declare function memoryStore(initial?: Record<string, string>): ArgStore & {
@@ -1 +1 @@
1
- {"version":3,"file":"argStore.d.ts","sourceRoot":"","sources":["../src/argStore.ts"],"names":[],"mappings":"AAAA,kHAAkH;AAClH,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG,SAAS,CAAC;AAE9C,gGAAgG;AAChG,MAAM,WAAW,SAAS;IACxB,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,GAAG,SAAS,CAAC;CACzB;AAED;;;;;GAKG;AACH,MAAM,WAAW,QAAQ;IACvB,IAAI,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;IACtC,kHAAkH;IAClH,KAAK,CAAC,OAAO,EAAE,SAAS,EAAE,EAAE,MAAM,EAAE,YAAY,GAAG,IAAI,CAAC;IACxD,SAAS,CAAC,QAAQ,EAAE,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC;IAC5C,6GAA6G;IAC7G,OAAO,CAAC,CAAC,OAAO,EAAE,SAAS,EAAE,GAAG,MAAM,CAAC;CACxC;AAED,oGAAoG;AACpG,wBAAgB,WAAW,CAAC,OAAO,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAM,GAAG,QAAQ,GAAG;IAAE,QAAQ,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAAE,CAuBnH"}
1
+ {"version":3,"file":"argStore.d.ts","sourceRoot":"","sources":["../src/argStore.ts"],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D,SAAS,CAAC,QAAQ;YAChB,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;YACxB,OAAO,GAAG,EAAE,CAAC,SAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;QAC1C,CAAC;QACD,QAAQ;YACN,OAAO,EAAE,GAAG,IAAI,EAAE,CAAC;QACrB,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,85 @@
1
+ import { type ComponentPropsWithoutRef, type ReactElement, type ReactNode } from 'react';
2
+ import type { ChangeSpeed } from './changeDurations.js';
3
+ import type { ChangeLevel } from './changesIn.js';
4
+ /**
5
+ * The timeline a switch's marks run on: `removals` for a switch that shows removed letters, the
6
+ * old letters cut away before the new ones are uncovered; `plain` for one that shows none, its
7
+ * letters lit at once. One per switch, over all its parts: a lent mark's removal timeline may
8
+ * light a word later than its plain one, so a switch's parts on two timelines would light apart
9
+ * (a switch with any removal uses the removals timeline for all its letters).
10
+ */
11
+ export type ChangeTimeline = 'plain' | 'removals';
12
+ /** A switch as its marks draw it: its number (0 outside one), its timeline (`undefined`: not
13
+ * decided yet, drawn `plain`), and its speed (the lent mark's `speed`; none: normal), taken as it
14
+ * started. */
15
+ export interface ChangeState {
16
+ number: number;
17
+ timeline: ChangeTimeline | undefined;
18
+ speed?: ChangeSpeed;
19
+ }
20
+ /** Where the marks read the switch's state from: the hook's store, read-only. */
21
+ export interface ChangeSource {
22
+ subscribe(listener: () => void): () => void;
23
+ getSnapshot(): ChangeState;
24
+ }
25
+ /** The hook's store of the switch's state: `set` replaces it, and with `notify` re-renders the
26
+ * marks (not the trees: no re-parse). */
27
+ export interface ChangeStore extends ChangeSource {
28
+ set(state: ChangeState, notify: boolean): void;
29
+ }
30
+ /** A store of the switch's state, from `initial` (by default, no switch: number 0, undecided). */
31
+ export declare function changeStore(initial?: ChangeState): ChangeStore;
32
+ /**
33
+ * A change from another version of the text, as the changes plugin marks it (`changesPlugin`): a
34
+ * changed word (`word`), its changed letters inside it (`letters`), the old letters that went
35
+ * (`removed`), and a replacement around old letters and the new ones at their place (`replaced`),
36
+ * each carrying `data-change`, its level. The one place the look is drawn.
37
+ *
38
+ * The look is the lent mark's: the `ChangeMark` an app lends through `VultusComponents`; without
39
+ * one, vultus's fallback (`FallbackMark`), static marks. `variant="change"` on the word, lightly.
40
+ * On the `plain` timeline (and until it is decided), `variant="change-strong"` on its letters
41
+ * inside it, more strongly: lit at once, then faded, each mark timed from its own insertion. On the
42
+ * `removals` timeline, the old letters in `variant="change-removed"` (cut away first) and the new
43
+ * ones in `variant="change-added"` (uncovered after); every word takes `timeline="removals"`, so
44
+ * that one holding neither removed nor added letters (the `vei` of `*hí*vei`, a piece of a word
45
+ * split by markup) waits with the rest rather than lighting at once. `removed` is drawn so on
46
+ * either timeline: a switch that shows any is on `removals`.
47
+ *
48
+ * A replacement (`replaced`), on the `removals` timeline, is `variant="change-replaced"` around its
49
+ * two, which morph from the old letters to the new. A lent mark may measure both letters once, as
50
+ * the wrapper is put in, so on `plain` and while undecided the two are drawn as they are, unwrapped
51
+ * (a Fragment): there the new letters are `change-strong`, with no letters span to measure, and the
52
+ * wrapper would close to no width. It is put in, and measures, in the commit that puts the switch
53
+ * on `removals`, before the paint.
54
+ *
55
+ * Keyed by `number`, the switch's: a lent mark's fade may belong to the element, timed from its
56
+ * insertion, and react-markdown keys an element by its tag's count among its siblings, so the next
57
+ * switch's mark on the same word has the same key. A new number draws new marks, lit from the
58
+ * start, never the switch before's, half faded or gone; a render within one keeps them, fading on.
59
+ *
60
+ * Every mark takes the switch's `speed` (the lent mark's; none: normal), so its words and letters
61
+ * run one timeline.
62
+ */
63
+ export declare function ChangeMark({ level, number, timeline, speed, children }: {
64
+ level: ChangeLevel;
65
+ number: number;
66
+ timeline: ChangeTimeline | undefined;
67
+ speed?: ChangeSpeed;
68
+ children?: ReactNode;
69
+ }): ReactElement;
70
+ /** An `ins` as react-markdown gives it to its `components`: its props, and the hast `node`. */
71
+ export type InsProps = ComponentPropsWithoutRef<'ins'> & {
72
+ node?: unknown;
73
+ };
74
+ /** The components entry an app merges into its Markdown's `components`. */
75
+ export interface ChangeComponents {
76
+ ins: (props: InsProps) => ReactElement;
77
+ }
78
+ /**
79
+ * The `ins` entry drawing the change marks with `source`'s state: an `ins` whose `data-change` is a
80
+ * change level is a `ChangeMark` with the switch's number, timeline and speed; any other `ins` is
81
+ * drawn as itself (react-markdown's `node` dropped). One frozen object per source, so its identity
82
+ * never changes: an app's Markdown memoises on its `components`.
83
+ */
84
+ export declare function changeComponents(source: ChangeSource): ChangeComponents;
85
+ //# sourceMappingURL=ChangeMark.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ChangeMark.d.ts","sourceRoot":"","sources":["../../src/changes/ChangeMark.tsx"],"names":[],"mappings":"AAAA,OAAO,EAC6C,KAAK,wBAAwB,EAAE,KAAK,YAAY,EAAE,KAAK,SAAS,EACnH,MAAM,OAAO,CAAC;AAEf,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAGlD;;;;;;GAMG;AACH,MAAM,MAAM,cAAc,GAAG,OAAO,GAAG,UAAU,CAAC;AAElD;;eAEe;AACf,MAAM,WAAW,WAAW;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,cAAc,GAAG,SAAS,CAAC;IACrC,KAAK,CAAC,EAAE,WAAW,CAAC;CACrB;AAED,iFAAiF;AACjF,MAAM,WAAW,YAAY;IAC3B,SAAS,CAAC,QAAQ,EAAE,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC;IAC5C,WAAW,IAAI,WAAW,CAAC;CAC5B;AAED;0CAC0C;AAC1C,MAAM,WAAW,WAAY,SAAQ,YAAY;IAC/C,GAAG,CAAC,KAAK,EAAE,WAAW,EAAE,MAAM,EAAE,OAAO,GAAG,IAAI,CAAC;CAChD;AAED,kGAAkG;AAClG,wBAAgB,WAAW,CAAC,OAAO,GAAE,WAAgD,GAAG,WAAW,CAkBlG;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,wBAAgB,UAAU,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE;IACvE,KAAK,EAAE,WAAW,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,cAAc,GAAG,SAAS,CAAC;IACrC,KAAK,CAAC,EAAE,WAAW,CAAC;IACpB,QAAQ,CAAC,EAAE,SAAS,CAAC;CACtB,GAAG,YAAY,CAWf;AAED,+FAA+F;AAC/F,MAAM,MAAM,QAAQ,GAAG,wBAAwB,CAAC,KAAK,CAAC,GAAG;IAAE,IAAI,CAAC,EAAE,OAAO,CAAA;CAAE,CAAC;AAE5E,2EAA2E;AAC3E,MAAM,WAAW,gBAAgB;IAC/B,GAAG,EAAE,CAAC,KAAK,EAAE,QAAQ,KAAK,YAAY,CAAC;CACxC;AAOD;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,YAAY,GAAG,gBAAgB,CAavE"}
@@ -0,0 +1,113 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { Fragment, useEffect, useLayoutEffect, useReducer, } from 'react';
3
+ import { useVultusComponents } from '../Components.js';
4
+ import { FallbackMark } from './FallbackMark.js';
5
+ /** A store of the switch's state, from `initial` (by default, no switch: number 0, undecided). */
6
+ export function changeStore(initial = { number: 0, timeline: undefined }) {
7
+ let state = initial;
8
+ const listeners = new Set();
9
+ return {
10
+ subscribe(listener) {
11
+ listeners.add(listener);
12
+ return () => {
13
+ listeners.delete(listener);
14
+ };
15
+ },
16
+ getSnapshot() {
17
+ return state;
18
+ },
19
+ set(next, notify) {
20
+ state = next;
21
+ if (notify)
22
+ for (const listener of Array.from(listeners))
23
+ listener();
24
+ },
25
+ };
26
+ }
27
+ /**
28
+ * A change from another version of the text, as the changes plugin marks it (`changesPlugin`): a
29
+ * changed word (`word`), its changed letters inside it (`letters`), the old letters that went
30
+ * (`removed`), and a replacement around old letters and the new ones at their place (`replaced`),
31
+ * each carrying `data-change`, its level. The one place the look is drawn.
32
+ *
33
+ * The look is the lent mark's: the `ChangeMark` an app lends through `VultusComponents`; without
34
+ * one, vultus's fallback (`FallbackMark`), static marks. `variant="change"` on the word, lightly.
35
+ * On the `plain` timeline (and until it is decided), `variant="change-strong"` on its letters
36
+ * inside it, more strongly: lit at once, then faded, each mark timed from its own insertion. On the
37
+ * `removals` timeline, the old letters in `variant="change-removed"` (cut away first) and the new
38
+ * ones in `variant="change-added"` (uncovered after); every word takes `timeline="removals"`, so
39
+ * that one holding neither removed nor added letters (the `vei` of `*hí*vei`, a piece of a word
40
+ * split by markup) waits with the rest rather than lighting at once. `removed` is drawn so on
41
+ * either timeline: a switch that shows any is on `removals`.
42
+ *
43
+ * A replacement (`replaced`), on the `removals` timeline, is `variant="change-replaced"` around its
44
+ * two, which morph from the old letters to the new. A lent mark may measure both letters once, as
45
+ * the wrapper is put in, so on `plain` and while undecided the two are drawn as they are, unwrapped
46
+ * (a Fragment): there the new letters are `change-strong`, with no letters span to measure, and the
47
+ * wrapper would close to no width. It is put in, and measures, in the commit that puts the switch
48
+ * on `removals`, before the paint.
49
+ *
50
+ * Keyed by `number`, the switch's: a lent mark's fade may belong to the element, timed from its
51
+ * insertion, and react-markdown keys an element by its tag's count among its siblings, so the next
52
+ * switch's mark on the same word has the same key. A new number draws new marks, lit from the
53
+ * start, never the switch before's, half faded or gone; a render within one keeps them, fading on.
54
+ *
55
+ * Every mark takes the switch's `speed` (the lent mark's; none: normal), so its words and letters
56
+ * run one timeline.
57
+ */
58
+ export function ChangeMark({ level, number, timeline, speed, children }) {
59
+ const Mark = useVultusComponents().ChangeMark ?? FallbackMark;
60
+ if (level === 'replaced' && timeline !== 'removals')
61
+ return _jsx(Fragment, { children: children }, number);
62
+ const variant = level === 'word' ? 'change'
63
+ : level === 'removed' ? 'change-removed'
64
+ : level === 'replaced' ? 'change-replaced'
65
+ : timeline === 'removals' ? 'change-added' : 'change-strong';
66
+ return (_jsx(Mark, { variant: variant, timeline: level === 'word' && timeline === 'removals' ? 'removals' : undefined, speed: speed, "data-change": level, children: children }, number));
67
+ }
68
+ const LEVELS = new Set(['word', 'letters', 'removed', 'replaced']);
69
+ /** The entries made, one per source. */
70
+ const made = new WeakMap();
71
+ /**
72
+ * The `ins` entry drawing the change marks with `source`'s state: an `ins` whose `data-change` is a
73
+ * change level is a `ChangeMark` with the switch's number, timeline and speed; any other `ins` is
74
+ * drawn as itself (react-markdown's `node` dropped). One frozen object per source, so its identity
75
+ * never changes: an app's Markdown memoises on its `components`.
76
+ */
77
+ export function changeComponents(source) {
78
+ let components = made.get(source);
79
+ if (!components) {
80
+ const ins = ({ node, ...rest }) => {
81
+ const level = rest['data-change'];
82
+ return typeof level === 'string' && LEVELS.has(level)
83
+ ? _jsx(LiveMark, { source: source, level: level, children: rest.children })
84
+ : _jsx("ins", { ...rest });
85
+ };
86
+ components = Object.freeze({ ins });
87
+ made.set(source, components);
88
+ }
89
+ return components;
90
+ }
91
+ // `useLayoutEffect` warns when it does nothing on the server; fall back to a plain effect there.
92
+ const useIsomorphicLayoutEffect = typeof window !== 'undefined' ? useLayoutEffect : useEffect;
93
+ /**
94
+ * A `ChangeMark` drawn with `source`'s state as it reads it in render, re-drawn on its
95
+ * notifications alone (its parents are not re-rendered). It subscribes in a layout effect, not
96
+ * through `useSyncExternalStore`, which subscribes in the passive phase: the hook decides the
97
+ * timeline in its own layout effect, which runs after its children's, so the marks have subscribed
98
+ * by then and take it before the paint. At subscription it re-draws if the state changed since its
99
+ * render.
100
+ */
101
+ function LiveMark({ source, level, children }) {
102
+ const [, redraw] = useReducer((count) => count + 1, 0);
103
+ const state = source.getSnapshot();
104
+ useIsomorphicLayoutEffect(() => {
105
+ const unsubscribe = source.subscribe(redraw);
106
+ // `state` is the one this effect's render read.
107
+ if (source.getSnapshot() !== state)
108
+ redraw();
109
+ return unsubscribe;
110
+ }, [source]);
111
+ return _jsx(ChangeMark, { level: level, number: state.number, timeline: state.timeline, speed: state.speed, children: children });
112
+ }
113
+ //# sourceMappingURL=ChangeMark.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ChangeMark.js","sourceRoot":"","sources":["../../src/changes/ChangeMark.tsx"],"names":[],"mappings":";AAAA,OAAO,EACL,QAAQ,EAAE,SAAS,EAAE,eAAe,EAAE,UAAU,GACjD,MAAM,OAAO,CAAC;AACf,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAGvD,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAgCjD,kGAAkG;AAClG,MAAM,UAAU,WAAW,CAAC,UAAuB,EAAE,MAAM,EAAE,CAAC,EAAE,QAAQ,EAAE,SAAS,EAAE;IACnF,IAAI,KAAK,GAAG,OAAO,CAAC;IACpB,MAAM,SAAS,GAAG,IAAI,GAAG,EAAc,CAAC;IACxC,OAAO;QACL,SAAS,CAAC,QAAQ;YAChB,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;YACxB,OAAO,GAAG,EAAE;gBACV,SAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;YAC7B,CAAC,CAAC;QACJ,CAAC;QACD,WAAW;YACT,OAAO,KAAK,CAAC;QACf,CAAC;QACD,GAAG,CAAC,IAAI,EAAE,MAAM;YACd,KAAK,GAAG,IAAI,CAAC;YACb,IAAI,MAAM;gBAAE,KAAK,MAAM,QAAQ,IAAI,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC;oBAAE,QAAQ,EAAE,CAAC;QACvE,CAAC;KACF,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,MAAM,UAAU,UAAU,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,QAAQ,EAMpE;IACC,MAAM,IAAI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C"}
@@ -0,0 +1,20 @@
1
+ import { type ReactElement } from 'react';
2
+ import type { ChangeSpeed } from './changeDurations.js';
3
+ export interface ChangingTextProps {
4
+ /** The string's identity: same key, new string animates; a new key swaps plainly. */
5
+ changeKey: string;
6
+ /** `false`: swap plainly once, under the same key too. */
7
+ animate?: boolean;
8
+ /** How fast a switch's marks run (`useTextChanges`' `speed`): `normal` by default, held per switch. */
9
+ speed?: ChangeSpeed;
10
+ children: string;
11
+ }
12
+ /**
13
+ * A plain string whose changes light up: `useTextChanges` for one string, with its key
14
+ * semantics (`changeKey`, `animate`) and `speed`. Rendered as it is, with no wrapper (a Fragment):
15
+ * the string's text as strings, its change marks through the hook's `ins` entry. The string is read
16
+ * inside a private `span`, never rendered: a text right under the root counts as between blocks,
17
+ * and would never be marked.
18
+ */
19
+ export declare function ChangingText({ changeKey, animate, speed, children }: ChangingTextProps): ReactElement;
20
+ //# sourceMappingURL=ChangingText.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ChangingText.d.ts","sourceRoot":"","sources":["../../src/changes/ChangingText.tsx"],"names":[],"mappings":"AACA,OAAO,EAAqB,KAAK,YAAY,EAAkB,MAAM,OAAO,CAAC;AAE7E,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAGxD,MAAM,WAAW,iBAAiB;IAChC,qFAAqF;IACrF,SAAS,EAAE,MAAM,CAAC;IAClB,0DAA0D;IAC1D,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,uGAAuG;IACvG,KAAK,CAAC,EAAE,WAAW,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,EAAE,SAAS,EAAE,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE,iBAAiB,GAAG,YAAY,CASrG"}