@thxgg/steward 0.1.24 → 0.1.26
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/.output/nitro.json +1 -1
- package/.output/public/_nuxt/{Bc2V3wPK.js → B2ow85x_.js} +2 -2
- package/.output/public/_nuxt/{U78rMDmo.js → B6CbIr08.js} +1 -1
- package/.output/public/_nuxt/{BknRrWsw.js → BLQAF8wp.js} +1 -1
- package/.output/public/_nuxt/BXuwtOqb.js +1 -0
- package/.output/public/_nuxt/CAMiEhze.js +1 -0
- package/.output/public/_nuxt/{BRQ9Cxaw.js → CIBCqZF5.js} +1 -1
- package/.output/public/_nuxt/Ce0-nlm9.js +1 -0
- package/.output/public/_nuxt/{T11EuTtn.js → ConzneVY.js} +1 -1
- package/.output/public/_nuxt/D0qxz_Pn.js +1310 -0
- package/.output/public/_nuxt/D3PDtLSF.js +3 -0
- package/.output/public/_nuxt/{C73kduX-.js → DdKC0UAK.js} +1 -1
- package/.output/public/_nuxt/Detail.BGdvrJGh.css +1 -0
- package/.output/public/_nuxt/{C53_p0K1.js → Dkh9ic1y.js} +1 -1
- package/.output/public/_nuxt/LEjJTR7-.js +1 -0
- package/.output/public/_nuxt/{BTmXUZ_s.js → UqZfMfrZ.js} +1 -1
- package/.output/public/_nuxt/builds/latest.json +1 -1
- package/.output/public/_nuxt/builds/meta/25438e34-19a2-421d-aede-53fd18f1ccd4.json +1 -0
- package/.output/public/_nuxt/dckrK0oj.js +1 -0
- package/.output/public/_nuxt/entry.DT4p6_uW.css +1 -0
- package/.output/public/_nuxt/pIWeVmPw.js +1 -0
- package/.output/public/_nuxt/xrHaPo1U.js +60 -0
- package/.output/server/chunks/_/prd-service.mjs.map +1 -1
- package/.output/server/chunks/build/{Detail-DMMUwTWr.mjs → Detail-rpcemNXe.mjs} +674 -481
- package/.output/server/chunks/build/Detail-rpcemNXe.mjs.map +1 -0
- package/.output/server/chunks/build/DiffViewer-styles.B1FB5NJj.mjs +8 -0
- package/.output/server/chunks/build/DiffViewer-styles.B1FB5NJj.mjs.map +1 -0
- package/.output/server/chunks/build/{_prd_-ByugK4Yi.mjs → _prd_-CeibvZOH.mjs} +67 -233
- package/.output/server/chunks/build/_prd_-CeibvZOH.mjs.map +1 -0
- package/.output/server/chunks/build/client.precomputed.mjs +1 -1
- package/.output/server/chunks/build/{default-BKKgG7HJ.mjs → default-iq8SaDDN.mjs} +3 -3
- package/.output/server/chunks/build/default-iq8SaDDN.mjs.map +1 -0
- package/.output/server/chunks/build/{error-404-Bf6kdO80.mjs → error-404-DFale9A5.mjs} +2 -2
- package/.output/server/chunks/build/error-404-DFale9A5.mjs.map +1 -0
- package/.output/server/chunks/build/{index-DE1tjHAd.mjs → index-Po00RvHm.mjs} +2 -2
- package/.output/server/chunks/build/index-Po00RvHm.mjs.map +1 -0
- package/.output/server/chunks/build/{nuxt-link-SvT1nf8Z.mjs → nuxt-link-B4oWFn7n.mjs} +2 -2
- package/.output/server/chunks/build/nuxt-link-B4oWFn7n.mjs.map +1 -0
- package/.output/server/chunks/build/{repo-graph-DzT45gSB.mjs → repo-graph-BQVFpA-w.mjs} +5 -4
- package/.output/server/chunks/build/repo-graph-BQVFpA-w.mjs.map +1 -0
- package/.output/server/chunks/build/server.mjs +7 -7
- package/.output/server/chunks/build/styles.mjs +4 -5
- package/.output/server/chunks/build/{usePrd-hXZOmvAv.mjs → usePrd-Bb6jlnNZ.mjs} +2 -2
- package/.output/server/chunks/build/usePrd-Bb6jlnNZ.mjs.map +1 -0
- package/.output/server/chunks/nitro/nitro.mjs +983 -678
- package/.output/server/chunks/nitro/nitro.mjs.map +1 -1
- package/.output/server/node_modules/@pierre/diffs/dist/components/File.js +324 -0
- package/.output/server/node_modules/@pierre/diffs/dist/components/FileDiff.js +395 -0
- package/.output/server/node_modules/@pierre/diffs/dist/components/FileStream.js +161 -0
- package/.output/server/node_modules/@pierre/diffs/dist/components/web-components.js +25 -0
- package/.output/server/node_modules/@pierre/diffs/dist/constants.js +23 -0
- package/.output/server/node_modules/@pierre/diffs/dist/highlighter/languages/areLanguagesAttached.js +11 -0
- package/.output/server/node_modules/@pierre/diffs/dist/highlighter/languages/attachResolvedLanguages.js +20 -0
- package/.output/server/node_modules/@pierre/diffs/dist/highlighter/languages/cleanUpResolvedLanguages.js +11 -0
- package/.output/server/node_modules/@pierre/diffs/dist/highlighter/languages/constants.js +8 -0
- package/.output/server/node_modules/@pierre/diffs/dist/highlighter/languages/getResolvedLanguages.js +16 -0
- package/.output/server/node_modules/@pierre/diffs/dist/highlighter/languages/getResolvedOrResolveLanguage.js +11 -0
- package/.output/server/node_modules/@pierre/diffs/dist/highlighter/languages/hasResolvedLanguages.js +11 -0
- package/.output/server/node_modules/@pierre/diffs/dist/highlighter/languages/resolveLanguage.js +30 -0
- package/.output/server/node_modules/@pierre/diffs/dist/highlighter/languages/resolveLanguages.js +25 -0
- package/.output/server/node_modules/@pierre/diffs/dist/highlighter/shared_highlighter.js +71 -0
- package/.output/server/node_modules/@pierre/diffs/dist/highlighter/themes/areThemesAttached.js +12 -0
- package/.output/server/node_modules/@pierre/diffs/dist/highlighter/themes/attachResolvedThemes.js +24 -0
- package/.output/server/node_modules/@pierre/diffs/dist/highlighter/themes/cleanUpResolvedThemes.js +11 -0
- package/.output/server/node_modules/@pierre/diffs/dist/highlighter/themes/constants.js +9 -0
- package/.output/server/node_modules/@pierre/diffs/dist/highlighter/themes/getResolvedOrResolveTheme.js +11 -0
- package/.output/server/node_modules/@pierre/diffs/dist/highlighter/themes/getResolvedThemes.js +16 -0
- package/.output/server/node_modules/@pierre/diffs/dist/highlighter/themes/hasResolvedThemes.js +11 -0
- package/.output/server/node_modules/@pierre/diffs/dist/highlighter/themes/registerCustomCSSVariableTheme.js +18 -0
- package/.output/server/node_modules/@pierre/diffs/dist/highlighter/themes/registerCustomTheme.js +14 -0
- package/.output/server/node_modules/@pierre/diffs/dist/highlighter/themes/resolveTheme.js +35 -0
- package/.output/server/node_modules/@pierre/diffs/dist/highlighter/themes/resolveThemes.js +21 -0
- package/.output/server/node_modules/@pierre/diffs/dist/index.js +84 -0
- package/.output/server/node_modules/@pierre/diffs/dist/managers/LineSelectionManager.js +282 -0
- package/.output/server/node_modules/@pierre/diffs/dist/managers/MouseEventManager.js +244 -0
- package/.output/server/node_modules/@pierre/diffs/dist/managers/ResizeManager.js +132 -0
- package/.output/server/node_modules/@pierre/diffs/dist/managers/ScrollSyncManager.js +62 -0
- package/.output/server/node_modules/@pierre/diffs/dist/managers/UniversalRenderingManager.js +32 -0
- package/.output/server/node_modules/@pierre/diffs/dist/renderers/DiffHunksRenderer.js +655 -0
- package/.output/server/node_modules/@pierre/diffs/dist/renderers/FileRenderer.js +243 -0
- package/.output/server/node_modules/@pierre/diffs/dist/shiki-stream/stream.js +32 -0
- package/.output/server/node_modules/@pierre/diffs/dist/shiki-stream/tokenizer.js +71 -0
- package/.output/server/node_modules/@pierre/diffs/dist/sprite.js +55 -0
- package/.output/server/node_modules/@pierre/diffs/dist/style.js +6 -0
- package/.output/server/node_modules/@pierre/diffs/dist/themes/pierre-dark.js +1328 -0
- package/.output/server/node_modules/@pierre/diffs/dist/themes/pierre-light.js +1328 -0
- package/.output/server/node_modules/@pierre/diffs/dist/utils/areFilesEqual.js +8 -0
- package/.output/server/node_modules/@pierre/diffs/dist/utils/areObjectsEqual.js +18 -0
- package/.output/server/node_modules/@pierre/diffs/dist/utils/areOptionsEqual.js +12 -0
- package/.output/server/node_modules/@pierre/diffs/dist/utils/areSelectionsEqual.js +8 -0
- package/.output/server/node_modules/@pierre/diffs/dist/utils/areThemesEqual.js +9 -0
- package/.output/server/node_modules/@pierre/diffs/dist/utils/cleanLastNewline.js +8 -0
- package/.output/server/node_modules/@pierre/diffs/dist/utils/createAnnotationElement.js +21 -0
- package/.output/server/node_modules/@pierre/diffs/dist/utils/createAnnotationWrapperNode.js +12 -0
- package/.output/server/node_modules/@pierre/diffs/dist/utils/createCodeNode.js +12 -0
- package/.output/server/node_modules/@pierre/diffs/dist/utils/createEmptyRowBuffer.js +16 -0
- package/.output/server/node_modules/@pierre/diffs/dist/utils/createFileHeaderElement.js +84 -0
- package/.output/server/node_modules/@pierre/diffs/dist/utils/createHoverContentNode.js +15 -0
- package/.output/server/node_modules/@pierre/diffs/dist/utils/createNoNewlineElement.js +24 -0
- package/.output/server/node_modules/@pierre/diffs/dist/utils/createPreElement.js +28 -0
- package/.output/server/node_modules/@pierre/diffs/dist/utils/createRowNodes.js +20 -0
- package/.output/server/node_modules/@pierre/diffs/dist/utils/createSeparator.js +69 -0
- package/.output/server/node_modules/@pierre/diffs/dist/utils/createSpanNodeFromToken.js +13 -0
- package/.output/server/node_modules/@pierre/diffs/dist/utils/createStyleElement.js +19 -0
- package/.output/server/node_modules/@pierre/diffs/dist/utils/createTransformerWithState.js +56 -0
- package/.output/server/node_modules/@pierre/diffs/dist/utils/createUnsafeCSSStyleNode.js +12 -0
- package/.output/server/node_modules/@pierre/diffs/dist/utils/cssWrappers.js +21 -0
- package/.output/server/node_modules/@pierre/diffs/dist/utils/diffAcceptRejectHunk.js +82 -0
- package/.output/server/node_modules/@pierre/diffs/dist/utils/formatCSSVariablePrefix.js +8 -0
- package/.output/server/node_modules/@pierre/diffs/dist/utils/getFiletypeFromFileName.js +343 -0
- package/.output/server/node_modules/@pierre/diffs/dist/utils/getHighlighterOptions.js +13 -0
- package/.output/server/node_modules/@pierre/diffs/dist/utils/getHighlighterThemeStyles.js +40 -0
- package/.output/server/node_modules/@pierre/diffs/dist/utils/getHunkSeparatorSlotName.js +8 -0
- package/.output/server/node_modules/@pierre/diffs/dist/utils/getIconForType.js +15 -0
- package/.output/server/node_modules/@pierre/diffs/dist/utils/getLineAnnotationName.js +8 -0
- package/.output/server/node_modules/@pierre/diffs/dist/utils/getLineEndingType.js +11 -0
- package/.output/server/node_modules/@pierre/diffs/dist/utils/getLineNodes.js +15 -0
- package/.output/server/node_modules/@pierre/diffs/dist/utils/getSingularPatch.js +20 -0
- package/.output/server/node_modules/@pierre/diffs/dist/utils/getThemes.js +16 -0
- package/.output/server/node_modules/@pierre/diffs/dist/utils/getTotalLineCountFromHunks.js +10 -0
- package/.output/server/node_modules/@pierre/diffs/dist/utils/hast_utils.js +42 -0
- package/.output/server/node_modules/@pierre/diffs/dist/utils/isWorkerContext.js +8 -0
- package/.output/server/node_modules/@pierre/diffs/dist/utils/parseDiffDecorations.js +34 -0
- package/.output/server/node_modules/@pierre/diffs/dist/utils/parseDiffFromFile.js +23 -0
- package/.output/server/node_modules/@pierre/diffs/dist/utils/parseLineType.js +17 -0
- package/.output/server/node_modules/@pierre/diffs/dist/utils/parsePatchFiles.js +211 -0
- package/.output/server/node_modules/@pierre/diffs/dist/utils/prerenderHTMLIfNecessary.js +10 -0
- package/.output/server/node_modules/@pierre/diffs/dist/utils/processLine.js +42 -0
- package/.output/server/node_modules/@pierre/diffs/dist/utils/renderDiffWithHighlighter.js +339 -0
- package/.output/server/node_modules/@pierre/diffs/dist/utils/renderFileWithHighlighter.js +52 -0
- package/.output/server/node_modules/@pierre/diffs/dist/utils/setLanguageOverride.js +11 -0
- package/.output/server/node_modules/@pierre/diffs/dist/utils/setWrapperNodeProps.js +29 -0
- package/.output/server/node_modules/@pierre/diffs/package.json +89 -0
- package/.output/server/node_modules/@shikijs/transformers/dist/index.mjs +831 -0
- package/.output/server/node_modules/@shikijs/transformers/package.json +37 -0
- package/.output/server/node_modules/diff/libesm/convert/dmp.js +21 -0
- package/.output/server/node_modules/diff/libesm/convert/xml.js +31 -0
- package/.output/server/node_modules/diff/libesm/diff/array.js +16 -0
- package/.output/server/node_modules/diff/libesm/diff/base.js +253 -0
- package/.output/server/node_modules/diff/libesm/diff/character.js +7 -0
- package/.output/server/node_modules/diff/libesm/diff/css.js +10 -0
- package/.output/server/node_modules/diff/libesm/diff/json.js +78 -0
- package/.output/server/node_modules/diff/libesm/diff/line.js +65 -0
- package/.output/server/node_modules/diff/libesm/diff/sentence.js +43 -0
- package/.output/server/node_modules/diff/libesm/diff/word.js +296 -0
- package/.output/server/node_modules/diff/libesm/index.js +30 -0
- package/.output/server/node_modules/diff/libesm/package.json +1 -0
- package/.output/server/node_modules/diff/libesm/patch/apply.js +257 -0
- package/.output/server/node_modules/diff/libesm/patch/create.js +228 -0
- package/.output/server/node_modules/diff/libesm/patch/line-endings.js +44 -0
- package/.output/server/node_modules/diff/libesm/patch/parse.js +147 -0
- package/.output/server/node_modules/diff/libesm/patch/reverse.js +23 -0
- package/.output/server/node_modules/diff/libesm/util/distance-iterator.js +37 -0
- package/.output/server/node_modules/diff/libesm/util/params.js +14 -0
- package/.output/server/node_modules/diff/libesm/util/string.js +128 -0
- package/.output/server/node_modules/diff/package.json +132 -0
- package/.output/server/package.json +4 -1
- package/README.md +41 -0
- package/bin/prd +1 -1
- package/dist/host/src/index.js +10 -0
- package/dist/host/src/sync.js +201 -0
- package/dist/server/utils/db.js +64 -0
- package/dist/server/utils/git.js +8 -6
- package/dist/server/utils/prd-state.js +24 -2
- package/dist/server/utils/repos.js +12 -2
- package/dist/server/utils/state-migration.js +4 -3
- package/dist/server/utils/sync-apply.js +380 -0
- package/dist/server/utils/sync-export.js +183 -0
- package/dist/server/utils/sync-identity.js +231 -0
- package/dist/server/utils/sync-inspect.js +103 -0
- package/dist/server/utils/sync-merge.js +579 -0
- package/dist/server/utils/sync-schema.js +100 -0
- package/package.json +2 -1
- package/.output/public/_nuxt/6tINjQEd.js +0 -141
- package/.output/public/_nuxt/B2mIQf5X.js +0 -3
- package/.output/public/_nuxt/C0BBSDJ7.js +0 -1
- package/.output/public/_nuxt/CN46Bgts.js +0 -1
- package/.output/public/_nuxt/CTJgb0zb.js +0 -1
- package/.output/public/_nuxt/Cce168lk.js +0 -30
- package/.output/public/_nuxt/CyVSeLw5.js +0 -1
- package/.output/public/_nuxt/Detail.CYc96mGf.css +0 -1
- package/.output/public/_nuxt/ZNypZshD.js +0 -13
- package/.output/public/_nuxt/builds/meta/8c342d49-fe70-4f67-a987-821c16f86125.json +0 -1
- package/.output/public/_nuxt/entry.Bw0CE6Iz.css +0 -1
- package/.output/public/_nuxt/pYJYAY-W.js +0 -60
- package/.output/server/chunks/build/Detail-DMMUwTWr.mjs.map +0 -1
- package/.output/server/chunks/build/DiffViewer-styles-1.mjs-d2dQvARr.mjs +0 -4
- package/.output/server/chunks/build/DiffViewer-styles-1.mjs-d2dQvARr.mjs.map +0 -1
- package/.output/server/chunks/build/DiffViewer-styles-2.mjs-X6QKNjM0.mjs +0 -4
- package/.output/server/chunks/build/DiffViewer-styles-2.mjs-X6QKNjM0.mjs.map +0 -1
- package/.output/server/chunks/build/DiffViewer-styles.0AbHFl6N.mjs +0 -8
- package/.output/server/chunks/build/DiffViewer-styles.0AbHFl6N.mjs.map +0 -1
- package/.output/server/chunks/build/DiffViewer-styles.BDwAqkTk.mjs +0 -8
- package/.output/server/chunks/build/DiffViewer-styles.BDwAqkTk.mjs.map +0 -1
- package/.output/server/chunks/build/DiffViewer-styles.DRJh5Ui4.mjs +0 -10
- package/.output/server/chunks/build/DiffViewer-styles.DRJh5Ui4.mjs.map +0 -1
- package/.output/server/chunks/build/_prd_-ByugK4Yi.mjs.map +0 -1
- package/.output/server/chunks/build/default-BKKgG7HJ.mjs.map +0 -1
- package/.output/server/chunks/build/error-404-Bf6kdO80.mjs.map +0 -1
- package/.output/server/chunks/build/index-DE1tjHAd.mjs.map +0 -1
- package/.output/server/chunks/build/nuxt-link-SvT1nf8Z.mjs.map +0 -1
- package/.output/server/chunks/build/repo-graph-DzT45gSB.mjs.map +0 -1
- package/.output/server/chunks/build/usePrd-hXZOmvAv.mjs.map +0 -1
|
@@ -0,0 +1,831 @@
|
|
|
1
|
+
const matchers = [
|
|
2
|
+
[/^(<!--)(.+)(-->)$/, false],
|
|
3
|
+
[/^(\/\*)(.+)(\*\/)$/, false],
|
|
4
|
+
[/^(\/\/|["'#]|;{1,2}|%{1,2}|--)(.*)$/, true],
|
|
5
|
+
/**
|
|
6
|
+
* for multi-line comments like this
|
|
7
|
+
*/
|
|
8
|
+
[/^(\*)(.+)$/, true]
|
|
9
|
+
];
|
|
10
|
+
function parseComments(lines, jsx, matchAlgorithm) {
|
|
11
|
+
const out = [];
|
|
12
|
+
for (const line of lines) {
|
|
13
|
+
if (matchAlgorithm === "v3") {
|
|
14
|
+
const splittedElements = line.children.flatMap((element, idx) => {
|
|
15
|
+
if (element.type !== "element")
|
|
16
|
+
return element;
|
|
17
|
+
const token = element.children[0];
|
|
18
|
+
if (token.type !== "text")
|
|
19
|
+
return element;
|
|
20
|
+
const isLast = idx === line.children.length - 1;
|
|
21
|
+
const isComment = matchToken(token.value, isLast);
|
|
22
|
+
if (!isComment)
|
|
23
|
+
return element;
|
|
24
|
+
const rawSplits = token.value.split(/(\s+\/\/)/);
|
|
25
|
+
if (rawSplits.length <= 1)
|
|
26
|
+
return element;
|
|
27
|
+
let splits = [rawSplits[0]];
|
|
28
|
+
for (let i = 1; i < rawSplits.length; i += 2) {
|
|
29
|
+
splits.push(rawSplits[i] + (rawSplits[i + 1] || ""));
|
|
30
|
+
}
|
|
31
|
+
splits = splits.filter(Boolean);
|
|
32
|
+
if (splits.length <= 1)
|
|
33
|
+
return element;
|
|
34
|
+
return splits.map((split) => {
|
|
35
|
+
return {
|
|
36
|
+
...element,
|
|
37
|
+
children: [
|
|
38
|
+
{
|
|
39
|
+
type: "text",
|
|
40
|
+
value: split
|
|
41
|
+
}
|
|
42
|
+
]
|
|
43
|
+
};
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
if (splittedElements.length !== line.children.length)
|
|
47
|
+
line.children = splittedElements;
|
|
48
|
+
}
|
|
49
|
+
const elements = line.children;
|
|
50
|
+
let start = elements.length - 1;
|
|
51
|
+
if (matchAlgorithm === "v1")
|
|
52
|
+
start = 0;
|
|
53
|
+
else if (jsx)
|
|
54
|
+
start = elements.length - 2;
|
|
55
|
+
for (let i = Math.max(start, 0); i < elements.length; i++) {
|
|
56
|
+
const token = elements[i];
|
|
57
|
+
if (token.type !== "element")
|
|
58
|
+
continue;
|
|
59
|
+
const head = token.children.at(0);
|
|
60
|
+
if (head?.type !== "text")
|
|
61
|
+
continue;
|
|
62
|
+
const isLast = i === elements.length - 1;
|
|
63
|
+
let match = matchToken(head.value, isLast);
|
|
64
|
+
let additionalTokens;
|
|
65
|
+
if (!match && i > 0 && head.value.trim().startsWith("[!code")) {
|
|
66
|
+
const prevToken = elements[i - 1];
|
|
67
|
+
if (prevToken?.type === "element") {
|
|
68
|
+
const prevHead = prevToken.children.at(0);
|
|
69
|
+
if (prevHead?.type === "text" && prevHead.value.includes("//")) {
|
|
70
|
+
const combinedValue = prevHead.value + head.value;
|
|
71
|
+
const combinedMatch = matchToken(combinedValue, isLast);
|
|
72
|
+
if (combinedMatch) {
|
|
73
|
+
match = combinedMatch;
|
|
74
|
+
out.push({
|
|
75
|
+
info: combinedMatch,
|
|
76
|
+
line,
|
|
77
|
+
token: prevToken,
|
|
78
|
+
// Use the previous token as the main token
|
|
79
|
+
isLineCommentOnly: elements.length === 2 && prevToken.children.length === 1 && token.children.length === 1,
|
|
80
|
+
isJsxStyle: false,
|
|
81
|
+
additionalTokens: [token]
|
|
82
|
+
// Current token is the additional one
|
|
83
|
+
});
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
if (!match)
|
|
90
|
+
continue;
|
|
91
|
+
if (jsx && !isLast && i !== 0) {
|
|
92
|
+
const isJsxStyle = isValue(elements[i - 1], "{") && isValue(elements[i + 1], "}");
|
|
93
|
+
out.push({
|
|
94
|
+
info: match,
|
|
95
|
+
line,
|
|
96
|
+
token,
|
|
97
|
+
isLineCommentOnly: elements.length === 3 && token.children.length === 1,
|
|
98
|
+
isJsxStyle,
|
|
99
|
+
additionalTokens
|
|
100
|
+
});
|
|
101
|
+
} else {
|
|
102
|
+
out.push({
|
|
103
|
+
info: match,
|
|
104
|
+
line,
|
|
105
|
+
token,
|
|
106
|
+
isLineCommentOnly: elements.length === 1 && token.children.length === 1,
|
|
107
|
+
isJsxStyle: false,
|
|
108
|
+
additionalTokens
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return out;
|
|
114
|
+
}
|
|
115
|
+
function isValue(element, value) {
|
|
116
|
+
if (element.type !== "element")
|
|
117
|
+
return false;
|
|
118
|
+
const text = element.children[0];
|
|
119
|
+
if (text.type !== "text")
|
|
120
|
+
return false;
|
|
121
|
+
return text.value.trim() === value;
|
|
122
|
+
}
|
|
123
|
+
function matchToken(text, isLast) {
|
|
124
|
+
let trimmed = text.trimStart();
|
|
125
|
+
const spaceFront = text.length - trimmed.length;
|
|
126
|
+
trimmed = trimmed.trimEnd();
|
|
127
|
+
const spaceEnd = text.length - trimmed.length - spaceFront;
|
|
128
|
+
for (const [matcher, endOfLine] of matchers) {
|
|
129
|
+
if (endOfLine && !isLast)
|
|
130
|
+
continue;
|
|
131
|
+
const result = matcher.exec(trimmed);
|
|
132
|
+
if (!result)
|
|
133
|
+
continue;
|
|
134
|
+
return [
|
|
135
|
+
" ".repeat(spaceFront) + result[1],
|
|
136
|
+
result[2],
|
|
137
|
+
result[3] ? result[3] + " ".repeat(spaceEnd) : void 0
|
|
138
|
+
];
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
function v1ClearEndCommentPrefix(text) {
|
|
142
|
+
const match = text.match(/(?:\/\/|["'#]|;{1,2}|%{1,2}|--)(\s*)$/);
|
|
143
|
+
if (match && match[1].trim().length === 0) {
|
|
144
|
+
return text.slice(0, match.index);
|
|
145
|
+
}
|
|
146
|
+
return text;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function createCommentNotationTransformer(name, regex, onMatch, matchAlgorithm) {
|
|
150
|
+
if (matchAlgorithm == null) {
|
|
151
|
+
matchAlgorithm = "v3";
|
|
152
|
+
}
|
|
153
|
+
return {
|
|
154
|
+
name,
|
|
155
|
+
code(code) {
|
|
156
|
+
const lines = code.children.filter((i) => i.type === "element");
|
|
157
|
+
const linesToRemove = [];
|
|
158
|
+
code.data ??= {};
|
|
159
|
+
const data = code.data;
|
|
160
|
+
data._shiki_notation ??= parseComments(lines, ["jsx", "tsx"].includes(this.options.lang), matchAlgorithm);
|
|
161
|
+
const parsed = data._shiki_notation;
|
|
162
|
+
for (const comment of parsed) {
|
|
163
|
+
if (comment.info[1].length === 0)
|
|
164
|
+
continue;
|
|
165
|
+
let lineIdx = lines.indexOf(comment.line);
|
|
166
|
+
if (comment.isLineCommentOnly && matchAlgorithm !== "v1")
|
|
167
|
+
lineIdx++;
|
|
168
|
+
let replaced = false;
|
|
169
|
+
comment.info[1] = comment.info[1].replace(regex, (...match) => {
|
|
170
|
+
if (onMatch.call(this, match, comment.line, comment.token, lines, lineIdx)) {
|
|
171
|
+
replaced = true;
|
|
172
|
+
return "";
|
|
173
|
+
}
|
|
174
|
+
return match[0];
|
|
175
|
+
});
|
|
176
|
+
if (!replaced)
|
|
177
|
+
continue;
|
|
178
|
+
if (matchAlgorithm === "v1")
|
|
179
|
+
comment.info[1] = v1ClearEndCommentPrefix(comment.info[1]);
|
|
180
|
+
const isEmpty = comment.info[1].trim().length === 0;
|
|
181
|
+
if (isEmpty)
|
|
182
|
+
comment.info[1] = "";
|
|
183
|
+
if (isEmpty && comment.isLineCommentOnly) {
|
|
184
|
+
linesToRemove.push(comment.line);
|
|
185
|
+
} else if (isEmpty && comment.isJsxStyle) {
|
|
186
|
+
comment.line.children.splice(comment.line.children.indexOf(comment.token) - 1, 3);
|
|
187
|
+
} else if (isEmpty) {
|
|
188
|
+
if (comment.additionalTokens) {
|
|
189
|
+
for (let j = comment.additionalTokens.length - 1; j >= 0; j--) {
|
|
190
|
+
const additionalToken = comment.additionalTokens[j];
|
|
191
|
+
const tokenIndex = comment.line.children.indexOf(additionalToken);
|
|
192
|
+
if (tokenIndex !== -1) {
|
|
193
|
+
comment.line.children.splice(tokenIndex, 1);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
comment.line.children.splice(comment.line.children.indexOf(comment.token), 1);
|
|
198
|
+
} else {
|
|
199
|
+
const head = comment.token.children[0];
|
|
200
|
+
if (head.type === "text") {
|
|
201
|
+
head.value = comment.info.join("");
|
|
202
|
+
if (comment.additionalTokens) {
|
|
203
|
+
for (const additionalToken of comment.additionalTokens) {
|
|
204
|
+
const additionalHead = additionalToken.children[0];
|
|
205
|
+
if (additionalHead?.type === "text") {
|
|
206
|
+
additionalHead.value = "";
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
for (const line of linesToRemove) {
|
|
214
|
+
const index = code.children.indexOf(line);
|
|
215
|
+
const nextLine = code.children[index + 1];
|
|
216
|
+
let removeLength = 1;
|
|
217
|
+
if (nextLine?.type === "text" && nextLine?.value === "\n")
|
|
218
|
+
removeLength = 2;
|
|
219
|
+
code.children.splice(index, removeLength);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
function transformerCompactLineOptions(lineOptions = []) {
|
|
226
|
+
return {
|
|
227
|
+
name: "@shikijs/transformers:compact-line-options",
|
|
228
|
+
line(node, line) {
|
|
229
|
+
const lineOption = lineOptions.find((o) => o.line === line);
|
|
230
|
+
if (lineOption?.classes)
|
|
231
|
+
this.addClassToHast(node, lineOption.classes);
|
|
232
|
+
return node;
|
|
233
|
+
}
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
function parseMetaHighlightString(meta) {
|
|
238
|
+
if (!meta)
|
|
239
|
+
return null;
|
|
240
|
+
const match = meta.match(/\{([\d,-]+)\}/);
|
|
241
|
+
if (!match)
|
|
242
|
+
return null;
|
|
243
|
+
const lines = match[1].split(",").flatMap((v) => {
|
|
244
|
+
const range = v.split("-").map((n) => Number.parseInt(n, 10));
|
|
245
|
+
return range.length === 1 ? [range[0]] : Array.from({ length: range[1] - range[0] + 1 }, (_, i) => range[0] + i);
|
|
246
|
+
});
|
|
247
|
+
return lines;
|
|
248
|
+
}
|
|
249
|
+
const symbol = /* @__PURE__ */ Symbol("highlighted-lines");
|
|
250
|
+
function transformerMetaHighlight(options = {}) {
|
|
251
|
+
const { className = "highlighted", zeroIndexed = false } = options;
|
|
252
|
+
return {
|
|
253
|
+
name: "@shikijs/transformers:meta-highlight",
|
|
254
|
+
line(node, lineNumber) {
|
|
255
|
+
if (!this.options.meta?.__raw)
|
|
256
|
+
return;
|
|
257
|
+
const meta = this.meta;
|
|
258
|
+
meta[symbol] ??= parseMetaHighlightString(this.options.meta.__raw);
|
|
259
|
+
const highlightedLines = meta[symbol] ?? [];
|
|
260
|
+
const effectiveLine = zeroIndexed ? lineNumber - 1 : lineNumber;
|
|
261
|
+
if (highlightedLines.includes(effectiveLine))
|
|
262
|
+
this.addClassToHast(node, className);
|
|
263
|
+
return node;
|
|
264
|
+
}
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
function parseMetaHighlightWords(meta) {
|
|
269
|
+
if (!meta)
|
|
270
|
+
return [];
|
|
271
|
+
const match = Array.from(meta.matchAll(/\/((?:\\.|[^/])+)\//g));
|
|
272
|
+
return match.map((v) => v[1].replace(/\\(.)/g, "$1"));
|
|
273
|
+
}
|
|
274
|
+
function transformerMetaWordHighlight(options = {}) {
|
|
275
|
+
const {
|
|
276
|
+
className = "highlighted-word"
|
|
277
|
+
} = options;
|
|
278
|
+
return {
|
|
279
|
+
name: "@shikijs/transformers:meta-word-highlight",
|
|
280
|
+
preprocess(code, options2) {
|
|
281
|
+
if (!this.options.meta?.__raw)
|
|
282
|
+
return;
|
|
283
|
+
const words = parseMetaHighlightWords(this.options.meta.__raw);
|
|
284
|
+
options2.decorations ||= [];
|
|
285
|
+
for (const word of words) {
|
|
286
|
+
const indexes = findAllSubstringIndexes(code, word);
|
|
287
|
+
for (const index of indexes) {
|
|
288
|
+
options2.decorations.push({
|
|
289
|
+
start: index,
|
|
290
|
+
end: index + word.length,
|
|
291
|
+
properties: {
|
|
292
|
+
class: className
|
|
293
|
+
}
|
|
294
|
+
});
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
};
|
|
299
|
+
}
|
|
300
|
+
function findAllSubstringIndexes(str, substr) {
|
|
301
|
+
const indexes = [];
|
|
302
|
+
let cursor = 0;
|
|
303
|
+
while (true) {
|
|
304
|
+
const index = str.indexOf(substr, cursor);
|
|
305
|
+
if (index === -1 || index >= str.length)
|
|
306
|
+
break;
|
|
307
|
+
if (index < cursor)
|
|
308
|
+
break;
|
|
309
|
+
indexes.push(index);
|
|
310
|
+
cursor = index + substr.length;
|
|
311
|
+
}
|
|
312
|
+
return indexes;
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
function escapeRegExp(str) {
|
|
316
|
+
return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
317
|
+
}
|
|
318
|
+
function transformerNotationMap(options = {}, name = "@shikijs/transformers:notation-map") {
|
|
319
|
+
const {
|
|
320
|
+
classMap = {},
|
|
321
|
+
classActivePre = void 0,
|
|
322
|
+
classActiveCode = void 0
|
|
323
|
+
} = options;
|
|
324
|
+
return createCommentNotationTransformer(
|
|
325
|
+
name,
|
|
326
|
+
new RegExp(`#?\\s*\\[!code (${Object.keys(classMap).map(escapeRegExp).join("|")})(:\\d+)?\\]`, "gi"),
|
|
327
|
+
function([_, match, range = ":1"], _line, _comment, lines, index) {
|
|
328
|
+
const lineNum = Number.parseInt(range.slice(1), 10);
|
|
329
|
+
for (let i = index; i < Math.min(index + lineNum, lines.length); i++) {
|
|
330
|
+
this.addClassToHast(lines[i], classMap[match]);
|
|
331
|
+
}
|
|
332
|
+
if (classActivePre)
|
|
333
|
+
this.addClassToHast(this.pre, classActivePre);
|
|
334
|
+
if (classActiveCode)
|
|
335
|
+
this.addClassToHast(this.code, classActiveCode);
|
|
336
|
+
return true;
|
|
337
|
+
},
|
|
338
|
+
options.matchAlgorithm
|
|
339
|
+
);
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
function transformerNotationDiff(options = {}) {
|
|
343
|
+
const {
|
|
344
|
+
classLineAdd = "diff add",
|
|
345
|
+
classLineRemove = "diff remove",
|
|
346
|
+
classActivePre = "has-diff",
|
|
347
|
+
classActiveCode
|
|
348
|
+
} = options;
|
|
349
|
+
return transformerNotationMap(
|
|
350
|
+
{
|
|
351
|
+
classMap: {
|
|
352
|
+
"++": classLineAdd,
|
|
353
|
+
"--": classLineRemove
|
|
354
|
+
},
|
|
355
|
+
classActivePre,
|
|
356
|
+
classActiveCode,
|
|
357
|
+
matchAlgorithm: options.matchAlgorithm
|
|
358
|
+
},
|
|
359
|
+
"@shikijs/transformers:notation-diff"
|
|
360
|
+
);
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
function transformerNotationErrorLevel(options = {}) {
|
|
364
|
+
const {
|
|
365
|
+
classMap = {
|
|
366
|
+
error: ["highlighted", "error"],
|
|
367
|
+
warning: ["highlighted", "warning"],
|
|
368
|
+
info: ["highlighted", "info"]
|
|
369
|
+
},
|
|
370
|
+
classActivePre = "has-highlighted",
|
|
371
|
+
classActiveCode
|
|
372
|
+
} = options;
|
|
373
|
+
return transformerNotationMap(
|
|
374
|
+
{
|
|
375
|
+
classMap,
|
|
376
|
+
classActivePre,
|
|
377
|
+
classActiveCode,
|
|
378
|
+
matchAlgorithm: options.matchAlgorithm
|
|
379
|
+
},
|
|
380
|
+
"@shikijs/transformers:notation-error-level"
|
|
381
|
+
);
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
function transformerNotationFocus(options = {}) {
|
|
385
|
+
const {
|
|
386
|
+
classActiveLine = "focused",
|
|
387
|
+
classActivePre = "has-focused",
|
|
388
|
+
classActiveCode
|
|
389
|
+
} = options;
|
|
390
|
+
return transformerNotationMap(
|
|
391
|
+
{
|
|
392
|
+
classMap: {
|
|
393
|
+
focus: classActiveLine
|
|
394
|
+
},
|
|
395
|
+
classActivePre,
|
|
396
|
+
classActiveCode,
|
|
397
|
+
matchAlgorithm: options.matchAlgorithm
|
|
398
|
+
},
|
|
399
|
+
"@shikijs/transformers:notation-focus"
|
|
400
|
+
);
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
function transformerNotationHighlight(options = {}) {
|
|
404
|
+
const {
|
|
405
|
+
classActiveLine = "highlighted",
|
|
406
|
+
classActivePre = "has-highlighted",
|
|
407
|
+
classActiveCode
|
|
408
|
+
} = options;
|
|
409
|
+
return transformerNotationMap(
|
|
410
|
+
{
|
|
411
|
+
classMap: {
|
|
412
|
+
highlight: classActiveLine,
|
|
413
|
+
hl: classActiveLine
|
|
414
|
+
},
|
|
415
|
+
classActivePre,
|
|
416
|
+
classActiveCode,
|
|
417
|
+
matchAlgorithm: options.matchAlgorithm
|
|
418
|
+
},
|
|
419
|
+
"@shikijs/transformers:notation-highlight"
|
|
420
|
+
);
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
function highlightWordInLine(line, ignoredElement, word, className) {
|
|
424
|
+
const content = getTextContent(line);
|
|
425
|
+
let index = content.indexOf(word);
|
|
426
|
+
while (index !== -1) {
|
|
427
|
+
highlightRange.call(this, line.children, ignoredElement, index, word.length, className);
|
|
428
|
+
index = content.indexOf(word, index + 1);
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
function getTextContent(element) {
|
|
432
|
+
if (element.type === "text")
|
|
433
|
+
return element.value;
|
|
434
|
+
if (element.type === "element" && element.tagName === "span")
|
|
435
|
+
return element.children.map(getTextContent).join("");
|
|
436
|
+
return "";
|
|
437
|
+
}
|
|
438
|
+
function highlightRange(elements, ignoredElement, index, len, className) {
|
|
439
|
+
let currentIdx = 0;
|
|
440
|
+
for (let i = 0; i < elements.length; i++) {
|
|
441
|
+
const element = elements[i];
|
|
442
|
+
if (element.type !== "element" || element.tagName !== "span" || element === ignoredElement)
|
|
443
|
+
continue;
|
|
444
|
+
const textNode = element.children[0];
|
|
445
|
+
if (textNode.type !== "text")
|
|
446
|
+
continue;
|
|
447
|
+
if (hasOverlap([currentIdx, currentIdx + textNode.value.length - 1], [index, index + len])) {
|
|
448
|
+
const start = Math.max(0, index - currentIdx);
|
|
449
|
+
const length = len - Math.max(0, currentIdx - index);
|
|
450
|
+
if (length === 0)
|
|
451
|
+
continue;
|
|
452
|
+
const separated = separateToken(element, textNode, start, length);
|
|
453
|
+
this.addClassToHast(separated[1], className);
|
|
454
|
+
const output = separated.filter(Boolean);
|
|
455
|
+
elements.splice(i, 1, ...output);
|
|
456
|
+
i += output.length - 1;
|
|
457
|
+
}
|
|
458
|
+
currentIdx += textNode.value.length;
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
function hasOverlap(range1, range2) {
|
|
462
|
+
return range1[0] <= range2[1] && range1[1] >= range2[0];
|
|
463
|
+
}
|
|
464
|
+
function separateToken(span, textNode, index, len) {
|
|
465
|
+
const text = textNode.value;
|
|
466
|
+
const createNode = (value) => inheritElement(span, {
|
|
467
|
+
children: [
|
|
468
|
+
{
|
|
469
|
+
type: "text",
|
|
470
|
+
value
|
|
471
|
+
}
|
|
472
|
+
]
|
|
473
|
+
});
|
|
474
|
+
return [
|
|
475
|
+
index > 0 ? createNode(text.slice(0, index)) : void 0,
|
|
476
|
+
createNode(text.slice(index, index + len)),
|
|
477
|
+
index + len < text.length ? createNode(text.slice(index + len)) : void 0
|
|
478
|
+
];
|
|
479
|
+
}
|
|
480
|
+
function inheritElement(original, overrides) {
|
|
481
|
+
return {
|
|
482
|
+
...original,
|
|
483
|
+
properties: {
|
|
484
|
+
...original.properties
|
|
485
|
+
},
|
|
486
|
+
...overrides
|
|
487
|
+
};
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
function transformerNotationWordHighlight(options = {}) {
|
|
491
|
+
const {
|
|
492
|
+
classActiveWord = "highlighted-word",
|
|
493
|
+
classActivePre = void 0
|
|
494
|
+
} = options;
|
|
495
|
+
return createCommentNotationTransformer(
|
|
496
|
+
"@shikijs/transformers:notation-highlight-word",
|
|
497
|
+
/\s*\[!code word:((?:\\.|[^:\]])+)(:\d+)?\]/,
|
|
498
|
+
function([_, word, range], _line, comment, lines, index) {
|
|
499
|
+
const lineNum = range ? Number.parseInt(range.slice(1), 10) : lines.length;
|
|
500
|
+
word = word.replace(/\\(.)/g, "$1");
|
|
501
|
+
for (let i = index; i < Math.min(index + lineNum, lines.length); i++) {
|
|
502
|
+
highlightWordInLine.call(this, lines[i], comment, word, classActiveWord);
|
|
503
|
+
}
|
|
504
|
+
if (classActivePre)
|
|
505
|
+
this.addClassToHast(this.pre, classActivePre);
|
|
506
|
+
return true;
|
|
507
|
+
},
|
|
508
|
+
options.matchAlgorithm
|
|
509
|
+
);
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
function transformerRemoveComments(options = {}) {
|
|
513
|
+
const { removeEmptyLines = true } = options;
|
|
514
|
+
return {
|
|
515
|
+
name: "@shikijs/transformers:remove-comments",
|
|
516
|
+
preprocess(_code, options2) {
|
|
517
|
+
if (options2.includeExplanation !== true && options2.includeExplanation !== "scopeName")
|
|
518
|
+
throw new Error("`transformerRemoveComments` requires `includeExplanation` to be set to `true` or `'scopeName'`");
|
|
519
|
+
},
|
|
520
|
+
tokens(tokens) {
|
|
521
|
+
const result = [];
|
|
522
|
+
for (const line of tokens) {
|
|
523
|
+
const filteredLine = [];
|
|
524
|
+
let hasComment = false;
|
|
525
|
+
for (const token of line) {
|
|
526
|
+
const isComment = token.explanation?.some(
|
|
527
|
+
(exp) => exp.scopes.some((s) => s.scopeName.startsWith("comment"))
|
|
528
|
+
);
|
|
529
|
+
if (isComment) {
|
|
530
|
+
hasComment = true;
|
|
531
|
+
} else {
|
|
532
|
+
filteredLine.push(token);
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
if (removeEmptyLines && hasComment) {
|
|
536
|
+
const isAllWhitespace = filteredLine.every((token) => !token.content.trim());
|
|
537
|
+
if (isAllWhitespace)
|
|
538
|
+
continue;
|
|
539
|
+
}
|
|
540
|
+
result.push(filteredLine);
|
|
541
|
+
}
|
|
542
|
+
return result;
|
|
543
|
+
}
|
|
544
|
+
};
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
function transformerRemoveLineBreak() {
|
|
548
|
+
return {
|
|
549
|
+
name: "@shikijs/transformers:remove-line-break",
|
|
550
|
+
code(code) {
|
|
551
|
+
code.children = code.children.filter((line) => !(line.type === "text" && line.value === "\n"));
|
|
552
|
+
}
|
|
553
|
+
};
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
function transformerRemoveNotationEscape() {
|
|
557
|
+
return {
|
|
558
|
+
name: "@shikijs/transformers:remove-notation-escape",
|
|
559
|
+
code(hast) {
|
|
560
|
+
function replace(node) {
|
|
561
|
+
if (node.type === "text") {
|
|
562
|
+
node.value = node.value.replace("[\\!code", "[!code");
|
|
563
|
+
} else if ("children" in node) {
|
|
564
|
+
for (const child of node.children) {
|
|
565
|
+
replace(child);
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
replace(hast);
|
|
570
|
+
return hast;
|
|
571
|
+
}
|
|
572
|
+
};
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
function transformerRenderIndentGuides(options = {}) {
|
|
576
|
+
return {
|
|
577
|
+
name: "@shikijs/transformers:render-indent-guides",
|
|
578
|
+
code(hast) {
|
|
579
|
+
const indent = Number(
|
|
580
|
+
this.options.meta?.indent ?? this.options.meta?.__raw?.match(/\{indent:(\d+|false)\}/)?.[1] ?? options.indent ?? 2
|
|
581
|
+
);
|
|
582
|
+
if (Number.isNaN(indent) || indent <= 0) {
|
|
583
|
+
return hast;
|
|
584
|
+
}
|
|
585
|
+
const indentRegex = new RegExp(` {${indent}}| {0,${indent - 1}} | {1,}$`, "g");
|
|
586
|
+
const emptyLines = [];
|
|
587
|
+
let level = 0;
|
|
588
|
+
for (const line of hast.children) {
|
|
589
|
+
if (line.type !== "element") {
|
|
590
|
+
continue;
|
|
591
|
+
}
|
|
592
|
+
const first = line.children[0];
|
|
593
|
+
if (first?.type !== "element" || first?.children[0]?.type !== "text") {
|
|
594
|
+
emptyLines.push([line, level]);
|
|
595
|
+
continue;
|
|
596
|
+
}
|
|
597
|
+
const text = first.children[0];
|
|
598
|
+
const blanks = text.value.split(/[^ \t]/, 1)[0];
|
|
599
|
+
const ranges = [];
|
|
600
|
+
for (const match of blanks.matchAll(indentRegex)) {
|
|
601
|
+
const start = match.index;
|
|
602
|
+
const end = start + match[0].length;
|
|
603
|
+
ranges.push([start, end]);
|
|
604
|
+
}
|
|
605
|
+
for (const [line2, level2] of emptyLines) {
|
|
606
|
+
line2.children.unshift(...Array.from({ length: Math.min(ranges.length, level2 + 1) }, (_, i) => ({
|
|
607
|
+
type: "element",
|
|
608
|
+
tagName: "span",
|
|
609
|
+
properties: {
|
|
610
|
+
class: "indent",
|
|
611
|
+
style: `--indent-offset: ${i * indent}ch;`
|
|
612
|
+
},
|
|
613
|
+
children: []
|
|
614
|
+
})));
|
|
615
|
+
}
|
|
616
|
+
emptyLines.length = 0;
|
|
617
|
+
level = ranges.length;
|
|
618
|
+
if (ranges.length) {
|
|
619
|
+
line.children.unshift(
|
|
620
|
+
...ranges.map(([start, end]) => ({
|
|
621
|
+
type: "element",
|
|
622
|
+
tagName: "span",
|
|
623
|
+
properties: {
|
|
624
|
+
class: "indent"
|
|
625
|
+
},
|
|
626
|
+
children: [{
|
|
627
|
+
type: "text",
|
|
628
|
+
value: text.value.slice(start, end)
|
|
629
|
+
}]
|
|
630
|
+
}))
|
|
631
|
+
);
|
|
632
|
+
text.value = text.value.slice(ranges.at(-1)[1]);
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
return hast;
|
|
636
|
+
}
|
|
637
|
+
};
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
function isTab(part) {
|
|
641
|
+
return part === " ";
|
|
642
|
+
}
|
|
643
|
+
function isSpace(part) {
|
|
644
|
+
return part === " " || part === " ";
|
|
645
|
+
}
|
|
646
|
+
function separateContinuousSpaces(inputs) {
|
|
647
|
+
const result = [];
|
|
648
|
+
let current = "";
|
|
649
|
+
function bump() {
|
|
650
|
+
if (current.length)
|
|
651
|
+
result.push(current);
|
|
652
|
+
current = "";
|
|
653
|
+
}
|
|
654
|
+
inputs.forEach((part, idx) => {
|
|
655
|
+
if (isTab(part)) {
|
|
656
|
+
bump();
|
|
657
|
+
result.push(part);
|
|
658
|
+
} else if (isSpace(part) && (isSpace(inputs[idx - 1]) || isSpace(inputs[idx + 1]))) {
|
|
659
|
+
bump();
|
|
660
|
+
result.push(part);
|
|
661
|
+
} else {
|
|
662
|
+
current += part;
|
|
663
|
+
}
|
|
664
|
+
});
|
|
665
|
+
bump();
|
|
666
|
+
return result;
|
|
667
|
+
}
|
|
668
|
+
function splitSpaces(parts, type, renderContinuousSpaces = true) {
|
|
669
|
+
if (type === "all")
|
|
670
|
+
return parts;
|
|
671
|
+
let leftCount = 0;
|
|
672
|
+
let rightCount = 0;
|
|
673
|
+
if (type === "boundary" || type === "leading") {
|
|
674
|
+
for (let i = 0; i < parts.length; i++) {
|
|
675
|
+
if (isSpace(parts[i]))
|
|
676
|
+
leftCount++;
|
|
677
|
+
else
|
|
678
|
+
break;
|
|
679
|
+
}
|
|
680
|
+
}
|
|
681
|
+
if (type === "boundary" || type === "trailing") {
|
|
682
|
+
for (let i = parts.length - 1; i >= 0; i--) {
|
|
683
|
+
if (isSpace(parts[i]))
|
|
684
|
+
rightCount++;
|
|
685
|
+
else
|
|
686
|
+
break;
|
|
687
|
+
}
|
|
688
|
+
}
|
|
689
|
+
const middle = parts.slice(leftCount, parts.length - rightCount);
|
|
690
|
+
return [
|
|
691
|
+
...parts.slice(0, leftCount),
|
|
692
|
+
...renderContinuousSpaces ? separateContinuousSpaces(middle) : [middle.join("")],
|
|
693
|
+
...parts.slice(parts.length - rightCount)
|
|
694
|
+
];
|
|
695
|
+
}
|
|
696
|
+
|
|
697
|
+
function transformerRenderWhitespace(options = {}) {
|
|
698
|
+
const classMap = {
|
|
699
|
+
" ": options.classSpace ?? "space",
|
|
700
|
+
" ": options.classTab ?? "tab"
|
|
701
|
+
};
|
|
702
|
+
const position = options.position ?? "all";
|
|
703
|
+
const keys = Object.keys(classMap);
|
|
704
|
+
return {
|
|
705
|
+
name: "@shikijs/transformers:render-whitespace",
|
|
706
|
+
// We use `root` hook here to ensure it runs after all other transformers
|
|
707
|
+
root(root) {
|
|
708
|
+
const pre = root.children[0];
|
|
709
|
+
const code = pre.tagName === "pre" ? pre.children[0] : { children: [root] };
|
|
710
|
+
code.children.forEach(
|
|
711
|
+
(line) => {
|
|
712
|
+
if (line.type !== "element" && line.type !== "root")
|
|
713
|
+
return;
|
|
714
|
+
const elements = line.children.filter((token) => token.type === "element");
|
|
715
|
+
const last = elements.length - 1;
|
|
716
|
+
line.children = line.children.flatMap((token) => {
|
|
717
|
+
if (token.type !== "element")
|
|
718
|
+
return token;
|
|
719
|
+
const index = elements.indexOf(token);
|
|
720
|
+
if (position === "boundary" && index !== 0 && index !== last)
|
|
721
|
+
return token;
|
|
722
|
+
if (position === "trailing" && index !== last)
|
|
723
|
+
return token;
|
|
724
|
+
if (position === "leading" && index !== 0)
|
|
725
|
+
return token;
|
|
726
|
+
const node = token.children[0];
|
|
727
|
+
if (node.type !== "text" || !node.value)
|
|
728
|
+
return token;
|
|
729
|
+
const parts = splitSpaces(
|
|
730
|
+
node.value.split(/([ \t])/).filter((i) => i.length),
|
|
731
|
+
position === "boundary" && index === last && last !== 0 ? "trailing" : position,
|
|
732
|
+
position !== "trailing" && position !== "leading"
|
|
733
|
+
);
|
|
734
|
+
if (parts.length <= 1)
|
|
735
|
+
return token;
|
|
736
|
+
return parts.map((part) => {
|
|
737
|
+
const clone = {
|
|
738
|
+
...token,
|
|
739
|
+
properties: { ...token.properties }
|
|
740
|
+
};
|
|
741
|
+
clone.children = [{ type: "text", value: part }];
|
|
742
|
+
if (keys.includes(part)) {
|
|
743
|
+
this.addClassToHast(clone, classMap[part]);
|
|
744
|
+
delete clone.properties.style;
|
|
745
|
+
}
|
|
746
|
+
return clone;
|
|
747
|
+
});
|
|
748
|
+
});
|
|
749
|
+
}
|
|
750
|
+
);
|
|
751
|
+
}
|
|
752
|
+
};
|
|
753
|
+
}
|
|
754
|
+
|
|
755
|
+
function transformerStyleToClass(options = {}) {
|
|
756
|
+
const {
|
|
757
|
+
classPrefix = "__shiki_",
|
|
758
|
+
classSuffix = "",
|
|
759
|
+
classReplacer = (className) => className
|
|
760
|
+
} = options;
|
|
761
|
+
const classToStyle = /* @__PURE__ */ new Map();
|
|
762
|
+
function stringifyStyle(style) {
|
|
763
|
+
return Object.entries(style).map(([key, value]) => `${key}:${value}`).join(";");
|
|
764
|
+
}
|
|
765
|
+
function registerStyle(style) {
|
|
766
|
+
const str = typeof style === "string" ? style : stringifyStyle(style);
|
|
767
|
+
let className = classPrefix + cyrb53(str) + classSuffix;
|
|
768
|
+
className = classReplacer(className);
|
|
769
|
+
if (!classToStyle.has(className)) {
|
|
770
|
+
classToStyle.set(
|
|
771
|
+
className,
|
|
772
|
+
typeof style === "string" ? style : { ...style }
|
|
773
|
+
);
|
|
774
|
+
}
|
|
775
|
+
return className;
|
|
776
|
+
}
|
|
777
|
+
return {
|
|
778
|
+
name: "@shikijs/transformers:style-to-class",
|
|
779
|
+
pre(t) {
|
|
780
|
+
if (!t.properties.style)
|
|
781
|
+
return;
|
|
782
|
+
const className = registerStyle(t.properties.style);
|
|
783
|
+
delete t.properties.style;
|
|
784
|
+
this.addClassToHast(t, className);
|
|
785
|
+
},
|
|
786
|
+
tokens(lines) {
|
|
787
|
+
for (const line of lines) {
|
|
788
|
+
for (const token of line) {
|
|
789
|
+
if (!token.htmlStyle)
|
|
790
|
+
continue;
|
|
791
|
+
const className = registerStyle(token.htmlStyle);
|
|
792
|
+
token.htmlStyle = {};
|
|
793
|
+
token.htmlAttrs ||= {};
|
|
794
|
+
if (!token.htmlAttrs.class)
|
|
795
|
+
token.htmlAttrs.class = className;
|
|
796
|
+
else
|
|
797
|
+
token.htmlAttrs.class += ` ${className}`;
|
|
798
|
+
}
|
|
799
|
+
}
|
|
800
|
+
},
|
|
801
|
+
getClassRegistry() {
|
|
802
|
+
return classToStyle;
|
|
803
|
+
},
|
|
804
|
+
getCSS() {
|
|
805
|
+
let css = "";
|
|
806
|
+
for (const [className, style] of classToStyle.entries()) {
|
|
807
|
+
css += `.${className}{${typeof style === "string" ? style : stringifyStyle(style)}}`;
|
|
808
|
+
}
|
|
809
|
+
return css;
|
|
810
|
+
},
|
|
811
|
+
clearRegistry() {
|
|
812
|
+
classToStyle.clear();
|
|
813
|
+
}
|
|
814
|
+
};
|
|
815
|
+
}
|
|
816
|
+
function cyrb53(str, seed = 0) {
|
|
817
|
+
let h1 = 3735928559 ^ seed;
|
|
818
|
+
let h2 = 1103547991 ^ seed;
|
|
819
|
+
for (let i = 0, ch; i < str.length; i++) {
|
|
820
|
+
ch = str.charCodeAt(i);
|
|
821
|
+
h1 = Math.imul(h1 ^ ch, 2654435761);
|
|
822
|
+
h2 = Math.imul(h2 ^ ch, 1597334677);
|
|
823
|
+
}
|
|
824
|
+
h1 = Math.imul(h1 ^ h1 >>> 16, 2246822507);
|
|
825
|
+
h1 ^= Math.imul(h2 ^ h2 >>> 13, 3266489909);
|
|
826
|
+
h2 = Math.imul(h2 ^ h2 >>> 16, 2246822507);
|
|
827
|
+
h2 ^= Math.imul(h1 ^ h1 >>> 13, 3266489909);
|
|
828
|
+
return (4294967296 * (2097151 & h2) + (h1 >>> 0)).toString(36).slice(0, 6);
|
|
829
|
+
}
|
|
830
|
+
|
|
831
|
+
export { createCommentNotationTransformer, findAllSubstringIndexes, parseMetaHighlightString, parseMetaHighlightWords, transformerCompactLineOptions, transformerMetaHighlight, transformerMetaWordHighlight, transformerNotationDiff, transformerNotationErrorLevel, transformerNotationFocus, transformerNotationHighlight, transformerNotationMap, transformerNotationWordHighlight, transformerRemoveComments, transformerRemoveLineBreak, transformerRemoveNotationEscape, transformerRenderIndentGuides, transformerRenderWhitespace, transformerStyleToClass };
|