@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
package/dist/element.js CHANGED
@@ -1,37 +1,123 @@
1
- import { cardMaterial, stackHeightMm } from './materials.js';
2
- import { stackLayout } from './stack.js';
3
- const template = document.createElement('template');
4
- template.innerHTML = `<style>
5
- :host{display:inline-block;width:300px;aspect-ratio:2.5/3.5;perspective:var(--fuda-perspective,1000px);container-type:inline-size;filter:drop-shadow(0 12px 14px #0006);--edge:linear-gradient(90deg,#f6dc8c,#b98631 50%,#f6dc8c);font-family:Georgia,serif;color:#27201b}*{box-sizing:border-box}.rotation{height:100%;transform-style:preserve-3d;transform-origin:center center}:host([card-spin="center"]) .rotation{animation:fuda-turn var(--fuda-card-spin-duration, 180s) linear infinite}:host([card-spin="corner"]) .rotation{transform-origin:0 100%;transform:translate(50%,-50%);animation:fuda-corner-turn var(--fuda-card-spin-duration, 180s) linear infinite}:host([card-spin-direction="reverse"]) .rotation{animation-direction:reverse}:host([card-spin-paused]) .rotation{animation-play-state:paused}@keyframes fuda-turn{to{transform:rotateY(360deg)}}@keyframes fuda-corner-turn{from{transform:translate(50%,-50%) rotateY(0)}to{transform:translate(50%,-50%) rotateY(360deg)}}:host([card-view]) .rotation{animation:none;transform:rotateX(var(--fuda-tilt,0deg)) rotateY(var(--fuda-yaw,0deg))}:host([card-view][card-spin="corner"]) .rotation{transform:translate(50%,-50%) rotateX(var(--fuda-tilt,0deg)) rotateY(var(--fuda-yaw,0deg))}@media (prefers-reduced-motion:reduce){:host([card-spin]) .rotation{animation:none}:host .card{transition:none}.art ::slotted(*){transition:none}}.card{--t:calc(var(--mm,.3) * 100cqw / 63);--pitch:calc(var(--mm1,var(--mm,.3)) * 100cqw / 63);height:100%;position:relative;transform-style:preserve-3d;transition:transform .65s}:host([flipped]) .card{transform:rotateY(180deg)}.face{position:absolute;inset:0;border-radius:15px;backface-visibility:hidden;overflow:hidden}.front{transform:translateZ(calc(var(--t) / 2));padding:13px;background:linear-gradient(135deg,#fbdf87,#ab742c 35%,#ffe9a6 58%,#ae792d);border:2px solid #9c702d}.inner{height:100%;padding:12px;background:linear-gradient(150deg,#f9edc8,#d6b477);border:2px solid #76512a;display:flex;flex-direction:column;gap:8px}.heading,.footer{display:flex;justify-content:space-between;align-items:center;gap:5px}.heading{font-weight:bold;font-size:20px}.badge{font:700 10px sans-serif;letter-spacing:.12em}.art{position:relative;height:53%;border:5px ridge #dcc18a;box-shadow:0 2px 5px #47301488;background:radial-gradient(circle at 50% 35%,#7496a1,#273c4c);overflow:hidden}.art ::slotted(*){width:100%;height:100%;object-fit:contain;display:block;opacity:0;transition:opacity .35s ease}.art.ready ::slotted(*){opacity:1}:host([motion="pan"]) .art ::slotted(img){object-fit:cover;object-position:var(--fuda-focus-x, 50%) var(--fuda-focus-y, 25%)}:host([motion="pan"][moving]) .art ::slotted(img){animation:fuda-pan var(--fuda-pan-duration, 12s) ease-in-out infinite alternate}:host([motion="pan"][pan-loop="restart"]) .art ::slotted(img){animation-direction:normal}:host([motion="pan"][pan-direction="up"]) .art ::slotted(img){animation-direction:alternate-reverse}:host([motion="pan"][pan-direction="up"][pan-loop="restart"]) .art ::slotted(img){animation-direction:reverse}@keyframes fuda-pan{from{object-position:50% 0%}to{object-position:50% 100%}}@media (prefers-reduced-motion:reduce){:host([motion="pan"][moving]) .art ::slotted(img){animation:none}.motion-button{transition:none}}.motion-button{position:absolute;right:0;bottom:0;z-index:1;width:48px;height:48px;padding:0;border:0;background:none;display:grid;place-items:center;cursor:pointer;opacity:.55;transition:opacity .2s;-webkit-tap-highlight-color:transparent}.motion-button:hover,.motion-button:focus-visible,.motion-button[aria-pressed=true]{opacity:1}.motion-button:focus-visible{outline:none}.motion-button:focus-visible .glyph{outline:3px solid white;outline-offset:2px}.glyph{width:26px;height:26px;border-radius:50%;display:grid;place-items:center;background:#101827b3;border:1px solid #fff5;color:white}.glyph svg{width:11px;height:11px;fill:currentColor}.motion-button[aria-pressed=true] .play,.motion-button[aria-pressed=false] .pause{display:none}.motion-button[hidden]{display:none}.subtitle{text-align:center;font:italic 11px Georgia}.description{border-top:1px solid #9d8054;padding-top:9px;font-size:13px;line-height:1.35;flex:1}.footer{border-top:1px solid #9d8054;padding-top:5px;font:700 9px sans-serif;letter-spacing:.08em}.back{transform:rotateY(180deg) translateZ(calc(var(--t) / 2));background:radial-gradient(ellipse at center,#b78745 0 12%,#152d46 13% 27%,#386988 28% 31%,#10233b 32% 62%,#d2b074 63% 66%,#182c45 67%);border:11px solid #b39158;display:grid;place-items:center;color:#f7e9bf}.emblem{width:125px;height:125px;border:2px solid #edd18c;border-radius:50%;display:grid;place-items:center;background:#17334a;box-shadow:0 0 0 7px #967344,0 0 30px #e6c98288;font:bold 23px Georgia;letter-spacing:.12em}.shine{pointer-events:none;position:absolute;inset:0;opacity:.35;mix-blend-mode:screen;background:linear-gradient(125deg,transparent 25%,#fff9 36%,transparent 48%,#7cf6 56%,#f9a5 62%,transparent 70%)}:host([finish=matte]) .shine{display:none}.edge{position:absolute;background:var(--fuda-edge,var(--edge))}.stacked .edge{--dir:180deg;background:repeating-linear-gradient(var(--dir),transparent 0 calc(var(--pitch) * .7),#8886 calc(var(--pitch) * .7) var(--pitch)),var(--fuda-edge,var(--edge))}.stacked .edge.side{--dir:90deg}.stills{display:contents}.still{position:absolute;inset:0;border-radius:15px;border:2px solid #9c702d;pointer-events:none;background:linear-gradient(135deg,#fbdf87,#ab742c 35%,#ffe9a6 58%,#ae792d);transform:translate3d(calc(var(--x) * 100cqw),calc(var(--y) * 100cqw),calc(var(--t) / -2 + var(--pitch) * var(--k))) rotate(calc(var(--r) * 1deg))}:host([variant=sport]) .still{background:linear-gradient(135deg,#ebedef,#525e69,#fff,#47505d);border-color:#394c5b}:host([variant=cosmic]) .still{background:linear-gradient(130deg,#c9b4ff,#433b83,#dabdff,#503969);border-color:#584378}:host([variant=sport]),:host([variant=cosmic]){--edge:#ece4d2}:host([variant=sport]) .front{background:linear-gradient(135deg,#ebedef,#525e69,#fff,#47505d)}:host([variant=sport]) .inner{background:linear-gradient(145deg,#eef1ee,#aebac1);border-color:#394c5b}:host([variant=sport]) .art{border-color:#a9b9c0}:host([variant=cosmic]) .front{background:linear-gradient(130deg,#c9b4ff,#433b83,#dabdff,#503969)}:host([variant=cosmic]) .inner{background:linear-gradient(145deg,#e6dafa,#a997cd);border-color:#584378}
6
- </style><div class="rotation"><div class="card"><div class="face front"><div class="inner"><div class="heading"><span id="title"></span><span class="badge" id="category"></span></div><div class="art"><slot></slot><button class="motion-button" type="button" aria-pressed="false" aria-label="Animate the picture" title="Animate" hidden><span class="glyph"><svg viewBox="0 0 12 12" aria-hidden="true"><path class="play" d="M3 1.5v9l7.5-4.5z"/><path class="pause" d="M2.5 1.5h2.8v9H2.5zM6.7 1.5h2.8v9H6.7z"/></svg></span></button></div><div class="subtitle" id="subtitle"></div><div class="description" id="description"></div><div class="footer"><span id="number"></span><span>✦ FUDA COLLECTION</span><span id="rarity"></span></div></div><div class="shine"></div></div><div class="face back"><div class="emblem">FUDA</div><div class="shine"></div></div><i class="edge" style="left:50%;top:0;width:calc(100% - 30px);height:var(--t);transform:translate(-50%,-50%) rotate(0deg) rotateX(90deg)"></i><i class="edge" style="left:50%;top:100%;width:calc(100% - 30px);height:var(--t);transform:translate(-50%,-50%) rotate(0deg) rotateX(90deg)"></i><i class="edge side" style="left:0;top:50%;width:var(--t);height:calc(100% - 30px);transform:translate(-50%,-50%) rotateY(90deg)"></i><i class="edge side" style="left:100%;top:50%;width:var(--t);height:calc(100% - 30px);transform:translate(-50%,-50%) rotateY(90deg)"></i><i class="edge" style="left:2.20px;top:9.70px;width:11.48px;height:var(--t);transform:translate(-50%,-50%) rotate(-67.5deg) rotateX(90deg)"></i><i class="edge" style="left:9.70px;top:2.20px;width:11.48px;height:var(--t);transform:translate(-50%,-50%) rotate(-22.5deg) rotateX(90deg)"></i><i class="edge" style="left:2.20px;top:calc(100% - 9.70px);width:11.48px;height:var(--t);transform:translate(-50%,-50%) rotate(67.5deg) rotateX(90deg)"></i><i class="edge" style="left:9.70px;top:calc(100% - 2.20px);width:11.48px;height:var(--t);transform:translate(-50%,-50%) rotate(22.5deg) rotateX(90deg)"></i><i class="edge" style="left:calc(100% - 2.20px);top:9.70px;width:11.48px;height:var(--t);transform:translate(-50%,-50%) rotate(67.5deg) rotateX(90deg)"></i><i class="edge" style="left:calc(100% - 9.70px);top:2.20px;width:11.48px;height:var(--t);transform:translate(-50%,-50%) rotate(22.5deg) rotateX(90deg)"></i><i class="edge" style="left:calc(100% - 2.20px);top:calc(100% - 9.70px);width:11.48px;height:var(--t);transform:translate(-50%,-50%) rotate(-67.5deg) rotateX(90deg)"></i><i class="edge" style="left:calc(100% - 9.70px);top:calc(100% - 2.20px);width:11.48px;height:var(--t);transform:translate(-50%,-50%) rotate(-22.5deg) rotateX(90deg)"></i><div class="stills"></div></div></div>`;
7
- const defaults = { title: 'Untitled', category: 'COLLECTIBLE', subtitle: 'An item worth collecting', description: 'Add a description to tell its story.', number: 'NO. 001', rarity: '✦' };
1
+ import { cardMarkup } from "./card-markup.js";
2
+ import { cardMaterial, DEFAULT_CARD_THICKNESS_MM, stackHeightMm } from "./materials.js";
3
+ import { reducedMotion } from "./motion.js";
4
+ import { stackLayout, stillsHtml } from "./stack.js";
5
+ const template = document.createElement("template");
6
+ template.innerHTML = cardMarkup();
7
+ const defaults = {
8
+ title: "Untitled",
9
+ category: "COLLECTIBLE",
10
+ subtitle: "An item worth collecting",
11
+ description: "Add a description to tell its story.",
12
+ number: "NO. 001",
13
+ rarity: "✦",
14
+ };
8
15
  /** The one card in focus: the card under the pointer, holding keyboard focus or last tapped. Only it may autoplay. */
