@johnmorrisdotca/fuda-cards 0.10.1 → 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 (82) hide show
  1. package/LICENSE +21 -0
  2. package/NOTICE.md +14 -0
  3. package/README.md +89 -7
  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 +30 -65
  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 +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 +87 -4
  45. package/dist/live-3d.js +120 -52
  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 +121 -131
  62. package/docs/guides/bundlers.md +60 -0
  63. package/docs/guides/card-element.md +2 -2
  64. package/docs/guides/embed-in-an-iframe.md +39 -0
  65. package/docs/guides/frameworks.md +93 -66
  66. package/docs/guides/getting-started.md +3 -1
  67. package/docs/guides/html-and-cdn.md +69 -0
  68. package/docs/guides/ja/bundlers.md +60 -0
  69. package/docs/guides/ja/card-element.md +2 -2
  70. package/docs/guides/ja/embed-in-an-iframe.md +39 -0
  71. package/docs/guides/ja/frameworks.md +93 -66
  72. package/docs/guides/ja/getting-started.md +3 -1
  73. package/docs/guides/ja/html-and-cdn.md +69 -0
  74. package/docs/guides/ja/materials-and-stacks.md +3 -3
  75. package/docs/guides/ja/troubleshooting.md +2 -2
  76. package/docs/guides/ja/typescript-and-node.md +45 -0
  77. package/docs/guides/ja/upgrading.md +1 -1
  78. package/docs/guides/materials-and-stacks.md +3 -3
  79. package/docs/guides/troubleshooting.md +2 -2
  80. package/docs/guides/typescript-and-node.md +45 -0
  81. package/docs/guides/upgrading.md +1 -1
  82. package/package.json +57 -10
package/dist/zoom.js CHANGED
@@ -1,41 +1,58 @@
1
- import '@johnmorrisdotca/kazoku-ui/view-controls/define';
1
+ import "@johnmorrisdotca/kazoku-ui/view-controls/define";
2
2
  const MARGIN = 12;
3
3
  const ZOOMED = 1.05;
4
- const TAPPABLE = 'button:not(:disabled), a[href], [role=button]';
4
+ const TAPPABLE = "button:not(:disabled), a[href], [role=button]";
5
5
  /**
6
6
  * Zoom, Fit and pan for a flat view. `stage` clips, `view` is its absolutely positioned child that holds the items and is
7
7
  * moved and scaled. Fit shows every item at once; the reader's zoom and pan are never reset by a change of content.
8
8
  */
