@overmvp/kumi 0.0.0-stage → 0.1.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.
Files changed (205) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +14 -2
  3. package/animation/color-transition.ts +196 -0
  4. package/animation/cycle.ts +151 -0
  5. package/animation/ease.ts +29 -0
  6. package/animation/index.ts +13 -0
  7. package/animation/package.json +12 -0
  8. package/animation/presets.ts +376 -0
  9. package/animation/spec.ts +197 -0
  10. package/builder/Cargo.lock +192 -0
  11. package/builder/Cargo.toml +7 -0
  12. package/builder/css-v1.mjs +334 -0
  13. package/builder/css-v1.test.mjs +321 -0
  14. package/builder/generated-output.mjs +61 -0
  15. package/builder/generated-output.test.mjs +132 -0
  16. package/builder/jsx-form.mjs +93 -0
  17. package/builder/jsx-form.test.mjs +48 -0
  18. package/builder/jsx-lists.mjs +209 -0
  19. package/builder/link-addon-package.mjs +86 -0
  20. package/builder/lua-assets.mjs +74 -0
  21. package/builder/lua-builtin-values.mjs +57 -0
  22. package/builder/lua-builtin-values.test.mjs +155 -0
  23. package/builder/lua-loop-closures.mjs +183 -0
  24. package/builder/lua-loop-closures.test.mjs +89 -0
  25. package/builder/lua-truthiness.mjs +61 -0
  26. package/builder/lua-truthiness.test.mjs +113 -0
  27. package/builder/module-declarations.mjs +594 -0
  28. package/builder/module-declarations.test.mjs +444 -0
  29. package/builder/native-kernels.mjs +60 -0
  30. package/builder/native-lua.d.ts +57 -0
  31. package/builder/native-routes.mjs +51 -0
  32. package/builder/no-static-ref-read.mjs +93 -0
  33. package/builder/no-static-ref-read.test.mjs +181 -0
  34. package/builder/secure-snippet.mjs +317 -0
  35. package/builder/secure-snippet.test.mjs +101 -0
  36. package/builder/shared-lua-runtime.mjs +150 -0
  37. package/builder/src/addon-link.lua +29 -0
  38. package/builder/src/arrays.lua +260 -0
  39. package/builder/src/assets.rs +177 -0
  40. package/builder/src/classes.lua +75 -0
  41. package/builder/src/collections.lua +190 -0
  42. package/builder/src/compiler.rs +2164 -0
  43. package/builder/src/config.rs +42 -0
  44. package/builder/src/entries.rs +166 -0
  45. package/builder/src/errors.lua +15 -0
  46. package/builder/src/lua_data.rs +231 -0
  47. package/builder/src/main.rs +367 -0
  48. package/builder/src/native_ir.rs +65 -0
  49. package/builder/src/native_signal.rs +47 -0
  50. package/builder/src/numbers.lua +62 -0
  51. package/builder/src/project-front.mjs +3331 -0
  52. package/builder/src/records.lua +75 -0
  53. package/builder/src/routes.rs +127 -0
  54. package/builder/src/signal-kernel.fingerprint +1 -0
  55. package/builder/src/strings.lua +103 -0
  56. package/builder/src/ts-lower.mjs +68 -0
  57. package/builder/src/wow_client.rs +253 -0
  58. package/builder/src/wow_types.rs +564 -0
  59. package/builder/style-states.mjs +100 -0
  60. package/builder/style-states.test.mjs +103 -0
  61. package/builder/vite-assets.mjs +53 -0
  62. package/builder/vite-project.mjs +10 -0
  63. package/config.ts +17 -0
  64. package/form/index.ts +522 -0
  65. package/form/package.json +13 -0
  66. package/motion/index.ts +2 -0
  67. package/motion/package.json +10 -0
  68. package/package.json +22 -4
  69. package/router/index.ts +43 -0
  70. package/router/package.json +12 -0
  71. package/router/routes.ts +64 -0
  72. package/scripts/kumi-cli.mjs +70 -0
  73. package/scripts/link-addons.mjs +51 -0
  74. package/src/bindings.ts +35 -0
  75. package/src/context.ts +15 -0
  76. package/src/css-tokens.ts +234 -0
  77. package/src/css-v1.ts +58 -0
  78. package/src/cvars.ts +91 -0
  79. package/src/element-node.ts +32 -0
  80. package/src/elements.ts +479 -0
  81. package/src/feature-scope.ts +82 -0
  82. package/src/flex-layout.ts +807 -0
  83. package/src/frame-scheduler.ts +334 -0
  84. package/src/grid-tracks.ts +165 -0
  85. package/src/image-imports.d.ts +24 -0
  86. package/src/images.ts +79 -0
  87. package/src/index.ts +28 -0
  88. package/src/jsx-dev-runtime.ts +2 -0
  89. package/src/jsx-runtime.ts +22 -0
  90. package/src/jsx.d.ts +12 -0
  91. package/src/keyed-list.ts +363 -0
  92. package/src/media-query.ts +144 -0
  93. package/src/module.ts +277 -0
  94. package/src/node-selectors.ts +114 -0
  95. package/src/owned-collections.ts +44 -0
  96. package/src/providers.ts +235 -0
  97. package/src/reactive-scope.ts +34 -0
  98. package/src/reactivity.ts +254 -0
  99. package/src/result.ts +58 -0
  100. package/src/runtime.ts +52 -0
  101. package/src/scheduler.ts +185 -0
  102. package/src/signal-kernel.ts +30 -0
  103. package/src/style-classes.ts +51 -0
  104. package/src/style-states.ts +134 -0
  105. package/src/style-variables.ts +53 -0
  106. package/src/text-children.ts +42 -0
  107. package/src/theme.ts +50 -0
  108. package/src/transition.ts +18 -0
  109. package/state/index.ts +3 -0
  110. package/state/package.json +12 -0
  111. package/state/store-bindings.ts +25 -0
  112. package/state/store.ts +82 -0
  113. package/styles/_layers.scss +14 -0
  114. package/templates/addon/README.md +14 -0
  115. package/templates/addon/__ADDON_NAME__.toc +4 -0
  116. package/templates/addon/eslint.config.mjs +12 -0
  117. package/templates/addon/gitignore +8 -0
  118. package/templates/addon/package.json +21 -0
  119. package/templates/addon/scripts/build.mjs +25 -0
  120. package/templates/addon/src/app/main.tsx +13 -0
  121. package/templates/addon/tsconfig.json +24 -0
  122. package/translate/index.ts +14 -0
  123. package/translate/package.json +9 -0
  124. package/utils/colors.ts +76 -0
  125. package/utils/format.ts +37 -0
  126. package/utils/index.ts +4 -0
  127. package/utils/number.ts +17 -0
  128. package/utils/package.json +7 -0
  129. package/utils/text.ts +6 -0
  130. package/validate/index.ts +119 -0
  131. package/validate/package.json +9 -0
  132. package/wow/absolute-position.ts +142 -0
  133. package/wow/animation.ts +428 -0
  134. package/wow/aura-button.ts +76 -0
  135. package/wow/aura-container.ts +591 -0
  136. package/wow/aura-countdown.ts +201 -0
  137. package/wow/aura-slot.ts +153 -0
  138. package/wow/bar-shade.ts +93 -0
  139. package/wow/borrowed-slot.ts +216 -0
  140. package/wow/button-drag.ts +48 -0
  141. package/wow/cast-clock.ts +153 -0
  142. package/wow/cast-text.ts +83 -0
  143. package/wow/class-colors.ts +126 -0
  144. package/wow/clock.ts +7 -0
  145. package/wow/color-picker.ts +128 -0
  146. package/wow/commands.ts +17 -0
  147. package/wow/contained-frame.ts +128 -0
  148. package/wow/contract.ts +42 -0
  149. package/wow/css-box.ts +110 -0
  150. package/wow/css-color.ts +12 -0
  151. package/wow/css-style.ts +109 -0
  152. package/wow/css-surfaces.ts +398 -0
  153. package/wow/css-text.ts +399 -0
  154. package/wow/cvar-schema.ts +32 -0
  155. package/wow/cvars.ts +98 -0
  156. package/wow/dropdown-art.ts +39 -0
  157. package/wow/element-click.ts +20 -0
  158. package/wow/element-event-coordinator.ts +219 -0
  159. package/wow/element-events.ts +317 -0
  160. package/wow/event-dispatcher.ts +151 -0
  161. package/wow/events.ts +50 -0
  162. package/wow/font-cache.ts +92 -0
  163. package/wow/frame-access.ts +31 -0
  164. package/wow/frame-layer.ts +5 -0
  165. package/wow/frames.ts +236 -0
  166. package/wow/heal-prediction.ts +305 -0
  167. package/wow/image-layers.ts +55 -0
  168. package/wow/index.ts +97 -0
  169. package/wow/layout-view.ts +651 -0
  170. package/wow/lua-string.ts +18 -0
  171. package/wow/lua-table.ts +18 -0
  172. package/wow/macro-book.ts +84 -0
  173. package/wow/map-position.ts +27 -0
  174. package/wow/media-query.ts +65 -0
  175. package/wow/module-events.ts +11 -0
  176. package/wow/native-hooks.ts +168 -0
  177. package/wow/native-placement.ts +88 -0
  178. package/wow/native.ts +135 -0
  179. package/wow/number-format.ts +8 -0
  180. package/wow/number-input.ts +10 -0
  181. package/wow/protect.ts +24 -0
  182. package/wow/protected-layout.ts +133 -0
  183. package/wow/range-art.ts +74 -0
  184. package/wow/reparent-frame.ts +99 -0
  185. package/wow/rounded-texture.ts +156 -0
  186. package/wow/saved-variables.ts +60 -0
  187. package/wow/scroll-view.ts +64 -0
  188. package/wow/secret-ref.ts +14 -0
  189. package/wow/secure-bindings.ts +89 -0
  190. package/wow/secure-clicks.ts +432 -0
  191. package/wow/secure-snippet.ts +235 -0
  192. package/wow/secure-state.ts +130 -0
  193. package/wow/secure-target-visibility.ts +89 -0
  194. package/wow/secure-transaction.ts +331 -0
  195. package/wow/special-window.ts +269 -0
  196. package/wow/start-addon.ts +99 -0
  197. package/wow/state-paint.ts +256 -0
  198. package/wow/transition.ts +86 -0
  199. package/wow/unit-button.ts +39 -0
  200. package/wow/unit-cast.ts +92 -0
  201. package/wow/unit-health-text.ts +47 -0
  202. package/wow/view-nodes.ts +304 -0
  203. package/wow/view.ts +1746 -0
  204. package/wow/visible-frame-job.ts +34 -0
  205. package/wow/width-reserve.ts +108 -0
