@composy/keyboard-core 0.0.1
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 +37 -0
- package/dist/index.js +3605 -0
- package/dist/index.js.map +1 -0
- package/dist/index.min.js +1 -0
- package/es/icons.d.ts +58 -0
- package/es/icons.d.ts.map +1 -0
- package/es/icons.js +34 -0
- package/es/icons.js.map +1 -0
- package/es/index.d.ts +12 -0
- package/es/index.d.ts.map +1 -0
- package/es/index.js +36 -0
- package/es/layouts/amount.d.ts +14 -0
- package/es/layouts/amount.d.ts.map +1 -0
- package/es/layouts/amount.js +175 -0
- package/es/layouts/amount.js.map +1 -0
- package/es/layouts/bankcard.d.ts +15 -0
- package/es/layouts/bankcard.d.ts.map +1 -0
- package/es/layouts/bankcard.js +99 -0
- package/es/layouts/bankcard.js.map +1 -0
- package/es/layouts/email.d.ts +11 -0
- package/es/layouts/email.d.ts.map +1 -0
- package/es/layouts/email.js +126 -0
- package/es/layouts/email.js.map +1 -0
- package/es/layouts/idcard.d.ts +16 -0
- package/es/layouts/idcard.d.ts.map +1 -0
- package/es/layouts/idcard.js +99 -0
- package/es/layouts/idcard.js.map +1 -0
- package/es/layouts/index.d.ts +54 -0
- package/es/layouts/index.d.ts.map +1 -0
- package/es/layouts/index.js +78 -0
- package/es/layouts/index.js.map +1 -0
- package/es/layouts/license-plate.d.ts +35 -0
- package/es/layouts/license-plate.d.ts.map +1 -0
- package/es/layouts/license-plate.js +290 -0
- package/es/layouts/license-plate.js.map +1 -0
- package/es/layouts/number.d.ts +14 -0
- package/es/layouts/number.d.ts.map +1 -0
- package/es/layouts/number.js +168 -0
- package/es/layouts/number.js.map +1 -0
- package/es/layouts/phone.d.ts +15 -0
- package/es/layouts/phone.d.ts.map +1 -0
- package/es/layouts/phone.js +175 -0
- package/es/layouts/phone.js.map +1 -0
- package/es/layouts/punct.d.ts +7 -0
- package/es/layouts/punct.d.ts.map +1 -0
- package/es/layouts/punct.js +112 -0
- package/es/layouts/punct.js.map +1 -0
- package/es/layouts/qwerty.d.ts +10 -0
- package/es/layouts/qwerty.d.ts.map +1 -0
- package/es/layouts/qwerty.js +116 -0
- package/es/layouts/qwerty.js.map +1 -0
- package/es/layouts/search.d.ts +7 -0
- package/es/layouts/search.d.ts.map +1 -0
- package/es/layouts/search.js +101 -0
- package/es/layouts/search.js.map +1 -0
- package/es/layouts/symbol.d.ts +14 -0
- package/es/layouts/symbol.d.ts.map +1 -0
- package/es/layouts/symbol.js +194 -0
- package/es/layouts/symbol.js.map +1 -0
- package/es/layouts/url.d.ts +7 -0
- package/es/layouts/url.d.ts.map +1 -0
- package/es/layouts/url.js +99 -0
- package/es/layouts/url.js.map +1 -0
- package/es/layouts/verifycode.d.ts +15 -0
- package/es/layouts/verifycode.d.ts.map +1 -0
- package/es/layouts/verifycode.js +100 -0
- package/es/layouts/verifycode.js.map +1 -0
- package/es/managers/index.d.ts +8 -0
- package/es/managers/index.d.ts.map +1 -0
- package/es/managers/index.js +14 -0
- package/es/managers/keyboard-manager.d.ts +130 -0
- package/es/managers/keyboard-manager.d.ts.map +1 -0
- package/es/managers/keyboard-manager.js +374 -0
- package/es/managers/keyboard-manager.js.map +1 -0
- package/es/managers/keyboard-renderer.d.ts +115 -0
- package/es/managers/keyboard-renderer.d.ts.map +1 -0
- package/es/managers/keyboard-renderer.js +283 -0
- package/es/managers/keyboard-renderer.js.map +1 -0
- package/es/managers/position-manager.d.ts +72 -0
- package/es/managers/position-manager.d.ts.map +1 -0
- package/es/managers/position-manager.js +199 -0
- package/es/managers/position-manager.js.map +1 -0
- package/es/themes/index.d.ts +70 -0
- package/es/themes/index.d.ts.map +1 -0
- package/es/themes/index.js +99 -0
- package/es/themes/index.js.map +1 -0
- package/es/themes/presets.d.ts +39 -0
- package/es/themes/presets.d.ts.map +1 -0
- package/es/themes/presets.js +207 -0
- package/es/themes/presets.js.map +1 -0
- package/es/themes/types.d.ts +118 -0
- package/es/themes/types.d.ts.map +1 -0
- package/es/themes/types.js +10 -0
- package/es/types/index.d.ts +7 -0
- package/es/types/index.d.ts.map +1 -0
- package/es/types/index.js +10 -0
- package/es/types/keyboard.d.ts +253 -0
- package/es/types/keyboard.d.ts.map +1 -0
- package/es/types/keyboard.js +10 -0
- package/es/types/position.d.ts +139 -0
- package/es/types/position.d.ts.map +1 -0
- package/es/types/position.js +10 -0
- package/es/utils/device.d.ts +45 -0
- package/es/utils/device.d.ts.map +1 -0
- package/es/utils/device.js +111 -0
- package/es/utils/device.js.map +1 -0
- package/es/utils/dom.d.ts +69 -0
- package/es/utils/dom.d.ts.map +1 -0
- package/es/utils/dom.js +134 -0
- package/es/utils/dom.js.map +1 -0
- package/es/utils/event-emitter.d.ts +52 -0
- package/es/utils/event-emitter.d.ts.map +1 -0
- package/es/utils/event-emitter.js +99 -0
- package/es/utils/event-emitter.js.map +1 -0
- package/es/utils/formatters.d.ts +51 -0
- package/es/utils/formatters.d.ts.map +1 -0
- package/es/utils/formatters.js +57 -0
- package/es/utils/formatters.js.map +1 -0
- package/es/utils/index.d.ts +10 -0
- package/es/utils/index.d.ts.map +1 -0
- package/es/utils/index.js +16 -0
- package/es/utils/random.d.ts +71 -0
- package/es/utils/random.d.ts.map +1 -0
- package/es/utils/random.js +292 -0
- package/es/utils/random.js.map +1 -0
- package/esm/icons.d.ts +58 -0
- package/esm/icons.d.ts.map +1 -0
- package/esm/icons.js +34 -0
- package/esm/icons.js.map +1 -0
- package/esm/index.d.ts +12 -0
- package/esm/index.d.ts.map +1 -0
- package/esm/index.js +37 -0
- package/esm/layouts/amount.d.ts +14 -0
- package/esm/layouts/amount.d.ts.map +1 -0
- package/esm/layouts/amount.js +175 -0
- package/esm/layouts/amount.js.map +1 -0
- package/esm/layouts/bankcard.d.ts +15 -0
- package/esm/layouts/bankcard.d.ts.map +1 -0
- package/esm/layouts/bankcard.js +99 -0
- package/esm/layouts/bankcard.js.map +1 -0
- package/esm/layouts/email.d.ts +11 -0
- package/esm/layouts/email.d.ts.map +1 -0
- package/esm/layouts/email.js +126 -0
- package/esm/layouts/email.js.map +1 -0
- package/esm/layouts/idcard.d.ts +16 -0
- package/esm/layouts/idcard.d.ts.map +1 -0
- package/esm/layouts/idcard.js +99 -0
- package/esm/layouts/idcard.js.map +1 -0
- package/esm/layouts/index.d.ts +54 -0
- package/esm/layouts/index.d.ts.map +1 -0
- package/esm/layouts/index.js +78 -0
- package/esm/layouts/index.js.map +1 -0
- package/esm/layouts/license-plate.d.ts +35 -0
- package/esm/layouts/license-plate.d.ts.map +1 -0
- package/esm/layouts/license-plate.js +290 -0
- package/esm/layouts/license-plate.js.map +1 -0
- package/esm/layouts/number.d.ts +14 -0
- package/esm/layouts/number.d.ts.map +1 -0
- package/esm/layouts/number.js +168 -0
- package/esm/layouts/number.js.map +1 -0
- package/esm/layouts/phone.d.ts +15 -0
- package/esm/layouts/phone.d.ts.map +1 -0
- package/esm/layouts/phone.js +175 -0
- package/esm/layouts/phone.js.map +1 -0
- package/esm/layouts/punct.d.ts +7 -0
- package/esm/layouts/punct.d.ts.map +1 -0
- package/esm/layouts/punct.js +112 -0
- package/esm/layouts/punct.js.map +1 -0
- package/esm/layouts/qwerty.d.ts +10 -0
- package/esm/layouts/qwerty.d.ts.map +1 -0
- package/esm/layouts/qwerty.js +116 -0
- package/esm/layouts/qwerty.js.map +1 -0
- package/esm/layouts/search.d.ts +7 -0
- package/esm/layouts/search.d.ts.map +1 -0
- package/esm/layouts/search.js +101 -0
- package/esm/layouts/search.js.map +1 -0
- package/esm/layouts/symbol.d.ts +14 -0
- package/esm/layouts/symbol.d.ts.map +1 -0
- package/esm/layouts/symbol.js +194 -0
- package/esm/layouts/symbol.js.map +1 -0
- package/esm/layouts/url.d.ts +7 -0
- package/esm/layouts/url.d.ts.map +1 -0
- package/esm/layouts/url.js +99 -0
- package/esm/layouts/url.js.map +1 -0
- package/esm/layouts/verifycode.d.ts +15 -0
- package/esm/layouts/verifycode.d.ts.map +1 -0
- package/esm/layouts/verifycode.js +100 -0
- package/esm/layouts/verifycode.js.map +1 -0
- package/esm/managers/index.d.ts +8 -0
- package/esm/managers/index.d.ts.map +1 -0
- package/esm/managers/index.js +14 -0
- package/esm/managers/keyboard-manager.d.ts +130 -0
- package/esm/managers/keyboard-manager.d.ts.map +1 -0
- package/esm/managers/keyboard-manager.js +374 -0
- package/esm/managers/keyboard-manager.js.map +1 -0
- package/esm/managers/keyboard-renderer.d.ts +115 -0
- package/esm/managers/keyboard-renderer.d.ts.map +1 -0
- package/esm/managers/keyboard-renderer.js +283 -0
- package/esm/managers/keyboard-renderer.js.map +1 -0
- package/esm/managers/position-manager.d.ts +72 -0
- package/esm/managers/position-manager.d.ts.map +1 -0
- package/esm/managers/position-manager.js +199 -0
- package/esm/managers/position-manager.js.map +1 -0
- package/esm/themes/index.d.ts +70 -0
- package/esm/themes/index.d.ts.map +1 -0
- package/esm/themes/index.js +99 -0
- package/esm/themes/index.js.map +1 -0
- package/esm/themes/presets.d.ts +39 -0
- package/esm/themes/presets.d.ts.map +1 -0
- package/esm/themes/presets.js +207 -0
- package/esm/themes/presets.js.map +1 -0
- package/esm/themes/types.d.ts +118 -0
- package/esm/themes/types.d.ts.map +1 -0
- package/esm/themes/types.js +10 -0
- package/esm/types/index.d.ts +7 -0
- package/esm/types/index.d.ts.map +1 -0
- package/esm/types/index.js +10 -0
- package/esm/types/keyboard.d.ts +253 -0
- package/esm/types/keyboard.d.ts.map +1 -0
- package/esm/types/keyboard.js +10 -0
- package/esm/types/position.d.ts +139 -0
- package/esm/types/position.d.ts.map +1 -0
- package/esm/types/position.js +10 -0
- package/esm/utils/device.d.ts +45 -0
- package/esm/utils/device.d.ts.map +1 -0
- package/esm/utils/device.js +111 -0
- package/esm/utils/device.js.map +1 -0
- package/esm/utils/dom.d.ts +69 -0
- package/esm/utils/dom.d.ts.map +1 -0
- package/esm/utils/dom.js +134 -0
- package/esm/utils/dom.js.map +1 -0
- package/esm/utils/event-emitter.d.ts +52 -0
- package/esm/utils/event-emitter.d.ts.map +1 -0
- package/esm/utils/event-emitter.js +99 -0
- package/esm/utils/event-emitter.js.map +1 -0
- package/esm/utils/formatters.d.ts +51 -0
- package/esm/utils/formatters.d.ts.map +1 -0
- package/esm/utils/formatters.js +57 -0
- package/esm/utils/formatters.js.map +1 -0
- package/esm/utils/index.d.ts +10 -0
- package/esm/utils/index.d.ts.map +1 -0
- package/esm/utils/index.js +16 -0
- package/esm/utils/random.d.ts +71 -0
- package/esm/utils/random.d.ts.map +1 -0
- package/esm/utils/random.js +292 -0
- package/esm/utils/random.js.map +1 -0
- package/lib/icons.cjs +44 -0
- package/lib/icons.cjs.map +1 -0
- package/lib/icons.d.ts +58 -0
- package/lib/index.cjs +141 -0
- package/lib/index.d.ts +12 -0
- package/lib/layouts/amount.cjs +177 -0
- package/lib/layouts/amount.cjs.map +1 -0
- package/lib/layouts/amount.d.ts +14 -0
- package/lib/layouts/bankcard.cjs +100 -0
- package/lib/layouts/bankcard.cjs.map +1 -0
- package/lib/layouts/bankcard.d.ts +15 -0
- package/lib/layouts/email.cjs +128 -0
- package/lib/layouts/email.cjs.map +1 -0
- package/lib/layouts/email.d.ts +11 -0
- package/lib/layouts/idcard.cjs +100 -0
- package/lib/layouts/idcard.cjs.map +1 -0
- package/lib/layouts/idcard.d.ts +16 -0
- package/lib/layouts/index.cjs +107 -0
- package/lib/layouts/index.cjs.map +1 -0
- package/lib/layouts/index.d.ts +54 -0
- package/lib/layouts/license-plate.cjs +296 -0
- package/lib/layouts/license-plate.cjs.map +1 -0
- package/lib/layouts/license-plate.d.ts +35 -0
- package/lib/layouts/number.cjs +170 -0
- package/lib/layouts/number.cjs.map +1 -0
- package/lib/layouts/number.d.ts +14 -0
- package/lib/layouts/phone.cjs +177 -0
- package/lib/layouts/phone.cjs.map +1 -0
- package/lib/layouts/phone.d.ts +15 -0
- package/lib/layouts/punct.cjs +113 -0
- package/lib/layouts/punct.cjs.map +1 -0
- package/lib/layouts/punct.d.ts +7 -0
- package/lib/layouts/qwerty.cjs +117 -0
- package/lib/layouts/qwerty.cjs.map +1 -0
- package/lib/layouts/qwerty.d.ts +10 -0
- package/lib/layouts/search.cjs +102 -0
- package/lib/layouts/search.cjs.map +1 -0
- package/lib/layouts/search.d.ts +7 -0
- package/lib/layouts/symbol.cjs +196 -0
- package/lib/layouts/symbol.cjs.map +1 -0
- package/lib/layouts/symbol.d.ts +14 -0
- package/lib/layouts/url.cjs +100 -0
- package/lib/layouts/url.cjs.map +1 -0
- package/lib/layouts/url.d.ts +7 -0
- package/lib/layouts/verifycode.cjs +101 -0
- package/lib/layouts/verifycode.cjs.map +1 -0
- package/lib/layouts/verifycode.d.ts +15 -0
- package/lib/managers/index.cjs +20 -0
- package/lib/managers/index.d.ts +8 -0
- package/lib/managers/keyboard-manager.cjs +376 -0
- package/lib/managers/keyboard-manager.cjs.map +1 -0
- package/lib/managers/keyboard-manager.d.ts +130 -0
- package/lib/managers/keyboard-renderer.cjs +285 -0
- package/lib/managers/keyboard-renderer.cjs.map +1 -0
- package/lib/managers/keyboard-renderer.d.ts +115 -0
- package/lib/managers/position-manager.cjs +201 -0
- package/lib/managers/position-manager.cjs.map +1 -0
- package/lib/managers/position-manager.d.ts +72 -0
- package/lib/package.json +3 -0
- package/lib/themes/index.cjs +117 -0
- package/lib/themes/index.cjs.map +1 -0
- package/lib/themes/index.d.ts +70 -0
- package/lib/themes/presets.cjs +214 -0
- package/lib/themes/presets.cjs.map +1 -0
- package/lib/themes/presets.d.ts +39 -0
- package/lib/themes/types.cjs +11 -0
- package/lib/themes/types.d.ts +118 -0
- package/lib/types/index.cjs +11 -0
- package/lib/types/index.d.ts +7 -0
- package/lib/types/keyboard.cjs +11 -0
- package/lib/types/keyboard.d.ts +253 -0
- package/lib/types/position.cjs +11 -0
- package/lib/types/position.d.ts +139 -0
- package/lib/utils/device.cjs +120 -0
- package/lib/utils/device.cjs.map +1 -0
- package/lib/utils/device.d.ts +45 -0
- package/lib/utils/dom.cjs +148 -0
- package/lib/utils/dom.cjs.map +1 -0
- package/lib/utils/dom.d.ts +69 -0
- package/lib/utils/event-emitter.cjs +100 -0
- package/lib/utils/event-emitter.cjs.map +1 -0
- package/lib/utils/event-emitter.d.ts +52 -0
- package/lib/utils/formatters.cjs +66 -0
- package/lib/utils/formatters.cjs.map +1 -0
- package/lib/utils/formatters.d.ts +51 -0
- package/lib/utils/index.cjs +58 -0
- package/lib/utils/index.d.ts +10 -0
- package/lib/utils/random.cjs +301 -0
- package/lib/utils/random.cjs.map +1 -0
- package/lib/utils/random.d.ts +71 -0
- package/package.json +121 -0
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* ***********************************
|
|
3
|
+
* @composy/keyboard-core v0.0.1 *
|
|
4
|
+
* Built with rollup *
|
|
5
|
+
* Build time: 2024-08-17 11:33:29 *
|
|
6
|
+
* Build mode: production *
|
|
7
|
+
* Minified: No *
|
|
8
|
+
* ***********************************
|
|
9
|
+
*/
|
|
10
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
11
|
+
//#region src/utils/random.ts
|
|
12
|
+
function shuffleArray(array) {
|
|
13
|
+
const result = [...array];
|
|
14
|
+
for (let i = result.length - 1; i > 0; i--) {
|
|
15
|
+
const j = Math.floor(Math.random() * (i + 1));
|
|
16
|
+
[result[i], result[j]] = [result[j], result[i]];
|
|
17
|
+
}
|
|
18
|
+
return result;
|
|
19
|
+
}
|
|
20
|
+
function getRandomNumbers() {
|
|
21
|
+
return shuffleArray([
|
|
22
|
+
"0",
|
|
23
|
+
"1",
|
|
24
|
+
"2",
|
|
25
|
+
"3",
|
|
26
|
+
"4",
|
|
27
|
+
"5",
|
|
28
|
+
"6",
|
|
29
|
+
"7",
|
|
30
|
+
"8",
|
|
31
|
+
"9"
|
|
32
|
+
]);
|
|
33
|
+
}
|
|
34
|
+
function getRandomLetters() {
|
|
35
|
+
return shuffleArray(Array.from({ length: 26 }, (_, i) => String.fromCharCode(65 + i)));
|
|
36
|
+
}
|
|
37
|
+
function getRandomAlphanumeric() {
|
|
38
|
+
const numbers = [
|
|
39
|
+
"0",
|
|
40
|
+
"1",
|
|
41
|
+
"2",
|
|
42
|
+
"3",
|
|
43
|
+
"4",
|
|
44
|
+
"5",
|
|
45
|
+
"6",
|
|
46
|
+
"7",
|
|
47
|
+
"8",
|
|
48
|
+
"9"
|
|
49
|
+
];
|
|
50
|
+
const letters = Array.from({ length: 26 }, (_, i) => String.fromCharCode(65 + i));
|
|
51
|
+
return shuffleArray([...numbers, ...letters]);
|
|
52
|
+
}
|
|
53
|
+
function createCharKey(char, index) {
|
|
54
|
+
return {
|
|
55
|
+
id: `random-${char}-${index}`,
|
|
56
|
+
type: "char",
|
|
57
|
+
label: char,
|
|
58
|
+
value: char,
|
|
59
|
+
className: "key-random"
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
function chunkArray(array, chunkSize) {
|
|
63
|
+
const chunks = [];
|
|
64
|
+
for (let i = 0; i < array.length; i += chunkSize) chunks.push(array.slice(i, i + chunkSize));
|
|
65
|
+
return chunks;
|
|
66
|
+
}
|
|
67
|
+
function createRandomNumberLayout(options) {
|
|
68
|
+
const { keysPerRow = 3, includeBackspace = true, includeDone = true, includeClear = false } = options || {};
|
|
69
|
+
const rows = chunkArray(getRandomNumbers().map((n, i) => createCharKey(n, i)), keysPerRow).map((keys, index) => ({
|
|
70
|
+
className: "numpad-row",
|
|
71
|
+
keys
|
|
72
|
+
}));
|
|
73
|
+
const fnKeys = [];
|
|
74
|
+
if (includeClear) fnKeys.push({
|
|
75
|
+
id: "clear",
|
|
76
|
+
type: "clear",
|
|
77
|
+
label: "清空",
|
|
78
|
+
className: "key-clear key-fn"
|
|
79
|
+
});
|
|
80
|
+
if (includeBackspace) fnKeys.push({
|
|
81
|
+
id: "backspace",
|
|
82
|
+
type: "backspace",
|
|
83
|
+
label: "⌫",
|
|
84
|
+
className: "key-backspace key-fn"
|
|
85
|
+
});
|
|
86
|
+
if (includeDone) fnKeys.push({
|
|
87
|
+
id: "done",
|
|
88
|
+
type: "done",
|
|
89
|
+
label: "确定",
|
|
90
|
+
className: "key-done key-fn"
|
|
91
|
+
});
|
|
92
|
+
if (fnKeys.length > 0) rows.push({
|
|
93
|
+
className: "numpad-row",
|
|
94
|
+
keys: fnKeys
|
|
95
|
+
});
|
|
96
|
+
return {
|
|
97
|
+
type: "custom",
|
|
98
|
+
name: "随机数字键盘",
|
|
99
|
+
supportShift: false,
|
|
100
|
+
rows,
|
|
101
|
+
data: {
|
|
102
|
+
isRandom: true,
|
|
103
|
+
randomType: "number"
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
function createRandomPinLayout(options) {
|
|
108
|
+
const { includeBackspace = true, includeDone = true } = options || {};
|
|
109
|
+
const randomNumbers = getRandomNumbers();
|
|
110
|
+
const rows = [
|
|
111
|
+
{
|
|
112
|
+
className: "numpad-row",
|
|
113
|
+
keys: randomNumbers.slice(0, 3).map((n, i) => createCharKey(n, i))
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
className: "numpad-row",
|
|
117
|
+
keys: randomNumbers.slice(3, 6).map((n, i) => createCharKey(n, i + 3))
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
className: "numpad-row",
|
|
121
|
+
keys: randomNumbers.slice(6, 9).map((n, i) => createCharKey(n, i + 6))
|
|
122
|
+
}
|
|
123
|
+
];
|
|
124
|
+
const lastRow = [];
|
|
125
|
+
if (includeBackspace) lastRow.push({
|
|
126
|
+
id: "backspace",
|
|
127
|
+
type: "backspace",
|
|
128
|
+
label: "⌫",
|
|
129
|
+
className: "key-backspace key-fn"
|
|
130
|
+
});
|
|
131
|
+
else lastRow.push({
|
|
132
|
+
id: "empty-1",
|
|
133
|
+
type: "char",
|
|
134
|
+
label: "",
|
|
135
|
+
value: "",
|
|
136
|
+
disabled: true,
|
|
137
|
+
className: "key-placeholder"
|
|
138
|
+
});
|
|
139
|
+
lastRow.push(createCharKey(randomNumbers[9], 9));
|
|
140
|
+
if (includeDone) lastRow.push({
|
|
141
|
+
id: "done",
|
|
142
|
+
type: "done",
|
|
143
|
+
label: "确定",
|
|
144
|
+
className: "key-done key-fn"
|
|
145
|
+
});
|
|
146
|
+
else lastRow.push({
|
|
147
|
+
id: "empty-2",
|
|
148
|
+
type: "char",
|
|
149
|
+
label: "",
|
|
150
|
+
value: "",
|
|
151
|
+
disabled: true,
|
|
152
|
+
className: "key-placeholder"
|
|
153
|
+
});
|
|
154
|
+
rows.push({
|
|
155
|
+
className: "numpad-row",
|
|
156
|
+
keys: lastRow
|
|
157
|
+
});
|
|
158
|
+
return {
|
|
159
|
+
type: "custom",
|
|
160
|
+
name: "随机PIN键盘",
|
|
161
|
+
supportShift: false,
|
|
162
|
+
rows,
|
|
163
|
+
data: {
|
|
164
|
+
isRandom: true,
|
|
165
|
+
randomType: "pin"
|
|
166
|
+
}
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
function createRandomLetterLayout(options) {
|
|
170
|
+
const { uppercase = true, rowDistribution = [
|
|
171
|
+
10,
|
|
172
|
+
9,
|
|
173
|
+
7
|
|
174
|
+
] } = options || {};
|
|
175
|
+
let randomLetters = getRandomLetters();
|
|
176
|
+
if (!uppercase) randomLetters = randomLetters.map((l) => l.toLowerCase());
|
|
177
|
+
const letterKeys = randomLetters.map((l, i) => createCharKey(l, i));
|
|
178
|
+
const rows = [];
|
|
179
|
+
let offset = 0;
|
|
180
|
+
for (const count of rowDistribution) {
|
|
181
|
+
rows.push({
|
|
182
|
+
className: "numpad-row",
|
|
183
|
+
keys: letterKeys.slice(offset, offset + count)
|
|
184
|
+
});
|
|
185
|
+
offset += count;
|
|
186
|
+
}
|
|
187
|
+
if (offset < letterKeys.length) rows.push({
|
|
188
|
+
className: "numpad-row",
|
|
189
|
+
keys: letterKeys.slice(offset)
|
|
190
|
+
});
|
|
191
|
+
rows.push({
|
|
192
|
+
className: "numpad-row",
|
|
193
|
+
keys: [
|
|
194
|
+
{
|
|
195
|
+
id: "clear",
|
|
196
|
+
type: "clear",
|
|
197
|
+
label: "清空",
|
|
198
|
+
className: "key-clear key-fn"
|
|
199
|
+
},
|
|
200
|
+
{
|
|
201
|
+
id: "backspace",
|
|
202
|
+
type: "backspace",
|
|
203
|
+
label: "⌫",
|
|
204
|
+
className: "key-backspace key-fn"
|
|
205
|
+
},
|
|
206
|
+
{
|
|
207
|
+
id: "done",
|
|
208
|
+
type: "done",
|
|
209
|
+
label: "确定",
|
|
210
|
+
className: "key-done key-fn"
|
|
211
|
+
}
|
|
212
|
+
]
|
|
213
|
+
});
|
|
214
|
+
return {
|
|
215
|
+
type: "custom",
|
|
216
|
+
name: "随机字母键盘",
|
|
217
|
+
supportShift: false,
|
|
218
|
+
rows,
|
|
219
|
+
data: {
|
|
220
|
+
isRandom: true,
|
|
221
|
+
randomType: "letter"
|
|
222
|
+
}
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
function createRandomMixedLayout(options) {
|
|
226
|
+
const { rowDistribution = [
|
|
227
|
+
10,
|
|
228
|
+
10,
|
|
229
|
+
9,
|
|
230
|
+
7
|
|
231
|
+
] } = options || {};
|
|
232
|
+
const charKeys = getRandomAlphanumeric().map((c, i) => createCharKey(c, i));
|
|
233
|
+
const rows = [];
|
|
234
|
+
let offset = 0;
|
|
235
|
+
for (const count of rowDistribution) {
|
|
236
|
+
if (offset >= charKeys.length) break;
|
|
237
|
+
rows.push({
|
|
238
|
+
className: "numpad-row",
|
|
239
|
+
keys: charKeys.slice(offset, offset + count)
|
|
240
|
+
});
|
|
241
|
+
offset += count;
|
|
242
|
+
}
|
|
243
|
+
if (offset < charKeys.length) rows.push({
|
|
244
|
+
className: "numpad-row",
|
|
245
|
+
keys: charKeys.slice(offset)
|
|
246
|
+
});
|
|
247
|
+
rows.push({
|
|
248
|
+
className: "numpad-row",
|
|
249
|
+
keys: [
|
|
250
|
+
{
|
|
251
|
+
id: "clear",
|
|
252
|
+
type: "clear",
|
|
253
|
+
label: "清空",
|
|
254
|
+
className: "key-clear key-fn"
|
|
255
|
+
},
|
|
256
|
+
{
|
|
257
|
+
id: "backspace",
|
|
258
|
+
type: "backspace",
|
|
259
|
+
label: "⌫",
|
|
260
|
+
className: "key-backspace key-fn"
|
|
261
|
+
},
|
|
262
|
+
{
|
|
263
|
+
id: "done",
|
|
264
|
+
type: "done",
|
|
265
|
+
label: "确定",
|
|
266
|
+
className: "key-done key-fn"
|
|
267
|
+
}
|
|
268
|
+
]
|
|
269
|
+
});
|
|
270
|
+
return {
|
|
271
|
+
type: "custom",
|
|
272
|
+
name: "随机混合键盘",
|
|
273
|
+
supportShift: false,
|
|
274
|
+
rows,
|
|
275
|
+
data: {
|
|
276
|
+
isRandom: true,
|
|
277
|
+
randomType: "mixed"
|
|
278
|
+
}
|
|
279
|
+
};
|
|
280
|
+
}
|
|
281
|
+
function refreshRandomLayout(layout) {
|
|
282
|
+
switch (layout.data?.randomType) {
|
|
283
|
+
case "number": return createRandomNumberLayout();
|
|
284
|
+
case "pin": return createRandomPinLayout();
|
|
285
|
+
case "letter": return createRandomLetterLayout();
|
|
286
|
+
case "mixed": return createRandomMixedLayout();
|
|
287
|
+
default: return layout;
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
//#endregion
|
|
291
|
+
exports.createRandomLetterLayout = createRandomLetterLayout;
|
|
292
|
+
exports.createRandomMixedLayout = createRandomMixedLayout;
|
|
293
|
+
exports.createRandomNumberLayout = createRandomNumberLayout;
|
|
294
|
+
exports.createRandomPinLayout = createRandomPinLayout;
|
|
295
|
+
exports.getRandomAlphanumeric = getRandomAlphanumeric;
|
|
296
|
+
exports.getRandomLetters = getRandomLetters;
|
|
297
|
+
exports.getRandomNumbers = getRandomNumbers;
|
|
298
|
+
exports.refreshRandomLayout = refreshRandomLayout;
|
|
299
|
+
exports.shuffleArray = shuffleArray;
|
|
300
|
+
/*! End of @composy/keyboard-core | Powered by @composy/builder */
|
|
301
|
+
//# sourceMappingURL=random.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"random.cjs","names":[],"sources":["../../src/utils/random.ts"],"sourcesContent":["/**\n * 随机工具函数\n * @module utils/random\n */\n\nimport type { KeyboardConfig, KeyboardRow, KeyDefinition } from '../types'\n\n/**\n * Fisher-Yates 洗牌算法\n * @param array - 要洗牌的数组\n * @returns 洗牌后的新数组\n */\nexport function shuffleArray<T>(array: T[]): T[] {\n const result = [...array]\n for (let i = result.length - 1; i > 0; i--) {\n const j = Math.floor(Math.random() * (i + 1))\n ;[result[i], result[j]] = [result[j], result[i]]\n }\n return result\n}\n\n/**\n * 生成随机数字数组 (0-9)\n */\nexport function getRandomNumbers(): string[] {\n return shuffleArray(['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'])\n}\n\n/**\n * 生成随机字母数组 (A-Z)\n */\nexport function getRandomLetters(): string[] {\n const letters = Array.from({ length: 26 }, (_, i) =>\n String.fromCharCode(65 + i),\n )\n return shuffleArray(letters)\n}\n\n/**\n * 生成随机数字+字母数组\n */\nexport function getRandomAlphanumeric(): string[] {\n const numbers = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']\n const letters = Array.from({ length: 26 }, (_, i) =>\n String.fromCharCode(65 + i),\n )\n return shuffleArray([...numbers, ...letters])\n}\n\n/**\n * 创建字符按键\n */\nfunction createCharKey(char: string, index: number): KeyDefinition {\n return {\n id: `random-${char}-${index}`,\n type: 'char',\n label: char,\n value: char,\n className: 'key-random',\n }\n}\n\n/**\n * 将字符数组分成行\n */\nfunction chunkArray<T>(array: T[], chunkSize: number): T[][] {\n const chunks: T[][] = []\n for (let i = 0; i < array.length; i += chunkSize) {\n chunks.push(array.slice(i, i + chunkSize))\n }\n return chunks\n}\n\n/**\n * 生成随机数字键盘布局\n * @param options - 配置选项\n */\nexport function createRandomNumberLayout(options?: {\n /** 每行按键数 */\n keysPerRow?: number\n /** 是否包含退格键 */\n includeBackspace?: boolean\n /** 是否包含完成键 */\n includeDone?: boolean\n /** 是否包含清空键 */\n includeClear?: boolean\n}): KeyboardConfig {\n const {\n keysPerRow = 3,\n includeBackspace = true,\n includeDone = true,\n includeClear = false,\n } = options || {}\n\n const randomNumbers = getRandomNumbers()\n const numberKeys = randomNumbers.map((n, i) => createCharKey(n, i))\n const chunks = chunkArray(numberKeys, keysPerRow)\n\n const rows: KeyboardRow[] = chunks.map((keys, index) => ({\n className: 'numpad-row',\n keys,\n }))\n\n // 添加功能键行\n const fnKeys: KeyDefinition[] = []\n\n if (includeClear) {\n fnKeys.push({\n id: 'clear',\n type: 'clear',\n label: '清空',\n className: 'key-clear key-fn',\n })\n }\n\n if (includeBackspace) {\n fnKeys.push({\n id: 'backspace',\n type: 'backspace',\n label: '⌫',\n className: 'key-backspace key-fn',\n })\n }\n\n if (includeDone) {\n fnKeys.push({\n id: 'done',\n type: 'done',\n label: '确定',\n className: 'key-done key-fn',\n })\n }\n\n if (fnKeys.length > 0) {\n rows.push({\n className: 'numpad-row',\n keys: fnKeys,\n })\n }\n\n return {\n type: 'custom',\n name: '随机数字键盘',\n supportShift: false,\n rows,\n data: {\n isRandom: true,\n randomType: 'number',\n },\n }\n}\n\n/**\n * 生成4x3随机数字键盘(密码输入常用)\n */\nexport function createRandomPinLayout(options?: {\n /** 是否包含退格键 */\n includeBackspace?: boolean\n /** 是否包含完成键 */\n includeDone?: boolean\n}): KeyboardConfig {\n const { includeBackspace = true, includeDone = true } = options || {}\n\n const randomNumbers = getRandomNumbers()\n\n // 前9个数字 (3x3)\n const rows: KeyboardRow[] = [\n {\n className: 'numpad-row',\n keys: randomNumbers.slice(0, 3).map((n, i) => createCharKey(n, i)),\n },\n {\n className: 'numpad-row',\n keys: randomNumbers.slice(3, 6).map((n, i) => createCharKey(n, i + 3)),\n },\n {\n className: 'numpad-row',\n keys: randomNumbers.slice(6, 9).map((n, i) => createCharKey(n, i + 6)),\n },\n ]\n\n // 最后一行:功能键 + 0 + 功能键\n const lastRow: KeyDefinition[] = []\n\n if (includeBackspace) {\n lastRow.push({\n id: 'backspace',\n type: 'backspace',\n label: '⌫',\n className: 'key-backspace key-fn',\n })\n } else {\n lastRow.push({\n id: 'empty-1',\n type: 'char',\n label: '',\n value: '',\n disabled: true,\n className: 'key-placeholder',\n })\n }\n\n lastRow.push(createCharKey(randomNumbers[9], 9))\n\n if (includeDone) {\n lastRow.push({\n id: 'done',\n type: 'done',\n label: '确定',\n className: 'key-done key-fn',\n })\n } else {\n lastRow.push({\n id: 'empty-2',\n type: 'char',\n label: '',\n value: '',\n disabled: true,\n className: 'key-placeholder',\n })\n }\n\n rows.push({\n className: 'numpad-row',\n keys: lastRow,\n })\n\n return {\n type: 'custom',\n name: '随机PIN键盘',\n supportShift: false,\n rows,\n data: {\n isRandom: true,\n randomType: 'pin',\n },\n }\n}\n\n/**\n * 生成随机字母键盘布局\n * 默认使用 QWERTY 风格行分布 (10/9/7),看起来像真实键盘\n */\nexport function createRandomLetterLayout(options?: {\n /** 是否大写 */\n uppercase?: boolean\n /** 行分布,默认 [10, 9, 7] 模拟 QWERTY 布局 */\n rowDistribution?: number[]\n}): KeyboardConfig {\n const { uppercase = true, rowDistribution = [10, 9, 7] } = options || {}\n\n let randomLetters = getRandomLetters()\n if (!uppercase) {\n randomLetters = randomLetters.map((l) => l.toLowerCase())\n }\n\n const letterKeys = randomLetters.map((l, i) => createCharKey(l, i))\n\n // 按行分布切割\n const rows: KeyboardRow[] = []\n let offset = 0\n for (const count of rowDistribution) {\n rows.push({\n className: 'numpad-row',\n keys: letterKeys.slice(offset, offset + count),\n })\n offset += count\n }\n // 剩余字母放最后一行\n if (offset < letterKeys.length) {\n rows.push({\n className: 'numpad-row',\n keys: letterKeys.slice(offset),\n })\n }\n\n // 功能键行\n rows.push({\n className: 'numpad-row',\n keys: [\n {\n id: 'clear',\n type: 'clear',\n label: '清空',\n className: 'key-clear key-fn',\n },\n {\n id: 'backspace',\n type: 'backspace',\n label: '⌫',\n className: 'key-backspace key-fn',\n },\n {\n id: 'done',\n type: 'done',\n label: '确定',\n className: 'key-done key-fn',\n },\n ],\n })\n\n return {\n type: 'custom',\n name: '随机字母键盘',\n supportShift: false,\n rows,\n data: {\n isRandom: true,\n randomType: 'letter',\n },\n }\n}\n\n/**\n * 生成混合随机键盘(数字+字母)\n * 默认使用 QWERTY 风格行分布 (10/10/9/7),看起来像真实键盘\n */\nexport function createRandomMixedLayout(options?: {\n /** 行分布,默认 [10, 10, 9, 7] */\n rowDistribution?: number[]\n}): KeyboardConfig {\n const { rowDistribution = [10, 10, 9, 7] } = options || {}\n\n const randomChars = getRandomAlphanumeric()\n const charKeys = randomChars.map((c, i) => createCharKey(c, i))\n\n // 按行分布切割\n const rows: KeyboardRow[] = []\n let offset = 0\n for (const count of rowDistribution) {\n if (offset >= charKeys.length) break\n rows.push({\n className: 'numpad-row',\n keys: charKeys.slice(offset, offset + count),\n })\n offset += count\n }\n // 剩余字符放最后一行\n if (offset < charKeys.length) {\n rows.push({\n className: 'numpad-row',\n keys: charKeys.slice(offset),\n })\n }\n\n // 功能键行\n rows.push({\n className: 'numpad-row',\n keys: [\n {\n id: 'clear',\n type: 'clear',\n label: '清空',\n className: 'key-clear key-fn',\n },\n {\n id: 'backspace',\n type: 'backspace',\n label: '⌫',\n className: 'key-backspace key-fn',\n },\n {\n id: 'done',\n type: 'done',\n label: '确定',\n className: 'key-done key-fn',\n },\n ],\n })\n\n return {\n type: 'custom',\n name: '随机混合键盘',\n supportShift: false,\n rows,\n data: {\n isRandom: true,\n randomType: 'mixed',\n },\n }\n}\n\n/**\n * 刷新随机键盘布局\n * @param layout - 现有布局\n * @returns 新的随机布局\n */\nexport function refreshRandomLayout(layout: KeyboardConfig): KeyboardConfig {\n const randomType = layout.data?.randomType as string | undefined\n\n switch (randomType) {\n case 'number':\n return createRandomNumberLayout()\n case 'pin':\n return createRandomPinLayout()\n case 'letter':\n return createRandomLetterLayout()\n case 'mixed':\n return createRandomMixedLayout()\n default:\n return layout\n }\n}\n"],"mappings":";;;;;;;;;;;A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ACA,MAAM;GACJ,UAAU;GACV,YAAY;EACd;CACF;AACF;AAMO,SAAS,wBAAwB,SAGrB;CACjB,MAAM,EAAE,kBAAkB;EAAC;EAAI;EAAI;EAAG;CAAC,MAAM,WAAW,CAAC;CAGzD,MAAM,WADc,sBACH,CAAA,CAAY,KAAK,GAAG,MAAM,cAAc,GAAG,CAAC,CAAC;CAG9D,MAAM,OAAsB,CAAC;CAC7B,IAAI,SAAS;CACb,KAAA,MAAW,SAAS,iBAAiB;EACnC,IAAI,UAAU,SAAS,QAAQ;EAC/B,KAAK,KAAK;GACR,WAAW;GACX,MAAM,SAAS,MAAM,QAAQ,SAAS,KAAK;EAC7C,CAAC;EACD,UAAU;CACZ;CAEA,IAAI,SAAS,SAAS,QACpB,KAAK,KAAK;EACR,WAAW;EACX,MAAM,SAAS,MAAM,MAAM;CAC7B,CAAC;CAIH,KAAK,KAAK;EACR,WAAW;EACX,MAAM;GACJ;IACE,IAAI;IACJ,MAAM;IACN,OAAO;IACP,WAAW;GACb;GACA;IACE,IAAI;IACJ,MAAM;IACN,OAAO;IACP,WAAW;GACb;GACA;IACE,IAAI;IACJ,MAAM;IACN,OAAO;IACP,WAAW;GACb;EACF;CACF,CAAC;CAED,OAAO;EACL,MAAM;EACN,MAAM;EACN,cAAc;EACd;EACA,MAAM;GACJ,UAAU;GACV,YAAY;EACd;CACF;AACF;AAOO,SAAS,oBAAoB,QAAwC;CAG1E,QAFmB,OAAO,MAAM,YAEhC;EACE,KAAK,UACH,OAAO,yBAAyB;EAClC,KAAK,OACH,OAAO,sBAAsB;EAC/B,KAAK,UACH,OAAO,yBAAyB;EAClC,KAAK,SACH,OAAO,wBAAwB;EACjC,SACE,OAAO;CACX;AACF"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 随机工具函数
|
|
3
|
+
* @module utils/random
|
|
4
|
+
*/
|
|
5
|
+
import type { KeyboardConfig } from '../types';
|
|
6
|
+
/**
|
|
7
|
+
* Fisher-Yates 洗牌算法
|
|
8
|
+
* @param array - 要洗牌的数组
|
|
9
|
+
* @returns 洗牌后的新数组
|
|
10
|
+
*/
|
|
11
|
+
export declare function shuffleArray<T>(array: T[]): T[];
|
|
12
|
+
/**
|
|
13
|
+
* 生成随机数字数组 (0-9)
|
|
14
|
+
*/
|
|
15
|
+
export declare function getRandomNumbers(): string[];
|
|
16
|
+
/**
|
|
17
|
+
* 生成随机字母数组 (A-Z)
|
|
18
|
+
*/
|
|
19
|
+
export declare function getRandomLetters(): string[];
|
|
20
|
+
/**
|
|
21
|
+
* 生成随机数字+字母数组
|
|
22
|
+
*/
|
|
23
|
+
export declare function getRandomAlphanumeric(): string[];
|
|
24
|
+
/**
|
|
25
|
+
* 生成随机数字键盘布局
|
|
26
|
+
* @param options - 配置选项
|
|
27
|
+
*/
|
|
28
|
+
export declare function createRandomNumberLayout(options?: {
|
|
29
|
+
/** 每行按键数 */
|
|
30
|
+
keysPerRow?: number;
|
|
31
|
+
/** 是否包含退格键 */
|
|
32
|
+
includeBackspace?: boolean;
|
|
33
|
+
/** 是否包含完成键 */
|
|
34
|
+
includeDone?: boolean;
|
|
35
|
+
/** 是否包含清空键 */
|
|
36
|
+
includeClear?: boolean;
|
|
37
|
+
}): KeyboardConfig;
|
|
38
|
+
/**
|
|
39
|
+
* 生成4x3随机数字键盘(密码输入常用)
|
|
40
|
+
*/
|
|
41
|
+
export declare function createRandomPinLayout(options?: {
|
|
42
|
+
/** 是否包含退格键 */
|
|
43
|
+
includeBackspace?: boolean;
|
|
44
|
+
/** 是否包含完成键 */
|
|
45
|
+
includeDone?: boolean;
|
|
46
|
+
}): KeyboardConfig;
|
|
47
|
+
/**
|
|
48
|
+
* 生成随机字母键盘布局
|
|
49
|
+
* 默认使用 QWERTY 风格行分布 (10/9/7),看起来像真实键盘
|
|
50
|
+
*/
|
|
51
|
+
export declare function createRandomLetterLayout(options?: {
|
|
52
|
+
/** 是否大写 */
|
|
53
|
+
uppercase?: boolean;
|
|
54
|
+
/** 行分布,默认 [10, 9, 7] 模拟 QWERTY 布局 */
|
|
55
|
+
rowDistribution?: number[];
|
|
56
|
+
}): KeyboardConfig;
|
|
57
|
+
/**
|
|
58
|
+
* 生成混合随机键盘(数字+字母)
|
|
59
|
+
* 默认使用 QWERTY 风格行分布 (10/10/9/7),看起来像真实键盘
|
|
60
|
+
*/
|
|
61
|
+
export declare function createRandomMixedLayout(options?: {
|
|
62
|
+
/** 行分布,默认 [10, 10, 9, 7] */
|
|
63
|
+
rowDistribution?: number[];
|
|
64
|
+
}): KeyboardConfig;
|
|
65
|
+
/**
|
|
66
|
+
* 刷新随机键盘布局
|
|
67
|
+
* @param layout - 现有布局
|
|
68
|
+
* @returns 新的随机布局
|
|
69
|
+
*/
|
|
70
|
+
export declare function refreshRandomLayout(layout: KeyboardConfig): KeyboardConfig;
|
|
71
|
+
//# sourceMappingURL=random.d.ts.map
|
package/package.json
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@composy/keyboard-core",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "LDesign 虚拟键盘 - 框架无关的核心模块",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"keyboard",
|
|
7
|
+
"virtual-keyboard",
|
|
8
|
+
"input",
|
|
9
|
+
"license-plate",
|
|
10
|
+
"ldesign",
|
|
11
|
+
"typescript"
|
|
12
|
+
],
|
|
13
|
+
"author": "LDesign Team",
|
|
14
|
+
"license": "MIT",
|
|
15
|
+
"type": "module",
|
|
16
|
+
"sideEffects": false,
|
|
17
|
+
"exports": {
|
|
18
|
+
".": {
|
|
19
|
+
"types": "./es/index.d.ts",
|
|
20
|
+
"import": "./es/index.js",
|
|
21
|
+
"require": "./lib/index.cjs",
|
|
22
|
+
"default": "./es/index.js"
|
|
23
|
+
},
|
|
24
|
+
"./layouts": {
|
|
25
|
+
"types": "./es/layouts/index.d.ts",
|
|
26
|
+
"import": "./es/layouts/index.js",
|
|
27
|
+
"require": "./lib/layouts/index.cjs",
|
|
28
|
+
"default": "./es/layouts/index.js"
|
|
29
|
+
},
|
|
30
|
+
"./layouts/*": {
|
|
31
|
+
"types": "./es/layouts/*.d.ts",
|
|
32
|
+
"import": "./es/layouts/*.js",
|
|
33
|
+
"require": "./lib/layouts/*.cjs",
|
|
34
|
+
"default": "./es/layouts/*.js"
|
|
35
|
+
},
|
|
36
|
+
"./managers": {
|
|
37
|
+
"types": "./es/managers/index.d.ts",
|
|
38
|
+
"import": "./es/managers/index.js",
|
|
39
|
+
"require": "./lib/managers/index.cjs",
|
|
40
|
+
"default": "./es/managers/index.js"
|
|
41
|
+
},
|
|
42
|
+
"./managers/*": {
|
|
43
|
+
"types": "./es/managers/*.d.ts",
|
|
44
|
+
"import": "./es/managers/*.js",
|
|
45
|
+
"require": "./lib/managers/*.cjs",
|
|
46
|
+
"default": "./es/managers/*.js"
|
|
47
|
+
},
|
|
48
|
+
"./themes": {
|
|
49
|
+
"types": "./es/themes/index.d.ts",
|
|
50
|
+
"import": "./es/themes/index.js",
|
|
51
|
+
"require": "./lib/themes/index.cjs",
|
|
52
|
+
"default": "./es/themes/index.js"
|
|
53
|
+
},
|
|
54
|
+
"./themes/*": {
|
|
55
|
+
"types": "./es/themes/*.d.ts",
|
|
56
|
+
"import": "./es/themes/*.js",
|
|
57
|
+
"require": "./lib/themes/*.cjs",
|
|
58
|
+
"default": "./es/themes/*.js"
|
|
59
|
+
},
|
|
60
|
+
"./types": {
|
|
61
|
+
"types": "./es/types/index.d.ts",
|
|
62
|
+
"import": "./es/types/index.js",
|
|
63
|
+
"require": "./lib/types/index.cjs",
|
|
64
|
+
"default": "./es/types/index.js"
|
|
65
|
+
},
|
|
66
|
+
"./types/*": {
|
|
67
|
+
"types": "./es/types/*.d.ts",
|
|
68
|
+
"import": "./es/types/*.js",
|
|
69
|
+
"require": "./lib/types/*.cjs",
|
|
70
|
+
"default": "./es/types/*.js"
|
|
71
|
+
},
|
|
72
|
+
"./utils": {
|
|
73
|
+
"types": "./es/utils/index.d.ts",
|
|
74
|
+
"import": "./es/utils/index.js",
|
|
75
|
+
"require": "./lib/utils/index.cjs",
|
|
76
|
+
"default": "./es/utils/index.js"
|
|
77
|
+
},
|
|
78
|
+
"./utils/*": {
|
|
79
|
+
"types": "./es/utils/*.d.ts",
|
|
80
|
+
"import": "./es/utils/*.js",
|
|
81
|
+
"require": "./lib/utils/*.cjs",
|
|
82
|
+
"default": "./es/utils/*.js"
|
|
83
|
+
},
|
|
84
|
+
"./package.json": "./package.json"
|
|
85
|
+
},
|
|
86
|
+
"main": "./lib/index.cjs",
|
|
87
|
+
"module": "./es/index.js",
|
|
88
|
+
"types": "./es/index.d.ts",
|
|
89
|
+
"unpkg": "./dist/index.min.js",
|
|
90
|
+
"jsdelivr": "./dist/index.min.js",
|
|
91
|
+
"files": [
|
|
92
|
+
"es",
|
|
93
|
+
"lib",
|
|
94
|
+
"README.md",
|
|
95
|
+
"esm",
|
|
96
|
+
"dist"
|
|
97
|
+
],
|
|
98
|
+
"scripts": {
|
|
99
|
+
"build": "ldesign-builder build",
|
|
100
|
+
"lint": "eslint . --cache",
|
|
101
|
+
"lint:check": "eslint . --cache --max-warnings 0",
|
|
102
|
+
"lint:fix": "eslint . --cache --fix",
|
|
103
|
+
"type-check": "tsc --noEmit",
|
|
104
|
+
"test": "ltesting run:unit",
|
|
105
|
+
"test:run": "ltesting run:unit",
|
|
106
|
+
"test:watch": "ltesting run:unit --watch",
|
|
107
|
+
"test:coverage": "ltesting run:unit --coverage",
|
|
108
|
+
"test:changed": "ltesting run:unit --changed",
|
|
109
|
+
"test:failed": "ltesting run:unit --failed",
|
|
110
|
+
"test:ui": "ltesting dashboard"
|
|
111
|
+
},
|
|
112
|
+
"devDependencies": {
|
|
113
|
+
"@antfu/eslint-config": "9.1.0",
|
|
114
|
+
"@composy/builder": "^0.0.1",
|
|
115
|
+
"@composy/testing": "^0.0.1",
|
|
116
|
+
"eslint": "10.7.0",
|
|
117
|
+
"typescript": "5.9.3"
|
|
118
|
+
},
|
|
119
|
+
"typings": "./es/index.d.ts",
|
|
120
|
+
"browser": "./dist/index.js"
|
|
121
|
+
}
|