@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/stack.d.ts CHANGED
@@ -1,9 +1,13 @@
1
1
  /**
2
- * Where the cards of a stack lie, from neat to messy, the same every time for the same seed.
2
+ * Where one card of a stack lies, as the stack's layout says: how far it is nudged across and down, in card widths, and how far it is turned.
3
3
  *
4
- * The idea and the three parameters (messiness, seed, depth) come from toranpu's pileLayout
5
- * (github.com/johnmorrisdotca/toranpu, `src/ui/layout.ts`, MIT). This is written again here for a stack that has a true
6
- * thickness: a card's height is not faked by moving it down the page, so only the nudge and the turn are laid out.
4
+ * @example
5
+ * ```ts
6
+ * import { stackLayout, type StackPlace } from "@johnmorrisdotca/fuda-cards";
7
+ *
8
+ * const place: StackPlace = stackLayout(5, { seed: 3 })[0];
9
+ * console.log(Object.keys(place)); // [ 'x', 'y', 'rotate' ]
10
+ * ```
7
11
  */
8
12
  export interface StackPlace {
9
13
  /** Across, in card widths from where a square card lies. */
@@ -13,6 +17,17 @@ export interface StackPlace {
13
17
  /** Turn in degrees. */
14
18
  rotate: number;
15
19
  }
20
+ /**
21
+ * How a stack is laid out: how messy, from which seed and how many cards deep.
22
+ *
23
+ * @example
24
+ * ```ts
25
+ * import { stackLayout, type StackLayoutOptions } from "@johnmorrisdotca/fuda-cards";
26
+ *
27
+ * const messy: StackLayoutOptions = { messiness: 0.8, seed: 7, depth: 5 };
28
+ * console.log(stackLayout(52, messy).length); // 5
29
+ * ```
30
+ */
16
31
  export interface StackLayoutOptions {
17
32
  /** From 0 (squared up) to 1 (very messy). Unless said, 0.3. */
18
33
  messiness?: number;
@@ -24,7 +39,28 @@ export interface StackLayoutOptions {
24
39
  /** A stream of numbers in [0, 1) fixed by a seed (mulberry32). */
25
40
  export declare function seededRandom(seed: number): () => number;
26
41
  /**
27
- * The cards under the top one of a stack of `count`, bottom first: the top `depth` of them, as the top card is the live one
28
- * and lies square. A card's place depends on its number from the bottom, so a card put on top moves none of those under it.
42
+ * Where the cards of a stack lie, from neat to messy, the same every time for the same seed: the cards under the top one, bottom first, at most
43
+ * `depth` of them, as the top card is the live one and lies square. A card's place depends on its number from the bottom, so a card put
44
+ * on top moves none of those under it.
45
+ *
46
+ * The idea and the three parameters (messiness, seed, depth) come from toranpu's pileLayout (github.com/johnmorrisdotca/toranpu,
47
+ * `src/ui/layout.ts`, MIT). This is written again here for a stack that has a true thickness: a card's height is not faked by moving it
48
+ * down the page, so only the nudge and the turn are laid out.
49
+ *
50
+ * @param count - How many cards the stack holds; with none or one there is nothing under the top.
51
+ * @param options - How messy, which seed and how deep. Unless said: 0.3, 1 and 10.
52
+ * @returns The places of the cards under the top one, bottom first; empty for a stack of one.
53
+ * @example
54
+ * ```ts
55
+ * import { stackLayout } from "@johnmorrisdotca/fuda-cards";
56
+ *
57
+ * const same = JSON.stringify(stackLayout(52, { seed: 7 })) === JSON.stringify(stackLayout(52, { seed: 7 }));
58
+ * console.log(same, stackLayout(1).length, stackLayout(52).length); // true 0 10
59
+ * ```
29
60
  */
30
61
  export declare function stackLayout(count: number, options?: StackLayoutOptions): StackPlace[];
62
+ /**
63
+ * The markup of the cards under the top one, bottom first, for a stack of `count` cards: each is the frame of the top card with
64
+ * nothing written on it, laid where `places` says and as many cards lower as its number from the bottom.
65
+ */
66
+ export declare function stillsHtml(places: StackPlace[], count: number): string;
package/dist/stack.js CHANGED
@@ -15,8 +15,24 @@ const round = (value) => {
15
15
  return Object.is(kept, -0) ? 0 : kept;
16
16
  };
17
17
  /**
18
- * The cards under the top one of a stack of `count`, bottom first: the top `depth` of them, as the top card is the live one
19
- * and lies square. A card's place depends on its number from the bottom, so a card put on top moves none of those under it.
18
+ * Where the cards of a stack lie, from neat to messy, the same every time for the same seed: the cards under the top one, bottom first, at most
19
+ * `depth` of them, as the top card is the live one and lies square. A card's place depends on its number from the bottom, so a card put
20
+ * on top moves none of those under it.
21
+ *
22
+ * The idea and the three parameters (messiness, seed, depth) come from toranpu's pileLayout (github.com/johnmorrisdotca/toranpu,
23
+ * `src/ui/layout.ts`, MIT). This is written again here for a stack that has a true thickness: a card's height is not faked by moving it
24
+ * down the page, so only the nudge and the turn are laid out.
25
+ *
26
+ * @param count - How many cards the stack holds; with none or one there is nothing under the top.
27
+ * @param options - How messy, which seed and how deep. Unless said: 0.3, 1 and 10.
28
+ * @returns The places of the cards under the top one, bottom first; empty for a stack of one.
29
+ * @example
30
+ * ```ts
31
+ * import { stackLayout } from "@johnmorrisdotca/fuda-cards";
32
+ *
33
+ * const same = JSON.stringify(stackLayout(52, { seed: 7 })) === JSON.stringify(stackLayout(52, { seed: 7 }));
34
+ * console.log(same, stackLayout(1).length, stackLayout(52).length); // true 0 10
35
+ * ```
20
36
  */
21
37
  export function stackLayout(count, options = {}) {
22
38
  const whole = Math.max(0, Math.floor(Number.isFinite(count) ? count : 0));
@@ -32,8 +48,17 @@ export function stackLayout(count, options = {}) {
32
48
  places.push({
33
49
  x: round((random() * 2 - 1) * nudge),
34
50
  y: round((random() * 2 - 1) * nudge * 0.8),
35
- rotate: round((random() * 2 - 1) * 14 * mess ** 1.3)
51
+ rotate: round((random() * 2 - 1) * 14 * mess ** 1.3),
36
52
  });
37
53
  }
38
54
  return places;
39
55
  }
56
+ /**
57
+ * The markup of the cards under the top one, bottom first, for a stack of `count` cards: each is the frame of the top card with
58
+ * nothing written on it, laid where `places` says and as many cards lower as its number from the bottom.
59
+ */
60
+ export function stillsHtml(places, count) {
61
+ return places
62
+ .map((place, at) => `<div class="still" style="--x:${place.x};--y:${place.y};--r:${place.rotate};--k:${count - places.length + at}"><div class="inner"></div><div class="shine"></div></div>`)
63
+ .join("");
64
+ }
@@ -0,0 +1,11 @@
1
+ /**
2
+ * The version of this package, the same as `package.json`'s (a test holds the two together).
3
+ *
4
+ * @example
5
+ * ```ts
6
+ * import { VERSION } from "@johnmorrisdotca/fuda-cards";
7
+ *
8
+ * console.log(/^\d+\.\d+\.\d+$/.test(VERSION)); // true
9
+ * ```
10
+ */
11
+ export declare const VERSION = "0.12.0";
@@ -0,0 +1,11 @@
1
+ /**
2
+ * The version of this package, the same as `package.json`'s (a test holds the two together).
3
+ *
4
+ * @example
5
+ * ```ts
6
+ * import { VERSION } from "@johnmorrisdotca/fuda-cards";
7
+ *
8
+ * console.log(/^\d+\.\d+\.\d+$/.test(VERSION)); // true
9
+ * ```
10
+ */
11
+ export const VERSION = "0.12.0";
package/dist/wear.d.ts CHANGED
@@ -1,4 +1,14 @@
1
- /** How much of each kind of wear, from 0 (none) to 1 (the worst the preset names). */
1
+ /**
2
+ * How much of each kind of wear, from 0 (none) to 1 (the worst the preset names).
3
+ *
4
+ * @example
5
+ * ```ts
6
+ * import { wearPreset, type WearLevels } from "@johnmorrisdotca/fuda-cards";
7
+ *
8
+ * const levels: WearLevels | undefined = wearPreset("near-mint")?.levels;
9
+ * console.log(levels?.corners, levels?.creases); // 0.18 0
10
+ * ```
11
+ */
2
12
  export interface WearLevels {
3
13
  corners: number;
4
14
  edges: number;
@@ -9,6 +19,17 @@ export interface WearLevels {
9
19
  /** How far the print sits off centre. */
10
20
  centering: number;
11
21
  }
22
+ /**
23
+ * A grading term with the levels it stands for and what it means in a few words.
24
+ *
25
+ * @example
26
+ * ```ts
27
+ * import { wearPresets, type WearPreset } from "@johnmorrisdotca/fuda-cards";
28
+ *
29
+ * const worst: WearPreset = wearPresets[wearPresets.length - 1];
30
+ * console.log(worst.id, worst.says); // damaged Chipped and folded corners, hard creases, staining.
31
+ * ```
32
+ */
12
33
  export interface WearPreset {
13
34
  id: string;
14
35
  name: string;
@@ -16,9 +37,42 @@ export interface WearPreset {
16
37
  /** What the condition term means in grading language, in a few words. */
17
38
  says: string;
18
39
  }
19
- /** From perfect to damaged. The names are the plain grading terms; the numbers are this package's reading of them (docs/wear.md). */
40
+ /**
41
+ * The seven grades, from perfect to damaged. The names are the plain grading terms; the numbers are this package's reading of them (docs/wear.md).
42
+ *
43
+ * @example
44
+ * ```ts
45
+ * import { wearPresets } from "@johnmorrisdotca/fuda-cards";
46
+ *
47
+ * console.log(wearPresets.map((preset) => preset.id).join(" "));
48
+ * // perfect mint near-mint lightly-played moderately-played heavily-played damaged
49
+ * ```
50
+ */
20
51
  export declare const wearPresets: readonly WearPreset[];
52
+ /**
53
+ * The grade with this id.
54
+ *
55
+ * @param id - A grade's id, such as `near-mint` (the `wear` attribute's value).
56
+ * @returns The grade, or `undefined` when there is none with that id.
57
+ * @example
58
+ * ```ts
59
+ * import { wearPreset } from "@johnmorrisdotca/fuda-cards";
60
+ *
61
+ * console.log(wearPreset("mint")?.name, wearPreset("pristine")); // Mint undefined
62
+ * ```
63
+ */
21
64
  export declare function wearPreset(id: string | null | undefined): WearPreset | undefined;
65
+ /**
66
+ * What a card asks of its wear: a grade or a number, a seed, and any level on its own.
67
+ *
68
+ * @example
69
+ * ```ts
70
+ * import { wearLevels, type WearOptions } from "@johnmorrisdotca/fuda-cards";
71
+ *
72
+ * const asked: WearOptions = { wear: "mint", corners: 0.5, seed: 4 };
73
+ * console.log(wearLevels(asked)?.corners); // 0.5
74
+ * ```
75
+ */
22
76
  export interface WearOptions {
23
77
  /** A preset's id, or a number from 0 to 1 for all the levels at once. */
24
78
  wear?: string | number | null;
@@ -30,9 +84,43 @@ export interface WearOptions {
30
84
  surface?: number;
31
85
  creases?: number;
32
86
  }
33
- /** The levels a card's wear asks for, or null when it asks for none (no wear, "perfect", an unknown name or all zero). */
87
+ /**
88
+ * The levels a card's wear asks for: the grade's or the number's, with any level named on its own laid over them.
89
+ *
90
+ * @param options - The wear asked for: a grade or a number from 0 to 1, and levels of corners, edges, surface and creases.
91
+ * @returns The levels, or `null` when the card asks for none: no wear, "perfect", an unknown name or every level zero.
92
+ * @example
93
+ * ```ts
94
+ * import { wearLevels } from "@johnmorrisdotca/fuda-cards";
95
+ *
96
+ * console.log(wearLevels({ wear: "perfect" })); // null
97
+ * console.log(wearLevels({ wear: 0.5 })?.surface); // 0.5
98
+ * ```
99
+ */
34
100
  export declare function wearLevels(options: WearOptions): WearLevels | null;
35
- export type CornerKind = 'sharp' | 'soft' | 'rounded' | 'chipped' | 'dog-eared';
101
+ /**
102
+ * How a corner is worn: sharp, softened, rounded, chipped or folded.
103
+ *
104
+ * @example
105
+ * ```ts
106
+ * import { wearLayout, wearPreset, type CornerKind } from "@johnmorrisdotca/fuda-cards";
107
+ *
108
+ * const kinds: CornerKind[] = wearLayout(wearPreset("damaged")!.levels, 3).corners.map((corner) => corner.kind);
109
+ * console.log(kinds.length); // 4
110
+ * ```
111
+ */
112
+ export type CornerKind = "sharp" | "soft" | "rounded" | "chipped" | "dog-eared";
113
+ /**
114
+ * One corner of a worn card: how it is worn and how far the damage reaches.
115
+ *
116
+ * @example
117
+ * ```ts
118
+ * import { wearLayout, wearPreset, type WearCorner } from "@johnmorrisdotca/fuda-cards";
119
+ *
120
+ * const corner: WearCorner = wearLayout(wearPreset("lightly-played")!.levels).corners[0];
121
+ * console.log(typeof corner.size, corner.jag.length >= 0); // number true
122
+ * ```
123
+ */
36
124
  export interface WearCorner {
37
125
  kind: CornerKind;
38
126
  /** How far the damage reaches along each edge, in units of a 250 by 350 card. */
@@ -76,6 +164,17 @@ export interface WearFace {
76
164
  a: number;
77
165
  } | null;
78
166
  }
167
+ /**
168
+ * Every mark of a worn card: its corners, its centring, and the creases, scratches, specks and stain of each face.
169
+ *
170
+ * @example
171
+ * ```ts
172
+ * import { wearLayout, wearPreset, type WearFeatures } from "@johnmorrisdotca/fuda-cards";
173
+ *
174
+ * const features: WearFeatures = wearLayout(wearPreset("moderately-played")!.levels, 2);
175
+ * console.log(features.front.scratches.length > 0); // true
176
+ * ```
177
+ */
79
178
  export interface WearFeatures {
80
179
  levels: WearLevels;
81
180
  /** Top left, top right, bottom right, bottom left of the front. */
@@ -92,12 +191,51 @@ export declare const CARD_W = 250;
92
191
  export declare const CARD_H = 350;
93
192
  /** The radius of a perfect card's corner in these units (15 px of 300). */
94
193
  export declare const BASE_RADIUS = 12.5;
95
- /** Where every mark of a card lies. A pure function of the levels and the seed: no DOM, nothing at random. */
194
+ /**
195
+ * Where every mark of a card lies. A pure function of the levels and the seed: no DOM, nothing at random, so the same seed lays the same marks every time.
196
+ *
197
+ * @param levels - How much of each kind of wear (see {@link wearLevels}).
198
+ * @param seed - The seed that lays the marks out. Unless said, 1.
199
+ * @returns The corners, centring and marks of both faces.
200
+ * @example
201
+ * ```ts
202
+ * import { wearLayout, wearPreset } from "@johnmorrisdotca/fuda-cards";
203
+ *
204
+ * const levels = wearPreset("heavily-played")!.levels;
205
+ * console.log(JSON.stringify(wearLayout(levels, 5)) === JSON.stringify(wearLayout(levels, 5))); // true
206
+ * ```
207
+ */
96
208
  export declare function wearLayout(levels: WearLevels, seed?: number): WearFeatures;
97
- /** The outline of a face as an SVG path in the 250 by 350 box, corners as worn. */
98
- export declare function wearOutline(features: WearFeatures, face?: 'front' | 'back'): string;
99
- /** The SVG laid over one face: whitening, folds, creases, scratches, specks, stain and toning. Markup only, no script. */
100
- export declare function wearOverlaySvg(features: WearFeatures, face?: 'front' | 'back'): string;
209
+ /**
210
+ * The outline of a face as an SVG path in the 250 by 350 box, corners as worn.
211
+ *
212
+ * @param features - The marks of the card (see {@link wearLayout}).
213
+ * @param face - Which face; the back's corners are the front's seen from behind. Unless said, the front.
214
+ * @returns The path's `d` attribute.
215
+ * @example
216
+ * ```ts
217
+ * import { wearLayout, wearOutline, wearPreset } from "@johnmorrisdotca/fuda-cards";
218
+ *
219
+ * const features = wearLayout(wearPreset("damaged")!.levels, 1);
220
+ * console.log(wearOutline(features).startsWith("M"), wearOutline(features, "back") !== wearOutline(features)); // true true
221
+ * ```
222
+ */
223
+ export declare function wearOutline(features: WearFeatures, face?: "front" | "back"): string;
224
+ /**
225
+ * The SVG laid over one face: whitening, folds, creases, scratches, specks, stain and toning. Markup only, no script.
226
+ *
227
+ * @param features - The marks of the card (see {@link wearLayout}).
228
+ * @param face - Which face. Unless said, the front.
229
+ * @returns The `<svg>` markup, in the 250 by 350 box.
230
+ * @example
231
+ * ```ts
232
+ * import { wearLayout, wearOverlaySvg, wearPreset } from "@johnmorrisdotca/fuda-cards";
233
+ *
234
+ * const svg = wearOverlaySvg(wearLayout(wearPreset("near-mint")!.levels));
235
+ * console.log(svg.startsWith("<svg"), /<script|onload/i.test(svg)); // true false
236
+ * ```
237
+ */
238
+ export declare function wearOverlaySvg(features: WearFeatures, face?: "front" | "back"): string;
101
239
  /** Draw a card's wear into its shadow root; calling it again with other options replaces the first. */
102
240
  export declare function applyWear(root: ShadowRoot, options: WearOptions): boolean;
103
241
  /** Take a card's wear away, leaving the card as it was. */