@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,252 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LDesign Keyboard shared styles.
|
|
3
|
+
*/
|
|
4
|
+
:root {
|
|
5
|
+
--keyboard-bg: var(--ld-bg-surface);
|
|
6
|
+
--keyboard-key-bg: var(--ld-bg-container);
|
|
7
|
+
--keyboard-key-color: var(--ld-text-primary);
|
|
8
|
+
--keyboard-key-active-bg: var(--ld-primary-50);
|
|
9
|
+
--keyboard-key-border: var(--ld-border);
|
|
10
|
+
--keyboard-fn-key-bg: var(--ld-bg-elevated);
|
|
11
|
+
--keyboard-fn-key-color: var(--ld-text-secondary);
|
|
12
|
+
--keyboard-fn-key-active-bg: var(--ld-primary-100);
|
|
13
|
+
--keyboard-primary-bg: var(--ld-primary-500);
|
|
14
|
+
--keyboard-primary-active-bg: var(--ld-primary-600);
|
|
15
|
+
--keyboard-primary-color: var(--ld-text-inverse);
|
|
16
|
+
--keyboard-mask-bg: color-mix(in srgb, var(--ld-black) 40%, var(--ld-transparent));
|
|
17
|
+
--keyboard-key-height: var(--ld-px-48);
|
|
18
|
+
--keyboard-key-radius: var(--ld-radius-md);
|
|
19
|
+
--keyboard-key-gap: var(--ld-spacing-sm);
|
|
20
|
+
--keyboard-font-size: var(--ld-font-lg);
|
|
21
|
+
--keyboard-fn-font-size: var(--ld-font-sm);
|
|
22
|
+
--keyboard-padding: var(--ld-spacing-sm);
|
|
23
|
+
--keyboard-key-shadow: var(--ld-shadow-sm, none);
|
|
24
|
+
}
|
|
25
|
+
.virtual-keyboard,
|
|
26
|
+
.virtual-keyboard *,
|
|
27
|
+
.keyboard-popup,
|
|
28
|
+
.keyboard-popup * {
|
|
29
|
+
box-sizing: border-box;
|
|
30
|
+
margin: 0;
|
|
31
|
+
padding: 0;
|
|
32
|
+
}
|
|
33
|
+
.virtual-keyboard {
|
|
34
|
+
display: flex;
|
|
35
|
+
flex-direction: column;
|
|
36
|
+
width: 100%;
|
|
37
|
+
padding: var(--keyboard-padding);
|
|
38
|
+
background-color: var(--keyboard-bg);
|
|
39
|
+
font-family: var(--ld-font-family);
|
|
40
|
+
-webkit-font-smoothing: antialiased;
|
|
41
|
+
-moz-osx-font-smoothing: grayscale;
|
|
42
|
+
-webkit-touch-callout: none;
|
|
43
|
+
-webkit-user-select: none;
|
|
44
|
+
-moz-user-select: none;
|
|
45
|
+
user-select: none;
|
|
46
|
+
}
|
|
47
|
+
.virtual-keyboard__row,
|
|
48
|
+
.numpad-row {
|
|
49
|
+
display: flex;
|
|
50
|
+
justify-content: center;
|
|
51
|
+
width: 100%;
|
|
52
|
+
gap: var(--keyboard-key-gap);
|
|
53
|
+
margin-bottom: var(--keyboard-key-gap);
|
|
54
|
+
}
|
|
55
|
+
.virtual-keyboard__row:last-child {
|
|
56
|
+
margin-bottom: 0;
|
|
57
|
+
}
|
|
58
|
+
.keyboard-key {
|
|
59
|
+
display: inline-flex;
|
|
60
|
+
flex: 1;
|
|
61
|
+
align-items: center;
|
|
62
|
+
justify-content: center;
|
|
63
|
+
min-width: 0;
|
|
64
|
+
height: var(--keyboard-key-height);
|
|
65
|
+
padding: 0 var(--ld-spacing-xs);
|
|
66
|
+
border: 0;
|
|
67
|
+
border-radius: var(--keyboard-key-radius);
|
|
68
|
+
background-color: var(--keyboard-key-bg);
|
|
69
|
+
color: var(--keyboard-key-color);
|
|
70
|
+
font-size: var(--keyboard-font-size);
|
|
71
|
+
font-weight: 500;
|
|
72
|
+
cursor: pointer;
|
|
73
|
+
touch-action: manipulation;
|
|
74
|
+
transition: background-color var(--ld-duration-fast), transform var(--ld-duration-fast);
|
|
75
|
+
-webkit-tap-highlight-color: transparent;
|
|
76
|
+
box-shadow: var(--keyboard-key-shadow);
|
|
77
|
+
}
|
|
78
|
+
.keyboard-key:active {
|
|
79
|
+
background-color: var(--keyboard-key-active-bg);
|
|
80
|
+
transform: scale(0.98);
|
|
81
|
+
}
|
|
82
|
+
.keyboard-key--disabled {
|
|
83
|
+
opacity: 0;
|
|
84
|
+
cursor: default;
|
|
85
|
+
pointer-events: none;
|
|
86
|
+
}
|
|
87
|
+
.keyboard-key--backspace,
|
|
88
|
+
.keyboard-key--shift,
|
|
89
|
+
.keyboard-key--tab,
|
|
90
|
+
.keyboard-key--clear,
|
|
91
|
+
.keyboard-key--close {
|
|
92
|
+
background-color: var(--keyboard-fn-key-bg);
|
|
93
|
+
color: var(--keyboard-fn-key-color);
|
|
94
|
+
font-size: var(--keyboard-fn-font-size);
|
|
95
|
+
font-weight: 400;
|
|
96
|
+
}
|
|
97
|
+
.keyboard-key--backspace:active,
|
|
98
|
+
.keyboard-key--shift:active,
|
|
99
|
+
.keyboard-key--tab:active,
|
|
100
|
+
.keyboard-key--clear:active,
|
|
101
|
+
.keyboard-key--close:active {
|
|
102
|
+
background-color: var(--keyboard-fn-key-active-bg);
|
|
103
|
+
}
|
|
104
|
+
.keyboard-key--shift.keyboard-key--active,
|
|
105
|
+
.keyboard-key--done,
|
|
106
|
+
.keyboard-key--enter {
|
|
107
|
+
background-color: var(--keyboard-primary-bg);
|
|
108
|
+
color: var(--keyboard-primary-color);
|
|
109
|
+
}
|
|
110
|
+
.keyboard-key--done:active,
|
|
111
|
+
.keyboard-key--enter:active {
|
|
112
|
+
background-color: var(--keyboard-primary-active-bg);
|
|
113
|
+
}
|
|
114
|
+
.keyboard-key--space {
|
|
115
|
+
flex: 4;
|
|
116
|
+
}
|
|
117
|
+
.key-placeholder {
|
|
118
|
+
background-color: transparent;
|
|
119
|
+
box-shadow: none;
|
|
120
|
+
cursor: default;
|
|
121
|
+
pointer-events: none;
|
|
122
|
+
}
|
|
123
|
+
.numpad-row .keyboard-key {
|
|
124
|
+
height: var(--ld-px-56);
|
|
125
|
+
font-size: var(--ld-font-xl);
|
|
126
|
+
}
|
|
127
|
+
.key-num,
|
|
128
|
+
.key-plate-province,
|
|
129
|
+
.key-plate-letter,
|
|
130
|
+
.key-plate-number {
|
|
131
|
+
background-color: var(--keyboard-key-bg);
|
|
132
|
+
color: var(--keyboard-key-color);
|
|
133
|
+
}
|
|
134
|
+
.key-numpad-fn,
|
|
135
|
+
.key-plate-fn,
|
|
136
|
+
.key-plate-switch {
|
|
137
|
+
background-color: var(--keyboard-fn-key-bg);
|
|
138
|
+
color: var(--keyboard-fn-key-color);
|
|
139
|
+
font-size: var(--keyboard-fn-font-size);
|
|
140
|
+
}
|
|
141
|
+
.key-numpad-done,
|
|
142
|
+
.key-plate-done {
|
|
143
|
+
background-color: var(--keyboard-primary-bg);
|
|
144
|
+
color: var(--keyboard-primary-color);
|
|
145
|
+
font-size: var(--keyboard-fn-font-size);
|
|
146
|
+
box-shadow: none;
|
|
147
|
+
}
|
|
148
|
+
.key-numpad-done:active,
|
|
149
|
+
.key-plate-done:active {
|
|
150
|
+
background-color: var(--keyboard-primary-active-bg);
|
|
151
|
+
}
|
|
152
|
+
.virtual-keyboard:has(.plate-keyboard-row) {
|
|
153
|
+
min-width: var(--ld-px-280);
|
|
154
|
+
}
|
|
155
|
+
.plate-keyboard-row {
|
|
156
|
+
display: flex;
|
|
157
|
+
flex-wrap: nowrap;
|
|
158
|
+
width: 100%;
|
|
159
|
+
gap: var(--ld-spacing-xs);
|
|
160
|
+
}
|
|
161
|
+
.plate-keyboard-row .keyboard-key {
|
|
162
|
+
flex: 1 1 0;
|
|
163
|
+
min-width: var(--ld-px-28);
|
|
164
|
+
height: var(--ld-px-42);
|
|
165
|
+
padding: 0 var(--ld-px-2);
|
|
166
|
+
font-size: var(--ld-font-sm);
|
|
167
|
+
border-radius: var(--ld-radius-sm);
|
|
168
|
+
}
|
|
169
|
+
.key-plate-fn {
|
|
170
|
+
flex: 1.2 1 0 !important;
|
|
171
|
+
}
|
|
172
|
+
.key-plate-done {
|
|
173
|
+
flex: 1.5 1 0 !important;
|
|
174
|
+
}
|
|
175
|
+
.key-plate-switch {
|
|
176
|
+
flex: 1.3 1 0 !important;
|
|
177
|
+
}
|
|
178
|
+
.key-plate-special {
|
|
179
|
+
background-color: var(--ld-warning-50);
|
|
180
|
+
color: var(--ld-warning-700);
|
|
181
|
+
}
|
|
182
|
+
.keyboard-popup {
|
|
183
|
+
position: fixed;
|
|
184
|
+
z-index: 1000;
|
|
185
|
+
overflow: hidden;
|
|
186
|
+
background-color: var(--keyboard-bg);
|
|
187
|
+
}
|
|
188
|
+
.keyboard-popup--desktop {
|
|
189
|
+
min-width: var(--ld-px-280);
|
|
190
|
+
border-radius: var(--ld-radius-lg);
|
|
191
|
+
box-shadow: var(--ld-shadow-lg, none);
|
|
192
|
+
}
|
|
193
|
+
.keyboard-popup--mobile {
|
|
194
|
+
right: 0;
|
|
195
|
+
bottom: 0;
|
|
196
|
+
left: 0;
|
|
197
|
+
border-radius: 0;
|
|
198
|
+
border-top-left-radius: var(--ld-radius-lg);
|
|
199
|
+
border-top-right-radius: var(--ld-radius-lg);
|
|
200
|
+
box-shadow: var(--ld-shadow-md, none);
|
|
201
|
+
}
|
|
202
|
+
.keyboard-mask {
|
|
203
|
+
position: fixed;
|
|
204
|
+
inset: 0;
|
|
205
|
+
z-index: 999;
|
|
206
|
+
background-color: var(--keyboard-mask-bg);
|
|
207
|
+
}
|
|
208
|
+
.keyboard-mask-enter-active,
|
|
209
|
+
.keyboard-mask-leave-active {
|
|
210
|
+
transition: opacity var(--ld-duration-fast);
|
|
211
|
+
}
|
|
212
|
+
.keyboard-mask-enter-from,
|
|
213
|
+
.keyboard-mask-leave-to {
|
|
214
|
+
opacity: 0;
|
|
215
|
+
}
|
|
216
|
+
.keyboard-fade-enter-active,
|
|
217
|
+
.keyboard-fade-leave-active {
|
|
218
|
+
transition: opacity var(--ld-duration-fast), transform var(--ld-duration-fast);
|
|
219
|
+
}
|
|
220
|
+
.keyboard-fade-enter-from,
|
|
221
|
+
.keyboard-fade-leave-to {
|
|
222
|
+
opacity: 0;
|
|
223
|
+
transform: translateY(calc(-1 * var(--ld-px-4))) scale(0.98);
|
|
224
|
+
}
|
|
225
|
+
.keyboard-slide-enter-active,
|
|
226
|
+
.keyboard-slide-leave-active {
|
|
227
|
+
transition: transform var(--ld-duration-normal);
|
|
228
|
+
}
|
|
229
|
+
.keyboard-slide-enter-from,
|
|
230
|
+
.keyboard-slide-leave-to {
|
|
231
|
+
transform: translateY(100%);
|
|
232
|
+
}
|
|
233
|
+
@media (max-width: 48em) {
|
|
234
|
+
.virtual-keyboard {
|
|
235
|
+
padding: var(--ld-spacing-xs);
|
|
236
|
+
}
|
|
237
|
+
.keyboard-key {
|
|
238
|
+
height: var(--ld-px-48);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
@media (orientation: landscape) and (max-height: 32em) {
|
|
242
|
+
.keyboard-key {
|
|
243
|
+
height: var(--ld-px-36);
|
|
244
|
+
font-size: var(--ld-font-base);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
@supports (padding-bottom: env(safe-area-inset-bottom)) {
|
|
248
|
+
.keyboard-popup--mobile {
|
|
249
|
+
padding-bottom: env(safe-area-inset-bottom);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
/*# sourceMappingURL=src\styles\keyboard.less.map */
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Keyboard theme tokens.
|
|
3
|
+
* Theme values intentionally reference the shared LDesign color and size runtime.
|
|
4
|
+
*/
|
|
5
|
+
[data-theme="miui"],
|
|
6
|
+
.keyboard-theme-miui {
|
|
7
|
+
--keyboard-bg: var(--ld-bg-surface);
|
|
8
|
+
--keyboard-key-bg: var(--ld-bg-container);
|
|
9
|
+
--keyboard-key-color: var(--ld-text-primary);
|
|
10
|
+
--keyboard-key-active-bg: var(--ld-warning-50);
|
|
11
|
+
--keyboard-fn-key-bg: var(--ld-bg-elevated);
|
|
12
|
+
--keyboard-fn-key-color: var(--ld-text-secondary);
|
|
13
|
+
--keyboard-fn-key-active-bg: var(--ld-warning-100);
|
|
14
|
+
--keyboard-primary-bg: var(--ld-warning-500);
|
|
15
|
+
--keyboard-primary-active-bg: var(--ld-warning-600);
|
|
16
|
+
--keyboard-primary-color: var(--ld-text-inverse);
|
|
17
|
+
--keyboard-mask-bg: color-mix(in srgb, var(--ld-black) 40%, var(--ld-transparent));
|
|
18
|
+
--keyboard-key-border: var(--ld-border);
|
|
19
|
+
--keyboard-key-radius: var(--ld-radius-md);
|
|
20
|
+
--keyboard-key-gap: var(--ld-spacing-sm);
|
|
21
|
+
--keyboard-key-height: var(--ld-px-48);
|
|
22
|
+
--keyboard-font-size: var(--ld-font-lg);
|
|
23
|
+
--keyboard-fn-font-size: var(--ld-font-sm);
|
|
24
|
+
--keyboard-padding: var(--ld-spacing-sm);
|
|
25
|
+
--keyboard-key-shadow: var(--ld-shadow-sm, none);
|
|
26
|
+
}
|
|
27
|
+
[data-theme="ios"],
|
|
28
|
+
.keyboard-theme-ios {
|
|
29
|
+
--keyboard-bg: var(--ld-bg-surface);
|
|
30
|
+
--keyboard-key-bg: var(--ld-bg-container);
|
|
31
|
+
--keyboard-key-color: var(--ld-text-primary);
|
|
32
|
+
--keyboard-key-active-bg: var(--ld-primary-50);
|
|
33
|
+
--keyboard-fn-key-bg: var(--ld-bg-elevated);
|
|
34
|
+
--keyboard-fn-key-color: var(--ld-text-primary);
|
|
35
|
+
--keyboard-fn-key-active-bg: var(--ld-primary-100);
|
|
36
|
+
--keyboard-primary-bg: var(--ld-primary-500);
|
|
37
|
+
--keyboard-primary-active-bg: var(--ld-primary-600);
|
|
38
|
+
--keyboard-primary-color: var(--ld-text-inverse);
|
|
39
|
+
--keyboard-mask-bg: color-mix(in srgb, var(--ld-black) 40%, var(--ld-transparent));
|
|
40
|
+
--keyboard-key-border: var(--ld-border);
|
|
41
|
+
--keyboard-key-radius: var(--ld-radius-sm);
|
|
42
|
+
--keyboard-key-gap: var(--ld-spacing-sm);
|
|
43
|
+
--keyboard-key-height: var(--ld-px-42);
|
|
44
|
+
--keyboard-font-size: var(--ld-font-xl);
|
|
45
|
+
--keyboard-fn-font-size: var(--ld-font-base);
|
|
46
|
+
--keyboard-padding: var(--ld-spacing-xs);
|
|
47
|
+
--keyboard-key-shadow: var(--ld-shadow-sm, none);
|
|
48
|
+
}
|
|
49
|
+
[data-theme="material"],
|
|
50
|
+
.keyboard-theme-material {
|
|
51
|
+
--keyboard-bg: var(--ld-bg-elevated);
|
|
52
|
+
--keyboard-key-bg: var(--ld-bg-container);
|
|
53
|
+
--keyboard-key-color: var(--ld-text-primary);
|
|
54
|
+
--keyboard-key-active-bg: var(--ld-success-50);
|
|
55
|
+
--keyboard-fn-key-bg: var(--ld-bg-surface);
|
|
56
|
+
--keyboard-fn-key-color: var(--ld-text-secondary);
|
|
57
|
+
--keyboard-fn-key-active-bg: var(--ld-success-100);
|
|
58
|
+
--keyboard-primary-bg: var(--ld-success-500);
|
|
59
|
+
--keyboard-primary-active-bg: var(--ld-success-600);
|
|
60
|
+
--keyboard-primary-color: var(--ld-text-inverse);
|
|
61
|
+
--keyboard-mask-bg: color-mix(in srgb, var(--ld-black) 40%, var(--ld-transparent));
|
|
62
|
+
--keyboard-key-border: var(--ld-border);
|
|
63
|
+
--keyboard-key-radius: var(--ld-radius-sm);
|
|
64
|
+
--keyboard-key-gap: var(--ld-spacing-xs);
|
|
65
|
+
--keyboard-key-height: var(--ld-px-48);
|
|
66
|
+
--keyboard-font-size: var(--ld-font-lg);
|
|
67
|
+
--keyboard-fn-font-size: var(--ld-font-sm);
|
|
68
|
+
--keyboard-padding: var(--ld-spacing-sm);
|
|
69
|
+
--keyboard-key-shadow: var(--ld-shadow-sm, none);
|
|
70
|
+
}
|
|
71
|
+
[data-theme="minimal"],
|
|
72
|
+
.keyboard-theme-minimal {
|
|
73
|
+
--keyboard-bg: var(--ld-bg-surface);
|
|
74
|
+
--keyboard-key-bg: var(--ld-bg-container);
|
|
75
|
+
--keyboard-key-color: var(--ld-text-primary);
|
|
76
|
+
--keyboard-key-active-bg: var(--ld-primary-50);
|
|
77
|
+
--keyboard-fn-key-bg: var(--ld-bg-surface);
|
|
78
|
+
--keyboard-fn-key-color: var(--ld-text-secondary);
|
|
79
|
+
--keyboard-fn-key-active-bg: var(--ld-primary-100);
|
|
80
|
+
--keyboard-primary-bg: var(--ld-text-primary);
|
|
81
|
+
--keyboard-primary-active-bg: var(--ld-text-secondary);
|
|
82
|
+
--keyboard-primary-color: var(--ld-bg-container);
|
|
83
|
+
--keyboard-key-border: var(--ld-border-subtle);
|
|
84
|
+
--keyboard-key-radius: var(--ld-radius-lg);
|
|
85
|
+
--keyboard-key-gap: var(--ld-spacing-sm);
|
|
86
|
+
--keyboard-key-height: var(--ld-px-48);
|
|
87
|
+
--keyboard-font-size: var(--ld-font-base);
|
|
88
|
+
--keyboard-fn-font-size: var(--ld-font-sm);
|
|
89
|
+
--keyboard-padding: var(--ld-spacing-md);
|
|
90
|
+
--keyboard-key-shadow: none;
|
|
91
|
+
}
|
|
92
|
+
[data-theme="dark"],
|
|
93
|
+
.keyboard-theme-dark {
|
|
94
|
+
--keyboard-bg: var(--ld-bg-surface);
|
|
95
|
+
--keyboard-key-bg: var(--ld-bg-elevated);
|
|
96
|
+
--keyboard-key-color: var(--ld-text-primary);
|
|
97
|
+
--keyboard-key-active-bg: var(--ld-primary-100);
|
|
98
|
+
--keyboard-fn-key-bg: var(--ld-bg-container);
|
|
99
|
+
--keyboard-fn-key-color: var(--ld-text-secondary);
|
|
100
|
+
--keyboard-fn-key-active-bg: var(--ld-primary-200);
|
|
101
|
+
--keyboard-primary-bg: var(--ld-primary-500);
|
|
102
|
+
--keyboard-primary-active-bg: var(--ld-primary-600);
|
|
103
|
+
--keyboard-primary-color: var(--ld-text-inverse);
|
|
104
|
+
--keyboard-mask-bg: color-mix(in srgb, var(--ld-black) 40%, var(--ld-transparent));
|
|
105
|
+
--keyboard-key-border: var(--ld-border);
|
|
106
|
+
--keyboard-key-radius: var(--ld-radius-md);
|
|
107
|
+
--keyboard-key-gap: var(--ld-spacing-sm);
|
|
108
|
+
--keyboard-key-height: var(--ld-px-48);
|
|
109
|
+
--keyboard-font-size: var(--ld-font-lg);
|
|
110
|
+
--keyboard-fn-font-size: var(--ld-font-sm);
|
|
111
|
+
--keyboard-padding: var(--ld-spacing-sm);
|
|
112
|
+
--keyboard-key-shadow: var(--ld-shadow-sm, none);
|
|
113
|
+
}
|
|
114
|
+
[data-theme="green"],
|
|
115
|
+
.keyboard-theme-green {
|
|
116
|
+
--keyboard-primary-bg: var(--ld-success-500);
|
|
117
|
+
--keyboard-primary-active-bg: var(--ld-success-600);
|
|
118
|
+
}
|
|
119
|
+
[data-theme="blue"],
|
|
120
|
+
.keyboard-theme-blue {
|
|
121
|
+
--keyboard-primary-bg: var(--ld-info-500);
|
|
122
|
+
--keyboard-primary-active-bg: var(--ld-info-600);
|
|
123
|
+
}
|
|
124
|
+
.keyboard-theme-light {
|
|
125
|
+
color-scheme: light;
|
|
126
|
+
}
|
|
127
|
+
.keyboard-theme-dark {
|
|
128
|
+
color-scheme: dark;
|
|
129
|
+
}
|
|
130
|
+
.keyboard-popup,
|
|
131
|
+
.virtual-keyboard {
|
|
132
|
+
transition: background-color var(--ld-duration-fast);
|
|
133
|
+
}
|
|
134
|
+
.keyboard-key {
|
|
135
|
+
transition: background-color var(--ld-duration-fast), transform var(--ld-duration-fast);
|
|
136
|
+
}
|
|
137
|
+
/*# sourceMappingURL=src\styles\themes.less.map */
|
|
@@ -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 KeyboardKey_vue_vue_type_script_setup_true_lang_default from "./KeyboardKey.vue_vue_type_script_setup_true_lang.js";
|
|
11
|
+
//#region src/components/KeyboardKey.vue
|
|
12
|
+
KeyboardKey_vue_vue_type_script_setup_true_lang_default.__file = "src/components/KeyboardKey.vue";
|
|
13
|
+
var KeyboardKey_default = KeyboardKey_vue_vue_type_script_setup_true_lang_default;
|
|
14
|
+
//#endregion
|
|
15
|
+
export { KeyboardKey_default as default };
|
|
16
|
+
/*! End of @composy/keyboard-vue | Powered by @composy/builder */
|
|
17
|
+
//# sourceMappingURL=KeyboardKey.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"KeyboardKey.js","names":[],"sources":["../../src/components/KeyboardKey.vue"],"sourcesContent":["<script setup lang=\"ts\">\r\nimport type { KeyDefinition } from '@composy/keyboard-core'\r\nimport { sanitizeSvgIcon } from '@composy/keyboard-core'\r\nimport { computed } from 'vue'\r\n\r\nconst props = defineProps<{\r\n /**\r\n * 按键定义\r\n */\r\n keyDef: KeyDefinition\r\n /**\r\n * 是否大写状态\r\n */\r\n isUpperCase?: boolean\r\n /**\r\n * 基础宽度(px)\r\n */\r\n baseWidth?: number\r\n /**\r\n * 是否使用 flex 布局(用于 numpad 等需要均分宽度的键盘)\r\n */\r\n useFlex?: boolean\r\n}>()\r\n\r\nconst emit = defineEmits<{\r\n press: [key: KeyDefinition]\r\n showOptions: [options: string[]]\r\n}>()\r\n\r\n/**\r\n * 获取显示文本\r\n */\r\nconst label = computed(() => {\r\n const keyLabel = props.keyDef.label\r\n if (typeof keyLabel === 'string') {\r\n return keyLabel\r\n }\r\n return props.isUpperCase ? keyLabel.upper : keyLabel.lower\r\n})\r\n\r\nconst iconMarkup = computed(() => {\r\n const icon = props.keyDef.icon\r\n return icon ? sanitizeSvgIcon(icon) : ''\r\n})\r\n\r\n/**\r\n * 计算按键宽度\r\n */\r\nconst keyWidth = computed(() => {\r\n // 使用 flex 布局时,不设置固定宽度\r\n if (props.useFlex) {\r\n return undefined\r\n }\r\n const base = props.baseWidth ?? 36\r\n const width = props.keyDef.width ?? 1\r\n const gap = 6\r\n return `${base * width + (width - 1) * gap}px`\r\n})\r\n\r\n/**\r\n * 计算按键的 flex 值(用于 numpad 布局)\r\n */\r\nconst keyFlex = computed(() => {\r\n if (!props.useFlex) {\r\n return undefined\r\n }\r\n // width 属性决定占几份\r\n return props.keyDef.width ?? 1\r\n})\r\n\r\n/**\r\n * 计算 CSS 类\r\n */\r\nconst keyClass = computed(() => {\r\n const classes = ['keyboard-key', `keyboard-key--${props.keyDef.type}`]\r\n\r\n if (props.keyDef.className) {\r\n classes.push(props.keyDef.className)\r\n }\r\n\r\n if (props.keyDef.disabled) {\r\n classes.push('keyboard-key--disabled')\r\n }\r\n\r\n // Shift 键激活状态\r\n if (props.keyDef.type === 'shift' && props.isUpperCase) {\r\n classes.push('keyboard-key--active')\r\n }\r\n\r\n return classes\r\n})\r\n\r\n/**\r\n * 是否有下拉选项\r\n */\r\nconst hasOptions = computed(() => {\r\n return props.keyDef.options && props.keyDef.options.length > 0\r\n})\r\n\r\n/**\r\n * 是否是纯选项按钮(有options但无value,点击只显示选项面板)\r\n */\r\nconst isOptionsOnly = computed(() => {\r\n return hasOptions.value && !props.keyDef.value\r\n})\r\n\r\n/**\r\n * 处理按键点击\r\n */\r\nconst handlePress = (event: MouseEvent | TouchEvent) => {\r\n event.preventDefault()\r\n event.stopPropagation()\r\n\r\n if (props.keyDef.disabled) {\r\n return\r\n }\r\n\r\n // 纯选项按钮:点击直接显示选项面板\r\n if (isOptionsOnly.value) {\r\n emit('showOptions', props.keyDef.options ?? [])\r\n return\r\n }\r\n\r\n // 正常按键:触发按键事件\r\n emit('press', props.keyDef)\r\n}\r\n\r\n/**\r\n * 处理下拉箭头点击(显示选项面板)\r\n */\r\nconst handleArrowClick = (event: MouseEvent | TouchEvent) => {\r\n event.preventDefault()\r\n event.stopPropagation()\r\n\r\n if (props.keyDef.disabled) {\r\n return\r\n }\r\n\r\n if (hasOptions.value) {\r\n emit('showOptions', props.keyDef.options ?? [])\r\n }\r\n}\r\n</script>\r\n\r\n<template>\r\n <div class=\"keyboard-key-wrapper\" :style=\"{ width: keyWidth, flex: keyFlex }\">\r\n <button\r\n :class=\"[\r\n keyClass,\r\n {\r\n 'has-options': hasOptions && !isOptionsOnly,\r\n 'is-options-only': isOptionsOnly,\r\n },\r\n ]\"\r\n :disabled=\"keyDef.disabled\"\r\n type=\"button\"\r\n @mousedown.prevent=\"handlePress\"\r\n @touchstart.prevent=\"handlePress\"\r\n >\r\n <!-- SVG 图标支持 -->\r\n <span v-if=\"iconMarkup\" class=\"keyboard-key__icon\" v-html=\"iconMarkup\" />\r\n <span v-else-if=\"keyDef.icon\" class=\"keyboard-key__label\">{{\r\n keyDef.icon\r\n }}</span>\r\n <span v-else class=\"keyboard-key__label\">{{ label }}</span>\r\n <!-- 纯选项按钮内嵌下拉箭头 -->\r\n <span v-if=\"isOptionsOnly\" class=\"keyboard-key__arrow-inline\">▼</span>\r\n </button>\r\n <!-- 有value又有options的按钮:单独可点击的下拉箭头 -->\r\n <span\r\n v-if=\"hasOptions && !isOptionsOnly\"\r\n class=\"keyboard-key__arrow\"\r\n @mousedown.prevent=\"handleArrowClick\"\r\n @touchstart.prevent=\"handleArrowClick\"\r\n >▼</span\r\n >\r\n </div>\r\n</template>\r\n\r\n<style>\r\n.keyboard-key-wrapper {\r\n position: relative;\r\n display: inline-flex;\r\n}\r\n\r\n.keyboard-key {\r\n display: inline-flex;\r\n align-items: center;\r\n justify-content: center;\r\n width: 100%;\r\n min-width: var(--ld-px-32);\r\n height: var(--keyboard-key-height);\r\n padding: 0 var(--ld-spacing-xs);\r\n border: 0;\r\n border-radius: var(--keyboard-key-radius);\r\n background-color: var(--keyboard-key-bg);\r\n color: var(--keyboard-key-color);\r\n font-size: var(--keyboard-font-size);\r\n font-weight: 500;\r\n cursor: pointer;\r\n user-select: none;\r\n touch-action: manipulation;\r\n box-shadow: var(--keyboard-key-shadow);\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-key.has-options {\r\n padding-right: var(--ld-px-16);\r\n}\r\n.keyboard-key:active {\r\n background-color: var(--keyboard-key-active-bg);\r\n transform: scale(0.95);\r\n}\r\n.keyboard-key--disabled {\r\n opacity: 0.4;\r\n cursor: not-allowed;\r\n}\r\n.keyboard-key--disabled:active {\r\n transform: none;\r\n background-color: var(--keyboard-key-bg);\r\n}\r\n\r\n.keyboard-key--backspace,\r\n.keyboard-key--shift,\r\n.keyboard-key--tab,\r\n.keyboard-key--clear,\r\n.keyboard-key--close {\r\n background-color: var(--keyboard-fn-key-bg);\r\n color: var(--keyboard-fn-key-color);\r\n font-size: var(--keyboard-fn-font-size);\r\n}\r\n\r\n.keyboard-key--backspace:active,\r\n.keyboard-key--shift:active,\r\n.keyboard-key--tab:active,\r\n.keyboard-key--clear:active,\r\n.keyboard-key--close:active {\r\n background-color: var(--keyboard-fn-key-active-bg);\r\n}\r\n\r\n.keyboard-key--active {\r\n background-color: var(--keyboard-key-active-bg) !important;\r\n color: var(--ld-text-inverse) !important;\r\n}\r\n\r\n.keyboard-key--done,\r\n.keyboard-key--enter {\r\n background-color: var(--keyboard-primary-bg);\r\n color: var(--keyboard-primary-color);\r\n font-size: var(--keyboard-fn-font-size);\r\n font-weight: 600;\r\n}\r\n\r\n.keyboard-key--done:active,\r\n.keyboard-key--enter:active {\r\n background-color: var(--keyboard-primary-active-bg);\r\n}\r\n.keyboard-key--space {\r\n background-color: var(--keyboard-key-bg);\r\n}\r\n\r\n.keyboard-key__icon {\r\n display: flex;\r\n align-items: center;\r\n justify-content: center;\r\n pointer-events: none;\r\n}\r\n.keyboard-key__icon svg {\r\n width: 1em;\r\n height: 1em;\r\n}\r\n.keyboard-key__label {\r\n pointer-events: none;\r\n line-height: 1;\r\n}\r\n\r\n.keyboard-key__arrow {\r\n position: absolute;\r\n top: 0;\r\n right: 0;\r\n bottom: 0;\r\n display: flex;\r\n align-items: center;\r\n justify-content: center;\r\n width: var(--ld-px-20);\r\n border-radius: var(--ld-radius-none) var(--ld-radius-sm) var(--ld-radius-sm)\r\n var(--ld-radius-none);\r\n font-size: var(--ld-font-xs);\r\n opacity: 0.5;\r\n cursor: pointer;\r\n user-select: none;\r\n touch-action: manipulation;\r\n}\r\n\r\n.keyboard-key__arrow:active {\r\n background-color: var(--keyboard-key-active-bg);\r\n opacity: 1;\r\n}\r\n\r\n.keyboard-key__arrow-inline {\r\n margin-left: var(--ld-px-4);\r\n font-size: var(--ld-font-xs);\r\n opacity: 0.6;\r\n pointer-events: none;\r\n}\r\n\r\n.keyboard-key.is-options-only {\r\n background-color: var(--keyboard-fn-key-bg);\r\n font-size: var(--ld-font-sm);\r\n}\r\n</style>\r\n"],"mappings":""}
|
|
@@ -0,0 +1,140 @@
|
|
|
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 { computed, createCommentVNode, createElementBlock, createElementVNode, defineComponent, normalizeClass, normalizeStyle, openBlock, toDisplayString, withModifiers } from "vue";
|
|
11
|
+
import { sanitizeSvgIcon } from "@composy/keyboard-core";
|
|
12
|
+
//#region src/components/KeyboardKey.vue?vue&type=script&setup=true&lang.ts
|
|
13
|
+
const _hoisted_1 = ["disabled"];
|
|
14
|
+
const _hoisted_2 = ["innerHTML"];
|
|
15
|
+
const _hoisted_3 = {
|
|
16
|
+
key: 1,
|
|
17
|
+
class: "keyboard-key__label"
|
|
18
|
+
};
|
|
19
|
+
const _hoisted_4 = {
|
|
20
|
+
key: 2,
|
|
21
|
+
class: "keyboard-key__label"
|
|
22
|
+
};
|
|
23
|
+
const _hoisted_5 = {
|
|
24
|
+
key: 3,
|
|
25
|
+
class: "keyboard-key__arrow-inline"
|
|
26
|
+
};
|
|
27
|
+
var KeyboardKey_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ defineComponent({
|
|
28
|
+
__name: "KeyboardKey",
|
|
29
|
+
props: {
|
|
30
|
+
keyDef: {
|
|
31
|
+
type: Object,
|
|
32
|
+
required: true
|
|
33
|
+
},
|
|
34
|
+
isUpperCase: {
|
|
35
|
+
type: Boolean,
|
|
36
|
+
required: false
|
|
37
|
+
},
|
|
38
|
+
baseWidth: {
|
|
39
|
+
type: Number,
|
|
40
|
+
required: false
|
|
41
|
+
},
|
|
42
|
+
useFlex: {
|
|
43
|
+
type: Boolean,
|
|
44
|
+
required: false
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
emits: ["press", "showOptions"],
|
|
48
|
+
setup(__props, { emit: __emit }) {
|
|
49
|
+
const props = __props;
|
|
50
|
+
const emit = __emit;
|
|
51
|
+
const label = computed(() => {
|
|
52
|
+
const keyLabel = props.keyDef.label;
|
|
53
|
+
if (typeof keyLabel === "string") return keyLabel;
|
|
54
|
+
return props.isUpperCase ? keyLabel.upper : keyLabel.lower;
|
|
55
|
+
});
|
|
56
|
+
const iconMarkup = computed(() => {
|
|
57
|
+
const icon = props.keyDef.icon;
|
|
58
|
+
return icon ? sanitizeSvgIcon(icon) : "";
|
|
59
|
+
});
|
|
60
|
+
const keyWidth = computed(() => {
|
|
61
|
+
if (props.useFlex) return;
|
|
62
|
+
const base = props.baseWidth ?? 36;
|
|
63
|
+
const width = props.keyDef.width ?? 1;
|
|
64
|
+
return `${base * width + (width - 1) * 6}px`;
|
|
65
|
+
});
|
|
66
|
+
const keyFlex = computed(() => {
|
|
67
|
+
if (!props.useFlex) return;
|
|
68
|
+
return props.keyDef.width ?? 1;
|
|
69
|
+
});
|
|
70
|
+
const keyClass = computed(() => {
|
|
71
|
+
const classes = ["keyboard-key", `keyboard-key--${props.keyDef.type}`];
|
|
72
|
+
if (props.keyDef.className) classes.push(props.keyDef.className);
|
|
73
|
+
if (props.keyDef.disabled) classes.push("keyboard-key--disabled");
|
|
74
|
+
if (props.keyDef.type === "shift" && props.isUpperCase) classes.push("keyboard-key--active");
|
|
75
|
+
return classes;
|
|
76
|
+
});
|
|
77
|
+
const hasOptions = computed(() => {
|
|
78
|
+
return props.keyDef.options && props.keyDef.options.length > 0;
|
|
79
|
+
});
|
|
80
|
+
const isOptionsOnly = computed(() => {
|
|
81
|
+
return hasOptions.value && !props.keyDef.value;
|
|
82
|
+
});
|
|
83
|
+
const handlePress = (event) => {
|
|
84
|
+
event.preventDefault();
|
|
85
|
+
event.stopPropagation();
|
|
86
|
+
if (props.keyDef.disabled) return;
|
|
87
|
+
if (isOptionsOnly.value) {
|
|
88
|
+
emit("showOptions", props.keyDef.options ?? []);
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
emit("press", props.keyDef);
|
|
92
|
+
};
|
|
93
|
+
const handleArrowClick = (event) => {
|
|
94
|
+
event.preventDefault();
|
|
95
|
+
event.stopPropagation();
|
|
96
|
+
if (props.keyDef.disabled) return;
|
|
97
|
+
if (hasOptions.value) emit("showOptions", props.keyDef.options ?? []);
|
|
98
|
+
};
|
|
99
|
+
return (_ctx, _cache) => {
|
|
100
|
+
return openBlock(), createElementBlock("div", {
|
|
101
|
+
class: "keyboard-key-wrapper",
|
|
102
|
+
style: normalizeStyle({
|
|
103
|
+
width: keyWidth.value,
|
|
104
|
+
flex: keyFlex.value
|
|
105
|
+
})
|
|
106
|
+
}, [
|
|
107
|
+
createElementVNode("button", {
|
|
108
|
+
class: normalizeClass([keyClass.value, {
|
|
109
|
+
"has-options": hasOptions.value && !isOptionsOnly.value,
|
|
110
|
+
"is-options-only": isOptionsOnly.value
|
|
111
|
+
}]),
|
|
112
|
+
disabled: __props.keyDef.disabled,
|
|
113
|
+
type: "button",
|
|
114
|
+
onMousedown: withModifiers(handlePress, ["prevent"]),
|
|
115
|
+
onTouchstart: withModifiers(handlePress, ["prevent"])
|
|
116
|
+
}, [
|
|
117
|
+
createCommentVNode(" SVG 图标支持 "),
|
|
118
|
+
iconMarkup.value ? (openBlock(), createElementBlock("span", {
|
|
119
|
+
key: 0,
|
|
120
|
+
class: "keyboard-key__icon",
|
|
121
|
+
innerHTML: iconMarkup.value
|
|
122
|
+
}, null, 8, _hoisted_2)) : __props.keyDef.icon ? (openBlock(), createElementBlock("span", _hoisted_3, toDisplayString(__props.keyDef.icon), 1)) : (openBlock(), createElementBlock("span", _hoisted_4, toDisplayString(label.value), 1)),
|
|
123
|
+
createCommentVNode(" 纯选项按钮内嵌下拉箭头 "),
|
|
124
|
+
isOptionsOnly.value ? (openBlock(), createElementBlock("span", _hoisted_5, "▼")) : createCommentVNode("v-if", true)
|
|
125
|
+
], 42, _hoisted_1),
|
|
126
|
+
createCommentVNode(" 有value又有options的按钮:单独可点击的下拉箭头 "),
|
|
127
|
+
hasOptions.value && !isOptionsOnly.value ? (openBlock(), createElementBlock("span", {
|
|
128
|
+
key: 0,
|
|
129
|
+
class: "keyboard-key__arrow",
|
|
130
|
+
onMousedown: withModifiers(handleArrowClick, ["prevent"]),
|
|
131
|
+
onTouchstart: withModifiers(handleArrowClick, ["prevent"])
|
|
132
|
+
}, "▼", 32)) : createCommentVNode("v-if", true)
|
|
133
|
+
], 4);
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
//#endregion
|
|
138
|
+
export { KeyboardKey_vue_vue_type_script_setup_true_lang_default as default };
|
|
139
|
+
/*! End of @composy/keyboard-vue | Powered by @composy/builder */
|
|
140
|
+
//# sourceMappingURL=KeyboardKey.vue_vue_type_script_setup_true_lang.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"KeyboardKey.vue_vue_type_script_setup_true_lang.js","names":[],"sources":["../../src/components/KeyboardKey.vue","../../src/components/KeyboardKey.vue"],"sourcesContent":["<script setup lang=\"ts\">\r\nimport type { KeyDefinition } from '@composy/keyboard-core'\r\nimport { sanitizeSvgIcon } from '@composy/keyboard-core'\r\nimport { computed } from 'vue'\r\n\r\nconst props = defineProps<{\r\n /**\r\n * 按键定义\r\n */\r\n keyDef: KeyDefinition\r\n /**\r\n * 是否大写状态\r\n */\r\n isUpperCase?: boolean\r\n /**\r\n * 基础宽度(px)\r\n */\r\n baseWidth?: number\r\n /**\r\n * 是否使用 flex 布局(用于 numpad 等需要均分宽度的键盘)\r\n */\r\n useFlex?: boolean\r\n}>()\r\n\r\nconst emit = defineEmits<{\r\n press: [key: KeyDefinition]\r\n showOptions: [options: string[]]\r\n}>()\r\n\r\n/**\r\n * 获取显示文本\r\n */\r\nconst label = computed(() => {\r\n const keyLabel = props.keyDef.label\r\n if (typeof keyLabel === 'string') {\r\n return keyLabel\r\n }\r\n return props.isUpperCase ? keyLabel.upper : keyLabel.lower\r\n})\r\n\r\nconst iconMarkup = computed(() => {\r\n const icon = props.keyDef.icon\r\n return icon ? sanitizeSvgIcon(icon) : ''\r\n})\r\n\r\n/**\r\n * 计算按键宽度\r\n */\r\nconst keyWidth = computed(() => {\r\n // 使用 flex 布局时,不设置固定宽度\r\n if (props.useFlex) {\r\n return undefined\r\n }\r\n const base = props.baseWidth ?? 36\r\n const width = props.keyDef.width ?? 1\r\n const gap = 6\r\n return `${base * width + (width - 1) * gap}px`\r\n})\r\n\r\n/**\r\n * 计算按键的 flex 值(用于 numpad 布局)\r\n */\r\nconst keyFlex = computed(() => {\r\n if (!props.useFlex) {\r\n return undefined\r\n }\r\n // width 属性决定占几份\r\n return props.keyDef.width ?? 1\r\n})\r\n\r\n/**\r\n * 计算 CSS 类\r\n */\r\nconst keyClass = computed(() => {\r\n const classes = ['keyboard-key', `keyboard-key--${props.keyDef.type}`]\r\n\r\n if (props.keyDef.className) {\r\n classes.push(props.keyDef.className)\r\n }\r\n\r\n if (props.keyDef.disabled) {\r\n classes.push('keyboard-key--disabled')\r\n }\r\n\r\n // Shift 键激活状态\r\n if (props.keyDef.type === 'shift' && props.isUpperCase) {\r\n classes.push('keyboard-key--active')\r\n }\r\n\r\n return classes\r\n})\r\n\r\n/**\r\n * 是否有下拉选项\r\n */\r\nconst hasOptions = computed(() => {\r\n return props.keyDef.options && props.keyDef.options.length > 0\r\n})\r\n\r\n/**\r\n * 是否是纯选项按钮(有options但无value,点击只显示选项面板)\r\n */\r\nconst isOptionsOnly = computed(() => {\r\n return hasOptions.value && !props.keyDef.value\r\n})\r\n\r\n/**\r\n * 处理按键点击\r\n */\r\nconst handlePress = (event: MouseEvent | TouchEvent) => {\r\n event.preventDefault()\r\n event.stopPropagation()\r\n\r\n if (props.keyDef.disabled) {\r\n return\r\n }\r\n\r\n // 纯选项按钮:点击直接显示选项面板\r\n if (isOptionsOnly.value) {\r\n emit('showOptions', props.keyDef.options ?? [])\r\n return\r\n }\r\n\r\n // 正常按键:触发按键事件\r\n emit('press', props.keyDef)\r\n}\r\n\r\n/**\r\n * 处理下拉箭头点击(显示选项面板)\r\n */\r\nconst handleArrowClick = (event: MouseEvent | TouchEvent) => {\r\n event.preventDefault()\r\n event.stopPropagation()\r\n\r\n if (props.keyDef.disabled) {\r\n return\r\n }\r\n\r\n if (hasOptions.value) {\r\n emit('showOptions', props.keyDef.options ?? [])\r\n }\r\n}\r\n</script>\r\n\r\n<template>\r\n <div class=\"keyboard-key-wrapper\" :style=\"{ width: keyWidth, flex: keyFlex }\">\r\n <button\r\n :class=\"[\r\n keyClass,\r\n {\r\n 'has-options': hasOptions && !isOptionsOnly,\r\n 'is-options-only': isOptionsOnly,\r\n },\r\n ]\"\r\n :disabled=\"keyDef.disabled\"\r\n type=\"button\"\r\n @mousedown.prevent=\"handlePress\"\r\n @touchstart.prevent=\"handlePress\"\r\n >\r\n <!-- SVG 图标支持 -->\r\n <span v-if=\"iconMarkup\" class=\"keyboard-key__icon\" v-html=\"iconMarkup\" />\r\n <span v-else-if=\"keyDef.icon\" class=\"keyboard-key__label\">{{\r\n keyDef.icon\r\n }}</span>\r\n <span v-else class=\"keyboard-key__label\">{{ label }}</span>\r\n <!-- 纯选项按钮内嵌下拉箭头 -->\r\n <span v-if=\"isOptionsOnly\" class=\"keyboard-key__arrow-inline\">▼</span>\r\n </button>\r\n <!-- 有value又有options的按钮:单独可点击的下拉箭头 -->\r\n <span\r\n v-if=\"hasOptions && !isOptionsOnly\"\r\n class=\"keyboard-key__arrow\"\r\n @mousedown.prevent=\"handleArrowClick\"\r\n @touchstart.prevent=\"handleArrowClick\"\r\n >▼</span\r\n >\r\n </div>\r\n</template>\r\n\r\n<style>\r\n.keyboard-key-wrapper {\r\n position: relative;\r\n display: inline-flex;\r\n}\r\n\r\n.keyboard-key {\r\n display: inline-flex;\r\n align-items: center;\r\n justify-content: center;\r\n width: 100%;\r\n min-width: var(--ld-px-32);\r\n height: var(--keyboard-key-height);\r\n padding: 0 var(--ld-spacing-xs);\r\n border: 0;\r\n border-radius: var(--keyboard-key-radius);\r\n background-color: var(--keyboard-key-bg);\r\n color: var(--keyboard-key-color);\r\n font-size: var(--keyboard-font-size);\r\n font-weight: 500;\r\n cursor: pointer;\r\n user-select: none;\r\n touch-action: manipulation;\r\n box-shadow: var(--keyboard-key-shadow);\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-key.has-options {\r\n padding-right: var(--ld-px-16);\r\n}\r\n.keyboard-key:active {\r\n background-color: var(--keyboard-key-active-bg);\r\n transform: scale(0.95);\r\n}\r\n.keyboard-key--disabled {\r\n opacity: 0.4;\r\n cursor: not-allowed;\r\n}\r\n.keyboard-key--disabled:active {\r\n transform: none;\r\n background-color: var(--keyboard-key-bg);\r\n}\r\n\r\n.keyboard-key--backspace,\r\n.keyboard-key--shift,\r\n.keyboard-key--tab,\r\n.keyboard-key--clear,\r\n.keyboard-key--close {\r\n background-color: var(--keyboard-fn-key-bg);\r\n color: var(--keyboard-fn-key-color);\r\n font-size: var(--keyboard-fn-font-size);\r\n}\r\n\r\n.keyboard-key--backspace:active,\r\n.keyboard-key--shift:active,\r\n.keyboard-key--tab:active,\r\n.keyboard-key--clear:active,\r\n.keyboard-key--close:active {\r\n background-color: var(--keyboard-fn-key-active-bg);\r\n}\r\n\r\n.keyboard-key--active {\r\n background-color: var(--keyboard-key-active-bg) !important;\r\n color: var(--ld-text-inverse) !important;\r\n}\r\n\r\n.keyboard-key--done,\r\n.keyboard-key--enter {\r\n background-color: var(--keyboard-primary-bg);\r\n color: var(--keyboard-primary-color);\r\n font-size: var(--keyboard-fn-font-size);\r\n font-weight: 600;\r\n}\r\n\r\n.keyboard-key--done:active,\r\n.keyboard-key--enter:active {\r\n background-color: var(--keyboard-primary-active-bg);\r\n}\r\n.keyboard-key--space {\r\n background-color: var(--keyboard-key-bg);\r\n}\r\n\r\n.keyboard-key__icon {\r\n display: flex;\r\n align-items: center;\r\n justify-content: center;\r\n pointer-events: none;\r\n}\r\n.keyboard-key__icon svg {\r\n width: 1em;\r\n height: 1em;\r\n}\r\n.keyboard-key__label {\r\n pointer-events: none;\r\n line-height: 1;\r\n}\r\n\r\n.keyboard-key__arrow {\r\n position: absolute;\r\n top: 0;\r\n right: 0;\r\n bottom: 0;\r\n display: flex;\r\n align-items: center;\r\n justify-content: center;\r\n width: var(--ld-px-20);\r\n border-radius: var(--ld-radius-none) var(--ld-radius-sm) var(--ld-radius-sm)\r\n var(--ld-radius-none);\r\n font-size: var(--ld-font-xs);\r\n opacity: 0.5;\r\n cursor: pointer;\r\n user-select: none;\r\n touch-action: manipulation;\r\n}\r\n\r\n.keyboard-key__arrow:active {\r\n background-color: var(--keyboard-key-active-bg);\r\n opacity: 1;\r\n}\r\n\r\n.keyboard-key__arrow-inline {\r\n margin-left: var(--ld-px-4);\r\n font-size: var(--ld-font-xs);\r\n opacity: 0.6;\r\n pointer-events: none;\r\n}\r\n\r\n.keyboard-key.is-options-only {\r\n background-color: var(--keyboard-fn-key-bg);\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\nimport { sanitizeSvgIcon } from '@composy/keyboard-core'\r\nimport { computed } from 'vue'\r\n\r\nconst props = defineProps<{\r\n /**\r\n * 按键定义\r\n */\r\n keyDef: KeyDefinition\r\n /**\r\n * 是否大写状态\r\n */\r\n isUpperCase?: boolean\r\n /**\r\n * 基础宽度(px)\r\n */\r\n baseWidth?: number\r\n /**\r\n * 是否使用 flex 布局(用于 numpad 等需要均分宽度的键盘)\r\n */\r\n useFlex?: boolean\r\n}>()\r\n\r\nconst emit = defineEmits<{\r\n press: [key: KeyDefinition]\r\n showOptions: [options: string[]]\r\n}>()\r\n\r\n/**\r\n * 获取显示文本\r\n */\r\nconst label = computed(() => {\r\n const keyLabel = props.keyDef.label\r\n if (typeof keyLabel === 'string') {\r\n return keyLabel\r\n }\r\n return props.isUpperCase ? keyLabel.upper : keyLabel.lower\r\n})\r\n\r\nconst iconMarkup = computed(() => {\r\n const icon = props.keyDef.icon\r\n return icon ? sanitizeSvgIcon(icon) : ''\r\n})\r\n\r\n/**\r\n * 计算按键宽度\r\n */\r\nconst keyWidth = computed(() => {\r\n // 使用 flex 布局时,不设置固定宽度\r\n if (props.useFlex) {\r\n return undefined\r\n }\r\n const base = props.baseWidth ?? 36\r\n const width = props.keyDef.width ?? 1\r\n const gap = 6\r\n return `${base * width + (width - 1) * gap}px`\r\n})\r\n\r\n/**\r\n * 计算按键的 flex 值(用于 numpad 布局)\r\n */\r\nconst keyFlex = computed(() => {\r\n if (!props.useFlex) {\r\n return undefined\r\n }\r\n // width 属性决定占几份\r\n return props.keyDef.width ?? 1\r\n})\r\n\r\n/**\r\n * 计算 CSS 类\r\n */\r\nconst keyClass = computed(() => {\r\n const classes = ['keyboard-key', `keyboard-key--${props.keyDef.type}`]\r\n\r\n if (props.keyDef.className) {\r\n classes.push(props.keyDef.className)\r\n }\r\n\r\n if (props.keyDef.disabled) {\r\n classes.push('keyboard-key--disabled')\r\n }\r\n\r\n // Shift 键激活状态\r\n if (props.keyDef.type === 'shift' && props.isUpperCase) {\r\n classes.push('keyboard-key--active')\r\n }\r\n\r\n return classes\r\n})\r\n\r\n/**\r\n * 是否有下拉选项\r\n */\r\nconst hasOptions = computed(() => {\r\n return props.keyDef.options && props.keyDef.options.length > 0\r\n})\r\n\r\n/**\r\n * 是否是纯选项按钮(有options但无value,点击只显示选项面板)\r\n */\r\nconst isOptionsOnly = computed(() => {\r\n return hasOptions.value && !props.keyDef.value\r\n})\r\n\r\n/**\r\n * 处理按键点击\r\n */\r\nconst handlePress = (event: MouseEvent | TouchEvent) => {\r\n event.preventDefault()\r\n event.stopPropagation()\r\n\r\n if (props.keyDef.disabled) {\r\n return\r\n }\r\n\r\n // 纯选项按钮:点击直接显示选项面板\r\n if (isOptionsOnly.value) {\r\n emit('showOptions', props.keyDef.options ?? [])\r\n return\r\n }\r\n\r\n // 正常按键:触发按键事件\r\n emit('press', props.keyDef)\r\n}\r\n\r\n/**\r\n * 处理下拉箭头点击(显示选项面板)\r\n */\r\nconst handleArrowClick = (event: MouseEvent | TouchEvent) => {\r\n event.preventDefault()\r\n event.stopPropagation()\r\n\r\n if (props.keyDef.disabled) {\r\n return\r\n }\r\n\r\n if (hasOptions.value) {\r\n emit('showOptions', props.keyDef.options ?? [])\r\n }\r\n}\r\n</script>\r\n\r\n<template>\r\n <div class=\"keyboard-key-wrapper\" :style=\"{ width: keyWidth, flex: keyFlex }\">\r\n <button\r\n :class=\"[\r\n keyClass,\r\n {\r\n 'has-options': hasOptions && !isOptionsOnly,\r\n 'is-options-only': isOptionsOnly,\r\n },\r\n ]\"\r\n :disabled=\"keyDef.disabled\"\r\n type=\"button\"\r\n @mousedown.prevent=\"handlePress\"\r\n @touchstart.prevent=\"handlePress\"\r\n >\r\n <!-- SVG 图标支持 -->\r\n <span v-if=\"iconMarkup\" class=\"keyboard-key__icon\" v-html=\"iconMarkup\" />\r\n <span v-else-if=\"keyDef.icon\" class=\"keyboard-key__label\">{{\r\n keyDef.icon\r\n }}</span>\r\n <span v-else class=\"keyboard-key__label\">{{ label }}</span>\r\n <!-- 纯选项按钮内嵌下拉箭头 -->\r\n <span v-if=\"isOptionsOnly\" class=\"keyboard-key__arrow-inline\">▼</span>\r\n </button>\r\n <!-- 有value又有options的按钮:单独可点击的下拉箭头 -->\r\n <span\r\n v-if=\"hasOptions && !isOptionsOnly\"\r\n class=\"keyboard-key__arrow\"\r\n @mousedown.prevent=\"handleArrowClick\"\r\n @touchstart.prevent=\"handleArrowClick\"\r\n >▼</span\r\n >\r\n </div>\r\n</template>\r\n\r\n<style>\r\n.keyboard-key-wrapper {\r\n position: relative;\r\n display: inline-flex;\r\n}\r\n\r\n.keyboard-key {\r\n display: inline-flex;\r\n align-items: center;\r\n justify-content: center;\r\n width: 100%;\r\n min-width: var(--ld-px-32);\r\n height: var(--keyboard-key-height);\r\n padding: 0 var(--ld-spacing-xs);\r\n border: 0;\r\n border-radius: var(--keyboard-key-radius);\r\n background-color: var(--keyboard-key-bg);\r\n color: var(--keyboard-key-color);\r\n font-size: var(--keyboard-font-size);\r\n font-weight: 500;\r\n cursor: pointer;\r\n user-select: none;\r\n touch-action: manipulation;\r\n box-shadow: var(--keyboard-key-shadow);\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-key.has-options {\r\n padding-right: var(--ld-px-16);\r\n}\r\n.keyboard-key:active {\r\n background-color: var(--keyboard-key-active-bg);\r\n transform: scale(0.95);\r\n}\r\n.keyboard-key--disabled {\r\n opacity: 0.4;\r\n cursor: not-allowed;\r\n}\r\n.keyboard-key--disabled:active {\r\n transform: none;\r\n background-color: var(--keyboard-key-bg);\r\n}\r\n\r\n.keyboard-key--backspace,\r\n.keyboard-key--shift,\r\n.keyboard-key--tab,\r\n.keyboard-key--clear,\r\n.keyboard-key--close {\r\n background-color: var(--keyboard-fn-key-bg);\r\n color: var(--keyboard-fn-key-color);\r\n font-size: var(--keyboard-fn-font-size);\r\n}\r\n\r\n.keyboard-key--backspace:active,\r\n.keyboard-key--shift:active,\r\n.keyboard-key--tab:active,\r\n.keyboard-key--clear:active,\r\n.keyboard-key--close:active {\r\n background-color: var(--keyboard-fn-key-active-bg);\r\n}\r\n\r\n.keyboard-key--active {\r\n background-color: var(--keyboard-key-active-bg) !important;\r\n color: var(--ld-text-inverse) !important;\r\n}\r\n\r\n.keyboard-key--done,\r\n.keyboard-key--enter {\r\n background-color: var(--keyboard-primary-bg);\r\n color: var(--keyboard-primary-color);\r\n font-size: var(--keyboard-fn-font-size);\r\n font-weight: 600;\r\n}\r\n\r\n.keyboard-key--done:active,\r\n.keyboard-key--enter:active {\r\n background-color: var(--keyboard-primary-active-bg);\r\n}\r\n.keyboard-key--space {\r\n background-color: var(--keyboard-key-bg);\r\n}\r\n\r\n.keyboard-key__icon {\r\n display: flex;\r\n align-items: center;\r\n justify-content: center;\r\n pointer-events: none;\r\n}\r\n.keyboard-key__icon svg {\r\n width: 1em;\r\n height: 1em;\r\n}\r\n.keyboard-key__label {\r\n pointer-events: none;\r\n line-height: 1;\r\n}\r\n\r\n.keyboard-key__arrow {\r\n position: absolute;\r\n top: 0;\r\n right: 0;\r\n bottom: 0;\r\n display: flex;\r\n align-items: center;\r\n justify-content: center;\r\n width: var(--ld-px-20);\r\n border-radius: var(--ld-radius-none) var(--ld-radius-sm) var(--ld-radius-sm)\r\n var(--ld-radius-none);\r\n font-size: var(--ld-font-xs);\r\n opacity: 0.5;\r\n cursor: pointer;\r\n user-select: none;\r\n touch-action: manipulation;\r\n}\r\n\r\n.keyboard-key__arrow:active {\r\n background-color: var(--keyboard-key-active-bg);\r\n opacity: 1;\r\n}\r\n\r\n.keyboard-key__arrow-inline {\r\n margin-left: var(--ld-px-4);\r\n font-size: var(--ld-font-xs);\r\n opacity: 0.6;\r\n pointer-events: none;\r\n}\r\n\r\n.keyboard-key.is-options-only {\r\n background-color: var(--keyboard-fn-key-bg);\r\n font-size: var(--ld-font-sm);\r\n}\r\n</style>\r\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAKA,MAAM,QAAQ;EAmBd,MAAM,OAAO;EAQb,MAAM,QAAQ,eAAe;GAC3B,MAAM,WAAW,MAAM,OAAO;GAC9B,IAAI,OAAO,aAAa,UACtB,OAAO;GAET,OAAO,MAAM,cAAc,SAAS,QAAQ,SAAS;EACvD,CAAC;EAED,MAAM,aAAa,eAAe;GAChC,MAAM,OAAO,MAAM,OAAO;GAC1B,OAAO,OAAO,gBAAgB,IAAI,IAAI;EACxC,CAAC;EAKD,MAAM,WAAW,eAAe;GAE9B,IAAI,MAAM,SACR;GAEF,MAAM,OAAO,MAAM,aAAa;GAChC,MAAM,QAAQ,MAAM,OAAO,SAAS;GAEpC,OAAO,GAAG,OAAO,SAAS,QAAQ,KAAK,EAAG;EAC5C,CAAC;EAKD,MAAM,UAAU,eAAe;GAC7B,IAAI,CAAC,MAAM,SACT;GAGF,OAAO,MAAM,OAAO,SAAS;EAC/B,CAAC;EAKD,MAAM,WAAW,eAAe;GAC9B,MAAM,UAAU,CAAC,gBAAgB,iBAAiB,MAAM,OAAO,MAAM;GAErE,IAAI,MAAM,OAAO,WACf,QAAQ,KAAK,MAAM,OAAO,SAAS;GAGrC,IAAI,MAAM,OAAO,UACf,QAAQ,KAAK,wBAAwB;GAIvC,IAAI,MAAM,OAAO,SAAS,WAAW,MAAM,aACzC,QAAQ,KAAK,sBAAsB;GAGrC,OAAO;EACT,CAAC;EAKD,MAAM,aAAa,eAAe;GAChC,OAAO,MAAM,OAAO,WAAW,MAAM,OAAO,QAAQ,SAAS;EAC/D,CAAC;EAKD,MAAM,gBAAgB,eAAe;GACnC,OAAO,WAAW,SAAS,CAAC,MAAM,OAAO;EAC3C,CAAC;EAKD,MAAM,eAAe,UAAmC;GACtD,MAAM,eAAe;GACrB,MAAM,gBAAgB;GAEtB,IAAI,MAAM,OAAO,UACf;GAIF,IAAI,cAAc,OAAO;IACvB,KAAK,eAAe,MAAM,OAAO,WAAW,CAAC,CAAC;IAC9C;GACF;GAGA,KAAK,SAAS,MAAM,MAAM;EAC5B;EAKA,MAAM,oBAAoB,UAAmC;GAC3D,MAAM,eAAe;GACrB,MAAM,gBAAgB;GAEtB,IAAI,MAAM,OAAO,UACf;GAGF,IAAI,WAAW,OACb,KAAK,eAAe,MAAM,OAAO,WAAW,CAAC,CAAC;EAElD;;uBCIE,mBA+BM,OAAA;IA/BD,OAAM;IAAwB,OAAK,eAAA;KAAA,OAAW,SAAA;KAAQ,MAAQ,QAAA;IAAO,CAAA;;IACxE,mBAqBS,UAAA;KApBN,OAAK,eAAA,CAAa,SAAA,OAAA;qBAA+C,WAAA,SAAU,CAAK,cAAA;yBAA6C,cAAA;;KAO7H,UAAU,QAAA,OAAO;KAClB,MAAK;KACJ,aAAS,cAAU,aAAW,CAAA,SAAA,CAAA;KAC9B,cAAU,cAAU,aAAW,CAAA,SAAA,CAAA;;KAEhC,mBAAA,YAAA;KACY,WAAA,SAAA,UAAA,GAAZ,mBAAyE,QAAA;;MAAjD,OAAM;MAAqB,WAAQ,WAAA;gCAC1C,QAAA,OAAO,QAAA,UAAA,GAAxB,mBAES,QAFT,YAES,gBADP,QAAA,OAAO,IAAI,GAAA,CAAA,MAAA,UAAA,GAEb,mBAA2D,QAA3D,YAA2D,gBAAf,MAAA,KAAK,GAAA,CAAA;KACjD,mBAAA,eAAA;KACY,cAAA,SAAA,UAAA,GAAZ,mBAAsE,QAAtE,YAA8D,GAAC,KAAA,mBAAA,QAAA,IAAA;;IAEjE,mBAAA,iCAAA;IAEQ,WAAA,SAAU,CAAK,cAAA,SAAA,UAAA,GADvB,mBAKiB,QAAA;;KAHf,OAAM;KACL,aAAS,cAAU,kBAAgB,CAAA,SAAA,CAAA;KACnC,cAAU,cAAU,kBAAgB,CAAA,SAAA,CAAA;OACpC,KAAC,EAAA,KAAA,mBAAA,QAAA,IAAA"}
|
|
@@ -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 KeyboardPopup_vue_vue_type_script_setup_true_lang_default from "./KeyboardPopup.vue_vue_type_script_setup_true_lang.js";
|
|
11
|
+
//#region src/components/KeyboardPopup.vue
|
|
12
|
+
KeyboardPopup_vue_vue_type_script_setup_true_lang_default.__file = "src/components/KeyboardPopup.vue";
|
|
13
|
+
var KeyboardPopup_default = KeyboardPopup_vue_vue_type_script_setup_true_lang_default;
|
|
14
|
+
//#endregion
|
|
15
|
+
export { KeyboardPopup_default as default };
|
|
16
|
+
/*! End of @composy/keyboard-vue | Powered by @composy/builder */
|
|
17
|
+
//# sourceMappingURL=KeyboardPopup.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"KeyboardPopup.js","names":[],"sources":["../../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"],"mappings":""}
|