@johnmorrisdotca/fuda-cards 0.10.1 → 0.12.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 (96) hide show
  1. package/LICENSE +21 -0
  2. package/NOTICE.md +16 -0
  3. package/README.md +106 -33
  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 +36 -67
  25. package/dist/collection-element.js +283 -484
  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 +154 -11
  37. package/dist/collection.js +140 -34
  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 +87 -4
  45. package/dist/live-3d.js +120 -52
  46. package/dist/materials.d.ts +117 -6
  47. package/dist/materials.js +246 -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 +138 -134
  62. package/docs/collection-displays.md +4 -4
  63. package/docs/collection-input.md +5 -5
  64. package/docs/framework-integration.md +1 -1
  65. package/docs/guides/architecture.md +8 -8
  66. package/docs/guides/bundlers.md +60 -0
  67. package/docs/guides/card-element.md +26 -2
  68. package/docs/guides/collections.md +2 -2
  69. package/docs/guides/embed-in-an-iframe.md +39 -0
  70. package/docs/guides/frameworks.md +93 -66
  71. package/docs/guides/getting-started.md +4 -2
  72. package/docs/guides/html-and-cdn.md +86 -0
  73. package/docs/guides/ja/architecture.md +4 -4
  74. package/docs/guides/ja/bundlers.md +60 -0
  75. package/docs/guides/ja/card-element.md +26 -2
  76. package/docs/guides/ja/collections.md +2 -2
  77. package/docs/guides/ja/embed-in-an-iframe.md +39 -0
  78. package/docs/guides/ja/frameworks.md +93 -66
  79. package/docs/guides/ja/getting-started.md +4 -2
  80. package/docs/guides/ja/html-and-cdn.md +86 -0
  81. package/docs/guides/ja/live-3d.md +37 -24
  82. package/docs/guides/ja/materials-and-stacks.md +4 -4
  83. package/docs/guides/ja/troubleshooting.md +2 -2
  84. package/docs/guides/ja/typescript-and-node.md +45 -0
  85. package/docs/guides/ja/upgrading.md +7 -2
  86. package/docs/guides/ja/wear.md +1 -1
  87. package/docs/guides/live-3d.md +37 -24
  88. package/docs/guides/materials-and-stacks.md +4 -4
  89. package/docs/guides/troubleshooting.md +2 -2
  90. package/docs/guides/typescript-and-node.md +45 -0
  91. package/docs/guides/upgrading.md +7 -2
  92. package/docs/guides/wear.md +1 -1
  93. package/docs/live-3d.md +1 -18
  94. package/docs/materials.md +15 -11
  95. package/docs/wear.md +4 -12
  96. package/package.json +57 -10
