@hfd-sdk/keyboard-kit 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -0
- package/dist/ai-lighting/engine.d.ts +9 -0
- package/dist/ai-lighting/index.d.ts +6 -0
- package/dist/ai-lighting/index.es.js +946 -0
- package/dist/ai-lighting/params.d.ts +5 -0
- package/dist/ai-lighting/preset-store.d.ts +17 -0
- package/dist/ai-lighting/validate.d.ts +3 -0
- package/dist/index.d.ts +2 -0
- package/dist/keyboard-kit.es.js +10 -0
- package/dist/runtime/index.d.ts +3 -0
- package/dist/runtime-core.es.js +5484 -0
- package/dist/runtime.es.js +44 -0
- package/dist/shared/composables/useKeySampler.d.ts +8 -0
- package/dist/shared/hardware/assert-hfd-device.d.ts +3 -0
- package/dist/shared/hardware/build-music-data.d.ts +4 -0
- package/dist/shared/serialize.d.ts +4 -0
- package/dist/shared/types.d.ts +123 -0
- package/package.json +58 -0
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { k as p, c as _, x as y, l as d, o as m, a as w, m as b, r as k, s as v, p as x, t as z, w as h } from "./runtime-core.es.js";
|
|
2
|
+
function s(e) {
|
|
3
|
+
const n = {};
|
|
4
|
+
for (const [o, t] of Object.entries(e))
|
|
5
|
+
n[o] = typeof t == "function" ? { __fn__: !0, body: t.toString() } : t;
|
|
6
|
+
return n;
|
|
7
|
+
}
|
|
8
|
+
function a(e) {
|
|
9
|
+
const n = {};
|
|
10
|
+
for (const [o, t] of Object.entries(e)) {
|
|
11
|
+
const r = t;
|
|
12
|
+
n[o] = r && typeof r == "object" && r.__fn__ ? c(r.body) : t;
|
|
13
|
+
}
|
|
14
|
+
return n;
|
|
15
|
+
}
|
|
16
|
+
function c(e) {
|
|
17
|
+
try {
|
|
18
|
+
return new Function(`return (${e})`)();
|
|
19
|
+
} catch {
|
|
20
|
+
return new Function(`return function ${e}`)();
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
function u(e) {
|
|
24
|
+
return s(e);
|
|
25
|
+
}
|
|
26
|
+
function i(e) {
|
|
27
|
+
return a(e);
|
|
28
|
+
}
|
|
29
|
+
export {
|
|
30
|
+
p as clearInterval,
|
|
31
|
+
_ as computed,
|
|
32
|
+
y as defineCustomElement,
|
|
33
|
+
i as deserializePreset,
|
|
34
|
+
d as nextTick,
|
|
35
|
+
m as onBeforeUnmount,
|
|
36
|
+
w as onMounted,
|
|
37
|
+
b as onScopeDispose,
|
|
38
|
+
k as ref,
|
|
39
|
+
u as serializePreset,
|
|
40
|
+
v as setInterval,
|
|
41
|
+
x as shallowRef,
|
|
42
|
+
z as toValue,
|
|
43
|
+
h as watch
|
|
44
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { KeyboardSyncConfig, KeyElementRef, RgbColor } from '../types';
|
|
2
|
+
export declare function discoverKeyElements(root: HTMLElement): KeyElementRef[];
|
|
3
|
+
export interface SampleKeysOptions {
|
|
4
|
+
canvas: HTMLCanvasElement;
|
|
5
|
+
keyboardConfig: KeyboardSyncConfig;
|
|
6
|
+
getKeyElements: () => KeyElementRef[];
|
|
7
|
+
}
|
|
8
|
+
export declare function sampleKeysFromCanvas(options: SampleKeysOptions): RgbColor[][] | null;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { KeyboardSyncConfig, RgbColor } from '../types';
|
|
2
|
+
export declare function getMusicGridCol(keyboardConfig: KeyboardSyncConfig, rowIndex: number, colIndex: number): number;
|
|
3
|
+
export declare function createKeysRgbGrid(keyboardConfig: KeyboardSyncConfig): RgbColor[][];
|
|
4
|
+
export declare function buildMusicData(keysRgb: RgbColor[][], keyboardConfig: KeyboardSyncConfig): number[];
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare function serialize(data: Record<string, unknown>): Record<string, unknown>;
|
|
2
|
+
export declare function deserialize(data: Record<string, unknown>): Record<string, unknown>;
|
|
3
|
+
export declare function serializePreset(preset: import('./types').AiLightingPreset): Record<string, unknown>;
|
|
4
|
+
export declare function deserializePreset(raw: Record<string, unknown>): import('./types').AiLightingPreset;
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
export interface RgbColor {
|
|
2
|
+
r: number;
|
|
3
|
+
g: number;
|
|
4
|
+
b: number;
|
|
5
|
+
}
|
|
6
|
+
export interface KeyOffset {
|
|
7
|
+
value: number;
|
|
8
|
+
offsetX: number;
|
|
9
|
+
}
|
|
10
|
+
export interface KeyboardKeyMeta {
|
|
11
|
+
value: number;
|
|
12
|
+
keyCode: number;
|
|
13
|
+
name?: string;
|
|
14
|
+
}
|
|
15
|
+
export interface KeyboardSyncConfig {
|
|
16
|
+
keys: KeyboardKeyMeta[][];
|
|
17
|
+
musicConfig?: {
|
|
18
|
+
keyOffset?: KeyOffset[];
|
|
19
|
+
maxColOffset?: number;
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
export interface KeyboardLayoutState {
|
|
23
|
+
x: number;
|
|
24
|
+
y: number;
|
|
25
|
+
width: number;
|
|
26
|
+
height: number;
|
|
27
|
+
rotation: number;
|
|
28
|
+
}
|
|
29
|
+
export interface KeyElementRef {
|
|
30
|
+
row: number;
|
|
31
|
+
col: number;
|
|
32
|
+
el: HTMLElement;
|
|
33
|
+
}
|
|
34
|
+
export type AiLightingPresetParamValue = number | string | boolean;
|
|
35
|
+
export interface AiLightingPresetParamOption {
|
|
36
|
+
label: string;
|
|
37
|
+
value: number | string;
|
|
38
|
+
}
|
|
39
|
+
export interface AiLightingPresetParam {
|
|
40
|
+
key: string;
|
|
41
|
+
name?: string;
|
|
42
|
+
type?: 'slider' | 'color' | 'select' | 'switch';
|
|
43
|
+
min?: number;
|
|
44
|
+
max?: number;
|
|
45
|
+
step?: number;
|
|
46
|
+
options?: AiLightingPresetParamOption[];
|
|
47
|
+
default?: AiLightingPresetParamValue;
|
|
48
|
+
}
|
|
49
|
+
export interface AiLightingPresetContext {
|
|
50
|
+
canvas2d: CanvasRenderingContext2D;
|
|
51
|
+
width: number;
|
|
52
|
+
height: number;
|
|
53
|
+
}
|
|
54
|
+
export interface AiLightingPreset {
|
|
55
|
+
id: string;
|
|
56
|
+
name: string;
|
|
57
|
+
icon?: string;
|
|
58
|
+
description?: string;
|
|
59
|
+
params?: AiLightingPresetParam[];
|
|
60
|
+
initialize: (ctx: AiLightingPresetContext, params: Record<string, AiLightingPresetParamValue>) => unknown;
|
|
61
|
+
render: (ctx: AiLightingPresetContext, state: unknown, frame: {
|
|
62
|
+
deltaTime: number;
|
|
63
|
+
elapsedTime: number;
|
|
64
|
+
}, params: Record<string, AiLightingPresetParamValue>) => void;
|
|
65
|
+
shutdown: (ctx: AiLightingPresetContext, state: unknown) => void;
|
|
66
|
+
}
|
|
67
|
+
/** `@hfd-sdk/keyboard-sdk` 的 HFDDevice 实例(init 必填,运行时 instanceof 校验) */
|
|
68
|
+
export interface HFDSDKDevice {
|
|
69
|
+
setMusicData(musicData: number[], amplitude?: number, isUSBDevice?: boolean, lightingVersion?: number): Promise<boolean>;
|
|
70
|
+
}
|
|
71
|
+
export interface ParamChangePayload {
|
|
72
|
+
key: string;
|
|
73
|
+
value: AiLightingPresetParamValue;
|
|
74
|
+
params: Record<string, AiLightingPresetParamValue>;
|
|
75
|
+
}
|
|
76
|
+
export interface ImportPresetPayload {
|
|
77
|
+
code: number;
|
|
78
|
+
message: string;
|
|
79
|
+
}
|
|
80
|
+
export interface AiLightingInitOptions {
|
|
81
|
+
presets?: AiLightingPreset[];
|
|
82
|
+
importedPresets?: AiLightingPreset[];
|
|
83
|
+
selectedPresetId?: string;
|
|
84
|
+
defaultParams?: Partial<Record<string, AiLightingPresetParamValue>>;
|
|
85
|
+
keyboardConfig: KeyboardSyncConfig;
|
|
86
|
+
device: HFDSDKDevice;
|
|
87
|
+
isUSBDevice?: boolean;
|
|
88
|
+
lightingVersion?: number;
|
|
89
|
+
syncIntervalMs?: number;
|
|
90
|
+
canvasWidth?: number;
|
|
91
|
+
canvasHeight?: number;
|
|
92
|
+
getKeyElements?: () => KeyElementRef[];
|
|
93
|
+
initialLayout?: KeyboardLayoutState;
|
|
94
|
+
}
|
|
95
|
+
/** 与 Vue Ref 结构兼容,供素材库 UI 读取列表/选中态 */
|
|
96
|
+
export interface KitRef<T> {
|
|
97
|
+
value: T;
|
|
98
|
+
}
|
|
99
|
+
/** 只读预设状态(`getPresetState()`) */
|
|
100
|
+
export interface AiLightingPresetState {
|
|
101
|
+
presetList: KitRef<AiLightingPreset[]>;
|
|
102
|
+
selectedPresetId: KitRef<string>;
|
|
103
|
+
selectedPreset(): AiLightingPreset | null;
|
|
104
|
+
isInitialPreset(id: string): boolean;
|
|
105
|
+
}
|
|
106
|
+
/** `<hfd-ai-lighting>` 实例 API */
|
|
107
|
+
export interface HfdAiLightingElementInstance extends HTMLElement {
|
|
108
|
+
init(options: AiLightingInitOptions): Promise<void>;
|
|
109
|
+
selectPreset(id: string): void;
|
|
110
|
+
deletePreset(id: string): Promise<void>;
|
|
111
|
+
importPreset(code: string): Promise<AiLightingPreset | null>;
|
|
112
|
+
setParam(key: string, value: AiLightingPresetParamValue): void;
|
|
113
|
+
getParamValues(): Record<string, AiLightingPresetParamValue>;
|
|
114
|
+
getPresetState(): AiLightingPresetState;
|
|
115
|
+
resetKeyboardLayout(): Promise<void>;
|
|
116
|
+
getKeyElements(): KeyElementRef[];
|
|
117
|
+
}
|
|
118
|
+
declare global {
|
|
119
|
+
interface HTMLElementTagNameMap {
|
|
120
|
+
'hfd-ai-lighting': HfdAiLightingElementInstance;
|
|
121
|
+
'hfd-ai-lighting-keyboard-overlay': HTMLElement;
|
|
122
|
+
}
|
|
123
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@hfd-sdk/keyboard-kit",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "HFD keyboard kit",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"files": [
|
|
7
|
+
"dist"
|
|
8
|
+
],
|
|
9
|
+
"main": "./dist/keyboard-kit.es.js",
|
|
10
|
+
"module": "./dist/keyboard-kit.es.js",
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
15
|
+
"import": "./dist/keyboard-kit.es.js"
|
|
16
|
+
},
|
|
17
|
+
"./ai-lighting": {
|
|
18
|
+
"types": "./dist/ai-lighting/index.d.ts",
|
|
19
|
+
"import": "./dist/ai-lighting/index.es.js"
|
|
20
|
+
},
|
|
21
|
+
"./runtime": {
|
|
22
|
+
"types": "./dist/runtime/index.d.ts",
|
|
23
|
+
"import": "./dist/runtime.es.js"
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
"scripts": {
|
|
27
|
+
"dev": "vite",
|
|
28
|
+
"build": "vite build && node scripts/clean-dts.js",
|
|
29
|
+
"preview": "vite preview",
|
|
30
|
+
"prepublishOnly": "npm run build"
|
|
31
|
+
},
|
|
32
|
+
"keywords": [
|
|
33
|
+
"hfd-sdk",
|
|
34
|
+
"keyboard-kit"
|
|
35
|
+
],
|
|
36
|
+
"author": "htw",
|
|
37
|
+
"license": "ISC",
|
|
38
|
+
"peerDependencies": {
|
|
39
|
+
"@hfd-sdk/keyboard-sdk": "^2.0.2"
|
|
40
|
+
},
|
|
41
|
+
"dependencies": {
|
|
42
|
+
"worker-timers": "^8.0.23"
|
|
43
|
+
},
|
|
44
|
+
"devDependencies": {
|
|
45
|
+
"@hfd-sdk/keyboard-sdk": "^2.0.2",
|
|
46
|
+
"@iconify/json": "^2.2.510",
|
|
47
|
+
"@iconify/utils": "^3.1.4",
|
|
48
|
+
"@types/node": "^22.19.17",
|
|
49
|
+
"@unocss/preset-rem-to-px": "^66.6.8",
|
|
50
|
+
"@vitejs/plugin-vue": "^5.2.4",
|
|
51
|
+
"typescript": "~5.8.3",
|
|
52
|
+
"unocss": "^66.6.8",
|
|
53
|
+
"vite": "^6.4.2",
|
|
54
|
+
"vite-plugin-dts": "^4.5.4",
|
|
55
|
+
"vue": "^3.5.33",
|
|
56
|
+
"vue-tsc": "^2.2.12"
|
|
57
|
+
}
|
|
58
|
+
}
|