@johnmorrisdotca/fuda-cards 0.9.2 → 0.11.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 (98) hide show
  1. package/LICENSE +21 -0
  2. package/NOTICE.md +14 -0
  3. package/README.md +466 -60
  4. package/dist/binder.d.ts +4 -6
  5. package/dist/binder.js +32 -23
  6. package/dist/card-markup.d.ts +2 -0
  7. package/dist/card-markup.js +59 -0
  8. package/dist/card-options.d.ts +131 -0
  9. package/dist/card-options.js +48 -0
  10. package/dist/card-styles.d.ts +2 -0
  11. package/dist/card-styles.js +314 -0
  12. package/dist/choice.d.ts +1 -1
  13. package/dist/choice.js +27 -23
  14. package/dist/collection-address.d.ts +8 -0
  15. package/dist/collection-address.js +52 -0
  16. package/dist/collection-binder-view.d.ts +9 -0
  17. package/dist/collection-binder-view.js +123 -0
  18. package/dist/collection-controls.d.ts +2 -0
  19. package/dist/collection-controls.js +143 -0
  20. package/dist/collection-deck.d.ts +11 -0
  21. package/dist/collection-deck.js +165 -0
  22. package/dist/collection-dialog.d.ts +2 -0
  23. package/dist/collection-dialog.js +28 -0
  24. package/dist/collection-element.d.ts +41 -63
  25. package/dist/collection-element.js +288 -472
  26. package/dist/collection-host.d.ts +5 -0
  27. package/dist/collection-host.js +1 -0
  28. package/dist/collection-icons.d.ts +3 -0
  29. package/dist/collection-icons.js +19 -0
  30. package/dist/collection-motion.d.ts +11 -0
  31. package/dist/collection-motion.js +72 -0
  32. package/dist/collection-styles.d.ts +4 -0
  33. package/dist/collection-styles.js +336 -0
  34. package/dist/collection-views.d.ts +8 -0
  35. package/dist/collection-views.js +8 -0
  36. package/dist/collection.d.ts +140 -11
  37. package/dist/collection.js +139 -33
  38. package/dist/element-define.d.ts +2 -0
  39. package/dist/element-define.js +3 -0
  40. package/dist/element.d.ts +20 -1
  41. package/dist/element.js +289 -98
  42. package/dist/index.d.ts +9 -52
  43. package/dist/index.js +5 -5
  44. package/dist/live-3d.d.ts +126 -0
  45. package/dist/live-3d.js +229 -0
  46. package/dist/materials.d.ts +117 -6
  47. package/dist/materials.js +191 -28
  48. package/dist/motion.d.ts +2 -0
  49. package/dist/motion.js +4 -0
  50. package/dist/pile-card.js +138 -91
  51. package/dist/pile.d.ts +61 -8
  52. package/dist/pile.js +89 -29
  53. package/dist/stack.d.ts +42 -6
  54. package/dist/stack.js +28 -3
  55. package/dist/version.d.ts +11 -0
  56. package/dist/version.js +11 -0
  57. package/dist/wear.d.ts +147 -9
  58. package/dist/wear.js +273 -89
  59. package/dist/zoom.d.ts +1 -1
  60. package/dist/zoom.js +73 -42
  61. package/docs/API.md +783 -0
  62. package/docs/collection-displays.md +1 -1
  63. package/docs/guides/accessibility-and-theming.md +62 -0
  64. package/docs/guides/architecture.md +53 -0
  65. package/docs/guides/binder-and-piles.md +83 -0
  66. package/docs/guides/bundlers.md +60 -0
  67. package/docs/guides/card-element.md +65 -0
  68. package/docs/guides/collections.md +86 -0
  69. package/docs/guides/embed-in-an-iframe.md +39 -0
  70. package/docs/guides/frameworks.md +132 -0
  71. package/docs/guides/getting-started.md +96 -0
  72. package/docs/guides/html-and-cdn.md +69 -0
  73. package/docs/guides/ja/accessibility-and-theming.md +62 -0
  74. package/docs/guides/ja/architecture.md +53 -0
  75. package/docs/guides/ja/binder-and-piles.md +83 -0
  76. package/docs/guides/ja/bundlers.md +60 -0
  77. package/docs/guides/ja/card-element.md +65 -0
  78. package/docs/guides/ja/collections.md +86 -0
  79. package/docs/guides/ja/embed-in-an-iframe.md +39 -0
  80. package/docs/guides/ja/frameworks.md +132 -0
  81. package/docs/guides/ja/getting-started.md +96 -0
  82. package/docs/guides/ja/html-and-cdn.md +69 -0
  83. package/docs/guides/ja/live-3d.md +75 -0
  84. package/docs/guides/ja/materials-and-stacks.md +73 -0
  85. package/docs/guides/ja/motion-and-spin.md +73 -0
  86. package/docs/guides/ja/troubleshooting.md +60 -0
  87. package/docs/guides/ja/typescript-and-node.md +45 -0
  88. package/docs/guides/ja/upgrading.md +56 -0
  89. package/docs/guides/ja/wear.md +63 -0
  90. package/docs/guides/live-3d.md +75 -0
  91. package/docs/guides/materials-and-stacks.md +73 -0
  92. package/docs/guides/motion-and-spin.md +73 -0
  93. package/docs/guides/troubleshooting.md +60 -0
  94. package/docs/guides/typescript-and-node.md +45 -0
  95. package/docs/guides/upgrading.md +56 -0
  96. package/docs/guides/wear.md +63 -0
  97. package/docs/live-3d.md +59 -0
  98. package/package.json +81 -11
