@qingwu-ui/ai-editor 0.9.0-beta.24 → 0.9.0-beta.26
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 +26 -10
- package/dist/components/release-notes-dialog.d.ts +1 -1
- package/dist/components/release-notes-dialog.d.ts.map +1 -1
- package/dist/editor/ai-editor.d.ts.map +1 -1
- package/dist/{export-dialog-BSEeEEHv.cjs → export-dialog-BJReD1PN.cjs} +1 -1
- package/dist/{export-dialog-CL7ie13Z.js → export-dialog-CJhm3uqR.js} +1 -1
- package/dist/index.cjs +4 -4
- package/dist/index.js +6 -7
- package/dist/{md-import-dialog-CnstzrIK.cjs → md-import-dialog-CVvu-Adt.cjs} +1 -1
- package/dist/{md-import-dialog-Cf3ZOwA_.js → md-import-dialog-DbC-NCH_.js} +1 -1
- package/dist/{sanitize-CrbFQE46.cjs → sanitize-Bcj55kwd.cjs} +1 -1
- package/dist/{sanitize-z8gMk0lV.js → sanitize-wGLeVLFO.js} +1 -1
- package/dist/{signed-fetch-DiWXujJ1.cjs → signed-fetch-BiI-JlzZ.cjs} +1 -1
- package/dist/{storage-settings-dialog-DZqqDAiO.js → storage-settings-dialog-DnWNQWjN.js} +3 -3
- package/dist/storage-settings-dialog-zPgJahMO.cjs +1 -0
- package/dist/styles.css +1 -1
- package/dist/{video-embed-dialog-AeGcMb4X.js → video-embed-dialog-B0_pc5xe.js} +1 -1
- package/dist/video-embed-dialog-f5HKKPzg.cjs +1 -0
- package/package.json +25 -69
- package/scripts/cli.mjs +28 -0
- package/scripts/copy-assets.mjs +114 -0
- package/dist/storage-settings-dialog-ZtMUoApJ.cjs +0 -1
- package/dist/video-embed-dialog-BbVHq51W.cjs +0 -1
|
@@ -79,7 +79,7 @@ var c = ({ open: c, onClose: l, onInsert: u }) => {
|
|
|
79
79
|
onClick: S
|
|
80
80
|
}), /* @__PURE__ */ a("div", {
|
|
81
81
|
ref: g,
|
|
82
|
-
className: "relative w-[calc(100vw-
|
|
82
|
+
className: "relative w-[calc(100vw-2rem)] max-w-[520px] max-h-[90dvh] bg-background rounded-2xl shadow-2xl border border-default-200 overflow-hidden animate-in",
|
|
83
83
|
children: [
|
|
84
84
|
/* @__PURE__ */ a("div", {
|
|
85
85
|
className: "flex items-center justify-between px-5 py-4 border-b border-default-100",
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
let e=require("react"),t=require("react/jsx-runtime");function n(e){return e.trim()?/bilibili\.com|BV[a-zA-Z0-9]{10}|av\d+/i.test(e)?`bilibili`:/xiaohongshu\.com|xhslink\.com/i.test(e)?`xiaohongshu`:/\.(mp4|m3u8|webm|ogg|flv|mkv|mov|avi|wmv|ts|m4v|3gp|f4v|rmvb)(\?|$)/i.test(e)||/\/.*\.(mp4|m3u8|mov|webm|flv|mkv)/i.test(e)?`direct`:`unknown`:`unknown`}function r(e){let t=e.match(/BV[a-zA-Z0-9]{10}/);if(t)return t[0];let n=e.match(/av(\d+)/i);return n?n[0]:e.trim()}var i=({open:i,onClose:a,onInsert:o})=>{let[s,c]=(0,e.useState)(``),[l,u]=(0,e.useState)(null),d=(0,e.useRef)(null),f=(0,e.useRef)(null),p=`video-preview-player`,m=n(s.trim()),h=m!==`unknown`,g=m===`bilibili`||m===`xiaohongshu`;(0,e.useEffect)(()=>{if(m!==`direct`||!i)return;let e=!1,t=setTimeout(async()=>{if(!e&&!(!document.getElementById(p)||d.current))try{let{default:t}=await import(`xgplayer`);if(e||!document.getElementById(p))return;d.current=new t({id:p,url:s.trim(),width:`100%`,fluid:!0,fitVideoSize:`fixWidth`,autoplay:!1,controls:!0,ignores:[`fullscreen`],lang:`zh-cn`})}catch{}},200);return()=>{e=!0,clearTimeout(t),d.current&&=(d.current.destroy(),null)}},[m,s,i]);let _=(0,e.useCallback)(()=>{if(!h){u(`请输入有效的视频链接`);return}o(s.trim()),c(``),u(null),d.current&&=(d.current.destroy(),null),a()},[s,h,o,a]),v=(0,e.useCallback)(()=>{c(``),u(null),d.current&&=(d.current.destroy(),null),a()},[a]);return(0,e.useEffect)(()=>{if(!i)return;let e=f.current;if(!e)return;let t=e=>{let t=e.clipboardData?.getData(`text`)?.trim();t&&n(t)!==`unknown`&&(e.preventDefault(),c(t))};return e.addEventListener(`paste`,t),()=>e.removeEventListener(`paste`,t)},[i]),(0,e.useEffect)(()=>{if(!i||m!==`direct`)return;let e=e=>{if(e.key!==` `)return;let t=e.target;if(t&&(t.tagName===`INPUT`||t.tagName===`TEXTAREA`))return;let n=d.current;n&&(e.preventDefault(),n.paused?n.play():n.pause())};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[i,m]),i?(0,t.jsxs)(`div`,{className:`fixed inset-0 z-[9999] flex items-center justify-center`,children:[(0,t.jsx)(`div`,{className:`absolute inset-0 bg-black/40 backdrop-blur-sm`,onClick:v}),(0,t.jsxs)(`div`,{ref:f,className:`relative w-[calc(100vw-2rem)] max-w-[520px] max-h-[90dvh] bg-background rounded-2xl shadow-2xl border border-default-200 overflow-hidden animate-in`,children:[(0,t.jsxs)(`div`,{className:`flex items-center justify-between px-5 py-4 border-b border-default-100`,children:[(0,t.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,t.jsx)(`svg`,{className:`w-5 h-5 text-primary`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,strokeWidth:`2`,children:(0,t.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M15.75 10.5l4.72-4.72a.75.75 0 011.28.53v11.38a.75.75 0 01-1.28.53l-4.72-4.72M4.5 18.75h9a2.25 2.25 0 002.25-2.25v-9a2.25 2.25 0 00-2.25-2.25h-9A2.25 2.25 0 002.25 7.5v9a2.25 2.25 0 002.25 2.25z`})}),(0,t.jsx)(`h2`,{className:`text-base font-semibold`,children:`导入视频`})]}),(0,t.jsx)(`button`,{type:`button`,className:`w-7 h-7 flex items-center justify-center rounded-lg text-default-400 hover:text-default-600 hover:bg-default-100 transition-colors`,onClick:v,children:`✕`})]}),(0,t.jsxs)(`div`,{className:`p-5 space-y-4`,children:[(0,t.jsxs)(`div`,{children:[(0,t.jsx)(`label`,{className:`block text-xs font-medium text-default-600 mb-1.5`,children:`粘贴视频链接`}),(0,t.jsx)(`input`,{type:`text`,className:`w-full px-3 py-2.5 rounded-xl border border-default-200 bg-background text-sm focus:outline-none focus:border-primary transition-colors`,placeholder:`粘贴视频直链、B站链接 或 小红书链接...`,value:s,onChange:e=>{c(e.target.value),u(null)},onKeyDown:e=>{e.key===`Enter`&&_()}}),(0,t.jsx)(`p`,{className:`mt-1.5 text-[11px] text-default-400`,children:`支持直链 (mp4/m3u8/webm…) · B站链接 · 小红书链接 — 粘贴后自动识别`})]}),s.trim()&&(0,t.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,t.jsx)(`span`,{className:`text-xs text-default-400`,children:`识别为:`}),(0,t.jsx)(`span`,{className:`px-2 py-0.5 text-xs rounded-full font-medium ${m===`bilibili`?`bg-[#fb7299]/10 text-[#fb7299]`:m===`direct`?`bg-blue-100 text-blue-700 dark:bg-blue-900/30 dark:text-blue-400`:m===`xiaohongshu`?`bg-[#ff2442]/10 text-[#ff2442]`:`bg-default-100 text-default-500`}`,children:m===`bilibili`?`B站视频`:m===`xiaohongshu`?`小红书`:m===`direct`?`直链视频`:`未知类型`})]}),g&&s.trim()&&(0,t.jsxs)(`div`,{className:`flex items-start gap-2 px-3 py-2.5 rounded-lg bg-amber-50 dark:bg-amber-900/20 border border-amber-200 dark:border-amber-800 text-xs`,children:[(0,t.jsx)(`svg`,{className:`w-4 h-4 shrink-0 mt-px text-amber-500`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,strokeWidth:`2`,children:(0,t.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M12 9v3.75m9-.75a9 9 0 11-18 0 9 9 0 0118 0zm-9 3.75h.008v.008H12v-.008z`})}),(0,t.jsxs)(`div`,{children:[(0,t.jsxs)(`p`,{className:`font-medium text-amber-700 dark:text-amber-400`,children:[`版权提示:`,m===`bilibili`?`B站`:`小红书`,`视频将以官方播放器嵌入,版权归原作者所有。`]}),(0,t.jsx)(`p`,{className:`mt-0.5 text-amber-600 dark:text-amber-500`,children:`请确保您有权限分享该内容。支持通过官方分享链接导入。`})]})]}),m===`direct`&&h?(0,t.jsx)(`div`,{id:p,style:{width:`100%`,aspectRatio:`16/9`,borderRadius:12,overflow:`hidden`,background:`#000`}}):m===`bilibili`&&h?(0,t.jsx)(`div`,{className:`relative rounded-xl overflow-hidden bg-black aspect-video`,children:(0,t.jsx)(`iframe`,{src:`https://player.bilibili.com/player.html?bvid=${r(s.trim())}&page=1&high_quality=1&autoplay=0`,className:`w-full h-full`,allowFullScreen:!0,style:{border:`none`},sandbox:`allow-scripts allow-same-origin allow-popups allow-popups-to-escape-sandbox`,referrerPolicy:`no-referrer-when-downgrade`})}):m===`xiaohongshu`&&h?(0,t.jsxs)(`div`,{className:`flex items-center gap-3 px-4 py-6 rounded-xl border border-dashed border-default-200 bg-default-50 dark:bg-default-100/10`,children:[(0,t.jsx)(`div`,{className:`w-10 h-10 rounded-xl bg-[#ff2442]/10 flex items-center justify-center text-lg`,children:`📌`}),(0,t.jsxs)(`div`,{children:[(0,t.jsx)(`p`,{className:`text-sm font-medium`,children:`小红书笔记`}),(0,t.jsx)(`p`,{className:`text-xs text-default-400`,children:`导入后将显示为卡片样式,点击跳转至小红书查看`})]})]}):s.trim()&&!h?(0,t.jsx)(`div`,{className:`flex items-center justify-center py-10 rounded-xl border border-dashed border-default-200 text-sm text-default-400`,children:`无法识别该链接类型,请检查后重试`}):(0,t.jsxs)(`div`,{className:`flex flex-col items-center justify-center gap-3 py-10 rounded-xl border-2 border-dashed border-default-200 bg-default-50 dark:bg-default-100/10 text-default-400`,children:[(0,t.jsx)(`svg`,{className:`w-10 h-10`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,strokeWidth:1,children:(0,t.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M15.75 10.5l4.72-4.72a.75.75 0 011.28.53v11.38a.75.75 0 01-1.28.53l-4.72-4.72M4.5 18.75h9a2.25 2.25 0 002.25-2.25v-9a2.25 2.25 0 00-2.25-2.25h-9A2.25 2.25 0 002.25 7.5v9a2.25 2.25 0 002.25 2.25z`})}),(0,t.jsxs)(`div`,{className:`text-center`,children:[(0,t.jsx)(`p`,{className:`text-sm`,children:`粘贴链接后自动识别并预览`}),(0,t.jsx)(`p`,{className:`text-xs mt-1`,children:`支持直链 mp4/m3u8 · B站 · 小红书`})]})]}),l&&(0,t.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-2.5 rounded-lg bg-danger-50 dark:bg-danger-900/20 text-sm text-danger`,children:[(0,t.jsx)(`svg`,{className:`w-4 h-4 shrink-0`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,strokeWidth:2,children:(0,t.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-2.5L13.732 4c-.77-.833-2.694-.833-3.464 0L3.34 16.5c-.77.833.192 2.5 1.732 2.5z`})}),l]}),(0,t.jsxs)(`div`,{className:`flex gap-2 pt-1`,children:[(0,t.jsx)(`button`,{type:`button`,className:`flex-1 py-2.5 rounded-xl bg-primary text-white text-sm font-medium hover:opacity-90 disabled:opacity-40 transition-opacity`,disabled:!h,onClick:_,children:`导入视频`}),(0,t.jsx)(`button`,{type:`button`,className:`px-4 py-2.5 rounded-xl border border-default-200 text-sm hover:bg-default-50 dark:hover:bg-default-100/10 transition-colors`,onClick:v,children:`取消`})]})]}),(0,t.jsx)(`div`,{className:`px-5 py-2.5 border-t border-default-100 text-[11px] text-default-300 text-center`,children:`直链使用 xgplayer 播放 · B站/小红书使用官方播放器`})]})]}):null};exports.VideoEmbedDialog=i;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@qingwu-ui/ai-editor",
|
|
3
|
-
"version": "0.9.0-beta.
|
|
3
|
+
"version": "0.9.0-beta.26",
|
|
4
4
|
"description": "青梧 AI 编辑器 —— 面向中文用户的智能富文本编辑器,基于 Tiptap + React 19",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -34,6 +34,8 @@
|
|
|
34
34
|
"dist/styles.css",
|
|
35
35
|
"dist/editor",
|
|
36
36
|
"dist/components",
|
|
37
|
+
"scripts/cli.mjs",
|
|
38
|
+
"scripts/copy-assets.mjs",
|
|
37
39
|
"README.md",
|
|
38
40
|
"LICENSE"
|
|
39
41
|
],
|
|
@@ -53,19 +55,6 @@
|
|
|
53
55
|
"typecheck": "tsc --noEmit"
|
|
54
56
|
},
|
|
55
57
|
"dependencies": {
|
|
56
|
-
"@qingwu-ui/text-layout": "^0.9.0-beta",
|
|
57
|
-
"@qingwu-ui/toast": "^0.9.0-beta",
|
|
58
|
-
"beautiful-mermaid": "^1.1.3",
|
|
59
|
-
"cmdk": "^1.1.1",
|
|
60
|
-
"dompurify": "^3.4.12",
|
|
61
|
-
"highlight.js": "~11.11.0",
|
|
62
|
-
"lowlight": "^3.3.0",
|
|
63
|
-
"tiptap-markdown": "0.9",
|
|
64
|
-
"xgplayer": "^3.0.26"
|
|
65
|
-
},
|
|
66
|
-
"devDependencies": {
|
|
67
|
-
"@ai-sdk/openai": "^4.0.18",
|
|
68
|
-
"@biomejs/biome": "^2.5.5",
|
|
69
58
|
"@file-viewer/core": "2.2.2",
|
|
70
59
|
"@file-viewer/react": "2.2.2",
|
|
71
60
|
"@file-viewer/renderer-archive": "2.2.2",
|
|
@@ -74,12 +63,8 @@
|
|
|
74
63
|
"@file-viewer/renderer-spreadsheet": "2.2.2",
|
|
75
64
|
"@file-viewer/renderer-text": "2.2.2",
|
|
76
65
|
"@file-viewer/renderer-word": "2.2.2",
|
|
77
|
-
"@
|
|
78
|
-
"@
|
|
79
|
-
"@tailwindcss/typography": "^0.5.16",
|
|
80
|
-
"@tailwindcss/vite": "^4.3.3",
|
|
81
|
-
"@testing-library/jest-dom": "^7.0.0",
|
|
82
|
-
"@testing-library/react": "^16.3.2",
|
|
66
|
+
"@qingwu-ui/text-layout": "^0.9.0-beta",
|
|
67
|
+
"@qingwu-ui/toast": "^0.9.0-beta",
|
|
83
68
|
"@tiptap/core": "^3.28.0",
|
|
84
69
|
"@tiptap/extension-character-count": "^3.28.0",
|
|
85
70
|
"@tiptap/extension-code-block-lowlight": "^3.28.0",
|
|
@@ -101,6 +86,26 @@
|
|
|
101
86
|
"@tiptap/react": "^3.28.0",
|
|
102
87
|
"@tiptap/starter-kit": "^3.28.0",
|
|
103
88
|
"@tiptap/suggestion": "^3.28.0",
|
|
89
|
+
"beautiful-mermaid": "^1.1.3",
|
|
90
|
+
"cmdk": "^1.1.1",
|
|
91
|
+
"dompurify": "^3.4.12",
|
|
92
|
+
"highlight.js": "~11.11.0",
|
|
93
|
+
"lowlight": "^3.3.0",
|
|
94
|
+
"tiptap-markdown": "0.9",
|
|
95
|
+
"xgplayer": "^3.0.26"
|
|
96
|
+
},
|
|
97
|
+
"bin": {
|
|
98
|
+
"qingwu-ai-editor": "scripts/cli.mjs"
|
|
99
|
+
},
|
|
100
|
+
"devDependencies": {
|
|
101
|
+
"@ai-sdk/openai": "^4.0.18",
|
|
102
|
+
"@biomejs/biome": "^2.5.5",
|
|
103
|
+
"@file-viewer/vite-plugin": "2.2.2",
|
|
104
|
+
"@tailwindcss/postcss": "^4.3.3",
|
|
105
|
+
"@tailwindcss/typography": "^0.5.16",
|
|
106
|
+
"@tailwindcss/vite": "^4.3.3",
|
|
107
|
+
"@testing-library/jest-dom": "^7.0.0",
|
|
108
|
+
"@testing-library/react": "^16.3.2",
|
|
104
109
|
"@types/node": "^26.1.1",
|
|
105
110
|
"@types/react": "^19.2.17",
|
|
106
111
|
"@types/react-dom": "^19.2.3",
|
|
@@ -122,34 +127,6 @@
|
|
|
122
127
|
"react-dom": "^19.0.0",
|
|
123
128
|
"devicon": "^2.17.0",
|
|
124
129
|
"@ai-sdk/openai": "^4.0.18",
|
|
125
|
-
"@file-viewer/react": "2.2.2",
|
|
126
|
-
"@file-viewer/renderer-archive": "2.2.2",
|
|
127
|
-
"@file-viewer/renderer-pdf": "2.2.2",
|
|
128
|
-
"@file-viewer/renderer-presentation": "2.2.2",
|
|
129
|
-
"@file-viewer/renderer-spreadsheet": "2.2.2",
|
|
130
|
-
"@file-viewer/renderer-text": "2.2.2",
|
|
131
|
-
"@file-viewer/renderer-word": "2.2.2",
|
|
132
|
-
"@tiptap/core": "^3.28.0",
|
|
133
|
-
"@tiptap/extension-character-count": "^3.28.0",
|
|
134
|
-
"@tiptap/extension-code-block-lowlight": "^3.28.0",
|
|
135
|
-
"@tiptap/extension-color": "^3.28.0",
|
|
136
|
-
"@tiptap/extension-highlight": "^3.28.0",
|
|
137
|
-
"@tiptap/extension-horizontal-rule": "^3.28.0",
|
|
138
|
-
"@tiptap/extension-image": "^3.28.0",
|
|
139
|
-
"@tiptap/extension-link": "^3.28.0",
|
|
140
|
-
"@tiptap/extension-placeholder": "^3.28.0",
|
|
141
|
-
"@tiptap/extension-table": "^3.28.0",
|
|
142
|
-
"@tiptap/extension-table-cell": "^3.28.0",
|
|
143
|
-
"@tiptap/extension-table-header": "^3.28.0",
|
|
144
|
-
"@tiptap/extension-table-row": "^3.28.0",
|
|
145
|
-
"@tiptap/extension-task-item": "^3.28.0",
|
|
146
|
-
"@tiptap/extension-task-list": "^3.28.0",
|
|
147
|
-
"@tiptap/extension-text-style": "^3.28.0",
|
|
148
|
-
"@tiptap/extension-underline": "^3.28.0",
|
|
149
|
-
"@tiptap/pm": "^3.28.0",
|
|
150
|
-
"@tiptap/react": "^3.28.0",
|
|
151
|
-
"@tiptap/starter-kit": "^3.28.0",
|
|
152
|
-
"@tiptap/suggestion": "^3.28.0",
|
|
153
130
|
"ai": "^7.0.35"
|
|
154
131
|
},
|
|
155
132
|
"peerDependenciesMeta": {
|
|
@@ -158,27 +135,6 @@
|
|
|
158
135
|
},
|
|
159
136
|
"@ai-sdk/openai": {
|
|
160
137
|
"optional": true
|
|
161
|
-
},
|
|
162
|
-
"@file-viewer/react": {
|
|
163
|
-
"optional": true
|
|
164
|
-
},
|
|
165
|
-
"@file-viewer/renderer-archive": {
|
|
166
|
-
"optional": true
|
|
167
|
-
},
|
|
168
|
-
"@file-viewer/renderer-pdf": {
|
|
169
|
-
"optional": true
|
|
170
|
-
},
|
|
171
|
-
"@file-viewer/renderer-presentation": {
|
|
172
|
-
"optional": true
|
|
173
|
-
},
|
|
174
|
-
"@file-viewer/renderer-spreadsheet": {
|
|
175
|
-
"optional": true
|
|
176
|
-
},
|
|
177
|
-
"@file-viewer/renderer-text": {
|
|
178
|
-
"optional": true
|
|
179
|
-
},
|
|
180
|
-
"@file-viewer/renderer-word": {
|
|
181
|
-
"optional": true
|
|
182
138
|
}
|
|
183
139
|
},
|
|
184
140
|
"publishConfig": {
|
package/scripts/cli.mjs
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { dirname, join } from "node:path";
|
|
3
|
+
/**
|
|
4
|
+
* @qingwu-ui/ai-editor 命令行入口
|
|
5
|
+
*
|
|
6
|
+
* 用法:
|
|
7
|
+
* npx @qingwu-ui/ai-editor copy-assets [--out 目录]
|
|
8
|
+
* 拷贝附件预览(PDF/Word/Excel/PPT/压缩包)所需的 worker/wasm/字体资源。
|
|
9
|
+
*/
|
|
10
|
+
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
11
|
+
|
|
12
|
+
const here = dirname(fileURLToPath(import.meta.url));
|
|
13
|
+
const [command, ...rest] = process.argv.slice(2);
|
|
14
|
+
|
|
15
|
+
if (command === "copy-assets" || command === "init-assets") {
|
|
16
|
+
// copy-assets.mjs 自己读 process.argv,需要把命令名剥掉只留参数
|
|
17
|
+
process.argv = [process.argv[0], process.argv[1], ...rest];
|
|
18
|
+
await import(pathToFileURL(join(here, "copy-assets.mjs")).href);
|
|
19
|
+
} else {
|
|
20
|
+
console.log(`@qingwu-ui/ai-editor CLI
|
|
21
|
+
|
|
22
|
+
命令:
|
|
23
|
+
copy-assets [--out 目录] 拷贝附件预览所需 worker/wasm/字体到 public/file-viewer
|
|
24
|
+
(默认输出到当前目录的 public/file-viewer)
|
|
25
|
+
`);
|
|
26
|
+
if (command) console.error(`未知命令:${command}`);
|
|
27
|
+
process.exit(command ? 1 : 0);
|
|
28
|
+
}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* 附件预览 worker/wasm/字体资源一次性拷贝。
|
|
4
|
+
*
|
|
5
|
+
* 背景:@file-viewer 的渲染引擎(PDF / Word / Excel / PPT / 压缩包)在运行时
|
|
6
|
+
* 需要一批 worker、wasm、字体静态文件。这些不是普通 JS 模块,npm install 不会
|
|
7
|
+
* 自动放进静态目录,所以由本命令从已安装的 @file-viewer 包及其传递依赖中抽出,
|
|
8
|
+
* 拷到项目的 public/file-viewer(路径与 FILE_VIEWER_OPTIONS 默认值对齐)。
|
|
9
|
+
*
|
|
10
|
+
* 用法:
|
|
11
|
+
* npx @qingwu-ui/ai-editor copy-assets # 拷到 ./public/file-viewer
|
|
12
|
+
* npx @qingwu-ui/ai-editor copy-assets --out static/fv # 自定义输出目录
|
|
13
|
+
*
|
|
14
|
+
* 注意:请在「项目根目录」执行,默认输出到 public/。
|
|
15
|
+
*/
|
|
16
|
+
import { cpSync, existsSync, mkdirSync } from "node:fs";
|
|
17
|
+
import { createRequire } from "node:module";
|
|
18
|
+
import { basename, dirname, join, resolve } from "node:path";
|
|
19
|
+
import { pathToFileURL } from "node:url";
|
|
20
|
+
|
|
21
|
+
const args = process.argv.slice(2);
|
|
22
|
+
const outIdx = args.indexOf("--out");
|
|
23
|
+
const outDir = resolve(
|
|
24
|
+
process.cwd(),
|
|
25
|
+
outIdx >= 0 && args[outIdx + 1] ? args[outIdx + 1] : join("public", "file-viewer"),
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
// 以本包自身位置为起点解析 @file-viewer 锚点包,再从锚点包解析它的传递依赖。
|
|
29
|
+
// 这样无论 bun(隔离 node_modules)、npm/pnpm(提升/符号链接)布局如何都能定位。
|
|
30
|
+
const selfRequire = createRequire(import.meta.url);
|
|
31
|
+
function anchorRequire(anchor) {
|
|
32
|
+
const pkgJson = selfRequire.resolve(`${anchor}/package.json`);
|
|
33
|
+
return createRequire(pathToFileURL(pkgJson));
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const pdfReq = anchorRequire("@file-viewer/renderer-pdf");
|
|
37
|
+
const wordReq = anchorRequire("@file-viewer/renderer-word");
|
|
38
|
+
const presReq = anchorRequire("@file-viewer/renderer-presentation");
|
|
39
|
+
const arcReq = anchorRequire("@file-viewer/renderer-archive");
|
|
40
|
+
const ssReq = anchorRequire("@file-viewer/renderer-spreadsheet");
|
|
41
|
+
|
|
42
|
+
/** 取某包安装目录:解析入口文件(受 exports 限制时也可用),再向上找到包根 */
|
|
43
|
+
function pkgDir(req, name) {
|
|
44
|
+
let entry;
|
|
45
|
+
try {
|
|
46
|
+
entry = req.resolve(name);
|
|
47
|
+
} catch {
|
|
48
|
+
// 入口兜底:用已知存在的子路径
|
|
49
|
+
entry = req.resolve(`${name}/package.json`);
|
|
50
|
+
return dirname(entry);
|
|
51
|
+
}
|
|
52
|
+
const tail = name.split("/").pop();
|
|
53
|
+
let dir = dirname(entry);
|
|
54
|
+
for (let i = 0; i < 8; i++) {
|
|
55
|
+
if (basename(dir) === tail) return dir;
|
|
56
|
+
dir = dirname(dir);
|
|
57
|
+
}
|
|
58
|
+
return dirname(entry);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const pdfjs = pkgDir(pdfReq, "pdfjs-dist");
|
|
62
|
+
const noto = pkgDir(pdfReq, "@fontsource-variable/noto-sans-sc");
|
|
63
|
+
const fvDocx = pkgDir(wordReq, "@file-viewer/docx");
|
|
64
|
+
const fvPpt = pkgDir(presReq, "@file-viewer/ppt");
|
|
65
|
+
const fvPptx = pkgDir(presReq, "@file-viewer/pptx");
|
|
66
|
+
const libarchive = pkgDir(arcReq, "libarchive.js");
|
|
67
|
+
const spreadsheet = pkgDir(ssReq, "@file-viewer/renderer-spreadsheet");
|
|
68
|
+
|
|
69
|
+
// [来源, 目标] 列表,目标相对 outDir
|
|
70
|
+
const copies = [
|
|
71
|
+
[join(pdfjs, "build/pdf.worker.mjs"), "vendor/pdf/pdf.worker.mjs"],
|
|
72
|
+
[join(pdfjs, "cmaps"), "vendor/pdf/cmaps"],
|
|
73
|
+
[join(pdfjs, "wasm"), "vendor/pdf/wasm"],
|
|
74
|
+
[join(pdfjs, "standard_fonts"), "vendor/pdf/standard_fonts"],
|
|
75
|
+
[join(noto, "files"), "vendor/pdf/fonts/files"],
|
|
76
|
+
[join(noto, "index.css"), "vendor/pdf/fonts/noto-sans-sc.css"],
|
|
77
|
+
[join(fvDocx, "dist/docx-preview.worker.js"), "vendor/docx/docx.worker.js"],
|
|
78
|
+
[join(fvDocx, "dist/jszip.min.js"), "vendor/docx/jszip.min.js"],
|
|
79
|
+
[join(fvPpt, "index.mjs"), "vendor/ppt/index.mjs"],
|
|
80
|
+
[join(fvPpt, "worker.mjs"), "vendor/ppt/worker.mjs"],
|
|
81
|
+
[join(fvPpt, "frame-cache.mjs"), "vendor/ppt/frame-cache.mjs"],
|
|
82
|
+
[join(fvPpt, "ppt-native.wasm"), "vendor/ppt/ppt-native.wasm"],
|
|
83
|
+
[join(fvPpt, "ppt-font-cjk.otf"), "vendor/ppt/ppt-font-cjk.otf"],
|
|
84
|
+
[join(fvPpt, "manifest.json"), "vendor/ppt/manifest.json"],
|
|
85
|
+
[join(fvPpt, "package.json"), "vendor/ppt/package.json"],
|
|
86
|
+
[join(fvPpt, "LICENSE"), "vendor/ppt/LICENSE"],
|
|
87
|
+
[join(fvPpt, "NOTICE"), "vendor/ppt/NOTICE"],
|
|
88
|
+
[join(fvPptx, "dist/worker/pptx.worker.js"), "vendor/pptx/pptx.worker.js"],
|
|
89
|
+
[join(libarchive, "dist/worker-bundle.js"), "vendor/libarchive/worker-bundle.js"],
|
|
90
|
+
[join(libarchive, "dist/libarchive.wasm"), "vendor/libarchive/libarchive.wasm"],
|
|
91
|
+
[join(spreadsheet, "dist/worker/sheet.worker.js"), "vendor/xlsx/sheet.worker.js"],
|
|
92
|
+
];
|
|
93
|
+
|
|
94
|
+
let count = 0;
|
|
95
|
+
const missing = [];
|
|
96
|
+
for (const [from, toRel] of copies) {
|
|
97
|
+
if (!existsSync(from)) {
|
|
98
|
+
missing.push(from);
|
|
99
|
+
continue;
|
|
100
|
+
}
|
|
101
|
+
const to = join(outDir, toRel);
|
|
102
|
+
mkdirSync(dirname(to), { recursive: true });
|
|
103
|
+
cpSync(from, to, { recursive: true });
|
|
104
|
+
count++;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
if (missing.length) {
|
|
108
|
+
console.error("以下资源在已安装包中未找到,可能依赖未装好:");
|
|
109
|
+
for (const m of missing) console.error(` - ${m}`);
|
|
110
|
+
process.exit(1);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
console.log(`✓ 已拷贝 ${count} 项附件预览资源到 ${outDir}`);
|
|
114
|
+
console.log(" 确保部署后 /file-viewer/vendor/... 可访问即可(与默认 FILE_VIEWER_OPTIONS 对齐)。");
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
const e=require("./signed-fetch-DiWXujJ1.cjs"),t=require("./storage-VaeLS7eM.cjs"),n=require("./local-D4481lUa.cjs");let r=require("react"),i=require("react/jsx-runtime");var a=[{key:`local`,label:`本地`,icon:`💻`},{key:`s3`,label:`S3 对象存储`,icon:`☁️`}],o=({open:o,onClose:s})=>{let c=t.t(),[l,u]=(0,r.useState)(c?.type===`local`?`local`:`s3`),[d,f]=(0,r.useState)(!1),[p,m]=(0,r.useState)(!1),[h,g]=(0,r.useState)(null),[_,v]=(0,r.useState)(``),[y,b]=(0,r.useState)(``),[x,S]=(0,r.useState)(`auto`),[C,w]=(0,r.useState)(``),[T,E]=(0,r.useState)(``),[D,O]=(0,r.useState)(``),[k,A]=(0,r.useState)(`qingwu`),[j,M]=(0,r.useState)(`{ts}{tz}_{src}_{name}_{rand}{ext}`);(0,r.useEffect)(()=>{let e=t.r();e?.type===`s3`?(v(e.endpoint||``),b(e.bucket||``),S(e.region||`auto`),w(e.accessKeyId||``),E(e.secretAccessKey||``),O(e.customDomain||``),A(e.uploadPrefix||`qingwu`),M(e.nameTemplate||`{ts}{tz}_{src}_{name}_{rand}{ext}`),u(`s3`)):e?.type===`oss`?(v(`https://${e.bucket}.${e.region}.aliyuncs.com`),b(e.bucket||``),S(e.region||`oss-cn-hangzhou`),w(e.accessKeyId||``),E(e.accessKeySecret||``),O(e.customDomain||``),A(e.uploadPrefix||`qingwu`),M(e.nameTemplate||`{ts}{tz}_{src}_{name}_{rand}{ext}`),u(`s3`)):e?.type===`cos`&&(v(`https://${e.bucket}.cos.${e.region}.myqcloud.com`),b(e.bucket||``),S(e.region||`ap-guangzhou`),w(e.secretId||``),E(e.secretKey||``),O(e.customDomain||``),A(e.uploadPrefix||`qingwu`),M(e.nameTemplate||`{ts}{tz}_{src}_{name}_{rand}{ext}`),u(`s3`))},[]),(0,r.useEffect)(()=>{if(!h)return;let e=window.setTimeout(()=>g(null),4e3);return()=>window.clearTimeout(e)},[h]);let N=(0,r.useCallback)(()=>{g(null),t.a(n.t(),{type:`local`,location:`浏览器内存 (Base64 编码)`}),f(!0),setTimeout(()=>{f(!1),s()},600)},[s]),P=(0,r.useCallback)(async()=>{if(!p){m(!0),g(null);try{let e=n.t(),t=new File([`qingwu storage test`],`qingwu-storage-test.txt`,{type:`text/plain`}),r=await e.upload(t,`editor`);await e.remove(r).catch(()=>{}),g({type:`success`,message:`本地存储可用`})}catch(e){g({type:`error`,message:e instanceof Error?e.message:`本地存储测试失败`})}finally{m(!1)}}},[p]),F=(0,r.useCallback)(()=>{if(!_||!y||!C)return;g(null);let r={endpoint:_,bucket:y,region:x,accessKeyId:C,secretAccessKey:T,customDomain:D||void 0,uploadPrefix:k||`qingwu`,nameTemplate:j||`{ts}{tz}_{src}_{name}_{rand}{ext}`};t.a(n.n(r),{type:`s3`,endpoint:_,bucket:y,region:x,accessKeyId:C,secretAccessKey:T,customDomain:D||void 0,uploadPrefix:k||`qingwu`,nameTemplate:j||`{ts}{tz}_{src}_{name}_{rand}{ext}`}),e.t(r),f(!0),setTimeout(()=>{f(!1),s()},600)},[_,y,x,C,T,D,k,j,s]),I=(0,r.useCallback)(async()=>{if(!_||!y||!C||p)return;m(!0),g(null);let e=``;try{let t=n.n({endpoint:_,bucket:y,region:x,accessKeyId:C,secretAccessKey:T,customDomain:D||void 0}),r=new File([`qingwu storage test`],`qingwu-storage-test.txt`,{type:`text/plain`});e=await t.upload(r,`editor`);let i=!1,a=!1;try{i=(await fetch(e,{method:`GET`})).ok}catch{i=!1}if(!i)try{let{signPreviewUrlHeaders:t}=await Promise.resolve().then(()=>require("./signed-fetch-DiWXujJ1.cjs")).then(e=>e.i),{registerS3PreviewConfig:n}=await Promise.resolve().then(()=>require("./signed-fetch-DiWXujJ1.cjs")).then(e=>e.i);n({endpoint:_,bucket:y,region:x,accessKeyId:C,secretAccessKey:T,customDomain:D||void 0});let r=await t(e);r&&(await fetch(e,{headers:r})).ok&&(i=!0,a=!0)}catch{}if(!i)throw Error(`上传成功,但访问失败。请确认 Bucket 读写权限配置正确。`);g({type:`success`,message:a?`存储连接成功(私有桶,通过签名访问)`:`存储连接和公开访问均成功`})}catch(e){g({type:`error`,message:e instanceof Error?e.message:`存储连接失败`})}finally{e&&await n.n({endpoint:_,bucket:y,region:x,accessKeyId:C,secretAccessKey:T,customDomain:D||void 0}).remove(e).catch(()=>{}),m(!1)}},[_,y,x,C,T,D,p]);return o?(0,i.jsxs)(`div`,{className:`fixed inset-0 z-[9999] flex items-center justify-center`,children:[h&&(0,i.jsx)(`div`,{className:`fixed right-4 top-4 z-[10001] w-[calc(100vw-32px)] max-w-sm rounded-xl border px-4 py-3 text-sm shadow-2xl backdrop-blur-sm ${h.type===`success`?`border-green-200 bg-green-50/95 text-green-700`:`border-danger-200 bg-danger-50/95 text-danger`}`,children:(0,i.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,i.jsx)(`span`,{className:`mt-0.5 shrink-0`,children:h.type===`success`?`✓`:`!`}),(0,i.jsx)(`span`,{className:`min-w-0 break-words`,children:h.message})]})}),(0,i.jsx)(`div`,{className:`absolute inset-0 bg-black/40 backdrop-blur-sm`,onClick:s}),(0,i.jsxs)(`div`,{className:`relative w-[calc(100vw-32px)] max-w-[460px] max-h-[85vh] bg-background rounded-2xl shadow-2xl border border-default-200 overflow-hidden animate-in`,children:[(0,i.jsxs)(`div`,{className:`flex items-center justify-between px-5 py-4 border-b border-default-100`,children:[(0,i.jsx)(`h2`,{className:`text-base font-semibold`,children:`存储设置`}),(0,i.jsx)(`button`,{type:`button`,className:`w-7 h-7 flex items-center justify-center rounded-lg text-default-400 hover:text-default-600 hover:bg-default-100 transition-colors`,onClick:s,children:`✕`})]}),c&&(0,i.jsxs)(`div`,{className:`mx-5 mt-4 p-3 rounded-xl bg-default-50 border border-default-100`,children:[(0,i.jsxs)(`div`,{className:`flex items-center gap-2 text-xs text-default-500 mb-1`,children:[(0,i.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full bg-green-500`}),`当前存储服务`]}),(0,i.jsx)(`div`,{className:`text-sm font-medium`,children:c.name}),(0,i.jsx)(`div`,{className:`text-[11px] text-default-400 mt-0.5`,children:c.type===`local`?`位置:浏览器内存 · Base64 编码 · 关闭页面后丢失`:c.type===`s3`&&c.config?.type===`s3`?`${c.config.endpoint} · ${c.config.bucket}${c.config.customDomain?` → ${c.config.customDomain}`:``}`:``})]}),(0,i.jsx)(`div`,{className:`flex border-b border-default-100 px-5 mt-4`,children:a.map(({key:e,label:t,icon:n})=>(0,i.jsxs)(`button`,{type:`button`,className:`flex items-center gap-1.5 px-3 py-2.5 text-sm font-medium transition-colors border-b-2 -mb-[1px] ${l===e?`border-primary text-primary`:`border-transparent text-default-400 hover:text-default-600`}`,onClick:()=>{u(e),f(!1)},children:[(0,i.jsx)(`span`,{children:n}),t]},e))}),(0,i.jsxs)(`div`,{className:`p-5 max-h-[50vh] overflow-y-auto`,children:[l===`local`&&(0,i.jsxs)(`div`,{className:`space-y-4`,children:[(0,i.jsxs)(`div`,{className:`p-4 rounded-xl bg-blue-50 border border-blue-100`,children:[(0,i.jsx)(`p`,{className:`text-sm font-medium text-blue-800 mb-1`,children:`💻 浏览器内存存储`}),(0,i.jsx)(`p`,{className:`text-xs text-blue-600 leading-relaxed`,children:`文件以 Base64 编码存储在浏览器内存中,页面关闭后清除。 适合演示和临时使用,不建议用于生产环境。`})]}),(0,i.jsx)(`button`,{type:`button`,className:`w-full py-2.5 rounded-xl text-sm font-medium transition-all ${d?`bg-green-500 text-white`:`bg-primary text-white hover:opacity-90`}`,onClick:N,children:d?`✓ 已保存`:`使用本地存储`}),(0,i.jsx)(`button`,{type:`button`,className:`w-full py-2.5 rounded-xl text-sm font-medium border border-default-200 hover:bg-default-100 transition-all disabled:opacity-40`,disabled:p,onClick:P,children:p?`测试中...`:`测试连接`})]}),l===`s3`&&(0,i.jsxs)(`div`,{className:`space-y-3`,children:[(0,i.jsx)(`div`,{className:`p-3 rounded-lg bg-default-50 text-xs text-default-500 leading-relaxed mb-1`,children:`兼容 AWS S3、Cloudflare R2、MinIO、阿里云 OSS、腾讯云 COS 等所有 S3 协议对象存储服务。`}),(0,i.jsxs)(`div`,{children:[(0,i.jsx)(`label`,{className:`block text-xs text-default-500 mb-1`,children:`Endpoint *`}),(0,i.jsx)(`input`,{className:`w-full px-3 py-2 rounded-lg border border-default-200 bg-background text-sm focus:outline-none focus:border-primary`,placeholder:`https://<account>.r2.cloudflarestorage.com`,value:_,onChange:e=>v(e.target.value)})]}),(0,i.jsxs)(`div`,{children:[(0,i.jsx)(`label`,{className:`block text-xs text-default-500 mb-1`,children:`Bucket 名称 *`}),(0,i.jsx)(`input`,{className:`w-full px-3 py-2 rounded-lg border border-default-200 bg-background text-sm focus:outline-none focus:border-primary`,placeholder:`my-bucket`,value:y,onChange:e=>b(e.target.value)})]}),(0,i.jsxs)(`div`,{children:[(0,i.jsx)(`label`,{className:`block text-xs text-default-500 mb-1`,children:`Region`}),(0,i.jsx)(`input`,{className:`w-full px-3 py-2 rounded-lg border border-default-200 bg-background text-sm focus:outline-none focus:border-primary`,placeholder:`auto / us-east-1 / ap-northeast-1`,value:x,onChange:e=>S(e.target.value)}),(0,i.jsxs)(`p`,{className:`text-[11px] text-default-400 mt-0.5`,children:[`R2 / MinIO 填 `,(0,i.jsx)(`code`,{children:`auto`}),`,AWS 按实际区域填写`]})]}),(0,i.jsxs)(`div`,{children:[(0,i.jsx)(`label`,{className:`block text-xs text-default-500 mb-1`,children:`Access Key ID *`}),(0,i.jsx)(`input`,{className:`w-full px-3 py-2 rounded-lg border border-default-200 bg-background text-sm focus:outline-none focus:border-primary`,placeholder:`AKIAIOSFODNN7EXAMPLE`,value:C,onChange:e=>w(e.target.value)})]}),(0,i.jsxs)(`div`,{children:[(0,i.jsx)(`label`,{className:`block text-xs text-default-500 mb-1`,children:`Secret Access Key`}),(0,i.jsx)(`input`,{type:`password`,className:`w-full px-3 py-2 rounded-lg border border-default-200 bg-background text-sm focus:outline-none focus:border-primary`,placeholder:`••••••••`,value:T,onChange:e=>E(e.target.value)})]}),(0,i.jsxs)(`div`,{children:[(0,i.jsx)(`label`,{className:`block text-xs text-default-500 mb-1`,children:`自定义访问域名(CDN,可选)`}),(0,i.jsx)(`input`,{className:`w-full px-3 py-2 rounded-lg border border-default-200 bg-background text-sm focus:outline-none focus:border-primary`,placeholder:`cdn.example.com`,value:D,onChange:e=>O(e.target.value)}),(0,i.jsx)(`p`,{className:`text-[11px] text-default-400 mt-0.5`,children:`设置后,上传返回的资源 URL 将使用此域名`})]}),(0,i.jsxs)(`div`,{children:[(0,i.jsx)(`label`,{className:`block text-xs text-default-500 mb-1`,children:`资源目录`}),(0,i.jsx)(`input`,{className:`w-full px-3 py-2 rounded-lg border border-default-200 bg-background text-sm focus:outline-none focus:border-primary`,placeholder:`qingwu`,value:k,onChange:e=>A(e.target.value)}),(0,i.jsx)(`p`,{className:`text-[11px] text-default-400 mt-0.5`,children:`上传文件的存储目录,默认 qingwu(MinIO/S3 路径风格需填 bucket 名)`})]}),(0,i.jsxs)(`div`,{children:[(0,i.jsx)(`label`,{className:`block text-xs text-default-500 mb-1`,children:`文件名模板`}),(0,i.jsx)(`input`,{className:`w-full px-3 py-2 rounded-lg border border-default-200 bg-background text-sm focus:outline-none focus:border-primary`,placeholder:`{ts}{tz}_{src}_{name}_{rand}{ext}`,value:j,onChange:e=>M(e.target.value)}),(0,i.jsx)(`p`,{className:`text-[11px] text-default-400 mt-0.5`,children:`占位符: {ts}=时间戳, {tz}=时区, {src}=出处(editor/cover), {name}=原名, {ext}=扩展名, {rand}=随机串`})]}),(0,i.jsxs)(`div`,{className:`p-3 rounded-lg bg-default-50 text-[11px] text-default-500 leading-relaxed`,children:[`上传路径:`,_&&y?`${_}/${y}/qingwu/...`:`请填写 Endpoint 和 Bucket`,D?`\n访问域名:https://${D}/qingwu/...`:``]}),(0,i.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,i.jsx)(`button`,{type:`button`,className:`py-2.5 rounded-xl text-sm font-medium border border-default-200 hover:bg-default-100 transition-all disabled:opacity-40`,disabled:!_||!y||!C||p,onClick:I,children:p?`测试中...`:`测试连接`}),(0,i.jsx)(`button`,{type:`button`,className:`py-2.5 rounded-xl text-sm font-medium transition-all disabled:opacity-40 ${d?`bg-green-500 text-white`:`bg-primary text-white hover:opacity-90`}`,disabled:!_||!y||!C||p,onClick:F,children:d?`✓ 已保存`:`保存并应用`})]})]})]})]})]}):null};exports.StorageSettingsDialog=o;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
let e=require("react"),t=require("react/jsx-runtime");function n(e){return e.trim()?/bilibili\.com|BV[a-zA-Z0-9]{10}|av\d+/i.test(e)?`bilibili`:/xiaohongshu\.com|xhslink\.com/i.test(e)?`xiaohongshu`:/\.(mp4|m3u8|webm|ogg|flv|mkv|mov|avi|wmv|ts|m4v|3gp|f4v|rmvb)(\?|$)/i.test(e)||/\/.*\.(mp4|m3u8|mov|webm|flv|mkv)/i.test(e)?`direct`:`unknown`:`unknown`}function r(e){let t=e.match(/BV[a-zA-Z0-9]{10}/);if(t)return t[0];let n=e.match(/av(\d+)/i);return n?n[0]:e.trim()}var i=({open:i,onClose:a,onInsert:o})=>{let[s,c]=(0,e.useState)(``),[l,u]=(0,e.useState)(null),d=(0,e.useRef)(null),f=(0,e.useRef)(null),p=`video-preview-player`,m=n(s.trim()),h=m!==`unknown`,g=m===`bilibili`||m===`xiaohongshu`;(0,e.useEffect)(()=>{if(m!==`direct`||!i)return;let e=!1,t=setTimeout(async()=>{if(!e&&!(!document.getElementById(p)||d.current))try{let{default:t}=await import(`xgplayer`);if(e||!document.getElementById(p))return;d.current=new t({id:p,url:s.trim(),width:`100%`,fluid:!0,fitVideoSize:`fixWidth`,autoplay:!1,controls:!0,ignores:[`fullscreen`],lang:`zh-cn`})}catch{}},200);return()=>{e=!0,clearTimeout(t),d.current&&=(d.current.destroy(),null)}},[m,s,i]);let _=(0,e.useCallback)(()=>{if(!h){u(`请输入有效的视频链接`);return}o(s.trim()),c(``),u(null),d.current&&=(d.current.destroy(),null),a()},[s,h,o,a]),v=(0,e.useCallback)(()=>{c(``),u(null),d.current&&=(d.current.destroy(),null),a()},[a]);return(0,e.useEffect)(()=>{if(!i)return;let e=f.current;if(!e)return;let t=e=>{let t=e.clipboardData?.getData(`text`)?.trim();t&&n(t)!==`unknown`&&(e.preventDefault(),c(t))};return e.addEventListener(`paste`,t),()=>e.removeEventListener(`paste`,t)},[i]),(0,e.useEffect)(()=>{if(!i||m!==`direct`)return;let e=e=>{if(e.key!==` `)return;let t=e.target;if(t&&(t.tagName===`INPUT`||t.tagName===`TEXTAREA`))return;let n=d.current;n&&(e.preventDefault(),n.paused?n.play():n.pause())};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[i,m]),i?(0,t.jsxs)(`div`,{className:`fixed inset-0 z-[9999] flex items-center justify-center`,children:[(0,t.jsx)(`div`,{className:`absolute inset-0 bg-black/40 backdrop-blur-sm`,onClick:v}),(0,t.jsxs)(`div`,{ref:f,className:`relative w-[calc(100vw-32px)] max-w-[520px] max-h-[90vh] bg-background rounded-2xl shadow-2xl border border-default-200 overflow-hidden animate-in`,children:[(0,t.jsxs)(`div`,{className:`flex items-center justify-between px-5 py-4 border-b border-default-100`,children:[(0,t.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,t.jsx)(`svg`,{className:`w-5 h-5 text-primary`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,strokeWidth:`2`,children:(0,t.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M15.75 10.5l4.72-4.72a.75.75 0 011.28.53v11.38a.75.75 0 01-1.28.53l-4.72-4.72M4.5 18.75h9a2.25 2.25 0 002.25-2.25v-9a2.25 2.25 0 00-2.25-2.25h-9A2.25 2.25 0 002.25 7.5v9a2.25 2.25 0 002.25 2.25z`})}),(0,t.jsx)(`h2`,{className:`text-base font-semibold`,children:`导入视频`})]}),(0,t.jsx)(`button`,{type:`button`,className:`w-7 h-7 flex items-center justify-center rounded-lg text-default-400 hover:text-default-600 hover:bg-default-100 transition-colors`,onClick:v,children:`✕`})]}),(0,t.jsxs)(`div`,{className:`p-5 space-y-4`,children:[(0,t.jsxs)(`div`,{children:[(0,t.jsx)(`label`,{className:`block text-xs font-medium text-default-600 mb-1.5`,children:`粘贴视频链接`}),(0,t.jsx)(`input`,{type:`text`,className:`w-full px-3 py-2.5 rounded-xl border border-default-200 bg-background text-sm focus:outline-none focus:border-primary transition-colors`,placeholder:`粘贴视频直链、B站链接 或 小红书链接...`,value:s,onChange:e=>{c(e.target.value),u(null)},onKeyDown:e=>{e.key===`Enter`&&_()}}),(0,t.jsx)(`p`,{className:`mt-1.5 text-[11px] text-default-400`,children:`支持直链 (mp4/m3u8/webm…) · B站链接 · 小红书链接 — 粘贴后自动识别`})]}),s.trim()&&(0,t.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,t.jsx)(`span`,{className:`text-xs text-default-400`,children:`识别为:`}),(0,t.jsx)(`span`,{className:`px-2 py-0.5 text-xs rounded-full font-medium ${m===`bilibili`?`bg-[#fb7299]/10 text-[#fb7299]`:m===`direct`?`bg-blue-100 text-blue-700 dark:bg-blue-900/30 dark:text-blue-400`:m===`xiaohongshu`?`bg-[#ff2442]/10 text-[#ff2442]`:`bg-default-100 text-default-500`}`,children:m===`bilibili`?`B站视频`:m===`xiaohongshu`?`小红书`:m===`direct`?`直链视频`:`未知类型`})]}),g&&s.trim()&&(0,t.jsxs)(`div`,{className:`flex items-start gap-2 px-3 py-2.5 rounded-lg bg-amber-50 dark:bg-amber-900/20 border border-amber-200 dark:border-amber-800 text-xs`,children:[(0,t.jsx)(`svg`,{className:`w-4 h-4 shrink-0 mt-px text-amber-500`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,strokeWidth:`2`,children:(0,t.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M12 9v3.75m9-.75a9 9 0 11-18 0 9 9 0 0118 0zm-9 3.75h.008v.008H12v-.008z`})}),(0,t.jsxs)(`div`,{children:[(0,t.jsxs)(`p`,{className:`font-medium text-amber-700 dark:text-amber-400`,children:[`版权提示:`,m===`bilibili`?`B站`:`小红书`,`视频将以官方播放器嵌入,版权归原作者所有。`]}),(0,t.jsx)(`p`,{className:`mt-0.5 text-amber-600 dark:text-amber-500`,children:`请确保您有权限分享该内容。支持通过官方分享链接导入。`})]})]}),m===`direct`&&h?(0,t.jsx)(`div`,{id:p,style:{width:`100%`,aspectRatio:`16/9`,borderRadius:12,overflow:`hidden`,background:`#000`}}):m===`bilibili`&&h?(0,t.jsx)(`div`,{className:`relative rounded-xl overflow-hidden bg-black aspect-video`,children:(0,t.jsx)(`iframe`,{src:`https://player.bilibili.com/player.html?bvid=${r(s.trim())}&page=1&high_quality=1&autoplay=0`,className:`w-full h-full`,allowFullScreen:!0,style:{border:`none`},sandbox:`allow-scripts allow-same-origin allow-popups allow-popups-to-escape-sandbox`,referrerPolicy:`no-referrer-when-downgrade`})}):m===`xiaohongshu`&&h?(0,t.jsxs)(`div`,{className:`flex items-center gap-3 px-4 py-6 rounded-xl border border-dashed border-default-200 bg-default-50 dark:bg-default-100/10`,children:[(0,t.jsx)(`div`,{className:`w-10 h-10 rounded-xl bg-[#ff2442]/10 flex items-center justify-center text-lg`,children:`📌`}),(0,t.jsxs)(`div`,{children:[(0,t.jsx)(`p`,{className:`text-sm font-medium`,children:`小红书笔记`}),(0,t.jsx)(`p`,{className:`text-xs text-default-400`,children:`导入后将显示为卡片样式,点击跳转至小红书查看`})]})]}):s.trim()&&!h?(0,t.jsx)(`div`,{className:`flex items-center justify-center py-10 rounded-xl border border-dashed border-default-200 text-sm text-default-400`,children:`无法识别该链接类型,请检查后重试`}):(0,t.jsxs)(`div`,{className:`flex flex-col items-center justify-center gap-3 py-10 rounded-xl border-2 border-dashed border-default-200 bg-default-50 dark:bg-default-100/10 text-default-400`,children:[(0,t.jsx)(`svg`,{className:`w-10 h-10`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,strokeWidth:1,children:(0,t.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M15.75 10.5l4.72-4.72a.75.75 0 011.28.53v11.38a.75.75 0 01-1.28.53l-4.72-4.72M4.5 18.75h9a2.25 2.25 0 002.25-2.25v-9a2.25 2.25 0 00-2.25-2.25h-9A2.25 2.25 0 002.25 7.5v9a2.25 2.25 0 002.25 2.25z`})}),(0,t.jsxs)(`div`,{className:`text-center`,children:[(0,t.jsx)(`p`,{className:`text-sm`,children:`粘贴链接后自动识别并预览`}),(0,t.jsx)(`p`,{className:`text-xs mt-1`,children:`支持直链 mp4/m3u8 · B站 · 小红书`})]})]}),l&&(0,t.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-2.5 rounded-lg bg-danger-50 dark:bg-danger-900/20 text-sm text-danger`,children:[(0,t.jsx)(`svg`,{className:`w-4 h-4 shrink-0`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,strokeWidth:2,children:(0,t.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-2.5L13.732 4c-.77-.833-2.694-.833-3.464 0L3.34 16.5c-.77.833.192 2.5 1.732 2.5z`})}),l]}),(0,t.jsxs)(`div`,{className:`flex gap-2 pt-1`,children:[(0,t.jsx)(`button`,{type:`button`,className:`flex-1 py-2.5 rounded-xl bg-primary text-white text-sm font-medium hover:opacity-90 disabled:opacity-40 transition-opacity`,disabled:!h,onClick:_,children:`导入视频`}),(0,t.jsx)(`button`,{type:`button`,className:`px-4 py-2.5 rounded-xl border border-default-200 text-sm hover:bg-default-50 dark:hover:bg-default-100/10 transition-colors`,onClick:v,children:`取消`})]})]}),(0,t.jsx)(`div`,{className:`px-5 py-2.5 border-t border-default-100 text-[11px] text-default-300 text-center`,children:`直链使用 xgplayer 播放 · B站/小红书使用官方播放器`})]})]}):null};exports.VideoEmbedDialog=i;
|