dotquilt 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.
Files changed (183) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +64 -2
  3. package/dist/animations.d.ts +105 -0
  4. package/dist/animations.js +107 -0
  5. package/dist/catalog-styles.d.ts +4 -0
  6. package/dist/catalog-styles.js +12 -0
  7. package/dist/chart-animations.d.ts +36 -0
  8. package/dist/chart-animations.js +25 -0
  9. package/dist/chart-styles.d.ts +3 -0
  10. package/dist/chart-styles.js +23 -0
  11. package/dist/chart.css +4 -0
  12. package/dist/chart.d.ts +73 -0
  13. package/dist/chart.js +80 -0
  14. package/dist/circle.css +5 -0
  15. package/dist/index.d.ts +11 -0
  16. package/dist/index.js +9 -0
  17. package/dist/internal/binding.d.ts +13 -0
  18. package/dist/internal/binding.js +21 -0
  19. package/dist/internal/capture.d.ts +4 -0
  20. package/dist/internal/capture.js +13 -0
  21. package/dist/internal/chart-appearance.d.ts +12 -0
  22. package/dist/internal/chart-appearance.js +2 -0
  23. package/dist/internal/chart-definitions.d.ts +19 -0
  24. package/dist/internal/chart-definitions.js +149 -0
  25. package/dist/internal/chart-factory.d.ts +12 -0
  26. package/dist/internal/chart-factory.js +31 -0
  27. package/dist/internal/chart-field.d.ts +22 -0
  28. package/dist/internal/chart-field.js +74 -0
  29. package/dist/internal/chart-idle.d.ts +3 -0
  30. package/dist/internal/chart-idle.js +96 -0
  31. package/dist/internal/chart-math.d.ts +8 -0
  32. package/dist/internal/chart-math.js +19 -0
  33. package/dist/internal/chart-participant.d.ts +8 -0
  34. package/dist/internal/chart-participant.js +4 -0
  35. package/dist/internal/chart-projection.d.ts +11 -0
  36. package/dist/internal/chart-projection.js +69 -0
  37. package/dist/internal/content-box.d.ts +11 -0
  38. package/dist/internal/content-box.js +36 -0
  39. package/dist/internal/coordinated-handoff.d.ts +4 -0
  40. package/dist/internal/coordinated-handoff.js +158 -0
  41. package/dist/internal/count.d.ts +3 -0
  42. package/dist/internal/count.js +20 -0
  43. package/dist/internal/defaults.d.ts +11 -0
  44. package/dist/internal/defaults.js +11 -0
  45. package/dist/internal/dense/managed-painter.d.ts +4 -0
  46. package/dist/internal/dense/managed-painter.js +361 -0
  47. package/dist/internal/dense/runner.d.ts +2 -0
  48. package/dist/internal/dense/runner.js +5 -0
  49. package/dist/internal/dense-loader.d.ts +83 -0
  50. package/dist/internal/dense-loader.js +331 -0
  51. package/dist/internal/dissolve.d.ts +27 -0
  52. package/dist/internal/dissolve.js +216 -0
  53. package/dist/internal/dom.d.ts +23 -0
  54. package/dist/internal/dom.js +104 -0
  55. package/dist/internal/effect.d.ts +2 -0
  56. package/dist/internal/effect.js +17 -0
  57. package/dist/internal/element.d.ts +89 -0
  58. package/dist/internal/element.js +384 -0
  59. package/dist/internal/event-element.d.ts +8 -0
  60. package/dist/internal/event-element.js +20 -0
  61. package/dist/internal/frames.d.ts +1 -0
  62. package/dist/internal/frames.js +51 -0
  63. package/dist/internal/handoff.d.ts +56 -0
  64. package/dist/internal/handoff.js +102 -0
  65. package/dist/internal/ledger.d.ts +13 -0
  66. package/dist/internal/ledger.js +78 -0
  67. package/dist/internal/loading-controller.d.ts +62 -0
  68. package/dist/internal/loading-controller.js +698 -0
  69. package/dist/internal/marks.d.ts +153 -0
  70. package/dist/internal/marks.js +227 -0
  71. package/dist/internal/math.d.ts +2 -0
  72. package/dist/internal/math.js +2 -0
  73. package/dist/internal/morph-marks.d.ts +62 -0
  74. package/dist/internal/morph-marks.js +205 -0
  75. package/dist/internal/morph.d.ts +35 -0
  76. package/dist/internal/morph.js +488 -0
  77. package/dist/internal/paint.d.ts +29 -0
  78. package/dist/internal/paint.js +1 -0
  79. package/dist/internal/painter.d.ts +20 -0
  80. package/dist/internal/painter.js +155 -0
  81. package/dist/internal/preset-data.d.ts +12 -0
  82. package/dist/internal/preset-data.js +31 -0
  83. package/dist/internal/preset.d.ts +22 -0
  84. package/dist/internal/preset.js +86 -0
  85. package/dist/internal/pulse.d.ts +7 -0
  86. package/dist/internal/pulse.js +74 -0
  87. package/dist/internal/reveal-effect.d.ts +7 -0
  88. package/dist/internal/reveal-effect.js +24 -0
  89. package/dist/internal/reveal.d.ts +5 -0
  90. package/dist/internal/reveal.js +11 -0
  91. package/dist/internal/runner.d.ts +9 -0
  92. package/dist/internal/runner.js +70 -0
  93. package/dist/internal/services.d.ts +12 -0
  94. package/dist/internal/services.js +159 -0
  95. package/dist/internal/skeleton-handoff.d.ts +26 -0
  96. package/dist/internal/skeleton-handoff.js +6 -0
  97. package/dist/internal/skeleton-source.d.ts +5 -0
  98. package/dist/internal/skeleton-source.js +106 -0
  99. package/dist/internal/surface.d.ts +4 -0
  100. package/dist/internal/surface.js +21 -0
  101. package/dist/internal/table-definitions.d.ts +27 -0
  102. package/dist/internal/table-definitions.js +139 -0
  103. package/dist/internal/table-factory.d.ts +12 -0
  104. package/dist/internal/table-factory.js +44 -0
  105. package/dist/internal/table-field.d.ts +12 -0
  106. package/dist/internal/table-field.js +75 -0
  107. package/dist/internal/table-model.d.ts +21 -0
  108. package/dist/internal/table-model.js +117 -0
  109. package/dist/internal/table-projection.d.ts +7 -0
  110. package/dist/internal/table-projection.js +110 -0
  111. package/dist/internal/target-changes.d.ts +3 -0
  112. package/dist/internal/target-changes.js +2 -0
  113. package/dist/internal/target-tracker.d.ts +18 -0
  114. package/dist/internal/target-tracker.js +33 -0
  115. package/dist/internal/targets.d.ts +3 -0
  116. package/dist/internal/targets.js +15 -0
  117. package/dist/internal/text-definitions.d.ts +141 -0
  118. package/dist/internal/text-definitions.js +228 -0
  119. package/dist/internal/text-glyphs.d.ts +4 -0
  120. package/dist/internal/text-glyphs.js +32 -0
  121. package/dist/internal/text-morph.d.ts +32 -0
  122. package/dist/internal/text-morph.js +113 -0
  123. package/dist/internal/text-playback.d.ts +4 -0
  124. package/dist/internal/text-playback.js +119 -0
  125. package/dist/internal/text-scramble.d.ts +18 -0
  126. package/dist/internal/text-scramble.js +47 -0
  127. package/dist/internal/time.d.ts +9 -0
  128. package/dist/internal/time.js +13 -0
  129. package/dist/internal/unstyled.d.ts +8 -0
  130. package/dist/internal/unstyled.js +8 -0
  131. package/dist/line.css +5 -0
  132. package/dist/region-css.d.ts +1 -0
  133. package/dist/region-css.js +6 -0
  134. package/dist/region-styles.d.ts +3 -0
  135. package/dist/region-styles.js +15 -0
  136. package/dist/region.css +1 -0
  137. package/dist/region.d.ts +31 -0
  138. package/dist/region.js +100 -0
  139. package/dist/register-all.d.ts +2 -0
  140. package/dist/register-all.js +33 -0
  141. package/dist/server.d.ts +63 -0
  142. package/dist/server.js +141 -0
  143. package/dist/skeleton-animations.d.ts +10 -0
  144. package/dist/skeleton-animations.js +35 -0
  145. package/dist/skeleton-block.d.ts +50 -0
  146. package/dist/skeleton-block.js +260 -0
  147. package/dist/skeleton-circle.d.ts +5 -0
  148. package/dist/skeleton-circle.js +11 -0
  149. package/dist/skeleton-family.css +13 -0
  150. package/dist/skeleton-line.d.ts +5 -0
  151. package/dist/skeleton-line.js +11 -0
  152. package/dist/skeleton-text.css +5 -0
  153. package/dist/skeleton-text.d.ts +22 -0
  154. package/dist/skeleton-text.js +115 -0
  155. package/dist/skeleton.css +4 -0
  156. package/dist/skeleton.d.ts +5 -0
  157. package/dist/skeleton.js +4 -0
  158. package/dist/static-catalog-styles.d.ts +8 -0
  159. package/dist/static-catalog-styles.js +44 -0
  160. package/dist/styles.d.ts +4 -0
  161. package/dist/styles.js +18 -0
  162. package/dist/table-animations.d.ts +11 -0
  163. package/dist/table-animations.js +4 -0
  164. package/dist/table-styles.d.ts +2 -0
  165. package/dist/table-styles.js +12 -0
  166. package/dist/table.css +3 -0
  167. package/dist/table.d.ts +88 -0
  168. package/dist/table.js +126 -0
  169. package/dist/text-animations.d.ts +31 -0
  170. package/dist/text-animations.js +40 -0
  171. package/dist/text-styles.d.ts +3 -0
  172. package/dist/text-styles.js +24 -0
  173. package/dist/text.css +3 -0
  174. package/dist/text.d.ts +42 -0
  175. package/dist/text.js +402 -0
  176. package/dist/types.d.ts +56 -0
  177. package/dist/types.js +18 -0
  178. package/dist/typing-styles.d.ts +1 -0
  179. package/dist/typing-styles.js +7 -0
  180. package/dist/typing.css +4 -0
  181. package/dist/typing.d.ts +35 -0
  182. package/dist/typing.js +164 -0
  183. package/package.json +100 -4