@@ -0,0 +1,314 @@
1
+ // The stylesheet of `<fuda-card>`, in the order it cascades: the host and its colours, the turn, the face, the picture, the foil and
2
+ // the gloss, the back, the edge, the cards under the top one. One design pixel is `--u`, a 300th of the card's width, so a card of any
3
+ // width is the same drawing: every length below is a number of design pixels, never a fixed pixel size.
4
+ /** The host: its size, its shadow and the colours of the look it has (the classic gold look unless a variant says otherwise). */
5
+ const HOST_CSS = `
6
+ :host {
7
+ display: inline-block;
8
+ width: 300px;
9
+ aspect-ratio: 2.5/3.5;
10
+ perspective: var(--fuda-perspective, 1000px);
11
+ container-type: inline-size;
12
+ /* A tight shadow where the card meets the table and a soft one under it. */
13
+ filter: drop-shadow(0 1px 1px #0006) drop-shadow(0 12px 14px #0005);
14
+ font-family: Georgia, serif;
15
+ color: #27201b;
16
+ /* The look: the frame and its line, the panel inside it and its line, the line round the picture, the rules between the texts, the card stock's edge. */
17
+ --frame: linear-gradient(135deg, #fbdf87, #ab742c 35%, #ffe9a6 58%, #ae792d);
18
+ --frame-line: #9c702d;
19
+ --panel: linear-gradient(150deg, #f9edc8, #d6b477);
20
+ --panel-line: #76512a;
21
+ --art-line: #dcc18a;
22
+ --rule: #9d8054;
23
+ --edge-color: #e3c777;
24
+ /* The foil: a rainbow in the frame that shifts with the light. A matte card has none. */
25
+ --foil: linear-gradient(115deg, #ff5d8f44, #ffb35c44, #f5f06544, #5de8a044, #5db7ff44, #a67bff44, #ff5d8f44);
26
+ }
27
+ :host([finish=matte]) { --foil: none; }
28
+ :host([variant=sport]) {
29
+ --frame: linear-gradient(135deg, #ebedef, #525e69, #fff, #47505d);
30
+ --frame-line: #394c5b;
31
+ --panel: linear-gradient(145deg, #eef1ee, #aebac1);
32
+ --panel-line: #394c5b;
33
+ --art-line: #a9b9c0;
34
+ --rule: #6f7f89;
35
+ --edge-color: #ece4d2;
36
+ }
37
+ :host([variant=cosmic]) {
38
+ --frame: linear-gradient(130deg, #c9b4ff, #433b83, #dabdff, #503969);
39
+ --frame-line: #584378;
40
+ --panel: linear-gradient(145deg, #e6dafa, #a997cd);
41
+ --panel-line: #584378;
42
+ --art-line: #bba8e0;
43
+ --rule: #7f6aa6;
44
+ --edge-color: #ece4d2;
45
+ }
46
+ * { box-sizing: border-box; }
47
+ `;
48
+ /** The turn: the card about its centre or a corner, a turn the reader sets, and the flip. */
49
+ const TURN_CSS = `
50
+ .rotation {
51
+ --u: calc(100cqw / 300);
52
+ height: 100%;
53
+ transform-style: preserve-3d;
54
+ transform-origin: center center;
55
+ }
56
+ :host([card-spin="center"]) .rotation { animation: fuda-turn var(--fuda-card-spin-duration, 180s) linear infinite; }
57
+ :host([card-spin="corner"]) .rotation {
58
+ transform-origin: 0 100%;
59
+ transform: translate(50%, -50%);
60
+ animation: fuda-corner-turn var(--fuda-card-spin-duration, 180s) linear infinite;
61
+ }
62
+ :host([card-spin-direction="reverse"]) .rotation { animation-direction: reverse; }
63
+ :host([card-spin-paused]) .rotation { animation-play-state: paused; }
64
+ @keyframes fuda-turn { to { transform: rotateY(360deg); } }
65
+ @keyframes fuda-corner-turn {
66
+ from { transform: translate(50%, -50%) rotateY(0); }
67
+ to { transform: translate(50%, -50%) rotateY(360deg); }
68
+ }
69
+ :host([card-view]) .rotation {
70
+ animation: none;
71
+ /* Kept as its own layer, so a style change that does not move the card does not draw it a second time. */
72
+ will-change: transform;
73
+ transform: rotateX(var(--fuda-tilt, 0deg)) rotateY(var(--fuda-yaw, 0deg));
74
+ }
75
+ :host([card-view][card-spin="corner"]) .rotation {
76
+ transform: translate(50%, -50%) rotateX(var(--fuda-tilt, 0deg)) rotateY(var(--fuda-yaw, 0deg));
77
+ }
78
+ /* A pure rotateY, once the angle has wrapped past 180, is not the same bitmap twice in software drawing, so the back carries half a degree of tilt and a second picture of it agrees with the first. */
79
+ :host([data-back][card-view]) .rotation {
80
+ transform: rotateX(calc(var(--fuda-tilt, 0deg) + 0.5deg)) rotateY(var(--fuda-yaw, 0deg));
81
+ }
82
+ :host([data-back][card-view][card-spin="corner"]) .rotation {
83
+ transform: translate(50%, -50%) rotateX(calc(var(--fuda-tilt, 0deg) + 0.5deg)) rotateY(var(--fuda-yaw, 0deg));
84
+ }
85
+ @media (prefers-reduced-motion: reduce) {
86
+ :host([card-spin]) .rotation { animation: none; }
87
+ :host .card { transition: none; }
88
+ .art ::slotted(*) { transition: none; }
89
+ }
90
+ .card {
91
+ /* The card's thickness and the pitch of one card in a stack, in pixels at this card's width (a card is 63 mm wide). */
92
+ --t: calc(var(--mm, 0.325) * 100cqw / 63);
93
+ --pitch: calc(var(--mm1, var(--mm, 0.325)) * 100cqw / 63);
94
+ height: 100%;
95
+ position: relative;
96
+ transform-style: preserve-3d;
97
+ transition: transform 0.65s;
98
+ }
99
+ :host([flipped]) .card { transform: rotateY(180deg); }
100
+ `;
101
+ /** The face a person reads: the frame, the panel, the texts and the rules. The cards under the top one of a stack are the same frame with nothing written on it. */
102
+ const FACE_CSS = `
103
+ .face {
104
+ position: absolute;
105
+ inset: 0;
106
+ border-radius: calc(15 * var(--u));
107
+ backface-visibility: hidden;
108
+ overflow: hidden;
109
+ }
110
+ .front, .still {
111
+ padding: calc(13 * var(--u));
112
+ background-image: var(--foil), var(--frame);
113
+ background-size: 220% 220%, auto;
114
+ background-position: calc(var(--fuda-sheen-x, 30) * 1%) calc(var(--fuda-sheen-y, 30) * 1%), 0 0;
115
+ border: calc(2 * var(--u)) solid var(--frame-line);
116
+ }
117
+ .front { transform: translateZ(calc(var(--t) / 2)); }
118
+ /* The front is not drawn while the back is toward the reader. */
119
+ :host([data-back]) .front { display: none; }
120
+ .inner {
121
+ height: 100%;
122
+ padding: calc(12 * var(--u));
123
+ background: var(--panel);
124
+ border: calc(2 * var(--u)) solid var(--panel-line);
125
+ box-shadow: inset 0 calc(1 * var(--u)) 0 #fff7, inset 0 calc(-2 * var(--u)) calc(6 * var(--u)) #4a2e0a26;
126
+ display: flex;
127
+ flex-direction: column;
128
+ gap: calc(8 * var(--u));
129
+ }
130
+ .heading, .footer {
131
+ display: flex;
132
+ justify-content: space-between;
133
+ align-items: center;
134
+ gap: calc(5 * var(--u));
135
+ }
136
+ .heading { font-weight: bold; font-size: calc(20 * var(--u)); }
137
+ .badge { font: 700 calc(10 * var(--u)) sans-serif; letter-spacing: 0.12em; }
138
+ .subtitle { text-align: center; font: italic calc(11 * var(--u)) Georgia; }
139
+ .description {
140
+ border-top: calc(1 * var(--u)) solid var(--rule);
141
+ padding-top: calc(9 * var(--u));
142
+ font-size: calc(13 * var(--u));
143
+ line-height: 1.35;
144
+ flex: 1;
145
+ }
146
+ .footer {
147
+ border-top: calc(1 * var(--u)) solid var(--rule);
148
+ padding-top: calc(5 * var(--u));
149
+ font: 700 calc(9 * var(--u)) sans-serif;
150
+ letter-spacing: 0.08em;
151
+ }
152
+ `;
153
+ /** The picture and its Animate button. */
154
+ const ART_CSS = `
155
+ .art {
156
+ position: relative;
157
+ height: 53%;
158
+ border: calc(5 * var(--u)) ridge var(--art-line);
159
+ box-shadow: 0 calc(2 * var(--u)) calc(5 * var(--u)) #47301488, inset 0 0 calc(10 * var(--u)) #0006;
160
+ background: radial-gradient(circle at 50% 35%, #7496a1, #273c4c);
161
+ overflow: hidden;
162
+ }
163
+ .art ::slotted(*) {
164
+ width: 100%;
165
+ height: 100%;
166
+ object-fit: contain;
167
+ display: block;
168
+ opacity: 0;
169
+ transition: opacity 0.35s ease;
170
+ }
171
+ .art.ready ::slotted(*) { opacity: 1; }
172
+ :host([motion="pan"]) .art ::slotted(img) {
173
+ object-fit: cover;
174
+ object-position: var(--fuda-focus-x, 50%) var(--fuda-focus-y, 25%);
175
+ }
176
+ :host([motion="pan"][moving]) .art ::slotted(img) { animation: fuda-pan var(--fuda-pan-duration, 12s) ease-in-out infinite alternate; }
177
+ :host([motion="pan"][pan-loop="restart"]) .art ::slotted(img) { animation-direction: normal; }
178
+ :host([motion="pan"][pan-direction="up"]) .art ::slotted(img) { animation-direction: alternate-reverse; }
179
+ :host([motion="pan"][pan-direction="up"][pan-loop="restart"]) .art ::slotted(img) { animation-direction: reverse; }
180
+ @keyframes fuda-pan {
181
+ from { object-position: 50% 0%; }
182
+ to { object-position: 50% 100%; }
183
+ }
184
+ @media (prefers-reduced-motion: reduce) {
185
+ :host([motion="pan"][moving]) .art ::slotted(img) { animation: none; }
186
+ .motion-button { transition: none; }
187
+ }
188
+ .motion-button {
189
+ position: absolute;
190
+ right: 0;
191
+ bottom: 0;
192
+ z-index: 1;
193
+ width: 48px;
194
+ height: 48px;
195
+ padding: 0;
196
+ border: 0;
197
+ background: none;
198
+ display: grid;
199
+ place-items: center;
200
+ cursor: pointer;
201
+ opacity: 0.55;
202
+ transition: opacity 0.2s;
203
+ -webkit-tap-highlight-color: transparent;
204
+ }
205
+ .motion-button:hover, .motion-button:focus-visible, .motion-button[aria-pressed=true] { opacity: 1; }
206
+ .motion-button:focus-visible { outline: none; }
207
+ .motion-button:focus-visible .glyph { outline: 3px solid white; outline-offset: 2px; }
208
+ .glyph {
209
+ width: 26px;
210
+ height: 26px;
211
+ border-radius: 50%;
212
+ display: grid;
213
+ place-items: center;
214
+ background: #101827b3;
215
+ border: 1px solid #fff5;
216
+ color: white;
217
+ }
218
+ .glyph svg { width: 11px; height: 11px; fill: currentColor; }
219
+ .motion-button[aria-pressed=true] .play, .motion-button[aria-pressed=false] .pause { display: none; }
220
+ .motion-button[hidden] { display: none; }
221
+ `;
222
+ /**
223
+ * The light on the card. A foil card catches a bright band and a rainbow that move across it as the light moves: the page says where the
224
+ * light is with --fuda-sheen-x and --fuda-sheen-y (percentages, 50 is the middle) and the card follows the pointer over it; a card
225
+ * that spins on its own sweeps the light across by itself. A matte card has no foil.
226
+ */
227
+ const SHEEN_CSS = `
228
+ .shine {
229
+ pointer-events: none;
230
+ position: absolute;
231
+ inset: 0;
232
+ background-image: linear-gradient(115deg, transparent 38%, #ffffff30 45%, #ffffff66 50%, #ffffff30 55%, transparent 62%);
233
+ background-size: 300% 300%;
234
+ background-position: calc(var(--fuda-sheen-x, 30) * 1%) calc(var(--fuda-sheen-y, 30) * 1%);
235
+ }
236
+ :host([card-spin]) .shine { animation: fuda-sheen var(--fuda-card-spin-duration, 180s) linear infinite; }
237
+ :host([card-spin-direction="reverse"]) .shine { animation-direction: reverse; }
238
+ :host([card-spin-paused]) .shine { animation-play-state: paused; }
239
+ @keyframes fuda-sheen {
240
+ from { background-position: 0% 30%; }
241
+ to { background-position: 100% 70%; }
242
+ }
243
+ :host([card-spin]) :is(.front, .still) { animation: fuda-foil var(--fuda-card-spin-duration, 180s) linear infinite; }
244
+ :host([card-spin-direction="reverse"]) :is(.front, .still) { animation-direction: reverse; }
245
+ :host([card-spin-paused]) :is(.front, .still) { animation-play-state: paused; }
246
+ @keyframes fuda-foil {
247
+ from { background-position: 0% 20%, 0 0; }
248
+ to { background-position: 100% 80%, 0 0; }
249
+ }
250
+ :host([finish=matte]) .shine { display: none; }
251
+ /* The reader is holding the angle, so the foil stays where the light is instead of sweeping on its own. */
252
+ :host([card-view]) .shine, :host([card-view]) :is(.front, .still) { animation: none; }
253
+ @media (prefers-reduced-motion: reduce) {
254
+ :host([card-spin]) .shine, :host([card-spin]) :is(.front, .still) { animation: none; }
255
+ }
256
+ `;
257
+ /** The back: the emblem on its ground, in the card stock's own frame. */
258
+ const BACK_CSS = `
259
+ .back {
260
+ transform: rotateY(180deg) translateZ(calc(var(--t) / 2));
261
+ background: radial-gradient(ellipse at center, #b78745 0 12%, #152d46 13% 27%, #386988 28% 31%, #10233b 32% 62%, #d2b074 63% 66%, #182c45 67%);
262
+ border: calc(11 * var(--u)) solid #b39158;
263
+ display: grid;
264
+ place-items: center;
265
+ color: #f7e9bf;
266
+ }
267
+ .emblem {
268
+ width: calc(125 * var(--u));
269
+ height: calc(125 * var(--u));
270
+ border: calc(2 * var(--u)) solid #edd18c;
271
+ border-radius: 50%;
272
+ display: grid;
273
+ place-items: center;
274
+ background: #17334a;
275
+ box-shadow: 0 0 0 calc(7 * var(--u)) #967344, 0 0 calc(30 * var(--u)) #e6c98288;
276
+ font: bold calc(23 * var(--u)) Georgia;
277
+ letter-spacing: 0.12em;
278
+ }
279
+ `;
280
+ /**
281
+ * The edge: the card stock seen from the side, a flat colour that darkens a little against each face (where the printed layers are), and
282
+ * for a stack one hairline for each card. The colour is the material's (`--edge-color`) or the page's own background (`--fuda-edge`).
283
+ */
284
+ const EDGE_CSS = `
285
+ .edge {
286
+ --dir: 180deg;
287
+ position: absolute;
288
+ background: var(--fuda-edge, linear-gradient(var(--dir),
289
+ color-mix(in srgb, var(--edge-color) 72%, #000),
290
+ var(--edge-color) 28%,
291
+ var(--edge-color) 72%,
292
+ color-mix(in srgb, var(--edge-color) 72%, #000)));
293
+ }
294
+ .edge.side { --dir: 90deg; }
295
+ .stacked .edge {
296
+ background:
297
+ repeating-linear-gradient(var(--dir), transparent 0 calc(var(--pitch) * 0.7), #8886 calc(var(--pitch) * 0.7) var(--pitch)),
298
+ var(--fuda-edge, linear-gradient(var(--dir), color-mix(in srgb, var(--edge-color) 72%, #000), var(--edge-color) 28%, var(--edge-color) 72%, color-mix(in srgb, var(--edge-color) 72%, #000)));
299
+ }
300
+ `;
301
+ /** The cards under the top one of a stack: the same frame as the top card, laid nudged and turned, each one a card's thickness lower. */
302
+ const STILL_CSS = `
303
+ .stills { display: contents; }
304
+ .still > .shine { border-radius: inherit; }
305
+ .still {
306
+ position: absolute;
307
+ inset: 0;
308
+ border-radius: calc(15 * var(--u));
309
+ pointer-events: none;
310
+ transform: translate3d(calc(var(--x) * 100cqw), calc(var(--y) * 100cqw), calc(var(--t) / -2 + var(--pitch) * var(--k))) rotate(calc(var(--r) * 1deg));
311
+ }
312
+ `;
313
+ /** The stylesheet of the card's shadow root. */
314
+ export const CARD_CSS = [HOST_CSS, TURN_CSS, FACE_CSS, ART_CSS, SHEEN_CSS, BACK_CSS, EDGE_CSS, STILL_CSS].join("");
package/dist/choice.d.ts CHANGED
@@ -26,7 +26,7 @@ export interface ChoiceConfig {
26
26
  value: string;
27
27
  onChange(value: string): void;
28
28
  /** `tiles` stacks the icon over the label; `row` (the default) puts them side by side. */
29
- layout?: 'tiles' | 'row';
29
+ layout?: "tiles" | "row";
30
30
  }
