@zh-keyboard/vue 1.1.0 → 1.1.2

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.
@@ -1,1434 +1,992 @@
1
- var Pe = Object.defineProperty;
2
- var _e = (e, o, s) => o in e ? Pe(e, o, { enumerable: !0, configurable: !0, writable: !0, value: s }) : e[o] = s;
3
- var T = (e, o, s) => _e(e, typeof o != "symbol" ? o + "" : o, s);
4
- import { onMounted as Q, nextTick as me, watch as X, getCurrentScope as $e, onScopeDispose as Ee, getCurrentInstance as pe, toValue as B, shallowRef as G, computed as S, watchEffect as q, unref as n, ref as E, onUnmounted as ce, onBeforeUnmount as Se, defineComponent as I, createElementBlock as x, openBlock as b, Fragment as L, renderList as V, toDisplayString as D, createVNode as Le, createElementVNode as h, withModifiers as C, normalizeStyle as se, normalizeClass as O, mergeModels as ie, useModel as ke, createBlock as K, createCommentVNode as W, createTextVNode as re, withDirectives as Re, vShow as Te } from "vue";
5
- function ee(e) {
6
- return $e() ? (Ee(e), !0) : !1;
7
- }
8
- const De = typeof window < "u" && typeof document < "u";
1
+ import { Fragment as e, computed as t, createBlock as n, createCommentVNode as r, createElementBlock as i, createElementVNode as a, createTextVNode as o, createVNode as s, defineComponent as c, getCurrentInstance as l, getCurrentScope as u, mergeModels as d, nextTick as f, normalizeClass as p, normalizeStyle as m, onBeforeUnmount as h, onMounted as g, onScopeDispose as _, onUnmounted as v, openBlock as y, ref as b, renderList as x, shallowRef as S, toDisplayString as C, toValue as w, unref as T, useModel as E, vShow as D, watch as O, watchEffect as k, withDirectives as A, withModifiers as j } from "vue";
2
+ import { CanvasDrawer as M, calculateKeyboardPosition as N, createKeyRepeater as P, delToInputElement as F, getHandwritingRecognizer as I, getKeyboardConfig as L, getPinyinEngine as R, isInputElement as z, writeToInputElement as ee } from "@zh-keyboard/core";
3
+ export * from "@zh-keyboard/core";
4
+ //#region ../../node_modules/.pnpm/@vueuse+shared@13.1.0_vue@3.5.13_typescript@5.8.3_/node_modules/@vueuse/shared/index.mjs
5
+ function B(e) {
6
+ return u() ? (_(e), !0) : !1;
7
+ }
8
+ var V = typeof window < "u" && typeof document < "u";
9
9
  typeof WorkerGlobalScope < "u" && globalThis instanceof WorkerGlobalScope;
