@incremark/svelte 0.2.6 → 0.3.0
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/README.en.md +274 -0
- package/dist/ThemeProvider.svelte +4 -1
- package/dist/ThemeProvider.svelte.d.ts.map +1 -1
- package/dist/components/AutoScrollContainer.svelte +18 -18
- package/dist/components/ConfigProvider.svelte +18 -0
- package/dist/components/ConfigProvider.svelte.d.ts +9 -0
- package/dist/components/ConfigProvider.svelte.d.ts.map +1 -0
- package/dist/components/Incremark.svelte +63 -72
- package/dist/components/Incremark.svelte.d.ts +5 -7
- package/dist/components/Incremark.svelte.d.ts.map +1 -1
- package/dist/components/IncremarkCode.svelte +28 -251
- package/dist/components/IncremarkCode.svelte.d.ts +4 -1
- package/dist/components/IncremarkCode.svelte.d.ts.map +1 -1
- package/dist/components/IncremarkCodeDefault.svelte +115 -0
- package/dist/components/IncremarkCodeDefault.svelte.d.ts +18 -0
- package/dist/components/IncremarkCodeDefault.svelte.d.ts.map +1 -0
- package/dist/components/IncremarkCodeMermaid.svelte +148 -0
- package/dist/components/IncremarkCodeMermaid.svelte.d.ts +14 -0
- package/dist/components/IncremarkCodeMermaid.svelte.d.ts.map +1 -0
- package/dist/components/IncremarkContent.svelte +115 -0
- package/dist/components/IncremarkContent.svelte.d.ts +5 -0
- package/dist/components/IncremarkContent.svelte.d.ts.map +1 -0
- package/dist/components/IncremarkFootnotes.svelte +4 -8
- package/dist/components/IncremarkFootnotes.svelte.d.ts.map +1 -1
- package/dist/components/IncremarkInline.svelte +3 -3
- package/dist/components/IncremarkList.svelte +1 -0
- package/dist/components/IncremarkRenderer.svelte +4 -0
- package/dist/components/IncremarkRenderer.svelte.d.ts +2 -0
- package/dist/components/IncremarkRenderer.svelte.d.ts.map +1 -1
- package/dist/components/IncremarkTable.svelte +6 -9
- package/dist/components/IncremarkTable.svelte.d.ts.map +1 -1
- package/dist/components/SvgIcon.svelte +25 -0
- package/dist/components/SvgIcon.svelte.d.ts +12 -0
- package/dist/components/SvgIcon.svelte.d.ts.map +1 -0
- package/dist/components/index.d.ts +2 -1
- package/dist/components/index.d.ts.map +1 -1
- package/dist/components/index.js +1 -0
- package/dist/components/types.d.ts +29 -3
- package/dist/components/types.d.ts.map +1 -1
- package/dist/index.d.ts +8 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -2
- package/dist/stores/{useDevTools.d.ts → useDevTools.svelte.d.ts} +1 -1
- package/dist/stores/useDevTools.svelte.d.ts.map +1 -0
- package/dist/stores/{useDevTools.js → useDevTools.svelte.js} +10 -9
- package/dist/stores/useIncremark.d.ts +4 -4
- package/dist/stores/useIncremark.d.ts.map +1 -1
- package/dist/stores/useLocale.svelte.d.ts +29 -0
- package/dist/stores/useLocale.svelte.d.ts.map +1 -0
- package/dist/stores/useLocale.svelte.js +32 -0
- package/dist/stores/useShiki.svelte.d.ts +9 -0
- package/dist/stores/useShiki.svelte.d.ts.map +1 -0
- package/dist/stores/useShiki.svelte.js +110 -0
- package/dist/stores/useTypewriter.d.ts +0 -1
- package/dist/stores/useTypewriter.d.ts.map +1 -1
- package/dist/stores/useTypewriter.js +1 -3
- package/package.json +13 -7
- package/dist/stores/useDevTools.d.ts.map +0 -1
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
// ============ 单例管理器 ============
|
|
2
|
+
class ShikiManager {
|
|
3
|
+
static instance = null;
|
|
4
|
+
highlighters = new Map();
|
|
5
|
+
constructor() { }
|
|
6
|
+
static getInstance() {
|
|
7
|
+
if (!ShikiManager.instance) {
|
|
8
|
+
ShikiManager.instance = new ShikiManager();
|
|
9
|
+
}
|
|
10
|
+
return ShikiManager.instance;
|
|
11
|
+
}
|
|
12
|
+
async getHighlighter(theme) {
|
|
13
|
+
if (this.highlighters.has(theme)) {
|
|
14
|
+
return this.highlighters.get(theme);
|
|
15
|
+
}
|
|
16
|
+
const { createHighlighter } = await import('shiki');
|
|
17
|
+
const highlighter = await createHighlighter({
|
|
18
|
+
themes: [theme],
|
|
19
|
+
langs: []
|
|
20
|
+
});
|
|
21
|
+
const info = {
|
|
22
|
+
highlighter,
|
|
23
|
+
loadedLanguages: new Set(),
|
|
24
|
+
loadedThemes: new Set([theme])
|
|
25
|
+
};
|
|
26
|
+
this.highlighters.set(theme, info);
|
|
27
|
+
return info;
|
|
28
|
+
}
|
|
29
|
+
async loadLanguage(theme, lang) {
|
|
30
|
+
const info = this.highlighters.get(theme);
|
|
31
|
+
if (!info || info.loadedLanguages.has(lang))
|
|
32
|
+
return;
|
|
33
|
+
try {
|
|
34
|
+
await info.highlighter.loadLanguage(lang);
|
|
35
|
+
info.loadedLanguages.add(lang);
|
|
36
|
+
}
|
|
37
|
+
catch { /* 静默处理 */ }
|
|
38
|
+
}
|
|
39
|
+
async loadTheme(theme) {
|
|
40
|
+
const info = this.highlighters.get(theme);
|
|
41
|
+
if (!info || info.loadedThemes.has(theme))
|
|
42
|
+
return;
|
|
43
|
+
try {
|
|
44
|
+
await info.highlighter.loadTheme(theme);
|
|
45
|
+
info.loadedThemes.add(theme);
|
|
46
|
+
}
|
|
47
|
+
catch { /* 静默处理 */ }
|
|
48
|
+
}
|
|
49
|
+
async codeToHtml(theme, code, lang, fallbackTheme) {
|
|
50
|
+
const info = this.highlighters.get(theme);
|
|
51
|
+
if (!info)
|
|
52
|
+
throw new Error('Highlighter not found');
|
|
53
|
+
const actualLang = info.loadedLanguages.has(lang) ? lang : 'text';
|
|
54
|
+
return info.highlighter.codeToHtml(code, {
|
|
55
|
+
lang: actualLang,
|
|
56
|
+
theme: theme
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
// ============ 延迟初始化单例 ============
|
|
61
|
+
let shikiManagerInstance = null;
|
|
62
|
+
/**
|
|
63
|
+
* 获取 ShikiManager 单例(延迟初始化)
|
|
64
|
+
* 避免模块加载时立即创建实例,支持 SSR
|
|
65
|
+
*/
|
|
66
|
+
function getShikiManager() {
|
|
67
|
+
if (!shikiManagerInstance) {
|
|
68
|
+
shikiManagerInstance = ShikiManager.getInstance();
|
|
69
|
+
}
|
|
70
|
+
return shikiManagerInstance;
|
|
71
|
+
}
|
|
72
|
+
// ============ Svelte 5 Composable ============
|
|
73
|
+
/**
|
|
74
|
+
* 使用 Shiki Highlighter
|
|
75
|
+
* @param themeGetter 传入一个返回主题字符串的函数,例如 () => theme
|
|
76
|
+
*/
|
|
77
|
+
export function useShiki(themeGetter) {
|
|
78
|
+
// 使用 Svelte 5 的原生响应式状态
|
|
79
|
+
let isHighlighting = $state(false);
|
|
80
|
+
/**
|
|
81
|
+
* 高亮代码
|
|
82
|
+
*/
|
|
83
|
+
async function highlight(code, lang, fallbackTheme) {
|
|
84
|
+
// 关键:每次执行时通过 Getter 获取最新的主题
|
|
85
|
+
const currentTheme = themeGetter();
|
|
86
|
+
const currentFallback = fallbackTheme;
|
|
87
|
+
isHighlighting = true;
|
|
88
|
+
try {
|
|
89
|
+
const manager = getShikiManager();
|
|
90
|
+
const info = await manager.getHighlighter(currentTheme);
|
|
91
|
+
// 按需加载语言
|
|
92
|
+
if (!info.loadedLanguages.has(lang) && lang !== 'text') {
|
|
93
|
+
await manager.loadLanguage(currentTheme, lang);
|
|
94
|
+
}
|
|
95
|
+
// 按需加载主题
|
|
96
|
+
if (!info.loadedThemes.has(currentTheme)) {
|
|
97
|
+
await manager.loadTheme(currentTheme);
|
|
98
|
+
}
|
|
99
|
+
return await manager.codeToHtml(currentTheme, code, lang, currentFallback);
|
|
100
|
+
}
|
|
101
|
+
finally {
|
|
102
|
+
isHighlighting = false;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
return {
|
|
106
|
+
// 使用 getter 暴露只读状态,保持 UI 响应
|
|
107
|
+
get isHighlighting() { return isHighlighting; },
|
|
108
|
+
highlight
|
|
109
|
+
};
|
|
110
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useTypewriter.d.ts","sourceRoot":"","sources":["../../src/stores/useT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@ -79,13 +79,12 @@ export function useTypewriter(options) {
|
|
|
79
79
|
const rawBlocks = derived([completedBlocks, pendingBlocks], ([$completedBlocks, $pendingBlocks]) => {
|
|
80
80
|
const result = [];
|
|
81
81
|
for (const block of $completedBlocks) {
|
|
82
|
-
result.push(
|
|
82
|
+
result.push(block);
|
|
83
83
|
}
|
|
84
84
|
for (let i = 0; i < $pendingBlocks.length; i++) {
|
|
85
85
|
const isLastPending = i === $pendingBlocks.length - 1;
|
|
86
86
|
result.push({
|
|
87
87
|
...$pendingBlocks[i],
|
|
88
|
-
stableId: `pending-${i}`,
|
|
89
88
|
isLastPending
|
|
90
89
|
});
|
|
91
90
|
}
|
|
@@ -108,7 +107,6 @@ export function useTypewriter(options) {
|
|
|
108
107
|
}
|
|
109
108
|
return {
|
|
110
109
|
id: db.id,
|
|
111
|
-
stableId: db.id,
|
|
112
110
|
status: (db.isDisplayComplete ? 'completed' : 'pending'),
|
|
113
111
|
isLastPending,
|
|
114
112
|
node,
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@incremark/svelte",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.3.0",
|
|
4
|
+
"description": "High-performance streaming markdown renderer for Svelte 5 ecosystem.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"svelte": "./dist/index.js",
|
|
7
7
|
"main": "./dist/index.js",
|
|
@@ -24,10 +24,11 @@
|
|
|
24
24
|
],
|
|
25
25
|
"dependencies": {
|
|
26
26
|
"shiki": "^3.20.0",
|
|
27
|
-
"@incremark/
|
|
28
|
-
"@incremark/
|
|
29
|
-
"@incremark/
|
|
30
|
-
"@incremark/shared": "0.
|
|
27
|
+
"@incremark/core": "0.3.0",
|
|
28
|
+
"@incremark/devtools": "0.3.0",
|
|
29
|
+
"@incremark/icons": "0.3.0",
|
|
30
|
+
"@incremark/shared": "0.3.0",
|
|
31
|
+
"@incremark/theme": "0.3.0"
|
|
31
32
|
},
|
|
32
33
|
"peerDependencies": {
|
|
33
34
|
"svelte": "^5.0.0",
|
|
@@ -54,7 +55,12 @@
|
|
|
54
55
|
"svelte",
|
|
55
56
|
"svelte5",
|
|
56
57
|
"streaming",
|
|
57
|
-
"ai"
|
|
58
|
+
"ai",
|
|
59
|
+
"chatgpt",
|
|
60
|
+
"llm",
|
|
61
|
+
"typewriter",
|
|
62
|
+
"i18n",
|
|
63
|
+
"a11y"
|
|
58
64
|
],
|
|
59
65
|
"license": "MIT",
|
|
60
66
|
"repository": {
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useDevTools.d.ts","sourceRoot":"","sources":["../../src/stores/useDevTools.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAkB,KAAK,eAAe,EAAE,MAAM,qBAAqB,CAAA;AAC1E,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAA;AAExD;;GAEG;AACH,MAAM,WAAW,kBAAmB,SAAQ,eAAe;CAAG;AAE9D;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,WAAW,CACzB,SAAS,EAAE,kBAAkB,EAC7B,OAAO,GAAE,kBAAuB,mDAgCjC"}
|