31
31
  /** The colours, for the dark theme (the default) and the light one. */
32
32
  export declare const CHOICE_VARS: {
package/dist/choice.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /** The colours, for the dark theme (the default) and the light one. */
2
2
  export const CHOICE_VARS = {
3
- dark: '--fc-surface:#20212c;--fc-text:#f6f4f1;--fc-muted:#b9b6c4;--fc-btn:#353747;--fc-btn-border:#79798c;--fc-accent:#ffd27e;--fc-on-accent:#241a05;--fc-stage-1:#52495a;--fc-stage-2:#222330;--fc-focus:#ffd27e;--fc-dialog:#242632',
4
- light: '--fc-surface:#f3efe6;--fc-text:#231e18;--fc-muted:#5b5346;--fc-btn:#fffdf8;--fc-btn-border:#a99d86;--fc-accent:#6d4400;--fc-on-accent:#ffffff;--fc-stage-1:#ebe2d0;--fc-stage-2:#cdc1a9;--fc-focus:#6d4400;--fc-dialog:#fbf8f1'
3
+ dark: "--fc-surface:#20212c;--fc-text:#f6f4f1;--fc-muted:#b9b6c4;--fc-btn:#353747;--fc-btn-border:#79798c;--fc-accent:#ffd27e;--fc-on-accent:#241a05;--fc-stage-1:#52495a;--fc-stage-2:#222330;--fc-focus:#ffd27e;--fc-dialog:#242632",
4
+ light: "--fc-surface:#f3efe6;--fc-text:#231e18;--fc-muted:#5b5346;--fc-btn:#fffdf8;--fc-btn-border:#a99d86;--fc-accent:#6d4400;--fc-on-accent:#ffffff;--fc-stage-1:#ebe2d0;--fc-stage-2:#cdc1a9;--fc-focus:#6d4400;--fc-dialog:#fbf8f1",
5
5
  };
6
6
  export const CHOICE_CSS = `.choice{display:grid;gap:.4rem;min-width:0}.choice[hidden]{display:none}.choice-label{font:700 .75rem system-ui;letter-spacing:.08em;text-transform:uppercase;color:var(--fc-muted,#b9b6c4)}
7
7
  .choice-list{display:grid;grid-template-columns:repeat(auto-fit,minmax(var(--choice-min,7.5rem),1fr));gap:.5rem}
@@ -11,29 +11,29 @@ export const CHOICE_CSS = `.choice{display:grid;gap:.4rem;min-width:0}.choice[hi
11
11
  .choice-list button:focus-visible{outline:3px solid var(--fc-focus,#ffd27e);outline-offset:3px}@media(prefers-reduced-motion:reduce){.choice-list button{transition:none}}`;
12
12
  /** Build the group. The caller puts `element` in the page and adds `CHOICE_CSS` once to the same root. */
13
13
  export function createChoice(config) {
14
- const element = document.createElement('div');
15
- element.className = 'choice';
16
- const label = document.createElement('span');
17
- label.className = 'choice-label';
14
+ const element = document.createElement("div");
15
+ element.className = "choice";
16
+ const label = document.createElement("span");
17
+ label.className = "choice-label";
18
18
  label.textContent = config.label;
19
- const list = document.createElement('div');
20
- list.className = `choice-list${config.layout === 'tiles' ? ' tiles' : ''}`;
21
- list.setAttribute('role', 'radiogroup');
22
- list.setAttribute('aria-label', config.label);
19
+ const list = document.createElement("div");
20
+ list.className = `choice-list${config.layout === "tiles" ? " tiles" : ""}`;
21
+ list.setAttribute("role", "radiogroup");
22
+ list.setAttribute("aria-label", config.label);
23
23
  let current = config.value;
24
24
  const buttons = config.options.map((option) => {
25
- const button = document.createElement('button');
26
- button.type = 'button';
27
- button.setAttribute('role', 'radio');
25
+ const button = document.createElement("button");
26
+ button.type = "button";
27
+ button.setAttribute("role", "radio");
28
28
  button.dataset.value = option.value;
29
- button.innerHTML = `${option.icon ?? ''}<span>${option.label.replace(/[&<>]/g, (c) => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;' })[c])}</span>`;
30
- button.addEventListener('click', () => choose(option.value, true));
29
+ button.innerHTML = `${option.icon ?? ""}<span>${option.label.replace(/[&<>]/g, (c) => ({ "&": "&amp;", "<": "&lt;", ">": "&gt;" })[c])}</span>`;
30
+ button.addEventListener("click", () => choose(option.value, true));
31
31
  return button;
32
32
  });
33
33
  function mark() {
34
34
  buttons.forEach((button) => {
35
35
  const on = button.dataset.value === current;
36
- button.setAttribute('aria-checked', String(on));
36
+ button.setAttribute("aria-checked", String(on));
37
37
  button.tabIndex = on ? 0 : -1;
38
38
  });
39
39
  if (!buttons.some((b) => b.tabIndex === 0) && buttons[0])
@@ -46,16 +46,16 @@ export function createChoice(config) {
46
46
  if (notify && changed)
47
47
  config.onChange(value);
48
48
  }
49
- list.addEventListener('keydown', (event) => {
49
+ list.addEventListener("keydown", (event) => {
50
50
  const at = buttons.findIndex((b) => b.dataset.value === current);
51
51
  let next = -1;
52
- if (event.key === 'ArrowRight' || event.key === 'ArrowDown')
52
+ if (event.key === "ArrowRight" || event.key === "ArrowDown")
53
53
  next = (at + 1) % buttons.length;
54
- else if (event.key === 'ArrowLeft' || event.key === 'ArrowUp')
54
+ else if (event.key === "ArrowLeft" || event.key === "ArrowUp")
55
55
  next = (at - 1 + buttons.length) % buttons.length;
56
- else if (event.key === 'Home')
56
+ else if (event.key === "Home")
57
57
  next = 0;
58
- else if (event.key === 'End')
58
+ else if (event.key === "End")
59
59
  next = buttons.length - 1;
60
60
  if (next < 0)
61
61
  return;
@@ -71,7 +71,11 @@ export function createChoice(config) {
71
71
  element,
72
72
  set: (value) => choose(value, false),
73
73
  get: () => current,
74
- get hidden() { return element.hidden; },
75
- set hidden(value) { element.hidden = value; }
74
+ get hidden() {
75
+ return element.hidden;
76
+ },
77
+ set hidden(value) {
78
+ element.hidden = value;
79
+ },
76
80
  };
77
81
  }
@@ -0,0 +1,8 @@
1
+ import type { CollectionHost } from "./collection-host.js";
2
+ /** With `address`, the display, the fan, the landing, the animation and its speed are kept in the page's address (`?view=fan&fan=open&land=face-down&animate=off`), and a link to it opens the same. */
3
+ /** The attributes kept in the address, in the order they are written. */
4
+ export declare const ADDRESS_KEYS: readonly ["view", "fan", "land", "animate", "speed", "binder", "cover", "sheet", "pockets"];
5
+ /** An address key whose attribute has another name. */
6
+ export declare const NAMES: Record<string, string>;
7
+ export declare function readAddress(host: CollectionHost): void;
8
+ export declare function writeAddress(host: CollectionHost): void;
@@ -0,0 +1,52 @@
1
+ // Keeping the display, the fan, the landing, the animation and the binder in the page's address.
2
+ import { binderCovers } from "./binder.js";
3
+ /** With `address`, the display, the fan, the landing, the animation and its speed are kept in the page's address (`?view=fan&fan=open&land=face-down&animate=off`), and a link to it opens the same. */
4
+ /** The attributes kept in the address, in the order they are written. */
5
+ export const ADDRESS_KEYS = ["view", "fan", "land", "animate", "speed", "binder", "cover", "sheet", "pockets"];
6
+ /** An address key whose attribute has another name. */
7
+ export const NAMES = { land: "deck-land" };
8
+ export function readAddress(host) {
9
+ try {
10
+ const params = new URLSearchParams(location.search);
11
+ for (const key of ADDRESS_KEYS) {
12
+ const value = params.get(key);
13
+ if (value === null)
14
+ continue;
15
+ const attr = NAMES[key] ?? key;
16
+ if (host.getAttribute(attr) !== value)
17
+ host.setAttribute(attr, value);
18
+ }
19
+ }
20
+ catch { }
21
+ }
22
+ export function writeAddress(host) {
23
+ if (!host.hasAttribute("address"))
24
+ return;
25
+ clearTimeout(host.addressTimer);
26
+ host.addressTimer = window.setTimeout(() => {
27
+ try {
28
+ const url = new URL(location.href);
29
+ const want = {
30
+ view: host.currentView === "deck" ? null : host.currentView,
31
+ fan: host.fanOpen ? "open" : null,
32
+ land: host.land === "face-up" ? null : host.land,
33
+ animate: host.getAttribute("animate") === "off" ? "off" : null,
34
+ speed: ["slow", "quick"].includes(host.getAttribute("speed") ?? "") ? host.getAttribute("speed") : null,
35
+ binder: host.getAttribute("binder") === "zip" ? "zip" : null,
36
+ cover: binderCovers.some((c) => c.id === host.getAttribute("cover")) && host.getAttribute("cover") !== "green"
37
+ ? host.getAttribute("cover")
38
+ : null,
39
+ sheet: host.getAttribute("sheet") === "black" ? "black" : null,
40
+ pockets: ["4", "12"].includes(host.getAttribute("pockets") ?? "") ? host.getAttribute("pockets") : null,
41
+ };
42
+ for (const [k, v] of Object.entries(want)) {
43
+ if (v === null)
44
+ url.searchParams.delete(k);
45
+ else
46
+ url.searchParams.set(k, v);
47
+ }
48
+ history.replaceState(history.state, "", url);
49
+ }
50
+ catch { }
51
+ }, 250);
52
+ }
@@ -0,0 +1,9 @@
1
+ import type { CollectionView } from "./collection.js";
2
+ import type { CollectionHost } from "./collection-host.js";
3
+ export declare function syncBinderChoices(host: CollectionHost, view: CollectionView): void;
4
+ export declare function binderPageCount(host: CollectionHost): string;
5
+ /** The binder: a ring or zip binder open on two facing sheets of pockets. A page turn swings the leaf about the spine, bending as it goes, and shows the pockets on its back. */
6
+ export declare function renderBinder(host: CollectionHost, v: HTMLElement, t: {
7
+ on: boolean;
8
+ ms: number;
9
+ }): void;
@@ -0,0 +1,123 @@
1
+ // Drawing the binder: two facing sheets of pockets, the page turn, and the page count.
2
+ import { binderCovers, buildLeaf, buildSide, sideCount, spreadOf, spreadSides } from "./binder.js";
3
+ export function syncBinderChoices(host, view) {
4
+ const show = view === "binder";
5
+ const cur = (attr, dflt, ok) => {
6
+ const v = host.getAttribute(attr);
7
+ return v && ok.includes(v) ? v : dflt;
8
+ };
9
+ const vals = {
10
+ binder: cur("binder", "ring", ["ring", "zip"]),
11
+ cover: cur("cover", "green", binderCovers.map((c) => c.id)),
12
+ sheet: cur("sheet", "clear", ["clear", "black"]),
13
+ pockets: cur("pockets", "9", ["4", "9", "12"]),
14
+ };
15
+ for (const [k, h] of Object.entries(host.binderChoices)) {
16
+ h.hidden = !show;
17
+ h.set(vals[k]);
18
+ }
19
+ }
20
+ export function binderPageCount(host) {
21
+ const per = host.binderLay().per;
22
+ const sides = sideCount(host.data.length, per);
23
+ const [l, r] = spreadSides(spreadOf(host.index, per), sides);
24
+ const a = (l < 0 ? r : l) + 1;
25
+ const b = (r < 0 ? l : r) + 1;
26
+ return a === b ? `Page ${a} / ${sides}` : `Pages ${a}–${b} / ${sides}`;
27
+ }
28
+ /** The binder: a ring or zip binder open on two facing sheets of pockets. A page turn swings the leaf about the spine, bending as it goes, and shows the pockets on its back. */
29
+ export function renderBinder(host, v, t) {
30
+ const layout = host.binderLay();
31
+ const n = host.data.length;
32
+ const sides = sideCount(n, layout.per);
33
+ const spread = spreadOf(host.index, layout.per);
34
+ const sheet = host.getAttribute("sheet") === "black" ? "black" : "clear";
35
+ const zip = host.getAttribute("binder") === "zip";
36
+ const cover = binderCovers.find((c) => c.id === host.getAttribute("cover")) ?? binderCovers[0];
37
+ v.classList.add("binder");
38
+ v.style.setProperty("--cover", cover.color);
39
+ const pocket = (index, live) => {
40
+ const c = host.data[index];
41
+ const el = document.createElement("div");
42
+ el.className = "pocket";
43
+ if (live)
44
+ el.append(host.image(c, index));
45
+ else {
46
+ const img = document.createElement("img");
47
+ img.src = c.image;
48
+ img.alt = "";
49
+ img.style.cssText = "width:86%;height:92%;object-fit:contain;border-radius:3%;box-shadow:0 2px 5px #0007";
50
+ el.append(img);
51
+ }
52
+ return el;
53
+ };
54
+ const [L, R] = spreadSides(spread, sides);
55
+ const turn = host.turn;
56
+ host.turn = null;
57
+ const flat = turn && t.on && Math.abs(turn.to - turn.from) === 1 ? turn : null;
58
+ const [oldL, oldR] = flat ? spreadSides(flat.from, sides) : [L, R];
59
+ const [newL, newR] = flat ? spreadSides(flat.to, sides) : [L, R];
60
+ const forward = !!flat && flat.to > flat.from;
61
+ const book = document.createElement("div");
62
+ book.className = `book ${zip ? "b-zip" : "b-ring"}`;
63
+ const inside = document.createElement("div");
64
+ inside.className = "inside";
65
+ const left = document.createElement("div");
66
+ const right = document.createElement("div");
67
+ left.className = "half";
68
+ right.className = "half";
69
+ const put = (half, side, where) => {
70
+ half.replaceChildren();
71
+ if (side >= 0)
72
+ half.append(buildSide(side, where, sheet, layout, n, pocket));
73
+ };
74
+ // While a leaf swings the half it has not reached yet shows the page it is leaving; the other half already shows the page it uncovers.
75
+ put(left, flat ? (forward ? oldL : newL) : L, "l");
76
+ put(right, flat ? (forward ? newR : oldR) : R, "r");
77
+ const spine = document.createElement("div");
78
+ spine.className = "spine";
79
+ for (const y of [18, 50, 82]) {
80
+ const ring = document.createElement("i");
81
+ ring.className = "ring";
82
+ ring.style.top = `${y}%`;
83
+ spine.append(ring);
84
+ }
85
+ inside.append(left, right, spine);
86
+ const tab = document.createElement("i");
87
+ tab.className = "tab";
88
+ book.append(inside, tab);
89
+ v.append(book);
90
+ if (flat) {
91
+ const w = 300;
92
+ const strip = 34;
93
+ const { leaf, slices } = buildLeaf(forward ? oldR : newR, forward ? newL : oldL, sheet, layout, n, pocket, w, strip);
94
+ inside.append(leaf);
95
+ const ms = Math.round(t.ms * 1.4);
96
+ const ease = "cubic-bezier(.45,.05,.3,1)";
97
+ const a = forward ? [0, -180] : [-180, 0];
98
+ leaf.style.transform = `rotateY(${a[1]}deg)`;
99
+ const swing = leaf.animate([{ transform: `rotateY(${a[0]}deg)` }, { transform: `rotateY(${a[1]}deg)` }], {
100
+ duration: ms,
101
+ easing: ease,
102
+ fill: "forwards",
103
+ });
104
+ // Each slice leans on the one before it, so the sheet bends as it swings (the free edge trails) and straightens at the end.
105
+ const bend = forward ? 8 : -8;
106
+ slices.forEach((s, k) => {
107
+ if (k)
108
+ s.animate([
109
+ { transform: "rotateY(0deg)" },
110
+ { transform: `rotateY(${bend}deg)`, offset: 0.5 },
111
+ { transform: "rotateY(0deg)" },
112
+ ], { duration: ms, easing: ease });
113
+ });
114
+ const finish = () => {
115
+ if (!leaf.isConnected)
116
+ return;
117
+ put(left, newL, "l");
118
+ put(right, newR, "r");
119
+ leaf.remove();
120
+ };
121
+ swing.finished.then(finish, finish);
122
+ }
123
+ }
@@ -0,0 +1,2 @@
1
+ import type { CollectionHost } from "./collection-host.js";
2
+ export declare function buildControls(host: CollectionHost): void;