9
16
  let focusedCard = null;
10
- const reducedMotion = () => typeof matchMedia === 'function' && matchMedia('(prefers-reduced-motion: reduce)').matches;
11
- document.addEventListener('pointerdown', event => { if (focusedCard && !event.composedPath().includes(focusedCard))
12
- focusedCard.setFocused(false); }, true);
17
+ document.addEventListener("pointerdown", (event) => {
18
+ if (focusedCard && !event.composedPath().includes(focusedCard))
19
+ focusedCard.setFocused(false);
20
+ }, true);
21
+ /**
22
+ * `<fuda-card>`: a collectible card frame around a picture you give it (or a live 3D view), drawn with a true thickness, an edge, a back, foil or matte,
23
+ * a stack, wear and the three looks. Import this module once to register the element; the attributes are listed in the card guide and in
24
+ * [`CardOptions`](api:CardOptions), and `cardAttributes(options)` writes them from an object.
25
+ *
26
+ * @example
27
+ * ```ts no-run
28
+ * import "@johnmorrisdotca/fuda-cards/element";
29
+ * import { cardAttributes } from "@johnmorrisdotca/fuda-cards";
30
+ *
31
+ * const card = document.createElement("fuda-card");
32
+ * for (const [name, value] of Object.entries(cardAttributes({ title: "Explorer One", stack: 10, wear: "near-mint" }))) card.setAttribute(name, value);
33
+ * document.body.append(card);
34
+ * ```
35
+ */
13
36
  export class FudaCard extends HTMLElement {
14
- static observedAttributes = ['title', 'category', 'subtitle', 'description', 'number', 'rarity', 'motion', 'playing', 'thickness', 'autoplay', 'material', 'stack', 'stack-messiness', 'stack-seed', 'stack-depth', 'wear', 'wear-seed', 'wear-corners', 'wear-edges', 'wear-surface', 'wear-creases', 'fan', 'taken-off', 'deck-land', 'animate', 'speed', 'pile-controls'];
37
+ static observedAttributes = [
38
+ "title",
39
+ "category",
40
+ "subtitle",
41
+ "description",
42
+ "number",
43
+ "rarity",
44
+ "motion",
45
+ "playing",
46
+ "thickness",
47
+ "autoplay",
48
+ "material",
49
+ "stack",
50
+ "stack-messiness",
51
+ "stack-seed",
52
+ "stack-depth",
53
+ "wear",
54
+ "wear-seed",
55
+ "wear-corners",
56
+ "wear-edges",
57
+ "wear-surface",
58
+ "wear-creases",
59
+ "fan",
60
+ "taken-off",
61
+ "deck-land",
62
+ "animate",
63
+ "speed",
64
+ "pile-controls",
65
+ ];
15
66
  focused = false;
16
67
  hushed = false;
17
68
  focusedAtPress;
18
- constructor() { super(); const root = this.attachShadow({ mode: 'open' }); root.append(template.content.cloneNode(true)); const button = root.querySelector('button'); button?.addEventListener('click', () => this.toggleMotion()); this.watchArt(root); this.watchFocus(button); }
69
+ constructor() {
70
+ super();
71
+ const root = this.attachShadow({ mode: "open" });
72
+ root.append(template.content.cloneNode(true));
73
+ const button = root.querySelector("button");
74
+ button?.addEventListener("click", () => this.toggleMotion());
75
+ this.watchArt(root);
76
+ this.watchFacing();
77
+ this.watchFocus(button);
78
+ this.watchLight();
79
+ }
80
+ /** The light follows the pointer over the card: a foil card shows its sheen where the pointer is (see `--fuda-sheen-x` and `--fuda-sheen-y`). */
81
+ watchLight() {
82
+ this.addEventListener("pointermove", (e) => {
83
+ const box = this.getBoundingClientRect();
84
+ if (!box.width || !box.height)
85
+ return;
86
+ this.style.setProperty("--fuda-sheen-x", String(Math.round(((e.clientX - box.left) / box.width) * 100)));
87
+ this.style.setProperty("--fuda-sheen-y", String(Math.round(((e.clientY - box.top) / box.height) * 100)));
88
+ });
89
+ this.addEventListener("pointerleave", () => {
90
+ this.style.removeProperty("--fuda-sheen-x");
91
+ this.style.removeProperty("--fuda-sheen-y");
92
+ });
93
+ }
19
94
  /** With `autoplay="focus"` the card in focus animates its art; leaving it (pointer, keyboard or a tap elsewhere) stops it. */
20
95
  watchFocus(button) {
21
- const auto = () => this.getAttribute('autoplay') === 'focus';
22
- this.addEventListener('pointerenter', e => { if (auto() && e.pointerType !== 'touch')
23
- this.setFocused(true); });
24
- this.addEventListener('pointerleave', e => { if (e.pointerType !== 'touch' && !this.matches(':focus-within'))
25
- this.setFocused(false); });
26
- this.addEventListener('pointerdown', e => { if (!auto())
27
- return; if (e.composedPath().includes(button))
28
- this.focusedAtPress = this.focused;
29
- else
30
- this.setFocused(true); });
31
- this.addEventListener('focusin', () => { if (auto())
32
- this.setFocused(true); });
33
- this.addEventListener('focusout', e => { if (!this.contains(e.relatedTarget) && !this.matches(':hover'))
34
- this.setFocused(false); });
96
+ const auto = () => this.getAttribute("autoplay") === "focus";
97
+ this.addEventListener("pointerenter", (e) => {
98
+ if (auto() && e.pointerType !== "touch")
99
+ this.setFocused(true);
100
+ });
101
+ this.addEventListener("pointerleave", (e) => {
102
+ if (e.pointerType !== "touch" && !this.matches(":focus-within"))
103
+ this.setFocused(false);
104
+ });
105
+ this.addEventListener("pointerdown", (e) => {
106
+ if (!auto())
107
+ return;
108
+ if (e.composedPath().includes(button))
109
+ this.focusedAtPress = this.focused;
110
+ else
111
+ this.setFocused(true);
112
+ });
113
+ this.addEventListener("focusin", () => {
114
+ if (auto())
115
+ this.setFocused(true);
116
+ });
117
+ this.addEventListener("focusout", (e) => {
118
+ if (!this.contains(e.relatedTarget) && !this.matches(":hover"))
119
+ this.setFocused(false);
120
+ });
35
121
  }
36
122
  /** Put this card in focus (or out of it); the card that had focus is put out, so only one is ever in focus. */
37
123
  setFocused(on) {
@@ -49,9 +135,13 @@ export class FudaCard extends HTMLElement {
49
135
  this.render();
50
136
  }
51
137
  /** True while the art moves: `playing` is set, or the card is in focus with `autoplay="focus"` and the person has not paused it. Never autoplays with reduced motion. */
52
- get isMoving() { return this.getAttribute('motion') === 'pan' && (this.hasAttribute('playing') || (this.getAttribute('autoplay') === 'focus' && this.focused && !this.hushed && !reducedMotion())); }
138
+ get isMoving() {
139
+ return (this.getAttribute("motion") === "pan" &&
140
+ (this.hasAttribute("playing") ||
141
+ (this.getAttribute("autoplay") === "focus" && this.focused && !this.hushed && !reducedMotion())));
142
+ }
53
143
  toggleMotion() {
54
- const auto = this.getAttribute('autoplay') === 'focus';
144
+ const auto = this.getAttribute("autoplay") === "focus";
55
145
  const was = this.focusedAtPress ?? this.focused;
56
146
  this.focusedAtPress = undefined;
57
147
  if (auto && !was) {
@@ -62,129 +152,230 @@ export class FudaCard extends HTMLElement {
62
152
  }
63
153
  const held = auto;
64
154
  if (this.isMoving) {
65
- this.removeAttribute('playing');
155
+ this.removeAttribute("playing");
66
156
  if (held)
67
157
  this.hushed = true;
68
158
  }
69
159
  else {
70
160
  this.hushed = false;
71
161
  if (!held || reducedMotion())
72
- this.setAttribute('playing', '');
162
+ this.setAttribute("playing", "");
73
163
  }
74
164
  this.render();
75
165
  }
76
166
  /** The art stays invisible until the card has a size on screen and every slotted image has loaded, so it never shows outside the frame. */
77
167
  watchArt(root) {
78
- const art = root.querySelector('.art'), slot = root.querySelector('slot');
79
- const update = () => { const laid = this.offsetWidth > 0 && this.offsetHeight > 0; const waiting = slot.assignedElements({ flatten: true }).some(el => el instanceof HTMLImageElement && !el.complete); art.classList.toggle('ready', laid && !waiting); };
80
- slot.addEventListener('slotchange', update);
81
- slot.addEventListener('load', update, true);
82
- slot.addEventListener('error', update, true);
83
- if (typeof ResizeObserver !== 'undefined')
168
+ const art = root.querySelector(".art");
169
+ const slot = root.querySelector("slot");
170
+ const update = () => {
171
+ const laid = this.offsetWidth > 0 && this.offsetHeight > 0;
172
+ const waiting = slot
173
+ .assignedElements({ flatten: true })
174
+ .some((el) => el instanceof HTMLImageElement && !el.complete);
175
+ art.classList.toggle("ready", laid && !waiting);
176
+ };
177
+ slot.addEventListener("slotchange", update);
178
+ slot.addEventListener("load", update, true);
179
+ slot.addEventListener("error", update, true);
180
+ if (typeof ResizeObserver !== "undefined")
84
181
  new ResizeObserver(update).observe(this);
85
182
  else
86
183
  requestAnimationFrame(update);
87
184
  }
88
- connectedCallback() { this.render(); }
89
- disconnectedCallback() { this.setFocused(false); }
90
- attributeChangedCallback(name) { if (name === 'autoplay' && this.getAttribute('autoplay') !== 'focus')
91
- this.setFocused(false); if (name === 'motion' && this.getAttribute('motion') !== 'pan' && this.hasAttribute('playing'))
92
- this.removeAttribute('playing'); if (this.shadowRoot)
93
- this.render(); }
94
- /** Millimetres thick: the `thickness` attribute, else the `material`'s, else 0.3. */
95
- get cardThicknessMm() { const asked = Number.parseFloat(this.getAttribute('thickness') ?? ''); return asked >= 0 ? asked : cardMaterial(this.getAttribute('material'))?.thicknessMm ?? 0.3; }
185
+ /** The front is hidden while `--fuda-yaw` has turned the back toward the reader. */
186
+ watchFacing() {
187
+ const sync = () => {
188
+ const raw = this.style.getPropertyValue("--fuda-yaw");
189
+ const yaw = Number.parseFloat(raw);
190
+ const turned = ((yaw % 360) + 360) % 360;
191
+ const back = raw !== "" && Number.isFinite(yaw) && turned > 90 && turned < 270;
192
+ this.toggleAttribute("data-back", back);
193
+ const front = this.shadowRoot?.querySelector(".front");
194
+ if (front instanceof HTMLElement)
195
+ front.style.display = back ? "none" : "";
196
+ // The host's drop-shadow keeps a flattened copy of the front, so it is off while the back faces the reader.
197
+ if (back) {
198
+ if (this.style.getPropertyValue("filter") !== "none")
199
+ this.style.setProperty("filter", "none");
200
+ }
201
+ else if (this.style.getPropertyValue("filter") === "none")
202
+ this.style.removeProperty("filter");
203
+ };
204
+ new MutationObserver(sync).observe(this, { attributes: true, attributeFilter: ["style"] });
205
+ sync();
206
+ }
207
+ connectedCallback() {
208
+ this.render();
209
+ }
210
+ disconnectedCallback() {
211
+ this.setFocused(false);
212
+ }
213
+ attributeChangedCallback(name) {
214
+ if (name === "autoplay" && this.getAttribute("autoplay") !== "focus")
215
+ this.setFocused(false);
216
+ if (name === "motion" && this.getAttribute("motion") !== "pan" && this.hasAttribute("playing"))
217
+ this.removeAttribute("playing");
218
+ if (this.shadowRoot)
219
+ this.render();
220
+ }
221
+ /** Millimetres thick: the `thickness` attribute, else the `material`'s, else the playing-card stock's 0.325 (`DEFAULT_CARD_THICKNESS_MM`). */
222
+ get cardThicknessMm() {
223
+ const asked = Number.parseFloat(this.getAttribute("thickness") ?? "");
224
+ return asked >= 0 ? asked : (cardMaterial(this.getAttribute("material"))?.thicknessMm ?? DEFAULT_CARD_THICKNESS_MM);
225
+ }
96
226
  /** How many cards the stack holds: the `stack` attribute as a whole number from 1 (one card) to 1000. */
97
- get stackCount() { const n = Math.floor(Number.parseFloat(this.getAttribute('stack') ?? '')); return n >= 1 ? Math.min(1000, n) : 1; }
227
+ get stackCount() {
228
+ const n = Math.floor(Number.parseFloat(this.getAttribute("stack") ?? ""));
229
+ return n >= 1 ? Math.min(1000, n) : 1;
230
+ }
98
231
  /** Height of the stack in millimetres: the count times a card's thickness. */
99
- get stackHeight() { return stackHeightMm(this.stackCount, this.cardThicknessMm); }
232
+ get stackHeight() {
233
+ return stackHeightMm(this.stackCount, this.cardThicknessMm);
234
+ }
100
235
  /** How many cards are still in the stack: `stack` less the `taken-off` ones (at least one stays). */
101
- get heldCount() { const n = this.stackCount, t = Math.floor(Number.parseFloat(this.getAttribute('taken-off') ?? '')); return t > 0 ? Math.max(1, n - t) : n; }
236
+ get heldCount() {
237
+ const n = this.stackCount;
238
+ const t = Math.floor(Number.parseFloat(this.getAttribute("taken-off") ?? ""));
239
+ return t > 0 ? Math.max(1, n - t) : n;
240
+ }
102
241
  /** True while the stack is fanned open (`fan="open"`, with more than one card). */
103
- get fanOpen() { return this.getAttribute('fan') === 'open' && this.heldCount > 1; }
242
+ get fanOpen() {
243
+ return this.getAttribute("fan") === "open" && this.heldCount > 1;
244
+ }
104
245
  /** How far the pile reaches beyond the card's own box, in card widths: an open fan and the pile of cards taken off. It is zero until a pile feature is used. Pages use it to fit the view; `fuda-pile` is sent when it changes. */
105
246
  pileBounds = { left: 0, right: 0, top: 0, bottom: 0 };
106
247
  /** Take the top card (or `count` cards) off the stack: it flies to a pile at the stack's side and lands as `deck-land` says. At least one card stays. */
107
- takeOff(count = 1) { const t = Math.max(0, Math.floor(Number.parseFloat(this.getAttribute('taken-off') ?? '')) || 0); this.setAttribute('taken-off', String(Math.min(this.stackCount - 1, t + Math.max(1, count)))); }
248
+ takeOff(count = 1) {
249
+ const t = Math.max(0, Math.floor(Number.parseFloat(this.getAttribute("taken-off") ?? "")) || 0);
250
+ this.setAttribute("taken-off", String(Math.min(this.stackCount - 1, t + Math.max(1, count))));
251
+ }
108
252
  /** Bring the card (or `count` cards) back from the pile onto the stack. */
109
- putBack(count = 1) { const t = Math.max(0, Math.floor(Number.parseFloat(this.getAttribute('taken-off') ?? '')) || 0); if (t - Math.max(1, count) > 0)
110
- this.setAttribute('taken-off', String(t - Math.max(1, count)));
111
- else
112
- this.removeAttribute('taken-off'); }
253
+ putBack(count = 1) {
254
+ const t = Math.max(0, Math.floor(Number.parseFloat(this.getAttribute("taken-off") ?? "")) || 0);
255
+ if (t - Math.max(1, count) > 0)
256
+ this.setAttribute("taken-off", String(t - Math.max(1, count)));
257
+ else
258
+ this.removeAttribute("taken-off");
259
+ }
113
260
  pileUsed = false;
114
261
  pileModule;
115
262
  /** Fanning, the pile of cards taken off and the controls are drawn by a module that is loaded only when a stack asks for them; a card without them never loads it. */
116
263
  applyPile() {
117
- const asked = this.stackCount > 1 && (this.getAttribute('fan') === 'open' || this.hasAttribute('taken-off') || this.hasAttribute('pile-controls'));
264
+ const asked = this.stackCount > 1 &&
265
+ (this.getAttribute("fan") === "open" || this.hasAttribute("taken-off") || this.hasAttribute("pile-controls"));
118
266
  if (!asked && !this.pileModule)
119
267
  return;
120
268
  if (asked)
121
269
  this.pileUsed = true;
122
- const draw = (m) => { if (!this.shadowRoot)
123
- return; this.pileModule = m; m.applyPile(this, this.shadowRoot); };
270
+ const draw = (m) => {
271
+ if (!this.shadowRoot)
272
+ return;
273
+ this.pileModule = m;
274
+ m.applyPile(this, this.shadowRoot);
275
+ };
124
276
  if (this.pileModule)
125
277
  draw(this.pileModule);
126
278
  else
127
- void import('./pile-card.js').then(draw);
279
+ void import("./pile-card.js").then(draw);
128
280
  }
129
- wearKey = '';
281
+ wearKey = "";
130
282
  wearToken = 0;
131
283
  wearModule;
132
284
  /** Wear (an imperfect card) is drawn by a module that is loaded only when a card asks for it; a perfect card never loads it. */
133
285
  applyWear() {
134
- const num = (name) => { const v = this.getAttribute(name); return v === null || v.trim() === '' ? undefined : Number(v); };
135
- const key = ['wear', 'wear-seed', 'wear-corners', 'wear-edges', 'wear-surface', 'wear-creases'].map(n => this.getAttribute(n) ?? '').join('|');
136
- const w = this.getAttribute('wear') ?? '', asked = (w !== '' && w !== 'perfect' && w !== '0') || ['wear-corners', 'wear-edges', 'wear-surface', 'wear-creases'].some(n => this.hasAttribute(n));
286
+ const num = (name) => {
287
+ const v = this.getAttribute(name);
288
+ return v === null || v.trim() === "" ? undefined : Number(v);
289
+ };
290
+ const key = ["wear", "wear-seed", "wear-corners", "wear-edges", "wear-surface", "wear-creases"]
291
+ .map((n) => this.getAttribute(n) ?? "")
292
+ .join("|");
293
+ const w = this.getAttribute("wear") ?? "";
294
+ const asked = (w !== "" && w !== "perfect" && w !== "0") ||
295
+ ["wear-corners", "wear-edges", "wear-surface", "wear-creases"].some((n) => this.hasAttribute(n));
137
296
  if (key === this.wearKey || (!asked && !this.wearModule))
138
297
  return;
139
298
  this.wearKey = key;
140
299
  const token = ++this.wearToken;
141
- const draw = (m) => { if (token !== this.wearToken || !this.shadowRoot)
142
- return; this.wearModule = m; m.applyWear(this.shadowRoot, { wear: this.getAttribute('wear'), seed: num('wear-seed'), corners: num('wear-corners'), edges: num('wear-edges'), surface: num('wear-surface'), creases: num('wear-creases') }); this.dispatchEvent(new CustomEvent('fuda-wear', { detail: { key } })); };
300
+ const draw = (m) => {
301
+ if (token !== this.wearToken || !this.shadowRoot)
302
+ return;
303
+ this.wearModule = m;
304
+ m.applyWear(this.shadowRoot, {
305
+ wear: this.getAttribute("wear"),
306
+ seed: num("wear-seed"),
307
+ corners: num("wear-corners"),
308
+ edges: num("wear-edges"),
309
+ surface: num("wear-surface"),
310
+ creases: num("wear-creases"),
311
+ });
312
+ this.dispatchEvent(new CustomEvent("fuda-wear", { detail: { key } }));
313
+ };
143
314
  if (this.wearModule)
144
315
  draw(this.wearModule);
145
316
  else
146
- void import('./wear.js').then(draw);
317
+ void import("./wear.js").then(draw);
147
318
  }
148
319
  /** The wear the card is drawn with: a preset's id, a number, or an empty string when it is perfect. */
149
- get wear() { return this.getAttribute('wear') ?? ''; }
150
- set wear(value) { if (value)
151
- this.setAttribute('wear', value);
152
- else
153
- this.removeAttribute('wear'); }
154
- stillsKey = '';
320
+ get wear() {
321
+ return this.getAttribute("wear") ?? "";
322
+ }
323
+ set wear(value) {
324
+ if (value)
325
+ this.setAttribute("wear", value);
326
+ else
327
+ this.removeAttribute("wear");
328
+ }
329
+ stillsKey = "";
155
330
  /** The cards under the top one that are laid out nudged and turned; the rest of the stack is one block with a line for each card on its edge. */
156
331
  drawStills(card, count) {
157
- const num = (name, fallback) => { const n = Number.parseFloat(this.getAttribute(name) ?? ''); return Number.isFinite(n) ? n : fallback; };
158
- const messiness = num('stack-messiness', 0.3), seed = num('stack-seed', 1), depth = Math.min(52, Math.max(0, Math.floor(num('stack-depth', 10))));
332
+ const num = (name, fallback) => {
333
+ const n = Number.parseFloat(this.getAttribute(name) ?? "");
334
+ return Number.isFinite(n) ? n : fallback;
335
+ };
336
+ const messiness = num("stack-messiness", 0.3);
337
+ const seed = num("stack-seed", 1);
338
+ const depth = Math.min(52, Math.max(0, Math.floor(num("stack-depth", 10))));
159
339
  const places = count > 1 && (messiness > 0 || this.pileUsed) ? stackLayout(count, { messiness, seed, depth }) : [];
160
- const key = places.length ? JSON.stringify([count, messiness, seed, depth]) : '';
340
+ const key = places.length ? JSON.stringify([count, messiness, seed, depth]) : "";
161
341
  if (key === this.stillsKey)
162
342
  return;
163
343
  this.stillsKey = key;
164
- const holder = card.querySelector('.stills');
344
+ const holder = card.querySelector(".stills");
165
345
  if (holder)
166
- holder.innerHTML = places.map((p, at) => `<i class="still" style="--x:${p.x};--y:${p.y};--r:${p.rotate};--k:${count - places.length + at}"></i>`).join('');
167
- }
168
- render() { const card = this.shadowRoot?.querySelector('.card'); if (card) {
169
- const mm = this.cardThicknessMm, count = this.heldCount, fan = this.fanOpen, material = cardMaterial(this.getAttribute('material'));
170
- card.style.setProperty('--mm', String(fan ? mm : mm * count));
171
- card.style.setProperty('--mm1', String(mm));
172
- card.classList.toggle('stacked', count > 1 && !fan);
173
- if (material)
174
- card.style.setProperty('--edge', material.edge);
175
- else
176
- card.style.removeProperty('--edge');
177
- this.drawStills(card, count);
178
- } this.applyWear(); this.applyPile(); const button = this.shadowRoot?.querySelector('.motion-button'); if (button) {
179
- button.hidden = this.getAttribute('motion') !== 'pan';
180
- const active = this.isMoving;
181
- this.toggleAttribute('moving', active);
182
- button.setAttribute('aria-pressed', String(active));
183
- } for (const key of FudaCard.observedAttributes) {
184
- const node = this.shadowRoot?.getElementById(key);
185
- if (node)
186
- node.textContent = this.getAttribute(key) || (defaults[key] ?? '');
187
- } }
346
+ holder.innerHTML = stillsHtml(places, count);
347
+ }
348
+ render() {
349
+ const card = this.shadowRoot?.querySelector(".card");
350
+ if (card) {
351
+ const mm = this.cardThicknessMm;
352
+ const count = this.heldCount;
353
+ const fan = this.fanOpen;
354
+ const material = cardMaterial(this.getAttribute("material"));
355
+ card.style.setProperty("--mm", String(fan ? mm : mm * count));
356
+ card.style.setProperty("--mm1", String(mm));
357
+ card.classList.toggle("stacked", count > 1 && !fan);
358
+ if (material)
359
+ card.style.setProperty("--edge-color", material.edge);
360
+ else
361
+ card.style.removeProperty("--edge-color");
362
+ this.drawStills(card, count);
363
+ }
364
+ this.applyWear();
365
+ this.applyPile();
366
+ const button = this.shadowRoot?.querySelector(".motion-button");
367
+ if (button) {
368
+ button.hidden = this.getAttribute("motion") !== "pan";
369
+ const active = this.isMoving;
370
+ this.toggleAttribute("moving", active);
371
+ button.setAttribute("aria-pressed", String(active));
372
+ }
373
+ for (const key of FudaCard.observedAttributes) {
374
+ const node = this.shadowRoot?.getElementById(key);
375
+ if (node)
376
+ node.textContent = this.getAttribute(key) || (defaults[key] ?? "");
377
+ }
378
+ }
188
379
  }
189
- if (typeof customElements !== 'undefined' && !customElements.get('fuda-card'))
190
- customElements.define('fuda-card', FudaCard);
380
+ if (typeof customElements !== "undefined" && !customElements.get("fuda-card"))
381
+ customElements.define("fuda-card", FudaCard);
package/dist/index.d.ts CHANGED
@@ -1,52 +1,9 @@
1
- /** A card's finish and visual family. */
2
- export type CardFinish = 'foil' | 'matte';
3
- export type CardVariant = 'classic' | 'sport' | 'cosmic';
4
- export interface CardOptions {
5
- title?: string;
6
- category?: string;
7
- subtitle?: string;
8
- description?: string;
9
- number?: string;
10
- rarity?: string;
11
- variant?: CardVariant;
12
- finish?: CardFinish;
13
- /** Card thickness in millimetres at the 63 mm wide card size; overrides the material's. Default 0.3, 0 for a flat card. */
14
- thickness?: number;
15
- /** A material's id (see `cardMaterials`): its sourced thickness and edge colour. */
16
- material?: string;
17
- /** How many cards the stack holds (1 to 1000); the stack is that many times the card's thickness high. Default 1, one card. */
18
- stack?: number;
19
- /** From 0 (squared up) to 1 (very messy) for the cards under the top one. Default 0.3. */
20
- stackMessiness?: number;
21
- /** The stack's seed: the same seed lays the same stack the same way. Default 1. */
22
- stackSeed?: number;
23
- /** How many cards under the top one are laid out nudged and turned, at most 52. Default 10. */
24
- stackDepth?: number;
25
- /** 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. */
26
- wear?: string | number;
27
- /** The wear's seed: the same seed draws the same marks the same way. Default 1. */
28
- wearSeed?: number;
29
- /** One level of the wear on its own, from 0 to 1, over the preset's. */
30
- wearCorners?: number;
31
- wearEdges?: number;
32
- wearSurface?: number;
33
- wearCreases?: number;
34
- flipped?: boolean;
35
- motion?: 'still' | 'pan';
36
- playing?: boolean;
37
- /** `focus`: the card in focus animates its art (needs `motion: 'pan'`); never with reduced motion. */
38
- autoplay?: 'focus';
39
- panDirection?: 'down' | 'up';
40
- panLoop?: 'alternate' | 'restart';
41
- cardSpin?: 'center' | 'corner';
42
- cardSpinDirection?: 'normal' | 'reverse';
43
- cardSpinPaused?: boolean;
44
- }
45
- export declare const cardVariants: readonly CardVariant[];
46
- export declare const cardFinishes: readonly CardFinish[];
47
- export { cardMaterials, cardMaterial, stackPresets, stackHeightMm, mmPerPoint } from './materials.js';
48
- export type { CardMaterial, CardMaterialGroup, CardMaterialSource, StackPreset } from './materials.js';
49
- export { stackLayout } from './stack.js';
50
- export type { StackPlace, StackLayoutOptions } from './stack.js';
51
- export { wearPresets, wearPreset, wearLevels, wearLayout, wearOutline, wearOverlaySvg } from './wear.js';
52
- export type { WearPreset, WearLevels, WearOptions, WearFeatures, WearCorner, CornerKind } from './wear.js';
1
+ export type { CardFinish, CardOptions, CardVariant } from "./card-options.js";
2
+ export { cardAttributes, cardFinishes, cardVariants } from "./card-options.js";
3
+ export type { CardMaterial, CardMaterialGroup, CardMaterialSource, StackPreset } from "./materials.js";
4
+ export { cardMaterial, cardMaterials, DEFAULT_CARD_THICKNESS_MM, mmPerPoint, stackHeightMm, stackPresets, } from "./materials.js";
5
+ export type { StackLayoutOptions, StackPlace } from "./stack.js";
6
+ export { stackLayout } from "./stack.js";
7
+ export { VERSION } from "./version.js";
8
+ export type { CornerKind, WearCorner, WearFeatures, WearLevels, WearOptions, WearPreset } from "./wear.js";
9
+ export { wearLayout, wearLevels, wearOutline, wearOverlaySvg, wearPreset, wearPresets } from "./wear.js";
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
- export const cardVariants = ['classic', 'sport', 'cosmic'];
2
- export const cardFinishes = ['foil', 'matte'];
3
- export { cardMaterials, cardMaterial, stackPresets, stackHeightMm, mmPerPoint } from './materials.js';
4
- export { stackLayout } from './stack.js';
5
- export { wearPresets, wearPreset, wearLevels, wearLayout, wearOutline, wearOverlaySvg } from './wear.js';
1
+ export { cardAttributes, cardFinishes, cardVariants } from "./card-options.js";
2
+ export { cardMaterial, cardMaterials, DEFAULT_CARD_THICKNESS_MM, mmPerPoint, stackHeightMm, stackPresets, } from "./materials.js";
3
+ export { stackLayout } from "./stack.js";
4
+ export { VERSION } from "./version.js";
5
+ export { wearLayout, wearLevels, wearOutline, wearOverlaySvg, wearPreset, wearPresets } from "./wear.js";