10
- const Me = (e) => e != null, He = Object.prototype.toString, Ve = (e) => He.call(e) === "[object Object]", le = () => {
11
- };
12
- function Be(e, o) {
13
- function s(...a) {
14
- return new Promise((l, i) => {
15
- Promise.resolve(e(() => o.apply(this, a), { fn: o, thisArg: this, args: a })).then(l).catch(i);
16
- });
17
- }
18
- return s;
19
- }
20
- function Ie(e, o = {}) {
21
- let s, a, l = le;
22
- const i = (c) => {
23
- clearTimeout(c), l(), l = le;
24
- };
25
- let d;
26
- return (c) => {
27
- const y = B(e), g = B(o.maxWait);
28
- return s && i(s), y <= 0 || g !== void 0 && g <= 0 ? (a && (i(a), a = null), Promise.resolve(c())) : new Promise((u, p) => {
29
- l = o.rejectOnCancel ? p : u, d = c, g && !a && (a = setTimeout(() => {
30
- s && i(s), a = null, u(d());
31
- }, g)), s = setTimeout(() => {
32
- a && i(a), a = null, u(c());
33
- }, y);
34
- });
35
- };
36
- }
37
- function j(e) {
38
- return Array.isArray(e) ? e : [e];
39
- }
40
- function Ae(e) {
41
- return pe();
42
- }
43
- function Ke(e, o = 200, s = {}) {
44
- return Be(
45
- Ie(o, s),
46
- e
47
- );
48
- }
49
- function We(e, o = !0, s) {
50
- Ae() ? Q(e, s) : o ? e() : me(e);
51
- }
52
- function Oe(e, o, s) {
53
- return X(
54
- e,
55
- o,
56
- {
57
- ...s,
58
- immediate: !0
59
- }
60
- );
61
- }
62
- const Y = De ? window : void 0;
63
- function H(e) {
64
- var o;
65
- const s = B(e);
66
- return (o = s == null ? void 0 : s.$el) != null ? o : s;
67
- }
68
- function J(...e) {
69
- const o = [], s = () => {
70
- o.forEach((f) => f()), o.length = 0;
71
- }, a = (f, c, y, g) => (f.addEventListener(c, y, g), () => f.removeEventListener(c, y, g)), l = S(() => {
72
- const f = j(B(e[0])).filter((c) => c != null);
73
- return f.every((c) => typeof c != "string") ? f : void 0;
74
- }), i = Oe(
75
- () => {
76
- var f, c;
77
- return [
78
- (c = (f = l.value) == null ? void 0 : f.map((y) => H(y))) != null ? c : [Y].filter((y) => y != null),
79
- j(B(l.value ? e[1] : e[0])),
80
- j(n(l.value ? e[2] : e[1])),
81
- // @ts-expect-error - TypeScript gets the correct types, but somehow still complains
82
- B(l.value ? e[3] : e[2])
83
- ];
84
- },
85
- ([f, c, y, g]) => {
86
- if (s(), !(f != null && f.length) || !(c != null && c.length) || !(y != null && y.length))
87
- return;
88
- const u = Ve(g) ? { ...g } : g;
89
- o.push(
90
- ...f.flatMap(
91
- (p) => c.flatMap(
92
- (v) => y.map((m) => a(p, v, m, u))
93
- )
94
- )
95
- );
96
- },
97
- { flush: "post" }
98
- ), d = () => {
99
- i(), s();
100
- };
101
- return ee(s), d;
102
- }
103
- function Ne() {
104
- const e = G(!1), o = pe();
105
- return o && Q(() => {
106
- e.value = !0;
107
- }, o), e;
108
- }
109
- function ge(e) {
110
- const o = Ne();
111
- return S(() => (o.value, !!e()));
112
- }
113
- function Ue(e, o, s = {}) {
114
- const { window: a = Y, ...l } = s;
115
- let i;
116
- const d = ge(() => a && "MutationObserver" in a), f = () => {
117
- i && (i.disconnect(), i = void 0);
118
- }, c = S(() => {
119
- const p = B(e), v = j(p).map(H).filter(Me);
120
- return new Set(v);
121
- }), y = X(
122
- () => c.value,
123
- (p) => {
124
- f(), d.value && p.size && (i = new MutationObserver(o), p.forEach((v) => i.observe(v, l)));
125
- },
126
- { immediate: !0, flush: "post" }
127
- ), g = () => i == null ? void 0 : i.takeRecords(), u = () => {
128
- y(), f();
129
- };
130
- return ee(u), {
131
- isSupported: d,
132
- stop: u,
133
- takeRecords: g
134
- };
135
- }
136
- function Fe(e, o, s = {}) {
137
- const {
138
- window: a = Y,
139
- document: l = a == null ? void 0 : a.document,
140
- flush: i = "sync"
141
- } = s;
142
- if (!a || !l)
143
- return le;
144
- let d;
145
- const f = (g) => {
146
- d == null || d(), d = g;
147
- }, c = q(() => {
148
- const g = H(e);
149
- if (g) {
150
- const { stop: u } = Ue(
151
- l,
152
- (p) => {
153
- p.map((m) => [...m.removedNodes]).flat().some((m) => m === g || m.contains(g)) && o(p);
154
- },
155
- {
156
- window: a,
157
- childList: !0,
158
- subtree: !0
159
- }
160
- );
161
- f(u);
162
- }
163
- }, { flush: i }), y = () => {
164
- c(), f();
165
- };
166
- return ee(y), y;
167
- }
168
- function Ze(e = {}) {
169
- var o;
170
- const {
171
- window: s = Y,
172
- deep: a = !0,
173
- triggerOnRemoval: l = !1
174
- } = e, i = (o = e.document) != null ? o : s == null ? void 0 : s.document, d = () => {
175
- var y;
176
- let g = i == null ? void 0 : i.activeElement;
177
- if (a)
178
- for (; g != null && g.shadowRoot; )
179
- g = (y = g == null ? void 0 : g.shadowRoot) == null ? void 0 : y.activeElement;
180
- return g;
181
- }, f = G(), c = () => {
182
- f.value = d();
183
- };
184
- if (s) {
185
- const y = {
186
- capture: !0,
187
- passive: !0
188
- };
189
- J(
190
- s,
191
- "blur",
192
- (g) => {
193
- g.relatedTarget === null && c();
194
- },
195
- y
196
- ), J(
197
- s,
198
- "focus",
199
- c,
200
- y
201
- );
202
- }
203
- return l && Fe(f, c, { document: i }), c(), f;
204
- }
205
- function Xe(e, o, s = {}) {
206
- const { window: a = Y, ...l } = s;
207
- let i;
208
- const d = ge(() => a && "ResizeObserver" in a), f = () => {
209
- i && (i.disconnect(), i = void 0);
210
- }, c = S(() => {
211
- const u = B(e);
212
- return Array.isArray(u) ? u.map((p) => H(p)) : [H(u)];
213
- }), y = X(
214
- c,
215
- (u) => {
216
- if (f(), d.value && a) {
217
- i = new ResizeObserver(o);
218
- for (const p of u)
219
- p && i.observe(p, l);
220
- }
221
- },
222
- { immediate: !0, flush: "post" }
223
- ), g = () => {
224
- f(), y();
225
- };
226
- return ee(g), {
227
- isSupported: d,
228
- stop: g
229
- };
230
- }
231
- function he(e, o = { width: 0, height: 0 }, s = {}) {
232
- const { window: a = Y, box: l = "content-box" } = s, i = S(() => {
233
- var u, p;
234
- return (p = (u = H(e)) == null ? void 0 : u.namespaceURI) == null ? void 0 : p.includes("svg");
235
- }), d = G(o.width), f = G(o.height), { stop: c } = Xe(
236
- e,
237
- ([u]) => {
238
- const p = l === "border-box" ? u.borderBoxSize : l === "content-box" ? u.contentBoxSize : u.devicePixelContentBoxSize;
239
- if (a && i.value) {
240
- const v = H(e);
241
- if (v) {
242
- const m = v.getBoundingClientRect();
243
- d.value = m.width, f.value = m.height;
244
- }
245
- } else if (p) {
246
- const v = j(p);
247
- d.value = v.reduce((m, { inlineSize: P }) => m + P, 0), f.value = v.reduce((m, { blockSize: P }) => m + P, 0);
248
- } else
249
- d.value = u.contentRect.width, f.value = u.contentRect.height;
250
- },
251
- s
252
- );
253
- We(() => {
254
- const u = H(e);
255
- u && (d.value = "offsetWidth" in u ? u.offsetWidth : o.width, f.value = "offsetHeight" in u ? u.offsetHeight : o.height);
256
- });
257
- const y = X(
258
- () => H(e),
259
- (u) => {
260
- d.value = u ? o.width : 0, f.value = u ? o.height : 0;
261
- }
262
- );
263
- function g() {
264
- c(), y();
265
- }
266
- return {
267
- width: d,
268
- height: f,
269
- stop: g
270
- };
271
- }
272
- var Ye = class {
273
- constructor(e, o = {}) {
274
- T(this, "canvas");
275
- T(this, "ctx");
276
- T(this, "lastX", 0);
277
- T(this, "lastY", 0);
278
- T(this, "strokeData", []);
279
- T(this, "clearTimerId", null);
280
- T(this, "isDrawing", !1);
281
- T(this, "options");
282
- T(this, "handleStart", (e) => {
283
- e.preventDefault(), this.isDrawing = !0;
284
- const { offsetX: o, offsetY: s } = this.getEventCoordinates(e);
285
- this.startDrawing(o, s), this.resetClearTimer();
286
- });
287
- T(this, "handleMove", (e) => {
288
- if (!this.isDrawing) return;
289
- e.preventDefault();
290
- const { offsetX: o, offsetY: s } = this.getEventCoordinates(e);
291
- this.draw(o, s), this.resetClearTimer();
292
- });
293
- T(this, "handleEnd", (e) => {
294
- this.isDrawing && (e.preventDefault(), this.isDrawing = !1, this.endStroke(), this.startClearTimer(), this.options.onDrawEnd && this.options.onDrawEnd());
295
- });
296
- this.canvas = e, this.options = {
297
- clearDelay: 1e3,
298
- ...o
299
- };
300
- const s = this.canvas.getContext("2d");
301
- if (!s) throw new Error("Failed to get 2D rendering context");
302
- this.ctx = s, this.setupCanvas(), this.attachEvents();
303
- }
304
- setupCanvas() {
305
- this.ctx.lineJoin = "round", this.ctx.lineCap = "round", this.ctx.lineWidth = 3, this.ctx.strokeStyle = "#000", this.clearCanvas(), this.drawGrid();
306
- }
307
- drawGrid() {
308
- const e = this.canvas.width, o = this.canvas.height;
309
- this.ctx.save(), this.ctx.strokeStyle = "#ddd", this.ctx.lineWidth = 1, this.ctx.setLineDash([3, 3]), this.ctx.beginPath(), this.ctx.moveTo(0, o / 2), this.ctx.lineTo(e, o / 2), this.ctx.moveTo(e / 2, 0), this.ctx.lineTo(e / 2, o), this.ctx.stroke(), this.ctx.setLineDash([]), this.ctx.beginPath(), this.ctx.rect(0, 0, e, o), this.ctx.stroke(), this.ctx.restore();
310
- }
311
- clearCanvas() {
312
- this.ctx.clearRect(0, 0, this.canvas.width, this.canvas.height), this.drawGrid(), this.strokeData = [], this.resetClearTimer();
313
- }
314
- startDrawing(e, o) {
315
- this.lastX = e, this.lastY = o, this.ctx.strokeStyle = "#000", this.ctx.lineWidth = 3, this.ctx.setLineDash([]), this.strokeData.push(e, o, 0);
316
- }
317
- draw(e, o) {
318
- this.ctx.beginPath(), this.ctx.moveTo(this.lastX, this.lastY), this.ctx.lineTo(e, o), this.ctx.stroke(), this.lastX = e, this.lastY = o, this.strokeData.push(e, o, 0);
319
- }
320
- endStroke() {
321
- this.strokeData.length >= 3 && (this.strokeData[this.strokeData.length - 1] = 1);
322
- }
323
- getStrokeData() {
324
- return this.strokeData;
325
- }
326
- resetClearTimer() {
327
- this.clearTimerId && (window.clearTimeout(this.clearTimerId), this.clearTimerId = null);
328
- }
329
- startClearTimer() {
330
- this.resetClearTimer(), this.clearTimerId = window.setTimeout(() => {
331
- this.clearCanvas(), this.clearTimerId = null;
332
- }, this.options.clearDelay);
333
- }
334
- getEventCoordinates(e) {
335
- if (e instanceof MouseEvent) return {
336
- offsetX: e.offsetX,
337
- offsetY: e.offsetY
338
- };
339
- {
340
- const o = e.touches[0] || e.changedTouches[0], s = e.target.getBoundingClientRect();
341
- return {
342
- offsetX: o.clientX - s.left,
343
- offsetY: o.clientY - s.top
344
- };
345
- }
346
- }
347
- attachEvents() {
348
- this.canvas.addEventListener("mousedown", this.handleStart), this.canvas.addEventListener("mousemove", this.handleMove), this.canvas.addEventListener("mouseup", this.handleEnd), this.canvas.addEventListener("mouseleave", this.handleEnd), this.canvas.addEventListener("touchstart", this.handleStart, { passive: !1 }), this.canvas.addEventListener("touchmove", this.handleMove, { passive: !1 }), this.canvas.addEventListener("touchend", this.handleEnd), this.canvas.addEventListener("touchcancel", this.handleEnd);
349
- }
350
- detachEvents() {
351
- this.canvas.removeEventListener("mousedown", this.handleStart), this.canvas.removeEventListener("mousemove", this.handleMove), this.canvas.removeEventListener("mouseup", this.handleEnd), this.canvas.removeEventListener("mouseleave", this.handleEnd), this.canvas.removeEventListener("touchstart", this.handleStart), this.canvas.removeEventListener("touchmove", this.handleMove), this.canvas.removeEventListener("touchend", this.handleEnd), this.canvas.removeEventListener("touchcancel", this.handleEnd);
352
- }
353
- destroy() {
354
- this.detachEvents(), this.resetClearTimer();
355
- }
356
- getCanvas() {
357
- return this.canvas;
358
- }
359
- getContext() {
360
- return this.ctx;
361
- }
362
- };
363
- let ae = {
364
- defaultMode: "en",
365
- enableHandwriting: !1,
366
- position: "static",
367
- disableWhenNoFocus: !0
368
- }, ye = null, be = null;
369
- function Z() {
370
- return ae;
371
- }
372
- function vn(e) {
373
- ae = {
374
- ...ae,
375
- ...e
376
- };
377
- }
378
- function fn(e) {
379
- ye = e;
380
- }
381
- function ue() {
382
- return ye;
383
- }
384
- function mn(e) {
385
- be = e;
386
- }
387
- function je() {
388
- return be;
389
- }
390
- function Ge(e, o, s, a = 0) {
391
- if (!e || !o || s === "static") return null;
392
- let l, i;
393
- if (s === "bottom")
394
- l = window.innerHeight - o.offsetHeight, i = 0;
395
- else {
396
- const d = e.getBoundingClientRect(), f = o.offsetWidth;
397
- l = d.bottom + window.scrollY + a, i = d.left + window.scrollX + d.width / 2 - f / 2;
398
- const c = window.innerWidth;
399
- i + f > c && (i = c - f - 10), i < 10 && (i = 10);
400
- }
401
- return {
402
- top: `${l}px`,
403
- left: `${i}px`
404
- };
405
- }
406
- function de(e) {
407
- if (!e) return !1;
408
- if (e.tagName === "TEXTAREA") return !0;
409
- if (e.tagName === "INPUT") {
410
- const s = (e.type || "text").toLowerCase();
411
- return ![
412
- "checkbox",
413
- "radio",
414
- "button",
415
- "submit",
416
- "reset",
417
- "file",
418
- "image",
419
- "range",
420
- "color",
421
- "hidden",
422
- "date",
423
- "datetime-local",
424
- "month",
425
- "week",
426
- "time"
427
- ].includes(s);
428
- }
429
- return !1;
430
- }
431
- function pn() {
432
- if (document.activeElement && de(document.activeElement)) return document.activeElement;
433
- throw new Error("输入框没有被激活");
434
- }
435
- function qe(e, o, s) {
436
- e.value = o, tt(e, s), e.dispatchEvent(new Event("input", { bubbles: !0 }));
437
- }
438
- function Je(e, o, s, a = "") {
439
- return e.slice(0, o) + a + e.slice(o + s);
440
- }
441
- function we(e, o = "") {
442
- const s = Number(e.getAttribute("maxlength"));
443
- let a = e.selectionStart ?? 0;
444
- const l = e.selectionEnd ?? a;
445
- let i;
446
- if (o.length > 0) i = l - a;
447
- else {
448
- const c = l - a;
449
- if (c > 0) i = c;
450
- else if (a > 0)
451
- i = 1, a--;
452
- else return;
453
- }
454
- if (o.length > 0 && s && e.value.length - i + o.length > s) return;
455
- const d = Je(e.value, a, i, o), f = a + o.length;
456
- qe(e, d, f);
457
- }
458
- function Qe(e, o) {
459
- we(e, o);
460
- }
461
- function et(e) {
462
- we(e);
463
- }
464
- function tt(e, o) {
465
- e.selectionStart = o, e.selectionEnd = o;
466
- }
467
- function nt(e = {}) {
468
- const o = e.delay ?? 400, s = e.interval ?? 60;
469
- let a, l;
470
- function i() {
471
- a && (clearTimeout(a), a = void 0), l && (clearInterval(l), l = void 0);
472
- }
473
- function d(f) {
474
- i(), f(), a = setTimeout(() => {
475
- l = setInterval(() => {
476
- f();
477
- }, s);
478
- }, o);
479
- }
480
- return {
481
- start: d,
482
- stop: i
483
- };
484
- }
485
- function ot(e = !1) {
486
- const o = E(!1), s = E(0);
487
- async function a() {
488
- const i = ue();
489
- if (i)
490
- try {
491
- o.value = await i.initialize({
492
- onProgress: (d) => {
493
- s.value = d;
494
- }
495
- });
496
- } catch (d) {
497
- console.error("初始化手写识别服务失败:", d), o.value = !1;
498
- }
499
- else
500
- console.warn("未注册手写识别服务"), o.value = !1;
501
- }
502
- async function l() {
503
- const i = ue();
504
- if (i && o.value)
505
- try {
506
- await i.close(), o.value = !1;
507
- } catch (d) {
508
- console.error("关闭手写识别服务失败:", d);
509
- }
510
- }
511
- return Q(() => {
512
- e && a();
513
- }), ce(() => {
514
- l();
515
- }), {
516
- recognizerInitialized: o,
517
- recognizerProgress: s
518
- };
519
- }
520
- const ve = "data:image/svg+xml,%3csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2024%2024'%3e%3cpath%20d='M21,11H6.83L10.41,7.41L9,6L3,12L9,18L10.41,16.58L6.83,13H21V11Z'%20/%3e%3c/svg%3e", fe = "data:image/svg+xml,%3csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2024%2024'%3e%3cpath%20d='M19,7V11H5.83L9.41,7.41L8,6L2,12L8,18L9.41,16.58L5.83,13H21V7H19Z'%20/%3e%3c/svg%3e";
521
- function te() {
522
- const e = nt();
523
- function o(a, l) {
524
- var i, d;
525
- a.preventDefault(), (d = (i = a.currentTarget) == null ? void 0 : i.setPointerCapture) == null || d.call(i, a.pointerId), e.start(l);
526
- }
527
- function s() {
528
- e.stop();
529
- }
530
- return Se(() => {
531
- e.stop();
532
- }), {
533
- startRepeat: o,
534
- stopRepeat: s
535
- };
536
- }
537
- const st = { class: "zhk-candidate-list" }, it = ["onClick"], xe = /* @__PURE__ */ I({
538
- __name: "CandidateList",
539
- props: {
540
- candidates: {}
541
- },
542
- emits: ["select"],
543
- setup(e, { emit: o }) {
544
- const s = o;
545
- function a(l) {
546
- s("select", l);
547
- }
548
- return (l, i) => (b(), x("div", st, [
549
- (b(!0), x(L, null, V(l.candidates, (d, f) => (b(), x("button", {
550
- key: `candidate-${f}`,
551
- class: "zhk-candidate-list__item",
552
- onClick: (c) => a(f)
553
- }, D(d), 9, it))), 128))
554
- ]));
555
- }
556
- }), rt = { class: "handwriting-input" }, lt = { class: "handwriting-buttons" }, at = { class: "handwriting-canvas-container" }, ut = { class: "progress-bar" }, dt = { class: "progress-text" }, ct = ["width", "height"], vt = { class: "handwriting-buttons" }, ft = /* @__PURE__ */ I({
557
- __name: "HandwritingInput",
558
- props: {
559
- recognizerInitialized: { type: Boolean },
560
- recognizerProgress: {}
561
- },
562
- emits: ["key", "exit"],
563
- setup(e, { emit: o }) {
564
- const s = e, a = o, l = E(null), i = E(null);
565
- let d = null;
566
- const f = E(!1), { height: c } = he(i);
567
- function y() {
568
- d && d.clearCanvas();
569
- }
570
- function g() {
571
- l.value && (d && d.destroy(), d = new Ye(l.value, {
572
- onDrawEnd: m
573
- }));
574
- }
575
- const u = E([]), { startRepeat: p, stopRepeat: v } = te();
576
- async function m() {
577
- if (!d || d.getStrokeData().length === 0 || f.value)
578
- return;
579
- const z = ue();
580
- if (z) {
581
- f.value = !0;
582
- try {
583
- const t = [...d.getStrokeData()], k = await z.recognize(t);
584
- u.value = k;
585
- } catch (t) {
586
- console.error("识别笔迹失败:", t);
587
- } finally {
588
- f.value = !1;
589
- }
590
- } else
591
- console.warn("手写识别服务不可用");
592
- }
593
- ce(() => {
594
- d && d.destroy();
595
- }), q(() => {
596
- l.value && c.value && s.recognizerInitialized && me(() => {
597
- g();
598
- });
599
- });
600
- function P(z) {
601
- const t = u.value[z];
602
- t && (a("key", { key: t }), u.value = [], y());
603
- }
604
- return (z, t) => (b(), x("div", rt, [
605
- Le(xe, {
606
- candidates: u.value,
607
- onSelect: P
608
- }, null, 8, ["candidates"]),
609
- h("div", {
610
- ref_key: "containerRef",
611
- ref: i,
612
- class: "handwriting-content"
613
- }, [
614
- h("div", lt, [
615
- h("button", {
616
- class: "handwriting-btn handwriting-btn--function",
617
- onPointerdown: t[0] || (t[0] = (k) => n(p)(k, () => a("key", { key: "。" }))),
618
- onPointerup: t[1] || (t[1] = //@ts-ignore
619
- (...k) => n(v) && n(v)(...k)),
620
- onPointerleave: t[2] || (t[2] = //@ts-ignore
621
- (...k) => n(v) && n(v)(...k)),
622
- onPointercancel: t[3] || (t[3] = //@ts-ignore
623
- (...k) => n(v) && n(v)(...k)),
624
- onContextmenu: t[4] || (t[4] = C(() => {
625
- }, ["prevent"]))
626
- }, " 。 ", 32),
627
- h("button", {
628
- class: "handwriting-btn handwriting-btn--function",
629
- onPointerdown: t[5] || (t[5] = (k) => n(p)(k, () => a("key", { key: "?" }))),
630
- onPointerup: t[6] || (t[6] = //@ts-ignore
631
- (...k) => n(v) && n(v)(...k)),
632
- onPointerleave: t[7] || (t[7] = //@ts-ignore
633
- (...k) => n(v) && n(v)(...k)),
634
- onPointercancel: t[8] || (t[8] = //@ts-ignore
635
- (...k) => n(v) && n(v)(...k)),
636
- onContextmenu: t[9] || (t[9] = C(() => {
637
- }, ["prevent"]))
638
- }, " ? ", 32),
639
- h("button", {
640
- class: "handwriting-btn handwriting-btn--function",
641
- onPointerdown: t[10] || (t[10] = (k) => n(p)(k, () => a("key", { key: "!" }))),
642
- onPointerup: t[11] || (t[11] = //@ts-ignore
643
- (...k) => n(v) && n(v)(...k)),
644
- onPointerleave: t[12] || (t[12] = //@ts-ignore
645
- (...k) => n(v) && n(v)(...k)),
646
- onPointercancel: t[13] || (t[13] = //@ts-ignore
647
- (...k) => n(v) && n(v)(...k)),
648
- onContextmenu: t[14] || (t[14] = C(() => {
649
- }, ["prevent"]))
650
- }, " ", 32),
651
- h("button", {
652
- class: "handwriting-btn handwriting-btn--function",
653
- onPointerdown: t[15] || (t[15] = (k) => n(p)(k, () => a("key", { key: "、" }))),
654
- onPointerup: t[16] || (t[16] = //@ts-ignore
655
- (...k) => n(v) && n(v)(...k)),
656
- onPointerleave: t[17] || (t[17] = //@ts-ignore
657
- (...k) => n(v) && n(v)(...k)),
658
- onPointercancel: t[18] || (t[18] = //@ts-ignore
659
- (...k) => n(v) && n(v)(...k)),
660
- onContextmenu: t[19] || (t[19] = C(() => {
661
- }, ["prevent"]))
662
- }, " ", 32)
663
- ]),
664
- h("div", at, [
665
- z.recognizerInitialized ? (b(), x("canvas", {
666
- key: 1,
667
- ref_key: "canvasRef",
668
- ref: l,
669
- class: "handwriting-canvas",
670
- width: n(c),
671
- height: n(c)
672
- }, null, 8, ct)) : (b(), x("div", {
673
- key: 0,
674
- class: "handwriting-loading",
675
- style: se({ width: `${n(c)}px`, height: `${n(c)}px` })
676
- }, [
677
- t[37] || (t[37] = h("div", { class: "loading-text" }, " 正在加载手写识别... ", -1)),
678
- h("div", ut, [
679
- h("div", {
680
- class: "progress-fill",
681
- style: se({ width: `${z.recognizerProgress * 100}%` })
682
- }, null, 4)
683
- ]),
684
- h("div", dt, D(Math.round(z.recognizerProgress * 100)) + "% ", 1)
685
- ], 4))
686
- ]),
687
- h("div", vt, [
688
- h("button", {
689
- class: "handwriting-btn handwriting-btn--function",
690
- onPointerdown: t[20] || (t[20] = (k) => n(p)(k, () => a("key", { key: "delete", isControl: !0 }))),
691
- onPointerup: t[21] || (t[21] = //@ts-ignore
692
- (...k) => n(v) && n(v)(...k)),
693
- onPointerleave: t[22] || (t[22] = //@ts-ignore
694
- (...k) => n(v) && n(v)(...k)),
695
- onPointercancel: t[23] || (t[23] = //@ts-ignore
696
- (...k) => n(v) && n(v)(...k)),
697
- onContextmenu: t[24] || (t[24] = C(() => {
698
- }, ["prevent"]))
699
- }, t[38] || (t[38] = [
700
- h("img", {
701
- src: ve,
702
- alt: "删除"
703
- }, null, -1)
704
- ]), 32),
705
- h("button", {
706
- class: "handwriting-btn handwriting-btn--function",
707
- onClick: t[25] || (t[25] = (k) => a("exit")),
708
- onContextmenu: t[26] || (t[26] = C(() => {
709
- }, ["prevent"]))
710
- }, " 拼音 ", 32),
711
- h("button", {
712
- class: "handwriting-btn handwriting-btn--function",
713
- onPointerdown: t[27] || (t[27] = (k) => n(p)(k, () => a("key", { key: "," }))),
714
- onPointerup: t[28] || (t[28] = //@ts-ignore
715
- (...k) => n(v) && n(v)(...k)),
716
- onPointerleave: t[29] || (t[29] = //@ts-ignore
717
- (...k) => n(v) && n(v)(...k)),
718
- onPointercancel: t[30] || (t[30] = //@ts-ignore
719
- (...k) => n(v) && n(v)(...k)),
720
- onContextmenu: t[31] || (t[31] = C(() => {
721
- }, ["prevent"]))
722
- }, "", 32),
723
- h("button", {
724
- class: "handwriting-btn handwriting-btn--function",
725
- onPointerdown: t[32] || (t[32] = (k) => n(p)(k, () => a("key", { key: "enter", isControl: !0 }))),
726
- onPointerup: t[33] || (t[33] = //@ts-ignore
727
- (...k) => n(v) && n(v)(...k)),
728
- onPointerleave: t[34] || (t[34] = //@ts-ignore
729
- (...k) => n(v) && n(v)(...k)),
730
- onPointercancel: t[35] || (t[35] = //@ts-ignore
731
- (...k) => n(v) && n(v)(...k)),
732
- onContextmenu: t[36] || (t[36] = C(() => {
733
- }, ["prevent"]))
734
- }, t[39] || (t[39] = [
735
- h("img", {
736
- src: fe,
737
- alt: "回车"
738
- }, null, -1)
739
- ]), 32)
740
- ])
741
- ], 512)
742
- ]));
743
- }
744
- }), mt = "data:image/svg+xml,%3csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2024%2024'%3e%3cpath%20d='M6,18H18V16H6M12,8.41L16.59,13L18,11.58L12,5.58L6,11.58L7.41,13L12,8.41Z'%20/%3e%3c/svg%3e", ze = "data:image/svg+xml,%3csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2024%2024'%3e%3cpath%20d='M3%2015H5V19H19V15H21V19C21%2020.1%2020.1%2021%2019%2021H5C3.9%2021%203%2020.1%203%2019V15Z'%20/%3e%3c/svg%3e", pt = "data:image/svg+xml,%3csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2024%2024'%3e%3cpath%20d='M8.59,16.58L13.17,12L8.59,7.41L10,6L16,12L10,18L8.59,16.58Z'%20/%3e%3c/svg%3e", kt = { class: "zhk-selection" }, gt = { class: "zhk-selection__list" }, ht = ["onClick"], yt = /* @__PURE__ */ I({
745
- __name: "CandidateSelection",
746
- props: {
747
- candidates: {}
748
- },
749
- emits: ["select", "close"],
750
- setup(e, { emit: o }) {
751
- const s = o;
752
- function a(d) {
753
- s("select", d);
754
- }
755
- function l() {
756
- s("close");
757
- }
758
- function i(d) {
759
- const f = Array.from(d).length;
760
- return f >= 2 && f <= 3 ? 2 : f >= 4 ? 3 : 1;
761
- }
762
- return (d, f) => (b(), x("div", kt, [
763
- h("div", gt, [
764
- (b(!0), x(L, null, V(d.candidates, (c, y) => (b(), x("div", {
765
- key: y,
766
- class: O(["zhk-selection__text", [`zhk-selection__text--span-${i(c)}`]]),
767
- onClick: (g) => a(y)
768
- }, D(c), 11, ht))), 128))
769
- ]),
770
- h("div", { class: "zhk-selection__func" }, [
771
- h("button", {
772
- class: "zhk-selection__func-btn",
773
- onClick: l
774
- }, " 返回 ")
775
- ])
776
- ]));
777
- }
778
- }), bt = { class: "zhk-candidate" }, wt = { class: "zhk-candidate__container" }, xt = {
779
- key: 0,
780
- class: "zhk-candidate__pinyin"
781
- }, zt = { class: "zhk-candidate__bottom-container" }, Ct = /* @__PURE__ */ I({
782
- __name: "CandidateBar",
783
- props: {
784
- modelValue: {
785
- required: !0
786
- },
787
- modelModifiers: {}
788
- },
789
- emits: /* @__PURE__ */ ie(["key", "input"], ["update:modelValue"]),
790
- setup(e, { expose: o, emit: s }) {
791
- const a = s, l = ke(e, "modelValue");
792
- let i = null;
793
- const d = E(null), f = S(() => {
794
- var u;
795
- return ((u = d.value) == null ? void 0 : u.candidates.map((p) => p.text)) ?? [];
796
- }), c = E(!1);
797
- Q(async () => {
798
- if (i = je(), !i)
799
- throw new Error("未找到拼音引擎实例,请确保已正确注册引擎");
800
- l.value && (d.value = await i.processInput(l.value));
801
- }), ce(() => {
802
- i == null || i.clearInput(), i = null;
803
- }), X(l, async (u) => {
804
- const p = i;
805
- if (p) {
806
- if (u === "") {
807
- p.clearInput(), d.value = null;
808
- return;
809
- }
810
- d.value = await p.processInput(u);
811
- }
812
- });
813
- async function y(u) {
814
- if (!i)
815
- return;
816
- const p = await i.pickCandidate(u);
817
- d.value = p, p.preeditBody || (a("input", p.committed || ""), l.value = "", d.value = null, c.value = !1);
818
- }
819
- o({
820
- handleSelection: y
821
- });
822
- const g = S(() => {
823
- const u = d.value;
824
- return u ? u.preeditHead + u.preeditBody : "";
825
- });
826
- return (u, p) => (b(), x("div", bt, [
827
- h("div", wt, [
828
- g.value ? (b(), x("div", xt, D(g.value), 1)) : W("", !0),
829
- h("div", zt, [
830
- f.value.length > 0 ? (b(), K(xe, {
831
- key: 0,
832
- candidates: f.value,
833
- onSelect: y
834
- }, null, 8, ["candidates"])) : W("", !0),
835
- f.value.length > 0 ? (b(), x("button", {
836
- key: 1,
837
- class: "zhk-candidate__more",
838
- onClick: p[0] || (p[0] = (v) => c.value = !0)
839
- }, p[2] || (p[2] = [
840
- h("img", {
841
- src: pt,
842
- alt: "更多"
843
- }, null, -1)
844
- ]))) : W("", !0)
845
- ])
846
- ]),
847
- c.value ? (b(), K(yt, {
848
- key: 0,
849
- candidates: f.value,
850
- onSelect: y,
851
- onClose: p[1] || (p[1] = (v) => c.value = !1)
852
- }, null, 8, ["candidates"])) : W("", !0)
853
- ]));
854
- }
855
- }), Pt = { class: "zhk-base" }, _t = { class: "zhk-base__row" }, $t = ["onPointerdown"], Et = ["disabled"], St = {
856
- key: 1,
857
- src: mt,
858
- class: "zhk-base__key-icon",
859
- alt: "Shift"
860
- }, Lt = ["onPointerdown"], Rt = { class: "zhk-base__row" }, Tt = { class: "zhk-base__toggle-main" }, Dt = { class: "zhk-base__toggle-sub" }, Mt = /* @__PURE__ */ I({
861
- __name: "KeyboardBase",
862
- props: /* @__PURE__ */ ie({
863
- enableHandwriting: { type: Boolean }
864
- }, {
865
- modelValue: {
866
- default: "en"
867
- },
868
- modelModifiers: {}
869
- }),
870
- emits: /* @__PURE__ */ ie(["key"], ["update:modelValue"]),
871
- setup(e, { emit: o }) {
872
- const s = e, a = o, l = ke(e, "modelValue"), i = S(() => l.value === "en_cap"), d = S(() => l.value === "zh"), f = S(() => d.value ? !0 : i.value);
873
- function c(M, r = !1) {
874
- a("key", { key: M, isControl: r });
875
- }
876
- function y() {
877
- d.value ? l.value = "hand" : l.value = i.value ? "en" : "en_cap";
878
- }
879
- function g() {
880
- l.value = "num";
881
- }
882
- function u() {
883
- l.value = "symbol";
884
- }
885
- const p = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "0"], v = [
886
- ["q", "w", "e", "r", "t", "y", "u", "i", "o", "p"],
887
- ["a", "s", "d", "f", "g", "h", "j", "k", "l"],
888
- ["z", "x", "c", "v", "b", "n", "m"]
889
- ], m = E(""), P = E(null), { startRepeat: z, stopRepeat: t } = te();
890
- function k() {
891
- if (l.value === "zh" && m.value) {
892
- m.value = m.value.slice(0, -1);
893
- return;
894
- }
895
- c("delete", !0);
896
- }
897
- function N() {
898
- var M;
899
- if (l.value === "zh" && m.value) {
900
- (M = P.value) == null || M.handleSelection(0);
901
- return;
902
- }
903
- c(" ");
904
- }
905
- function ne() {
906
- if (l.value === "zh" && m.value) {
907
- c(m.value), m.value = "";
908
- return;
909
- }
910
- c("enter", !0);
911
- }
912
- function U(M) {
913
- if (l.value === "zh") {
914
- m.value += M;
915
- return;
916
- }
917
- const r = i.value ? M.toUpperCase() : M;
918
- c(r);
919
- }
920
- function oe() {
921
- l.value = l.value === "zh" ? "en" : "zh";
922
- }
923
- const $ = S(() => s.enableHandwriting ? "手写" : "-"), R = S(() => !s.enableHandwriting);
924
- return (M, r) => (b(), x("div", Pt, [
925
- h("div", _t, [
926
- l.value === "zh" ? (b(), K(Ct, {
927
- key: 0,
928
- ref_key: "candidateBarRef",
929
- ref: P,
930
- modelValue: m.value,
931
- "onUpdate:modelValue": r[0] || (r[0] = (w) => m.value = w),
932
- onInput: r[1] || (r[1] = (w) => c(w, !1))
933
- }, null, 8, ["modelValue"])) : (b(), x(L, { key: 1 }, V(p, (w, F) => h("button", {
934
- key: `number-${F}`,
935
- class: "zhk-base__key zhk-base__key--letter",
936
- onPointerdown: (_) => n(z)(_, () => U(w)),
937
- onPointerup: r[2] || (r[2] = //@ts-ignore
938
- (..._) => n(t) && n(t)(..._)),
939
- onPointerleave: r[3] || (r[3] = //@ts-ignore
940
- (..._) => n(t) && n(t)(..._)),
941
- onPointercancel: r[4] || (r[4] = //@ts-ignore
942
- (..._) => n(t) && n(t)(..._)),
943
- onContextmenu: r[5] || (r[5] = C(() => {
944
- }, ["prevent"]))
945
- }, D(w), 41, $t)), 64))
946
- ]),
947
- (b(), x(L, null, V(v, (w, F) => h("div", {
948
- key: `row-${F}`,
949
- class: "zhk-base__row"
950
- }, [
951
- F === 2 ? (b(), x("button", {
952
- key: 0,
953
- class: O(["zhk-base__key zhk-base__key--function zhk-base__key--shift", {
954
- "zhk-base__key--active": !d.value && i.value,
955
- "zhk-base__key--disabled": d.value && R.value
956
- }]),
957
- disabled: d.value && R.value,
958
- onClick: y,
959
- onContextmenu: r[6] || (r[6] = C(() => {
960
- }, ["prevent"]))
961
- }, [
962
- d.value ? (b(), x(L, { key: 0 }, [
963
- re(D($.value), 1)
964
- ], 64)) : (b(), x("img", St))
965
- ], 42, Et)) : W("", !0),
966
- (b(!0), x(L, null, V(w, (_, Ce) => (b(), x("button", {
967
- key: `key-${F}-${Ce}`,
968
- class: "zhk-base__key zhk-base__key--letter",
969
- onPointerdown: (A) => n(z)(A, () => U(_)),
970
- onPointerup: r[7] || (r[7] = //@ts-ignore
971
- (...A) => n(t) && n(t)(...A)),
972
- onPointerleave: r[8] || (r[8] = //@ts-ignore
973
- (...A) => n(t) && n(t)(...A)),
974
- onPointercancel: r[9] || (r[9] = //@ts-ignore
975
- (...A) => n(t) && n(t)(...A)),
976
- onContextmenu: r[10] || (r[10] = C(() => {
977
- }, ["prevent"]))
978
- }, D(f.value ? _.toUpperCase() : _), 41, Lt))), 128)),
979
- F === 2 ? (b(), x("button", {
980
- key: 1,
981
- class: "zhk-base__key zhk-base__key--function zhk-base__key--delete",
982
- onPointerdown: r[11] || (r[11] = (_) => n(z)(_, () => k())),
983
- onPointerup: r[12] || (r[12] = //@ts-ignore
984
- (..._) => n(t) && n(t)(..._)),
985
- onPointerleave: r[13] || (r[13] = //@ts-ignore
986
- (..._) => n(t) && n(t)(..._)),
987
- onPointercancel: r[14] || (r[14] = //@ts-ignore
988
- (..._) => n(t) && n(t)(..._)),
989
- onContextmenu: r[15] || (r[15] = C(() => {
990
- }, ["prevent"]))
991
- }, r[39] || (r[39] = [
992
- h("img", {
993
- src: ve,
994
- class: "zhk-base__key-icon",
995
- alt: "Delete"
996
- }, null, -1)
997
- ]), 32)) : W("", !0)
998
- ])), 64)),
999
- h("div", Rt, [
1000
- h("button", {
1001
- class: "zhk-base__key zhk-base__key--function",
1002
- onClick: u,
1003
- onContextmenu: r[16] || (r[16] = C(() => {
1004
- }, ["prevent"]))
1005
- }, " 符 ", 32),
1006
- h("button", {
1007
- class: "zhk-base__key zhk-base__key--function",
1008
- onClick: g,
1009
- onContextmenu: r[17] || (r[17] = C(() => {
1010
- }, ["prevent"]))
1011
- }, " 123 ", 32),
1012
- h("button", {
1013
- class: "zhk-base__key",
1014
- onPointerdown: r[18] || (r[18] = (w) => n(z)(w, () => c(","))),
1015
- onPointerup: r[19] || (r[19] = //@ts-ignore
1016
- (...w) => n(t) && n(t)(...w)),
1017
- onPointerleave: r[20] || (r[20] = //@ts-ignore
1018
- (...w) => n(t) && n(t)(...w)),
1019
- onPointercancel: r[21] || (r[21] = //@ts-ignore
1020
- (...w) => n(t) && n(t)(...w)),
1021
- onContextmenu: r[22] || (r[22] = C(() => {
1022
- }, ["prevent"]))
1023
- }, " , ", 32),
1024
- h("button", {
1025
- class: "zhk-base__key zhk-base__key--space",
1026
- onPointerdown: r[23] || (r[23] = (w) => n(z)(w, () => N())),
1027
- onPointerup: r[24] || (r[24] = //@ts-ignore
1028
- (...w) => n(t) && n(t)(...w)),
1029
- onPointerleave: r[25] || (r[25] = //@ts-ignore
1030
- (...w) => n(t) && n(t)(...w)),
1031
- onPointercancel: r[26] || (r[26] = //@ts-ignore
1032
- (...w) => n(t) && n(t)(...w)),
1033
- onContextmenu: r[27] || (r[27] = C(() => {
1034
- }, ["prevent"]))
1035
- }, r[40] || (r[40] = [
1036
- h("img", {
1037
- src: ze,
1038
- class: "zhk-base__key-icon",
1039
- alt: "Space"
1040
- }, null, -1)
1041
- ]), 32),
1042
- h("button", {
1043
- class: "zhk-base__key",
1044
- onPointerdown: r[28] || (r[28] = (w) => n(z)(w, () => c("。"))),
1045
- onPointerup: r[29] || (r[29] = //@ts-ignore
1046
- (...w) => n(t) && n(t)(...w)),
1047
- onPointerleave: r[30] || (r[30] = //@ts-ignore
1048
- (...w) => n(t) && n(t)(...w)),
1049
- onPointercancel: r[31] || (r[31] = //@ts-ignore
1050
- (...w) => n(t) && n(t)(...w)),
1051
- onContextmenu: r[32] || (r[32] = C(() => {
1052
- }, ["prevent"]))
1053
- }, " 。 ", 32),
1054
- h("button", {
1055
- class: "zhk-base__key zhk-base__key--function",
1056
- onClick: oe,
1057
- onContextmenu: r[33] || (r[33] = C(() => {
1058
- }, ["prevent"]))
1059
- }, [
1060
- h("span", Tt, D(l.value === "zh" ? "中" : "英"), 1),
1061
- h("span", Dt, "/" + D(l.value === "zh" ? "英" : "中"), 1)
1062
- ], 32),
1063
- h("button", {
1064
- class: "zhk-base__key zhk-base__key--function",
1065
- onPointerdown: r[34] || (r[34] = (w) => n(z)(w, () => ne())),
1066
- onPointerup: r[35] || (r[35] = //@ts-ignore
1067
- (...w) => n(t) && n(t)(...w)),
1068
- onPointerleave: r[36] || (r[36] = //@ts-ignore
1069
- (...w) => n(t) && n(t)(...w)),
1070
- onPointercancel: r[37] || (r[37] = //@ts-ignore
1071
- (...w) => n(t) && n(t)(...w)),
1072
- onContextmenu: r[38] || (r[38] = C(() => {
1073
- }, ["prevent"]))
1074
- }, r[41] || (r[41] = [
1075
- h("img", {
1076
- src: fe,
1077
- class: "zhk-base__key-icon",
1078
- alt: "Enter"
1079
- }, null, -1)
1080
- ]), 32)
1081
- ])
1082
- ]));
1083
- }
1084
- }), Ht = { class: "num-keyboard" }, Vt = { class: "num-keyboard__container" }, Bt = { class: "num-keyboard__left" }, It = { class: "num-keyboard__rows" }, At = ["onClick", "onPointerdown"], Kt = {
1085
- key: 1,
1086
- src: ze,
1087
- class: "zhk-base__key-icon",
1088
- alt: "Space"
1089
- }, Wt = { class: "num-keyboard__right" }, Ot = ["onPointerdown"], Nt = ["src", "alt"], Ut = { key: 1 }, Ft = /* @__PURE__ */ I({
1090
- __name: "NumericKeyboard",
1091
- props: {
1092
- keyboardRows: { default: () => Z().numKeys || [
1093
- ["1", "2", "3"],
1094
- ["4", "5", "6"],
1095
- ["7", "8", "9"],
1096
- ["back", "0", "space"]
1097
- ] }
1098
- },
1099
- emits: ["key", "exit"],
1100
- setup(e, { emit: o }) {
1101
- const s = o, a = [
1102
- { key: "delete", icon: ve, text: "", alt: "Delete" },
1103
- { key: ".", icon: "", text: ".", alt: "." },
1104
- { key: "@", icon: "", text: "@", alt: "@" },
1105
- { key: "enter", icon: fe, text: "", alt: "Enter" }
1106
- ];
1107
- function l(g) {
1108
- s("key", { key: g });
1109
- }
1110
- function i(g, u = !0) {
1111
- s("key", { key: g, isControl: u });
1112
- }
1113
- function d() {
1114
- s("exit");
1115
- }
1116
- const { startRepeat: f, stopRepeat: c } = te();
1117
- function y(g, u) {
1118
- g === "back" || (g === "space" && (g = " "), g === "delete" || g === "enter" ? f(u, () => i(g)) : f(u, () => l(g)));
1119
- }
1120
- return (g, u) => (b(), x("div", Ht, [
1121
- h("div", Vt, [
1122
- h("div", Bt, [
1123
- h("div", It, [
1124
- (b(!0), x(L, null, V(g.keyboardRows, (p, v) => (b(), x("div", {
1125
- key: `row-${v}`,
1126
- class: "num-keyboard__row"
1127
- }, [
1128
- (b(!0), x(L, null, V(p, (m, P) => (b(), x("button", {
1129
- key: `key-${v}-${P}`,
1130
- class: O(["num-keyboard__key", {
1131
- "num-keyboard__key--back": m === "back",
1132
- "num-keyboard__key--space": m === "space"
1133
- }]),
1134
- onClick: (z) => m === "back" && d(),
1135
- onPointerdown: (z) => y(m, z),
1136
- onPointerup: u[0] || (u[0] = //@ts-ignore
1137
- (...z) => n(c) && n(c)(...z)),
1138
- onPointerleave: u[1] || (u[1] = //@ts-ignore
1139
- (...z) => n(c) && n(c)(...z)),
1140
- onPointercancel: u[2] || (u[2] = //@ts-ignore
1141
- (...z) => n(c) && n(c)(...z)),
1142
- onContextmenu: u[3] || (u[3] = C(() => {
1143
- }, ["prevent"]))
1144
- }, [
1145
- m === "back" ? (b(), x(L, { key: 0 }, [
1146
- re(" 返回 ")
1147
- ], 64)) : m === "space" ? (b(), x("img", Kt)) : (b(), x(L, { key: 2 }, [
1148
- re(D(m), 1)
1149
- ], 64))
1150
- ], 42, At))), 128))
1151
- ]))), 128))
1152
- ])
1153
- ]),
1154
- h("div", Wt, [
1155
- (b(), x(L, null, V(a, (p, v) => h("button", {
1156
- key: `func-${v}`,
1157
- class: "num-keyboard__key num-keyboard__key--function",
1158
- onPointerdown: (m) => y(p.key, m),
1159
- onPointerup: u[4] || (u[4] = //@ts-ignore
1160
- (...m) => n(c) && n(c)(...m)),
1161
- onPointerleave: u[5] || (u[5] = //@ts-ignore
1162
- (...m) => n(c) && n(c)(...m)),
1163
- onPointercancel: u[6] || (u[6] = //@ts-ignore
1164
- (...m) => n(c) && n(c)(...m)),
1165
- onContextmenu: u[7] || (u[7] = C(() => {
1166
- }, ["prevent"]))
1167
- }, [
1168
- p.icon ? (b(), x("img", {
1169
- key: 0,
1170
- src: p.icon,
1171
- class: "num-keyboard__key-icon",
1172
- alt: p.alt
1173
- }, null, 8, Nt)) : (b(), x("span", Ut, D(p.text), 1))
1174
- ], 40, Ot)), 64))
1175
- ])
1176
- ])
1177
- ]));
1178
- }
1179
- }), Zt = "data:image/svg+xml,%3csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2024%2024'%3e%3cpath%20d='M18,20V10H6V20H18M18,8A2,2%200%200,1%2020,10V20A2,2%200%200,1%2018,22H6C4.89,22%204,21.1%204,20V10A2,2%200%200,1%206,8H15V6A3,3%200%200,0%2012,3A3,3%200%200,0%209,6H7A5,5%200%200,1%2012,1A5,5%200%200,1%2017,6V8H18M12,17A2,2%200%200,1%2010,15A2,2%200%200,1%2012,13A2,2%200%200,1%2014,15A2,2%200%200,1%2012,17Z'%20/%3e%3c/svg%3e", Xt = "data:image/svg+xml,%3csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2024%2024'%3e%3cpath%20d='M12,17C10.89,17%2010,16.1%2010,15C10,13.89%2010.89,13%2012,13A2,2%200%200,1%2014,15A2,2%200%200,1%2012,17M18,20V10H6V20H18M18,8A2,2%200%200,1%2020,10V20A2,2%200%200,1%2018,22H6C4.89,22%204,21.1%204,20V10C4,8.89%204.89,8%206,8H7V6A5,5%200%200,1%2012,1A5,5%200%200,1%2017,6V8H18M12,3A3,3%200%200,0%209,6V8H15V6A3,3%200%200,0%2012,3Z'%20/%3e%3c/svg%3e", Yt = { class: "symbol-keyboard" }, jt = { class: "symbol-keyboard__content" }, Gt = { class: "symbol-keyboard__functions" }, qt = { class: "symbol-keyboard__lang-selector" }, Jt = { class: "symbol-keyboard__control-group" }, Qt = ["src"], en = ["src"], tn = { class: "symbol-keyboard__symbols-container" }, nn = { class: "symbol-keyboard__symbols-grid" }, on = ["onClick", "onPointerdown"], sn = "!@#$%^&*(){}[]<>/\\|:;\"',.?+-=_~`€£¥₹©®™°", rn = "!@#¥%…&*(){}[]<>/\|:;"',。?+-=_~·€£¥₹©®™°", ln = /* @__PURE__ */ I({
1180
- __name: "SymbolKeyboard",
1181
- emits: ["key", "exit"],
1182
- setup(e, { emit: o }) {
1183
- const s = o, a = E("en"), l = S(() => a.value === "zh" ? rn : sn), i = E(!1), { startRepeat: d, stopRepeat: f } = te();
1184
- function c(v, m) {
1185
- i.value && d(m, () => y(v));
1186
- }
1187
- function y(v) {
1188
- s("key", { key: v }), i.value || s("exit");
1189
- }
1190
- function g() {
1191
- s("exit");
1192
- }
1193
- function u(v) {
1194
- a.value = v;
1195
- }
1196
- function p() {
1197
- i.value = !i.value;
1198
- }
1199
- return (v, m) => (b(), x("div", Yt, [
1200
- h("div", jt, [
1201
- h("div", Gt, [
1202
- h("div", qt, [
1203
- h("button", {
1204
- class: O(["symbol-keyboard__lang-btn", { "symbol-keyboard__lang-btn--active": a.value === "zh" }]),
1205
- onClick: m[0] || (m[0] = (P) => u("zh")),
1206
- onContextmenu: m[1] || (m[1] = C(() => {
1207
- }, ["prevent"]))
1208
- }, " 中文 ", 34),
1209
- h("button", {
1210
- class: O(["symbol-keyboard__lang-btn", { "symbol-keyboard__lang-btn--active": a.value === "en" }]),
1211
- onClick: m[2] || (m[2] = (P) => u("en")),
1212
- onContextmenu: m[3] || (m[3] = C(() => {
1213
- }, ["prevent"]))
1214
- }, " 英文 ", 34)
1215
- ]),
1216
- h("div", Jt, [
1217
- h("button", {
1218
- class: O(["symbol-keyboard__key symbol-keyboard__key--function symbol-keyboard__key--lock", { "symbol-keyboard__key--locked": i.value }]),
1219
- onClick: p,
1220
- onContextmenu: m[4] || (m[4] = C(() => {
1221
- }, ["prevent"]))
1222
- }, [
1223
- i.value ? (b(), x("img", {
1224
- key: 1,
1225
- src: n(Xt),
1226
- alt: "Lock closed"
1227
- }, null, 8, en)) : (b(), x("img", {
1228
- key: 0,
1229
- src: n(Zt),
1230
- alt: "Lock open"
1231
- }, null, 8, Qt))
1232
- ], 34),
1233
- h("button", {
1234
- class: "symbol-keyboard__key symbol-keyboard__key--function symbol-keyboard__key--back",
1235
- onClick: g,
1236
- onContextmenu: m[5] || (m[5] = C(() => {
1237
- }, ["prevent"]))
1238
- }, " 返回 ", 32)
1239
- ])
1240
- ]),
1241
- h("div", tn, [
1242
- h("div", nn, [
1243
- (b(!0), x(L, null, V(l.value, (P, z) => (b(), x("button", {
1244
- key: `key-${z}`,
1245
- class: "symbol-keyboard__key",
1246
- onClick: (t) => !i.value && y(P),
1247
- onPointerdown: (t) => c(P, t),
1248
- onPointerup: m[6] || (m[6] = //@ts-ignore
1249
- (...t) => n(f) && n(f)(...t)),
1250
- onPointerleave: m[7] || (m[7] = //@ts-ignore
1251
- (...t) => n(f) && n(f)(...t)),
1252
- onPointercancel: m[8] || (m[8] = //@ts-ignore
1253
- (...t) => n(f) && n(f)(...t)),
1254
- onContextmenu: m[9] || (m[9] = C(() => {
1255
- }, ["prevent"]))
1256
- }, D(P), 41, on))), 128))
1257
- ])
1258
- ])
1259
- ])
1260
- ]));
1261
- }
1262
- }), an = {
1263
- key: 0,
1264
- class: "zhk__disabled-overlay"
1265
- }, un = /* @__PURE__ */ I({
1266
- __name: "ZhKeyboard",
1267
- props: {
1268
- /**
1269
- * 默认的键盘模式
1270
- */
1271
- defaultMode: {
1272
- type: String,
1273
- default: () => Z().defaultMode ?? "en"
1274
- },
1275
- /**
1276
- * 是否启用手写输入
1277
- */
1278
- enableHandwriting: {
1279
- type: Boolean,
1280
- default: () => Z().enableHandwriting ?? !1
1281
- },
1282
- /**
1283
- * 键盘定位模式
1284
- * @default 'static'
1285
- */
1286
- position: {
1287
- type: String,
1288
- default: () => Z().position ?? "static"
1289
- },
1290
- /**
1291
- * 浮动模式下键盘与输入框的距离
1292
- * @default 10
1293
- */
1294
- floatMarginTop: {
1295
- type: Number,
1296
- default: () => Z().floatMarginTop ?? 0
1297
- },
1298
- /**
1299
- * 当没有input获得焦点时是否禁用键盘
1300
- * @default true
1301
- */
1302
- disableWhenNoFocus: {
1303
- type: Boolean,
1304
- default: () => Z().disableWhenNoFocus ?? !0
1305
- },
1306
- /**
1307
- * 数字键盘的行配置
1308
- */
1309
- numKeys: {
1310
- type: Array || void 0
1311
- }
1312
- },
1313
- emits: ["key"],
1314
- setup(e, { emit: o }) {
1315
- const s = e, a = o, l = E(s.defaultMode), i = E(s.defaultMode), d = E([]), f = E(!1), c = E(null), y = E(null), { recognizerInitialized: g, recognizerProgress: u } = ot(s.enableHandwriting);
1316
- X(l, ($, R) => {
1317
- $ !== R && (i.value = R);
1318
- });
1319
- const p = Ze(), v = S(() => p.value && de(p.value) ? p.value : null), m = S(() => s.position === "static" || !!(p.value && de(p.value))), { height: P } = he(y);
1320
- q(() => {
1321
- if (v.value) {
1322
- const $ = v.value.dataset.inputmode;
1323
- $ && (l.value = $);
1324
- }
1325
- });
1326
- const z = S(() => s.disableWhenNoFocus === !1 ? !1 : !v.value);
1327
- function t() {
1328
- if (!P.value)
1329
- return;
1330
- const $ = Ge(
1331
- v.value,
1332
- y.value,
1333
- s.position,
1334
- s.floatMarginTop
1335
- );
1336
- c.value = $;
1337
- }
1338
- q(t);
1339
- const k = Ke(t, 100);
1340
- J(window, "scroll", k, { passive: !0 }), J(window, "resize", k, { passive: !0 });
1341
- function N($) {
1342
- if ($.isControl) {
1343
- switch ($.key) {
1344
- case "delete":
1345
- et(v.value);
1346
- break;
1347
- case "more":
1348
- f.value = !0;
1349
- break;
1350
- }
1351
- return;
1352
- } else
1353
- ne($.key);
1354
- a("key", $);
1355
- }
1356
- function ne($) {
1357
- Qe(v.value, $);
1358
- }
1359
- function U() {
1360
- l.value === "hand" ? i.value = "zh" : ["num", "symbol"].includes(i.value) && (i.value = s.defaultMode), l.value = i.value;
1361
- }
1362
- function oe($) {
1363
- d.value = $;
1364
- }
1365
- return ($, R) => Re((b(), x("div", {
1366
- ref_key: "keyboardRef",
1367
- ref: y,
1368
- class: O(["zhk", {
1369
- "zhk--floating": e.position === "float",
1370
- "zhk--bottom": e.position === "bottom",
1371
- "zhk--disabled": z.value
1372
- }]),
1373
- style: se({
1374
- "--keyboard-height": `${n(P)}px`,
1375
- ...c.value
1376
- }),
1377
- onMousedown: R[1] || (R[1] = C(() => {
1378
- }, ["prevent"]))
1379
- }, [
1380
- z.value || !m.value || !n(P) ? (b(), x("div", an, R[2] || (R[2] = [
1381
- h("span", null, "请选择输入框以启用键盘", -1)
1382
- ]))) : (b(), x(L, { key: 1 }, [
1383
- l.value === "hand" ? (b(), K(ft, {
1384
- key: 0,
1385
- "recognizer-initialized": n(g),
1386
- "recognizer-progress": n(u),
1387
- onKey: N,
1388
- onExit: U,
1389
- onRecognize: oe
1390
- }, null, 8, ["recognizer-initialized", "recognizer-progress"])) : l.value === "num" ? (b(), K(Ft, {
1391
- key: 1,
1392
- "keyboard-rows": e.numKeys,
1393
- onKey: N,
1394
- onExit: U
1395
- }, null, 8, ["keyboard-rows"])) : l.value === "symbol" ? (b(), K(ln, {
1396
- key: 2,
1397
- onKey: N,
1398
- onExit: U
1399
- })) : l.value === "en" || l.value === "en_cap" || l.value === "zh" ? (b(), K(Mt, {
1400
- key: 3,
1401
- modelValue: l.value,
1402
- "onUpdate:modelValue": R[0] || (R[0] = (M) => l.value = M),
1403
- "enable-handwriting": e.enableHandwriting,
1404
- onKey: N
1405
- }, null, 8, ["modelValue", "enable-handwriting"])) : W("", !0)
1406
- ], 64))
1407
- ], 38)), [
1408
- [Te, m.value]
1409
- ]);
1410
- }
1411
- }), kn = {
1412
- install: (e) => {
1413
- e.component("ZhKeyboard", un);
1414
- }
1415
- };
1416
- export {
1417
- Ye as CanvasDrawer,
1418
- un as ZhKeyboard,
1419
- Ge as calculateKeyboardPosition,
1420
- nt as createKeyRepeater,
1421
- kn as default,
1422
- et as delToInputElement,
1423
- ue as getHandwritingRecognizer,
1424
- pn as getInputElement,
1425
- Z as getKeyboardConfig,
1426
- je as getPinyinEngine,
1427
- de as isInputElement,
1428
- tt as moveCursor,
1429
- fn as registerHandwritingRecognizer,
1430
- mn as registerPinyinEngine,
1431
- vn as setKeyboardConfig,
1432
- Qe as writeToInputElement
1433
- };
1434
- //# sourceMappingURL=zh-keyboard-vue.js.map
10
+ var te = (e) => e != null, H = Object.prototype.toString, ne = (e) => H.call(e) === "[object Object]", U = () => {};
11
+ function re(e, t) {
12
+ function n(...n) {
13
+ return new Promise((r, i) => {
14
+ Promise.resolve(e(() => t.apply(this, n), {
15
+ fn: t,
16
+ thisArg: this,
17
+ args: n
18
+ })).then(r).catch(i);
19
+ });
20
+ }
21
+ return n;
22
+ }
23
+ function ie(e, t = {}) {
24
+ let n, r, i = U, a = (e) => {
25
+ clearTimeout(e), i(), i = U;
26
+ }, o;
27
+ return (s) => {
28
+ let c = w(e), l = w(t.maxWait);
29
+ return n && a(n), c <= 0 || l !== void 0 && l <= 0 ? (r &&= (a(r), null), Promise.resolve(s())) : new Promise((e, u) => {
30
+ i = t.rejectOnCancel ? u : e, o = s, l && !r && (r = setTimeout(() => {
31
+ n && a(n), r = null, e(o());
32
+ }, l)), n = setTimeout(() => {
33
+ r && a(r), r = null, e(s());
34
+ }, c);
35
+ });
36
+ };
37
+ }
38
+ function W(e) {
39
+ return Array.isArray(e) ? e : [e];
40
+ }
41
+ function ae(e) {
42
+ return e || l();
43
+ }
44
+ function oe(e, t = 200, n = {}) {
45
+ return re(ie(t, n), e);
46
+ }
47
+ function se(e, t = !0, n) {
48
+ ae(n) ? g(e, n) : t ? e() : f(e);
49
+ }
50
+ function ce(e, t, n) {
51
+ return O(e, t, {
52
+ ...n,
53
+ immediate: !0
54
+ });
55
+ }
56
+ //#endregion
57
+ //#region ../../node_modules/.pnpm/@vueuse+core@13.1.0_vue@3.5.13_typescript@5.8.3_/node_modules/@vueuse/core/index.mjs
58
+ var G = V ? window : void 0;
59
+ V && window.document, V && window.navigator, V && window.location;
60
+ function K(e) {
61
+ let t = w(e);
62
+ return t?.$el ?? t;
63
+ }
64
+ function q(...e) {
65
+ let n = [], r = () => {
66
+ n.forEach((e) => e()), n.length = 0;
67
+ }, i = (e, t, n, r) => (e.addEventListener(t, n, r), () => e.removeEventListener(t, n, r)), a = t(() => {
68
+ let t = W(w(e[0])).filter((e) => e != null);
69
+ return t.every((e) => typeof e != "string") ? t : void 0;
70
+ }), o = ce(() => [
71
+ a.value?.map((e) => K(e)) ?? [G].filter((e) => e != null),
72
+ W(w(a.value ? e[1] : e[0])),
73
+ W(T(a.value ? e[2] : e[1])),
74
+ w(a.value ? e[3] : e[2])
75
+ ], ([e, t, a, o]) => {
76
+ if (r(), !e?.length || !t?.length || !a?.length) return;
77
+ let s = ne(o) ? { ...o } : o;
78
+ n.push(...e.flatMap((e) => t.flatMap((t) => a.map((n) => i(e, t, n, s)))));
79
+ }, { flush: "post" });
80
+ return B(r), () => {
81
+ o(), r();
82
+ };
83
+ }
84
+ function le() {
85
+ let e = S(!1), t = l();
86
+ return t && g(() => {
87
+ e.value = !0;
88
+ }, t), e;
89
+ }
90
+ function J(e) {
91
+ let n = le();
92
+ return t(() => (n.value, !!e()));
93
+ }
94
+ function ue(e, n, r = {}) {
95
+ let { window: i = G, ...a } = r, o, s = J(() => i && "MutationObserver" in i), c = () => {
96
+ o &&= (o.disconnect(), void 0);
97
+ }, l = t(() => {
98
+ let t = W(w(e)).map(K).filter(te);
99
+ return new Set(t);
100
+ }), u = O(() => l.value, (e) => {
101
+ c(), s.value && e.size && (o = new MutationObserver(n), e.forEach((e) => o.observe(e, a)));
102
+ }, {
103
+ immediate: !0,
104
+ flush: "post"
105
+ }), d = () => o?.takeRecords(), f = () => {
106
+ u(), c();
107
+ };
108
+ return B(f), {
109
+ isSupported: s,
110
+ stop: f,
111
+ takeRecords: d
112
+ };
113
+ }
114
+ function de(e, t, n = {}) {
115
+ let { window: r = G, document: i = r?.document, flush: a = "sync" } = n;
116
+ if (!r || !i) return U;
117
+ let o, s = (e) => {
118
+ o?.(), o = e;
119
+ }, c = k(() => {
120
+ let n = K(e);
121
+ if (n) {
122
+ let { stop: e } = ue(i, (e) => {
123
+ e.map((e) => [...e.removedNodes]).flat().some((e) => e === n || e.contains(n)) && t(e);
124
+ }, {
125
+ window: r,
126
+ childList: !0,
127
+ subtree: !0
128
+ });
129
+ s(e);
130
+ }
131
+ }, { flush: a }), l = () => {
132
+ c(), s();
133
+ };
134
+ return B(l), l;
135
+ }
136
+ function fe(e = {}) {
137
+ let { window: t = G, deep: n = !0, triggerOnRemoval: r = !1 } = e, i = e.document ?? t?.document, a = () => {
138
+ let e = i?.activeElement;
139
+ if (n) for (; e?.shadowRoot;) e = e?.shadowRoot?.activeElement;
140
+ return e;
141
+ }, o = S(), s = () => {
142
+ o.value = a();
143
+ };
144
+ if (t) {
145
+ let e = {
146
+ capture: !0,
147
+ passive: !0
148
+ };
149
+ q(t, "blur", (e) => {
150
+ e.relatedTarget === null && s();
151
+ }, e), q(t, "focus", s, e);
152
+ }
153
+ return r && de(o, s, { document: i }), s(), o;
154
+ }
155
+ function pe(e, n, r = {}) {
156
+ let { window: i = G, ...a } = r, o, s = J(() => i && "ResizeObserver" in i), c = () => {
157
+ o &&= (o.disconnect(), void 0);
158
+ }, l = O(t(() => {
159
+ let t = w(e);
160
+ return Array.isArray(t) ? t.map((e) => K(e)) : [K(t)];
161
+ }), (e) => {
162
+ if (c(), s.value && i) {
163
+ o = new ResizeObserver(n);
164
+ for (let t of e) t && o.observe(t, a);
165
+ }
166
+ }, {
167
+ immediate: !0,
168
+ flush: "post"
169
+ }), u = () => {
170
+ c(), l();
171
+ };
172
+ return B(u), {
173
+ isSupported: s,
174
+ stop: u
175
+ };
176
+ }
177
+ function Y(e, n = {
178
+ width: 0,
179
+ height: 0
180
+ }, r = {}) {
181
+ let { window: i = G, box: a = "content-box" } = r, o = t(() => (K(e)?.namespaceURI)?.includes("svg")), s = S(n.width), c = S(n.height), { stop: l } = pe(e, ([t]) => {
182
+ let n = a === "border-box" ? t.borderBoxSize : a === "content-box" ? t.contentBoxSize : t.devicePixelContentBoxSize;
183
+ if (i && o.value) {
184
+ let t = K(e);
185
+ if (t) {
186
+ let e = t.getBoundingClientRect();
187
+ s.value = e.width, c.value = e.height;
188
+ }
189
+ } else if (n) {
190
+ let e = W(n);
191
+ s.value = e.reduce((e, { inlineSize: t }) => e + t, 0), c.value = e.reduce((e, { blockSize: t }) => e + t, 0);
192
+ } else s.value = t.contentRect.width, c.value = t.contentRect.height;
193
+ }, r);
194
+ se(() => {
195
+ let t = K(e);
196
+ t && (s.value = "offsetWidth" in t ? t.offsetWidth : n.width, c.value = "offsetHeight" in t ? t.offsetHeight : n.height);
197
+ });
198
+ let u = O(() => K(e), (e) => {
199
+ s.value = e ? n.width : 0, c.value = e ? n.height : 0;
200
+ });
201
+ function d() {
202
+ l(), u();
203
+ }
204
+ return {
205
+ width: s,
206
+ height: c,
207
+ stop: d
208
+ };
209
+ }
210
+ //#endregion
211
+ //#region src/utils/useHandwritingRecognizer.ts
212
+ function me(e = !1) {
213
+ let t = b(!1), n = b(0);
214
+ async function r() {
215
+ let e = I();
216
+ if (e) try {
217
+ t.value = await e.initialize({ onProgress: (e) => {
218
+ n.value = e;
219
+ } });
220
+ } catch (e) {
221
+ console.error("初始化手写识别服务失败:", e), t.value = !1;
222
+ }
223
+ else console.warn("未注册手写识别服务"), t.value = !1;
224
+ }
225
+ async function i() {
226
+ let e = I();
227
+ if (e && t.value) try {
228
+ await e.close(), t.value = !1;
229
+ } catch (e) {
230
+ console.error("关闭手写识别服务失败:", e);
231
+ }
232
+ }
233
+ return g(() => {
234
+ e && r();
235
+ }), v(() => {
236
+ i();
237
+ }), {
238
+ recognizerInitialized: t,
239
+ recognizerProgress: n
240
+ };
241
+ }
242
+ //#endregion
243
+ //#region src/assets/icons/keyboard-backspace.svg
244
+ var he = "data:image/svg+xml,%3csvg%20t='1777011781316'%20class='icon'%20viewBox='0%200%201439%201024'%20version='1.1'%20xmlns='http://www.w3.org/2000/svg'%20p-id='5887'%20width='200'%20height='200'%3e%3cpath%20d='M1283.03672%200.000187H465.243153a158.045778%20158.045778%200%200%200-122.329921%2057.680486L24.083875%20440.475014c-0.622227%200.68445-1.182232%201.431123-1.742237%202.177796A115.672087%20115.672087%200%200%200%200.003672%20511.906728a118.658779%20118.658779%200%200%200%2026.818004%2074.667297l316.713783%20380.492099a158.232446%20158.232446%200%200%200%20121.707694%2056.933814H1283.03672a156.303541%20156.303541%200%200%200%20156.05465-156.116873V156.054837A156.241318%20156.241318%200%200%200%201283.03672%200.000187z%20m-257.477728%20689.863598a47.538179%2047.538179%200%200%201-33.600284%2013.937896%2047.662624%2047.662624%200%200%201-33.662506-13.937896L847.72638%20579.293963l-110.569822%20110.569822a47.911515%2047.911515%200%200%201-33.724729%2013.937896%2047.662624%2047.662624%200%200%201-33.662506-81.325131l110.383154-110.569822-110.569822-110.569822a47.662624%2047.662624%200%200%201%200-67.387235%2047.600402%2047.600402%200%200%201%2067.325012%200l110.632045%20110.632045%20110.569822-110.632045A47.625291%2047.625291%200%200%201%201025.434546%20401.336906l-110.383153%20110.569822%20110.569821%20110.569822a47.662624%2047.662624%200%200%201-0.062222%2067.387235z'%20fill='%232C2C2C'%20p-id='5888'%3e%3c/path%3e%3c/svg%3e", ge = "data:image/svg+xml,%3csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2024%2024'%3e%3cpath%20d='M19,7V11H5.83L9.41,7.41L8,6L2,12L8,18L9.41,16.58L5.83,13H21V7H19Z'%20/%3e%3c/svg%3e";
245
+ //#endregion
246
+ //#region src/hooks/useKeyRepeater.ts
247
+ function X() {
248
+ let e = P();
249
+ function t(t, n) {
250
+ t.preventDefault(), t.currentTarget?.setPointerCapture?.(t.pointerId), e.start(n);
251
+ }
252
+ function n() {
253
+ e.stop();
254
+ }
255
+ return h(() => {
256
+ e.stop();
257
+ }), {
258
+ startRepeat: t,
259
+ stopRepeat: n
260
+ };
261
+ }
262
+ //#endregion
263
+ //#region src/components/CandidateList.vue?vue&type=script&setup=true&lang.ts
264
+ var _e = { class: "zhk-candidate-list" }, ve = ["onClick"], Z = /* @__PURE__ */ c({
265
+ __name: "CandidateList",
266
+ props: { candidates: {} },
267
+ emits: ["select"],
268
+ setup(t, { emit: n }) {
269
+ let r = n;
270
+ function a(e) {
271
+ r("select", e);
272
+ }
273
+ return (t, n) => (y(), i("div", _e, [(y(!0), i(e, null, x(t.candidates, (e, t) => (y(), i("button", {
274
+ key: `candidate-${t}`,
275
+ class: "zhk-candidate-list__item",
276
+ onClick: (e) => a(t)
277
+ }, C(e), 9, ve))), 128))]));
278
+ }
279
+ }), ye = { class: "handwriting-input" }, be = { class: "handwriting-content" }, xe = { class: "handwriting-buttons" }, Se = { class: "handwriting-canvas-container" }, Ce = {
280
+ key: 0,
281
+ class: "handwriting-loading"
282
+ }, we = { class: "progress-bar" }, Te = { class: "progress-text" }, Ee = { class: "handwriting-buttons" }, De = /* @__PURE__ */ c({
283
+ __name: "HandwritingInput",
284
+ props: {
285
+ recognizerInitialized: { type: Boolean },
286
+ recognizerProgress: {}
287
+ },
288
+ emits: ["key", "exit"],
289
+ setup(e, { emit: t }) {
290
+ let n = e, r = t, o = b(null), c = null, l = b(!1), { width: u, height: d } = Y(o);
291
+ function p() {
292
+ c && c.clearCanvas();
293
+ }
294
+ function h() {
295
+ o.value && (c && c.destroy(), o.value.width = u.value, o.value.height = d.value, c = new M(o.value, { onDrawEnd: S }));
296
+ }
297
+ let g = b([]), { startRepeat: _, stopRepeat: x } = X();
298
+ async function S() {
299
+ if (!c || c.getStrokeData().length === 0 || l.value) return;
300
+ let e = I();
301
+ if (e) {
302
+ l.value = !0;
303
+ try {
304
+ let t = [...c.getStrokeData()];
305
+ g.value = await e.recognize(t);
306
+ } catch (e) {
307
+ console.error("识别笔迹失败:", e);
308
+ } finally {
309
+ l.value = !1;
310
+ }
311
+ } else console.warn("手写识别服务不可用");
312
+ }
313
+ v(() => {
314
+ c && c.destroy();
315
+ }), k(() => {
316
+ o.value && (u.value || d.value) && n.recognizerInitialized && f(() => {
317
+ h();
318
+ });
319
+ });
320
+ function w(e) {
321
+ let t = g.value[e];
322
+ t && (r("key", { key: t }), g.value = [], p());
323
+ }
324
+ return (e, t) => (y(), i("div", ye, [s(Z, {
325
+ candidates: g.value,
326
+ onSelect: w
327
+ }, null, 8, ["candidates"]), a("div", be, [
328
+ a("div", xe, [
329
+ a("button", {
330
+ class: "handwriting-btn handwriting-btn--function",
331
+ onPointerdown: t[0] ||= (e) => T(_)(e, () => r("key", { key: "。" })),
332
+ onPointerup: t[1] ||= (...e) => T(x) && T(x)(...e),
333
+ onPointerleave: t[2] ||= (...e) => T(x) && T(x)(...e),
334
+ onPointercancel: t[3] ||= (...e) => T(x) && T(x)(...e),
335
+ onContextmenu: t[4] ||= j(() => {}, ["prevent"])
336
+ }, " 。 ", 32),
337
+ a("button", {
338
+ class: "handwriting-btn handwriting-btn--function",
339
+ onPointerdown: t[5] ||= (e) => T(_)(e, () => r("key", { key: "?" })),
340
+ onPointerup: t[6] ||= (...e) => T(x) && T(x)(...e),
341
+ onPointerleave: t[7] ||= (...e) => T(x) && T(x)(...e),
342
+ onPointercancel: t[8] ||= (...e) => T(x) && T(x)(...e),
343
+ onContextmenu: t[9] ||= j(() => {}, ["prevent"])
344
+ }, " ? ", 32),
345
+ a("button", {
346
+ class: "handwriting-btn handwriting-btn--function",
347
+ onPointerdown: t[10] ||= (e) => T(_)(e, () => r("key", { key: "!" })),
348
+ onPointerup: t[11] ||= (...e) => T(x) && T(x)(...e),
349
+ onPointerleave: t[12] ||= (...e) => T(x) && T(x)(...e),
350
+ onPointercancel: t[13] ||= (...e) => T(x) && T(x)(...e),
351
+ onContextmenu: t[14] ||= j(() => {}, ["prevent"])
352
+ }, " ! ", 32),
353
+ a("button", {
354
+ class: "handwriting-btn handwriting-btn--function",
355
+ onPointerdown: t[15] ||= (e) => T(_)(e, () => r("key", { key: "、" })),
356
+ onPointerup: t[16] ||= (...e) => T(x) && T(x)(...e),
357
+ onPointerleave: t[17] ||= (...e) => T(x) && T(x)(...e),
358
+ onPointercancel: t[18] ||= (...e) => T(x) && T(x)(...e),
359
+ onContextmenu: t[19] ||= j(() => {}, ["prevent"])
360
+ }, " 、 ", 32)
361
+ ]),
362
+ a("div", Se, [e.recognizerInitialized ? (y(), i("canvas", {
363
+ key: 1,
364
+ ref_key: "canvasRef",
365
+ ref: o,
366
+ class: "handwriting-canvas"
367
+ }, null, 512)) : (y(), i("div", Ce, [
368
+ t[37] ||= a("div", { class: "loading-text" }, " 正在加载手写识别... ", -1),
369
+ a("div", we, [a("div", {
370
+ class: "progress-fill",
371
+ style: m({ width: `${e.recognizerProgress * 100}%` })
372
+ }, null, 4)]),
373
+ a("div", Te, C(Math.round(e.recognizerProgress * 100)) + "% ", 1)
374
+ ]))]),
375
+ a("div", Ee, [
376
+ a("button", {
377
+ class: "handwriting-btn handwriting-btn--function",
378
+ onPointerdown: t[20] ||= (e) => T(_)(e, () => r("key", {
379
+ key: "delete",
380
+ isControl: !0
381
+ })),
382
+ onPointerup: t[21] ||= (...e) => T(x) && T(x)(...e),
383
+ onPointerleave: t[22] ||= (...e) => T(x) && T(x)(...e),
384
+ onPointercancel: t[23] ||= (...e) => T(x) && T(x)(...e),
385
+ onContextmenu: t[24] ||= j(() => {}, ["prevent"])
386
+ }, t[38] ||= [a("img", {
387
+ src: "data:image/svg+xml,%3csvg%20t='1777011781316'%20class='icon'%20viewBox='0%200%201439%201024'%20version='1.1'%20xmlns='http://www.w3.org/2000/svg'%20p-id='5887'%20width='200'%20height='200'%3e%3cpath%20d='M1283.03672%200.000187H465.243153a158.045778%20158.045778%200%200%200-122.329921%2057.680486L24.083875%20440.475014c-0.622227%200.68445-1.182232%201.431123-1.742237%202.177796A115.672087%20115.672087%200%200%200%200.003672%20511.906728a118.658779%20118.658779%200%200%200%2026.818004%2074.667297l316.713783%20380.492099a158.232446%20158.232446%200%200%200%20121.707694%2056.933814H1283.03672a156.303541%20156.303541%200%200%200%20156.05465-156.116873V156.054837A156.241318%20156.241318%200%200%200%201283.03672%200.000187z%20m-257.477728%20689.863598a47.538179%2047.538179%200%200%201-33.600284%2013.937896%2047.662624%2047.662624%200%200%201-33.662506-13.937896L847.72638%20579.293963l-110.569822%20110.569822a47.911515%2047.911515%200%200%201-33.724729%2013.937896%2047.662624%2047.662624%200%200%201-33.662506-81.325131l110.383154-110.569822-110.569822-110.569822a47.662624%2047.662624%200%200%201%200-67.387235%2047.600402%2047.600402%200%200%201%2067.325012%200l110.632045%20110.632045%20110.569822-110.632045A47.625291%2047.625291%200%200%201%201025.434546%20401.336906l-110.383153%20110.569822%20110.569821%20110.569822a47.662624%2047.662624%200%200%201-0.062222%2067.387235z'%20fill='%232C2C2C'%20p-id='5888'%3e%3c/path%3e%3c/svg%3e",
388
+ alt: "删除"
389
+ }, null, -1)], 32),
390
+ a("button", {
391
+ class: "handwriting-btn handwriting-btn--function",
392
+ onClick: t[25] ||= (e) => r("exit"),
393
+ onContextmenu: t[26] ||= j(() => {}, ["prevent"])
394
+ }, " 拼音 ", 32),
395
+ a("button", {
396
+ class: "handwriting-btn handwriting-btn--function",
397
+ onPointerdown: t[27] ||= (e) => T(_)(e, () => r("key", { key: "," })),
398
+ onPointerup: t[28] ||= (...e) => T(x) && T(x)(...e),
399
+ onPointerleave: t[29] ||= (...e) => T(x) && T(x)(...e),
400
+ onPointercancel: t[30] ||= (...e) => T(x) && T(x)(...e),
401
+ onContextmenu: t[31] ||= j(() => {}, ["prevent"])
402
+ }, " , ", 32),
403
+ a("button", {
404
+ class: "handwriting-btn handwriting-btn--function",
405
+ onPointerdown: t[32] ||= (e) => T(_)(e, () => r("key", {
406
+ key: "enter",
407
+ isControl: !0
408
+ })),
409
+ onPointerup: t[33] ||= (...e) => T(x) && T(x)(...e),
410
+ onPointerleave: t[34] ||= (...e) => T(x) && T(x)(...e),
411
+ onPointercancel: t[35] ||= (...e) => T(x) && T(x)(...e),
412
+ onContextmenu: t[36] ||= j(() => {}, ["prevent"])
413
+ }, t[39] ||= [a("img", {
414
+ src: "data:image/svg+xml,%3csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2024%2024'%3e%3cpath%20d='M19,7V11H5.83L9.41,7.41L8,6L2,12L8,18L9.41,16.58L5.83,13H21V7H19Z'%20/%3e%3c/svg%3e",
415
+ alt: "回车"
416
+ }, null, -1)], 32)
417
+ ])
418
+ ])]));
419
+ }
420
+ }), Oe = "data:image/svg+xml,%3csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2024%2024'%3e%3cpath%20d='M6,18H18V16H6M12,8.41L16.59,13L18,11.58L12,5.58L6,11.58L7.41,13L12,8.41Z'%20/%3e%3c/svg%3e", ke = "data:image/svg+xml,%3csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2024%2024'%3e%3cpath%20d='M3%2015H5V19H19V15H21V19C21%2020.1%2020.1%2021%2019%2021H5C3.9%2021%203%2020.1%203%2019V15Z'%20/%3e%3c/svg%3e", Ae = { class: "zhk-selection" }, je = { class: "zhk-selection__list" }, Me = ["onClick"], Ne = /* @__PURE__ */ c({
421
+ __name: "CandidateSelection",
422
+ props: { candidates: {} },
423
+ emits: ["select", "close"],
424
+ setup(t, { emit: n }) {
425
+ let r = n;
426
+ function o(e) {
427
+ r("select", e);
428
+ }
429
+ function s() {
430
+ r("close");
431
+ }
432
+ function c(e) {
433
+ let t = Array.from(e).length;
434
+ return t >= 2 && t <= 3 ? 2 : t >= 4 ? 3 : 1;
435
+ }
436
+ return (t, n) => (y(), i("div", Ae, [a("div", je, [(y(!0), i(e, null, x(t.candidates, (e, t) => (y(), i("div", {
437
+ key: t,
438
+ class: p(["zhk-selection__text", [`zhk-selection__text--span-${c(e)}`]]),
439
+ onClick: (e) => o(t)
440
+ }, C(e), 11, Me))), 128))]), a("div", { class: "zhk-selection__func" }, [a("button", {
441
+ class: "zhk-selection__func-btn",
442
+ onClick: s
443
+ }, " 返回 ")])]));
444
+ }
445
+ }), Pe = { class: "zhk-candidate" }, Fe = { class: "zhk-candidate__container" }, Ie = {
446
+ key: 0,
447
+ class: "zhk-candidate__pinyin"
448
+ }, Le = { class: "zhk-candidate__bottom-container" }, Re = /* @__PURE__ */ c({
449
+ __name: "CandidateBar",
450
+ props: {
451
+ modelValue: { required: !0 },
452
+ modelModifiers: {}
453
+ },
454
+ emits: /* @__PURE__ */ d(["key", "input"], ["update:modelValue"]),
455
+ setup(e, { expose: o, emit: s }) {
456
+ let c = s, l = E(e, "modelValue"), u = null, d = b(null), f = t(() => d.value?.candidates.map((e) => e.text) ?? []), p = b(!1);
457
+ g(async () => {
458
+ if (u = R(), !u) throw Error("未找到拼音引擎实例,请确保已正确注册引擎");
459
+ l.value && (d.value = await u.processInput(l.value));
460
+ }), v(() => {
461
+ u?.processInput("").catch(() => {}), u = null;
462
+ }), O(l, async (e) => {
463
+ let t = u;
464
+ if (t) {
465
+ if (e === "") {
466
+ t.processInput("").catch(() => {}), d.value = null;
467
+ return;
468
+ }
469
+ d.value = await t.processInput(e);
470
+ }
471
+ });
472
+ async function m(e) {
473
+ if (!u) return;
474
+ let t = await u.pickCandidate(e);
475
+ d.value = t, t.preeditBody || (c("input", t.committed || ""), l.value = "", d.value = null, p.value = !1);
476
+ }
477
+ o({ handleSelection: m });
478
+ let h = t(() => {
479
+ let e = d.value;
480
+ return e ? e.preeditHead + e.preeditBody : "";
481
+ });
482
+ return (e, t) => (y(), i("div", Pe, [a("div", Fe, [h.value ? (y(), i("div", Ie, C(h.value), 1)) : r("", !0), a("div", Le, [f.value.length > 0 ? (y(), n(Z, {
483
+ key: 0,
484
+ candidates: f.value,
485
+ onSelect: m
486
+ }, null, 8, ["candidates"])) : r("", !0), f.value.length > 0 ? (y(), i("button", {
487
+ key: 1,
488
+ class: "zhk-candidate__more",
489
+ onClick: t[0] ||= (e) => p.value = !0
490
+ }, t[2] ||= [a("img", {
491
+ src: "data:image/svg+xml,%3csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2024%2024'%3e%3cpath%20d='M8.59,16.58L13.17,12L8.59,7.41L10,6L16,12L10,18L8.59,16.58Z'%20/%3e%3c/svg%3e",
492
+ alt: "更多"
493
+ }, null, -1)])) : r("", !0)])]), p.value ? (y(), n(Ne, {
494
+ key: 0,
495
+ candidates: f.value,
496
+ onSelect: m,
497
+ onClose: t[1] ||= (e) => p.value = !1
498
+ }, null, 8, ["candidates"])) : r("", !0)]));
499
+ }
500
+ }), ze = { class: "zhk-base" }, Be = { class: "zhk-base__row" }, Ve = ["onPointerdown"], He = ["disabled"], Ue = {
501
+ key: 1,
502
+ src: Oe,
503
+ class: "zhk-base__key-icon",
504
+ alt: "Shift"
505
+ }, We = ["onPointerdown"], Ge = { class: "zhk-base__row" }, Ke = { class: "zhk-base__toggle-main" }, qe = { class: "zhk-base__toggle-sub" }, Je = /* @__PURE__ */ c({
506
+ __name: "KeyboardBase",
507
+ props: /* @__PURE__ */ d({ enableHandwriting: { type: Boolean } }, {
508
+ modelValue: { default: "en" },
509
+ modelModifiers: {}
510
+ }),
511
+ emits: /* @__PURE__ */ d(["key"], ["update:modelValue"]),
512
+ setup(s, { emit: c }) {
513
+ let l = s, u = c, d = E(s, "modelValue"), f = t(() => d.value === "en_cap"), m = t(() => d.value === "zh"), h = t(() => m.value ? !0 : f.value);
514
+ function g(e, t = !1) {
515
+ u("key", {
516
+ key: e,
517
+ isControl: t
518
+ });
519
+ }
520
+ function _() {
521
+ m.value ? d.value = "hand" : d.value = f.value ? "en" : "en_cap";
522
+ }
523
+ function v() {
524
+ d.value = "num";
525
+ }
526
+ function S() {
527
+ d.value = "symbol";
528
+ }
529
+ let w = [
530
+ "1",
531
+ "2",
532
+ "3",
533
+ "4",
534
+ "5",
535
+ "6",
536
+ "7",
537
+ "8",
538
+ "9",
539
+ "0"
540
+ ], D = [
541
+ [
542
+ "q",
543
+ "w",
544
+ "e",
545
+ "r",
546
+ "t",
547
+ "y",
548
+ "u",
549
+ "i",
550
+ "o",
551
+ "p"
552
+ ],
553
+ [
554
+ "a",
555
+ "s",
556
+ "d",
557
+ "f",
558
+ "g",
559
+ "h",
560
+ "j",
561
+ "k",
562
+ "l"
563
+ ],
564
+ [
565
+ "z",
566
+ "x",
567
+ "c",
568
+ "v",
569
+ "b",
570
+ "n",
571
+ "m"
572
+ ]
573
+ ], O = b(""), k = b(null), { startRepeat: A, stopRepeat: M } = X();
574
+ function N() {
575
+ if (d.value === "zh" && O.value) {
576
+ O.value = O.value.slice(0, -1);
577
+ return;
578
+ }
579
+ g("delete", !0);
580
+ }
581
+ function P() {
582
+ if (d.value === "zh" && O.value) {
583
+ k.value?.handleSelection(0);
584
+ return;
585
+ }
586
+ g(" ");
587
+ }
588
+ function F() {
589
+ if (d.value === "zh" && O.value) {
590
+ g(O.value), O.value = "";
591
+ return;
592
+ }
593
+ g("enter", !0);
594
+ }
595
+ function I(e) {
596
+ if (d.value === "zh") {
597
+ O.value += e;
598
+ return;
599
+ }
600
+ g(f.value ? e.toUpperCase() : e);
601
+ }
602
+ function L() {
603
+ d.value = d.value === "zh" ? "en" : "zh";
604
+ }
605
+ let R = t(() => l.enableHandwriting ? "手写" : "-"), z = t(() => !l.enableHandwriting);
606
+ return (t, s) => (y(), i("div", ze, [
607
+ a("div", Be, [d.value === "zh" ? (y(), n(Re, {
608
+ key: 0,
609
+ ref_key: "candidateBarRef",
610
+ ref: k,
611
+ modelValue: O.value,
612
+ "onUpdate:modelValue": s[0] ||= (e) => O.value = e,
613
+ onInput: s[1] ||= (e) => g(e, !1)
614
+ }, null, 8, ["modelValue"])) : (y(), i(e, { key: 1 }, x(w, (e, t) => a("button", {
615
+ key: `number-${t}`,
616
+ class: "zhk-base__key zhk-base__key--letter",
617
+ onPointerdown: (t) => T(A)(t, () => I(e)),
618
+ onPointerup: s[2] ||= (...e) => T(M) && T(M)(...e),
619
+ onPointerleave: s[3] ||= (...e) => T(M) && T(M)(...e),
620
+ onPointercancel: s[4] ||= (...e) => T(M) && T(M)(...e),
621
+ onContextmenu: s[5] ||= j(() => {}, ["prevent"])
622
+ }, C(e), 41, Ve)), 64))]),
623
+ (y(), i(e, null, x(D, (t, n) => a("div", {
624
+ key: `row-${n}`,
625
+ class: "zhk-base__row"
626
+ }, [
627
+ n === 2 ? (y(), i("button", {
628
+ key: 0,
629
+ class: p(["zhk-base__key zhk-base__key--function zhk-base__key--shift", {
630
+ "zhk-base__key--active": !m.value && f.value,
631
+ "zhk-base__key--disabled": m.value && z.value
632
+ }]),
633
+ disabled: m.value && z.value,
634
+ onClick: _,
635
+ onContextmenu: s[6] ||= j(() => {}, ["prevent"])
636
+ }, [m.value ? (y(), i(e, { key: 0 }, [o(C(R.value), 1)], 64)) : (y(), i("img", Ue))], 42, He)) : r("", !0),
637
+ (y(!0), i(e, null, x(t, (e, t) => (y(), i("button", {
638
+ key: `key-${n}-${t}`,
639
+ class: "zhk-base__key zhk-base__key--letter",
640
+ onPointerdown: (t) => T(A)(t, () => I(e)),
641
+ onPointerup: s[7] ||= (...e) => T(M) && T(M)(...e),
642
+ onPointerleave: s[8] ||= (...e) => T(M) && T(M)(...e),
643
+ onPointercancel: s[9] ||= (...e) => T(M) && T(M)(...e),
644
+ onContextmenu: s[10] ||= j(() => {}, ["prevent"])
645
+ }, C(h.value ? e.toUpperCase() : e), 41, We))), 128)),
646
+ n === 2 ? (y(), i("button", {
647
+ key: 1,
648
+ class: "zhk-base__key zhk-base__key--function zhk-base__key--delete",
649
+ onPointerdown: s[11] ||= (e) => T(A)(e, () => N()),
650
+ onPointerup: s[12] ||= (...e) => T(M) && T(M)(...e),
651
+ onPointerleave: s[13] ||= (...e) => T(M) && T(M)(...e),
652
+ onPointercancel: s[14] ||= (...e) => T(M) && T(M)(...e),
653
+ onContextmenu: s[15] ||= j(() => {}, ["prevent"])
654
+ }, s[39] ||= [a("img", {
655
+ src: "data:image/svg+xml,%3csvg%20t='1777011781316'%20class='icon'%20viewBox='0%200%201439%201024'%20version='1.1'%20xmlns='http://www.w3.org/2000/svg'%20p-id='5887'%20width='200'%20height='200'%3e%3cpath%20d='M1283.03672%200.000187H465.243153a158.045778%20158.045778%200%200%200-122.329921%2057.680486L24.083875%20440.475014c-0.622227%200.68445-1.182232%201.431123-1.742237%202.177796A115.672087%20115.672087%200%200%200%200.003672%20511.906728a118.658779%20118.658779%200%200%200%2026.818004%2074.667297l316.713783%20380.492099a158.232446%20158.232446%200%200%200%20121.707694%2056.933814H1283.03672a156.303541%20156.303541%200%200%200%20156.05465-156.116873V156.054837A156.241318%20156.241318%200%200%200%201283.03672%200.000187z%20m-257.477728%20689.863598a47.538179%2047.538179%200%200%201-33.600284%2013.937896%2047.662624%2047.662624%200%200%201-33.662506-13.937896L847.72638%20579.293963l-110.569822%20110.569822a47.911515%2047.911515%200%200%201-33.724729%2013.937896%2047.662624%2047.662624%200%200%201-33.662506-81.325131l110.383154-110.569822-110.569822-110.569822a47.662624%2047.662624%200%200%201%200-67.387235%2047.600402%2047.600402%200%200%201%2067.325012%200l110.632045%20110.632045%20110.569822-110.632045A47.625291%2047.625291%200%200%201%201025.434546%20401.336906l-110.383153%20110.569822%20110.569821%20110.569822a47.662624%2047.662624%200%200%201-0.062222%2067.387235z'%20fill='%232C2C2C'%20p-id='5888'%3e%3c/path%3e%3c/svg%3e",
656
+ class: "zhk-base__key-icon",
657
+ alt: "Delete"
658
+ }, null, -1)], 32)) : r("", !0)
659
+ ])), 64)),
660
+ a("div", Ge, [
661
+ a("button", {
662
+ class: "zhk-base__key zhk-base__key--function",
663
+ onClick: S,
664
+ onContextmenu: s[16] ||= j(() => {}, ["prevent"])
665
+ }, " ", 32),
666
+ a("button", {
667
+ class: "zhk-base__key zhk-base__key--function",
668
+ onClick: v,
669
+ onContextmenu: s[17] ||= j(() => {}, ["prevent"])
670
+ }, " 123 ", 32),
671
+ a("button", {
672
+ class: "zhk-base__key",
673
+ onPointerdown: s[18] ||= (e) => T(A)(e, () => g(",")),
674
+ onPointerup: s[19] ||= (...e) => T(M) && T(M)(...e),
675
+ onPointerleave: s[20] ||= (...e) => T(M) && T(M)(...e),
676
+ onPointercancel: s[21] ||= (...e) => T(M) && T(M)(...e),
677
+ onContextmenu: s[22] ||= j(() => {}, ["prevent"])
678
+ }, "", 32),
679
+ a("button", {
680
+ class: "zhk-base__key zhk-base__key--space",
681
+ onPointerdown: s[23] ||= (e) => T(A)(e, () => P()),
682
+ onPointerup: s[24] ||= (...e) => T(M) && T(M)(...e),
683
+ onPointerleave: s[25] ||= (...e) => T(M) && T(M)(...e),
684
+ onPointercancel: s[26] ||= (...e) => T(M) && T(M)(...e),
685
+ onContextmenu: s[27] ||= j(() => {}, ["prevent"])
686
+ }, s[40] ||= [a("img", {
687
+ src: "data:image/svg+xml,%3csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2024%2024'%3e%3cpath%20d='M3%2015H5V19H19V15H21V19C21%2020.1%2020.1%2021%2019%2021H5C3.9%2021%203%2020.1%203%2019V15Z'%20/%3e%3c/svg%3e",
688
+ class: "zhk-base__key-icon",
689
+ alt: "Space"
690
+ }, null, -1)], 32),
691
+ a("button", {
692
+ class: "zhk-base__key",
693
+ onPointerdown: s[28] ||= (e) => T(A)(e, () => g("。")),
694
+ onPointerup: s[29] ||= (...e) => T(M) && T(M)(...e),
695
+ onPointerleave: s[30] ||= (...e) => T(M) && T(M)(...e),
696
+ onPointercancel: s[31] ||= (...e) => T(M) && T(M)(...e),
697
+ onContextmenu: s[32] ||= j(() => {}, ["prevent"])
698
+ }, "", 32),
699
+ a("button", {
700
+ class: "zhk-base__key zhk-base__key--function",
701
+ onClick: L,
702
+ onContextmenu: s[33] ||= j(() => {}, ["prevent"])
703
+ }, [a("span", Ke, C(d.value === "zh" ? "中" : "英"), 1), a("span", qe, "/" + C(d.value === "zh" ? "英" : "中"), 1)], 32),
704
+ a("button", {
705
+ class: "zhk-base__key zhk-base__key--function",
706
+ onPointerdown: s[34] ||= (e) => T(A)(e, () => F()),
707
+ onPointerup: s[35] ||= (...e) => T(M) && T(M)(...e),
708
+ onPointerleave: s[36] ||= (...e) => T(M) && T(M)(...e),
709
+ onPointercancel: s[37] ||= (...e) => T(M) && T(M)(...e),
710
+ onContextmenu: s[38] ||= j(() => {}, ["prevent"])
711
+ }, s[41] ||= [a("img", {
712
+ src: "data:image/svg+xml,%3csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2024%2024'%3e%3cpath%20d='M19,7V11H5.83L9.41,7.41L8,6L2,12L8,18L9.41,16.58L5.83,13H21V7H19Z'%20/%3e%3c/svg%3e",
713
+ class: "zhk-base__key-icon",
714
+ alt: "Enter"
715
+ }, null, -1)], 32)
716
+ ])
717
+ ]));
718
+ }
719
+ }), Ye = { class: "num-keyboard" }, Xe = { class: "num-keyboard__container" }, Ze = { class: "num-keyboard__left" }, Qe = { class: "num-keyboard__rows" }, $e = ["onClick", "onPointerdown"], et = {
720
+ key: 1,
721
+ src: ke,
722
+ class: "zhk-base__key-icon",
723
+ alt: "Space"
724
+ }, tt = { class: "num-keyboard__right" }, nt = ["onPointerdown"], rt = ["src", "alt"], it = { key: 1 }, at = /* @__PURE__ */ c({
725
+ __name: "NumericKeyboard",
726
+ props: { keyboardRows: { default: () => L().numKeys || [
727
+ [
728
+ "1",
729
+ "2",
730
+ "3"
731
+ ],
732
+ [
733
+ "4",
734
+ "5",
735
+ "6"
736
+ ],
737
+ [
738
+ "7",
739
+ "8",
740
+ "9"
741
+ ],
742
+ [
743
+ "back",
744
+ "0",
745
+ "space"
746
+ ]
747
+ ] } },
748
+ emits: ["key", "exit"],
749
+ setup(t, { emit: n }) {
750
+ let r = n, s = [
751
+ {
752
+ key: "delete",
753
+ icon: he,
754
+ text: "",
755
+ alt: "Delete"
756
+ },
757
+ {
758
+ key: ".",
759
+ icon: "",
760
+ text: ".",
761
+ alt: "."
762
+ },
763
+ {
764
+ key: "@",
765
+ icon: "",
766
+ text: "@",
767
+ alt: "@"
768
+ },
769
+ {
770
+ key: "enter",
771
+ icon: ge,
772
+ text: "",
773
+ alt: "Enter"
774
+ }
775
+ ];
776
+ function c(e) {
777
+ r("key", { key: e });
778
+ }
779
+ function l(e, t = !0) {
780
+ r("key", {
781
+ key: e,
782
+ isControl: t
783
+ });
784
+ }
785
+ function u() {
786
+ r("exit");
787
+ }
788
+ let { startRepeat: d, stopRepeat: f } = X();
789
+ function m(e, t) {
790
+ e === "back" || (e === "space" && (e = " "), e === "delete" || e === "enter" ? d(t, () => l(e)) : d(t, () => c(e)));
791
+ }
792
+ return (t, n) => (y(), i("div", Ye, [a("div", Xe, [a("div", Ze, [a("div", Qe, [(y(!0), i(e, null, x(t.keyboardRows, (t, r) => (y(), i("div", {
793
+ key: `row-${r}`,
794
+ class: "num-keyboard__row"
795
+ }, [(y(!0), i(e, null, x(t, (t, a) => (y(), i("button", {
796
+ key: `key-${r}-${a}`,
797
+ class: p(["num-keyboard__key", {
798
+ "num-keyboard__key--back": t === "back",
799
+ "num-keyboard__key--space": t === "space"
800
+ }]),
801
+ onClick: (e) => t === "back" && u(),
802
+ onPointerdown: (e) => m(t, e),
803
+ onPointerup: n[0] ||= (...e) => T(f) && T(f)(...e),
804
+ onPointerleave: n[1] ||= (...e) => T(f) && T(f)(...e),
805
+ onPointercancel: n[2] ||= (...e) => T(f) && T(f)(...e),
806
+ onContextmenu: n[3] ||= j(() => {}, ["prevent"])
807
+ }, [t === "back" ? (y(), i(e, { key: 0 }, [o(" 返回 ")], 64)) : t === "space" ? (y(), i("img", et)) : (y(), i(e, { key: 2 }, [o(C(t), 1)], 64))], 42, $e))), 128))]))), 128))])]), a("div", tt, [(y(), i(e, null, x(s, (e, t) => a("button", {
808
+ key: `func-${t}`,
809
+ class: "num-keyboard__key num-keyboard__key--function",
810
+ onPointerdown: (t) => m(e.key, t),
811
+ onPointerup: n[4] ||= (...e) => T(f) && T(f)(...e),
812
+ onPointerleave: n[5] ||= (...e) => T(f) && T(f)(...e),
813
+ onPointercancel: n[6] ||= (...e) => T(f) && T(f)(...e),
814
+ onContextmenu: n[7] ||= j(() => {}, ["prevent"])
815
+ }, [e.icon ? (y(), i("img", {
816
+ key: 0,
817
+ src: e.icon,
818
+ class: "num-keyboard__key-icon",
819
+ alt: e.alt
820
+ }, null, 8, rt)) : (y(), i("span", it, C(e.text), 1))], 40, nt)), 64))])])]));
821
+ }
822
+ }), ot = "data:image/svg+xml,%3csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2024%2024'%3e%3cpath%20d='M18,20V10H6V20H18M18,8A2,2%200%200,1%2020,10V20A2,2%200%200,1%2018,22H6C4.89,22%204,21.1%204,20V10A2,2%200%200,1%206,8H15V6A3,3%200%200,0%2012,3A3,3%200%200,0%209,6H7A5,5%200%200,1%2012,1A5,5%200%200,1%2017,6V8H18M12,17A2,2%200%200,1%2010,15A2,2%200%200,1%2012,13A2,2%200%200,1%2014,15A2,2%200%200,1%2012,17Z'%20/%3e%3c/svg%3e", st = "data:image/svg+xml,%3csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2024%2024'%3e%3cpath%20d='M12,17C10.89,17%2010,16.1%2010,15C10,13.89%2010.89,13%2012,13A2,2%200%200,1%2014,15A2,2%200%200,1%2012,17M18,20V10H6V20H18M18,8A2,2%200%200,1%2020,10V20A2,2%200%200,1%2018,22H6C4.89,22%204,21.1%204,20V10C4,8.89%204.89,8%206,8H7V6A5,5%200%200,1%2012,1A5,5%200%200,1%2017,6V8H18M12,3A3,3%200%200,0%209,6V8H15V6A3,3%200%200,0%2012,3Z'%20/%3e%3c/svg%3e", ct = { class: "symbol-keyboard" }, lt = { class: "symbol-keyboard__content" }, ut = { class: "symbol-keyboard__functions" }, dt = { class: "symbol-keyboard__lang-selector" }, ft = { class: "symbol-keyboard__control-group" }, pt = ["src"], Q = ["src"], mt = { class: "symbol-keyboard__symbols-container" }, ht = { class: "symbol-keyboard__symbols-grid" }, gt = ["onClick", "onPointerdown"], _t = "!@#$%^&*(){}[]<>/\\|:;\"',.?+-=_~`€£¥₹©®™°", vt = "!@#¥%…&*(){}[]<>/\|:;"',。?+-=_~·€£¥₹©®™°", yt = /* @__PURE__ */ c({
823
+ __name: "SymbolKeyboard",
824
+ emits: ["key", "exit"],
825
+ setup(n, { emit: r }) {
826
+ let o = r, s = b("en"), c = t(() => s.value === "zh" ? vt : _t), l = b(!1), { startRepeat: u, stopRepeat: d } = X();
827
+ function f(e, t) {
828
+ l.value && u(t, () => m(e));
829
+ }
830
+ function m(e) {
831
+ o("key", { key: e }), l.value || o("exit");
832
+ }
833
+ function h() {
834
+ o("exit");
835
+ }
836
+ function g(e) {
837
+ s.value = e;
838
+ }
839
+ function _() {
840
+ l.value = !l.value;
841
+ }
842
+ return (t, n) => (y(), i("div", ct, [a("div", lt, [a("div", ut, [a("div", dt, [a("button", {
843
+ class: p(["symbol-keyboard__lang-btn", { "symbol-keyboard__lang-btn--active": s.value === "zh" }]),
844
+ onClick: n[0] ||= (e) => g("zh"),
845
+ onContextmenu: n[1] ||= j(() => {}, ["prevent"])
846
+ }, " 中文 ", 34), a("button", {
847
+ class: p(["symbol-keyboard__lang-btn", { "symbol-keyboard__lang-btn--active": s.value === "en" }]),
848
+ onClick: n[2] ||= (e) => g("en"),
849
+ onContextmenu: n[3] ||= j(() => {}, ["prevent"])
850
+ }, " 英文 ", 34)]), a("div", ft, [a("button", {
851
+ class: p(["symbol-keyboard__key symbol-keyboard__key--function symbol-keyboard__key--lock", { "symbol-keyboard__key--locked": l.value }]),
852
+ onClick: _,
853
+ onContextmenu: n[4] ||= j(() => {}, ["prevent"])
854
+ }, [l.value ? (y(), i("img", {
855
+ key: 1,
856
+ src: T(st),
857
+ alt: "Lock closed"
858
+ }, null, 8, Q)) : (y(), i("img", {
859
+ key: 0,
860
+ src: T(ot),
861
+ alt: "Lock open"
862
+ }, null, 8, pt))], 34), a("button", {
863
+ class: "symbol-keyboard__key symbol-keyboard__key--function symbol-keyboard__key--back",
864
+ onClick: h,
865
+ onContextmenu: n[5] ||= j(() => {}, ["prevent"])
866
+ }, " 返回 ", 32)])]), a("div", mt, [a("div", ht, [(y(!0), i(e, null, x(c.value, (e, t) => (y(), i("button", {
867
+ key: `key-${t}`,
868
+ class: "symbol-keyboard__key",
869
+ onClick: (t) => !l.value && m(e),
870
+ onPointerdown: (t) => f(e, t),
871
+ onPointerup: n[6] ||= (...e) => T(d) && T(d)(...e),
872
+ onPointerleave: n[7] ||= (...e) => T(d) && T(d)(...e),
873
+ onPointercancel: n[8] ||= (...e) => T(d) && T(d)(...e),
874
+ onContextmenu: n[9] ||= j(() => {}, ["prevent"])
875
+ }, C(e), 41, gt))), 128))])])])]));
876
+ }
877
+ }), bt = {
878
+ key: 0,
879
+ class: "zhk__disabled-overlay"
880
+ }, $ = /* @__PURE__ */ c({
881
+ __name: "ZhKeyboard",
882
+ props: {
883
+ defaultMode: {
884
+ type: String,
885
+ default: () => L().defaultMode ?? "en"
886
+ },
887
+ enableHandwriting: {
888
+ type: Boolean,
889
+ default: () => L().enableHandwriting ?? !1
890
+ },
891
+ position: {
892
+ type: String,
893
+ default: () => L().position ?? "static"
894
+ },
895
+ floatMarginTop: {
896
+ type: Number,
897
+ default: () => L().floatMarginTop ?? 0
898
+ },
899
+ disableWhenNoFocus: {
900
+ type: Boolean,
901
+ default: () => L().disableWhenNoFocus ?? !0
902
+ },
903
+ numKeys: { type: Array || void 0 }
904
+ },
905
+ emits: ["key"],
906
+ setup(o, { emit: s }) {
907
+ let c = o, l = s, u = b(c.defaultMode), d = b(c.defaultMode), f = b([]), h = b(!1), g = b(null), _ = b(null), { recognizerInitialized: v, recognizerProgress: x } = me(c.enableHandwriting);
908
+ O(u, (e, t) => {
909
+ e !== t && (d.value = t);
910
+ });
911
+ let S = fe(), C = t(() => S.value && z(S.value) ? S.value : null), w = t(() => c.position === "static" || !!(S.value && z(S.value))), { height: E } = Y(_);
912
+ k(() => {
913
+ if (C.value) {
914
+ let e = C.value.dataset.inputmode;
915
+ e && (u.value = e);
916
+ }
917
+ });
918
+ let M = t(() => c.disableWhenNoFocus === !1 ? !1 : !C.value);
919
+ function P() {
920
+ E.value && (g.value = N(C.value, _.value, c.position, c.floatMarginTop));
921
+ }
922
+ k(P);
923
+ let I = oe(P, 100);
924
+ q(window, "scroll", I, { passive: !0 }), q(window, "resize", I, { passive: !0 });
925
+ function L(e) {
926
+ if (e.isControl) {
927
+ switch (e.key) {
928
+ case "delete":
929
+ F(C.value);
930
+ break;
931
+ case "more":
932
+ h.value = !0;
933
+ break;
934
+ default: break;
935
+ }
936
+ return;
937
+ } else R(e.key);
938
+ l("key", e);
939
+ }
940
+ function R(e) {
941
+ ee(C.value, e);
942
+ }
943
+ function B() {
944
+ u.value === "hand" ? d.value = "zh" : ["num", "symbol"].includes(d.value) && (d.value = c.defaultMode), u.value = d.value;
945
+ }
946
+ function V(e) {
947
+ f.value = e;
948
+ }
949
+ return (t, s) => A((y(), i("div", {
950
+ ref_key: "keyboardRef",
951
+ ref: _,
952
+ class: p(["zhk", {
953
+ "zhk--floating": o.position === "float",
954
+ "zhk--bottom": o.position === "bottom",
955
+ "zhk--disabled": M.value
956
+ }]),
957
+ style: m({
958
+ "--keyboard-height": `${T(E)}px`,
959
+ ...g.value
960
+ }),
961
+ onMousedown: s[1] ||= j(() => {}, ["prevent"])
962
+ }, [M.value || !w.value || !T(E) ? (y(), i("div", bt, s[2] ||= [a("span", null, "请选择输入框以启用键盘", -1)])) : (y(), i(e, { key: 1 }, [u.value === "hand" ? (y(), n(De, {
963
+ key: 0,
964
+ "recognizer-initialized": T(v),
965
+ "recognizer-progress": T(x),
966
+ onKey: L,
967
+ onExit: B,
968
+ onRecognize: V
969
+ }, null, 8, ["recognizer-initialized", "recognizer-progress"])) : u.value === "num" ? (y(), n(at, {
970
+ key: 1,
971
+ "keyboard-rows": o.numKeys,
972
+ onKey: L,
973
+ onExit: B
974
+ }, null, 8, ["keyboard-rows"])) : u.value === "symbol" ? (y(), n(yt, {
975
+ key: 2,
976
+ onKey: L,
977
+ onExit: B
978
+ })) : u.value === "en" || u.value === "en_cap" || u.value === "zh" ? (y(), n(Je, {
979
+ key: 3,
980
+ modelValue: u.value,
981
+ "onUpdate:modelValue": s[0] ||= (e) => u.value = e,
982
+ "enable-handwriting": o.enableHandwriting,
983
+ onKey: L
984
+ }, null, 8, ["modelValue", "enable-handwriting"])) : r("", !0)], 64))], 38)), [[D, w.value]]);
985
+ }
986
+ }), xt = { install: (e) => {
987
+ e.component("ZhKeyboard", $);
988
+ } };
989
+ //#endregion
990
+ export { $ as ZhKeyboard, xt as default };
991
+
992
+ //# sourceMappingURL=zh-keyboard-vue.js.map