@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
package/dist/binder.d.ts CHANGED
@@ -6,8 +6,8 @@
6
6
  * A leaf has two sides, as a real one does: leaf k holds sides 2k (the right-hand page) and 2k+1 (the left-hand page of the next opening).
7
7
  * An opening (spread) j shows side 2j-1 on the left (none at the start) and side 2j on the right.
8
8
  */
9
- export type BinderStyle = 'ring' | 'zip';
10
- export type BinderSheet = 'clear' | 'black';
9
+ export type BinderStyle = "ring" | "zip";
10
+ export type BinderSheet = "clear" | "black";
11
11
  export declare const binderCovers: ReadonlyArray<{
12
12
  id: string;
13
13
  label: string;
@@ -36,11 +36,9 @@ export declare function spreadSides(spread: number, sides: number): [number, num
36
36
  export declare const BINDER_CSS = "\n.stage.binder{perspective:2400px;background:radial-gradient(ellipse,var(--fc-stage-1),var(--fc-stage-2) 68%)}\n.v.binder{--sw:300px;--sh:384px;--strip:34px;--cover:#1f7a4a;display:flex;align-items:center;justify-content:center;transform-style:preserve-3d}\n.book{position:relative;display:flex;padding:18px 16px;border-radius:16px;background:var(--cover);box-shadow:0 12px 28px #0008,inset 0 0 0 2px #fff2,inset 0 0 24px #0005;transform-style:preserve-3d}\n.book::before{content:'';position:absolute;inset:6px;border-radius:12px;box-shadow:inset 0 0 0 2px #0004;pointer-events:none}\n.book.b-zip::after{content:'';position:absolute;inset:5px;border-radius:13px;border:3px dotted #cfd2d8;opacity:.7;pointer-events:none}\n.book .tab{display:none}.book.b-zip .tab{display:block;position:absolute;right:30px;bottom:-4px;width:34px;height:14px;border-radius:5px;background:linear-gradient(#e4e6ea,#8d9098);box-shadow:0 2px 4px #0006}\n.inside{position:relative;display:flex;transform-style:preserve-3d;background:var(--lining,#f1eee6);border-radius:6px;box-shadow:inset 0 0 18px #0003}\n.half{position:relative;width:var(--sw);height:var(--sh);flex:none}\n.half:empty::after{content:'';position:absolute;inset:0;background:linear-gradient(90deg,#0002,transparent 14%)}\n.spine{position:absolute;left:50%;top:0;bottom:0;width:0;transform-style:preserve-3d;pointer-events:none;z-index:3}\n.ring{position:absolute;left:-9px;width:18px;height:46px;margin-top:-23px;border-radius:9px;border:4px solid #c3c6cd;border-color:#f1f2f5 #8d9098 #8d9098 #f1f2f5;box-shadow:0 2px 3px #0005;transform:translateZ(2px)}\n.side{position:absolute;inset:0;display:grid;padding:12px 10px;grid-template-columns:repeat(var(--cols,3),minmax(0,1fr));grid-template-rows:repeat(var(--rows,3),minmax(0,1fr));gap:5px;background:var(--sheetbg);box-sizing:border-box;border:1px solid var(--sheetedge)}\n.side.clear{--sheetbg:#ffffff2e;--sheetedge:#ffffff55;--pocketbg:#ffffff26;--pocketedge:#ffffffa0}.side.black{--sheetbg:#17171b;--sheetedge:#000;--pocketbg:#ffffff12;--pocketedge:#ffffff55}\n.side.r{padding-left:calc(var(--strip) + 6px)}.side.l{padding-right:calc(var(--strip) + 6px)}\n.holes{position:absolute;top:0;bottom:0;width:var(--strip);display:flex;flex-direction:column;justify-content:space-evenly;align-items:center;padding:14px 0}.side.r .holes{left:0}.side.l .holes{right:0}.holes i{width:9px;height:9px;border-radius:50%;background:var(--lining,#f1eee6);box-shadow:inset 0 1px 2px #0007,0 0 0 1px #0002}\n.pocket{position:relative;display:grid;place-items:center;border-radius:4px;background:var(--pocketbg);border:1px solid var(--pocketedge);box-shadow:inset 0 0 0 1px #0000000d,0 1px 2px #0003;overflow:hidden;min-width:0;min-height:0}\n.pocket::after{content:'';position:absolute;inset:0;pointer-events:none;background:linear-gradient(118deg,#ffffff55 0,#ffffff00 32%,#ffffff12 55%,#ffffff00 70%,#ffffff33 100%)}\n.pocket .card{position:relative;z-index:0;width:86%;height:92%;padding:0;border:0;background:transparent;line-height:0;display:grid;place-items:center}.pocket .card img{width:100%;height:100%;object-fit:contain;border-radius:3%;box-shadow:0 2px 5px #0007}\n.pocket.empty{opacity:.55}\n.leaf{position:absolute;left:50%;top:0;width:var(--sw);height:var(--sh);transform-origin:0 50%;transform-style:preserve-3d;pointer-events:none;z-index:2}\n.slice{position:absolute;top:0;height:100%;transform-origin:0 50%;transform-style:preserve-3d}\n.slice>.f,.slice>.b{position:absolute;inset:0 -1.5px;backface-visibility:hidden;-webkit-backface-visibility:hidden;overflow:hidden}.slice>.b{transform:rotateY(180deg)}\n.slice .sf{position:absolute;top:0;height:100%}\n/* The slices overlap their neighbours by a pixel and a half, so no seam between them lets the page behind show; the outer edges of the leaf stay where they are. */\n.slice.first>.f,.slice.last>.b{left:0}.slice.first>.b,.slice.last>.f{right:0}\n";
37
37
  /** The cards a side holds, as indexes into the collection (or -1 for an empty pocket), in reading order. */
38
38
  export declare function sideCards(side: number, layout: BinderLayout, total: number): number[];
39
- export interface PocketMaker {
40
- (index: number, live: boolean): HTMLElement;
41
- }
39
+ export type PocketMaker = (index: number, live: boolean) => HTMLElement;
42
40
  /** One side as it lies in the book: `left` or `right` of the spine, with its hole strip against the spine. `live` pockets hold the page's real card buttons; the rest hold pictures only. */
43
- export declare function buildSide(side: number, where: 'l' | 'r', sheet: BinderSheet, layout: BinderLayout, total: number, pocket: PocketMaker, live?: boolean): HTMLElement;
41
+ export declare function buildSide(side: number, where: "l" | "r", sheet: BinderSheet, layout: BinderLayout, total: number, pocket: PocketMaker, live?: boolean): HTMLElement;
44
42
  /**
45
43
  * A leaf of the book, built to swing: a chain of slices hinged one on the next (the hole strip, then a slice for each column of
46
44
  * pockets), so that each can lean a little more than the one before it and the sheet bends. Each slice has the pockets of the front side on its
package/dist/binder.js CHANGED
@@ -1,10 +1,15 @@
1
1
  export const binderCovers = [
2
- { id: 'green', label: 'Green', color: '#1f7a4a' }, { id: 'black', label: 'Black', color: '#1d1d22' }, { id: 'teal', label: 'Teal', color: '#1a9d93' },
3
- { id: 'navy', label: 'Navy', color: '#1f3a70' }, { id: 'red', label: 'Red', color: '#b0262d' }
2
+ { id: "green", label: "Green", color: "#1f7a4a" },
3
+ { id: "black", label: "Black", color: "#1d1d22" },
4
+ { id: "teal", label: "Teal", color: "#1a9d93" },
5
+ { id: "navy", label: "Navy", color: "#1f3a70" },
6
+ { id: "red", label: "Red", color: "#b0262d" },
4
7
  ];
5
8
  /** The sheets a binder takes: how many pockets and how they lie (across by down). 9 is the usual page; 4 and 12 are the other common ones. */
6
9
  export const binderPockets = [
7
- { count: 4, cols: 2, rows: 2 }, { count: 9, cols: 3, rows: 3 }, { count: 12, cols: 4, rows: 3 }
10
+ { count: 4, cols: 2, rows: 2 },
11
+ { count: 9, cols: 3, rows: 3 },
12
+ { count: 12, cols: 4, rows: 3 },
8
13
  ];
9
14
  /** The pockets of a sheet: `pockets` (4, 9 or 12) if the page asks, else the older `columns` and `page-size`, else nine in three columns. */
10
15
  export function binderLayout(pockets, columns, pageSize) {
@@ -22,7 +27,8 @@ export const spreadCount = (sides) => Math.ceil((sides + 1) / 2);
22
27
  export const spreadOf = (index, per) => Math.ceil(Math.floor(index / per) / 2);
23
28
  /** The sides an opening shows (-1 where there is none), left then right, for `sides` sides in all. */
24
29
  export function spreadSides(spread, sides) {
25
- const left = 2 * spread - 1, right = 2 * spread;
30
+ const left = 2 * spread - 1;
31
+ const right = 2 * spread;
26
32
  return [left >= 0 && left < sides ? left : -1, right < sides ? right : -1];
27
33
  }
28
34
  export const BINDER_CSS = `
@@ -58,17 +64,17 @@ export function sideCards(side, layout, total) {
58
64
  }
59
65
  /** One side as it lies in the book: `left` or `right` of the spine, with its hole strip against the spine. `live` pockets hold the page's real card buttons; the rest hold pictures only. */
60
66
  export function buildSide(side, where, sheet, layout, total, pocket, live = true) {
61
- const el = document.createElement('div');
67
+ const el = document.createElement("div");
62
68
  el.className = `side ${where} ${sheet}`;
63
69
  el.dataset.side = String(side);
64
- el.style.setProperty('--cols', String(layout.cols));
65
- el.style.setProperty('--rows', String(layout.rows));
66
- const holes = document.createElement('div');
67
- holes.className = 'holes';
68
- holes.innerHTML = '<i></i>'.repeat(9);
70
+ el.style.setProperty("--cols", String(layout.cols));
71
+ el.style.setProperty("--rows", String(layout.rows));
72
+ const holes = document.createElement("div");
73
+ holes.className = "holes";
74
+ holes.innerHTML = "<i></i>".repeat(9);
69
75
  el.append(holes);
70
76
  for (const index of sideCards(side, layout, total))
71
- el.append(index < 0 ? Object.assign(document.createElement('div'), { className: 'pocket empty' }) : pocket(index, live));
77
+ el.append(index < 0 ? Object.assign(document.createElement("div"), { className: "pocket empty" }) : pocket(index, live));
72
78
  return el;
73
79
  }
74
80
  /**
@@ -77,32 +83,35 @@ export function buildSide(side, where, sheet, layout, total, pocket, live = true
77
83
  * front and the matching column of the back side on its back. Returns the leaf and its slices.
78
84
  */
79
85
  export function buildLeaf(front, back, sheet, layout, total, pocket, widthPx, strip) {
80
- const leaf = document.createElement('div');
81
- leaf.className = 'leaf';
86
+ const leaf = document.createElement("div");
87
+ leaf.className = "leaf";
82
88
  const faces = (side, where) => side < 0 ? null : buildSide(side, where, sheet, layout, total, pocket, false);
83
- const rightSide = faces(front, 'r'), leftSide = faces(back, 'l');
89
+ const rightSide = faces(front, "r");
90
+ const leftSide = faces(back, "l");
84
91
  const widths = [strip + 6, ...Array.from({ length: layout.cols }, () => (widthPx - strip - 6) / layout.cols)];
85
92
  const slices = [];
86
- let parent = leaf, offset = 0;
93
+ let parent = leaf;
94
+ let offset = 0;
87
95
  widths.forEach((w, k) => {
88
- const slice = document.createElement('div');
89
- slice.className = k === 0 ? 'slice first' : k === widths.length - 1 ? 'slice last' : 'slice';
96
+ const slice = document.createElement("div");
97
+ slice.className = k === 0 ? "slice first" : k === widths.length - 1 ? "slice last" : "slice";
90
98
  slice.style.width = `${w}px`;
91
- slice.style.left = k === 0 ? '0' : '100%';
92
- const f = document.createElement('div'), b = document.createElement('div');
93
- f.className = 'f';
94
- b.className = 'b';
99
+ slice.style.left = k === 0 ? "0" : "100%";
100
+ const f = document.createElement("div");
101
+ const b = document.createElement("div");
102
+ f.className = "f";
103
+ b.className = "b";
95
104
  // The whole side is placed inside each slice's face and shifted so that this slice shows its own part of it.
96
105
  if (rightSide) {
97
106
  const copy = rightSide.cloneNode(true);
98
- copy.classList.add('sf');
107
+ copy.classList.add("sf");
99
108
  copy.style.width = `${widthPx}px`;
100
109
  copy.style.left = `${-offset}px`;
101
110
  f.append(copy);
102
111
  }
103
112
  if (leftSide) {
104
113
  const copy = leftSide.cloneNode(true);
105
- copy.classList.add('sf');
114
+ copy.classList.add("sf");
106
115
  copy.style.width = `${widthPx}px`;
107
116
  copy.style.left = `${-(widthPx - offset - w)}px`;
108
117
  b.append(copy);
@@ -0,0 +1,2 @@
1
+ /** The card's shadow root: its stylesheet, the front, the back, the edge and the place for the cards under the top one. */
2
+ export declare function cardMarkup(): string;
@@ -0,0 +1,59 @@
1
+ import { CARD_CSS } from "./card-styles.js";
2
+ /** The corner radius of the card's face, in design pixels (a 300th of the card's width). */
3
+ const CORNER_RADIUS = 15;
4
+ /** The edge planes stop this far from the corner so that the rounded corner is not poked through (twice the corner radius). */
5
+ const EDGE_INSET = CORNER_RADIUS * 2;
6
+ /**
7
+ * Each rounded corner is edged by two short planes that follow its curve, as the straight edges are by one: where they sit from the corner, how long
8
+ * they are and how far they turn. They are tangents of the 15 pixel arc, one at 22.5 degrees and one at 67.5 degrees round it (length 2 r tan 22.5, at
9
+ * r (1 - cos 22.5) and r (1 - sin 22.5) from the corner), not chords. A plane of the edge reaches across the whole card when it is extended, and the browser
10
+ * cuts the faces it crosses along it, which left a thin diagonal line on the card (MODULES-142): a tangent of a convex card never crosses its face.
11
+ */
12
+ const CORNER_PLANE = { near: 1.14, far: 9.26, length: 12.43, steep: 67.5, shallow: 22.5 };
13
+ const design = (pixels) => `calc(${pixels} * var(--u))`;
14
+ const fromRight = (pixels) => `calc(100% - ${design(pixels)})`;
15
+ const plane = ({ left, top, width, height, transform, side }) => `<i class="edge${side ? " side" : ""}" style="left:${left};top:${top};width:${width};height:${height};transform:${transform}"></i>`;
16
+ const turned = (degrees) => `translate(-50%,-50%) rotate(${degrees}deg) rotateX(90deg)`;
17
+ /** The planes that make the card's edge: four straight ones and eight that follow the corners. */
18
+ function edgePlanes() {
19
+ const run = `calc(100% - ${design(EDGE_INSET)})`;
20
+ const { near, far, length, steep, shallow } = CORNER_PLANE;
21
+ const long = design(length);
22
+ const corner = (left, top, degrees) => plane({ left, top, width: long, height: "var(--t)", transform: turned(degrees) });
23
+ return [
24
+ plane({ left: "50%", top: "0", width: run, height: "var(--t)", transform: turned(0) }),
25
+ plane({ left: "50%", top: "100%", width: run, height: "var(--t)", transform: turned(0) }),
26
+ plane({
27
+ left: "0",
28
+ top: "50%",
29
+ width: "var(--t)",
30
+ height: run,
31
+ transform: "translate(-50%,-50%) rotateY(90deg)",
32
+ side: true,
33
+ }),
34
+ plane({
35
+ left: "100%",
36
+ top: "50%",
37
+ width: "var(--t)",
38
+ height: run,
39
+ transform: "translate(-50%,-50%) rotateY(90deg)",
40
+ side: true,
41
+ }),
42
+ corner(design(near), design(far), -steep),
43
+ corner(design(far), design(near), -shallow),
44
+ corner(design(near), fromRight(far), steep),
45
+ corner(design(far), fromRight(near), shallow),
46
+ corner(fromRight(near), design(far), steep),
47
+ corner(fromRight(far), design(near), shallow),
48
+ corner(fromRight(near), fromRight(far), -steep),
49
+ corner(fromRight(far), fromRight(near), -shallow),
50
+ ].join("");
51
+ }
52
+ /** The picture's slot and its Animate button. */
53
+ const ART = `<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>`;
54
+ const FRONT = `<div class="face front"><div class="inner"><div class="heading"><span id="title"></span><span class="badge" id="category"></span></div>${ART}<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>`;
55
+ const BACK = `<div class="face back"><div class="emblem">FUDA</div><div class="shine"></div></div>`;
56
+ /** The card's shadow root: its stylesheet, the front, the back, the edge and the place for the cards under the top one. */
57
+ export function cardMarkup() {
58
+ return `<style>${CARD_CSS}</style><div class="rotation"><div class="card">${FRONT}${BACK}${edgePlanes()}<div class="stills"></div></div></div>`;
59
+ }
@@ -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;