@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.
- package/LICENSE +21 -0
- package/NOTICE.md +16 -0
- package/README.md +106 -33
- package/dist/binder.d.ts +4 -6
- package/dist/binder.js +32 -23
- package/dist/card-markup.d.ts +2 -0
- package/dist/card-markup.js +59 -0
- package/dist/card-options.d.ts +131 -0
- package/dist/card-options.js +48 -0
- package/dist/card-styles.d.ts +2 -0
- package/dist/card-styles.js +314 -0
- package/dist/choice.d.ts +1 -1
- package/dist/choice.js +27 -23
- package/dist/collection-address.d.ts +8 -0
- package/dist/collection-address.js +52 -0
- package/dist/collection-binder-view.d.ts +9 -0
- package/dist/collection-binder-view.js +123 -0
- package/dist/collection-controls.d.ts +2 -0
- package/dist/collection-controls.js +143 -0
- package/dist/collection-deck.d.ts +11 -0
- package/dist/collection-deck.js +165 -0
- package/dist/collection-dialog.d.ts +2 -0
- package/dist/collection-dialog.js +28 -0
- package/dist/collection-element.d.ts +36 -67
- package/dist/collection-element.js +283 -484
- package/dist/collection-host.d.ts +5 -0
- package/dist/collection-host.js +1 -0
- package/dist/collection-icons.d.ts +3 -0
- package/dist/collection-icons.js +19 -0
- package/dist/collection-motion.d.ts +11 -0
- package/dist/collection-motion.js +72 -0
- package/dist/collection-styles.d.ts +4 -0
- package/dist/collection-styles.js +336 -0
- package/dist/collection-views.d.ts +8 -0
- package/dist/collection-views.js +8 -0
- package/dist/collection.d.ts +154 -11
- package/dist/collection.js +140 -34
- package/dist/element-define.d.ts +2 -0
- package/dist/element-define.js +3 -0
- package/dist/element.d.ts +20 -1
- package/dist/element.js +289 -98
- package/dist/index.d.ts +9 -52
- package/dist/index.js +5 -5
- package/dist/live-3d.d.ts +87 -4
- package/dist/live-3d.js +120 -52
- package/dist/materials.d.ts +117 -6
- package/dist/materials.js +246 -28
- package/dist/motion.d.ts +2 -0
- package/dist/motion.js +4 -0
- package/dist/pile-card.js +138 -91
- package/dist/pile.d.ts +61 -8
- package/dist/pile.js +89 -29
- package/dist/stack.d.ts +42 -6
- package/dist/stack.js +28 -3
- package/dist/version.d.ts +11 -0
- package/dist/version.js +11 -0
- package/dist/wear.d.ts +147 -9
- package/dist/wear.js +273 -89
- package/dist/zoom.d.ts +1 -1
- package/dist/zoom.js +73 -42
- package/docs/API.md +138 -134
- package/docs/collection-displays.md +4 -4
- package/docs/collection-input.md +5 -5
- package/docs/framework-integration.md +1 -1
- package/docs/guides/architecture.md +8 -8
- package/docs/guides/bundlers.md +60 -0
- package/docs/guides/card-element.md +26 -2
- package/docs/guides/collections.md +2 -2
- package/docs/guides/embed-in-an-iframe.md +39 -0
- package/docs/guides/frameworks.md +93 -66
- package/docs/guides/getting-started.md +4 -2
- package/docs/guides/html-and-cdn.md +86 -0
- package/docs/guides/ja/architecture.md +4 -4
- package/docs/guides/ja/bundlers.md +60 -0
- package/docs/guides/ja/card-element.md +26 -2
- package/docs/guides/ja/collections.md +2 -2
- package/docs/guides/ja/embed-in-an-iframe.md +39 -0
- package/docs/guides/ja/frameworks.md +93 -66
- package/docs/guides/ja/getting-started.md +4 -2
- package/docs/guides/ja/html-and-cdn.md +86 -0
- package/docs/guides/ja/live-3d.md +37 -24
- package/docs/guides/ja/materials-and-stacks.md +4 -4
- package/docs/guides/ja/troubleshooting.md +2 -2
- package/docs/guides/ja/typescript-and-node.md +45 -0
- package/docs/guides/ja/upgrading.md +7 -2
- package/docs/guides/ja/wear.md +1 -1
- package/docs/guides/live-3d.md +37 -24
- package/docs/guides/materials-and-stacks.md +4 -4
- package/docs/guides/troubleshooting.md +2 -2
- package/docs/guides/typescript-and-node.md +45 -0
- package/docs/guides/upgrading.md +7 -2
- package/docs/guides/wear.md +1 -1
- package/docs/live-3d.md +1 -18
- package/docs/materials.md +15 -11
- package/docs/wear.md +4 -12
- package/package.json +57 -10
package/dist/zoom.js
CHANGED
|
@@ -1,41 +1,58 @@
|
|
|
1
|
-
import
|
|
1
|
+
import "@johnmorrisdotca/kazoku-ui/view-controls/define";
|
|
2
2
|
const MARGIN = 12;
|
|
3
3
|
const ZOOMED = 1.05;
|
|
4
|
-
const TAPPABLE =
|
|
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(
|
|
11
|
-
controls.setAttribute(
|
|
12
|
-
controls.setAttribute(
|
|
13
|
-
controls.setAttribute(
|
|
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(
|
|
15
|
+
controls.setAttribute("theme", options.theme);
|
|
16
16
|
if (options.address)
|
|
17
|
-
controls.setAttribute(
|
|
17
|
+
controls.setAttribute("address", "");
|
|
18
18
|
(options.after ?? stage).after(controls);
|
|
19
19
|
controls.view = stage;
|
|
20
|
-
stage.style.userSelect =
|
|
21
|
-
stage.addEventListener(
|
|
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 = {
|
|
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() {
|
|
29
|
-
glide
|
|
30
|
-
|
|
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 =
|
|
48
|
+
view.style.transform = "none";
|
|
36
49
|
const origin = stage.getBoundingClientRect();
|
|
37
|
-
const left = origin.left + stage.clientLeft
|
|
38
|
-
|
|
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
|
|
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(
|
|
64
|
-
view.style.setProperty(
|
|
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(
|
|
95
|
+
controls.toggleAttribute("flat", !on);
|
|
78
96
|
draw(controls.state);
|
|
79
97
|
}
|
|
80
|
-
const EASE =
|
|
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 !==
|
|
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 =
|
|
95
|
-
const origin = stage.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
|
|
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(
|
|
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(
|
|
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(
|
|
146
|
+
controls.addEventListener("kazoku-viewchange", (e) => draw(e.detail));
|
|
127
147
|
new ResizeObserver(() => refresh()).observe(stage);
|
|
128
148
|
let queued = 0;
|
|
129
|
-
view.addEventListener(
|
|
130
|
-
|
|
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
|
|
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(
|
|
140
|
-
const target = e.isPrimary
|
|
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(
|
|
144
|
-
if (tap &&
|
|
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(
|
|
149
|
-
|
|
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();
|