@willa-ui/shared 0.0.2 → 0.0.3-alpha.284d401
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.cjs +98 -1
- package/dist/index.d.cts +17 -2
- package/dist/index.global.js +49340 -1
- package/dist/index.js +85 -1
- package/dist/index.mjs +72 -2
- package/package.json +4 -3
package/dist/index.cjs
CHANGED
|
@@ -1,8 +1,32 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* @willa-ui/shared.js v0.0.
|
|
2
|
+
* @willa-ui/shared.js v0.0.3-alpha.284d401
|
|
3
3
|
* (c) 2026 chentao.arthur
|
|
4
4
|
*/
|
|
5
5
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
6
|
+
//#region \0rolldown/runtime.js
|
|
7
|
+
var __create = Object.create;
|
|
8
|
+
var __defProp = Object.defineProperty;
|
|
9
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
10
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
11
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
12
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
15
|
+
key = keys[i];
|
|
16
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
17
|
+
get: ((k) => from[k]).bind(null, key),
|
|
18
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
return to;
|
|
22
|
+
};
|
|
23
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
24
|
+
value: mod,
|
|
25
|
+
enumerable: true
|
|
26
|
+
}) : target, mod));
|
|
27
|
+
//#endregion
|
|
28
|
+
let highlight_js = require("highlight.js");
|
|
29
|
+
highlight_js = __toESM(highlight_js);
|
|
6
30
|
let react = require("react");
|
|
7
31
|
let aidly = require("aidly");
|
|
8
32
|
//#region src/clipboard.ts
|
|
@@ -30,6 +54,75 @@ async function copyToClipboard(text) {
|
|
|
30
54
|
}
|
|
31
55
|
}
|
|
32
56
|
//#endregion
|
|
57
|
+
//#region src/codeHighlight.ts
|
|
58
|
+
const parseCodeMeta = (className) => {
|
|
59
|
+
const [rawLanguage = "text", rawMeta = ""] = (/language-([^\s]+)/.exec(className ?? "")?.[1] ?? "text").split("--meta-");
|
|
60
|
+
const highlightLines = /* @__PURE__ */ new Set();
|
|
61
|
+
const normalizedMeta = rawMeta.replace(/_/g, " ");
|
|
62
|
+
const showLineNumbers = /(?:^|[^A-Za-z0-9-])ln(?:$|[^A-Za-z0-9-])/.test(normalizedMeta);
|
|
63
|
+
for (const match of rawMeta.matchAll(/\{([^}]+)\}/g)) addCodeHighlightRange(highlightLines, match[1]);
|
|
64
|
+
return {
|
|
65
|
+
rawLanguage,
|
|
66
|
+
highlightLines,
|
|
67
|
+
showLineNumbers
|
|
68
|
+
};
|
|
69
|
+
};
|
|
70
|
+
const normalizeHljsLanguage = (language) => {
|
|
71
|
+
const key = language.toLowerCase();
|
|
72
|
+
return {
|
|
73
|
+
c: "c",
|
|
74
|
+
cc: "cpp",
|
|
75
|
+
"c++": "cpp",
|
|
76
|
+
cpp: "cpp",
|
|
77
|
+
cxx: "cpp",
|
|
78
|
+
css: "css",
|
|
79
|
+
go: "go",
|
|
80
|
+
golang: "go",
|
|
81
|
+
html: "xml",
|
|
82
|
+
js: "javascript",
|
|
83
|
+
jsx: "javascript",
|
|
84
|
+
rs: "rust",
|
|
85
|
+
rust: "rust",
|
|
86
|
+
ts: "typescript",
|
|
87
|
+
tsx: "typescript",
|
|
88
|
+
sh: "bash",
|
|
89
|
+
bash: "bash",
|
|
90
|
+
shell: "bash",
|
|
91
|
+
yml: "yaml",
|
|
92
|
+
md: "markdown"
|
|
93
|
+
}[key] ?? key;
|
|
94
|
+
};
|
|
95
|
+
const highlightCodeToHtml = (code, rawLanguage) => {
|
|
96
|
+
const language = normalizeHljsLanguage(rawLanguage);
|
|
97
|
+
if (highlight_js.default.getLanguage(language)) return {
|
|
98
|
+
html: highlight_js.default.highlight(code, { language }).value,
|
|
99
|
+
display: rawLanguage
|
|
100
|
+
};
|
|
101
|
+
const result = highlight_js.default.highlightAuto(code);
|
|
102
|
+
return {
|
|
103
|
+
html: result.value,
|
|
104
|
+
display: result.language ?? rawLanguage
|
|
105
|
+
};
|
|
106
|
+
};
|
|
107
|
+
const createCodeHighlightLines = (ranges) => {
|
|
108
|
+
const highlightLines = /* @__PURE__ */ new Set();
|
|
109
|
+
for (const range of ranges ?? []) if (typeof range === "number") {
|
|
110
|
+
if (!Number.isInteger(range) || range <= 0) continue;
|
|
111
|
+
highlightLines.add(range);
|
|
112
|
+
} else addCodeHighlightRange(highlightLines, range.join("-"));
|
|
113
|
+
return highlightLines;
|
|
114
|
+
};
|
|
115
|
+
const addCodeHighlightRange = (highlightLines, value) => {
|
|
116
|
+
for (const part of value.split(",")) {
|
|
117
|
+
const rangeMatch = /^\s*(\d+)(?:-(\d+))?\s*$/.exec(part);
|
|
118
|
+
if (!rangeMatch) continue;
|
|
119
|
+
const start = Number(rangeMatch[1]);
|
|
120
|
+
const end = Number(rangeMatch[2] ?? rangeMatch[1]);
|
|
121
|
+
if (!Number.isInteger(start) || !Number.isInteger(end)) continue;
|
|
122
|
+
for (let line = start; line <= end; line += 1) if (line > 0) highlightLines.add(line);
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
//#endregion
|
|
33
126
|
//#region src/nodes.ts
|
|
34
127
|
const toNodeArray = (children) => {
|
|
35
128
|
return ((0, aidly.isArray)(children) ? children : [children]).filter((item) => {
|
|
@@ -95,7 +188,11 @@ function extractHeadings(source) {
|
|
|
95
188
|
}
|
|
96
189
|
//#endregion
|
|
97
190
|
exports.copyToClipboard = copyToClipboard;
|
|
191
|
+
exports.createCodeHighlightLines = createCodeHighlightLines;
|
|
98
192
|
exports.createHeadingIdFactory = createHeadingIdFactory;
|
|
99
193
|
exports.extractHeadings = extractHeadings;
|
|
100
194
|
exports.flattenText = flattenText;
|
|
195
|
+
exports.highlightCodeToHtml = highlightCodeToHtml;
|
|
101
196
|
exports.isMediaOnlyParagraph = isMediaOnlyParagraph;
|
|
197
|
+
exports.normalizeHljsLanguage = normalizeHljsLanguage;
|
|
198
|
+
exports.parseCodeMeta = parseCodeMeta;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* @willa-ui/shared.js v0.0.
|
|
2
|
+
* @willa-ui/shared.js v0.0.3-alpha.284d401
|
|
3
3
|
* (c) 2026 chentao.arthur
|
|
4
4
|
*/
|
|
5
5
|
import { ReactNode } from "react";
|
|
@@ -7,6 +7,21 @@ import { ReactNode } from "react";
|
|
|
7
7
|
//#region src/clipboard.d.ts
|
|
8
8
|
declare function copyToClipboard(text: string): Promise<boolean>;
|
|
9
9
|
//#endregion
|
|
10
|
+
//#region src/codeHighlight.d.ts
|
|
11
|
+
type CodeHighlightMeta = {
|
|
12
|
+
rawLanguage: string;
|
|
13
|
+
highlightLines: Set<number>;
|
|
14
|
+
showLineNumbers: boolean;
|
|
15
|
+
};
|
|
16
|
+
type HighlightedCode = {
|
|
17
|
+
html: string;
|
|
18
|
+
display: string;
|
|
19
|
+
};
|
|
20
|
+
declare const parseCodeMeta: (className?: string) => CodeHighlightMeta;
|
|
21
|
+
declare const normalizeHljsLanguage: (language: string) => string;
|
|
22
|
+
declare const highlightCodeToHtml: (code: string, rawLanguage: string) => HighlightedCode;
|
|
23
|
+
declare const createCodeHighlightLines: (ranges: Array<number | readonly [start: number, end: number]> | undefined) => Set<number>;
|
|
24
|
+
//#endregion
|
|
10
25
|
//#region src/nodes.d.ts
|
|
11
26
|
declare function isMediaOnlyParagraph(children: ReactNode): boolean;
|
|
12
27
|
//#endregion
|
|
@@ -37,4 +52,4 @@ declare function flattenText(node: unknown): string;
|
|
|
37
52
|
declare function createHeadingIdFactory(): (text: string) => string;
|
|
38
53
|
declare function extractHeadings(source: string): Heading[];
|
|
39
54
|
//#endregion
|
|
40
|
-
export { type Heading, type LightboxImage, type LightboxState, type OpenLightbox, type ResolveAssetUrl, copyToClipboard, createHeadingIdFactory, extractHeadings, flattenText, isMediaOnlyParagraph };
|
|
55
|
+
export { type CodeHighlightMeta, type Heading, type HighlightedCode, type LightboxImage, type LightboxState, type OpenLightbox, type ResolveAssetUrl, copyToClipboard, createCodeHighlightLines, createHeadingIdFactory, extractHeadings, flattenText, highlightCodeToHtml, isMediaOnlyParagraph, normalizeHljsLanguage, parseCodeMeta };
|