@youtyan/code-viewer 0.1.48 → 0.1.50
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/web/app.js +100 -30
package/package.json
CHANGED
package/web/app.js
CHANGED
|
@@ -175,6 +175,75 @@
|
|
|
175
175
|
return scrollable || doc.scrollingElement;
|
|
176
176
|
}
|
|
177
177
|
|
|
178
|
+
// web-src/core/highlight-languages.ts
|
|
179
|
+
function lineComment(hljs, begin) {
|
|
180
|
+
return hljs.COMMENT?.(begin, "$") || {
|
|
181
|
+
scope: "comment",
|
|
182
|
+
begin,
|
|
183
|
+
end: "$"
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
function blockComment(hljs) {
|
|
187
|
+
return hljs.COMMENT?.("/\\*", "\\*/") || {
|
|
188
|
+
scope: "comment",
|
|
189
|
+
begin: "/\\*",
|
|
190
|
+
end: "\\*/"
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
function terraformLanguageDefinition(hljs) {
|
|
194
|
+
const api = hljs;
|
|
195
|
+
return {
|
|
196
|
+
name: "Terraform",
|
|
197
|
+
aliases: ["tf", "tfvars", "hcl"],
|
|
198
|
+
keywords: {
|
|
199
|
+
keyword: "resource data variable output locals module provider terraform backend dynamic lifecycle provisioner connection count for_each depends_on source version required_version required_providers",
|
|
200
|
+
literal: "true false null",
|
|
201
|
+
built_in: "abspath basename chomp cidrhost cidrnetmask cidrsubnet cidrsubnets compact concat contains csvdecode dirname distinct element file filebase64 fileexists flatten format formatdate index jsondecode jsonencode keys length lookup lower merge nonsensitive regex replace sensitive setproduct sort split substr templatefile tobool tonumber tostring try upper values yamldecode yamlencode zipmap"
|
|
202
|
+
},
|
|
203
|
+
contains: [
|
|
204
|
+
lineComment(api, "#"),
|
|
205
|
+
lineComment(api, "//"),
|
|
206
|
+
blockComment(api),
|
|
207
|
+
api.QUOTE_STRING_MODE || {
|
|
208
|
+
scope: "string",
|
|
209
|
+
begin: '"',
|
|
210
|
+
end: '"',
|
|
211
|
+
contains: [{ begin: "\\$\\{", end: "\\}" }]
|
|
212
|
+
},
|
|
213
|
+
{
|
|
214
|
+
scope: "string",
|
|
215
|
+
begin: "<<-?\\s*([A-Za-z_][\\w-]*)",
|
|
216
|
+
end: "^\\s*\\1\\s*$"
|
|
217
|
+
},
|
|
218
|
+
api.NUMBER_MODE || {
|
|
219
|
+
scope: "number",
|
|
220
|
+
begin: "\\b\\d+(\\.\\d+)?\\b"
|
|
221
|
+
},
|
|
222
|
+
{
|
|
223
|
+
scope: "attr",
|
|
224
|
+
begin: "\\b[A-Za-z_][\\w-]*(?=\\s*=)"
|
|
225
|
+
},
|
|
226
|
+
{
|
|
227
|
+
scope: "function",
|
|
228
|
+
begin: "\\b[A-Za-z_][\\w-]*(?=\\()"
|
|
229
|
+
},
|
|
230
|
+
{
|
|
231
|
+
scope: "variable",
|
|
232
|
+
begin: "\\b(?:var|local|module|data|resource|provider)\\.[A-Za-z_][\\w-]*(?:\\.[A-Za-z_][\\w-]*)*"
|
|
233
|
+
}
|
|
234
|
+
]
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
function ensureTerraformHighlightLanguage(hljsRef) {
|
|
238
|
+
if (!hljsRef?.registerLanguage)
|
|
239
|
+
return;
|
|
240
|
+
if (hljsRef.getLanguage?.("terraform"))
|
|
241
|
+
return;
|
|
242
|
+
try {
|
|
243
|
+
hljsRef.registerLanguage("terraform", terraformLanguageDefinition);
|
|
244
|
+
} catch {}
|
|
245
|
+
}
|
|
246
|
+
|
|
178
247
|
// web-src/core/icons.ts
|
|
179
248
|
var FOLDER_ICON_PATHS = {
|
|
180
249
|
closed: "M1.75 1A1.75 1.75 0 0 0 0 2.75v10.5C0 14.216.784 15 1.75 15h12.5A1.75 1.75 0 0 0 16 13.25v-8.5A1.75 1.75 0 0 0 14.25 3H7.5a.25.25 0 0 1-.2-.1l-.9-1.2C6.07 1.26 5.55 1 5 1H1.75Z",
|
|
@@ -6403,6 +6472,9 @@
|
|
|
6403
6472
|
shellscript: "bash",
|
|
6404
6473
|
console: "bash",
|
|
6405
6474
|
"shell-session": "bash",
|
|
6475
|
+
tf: "terraform",
|
|
6476
|
+
tfvars: "terraform",
|
|
6477
|
+
hcl: "terraform",
|
|
6406
6478
|
yml: "yaml",
|
|
6407
6479
|
ts: "typescript",
|
|
6408
6480
|
tsx: "typescript",
|
|
@@ -6440,6 +6512,7 @@
|
|
|
6440
6512
|
"sql",
|
|
6441
6513
|
"svelte",
|
|
6442
6514
|
"swift",
|
|
6515
|
+
"terraform",
|
|
6443
6516
|
"toml",
|
|
6444
6517
|
"tsx",
|
|
6445
6518
|
"typescript",
|
|
@@ -8430,8 +8503,10 @@ ${frontmatter.yaml}
|
|
|
8430
8503
|
ui.draw();
|
|
8431
8504
|
if (STATE.ignoreWs)
|
|
8432
8505
|
suppressWhitespaceOnlyInlineHighlights(body);
|
|
8433
|
-
if (STATE.syntaxHighlight && file.highlight && hljsRef && typeof ui.highlightCode === "function")
|
|
8506
|
+
if (STATE.syntaxHighlight && file.highlight && hljsRef && typeof ui.highlightCode === "function") {
|
|
8434
8507
|
ui.highlightCode();
|
|
8508
|
+
highlightPlaintextSpans(card, file);
|
|
8509
|
+
}
|
|
8435
8510
|
enhanceMediaCard(file, card);
|
|
8436
8511
|
syncSideScrollCard(card);
|
|
8437
8512
|
appendStatSquaresToHeader(card, file);
|
|
@@ -8753,31 +8828,41 @@ ${frontmatter.yaml}
|
|
|
8753
8828
|
}
|
|
8754
8829
|
}
|
|
8755
8830
|
function highlightInsertedSpans(card, file) {
|
|
8831
|
+
const spans = card.querySelectorAll("tr.gdp-inserted-ctx .d2h-code-line-ctn:not([data-gdp-hl])");
|
|
8832
|
+
highlightDiffSpans(file, spans);
|
|
8833
|
+
}
|
|
8834
|
+
function highlightPlaintextSpans(card, file) {
|
|
8835
|
+
const spans = card.querySelectorAll(".d2h-code-line-ctn.hljs.plaintext:not([data-gdp-hl])");
|
|
8836
|
+
highlightDiffSpans(file, spans);
|
|
8837
|
+
}
|
|
8838
|
+
function highlightDiffSpans(file, spans, deadline) {
|
|
8756
8839
|
if (file.size_class === "huge")
|
|
8757
|
-
return;
|
|
8840
|
+
return true;
|
|
8758
8841
|
if (!STATE.syntaxHighlight)
|
|
8759
|
-
return;
|
|
8842
|
+
return true;
|
|
8760
8843
|
const hljsRef = getHljs();
|
|
8761
8844
|
if (!hljsRef?.highlight)
|
|
8762
|
-
return;
|
|
8845
|
+
return true;
|
|
8763
8846
|
const lang = inferLang(file.path);
|
|
8764
|
-
if (!lang || !hljsRef.getLanguage
|
|
8765
|
-
return;
|
|
8766
|
-
const
|
|
8767
|
-
|
|
8847
|
+
if (!lang || hljsRef.getLanguage && !hljsRef.getLanguage(lang))
|
|
8848
|
+
return true;
|
|
8849
|
+
for (const s2 of spans) {
|
|
8850
|
+
if (deadline && deadline.timeRemaining() <= 4)
|
|
8851
|
+
return false;
|
|
8768
8852
|
s2.dataset.gdpHl = "1";
|
|
8769
8853
|
const text2 = s2.textContent || "";
|
|
8770
8854
|
if (text2.length === 0)
|
|
8771
|
-
|
|
8855
|
+
continue;
|
|
8772
8856
|
try {
|
|
8773
8857
|
s2.innerHTML = hljsRef.highlight(text2, {
|
|
8774
8858
|
language: lang,
|
|
8775
8859
|
ignoreIllegals: true
|
|
8776
8860
|
}).value;
|
|
8777
|
-
|
|
8778
|
-
|
|
8861
|
+
s2.classList.add("hljs", `language-${lang}`);
|
|
8862
|
+
s2.classList.remove("plaintext");
|
|
8779
8863
|
} catch (_) {}
|
|
8780
|
-
}
|
|
8864
|
+
}
|
|
8865
|
+
return true;
|
|
8781
8866
|
}
|
|
8782
8867
|
function scheduleIdleHighlight(card, file) {
|
|
8783
8868
|
if (file.highlight)
|
|
@@ -8796,23 +8881,7 @@ ${frontmatter.yaml}
|
|
|
8796
8881
|
return;
|
|
8797
8882
|
const work = (deadline) => {
|
|
8798
8883
|
const spans = card.querySelectorAll(".d2h-code-line-ctn:not([data-gdp-hl])");
|
|
8799
|
-
|
|
8800
|
-
while (i2 < spans.length && deadline.timeRemaining() > 4) {
|
|
8801
|
-
const s2 = spans[i2++];
|
|
8802
|
-
s2.dataset.gdpHl = "1";
|
|
8803
|
-
const text2 = s2.textContent || "";
|
|
8804
|
-
if (text2.length === 0)
|
|
8805
|
-
continue;
|
|
8806
|
-
try {
|
|
8807
|
-
s2.innerHTML = hljsRef.highlight(text2, {
|
|
8808
|
-
language: lang,
|
|
8809
|
-
ignoreIllegals: true
|
|
8810
|
-
}).value;
|
|
8811
|
-
if (!s2.classList.contains("hljs"))
|
|
8812
|
-
s2.classList.add("hljs");
|
|
8813
|
-
} catch (_) {}
|
|
8814
|
-
}
|
|
8815
|
-
if (i2 < spans.length)
|
|
8884
|
+
if (!highlightDiffSpans(file, spans, deadline))
|
|
8816
8885
|
requestIdleCallback(work, { timeout: 1500 });
|
|
8817
8886
|
};
|
|
8818
8887
|
requestIdleCallback(work, { timeout: 2000 });
|
|
@@ -13500,7 +13569,7 @@ ${frontmatter.yaml}
|
|
|
13500
13569
|
b2.classList.toggle("active", b2.dataset.view === STATE.sbView);
|
|
13501
13570
|
});
|
|
13502
13571
|
$$(".sb-tree-action").forEach((b2) => {
|
|
13503
|
-
b2.disabled = STATE.sbView !== "tree" || !
|
|
13572
|
+
b2.disabled = STATE.sbView !== "tree" || !files.length;
|
|
13504
13573
|
});
|
|
13505
13574
|
if (STATE.activeFile)
|
|
13506
13575
|
markActive(STATE.activeFile);
|
|
@@ -16331,6 +16400,7 @@ ${frontmatter.yaml}
|
|
|
16331
16400
|
const hljsRef = window.hljs || window.Diff2HtmlUI?.hljs;
|
|
16332
16401
|
if (!hljsRef)
|
|
16333
16402
|
return null;
|
|
16403
|
+
ensureTerraformHighlightLanguage(hljsRef);
|
|
16334
16404
|
if (!highlightConfigured && typeof hljsRef.configure === "function") {
|
|
16335
16405
|
hljsRef.configure({ ignoreUnescapedHTML: true });
|
|
16336
16406
|
highlightConfigured = true;
|