free-pi-cli 0.4.5 → 0.4.7
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/index.js +1 -1
- package/dist/{main-r61kpjqw.js → main-ep5298x9.js} +2806 -38
- package/package.json +1 -1
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
// src/main.ts
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
4
|
+
import { spawn as spawn2 } from "node:child_process";
|
|
5
|
+
import { realpathSync, writeFileSync as writeFileSync2 } from "node:fs";
|
|
6
|
+
import { dirname as dirname5, join as join6 } from "node:path";
|
|
6
7
|
|
|
7
8
|
// src/browser.ts
|
|
8
9
|
import { spawn } from "node:child_process";
|
|
@@ -45,7 +46,7 @@ function openBrowser(url, platform = process.platform, spawnImpl = spawn) {
|
|
|
45
46
|
// package.json
|
|
46
47
|
var package_default = {
|
|
47
48
|
name: "free-pi-cli",
|
|
48
|
-
version: "0.4.
|
|
49
|
+
version: "0.4.7",
|
|
49
50
|
description: "Free, ad-supported distribution of the pi coding agent. Inference paid for by ads.",
|
|
50
51
|
license: "MIT",
|
|
51
52
|
type: "module",
|
|
@@ -5238,6 +5239,2585 @@ async function fetchMe(deps) {
|
|
|
5238
5239
|
|
|
5239
5240
|
// ../pi-ads/src/style.ts
|
|
5240
5241
|
import { createHash as createHash2 } from "node:crypto";
|
|
5242
|
+
|
|
5243
|
+
// ../../node_modules/.bun/marked@18.0.11/node_modules/marked/lib/marked.esm.js
|
|
5244
|
+
function A() {
|
|
5245
|
+
return { async: false, breaks: false, extensions: null, gfm: true, hooks: null, pedantic: false, renderer: null, silent: false, tokenizer: null, walkTokens: null };
|
|
5246
|
+
}
|
|
5247
|
+
var R = A();
|
|
5248
|
+
function j(l) {
|
|
5249
|
+
R = l;
|
|
5250
|
+
}
|
|
5251
|
+
var z = { exec: () => null };
|
|
5252
|
+
function I(l) {
|
|
5253
|
+
let e = [];
|
|
5254
|
+
return (t) => {
|
|
5255
|
+
let n = Math.max(0, Math.min(3, t - 1)), s = e[n];
|
|
5256
|
+
return s || (s = l(n), e[n] = s), s;
|
|
5257
|
+
};
|
|
5258
|
+
}
|
|
5259
|
+
function k(l, e = "") {
|
|
5260
|
+
let t = typeof l == "string" ? l : l.source, n = { replace: (s, r) => {
|
|
5261
|
+
let i = typeof r == "string" ? r : r.source;
|
|
5262
|
+
return i = i.replace(m.caret, "$1"), t = t.replace(s, i), n;
|
|
5263
|
+
}, getRegex: () => new RegExp(t, e) };
|
|
5264
|
+
return n;
|
|
5265
|
+
}
|
|
5266
|
+
var Oe = ((l = "") => {
|
|
5267
|
+
try {
|
|
5268
|
+
return !!new RegExp("(?<=1)(?<!1)" + l);
|
|
5269
|
+
} catch {
|
|
5270
|
+
return false;
|
|
5271
|
+
}
|
|
5272
|
+
})();
|
|
5273
|
+
var m = { codeRemoveIndent: /^(?: {1,4}| {0,3}\t)/gm, outputLinkReplace: /\\([\[\]])/g, indentCodeCompensation: /^(\s+)(?:```)/, beginningSpace: /^\s+/, endingHash: /#$/, startingSpaceChar: /^ /, endingSpaceChar: / $/, nonSpaceChar: /[^ ]/, newLineCharGlobal: /\n/g, tabCharGlobal: /\t/g, multipleSpaceGlobal: /\s+/g, blankLine: /^[ \t]*$/, doubleBlankLine: /\n[ \t]*\n[ \t]*$/, blockquoteStart: /^ {0,3}>/, blockquoteSetextReplace: /\n {0,3}((?:=+|-+) *)(?=\n|$)/g, blockquoteSetextReplace2: /^ {0,3}>[ \t]?/gm, listReplaceNesting: /^ {1,4}(?=( {4})*[^ ])/g, listIsTask: /^\[[ xX]\] +\S/, listReplaceTask: /^\[[ xX]\] +/, listTaskCheckbox: /\[[ xX]\]/, anyLine: /\n.*\n/, hrefBrackets: /^<(.*)>$/, tableDelimiter: /[:|]/, tableAlignChars: /^\||\| *$/g, tableRowBlankLine: /\n[ \t]*$/, tableAlignRight: /^ *-+: *$/, tableAlignCenter: /^ *:-+: *$/, tableAlignLeft: /^ *:-+ *$/, startATag: /^<a /i, endATag: /^<\/a>/i, startPreScriptTag: /^<(pre|code|kbd|script)(\s|>)/i, endPreScriptTag: /^<\/(pre|code|kbd|script)(\s|>)/i, startAngleBracket: /^</, endAngleBracket: />$/, pedanticHrefTitle: /^([^'"]*[^\s])\s+(['"])(.*)\2/, unicodeAlphaNumeric: /[\p{L}\p{N}]/u, escapeTest: /[&<>"']/, escapeReplace: /[&<>"']/g, escapeTestNoEncode: /[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/, escapeReplaceNoEncode: /[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/g, caret: /(^|[^\[])\^/g, percentDecode: /%25/g, findPipe: /\|/g, splitPipe: / \|/, slashPipe: /\\\|/g, carriageReturn: /\r\n|\r/g, spaceLine: /^ +$/gm, notSpaceStart: /^\S*/, endingNewline: /\n$/, listItemRegex: (l) => new RegExp(`^( {0,3}${l})((?:[ ][^\\n]*)?(?:\\n|$))`), nextBulletRegex: I((l) => new RegExp(`^ {0,${l}}(?:[*+-]|\\d{1,9}[.)])((?:[ ][^\\n]*)?(?:\\n|$))`)), hrRegex: I((l) => new RegExp(`^ {0,${l}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`)), fencesBeginRegex: I((l) => new RegExp(`^ {0,${l}}(?:\`\`\`|~~~)`)), headingBeginRegex: I((l) => new RegExp(`^ {0,${l}}#`)), htmlBeginRegex: I((l) => new RegExp(`^ {0,${l}}<(?:[a-z].*>|!--)`, "i")), blockquoteBeginRegex: I((l) => new RegExp(`^ {0,${l}}>`)) };
|
|
5274
|
+
var Te = /^(?:[ \t]*(?:\n|$))+/;
|
|
5275
|
+
var we = /^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/;
|
|
5276
|
+
var ye = /^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/;
|
|
5277
|
+
var q = /^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/;
|
|
5278
|
+
var Pe = /^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/;
|
|
5279
|
+
var U = / {0,3}(?:[*+-]|\d{1,9}[.)])/;
|
|
5280
|
+
var oe = /^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html|table))+?)\n {0,3}(=+|-+) *(?:\n+|$)/;
|
|
5281
|
+
var ae = k(oe).replace(/bull/g, U).replace(/blockCode/g, /(?: {4}| {0,3}\t)/).replace(/fences/g, / {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g, / {0,3}>/).replace(/heading/g, / {0,3}#{1,6}(?:\s|$)/).replace(/html/g, / {0,3}<[^\n>]+>\n/).replace(/\|table/g, "").getRegex();
|
|
5282
|
+
var Se = k(oe).replace(/bull/g, U).replace(/blockCode/g, /(?: {4}| {0,3}\t)/).replace(/fences/g, / {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g, / {0,3}>/).replace(/heading/g, / {0,3}#{1,6}(?:\s|$)/).replace(/html/g, / {0,3}<[^\n>]+>\n/).replace(/table/g, / {0,3}\|?(?:[:\- ]*\|)+[\:\- ]*\n/).getRegex();
|
|
5283
|
+
var K = /^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table|[ \t]+\n)[^\n]+)*)/;
|
|
5284
|
+
var _e = /^[^\n]+/;
|
|
5285
|
+
var W = /(?!\s*\])(?:\\[\s\S]|[^\[\]\\])+/;
|
|
5286
|
+
var $e = k(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/).replace("label", W).replace("title", /(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex();
|
|
5287
|
+
var Le = k(/^(bull)([ \t][^\n]*?)?(?:\n|$)/).replace(/bull/g, U).getRegex();
|
|
5288
|
+
var Q = "address|article|aside|base|basefont|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h[1-6]|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|meta|nav|noframes|ol|optgroup|option|p|param|search|section|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul";
|
|
5289
|
+
var X = /<!--(?:-?>|[\s\S]*?(?:-->|$))/;
|
|
5290
|
+
var Ee = k("^ {0,3}(?:<(script|pre|style|textarea)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n*|$)|comment[^\\n]*(\\n+|$)|<\\?[\\s\\S]*?(?:\\?>[^\\n]*\\n*|$)|<![A-Z][\\s\\S]*?(?:>[^\\n]*\\n*|$)|<!\\[CDATA\\[[\\s\\S]*?(?:\\]\\]>[^\\n]*\\n*|$)|</?(tag)(?: +|\\n|/?>)[\\s\\S]*?(?:(?:\\n[ \t]*)+\\n|$)|<(?!script|pre|style|textarea)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ \t]*)+\\n|$)|</(?!script|pre|style|textarea)[a-z][\\w-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ \t]*)+\\n|$))", "i").replace("comment", X).replace("tag", Q).replace("attribute", / +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex();
|
|
5291
|
+
var le = (l) => k(K).replace("hr", q).replace("heading", " {0,3}#{1,6}(?:\\s|$)").replace("|lheading", "").replace("|table", "").replace("blockquote", " {0,3}>").replace("fences", " {0,3}(?:`{3,}(?=[^`\\n]*(?:\\n|$))|~~~)[^\\n]*(?:\\n|$)").replace("list", l).replace("html", "</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag", Q).getRegex();
|
|
5292
|
+
var ze = le(/ {0,3}(?:[*+-]|1[.)])[ \t]+[^ \t\n]/);
|
|
5293
|
+
var Me = le(/ {0,3}(?:[*+-]|\d{1,9}[.)])(?:[ \t]|\n|$)/);
|
|
5294
|
+
var Ae = k(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace("paragraph", Me).getRegex();
|
|
5295
|
+
var J = { blockquote: Ae, code: we, def: $e, fences: ye, heading: Pe, hr: q, html: Ee, lheading: ae, list: Le, newline: Te, paragraph: ze, table: z, text: _e };
|
|
5296
|
+
var se = k("^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)").replace("hr", q).replace("heading", " {0,3}#{1,6}(?:\\s|$)").replace("blockquote", " {0,3}>").replace("code", "(?: {4}| {0,3}\t)[^\\n]").replace("fences", " {0,3}(?:`{3,}(?=[^`\\n]*(?:\\n|$))|~~~)[^\\n]*(?:\\n|$)").replace("list", " {0,3}(?:[*+-]|1[.)])[ \\t]").replace("html", "</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag", Q).getRegex();
|
|
5297
|
+
var Ie = { ...J, lheading: Se, table: se, paragraph: k(K).replace("hr", q).replace("heading", " {0,3}#{1,6}(?:\\s|$)").replace("|lheading", "").replace("table", se).replace("blockquote", " {0,3}>").replace("fences", " {0,3}(?:`{3,}(?=[^`\\n]*(?:\\n|$))|~~~)[^\\n]*(?:\\n|$)").replace("list", " {0,3}(?:[*+-]|1[.)])[ \\t]+[^ \\t\\n]").replace("html", "</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag", Q).getRegex() };
|
|
5298
|
+
var Ce = { ...J, html: k(`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`).replace("comment", X).replace(/tag/g, "(?!(?:a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo|span|br|wbr|ins|del|img)\\b)\\w+(?!:|[^\\w\\s@]*@)\\b").getRegex(), def: /^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/, heading: /^(#{1,6})(.*)(?:\n+|$)/, fences: z, lheading: /^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/, paragraph: k(K).replace("hr", q).replace("heading", ` *#{1,6} *[^
|
|
5299
|
+
]`).replace("lheading", ae).replace("|table", "").replace("blockquote", " {0,3}>").replace("|fences", "").replace("|list", "").replace("|html", "").replace("|tag", "").getRegex() };
|
|
5300
|
+
var Be = /^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/;
|
|
5301
|
+
var De = /^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/;
|
|
5302
|
+
var ue = /^( {2,}|\\)\n(?!\s*$)/;
|
|
5303
|
+
var qe = /^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/;
|
|
5304
|
+
var _ = /[\p{P}\p{S}]/u;
|
|
5305
|
+
var C = /[\s\p{P}\p{S}]/u;
|
|
5306
|
+
var v = /[^\s\p{P}\p{S}]/u;
|
|
5307
|
+
var ve = k(/^((?![*_])punctSpace)/, "u").replace(/punctSpace/g, C).getRegex();
|
|
5308
|
+
var He = /[\p{Pi}\p{Ps}"']/u;
|
|
5309
|
+
var pe = /(?!~)[\p{P}\p{S}]/u;
|
|
5310
|
+
var Ze = /(?!~)[\s\p{P}\p{S}]/u;
|
|
5311
|
+
var Ge = /(?:[^\s\p{P}\p{S}]|~)/u;
|
|
5312
|
+
var Qe = k(/link|precode-code|html/, "g").replace("link", /\[(?:[^\[\]`]|(?<a>`+)[^`]+\k<a>(?!`))*?\]\((?:\\[\s\S]|[^\\\(\)]|\((?:\\[\s\S]|[^\\\(\)])*\))*\)/).replace("precode-", Oe ? "(?<!`)()" : "(^^|[^`])").replace("code", /(?<b>`+)[^`]+\k<b>(?!`)/).replace("html", /<(?! )[^<>]*?>/).getRegex();
|
|
5313
|
+
var ce = /^(?:\*+(?:((?!\*)punct)|([^\s*]))?)|^_+(?:((?!_)punct)|([^\s_]))?/;
|
|
5314
|
+
var Ne = k(ce, "u").replace(/punct/g, _).getRegex();
|
|
5315
|
+
var je = k(ce, "u").replace(/punct/g, pe).getRegex();
|
|
5316
|
+
var Fe = /^(?:\*+(?:((?!\*)(?!openQuote)punct)|([^\s*]))?)|^_+(?:((?!_)(?!openQuote)punct)|([^\s_]))?/;
|
|
5317
|
+
var Ue = k(Fe, "u").replace(/openQuote/g, He).replace(/punct/g, _).getRegex();
|
|
5318
|
+
var he = "^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)punctSpace(\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|notPunctSpace(\\*+)(?=notPunctSpace)";
|
|
5319
|
+
var Ke = k(he, "gu").replace(/notPunctSpace/g, v).replace(/punctSpace/g, C).replace(/punct/g, _).getRegex();
|
|
5320
|
+
var We = k(he, "gu").replace(/notPunctSpace/g, Ge).replace(/punctSpace/g, Ze).replace(/punct/g, pe).getRegex();
|
|
5321
|
+
var Xe = "^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)[\\s](\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|(?:(?!\\*)punct|notPunctSpace)(\\*+)(?!\\*)(?=notPunctSpace)";
|
|
5322
|
+
var Je = k(Xe, "gu").replace(/notPunctSpace/g, v).replace(/punctSpace/g, C).replace(/punct/g, _).getRegex();
|
|
5323
|
+
var Ve = k("^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)punctSpace(_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)", "gu").replace(/notPunctSpace/g, v).replace(/punctSpace/g, C).replace(/punct/g, _).getRegex();
|
|
5324
|
+
var Ye = "^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)[\\s](_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)|(?:(?!_)punct|notPunctSpace)(_+)(?!_)(?=notPunctSpace)";
|
|
5325
|
+
var et = k(Ye, "gu").replace(/notPunctSpace/g, v).replace(/punctSpace/g, C).replace(/punct/g, _).getRegex();
|
|
5326
|
+
var tt = k(/^~~?(?:((?!~)punct)|[^\s~])/, "u").replace(/punct/g, _).getRegex();
|
|
5327
|
+
var nt = "^[^~]+(?=[^~])|(?!~)punct(~~?)(?=[\\s]|$)|notPunctSpace(~~?)(?!~)(?=punctSpace|$)|(?!~)punctSpace(~~?)(?=notPunctSpace)|[\\s](~~?)(?!~)(?=punct)|(?!~)punct(~~?)(?!~)(?=punct)|notPunctSpace(~~?)(?=notPunctSpace)";
|
|
5328
|
+
var rt = k(nt, "gu").replace(/notPunctSpace/g, v).replace(/punctSpace/g, C).replace(/punct/g, _).getRegex();
|
|
5329
|
+
var st = k(/\\(punct)/, "gu").replace(/punct/g, _).getRegex();
|
|
5330
|
+
var it = k(/^<(scheme:[^\s\x00-\x1f<>]*|email)>/).replace("scheme", /[a-zA-Z][a-zA-Z0-9+.-]{1,31}/).replace("email", /[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+(@)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+(?![-_])/).getRegex();
|
|
5331
|
+
var ot = k(X).replace("(?:-->|$)", "-->").getRegex();
|
|
5332
|
+
var at = k("^comment|^</[a-zA-Z][\\w:-]*\\s*>|^<[a-zA-Z][\\w-]*(?:attribute)*?\\s*/?>|^<\\?[\\s\\S]*?\\?>|^<![a-zA-Z]+\\s[\\s\\S]*?>|^<!\\[CDATA\\[[\\s\\S]*?\\]\\]>").replace("comment", ot).replace("attribute", /\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex();
|
|
5333
|
+
var G = /(?:\[(?:\\[\s\S]|[^\[\]\\])*\]|\\[\s\S]|`+(?!`)[^`]*?`+(?!`)|``+(?=\])|[^\[\]\\`])*?/;
|
|
5334
|
+
var lt = k(/^!?\[(label)\]\(\s*(href)(?:(?:[ \t]+(?:\n[ \t]*)?|\n[ \t]*)(title))?\s*\)/).replace("label", G).replace("href", /<(?:\\.|[^\n<>\\])+>|[^ \t\n\x00-\x1f]+|(?=\))/).replace("title", /"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/).getRegex();
|
|
5335
|
+
var ke = k(/^!?\[(label)\]\[(ref)\]/).replace("label", G).replace("ref", W).getRegex();
|
|
5336
|
+
var de = k(/^!?\[(ref)\](?:\[\])?/).replace("ref", W).getRegex();
|
|
5337
|
+
var ut = k("reflink|nolink(?!\\()", "g").replace("reflink", ke).replace("nolink", de).getRegex();
|
|
5338
|
+
var ie = /[hH][tT][tT][pP][sS]?|[fF][tT][pP]/;
|
|
5339
|
+
var V = { _backpedal: z, anyPunctuation: st, autolink: it, blockSkip: Qe, br: ue, code: De, del: z, delLDelim: z, delRDelim: z, emStrongLDelim: Ne, emStrongRDelimAst: Ke, emStrongRDelimUnd: Ve, escape: Be, link: lt, nolink: de, punctuation: ve, reflink: ke, reflinkSearch: ut, tag: at, text: qe, url: z };
|
|
5340
|
+
var pt = { ...V, emStrongLDelim: Ue, emStrongRDelimAst: Je, emStrongRDelimUnd: et, link: k(/^!?\[(label)\]\((.*?)\)/).replace("label", G).getRegex(), reflink: k(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label", G).getRegex() };
|
|
5341
|
+
var F = { ...V, emStrongRDelimAst: We, emStrongLDelim: je, delLDelim: tt, delRDelim: rt, url: k(/^((?:protocol):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/).replace("protocol", ie).replace("email", /[A-Za-z0-9._+-]+(@)[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![-_])/).getRegex(), _backpedal: /(?:[^?!.,:;*_'"~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_'"~)]+(?!$))+/, del: /^(~~?)(?=[^\s~])((?:\\[\s\S]|[^\\])*?(?:\\[\s\S]|[^\s~\\]))\1(?=[^~]|$)/, text: k(/^(`+|~+|[^`~])(?:(?=[`~])|(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|protocol:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)))/).replace("protocol", ie).getRegex() };
|
|
5342
|
+
var ct = { ...F, br: k(ue).replace("{2,}", "*").getRegex(), text: k(F.text).replace("\\b_", "\\b_| {2,}\\n").replace(/\{2,\}/g, "*").getRegex() };
|
|
5343
|
+
var H = { normal: J, gfm: Ie, pedantic: Ce };
|
|
5344
|
+
var B = { normal: V, gfm: F, breaks: ct, pedantic: pt };
|
|
5345
|
+
var ht = { "&": "&", "<": "<", ">": ">", '"': """, "'": "'" };
|
|
5346
|
+
var ge = (l) => ht[l];
|
|
5347
|
+
function T(l, e) {
|
|
5348
|
+
if (e) {
|
|
5349
|
+
if (m.escapeTest.test(l))
|
|
5350
|
+
return l.replace(m.escapeReplace, ge);
|
|
5351
|
+
} else if (m.escapeTestNoEncode.test(l))
|
|
5352
|
+
return l.replace(m.escapeReplaceNoEncode, ge);
|
|
5353
|
+
return l;
|
|
5354
|
+
}
|
|
5355
|
+
function Y(l) {
|
|
5356
|
+
try {
|
|
5357
|
+
l = encodeURI(l).replace(m.percentDecode, "%");
|
|
5358
|
+
} catch {
|
|
5359
|
+
return null;
|
|
5360
|
+
}
|
|
5361
|
+
return l;
|
|
5362
|
+
}
|
|
5363
|
+
function ee(l, e) {
|
|
5364
|
+
let t = l.replace(m.findPipe, (r, i, o) => {
|
|
5365
|
+
let u = false, a = i;
|
|
5366
|
+
for (;--a >= 0 && o[a] === "\\"; )
|
|
5367
|
+
u = !u;
|
|
5368
|
+
return u ? "|" : " |";
|
|
5369
|
+
}), n = t.split(m.splitPipe), s = 0;
|
|
5370
|
+
if (n[0].trim() || n.shift(), n.length > 0 && !n.at(-1)?.trim() && n.pop(), e)
|
|
5371
|
+
if (n.length > e)
|
|
5372
|
+
n.splice(e);
|
|
5373
|
+
else
|
|
5374
|
+
for (;n.length < e; )
|
|
5375
|
+
n.push("");
|
|
5376
|
+
for (;s < n.length; s++)
|
|
5377
|
+
n[s] = n[s].trim().replace(m.slashPipe, "|");
|
|
5378
|
+
return n;
|
|
5379
|
+
}
|
|
5380
|
+
function $(l, e, t) {
|
|
5381
|
+
let n = l.length;
|
|
5382
|
+
if (n === 0)
|
|
5383
|
+
return "";
|
|
5384
|
+
let s = 0;
|
|
5385
|
+
for (;s < n; ) {
|
|
5386
|
+
let r = l.charAt(n - s - 1);
|
|
5387
|
+
if (r === e && !t)
|
|
5388
|
+
s++;
|
|
5389
|
+
else if (r !== e && t)
|
|
5390
|
+
s++;
|
|
5391
|
+
else
|
|
5392
|
+
break;
|
|
5393
|
+
}
|
|
5394
|
+
return l.slice(0, n - s);
|
|
5395
|
+
}
|
|
5396
|
+
function te(l) {
|
|
5397
|
+
let e = l.split(`
|
|
5398
|
+
`), t = e.length - 1;
|
|
5399
|
+
for (;t >= 0 && m.blankLine.test(e[t]); )
|
|
5400
|
+
t--;
|
|
5401
|
+
return e.length - t <= 2 ? l : e.slice(0, t + 1).join(`
|
|
5402
|
+
`);
|
|
5403
|
+
}
|
|
5404
|
+
function fe(l, e) {
|
|
5405
|
+
if (l.indexOf(e[1]) === -1)
|
|
5406
|
+
return -1;
|
|
5407
|
+
let t = 0;
|
|
5408
|
+
for (let n = 0;n < l.length; n++)
|
|
5409
|
+
if (l[n] === "\\")
|
|
5410
|
+
n++;
|
|
5411
|
+
else if (l[n] === e[0])
|
|
5412
|
+
t++;
|
|
5413
|
+
else if (l[n] === e[1] && (t--, t < 0))
|
|
5414
|
+
return n;
|
|
5415
|
+
return t > 0 ? -2 : -1;
|
|
5416
|
+
}
|
|
5417
|
+
function me(l, e = 0) {
|
|
5418
|
+
let t = e, n = "";
|
|
5419
|
+
for (let s of l)
|
|
5420
|
+
if (s === "\t") {
|
|
5421
|
+
let r = 4 - t % 4;
|
|
5422
|
+
n += " ".repeat(r), t += r;
|
|
5423
|
+
} else
|
|
5424
|
+
n += s, t++;
|
|
5425
|
+
return n;
|
|
5426
|
+
}
|
|
5427
|
+
function xe(l, e, t, n, s) {
|
|
5428
|
+
let r = e.href, i = e.title || null, o = l[1].replace(s.other.outputLinkReplace, "$1"), u = l[0].charAt(0) === "!";
|
|
5429
|
+
n.state.inLink = true;
|
|
5430
|
+
let a = n.state.linkEmitted, p = n.state.inRawBlock;
|
|
5431
|
+
n.state.linkEmitted = false;
|
|
5432
|
+
let c = n.inlineTokens(o), h = n.state.linkEmitted;
|
|
5433
|
+
if (n.state.linkEmitted = a, n.state.inLink = false, !u) {
|
|
5434
|
+
if (h) {
|
|
5435
|
+
n.state.inRawBlock = p;
|
|
5436
|
+
return;
|
|
5437
|
+
}
|
|
5438
|
+
n.state.linkEmitted = true;
|
|
5439
|
+
}
|
|
5440
|
+
return { type: u ? "image" : "link", raw: t, href: r, title: i, text: o, tokens: c };
|
|
5441
|
+
}
|
|
5442
|
+
function kt(l, e, t) {
|
|
5443
|
+
let n = l.match(t.other.indentCodeCompensation);
|
|
5444
|
+
if (n === null)
|
|
5445
|
+
return e;
|
|
5446
|
+
let s = n[1];
|
|
5447
|
+
return e.split(`
|
|
5448
|
+
`).map((r) => {
|
|
5449
|
+
let i = r.match(t.other.beginningSpace);
|
|
5450
|
+
if (i === null)
|
|
5451
|
+
return r;
|
|
5452
|
+
let [o] = i;
|
|
5453
|
+
return o.length >= s.length ? r.slice(s.length) : r;
|
|
5454
|
+
}).join(`
|
|
5455
|
+
`);
|
|
5456
|
+
}
|
|
5457
|
+
var y = class {
|
|
5458
|
+
options;
|
|
5459
|
+
rules;
|
|
5460
|
+
lexer;
|
|
5461
|
+
constructor(e) {
|
|
5462
|
+
this.options = e || R;
|
|
5463
|
+
}
|
|
5464
|
+
space(e) {
|
|
5465
|
+
let t = this.rules.block.newline.exec(e);
|
|
5466
|
+
if (t && t[0].length > 0)
|
|
5467
|
+
return { type: "space", raw: t[0] };
|
|
5468
|
+
}
|
|
5469
|
+
code(e) {
|
|
5470
|
+
let t = this.rules.block.code.exec(e);
|
|
5471
|
+
if (t) {
|
|
5472
|
+
let n = this.options.pedantic ? t[0] : te(t[0]), s = n.replace(this.rules.other.codeRemoveIndent, "");
|
|
5473
|
+
return { type: "code", raw: n, codeBlockStyle: "indented", text: s };
|
|
5474
|
+
}
|
|
5475
|
+
}
|
|
5476
|
+
fences(e) {
|
|
5477
|
+
let t = this.rules.block.fences.exec(e);
|
|
5478
|
+
if (t) {
|
|
5479
|
+
let n = t[0], s = kt(n, t[3] || "", this.rules);
|
|
5480
|
+
return { type: "code", raw: n, lang: t[2] ? t[2].trim().replace(this.rules.inline.anyPunctuation, "$1") : t[2], text: s };
|
|
5481
|
+
}
|
|
5482
|
+
}
|
|
5483
|
+
heading(e) {
|
|
5484
|
+
let t = this.rules.block.heading.exec(e);
|
|
5485
|
+
if (t) {
|
|
5486
|
+
let n = t[2].trim();
|
|
5487
|
+
if (this.rules.other.endingHash.test(n)) {
|
|
5488
|
+
let s = $(n, "#");
|
|
5489
|
+
(this.options.pedantic || !s || this.rules.other.endingSpaceChar.test(s)) && (n = s.trim());
|
|
5490
|
+
}
|
|
5491
|
+
return { type: "heading", raw: $(t[0], `
|
|
5492
|
+
`), depth: t[1].length, text: n, tokens: this.lexer.inline(n) };
|
|
5493
|
+
}
|
|
5494
|
+
}
|
|
5495
|
+
hr(e) {
|
|
5496
|
+
let t = this.rules.block.hr.exec(e);
|
|
5497
|
+
if (t)
|
|
5498
|
+
return { type: "hr", raw: $(t[0], `
|
|
5499
|
+
`) };
|
|
5500
|
+
}
|
|
5501
|
+
blockquote(e) {
|
|
5502
|
+
let t = this.rules.block.blockquote.exec(e);
|
|
5503
|
+
if (t) {
|
|
5504
|
+
let n = $(t[0], `
|
|
5505
|
+
`).split(`
|
|
5506
|
+
`), s = "", r = "", i = [];
|
|
5507
|
+
for (;n.length > 0; ) {
|
|
5508
|
+
let o = false, u = [], a;
|
|
5509
|
+
for (a = 0;a < n.length; a++)
|
|
5510
|
+
if (this.rules.other.blockquoteStart.test(n[a]))
|
|
5511
|
+
u.push(n[a]), o = true;
|
|
5512
|
+
else if (!o)
|
|
5513
|
+
u.push(n[a]);
|
|
5514
|
+
else
|
|
5515
|
+
break;
|
|
5516
|
+
n = n.slice(a);
|
|
5517
|
+
let p = u.join(`
|
|
5518
|
+
`), c = p.replace(this.rules.other.blockquoteSetextReplace, `
|
|
5519
|
+
$1`).replace(this.rules.other.blockquoteSetextReplace2, "");
|
|
5520
|
+
s = s ? `${s}
|
|
5521
|
+
${p}` : p, r = r ? `${r}
|
|
5522
|
+
${c}` : c;
|
|
5523
|
+
let h = this.lexer.state.top;
|
|
5524
|
+
if (this.lexer.state.top = true, this.lexer.blockTokens(c, i, true), this.lexer.state.top = h, n.length === 0)
|
|
5525
|
+
break;
|
|
5526
|
+
let d = i.at(-1);
|
|
5527
|
+
if (d?.type === "code")
|
|
5528
|
+
break;
|
|
5529
|
+
if (d?.type === "blockquote") {
|
|
5530
|
+
let O = d, g = n.join(`
|
|
5531
|
+
`), w = O.raw + `
|
|
5532
|
+
` + g.replace(this.rules.other.blockquoteSetextReplace2, ""), E = this.blockquote(w);
|
|
5533
|
+
i[i.length - 1] = E, s = `${s}
|
|
5534
|
+
${g}`, r = r.substring(0, r.length - O.text.length) + E.text;
|
|
5535
|
+
break;
|
|
5536
|
+
} else if (d?.type === "list") {
|
|
5537
|
+
let O = d, g = O.raw + `
|
|
5538
|
+
` + n.join(`
|
|
5539
|
+
`), w = this.list(g);
|
|
5540
|
+
i[i.length - 1] = w, s = s.substring(0, s.length - d.raw.length) + w.raw, r = r.substring(0, r.length - O.raw.length) + w.raw, n = g.substring(i.at(-1).raw.length).split(`
|
|
5541
|
+
`);
|
|
5542
|
+
continue;
|
|
5543
|
+
}
|
|
5544
|
+
}
|
|
5545
|
+
return { type: "blockquote", raw: s, tokens: i, text: r };
|
|
5546
|
+
}
|
|
5547
|
+
}
|
|
5548
|
+
list(e) {
|
|
5549
|
+
let t = this.rules.block.list.exec(e);
|
|
5550
|
+
if (t) {
|
|
5551
|
+
let n = t[1].trim(), s = n.length > 1, r = { type: "list", raw: "", ordered: s, start: s ? +n.slice(0, -1) : "", loose: false, items: [] };
|
|
5552
|
+
n = s ? `\\d{1,9}\\${n.slice(-1)}` : `\\${n}`, this.options.pedantic && (n = s ? n : "[*+-]");
|
|
5553
|
+
let i = this.rules.other.listItemRegex(n), o = false;
|
|
5554
|
+
for (;e; ) {
|
|
5555
|
+
let a = false, p = "", c = "";
|
|
5556
|
+
if (!(t = i.exec(e)) || this.rules.block.hr.test(e))
|
|
5557
|
+
break;
|
|
5558
|
+
p = t[0], e = e.substring(p.length);
|
|
5559
|
+
let h = me(t[2].split(`
|
|
5560
|
+
`, 1)[0], t[1].length), d = e.split(`
|
|
5561
|
+
`, 1)[0], O = !h.trim(), g = 0;
|
|
5562
|
+
if (this.options.pedantic ? (g = 2, c = h.trimStart()) : O ? g = t[1].length + 1 : (g = h.search(this.rules.other.nonSpaceChar), g = g > 4 ? 1 : g, c = h.slice(g), g += t[1].length), O && this.rules.other.blankLine.test(d) && (p += d + `
|
|
5563
|
+
`, e = e.substring(d.length + 1), a = true), !a) {
|
|
5564
|
+
let w = this.rules.other.nextBulletRegex(g), E = this.rules.other.hrRegex(g), ne = this.rules.other.fencesBeginRegex(g), re = this.rules.other.headingBeginRegex(g), be = this.rules.other.htmlBeginRegex(g), Re = this.rules.other.blockquoteBeginRegex(g);
|
|
5565
|
+
for (;e; ) {
|
|
5566
|
+
let N = e.split(`
|
|
5567
|
+
`, 1)[0], D;
|
|
5568
|
+
if (d = N, this.options.pedantic ? (d = d.replace(this.rules.other.listReplaceNesting, " "), D = d) : D = d.replace(this.rules.other.tabCharGlobal, " "), ne.test(d) || re.test(d) || be.test(d) || Re.test(d) || w.test(d) || E.test(d))
|
|
5569
|
+
break;
|
|
5570
|
+
if (D.search(this.rules.other.nonSpaceChar) >= g || !d.trim())
|
|
5571
|
+
c += `
|
|
5572
|
+
` + D.slice(g);
|
|
5573
|
+
else {
|
|
5574
|
+
if (O || h.replace(this.rules.other.tabCharGlobal, " ").search(this.rules.other.nonSpaceChar) >= 4 || ne.test(h) || re.test(h) || E.test(h))
|
|
5575
|
+
break;
|
|
5576
|
+
c += `
|
|
5577
|
+
` + d;
|
|
5578
|
+
}
|
|
5579
|
+
O = !d.trim(), p += N + `
|
|
5580
|
+
`, e = e.substring(N.length + 1), h = D.slice(g);
|
|
5581
|
+
}
|
|
5582
|
+
}
|
|
5583
|
+
r.loose || (o ? r.loose = true : this.rules.other.doubleBlankLine.test(p) && (o = true)), r.items.push({ type: "list_item", raw: p, task: !!this.options.gfm && this.rules.other.listIsTask.test(c), loose: false, text: c, tokens: [] }), r.raw += p;
|
|
5584
|
+
}
|
|
5585
|
+
let u = r.items.at(-1);
|
|
5586
|
+
if (u)
|
|
5587
|
+
u.raw = u.raw.trimEnd(), u.text = u.text.trimEnd();
|
|
5588
|
+
else
|
|
5589
|
+
return;
|
|
5590
|
+
r.raw = r.raw.trimEnd();
|
|
5591
|
+
for (let a of r.items)
|
|
5592
|
+
if (this.lexer.state.top = false, a.tokens = this.lexer.blockTokens(a.text, []), !r.loose) {
|
|
5593
|
+
let p = a.tokens.filter((h) => h.type === "space"), c = p.length > 0 && p.some((h) => this.rules.other.anyLine.test(h.raw));
|
|
5594
|
+
r.loose = c;
|
|
5595
|
+
}
|
|
5596
|
+
for (let a of r.items) {
|
|
5597
|
+
let p = a.tokens[0];
|
|
5598
|
+
if (a.task && (p?.type === "text" || p?.type === "paragraph")) {
|
|
5599
|
+
a.text = a.text.replace(this.rules.other.listReplaceTask, ""), p.raw = p.raw.replace(this.rules.other.listReplaceTask, ""), p.text = p.text.replace(this.rules.other.listReplaceTask, "");
|
|
5600
|
+
for (let h = this.lexer.inlineQueue.length - 1;h >= 0; h--)
|
|
5601
|
+
if (this.rules.other.listIsTask.test(this.lexer.inlineQueue[h].src)) {
|
|
5602
|
+
this.lexer.inlineQueue[h].src = this.lexer.inlineQueue[h].src.replace(this.rules.other.listReplaceTask, "");
|
|
5603
|
+
break;
|
|
5604
|
+
}
|
|
5605
|
+
let c = this.rules.other.listTaskCheckbox.exec(a.raw);
|
|
5606
|
+
if (c) {
|
|
5607
|
+
let h = { type: "checkbox", raw: c[0] + " ", checked: c[0] !== "[ ]" };
|
|
5608
|
+
a.checked = h.checked, r.loose ? a.tokens[0] && ["paragraph", "text"].includes(a.tokens[0].type) && "tokens" in a.tokens[0] && a.tokens[0].tokens ? (a.tokens[0].raw = h.raw + a.tokens[0].raw, a.tokens[0].text = h.raw + a.tokens[0].text, a.tokens[0].tokens.unshift(h)) : a.tokens.unshift({ type: "paragraph", raw: h.raw, text: h.raw, tokens: [h] }) : a.tokens.unshift(h);
|
|
5609
|
+
}
|
|
5610
|
+
} else
|
|
5611
|
+
a.task && (a.task = false);
|
|
5612
|
+
}
|
|
5613
|
+
if (r.loose)
|
|
5614
|
+
for (let a of r.items) {
|
|
5615
|
+
a.loose = true;
|
|
5616
|
+
for (let p of a.tokens)
|
|
5617
|
+
p.type === "text" && (p.type = "paragraph");
|
|
5618
|
+
}
|
|
5619
|
+
return r;
|
|
5620
|
+
}
|
|
5621
|
+
}
|
|
5622
|
+
html(e) {
|
|
5623
|
+
let t = this.rules.block.html.exec(e);
|
|
5624
|
+
if (t) {
|
|
5625
|
+
let n = te(t[0]);
|
|
5626
|
+
return { type: "html", block: true, raw: n, pre: t[1] === "pre" || t[1] === "script" || t[1] === "style", text: n };
|
|
5627
|
+
}
|
|
5628
|
+
}
|
|
5629
|
+
def(e) {
|
|
5630
|
+
let t = this.rules.block.def.exec(e);
|
|
5631
|
+
if (t) {
|
|
5632
|
+
let n = t[1].toLowerCase().replace(this.rules.other.multipleSpaceGlobal, " "), s = t[2] ? t[2].replace(this.rules.other.hrefBrackets, "$1").replace(this.rules.inline.anyPunctuation, "$1") : "", r = t[3] ? t[3].substring(1, t[3].length - 1).replace(this.rules.inline.anyPunctuation, "$1") : t[3];
|
|
5633
|
+
return { type: "def", tag: n, raw: $(t[0], `
|
|
5634
|
+
`), href: s, title: r };
|
|
5635
|
+
}
|
|
5636
|
+
}
|
|
5637
|
+
table(e) {
|
|
5638
|
+
let t = this.rules.block.table.exec(e);
|
|
5639
|
+
if (!t || !this.rules.other.tableDelimiter.test(t[2]))
|
|
5640
|
+
return;
|
|
5641
|
+
let n = ee(t[1]), s = t[2].replace(this.rules.other.tableAlignChars, "").split("|"), r = t[3]?.trim() ? t[3].replace(this.rules.other.tableRowBlankLine, "").split(`
|
|
5642
|
+
`) : [], i = { type: "table", raw: $(t[0], `
|
|
5643
|
+
`), header: [], align: [], rows: [] };
|
|
5644
|
+
if (n.length === s.length) {
|
|
5645
|
+
for (let o of s)
|
|
5646
|
+
this.rules.other.tableAlignRight.test(o) ? i.align.push("right") : this.rules.other.tableAlignCenter.test(o) ? i.align.push("center") : this.rules.other.tableAlignLeft.test(o) ? i.align.push("left") : i.align.push(null);
|
|
5647
|
+
for (let o = 0;o < n.length; o++)
|
|
5648
|
+
i.header.push({ text: n[o], tokens: this.lexer.inline(n[o]), header: true, align: i.align[o] });
|
|
5649
|
+
for (let o of r)
|
|
5650
|
+
i.rows.push(ee(o, i.header.length).map((u, a) => ({ text: u, tokens: this.lexer.inline(u), header: false, align: i.align[a] })));
|
|
5651
|
+
return i;
|
|
5652
|
+
}
|
|
5653
|
+
}
|
|
5654
|
+
lheading(e) {
|
|
5655
|
+
let t = this.rules.block.lheading.exec(e);
|
|
5656
|
+
if (t) {
|
|
5657
|
+
let n = t[1].trim();
|
|
5658
|
+
return { type: "heading", raw: $(t[0], `
|
|
5659
|
+
`), depth: t[2].charAt(0) === "=" ? 1 : 2, text: n, tokens: this.lexer.inline(n) };
|
|
5660
|
+
}
|
|
5661
|
+
}
|
|
5662
|
+
paragraph(e) {
|
|
5663
|
+
let t = this.rules.block.paragraph.exec(e);
|
|
5664
|
+
if (t) {
|
|
5665
|
+
let n = t[1].charAt(t[1].length - 1) === `
|
|
5666
|
+
` ? t[1].slice(0, -1) : t[1];
|
|
5667
|
+
return { type: "paragraph", raw: t[0], text: n, tokens: this.lexer.inline(n) };
|
|
5668
|
+
}
|
|
5669
|
+
}
|
|
5670
|
+
text(e) {
|
|
5671
|
+
let t = this.rules.block.text.exec(e);
|
|
5672
|
+
if (t)
|
|
5673
|
+
return { type: "text", raw: t[0], text: t[0], tokens: this.lexer.inline(t[0]) };
|
|
5674
|
+
}
|
|
5675
|
+
escape(e) {
|
|
5676
|
+
let t = this.rules.inline.escape.exec(e);
|
|
5677
|
+
if (t)
|
|
5678
|
+
return { type: "escape", raw: t[0], text: t[1] };
|
|
5679
|
+
}
|
|
5680
|
+
tag(e) {
|
|
5681
|
+
let t = this.rules.inline.tag.exec(e);
|
|
5682
|
+
if (t)
|
|
5683
|
+
return !this.lexer.state.inLink && this.rules.other.startATag.test(t[0]) ? this.lexer.state.inLink = true : this.lexer.state.inLink && this.rules.other.endATag.test(t[0]) && (this.lexer.state.inLink = false), !this.lexer.state.inRawBlock && this.rules.other.startPreScriptTag.test(t[0]) ? this.lexer.state.inRawBlock = true : this.lexer.state.inRawBlock && this.rules.other.endPreScriptTag.test(t[0]) && (this.lexer.state.inRawBlock = false), { type: "html", raw: t[0], inLink: this.lexer.state.inLink, inRawBlock: this.lexer.state.inRawBlock, block: false, text: t[0] };
|
|
5684
|
+
}
|
|
5685
|
+
link(e) {
|
|
5686
|
+
let t = this.rules.inline.link.exec(e);
|
|
5687
|
+
if (t) {
|
|
5688
|
+
let n = t[2].trim();
|
|
5689
|
+
if (!this.options.pedantic && this.rules.other.startAngleBracket.test(n)) {
|
|
5690
|
+
if (!this.rules.other.endAngleBracket.test(n))
|
|
5691
|
+
return;
|
|
5692
|
+
let i = $(n.slice(0, -1), "\\");
|
|
5693
|
+
if ((n.length - i.length) % 2 === 0)
|
|
5694
|
+
return;
|
|
5695
|
+
} else {
|
|
5696
|
+
let i = fe(t[2], "()");
|
|
5697
|
+
if (i === -2)
|
|
5698
|
+
return;
|
|
5699
|
+
if (i > -1) {
|
|
5700
|
+
let u = (t[0].indexOf("!") === 0 ? 5 : 4) + t[1].length + i;
|
|
5701
|
+
t[2] = t[2].substring(0, i), t[0] = t[0].substring(0, u).trim(), t[3] = "";
|
|
5702
|
+
}
|
|
5703
|
+
}
|
|
5704
|
+
let s = t[2], r = "";
|
|
5705
|
+
if (this.options.pedantic) {
|
|
5706
|
+
let i = this.rules.other.pedanticHrefTitle.exec(s);
|
|
5707
|
+
i && (s = i[1], r = i[3]);
|
|
5708
|
+
} else
|
|
5709
|
+
r = t[3] ? t[3].slice(1, -1) : "";
|
|
5710
|
+
return s = s.trim(), this.rules.other.startAngleBracket.test(s) && (this.options.pedantic && !this.rules.other.endAngleBracket.test(n) ? s = s.slice(1) : s = s.slice(1, -1)), xe(t, { href: s && s.replace(this.rules.inline.anyPunctuation, "$1"), title: r && r.replace(this.rules.inline.anyPunctuation, "$1") }, t[0], this.lexer, this.rules);
|
|
5711
|
+
}
|
|
5712
|
+
}
|
|
5713
|
+
reflink(e, t) {
|
|
5714
|
+
let n;
|
|
5715
|
+
if ((n = this.rules.inline.reflink.exec(e)) || (n = this.rules.inline.nolink.exec(e))) {
|
|
5716
|
+
let s = (n[2] || n[1]).replace(this.rules.other.multipleSpaceGlobal, " "), r = t[s.toLowerCase()];
|
|
5717
|
+
if (!r) {
|
|
5718
|
+
let i = n[0].charAt(0);
|
|
5719
|
+
return { type: "text", raw: i, text: i };
|
|
5720
|
+
}
|
|
5721
|
+
return xe(n, r, n[0], this.lexer, this.rules);
|
|
5722
|
+
}
|
|
5723
|
+
}
|
|
5724
|
+
emStrong(e, t, n = "") {
|
|
5725
|
+
let s = this.rules.inline.emStrongLDelim.exec(e);
|
|
5726
|
+
if (!s || !s[1] && !s[2] && !s[3] && !s[4] || s[4] && n.match(this.rules.other.unicodeAlphaNumeric))
|
|
5727
|
+
return;
|
|
5728
|
+
if (!(s[1] || s[3] || "") || !n || this.rules.inline.punctuation.exec(n)) {
|
|
5729
|
+
let i = [...s[0]].length - 1, o, u, a = i, p = 0, c = s[0][0], h = n === c, d = c === "*" ? this.rules.inline.emStrongRDelimAst : this.rules.inline.emStrongRDelimUnd;
|
|
5730
|
+
for (d.lastIndex = 0, t = t.slice(-1 * e.length + i);(s = d.exec(t)) !== null; ) {
|
|
5731
|
+
if (o = s[1] || s[2] || s[3] || s[4] || s[5] || s[6], !o)
|
|
5732
|
+
continue;
|
|
5733
|
+
if (u = [...o].length, s[3] || s[4]) {
|
|
5734
|
+
a += u;
|
|
5735
|
+
continue;
|
|
5736
|
+
} else if (s[5] || s[6]) {
|
|
5737
|
+
if (i % 3 && !((i + u) % 3)) {
|
|
5738
|
+
p += u;
|
|
5739
|
+
continue;
|
|
5740
|
+
}
|
|
5741
|
+
if (h)
|
|
5742
|
+
break;
|
|
5743
|
+
}
|
|
5744
|
+
if (a -= u, a > 0)
|
|
5745
|
+
continue;
|
|
5746
|
+
u = Math.min(u, u + a + p);
|
|
5747
|
+
let O = [...s[0]][0].length, g = e.slice(0, i + s.index + O + u);
|
|
5748
|
+
if (Math.min(i, u) % 2) {
|
|
5749
|
+
let E = g.slice(1, -1);
|
|
5750
|
+
return { type: "em", raw: g, text: E, tokens: this.lexer.inlineTokens(E) };
|
|
5751
|
+
}
|
|
5752
|
+
let w = g.slice(2, -2);
|
|
5753
|
+
return { type: "strong", raw: g, text: w, tokens: this.lexer.inlineTokens(w) };
|
|
5754
|
+
}
|
|
5755
|
+
}
|
|
5756
|
+
}
|
|
5757
|
+
codespan(e) {
|
|
5758
|
+
let t = this.rules.inline.code.exec(e);
|
|
5759
|
+
if (t) {
|
|
5760
|
+
let n = t[2].replace(this.rules.other.newLineCharGlobal, " "), s = this.rules.other.nonSpaceChar.test(n), r = this.rules.other.startingSpaceChar.test(n) && this.rules.other.endingSpaceChar.test(n);
|
|
5761
|
+
return s && r && (n = n.substring(1, n.length - 1)), { type: "codespan", raw: t[0], text: n };
|
|
5762
|
+
}
|
|
5763
|
+
}
|
|
5764
|
+
br(e) {
|
|
5765
|
+
let t = this.rules.inline.br.exec(e);
|
|
5766
|
+
if (t)
|
|
5767
|
+
return { type: "br", raw: t[0] };
|
|
5768
|
+
}
|
|
5769
|
+
del(e, t, n = "") {
|
|
5770
|
+
let s = this.rules.inline.delLDelim.exec(e);
|
|
5771
|
+
if (!s)
|
|
5772
|
+
return;
|
|
5773
|
+
if (!(s[1] || "") || !n || this.rules.inline.punctuation.exec(n)) {
|
|
5774
|
+
let i = [...s[0]].length - 1, o, u, a = i, p = this.rules.inline.delRDelim;
|
|
5775
|
+
for (p.lastIndex = 0, t = t.slice(-1 * e.length + i);(s = p.exec(t)) !== null; ) {
|
|
5776
|
+
if (o = s[1] || s[2] || s[3] || s[4] || s[5] || s[6], !o || (u = [...o].length, u !== i))
|
|
5777
|
+
continue;
|
|
5778
|
+
if (s[3] || s[4]) {
|
|
5779
|
+
a += u;
|
|
5780
|
+
continue;
|
|
5781
|
+
}
|
|
5782
|
+
if (a -= u, a > 0)
|
|
5783
|
+
continue;
|
|
5784
|
+
u = Math.min(u, u + a);
|
|
5785
|
+
let c = [...s[0]][0].length, h = e.slice(0, i + s.index + c + u), d = h.slice(i, -i);
|
|
5786
|
+
return { type: "del", raw: h, text: d, tokens: this.lexer.inlineTokens(d) };
|
|
5787
|
+
}
|
|
5788
|
+
}
|
|
5789
|
+
}
|
|
5790
|
+
autolink(e) {
|
|
5791
|
+
let t = this.rules.inline.autolink.exec(e);
|
|
5792
|
+
if (t) {
|
|
5793
|
+
let n, s;
|
|
5794
|
+
return t[2] === "@" ? (n = t[1], s = "mailto:" + n) : (n = t[1], s = n), { type: "link", raw: t[0], text: n, href: s, tokens: [{ type: "text", raw: n, text: n }] };
|
|
5795
|
+
}
|
|
5796
|
+
}
|
|
5797
|
+
url(e) {
|
|
5798
|
+
let t;
|
|
5799
|
+
if (t = this.rules.inline.url.exec(e)) {
|
|
5800
|
+
let n, s;
|
|
5801
|
+
if (t[2] === "@")
|
|
5802
|
+
n = t[0], s = "mailto:" + n;
|
|
5803
|
+
else {
|
|
5804
|
+
let r;
|
|
5805
|
+
do
|
|
5806
|
+
r = t[0], t[0] = this.rules.inline._backpedal.exec(t[0])?.[0] ?? "";
|
|
5807
|
+
while (r !== t[0]);
|
|
5808
|
+
n = t[0], t[1] === "www." ? s = "http://" + t[0] : s = t[0];
|
|
5809
|
+
}
|
|
5810
|
+
return { type: "link", raw: t[0], text: n, href: s, tokens: [{ type: "text", raw: n, text: n }] };
|
|
5811
|
+
}
|
|
5812
|
+
}
|
|
5813
|
+
inlineText(e) {
|
|
5814
|
+
let t = this.rules.inline.text.exec(e);
|
|
5815
|
+
if (t) {
|
|
5816
|
+
let n = this.lexer.state.inRawBlock;
|
|
5817
|
+
return { type: "text", raw: t[0], text: t[0], escaped: n };
|
|
5818
|
+
}
|
|
5819
|
+
}
|
|
5820
|
+
};
|
|
5821
|
+
var x = class l {
|
|
5822
|
+
tokens;
|
|
5823
|
+
options;
|
|
5824
|
+
state;
|
|
5825
|
+
inlineQueue;
|
|
5826
|
+
tokenizer;
|
|
5827
|
+
constructor(e) {
|
|
5828
|
+
this.tokens = [], this.tokens.links = Object.create(null), this.options = e || R, this.options.tokenizer = this.options.tokenizer || new y, this.tokenizer = this.options.tokenizer, this.tokenizer.options = this.options, this.tokenizer.lexer = this, this.inlineQueue = [], this.state = { inLink: false, inRawBlock: false, linkEmitted: false, top: true };
|
|
5829
|
+
let t = { other: m, block: H.normal, inline: B.normal };
|
|
5830
|
+
this.options.pedantic ? (t.block = H.pedantic, t.inline = B.pedantic) : this.options.gfm && (t.block = H.gfm, this.options.breaks ? t.inline = B.breaks : t.inline = B.gfm), this.tokenizer.rules = t;
|
|
5831
|
+
}
|
|
5832
|
+
static get rules() {
|
|
5833
|
+
return { block: H, inline: B };
|
|
5834
|
+
}
|
|
5835
|
+
static lex(e, t) {
|
|
5836
|
+
return new l(t).lex(e);
|
|
5837
|
+
}
|
|
5838
|
+
static lexInline(e, t) {
|
|
5839
|
+
return new l(t).inlineTokens(e);
|
|
5840
|
+
}
|
|
5841
|
+
lex(e) {
|
|
5842
|
+
e = e.replace(m.carriageReturn, `
|
|
5843
|
+
`), this.blockTokens(e, this.tokens);
|
|
5844
|
+
for (let t = 0;t < this.inlineQueue.length; t++) {
|
|
5845
|
+
let n = this.inlineQueue[t];
|
|
5846
|
+
this.inlineTokens(n.src, n.tokens);
|
|
5847
|
+
}
|
|
5848
|
+
return this.inlineQueue = [], this.tokens;
|
|
5849
|
+
}
|
|
5850
|
+
blockTokens(e, t = [], n = false) {
|
|
5851
|
+
this.tokenizer.lexer = this, this.options.pedantic && (e = e.replace(m.tabCharGlobal, " ").replace(m.spaceLine, ""));
|
|
5852
|
+
let s = 1 / 0;
|
|
5853
|
+
for (;e; ) {
|
|
5854
|
+
if (e.length < s)
|
|
5855
|
+
s = e.length;
|
|
5856
|
+
else {
|
|
5857
|
+
this.infiniteLoopError(e.charCodeAt(0));
|
|
5858
|
+
break;
|
|
5859
|
+
}
|
|
5860
|
+
let r;
|
|
5861
|
+
if (this.options.extensions?.block?.some((o) => (r = o.call({ lexer: this }, e, t)) ? (e = e.substring(r.raw.length), t.push(r), true) : false))
|
|
5862
|
+
continue;
|
|
5863
|
+
if (r = this.tokenizer.space(e)) {
|
|
5864
|
+
e = e.substring(r.raw.length);
|
|
5865
|
+
let o = t.at(-1);
|
|
5866
|
+
r.raw.length === 1 && o !== undefined ? o.raw += `
|
|
5867
|
+
` : t.push(r);
|
|
5868
|
+
continue;
|
|
5869
|
+
}
|
|
5870
|
+
if (r = this.tokenizer.code(e)) {
|
|
5871
|
+
e = e.substring(r.raw.length);
|
|
5872
|
+
let o = t.at(-1);
|
|
5873
|
+
o?.type === "paragraph" || o?.type === "text" ? (o.raw += (o.raw.endsWith(`
|
|
5874
|
+
`) ? "" : `
|
|
5875
|
+
`) + r.raw, o.text += `
|
|
5876
|
+
` + r.text, this.inlineQueue.at(-1).src = o.text) : t.push(r);
|
|
5877
|
+
continue;
|
|
5878
|
+
}
|
|
5879
|
+
if (r = this.tokenizer.fences(e)) {
|
|
5880
|
+
e = e.substring(r.raw.length), t.push(r);
|
|
5881
|
+
continue;
|
|
5882
|
+
}
|
|
5883
|
+
if (r = this.tokenizer.heading(e)) {
|
|
5884
|
+
e = e.substring(r.raw.length), t.push(r);
|
|
5885
|
+
continue;
|
|
5886
|
+
}
|
|
5887
|
+
if (r = this.tokenizer.hr(e)) {
|
|
5888
|
+
e = e.substring(r.raw.length), t.push(r);
|
|
5889
|
+
continue;
|
|
5890
|
+
}
|
|
5891
|
+
if (r = this.tokenizer.blockquote(e)) {
|
|
5892
|
+
e = e.substring(r.raw.length), t.push(r);
|
|
5893
|
+
continue;
|
|
5894
|
+
}
|
|
5895
|
+
if (r = this.tokenizer.list(e)) {
|
|
5896
|
+
e = e.substring(r.raw.length), t.push(r);
|
|
5897
|
+
continue;
|
|
5898
|
+
}
|
|
5899
|
+
if (r = this.tokenizer.html(e)) {
|
|
5900
|
+
e = e.substring(r.raw.length), t.push(r);
|
|
5901
|
+
continue;
|
|
5902
|
+
}
|
|
5903
|
+
if (r = this.tokenizer.def(e)) {
|
|
5904
|
+
e = e.substring(r.raw.length);
|
|
5905
|
+
let o = t.at(-1);
|
|
5906
|
+
o?.type === "paragraph" || o?.type === "text" ? (o.raw += (o.raw.endsWith(`
|
|
5907
|
+
`) ? "" : `
|
|
5908
|
+
`) + r.raw, o.text += `
|
|
5909
|
+
` + r.raw, this.inlineQueue.at(-1).src = o.text) : this.tokens.links[r.tag] || (this.tokens.links[r.tag] = { href: r.href, title: r.title }, t.push(r));
|
|
5910
|
+
continue;
|
|
5911
|
+
}
|
|
5912
|
+
if (r = this.tokenizer.table(e)) {
|
|
5913
|
+
e = e.substring(r.raw.length), t.push(r);
|
|
5914
|
+
continue;
|
|
5915
|
+
}
|
|
5916
|
+
if (r = this.tokenizer.lheading(e)) {
|
|
5917
|
+
e = e.substring(r.raw.length), t.push(r);
|
|
5918
|
+
continue;
|
|
5919
|
+
}
|
|
5920
|
+
let i = e;
|
|
5921
|
+
if (this.options.extensions?.startBlock) {
|
|
5922
|
+
let o = 1 / 0, u = e.slice(1), a;
|
|
5923
|
+
this.options.extensions.startBlock.forEach((p) => {
|
|
5924
|
+
a = p.call({ lexer: this }, u), typeof a == "number" && a >= 0 && (o = Math.min(o, a));
|
|
5925
|
+
}), o < 1 / 0 && o >= 0 && (i = e.substring(0, o + 1));
|
|
5926
|
+
}
|
|
5927
|
+
if (this.state.top && (r = this.tokenizer.paragraph(i))) {
|
|
5928
|
+
let o = t.at(-1);
|
|
5929
|
+
n && o?.type === "paragraph" ? (o.raw += (o.raw.endsWith(`
|
|
5930
|
+
`) ? "" : `
|
|
5931
|
+
`) + r.raw, o.text += `
|
|
5932
|
+
` + r.text, this.inlineQueue.pop(), this.inlineQueue.at(-1).src = o.text) : t.push(r), n = i.length !== e.length, e = e.substring(r.raw.length);
|
|
5933
|
+
continue;
|
|
5934
|
+
}
|
|
5935
|
+
if (r = this.tokenizer.text(e)) {
|
|
5936
|
+
e = e.substring(r.raw.length);
|
|
5937
|
+
let o = t.at(-1);
|
|
5938
|
+
o?.type === "text" ? (o.raw += (o.raw.endsWith(`
|
|
5939
|
+
`) ? "" : `
|
|
5940
|
+
`) + r.raw, o.text += `
|
|
5941
|
+
` + r.text, this.inlineQueue.pop(), this.inlineQueue.at(-1).src = o.text) : t.push(r);
|
|
5942
|
+
continue;
|
|
5943
|
+
}
|
|
5944
|
+
if (e) {
|
|
5945
|
+
this.infiniteLoopError(e.charCodeAt(0));
|
|
5946
|
+
break;
|
|
5947
|
+
}
|
|
5948
|
+
}
|
|
5949
|
+
return this.state.top = true, t;
|
|
5950
|
+
}
|
|
5951
|
+
inline(e, t = []) {
|
|
5952
|
+
return this.inlineQueue.push({ src: e, tokens: t }), t;
|
|
5953
|
+
}
|
|
5954
|
+
linkInText(e) {
|
|
5955
|
+
if (!e.includes("["))
|
|
5956
|
+
return false;
|
|
5957
|
+
let t = this.tokenizer.rules.inline.link;
|
|
5958
|
+
for (let n of e.matchAll(this.tokenizer.rules.inline.blockSkip))
|
|
5959
|
+
if (t.test(n[0]) && e.charAt(n.index - 1) !== "!")
|
|
5960
|
+
return true;
|
|
5961
|
+
for (let n of e.matchAll(this.tokenizer.rules.inline.reflinkSearch)) {
|
|
5962
|
+
let s = n[0], r = s.lastIndexOf("[");
|
|
5963
|
+
if (!(s.charAt(0) === "!" || !Object.hasOwn(this.tokens.links, s.slice(r + 1, -1))) && !(r > 1 && this.linkInText(s.slice(1, r - 1))))
|
|
5964
|
+
return true;
|
|
5965
|
+
}
|
|
5966
|
+
return false;
|
|
5967
|
+
}
|
|
5968
|
+
inlineTokens(e, t = []) {
|
|
5969
|
+
this.tokenizer.lexer = this;
|
|
5970
|
+
let n = e;
|
|
5971
|
+
if (this.tokens.links && e.includes("[")) {
|
|
5972
|
+
let o = this.tokenizer.rules.inline.reflinkSearch, u = (a) => {
|
|
5973
|
+
let p = a.lastIndexOf("[");
|
|
5974
|
+
if (!Object.hasOwn(this.tokens.links, a.slice(p + 1, -1)))
|
|
5975
|
+
return a;
|
|
5976
|
+
if (p > 1 && a.charAt(0) !== "!") {
|
|
5977
|
+
let c = a.slice(1, p - 1);
|
|
5978
|
+
if (this.linkInText(c))
|
|
5979
|
+
return "[" + c.replace(o, u) + "][" + "a".repeat(a.length - p - 2) + "]";
|
|
5980
|
+
}
|
|
5981
|
+
return "[" + "a".repeat(a.length - 2) + "]";
|
|
5982
|
+
};
|
|
5983
|
+
n = n.replace(o, u);
|
|
5984
|
+
}
|
|
5985
|
+
n = n.replace(this.tokenizer.rules.inline.anyPunctuation, (o) => "+".repeat(o.length)), n = n.replace(this.tokenizer.rules.inline.blockSkip, (o, u, a) => {
|
|
5986
|
+
let p = a ? a.length : 0;
|
|
5987
|
+
return o.slice(0, p) + "[" + "a".repeat(o.length - p - 2) + "]";
|
|
5988
|
+
}), n = this.options.hooks?.emStrongMask?.call({ lexer: this }, n) ?? n;
|
|
5989
|
+
let s = false, r = "", i = 1 / 0;
|
|
5990
|
+
for (;e; ) {
|
|
5991
|
+
if (e.length < i)
|
|
5992
|
+
i = e.length;
|
|
5993
|
+
else {
|
|
5994
|
+
this.infiniteLoopError(e.charCodeAt(0));
|
|
5995
|
+
break;
|
|
5996
|
+
}
|
|
5997
|
+
s || (r = ""), s = false;
|
|
5998
|
+
let o;
|
|
5999
|
+
if (this.options.extensions?.inline?.some((a) => (o = a.call({ lexer: this }, e, t)) ? (e = e.substring(o.raw.length), t.push(o), true) : false))
|
|
6000
|
+
continue;
|
|
6001
|
+
if (o = this.tokenizer.escape(e)) {
|
|
6002
|
+
e = e.substring(o.raw.length), t.push(o);
|
|
6003
|
+
continue;
|
|
6004
|
+
}
|
|
6005
|
+
if (o = this.tokenizer.tag(e)) {
|
|
6006
|
+
e = e.substring(o.raw.length), t.push(o);
|
|
6007
|
+
continue;
|
|
6008
|
+
}
|
|
6009
|
+
if (o = this.tokenizer.link(e)) {
|
|
6010
|
+
e = e.substring(o.raw.length), t.push(o);
|
|
6011
|
+
continue;
|
|
6012
|
+
}
|
|
6013
|
+
if (o = this.tokenizer.reflink(e, this.tokens.links)) {
|
|
6014
|
+
e = e.substring(o.raw.length);
|
|
6015
|
+
let a = t.at(-1);
|
|
6016
|
+
o.type === "text" && a?.type === "text" ? (a.raw += o.raw, a.text += o.text) : t.push(o);
|
|
6017
|
+
continue;
|
|
6018
|
+
}
|
|
6019
|
+
if (o = this.tokenizer.emStrong(e, n, r)) {
|
|
6020
|
+
e = e.substring(o.raw.length), t.push(o);
|
|
6021
|
+
continue;
|
|
6022
|
+
}
|
|
6023
|
+
if (o = this.tokenizer.codespan(e)) {
|
|
6024
|
+
e = e.substring(o.raw.length), t.push(o);
|
|
6025
|
+
continue;
|
|
6026
|
+
}
|
|
6027
|
+
if (o = this.tokenizer.br(e)) {
|
|
6028
|
+
e = e.substring(o.raw.length), t.push(o);
|
|
6029
|
+
continue;
|
|
6030
|
+
}
|
|
6031
|
+
if (o = this.tokenizer.del(e, n, r)) {
|
|
6032
|
+
e = e.substring(o.raw.length), t.push(o);
|
|
6033
|
+
continue;
|
|
6034
|
+
}
|
|
6035
|
+
if (o = this.tokenizer.autolink(e)) {
|
|
6036
|
+
e = e.substring(o.raw.length), t.push(o);
|
|
6037
|
+
continue;
|
|
6038
|
+
}
|
|
6039
|
+
if (!this.state.inLink && (o = this.tokenizer.url(e))) {
|
|
6040
|
+
e = e.substring(o.raw.length), t.push(o);
|
|
6041
|
+
continue;
|
|
6042
|
+
}
|
|
6043
|
+
let u = e;
|
|
6044
|
+
if (this.options.extensions?.startInline) {
|
|
6045
|
+
let a = 1 / 0, p = e.slice(1), c;
|
|
6046
|
+
this.options.extensions.startInline.forEach((h) => {
|
|
6047
|
+
c = h.call({ lexer: this }, p), typeof c == "number" && c >= 0 && (a = Math.min(a, c));
|
|
6048
|
+
}), a < 1 / 0 && a >= 0 && (u = e.substring(0, a + 1));
|
|
6049
|
+
}
|
|
6050
|
+
if (o = this.tokenizer.inlineText(u)) {
|
|
6051
|
+
e = e.substring(o.raw.length), o.raw.slice(-1) !== "_" && (r = o.raw.slice(-1)), s = true;
|
|
6052
|
+
let a = t.at(-1);
|
|
6053
|
+
a?.type === "text" ? (a.raw += o.raw, a.text += o.text) : t.push(o);
|
|
6054
|
+
continue;
|
|
6055
|
+
}
|
|
6056
|
+
if (e) {
|
|
6057
|
+
this.infiniteLoopError(e.charCodeAt(0));
|
|
6058
|
+
break;
|
|
6059
|
+
}
|
|
6060
|
+
}
|
|
6061
|
+
return t;
|
|
6062
|
+
}
|
|
6063
|
+
infiniteLoopError(e) {
|
|
6064
|
+
let t = "Infinite loop on byte: " + e;
|
|
6065
|
+
if (this.options.silent)
|
|
6066
|
+
console.error(t);
|
|
6067
|
+
else
|
|
6068
|
+
throw new Error(t);
|
|
6069
|
+
}
|
|
6070
|
+
};
|
|
6071
|
+
var P = class {
|
|
6072
|
+
options;
|
|
6073
|
+
parser;
|
|
6074
|
+
constructor(e) {
|
|
6075
|
+
this.options = e || R;
|
|
6076
|
+
}
|
|
6077
|
+
space(e) {
|
|
6078
|
+
return "";
|
|
6079
|
+
}
|
|
6080
|
+
code({ text: e, lang: t, escaped: n }) {
|
|
6081
|
+
let s = (t || "").match(m.notSpaceStart)?.[0], r = e.replace(m.endingNewline, "") + `
|
|
6082
|
+
`;
|
|
6083
|
+
return s ? '<pre><code class="language-' + T(s) + '">' + (n ? r : T(r, true)) + `</code></pre>
|
|
6084
|
+
` : "<pre><code>" + (n ? r : T(r, true)) + `</code></pre>
|
|
6085
|
+
`;
|
|
6086
|
+
}
|
|
6087
|
+
blockquote({ tokens: e }) {
|
|
6088
|
+
return `<blockquote>
|
|
6089
|
+
${this.parser.parse(e)}</blockquote>
|
|
6090
|
+
`;
|
|
6091
|
+
}
|
|
6092
|
+
html({ text: e }) {
|
|
6093
|
+
return e;
|
|
6094
|
+
}
|
|
6095
|
+
def(e) {
|
|
6096
|
+
return "";
|
|
6097
|
+
}
|
|
6098
|
+
heading({ tokens: e, depth: t }) {
|
|
6099
|
+
return `<h${t}>${this.parser.parseInline(e)}</h${t}>
|
|
6100
|
+
`;
|
|
6101
|
+
}
|
|
6102
|
+
hr(e) {
|
|
6103
|
+
return `<hr>
|
|
6104
|
+
`;
|
|
6105
|
+
}
|
|
6106
|
+
list(e) {
|
|
6107
|
+
let { ordered: t, start: n } = e, s = "";
|
|
6108
|
+
for (let o = 0;o < e.items.length; o++) {
|
|
6109
|
+
let u = e.items[o];
|
|
6110
|
+
s += this.listitem(u);
|
|
6111
|
+
}
|
|
6112
|
+
let r = t ? "ol" : "ul", i = t && n !== 1 ? ' start="' + n + '"' : "";
|
|
6113
|
+
return "<" + r + i + `>
|
|
6114
|
+
` + s + "</" + r + `>
|
|
6115
|
+
`;
|
|
6116
|
+
}
|
|
6117
|
+
listitem(e) {
|
|
6118
|
+
return `<li>${this.parser.parse(e.tokens)}</li>
|
|
6119
|
+
`;
|
|
6120
|
+
}
|
|
6121
|
+
checkbox({ checked: e }) {
|
|
6122
|
+
return "<input " + (e ? 'checked="" ' : "") + 'disabled="" type="checkbox"> ';
|
|
6123
|
+
}
|
|
6124
|
+
paragraph({ tokens: e }) {
|
|
6125
|
+
return `<p>${this.parser.parseInline(e)}</p>
|
|
6126
|
+
`;
|
|
6127
|
+
}
|
|
6128
|
+
table(e) {
|
|
6129
|
+
let t = "", n = "";
|
|
6130
|
+
for (let r = 0;r < e.header.length; r++)
|
|
6131
|
+
n += this.tablecell(e.header[r]);
|
|
6132
|
+
t += this.tablerow({ text: n });
|
|
6133
|
+
let s = "";
|
|
6134
|
+
for (let r = 0;r < e.rows.length; r++) {
|
|
6135
|
+
let i = e.rows[r];
|
|
6136
|
+
n = "";
|
|
6137
|
+
for (let o = 0;o < i.length; o++)
|
|
6138
|
+
n += this.tablecell(i[o]);
|
|
6139
|
+
s += this.tablerow({ text: n });
|
|
6140
|
+
}
|
|
6141
|
+
return s && (s = `<tbody>${s}</tbody>`), `<table>
|
|
6142
|
+
<thead>
|
|
6143
|
+
` + t + `</thead>
|
|
6144
|
+
` + s + `</table>
|
|
6145
|
+
`;
|
|
6146
|
+
}
|
|
6147
|
+
tablerow({ text: e }) {
|
|
6148
|
+
return `<tr>
|
|
6149
|
+
${e}</tr>
|
|
6150
|
+
`;
|
|
6151
|
+
}
|
|
6152
|
+
tablecell(e) {
|
|
6153
|
+
let t = this.parser.parseInline(e.tokens), n = e.header ? "th" : "td";
|
|
6154
|
+
return (e.align ? `<${n} align="${e.align}">` : `<${n}>`) + t + `</${n}>
|
|
6155
|
+
`;
|
|
6156
|
+
}
|
|
6157
|
+
strong({ tokens: e }) {
|
|
6158
|
+
return `<strong>${this.parser.parseInline(e)}</strong>`;
|
|
6159
|
+
}
|
|
6160
|
+
em({ tokens: e }) {
|
|
6161
|
+
return `<em>${this.parser.parseInline(e)}</em>`;
|
|
6162
|
+
}
|
|
6163
|
+
codespan({ text: e }) {
|
|
6164
|
+
return `<code>${T(e, true)}</code>`;
|
|
6165
|
+
}
|
|
6166
|
+
br(e) {
|
|
6167
|
+
return "<br>";
|
|
6168
|
+
}
|
|
6169
|
+
del({ tokens: e }) {
|
|
6170
|
+
return `<del>${this.parser.parseInline(e)}</del>`;
|
|
6171
|
+
}
|
|
6172
|
+
link({ href: e, title: t, tokens: n }) {
|
|
6173
|
+
let s = this.parser.parseInline(n), r = Y(e);
|
|
6174
|
+
if (r === null)
|
|
6175
|
+
return s;
|
|
6176
|
+
e = r;
|
|
6177
|
+
let i = '<a href="' + e + '"';
|
|
6178
|
+
return t && (i += ' title="' + T(t) + '"'), i += ">" + s + "</a>", i;
|
|
6179
|
+
}
|
|
6180
|
+
image({ href: e, title: t, text: n, tokens: s }) {
|
|
6181
|
+
s && (n = this.parser.parseInline(s, this.parser.textRenderer));
|
|
6182
|
+
let r = Y(e);
|
|
6183
|
+
if (r === null)
|
|
6184
|
+
return T(n);
|
|
6185
|
+
e = r;
|
|
6186
|
+
let i = `<img src="${e}" alt="${T(n)}"`;
|
|
6187
|
+
return t && (i += ` title="${T(t)}"`), i += ">", i;
|
|
6188
|
+
}
|
|
6189
|
+
text(e) {
|
|
6190
|
+
return "tokens" in e && e.tokens ? this.parser.parseInline(e.tokens) : ("escaped" in e) && e.escaped ? e.text : T(e.text);
|
|
6191
|
+
}
|
|
6192
|
+
};
|
|
6193
|
+
var L = class {
|
|
6194
|
+
strong({ text: e }) {
|
|
6195
|
+
return e;
|
|
6196
|
+
}
|
|
6197
|
+
em({ text: e }) {
|
|
6198
|
+
return e;
|
|
6199
|
+
}
|
|
6200
|
+
codespan({ text: e }) {
|
|
6201
|
+
return e;
|
|
6202
|
+
}
|
|
6203
|
+
del({ text: e }) {
|
|
6204
|
+
return e;
|
|
6205
|
+
}
|
|
6206
|
+
html({ text: e }) {
|
|
6207
|
+
return e;
|
|
6208
|
+
}
|
|
6209
|
+
text({ text: e }) {
|
|
6210
|
+
return e;
|
|
6211
|
+
}
|
|
6212
|
+
link({ text: e }) {
|
|
6213
|
+
return "" + e;
|
|
6214
|
+
}
|
|
6215
|
+
image({ text: e }) {
|
|
6216
|
+
return "" + e;
|
|
6217
|
+
}
|
|
6218
|
+
br() {
|
|
6219
|
+
return "";
|
|
6220
|
+
}
|
|
6221
|
+
checkbox({ raw: e }) {
|
|
6222
|
+
return e;
|
|
6223
|
+
}
|
|
6224
|
+
};
|
|
6225
|
+
var b = class l {
|
|
6226
|
+
options;
|
|
6227
|
+
renderer;
|
|
6228
|
+
textRenderer;
|
|
6229
|
+
constructor(e) {
|
|
6230
|
+
this.options = e || R, this.options.renderer = this.options.renderer || new P, this.renderer = this.options.renderer, this.renderer.options = this.options, this.renderer.parser = this, this.textRenderer = new L;
|
|
6231
|
+
}
|
|
6232
|
+
static parse(e, t) {
|
|
6233
|
+
return new l(t).parse(e);
|
|
6234
|
+
}
|
|
6235
|
+
static parseInline(e, t) {
|
|
6236
|
+
return new l(t).parseInline(e);
|
|
6237
|
+
}
|
|
6238
|
+
parse(e) {
|
|
6239
|
+
this.renderer.parser = this;
|
|
6240
|
+
let t = "";
|
|
6241
|
+
for (let n = 0;n < e.length; n++) {
|
|
6242
|
+
let s = e[n];
|
|
6243
|
+
if (this.options.extensions?.renderers?.[s.type]) {
|
|
6244
|
+
let i = s, o = this.options.extensions.renderers[i.type].call({ parser: this }, i);
|
|
6245
|
+
if (o !== false || !["space", "hr", "heading", "code", "table", "blockquote", "list", "checkbox", "html", "def", "paragraph", "text"].includes(i.type)) {
|
|
6246
|
+
t += o || "";
|
|
6247
|
+
continue;
|
|
6248
|
+
}
|
|
6249
|
+
}
|
|
6250
|
+
let r = s;
|
|
6251
|
+
switch (r.type) {
|
|
6252
|
+
case "space": {
|
|
6253
|
+
t += this.renderer.space(r);
|
|
6254
|
+
break;
|
|
6255
|
+
}
|
|
6256
|
+
case "hr": {
|
|
6257
|
+
t += this.renderer.hr(r);
|
|
6258
|
+
break;
|
|
6259
|
+
}
|
|
6260
|
+
case "heading": {
|
|
6261
|
+
t += this.renderer.heading(r);
|
|
6262
|
+
break;
|
|
6263
|
+
}
|
|
6264
|
+
case "code": {
|
|
6265
|
+
t += this.renderer.code(r);
|
|
6266
|
+
break;
|
|
6267
|
+
}
|
|
6268
|
+
case "table": {
|
|
6269
|
+
t += this.renderer.table(r);
|
|
6270
|
+
break;
|
|
6271
|
+
}
|
|
6272
|
+
case "blockquote": {
|
|
6273
|
+
t += this.renderer.blockquote(r);
|
|
6274
|
+
break;
|
|
6275
|
+
}
|
|
6276
|
+
case "list": {
|
|
6277
|
+
t += this.renderer.list(r);
|
|
6278
|
+
break;
|
|
6279
|
+
}
|
|
6280
|
+
case "checkbox": {
|
|
6281
|
+
t += this.renderer.checkbox(r);
|
|
6282
|
+
break;
|
|
6283
|
+
}
|
|
6284
|
+
case "html": {
|
|
6285
|
+
t += this.renderer.html(r);
|
|
6286
|
+
break;
|
|
6287
|
+
}
|
|
6288
|
+
case "def": {
|
|
6289
|
+
t += this.renderer.def(r);
|
|
6290
|
+
break;
|
|
6291
|
+
}
|
|
6292
|
+
case "paragraph": {
|
|
6293
|
+
t += this.renderer.paragraph(r);
|
|
6294
|
+
break;
|
|
6295
|
+
}
|
|
6296
|
+
case "text": {
|
|
6297
|
+
t += this.renderer.text(r);
|
|
6298
|
+
break;
|
|
6299
|
+
}
|
|
6300
|
+
default: {
|
|
6301
|
+
let i = 'Token with "' + r.type + '" type was not found.';
|
|
6302
|
+
if (this.options.silent)
|
|
6303
|
+
return console.error(i), "";
|
|
6304
|
+
throw new Error(i);
|
|
6305
|
+
}
|
|
6306
|
+
}
|
|
6307
|
+
}
|
|
6308
|
+
return t;
|
|
6309
|
+
}
|
|
6310
|
+
parseInline(e, t = this.renderer) {
|
|
6311
|
+
this.renderer.parser = this;
|
|
6312
|
+
let n = "";
|
|
6313
|
+
for (let s = 0;s < e.length; s++) {
|
|
6314
|
+
let r = e[s];
|
|
6315
|
+
if (this.options.extensions?.renderers?.[r.type]) {
|
|
6316
|
+
let o = this.options.extensions.renderers[r.type].call({ parser: this }, r);
|
|
6317
|
+
if (o !== false || !["escape", "html", "link", "image", "checkbox", "strong", "em", "codespan", "br", "del", "text"].includes(r.type)) {
|
|
6318
|
+
n += o || "";
|
|
6319
|
+
continue;
|
|
6320
|
+
}
|
|
6321
|
+
}
|
|
6322
|
+
let i = r;
|
|
6323
|
+
switch (i.type) {
|
|
6324
|
+
case "escape": {
|
|
6325
|
+
n += t.text(i);
|
|
6326
|
+
break;
|
|
6327
|
+
}
|
|
6328
|
+
case "html": {
|
|
6329
|
+
n += t.html(i);
|
|
6330
|
+
break;
|
|
6331
|
+
}
|
|
6332
|
+
case "link": {
|
|
6333
|
+
n += t.link(i);
|
|
6334
|
+
break;
|
|
6335
|
+
}
|
|
6336
|
+
case "image": {
|
|
6337
|
+
n += t.image(i);
|
|
6338
|
+
break;
|
|
6339
|
+
}
|
|
6340
|
+
case "checkbox": {
|
|
6341
|
+
n += t.checkbox(i);
|
|
6342
|
+
break;
|
|
6343
|
+
}
|
|
6344
|
+
case "strong": {
|
|
6345
|
+
n += t.strong(i);
|
|
6346
|
+
break;
|
|
6347
|
+
}
|
|
6348
|
+
case "em": {
|
|
6349
|
+
n += t.em(i);
|
|
6350
|
+
break;
|
|
6351
|
+
}
|
|
6352
|
+
case "codespan": {
|
|
6353
|
+
n += t.codespan(i);
|
|
6354
|
+
break;
|
|
6355
|
+
}
|
|
6356
|
+
case "br": {
|
|
6357
|
+
n += t.br(i);
|
|
6358
|
+
break;
|
|
6359
|
+
}
|
|
6360
|
+
case "del": {
|
|
6361
|
+
n += t.del(i);
|
|
6362
|
+
break;
|
|
6363
|
+
}
|
|
6364
|
+
case "text": {
|
|
6365
|
+
n += t.text(i);
|
|
6366
|
+
break;
|
|
6367
|
+
}
|
|
6368
|
+
default: {
|
|
6369
|
+
let o = 'Token with "' + i.type + '" type was not found.';
|
|
6370
|
+
if (this.options.silent)
|
|
6371
|
+
return console.error(o), "";
|
|
6372
|
+
throw new Error(o);
|
|
6373
|
+
}
|
|
6374
|
+
}
|
|
6375
|
+
}
|
|
6376
|
+
return n;
|
|
6377
|
+
}
|
|
6378
|
+
};
|
|
6379
|
+
var S = class {
|
|
6380
|
+
options;
|
|
6381
|
+
block;
|
|
6382
|
+
constructor(e) {
|
|
6383
|
+
this.options = e || R;
|
|
6384
|
+
}
|
|
6385
|
+
static passThroughHooks = new Set(["preprocess", "postprocess", "processAllTokens", "emStrongMask"]);
|
|
6386
|
+
static passThroughHooksRespectAsync = new Set(["preprocess", "postprocess", "processAllTokens"]);
|
|
6387
|
+
preprocess(e) {
|
|
6388
|
+
return e;
|
|
6389
|
+
}
|
|
6390
|
+
postprocess(e) {
|
|
6391
|
+
return e;
|
|
6392
|
+
}
|
|
6393
|
+
processAllTokens(e) {
|
|
6394
|
+
return e;
|
|
6395
|
+
}
|
|
6396
|
+
emStrongMask(e) {
|
|
6397
|
+
return e;
|
|
6398
|
+
}
|
|
6399
|
+
provideLexer(e = this.block) {
|
|
6400
|
+
return e ? x.lex : x.lexInline;
|
|
6401
|
+
}
|
|
6402
|
+
provideParser(e = this.block) {
|
|
6403
|
+
return e ? b.parse : b.parseInline;
|
|
6404
|
+
}
|
|
6405
|
+
};
|
|
6406
|
+
var Z = class {
|
|
6407
|
+
defaults = A();
|
|
6408
|
+
options = this.setOptions;
|
|
6409
|
+
parse = this.parseMarkdown(true);
|
|
6410
|
+
parseInline = this.parseMarkdown(false);
|
|
6411
|
+
Parser = b;
|
|
6412
|
+
Renderer = P;
|
|
6413
|
+
TextRenderer = L;
|
|
6414
|
+
Lexer = x;
|
|
6415
|
+
Tokenizer = y;
|
|
6416
|
+
Hooks = S;
|
|
6417
|
+
constructor(...e) {
|
|
6418
|
+
this.use(...e);
|
|
6419
|
+
}
|
|
6420
|
+
walkTokens(e, t) {
|
|
6421
|
+
let n = [];
|
|
6422
|
+
for (let s of e)
|
|
6423
|
+
switch (n = n.concat(t.call(this, s)), s.type) {
|
|
6424
|
+
case "table": {
|
|
6425
|
+
let r = s;
|
|
6426
|
+
for (let i of r.header)
|
|
6427
|
+
n = n.concat(this.walkTokens(i.tokens, t));
|
|
6428
|
+
for (let i of r.rows)
|
|
6429
|
+
for (let o of i)
|
|
6430
|
+
n = n.concat(this.walkTokens(o.tokens, t));
|
|
6431
|
+
break;
|
|
6432
|
+
}
|
|
6433
|
+
case "list": {
|
|
6434
|
+
let r = s;
|
|
6435
|
+
n = n.concat(this.walkTokens(r.items, t));
|
|
6436
|
+
break;
|
|
6437
|
+
}
|
|
6438
|
+
default: {
|
|
6439
|
+
let r = s;
|
|
6440
|
+
this.defaults.extensions?.childTokens?.[r.type] ? this.defaults.extensions.childTokens[r.type].forEach((i) => {
|
|
6441
|
+
let o = r[i].flat(1 / 0);
|
|
6442
|
+
n = n.concat(this.walkTokens(o, t));
|
|
6443
|
+
}) : r.tokens && (n = n.concat(this.walkTokens(r.tokens, t)));
|
|
6444
|
+
}
|
|
6445
|
+
}
|
|
6446
|
+
return n;
|
|
6447
|
+
}
|
|
6448
|
+
use(...e) {
|
|
6449
|
+
let t = this.defaults.extensions || { renderers: {}, childTokens: {} };
|
|
6450
|
+
return e.forEach((n) => {
|
|
6451
|
+
let s = { ...n };
|
|
6452
|
+
if (s.async = this.defaults.async || s.async || false, n.extensions && (n.extensions.forEach((r) => {
|
|
6453
|
+
if (!r.name)
|
|
6454
|
+
throw new Error("extension name required");
|
|
6455
|
+
if ("renderer" in r) {
|
|
6456
|
+
let i = t.renderers[r.name];
|
|
6457
|
+
i ? t.renderers[r.name] = function(...o) {
|
|
6458
|
+
let u = r.renderer.apply(this, o);
|
|
6459
|
+
return u === false && (u = i.apply(this, o)), u;
|
|
6460
|
+
} : t.renderers[r.name] = r.renderer;
|
|
6461
|
+
}
|
|
6462
|
+
if ("tokenizer" in r) {
|
|
6463
|
+
if (!r.level || r.level !== "block" && r.level !== "inline")
|
|
6464
|
+
throw new Error("extension level must be 'block' or 'inline'");
|
|
6465
|
+
let i = t[r.level];
|
|
6466
|
+
i ? i.unshift(r.tokenizer) : t[r.level] = [r.tokenizer], r.start && (r.level === "block" ? t.startBlock ? t.startBlock.push(r.start) : t.startBlock = [r.start] : r.level === "inline" && (t.startInline ? t.startInline.push(r.start) : t.startInline = [r.start]));
|
|
6467
|
+
}
|
|
6468
|
+
"childTokens" in r && r.childTokens && (t.childTokens[r.name] = r.childTokens);
|
|
6469
|
+
}), s.extensions = t), n.renderer) {
|
|
6470
|
+
let r = this.defaults.renderer || new P(this.defaults);
|
|
6471
|
+
for (let i in n.renderer) {
|
|
6472
|
+
if (!(i in r))
|
|
6473
|
+
throw new Error(`renderer '${i}' does not exist`);
|
|
6474
|
+
if (["options", "parser"].includes(i))
|
|
6475
|
+
continue;
|
|
6476
|
+
let o = i, u = n.renderer[o], a = r[o];
|
|
6477
|
+
r[o] = (...p) => {
|
|
6478
|
+
let c = u.apply(r, p);
|
|
6479
|
+
return c === false && (c = a.apply(r, p)), c || "";
|
|
6480
|
+
};
|
|
6481
|
+
}
|
|
6482
|
+
s.renderer = r;
|
|
6483
|
+
}
|
|
6484
|
+
if (n.tokenizer) {
|
|
6485
|
+
let r = this.defaults.tokenizer || new y(this.defaults);
|
|
6486
|
+
for (let i in n.tokenizer) {
|
|
6487
|
+
if (!(i in r))
|
|
6488
|
+
throw new Error(`tokenizer '${i}' does not exist`);
|
|
6489
|
+
if (["options", "rules", "lexer"].includes(i))
|
|
6490
|
+
continue;
|
|
6491
|
+
let o = i, u = n.tokenizer[o], a = r[o];
|
|
6492
|
+
r[o] = (...p) => {
|
|
6493
|
+
let c = u.apply(r, p);
|
|
6494
|
+
return c === false && (c = a.apply(r, p)), c;
|
|
6495
|
+
};
|
|
6496
|
+
}
|
|
6497
|
+
s.tokenizer = r;
|
|
6498
|
+
}
|
|
6499
|
+
if (n.hooks) {
|
|
6500
|
+
let r = this.defaults.hooks || new S;
|
|
6501
|
+
for (let i in n.hooks) {
|
|
6502
|
+
if (!(i in r))
|
|
6503
|
+
throw new Error(`hook '${i}' does not exist`);
|
|
6504
|
+
if (["options", "block"].includes(i))
|
|
6505
|
+
continue;
|
|
6506
|
+
let o = i, u = n.hooks[o], a = r[o];
|
|
6507
|
+
S.passThroughHooks.has(i) ? r[o] = (p) => {
|
|
6508
|
+
if (this.defaults.async && S.passThroughHooksRespectAsync.has(i))
|
|
6509
|
+
return (async () => {
|
|
6510
|
+
let h = await u.call(r, p);
|
|
6511
|
+
return a.call(r, h);
|
|
6512
|
+
})();
|
|
6513
|
+
let c = u.call(r, p);
|
|
6514
|
+
return a.call(r, c);
|
|
6515
|
+
} : r[o] = (...p) => {
|
|
6516
|
+
if (this.defaults.async)
|
|
6517
|
+
return (async () => {
|
|
6518
|
+
let h = await u.apply(r, p);
|
|
6519
|
+
return h === false && (h = await a.apply(r, p)), h;
|
|
6520
|
+
})();
|
|
6521
|
+
let c = u.apply(r, p);
|
|
6522
|
+
return c === false && (c = a.apply(r, p)), c;
|
|
6523
|
+
};
|
|
6524
|
+
}
|
|
6525
|
+
s.hooks = r;
|
|
6526
|
+
}
|
|
6527
|
+
if (n.walkTokens) {
|
|
6528
|
+
let r = this.defaults.walkTokens, i = n.walkTokens;
|
|
6529
|
+
s.walkTokens = function(o) {
|
|
6530
|
+
let u = [];
|
|
6531
|
+
return u.push(i.call(this, o)), r && (u = u.concat(r.call(this, o))), u;
|
|
6532
|
+
};
|
|
6533
|
+
}
|
|
6534
|
+
this.defaults = { ...this.defaults, ...s };
|
|
6535
|
+
}), this;
|
|
6536
|
+
}
|
|
6537
|
+
setOptions(e) {
|
|
6538
|
+
return this.defaults = { ...this.defaults, ...e }, this;
|
|
6539
|
+
}
|
|
6540
|
+
lexer(e, t) {
|
|
6541
|
+
return x.lex(e, t ?? this.defaults);
|
|
6542
|
+
}
|
|
6543
|
+
parser(e, t) {
|
|
6544
|
+
return b.parse(e, t ?? this.defaults);
|
|
6545
|
+
}
|
|
6546
|
+
parseMarkdown(e) {
|
|
6547
|
+
return (n, s) => {
|
|
6548
|
+
let r = { ...s }, i = { ...this.defaults, ...r }, o = this.onError(!!i.silent, !!i.async);
|
|
6549
|
+
if (this.defaults.async === true && r.async === false)
|
|
6550
|
+
return o(new Error("marked(): The async option was set to true by an extension. Remove async: false from the parse options object to return a Promise."));
|
|
6551
|
+
if (typeof n > "u" || n === null)
|
|
6552
|
+
return o(new Error("marked(): input parameter is undefined or null"));
|
|
6553
|
+
if (typeof n != "string")
|
|
6554
|
+
return o(new Error("marked(): input parameter is of type " + Object.prototype.toString.call(n) + ", string expected"));
|
|
6555
|
+
if (i.hooks && (i.hooks.options = i, i.hooks.block = e), i.async)
|
|
6556
|
+
return (async () => {
|
|
6557
|
+
let u = i.hooks ? await i.hooks.preprocess(n) : n, p = await (i.hooks ? await i.hooks.provideLexer(e) : e ? x.lex : x.lexInline)(u, i), c = i.hooks ? await i.hooks.processAllTokens(p) : p;
|
|
6558
|
+
i.walkTokens && await Promise.all(this.walkTokens(c, i.walkTokens));
|
|
6559
|
+
let d = await (i.hooks ? await i.hooks.provideParser(e) : e ? b.parse : b.parseInline)(c, i);
|
|
6560
|
+
return i.hooks ? await i.hooks.postprocess(d) : d;
|
|
6561
|
+
})().catch(o);
|
|
6562
|
+
try {
|
|
6563
|
+
i.hooks && (n = i.hooks.preprocess(n));
|
|
6564
|
+
let a = (i.hooks ? i.hooks.provideLexer(e) : e ? x.lex : x.lexInline)(n, i);
|
|
6565
|
+
i.hooks && (a = i.hooks.processAllTokens(a)), i.walkTokens && this.walkTokens(a, i.walkTokens);
|
|
6566
|
+
let c = (i.hooks ? i.hooks.provideParser(e) : e ? b.parse : b.parseInline)(a, i);
|
|
6567
|
+
return i.hooks && (c = i.hooks.postprocess(c)), c;
|
|
6568
|
+
} catch (u) {
|
|
6569
|
+
return o(u);
|
|
6570
|
+
}
|
|
6571
|
+
};
|
|
6572
|
+
}
|
|
6573
|
+
onError(e, t) {
|
|
6574
|
+
return (n) => {
|
|
6575
|
+
if (n.message += `
|
|
6576
|
+
Please report this to https://github.com/markedjs/marked.`, e) {
|
|
6577
|
+
let s = "<p>An error occurred:</p><pre>" + T(n.message + "", true) + "</pre>";
|
|
6578
|
+
return t ? Promise.resolve(s) : s;
|
|
6579
|
+
}
|
|
6580
|
+
if (t)
|
|
6581
|
+
return Promise.reject(n);
|
|
6582
|
+
throw n;
|
|
6583
|
+
};
|
|
6584
|
+
}
|
|
6585
|
+
};
|
|
6586
|
+
var M = new Z;
|
|
6587
|
+
function f(l, e) {
|
|
6588
|
+
return M.parse(l, e);
|
|
6589
|
+
}
|
|
6590
|
+
f.options = f.setOptions = function(l) {
|
|
6591
|
+
return M.setOptions(l), f.defaults = M.defaults, j(f.defaults), f;
|
|
6592
|
+
};
|
|
6593
|
+
f.getDefaults = A;
|
|
6594
|
+
f.defaults = R;
|
|
6595
|
+
function dt(...l) {
|
|
6596
|
+
return M.use(...l), f.defaults = M.defaults, j(f.defaults), f;
|
|
6597
|
+
}
|
|
6598
|
+
f.use = dt;
|
|
6599
|
+
f.walkTokens = function(l, e) {
|
|
6600
|
+
return M.walkTokens(l, e);
|
|
6601
|
+
};
|
|
6602
|
+
f.parseInline = M.parseInline;
|
|
6603
|
+
f.Parser = b;
|
|
6604
|
+
f.parser = b.parse;
|
|
6605
|
+
f.Renderer = P;
|
|
6606
|
+
f.TextRenderer = L;
|
|
6607
|
+
f.Lexer = x;
|
|
6608
|
+
f.lexer = x.lex;
|
|
6609
|
+
f.Tokenizer = y;
|
|
6610
|
+
f.Hooks = S;
|
|
6611
|
+
f.parse = f;
|
|
6612
|
+
var nn = f.options;
|
|
6613
|
+
var rn = f.setOptions;
|
|
6614
|
+
var sn = f.walkTokens;
|
|
6615
|
+
var on = f.parseInline;
|
|
6616
|
+
var ln = b.parse;
|
|
6617
|
+
var un = x.lex;
|
|
6618
|
+
// ../../node_modules/.bun/get-east-asian-width@1.6.0/node_modules/get-east-asian-width/lookup-data.js
|
|
6619
|
+
var ambiguousMinimalCodePoint = 161;
|
|
6620
|
+
var ambiguousMaximumCodePoint = 1114109;
|
|
6621
|
+
var ambiguousRanges = [161, 161, 164, 164, 167, 168, 170, 170, 173, 174, 176, 180, 182, 186, 188, 191, 198, 198, 208, 208, 215, 216, 222, 225, 230, 230, 232, 234, 236, 237, 240, 240, 242, 243, 247, 250, 252, 252, 254, 254, 257, 257, 273, 273, 275, 275, 283, 283, 294, 295, 299, 299, 305, 307, 312, 312, 319, 322, 324, 324, 328, 331, 333, 333, 338, 339, 358, 359, 363, 363, 462, 462, 464, 464, 466, 466, 468, 468, 470, 470, 472, 472, 474, 474, 476, 476, 593, 593, 609, 609, 708, 708, 711, 711, 713, 715, 717, 717, 720, 720, 728, 731, 733, 733, 735, 735, 768, 879, 913, 929, 931, 937, 945, 961, 963, 969, 1025, 1025, 1040, 1103, 1105, 1105, 8208, 8208, 8211, 8214, 8216, 8217, 8220, 8221, 8224, 8226, 8228, 8231, 8240, 8240, 8242, 8243, 8245, 8245, 8251, 8251, 8254, 8254, 8308, 8308, 8319, 8319, 8321, 8324, 8364, 8364, 8451, 8451, 8453, 8453, 8457, 8457, 8467, 8467, 8470, 8470, 8481, 8482, 8486, 8486, 8491, 8491, 8531, 8532, 8539, 8542, 8544, 8555, 8560, 8569, 8585, 8585, 8592, 8601, 8632, 8633, 8658, 8658, 8660, 8660, 8679, 8679, 8704, 8704, 8706, 8707, 8711, 8712, 8715, 8715, 8719, 8719, 8721, 8721, 8725, 8725, 8730, 8730, 8733, 8736, 8739, 8739, 8741, 8741, 8743, 8748, 8750, 8750, 8756, 8759, 8764, 8765, 8776, 8776, 8780, 8780, 8786, 8786, 8800, 8801, 8804, 8807, 8810, 8811, 8814, 8815, 8834, 8835, 8838, 8839, 8853, 8853, 8857, 8857, 8869, 8869, 8895, 8895, 8978, 8978, 9312, 9449, 9451, 9547, 9552, 9587, 9600, 9615, 9618, 9621, 9632, 9633, 9635, 9641, 9650, 9651, 9654, 9655, 9660, 9661, 9664, 9665, 9670, 9672, 9675, 9675, 9678, 9681, 9698, 9701, 9711, 9711, 9733, 9734, 9737, 9737, 9742, 9743, 9756, 9756, 9758, 9758, 9792, 9792, 9794, 9794, 9824, 9825, 9827, 9829, 9831, 9834, 9836, 9837, 9839, 9839, 9886, 9887, 9919, 9919, 9926, 9933, 9935, 9939, 9941, 9953, 9955, 9955, 9960, 9961, 9963, 9969, 9972, 9972, 9974, 9977, 9979, 9980, 9982, 9983, 10045, 10045, 10102, 10111, 11094, 11097, 12872, 12879, 57344, 63743, 65024, 65039, 65533, 65533, 127232, 127242, 127248, 127277, 127280, 127337, 127344, 127373, 127375, 127376, 127387, 127404, 917760, 917999, 983040, 1048573, 1048576, 1114109];
|
|
6622
|
+
var fullwidthMinimalCodePoint = 12288;
|
|
6623
|
+
var fullwidthMaximumCodePoint = 65510;
|
|
6624
|
+
var fullwidthRanges = [12288, 12288, 65281, 65376, 65504, 65510];
|
|
6625
|
+
var wideMinimalCodePoint = 4352;
|
|
6626
|
+
var wideMaximumCodePoint = 262141;
|
|
6627
|
+
var wideRanges = [4352, 4447, 8986, 8987, 9001, 9002, 9193, 9196, 9200, 9200, 9203, 9203, 9725, 9726, 9748, 9749, 9776, 9783, 9800, 9811, 9855, 9855, 9866, 9871, 9875, 9875, 9889, 9889, 9898, 9899, 9917, 9918, 9924, 9925, 9934, 9934, 9940, 9940, 9962, 9962, 9970, 9971, 9973, 9973, 9978, 9978, 9981, 9981, 9989, 9989, 9994, 9995, 10024, 10024, 10060, 10060, 10062, 10062, 10067, 10069, 10071, 10071, 10133, 10135, 10160, 10160, 10175, 10175, 11035, 11036, 11088, 11088, 11093, 11093, 11904, 11929, 11931, 12019, 12032, 12245, 12272, 12287, 12289, 12350, 12353, 12438, 12441, 12543, 12549, 12591, 12593, 12686, 12688, 12773, 12783, 12830, 12832, 12871, 12880, 42124, 42128, 42182, 43360, 43388, 44032, 55203, 63744, 64255, 65040, 65049, 65072, 65106, 65108, 65126, 65128, 65131, 94176, 94180, 94192, 94198, 94208, 101589, 101631, 101662, 101760, 101874, 110576, 110579, 110581, 110587, 110589, 110590, 110592, 110882, 110898, 110898, 110928, 110930, 110933, 110933, 110948, 110951, 110960, 111355, 119552, 119638, 119648, 119670, 126980, 126980, 127183, 127183, 127374, 127374, 127377, 127386, 127488, 127490, 127504, 127547, 127552, 127560, 127568, 127569, 127584, 127589, 127744, 127776, 127789, 127797, 127799, 127868, 127870, 127891, 127904, 127946, 127951, 127955, 127968, 127984, 127988, 127988, 127992, 128062, 128064, 128064, 128066, 128252, 128255, 128317, 128331, 128334, 128336, 128359, 128378, 128378, 128405, 128406, 128420, 128420, 128507, 128591, 128640, 128709, 128716, 128716, 128720, 128722, 128725, 128728, 128732, 128735, 128747, 128748, 128756, 128764, 128992, 129003, 129008, 129008, 129292, 129338, 129340, 129349, 129351, 129535, 129648, 129660, 129664, 129674, 129678, 129734, 129736, 129736, 129741, 129756, 129759, 129770, 129775, 129784, 131072, 196605, 196608, 262141];
|
|
6628
|
+
|
|
6629
|
+
// ../../node_modules/.bun/get-east-asian-width@1.6.0/node_modules/get-east-asian-width/utilities.js
|
|
6630
|
+
var isInRange = (ranges, codePoint) => {
|
|
6631
|
+
let low = 0;
|
|
6632
|
+
let high = Math.floor(ranges.length / 2) - 1;
|
|
6633
|
+
while (low <= high) {
|
|
6634
|
+
const mid = Math.floor((low + high) / 2);
|
|
6635
|
+
const i = mid * 2;
|
|
6636
|
+
if (codePoint < ranges[i]) {
|
|
6637
|
+
high = mid - 1;
|
|
6638
|
+
} else if (codePoint > ranges[i + 1]) {
|
|
6639
|
+
low = mid + 1;
|
|
6640
|
+
} else {
|
|
6641
|
+
return true;
|
|
6642
|
+
}
|
|
6643
|
+
}
|
|
6644
|
+
return false;
|
|
6645
|
+
};
|
|
6646
|
+
|
|
6647
|
+
// ../../node_modules/.bun/get-east-asian-width@1.6.0/node_modules/get-east-asian-width/lookup.js
|
|
6648
|
+
var commonCjkCodePoint = 19968;
|
|
6649
|
+
var [wideFastPathStart, wideFastPathEnd] = /* @__PURE__ */ findWideFastPathRange(wideRanges);
|
|
6650
|
+
function findWideFastPathRange(ranges) {
|
|
6651
|
+
let fastPathStart = ranges[0];
|
|
6652
|
+
let fastPathEnd = ranges[1];
|
|
6653
|
+
for (let index = 0;index < ranges.length; index += 2) {
|
|
6654
|
+
const start = ranges[index];
|
|
6655
|
+
const end = ranges[index + 1];
|
|
6656
|
+
if (commonCjkCodePoint >= start && commonCjkCodePoint <= end) {
|
|
6657
|
+
return [start, end];
|
|
6658
|
+
}
|
|
6659
|
+
if (end - start > fastPathEnd - fastPathStart) {
|
|
6660
|
+
fastPathStart = start;
|
|
6661
|
+
fastPathEnd = end;
|
|
6662
|
+
}
|
|
6663
|
+
}
|
|
6664
|
+
return [fastPathStart, fastPathEnd];
|
|
6665
|
+
}
|
|
6666
|
+
var isAmbiguous = (codePoint) => {
|
|
6667
|
+
if (codePoint < ambiguousMinimalCodePoint || codePoint > ambiguousMaximumCodePoint) {
|
|
6668
|
+
return false;
|
|
6669
|
+
}
|
|
6670
|
+
return isInRange(ambiguousRanges, codePoint);
|
|
6671
|
+
};
|
|
6672
|
+
var isFullWidth = (codePoint) => {
|
|
6673
|
+
if (codePoint < fullwidthMinimalCodePoint || codePoint > fullwidthMaximumCodePoint) {
|
|
6674
|
+
return false;
|
|
6675
|
+
}
|
|
6676
|
+
return isInRange(fullwidthRanges, codePoint);
|
|
6677
|
+
};
|
|
6678
|
+
var isWide = (codePoint) => {
|
|
6679
|
+
if (codePoint >= wideFastPathStart && codePoint <= wideFastPathEnd) {
|
|
6680
|
+
return true;
|
|
6681
|
+
}
|
|
6682
|
+
if (codePoint < wideMinimalCodePoint || codePoint > wideMaximumCodePoint) {
|
|
6683
|
+
return false;
|
|
6684
|
+
}
|
|
6685
|
+
return isInRange(wideRanges, codePoint);
|
|
6686
|
+
};
|
|
6687
|
+
|
|
6688
|
+
// ../../node_modules/.bun/get-east-asian-width@1.6.0/node_modules/get-east-asian-width/index.js
|
|
6689
|
+
function validate(codePoint) {
|
|
6690
|
+
if (!Number.isSafeInteger(codePoint)) {
|
|
6691
|
+
throw new TypeError(`Expected a code point, got \`${typeof codePoint}\`.`);
|
|
6692
|
+
}
|
|
6693
|
+
}
|
|
6694
|
+
function eastAsianWidth(codePoint, { ambiguousAsWide = false } = {}) {
|
|
6695
|
+
validate(codePoint);
|
|
6696
|
+
if (isFullWidth(codePoint) || isWide(codePoint) || ambiguousAsWide && isAmbiguous(codePoint)) {
|
|
6697
|
+
return 2;
|
|
6698
|
+
}
|
|
6699
|
+
return 1;
|
|
6700
|
+
}
|
|
6701
|
+
|
|
6702
|
+
// ../../node_modules/.bun/@earendil-works+pi-tui@1.2.0/node_modules/@earendil-works/pi-tui/dist/utils.js
|
|
6703
|
+
var graphemeSegmenter = new Intl.Segmenter(undefined, { granularity: "grapheme" });
|
|
6704
|
+
var wordSegmenter = new Intl.Segmenter(undefined, { granularity: "word" });
|
|
6705
|
+
function getGraphemeSegmenter() {
|
|
6706
|
+
return graphemeSegmenter;
|
|
6707
|
+
}
|
|
6708
|
+
function getWordSegmenter() {
|
|
6709
|
+
return wordSegmenter;
|
|
6710
|
+
}
|
|
6711
|
+
function couldBeEmoji(segment) {
|
|
6712
|
+
const cp = segment.codePointAt(0);
|
|
6713
|
+
return cp >= 126976 && cp <= 130047 || cp >= 8960 && cp <= 9215 || cp >= 9728 && cp <= 10175 || cp >= 11088 && cp <= 11093 || segment.includes("️") || segment.length > 2;
|
|
6714
|
+
}
|
|
6715
|
+
var zeroWidthRegex = /^(?:\p{Default_Ignorable_Code_Point}|\p{Control}|\p{Mark}|\p{Surrogate})+$/v;
|
|
6716
|
+
var leadingNonPrintingRegex = /^[\p{Default_Ignorable_Code_Point}\p{Control}\p{Format}\p{Mark}\p{Surrogate}]+/v;
|
|
6717
|
+
var nonPrintingCharRegex = /^(?:\p{Default_Ignorable_Code_Point}|\p{Control}|\p{Format}|\p{Mark}|\p{Surrogate})$/v;
|
|
6718
|
+
var markCharRegex = /^\p{Mark}$/v;
|
|
6719
|
+
var terminalSpacingMarkRegex = /^(?:[\p{Spacing_Mark}--[\u1734\u302E\u302F]]|[\u065F\u0F7F\u102B\u102C\u1031\u1033-\u1035\u1038\u103A-\u103E])+$/v;
|
|
6720
|
+
var rgiEmojiRegex = /^\p{RGI_Emoji}$/v;
|
|
6721
|
+
var WIDTH_CACHE_SIZE = 512;
|
|
6722
|
+
var widthCache = new Map;
|
|
6723
|
+
var cjkBreakRegex = /[\p{Script_Extensions=Han}\p{Script_Extensions=Hiragana}\p{Script_Extensions=Katakana}\p{Script_Extensions=Hangul}\p{Script_Extensions=Bopomofo}]/u;
|
|
6724
|
+
var cjkPunctuationRegex = new RegExp(`(?:(?=\\p{Punctuation})${cjkBreakRegex.source}|[,.:;!?()[]{}“”‘’…—])`, "u");
|
|
6725
|
+
var autocompleteSeparatorRegex = new RegExp(`(?:\\s|${cjkPunctuationRegex.source})`, "u");
|
|
6726
|
+
var autocompleteBoundaryRegex = new RegExp(`(?:^|${autocompleteSeparatorRegex.source})`, "u");
|
|
6727
|
+
function isPrintableAscii(str) {
|
|
6728
|
+
for (let i = 0;i < str.length; i++) {
|
|
6729
|
+
const code = str.charCodeAt(i);
|
|
6730
|
+
if (code < 32 || code > 126) {
|
|
6731
|
+
return false;
|
|
6732
|
+
}
|
|
6733
|
+
}
|
|
6734
|
+
return true;
|
|
6735
|
+
}
|
|
6736
|
+
function truncateFragmentToWidth(text, maxWidth) {
|
|
6737
|
+
if (maxWidth <= 0 || text.length === 0) {
|
|
6738
|
+
return { text: "", width: 0 };
|
|
6739
|
+
}
|
|
6740
|
+
if (isPrintableAscii(text)) {
|
|
6741
|
+
const clipped = text.slice(0, maxWidth);
|
|
6742
|
+
return { text: clipped, width: clipped.length };
|
|
6743
|
+
}
|
|
6744
|
+
const hasAnsi = text.includes("\x1B");
|
|
6745
|
+
const hasTabs = text.includes("\t");
|
|
6746
|
+
if (!hasAnsi && !hasTabs) {
|
|
6747
|
+
let result = "";
|
|
6748
|
+
let width = 0;
|
|
6749
|
+
for (const { segment } of graphemeSegmenter.segment(text)) {
|
|
6750
|
+
const w = graphemeWidth(segment);
|
|
6751
|
+
if (width + w > maxWidth) {
|
|
6752
|
+
break;
|
|
6753
|
+
}
|
|
6754
|
+
result += segment;
|
|
6755
|
+
width += w;
|
|
6756
|
+
}
|
|
6757
|
+
return { text: result, width };
|
|
6758
|
+
}
|
|
6759
|
+
let result = "";
|
|
6760
|
+
let width = 0;
|
|
6761
|
+
let i = 0;
|
|
6762
|
+
let pendingAnsi = "";
|
|
6763
|
+
while (i < text.length) {
|
|
6764
|
+
const ansi = extractAnsiCode(text, i);
|
|
6765
|
+
if (ansi) {
|
|
6766
|
+
pendingAnsi += ansi.code;
|
|
6767
|
+
i += ansi.length;
|
|
6768
|
+
continue;
|
|
6769
|
+
}
|
|
6770
|
+
if (text[i] === "\t") {
|
|
6771
|
+
if (width + 3 > maxWidth) {
|
|
6772
|
+
break;
|
|
6773
|
+
}
|
|
6774
|
+
if (pendingAnsi) {
|
|
6775
|
+
result += pendingAnsi;
|
|
6776
|
+
pendingAnsi = "";
|
|
6777
|
+
}
|
|
6778
|
+
result += "\t";
|
|
6779
|
+
width += 3;
|
|
6780
|
+
i++;
|
|
6781
|
+
continue;
|
|
6782
|
+
}
|
|
6783
|
+
let end = i;
|
|
6784
|
+
while (end < text.length && text[end] !== "\t") {
|
|
6785
|
+
const nextAnsi = extractAnsiCode(text, end);
|
|
6786
|
+
if (nextAnsi) {
|
|
6787
|
+
break;
|
|
6788
|
+
}
|
|
6789
|
+
end++;
|
|
6790
|
+
}
|
|
6791
|
+
for (const { segment } of graphemeSegmenter.segment(text.slice(i, end))) {
|
|
6792
|
+
const w = graphemeWidth(segment);
|
|
6793
|
+
if (width + w > maxWidth) {
|
|
6794
|
+
return { text: result, width };
|
|
6795
|
+
}
|
|
6796
|
+
if (pendingAnsi) {
|
|
6797
|
+
result += pendingAnsi;
|
|
6798
|
+
pendingAnsi = "";
|
|
6799
|
+
}
|
|
6800
|
+
result += segment;
|
|
6801
|
+
width += w;
|
|
6802
|
+
}
|
|
6803
|
+
i = end;
|
|
6804
|
+
}
|
|
6805
|
+
return { text: result, width };
|
|
6806
|
+
}
|
|
6807
|
+
function finalizeTruncatedResult(prefix, prefixWidth, ellipsis, ellipsisWidth, maxWidth, pad) {
|
|
6808
|
+
const reset = "\x1B[0m";
|
|
6809
|
+
const hyperlinkClose = getActiveOsc8Close(prefix);
|
|
6810
|
+
const visibleWidth = prefixWidth + ellipsisWidth;
|
|
6811
|
+
let result;
|
|
6812
|
+
if (ellipsis.length > 0) {
|
|
6813
|
+
result = `${prefix}${hyperlinkClose}${reset}${ellipsis}${reset}`;
|
|
6814
|
+
} else {
|
|
6815
|
+
result = `${prefix}${hyperlinkClose}${reset}`;
|
|
6816
|
+
}
|
|
6817
|
+
return pad ? result + " ".repeat(Math.max(0, maxWidth - visibleWidth)) : result;
|
|
6818
|
+
}
|
|
6819
|
+
function graphemeWidth(segment) {
|
|
6820
|
+
if (segment.length === 1) {
|
|
6821
|
+
const code = segment.charCodeAt(0);
|
|
6822
|
+
if (code >= 32 && code <= 126)
|
|
6823
|
+
return 1;
|
|
6824
|
+
if (code === 9)
|
|
6825
|
+
return 3;
|
|
6826
|
+
}
|
|
6827
|
+
if (terminalSpacingMarkRegex.test(segment)) {
|
|
6828
|
+
return [...segment].length;
|
|
6829
|
+
}
|
|
6830
|
+
if (zeroWidthRegex.test(segment)) {
|
|
6831
|
+
return 0;
|
|
6832
|
+
}
|
|
6833
|
+
if (couldBeEmoji(segment) && rgiEmojiRegex.test(segment)) {
|
|
6834
|
+
return 2;
|
|
6835
|
+
}
|
|
6836
|
+
const base = segment.replace(leadingNonPrintingRegex, "");
|
|
6837
|
+
const cp = base.codePointAt(0);
|
|
6838
|
+
if (cp === undefined) {
|
|
6839
|
+
return 0;
|
|
6840
|
+
}
|
|
6841
|
+
if (cp >= 127462 && cp <= 127487) {
|
|
6842
|
+
return 2;
|
|
6843
|
+
}
|
|
6844
|
+
let width = eastAsianWidth(cp);
|
|
6845
|
+
let followsMark = false;
|
|
6846
|
+
const chars = [...base];
|
|
6847
|
+
for (const char of chars.slice(1)) {
|
|
6848
|
+
if (terminalSpacingMarkRegex.test(char)) {
|
|
6849
|
+
width += 1;
|
|
6850
|
+
followsMark = false;
|
|
6851
|
+
} else if (markCharRegex.test(char)) {
|
|
6852
|
+
followsMark = true;
|
|
6853
|
+
} else if (!nonPrintingCharRegex.test(char)) {
|
|
6854
|
+
const c = char.codePointAt(0);
|
|
6855
|
+
if (followsMark || c >= 65280 && c <= 65519) {
|
|
6856
|
+
width += eastAsianWidth(c);
|
|
6857
|
+
} else if (c === 3635 || c === 3763) {
|
|
6858
|
+
width += 1;
|
|
6859
|
+
}
|
|
6860
|
+
followsMark = false;
|
|
6861
|
+
}
|
|
6862
|
+
}
|
|
6863
|
+
return width;
|
|
6864
|
+
}
|
|
6865
|
+
function visibleWidth(str) {
|
|
6866
|
+
if (str.length === 0) {
|
|
6867
|
+
return 0;
|
|
6868
|
+
}
|
|
6869
|
+
const asciiWidth = asciiVisibleWidth(str);
|
|
6870
|
+
if (asciiWidth !== -1) {
|
|
6871
|
+
return asciiWidth;
|
|
6872
|
+
}
|
|
6873
|
+
const cached = widthCache.get(str);
|
|
6874
|
+
if (cached !== undefined) {
|
|
6875
|
+
return cached;
|
|
6876
|
+
}
|
|
6877
|
+
let clean = str;
|
|
6878
|
+
if (str.includes("\t")) {
|
|
6879
|
+
clean = clean.replace(/\t/g, " ");
|
|
6880
|
+
}
|
|
6881
|
+
let escapeIndex = clean.indexOf("\x1B");
|
|
6882
|
+
if (escapeIndex !== -1) {
|
|
6883
|
+
let stripped = "";
|
|
6884
|
+
let copyFrom = 0;
|
|
6885
|
+
while (escapeIndex !== -1) {
|
|
6886
|
+
const length = ansiCodeLength(clean, escapeIndex);
|
|
6887
|
+
if (length > 0) {
|
|
6888
|
+
stripped += clean.slice(copyFrom, escapeIndex);
|
|
6889
|
+
escapeIndex += length;
|
|
6890
|
+
copyFrom = escapeIndex;
|
|
6891
|
+
} else {
|
|
6892
|
+
escapeIndex++;
|
|
6893
|
+
}
|
|
6894
|
+
escapeIndex = clean.indexOf("\x1B", escapeIndex);
|
|
6895
|
+
}
|
|
6896
|
+
clean = stripped + clean.slice(copyFrom);
|
|
6897
|
+
}
|
|
6898
|
+
let width = 0;
|
|
6899
|
+
for (const { segment } of graphemeSegmenter.segment(clean)) {
|
|
6900
|
+
width += graphemeWidth(segment);
|
|
6901
|
+
}
|
|
6902
|
+
if (widthCache.size >= WIDTH_CACHE_SIZE) {
|
|
6903
|
+
const firstKey = widthCache.keys().next().value;
|
|
6904
|
+
if (firstKey !== undefined) {
|
|
6905
|
+
widthCache.delete(firstKey);
|
|
6906
|
+
}
|
|
6907
|
+
}
|
|
6908
|
+
widthCache.set(str, width);
|
|
6909
|
+
return width;
|
|
6910
|
+
}
|
|
6911
|
+
function extractAnsiCode(str, pos) {
|
|
6912
|
+
const length = ansiCodeLength(str, pos);
|
|
6913
|
+
return length > 0 ? { code: str.substring(pos, pos + length), length } : null;
|
|
6914
|
+
}
|
|
6915
|
+
function asciiVisibleWidth(str) {
|
|
6916
|
+
let width = 0;
|
|
6917
|
+
let i = 0;
|
|
6918
|
+
while (i < str.length) {
|
|
6919
|
+
const code = str.charCodeAt(i);
|
|
6920
|
+
if (code >= 32 && code <= 126) {
|
|
6921
|
+
width++;
|
|
6922
|
+
i++;
|
|
6923
|
+
} else if (code === 9) {
|
|
6924
|
+
width += 3;
|
|
6925
|
+
i++;
|
|
6926
|
+
} else if (code === 27) {
|
|
6927
|
+
const length = ansiCodeLength(str, i);
|
|
6928
|
+
if (length === 0)
|
|
6929
|
+
return -1;
|
|
6930
|
+
i += length;
|
|
6931
|
+
} else {
|
|
6932
|
+
return -1;
|
|
6933
|
+
}
|
|
6934
|
+
}
|
|
6935
|
+
return width;
|
|
6936
|
+
}
|
|
6937
|
+
function ansiCodeLength(str, pos) {
|
|
6938
|
+
if (pos >= str.length || str.charCodeAt(pos) !== 27)
|
|
6939
|
+
return 0;
|
|
6940
|
+
const next = str[pos + 1];
|
|
6941
|
+
if (next === "[") {
|
|
6942
|
+
for (let j = pos + 2;j < str.length; j++) {
|
|
6943
|
+
const c = str.charCodeAt(j);
|
|
6944
|
+
if (c === 109 || c === 71 || c === 75 || c === 72 || c === 74)
|
|
6945
|
+
return j + 1 - pos;
|
|
6946
|
+
}
|
|
6947
|
+
return 0;
|
|
6948
|
+
}
|
|
6949
|
+
if (next === "]" || next === "_") {
|
|
6950
|
+
for (let j = pos + 2;j < str.length; j++) {
|
|
6951
|
+
const c = str.charCodeAt(j);
|
|
6952
|
+
if (c === 7)
|
|
6953
|
+
return j + 1 - pos;
|
|
6954
|
+
if (c === 27 && str[j + 1] === "\\")
|
|
6955
|
+
return j + 2 - pos;
|
|
6956
|
+
}
|
|
6957
|
+
return 0;
|
|
6958
|
+
}
|
|
6959
|
+
return 0;
|
|
6960
|
+
}
|
|
6961
|
+
function parseOsc8Hyperlink(ansiCode) {
|
|
6962
|
+
if (!ansiCode.startsWith("\x1B]8;")) {
|
|
6963
|
+
return;
|
|
6964
|
+
}
|
|
6965
|
+
const terminator = ansiCode.endsWith("\x07") ? "\x07" : "\x1B\\";
|
|
6966
|
+
const body = ansiCode.slice(4, terminator === "\x07" ? -1 : -2);
|
|
6967
|
+
const separatorIndex = body.indexOf(";");
|
|
6968
|
+
if (separatorIndex === -1) {
|
|
6969
|
+
return;
|
|
6970
|
+
}
|
|
6971
|
+
const params = body.slice(0, separatorIndex);
|
|
6972
|
+
const url = body.slice(separatorIndex + 1);
|
|
6973
|
+
if (!url) {
|
|
6974
|
+
return null;
|
|
6975
|
+
}
|
|
6976
|
+
return { params, url, terminator };
|
|
6977
|
+
}
|
|
6978
|
+
function formatOsc8Hyperlink(hyperlink) {
|
|
6979
|
+
return `\x1B]8;${hyperlink.params};${hyperlink.url}${hyperlink.terminator}`;
|
|
6980
|
+
}
|
|
6981
|
+
function formatOsc8Close(terminator) {
|
|
6982
|
+
return `\x1B]8;;${terminator}`;
|
|
6983
|
+
}
|
|
6984
|
+
function getActiveOsc8Close(prefix) {
|
|
6985
|
+
if (!prefix.includes("\x1B]8;")) {
|
|
6986
|
+
return "";
|
|
6987
|
+
}
|
|
6988
|
+
let activeHyperlink = null;
|
|
6989
|
+
let i = 0;
|
|
6990
|
+
while (i < prefix.length) {
|
|
6991
|
+
const ansi = extractAnsiCode(prefix, i);
|
|
6992
|
+
if (ansi) {
|
|
6993
|
+
const hyperlink = parseOsc8Hyperlink(ansi.code);
|
|
6994
|
+
if (hyperlink !== undefined) {
|
|
6995
|
+
activeHyperlink = hyperlink;
|
|
6996
|
+
}
|
|
6997
|
+
i += ansi.length;
|
|
6998
|
+
} else {
|
|
6999
|
+
i++;
|
|
7000
|
+
}
|
|
7001
|
+
}
|
|
7002
|
+
return activeHyperlink ? formatOsc8Close(activeHyperlink.terminator) : "";
|
|
7003
|
+
}
|
|
7004
|
+
|
|
7005
|
+
class AnsiCodeTracker {
|
|
7006
|
+
bold = false;
|
|
7007
|
+
dim = false;
|
|
7008
|
+
italic = false;
|
|
7009
|
+
underline = false;
|
|
7010
|
+
blink = false;
|
|
7011
|
+
inverse = false;
|
|
7012
|
+
hidden = false;
|
|
7013
|
+
strikethrough = false;
|
|
7014
|
+
fgColor = null;
|
|
7015
|
+
bgColor = null;
|
|
7016
|
+
activeHyperlink = null;
|
|
7017
|
+
process(ansiCode) {
|
|
7018
|
+
const hyperlink = parseOsc8Hyperlink(ansiCode);
|
|
7019
|
+
if (hyperlink !== undefined) {
|
|
7020
|
+
this.activeHyperlink = hyperlink;
|
|
7021
|
+
return;
|
|
7022
|
+
}
|
|
7023
|
+
if (!ansiCode.endsWith("m")) {
|
|
7024
|
+
return;
|
|
7025
|
+
}
|
|
7026
|
+
const match = ansiCode.match(/\x1b\[([\d;]*)m/);
|
|
7027
|
+
if (!match)
|
|
7028
|
+
return;
|
|
7029
|
+
const params = match[1];
|
|
7030
|
+
if (params === "" || params === "0") {
|
|
7031
|
+
this.reset();
|
|
7032
|
+
return;
|
|
7033
|
+
}
|
|
7034
|
+
const parts = params.split(";");
|
|
7035
|
+
let i = 0;
|
|
7036
|
+
while (i < parts.length) {
|
|
7037
|
+
const code = Number.parseInt(parts[i], 10);
|
|
7038
|
+
if (code === 38 || code === 48) {
|
|
7039
|
+
if (parts[i + 1] === "5" && parts[i + 2] !== undefined) {
|
|
7040
|
+
const colorCode = `${parts[i]};${parts[i + 1]};${parts[i + 2]}`;
|
|
7041
|
+
if (code === 38) {
|
|
7042
|
+
this.fgColor = colorCode;
|
|
7043
|
+
} else {
|
|
7044
|
+
this.bgColor = colorCode;
|
|
7045
|
+
}
|
|
7046
|
+
i += 3;
|
|
7047
|
+
continue;
|
|
7048
|
+
} else if (parts[i + 1] === "2" && parts[i + 4] !== undefined) {
|
|
7049
|
+
const colorCode = `${parts[i]};${parts[i + 1]};${parts[i + 2]};${parts[i + 3]};${parts[i + 4]}`;
|
|
7050
|
+
if (code === 38) {
|
|
7051
|
+
this.fgColor = colorCode;
|
|
7052
|
+
} else {
|
|
7053
|
+
this.bgColor = colorCode;
|
|
7054
|
+
}
|
|
7055
|
+
i += 5;
|
|
7056
|
+
continue;
|
|
7057
|
+
}
|
|
7058
|
+
}
|
|
7059
|
+
switch (code) {
|
|
7060
|
+
case 0:
|
|
7061
|
+
this.reset();
|
|
7062
|
+
break;
|
|
7063
|
+
case 1:
|
|
7064
|
+
this.bold = true;
|
|
7065
|
+
break;
|
|
7066
|
+
case 2:
|
|
7067
|
+
this.dim = true;
|
|
7068
|
+
break;
|
|
7069
|
+
case 3:
|
|
7070
|
+
this.italic = true;
|
|
7071
|
+
break;
|
|
7072
|
+
case 4:
|
|
7073
|
+
this.underline = true;
|
|
7074
|
+
break;
|
|
7075
|
+
case 5:
|
|
7076
|
+
this.blink = true;
|
|
7077
|
+
break;
|
|
7078
|
+
case 7:
|
|
7079
|
+
this.inverse = true;
|
|
7080
|
+
break;
|
|
7081
|
+
case 8:
|
|
7082
|
+
this.hidden = true;
|
|
7083
|
+
break;
|
|
7084
|
+
case 9:
|
|
7085
|
+
this.strikethrough = true;
|
|
7086
|
+
break;
|
|
7087
|
+
case 21:
|
|
7088
|
+
this.bold = false;
|
|
7089
|
+
break;
|
|
7090
|
+
case 22:
|
|
7091
|
+
this.bold = false;
|
|
7092
|
+
this.dim = false;
|
|
7093
|
+
break;
|
|
7094
|
+
case 23:
|
|
7095
|
+
this.italic = false;
|
|
7096
|
+
break;
|
|
7097
|
+
case 24:
|
|
7098
|
+
this.underline = false;
|
|
7099
|
+
break;
|
|
7100
|
+
case 25:
|
|
7101
|
+
this.blink = false;
|
|
7102
|
+
break;
|
|
7103
|
+
case 27:
|
|
7104
|
+
this.inverse = false;
|
|
7105
|
+
break;
|
|
7106
|
+
case 28:
|
|
7107
|
+
this.hidden = false;
|
|
7108
|
+
break;
|
|
7109
|
+
case 29:
|
|
7110
|
+
this.strikethrough = false;
|
|
7111
|
+
break;
|
|
7112
|
+
case 39:
|
|
7113
|
+
this.fgColor = null;
|
|
7114
|
+
break;
|
|
7115
|
+
case 49:
|
|
7116
|
+
this.bgColor = null;
|
|
7117
|
+
break;
|
|
7118
|
+
default:
|
|
7119
|
+
if (code >= 30 && code <= 37 || code >= 90 && code <= 97) {
|
|
7120
|
+
this.fgColor = String(code);
|
|
7121
|
+
} else if (code >= 40 && code <= 47 || code >= 100 && code <= 107) {
|
|
7122
|
+
this.bgColor = String(code);
|
|
7123
|
+
}
|
|
7124
|
+
break;
|
|
7125
|
+
}
|
|
7126
|
+
i++;
|
|
7127
|
+
}
|
|
7128
|
+
}
|
|
7129
|
+
reset() {
|
|
7130
|
+
this.bold = false;
|
|
7131
|
+
this.dim = false;
|
|
7132
|
+
this.italic = false;
|
|
7133
|
+
this.underline = false;
|
|
7134
|
+
this.blink = false;
|
|
7135
|
+
this.inverse = false;
|
|
7136
|
+
this.hidden = false;
|
|
7137
|
+
this.strikethrough = false;
|
|
7138
|
+
this.fgColor = null;
|
|
7139
|
+
this.bgColor = null;
|
|
7140
|
+
}
|
|
7141
|
+
clear() {
|
|
7142
|
+
this.reset();
|
|
7143
|
+
this.activeHyperlink = null;
|
|
7144
|
+
}
|
|
7145
|
+
getActiveCodes() {
|
|
7146
|
+
const codes = [];
|
|
7147
|
+
if (this.bold)
|
|
7148
|
+
codes.push("1");
|
|
7149
|
+
if (this.dim)
|
|
7150
|
+
codes.push("2");
|
|
7151
|
+
if (this.italic)
|
|
7152
|
+
codes.push("3");
|
|
7153
|
+
if (this.underline)
|
|
7154
|
+
codes.push("4");
|
|
7155
|
+
if (this.blink)
|
|
7156
|
+
codes.push("5");
|
|
7157
|
+
if (this.inverse)
|
|
7158
|
+
codes.push("7");
|
|
7159
|
+
if (this.hidden)
|
|
7160
|
+
codes.push("8");
|
|
7161
|
+
if (this.strikethrough)
|
|
7162
|
+
codes.push("9");
|
|
7163
|
+
if (this.fgColor)
|
|
7164
|
+
codes.push(this.fgColor);
|
|
7165
|
+
if (this.bgColor)
|
|
7166
|
+
codes.push(this.bgColor);
|
|
7167
|
+
let result = codes.length > 0 ? `\x1B[${codes.join(";")}m` : "";
|
|
7168
|
+
if (this.activeHyperlink) {
|
|
7169
|
+
result += formatOsc8Hyperlink(this.activeHyperlink);
|
|
7170
|
+
}
|
|
7171
|
+
return result;
|
|
7172
|
+
}
|
|
7173
|
+
getActiveBackgroundCode() {
|
|
7174
|
+
return this.bgColor ? `\x1B[${this.bgColor}m` : "";
|
|
7175
|
+
}
|
|
7176
|
+
hasActiveCodes() {
|
|
7177
|
+
return this.bold || this.dim || this.italic || this.underline || this.blink || this.inverse || this.hidden || this.strikethrough || this.fgColor !== null || this.bgColor !== null || this.activeHyperlink !== null;
|
|
7178
|
+
}
|
|
7179
|
+
getLineEndReset() {
|
|
7180
|
+
let result = "";
|
|
7181
|
+
if (this.underline) {
|
|
7182
|
+
result += "\x1B[24m";
|
|
7183
|
+
}
|
|
7184
|
+
if (this.activeHyperlink) {
|
|
7185
|
+
result += formatOsc8Close(this.activeHyperlink.terminator);
|
|
7186
|
+
}
|
|
7187
|
+
return result;
|
|
7188
|
+
}
|
|
7189
|
+
}
|
|
7190
|
+
function truncateToWidth(text, maxWidth, ellipsis = "...", pad = false) {
|
|
7191
|
+
if (maxWidth <= 0) {
|
|
7192
|
+
return "";
|
|
7193
|
+
}
|
|
7194
|
+
if (text.length === 0) {
|
|
7195
|
+
return pad ? " ".repeat(maxWidth) : "";
|
|
7196
|
+
}
|
|
7197
|
+
const ellipsisWidth = visibleWidth(ellipsis);
|
|
7198
|
+
if (ellipsisWidth >= maxWidth) {
|
|
7199
|
+
const textWidth = visibleWidth(text);
|
|
7200
|
+
if (textWidth <= maxWidth) {
|
|
7201
|
+
return pad ? text + " ".repeat(maxWidth - textWidth) : text;
|
|
7202
|
+
}
|
|
7203
|
+
const clippedEllipsis = truncateFragmentToWidth(ellipsis, maxWidth);
|
|
7204
|
+
if (clippedEllipsis.width === 0) {
|
|
7205
|
+
return pad ? " ".repeat(maxWidth) : "";
|
|
7206
|
+
}
|
|
7207
|
+
return finalizeTruncatedResult("", 0, clippedEllipsis.text, clippedEllipsis.width, maxWidth, pad);
|
|
7208
|
+
}
|
|
7209
|
+
if (isPrintableAscii(text)) {
|
|
7210
|
+
if (text.length <= maxWidth) {
|
|
7211
|
+
return pad ? text + " ".repeat(maxWidth - text.length) : text;
|
|
7212
|
+
}
|
|
7213
|
+
const targetWidth = maxWidth - ellipsisWidth;
|
|
7214
|
+
return finalizeTruncatedResult(text.slice(0, targetWidth), targetWidth, ellipsis, ellipsisWidth, maxWidth, pad);
|
|
7215
|
+
}
|
|
7216
|
+
const targetWidth = maxWidth - ellipsisWidth;
|
|
7217
|
+
let result = "";
|
|
7218
|
+
let pendingAnsi = "";
|
|
7219
|
+
let visibleSoFar = 0;
|
|
7220
|
+
let keptWidth = 0;
|
|
7221
|
+
let keepContiguousPrefix = true;
|
|
7222
|
+
let overflowed = false;
|
|
7223
|
+
let exhaustedInput = false;
|
|
7224
|
+
const hasAnsi = text.includes("\x1B");
|
|
7225
|
+
const hasTabs = text.includes("\t");
|
|
7226
|
+
if (!hasAnsi && !hasTabs) {
|
|
7227
|
+
for (const { segment } of graphemeSegmenter.segment(text)) {
|
|
7228
|
+
const width = graphemeWidth(segment);
|
|
7229
|
+
if (keepContiguousPrefix && keptWidth + width <= targetWidth) {
|
|
7230
|
+
result += segment;
|
|
7231
|
+
keptWidth += width;
|
|
7232
|
+
} else {
|
|
7233
|
+
keepContiguousPrefix = false;
|
|
7234
|
+
}
|
|
7235
|
+
visibleSoFar += width;
|
|
7236
|
+
if (visibleSoFar > maxWidth) {
|
|
7237
|
+
overflowed = true;
|
|
7238
|
+
break;
|
|
7239
|
+
}
|
|
7240
|
+
}
|
|
7241
|
+
exhaustedInput = !overflowed;
|
|
7242
|
+
} else {
|
|
7243
|
+
let i = 0;
|
|
7244
|
+
while (i < text.length) {
|
|
7245
|
+
const ansi = extractAnsiCode(text, i);
|
|
7246
|
+
if (ansi) {
|
|
7247
|
+
pendingAnsi += ansi.code;
|
|
7248
|
+
i += ansi.length;
|
|
7249
|
+
continue;
|
|
7250
|
+
}
|
|
7251
|
+
if (text[i] === "\t") {
|
|
7252
|
+
if (keepContiguousPrefix && keptWidth + 3 <= targetWidth) {
|
|
7253
|
+
if (pendingAnsi) {
|
|
7254
|
+
result += pendingAnsi;
|
|
7255
|
+
pendingAnsi = "";
|
|
7256
|
+
}
|
|
7257
|
+
result += "\t";
|
|
7258
|
+
keptWidth += 3;
|
|
7259
|
+
} else {
|
|
7260
|
+
keepContiguousPrefix = false;
|
|
7261
|
+
pendingAnsi = "";
|
|
7262
|
+
}
|
|
7263
|
+
visibleSoFar += 3;
|
|
7264
|
+
if (visibleSoFar > maxWidth) {
|
|
7265
|
+
overflowed = true;
|
|
7266
|
+
break;
|
|
7267
|
+
}
|
|
7268
|
+
i++;
|
|
7269
|
+
continue;
|
|
7270
|
+
}
|
|
7271
|
+
let end = i;
|
|
7272
|
+
while (end < text.length && text[end] !== "\t") {
|
|
7273
|
+
const nextAnsi = extractAnsiCode(text, end);
|
|
7274
|
+
if (nextAnsi) {
|
|
7275
|
+
break;
|
|
7276
|
+
}
|
|
7277
|
+
end++;
|
|
7278
|
+
}
|
|
7279
|
+
for (const { segment } of graphemeSegmenter.segment(text.slice(i, end))) {
|
|
7280
|
+
const width = graphemeWidth(segment);
|
|
7281
|
+
if (keepContiguousPrefix && keptWidth + width <= targetWidth) {
|
|
7282
|
+
if (pendingAnsi) {
|
|
7283
|
+
result += pendingAnsi;
|
|
7284
|
+
pendingAnsi = "";
|
|
7285
|
+
}
|
|
7286
|
+
result += segment;
|
|
7287
|
+
keptWidth += width;
|
|
7288
|
+
} else {
|
|
7289
|
+
keepContiguousPrefix = false;
|
|
7290
|
+
pendingAnsi = "";
|
|
7291
|
+
}
|
|
7292
|
+
visibleSoFar += width;
|
|
7293
|
+
if (visibleSoFar > maxWidth) {
|
|
7294
|
+
overflowed = true;
|
|
7295
|
+
break;
|
|
7296
|
+
}
|
|
7297
|
+
}
|
|
7298
|
+
if (overflowed) {
|
|
7299
|
+
break;
|
|
7300
|
+
}
|
|
7301
|
+
i = end;
|
|
7302
|
+
}
|
|
7303
|
+
exhaustedInput = i >= text.length;
|
|
7304
|
+
}
|
|
7305
|
+
if (!overflowed && exhaustedInput) {
|
|
7306
|
+
return pad ? text + " ".repeat(Math.max(0, maxWidth - visibleSoFar)) : text;
|
|
7307
|
+
}
|
|
7308
|
+
return finalizeTruncatedResult(result, keptWidth, ellipsis, ellipsisWidth, maxWidth, pad);
|
|
7309
|
+
}
|
|
7310
|
+
var pooledStyleTracker = new AnsiCodeTracker;
|
|
7311
|
+
|
|
7312
|
+
// ../../node_modules/.bun/@earendil-works+pi-tui@1.2.0/node_modules/@earendil-works/pi-tui/dist/autocomplete.js
|
|
7313
|
+
var PATH_DELIMITERS = new Set([" ", "\t", '"', "'", "="]);
|
|
7314
|
+
var tokenStartRegex = new RegExp(`${autocompleteBoundaryRegex.source}$`, "u");
|
|
7315
|
+
// ../../node_modules/.bun/@earendil-works+pi-tui@1.2.0/node_modules/@earendil-works/pi-tui/dist/oklab.js
|
|
7316
|
+
var K1 = 0.206;
|
|
7317
|
+
var K2 = 0.03;
|
|
7318
|
+
var K3 = (1 + K1) / (1 + K2);
|
|
7319
|
+
|
|
7320
|
+
// ../../node_modules/.bun/@earendil-works+pi-tui@1.2.0/node_modules/@earendil-works/pi-tui/dist/colors.js
|
|
7321
|
+
var NUMBER_PATTERN = String.raw`[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?`;
|
|
7322
|
+
var OKLCH_PATTERN = new RegExp(`^oklch\\(\\s*(${NUMBER_PATTERN})(%)?\\s+(${NUMBER_PATTERN})\\s+(${NUMBER_PATTERN})(?:deg)?\\s*\\)$`, "i");
|
|
7323
|
+
var OKHSL_PATTERN = new RegExp(`^okhsl\\(\\s*(${NUMBER_PATTERN})(?:deg)?\\s+(${NUMBER_PATTERN})(%)?\\s+(${NUMBER_PATTERN})(%)?\\s*\\)$`, "i");
|
|
7324
|
+
var GRAY_VALUES = Array.from({ length: 24 }, (_, index) => 8 + index * 10);
|
|
7325
|
+
// ../../node_modules/.bun/@earendil-works+pi-tui@1.2.0/node_modules/@earendil-works/pi-tui/dist/keys.js
|
|
7326
|
+
var SYMBOL_KEYS = new Set([
|
|
7327
|
+
"`",
|
|
7328
|
+
"-",
|
|
7329
|
+
"=",
|
|
7330
|
+
"[",
|
|
7331
|
+
"]",
|
|
7332
|
+
"\\",
|
|
7333
|
+
";",
|
|
7334
|
+
"'",
|
|
7335
|
+
",",
|
|
7336
|
+
".",
|
|
7337
|
+
"/",
|
|
7338
|
+
"!",
|
|
7339
|
+
"@",
|
|
7340
|
+
"#",
|
|
7341
|
+
"$",
|
|
7342
|
+
"%",
|
|
7343
|
+
"^",
|
|
7344
|
+
"&",
|
|
7345
|
+
"*",
|
|
7346
|
+
"(",
|
|
7347
|
+
")",
|
|
7348
|
+
"_",
|
|
7349
|
+
"+",
|
|
7350
|
+
"|",
|
|
7351
|
+
"~",
|
|
7352
|
+
"{",
|
|
7353
|
+
"}",
|
|
7354
|
+
":",
|
|
7355
|
+
"<",
|
|
7356
|
+
">",
|
|
7357
|
+
"?"
|
|
7358
|
+
]);
|
|
7359
|
+
var SHIFTED_SYMBOL_KEYS = new Set("~!@#$%^&*()_+|{}:<>?");
|
|
7360
|
+
var MODIFIERS = {
|
|
7361
|
+
shift: 1,
|
|
7362
|
+
alt: 2,
|
|
7363
|
+
ctrl: 4,
|
|
7364
|
+
super: 8
|
|
7365
|
+
};
|
|
7366
|
+
var LOCK_MASK = 64 + 128;
|
|
7367
|
+
var ARROW_CODEPOINTS = {
|
|
7368
|
+
up: -1,
|
|
7369
|
+
down: -2,
|
|
7370
|
+
right: -3,
|
|
7371
|
+
left: -4
|
|
7372
|
+
};
|
|
7373
|
+
var FUNCTIONAL_CODEPOINTS = {
|
|
7374
|
+
delete: -10,
|
|
7375
|
+
insert: -11,
|
|
7376
|
+
pageUp: -12,
|
|
7377
|
+
pageDown: -13,
|
|
7378
|
+
home: -14,
|
|
7379
|
+
end: -15
|
|
7380
|
+
};
|
|
7381
|
+
var KITTY_FUNCTIONAL_KEY_EQUIVALENTS = new Map([
|
|
7382
|
+
[57399, 48],
|
|
7383
|
+
[57400, 49],
|
|
7384
|
+
[57401, 50],
|
|
7385
|
+
[57402, 51],
|
|
7386
|
+
[57403, 52],
|
|
7387
|
+
[57404, 53],
|
|
7388
|
+
[57405, 54],
|
|
7389
|
+
[57406, 55],
|
|
7390
|
+
[57407, 56],
|
|
7391
|
+
[57408, 57],
|
|
7392
|
+
[57409, 46],
|
|
7393
|
+
[57410, 47],
|
|
7394
|
+
[57411, 42],
|
|
7395
|
+
[57412, 45],
|
|
7396
|
+
[57413, 43],
|
|
7397
|
+
[57415, 61],
|
|
7398
|
+
[57416, 44],
|
|
7399
|
+
[57417, ARROW_CODEPOINTS.left],
|
|
7400
|
+
[57418, ARROW_CODEPOINTS.right],
|
|
7401
|
+
[57419, ARROW_CODEPOINTS.up],
|
|
7402
|
+
[57420, ARROW_CODEPOINTS.down],
|
|
7403
|
+
[57421, FUNCTIONAL_CODEPOINTS.pageUp],
|
|
7404
|
+
[57422, FUNCTIONAL_CODEPOINTS.pageDown],
|
|
7405
|
+
[57423, FUNCTIONAL_CODEPOINTS.home],
|
|
7406
|
+
[57424, FUNCTIONAL_CODEPOINTS.end],
|
|
7407
|
+
[57425, FUNCTIONAL_CODEPOINTS.insert],
|
|
7408
|
+
[57426, FUNCTIONAL_CODEPOINTS.delete]
|
|
7409
|
+
]);
|
|
7410
|
+
var KITTY_PRINTABLE_ALLOWED_MODIFIERS = MODIFIERS.shift | LOCK_MASK;
|
|
7411
|
+
|
|
7412
|
+
// ../../node_modules/.bun/@earendil-works+pi-tui@1.2.0/node_modules/@earendil-works/pi-tui/dist/terminal-image.js
|
|
7413
|
+
var kittyImageMetadata = new Map;
|
|
7414
|
+
var KITTY_PLACEMENT_CONTROL_KEYS = new Set([
|
|
7415
|
+
"i",
|
|
7416
|
+
"p",
|
|
7417
|
+
"x",
|
|
7418
|
+
"y",
|
|
7419
|
+
"w",
|
|
7420
|
+
"h",
|
|
7421
|
+
"X",
|
|
7422
|
+
"Y",
|
|
7423
|
+
"c",
|
|
7424
|
+
"r",
|
|
7425
|
+
"C",
|
|
7426
|
+
"U",
|
|
7427
|
+
"z",
|
|
7428
|
+
"P",
|
|
7429
|
+
"Q",
|
|
7430
|
+
"H",
|
|
7431
|
+
"V"
|
|
7432
|
+
]);
|
|
7433
|
+
|
|
7434
|
+
// ../../node_modules/.bun/@earendil-works+pi-tui@1.2.0/node_modules/@earendil-works/pi-tui/dist/tui.js
|
|
7435
|
+
var TERMINAL_PALETTE_SIZE = 16;
|
|
7436
|
+
var TERMINAL_COLOR_REPLY_COUNT = 2 + TERMINAL_PALETTE_SIZE;
|
|
7437
|
+
var TERMINAL_COLOR_QUERY = `\x1B]10;?\x07\x1B]11;?\x07${Array.from({ length: TERMINAL_PALETTE_SIZE }, (_, index) => `\x1B]4;${index};?\x07`).join("")}\x1B[c`;
|
|
7438
|
+
var VIEWPORT_TUI = Symbol.for("@earendil-works/pi-tui/viewport");
|
|
7439
|
+
// ../../node_modules/.bun/@earendil-works+pi-tui@1.2.0/node_modules/@earendil-works/pi-tui/dist/word-navigation.js
|
|
7440
|
+
var wordSegmenter2 = getWordSegmenter();
|
|
7441
|
+
|
|
7442
|
+
// ../../node_modules/.bun/@earendil-works+pi-tui@1.2.0/node_modules/@earendil-works/pi-tui/dist/components/editor.js
|
|
7443
|
+
var graphemeSegmenter2 = getGraphemeSegmenter();
|
|
7444
|
+
var wordSegmenter3 = getWordSegmenter();
|
|
7445
|
+
var unquotedAutocompleteSuffixRegex = new RegExp(`(?:(?!${autocompleteSeparatorRegex.source}).)*`, "u");
|
|
7446
|
+
var autocompleteTokenStartSource = `${autocompleteBoundaryRegex.source}[([{<\`]*`;
|
|
7447
|
+
// ../../node_modules/.bun/@earendil-works+pi-tui@1.2.0/node_modules/@earendil-works/pi-tui/dist/layout-node.js
|
|
7448
|
+
var LAYOUT_NODE = Symbol.for("@earendil-works/pi-tui/layout-node");
|
|
7449
|
+
// ../../node_modules/.bun/@earendil-works+pi-tui@1.2.0/node_modules/@earendil-works/pi-tui/dist/components/image.js
|
|
7450
|
+
var pngCache = new Map;
|
|
7451
|
+
// ../../node_modules/.bun/@earendil-works+pi-tui@1.2.0/node_modules/@earendil-works/pi-tui/dist/components/input.js
|
|
7452
|
+
var segmenter = getGraphemeSegmenter();
|
|
7453
|
+
// ../../node_modules/.bun/@earendil-works+pi-tui@1.2.0/node_modules/@earendil-works/pi-tui/dist/latex.js
|
|
7454
|
+
var NAMED_OPERATORS = new Set([
|
|
7455
|
+
"arccos",
|
|
7456
|
+
"arcsin",
|
|
7457
|
+
"arctan",
|
|
7458
|
+
"arg",
|
|
7459
|
+
"cos",
|
|
7460
|
+
"cosh",
|
|
7461
|
+
"cot",
|
|
7462
|
+
"coth",
|
|
7463
|
+
"csc",
|
|
7464
|
+
"deg",
|
|
7465
|
+
"det",
|
|
7466
|
+
"dim",
|
|
7467
|
+
"exp",
|
|
7468
|
+
"gcd",
|
|
7469
|
+
"hom",
|
|
7470
|
+
"inf",
|
|
7471
|
+
"ker",
|
|
7472
|
+
"lg",
|
|
7473
|
+
"lim",
|
|
7474
|
+
"liminf",
|
|
7475
|
+
"limsup",
|
|
7476
|
+
"ln",
|
|
7477
|
+
"log",
|
|
7478
|
+
"max",
|
|
7479
|
+
"min",
|
|
7480
|
+
"Pr",
|
|
7481
|
+
"sec",
|
|
7482
|
+
"sin",
|
|
7483
|
+
"sinh",
|
|
7484
|
+
"sup",
|
|
7485
|
+
"tan",
|
|
7486
|
+
"tanh"
|
|
7487
|
+
]);
|
|
7488
|
+
var LIMIT_OPERATORS = new Set([
|
|
7489
|
+
"argmax",
|
|
7490
|
+
"argmin",
|
|
7491
|
+
"inf",
|
|
7492
|
+
"injlim",
|
|
7493
|
+
"lim",
|
|
7494
|
+
"liminf",
|
|
7495
|
+
"limsup",
|
|
7496
|
+
"max",
|
|
7497
|
+
"min",
|
|
7498
|
+
"projlim",
|
|
7499
|
+
"sup"
|
|
7500
|
+
]);
|
|
7501
|
+
var DISPLAY_LIMIT_SYMBOLS = new Set([
|
|
7502
|
+
"bigcap",
|
|
7503
|
+
"bigcup",
|
|
7504
|
+
"bigodot",
|
|
7505
|
+
"bigoplus",
|
|
7506
|
+
"bigotimes",
|
|
7507
|
+
"bigsqcup",
|
|
7508
|
+
"biguplus",
|
|
7509
|
+
"bigvee",
|
|
7510
|
+
"bigwedge",
|
|
7511
|
+
"coprod",
|
|
7512
|
+
"int",
|
|
7513
|
+
"iint",
|
|
7514
|
+
"iiint",
|
|
7515
|
+
"oint",
|
|
7516
|
+
"prod",
|
|
7517
|
+
"sum"
|
|
7518
|
+
]);
|
|
7519
|
+
var RELATION_COMMANDS = new Set([
|
|
7520
|
+
"Leftarrow",
|
|
7521
|
+
"Leftrightarrow",
|
|
7522
|
+
"Longleftarrow",
|
|
7523
|
+
"Longleftrightarrow",
|
|
7524
|
+
"Longrightarrow",
|
|
7525
|
+
"Rightarrow",
|
|
7526
|
+
"Join",
|
|
7527
|
+
"Vdash",
|
|
7528
|
+
"Vvdash",
|
|
7529
|
+
"approx",
|
|
7530
|
+
"asymp",
|
|
7531
|
+
"bowtie",
|
|
7532
|
+
"cong",
|
|
7533
|
+
"dashv",
|
|
7534
|
+
"fullouterjoin",
|
|
7535
|
+
"doteq",
|
|
7536
|
+
"downarrow",
|
|
7537
|
+
"equiv",
|
|
7538
|
+
"ge",
|
|
7539
|
+
"geq",
|
|
7540
|
+
"geqslant",
|
|
7541
|
+
"gets",
|
|
7542
|
+
"gg",
|
|
7543
|
+
"hookleftarrow",
|
|
7544
|
+
"hookrightarrow",
|
|
7545
|
+
"iff",
|
|
7546
|
+
"implies",
|
|
7547
|
+
"in",
|
|
7548
|
+
"leadsto",
|
|
7549
|
+
"le",
|
|
7550
|
+
"leftarrow",
|
|
7551
|
+
"leftharpoondown",
|
|
7552
|
+
"leftharpoonup",
|
|
7553
|
+
"leftrightarrow",
|
|
7554
|
+
"leftrightharpoons",
|
|
7555
|
+
"leftouterjoin",
|
|
7556
|
+
"leq",
|
|
7557
|
+
"leqslant",
|
|
7558
|
+
"ll",
|
|
7559
|
+
"longleftarrow",
|
|
7560
|
+
"longleftrightarrow",
|
|
7561
|
+
"longmapsto",
|
|
7562
|
+
"longrightarrow",
|
|
7563
|
+
"ltimes",
|
|
7564
|
+
"mapsto",
|
|
7565
|
+
"mid",
|
|
7566
|
+
"models",
|
|
7567
|
+
"ne",
|
|
7568
|
+
"nearrow",
|
|
7569
|
+
"neq",
|
|
7570
|
+
"ni",
|
|
7571
|
+
"notin",
|
|
7572
|
+
"nvdash",
|
|
7573
|
+
"nvDash",
|
|
7574
|
+
"nwarrow",
|
|
7575
|
+
"parallel",
|
|
7576
|
+
"perp",
|
|
7577
|
+
"prec",
|
|
7578
|
+
"preceq",
|
|
7579
|
+
"propto",
|
|
7580
|
+
"rightharpoondown",
|
|
7581
|
+
"rightharpoonup",
|
|
7582
|
+
"rightleftharpoons",
|
|
7583
|
+
"rightouterjoin",
|
|
7584
|
+
"rightarrow",
|
|
7585
|
+
"rightsquigarrow",
|
|
7586
|
+
"rtimes",
|
|
7587
|
+
"searrow",
|
|
7588
|
+
"sim",
|
|
7589
|
+
"simeq",
|
|
7590
|
+
"sqsubset",
|
|
7591
|
+
"sqsubseteq",
|
|
7592
|
+
"sqsupset",
|
|
7593
|
+
"sqsupseteq",
|
|
7594
|
+
"subset",
|
|
7595
|
+
"subseteq",
|
|
7596
|
+
"succ",
|
|
7597
|
+
"succeq",
|
|
7598
|
+
"supset",
|
|
7599
|
+
"supseteq",
|
|
7600
|
+
"swarrow",
|
|
7601
|
+
"to",
|
|
7602
|
+
"triangleleft",
|
|
7603
|
+
"triangleright",
|
|
7604
|
+
"twoheadleftarrow",
|
|
7605
|
+
"twoheadrightarrow",
|
|
7606
|
+
"uparrow",
|
|
7607
|
+
"vdash"
|
|
7608
|
+
]);
|
|
7609
|
+
var SPACING_COMMANDS = new Set([
|
|
7610
|
+
",",
|
|
7611
|
+
":",
|
|
7612
|
+
";",
|
|
7613
|
+
" ",
|
|
7614
|
+
">",
|
|
7615
|
+
"enspace",
|
|
7616
|
+
"enskip",
|
|
7617
|
+
"medspace",
|
|
7618
|
+
"quad",
|
|
7619
|
+
"qquad",
|
|
7620
|
+
"thickspace",
|
|
7621
|
+
"thinspace"
|
|
7622
|
+
]);
|
|
7623
|
+
var NEGATIVE_SPACING_COMMANDS = new Set(["!", "negmedspace", "negthickspace", "negthinspace"]);
|
|
7624
|
+
var FONT_SWITCH_COMMANDS = new Set(["bf", "cal", "it", "rm", "sf", "sl", "tt"]);
|
|
7625
|
+
var IGNORED_COMMANDS = new Set([
|
|
7626
|
+
"displaystyle",
|
|
7627
|
+
"limits",
|
|
7628
|
+
"nolimits",
|
|
7629
|
+
"scriptstyle",
|
|
7630
|
+
"scriptscriptstyle",
|
|
7631
|
+
"textstyle"
|
|
7632
|
+
]);
|
|
7633
|
+
var SIZE_COMMANDS = new Set([
|
|
7634
|
+
"big",
|
|
7635
|
+
"Big",
|
|
7636
|
+
"bigg",
|
|
7637
|
+
"Bigg",
|
|
7638
|
+
"bigl",
|
|
7639
|
+
"Bigl",
|
|
7640
|
+
"biggl",
|
|
7641
|
+
"Biggl",
|
|
7642
|
+
"bigr",
|
|
7643
|
+
"Bigr",
|
|
7644
|
+
"biggr",
|
|
7645
|
+
"Biggr"
|
|
7646
|
+
]);
|
|
7647
|
+
var PLAIN_WRAPPERS = new Set([
|
|
7648
|
+
"emph",
|
|
7649
|
+
"mathcal",
|
|
7650
|
+
"mathbf",
|
|
7651
|
+
"mathfrak",
|
|
7652
|
+
"mathit",
|
|
7653
|
+
"mathrm",
|
|
7654
|
+
"mathnormal",
|
|
7655
|
+
"mathscr",
|
|
7656
|
+
"mathsf",
|
|
7657
|
+
"mathtt",
|
|
7658
|
+
"mathup",
|
|
7659
|
+
"mbox",
|
|
7660
|
+
"overbrace",
|
|
7661
|
+
"pmb",
|
|
7662
|
+
"smash",
|
|
7663
|
+
"substack",
|
|
7664
|
+
"text",
|
|
7665
|
+
"textbf",
|
|
7666
|
+
"textit",
|
|
7667
|
+
"textmd",
|
|
7668
|
+
"textnormal",
|
|
7669
|
+
"textrm",
|
|
7670
|
+
"textsc",
|
|
7671
|
+
"textsf",
|
|
7672
|
+
"textsl",
|
|
7673
|
+
"texttt",
|
|
7674
|
+
"textup",
|
|
7675
|
+
"underbrace",
|
|
7676
|
+
"bm",
|
|
7677
|
+
"boldsymbol"
|
|
7678
|
+
]);
|
|
7679
|
+
|
|
7680
|
+
// ../../node_modules/.bun/@earendil-works+pi-tui@1.2.0/node_modules/@earendil-works/pi-tui/dist/components/markdown.js
|
|
7681
|
+
var STRICT_STRIKETHROUGH_REGEX = /^(~~)(?=[^\s~])((?:\\.|[^\\])*?(?:\\.|[^\s~\\]))\1(?=[^~]|$)/;
|
|
7682
|
+
|
|
7683
|
+
class StrictStrikethroughTokenizer extends y {
|
|
7684
|
+
del(src) {
|
|
7685
|
+
const match = STRICT_STRIKETHROUGH_REGEX.exec(src);
|
|
7686
|
+
if (!match) {
|
|
7687
|
+
return;
|
|
7688
|
+
}
|
|
7689
|
+
const text = match[2];
|
|
7690
|
+
return {
|
|
7691
|
+
type: "del",
|
|
7692
|
+
raw: match[0],
|
|
7693
|
+
text,
|
|
7694
|
+
tokens: this.lexer.inlineTokens(text)
|
|
7695
|
+
};
|
|
7696
|
+
}
|
|
7697
|
+
}
|
|
7698
|
+
function isEscaped(source, index) {
|
|
7699
|
+
let backslashes = 0;
|
|
7700
|
+
for (let position = index - 1;position >= 0 && source[position] === "\\"; position--) {
|
|
7701
|
+
backslashes++;
|
|
7702
|
+
}
|
|
7703
|
+
return backslashes % 2 === 1;
|
|
7704
|
+
}
|
|
7705
|
+
function findClosingDelimiter(source, closing, start) {
|
|
7706
|
+
let index = source.indexOf(closing, start);
|
|
7707
|
+
while (index >= 0 && isEscaped(source, index)) {
|
|
7708
|
+
index = source.indexOf(closing, index + closing.length);
|
|
7709
|
+
}
|
|
7710
|
+
return index;
|
|
7711
|
+
}
|
|
7712
|
+
function looksLikePendingDollarMath(source) {
|
|
7713
|
+
return /\\[A-Za-z]+|[_^=+*/<>()[\]|±≤≥≠≈∈→⇒∞∫∑√-]/.test(source);
|
|
7714
|
+
}
|
|
7715
|
+
function tokenizeInlineLatex(source) {
|
|
7716
|
+
let opening = "";
|
|
7717
|
+
let closing = "";
|
|
7718
|
+
if (source.startsWith("$$")) {
|
|
7719
|
+
opening = "$$";
|
|
7720
|
+
closing = "$$";
|
|
7721
|
+
} else if (source.startsWith("\\(")) {
|
|
7722
|
+
opening = "\\(";
|
|
7723
|
+
closing = "\\)";
|
|
7724
|
+
} else if (source.startsWith("\\[")) {
|
|
7725
|
+
opening = "\\[";
|
|
7726
|
+
closing = "\\]";
|
|
7727
|
+
} else if (source.startsWith("$") && !/^\$\s/.test(source)) {
|
|
7728
|
+
opening = "$";
|
|
7729
|
+
closing = "$";
|
|
7730
|
+
} else {
|
|
7731
|
+
return;
|
|
7732
|
+
}
|
|
7733
|
+
const closingIndex = findClosingDelimiter(source, closing, opening.length);
|
|
7734
|
+
if (closingIndex >= 0 && opening === "$" && (/\s$/.test(source.slice(opening.length, closingIndex)) || /^\d/.test(source.slice(closingIndex + 1)) || /^[A-Z_][A-Z0-9_]*(?:[^A-Za-z0-9_\s])?$/.test(source.slice(opening.length, closingIndex)) && /^[A-Za-z_][A-Za-z0-9_]*/.test(source.slice(closingIndex + 1)) || source.slice(opening.length, closingIndex).includes("`"))) {
|
|
7735
|
+
return;
|
|
7736
|
+
}
|
|
7737
|
+
if (closingIndex < 0) {
|
|
7738
|
+
const pendingSource = source.slice(opening.length);
|
|
7739
|
+
if (opening.startsWith("\\") || looksLikePendingDollarMath(pendingSource)) {
|
|
7740
|
+
return { type: "latex", raw: source, text: pendingSource, pending: true };
|
|
7741
|
+
}
|
|
7742
|
+
return;
|
|
7743
|
+
}
|
|
7744
|
+
const text = source.slice(opening.length, closingIndex);
|
|
7745
|
+
if (!text || text.includes(`
|
|
7746
|
+
`)) {
|
|
7747
|
+
return;
|
|
7748
|
+
}
|
|
7749
|
+
const raw = source.slice(0, closingIndex + closing.length);
|
|
7750
|
+
return { type: "latex", raw, text };
|
|
7751
|
+
}
|
|
7752
|
+
function tokenizeBlockLatex(source) {
|
|
7753
|
+
const dollarMatch = /^ {0,3}\$\$[ \t]*(?:\n)?([\s\S]*?)\$\$[ \t]*(?:\n|$)/.exec(source);
|
|
7754
|
+
if (dollarMatch?.[1]) {
|
|
7755
|
+
return { type: "latexBlock", raw: dollarMatch[0], text: dollarMatch[1].trim() };
|
|
7756
|
+
}
|
|
7757
|
+
const bracketMatch = /^ {0,3}\\\[[ \t]*(?:\n)?([\s\S]*?)\\\][ \t]*(?:\n|$)/.exec(source);
|
|
7758
|
+
if (bracketMatch?.[1]) {
|
|
7759
|
+
return { type: "latexBlock", raw: bracketMatch[0], text: bracketMatch[1].trim() };
|
|
7760
|
+
}
|
|
7761
|
+
const pendingBracket = /^ {0,3}\\\[[ \t]*(?:\n)?([\s\S]*)$/.exec(source);
|
|
7762
|
+
if (pendingBracket) {
|
|
7763
|
+
return { type: "latexBlock", raw: pendingBracket[0], text: pendingBracket[1], pending: true };
|
|
7764
|
+
}
|
|
7765
|
+
const pendingDollar = /^ {0,3}\$\$[ \t]*(?:\n)?([\s\S]*)$/.exec(source);
|
|
7766
|
+
if (pendingDollar?.[1] && looksLikePendingDollarMath(pendingDollar[1])) {
|
|
7767
|
+
return { type: "latexBlock", raw: pendingDollar[0], text: pendingDollar[1], pending: true };
|
|
7768
|
+
}
|
|
7769
|
+
return;
|
|
7770
|
+
}
|
|
7771
|
+
var LATEX_MARKDOWN_EXTENSIONS = [
|
|
7772
|
+
{
|
|
7773
|
+
name: "latexBlock",
|
|
7774
|
+
level: "block",
|
|
7775
|
+
start(source) {
|
|
7776
|
+
const match = /(?:^|\n) {0,3}(?:\$\$|\\\[)/.exec(source);
|
|
7777
|
+
return match ? match.index + (match[0].startsWith(`
|
|
7778
|
+
`) ? 1 : 0) : undefined;
|
|
7779
|
+
},
|
|
7780
|
+
tokenizer: tokenizeBlockLatex
|
|
7781
|
+
},
|
|
7782
|
+
{
|
|
7783
|
+
name: "latex",
|
|
7784
|
+
level: "inline",
|
|
7785
|
+
start(source) {
|
|
7786
|
+
const indices = [source.indexOf("$"), source.indexOf("\\("), source.indexOf("\\[")].filter((index) => index >= 0);
|
|
7787
|
+
return indices.length > 0 ? Math.min(...indices) : undefined;
|
|
7788
|
+
},
|
|
7789
|
+
tokenizer: tokenizeInlineLatex
|
|
7790
|
+
}
|
|
7791
|
+
];
|
|
7792
|
+
var markdownParser = new Z;
|
|
7793
|
+
markdownParser.setOptions({
|
|
7794
|
+
tokenizer: new StrictStrikethroughTokenizer
|
|
7795
|
+
});
|
|
7796
|
+
markdownParser.use({ extensions: [...LATEX_MARKDOWN_EXTENSIONS] });
|
|
7797
|
+
// ../../node_modules/.bun/@earendil-works+pi-tui@1.2.0/node_modules/@earendil-works/pi-tui/dist/native-platform.js
|
|
7798
|
+
import { createRequire as createRequire2 } from "node:module";
|
|
7799
|
+
|
|
7800
|
+
// ../../node_modules/.bun/@earendil-works+pi-tui@1.2.0/node_modules/@earendil-works/pi-tui/dist/native-module-path.js
|
|
7801
|
+
import { createRequire } from "node:module";
|
|
7802
|
+
var moduleRequire = createRequire(import.meta.url);
|
|
7803
|
+
|
|
7804
|
+
// ../../node_modules/.bun/@earendil-works+pi-tui@1.2.0/node_modules/@earendil-works/pi-tui/dist/native-platform.js
|
|
7805
|
+
var cjsRequire = createRequire2(import.meta.url);
|
|
7806
|
+
var helpers = new Map;
|
|
7807
|
+
// ../../node_modules/.bun/@earendil-works+pi-tui@1.2.0/node_modules/@earendil-works/pi-tui/dist/terminal.js
|
|
7808
|
+
var DESIRED_KITTY_KEYBOARD_PROTOCOL_FLAGS = 7;
|
|
7809
|
+
var KITTY_KEYBOARD_PROTOCOL_QUERY = `\x1B[>${DESIRED_KITTY_KEYBOARD_PROTOCOL_FLAGS}u\x1B[?u`;
|
|
7810
|
+
// ../../node_modules/.bun/@earendil-works+pi-tui@1.2.0/node_modules/@earendil-works/pi-tui/dist/alt-screen-search.js
|
|
7811
|
+
var segmenter2 = getGraphemeSegmenter();
|
|
7812
|
+
|
|
7813
|
+
// ../../node_modules/.bun/@earendil-works+pi-tui@1.2.0/node_modules/@earendil-works/pi-tui/dist/tui-alt-screen.js
|
|
7814
|
+
var MAX_CACHED_OFFSCREEN_KITTY_TRANSMISSION_BYTES = 32 * 1024 * 1024;
|
|
7815
|
+
var MAX_CACHED_OFFSCREEN_KITTY_DECODED_BYTES = 64 * 1024 * 1024;
|
|
7816
|
+
var TERMINAL_WORD_SELECTION_JOINERS = new Set(["/", "-"]);
|
|
7817
|
+
var wordSegmenter4 = getWordSegmenter();
|
|
7818
|
+
// ../../node_modules/.bun/@earendil-works+pi-tui@1.2.0/node_modules/@earendil-works/pi-tui/dist/tui-main-screen.js
|
|
7819
|
+
var MAX_RENDER_WRITE_CHARS = 1024 * 1024;
|
|
7820
|
+
// ../pi-ads/src/style.ts
|
|
5241
7821
|
var OSC_RE = /\x1b\][\s\S]*?(?:\x07|\x1b\\)/g;
|
|
5242
7822
|
var CSI_RE = /\x1b\[[0-9;?]*[ -/]*[@-~]/g;
|
|
5243
7823
|
var C1_RE = /[\x80-\x9f]/g;
|
|
@@ -5245,17 +7825,8 @@ var C0_RE = /[\x00-\x08\x0b\x0c\x0e-\x1f\x7f]/g;
|
|
|
5245
7825
|
function sanitizeText(input) {
|
|
5246
7826
|
return input.replace(OSC_RE, "").replace(CSI_RE, "").replace(/\x1b/g, "").replace(C1_RE, "").replace(/[\t\r\n]+/g, " ").replace(C0_RE, "").trim();
|
|
5247
7827
|
}
|
|
5248
|
-
function
|
|
5249
|
-
|
|
5250
|
-
return "";
|
|
5251
|
-
if (text.length <= maxWidth)
|
|
5252
|
-
return text;
|
|
5253
|
-
if (maxWidth <= 1)
|
|
5254
|
-
return text.slice(0, maxWidth);
|
|
5255
|
-
return `${text.slice(0, maxWidth - 1)}…`;
|
|
5256
|
-
}
|
|
5257
|
-
function pad(text, width) {
|
|
5258
|
-
return text.length >= width ? text.slice(0, width) : text + " ".repeat(width - text.length);
|
|
7828
|
+
function fit(text, width) {
|
|
7829
|
+
return truncateToWidth(text, Math.max(0, width), "…", true);
|
|
5259
7830
|
}
|
|
5260
7831
|
function osc8(text, url, id) {
|
|
5261
7832
|
const params = id ? `id=${id}` : "";
|
|
@@ -5272,7 +7843,7 @@ function renderAdCard(creative, clickUrl, theme, columns) {
|
|
|
5272
7843
|
const bottom = `└${"─".repeat(innerWidth + 2)}┘`;
|
|
5273
7844
|
const linkId = createHash2("sha256").update(url).digest("hex").slice(0, 12);
|
|
5274
7845
|
const row = (text, opts) => {
|
|
5275
|
-
const plain =
|
|
7846
|
+
const plain = fit(text, innerWidth);
|
|
5276
7847
|
let styled = theme.fg("accent", plain);
|
|
5277
7848
|
if (opts?.bold)
|
|
5278
7849
|
styled = theme.bold(styled);
|
|
@@ -5290,9 +7861,16 @@ function renderPlainAdLine(creative, clickUrl, theme, columns) {
|
|
|
5290
7861
|
const headline = sanitizeText(creative.headline);
|
|
5291
7862
|
const cta = sanitizeText(creative.cta);
|
|
5292
7863
|
const url = sanitizeText(clickUrl);
|
|
5293
|
-
const plain =
|
|
7864
|
+
const plain = truncateToWidth(`AD ▚ ${headline} — ${cta}`, Math.max(0, columns - 2), "…");
|
|
5294
7865
|
return theme.fg("dim", osc8(plain, url));
|
|
5295
7866
|
}
|
|
7867
|
+
var CARD_MIN_COLUMNS = 25;
|
|
7868
|
+
function adWidget(creative, clickUrl, adMinColumns) {
|
|
7869
|
+
return (_tui, theme) => ({
|
|
7870
|
+
render: (width) => width < 1 ? [] : (width >= Math.max(adMinColumns, CARD_MIN_COLUMNS) ? renderAdCard(creative, clickUrl, theme, width) : [renderPlainAdLine(creative, clickUrl, theme, width)]).map((line) => ` ${line}`),
|
|
7871
|
+
invalidate() {}
|
|
7872
|
+
});
|
|
7873
|
+
}
|
|
5296
7874
|
function renderErrorLine(message, theme) {
|
|
5297
7875
|
return theme.fg("error", message);
|
|
5298
7876
|
}
|
|
@@ -5306,7 +7884,7 @@ function createBannerRenderer(opts = {}) {
|
|
|
5306
7884
|
let lastPostedToken;
|
|
5307
7885
|
const screen = opts.screen ?? {};
|
|
5308
7886
|
return {
|
|
5309
|
-
async render(deps, ctx, config
|
|
7887
|
+
async render(deps, ctx, config) {
|
|
5310
7888
|
const ad = await fetchAdNext(deps, "banner");
|
|
5311
7889
|
if (opts.isActive && !opts.isActive())
|
|
5312
7890
|
return;
|
|
@@ -5331,10 +7909,7 @@ function createBannerRenderer(opts = {}) {
|
|
|
5331
7909
|
ctx.ui.setWidget(BANNER_WIDGET_ID, undefined);
|
|
5332
7910
|
opts.onBannerAd?.(undefined);
|
|
5333
7911
|
};
|
|
5334
|
-
|
|
5335
|
-
const columns = columnsOverride ?? process.stdout.columns ?? 80;
|
|
5336
|
-
const lines = columns >= config.adMinColumns ? renderAdCard(ad.creative, ad.click_url, theme, columns) : [renderPlainAdLine(ad.creative, ad.click_url, theme, columns)];
|
|
5337
|
-
ctx.ui.setWidget(BANNER_WIDGET_ID, lines);
|
|
7912
|
+
ctx.ui.setWidget(BANNER_WIDGET_ID, adWidget(ad.creative, ad.click_url, config.adMinColumns));
|
|
5338
7913
|
opts.onBannerAd?.(ad.click_url);
|
|
5339
7914
|
if (lastPostedToken !== ad.click_token) {
|
|
5340
7915
|
lastPostedToken = ad.click_token;
|
|
@@ -5358,7 +7933,7 @@ function createInlineRenderer(screen = {}) {
|
|
|
5358
7933
|
screen.inline = undefined;
|
|
5359
7934
|
};
|
|
5360
7935
|
return {
|
|
5361
|
-
async onTurnEnd(deps, ctx, config
|
|
7936
|
+
async onTurnEnd(deps, ctx, config) {
|
|
5362
7937
|
turnCount += 1;
|
|
5363
7938
|
clearInline(ctx);
|
|
5364
7939
|
if (turnCount % config.adInlineTurnFrequency !== 0)
|
|
@@ -5373,10 +7948,7 @@ function createInlineRenderer(screen = {}) {
|
|
|
5373
7948
|
return;
|
|
5374
7949
|
if (isGravity && screen.banner)
|
|
5375
7950
|
screen.clearBanner?.();
|
|
5376
|
-
|
|
5377
|
-
const columns = columnsOverride ?? process.stdout.columns ?? 80;
|
|
5378
|
-
const lines = columns >= config.adMinColumns ? renderAdCard(ad.creative, ad.click_url, theme, columns) : [renderPlainAdLine(ad.creative, ad.click_url, theme, columns)];
|
|
5379
|
-
ctx.ui.setWidget(INLINE_WIDGET_ID, lines, { placement: "belowEditor" });
|
|
7951
|
+
ctx.ui.setWidget(INLINE_WIDGET_ID, adWidget(ad.creative, ad.click_url, config.adMinColumns), { placement: "belowEditor" });
|
|
5380
7952
|
inlineVisible = true;
|
|
5381
7953
|
screen.inline = isGravity ? "gravity" : "own";
|
|
5382
7954
|
screen.clearInline = () => clearInline(ctx);
|
|
@@ -5840,6 +8412,9 @@ var F64Out = new Uint8Array(F64.buffer);
|
|
|
5840
8412
|
var encoder = new TextEncoder;
|
|
5841
8413
|
// ../../node_modules/.bun/typebox@1.3.27/node_modules/typebox/build/type/types/integer.mjs
|
|
5842
8414
|
var IntegerPattern = "-?(?:0|[1-9][0-9]*)";
|
|
8415
|
+
function Integer(options) {
|
|
8416
|
+
return Create({ "~kind": "Integer" }, { type: "integer" }, options);
|
|
8417
|
+
}
|
|
5843
8418
|
// ../../node_modules/.bun/typebox@1.3.27/node_modules/typebox/build/type/types/literal.mjs
|
|
5844
8419
|
class InvalidLiteralValue extends Error {
|
|
5845
8420
|
constructor(value) {
|
|
@@ -5970,6 +8545,106 @@ function createUsageToolExtension(opts) {
|
|
|
5970
8545
|
};
|
|
5971
8546
|
}
|
|
5972
8547
|
|
|
8548
|
+
// src/web-tools.ts
|
|
8549
|
+
var WEB_SEARCH_TOOL_NAME = "web_search";
|
|
8550
|
+
var DOCS_LOOKUP_TOOL_NAME = "docs_lookup";
|
|
8551
|
+
var COST_GUIDELINE = "Each web_search or docs_lookup call costs part of the user's daily allowance; one or two well-aimed calls usually suffice.";
|
|
8552
|
+
var DOCS_LOOKUP_GUIDELINES = [
|
|
8553
|
+
"Use docs_lookup before writing or fixing code against a third-party library, framework, SDK or API whose exact signature or config you are not sure of, and whenever an import, method or option you used turns out not to exist.",
|
|
8554
|
+
'Pass the package name as `library` (e.g. "next.js", "prisma", "@tanstack/react-query") and one specific question as `query` (e.g. "configure middleware matcher for API routes"), not a bare topic. Reuse the returned `library_id` for follow-up lookups on the same library.',
|
|
8555
|
+
COST_GUIDELINE
|
|
8556
|
+
];
|
|
8557
|
+
var WEB_SEARCH_GUIDELINES = [
|
|
8558
|
+
"Use web_search for things that change or are newer than your knowledge: release notes, current versions, exact error messages you cannot explain from the code, service status, and pages the user links or mentions. Prefer docs_lookup for library API docs, and read/grep for anything in the local project.",
|
|
8559
|
+
"Write a specific query the way you would type it into a search engine (include the product name, the version and the exact error text). Read the returned page text before searching again, and do not repeat a query that already returned results. Cite the URLs you relied on in your answer.",
|
|
8560
|
+
COST_GUIDELINE
|
|
8561
|
+
];
|
|
8562
|
+
var ERROR_TEXT = {
|
|
8563
|
+
daily_cap: "The user's daily free usage is used up. Do not retry; tell the user and continue without this tool.",
|
|
8564
|
+
rolling_cap: "The user's short-term usage limit is reached. Do not retry; continue without this tool.",
|
|
8565
|
+
rate_limited: "Too many calls right now. Wait for the current call to finish, and do not call again in this turn unless needed.",
|
|
8566
|
+
not_found: (library) => `No documentation library matched "${library}". Retry once with the package's exact name, or use web_search.`,
|
|
8567
|
+
not_configured: "This tool is not available on this server. Do not call it again in this session.",
|
|
8568
|
+
upstream_error: "The search provider failed. You may retry once."
|
|
8569
|
+
};
|
|
8570
|
+
async function post(opts, path, body, label, signal) {
|
|
8571
|
+
try {
|
|
8572
|
+
const timeout = AbortSignal.timeout(30000);
|
|
8573
|
+
const res = await (opts.fetchImpl ?? fetch)(`${opts.baseUrl}${path}`, {
|
|
8574
|
+
method: "POST",
|
|
8575
|
+
headers: { Authorization: `Bearer ${await opts.getToken()}`, "Content-Type": "application/json" },
|
|
8576
|
+
body: JSON.stringify(body),
|
|
8577
|
+
signal: signal ? AbortSignal.any([signal, timeout]) : timeout
|
|
8578
|
+
});
|
|
8579
|
+
if (res.ok)
|
|
8580
|
+
return { ok: true, data: await res.json() };
|
|
8581
|
+
const err = await res.json().catch(() => ({}));
|
|
8582
|
+
const mapped = ERROR_TEXT[err.code ?? ""];
|
|
8583
|
+
if (mapped)
|
|
8584
|
+
return { ok: false, text: typeof mapped === "function" ? mapped(label) : mapped };
|
|
8585
|
+
return { ok: false, text: `Request failed (HTTP ${res.status}): ${err.message ?? "no message"}` };
|
|
8586
|
+
} catch (e) {
|
|
8587
|
+
if (e instanceof Error && e.name === "TimeoutError")
|
|
8588
|
+
return { ok: false, text: "Request timed out after 30 seconds." };
|
|
8589
|
+
return { ok: false, text: `Request failed: ${String(e)}` };
|
|
8590
|
+
}
|
|
8591
|
+
}
|
|
8592
|
+
var done = (o) => ({ content: [{ type: "text", text: o.text }], details: o.details });
|
|
8593
|
+
function createWebToolsExtension(opts) {
|
|
8594
|
+
return {
|
|
8595
|
+
name: "free-pi-web-tools",
|
|
8596
|
+
factory(pi) {
|
|
8597
|
+
pi.registerTool({
|
|
8598
|
+
name: WEB_SEARCH_TOOL_NAME,
|
|
8599
|
+
label: "Web Search",
|
|
8600
|
+
description: "Search the web and return a numbered list of results, each with title, URL, publish date and the page text. Use it for current or recent information that your training data may lack. Each call uses part of the user's daily allowance.",
|
|
8601
|
+
promptSnippet: "Search the web for current information (counts against the user's daily allowance)",
|
|
8602
|
+
promptGuidelines: WEB_SEARCH_GUIDELINES,
|
|
8603
|
+
parameters: _Object_({
|
|
8604
|
+
query: String2({ minLength: 1, maxLength: 500, description: 'Specific query as you would type it into a search engine, e.g. "vite 6 release notes breaking changes"' }),
|
|
8605
|
+
num_results: Optional(Integer({ minimum: 1, maximum: 10, description: "1-10, default 5; use 3 for a quick fact, 8-10 for a survey" }))
|
|
8606
|
+
}),
|
|
8607
|
+
async execute(_id, params, signal) {
|
|
8608
|
+
const r = await post(opts, "/tools/web-search", params, "", signal);
|
|
8609
|
+
if (!r.ok)
|
|
8610
|
+
return done({ text: r.text, details: { ok: false } });
|
|
8611
|
+
const results = r.data.results ?? [];
|
|
8612
|
+
const text = results.length ? `Web results for "${params.query}":
|
|
8613
|
+
|
|
8614
|
+
` + results.map((x, i) => `${i + 1}. ${x.title}
|
|
8615
|
+
${x.url}${x.published_date ? `
|
|
8616
|
+
Published: ${x.published_date}` : ""}
|
|
8617
|
+
${x.text}`).join(`
|
|
8618
|
+
|
|
8619
|
+
`) : `No results for "${params.query}". Try a broader or differently worded query.`;
|
|
8620
|
+
return done({ text, details: { ok: true, cost_usd: r.data.cost_usd } });
|
|
8621
|
+
}
|
|
8622
|
+
});
|
|
8623
|
+
pi.registerTool({
|
|
8624
|
+
name: DOCS_LOOKUP_TOOL_NAME,
|
|
8625
|
+
label: "Docs Lookup",
|
|
8626
|
+
description: "Look up current documentation for a third-party library, framework or API. Returns the matching library's title and library_id, then documentation text relevant to your query. Use it instead of relying on memory for exact signatures and options. Each call uses part of the user's daily allowance.",
|
|
8627
|
+
promptSnippet: "Look up library/framework documentation before relying on memory (counts against the user's daily allowance)",
|
|
8628
|
+
promptGuidelines: DOCS_LOOKUP_GUIDELINES,
|
|
8629
|
+
parameters: _Object_({
|
|
8630
|
+
library: String2({ minLength: 1, maxLength: 200, description: 'Package or library name, e.g. "next.js", "prisma", "@tanstack/react-query"' }),
|
|
8631
|
+
query: String2({ minLength: 1, maxLength: 500, description: 'One specific question, e.g. "configure middleware matcher for API routes"' }),
|
|
8632
|
+
library_id: Optional(String2({ description: "The library_id printed by an earlier docs_lookup, e.g. /vercel/next.js; skips the name search" }))
|
|
8633
|
+
}),
|
|
8634
|
+
async execute(_id, params, signal) {
|
|
8635
|
+
const r = await post(opts, "/tools/docs", params, params.library, signal);
|
|
8636
|
+
if (!r.ok)
|
|
8637
|
+
return done({ text: r.text, details: { ok: false } });
|
|
8638
|
+
const d = r.data;
|
|
8639
|
+
return done({ text: `${d.title} (library_id: ${d.library_id})
|
|
8640
|
+
|
|
8641
|
+
${d.docs}`, details: { ok: true, cost_usd: d.cost_usd } });
|
|
8642
|
+
}
|
|
8643
|
+
});
|
|
8644
|
+
}
|
|
8645
|
+
};
|
|
8646
|
+
}
|
|
8647
|
+
|
|
5973
8648
|
// src/buy-tool.ts
|
|
5974
8649
|
async function resolveBuyPage(opts) {
|
|
5975
8650
|
try {
|
|
@@ -6126,7 +8801,7 @@ function createDocsToolExtension() {
|
|
|
6126
8801
|
// src/todo-view.ts
|
|
6127
8802
|
var PLAIN_STYLE = { bold: (s) => s, dim: (s) => s, accent: (s) => s, error: (s) => s };
|
|
6128
8803
|
var GAP = " ";
|
|
6129
|
-
function
|
|
8804
|
+
function truncate(text, max) {
|
|
6130
8805
|
if (max <= 0)
|
|
6131
8806
|
return "";
|
|
6132
8807
|
if ([...text].length <= max)
|
|
@@ -6152,19 +8827,19 @@ function widgetLines(todos, width, st = PLAIN_STYLE) {
|
|
|
6152
8827
|
].join(GAP)
|
|
6153
8828
|
];
|
|
6154
8829
|
}
|
|
6155
|
-
const lines = [st.bold(
|
|
8830
|
+
const lines = [st.bold(truncate(header, width))];
|
|
6156
8831
|
const open = todos.filter((t) => !t.done);
|
|
6157
8832
|
if (open.length === 0) {
|
|
6158
|
-
lines.push(st.dim(
|
|
8833
|
+
lines.push(st.dim(truncate("✓ All done", width)));
|
|
6159
8834
|
return lines;
|
|
6160
8835
|
}
|
|
6161
8836
|
open.slice(0, 3).forEach((t, i) => {
|
|
6162
|
-
const line =
|
|
8837
|
+
const line = truncate(`${i === 0 ? "▸" : "○"} ${t.text}`, width);
|
|
6163
8838
|
lines.push(i === 0 ? st.accent(st.bold(line)) : st.dim(line));
|
|
6164
8839
|
});
|
|
6165
8840
|
const more = open.length - 3;
|
|
6166
8841
|
if (more > 0)
|
|
6167
|
-
lines.push(st.dim(
|
|
8842
|
+
lines.push(st.dim(truncate(`+${more} more · /todos for all`, width)));
|
|
6168
8843
|
return lines;
|
|
6169
8844
|
}
|
|
6170
8845
|
function resultLines(d, st = PLAIN_STYLE) {
|
|
@@ -6602,6 +9277,19 @@ function installFooterRightAlign(mode) {
|
|
|
6602
9277
|
|
|
6603
9278
|
// src/changelog.ts
|
|
6604
9279
|
var CHANGELOG_HIGHLIGHTS = [
|
|
9280
|
+
{
|
|
9281
|
+
version: "0.4.7",
|
|
9282
|
+
highlights: [
|
|
9283
|
+
"free-pi now updates itself when a new version is required: no more running npx free-pi-cli@latest.",
|
|
9284
|
+
"The ad box redraws at your terminal's width after a resize, and never overflows with wide characters."
|
|
9285
|
+
]
|
|
9286
|
+
},
|
|
9287
|
+
{
|
|
9288
|
+
version: "0.4.6",
|
|
9289
|
+
highlights: [
|
|
9290
|
+
"Free web search and documentation lookup: the agent can now search the web (web_search) and look up current library docs (docs_lookup). Both run on the free-pi server and count toward your daily allowance."
|
|
9291
|
+
]
|
|
9292
|
+
},
|
|
6605
9293
|
{
|
|
6606
9294
|
version: "0.4.5",
|
|
6607
9295
|
highlights: [
|
|
@@ -6953,12 +9641,12 @@ function updateBannerLines(theme, latest, width) {
|
|
|
6953
9641
|
return [
|
|
6954
9642
|
"",
|
|
6955
9643
|
border,
|
|
6956
|
-
theme.bold(theme.fg("warning",
|
|
6957
|
-
theme.fg("dim",
|
|
9644
|
+
theme.bold(theme.fg("warning", truncate2(headline, inner))),
|
|
9645
|
+
theme.fg("dim", truncate2(detail, inner)),
|
|
6958
9646
|
border
|
|
6959
9647
|
];
|
|
6960
9648
|
}
|
|
6961
|
-
function
|
|
9649
|
+
function truncate2(text, maxWidth) {
|
|
6962
9650
|
if (maxWidth <= 0)
|
|
6963
9651
|
return "";
|
|
6964
9652
|
if (text.length <= maxWidth)
|
|
@@ -6969,7 +9657,7 @@ function truncate3(text, maxWidth) {
|
|
|
6969
9657
|
}
|
|
6970
9658
|
function headerLines(theme, modelName, expanded, width = Number.POSITIVE_INFINITY, updateLatest) {
|
|
6971
9659
|
const inner = width - 1;
|
|
6972
|
-
const fit = (plain, styled) => plain.length <= inner ? styled() : theme.fg("dim",
|
|
9660
|
+
const fit = (plain, styled) => plain.length <= inner ? styled() : theme.fg("dim", truncate2(plain, inner));
|
|
6973
9661
|
const titleRest = ` · ${modelName} · ctrl+o for help`;
|
|
6974
9662
|
const title = fit(`free-pi${titleRest}`, () => `${theme.bold(theme.fg("accent", "free-pi"))}${theme.fg("dim", titleRest)}`);
|
|
6975
9663
|
const commandLines = COMMANDS.map(({ name, description }) => {
|
|
@@ -7182,6 +9870,8 @@ var ALLOWED_TOOL_NAMES = [
|
|
|
7182
9870
|
USAGE_TOOL_NAME,
|
|
7183
9871
|
BUY_TOOL_NAME,
|
|
7184
9872
|
DOCS_TOOL_NAME,
|
|
9873
|
+
WEB_SEARCH_TOOL_NAME,
|
|
9874
|
+
DOCS_LOOKUP_TOOL_NAME,
|
|
7185
9875
|
TODO_TOOL_NAME,
|
|
7186
9876
|
"codemode",
|
|
7187
9877
|
"tool_search"
|
|
@@ -7240,6 +9930,10 @@ function buildRuntimeOptions(opts, sessionId) {
|
|
|
7240
9930
|
getToken: () => opts.jwt
|
|
7241
9931
|
});
|
|
7242
9932
|
const docsToolExtension = createDocsToolExtension();
|
|
9933
|
+
const webToolsExtension = createWebToolsExtension({
|
|
9934
|
+
baseUrl: opts.baseUrl,
|
|
9935
|
+
getToken: () => opts.jwt
|
|
9936
|
+
});
|
|
7243
9937
|
const errorNoticeExtension = createErrorNoticeExtension();
|
|
7244
9938
|
const toolGuardExtension = createToolGuardExtension({
|
|
7245
9939
|
baseUrl: opts.baseUrl,
|
|
@@ -7267,6 +9961,7 @@ function buildRuntimeOptions(opts, sessionId) {
|
|
|
7267
9961
|
usageToolExtension,
|
|
7268
9962
|
buyToolExtension,
|
|
7269
9963
|
docsToolExtension,
|
|
9964
|
+
webToolsExtension,
|
|
7270
9965
|
errorNoticeExtension,
|
|
7271
9966
|
toolGuardExtension,
|
|
7272
9967
|
commandsExtension,
|
|
@@ -7434,6 +10129,62 @@ function createRealSpawn(io = { platform: process.platform, spawnSyncImpl: spawn
|
|
|
7434
10129
|
};
|
|
7435
10130
|
}
|
|
7436
10131
|
|
|
10132
|
+
// src/relaunch.ts
|
|
10133
|
+
import { mkdtempSync, existsSync as existsSync2, rmSync } from "node:fs";
|
|
10134
|
+
import { constants as osConstants, tmpdir } from "node:os";
|
|
10135
|
+
import { join as join5 } from "node:path";
|
|
10136
|
+
var SEMVER = /^\d+\.\d+\.\d+(?:[-+][0-9A-Za-z.-]+)?$/;
|
|
10137
|
+
var WIN_SAFE_ARG = /^[A-Za-z0-9._:=\/@+,-]+$/;
|
|
10138
|
+
async function relaunchViaNpx(latest, deps) {
|
|
10139
|
+
const { env } = deps;
|
|
10140
|
+
if ("FREEPI_NO_AUTO_UPDATE" in env || !deps.autoUpdateEnabled())
|
|
10141
|
+
return;
|
|
10142
|
+
if (env.FREEPI_AUTO_UPDATED)
|
|
10143
|
+
return;
|
|
10144
|
+
const win = deps.platform === "win32";
|
|
10145
|
+
if (win && !deps.argv.every((a) => WIN_SAFE_ARG.test(a)))
|
|
10146
|
+
return;
|
|
10147
|
+
const target = latest && SEMVER.test(latest) ? latest : "latest";
|
|
10148
|
+
const readyDir = mkdtempSync(join5(tmpdir(), "free-pi-relaunch-"));
|
|
10149
|
+
const readyFile = join5(readyDir, "started");
|
|
10150
|
+
try {
|
|
10151
|
+
deps.log(`Updating free-pi to ${target}…`);
|
|
10152
|
+
return await new Promise((resolve) => {
|
|
10153
|
+
let child;
|
|
10154
|
+
try {
|
|
10155
|
+
child = deps.spawn(win ? "npx.cmd" : "npx", ["--yes", `free-pi-cli@${target}`, ...deps.argv], {
|
|
10156
|
+
stdio: "inherit",
|
|
10157
|
+
env: { ...env, FREEPI_AUTO_UPDATED: target, FREEPI_RELAUNCH_READY: readyFile },
|
|
10158
|
+
shell: win
|
|
10159
|
+
});
|
|
10160
|
+
} catch {
|
|
10161
|
+
resolve(undefined);
|
|
10162
|
+
return;
|
|
10163
|
+
}
|
|
10164
|
+
const handlers = win ? [] : [
|
|
10165
|
+
["SIGINT", () => {}],
|
|
10166
|
+
["SIGTERM", () => void child.kill("SIGTERM")],
|
|
10167
|
+
["SIGHUP", () => void child.kill("SIGHUP")]
|
|
10168
|
+
];
|
|
10169
|
+
for (const [sig, cb] of handlers)
|
|
10170
|
+
deps.proc.on(sig, cb);
|
|
10171
|
+
const done = (code) => {
|
|
10172
|
+
for (const [sig, cb] of handlers)
|
|
10173
|
+
deps.proc.off(sig, cb);
|
|
10174
|
+
resolve(code);
|
|
10175
|
+
};
|
|
10176
|
+
child.on("error", () => done(undefined));
|
|
10177
|
+
child.on("exit", (code, signal) => {
|
|
10178
|
+
const exitCode = code ?? 128 + (signal ? osConstants.signals[signal] ?? 0 : 0);
|
|
10179
|
+
const cancelled = signal === "SIGINT" || signal === "SIGTERM" || signal === "SIGHUP" || exitCode === 130 || exitCode === 143 || exitCode === 129;
|
|
10180
|
+
done(exitCode !== 0 && !cancelled && !existsSync2(readyFile) ? undefined : exitCode);
|
|
10181
|
+
});
|
|
10182
|
+
});
|
|
10183
|
+
} finally {
|
|
10184
|
+
rmSync(readyDir, { recursive: true, force: true });
|
|
10185
|
+
}
|
|
10186
|
+
}
|
|
10187
|
+
|
|
7437
10188
|
// src/auth-flow.ts
|
|
7438
10189
|
class UnauthorizedError extends Error {
|
|
7439
10190
|
constructor() {
|
|
@@ -7564,12 +10315,12 @@ ${INTRO_TEXT}
|
|
|
7564
10315
|
}
|
|
7565
10316
|
|
|
7566
10317
|
// src/whats-new.ts
|
|
7567
|
-
import { existsSync as
|
|
10318
|
+
import { existsSync as existsSync3, mkdirSync, readFileSync as readFileSync2, writeFileSync } from "node:fs";
|
|
7568
10319
|
import { dirname as dirname4 } from "node:path";
|
|
7569
10320
|
function maybeWhatsNew(cliVersion, agentDir) {
|
|
7570
10321
|
try {
|
|
7571
10322
|
const path = getLastSeenVersionPath(agentDir);
|
|
7572
|
-
const lastSeen =
|
|
10323
|
+
const lastSeen = existsSync3(path) ? readFileSync2(path, "utf-8").trim() : undefined;
|
|
7573
10324
|
writeLastSeen(path, cliVersion);
|
|
7574
10325
|
if (lastSeen === undefined)
|
|
7575
10326
|
return;
|
|
@@ -7665,6 +10416,9 @@ async function run(deps, argv = process.argv) {
|
|
|
7665
10416
|
if (outcome === "updated-exit")
|
|
7666
10417
|
return 0;
|
|
7667
10418
|
if (outcome === "blocked") {
|
|
10419
|
+
const relaunched = await deps.relaunchLatest?.(versionCheck.latest);
|
|
10420
|
+
if (relaunched !== undefined)
|
|
10421
|
+
return relaunched;
|
|
7668
10422
|
deps.log("free-pi-cli is below the required minimum version; update with: npx free-pi-cli@latest");
|
|
7669
10423
|
return 1;
|
|
7670
10424
|
}
|
|
@@ -7773,6 +10527,11 @@ function resolveCliRealpath() {
|
|
|
7773
10527
|
}
|
|
7774
10528
|
}
|
|
7775
10529
|
async function main() {
|
|
10530
|
+
if (process.env.FREEPI_RELAUNCH_READY) {
|
|
10531
|
+
try {
|
|
10532
|
+
writeFileSync2(process.env.FREEPI_RELAUNCH_READY, "");
|
|
10533
|
+
} catch {}
|
|
10534
|
+
}
|
|
7776
10535
|
const command = parseCliArgs(process.argv.slice(2));
|
|
7777
10536
|
if (command.kind === "version") {
|
|
7778
10537
|
console.log(versionLine());
|
|
@@ -7817,7 +10576,16 @@ ${HELP_TEXT}`);
|
|
|
7817
10576
|
launchPi,
|
|
7818
10577
|
log: (message) => console.log(message),
|
|
7819
10578
|
checkClientVersion,
|
|
7820
|
-
startGravityPixel: (jwt) => startGravityPixel(jwt,
|
|
10579
|
+
startGravityPixel: (jwt) => startGravityPixel(jwt, join6(dirname5(agentDir), "gravity")),
|
|
10580
|
+
relaunchLatest: (latest) => relaunchViaNpx(latest, {
|
|
10581
|
+
env: process.env,
|
|
10582
|
+
argv: process.argv.slice(2),
|
|
10583
|
+
platform: process.platform,
|
|
10584
|
+
autoUpdateEnabled: () => readAutoUpdate(getConfigPath()),
|
|
10585
|
+
spawn: (cmd, args, opts) => spawn2(cmd, args, opts),
|
|
10586
|
+
proc: process,
|
|
10587
|
+
log: (message) => console.log(message)
|
|
10588
|
+
}),
|
|
7821
10589
|
maybeSelfUpdate: (action, latest) => maybeSelfUpdate(action, latest, {
|
|
7822
10590
|
env: process.env,
|
|
7823
10591
|
autoUpdateEnabled: () => readAutoUpdate(getConfigPath()),
|