@margoengine/ui 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.
- package/LICENSE +201 -0
- package/NOTICE +4 -0
- package/README.md +708 -3
- package/dist/basic.d.ts +87 -0
- package/dist/collections.d.ts +180 -0
- package/dist/color.d.ts +24 -0
- package/dist/controls.d.ts +130 -0
- package/dist/curved.d.ts +41 -0
- package/dist/curved.js +105 -0
- package/dist/dom-CWJhpotq.js +340 -0
- package/dist/dom-host.d.ts +67 -0
- package/dist/dom-host.js +563 -0
- package/dist/dom-spec.d.ts +21 -0
- package/dist/dom.d.ts +63 -0
- package/dist/draw.d.ts +107 -0
- package/dist/editor.d.ts +83 -0
- package/dist/editor.js +323 -0
- package/dist/errors-CDgOgzCd.js +7 -0
- package/dist/focus.d.ts +12 -0
- package/dist/forms.d.ts +114 -0
- package/dist/forms.js +354 -0
- package/dist/gl-bb768Mje.js +165 -0
- package/dist/gl-load-wwKmojhb.js +5 -0
- package/dist/gl-load.d.ts +3 -0
- package/dist/gl.d.ts +30 -0
- package/dist/i18n.d.ts +69 -0
- package/dist/i18n.js +117 -0
- package/dist/image.d.ts +74 -0
- package/dist/image.js +295 -0
- package/dist/index.d.ts +36 -0
- package/dist/index.js +4 -0
- package/dist/input-dom.d.ts +14 -0
- package/dist/input.d.ts +92 -0
- package/dist/input.js +315 -0
- package/dist/interaction.d.ts +106 -0
- package/dist/keyboard.d.ts +40 -0
- package/dist/keyboard.js +132 -0
- package/dist/layout.d.ts +116 -0
- package/dist/markup.d.ts +89 -0
- package/dist/markup.js +369 -0
- package/dist/meters-yaZRtwsX.js +1401 -0
- package/dist/meters.d.ts +72 -0
- package/dist/mirror.d.ts +30 -0
- package/dist/overlays.d.ts +89 -0
- package/dist/painter.d.ts +115 -0
- package/dist/pass-CAn29pqc.js +15 -0
- package/dist/react.d.ts +99 -0
- package/dist/react.js +246 -0
- package/dist/renderer-Bdhc_0Cu.js +1653 -0
- package/dist/renderer.d.ts +92 -0
- package/dist/rsc/react.js +3 -0
- package/dist/shader.d.ts +6 -0
- package/dist/theme.d.ts +104 -0
- package/dist/ui.d.ts +328 -0
- package/dist/virtual.d.ts +81 -0
- package/dist/widget.d.ts +196 -0
- package/dist/world-gl.d.ts +32 -0
- package/dist/world-gl.js +195 -0
- package/dist/world.d.ts +216 -0
- package/dist/world.js +561 -0
- package/package.json +119 -6
package/dist/i18n.js
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { n as e, r as t } from "./errors-CDgOgzCd.js";
|
|
2
|
+
//#region src/i18n.ts
|
|
3
|
+
function n(t) {
|
|
4
|
+
try {
|
|
5
|
+
return new Intl.Locale(t).baseName;
|
|
6
|
+
} catch {
|
|
7
|
+
throw e("Locale must be a BCP 47 language tag such as en-US or ar; supply a valid tag", "ui");
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
var r = /* @__PURE__ */ new Set(/* @__PURE__ */ "Arab.Hebr.Syrc.Thaa.Nkoo.Adlm.Rohg.Samr.Mand.Armi.Avst.Chrs.Elym.Hatr.Hung.Khar.Lydi.Mani.Mend.Merc.Mero.Narb.Nbat.Orkh.Ougr.Palm.Phli.Phlp.Phnx.Prti.Sogd.Sogo.Yezi".split(".")), i = class {
|
|
11
|
+
constructor(e = {}, r = {}) {
|
|
12
|
+
this.tables = /* @__PURE__ */ new Map(), this.listeners = /* @__PURE__ */ new Set(), this.bindings = /* @__PURE__ */ new Set(), this.directions = /* @__PURE__ */ new Map();
|
|
13
|
+
let i = Object.keys(e)[0] ?? "en";
|
|
14
|
+
if (this.current = n(r.locale ?? i), this.fallback = n(r.fallback ?? i), this.missing = r.missing ?? "key", !["key", "error"].includes(this.missing)) throw t("missing must be key or error; select a missing-key policy", "ui");
|
|
15
|
+
for (let [e, i] of Object.entries(r.directions ?? {})) {
|
|
16
|
+
if (i !== "ltr" && i !== "rtl") throw t("Locale direction must be ltr or rtl; supply one of these values", "ui");
|
|
17
|
+
this.directions.set(n(e), i);
|
|
18
|
+
}
|
|
19
|
+
for (let [t, n] of Object.entries(e)) this.setTable(t, n);
|
|
20
|
+
}
|
|
21
|
+
get locale() {
|
|
22
|
+
return this.current;
|
|
23
|
+
}
|
|
24
|
+
set locale(e) {
|
|
25
|
+
let t = n(e);
|
|
26
|
+
t !== this.current && (this.current = t, this.refresh());
|
|
27
|
+
}
|
|
28
|
+
get direction() {
|
|
29
|
+
for (let e of this.parents(this.current)) {
|
|
30
|
+
let t = this.directions.get(e);
|
|
31
|
+
if (t) return t;
|
|
32
|
+
}
|
|
33
|
+
let e = new Intl.Locale(this.current);
|
|
34
|
+
return e.getTextInfo?.().direction ?? (r.has(e.maximize().script ?? "") ? "rtl" : "ltr");
|
|
35
|
+
}
|
|
36
|
+
setTable(e, r) {
|
|
37
|
+
let i = Object.create(null);
|
|
38
|
+
if (!r || typeof r != "object" || Array.isArray(r)) throw t("Locale table must map string keys to messages; pass an object", "ui");
|
|
39
|
+
for (let [e, n] of Object.entries(r)) if (typeof n == "string") i[e] = n;
|
|
40
|
+
else {
|
|
41
|
+
if (!n || typeof n.other != "string" || Object.entries(n).some(([e, t]) => typeof t != "string" || ![
|
|
42
|
+
"zero",
|
|
43
|
+
"one",
|
|
44
|
+
"two",
|
|
45
|
+
"few",
|
|
46
|
+
"many",
|
|
47
|
+
"other"
|
|
48
|
+
].includes(e) && !/^=-?\d+(?:\.\d+)?$/.test(e))) throw t("Plural messages need string forms and an other fallback; supply a valid message table", "ui");
|
|
49
|
+
i[e] = Object.freeze({ ...n });
|
|
50
|
+
}
|
|
51
|
+
this.tables.set(n(e), Object.freeze(i)), this.refresh();
|
|
52
|
+
}
|
|
53
|
+
parents(e) {
|
|
54
|
+
let t = [], n = e.split("-");
|
|
55
|
+
for (; n.length;) t.push(n.join("-")), n = n.slice(0, -1);
|
|
56
|
+
return t;
|
|
57
|
+
}
|
|
58
|
+
t(t, n = {}) {
|
|
59
|
+
let r, i = this.current;
|
|
60
|
+
for (let e of /* @__PURE__ */ new Set([...this.parents(this.current), ...this.parents(this.fallback)])) {
|
|
61
|
+
let n = this.tables.get(e);
|
|
62
|
+
if (n && Object.hasOwn(n, t)) {
|
|
63
|
+
r = n[t], i = e;
|
|
64
|
+
break;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
if (r === void 0) {
|
|
68
|
+
if (this.missing === "error") throw e(`Missing translation ${t}; add it to ${this.current} or ${this.fallback}`, "ui");
|
|
69
|
+
return t;
|
|
70
|
+
}
|
|
71
|
+
if (typeof r != "string") {
|
|
72
|
+
let a = n.count;
|
|
73
|
+
if (typeof a != "number" || !Number.isFinite(a)) throw e(`Plural translation ${t} needs a finite count parameter; pass {count: number}`, "ui");
|
|
74
|
+
r = r[`=${a}`] ?? r[new Intl.PluralRules(i).select(a)] ?? r.other;
|
|
75
|
+
}
|
|
76
|
+
return r.replace(/\{([\w.-]+)\}/g, (r, i) => {
|
|
77
|
+
if (Object.hasOwn(n, i)) return String(n[i]);
|
|
78
|
+
if (this.missing === "error") throw e(`Translation ${t} needs parameter ${i}; supply it in parameters`, "ui");
|
|
79
|
+
return r;
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
refresh() {
|
|
83
|
+
for (let e of this.listeners) e();
|
|
84
|
+
}
|
|
85
|
+
onChange(e) {
|
|
86
|
+
this.listeners.add(e);
|
|
87
|
+
let t = () => {
|
|
88
|
+
this.listeners.delete(e);
|
|
89
|
+
};
|
|
90
|
+
return Object.assign(t, { [Symbol.dispose ?? Symbol.for("Symbol.dispose")]: t });
|
|
91
|
+
}
|
|
92
|
+
bind(e, t, n = {}) {
|
|
93
|
+
n.signal?.throwIfAborted();
|
|
94
|
+
let r = () => {
|
|
95
|
+
let n = t.map((e) => this.t(e.key, typeof e.parameters == "function" ? e.parameters() : e.parameters));
|
|
96
|
+
e.direction = this.direction, t.forEach((e, t) => {
|
|
97
|
+
e.target[e.property ?? "text"] = n[t];
|
|
98
|
+
});
|
|
99
|
+
};
|
|
100
|
+
r();
|
|
101
|
+
let i = this.onChange(r), a = () => o();
|
|
102
|
+
n.signal?.addEventListener("abort", a, { once: !0 });
|
|
103
|
+
let o = () => {
|
|
104
|
+
i(), n.signal?.removeEventListener("abort", a), this.bindings.delete(o);
|
|
105
|
+
};
|
|
106
|
+
return this.bindings.add(o), Object.assign(o, { [Symbol.dispose ?? Symbol.for("Symbol.dispose")]: o });
|
|
107
|
+
}
|
|
108
|
+
dispose() {
|
|
109
|
+
for (let e of this.bindings) e();
|
|
110
|
+
this.listeners.clear();
|
|
111
|
+
}
|
|
112
|
+
[Symbol.dispose ?? Symbol.for("Symbol.dispose")]() {
|
|
113
|
+
this.dispose();
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
//#endregion
|
|
117
|
+
export { i as Localization };
|
package/dist/image.d.ts
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { Widget, type DrawContext, type WidgetOptions, type Rect, type Edges, type Rgba } from '@margoengine/ui';
|
|
2
|
+
/** Immutable straight-alpha sRGB pixels, shared by image widgets. */
|
|
3
|
+
export declare class ImageTexture {
|
|
4
|
+
/** Pixel width. */
|
|
5
|
+
readonly width: number;
|
|
6
|
+
/** Pixel height. */
|
|
7
|
+
readonly height: number;
|
|
8
|
+
private readonly pixels;
|
|
9
|
+
private readonly cells;
|
|
10
|
+
/** Copy width * height * 4 RGBA bytes. */
|
|
11
|
+
constructor(width: number, height: number, data: Uint8Array | Uint8ClampedArray);
|
|
12
|
+
/** Decode a URL with cancellation; caller retains ownership of any original image. */
|
|
13
|
+
static load(url: string | URL, options?: {
|
|
14
|
+
signal?: AbortSignal;
|
|
15
|
+
}): Promise<ImageTexture>;
|
|
16
|
+
/** Snapshot a decoded image, video frame or canvas using its natural pixel size. */
|
|
17
|
+
static from(source: CanvasImageSource): ImageTexture;
|
|
18
|
+
/** @internal Snapshot an atlas cell with clamped neighbor texels for bilinear filtering. */
|
|
19
|
+
tiles(cell: Rect): readonly ImageTile[];
|
|
20
|
+
}
|
|
21
|
+
interface ImageTile extends Rect {
|
|
22
|
+
bitmap: import('@margoengine/text').GlyphBitmap;
|
|
23
|
+
}
|
|
24
|
+
/** Options for an Image, including atlas cropping and fixed corner borders. */
|
|
25
|
+
export interface ImageOptions extends WidgetOptions {
|
|
26
|
+
/** Shared pixel texture. */
|
|
27
|
+
texture: ImageTexture;
|
|
28
|
+
/** Pixel rectangle within the texture. Default full image. */
|
|
29
|
+
source?: Rect;
|
|
30
|
+
/** Default contain. Cover crops the source; fill stretches it. */
|
|
31
|
+
fit?: 'contain' | 'cover' | 'fill';
|
|
32
|
+
/** Top, right, bottom, left source border pixels. Omit for ordinary images. */
|
|
33
|
+
slice?: Edges;
|
|
34
|
+
/** UI units per source border pixel. Default 1. */
|
|
35
|
+
borderScale?: number;
|
|
36
|
+
/** Straight sRGB tint. Default opaque white. */
|
|
37
|
+
tint?: Rgba;
|
|
38
|
+
}
|
|
39
|
+
/** Textured widget with atlas cells, fit modes and nine-slice borders. */
|
|
40
|
+
export declare class Image extends Widget {
|
|
41
|
+
private _texture;
|
|
42
|
+
private _source?;
|
|
43
|
+
private _fit;
|
|
44
|
+
private _slice?;
|
|
45
|
+
private _borderScale;
|
|
46
|
+
private _tint;
|
|
47
|
+
constructor({ texture, source, fit, slice, borderScale, tint, ...rest }: ImageOptions);
|
|
48
|
+
private validate;
|
|
49
|
+
private get cell();
|
|
50
|
+
/** Current immutable pixel texture. */
|
|
51
|
+
get texture(): ImageTexture;
|
|
52
|
+
set texture(v: ImageTexture);
|
|
53
|
+
/** Source atlas cell. Undefined selects the whole texture. */
|
|
54
|
+
get source(): Rect | undefined;
|
|
55
|
+
set source(v: Rect | undefined);
|
|
56
|
+
/** Image sizing mode. */
|
|
57
|
+
get fit(): 'contain' | 'cover' | 'fill';
|
|
58
|
+
set fit(v: 'contain' | 'cover' | 'fill');
|
|
59
|
+
/** Source border widths. */
|
|
60
|
+
get slice(): Edges | undefined;
|
|
61
|
+
set slice(v: Edges | undefined);
|
|
62
|
+
/** Border size in UI units per source pixel. */
|
|
63
|
+
get borderScale(): number;
|
|
64
|
+
set borderScale(v: number);
|
|
65
|
+
/** Multiplies texture RGBA. */
|
|
66
|
+
get tint(): Rgba;
|
|
67
|
+
set tint(v: Rgba);
|
|
68
|
+
measure(): {
|
|
69
|
+
width: number;
|
|
70
|
+
height: number;
|
|
71
|
+
};
|
|
72
|
+
draw({ list }: DrawContext): void;
|
|
73
|
+
}
|
|
74
|
+
export {};
|
package/dist/image.js
ADDED
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
import { n as e, r as t, t as n } from "./errors-CDgOgzCd.js";
|
|
2
|
+
import { Widget as r, edges as i } from "@margoengine/ui";
|
|
3
|
+
//#region src/image.ts
|
|
4
|
+
function a(e) {
|
|
5
|
+
if (e === void 0) return;
|
|
6
|
+
let [t, n, r, a] = i(e);
|
|
7
|
+
return [
|
|
8
|
+
t,
|
|
9
|
+
n,
|
|
10
|
+
r,
|
|
11
|
+
a
|
|
12
|
+
];
|
|
13
|
+
}
|
|
14
|
+
var o = class t {
|
|
15
|
+
constructor(t, n, r) {
|
|
16
|
+
if (this.cells = /* @__PURE__ */ new Map(), ![t, n].every((e) => Number.isSafeInteger(e) && e > 0) || r.length !== t * n * 4) throw e("ImageTexture needs positive integer dimensions and width * height * 4 RGBA bytes", "ui");
|
|
17
|
+
this.width = t, this.height = n, this.pixels = new Uint8Array(r);
|
|
18
|
+
}
|
|
19
|
+
static async load(e, r = {}) {
|
|
20
|
+
try {
|
|
21
|
+
let i = await fetch(e, { signal: r.signal });
|
|
22
|
+
if (!i.ok) throw n("failed", `Image load returned HTTP ${i.status}; use an accessible image URL`, "ui");
|
|
23
|
+
let a = await createImageBitmap(await i.blob());
|
|
24
|
+
try {
|
|
25
|
+
return r.signal?.throwIfAborted(), t.from(a);
|
|
26
|
+
} finally {
|
|
27
|
+
a.close();
|
|
28
|
+
}
|
|
29
|
+
} catch (e) {
|
|
30
|
+
throw r.signal?.aborted ? r.signal.reason : e instanceof Error && e.name === "MargoError" ? e : Object.assign(n("failed", "Could not decode the UI image; use a supported, CORS-accessible image URL in a browser", "ui"), { cause: e });
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
static from(n) {
|
|
34
|
+
let r = n, i = (e) => typeof e == "number" ? e : e?.baseVal.value ?? 0, a = r.naturalWidth ?? r.videoWidth ?? r.displayWidth ?? i(r.width), o = r.naturalHeight ?? r.videoHeight ?? r.displayHeight ?? i(r.height);
|
|
35
|
+
if (!(a > 0) || !(o > 0)) throw e("ImageTexture.from needs a decoded image or a video with a current frame", "ui");
|
|
36
|
+
let s = new OffscreenCanvas(a, o).getContext("2d");
|
|
37
|
+
return s.drawImage(n, 0, 0), new t(a, o, s.getImageData(0, 0, a, o).data);
|
|
38
|
+
}
|
|
39
|
+
tiles(e) {
|
|
40
|
+
let t = `${e.x},${e.y},${e.width},${e.height}`, n = this.cells.get(t);
|
|
41
|
+
if (n) return n;
|
|
42
|
+
let r = [];
|
|
43
|
+
for (let t = 0; t < e.height; t += 60) for (let n = 0; n < e.width; n += 60) {
|
|
44
|
+
let i = Math.min(60, e.width - n), a = Math.min(60, e.height - t), o = new Uint8Array((i + 2) * (a + 2) * 4);
|
|
45
|
+
for (let r = -1; r <= a; r++) for (let a = -1; a <= i; a++) {
|
|
46
|
+
let s = e.x + Math.max(0, Math.min(e.width - 1, n + a)), c = ((e.y + Math.max(0, Math.min(e.height - 1, t + r))) * this.width + s) * 4, l = ((r + 1) * (i + 2) + a + 1) * 4, u = this.pixels[c + 3];
|
|
47
|
+
for (let e = 0; e < 3; e++) o[l + e] = Math.round(this.pixels[c + e] * u / 255);
|
|
48
|
+
o[l + 3] = u;
|
|
49
|
+
}
|
|
50
|
+
r.push({
|
|
51
|
+
x: n,
|
|
52
|
+
y: t,
|
|
53
|
+
width: i,
|
|
54
|
+
height: a,
|
|
55
|
+
bitmap: {
|
|
56
|
+
cluster: "",
|
|
57
|
+
left: 0,
|
|
58
|
+
top: 0,
|
|
59
|
+
color: !0,
|
|
60
|
+
width: i + 2,
|
|
61
|
+
height: a + 2,
|
|
62
|
+
data: o
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
return this.cells.set(t, r), r;
|
|
67
|
+
}
|
|
68
|
+
}, s = class extends r {
|
|
69
|
+
constructor({ texture: e, source: t, fit: n = "contain", slice: r, borderScale: i = 1, tint: o = [
|
|
70
|
+
1,
|
|
71
|
+
1,
|
|
72
|
+
1,
|
|
73
|
+
1
|
|
74
|
+
], ...s }) {
|
|
75
|
+
super(s), this._texture = e, this._source = t && { ...t }, this._fit = n, this._slice = a(r), this._borderScale = i, this._tint = [...o], this.validate(), this.role = "img", this.pointerEvents = s.pointerEvents ?? "none";
|
|
76
|
+
}
|
|
77
|
+
validate() {
|
|
78
|
+
if (!(this._texture instanceof o)) throw t("Image needs an ImageTexture; load or create one first", "ui");
|
|
79
|
+
if (![
|
|
80
|
+
"contain",
|
|
81
|
+
"cover",
|
|
82
|
+
"fill"
|
|
83
|
+
].includes(this._fit)) throw t("Image fit must be contain, cover or fill", "ui");
|
|
84
|
+
let n = this.cell;
|
|
85
|
+
if (![
|
|
86
|
+
n.x,
|
|
87
|
+
n.y,
|
|
88
|
+
n.width,
|
|
89
|
+
n.height
|
|
90
|
+
].every(Number.isInteger) || n.x < 0 || n.y < 0 || n.width <= 0 || n.height <= 0 || n.x + n.width > this.texture.width || n.y + n.height > this.texture.height) throw e("Image source must be an integer pixel rectangle inside its texture", "ui");
|
|
91
|
+
if (!(this._borderScale >= 0) || !Number.isFinite(this._borderScale) || !this._tint || this._tint.length !== 4 || !this._tint.every((e) => Number.isFinite(e) && e >= 0 && e <= 1)) throw e("Image borderScale must be finite and nonnegative and tint must contain four values in [0,1]", "ui");
|
|
92
|
+
if (this._slice !== void 0) {
|
|
93
|
+
let [t, r, a, o] = i(this._slice);
|
|
94
|
+
if (![
|
|
95
|
+
t,
|
|
96
|
+
r,
|
|
97
|
+
a,
|
|
98
|
+
o
|
|
99
|
+
].every((e) => Number.isFinite(e) && e >= 0) || o + r > n.width || t + a > n.height) throw e("Image slice borders must be nonnegative and fit within the source rectangle", "ui");
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
get cell() {
|
|
103
|
+
return this._source ?? {
|
|
104
|
+
x: 0,
|
|
105
|
+
y: 0,
|
|
106
|
+
width: this.texture.width,
|
|
107
|
+
height: this.texture.height
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
get texture() {
|
|
111
|
+
return this._texture;
|
|
112
|
+
}
|
|
113
|
+
set texture(e) {
|
|
114
|
+
let t = this._texture;
|
|
115
|
+
this._texture = e;
|
|
116
|
+
try {
|
|
117
|
+
this.validate();
|
|
118
|
+
} catch (e) {
|
|
119
|
+
throw this._texture = t, e;
|
|
120
|
+
}
|
|
121
|
+
this.invalidate();
|
|
122
|
+
}
|
|
123
|
+
get source() {
|
|
124
|
+
return this._source && { ...this._source };
|
|
125
|
+
}
|
|
126
|
+
set source(e) {
|
|
127
|
+
let t = this._source;
|
|
128
|
+
this._source = e && { ...e };
|
|
129
|
+
try {
|
|
130
|
+
this.validate();
|
|
131
|
+
} catch (e) {
|
|
132
|
+
throw this._source = t, e;
|
|
133
|
+
}
|
|
134
|
+
this.invalidate();
|
|
135
|
+
}
|
|
136
|
+
get fit() {
|
|
137
|
+
return this._fit;
|
|
138
|
+
}
|
|
139
|
+
set fit(e) {
|
|
140
|
+
let t = this._fit;
|
|
141
|
+
this._fit = e;
|
|
142
|
+
try {
|
|
143
|
+
this.validate();
|
|
144
|
+
} catch (e) {
|
|
145
|
+
throw this._fit = t, e;
|
|
146
|
+
}
|
|
147
|
+
this.invalidate(!1);
|
|
148
|
+
}
|
|
149
|
+
get slice() {
|
|
150
|
+
return a(this._slice);
|
|
151
|
+
}
|
|
152
|
+
set slice(e) {
|
|
153
|
+
let t = this._slice;
|
|
154
|
+
this._slice = a(e);
|
|
155
|
+
try {
|
|
156
|
+
this.validate();
|
|
157
|
+
} catch (e) {
|
|
158
|
+
throw this._slice = t, e;
|
|
159
|
+
}
|
|
160
|
+
this.invalidate(!1);
|
|
161
|
+
}
|
|
162
|
+
get borderScale() {
|
|
163
|
+
return this._borderScale;
|
|
164
|
+
}
|
|
165
|
+
set borderScale(e) {
|
|
166
|
+
let t = this._borderScale;
|
|
167
|
+
this._borderScale = e;
|
|
168
|
+
try {
|
|
169
|
+
this.validate();
|
|
170
|
+
} catch (e) {
|
|
171
|
+
throw this._borderScale = t, e;
|
|
172
|
+
}
|
|
173
|
+
this.invalidate(!1);
|
|
174
|
+
}
|
|
175
|
+
get tint() {
|
|
176
|
+
return [...this._tint];
|
|
177
|
+
}
|
|
178
|
+
set tint(e) {
|
|
179
|
+
let t = this._tint;
|
|
180
|
+
this._tint = [...e];
|
|
181
|
+
try {
|
|
182
|
+
this.validate();
|
|
183
|
+
} catch (e) {
|
|
184
|
+
throw this._tint = t, e;
|
|
185
|
+
}
|
|
186
|
+
this.invalidate(!1);
|
|
187
|
+
}
|
|
188
|
+
measure() {
|
|
189
|
+
return {
|
|
190
|
+
width: this.cell.width,
|
|
191
|
+
height: this.cell.height
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
draw({ list: e }) {
|
|
195
|
+
let [t, n, r, a] = i(this.style.padding), o = {
|
|
196
|
+
x: this.rect.x + a,
|
|
197
|
+
y: this.rect.y + t,
|
|
198
|
+
width: Math.max(0, this.rect.width - a - n),
|
|
199
|
+
height: Math.max(0, this.rect.height - t - r)
|
|
200
|
+
}, s = this.cell;
|
|
201
|
+
if (!o.width || !o.height) return;
|
|
202
|
+
let c = [];
|
|
203
|
+
if (this.slice !== void 0) {
|
|
204
|
+
let [e, t, n, r] = i(this.slice), a = Math.min(this.borderScale, o.width / (r + t || 1), o.height / (e + n || 1)), l = [
|
|
205
|
+
0,
|
|
206
|
+
r,
|
|
207
|
+
s.width - t,
|
|
208
|
+
s.width
|
|
209
|
+
], u = [
|
|
210
|
+
0,
|
|
211
|
+
e,
|
|
212
|
+
s.height - n,
|
|
213
|
+
s.height
|
|
214
|
+
], d = [
|
|
215
|
+
o.x,
|
|
216
|
+
o.x + r * a,
|
|
217
|
+
o.x + o.width - t * a,
|
|
218
|
+
o.x + o.width
|
|
219
|
+
], f = [
|
|
220
|
+
o.y,
|
|
221
|
+
o.y + e * a,
|
|
222
|
+
o.y + o.height - n * a,
|
|
223
|
+
o.y + o.height
|
|
224
|
+
];
|
|
225
|
+
for (let e = 0; e < 3; e++) for (let t = 0; t < 3; t++) c.push({
|
|
226
|
+
src: {
|
|
227
|
+
x: l[t],
|
|
228
|
+
y: u[e],
|
|
229
|
+
width: l[t + 1] - l[t],
|
|
230
|
+
height: u[e + 1] - u[e]
|
|
231
|
+
},
|
|
232
|
+
dst: {
|
|
233
|
+
x: d[t],
|
|
234
|
+
y: f[e],
|
|
235
|
+
width: d[t + 1] - d[t],
|
|
236
|
+
height: f[e + 1] - f[e]
|
|
237
|
+
}
|
|
238
|
+
});
|
|
239
|
+
} else {
|
|
240
|
+
let e = {
|
|
241
|
+
x: 0,
|
|
242
|
+
y: 0,
|
|
243
|
+
width: s.width,
|
|
244
|
+
height: s.height
|
|
245
|
+
}, t = { ...o };
|
|
246
|
+
if (this.fit !== "fill") {
|
|
247
|
+
let n = (this.fit === "contain" ? Math.min : Math.max)(o.width / s.width, o.height / s.height);
|
|
248
|
+
this.fit === "contain" ? t = {
|
|
249
|
+
x: o.x + (o.width - s.width * n) / 2,
|
|
250
|
+
y: o.y + (o.height - s.height * n) / 2,
|
|
251
|
+
width: s.width * n,
|
|
252
|
+
height: s.height * n
|
|
253
|
+
} : e = {
|
|
254
|
+
x: (s.width - o.width / n) / 2,
|
|
255
|
+
y: (s.height - o.height / n) / 2,
|
|
256
|
+
width: o.width / n,
|
|
257
|
+
height: o.height / n
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
c.push({
|
|
261
|
+
src: e,
|
|
262
|
+
dst: t
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
e.pushClip(o.x, o.y, o.width, o.height);
|
|
266
|
+
for (let { src: t, dst: n } of c) if (!(t.width <= 0 || t.height <= 0 || n.width <= 0 || n.height <= 0)) for (let r of this.texture.tiles(s)) {
|
|
267
|
+
let i = Math.max(t.x, r.x), a = Math.max(t.y, r.y), o = Math.min(t.x + t.width, r.x + r.width), s = Math.min(t.y + t.height, r.y + r.height);
|
|
268
|
+
if (o <= i || s <= a) continue;
|
|
269
|
+
let c = n.width / t.width, l = n.height / t.height, u = e.scale;
|
|
270
|
+
e.commands.push({
|
|
271
|
+
type: "image",
|
|
272
|
+
bitmap: r.bitmap,
|
|
273
|
+
x: (n.x + (i - t.x) * c) * u,
|
|
274
|
+
y: (n.y + (a - t.y) * l) * u,
|
|
275
|
+
width: (o - i) * c * u,
|
|
276
|
+
height: (s - a) * l * u,
|
|
277
|
+
source: {
|
|
278
|
+
x: i - r.x + 1,
|
|
279
|
+
y: a - r.y + 1,
|
|
280
|
+
width: o - i,
|
|
281
|
+
height: s - a
|
|
282
|
+
},
|
|
283
|
+
color: [
|
|
284
|
+
this._tint[0],
|
|
285
|
+
this._tint[1],
|
|
286
|
+
this._tint[2],
|
|
287
|
+
this._tint[3] * e.alpha
|
|
288
|
+
]
|
|
289
|
+
});
|
|
290
|
+
}
|
|
291
|
+
e.popClip();
|
|
292
|
+
}
|
|
293
|
+
};
|
|
294
|
+
//#endregion
|
|
295
|
+
export { s as Image, o as ImageTexture };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export { Ui, resolutionScale, readSafeArea, browserTextScale } from './ui.js';
|
|
2
|
+
export type { UiOptions, ScaleOptions, SafeArea, UiDirection } from './ui.js';
|
|
3
|
+
export { UiRenderer } from './renderer.js';
|
|
4
|
+
export { attachInput } from './dom.js';
|
|
5
|
+
export { attachMirror } from './mirror.js';
|
|
6
|
+
export { describeWidget, SKIP as WIDGET_SKIP } from './dom-spec.js';
|
|
7
|
+
export { handleKeyDown } from './dom.js';
|
|
8
|
+
export type { MirrorOptions } from './mirror.js';
|
|
9
|
+
export type { AttachOptions, Detach } from './dom.js';
|
|
10
|
+
export { uiActions, UI_ACTIONS } from './interaction.js';
|
|
11
|
+
export type { InputSource, PointerInfo, UiActionOptions } from './interaction.js';
|
|
12
|
+
export { moveFocus } from './focus.js';
|
|
13
|
+
export type { Direction } from './focus.js';
|
|
14
|
+
export type { UiRendererOptions } from './renderer.js';
|
|
15
|
+
export { DrawList } from './draw.js';
|
|
16
|
+
export type { DrawCommand, ImageCommand, RectCommand, TextCommand, ClipCommand, UnclipCommand, RectStyle, } from './draw.js';
|
|
17
|
+
export { arrange, edges, translate, validateStyle } from './layout.js';
|
|
18
|
+
export type { LayoutStyle, LayoutNode, Rect, Size, Edges, Align, Justify, Anchor } from './layout.js';
|
|
19
|
+
export { Widget } from './widget.js';
|
|
20
|
+
export type { WidgetOptions, UiEvent, UiHandler, Unsubscribe, UiCommand, DrawContext, ColorRef } from './widget.js';
|
|
21
|
+
export { Panel, Label } from './basic.js';
|
|
22
|
+
export type { PanelOptions, PanelBackground, LabelOptions, TextSize } from './basic.js';
|
|
23
|
+
export { Button, Toggle, Slider } from './controls.js';
|
|
24
|
+
export type { ButtonOptions, ButtonVariant, ToggleOptions, SliderOptions } from './controls.js';
|
|
25
|
+
export { ProgressBar, HealthBar } from './meters.js';
|
|
26
|
+
export type { ProgressBarOptions, HealthBarOptions, MeterVariant } from './meters.js';
|
|
27
|
+
export { List, Inventory, Menu } from './collections.js';
|
|
28
|
+
export { VirtualList } from './virtual.js';
|
|
29
|
+
export type { VirtualListOptions } from './virtual.js';
|
|
30
|
+
export type { ListOptions, ListEntry, InventoryOptions, InventoryItem, MenuOptions, MenuItem } from './collections.js';
|
|
31
|
+
export { Dialog, Toast, Tooltip } from './overlays.js';
|
|
32
|
+
export type { DialogOptions, DialogButton, ToastOptions, ToastKind } from './overlays.js';
|
|
33
|
+
export { themes, createTheme, themeForPreferences } from './theme.js';
|
|
34
|
+
export type { Theme, ThemeColors, ThemeOverrides } from './theme.js';
|
|
35
|
+
export { parseRgba, contrastRatio, luminance, mixColors, withAlpha, simulateColorBlindness, colorDifference, } from './color.js';
|
|
36
|
+
export type { Rgba, ColorBlindness } from './color.js';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { C as e, S as t, _ as n, b as r, c as i, d as a, f as o, g as s, h as c, i as l, l as u, m as d, n as f, o as p, p as m, r as h, s as g, t as _, u as v, v as y, x as b, y as x } from "./meters-yaZRtwsX.js";
|
|
2
|
+
import { _ as S, a as C, c as w, d as T, f as E, g as D, h as O, i as k, l as A, m as j, n as M, o as N, p as P, r as F, s as I, t as L, u as R, v as z, y as B } from "./renderer-Bdhc_0Cu.js";
|
|
3
|
+
import { i as V, t as H } from "./dom-CWJhpotq.js";
|
|
4
|
+
export { g as Button, O as Dialog, B as DrawList, _ as HealthBar, h as Inventory, n as Label, l as List, p as Menu, y as Panel, f as ProgressBar, i as Slider, D as Toast, u as Toggle, S as Tooltip, P as UI_ACTIONS, N as Ui, L as UiRenderer, C as VirtualList, F as WIDGET_SKIP, x as Widget, r as arrange, H as attachInput, M as attachMirror, I as browserTextScale, v as colorDifference, a as contrastRatio, R as createTheme, k as describeWidget, b as edges, V as handleKeyDown, o as luminance, m as mixColors, z as moveFocus, d as parseRgba, w as readSafeArea, A as resolutionScale, c as simulateColorBlindness, T as themeForPreferences, E as themes, t as translate, j as uiActions, e as validateStyle, s as withAlpha };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type Detach, type Ui } from '@margoengine/ui';
|
|
2
|
+
/** DOM ownership and lifetime for attachTextInputs. */
|
|
3
|
+
export interface TextInputMirrorOptions {
|
|
4
|
+
/** Parent for the invisible accessible controls. Default canvas parent. */
|
|
5
|
+
container?: HTMLElement;
|
|
6
|
+
/** Remove controls and listeners when aborted. */
|
|
7
|
+
signal?: AbortSignal;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Attach once per Ui next to its canvas. Real input/textarea elements own clipboard,
|
|
11
|
+
* undo, selection, mobile keyboards and IME; the canvas paints their value and caret.
|
|
12
|
+
* Controls remain in the accessibility tree, with no duplicate password text nodes.
|
|
13
|
+
*/
|
|
14
|
+
export declare function attachTextInputs(ui: Ui, target: HTMLElement, options?: TextInputMirrorOptions): Detach;
|
package/dist/input.d.ts
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/// <reference lib="esnext.disposable" preserve="true" />
|
|
2
|
+
import { Widget, type DrawContext, type UiCommand, type UiEvent, type WidgetOptions } from '@margoengine/ui';
|
|
3
|
+
import { attachTextInputs } from './input-dom.js';
|
|
4
|
+
export { attachTextInputs };
|
|
5
|
+
export type { TextInputMirrorOptions } from './input-dom.js';
|
|
6
|
+
/** Options shared by single-line, password and multiline fields. */
|
|
7
|
+
export interface TextInputOptions extends WidgetOptions {
|
|
8
|
+
/** Initial text. Default ''. Programmatic changes do not emit change. */
|
|
9
|
+
value?: string;
|
|
10
|
+
/** Hint shown only while empty. Default ''. */
|
|
11
|
+
placeholder?: string;
|
|
12
|
+
/** Default 'text'. Passwords draw one bullet per grapheme. */
|
|
13
|
+
type?: 'text' | 'password';
|
|
14
|
+
/** Default false. Read-only text can still be selected and copied. */
|
|
15
|
+
readOnly?: boolean;
|
|
16
|
+
/** Native UTF-16 user-input limit; default unlimited. */
|
|
17
|
+
maxLength?: number;
|
|
18
|
+
/** Native autofill hint. Default 'off'. */
|
|
19
|
+
autocomplete?: string;
|
|
20
|
+
/** Native spellchecking. Default true, false for passwords. */
|
|
21
|
+
spellcheck?: boolean;
|
|
22
|
+
/** Default false. Mirrored as aria-required. */
|
|
23
|
+
required?: boolean;
|
|
24
|
+
/** Default false. Mirrored as aria-invalid. */
|
|
25
|
+
invalid?: boolean;
|
|
26
|
+
/** Called for user edits (including IME updates). */
|
|
27
|
+
onChange?: (event: UiEvent) => void;
|
|
28
|
+
/** Single-line Enter, outside composition. */
|
|
29
|
+
onSubmit?: (event: UiEvent) => void;
|
|
30
|
+
}
|
|
31
|
+
/** A canvas text field backed by a native input through attachTextInputs. */
|
|
32
|
+
export declare class TextInput extends Widget {
|
|
33
|
+
readonly multiline: boolean;
|
|
34
|
+
readonly type: 'text' | 'password';
|
|
35
|
+
readonly maxLength: number;
|
|
36
|
+
readonly autocomplete: string;
|
|
37
|
+
readonly spellcheck: boolean;
|
|
38
|
+
readonly required: boolean;
|
|
39
|
+
readonly invalid: boolean;
|
|
40
|
+
private _value;
|
|
41
|
+
private _placeholder;
|
|
42
|
+
private _readOnly;
|
|
43
|
+
private start;
|
|
44
|
+
private end;
|
|
45
|
+
private direction;
|
|
46
|
+
private anchor;
|
|
47
|
+
private blink;
|
|
48
|
+
private offsetX;
|
|
49
|
+
private offsetY;
|
|
50
|
+
private clicks;
|
|
51
|
+
private clickAge;
|
|
52
|
+
/** True between native compositionstart and compositionend. */
|
|
53
|
+
composing: boolean;
|
|
54
|
+
constructor(options?: TextInputOptions);
|
|
55
|
+
protected normalize(value: string): string;
|
|
56
|
+
get value(): string;
|
|
57
|
+
set value(value: string);
|
|
58
|
+
get placeholder(): string;
|
|
59
|
+
set placeholder(value: string);
|
|
60
|
+
get readOnly(): boolean;
|
|
61
|
+
set readOnly(value: boolean);
|
|
62
|
+
get selectionStart(): number;
|
|
63
|
+
get selectionEnd(): number;
|
|
64
|
+
get selectionDirection(): 'forward' | 'backward' | 'none';
|
|
65
|
+
/** HTML-compatible UTF-16 selection; reversed bounds collapse at end. */
|
|
66
|
+
setSelectionRange(start: number, end?: number, direction?: 'forward' | 'backward' | 'none'): void;
|
|
67
|
+
select(): void;
|
|
68
|
+
/** Replace selection from a virtual keyboard or application. Native edits use the browser's undo stack. */
|
|
69
|
+
insertText(text: string): void;
|
|
70
|
+
/** @internal Mirror an edit already performed by the native control. */
|
|
71
|
+
edit(value: string, start: number, end: number, direction: 'forward' | 'backward' | 'none'): void;
|
|
72
|
+
measure(): {
|
|
73
|
+
width: number;
|
|
74
|
+
height: number;
|
|
75
|
+
};
|
|
76
|
+
private display;
|
|
77
|
+
private geometry;
|
|
78
|
+
private indexAt;
|
|
79
|
+
pointerDown(x: number, y: number): boolean;
|
|
80
|
+
pointerMove(x: number, y: number): void;
|
|
81
|
+
command(command: UiCommand): boolean;
|
|
82
|
+
activate(): void;
|
|
83
|
+
tick(dt: number): boolean;
|
|
84
|
+
draw(context: DrawContext): void;
|
|
85
|
+
private drawSelection;
|
|
86
|
+
}
|
|
87
|
+
/** Multiline field with wrapping, native navigation and an independently scrolling caret. */
|
|
88
|
+
export declare class TextArea extends TextInput {
|
|
89
|
+
readonly multiline = true;
|
|
90
|
+
constructor(options?: Omit<TextInputOptions, 'type'>);
|
|
91
|
+
protected normalize(value: string): string;
|
|
92
|
+
}
|