@coopcli/specsketch 2026.819.1 → 2026.825.2
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/dist/cli/index.js +80 -17
- package/dist/client/assets/{MarkdownEditorImpl-7ZHuf34p.js → MarkdownEditorImpl-B7fANsTl.js} +1 -1
- package/dist/client/assets/index-DzRQXC_d.js +197 -0
- package/dist/client/index.html +1 -1
- package/package.json +1 -1
- package/dist/client/assets/index-BD3c5qem.js +0 -197
package/dist/cli/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
// server/cli.ts
|
|
4
|
-
import { existsSync as
|
|
4
|
+
import { existsSync as existsSync9, readFileSync as readFileSync9, readdirSync as readdirSync8 } from "node:fs";
|
|
5
5
|
import { homedir as homedir4 } from "node:os";
|
|
6
6
|
import { dirname as dirname6, extname, join as join11, normalize as normalize2, resolve as resolve4 } from "node:path";
|
|
7
7
|
import { fileURLToPath } from "node:url";
|
|
@@ -2150,7 +2150,7 @@ var ChangeWorkspace = class {
|
|
|
2150
2150
|
};
|
|
2151
2151
|
|
|
2152
2152
|
// server/workbench-host.ts
|
|
2153
|
-
import { existsSync as
|
|
2153
|
+
import { existsSync as existsSync8, readFileSync as readFileSync8 } from "node:fs";
|
|
2154
2154
|
import { homedir as homedir3 } from "node:os";
|
|
2155
2155
|
import { dirname as dirname5, join as join10, resolve as resolve3 } from "node:path";
|
|
2156
2156
|
|
|
@@ -2491,6 +2491,7 @@ function changeDocument(change) {
|
|
|
2491
2491
|
design: change.design,
|
|
2492
2492
|
groups: numberTasks(change.tasks),
|
|
2493
2493
|
testing: testingRows(change.capabilities),
|
|
2494
|
+
proposalExtras: change.proposalExtras,
|
|
2494
2495
|
deltaSpecs: change.capabilities.filter(emitsDeltaSpec).map(deltaSpecDocument).sort((a, b) => a.capability < b.capability ? -1 : a.capability > b.capability ? 1 : 0)
|
|
2495
2496
|
};
|
|
2496
2497
|
}
|
|
@@ -2517,10 +2518,14 @@ ${UNSATISFIED_MARKER}
|
|
|
2517
2518
|
}
|
|
2518
2519
|
}
|
|
2519
2520
|
function renderProposal(doc) {
|
|
2521
|
+
const extras = doc.proposalExtras ?? [];
|
|
2522
|
+
const after = (id) => extras.filter((e) => e.afterSection === id).map((e) => `${e.text.trimEnd()}
|
|
2523
|
+
`);
|
|
2520
2524
|
const parts = [`# ${doc.id}
|
|
2521
|
-
|
|
2525
|
+
`, ...after(null)];
|
|
2522
2526
|
for (const spec of PROPOSAL_SECTIONS) {
|
|
2523
2527
|
parts.push(renderProposalSection(spec, doc.proposal[spec.id]));
|
|
2528
|
+
parts.push(...after(spec.id));
|
|
2524
2529
|
}
|
|
2525
2530
|
return `${parts.join("\n")}`;
|
|
2526
2531
|
}
|
|
@@ -2651,11 +2656,13 @@ function parseChangeDocument(emitted) {
|
|
|
2651
2656
|
const proposalSrc = byPath.get("proposal.md") ?? "";
|
|
2652
2657
|
const designSrc = byPath.get("design.md") ?? "";
|
|
2653
2658
|
const tasksSrc = byPath.get("tasks.md") ?? "";
|
|
2659
|
+
const parsedProposal = parseProposalFile(proposalSrc);
|
|
2654
2660
|
const groups = parseTasksFile(tasksSrc);
|
|
2655
2661
|
const deltaSpecs = emitted.files.filter((f) => f.path.startsWith("specs/") && f.path.endsWith("/spec.md")).map((f) => parseDeltaSpecFile(capabilityOfPath(f.path), f.content));
|
|
2656
2662
|
return {
|
|
2657
2663
|
id: emitted.id,
|
|
2658
|
-
proposal:
|
|
2664
|
+
proposal: parsedProposal.draft,
|
|
2665
|
+
proposalExtras: parsedProposal.extras,
|
|
2659
2666
|
design: parseDesignFile(designSrc),
|
|
2660
2667
|
groups: numberTasks(groups),
|
|
2661
2668
|
testing: parseTestingTable(tasksSrc),
|
|
@@ -2670,22 +2677,38 @@ function parseProposalFile(src) {
|
|
|
2670
2677
|
const lines = src.split("\n");
|
|
2671
2678
|
const bodies = /* @__PURE__ */ new Map();
|
|
2672
2679
|
let current = null;
|
|
2680
|
+
const extras = [];
|
|
2681
|
+
let extra = null;
|
|
2682
|
+
let lastFixed = null;
|
|
2683
|
+
const flushExtra = () => {
|
|
2684
|
+
if (!extra) return;
|
|
2685
|
+
const text = extra.lines.join("\n").trimEnd();
|
|
2686
|
+
if (text !== "") extras.push({ afterSection: extra.afterSection, text });
|
|
2687
|
+
extra = null;
|
|
2688
|
+
};
|
|
2673
2689
|
for (const line of lines) {
|
|
2674
2690
|
const p = probe2(line);
|
|
2675
2691
|
const spec = PROPOSAL_SECTIONS.find(
|
|
2676
2692
|
(s) => p === `${"#".repeat(s.level)} ${s.title}`
|
|
2677
2693
|
);
|
|
2678
2694
|
if (spec) {
|
|
2695
|
+
flushExtra();
|
|
2679
2696
|
current = spec.id;
|
|
2697
|
+
lastFixed = spec.id;
|
|
2680
2698
|
bodies.set(spec.id, []);
|
|
2681
2699
|
continue;
|
|
2682
2700
|
}
|
|
2683
2701
|
if (ANY_HEADING.test(p)) {
|
|
2702
|
+
flushExtra();
|
|
2684
2703
|
current = null;
|
|
2704
|
+
if (/^#[ \t]/.test(p) && !/^##/.test(p)) continue;
|
|
2705
|
+
extra = { afterSection: lastFixed, lines: [p] };
|
|
2685
2706
|
continue;
|
|
2686
2707
|
}
|
|
2687
2708
|
if (current) bodies.get(current).push(p);
|
|
2709
|
+
else if (extra) extra.lines.push(p);
|
|
2688
2710
|
}
|
|
2711
|
+
flushExtra();
|
|
2689
2712
|
const draft = emptyProposal();
|
|
2690
2713
|
for (const spec of PROPOSAL_SECTIONS) {
|
|
2691
2714
|
const collected = [...bodies.get(spec.id) ?? []];
|
|
@@ -2702,7 +2725,7 @@ function parseProposalFile(src) {
|
|
|
2702
2725
|
}
|
|
2703
2726
|
draft[spec.id] = { state: "authored", body };
|
|
2704
2727
|
}
|
|
2705
|
-
return draft;
|
|
2728
|
+
return { draft, extras };
|
|
2706
2729
|
}
|
|
2707
2730
|
var DESIGN_HEADING = /^##[ \t]+(.*)$/;
|
|
2708
2731
|
function parseDesignFile(src) {
|
|
@@ -3013,10 +3036,29 @@ function validateDesign(change) {
|
|
|
3013
3036
|
});
|
|
3014
3037
|
return findings;
|
|
3015
3038
|
}
|
|
3039
|
+
function draftIsWholeAgain(entry) {
|
|
3040
|
+
const declared = entry.declaredRequirements ?? [];
|
|
3041
|
+
if (declared.length === 0) return false;
|
|
3042
|
+
return declared.every(
|
|
3043
|
+
(name) => new RegExp(`^###[ \\t]+Requirement:[ \\t]*${escapeForRegExp(name)}\\s*$`, "m").test(entry.draft)
|
|
3044
|
+
);
|
|
3045
|
+
}
|
|
3046
|
+
function escapeForRegExp(text) {
|
|
3047
|
+
return text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
3048
|
+
}
|
|
3016
3049
|
function validateCapabilities(change) {
|
|
3017
3050
|
const findings = [];
|
|
3018
3051
|
let derivedDeltas = 0;
|
|
3019
3052
|
for (const entry of change.capabilities) {
|
|
3053
|
+
if (entry.reconstructed === false && !draftIsWholeAgain(entry)) {
|
|
3054
|
+
findings.push({
|
|
3055
|
+
severity: "error",
|
|
3056
|
+
kind: "capability-draft-unreconstructed",
|
|
3057
|
+
subject: { kind: "capability", capability: entry.capability },
|
|
3058
|
+
message: `\`${entry.capability}\`'s draft could not be rebuilt from this change's delta and opened from the folded text instead${entry.reconstructionReason ? ` (${entry.reconstructionReason})` : ""}. Emitting from it would derive a delta without whatever this change had already added. Restore the draft before emitting.`
|
|
3059
|
+
});
|
|
3060
|
+
continue;
|
|
3061
|
+
}
|
|
3020
3062
|
if (entry.derivation.outcome === "refused") {
|
|
3021
3063
|
findings.push(...refusalFindings(entry));
|
|
3022
3064
|
continue;
|
|
@@ -3449,8 +3491,16 @@ function isDirectory(path) {
|
|
|
3449
3491
|
}
|
|
3450
3492
|
|
|
3451
3493
|
// src/workbench/write/write-change.ts
|
|
3452
|
-
import { mkdirSync as mkdirSync4, readFileSync as readFileSync6, readdirSync as readdirSync6, statSync as statSync4, writeFileSync as writeFileSync3 } from "node:fs";
|
|
3494
|
+
import { existsSync as existsSync6, mkdirSync as mkdirSync4, readFileSync as readFileSync6, readdirSync as readdirSync6, statSync as statSync4, writeFileSync as writeFileSync3 } from "node:fs";
|
|
3453
3495
|
import { dirname as dirname4, join as join8 } from "node:path";
|
|
3496
|
+
|
|
3497
|
+
// src/workbench/shell/lifecycle.ts
|
|
3498
|
+
var SPEC_DRIVEN = Object.freeze({
|
|
3499
|
+
name: "spec-driven",
|
|
3500
|
+
artifacts: Object.freeze(["proposal", "specs", "design", "tasks"])
|
|
3501
|
+
});
|
|
3502
|
+
|
|
3503
|
+
// src/workbench/write/write-change.ts
|
|
3454
3504
|
function changeDirectory(repoRoot, changeId) {
|
|
3455
3505
|
return join8(repoRoot, "openspec", "changes", changeId);
|
|
3456
3506
|
}
|
|
@@ -3470,6 +3520,7 @@ function writeChange(repoRoot, change, provenance, options = {}) {
|
|
|
3470
3520
|
}
|
|
3471
3521
|
const emitted = emitChangeWithProvenance(change, provenance);
|
|
3472
3522
|
writeEmitted(directory, emitted);
|
|
3523
|
+
writeSchemaFile(directory);
|
|
3473
3524
|
return {
|
|
3474
3525
|
outcome: "written",
|
|
3475
3526
|
directory,
|
|
@@ -3505,6 +3556,12 @@ function readEmittedChange(directory, id) {
|
|
|
3505
3556
|
}
|
|
3506
3557
|
return { id, files };
|
|
3507
3558
|
}
|
|
3559
|
+
function writeSchemaFile(directory) {
|
|
3560
|
+
const path = join8(directory, ".openspec.yaml");
|
|
3561
|
+
if (existsSync6(path)) return;
|
|
3562
|
+
writeFileSync3(path, `schema: ${SPEC_DRIVEN.name}
|
|
3563
|
+
`, "utf8");
|
|
3564
|
+
}
|
|
3508
3565
|
function writeEmitted(directory, emitted) {
|
|
3509
3566
|
mkdirSync4(directory, { recursive: true });
|
|
3510
3567
|
for (const file of emitted.files) {
|
|
@@ -3615,11 +3672,11 @@ ${body}
|
|
|
3615
3672
|
}
|
|
3616
3673
|
|
|
3617
3674
|
// src/workbench/agent/credential-probe.ts
|
|
3618
|
-
import { existsSync as
|
|
3675
|
+
import { existsSync as existsSync7, readFileSync as readFileSync7, readdirSync as readdirSync7, statSync as statSync5 } from "node:fs";
|
|
3619
3676
|
import { delimiter, join as join9 } from "node:path";
|
|
3620
3677
|
function readSubscriptionToken(home) {
|
|
3621
3678
|
const path = join9(home, ".claude", ".credentials.json");
|
|
3622
|
-
if (!
|
|
3679
|
+
if (!existsSync7(path)) return null;
|
|
3623
3680
|
try {
|
|
3624
3681
|
const parsed = JSON.parse(readFileSync7(path, "utf8"));
|
|
3625
3682
|
const token = parsed.claudeAiOauth?.accessToken;
|
|
@@ -3857,7 +3914,7 @@ ${file.content}`;
|
|
|
3857
3914
|
if (!target.resuming) return { read, changeText };
|
|
3858
3915
|
for (const name of ["proposal.md", "tasks.md"]) {
|
|
3859
3916
|
const file = join10(target.changeDir, name);
|
|
3860
|
-
if (!
|
|
3917
|
+
if (!existsSync8(file)) continue;
|
|
3861
3918
|
changeText += `
|
|
3862
3919
|
|
|
3863
3920
|
===== ${name} =====
|
|
@@ -3866,7 +3923,7 @@ ${readFileSync8(file, "utf8")}`;
|
|
|
3866
3923
|
}
|
|
3867
3924
|
for (const capability of source.openCapabilities ?? []) {
|
|
3868
3925
|
const file = join10(target.changeDir, "specs", capability, "spec.md");
|
|
3869
|
-
if (!
|
|
3926
|
+
if (!existsSync8(file)) continue;
|
|
3870
3927
|
changeText += `
|
|
3871
3928
|
|
|
3872
3929
|
===== specs/${capability}/spec.md (the change's deltas) =====
|
|
@@ -3880,7 +3937,7 @@ var WorkbenchHostError = class extends Error {
|
|
|
3880
3937
|
function findRepoRoot(start) {
|
|
3881
3938
|
let dir = resolve3(start);
|
|
3882
3939
|
for (; ; ) {
|
|
3883
|
-
if (
|
|
3940
|
+
if (existsSync8(join10(dir, "openspec"))) return dir;
|
|
3884
3941
|
const parent = dirname5(dir);
|
|
3885
3942
|
if (parent === dir) return null;
|
|
3886
3943
|
dir = parent;
|
|
@@ -3902,7 +3959,7 @@ function resolveTarget(cwd, changeId) {
|
|
|
3902
3959
|
);
|
|
3903
3960
|
}
|
|
3904
3961
|
const changeDir = changeDirectory(repoRoot, changeId);
|
|
3905
|
-
return { repoRoot, changeId, changeDir, resuming:
|
|
3962
|
+
return { repoRoot, changeId, changeDir, resuming: existsSync8(changeDir) };
|
|
3906
3963
|
}
|
|
3907
3964
|
function mountWorkbenchHost(app, options) {
|
|
3908
3965
|
const { target } = options;
|
|
@@ -3924,7 +3981,13 @@ function mountWorkbenchHost(app, options) {
|
|
|
3924
3981
|
folded,
|
|
3925
3982
|
draft: rebuilt.draft,
|
|
3926
3983
|
reconstructed: rebuilt.outcome === "reconstructed",
|
|
3927
|
-
...rebuilt.outcome === "unreconstructable" ? { reason: rebuilt.reason } : {}
|
|
3984
|
+
...rebuilt.outcome === "unreconstructable" ? { reason: rebuilt.reason } : {},
|
|
3985
|
+
// The requirement names the EMITTED delta declares. Carried so the
|
|
3986
|
+
// emission gate can ask whether the draft is whole NOW, rather than
|
|
3987
|
+
// only whether it loaded whole — otherwise an author who restores a
|
|
3988
|
+
// requirement by hand stays blocked with no way forward inside the
|
|
3989
|
+
// tool, which is a lock rather than a guard.
|
|
3990
|
+
declared: [...spec.added, ...spec.modified].map((b) => /^###[ \t]+Requirement:[ \t]*(.*)$/m.exec(b)?.[1]?.trim()).filter((n) => n !== void 0 && n !== "")
|
|
3928
3991
|
});
|
|
3929
3992
|
}
|
|
3930
3993
|
} catch {
|
|
@@ -4030,7 +4093,7 @@ function mountWorkbenchHost(app, options) {
|
|
|
4030
4093
|
}
|
|
4031
4094
|
|
|
4032
4095
|
// server/cli.ts
|
|
4033
|
-
var CLI_VERSION = true ? "2026.08.
|
|
4096
|
+
var CLI_VERSION = true ? "2026.08.25.2" : "dev";
|
|
4034
4097
|
var USAGE = `Usage: specsketch <change-id> [--port <n>] [--fixture]
|
|
4035
4098
|
specsketch login [--profile <name>] [--web-url <url>]
|
|
4036
4099
|
specsketch --version
|
|
@@ -4111,7 +4174,7 @@ function resolveClientDir(moduleUrl) {
|
|
|
4111
4174
|
// repo: server/ -> dist/client
|
|
4112
4175
|
];
|
|
4113
4176
|
for (const dir of candidates) {
|
|
4114
|
-
if (
|
|
4177
|
+
if (existsSync9(join11(dir, "index.html"))) return dir;
|
|
4115
4178
|
}
|
|
4116
4179
|
return null;
|
|
4117
4180
|
}
|
|
@@ -4119,8 +4182,8 @@ function staticResponse(clientDir, pathname) {
|
|
|
4119
4182
|
const rel = normalize2(decodeURIComponent(pathname)).replace(/^\/+/, "");
|
|
4120
4183
|
const target = resolve4(clientDir, rel === "" ? "index.html" : rel);
|
|
4121
4184
|
if (!target.startsWith(resolve4(clientDir))) return null;
|
|
4122
|
-
const file =
|
|
4123
|
-
if (!
|
|
4185
|
+
const file = existsSync9(target) && extname(target) ? target : join11(clientDir, "index.html");
|
|
4186
|
+
if (!existsSync9(file)) return null;
|
|
4124
4187
|
return new Response(readFileSync9(file), {
|
|
4125
4188
|
headers: { "Content-Type": MIME[extname(file)] ?? "application/octet-stream" }
|
|
4126
4189
|
});
|
package/dist/client/assets/{MarkdownEditorImpl-7ZHuf34p.js → MarkdownEditorImpl-B7fANsTl.js}
RENAMED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{n as e,t}from"./index-
|
|
1
|
+
import{n as e,t}from"./index-DzRQXC_d.js";var n=e(),r=[],i=[];(()=>{let e=`lc,34,7n,7,7b,19,,,,2,,2,,,20,b,1c,l,g,,2t,7,2,6,2,2,,4,z,,u,r,2j,b,1m,9,9,,o,4,,9,,3,,5,17,3,3b,f,,w,1j,,,,4,8,4,,3,7,a,2,t,,1m,,,,2,4,8,,9,,a,2,q,,2,2,1l,,4,2,4,2,2,3,3,,u,2,3,,b,2,1l,,4,5,,2,4,,k,2,m,6,,,1m,,,2,,4,8,,7,3,a,2,u,,1n,,,,c,,9,,14,,3,,1l,3,5,3,,4,7,2,b,2,t,,1m,,2,,2,,3,,5,2,7,2,b,2,s,2,1l,2,,,2,4,8,,9,,a,2,t,,20,,4,,2,3,,,8,,29,,2,7,c,8,2q,,2,9,b,6,22,2,r,,,,,,1j,e,,5,,2,5,b,,10,9,,2u,4,,6,,2,2,2,p,2,4,3,g,4,d,,2,2,6,,f,,jj,3,qa,3,t,3,t,2,u,2,1s,2,,7,8,,2,b,9,,19,3,3b,2,y,,3a,3,4,2,9,,6,3,63,2,2,,1m,,,7,,,,,2,8,6,a,2,,1c,h,1r,4,1c,7,,,5,,14,9,c,2,w,4,2,2,,3,1k,,,2,3,,,3,1m,8,2,2,48,3,,d,,7,4,,6,,3,2,5i,1m,,5,ek,,5f,x,2da,3,3x,,2o,w,fe,6,2x,2,n9w,4,,a,w,2,28,2,7k,,3,,4,,p,2,5,,47,2,q,i,d,,12,8,p,b,1a,3,1c,,2,4,2,2,13,,1v,6,2,2,2,2,c,,8,,1b,,1f,,,3,2,2,5,2,,,16,2,8,,6m,,2,,4,,fn4,,kh,g,g,g,a6,2,gt,,6a,,45,5,1ae,3,,2,5,4,14,3,4,,4l,2,fx,4,ar,2,49,b,4w,,1i,f,1k,3,1d,4,2,2,1x,3,10,5,,8,1q,,c,2,1g,9,a,4,2,,2n,3,2,,,2,6,,4g,,3,8,l,2,1l,2,,,,,m,,e,7,3,5,5f,8,2,3,,,n,,29,,2,6,,,2,,,2,,2,6j,,2,4,6,2,,2,r,2,2d,8,2,,,2,2y,,,,2,6,,,2t,3,2,4,,5,77,9,,2,6t,,a,2,,,4,,40,4,2,2,4,,w,a,14,6,2,4,8,,9,6,2,3,1a,d,,2,ba,7,,6,,,2a,m,2,7,,2,,2,3e,6,3,,,2,,7,,,20,2,3,,,,9n,2,f0b,5,1n,7,t4,,1r,4,29,,f5k,2,43q,,,3,4,5,8,8,2,7,u,4,44,3,1iz,1j,4,1e,8,,e,,m,5,,f,11s,7,,h,2,7,,2,,5,79,7,c5,4,15s,7,31,7,240,5,gx7k,2o,3k,6o`.split(`,`).map(e=>e?parseInt(e,36):1);for(let t=0,n=0;t<e.length;t++)(t%2?i:r).push(n+=e[t])})();function a(e){if(e<768)return!1;for(let t=0,n=r.length;;){let a=t+n>>1;if(e<r[a])n=a;else if(e>=i[a])t=a+1;else return!0;if(t==n)return!1}}function o(e){return e>=127462&&e<=127487}var s=8205;function c(e,t,n=!0,r=!0){return(n?l:u)(e,t,r)}function l(e,t,n){if(t==e.length)return t;t&&f(e.charCodeAt(t))&&p(e.charCodeAt(t-1))&&t--;let r=d(e,t);for(t+=m(r);t<e.length;){let i=d(e,t);if(r==s||i==s||n&&a(i))t+=m(i),r=i;else if(o(i)){let n=0,r=t-2;for(;r>=0&&o(d(e,r));)n++,r-=2;if(n%2==0)break;t+=2}else break}return t}function u(e,t,n){for(;t>1;){let r=l(e,t-2,n);if(r<t)return r;t--}return 0}function d(e,t){let n=e.charCodeAt(t);if(!p(n)||t+1==e.length)return n;let r=e.charCodeAt(t+1);return f(r)?(n-55296<<10)+(r-56320)+65536:n}function f(e){return e>=56320&&e<57344}function p(e){return e>=55296&&e<56320}function m(e){return e<65536?1:2}var h=class e{lineAt(e){if(e<0||e>this.length)throw RangeError(`Invalid position ${e} in document of length ${this.length}`);return this.lineInner(e,!1,1,0)}line(e){if(e<1||e>this.lines)throw RangeError(`Invalid line number ${e} in ${this.lines}-line document`);return this.lineInner(e,!0,1,0)}replace(e,t,n){[e,t]=ae(this,e,t);let r=[];return this.decompose(0,e,r,2),n.length&&n.decompose(0,n.length,r,3),this.decompose(t,this.length,r,1),_.from(r,this.length-(t-e)+n.length)}append(e){return this.replace(this.length,this.length,e)}slice(e,t=this.length){[e,t]=ae(this,e,t);let n=[];return this.decompose(e,t,n,0),_.from(n,t-e)}eq(e){if(e==this)return!0;if(e.length!=this.length||e.lines!=this.lines)return!1;let t=this.scanIdentical(e,1),n=this.length-this.scanIdentical(e,-1),r=new v(this),i=new v(e);for(let e=t,a=t;;){if(r.next(e),i.next(e),e=0,r.lineBreak!=i.lineBreak||r.done!=i.done||r.value!=i.value)return!1;if(a+=r.value.length,r.done||a>=n)return!0}}iter(e=1){return new v(this,e)}iterRange(e,t=this.length){return new y(this,e,t)}iterLines(e,t){let n;if(e==null)n=this.iter();else{t??=this.lines+1;let r=this.line(e).from;n=this.iterRange(r,Math.max(r,t==this.lines+1?this.length:t<=1?0:this.line(t-1).to))}return new re(n)}toString(){return this.sliceString(0)}toJSON(){let e=[];return this.flatten(e),e}constructor(){}static of(t){if(t.length==0)throw RangeError(`A document must have at least one line`);return t.length==1&&!t[0]?e.empty:t.length<=32?new g(t):_.from(g.split(t,[]))}},g=class e extends h{constructor(e,t=ee(e)){super(),this.text=e,this.length=t}get lines(){return this.text.length}get children(){return null}lineInner(e,t,n,r){for(let i=0;;i++){let a=this.text[i],o=r+a.length;if((t?n:o)>=e)return new ie(r,o,n,a);r=o+1,n++}}decompose(t,n,r,i){let a=t<=0&&n>=this.length?this:new e(ne(this.text,t,n),Math.min(n,this.length)-Math.max(0,t));if(i&1){let t=r.pop(),n=te(a.text,t.text.slice(),0,a.length);if(n.length<=32)r.push(new e(n,t.length+a.length));else{let t=n.length>>1;r.push(new e(n.slice(0,t)),new e(n.slice(t)))}}else r.push(a)}replace(t,n,r){if(!(r instanceof e))return super.replace(t,n,r);[t,n]=ae(this,t,n);let i=te(this.text,te(r.text,ne(this.text,0,t)),n),a=this.length+r.length-(n-t);return i.length<=32?new e(i,a):_.from(e.split(i,[]),a)}sliceString(e,t=this.length,n=`
|
|
2
2
|
`){[e,t]=ae(this,e,t);let r=``;for(let i=0,a=0;i<=t&&a<this.text.length;a++){let o=this.text[a],s=i+o.length;i>e&&a&&(r+=n),e<s&&t>i&&(r+=o.slice(Math.max(0,e-i),t-i)),i=s+1}return r}flatten(e){for(let t of this.text)e.push(t)}scanIdentical(){return 0}static split(t,n){let r=[],i=-1;for(let a of t)r.push(a),i+=a.length+1,r.length==32&&(n.push(new e(r,i)),r=[],i=-1);return i>-1&&n.push(new e(r,i)),n}},_=class e extends h{constructor(e,t){super(),this.children=e,this.length=t,this.lines=0;for(let t of e)this.lines+=t.lines}lineInner(e,t,n,r){for(let i=0;;i++){let a=this.children[i],o=r+a.length,s=n+a.lines-1;if((t?s:o)>=e)return a.lineInner(e,t,n,r);r=o+1,n=s+1}}decompose(e,t,n,r){for(let i=0,a=0;a<=t&&i<this.children.length;i++){let o=this.children[i],s=a+o.length;if(e<=s&&t>=a){let i=r&(a<=e|(s>=t?2:0));a>=e&&s<=t&&!i?n.push(o):o.decompose(e-a,t-a,n,i)}a=s+1}}replace(t,n,r){if([t,n]=ae(this,t,n),r.lines<this.lines)for(let i=0,a=0;i<this.children.length;i++){let o=this.children[i],s=a+o.length;if(t>=a&&n<=s){let c=o.replace(t-a,n-a,r),l=this.lines-o.lines+c.lines;if(c.lines<l>>4&&c.lines>l>>6){let a=this.children.slice();return a[i]=c,new e(a,this.length-(n-t)+r.length)}return super.replace(a,s,c)}a=s+1}return super.replace(t,n,r)}sliceString(e,t=this.length,n=`
|
|
3
3
|
`){[e,t]=ae(this,e,t);let r=``;for(let i=0,a=0;i<this.children.length&&a<=t;i++){let o=this.children[i],s=a+o.length;a>e&&i&&(r+=n),e<s&&t>a&&(r+=o.sliceString(e-a,t-a,n)),a=s+1}return r}flatten(e){for(let t of this.children)t.flatten(e)}scanIdentical(t,n){if(!(t instanceof e))return 0;let r=0,[i,a,o,s]=n>0?[0,0,this.children.length,t.children.length]:[this.children.length-1,t.children.length-1,-1,-1];for(;;i+=n,a+=n){if(i==o||a==s)return r;let e=this.children[i],c=t.children[a];if(e!=c)return r+e.scanIdentical(c,n);r+=e.length+1}}static from(t,n=t.reduce((e,t)=>e+t.length+1,-1)){let r=0;for(let e of t)r+=e.lines;if(r<32){let e=[];for(let n of t)n.flatten(e);return new g(e,n)}let i=Math.max(32,r>>5),a=i<<1,o=i>>1,s=[],c=0,l=-1,u=[];function d(t){let n;if(t.lines>a&&t instanceof e)for(let e of t.children)d(e);else t.lines>o&&(c>o||!c)?(f(),s.push(t)):t instanceof g&&c&&(n=u[u.length-1])instanceof g&&t.lines+n.lines<=32?(c+=t.lines,l+=t.length+1,u[u.length-1]=new g(n.text.concat(t.text),n.length+1+t.length)):(c+t.lines>i&&f(),c+=t.lines,l+=t.length+1,u.push(t))}function f(){c!=0&&(s.push(u.length==1?u[0]:e.from(u,l)),l=-1,c=u.length=0)}for(let e of t)d(e);return f(),s.length==1?s[0]:new e(s,n)}};h.empty=new g([``],0);function ee(e){let t=-1;for(let n of e)t+=n.length+1;return t}function te(e,t,n=0,r=1e9){for(let i=0,a=0,o=!0;a<e.length&&i<=r;a++){let s=e[a],c=i+s.length;c>=n&&(c>r&&(s=s.slice(0,r-i)),i<n&&(s=s.slice(n-i)),o?(t[t.length-1]+=s,o=!1):t.push(s)),i=c+1}return t}function ne(e,t,n){return te(e,[``],t,n)}var v=class{constructor(e,t=1){this.dir=t,this.done=!1,this.lineBreak=!1,this.value=``,this.nodes=[e],this.offsets=[t>0?1:(e instanceof g?e.text.length:e.children.length)<<1]}nextInner(e,t){for(this.done=this.lineBreak=!1;;){let n=this.nodes.length-1,r=this.nodes[n],i=this.offsets[n],a=i>>1,o=r instanceof g?r.text.length:r.children.length;if(a==(t>0?o:0)){if(n==0)return this.done=!0,this.value=``,this;t>0&&this.offsets[n-1]++,this.nodes.pop(),this.offsets.pop()}else if((i&1)==(t>0?0:1)){if(this.offsets[n]+=t,e==0)return this.lineBreak=!0,this.value=`
|
|
4
4
|
`,this;e--}else if(r instanceof g){let i=r.text[a+(t<0?-1:0)];if(this.offsets[n]+=t,i.length>Math.max(0,e))return this.value=e==0?i:t>0?i.slice(e):i.slice(0,i.length-e),this;e-=i.length}else{let i=r.children[a+(t<0?-1:0)];e>i.length?(e-=i.length,this.offsets[n]+=t):(t<0&&this.offsets[n]--,this.nodes.push(i),this.offsets.push(t>0?1:(i instanceof g?i.text.length:i.children.length)<<1))}}}next(e=0){return e<0&&(this.nextInner(-e,-this.dir),e=this.value.length),this.nextInner(e,this.dir)}},y=class{constructor(e,t,n){this.value=``,this.done=!1,this.cursor=new v(e,t>n?-1:1),this.pos=t>n?e.length:0,this.from=Math.min(t,n),this.to=Math.max(t,n)}nextInner(e,t){if(t<0?this.pos<=this.from:this.pos>=this.to)return this.value=``,this.done=!0,this;e+=Math.max(0,t<0?this.pos-this.to:this.from-this.pos);let n=t<0?this.pos-this.from:this.to-this.pos;e>n&&(e=n),n-=e;let{value:r}=this.cursor.next(e);return this.pos+=(r.length+e)*t,this.value=r.length<=n?r:t<0?r.slice(r.length-n):r.slice(0,n),this.done=!this.value,this}next(e=0){return e<0?e=Math.max(e,this.from-this.pos):e>0&&(e=Math.min(e,this.to-this.pos)),this.nextInner(e,this.cursor.dir)}get lineBreak(){return this.cursor.lineBreak&&this.value!=``}},re=class{constructor(e){this.inner=e,this.afterBreak=!0,this.value=``,this.done=!1}next(e=0){let{done:t,lineBreak:n,value:r}=this.inner.next(e);return t&&this.afterBreak?(this.value=``,this.afterBreak=!1):t?(this.done=!0,this.value=``):n?this.afterBreak?this.value=``:(this.afterBreak=!0,this.next()):(this.value=r,this.afterBreak=!1),this}get lineBreak(){return!1}};typeof Symbol<`u`&&(h.prototype[Symbol.iterator]=function(){return this.iter()},v.prototype[Symbol.iterator]=y.prototype[Symbol.iterator]=re.prototype[Symbol.iterator]=function(){return this});var ie=class{constructor(e,t,n,r){this.from=e,this.to=t,this.number=n,this.text=r}get length(){return this.to-this.from}};function ae(e,t,n){return t=Math.max(0,Math.min(e.length,t)),[t,Math.max(t,Math.min(e.length,n))]}function b(e,t,n=!0,r=!0){return c(e,t,n,r)}function oe(e){return e>=56320&&e<57344}function se(e){return e>=55296&&e<56320}function ce(e,t){let n=e.charCodeAt(t);if(!se(n)||t+1==e.length)return n;let r=e.charCodeAt(t+1);return oe(r)?(n-55296<<10)+(r-56320)+65536:n}function le(e){return e<65536?1:2}var ue=/\r\n?|\n/,x=(function(e){return e[e.Simple=0]=`Simple`,e[e.TrackDel=1]=`TrackDel`,e[e.TrackBefore=2]=`TrackBefore`,e[e.TrackAfter=3]=`TrackAfter`,e})(x||={}),de=class e{constructor(e){this.sections=e}get length(){let e=0;for(let t=0;t<this.sections.length;t+=2)e+=this.sections[t];return e}get newLength(){let e=0;for(let t=0;t<this.sections.length;t+=2){let n=this.sections[t+1];e+=n<0?this.sections[t]:n}return e}get empty(){return this.sections.length==0||this.sections.length==2&&this.sections[1]<0}iterGaps(e){for(let t=0,n=0,r=0;t<this.sections.length;){let i=this.sections[t++],a=this.sections[t++];a<0?(e(n,r,i),r+=i):r+=a,n+=i}}iterChangedRanges(e,t=!1){me(this,e,t)}get invertedDesc(){let t=[];for(let e=0;e<this.sections.length;){let n=this.sections[e++],r=this.sections[e++];r<0?t.push(n,r):t.push(r,n)}return new e(t)}composeDesc(e){return this.empty?e:e.empty?this:ge(this,e)}mapDesc(e,t=!1){return e.empty?this:he(this,e,t)}mapPos(e,t=-1,n=x.Simple){let r=0,i=0;for(let a=0;a<this.sections.length;){let o=this.sections[a++],s=this.sections[a++],c=r+o;if(s<0){if(c>e)return i+(e-r);i+=o}else{if(n!=x.Simple&&c>=e&&(n==x.TrackDel&&r<e&&c>e||n==x.TrackBefore&&r<e||n==x.TrackAfter&&c>e))return null;if(c>e||c==e&&t<0&&!o)return e==r||t<0?i:i+s;i+=s}r=c}if(e>r)throw RangeError(`Position ${e} is out of range for changeset of length ${r}`);return i}touchesRange(e,t=e){for(let n=0,r=0;n<this.sections.length&&r<=t;){let i=this.sections[n++],a=this.sections[n++],o=r+i;if(a>=0&&r<=t&&o>=e)return r<e&&o>t?`cover`:!0;r=o}return!1}toString(){let e=``;for(let t=0;t<this.sections.length;){let n=this.sections[t++],r=this.sections[t++];e+=(e?` `:``)+n+(r>=0?`:`+r:``)}return e}toJSON(){return this.sections}static fromJSON(t){if(!Array.isArray(t)||t.length%2||t.some(e=>typeof e!=`number`))throw RangeError(`Invalid JSON representation of ChangeDesc`);return new e(t)}static create(t){return new e(t)}},fe=class e extends de{constructor(e,t){super(e),this.inserted=t}apply(e){if(this.length!=e.length)throw RangeError(`Applying change set to a document with the wrong length`);return me(this,(t,n,r,i,a)=>e=e.replace(r,r+(n-t),a),!1),e}mapDesc(e,t=!1){return he(this,e,t,!0)}invert(t){let n=this.sections.slice(),r=[];for(let e=0,i=0;e<n.length;e+=2){let a=n[e],o=n[e+1];if(o>=0){n[e]=o,n[e+1]=a;let s=e>>1;for(;r.length<s;)r.push(h.empty);r.push(a?t.slice(i,i+a):h.empty)}i+=a}return new e(n,r)}compose(e){return this.empty?e:e.empty?this:ge(this,e,!0)}map(e,t=!1){return e.empty?this:he(this,e,t,!0)}iterChanges(e,t=!1){me(this,e,t)}get desc(){return de.create(this.sections)}filter(t){let n=[],r=[],i=[],a=new _e(this);done:for(let e=0,o=0;;){let s=e==t.length?1e9:t[e++];for(;o<s||o==s&&a.len==0;){if(a.done)break done;let e=Math.min(a.len,s-o);S(i,e,-1);let t=a.ins==-1?-1:a.off==0?a.ins:0;S(n,e,t),t>0&&pe(r,n,a.text),a.forward(e),o+=e}let c=t[e++];for(;o<c;){if(a.done)break done;let e=Math.min(a.len,c-o);S(n,e,-1),S(i,e,a.ins==-1?-1:a.off==0?a.ins:0),a.forward(e),o+=e}}return{changes:new e(n,r),filtered:de.create(i)}}toJSON(){let e=[];for(let t=0;t<this.sections.length;t+=2){let n=this.sections[t],r=this.sections[t+1];r<0?e.push(n):r==0?e.push([n]):e.push([n].concat(this.inserted[t>>1].toJSON()))}return e}static of(t,n,r){let i=[],a=[],o=0,s=null;function c(t=!1){if(!t&&!i.length)return;o<n&&S(i,n-o,-1);let r=new e(i,a);s=s?s.compose(r.map(s)):r,i=[],a=[],o=0}function l(t){if(Array.isArray(t))for(let e of t)l(e);else if(t instanceof e){if(t.length!=n)throw RangeError(`Mismatched change set length (got ${t.length}, expected ${n})`);c(),s=s?s.compose(t.map(s)):t}else{let{from:e,to:s=e,insert:l}=t;if(e>s||e<0||s>n)throw RangeError(`Invalid change range ${e} to ${s} (in doc of length ${n})`);let u=l?typeof l==`string`?h.of(l.split(r||ue)):l:h.empty,d=u.length;if(e==s&&d==0)return;e<o&&c(),e>o&&S(i,e-o,-1),S(i,s-e,d),pe(a,i,u),o=s}}return l(t),c(!s),s}static empty(t){return new e(t?[t,-1]:[],[])}static fromJSON(t){if(!Array.isArray(t))throw RangeError(`Invalid JSON representation of ChangeSet`);let n=[],r=[];for(let e=0;e<t.length;e++){let i=t[e];if(typeof i==`number`)n.push(i,-1);else if(!Array.isArray(i)||typeof i[0]!=`number`||i.some((e,t)=>t&&typeof e!=`string`))throw RangeError(`Invalid JSON representation of ChangeSet`);else if(i.length==1)n.push(i[0],0);else{for(;r.length<e;)r.push(h.empty);r[e]=h.of(i.slice(1)),n.push(i[0],r[e].length)}}return new e(n,r)}static createSet(t,n){return new e(t,n)}};function S(e,t,n,r=!1){if(t==0&&n<=0)return;let i=e.length-2;i>=0&&n<=0&&n==e[i+1]?e[i]+=t:i>=0&&t==0&&e[i]==0?e[i+1]+=n:r?(e[i]+=t,e[i+1]+=n):e.push(t,n)}function pe(e,t,n){if(n.length==0)return;let r=t.length-2>>1;if(r<e.length)e[e.length-1]=e[e.length-1].append(n);else{for(;e.length<r;)e.push(h.empty);e.push(n)}}function me(e,t,n){let r=e.inserted;for(let i=0,a=0,o=0;o<e.sections.length;){let s=e.sections[o++],c=e.sections[o++];if(c<0)i+=s,a+=s;else{let l=i,u=a,d=h.empty;for(;l+=s,u+=c,c&&r&&(d=d.append(r[o-2>>1])),!(n||o==e.sections.length||e.sections[o+1]<0);)s=e.sections[o++],c=e.sections[o++];t(i,l,a,u,d),i=l,a=u}}}function he(e,t,n,r=!1){let i=[],a=r?[]:null,o=new _e(e),s=new _e(t);for(let e=-1;;)if(o.done&&s.len||s.done&&o.len)throw Error(`Mismatched change set lengths`);else if(o.ins==-1&&s.ins==-1){let e=Math.min(o.len,s.len);S(i,e,-1),o.forward(e),s.forward(e)}else if(s.ins>=0&&(o.ins<0||e==o.i||o.off==0&&(s.len<o.len||s.len==o.len&&!n))){let t=s.len;for(S(i,s.ins,-1);t;){let n=Math.min(o.len,t);o.ins>=0&&e<o.i&&o.len<=n&&(S(i,0,o.ins),a&&pe(a,i,o.text),e=o.i),o.forward(n),t-=n}s.next()}else if(o.ins>=0){let t=0,n=o.len;for(;n;)if(s.ins==-1){let e=Math.min(n,s.len);t+=e,n-=e,s.forward(e)}else if(s.ins==0&&s.len<n)n-=s.len,s.next();else break;S(i,t,e<o.i?o.ins:0),a&&e<o.i&&pe(a,i,o.text),e=o.i,o.forward(o.len-n)}else if(o.done&&s.done)return a?fe.createSet(i,a):de.create(i);else throw Error(`Mismatched change set lengths`)}function ge(e,t,n=!1){let r=[],i=n?[]:null,a=new _e(e),o=new _e(t);for(let e=!1;;)if(a.done&&o.done)return i?fe.createSet(r,i):de.create(r);else if(a.ins==0)S(r,a.len,0,e),a.next();else if(o.len==0&&!o.done)S(r,0,o.ins,e),i&&pe(i,r,o.text),o.next();else if(a.done||o.done)throw Error(`Mismatched change set lengths`);else{let t=Math.min(a.len2,o.len),n=r.length;if(a.ins==-1){let n=o.ins==-1?-1:o.off?0:o.ins;S(r,t,n,e),i&&n&&pe(i,r,o.text)}else o.ins==-1?(S(r,a.off?0:a.len,t,e),i&&pe(i,r,a.textBit(t))):(S(r,a.off?0:a.len,o.off?0:o.ins,e),i&&!o.off&&pe(i,r,o.text));e=(a.ins>t||o.ins>=0&&o.len>t)&&(e||r.length>n),a.forward2(t),o.forward(t)}}var _e=class{constructor(e){this.set=e,this.i=0,this.next()}next(){let{sections:e}=this.set;this.i<e.length?(this.len=e[this.i++],this.ins=e[this.i++]):(this.len=0,this.ins=-2),this.off=0}get done(){return this.ins==-2}get len2(){return this.ins<0?this.len:this.ins}get text(){let{inserted:e}=this.set,t=this.i-2>>1;return t>=e.length?h.empty:e[t]}textBit(e){let{inserted:t}=this.set,n=this.i-2>>1;return n>=t.length&&!e?h.empty:t[n].slice(this.off,e==null?void 0:this.off+e)}forward(e){e==this.len?this.next():(this.len-=e,this.off+=e)}forward2(e){this.ins==-1?this.forward(e):e==this.ins?this.next():(this.ins-=e,this.off+=e)}},ve=class e{constructor(e,t,n,r){this.from=e,this.to=t,this.flags=n,this.goalColumn=r}get anchor(){return this.flags&32?this.to:this.from}get head(){return this.flags&32?this.from:this.to}get empty(){return this.from==this.to}get assoc(){return this.flags&8?-1:this.flags&16?1:0}get undirectional(){return(this.flags&64)>0}get bidiLevel(){let e=this.flags&7;return e==7?null:e}map(t,n=-1){let r,i;return this.empty?r=i=t.mapPos(this.from,n):(r=t.mapPos(this.from,1),i=t.mapPos(this.to,-1)),r==this.from&&i==this.to?this:new e(r,i,this.flags,this.goalColumn)}extend(e,t=e,n=0){if(e<=this.anchor&&t>=this.anchor)return C.range(e,t,void 0,void 0,n);let r=Math.abs(e-this.anchor)>Math.abs(t-this.anchor)?e:t;return C.range(this.anchor,r,void 0,void 0,n)}eq(e,t=!1){return this.anchor==e.anchor&&this.head==e.head&&this.goalColumn==e.goalColumn&&(!t||!this.empty||this.assoc==e.assoc)}toJSON(){return{anchor:this.anchor,head:this.head}}static fromJSON(e){if(!e||typeof e.anchor!=`number`||typeof e.head!=`number`)throw RangeError(`Invalid JSON representation for SelectionRange`);return C.range(e.anchor,e.head)}static create(t,n,r,i){return new e(t,n,r,i)}},C=class e{constructor(e,t){this.ranges=e,this.mainIndex=t}map(t,n=-1){return t.empty?this:e.create(this.ranges.map(e=>e.map(t,n)),this.mainIndex)}eq(e,t=!1){if(this.ranges.length!=e.ranges.length||this.mainIndex!=e.mainIndex)return!1;for(let n=0;n<this.ranges.length;n++)if(!this.ranges[n].eq(e.ranges[n],t))return!1;return!0}get main(){return this.ranges[this.mainIndex]}asSingle(){return this.ranges.length==1?this:new e([this.main],0)}addRange(t,n=!0){return e.create([t].concat(this.ranges),n?0:this.mainIndex+1)}replaceRange(t,n=this.mainIndex){let r=this.ranges.slice();return r[n]=t,e.create(r,this.mainIndex)}toJSON(){return{ranges:this.ranges.map(e=>e.toJSON()),main:this.mainIndex}}static fromJSON(t){if(!t||!Array.isArray(t.ranges)||typeof t.main!=`number`||t.main>=t.ranges.length)throw RangeError(`Invalid JSON representation for EditorSelection`);return new e(t.ranges.map(e=>ve.fromJSON(e)),t.main)}static single(t,n=t){return new e([e.range(t,n)],0)}static create(t,n=0){if(t.length==0)throw RangeError(`A selection needs at least one range`);for(let r=0,i=0;i<t.length;i++){let a=t[i];if(a.empty?a.from<=r:a.from<r)return e.normalized(t.slice(),n);r=a.to}return new e(t,n)}static cursor(e,t=0,n,r){return ve.create(e,e,(t==0?0:t<0?8:16)|(n==null?7:Math.min(6,n)),r)}static range(e,t,n,r,i){let a=r==null?7:Math.min(6,r);return!i&&e!=t&&(i=t<e?1:-1),i&&(a|=i<0?8:16),t<e?ve.create(t,e,a|32,n):ve.create(e,t,a,n)}static undirectionalRange(e,t){return ve.create(e,t,64,void 0)}static normalized(t,n=0){let r=t[n];t.sort((e,t)=>e.from-t.from),n=t.indexOf(r);for(let r=1;r<t.length;r++){let i=t[r],a=t[r-1];if(i.empty?i.from<=a.to:i.from<a.to){let o=a.from,s=Math.max(i.to,a.to);r<=n&&n--,t.splice(--r,2,i.anchor>i.head?e.range(s,o):e.range(o,s))}}return new e(t,n)}};function ye(e,t){for(let n of e.ranges)if(n.to>t)throw RangeError(`Selection points outside of document`)}var be=0,w=class e{constructor(e,t,n,r,i){this.combine=e,this.compareInput=t,this.compare=n,this.isStatic=r,this.id=be++,this.default=e([]),this.extensions=typeof i==`function`?i(this):i}get reader(){return this}static define(t={}){return new e(t.combine||(e=>e),t.compareInput||((e,t)=>e===t),t.compare||(t.combine?(e,t)=>e===t:xe),!!t.static,t.enables)}of(e){return new Se([],this,0,e)}compute(e,t){if(this.isStatic)throw Error(`Can't compute a static facet`);return new Se(e,this,1,t)}computeN(e,t){if(this.isStatic)throw Error(`Can't compute a static facet`);return new Se(e,this,2,t)}from(e,t){return t||=e=>e,this.compute([e],n=>t(n.field(e)))}};function xe(e,t){return e==t||e.length==t.length&&e.every((e,n)=>e===t[n])}var Se=class{constructor(e,t,n,r){this.dependencies=e,this.facet=t,this.type=n,this.value=r,this.id=be++}dynamicSlot(e){let t=this.value,n=this.facet.compareInput,r=this.id,i=e[r]>>1,a=this.type==2,o=!1,s=!1,c=[];for(let t of this.dependencies)t==`doc`?o=!0:t==`selection`?s=!0:(e[t.id]??1)&1||c.push(e[t.id]);return{create(e){return e.values[i]=t(e),1},update(e,r){if(o&&r.docChanged||s&&(r.docChanged||r.selection)||we(e,c)){let r=t(e);if(a?!Ce(r,e.values[i],n):!n(r,e.values[i]))return e.values[i]=r,1}return 0},reconfigure:(e,o)=>{let s,c=o.config.address[r];if(c!=null){let r=Le(o,c);if(this.dependencies.every(t=>t instanceof w?o.facet(t)===e.facet(t):t instanceof De?o.field(t,!1)==e.field(t,!1):!0)||(a?Ce(s=t(e),r,n):n(s=t(e),r)))return e.values[i]=r,0}else s=t(e);return e.values[i]=s,1}}}get extension(){return this}};function Ce(e,t,n){if(e.length!=t.length)return!1;for(let r=0;r<e.length;r++)if(!n(e[r],t[r]))return!1;return!0}function we(e,t){let n=!1;for(let r of t)Ie(e,r)&1&&(n=!0);return n}function Te(e,t,n){let r=n.map(t=>e[t.id]),i=n.map(e=>e.type),a=r.filter(e=>!(e&1)),o=e[t.id]>>1;function s(e){let n=[];for(let t=0;t<r.length;t++){let a=Le(e,r[t]);if(i[t]==2)for(let e of a)n.push(e);else n.push(a)}return t.combine(n)}return{create(e){for(let t of r)Ie(e,t);return e.values[o]=s(e),1},update(e,n){if(!we(e,a))return 0;let r=s(e);return t.compare(r,e.values[o])?0:(e.values[o]=r,1)},reconfigure(e,i){let a=we(e,r),c=i.config.facets[t.id],l=i.facet(t);if(c&&!a&&xe(n,c))return e.values[o]=l,0;let u=s(e);return t.compare(u,l)?(e.values[o]=l,0):(e.values[o]=u,1)}}}var Ee=w.define({static:!0}),De=class e{constructor(e,t,n,r,i){this.id=e,this.createF=t,this.updateF=n,this.compareF=r,this.spec=i,this.provides=void 0}static define(t){let n=new e(be++,t.create,t.update,t.compare||((e,t)=>e===t),t);return t.provide&&(n.provides=t.provide(n)),n}create(e){return(e.facet(Ee).find(e=>e.field==this)?.create||this.createF)(e)}slot(e){let t=e[this.id]>>1;return{create:e=>(e.values[t]=this.create(e),1),update:(e,n)=>{let r=e.values[t],i=this.updateF(r,n);return this.compareF(r,i)?0:(e.values[t]=i,1)},reconfigure:(e,n)=>{let r=e.facet(Ee),i=n.facet(Ee),a;return(a=r.find(e=>e.field==this))&&a!=i.find(e=>e.field==this)?(e.values[t]=a.create(e),1):n.config.address[this.id]==null?(e.values[t]=this.create(e),1):(e.values[t]=n.field(this),0)}}}init(e){return[this,Ee.of({field:this,create:e})]}get extension(){return this}},Oe={lowest:4,low:3,default:2,high:1,highest:0};function ke(e){return t=>new je(t,e)}var Ae={highest:ke(Oe.highest),high:ke(Oe.high),default:ke(Oe.default),low:ke(Oe.low),lowest:ke(Oe.lowest)},je=class{constructor(e,t){this.inner=e,this.prec=t}get extension(){return this}},Me=class e{of(e){return new Ne(this,e)}reconfigure(t){return e.reconfigure.of({compartment:this,extension:t})}get(e){return e.config.compartments.get(this)}},Ne=class{constructor(e,t){this.compartment=e,this.inner=t}get extension(){return this}},Pe=class e{constructor(e,t,n,r,i,a){for(this.base=e,this.compartments=t,this.dynamicSlots=n,this.address=r,this.staticValues=i,this.facets=a,this.statusTemplate=[];this.statusTemplate.length<n.length;)this.statusTemplate.push(0)}staticFacet(e){let t=this.address[e.id];return t==null?e.default:this.staticValues[t>>1]}static resolve(t,n,r){let i=[],a=Object.create(null),o=new Map;for(let e of Fe(t,n,o))e instanceof De?i.push(e):(a[e.facet.id]||(a[e.facet.id]=[])).push(e);let s=Object.create(null),c=[],l=[];for(let e of i)s[e.id]=l.length<<1,l.push(t=>e.slot(t));let u=r?.config.facets;for(let e in a){let t=a[e],n=t[0].facet,i=u&&u[e]||[];if(t.every(e=>e.type==0))if(s[n.id]=c.length<<1|1,xe(i,t))c.push(r.facet(n));else{let e=n.combine(t.map(e=>e.value));c.push(r&&n.compare(e,r.facet(n))?r.facet(n):e)}else{for(let e of t)e.type==0?(s[e.id]=c.length<<1|1,c.push(e.value)):(s[e.id]=l.length<<1,l.push(t=>e.dynamicSlot(t)));s[n.id]=l.length<<1,l.push(e=>Te(e,n,t))}}let d=l.map(e=>e(s));return new e(t,o,d,s,c,a)}};function Fe(e,t,n){let r=[[],[],[],[],[]],i=new Map;function a(e,o){let s=i.get(e);if(s!=null){if(s<=o)return;let t=r[s].indexOf(e);t>-1&&r[s].splice(t,1),e instanceof Ne&&n.delete(e.compartment)}if(i.set(e,o),Array.isArray(e))for(let t of e)a(t,o);else if(e instanceof Ne){if(n.has(e.compartment))throw RangeError(`Duplicate use of compartment in extensions`);let r=t.get(e.compartment)||e.inner;n.set(e.compartment,r),a(r,o)}else if(e instanceof je)a(e.inner,e.prec);else if(e instanceof De)r[o].push(e),e.provides&&a(e.provides,o);else if(e instanceof Se)r[o].push(e),e.facet.extensions&&a(e.facet.extensions,Oe.default);else{let t=e.extension;if(!t)throw Error(`Unrecognized extension value in extension set (${e}).`);if(t==e)throw Error(`Unrecognized extension value in extension set (${e}). This sometimes happens because multiple instances of @codemirror/state are loaded, breaking instanceof checks.`);a(t,o)}}return a(e,Oe.default),r.reduce((e,t)=>e.concat(t))}function Ie(e,t){if(t&1)return 2;let n=t>>1,r=e.status[n];if(r==4)throw Error(`Cyclic dependency between fields and/or facets`);if(r&2)return r;e.status[n]=4;let i=e.computeSlot(e,e.config.dynamicSlots[n]);return e.status[n]=2|i}function Le(e,t){return t&1?e.config.staticValues[t>>1]:e.values[t>>1]}var Re=w.define(),ze=w.define({combine:e=>e.some(e=>e),static:!0}),Be=w.define({combine:e=>e.length?e[0]:void 0,static:!0}),Ve=w.define(),He=w.define(),Ue=w.define(),We=w.define({combine:e=>e.length?e[0]:!1}),Ge=class{constructor(e,t){this.type=e,this.value=t}static define(){return new Ke}},Ke=class{of(e){return new Ge(this,e)}},qe=class{constructor(e){this.map=e}of(e){return new T(this,e)}},T=class e{constructor(e,t){this.type=e,this.value=t}map(t){let n=this.type.map(this.value,t);return n===void 0?void 0:n==this.value?this:new e(this.type,n)}is(e){return this.type==e}static define(e={}){return new qe(e.map||(e=>e))}static mapEffects(e,t){if(!e.length)return e;let n=[];for(let r of e){let e=r.map(t);e&&n.push(e)}return n}};T.reconfigure=T.define(),T.appendConfig=T.define();var E=class e{constructor(t,n,r,i,a,o){this.startState=t,this.changes=n,this.selection=r,this.effects=i,this.annotations=a,this.scrollIntoView=o,this._doc=null,this._state=null,r&&ye(r,n.newLength),a.some(t=>t.type==e.time)||(this.annotations=a.concat(e.time.of(Date.now())))}static create(t,n,r,i,a,o){return new e(t,n,r,i,a,o)}get newDoc(){return this._doc||=this.changes.apply(this.startState.doc)}get newSelection(){return this.selection||this.startState.selection.map(this.changes)}get state(){return this._state||this.startState.applyTransaction(this),this._state}annotation(e){for(let t of this.annotations)if(t.type==e)return t.value}get docChanged(){return!this.changes.empty}get reconfigured(){return this.startState.config!=this.state.config}isUserEvent(t){let n=this.annotation(e.userEvent);return!!(n&&(n==t||n.length>t.length&&n.slice(0,t.length)==t&&n[t.length]==`.`))}};E.time=Ge.define(),E.userEvent=Ge.define(),E.addToHistory=Ge.define(),E.remote=Ge.define();function Je(e,t){let n=[];for(let r=0,i=0;;){let a,o;if(r<e.length&&(i==t.length||t[i]>=e[r]))a=e[r++],o=e[r++];else if(i<t.length)a=t[i++],o=t[i++];else return n;!n.length||n[n.length-1]<a?n.push(a,o):n[n.length-1]<o&&(n[n.length-1]=o)}}function Ye(e,t,n){let r,i,a;return n?(r=t.changes,i=fe.empty(t.changes.length),a=e.changes.compose(t.changes)):(r=t.changes.map(e.changes),i=e.changes.mapDesc(t.changes,!0),a=e.changes.compose(r)),{changes:a,selection:t.selection?t.selection.map(i):e.selection?.map(r),effects:T.mapEffects(e.effects,r).concat(T.mapEffects(t.effects,i)),annotations:e.annotations.length?e.annotations.concat(t.annotations):t.annotations,scrollIntoView:e.scrollIntoView||t.scrollIntoView}}function Xe(e,t,n){let r=t.selection,i=tt(t.annotations);return t.userEvent&&(i=i.concat(E.userEvent.of(t.userEvent))),{changes:t.changes instanceof fe?t.changes:fe.of(t.changes||[],n,e.facet(Be)),selection:r&&(r instanceof C?r:C.single(r.anchor,r.head)),effects:tt(t.effects),annotations:i,scrollIntoView:!!t.scrollIntoView}}function Ze(e,t,n){let r=Xe(e,t.length?t[0]:{},e.doc.length);t.length&&t[0].filter===!1&&(n=!1);for(let i=1;i<t.length;i++){t[i].filter===!1&&(n=!1);let a=!!t[i].sequential;r=Ye(r,Xe(e,t[i],a?r.changes.newLength:e.doc.length),a)}let i=E.create(e,r.changes,r.selection,r.effects,r.annotations,r.scrollIntoView);return $e(n?Qe(i):i)}function Qe(e){let t=e.startState,n=!0;for(let r of t.facet(Ve)){let t=r(e);if(t===!1){n=!1;break}Array.isArray(t)&&(n=n===!0?t:Je(n,t))}if(n!==!0){let r,i;if(n===!1)i=e.changes.invertedDesc,r=fe.empty(t.doc.length);else{let t=e.changes.filter(n);r=t.changes,i=t.filtered.mapDesc(t.changes).invertedDesc}e=E.create(t,r,e.selection&&e.selection.map(i),T.mapEffects(e.effects,i),e.annotations,e.scrollIntoView)}let r=t.facet(He);for(let n=r.length-1;n>=0;n--){let i=r[n](e);e=i instanceof E?i:Array.isArray(i)&&i.length==1&&i[0]instanceof E?i[0]:Ze(t,tt(i),!1)}return e}function $e(e){let t=e.startState,n=t.facet(Ue),r=e;for(let i=n.length-1;i>=0;i--){let a=n[i](e);a&&Object.keys(a).length&&(r=Ye(r,Xe(t,a,e.changes.newLength),!0))}return r==e?e:E.create(t,e.changes,e.selection,r.effects,r.annotations,r.scrollIntoView)}var et=[];function tt(e){return e==null?et:Array.isArray(e)?e:[e]}var nt=(function(e){return e[e.Word=0]=`Word`,e[e.Space=1]=`Space`,e[e.Other=2]=`Other`,e})(nt||={}),rt=/[\u00df\u0587\u0590-\u05f4\u0600-\u06ff\u3040-\u309f\u30a0-\u30ff\u3400-\u4db5\u4e00-\u9fcc\uac00-\ud7af]/,it;try{it=RegExp(`[\\p{Alphabetic}\\p{Number}_]`,`u`)}catch{}function at(e){if(it)return it.test(e);for(let t=0;t<e.length;t++){let n=e[t];if(/\w/.test(n)||n>``&&(n.toUpperCase()!=n.toLowerCase()||rt.test(n)))return!0}return!1}function ot(e){return t=>{if(!/\S/.test(t))return nt.Space;if(at(t))return nt.Word;for(let n=0;n<e.length;n++)if(t.indexOf(e[n])>-1)return nt.Word;return nt.Other}}var D=class e{constructor(e,t,n,r,i,a){this.config=e,this.doc=t,this.selection=n,this.values=r,this.status=e.statusTemplate.slice(),this.computeSlot=i,a&&(a._state=this);for(let e=0;e<this.config.dynamicSlots.length;e++)Ie(this,e<<1);this.computeSlot=null}field(e,t=!0){let n=this.config.address[e.id];if(n==null){if(t)throw RangeError(`Field is not present in this state`);return}return Ie(this,n),Le(this,n)}update(...e){return Ze(this,e,!0)}applyTransaction(t){let n=this.config,{base:r,compartments:i}=n;for(let e of t.effects)e.is(Me.reconfigure)?(n&&=(i=new Map,n.compartments.forEach((e,t)=>i.set(t,e)),null),i.set(e.value.compartment,e.value.extension)):e.is(T.reconfigure)?(n=null,r=e.value):e.is(T.appendConfig)&&(n=null,r=tt(r).concat(e.value));let a;n?a=t.startState.values.slice():(n=Pe.resolve(r,i,this),a=new e(n,this.doc,this.selection,n.dynamicSlots.map(()=>null),(e,t)=>t.reconfigure(e,this),null).values);let o=t.startState.facet(ze)?t.newSelection:t.newSelection.asSingle();new e(n,t.newDoc,o,a,(e,n)=>n.update(e,t),t)}replaceSelection(e){return typeof e==`string`&&(e=this.toText(e)),this.changeByRange(t=>({changes:{from:t.from,to:t.to,insert:e},range:C.cursor(t.from+e.length)}))}changeByRange(e){let t=this.selection,n=e(t.ranges[0]),r=this.changes(n.changes),i=[n.range],a=tt(n.effects);for(let n=1;n<t.ranges.length;n++){let o=e(t.ranges[n]),s=this.changes(o.changes),c=s.map(r);for(let e=0;e<n;e++)i[e]=i[e].map(c);let l=r.mapDesc(s,!0);i.push(o.range.map(l)),r=r.compose(c),a=T.mapEffects(a,c).concat(T.mapEffects(tt(o.effects),l))}return{changes:r,selection:C.create(i,t.mainIndex),effects:a}}changes(t=[]){return t instanceof fe?t:fe.of(t,this.doc.length,this.facet(e.lineSeparator))}toText(t){return h.of(t.split(this.facet(e.lineSeparator)||ue))}sliceDoc(e=0,t=this.doc.length){return this.doc.sliceString(e,t,this.lineBreak)}facet(e){let t=this.config.address[e.id];return t==null?e.default:(Ie(this,t),Le(this,t))}toJSON(e){let t={doc:this.sliceDoc(),selection:this.selection.toJSON()};if(e)for(let n in e){let r=e[n];r instanceof De&&this.config.address[r.id]!=null&&(t[n]=r.spec.toJSON(this.field(e[n]),this))}return t}static fromJSON(t,n={},r){if(!t||typeof t.doc!=`string`)throw RangeError(`Invalid JSON representation for EditorState`);let i=[];if(r){for(let e in r)if(Object.prototype.hasOwnProperty.call(t,e)){let n=r[e],a=t[e];i.push(n.init(e=>n.spec.fromJSON(a,e)))}}return e.create({doc:t.doc,selection:C.fromJSON(t.selection),extensions:n.extensions?i.concat([n.extensions]):i})}static create(t={}){let n=Pe.resolve(t.extensions||[],new Map),r=t.doc instanceof h?t.doc:h.of((t.doc||``).split(n.staticFacet(e.lineSeparator)||ue)),i=t.selection?t.selection instanceof C?t.selection:C.single(t.selection.anchor,t.selection.head):C.single(0);return ye(i,r.length),n.staticFacet(ze)||(i=i.asSingle()),new e(n,r,i,n.dynamicSlots.map(()=>null),(e,t)=>t.create(e),null)}get tabSize(){return this.facet(e.tabSize)}get lineBreak(){return this.facet(e.lineSeparator)||`
|