9
9
  export function zoomView(stage, view, options = {}) {
10
- const controls = document.createElement('kazoku-view-controls');
11
- controls.setAttribute('flat', '');
12
- controls.setAttribute('ignore', '');
13
- controls.setAttribute('zoom-min', '0.4');
10
+ const controls = document.createElement("kazoku-view-controls");
11
+ controls.setAttribute("flat", "");
12
+ controls.setAttribute("ignore", "");
13
+ controls.setAttribute("zoom-min", "0.4");
14
14
  if (options.theme)
15
- controls.setAttribute('theme', options.theme);
15
+ controls.setAttribute("theme", options.theme);
16
16
  if (options.address)
17
- controls.setAttribute('address', '');
17
+ controls.setAttribute("address", "");
18
18
  (options.after ?? stage).after(controls);
19
19
  controls.view = stage;
20
- stage.style.userSelect = 'none';
21
- stage.addEventListener('dragstart', e => e.preventDefault());
20
+ stage.style.userSelect = "none";
21
+ stage.addEventListener("dragstart", (e) => e.preventDefault());
22
22
  let box = { w: 0, h: 0, cx: 0, cy: 0, bw: 0, bh: 0 };
23
23
  let fit = 1;
24
24
  let turnable = false;
25
- const self = { controls, minOpen: 0, items: options.items ?? '.card', refresh, reset: () => refresh(true), zoomed: () => controls.state.zoom > ZOOMED, setTurnable, animated, reveal, turned: () => turnable && Boolean(controls.state.yaw || controls.state.tilt) };
25
+ const self = {
26
+ controls,
27
+ minOpen: 0,
28
+ items: options.items ?? ".card",
29
+ refresh,
30
+ reset: () => refresh(true),
31
+ zoomed: () => controls.state.zoom > ZOOMED,
32
+ setTurnable,
33
+ animated,
34
+ reveal,
35
+ turned: () => turnable && Boolean(controls.state.yaw || controls.state.tilt),
36
+ };
26
37
  let glide;
27
38
  /** A glide that is still running would be measured as if it were the layout, so a new measure ends it first. */
28
- function settleGlide() { if (glide) {
29
- glide.cancel();
30
- glide = undefined;
31
- } }
39
+ function settleGlide() {
40
+ if (glide) {
41
+ glide.cancel();
42
+ glide = undefined;
43
+ }
44
+ }
32
45
  function measure() {
33
46
  settleGlide();
34
47
  const previous = view.style.transform;
35
- view.style.transform = 'none';
48
+ view.style.transform = "none";
36
49
  const origin = stage.getBoundingClientRect();
37
- const left = origin.left + stage.clientLeft, top = origin.top + stage.clientTop;
38
- let x0 = Infinity, y0 = Infinity, x1 = -Infinity, y1 = -Infinity;
50
+ const left = origin.left + stage.clientLeft;
51
+ const top = origin.top + stage.clientTop;
52
+ let x0 = Infinity;
53
+ let y0 = Infinity;
54
+ let x1 = -Infinity;
55
+ let y1 = -Infinity;
39
56
  for (const item of Array.from(view.querySelectorAll(self.items))) {
40
57
  const r = item.getBoundingClientRect();
41
58
  if (!r.width || !r.height)
@@ -46,7 +63,8 @@ export function zoomView(stage, view, options = {}) {
46
63
  y1 = Math.max(y1, r.bottom - top);
47
64
  }
48
65
  view.style.transform = previous;
49
- const w = stage.clientWidth, h = stage.clientHeight;
66
+ const w = stage.clientWidth;
67
+ const h = stage.clientHeight;
50
68
  if (x0 > x1) {
51
69
  x0 = 0;
52
70
  y0 = 0;
@@ -58,10 +76,10 @@ export function zoomView(stage, view, options = {}) {
58
76
  function draw(state) {
59
77
  const scale = fit * state.zoom;
60
78
  view.style.transformOrigin = `${box.cx}px ${box.cy}px`;
61
- const turn = turnable ? ` rotateX(${state.tilt ?? 0}deg) rotateY(${state.yaw ?? 0}deg)` : '';
79
+ const turn = turnable ? ` rotateX(${state.tilt ?? 0}deg) rotateY(${state.yaw ?? 0}deg)` : "";
62
80
  // The turn, for the items that must stay square to the reader (they turn the other way by this much).
63
- view.style.setProperty('--fuda-yaw', turnable ? String(state.yaw ?? 0) : '0');
64
- view.style.setProperty('--fuda-tilt', turnable ? String(state.tilt ?? 0) : '0');
81
+ view.style.setProperty("--fuda-yaw", turnable ? String(state.yaw ?? 0) : "0");
82
+ view.style.setProperty("--fuda-tilt", turnable ? String(state.tilt ?? 0) : "0");
65
83
  view.style.transform = `translate(${box.w / 2 - box.cx + state.panX}px,${box.h / 2 - box.cy + state.panY}px) scale(${scale})${turn}`;
66
84
  }
67
85
  function setTurnable(on, never = false) {
@@ -74,15 +92,15 @@ export function zoomView(stage, view, options = {}) {
74
92
  turnable = on;
75
93
  if (!on)
76
94
  controls.set({ yaw: 0, tilt: 0 });
77
- controls.toggleAttribute('flat', !on);
95
+ controls.toggleAttribute("flat", !on);
78
96
  draw(controls.state);
79
97
  }
80
- const EASE = 'cubic-bezier(.2,.8,.2,1)';
98
+ const EASE = "cubic-bezier(.2,.8,.2,1)";
81
99
  function animated(change, ms) {
82
- const from = ms > 0 ? getComputedStyle(view).transform : '';
100
+ const from = ms > 0 ? getComputedStyle(view).transform : "";
83
101
  change();
84
102
  const to = view.style.transform;
85
- if (ms > 0 && from && from !== 'none' && to && from !== to) {
103
+ if (ms > 0 && from && from !== "none" && to && from !== to) {
86
104
  settleGlide();
87
105
  glide = view.animate([{ transform: from }, { transform: to }], { duration: ms, easing: EASE });
88
106
  }
@@ -91,13 +109,15 @@ export function zoomView(stage, view, options = {}) {
91
109
  animated(() => {
92
110
  measure();
93
111
  const previous = view.style.transform;
94
- view.style.transform = 'none';
95
- const origin = stage.getBoundingClientRect(), r = item.getBoundingClientRect();
112
+ view.style.transform = "none";
113
+ const origin = stage.getBoundingClientRect();
114
+ const r = item.getBoundingClientRect();
96
115
  view.style.transform = previous;
97
116
  if (!r.width)
98
117
  return;
99
118
  const s = fit * controls.state.zoom;
100
- const px = r.left + r.width / 2 - origin.left - stage.clientLeft, py = r.top + r.height / 2 - origin.top - stage.clientTop;
119
+ const px = r.left + r.width / 2 - origin.left - stage.clientLeft;
120
+ const py = r.top + r.height / 2 - origin.top - stage.clientTop;
101
121
  controls.set({ panX: -s * (px - box.cx), panY: -s * (py - box.cy) });
102
122
  draw(controls.state);
103
123
  }, ms);
@@ -109,44 +129,55 @@ export function zoomView(stage, view, options = {}) {
109
129
  fit = Math.min(1, (box.w - 2 * MARGIN) / (box.bw || 1), (box.h - 2 * MARGIN) / (box.bh || 1));
110
130
  if (!(fit > 0))
111
131
  fit = 1;
112
- controls.setAttribute('zoom-max', String(Math.max(5, Math.ceil(2 / fit))));
132
+ controls.setAttribute("zoom-max", String(Math.max(5, Math.ceil(2 / fit))));
113
133
  const atOpening = Math.abs(controls.state.zoom - controls.controller.startZoom) < 1e-6;
114
134
  controls.setFitScale(fit);
115
135
  if (open || atOpening) {
116
136
  const scale = Math.max(fit, Math.min(1, self.minOpen));
117
- controls.setAttribute('zoom', String(scale));
137
+ controls.setAttribute("zoom", String(scale));
118
138
  const s = fit * controls.state.zoom;
119
139
  controls.set({
120
140
  panX: box.bw * s > box.w - 2 * MARGIN ? MARGIN - box.w / 2 + (box.bw * s) / 2 : 0,
121
- panY: box.bh * s > box.h - 2 * MARGIN ? MARGIN - box.h / 2 + (box.bh * s) / 2 : 0
141
+ panY: box.bh * s > box.h - 2 * MARGIN ? MARGIN - box.h / 2 + (box.bh * s) / 2 : 0,
122
142
  });
123
143
  }
124
144
  draw(controls.state);
125
145
  }
126
- controls.addEventListener('kazoku-viewchange', e => draw(e.detail));
146
+ controls.addEventListener("kazoku-viewchange", (e) => draw(e.detail));
127
147
  new ResizeObserver(() => refresh()).observe(stage);
128
148
  let queued = 0;
129
- view.addEventListener('transitionend', () => { cancelAnimationFrame(queued); queued = requestAnimationFrame(() => refresh()); });
130
- stage.addEventListener('wheel', e => {
149
+ view.addEventListener("transitionend", () => {
150
+ cancelAnimationFrame(queued);
151
+ queued = requestAnimationFrame(() => refresh());
152
+ });
153
+ stage.addEventListener("wheel", (e) => {
131
154
  if (e.ctrlKey || e.metaKey || !self.zoomed())
132
155
  return;
133
156
  e.preventDefault();
134
- const k = e.deltaMode === 1 ? 16 : 1, s = controls.state;
157
+ const k = e.deltaMode === 1 ? 16 : 1;
158
+ const s = controls.state;
135
159
  controls.set({ panX: s.panX - e.deltaX * k, panY: s.panY - e.deltaY * k });
136
160
  }, { passive: false });
137
161
  // The controls take every press on the stage, so a drag or a pinch works over the items too. A tap that did not move is passed on as a click.
138
162
  let tap = null;
139
- stage.addEventListener('pointerdown', e => {
140
- const target = e.isPrimary ? e.composedPath().find((n) => n instanceof HTMLElement && n !== stage && n.matches(TAPPABLE)) : undefined;
163
+ stage.addEventListener("pointerdown", (e) => {
164
+ const target = e.isPrimary
165
+ ? e.composedPath().find((n) => n instanceof HTMLElement && n !== stage && n.matches(TAPPABLE))
166
+ : undefined;
141
167
  tap = target ? { id: e.pointerId, x: e.clientX, y: e.clientY, at: e.timeStamp, target } : null;
142
168
  }, true);
143
- stage.addEventListener('pointerup', e => {
144
- if (tap && e.pointerId === tap.id && Math.hypot(e.clientX - tap.x, e.clientY - tap.y) < 10 && e.timeStamp - tap.at < 800)
169
+ stage.addEventListener("pointerup", (e) => {
170
+ if (tap &&
171
+ e.pointerId === tap.id &&
172
+ Math.hypot(e.clientX - tap.x, e.clientY - tap.y) < 10 &&
173
+ e.timeStamp - tap.at < 800)
145
174
  tap.target.click();
146
175
  tap = null;
147
176
  });
148
- stage.addEventListener('pointercancel', () => { tap = null; });
149
- stage.addEventListener('click', e => {
177
+ stage.addEventListener("pointercancel", () => {
178
+ tap = null;
179
+ });
180
+ stage.addEventListener("click", (e) => {
150
181
  if (e.isTrusted && e.detail > 0) {
151
182
  e.stopImmediatePropagation();
152
183
  e.preventDefault();