@yushaw/sanqian-chat 0.1.1 → 0.2.1
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.md +116 -0
- package/dist/core/index.d.mts +180 -6
- package/dist/core/index.d.ts +180 -6
- package/dist/core/index.js +548 -64
- package/dist/core/index.mjs +534 -63
- package/dist/main/index.d.mts +320 -5
- package/dist/main/index.d.ts +320 -5
- package/dist/main/index.js +466 -39
- package/dist/main/index.mjs +454 -38
- package/dist/preload/index.d.ts +88 -0
- package/dist/preload/index.js +5 -1
- package/dist/renderer/index.d.mts +609 -18
- package/dist/renderer/index.d.ts +609 -18
- package/dist/renderer/index.js +7870 -537
- package/dist/renderer/index.mjs +7854 -538
- package/package.json +16 -4
- package/src/renderer/styles/baseStyles.ts +74 -0
- package/src/renderer/styles/chat.css +3674 -0
- package/src/renderer/styles/chatCss.ts +11 -0
- package/src/renderer/styles/coreCss.ts +3237 -0
- package/src/renderer/styles/preflightCss.ts +454 -0
- package/src/renderer/styles/safe.css +3227 -0
- package/src/renderer/styles/safeCss.ts +10 -0
- package/src/renderer/styles/tailwind.css +683 -0
- package/src/renderer/styles/variables.css +704 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yushaw/sanqian-chat",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "Floating chat window SDK for Sanqian AI Assistant",
|
|
5
5
|
"main": "./dist/main/index.js",
|
|
6
6
|
"types": "./dist/main/index.d.ts",
|
|
@@ -20,24 +20,36 @@
|
|
|
20
20
|
"import": "./dist/renderer/index.mjs",
|
|
21
21
|
"require": "./dist/renderer/index.js"
|
|
22
22
|
},
|
|
23
|
+
"./renderer/styles/chat.css": "./src/renderer/styles/chat.css",
|
|
24
|
+
"./renderer/styles/safe.css": "./src/renderer/styles/safe.css",
|
|
25
|
+
"./renderer/styles/variables.css": "./src/renderer/styles/variables.css",
|
|
23
26
|
"./preload": {
|
|
24
27
|
"types": "./dist/preload/index.d.ts",
|
|
25
28
|
"require": "./dist/preload/index.js"
|
|
26
29
|
}
|
|
27
30
|
},
|
|
28
31
|
"files": [
|
|
29
|
-
"dist"
|
|
32
|
+
"dist",
|
|
33
|
+
"src/renderer/styles"
|
|
30
34
|
],
|
|
31
35
|
"scripts": {
|
|
32
|
-
"build": "tsup",
|
|
36
|
+
"build": "npm run build:css && tsup",
|
|
37
|
+
"build:css": "node scripts/build-css.js",
|
|
33
38
|
"dev": "tsup --watch",
|
|
39
|
+
"dev:test": "vite --config dev/vite.config.ts",
|
|
34
40
|
"typecheck": "tsc --noEmit",
|
|
35
41
|
"clean": "rimraf dist",
|
|
36
42
|
"test": "vitest run",
|
|
37
43
|
"test:watch": "vitest"
|
|
38
44
|
},
|
|
45
|
+
"dependencies": {
|
|
46
|
+
"@yushaw/sanqian-sdk": "^0.3.0",
|
|
47
|
+
"react-virtuoso": "^4.15.0",
|
|
48
|
+
"rehype-harden": "^1.1.6",
|
|
49
|
+
"remark-gfm": "^4.0.1",
|
|
50
|
+
"streamdown": "^1.6.9"
|
|
51
|
+
},
|
|
39
52
|
"peerDependencies": {
|
|
40
|
-
"@yushaw/sanqian-sdk": ">=0.2.14",
|
|
41
53
|
"electron": ">=28.0.0",
|
|
42
54
|
"react": ">=18.0.0",
|
|
43
55
|
"react-dom": ">=18.0.0",
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { SAFE_CSS } from './safeCss';
|
|
2
|
+
import { CHAT_CSS } from './chatCss';
|
|
3
|
+
|
|
4
|
+
const SAFE_STYLE_ID = 'sanqian-chat-safe-styles';
|
|
5
|
+
const FULL_STYLE_ID = 'sanqian-chat-full-styles';
|
|
6
|
+
|
|
7
|
+
type StyleMode = 'safe' | 'full' | false;
|
|
8
|
+
|
|
9
|
+
interface GlobalWindow {
|
|
10
|
+
__SANQIAN_CHAT_DISABLE_STYLES__?: boolean;
|
|
11
|
+
__SANQIAN_CHAT_STYLE_MODE__?: StyleMode;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Inject chat styles into the document.
|
|
16
|
+
*
|
|
17
|
+
* Style modes:
|
|
18
|
+
* - 'safe' (default): CSS variables + component styles + Tailwind utilities.
|
|
19
|
+
* No global resets (preflight). Safe for third-party integration.
|
|
20
|
+
* - 'full': Complete styles including Tailwind CSS preflight.
|
|
21
|
+
* Use this for standalone windows where you control the entire page.
|
|
22
|
+
* - false: Disable all style injection.
|
|
23
|
+
*
|
|
24
|
+
* Configure via:
|
|
25
|
+
* - window.__SANQIAN_CHAT_STYLE_MODE__ = 'full' | 'safe' | false
|
|
26
|
+
* - window.__SANQIAN_CHAT_DISABLE_STYLES__ = true (legacy, same as 'false')
|
|
27
|
+
*
|
|
28
|
+
* Or import CSS directly:
|
|
29
|
+
* - '@yushaw/sanqian-chat/renderer/styles/safe.css' (no preflight)
|
|
30
|
+
* - '@yushaw/sanqian-chat/renderer/styles/chat.css' (full with preflight)
|
|
31
|
+
*/
|
|
32
|
+
export function ensureChatBaseStyles(): void {
|
|
33
|
+
if (typeof document === 'undefined') return;
|
|
34
|
+
|
|
35
|
+
const win = window as GlobalWindow;
|
|
36
|
+
|
|
37
|
+
// Legacy opt-out
|
|
38
|
+
if (win.__SANQIAN_CHAT_DISABLE_STYLES__) return;
|
|
39
|
+
|
|
40
|
+
// Determine style mode
|
|
41
|
+
const mode: StyleMode = win.__SANQIAN_CHAT_STYLE_MODE__ ?? 'safe';
|
|
42
|
+
if (mode === false) return;
|
|
43
|
+
|
|
44
|
+
if (mode === 'full') {
|
|
45
|
+
// Full styles (includes Tailwind preflight)
|
|
46
|
+
if (document.getElementById(FULL_STYLE_ID)) return;
|
|
47
|
+
// Remove safe styles if present
|
|
48
|
+
document.getElementById(SAFE_STYLE_ID)?.remove();
|
|
49
|
+
const style = document.createElement('style');
|
|
50
|
+
style.id = FULL_STYLE_ID;
|
|
51
|
+
style.textContent = CHAT_CSS;
|
|
52
|
+
document.head.appendChild(style);
|
|
53
|
+
} else {
|
|
54
|
+
// Safe styles (default) - no global resets, but includes utilities
|
|
55
|
+
if (document.getElementById(SAFE_STYLE_ID)) return;
|
|
56
|
+
if (document.getElementById(FULL_STYLE_ID)) return; // Don't downgrade
|
|
57
|
+
const style = document.createElement('style');
|
|
58
|
+
style.id = SAFE_STYLE_ID;
|
|
59
|
+
style.textContent = SAFE_CSS;
|
|
60
|
+
document.head.appendChild(style);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Inject full chat styles including Tailwind preflight.
|
|
66
|
+
* Use this for standalone windows where you control the entire page.
|
|
67
|
+
*
|
|
68
|
+
* @deprecated Use window.__SANQIAN_CHAT_STYLE_MODE__ = 'full' instead
|
|
69
|
+
*/
|
|
70
|
+
export function ensureFullChatStyles(): void {
|
|
71
|
+
if (typeof document === 'undefined') return;
|
|
72
|
+
(window as GlobalWindow).__SANQIAN_CHAT_STYLE_MODE__ = 'full';
|
|
73
|
+
ensureChatBaseStyles();
|
|
74
|
+
}
|