@jboltai/tokui-svelte 0.1.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/LICENSE +21 -0
- package/README.md +39 -0
- package/package.json +61 -0
- package/src/TokUI.svelte +29 -0
- package/src/index.d.ts +18 -0
- package/src/index.js +41 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 jboltai.com
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# @jboltai/tokui-svelte
|
|
2
|
+
|
|
3
|
+
> TokUI 的 Svelte 适配器:`use:tokui` action + `<TokUI>` 组件。
|
|
4
|
+
|
|
5
|
+
## 安装
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @jboltai/tokui-svelte svelte
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Action(无需编译,最简)
|
|
12
|
+
|
|
13
|
+
```svelte
|
|
14
|
+
<script>
|
|
15
|
+
import { tokui } from '@jboltai/tokui-svelte';
|
|
16
|
+
const dsl = '[card tt:你好 TokUI][p 流式 UI,零依赖][/card]';
|
|
17
|
+
</script>
|
|
18
|
+
|
|
19
|
+
<div use:tokui={{ dsl, theme: 'default' }}></div>
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
`dsl` 变化时 action 的 `update` 自动重新渲染。
|
|
23
|
+
|
|
24
|
+
## 组件(需 svelte 编译器)
|
|
25
|
+
|
|
26
|
+
```svelte
|
|
27
|
+
<script>
|
|
28
|
+
import TokUI from '@jboltai/tokui-svelte/src/TokUI.svelte';
|
|
29
|
+
const dsl = '[card tt:你好][p 内容][/card]';
|
|
30
|
+
</script>
|
|
31
|
+
|
|
32
|
+
<TokUI {dsl} theme="default" />
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## CSS
|
|
36
|
+
|
|
37
|
+
样式随 `@jboltai/tokui` 自动注入,无需手动引 CSS。
|
|
38
|
+
|
|
39
|
+
License: MIT
|
package/package.json
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@jboltai/tokui-svelte",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "TokUI Svelte adapter — use:tokui action and TokUI component for streaming DSL UI.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "sdxiaomu (https://jboltai.com)",
|
|
7
|
+
"homepage": "https://github.com/jboltai/tokui",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "https://github.com/jboltai/tokui.git",
|
|
11
|
+
"directory": "packages/svelte"
|
|
12
|
+
},
|
|
13
|
+
"main": "src/index.js",
|
|
14
|
+
"module": "src/index.js",
|
|
15
|
+
"types": "src/index.d.ts",
|
|
16
|
+
"type": "module",
|
|
17
|
+
"svelte": "src/TokUI.svelte",
|
|
18
|
+
"exports": {
|
|
19
|
+
".": {
|
|
20
|
+
"types": "./src/index.d.ts",
|
|
21
|
+
"svelte": "./src/TokUI.svelte",
|
|
22
|
+
"import": "./src/index.js",
|
|
23
|
+
"require": "./src/index.js",
|
|
24
|
+
"default": "./src/index.js"
|
|
25
|
+
},
|
|
26
|
+
"./action": {
|
|
27
|
+
"types": "./src/index.d.ts",
|
|
28
|
+
"import": "./src/index.js",
|
|
29
|
+
"default": "./src/index.js"
|
|
30
|
+
},
|
|
31
|
+
"./package.json": "./package.json"
|
|
32
|
+
},
|
|
33
|
+
"dependencies": {
|
|
34
|
+
"@jboltai/tokui": "^0.1.0"
|
|
35
|
+
},
|
|
36
|
+
"peerDependencies": {
|
|
37
|
+
"svelte": ">=3.46.0"
|
|
38
|
+
},
|
|
39
|
+
"peerDependenciesMeta": {
|
|
40
|
+
"svelte": {
|
|
41
|
+
"optional": false
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
"sideEffects": [
|
|
45
|
+
"**/*.css"
|
|
46
|
+
],
|
|
47
|
+
"files": [
|
|
48
|
+
"src",
|
|
49
|
+
"README.md"
|
|
50
|
+
],
|
|
51
|
+
"keywords": [
|
|
52
|
+
"tokui",
|
|
53
|
+
"svelte",
|
|
54
|
+
"streaming-ui",
|
|
55
|
+
"dsl",
|
|
56
|
+
"action"
|
|
57
|
+
],
|
|
58
|
+
"publishConfig": {
|
|
59
|
+
"access": "public"
|
|
60
|
+
}
|
|
61
|
+
}
|
package/src/TokUI.svelte
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
// TokUI Svelte 组件(需 svelte 编译器)。无需编译的 action 版见 ./index.js。
|
|
3
|
+
import { onMount, onDestroy } from 'svelte';
|
|
4
|
+
import { TokUI, setTheme } from '@jboltai/tokui';
|
|
5
|
+
|
|
6
|
+
/** @type {string} DSL 文本 */
|
|
7
|
+
export let dsl = '';
|
|
8
|
+
/** @type {string} 主题名 */
|
|
9
|
+
export let theme = '';
|
|
10
|
+
|
|
11
|
+
let container;
|
|
12
|
+
/** @type {any} */
|
|
13
|
+
let ui;
|
|
14
|
+
|
|
15
|
+
onMount(() => {
|
|
16
|
+
ui = new TokUI({ container });
|
|
17
|
+
if (theme) setTheme(theme);
|
|
18
|
+
if (dsl) ui.render(dsl);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
// dsl 响应式变化 → 重新渲染
|
|
22
|
+
$: if (ui && dsl) ui.render(dsl);
|
|
23
|
+
// theme 响应式变化 → 切换主题
|
|
24
|
+
$: if (theme) { try { setTheme(theme); } catch (e) { /* ignore */ } }
|
|
25
|
+
|
|
26
|
+
onDestroy(() => { if (ui && ui.disconnect) ui.disconnect(); });
|
|
27
|
+
</script>
|
|
28
|
+
|
|
29
|
+
<div bind:this={container} class="tokui-svelte-view"></div>
|
package/src/index.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { TokUIEventCallback } from '@jboltai/tokui';
|
|
2
|
+
|
|
3
|
+
export interface TokuiActionOptions {
|
|
4
|
+
dsl?: string;
|
|
5
|
+
theme?: string;
|
|
6
|
+
onEvent?: TokUIEventCallback;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/** Svelte action:<div use:tokui={{ dsl, theme }} /> */
|
|
10
|
+
export declare function tokui(
|
|
11
|
+
node: HTMLElement,
|
|
12
|
+
options?: TokuiActionOptions
|
|
13
|
+
): {
|
|
14
|
+
update: (options: TokuiActionOptions) => void;
|
|
15
|
+
destroy: () => void;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export default tokui;
|
package/src/index.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// TokUI Svelte 适配器:use:tokui action(纯 JS,无需 svelte 预处理即可用)。
|
|
4
|
+
// 组件版见 ./TokUI.svelte(需 svelte 编译器)。
|
|
5
|
+
import { TokUI, setTheme } from '@jboltai/tokui';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Svelte action:<div use:tokui={{ dsl, theme }}></div>
|
|
9
|
+
* @param {HTMLElement} node 挂载节点
|
|
10
|
+
* @param {{dsl?:string, theme?:string, onEvent?:function}} [options]
|
|
11
|
+
*/
|
|
12
|
+
export function tokui(node, options) {
|
|
13
|
+
let ui = null;
|
|
14
|
+
|
|
15
|
+
const ensure = (opts) => {
|
|
16
|
+
if (ui) return ui;
|
|
17
|
+
ui = new TokUI({ container: node });
|
|
18
|
+
return ui;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
// 初始渲染
|
|
22
|
+
if (options) {
|
|
23
|
+
const ui0 = ensure(options);
|
|
24
|
+
if (options.theme) { try { setTheme(options.theme); } catch (e) { /* ignore */ } }
|
|
25
|
+
if (options.dsl) ui0.render(options.dsl);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return {
|
|
29
|
+
update(opts) {
|
|
30
|
+
const u = ensure(opts);
|
|
31
|
+
if (opts && opts.theme) { try { setTheme(opts.theme); } catch (e) { /* ignore */ } }
|
|
32
|
+
if (opts && opts.dsl != null) u.render(opts.dsl);
|
|
33
|
+
},
|
|
34
|
+
destroy() {
|
|
35
|
+
if (ui && ui.disconnect) ui.disconnect();
|
|
36
|
+
ui = null;
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export default tokui;
|