@onerjs/code-input 0.0.0-stage → 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/README.md +289 -2
- package/dist/code-input.cjs +20 -0
- package/dist/code-input.es.js +1222 -0
- package/dist/components/CodeEditor.vue.d.ts +61 -0
- package/dist/core/builtins.d.ts +2 -0
- package/dist/core/completion.d.ts +12 -0
- package/dist/core/hover.d.ts +6 -0
- package/dist/core/keywords.d.ts +3 -0
- package/dist/core/parser.d.ts +2 -0
- package/dist/core/template.d.ts +6 -0
- package/dist/core/tokenizer.d.ts +13 -0
- package/dist/core/types.d.ts +22 -0
- package/dist/index.d.ts +12 -0
- package/dist/style.css +1 -0
- package/package.json +49 -5
package/README.md
CHANGED
|
@@ -1,3 +1,290 @@
|
|
|
1
|
-
#
|
|
1
|
+
# 轻量代码输入框 CodeEditor
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
一个基于 Vue 3 + Vite 的轻量代码输入框组件,用于在业务表单中提供 JavaScript / TypeScript 的代码编辑与提示能力。
|
|
4
|
+
|
|
5
|
+
不使用 CodeMirror / Monaco 等重型编辑器,全部逻辑自研,体积小、可定制。
|
|
6
|
+
|
|
7
|
+
## 特性
|
|
8
|
+
|
|
9
|
+
- **轻量自研补全**:内置 JS / TS 关键字、全局对象,支持自定义变量 / 方法的成员提示(`obj.`)
|
|
10
|
+
- **类型提示**:`detail`(类型签名)与 `type`(完整类型定义,TS 语法高亮)
|
|
11
|
+
- **悬停定义**:鼠标悬停在变量 / 成员上显示含义与类型定义
|
|
12
|
+
- **模板模式**:仅在 `{{ }}`(可自定义定界符)区间内触发代码补全
|
|
13
|
+
- **语法高亮**:关键字 / 字符串 / 数字 / 注释 / 内置对象着色
|
|
14
|
+
- **暗色主题**:亮色 / 暗色一键切换
|
|
15
|
+
- **折叠展开**:默认单行输入,点击展开为多行编辑器
|
|
16
|
+
- **智能滚动**:光标移动 / 换行自动滚动到可视区,单行模式整行吸附
|
|
17
|
+
- **编辑增强**:括号自动闭合、回车自动缩进
|
|
18
|
+
|
|
19
|
+
## 安装
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
npm install @onerjs/code-input
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
作为插件全局注册(组件名为 `CodeInput`):
|
|
26
|
+
|
|
27
|
+
```ts
|
|
28
|
+
import { createApp } from 'vue'
|
|
29
|
+
import CodeInput from '@onerjs/code-input'
|
|
30
|
+
import '@onerjs/code-input/style.css'
|
|
31
|
+
|
|
32
|
+
createApp(App).use(CodeInput).mount('#app')
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
或按需引入组件:
|
|
36
|
+
|
|
37
|
+
```vue
|
|
38
|
+
<script setup lang="ts">
|
|
39
|
+
import { CodeEditor } from '@onerjs/code-input'
|
|
40
|
+
import type { CompletionItem } from '@onerjs/code-input'
|
|
41
|
+
import '@onerjs/code-input/style.css'
|
|
42
|
+
</script>
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
也可以只使用核心能力(不渲染组件):
|
|
46
|
+
|
|
47
|
+
```ts
|
|
48
|
+
import { parseTsCompletions, defaultCompletions } from '@onerjs/code-input'
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
> 需要 Vue 3.5+(作为 `peerDependency`,由宿主项目提供)。
|
|
52
|
+
|
|
53
|
+
## 本地开发
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
npm install
|
|
57
|
+
npm run dev # 启动演示页
|
|
58
|
+
npm run build # 类型检查 + 构建库产物到 dist/
|
|
59
|
+
npm run preview # 预览构建产物
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## 构建与发布
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
npm run build
|
|
66
|
+
npm publish
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
产物说明:
|
|
70
|
+
|
|
71
|
+
- `dist/code-input.es.js` / `dist/code-input.cjs`:ESM / CJS 两种模块格式(`vue` 已 external)
|
|
72
|
+
- `dist/style.css`:样式文件,需使用方手动引入
|
|
73
|
+
- `dist/index.d.ts`:类型声明入口
|
|
74
|
+
|
|
75
|
+
## 基础用法
|
|
76
|
+
|
|
77
|
+
```vue
|
|
78
|
+
<script setup lang="ts">
|
|
79
|
+
import { ref } from 'vue'
|
|
80
|
+
import CodeEditor from './components/CodeEditor.vue'
|
|
81
|
+
import type { CompletionItem } from './core/types'
|
|
82
|
+
|
|
83
|
+
const code = ref('const user = $user\n')
|
|
84
|
+
|
|
85
|
+
const completions: CompletionItem[] = [
|
|
86
|
+
{
|
|
87
|
+
label: '$user',
|
|
88
|
+
kind: 'variable',
|
|
89
|
+
detail: 'User',
|
|
90
|
+
type: `interface User {
|
|
91
|
+
id: number
|
|
92
|
+
name: string
|
|
93
|
+
}`,
|
|
94
|
+
documentation: '当前登录用户',
|
|
95
|
+
members: [
|
|
96
|
+
{ label: 'id', kind: 'property', detail: 'number' },
|
|
97
|
+
{ label: 'name', kind: 'property', detail: 'string' }
|
|
98
|
+
]
|
|
99
|
+
}
|
|
100
|
+
]
|
|
101
|
+
</script>
|
|
102
|
+
|
|
103
|
+
<template>
|
|
104
|
+
<CodeEditor v-model="code" language="typescript" :completions="completions" />
|
|
105
|
+
</template>
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
## Props
|
|
109
|
+
|
|
110
|
+
| 名称 | 类型 | 默认值 | 说明 |
|
|
111
|
+
| --- | --- | --- | --- |
|
|
112
|
+
| `modelValue` | `string` | — | 输入内容(`v-model`) |
|
|
113
|
+
| `mode` | `'code' \| 'template'` | `'code'` | 补全模式,`template` 仅在定界符区间内触发 |
|
|
114
|
+
| `language` | `'javascript' \| 'typescript'` | `'javascript'` | 语言,影响关键字集合 |
|
|
115
|
+
| `completions` | `CompletionItem[]` | `[]` | 自定义补全项(内置项会自动合并) |
|
|
116
|
+
| `tsTypes` | `string` | `''` | TS 类型声明代码,自动解析为补全项(见下文) |
|
|
117
|
+
| `templateCompletions` | `CompletionItem[]` | `[]` | 模板模式专属补全项,展示优先级最高 |
|
|
118
|
+
| `templateOpen` | `string` | `'{{'` | 模板区间起始定界符 |
|
|
119
|
+
| `templateClose` | `string` | `'}}'` | 模板区间结束定界符 |
|
|
120
|
+
| `placeholder` | `string` | `''` | 占位文本 |
|
|
121
|
+
| `readonly` | `boolean` | `false` | 只读 |
|
|
122
|
+
| `lineNumbers` | `boolean` | `true` | 是否显示行号 |
|
|
123
|
+
| `hover` | `boolean` | `true` | 是否启用悬停显示定义 |
|
|
124
|
+
| `theme` | `'light' \| 'dark'` | `'light'` | 主题 |
|
|
125
|
+
| `collapsible` | `boolean` | `false` | 是否启用折叠 / 展开 |
|
|
126
|
+
| `defaultExpanded` | `boolean` | `false` | 折叠模式下是否默认展开 |
|
|
127
|
+
| `collapsedHeight` | `string` | `'34px'` | 单行模式高度(同时也是行高) |
|
|
128
|
+
| `collapseOnBlur` | `boolean` | `false` | 展开状态下失焦后是否自动收起 |
|
|
129
|
+
| `minHeight` | `string` | `'260px'` | 展开模式高度 |
|
|
130
|
+
|
|
131
|
+
## Events
|
|
132
|
+
|
|
133
|
+
| 事件 | 参数 | 说明 |
|
|
134
|
+
| --- | --- | --- |
|
|
135
|
+
| `update:modelValue` | `(value: string)` | 内容变化 |
|
|
136
|
+
| `change` | `(value: string)` | 内容变化(同 `update:modelValue`,便于监听) |
|
|
137
|
+
| `expand` | — | 展开为多行编辑器 |
|
|
138
|
+
| `collapse` | — | 收起为单行输入框 |
|
|
139
|
+
|
|
140
|
+
## 方法
|
|
141
|
+
|
|
142
|
+
通过 `ref` 调用:
|
|
143
|
+
|
|
144
|
+
```vue
|
|
145
|
+
<CodeEditor ref="editorRef" v-model="code" />
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
| 方法 | 说明 |
|
|
149
|
+
| --- | --- |
|
|
150
|
+
| `focus()` | 聚焦输入框 |
|
|
151
|
+
|
|
152
|
+
## 补全数据格式 CompletionItem
|
|
153
|
+
|
|
154
|
+
```ts
|
|
155
|
+
interface CompletionItem {
|
|
156
|
+
label: string // 展示名称,同时作为匹配与插入文本
|
|
157
|
+
kind: CompletionKind // 'variable' | 'function' | 'property' | 'class' | 'keyword'
|
|
158
|
+
detail?: string // 类型签名 / 类型名,如 '(url: string) => Promise<any>'
|
|
159
|
+
type?: string // 完整类型定义,支持多行,hover 时以 TS 语法高亮展示
|
|
160
|
+
documentation?: string // 含义说明
|
|
161
|
+
insertText?: string // 插入文本(缺省使用 label)
|
|
162
|
+
members?: CompletionItem[] // 成员列表,用于 `obj.` 提示
|
|
163
|
+
}
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
补全弹窗与悬停卡片中的类型徽标:`变量 / 函数 / 属性 / 对象 / 关键字`。
|
|
167
|
+
|
|
168
|
+
## 从 TS 类型代码生成补全
|
|
169
|
+
|
|
170
|
+
除了手写 `CompletionItem`,也可以直接传入一段 TS 声明代码,组件会用内置解析器(`src/core/parser.ts`)自动生成变量、函数与成员提示。
|
|
171
|
+
|
|
172
|
+
```vue
|
|
173
|
+
<script setup lang="ts">
|
|
174
|
+
const tsTypes = `
|
|
175
|
+
interface AppConfig {
|
|
176
|
+
apiBase: string
|
|
177
|
+
timeout: number
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
interface User {
|
|
181
|
+
id: number
|
|
182
|
+
name: string
|
|
183
|
+
roles: string[]
|
|
184
|
+
hasRole(role: string): boolean
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
interface Store {
|
|
188
|
+
count: number
|
|
189
|
+
user: User
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
declare const $config: AppConfig
|
|
193
|
+
declare const $store: Store
|
|
194
|
+
declare function $notify(message: string, type?: 'success' | 'error'): void
|
|
195
|
+
`
|
|
196
|
+
</script>
|
|
197
|
+
|
|
198
|
+
<template>
|
|
199
|
+
<CodeEditor v-model="code" language="typescript" :ts-types="tsTypes" />
|
|
200
|
+
</template>
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
支持的声明形式:
|
|
204
|
+
|
|
205
|
+
- `interface X { ... }`、`class X { ... }`、`type X = ...`
|
|
206
|
+
- `declare const / let / var x: Type`(`export` 可选)
|
|
207
|
+
- `declare function f(a: T): R`
|
|
208
|
+
|
|
209
|
+
解析规则:
|
|
210
|
+
|
|
211
|
+
- 成员区分属性 / 方法,方法生成 `(params) => ret` 签名;可选属性 `?` 会读取类型
|
|
212
|
+
- 变量的类型若指向已定义的 `interface / class / type`,会自动关联其类型定义与成员
|
|
213
|
+
- 成员类型再次指向某个对象类型时会递归展开,因此 `$store.user.` 也能提示 `User` 的成员
|
|
214
|
+
- 也可单独调用:`import { parseTsCompletions } from './core/parser'`
|
|
215
|
+
|
|
216
|
+
## 模板模式
|
|
217
|
+
|
|
218
|
+
模板模式下只有光标位于未闭合的 `{{ ... }}` 内才会触发代码补全,区间外输入不弹窗。
|
|
219
|
+
|
|
220
|
+
```vue
|
|
221
|
+
<CodeEditor
|
|
222
|
+
v-model="template"
|
|
223
|
+
mode="template"
|
|
224
|
+
:template-completions="templateVars"
|
|
225
|
+
template-open="{{"
|
|
226
|
+
template-close="}}"
|
|
227
|
+
/>
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
定界符可自定义,例如改为 `${ }`:
|
|
231
|
+
|
|
232
|
+
```vue
|
|
233
|
+
<CodeEditor mode="template" template-open="${" template-close="}" />
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
## 折叠模式
|
|
237
|
+
|
|
238
|
+
```vue
|
|
239
|
+
<CodeEditor v-model="code" collapsible collapsed-height="40px" min-height="300px" />
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
- 默认单行显示,行高等于输入框高度,文字垂直居中
|
|
243
|
+
- 点击右侧按钮展开为多行编辑器(含行号)
|
|
244
|
+
- 单行模式下滚轮滚动按整行吸附
|
|
245
|
+
- 设置 `collapse-on-blur` 后:展开时若编辑器没有焦点会自动聚焦,失焦时自动收起(点击展开 / 收起按钮本身不会误触发)
|
|
246
|
+
|
|
247
|
+
## 主题
|
|
248
|
+
|
|
249
|
+
```vue
|
|
250
|
+
<CodeEditor v-model="code" theme="dark" />
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
## 键盘交互
|
|
254
|
+
|
|
255
|
+
| 按键 | 行为 |
|
|
256
|
+
| --- | --- |
|
|
257
|
+
| `Ctrl / ⌘ + Space` | 手动触发补全 |
|
|
258
|
+
| `↑` / `↓` | 补全列表上下选择 |
|
|
259
|
+
| `Enter` / `Tab` | 确认补全项 |
|
|
260
|
+
| `Esc` | 关闭补全 |
|
|
261
|
+
| `Enter` | 换行并自动缩进(补全未打开时) |
|
|
262
|
+
| `(` `[` `{` `"` `'` | 自动闭合 |
|
|
263
|
+
|
|
264
|
+
光标移动(点击、方向键、Home / End)到 `obj.` 之后会自动弹出成员提示。
|
|
265
|
+
|
|
266
|
+
## 目录结构
|
|
267
|
+
|
|
268
|
+
```
|
|
269
|
+
src/
|
|
270
|
+
├─ components/
|
|
271
|
+
│ └─ CodeEditor.vue # 组件本体(模板 / 交互 / 样式)
|
|
272
|
+
├─ core/
|
|
273
|
+
│ ├─ types.ts # 类型定义
|
|
274
|
+
│ ├─ builtins.ts # 内置补全(Math / JSON / console 等)
|
|
275
|
+
│ ├─ keywords.ts # JS / TS 关键字
|
|
276
|
+
│ ├─ completion.ts # 补全上下文解析、成员链、模糊匹配
|
|
277
|
+
│ ├─ hover.ts # 悬停定义解析
|
|
278
|
+
│ ├─ template.ts # 模板区间识别
|
|
279
|
+
│ └─ tokenizer.ts # 词法分析与高亮
|
|
280
|
+
├─ App.vue # 演示页
|
|
281
|
+
└─ main.ts
|
|
282
|
+
```
|
|
283
|
+
|
|
284
|
+
## 实现原理
|
|
285
|
+
|
|
286
|
+
- **渲染**:`textarea`(文字透明)叠加一层高亮 `<pre>`,两者共享字体、行高与尺寸;滚动时用 `transform` 平移高亮层,保证逐像素对齐
|
|
287
|
+
- **高亮层同时作为命中层**:每个 token 的 `<span>` 携带 `data-start` / `data-end`,鼠标坐标换算为内容坐标后比对字符矩形,用于悬停查定义
|
|
288
|
+
- **补全**:解析光标前的标识符链与前缀,从根级集合或对象成员中取出候选,做前缀 / 子序列模糊打分排序
|
|
289
|
+
- **单行模式**:行高等于输入框高度、上下 padding 归零,配合整行吸附实现单行窗口滚动
|
|
290
|
+
- **模板模式**:定位光标所在的 `{{ }}` 区间,仅在该区间内启用代码补全与高亮
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const t=require("vue"),Me=[{label:"Math",kind:"class",detail:"Math",type:`interface Math {
|
|
2
|
+
readonly PI: number
|
|
3
|
+
readonly E: number
|
|
4
|
+
abs(x: number): number
|
|
5
|
+
round(x: number): number
|
|
6
|
+
max(...values: number[]): number
|
|
7
|
+
random(): number
|
|
8
|
+
}`,documentation:"内置数学对象",members:[{label:"PI",kind:"property",detail:"number"},{label:"E",kind:"property",detail:"number"},{label:"abs",kind:"function",detail:"(x: number) => number"},{label:"ceil",kind:"function",detail:"(x: number) => number"},{label:"floor",kind:"function",detail:"(x: number) => number"},{label:"round",kind:"function",detail:"(x: number) => number"},{label:"max",kind:"function",detail:"(...values: number[]) => number"},{label:"min",kind:"function",detail:"(...values: number[]) => number"},{label:"pow",kind:"function",detail:"(base: number, exp: number) => number"},{label:"random",kind:"function",detail:"() => number"},{label:"sqrt",kind:"function",detail:"(x: number) => number"},{label:"trunc",kind:"function",detail:"(x: number) => number"}]},{label:"JSON",kind:"class",detail:"JSON",members:[{label:"parse",kind:"function",detail:"(text: string) => any"},{label:"stringify",kind:"function",detail:"(value: any, space?: number) => string"}]},{label:"console",kind:"variable",detail:"Console",members:[{label:"log",kind:"function",detail:"(...data: any[]) => void"},{label:"info",kind:"function",detail:"(...data: any[]) => void"},{label:"warn",kind:"function",detail:"(...data: any[]) => void"},{label:"error",kind:"function",detail:"(...data: any[]) => void"},{label:"debug",kind:"function",detail:"(...data: any[]) => void"},{label:"table",kind:"function",detail:"(data: any) => void"},{label:"time",kind:"function",detail:"(label: string) => void"},{label:"timeEnd",kind:"function",detail:"(label: string) => void"}]},{label:"Object",kind:"class",detail:"Object",members:[{label:"keys",kind:"function",detail:"(o: object) => string[]"},{label:"values",kind:"function",detail:"(o: object) => any[]"},{label:"entries",kind:"function",detail:"(o: object) => [string, any][]"},{label:"assign",kind:"function",detail:"(target: object, ...sources: object[]) => object"},{label:"freeze",kind:"function",detail:"(o: object) => object"}]},{label:"Array",kind:"class",detail:"Array",members:[{label:"isArray",kind:"function",detail:"(value: any) => boolean"},{label:"from",kind:"function",detail:"(iterable: any) => any[]"},{label:"of",kind:"function",detail:"(...items: any[]) => any[]"}]},{label:"Promise",kind:"class",detail:"Promise",members:[{label:"resolve",kind:"function",detail:"(value?: any) => Promise<any>"},{label:"reject",kind:"function",detail:"(reason?: any) => Promise<never>"},{label:"all",kind:"function",detail:"(values: any[]) => Promise<any[]>"},{label:"race",kind:"function",detail:"(values: any[]) => Promise<any>"}]},{label:"Date",kind:"class",detail:"Date",members:[{label:"now",kind:"function",detail:"() => number"},{label:"parse",kind:"function",detail:"(dateString: string) => number"}]},{label:"String",kind:"class",detail:"String",members:[{label:"fromCharCode",kind:"function",detail:"(...codes: number[]) => string"},{label:"from",kind:"function",detail:"(value: any) => string"}]},{label:"Number",kind:"class",detail:"Number",members:[{label:"isNaN",kind:"function",detail:"(value: any) => boolean"},{label:"isInteger",kind:"function",detail:"(value: any) => boolean"},{label:"parseFloat",kind:"function",detail:"(value: string) => number"},{label:"parseInt",kind:"function",detail:"(value: string, radix?: number) => number"}]},{label:"setTimeout",kind:"function",detail:"(callback: Function, ms?: number) => number"},{label:"clearTimeout",kind:"function",detail:"(id: number) => void"},{label:"setInterval",kind:"function",detail:"(callback: Function, ms?: number) => number"},{label:"clearInterval",kind:"function",detail:"(id: number) => void"}],Te=["break","case","catch","class","const","continue","debugger","default","delete","do","else","export","extends","finally","for","from","function","if","import","in","instanceof","let","new","of","return","super","switch","this","throw","try","typeof","var","void","while","with","yield","async","await","true","false","null","undefined","NaN","Infinity"],st=["abstract","any","as","asserts","bigint","boolean","declare","enum","implements","infer","interface","is","keyof","namespace","never","number","object","override","private","protected","public","readonly","satisfies","static","string","symbol","type","unknown"];function re(a){return a==="typescript"?[...Te,...st]:Te}function ae(a){return new Set(re(a))}const ct=/((?:[A-Za-z_$][\w$]*\??\.)*)([A-Za-z_$][\w$]*)?$/,Ce=/\b(?:const|let|var|function|class)\s+([A-Za-z_$][\w$]*)/g,ut=/^[A-Za-z_$]/;function dt(a,c){const i=a.slice(0,c),l=ct.exec(i);if(!l)return{prefix:"",chain:[]};const o=l[1]??"",u=l[2]??"",d=o.split(".").filter(Boolean).map(f=>f.replace(/\?$/,""));return{prefix:u,chain:d}}function ie(a,c){const i=[],l=new Set;let o;for(Ce.lastIndex=0;(o=Ce.exec(a))&&!(o.index>=c);){const u=o[1];if(l.has(u))continue;l.add(u);const d=o[0].slice(0,o[0].indexOf(u)).trim();i.push({label:u,kind:d==="function"?"function":d==="class"?"class":"variable",detail:"当前文件"})}return i}function Ne(a,c){let i=c;for(const l of a){if(!i)return null;const o=i.find(u=>u.label===l);if(!o)return null;i=o.members??[]}return i}function ft(a,c){const i=a.toLowerCase(),l=c.toLowerCase(),o=i.indexOf(l);if(o===0)return 1e3-i.length;if(o>0)return 800-o;let u=0,d=0,f=-1;for(let r=0;r<i.length&&u<l.length;r++)i[r]===l[u]&&(f>=0&&(d+=r-f-1),f=r,u++);return u!==l.length?null:400-d-i.length}function pt(a,c){if(!c)return a;const i=[];for(const l of a){const o=ft(l.label,c);o!==null&&i.push({item:l,score:o})}return i.sort((l,o)=>o.score-l.score||l.item.label.localeCompare(o.item.label)),i.map(l=>l.item)}function mt(a){const c=new Set,i=[];for(const l of a)c.has(l.label)||(c.add(l.label),i.push(l));return i}function He(a,c,i){const{prefix:l,chain:o}=dt(a,c);if(i.auto&&(!l&&o.length===0||l&&!ut.test(l)))return null;const u=i.declared??[],d=[...u,...i.completions];let f;if(o.length>0){const p=Ne(o,d);if(!p||p.length===0)return null;f=p}else f=[...i.completions,...u,...re(i.language).map(p=>({label:p,kind:"keyword"}))];const r=pt(mt(f),l);return r.length===0?null:{items:r,start:c-l.length,end:c}}const ht=/([A-Za-z_$][\w$]*(?:\??\.[A-Za-z_$][\w$]*)*)\??\.\s*$/;function Ae(a,c,i,l){const o=a.slice(c,i);if(!o)return null;const u=[...l.declared??[],...l.completions],d=ht.exec(a.slice(0,c));if(d){const f=d[1].split(".").filter(Boolean).map(b=>b.replace(/\?$/,"")),r=Ne(f,u),p=r==null?void 0:r.find(b=>b.label===o);if(p)return p}return u.find(f=>f.label===o)??null}const V="[A-Za-z_$][\\w$]*",Se="(?:readonly\\s+|public\\s+|private\\s+|protected\\s+|static\\s+|abstract\\s+)*";function $e(a,c){let i=0,l=!1,o=c;for(let u=c;u<a.length;u++){const d=a[u];for(let f=0;f<d.length;f++){const r=d[f];r==="{"?(i++,l=!0):r==="}"&&i--}if(l&&i<=0){o=u;break}}return{end:o,body:a.slice(c+1,o)}}function Be(a){return a.trim().replace(/[,;]$/,"").trim()}function _e(a){const c=[],i=new Set,l=new RegExp(`^${Se}(${V})(\\?)?\\s*\\((.*)\\)\\s*:\\s*(.+?);?$`),o=new RegExp(`^${Se}(${V})(\\?)?\\s*:\\s*(.+?);?$`);for(const u of a){const d=u.trim();if(!d||d.startsWith("//")||d.startsWith("/*")||d.startsWith("*")||d.startsWith("}"))continue;const f=l.exec(d);if(f){const p=f[1];if(i.has(p))continue;i.add(p),c.push({label:p,kind:"function",detail:`(${f[3].trim()}) => ${Be(f[4])}`});continue}const r=o.exec(d);if(r){const p=r[1];if(i.has(p))continue;i.add(p);const b=Be(r[3]),k=/^\(|=>/.test(b)?"function":"property";c.push({label:p,kind:k,detail:b})}}return c}function Le(a){const c=a.replace(/\[\]/g,"").replace(/<[^>]*>/g,"").replace(/\s*\|\s*null\s*/g,"").trim(),i=new RegExp(`^(${V})$`).exec(c);return i?i[1]:null}function gt(a){const c=a.trim();if(!c||c.endsWith(";"))return!1;const i=(c.match(/[(<[{]/g)??[]).length,l=(c.match(/[)>\]}]/g)??[]).length;return/[|&,(<]\s*$/.test(c)||i>l}function Ve(a,c,i,l=0){return l>6?a:a.map(o=>{if(o.kind!=="property"||!o.detail)return o;const u=Le(o.detail),d=u?c.get(u):void 0;if(!d||i.has(d.label))return o;const f=new Set(i);return f.add(d.label),{...o,type:d.type,members:Ve(d.members,c,f,l+1)}})}function Oe(a){if(!a||!a.trim())return[];const c=a.split(`
|
|
9
|
+
`),i=new Map,l=new RegExp(`^(?:export\\s+)?(?:declare\\s+)?interface\\s+(${V})`),o=new RegExp(`^(?:export\\s+)?(?:declare\\s+)?(?:abstract\\s+)?class\\s+(${V})`),u=new RegExp(`^(?:export\\s+)?(?:declare\\s+)?type\\s+(${V})\\s*=`);for(let b=0;b<c.length;b++){const k=c[b].trim();if(!k||k.startsWith("//")||k.startsWith("/*")||k.startsWith("*"))continue;const R=l.exec(k);if(R&&k.includes("{")){const{end:x,body:E}=$e(c,b),v=R[1];i.set(v,{label:v,type:c.slice(b,x+1).join(`
|
|
10
|
+
`).replace(/^\s*export\s+/,"").trim(),members:_e(E),kind:"interface"}),b=x;continue}const I=o.exec(k);if(I&&k.includes("{")){const{end:x,body:E}=$e(c,b),v=I[1];i.set(v,{label:v,type:c.slice(b,x+1).join(`
|
|
11
|
+
`).replace(/^\s*export\s+/,"").trim(),members:_e(E),kind:"class"}),b=x;continue}const T=u.exec(k);if(T){const x=[c[b]];let E=b;for(;gt(x.join(`
|
|
12
|
+
`))&&E+1<c.length;)E++,x.push(c[E]);const v=x.join(`
|
|
13
|
+
`).replace(/^\s*export\s+/,"").replace(/;\s*$/,"").trim();i.set(T[1],{label:T[1],type:v,members:[],kind:"type"}),b=E}}const d=[],f=new Set,r=new RegExp(`^(?:export\\s+)?(?:declare\\s+)?function\\s+(${V})\\s*\\(([^)]*)\\)\\s*:\\s*([^;{]+)`),p=new RegExp(`^(?:export\\s+)?(?:declare\\s+)?(?:const|let|var)\\s+(${V})\\s*:\\s*([^=;]+)`);for(const b of c){const k=b.trim();if(!k||k.startsWith("//")||k.startsWith("/*")||k.startsWith("*"))continue;const R=r.exec(k);if(R){const T=R[1];f.has(T)||(f.add(T),d.push({label:T,kind:"function",detail:`(${R[2].trim()}) => ${R[3].trim()}`}));continue}const I=p.exec(k);if(I){const T=I[1];if(f.has(T))continue;f.add(T);const x=I[2].trim(),E=Le(x),v=E?i.get(E):void 0,N=(v==null?void 0:v.kind)==="class"?"class":/^\(|=>/.test(x)?"function":"variable";d.push({label:T,kind:N,detail:x,type:v==null?void 0:v.type,members:v?Ve(v.members,i,new Set([v.label])):void 0})}}return d}function J(a,c,i,l){if(!i||!l)return null;const o=Math.max(0,c-1),u=a.lastIndexOf(i,o);if(u===-1||a.lastIndexOf(l,o)>u)return null;const f=a.indexOf(l,u+i.length);return{start:u+i.length,end:f===-1?a.length:f}}function bt(a,c,i,l){return J(a,c,i,l)!==null}const Re=/[A-Za-z_$]/,vt=/[\w$]/,Ie=/\s/;function Z(a,c){const i=[],l=a.length;let o=0;for(;o<l;){const u=a[o],d=a[o+1];if(Ie.test(u)){o++;continue}if(u==="/"&&d==="/"){let r=a.indexOf(`
|
|
14
|
+
`,o);r===-1&&(r=l),i.push({start:o,end:r,type:"comment"}),o=r;continue}if(u==="/"&&d==="*"){const r=a.indexOf("*/",o+2),p=r===-1?l:r+2;i.push({start:o,end:p,type:"comment"}),o=p;continue}if(u==='"'||u==="'"){let r=o+1;for(;r<l;){if(a[r]==="\\"){r+=2;continue}if(a[r]===`
|
|
15
|
+
`)break;if(a[r]===u){r++;break}r++}i.push({start:o,end:r,type:"string"}),o=r;continue}if(u==="`"){let r=o+1;for(;r<l;){if(a[r]==="\\"){r+=2;continue}if(a[r]==="`"){r++;break}r++}i.push({start:o,end:r,type:"template"}),o=r;continue}if(/[0-9]/.test(u)||u==="."&&/[0-9]/.test(d??"")){let r=o+1;for(;r<l&&/[\w.]/.test(a[r]);)r++;i.push({start:o,end:r,type:"number"}),o=r;continue}if(Re.test(u)){let r=o+1;for(;r<l&&vt.test(a[r]);)r++;const p=a.slice(o,r),b=c.keywords.has(p)?"keyword":c.builtins.has(p)?"builtin":"identifier";i.push({start:o,end:r,type:b}),o=r;continue}let f=o+1;for(;f<l;){const r=a[f];if(Ie.test(r)||Re.test(r)||/[0-9]/.test(r)||r==='"'||r==="'"||r==="`"||r==="/")break;f++}i.push({start:o,end:f,type:"punctuation"}),o=f}return i}const yt={"&":"&","<":"<",">":">"};function D(a){return a.replace(/[&<>]/g,c=>yt[c]??c)}function q(a,c,i=0){let l="",o=0;for(const u of c){u.start>o&&(l+=D(a.slice(o,u.start)));const d=D(a.slice(u.start,u.end));l+=`<span class="tok-${u.type}" data-start="${u.start+i}" data-end="${u.end+i}">${d}</span>`,o=u.end}return o<a.length&&(l+=D(a.slice(o))),l}function De(a,c,i,l){if(!i||!l)return q(a,Z(a,c));let o="",u=0;for(;u<a.length;){const d=a.indexOf(i,u);if(d===-1){o+=D(a.slice(u));break}o+=D(a.slice(u,d));const f=a.indexOf(l,d+i.length),r=f===-1?a.length:f,p=a.slice(d+i.length,r);o+=`<span class="tok-brace">${D(i)}</span>`,o+=q(p,Z(p,c),d+i.length),f===-1?u=r:(o+=`<span class="tok-brace">${D(l)}</span>`,u=f+l.length)}return o}const kt={key:0,class:"gutter","aria-hidden":"true"},wt=["innerHTML"],xt=["value","readonly","placeholder"],Et=["onMouseenter","onClick"],Tt={class:"popup-label"},Ct={key:0,class:"popup-detail"},St={class:"hover-head"},$t={class:"hover-name"},Bt={key:0,class:"hover-colon"},_t={key:0,class:"hover-type"},Rt={key:0,class:"hover-doc"},It={key:1,class:"hover-def"},Mt=["innerHTML"],Nt=["title","aria-label"],Ht={key:0,viewBox:"0 0 16 16",width:"14",height:"14","aria-hidden":"true"},At={key:1,viewBox:"0 0 16 16",width:"14",height:"14","aria-hidden":"true"},Lt=t.defineComponent({__name:"CodeEditor",props:{modelValue:{},mode:{default:"code"},language:{default:"javascript"},completions:{default:()=>[]},tsTypes:{default:""},templateCompletions:{default:()=>[]},templateOpen:{default:"{{"},templateClose:{default:"}}"},placeholder:{default:""},readonly:{type:Boolean,default:!1},lineNumbers:{type:Boolean,default:!0},hover:{type:Boolean,default:!0},theme:{default:"light"},collapsible:{type:Boolean,default:!1},defaultExpanded:{type:Boolean,default:!1},collapsedHeight:{default:"34px"},collapseOnBlur:{type:Boolean,default:!1},minHeight:{default:"260px"}},emits:["update:modelValue","change","expand","collapse"],setup(a,{expose:c,emit:i}){const l=a,o=i,u={variable:"变量",function:"函数",property:"属性",class:"对象",keyword:"关键字"},d={"(":")","[":"]","{":"}",'"':'"',"'":"'"},f=new Set(["ArrowLeft","ArrowRight","ArrowUp","ArrowDown","Home","End","PageUp","PageDown"]),r=t.ref(l.modelValue),p=t.ref(),b=t.ref(),k=t.ref(),R=t.ref(),I=t.ref(),T=t.ref(),x=t.ref(),E=t.ref([]),v=t.ref(0),N=t.ref(!1),G=t.ref({start:0,end:0}),se=t.ref({}),C=t.ref(null),ce=t.ref({}),We=t.computed(()=>l.tsTypes?Oe(l.tsTypes):[]),ue=t.computed(()=>[...Me,...We.value,...l.completions]),X=t.computed(()=>l.mode==="template"?[...l.templateCompletions,...ue.value]:ue.value),je=t.computed(()=>{const e={keywords:ae(l.language),builtins:new Set(X.value.map(n=>n.label))};return l.mode==="template"?`${De(r.value,e,l.templateOpen,l.templateClose)}
|
|
16
|
+
`:`${q(r.value,Z(r.value,e))}
|
|
17
|
+
`}),Pe=t.computed(()=>r.value.split(`
|
|
18
|
+
`).length),H=t.ref(l.defaultExpanded),z=t.computed(()=>l.collapsible&&!H.value),Fe=t.computed(()=>z.value?{"--ce-collapsed-height":l.collapsedHeight}:{height:l.minHeight}),Ke=t.computed(()=>z.value?{height:l.collapsedHeight}:{});let de=0;function fe(e){if(H.value===e)return;const n=p.value;e&&n&&(de=n.scrollTop),H.value=e,o(e?"expand":"collapse"),S(),_(),t.nextTick(()=>{if(Q(),!H.value&&n){const s=Math.max(0,n.scrollHeight-n.clientHeight);n.scrollTop=Math.max(0,Math.min(de,s)),M(!0),document.activeElement===n&&j();return}M(!0),e&&l.collapseOnBlur&&n&&document.activeElement!==n&&n.focus()})}function Ze(){fe(!H.value)}t.watch(()=>l.modelValue,e=>{e!==r.value&&(r.value=e,S())}),t.watch(r,()=>{t.nextTick(()=>M(!0))});function pe(e){return u[e]}function qe(e){return e?q(e,Z(e,{keywords:ae("typescript"),builtins:new Set})):""}let W={top:14,bottom:14,lineHeight:22};function Q(){const e=p.value;if(!e)return;const n=window.getComputedStyle(e);W={top:parseFloat(n.paddingTop)||0,bottom:parseFloat(n.paddingBottom)||0,lineHeight:parseFloat(n.lineHeight)||22}}function M(e=!1){const n=p.value;if(!n)return;const s=R.value;if(s&&(s.style.transform=`translate(${-n.scrollLeft}px, ${-n.scrollTop}px)`),I.value&&(I.value.style.transform=`translateY(${-n.scrollTop}px)`),e){const h=`${r.value}|${l.mode}|${n.clientWidth}|${n.clientHeight}`;h!==he&&(he=h,Ue())}}function j(){const e=p.value;if(!e||!z.value)return;const n=ge();if(!n)return;const s=e.clientHeight-W.top-W.bottom,g=n.top+e.scrollTop-W.top-Math.max(0,(s-n.lineHeight)/2),m=Math.max(0,e.scrollHeight-e.clientHeight),w=Math.max(0,Math.min(g,m));Math.abs(w-e.scrollTop)>.5&&(e.scrollTop=w,M())}let me=[],he="",U=0,ee=-1,te=-1,ne={x:0,y:0};function Ue(){const e=p.value,n=k.value;if(!e||!n)return;const s=e.getBoundingClientRect(),h=[];n.querySelectorAll("[data-start]").forEach(g=>{const m=g.getBoundingClientRect();h.push({start:Number(g.dataset.start),end:Number(g.dataset.end),left:m.left-s.left+e.scrollLeft,right:m.right-s.left+e.scrollLeft,top:m.top-s.top+e.scrollTop,bottom:m.bottom-s.top+e.scrollTop})}),me=h}function Ye(e,n){for(const s of me)if(e>=s.left-1&&e<=s.right+1&&n>=s.top&&n<=s.bottom)return s;return null}function _(){C.value=null,U=0,ee=-1,te=-1}function Je(e){const n=x.value,s=p.value;if(!n||!s)return;const h=s.getBoundingClientRect(),g=h.left+e.left-s.scrollLeft,m=h.left+e.right-s.scrollLeft,w=h.top+e.top-s.scrollTop,y=h.top+e.bottom-s.scrollTop,$=12,B=8,A=n.offsetWidth,F=n.offsetHeight;let L=g,O=y+B;L+A>window.innerWidth-$&&(L=m-A),O+F>window.innerHeight-$&&(O=w-F-B),L=Math.max($,Math.min(L,window.innerWidth-$-A)),O=Math.max($,O),ce.value={left:`${L}px`,top:`${O}px`}}function Ge(e,n){const s=p.value;if(!s||l.readonly||!l.hover||N.value){_();return}if(s.selectionStart!==s.selectionEnd){_();return}const h=x.value;if(C.value&&h){const y=h.getBoundingClientRect();if(e>=y.left&&e<=y.right&&n>=y.top&&n<=y.bottom)return}const g=s.getBoundingClientRect(),m=Ye(e-g.left+s.scrollLeft,n-g.top+s.scrollTop);if(!m){_();return}if(C.value&&ee===m.start&&te===m.end)return;const w=Ae(s.value,m.start,m.end,{completions:X.value,declared:ie(s.value,m.start)});if(!w){_();return}C.value=w,ee=m.start,te=m.end,t.nextTick(()=>Je(m))}function Xe(e){ne={x:e.clientX,y:e.clientY},!U&&(U=requestAnimationFrame(()=>{U=0,Ge(ne.x,ne.y)}))}function ge(){const e=p.value;if(!e)return null;const n=window.getComputedStyle(e),s=document.createElement("div"),h=parseFloat(n.paddingLeft)||0,g=parseFloat(n.paddingRight)||0,m=e.getBoundingClientRect();Object.assign(s.style,{position:"fixed",left:`${m.left}px`,top:`${m.top}px`,visibility:"hidden",pointerEvents:"none",zIndex:"-1",whiteSpace:"pre-wrap",overflowWrap:"break-word",wordBreak:"normal",boxSizing:"content-box",width:`${e.clientWidth-h-g}px`,paddingTop:n.paddingTop,paddingRight:n.paddingRight,paddingBottom:n.paddingBottom,paddingLeft:n.paddingLeft,border:"0",fontFamily:n.fontFamily,fontSize:n.fontSize,fontWeight:n.fontWeight,fontStyle:n.fontStyle,fontVariant:n.fontVariant,letterSpacing:n.letterSpacing,lineHeight:n.lineHeight,textTransform:n.textTransform,tabSize:n.tabSize}),s.textContent=e.value.slice(0,e.selectionStart);const w=document.createElement("span");w.textContent="",s.appendChild(w),document.body.appendChild(s);const y=w.getBoundingClientRect();document.body.removeChild(s);const $=parseFloat(n.lineHeight)||22,B=y.height,A=B>0&&B<$?($-B)/2:0;return{left:y.left-m.left-e.scrollLeft,top:y.top-m.top-e.scrollTop-A,lineHeight:$}}async function Qe(){await t.nextTick();const e=b.value,n=T.value,s=ge();if(!e||!n||!s)return;const h=4,g=8,m=window.innerWidth,w=window.innerHeight,y=e.getBoundingClientRect(),$=n.scrollHeight,B=w-(y.top+s.top+s.lineHeight)-h-g,A=y.top+s.top-h-g,F=B>=Math.min($,180)||B>=A,L=Math.min(248,Math.max(F?B:A,96)),O=Math.min($,L),Ee=n.offsetWidth||280;let K=s.left;y.left+K+Ee>m-g&&(K=m-g-Ee-y.left),K=Math.max(K,g-y.left),se.value={left:`${K}px`,top:`${F?s.top+s.lineHeight+h:s.top-h-O}px`,maxHeight:`${L}px`}}function S(){N.value=!1,E.value=[],v.value=0,_()}function P(e=!1){const n=p.value;if(!n||l.readonly)return;if(n.selectionStart!==n.selectionEnd){S();return}const s=n.selectionStart;let h=!e;if(l.mode==="template"){const m=J(n.value,s,l.templateOpen,l.templateClose);if(!m){S();return}e&&n.value.slice(m.start,s).trim()===""&&(h=!0)}const g=He(n.value,s,{language:l.language,completions:X.value,declared:ie(n.value,s),auto:!h});if(!g){S();return}E.value=g.items,G.value={start:g.start,end:g.end},v.value=0,N.value=!0,Qe()}function et(e){r.value=e,o("update:modelValue",e),o("change",e)}function Y(e,n,s,h=e+s.length){const g=p.value;if(!g)return;const m=g.value.slice(0,e)+s+g.value.slice(n);et(m),S(),t.nextTick(()=>{g.value=m,g.setSelectionRange(h,h),g.focus(),M(!0),j()})}function be(e=E.value[v.value]){if(!e)return;const n=e.insertText??e.label;Y(G.value.start,G.value.end,n),S()}function ve(e){const n=E.value.length;n&&(v.value=(v.value+e+n)%n,t.nextTick(()=>{var s,h;(h=(s=T.value)==null?void 0:s.querySelector(".is-active"))==null||h.scrollIntoView({block:"nearest"})}))}function tt(e){const n=e.target;r.value=n.value,o("update:modelValue",n.value),o("change",n.value),_(),M(),t.nextTick(j),P(!0)}function nt(e){if(S(),_(),!l.collapsible||!l.collapseOnBlur||!H.value)return;const n=e.relatedTarget;n&&n.closest(".expand-toggle")||fe(!1)}function lt(){ye(),j()}function ye(){const e=p.value;if(!e||l.readonly)return;if(e.selectionStart!==e.selectionEnd){S();return}const n=e.selectionStart;if(n>0&&e.value[n-1]==="."){P(!0);return}if(l.mode==="template"){const s=J(e.value,n,l.templateOpen,l.templateClose);if(s&&e.value.slice(s.start,n).trim()===""){P(!0);return}}S()}let le=0;function ke(){window.clearTimeout(le),le=window.setTimeout(()=>{le=0,ye(),j()},0)}function we(e){e.target!==p.value&&N.value&&S()}function ot(){_(),M(),z.value&&at()}let oe=0;function at(){window.clearTimeout(oe),oe=window.setTimeout(()=>{oe=0,it()},120)}function it(){const e=p.value;if(!e)return;const n=W.lineHeight,s=e.scrollTop,h=Math.round(s/n)*n;Math.abs(h-s)<.5||(e.scrollTop=h,M())}function rt(e){var g;const n=p.value;if(!n)return;const s=e.metaKey||e.ctrlKey,h=f.has(e.key);if(e.key===" "&&s){e.preventDefault(),P(!1);return}if(N.value){if(e.key==="ArrowDown"){e.preventDefault(),ve(1);return}if(e.key==="ArrowUp"){e.preventDefault(),ve(-1);return}if(e.key==="Enter"||e.key==="Tab"){e.preventDefault(),be();return}if(e.key==="Escape"){e.preventDefault(),S();return}if(h||s){S(),h&&!s&&ke();return}}if(h&&!s){ke();return}if(e.key==="Enter"&&!s&&!e.shiftKey){const m=n.selectionStart;if(m!==n.selectionEnd)return;const w=n.value.lastIndexOf(`
|
|
19
|
+
`,m-1)+1,y=n.value.slice(w,m),$=((g=y.match(/^[ \t]*/))==null?void 0:g[0])??"",B=/[{[(]$/.test(y.trimEnd())?" ":"";e.preventDefault(),Y(m,m,`
|
|
20
|
+
${$}${B}`);return}if(e.key==="Tab"){e.preventDefault(),Y(n.selectionStart,n.selectionEnd," ");return}if(e.key.length===1&&!s&&!e.altKey&&d[e.key]){if(n.selectionStart!==n.selectionEnd)return;const m=n.selectionStart,w=n.value[m-1],y=n.value[m];if((e.key==='"'||e.key==="'")&&w&&/[\w$]/.test(w)||y!==void 0&&!/[\s)\]},;:]/.test(y))return;e.preventDefault(),Y(m,m,e.key+d[e.key],m+1),l.mode==="template"&&t.nextTick(()=>P(!0))}}function xe(){N.value&&S(),_(),t.nextTick(()=>{Q(),M(!0)})}return t.onMounted(()=>{window.addEventListener("resize",xe),window.addEventListener("scroll",we,!0),t.nextTick(()=>{Q(),M(!0)})}),t.onBeforeUnmount(()=>{window.removeEventListener("resize",xe),window.removeEventListener("scroll",we,!0)}),c({focus:()=>{var e;return(e=p.value)==null?void 0:e.focus()}}),(e,n)=>(t.openBlock(),t.createElementBlock("div",{class:t.normalizeClass(["code-editor",{"is-readonly":a.readonly,"is-dark":a.theme==="dark","is-collapsed":z.value}]),style:t.normalizeStyle(Fe.value)},[a.lineNumbers&&!z.value?(t.openBlock(),t.createElementBlock("div",kt,[t.createElementVNode("div",{ref_key:"gutterInner",ref:I,class:"gutter-inner code-font"},[(t.openBlock(!0),t.createElementBlock(t.Fragment,null,t.renderList(Pe.value,s=>(t.openBlock(),t.createElementBlock("div",{key:s,class:"gutter-line"},t.toDisplayString(s),1))),128))],512)])):t.createCommentVNode("",!0),t.createElementVNode("div",{ref_key:"stage",ref:b,class:"stage",style:t.normalizeStyle(Ke.value)},[t.createElementVNode("div",{ref_key:"highlightLayer",ref:k,class:"highlight code-font"},[t.createElementVNode("pre",{ref_key:"highlightInner",ref:R,class:"code-font"},[t.createElementVNode("code",{innerHTML:je.value},null,8,wt)],512)],512),t.createElementVNode("textarea",{ref_key:"textarea",ref:p,class:"code-font input",value:r.value,readonly:a.readonly,placeholder:a.placeholder,spellcheck:"false",autocomplete:"off",autocapitalize:"off",autocorrect:"off",wrap:"soft",onInput:tt,onKeydown:rt,onScroll:ot,onClick:lt,onMousemove:Xe,onMouseleave:_,onBlur:nt},null,40,xt),N.value?(t.openBlock(),t.createElementBlock("ul",{key:0,ref_key:"popup",ref:T,class:"popup",style:t.normalizeStyle(se.value),onMousedown:n[0]||(n[0]=t.withModifiers(()=>{},["prevent"]))},[(t.openBlock(!0),t.createElementBlock(t.Fragment,null,t.renderList(E.value,(s,h)=>(t.openBlock(),t.createElementBlock("li",{key:`${s.label}-${h}`,class:t.normalizeClass(["popup-item",{"is-active":h===v.value}]),onMouseenter:g=>v.value=h,onClick:g=>be(s)},[t.createElementVNode("span",{class:t.normalizeClass(["badge",`badge-${s.kind}`])},t.toDisplayString(pe(s.kind)),3),t.createElementVNode("span",Tt,t.toDisplayString(s.label),1),s.detail?(t.openBlock(),t.createElementBlock("span",Ct,t.toDisplayString(s.detail),1)):t.createCommentVNode("",!0)],42,Et))),128))],36)):t.createCommentVNode("",!0),C.value?(t.openBlock(),t.createElementBlock("div",{key:1,ref_key:"hoverCard",ref:x,class:"hover-card",style:t.normalizeStyle(ce.value)},[t.createElementVNode("div",St,[t.createElementVNode("span",{class:t.normalizeClass(["badge",`badge-${C.value.kind}`])},t.toDisplayString(pe(C.value.kind)),3),t.createElementVNode("span",$t,[t.createTextVNode(t.toDisplayString(C.value.label),1),C.value.detail?(t.openBlock(),t.createElementBlock("span",Bt,":")):t.createCommentVNode("",!0)]),C.value.detail?(t.openBlock(),t.createElementBlock("span",_t,t.toDisplayString(C.value.detail),1)):t.createCommentVNode("",!0)]),C.value.documentation?(t.openBlock(),t.createElementBlock("p",Rt,t.toDisplayString(C.value.documentation),1)):t.createCommentVNode("",!0),C.value.type?(t.openBlock(),t.createElementBlock("pre",It,[t.createElementVNode("code",{innerHTML:qe(C.value.type)},null,8,Mt)])):t.createCommentVNode("",!0)],4)):t.createCommentVNode("",!0)],4),a.collapsible?(t.openBlock(),t.createElementBlock("button",{key:1,type:"button",class:"expand-toggle",title:H.value?"收起":"展开","aria-label":H.value?"收起编辑器":"展开编辑器",onClick:Ze},[H.value?(t.openBlock(),t.createElementBlock("svg",At,[...n[2]||(n[2]=[t.createElementVNode("path",{d:"M11 2 5 8 11 14",fill:"none",stroke:"currentColor","stroke-width":"1.6","stroke-linecap":"round","stroke-linejoin":"round"},null,-1)])])):(t.openBlock(),t.createElementBlock("svg",Ht,[...n[1]||(n[1]=[t.createElementVNode("path",{d:"M6 2 12 8 6 14",fill:"none",stroke:"currentColor","stroke-width":"1.6","stroke-linecap":"round","stroke-linejoin":"round"},null,-1)])]))],8,Nt)):t.createCommentVNode("",!0)],6))}}),Vt=(a,c)=>{const i=a.__vccOpts||a;for(const[l,o]of c)i[l]=o;return i},ze=Vt(Lt,[["__scopeId","data-v-dc3651c9"]]),Ot={install(a){a.component("CodeInput",ze)}};exports.CodeEditor=ze;exports.collectCompletions=He;exports.default=Ot;exports.defaultCompletions=Me;exports.findTemplateRange=J;exports.getKeywordSet=ae;exports.getKeywords=re;exports.highlight=q;exports.highlightTemplate=De;exports.isInsideTemplate=bt;exports.parseTsCompletions=Oe;exports.resolveHoverItem=Ae;exports.scanDeclarations=ie;exports.tokenize=Z;
|