@quillmark/svelte 0.35.1 → 0.37.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (82) hide show
  1. package/README.md +30 -18
  2. package/THEMING.md +1 -1
  3. package/dist/core/address.d.ts +5 -0
  4. package/dist/core/address.js +14 -0
  5. package/dist/core/codec/decode.d.ts +4 -2
  6. package/dist/core/codec/decode.js +5 -2
  7. package/dist/core/codec/field.d.ts +42 -16
  8. package/dist/core/codec/field.js +97 -28
  9. package/dist/core/codec/index.d.ts +8 -5
  10. package/dist/core/codec/index.js +4 -5
  11. package/dist/core/codec/prose.css +25 -81
  12. package/dist/core/codec/review.d.ts +31 -26
  13. package/dist/core/codec/review.js +93 -169
  14. package/dist/core/codec/schema.d.ts +12 -2
  15. package/dist/core/codec/schema.js +27 -5
  16. package/dist/core/codec/shortcuts.d.ts +5 -4
  17. package/dist/core/codec/shortcuts.js +9 -8
  18. package/dist/core/codec/table-view.js +15 -3
  19. package/dist/core/codec/value-diff.d.ts +21 -0
  20. package/dist/core/codec/value-diff.js +83 -0
  21. package/dist/core/codec/value-plan.d.ts +29 -0
  22. package/dist/core/codec/value-plan.js +157 -0
  23. package/dist/core/theme.css +46 -15
  24. package/dist/core/tooltip.css +49 -0
  25. package/dist/core/tooltip.d.ts +6 -0
  26. package/dist/core/tooltip.js +176 -0
  27. package/dist/preview/Preview.svelte +22 -1
  28. package/dist/preview/controller.js +38 -0
  29. package/dist/preview/strings.d.ts +2 -0
  30. package/dist/preview/strings.js +1 -0
  31. package/dist/visual/ArrayField.svelte +374 -96
  32. package/dist/visual/Card.svelte +33 -12
  33. package/dist/visual/Card.svelte.d.ts +3 -0
  34. package/dist/visual/CardControls.svelte +3 -3
  35. package/dist/visual/DateField.svelte +47 -5
  36. package/dist/visual/DiagnosticList.svelte +3 -2
  37. package/dist/visual/EnumField.svelte +20 -5
  38. package/dist/visual/EnumField.svelte.d.ts +5 -0
  39. package/dist/visual/Field.svelte +56 -47
  40. package/dist/visual/FieldHint.svelte +20 -8
  41. package/dist/visual/FormatPopover.svelte +54 -20
  42. package/dist/visual/MatrixField.svelte +48 -6
  43. package/dist/visual/MatrixField.svelte.d.ts +5 -0
  44. package/dist/visual/NumberField.svelte +131 -6
  45. package/dist/visual/NumberField.svelte.d.ts +5 -0
  46. package/dist/visual/ObjectField.svelte +60 -18
  47. package/dist/visual/ProseField.svelte +21 -5
  48. package/dist/visual/ProseField.svelte.d.ts +5 -1
  49. package/dist/visual/ProseValue.svelte +49 -8
  50. package/dist/visual/ProseValue.svelte.d.ts +7 -1
  51. package/dist/visual/ReviewCard.svelte +400 -0
  52. package/dist/visual/ReviewCard.svelte.d.ts +20 -0
  53. package/dist/visual/ReviewProposal.svelte +98 -138
  54. package/dist/visual/ReviewProposal.svelte.d.ts +3 -6
  55. package/dist/visual/ReviewRows.svelte +6 -25
  56. package/dist/visual/ReviewRows.svelte.d.ts +1 -3
  57. package/dist/visual/SlashMenu.svelte +1 -0
  58. package/dist/visual/TipsCard.svelte +1 -1
  59. package/dist/visual/VariantField.svelte +45 -4
  60. package/dist/visual/VariantField.svelte.d.ts +5 -0
  61. package/dist/visual/VisualEditor.svelte +24 -9
  62. package/dist/visual/VisualEditor.svelte.d.ts +8 -1
  63. package/dist/visual/VisualEditorInner.svelte +917 -280
  64. package/dist/visual/VisualEditorInner.svelte.d.ts +8 -1
  65. package/dist/visual/controls.css +2 -2
  66. package/dist/visual/index.d.ts +2 -2
  67. package/dist/visual/proposals.d.ts +25 -24
  68. package/dist/visual/proposals.js +92 -32
  69. package/dist/visual/props.d.ts +18 -18
  70. package/dist/visual/review-order.d.ts +51 -0
  71. package/dist/visual/review-order.js +87 -0
  72. package/dist/visual/review.d.ts +94 -3
  73. package/dist/visual/review.js +37 -2
  74. package/dist/visual/review.svelte.d.ts +77 -20
  75. package/dist/visual/review.svelte.js +306 -49
  76. package/dist/visual/strings.d.ts +59 -25
  77. package/dist/visual/strings.js +90 -29
  78. package/dist/visual/structure.d.ts +17 -3
  79. package/dist/visual/structure.js +71 -5
  80. package/dist/visual/undo.svelte.d.ts +3 -1
  81. package/dist/visual/undo.svelte.js +7 -3
  82. package/package.json +2 -2
