@yunlefun/vue 0.1.3 → 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.
@@ -0,0 +1,6 @@
1
+ <svg width="50.000000" height="50.000000" viewBox="0 0 50 50" fill="none" xmlns="http://www.w3.org/2000/svg"
2
+ xmlns:xlink="http://www.w3.org/1999/xlink">
3
+ <path id="path"
4
+ d="M48.8354 10.0479C48.3232 9.79199 48.1025 10.2798 47.8032 10.5278C47.7007 10.6079 47.6143 10.7119 47.5273 10.8076C46.7793 11.624 45.9048 12.1597 44.7622 12.0957C43.0923 12 41.666 12.5356 40.4058 13.8398C40.1377 12.2319 39.2476 11.272 37.8926 10.6558C37.1836 10.3359 36.4668 10.0156 35.9702 9.31982C35.6235 8.82373 35.5293 8.27197 35.356 7.72754C35.2456 7.3999 35.1353 7.06396 34.7651 7.00781C34.3633 6.94385 34.2056 7.2876 34.0479 7.57568C33.418 8.75195 33.1733 10.0479 33.1973 11.3599C33.2524 14.312 34.4736 16.6641 36.8999 18.3359C37.1758 18.5278 37.2466 18.7197 37.1597 19C36.9946 19.5757 36.7974 20.1357 36.624 20.7119C36.5137 21.0801 36.3486 21.1597 35.9624 21C34.6309 20.4321 33.481 19.5918 32.4644 18.5757C30.7393 16.8721 29.1792 14.9917 27.2334 13.52C26.7764 13.1758 26.3193 12.856 25.8467 12.5518C23.8618 10.584 26.1069 8.96777 26.627 8.77588C27.1704 8.57568 26.8159 7.8877 25.0591 7.896C23.3022 7.90381 21.6953 8.50391 19.647 9.30371C19.3477 9.42383 19.0322 9.51172 18.7095 9.58398C16.8501 9.22363 14.9199 9.14355 12.9033 9.37598C9.10596 9.80762 6.07275 11.6396 3.84326 14.7681C1.16455 18.5278 0.53418 22.7998 1.30664 27.2559C2.11768 31.9521 4.46582 35.8398 8.07373 38.8799C11.8159 42.0322 16.1255 43.5762 21.041 43.2803C24.0269 43.104 27.3516 42.6963 31.1016 39.4561C32.0469 39.936 33.0396 40.1279 34.686 40.272C35.9546 40.3921 37.1758 40.208 38.1211 40.0078C39.6021 39.688 39.4995 38.2881 38.9639 38.0322C34.623 35.9678 35.5762 36.8081 34.71 36.1279C36.9155 33.4639 40.2402 30.6958 41.54 21.728C41.6426 21.0161 41.5557 20.5679 41.54 19.9917C41.5322 19.6396 41.6108 19.5039 42.0049 19.4639C43.0923 19.3359 44.1479 19.0317 45.1167 18.4878C47.9292 16.9199 49.064 14.3438 49.3315 11.2559C49.3711 10.7837 49.3237 10.2959 48.8354 10.0479ZM24.3262 37.8398C20.1196 34.4639 18.0791 33.3521 17.2358 33.3999C16.4482 33.4482 16.5898 34.3682 16.7632 34.9678C16.9443 35.5601 17.1812 35.9683 17.5117 36.4878C17.7402 36.832 17.8979 37.3442 17.2832 37.728C15.9282 38.584 13.5728 37.4399 13.4624 37.3838C10.7207 35.7358 8.42822 33.5601 6.81348 30.584C5.25342 27.7197 4.34766 24.6479 4.19775 21.3677C4.1582 20.5757 4.38672 20.2959 5.15869 20.1519C6.17529 19.96 7.22314 19.9199 8.23926 20.0718C12.5327 20.7119 16.1885 22.6719 19.2529 25.7759C21.002 27.5439 22.3252 29.6558 23.6885 31.7202C25.1377 33.9121 26.6978 36 28.6831 37.7119C29.3843 38.312 29.9434 38.7681 30.479 39.104C28.8643 39.2881 26.1699 39.3281 24.3262 37.8398ZM26.3433 24.6001C26.3433 24.248 26.6191 23.9678 26.9658 23.9678C27.0444 23.9678 27.1152 23.9839 27.1782 24.0078C27.2651 24.04 27.3438 24.0879 27.4067 24.1602C27.5171 24.272 27.5801 24.4321 27.5801 24.6001C27.5801 24.9521 27.3042 25.2319 26.9575 25.2319C26.6108 25.2319 26.3433 24.9521 26.3433 24.6001ZM32.6064 27.8799C32.2046 28.0479 31.8027 28.1919 31.4165 28.208C30.8179 28.2397 30.1641 27.9922 29.8096 27.688C29.2583 27.2158 28.8643 26.9521 28.6987 26.1279C28.6279 25.7759 28.6675 25.2319 28.7305 24.9199C28.8721 24.248 28.7144 23.8159 28.2495 23.4238C27.8716 23.104 27.3911 23.0161 26.8633 23.0161C26.666 23.0161 26.4849 22.9277 26.3511 22.856C26.1304 22.7441 25.9492 22.4639 26.1226 22.1201C26.1777 22.0078 26.4458 21.7358 26.5088 21.688C27.2256 21.272 28.0527 21.4077 28.8169 21.7197C29.5259 22.0161 30.0615 22.5601 30.834 23.3281C31.6216 24.2559 31.7632 24.5117 32.2124 25.208C32.5669 25.752 32.8901 26.312 33.1104 26.9521C33.2446 27.3521 33.0713 27.6802 32.6064 27.8799Z"
5
+ fill="#4D6BFE" fill-opacity="1.000000" fill-rule="nonzero" />
6
+ </svg>
@@ -0,0 +1,14 @@
1
+ <script setup lang="ts">
2
+ import { shallowRef } from 'vue'
3
+ import YlfAiPromptLauncher from '../YlfAiPromptLauncher.vue'
4
+
5
+ const prompt = shallowRef('请帮我把这段话写得更清楚:今天做一个让人开心的小作品。')
6
+ </script>
7
+
8
+ <template>
9
+ <div>
10
+ <label for="ai-launcher-demo-prompt">想交给 AI 的提示词</label>
11
+ <textarea id="ai-launcher-demo-prompt" v-model="prompt" rows="3" style="display: block; width: 100%; padding: 12px; border: 1px solid var(--ylf-c-border); border-radius: 12px; font: inherit;" />
12
+ <YlfAiPromptLauncher :prompt="prompt" />
13
+ </div>
14
+ </template>
@@ -0,0 +1,116 @@
1
+ ---
2
+ title: AI Prompt Launcher
3
+ title_zh: AI 提示词入口
4
+ description: 带服务 logo 的外部 AI 入口,统一提示词链接、复制兜底与桌面适配。
5
+ ---
6
+
7
+ 把提示词带到常用 AI。业务负责生成提示词与处理回复,组件负责入口、复制、状态提示和手动复制兜底。
8
+
9
+ ## 使用
10
+
11
+ ```vue
12
+ <script setup lang="ts">
13
+ import YlfAiPromptLauncher from '@yunlefun/vue/components/YlfAiPromptLauncher.vue'
14
+ </script>
15
+
16
+ <template>
17
+ <YlfAiPromptLauncher :prompt="prompt" :disabled="!valid" />
18
+ </template>
19
+ ```
20
+
21
+ | 属性 | 说明 |
22
+ | ----------- | -------------------------------------------------------- |
23
+ | `prompt` | 必填的完整提示词;空白内容不可点击 |
24
+ | `providers` | 可选的服务 ID 列表,控制顺序和显示范围;默认六家 |
25
+ | `disabled` | 业务校验未通过时禁用 |
26
+ | `locale` | `zh-CN`(默认)或 `en` |
27
+ | `options` | `{ chatgptSearch?: boolean, maxUrlLength?: number }` |
28
+ | `launch` | 可选的宿主打开函数 `(target, prompt) => Promise<status>` |
29
+ | `copyText` | 可选的宿主剪贴板函数 `(text) => Promise<void>` |
30
+
31
+ 事件:`busy(boolean)` 便于业务锁住输入;`result({ target, status })` 返回打开或复制结果。结果描述浏览器/宿主操作,无法证明第三方最终收到、预填或发送成功。
32
+
33
+ ## 独立主题与样式覆盖
34
+
35
+ 优先在组件的业务 class 上设置 `--ylf-ai-*`,只影响这个入口;未设置时沿用 `--ylf-c-*` 主题和组件默认值。无需图标插件,logo 随包分发。
36
+
37
+ | 变量 | 用途 / 默认值 |
38
+ | ------------------------------------------------------------------------------- | ----------------------------------------------- |
39
+ | `--ylf-ai-text`、`--ylf-ai-muted` | 主文字与说明文字 |
40
+ | `--ylf-ai-border`、`--ylf-ai-surface`、`--ylf-ai-background`、`--ylf-ai-accent` | 边框、表面、卡片底色、焦点强调 |
41
+ | `--ylf-ai-columns` | 固定列数;默认随容器宽度在 3 / 2 / 1 列之间切换 |
42
+ | `--ylf-ai-gap`、`--ylf-ai-item-gap` | 卡片间距、卡片内部间距,默认 `10px` |
43
+ | `--ylf-ai-item-height`、`--ylf-ai-item-padding` | 最小高度 `76px`、内边距 `12px` |
44
+ | `--ylf-ai-radius`、`--ylf-ai-logo-size` | 圆角 `14px`、logo `40px` |
45
+ | `--ylf-ai-name-size`、`--ylf-ai-action-size` | 服务名 `14px`、操作说明 `12px` |
46
+
47
+ ```vue
48
+ <template>
49
+ <YlfAiPromptLauncher class="cms-ai-entry" :prompt="prompt" />
50
+ </template>
51
+
52
+ <style scoped>
53
+ .cms-ai-entry {
54
+ --ylf-ai-text: var(--ink);
55
+ --ylf-ai-muted: var(--muted);
56
+ --ylf-ai-border: var(--line);
57
+ --ylf-ai-surface: var(--paper);
58
+ --ylf-ai-background: var(--paper);
59
+ --ylf-ai-accent: var(--blue);
60
+ --ylf-ai-columns: 2;
61
+ --ylf-ai-radius: 8px;
62
+ --ylf-ai-logo-size: 28px;
63
+ --ylf-ai-item-padding: 8px;
64
+ }
65
+ /* 结构样式的额外定制可用 scoped :deep(),无需复制组件。 */
66
+ .cms-ai-entry :deep(.ylf-ai-launcher__actions) {
67
+ align-items: flex-start;
68
+ }
69
+ </style>
70
+ ```
71
+
72
+ 公开样式钩子:`.ylf-ai-launcher__providers`、`__provider`、`__label`、`__arrow`、`__actions`、`__status`、`__details`、`__fallback`。按服务覆盖可用 `[data-provider="cursor"]`。请保留禁用、键盘焦点和状态提示语义,不隐藏手动复制兜底。
73
+
74
+ `manual-copy(prompt)` 在用户复制完整提示词文本框时触发,CMS 可据此记录对应请求快照,保证剪贴板 API 不可用时仍能完成回填。该事件代表复制操作,不证明第三方收到了提示词。
75
+
76
+ ## 链接能力
77
+
78
+ | ID | 入口 | 行为 |
79
+ | ---------- | ----------------------------------------- | ---------------------------------------- |
80
+ | `yuanbao` | `https://yuanbao.tencent.com/` | 未确认公开预填协议;复制后打开 |
81
+ | `doubao` | `https://www.doubao.com/chat/` | 站内 `url-action` 有校验令牌;复制后打开 |
82
+ | `deepseek` | `https://chat.deepseek.com/?q=...` | 预填,不添加 `autosend` |
83
+ | `chatgpt` | `https://chatgpt.com/?q=...` | 带提示词打开,站点可能直接开始对话 |
84
+ | `claude` | `https://claude.ai/new?q=...` | 带提示词打开,可能先登录或确认 |
85
+ | `cursor` | `https://cursor.com/link/prompt?text=...` | 官方 HTTPS 中转页,再由用户打开 Cursor |
86
+
87
+ 没有统一的跨站协议,适配规则集中在 `ai-prompt.ts`。`chatgptSearch` 显式开启时才添加 `hints=search`,愿望故事和改稿默认不强制联网搜索。
88
+
89
+ 默认 URL 编码后的预算是 8,192 个字符(组件的保守策略,不是各站官方上限)。Cursor 官方上限是 10,000,组件额外为 HTTPS 中转转成 `cursor://` 预留空间。超长提示词全部复制后打开;不截断、压缩或添加自动发送参数。用户也始终可以仅复制,或展开全文手动复制。登录、网络、第三方改版可能影响带入。
90
+
91
+ 核验记录(2026-09-27):
92
+
93
+ - [Cursor 官方 Deeplinks](https://cursor.com/docs/reference/deeplinks):`text`、HTTPS 入口和 10,000 字符限制。
94
+ - [Claude 官方 Desktop 链接](https://support.claude.com/en/articles/14729294-open-claude-desktop-with-a-link):`q` 预填;该文档是桌面协议,不应当视为网页接口的稳定性保证。网页 `/new?q=` 本次保留参数进入登录流程,登录后的填入尚未验证。
95
+ - ChatGPT:按 `https://chatgpt.com/?q=...` 实测进入包含提示词的对话,行为可能直接发送,未找到公开稳定协议承诺。
96
+ - DeepSeek:当前网页实现支持 `q`,完整中文提示词在浏览器输入区实测匹配。
97
+
98
+ ## 纯函数与 CMS / Electron
99
+
100
+ ```ts
101
+ import { buildAiPromptTarget } from '@yunlefun/vue/ai-prompt'
102
+
103
+ const target = buildAiPromptTarget('cursor', articlePrompt)
104
+ // target.mode: 'link' | 'copy'
105
+ // target.reason: 'too-long' | 'unsupported' | 'empty' | undefined
106
+ ```
107
+
108
+ 模块可在 Node / SSR 使用,导入时不访问 `window` 或 `navigator`。组件不导入 Electron,也不持有 API Key。
109
+
110
+ CMS 接入时由文章工作区生成并保存 requestId / 原文快照,将完整提示词传入组件;通过 `launch` 和 `copyText` 接现有 preload API。主进程接收服务 ID、提示词及允许的选项,重新调用 `buildAiPromptTarget`,再决定写入原生剪贴板或 `shell.openExternal`。不要将任意 renderer URL 直接交给 `shell.openExternal`。
111
+
112
+ `launch` 返回 `opened`、`copied`、`copy-failed` 或 `open-failed`;`copied` 表示文本已复制但无法打开。组件可以手动复制兜底;桌面宿主应在自身 UI 中提供重试。复制、打开或用户手动复制后业务才确认本次请求快照,回复解析、差异确认、撤销和保存均留在 CMS。
113
+
114
+ ## 分发
115
+
116
+ 组件和纯函数统一通过 `@yunlefun/vue` 分发;业务只引用 npm 包并设置自己的 CSS 变量,不复制组件源码或链接规则。
@@ -0,0 +1,103 @@
1
+ /** Services supported by the shared AI prompt launcher. */
2
+ export type AiProviderId = 'yuanbao' | 'doubao' | 'deepseek' | 'chatgpt' | 'claude' | 'cursor'
3
+
4
+ export interface AiProvider {
5
+ readonly id: AiProviderId
6
+ readonly name: string
7
+ readonly url: string
8
+ readonly promptParameter?: 'q' | 'text'
9
+ }
10
+
11
+ /** Only public entry points belong here; never accept an arbitrary destination URL. */
12
+ export const aiProviders: readonly AiProvider[] = [
13
+ { id: 'yuanbao', name: '元宝', url: 'https://yuanbao.tencent.com/' },
14
+ { id: 'doubao', name: '豆包', url: 'https://www.doubao.com/chat/' },
15
+ { id: 'deepseek', name: 'DeepSeek', url: 'https://chat.deepseek.com/', promptParameter: 'q' },
16
+ { id: 'chatgpt', name: 'ChatGPT', url: 'https://chatgpt.com/', promptParameter: 'q' },
17
+ { id: 'claude', name: 'Claude', url: 'https://claude.ai/new', promptParameter: 'q' },
18
+ { id: 'cursor', name: 'Cursor', url: 'https://cursor.com/link/prompt', promptParameter: 'text' },
19
+ ]
20
+
21
+ export interface AiPromptOptions {
22
+ /** Optional ChatGPT search hint. Ordinary creative/editorial prompts leave this off. */
23
+ chatgptSearch?: boolean
24
+ /** Conservative encoded URL budget; Cursor also has a hard 10,000-character limit. */
25
+ maxUrlLength?: number
26
+ }
27
+
28
+ export interface AiPromptTarget {
29
+ provider: AiProvider
30
+ url: string
31
+ mode: 'link' | 'copy'
32
+ reason?: 'unsupported' | 'too-long' | 'empty'
33
+ }
34
+
35
+ /** Build a lossless handoff. Long prompts use the clipboard, never truncated query text. */
36
+ export function buildAiPromptTarget(id: AiProviderId, prompt: string, options: AiPromptOptions = {}): AiPromptTarget {
37
+ const provider = aiProviders.find(item => item.id === id)
38
+ if (!provider)
39
+ throw new Error(`Unknown AI provider: ${id}`)
40
+ const fallback = (reason: AiPromptTarget['reason']): AiPromptTarget => ({ provider, url: provider.url, mode: 'copy', reason })
41
+ if (!prompt.trim())
42
+ return fallback('empty')
43
+ if (!provider.promptParameter)
44
+ return fallback('unsupported')
45
+
46
+ const url = new URL(provider.url)
47
+ url.searchParams.set(provider.promptParameter, prompt)
48
+ if (id === 'chatgpt' && options.chatgptSearch)
49
+ url.searchParams.set('hints', 'search')
50
+ // Cursor's HTTPS landing page builds a slightly longer cursor:// deeplink.
51
+ const providerLimit = id === 'cursor' ? 9900 : Number.POSITIVE_INFINITY
52
+ const limit = Math.min(options.maxUrlLength ?? 8192, providerLimit)
53
+ if (!Number.isFinite(limit) || limit <= 0 || url.href.length > limit)
54
+ return fallback('too-long')
55
+ return { provider, url: url.href, mode: 'link' }
56
+ }
57
+
58
+ export type AiPromptLaunchStatus = 'opened' | 'copied' | 'copy-failed' | 'open-failed'
59
+ export interface AiPromptLaunchResult {
60
+ target: AiPromptTarget
61
+ status: AiPromptLaunchStatus
62
+ }
63
+
64
+ /** A desktop host can supply an IPC-backed launcher without exposing Electron to this package. */
65
+ export type AiPromptLaunch = (target: AiPromptTarget, prompt: string) => Promise<AiPromptLaunchStatus>
66
+
67
+ /** Browser fallback. Call synchronously from a click to retain clipboard and popup activation. */
68
+ export async function copyAndOpenAiPrompt(target: AiPromptTarget, prompt: string): Promise<AiPromptLaunchStatus> {
69
+ let copying: Promise<void>
70
+ try {
71
+ copying = navigator.clipboard.writeText(prompt)
72
+ }
73
+ catch { return 'copy-failed' }
74
+
75
+ let popup: Window | null = null
76
+ try {
77
+ popup = window.open('about:blank', '_blank')
78
+ if (popup)
79
+ popup.opener = null
80
+ }
81
+ catch {
82
+ popup?.close()
83
+ popup = null
84
+ }
85
+ try {
86
+ await copying
87
+ }
88
+ catch {
89
+ popup?.close()
90
+ return 'copy-failed'
91
+ }
92
+ if (!popup || popup.closed)
93
+ return 'copied'
94
+ try {
95
+ // This helper is only the copy fallback: never navigate to a stale prompt query.
96
+ popup.location.replace(target.provider.url)
97
+ return 'opened'
98
+ }
99
+ catch {
100
+ popup.close()
101
+ return 'copied'
102
+ }
103
+ }
@@ -0,0 +1,11 @@
1
+ import type { AiProviderId } from './ai-prompt'
2
+
3
+ /** Bundled assets: no favicon service or third-party image requests. */
4
+ export const aiProviderLogos: Record<AiProviderId, string> = {
5
+ yuanbao: new URL('./_ai-providers/yuanbao.png', import.meta.url).href,
6
+ doubao: new URL('./_ai-providers/doubao.png', import.meta.url).href,
7
+ deepseek: new URL('./_ai-providers/deepseek.svg', import.meta.url).href,
8
+ chatgpt: new URL('./_ai-providers/chatgpt.svg', import.meta.url).href,
9
+ claude: new URL('./_ai-providers/claude.svg', import.meta.url).href,
10
+ cursor: new URL('./_ai-providers/cursor.svg', import.meta.url).href,
11
+ }
@@ -0,0 +1,21 @@
1
+ <script setup lang="ts">
2
+ import { shallowRef } from 'vue'
3
+ import YlfSegmentedControl from '../YlfSegmentedControl.vue'
4
+
5
+ const view = shallowRef<'grid' | 'list'>('grid')
6
+ const kind = shallowRef('all')
7
+ const options = [{ value: 'grid', label: '网格视图' }, { value: 'list', label: '列表视图' }] as const
8
+ const icons = { grid: 'i-ri-grid-line', list: 'i-ri-list-check' }
9
+ const kinds = [{ value: 'all', label: '全部', count: 24 }, { value: 'image', label: '图片', count: 18 }, { value: 'video', label: '视频', count: 6 }]
10
+ </script>
11
+
12
+ <template>
13
+ <div class="flex flex-wrap items-center gap-4">
14
+ <YlfSegmentedControl v-model="kind" :options="kinds" label="素材类型" size="sm" />
15
+ <YlfSegmentedControl v-model="view" :options="options" label="资源视图" size="sm" icon-only>
16
+ <template #icon="{ option }">
17
+ <i :class="icons[option.value]" />
18
+ </template>
19
+ </YlfSegmentedControl>
20
+ </div>
21
+ </template>
@@ -0,0 +1,41 @@
1
+ ---
2
+ title: Segmented Control
3
+ title_zh: 分段选择器
4
+ ---
5
+
6
+ 单选视图与筛选控件,基于 [Reka UI ToggleGroup](https://reka-ui.com/docs/components/toggle-group)。保留方向键、Home / End 和禁用项处理,再次点击当前项不会清空选择。切换独立内容面板请使用 Tabs。
7
+
8
+ | 属性 | 说明 | 默认值 |
9
+ | ----------- | ----------------------------------------------------------------- | ------- |
10
+ | `v-model` | 当前选项,支持字符串联合类型 | 必填 |
11
+ | `options` | `{ value, label, disabled?, count?, ariaLabel? }[]`,支持只读数组 | 必填 |
12
+ | `label` | 组合控件的无障碍名称 | 必填 |
13
+ | `size` | `sm`:34px 工作台;`md`:44px 常规界面 | `md` |
14
+ | `icon-only` | 仅显示图标,并提供文字 Tooltip | `false` |
15
+ | `disabled` | 禁用全部选项 | `false` |
16
+
17
+ `#icon="{ option, selected }"` 插槽接收当前项及选中状态。应用通过完整的 UnoCSS / Iconify 类名映射渲染图标,公共组件不依赖应用的图标构建方式。没有图标插槽时仍显示标签。
18
+
19
+ ```vue
20
+ <script setup lang="ts">
21
+ import YlfSegmentedControl from '@yunlefun/vue/components/YlfSegmentedControl.vue'
22
+ import { shallowRef } from 'vue'
23
+
24
+ const view = shallowRef<'grid' | 'list'>('grid')
25
+ const options = [
26
+ { value: 'grid', label: '网格视图' },
27
+ { value: 'list', label: '列表视图' },
28
+ ] as const
29
+ const icons = { grid: 'i-lucide-grid-2x2', list: 'i-lucide-list' }
30
+ </script>
31
+
32
+ <template>
33
+ <YlfSegmentedControl v-model="view" :options="options" label="资源视图" size="sm" icon-only>
34
+ <template #icon="{ option }">
35
+ <i :class="icons[option.value]" />
36
+ </template>
37
+ </YlfSegmentedControl>
38
+ </template>
39
+ ```
40
+
41
+ 样式统一来自 `--ylf-*`:轻灰底座、表面色选中项、品牌色文字、细边框与焦点环。`sm` 与 `YlfSelect size="sm"` 对齐。触摸设备中选项至少 44px;减少动态效果时禁用过渡。不需要在业务页面覆盖选中态或圆角。
@@ -0,0 +1,8 @@
1
+ /** One choice in a single-selection segmented control. */
2
+ export interface YlfSegmentedOption<T extends string = string> {
3
+ value: T
4
+ label: string
5
+ disabled?: boolean
6
+ count?: number
7
+ ariaLabel?: string
8
+ }
@@ -39,3 +39,7 @@ const options = [
39
39
  ```
40
40
 
41
41
  使用 token 时,色点会随所在主题更新;页面和浮层需处于同一主题范围。
42
+
43
+ ## 工作台密度与图标
44
+
45
+ `size="sm"` 使用 34px 高度、紧凑文字与 10px 圆角,适合排序、项目范围等工具栏控件;默认 `md` 保持 44px 表单尺寸。触摸设备中紧凑选择器与选项仍至少 44px。`#icon` 和 `#indicator` 可传入应用已有的 UnoCSS / Iconify 图标;未提供时保留内置 SVG。
@@ -19,3 +19,5 @@ title_zh: 文字提示
19
19
  | --------- | ---------------------- |
20
20
  | `default` | 触发元素(`as-child`) |
21
21
  | `content` | 自定义提示内容 |
22
+
23
+ `disabled` 可关闭 Tooltip;例如分段选择器显示文字时不重复提示,仅图标模式下再启用。
@@ -0,0 +1,65 @@
1
+ 'use strict';
2
+
3
+ const aiProviders = [
4
+ { id: "yuanbao", name: "\u5143\u5B9D", url: "https://yuanbao.tencent.com/" },
5
+ { id: "doubao", name: "\u8C46\u5305", url: "https://www.doubao.com/chat/" },
6
+ { id: "deepseek", name: "DeepSeek", url: "https://chat.deepseek.com/", promptParameter: "q" },
7
+ { id: "chatgpt", name: "ChatGPT", url: "https://chatgpt.com/", promptParameter: "q" },
8
+ { id: "claude", name: "Claude", url: "https://claude.ai/new", promptParameter: "q" },
9
+ { id: "cursor", name: "Cursor", url: "https://cursor.com/link/prompt", promptParameter: "text" }
10
+ ];
11
+ function buildAiPromptTarget(id, prompt, options = {}) {
12
+ const provider = aiProviders.find((item) => item.id === id);
13
+ if (!provider)
14
+ throw new Error(`Unknown AI provider: ${id}`);
15
+ const fallback = (reason) => ({ provider, url: provider.url, mode: "copy", reason });
16
+ if (!prompt.trim())
17
+ return fallback("empty");
18
+ if (!provider.promptParameter)
19
+ return fallback("unsupported");
20
+ const url = new URL(provider.url);
21
+ url.searchParams.set(provider.promptParameter, prompt);
22
+ if (id === "chatgpt" && options.chatgptSearch)
23
+ url.searchParams.set("hints", "search");
24
+ const providerLimit = id === "cursor" ? 9900 : Number.POSITIVE_INFINITY;
25
+ const limit = Math.min(options.maxUrlLength ?? 8192, providerLimit);
26
+ if (!Number.isFinite(limit) || limit <= 0 || url.href.length > limit)
27
+ return fallback("too-long");
28
+ return { provider, url: url.href, mode: "link" };
29
+ }
30
+ async function copyAndOpenAiPrompt(target, prompt) {
31
+ let copying;
32
+ try {
33
+ copying = navigator.clipboard.writeText(prompt);
34
+ } catch {
35
+ return "copy-failed";
36
+ }
37
+ let popup = null;
38
+ try {
39
+ popup = window.open("about:blank", "_blank");
40
+ if (popup)
41
+ popup.opener = null;
42
+ } catch {
43
+ popup?.close();
44
+ popup = null;
45
+ }
46
+ try {
47
+ await copying;
48
+ } catch {
49
+ popup?.close();
50
+ return "copy-failed";
51
+ }
52
+ if (!popup || popup.closed)
53
+ return "copied";
54
+ try {
55
+ popup.location.replace(target.provider.url);
56
+ return "opened";
57
+ } catch {
58
+ popup.close();
59
+ return "copied";
60
+ }
61
+ }
62
+
63
+ exports.aiProviders = aiProviders;
64
+ exports.buildAiPromptTarget = buildAiPromptTarget;
65
+ exports.copyAndOpenAiPrompt = copyAndOpenAiPrompt;
@@ -0,0 +1,36 @@
1
+ /** Services supported by the shared AI prompt launcher. */
2
+ type AiProviderId = 'yuanbao' | 'doubao' | 'deepseek' | 'chatgpt' | 'claude' | 'cursor';
3
+ interface AiProvider {
4
+ readonly id: AiProviderId;
5
+ readonly name: string;
6
+ readonly url: string;
7
+ readonly promptParameter?: 'q' | 'text';
8
+ }
9
+ /** Only public entry points belong here; never accept an arbitrary destination URL. */
10
+ declare const aiProviders: readonly AiProvider[];
11
+ interface AiPromptOptions {
12
+ /** Optional ChatGPT search hint. Ordinary creative/editorial prompts leave this off. */
13
+ chatgptSearch?: boolean;
14
+ /** Conservative encoded URL budget; Cursor also has a hard 10,000-character limit. */
15
+ maxUrlLength?: number;
16
+ }
17
+ interface AiPromptTarget {
18
+ provider: AiProvider;
19
+ url: string;
20
+ mode: 'link' | 'copy';
21
+ reason?: 'unsupported' | 'too-long' | 'empty';
22
+ }
23
+ /** Build a lossless handoff. Long prompts use the clipboard, never truncated query text. */
24
+ declare function buildAiPromptTarget(id: AiProviderId, prompt: string, options?: AiPromptOptions): AiPromptTarget;
25
+ type AiPromptLaunchStatus = 'opened' | 'copied' | 'copy-failed' | 'open-failed';
26
+ interface AiPromptLaunchResult {
27
+ target: AiPromptTarget;
28
+ status: AiPromptLaunchStatus;
29
+ }
30
+ /** A desktop host can supply an IPC-backed launcher without exposing Electron to this package. */
31
+ type AiPromptLaunch = (target: AiPromptTarget, prompt: string) => Promise<AiPromptLaunchStatus>;
32
+ /** Browser fallback. Call synchronously from a click to retain clipboard and popup activation. */
33
+ declare function copyAndOpenAiPrompt(target: AiPromptTarget, prompt: string): Promise<AiPromptLaunchStatus>;
34
+
35
+ export { aiProviders, buildAiPromptTarget, copyAndOpenAiPrompt };
36
+ export type { AiPromptLaunch, AiPromptLaunchResult, AiPromptLaunchStatus, AiPromptOptions, AiPromptTarget, AiProvider, AiProviderId };
@@ -0,0 +1,36 @@
1
+ /** Services supported by the shared AI prompt launcher. */
2
+ type AiProviderId = 'yuanbao' | 'doubao' | 'deepseek' | 'chatgpt' | 'claude' | 'cursor';
3
+ interface AiProvider {
4
+ readonly id: AiProviderId;
5
+ readonly name: string;
6
+ readonly url: string;
7
+ readonly promptParameter?: 'q' | 'text';
8
+ }
9
+ /** Only public entry points belong here; never accept an arbitrary destination URL. */
10
+ declare const aiProviders: readonly AiProvider[];
11
+ interface AiPromptOptions {
12
+ /** Optional ChatGPT search hint. Ordinary creative/editorial prompts leave this off. */
13
+ chatgptSearch?: boolean;
14
+ /** Conservative encoded URL budget; Cursor also has a hard 10,000-character limit. */
15
+ maxUrlLength?: number;
16
+ }
17
+ interface AiPromptTarget {
18
+ provider: AiProvider;
19
+ url: string;
20
+ mode: 'link' | 'copy';
21
+ reason?: 'unsupported' | 'too-long' | 'empty';
22
+ }
23
+ /** Build a lossless handoff. Long prompts use the clipboard, never truncated query text. */
24
+ declare function buildAiPromptTarget(id: AiProviderId, prompt: string, options?: AiPromptOptions): AiPromptTarget;
25
+ type AiPromptLaunchStatus = 'opened' | 'copied' | 'copy-failed' | 'open-failed';
26
+ interface AiPromptLaunchResult {
27
+ target: AiPromptTarget;
28
+ status: AiPromptLaunchStatus;
29
+ }
30
+ /** A desktop host can supply an IPC-backed launcher without exposing Electron to this package. */
31
+ type AiPromptLaunch = (target: AiPromptTarget, prompt: string) => Promise<AiPromptLaunchStatus>;
32
+ /** Browser fallback. Call synchronously from a click to retain clipboard and popup activation. */
33
+ declare function copyAndOpenAiPrompt(target: AiPromptTarget, prompt: string): Promise<AiPromptLaunchStatus>;
34
+
35
+ export { aiProviders, buildAiPromptTarget, copyAndOpenAiPrompt };
36
+ export type { AiPromptLaunch, AiPromptLaunchResult, AiPromptLaunchStatus, AiPromptOptions, AiPromptTarget, AiProvider, AiProviderId };
@@ -0,0 +1,36 @@
1
+ /** Services supported by the shared AI prompt launcher. */
2
+ type AiProviderId = 'yuanbao' | 'doubao' | 'deepseek' | 'chatgpt' | 'claude' | 'cursor';
3
+ interface AiProvider {
4
+ readonly id: AiProviderId;
5
+ readonly name: string;
6
+ readonly url: string;
7
+ readonly promptParameter?: 'q' | 'text';
8
+ }
9
+ /** Only public entry points belong here; never accept an arbitrary destination URL. */
10
+ declare const aiProviders: readonly AiProvider[];
11
+ interface AiPromptOptions {
12
+ /** Optional ChatGPT search hint. Ordinary creative/editorial prompts leave this off. */
13
+ chatgptSearch?: boolean;
14
+ /** Conservative encoded URL budget; Cursor also has a hard 10,000-character limit. */
15
+ maxUrlLength?: number;
16
+ }
17
+ interface AiPromptTarget {
18
+ provider: AiProvider;
19
+ url: string;
20
+ mode: 'link' | 'copy';
21
+ reason?: 'unsupported' | 'too-long' | 'empty';
22
+ }
23
+ /** Build a lossless handoff. Long prompts use the clipboard, never truncated query text. */
24
+ declare function buildAiPromptTarget(id: AiProviderId, prompt: string, options?: AiPromptOptions): AiPromptTarget;
25
+ type AiPromptLaunchStatus = 'opened' | 'copied' | 'copy-failed' | 'open-failed';
26
+ interface AiPromptLaunchResult {
27
+ target: AiPromptTarget;
28
+ status: AiPromptLaunchStatus;
29
+ }
30
+ /** A desktop host can supply an IPC-backed launcher without exposing Electron to this package. */
31
+ type AiPromptLaunch = (target: AiPromptTarget, prompt: string) => Promise<AiPromptLaunchStatus>;
32
+ /** Browser fallback. Call synchronously from a click to retain clipboard and popup activation. */
33
+ declare function copyAndOpenAiPrompt(target: AiPromptTarget, prompt: string): Promise<AiPromptLaunchStatus>;
34
+
35
+ export { aiProviders, buildAiPromptTarget, copyAndOpenAiPrompt };
36
+ export type { AiPromptLaunch, AiPromptLaunchResult, AiPromptLaunchStatus, AiPromptOptions, AiPromptTarget, AiProvider, AiProviderId };
@@ -0,0 +1,61 @@
1
+ const aiProviders = [
2
+ { id: "yuanbao", name: "\u5143\u5B9D", url: "https://yuanbao.tencent.com/" },
3
+ { id: "doubao", name: "\u8C46\u5305", url: "https://www.doubao.com/chat/" },
4
+ { id: "deepseek", name: "DeepSeek", url: "https://chat.deepseek.com/", promptParameter: "q" },
5
+ { id: "chatgpt", name: "ChatGPT", url: "https://chatgpt.com/", promptParameter: "q" },
6
+ { id: "claude", name: "Claude", url: "https://claude.ai/new", promptParameter: "q" },
7
+ { id: "cursor", name: "Cursor", url: "https://cursor.com/link/prompt", promptParameter: "text" }
8
+ ];
9
+ function buildAiPromptTarget(id, prompt, options = {}) {
10
+ const provider = aiProviders.find((item) => item.id === id);
11
+ if (!provider)
12
+ throw new Error(`Unknown AI provider: ${id}`);
13
+ const fallback = (reason) => ({ provider, url: provider.url, mode: "copy", reason });
14
+ if (!prompt.trim())
15
+ return fallback("empty");
16
+ if (!provider.promptParameter)
17
+ return fallback("unsupported");
18
+ const url = new URL(provider.url);
19
+ url.searchParams.set(provider.promptParameter, prompt);
20
+ if (id === "chatgpt" && options.chatgptSearch)
21
+ url.searchParams.set("hints", "search");
22
+ const providerLimit = id === "cursor" ? 9900 : Number.POSITIVE_INFINITY;
23
+ const limit = Math.min(options.maxUrlLength ?? 8192, providerLimit);
24
+ if (!Number.isFinite(limit) || limit <= 0 || url.href.length > limit)
25
+ return fallback("too-long");
26
+ return { provider, url: url.href, mode: "link" };
27
+ }
28
+ async function copyAndOpenAiPrompt(target, prompt) {
29
+ let copying;
30
+ try {
31
+ copying = navigator.clipboard.writeText(prompt);
32
+ } catch {
33
+ return "copy-failed";
34
+ }
35
+ let popup = null;
36
+ try {
37
+ popup = window.open("about:blank", "_blank");
38
+ if (popup)
39
+ popup.opener = null;
40
+ } catch {
41
+ popup?.close();
42
+ popup = null;
43
+ }
44
+ try {
45
+ await copying;
46
+ } catch {
47
+ popup?.close();
48
+ return "copy-failed";
49
+ }
50
+ if (!popup || popup.closed)
51
+ return "copied";
52
+ try {
53
+ popup.location.replace(target.provider.url);
54
+ return "opened";
55
+ } catch {
56
+ popup.close();
57
+ return "copied";
58
+ }
59
+ }
60
+
61
+ export { aiProviders, buildAiPromptTarget, copyAndOpenAiPrompt };
package/dist/index.d.cts CHANGED
@@ -19,6 +19,15 @@ interface BottomMenuItem {
19
19
  onClick?: (...args: any[]) => void;
20
20
  }
21
21
 
22
+ /** One choice in a single-selection segmented control. */
23
+ interface YlfSegmentedOption<T extends string = string> {
24
+ value: T;
25
+ label: string;
26
+ disabled?: boolean;
27
+ count?: number;
28
+ ariaLabel?: string;
29
+ }
30
+
22
31
  /** Shared accents, defaulting to sky blue. Status colors use their own semantic variants. */
23
32
  type YlfAccentTone = 'blue' | 'sun' | 'cyan' | 'coral' | 'pink' | 'green';
24
33
  /** Visual emphasis for accent and status buttons/badges. */
@@ -28,4 +37,4 @@ declare const _dirname: string;
28
37
  declare const componentsDir: string;
29
38
 
30
39
  export { _dirname, componentsDir };
31
- export type { BottomMenuItem, YlfAccentTone, YlfColorAppearance };
40
+ export type { BottomMenuItem, YlfAccentTone, YlfColorAppearance, YlfSegmentedOption };
package/dist/index.d.mts CHANGED
@@ -19,6 +19,15 @@ interface BottomMenuItem {
19
19
  onClick?: (...args: any[]) => void;
20
20
  }
21
21
 
22
+ /** One choice in a single-selection segmented control. */
23
+ interface YlfSegmentedOption<T extends string = string> {
24
+ value: T;
25
+ label: string;
26
+ disabled?: boolean;
27
+ count?: number;
28
+ ariaLabel?: string;
29
+ }
30
+
22
31
  /** Shared accents, defaulting to sky blue. Status colors use their own semantic variants. */
23
32
  type YlfAccentTone = 'blue' | 'sun' | 'cyan' | 'coral' | 'pink' | 'green';
24
33
  /** Visual emphasis for accent and status buttons/badges. */
@@ -28,4 +37,4 @@ declare const _dirname: string;
28
37
  declare const componentsDir: string;
29
38
 
30
39
  export { _dirname, componentsDir };
31
- export type { BottomMenuItem, YlfAccentTone, YlfColorAppearance };
40
+ export type { BottomMenuItem, YlfAccentTone, YlfColorAppearance, YlfSegmentedOption };