@@ -0,0 +1,153 @@
1
+ /**
2
+ * Default marks, from design/SPEC.md ("System, refined"). Every stylesheet
3
+ * takes its dot size, spacing, colours and opacity from here, so the static
4
+ * look, the idle motion and the painters agree. Apps override them through the
5
+ * `--dotquilt-*` custom properties.
6
+ *
7
+ * Colours follow the page's `color-scheme` through `light-dark()`. CSS cannot
8
+ * switch a number between themes, so both use one resting opacity: the dark
9
+ * mark is #A3AFC2, which at 37% on the dark surface matches the spec's #8E99AB
10
+ * at 44%.
11
+ */
12
+ export declare const markSize = "var(--dotquilt-dot-size,4.4px)";
13
+ export declare const markGap = "var(--dotquilt-dot-gap,4.6px)";
14
+ export declare const markColor = "var(--dotquilt-color,light-dark(#6e7889,#a3afc2))";
15
+ export declare const glowColor = "var(--dotquilt-accent-color,light-dark(#4f8f93,#8dc4c5))";
16
+ /** Resting opacity of the marks. */
17
+ export declare const restOpacity = 0.37;
18
+ /** Opacity of the glow at its centre. */
19
+ export declare const peakOpacity = 0.9;
20
+ /**
21
+ * TypingDots are larger than the field marks so they read as a status, not a
22
+ * speck (the spec's mockup: 8 px dots, 6 px apart).
23
+ */
24
+ export declare const typingSize = "var(--dotquilt-dot-size,8px)";
25
+ export declare const typingGap = "var(--dotquilt-dot-gap,6px)";
26
+ /** A line placeholder is two rows of marks tall, as in the spec's mockup. */
27
+ export declare const lineHeight = "calc(2*(var(--dotquilt-dot-size,4.4px) + var(--dotquilt-dot-gap,4.6px)))";
28
+ /**
29
+ * A grid of round marks painted with CSS, used by static and skeleton surfaces.
30
+ * By default only whole marks are drawn (`space`): blocks and circles of any
31
+ * size spread the leftover evenly instead of clipping half a row at an edge.
32
+ * Lines, exactly two rows tall, pass `0 0` and repeat from the left so their
33
+ * columns line up. The 1 px soft edge keeps small marks round at 1× density.
34
+ */
35
+ export declare function dotGrid(position?: string): string;
36
+ /**
37
+ * The alternative marks (design/SPEC.md): width, height and the pitch across
38
+ * and down. Squares are crisp at small sizes; dashes suit text lines and rows.
39
+ */
40
+ export declare const shapes: {
41
+ readonly square: {
42
+ readonly width: 4;
43
+ readonly height: 4;
44
+ readonly across: 8.5;
45
+ readonly down: 8.5;
46
+ readonly radius: 1.1;
47
+ };
48
+ readonly dash: {
49
+ readonly width: 9.4;
50
+ readonly height: 3.4;
51
+ readonly across: 13;
52
+ readonly down: 9.5;
53
+ readonly radius: 1.7;
54
+ };
55
+ };
56
+ /**
57
+ * Squares or dashes for a skeleton or chart surface. `position` works like
58
+ * dotGrid's: `space` (whole marks only) unless a position is given.
59
+ */
60
+ export declare function shapeGrid(mark: keyof typeof shapes, position?: string): string;
61
+ /**
62
+ * Lines end on their last whole mark instead of a mark cut in half: a mask
63
+ * keeps whole tiles from the left. It needs CSS round(); without it a line
64
+ * looks as before. Forced colours draw an outline, so they keep no mask.
65
+ */
66
+ export declare function lineTrim(host: (mark?: keyof typeof shapes) => string, surface: string, marks?: readonly Mark[]): string;
67
+ /**
68
+ * A circle fades out over its last few pixels, so marks its edge would cut
69
+ * read as softly faded instead of as slivers.
70
+ */
71
+ export declare const circleEdge = "mask:radial-gradient(closest-side,#000 calc(100% - var(--dotquilt-dot-size,4.4px)*.7),#0000)";
72
+ /**
73
+ * Rules that draw TextLoader's placeholder with squares or dashes, in the
74
+ * mark colour: the placeholder's own text is transparent, so `currentColor`
75
+ * would draw nothing.
76
+ */
77
+ export declare function textMarkShapes(host: (mark: keyof typeof shapes) => string, surface: string): string;
78
+ /**
79
+ * TypingDots shapes, from the spec's mockup: a square is 90% of the dot size,
80
+ * and a dash is 80% of it tall and 2.7 times as wide as it is tall.
81
+ */
82
+ export declare function typingShapes(host: (mark: keyof typeof shapes) => string, dot: string): string;
83
+ /** Rules that give a painted surface its mark's pitch, for the fields that read it. */
84
+ export declare function markPitches(host: (mark: keyof typeof shapes) => string, surface: string): string;
85
+ /**
86
+ * A drawn mark: the public `Mark` type. It is spelled out here so build
87
+ * scripts that read these styles from source don't load the element types.
88
+ */
89
+ export type Mark = 'dot' | keyof typeof shapes;
90
+ /** The host's mark; a missing or unknown value draws dots. */
91
+ export declare function markOf(host: Element): Mark;
92
+ /** The default dot's radius. Painter commands give a radius; other marks scale from it. */
93
+ export declare const dotRadius = 2.2;
94
+ /**
95
+ * The box a painter draws for a command of radius `r`: a circle for a dot,
96
+ * and for squares and dashes the spec's shape scaled by `r` against the
97
+ * default dot, so the default radius draws them at their spec size.
98
+ */
99
+ export declare function markBox(mark: Mark, r: number): {
100
+ width: number;
101
+ height: number;
102
+ radius: number;
103
+ };
104
+ /** Rules that draw `surface` with squares or dashes when `host(mark)` matches. */
105
+ export declare function markShapes(host: (mark: keyof typeof shapes) => string, surface: string, position?: string): string;
106
+ /** Line placeholders are two rows of the host's mark tall. */
107
+ export declare function markLineHeights(host: (mark: keyof typeof shapes) => string): string;
108
+ /**
109
+ * The idle glow's profile across the field: a Gaussian, exp(-d²) for d in
110
+ * [-3.2, 3.2] standard deviations, in mask alpha. The mask is 128% of the
111
+ * field wide, because one deviation is 20% of the field.
112
+ */
113
+ export declare const glowMask = "linear-gradient(104deg,#0000 12.5%,#00000005 18.75%,#0000001b 26.56%,#0000005e 34.38%,#000000c7 42.19%,#000 50%,#000000c7 57.81%,#0000005e 65.63%,#0000001b 73.44%,#00000005 81.25%,#0000 87.5%) 0 0/128% 100% no-repeat";
114
+ /** Motion curves from the spec. */
115
+ export declare const curves: {
116
+ /** Content entering and UI transitions: a long tail, no overshoot. */
117
+ readonly settle: 'cubic-bezier(.22,1,.36,1)';
118
+ /** Opacity of revealed content. */
119
+ readonly fade: 'cubic-bezier(.33,0,.2,1)';
120
+ /** Marks, the idle glow and chart glides. */
121
+ readonly sine: 'cubic-bezier(.37,0,.63,1)';
122
+ };
123
+ /**
124
+ * The handoff (design/SPEC.md): 1.1 s in all. Content fades in over 700 ms
125
+ * while a 2 px blur clears, and rises 5 px over 910 ms. Marks dim, shrink by
126
+ * 30% and drift up 3 px. An explicit `timing.duration` scales every part.
127
+ */
128
+ export declare const handoff: {
129
+ readonly duration: 1100;
130
+ readonly contentFade: 700;
131
+ readonly contentRise: 910;
132
+ readonly risePx: 5;
133
+ readonly blurPx: 2;
134
+ readonly markShrink: 0.3;
135
+ readonly markDriftPx: 3;
136
+ };
137
+ /**
138
+ * The "take shape, then hand over" handoff (design/SPEC.md), shared by every
139
+ * loader: marks travel in a wave to the real content's shape, then the content
140
+ * wipes in along a soft front and the marks leave where it passes them.
141
+ */
142
+ export declare const morphTiming: {
143
+ /** Each mark's own journey, as a share of the handoff. */
144
+ readonly travel: 0.34;
145
+ /** How much later the far end of the content starts travelling. */
146
+ readonly stagger: 0.2;
147
+ /** When the content starts to wipe in. */
148
+ readonly wipeStart: 0.46;
149
+ /** Width of the soft front, in px. */
150
+ readonly edge: 36;
151
+ /** Opacity of a mark that has arrived. */
152
+ readonly arrive: 0.62;
153
+ };
@@ -0,0 +1,227 @@
1
+ /**
2
+ * Default marks, from design/SPEC.md ("System, refined"). Every stylesheet
3
+ * takes its dot size, spacing, colours and opacity from here, so the static
4
+ * look, the idle motion and the painters agree. Apps override them through the
5
+ * `--dotquilt-*` custom properties.
6
+ *
7
+ * Colours follow the page's `color-scheme` through `light-dark()`. CSS cannot
8
+ * switch a number between themes, so both use one resting opacity: the dark
9
+ * mark is #A3AFC2, which at 37% on the dark surface matches the spec's #8E99AB
10
+ * at 44%.
11
+ */
12
+ export const markSize = 'var(--dotquilt-dot-size,4.4px)';
13
+ export const markGap = 'var(--dotquilt-dot-gap,4.6px)';
14
+ export const markColor = 'var(--dotquilt-color,light-dark(#6e7889,#a3afc2))';
15
+ export const glowColor = 'var(--dotquilt-accent-color,light-dark(#4f8f93,#8dc4c5))';
16
+ /** Resting opacity of the marks. */
17
+ export const restOpacity = 0.37;
18
+ /** Opacity of the glow at its centre. */
19
+ export const peakOpacity = 0.9;
20
+ /**
21
+ * TypingDots are larger than the field marks so they read as a status, not a
22
+ * speck (the spec's mockup: 8 px dots, 6 px apart).
23
+ */
24
+ export const typingSize = 'var(--dotquilt-dot-size,8px)';
25
+ export const typingGap = 'var(--dotquilt-dot-gap,6px)';
26
+ /** A line placeholder is two rows of marks tall, as in the spec's mockup. */
27
+ export const lineHeight = `calc(2*(${markSize} + ${markGap}))`;
28
+ /**
29
+ * A grid of round marks painted with CSS, used by static and skeleton surfaces.
30
+ * By default only whole marks are drawn (`space`): blocks and circles of any
31
+ * size spread the leftover evenly instead of clipping half a row at an edge.
32
+ * Lines, exactly two rows tall, pass `0 0` and repeat from the left so their
33
+ * columns line up. The 1 px soft edge keeps small marks round at 1× density.
34
+ */
35
+ export function dotGrid(position) {
36
+ const place = position
37
+ ? `${position}/var(--g) var(--g)`
38
+ : 'center/var(--g) var(--g) space';
39
+ return `--s:${markSize};--g:calc(var(--s) + ${markGap});background:radial-gradient(circle,${markColor} calc(var(--s)/2 - .5px),#0000 calc(var(--s)/2 + .5px)) ${place}`;
40
+ }
41
+ /**
42
+ * The alternative marks (design/SPEC.md): width, height and the pitch across
43
+ * and down. Squares are crisp at small sizes; dashes suit text lines and rows.
44
+ */
45
+ export const shapes = {
46
+ square: { width: 4, height: 4, across: 8.5, down: 8.5, radius: 1.1 },
47
+ dash: { width: 9.4, height: 3.4, across: 13, down: 9.5, radius: 1.7 },
48
+ };
49
+ /** A length in px, rounded so the CSS stays short. */
50
+ const px = (value) => `${Math.round(value * 100) / 100}px`;
51
+ /**
52
+ * One mask layer: a band between `from` and `to` px, with a 1 px soft edge.
53
+ * Without an angle it runs down the tile.
54
+ */
55
+ function band(from, to, angle = '') {
56
+ return `linear-gradient(${angle}#0000 ${px(from - 0.5)},#000 ${px(from + 0.5)},#000 ${px(to - 0.5)},#0000 ${px(to + 0.5)})`;
57
+ }
58
+ /**
59
+ * A grid of `shape` marks painted with CSS masks, so it needs no image and
60
+ * passes a strict CSP. A square is a horizontal band intersected with a
61
+ * vertical one; a dash adds two round caps, so its ends are round.
62
+ */
63
+ function maskGrid(mark, shape, place, color) {
64
+ const { width, height, across, down } = shape;
65
+ const x = (across - width) / 2, y = (down - height) / 2;
66
+ const rows = band(y, y + height);
67
+ const layers = mark === 'square'
68
+ ? [rows, band(x, x + width, '90deg,')]
69
+ : [
70
+ ...[x + height / 2, x + width - height / 2].map((cx) => `radial-gradient(circle at ${px(cx)} ${px(down / 2)},#000 ${px(height / 2 - 0.5)},#0000 ${px(height / 2 + 0.5)})`),
71
+ rows,
72
+ band(x + height / 2, x + width - height / 2, '90deg,'),
73
+ ];
74
+ const composite = mark === 'square' ? 'intersect' : 'add,add,intersect';
75
+ if (place.trim) {
76
+ // A line ends on its last whole mark: one more layer, on top, keeps only
77
+ // whole tiles from the left (lineTrim).
78
+ const n = layers.length;
79
+ const size = `${px(across)} ${px(down)}`;
80
+ return `mask-image:linear-gradient(#000 0 0),${layers.join(',')};mask-size:round(down,100%,${px(across)})${`,${size}`.repeat(n)};mask-position:0${`,${place.position}`.repeat(n)};mask-repeat:no-repeat${`,${place.repeat}`.repeat(n)};mask-composite:intersect,${composite}`;
81
+ }
82
+ const size = `${px(across)} ${px(down)}`;
83
+ // Every layer shares one tile. The fill carries it too, so code that reads
84
+ // the grid from the background (the dissolve, the chart and table fields)
85
+ // finds the same marks.
86
+ return `background:${color} ${place.position}/${size} ${place.repeat};mask:${layers.join(',')};mask-size:${size};mask-position:${place.position};mask-repeat:${place.repeat};mask-composite:${composite}`;
87
+ }
88
+ /**
89
+ * Squares or dashes for a skeleton or chart surface. `position` works like
90
+ * dotGrid's: `space` (whole marks only) unless a position is given.
91
+ */
92
+ export function shapeGrid(mark, position) {
93
+ return maskGrid(mark, shapes[mark], position
94
+ ? { position, repeat: 'repeat' }
95
+ : { position: 'center', repeat: 'space' }, markColor);
96
+ }
97
+ /**
98
+ * Lines end on their last whole mark instead of a mark cut in half: a mask
99
+ * keeps whole tiles from the left. It needs CSS round(); without it a line
100
+ * looks as before. Forced colours draw an outline, so they keep no mask.
101
+ */
102
+ export function lineTrim(host, surface, marks = ['dot', 'square', 'dash']) {
103
+ const rules = marks
104
+ .map((mark) => mark === 'dot'
105
+ ? `${host()} ${surface}{mask:linear-gradient(#000 0 0) 0/round(down,100%,var(--g)) no-repeat}`
106
+ : `${host(mark)} ${surface}{${maskGrid(mark, shapes[mark], { position: '0 0', repeat: 'repeat', trim: true }, markColor)}}`)
107
+ .join('');
108
+ return `@supports (width:round(down,1px,1px)){@media(forced-colors:none){${rules}}}`;
109
+ }
110
+ /**
111
+ * A circle fades out over its last few pixels, so marks its edge would cut
112
+ * read as softly faded instead of as slivers.
113
+ */
114
+ export const circleEdge = `mask:radial-gradient(closest-side,#000 calc(100% - ${markSize}*.7),#0000)`;
115
+ /**
116
+ * TextLoader's placeholder has 2 px dots at a 6 px pitch; squares and dashes
117
+ * keep that weight. Dashes read as hatching here (design/SPEC.md), but an app
118
+ * that asks for them still gets them.
119
+ */
120
+ const textShapes = {
121
+ square: { width: 2, height: 2, across: 6, down: 6, radius: 0.5 },
122
+ dash: { width: 4.2, height: 1.6, across: 6, down: 6, radius: 0.8 },
123
+ };
124
+ /**
125
+ * Rules that draw TextLoader's placeholder with squares or dashes, in the
126
+ * mark colour: the placeholder's own text is transparent, so `currentColor`
127
+ * would draw nothing.
128
+ */
129
+ export function textMarkShapes(host, surface) {
130
+ return ['square', 'dash']
131
+ .map((mark) => `${host(mark)} ${surface}{${maskGrid(mark, textShapes[mark], { position: '0 0', repeat: 'repeat' }, markColor)}}`)
132
+ .join('');
133
+ }
134
+ /**
135
+ * TypingDots shapes, from the spec's mockup: a square is 90% of the dot size,
136
+ * and a dash is 80% of it tall and 2.7 times as wide as it is tall.
137
+ */
138
+ export function typingShapes(host, dot) {
139
+ return `${host('square')} ${dot}{width:calc(${typingSize}*.9);height:calc(${typingSize}*.9);border-radius:calc(${typingSize}*.25)}${host('dash')} ${dot}{width:calc(${typingSize}*2.16);height:calc(${typingSize}*.8);border-radius:999px}`;
140
+ }
141
+ /** Rules that give a painted surface its mark's pitch, for the fields that read it. */
142
+ export function markPitches(host, surface) {
143
+ return ['square', 'dash']
144
+ .map((mark) => `${host(mark)} ${surface}{background-size:${shapes[mark].across}px ${shapes[mark].down}px}`)
145
+ .join('');
146
+ }
147
+ /** The host's mark; a missing or unknown value draws dots. */
148
+ export function markOf(host) {
149
+ const value = host.getAttribute('mark');
150
+ return value === 'dash' || value === 'square' ? value : 'dot';
151
+ }
152
+ /** The default dot's radius. Painter commands give a radius; other marks scale from it. */
153
+ export const dotRadius = 2.2;
154
+ /**
155
+ * The box a painter draws for a command of radius `r`: a circle for a dot,
156
+ * and for squares and dashes the spec's shape scaled by `r` against the
157
+ * default dot, so the default radius draws them at their spec size.
158
+ */
159
+ export function markBox(mark, r) {
160
+ if (mark === 'dot')
161
+ return { width: 2 * r, height: 2 * r, radius: r };
162
+ const shape = shapes[mark];
163
+ const scale = r / dotRadius;
164
+ return {
165
+ width: shape.width * scale,
166
+ height: shape.height * scale,
167
+ radius: shape.radius * scale,
168
+ };
169
+ }
170
+ /** Rules that draw `surface` with squares or dashes when `host(mark)` matches. */
171
+ export function markShapes(host, surface, position) {
172
+ return ['square', 'dash']
173
+ .map((mark) => `${host(mark)} ${surface}{${shapeGrid(mark, position)}}`)
174
+ .join('');
175
+ }
176
+ /** Line placeholders are two rows of the host's mark tall. */
177
+ export function markLineHeights(host) {
178
+ return ['square', 'dash']
179
+ .map((mark) => `${host(mark)}{height:${2 * shapes[mark].down}px}`)
180
+ .join('');
181
+ }
182
+ /**
183
+ * The idle glow's profile across the field: a Gaussian, exp(-d²) for d in
184
+ * [-3.2, 3.2] standard deviations, in mask alpha. The mask is 128% of the
185
+ * field wide, because one deviation is 20% of the field.
186
+ */
187
+ export const glowMask = 'linear-gradient(104deg,#0000 12.5%,#00000005 18.75%,#0000001b 26.56%,#0000005e 34.38%,#000000c7 42.19%,#000 50%,#000000c7 57.81%,#0000005e 65.63%,#0000001b 73.44%,#00000005 81.25%,#0000 87.5%) 0 0/128% 100% no-repeat';
188
+ /** Motion curves from the spec. */
189
+ export const curves = {
190
+ /** Content entering and UI transitions: a long tail, no overshoot. */
191
+ settle: 'cubic-bezier(.22,1,.36,1)',
192
+ /** Opacity of revealed content. */
193
+ fade: 'cubic-bezier(.33,0,.2,1)',
194
+ /** Marks, the idle glow and chart glides. */
195
+ sine: 'cubic-bezier(.37,0,.63,1)',
196
+ };
197
+ /**
198
+ * The handoff (design/SPEC.md): 1.1 s in all. Content fades in over 700 ms
199
+ * while a 2 px blur clears, and rises 5 px over 910 ms. Marks dim, shrink by
200
+ * 30% and drift up 3 px. An explicit `timing.duration` scales every part.
201
+ */
202
+ export const handoff = {
203
+ duration: 1100,
204
+ contentFade: 700,
205
+ contentRise: 910,
206
+ risePx: 5,
207
+ blurPx: 2,
208
+ markShrink: 0.3,
209
+ markDriftPx: 3,
210
+ };
211
+ /**
212
+ * The "take shape, then hand over" handoff (design/SPEC.md), shared by every
213
+ * loader: marks travel in a wave to the real content's shape, then the content
214
+ * wipes in along a soft front and the marks leave where it passes them.
215
+ */
216
+ export const morphTiming = {
217
+ /** Each mark's own journey, as a share of the handoff. */
218
+ travel: 0.34,
219
+ /** How much later the far end of the content starts travelling. */
220
+ stagger: 0.2,
221
+ /** When the content starts to wipe in. */
222
+ wipeStart: 0.46,
223
+ /** Width of the soft front, in px. */
224
+ edge: 36,
225
+ /** Opacity of a mark that has arrived. */
226
+ arrive: 0.62,
227
+ };
@@ -0,0 +1,2 @@
1
+ /** Inclusive finite-command bounds, shared by recipes and owned rendering. */
2
+ export declare const clamp: (value: number, minimum?: number, maximum?: number) => number;
@@ -0,0 +1,2 @@
1
+ /** Inclusive finite-command bounds, shared by recipes and owned rendering. */
2
+ export const clamp = (value, minimum = 0, maximum = 1) => Math.max(minimum, Math.min(maximum, value));
@@ -0,0 +1,62 @@
1
+ import type { Dot } from '../animations.js';
2
+ import { type Mark } from './marks.js';
3
+ /**
4
+ * What a placeholder hands the region's morph (morph.ts): its marks as last
5
+ * drawn, grouped into parts, in the region's coordinates. Skeletons and
6
+ * TypingDots draw theirs with CSS, so the morph reads them from the page
7
+ * (`skeletonParts`, `typingPart`) and they carry none of this code. Chart and
8
+ * table paint theirs on a canvas, so they hand them over through
9
+ * `[morphMarks]`.
10
+ */
11
+ export declare const morphMarks: unique symbol;
12
+ export interface MarkSource {
13
+ [morphMarks](origin: DOMRect): readonly Part[];
14
+ }
15
+ export interface Box {
16
+ readonly x: number;
17
+ readonly y: number;
18
+ readonly w: number;
19
+ readonly h: number;
20
+ /** Corner radius in px. */
21
+ readonly r: number;
22
+ }
23
+ export interface Seed {
24
+ readonly x: number;
25
+ readonly y: number;
26
+ readonly r: number;
27
+ readonly o: number;
28
+ readonly mark: Mark;
29
+ readonly fill: string;
30
+ readonly accent: string;
31
+ }
32
+ export type Kind = 'row' | 'box' | 'round';
33
+ export interface Part {
34
+ readonly kind: Kind;
35
+ readonly box: Box;
36
+ readonly seeds: readonly Seed[];
37
+ /** Pitch and radius of the marks it lays out at its destination. */
38
+ readonly pitch: number;
39
+ readonly radius: number;
40
+ }
41
+ export declare const relative: (rect: DOMRect, origin: DOMRect, r?: number) => Box;
42
+ /** Corner radius in px, from the first computed corner. */
43
+ export declare function radiusOf(css: CSSStyleDeclaration, w: number, h: number): number;
44
+ /** Whether a mark centred at (x, y) sits inside a rounded box. */
45
+ export declare function inside(box: Box, x: number, y: number, margin?: number): boolean;
46
+ /** A circle or a near-square with round corners, not a pill: an avatar or a dot. */
47
+ export declare const round: (box: Box) => boolean;
48
+ /** The marks' colours: the placeholder's own, or the defaults. */
49
+ export declare function colours(host: Element, css: CSSStyleDeclaration): {
50
+ fill: string;
51
+ accent: string;
52
+ mark: Mark;
53
+ };
54
+ /** A skeleton's marks, where its stylesheet draws them. */
55
+ export declare function skeletonParts(host: HTMLElement, origin: DOMRect): Part[];
56
+ /** TypingDots: its dots unroll into the message's lines, at field size. */
57
+ export declare function typingPart(host: HTMLElement, origin: DOMRect): Part[];
58
+ /**
59
+ * A TableLoader: its painted marks, grouped into runs, one per cell (two rows
60
+ * of marks that sit together), so each cell becomes the text in its place.
61
+ */
62
+ export declare function denseParts(host: HTMLElement, origin: DOMRect, marks: readonly Dot[]): Part[];
@@ -0,0 +1,205 @@
1
+ import { measureSurface } from './dissolve.js';
2
+ import { dotRadius, glowColor, markBox, markColor, markOf, } from './marks.js';
3
+ import { clamp } from './math.js';
4
+ /**
5
+ * What a placeholder hands the region's morph (morph.ts): its marks as last
6
+ * drawn, grouped into parts, in the region's coordinates. Skeletons and
7
+ * TypingDots draw theirs with CSS, so the morph reads them from the page
8
+ * (`skeletonParts`, `typingPart`) and they carry none of this code. Chart and
9
+ * table paint theirs on a canvas, so they hand them over through
10
+ * `[morphMarks]`.
11
+ */
12
+ export const morphMarks = Symbol('dotquilt.morph-marks');
13
+ export const relative = (rect, origin, r = 0) => ({
14
+ x: rect.left - origin.left,
15
+ y: rect.top - origin.top,
16
+ w: rect.width,
17
+ h: rect.height,
18
+ r,
19
+ });
20
+ /** Corner radius in px, from the first computed corner. */
21
+ export function radiusOf(css, w, h) {
22
+ const value = css.borderTopLeftRadius.split(/\s+/)[0] ?? '0';
23
+ const n = parseFloat(value) || 0;
24
+ return Math.min(Math.min(w, h) / 2, value.endsWith('%') ? (n / 100) * Math.min(w, h) : n);
25
+ }
26
+ /** Whether a mark centred at (x, y) sits inside a rounded box. */
27
+ export function inside(box, x, y, margin = 0) {
28
+ const dx = Math.max(0, Math.abs(x - box.x - box.w / 2) - (box.w / 2 - box.r));
29
+ const dy = Math.max(0, Math.abs(y - box.y - box.h / 2) - (box.h / 2 - box.r));
30
+ return (x >= box.x - margin &&
31
+ x <= box.x + box.w + margin &&
32
+ y >= box.y - margin &&
33
+ y <= box.y + box.h + margin &&
34
+ dx * dx + dy * dy <= (box.r + margin) ** 2);
35
+ }
36
+ /** A circle or a near-square with round corners, not a pill: an avatar or a dot. */
37
+ export const round = (box) => box.r >= Math.min(box.w, box.h) / 2 - 1 &&
38
+ Math.max(box.w, box.h) <= 1.3 * Math.min(box.w, box.h);
39
+ /** The marks' colours: the placeholder's own, or the defaults. */
40
+ export function colours(host, css) {
41
+ const own = css.getPropertyValue('--dotquilt-color').trim();
42
+ const accent = css.getPropertyValue('--dotquilt-accent-color').trim();
43
+ return {
44
+ fill: own || markColor,
45
+ accent: accent || glowColor,
46
+ mark: markOf(host),
47
+ };
48
+ }
49
+ /** A skeleton's marks, where its stylesheet draws them. */
50
+ export function skeletonParts(host, origin) {
51
+ const root = host.shadowRoot, win = host.ownerDocument.defaultView;
52
+ if (!root || !win)
53
+ return [];
54
+ const css = win.getComputedStyle(host), look = colours(host, css), hostBox = host.getBoundingClientRect(), clip = relative(hostBox, origin, radiusOf(css, hostBox.width, hostBox.height));
55
+ const name = host.localName;
56
+ const parts = [];
57
+ for (const surface of root.querySelectorAll('.surface')) {
58
+ if (surface.closest('.pulse,.lift'))
59
+ continue;
60
+ const shape = measureSurface(win, surface, origin);
61
+ if (![shape.width, shape.height, shape.columnStep, shape.rowStep].every((n) => Number.isFinite(n) && n > 0))
62
+ continue;
63
+ const opacity = +win.getComputedStyle(surface).opacity || 0;
64
+ const r = look.mark === 'dot' ? shape.size / 2 : dotRadius;
65
+ const seeds = [];
66
+ // Lines end on their last whole mark where CSS round() trims them.
67
+ const end = (name === 'dotquilt-skeleton-line' ||
68
+ name === 'dotquilt-skeleton-text') &&
69
+ win.CSS?.supports?.('width', 'round(down, 1px, 1px)')
70
+ ? Math.floor(shape.width / shape.columnStep + 1e-6) * shape.columnStep
71
+ : Number.POSITIVE_INFINITY;
72
+ const firstColumn = shape.columnOffset + shape.columnStep / 2, firstRow = shape.rowOffset + shape.rowStep / 2;
73
+ for (let y = firstRow - shape.rowStep; y <= shape.height + r && seeds.length < 3000; y += shape.rowStep)
74
+ for (let x = firstColumn - shape.columnStep; x <= shape.width + r; x += shape.columnStep) {
75
+ // Marks the edge cuts in half keep their visible share.
76
+ const cover = clamp((x + r) / (2 * r)) *
77
+ clamp((shape.width - x + r) / (2 * r)) *
78
+ clamp((y + r) / (2 * r)) *
79
+ clamp((shape.height - y + r) / (2 * r));
80
+ const px = shape.x + x, py = shape.y + y;
81
+ if (cover < 0.35 ||
82
+ x + shape.columnStep / 2 > end + 0.01 ||
83
+ !inside(clip, px, py, -r * 0.4))
84
+ continue;
85
+ seeds.push({ x: px, y: py, r, o: opacity * cover, ...look });
86
+ }
87
+ if (!seeds.length)
88
+ continue;
89
+ const box = { x: shape.x, y: shape.y, w: shape.width, h: shape.height };
90
+ const kind = name === 'dotquilt-skeleton-circle' || round(clip)
91
+ ? 'round'
92
+ : name === 'dotquilt-skeleton-block' &&
93
+ shape.height > 2.5 * shape.rowStep
94
+ ? 'box'
95
+ : 'row';
96
+ parts.push({
97
+ kind,
98
+ box: { ...box, r: kind === 'round' ? Math.min(box.w, box.h) / 2 : 0 },
99
+ seeds,
100
+ pitch: shape.columnStep,
101
+ radius: r,
102
+ });
103
+ }
104
+ return parts;
105
+ }
106
+ /** TypingDots: its dots unroll into the message's lines, at field size. */
107
+ export function typingPart(host, origin) {
108
+ const root = host.shadowRoot, win = host.ownerDocument.defaultView;
109
+ if (!root || !win)
110
+ return [];
111
+ const look = colours(host, win.getComputedStyle(host));
112
+ const unit = markBox(look.mark, dotRadius).height;
113
+ const seeds = [...root.querySelectorAll('.dot')].flatMap((dot) => {
114
+ const box = dot.getBoundingClientRect();
115
+ if (!box.width || !box.height)
116
+ return [];
117
+ return [
118
+ {
119
+ x: box.left - origin.left + box.width / 2,
120
+ y: box.top - origin.top + box.height / 2,
121
+ r: (dotRadius * box.height) / unit,
122
+ o: +win.getComputedStyle(dot).opacity || 0.3,
123
+ ...look,
124
+ },
125
+ ];
126
+ });
127
+ if (!seeds.length)
128
+ return [];
129
+ const xs = seeds.map((s) => s.x), ys = seeds.map((s) => s.y), x = Math.min(...xs), y = Math.min(...ys);
130
+ return [
131
+ {
132
+ kind: 'row',
133
+ box: { x, y, w: Math.max(...xs) - x, h: Math.max(...ys) - y, r: 0 },
134
+ seeds,
135
+ pitch: 9,
136
+ radius: dotRadius,
137
+ },
138
+ ];
139
+ }
140
+ /**
141
+ * A TableLoader: its painted marks, grouped into runs, one per cell (two rows
142
+ * of marks that sit together), so each cell becomes the text in its place.
143
+ */
144
+ export function denseParts(host, origin, marks) {
145
+ const win = host.ownerDocument.defaultView;
146
+ if (!win || !marks.length)
147
+ return [];
148
+ const look = colours(host, win.getComputedStyle(host));
149
+ const box = host.getBoundingClientRect();
150
+ const seeds = marks
151
+ .filter((mark) => mark.tone !== 'accent' && mark.opacity > 0.02)
152
+ .map((mark) => ({
153
+ x: box.left - origin.left + mark.x,
154
+ y: box.top - origin.top + mark.y,
155
+ r: mark.size,
156
+ o: mark.opacity,
157
+ ...look,
158
+ }));
159
+ if (!seeds.length)
160
+ return [];
161
+ // The pitch: the usual distance to the next mark along a row.
162
+ const sorted = [...seeds].sort((a, b) => a.y - b.y || a.x - b.x);
163
+ const steps = sorted
164
+ .slice(1)
165
+ .map((seed, i) => seed.x - sorted[i].x)
166
+ .filter((step) => step > 0.5)
167
+ .sort((a, b) => a - b);
168
+ const pitch = steps[Math.floor(steps.length / 2)] ?? 9;
169
+ // Bands of rows, then runs within a band split where marks stop.
170
+ const bands = [];
171
+ for (const seed of sorted) {
172
+ const band = bands.at(-1);
173
+ const last = band?.at(-1);
174
+ if (band && last && seed.y - last.y <= pitch * 1.5)
175
+ band.push(seed);
176
+ else
177
+ bands.push([seed]);
178
+ }
179
+ const parts = [];
180
+ for (const band of bands) {
181
+ const across = [...band].sort((a, b) => a.x - b.x);
182
+ let run = [];
183
+ const flush = () => {
184
+ if (!run.length)
185
+ return;
186
+ const xs = run.map((seed) => seed.x), ys = run.map((seed) => seed.y), x = Math.min(...xs), y = Math.min(...ys);
187
+ parts.push({
188
+ kind: 'row',
189
+ box: { x, y, w: Math.max(...xs) - x, h: Math.max(...ys) - y, r: 0 },
190
+ seeds: run,
191
+ pitch,
192
+ radius: run[0]?.r ?? dotRadius,
193
+ });
194
+ run = [];
195
+ };
196
+ for (const seed of across) {
197
+ const last = run.at(-1);
198
+ if (last && seed.x - last.x > pitch * 2.2)
199
+ flush();
200
+ run.push(seed);
201
+ }
202
+ flush();
203
+ }
204
+ return parts;
205
+ }