@overmvp/kumi 0.0.0-stage → 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/LICENSE +21 -0
- package/README.md +67 -2
- package/animation/color-transition.ts +196 -0
- package/animation/cycle.ts +151 -0
- package/animation/ease.ts +29 -0
- package/animation/index.ts +13 -0
- package/animation/package.json +12 -0
- package/animation/presets.ts +376 -0
- package/animation/spec.ts +197 -0
- package/builder/Cargo.lock +192 -0
- package/builder/Cargo.toml +7 -0
- package/builder/css-v1.mjs +387 -0
- package/builder/css-v1.test.mjs +361 -0
- package/builder/generated-output.mjs +61 -0
- package/builder/generated-output.test.mjs +132 -0
- package/builder/jsx-form.mjs +93 -0
- package/builder/jsx-form.test.mjs +48 -0
- package/builder/jsx-lists.mjs +209 -0
- package/builder/link-addon-package.mjs +127 -0
- package/builder/lua-assets.mjs +74 -0
- package/builder/lua-builtin-values.mjs +57 -0
- package/builder/lua-builtin-values.test.mjs +155 -0
- package/builder/lua-loop-closures.mjs +183 -0
- package/builder/lua-loop-closures.test.mjs +89 -0
- package/builder/lua-truthiness.mjs +61 -0
- package/builder/lua-truthiness.test.mjs +113 -0
- package/builder/module-declarations.mjs +594 -0
- package/builder/module-declarations.test.mjs +435 -0
- package/builder/native-kernels.mjs +60 -0
- package/builder/native-lua.d.ts +57 -0
- package/builder/native-routes.mjs +51 -0
- package/builder/no-static-ref-read.mjs +93 -0
- package/builder/no-static-ref-read.test.mjs +181 -0
- package/builder/secure-snippet.mjs +317 -0
- package/builder/secure-snippet.test.mjs +101 -0
- package/builder/shared-lua-runtime.mjs +150 -0
- package/builder/src/addon-link.lua +29 -0
- package/builder/src/arrays.lua +260 -0
- package/builder/src/assets.rs +177 -0
- package/builder/src/classes.lua +75 -0
- package/builder/src/collections.lua +190 -0
- package/builder/src/compiler.rs +2336 -0
- package/builder/src/config.rs +42 -0
- package/builder/src/entries.rs +166 -0
- package/builder/src/errors.lua +15 -0
- package/builder/src/lua_data.rs +231 -0
- package/builder/src/main.rs +381 -0
- package/builder/src/native_ir.rs +65 -0
- package/builder/src/native_signal.rs +83 -0
- package/builder/src/numbers.lua +76 -0
- package/builder/src/project-front.mjs +3682 -0
- package/builder/src/records.lua +75 -0
- package/builder/src/routes.rs +124 -0
- package/builder/src/setup-store.lua +18 -0
- package/builder/src/signal-kernel.fingerprint +1 -0
- package/builder/src/strings.lua +103 -0
- package/builder/src/ts-lower.mjs +68 -0
- package/builder/src/wow-reads.lua +22 -0
- package/builder/src/wow_client.rs +253 -0
- package/builder/src/wow_types.rs +564 -0
- package/builder/style-modules.mjs +93 -0
- package/builder/style-states.mjs +100 -0
- package/builder/style-states.test.mjs +103 -0
- package/builder/vite-assets.mjs +53 -0
- package/builder/vite-project.mjs +10 -0
- package/config.ts +59 -0
- package/eslint.mjs +74 -0
- package/form/index.ts +526 -0
- package/form/package.json +13 -0
- package/motion/index.ts +2 -0
- package/motion/package.json +10 -0
- package/package.json +26 -4
- package/router/index.ts +50 -0
- package/router/navigation.ts +22 -0
- package/router/package.json +12 -0
- package/router/router-view.ts +134 -0
- package/router/routes.ts +64 -0
- package/scripts/addon-build.mjs +364 -0
- package/scripts/addon-project.mjs +78 -0
- package/scripts/kumi-cli.mjs +105 -0
- package/scripts/link-addons.mjs +61 -0
- package/src/bindings.ts +35 -0
- package/src/context.ts +15 -0
- package/src/css-tokens.ts +239 -0
- package/src/css-v1.ts +68 -0
- package/src/cvars.ts +91 -0
- package/src/element-node.ts +32 -0
- package/src/elements.ts +505 -0
- package/src/feature-scope.ts +82 -0
- package/src/flex-layout.ts +807 -0
- package/src/frame-scheduler.ts +336 -0
- package/src/grid-tracks.ts +165 -0
- package/src/image-imports.d.ts +24 -0
- package/src/images.ts +79 -0
- package/src/index.ts +29 -0
- package/src/jsx-dev-runtime.ts +2 -0
- package/src/jsx-runtime.ts +29 -0
- package/src/jsx.d.ts +12 -0
- package/src/keyed-list.ts +366 -0
- package/src/media-query.ts +144 -0
- package/src/module-ui.ts +147 -0
- package/src/module.ts +311 -0
- package/src/node-selectors.ts +114 -0
- package/src/owned-collections.ts +52 -0
- package/src/providers.ts +241 -0
- package/src/reactive-scope.ts +34 -0
- package/src/reactivity.ts +275 -0
- package/src/result.ts +64 -0
- package/src/runtime.ts +52 -0
- package/src/scheduler.ts +185 -0
- package/src/signal-kernel.ts +63 -0
- package/src/style-classes.ts +51 -0
- package/src/style-states.ts +134 -0
- package/src/style-variables.ts +53 -0
- package/src/text-children.ts +42 -0
- package/src/theme.ts +50 -0
- package/src/transition.ts +18 -0
- package/state/index.ts +9 -0
- package/state/package.json +12 -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-bindings.ts +25 -0
- package/state/store.ts +84 -0
- package/styles/_layers.scss +14 -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 +49 -0
- package/templates/addon/eslint.config.mjs +6 -0
- package/templates/addon/gitignore +9 -0
- package/templates/addon/kumi.config.ts +17 -0
- package/templates/addon/package.json +20 -0
- 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 +63 -0
- package/translate/index.ts +14 -0
- package/translate/package.json +9 -0
- package/utils/colors.ts +76 -0
- package/utils/format.ts +37 -0
- package/utils/index.ts +4 -0
- package/utils/number.ts +17 -0
- package/utils/package.json +7 -0
- package/utils/text.ts +6 -0
- package/validate/index.ts +119 -0
- package/validate/package.json +9 -0
- package/wow/absolute-position.ts +142 -0
- 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/animation.ts +428 -0
- package/wow/app-ui.ts +221 -0
- package/wow/aura-button.ts +76 -0
- package/wow/aura-container.ts +591 -0
- package/wow/aura-countdown.ts +201 -0
- package/wow/aura-slot.ts +153 -0
- package/wow/bar-shade.ts +93 -0
- package/wow/borrowed-slot.ts +216 -0
- package/wow/button-drag.ts +48 -0
- package/wow/cast-clock.ts +153 -0
- package/wow/cast-text.ts +83 -0
- package/wow/class-colors.ts +126 -0
- package/wow/clock.ts +7 -0
- package/wow/color-picker.ts +128 -0
- package/wow/commands.ts +17 -0
- package/wow/contained-frame.ts +128 -0
- package/wow/contract.ts +42 -0
- package/wow/cooldown-timing.ts +24 -0
- package/wow/css-box.ts +144 -0
- package/wow/css-color.ts +12 -0
- package/wow/css-style.ts +109 -0
- package/wow/css-surfaces.ts +603 -0
- package/wow/css-text.ts +399 -0
- package/wow/cursor.ts +45 -0
- package/wow/cvar-schema.ts +32 -0
- package/wow/cvars.ts +98 -0
- package/wow/dropdown-art.ts +39 -0
- package/wow/element-click.ts +20 -0
- package/wow/element-event-coordinator.ts +219 -0
- package/wow/element-events.ts +317 -0
- package/wow/event-dispatcher.ts +151 -0
- package/wow/events.ts +50 -0
- package/wow/font-cache.ts +92 -0
- package/wow/frame-access.ts +53 -0
- package/wow/frame-layer.ts +5 -0
- package/wow/frame-timing.ts +13 -0
- package/wow/frames.ts +236 -0
- package/wow/heal-prediction.ts +305 -0
- package/wow/hooks.ts +133 -0
- package/wow/image-layers.ts +55 -0
- package/wow/index.ts +111 -0
- package/wow/layout-view.ts +663 -0
- package/wow/locale-font.ts +15 -0
- package/wow/lua-string.ts +18 -0
- package/wow/lua-table.ts +18 -0
- package/wow/macro-book.ts +84 -0
- package/wow/map-position.ts +27 -0
- package/wow/media-query.ts +65 -0
- package/wow/module-events.ts +11 -0
- package/wow/native-hooks.ts +168 -0
- package/wow/native-placement.ts +88 -0
- package/wow/native.ts +153 -0
- package/wow/number-format.ts +8 -0
- package/wow/number-input.ts +10 -0
- package/wow/panel-host.ts +97 -0
- package/wow/pixel.ts +35 -0
- package/wow/plugins.ts +246 -0
- package/wow/protect.ts +48 -0
- package/wow/protected-layout.ts +133 -0
- package/wow/protected-view.ts +103 -0
- package/wow/range-art.ts +81 -0
- package/wow/readable-api.ts +120 -0
- package/wow/reparent-frame.ts +99 -0
- package/wow/rounded-texture.ts +183 -0
- package/wow/saved-variables.ts +109 -0
- package/wow/scroll-view.ts +64 -0
- package/wow/secret-ref.ts +14 -0
- package/wow/secure-bindings.ts +89 -0
- package/wow/secure-clicks.ts +432 -0
- package/wow/secure-snippet.ts +235 -0
- package/wow/secure-state.ts +130 -0
- package/wow/secure-target-visibility.ts +89 -0
- package/wow/secure-transaction.ts +331 -0
- package/wow/special-window.ts +269 -0
- package/wow/spell-cooldown.ts +36 -0
- package/wow/start-addon.ts +122 -0
- package/wow/state-paint.ts +256 -0
- package/wow/transition.ts +86 -0
- package/wow/unit-button.ts +39 -0
- package/wow/unit-cast.ts +92 -0
- package/wow/unit-health-text.ts +47 -0
- package/wow/view-nodes.ts +304 -0
- package/wow/view.ts +1864 -0
- package/wow/visible-frame-job.ts +34 -0
- package/wow/width-reserve.ts +108 -0
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
import { ownedArray, type OwnedArray, type OwnedMap, type OwnedReadonlyArray } from "../src/owned-collections";
|
|
2
|
+
import { fail, ok, type Result } from "../src/result";
|
|
3
|
+
import { isSecret, reveal } from "./native";
|
|
4
|
+
import { driverKey, hasSecureStateHandler, isMacroCondition, registerSecureStateDriver } from "./secure-state";
|
|
5
|
+
import {
|
|
6
|
+
attributeName, installSecure, SecureTransaction, secureFrame,
|
|
7
|
+
type SecureFrame, type SecureInstallation, type SecureOptions, type SecureScript,
|
|
8
|
+
} from "./secure-transaction";
|
|
9
|
+
|
|
10
|
+
declare const frameHandle: unique symbol;
|
|
11
|
+
declare const snippetEvent: unique symbol;
|
|
12
|
+
|
|
13
|
+
type SecurePoint = "TOP" | "BOTTOM" | "LEFT" | "RIGHT" | "CENTER" | "TOPLEFT" | "TOPRIGHT" | "BOTTOMLEFT" | "BOTTOMRIGHT";
|
|
14
|
+
export type SecureSnippetValue = string | number | boolean | SecureFrameHandle;
|
|
15
|
+
|
|
16
|
+
/** A handle supplied by WoW to a compiled snippet. */
|
|
17
|
+
export interface SecureFrameHandle {
|
|
18
|
+
readonly [frameHandle]: never;
|
|
19
|
+
GetFrameRef(this: object, name: string): SecureFrameHandle | undefined;
|
|
20
|
+
GetAttribute<Value extends SecureSnippetValue = SecureSnippetValue>(this: object, name: string): Value | undefined;
|
|
21
|
+
SetAttribute(this: object, name: string, value?: SecureSnippetValue): void;
|
|
22
|
+
Show(this: object): void;
|
|
23
|
+
Hide(this: object): void;
|
|
24
|
+
IsShown(this: object): boolean;
|
|
25
|
+
GetName(this: object): string | undefined;
|
|
26
|
+
GetParent(this: object): SecureFrameHandle | undefined;
|
|
27
|
+
Raise(this: object): void;
|
|
28
|
+
SetBindingClick(this: object, priority: boolean, key: string, name: string | SecureFrameHandle, button?: string): void;
|
|
29
|
+
SetBinding(this: object, priority: boolean, key: string, action?: string): void;
|
|
30
|
+
ClearBindings(this: object): void;
|
|
31
|
+
SetHeight(this: object, height: number): void;
|
|
32
|
+
ClearAllPoints(this: object): void;
|
|
33
|
+
SetPoint(this: object, point: SecurePoint, relativeTo?: SecureFrameHandle, relativePoint?: SecurePoint, x?: number, y?: number): void;
|
|
34
|
+
ChildUpdate(this: object, scriptId: string, message?: SecureSnippetValue): void;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
type HoverArgs = [self: SecureFrameHandle, control: SecureFrameHandle];
|
|
38
|
+
type EventArgs = {
|
|
39
|
+
OnClick: [self: SecureFrameHandle, button: string, down: boolean, control: SecureFrameHandle];
|
|
40
|
+
PostClick: [self: SecureFrameHandle, message: SecureSnippetValue, button: string, down: boolean, control: SecureFrameHandle];
|
|
41
|
+
OnEnter: HoverArgs;
|
|
42
|
+
OnLeave: HoverArgs;
|
|
43
|
+
OnShow: HoverArgs;
|
|
44
|
+
OnHide: HoverArgs;
|
|
45
|
+
state: [self: SecureFrameHandle, stateid: string, newstate: string | number | boolean | undefined, control: SecureFrameHandle];
|
|
46
|
+
childUpdate: [self: SecureFrameHandle, scriptid: string, message: SecureSnippetValue | undefined, control: SecureFrameHandle];
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
export type SecureSnippetEvent = keyof EventArgs;
|
|
50
|
+
type SnippetReturn<Event extends SecureSnippetEvent> = Event extends "OnClick"
|
|
51
|
+
? void | false | string | readonly [button: false | string | undefined, message: SecureSnippetValue | undefined]
|
|
52
|
+
: Event extends SecureScript ? void | false : void;
|
|
53
|
+
type SnippetBody<Event extends SecureSnippetEvent> = (this: void, ...args: EventArgs[Event]) => SnippetReturn<Event>;
|
|
54
|
+
|
|
55
|
+
export interface SecureSnippet<Event extends SecureSnippetEvent = SecureSnippetEvent> {
|
|
56
|
+
readonly [snippetEvent]: Event;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export interface SecureSnippetOptions<Event extends SecureSnippetEvent> {
|
|
60
|
+
event: Event;
|
|
61
|
+
refs?: Readonly<Record<string, SecureFrame>>;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export interface WrapSecureSnippetOptions extends SecureOptions {
|
|
65
|
+
after?: SecureSnippet<"PostClick">;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
type Reference = readonly [label: string, frame: SecureFrame];
|
|
69
|
+
|
|
70
|
+
interface SnippetCode {
|
|
71
|
+
readonly event: SecureSnippetEvent;
|
|
72
|
+
readonly body: string;
|
|
73
|
+
readonly refs: OwnedReadonlyArray<Reference>;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const compiled = new WeakMap<SecureSnippet, SnippetCode>();
|
|
77
|
+
|
|
78
|
+
/** Build-time marker lowered by the Kumi compiler. */
|
|
79
|
+
export function secureSnippet<Event extends SecureSnippetEvent>(this: void, body: SnippetBody<Event>,
|
|
80
|
+
options: SecureSnippetOptions<Event>): SecureSnippet<Event>;
|
|
81
|
+
export function secureSnippet(this: void, body: SnippetBody<"OnClick">,
|
|
82
|
+
options?: Omit<SecureSnippetOptions<"OnClick">, "event">): SecureSnippet<"OnClick">;
|
|
83
|
+
export function secureSnippet(this: void, body: unknown, options?: Partial<SecureSnippetOptions<SecureSnippetEvent>>): SecureSnippet {
|
|
84
|
+
const snippet = {} as SecureSnippet;
|
|
85
|
+
if (!isSecret(body) && typeof body === "string") {
|
|
86
|
+
const refs = options?.refs;
|
|
87
|
+
const values = ownedArray<Reference>();
|
|
88
|
+
if (refs !== undefined) {
|
|
89
|
+
for (const name of Object.keys(refs).sort()) values.push([name, refs[name]]);
|
|
90
|
+
}
|
|
91
|
+
compiled.set(snippet, { event: options?.event ?? "OnClick", body, refs: values });
|
|
92
|
+
}
|
|
93
|
+
return snippet;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function decode(snippet: SecureSnippet): Result<SnippetCode> {
|
|
97
|
+
const code = compiled.get(snippet);
|
|
98
|
+
return code === undefined ? fail("The secureSnippet callback must be compiled before installation") : ok(code);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function isWrapEvent(event: SecureSnippetEvent): event is SecureScript {
|
|
102
|
+
return event === "OnClick" || event === "OnEnter" || event === "OnLeave" || event === "OnShow" || event === "OnHide";
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
interface SharedReference {
|
|
106
|
+
readonly frame: SecureFrame;
|
|
107
|
+
readonly transaction: SecureTransaction;
|
|
108
|
+
count: number;
|
|
109
|
+
handle?: unknown;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const references = new WeakMap<SecureFrame, OwnedMap<string, SharedReference>>();
|
|
113
|
+
|
|
114
|
+
function retainRef(transaction: SecureTransaction, control: SecureFrame, [label, frame]: Reference): Result<void> {
|
|
115
|
+
if (!attributeName(label)) return fail("Invalid secure frame reference: " + label);
|
|
116
|
+
const valid = secureFrame(frame);
|
|
117
|
+
if (!valid.ok) return valid;
|
|
118
|
+
|
|
119
|
+
let refs = references.get(control);
|
|
120
|
+
if (refs === undefined) {
|
|
121
|
+
refs = new Map<string, SharedReference>() as OwnedMap<string, SharedReference>;
|
|
122
|
+
references.set(control, refs);
|
|
123
|
+
}
|
|
124
|
+
const attribute = "frameref-" + label;
|
|
125
|
+
const previous = refs.get(label);
|
|
126
|
+
if (previous !== undefined) {
|
|
127
|
+
const current = control.GetAttribute(attribute);
|
|
128
|
+
if (previous.frame !== frame || previous.handle === undefined || isSecret(current) || current !== previous.handle) {
|
|
129
|
+
return fail("Secure frame reference already belongs to another installation: " + label);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
const entry = previous ?? { frame, transaction: new SecureTransaction(), count: 0 };
|
|
134
|
+
entry.count++;
|
|
135
|
+
refs.set(label, entry);
|
|
136
|
+
transaction.defer(() => {
|
|
137
|
+
if (entry.count > 1) {
|
|
138
|
+
entry.count--;
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
const released = entry.transaction.dispose();
|
|
142
|
+
if (released.ok && refs.get(label) === entry) refs.delete(label);
|
|
143
|
+
return released;
|
|
144
|
+
});
|
|
145
|
+
if (previous !== undefined) return ok(undefined);
|
|
146
|
+
|
|
147
|
+
const result = entry.transaction.ref(control, label, frame);
|
|
148
|
+
if (result.ok) entry.handle = control.GetAttribute(attribute);
|
|
149
|
+
return result;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
function retainRefs(transaction: SecureTransaction, control: SecureFrame, refs: OwnedReadonlyArray<Reference>): Result<void> {
|
|
153
|
+
for (const ref of refs) {
|
|
154
|
+
const installed = retainRef(transaction, control, ref);
|
|
155
|
+
if (!installed.ok) return installed;
|
|
156
|
+
}
|
|
157
|
+
return ok(undefined);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
function signature(code: SnippetCode) {
|
|
161
|
+
const refs = code.refs.flatMap(([label, frame]) => [label, frame]) as OwnedArray<string | SecureFrame>;
|
|
162
|
+
return [code.event, code.body, code.refs.length, ...refs] as OwnedArray<string | number | SecureFrame>;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
export function wrapSecureSnippet(this: void, frame: SecureFrame, control: SecureFrame, snippet: SecureSnippet<SecureScript>,
|
|
166
|
+
options: WrapSecureSnippetOptions = {}): Result<SecureInstallation> {
|
|
167
|
+
const before = decode(snippet);
|
|
168
|
+
if (!before.ok) return before;
|
|
169
|
+
const { event, body, refs } = before.value;
|
|
170
|
+
if (!isWrapEvent(event)) return fail("The secure snippet is not a supported wrapped script");
|
|
171
|
+
const after = options.after === undefined ? ok(undefined) : decode(options.after);
|
|
172
|
+
if (!after.ok) return after;
|
|
173
|
+
const post = after.value;
|
|
174
|
+
if (post !== undefined && (event !== "OnClick" || post.event !== "PostClick")) {
|
|
175
|
+
return fail("A PostClick snippet requires an OnClick wrapper");
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
return installSecure(frame, event, options, [control, ...signature(before.value), ...(post === undefined ? [] : signature(post))],
|
|
179
|
+
(transaction, dispose) => {
|
|
180
|
+
const target = secureFrame(frame);
|
|
181
|
+
if (!target.ok) return target;
|
|
182
|
+
const header = secureFrame(control, true);
|
|
183
|
+
if (!header.ok) return header;
|
|
184
|
+
const linked = retainRefs(transaction, control, post === undefined ? refs : [...refs, ...post.refs] as OwnedArray<Reference>);
|
|
185
|
+
if (!linked.ok) return linked;
|
|
186
|
+
const wrapped = transaction.wrap(frame, event, control, body, post?.body);
|
|
187
|
+
return wrapped.ok ? ok({ dispose }) : wrapped;
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
export function secureStateSnippet(this: void, frame: SecureFrame, state: string, macroCondition: string, snippet: SecureSnippet<"state">,
|
|
192
|
+
options: SecureOptions = {}): Result<SecureInstallation> {
|
|
193
|
+
const decoded = decode(snippet);
|
|
194
|
+
if (!decoded.ok) return decoded;
|
|
195
|
+
const code = decoded.value;
|
|
196
|
+
if (code.event !== "state" || !attributeName(state) || state === "visibility" || !isMacroCondition(macroCondition)) {
|
|
197
|
+
return fail("A secure state snippet requires a named attribute state and readable macro condition");
|
|
198
|
+
}
|
|
199
|
+
return installSecure(frame, driverKey(state), options, [macroCondition, ...signature(code)], (transaction, dispose) => {
|
|
200
|
+
const valid = secureFrame(frame, true);
|
|
201
|
+
if (!valid.ok) return valid;
|
|
202
|
+
if (!hasSecureStateHandler(frame)) return fail("A secure state snippet requires a SecureHandlerStateTemplate frame");
|
|
203
|
+
const name = "_onstate-" + state;
|
|
204
|
+
const occupied = frame.GetAttribute(name);
|
|
205
|
+
if (isSecret(occupied) || occupied !== undefined) return fail("Secure handler already exists: " + name);
|
|
206
|
+
const linked = retainRefs(transaction, frame, code.refs);
|
|
207
|
+
if (!linked.ok) return linked;
|
|
208
|
+
const reset = transaction.write(frame, "state-" + state);
|
|
209
|
+
if (!reset.ok) return reset;
|
|
210
|
+
const handler = transaction.setHandler(frame, name, code.body);
|
|
211
|
+
if (!handler.ok) return handler;
|
|
212
|
+
const driver = registerSecureStateDriver(transaction, frame, state, macroCondition);
|
|
213
|
+
return driver.ok ? ok({ dispose }) : driver;
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
export function secureChildUpdateSnippet(this: void, frame: SecureFrame, control: SecureFrame, scriptId: string,
|
|
218
|
+
snippet: SecureSnippet<"childUpdate">, options: SecureOptions = {}): Result<SecureInstallation> {
|
|
219
|
+
const decoded = decode(snippet);
|
|
220
|
+
if (!decoded.ok) return decoded;
|
|
221
|
+
const code = decoded.value;
|
|
222
|
+
if (code.event !== "childUpdate" || !attributeName(scriptId)) return fail("A child update snippet requires a readable script id");
|
|
223
|
+
const name = "_childupdate-" + scriptId;
|
|
224
|
+
return installSecure(frame, name, options, [control, ...signature(code)], (transaction, dispose) => {
|
|
225
|
+
const child = secureFrame(frame);
|
|
226
|
+
if (!child.ok) return child;
|
|
227
|
+
const header = secureFrame(control, true);
|
|
228
|
+
if (!header.ok) return header;
|
|
229
|
+
if (reveal(frame.GetParent()) !== control) return fail("A child update snippet requires a direct child of its control frame");
|
|
230
|
+
const linked = retainRefs(transaction, control, code.refs);
|
|
231
|
+
if (!linked.ok) return linked;
|
|
232
|
+
const handler = transaction.setHandler(frame, name, code.body);
|
|
233
|
+
return handler.ok ? ok({ dispose }) : handler;
|
|
234
|
+
});
|
|
235
|
+
}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { fail, ok, type Result } from "../src/result";
|
|
2
|
+
import type { OwnedReadonlyArray } from "../src/owned-collections";
|
|
3
|
+
import { createdWithSecureStateHandler } from "./frames";
|
|
4
|
+
import { luaString } from "./lua-string";
|
|
5
|
+
import { api, isSecret, reveal } from "./native";
|
|
6
|
+
import {
|
|
7
|
+
attributeName, installSecure, positiveInteger, readableArray, scriptOf, secureFrame, secureUpdate, type SecureButton,
|
|
8
|
+
type SecureFrame, type SecureInstallation, type SecureOptions, type SecureTransaction,
|
|
9
|
+
} from "./secure-transaction";
|
|
10
|
+
|
|
11
|
+
export interface StateDriverInstallation extends SecureInstallation {
|
|
12
|
+
update(this: void, macroCondition: string): Result<void>;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface SecureActionPagingOptions extends SecureOptions {
|
|
16
|
+
buttons: readonly SecureButton[];
|
|
17
|
+
slotsPerPage: number;
|
|
18
|
+
macroCondition: string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const childState = "_childupdate-actionpage";
|
|
22
|
+
const pageState = "_onstate-page";
|
|
23
|
+
const pageBody = `if type(newstate) == "number" and newstate > 0 then
|
|
24
|
+
control:ChildUpdate("actionpage", newstate)
|
|
25
|
+
end`;
|
|
26
|
+
|
|
27
|
+
export function isMacroCondition(condition: string): boolean {
|
|
28
|
+
return !isSecret(condition) && typeof condition === "string" && luaString.match(condition, "%S") !== undefined
|
|
29
|
+
&& luaString.match(condition, "%z") === undefined;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function driverKey(state: string) {
|
|
33
|
+
return "state driver " + state;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function hasSecureStateHandler(frame: SecureFrame): boolean {
|
|
37
|
+
const script = scriptOf(frame, "OnAttributeChanged");
|
|
38
|
+
return typeof script === "function" && (createdWithSecureStateHandler(frame) || script === api.SecureHandler_StateOnAttributeChanged);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function hasCreatedSecureStateHandler(frame: SecureFrame): boolean {
|
|
42
|
+
return createdWithSecureStateHandler(frame) && typeof scriptOf(frame, "OnAttributeChanged") === "function";
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function registerSecureStateDriver(transaction: SecureTransaction, frame: SecureFrame, state: string, macroCondition: string): Result<void> {
|
|
46
|
+
const reserved = transaction.claim(frame, driverKey(state));
|
|
47
|
+
if (!reserved.ok) return reserved;
|
|
48
|
+
if (state === "visibility") {
|
|
49
|
+
const shown = reveal(frame.IsShown());
|
|
50
|
+
if (typeof shown !== "boolean") return fail("Secure frame visibility is unreadable");
|
|
51
|
+
transaction.defer(() => {
|
|
52
|
+
if (shown) frame.Show();
|
|
53
|
+
else frame.Hide();
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
const attribute = transaction.capture(frame, state === "visibility" ? "statehidden" : "state-" + state);
|
|
57
|
+
if (!attribute.ok) return attribute;
|
|
58
|
+
transaction.defer(() => api.UnregisterStateDriver(frame, state));
|
|
59
|
+
api.RegisterStateDriver(frame, state, macroCondition);
|
|
60
|
+
return ok(undefined);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function driver(frame: SecureFrame, state: string, macroCondition: string, dispose: SecureInstallation["dispose"],
|
|
64
|
+
update: (this: void, run: (this: void) => Result<void>) => Result<void>): StateDriverInstallation {
|
|
65
|
+
let condition = macroCondition;
|
|
66
|
+
return {
|
|
67
|
+
dispose,
|
|
68
|
+
update: next => update(() => {
|
|
69
|
+
if (!isMacroCondition(next)) return fail("A nonempty, readable macro condition is required");
|
|
70
|
+
if (next === condition) return ok(undefined);
|
|
71
|
+
const result = secureUpdate(transaction => {
|
|
72
|
+
const previous = condition;
|
|
73
|
+
transaction.defer(() => api.RegisterStateDriver(frame, state, previous));
|
|
74
|
+
api.RegisterStateDriver(frame, state, next);
|
|
75
|
+
return ok(undefined);
|
|
76
|
+
});
|
|
77
|
+
if (result.ok) condition = next;
|
|
78
|
+
return result;
|
|
79
|
+
}),
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export function stateDriver(this: void, frame: SecureFrame, state: string, macroCondition: string,
|
|
84
|
+
options: SecureOptions = {}): Result<StateDriverInstallation> {
|
|
85
|
+
if (!attributeName(state) || !isMacroCondition(macroCondition)) return fail("A readable state name and macro condition are required");
|
|
86
|
+
return installSecure(frame, driverKey(state), options, [macroCondition], (transaction, dispose, update) => {
|
|
87
|
+
const valid = secureFrame(frame);
|
|
88
|
+
if (!valid.ok) return valid;
|
|
89
|
+
const registered = registerSecureStateDriver(transaction, frame, state, macroCondition);
|
|
90
|
+
return registered.ok ? ok(driver(frame, state, macroCondition, dispose, update)) : registered;
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export function secureActionPaging(this: void, header: SecureFrame, options: SecureActionPagingOptions): Result<StateDriverInstallation> {
|
|
95
|
+
const { buttons: supplied, slotsPerPage, macroCondition } = options;
|
|
96
|
+
const buttons = supplied as OwnedReadonlyArray<SecureButton>;
|
|
97
|
+
if (!positiveInteger(slotsPerPage) || !readableArray(buttons) || buttons.length === 0
|
|
98
|
+
|| buttons.length > slotsPerPage || new Set(buttons).size !== buttons.length || !isMacroCondition(macroCondition)) {
|
|
99
|
+
return fail("Secure paging requires distinct buttons, a page size and a readable macro condition");
|
|
100
|
+
}
|
|
101
|
+
return installSecure(header, driverKey("page"), options, ["paging", slotsPerPage, macroCondition, ...buttons], (transaction, dispose, update) => {
|
|
102
|
+
const valid = secureFrame(header, true);
|
|
103
|
+
if (!valid.ok) return valid;
|
|
104
|
+
if (!hasSecureStateHandler(header)) {
|
|
105
|
+
return fail("Secure paging requires a SecureHandlerStateTemplate header");
|
|
106
|
+
}
|
|
107
|
+
for (const button of buttons) {
|
|
108
|
+
const child = secureFrame(button);
|
|
109
|
+
if (!child.ok) return child;
|
|
110
|
+
if (reveal(button.GetParent()) !== header) return fail("Secure paging buttons must be direct children of the header");
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
const body = `self:SetAttribute("action", self:GetAttribute("index") + (message - 1) * ${slotsPerPage})`;
|
|
114
|
+
for (let index = 0; index < buttons.length; index++) {
|
|
115
|
+
const button = buttons[index];
|
|
116
|
+
const action = transaction.capture(button, "action");
|
|
117
|
+
if (!action.ok) return action;
|
|
118
|
+
const position = transaction.write(button, "index", index + 1);
|
|
119
|
+
if (!position.ok) return position;
|
|
120
|
+
const updateChild = transaction.write(button, childState, body);
|
|
121
|
+
if (!updateChild.ok) return updateChild;
|
|
122
|
+
}
|
|
123
|
+
const page = transaction.write(header, "state-page");
|
|
124
|
+
if (!page.ok) return page;
|
|
125
|
+
const handler = transaction.write(header, pageState, pageBody);
|
|
126
|
+
if (!handler.ok) return handler;
|
|
127
|
+
const registered = registerSecureStateDriver(transaction, header, "page", macroCondition);
|
|
128
|
+
return registered.ok ? ok(driver(header, "page", macroCondition, dispose, update)) : registered;
|
|
129
|
+
});
|
|
130
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { fail, ok, type Result } from "../src/result";
|
|
2
|
+
import { currentScope } from "../src/reactive-scope";
|
|
3
|
+
import { canAccessRegion } from "./frame-access";
|
|
4
|
+
import type { Frame } from "./frames";
|
|
5
|
+
import { api, isSecret, reveal } from "./native";
|
|
6
|
+
import { createProtectedLayoutUpdate } from "./protected-layout";
|
|
7
|
+
import { driverKey, hasCreatedSecureStateHandler, registerSecureStateDriver } from "./secure-state";
|
|
8
|
+
import { installSecure, secureUpdate, type SecureFrame, type SecureInstallation, type SecureOptions } from "./secure-transaction";
|
|
9
|
+
|
|
10
|
+
export interface SecureTargetVisibilityOptions extends SecureOptions {
|
|
11
|
+
shown: boolean;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface SecureTargetVisibilityInstallation extends SecureInstallation {
|
|
15
|
+
setShown(this: void, shown: boolean): Result<void>;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const targetState = "vis";
|
|
19
|
+
const targetLabel = "kumi-visibility-target";
|
|
20
|
+
const targetBody = `local target = self:GetFrameRef("${targetLabel}")
|
|
21
|
+
if not target then return end
|
|
22
|
+
if newstate == "hide" then target:Hide()
|
|
23
|
+
elseif newstate == "show" then target:Show() end`;
|
|
24
|
+
|
|
25
|
+
/** Drive only the visibility of a referenced native frame, outside combat. */
|
|
26
|
+
export function secureTargetVisibility(this: void, controller: SecureFrame, target: Frame,
|
|
27
|
+
options: SecureTargetVisibilityOptions): Result<SecureTargetVisibilityInstallation> {
|
|
28
|
+
const shown = reveal(options.shown);
|
|
29
|
+
const scope = options.scope ?? currentScope();
|
|
30
|
+
if (isSecret(controller) || isSecret(target) || controller === target || typeof shown !== "boolean"
|
|
31
|
+
|| scope === undefined || !scope.isActive()) return fail("Target visibility requires readable frames, a boolean and an active scope");
|
|
32
|
+
|
|
33
|
+
const initial = shown ? "show" : "hide";
|
|
34
|
+
return installSecure(controller, driverKey(targetState), { ...options, scope }, [target, shown],
|
|
35
|
+
(transaction, dispose, update) => {
|
|
36
|
+
if (!hasCreatedSecureStateHandler(controller) || !canAccessRegion(target)) {
|
|
37
|
+
return fail("Target visibility requires a Kumi-created state controller and an accessible target");
|
|
38
|
+
}
|
|
39
|
+
const original = reveal(target.IsShown());
|
|
40
|
+
if (typeof original !== "boolean") return fail("The target's original visibility is unreadable");
|
|
41
|
+
|
|
42
|
+
let applied = initial;
|
|
43
|
+
let desired = initial;
|
|
44
|
+
let closing = false;
|
|
45
|
+
const layout = createProtectedLayoutUpdate(() => {
|
|
46
|
+
if (closing) return;
|
|
47
|
+
const next = desired;
|
|
48
|
+
const result = update(() => secureUpdate(change => {
|
|
49
|
+
const before = applied;
|
|
50
|
+
change.defer(() => api.RegisterStateDriver(controller, targetState, before));
|
|
51
|
+
api.UnregisterStateDriver(controller, targetState);
|
|
52
|
+
api.RegisterStateDriver(controller, targetState, next);
|
|
53
|
+
applied = next;
|
|
54
|
+
return ok(undefined);
|
|
55
|
+
}));
|
|
56
|
+
if (!result.ok) return result;
|
|
57
|
+
}, { scope, label: "Secure target visibility" });
|
|
58
|
+
if (!layout.ok) return layout;
|
|
59
|
+
|
|
60
|
+
const reference = transaction.ref(controller, targetLabel, target);
|
|
61
|
+
if (!reference.ok) return reference;
|
|
62
|
+
const cleared = transaction.write(controller, "state-" + targetState);
|
|
63
|
+
if (!cleared.ok) return cleared;
|
|
64
|
+
const handler = transaction.setHandler(controller, "_onstate-" + targetState, targetBody);
|
|
65
|
+
if (!handler.ok) return handler;
|
|
66
|
+
transaction.defer(() => {
|
|
67
|
+
// Run before the handler and its reference are released.
|
|
68
|
+
if (reveal(target.IsShown()) !== original) {
|
|
69
|
+
api.RegisterStateDriver(controller, targetState, original ? "show" : "hide");
|
|
70
|
+
}
|
|
71
|
+
api.UnregisterStateDriver(controller, targetState);
|
|
72
|
+
});
|
|
73
|
+
const registered = registerSecureStateDriver(transaction, controller, targetState, initial);
|
|
74
|
+
if (!registered.ok) return registered;
|
|
75
|
+
|
|
76
|
+
return ok({
|
|
77
|
+
setShown: value => {
|
|
78
|
+
const next = reveal(value);
|
|
79
|
+
if (closing || typeof next !== "boolean") return fail("Target visibility is unavailable or unreadable");
|
|
80
|
+
desired = next ? "show" : "hide";
|
|
81
|
+
return layout.value.request();
|
|
82
|
+
},
|
|
83
|
+
dispose: () => {
|
|
84
|
+
closing = true;
|
|
85
|
+
return dispose();
|
|
86
|
+
},
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
}
|