@@ -0,0 +1,83 @@
1
+ // A field's whole proposed value, drawn as a word diff over a leaf of lines: the words Accept would
2
+ // strike struck where they stand, the words it would write tinted beside them in their own
3
+ // formatting, nothing written. What is drawn is the difference between the leaf as it reads and
4
+ // what Accept would write (`planValue`), so the reader's words beside a proposal stay unstruck.
5
+ // The leaf holds its own text throughout, so the caret, a selection and a copy read what the field
6
+ // holds; taking the proposal is the field's own write, not this plugin's.
7
+ import { Plugin, PluginKey } from 'prosemirror-state';
8
+ import { Decoration, DecorationSet } from 'prosemirror-view';
9
+ import { DOMSerializer } from 'prosemirror-model';
10
+ import { scanContent, scanDoc } from './encode.js';
11
+ import { lineIndexOf, offsetToPM } from './positions.js';
12
+ import { decode } from './decode.js';
13
+ import { hasMarks } from './schema.js';
14
+ import { planValue, valueChanges } from './value-plan.js';
15
+ export const valueDiffKey = new PluginKey('qm-value-diff');
16
+ /** `[from, to)` of `c` as a value of its own, one line. */
17
+ function slice(c, from, to) {
18
+ const marks = (c.marks ?? []).flatMap((m) => {
19
+ const start = Math.max(m.start, from);
20
+ const end = Math.min(m.end, to);
21
+ return end > start ? [{ ...m, start: start - from, end: end - from }] : [];
22
+ });
23
+ return { text: c.text.slice(from, to), blocks: [{ id: '', kind: 'para' }], marks };
24
+ }
25
+ /** The proposed words as they would read: in their own formatting where the leaf holds marks. */
26
+ function inserted(schema, c, from, to) {
27
+ const part = slice(c, from, to);
28
+ if (!hasMarks(schema) || !part.marks?.length || part.text.includes('\n'))
29
+ return document.createTextNode(part.text);
30
+ const doc = decode(part, schema);
31
+ const inline = doc.firstChild?.isTextblock ? doc.firstChild.content : doc.content;
32
+ return DOMSerializer.fromSchema(schema).serializeFragment(inline);
33
+ }
34
+ function draw(state, p, planned) {
35
+ const scan = scanDoc(state.doc);
36
+ const live = scanContent(scan);
37
+ const index = lineIndexOf(scan);
38
+ const at = (offset) => offsetToPM(index, offset);
39
+ const { merged, outdated } = planValue(p.before, live, p.after);
40
+ const changes = valueChanges(live, merged);
41
+ planned?.(p.id, !changes.length ? 'applied' : outdated ? 'outdated' : 'open');
42
+ const decos = [];
43
+ const name = { 'data-qm-review': p.id };
44
+ const lit = p.lit ? ' qm-review-lit' : '';
45
+ changes.forEach(({ at: from, end, from: start, to }, n) => {
46
+ if (end > from)
47
+ decos.push(Decoration.inline(at(from), at(end), {
48
+ nodeName: 'del',
49
+ class: `qm-review-del${lit}`,
50
+ ...name
51
+ }));
52
+ if (to <= start)
53
+ return;
54
+ const text = merged.text.slice(start, to);
55
+ decos.push(Decoration.widget(end > from ? at(end) : at(from), () => {
56
+ const el = document.createElement('ins');
57
+ el.className = `qm-review-ins${lit}`;
58
+ el.contentEditable = 'false';
59
+ el.setAttribute('data-qm-review', p.id);
60
+ el.append(inserted(state.schema, merged, start, to));
61
+ return el;
62
+ }, {
63
+ side: end > from ? -1 : 1,
64
+ key: `value:${p.id}:${n}:${start}:${JSON.stringify(slice(merged, start, to).marks)}:${text}:${p.lit}`
65
+ }));
66
+ });
67
+ return DecorationSet.create(state.doc, decos);
68
+ }
69
+ /**
70
+ * The plugin, reading the proposal live: a caller that moves it redraws with `setProps`.
71
+ * `planned` hears, on each draw, how the proposal stands against what the leaf holds.
72
+ */
73
+ export function valueDiffPlugin(read, planned) {
74
+ return new Plugin({
75
+ key: valueDiffKey,
76
+ props: {
77
+ decorations(state) {
78
+ const p = read();
79
+ return p ? draw(state, p, planned) : null;
80
+ }
81
+ }
82
+ });
83
+ }
@@ -0,0 +1,29 @@
1
+ import type { Content } from '@quillmark/wasm';
2
+ /** `[at, end)` of one value gives way to `[from, to)` of another. */
3
+ export interface ValueChange {
4
+ at: number;
5
+ end: number;
6
+ from: number;
7
+ to: number;
8
+ }
9
+ /** What Accept writes, and whether the reader's own change meets the proposal. */
10
+ export interface ValuePlan {
11
+ merged: Content;
12
+ outdated: boolean;
13
+ }
14
+ /** A field value of words as a `Content`: a string by its lines, a rich or plain text value as it
15
+ * is, nothing as the empty line. `undefined` for a value that is not words. */
16
+ export declare function asContent(value: unknown): Content | undefined;
17
+ /**
18
+ * The changes that take `a` to `b`, in order and apart: the words that differ, then, in the words
19
+ * both hold, each run whose formatting differs, which gives way to itself as `b` formats it.
20
+ */
21
+ export declare function valueChanges(a: Content, b: Content): ValueChange[];
22
+ /**
23
+ * What Accept writes over `live`, the value as it reads now: `after` where there is no `before`,
24
+ * or where the reader has changed nothing since; else each change from `before` to `after` carried
25
+ * onto `live`, the reader's own changes kept. Where a change of the reader's meets one of the
26
+ * proposal's, or the value holds more than lines of words, it is `after` whole and outdated, unless
27
+ * the value already reads as `after`.
28
+ */
29
+ export declare function planValue(before: Content | undefined, live: Content, after: Content): ValuePlan;
@@ -0,0 +1,157 @@
1
+ import { wordDiff } from './review-diff.js';
2
+ /** Line `k`'s block where a value of words names none of its own. */
3
+ const para = (_, k) => ({ id: `b${k}`, kind: 'para' });
4
+ /** A field value of words as a `Content`: a string by its lines, a rich or plain text value as it
5
+ * is, nothing as the empty line. `undefined` for a value that is not words. */
6
+ export function asContent(value) {
7
+ if (value == null)
8
+ return { text: '', blocks: [para(null, 0)] };
9
+ if (typeof value === 'string')
10
+ return { text: value, blocks: value.split('\n').map(para) };
11
+ if (typeof value !== 'object' || typeof value.text !== 'string')
12
+ return undefined;
13
+ const v = value;
14
+ return Array.isArray(v.blocks) ? v : { ...v, blocks: v.text.split('\n').map(para) };
15
+ }
16
+ const markKey = (m) => JSON.stringify([m.type, 'attrs' in m ? (m.attrs ?? null) : null]);
17
+ /** The marks over each offset of `c`, as one key per offset. */
18
+ function marksAt(c) {
19
+ const out = new Array(c.text.length);
20
+ for (let i = 0; i < out.length; i++)
21
+ out[i] = [];
22
+ for (const m of c.marks ?? [])
23
+ for (let i = m.start; i < m.end && i < out.length; i++)
24
+ out[i].push(markKey(m));
25
+ return out.map((keys) => keys.sort().join('|'));
26
+ }
27
+ /**
28
+ * The changes that take `a` to `b`, in order and apart: the words that differ, then, in the words
29
+ * both hold, each run whose formatting differs, which gives way to itself as `b` formats it.
30
+ */
31
+ export function valueChanges(a, b) {
32
+ const words = [];
33
+ let shift = 0;
34
+ for (const h of wordDiff(a.text, b.text)) {
35
+ const from = h.at + shift;
36
+ words.push({ at: h.at, end: h.end, from, to: from + h.insert.length });
37
+ shift += h.insert.length - (h.end - h.at);
38
+ }
39
+ if (!(a.marks?.length || b.marks?.length))
40
+ return words;
41
+ const ma = marksAt(a);
42
+ const mb = marksAt(b);
43
+ const out = [];
44
+ let i = 0;
45
+ let j = 0;
46
+ const kept = (end) => {
47
+ let run;
48
+ for (; i < end; i++, j++) {
49
+ if (ma[i] === mb[j]) {
50
+ if (run)
51
+ out.push(run);
52
+ run = undefined;
53
+ continue;
54
+ }
55
+ if (run) {
56
+ run.end = i + 1;
57
+ run.to = j + 1;
58
+ }
59
+ else
60
+ run = { at: i, end: i + 1, from: j, to: j + 1 };
61
+ }
62
+ if (run)
63
+ out.push(run);
64
+ };
65
+ for (const w of words) {
66
+ kept(w.at);
67
+ out.push(w);
68
+ i = w.end;
69
+ j = w.to;
70
+ }
71
+ kept(a.text.length);
72
+ return out;
73
+ }
74
+ /** Whether two changes over one value touch the same words: they overlap, or one inserts inside
75
+ * the other, or both insert at one place. */
76
+ function meet(p, r) {
77
+ if (p.at < r.end && r.at < p.end)
78
+ return true;
79
+ if (p.at === p.end && r.at === r.end)
80
+ return p.at === r.at;
81
+ if (p.at === p.end)
82
+ return p.at > r.at && p.at < r.end;
83
+ if (r.at === r.end)
84
+ return r.at > p.at && r.at < p.end;
85
+ return false;
86
+ }
87
+ /** The marks of `[from, to)` of `c`, from `at`. */
88
+ function marksIn(c, from, to, at) {
89
+ return (c.marks ?? []).flatMap((m) => {
90
+ const start = Math.max(m.start, from);
91
+ const end = Math.min(m.end, to);
92
+ return end > start ? [{ ...m, start: start - from + at, end: end - from + at }] : [];
93
+ });
94
+ }
95
+ /** One mark for each run of touching marks of one kind. */
96
+ function joinMarks(marks) {
97
+ const sorted = [...marks].sort((x, y) => x.start - y.start || x.end - y.end);
98
+ const out = [];
99
+ for (const m of sorted) {
100
+ const prev = out.find((o) => markKey(o) === markKey(m) && o.end >= m.start);
101
+ if (prev)
102
+ prev.end = Math.max(prev.end, m.end);
103
+ else
104
+ out.push({ ...m });
105
+ }
106
+ return out.sort((x, y) => x.start - y.start || x.end - y.end);
107
+ }
108
+ /** `c` with `[at, end)` giving way to `[from, to)` of `src`, marks and all. */
109
+ function splice(c, at, end, src, from, to) {
110
+ const delta = to - from - (end - at);
111
+ const text = c.text.slice(0, at) + src.text.slice(from, to) + c.text.slice(end);
112
+ const marks = joinMarks([
113
+ ...marksIn(c, 0, at, 0),
114
+ ...marksIn(c, end, c.text.length, end + delta),
115
+ ...marksIn(src, from, to, at)
116
+ ]);
117
+ const lines = text.split('\n').length;
118
+ const blocks = lines === c.blocks.length
119
+ ? c.blocks
120
+ : Array.from({ length: lines }, (_, k) => c.blocks[k] ?? para(null, k));
121
+ const out = { ...c, text, blocks };
122
+ if (marks.length)
123
+ out.marks = marks;
124
+ else
125
+ delete out.marks;
126
+ delete out.anchors;
127
+ return out;
128
+ }
129
+ /** Whether a value holds a block of its own kind, a container or an island, which a change to
130
+ * its words alone does not carry. */
131
+ const structured = (c) => !!c.islands?.length ||
132
+ !!c.containers?.length ||
133
+ c.blocks.some((b) => b.kind !== 'para' || b.path?.length);
134
+ /**
135
+ * What Accept writes over `live`, the value as it reads now: `after` where there is no `before`,
136
+ * or where the reader has changed nothing since; else each change from `before` to `after` carried
137
+ * onto `live`, the reader's own changes kept. Where a change of the reader's meets one of the
138
+ * proposal's, or the value holds more than lines of words, it is `after` whole and outdated, unless
139
+ * the value already reads as `after`.
140
+ */
141
+ export function planValue(before, live, after) {
142
+ if (!before)
143
+ return { merged: after, outdated: false };
144
+ const ours = valueChanges(before, live);
145
+ if (!ours.length || !valueChanges(live, after).length)
146
+ return { merged: after, outdated: false };
147
+ const theirs = valueChanges(before, after);
148
+ if ([before, live, after].some(structured) || theirs.some((p) => ours.some((r) => meet(p, r))))
149
+ return { merged: after, outdated: true };
150
+ const moved = (x) => ours.reduce((at, r) => (r.end <= x ? at + (r.to - r.from) - (r.end - r.at) : at), x);
151
+ let merged = live;
152
+ for (const p of [...theirs].reverse()) {
153
+ const at = moved(p.at);
154
+ merged = splice(merged, at, at + (p.end - p.at), after, p.from, p.to);
155
+ }
156
+ return { merged, outdated: false };
157
+ }
@@ -198,6 +198,17 @@
198
198
  --_qm-ink: var(--_qm-fg);
