yuhwa 1.0.2 → 1.2.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/README.md +13 -12
- package/client.d.ts +9 -1
- package/dist/astro.d.ts +2 -2
- package/dist/astro.js +8 -1
- package/dist/browser.d.ts +11 -5
- package/dist/browser.js +27 -7
- package/dist/cli.js +612 -49
- package/dist/editor/assets/index-BphHLTvA.js +689 -0
- package/dist/editor/assets/lsp.worker-sZtzIA6-.js +30 -0
- package/dist/editor/index.html +5 -4
- package/dist/figure-CA2hy0xh.d.ts +48 -0
- package/dist/{index-Dl845tUQ.d.ts → index-CnnoZYl0.d.ts} +76 -7
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/ironmark.d.ts +4 -2
- package/dist/ironmark.js +18 -7
- package/dist/llms.txt +26 -17
- package/dist/lsp-browser.d.ts +2 -2
- package/dist/lsp-browser.js +1 -1
- package/dist/lsp-node.js +208 -212
- package/dist/lsp-server.d.ts +1 -1
- package/dist/lsp-server.js +1 -1
- package/dist/lsp.d.ts +44 -2
- package/dist/lsp.js +1 -1
- package/dist/markdown-it.d.ts +2 -1
- package/dist/markdown-it.js +7 -6
- package/dist/node-Bzn2uKXZ.js +224 -0
- package/dist/remark.d.ts +2 -1
- package/dist/remark.js +16 -5
- package/dist/{server-DJC_fQMe.d.ts → server--jHjJjOS.d.ts} +2 -2
- package/dist/{server-DmQuHQrG.js → server-Dxo7OG8K.js} +19 -2
- package/dist/{service-BYS9Qfkq.js → service-B1fpOg_L.js} +348 -44
- package/dist/{service-ClZ8clSQ.d.ts → service-Brvpt7Do.d.ts} +3 -1
- package/dist/{shared-qo_r6RUN.js → shared-Ddw88O9D.js} +3069 -742
- package/dist/{src-wk7tBpWs.js → src-DkQj7aIV.js} +2842 -744
- package/dist/style.css +14 -0
- package/dist/vite.d.ts +1 -1
- package/dist/vite.js +19 -12
- package/dist/vuepress.d.ts +3 -1
- package/dist/vuepress.js +7 -2
- package/dist/yuhwa.iife.js +91 -75
- package/dist/zoom-CCSUbX1X.d.ts +49 -0
- package/dist/zoom-QeqB6QlH.js +275 -0
- package/dist/zoom-script-CVdAzMhX.js +51 -0
- package/dist/zoom.d.ts +35 -0
- package/dist/zoom.js +19 -0
- package/package.json +10 -2
- package/dist/editor/assets/index-BQLsumas.js +0 -587
- package/dist/editor/assets/lsp.worker-RlPj9blG.js +0 -26
- package/dist/figure-BZHIKnxv.d.ts +0 -27
- package/dist/node-Bneu5eJV.js +0 -108
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pan and zoom for a rendered diagram: drag to move, Ctrl/⌘ + wheel or a
|
|
3
|
+
* pinch to zoom, double-click to zoom in, buttons in the corner, keys
|
|
4
|
+
* `+` `-` `0` and the arrows, and full screen.
|
|
5
|
+
*
|
|
6
|
+
* zoomable(document.querySelector('figure.yuhwa'), { height: '480px' })
|
|
7
|
+
*
|
|
8
|
+
* `zoomable` is self-contained on purpose: no imports and no module-level
|
|
9
|
+
* helpers, so `String(zoomable)` can be inlined into a page as a script
|
|
10
|
+
* (`yuhwa/zoom`'s `zoomScript`, `yuhwa render -o x.html`, `yuhwa serve`'s
|
|
11
|
+
* `/view` routes).
|
|
12
|
+
*/
|
|
13
|
+
interface ZoomOptions {
|
|
14
|
+
/** smallest zoom (default 1: the fitted diagram) */
|
|
15
|
+
min?: number;
|
|
16
|
+
/** largest zoom (default 8) */
|
|
17
|
+
max?: number;
|
|
18
|
+
/** fixed viewport height (any CSS length); the diagram is fitted inside it */
|
|
19
|
+
height?: string;
|
|
20
|
+
/**
|
|
21
|
+
* zoom with the plain wheel. Off by default, so the page still scrolls:
|
|
22
|
+
* then Ctrl/⌘ + wheel and trackpad pinches zoom, and the plain wheel pans
|
|
23
|
+
* only while zoomed in. Always on in full screen.
|
|
24
|
+
*/
|
|
25
|
+
wheel?: boolean;
|
|
26
|
+
/** the buttons in the corner (default `true`) */
|
|
27
|
+
controls?: boolean;
|
|
28
|
+
}
|
|
29
|
+
interface Zoomer {
|
|
30
|
+
/** current zoom, 1 = fitted */
|
|
31
|
+
readonly scale: number;
|
|
32
|
+
/** zoom by `factor` around a point in the element (default: its centre) */
|
|
33
|
+
zoom(factor: number, at?: {
|
|
34
|
+
x: number;
|
|
35
|
+
y: number;
|
|
36
|
+
}): void;
|
|
37
|
+
/** back to the fitted view */
|
|
38
|
+
reset(): void;
|
|
39
|
+
/** remove the viewer and put the diagram back as it was */
|
|
40
|
+
destroy(): void;
|
|
41
|
+
}
|
|
42
|
+
/** Make the diagram inside `host` pannable and zoomable. Calling it again replaces the earlier viewer. */
|
|
43
|
+
declare function zoomable(host: HTMLElement, opts?: ZoomOptions): Zoomer;
|
|
44
|
+
/**
|
|
45
|
+
* The `height` of a `zoom` flag or attribute: empty means the diagram's own
|
|
46
|
+
* height, a bare number means pixels, anything else is a CSS length.
|
|
47
|
+
*/
|
|
48
|
+
declare function zoomHeight(value: string | null | undefined): string | undefined;
|
|
49
|
+
export { zoomable as i, Zoomer as n, zoomHeight as r, ZoomOptions as t };
|
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
// src/zoom.ts
|
|
2
|
+
/** Make the diagram inside `host` pannable and zoomable. Calling it again replaces the earlier viewer. */
|
|
3
|
+
function zoomable(host, opts = {}) {
|
|
4
|
+
host.yuhwaZoom?.destroy();
|
|
5
|
+
const doc = host.ownerDocument;
|
|
6
|
+
const win = doc.defaultView ?? window;
|
|
7
|
+
if (!doc.getElementById("yuhwa-zoom-css")) {
|
|
8
|
+
const css = doc.createElement("style");
|
|
9
|
+
css.id = "yuhwa-zoom-css";
|
|
10
|
+
css.textContent = `
|
|
11
|
+
.yuhwa-zoom{position:relative;display:block;overflow:hidden;touch-action:pan-x pan-y;-webkit-user-select:none;user-select:none;outline:none}
|
|
12
|
+
.yuhwa-zoom:focus-visible{box-shadow:0 0 0 2px Highlight}
|
|
13
|
+
.yuhwa-zoom[data-zoomed]{cursor:grab;touch-action:none}
|
|
14
|
+
.yuhwa-zoom[data-dragging]{cursor:grabbing}
|
|
15
|
+
.yuhwa-zoom-stage{transform-origin:0 0}
|
|
16
|
+
.yuhwa-zoom-stage.yuhwa-zoom-anim{transition:transform .18s ease-out}
|
|
17
|
+
.yuhwa-zoom-fixed .yuhwa-zoom-stage,.yuhwa-zoom:fullscreen .yuhwa-zoom-stage{height:100%;display:flex;align-items:center;justify-content:center}
|
|
18
|
+
.yuhwa-zoom-fixed .yuhwa-zoom-stage :is(svg,img),.yuhwa-zoom:fullscreen .yuhwa-zoom-stage :is(svg,img){max-width:100%;max-height:100%;width:auto;height:auto}
|
|
19
|
+
.yuhwa-zoom:fullscreen{background:var(--yuhwa-zoom-bg,Canvas)}
|
|
20
|
+
.yuhwa-zoom-stage img{-webkit-user-drag:none}
|
|
21
|
+
.yuhwa-zoom-bar{position:absolute;top:8px;right:8px;display:flex;align-items:center;gap:2px;padding:3px;border-radius:8px;background:color-mix(in srgb,Canvas 86%,transparent);box-shadow:0 1px 4px rgba(0,0,0,.18);-webkit-backdrop-filter:blur(6px);backdrop-filter:blur(6px);opacity:0;transition:opacity .15s;font:500 12px/1 system-ui,sans-serif;color:CanvasText;cursor:default}
|
|
22
|
+
.yuhwa-zoom:hover .yuhwa-zoom-bar,.yuhwa-zoom:focus-within .yuhwa-zoom-bar,.yuhwa-zoom[data-zoomed] .yuhwa-zoom-bar{opacity:1}
|
|
23
|
+
@media (hover:none){.yuhwa-zoom-bar{opacity:1}}
|
|
24
|
+
.yuhwa-zoom-bar button{all:unset;box-sizing:border-box;min-width:28px;height:28px;padding:0 6px;display:grid;place-items:center;border-radius:6px;cursor:pointer;font-variant-numeric:tabular-nums}
|
|
25
|
+
.yuhwa-zoom-bar button:hover{background:color-mix(in srgb,CanvasText 10%,transparent)}
|
|
26
|
+
.yuhwa-zoom-bar button:focus-visible{outline:2px solid Highlight}
|
|
27
|
+
.yuhwa-zoom-bar button:disabled{opacity:.35;cursor:default;background:none}
|
|
28
|
+
.yuhwa-zoom-hint{position:absolute;left:50%;bottom:10px;transform:translateX(-50%);padding:5px 10px;border-radius:6px;background:rgba(20,20,20,.78);color:#fff;font:12px/1.3 system-ui,sans-serif;white-space:nowrap;pointer-events:none;opacity:0;transition:opacity .2s}
|
|
29
|
+
.yuhwa-zoom-hint[data-show]{opacity:1}
|
|
30
|
+
@media (prefers-reduced-motion:reduce){.yuhwa-zoom-stage.yuhwa-zoom-anim,.yuhwa-zoom-hint,.yuhwa-zoom-bar{transition:none}}`;
|
|
31
|
+
doc.head.append(css);
|
|
32
|
+
}
|
|
33
|
+
const min = opts.min ?? 1;
|
|
34
|
+
const max = Math.max(opts.max ?? 8, min);
|
|
35
|
+
let s = 1;
|
|
36
|
+
let x = 0;
|
|
37
|
+
let y = 0;
|
|
38
|
+
const addedTabIndex = !host.hasAttribute("tabindex");
|
|
39
|
+
const oldHeight = host.style.height;
|
|
40
|
+
host.classList.add("yuhwa-zoom");
|
|
41
|
+
if (opts.height) {
|
|
42
|
+
host.classList.add("yuhwa-zoom-fixed");
|
|
43
|
+
host.style.height = opts.height;
|
|
44
|
+
}
|
|
45
|
+
if (addedTabIndex) host.tabIndex = 0;
|
|
46
|
+
const stage = doc.createElement("div");
|
|
47
|
+
stage.className = "yuhwa-zoom-stage";
|
|
48
|
+
stage.append(...host.childNodes);
|
|
49
|
+
host.append(stage);
|
|
50
|
+
const icon = (d) => `<svg viewBox="0 0 16 16" width="14" height="14" aria-hidden="true"><path d="${d}" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round"/></svg>`;
|
|
51
|
+
const button = (label, html, onClick) => {
|
|
52
|
+
const b = doc.createElement("button");
|
|
53
|
+
b.type = "button";
|
|
54
|
+
b.title = label;
|
|
55
|
+
b.setAttribute("aria-label", label);
|
|
56
|
+
b.innerHTML = html;
|
|
57
|
+
b.addEventListener("click", (e) => {
|
|
58
|
+
e.stopPropagation();
|
|
59
|
+
onClick();
|
|
60
|
+
});
|
|
61
|
+
return b;
|
|
62
|
+
};
|
|
63
|
+
const bar = doc.createElement("div");
|
|
64
|
+
bar.className = "yuhwa-zoom-bar";
|
|
65
|
+
const minus = button("Zoom out (−)", icon("M3.5 8h9"), () => zoom(1 / 1.5, void 0, true));
|
|
66
|
+
const pct = button("Reset zoom (0)", "100%", () => reset());
|
|
67
|
+
const plus = button("Zoom in (+)", icon("M3.5 8h9M8 3.5v9"), () => zoom(1.5, void 0, true));
|
|
68
|
+
bar.append(minus, pct, plus);
|
|
69
|
+
if (!!(doc.fullscreenEnabled && host.requestFullscreen)) bar.append(button("Full screen", icon("M2.5 6V2.5H6M10 2.5h3.5V6M13.5 10v3.5H10M6 13.5H2.5V10"), () => doc.fullscreenElement === host ? doc.exitFullscreen() : host.requestFullscreen().catch(() => {})));
|
|
70
|
+
if (opts.controls !== false) host.append(bar);
|
|
71
|
+
const hint = doc.createElement("div");
|
|
72
|
+
hint.className = "yuhwa-zoom-hint";
|
|
73
|
+
hint.setAttribute("aria-hidden", "true");
|
|
74
|
+
hint.textContent = /Mac|iP/.test(win.navigator.platform) ? "Pinch or ⌘ + scroll to zoom" : "Ctrl + scroll to zoom";
|
|
75
|
+
host.append(hint);
|
|
76
|
+
let hintTimer = 0;
|
|
77
|
+
const showHint = () => {
|
|
78
|
+
hint.setAttribute("data-show", "");
|
|
79
|
+
win.clearTimeout(hintTimer);
|
|
80
|
+
hintTimer = win.setTimeout(() => hint.removeAttribute("data-show"), 1400);
|
|
81
|
+
};
|
|
82
|
+
const apply = (animate = false) => {
|
|
83
|
+
const w = host.clientWidth;
|
|
84
|
+
const h = host.clientHeight;
|
|
85
|
+
const ex = w - w * s;
|
|
86
|
+
const ey = h - h * s;
|
|
87
|
+
x = Math.min(Math.max(x, Math.min(0, ex)), Math.max(0, ex));
|
|
88
|
+
y = Math.min(Math.max(y, Math.min(0, ey)), Math.max(0, ey));
|
|
89
|
+
stage.classList.toggle("yuhwa-zoom-anim", animate);
|
|
90
|
+
stage.style.transform = s === 1 && !x && !y ? "" : `translate(${x}px, ${y}px) scale(${s})`;
|
|
91
|
+
host.toggleAttribute("data-zoomed", s > 1.001);
|
|
92
|
+
const label = `${Math.round(s * 100)}%`;
|
|
93
|
+
if (pct.textContent !== label) pct.textContent = label;
|
|
94
|
+
minus.disabled = s <= min + .001;
|
|
95
|
+
plus.disabled = s >= max - .001;
|
|
96
|
+
};
|
|
97
|
+
const zoom = (factor, at, animate = false) => {
|
|
98
|
+
const p = at ?? {
|
|
99
|
+
x: host.clientWidth / 2,
|
|
100
|
+
y: host.clientHeight / 2
|
|
101
|
+
};
|
|
102
|
+
const next = Math.min(max, Math.max(min, s * factor));
|
|
103
|
+
x = p.x - (p.x - x) * next / s;
|
|
104
|
+
y = p.y - (p.y - y) * next / s;
|
|
105
|
+
s = next;
|
|
106
|
+
apply(animate);
|
|
107
|
+
};
|
|
108
|
+
const reset = (animate = true) => {
|
|
109
|
+
s = 1;
|
|
110
|
+
x = y = 0;
|
|
111
|
+
apply(animate);
|
|
112
|
+
};
|
|
113
|
+
const local = (e) => {
|
|
114
|
+
const r = host.getBoundingClientRect();
|
|
115
|
+
return {
|
|
116
|
+
x: e.clientX - r.left,
|
|
117
|
+
y: e.clientY - r.top
|
|
118
|
+
};
|
|
119
|
+
};
|
|
120
|
+
const onWheel = (e) => {
|
|
121
|
+
const unit = e.deltaMode === 1 ? 16 : e.deltaMode === 2 ? host.clientHeight : 1;
|
|
122
|
+
const dx = e.deltaX * unit;
|
|
123
|
+
const dy = e.deltaY * unit;
|
|
124
|
+
if (e.ctrlKey || e.metaKey || opts.wheel || doc.fullscreenElement === host) {
|
|
125
|
+
e.preventDefault();
|
|
126
|
+
zoom(Math.exp(-dy * (Math.abs(dy) < 50 ? .01 : .002)), local(e));
|
|
127
|
+
} else if (s > 1.001) {
|
|
128
|
+
const ox = x;
|
|
129
|
+
const oy = y;
|
|
130
|
+
x -= dx;
|
|
131
|
+
y -= dy;
|
|
132
|
+
apply();
|
|
133
|
+
if (x !== ox || y !== oy) e.preventDefault();
|
|
134
|
+
} else if (Math.abs(dy) > Math.abs(dx)) showHint();
|
|
135
|
+
};
|
|
136
|
+
const points = /* @__PURE__ */ new Map();
|
|
137
|
+
let pinch = null;
|
|
138
|
+
let moved = 0;
|
|
139
|
+
const pinchState = () => {
|
|
140
|
+
const [a, b] = [...points.values()];
|
|
141
|
+
return {
|
|
142
|
+
d: Math.hypot(a.x - b.x, a.y - b.y) || 1,
|
|
143
|
+
x: (a.x + b.x) / 2,
|
|
144
|
+
y: (a.y + b.y) / 2
|
|
145
|
+
};
|
|
146
|
+
};
|
|
147
|
+
const onDown = (e) => {
|
|
148
|
+
if (e.pointerType === "mouse" && e.button !== 0 || bar.contains(e.target)) return;
|
|
149
|
+
if (points.size === 0) moved = 0;
|
|
150
|
+
points.set(e.pointerId, local(e));
|
|
151
|
+
if (points.size === 2) {
|
|
152
|
+
pinch = pinchState();
|
|
153
|
+
for (const id of points.keys()) host.setPointerCapture?.(id);
|
|
154
|
+
} else if (points.size === 1 && s > 1.001) {
|
|
155
|
+
host.setPointerCapture?.(e.pointerId);
|
|
156
|
+
host.setAttribute("data-dragging", "");
|
|
157
|
+
}
|
|
158
|
+
};
|
|
159
|
+
const onMove = (e) => {
|
|
160
|
+
const last = points.get(e.pointerId);
|
|
161
|
+
if (!last) return;
|
|
162
|
+
const p = local(e);
|
|
163
|
+
points.set(e.pointerId, p);
|
|
164
|
+
if (points.size >= 2 && pinch) {
|
|
165
|
+
const now = pinchState();
|
|
166
|
+
x += now.x - pinch.x;
|
|
167
|
+
y += now.y - pinch.y;
|
|
168
|
+
zoom(now.d / pinch.d, now);
|
|
169
|
+
moved += Math.abs(now.d - pinch.d) + Math.abs(now.x - pinch.x) + Math.abs(now.y - pinch.y);
|
|
170
|
+
pinch = now;
|
|
171
|
+
} else if (host.hasAttribute("data-dragging")) {
|
|
172
|
+
x += p.x - last.x;
|
|
173
|
+
y += p.y - last.y;
|
|
174
|
+
moved += Math.abs(p.x - last.x) + Math.abs(p.y - last.y);
|
|
175
|
+
apply();
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
const onUp = (e) => {
|
|
179
|
+
points.delete(e.pointerId);
|
|
180
|
+
pinch = points.size >= 2 ? pinchState() : null;
|
|
181
|
+
if (points.size === 0) host.removeAttribute("data-dragging");
|
|
182
|
+
};
|
|
183
|
+
const onClick = (e) => {
|
|
184
|
+
if (moved > 4 && !bar.contains(e.target)) {
|
|
185
|
+
e.preventDefault();
|
|
186
|
+
e.stopPropagation();
|
|
187
|
+
}
|
|
188
|
+
};
|
|
189
|
+
const onDblClick = (e) => {
|
|
190
|
+
if (bar.contains(e.target)) return;
|
|
191
|
+
e.preventDefault();
|
|
192
|
+
if (s >= max - .001) reset();
|
|
193
|
+
else zoom(2, local(e), true);
|
|
194
|
+
};
|
|
195
|
+
const onKey = (e) => {
|
|
196
|
+
if (e.target !== host || e.altKey || e.ctrlKey || e.metaKey) return;
|
|
197
|
+
const step = 60;
|
|
198
|
+
const moves = {
|
|
199
|
+
ArrowLeft: [step, 0],
|
|
200
|
+
ArrowRight: [-60, 0],
|
|
201
|
+
ArrowUp: [0, step],
|
|
202
|
+
ArrowDown: [0, -60]
|
|
203
|
+
};
|
|
204
|
+
if (e.key === "+" || e.key === "=") zoom(1.5, void 0, true);
|
|
205
|
+
else if (e.key === "-" || e.key === "_") zoom(1 / 1.5, void 0, true);
|
|
206
|
+
else if (e.key === "0") reset();
|
|
207
|
+
else if (moves[e.key] && s > 1.001) {
|
|
208
|
+
const ox = x;
|
|
209
|
+
const oy = y;
|
|
210
|
+
x += moves[e.key][0];
|
|
211
|
+
y += moves[e.key][1];
|
|
212
|
+
apply(true);
|
|
213
|
+
if (x === ox && y === oy) return;
|
|
214
|
+
} else return;
|
|
215
|
+
e.preventDefault();
|
|
216
|
+
};
|
|
217
|
+
const onDragStart = (e) => e.preventDefault();
|
|
218
|
+
const off = new AbortController();
|
|
219
|
+
const signal = off.signal;
|
|
220
|
+
host.addEventListener("wheel", onWheel, {
|
|
221
|
+
passive: false,
|
|
222
|
+
signal
|
|
223
|
+
});
|
|
224
|
+
host.addEventListener("pointerdown", onDown, { signal });
|
|
225
|
+
host.addEventListener("pointermove", onMove, { signal });
|
|
226
|
+
host.addEventListener("pointerup", onUp, { signal });
|
|
227
|
+
host.addEventListener("pointercancel", onUp, { signal });
|
|
228
|
+
host.addEventListener("click", onClick, {
|
|
229
|
+
capture: true,
|
|
230
|
+
signal
|
|
231
|
+
});
|
|
232
|
+
host.addEventListener("dblclick", onDblClick, { signal });
|
|
233
|
+
host.addEventListener("keydown", onKey, { signal });
|
|
234
|
+
host.addEventListener("dragstart", onDragStart, { signal });
|
|
235
|
+
doc.addEventListener("fullscreenchange", () => reset(false), { signal });
|
|
236
|
+
const resize = typeof ResizeObserver === "undefined" ? null : new ResizeObserver(() => apply());
|
|
237
|
+
resize?.observe(host);
|
|
238
|
+
apply();
|
|
239
|
+
const api = {
|
|
240
|
+
get scale() {
|
|
241
|
+
return s;
|
|
242
|
+
},
|
|
243
|
+
zoom: (factor, at) => zoom(factor, at, true),
|
|
244
|
+
reset: () => reset(),
|
|
245
|
+
destroy() {
|
|
246
|
+
off.abort();
|
|
247
|
+
resize?.disconnect();
|
|
248
|
+
win.clearTimeout(hintTimer);
|
|
249
|
+
bar.remove();
|
|
250
|
+
hint.remove();
|
|
251
|
+
if (stage.parentNode === host) {
|
|
252
|
+
host.append(...stage.childNodes);
|
|
253
|
+
stage.remove();
|
|
254
|
+
}
|
|
255
|
+
host.classList.remove("yuhwa-zoom", "yuhwa-zoom-fixed");
|
|
256
|
+
host.removeAttribute("data-zoomed");
|
|
257
|
+
host.removeAttribute("data-dragging");
|
|
258
|
+
host.style.height = oldHeight;
|
|
259
|
+
if (addedTabIndex) host.removeAttribute("tabindex");
|
|
260
|
+
delete host.yuhwaZoom;
|
|
261
|
+
}
|
|
262
|
+
};
|
|
263
|
+
host.yuhwaZoom = api;
|
|
264
|
+
return api;
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* The `height` of a `zoom` flag or attribute: empty means the diagram's own
|
|
268
|
+
* height, a bare number means pixels, anything else is a CSS length.
|
|
269
|
+
*/
|
|
270
|
+
function zoomHeight(value) {
|
|
271
|
+
const v = value?.trim();
|
|
272
|
+
if (!v || v === "true") return void 0;
|
|
273
|
+
return /^\d+(\.\d+)?$/.test(v) ? `${v}px` : v;
|
|
274
|
+
}
|
|
275
|
+
export { zoomable as n, zoomHeight as t };
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { n as zoomable } from "./zoom-QeqB6QlH.js";
|
|
2
|
+
// src/integrations/zoom-script.ts
|
|
3
|
+
/**
|
|
4
|
+
* Pan and zoom for figures rendered with `zoom`: every
|
|
5
|
+
* `[data-zoom] > .yuhwa-view` becomes a viewer (drag, Ctrl/⌘ + wheel, pinch,
|
|
6
|
+
* double-click, `+` `-` `0`, buttons and full screen). The figure's
|
|
7
|
+
* `data-zoom` value, when set, is the viewer's height. A MutationObserver
|
|
8
|
+
* picks up figures added later by client-side navigation, and figures whose
|
|
9
|
+
* viewer a framework threw away on hydration. It watches `document`, not
|
|
10
|
+
* `<html>`, because hydration can replace the `<html>` element.
|
|
11
|
+
*
|
|
12
|
+
* `make` is the viewer itself; `zoomScript` passes it in as an argument, so
|
|
13
|
+
* the string needs no imports.
|
|
14
|
+
*/
|
|
15
|
+
function installZoom(make = zoomable) {
|
|
16
|
+
const w = window;
|
|
17
|
+
if (w.__yuhwaZoom) return;
|
|
18
|
+
w.__yuhwaZoom = true;
|
|
19
|
+
const attach = () => {
|
|
20
|
+
document.querySelectorAll("[data-zoom] > .yuhwa-view").forEach((view) => {
|
|
21
|
+
if (view.yuhwaZoom && view.querySelector(":scope > .yuhwa-zoom-stage")) return;
|
|
22
|
+
make(view, { height: view.parentElement?.getAttribute("data-zoom") || void 0 });
|
|
23
|
+
});
|
|
24
|
+
};
|
|
25
|
+
let queued = false;
|
|
26
|
+
const later = () => {
|
|
27
|
+
if (queued) return;
|
|
28
|
+
queued = true;
|
|
29
|
+
requestAnimationFrame(() => {
|
|
30
|
+
queued = false;
|
|
31
|
+
attach();
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
if (document.readyState === "loading") document.addEventListener("DOMContentLoaded", attach, { once: true });
|
|
35
|
+
else attach();
|
|
36
|
+
addEventListener("load", later);
|
|
37
|
+
addEventListener("pageshow", later);
|
|
38
|
+
new MutationObserver((records) => {
|
|
39
|
+
if (records.some((r) => [...r.addedNodes].some((n) => n.nodeType === 1))) later();
|
|
40
|
+
}).observe(document, {
|
|
41
|
+
childList: true,
|
|
42
|
+
subtree: true
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* The same code as a string, for an inline `<script>` or a site's `head`.
|
|
47
|
+
* Squeezed: no blank lines (they would end a Markdown HTML block), and none of
|
|
48
|
+
* the code's strings hold two spaces in a row.
|
|
49
|
+
*/
|
|
50
|
+
const zoomScript = `(${installZoom})(${zoomable});`.replace(/\s*\n\s*/g, "\n").replace(/[ \t]{2,}/g, " ");
|
|
51
|
+
export { zoomScript as n, installZoom as t };
|
package/dist/zoom.d.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pan and zoom for diagrams rendered with `zoom: true` or a `zoom` fence flag.
|
|
3
|
+
* Import it once in the site's client code; it does nothing during server
|
|
4
|
+
* rendering.
|
|
5
|
+
*
|
|
6
|
+
* import 'yuhwa/zoom';
|
|
7
|
+
*
|
|
8
|
+
* Sites that only take a script string (a `head` option) use `zoomScript`:
|
|
9
|
+
*
|
|
10
|
+
* import { zoomScript } from 'yuhwa/zoom';
|
|
11
|
+
* head: { script: [{ innerHTML: zoomScript }] }
|
|
12
|
+
*
|
|
13
|
+
* `zoomable(element)` turns any element holding a diagram into a viewer.
|
|
14
|
+
*/
|
|
15
|
+
import { i as zoomable, n as Zoomer, r as zoomHeight, t as ZoomOptions } from "./zoom-CCSUbX1X.js";
|
|
16
|
+
/**
|
|
17
|
+
* Pan and zoom for figures rendered with `zoom`: every
|
|
18
|
+
* `[data-zoom] > .yuhwa-view` becomes a viewer (drag, Ctrl/⌘ + wheel, pinch,
|
|
19
|
+
* double-click, `+` `-` `0`, buttons and full screen). The figure's
|
|
20
|
+
* `data-zoom` value, when set, is the viewer's height. A MutationObserver
|
|
21
|
+
* picks up figures added later by client-side navigation, and figures whose
|
|
22
|
+
* viewer a framework threw away on hydration. It watches `document`, not
|
|
23
|
+
* `<html>`, because hydration can replace the `<html>` element.
|
|
24
|
+
*
|
|
25
|
+
* `make` is the viewer itself; `zoomScript` passes it in as an argument, so
|
|
26
|
+
* the string needs no imports.
|
|
27
|
+
*/
|
|
28
|
+
export declare function installZoom(make?: typeof zoomable): void;
|
|
29
|
+
/**
|
|
30
|
+
* The same code as a string, for an inline `<script>` or a site's `head`.
|
|
31
|
+
* Squeezed: no blank lines (they would end a Markdown HTML block), and none of
|
|
32
|
+
* the code's strings hold two spaces in a row.
|
|
33
|
+
*/
|
|
34
|
+
export declare const zoomScript: string;
|
|
35
|
+
export { type ZoomOptions, type Zoomer, zoomHeight, zoomable };
|
package/dist/zoom.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { n as zoomScript, t as installZoom } from "./zoom-script-CVdAzMhX.js";
|
|
2
|
+
import { n as zoomable, t as zoomHeight } from "./zoom-QeqB6QlH.js";
|
|
3
|
+
// src/integrations/zoom.ts
|
|
4
|
+
/**
|
|
5
|
+
* Pan and zoom for diagrams rendered with `zoom: true` or a `zoom` fence flag.
|
|
6
|
+
* Import it once in the site's client code; it does nothing during server
|
|
7
|
+
* rendering.
|
|
8
|
+
*
|
|
9
|
+
* import 'yuhwa/zoom';
|
|
10
|
+
*
|
|
11
|
+
* Sites that only take a script string (a `head` option) use `zoomScript`:
|
|
12
|
+
*
|
|
13
|
+
* import { zoomScript } from 'yuhwa/zoom';
|
|
14
|
+
* head: { script: [{ innerHTML: zoomScript }] }
|
|
15
|
+
*
|
|
16
|
+
* `zoomable(element)` turns any element holding a diagram into a viewer.
|
|
17
|
+
*/
|
|
18
|
+
if (typeof document !== "undefined") installZoom();
|
|
19
|
+
export { installZoom, zoomHeight, zoomScript, zoomable };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "yuhwa",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "Beautiful, hand-tunable text diagrams for Markdown and docs. A friendlier alternative to Mermaid.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"architecture",
|
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
"url": "git+https://github.com/ph1p/yuhwa.git"
|
|
23
23
|
},
|
|
24
24
|
"bin": {
|
|
25
|
+
"yu": "dist/cli.js",
|
|
25
26
|
"yuhwa": "dist/cli.js",
|
|
26
27
|
"yuhwa-lsp": "dist/lsp-node.js"
|
|
27
28
|
},
|
|
@@ -35,7 +36,9 @@
|
|
|
35
36
|
"./dist/yuhwa.iife.js",
|
|
36
37
|
"./dist/src-*.js",
|
|
37
38
|
"./src/index.ts",
|
|
38
|
-
"./src/setup.ts"
|
|
39
|
+
"./src/setup.ts",
|
|
40
|
+
"./dist/zoom.js",
|
|
41
|
+
"./src/integrations/zoom.ts"
|
|
39
42
|
],
|
|
40
43
|
"types": "./dist/index.d.ts",
|
|
41
44
|
"unpkg": "./dist/yuhwa.iife.js",
|
|
@@ -105,6 +108,11 @@
|
|
|
105
108
|
"types": "./dist/ironmark.d.ts",
|
|
106
109
|
"default": "./dist/ironmark.js"
|
|
107
110
|
},
|
|
111
|
+
"./zoom": {
|
|
112
|
+
"yuhwa-source": "./src/integrations/zoom.ts",
|
|
113
|
+
"types": "./dist/zoom.d.ts",
|
|
114
|
+
"default": "./dist/zoom.js"
|
|
115
|
+
},
|
|
108
116
|
"./style.css": {
|
|
109
117
|
"yuhwa-source": "./src/integrations/style.css",
|
|
110
118
|
"default": "./dist/style.css"
|