@overmvp/kumi 0.1.0 → 0.3.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 +59 -6
- package/builder/css-v1.mjs +54 -1
- package/builder/css-v1.test.mjs +40 -0
- package/builder/link-addon-package.mjs +47 -6
- package/builder/module-declarations.test.mjs +9 -18
- package/builder/native-kernels.mjs +1 -1
- package/builder/src/compiler.rs +180 -8
- package/builder/src/main.rs +19 -5
- package/builder/src/native_ir.rs +1 -1
- package/builder/src/native_signal.rs +46 -10
- package/builder/src/numbers.lua +14 -0
- package/builder/src/project-front.mjs +385 -34
- package/builder/src/routes.rs +11 -14
- package/builder/src/setup-store.lua +18 -0
- package/builder/src/signal-kernel.fingerprint +1 -1
- package/builder/src/ts-lower.mjs +2 -2
- package/builder/src/wow-reads.lua +22 -0
- package/builder/style-modules.mjs +93 -0
- package/config.ts +56 -14
- package/eslint.mjs +74 -0
- package/form/index.ts +15 -11
- package/package.json +11 -7
- package/router/index.ts +9 -2
- package/router/navigation.ts +22 -0
- package/router/router-view.ts +134 -0
- package/scripts/addon-build.mjs +364 -0
- package/scripts/addon-project.mjs +78 -0
- package/scripts/kumi-cli.mjs +52 -17
- package/scripts/link-addons.mjs +12 -2
- package/src/bindings.ts +2 -2
- package/src/css-tokens.ts +16 -11
- package/src/css-v1.ts +10 -0
- package/src/elements.ts +26 -0
- package/src/frame-scheduler.ts +3 -1
- package/src/index.ts +1 -0
- package/src/jsx-runtime.ts +8 -1
- package/src/keyed-list.ts +8 -5
- package/src/module-ui.ts +147 -0
- package/src/module.ts +42 -8
- package/src/owned-collections.ts +8 -0
- package/src/providers.ts +7 -1
- package/src/reactive-scope.ts +3 -3
- package/src/reactivity.ts +28 -7
- package/src/result.ts +6 -0
- package/src/signal-kernel.ts +35 -2
- package/state/index.ts +6 -0
- package/state/setup-store-persistence.ts +206 -0
- package/state/setup-store-view.ts +10 -0
- package/state/setup-store.ts +342 -0
- package/state/store.ts +2 -0
- package/templates/addon/.agents/skills/kumi-build-debug/SKILL.md +36 -0
- package/templates/addon/.agents/skills/kumi-feature/SKILL.md +50 -0
- package/templates/addon/.agents/skills/kumi-plugin/SKILL.md +36 -0
- package/templates/addon/.agents/skills/kumi-store/SKILL.md +47 -0
- package/templates/addon/.agents/skills/kumi-ui/SKILL.md +73 -0
- package/templates/addon/.agents/skills/kumi-wow-api/SKILL.md +30 -0
- package/templates/addon/.claude/skills/kumi-build-debug/SKILL.md +36 -0
- package/templates/addon/.claude/skills/kumi-feature/SKILL.md +50 -0
- package/templates/addon/.claude/skills/kumi-plugin/SKILL.md +36 -0
- package/templates/addon/.claude/skills/kumi-store/SKILL.md +47 -0
- package/templates/addon/.claude/skills/kumi-ui/SKILL.md +73 -0
- package/templates/addon/.claude/skills/kumi-wow-api/SKILL.md +30 -0
- package/templates/addon/AGENTS.md +34 -0
- package/templates/addon/Assets/Art/Corner10.tga +0 -0
- package/templates/addon/Assets/Art/Corner11.tga +0 -0
- package/templates/addon/Assets/Art/Corner12.tga +0 -0
- package/templates/addon/Assets/Art/Corner13.tga +0 -0
- package/templates/addon/Assets/Art/Corner14.tga +0 -0
- package/templates/addon/Assets/Art/Corner15.tga +0 -0
- package/templates/addon/Assets/Art/Corner16.tga +0 -0
- package/templates/addon/Assets/Art/Corner2.tga +0 -0
- package/templates/addon/Assets/Art/Corner3.tga +0 -0
- package/templates/addon/Assets/Art/Corner4.tga +0 -0
- package/templates/addon/Assets/Art/Corner5.tga +0 -0
- package/templates/addon/Assets/Art/Corner6.tga +0 -0
- package/templates/addon/Assets/Art/Corner7.tga +0 -0
- package/templates/addon/Assets/Art/Corner8.tga +0 -0
- package/templates/addon/Assets/Art/Corner9.tga +0 -0
- package/templates/addon/Assets/Art/Dot.tga +0 -0
- package/templates/addon/Assets/Art/Gear.tga +0 -0
- package/templates/addon/Assets/Art/Grip.tga +0 -0
- package/templates/addon/Assets/Art/Outline10.tga +0 -0
- package/templates/addon/Assets/Art/Outline12.tga +0 -0
- package/templates/addon/Assets/Art/Outline13.tga +0 -0
- package/templates/addon/Assets/Art/Outline14.tga +0 -0
- package/templates/addon/Assets/Art/Outline15.tga +0 -0
- package/templates/addon/Assets/Art/Outline2.tga +0 -0
- package/templates/addon/Assets/Art/Outline3.tga +0 -0
- package/templates/addon/Assets/Art/Outline5.tga +0 -0
- package/templates/addon/Assets/Art/Outline7.tga +0 -0
- package/templates/addon/Assets/Art/Outline9.tga +0 -0
- package/templates/addon/Assets/Art/Round11.tga +0 -0
- package/templates/addon/Assets/Art/Round11Border.tga +0 -0
- package/templates/addon/Assets/Art/Round4.tga +0 -0
- package/templates/addon/Assets/Art/Round4Border.tga +0 -0
- package/templates/addon/Assets/Art/Round6.tga +0 -0
- package/templates/addon/Assets/Art/Round6Border.tga +0 -0
- package/templates/addon/Assets/Art/Round8.tga +0 -0
- package/templates/addon/Assets/Art/Round8Border.tga +0 -0
- package/templates/addon/Assets/Art/Search.tga +0 -0
- package/templates/addon/CLAUDE.md +1 -0
- package/templates/addon/README.md +42 -7
- package/templates/addon/eslint.config.mjs +3 -9
- package/templates/addon/gitignore +1 -0
- package/templates/addon/kumi.config.ts +17 -0
- package/templates/addon/package.json +4 -5
- package/templates/addon/src/app/app.module.ts +18 -0
- package/templates/addon/src/app/commands.store.ts +11 -0
- package/templates/addon/src/app/layout/AppWindow.module.scss +92 -0
- package/templates/addon/src/app/layout/AppWindow.tsx +32 -0
- package/templates/addon/src/app/main.ts +5 -0
- package/templates/addon/src/app/routes/(window)/home/page.tsx +8 -0
- package/templates/addon/src/app/routes/(window)/plugins/page.tsx +38 -0
- package/templates/addon/src/app/routes/(window)/settings/page.tsx +8 -0
- package/templates/addon/src/app/theme.ts +6 -0
- package/templates/addon/src/modules/greeting/api/player.api.ts +29 -0
- package/templates/addon/src/modules/greeting/greeting.module.ts +18 -0
- package/templates/addon/src/modules/greeting/model/greeting.store.ts +81 -0
- package/templates/addon/src/modules/greeting/services/greeting.service.ts +38 -0
- package/templates/addon/src/modules/greeting/ui/Greeting.module.scss +105 -0
- package/templates/addon/src/modules/greeting/ui/GreetingCard.tsx +29 -0
- package/templates/addon/src/modules/greeting/widgets/GreetingHud.tsx +54 -0
- package/templates/addon/src/modules/greeting/widgets/GreetingOverview.tsx +18 -0
- package/templates/addon/src/modules/greeting/widgets/GreetingSettings.tsx +56 -0
- package/templates/addon/src/modules/playtime/api/clock.api.ts +6 -0
- package/templates/addon/src/modules/playtime/model/playtime.store.ts +19 -0
- package/templates/addon/src/modules/playtime/playtime.module.ts +18 -0
- package/templates/addon/src/modules/playtime/services/playtime.service.ts +18 -0
- package/templates/addon/src/modules/playtime/ui/Playtime.module.scss +25 -0
- package/templates/addon/src/modules/playtime/ui/PlaytimeBadge.tsx +10 -0
- package/templates/addon/src/modules/playtime/widgets/PlaytimePage.tsx +16 -0
- package/templates/addon/src/shared/api/native-art.ts +28 -0
- package/templates/addon/src/shared/assets/close.png +0 -0
- package/templates/addon/src/shared/lib/format.ts +20 -0
- package/templates/addon/src/shared/styles/_tokens.scss +12 -0
- package/templates/addon/src/shared/ui/Button.tsx +29 -0
- package/templates/addon/src/shared/ui/Choice.tsx +34 -0
- package/templates/addon/src/shared/ui/Controls.module.scss +93 -0
- package/templates/addon/src/shared/ui/Glyph.tsx +18 -0
- package/templates/addon/src/shared/ui/Slider.tsx +25 -0
- package/templates/addon/src/shared/ui/Toggle.tsx +29 -0
- package/templates/addon/src/shared/ui/focus-ref.ts +7 -0
- package/templates/addon/src/shared/ui/range-skin.tsx +15 -0
- package/templates/addon/tsconfig.json +49 -10
- package/wow/action-bar-layout.ts +108 -0
- package/wow/action-button.ts +219 -0
- package/wow/action-catalog.ts +98 -0
- package/wow/addon-manifest.ts +36 -0
- package/wow/app-ui.ts +221 -0
- package/wow/cooldown-timing.ts +24 -0
- package/wow/css-box.ts +40 -6
- package/wow/css-surfaces.ts +229 -24
- package/wow/cursor.ts +45 -0
- package/wow/frame-access.ts +23 -1
- package/wow/frame-timing.ts +13 -0
- package/wow/hooks.ts +133 -0
- package/wow/index.ts +18 -4
- package/wow/layout-view.ts +26 -14
- package/wow/locale-font.ts +15 -0
- package/wow/native.ts +18 -0
- package/wow/panel-host.ts +97 -0
- package/wow/pixel.ts +35 -0
- package/wow/plugins.ts +246 -0
- package/wow/protect.ts +27 -3
- package/wow/protected-view.ts +103 -0
- package/wow/range-art.ts +7 -0
- package/wow/readable-api.ts +120 -0
- package/wow/rounded-texture.ts +33 -6
- package/wow/saved-variables.ts +67 -18
- package/wow/spell-cooldown.ts +36 -0
- package/wow/start-addon.ts +31 -8
- package/wow/view.ts +201 -83
- package/templates/addon/__ADDON_NAME__.toc +0 -4
- package/templates/addon/scripts/build.mjs +0 -25
- package/templates/addon/src/app/main.tsx +0 -13
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/** Format seconds as 1:05 or 1:02:05. */
|
|
2
|
+
export function formatDuration(seconds: number): string {
|
|
3
|
+
const total = Math.max(0, Math.floor(seconds));
|
|
4
|
+
const hours = Math.floor(total / 3600);
|
|
5
|
+
const minutes = Math.floor((total % 3600) / 60);
|
|
6
|
+
const rest = total % 60;
|
|
7
|
+
const pad = (value: number) => value < 10 ? "0" + String(value) : String(value);
|
|
8
|
+
return hours > 0 ? String(hours) + ":" + pad(minutes) + ":" + pad(rest) : String(minutes) + ":" + pad(rest);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/** Format copper as 12g 34s 56c, leaving out empty leading units. */
|
|
12
|
+
export function formatMoney(copper: number): string {
|
|
13
|
+
const value = Math.max(0, Math.floor(copper));
|
|
14
|
+
const gold = Math.floor(value / 10000);
|
|
15
|
+
const silver = Math.floor((value % 10000) / 100);
|
|
16
|
+
const rest = value % 100;
|
|
17
|
+
if (gold > 0) return String(gold) + "g " + String(silver) + "s " + String(rest) + "c";
|
|
18
|
+
if (silver > 0) return String(silver) + "s " + String(rest) + "c";
|
|
19
|
+
return String(rest) + "c";
|
|
20
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// Design tokens shared by every stylesheet. Import with `@use "../styles/tokens" as *;`.
|
|
2
|
+
$panel: #101721;
|
|
3
|
+
$header: #17212e;
|
|
4
|
+
$control: #1b2533;
|
|
5
|
+
$raised: #263345;
|
|
6
|
+
$line: #405168;
|
|
7
|
+
$edge: #536682;
|
|
8
|
+
$text: #edf2fb;
|
|
9
|
+
$muted: #a7bdd3;
|
|
10
|
+
$gold: #efbf68;
|
|
11
|
+
$gold-dark: #936222;
|
|
12
|
+
$selected: #483921;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { Binding, NodeRef, StyleClass, UINode } from "@kumi/core";
|
|
2
|
+
import styles from "@kumi/styles/shared/ui/Controls";
|
|
3
|
+
|
|
4
|
+
interface ButtonProps {
|
|
5
|
+
readonly label?: Binding<string>;
|
|
6
|
+
/** The name screen readers and tooltips use when the button shows only an icon. */
|
|
7
|
+
readonly accessibleLabel?: string;
|
|
8
|
+
readonly checked?: Binding<boolean>;
|
|
9
|
+
readonly disabled?: Binding<boolean>;
|
|
10
|
+
readonly shown?: Binding<boolean>;
|
|
11
|
+
readonly primary?: boolean;
|
|
12
|
+
/** One extra class for this button, added after the base style. */
|
|
13
|
+
readonly className?: string | StyleClass;
|
|
14
|
+
readonly children?: UINode;
|
|
15
|
+
readonly ref?: NodeRef<"button">;
|
|
16
|
+
onClick(this: void): void;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** A text or icon button. Pass `label` for text, or children for an icon. */
|
|
20
|
+
export function Button(props: ButtonProps) {
|
|
21
|
+
const base = props.primary === true ? styles.primary : styles.button;
|
|
22
|
+
const ariaLabel = props.accessibleLabel ?? (typeof props.label === "string" ? props.label : undefined);
|
|
23
|
+
return (
|
|
24
|
+
<button unstyled ariaLabel={ariaLabel} checked={props.checked} disabled={props.disabled} shown={props.shown}
|
|
25
|
+
className={props.className === undefined ? base : [base, props.className]} nodeRef={props.ref} onClick={props.onClick}>
|
|
26
|
+
{props.label === undefined ? props.children : <span className={styles.label} value={props.label} />}
|
|
27
|
+
</button>
|
|
28
|
+
);
|
|
29
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { Binding, FocusRef } from "@kumi/core";
|
|
2
|
+
import { computed, type ReadonlyRef } from "@kumi/state";
|
|
3
|
+
import styles from "@kumi/styles/shared/ui/Controls";
|
|
4
|
+
import { Button } from "./Button";
|
|
5
|
+
|
|
6
|
+
export interface ChoiceOption<Value extends string> {
|
|
7
|
+
readonly value: Value;
|
|
8
|
+
readonly label: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
interface ChoiceProps<Value extends string> {
|
|
12
|
+
readonly options: readonly ChoiceOption<Value>[];
|
|
13
|
+
readonly value: ReadonlyRef<Value>;
|
|
14
|
+
readonly disabled?: Binding<boolean>;
|
|
15
|
+
readonly ref?: FocusRef;
|
|
16
|
+
onChange(this: void, value: Value): void;
|
|
17
|
+
onBlur?(this: void): void;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** A row of buttons for picking one value. */
|
|
21
|
+
export function Choice<Value extends string>(props: ChoiceProps<Value>) {
|
|
22
|
+
function pick(value: Value) {
|
|
23
|
+
props.onChange(value);
|
|
24
|
+
props.onBlur?.();
|
|
25
|
+
}
|
|
26
|
+
return (
|
|
27
|
+
<div className={styles.choice}>
|
|
28
|
+
{props.options.map(option => (
|
|
29
|
+
<Button key={option.value} label={option.label} disabled={props.disabled}
|
|
30
|
+
checked={computed(() => props.value.value === option.value)} onClick={() => pick(option.value)} />
|
|
31
|
+
))}
|
|
32
|
+
</div>
|
|
33
|
+
);
|
|
34
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
@use "../styles/tokens" as *;
|
|
2
|
+
|
|
3
|
+
.button {
|
|
4
|
+
height: 28px;
|
|
5
|
+
min-width: 72px;
|
|
6
|
+
border: 1px solid $line;
|
|
7
|
+
border-radius: 4px;
|
|
8
|
+
background-color: $control;
|
|
9
|
+
font-size: 14px;
|
|
10
|
+
color: $text;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
.button:hover { background-color: $raised; }
|
|
14
|
+
.button:checked { background-color: $selected; border-color: $gold; }
|
|
15
|
+
.button:disabled { opacity: 0.55; }
|
|
16
|
+
|
|
17
|
+
.primary {
|
|
18
|
+
height: 28px;
|
|
19
|
+
min-width: 96px;
|
|
20
|
+
border: 1px solid $gold;
|
|
21
|
+
border-radius: 4px;
|
|
22
|
+
background-color: $gold-dark;
|
|
23
|
+
font-size: 14px;
|
|
24
|
+
color: $text;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
.primary:hover { background-color: #ad7528; }
|
|
28
|
+
.primary:disabled { opacity: 0.55; }
|
|
29
|
+
|
|
30
|
+
.label {
|
|
31
|
+
position: absolute;
|
|
32
|
+
inset: 0 6px;
|
|
33
|
+
text-align: center;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
.glyph {
|
|
37
|
+
width: 16px;
|
|
38
|
+
height: 16px;
|
|
39
|
+
color: $muted;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
.switch {
|
|
43
|
+
width: 46px;
|
|
44
|
+
height: 22px;
|
|
45
|
+
border: 1px solid $edge;
|
|
46
|
+
border-radius: 11px;
|
|
47
|
+
background-color: $control;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
.switch:checked { border-color: $gold; background-color: $selected; }
|
|
51
|
+
.switch:disabled { opacity: 0.55; }
|
|
52
|
+
|
|
53
|
+
.knobOff, .knobOn {
|
|
54
|
+
position: absolute;
|
|
55
|
+
top: 3px;
|
|
56
|
+
width: 16px;
|
|
57
|
+
height: 16px;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
.knobOff { left: 3px; color: $muted; }
|
|
61
|
+
.knobOn { right: 3px; color: $gold; }
|
|
62
|
+
|
|
63
|
+
.choice {
|
|
64
|
+
display: flex;
|
|
65
|
+
gap: 6px;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
.slider {
|
|
69
|
+
width: 220px;
|
|
70
|
+
height: 24px;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
.track {
|
|
74
|
+
height: 6px;
|
|
75
|
+
background-color: $line;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
.fill {
|
|
79
|
+
height: 6px;
|
|
80
|
+
background-color: $gold;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
.thumb {
|
|
84
|
+
width: 16px;
|
|
85
|
+
height: 16px;
|
|
86
|
+
color: $gold;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
.sliderCaption {
|
|
90
|
+
text-align: left;
|
|
91
|
+
font-size: 13px;
|
|
92
|
+
color: $muted;
|
|
93
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { ClassNames, NodeRef } from "@kumi/core";
|
|
2
|
+
import styles from "@kumi/styles/shared/ui/Controls";
|
|
3
|
+
import { artwork } from "../api/native-art";
|
|
4
|
+
import closeIcon from "../assets/close.png";
|
|
5
|
+
|
|
6
|
+
export type GlyphName = "Close" | "Gear" | "Grip" | "Dot" | "Search";
|
|
7
|
+
|
|
8
|
+
interface GlyphProps {
|
|
9
|
+
readonly name: GlyphName;
|
|
10
|
+
readonly className?: ClassNames;
|
|
11
|
+
readonly ref?: NodeRef<"image">;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/** A small icon from Assets/Art. Size and color it with a class. */
|
|
15
|
+
export function Glyph(props: GlyphProps) {
|
|
16
|
+
const source = props.name === "Close" ? closeIcon : artwork(props.name);
|
|
17
|
+
return <image src={source} className={props.className ?? styles.glyph} nodeRef={props.ref} nativePixelSnap={false} />;
|
|
18
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { Binding, FocusRef } from "@kumi/core";
|
|
2
|
+
import type { ReadonlyRef } from "@kumi/state";
|
|
3
|
+
import styles from "@kumi/styles/shared/ui/Controls";
|
|
4
|
+
import { focusNodeRef } from "./focus-ref";
|
|
5
|
+
|
|
6
|
+
interface SliderProps {
|
|
7
|
+
readonly label: string;
|
|
8
|
+
readonly value: ReadonlyRef<number>;
|
|
9
|
+
readonly min: number;
|
|
10
|
+
readonly max: number;
|
|
11
|
+
readonly step?: number;
|
|
12
|
+
readonly disabled?: Binding<boolean>;
|
|
13
|
+
readonly ref?: FocusRef;
|
|
14
|
+
onChange(this: void, value: number): void;
|
|
15
|
+
onBlur?(this: void): void;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** A range slider. The app theme draws its track and thumb. */
|
|
19
|
+
export function Slider(props: SliderProps) {
|
|
20
|
+
return (
|
|
21
|
+
<input type="range" hideLabel className={styles.slider} label={props.label} min={props.min} max={props.max} step={props.step}
|
|
22
|
+
value={props.value} disabled={props.disabled} nodeRef={focusNodeRef<"range">(props.ref)}
|
|
23
|
+
onChange={props.onChange} onCommit={props.onBlur} />
|
|
24
|
+
);
|
|
25
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { Binding, FocusRef } from "@kumi/core";
|
|
2
|
+
import { computed, type ReadonlyRef } from "@kumi/state";
|
|
3
|
+
import styles from "@kumi/styles/shared/ui/Controls";
|
|
4
|
+
import { artwork } from "../api/native-art";
|
|
5
|
+
import { focusNodeRef } from "./focus-ref";
|
|
6
|
+
|
|
7
|
+
interface ToggleProps {
|
|
8
|
+
readonly label: string;
|
|
9
|
+
readonly value: ReadonlyRef<boolean>;
|
|
10
|
+
readonly disabled?: Binding<boolean>;
|
|
11
|
+
readonly ref?: FocusRef;
|
|
12
|
+
onChange(this: void, value: boolean): void;
|
|
13
|
+
onBlur?(this: void): void;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** An on/off switch. Spread a form field into it: `<Toggle {...register("enabled")} label="Enabled" />`. */
|
|
17
|
+
export function Toggle(props: ToggleProps) {
|
|
18
|
+
function toggle() {
|
|
19
|
+
props.onChange(!props.value.value);
|
|
20
|
+
props.onBlur?.();
|
|
21
|
+
}
|
|
22
|
+
return (
|
|
23
|
+
<button unstyled ariaLabel={props.label} checked={props.value} disabled={props.disabled}
|
|
24
|
+
nodeRef={focusNodeRef<"button">(props.ref)} className={styles.switch} onClick={toggle}>
|
|
25
|
+
<image src={artwork("Dot")} className={styles.knobOff} nativePixelSnap={false} shown={computed(() => !props.value.value)} />
|
|
26
|
+
<image src={artwork("Dot")} className={styles.knobOn} nativePixelSnap={false} shown={props.value} />
|
|
27
|
+
</button>
|
|
28
|
+
);
|
|
29
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { FocusRef, MountedElementKind, NodeRef } from "@kumi/core";
|
|
2
|
+
|
|
3
|
+
/** Turn a form field's focus ref into a node ref for the control that should take focus. */
|
|
4
|
+
export function focusNodeRef<Kind extends MountedElementKind>(ref?: FocusRef): NodeRef<Kind> | undefined {
|
|
5
|
+
if (ref === undefined) return;
|
|
6
|
+
return node => ref(node === undefined ? undefined : { focus: () => node.focus() === true });
|
|
7
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { AppTheme } from "@kumi/wow";
|
|
2
|
+
import styles from "@kumi/styles/shared/ui/Controls";
|
|
3
|
+
import { Glyph } from "./Glyph";
|
|
4
|
+
|
|
5
|
+
/** How range sliders draw their track, fill and thumb. */
|
|
6
|
+
export const rangeSkin: NonNullable<AppTheme["rangeSkin"]> = {
|
|
7
|
+
control: styles.slider,
|
|
8
|
+
caption: styles.sliderCaption,
|
|
9
|
+
thumbSize: 16,
|
|
10
|
+
render: () => ({
|
|
11
|
+
track: <div fullWidth anchor={{ point: "CENTER" }} className={styles.track} />,
|
|
12
|
+
fill: <div fullWidth anchor={{ point: "CENTER" }} className={styles.fill} />,
|
|
13
|
+
thumb: <Glyph name="Dot" className={styles.thumb} />,
|
|
14
|
+
}),
|
|
15
|
+
};
|
|
@@ -1,24 +1,63 @@
|
|
|
1
1
|
{
|
|
2
2
|
"compilerOptions": {
|
|
3
3
|
"target": "ES2020",
|
|
4
|
-
"lib": [
|
|
4
|
+
"lib": [
|
|
5
|
+
"ES2020"
|
|
6
|
+
],
|
|
5
7
|
"module": "ESNext",
|
|
6
8
|
"moduleResolution": "Bundler",
|
|
7
9
|
"strict": true,
|
|
8
10
|
"noEmit": true,
|
|
9
11
|
"types": [],
|
|
10
|
-
"jsx": "react",
|
|
11
|
-
"jsxFactory": "createElement",
|
|
12
|
+
"jsx": "react-jsx",
|
|
12
13
|
"paths": {
|
|
13
|
-
"@kumi/core": [
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
"@kumi/
|
|
17
|
-
|
|
14
|
+
"@kumi/core": [
|
|
15
|
+
"./node_modules/__KUMI_PACKAGE__/src/index.ts"
|
|
16
|
+
],
|
|
17
|
+
"@kumi/state": [
|
|
18
|
+
"./node_modules/__KUMI_PACKAGE__/state/index.ts"
|
|
19
|
+
],
|
|
20
|
+
"@kumi/wow": [
|
|
21
|
+
"./node_modules/__KUMI_PACKAGE__/wow/index.ts"
|
|
22
|
+
],
|
|
23
|
+
"@kumi/wow-generated": [
|
|
24
|
+
"./build/types/wow-api.d.ts"
|
|
25
|
+
],
|
|
26
|
+
"@kumi/animation": [
|
|
27
|
+
"./node_modules/__KUMI_PACKAGE__/animation/index.ts"
|
|
28
|
+
],
|
|
29
|
+
"@kumi/form": [
|
|
30
|
+
"./node_modules/__KUMI_PACKAGE__/form/index.ts"
|
|
31
|
+
],
|
|
32
|
+
"@kumi/router": [
|
|
33
|
+
"./node_modules/__KUMI_PACKAGE__/router/index.ts"
|
|
34
|
+
],
|
|
35
|
+
"@kumi/routes": [
|
|
36
|
+
"./build/routes/index.ts"
|
|
37
|
+
],
|
|
38
|
+
"@kumi/routes/paths": [
|
|
39
|
+
"./build/routes/paths.ts"
|
|
40
|
+
],
|
|
41
|
+
"@kumi/core/jsx-runtime": [
|
|
42
|
+
"./node_modules/__KUMI_PACKAGE__/src/jsx-runtime.ts"
|
|
43
|
+
],
|
|
44
|
+
"@/*": [
|
|
45
|
+
"./src/*"
|
|
46
|
+
],
|
|
47
|
+
"@kumi/styles/*": [
|
|
48
|
+
"./build/styles/*"
|
|
49
|
+
]
|
|
50
|
+
},
|
|
51
|
+
"jsxImportSource": "@kumi/core",
|
|
52
|
+
"experimentalDecorators": true
|
|
18
53
|
},
|
|
19
54
|
"files": [
|
|
20
|
-
"node_modules/__KUMI_PACKAGE__/src/jsx.d.ts",
|
|
21
55
|
"node_modules/__KUMI_PACKAGE__/builder/native-lua.d.ts"
|
|
22
56
|
],
|
|
23
|
-
"include": [
|
|
57
|
+
"include": [
|
|
58
|
+
"src/**/*.ts",
|
|
59
|
+
"src/**/*.tsx",
|
|
60
|
+
"build/kumi/*.d.ts",
|
|
61
|
+
"kumi.config.ts"
|
|
62
|
+
]
|
|
24
63
|
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import type { Anchor } from "../src/elements";
|
|
2
|
+
import type { ReadonlyRef } from "../src/reactivity";
|
|
3
|
+
import { computed, computedResult } from "../src/reactive-scope";
|
|
4
|
+
import { ok } from "../src/result";
|
|
5
|
+
import { snapPixel } from "./pixel";
|
|
6
|
+
|
|
7
|
+
export interface ActionBarPosition {
|
|
8
|
+
readonly x: number;
|
|
9
|
+
readonly y: number;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface ActionBarLayoutOptions {
|
|
13
|
+
readonly count: ReadonlyRef<number>;
|
|
14
|
+
readonly slotSize: ReadonlyRef<number>;
|
|
15
|
+
readonly vertical: ReadonlyRef<boolean>;
|
|
16
|
+
readonly pixel: ReadonlyRef<number>;
|
|
17
|
+
readonly x: ReadonlyRef<number>;
|
|
18
|
+
readonly y: ReadonlyRef<number>;
|
|
19
|
+
readonly preview: ReadonlyRef<ActionBarPosition | undefined>;
|
|
20
|
+
readonly gap: number;
|
|
21
|
+
readonly padding: number;
|
|
22
|
+
readonly controlSize: number;
|
|
23
|
+
readonly controlGap: number;
|
|
24
|
+
readonly iconInsetPixels: number;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function measure(size: number, pixel: number, options: ActionBarLayoutOptions) {
|
|
28
|
+
const cell = snapPixel(size, pixel);
|
|
29
|
+
const step = cell + snapPixel(options.gap, pixel);
|
|
30
|
+
const control = snapPixel(options.controlSize, pixel);
|
|
31
|
+
const padding = snapPixel(options.padding, pixel);
|
|
32
|
+
const trayInset = control + snapPixel(options.controlGap, pixel);
|
|
33
|
+
const first = trayInset + padding;
|
|
34
|
+
const across = Math.max(cell, control) + 2 * padding;
|
|
35
|
+
return {
|
|
36
|
+
cell, step, first, control, trayInset, across,
|
|
37
|
+
cellCenter: snapPixel((across - cell) / 2, pixel),
|
|
38
|
+
controlCenter: snapPixel((across - control) / 2, pixel),
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** Bind an explicitly anchored strip of secure slots, a tray and two end controls. */
|
|
43
|
+
export function useActionBarLayout(this: void, options: ActionBarLayoutOptions) {
|
|
44
|
+
const { count, slotSize, vertical, pixel, preview, x, y } = options;
|
|
45
|
+
const geometry = computed(() => measure(slotSize.value, pixel.value, options));
|
|
46
|
+
|
|
47
|
+
function select<Value>(read: (this: void, value: ReturnType<typeof measure>) => Value) {
|
|
48
|
+
return computedResult(() => {
|
|
49
|
+
const size = geometry.value;
|
|
50
|
+
return size.ok ? ok(read(size.value)) : size;
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function length(value: ReturnType<typeof measure>) {
|
|
55
|
+
const slots = count.value;
|
|
56
|
+
return 2 * value.first + (slots > 0 ? value.cell + (slots - 1) * value.step : 0);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const anchor = computed<Anchor>(() => {
|
|
60
|
+
const current = preview.value;
|
|
61
|
+
return { point: "BOTTOM", x: snapPixel(current?.x ?? x.value, pixel.value), y: snapPixel(current?.y ?? y.value, pixel.value) };
|
|
62
|
+
});
|
|
63
|
+
const control = select(value => value.control);
|
|
64
|
+
const cell = select(value => value.cell);
|
|
65
|
+
const icon = select(value => value.cell - 2 * options.iconInsetPixels * pixel.value);
|
|
66
|
+
|
|
67
|
+
return {
|
|
68
|
+
bar: {
|
|
69
|
+
anchor,
|
|
70
|
+
width: select(value => vertical.value ? value.across : length(value)),
|
|
71
|
+
height: select(value => vertical.value ? length(value) : value.across),
|
|
72
|
+
},
|
|
73
|
+
start: {
|
|
74
|
+
width: control, height: control,
|
|
75
|
+
anchor: select((value): Anchor => vertical.value
|
|
76
|
+
? { point: "TOPLEFT", x: value.controlCenter }
|
|
77
|
+
: { point: "TOPLEFT", y: -value.controlCenter }),
|
|
78
|
+
},
|
|
79
|
+
end: {
|
|
80
|
+
width: control, height: control,
|
|
81
|
+
anchor: select((value): Anchor => vertical.value
|
|
82
|
+
? { point: "BOTTOMLEFT", x: value.controlCenter }
|
|
83
|
+
: { point: "TOPRIGHT", y: -value.controlCenter }),
|
|
84
|
+
},
|
|
85
|
+
tray: {
|
|
86
|
+
width: select(value => vertical.value ? value.across : length(value) - 2 * value.trayInset),
|
|
87
|
+
height: select(value => vertical.value ? length(value) - 2 * value.trayInset : value.across),
|
|
88
|
+
anchor: select((value): Anchor => vertical.value
|
|
89
|
+
? { point: "TOPLEFT", y: -value.trayInset }
|
|
90
|
+
: { point: "TOPLEFT", x: value.trayInset }),
|
|
91
|
+
},
|
|
92
|
+
iconSize: icon,
|
|
93
|
+
cellSize: cell,
|
|
94
|
+
slot(this: void, index: number) {
|
|
95
|
+
return {
|
|
96
|
+
width: cell,
|
|
97
|
+
height: cell,
|
|
98
|
+
shown: computed(() => index < count.value),
|
|
99
|
+
anchor: select((value): Anchor => {
|
|
100
|
+
const offset = value.first + index * value.step;
|
|
101
|
+
return vertical.value
|
|
102
|
+
? { point: "TOPLEFT", x: value.cellCenter, y: -offset }
|
|
103
|
+
: { point: "TOPLEFT", x: offset, y: -value.cellCenter };
|
|
104
|
+
}),
|
|
105
|
+
};
|
|
106
|
+
},
|
|
107
|
+
};
|
|
108
|
+
}
|