199
199
  --_qm-ink-default: color-mix(in oklab, var(--_qm-fg), var(--_qm-bg) 20%);
200
200
  --_qm-ink-label: color-mix(in oklab, var(--_qm-fg), var(--_qm-bg) 35%);
201
+ /* `label` over a floating surface. `raised` lifts the plane off the card while the rung
202
+ stays where the card put it, so it stands that much nearer the plane: under 4.5:1 on
203
+ the dark default. Here the rung lifts by the plane's own step and keeps over `raised`
204
+ the distance it keeps over the card. The card's share of the mix is 35%, so the card
205
+ going 23% toward white under it moves the rung the 8% `raised` moves. No step over a
206
+ white card, where `raised` takes none. */
207
+ --_qm-ink-label-raised: color-mix(
208
+ in oklab,
209
+ var(--_qm-fg),
210
+ color-mix(in oklab, var(--_qm-bg), #fff 23%) 35%
211
+ );
201
212
  /* The arrival wash (`core/bloom.ts`). Its alpha is a peak, not a tint: the
202
213
  wash animates from and back to zero, never held, so it reads over the leaf it
203
214
  lands on while the leaf rests clean. */
@@ -219,10 +230,15 @@
219
230
  the strength the accent's own tint is held under body text plus what a state resting
220
231
  on a well has to clear. `lit` is that tint under attention: the pointer over the
221
232
  item, the caret in it, a host revealing it. `line` is the stroke through the words a
222
- proposal would take, held back so it reads under the ink rather than as it. */
233
+ proposal would take, held back so it reads under the ink rather than as it, yet at 3:1 over
234
+ the card and a well at both poles, being the one mark a struck word or a tinted control's
235
+ edge has that is not colour alone: 75% of the light pole's hue, 60% of the dark's. */
223
236
  --_qm-review-tint: color-mix(in oklab, var(--_qm-review) 20%, transparent);
224
237
  --_qm-review-lit: color-mix(in oklab, var(--_qm-review) 34%, transparent);
225
- --_qm-review-line: color-mix(in oklab, var(--_qm-review) 60%, transparent);
238
+ --_qm-review-line: light-dark(
239
+ color-mix(in oklab, var(--_qm-review) 75%, transparent),
240
+ color-mix(in oklab, var(--_qm-review) 60%, transparent)
241
+ );
226
242
  /* The danger hue held: what a destructive control fills with where the family's
227
243
  neutral hover rung would read as one more button. Mixed at the accent tint's
228
244
  strength, so a held tint is a held tint whichever hue it carries. */
@@ -322,8 +338,9 @@
322
338
  control resting at nothing reads as arriving rather than as switching. */
323
339
  --_qm-reveal: 500ms cubic-bezier(0.4, 0, 0.2, 1);
324
340
  /* A wait rather than a trip: how long a caret rests on an empty line before the
325
- slash hint comes up. Longer than the gap between two keystrokes, so typing on
326
- through an Enter never draws it. */
341
+ slash hint comes up, and a pointer on a glyph control before its tip does
342
+ (`core/tooltip.ts`). Longer than the gap between two keystrokes, so typing on
343
+ through an Enter never draws it, and than a pointer takes to cross a control. */
327
344
  --_qm-hint-wait: 500ms;
328
345
 
329
346
  /* ── Geometry ──────────────────────────────────────────────────────────*/
@@ -409,18 +426,17 @@
409
426
  `vector-effect: non-scaling-stroke`, so every glyph strokes at one weight. */
410
427
  --_qm-glyph-stroke: calc(var(--_qm-glyph-control) / 12);
411
428
  /* The narrowest track a control that fills its width stays usable in: a table's
412
- column floors at it, rises no further than its content, and a row of them scrolls
413
- sideways rather than crushing a cell. A column drawing a mark takes no floor — a
414
- switch is one width at every width, so there is no width for it to be usable in
415
- (`ArrayField`). What the field has spare stands after the last column, an inner
416
- grid carrying its own rhythm rather than the card's. Under the field minimum the
417
- capacity ladder steps at (`.qm-tracks`), since a cell in a row has the header to
418
- name it and no label of its own to fit. A threshold rather than a rhythm choice,
419
- so it does not move with `--qm-space`. */
429
+ column floors at it, and a row of them scrolls sideways rather than crushing a
430
+ cell. A column drawing a mark takes no floor — a switch is one width at every
431
+ width, so there is no width for it to be usable in (`ArrayField`). Under the field
432
+ minimum the capacity ladder steps at (`.qm-tracks`), since a cell in a row has the
433
+ header to name it and no label of its own to fit. A threshold rather than a rhythm
434
+ choice, so it does not move with `--qm-space`. */
420
435
  --_qm-track-min: 7rem;
421
- /* A prose column's floor: its cell wraps, and at `--_qm-track-min` a line holds a
422
- word, standing the row many lines tall beside cells one line tall. A multiple of
423
- the floor, so the two move together. */
436
+ /* A prose column's floor while the field has the width: its cell wraps, and at
437
+ `--_qm-track-min` a line holds a word, standing the row many lines tall beside cells
438
+ one line tall. Short of the width it gives way down to `--_qm-track-min` before the
439
+ table scrolls (`ArrayField`). A multiple of the floor, so the two move together. */
424
440
  --_qm-track-prose: calc(var(--_qm-track-min) * 2);
425
441
 
426
442
  /* ── Type ────────────────────────────────────────────────────────────────
@@ -507,6 +523,21 @@
507
523
  line-height: var(--_qm-leading-body);
508
524
  }
509
525
 
526
+ /* A floating surface holds the label rung against its own plane, so what it carries at
527
+ that rung — a row's shortcut, a tag, a note, a quiet answer — reads over it as it does
528
+ over a card, and no component on one has to know where it stands. Stated here and not
529
+ in the recipes (`visual/controls.css`): a floating surface is mostly a root itself, so
530
+ a declaration from another sheet would tie with the rule above and leave the rung to
531
+ the order a bundler emits the two in. */
532
+ :where(.qm-menu-surface, .qm-popover-surface) {
533
+ --_qm-ink-label: var(--_qm-ink-label-raised);
534
+ }
535
+ /* A menu's cursor fills its row, which takes that distance back, so under it the rung
536
+ steps to the ink: the ladder a chip takes under the pointer (`visual/controls.css`). */
537
+ :where(.qm-menu-item[data-highlighted]) {
538
+ --_qm-ink-label: var(--_qm-ink);
539
+ }
540
+
510
541
  /* More contrast steps the two rungs that identify a control rather than a list of
511
542
  selectors: the well's edge to 3:1 against the card at both poles (WCAG 1.4.11),
512
543
  which half the ink over the well clears, and the ring a pixel wider. */
@@ -0,0 +1,49 @@
1
+ /* The tip a glyph control raises (`core/tooltip.ts`), which imports this sheet, so the
2
+ editor's chrome and a leaf mounted on its own draw the same one.
3
+
4
+ A floating surface, so it takes the stroke and the lift a surface with no plane under
5
+ it stands on (INVARIANTS §Styling), on the raised rung and opaque: it is a word or two
6
+ over glyphs, and nothing behind it is worth reading through. One rung in from a
7
+ control's own corner and at the label size, so it reads as a note on a control and
8
+ never as one more control.
9
+
10
+ Placed in the root it is appended to, over every other floating surface, the format
11
+ bar and the table island's clusters being where half its controls stand. It takes no
12
+ pointer: a tip between the pointer and the next control would be a tip in the way.
13
+
14
+ It arrives by a fade and leaves at once. A scale would move a surface this small more
15
+ than it shows it, and a tip is lowered by the press or the key that makes it stale. A
16
+ tip that follows another along a row of controls does not arrive again. */
17
+ :where(.qm-tip) {
18
+ position: absolute;
19
+ z-index: 4;
20
+ display: flex;
21
+ gap: var(--_qm-space-2);
22
+ width: max-content;
23
+ padding: var(--_qm-space-half) var(--_qm-space-2);
24
+ border: var(--_qm-border-width) solid var(--_qm-border);
25
+ border-radius: var(--_qm-radius-inner);
26
+ background: var(--_qm-surface-raised);
27
+ box-shadow: var(--_qm-lift);
28
+ font-family: var(--_qm-font);
29
+ font-size: var(--_qm-text-label);
30
+ line-height: var(--_qm-leading-tight);
31
+ color: var(--_qm-ink);
32
+ white-space: nowrap;
33
+ pointer-events: none;
34
+ user-select: none;
35
+ }
36
+ :where(.qm-tip[data-arriving]) {
37
+ animation: qm-tip-in var(--_qm-duration-fast) var(--_qm-ease-reverse);
38
+ }
39
+ /* The shortcut, a step off the name it follows: the name is what the control is, the
40
+ keys a way to it. */
41
+ :where(.qm-tip kbd) {
42
+ font: inherit;
43
+ color: var(--_qm-ink-label-raised);
44
+ }
45
+ @keyframes qm-tip-in {
46
+ from {
47
+ opacity: 0;
48
+ }
49
+ }
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Serve the tips of every control under `root`, the `[data-qm-root]` a tip is appended to and
3
+ * kept inside. One install per root however many callers ask; the returned function releases this
4
+ * caller's.
5
+ */
6
+ export declare function tooltips(root: HTMLElement): () => void;
@@ -0,0 +1,176 @@
1
+ // The name of a control that draws only a glyph, raised beside it: one surface per root, where the
2
+ // native `title` reaches no dial, waits a second, answers a pointer alone and cannot be dismissed.
3
+ //
4
+ // A control opts in by attribute rather than by a wrapper, so chrome built without a framework
5
+ // (the table island's) and chrome built with one are served by the same listeners on the root
6
+ // they stand in, and a control costs no listener of its own:
7
+ //
8
+ // data-qm-tip the control's name
9
+ // data-qm-tip-keys its shortcut, as the platform prints it
10
+ // data-qm-tip-side on the control or an ancestor: the box the tip stands clear of, and
11
+ // `bottom` to stand under it. A floating row of controls names itself here,
12
+ // so its tips fall on the side away from what the row is about.
13
+ //
14
+ // The tip is decoration for a reader who can see it. It is `aria-hidden` and nothing points at it:
15
+ // the control's `aria-label` is its name and `aria-keyshortcuts` its shortcut. It takes no pointer
16
+ // and holds nothing to press.
17
+ //
18
+ // It comes up once the pointer has rested on the control (`--_qm-hint-wait`), at once under
19
+ // keyboard focus, and at once and without its fade on the control after one that just showed its
20
+ // own, so a tip carried along a row of glyphs reads as one tip moving. A press, a key or
21
+ // a scroll lowers it until the pointer or the focus comes back to the control: each can move the
22
+ // control, and the tip is placed once, from where the control stood.
23
+ import { rungMs, rungStyle, spacePx } from './rungs.js';
24
+ import './tooltip.css';
25
+ const TIP = 'data-qm-tip';
26
+ const KEYS = 'data-qm-tip-keys';
27
+ const SIDE = 'data-qm-tip-side';
28
+ const installed = new WeakMap();
29
+ /**
30
+ * Serve the tips of every control under `root`, the `[data-qm-root]` a tip is appended to and
31
+ * kept inside. One install per root however many callers ask; the returned function releases this
32
+ * caller's.
33
+ */
34
+ export function tooltips(root) {
35
+ let entry = installed.get(root);
36
+ if (!entry)
37
+ installed.set(root, (entry = { users: 0, remove: install(root) }));
38
+ entry.users++;
39
+ const held = entry;
40
+ let released = false;
41
+ return () => {
42
+ if (released)
43
+ return;
44
+ released = true;
45
+ if (--held.users > 0)
46
+ return;
47
+ held.remove();
48
+ installed.delete(root);
49
+ };
50
+ }
51
+ const clamp = (n, min, max) => Math.max(min, Math.min(max, n));
52
+ function install(root) {
53
+ const doc = root.ownerDocument;
54
+ const tip = doc.createElement('div');
55
+ tip.className = 'qm-tip';
56
+ tip.setAttribute('aria-hidden', 'true');
57
+ /** The control the pointer or the focus is on, whether or not its tip is up. */
58
+ let anchor;
59
+ let by = 'pointer';
60
+ let pending;
61
+ /** Until when the next control's tip skips the wait: a reader moving along a row of
62
+ * glyphs is reading them, not resting. */
63
+ let warm = 0;
64
+ const wait = () => rungMs(rungStyle(root), '--_qm-hint-wait') ?? 0;
65
+ function place(control) {
66
+ const holder = control.closest(`[${SIDE}]`) ?? control;
67
+ const across = control.getBoundingClientRect();
68
+ const along = holder.getBoundingClientRect();
69
+ const frame = root.getBoundingClientRect();
70
+ // The root is positioned wherever the editor mounts it; a leaf mounted on its own may
71
+ // stand in one that is not, and the tip is then placed in whatever is.
72
+ const origin = tip.offsetParent ?? root;
73
+ const from = origin.getBoundingClientRect();
74
+ const view = doc.defaultView;
75
+ const top = Math.max(frame.top, 0);
76
+ const bottom = Math.min(frame.bottom, view?.innerHeight ?? frame.bottom);
77
+ const left = Math.max(frame.left, 0);
78
+ const right = Math.min(frame.right, view?.innerWidth ?? frame.right);
79
+ const gap = spacePx(root) ?? 0;
80
+ const w = tip.offsetWidth;
81
+ const h = tip.offsetHeight;
82
+ const over = along.top - gap - h;
83
+ const under = along.bottom + gap;
84
+ const overFits = over >= top;
85
+ const underFits = under + h <= bottom;
86
+ const below = holder.getAttribute(SIDE) === 'bottom' ? underFits || !overFits : !overFits && underFits;
87
+ const x = clamp(across.left + (across.width - w) / 2, left + gap, right - gap - w);
88
+ const y = clamp(below ? under : over, top, bottom - h);
89
+ tip.style.left = `${x - from.left - origin.clientLeft + origin.scrollLeft}px`;
90
+ tip.style.top = `${y - from.top - origin.clientTop + origin.scrollTop}px`;
91
+ }
92
+ function raise(control, arriving = true) {
93
+ pending = undefined;
94
+ const name = control.getAttribute(TIP);
95
+ if (!name || !control.isConnected)
96
+ return;
97
+ const keys = control.getAttribute(KEYS);
98
+ tip.replaceChildren(name);
99
+ if (keys) {
100
+ const cap = doc.createElement('kbd');
101
+ cap.textContent = keys;
102
+ tip.appendChild(cap);
103
+ }
104
+ tip.toggleAttribute('data-arriving', arriving);
105
+ root.appendChild(tip);
106
+ place(control);
107
+ }
108
+ /** Take the tip down, the control still the one attended to, so it stays down. */
109
+ function lower() {
110
+ clearTimeout(pending);
111
+ pending = undefined;
112
+ if (tip.isConnected)
113
+ warm = performance.now() + wait();
114
+ tip.remove();
115
+ doc.removeEventListener('scroll', lower, true);
116
+ doc.removeEventListener('keydown', lower, true);
117
+ }
118
+ function leave() {
119
+ lower();
120
+ anchor = undefined;
121
+ }
122
+ function attend(control, from) {
123
+ leave();
124
+ anchor = control;
125
+ by = from;
126
+ doc.addEventListener('scroll', lower, { capture: true, passive: true });
127
+ doc.addEventListener('keydown', lower, true);
128
+ if (performance.now() < warm)
129
+ raise(control, false);
130
+ else if (from === 'focus')
131
+ raise(control);
132
+ else
133
+ pending = setTimeout(() => raise(control), wait());
134
+ }
135
+ const tipped = (target) => (target instanceof Element && target.closest(`[${TIP}]`)) || undefined;
136
+ function onOver(e) {
137
+ if (e.pointerType === 'touch')
138
+ return;
139
+ const control = tipped(e.target);
140
+ if (control === anchor)
141
+ return;
142
+ if (control)
143
+ attend(control, 'pointer');
144
+ else if (by === 'pointer')
145
+ leave();
146
+ }
147
+ function onOut(e) {
148
+ if (by !== 'pointer' || !anchor)
149
+ return;
150
+ if (e.relatedTarget instanceof Node && anchor.contains(e.relatedTarget))
151
+ return;
152
+ leave();
153
+ }
154
+ function onFocusIn(e) {
155
+ const control = tipped(e.target);
156
+ if (control && control.matches(':focus-visible'))
157
+ attend(control, 'focus');
158
+ }
159
+ function onFocusOut() {
160
+ if (by === 'focus')
161
+ leave();
162
+ }
163
+ root.addEventListener('pointerover', onOver);
164
+ root.addEventListener('pointerout', onOut);
165
+ root.addEventListener('pointerdown', lower, true);
166
+ root.addEventListener('focusin', onFocusIn);
167
+ root.addEventListener('focusout', onFocusOut);
168
+ return () => {
169
+ leave();
170
+ root.removeEventListener('pointerover', onOver);
171
+ root.removeEventListener('pointerout', onOut);
172
+ root.removeEventListener('pointerdown', lower, true);
173
+ root.removeEventListener('focusin', onFocusIn);
174
+ root.removeEventListener('focusout', onFocusOut);
175
+ };
176
+ }
@@ -129,6 +129,27 @@
129
129
  padding: var(--_qm-space-4);
130
130
  background: var(--_qm-surface-sunken);
131
131
  }
