@duskmoon-dev/components 0.6.3 → 0.6.4
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.
|
@@ -118,7 +118,7 @@ var ChatRequest = forwardRef(({
|
|
|
118
118
|
children: actions.map((action) => /* @__PURE__ */ jsx("button", {
|
|
119
119
|
type: "button",
|
|
120
120
|
"data-chat-request-action": "",
|
|
121
|
-
className: cn("btn btn-sm", action.tone === "primary" && "btn-primary", action.tone === "danger" && "btn-error"),
|
|
121
|
+
className: cn("btn btn-sm", action.tone === "primary" && "btn-primary", action.tone === "danger" && "btn-error", action.tone === undefined && "btn-outline"),
|
|
122
122
|
"aria-label": action.ariaLabel,
|
|
123
123
|
disabled: pending || action.disabled,
|
|
124
124
|
onClick: action.onSelect,
|
|
@@ -6,6 +6,73 @@ import ReactMarkdown from "react-markdown";
|
|
|
6
6
|
import remarkBreaks from "remark-breaks";
|
|
7
7
|
import remarkGfm from "remark-gfm";
|
|
8
8
|
|
|
9
|
+
// src/components/markdown/remarkCjkAutolink.ts
|
|
10
|
+
var CJK_BOUNDARY = /[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Hangul}\u3000-\u303F\u30FB\uFF00-\uFFEF]/u;
|
|
11
|
+
var BARE_URL = /(?:https?:\/\/|www\.)[\p{L}\p{N}_-]/iu;
|
|
12
|
+
var LEADING_BARE_URL = new RegExp(`^${BARE_URL.source}`, "iu");
|
|
13
|
+
var TRAILING_PUNCTUATION = /[?!.,:;*_~'"]$/;
|
|
14
|
+
function isLiteralAutolink(node) {
|
|
15
|
+
const [child] = node.children ?? [];
|
|
16
|
+
return node.children?.length === 1 && child.type === "text" && child.value !== undefined && node.position?.start.offset !== undefined && child.position?.start.offset === node.position.start.offset && LEADING_BARE_URL.test(child.value);
|
|
17
|
+
}
|
|
18
|
+
function trimTrailing(url) {
|
|
19
|
+
let end = url;
|
|
20
|
+
for (;; ) {
|
|
21
|
+
if (TRAILING_PUNCTUATION.test(end)) {
|
|
22
|
+
end = end.slice(0, -1);
|
|
23
|
+
} else if (end.endsWith(")") && end.split(")").length > end.split("(").length) {
|
|
24
|
+
end = end.slice(0, -1);
|
|
25
|
+
} else {
|
|
26
|
+
return end;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
function linkNode(text) {
|
|
31
|
+
return {
|
|
32
|
+
type: "link",
|
|
33
|
+
url: /^www\./i.test(text) ? `http://${text}` : text,
|
|
34
|
+
children: [{ type: "text", value: text }]
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
function splitBareUrl(value) {
|
|
38
|
+
const boundary = value.search(CJK_BOUNDARY);
|
|
39
|
+
if (boundary === -1)
|
|
40
|
+
return [linkNode(value)];
|
|
41
|
+
const url = trimTrailing(value.slice(0, boundary));
|
|
42
|
+
const nodes = [
|
|
43
|
+
LEADING_BARE_URL.test(url) ? linkNode(url) : { type: "text", value: url }
|
|
44
|
+
];
|
|
45
|
+
const rest = value.slice(url.length);
|
|
46
|
+
const next = rest.search(BARE_URL);
|
|
47
|
+
if (next === -1) {
|
|
48
|
+
nodes.push({ type: "text", value: rest });
|
|
49
|
+
} else {
|
|
50
|
+
if (next > 0)
|
|
51
|
+
nodes.push({ type: "text", value: rest.slice(0, next) });
|
|
52
|
+
nodes.push(...splitBareUrl(rest.slice(next)));
|
|
53
|
+
}
|
|
54
|
+
return nodes;
|
|
55
|
+
}
|
|
56
|
+
function visit(parent) {
|
|
57
|
+
const children = parent.children;
|
|
58
|
+
if (!children)
|
|
59
|
+
return;
|
|
60
|
+
for (let index = 0;index < children.length; index++) {
|
|
61
|
+
const node = children[index];
|
|
62
|
+
const text = node.children?.[0]?.value;
|
|
63
|
+
if (node.type === "link" && text !== undefined && isLiteralAutolink(node) && CJK_BOUNDARY.test(text)) {
|
|
64
|
+
const replacement = splitBareUrl(text);
|
|
65
|
+
children.splice(index, 1, ...replacement);
|
|
66
|
+
index += replacement.length - 1;
|
|
67
|
+
} else {
|
|
68
|
+
visit(node);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
function remarkCjkAutolink() {
|
|
73
|
+
return (tree) => visit(tree);
|
|
74
|
+
}
|
|
75
|
+
|
|
9
76
|
// ../../node_modules/.bun/clsx@2.1.1/node_modules/clsx/dist/clsx.mjs
|
|
10
77
|
function r(e) {
|
|
11
78
|
var t, f, n = "";
|
|
@@ -159,7 +226,7 @@ var Markdown = forwardRef(function Markdown({
|
|
|
159
226
|
})
|
|
160
227
|
}) : null,
|
|
161
228
|
/* @__PURE__ */ jsx(ReactMarkdown, {
|
|
162
|
-
remarkPlugins: breaks ? [remarkGfm, remarkBreaks] : [remarkGfm],
|
|
229
|
+
remarkPlugins: breaks ? [remarkGfm, remarkCjkAutolink, remarkBreaks] : [remarkGfm, remarkCjkAutolink],
|
|
163
230
|
components,
|
|
164
231
|
children: source.body
|
|
165
232
|
})
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ends GFM literal autolinks (bare `https://…` / `www.…` URLs) at CJK text.
|
|
3
|
+
*
|
|
4
|
+
* GFM only stops a literal URL at whitespace, `<` or trailing ASCII
|
|
5
|
+
* punctuation, so `https://example.com,告诉我` links the Chinese text too.
|
|
6
|
+
* This transform runs after `remark-gfm` and cuts each literal autolink before
|
|
7
|
+
* the first CJK ideograph, kana, Hangul, CJK symbol/punctuation or full-width
|
|
8
|
+
* form. Non-ASCII path text is therefore not kept (`https://a.com/路径` links
|
|
9
|
+
* `https://a.com/`); percent-encoded paths, `<url>` autolinks and
|
|
10
|
+
* `[text](url)` links are untouched.
|
|
11
|
+
*/
|
|
12
|
+
interface MdNode {
|
|
13
|
+
type: string;
|
|
14
|
+
value?: string;
|
|
15
|
+
url?: string;
|
|
16
|
+
children?: MdNode[];
|
|
17
|
+
position?: {
|
|
18
|
+
start: {
|
|
19
|
+
offset?: number;
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
export declare function remarkCjkAutolink(): (tree: MdNode) => void;
|
|
24
|
+
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "0.6.
|
|
1
|
+
export declare const version = "0.6.4";
|
package/dist/index.js
CHANGED
|
@@ -107,7 +107,7 @@ function duskmoonMerge(classes) {
|
|
|
107
107
|
import { useCallback as useCallback2, useState as useState2 } from "react";
|
|
108
108
|
|
|
109
109
|
// src/generated/version.ts
|
|
110
|
-
var version = "0.6.
|
|
110
|
+
var version = "0.6.4";
|
|
111
111
|
|
|
112
112
|
// src/infrastructure.ts
|
|
113
113
|
var theme = {
|
|
@@ -1041,7 +1041,7 @@ var ChatRequest = forwardRef2(({
|
|
|
1041
1041
|
children: actions.map((action) => /* @__PURE__ */ jsx6("button", {
|
|
1042
1042
|
type: "button",
|
|
1043
1043
|
"data-chat-request-action": "",
|
|
1044
|
-
className: cn("btn btn-sm", action.tone === "primary" && "btn-primary", action.tone === "danger" && "btn-error"),
|
|
1044
|
+
className: cn("btn btn-sm", action.tone === "primary" && "btn-primary", action.tone === "danger" && "btn-error", action.tone === undefined && "btn-outline"),
|
|
1045
1045
|
"aria-label": action.ariaLabel,
|
|
1046
1046
|
disabled: pending || action.disabled,
|
|
1047
1047
|
onClick: action.onSelect,
|
|
@@ -24449,6 +24449,73 @@ import ReactMarkdown from "react-markdown";
|
|
|
24449
24449
|
import remarkBreaks from "remark-breaks";
|
|
24450
24450
|
import remarkGfm from "remark-gfm";
|
|
24451
24451
|
|
|
24452
|
+
// src/components/markdown/remarkCjkAutolink.ts
|
|
24453
|
+
var CJK_BOUNDARY = /[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Hangul}\u3000-\u303F\u30FB\uFF00-\uFFEF]/u;
|
|
24454
|
+
var BARE_URL = /(?:https?:\/\/|www\.)[\p{L}\p{N}_-]/iu;
|
|
24455
|
+
var LEADING_BARE_URL = new RegExp(`^${BARE_URL.source}`, "iu");
|
|
24456
|
+
var TRAILING_PUNCTUATION = /[?!.,:;*_~'"]$/;
|
|
24457
|
+
function isLiteralAutolink(node) {
|
|
24458
|
+
const [child] = node.children ?? [];
|
|
24459
|
+
return node.children?.length === 1 && child.type === "text" && child.value !== undefined && node.position?.start.offset !== undefined && child.position?.start.offset === node.position.start.offset && LEADING_BARE_URL.test(child.value);
|
|
24460
|
+
}
|
|
24461
|
+
function trimTrailing(url) {
|
|
24462
|
+
let end = url;
|
|
24463
|
+
for (;; ) {
|
|
24464
|
+
if (TRAILING_PUNCTUATION.test(end)) {
|
|
24465
|
+
end = end.slice(0, -1);
|
|
24466
|
+
} else if (end.endsWith(")") && end.split(")").length > end.split("(").length) {
|
|
24467
|
+
end = end.slice(0, -1);
|
|
24468
|
+
} else {
|
|
24469
|
+
return end;
|
|
24470
|
+
}
|
|
24471
|
+
}
|
|
24472
|
+
}
|
|
24473
|
+
function linkNode(text) {
|
|
24474
|
+
return {
|
|
24475
|
+
type: "link",
|
|
24476
|
+
url: /^www\./i.test(text) ? `http://${text}` : text,
|
|
24477
|
+
children: [{ type: "text", value: text }]
|
|
24478
|
+
};
|
|
24479
|
+
}
|
|
24480
|
+
function splitBareUrl(value) {
|
|
24481
|
+
const boundary = value.search(CJK_BOUNDARY);
|
|
24482
|
+
if (boundary === -1)
|
|
24483
|
+
return [linkNode(value)];
|
|
24484
|
+
const url = trimTrailing(value.slice(0, boundary));
|
|
24485
|
+
const nodes = [
|
|
24486
|
+
LEADING_BARE_URL.test(url) ? linkNode(url) : { type: "text", value: url }
|
|
24487
|
+
];
|
|
24488
|
+
const rest = value.slice(url.length);
|
|
24489
|
+
const next = rest.search(BARE_URL);
|
|
24490
|
+
if (next === -1) {
|
|
24491
|
+
nodes.push({ type: "text", value: rest });
|
|
24492
|
+
} else {
|
|
24493
|
+
if (next > 0)
|
|
24494
|
+
nodes.push({ type: "text", value: rest.slice(0, next) });
|
|
24495
|
+
nodes.push(...splitBareUrl(rest.slice(next)));
|
|
24496
|
+
}
|
|
24497
|
+
return nodes;
|
|
24498
|
+
}
|
|
24499
|
+
function visit(parent) {
|
|
24500
|
+
const children = parent.children;
|
|
24501
|
+
if (!children)
|
|
24502
|
+
return;
|
|
24503
|
+
for (let index = 0;index < children.length; index++) {
|
|
24504
|
+
const node = children[index];
|
|
24505
|
+
const text = node.children?.[0]?.value;
|
|
24506
|
+
if (node.type === "link" && text !== undefined && isLiteralAutolink(node) && CJK_BOUNDARY.test(text)) {
|
|
24507
|
+
const replacement = splitBareUrl(text);
|
|
24508
|
+
children.splice(index, 1, ...replacement);
|
|
24509
|
+
index += replacement.length - 1;
|
|
24510
|
+
} else {
|
|
24511
|
+
visit(node);
|
|
24512
|
+
}
|
|
24513
|
+
}
|
|
24514
|
+
}
|
|
24515
|
+
function remarkCjkAutolink() {
|
|
24516
|
+
return (tree) => visit(tree);
|
|
24517
|
+
}
|
|
24518
|
+
|
|
24452
24519
|
// src/classes/markdown.ts
|
|
24453
24520
|
var markdownBaseClass = "markdown-body";
|
|
24454
24521
|
var markdownFrontMatterClass = "dm-front-matter";
|
|
@@ -24577,7 +24644,7 @@ var Markdown = forwardRef93(function Markdown({
|
|
|
24577
24644
|
})
|
|
24578
24645
|
}) : null,
|
|
24579
24646
|
/* @__PURE__ */ jsx113(ReactMarkdown, {
|
|
24580
|
-
remarkPlugins: breaks ? [remarkGfm, remarkBreaks] : [remarkGfm],
|
|
24647
|
+
remarkPlugins: breaks ? [remarkGfm, remarkCjkAutolink, remarkBreaks] : [remarkGfm, remarkCjkAutolink],
|
|
24581
24648
|
components,
|
|
24582
24649
|
children: source.body
|
|
24583
24650
|
})
|
package/dist/infrastructure.js
CHANGED