@tdacorp/hyle-sdk 0.17.0 → 0.21.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 +155 -28
- package/dist/check-routes-bin.js +38 -13
- package/dist/chunk-56Y24XBV.js +840 -0
- package/dist/{chunk-MGSUQBDW.js → chunk-75JFLML4.js} +176 -14
- package/dist/chunk-HJX57NLI.js +1105 -0
- package/dist/chunk-K5VDLROQ.js +145 -0
- package/dist/{chunk-BUJFMR3M.js → chunk-QVYQM5R2.js} +15 -6
- package/dist/chunk-U74B7AUG.js +398 -0
- package/dist/{chunk-6VOHFFA5.js → chunk-X2TLYM7Y.js} +2 -2
- package/dist/client-41fU6OY2.d.cts +201 -0
- package/dist/client-LwzHwqpM.d.ts +201 -0
- package/dist/code-copy.cjs +72 -0
- package/dist/code-copy.d.cts +15 -0
- package/dist/code-copy.d.ts +15 -0
- package/dist/code-copy.js +48 -0
- package/dist/comments.cjs +728 -275
- package/dist/comments.d.cts +66 -3
- package/dist/comments.d.ts +66 -3
- package/dist/comments.js +409 -326
- package/dist/{diagram-viewer-FJPED4SN.js → diagram-viewer-XY3CG75U.js} +62 -21
- package/dist/{embed-BmdwA2G9.d.cts → embed-BUFRQboD.d.ts} +2 -2
- package/dist/{embed-DNTZ2UXv.d.ts → embed-CYt-q13P.d.cts} +2 -2
- package/dist/fragment-alias.cjs +51 -0
- package/dist/fragment-alias.d.cts +7 -0
- package/dist/fragment-alias.d.ts +7 -0
- package/dist/fragment-alias.js +27 -0
- package/dist/html.cjs +881 -0
- package/dist/html.d.cts +20 -0
- package/dist/html.d.ts +20 -0
- package/dist/html.js +45 -0
- package/dist/index.cjs +181 -14
- package/dist/index.d.cts +14 -62
- package/dist/index.d.ts +14 -62
- package/dist/index.js +11 -1
- package/dist/{labels-nmukKYgL.d.ts → labels-CrA-iqTN.d.cts} +9 -0
- package/dist/{labels-nmukKYgL.d.cts → labels-CrA-iqTN.d.ts} +9 -0
- package/dist/mermaid-diagram.cjs +401 -125
- package/dist/mermaid-diagram.d.cts +23 -7
- package/dist/mermaid-diagram.d.ts +23 -7
- package/dist/mermaid-diagram.js +204 -51
- package/dist/mermaid-image.cjs +134 -60
- package/dist/mermaid-image.d.cts +4 -3
- package/dist/mermaid-image.d.ts +4 -3
- package/dist/mermaid-image.js +27 -28
- package/dist/next.cjs +627 -264
- package/dist/next.d.cts +11 -8
- package/dist/next.d.ts +11 -8
- package/dist/next.js +39 -12
- package/dist/print-coordinator.cjs +157 -0
- package/dist/print-coordinator.d.cts +27 -0
- package/dist/print-coordinator.d.ts +27 -0
- package/dist/print-coordinator.js +83 -0
- package/dist/react.cjs +556 -226
- package/dist/react.d.cts +136 -29
- package/dist/react.d.ts +136 -29
- package/dist/react.js +23 -3
- package/dist/reactions.cjs +653 -0
- package/dist/reactions.d.cts +27 -0
- package/dist/reactions.d.ts +27 -0
- package/dist/reactions.js +364 -0
- package/dist/{resolve-Ae7UFjsQ.d.ts → resolve-BjAK0k_Y.d.ts} +2 -2
- package/dist/{resolve-euZ4-aC9.d.cts → resolve-eI1muCKL.d.cts} +2 -2
- package/dist/revalidation-callback-BQl77tQR.d.cts +75 -0
- package/dist/revalidation-callback-BQl77tQR.d.ts +75 -0
- package/dist/sanitize-ijiWjEm9.d.cts +23 -0
- package/dist/sanitize-ijiWjEm9.d.ts +23 -0
- package/dist/styles.css +96 -25
- package/dist/toc-spy.cjs +59 -0
- package/dist/toc-spy.d.cts +15 -0
- package/dist/toc-spy.d.ts +15 -0
- package/dist/toc-spy.js +35 -0
- package/dist/{types-Czt887Iv.d.cts → types-3F0wqD-o.d.cts} +26 -2
- package/dist/{types-Czt887Iv.d.ts → types-3F0wqD-o.d.ts} +26 -2
- package/dist/use-cache.cjs +37 -11
- package/dist/use-cache.d.cts +12 -5
- package/dist/use-cache.d.ts +12 -5
- package/dist/use-cache.js +7 -7
- package/dist/youtube-facade.cjs +50 -0
- package/dist/youtube-facade.d.cts +17 -0
- package/dist/youtube-facade.d.ts +17 -0
- package/dist/youtube-facade.js +26 -0
- package/package.json +16 -3
- package/dist/chunk-DMK4XQLU.js +0 -1556
- package/dist/chunk-PJMJMP66.js +0 -63
- package/dist/revalidation-callback-D7Ms_Puz.d.cts +0 -42
- package/dist/revalidation-callback-D7Ms_Puz.d.ts +0 -42
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
fill
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-QVYQM5R2.js";
|
|
4
4
|
|
|
5
5
|
// src/react/viewer/diagram-viewer.tsx
|
|
6
6
|
import { useEffect, useId, useLayoutEffect, useMemo, useRef, useState } from "react";
|
|
@@ -70,7 +70,10 @@ function nearest(nodes, x, y) {
|
|
|
70
70
|
let d = GEOMETRY_SLACK;
|
|
71
71
|
for (const n of nodes) {
|
|
72
72
|
const nd = dist(n.box, x, y);
|
|
73
|
-
if (nd < d)
|
|
73
|
+
if (nd < d) {
|
|
74
|
+
d = nd;
|
|
75
|
+
best = n.key;
|
|
76
|
+
}
|
|
74
77
|
}
|
|
75
78
|
return best;
|
|
76
79
|
}
|
|
@@ -157,7 +160,10 @@ function walk(g, start, next, far) {
|
|
|
157
160
|
edges.add(i);
|
|
158
161
|
const other = far(g.edges[i]);
|
|
159
162
|
nodes.add(other);
|
|
160
|
-
if (!seen.has(other))
|
|
163
|
+
if (!seen.has(other)) {
|
|
164
|
+
seen.add(other);
|
|
165
|
+
queue.push(other);
|
|
166
|
+
}
|
|
161
167
|
}
|
|
162
168
|
}
|
|
163
169
|
return { nodes, edges };
|
|
@@ -170,7 +176,10 @@ function trace(g, key) {
|
|
|
170
176
|
function neighbourhood(g, key) {
|
|
171
177
|
const edges = /* @__PURE__ */ new Set([...g.out.get(key) ?? [], ...g.inn.get(key) ?? []]);
|
|
172
178
|
const nodes = /* @__PURE__ */ new Set([key]);
|
|
173
|
-
for (const i of edges)
|
|
179
|
+
for (const i of edges) {
|
|
180
|
+
nodes.add(g.edges[i].from);
|
|
181
|
+
nodes.add(g.edges[i].to);
|
|
182
|
+
}
|
|
174
183
|
return { nodes, edges };
|
|
175
184
|
}
|
|
176
185
|
var VEC = { up: [0, -1], down: [0, 1], left: [-1, 0], right: [1, 0] };
|
|
@@ -192,12 +201,18 @@ function pickNeighbour(g, key, dir) {
|
|
|
192
201
|
const across = Math.abs((x - cx) * vy - (y - cy) * vx);
|
|
193
202
|
if (along <= 0 || across > along * cone) continue;
|
|
194
203
|
const c = along + across * 2;
|
|
195
|
-
if (c < cost)
|
|
204
|
+
if (c < cost) {
|
|
205
|
+
cost = c;
|
|
206
|
+
pick = k;
|
|
207
|
+
}
|
|
196
208
|
}
|
|
197
209
|
return pick;
|
|
198
210
|
};
|
|
199
211
|
const adjacent = /* @__PURE__ */ new Set();
|
|
200
|
-
for (const i of [...g.out.get(key) ?? [], ...g.inn.get(key) ?? []])
|
|
212
|
+
for (const i of [...g.out.get(key) ?? [], ...g.inn.get(key) ?? []]) {
|
|
213
|
+
adjacent.add(g.edges[i].from);
|
|
214
|
+
adjacent.add(g.edges[i].to);
|
|
215
|
+
}
|
|
201
216
|
return best(adjacent, CONE) ?? best(adjacent, Infinity) ?? best(g.byKey.keys(), CONE);
|
|
202
217
|
}
|
|
203
218
|
function searchNodes(nodes, query) {
|
|
@@ -226,18 +241,25 @@ var escapeRe = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
|
226
241
|
var isTag = (segment) => !/^<style\b/i.test(segment);
|
|
227
242
|
function scopeSvg(svg, oldId, newId) {
|
|
228
243
|
if (!/^[\w-]+$/.test(oldId) || !/^[\w-]+$/.test(newId)) throw new Error("unsafe svg id");
|
|
244
|
+
const own = `${oldId}-`;
|
|
229
245
|
const token = new RegExp(`(?<![\\w-])${escapeRe(oldId)}(?![A-Za-z0-9-])`, "g");
|
|
230
246
|
const rooted = svg.replace(SEGMENT, (segment) => segment.replace(token, newId));
|
|
231
|
-
const
|
|
247
|
+
const ids = /* @__PURE__ */ new Set();
|
|
232
248
|
for (const segment of rooted.match(SEGMENT) ?? []) {
|
|
233
249
|
if (!isTag(segment)) continue;
|
|
234
|
-
for (const m of segment.matchAll(/\sid="([^"]*)"/g))
|
|
250
|
+
for (const m of segment.matchAll(/\sid="([^"]*)"/g)) ids.add(m[1]);
|
|
235
251
|
}
|
|
252
|
+
const stripped = (id) => id.startsWith(own) ? id.slice(own.length) : id;
|
|
253
|
+
const target = (id) => `${newId}_${stripped(id)}`;
|
|
254
|
+
const plain = [...ids].filter((id) => !id.startsWith(`${newId}_`) && id !== newId);
|
|
255
|
+
const claims = /* @__PURE__ */ new Map();
|
|
256
|
+
for (const id of plain) claims.set(target(id), (claims.get(target(id)) ?? 0) + 1);
|
|
257
|
+
const fresh = new Map(plain.map((id) => [id, ids.has(target(id)) || claims.get(target(id)) > 1 ? `${newId}_${id}` : target(id)]));
|
|
236
258
|
if (!fresh.size) return rooted;
|
|
237
259
|
const to = (id) => fresh.get(id) ?? id;
|
|
238
260
|
return rooted.replace(
|
|
239
261
|
SEGMENT,
|
|
240
|
-
(segment) => !isTag(segment) ? segment : segment.replace(/(\sid=")([^"]*)"/g, (_, a, id) => `${a}${to(id)}"`).replace(/url\(#([^)"'\s]+)\)/g, (_, id) => `url(#${to(id)})`).replace(/(\s(?:xlink:)?href=")#([^"]*)"/g, (_, a, id) => `${a}#${to(id)}"`).replace(/(\saria-(?:labelledby|describedby)=")([^"]*)"/g, (_, a,
|
|
262
|
+
(segment) => !isTag(segment) ? segment : segment.replace(/(\sid=")([^"]*)"/g, (_, a, id) => `${a}${to(id)}"`).replace(/url\(#([^)"'\s]+)\)/g, (_, id) => `url(#${to(id)})`).replace(/(\s(?:xlink:)?href=")#([^"]*)"/g, (_, a, id) => `${a}#${to(id)}"`).replace(/(\saria-(?:labelledby|describedby)=")([^"]*)"/g, (_, a, ids2) => `${a}${ids2.split(/\s+/).map(to).join(" ")}"`)
|
|
241
263
|
);
|
|
242
264
|
}
|
|
243
265
|
function svgSize(svg) {
|
|
@@ -497,7 +519,10 @@ var DiagramController = class {
|
|
|
497
519
|
n.el.setAttribute("aria-pressed", "false");
|
|
498
520
|
});
|
|
499
521
|
if (this.nodes[0]) this.roving = this.nodes[0].el;
|
|
500
|
-
for (const e of this.edges)
|
|
522
|
+
for (const e of this.edges) {
|
|
523
|
+
e.el.classList.add("hv-e");
|
|
524
|
+
e.labelEl?.classList.add("hv-e");
|
|
525
|
+
}
|
|
501
526
|
this.o.stage.classList.toggle("hv-plain", this.nodes.length > FADE_MAX_NODES);
|
|
502
527
|
}
|
|
503
528
|
// ---- view ---------------------------------------------------------------------------------------------------------------------------
|
|
@@ -756,13 +781,22 @@ var DiagramController = class {
|
|
|
756
781
|
for (const k of t.down) mark(at(k)?.el, "hv-down");
|
|
757
782
|
mark(at(this.pinned)?.el, "hv-sel");
|
|
758
783
|
const flow = t.upEdges.size + t.downEdges.size <= FLOW_MAX_EDGES ? ["hv-flow"] : [];
|
|
759
|
-
for (const i of t.upEdges)
|
|
760
|
-
|
|
784
|
+
for (const i of t.upEdges) {
|
|
785
|
+
mark(this.edges[i]?.el, "hv-up", ...flow);
|
|
786
|
+
mark(this.edges[i]?.labelEl, "hv-up");
|
|
787
|
+
}
|
|
788
|
+
for (const i of t.downEdges) {
|
|
789
|
+
mark(this.edges[i]?.el, "hv-down", ...flow);
|
|
790
|
+
mark(this.edges[i]?.labelEl, "hv-down");
|
|
791
|
+
}
|
|
761
792
|
} else if (g && this.hot) {
|
|
762
793
|
active = true;
|
|
763
794
|
const n = neighbourhood(g, this.hot);
|
|
764
795
|
for (const k of n.nodes) mark(at(k)?.el, k === this.hot ? "hv-sel" : "hv-nb");
|
|
765
|
-
for (const i of n.edges)
|
|
796
|
+
for (const i of n.edges) {
|
|
797
|
+
mark(this.edges[i]?.el, "hv-nb");
|
|
798
|
+
mark(this.edges[i]?.labelEl, "hv-nb");
|
|
799
|
+
}
|
|
766
800
|
} else if (this.query && this.hitEls.length) {
|
|
767
801
|
active = true;
|
|
768
802
|
for (const el of this.hitEls) mark(el);
|
|
@@ -970,6 +1004,7 @@ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
|
970
1004
|
var sequence = 0;
|
|
971
1005
|
var locks = 0;
|
|
972
1006
|
var LOCK_CLASS = "hyle-viewer-lock";
|
|
1007
|
+
var FULLSCREEN_CLASS = "hyle-viewer-fs";
|
|
973
1008
|
var SCALES = ["1", "2", "4"];
|
|
974
1009
|
var TOAST_MS = 4e3;
|
|
975
1010
|
var Glyph = ({ d }) => /* @__PURE__ */ jsx("svg", { className: "hv-ic", viewBox: "0 0 16 16", "aria-hidden": "true", children: /* @__PURE__ */ jsx("path", { d }) });
|
|
@@ -977,7 +1012,7 @@ var ICONS = {
|
|
|
977
1012
|
close: "m4 4 8 8M12 4l-8 8",
|
|
978
1013
|
fit: "M2.5 6V2.5H6M10 2.5h3.5V6M13.5 10v3.5H10M6 13.5H2.5V10",
|
|
979
1014
|
search: "M7 12.2A5.2 5.2 0 1 0 7 1.8a5.2 5.2 0 0 0 0 10.4zM11 11l3.2 3.2",
|
|
980
|
-
full: "
|
|
1015
|
+
full: "M9.5 2.5h4v4M13.5 2.5 9 7M6.5 13.5h-4v-4M2.5 13.5 7 9",
|
|
981
1016
|
exit: "M6 2.5V6H2.5M13.5 6H10V2.5M10 13.5V10h3.5M2.5 10H6v3.5"
|
|
982
1017
|
};
|
|
983
1018
|
function DiagramViewer({ svg, svgId, source, title, labels, onClose }) {
|
|
@@ -990,8 +1025,7 @@ function DiagramViewer({ svg, svgId, source, title, labels, onClose }) {
|
|
|
990
1025
|
const finder = useRef(null);
|
|
991
1026
|
const ctl = useRef(null);
|
|
992
1027
|
const labelsRef = useRef(labels);
|
|
993
|
-
|
|
994
|
-
const ownId = useRef(`hyle-viewer-${++sequence}`);
|
|
1028
|
+
const [ownId] = useState(() => `hyleViewer-${++sequence}`);
|
|
995
1029
|
const helpId = useId();
|
|
996
1030
|
const toastTimer = useRef(void 0);
|
|
997
1031
|
const downOnBackdrop = useRef(false);
|
|
@@ -1001,12 +1035,15 @@ function DiagramViewer({ svg, svgId, source, title, labels, onClose }) {
|
|
|
1001
1035
|
const [query, setQuery] = useState("");
|
|
1002
1036
|
const [scale, setScale] = useState("2");
|
|
1003
1037
|
const [fullscreen, setFullscreen] = useState(false);
|
|
1004
|
-
const scoped = useMemo(() => scopeSvg(svg, svgId, ownId
|
|
1038
|
+
const scoped = useMemo(() => scopeSvg(svg, svgId, ownId), [svg, svgId, ownId]);
|
|
1005
1039
|
const say = (message) => {
|
|
1006
1040
|
clearTimeout(toastTimer.current);
|
|
1007
1041
|
setToast(message);
|
|
1008
1042
|
toastTimer.current = setTimeout(() => setToast(""), TOAST_MS);
|
|
1009
1043
|
};
|
|
1044
|
+
useLayoutEffect(() => {
|
|
1045
|
+
labelsRef.current = labels;
|
|
1046
|
+
}, [labels]);
|
|
1010
1047
|
useLayoutEffect(() => {
|
|
1011
1048
|
const c = new DiagramController({
|
|
1012
1049
|
viewport: viewport.current,
|
|
@@ -1023,18 +1060,22 @@ function DiagramViewer({ svg, svgId, source, title, labels, onClose }) {
|
|
|
1023
1060
|
ctl.current = null;
|
|
1024
1061
|
};
|
|
1025
1062
|
}, []);
|
|
1026
|
-
useLayoutEffect(() => ctl.current?.show(scoped, `${ownId
|
|
1063
|
+
useLayoutEffect(() => ctl.current?.show(scoped, `${ownId}_`), [scoped, ownId]);
|
|
1027
1064
|
useEffect(() => {
|
|
1028
1065
|
const d = dialog.current;
|
|
1029
1066
|
if (!d.open) d.showModal();
|
|
1030
1067
|
if (locks++ === 0) document.documentElement.classList.add(LOCK_CLASS);
|
|
1031
1068
|
viewport.current?.focus({ preventScroll: true });
|
|
1032
|
-
const sync = () =>
|
|
1069
|
+
const sync = () => {
|
|
1070
|
+
const full = document.fullscreenElement === shell.current;
|
|
1071
|
+
setFullscreen(full);
|
|
1072
|
+
document.documentElement.classList.toggle(FULLSCREEN_CLASS, full);
|
|
1073
|
+
};
|
|
1033
1074
|
document.addEventListener("fullscreenchange", sync);
|
|
1034
1075
|
return () => {
|
|
1035
1076
|
document.removeEventListener("fullscreenchange", sync);
|
|
1036
1077
|
clearTimeout(toastTimer.current);
|
|
1037
|
-
if (--locks === 0) document.documentElement.classList.remove(LOCK_CLASS);
|
|
1078
|
+
if (--locks === 0) document.documentElement.classList.remove(LOCK_CLASS, FULLSCREEN_CLASS);
|
|
1038
1079
|
if (document.fullscreenElement && d.contains(document.fullscreenElement)) void document.exitFullscreen().catch(() => {
|
|
1039
1080
|
});
|
|
1040
1081
|
};
|
|
@@ -1141,7 +1182,7 @@ function DiagramViewer({ svg, svgId, source, title, labels, onClose }) {
|
|
|
1141
1182
|
/* @__PURE__ */ jsx("li", { className: "hv-down", children: labels.legendDownstream })
|
|
1142
1183
|
] }) : null,
|
|
1143
1184
|
/* @__PURE__ */ jsx("p", { className: "hv-hint", id: helpId, children: labels.hint }),
|
|
1144
|
-
/* @__PURE__ */ jsx("output", { className: "hv-toast",
|
|
1185
|
+
/* @__PURE__ */ jsx("output", { className: "hv-toast", children: toast })
|
|
1145
1186
|
] })
|
|
1146
1187
|
] })
|
|
1147
1188
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ElementType, ReactNode, ComponentType, ReactElement } from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { j as ResolvedArticle, L as ListItem } from './types-3F0wqD-o.js';
|
|
3
3
|
|
|
4
|
-
type CalloutKind = "note" | "tip" | "warning" | "caution";
|
|
4
|
+
type CalloutKind = "note" | "tip" | "important" | "warning" | "caution";
|
|
5
5
|
interface LinkProps {
|
|
6
6
|
href: string;
|
|
7
7
|
children?: ReactNode;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ElementType, ReactNode, ComponentType, ReactElement } from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { j as ResolvedArticle, L as ListItem } from './types-3F0wqD-o.cjs';
|
|
3
3
|
|
|
4
|
-
type CalloutKind = "note" | "tip" | "warning" | "caution";
|
|
4
|
+
type CalloutKind = "note" | "tip" | "important" | "warning" | "caution";
|
|
5
5
|
interface LinkProps {
|
|
6
6
|
href: string;
|
|
7
7
|
children?: ReactNode;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
"use client";
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
|
|
21
|
+
// src/react/fragment-alias.tsx
|
|
22
|
+
var fragment_alias_exports = {};
|
|
23
|
+
__export(fragment_alias_exports, {
|
|
24
|
+
FragmentAlias: () => FragmentAlias
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(fragment_alias_exports);
|
|
27
|
+
var import_react = require("react");
|
|
28
|
+
var PREFIX = "user-content-";
|
|
29
|
+
function FragmentAlias() {
|
|
30
|
+
(0, import_react.useEffect)(() => {
|
|
31
|
+
const redirect = () => {
|
|
32
|
+
const [page, hash] = [location.href.slice(0, location.href.length - location.hash.length), location.hash.slice(1)];
|
|
33
|
+
let ids;
|
|
34
|
+
try {
|
|
35
|
+
ids = [hash, decodeURIComponent(hash)];
|
|
36
|
+
} catch {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
const found = (prefix) => ids.some((id) => document.getElementById(prefix + id) !== null);
|
|
40
|
+
if (hash && !found("") && found(PREFIX)) location.replace(`${page}#${PREFIX}${hash}`);
|
|
41
|
+
};
|
|
42
|
+
redirect();
|
|
43
|
+
window.addEventListener("hashchange", redirect);
|
|
44
|
+
return () => window.removeEventListener("hashchange", redirect);
|
|
45
|
+
}, []);
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
49
|
+
0 && (module.exports = {
|
|
50
|
+
FragmentAlias
|
|
51
|
+
});
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Every id hyle emits is prefixed `user-content-`, but links shared before that (or typed by hand) say `#x`. When `#x` matches
|
|
3
|
+
* nothing and `#user-content-x` exists, the history entry is replaced with the latter, on load and on every hash change.
|
|
4
|
+
*/
|
|
5
|
+
declare function FragmentAlias(): null;
|
|
6
|
+
|
|
7
|
+
export { FragmentAlias };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Every id hyle emits is prefixed `user-content-`, but links shared before that (or typed by hand) say `#x`. When `#x` matches
|
|
3
|
+
* nothing and `#user-content-x` exists, the history entry is replaced with the latter, on load and on every hash change.
|
|
4
|
+
*/
|
|
5
|
+
declare function FragmentAlias(): null;
|
|
6
|
+
|
|
7
|
+
export { FragmentAlias };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
// src/react/fragment-alias.tsx
|
|
4
|
+
import { useEffect } from "react";
|
|
5
|
+
var PREFIX = "user-content-";
|
|
6
|
+
function FragmentAlias() {
|
|
7
|
+
useEffect(() => {
|
|
8
|
+
const redirect = () => {
|
|
9
|
+
const [page, hash] = [location.href.slice(0, location.href.length - location.hash.length), location.hash.slice(1)];
|
|
10
|
+
let ids;
|
|
11
|
+
try {
|
|
12
|
+
ids = [hash, decodeURIComponent(hash)];
|
|
13
|
+
} catch {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
const found = (prefix) => ids.some((id) => document.getElementById(prefix + id) !== null);
|
|
17
|
+
if (hash && !found("") && found(PREFIX)) location.replace(`${page}#${PREFIX}${hash}`);
|
|
18
|
+
};
|
|
19
|
+
redirect();
|
|
20
|
+
window.addEventListener("hashchange", redirect);
|
|
21
|
+
return () => window.removeEventListener("hashchange", redirect);
|
|
22
|
+
}, []);
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
export {
|
|
26
|
+
FragmentAlias
|
|
27
|
+
};
|