@@ -0,0 +1,398 @@
1
+ import type { CssBorder, CssSide } from "../src/css-v1";
2
+ import type { OwnedArray } from "../src/owned-collections";
3
+ import { ref } from "../src/reactivity";
4
+ import { fail, ok, type Result } from "../src/result";
5
+ import type { RuntimeScope } from "../src/runtime";
6
+ import type { StatePaint } from "../src/style-states";
7
+ import { resolveStyleValue, type StyleEnvironment } from "../src/style-variables";
8
+ import type { RGBA } from "../utils/colors";
9
+ import { readCssColor } from "./css-color";
10
+ import type { Frame, MaskTexture, Texture } from "./frames";
11
+ import { isSecret, reveal } from "./native";
12
+ import type { RoundedTextures } from "./rounded-texture";
13
+
14
+ type Insets = readonly [top: number, right: number, bottom: number, left: number];
15
+ type BackgroundImage = StatePaint["backgroundImage"];
16
+ type Point = "TOPLEFT" | "TOPRIGHT" | "BOTTOMRIGHT" | "BOTTOMLEFT";
17
+
18
+ interface SurfaceTexture {
19
+ texture: Texture;
20
+ shown: boolean;
21
+ masked: boolean;
22
+ red?: number;
23
+ green?: number;
24
+ blue?: number;
25
+ alpha?: number;
26
+ }
27
+
28
+ interface NativeBorder {
29
+ insets: Insets;
30
+ colors: Partial<Record<CssSide, { literal: string; rgba: RGBA }>>;
31
+ }
32
+
33
+ export interface CssSurfaceOptions {
34
+ readonly rounded?: Pick<RoundedTextures, "applyMask"> & Partial<Pick<RoundedTextures, "apply">>;
35
+ readonly nativeRoundedArt?: boolean;
36
+ readonly environment?: StyleEnvironment;
37
+ readonly color?: boolean;
38
+ readonly image?: boolean;
39
+ readonly borderState?: boolean;
40
+ }
41
+
42
+ export interface CssSurface {
43
+ setBorder(this: void, border?: CssBorder, radius?: number): Result<void>;
44
+ readonly borderPaint?: {
45
+ readonly sides?: readonly CssSide[];
46
+ read(this: void, side: CssSide): string | undefined;
47
+ write(this: void, side: CssSide, red: number, green: number, blue: number, alpha: number): void;
48
+ };
49
+ setBackgroundColor(this: void, r: number, g: number, b: number, a: number): void;
50
+ setBackgroundImage(this: void, image?: BackgroundImage): void;
51
+ }
52
+
53
+ export const borderSides = ["top", "right", "bottom", "left"] as const;
54
+ const zeroInsets: Insets = [0, 0, 0, 0];
55
+ const white = "Interface\\Buttons\\WHITE8X8";
56
+ const maskWrap = "CLAMPTOBLACKADDITIVE";
57
+
58
+ function width(value: number | undefined): number {
59
+ return !isSecret(value) && typeof value === "number" && Number.isFinite(value) && value > 0 ? value : 0;
60
+ }
61
+
62
+ export function borderInsets(this: void, border?: CssBorder): Insets {
63
+ if (border === undefined) return zeroInsets;
64
+ return [width(border.top?.width), width(border.right?.width), width(border.bottom?.width), width(border.left?.width)];
65
+ }
66
+
67
+ function readBorder(border: CssBorder | undefined, environment: StyleEnvironment | undefined): Result<NativeBorder> {
68
+ const colors: NativeBorder["colors"] = {};
69
+ for (const side of borderSides) {
70
+ const edge = border?.[side];
71
+ if (edge === undefined) continue;
72
+ const value = reveal(edge.width);
73
+ if (typeof value !== "number" || !Number.isFinite(value) || value < 0) return fail(`Invalid ${side} border width`);
74
+ if (value === 0) continue;
75
+ const color = reveal(edge.color);
76
+ if (typeof color !== "string") return fail(`Invalid ${side} border color`);
77
+ const resolved = resolveStyleValue(color, environment);
78
+ if (!resolved.ok) return resolved;
79
+ const literal = reveal(resolved.value);
80
+ const rgba = typeof literal === "string" ? readCssColor(literal) : undefined;
81
+ if (literal === undefined || rgba === undefined) return fail(`Invalid ${side} border color`);
82
+ colors[side] = { literal, rgba };
83
+ }
84
+ return ok({ insets: borderInsets(border), colors });
85
+ }
86
+
87
+ function sameInsets(left: Insets, right: Insets) {
88
+ return left[0] === right[0] && left[1] === right[1] && left[2] === right[2] && left[3] === right[3];
89
+ }
90
+
91
+ /** Draw in the outer box. Only a border configuration touches native anchors. */
92
+ export function createCssSurface(this: void, scope: RuntimeScope, frame: Frame, options: CssSurfaceOptions = {}): Result<CssSurface> {
93
+ if (!scope.isActive()) return fail("CSS surface requires an active scope");
94
+ const artwork = options.nativeRoundedArt === true ? options.rounded?.apply : undefined;
95
+ if (options.nativeRoundedArt === true && (artwork === undefined || options.color !== true || options.image === true)) {
96
+ return fail("Native rounded art requires a host texture port and a CSS color fill");
97
+ }
98
+ const layers: SurfaceTexture[] = [];
99
+ const edges: Record<CssSide, SurfaceTexture[]> = { top: [], right: [], bottom: [], left: [] };
100
+ const used: Record<CssSide, number> = { top: 0, right: 0, bottom: 0, left: 0 };
101
+ const borderState = options.borderState === true
102
+ ? { base: ref<NativeBorder["colors"]>({}), drawn: {} as Partial<Record<CssSide, RGBA>> }
103
+ : undefined;
104
+ let color: SurfaceTexture | undefined;
105
+ let image: SurfaceTexture | undefined;
106
+ let outline: SurfaceTexture | undefined;
107
+ let mask: MaskTexture | undefined;
108
+ let maskRadius: number | undefined;
109
+ let hasMaskAnchor = false;
110
+ let previousInsets = zeroInsets;
111
+ let previousRadius = 0;
112
+ let artworkRadius: number | undefined;
113
+
114
+ function shown(layer: SurfaceTexture, visible: boolean) {
115
+ if (layer.shown === visible) return;
116
+ layer.texture.SetShown(visible);
117
+ layer.shown = visible;
118
+ }
119
+
120
+ function tint(layer: SurfaceTexture, red: number, green: number, blue: number, alpha: number) {
121
+ if (layer.red === red && layer.green === green && layer.blue === blue && layer.alpha === alpha) return;
122
+ layer.texture.SetVertexColor(red, green, blue, alpha);
123
+ layer.red = red;
124
+ layer.green = green;
125
+ layer.blue = blue;
126
+ layer.alpha = alpha;
127
+ }
128
+
129
+ function attach(layer: SurfaceTexture, next: MaskTexture) {
130
+ if (!layer.masked) {
131
+ layer.texture.AddMaskTexture(next);
132
+ layer.masked = true;
133
+ }
134
+ }
135
+
136
+ function detach(layer: SurfaceTexture, old: MaskTexture) {
137
+ if (layer.masked) {
138
+ layer.texture.RemoveMaskTexture(old);
139
+ layer.masked = false;
140
+ }
141
+ }
142
+
143
+ function makeLayer(layer: "BACKGROUND" | "BORDER", level: number, solid: boolean) {
144
+ const texture = frame.CreateTexture(undefined, layer, undefined, level);
145
+ const entry: SurfaceTexture = { texture, shown: true, masked: false };
146
+ layers.push(entry);
147
+ shown(entry, false);
148
+ if (solid) texture.SetColorTexture(1, 1, 1, 1);
149
+ if (mask !== undefined && maskRadius !== undefined) attach(entry, mask);
150
+ return entry;
151
+ }
152
+
153
+ function applyMask(target: MaskTexture, radius: number) {
154
+ if (radius > 0) return options.rounded?.applyMask(target, radius) === true;
155
+ if (target.SetTexture(white, maskWrap, maskWrap) === false) return false;
156
+ target.SetTextureSliceMargins?.(0, 0, 0, 0);
157
+ return true;
158
+ }
159
+
160
+ function setMask(radius: number | undefined): Result<void> {
161
+ if (maskRadius === radius) return ok(undefined);
162
+ if (radius === undefined) {
163
+ if (mask !== undefined) for (const layer of layers) detach(layer, mask);
164
+ maskRadius = undefined;
165
+ return ok(undefined);
166
+ }
167
+ if (typeof frame.CreateMaskTexture !== "function") {
168
+ return radius === 0 ? ok(undefined) : fail(`CSS border radius ${radius} requires native masks`);
169
+ }
170
+ if (radius > 0 && options.rounded === undefined) return fail(`Unsupported CSS border radius ${radius}`);
171
+ const target = mask ??= frame.CreateMaskTexture();
172
+ const previous = maskRadius;
173
+ const next = scope.protect(() => applyMask(target, radius));
174
+ if (!next.ok || !next.value) {
175
+ if (previous !== undefined) scope.protect(() => applyMask(target, previous));
176
+ return next.ok ? fail(`Unsupported CSS border radius ${radius}`) : next;
177
+ }
178
+ if (!hasMaskAnchor) {
179
+ target.SetAllPoints(frame);
180
+ hasMaskAnchor = true;
181
+ }
182
+ for (const layer of layers) attach(layer, target);
183
+ maskRadius = radius;
184
+ return ok(undefined);
185
+ }
186
+
187
+ function nextPart(side: CssSide): SurfaceTexture {
188
+ const index = used[side]++;
189
+ const parts = edges[side] as OwnedArray<SurfaceTexture>;
190
+ let part = parts[index];
191
+ if (part === undefined) {
192
+ part = makeLayer("BORDER", -8, true);
193
+ parts.push(part);
194
+ }
195
+ part.texture.ClearAllPoints();
196
+ return part;
197
+ }
198
+
199
+ function band(side: CssSide, inset: number, start: Point, end: Point, first: number, last: number, horizontal: boolean) {
200
+ if (inset === 0) return;
201
+ const part = nextPart(side).texture;
202
+ part.SetPoint(start, frame, start, horizontal ? first : 0, horizontal ? 0 : -first);
203
+ part.SetPoint(end, frame, end, horizontal ? -last : 0, horizontal ? 0 : last);
204
+ if (horizontal) part.SetHeight(inset);
205
+ else part.SetWidth(inset);
206
+ }
207
+
208
+ function corner(point: Point, horizontal: CssSide, vertical: CssSide, height: number, width: number, radius: number) {
209
+ if (radius === 0 || (height === 0 && width === 0)) return;
210
+ const xSign = point === "TOPLEFT" || point === "BOTTOMLEFT" ? 1 : -1;
211
+ const ySign = point === "TOPLEFT" || point === "TOPRIGHT" ? -1 : 1;
212
+ const outerX = Math.max(radius, width);
213
+ const outerY = Math.max(radius, height);
214
+ const innerX = outerX - width;
215
+ const innerY = outerY - height;
216
+
217
+ function patch(side: CssSide, x: number, y: number, w: number, h: number) {
218
+ if (w <= 0 || h <= 0) return;
219
+ const part = nextPart(side).texture;
220
+ part.SetPoint(point, frame, point, x * xSign, y * ySign);
221
+ part.SetSize(w, h);
222
+ }
223
+
224
+ function paint(top: number, bottom: number, limit: number) {
225
+ const split = height === 0 ? limit : Math.min(limit, (top + bottom) * width / (2 * height));
226
+ patch(vertical, 0, top, split, bottom - top);
227
+ patch(horizontal, split, top, limit - split, bottom - top);
228
+ }
229
+
230
+ paint(0, height, outerX);
231
+ // The mask draws the outer arc. Sample the inner curve in a bounded number of strips so thin borders
232
+ // continue around the corner even when their thickness is smaller than the radius.
233
+ const strips = Math.min(5, Math.ceil(innerY));
234
+ for (let index = 0; index < strips; index++) {
235
+ const top = height + innerY * index / strips;
236
+ const bottom = height + innerY * (index + 1) / strips;
237
+ const progress = 1 - index / strips;
238
+ paint(top, bottom, outerX - innerX * Math.sqrt(1 - progress * progress));
239
+ }
240
+ }
241
+
242
+ function geometry(insets: Insets, radius: number) {
243
+ const [top, right, bottom, left] = insets;
244
+ const startX = radius > 0 ? Math.max(radius, left) : 0;
245
+ const endX = radius > 0 ? Math.max(radius, right) : 0;
246
+ const startY = Math.max(radius, top);
247
+ const endY = Math.max(radius, bottom);
248
+ for (const side of borderSides) used[side] = 0;
249
+ band("top", top, "TOPLEFT", "TOPRIGHT", startX, endX, true);
250
+ band("bottom", bottom, "BOTTOMLEFT", "BOTTOMRIGHT", startX, endX, true);
251
+ band("left", left, "TOPLEFT", "BOTTOMLEFT", startY, endY, false);
252
+ band("right", right, "TOPRIGHT", "BOTTOMRIGHT", startY, endY, false);
253
+ corner("TOPLEFT", "top", "left", top, left, radius);
254
+ corner("TOPRIGHT", "top", "right", top, right, radius);
255
+ corner("BOTTOMLEFT", "bottom", "left", bottom, left, radius);
256
+ corner("BOTTOMRIGHT", "bottom", "right", bottom, right, radius);
257
+ }
258
+
259
+ function setBorder(border?: CssBorder, radius = 0): Result<void> {
260
+ if (!scope.isActive()) return fail("CSS surface scope is disposed");
261
+ if (isSecret(radius) || !Number.isFinite(radius) || radius < 0) return fail("Invalid CSS border radius");
262
+ const read = readBorder(border, options.environment);
263
+ if (!read.ok) return read;
264
+ const { insets, colors } = read.value;
265
+ if (artwork !== undefined) {
266
+ const edge = colors.top;
267
+ if (border !== undefined && (!insets.every(amount => amount === 1) || edge === undefined
268
+ || !borderSides.every(side => colors[side]?.literal === edge.literal))) {
269
+ return fail("Native rounded art requires a uniform 1px CSS border");
270
+ }
271
+ const configured = scope.protect(() => {
272
+ const changed = artworkRadius !== radius;
273
+ if (changed && color !== undefined) artwork(color.texture, radius, false);
274
+ if (edge === undefined) {
275
+ if (outline !== undefined) shown(outline, false);
276
+ if (borderState !== undefined) borderState.drawn.top = undefined;
277
+ } else {
278
+ if (outline === undefined) {
279
+ outline = makeLayer("BORDER", -8, false);
280
+ outline.texture.SetAllPoints(frame);
281
+ }
282
+ if (changed || !outline.shown) artwork(outline.texture, radius, true);
283
+ const drawn = borderState === undefined ? undefined : borderState.drawn.top;
284
+ const [r, g, b, a] = drawn ?? edge.rgba;
285
+ tint(outline, r, g, b, a);
286
+ shown(outline, true);
287
+ }
288
+ artworkRadius = radius;
289
+ if (borderState !== undefined) borderState.base.value = colors;
290
+ });
291
+ return configured;
292
+ }
293
+ const configured = scope.protect(() => {
294
+ if (radius !== previousRadius || !sameInsets(previousInsets, insets)) {
295
+ const masked = setMask(radius > 0 ? radius : insets.some(value => value > 0) ? 0 : undefined);
296
+ if (!masked.ok) return masked;
297
+ geometry(insets, radius);
298
+ previousRadius = radius;
299
+ previousInsets = insets;
300
+ }
301
+ for (const side of borderSides) {
302
+ const base = colors[side];
303
+ if (base === undefined && borderState !== undefined) borderState.drawn[side] = undefined;
304
+ const drawn = base === undefined || borderState === undefined ? undefined : borderState.drawn[side];
305
+ const paint = drawn ?? base?.rgba;
306
+ const parts = edges[side] as OwnedArray<SurfaceTexture>;
307
+ for (let index = 0; index < parts.length; index++) {
308
+ const part = parts[index];
309
+ if (paint === undefined || index >= used[side]) shown(part, false);
310
+ else {
311
+ tint(part, paint[0], paint[1], paint[2], paint[3]);
312
+ shown(part, true);
313
+ }
314
+ }
315
+ }
316
+ if (borderState !== undefined) borderState.base.value = colors;
317
+ return ok(undefined);
318
+ });
319
+ return configured.ok ? configured.value : configured;
320
+ }
321
+
322
+ const borderPaint: CssSurface["borderPaint"] = borderState === undefined ? undefined : {
323
+ sides: artwork === undefined ? undefined : ["top"],
324
+ read: side => borderState.base.value[side]?.literal,
325
+ write(this: void, side, red, green, blue, alpha) {
326
+ if (!scope.isActive() || borderState.base.value[side] === undefined) return;
327
+ const drawn = borderState.drawn[side] ??= [red, green, blue, alpha];
328
+ drawn[0] = red;
329
+ drawn[1] = green;
330
+ drawn[2] = blue;
331
+ drawn[3] = alpha;
332
+ if (outline !== undefined) {
333
+ tint(outline, red, green, blue, alpha);
334
+ return;
335
+ }
336
+ const parts = edges[side] as OwnedArray<SurfaceTexture>;
337
+ for (let index = 0; index < used[side]; index++) tint(parts[index], red, green, blue, alpha);
338
+ },
339
+ };
340
+
341
+ let colorR: number | undefined, colorG: number | undefined, colorB: number | undefined, colorA: number | undefined;
342
+ function setBackgroundColor(r: number, g: number, b: number, a: number) {
343
+ if (!scope.isActive() || color === undefined || (r === colorR && g === colorG && b === colorB && a === colorA)) return;
344
+ color.texture.SetVertexColor(r, g, b, a);
345
+ shown(color, a > 0);
346
+ colorR = r;
347
+ colorG = g;
348
+ colorB = b;
349
+ colorA = a;
350
+ }
351
+
352
+ let path: string | undefined, atlas: string | undefined;
353
+ function setBackgroundImage(next?: BackgroundImage) {
354
+ if (!scope.isActive() || image === undefined) return;
355
+ const nextPath = next !== undefined && "path" in next ? next.path : undefined;
356
+ const nextAtlas = next !== undefined && "atlas" in next ? next.atlas : undefined;
357
+ if (path === nextPath && atlas === nextAtlas) return;
358
+ if (nextPath !== undefined) {
359
+ const local = nextPath.startsWith("./") ? nextPath.slice(2) : nextPath;
360
+ if (atlas !== undefined) image.texture.SetTexCoord(0, 1, 0, 1);
361
+ shown(image, image.texture.SetTexture(local.split("/").join("\\")) !== false);
362
+ } else if (nextAtlas !== undefined) {
363
+ image.texture.SetAtlas(nextAtlas, false);
364
+ shown(image, true);
365
+ } else shown(image, false);
366
+ path = nextPath;
367
+ atlas = nextAtlas;
368
+ }
369
+
370
+ function release() {
371
+ for (const layer of layers) {
372
+ shown(layer, false);
373
+ if (mask !== undefined) detach(layer, mask);
374
+ }
375
+ mask?.Hide();
376
+ }
377
+
378
+ const created = scope.protect(() => {
379
+ if (options.color === true) {
380
+ color = makeLayer("BACKGROUND", -8, artwork === undefined);
381
+ color.texture.SetAllPoints(frame);
382
+ }
383
+ if (options.image === true) {
384
+ image = makeLayer("BACKGROUND", -7, false);
385
+ image.texture.SetAllPoints(frame);
386
+ }
387
+ });
388
+ if (!created.ok) {
389
+ scope.protect(release);
390
+ return created;
391
+ }
392
+ const cleanup = scope.onDispose(release);
393
+ if (!cleanup.ok) {
394
+ scope.protect(release);
395
+ return cleanup;
396
+ }
397
+ return ok({ setBorder, borderPaint, setBackgroundColor, setBackgroundImage });
398
+ }