@inkandswitch/patchwork-pkg-base 0.0.65 → 0.0.67
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/module-settings-url +1 -0
- package/package.json +2 -1
- package/packages/codemirror-markdown/example.js +1 -2
- package/packages/drafts/dist/assets/{DraftOverlayProvider-VYKlzOy1.js → DraftOverlayProvider-D2vIz7hy.js} +2 -3
- package/packages/drafts/dist/assets/{DraftOverlayProvider-VYKlzOy1.js.map → DraftOverlayProvider-D2vIz7hy.js.map} +1 -1
- package/packages/drafts/dist/assets/{DraftStateProvider-DX8b_RgQ.js → DraftStateProvider-Bhz0S4c1.js} +212 -87
- package/packages/drafts/dist/assets/DraftStateProvider-Bhz0S4c1.js.map +1 -0
- package/packages/drafts/dist/assets/{draft-docs-Bi8K1y3a.js → draft-docs-DyJ2l14d.js} +108 -99
- package/packages/drafts/dist/assets/draft-docs-DyJ2l14d.js.map +1 -0
- package/packages/drafts/dist/assets/{main-EEciTwbZ.js → main-CG9HOCai.js} +14 -10
- package/packages/drafts/dist/assets/main-CG9HOCai.js.map +1 -0
- package/packages/drafts/dist/index.js +9 -9
- package/packages/drafts/package.json +5 -5
- package/packages/sideboard/dist/{chunk-KHS2XJKP.js → chunk-6POQCUBB.js} +3 -3
- package/packages/sideboard/dist/{chunk-TXFTRSLY.js → chunk-DS3QVJZT.js} +3 -3
- package/packages/sideboard/dist/chunk-DS3QVJZT.js.map +7 -0
- package/packages/sideboard/dist/{create-new-menu-EU5KJJ3R.js → create-new-menu-VA4ELRJ6.js} +2 -2
- package/packages/sideboard/dist/document-list-panel-GHYN6JR5.js +2 -0
- package/packages/sideboard/dist/index.js +1 -1
- package/packages/sideboard/dist/sideboard/sideboard.js +1 -1
- package/packages/tldraw4/dist/{chunk-IKZWERSR.js → chunk-G3PMV62Z.js} +1 -3
- package/packages/tldraw4/dist/{chunk-7CJQMVDI.js → chunk-PMHAL5YM.js} +4 -4
- package/packages/tldraw4/dist/datatype.js +2 -2
- package/packages/tldraw4/dist/main.js +1 -1
- package/packages/tldraw4/dist/{sanitizeSvg-OOYBXUQ2.js → sanitizeSvg-NCGPTJ3E.js} +2 -2
- package/packages/tldraw4/dist/tool.js +450 -5675
- package/packages/tldraw4/dist/tool.js.map +4 -4
- package/packages/tldraw4/package.json +0 -1
- package/packages/tldraw5/dist/{chunk-GKLJTYCF.js → chunk-DO47QRII.js} +1 -3
- package/packages/tldraw5/dist/{chunk-4JN3PIR7.js → chunk-FTKY6DDS.js} +3 -3
- package/packages/tldraw5/dist/{chunk-JDHJ334K.js → chunk-SZI4VCOI.js} +4 -4
- package/packages/tldraw5/dist/datatype.js +3 -3
- package/packages/tldraw5/dist/main.js +1 -1
- package/packages/tldraw5/dist/{sanitizeSvg-3EKLLIYO.js → sanitizeSvg-J7F3MQGT.js} +2 -2
- package/packages/tldraw5/dist/{script-VW3AAU5T.js → script-4RKE5JKT.js} +3 -3
- package/packages/tldraw5/dist/script-4RKE5JKT.js.map +7 -0
- package/packages/tldraw5/dist/{tldr-archive-WERHN3T4.js → tldr-archive-5X7EMHWZ.js} +3 -3
- package/packages/tldraw5/dist/tool.js +293 -1543
- package/packages/tldraw5/dist/tool.js.map +4 -4
- package/packages/tldraw5/package.json +0 -1
- package/plugin-registry-url +1 -0
- package/packages/drafts/dist/assets/DraftStateProvider-DX8b_RgQ.js.map +0 -1
- package/packages/drafts/dist/assets/draft-docs-Bi8K1y3a.js.map +0 -1
- package/packages/drafts/dist/assets/index-FKZtof6Z.js +0 -67
- package/packages/drafts/dist/assets/index-FKZtof6Z.js.map +0 -1
- package/packages/drafts/dist/assets/main-EEciTwbZ.js.map +0 -1
- package/packages/sideboard/dist/chunk-TXFTRSLY.js.map +0 -7
- package/packages/sideboard/dist/document-list-panel-WDIVYTZU.js +0 -2
- package/packages/tldraw5/dist/script-VW3AAU5T.js.map +0 -7
- /package/packages/sideboard/dist/{chunk-KHS2XJKP.js.map → chunk-6POQCUBB.js.map} +0 -0
- /package/packages/sideboard/dist/{create-new-menu-EU5KJJ3R.js.map → create-new-menu-VA4ELRJ6.js.map} +0 -0
- /package/packages/sideboard/dist/{document-list-panel-WDIVYTZU.js.map → document-list-panel-GHYN6JR5.js.map} +0 -0
- /package/packages/tldraw4/dist/{chunk-IKZWERSR.js.map → chunk-G3PMV62Z.js.map} +0 -0
- /package/packages/tldraw4/dist/{chunk-7CJQMVDI.js.map → chunk-PMHAL5YM.js.map} +0 -0
- /package/packages/tldraw4/dist/{sanitizeSvg-OOYBXUQ2.js.map → sanitizeSvg-NCGPTJ3E.js.map} +0 -0
- /package/packages/tldraw5/dist/{chunk-GKLJTYCF.js.map → chunk-DO47QRII.js.map} +0 -0
- /package/packages/tldraw5/dist/{chunk-4JN3PIR7.js.map → chunk-FTKY6DDS.js.map} +0 -0
- /package/packages/tldraw5/dist/{chunk-JDHJ334K.js.map → chunk-SZI4VCOI.js.map} +0 -0
- /package/packages/tldraw5/dist/{sanitizeSvg-3EKLLIYO.js.map → sanitizeSvg-J7F3MQGT.js.map} +0 -0
- /package/packages/tldraw5/dist/{tldr-archive-WERHN3T4.js.map → tldr-archive-5X7EMHWZ.js.map} +0 -0
|
@@ -2,7 +2,7 @@ import {
|
|
|
2
2
|
applyTLStoreChangesToAutomerge,
|
|
3
3
|
getTitle,
|
|
4
4
|
require_lodash
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-FTKY6DDS.js";
|
|
6
6
|
import {
|
|
7
7
|
DefaultMainMenu,
|
|
8
8
|
DefaultMainMenuContent,
|
|
@@ -41,38 +41,16 @@ import {
|
|
|
41
41
|
useToasts,
|
|
42
42
|
useValue,
|
|
43
43
|
validation_exports
|
|
44
|
-
} from "./chunk-
|
|
44
|
+
} from "./chunk-SZI4VCOI.js";
|
|
45
45
|
import "./chunk-HNSBWAQA.js";
|
|
46
46
|
import {
|
|
47
|
-
__export,
|
|
48
|
-
__reExport,
|
|
49
47
|
__toESM
|
|
50
|
-
} from "./chunk-
|
|
48
|
+
} from "./chunk-DO47QRII.js";
|
|
51
49
|
|
|
52
50
|
// src/tool.tsx
|
|
53
51
|
import { decodeHeads } from "@automerge/automerge-repo/slim";
|
|
54
52
|
|
|
55
|
-
// node_modules/.pnpm/@automerge+react@2.6.0-subduction.
|
|
56
|
-
var dist_exports = {};
|
|
57
|
-
__export(dist_exports, {
|
|
58
|
-
BroadcastChannelNetworkAdapter: () => BroadcastChannelNetworkAdapter,
|
|
59
|
-
IndexedDBStorageAdapter: () => IndexedDBStorageAdapter,
|
|
60
|
-
MessageChannelNetworkAdapter: () => MessageChannelNetworkAdapter,
|
|
61
|
-
RepoContext: () => RepoContext,
|
|
62
|
-
WebSocketClientAdapter: () => WebSocketClientAdapter,
|
|
63
|
-
useDocHandle: () => useDocHandle,
|
|
64
|
-
useDocHandles: () => useDocHandles,
|
|
65
|
-
useDocument: () => useDocument,
|
|
66
|
-
useDocuments: () => useDocuments,
|
|
67
|
-
useLocalAwareness: () => useLocalAwareness,
|
|
68
|
-
usePresence: () => usePresence,
|
|
69
|
-
useRemoteAwareness: () => useRemoteAwareness,
|
|
70
|
-
useRepo: () => useRepo
|
|
71
|
-
});
|
|
72
|
-
__reExport(dist_exports, automerge_repo_star);
|
|
73
|
-
import * as automerge_repo_star from "@automerge/automerge-repo";
|
|
74
|
-
|
|
75
|
-
// node_modules/.pnpm/@automerge+automerge-repo-react-hooks@2.6.0-subduction.47_react-dom@18.3.1_react@18.3.1_6df4f690027be2800278543489b1f96f/node_modules/@automerge/automerge-repo-react-hooks/dist/index.js
|
|
53
|
+
// node_modules/.pnpm/@automerge+automerge-repo-react-hooks@2.6.0-subduction.46_react-dom@18.3.1_react@18.3.1_4b92195feb6ea50576810c4c883087b2/node_modules/@automerge/automerge-repo-react-hooks/dist/index.js
|
|
76
54
|
var import_react = __toESM(require_react(), 1);
|
|
77
55
|
import { PeerStateView, Presence } from "@automerge/automerge-repo/slim";
|
|
78
56
|
var __create = Object.create;
|
|
@@ -661,1428 +639,46 @@ var keyCodec = {
|
|
|
661
639
|
[KIND]: "key",
|
|
662
640
|
key: decodeURIComponent(s)
|
|
663
641
|
};
|
|
664
|
-
},
|
|
665
|
-
serialize: (seg) => {
|
|
666
|
-
if (seg.key === "") throw new Error("Path keys cannot be empty strings");
|
|
667
|
-
const needsEscape = ESCAPE_TRIGGERS.some((p) => seg.key.startsWith(p));
|
|
668
|
-
const encoded = encodeURIComponent(seg.key);
|
|
669
|
-
return needsEscape ? `${ESCAPE_PREFIX}${encoded}` : encoded;
|
|
670
|
-
}
|
|
671
|
-
};
|
|
672
|
-
function safeDecodeURIComponent(s) {
|
|
673
|
-
try {
|
|
674
|
-
return decodeURIComponent(s);
|
|
675
|
-
} catch {
|
|
676
|
-
return s;
|
|
677
|
-
}
|
|
678
|
-
}
|
|
679
|
-
var SEGMENT_CODECS = [
|
|
680
|
-
indexCodec,
|
|
681
|
-
matchCodec,
|
|
682
|
-
cursorsCodec,
|
|
683
|
-
keyCodec
|
|
684
|
-
];
|
|
685
|
-
function parseSegment(segment) {
|
|
686
|
-
for (const codec of SEGMENT_CODECS) if (codec.match(segment)) return codec.parse(segment);
|
|
687
|
-
throw new Error(`Invalid segment: "${segment}"`);
|
|
688
|
-
}
|
|
689
|
-
function serializeSegment(segment) {
|
|
690
|
-
for (const codec of SEGMENT_CODECS) if (segment["AUTOMERGE_REF_KIND"] === codec.kind) return codec.serialize(segment);
|
|
691
|
-
throw new Error(`No codec found for segment kind: ${segment[KIND]}`);
|
|
692
|
-
}
|
|
693
|
-
function parsePath(path) {
|
|
694
|
-
if (!path) return [];
|
|
695
|
-
const trimmed = path.replace(/^\/+|\/+$/g, "");
|
|
696
|
-
if (!trimmed) throw new Error("Invalid path: path cannot be empty or consist only of slashes");
|
|
697
|
-
if (trimmed.includes("//")) throw new Error("Invalid path: contains empty segment (double slash)");
|
|
698
|
-
return trimmed.split("/").map(parseSegment);
|
|
699
|
-
}
|
|
700
|
-
function serializePath(segments) {
|
|
701
|
-
return segments.map(serializeSegment).join("/");
|
|
702
|
-
}
|
|
703
|
-
var require_ms = /* @__PURE__ */ __commonJSMin((exports, module) => {
|
|
704
|
-
var s = 1e3;
|
|
705
|
-
var m = s * 60;
|
|
706
|
-
var h = m * 60;
|
|
707
|
-
var d = h * 24;
|
|
708
|
-
var w = d * 7;
|
|
709
|
-
var y = d * 365.25;
|
|
710
|
-
module.exports = function(val, options) {
|
|
711
|
-
options = options || {};
|
|
712
|
-
var type = typeof val;
|
|
713
|
-
if (type === "string" && val.length > 0) return parse2(val);
|
|
714
|
-
else if (type === "number" && isFinite(val)) return options.long ? fmtLong(val) : fmtShort(val);
|
|
715
|
-
throw new Error("val is not a non-empty string or a valid number. val=" + JSON.stringify(val));
|
|
716
|
-
};
|
|
717
|
-
function parse2(str) {
|
|
718
|
-
str = String(str);
|
|
719
|
-
if (str.length > 100) return;
|
|
720
|
-
var match = /^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(str);
|
|
721
|
-
if (!match) return;
|
|
722
|
-
var n = parseFloat(match[1]);
|
|
723
|
-
switch ((match[2] || "ms").toLowerCase()) {
|
|
724
|
-
case "years":
|
|
725
|
-
case "year":
|
|
726
|
-
case "yrs":
|
|
727
|
-
case "yr":
|
|
728
|
-
case "y":
|
|
729
|
-
return n * y;
|
|
730
|
-
case "weeks":
|
|
731
|
-
case "week":
|
|
732
|
-
case "w":
|
|
733
|
-
return n * w;
|
|
734
|
-
case "days":
|
|
735
|
-
case "day":
|
|
736
|
-
case "d":
|
|
737
|
-
return n * d;
|
|
738
|
-
case "hours":
|
|
739
|
-
case "hour":
|
|
740
|
-
case "hrs":
|
|
741
|
-
case "hr":
|
|
742
|
-
case "h":
|
|
743
|
-
return n * h;
|
|
744
|
-
case "minutes":
|
|
745
|
-
case "minute":
|
|
746
|
-
case "mins":
|
|
747
|
-
case "min":
|
|
748
|
-
case "m":
|
|
749
|
-
return n * m;
|
|
750
|
-
case "seconds":
|
|
751
|
-
case "second":
|
|
752
|
-
case "secs":
|
|
753
|
-
case "sec":
|
|
754
|
-
case "s":
|
|
755
|
-
return n * s;
|
|
756
|
-
case "milliseconds":
|
|
757
|
-
case "millisecond":
|
|
758
|
-
case "msecs":
|
|
759
|
-
case "msec":
|
|
760
|
-
case "ms":
|
|
761
|
-
return n;
|
|
762
|
-
default:
|
|
763
|
-
return;
|
|
764
|
-
}
|
|
765
|
-
}
|
|
766
|
-
function fmtShort(ms) {
|
|
767
|
-
var msAbs = Math.abs(ms);
|
|
768
|
-
if (msAbs >= d) return Math.round(ms / d) + "d";
|
|
769
|
-
if (msAbs >= h) return Math.round(ms / h) + "h";
|
|
770
|
-
if (msAbs >= m) return Math.round(ms / m) + "m";
|
|
771
|
-
if (msAbs >= s) return Math.round(ms / s) + "s";
|
|
772
|
-
return ms + "ms";
|
|
773
|
-
}
|
|
774
|
-
function fmtLong(ms) {
|
|
775
|
-
var msAbs = Math.abs(ms);
|
|
776
|
-
if (msAbs >= d) return plural(ms, msAbs, d, "day");
|
|
777
|
-
if (msAbs >= h) return plural(ms, msAbs, h, "hour");
|
|
778
|
-
if (msAbs >= m) return plural(ms, msAbs, m, "minute");
|
|
779
|
-
if (msAbs >= s) return plural(ms, msAbs, s, "second");
|
|
780
|
-
return ms + " ms";
|
|
781
|
-
}
|
|
782
|
-
function plural(ms, msAbs, n, name) {
|
|
783
|
-
var isPlural = msAbs >= n * 1.5;
|
|
784
|
-
return Math.round(ms / n) + " " + name + (isPlural ? "s" : "");
|
|
785
|
-
}
|
|
786
|
-
});
|
|
787
|
-
var require_common = /* @__PURE__ */ __commonJSMin((exports, module) => {
|
|
788
|
-
function setup(env) {
|
|
789
|
-
createDebug.debug = createDebug;
|
|
790
|
-
createDebug.default = createDebug;
|
|
791
|
-
createDebug.coerce = coerce;
|
|
792
|
-
createDebug.disable = disable;
|
|
793
|
-
createDebug.enable = enable;
|
|
794
|
-
createDebug.enabled = enabled;
|
|
795
|
-
createDebug.humanize = require_ms();
|
|
796
|
-
createDebug.destroy = destroy;
|
|
797
|
-
Object.keys(env).forEach((key) => {
|
|
798
|
-
createDebug[key] = env[key];
|
|
799
|
-
});
|
|
800
|
-
createDebug.names = [];
|
|
801
|
-
createDebug.skips = [];
|
|
802
|
-
createDebug.formatters = {};
|
|
803
|
-
function selectColor(namespace) {
|
|
804
|
-
let hash = 0;
|
|
805
|
-
for (let i = 0; i < namespace.length; i++) {
|
|
806
|
-
hash = (hash << 5) - hash + namespace.charCodeAt(i);
|
|
807
|
-
hash |= 0;
|
|
808
|
-
}
|
|
809
|
-
return createDebug.colors[Math.abs(hash) % createDebug.colors.length];
|
|
810
|
-
}
|
|
811
|
-
createDebug.selectColor = selectColor;
|
|
812
|
-
function createDebug(namespace) {
|
|
813
|
-
let prevTime;
|
|
814
|
-
let enableOverride = null;
|
|
815
|
-
let namespacesCache;
|
|
816
|
-
let enabledCache;
|
|
817
|
-
function debug(...args) {
|
|
818
|
-
if (!debug.enabled) return;
|
|
819
|
-
const self = debug;
|
|
820
|
-
const curr = Number(/* @__PURE__ */ new Date());
|
|
821
|
-
self.diff = curr - (prevTime || curr);
|
|
822
|
-
self.prev = prevTime;
|
|
823
|
-
self.curr = curr;
|
|
824
|
-
prevTime = curr;
|
|
825
|
-
args[0] = createDebug.coerce(args[0]);
|
|
826
|
-
if (typeof args[0] !== "string") args.unshift("%O");
|
|
827
|
-
let index = 0;
|
|
828
|
-
args[0] = args[0].replace(/%([a-zA-Z%])/g, (match, format) => {
|
|
829
|
-
if (match === "%%") return "%";
|
|
830
|
-
index++;
|
|
831
|
-
const formatter = createDebug.formatters[format];
|
|
832
|
-
if (typeof formatter === "function") {
|
|
833
|
-
const val = args[index];
|
|
834
|
-
match = formatter.call(self, val);
|
|
835
|
-
args.splice(index, 1);
|
|
836
|
-
index--;
|
|
837
|
-
}
|
|
838
|
-
return match;
|
|
839
|
-
});
|
|
840
|
-
createDebug.formatArgs.call(self, args);
|
|
841
|
-
(self.log || createDebug.log).apply(self, args);
|
|
842
|
-
}
|
|
843
|
-
debug.namespace = namespace;
|
|
844
|
-
debug.useColors = createDebug.useColors();
|
|
845
|
-
debug.color = createDebug.selectColor(namespace);
|
|
846
|
-
debug.extend = extend;
|
|
847
|
-
debug.destroy = createDebug.destroy;
|
|
848
|
-
Object.defineProperty(debug, "enabled", {
|
|
849
|
-
enumerable: true,
|
|
850
|
-
configurable: false,
|
|
851
|
-
get: () => {
|
|
852
|
-
if (enableOverride !== null) return enableOverride;
|
|
853
|
-
if (namespacesCache !== createDebug.namespaces) {
|
|
854
|
-
namespacesCache = createDebug.namespaces;
|
|
855
|
-
enabledCache = createDebug.enabled(namespace);
|
|
856
|
-
}
|
|
857
|
-
return enabledCache;
|
|
858
|
-
},
|
|
859
|
-
set: (v) => {
|
|
860
|
-
enableOverride = v;
|
|
861
|
-
}
|
|
862
|
-
});
|
|
863
|
-
if (typeof createDebug.init === "function") createDebug.init(debug);
|
|
864
|
-
return debug;
|
|
865
|
-
}
|
|
866
|
-
function extend(namespace, delimiter) {
|
|
867
|
-
const newDebug = createDebug(this.namespace + (typeof delimiter === "undefined" ? ":" : delimiter) + namespace);
|
|
868
|
-
newDebug.log = this.log;
|
|
869
|
-
return newDebug;
|
|
870
|
-
}
|
|
871
|
-
function enable(namespaces) {
|
|
872
|
-
createDebug.save(namespaces);
|
|
873
|
-
createDebug.namespaces = namespaces;
|
|
874
|
-
createDebug.names = [];
|
|
875
|
-
createDebug.skips = [];
|
|
876
|
-
const split = (typeof namespaces === "string" ? namespaces : "").trim().replace(/\s+/g, ",").split(",").filter(Boolean);
|
|
877
|
-
for (const ns of split) if (ns[0] === "-") createDebug.skips.push(ns.slice(1));
|
|
878
|
-
else createDebug.names.push(ns);
|
|
879
|
-
}
|
|
880
|
-
function matchesTemplate(search, template) {
|
|
881
|
-
let searchIndex = 0;
|
|
882
|
-
let templateIndex = 0;
|
|
883
|
-
let starIndex = -1;
|
|
884
|
-
let matchIndex = 0;
|
|
885
|
-
while (searchIndex < search.length) if (templateIndex < template.length && (template[templateIndex] === search[searchIndex] || template[templateIndex] === "*")) if (template[templateIndex] === "*") {
|
|
886
|
-
starIndex = templateIndex;
|
|
887
|
-
matchIndex = searchIndex;
|
|
888
|
-
templateIndex++;
|
|
889
|
-
} else {
|
|
890
|
-
searchIndex++;
|
|
891
|
-
templateIndex++;
|
|
892
|
-
}
|
|
893
|
-
else if (starIndex !== -1) {
|
|
894
|
-
templateIndex = starIndex + 1;
|
|
895
|
-
matchIndex++;
|
|
896
|
-
searchIndex = matchIndex;
|
|
897
|
-
} else return false;
|
|
898
|
-
while (templateIndex < template.length && template[templateIndex] === "*") templateIndex++;
|
|
899
|
-
return templateIndex === template.length;
|
|
900
|
-
}
|
|
901
|
-
function disable() {
|
|
902
|
-
const namespaces = [...createDebug.names, ...createDebug.skips.map((namespace) => "-" + namespace)].join(",");
|
|
903
|
-
createDebug.enable("");
|
|
904
|
-
return namespaces;
|
|
905
|
-
}
|
|
906
|
-
function enabled(name) {
|
|
907
|
-
for (const skip of createDebug.skips) if (matchesTemplate(name, skip)) return false;
|
|
908
|
-
for (const ns of createDebug.names) if (matchesTemplate(name, ns)) return true;
|
|
909
|
-
return false;
|
|
910
|
-
}
|
|
911
|
-
function coerce(val) {
|
|
912
|
-
if (val instanceof Error) return val.stack || val.message;
|
|
913
|
-
return val;
|
|
914
|
-
}
|
|
915
|
-
function destroy() {
|
|
916
|
-
console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.");
|
|
917
|
-
}
|
|
918
|
-
createDebug.enable(createDebug.load());
|
|
919
|
-
return createDebug;
|
|
920
|
-
}
|
|
921
|
-
module.exports = setup;
|
|
922
|
-
});
|
|
923
|
-
(/* @__PURE__ */ __commonJSMin((exports, module) => {
|
|
924
|
-
exports.formatArgs = formatArgs;
|
|
925
|
-
exports.save = save;
|
|
926
|
-
exports.load = load;
|
|
927
|
-
exports.useColors = useColors;
|
|
928
|
-
exports.storage = localstorage();
|
|
929
|
-
exports.destroy = /* @__PURE__ */ (() => {
|
|
930
|
-
let warned = false;
|
|
931
|
-
return () => {
|
|
932
|
-
if (!warned) {
|
|
933
|
-
warned = true;
|
|
934
|
-
console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.");
|
|
935
|
-
}
|
|
936
|
-
};
|
|
937
|
-
})();
|
|
938
|
-
exports.colors = [
|
|
939
|
-
"#0000CC",
|
|
940
|
-
"#0000FF",
|
|
941
|
-
"#0033CC",
|
|
942
|
-
"#0033FF",
|
|
943
|
-
"#0066CC",
|
|
944
|
-
"#0066FF",
|
|
945
|
-
"#0099CC",
|
|
946
|
-
"#0099FF",
|
|
947
|
-
"#00CC00",
|
|
948
|
-
"#00CC33",
|
|
949
|
-
"#00CC66",
|
|
950
|
-
"#00CC99",
|
|
951
|
-
"#00CCCC",
|
|
952
|
-
"#00CCFF",
|
|
953
|
-
"#3300CC",
|
|
954
|
-
"#3300FF",
|
|
955
|
-
"#3333CC",
|
|
956
|
-
"#3333FF",
|
|
957
|
-
"#3366CC",
|
|
958
|
-
"#3366FF",
|
|
959
|
-
"#3399CC",
|
|
960
|
-
"#3399FF",
|
|
961
|
-
"#33CC00",
|
|
962
|
-
"#33CC33",
|
|
963
|
-
"#33CC66",
|
|
964
|
-
"#33CC99",
|
|
965
|
-
"#33CCCC",
|
|
966
|
-
"#33CCFF",
|
|
967
|
-
"#6600CC",
|
|
968
|
-
"#6600FF",
|
|
969
|
-
"#6633CC",
|
|
970
|
-
"#6633FF",
|
|
971
|
-
"#66CC00",
|
|
972
|
-
"#66CC33",
|
|
973
|
-
"#9900CC",
|
|
974
|
-
"#9900FF",
|
|
975
|
-
"#9933CC",
|
|
976
|
-
"#9933FF",
|
|
977
|
-
"#99CC00",
|
|
978
|
-
"#99CC33",
|
|
979
|
-
"#CC0000",
|
|
980
|
-
"#CC0033",
|
|
981
|
-
"#CC0066",
|
|
982
|
-
"#CC0099",
|
|
983
|
-
"#CC00CC",
|
|
984
|
-
"#CC00FF",
|
|
985
|
-
"#CC3300",
|
|
986
|
-
"#CC3333",
|
|
987
|
-
"#CC3366",
|
|
988
|
-
"#CC3399",
|
|
989
|
-
"#CC33CC",
|
|
990
|
-
"#CC33FF",
|
|
991
|
-
"#CC6600",
|
|
992
|
-
"#CC6633",
|
|
993
|
-
"#CC9900",
|
|
994
|
-
"#CC9933",
|
|
995
|
-
"#CCCC00",
|
|
996
|
-
"#CCCC33",
|
|
997
|
-
"#FF0000",
|
|
998
|
-
"#FF0033",
|
|
999
|
-
"#FF0066",
|
|
1000
|
-
"#FF0099",
|
|
1001
|
-
"#FF00CC",
|
|
1002
|
-
"#FF00FF",
|
|
1003
|
-
"#FF3300",
|
|
1004
|
-
"#FF3333",
|
|
1005
|
-
"#FF3366",
|
|
1006
|
-
"#FF3399",
|
|
1007
|
-
"#FF33CC",
|
|
1008
|
-
"#FF33FF",
|
|
1009
|
-
"#FF6600",
|
|
1010
|
-
"#FF6633",
|
|
1011
|
-
"#FF9900",
|
|
1012
|
-
"#FF9933",
|
|
1013
|
-
"#FFCC00",
|
|
1014
|
-
"#FFCC33"
|
|
1015
|
-
];
|
|
1016
|
-
function useColors() {
|
|
1017
|
-
if (typeof window !== "undefined" && window.process && (window.process.type === "renderer" || window.process.__nwjs)) return true;
|
|
1018
|
-
if (typeof navigator !== "undefined" && navigator.userAgent && navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/)) return false;
|
|
1019
|
-
let m;
|
|
1020
|
-
return typeof document !== "undefined" && document.documentElement && document.documentElement.style && document.documentElement.style.WebkitAppearance || typeof window !== "undefined" && window.console && (window.console.firebug || window.console.exception && window.console.table) || typeof navigator !== "undefined" && navigator.userAgent && (m = navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)) && parseInt(m[1], 10) >= 31 || typeof navigator !== "undefined" && navigator.userAgent && navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/);
|
|
1021
|
-
}
|
|
1022
|
-
function formatArgs(args) {
|
|
1023
|
-
args[0] = (this.useColors ? "%c" : "") + this.namespace + (this.useColors ? " %c" : " ") + args[0] + (this.useColors ? "%c " : " ") + "+" + module.exports.humanize(this.diff);
|
|
1024
|
-
if (!this.useColors) return;
|
|
1025
|
-
const c = "color: " + this.color;
|
|
1026
|
-
args.splice(1, 0, c, "color: inherit");
|
|
1027
|
-
let index = 0;
|
|
1028
|
-
let lastC = 0;
|
|
1029
|
-
args[0].replace(/%[a-zA-Z%]/g, (match) => {
|
|
1030
|
-
if (match === "%%") return;
|
|
1031
|
-
index++;
|
|
1032
|
-
if (match === "%c") lastC = index;
|
|
1033
|
-
});
|
|
1034
|
-
args.splice(lastC, 0, c);
|
|
1035
|
-
}
|
|
1036
|
-
exports.log = console.debug || console.log || (() => {
|
|
1037
|
-
});
|
|
1038
|
-
function save(namespaces) {
|
|
1039
|
-
try {
|
|
1040
|
-
if (namespaces) exports.storage.setItem("debug", namespaces);
|
|
1041
|
-
else exports.storage.removeItem("debug");
|
|
1042
|
-
} catch (error) {
|
|
1043
|
-
}
|
|
1044
|
-
}
|
|
1045
|
-
function load() {
|
|
1046
|
-
let r;
|
|
1047
|
-
try {
|
|
1048
|
-
r = exports.storage.getItem("debug") || exports.storage.getItem("DEBUG");
|
|
1049
|
-
} catch (error) {
|
|
1050
|
-
}
|
|
1051
|
-
if (!r && typeof process !== "undefined" && "env" in process) r = process.env.DEBUG;
|
|
1052
|
-
return r;
|
|
1053
|
-
}
|
|
1054
|
-
function localstorage() {
|
|
1055
|
-
try {
|
|
1056
|
-
return localStorage;
|
|
1057
|
-
} catch (error) {
|
|
1058
|
-
}
|
|
1059
|
-
}
|
|
1060
|
-
module.exports = require_common()(exports);
|
|
1061
|
-
var { formatters } = module.exports;
|
|
1062
|
-
formatters.j = function(v) {
|
|
1063
|
-
try {
|
|
1064
|
-
return JSON.stringify(v);
|
|
1065
|
-
} catch (error) {
|
|
1066
|
-
return "[UnexpectedJSONParseError]: " + error.message;
|
|
1067
|
-
}
|
|
1068
|
-
};
|
|
1069
|
-
}))();
|
|
1070
|
-
var urlPrefix = "automerge:";
|
|
1071
|
-
var parseAutomergeUrl = (url) => {
|
|
1072
|
-
const [baseUrl, headsSection, ...rest] = url.split("#");
|
|
1073
|
-
if (rest.length > 0) throw new Error("Invalid URL: contains multiple heads sections");
|
|
1074
|
-
const match = baseUrl.match(new RegExp(`^${urlPrefix}([^/]+)(?:\\/(.*))?$`));
|
|
1075
|
-
if (!match) throw new Error("Invalid document URL: " + url);
|
|
1076
|
-
const [, docMatch, pathStr] = match;
|
|
1077
|
-
const documentId = docMatch;
|
|
1078
|
-
const binaryDocumentId = documentIdToBinary(documentId);
|
|
1079
|
-
if (!binaryDocumentId) throw new Error("Invalid document URL: " + url);
|
|
1080
|
-
const segments = pathStr !== void 0 && pathStr.length > 0 ? parsePath(pathStr) : void 0;
|
|
1081
|
-
if (headsSection === void 0) return segments ? {
|
|
1082
|
-
binaryDocumentId,
|
|
1083
|
-
documentId,
|
|
1084
|
-
segments
|
|
1085
|
-
} : {
|
|
1086
|
-
binaryDocumentId,
|
|
1087
|
-
documentId
|
|
1088
|
-
};
|
|
1089
|
-
const heads = headsSection === "" ? [] : headsSection.split("|");
|
|
1090
|
-
const hexHeads = heads.map((head) => {
|
|
1091
|
-
try {
|
|
1092
|
-
return uint8ArrayToHexString(esm_default.decode(head));
|
|
1093
|
-
} catch (e) {
|
|
1094
|
-
throw new Error(`Invalid head in URL: ${head}`);
|
|
1095
|
-
}
|
|
1096
|
-
});
|
|
1097
|
-
return segments ? {
|
|
1098
|
-
binaryDocumentId,
|
|
1099
|
-
hexHeads,
|
|
1100
|
-
documentId,
|
|
1101
|
-
heads,
|
|
1102
|
-
segments
|
|
1103
|
-
} : {
|
|
1104
|
-
binaryDocumentId,
|
|
1105
|
-
hexHeads,
|
|
1106
|
-
documentId,
|
|
1107
|
-
heads
|
|
1108
|
-
};
|
|
1109
|
-
};
|
|
1110
|
-
var stringifyAutomergeUrl = (arg) => {
|
|
1111
|
-
if (arg instanceof Uint8Array || typeof arg === "string") return urlPrefix + (arg instanceof Uint8Array ? binaryToDocumentId(arg) : arg);
|
|
1112
|
-
const { documentId, heads = void 0, segments = void 0 } = arg;
|
|
1113
|
-
if (documentId === void 0) throw new Error("Invalid documentId: " + documentId);
|
|
1114
|
-
let url = `${urlPrefix}${documentId instanceof Uint8Array ? binaryToDocumentId(documentId) : documentId}`;
|
|
1115
|
-
if (segments !== void 0 && segments.length > 0) url += "/" + serializePath(segments);
|
|
1116
|
-
if (heads !== void 0) {
|
|
1117
|
-
heads.forEach((head) => {
|
|
1118
|
-
try {
|
|
1119
|
-
esm_default.decode(head);
|
|
1120
|
-
} catch (e) {
|
|
1121
|
-
throw new Error(`Invalid head: ${head}`);
|
|
1122
|
-
}
|
|
1123
|
-
});
|
|
1124
|
-
url += "#" + [...heads].sort().join("|");
|
|
1125
|
-
}
|
|
1126
|
-
return url;
|
|
1127
|
-
};
|
|
1128
|
-
var anyDocumentIdToAutomergeUrl = (id) => isValidAutomergeUrl(id) ? id : isValidDocumentId(id) ? stringifyAutomergeUrl({ documentId: id }) : isValidUuid(id) ? parseLegacyUUID(id) : void 0;
|
|
1129
|
-
var isValidAutomergeUrl = (str) => {
|
|
1130
|
-
if (typeof str !== "string" || !str || !str.startsWith("automerge:")) return false;
|
|
1131
|
-
try {
|
|
1132
|
-
const { documentId, heads } = parseAutomergeUrl(str);
|
|
1133
|
-
if (!isValidDocumentId(documentId)) return false;
|
|
1134
|
-
if (heads && !heads.every((head) => {
|
|
1135
|
-
try {
|
|
1136
|
-
esm_default.decode(head);
|
|
1137
|
-
return true;
|
|
1138
|
-
} catch {
|
|
1139
|
-
return false;
|
|
1140
|
-
}
|
|
1141
|
-
})) return false;
|
|
1142
|
-
return true;
|
|
1143
|
-
} catch {
|
|
1144
|
-
return false;
|
|
1145
|
-
}
|
|
1146
|
-
};
|
|
1147
|
-
var isValidDocumentId = (str) => {
|
|
1148
|
-
if (typeof str !== "string") return false;
|
|
1149
|
-
return documentIdToBinary(str) !== void 0;
|
|
1150
|
-
};
|
|
1151
|
-
var isValidUuid = (str) => typeof str === "string" && validate(str);
|
|
1152
|
-
var documentIdToBinary = (docId) => esm_default.decodeUnsafe(docId);
|
|
1153
|
-
var binaryToDocumentId = (docId) => esm_default.encode(docId);
|
|
1154
|
-
var parseLegacyUUID = (str) => {
|
|
1155
|
-
if (!validate(str)) return void 0;
|
|
1156
|
-
return stringifyAutomergeUrl({ documentId: parse(str) });
|
|
1157
|
-
};
|
|
1158
|
-
var wrapperCache = /* @__PURE__ */ new Map();
|
|
1159
|
-
function useDocHandle(id, { suspense } = { suspense: false }) {
|
|
1160
|
-
const repo = useRepo();
|
|
1161
|
-
const controllerRef = (0, import_react.useRef)(void 0);
|
|
1162
|
-
const [handle, setHandle] = (0, import_react.useState)();
|
|
1163
|
-
let currentHandle = id && handle && handle.url === anyDocumentIdToAutomergeUrl(id) ? handle : void 0;
|
|
1164
|
-
if (id && !currentHandle) {
|
|
1165
|
-
const state = repo.findWithProgress(id).peek();
|
|
1166
|
-
if (state.state === "ready") currentHandle = state.handle;
|
|
1167
|
-
}
|
|
1168
|
-
let wrapper = id ? wrapperCache.get(id) : void 0;
|
|
1169
|
-
if (!wrapper && id) {
|
|
1170
|
-
controllerRef.current?.abort();
|
|
1171
|
-
controllerRef.current = new AbortController();
|
|
1172
|
-
wrapper = wrapPromise(repo.find(id, { signal: controllerRef.current.signal }));
|
|
1173
|
-
wrapperCache.set(id, wrapper);
|
|
1174
|
-
}
|
|
1175
|
-
(0, import_react.useEffect)(() => {
|
|
1176
|
-
if (currentHandle || suspense || !wrapper) return;
|
|
1177
|
-
let active = true;
|
|
1178
|
-
wrapper.promise.then((handle2) => {
|
|
1179
|
-
if (active) setHandle(handle2);
|
|
1180
|
-
}).catch(() => {
|
|
1181
|
-
if (id && wrapperCache.get(id) === wrapper) wrapperCache.delete(id);
|
|
1182
|
-
if (active) setHandle(void 0);
|
|
1183
|
-
});
|
|
1184
|
-
return () => {
|
|
1185
|
-
active = false;
|
|
1186
|
-
};
|
|
1187
|
-
}, [
|
|
1188
|
-
currentHandle,
|
|
1189
|
-
suspense,
|
|
1190
|
-
wrapper,
|
|
1191
|
-
id
|
|
1192
|
-
]);
|
|
1193
|
-
if (currentHandle || !suspense || !wrapper) return currentHandle;
|
|
1194
|
-
return wrapper.read();
|
|
1195
|
-
}
|
|
1196
|
-
function useDocument(id, params = { suspense: false }) {
|
|
1197
|
-
const handle = useDocHandle(id, params);
|
|
1198
|
-
const [doc, setDoc] = (0, import_react.useState)(() => handle?.doc());
|
|
1199
|
-
const [deleteError, setDeleteError] = (0, import_react.useState)();
|
|
1200
|
-
(0, import_react.useEffect)(() => {
|
|
1201
|
-
setDoc(handle?.doc());
|
|
1202
|
-
}, [handle]);
|
|
1203
|
-
(0, import_react.useEffect)(() => {
|
|
1204
|
-
if (!handle) return;
|
|
1205
|
-
const onChange = () => setDoc(handle.doc());
|
|
1206
|
-
const onDelete = () => {
|
|
1207
|
-
setDeleteError(/* @__PURE__ */ new Error(`Document ${id} was deleted`));
|
|
1208
|
-
};
|
|
1209
|
-
handle.on("change", onChange);
|
|
1210
|
-
handle.on("delete", onDelete);
|
|
1211
|
-
return () => {
|
|
1212
|
-
handle.removeListener("change", onChange);
|
|
1213
|
-
handle.removeListener("delete", onDelete);
|
|
1214
|
-
};
|
|
1215
|
-
}, [handle, id]);
|
|
1216
|
-
const changeDoc = (0, import_react.useCallback)((changeFn, options) => {
|
|
1217
|
-
handle.change(changeFn, options);
|
|
1218
|
-
}, [handle]);
|
|
1219
|
-
if (deleteError) throw deleteError;
|
|
1220
|
-
if (!doc) return [void 0, () => {
|
|
1221
|
-
}];
|
|
1222
|
-
return [doc, changeDoc];
|
|
1223
|
-
}
|
|
1224
|
-
function useSet(items) {
|
|
1225
|
-
const [set, setSet] = (0, import_react.useState)(() => {
|
|
1226
|
-
return new Set(items);
|
|
1227
|
-
});
|
|
1228
|
-
(0, import_react.useEffect)(() => {
|
|
1229
|
-
const newSet = new Set(items);
|
|
1230
|
-
if (identical(set, newSet)) return;
|
|
1231
|
-
setSet(newSet);
|
|
1232
|
-
}, [set, items]);
|
|
1233
|
-
return set;
|
|
1234
|
-
}
|
|
1235
|
-
function identical(s1, s2) {
|
|
1236
|
-
return s1.size === s2.size && Array.from(s1).every((v) => s2.has(v));
|
|
1237
|
-
}
|
|
1238
|
-
function useDocHandles(ids, { suspense = false } = {}) {
|
|
1239
|
-
const idSet = useSet(ids);
|
|
1240
|
-
const repo = useRepo();
|
|
1241
|
-
const [handleMap, setHandleMap] = (0, import_react.useState)(() => {
|
|
1242
|
-
const map = /* @__PURE__ */ new Map();
|
|
1243
|
-
for (const id of idSet.values()) {
|
|
1244
|
-
let progress;
|
|
1245
|
-
try {
|
|
1246
|
-
progress = repo.findWithProgress(id);
|
|
1247
|
-
} catch (e) {
|
|
1248
|
-
continue;
|
|
1249
|
-
}
|
|
1250
|
-
const state = progress.peek();
|
|
1251
|
-
if (state.state === "ready") map.set(id, state.handle);
|
|
1252
|
-
}
|
|
1253
|
-
return map;
|
|
1254
|
-
});
|
|
1255
|
-
const pendingPromises = [];
|
|
1256
|
-
const nextHandleMap = /* @__PURE__ */ new Map();
|
|
1257
|
-
for (const id of idSet.values()) {
|
|
1258
|
-
let handle = handleMap.get(id);
|
|
1259
|
-
let wrapper = wrapperCache.get(id);
|
|
1260
|
-
if (!wrapper) try {
|
|
1261
|
-
wrapper = wrapPromise(repo.find(id));
|
|
1262
|
-
wrapperCache.set(id, wrapper);
|
|
1263
|
-
} catch (e) {
|
|
1264
|
-
continue;
|
|
1265
|
-
}
|
|
1266
|
-
try {
|
|
1267
|
-
handle ??= wrapper.read();
|
|
1268
|
-
nextHandleMap.set(id, handle);
|
|
1269
|
-
} catch (e) {
|
|
1270
|
-
if (e instanceof Promise) pendingPromises.push(wrapper);
|
|
1271
|
-
else nextHandleMap.set(id, void 0);
|
|
1272
|
-
}
|
|
1273
|
-
}
|
|
1274
|
-
(0, import_react.useEffect)(() => {
|
|
1275
|
-
let active = true;
|
|
1276
|
-
if (pendingPromises.length > 0) Promise.allSettled(pendingPromises.map((p) => p.promise)).then((handles) => {
|
|
1277
|
-
if (!active) return;
|
|
1278
|
-
handles.forEach((r) => {
|
|
1279
|
-
if (r.status === "fulfilled") {
|
|
1280
|
-
const h = r.value;
|
|
1281
|
-
nextHandleMap.set(h.url, h);
|
|
1282
|
-
}
|
|
1283
|
-
});
|
|
1284
|
-
setHandleMap(nextHandleMap);
|
|
1285
|
-
});
|
|
1286
|
-
else setHandleMap(nextHandleMap);
|
|
1287
|
-
return () => {
|
|
1288
|
-
active = false;
|
|
1289
|
-
};
|
|
1290
|
-
}, [suspense, idSet]);
|
|
1291
|
-
if (suspense && pendingPromises.length > 0) throw Promise.all(pendingPromises.map((p) => p.promise));
|
|
1292
|
-
return handleMap;
|
|
1293
|
-
}
|
|
1294
|
-
function useDocuments(ids, { suspense = true } = {}) {
|
|
1295
|
-
const handleMap = useDocHandles(ids, { suspense });
|
|
1296
|
-
const [docMap, setDocMap] = (0, import_react.useState)(() => {
|
|
1297
|
-
const docs = /* @__PURE__ */ new Map();
|
|
1298
|
-
handleMap.forEach((handle) => {
|
|
1299
|
-
const url = handle?.url;
|
|
1300
|
-
if (url) docs.set(url, handle?.doc());
|
|
1301
|
-
});
|
|
1302
|
-
return docs;
|
|
1303
|
-
});
|
|
1304
|
-
(0, import_react.useEffect)(() => {
|
|
1305
|
-
const listeners = /* @__PURE__ */ new Map();
|
|
1306
|
-
handleMap.forEach((handle, id) => {
|
|
1307
|
-
if (handle) {
|
|
1308
|
-
const onChange = () => {
|
|
1309
|
-
setDocMap((prev) => {
|
|
1310
|
-
const next = new Map(prev);
|
|
1311
|
-
next.set(id, handle.doc());
|
|
1312
|
-
return next;
|
|
1313
|
-
});
|
|
1314
|
-
};
|
|
1315
|
-
setDocMap((prev) => {
|
|
1316
|
-
const next = new Map(prev);
|
|
1317
|
-
next.set(id, handle.doc());
|
|
1318
|
-
return next;
|
|
1319
|
-
});
|
|
1320
|
-
handle.on("change", onChange);
|
|
1321
|
-
listeners.set(id, onChange);
|
|
1322
|
-
}
|
|
1323
|
-
});
|
|
1324
|
-
setDocMap((prev) => {
|
|
1325
|
-
const next = new Map(prev);
|
|
1326
|
-
for (const [id] of next) if (!handleMap.has(id)) next.delete(id);
|
|
1327
|
-
return next;
|
|
1328
|
-
});
|
|
1329
|
-
return () => {
|
|
1330
|
-
handleMap.forEach((handle, id) => {
|
|
1331
|
-
const listener = listeners.get(id);
|
|
1332
|
-
if (handle && listener) handle.removeListener("change", listener);
|
|
1333
|
-
});
|
|
1334
|
-
};
|
|
1335
|
-
}, [handleMap]);
|
|
1336
|
-
return [docMap, (0, import_react.useCallback)((id, changeFn, options) => {
|
|
1337
|
-
const handle = handleMap.get(id);
|
|
1338
|
-
if (handle) handle.change(changeFn, options);
|
|
1339
|
-
}, [handleMap])];
|
|
1340
|
-
}
|
|
1341
|
-
function useStateRef(initialState) {
|
|
1342
|
-
const [state, setState] = (0, import_react.useState)(initialState);
|
|
1343
|
-
const ref = (0, import_react.useRef)(state);
|
|
1344
|
-
return [
|
|
1345
|
-
state,
|
|
1346
|
-
(0, import_react.useCallback)((setStateAction) => {
|
|
1347
|
-
ref.current = typeof setStateAction === "function" ? setStateAction(ref.current) : setStateAction;
|
|
1348
|
-
setState(ref.current);
|
|
1349
|
-
}, []),
|
|
1350
|
-
ref
|
|
1351
|
-
];
|
|
1352
|
-
}
|
|
1353
|
-
var peerEvents = new (/* @__PURE__ */ __toESM2((/* @__PURE__ */ __commonJSMin((exports, module) => {
|
|
1354
|
-
var has = Object.prototype.hasOwnProperty, prefix = "~";
|
|
1355
|
-
function Events() {
|
|
1356
|
-
}
|
|
1357
|
-
if (Object.create) {
|
|
1358
|
-
Events.prototype = /* @__PURE__ */ Object.create(null);
|
|
1359
|
-
if (!new Events().__proto__) prefix = false;
|
|
1360
|
-
}
|
|
1361
|
-
function EE(fn, context, once) {
|
|
1362
|
-
this.fn = fn;
|
|
1363
|
-
this.context = context;
|
|
1364
|
-
this.once = once || false;
|
|
1365
|
-
}
|
|
1366
|
-
function addListener(emitter, event, fn, context, once) {
|
|
1367
|
-
if (typeof fn !== "function") throw new TypeError("The listener must be a function");
|
|
1368
|
-
var listener = new EE(fn, context || emitter, once), evt = prefix ? prefix + event : event;
|
|
1369
|
-
if (!emitter._events[evt]) emitter._events[evt] = listener, emitter._eventsCount++;
|
|
1370
|
-
else if (!emitter._events[evt].fn) emitter._events[evt].push(listener);
|
|
1371
|
-
else emitter._events[evt] = [emitter._events[evt], listener];
|
|
1372
|
-
return emitter;
|
|
1373
|
-
}
|
|
1374
|
-
function clearEvent(emitter, evt) {
|
|
1375
|
-
if (--emitter._eventsCount === 0) emitter._events = new Events();
|
|
1376
|
-
else delete emitter._events[evt];
|
|
1377
|
-
}
|
|
1378
|
-
function EventEmitter() {
|
|
1379
|
-
this._events = new Events();
|
|
1380
|
-
this._eventsCount = 0;
|
|
1381
|
-
}
|
|
1382
|
-
EventEmitter.prototype.eventNames = function eventNames() {
|
|
1383
|
-
var names = [], events, name;
|
|
1384
|
-
if (this._eventsCount === 0) return names;
|
|
1385
|
-
for (name in events = this._events) if (has.call(events, name)) names.push(prefix ? name.slice(1) : name);
|
|
1386
|
-
if (Object.getOwnPropertySymbols) return names.concat(Object.getOwnPropertySymbols(events));
|
|
1387
|
-
return names;
|
|
1388
|
-
};
|
|
1389
|
-
EventEmitter.prototype.listeners = function listeners(event) {
|
|
1390
|
-
var evt = prefix ? prefix + event : event, handlers = this._events[evt];
|
|
1391
|
-
if (!handlers) return [];
|
|
1392
|
-
if (handlers.fn) return [handlers.fn];
|
|
1393
|
-
for (var i = 0, l = handlers.length, ee = new Array(l); i < l; i++) ee[i] = handlers[i].fn;
|
|
1394
|
-
return ee;
|
|
1395
|
-
};
|
|
1396
|
-
EventEmitter.prototype.listenerCount = function listenerCount(event) {
|
|
1397
|
-
var evt = prefix ? prefix + event : event, listeners = this._events[evt];
|
|
1398
|
-
if (!listeners) return 0;
|
|
1399
|
-
if (listeners.fn) return 1;
|
|
1400
|
-
return listeners.length;
|
|
1401
|
-
};
|
|
1402
|
-
EventEmitter.prototype.emit = function emit(event, a1, a2, a3, a4, a5) {
|
|
1403
|
-
var evt = prefix ? prefix + event : event;
|
|
1404
|
-
if (!this._events[evt]) return false;
|
|
1405
|
-
var listeners = this._events[evt], len = arguments.length, args, i;
|
|
1406
|
-
if (listeners.fn) {
|
|
1407
|
-
if (listeners.once) this.removeListener(event, listeners.fn, void 0, true);
|
|
1408
|
-
switch (len) {
|
|
1409
|
-
case 1:
|
|
1410
|
-
return listeners.fn.call(listeners.context), true;
|
|
1411
|
-
case 2:
|
|
1412
|
-
return listeners.fn.call(listeners.context, a1), true;
|
|
1413
|
-
case 3:
|
|
1414
|
-
return listeners.fn.call(listeners.context, a1, a2), true;
|
|
1415
|
-
case 4:
|
|
1416
|
-
return listeners.fn.call(listeners.context, a1, a2, a3), true;
|
|
1417
|
-
case 5:
|
|
1418
|
-
return listeners.fn.call(listeners.context, a1, a2, a3, a4), true;
|
|
1419
|
-
case 6:
|
|
1420
|
-
return listeners.fn.call(listeners.context, a1, a2, a3, a4, a5), true;
|
|
1421
|
-
}
|
|
1422
|
-
for (i = 1, args = new Array(len - 1); i < len; i++) args[i - 1] = arguments[i];
|
|
1423
|
-
listeners.fn.apply(listeners.context, args);
|
|
1424
|
-
} else {
|
|
1425
|
-
var length = listeners.length, j;
|
|
1426
|
-
for (i = 0; i < length; i++) {
|
|
1427
|
-
if (listeners[i].once) this.removeListener(event, listeners[i].fn, void 0, true);
|
|
1428
|
-
switch (len) {
|
|
1429
|
-
case 1:
|
|
1430
|
-
listeners[i].fn.call(listeners[i].context);
|
|
1431
|
-
break;
|
|
1432
|
-
case 2:
|
|
1433
|
-
listeners[i].fn.call(listeners[i].context, a1);
|
|
1434
|
-
break;
|
|
1435
|
-
case 3:
|
|
1436
|
-
listeners[i].fn.call(listeners[i].context, a1, a2);
|
|
1437
|
-
break;
|
|
1438
|
-
case 4:
|
|
1439
|
-
listeners[i].fn.call(listeners[i].context, a1, a2, a3);
|
|
1440
|
-
break;
|
|
1441
|
-
default:
|
|
1442
|
-
if (!args) for (j = 1, args = new Array(len - 1); j < len; j++) args[j - 1] = arguments[j];
|
|
1443
|
-
listeners[i].fn.apply(listeners[i].context, args);
|
|
1444
|
-
}
|
|
1445
|
-
}
|
|
1446
|
-
}
|
|
1447
|
-
return true;
|
|
1448
|
-
};
|
|
1449
|
-
EventEmitter.prototype.on = function on(event, fn, context) {
|
|
1450
|
-
return addListener(this, event, fn, context, false);
|
|
1451
|
-
};
|
|
1452
|
-
EventEmitter.prototype.once = function once(event, fn, context) {
|
|
1453
|
-
return addListener(this, event, fn, context, true);
|
|
1454
|
-
};
|
|
1455
|
-
EventEmitter.prototype.removeListener = function removeListener(event, fn, context, once) {
|
|
1456
|
-
var evt = prefix ? prefix + event : event;
|
|
1457
|
-
if (!this._events[evt]) return this;
|
|
1458
|
-
if (!fn) {
|
|
1459
|
-
clearEvent(this, evt);
|
|
1460
|
-
return this;
|
|
1461
|
-
}
|
|
1462
|
-
var listeners = this._events[evt];
|
|
1463
|
-
if (listeners.fn) {
|
|
1464
|
-
if (listeners.fn === fn && (!once || listeners.once) && (!context || listeners.context === context)) clearEvent(this, evt);
|
|
1465
|
-
} else {
|
|
1466
|
-
for (var i = 0, events = [], length = listeners.length; i < length; i++) if (listeners[i].fn !== fn || once && !listeners[i].once || context && listeners[i].context !== context) events.push(listeners[i]);
|
|
1467
|
-
if (events.length) this._events[evt] = events.length === 1 ? events[0] : events;
|
|
1468
|
-
else clearEvent(this, evt);
|
|
1469
|
-
}
|
|
1470
|
-
return this;
|
|
1471
|
-
};
|
|
1472
|
-
EventEmitter.prototype.removeAllListeners = function removeAllListeners(event) {
|
|
1473
|
-
var evt;
|
|
1474
|
-
if (event) {
|
|
1475
|
-
evt = prefix ? prefix + event : event;
|
|
1476
|
-
if (this._events[evt]) clearEvent(this, evt);
|
|
1477
|
-
} else {
|
|
1478
|
-
this._events = new Events();
|
|
1479
|
-
this._eventsCount = 0;
|
|
1480
|
-
}
|
|
1481
|
-
return this;
|
|
1482
|
-
};
|
|
1483
|
-
EventEmitter.prototype.off = EventEmitter.prototype.removeListener;
|
|
1484
|
-
EventEmitter.prototype.addListener = EventEmitter.prototype.on;
|
|
1485
|
-
EventEmitter.prefixed = prefix;
|
|
1486
|
-
EventEmitter.EventEmitter = EventEmitter;
|
|
1487
|
-
if ("undefined" !== typeof module) module.exports = EventEmitter;
|
|
1488
|
-
}))(), 1)).default();
|
|
1489
|
-
var useRemoteAwareness = ({ handle, localUserId, offlineTimeout = 3e4, getTime = () => (/* @__PURE__ */ new Date()).getTime() }) => {
|
|
1490
|
-
const [peerStates, setPeerStates, peerStatesRef] = useStateRef({});
|
|
1491
|
-
const [heartbeats, setHeartbeats, heartbeatsRef] = useStateRef({});
|
|
1492
|
-
(0, import_react.useEffect)(() => {
|
|
1493
|
-
if (!handle) return;
|
|
1494
|
-
const handleIncomingUpdate = (event) => {
|
|
1495
|
-
const [userId, state] = event.message;
|
|
1496
|
-
if (userId === localUserId) return;
|
|
1497
|
-
if (!heartbeatsRef.current[userId]) peerEvents.emit("new_peer", event);
|
|
1498
|
-
setPeerStates({
|
|
1499
|
-
...peerStatesRef.current,
|
|
1500
|
-
[userId]: state
|
|
1501
|
-
});
|
|
1502
|
-
setHeartbeats({
|
|
1503
|
-
...heartbeatsRef.current,
|
|
1504
|
-
[userId]: getTime()
|
|
1505
|
-
});
|
|
1506
|
-
};
|
|
1507
|
-
const pruneOfflinePeers = () => {
|
|
1508
|
-
const peerStates2 = { ...peerStatesRef.current };
|
|
1509
|
-
const heartbeats2 = { ...heartbeatsRef.current };
|
|
1510
|
-
const time = getTime();
|
|
1511
|
-
let hasChanges = false;
|
|
1512
|
-
for (const key in heartbeats2) if (time - heartbeats2[key] > offlineTimeout) {
|
|
1513
|
-
delete peerStates2[key];
|
|
1514
|
-
delete heartbeats2[key];
|
|
1515
|
-
hasChanges = true;
|
|
1516
|
-
}
|
|
1517
|
-
if (hasChanges) {
|
|
1518
|
-
setPeerStates(peerStates2);
|
|
1519
|
-
setHeartbeats(heartbeats2);
|
|
1520
|
-
}
|
|
1521
|
-
};
|
|
1522
|
-
handle.on("ephemeral-message", handleIncomingUpdate);
|
|
1523
|
-
const pruneOfflinePeersIntervalId = setInterval(pruneOfflinePeers, offlineTimeout);
|
|
1524
|
-
return () => {
|
|
1525
|
-
handle.removeListener("ephemeral-message", handleIncomingUpdate);
|
|
1526
|
-
clearInterval(pruneOfflinePeersIntervalId);
|
|
1527
|
-
};
|
|
1528
|
-
}, [
|
|
1529
|
-
handle,
|
|
1530
|
-
localUserId,
|
|
1531
|
-
offlineTimeout,
|
|
1532
|
-
getTime
|
|
1533
|
-
]);
|
|
1534
|
-
return [peerStates, heartbeats];
|
|
1535
|
-
};
|
|
1536
|
-
var useLocalAwareness = ({ handle, userId, initialState, heartbeatTime = 15e3 }) => {
|
|
1537
|
-
const [localState, setLocalState, localStateRef] = useStateRef(initialState);
|
|
1538
|
-
const setState = (stateOrUpdater) => {
|
|
1539
|
-
const state = typeof stateOrUpdater === "function" ? stateOrUpdater(localStateRef.current) : stateOrUpdater;
|
|
1540
|
-
setLocalState(state);
|
|
1541
|
-
if (handle) handle.broadcast([userId, state]);
|
|
1542
|
-
};
|
|
1543
|
-
(0, import_react.useEffect)(() => {
|
|
1544
|
-
if (!userId || !handle) return;
|
|
1545
|
-
const heartbeat = () => void handle.broadcast([userId, localStateRef.current]);
|
|
1546
|
-
heartbeat();
|
|
1547
|
-
const heartbeatIntervalId = setInterval(heartbeat, heartbeatTime);
|
|
1548
|
-
return () => void clearInterval(heartbeatIntervalId);
|
|
1549
|
-
}, [
|
|
1550
|
-
handle,
|
|
1551
|
-
userId,
|
|
1552
|
-
heartbeatTime
|
|
1553
|
-
]);
|
|
1554
|
-
(0, import_react.useEffect)(() => {
|
|
1555
|
-
if (!handle || !userId) return;
|
|
1556
|
-
let broadcastTimeoutId;
|
|
1557
|
-
const newPeerEvents = peerEvents.on("new_peer", () => {
|
|
1558
|
-
broadcastTimeoutId = setTimeout(() => handle.broadcast([userId, localStateRef.current]), 500);
|
|
1559
|
-
});
|
|
1560
|
-
return () => {
|
|
1561
|
-
newPeerEvents.off("new_peer");
|
|
1562
|
-
broadcastTimeoutId && clearTimeout(broadcastTimeoutId);
|
|
1563
|
-
};
|
|
1564
|
-
}, [
|
|
1565
|
-
handle,
|
|
1566
|
-
userId,
|
|
1567
|
-
peerEvents
|
|
1568
|
-
]);
|
|
1569
|
-
return [localState, setState];
|
|
1570
|
-
};
|
|
1571
|
-
function usePresence({ handle, initialState, heartbeatMs, peerTtlMs }) {
|
|
1572
|
-
const [localState, setLocalState] = (0, import_react.useState)(initialState);
|
|
1573
|
-
const [peerStates, setPeerStates] = (0, import_react.useState)(new PeerStateView({}));
|
|
1574
|
-
const firstOpts = (0, import_react.useRef)({
|
|
1575
|
-
heartbeatMs,
|
|
1576
|
-
peerTtlMs
|
|
1577
|
-
});
|
|
1578
|
-
const firstInitialState = (0, import_react.useRef)(initialState);
|
|
1579
|
-
const [presence] = (0, import_react.useState)(() => new Presence({ handle }));
|
|
1580
|
-
(0, import_react.useEffect)(() => {
|
|
1581
|
-
presence.start({
|
|
1582
|
-
initialState: firstInitialState.current,
|
|
1583
|
-
...firstOpts.current
|
|
1584
|
-
});
|
|
1585
|
-
presence.on("heartbeat", () => setPeerStates(presence.getPeerStates()));
|
|
1586
|
-
presence.on("snapshot", () => setPeerStates(presence.getPeerStates()));
|
|
1587
|
-
presence.on("update", () => setPeerStates(presence.getPeerStates()));
|
|
1588
|
-
presence.on("goodbye", () => setPeerStates(presence.getPeerStates()));
|
|
1589
|
-
presence.on("pruned", () => setPeerStates(presence.getPeerStates()));
|
|
1590
|
-
return () => {
|
|
1591
|
-
presence.stop();
|
|
1592
|
-
};
|
|
1593
|
-
}, [
|
|
1594
|
-
presence,
|
|
1595
|
-
firstInitialState,
|
|
1596
|
-
firstOpts
|
|
1597
|
-
]);
|
|
1598
|
-
const start = (0, import_react.useCallback)((config) => {
|
|
1599
|
-
const initialState2 = config?.initialState ?? presence.getLocalState();
|
|
1600
|
-
const opts = {
|
|
1601
|
-
...firstOpts.current,
|
|
1602
|
-
...config,
|
|
1603
|
-
initialState: initialState2
|
|
1604
|
-
};
|
|
1605
|
-
presence.start(opts);
|
|
1606
|
-
}, [presence, firstOpts]);
|
|
1607
|
-
const stop = (0, import_react.useCallback)(() => {
|
|
1608
|
-
presence.stop();
|
|
1609
|
-
}, [presence]);
|
|
1610
|
-
return {
|
|
1611
|
-
peerStates,
|
|
1612
|
-
localState,
|
|
1613
|
-
update: (0, import_react.useCallback)((channel, msg) => {
|
|
1614
|
-
presence.broadcast(channel, msg);
|
|
1615
|
-
setLocalState(presence.getLocalState());
|
|
1616
|
-
}, [presence]),
|
|
1617
|
-
start,
|
|
1618
|
-
stop
|
|
1619
|
-
};
|
|
1620
|
-
}
|
|
1621
|
-
|
|
1622
|
-
// node_modules/.pnpm/@automerge+react@2.6.0-subduction.47_react-dom@18.3.1_react@18.3.1__react@18.3.1_supports-color@7.2.0/node_modules/@automerge/react/dist/default-exports.js
|
|
1623
|
-
import { BroadcastChannelNetworkAdapter } from "@automerge/automerge-repo-network-broadcastchannel";
|
|
1624
|
-
import { MessageChannelNetworkAdapter } from "@automerge/automerge-repo-network-messagechannel";
|
|
1625
|
-
import { WebSocketClientAdapter } from "@automerge/automerge-repo-network-websocket";
|
|
1626
|
-
import { IndexedDBStorageAdapter } from "@automerge/automerge-repo-storage-indexeddb";
|
|
1627
|
-
|
|
1628
|
-
// src/lith/useAutomergeStore.ts
|
|
1629
|
-
var import_react3 = __toESM(require_react(), 1);
|
|
1630
|
-
|
|
1631
|
-
// node_modules/.pnpm/@automerge+automerge-repo-react-hooks@2.6.0-subduction.46_react-dom@18.3.1_react@18.3.1_4b92195feb6ea50576810c4c883087b2/node_modules/@automerge/automerge-repo-react-hooks/dist/index.js
|
|
1632
|
-
var import_react2 = __toESM(require_react(), 1);
|
|
1633
|
-
import { PeerStateView as PeerStateView2, Presence as Presence2 } from "@automerge/automerge-repo/slim";
|
|
1634
|
-
var __create2 = Object.create;
|
|
1635
|
-
var __defProp2 = Object.defineProperty;
|
|
1636
|
-
var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor;
|
|
1637
|
-
var __getOwnPropNames2 = Object.getOwnPropertyNames;
|
|
1638
|
-
var __getProtoOf2 = Object.getPrototypeOf;
|
|
1639
|
-
var __hasOwnProp2 = Object.prototype.hasOwnProperty;
|
|
1640
|
-
var __commonJSMin2 = (cb, mod) => () => (mod || (cb((mod = { exports: {} }).exports, mod), cb = null), mod.exports);
|
|
1641
|
-
var __copyProps2 = (to, from, except, desc) => {
|
|
1642
|
-
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames2(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
1643
|
-
key = keys[i];
|
|
1644
|
-
if (!__hasOwnProp2.call(to, key) && key !== except) __defProp2(to, key, {
|
|
1645
|
-
get: ((k) => from[k]).bind(null, key),
|
|
1646
|
-
enumerable: !(desc = __getOwnPropDesc2(from, key)) || desc.enumerable
|
|
1647
|
-
});
|
|
1648
|
-
}
|
|
1649
|
-
return to;
|
|
1650
|
-
};
|
|
1651
|
-
var __toESM3 = (mod, isNodeMode, target) => (target = mod != null ? __create2(__getProtoOf2(mod)) : {}, __copyProps2(isNodeMode || !mod || !mod.__esModule ? __defProp2(target, "default", {
|
|
1652
|
-
value: mod,
|
|
1653
|
-
enumerable: true
|
|
1654
|
-
}) : target, mod));
|
|
1655
|
-
var RepoContext2 = (0, import_react2.createContext)(null);
|
|
1656
|
-
function isBytes2(a) {
|
|
1657
|
-
return a instanceof Uint8Array || ArrayBuffer.isView(a) && a.constructor.name === "Uint8Array";
|
|
1658
|
-
}
|
|
1659
|
-
function abytes2(b, ...lengths) {
|
|
1660
|
-
if (!isBytes2(b)) throw new Error("Uint8Array expected");
|
|
1661
|
-
if (lengths.length > 0 && !lengths.includes(b.length)) throw new Error("Uint8Array expected of length " + lengths + ", got length=" + b.length);
|
|
1662
|
-
}
|
|
1663
|
-
function aexists2(instance, checkFinished = true) {
|
|
1664
|
-
if (instance.destroyed) throw new Error("Hash instance has been destroyed");
|
|
1665
|
-
if (checkFinished && instance.finished) throw new Error("Hash#digest() has already been called");
|
|
1666
|
-
}
|
|
1667
|
-
function aoutput2(out, instance) {
|
|
1668
|
-
abytes2(out);
|
|
1669
|
-
const min = instance.outputLen;
|
|
1670
|
-
if (out.length < min) throw new Error("digestInto() expects output buffer of length at least " + min);
|
|
1671
|
-
}
|
|
1672
|
-
function clean2(...arrays) {
|
|
1673
|
-
for (let i = 0; i < arrays.length; i++) arrays[i].fill(0);
|
|
1674
|
-
}
|
|
1675
|
-
function createView2(arr) {
|
|
1676
|
-
return new DataView(arr.buffer, arr.byteOffset, arr.byteLength);
|
|
1677
|
-
}
|
|
1678
|
-
function rotr2(word, shift) {
|
|
1679
|
-
return word << 32 - shift | word >>> shift;
|
|
1680
|
-
}
|
|
1681
|
-
function utf8ToBytes2(str) {
|
|
1682
|
-
if (typeof str !== "string") throw new Error("string expected");
|
|
1683
|
-
return new Uint8Array(new TextEncoder().encode(str));
|
|
1684
|
-
}
|
|
1685
|
-
function toBytes2(data) {
|
|
1686
|
-
if (typeof data === "string") data = utf8ToBytes2(data);
|
|
1687
|
-
abytes2(data);
|
|
1688
|
-
return data;
|
|
1689
|
-
}
|
|
1690
|
-
var Hash2 = class {
|
|
1691
|
-
};
|
|
1692
|
-
function createHasher2(hashCons) {
|
|
1693
|
-
const hashC = (msg) => hashCons().update(toBytes2(msg)).digest();
|
|
1694
|
-
const tmp = hashCons();
|
|
1695
|
-
hashC.outputLen = tmp.outputLen;
|
|
1696
|
-
hashC.blockLen = tmp.blockLen;
|
|
1697
|
-
hashC.create = () => hashCons();
|
|
1698
|
-
return hashC;
|
|
1699
|
-
}
|
|
1700
|
-
function setBigUint642(view2, byteOffset, value, isLE) {
|
|
1701
|
-
if (typeof view2.setBigUint64 === "function") return view2.setBigUint64(byteOffset, value, isLE);
|
|
1702
|
-
const _32n = BigInt(32);
|
|
1703
|
-
const _u32_max = BigInt(4294967295);
|
|
1704
|
-
const wh = Number(value >> _32n & _u32_max);
|
|
1705
|
-
const wl = Number(value & _u32_max);
|
|
1706
|
-
const h = isLE ? 4 : 0;
|
|
1707
|
-
const l = isLE ? 0 : 4;
|
|
1708
|
-
view2.setUint32(byteOffset + h, wh, isLE);
|
|
1709
|
-
view2.setUint32(byteOffset + l, wl, isLE);
|
|
1710
|
-
}
|
|
1711
|
-
function Chi2(a, b, c) {
|
|
1712
|
-
return a & b ^ ~a & c;
|
|
1713
|
-
}
|
|
1714
|
-
function Maj2(a, b, c) {
|
|
1715
|
-
return a & b ^ a & c ^ b & c;
|
|
1716
|
-
}
|
|
1717
|
-
var HashMD2 = class extends Hash2 {
|
|
1718
|
-
constructor(blockLen, outputLen, padOffset, isLE) {
|
|
1719
|
-
super();
|
|
1720
|
-
this.finished = false;
|
|
1721
|
-
this.length = 0;
|
|
1722
|
-
this.pos = 0;
|
|
1723
|
-
this.destroyed = false;
|
|
1724
|
-
this.blockLen = blockLen;
|
|
1725
|
-
this.outputLen = outputLen;
|
|
1726
|
-
this.padOffset = padOffset;
|
|
1727
|
-
this.isLE = isLE;
|
|
1728
|
-
this.buffer = new Uint8Array(blockLen);
|
|
1729
|
-
this.view = createView2(this.buffer);
|
|
1730
|
-
}
|
|
1731
|
-
update(data) {
|
|
1732
|
-
aexists2(this);
|
|
1733
|
-
data = toBytes2(data);
|
|
1734
|
-
abytes2(data);
|
|
1735
|
-
const { view: view2, buffer, blockLen } = this;
|
|
1736
|
-
const len = data.length;
|
|
1737
|
-
for (let pos = 0; pos < len; ) {
|
|
1738
|
-
const take = Math.min(blockLen - this.pos, len - pos);
|
|
1739
|
-
if (take === blockLen) {
|
|
1740
|
-
const dataView = createView2(data);
|
|
1741
|
-
for (; blockLen <= len - pos; pos += blockLen) this.process(dataView, pos);
|
|
1742
|
-
continue;
|
|
1743
|
-
}
|
|
1744
|
-
buffer.set(data.subarray(pos, pos + take), this.pos);
|
|
1745
|
-
this.pos += take;
|
|
1746
|
-
pos += take;
|
|
1747
|
-
if (this.pos === blockLen) {
|
|
1748
|
-
this.process(view2, 0);
|
|
1749
|
-
this.pos = 0;
|
|
1750
|
-
}
|
|
1751
|
-
}
|
|
1752
|
-
this.length += data.length;
|
|
1753
|
-
this.roundClean();
|
|
1754
|
-
return this;
|
|
1755
|
-
}
|
|
1756
|
-
digestInto(out) {
|
|
1757
|
-
aexists2(this);
|
|
1758
|
-
aoutput2(out, this);
|
|
1759
|
-
this.finished = true;
|
|
1760
|
-
const { buffer, view: view2, blockLen, isLE } = this;
|
|
1761
|
-
let { pos } = this;
|
|
1762
|
-
buffer[pos++] = 128;
|
|
1763
|
-
clean2(this.buffer.subarray(pos));
|
|
1764
|
-
if (this.padOffset > blockLen - pos) {
|
|
1765
|
-
this.process(view2, 0);
|
|
1766
|
-
pos = 0;
|
|
1767
|
-
}
|
|
1768
|
-
for (let i = pos; i < blockLen; i++) buffer[i] = 0;
|
|
1769
|
-
setBigUint642(view2, blockLen - 8, BigInt(this.length * 8), isLE);
|
|
1770
|
-
this.process(view2, 0);
|
|
1771
|
-
const oview = createView2(out);
|
|
1772
|
-
const len = this.outputLen;
|
|
1773
|
-
if (len % 4) throw new Error("_sha2: outputLen should be aligned to 32bit");
|
|
1774
|
-
const outLen = len / 4;
|
|
1775
|
-
const state = this.get();
|
|
1776
|
-
if (outLen > state.length) throw new Error("_sha2: outputLen bigger than state");
|
|
1777
|
-
for (let i = 0; i < outLen; i++) oview.setUint32(4 * i, state[i], isLE);
|
|
1778
|
-
}
|
|
1779
|
-
digest() {
|
|
1780
|
-
const { buffer, outputLen } = this;
|
|
1781
|
-
this.digestInto(buffer);
|
|
1782
|
-
const res = buffer.slice(0, outputLen);
|
|
1783
|
-
this.destroy();
|
|
1784
|
-
return res;
|
|
1785
|
-
}
|
|
1786
|
-
_cloneInto(to) {
|
|
1787
|
-
to || (to = new this.constructor());
|
|
1788
|
-
to.set(...this.get());
|
|
1789
|
-
const { blockLen, buffer, length, finished, destroyed, pos } = this;
|
|
1790
|
-
to.destroyed = destroyed;
|
|
1791
|
-
to.finished = finished;
|
|
1792
|
-
to.length = length;
|
|
1793
|
-
to.pos = pos;
|
|
1794
|
-
if (length % blockLen) to.buffer.set(buffer);
|
|
1795
|
-
return to;
|
|
1796
|
-
}
|
|
1797
|
-
clone() {
|
|
1798
|
-
return this._cloneInto();
|
|
1799
|
-
}
|
|
1800
|
-
};
|
|
1801
|
-
var SHA256_IV2 = /* @__PURE__ */ Uint32Array.from([
|
|
1802
|
-
1779033703,
|
|
1803
|
-
3144134277,
|
|
1804
|
-
1013904242,
|
|
1805
|
-
2773480762,
|
|
1806
|
-
1359893119,
|
|
1807
|
-
2600822924,
|
|
1808
|
-
528734635,
|
|
1809
|
-
1541459225
|
|
1810
|
-
]);
|
|
1811
|
-
var SHA256_K2 = /* @__PURE__ */ Uint32Array.from([
|
|
1812
|
-
1116352408,
|
|
1813
|
-
1899447441,
|
|
1814
|
-
3049323471,
|
|
1815
|
-
3921009573,
|
|
1816
|
-
961987163,
|
|
1817
|
-
1508970993,
|
|
1818
|
-
2453635748,
|
|
1819
|
-
2870763221,
|
|
1820
|
-
3624381080,
|
|
1821
|
-
310598401,
|
|
1822
|
-
607225278,
|
|
1823
|
-
1426881987,
|
|
1824
|
-
1925078388,
|
|
1825
|
-
2162078206,
|
|
1826
|
-
2614888103,
|
|
1827
|
-
3248222580,
|
|
1828
|
-
3835390401,
|
|
1829
|
-
4022224774,
|
|
1830
|
-
264347078,
|
|
1831
|
-
604807628,
|
|
1832
|
-
770255983,
|
|
1833
|
-
1249150122,
|
|
1834
|
-
1555081692,
|
|
1835
|
-
1996064986,
|
|
1836
|
-
2554220882,
|
|
1837
|
-
2821834349,
|
|
1838
|
-
2952996808,
|
|
1839
|
-
3210313671,
|
|
1840
|
-
3336571891,
|
|
1841
|
-
3584528711,
|
|
1842
|
-
113926993,
|
|
1843
|
-
338241895,
|
|
1844
|
-
666307205,
|
|
1845
|
-
773529912,
|
|
1846
|
-
1294757372,
|
|
1847
|
-
1396182291,
|
|
1848
|
-
1695183700,
|
|
1849
|
-
1986661051,
|
|
1850
|
-
2177026350,
|
|
1851
|
-
2456956037,
|
|
1852
|
-
2730485921,
|
|
1853
|
-
2820302411,
|
|
1854
|
-
3259730800,
|
|
1855
|
-
3345764771,
|
|
1856
|
-
3516065817,
|
|
1857
|
-
3600352804,
|
|
1858
|
-
4094571909,
|
|
1859
|
-
275423344,
|
|
1860
|
-
430227734,
|
|
1861
|
-
506948616,
|
|
1862
|
-
659060556,
|
|
1863
|
-
883997877,
|
|
1864
|
-
958139571,
|
|
1865
|
-
1322822218,
|
|
1866
|
-
1537002063,
|
|
1867
|
-
1747873779,
|
|
1868
|
-
1955562222,
|
|
1869
|
-
2024104815,
|
|
1870
|
-
2227730452,
|
|
1871
|
-
2361852424,
|
|
1872
|
-
2428436474,
|
|
1873
|
-
2756734187,
|
|
1874
|
-
3204031479,
|
|
1875
|
-
3329325298
|
|
1876
|
-
]);
|
|
1877
|
-
var SHA256_W2 = /* @__PURE__ */ new Uint32Array(64);
|
|
1878
|
-
var SHA2562 = class extends HashMD2 {
|
|
1879
|
-
constructor(outputLen = 32) {
|
|
1880
|
-
super(64, outputLen, 8, false);
|
|
1881
|
-
this.A = SHA256_IV2[0] | 0;
|
|
1882
|
-
this.B = SHA256_IV2[1] | 0;
|
|
1883
|
-
this.C = SHA256_IV2[2] | 0;
|
|
1884
|
-
this.D = SHA256_IV2[3] | 0;
|
|
1885
|
-
this.E = SHA256_IV2[4] | 0;
|
|
1886
|
-
this.F = SHA256_IV2[5] | 0;
|
|
1887
|
-
this.G = SHA256_IV2[6] | 0;
|
|
1888
|
-
this.H = SHA256_IV2[7] | 0;
|
|
1889
|
-
}
|
|
1890
|
-
get() {
|
|
1891
|
-
const { A, B, C, D, E, F, G, H } = this;
|
|
1892
|
-
return [
|
|
1893
|
-
A,
|
|
1894
|
-
B,
|
|
1895
|
-
C,
|
|
1896
|
-
D,
|
|
1897
|
-
E,
|
|
1898
|
-
F,
|
|
1899
|
-
G,
|
|
1900
|
-
H
|
|
1901
|
-
];
|
|
1902
|
-
}
|
|
1903
|
-
set(A, B, C, D, E, F, G, H) {
|
|
1904
|
-
this.A = A | 0;
|
|
1905
|
-
this.B = B | 0;
|
|
1906
|
-
this.C = C | 0;
|
|
1907
|
-
this.D = D | 0;
|
|
1908
|
-
this.E = E | 0;
|
|
1909
|
-
this.F = F | 0;
|
|
1910
|
-
this.G = G | 0;
|
|
1911
|
-
this.H = H | 0;
|
|
1912
|
-
}
|
|
1913
|
-
process(view2, offset) {
|
|
1914
|
-
for (let i = 0; i < 16; i++, offset += 4) SHA256_W2[i] = view2.getUint32(offset, false);
|
|
1915
|
-
for (let i = 16; i < 64; i++) {
|
|
1916
|
-
const W15 = SHA256_W2[i - 15];
|
|
1917
|
-
const W2 = SHA256_W2[i - 2];
|
|
1918
|
-
const s0 = rotr2(W15, 7) ^ rotr2(W15, 18) ^ W15 >>> 3;
|
|
1919
|
-
SHA256_W2[i] = (rotr2(W2, 17) ^ rotr2(W2, 19) ^ W2 >>> 10) + SHA256_W2[i - 7] + s0 + SHA256_W2[i - 16] | 0;
|
|
1920
|
-
}
|
|
1921
|
-
let { A, B, C, D, E, F, G, H } = this;
|
|
1922
|
-
for (let i = 0; i < 64; i++) {
|
|
1923
|
-
const sigma1 = rotr2(E, 6) ^ rotr2(E, 11) ^ rotr2(E, 25);
|
|
1924
|
-
const T1 = H + sigma1 + Chi2(E, F, G) + SHA256_K2[i] + SHA256_W2[i] | 0;
|
|
1925
|
-
const T2 = (rotr2(A, 2) ^ rotr2(A, 13) ^ rotr2(A, 22)) + Maj2(A, B, C) | 0;
|
|
1926
|
-
H = G;
|
|
1927
|
-
G = F;
|
|
1928
|
-
F = E;
|
|
1929
|
-
E = D + T1 | 0;
|
|
1930
|
-
D = C;
|
|
1931
|
-
C = B;
|
|
1932
|
-
B = A;
|
|
1933
|
-
A = T1 + T2 | 0;
|
|
1934
|
-
}
|
|
1935
|
-
A = A + this.A | 0;
|
|
1936
|
-
B = B + this.B | 0;
|
|
1937
|
-
C = C + this.C | 0;
|
|
1938
|
-
D = D + this.D | 0;
|
|
1939
|
-
E = E + this.E | 0;
|
|
1940
|
-
F = F + this.F | 0;
|
|
1941
|
-
G = G + this.G | 0;
|
|
1942
|
-
H = H + this.H | 0;
|
|
1943
|
-
this.set(A, B, C, D, E, F, G, H);
|
|
1944
|
-
}
|
|
1945
|
-
roundClean() {
|
|
1946
|
-
clean2(SHA256_W2);
|
|
1947
|
-
}
|
|
1948
|
-
destroy() {
|
|
1949
|
-
this.set(0, 0, 0, 0, 0, 0, 0, 0);
|
|
1950
|
-
clean2(this.buffer);
|
|
1951
|
-
}
|
|
1952
|
-
};
|
|
1953
|
-
var sha2562 = /* @__PURE__ */ createHasher2(() => new SHA2562());
|
|
1954
|
-
function base2(ALPHABET) {
|
|
1955
|
-
if (ALPHABET.length >= 255) throw new TypeError("Alphabet too long");
|
|
1956
|
-
const BASE_MAP = new Uint8Array(256);
|
|
1957
|
-
for (let j = 0; j < BASE_MAP.length; j++) BASE_MAP[j] = 255;
|
|
1958
|
-
for (let i = 0; i < ALPHABET.length; i++) {
|
|
1959
|
-
const x = ALPHABET.charAt(i);
|
|
1960
|
-
const xc = x.charCodeAt(0);
|
|
1961
|
-
if (BASE_MAP[xc] !== 255) throw new TypeError(x + " is ambiguous");
|
|
1962
|
-
BASE_MAP[xc] = i;
|
|
1963
|
-
}
|
|
1964
|
-
const BASE = ALPHABET.length;
|
|
1965
|
-
const LEADER = ALPHABET.charAt(0);
|
|
1966
|
-
const FACTOR = Math.log(BASE) / Math.log(256);
|
|
1967
|
-
const iFACTOR = Math.log(256) / Math.log(BASE);
|
|
1968
|
-
function encode(source) {
|
|
1969
|
-
if (source instanceof Uint8Array) {
|
|
1970
|
-
} else if (ArrayBuffer.isView(source)) source = new Uint8Array(source.buffer, source.byteOffset, source.byteLength);
|
|
1971
|
-
else if (Array.isArray(source)) source = Uint8Array.from(source);
|
|
1972
|
-
if (!(source instanceof Uint8Array)) throw new TypeError("Expected Uint8Array");
|
|
1973
|
-
if (source.length === 0) return "";
|
|
1974
|
-
let zeroes = 0;
|
|
1975
|
-
let length = 0;
|
|
1976
|
-
let pbegin = 0;
|
|
1977
|
-
const pend = source.length;
|
|
1978
|
-
while (pbegin !== pend && source[pbegin] === 0) {
|
|
1979
|
-
pbegin++;
|
|
1980
|
-
zeroes++;
|
|
1981
|
-
}
|
|
1982
|
-
const size = (pend - pbegin) * iFACTOR + 1 >>> 0;
|
|
1983
|
-
const b58 = new Uint8Array(size);
|
|
1984
|
-
while (pbegin !== pend) {
|
|
1985
|
-
let carry = source[pbegin];
|
|
1986
|
-
let i = 0;
|
|
1987
|
-
for (let it1 = size - 1; (carry !== 0 || i < length) && it1 !== -1; it1--, i++) {
|
|
1988
|
-
carry += 256 * b58[it1] >>> 0;
|
|
1989
|
-
b58[it1] = carry % BASE >>> 0;
|
|
1990
|
-
carry = carry / BASE >>> 0;
|
|
1991
|
-
}
|
|
1992
|
-
if (carry !== 0) throw new Error("Non-zero carry");
|
|
1993
|
-
length = i;
|
|
1994
|
-
pbegin++;
|
|
1995
|
-
}
|
|
1996
|
-
let it2 = size - length;
|
|
1997
|
-
while (it2 !== size && b58[it2] === 0) it2++;
|
|
1998
|
-
let str = LEADER.repeat(zeroes);
|
|
1999
|
-
for (; it2 < size; ++it2) str += ALPHABET.charAt(b58[it2]);
|
|
2000
|
-
return str;
|
|
2001
|
-
}
|
|
2002
|
-
function decodeUnsafe(source) {
|
|
2003
|
-
if (typeof source !== "string") throw new TypeError("Expected String");
|
|
2004
|
-
if (source.length === 0) return new Uint8Array();
|
|
2005
|
-
let psz = 0;
|
|
2006
|
-
let zeroes = 0;
|
|
2007
|
-
let length = 0;
|
|
2008
|
-
while (source[psz] === LEADER) {
|
|
2009
|
-
zeroes++;
|
|
2010
|
-
psz++;
|
|
2011
|
-
}
|
|
2012
|
-
const size = (source.length - psz) * FACTOR + 1 >>> 0;
|
|
2013
|
-
const b256 = new Uint8Array(size);
|
|
2014
|
-
while (psz < source.length) {
|
|
2015
|
-
const charCode = source.charCodeAt(psz);
|
|
2016
|
-
if (charCode > 255) return;
|
|
2017
|
-
let carry = BASE_MAP[charCode];
|
|
2018
|
-
if (carry === 255) return;
|
|
2019
|
-
let i = 0;
|
|
2020
|
-
for (let it3 = size - 1; (carry !== 0 || i < length) && it3 !== -1; it3--, i++) {
|
|
2021
|
-
carry += BASE * b256[it3] >>> 0;
|
|
2022
|
-
b256[it3] = carry % 256 >>> 0;
|
|
2023
|
-
carry = carry / 256 >>> 0;
|
|
2024
|
-
}
|
|
2025
|
-
if (carry !== 0) throw new Error("Non-zero carry");
|
|
2026
|
-
length = i;
|
|
2027
|
-
psz++;
|
|
2028
|
-
}
|
|
2029
|
-
let it4 = size - length;
|
|
2030
|
-
while (it4 !== size && b256[it4] === 0) it4++;
|
|
2031
|
-
const vch = new Uint8Array(zeroes + (size - it4));
|
|
2032
|
-
let j = zeroes;
|
|
2033
|
-
while (it4 !== size) vch[j++] = b256[it4++];
|
|
2034
|
-
return vch;
|
|
2035
|
-
}
|
|
2036
|
-
function decode(string) {
|
|
2037
|
-
const buffer = decodeUnsafe(string);
|
|
2038
|
-
if (buffer) return buffer;
|
|
2039
|
-
throw new Error("Non-base" + BASE + " character");
|
|
2040
|
-
}
|
|
2041
|
-
return {
|
|
2042
|
-
encode,
|
|
2043
|
-
decodeUnsafe,
|
|
2044
|
-
decode
|
|
2045
|
-
};
|
|
2046
|
-
}
|
|
2047
|
-
var esm_default$12 = base2("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");
|
|
2048
|
-
function base_default2(checksumFn) {
|
|
2049
|
-
function encode(payload) {
|
|
2050
|
-
var payloadU8 = Uint8Array.from(payload);
|
|
2051
|
-
var checksum = checksumFn(payloadU8);
|
|
2052
|
-
var length = payloadU8.length + 4;
|
|
2053
|
-
var both = new Uint8Array(length);
|
|
2054
|
-
both.set(payloadU8, 0);
|
|
2055
|
-
both.set(checksum.subarray(0, 4), payloadU8.length);
|
|
2056
|
-
return esm_default$12.encode(both);
|
|
2057
|
-
}
|
|
2058
|
-
function decodeRaw(buffer) {
|
|
2059
|
-
var payload = buffer.slice(0, -4);
|
|
2060
|
-
var checksum = buffer.slice(-4);
|
|
2061
|
-
var newChecksum = checksumFn(payload);
|
|
2062
|
-
if (checksum[0] ^ newChecksum[0] | checksum[1] ^ newChecksum[1] | checksum[2] ^ newChecksum[2] | checksum[3] ^ newChecksum[3]) return;
|
|
2063
|
-
return payload;
|
|
2064
|
-
}
|
|
2065
|
-
function decodeUnsafe(str) {
|
|
2066
|
-
var buffer = esm_default$12.decodeUnsafe(str);
|
|
2067
|
-
if (buffer == null) return;
|
|
2068
|
-
return decodeRaw(buffer);
|
|
642
|
+
},
|
|
643
|
+
serialize: (seg) => {
|
|
644
|
+
if (seg.key === "") throw new Error("Path keys cannot be empty strings");
|
|
645
|
+
const needsEscape = ESCAPE_TRIGGERS.some((p) => seg.key.startsWith(p));
|
|
646
|
+
const encoded = encodeURIComponent(seg.key);
|
|
647
|
+
return needsEscape ? `${ESCAPE_PREFIX}${encoded}` : encoded;
|
|
2069
648
|
}
|
|
2070
|
-
|
|
2071
|
-
|
|
2072
|
-
|
|
2073
|
-
return
|
|
649
|
+
};
|
|
650
|
+
function safeDecodeURIComponent(s) {
|
|
651
|
+
try {
|
|
652
|
+
return decodeURIComponent(s);
|
|
653
|
+
} catch {
|
|
654
|
+
return s;
|
|
2074
655
|
}
|
|
2075
|
-
return {
|
|
2076
|
-
encode,
|
|
2077
|
-
decode,
|
|
2078
|
-
decodeUnsafe
|
|
2079
|
-
};
|
|
2080
656
|
}
|
|
2081
|
-
|
|
2082
|
-
|
|
657
|
+
var SEGMENT_CODECS = [
|
|
658
|
+
indexCodec,
|
|
659
|
+
matchCodec,
|
|
660
|
+
cursorsCodec,
|
|
661
|
+
keyCodec
|
|
662
|
+
];
|
|
663
|
+
function parseSegment(segment) {
|
|
664
|
+
for (const codec of SEGMENT_CODECS) if (codec.match(segment)) return codec.parse(segment);
|
|
665
|
+
throw new Error(`Invalid segment: "${segment}"`);
|
|
666
|
+
}
|
|
667
|
+
function serializeSegment(segment) {
|
|
668
|
+
for (const codec of SEGMENT_CODECS) if (segment["AUTOMERGE_REF_KIND"] === codec.kind) return codec.serialize(segment);
|
|
669
|
+
throw new Error(`No codec found for segment kind: ${segment[KIND]}`);
|
|
670
|
+
}
|
|
671
|
+
function parsePath(path) {
|
|
672
|
+
if (!path) return [];
|
|
673
|
+
const trimmed = path.replace(/^\/+|\/+$/g, "");
|
|
674
|
+
if (!trimmed) throw new Error("Invalid path: path cannot be empty or consist only of slashes");
|
|
675
|
+
if (trimmed.includes("//")) throw new Error("Invalid path: contains empty segment (double slash)");
|
|
676
|
+
return trimmed.split("/").map(parseSegment);
|
|
677
|
+
}
|
|
678
|
+
function serializePath(segments) {
|
|
679
|
+
return segments.map(serializeSegment).join("/");
|
|
2083
680
|
}
|
|
2084
|
-
var
|
|
2085
|
-
var require_ms2 = /* @__PURE__ */ __commonJSMin2((exports, module) => {
|
|
681
|
+
var require_ms = /* @__PURE__ */ __commonJSMin((exports, module) => {
|
|
2086
682
|
var s = 1e3;
|
|
2087
683
|
var m = s * 60;
|
|
2088
684
|
var h = m * 60;
|
|
@@ -2166,7 +762,7 @@ var require_ms2 = /* @__PURE__ */ __commonJSMin2((exports, module) => {
|
|
|
2166
762
|
return Math.round(ms / n) + " " + name + (isPlural ? "s" : "");
|
|
2167
763
|
}
|
|
2168
764
|
});
|
|
2169
|
-
var
|
|
765
|
+
var require_common = /* @__PURE__ */ __commonJSMin((exports, module) => {
|
|
2170
766
|
function setup(env) {
|
|
2171
767
|
createDebug.debug = createDebug;
|
|
2172
768
|
createDebug.default = createDebug;
|
|
@@ -2174,7 +770,7 @@ var require_common2 = /* @__PURE__ */ __commonJSMin2((exports, module) => {
|
|
|
2174
770
|
createDebug.disable = disable;
|
|
2175
771
|
createDebug.enable = enable;
|
|
2176
772
|
createDebug.enabled = enabled;
|
|
2177
|
-
createDebug.humanize =
|
|
773
|
+
createDebug.humanize = require_ms();
|
|
2178
774
|
createDebug.destroy = destroy;
|
|
2179
775
|
Object.keys(env).forEach((key) => {
|
|
2180
776
|
createDebug[key] = env[key];
|
|
@@ -2302,7 +898,7 @@ var require_common2 = /* @__PURE__ */ __commonJSMin2((exports, module) => {
|
|
|
2302
898
|
}
|
|
2303
899
|
module.exports = setup;
|
|
2304
900
|
});
|
|
2305
|
-
(/* @__PURE__ */
|
|
901
|
+
(/* @__PURE__ */ __commonJSMin((exports, module) => {
|
|
2306
902
|
exports.formatArgs = formatArgs;
|
|
2307
903
|
exports.save = save;
|
|
2308
904
|
exports.load = load;
|
|
@@ -2439,7 +1035,7 @@ var require_common2 = /* @__PURE__ */ __commonJSMin2((exports, module) => {
|
|
|
2439
1035
|
} catch (error) {
|
|
2440
1036
|
}
|
|
2441
1037
|
}
|
|
2442
|
-
module.exports =
|
|
1038
|
+
module.exports = require_common()(exports);
|
|
2443
1039
|
var { formatters } = module.exports;
|
|
2444
1040
|
formatters.j = function(v) {
|
|
2445
1041
|
try {
|
|
@@ -2449,7 +1045,161 @@ var require_common2 = /* @__PURE__ */ __commonJSMin2((exports, module) => {
|
|
|
2449
1045
|
}
|
|
2450
1046
|
};
|
|
2451
1047
|
}))();
|
|
2452
|
-
var
|
|
1048
|
+
var urlPrefix = "automerge:";
|
|
1049
|
+
var parseAutomergeUrl = (url) => {
|
|
1050
|
+
const [baseUrl, headsSection, ...rest] = url.split("#");
|
|
1051
|
+
if (rest.length > 0) throw new Error("Invalid URL: contains multiple heads sections");
|
|
1052
|
+
const match = baseUrl.match(new RegExp(`^${urlPrefix}([^/]+)(?:\\/(.*))?$`));
|
|
1053
|
+
if (!match) throw new Error("Invalid document URL: " + url);
|
|
1054
|
+
const [, docMatch, pathStr] = match;
|
|
1055
|
+
const documentId = docMatch;
|
|
1056
|
+
const binaryDocumentId = documentIdToBinary(documentId);
|
|
1057
|
+
if (!binaryDocumentId) throw new Error("Invalid document URL: " + url);
|
|
1058
|
+
const segments = pathStr !== void 0 && pathStr.length > 0 ? parsePath(pathStr) : void 0;
|
|
1059
|
+
if (headsSection === void 0) return segments ? {
|
|
1060
|
+
binaryDocumentId,
|
|
1061
|
+
documentId,
|
|
1062
|
+
segments
|
|
1063
|
+
} : {
|
|
1064
|
+
binaryDocumentId,
|
|
1065
|
+
documentId
|
|
1066
|
+
};
|
|
1067
|
+
const heads = headsSection === "" ? [] : headsSection.split("|");
|
|
1068
|
+
const hexHeads = heads.map((head) => {
|
|
1069
|
+
try {
|
|
1070
|
+
return uint8ArrayToHexString(esm_default.decode(head));
|
|
1071
|
+
} catch (e) {
|
|
1072
|
+
throw new Error(`Invalid head in URL: ${head}`);
|
|
1073
|
+
}
|
|
1074
|
+
});
|
|
1075
|
+
return segments ? {
|
|
1076
|
+
binaryDocumentId,
|
|
1077
|
+
hexHeads,
|
|
1078
|
+
documentId,
|
|
1079
|
+
heads,
|
|
1080
|
+
segments
|
|
1081
|
+
} : {
|
|
1082
|
+
binaryDocumentId,
|
|
1083
|
+
hexHeads,
|
|
1084
|
+
documentId,
|
|
1085
|
+
heads
|
|
1086
|
+
};
|
|
1087
|
+
};
|
|
1088
|
+
var stringifyAutomergeUrl = (arg) => {
|
|
1089
|
+
if (arg instanceof Uint8Array || typeof arg === "string") return urlPrefix + (arg instanceof Uint8Array ? binaryToDocumentId(arg) : arg);
|
|
1090
|
+
const { documentId, heads = void 0, segments = void 0 } = arg;
|
|
1091
|
+
if (documentId === void 0) throw new Error("Invalid documentId: " + documentId);
|
|
1092
|
+
let url = `${urlPrefix}${documentId instanceof Uint8Array ? binaryToDocumentId(documentId) : documentId}`;
|
|
1093
|
+
if (segments !== void 0 && segments.length > 0) url += "/" + serializePath(segments);
|
|
1094
|
+
if (heads !== void 0) {
|
|
1095
|
+
heads.forEach((head) => {
|
|
1096
|
+
try {
|
|
1097
|
+
esm_default.decode(head);
|
|
1098
|
+
} catch (e) {
|
|
1099
|
+
throw new Error(`Invalid head: ${head}`);
|
|
1100
|
+
}
|
|
1101
|
+
});
|
|
1102
|
+
url += "#" + [...heads].sort().join("|");
|
|
1103
|
+
}
|
|
1104
|
+
return url;
|
|
1105
|
+
};
|
|
1106
|
+
var anyDocumentIdToAutomergeUrl = (id) => isValidAutomergeUrl(id) ? id : isValidDocumentId(id) ? stringifyAutomergeUrl({ documentId: id }) : isValidUuid(id) ? parseLegacyUUID(id) : void 0;
|
|
1107
|
+
var isValidAutomergeUrl = (str) => {
|
|
1108
|
+
if (typeof str !== "string" || !str || !str.startsWith("automerge:")) return false;
|
|
1109
|
+
try {
|
|
1110
|
+
const { documentId, heads } = parseAutomergeUrl(str);
|
|
1111
|
+
if (!isValidDocumentId(documentId)) return false;
|
|
1112
|
+
if (heads && !heads.every((head) => {
|
|
1113
|
+
try {
|
|
1114
|
+
esm_default.decode(head);
|
|
1115
|
+
return true;
|
|
1116
|
+
} catch {
|
|
1117
|
+
return false;
|
|
1118
|
+
}
|
|
1119
|
+
})) return false;
|
|
1120
|
+
return true;
|
|
1121
|
+
} catch {
|
|
1122
|
+
return false;
|
|
1123
|
+
}
|
|
1124
|
+
};
|
|
1125
|
+
var isValidDocumentId = (str) => {
|
|
1126
|
+
if (typeof str !== "string") return false;
|
|
1127
|
+
return documentIdToBinary(str) !== void 0;
|
|
1128
|
+
};
|
|
1129
|
+
var isValidUuid = (str) => typeof str === "string" && validate(str);
|
|
1130
|
+
var documentIdToBinary = (docId) => esm_default.decodeUnsafe(docId);
|
|
1131
|
+
var binaryToDocumentId = (docId) => esm_default.encode(docId);
|
|
1132
|
+
var parseLegacyUUID = (str) => {
|
|
1133
|
+
if (!validate(str)) return void 0;
|
|
1134
|
+
return stringifyAutomergeUrl({ documentId: parse(str) });
|
|
1135
|
+
};
|
|
1136
|
+
var wrapperCache = /* @__PURE__ */ new Map();
|
|
1137
|
+
function useDocHandle(id, { suspense } = { suspense: false }) {
|
|
1138
|
+
const repo = useRepo();
|
|
1139
|
+
const controllerRef = (0, import_react.useRef)(void 0);
|
|
1140
|
+
const [handle, setHandle] = (0, import_react.useState)();
|
|
1141
|
+
let currentHandle = id && handle && handle.url === anyDocumentIdToAutomergeUrl(id) ? handle : void 0;
|
|
1142
|
+
if (id && !currentHandle) {
|
|
1143
|
+
const state = repo.findWithProgress(id).peek();
|
|
1144
|
+
if (state.state === "ready") currentHandle = state.handle;
|
|
1145
|
+
}
|
|
1146
|
+
let wrapper = id ? wrapperCache.get(id) : void 0;
|
|
1147
|
+
if (!wrapper && id) {
|
|
1148
|
+
controllerRef.current?.abort();
|
|
1149
|
+
controllerRef.current = new AbortController();
|
|
1150
|
+
wrapper = wrapPromise(repo.find(id, { signal: controllerRef.current.signal }));
|
|
1151
|
+
wrapperCache.set(id, wrapper);
|
|
1152
|
+
}
|
|
1153
|
+
(0, import_react.useEffect)(() => {
|
|
1154
|
+
if (currentHandle || suspense || !wrapper) return;
|
|
1155
|
+
let active = true;
|
|
1156
|
+
wrapper.promise.then((handle2) => {
|
|
1157
|
+
if (active) setHandle(handle2);
|
|
1158
|
+
}).catch(() => {
|
|
1159
|
+
if (id && wrapperCache.get(id) === wrapper) wrapperCache.delete(id);
|
|
1160
|
+
if (active) setHandle(void 0);
|
|
1161
|
+
});
|
|
1162
|
+
return () => {
|
|
1163
|
+
active = false;
|
|
1164
|
+
};
|
|
1165
|
+
}, [
|
|
1166
|
+
currentHandle,
|
|
1167
|
+
suspense,
|
|
1168
|
+
wrapper,
|
|
1169
|
+
id
|
|
1170
|
+
]);
|
|
1171
|
+
if (currentHandle || !suspense || !wrapper) return currentHandle;
|
|
1172
|
+
return wrapper.read();
|
|
1173
|
+
}
|
|
1174
|
+
function useDocument(id, params = { suspense: false }) {
|
|
1175
|
+
const handle = useDocHandle(id, params);
|
|
1176
|
+
const [doc, setDoc] = (0, import_react.useState)(() => handle?.doc());
|
|
1177
|
+
const [deleteError, setDeleteError] = (0, import_react.useState)();
|
|
1178
|
+
(0, import_react.useEffect)(() => {
|
|
1179
|
+
setDoc(handle?.doc());
|
|
1180
|
+
}, [handle]);
|
|
1181
|
+
(0, import_react.useEffect)(() => {
|
|
1182
|
+
if (!handle) return;
|
|
1183
|
+
const onChange = () => setDoc(handle.doc());
|
|
1184
|
+
const onDelete = () => {
|
|
1185
|
+
setDeleteError(/* @__PURE__ */ new Error(`Document ${id} was deleted`));
|
|
1186
|
+
};
|
|
1187
|
+
handle.on("change", onChange);
|
|
1188
|
+
handle.on("delete", onDelete);
|
|
1189
|
+
return () => {
|
|
1190
|
+
handle.removeListener("change", onChange);
|
|
1191
|
+
handle.removeListener("delete", onDelete);
|
|
1192
|
+
};
|
|
1193
|
+
}, [handle, id]);
|
|
1194
|
+
const changeDoc = (0, import_react.useCallback)((changeFn, options) => {
|
|
1195
|
+
handle.change(changeFn, options);
|
|
1196
|
+
}, [handle]);
|
|
1197
|
+
if (deleteError) throw deleteError;
|
|
1198
|
+
if (!doc) return [void 0, () => {
|
|
1199
|
+
}];
|
|
1200
|
+
return [doc, changeDoc];
|
|
1201
|
+
}
|
|
1202
|
+
var peerEvents = new (/* @__PURE__ */ __toESM2((/* @__PURE__ */ __commonJSMin((exports, module) => {
|
|
2453
1203
|
var has = Object.prototype.hasOwnProperty, prefix = "~";
|
|
2454
1204
|
function Events() {
|
|
2455
1205
|
}
|
|
@@ -2585,16 +1335,16 @@ var peerEvents2 = new (/* @__PURE__ */ __toESM3((/* @__PURE__ */ __commonJSMin2(
|
|
|
2585
1335
|
EventEmitter.EventEmitter = EventEmitter;
|
|
2586
1336
|
if ("undefined" !== typeof module) module.exports = EventEmitter;
|
|
2587
1337
|
}))(), 1)).default();
|
|
2588
|
-
function
|
|
2589
|
-
const [localState, setLocalState] = (0,
|
|
2590
|
-
const [peerStates, setPeerStates] = (0,
|
|
2591
|
-
const firstOpts = (0,
|
|
1338
|
+
function usePresence({ handle, initialState, heartbeatMs, peerTtlMs }) {
|
|
1339
|
+
const [localState, setLocalState] = (0, import_react.useState)(initialState);
|
|
1340
|
+
const [peerStates, setPeerStates] = (0, import_react.useState)(new PeerStateView({}));
|
|
1341
|
+
const firstOpts = (0, import_react.useRef)({
|
|
2592
1342
|
heartbeatMs,
|
|
2593
1343
|
peerTtlMs
|
|
2594
1344
|
});
|
|
2595
|
-
const firstInitialState = (0,
|
|
2596
|
-
const [presence] = (0,
|
|
2597
|
-
(0,
|
|
1345
|
+
const firstInitialState = (0, import_react.useRef)(initialState);
|
|
1346
|
+
const [presence] = (0, import_react.useState)(() => new Presence({ handle }));
|
|
1347
|
+
(0, import_react.useEffect)(() => {
|
|
2598
1348
|
presence.start({
|
|
2599
1349
|
initialState: firstInitialState.current,
|
|
2600
1350
|
...firstOpts.current
|
|
@@ -2612,7 +1362,7 @@ function usePresence2({ handle, initialState, heartbeatMs, peerTtlMs }) {
|
|
|
2612
1362
|
firstInitialState,
|
|
2613
1363
|
firstOpts
|
|
2614
1364
|
]);
|
|
2615
|
-
const start = (0,
|
|
1365
|
+
const start = (0, import_react.useCallback)((config) => {
|
|
2616
1366
|
const initialState2 = config?.initialState ?? presence.getLocalState();
|
|
2617
1367
|
const opts = {
|
|
2618
1368
|
...firstOpts.current,
|
|
@@ -2621,13 +1371,13 @@ function usePresence2({ handle, initialState, heartbeatMs, peerTtlMs }) {
|
|
|
2621
1371
|
};
|
|
2622
1372
|
presence.start(opts);
|
|
2623
1373
|
}, [presence, firstOpts]);
|
|
2624
|
-
const stop = (0,
|
|
1374
|
+
const stop = (0, import_react.useCallback)(() => {
|
|
2625
1375
|
presence.stop();
|
|
2626
1376
|
}, [presence]);
|
|
2627
1377
|
return {
|
|
2628
1378
|
peerStates,
|
|
2629
1379
|
localState,
|
|
2630
|
-
update: (0,
|
|
1380
|
+
update: (0, import_react.useCallback)((channel, msg) => {
|
|
2631
1381
|
presence.broadcast(channel, msg);
|
|
2632
1382
|
setLocalState(presence.getLocalState());
|
|
2633
1383
|
}, [presence]),
|
|
@@ -2636,6 +1386,9 @@ function usePresence2({ handle, initialState, heartbeatMs, peerTtlMs }) {
|
|
|
2636
1386
|
};
|
|
2637
1387
|
}
|
|
2638
1388
|
|
|
1389
|
+
// src/lith/useAutomergeStore.ts
|
|
1390
|
+
var import_react2 = __toESM(require_react(), 1);
|
|
1391
|
+
|
|
2639
1392
|
// src/lith/AutomergeToTLStore.ts
|
|
2640
1393
|
function applyAutomergePatchesToTLStore(patches, store, doc) {
|
|
2641
1394
|
const changedIds = /* @__PURE__ */ new Set();
|
|
@@ -2667,16 +1420,16 @@ function useAutomergeStore({
|
|
|
2667
1420
|
bindingUtils = [],
|
|
2668
1421
|
readOnly = false
|
|
2669
1422
|
}) {
|
|
2670
|
-
const [store] = (0,
|
|
1423
|
+
const [store] = (0, import_react2.useState)(() => {
|
|
2671
1424
|
const store2 = createTLStore({ shapeUtils, bindingUtils });
|
|
2672
1425
|
return store2;
|
|
2673
1426
|
});
|
|
2674
|
-
const [storeWithStatus, setStoreWithStatus] = (0,
|
|
1427
|
+
const [storeWithStatus, setStoreWithStatus] = (0, import_react2.useState)({
|
|
2675
1428
|
status: "loading"
|
|
2676
1429
|
});
|
|
2677
|
-
const readOnlyRef = (0,
|
|
1430
|
+
const readOnlyRef = (0, import_react2.useRef)(readOnly);
|
|
2678
1431
|
readOnlyRef.current = readOnly;
|
|
2679
|
-
(0,
|
|
1432
|
+
(0, import_react2.useEffect)(() => {
|
|
2680
1433
|
const unsubs = [];
|
|
2681
1434
|
let preventPatchApplications = false;
|
|
2682
1435
|
function syncStoreChangesToAutomergeDoc({
|
|
@@ -2751,8 +1504,8 @@ function useAutomergeStore({
|
|
|
2751
1504
|
return storeWithStatus;
|
|
2752
1505
|
}
|
|
2753
1506
|
function useIsHandleReadOnly(handle) {
|
|
2754
|
-
const [readOnly, setReadOnly] = (0,
|
|
2755
|
-
(0,
|
|
1507
|
+
const [readOnly, setReadOnly] = (0, import_react2.useState)(() => handle.isReadOnly());
|
|
1508
|
+
(0, import_react2.useEffect)(() => {
|
|
2756
1509
|
setReadOnly(handle.isReadOnly());
|
|
2757
1510
|
const onChange = (payload) => {
|
|
2758
1511
|
if (payload.scopeReplaced) setReadOnly(handle.isReadOnly());
|
|
@@ -2764,7 +1517,7 @@ function useIsHandleReadOnly(handle) {
|
|
|
2764
1517
|
}
|
|
2765
1518
|
function useClearHistoryOnScopeSwap(handle) {
|
|
2766
1519
|
const editor = useEditor();
|
|
2767
|
-
(0,
|
|
1520
|
+
(0, import_react2.useEffect)(() => {
|
|
2768
1521
|
if (!editor) return;
|
|
2769
1522
|
const onChange = (payload) => {
|
|
2770
1523
|
if (payload.scopeReplaced) editor.clearHistory();
|
|
@@ -2782,11 +1535,11 @@ function useAutomergePresence({
|
|
|
2782
1535
|
const innerStore = store?.store;
|
|
2783
1536
|
const { userId, name, color } = userMetadata;
|
|
2784
1537
|
const isCursorActive = useIsCursorActive(element);
|
|
2785
|
-
const { peerStates, update, stop } =
|
|
1538
|
+
const { peerStates, update, stop } = usePresence({
|
|
2786
1539
|
handle,
|
|
2787
1540
|
initialState: { presence: null }
|
|
2788
1541
|
});
|
|
2789
|
-
(0,
|
|
1542
|
+
(0, import_react2.useEffect)(() => {
|
|
2790
1543
|
if (!innerStore) return;
|
|
2791
1544
|
const toPut = peerStates.peers.filter((peer) => peer.value?.presence).map((peer) => ({
|
|
2792
1545
|
...peer.value.presence,
|
|
@@ -2796,7 +1549,7 @@ function useAutomergePresence({
|
|
|
2796
1549
|
if (toRemove.length) innerStore.remove(toRemove);
|
|
2797
1550
|
if (toPut.length) innerStore.put(toPut);
|
|
2798
1551
|
}, [innerStore, peerStates]);
|
|
2799
|
-
(0,
|
|
1552
|
+
(0, import_react2.useEffect)(() => {
|
|
2800
1553
|
if (!innerStore) return;
|
|
2801
1554
|
const user = computed("user", () => ({
|
|
2802
1555
|
typeName: "user",
|
|
@@ -2833,11 +1586,11 @@ function useAutomergePresence({
|
|
|
2833
1586
|
}, [innerStore, userId, name, color, update, stop, isCursorActive]);
|
|
2834
1587
|
}
|
|
2835
1588
|
function useIsCursorActive(element) {
|
|
2836
|
-
const [isFocused, setIsFocused] = (0,
|
|
2837
|
-
const [isPointerOver, setIsPointerOver] = (0,
|
|
1589
|
+
const [isFocused, setIsFocused] = (0, import_react2.useState)(() => document.hasFocus());
|
|
1590
|
+
const [isPointerOver, setIsPointerOver] = (0, import_react2.useState)(
|
|
2838
1591
|
() => element.matches(":hover")
|
|
2839
1592
|
);
|
|
2840
|
-
(0,
|
|
1593
|
+
(0, import_react2.useEffect)(() => {
|
|
2841
1594
|
const onFocus = () => setIsFocused(true);
|
|
2842
1595
|
const onBlur = () => setIsFocused(false);
|
|
2843
1596
|
const onEnter = () => setIsPointerOver(true);
|
|
@@ -2857,16 +1610,16 @@ function useIsCursorActive(element) {
|
|
|
2857
1610
|
}
|
|
2858
1611
|
|
|
2859
1612
|
// src/tool.tsx
|
|
2860
|
-
var
|
|
1613
|
+
var import_react11 = __toESM(require_react(), 1);
|
|
2861
1614
|
import { automergeUrlToServiceWorkerUrl as automergeUrlToServiceWorkerUrl2 } from "@inkandswitch/patchwork-filesystem";
|
|
2862
1615
|
|
|
2863
1616
|
// node_modules/.pnpm/@inkandswitch+patchwork-providers-react@0.2.6_@automerge+automerge-repo-react-hooks@2.6_80ffcbcf3e158b4c39ecf6aef28824ac/node_modules/@inkandswitch/patchwork-providers-react/dist/index.js
|
|
2864
|
-
var
|
|
1617
|
+
var import_react3 = __toESM(require_react(), 1);
|
|
2865
1618
|
import * as Providers from "@inkandswitch/patchwork-providers";
|
|
2866
1619
|
function useSubscribe(element, selector, initialValue) {
|
|
2867
|
-
const [value, setValue] = (0,
|
|
1620
|
+
const [value, setValue] = (0, import_react3.useState)(initialValue);
|
|
2868
1621
|
const key = JSON.stringify(selector);
|
|
2869
|
-
(0,
|
|
1622
|
+
(0, import_react3.useEffect)(() => {
|
|
2870
1623
|
const unsubscribe = Providers.subscribe(element, selector, (v) => {
|
|
2871
1624
|
setValue(() => v);
|
|
2872
1625
|
});
|
|
@@ -2907,12 +1660,12 @@ function diffStore(doc, headsBefore) {
|
|
|
2907
1660
|
}
|
|
2908
1661
|
|
|
2909
1662
|
// src/DiffShapeWrapper.tsx
|
|
2910
|
-
var
|
|
1663
|
+
var import_react4 = __toESM(require_react(), 1);
|
|
2911
1664
|
var import_jsx_runtime = __toESM(require_jsx_runtime(), 1);
|
|
2912
|
-
var DiffStatusContext = (0,
|
|
2913
|
-
var DiffShapeWrapper = (0,
|
|
1665
|
+
var DiffStatusContext = (0, import_react4.createContext)(null);
|
|
1666
|
+
var DiffShapeWrapper = (0, import_react4.forwardRef)(
|
|
2914
1667
|
function DiffShapeWrapper2({ children, shape, isBackground }, ref) {
|
|
2915
|
-
const statusAtom = (0,
|
|
1668
|
+
const statusAtom = (0, import_react4.useContext)(DiffStatusContext);
|
|
2916
1669
|
const status = useValue(
|
|
2917
1670
|
"diff status",
|
|
2918
1671
|
() => statusAtom?.get().get(shape.id),
|
|
@@ -2932,13 +1685,13 @@ var DiffShapeWrapper = (0, import_react5.forwardRef)(
|
|
|
2932
1685
|
);
|
|
2933
1686
|
|
|
2934
1687
|
// src/PatchworkDocShape.tsx
|
|
2935
|
-
var
|
|
1688
|
+
var import_react5 = __toESM(require_react(), 1);
|
|
2936
1689
|
import {
|
|
2937
1690
|
getRegistry,
|
|
2938
1691
|
getSupportedToolsForType
|
|
2939
1692
|
} from "@inkandswitch/patchwork-plugins";
|
|
2940
1693
|
var import_jsx_runtime2 = __toESM(require_jsx_runtime(), 1);
|
|
2941
|
-
var
|
|
1694
|
+
var import_react6 = (
|
|
2942
1695
|
// @ts-expect-error Custom element from @inkandswitch/patchwork-elements
|
|
2943
1696
|
__toESM(require_react(), 1)
|
|
2944
1697
|
);
|
|
@@ -3014,7 +1767,7 @@ function getDefaultToolId(datatypeId) {
|
|
|
3014
1767
|
}
|
|
3015
1768
|
}
|
|
3016
1769
|
function useSupportedTools(docType) {
|
|
3017
|
-
return (0,
|
|
1770
|
+
return (0, import_react5.useMemo)(() => {
|
|
3018
1771
|
if (!docType) return [];
|
|
3019
1772
|
try {
|
|
3020
1773
|
return getSupportedToolsForType(docType).filter((t) => !t.unlisted);
|
|
@@ -3053,20 +1806,20 @@ function PatchworkDocComponent({ shape }) {
|
|
|
3053
1806
|
[editor, shape.id]
|
|
3054
1807
|
);
|
|
3055
1808
|
const isFocused = isEditingShape;
|
|
3056
|
-
const [isEditingName, setIsEditingName] = (0,
|
|
3057
|
-
const [toolMenuOpen, setToolMenuOpen] = (0,
|
|
3058
|
-
const nameInputRef = (0,
|
|
3059
|
-
const containerRef = (0,
|
|
3060
|
-
const contentRef = (0,
|
|
3061
|
-
const toolMenuRef = (0,
|
|
1809
|
+
const [isEditingName, setIsEditingName] = (0, import_react5.useState)(false);
|
|
1810
|
+
const [toolMenuOpen, setToolMenuOpen] = (0, import_react5.useState)(false);
|
|
1811
|
+
const nameInputRef = (0, import_react5.useRef)(null);
|
|
1812
|
+
const containerRef = (0, import_react5.useRef)(null);
|
|
1813
|
+
const contentRef = (0, import_react5.useRef)(null);
|
|
1814
|
+
const toolMenuRef = (0, import_react5.useRef)(null);
|
|
3062
1815
|
const currentTool = tools.find((t) => t.id === toolId) ?? tools[0];
|
|
3063
|
-
(0,
|
|
1816
|
+
(0, import_react5.useEffect)(() => {
|
|
3064
1817
|
if (isEditingName && nameInputRef.current) {
|
|
3065
1818
|
nameInputRef.current.focus();
|
|
3066
1819
|
nameInputRef.current.select();
|
|
3067
1820
|
}
|
|
3068
1821
|
}, [isEditingName]);
|
|
3069
|
-
(0,
|
|
1822
|
+
(0, import_react5.useEffect)(() => {
|
|
3070
1823
|
if (!toolMenuOpen) return;
|
|
3071
1824
|
const handler = (e) => {
|
|
3072
1825
|
if (toolMenuRef.current && !toolMenuRef.current.contains(e.target)) {
|
|
@@ -3076,7 +1829,7 @@ function PatchworkDocComponent({ shape }) {
|
|
|
3076
1829
|
window.addEventListener("pointerdown", handler, true);
|
|
3077
1830
|
return () => window.removeEventListener("pointerdown", handler, true);
|
|
3078
1831
|
}, [toolMenuOpen]);
|
|
3079
|
-
(0,
|
|
1832
|
+
(0, import_react5.useEffect)(() => {
|
|
3080
1833
|
if (!isFocused) return;
|
|
3081
1834
|
const el = contentRef.current;
|
|
3082
1835
|
if (!el) return;
|
|
@@ -3102,7 +1855,7 @@ function PatchworkDocComponent({ shape }) {
|
|
|
3102
1855
|
el.removeEventListener("pointerup", stopPointer, true);
|
|
3103
1856
|
};
|
|
3104
1857
|
}, [isFocused]);
|
|
3105
|
-
const handleToolChange = (0,
|
|
1858
|
+
const handleToolChange = (0, import_react5.useCallback)(
|
|
3106
1859
|
(newToolId) => {
|
|
3107
1860
|
editor.updateShape({
|
|
3108
1861
|
id: shape.id,
|
|
@@ -3113,12 +1866,12 @@ function PatchworkDocComponent({ shape }) {
|
|
|
3113
1866
|
},
|
|
3114
1867
|
[editor, shape.id]
|
|
3115
1868
|
);
|
|
3116
|
-
const handleOpenDocument = (0,
|
|
1869
|
+
const handleOpenDocument = (0, import_react5.useCallback)(() => {
|
|
3117
1870
|
const el = containerRef.current;
|
|
3118
1871
|
if (!el || !docUrl) return;
|
|
3119
1872
|
openDocumentInHost(el, docUrl, toolId || void 0);
|
|
3120
1873
|
}, [docUrl, toolId]);
|
|
3121
|
-
const handleRename = (0,
|
|
1874
|
+
const handleRename = (0, import_react5.useCallback)(
|
|
3122
1875
|
async (newName) => {
|
|
3123
1876
|
const trimmed = newName.trim();
|
|
3124
1877
|
if (!trimmed || trimmed === docName || !docUrl || !docType) {
|
|
@@ -3408,7 +2161,7 @@ function PatchworkDocComponent({ shape }) {
|
|
|
3408
2161
|
alt: docName,
|
|
3409
2162
|
style: { width: "100%", height: "100%", objectFit: "contain" }
|
|
3410
2163
|
}
|
|
3411
|
-
) : docUrl ? /* @__PURE__ */ (0,
|
|
2164
|
+
) : docUrl ? /* @__PURE__ */ (0, import_react6.createElement)(
|
|
3412
2165
|
"patchwork-view",
|
|
3413
2166
|
{
|
|
3414
2167
|
"doc-url": docUrl,
|
|
@@ -3446,7 +2199,7 @@ async function loadDatatype(id) {
|
|
|
3446
2199
|
}
|
|
3447
2200
|
|
|
3448
2201
|
// src/NewDocTool.tsx
|
|
3449
|
-
var
|
|
2202
|
+
var import_react7 = __toESM(require_react(), 1);
|
|
3450
2203
|
var import_react_dom = __toESM(require_react_dom(), 1);
|
|
3451
2204
|
import {
|
|
3452
2205
|
createDocOfDatatype2,
|
|
@@ -3643,13 +2396,13 @@ function NewDocToolbar() {
|
|
|
3643
2396
|
const isActive = useValue("new-doc active", () => editor.getCurrentToolId() === "new-doc", [
|
|
3644
2397
|
editor
|
|
3645
2398
|
]);
|
|
3646
|
-
const [datatypes, setDatatypes] = (0,
|
|
3647
|
-
const [menuOpen, setMenuOpen] = (0,
|
|
3648
|
-
const [selectedId, setSelectedId] = (0,
|
|
3649
|
-
const [menuPos, setMenuPos] = (0,
|
|
3650
|
-
const buttonRef = (0,
|
|
3651
|
-
const menuRef = (0,
|
|
3652
|
-
(0,
|
|
2399
|
+
const [datatypes, setDatatypes] = (0, import_react7.useState)([]);
|
|
2400
|
+
const [menuOpen, setMenuOpen] = (0, import_react7.useState)(false);
|
|
2401
|
+
const [selectedId, setSelectedId] = (0, import_react7.useState)(_selectedDatatypeId);
|
|
2402
|
+
const [menuPos, setMenuPos] = (0, import_react7.useState)(null);
|
|
2403
|
+
const buttonRef = (0, import_react7.useRef)(null);
|
|
2404
|
+
const menuRef = (0, import_react7.useRef)(null);
|
|
2405
|
+
(0, import_react7.useEffect)(() => {
|
|
3653
2406
|
const dt = getListedDatatypeDescriptions();
|
|
3654
2407
|
setDatatypes(dt);
|
|
3655
2408
|
if (dt.length > 0 && !_selectedDatatypeId) {
|
|
@@ -3657,7 +2410,7 @@ function NewDocToolbar() {
|
|
|
3657
2410
|
setSelectedId(dt[0].id);
|
|
3658
2411
|
}
|
|
3659
2412
|
}, []);
|
|
3660
|
-
(0,
|
|
2413
|
+
(0, import_react7.useEffect)(() => {
|
|
3661
2414
|
if (!menuOpen) return;
|
|
3662
2415
|
const handler = (e) => {
|
|
3663
2416
|
const t = e.target;
|
|
@@ -3667,7 +2420,7 @@ function NewDocToolbar() {
|
|
|
3667
2420
|
document.addEventListener("pointerdown", handler, true);
|
|
3668
2421
|
return () => document.removeEventListener("pointerdown", handler, true);
|
|
3669
2422
|
}, [menuOpen]);
|
|
3670
|
-
const openMenu = (0,
|
|
2423
|
+
const openMenu = (0, import_react7.useCallback)(() => {
|
|
3671
2424
|
if (buttonRef.current) {
|
|
3672
2425
|
const rect = buttonRef.current.getBoundingClientRect();
|
|
3673
2426
|
setMenuPos({ x: rect.left + rect.width / 2, y: rect.top });
|
|
@@ -3675,7 +2428,7 @@ function NewDocToolbar() {
|
|
|
3675
2428
|
setDatatypes(getListedDatatypeDescriptions());
|
|
3676
2429
|
setMenuOpen(true);
|
|
3677
2430
|
}, []);
|
|
3678
|
-
const handlePlusClick = (0,
|
|
2431
|
+
const handlePlusClick = (0, import_react7.useCallback)(() => {
|
|
3679
2432
|
if (datatypes.length > 0 && !_selectedDatatypeId) {
|
|
3680
2433
|
setSelectedDatatypeId(datatypes[0].id);
|
|
3681
2434
|
setSelectedId(datatypes[0].id);
|
|
@@ -3686,7 +2439,7 @@ function NewDocToolbar() {
|
|
|
3686
2439
|
else requestAnimationFrame(openMenu);
|
|
3687
2440
|
}
|
|
3688
2441
|
}, [datatypes, editor, menuOpen, openMenu]);
|
|
3689
|
-
const handlePick = (0,
|
|
2442
|
+
const handlePick = (0, import_react7.useCallback)(
|
|
3690
2443
|
(id) => {
|
|
3691
2444
|
setSelectedDatatypeId(id);
|
|
3692
2445
|
setSelectedId(id);
|
|
@@ -3868,7 +2621,7 @@ function urlFromText(line) {
|
|
|
3868
2621
|
}
|
|
3869
2622
|
|
|
3870
2623
|
// src/migrate.tsx
|
|
3871
|
-
var
|
|
2624
|
+
var import_react8 = __toESM(require_react(), 1);
|
|
3872
2625
|
import {
|
|
3873
2626
|
getRegistry as getRegistry3
|
|
3874
2627
|
} from "@inkandswitch/patchwork-plugins";
|
|
@@ -3914,8 +2667,8 @@ function MigratePrompt({
|
|
|
3914
2667
|
handle,
|
|
3915
2668
|
readOnly
|
|
3916
2669
|
}) {
|
|
3917
|
-
const [error, setError] = (0,
|
|
3918
|
-
const [busy, setBusy] = (0,
|
|
2670
|
+
const [error, setError] = (0, import_react8.useState)(null);
|
|
2671
|
+
const [busy, setBusy] = (0, import_react8.useState)(false);
|
|
3919
2672
|
const onMigrate = () => {
|
|
3920
2673
|
setBusy(true);
|
|
3921
2674
|
setError(null);
|
|
@@ -3940,7 +2693,7 @@ function MigratePrompt({
|
|
|
3940
2693
|
}
|
|
3941
2694
|
|
|
3942
2695
|
// src/color-scheme.ts
|
|
3943
|
-
var
|
|
2696
|
+
var import_react9 = __toESM(require_react(), 1);
|
|
3944
2697
|
function prefersDark() {
|
|
3945
2698
|
return window.matchMedia("(prefers-color-scheme: dark)").matches;
|
|
3946
2699
|
}
|
|
@@ -3953,10 +2706,10 @@ function resolveColorScheme(element) {
|
|
|
3953
2706
|
return prefersDark() ? "dark" : "light";
|
|
3954
2707
|
}
|
|
3955
2708
|
function useColorScheme(element) {
|
|
3956
|
-
const [scheme, setScheme] = (0,
|
|
2709
|
+
const [scheme, setScheme] = (0, import_react9.useState)(
|
|
3957
2710
|
() => resolveColorScheme(element)
|
|
3958
2711
|
);
|
|
3959
|
-
(0,
|
|
2712
|
+
(0, import_react9.useEffect)(() => {
|
|
3960
2713
|
const update = () => setScheme(resolveColorScheme(element));
|
|
3961
2714
|
update();
|
|
3962
2715
|
const media = window.matchMedia("(prefers-color-scheme: dark)");
|
|
@@ -3973,13 +2726,13 @@ function useColorScheme(element) {
|
|
|
3973
2726
|
}
|
|
3974
2727
|
|
|
3975
2728
|
// src/file-io.tsx
|
|
3976
|
-
var
|
|
2729
|
+
var import_react10 = __toESM(require_react(), 1);
|
|
3977
2730
|
import {
|
|
3978
2731
|
createDocOfDatatype2 as createDocOfDatatype22,
|
|
3979
2732
|
getRegistry as getRegistry4
|
|
3980
2733
|
} from "@inkandswitch/patchwork-plugins";
|
|
3981
2734
|
var import_jsx_runtime5 = __toESM(require_jsx_runtime(), 1);
|
|
3982
|
-
var archiveModule = () => import("./tldr-archive-
|
|
2735
|
+
var archiveModule = () => import("./tldr-archive-5X7EMHWZ.js");
|
|
3983
2736
|
var ARCHIVE_EXTENSIONS = [".tldraw", ".tldr"];
|
|
3984
2737
|
var SCRIPT_ENTRY = "main.js";
|
|
3985
2738
|
function isTldrArchiveFile(file) {
|
|
@@ -3990,7 +2743,7 @@ async function importArchiveFile(file, repo) {
|
|
|
3990
2743
|
const bytes = new Uint8Array(await file.arrayBuffer());
|
|
3991
2744
|
const { readTldrArchive } = await archiveModule();
|
|
3992
2745
|
const archive = await readTldrArchive(bytes, baseName(file.name));
|
|
3993
|
-
const { extractScriptFiles, storeScriptFiles } = await import("./script-
|
|
2746
|
+
const { extractScriptFiles, storeScriptFiles } = await import("./script-4RKE5JKT.js");
|
|
3994
2747
|
const docs = await storeScriptFiles(repo, extractScriptFiles(archive.files));
|
|
3995
2748
|
const pageId = Object.keys(archive.store).find((id) => id.startsWith("page:"));
|
|
3996
2749
|
if (pageId) {
|
|
@@ -4060,7 +2813,7 @@ async function exportDoc(handle, repo) {
|
|
|
4060
2813
|
const snapshot = JSON.parse(JSON.stringify(doc));
|
|
4061
2814
|
const title = getTitle(snapshot) || "Untitled";
|
|
4062
2815
|
const { store, dropped } = withoutEmbeddedDocs(snapshot.store);
|
|
4063
|
-
const scriptFiles = doc.docs?.length ? await (await import("./script-
|
|
2816
|
+
const scriptFiles = doc.docs?.length ? await (await import("./script-4RKE5JKT.js")).readScriptFiles(repo, doc.docs) : void 0;
|
|
4064
2817
|
const { writeTldrArchive } = await archiveModule();
|
|
4065
2818
|
const bytes = await writeTldrArchive({
|
|
4066
2819
|
displayName: title,
|
|
@@ -4072,9 +2825,9 @@ async function exportDoc(handle, repo) {
|
|
|
4072
2825
|
return { dropped };
|
|
4073
2826
|
}
|
|
4074
2827
|
var MenuGroup = TldrawUiMenuGroup;
|
|
4075
|
-
var TldrFileContext = (0,
|
|
2828
|
+
var TldrFileContext = (0, import_react10.createContext)(null);
|
|
4076
2829
|
function TldrFileMainMenu() {
|
|
4077
|
-
const context = (0,
|
|
2830
|
+
const context = (0, import_react10.useContext)(TldrFileContext);
|
|
4078
2831
|
const repo = useRepo();
|
|
4079
2832
|
const { addToast } = useToasts();
|
|
4080
2833
|
const onImport = async () => {
|
|
@@ -4114,7 +2867,7 @@ function TldrFileMainMenu() {
|
|
|
4114
2867
|
const onOpenScript = async () => {
|
|
4115
2868
|
if (!context || !docs) return;
|
|
4116
2869
|
try {
|
|
4117
|
-
const { resolveScriptFiles } = await import("./script-
|
|
2870
|
+
const { resolveScriptFiles } = await import("./script-4RKE5JKT.js");
|
|
4118
2871
|
const url = (await resolveScriptFiles(repo, docs))[SCRIPT_ENTRY];
|
|
4119
2872
|
if (!url) return;
|
|
4120
2873
|
context.element.dispatchEvent(
|
|
@@ -4184,8 +2937,8 @@ function extensionForMimeType(mimeType) {
|
|
|
4184
2937
|
}
|
|
4185
2938
|
function useContactInfo() {
|
|
4186
2939
|
const repo = useRepo();
|
|
4187
|
-
const [contactUrl, setContactUrl] = (0,
|
|
4188
|
-
(0,
|
|
2940
|
+
const [contactUrl, setContactUrl] = (0, import_react11.useState)();
|
|
2941
|
+
(0, import_react11.useEffect)(() => {
|
|
4189
2942
|
const accountDocHandle = window.accountDocHandle;
|
|
4190
2943
|
if (!accountDocHandle) return;
|
|
4191
2944
|
const doc = accountDocHandle.doc();
|
|
@@ -4257,9 +3010,9 @@ function baseConfig() {
|
|
|
4257
3010
|
};
|
|
4258
3011
|
}
|
|
4259
3012
|
function useScriptConfig(repo, docs) {
|
|
4260
|
-
const [config, setConfig] = (0,
|
|
3013
|
+
const [config, setConfig] = (0, import_react11.useState)(null);
|
|
4261
3014
|
const key = docs?.length ? JSON.stringify(docs) : "";
|
|
4262
|
-
(0,
|
|
3015
|
+
(0, import_react11.useEffect)(() => {
|
|
4263
3016
|
if (!key) {
|
|
4264
3017
|
setConfig({ config: baseConfig(), version: 0 });
|
|
4265
3018
|
return;
|
|
@@ -4272,7 +3025,7 @@ function useScriptConfig(repo, docs) {
|
|
|
4272
3025
|
version: (previous?.version ?? 0) + 1
|
|
4273
3026
|
}));
|
|
4274
3027
|
void (async () => {
|
|
4275
|
-
const { watchScriptTree, runConfigScript, signatureOf } = await import("./script-
|
|
3028
|
+
const { watchScriptTree, runConfigScript, signatureOf } = await import("./script-4RKE5JKT.js");
|
|
4276
3029
|
if (cancelled) return;
|
|
4277
3030
|
let queue = Promise.resolve();
|
|
4278
3031
|
unwatch = watchScriptTree(repo, JSON.parse(key), (tree) => {
|
|
@@ -4340,15 +3093,15 @@ function TldrawConfiguredCanvas({
|
|
|
4340
3093
|
{ heads: null }
|
|
4341
3094
|
);
|
|
4342
3095
|
const diff = useShapeDiff(handle, baseline.heads ?? void 0);
|
|
4343
|
-
const [statusAtom] = (0,
|
|
3096
|
+
const [statusAtom] = (0, import_react11.useState)(
|
|
4344
3097
|
() => atom("diff status", /* @__PURE__ */ new Map())
|
|
4345
3098
|
);
|
|
4346
|
-
(0,
|
|
3099
|
+
(0, import_react11.useEffect)(() => {
|
|
4347
3100
|
statusAtom.set(buildStatusMap(diff));
|
|
4348
3101
|
}, [diff, statusAtom]);
|
|
4349
3102
|
useDeletedGhosts(store, handle, diff);
|
|
4350
3103
|
const components = config.components;
|
|
4351
|
-
const fileContext = (0,
|
|
3104
|
+
const fileContext = (0, import_react11.useMemo)(() => ({ handle, element }), [handle, element]);
|
|
4352
3105
|
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(DiffStatusContext.Provider, { value: statusAtom, children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(TldrFileContext.Provider, { value: fileContext, children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
4353
3106
|
Tldraw,
|
|
4354
3107
|
{
|
|
@@ -4368,8 +3121,8 @@ function TldrawConfiguredCanvas({
|
|
|
4368
3121
|
) }) });
|
|
4369
3122
|
}
|
|
4370
3123
|
function useShapeDiff(handle, heads) {
|
|
4371
|
-
const [tick, setTick] = (0,
|
|
4372
|
-
(0,
|
|
3124
|
+
const [tick, setTick] = (0, import_react11.useState)(0);
|
|
3125
|
+
(0, import_react11.useEffect)(() => {
|
|
4373
3126
|
let scheduled = false;
|
|
4374
3127
|
const onChange = () => {
|
|
4375
3128
|
if (scheduled) return;
|
|
@@ -4384,7 +3137,7 @@ function useShapeDiff(handle, heads) {
|
|
|
4384
3137
|
handle.off("change", onChange);
|
|
4385
3138
|
};
|
|
4386
3139
|
}, [handle]);
|
|
4387
|
-
return (0,
|
|
3140
|
+
return (0, import_react11.useMemo)(() => {
|
|
4388
3141
|
if (!heads) return null;
|
|
4389
3142
|
const doc = handle.doc();
|
|
4390
3143
|
if (!doc) return null;
|
|
@@ -4405,8 +3158,8 @@ function buildStatusMap(diff) {
|
|
|
4405
3158
|
return map;
|
|
4406
3159
|
}
|
|
4407
3160
|
function useDeletedGhosts(store, handle, diff) {
|
|
4408
|
-
const ghostIds = (0,
|
|
4409
|
-
(0,
|
|
3161
|
+
const ghostIds = (0, import_react11.useRef)(/* @__PURE__ */ new Set());
|
|
3162
|
+
(0, import_react11.useEffect)(() => {
|
|
4410
3163
|
const inner = store.store;
|
|
4411
3164
|
if (!inner) return;
|
|
4412
3165
|
const desired = /* @__PURE__ */ new Map();
|
|
@@ -4435,21 +3188,21 @@ function useDeletedGhosts(store, handle, diff) {
|
|
|
4435
3188
|
}, [store, handle, diff]);
|
|
4436
3189
|
}
|
|
4437
3190
|
function TldrawInner(props) {
|
|
4438
|
-
const key = (0,
|
|
3191
|
+
const key = (0, import_react11.useMemo)(() => `${props.docUrl}-camera`, [props.docUrl]);
|
|
4439
3192
|
const editor = useEditor();
|
|
4440
3193
|
const repo = useRepo();
|
|
4441
3194
|
const handle = useDocHandle(props.docUrl, { suspense: true });
|
|
4442
3195
|
usePatchworkDrop(props.element);
|
|
4443
3196
|
useClearHistoryOnScopeSwap(handle);
|
|
4444
3197
|
useDocumentScript(props.docUrl, editor, repo);
|
|
4445
|
-
const onChange = (0,
|
|
3198
|
+
const onChange = (0, import_react11.useCallback)(() => {
|
|
4446
3199
|
if (!editor) return;
|
|
4447
3200
|
const camstate = editor.getCameraState();
|
|
4448
3201
|
if (camstate == "moving") {
|
|
4449
3202
|
localStorage.setItem(key, JSON.stringify(editor.getCamera()));
|
|
4450
3203
|
}
|
|
4451
3204
|
}, []);
|
|
4452
|
-
(0,
|
|
3205
|
+
(0, import_react11.useEffect)(() => {
|
|
4453
3206
|
if (!editor) return;
|
|
4454
3207
|
editor.updateInstanceState({ isReadonly: props.readOnly });
|
|
4455
3208
|
setNewDocToolContext(repo, editor);
|
|
@@ -4512,13 +3265,13 @@ function TldrawInner(props) {
|
|
|
4512
3265
|
function useDocumentScript(docUrl, editor, repo) {
|
|
4513
3266
|
const [doc] = useDocument(docUrl);
|
|
4514
3267
|
const key = doc?.docs?.length ? JSON.stringify(doc.docs) : "";
|
|
4515
|
-
(0,
|
|
3268
|
+
(0, import_react11.useEffect)(() => {
|
|
4516
3269
|
if (!editor || !key) return;
|
|
4517
3270
|
let cancelled = false;
|
|
4518
3271
|
let unwatch;
|
|
4519
3272
|
let current = null;
|
|
4520
3273
|
void (async () => {
|
|
4521
|
-
const { watchScriptTree, hasScript, runScript, signatureOf } = await import("./script-
|
|
3274
|
+
const { watchScriptTree, hasScript, runScript, signatureOf } = await import("./script-4RKE5JKT.js");
|
|
4522
3275
|
if (cancelled) return;
|
|
4523
3276
|
let queue = Promise.resolve();
|
|
4524
3277
|
unwatch = watchScriptTree(repo, JSON.parse(key), (tree) => {
|
|
@@ -4556,7 +3309,7 @@ function useDocumentScript(docUrl, editor, repo) {
|
|
|
4556
3309
|
function usePatchworkDrop(element) {
|
|
4557
3310
|
const editor = useEditor();
|
|
4558
3311
|
const repo = useRepo();
|
|
4559
|
-
(0,
|
|
3312
|
+
(0, import_react11.useEffect)(() => {
|
|
4560
3313
|
if (!editor || !element) return;
|
|
4561
3314
|
const isInsideEmbeddedPatchworkView = (e) => {
|
|
4562
3315
|
for (const el of e.composedPath()) {
|
|
@@ -4690,9 +3443,6 @@ export {
|
|
|
4690
3443
|
};
|
|
4691
3444
|
/*! Bundled license information:
|
|
4692
3445
|
|
|
4693
|
-
@automerge/automerge-repo-react-hooks/dist/index.js:
|
|
4694
|
-
(*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
|
4695
|
-
|
|
4696
3446
|
@automerge/automerge-repo-react-hooks/dist/index.js:
|
|
4697
3447
|
(*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
|
4698
3448
|
*/
|