pim-agent 0.10.0 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -2
- package/packages/core/src/extensions/bash/index.ts +2 -1
- package/packages/core/src/extensions/bash/run.ts +8 -2
- package/packages/core/src/extensions/system-prompt/index.ts +16 -1
- package/packages/core/src/extensions/system-prompt/prompt.ts +1 -2
- package/packages/core/src/session/SessionHost.ts +35 -9
- package/packages/core/src/session/SessionRegistry.ts +22 -1
- package/packages/core/src/session/SessionUi.ts +127 -0
- package/packages/core/src/shared/Directories.ts +39 -5
- package/packages/core/src/shared/ExtensionToggles.ts +8 -0
- package/packages/core/src/shared/PiExtensions.ts +228 -0
- package/packages/protocol/src/Command.ts +22 -1
- package/packages/protocol/src/ServerEvent.ts +34 -0
- package/packages/server/src/ProbeClient.ts +21 -0
- package/packages/server/src/SessionStream.ts +228 -2
- package/packages/server/src/WsGateway.ts +153 -16
- package/packages/server/src/probe.ts +16 -0
- package/packages/web/dist/client/assets/CommitMonoV143-VF-ytizKI8U.woff2 +0 -0
- package/packages/web/dist/client/assets/{core-CA0aSzPu.js → core-D3tyj0PP.js} +1 -1
- package/packages/web/dist/client/assets/index-CTrlTM53.js +45 -0
- package/packages/web/dist/client/assets/index-JnduS4Cd.css +1 -0
- package/packages/web/dist/client/index.html +2 -2
- package/packages/web/dist/client/assets/commit-mono-latin-300-italic-B48RJMeK.woff +0 -0
- package/packages/web/dist/client/assets/commit-mono-latin-300-italic-DBq5bJCE.woff2 +0 -0
- package/packages/web/dist/client/assets/commit-mono-latin-300-normal-B-iV2FbL.woff2 +0 -0
- package/packages/web/dist/client/assets/commit-mono-latin-300-normal-kM0OTZCv.woff +0 -0
- package/packages/web/dist/client/assets/commit-mono-latin-400-italic-BXinMwCi.woff +0 -0
- package/packages/web/dist/client/assets/commit-mono-latin-400-italic-DjSHLl2N.woff2 +0 -0
- package/packages/web/dist/client/assets/commit-mono-latin-400-normal-s0S3qwFW.woff +0 -0
- package/packages/web/dist/client/assets/commit-mono-latin-400-normal-wzhe4RuD.woff2 +0 -0
- package/packages/web/dist/client/assets/commit-mono-latin-600-normal-BuQDXT0M.woff +0 -0
- package/packages/web/dist/client/assets/commit-mono-latin-600-normal-SwgSWHaV.woff2 +0 -0
- package/packages/web/dist/client/assets/commit-mono-latin-700-normal-1-GU0IUE.woff +0 -0
- package/packages/web/dist/client/assets/commit-mono-latin-700-normal-DU8mrtj2.woff2 +0 -0
- package/packages/web/dist/client/assets/index-B9be-i9d.css +0 -1
- package/packages/web/dist/client/assets/index-CpinM5NK.js +0 -45
|
@@ -9,6 +9,11 @@ import { Directories } from "#core/shared/Directories";
|
|
|
9
9
|
import type { DirectoryListing } from "#core/shared/Directories";
|
|
10
10
|
import { Git, type GitBranch } from "#core/shared/Git";
|
|
11
11
|
import { GitMonitor, type GitRun } from "#core/shared/GitMonitor";
|
|
12
|
+
import {
|
|
13
|
+
PiExtensions,
|
|
14
|
+
type ExtensionEntry,
|
|
15
|
+
type ExtensionScope,
|
|
16
|
+
} from "#core/shared/PiExtensions";
|
|
12
17
|
import { RepoDiff } from "#core/shared/RepoDiff";
|
|
13
18
|
import { ReadCursors } from "#core/session/ReadCursors";
|
|
14
19
|
import type { SessionHost } from "#core/session/SessionHost";
|
|
@@ -51,6 +56,10 @@ export type WsGatewayDeps = {
|
|
|
51
56
|
readonly sessionMetaPath?: string;
|
|
52
57
|
/** How often a session file is polled where `fs.watch` says nothing; the default is a second. */
|
|
53
58
|
readonly pollMs?: number;
|
|
59
|
+
/** Longest a dialog may hold an extension waiting; the default is `SessionStream`'s three minutes. */
|
|
60
|
+
readonly requestCeilingMs?: number;
|
|
61
|
+
/** How long a pending dialog outlives its last reader; the default is `SessionStream`'s fifteen seconds. */
|
|
62
|
+
readonly detachGraceMs?: number;
|
|
54
63
|
/** The built web client; defaults to the bundle shipped beside this package. */
|
|
55
64
|
readonly clientDir?: string;
|
|
56
65
|
/** Runs the update a `reload` asks for, reporting each step as it starts. */
|
|
@@ -69,6 +78,7 @@ type Outcome = {
|
|
|
69
78
|
readonly scanned?: number;
|
|
70
79
|
readonly models?: readonly ModelView[];
|
|
71
80
|
readonly thinkingLevels?: readonly string[];
|
|
81
|
+
readonly extensions?: readonly ExtensionEntry[];
|
|
72
82
|
readonly directory?: DirectoryListing;
|
|
73
83
|
readonly branches?: readonly GitBranch[];
|
|
74
84
|
readonly commit?: { readonly sha: string };
|
|
@@ -76,6 +86,8 @@ type Outcome = {
|
|
|
76
86
|
readonly fileDiff?: FileDiff;
|
|
77
87
|
readonly fileLines?: FileLines;
|
|
78
88
|
readonly restored?: readonly string[];
|
|
89
|
+
/** The message was dispatched as an extension command: no turn started, no entry written. */
|
|
90
|
+
readonly dispatched?: boolean;
|
|
79
91
|
readonly after?: () => void;
|
|
80
92
|
};
|
|
81
93
|
|
|
@@ -92,6 +104,15 @@ export const DEFAULT_HOSTNAME = "127.0.0.1";
|
|
|
92
104
|
// Bun 1.3.14 never frees the slot of a server-closed socket, so an unbounded `Server.stop(true)` hangs.
|
|
93
105
|
const STOP_GRACE_MS = 250;
|
|
94
106
|
|
|
107
|
+
/**
|
|
108
|
+
* Pi's own dispatch parse, three lines of `_tryExecuteExtensionCommand`
|
|
109
|
+
* (`agent-session.js:954`); a pi upgrade re-verifies it.
|
|
110
|
+
*/
|
|
111
|
+
function commandNameOf(text: string): string {
|
|
112
|
+
const spaceIndex = text.indexOf(" ");
|
|
113
|
+
return spaceIndex === -1 ? text.slice(1) : text.slice(1, spaceIndex);
|
|
114
|
+
}
|
|
115
|
+
|
|
95
116
|
/** The transport half of pim-server: a WebSocket endpoint over the session runtime in `core`. */
|
|
96
117
|
export class WsGateway {
|
|
97
118
|
private readonly registry: SessionRegistry;
|
|
@@ -111,15 +132,26 @@ export class WsGateway {
|
|
|
111
132
|
private readonly reloader: Reloader;
|
|
112
133
|
private readonly git = new GitMonitor();
|
|
113
134
|
private readonly pollMs: number | undefined;
|
|
135
|
+
private readonly requestCeilingMs: number | undefined;
|
|
136
|
+
private readonly detachGraceMs: number | undefined;
|
|
114
137
|
private readonly busyRepos = new Set<string>();
|
|
115
138
|
private versionsRead: Promise<readonly [string, string]> | undefined;
|
|
116
139
|
private server: Server<undefined> | undefined;
|
|
117
140
|
|
|
118
141
|
public constructor(deps: WsGatewayDeps) {
|
|
119
142
|
this.registry = deps.registry;
|
|
143
|
+
// `SessionStream` is the sink, so the whole routing is a lookup: a host
|
|
144
|
+
// outlives the stream that speaks for it, and pi asks per call.
|
|
145
|
+
this.registry.setUi((host) =>
|
|
146
|
+
host.sessionId === undefined
|
|
147
|
+
? undefined
|
|
148
|
+
: this.streams.get(host.sessionId)
|
|
149
|
+
);
|
|
120
150
|
this.hostname = deps.hostname ?? DEFAULT_HOSTNAME;
|
|
121
151
|
this.requestedPort = deps.port ?? DEFAULT_PORT;
|
|
122
152
|
this.pollMs = deps.pollMs;
|
|
153
|
+
this.requestCeilingMs = deps.requestCeilingMs;
|
|
154
|
+
this.detachGraceMs = deps.detachGraceMs;
|
|
123
155
|
this.uploads = new AttachmentEndpoint(
|
|
124
156
|
deps.attachmentsRoot === undefined ? {} : { root: deps.attachmentsRoot }
|
|
125
157
|
);
|
|
@@ -362,8 +394,26 @@ export class WsGateway {
|
|
|
362
394
|
thinkingLevels:
|
|
363
395
|
this.streamFor(connection)?.host.supportedThinkingLevels ?? [],
|
|
364
396
|
};
|
|
397
|
+
case "list_extensions":
|
|
398
|
+
return {
|
|
399
|
+
extensions: await PiExtensions.list(this.scopeFor(connection)),
|
|
400
|
+
};
|
|
401
|
+
case "set_extension":
|
|
402
|
+
await PiExtensions.setEnabled(
|
|
403
|
+
command.extensionId,
|
|
404
|
+
command.value,
|
|
405
|
+
this.scopeFor(connection)
|
|
406
|
+
);
|
|
407
|
+
return {
|
|
408
|
+
after: () => {
|
|
409
|
+
this.rebuildAgents();
|
|
410
|
+
},
|
|
411
|
+
};
|
|
365
412
|
case "list_dirs":
|
|
366
413
|
return { directory: await Directories.list(command.path) };
|
|
414
|
+
case "create_dir":
|
|
415
|
+
await Directories.create(command.path);
|
|
416
|
+
return {};
|
|
367
417
|
case "refresh_git": {
|
|
368
418
|
const stream = this.requireStream(connection);
|
|
369
419
|
await stream.refreshGit(command.fetch === true);
|
|
@@ -425,8 +475,16 @@ export class WsGateway {
|
|
|
425
475
|
case "reload":
|
|
426
476
|
return this.reload(command.force === true);
|
|
427
477
|
case "user_message":
|
|
428
|
-
this.promptWithAttachments(
|
|
429
|
-
|
|
478
|
+
return await this.promptWithAttachments(
|
|
479
|
+
this.requireStream(connection),
|
|
480
|
+
command
|
|
481
|
+
);
|
|
482
|
+
case "ui_response": {
|
|
483
|
+
const stream = this.requireStream(connection);
|
|
484
|
+
return stream.answer(command.requestId, command)
|
|
485
|
+
? {}
|
|
486
|
+
: { error: `no request ${command.requestId} is waiting` };
|
|
487
|
+
}
|
|
430
488
|
case "cancel": {
|
|
431
489
|
const { cancelled, restored } =
|
|
432
490
|
await this.requireStream(connection).host.cancel();
|
|
@@ -492,6 +550,27 @@ export class WsGateway {
|
|
|
492
550
|
return sessionId ? this.streams.get(sessionId) : undefined;
|
|
493
551
|
}
|
|
494
552
|
|
|
553
|
+
/** A session's directory decides which project extensions are listed; a connection without one reads this process's. */
|
|
554
|
+
private scopeFor(connection: ClientConnection): ExtensionScope {
|
|
555
|
+
return {
|
|
556
|
+
cwd: this.streamFor(connection)?.host.cwd ?? process.cwd(),
|
|
557
|
+
agentDir: this.registry.agentDir,
|
|
558
|
+
};
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
private rebuildAgents(): void {
|
|
562
|
+
for (const stream of this.streams.values()) {
|
|
563
|
+
const { host } = stream;
|
|
564
|
+
// Through the turn queue: detaching the agent under a running turn kills it.
|
|
565
|
+
void host
|
|
566
|
+
.serialize(() => host.invalidate())
|
|
567
|
+
.catch((err: unknown) => {
|
|
568
|
+
this.failed(stream, err, "extension reload");
|
|
569
|
+
});
|
|
570
|
+
}
|
|
571
|
+
this.broadcast({ type: "extensions_changed" });
|
|
572
|
+
}
|
|
573
|
+
|
|
495
574
|
private requireStream(connection: ClientConnection): SessionStream {
|
|
496
575
|
const stream = this.streamFor(connection);
|
|
497
576
|
if (!stream) {
|
|
@@ -732,10 +811,14 @@ export class WsGateway {
|
|
|
732
811
|
git: this.git,
|
|
733
812
|
repoBusy: () => this.repoBusy(host.cwd),
|
|
734
813
|
pollMs: this.pollMs,
|
|
814
|
+
requestCeilingMs: this.requestCeilingMs,
|
|
815
|
+
detachGraceMs: this.detachGraceMs,
|
|
735
816
|
});
|
|
736
817
|
stream.start();
|
|
737
818
|
this.catalogue.track(id, host.status);
|
|
738
|
-
|
|
819
|
+
// Observed rather than subscribed: this never leaves, and a reader that
|
|
820
|
+
// never leaves is a session that is never detached.
|
|
821
|
+
stream.observe((event) => {
|
|
739
822
|
if (event.type === "session_state") {
|
|
740
823
|
this.catalogue.onStatus(id, event.status);
|
|
741
824
|
this.syncRepoBusy(stream.host.cwd, id);
|
|
@@ -745,17 +828,70 @@ export class WsGateway {
|
|
|
745
828
|
return stream;
|
|
746
829
|
}
|
|
747
830
|
|
|
748
|
-
private promptWithAttachments(
|
|
831
|
+
private async promptWithAttachments(
|
|
749
832
|
stream: SessionStream,
|
|
750
833
|
command: Command & { readonly type: "user_message" }
|
|
751
|
-
):
|
|
834
|
+
): Promise<Outcome> {
|
|
835
|
+
// Trimmed once, here: pi dispatches on the text it is handed after the
|
|
836
|
+
// fallthrough trims it, so a client that does not trim would otherwise
|
|
837
|
+
// slip a command past this check and into pi's own.
|
|
838
|
+
const text = command.text.trim();
|
|
839
|
+
// Read before anything is rendered: what a command is, is its own text.
|
|
840
|
+
const dispatched = await this.dispatchCommand(stream, text);
|
|
752
841
|
const taken = this.uploads.take(
|
|
753
842
|
stream.sessionId,
|
|
754
843
|
(command.attachments ?? []).map((ref) => ref.id)
|
|
755
844
|
);
|
|
845
|
+
// A slash command carries no pictures; the uploads are still taken, so the
|
|
846
|
+
// endpoint stops holding their bytes for the rest of the session.
|
|
847
|
+
if (dispatched) {
|
|
848
|
+
return { dispatched: true };
|
|
849
|
+
}
|
|
756
850
|
const { lines, images } = Attachments.render(taken);
|
|
757
|
-
|
|
758
|
-
|
|
851
|
+
this.prompt(stream, [text, ...lines].filter(Boolean).join("\n\n"), images);
|
|
852
|
+
return {};
|
|
853
|
+
}
|
|
854
|
+
|
|
855
|
+
/**
|
|
856
|
+
* Whether `text` names an extension command, having started it if it does.
|
|
857
|
+
* Only the decision is awaited: the handler runs on beyond the ack, exactly
|
|
858
|
+
* as a turn does.
|
|
859
|
+
*/
|
|
860
|
+
private async dispatchCommand(
|
|
861
|
+
stream: SessionStream,
|
|
862
|
+
text: string
|
|
863
|
+
): Promise<boolean> {
|
|
864
|
+
const host = stream.host;
|
|
865
|
+
if (!text.startsWith("/")) {
|
|
866
|
+
return false;
|
|
867
|
+
}
|
|
868
|
+
// The picker offers extension commands only once an agent exists, so this
|
|
869
|
+
// is someone typing from memory; cold is idle, so nothing is queued behind it.
|
|
870
|
+
const agent = host.agentSession ?? (await host.ensureAgent());
|
|
871
|
+
const name = commandNameOf(text);
|
|
872
|
+
if (agent.extensionRunner.getCommand(name) === undefined) {
|
|
873
|
+
return false;
|
|
874
|
+
}
|
|
875
|
+
void stream
|
|
876
|
+
.dispatch(`/${name}`, async () => {
|
|
877
|
+
// Prompted whole, never merged into the queue: a merged string starts
|
|
878
|
+
// with the earlier message, and pi reads the leading `/` before it
|
|
879
|
+
// looks at `isStreaming` — so the turn we are holding dispatches it.
|
|
880
|
+
if (host.isStreaming) {
|
|
881
|
+
await agent.prompt(text, {
|
|
882
|
+
streamingBehavior: "steer",
|
|
883
|
+
source: "rpc",
|
|
884
|
+
});
|
|
885
|
+
return;
|
|
886
|
+
}
|
|
887
|
+
await host.run(async (session) => {
|
|
888
|
+
await session.prompt(text, { source: "rpc" });
|
|
889
|
+
});
|
|
890
|
+
})
|
|
891
|
+
.catch((err: unknown) => {
|
|
892
|
+
this.failed(stream, err, "command");
|
|
893
|
+
});
|
|
894
|
+
return true;
|
|
759
895
|
}
|
|
760
896
|
|
|
761
897
|
// Merge into the queued message: pi holds at most one, so a second queued send would be unreachable.
|
|
@@ -767,13 +903,6 @@ export class WsGateway {
|
|
|
767
903
|
const attached = images.length === 0 ? {} : { images: [...images] };
|
|
768
904
|
const host = stream.host;
|
|
769
905
|
const agent = host.agentSession;
|
|
770
|
-
const failed = (err: unknown, what: string): void => {
|
|
771
|
-
console.error(`[gateway] ${what} failed:`, err);
|
|
772
|
-
stream.push({
|
|
773
|
-
type: "error",
|
|
774
|
-
message: (err as Error).message || String(err),
|
|
775
|
-
});
|
|
776
|
-
};
|
|
777
906
|
if (agent && host.isStreaming) {
|
|
778
907
|
const queued = [...host.takeBack(), text].join("\n\n");
|
|
779
908
|
void agent
|
|
@@ -783,7 +912,7 @@ export class WsGateway {
|
|
|
783
912
|
...attached,
|
|
784
913
|
})
|
|
785
914
|
.catch((err: unknown) => {
|
|
786
|
-
failed(err, "steer");
|
|
915
|
+
this.failed(stream, err, "steer");
|
|
787
916
|
});
|
|
788
917
|
return;
|
|
789
918
|
}
|
|
@@ -792,7 +921,15 @@ export class WsGateway {
|
|
|
792
921
|
await session.prompt(text, { source: "rpc", ...attached });
|
|
793
922
|
})
|
|
794
923
|
.catch((err: unknown) => {
|
|
795
|
-
failed(err, "turn");
|
|
924
|
+
this.failed(stream, err, "turn");
|
|
796
925
|
});
|
|
797
926
|
}
|
|
927
|
+
|
|
928
|
+
private failed(stream: SessionStream, err: unknown, what: string): void {
|
|
929
|
+
console.error(`[gateway] ${what} failed:`, err);
|
|
930
|
+
stream.push({
|
|
931
|
+
type: "error",
|
|
932
|
+
message: (err as Error).message || String(err),
|
|
933
|
+
});
|
|
934
|
+
}
|
|
798
935
|
}
|
|
@@ -33,6 +33,8 @@ const USAGE = `pim probe — CLI client for pim-server, dumps every frame as JSO
|
|
|
33
33
|
--pin <path> pin a working directory, so its sessions sort first
|
|
34
34
|
--unpin <path> unpin it again
|
|
35
35
|
--list-models print the models this server can switch to
|
|
36
|
+
--list-extensions print the extensions this server can switch
|
|
37
|
+
--set-extension <id> switch one extension off, or on with --on
|
|
36
38
|
--upload <path> transfer a local file to the server, attach it to
|
|
37
39
|
--prompt (repeatable)
|
|
38
40
|
--cancel cancel the current turn
|
|
@@ -61,6 +63,9 @@ const { values } = parseArgs({
|
|
|
61
63
|
pin: { type: "string" },
|
|
62
64
|
unpin: { type: "string" },
|
|
63
65
|
"list-models": { type: "boolean", default: false },
|
|
66
|
+
"list-extensions": { type: "boolean", default: false },
|
|
67
|
+
"set-extension": { type: "string" },
|
|
68
|
+
on: { type: "boolean", default: false },
|
|
64
69
|
upload: { type: "string", multiple: true },
|
|
65
70
|
cancel: { type: "boolean", default: false },
|
|
66
71
|
dequeue: { type: "boolean", default: false },
|
|
@@ -129,6 +134,17 @@ if (values["list-sessions"]) {
|
|
|
129
134
|
if (values["list-models"]) {
|
|
130
135
|
process.stdout.write(`${JSON.stringify(await probe.listModels())}\n`);
|
|
131
136
|
}
|
|
137
|
+
if (values["list-extensions"]) {
|
|
138
|
+
for (const entry of await probe.listExtensions()) {
|
|
139
|
+
process.stdout.write(`${JSON.stringify(entry)}\n`);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
if (values["set-extension"] !== undefined) {
|
|
143
|
+
await probe.setExtension(values["set-extension"], values.on);
|
|
144
|
+
process.stderr.write(
|
|
145
|
+
`set-extension: ${values["set-extension"]} ${values.on ? "on" : "off"}\n`
|
|
146
|
+
);
|
|
147
|
+
}
|
|
132
148
|
if (values["pick-commands"] !== undefined) {
|
|
133
149
|
const items = await probe.pickCommands(values["pick-commands"]);
|
|
134
150
|
process.stderr.write(`pick-commands: ${items.length} rows\n`);
|
|
Binary file
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{n as e,t}from"./index-CpinM5NK.js";var n=e(t(((e,t)=>{function n(e){return e instanceof Map?e.clear=e.delete=e.set=function(){throw Error(`map is read-only`)}:e instanceof Set&&(e.add=e.clear=e.delete=function(){throw Error(`set is read-only`)}),Object.freeze(e),Object.getOwnPropertyNames(e).forEach(t=>{let r=e[t],i=typeof r;(i===`object`||i===`function`)&&!Object.isFrozen(r)&&n(r)}),e}var r=class{constructor(e){e.data===void 0&&(e.data={}),this.data=e.data,this.isMatchIgnored=!1}ignoreMatch(){this.isMatchIgnored=!0}};function i(e){return e.replace(/&/g,`&`).replace(/</g,`<`).replace(/>/g,`>`).replace(/"/g,`"`).replace(/'/g,`'`)}function a(e,...t){let n=Object.create(null);for(let t in e)n[t]=e[t];return t.forEach(function(e){for(let t in e)n[t]=e[t]}),n}var o=`</span>`,s=e=>!!e.scope,c=(e,{prefix:t})=>{if(e.startsWith(`language:`))return e.replace(`language:`,`language-`);if(e.includes(`.`)){let n=e.split(`.`);return[`${t}${n.shift()}`,...n.map((e,t)=>`${e}${`_`.repeat(t+1)}`)].join(` `)}return`${t}${e}`},l=class{constructor(e,t){this.buffer=``,this.classPrefix=t.classPrefix,e.walk(this)}addText(e){this.buffer+=i(e)}openNode(e){if(!s(e))return;let t=c(e.scope,{prefix:this.classPrefix});this.span(t)}closeNode(e){s(e)&&(this.buffer+=o)}value(){return this.buffer}span(e){this.buffer+=`<span class="${e}">`}},u=(e={})=>{let t={children:[]};return Object.assign(t,e),t},d=class e{constructor(){this.rootNode=u(),this.stack=[this.rootNode]}get top(){return this.stack[this.stack.length-1]}get root(){return this.rootNode}add(e){this.top.children.push(e)}openNode(e){let t=u({scope:e});this.add(t),this.stack.push(t)}closeNode(){if(this.stack.length>1)return this.stack.pop()}closeAllNodes(){for(;this.closeNode(););}toJSON(){return JSON.stringify(this.rootNode,null,4)}walk(e){return this.constructor._walk(e,this.rootNode)}static _walk(e,t){return typeof t==`string`?e.addText(t):t.children&&(e.openNode(t),t.children.forEach(t=>this._walk(e,t)),e.closeNode(t)),e}static _collapse(t){typeof t!=`string`&&t.children&&(t.children.every(e=>typeof e==`string`)?t.children=[t.children.join(``)]:t.children.forEach(t=>{e._collapse(t)}))}},f=class extends d{constructor(e){super(),this.options=e}addText(e){e!==``&&this.add(e)}startScope(e){this.openNode(e)}endScope(){this.closeNode()}__addSublanguage(e,t){let n=e.root;t&&(n.scope=`language:${t}`),this.add(n)}toHTML(){return new l(this,this.options).value()}finalize(){return this.closeAllNodes(),!0}};function p(e){return e?typeof e==`string`?e:e.source:null}function m(e){return _(`(?=`,e,`)`)}function h(e){return _(`(?:`,e,`)*`)}function g(e){return _(`(?:`,e,`)?`)}function _(...e){return e.map(e=>p(e)).join(``)}function v(e){let t=e[e.length-1];return typeof t==`object`&&t.constructor===Object?(e.splice(e.length-1,1),t):{}}function y(...e){return`(`+(v(e).capture?``:`?:`)+e.map(e=>p(e)).join(`|`)+`)`}function b(e){return RegExp(e.toString()+`|`).exec(``).length-1}function ee(e,t){let n=e&&e.exec(t);return n&&n.index===0}var x=new RegExp(y(/\[(?:[^\\\]]|\\.)*\]/,/\(\?<(?![=!])[^>]+>/,/\(\?'[^']+'/,/\(\??/,/\\([1-9][0-9]*)/,/\\./));function S(e,{joinWith:t}){let n=0;return e.map(e=>{n+=1;let t=n,r=p(e),i=``;for(;r.length>0;){let e=x.exec(r);if(!e){i+=r;break}i+=r.substring(0,e.index),r=r.substring(e.index+e[0].length),e[0][0]===`\\`&&e[1]?i+=`\\`+String(Number(e[1])+t):(i+=e[0],(e[0]===`(`||/^\(\?[<']/.test(e[0]))&&n++)}return i}).map(e=>`(${e})`).join(t)}var C=/\b\B/,w=`[a-zA-Z]\\w*`,T=`[a-zA-Z_]\\w*`,E=`\\b\\d+(\\.\\d+)?`,D=`(-?)(\\b0[xX][a-fA-F0-9]+|(\\b\\d+(\\.\\d*)?|\\.\\d+)([eE][-+]?\\d+)?)`,O=`\\b(0b[01]+)`,k=`!|!=|!==|%|%=|&|&&|&=|\\*|\\*=|\\+|\\+=|,|-|-=|/=|/|:|;|<<|<<=|<=|<|===|==|=|>>>=|>>=|>=|>>>|>>|>|\\?|\\[|\\{|\\(|\\^|\\^=|\\||\\|=|\\|\\||~`,A=(e={})=>{let t=/^#![ ]*\//;return e.binary&&(e.begin=_(t,/.*\b/,e.binary,/\b.*/)),a({scope:`meta`,begin:t,end:/$/,relevance:0,"on:begin":(e,t)=>{e.index!==0&&t.ignoreMatch()}},e)},j={begin:`\\\\[\\s\\S]`,relevance:0},M={scope:`string`,begin:`'`,end:`'`,illegal:`\\n`,contains:[j]},N={scope:`string`,begin:`"`,end:`"`,illegal:`\\n`,contains:[j]},P={begin:/\b(a|an|the|are|I'm|isn't|don't|doesn't|won't|but|just|should|pretty|simply|enough|gonna|going|wtf|so|such|will|you|your|they|like|more)\b/},F=function(e,t,n={}){let r=a({scope:`comment`,begin:e,end:t,contains:[]},n);r.contains.push({scope:`doctag`,begin:`[ ]*(?=(TODO|FIXME|NOTE|BUG|OPTIMIZE|HACK|XXX):)`,end:/(TODO|FIXME|NOTE|BUG|OPTIMIZE|HACK|XXX):/,excludeBegin:!0,relevance:0});let i=y(`I`,`a`,`is`,`so`,`us`,`to`,`at`,`if`,`in`,`it`,`on`,/[A-Za-z]+['](d|ve|re|ll|t|s|n)/,/[A-Za-z]+[-][a-z]+/,/[A-Za-z][a-z]{2,}/);return r.contains.push({begin:_(/[ ]+/,`(`,i,/[.]?[:]?([.][ ]|[ ])/,`){3}`)}),r},I=F(`//`,`$`),L=F(`/\\*`,`\\*/`),R=F(`#`,`$`),z=Object.freeze({__proto__:null,APOS_STRING_MODE:M,BACKSLASH_ESCAPE:j,BINARY_NUMBER_MODE:{scope:`number`,begin:O,relevance:0},BINARY_NUMBER_RE:O,COMMENT:F,C_BLOCK_COMMENT_MODE:L,C_LINE_COMMENT_MODE:I,C_NUMBER_MODE:{scope:`number`,begin:D,relevance:0},C_NUMBER_RE:D,END_SAME_AS_BEGIN:function(e){return Object.assign(e,{"on:begin":(e,t)=>{t.data._beginMatch=e[1]},"on:end":(e,t)=>{t.data._beginMatch!==e[1]&&t.ignoreMatch()}})},HASH_COMMENT_MODE:R,IDENT_RE:w,MATCH_NOTHING_RE:C,METHOD_GUARD:{begin:`\\.\\s*[a-zA-Z_]\\w*`,relevance:0},NUMBER_MODE:{scope:`number`,begin:E,relevance:0},NUMBER_RE:E,PHRASAL_WORDS_MODE:P,QUOTE_STRING_MODE:N,REGEXP_MODE:{scope:`regexp`,begin:/\/(?=[^/\n]*\/)/,end:/\/[gimuy]*/,contains:[j,{begin:/\[/,end:/\]/,relevance:0,contains:[j]}]},RE_STARTERS_RE:k,SHEBANG:A,TITLE_MODE:{scope:`title`,begin:w,relevance:0},UNDERSCORE_IDENT_RE:T,UNDERSCORE_TITLE_MODE:{scope:`title`,begin:T,relevance:0}});function B(e,t){e.input[e.index-1]===`.`&&t.ignoreMatch()}function te(e,t){e.className!==void 0&&(e.scope=e.className,delete e.className)}function ne(e,t){t&&e.beginKeywords&&(e.begin=`\\b(`+e.beginKeywords.split(` `).join(`|`)+`)(?!\\.)(?=\\b|\\s)`,e.__beforeBegin=B,e.keywords=e.keywords||e.beginKeywords,delete e.beginKeywords,e.relevance===void 0&&(e.relevance=0))}function re(e,t){Array.isArray(e.illegal)&&(e.illegal=y(...e.illegal))}function ie(e,t){if(e.match){if(e.begin||e.end)throw Error(`begin & end are not supported with match`);e.begin=e.match,delete e.match}}function ae(e,t){e.relevance===void 0&&(e.relevance=1)}var oe=(e,t)=>{if(!e.beforeMatch)return;if(e.starts)throw Error(`beforeMatch cannot be used with starts`);let n=Object.assign({},e);Object.keys(e).forEach(t=>{delete e[t]}),e.keywords=n.keywords,e.begin=_(n.beforeMatch,m(n.begin)),e.starts={relevance:0,contains:[Object.assign(n,{endsParent:!0})]},e.relevance=0,delete n.beforeMatch},se=[`of`,`and`,`for`,`in`,`not`,`or`,`if`,`then`,`parent`,`list`,`value`],ce=`keyword`;function V(e,t,n=ce){let r=Object.create(null);return typeof e==`string`?i(n,e.split(` `)):Array.isArray(e)?i(n,e):Object.keys(e).forEach(function(n){Object.assign(r,V(e[n],t,n))}),r;function i(e,n){t&&(n=n.map(e=>e.toLowerCase())),n.forEach(function(t){let n=t.split(`|`);r[n[0]]=[e,le(n[0],n[1])]})}}function le(e,t){return t?Number(t):+!ue(e)}function ue(e){return se.includes(e.toLowerCase())}var H={},U=e=>{console.error(e)},W=(e,...t)=>{console.log(`WARN: ${e}`,...t)},G=(e,t)=>{H[`${e}/${t}`]||(console.log(`Deprecated as of ${e}. ${t}`),H[`${e}/${t}`]=!0)},K=Error();function q(e,t,{key:n}){let r=0,i=e[n],a={},o={};for(let e=1;e<=t.length;e++)o[e+r]=i[e],a[e+r]=!0,r+=b(t[e-1]);e[n]=o,e[n]._emit=a,e[n]._multi=!0}function de(e){if(Array.isArray(e.begin)){if(e.skip||e.excludeBegin||e.returnBegin)throw U(`skip, excludeBegin, returnBegin not compatible with beginScope: {}`),K;if(typeof e.beginScope!=`object`||e.beginScope===null)throw U(`beginScope must be object`),K;q(e,e.begin,{key:`beginScope`}),e.begin=S(e.begin,{joinWith:``})}}function fe(e){if(Array.isArray(e.end)){if(e.skip||e.excludeEnd||e.returnEnd)throw U(`skip, excludeEnd, returnEnd not compatible with endScope: {}`),K;if(typeof e.endScope!=`object`||e.endScope===null)throw U(`endScope must be object`),K;q(e,e.end,{key:`endScope`}),e.end=S(e.end,{joinWith:``})}}function pe(e){e.scope&&typeof e.scope==`object`&&e.scope!==null&&(e.beginScope=e.scope,delete e.scope)}function me(e){pe(e),typeof e.beginScope==`string`&&(e.beginScope={_wrap:e.beginScope}),typeof e.endScope==`string`&&(e.endScope={_wrap:e.endScope}),de(e),fe(e)}function he(e){function t(t,n){return new RegExp(p(t),`m`+(e.case_insensitive?`i`:``)+(e.unicodeRegex?`u`:``)+(n?`g`:``))}class n{constructor(){this.matchIndexes={},this.regexes=[],this.matchAt=1,this.position=0}addRule(e,t){t.position=this.position++,this.matchIndexes[this.matchAt]=t,this.regexes.push([t,e]),this.matchAt+=b(e)+1}compile(){this.regexes.length===0&&(this.exec=()=>null);let e=this.regexes.map(e=>e[1]);this.matcherRe=t(S(e,{joinWith:`|`}),!0),this.lastIndex=0}exec(e){this.matcherRe.lastIndex=this.lastIndex;let t=this.matcherRe.exec(e);if(!t)return null;let n=t.findIndex((e,t)=>t>0&&e!==void 0),r=this.matchIndexes[n];return t.splice(0,n),Object.assign(t,r)}}class r{constructor(){this.rules=[],this.multiRegexes=[],this.count=0,this.lastIndex=0,this.regexIndex=0}getMatcher(e){if(this.multiRegexes[e])return this.multiRegexes[e];let t=new n;return this.rules.slice(e).forEach(([e,n])=>t.addRule(e,n)),t.compile(),this.multiRegexes[e]=t,t}resumingScanAtSamePosition(){return this.regexIndex!==0}considerAll(){this.regexIndex=0}addRule(e,t){this.rules.push([e,t]),t.type===`begin`&&this.count++}exec(e){let t=this.getMatcher(this.regexIndex);t.lastIndex=this.lastIndex;let n=t.exec(e);if(this.resumingScanAtSamePosition()&&!(n&&n.index===this.lastIndex)){let t=this.getMatcher(0);t.lastIndex=this.lastIndex+1,n=t.exec(e)}return n&&(this.regexIndex+=n.position+1,this.regexIndex===this.count&&this.considerAll()),n}}function i(e){let t=new r;return e.contains.forEach(e=>t.addRule(e.begin,{rule:e,type:`begin`})),e.terminatorEnd&&t.addRule(e.terminatorEnd,{type:`end`}),e.illegal&&t.addRule(e.illegal,{type:`illegal`}),t}function o(n,r){let a=n;if(n.isCompiled)return a;[te,ie,me,oe].forEach(e=>e(n,r)),e.compilerExtensions.forEach(e=>e(n,r)),n.__beforeBegin=null,[ne,re,ae].forEach(e=>e(n,r)),n.isCompiled=!0;let s=null;return typeof n.keywords==`object`&&n.keywords.$pattern&&(n.keywords=Object.assign({},n.keywords),s=n.keywords.$pattern,delete n.keywords.$pattern),s||=/\w+/,n.keywords&&=V(n.keywords,e.case_insensitive),a.keywordPatternRe=t(s,!0),r&&(n.begin||=/\B|\b/,a.beginRe=t(a.begin),!n.end&&!n.endsWithParent&&(n.end=/\B|\b/),n.end&&(a.endRe=t(a.end)),a.terminatorEnd=p(a.end)||``,n.endsWithParent&&r.terminatorEnd&&(a.terminatorEnd+=(n.end?`|`:``)+r.terminatorEnd)),n.illegal&&(a.illegalRe=t(n.illegal)),n.contains||=[],n.contains=[].concat(...n.contains.map(function(e){return ge(e===`self`?n:e)})),n.contains.forEach(function(e){o(e,a)}),n.starts&&o(n.starts,r),a.matcher=i(a),a}if(e.compilerExtensions||=[],e.contains&&e.contains.includes(`self`))throw Error("ERR: contains `self` is not supported at the top-level of a language. See documentation.");return e.classNameAliases=a(e.classNameAliases||{}),o(e)}function J(e){return e?e.endsWithParent||J(e.starts):!1}function ge(e){return e.variants&&!e.cachedVariants&&(e.cachedVariants=e.variants.map(function(t){return a(e,{variants:null},t)})),e.cachedVariants?e.cachedVariants:J(e)?a(e,{starts:e.starts?a(e.starts):null}):Object.isFrozen(e)?a(e):e}var _e=`11.12.0`,ve=class extends Error{constructor(e,t){super(e),this.name=`HTMLInjectionError`,this.html=t}},Y=i,X=a,Z=Symbol(`nomatch`),ye=7,Q=function(e){let t=Object.create(null),i=Object.create(null),a=[],o=!0,s=`Could not find the language '{}', did you forget to load/include a language module?`,c={disableAutodetect:!0,name:`Plain text`,contains:[]},l={ignoreUnescapedHTML:!1,throwUnescapedHTML:!1,noHighlightRe:/^(no-?highlight)$/i,languageDetectRe:/\blang(?:uage)?-([\w-]+)\b/i,classPrefix:`hljs-`,cssSelector:`pre code`,languages:null,__emitter:f};function u(e){return l.noHighlightRe.test(e)}function d(e){let t=e.className+` `;t+=e.parentNode?e.parentNode.className:``;let n=l.languageDetectRe.exec(t);if(n){let t=M(n[1]);return t||(W(s.replace(`{}`,n[1])),W(`Falling back to no-highlight mode for this block.`,e)),t?n[1]:`no-highlight`}return t.split(/\s+/).find(e=>u(e)||M(e))}function p(e,t,n){let r=``,i=``;typeof t==`object`?(r=e,n=t.ignoreIllegals,i=t.language):(G(`10.7.0`,`highlight(lang, code, ...args) has been deprecated.`),G(`10.7.0`,`Please use highlight(code, options) instead.
|
|
1
|
+
import{n as e,t}from"./index-CTrlTM53.js";var n=e(t(((e,t)=>{function n(e){return e instanceof Map?e.clear=e.delete=e.set=function(){throw Error(`map is read-only`)}:e instanceof Set&&(e.add=e.clear=e.delete=function(){throw Error(`set is read-only`)}),Object.freeze(e),Object.getOwnPropertyNames(e).forEach(t=>{let r=e[t],i=typeof r;(i===`object`||i===`function`)&&!Object.isFrozen(r)&&n(r)}),e}var r=class{constructor(e){e.data===void 0&&(e.data={}),this.data=e.data,this.isMatchIgnored=!1}ignoreMatch(){this.isMatchIgnored=!0}};function i(e){return e.replace(/&/g,`&`).replace(/</g,`<`).replace(/>/g,`>`).replace(/"/g,`"`).replace(/'/g,`'`)}function a(e,...t){let n=Object.create(null);for(let t in e)n[t]=e[t];return t.forEach(function(e){for(let t in e)n[t]=e[t]}),n}var o=`</span>`,s=e=>!!e.scope,c=(e,{prefix:t})=>{if(e.startsWith(`language:`))return e.replace(`language:`,`language-`);if(e.includes(`.`)){let n=e.split(`.`);return[`${t}${n.shift()}`,...n.map((e,t)=>`${e}${`_`.repeat(t+1)}`)].join(` `)}return`${t}${e}`},l=class{constructor(e,t){this.buffer=``,this.classPrefix=t.classPrefix,e.walk(this)}addText(e){this.buffer+=i(e)}openNode(e){if(!s(e))return;let t=c(e.scope,{prefix:this.classPrefix});this.span(t)}closeNode(e){s(e)&&(this.buffer+=o)}value(){return this.buffer}span(e){this.buffer+=`<span class="${e}">`}},u=(e={})=>{let t={children:[]};return Object.assign(t,e),t},d=class e{constructor(){this.rootNode=u(),this.stack=[this.rootNode]}get top(){return this.stack[this.stack.length-1]}get root(){return this.rootNode}add(e){this.top.children.push(e)}openNode(e){let t=u({scope:e});this.add(t),this.stack.push(t)}closeNode(){if(this.stack.length>1)return this.stack.pop()}closeAllNodes(){for(;this.closeNode(););}toJSON(){return JSON.stringify(this.rootNode,null,4)}walk(e){return this.constructor._walk(e,this.rootNode)}static _walk(e,t){return typeof t==`string`?e.addText(t):t.children&&(e.openNode(t),t.children.forEach(t=>this._walk(e,t)),e.closeNode(t)),e}static _collapse(t){typeof t!=`string`&&t.children&&(t.children.every(e=>typeof e==`string`)?t.children=[t.children.join(``)]:t.children.forEach(t=>{e._collapse(t)}))}},f=class extends d{constructor(e){super(),this.options=e}addText(e){e!==``&&this.add(e)}startScope(e){this.openNode(e)}endScope(){this.closeNode()}__addSublanguage(e,t){let n=e.root;t&&(n.scope=`language:${t}`),this.add(n)}toHTML(){return new l(this,this.options).value()}finalize(){return this.closeAllNodes(),!0}};function p(e){return e?typeof e==`string`?e:e.source:null}function m(e){return _(`(?=`,e,`)`)}function h(e){return _(`(?:`,e,`)*`)}function g(e){return _(`(?:`,e,`)?`)}function _(...e){return e.map(e=>p(e)).join(``)}function v(e){let t=e[e.length-1];return typeof t==`object`&&t.constructor===Object?(e.splice(e.length-1,1),t):{}}function y(...e){return`(`+(v(e).capture?``:`?:`)+e.map(e=>p(e)).join(`|`)+`)`}function b(e){return RegExp(e.toString()+`|`).exec(``).length-1}function ee(e,t){let n=e&&e.exec(t);return n&&n.index===0}var x=new RegExp(y(/\[(?:[^\\\]]|\\.)*\]/,/\(\?<(?![=!])[^>]+>/,/\(\?'[^']+'/,/\(\??/,/\\([1-9][0-9]*)/,/\\./));function S(e,{joinWith:t}){let n=0;return e.map(e=>{n+=1;let t=n,r=p(e),i=``;for(;r.length>0;){let e=x.exec(r);if(!e){i+=r;break}i+=r.substring(0,e.index),r=r.substring(e.index+e[0].length),e[0][0]===`\\`&&e[1]?i+=`\\`+String(Number(e[1])+t):(i+=e[0],(e[0]===`(`||/^\(\?[<']/.test(e[0]))&&n++)}return i}).map(e=>`(${e})`).join(t)}var C=/\b\B/,w=`[a-zA-Z]\\w*`,T=`[a-zA-Z_]\\w*`,E=`\\b\\d+(\\.\\d+)?`,D=`(-?)(\\b0[xX][a-fA-F0-9]+|(\\b\\d+(\\.\\d*)?|\\.\\d+)([eE][-+]?\\d+)?)`,O=`\\b(0b[01]+)`,k=`!|!=|!==|%|%=|&|&&|&=|\\*|\\*=|\\+|\\+=|,|-|-=|/=|/|:|;|<<|<<=|<=|<|===|==|=|>>>=|>>=|>=|>>>|>>|>|\\?|\\[|\\{|\\(|\\^|\\^=|\\||\\|=|\\|\\||~`,A=(e={})=>{let t=/^#![ ]*\//;return e.binary&&(e.begin=_(t,/.*\b/,e.binary,/\b.*/)),a({scope:`meta`,begin:t,end:/$/,relevance:0,"on:begin":(e,t)=>{e.index!==0&&t.ignoreMatch()}},e)},j={begin:`\\\\[\\s\\S]`,relevance:0},M={scope:`string`,begin:`'`,end:`'`,illegal:`\\n`,contains:[j]},N={scope:`string`,begin:`"`,end:`"`,illegal:`\\n`,contains:[j]},P={begin:/\b(a|an|the|are|I'm|isn't|don't|doesn't|won't|but|just|should|pretty|simply|enough|gonna|going|wtf|so|such|will|you|your|they|like|more)\b/},F=function(e,t,n={}){let r=a({scope:`comment`,begin:e,end:t,contains:[]},n);r.contains.push({scope:`doctag`,begin:`[ ]*(?=(TODO|FIXME|NOTE|BUG|OPTIMIZE|HACK|XXX):)`,end:/(TODO|FIXME|NOTE|BUG|OPTIMIZE|HACK|XXX):/,excludeBegin:!0,relevance:0});let i=y(`I`,`a`,`is`,`so`,`us`,`to`,`at`,`if`,`in`,`it`,`on`,/[A-Za-z]+['](d|ve|re|ll|t|s|n)/,/[A-Za-z]+[-][a-z]+/,/[A-Za-z][a-z]{2,}/);return r.contains.push({begin:_(/[ ]+/,`(`,i,/[.]?[:]?([.][ ]|[ ])/,`){3}`)}),r},I=F(`//`,`$`),L=F(`/\\*`,`\\*/`),R=F(`#`,`$`),z=Object.freeze({__proto__:null,APOS_STRING_MODE:M,BACKSLASH_ESCAPE:j,BINARY_NUMBER_MODE:{scope:`number`,begin:O,relevance:0},BINARY_NUMBER_RE:O,COMMENT:F,C_BLOCK_COMMENT_MODE:L,C_LINE_COMMENT_MODE:I,C_NUMBER_MODE:{scope:`number`,begin:D,relevance:0},C_NUMBER_RE:D,END_SAME_AS_BEGIN:function(e){return Object.assign(e,{"on:begin":(e,t)=>{t.data._beginMatch=e[1]},"on:end":(e,t)=>{t.data._beginMatch!==e[1]&&t.ignoreMatch()}})},HASH_COMMENT_MODE:R,IDENT_RE:w,MATCH_NOTHING_RE:C,METHOD_GUARD:{begin:`\\.\\s*[a-zA-Z_]\\w*`,relevance:0},NUMBER_MODE:{scope:`number`,begin:E,relevance:0},NUMBER_RE:E,PHRASAL_WORDS_MODE:P,QUOTE_STRING_MODE:N,REGEXP_MODE:{scope:`regexp`,begin:/\/(?=[^/\n]*\/)/,end:/\/[gimuy]*/,contains:[j,{begin:/\[/,end:/\]/,relevance:0,contains:[j]}]},RE_STARTERS_RE:k,SHEBANG:A,TITLE_MODE:{scope:`title`,begin:w,relevance:0},UNDERSCORE_IDENT_RE:T,UNDERSCORE_TITLE_MODE:{scope:`title`,begin:T,relevance:0}});function B(e,t){e.input[e.index-1]===`.`&&t.ignoreMatch()}function te(e,t){e.className!==void 0&&(e.scope=e.className,delete e.className)}function ne(e,t){t&&e.beginKeywords&&(e.begin=`\\b(`+e.beginKeywords.split(` `).join(`|`)+`)(?!\\.)(?=\\b|\\s)`,e.__beforeBegin=B,e.keywords=e.keywords||e.beginKeywords,delete e.beginKeywords,e.relevance===void 0&&(e.relevance=0))}function re(e,t){Array.isArray(e.illegal)&&(e.illegal=y(...e.illegal))}function ie(e,t){if(e.match){if(e.begin||e.end)throw Error(`begin & end are not supported with match`);e.begin=e.match,delete e.match}}function ae(e,t){e.relevance===void 0&&(e.relevance=1)}var oe=(e,t)=>{if(!e.beforeMatch)return;if(e.starts)throw Error(`beforeMatch cannot be used with starts`);let n=Object.assign({},e);Object.keys(e).forEach(t=>{delete e[t]}),e.keywords=n.keywords,e.begin=_(n.beforeMatch,m(n.begin)),e.starts={relevance:0,contains:[Object.assign(n,{endsParent:!0})]},e.relevance=0,delete n.beforeMatch},se=[`of`,`and`,`for`,`in`,`not`,`or`,`if`,`then`,`parent`,`list`,`value`],ce=`keyword`;function V(e,t,n=ce){let r=Object.create(null);return typeof e==`string`?i(n,e.split(` `)):Array.isArray(e)?i(n,e):Object.keys(e).forEach(function(n){Object.assign(r,V(e[n],t,n))}),r;function i(e,n){t&&(n=n.map(e=>e.toLowerCase())),n.forEach(function(t){let n=t.split(`|`);r[n[0]]=[e,le(n[0],n[1])]})}}function le(e,t){return t?Number(t):+!ue(e)}function ue(e){return se.includes(e.toLowerCase())}var H={},U=e=>{console.error(e)},W=(e,...t)=>{console.log(`WARN: ${e}`,...t)},G=(e,t)=>{H[`${e}/${t}`]||(console.log(`Deprecated as of ${e}. ${t}`),H[`${e}/${t}`]=!0)},K=Error();function q(e,t,{key:n}){let r=0,i=e[n],a={},o={};for(let e=1;e<=t.length;e++)o[e+r]=i[e],a[e+r]=!0,r+=b(t[e-1]);e[n]=o,e[n]._emit=a,e[n]._multi=!0}function de(e){if(Array.isArray(e.begin)){if(e.skip||e.excludeBegin||e.returnBegin)throw U(`skip, excludeBegin, returnBegin not compatible with beginScope: {}`),K;if(typeof e.beginScope!=`object`||e.beginScope===null)throw U(`beginScope must be object`),K;q(e,e.begin,{key:`beginScope`}),e.begin=S(e.begin,{joinWith:``})}}function fe(e){if(Array.isArray(e.end)){if(e.skip||e.excludeEnd||e.returnEnd)throw U(`skip, excludeEnd, returnEnd not compatible with endScope: {}`),K;if(typeof e.endScope!=`object`||e.endScope===null)throw U(`endScope must be object`),K;q(e,e.end,{key:`endScope`}),e.end=S(e.end,{joinWith:``})}}function pe(e){e.scope&&typeof e.scope==`object`&&e.scope!==null&&(e.beginScope=e.scope,delete e.scope)}function me(e){pe(e),typeof e.beginScope==`string`&&(e.beginScope={_wrap:e.beginScope}),typeof e.endScope==`string`&&(e.endScope={_wrap:e.endScope}),de(e),fe(e)}function he(e){function t(t,n){return new RegExp(p(t),`m`+(e.case_insensitive?`i`:``)+(e.unicodeRegex?`u`:``)+(n?`g`:``))}class n{constructor(){this.matchIndexes={},this.regexes=[],this.matchAt=1,this.position=0}addRule(e,t){t.position=this.position++,this.matchIndexes[this.matchAt]=t,this.regexes.push([t,e]),this.matchAt+=b(e)+1}compile(){this.regexes.length===0&&(this.exec=()=>null);let e=this.regexes.map(e=>e[1]);this.matcherRe=t(S(e,{joinWith:`|`}),!0),this.lastIndex=0}exec(e){this.matcherRe.lastIndex=this.lastIndex;let t=this.matcherRe.exec(e);if(!t)return null;let n=t.findIndex((e,t)=>t>0&&e!==void 0),r=this.matchIndexes[n];return t.splice(0,n),Object.assign(t,r)}}class r{constructor(){this.rules=[],this.multiRegexes=[],this.count=0,this.lastIndex=0,this.regexIndex=0}getMatcher(e){if(this.multiRegexes[e])return this.multiRegexes[e];let t=new n;return this.rules.slice(e).forEach(([e,n])=>t.addRule(e,n)),t.compile(),this.multiRegexes[e]=t,t}resumingScanAtSamePosition(){return this.regexIndex!==0}considerAll(){this.regexIndex=0}addRule(e,t){this.rules.push([e,t]),t.type===`begin`&&this.count++}exec(e){let t=this.getMatcher(this.regexIndex);t.lastIndex=this.lastIndex;let n=t.exec(e);if(this.resumingScanAtSamePosition()&&!(n&&n.index===this.lastIndex)){let t=this.getMatcher(0);t.lastIndex=this.lastIndex+1,n=t.exec(e)}return n&&(this.regexIndex+=n.position+1,this.regexIndex===this.count&&this.considerAll()),n}}function i(e){let t=new r;return e.contains.forEach(e=>t.addRule(e.begin,{rule:e,type:`begin`})),e.terminatorEnd&&t.addRule(e.terminatorEnd,{type:`end`}),e.illegal&&t.addRule(e.illegal,{type:`illegal`}),t}function o(n,r){let a=n;if(n.isCompiled)return a;[te,ie,me,oe].forEach(e=>e(n,r)),e.compilerExtensions.forEach(e=>e(n,r)),n.__beforeBegin=null,[ne,re,ae].forEach(e=>e(n,r)),n.isCompiled=!0;let s=null;return typeof n.keywords==`object`&&n.keywords.$pattern&&(n.keywords=Object.assign({},n.keywords),s=n.keywords.$pattern,delete n.keywords.$pattern),s||=/\w+/,n.keywords&&=V(n.keywords,e.case_insensitive),a.keywordPatternRe=t(s,!0),r&&(n.begin||=/\B|\b/,a.beginRe=t(a.begin),!n.end&&!n.endsWithParent&&(n.end=/\B|\b/),n.end&&(a.endRe=t(a.end)),a.terminatorEnd=p(a.end)||``,n.endsWithParent&&r.terminatorEnd&&(a.terminatorEnd+=(n.end?`|`:``)+r.terminatorEnd)),n.illegal&&(a.illegalRe=t(n.illegal)),n.contains||=[],n.contains=[].concat(...n.contains.map(function(e){return ge(e===`self`?n:e)})),n.contains.forEach(function(e){o(e,a)}),n.starts&&o(n.starts,r),a.matcher=i(a),a}if(e.compilerExtensions||=[],e.contains&&e.contains.includes(`self`))throw Error("ERR: contains `self` is not supported at the top-level of a language. See documentation.");return e.classNameAliases=a(e.classNameAliases||{}),o(e)}function J(e){return e?e.endsWithParent||J(e.starts):!1}function ge(e){return e.variants&&!e.cachedVariants&&(e.cachedVariants=e.variants.map(function(t){return a(e,{variants:null},t)})),e.cachedVariants?e.cachedVariants:J(e)?a(e,{starts:e.starts?a(e.starts):null}):Object.isFrozen(e)?a(e):e}var _e=`11.12.0`,ve=class extends Error{constructor(e,t){super(e),this.name=`HTMLInjectionError`,this.html=t}},Y=i,X=a,Z=Symbol(`nomatch`),ye=7,Q=function(e){let t=Object.create(null),i=Object.create(null),a=[],o=!0,s=`Could not find the language '{}', did you forget to load/include a language module?`,c={disableAutodetect:!0,name:`Plain text`,contains:[]},l={ignoreUnescapedHTML:!1,throwUnescapedHTML:!1,noHighlightRe:/^(no-?highlight)$/i,languageDetectRe:/\blang(?:uage)?-([\w-]+)\b/i,classPrefix:`hljs-`,cssSelector:`pre code`,languages:null,__emitter:f};function u(e){return l.noHighlightRe.test(e)}function d(e){let t=e.className+` `;t+=e.parentNode?e.parentNode.className:``;let n=l.languageDetectRe.exec(t);if(n){let t=M(n[1]);return t||(W(s.replace(`{}`,n[1])),W(`Falling back to no-highlight mode for this block.`,e)),t?n[1]:`no-highlight`}return t.split(/\s+/).find(e=>u(e)||M(e))}function p(e,t,n){let r=``,i=``;typeof t==`object`?(r=e,n=t.ignoreIllegals,i=t.language):(G(`10.7.0`,`highlight(lang, code, ...args) has been deprecated.`),G(`10.7.0`,`Please use highlight(code, options) instead.
|
|
2
2
|
https://github.com/highlightjs/highlight.js/issues/2277`),i=e,r=t),n===void 0&&(n=!0);let a={code:r,language:i};R(`before:highlight`,a);let o=a.result?a.result:v(a.language,a.code,n);return o.code=a.code,R(`after:highlight`,o),o}function v(e,n,i,a){let c=Object.create(null);function u(e,t){return e.keywords[t]}function d(){if(!k.keywords){j.addText(N);return}let e=0;k.keywordPatternRe.lastIndex=0;let t=k.keywordPatternRe.exec(N),n=``;for(;t;){n+=N.substring(e,t.index);let r=E.case_insensitive?t[0].toLowerCase():t[0],i=u(k,r);if(i){let[e,a]=i;if(j.addText(n),n=``,c[r]=(c[r]||0)+1,c[r]<=ye&&(P+=a),e.startsWith(`_`))n+=t[0];else{let n=E.classNameAliases[e]||e;m(t[0],n)}}else n+=t[0];e=k.keywordPatternRe.lastIndex,t=k.keywordPatternRe.exec(N)}n+=N.substring(e),j.addText(n)}function f(){if(N===``)return;let e=null;if(typeof k.subLanguage==`string`){if(!t[k.subLanguage]){j.addText(N);return}e=v(k.subLanguage,N,!0,A[k.subLanguage]),A[k.subLanguage]=e._top}else e=x(N,k.subLanguage.length?k.subLanguage:null);k.relevance>0&&(P+=e.relevance),j.__addSublanguage(e._emitter,e.language)}function p(){k.subLanguage==null?d():f(),N=``}function m(e,t){e!==``&&(j.startScope(t),j.addText(e),j.endScope())}function h(e,t){let n=1,r=t.length-1;for(;n<=r;){if(!e._emit[n]){n++;continue}let r=E.classNameAliases[e[n]]||e[n],i=t[n];r?m(i,r):(N=i,d(),N=``),n++}}function g(e,t){return e.scope&&typeof e.scope==`string`&&j.openNode(E.classNameAliases[e.scope]||e.scope),e.beginScope&&(e.beginScope._wrap?(m(N,E.classNameAliases[e.beginScope._wrap]||e.beginScope._wrap),N=``):e.beginScope._multi&&(h(e.beginScope,t),N=``)),k=Object.create(e,{parent:{value:k}}),k}function _(e,t,n){let i=ee(e.endRe,n);if(i){if(e[`on:end`]){let n=new r(e);e[`on:end`](t,n),n.isMatchIgnored&&(i=!1)}if(i){for(;e.endsParent&&e.parent;)e=e.parent;return e}}if(e.endsWithParent)return _(e.parent,t,n)}function y(e){return k.matcher.regexIndex===0?(N+=e[0],1):(L=!0,0)}function b(e){let t=e[0],n=e.rule,i=new r(n),a=[n.__beforeBegin,n[`on:begin`]];for(let n of a)if(n&&(n(e,i),i.isMatchIgnored))return y(t);return n.skip?N+=t:(n.excludeBegin&&(N+=t),p(),!n.returnBegin&&!n.excludeBegin&&(N=t)),g(n,e),n.returnBegin?0:t.length}function S(e){let t=e[0],r=n.substring(e.index),i=_(k,e,r);if(!i)return Z;let a=k;k.endScope&&k.endScope._wrap?(p(),m(t,k.endScope._wrap)):k.endScope&&k.endScope._multi?(p(),h(k.endScope,e)):a.skip?N+=t:(a.returnEnd||a.excludeEnd||(N+=t),p(),a.excludeEnd&&(N=t));do k.scope&&j.closeNode(),!k.skip&&!k.subLanguage&&(P+=k.relevance),k=k.parent;while(k!==i.parent);return i.starts&&g(i.starts,e),a.returnEnd?0:t.length}function C(){let e=[];for(let t=k;t!==E;t=t.parent)t.scope&&e.unshift(t.scope);e.forEach(e=>j.openNode(e))}let w={};function T(t,r){let a=r&&r[0];if(N+=t,a==null)return p(),0;if(w.type===`begin`&&r.type===`end`&&w.index===r.index&&a===``){if(N+=n.slice(r.index,r.index+1),!o){let t=Error(`0 width match regex (${e})`);throw t.languageName=e,t.badRule=w.rule,t}return 1}if(w=r,r.type===`begin`)return b(r);if(r.type===`illegal`&&!i){let e=Error(`Illegal lexeme "`+a+`" for mode "`+(k.scope||`<unnamed>`)+`"`);throw e.mode=k,e}if(r.type===`end`){let e=S(r);if(e!==Z)return e}if(r.type===`illegal`&&a===``)return r.index===n.length||(N+=`
|
|
3
3
|
`),1;if(I>1e5&&I>r.index*3)throw Error(`potential infinite loop, way more iterations than matches`);return N+=a,a.length}let E=M(e);if(!E)throw U(s.replace(`{}`,e)),Error(`Unknown language: "`+e+`"`);let D=he(E),O=``,k=a||D,A={},j=new l.__emitter(l);C();let N=``,P=0,F=0,I=0,L=!1;try{if(E.__emitTokens)E.__emitTokens(n,j);else{for(k.matcher.considerAll();;){I++,L?L=!1:k.matcher.considerAll(),k.matcher.lastIndex=F;let e=k.matcher.exec(n);if(!e)break;let t=T(n.substring(F,e.index),e);F=e.index+t}T(n.substring(F))}return j.finalize(),O=j.toHTML(),{language:e,value:O,relevance:P,illegal:!1,_emitter:j,_top:k}}catch(t){if(t.message&&t.message.includes(`Illegal`))return{language:e,value:Y(n),illegal:!0,relevance:0,_illegalBy:{message:t.message,index:F,context:n.slice(F-100,F+100),mode:t.mode,resultSoFar:O},_emitter:j};if(o)return{language:e,value:Y(n),illegal:!1,relevance:0,errorRaised:t,_emitter:j,_top:k};throw t}}function b(e){let t={value:Y(e),illegal:!1,relevance:0,_top:c,_emitter:new l.__emitter(l)};return t._emitter.addText(e),t}function x(e,n){n=n||l.languages||Object.keys(t);let r=b(e),i=n.filter(M).filter(P).map(t=>v(t,e,!1));i.unshift(r);let[a,o]=i.sort((e,t)=>{if(e.relevance!==t.relevance)return t.relevance-e.relevance;if(e.language&&t.language){if(M(e.language).supersetOf===t.language)return 1;if(M(t.language).supersetOf===e.language)return-1}return 0}),s=a;return s.secondBest=o,s}function S(e,t,n){let r=t&&i[t]||n;e.classList.add(`hljs`),e.classList.add(`language-${r}`)}function C(e){let t=null,n=d(e);if(u(n))return;if(R(`before:highlightElement`,{el:e,language:n}),e.dataset.highlighted){console.log("Element previously highlighted. To highlight again, first unset `dataset.highlighted`.",e);return}if(e.children.length>0&&(l.ignoreUnescapedHTML||(console.warn(`One of your code blocks includes unescaped HTML. This is a potentially serious security risk.`),console.warn(`https://github.com/highlightjs/highlight.js/wiki/security`),console.warn(`The element with unescaped HTML:`),console.warn(e)),l.throwUnescapedHTML))throw new ve(`One of your code blocks includes unescaped HTML.`,e.innerHTML);t=e;let r=t.textContent,i=n?p(r,{language:n,ignoreIllegals:!0}):x(r);e.innerHTML=i.value,e.dataset.highlighted=`yes`,S(e,n,i.language),e.result={language:i.language,re:i.relevance,relevance:i.relevance},i.secondBest&&(e.secondBest={language:i.secondBest.language,relevance:i.secondBest.relevance}),R(`after:highlightElement`,{el:e,result:i,text:r})}function w(e){l=X(l,e)}let T=()=>{O(),G(`10.6.0`,`initHighlighting() deprecated. Use highlightAll() now.`)};function E(){O(),G(`10.6.0`,`initHighlightingOnLoad() deprecated. Use highlightAll() now.`)}let D=!1;function O(){function e(){O()}if(document.readyState===`loading`){D||window.addEventListener(`DOMContentLoaded`,e,!1),D=!0;return}document.querySelectorAll(l.cssSelector).forEach(C)}function k(n,r){let i=null;try{i=r(e)}catch(e){if(U(`Language definition for '{}' could not be registered.`.replace(`{}`,n)),o)U(e);else throw e;i=c}i.name||(i.name=n),t[n]=i,i.rawDefinition=r.bind(null,e),i.aliases&&N(i.aliases,{languageName:n})}function A(e){delete t[e];for(let t of Object.keys(i))i[t]===e&&delete i[t]}function j(){return Object.keys(t)}function M(e){return e=(e||``).toLowerCase(),t[e]||t[i[e]]}function N(e,{languageName:t}){typeof e==`string`&&(e=[e]),e.forEach(e=>{i[e.toLowerCase()]=t})}function P(e){let t=M(e);return t&&!t.disableAutodetect}function F(e){e[`before:highlightBlock`]&&!e[`before:highlightElement`]&&(e[`before:highlightElement`]=t=>{e[`before:highlightBlock`](Object.assign({block:t.el},t))}),e[`after:highlightBlock`]&&!e[`after:highlightElement`]&&(e[`after:highlightElement`]=t=>{e[`after:highlightBlock`](Object.assign({block:t.el},t))})}function I(e){F(e),a.push(e)}function L(e){let t=a.indexOf(e);t!==-1&&a.splice(t,1)}function R(e,t){let n=e;a.forEach(function(e){e[n]&&e[n](t)})}function B(e){return G(`10.7.0`,`highlightBlock will be removed entirely in v12.0`),G(`10.7.0`,`Please use highlightElement now.`),C(e)}Object.assign(e,{highlight:p,highlightAuto:x,highlightAll:O,highlightElement:C,highlightBlock:B,configure:w,initHighlighting:T,initHighlightingOnLoad:E,registerLanguage:k,unregisterLanguage:A,listLanguages:j,getLanguage:M,registerAliases:N,autoDetection:P,inherit:X,addPlugin:I,removePlugin:L}),e.debugMode=function(){o=!1},e.safeMode=function(){o=!0},e.versionString=_e,e.regex={concat:_,lookahead:m,either:y,optional:g,anyNumberOfTimes:h};for(let e in z)typeof z[e]==`object`&&n(z[e]);return Object.assign(e,z),e},$=Q({});$.newInstance=()=>Q({}),t.exports=$,$.HighlightJS=$,$.default=$}))()).default;export{n as default};
|