132
+ /* Inset, so the scrollport does not clip it. */
133
+ :global(:where(.qm-preview:focus-visible)) {
134
+ outline: var(--_qm-ring);
135
+ outline-offset: calc(-1 * var(--_qm-ring-reach));
136
+ }
137
+
138
+ /* The message in place of the pages (controller.ts): words about the pane, at the chrome's
139
+ label size, where a page would stand. */
140
+ :global(:where(.qm-preview-message)) {
141
+ padding: var(--_qm-space-5) var(--_qm-space-4);
142
+ font-family: var(--_qm-font);
143
+ font-size: var(--_qm-text-label);
144
+ line-height: var(--_qm-leading-body);
145
+ text-align: center;
146
+ }
147
+ :global(:where(.qm-preview-empty)) {
148
+ color: var(--_qm-ink-label);
149
+ }
150
+ :global(:where(.qm-preview-error)) {
151
+ color: var(--_qm-danger);
152
+ }
132
153
 
133
154
  /* The arrival wash on the page (`wash.ts`): a plane at a field's box, its tone the editor's,
134
155
  reaching a hair past the ink's tight box and rounded, as a control's wash is a box's own. Over
@@ -175,7 +196,7 @@
175
196
  background: var(--_qm-surface-popover);
176
197
  backdrop-filter: blur(var(--_qm-blur));
177
198
  box-shadow: var(--_qm-lift);
178
- color: var(--_qm-ink-label);
199
+ color: var(--_qm-ink-label-raised);
179
200
  font-family: var(--_qm-font);
180
201
  font-size: var(--_qm-text-label);
181
202
  font-variant-numeric: tabular-nums;