@@ -0,0 +1,131 @@
1
+ /**
2
+ * A card's finish: foil catches the light and shows a rainbow in its frame, matte does not.
3
+ *
4
+ * @example
5
+ * ```ts
6
+ * import { cardFinishes, type CardFinish } from "@johnmorrisdotca/fuda-cards";
7
+ *
8
+ * const finish: CardFinish = "matte";
9
+ * console.log(cardFinishes.includes(finish)); // true
10
+ * ```
11
+ */
12
+ export type CardFinish = "foil" | "matte";
13
+ /**
14
+ * A card's look: classic gold, silver sport or cosmic violet.
15
+ *
16
+ * @example
17
+ * ```ts
18
+ * import { cardVariants, type CardVariant } from "@johnmorrisdotca/fuda-cards";
19
+ *
20
+ * const look: CardVariant = "cosmic";
21
+ * console.log(cardVariants.indexOf(look)); // 2
22
+ * ```
23
+ */
24
+ export type CardVariant = "classic" | "sport" | "cosmic";
25
+ /**
26
+ * Every setting of `<fuda-card>` as an object. `cardAttributes(options)` turns it into the element's attributes, so the same object
27
+ * works in a framework, a script and a test.
28
+ *
29
+ * @example
30
+ * ```ts
31
+ * import { type CardOptions, cardAttributes } from "@johnmorrisdotca/fuda-cards";
32
+ *
33
+ * const options: CardOptions = { title: "Explorer One", variant: "sport", stack: 10, wear: "near-mint" };
34
+ * console.log(cardAttributes(options).variant); // sport
35
+ * ```
36
+ */
37
+ export interface CardOptions {
38
+ title?: string;
39
+ category?: string;
40
+ subtitle?: string;
41
+ description?: string;
42
+ number?: string;
43
+ rarity?: string;
44
+ variant?: CardVariant;
45
+ finish?: CardFinish;
46
+ /** Card thickness in millimetres at the 63 mm wide card size; overrides the material's. Default 0.325, 0 for a flat card. */
47
+ thickness?: number;
48
+ /** A material's id (see `cardMaterials`): its sourced thickness and edge colour. */
49
+ material?: string;
50
+ /** How many cards the stack holds (1 to 1000); the stack is that many times the card's thickness high. Default 1, one card. */
51
+ stack?: number;
52
+ /** From 0 (squared up) to 1 (very messy) for the cards under the top one. Default 0.3. */
53
+ stackMessiness?: number;
54
+ /** The stack's seed: the same seed lays the same stack the same way. Default 1. */
55
+ stackSeed?: number;
56
+ /** How many cards under the top one are laid out nudged and turned, at most 52. Default 10. */
57
+ stackDepth?: number;
58
+ /** A card that is not perfect: a preset's id (`mint`, `near-mint`, `lightly-played`, `moderately-played`, `heavily-played`, `damaged`) or a number from 0 to 1. Default: perfect, nothing drawn. */
59
+ wear?: string | number;
60
+ /** The wear's seed: the same seed draws the same marks the same way. Default 1. */
61
+ wearSeed?: number;
62
+ /** One level of the wear on its own, from 0 to 1, over the preset's. */
63
+ wearCorners?: number;
64
+ wearEdges?: number;
65
+ wearSurface?: number;
66
+ wearCreases?: number;
67
+ /** The card shows its back. */
68
+ flipped?: boolean;
69
+ motion?: "still" | "pan";
70
+ /** The picture is moving now (needs `motion: "pan"`). */
71
+ playing?: boolean;
72
+ /** `focus`: the card in focus animates its art (needs `motion: 'pan'`); never with reduced motion. */
73
+ autoplay?: "focus";
74
+ panDirection?: "down" | "up";
75
+ panLoop?: "alternate" | "restart";
76
+ cardSpin?: "center" | "corner";
77
+ cardSpinDirection?: "normal" | "reverse";
78
+ cardSpinPaused?: boolean;
79
+ /** The page turns the card with `--fuda-yaw` and `--fuda-tilt` instead of the built-in spin. */
80
+ cardView?: boolean;
81
+ /** `open`: a stack of more than one card fans open. */
82
+ fan?: "open";
83
+ /** How many cards are on the pile beside the stack. */
84
+ takenOff?: number;
85
+ /** How a card taken off lands: `face-up` or turned over (`face-down`). */
86
+ deckLand?: "face-up" | "face-down";
87
+ /** `off` ends every move at once. */
88
+ animate?: "on" | "off";
89
+ /** How long a move takes: `slow`, `normal` or `quick`. */
90
+ speed?: "slow" | "normal" | "quick";
91
+ /** The three buttons under a stack: Fan, Take a card off and Put it back. */
92
+ pileControls?: boolean;
93
+ }
94
+ /**
95
+ * The three looks, in the order the studio offers them.
96
+ *
97
+ * @example
98
+ * ```ts
99
+ * import { cardVariants } from "@johnmorrisdotca/fuda-cards";
100
+ *
101
+ * console.log(cardVariants.join(" ")); // classic sport cosmic
102
+ * ```
103
+ */
104
+ export declare const cardVariants: readonly CardVariant[];
105
+ /**
106
+ * The two finishes, foil and matte.
107
+ *
108
+ * @example
109
+ * ```ts
110
+ * import { cardFinishes } from "@johnmorrisdotca/fuda-cards";
111
+ *
112
+ * console.log(cardFinishes.join(" ")); // foil matte
113
+ * ```
114
+ */
115
+ export declare const cardFinishes: readonly CardFinish[];
116
+ /**
117
+ * The attributes of a `<fuda-card>` for these options, ready to set one by one (`element.setAttribute(name, value)`): names are the
118
+ * kebab-case of the option's, a `true` boolean is the empty string (the attribute is present) and a `false` one, like anything that
119
+ * is `undefined` or `null`, is left out. Numbers are written as plain text.
120
+ *
121
+ * @param options - The settings of the card, by their camel-case names.
122
+ * @returns The attributes by name; set each with `element.setAttribute(name, value)`. Nothing is shared with `options`.
123
+ * @example
124
+ * ```ts
125
+ * import { cardAttributes } from "@johnmorrisdotca/fuda-cards";
126
+ *
127
+ * console.log(cardAttributes({ title: "Explorer One", stackMessiness: 0.5, flipped: true, wear: undefined }));
128
+ * // { title: 'Explorer One', 'stack-messiness': '0.5', flipped: '' }
129
+ * ```
130
+ */
131
+ export declare function cardAttributes(options: CardOptions): Record<string, string>;
@@ -0,0 +1,48 @@
1
+ /**
2
+ * The three looks, in the order the studio offers them.
3
+ *
4
+ * @example
5
+ * ```ts
6
+ * import { cardVariants } from "@johnmorrisdotca/fuda-cards";
7
+ *
8
+ * console.log(cardVariants.join(" ")); // classic sport cosmic
9
+ * ```
10
+ */
11
+ export const cardVariants = ["classic", "sport", "cosmic"];
12
+ /**
13
+ * The two finishes, foil and matte.
14
+ *
15
+ * @example
16
+ * ```ts
17
+ * import { cardFinishes } from "@johnmorrisdotca/fuda-cards";
18
+ *
19
+ * console.log(cardFinishes.join(" ")); // foil matte
20
+ * ```
21
+ */
22
+ export const cardFinishes = ["foil", "matte"];
23
+ /** A setting's name as the element's attribute: `stackMessiness` is `stack-messiness`. */
24
+ const attributeName = (name) => name.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`);
25
+ /**
26
+ * The attributes of a `<fuda-card>` for these options, ready to set one by one (`element.setAttribute(name, value)`): names are the
27
+ * kebab-case of the option's, a `true` boolean is the empty string (the attribute is present) and a `false` one, like anything that
28
+ * is `undefined` or `null`, is left out. Numbers are written as plain text.
29
+ *
30
+ * @param options - The settings of the card, by their camel-case names.
31
+ * @returns The attributes by name; set each with `element.setAttribute(name, value)`. Nothing is shared with `options`.
32
+ * @example
33
+ * ```ts
34
+ * import { cardAttributes } from "@johnmorrisdotca/fuda-cards";
35
+ *
36
+ * console.log(cardAttributes({ title: "Explorer One", stackMessiness: 0.5, flipped: true, wear: undefined }));
37
+ * // { title: 'Explorer One', 'stack-messiness': '0.5', flipped: '' }
38
+ * ```
39
+ */
40
+ export function cardAttributes(options) {
41
+ const attributes = {};
42
+ for (const [name, value] of Object.entries(options)) {
43
+ if (value === undefined || value === null || value === false)
44
+ continue;
45
+ attributes[attributeName(name)] = value === true ? "" : String(value);
46
+ }
47
+ return attributes;
48
+ }
@@ -0,0 +1,2 @@
1
+ /** The stylesheet of the card's shadow root. */
2
+ export declare const CARD_CSS: string;
@@ -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;