@composy/keyboard-vue 0.0.1 → 0.0.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.
- package/README.md +48 -24
- package/dist/index.css +552 -560
- package/dist/index.js +228 -192
- package/dist/index.js.map +1 -1
- package/dist/index.min.css +1 -1
- package/dist/index.min.js +954 -1
- package/dist/index.min.js.map +1 -0
- package/es/.dts-output-manifest.json +1 -0
- package/es/.dts.tsbuildinfo +1 -0
- package/es/components/KeyboardKey.js +1 -1
- package/es/components/KeyboardKey.js.map +1 -1
- package/es/components/KeyboardKey.vue_vue_type_script_setup_true_lang.js +16 -7
- package/es/components/KeyboardKey.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/es/components/KeyboardPopup.js +1 -1
- package/es/components/KeyboardPopup.js.map +1 -1
- package/es/components/KeyboardPopup.vue_vue_type_script_setup_true_lang.js +8 -5
- package/es/components/KeyboardPopup.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/es/components/LicensePlateKeyboard.js +1 -1
- package/es/components/LicensePlateKeyboard.js.map +1 -1
- package/es/components/LicensePlateKeyboard.vue_vue_type_script_setup_true_lang.js +2 -2
- package/es/components/LicensePlateKeyboard.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/es/components/VirtualKeyboard.js +1 -1
- package/es/components/VirtualKeyboard.js.map +1 -1
- package/es/components/VirtualKeyboard.vue_vue_type_script_setup_true_lang.js +4 -4
- package/es/components/VirtualKeyboard.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/es/components/index.d.ts +1 -2
- package/es/components/index.d.ts.map +1 -1
- package/es/components/index.js +1 -1
- package/es/composables/index.d.ts +0 -1
- package/es/composables/index.js +1 -1
- package/es/composables/useKeyboard.d.ts +1 -2
- package/es/composables/useKeyboard.d.ts.map +1 -1
- package/es/composables/useKeyboard.js +8 -15
- package/es/composables/useKeyboard.js.map +1 -1
- package/es/composables/useKeyboardPopup.d.ts +2 -51
- package/es/composables/useKeyboardPopup.d.ts.map +1 -1
- package/es/composables/useKeyboardPopup.js +66 -49
- package/es/composables/useKeyboardPopup.js.map +1 -1
- package/es/directives/index.d.ts +0 -1
- package/es/directives/index.js +1 -1
- package/es/directives/v-keyboard.d.ts +0 -1
- package/es/directives/v-keyboard.d.ts.map +1 -1
- package/es/directives/v-keyboard.js +10 -11
- package/es/directives/v-keyboard.js.map +1 -1
- package/es/index.d.ts +3 -4
- package/es/index.d.ts.map +1 -1
- package/es/index.js +2 -5
- package/es/index.js.map +1 -1
- package/es/plugins/engine-plugin.d.ts +0 -1
- package/es/plugins/engine-plugin.d.ts.map +1 -1
- package/es/plugins/engine-plugin.js +19 -4
- package/es/plugins/engine-plugin.js.map +1 -1
- package/es/plugins/index.d.ts +0 -1
- package/es/plugins/index.js +1 -1
- package/es/style/css.js +1 -1
- package/es/style/index.css +2 -0
- package/es/style/index.js +1 -1
- package/es/styles/index.css +391 -0
- package/es/styles/keyboard.css +252 -0
- package/es/styles/themes.css +137 -0
- package/esm/components/KeyboardKey.js +17 -0
- package/esm/components/KeyboardKey.js.map +1 -0
- package/esm/components/KeyboardKey.vue_vue_type_script_setup_true_lang.js +140 -0
- package/esm/components/KeyboardKey.vue_vue_type_script_setup_true_lang.js.map +1 -0
- package/esm/components/KeyboardPopup.js +17 -0
- package/esm/components/KeyboardPopup.js.map +1 -0
- package/esm/components/KeyboardPopup.vue_vue_type_script_setup_true_lang.js +167 -0
- package/esm/components/KeyboardPopup.vue_vue_type_script_setup_true_lang.js.map +1 -0
- package/esm/components/LicensePlateKeyboard.js +17 -0
- package/esm/components/LicensePlateKeyboard.js.map +1 -0
- package/esm/components/LicensePlateKeyboard.vue_vue_type_script_setup_true_lang.js +97 -0
- package/esm/components/LicensePlateKeyboard.vue_vue_type_script_setup_true_lang.js.map +1 -0
- package/esm/components/VirtualKeyboard.js +17 -0
- package/esm/components/VirtualKeyboard.js.map +1 -0
- package/esm/components/VirtualKeyboard.vue_vue_type_script_setup_true_lang.js +127 -0
- package/esm/components/VirtualKeyboard.vue_vue_type_script_setup_true_lang.js.map +1 -0
- package/{lib → esm}/components/index.d.ts +1 -1
- package/esm/components/index.d.ts.map +1 -0
- package/esm/components/index.js +15 -0
- package/esm/composables/index.d.ts.map +1 -0
- package/esm/composables/index.js +13 -0
- package/{lib → esm}/composables/useKeyboard.d.ts +1 -1
- package/esm/composables/useKeyboard.d.ts.map +1 -0
- package/esm/composables/useKeyboard.js +68 -0
- package/esm/composables/useKeyboard.js.map +1 -0
- package/esm/composables/useKeyboardPopup.d.ts +25 -0
- package/esm/composables/useKeyboardPopup.d.ts.map +1 -0
- package/esm/composables/useKeyboardPopup.js +136 -0
- package/esm/composables/useKeyboardPopup.js.map +1 -0
- package/esm/directives/index.d.ts.map +1 -0
- package/esm/directives/index.js +12 -0
- package/esm/directives/v-keyboard.d.ts.map +1 -0
- package/esm/directives/v-keyboard.js +64 -0
- package/esm/directives/v-keyboard.js.map +1 -0
- package/esm/index.d.ts +42 -0
- package/esm/index.d.ts.map +1 -0
- package/esm/index.js +34 -0
- package/esm/index.js.map +1 -0
- package/esm/plugins/engine-plugin.d.ts.map +1 -0
- package/esm/plugins/engine-plugin.js +53 -0
- package/esm/plugins/engine-plugin.js.map +1 -0
- package/esm/plugins/index.d.ts.map +1 -0
- package/esm/plugins/index.js +12 -0
- package/esm/style/css.js +1 -0
- package/esm/style/index.js +1 -0
- package/{es → esm}/style/index.less +1 -1
- package/esm/styles/index.less +5 -0
- package/esm/styles/keyboard.less +286 -0
- package/esm/styles/themes.less +164 -0
- package/lib/components/KeyboardKey.cjs +1 -1
- package/lib/components/KeyboardKey.cjs.map +1 -1
- package/lib/components/KeyboardKey.vue_vue_type_script_setup_true_lang.cjs +16 -7
- package/lib/components/KeyboardKey.vue_vue_type_script_setup_true_lang.cjs.map +1 -1
- package/lib/components/KeyboardPopup.cjs +1 -1
- package/lib/components/KeyboardPopup.cjs.map +1 -1
- package/lib/components/KeyboardPopup.vue_vue_type_script_setup_true_lang.cjs +8 -5
- package/lib/components/KeyboardPopup.vue_vue_type_script_setup_true_lang.cjs.map +1 -1
- package/lib/components/LicensePlateKeyboard.cjs +1 -1
- package/lib/components/LicensePlateKeyboard.cjs.map +1 -1
- package/lib/components/LicensePlateKeyboard.vue_vue_type_script_setup_true_lang.cjs +2 -2
- package/lib/components/LicensePlateKeyboard.vue_vue_type_script_setup_true_lang.cjs.map +1 -1
- package/lib/components/VirtualKeyboard.cjs +1 -1
- package/lib/components/VirtualKeyboard.cjs.map +1 -1
- package/lib/components/VirtualKeyboard.vue_vue_type_script_setup_true_lang.cjs +4 -4
- package/lib/components/VirtualKeyboard.vue_vue_type_script_setup_true_lang.cjs.map +1 -1
- package/lib/components/index.cjs +1 -1
- package/lib/components/index.d.cts +8 -0
- package/lib/components/index.d.cts.map +1 -0
- package/lib/composables/index.cjs +1 -1
- package/lib/composables/index.d.cts +6 -0
- package/lib/composables/index.d.cts.map +1 -0
- package/lib/composables/useKeyboard.cjs +8 -15
- package/lib/composables/useKeyboard.cjs.map +1 -1
- package/lib/composables/useKeyboard.d.cts +112 -0
- package/lib/composables/useKeyboard.d.cts.map +1 -0
- package/lib/composables/useKeyboardPopup.cjs +66 -49
- package/lib/composables/useKeyboardPopup.cjs.map +1 -1
- package/lib/composables/useKeyboardPopup.d.cts +24 -0
- package/lib/composables/useKeyboardPopup.d.cts.map +1 -0
- package/lib/directives/index.cjs +1 -1
- package/lib/directives/index.d.cts +5 -0
- package/lib/directives/index.d.cts.map +1 -0
- package/lib/directives/v-keyboard.cjs +10 -11
- package/lib/directives/v-keyboard.cjs.map +1 -1
- package/lib/directives/v-keyboard.d.cts +35 -0
- package/lib/directives/v-keyboard.d.cts.map +1 -0
- package/lib/index.cjs +2 -2
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +41 -0
- package/lib/index.d.cts.map +1 -0
- package/lib/plugins/engine-plugin.cjs +19 -3
- package/lib/plugins/engine-plugin.cjs.map +1 -1
- package/lib/plugins/engine-plugin.d.cts +36 -0
- package/lib/plugins/engine-plugin.d.cts.map +1 -0
- package/lib/plugins/index.cjs +1 -1
- package/lib/plugins/index.d.cts +5 -0
- package/lib/plugins/index.d.cts.map +1 -0
- package/lib/style/index.css +1 -1
- package/lib/styles/index.css +357 -195
- package/lib/styles/keyboard.css +92 -186
- package/lib/styles/themes.css +102 -178
- package/package.json +43 -34
- package/es/styles/index.less +0 -267
- package/es/styles/keyboard.less +0 -399
- package/es/styles/themes.less +0 -233
- package/lib/composables/useKeyboardPopup.d.ts +0 -73
- package/lib/index.d.ts +0 -42
- /package/{lib → esm}/composables/index.d.ts +0 -0
- /package/{lib → esm}/directives/index.d.ts +0 -0
- /package/{lib → esm}/directives/v-keyboard.d.ts +0 -0
- /package/{lib → esm}/plugins/engine-plugin.d.ts +0 -0
- /package/{lib → esm}/plugins/index.d.ts +0 -0
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* ***********************************
|
|
3
|
+
* @composy/keyboard-vue v0.0.1 *
|
|
4
|
+
* Built with rollup *
|
|
5
|
+
* Build time: 2024-10-12 17:44:15 *
|
|
6
|
+
* Build mode: production *
|
|
7
|
+
* Minified: No *
|
|
8
|
+
* ***********************************
|
|
9
|
+
*/
|
|
10
|
+
import { useKeyboard } from "../composables/useKeyboard.js";
|
|
11
|
+
import { useKeyboardPopup } from "../composables/useKeyboardPopup.js";
|
|
12
|
+
import VirtualKeyboard_default from "./VirtualKeyboard.js";
|
|
13
|
+
import { Teleport, Transition, computed, createBlock, createCommentVNode, createElementBlock, createVNode, defineComponent, nextTick, normalizeClass, normalizeStyle, openBlock, ref, unref, watch, withCtx, withModifiers } from "vue";
|
|
14
|
+
import { isMobile } from "@composy/keyboard-core";
|
|
15
|
+
//#region src/components/KeyboardPopup.vue?vue&type=script&setup=true&lang.ts
|
|
16
|
+
var KeyboardPopup_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ defineComponent({
|
|
17
|
+
__name: "KeyboardPopup",
|
|
18
|
+
props: {
|
|
19
|
+
modelValue: {
|
|
20
|
+
type: Boolean,
|
|
21
|
+
required: false,
|
|
22
|
+
default: false
|
|
23
|
+
},
|
|
24
|
+
type: {
|
|
25
|
+
type: String,
|
|
26
|
+
required: false,
|
|
27
|
+
default: "qwerty"
|
|
28
|
+
},
|
|
29
|
+
value: {
|
|
30
|
+
type: String,
|
|
31
|
+
required: false,
|
|
32
|
+
default: ""
|
|
33
|
+
},
|
|
34
|
+
target: {
|
|
35
|
+
type: null,
|
|
36
|
+
required: false,
|
|
37
|
+
default: null
|
|
38
|
+
},
|
|
39
|
+
maxLength: {
|
|
40
|
+
type: Number,
|
|
41
|
+
required: false
|
|
42
|
+
},
|
|
43
|
+
closeOnClickOutside: {
|
|
44
|
+
type: Boolean,
|
|
45
|
+
required: false,
|
|
46
|
+
default: true
|
|
47
|
+
},
|
|
48
|
+
enableVibrate: {
|
|
49
|
+
type: Boolean,
|
|
50
|
+
required: false,
|
|
51
|
+
default: true
|
|
52
|
+
},
|
|
53
|
+
teleportTo: {
|
|
54
|
+
type: null,
|
|
55
|
+
required: false,
|
|
56
|
+
default: "body"
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
emits: [
|
|
60
|
+
"update:modelValue",
|
|
61
|
+
"update:value",
|
|
62
|
+
"confirm",
|
|
63
|
+
"keypress"
|
|
64
|
+
],
|
|
65
|
+
setup(__props, { emit: __emit }) {
|
|
66
|
+
const props = __props;
|
|
67
|
+
const emit = __emit;
|
|
68
|
+
const popupRef = ref(null);
|
|
69
|
+
const targetRef = computed(() => props.target);
|
|
70
|
+
const isMobileDevice = ref(isMobile());
|
|
71
|
+
const keyboard = useKeyboard({
|
|
72
|
+
type: props.type,
|
|
73
|
+
value: props.value,
|
|
74
|
+
maxLength: props.maxLength ?? (props.type.startsWith("license-plate") ? 7 : void 0),
|
|
75
|
+
enableVibrate: props.enableVibrate
|
|
76
|
+
});
|
|
77
|
+
const { popupStyles, maskStyles, placement, showMask, updatePosition, close: closePopup } = useKeyboardPopup({
|
|
78
|
+
visible: computed(() => props.modelValue),
|
|
79
|
+
target: targetRef,
|
|
80
|
+
popup: popupRef,
|
|
81
|
+
closeOnClickOutside: props.closeOnClickOutside,
|
|
82
|
+
onClose: () => {
|
|
83
|
+
emit("update:modelValue", false);
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
watch(() => props.type, (newType) => {
|
|
87
|
+
keyboard.switchType(newType);
|
|
88
|
+
if (newType.startsWith("license-plate") && !props.maxLength) keyboard.setMaxLength(7);
|
|
89
|
+
});
|
|
90
|
+
watch(() => props.maxLength, (maxLength) => {
|
|
91
|
+
if (maxLength !== void 0) keyboard.setMaxLength(maxLength);
|
|
92
|
+
});
|
|
93
|
+
watch(() => props.value, (newValue) => {
|
|
94
|
+
if (newValue !== keyboard.value.value) keyboard.setValue(newValue);
|
|
95
|
+
});
|
|
96
|
+
watch(keyboard.value, (newValue) => {
|
|
97
|
+
emit("update:value", newValue);
|
|
98
|
+
});
|
|
99
|
+
watch(() => props.modelValue, (visible) => {
|
|
100
|
+
if (visible) {
|
|
101
|
+
isMobileDevice.value = isMobile();
|
|
102
|
+
if (props.target) keyboard.bindInput(props.target);
|
|
103
|
+
keyboard.show(props.target ?? void 0);
|
|
104
|
+
nextTick(() => {
|
|
105
|
+
updatePosition();
|
|
106
|
+
});
|
|
107
|
+
} else keyboard.hide();
|
|
108
|
+
}, { immediate: true });
|
|
109
|
+
keyboard.on("confirm", ({ value }) => {
|
|
110
|
+
emit("confirm", value);
|
|
111
|
+
emit("update:modelValue", false);
|
|
112
|
+
});
|
|
113
|
+
const handleKeyPress = (key) => {
|
|
114
|
+
keyboard.handleKey(key);
|
|
115
|
+
emit("keypress", key);
|
|
116
|
+
};
|
|
117
|
+
const handleSelectOption = (option) => {
|
|
118
|
+
let valueToAppend = option;
|
|
119
|
+
if (option.startsWith("@") && keyboard.value.value.endsWith("@")) valueToAppend = option.slice(1);
|
|
120
|
+
keyboard.appendValue(valueToAppend);
|
|
121
|
+
};
|
|
122
|
+
const handleMaskClick = () => {
|
|
123
|
+
if (props.closeOnClickOutside) closePopup();
|
|
124
|
+
};
|
|
125
|
+
const popupClass = computed(() => {
|
|
126
|
+
return [
|
|
127
|
+
"keyboard-popup",
|
|
128
|
+
`keyboard-popup--${placement.value}`,
|
|
129
|
+
{
|
|
130
|
+
"keyboard-popup--mobile": isMobileDevice.value,
|
|
131
|
+
"keyboard-popup--desktop": !isMobileDevice.value
|
|
132
|
+
}
|
|
133
|
+
];
|
|
134
|
+
});
|
|
135
|
+
return (_ctx, _cache) => {
|
|
136
|
+
return openBlock(), createBlock(Teleport, { to: __props.teleportTo }, [createVNode(Transition, { name: "keyboard-mask" }, {
|
|
137
|
+
default: withCtx(() => [__props.modelValue && unref(showMask) ? (openBlock(), createElementBlock("div", {
|
|
138
|
+
key: 0,
|
|
139
|
+
class: "keyboard-mask",
|
|
140
|
+
style: normalizeStyle(unref(maskStyles)),
|
|
141
|
+
onClick: handleMaskClick
|
|
142
|
+
}, null, 4)) : createCommentVNode("v-if", true)]),
|
|
143
|
+
_: 1
|
|
144
|
+
}), createVNode(Transition, { name: isMobileDevice.value ? "keyboard-slide" : "keyboard-fade" }, {
|
|
145
|
+
default: withCtx(() => [__props.modelValue ? (openBlock(), createElementBlock("div", {
|
|
146
|
+
key: 0,
|
|
147
|
+
ref_key: "popupRef",
|
|
148
|
+
ref: popupRef,
|
|
149
|
+
class: normalizeClass(popupClass.value),
|
|
150
|
+
style: normalizeStyle(unref(popupStyles)),
|
|
151
|
+
onMousedown: _cache[0] || (_cache[0] = withModifiers(() => {}, ["prevent"])),
|
|
152
|
+
onTouchstart: _cache[1] || (_cache[1] = withModifiers(() => {}, ["prevent"]))
|
|
153
|
+
}, [createVNode(VirtualKeyboard_default, {
|
|
154
|
+
type: unref(keyboard).type.value,
|
|
155
|
+
"is-upper-case": unref(keyboard).isUpperCase.value,
|
|
156
|
+
onKeypress: handleKeyPress,
|
|
157
|
+
onSelectOption: handleSelectOption
|
|
158
|
+
}, null, 8, ["type", "is-upper-case"])], 38)) : createCommentVNode("v-if", true)]),
|
|
159
|
+
_: 1
|
|
160
|
+
}, 8, ["name"])], 8, ["to"]);
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
//#endregion
|
|
165
|
+
export { KeyboardPopup_vue_vue_type_script_setup_true_lang_default as default };
|
|
166
|
+
/*! End of @composy/keyboard-vue | Powered by @composy/builder */
|
|
167
|
+
//# sourceMappingURL=KeyboardPopup.vue_vue_type_script_setup_true_lang.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"KeyboardPopup.vue_vue_type_script_setup_true_lang.js","names":[],"sources":["../../src/components/KeyboardPopup.vue","../../src/components/KeyboardPopup.vue"],"sourcesContent":["<script setup lang=\"ts\">\r\nimport type { KeyboardType, KeyDefinition } from '@composy/keyboard-core'\r\nimport { isMobile } from '@composy/keyboard-core'\r\nimport { computed, nextTick, ref, watch } from 'vue'\r\nimport { useKeyboard } from '../composables/useKeyboard'\r\nimport { useKeyboardPopup } from '../composables/useKeyboardPopup'\r\nimport VirtualKeyboard from './VirtualKeyboard.vue'\r\n\r\nconst props = withDefaults(\r\n defineProps<{\r\n /**\r\n * 是否显示 (v-model)\r\n */\r\n modelValue?: boolean\r\n /**\r\n * 键盘类型\r\n */\r\n type?: KeyboardType | string\r\n /**\r\n * 绑定的输入值 (v-model:value)\r\n */\r\n value?: string\r\n /**\r\n * 目标输入框元素\r\n */\r\n target?: HTMLInputElement | HTMLTextAreaElement | null\r\n /**\r\n * 最大输入长度\r\n */\r\n maxLength?: number\r\n /**\r\n * 点击外部是否关闭\r\n */\r\n closeOnClickOutside?: boolean\r\n /**\r\n * 是否启用震动反馈\r\n */\r\n enableVibrate?: boolean\r\n /**\r\n * 挂载目标\r\n */\r\n teleportTo?: string | HTMLElement\r\n }>(),\r\n {\r\n modelValue: false,\r\n type: 'qwerty',\r\n value: '',\r\n target: null,\r\n closeOnClickOutside: true,\r\n enableVibrate: true,\r\n teleportTo: 'body',\r\n }\r\n)\r\n\r\nconst emit = defineEmits<{\r\n 'update:modelValue': [visible: boolean]\r\n 'update:value': [value: string]\r\n confirm: [value: string]\r\n keypress: [key: KeyDefinition]\r\n}>()\r\n\r\n// 弹出层 DOM 引用\r\nconst popupRef = ref<HTMLElement | null>(null)\r\n\r\n// 目标元素引用\r\nconst targetRef = computed(() => props.target as HTMLElement | null)\r\n\r\n// 是否移动端\r\nconst isMobileDevice = ref(isMobile())\r\n\r\n// 创建键盘管理器\r\nconst keyboard = useKeyboard({\r\n type: props.type as KeyboardType,\r\n value: props.value,\r\n maxLength:\r\n props.maxLength ?? (props.type.startsWith('license-plate') ? 7 : undefined),\r\n enableVibrate: props.enableVibrate,\r\n})\r\n\r\n// 创建弹出层管理\r\nconst {\r\n popupStyles,\r\n maskStyles,\r\n placement,\r\n showMask,\r\n updatePosition,\r\n close: closePopup,\r\n} = useKeyboardPopup({\r\n visible: computed(() => props.modelValue),\r\n target: targetRef,\r\n popup: popupRef,\r\n closeOnClickOutside: props.closeOnClickOutside,\r\n onClose: () => {\r\n emit('update:modelValue', false)\r\n },\r\n})\r\n\r\n// 监听键盘类型变化\r\nwatch(\r\n () => props.type,\r\n newType => {\r\n keyboard.switchType(newType as KeyboardType)\r\n\r\n // 车牌键盘需要设置默认 maxLength\r\n if (newType.startsWith('license-plate') && !props.maxLength) {\r\n keyboard.setMaxLength(7)\r\n }\r\n }\r\n)\r\n\r\nwatch(\r\n () => props.maxLength,\r\n maxLength => {\r\n if (maxLength !== undefined) keyboard.setMaxLength(maxLength)\r\n }\r\n)\r\n\r\n// 监听外部 value 变化\r\nwatch(\r\n () => props.value,\r\n newValue => {\r\n if (newValue !== keyboard.value.value) {\r\n keyboard.setValue(newValue)\r\n }\r\n }\r\n)\r\n\r\n// 监听键盘内部 value 变化\r\nwatch(keyboard.value, newValue => {\r\n emit('update:value', newValue)\r\n})\r\n\r\n// 监听可见性变化\r\nwatch(\r\n () => props.modelValue,\r\n visible => {\r\n if (visible) {\r\n isMobileDevice.value = isMobile()\r\n if (props.target) {\r\n keyboard.bindInput(props.target)\r\n }\r\n keyboard.show(props.target ?? undefined)\r\n\r\n nextTick(() => {\r\n updatePosition()\r\n })\r\n } else {\r\n keyboard.hide()\r\n }\r\n },\r\n { immediate: true }\r\n)\r\n\r\n// 监听确认事件\r\nkeyboard.on('confirm', ({ value }) => {\r\n emit('confirm', value)\r\n emit('update:modelValue', false)\r\n})\r\n\r\n/**\r\n * 处理按键\r\n */\r\nconst handleKeyPress = (key: KeyDefinition) => {\r\n keyboard.handleKey(key)\r\n emit('keypress', key)\r\n}\r\n\r\n/**\r\n * 处理下拉选项选择(如邮箱后缀)\r\n */\r\nconst handleSelectOption = (option: string) => {\r\n let valueToAppend = option\r\n\r\n // 智能处理邮箱后缀:如果当前值已以 @ 结尾,而选项以 @ 开头,则去掉选项的 @\r\n if (option.startsWith('@') && keyboard.value.value.endsWith('@')) {\r\n valueToAppend = option.slice(1) // 去掉开头的 @\r\n }\r\n\r\n keyboard.appendValue(valueToAppend)\r\n}\r\n\r\n/**\r\n * 处理遮罩点击\r\n */\r\nconst handleMaskClick = () => {\r\n if (props.closeOnClickOutside) {\r\n closePopup()\r\n }\r\n}\r\n\r\n/**\r\n * 计算弹出层类名\r\n */\r\nconst popupClass = computed(() => {\r\n return [\r\n 'keyboard-popup',\r\n `keyboard-popup--${placement.value}`,\r\n {\r\n 'keyboard-popup--mobile': isMobileDevice.value,\r\n 'keyboard-popup--desktop': !isMobileDevice.value,\r\n },\r\n ]\r\n})\r\n</script>\r\n\r\n<template>\r\n <Teleport :to=\"teleportTo\">\r\n <Transition name=\"keyboard-mask\">\r\n <div\r\n v-if=\"modelValue && showMask\"\r\n class=\"keyboard-mask\"\r\n :style=\"maskStyles\"\r\n @click=\"handleMaskClick\"\r\n />\r\n </Transition>\r\n\r\n <Transition :name=\"isMobileDevice ? 'keyboard-slide' : 'keyboard-fade'\">\r\n <div\r\n v-if=\"modelValue\"\r\n ref=\"popupRef\"\r\n :class=\"popupClass\"\r\n :style=\"popupStyles\"\r\n @mousedown.prevent\r\n @touchstart.prevent\r\n >\r\n <VirtualKeyboard\r\n :type=\"keyboard.type.value\"\r\n :is-upper-case=\"keyboard.isUpperCase.value\"\r\n @keypress=\"handleKeyPress\"\r\n @select-option=\"handleSelectOption\"\r\n />\r\n </div>\r\n </Transition>\r\n </Teleport>\r\n</template>\r\n\r\n<style>\r\n.keyboard-popup {\r\n overflow: hidden;\r\n background-color: var(--keyboard-bg);\r\n box-shadow: var(--ld-shadow-md, none);\r\n}\r\n\r\n.keyboard-popup--desktop {\r\n min-width: var(--ld-px-280);\r\n border-radius: var(--ld-radius-lg);\r\n box-shadow: var(--ld-shadow-lg, none);\r\n}\r\n\r\n.keyboard-popup--mobile {\r\n border-radius: var(--ld-radius-none);\r\n padding-bottom: env(safe-area-inset-bottom, var(--ld-px-0));\r\n}\r\n\r\n.keyboard-popup--bottom-sheet {\r\n border-top-left-radius: var(--ld-radius-lg);\r\n border-top-right-radius: var(--ld-radius-lg);\r\n}\r\n\r\n.keyboard-mask {\r\n position: fixed;\r\n inset: 0;\r\n z-index: 999;\r\n background-color: var(--keyboard-mask-bg);\r\n}\r\n\r\n.keyboard-mask-enter-active,\r\n.keyboard-mask-leave-active {\r\n transition: opacity var(--ld-duration-fast);\r\n}\r\n.keyboard-mask-enter-from,\r\n.keyboard-mask-leave-to {\r\n opacity: 0;\r\n}\r\n.keyboard-fade-enter-active,\r\n.keyboard-fade-leave-active {\r\n transition:\r\n opacity var(--ld-duration-fast),\r\n transform var(--ld-duration-fast);\r\n}\r\n.keyboard-fade-enter-from,\r\n.keyboard-fade-leave-to {\r\n opacity: 0;\r\n transform: translateY(calc(-1 * var(--ld-px-10)));\r\n}\r\n.keyboard-slide-enter-active,\r\n.keyboard-slide-leave-active {\r\n transition: transform var(--ld-duration-normal);\r\n}\r\n.keyboard-slide-enter-from,\r\n.keyboard-slide-leave-to {\r\n transform: translateY(100%);\r\n}\r\n</style>\r\n","<script setup lang=\"ts\">\r\nimport type { KeyboardType, KeyDefinition } from '@composy/keyboard-core'\r\nimport { isMobile } from '@composy/keyboard-core'\r\nimport { computed, nextTick, ref, watch } from 'vue'\r\nimport { useKeyboard } from '../composables/useKeyboard'\r\nimport { useKeyboardPopup } from '../composables/useKeyboardPopup'\r\nimport VirtualKeyboard from './VirtualKeyboard.vue'\r\n\r\nconst props = withDefaults(\r\n defineProps<{\r\n /**\r\n * 是否显示 (v-model)\r\n */\r\n modelValue?: boolean\r\n /**\r\n * 键盘类型\r\n */\r\n type?: KeyboardType | string\r\n /**\r\n * 绑定的输入值 (v-model:value)\r\n */\r\n value?: string\r\n /**\r\n * 目标输入框元素\r\n */\r\n target?: HTMLInputElement | HTMLTextAreaElement | null\r\n /**\r\n * 最大输入长度\r\n */\r\n maxLength?: number\r\n /**\r\n * 点击外部是否关闭\r\n */\r\n closeOnClickOutside?: boolean\r\n /**\r\n * 是否启用震动反馈\r\n */\r\n enableVibrate?: boolean\r\n /**\r\n * 挂载目标\r\n */\r\n teleportTo?: string | HTMLElement\r\n }>(),\r\n {\r\n modelValue: false,\r\n type: 'qwerty',\r\n value: '',\r\n target: null,\r\n closeOnClickOutside: true,\r\n enableVibrate: true,\r\n teleportTo: 'body',\r\n }\r\n)\r\n\r\nconst emit = defineEmits<{\r\n 'update:modelValue': [visible: boolean]\r\n 'update:value': [value: string]\r\n confirm: [value: string]\r\n keypress: [key: KeyDefinition]\r\n}>()\r\n\r\n// 弹出层 DOM 引用\r\nconst popupRef = ref<HTMLElement | null>(null)\r\n\r\n// 目标元素引用\r\nconst targetRef = computed(() => props.target as HTMLElement | null)\r\n\r\n// 是否移动端\r\nconst isMobileDevice = ref(isMobile())\r\n\r\n// 创建键盘管理器\r\nconst keyboard = useKeyboard({\r\n type: props.type as KeyboardType,\r\n value: props.value,\r\n maxLength:\r\n props.maxLength ?? (props.type.startsWith('license-plate') ? 7 : undefined),\r\n enableVibrate: props.enableVibrate,\r\n})\r\n\r\n// 创建弹出层管理\r\nconst {\r\n popupStyles,\r\n maskStyles,\r\n placement,\r\n showMask,\r\n updatePosition,\r\n close: closePopup,\r\n} = useKeyboardPopup({\r\n visible: computed(() => props.modelValue),\r\n target: targetRef,\r\n popup: popupRef,\r\n closeOnClickOutside: props.closeOnClickOutside,\r\n onClose: () => {\r\n emit('update:modelValue', false)\r\n },\r\n})\r\n\r\n// 监听键盘类型变化\r\nwatch(\r\n () => props.type,\r\n newType => {\r\n keyboard.switchType(newType as KeyboardType)\r\n\r\n // 车牌键盘需要设置默认 maxLength\r\n if (newType.startsWith('license-plate') && !props.maxLength) {\r\n keyboard.setMaxLength(7)\r\n }\r\n }\r\n)\r\n\r\nwatch(\r\n () => props.maxLength,\r\n maxLength => {\r\n if (maxLength !== undefined) keyboard.setMaxLength(maxLength)\r\n }\r\n)\r\n\r\n// 监听外部 value 变化\r\nwatch(\r\n () => props.value,\r\n newValue => {\r\n if (newValue !== keyboard.value.value) {\r\n keyboard.setValue(newValue)\r\n }\r\n }\r\n)\r\n\r\n// 监听键盘内部 value 变化\r\nwatch(keyboard.value, newValue => {\r\n emit('update:value', newValue)\r\n})\r\n\r\n// 监听可见性变化\r\nwatch(\r\n () => props.modelValue,\r\n visible => {\r\n if (visible) {\r\n isMobileDevice.value = isMobile()\r\n if (props.target) {\r\n keyboard.bindInput(props.target)\r\n }\r\n keyboard.show(props.target ?? undefined)\r\n\r\n nextTick(() => {\r\n updatePosition()\r\n })\r\n } else {\r\n keyboard.hide()\r\n }\r\n },\r\n { immediate: true }\r\n)\r\n\r\n// 监听确认事件\r\nkeyboard.on('confirm', ({ value }) => {\r\n emit('confirm', value)\r\n emit('update:modelValue', false)\r\n})\r\n\r\n/**\r\n * 处理按键\r\n */\r\nconst handleKeyPress = (key: KeyDefinition) => {\r\n keyboard.handleKey(key)\r\n emit('keypress', key)\r\n}\r\n\r\n/**\r\n * 处理下拉选项选择(如邮箱后缀)\r\n */\r\nconst handleSelectOption = (option: string) => {\r\n let valueToAppend = option\r\n\r\n // 智能处理邮箱后缀:如果当前值已以 @ 结尾,而选项以 @ 开头,则去掉选项的 @\r\n if (option.startsWith('@') && keyboard.value.value.endsWith('@')) {\r\n valueToAppend = option.slice(1) // 去掉开头的 @\r\n }\r\n\r\n keyboard.appendValue(valueToAppend)\r\n}\r\n\r\n/**\r\n * 处理遮罩点击\r\n */\r\nconst handleMaskClick = () => {\r\n if (props.closeOnClickOutside) {\r\n closePopup()\r\n }\r\n}\r\n\r\n/**\r\n * 计算弹出层类名\r\n */\r\nconst popupClass = computed(() => {\r\n return [\r\n 'keyboard-popup',\r\n `keyboard-popup--${placement.value}`,\r\n {\r\n 'keyboard-popup--mobile': isMobileDevice.value,\r\n 'keyboard-popup--desktop': !isMobileDevice.value,\r\n },\r\n ]\r\n})\r\n</script>\r\n\r\n<template>\r\n <Teleport :to=\"teleportTo\">\r\n <Transition name=\"keyboard-mask\">\r\n <div\r\n v-if=\"modelValue && showMask\"\r\n class=\"keyboard-mask\"\r\n :style=\"maskStyles\"\r\n @click=\"handleMaskClick\"\r\n />\r\n </Transition>\r\n\r\n <Transition :name=\"isMobileDevice ? 'keyboard-slide' : 'keyboard-fade'\">\r\n <div\r\n v-if=\"modelValue\"\r\n ref=\"popupRef\"\r\n :class=\"popupClass\"\r\n :style=\"popupStyles\"\r\n @mousedown.prevent\r\n @touchstart.prevent\r\n >\r\n <VirtualKeyboard\r\n :type=\"keyboard.type.value\"\r\n :is-upper-case=\"keyboard.isUpperCase.value\"\r\n @keypress=\"handleKeyPress\"\r\n @select-option=\"handleSelectOption\"\r\n />\r\n </div>\r\n </Transition>\r\n </Teleport>\r\n</template>\r\n\r\n<style>\r\n.keyboard-popup {\r\n overflow: hidden;\r\n background-color: var(--keyboard-bg);\r\n box-shadow: var(--ld-shadow-md, none);\r\n}\r\n\r\n.keyboard-popup--desktop {\r\n min-width: var(--ld-px-280);\r\n border-radius: var(--ld-radius-lg);\r\n box-shadow: var(--ld-shadow-lg, none);\r\n}\r\n\r\n.keyboard-popup--mobile {\r\n border-radius: var(--ld-radius-none);\r\n padding-bottom: env(safe-area-inset-bottom, var(--ld-px-0));\r\n}\r\n\r\n.keyboard-popup--bottom-sheet {\r\n border-top-left-radius: var(--ld-radius-lg);\r\n border-top-right-radius: var(--ld-radius-lg);\r\n}\r\n\r\n.keyboard-mask {\r\n position: fixed;\r\n inset: 0;\r\n z-index: 999;\r\n background-color: var(--keyboard-mask-bg);\r\n}\r\n\r\n.keyboard-mask-enter-active,\r\n.keyboard-mask-leave-active {\r\n transition: opacity var(--ld-duration-fast);\r\n}\r\n.keyboard-mask-enter-from,\r\n.keyboard-mask-leave-to {\r\n opacity: 0;\r\n}\r\n.keyboard-fade-enter-active,\r\n.keyboard-fade-leave-active {\r\n transition:\r\n opacity var(--ld-duration-fast),\r\n transform var(--ld-duration-fast);\r\n}\r\n.keyboard-fade-enter-from,\r\n.keyboard-fade-leave-to {\r\n opacity: 0;\r\n transform: translateY(calc(-1 * var(--ld-px-10)));\r\n}\r\n.keyboard-slide-enter-active,\r\n.keyboard-slide-leave-active {\r\n transition: transform var(--ld-duration-normal);\r\n}\r\n.keyboard-slide-enter-from,\r\n.keyboard-slide-leave-to {\r\n transform: translateY(100%);\r\n}\r\n</style>\r\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAQA,MAAM,QAAQ;EA8Cd,MAAM,OAAO;EAQb,MAAM,WAAW,IAAwB,IAAI;EAG7C,MAAM,YAAY,eAAe,MAAM,MAA4B;EAGnE,MAAM,iBAAiB,IAAI,SAAS,CAAC;EAGrC,MAAM,WAAW,YAAY;GAC3B,MAAM,MAAM;GACZ,OAAO,MAAM;GACb,WACE,MAAM,cAAc,MAAM,KAAK,WAAW,eAAe,IAAI,IAAI,KAAA;GACnE,eAAe,MAAM;EACvB,CAAC;EAGD,MAAM,EACJ,aACA,YACA,WACA,UACA,gBACA,OAAO,eACL,iBAAiB;GACnB,SAAS,eAAe,MAAM,UAAU;GACxC,QAAQ;GACR,OAAO;GACP,qBAAqB,MAAM;GAC3B,eAAe;IACb,KAAK,qBAAqB,KAAK;GACjC;EACF,CAAC;EAGD,YACQ,MAAM,OACZ,YAAW;GACT,SAAS,WAAW,OAAuB;GAG3C,IAAI,QAAQ,WAAW,eAAe,KAAK,CAAC,MAAM,WAChD,SAAS,aAAa,CAAC;EAE3B,CACF;EAEA,YACQ,MAAM,YACZ,cAAa;GACX,IAAI,cAAc,KAAA,GAAW,SAAS,aAAa,SAAS;EAC9D,CACF;EAGA,YACQ,MAAM,QACZ,aAAY;GACV,IAAI,aAAa,SAAS,MAAM,OAC9B,SAAS,SAAS,QAAQ;EAE9B,CACF;EAGA,MAAM,SAAS,QAAO,aAAY;GAChC,KAAK,gBAAgB,QAAQ;EAC/B,CAAC;EAGD,YACQ,MAAM,aACZ,YAAW;GACT,IAAI,SAAS;IACX,eAAe,QAAQ,SAAS;IAChC,IAAI,MAAM,QACR,SAAS,UAAU,MAAM,MAAM;IAEjC,SAAS,KAAK,MAAM,UAAU,KAAA,CAAS;IAEvC,eAAe;KACb,eAAe;IACjB,CAAC;GACH,OACE,SAAS,KAAK;EAElB,GACA,EAAE,WAAW,KAAK,CACpB;EAGA,SAAS,GAAG,YAAY,EAAE,YAAY;GACpC,KAAK,WAAW,KAAK;GACrB,KAAK,qBAAqB,KAAK;EACjC,CAAC;EAKD,MAAM,kBAAkB,QAAuB;GAC7C,SAAS,UAAU,GAAG;GACtB,KAAK,YAAY,GAAG;EACtB;EAKA,MAAM,sBAAsB,WAAmB;GAC7C,IAAI,gBAAgB;GAGpB,IAAI,OAAO,WAAW,GAAG,KAAK,SAAS,MAAM,MAAM,SAAS,GAAG,GAC7D,gBAAgB,OAAO,MAAM,CAAC;GAGhC,SAAS,YAAY,aAAa;EACpC;EAKA,MAAM,wBAAwB;GAC5B,IAAI,MAAM,qBACR,WAAW;EAEf;EAKA,MAAM,aAAa,eAAe;GAChC,OAAO;IACL;IACA,mBAAmB,UAAU;IAC7B;KACE,0BAA0B,eAAe;KACzC,2BAA2B,CAAC,eAAe;IAC7C;GACF;EACF,CAAC;;uBCIC,YA2BW,UAAA,EA3BA,IAAI,QAAA,WAAU,GAAA,CACvB,YAOa,YAAA,EAPD,MAAK,gBAAe,GAAA;2BAM5B,CAJM,QAAA,cAAc,MAAA,QAAA,KAAA,UAAA,GADtB,mBAKE,OAAA;;KAHA,OAAM;KACL,OAAK,eAAE,MAAA,UAAA,CAAU;KACjB,SAAO;;;OAIZ,YAgBa,YAAA,EAhBA,MAAM,eAAA,QAAc,mBAAA,gBAAA,GAAA;2BAezB,CAbE,QAAA,cAAA,UAAA,GADR,mBAcM,OAAA;;cAZA;KAAJ,KAAI;KACH,OAAK,eAAE,WAAA,KAAU;KACjB,OAAK,eAAE,MAAA,WAAA,CAAW;KAClB,aAAS,OAAA,OAAA,OAAA,KAAA,oBAAV,CAAA,GAAkB,CAAA,SAAA,CAAA;KACjB,cAAU,OAAA,OAAA,OAAA,KAAA,oBAAX,CAAA,GAAmB,CAAA,SAAA,CAAA;QAEnB,YAKE,yBAAA;KAJC,MAAM,MAAA,QAAA,CAAA,CAAS,KAAK;KACpB,iBAAe,MAAA,QAAA,CAAA,CAAS,YAAY;KACpC,YAAU;KACV,gBAAe"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* ***********************************
|
|
3
|
+
* @composy/keyboard-vue v0.0.1 *
|
|
4
|
+
* Built with rollup *
|
|
5
|
+
* Build time: 2024-10-12 17:44:15 *
|
|
6
|
+
* Build mode: production *
|
|
7
|
+
* Minified: No *
|
|
8
|
+
* ***********************************
|
|
9
|
+
*/
|
|
10
|
+
import LicensePlateKeyboard_vue_vue_type_script_setup_true_lang_default from "./LicensePlateKeyboard.vue_vue_type_script_setup_true_lang.js";
|
|
11
|
+
//#region src/components/LicensePlateKeyboard.vue
|
|
12
|
+
LicensePlateKeyboard_vue_vue_type_script_setup_true_lang_default.__file = "src/components/LicensePlateKeyboard.vue";
|
|
13
|
+
var LicensePlateKeyboard_default = LicensePlateKeyboard_vue_vue_type_script_setup_true_lang_default;
|
|
14
|
+
//#endregion
|
|
15
|
+
export { LicensePlateKeyboard_default as default };
|
|
16
|
+
/*! End of @composy/keyboard-vue | Powered by @composy/builder */
|
|
17
|
+
//# sourceMappingURL=LicensePlateKeyboard.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LicensePlateKeyboard.js","names":[],"sources":["../../src/components/LicensePlateKeyboard.vue"],"sourcesContent":["<script setup lang=\"ts\">\r\nimport type { KeyDefinition } from '@composy/keyboard-core'\r\n/**\r\n * 智能车牌号键盘组件\r\n * 核心逻辑在 KeyboardManager 中实现自动切换\r\n * Vue 组件只负责 UI 展示和状态同步\r\n */\r\nimport { computed, watch } from 'vue'\r\nimport { useKeyboard } from '../composables/useKeyboard'\r\nimport VirtualKeyboard from './VirtualKeyboard.vue'\r\n\r\nconst props = withDefaults(\r\n defineProps<{\r\n /**\r\n * 当前车牌号值(双向绑定)\r\n */\r\n modelValue?: string\r\n /**\r\n * 是否新能源车牌(8位)\r\n * @default false\r\n */\r\n newEnergy?: boolean\r\n }>(),\r\n {\r\n modelValue: '',\r\n newEnergy: false,\r\n }\r\n)\r\n\r\nconst emit = defineEmits<{\r\n 'update:modelValue': [value: string]\r\n done: [value: string]\r\n}>()\r\n\r\n/**\r\n * 最大长度\r\n */\r\nconst maxLength = computed(() => (props.newEnergy ? 8 : 7))\r\n\r\n/**\r\n * 使用 KeyboardManager 管理键盘状态\r\n */\r\nconst keyboard = useKeyboard({\r\n type: 'license-plate-province',\r\n value: props.modelValue,\r\n maxLength: maxLength.value,\r\n enableVibrate: true,\r\n})\r\n\r\n// 监听外部 value 变化\r\nwatch(\r\n () => props.modelValue,\r\n newValue => {\r\n if (newValue !== keyboard.value.value) {\r\n keyboard.setValue(newValue)\r\n }\r\n }\r\n)\r\n\r\n// 监听键盘内部 value 变化\r\nwatch(keyboard.value, newValue => {\r\n emit('update:modelValue', newValue)\r\n})\r\n\r\n// 监听 maxLength 变化\r\nwatch(maxLength, newMaxLength => {\r\n keyboard.setMaxLength(newMaxLength)\r\n\r\n // 如果当前值超过新的最大长度,截断\r\n if (props.modelValue.length > newMaxLength) {\r\n const truncated = props.modelValue.slice(0, newMaxLength)\r\n keyboard.setValue(truncated)\r\n emit('update:modelValue', truncated)\r\n }\r\n})\r\n\r\n// 监听确认事件\r\nkeyboard.on('confirm', ({ value }) => {\r\n emit('done', value)\r\n})\r\n\r\n/**\r\n * 处理按键\r\n */\r\nconst handleKeyPress = (key: KeyDefinition) => {\r\n keyboard.handleKey(key)\r\n}\r\n\r\n/**\r\n * 当前位置提示\r\n */\r\nconst positionHint = computed(() => {\r\n const len = props.modelValue.length\r\n if (len === 0) return '请选择省份'\r\n if (len === 1) return '请输入字母'\r\n if (len < maxLength.value) return `第${len + 1}位`\r\n return '已完成'\r\n})\r\n</script>\r\n\r\n<template>\r\n <div class=\"license-plate-keyboard\">\r\n <!-- 输入显示区 -->\r\n <div class=\"license-plate-keyboard__display\">\r\n <div class=\"license-plate-keyboard__value\">\r\n <span\r\n v-for=\"(char, index) in modelValue.padEnd(maxLength, ' ').split('')\"\r\n :key=\"index\"\r\n class=\"license-plate-keyboard__char\"\r\n :class=\"{\r\n 'license-plate-keyboard__char--filled': char !== ' ',\r\n 'license-plate-keyboard__char--current':\r\n index === modelValue.length,\r\n 'license-plate-keyboard__char--province': index === 0,\r\n 'license-plate-keyboard__char--new-energy':\r\n newEnergy && index === 7,\r\n }\"\r\n >\r\n {{ char === ' ' ? '' : char }}\r\n </span>\r\n </div>\r\n <div class=\"license-plate-keyboard__hint\">\r\n {{ positionHint }}\r\n </div>\r\n </div>\r\n\r\n <!-- 键盘区 - 由 core 的 KeyboardManager 自动切换布局 -->\r\n <VirtualKeyboard\r\n :type=\"keyboard.type.value\"\r\n :is-upper-case=\"keyboard.isUpperCase.value\"\r\n @keypress=\"handleKeyPress\"\r\n />\r\n </div>\r\n</template>\r\n\r\n<style>\r\n.license-plate-keyboard {\r\n display: flex;\r\n flex-direction: column;\r\n background: var(--keyboard-bg);\r\n}\r\n\r\n.license-plate-keyboard__display {\r\n padding: var(--ld-spacing-md) var(--ld-spacing-lg);\r\n background: var(--keyboard-display-bg, var(--ld-bg-surface-soft));\r\n border-bottom: var(--ld-border-width-thin) solid var(--ld-border-subtle);\r\n}\r\n\r\n.license-plate-keyboard__value {\r\n display: flex;\r\n justify-content: center;\r\n gap: var(--ld-spacing-sm);\r\n margin-bottom: var(--ld-spacing-sm);\r\n}\r\n\r\n.license-plate-keyboard__char {\r\n display: flex;\r\n align-items: center;\r\n justify-content: center;\r\n width: var(--ld-px-40);\r\n height: var(--ld-px-48);\r\n border: var(--ld-border-width-medium) solid var(--ld-border);\r\n border-radius: var(--ld-radius-md);\r\n background: var(--keyboard-key-bg);\r\n color: var(--keyboard-key-color);\r\n font-size: var(--ld-font-xl);\r\n font-weight: 600;\r\n transition:\r\n border-color var(--ld-duration-fast),\r\n background-color var(--ld-duration-fast);\r\n}\r\n\r\n.license-plate-keyboard__char--filled,\r\n.license-plate-keyboard__char--current {\r\n border-color: var(--keyboard-primary-bg);\r\n background: color-mix(\r\n in srgb,\r\n var(--keyboard-primary-bg) 10%,\r\n var(--keyboard-key-bg)\r\n );\r\n}\r\n\r\n.license-plate-keyboard__char--current {\r\n animation: plate-char-pulse var(--ld-duration-slow) infinite;\r\n}\r\n\r\n.license-plate-keyboard__char--province {\r\n background: color-mix(\r\n in srgb,\r\n var(--ld-warning-500) 10%,\r\n var(--keyboard-key-bg)\r\n );\r\n}\r\n\r\n.license-plate-keyboard__char--province.license-plate-keyboard__char--filled {\r\n border-color: var(--ld-warning-500);\r\n background: color-mix(\r\n in srgb,\r\n var(--ld-warning-500) 15%,\r\n var(--keyboard-key-bg)\r\n );\r\n}\r\n\r\n.license-plate-keyboard__char--new-energy {\r\n background: color-mix(\r\n in srgb,\r\n var(--ld-success-500) 10%,\r\n var(--keyboard-key-bg)\r\n );\r\n}\r\n\r\n.license-plate-keyboard__char--new-energy.license-plate-keyboard__char--filled {\r\n border-color: var(--ld-success-500);\r\n background: color-mix(\r\n in srgb,\r\n var(--ld-success-500) 15%,\r\n var(--keyboard-key-bg)\r\n );\r\n}\r\n\r\n@keyframes plate-char-pulse {\r\n 0%,\r\n 100% {\r\n opacity: 1;\r\n }\r\n 50% {\r\n opacity: 0.6;\r\n }\r\n}\r\n\r\n.license-plate-keyboard__hint {\r\n color: var(--ld-text-muted);\r\n font-size: var(--ld-font-sm);\r\n text-align: center;\r\n}\r\n\r\n.license-plate-keyboard .plate-keyboard-row {\r\n gap: var(--ld-spacing-xs);\r\n}\r\n\r\n.license-plate-keyboard .key-plate-province,\r\n.license-plate-keyboard .key-plate-letter,\r\n.license-plate-keyboard .key-plate-number {\r\n min-width: var(--ld-px-28);\r\n height: var(--ld-px-40);\r\n border-radius: var(--keyboard-key-radius);\r\n font-size: var(--ld-font-sm);\r\n}\r\n\r\n.license-plate-keyboard .key-plate-special {\r\n background: color-mix(\r\n in srgb,\r\n var(--ld-warning-500) 20%,\r\n var(--keyboard-key-bg)\r\n );\r\n color: var(--ld-warning-700);\r\n}\r\n\r\n.license-plate-keyboard .key-plate-fn,\r\n.license-plate-keyboard .key-plate-switch {\r\n background: var(--keyboard-fn-key-bg);\r\n}\r\n\r\n.license-plate-keyboard .key-plate-switch {\r\n font-size: var(--ld-font-sm);\r\n}\r\n.license-plate-keyboard .key-plate-done {\r\n background: var(--keyboard-primary-bg);\r\n color: var(--keyboard-primary-color);\r\n font-size: var(--ld-font-sm);\r\n}\r\n</style>\r\n"],"mappings":""}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* ***********************************
|
|
3
|
+
* @composy/keyboard-vue v0.0.1 *
|
|
4
|
+
* Built with rollup *
|
|
5
|
+
* Build time: 2024-10-12 17:44:15 *
|
|
6
|
+
* Build mode: production *
|
|
7
|
+
* Minified: No *
|
|
8
|
+
* ***********************************
|
|
9
|
+
*/
|
|
10
|
+
import { useKeyboard } from "../composables/useKeyboard.js";
|
|
11
|
+
import VirtualKeyboard_default from "./VirtualKeyboard.js";
|
|
12
|
+
import { Fragment, computed, createCommentVNode, createElementBlock, createElementVNode, createVNode, defineComponent, normalizeClass, openBlock, renderList, toDisplayString, unref, watch } from "vue";
|
|
13
|
+
//#region src/components/LicensePlateKeyboard.vue?vue&type=script&setup=true&lang.ts
|
|
14
|
+
const _hoisted_1 = { class: "license-plate-keyboard" };
|
|
15
|
+
const _hoisted_2 = { class: "license-plate-keyboard__display" };
|
|
16
|
+
const _hoisted_3 = { class: "license-plate-keyboard__value" };
|
|
17
|
+
const _hoisted_4 = { class: "license-plate-keyboard__hint" };
|
|
18
|
+
var LicensePlateKeyboard_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ defineComponent({
|
|
19
|
+
__name: "LicensePlateKeyboard",
|
|
20
|
+
props: {
|
|
21
|
+
modelValue: {
|
|
22
|
+
type: String,
|
|
23
|
+
required: false,
|
|
24
|
+
default: ""
|
|
25
|
+
},
|
|
26
|
+
newEnergy: {
|
|
27
|
+
type: Boolean,
|
|
28
|
+
required: false,
|
|
29
|
+
default: false
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
emits: ["update:modelValue", "done"],
|
|
33
|
+
setup(__props, { emit: __emit }) {
|
|
34
|
+
const props = __props;
|
|
35
|
+
const emit = __emit;
|
|
36
|
+
const maxLength = computed(() => props.newEnergy ? 8 : 7);
|
|
37
|
+
const keyboard = useKeyboard({
|
|
38
|
+
type: "license-plate-province",
|
|
39
|
+
value: props.modelValue,
|
|
40
|
+
maxLength: maxLength.value,
|
|
41
|
+
enableVibrate: true
|
|
42
|
+
});
|
|
43
|
+
watch(() => props.modelValue, (newValue) => {
|
|
44
|
+
if (newValue !== keyboard.value.value) keyboard.setValue(newValue);
|
|
45
|
+
});
|
|
46
|
+
watch(keyboard.value, (newValue) => {
|
|
47
|
+
emit("update:modelValue", newValue);
|
|
48
|
+
});
|
|
49
|
+
watch(maxLength, (newMaxLength) => {
|
|
50
|
+
keyboard.setMaxLength(newMaxLength);
|
|
51
|
+
if (props.modelValue.length > newMaxLength) {
|
|
52
|
+
const truncated = props.modelValue.slice(0, newMaxLength);
|
|
53
|
+
keyboard.setValue(truncated);
|
|
54
|
+
emit("update:modelValue", truncated);
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
keyboard.on("confirm", ({ value }) => {
|
|
58
|
+
emit("done", value);
|
|
59
|
+
});
|
|
60
|
+
const handleKeyPress = (key) => {
|
|
61
|
+
keyboard.handleKey(key);
|
|
62
|
+
};
|
|
63
|
+
const positionHint = computed(() => {
|
|
64
|
+
const len = props.modelValue.length;
|
|
65
|
+
if (len === 0) return "请选择省份";
|
|
66
|
+
if (len === 1) return "请输入字母";
|
|
67
|
+
if (len < maxLength.value) return `\u7B2C${len + 1}\u4F4D`;
|
|
68
|
+
return "已完成";
|
|
69
|
+
});
|
|
70
|
+
return (_ctx, _cache) => {
|
|
71
|
+
return openBlock(), createElementBlock("div", _hoisted_1, [
|
|
72
|
+
createCommentVNode(" 输入显示区 "),
|
|
73
|
+
createElementVNode("div", _hoisted_2, [createElementVNode("div", _hoisted_3, [(openBlock(true), createElementBlock(Fragment, null, renderList(__props.modelValue.padEnd(maxLength.value, " ").split(""), (char, index) => {
|
|
74
|
+
return openBlock(), createElementBlock("span", {
|
|
75
|
+
key: index,
|
|
76
|
+
class: normalizeClass(["license-plate-keyboard__char", {
|
|
77
|
+
"license-plate-keyboard__char--filled": char !== " ",
|
|
78
|
+
"license-plate-keyboard__char--current": index === __props.modelValue.length,
|
|
79
|
+
"license-plate-keyboard__char--province": index === 0,
|
|
80
|
+
"license-plate-keyboard__char--new-energy": __props.newEnergy && index === 7
|
|
81
|
+
}])
|
|
82
|
+
}, toDisplayString(char === " " ? "" : char), 3);
|
|
83
|
+
}), 128))]), createElementVNode("div", _hoisted_4, toDisplayString(positionHint.value), 1)]),
|
|
84
|
+
createCommentVNode(" 键盘区 - 由 core 的 KeyboardManager 自动切换布局 "),
|
|
85
|
+
createVNode(VirtualKeyboard_default, {
|
|
86
|
+
type: unref(keyboard).type.value,
|
|
87
|
+
"is-upper-case": unref(keyboard).isUpperCase.value,
|
|
88
|
+
onKeypress: handleKeyPress
|
|
89
|
+
}, null, 8, ["type", "is-upper-case"])
|
|
90
|
+
]);
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
//#endregion
|
|
95
|
+
export { LicensePlateKeyboard_vue_vue_type_script_setup_true_lang_default as default };
|
|
96
|
+
/*! End of @composy/keyboard-vue | Powered by @composy/builder */
|
|
97
|
+
//# sourceMappingURL=LicensePlateKeyboard.vue_vue_type_script_setup_true_lang.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LicensePlateKeyboard.vue_vue_type_script_setup_true_lang.js","names":[],"sources":["../../src/components/LicensePlateKeyboard.vue","../../src/components/LicensePlateKeyboard.vue"],"sourcesContent":["<script setup lang=\"ts\">\r\nimport type { KeyDefinition } from '@composy/keyboard-core'\r\n/**\r\n * 智能车牌号键盘组件\r\n * 核心逻辑在 KeyboardManager 中实现自动切换\r\n * Vue 组件只负责 UI 展示和状态同步\r\n */\r\nimport { computed, watch } from 'vue'\r\nimport { useKeyboard } from '../composables/useKeyboard'\r\nimport VirtualKeyboard from './VirtualKeyboard.vue'\r\n\r\nconst props = withDefaults(\r\n defineProps<{\r\n /**\r\n * 当前车牌号值(双向绑定)\r\n */\r\n modelValue?: string\r\n /**\r\n * 是否新能源车牌(8位)\r\n * @default false\r\n */\r\n newEnergy?: boolean\r\n }>(),\r\n {\r\n modelValue: '',\r\n newEnergy: false,\r\n }\r\n)\r\n\r\nconst emit = defineEmits<{\r\n 'update:modelValue': [value: string]\r\n done: [value: string]\r\n}>()\r\n\r\n/**\r\n * 最大长度\r\n */\r\nconst maxLength = computed(() => (props.newEnergy ? 8 : 7))\r\n\r\n/**\r\n * 使用 KeyboardManager 管理键盘状态\r\n */\r\nconst keyboard = useKeyboard({\r\n type: 'license-plate-province',\r\n value: props.modelValue,\r\n maxLength: maxLength.value,\r\n enableVibrate: true,\r\n})\r\n\r\n// 监听外部 value 变化\r\nwatch(\r\n () => props.modelValue,\r\n newValue => {\r\n if (newValue !== keyboard.value.value) {\r\n keyboard.setValue(newValue)\r\n }\r\n }\r\n)\r\n\r\n// 监听键盘内部 value 变化\r\nwatch(keyboard.value, newValue => {\r\n emit('update:modelValue', newValue)\r\n})\r\n\r\n// 监听 maxLength 变化\r\nwatch(maxLength, newMaxLength => {\r\n keyboard.setMaxLength(newMaxLength)\r\n\r\n // 如果当前值超过新的最大长度,截断\r\n if (props.modelValue.length > newMaxLength) {\r\n const truncated = props.modelValue.slice(0, newMaxLength)\r\n keyboard.setValue(truncated)\r\n emit('update:modelValue', truncated)\r\n }\r\n})\r\n\r\n// 监听确认事件\r\nkeyboard.on('confirm', ({ value }) => {\r\n emit('done', value)\r\n})\r\n\r\n/**\r\n * 处理按键\r\n */\r\nconst handleKeyPress = (key: KeyDefinition) => {\r\n keyboard.handleKey(key)\r\n}\r\n\r\n/**\r\n * 当前位置提示\r\n */\r\nconst positionHint = computed(() => {\r\n const len = props.modelValue.length\r\n if (len === 0) return '请选择省份'\r\n if (len === 1) return '请输入字母'\r\n if (len < maxLength.value) return `第${len + 1}位`\r\n return '已完成'\r\n})\r\n</script>\r\n\r\n<template>\r\n <div class=\"license-plate-keyboard\">\r\n <!-- 输入显示区 -->\r\n <div class=\"license-plate-keyboard__display\">\r\n <div class=\"license-plate-keyboard__value\">\r\n <span\r\n v-for=\"(char, index) in modelValue.padEnd(maxLength, ' ').split('')\"\r\n :key=\"index\"\r\n class=\"license-plate-keyboard__char\"\r\n :class=\"{\r\n 'license-plate-keyboard__char--filled': char !== ' ',\r\n 'license-plate-keyboard__char--current':\r\n index === modelValue.length,\r\n 'license-plate-keyboard__char--province': index === 0,\r\n 'license-plate-keyboard__char--new-energy':\r\n newEnergy && index === 7,\r\n }\"\r\n >\r\n {{ char === ' ' ? '' : char }}\r\n </span>\r\n </div>\r\n <div class=\"license-plate-keyboard__hint\">\r\n {{ positionHint }}\r\n </div>\r\n </div>\r\n\r\n <!-- 键盘区 - 由 core 的 KeyboardManager 自动切换布局 -->\r\n <VirtualKeyboard\r\n :type=\"keyboard.type.value\"\r\n :is-upper-case=\"keyboard.isUpperCase.value\"\r\n @keypress=\"handleKeyPress\"\r\n />\r\n </div>\r\n</template>\r\n\r\n<style>\r\n.license-plate-keyboard {\r\n display: flex;\r\n flex-direction: column;\r\n background: var(--keyboard-bg);\r\n}\r\n\r\n.license-plate-keyboard__display {\r\n padding: var(--ld-spacing-md) var(--ld-spacing-lg);\r\n background: var(--keyboard-display-bg, var(--ld-bg-surface-soft));\r\n border-bottom: var(--ld-border-width-thin) solid var(--ld-border-subtle);\r\n}\r\n\r\n.license-plate-keyboard__value {\r\n display: flex;\r\n justify-content: center;\r\n gap: var(--ld-spacing-sm);\r\n margin-bottom: var(--ld-spacing-sm);\r\n}\r\n\r\n.license-plate-keyboard__char {\r\n display: flex;\r\n align-items: center;\r\n justify-content: center;\r\n width: var(--ld-px-40);\r\n height: var(--ld-px-48);\r\n border: var(--ld-border-width-medium) solid var(--ld-border);\r\n border-radius: var(--ld-radius-md);\r\n background: var(--keyboard-key-bg);\r\n color: var(--keyboard-key-color);\r\n font-size: var(--ld-font-xl);\r\n font-weight: 600;\r\n transition:\r\n border-color var(--ld-duration-fast),\r\n background-color var(--ld-duration-fast);\r\n}\r\n\r\n.license-plate-keyboard__char--filled,\r\n.license-plate-keyboard__char--current {\r\n border-color: var(--keyboard-primary-bg);\r\n background: color-mix(\r\n in srgb,\r\n var(--keyboard-primary-bg) 10%,\r\n var(--keyboard-key-bg)\r\n );\r\n}\r\n\r\n.license-plate-keyboard__char--current {\r\n animation: plate-char-pulse var(--ld-duration-slow) infinite;\r\n}\r\n\r\n.license-plate-keyboard__char--province {\r\n background: color-mix(\r\n in srgb,\r\n var(--ld-warning-500) 10%,\r\n var(--keyboard-key-bg)\r\n );\r\n}\r\n\r\n.license-plate-keyboard__char--province.license-plate-keyboard__char--filled {\r\n border-color: var(--ld-warning-500);\r\n background: color-mix(\r\n in srgb,\r\n var(--ld-warning-500) 15%,\r\n var(--keyboard-key-bg)\r\n );\r\n}\r\n\r\n.license-plate-keyboard__char--new-energy {\r\n background: color-mix(\r\n in srgb,\r\n var(--ld-success-500) 10%,\r\n var(--keyboard-key-bg)\r\n );\r\n}\r\n\r\n.license-plate-keyboard__char--new-energy.license-plate-keyboard__char--filled {\r\n border-color: var(--ld-success-500);\r\n background: color-mix(\r\n in srgb,\r\n var(--ld-success-500) 15%,\r\n var(--keyboard-key-bg)\r\n );\r\n}\r\n\r\n@keyframes plate-char-pulse {\r\n 0%,\r\n 100% {\r\n opacity: 1;\r\n }\r\n 50% {\r\n opacity: 0.6;\r\n }\r\n}\r\n\r\n.license-plate-keyboard__hint {\r\n color: var(--ld-text-muted);\r\n font-size: var(--ld-font-sm);\r\n text-align: center;\r\n}\r\n\r\n.license-plate-keyboard .plate-keyboard-row {\r\n gap: var(--ld-spacing-xs);\r\n}\r\n\r\n.license-plate-keyboard .key-plate-province,\r\n.license-plate-keyboard .key-plate-letter,\r\n.license-plate-keyboard .key-plate-number {\r\n min-width: var(--ld-px-28);\r\n height: var(--ld-px-40);\r\n border-radius: var(--keyboard-key-radius);\r\n font-size: var(--ld-font-sm);\r\n}\r\n\r\n.license-plate-keyboard .key-plate-special {\r\n background: color-mix(\r\n in srgb,\r\n var(--ld-warning-500) 20%,\r\n var(--keyboard-key-bg)\r\n );\r\n color: var(--ld-warning-700);\r\n}\r\n\r\n.license-plate-keyboard .key-plate-fn,\r\n.license-plate-keyboard .key-plate-switch {\r\n background: var(--keyboard-fn-key-bg);\r\n}\r\n\r\n.license-plate-keyboard .key-plate-switch {\r\n font-size: var(--ld-font-sm);\r\n}\r\n.license-plate-keyboard .key-plate-done {\r\n background: var(--keyboard-primary-bg);\r\n color: var(--keyboard-primary-color);\r\n font-size: var(--ld-font-sm);\r\n}\r\n</style>\r\n","<script setup lang=\"ts\">\r\nimport type { KeyDefinition } from '@composy/keyboard-core'\r\n/**\r\n * 智能车牌号键盘组件\r\n * 核心逻辑在 KeyboardManager 中实现自动切换\r\n * Vue 组件只负责 UI 展示和状态同步\r\n */\r\nimport { computed, watch } from 'vue'\r\nimport { useKeyboard } from '../composables/useKeyboard'\r\nimport VirtualKeyboard from './VirtualKeyboard.vue'\r\n\r\nconst props = withDefaults(\r\n defineProps<{\r\n /**\r\n * 当前车牌号值(双向绑定)\r\n */\r\n modelValue?: string\r\n /**\r\n * 是否新能源车牌(8位)\r\n * @default false\r\n */\r\n newEnergy?: boolean\r\n }>(),\r\n {\r\n modelValue: '',\r\n newEnergy: false,\r\n }\r\n)\r\n\r\nconst emit = defineEmits<{\r\n 'update:modelValue': [value: string]\r\n done: [value: string]\r\n}>()\r\n\r\n/**\r\n * 最大长度\r\n */\r\nconst maxLength = computed(() => (props.newEnergy ? 8 : 7))\r\n\r\n/**\r\n * 使用 KeyboardManager 管理键盘状态\r\n */\r\nconst keyboard = useKeyboard({\r\n type: 'license-plate-province',\r\n value: props.modelValue,\r\n maxLength: maxLength.value,\r\n enableVibrate: true,\r\n})\r\n\r\n// 监听外部 value 变化\r\nwatch(\r\n () => props.modelValue,\r\n newValue => {\r\n if (newValue !== keyboard.value.value) {\r\n keyboard.setValue(newValue)\r\n }\r\n }\r\n)\r\n\r\n// 监听键盘内部 value 变化\r\nwatch(keyboard.value, newValue => {\r\n emit('update:modelValue', newValue)\r\n})\r\n\r\n// 监听 maxLength 变化\r\nwatch(maxLength, newMaxLength => {\r\n keyboard.setMaxLength(newMaxLength)\r\n\r\n // 如果当前值超过新的最大长度,截断\r\n if (props.modelValue.length > newMaxLength) {\r\n const truncated = props.modelValue.slice(0, newMaxLength)\r\n keyboard.setValue(truncated)\r\n emit('update:modelValue', truncated)\r\n }\r\n})\r\n\r\n// 监听确认事件\r\nkeyboard.on('confirm', ({ value }) => {\r\n emit('done', value)\r\n})\r\n\r\n/**\r\n * 处理按键\r\n */\r\nconst handleKeyPress = (key: KeyDefinition) => {\r\n keyboard.handleKey(key)\r\n}\r\n\r\n/**\r\n * 当前位置提示\r\n */\r\nconst positionHint = computed(() => {\r\n const len = props.modelValue.length\r\n if (len === 0) return '请选择省份'\r\n if (len === 1) return '请输入字母'\r\n if (len < maxLength.value) return `第${len + 1}位`\r\n return '已完成'\r\n})\r\n</script>\r\n\r\n<template>\r\n <div class=\"license-plate-keyboard\">\r\n <!-- 输入显示区 -->\r\n <div class=\"license-plate-keyboard__display\">\r\n <div class=\"license-plate-keyboard__value\">\r\n <span\r\n v-for=\"(char, index) in modelValue.padEnd(maxLength, ' ').split('')\"\r\n :key=\"index\"\r\n class=\"license-plate-keyboard__char\"\r\n :class=\"{\r\n 'license-plate-keyboard__char--filled': char !== ' ',\r\n 'license-plate-keyboard__char--current':\r\n index === modelValue.length,\r\n 'license-plate-keyboard__char--province': index === 0,\r\n 'license-plate-keyboard__char--new-energy':\r\n newEnergy && index === 7,\r\n }\"\r\n >\r\n {{ char === ' ' ? '' : char }}\r\n </span>\r\n </div>\r\n <div class=\"license-plate-keyboard__hint\">\r\n {{ positionHint }}\r\n </div>\r\n </div>\r\n\r\n <!-- 键盘区 - 由 core 的 KeyboardManager 自动切换布局 -->\r\n <VirtualKeyboard\r\n :type=\"keyboard.type.value\"\r\n :is-upper-case=\"keyboard.isUpperCase.value\"\r\n @keypress=\"handleKeyPress\"\r\n />\r\n </div>\r\n</template>\r\n\r\n<style>\r\n.license-plate-keyboard {\r\n display: flex;\r\n flex-direction: column;\r\n background: var(--keyboard-bg);\r\n}\r\n\r\n.license-plate-keyboard__display {\r\n padding: var(--ld-spacing-md) var(--ld-spacing-lg);\r\n background: var(--keyboard-display-bg, var(--ld-bg-surface-soft));\r\n border-bottom: var(--ld-border-width-thin) solid var(--ld-border-subtle);\r\n}\r\n\r\n.license-plate-keyboard__value {\r\n display: flex;\r\n justify-content: center;\r\n gap: var(--ld-spacing-sm);\r\n margin-bottom: var(--ld-spacing-sm);\r\n}\r\n\r\n.license-plate-keyboard__char {\r\n display: flex;\r\n align-items: center;\r\n justify-content: center;\r\n width: var(--ld-px-40);\r\n height: var(--ld-px-48);\r\n border: var(--ld-border-width-medium) solid var(--ld-border);\r\n border-radius: var(--ld-radius-md);\r\n background: var(--keyboard-key-bg);\r\n color: var(--keyboard-key-color);\r\n font-size: var(--ld-font-xl);\r\n font-weight: 600;\r\n transition:\r\n border-color var(--ld-duration-fast),\r\n background-color var(--ld-duration-fast);\r\n}\r\n\r\n.license-plate-keyboard__char--filled,\r\n.license-plate-keyboard__char--current {\r\n border-color: var(--keyboard-primary-bg);\r\n background: color-mix(\r\n in srgb,\r\n var(--keyboard-primary-bg) 10%,\r\n var(--keyboard-key-bg)\r\n );\r\n}\r\n\r\n.license-plate-keyboard__char--current {\r\n animation: plate-char-pulse var(--ld-duration-slow) infinite;\r\n}\r\n\r\n.license-plate-keyboard__char--province {\r\n background: color-mix(\r\n in srgb,\r\n var(--ld-warning-500) 10%,\r\n var(--keyboard-key-bg)\r\n );\r\n}\r\n\r\n.license-plate-keyboard__char--province.license-plate-keyboard__char--filled {\r\n border-color: var(--ld-warning-500);\r\n background: color-mix(\r\n in srgb,\r\n var(--ld-warning-500) 15%,\r\n var(--keyboard-key-bg)\r\n );\r\n}\r\n\r\n.license-plate-keyboard__char--new-energy {\r\n background: color-mix(\r\n in srgb,\r\n var(--ld-success-500) 10%,\r\n var(--keyboard-key-bg)\r\n );\r\n}\r\n\r\n.license-plate-keyboard__char--new-energy.license-plate-keyboard__char--filled {\r\n border-color: var(--ld-success-500);\r\n background: color-mix(\r\n in srgb,\r\n var(--ld-success-500) 15%,\r\n var(--keyboard-key-bg)\r\n );\r\n}\r\n\r\n@keyframes plate-char-pulse {\r\n 0%,\r\n 100% {\r\n opacity: 1;\r\n }\r\n 50% {\r\n opacity: 0.6;\r\n }\r\n}\r\n\r\n.license-plate-keyboard__hint {\r\n color: var(--ld-text-muted);\r\n font-size: var(--ld-font-sm);\r\n text-align: center;\r\n}\r\n\r\n.license-plate-keyboard .plate-keyboard-row {\r\n gap: var(--ld-spacing-xs);\r\n}\r\n\r\n.license-plate-keyboard .key-plate-province,\r\n.license-plate-keyboard .key-plate-letter,\r\n.license-plate-keyboard .key-plate-number {\r\n min-width: var(--ld-px-28);\r\n height: var(--ld-px-40);\r\n border-radius: var(--keyboard-key-radius);\r\n font-size: var(--ld-font-sm);\r\n}\r\n\r\n.license-plate-keyboard .key-plate-special {\r\n background: color-mix(\r\n in srgb,\r\n var(--ld-warning-500) 20%,\r\n var(--keyboard-key-bg)\r\n );\r\n color: var(--ld-warning-700);\r\n}\r\n\r\n.license-plate-keyboard .key-plate-fn,\r\n.license-plate-keyboard .key-plate-switch {\r\n background: var(--keyboard-fn-key-bg);\r\n}\r\n\r\n.license-plate-keyboard .key-plate-switch {\r\n font-size: var(--ld-font-sm);\r\n}\r\n.license-plate-keyboard .key-plate-done {\r\n background: var(--keyboard-primary-bg);\r\n color: var(--keyboard-primary-color);\r\n font-size: var(--ld-font-sm);\r\n}\r\n</style>\r\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAWA,MAAM,QAAQ;EAkBd,MAAM,OAAO;EAQb,MAAM,YAAY,eAAgB,MAAM,YAAY,IAAI,CAAE;EAK1D,MAAM,WAAW,YAAY;GAC3B,MAAM;GACN,OAAO,MAAM;GACb,WAAW,UAAU;GACrB,eAAe;EACjB,CAAC;EAGD,YACQ,MAAM,aACZ,aAAY;GACV,IAAI,aAAa,SAAS,MAAM,OAC9B,SAAS,SAAS,QAAQ;EAE9B,CACF;EAGA,MAAM,SAAS,QAAO,aAAY;GAChC,KAAK,qBAAqB,QAAQ;EACpC,CAAC;EAGD,MAAM,YAAW,iBAAgB;GAC/B,SAAS,aAAa,YAAY;GAGlC,IAAI,MAAM,WAAW,SAAS,cAAc;IAC1C,MAAM,YAAY,MAAM,WAAW,MAAM,GAAG,YAAY;IACxD,SAAS,SAAS,SAAS;IAC3B,KAAK,qBAAqB,SAAS;GACrC;EACF,CAAC;EAGD,SAAS,GAAG,YAAY,EAAE,YAAY;GACpC,KAAK,QAAQ,KAAK;EACpB,CAAC;EAKD,MAAM,kBAAkB,QAAuB;GAC7C,SAAS,UAAU,GAAG;EACxB;EAKA,MAAM,eAAe,eAAe;GAClC,MAAM,MAAM,MAAM,WAAW;GAC7B,IAAI,QAAQ,GAAG,OAAO;GACtB,IAAI,QAAQ,GAAG,OAAO;GACtB,IAAI,MAAM,UAAU,OAAO,OAAO,SAAI,MAAM,EAAC;GAC7C,OAAO;EACT,CAAC;;uBCIC,mBA+BM,OA/BN,YA+BM;IA9BJ,mBAAA,SAAA;IACA,mBAqBM,OArBN,YAqBM,CApBJ,mBAgBM,OAhBN,YAgBM,EAAA,UAAA,IAAA,GAfJ,mBAcO,UAAA,MAAA,WAbmB,QAAA,WAAW,OAAO,UAAA,OAAS,GAAA,CAAA,CAAO,MAAK,EAAA,IAAvD,MAAM,UAAK;yBADrB,mBAcO,QAAA;MAZJ,KAAK;MACN,OAAK,eAAA,CAAC,gCAA8B;+CAC2B,SAAI;gDAA+E,UAAU,QAAA,WAAW;iDAA+D,UAAK;mDAAgF,QAAA,aAAa,UAAK;;wBAS1U,SAAI,MAAA,KAAgB,IAAI,GAAA,CAAA;iBAG/B,mBAEM,OAFN,YAEM,gBADD,aAAA,KAAY,GAAA,CAAA,CAAA,CAAA;IAInB,mBAAA,yCAAA;IACA,YAIE,yBAAA;KAHC,MAAM,MAAA,QAAA,CAAA,CAAS,KAAK;KACpB,iBAAe,MAAA,QAAA,CAAA,CAAS,YAAY;KACpC,YAAU"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* ***********************************
|
|
3
|
+
* @composy/keyboard-vue v0.0.1 *
|
|
4
|
+
* Built with rollup *
|
|
5
|
+
* Build time: 2024-10-12 17:44:15 *
|
|
6
|
+
* Build mode: production *
|
|
7
|
+
* Minified: No *
|
|
8
|
+
* ***********************************
|
|
9
|
+
*/
|
|
10
|
+
import VirtualKeyboard_vue_vue_type_script_setup_true_lang_default from "./VirtualKeyboard.vue_vue_type_script_setup_true_lang.js";
|
|
11
|
+
//#region src/components/VirtualKeyboard.vue
|
|
12
|
+
VirtualKeyboard_vue_vue_type_script_setup_true_lang_default.__file = "src/components/VirtualKeyboard.vue";
|
|
13
|
+
var VirtualKeyboard_default = VirtualKeyboard_vue_vue_type_script_setup_true_lang_default;
|
|
14
|
+
//#endregion
|
|
15
|
+
export { VirtualKeyboard_default as default };
|
|
16
|
+
/*! End of @composy/keyboard-vue | Powered by @composy/builder */
|
|
17
|
+
//# sourceMappingURL=VirtualKeyboard.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"VirtualKeyboard.js","names":[],"sources":["../../src/components/VirtualKeyboard.vue"],"sourcesContent":["<script setup lang=\"ts\">\r\nimport type {\r\n KeyboardConfig,\r\n KeyboardType,\r\n KeyDefinition,\r\n} from '@composy/keyboard-core'\r\nimport { getLayout } from '@composy/keyboard-core'\r\nimport { computed, ref } from 'vue'\r\nimport KeyboardKey from './KeyboardKey.vue'\r\n\r\nconst props = withDefaults(\r\n defineProps<{\r\n /**\r\n * 键盘类型\r\n */\r\n type?: KeyboardType | string\r\n /**\r\n * 是否大写状态\r\n */\r\n isUpperCase?: boolean\r\n /**\r\n * 自定义布局配置\r\n */\r\n layout?: KeyboardConfig\r\n /**\r\n * 按键基础宽度\r\n */\r\n keyWidth?: number\r\n }>(),\r\n {\r\n type: 'qwerty',\r\n isUpperCase: false,\r\n keyWidth: 36,\r\n }\r\n)\r\n\r\nconst emit = defineEmits<{\r\n keypress: [key: KeyDefinition]\r\n selectOption: [option: string]\r\n}>()\r\n\r\n/**\r\n * 选项面板状态\r\n */\r\nconst showOptionsPanel = ref(false)\r\nconst currentOptions = ref<string[]>([])\r\n\r\n/**\r\n * 当前布局配置\r\n */\r\nconst currentLayout = computed(() => {\r\n if (props.layout) {\r\n return props.layout\r\n }\r\n return getLayout(props.type) ?? null\r\n})\r\n\r\n/**\r\n * 处理按键\r\n */\r\nconst handleKeyPress = (key: KeyDefinition) => {\r\n emit('keypress', key)\r\n}\r\n\r\n/**\r\n * 显示选项面板\r\n */\r\nconst handleShowOptions = (options: string[]) => {\r\n currentOptions.value = options\r\n showOptionsPanel.value = true\r\n}\r\n\r\n/**\r\n * 处理选项选择\r\n */\r\nconst handleSelectOption = (option: string, event: MouseEvent | TouchEvent) => {\r\n event.preventDefault()\r\n event.stopPropagation()\r\n showOptionsPanel.value = false\r\n emit('selectOption', option)\r\n}\r\n\r\n/**\r\n * 关闭选项面板\r\n */\r\nconst closeOptionsPanel = () => {\r\n showOptionsPanel.value = false\r\n}\r\n\r\n/**\r\n * 计算每行的总宽度,用于居中对齐\r\n */\r\nconst getRowStyle = () => {\r\n // 可以根据需要添加行样式\r\n return {}\r\n}\r\n</script>\r\n\r\n<template>\r\n <div class=\"virtual-keyboard\">\r\n <template v-if=\"currentLayout\">\r\n <div\r\n v-for=\"(row, rowIndex) in currentLayout.rows\"\r\n :key=\"rowIndex\"\r\n class=\"virtual-keyboard__row\"\r\n :class=\"row.className\"\r\n :style=\"getRowStyle()\"\r\n >\r\n <KeyboardKey\r\n v-for=\"key in row.keys\"\r\n :key=\"key.id\"\r\n :key-def=\"key\"\r\n :is-upper-case=\"isUpperCase\"\r\n :base-width=\"keyWidth\"\r\n :use-flex=\"row.className === 'numpad-row'\"\r\n @press=\"handleKeyPress\"\r\n @show-options=\"handleShowOptions\"\r\n />\r\n </div>\r\n </template>\r\n <div v-else class=\"virtual-keyboard__empty\">键盘布局未找到</div>\r\n\r\n <!-- 选项面板 -->\r\n <Transition name=\"options-panel\">\r\n <div v-if=\"showOptionsPanel\" class=\"keyboard-options-panel\">\r\n <div class=\"keyboard-options-panel__header\">\r\n <span class=\"keyboard-options-panel__title\">选择邮箱后缀</span>\r\n <button\r\n class=\"keyboard-options-panel__close\"\r\n type=\"button\"\r\n @click=\"closeOptionsPanel\"\r\n @touchstart.prevent=\"closeOptionsPanel\"\r\n >\r\n ×\r\n </button>\r\n </div>\r\n <div class=\"keyboard-options-panel__grid\">\r\n <button\r\n v-for=\"option in currentOptions\"\r\n :key=\"option\"\r\n class=\"keyboard-options-panel__item\"\r\n type=\"button\"\r\n @mousedown.prevent=\"e => handleSelectOption(option, e)\"\r\n @touchstart.prevent=\"e => handleSelectOption(option, e)\"\r\n >\r\n {{ option }}\r\n </button>\r\n </div>\r\n </div>\r\n </Transition>\r\n </div>\r\n</template>\r\n\r\n<style>\r\n.virtual-keyboard {\r\n --key-gap: var(--keyboard-key-gap);\r\n position: relative;\r\n display: flex;\r\n flex-direction: column;\r\n align-items: center;\r\n gap: var(--key-gap);\r\n padding: var(--keyboard-padding);\r\n background-color: var(--keyboard-bg);\r\n user-select: none;\r\n -webkit-user-select: none;\r\n overflow: hidden;\r\n font-family: var(--ld-font-family);\r\n}\r\n\r\n.virtual-keyboard__row {\r\n display: flex;\r\n justify-content: center;\r\n gap: var(--key-gap);\r\n width: 100%;\r\n padding: 0 var(--ld-px-2);\r\n}\r\n\r\n.virtual-keyboard__row.numpad-row {\r\n justify-content: stretch;\r\n}\r\n.virtual-keyboard__row.numpad-row .keyboard-key-wrapper {\r\n flex: 1;\r\n}\r\n\r\n.virtual-keyboard__empty {\r\n padding: var(--ld-spacing-lg);\r\n color: var(--ld-text-muted);\r\n text-align: center;\r\n}\r\n\r\n.keyboard-options-panel {\r\n position: absolute;\r\n inset: 0;\r\n z-index: 10;\r\n display: flex;\r\n flex-direction: column;\r\n padding: var(--ld-spacing-sm);\r\n background: var(--keyboard-bg);\r\n}\r\n\r\n.keyboard-options-panel__header {\r\n display: flex;\r\n align-items: center;\r\n justify-content: space-between;\r\n padding: var(--ld-spacing-sm) var(--ld-spacing-sm) var(--ld-spacing-md);\r\n margin-bottom: var(--ld-spacing-sm);\r\n border-bottom: var(--ld-border-width-thin) solid var(--ld-border-subtle);\r\n}\r\n\r\n.keyboard-options-panel__title {\r\n color: var(--keyboard-key-color);\r\n font-size: var(--ld-font-sm);\r\n font-weight: 600;\r\n}\r\n\r\n.keyboard-options-panel__close {\r\n display: flex;\r\n align-items: center;\r\n justify-content: center;\r\n width: var(--ld-px-28);\r\n height: var(--ld-px-28);\r\n border: 0;\r\n border-radius: var(--ld-radius-full);\r\n background: var(--keyboard-fn-key-bg);\r\n color: var(--keyboard-key-color);\r\n font-size: var(--ld-font-lg);\r\n line-height: 1;\r\n cursor: pointer;\r\n}\r\n\r\n.keyboard-options-panel__close:active {\r\n background: var(--keyboard-fn-key-active-bg);\r\n}\r\n\r\n.keyboard-options-panel__grid {\r\n display: grid;\r\n flex: 1;\r\n grid-template-columns: repeat(3, 1fr);\r\n gap: var(--ld-spacing-sm);\r\n padding: var(--ld-spacing-xs) 0;\r\n overflow-y: auto;\r\n}\r\n\r\n.keyboard-options-panel__item {\r\n padding: var(--ld-spacing-md) var(--ld-spacing-sm);\r\n border: 0;\r\n border-radius: var(--ld-radius-md);\r\n background: var(--keyboard-key-bg);\r\n color: var(--keyboard-key-color);\r\n font-size: var(--ld-font-sm);\r\n font-weight: 500;\r\n cursor: pointer;\r\n box-shadow: var(--ld-shadow-sm, none);\r\n transition:\r\n background-color var(--ld-duration-fast),\r\n transform var(--ld-duration-fast);\r\n}\r\n\r\n.keyboard-options-panel__item:active {\r\n background: var(--keyboard-key-active-bg);\r\n transform: scale(0.96);\r\n}\r\n\r\n.options-panel-enter-active,\r\n.options-panel-leave-active {\r\n transition:\r\n opacity var(--ld-duration-fast),\r\n transform var(--ld-duration-fast);\r\n}\r\n\r\n.options-panel-enter-from,\r\n.options-panel-leave-to {\r\n opacity: 0;\r\n transform: translateY(var(--ld-px-20));\r\n}\r\n</style>\r\n"],"mappings":""}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* ***********************************
|
|
3
|
+
* @composy/keyboard-vue v0.0.1 *
|
|
4
|
+
* Built with rollup *
|
|
5
|
+
* Build time: 2024-10-12 17:44:15 *
|
|
6
|
+
* Build mode: production *
|
|
7
|
+
* Minified: No *
|
|
8
|
+
* ***********************************
|
|
9
|
+
*/
|
|
10
|
+
import KeyboardKey_default from "./KeyboardKey.js";
|
|
11
|
+
import { Fragment, Transition, computed, createBlock, createCommentVNode, createElementBlock, createElementVNode, createVNode, defineComponent, normalizeClass, normalizeStyle, openBlock, ref, renderList, toDisplayString, withCtx, withModifiers } from "vue";
|
|
12
|
+
import { getLayout } from "@composy/keyboard-core";
|
|
13
|
+
//#region src/components/VirtualKeyboard.vue?vue&type=script&setup=true&lang.ts
|
|
14
|
+
const _hoisted_1 = { class: "virtual-keyboard" };
|
|
15
|
+
const _hoisted_2 = {
|
|
16
|
+
key: 1,
|
|
17
|
+
class: "virtual-keyboard__empty"
|
|
18
|
+
};
|
|
19
|
+
const _hoisted_3 = {
|
|
20
|
+
key: 0,
|
|
21
|
+
class: "keyboard-options-panel"
|
|
22
|
+
};
|
|
23
|
+
const _hoisted_4 = { class: "keyboard-options-panel__header" };
|
|
24
|
+
const _hoisted_5 = { class: "keyboard-options-panel__grid" };
|
|
25
|
+
const _hoisted_6 = ["onMousedown", "onTouchstart"];
|
|
26
|
+
var VirtualKeyboard_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ defineComponent({
|
|
27
|
+
__name: "VirtualKeyboard",
|
|
28
|
+
props: {
|
|
29
|
+
type: {
|
|
30
|
+
type: String,
|
|
31
|
+
required: false,
|
|
32
|
+
default: "qwerty"
|
|
33
|
+
},
|
|
34
|
+
isUpperCase: {
|
|
35
|
+
type: Boolean,
|
|
36
|
+
required: false,
|
|
37
|
+
default: false
|
|
38
|
+
},
|
|
39
|
+
layout: {
|
|
40
|
+
type: Object,
|
|
41
|
+
required: false
|
|
42
|
+
},
|
|
43
|
+
keyWidth: {
|
|
44
|
+
type: Number,
|
|
45
|
+
required: false,
|
|
46
|
+
default: 36
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
emits: ["keypress", "selectOption"],
|
|
50
|
+
setup(__props, { emit: __emit }) {
|
|
51
|
+
const props = __props;
|
|
52
|
+
const emit = __emit;
|
|
53
|
+
const showOptionsPanel = ref(false);
|
|
54
|
+
const currentOptions = ref([]);
|
|
55
|
+
const currentLayout = computed(() => {
|
|
56
|
+
if (props.layout) return props.layout;
|
|
57
|
+
return getLayout(props.type) ?? null;
|
|
58
|
+
});
|
|
59
|
+
const handleKeyPress = (key) => {
|
|
60
|
+
emit("keypress", key);
|
|
61
|
+
};
|
|
62
|
+
const handleShowOptions = (options) => {
|
|
63
|
+
currentOptions.value = options;
|
|
64
|
+
showOptionsPanel.value = true;
|
|
65
|
+
};
|
|
66
|
+
const handleSelectOption = (option, event) => {
|
|
67
|
+
event.preventDefault();
|
|
68
|
+
event.stopPropagation();
|
|
69
|
+
showOptionsPanel.value = false;
|
|
70
|
+
emit("selectOption", option);
|
|
71
|
+
};
|
|
72
|
+
const closeOptionsPanel = () => {
|
|
73
|
+
showOptionsPanel.value = false;
|
|
74
|
+
};
|
|
75
|
+
const getRowStyle = () => {
|
|
76
|
+
return {};
|
|
77
|
+
};
|
|
78
|
+
return (_ctx, _cache) => {
|
|
79
|
+
return openBlock(), createElementBlock("div", _hoisted_1, [
|
|
80
|
+
currentLayout.value ? (openBlock(true), createElementBlock(Fragment, { key: 0 }, renderList(currentLayout.value.rows, (row, rowIndex) => {
|
|
81
|
+
return openBlock(), createElementBlock("div", {
|
|
82
|
+
key: rowIndex,
|
|
83
|
+
class: normalizeClass(["virtual-keyboard__row", row.className]),
|
|
84
|
+
style: normalizeStyle(getRowStyle())
|
|
85
|
+
}, [(openBlock(true), createElementBlock(Fragment, null, renderList(row.keys, (key) => {
|
|
86
|
+
return openBlock(), createBlock(KeyboardKey_default, {
|
|
87
|
+
key: key.id,
|
|
88
|
+
"key-def": key,
|
|
89
|
+
"is-upper-case": __props.isUpperCase,
|
|
90
|
+
"base-width": __props.keyWidth,
|
|
91
|
+
"use-flex": row.className === "numpad-row",
|
|
92
|
+
onPress: handleKeyPress,
|
|
93
|
+
onShowOptions: handleShowOptions
|
|
94
|
+
}, null, 8, [
|
|
95
|
+
"key-def",
|
|
96
|
+
"is-upper-case",
|
|
97
|
+
"base-width",
|
|
98
|
+
"use-flex"
|
|
99
|
+
]);
|
|
100
|
+
}), 128))], 6);
|
|
101
|
+
}), 128)) : (openBlock(), createElementBlock("div", _hoisted_2, "键盘布局未找到")),
|
|
102
|
+
createCommentVNode(" 选项面板 "),
|
|
103
|
+
createVNode(Transition, { name: "options-panel" }, {
|
|
104
|
+
default: withCtx(() => [showOptionsPanel.value ? (openBlock(), createElementBlock("div", _hoisted_3, [createElementVNode("div", _hoisted_4, [_cache[0] || (_cache[0] = createElementVNode("span", { class: "keyboard-options-panel__title" }, "选择邮箱后缀", -1)), createElementVNode("button", {
|
|
105
|
+
class: "keyboard-options-panel__close",
|
|
106
|
+
type: "button",
|
|
107
|
+
onClick: closeOptionsPanel,
|
|
108
|
+
onTouchstart: withModifiers(closeOptionsPanel, ["prevent"])
|
|
109
|
+
}, " × ", 32)]), createElementVNode("div", _hoisted_5, [(openBlock(true), createElementBlock(Fragment, null, renderList(currentOptions.value, (option) => {
|
|
110
|
+
return openBlock(), createElementBlock("button", {
|
|
111
|
+
key: option,
|
|
112
|
+
class: "keyboard-options-panel__item",
|
|
113
|
+
type: "button",
|
|
114
|
+
onMousedown: withModifiers((e) => handleSelectOption(option, e), ["prevent"]),
|
|
115
|
+
onTouchstart: withModifiers((e) => handleSelectOption(option, e), ["prevent"])
|
|
116
|
+
}, toDisplayString(option), 41, _hoisted_6);
|
|
117
|
+
}), 128))])])) : createCommentVNode("v-if", true)]),
|
|
118
|
+
_: 1
|
|
119
|
+
})
|
|
120
|
+
]);
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
//#endregion
|
|
125
|
+
export { VirtualKeyboard_vue_vue_type_script_setup_true_lang_default as default };
|
|
126
|
+
/*! End of @composy/keyboard-vue | Powered by @composy/builder */
|
|
127
|
+
//# sourceMappingURL=VirtualKeyboard.vue_vue_type_script_setup_true_lang.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"VirtualKeyboard.vue_vue_type_script_setup_true_lang.js","names":[],"sources":["../../src/components/VirtualKeyboard.vue","../../src/components/VirtualKeyboard.vue"],"sourcesContent":["<script setup lang=\"ts\">\r\nimport type {\r\n KeyboardConfig,\r\n KeyboardType,\r\n KeyDefinition,\r\n} from '@composy/keyboard-core'\r\nimport { getLayout } from '@composy/keyboard-core'\r\nimport { computed, ref } from 'vue'\r\nimport KeyboardKey from './KeyboardKey.vue'\r\n\r\nconst props = withDefaults(\r\n defineProps<{\r\n /**\r\n * 键盘类型\r\n */\r\n type?: KeyboardType | string\r\n /**\r\n * 是否大写状态\r\n */\r\n isUpperCase?: boolean\r\n /**\r\n * 自定义布局配置\r\n */\r\n layout?: KeyboardConfig\r\n /**\r\n * 按键基础宽度\r\n */\r\n keyWidth?: number\r\n }>(),\r\n {\r\n type: 'qwerty',\r\n isUpperCase: false,\r\n keyWidth: 36,\r\n }\r\n)\r\n\r\nconst emit = defineEmits<{\r\n keypress: [key: KeyDefinition]\r\n selectOption: [option: string]\r\n}>()\r\n\r\n/**\r\n * 选项面板状态\r\n */\r\nconst showOptionsPanel = ref(false)\r\nconst currentOptions = ref<string[]>([])\r\n\r\n/**\r\n * 当前布局配置\r\n */\r\nconst currentLayout = computed(() => {\r\n if (props.layout) {\r\n return props.layout\r\n }\r\n return getLayout(props.type) ?? null\r\n})\r\n\r\n/**\r\n * 处理按键\r\n */\r\nconst handleKeyPress = (key: KeyDefinition) => {\r\n emit('keypress', key)\r\n}\r\n\r\n/**\r\n * 显示选项面板\r\n */\r\nconst handleShowOptions = (options: string[]) => {\r\n currentOptions.value = options\r\n showOptionsPanel.value = true\r\n}\r\n\r\n/**\r\n * 处理选项选择\r\n */\r\nconst handleSelectOption = (option: string, event: MouseEvent | TouchEvent) => {\r\n event.preventDefault()\r\n event.stopPropagation()\r\n showOptionsPanel.value = false\r\n emit('selectOption', option)\r\n}\r\n\r\n/**\r\n * 关闭选项面板\r\n */\r\nconst closeOptionsPanel = () => {\r\n showOptionsPanel.value = false\r\n}\r\n\r\n/**\r\n * 计算每行的总宽度,用于居中对齐\r\n */\r\nconst getRowStyle = () => {\r\n // 可以根据需要添加行样式\r\n return {}\r\n}\r\n</script>\r\n\r\n<template>\r\n <div class=\"virtual-keyboard\">\r\n <template v-if=\"currentLayout\">\r\n <div\r\n v-for=\"(row, rowIndex) in currentLayout.rows\"\r\n :key=\"rowIndex\"\r\n class=\"virtual-keyboard__row\"\r\n :class=\"row.className\"\r\n :style=\"getRowStyle()\"\r\n >\r\n <KeyboardKey\r\n v-for=\"key in row.keys\"\r\n :key=\"key.id\"\r\n :key-def=\"key\"\r\n :is-upper-case=\"isUpperCase\"\r\n :base-width=\"keyWidth\"\r\n :use-flex=\"row.className === 'numpad-row'\"\r\n @press=\"handleKeyPress\"\r\n @show-options=\"handleShowOptions\"\r\n />\r\n </div>\r\n </template>\r\n <div v-else class=\"virtual-keyboard__empty\">键盘布局未找到</div>\r\n\r\n <!-- 选项面板 -->\r\n <Transition name=\"options-panel\">\r\n <div v-if=\"showOptionsPanel\" class=\"keyboard-options-panel\">\r\n <div class=\"keyboard-options-panel__header\">\r\n <span class=\"keyboard-options-panel__title\">选择邮箱后缀</span>\r\n <button\r\n class=\"keyboard-options-panel__close\"\r\n type=\"button\"\r\n @click=\"closeOptionsPanel\"\r\n @touchstart.prevent=\"closeOptionsPanel\"\r\n >\r\n ×\r\n </button>\r\n </div>\r\n <div class=\"keyboard-options-panel__grid\">\r\n <button\r\n v-for=\"option in currentOptions\"\r\n :key=\"option\"\r\n class=\"keyboard-options-panel__item\"\r\n type=\"button\"\r\n @mousedown.prevent=\"e => handleSelectOption(option, e)\"\r\n @touchstart.prevent=\"e => handleSelectOption(option, e)\"\r\n >\r\n {{ option }}\r\n </button>\r\n </div>\r\n </div>\r\n </Transition>\r\n </div>\r\n</template>\r\n\r\n<style>\r\n.virtual-keyboard {\r\n --key-gap: var(--keyboard-key-gap);\r\n position: relative;\r\n display: flex;\r\n flex-direction: column;\r\n align-items: center;\r\n gap: var(--key-gap);\r\n padding: var(--keyboard-padding);\r\n background-color: var(--keyboard-bg);\r\n user-select: none;\r\n -webkit-user-select: none;\r\n overflow: hidden;\r\n font-family: var(--ld-font-family);\r\n}\r\n\r\n.virtual-keyboard__row {\r\n display: flex;\r\n justify-content: center;\r\n gap: var(--key-gap);\r\n width: 100%;\r\n padding: 0 var(--ld-px-2);\r\n}\r\n\r\n.virtual-keyboard__row.numpad-row {\r\n justify-content: stretch;\r\n}\r\n.virtual-keyboard__row.numpad-row .keyboard-key-wrapper {\r\n flex: 1;\r\n}\r\n\r\n.virtual-keyboard__empty {\r\n padding: var(--ld-spacing-lg);\r\n color: var(--ld-text-muted);\r\n text-align: center;\r\n}\r\n\r\n.keyboard-options-panel {\r\n position: absolute;\r\n inset: 0;\r\n z-index: 10;\r\n display: flex;\r\n flex-direction: column;\r\n padding: var(--ld-spacing-sm);\r\n background: var(--keyboard-bg);\r\n}\r\n\r\n.keyboard-options-panel__header {\r\n display: flex;\r\n align-items: center;\r\n justify-content: space-between;\r\n padding: var(--ld-spacing-sm) var(--ld-spacing-sm) var(--ld-spacing-md);\r\n margin-bottom: var(--ld-spacing-sm);\r\n border-bottom: var(--ld-border-width-thin) solid var(--ld-border-subtle);\r\n}\r\n\r\n.keyboard-options-panel__title {\r\n color: var(--keyboard-key-color);\r\n font-size: var(--ld-font-sm);\r\n font-weight: 600;\r\n}\r\n\r\n.keyboard-options-panel__close {\r\n display: flex;\r\n align-items: center;\r\n justify-content: center;\r\n width: var(--ld-px-28);\r\n height: var(--ld-px-28);\r\n border: 0;\r\n border-radius: var(--ld-radius-full);\r\n background: var(--keyboard-fn-key-bg);\r\n color: var(--keyboard-key-color);\r\n font-size: var(--ld-font-lg);\r\n line-height: 1;\r\n cursor: pointer;\r\n}\r\n\r\n.keyboard-options-panel__close:active {\r\n background: var(--keyboard-fn-key-active-bg);\r\n}\r\n\r\n.keyboard-options-panel__grid {\r\n display: grid;\r\n flex: 1;\r\n grid-template-columns: repeat(3, 1fr);\r\n gap: var(--ld-spacing-sm);\r\n padding: var(--ld-spacing-xs) 0;\r\n overflow-y: auto;\r\n}\r\n\r\n.keyboard-options-panel__item {\r\n padding: var(--ld-spacing-md) var(--ld-spacing-sm);\r\n border: 0;\r\n border-radius: var(--ld-radius-md);\r\n background: var(--keyboard-key-bg);\r\n color: var(--keyboard-key-color);\r\n font-size: var(--ld-font-sm);\r\n font-weight: 500;\r\n cursor: pointer;\r\n box-shadow: var(--ld-shadow-sm, none);\r\n transition:\r\n background-color var(--ld-duration-fast),\r\n transform var(--ld-duration-fast);\r\n}\r\n\r\n.keyboard-options-panel__item:active {\r\n background: var(--keyboard-key-active-bg);\r\n transform: scale(0.96);\r\n}\r\n\r\n.options-panel-enter-active,\r\n.options-panel-leave-active {\r\n transition:\r\n opacity var(--ld-duration-fast),\r\n transform var(--ld-duration-fast);\r\n}\r\n\r\n.options-panel-enter-from,\r\n.options-panel-leave-to {\r\n opacity: 0;\r\n transform: translateY(var(--ld-px-20));\r\n}\r\n</style>\r\n","<script setup lang=\"ts\">\r\nimport type {\r\n KeyboardConfig,\r\n KeyboardType,\r\n KeyDefinition,\r\n} from '@composy/keyboard-core'\r\nimport { getLayout } from '@composy/keyboard-core'\r\nimport { computed, ref } from 'vue'\r\nimport KeyboardKey from './KeyboardKey.vue'\r\n\r\nconst props = withDefaults(\r\n defineProps<{\r\n /**\r\n * 键盘类型\r\n */\r\n type?: KeyboardType | string\r\n /**\r\n * 是否大写状态\r\n */\r\n isUpperCase?: boolean\r\n /**\r\n * 自定义布局配置\r\n */\r\n layout?: KeyboardConfig\r\n /**\r\n * 按键基础宽度\r\n */\r\n keyWidth?: number\r\n }>(),\r\n {\r\n type: 'qwerty',\r\n isUpperCase: false,\r\n keyWidth: 36,\r\n }\r\n)\r\n\r\nconst emit = defineEmits<{\r\n keypress: [key: KeyDefinition]\r\n selectOption: [option: string]\r\n}>()\r\n\r\n/**\r\n * 选项面板状态\r\n */\r\nconst showOptionsPanel = ref(false)\r\nconst currentOptions = ref<string[]>([])\r\n\r\n/**\r\n * 当前布局配置\r\n */\r\nconst currentLayout = computed(() => {\r\n if (props.layout) {\r\n return props.layout\r\n }\r\n return getLayout(props.type) ?? null\r\n})\r\n\r\n/**\r\n * 处理按键\r\n */\r\nconst handleKeyPress = (key: KeyDefinition) => {\r\n emit('keypress', key)\r\n}\r\n\r\n/**\r\n * 显示选项面板\r\n */\r\nconst handleShowOptions = (options: string[]) => {\r\n currentOptions.value = options\r\n showOptionsPanel.value = true\r\n}\r\n\r\n/**\r\n * 处理选项选择\r\n */\r\nconst handleSelectOption = (option: string, event: MouseEvent | TouchEvent) => {\r\n event.preventDefault()\r\n event.stopPropagation()\r\n showOptionsPanel.value = false\r\n emit('selectOption', option)\r\n}\r\n\r\n/**\r\n * 关闭选项面板\r\n */\r\nconst closeOptionsPanel = () => {\r\n showOptionsPanel.value = false\r\n}\r\n\r\n/**\r\n * 计算每行的总宽度,用于居中对齐\r\n */\r\nconst getRowStyle = () => {\r\n // 可以根据需要添加行样式\r\n return {}\r\n}\r\n</script>\r\n\r\n<template>\r\n <div class=\"virtual-keyboard\">\r\n <template v-if=\"currentLayout\">\r\n <div\r\n v-for=\"(row, rowIndex) in currentLayout.rows\"\r\n :key=\"rowIndex\"\r\n class=\"virtual-keyboard__row\"\r\n :class=\"row.className\"\r\n :style=\"getRowStyle()\"\r\n >\r\n <KeyboardKey\r\n v-for=\"key in row.keys\"\r\n :key=\"key.id\"\r\n :key-def=\"key\"\r\n :is-upper-case=\"isUpperCase\"\r\n :base-width=\"keyWidth\"\r\n :use-flex=\"row.className === 'numpad-row'\"\r\n @press=\"handleKeyPress\"\r\n @show-options=\"handleShowOptions\"\r\n />\r\n </div>\r\n </template>\r\n <div v-else class=\"virtual-keyboard__empty\">键盘布局未找到</div>\r\n\r\n <!-- 选项面板 -->\r\n <Transition name=\"options-panel\">\r\n <div v-if=\"showOptionsPanel\" class=\"keyboard-options-panel\">\r\n <div class=\"keyboard-options-panel__header\">\r\n <span class=\"keyboard-options-panel__title\">选择邮箱后缀</span>\r\n <button\r\n class=\"keyboard-options-panel__close\"\r\n type=\"button\"\r\n @click=\"closeOptionsPanel\"\r\n @touchstart.prevent=\"closeOptionsPanel\"\r\n >\r\n ×\r\n </button>\r\n </div>\r\n <div class=\"keyboard-options-panel__grid\">\r\n <button\r\n v-for=\"option in currentOptions\"\r\n :key=\"option\"\r\n class=\"keyboard-options-panel__item\"\r\n type=\"button\"\r\n @mousedown.prevent=\"e => handleSelectOption(option, e)\"\r\n @touchstart.prevent=\"e => handleSelectOption(option, e)\"\r\n >\r\n {{ option }}\r\n </button>\r\n </div>\r\n </div>\r\n </Transition>\r\n </div>\r\n</template>\r\n\r\n<style>\r\n.virtual-keyboard {\r\n --key-gap: var(--keyboard-key-gap);\r\n position: relative;\r\n display: flex;\r\n flex-direction: column;\r\n align-items: center;\r\n gap: var(--key-gap);\r\n padding: var(--keyboard-padding);\r\n background-color: var(--keyboard-bg);\r\n user-select: none;\r\n -webkit-user-select: none;\r\n overflow: hidden;\r\n font-family: var(--ld-font-family);\r\n}\r\n\r\n.virtual-keyboard__row {\r\n display: flex;\r\n justify-content: center;\r\n gap: var(--key-gap);\r\n width: 100%;\r\n padding: 0 var(--ld-px-2);\r\n}\r\n\r\n.virtual-keyboard__row.numpad-row {\r\n justify-content: stretch;\r\n}\r\n.virtual-keyboard__row.numpad-row .keyboard-key-wrapper {\r\n flex: 1;\r\n}\r\n\r\n.virtual-keyboard__empty {\r\n padding: var(--ld-spacing-lg);\r\n color: var(--ld-text-muted);\r\n text-align: center;\r\n}\r\n\r\n.keyboard-options-panel {\r\n position: absolute;\r\n inset: 0;\r\n z-index: 10;\r\n display: flex;\r\n flex-direction: column;\r\n padding: var(--ld-spacing-sm);\r\n background: var(--keyboard-bg);\r\n}\r\n\r\n.keyboard-options-panel__header {\r\n display: flex;\r\n align-items: center;\r\n justify-content: space-between;\r\n padding: var(--ld-spacing-sm) var(--ld-spacing-sm) var(--ld-spacing-md);\r\n margin-bottom: var(--ld-spacing-sm);\r\n border-bottom: var(--ld-border-width-thin) solid var(--ld-border-subtle);\r\n}\r\n\r\n.keyboard-options-panel__title {\r\n color: var(--keyboard-key-color);\r\n font-size: var(--ld-font-sm);\r\n font-weight: 600;\r\n}\r\n\r\n.keyboard-options-panel__close {\r\n display: flex;\r\n align-items: center;\r\n justify-content: center;\r\n width: var(--ld-px-28);\r\n height: var(--ld-px-28);\r\n border: 0;\r\n border-radius: var(--ld-radius-full);\r\n background: var(--keyboard-fn-key-bg);\r\n color: var(--keyboard-key-color);\r\n font-size: var(--ld-font-lg);\r\n line-height: 1;\r\n cursor: pointer;\r\n}\r\n\r\n.keyboard-options-panel__close:active {\r\n background: var(--keyboard-fn-key-active-bg);\r\n}\r\n\r\n.keyboard-options-panel__grid {\r\n display: grid;\r\n flex: 1;\r\n grid-template-columns: repeat(3, 1fr);\r\n gap: var(--ld-spacing-sm);\r\n padding: var(--ld-spacing-xs) 0;\r\n overflow-y: auto;\r\n}\r\n\r\n.keyboard-options-panel__item {\r\n padding: var(--ld-spacing-md) var(--ld-spacing-sm);\r\n border: 0;\r\n border-radius: var(--ld-radius-md);\r\n background: var(--keyboard-key-bg);\r\n color: var(--keyboard-key-color);\r\n font-size: var(--ld-font-sm);\r\n font-weight: 500;\r\n cursor: pointer;\r\n box-shadow: var(--ld-shadow-sm, none);\r\n transition:\r\n background-color var(--ld-duration-fast),\r\n transform var(--ld-duration-fast);\r\n}\r\n\r\n.keyboard-options-panel__item:active {\r\n background: var(--keyboard-key-active-bg);\r\n transform: scale(0.96);\r\n}\r\n\r\n.options-panel-enter-active,\r\n.options-panel-leave-active {\r\n transition:\r\n opacity var(--ld-duration-fast),\r\n transform var(--ld-duration-fast);\r\n}\r\n\r\n.options-panel-enter-from,\r\n.options-panel-leave-to {\r\n opacity: 0;\r\n transform: translateY(var(--ld-px-20));\r\n}\r\n</style>\r\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAUA,MAAM,QAAQ;EA0Bd,MAAM,OAAO;EAQb,MAAM,mBAAmB,IAAI,KAAK;EAClC,MAAM,iBAAiB,IAAc,CAAC,CAAC;EAKvC,MAAM,gBAAgB,eAAe;GACnC,IAAI,MAAM,QACR,OAAO,MAAM;GAEf,OAAO,UAAU,MAAM,IAAI,KAAK;EAClC,CAAC;EAKD,MAAM,kBAAkB,QAAuB;GAC7C,KAAK,YAAY,GAAG;EACtB;EAKA,MAAM,qBAAqB,YAAsB;GAC/C,eAAe,QAAQ;GACvB,iBAAiB,QAAQ;EAC3B;EAKA,MAAM,sBAAsB,QAAgB,UAAmC;GAC7E,MAAM,eAAe;GACrB,MAAM,gBAAgB;GACtB,iBAAiB,QAAQ;GACzB,KAAK,gBAAgB,MAAM;EAC7B;EAKA,MAAM,0BAA0B;GAC9B,iBAAiB,QAAQ;EAC3B;EAKA,MAAM,oBAAoB;GAExB,OAAO,CAAC;EACV;;uBCIE,mBAmDM,OAnDN,YAmDM;IAlDY,cAAA,SAAA,UAAA,IAAA,GACd,mBAiBM,UAAA,EAAA,KAAA,EAAA,GAAA,WAhBsB,cAAA,MAAc,OAAhC,KAAK,aAAQ;yBADvB,mBAiBM,OAAA;MAfH,KAAK;MACN,OAAK,eAAA,CAAC,yBACE,IAAI,SAAS,CAAA;MACpB,OAAK,eAAE,YAAW,CAAA;2BAEnB,mBASE,UAAA,MAAA,WARc,IAAI,OAAX,QAAG;0BADZ,YASE,qBAAA;OAPC,KAAK,IAAI;OACT,WAAS;OACT,iBAAe,QAAA;OACf,cAAY,QAAA;OACZ,YAAU,IAAI,cAAS;OACvB,SAAO;OACP,eAAc;;;;;;;;8BAIrB,mBAAyD,OAAzD,YAA4C,SAAO;IAEnD,mBAAA,QAAA;IACA,YA0Ba,YAAA,EA1BD,MAAK,gBAAe,GAAA;4BAyBxB,CAxBK,iBAAA,SAAA,UAAA,GAAX,mBAwBM,OAxBN,YAwBM,CAvBJ,mBAUM,OAVN,YAUM,CAAA,OAAA,OAAA,OAAA,KATJ,mBAAyD,QAAA,EAAnD,OAAM,gCAA+B,GAAC,UAAM,EAAA,IAClD,mBAOS,UAAA;MANP,OAAM;MACN,MAAK;MACJ,SAAO;MACP,cAAU,cAAU,mBAAiB,CAAA,SAAA,CAAA;QACvC,OAED,EAAA,CAAA,CAAA,GAEF,mBAWM,OAXN,YAWM,EAAA,UAAA,IAAA,GAVJ,mBASS,UAAA,MAAA,WARU,eAAA,QAAV,WAAM;0BADf,mBASS,UAAA;OAPN,KAAK;OACN,OAAM;OACN,MAAK;OACJ,aAAS,eAAU,MAAK,mBAAmB,QAAQ,CAAC,GAAA,CAAA,SAAA,CAAA;OACpD,cAAU,eAAU,MAAK,mBAAmB,QAAQ,CAAC,GAAA,CAAA,SAAA,CAAA;yBAEnD,MAAM,GAAA,IAAA,UAAA"}
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
* Vue 组件导出
|
|
3
3
|
* @module components
|
|
4
4
|
*/
|
|
5
|
-
export { default as VirtualKeyboard } from './VirtualKeyboard.vue';
|
|
6
5
|
export { default as KeyboardKey } from './KeyboardKey.vue';
|
|
7
6
|
export { default as KeyboardPopup } from './KeyboardPopup.vue';
|
|
8
7
|
export { default as LicensePlateKeyboard } from './LicensePlateKeyboard.vue';
|
|
8
|
+
export { default as VirtualKeyboard } from './VirtualKeyboard.vue';
|
|
9
9
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/components/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAC1D,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,qBAAqB,CAAA;AAC9D,OAAO,EAAE,OAAO,IAAI,oBAAoB,EAAE,MAAM,4BAA4B,CAAA;AAC5E,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,uBAAuB,CAAA"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* ***********************************
|
|
3
|
+
* @composy/keyboard-vue v0.0.1 *
|
|
4
|
+
* Built with rollup *
|
|
5
|
+
* Build time: 2024-10-12 17:44:15 *
|
|
6
|
+
* Build mode: production *
|
|
7
|
+
* Minified: No *
|
|
8
|
+
* ***********************************
|
|
9
|
+
*/
|
|
10
|
+
import KeyboardKey_default from "./KeyboardKey.js";
|
|
11
|
+
import VirtualKeyboard_default from "./VirtualKeyboard.js";
|
|
12
|
+
import KeyboardPopup_default from "./KeyboardPopup.js";
|
|
13
|
+
import LicensePlateKeyboard_default from "./LicensePlateKeyboard.js";
|
|
14
|
+
export { KeyboardKey_default as KeyboardKey, KeyboardPopup_default as KeyboardPopup, LicensePlateKeyboard_default as LicensePlateKeyboard, VirtualKeyboard_default as VirtualKeyboard };
|
|
15
|
+
/*! End of @composy/keyboard-vue | Powered by @composy/builder */
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/composables/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,cAAc,eAAe,CAAA;AAC7B,cAAc,oBAAoB,CAAA"}
|