@debuffjp/core 0.9.0 → 0.9.1
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/dist/render/backend.d.ts +48 -0
- package/dist/render/backend.d.ts.map +1 -0
- package/dist/render/backend.js +2 -0
- package/dist/render/backend.js.map +1 -0
- package/dist/render/bitmap-font.d.ts +55 -0
- package/dist/render/bitmap-font.d.ts.map +1 -0
- package/dist/render/bitmap-font.js +103 -0
- package/dist/render/bitmap-font.js.map +1 -0
- package/dist/render/canvas2d.d.ts +30 -0
- package/dist/render/canvas2d.d.ts.map +1 -0
- package/dist/render/canvas2d.js +128 -0
- package/dist/render/canvas2d.js.map +1 -0
- package/dist/render/color.d.ts +7 -0
- package/dist/render/color.d.ts.map +1 -0
- package/dist/render/color.js +49 -0
- package/dist/render/color.js.map +1 -0
- package/dist/render/draw.d.ts +125 -0
- package/dist/render/draw.d.ts.map +1 -0
- package/dist/render/draw.js +426 -0
- package/dist/render/draw.js.map +1 -0
- package/dist/render/webgl2.d.ts +46 -0
- package/dist/render/webgl2.d.ts.map +1 -0
- package/dist/render/webgl2.js +312 -0
- package/dist/render/webgl2.js.map +1 -0
- package/package.json +2 -2
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/** 2D affine matrix `[a, b, c, d, e, f]`: x' = a·x + c·y + e, y' = b·x + d·y + f (Canvas order). */
|
|
2
|
+
export type Matrix = [number, number, number, number, number, number];
|
|
3
|
+
export type BlendMode = "normal" | "add";
|
|
4
|
+
export interface ClipRect {
|
|
5
|
+
x: number;
|
|
6
|
+
y: number;
|
|
7
|
+
w: number;
|
|
8
|
+
h: number;
|
|
9
|
+
}
|
|
10
|
+
/** Raw access for advanced users. The backends are not interchangeable at this level. */
|
|
11
|
+
export type RawContext = {
|
|
12
|
+
kind: "webgl2";
|
|
13
|
+
gl: WebGL2RenderingContext;
|
|
14
|
+
} | {
|
|
15
|
+
kind: "2d";
|
|
16
|
+
ctx: CanvasRenderingContext2D;
|
|
17
|
+
};
|
|
18
|
+
/** Image sources the renderer can draw. Textures are cached per source object. */
|
|
19
|
+
export type TextureSource = HTMLImageElement | HTMLCanvasElement | OffscreenCanvas | ImageBitmap;
|
|
20
|
+
/**
|
|
21
|
+
* What a rendering backend implements. Everything is expressed as quads: a transform that maps the
|
|
22
|
+
* unit square onto logical space, an optional source rectangle, and an RGBA colour (tint).
|
|
23
|
+
* @internal
|
|
24
|
+
*/
|
|
25
|
+
export interface Backend {
|
|
26
|
+
readonly kind: "webgl2" | "2d";
|
|
27
|
+
readonly raw: RawContext;
|
|
28
|
+
/** GPU draw calls submitted so far this frame, where the backend batches (WebGL2). */
|
|
29
|
+
readonly drawCalls?: number;
|
|
30
|
+
/** Begin a frame: clear to `clear` (0xRRGGBBAA) at the given logical size and backing scale. */
|
|
31
|
+
begin(clear: number, width: number, height: number, scale: number): void;
|
|
32
|
+
/**
|
|
33
|
+
* Draw the unit square transformed by `m`. `src` null draws solid `color`.
|
|
34
|
+
* `sx, sy, sw, sh` is the source rect in source pixels (ignored when `src` is null). `flash` (0..1) mixes the texture toward white.
|
|
35
|
+
* `smooth` selects linear filtering for this source.
|
|
36
|
+
*/
|
|
37
|
+
quad(m: Matrix, src: TextureSource | null, sx: number, sy: number, sw: number, sh: number, color: number, flash: number, smooth: boolean): void;
|
|
38
|
+
setBlend(mode: BlendMode): void;
|
|
39
|
+
/** Restrict drawing to a rectangle in backing-store pixels (top-left origin), or remove the clip. */
|
|
40
|
+
setClip(rect: ClipRect | null): void;
|
|
41
|
+
/** Submit everything queued this frame. */
|
|
42
|
+
end(): void;
|
|
43
|
+
resize(backingWidth: number, backingHeight: number): void;
|
|
44
|
+
/** Drop cached GPU data for a source whose pixels changed. */
|
|
45
|
+
invalidate(src: TextureSource): void;
|
|
46
|
+
dispose(): void;
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=backend.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"backend.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EAAE,MAAM,EACb,MAAM,EAAE,OAAO,GACd,IAAI,CAAC;IACR,QAAQ,CAAC,IAAI,EAAE,SAAS,GAAG,IAAI,CAAC;IAChC,qGAAqG;IACrG,OAAO,CAAC,IAAI,EAAE,QAAQ,GAAG,IAAI,GAAG,IAAI,CAAC;IACrC,2CAA2C;IAC3C,GAAG,IAAI,IAAI,CAAC;IACZ,MAAM,CAAC,YAAY,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1D,8DAA8D;IAC9D,UAAU,CAAC,GAAG,EAAE,aAAa,GAAG,IAAI,CAAC;IACrC,OAAO,IAAI,IAAI,CAAC;CACjB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"backend.js","sourceRoot":"","sources":["../../src/render/backend.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { Frame } from "./draw.js";
|
|
2
|
+
export interface BitmapFontOptions {
|
|
3
|
+
/** One frame per glyph, in the order of `chars`: usually `assets.frames("font")` from a `font@WxH.png` grid. */
|
|
4
|
+
frames: readonly Frame[];
|
|
5
|
+
/** The characters the frames hold, in order. */
|
|
6
|
+
chars: string;
|
|
7
|
+
/**
|
|
8
|
+
* Advance per glyph in pixels. Default: measured from each glyph's rightmost opaque column, so a
|
|
9
|
+
* grid drawn in Aseprite becomes a proportional font. Pass a number for a monospaced font.
|
|
10
|
+
*/
|
|
11
|
+
widths?: readonly number[] | number;
|
|
12
|
+
/** Pixels between glyphs. Default 1. */
|
|
13
|
+
spacing?: number;
|
|
14
|
+
/** Advance for a space (and any glyph that measures empty). Default a third of the cell height, rounded. */
|
|
15
|
+
spaceWidth?: number;
|
|
16
|
+
/** Pixels from one line's top to the next. Default the cell height + 1. */
|
|
17
|
+
lineHeight?: number;
|
|
18
|
+
/** Drawn for characters the font lacks. Default "?" if present, else nothing. */
|
|
19
|
+
fallback?: string;
|
|
20
|
+
}
|
|
21
|
+
export interface Glyph {
|
|
22
|
+
frame: Frame;
|
|
23
|
+
/** Pixels to advance after drawing, before spacing. */
|
|
24
|
+
advance: number;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* A pixel font from a sprite sheet. Pass it as `font` to `draw.text` and `draw.measure`: glyphs land
|
|
28
|
+
* on whole pixels, so it stays crisp at any integer scale.
|
|
29
|
+
*
|
|
30
|
+
* ```ts
|
|
31
|
+
* // assets/font@6x9.png: glyphs on a 6×9 grid, exported from Aseprite
|
|
32
|
+
* const font = new BitmapFont({ frames: assets.frames("font"), chars: BitmapFont.ASCII });
|
|
33
|
+
* draw.text("coins 3", 4, 4, { font, color: "#fbbf24" });
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export declare class BitmapFont {
|
|
37
|
+
/** Printable ASCII from space to "~", the order most font sheets use. */
|
|
38
|
+
static readonly ASCII: string;
|
|
39
|
+
/** Cell height in pixels. */
|
|
40
|
+
readonly height: number;
|
|
41
|
+
readonly lineHeight: number;
|
|
42
|
+
readonly spacing: number;
|
|
43
|
+
private readonly glyphs;
|
|
44
|
+
private readonly fallback;
|
|
45
|
+
constructor(o: BitmapFontOptions);
|
|
46
|
+
glyph(ch: string): Glyph | undefined;
|
|
47
|
+
/** Size of `text` in pixels. Lines split on "\n". */
|
|
48
|
+
measure(text: string): {
|
|
49
|
+
w: number;
|
|
50
|
+
h: number;
|
|
51
|
+
};
|
|
52
|
+
/** Width of one line, without trailing spacing. */
|
|
53
|
+
lineWidth(line: string): number;
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=bitmap-font.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bitmap-font.d.ts","sourceRoot":"","sources":["../../src/render/bitmap-font.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AAEvC,MAAM,WAAW,iBAAiB;IAChC,gHAAgH;IAChH,MAAM,EAAE,SAAS,KAAK,EAAE,CAAC;IACzB,gDAAgD;IAChD,KAAK,EAAE,MAAM,CAAC;IACd;;;OAGG;IACH,MAAM,CAAC,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,CAAC;IACpC,wCAAwC;IACxC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,4GAA4G;IAC5G,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,2EAA2E;IAC3E,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,iFAAiF;IACjF,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,KAAK;IACpB,KAAK,EAAE,KAAK,CAAC;IACb,uDAAuD;IACvD,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;;;;;;;;GASG;AACH,qBAAa,UAAU;IACrB,yEAAyE;IACzE,MAAM,CAAC,QAAQ,CAAC,KAAK,SAA8E;IAEnG,6BAA6B;IAC7B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAA4B;IACnD,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAoB;IAE7C,YAAY,CAAC,EAAE,iBAAiB,EAiB/B;IAED,KAAK,CAAC,EAAE,EAAE,MAAM,GAAG,KAAK,GAAG,SAAS,CAEnC;IAED,qDAAqD;IACrD,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG;QAAE,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAA;KAAE,CAM9C;IAED,mDAAmD;IACnD,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAU9B;CACF"}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A pixel font from a sprite sheet. Pass it as `font` to `draw.text` and `draw.measure`: glyphs land
|
|
3
|
+
* on whole pixels, so it stays crisp at any integer scale.
|
|
4
|
+
*
|
|
5
|
+
* ```ts
|
|
6
|
+
* // assets/font@6x9.png: glyphs on a 6×9 grid, exported from Aseprite
|
|
7
|
+
* const font = new BitmapFont({ frames: assets.frames("font"), chars: BitmapFont.ASCII });
|
|
8
|
+
* draw.text("coins 3", 4, 4, { font, color: "#fbbf24" });
|
|
9
|
+
* ```
|
|
10
|
+
*/
|
|
11
|
+
export class BitmapFont {
|
|
12
|
+
/** Printable ASCII from space to "~", the order most font sheets use. */
|
|
13
|
+
static ASCII = Array.from({ length: 95 }, (_, i) => String.fromCharCode(32 + i)).join("");
|
|
14
|
+
/** Cell height in pixels. */
|
|
15
|
+
height;
|
|
16
|
+
lineHeight;
|
|
17
|
+
spacing;
|
|
18
|
+
glyphs = new Map();
|
|
19
|
+
fallback;
|
|
20
|
+
constructor(o) {
|
|
21
|
+
const first = o.frames[0];
|
|
22
|
+
if (!first)
|
|
23
|
+
throw new Error("BitmapFont needs at least one frame");
|
|
24
|
+
const chars = [...o.chars];
|
|
25
|
+
if (chars.length > o.frames.length)
|
|
26
|
+
throw new Error(`BitmapFont has ${chars.length} chars but only ${o.frames.length} frames; check the grid size in the file name`);
|
|
27
|
+
this.height = first.h;
|
|
28
|
+
this.lineHeight = o.lineHeight ?? first.h + 1;
|
|
29
|
+
this.spacing = o.spacing ?? 1;
|
|
30
|
+
const space = o.spaceWidth ?? Math.max(1, Math.round(first.h / 3));
|
|
31
|
+
const measured = o.widths === undefined ? measureWidths(o.frames.slice(0, chars.length)) : undefined;
|
|
32
|
+
chars.forEach((ch, i) => {
|
|
33
|
+
const frame = o.frames[i];
|
|
34
|
+
const w = typeof o.widths === "number" ? o.widths : (o.widths?.[i] ?? measured?.[i] ?? frame.w);
|
|
35
|
+
this.glyphs.set(ch, { frame, advance: w > 0 ? w : space });
|
|
36
|
+
});
|
|
37
|
+
this.fallback = this.glyphs.get(o.fallback ?? "?");
|
|
38
|
+
}
|
|
39
|
+
glyph(ch) {
|
|
40
|
+
return this.glyphs.get(ch) ?? this.fallback;
|
|
41
|
+
}
|
|
42
|
+
/** Size of `text` in pixels. Lines split on "\n". */
|
|
43
|
+
measure(text) {
|
|
44
|
+
if (!text)
|
|
45
|
+
return { w: 0, h: 0 };
|
|
46
|
+
const lines = text.split("\n");
|
|
47
|
+
let w = 0;
|
|
48
|
+
for (const line of lines)
|
|
49
|
+
w = Math.max(w, this.lineWidth(line));
|
|
50
|
+
return { w, h: (lines.length - 1) * this.lineHeight + this.height };
|
|
51
|
+
}
|
|
52
|
+
/** Width of one line, without trailing spacing. */
|
|
53
|
+
lineWidth(line) {
|
|
54
|
+
let w = 0;
|
|
55
|
+
let n = 0;
|
|
56
|
+
for (const ch of line) {
|
|
57
|
+
const g = this.glyph(ch);
|
|
58
|
+
if (!g)
|
|
59
|
+
continue;
|
|
60
|
+
w += g.advance;
|
|
61
|
+
n++;
|
|
62
|
+
}
|
|
63
|
+
return n ? w + (n - 1) * this.spacing : 0;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
/** Rightmost opaque column + 1 for each frame; 0 for empty ones. Falls back to the frame width without a 2D canvas. */
|
|
67
|
+
function measureWidths(frames) {
|
|
68
|
+
const cache = new Map();
|
|
69
|
+
return frames.map((f) => {
|
|
70
|
+
let img = cache.get(f.image);
|
|
71
|
+
if (img === undefined) {
|
|
72
|
+
img = readPixels(f.image);
|
|
73
|
+
cache.set(f.image, img);
|
|
74
|
+
}
|
|
75
|
+
if (!img)
|
|
76
|
+
return f.w;
|
|
77
|
+
for (let x = f.w - 1; x >= 0; x--)
|
|
78
|
+
for (let y = 0; y < f.h; y++)
|
|
79
|
+
if ((img.data[((f.y + y) * img.width + f.x + x) * 4 + 3] ?? 0) > 0)
|
|
80
|
+
return x + 1;
|
|
81
|
+
return 0;
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
function readPixels(src) {
|
|
85
|
+
const w = "naturalWidth" in src ? src.naturalWidth : src.width;
|
|
86
|
+
const h = "naturalHeight" in src ? src.naturalHeight : src.height;
|
|
87
|
+
if (!w || !h)
|
|
88
|
+
return null;
|
|
89
|
+
try {
|
|
90
|
+
const canvas = typeof OffscreenCanvas !== "undefined" ? new OffscreenCanvas(w, h) : document.createElement("canvas");
|
|
91
|
+
canvas.width = w;
|
|
92
|
+
canvas.height = h;
|
|
93
|
+
const ctx = canvas.getContext("2d");
|
|
94
|
+
if (!ctx)
|
|
95
|
+
return null;
|
|
96
|
+
ctx.drawImage(src, 0, 0);
|
|
97
|
+
return { data: ctx.getImageData(0, 0, w, h).data, width: w };
|
|
98
|
+
}
|
|
99
|
+
catch {
|
|
100
|
+
return null;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
//# sourceMappingURL=bitmap-font.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bitmap-font.js","sourceRoot":"","sources":["../../src/render/bitmap-font.ts"],"names":[],"mappings":"AA4BA;;;;;;;;;GASG;AACH,MAAM,OAAO,UAAU;IACrB,yEAAyE;IACzE,MAAM,CAAU,KAAK,GAAG,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,YAAY,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAEnG,6BAA6B;IACpB,MAAM,CAAS;IACf,UAAU,CAAS;IACnB,OAAO,CAAS;IACR,MAAM,GAAG,IAAI,GAAG,EAAiB,CAAC;IAClC,QAAQ,CAAoB;IAE7C,YAAY,CAAoB;QAC9B,MAAM,KAAK,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;QAC1B,IAAI,CAAC,KAAK;YAAE,MAAM,IAAI,KAAK,CAAC,qCAAqC,CAAC,CAAC;QACnE,MAAM,KAAK,GAAG,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC;QAC3B,IAAI,KAAK,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F,MAAM,CAAC,GAAG,eAAe,IAAI,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC,CAAE,GAA0B,CAAC,MAAM,CAAC;IAC1F,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC;QAAE,OAAO,IAAI,CAAC;IAC1B,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,OAAO,eAAe,KAAK,WAAW,CAAC,CAAC,CAAC,IAAI,eAAe,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;QACrH,MAAM,CAAC,KAAK,GAAG,CAAC,CAAC;QACjB,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC;QAClB,MAAM,GAAG,GAAG,MAAM,CAAC,UAAU,CAAC,IAAI,CAAoC,CAAC;QACvE,IAAI,CAAC,GAAG;YAAE,OAAO,IAAI,CAAC;QACtB,GAAG,CAAC,SAAS,CAAC,GAAwB,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;QAC9C,OAAO,EAAE,IAAI,EAAE,GAAG,CAAC,YAAY,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC;IAC/D,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { Backend, BlendMode, ClipRect, Matrix, RawContext, TextureSource } from "./backend.js";
|
|
2
|
+
/**
|
|
3
|
+
* Canvas 2D fallback for the `draw` API. Same output for solid shapes, sprites, text and alpha.
|
|
4
|
+
* Canvas 2D has no per-draw tint, so tinted textures (text, bitmap fonts, `tint`) go through a scratch
|
|
5
|
+
* canvas: slower than WebGL2, but only when a tint other than white is asked for.
|
|
6
|
+
*/
|
|
7
|
+
export declare class Canvas2DBackend implements Backend {
|
|
8
|
+
readonly kind: "2d";
|
|
9
|
+
readonly raw: RawContext;
|
|
10
|
+
private readonly ctx;
|
|
11
|
+
private scale;
|
|
12
|
+
private smoothing;
|
|
13
|
+
private scratch;
|
|
14
|
+
private clipped;
|
|
15
|
+
private blendMode;
|
|
16
|
+
constructor(ctx: CanvasRenderingContext2D);
|
|
17
|
+
begin(clear: number, width: number, height: number, scale: number): void;
|
|
18
|
+
quad(m: Matrix, src: TextureSource | null, sx: number, sy: number, sw: number, sh: number, color: number, flash: number, smooth: boolean): void;
|
|
19
|
+
setBlend(mode: BlendMode): void;
|
|
20
|
+
setClip(rect: ClipRect | null): void;
|
|
21
|
+
end(): void;
|
|
22
|
+
resize(): void;
|
|
23
|
+
invalidate(): void;
|
|
24
|
+
dispose(): void;
|
|
25
|
+
/** The source region multiplied by `color`'s RGB, keeping the source's alpha. */
|
|
26
|
+
private tinted;
|
|
27
|
+
private scratchCanvas;
|
|
28
|
+
private whiteSilhouette;
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=canvas2d.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"canvas2d.d.ts","sourceRoot":"","sources":["../../src/render/canvas2d.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAGpG;;;;GAIG;AACH,qBAAa,eAAgB,YAAW,OAAO;IAC7C,QAAQ,CAAC,IAAI,EAAG,IAAI,CAAU;IAC9B,QAAQ,CAAC,GAAG,EAAE,UAAU,CAAC;IACzB,OAAO,CAAC,QAAQ,CAAC,GAAG,CAA2B;IAC/C,OAAO,CAAC,KAAK,CAAK;IAClB,OAAO,CAAC,SAAS,CAAsB;IACvC,OAAO,CAAC,OAAO,CAAkD;IACjE,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,SAAS,CAAuB;IAExC,YAAY,GAAG,EAAE,wBAAwB,EAGxC;IAED,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAQvE;IAED,IAAI,CACF,CAAC,EAAE,MAAM,EACT,GAAG,EAAE,aAAa,GAAG,IAAI,EACzB,EAAE,EAAE,MAAM,EACV,EAAE,EAAE,MAAM,EACV,EAAE,EAAE,MAAM,EACV,EAAE,EAAE,MAAM,EACV,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,OAAO,GACd,IAAI,CAqBN;IAED,QAAQ,CAAC,IAAI,EAAE,SAAS,GAAG,IAAI,CAG9B;IAED,OAAO,CAAC,IAAI,EAAE,QAAQ,GAAG,IAAI,GAAG,IAAI,CAenC;IAED,GAAG,IAAI,IAAI,CAIV;IAED,MAAM,IAAI,IAAI,CAGb;IAED,UAAU,IAAI,IAAI,CAEjB;IAED,OAAO,IAAI,IAAI,CAAG;IAElB,iFAAiF;IACjF,OAAO,CAAC,MAAM;IAiBd,OAAO,CAAC,aAAa;IAOrB,OAAO,CAAC,eAAe;CAYxB"}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { rgbaToCss } from "./color.js";
|
|
2
|
+
/**
|
|
3
|
+
* Canvas 2D fallback for the `draw` API. Same output for solid shapes, sprites, text and alpha.
|
|
4
|
+
* Canvas 2D has no per-draw tint, so tinted textures (text, bitmap fonts, `tint`) go through a scratch
|
|
5
|
+
* canvas: slower than WebGL2, but only when a tint other than white is asked for.
|
|
6
|
+
*/
|
|
7
|
+
export class Canvas2DBackend {
|
|
8
|
+
kind = "2d";
|
|
9
|
+
raw;
|
|
10
|
+
ctx;
|
|
11
|
+
scale = 1;
|
|
12
|
+
smoothing;
|
|
13
|
+
scratch;
|
|
14
|
+
clipped = false;
|
|
15
|
+
blendMode = "normal";
|
|
16
|
+
constructor(ctx) {
|
|
17
|
+
this.ctx = ctx;
|
|
18
|
+
this.raw = { kind: "2d", ctx };
|
|
19
|
+
}
|
|
20
|
+
begin(clear, width, height, scale) {
|
|
21
|
+
this.scale = scale;
|
|
22
|
+
const ctx = this.ctx;
|
|
23
|
+
ctx.setTransform(scale, 0, 0, scale, 0, 0);
|
|
24
|
+
ctx.globalAlpha = 1;
|
|
25
|
+
ctx.globalCompositeOperation = "source-over";
|
|
26
|
+
ctx.fillStyle = rgbaToCss(clear);
|
|
27
|
+
ctx.fillRect(0, 0, width, height);
|
|
28
|
+
}
|
|
29
|
+
quad(m, src, sx, sy, sw, sh, color, flash, smooth) {
|
|
30
|
+
const ctx = this.ctx;
|
|
31
|
+
const s = this.scale;
|
|
32
|
+
ctx.setTransform(m[0] * s, m[1] * s, m[2] * s, m[3] * s, m[4] * s, m[5] * s);
|
|
33
|
+
if (!src) {
|
|
34
|
+
ctx.globalAlpha = 1;
|
|
35
|
+
ctx.fillStyle = rgbaToCss(color);
|
|
36
|
+
ctx.fillRect(0, 0, 1, 1);
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
if (this.smoothing !== smooth) {
|
|
40
|
+
ctx.imageSmoothingEnabled = smooth;
|
|
41
|
+
this.smoothing = smooth;
|
|
42
|
+
}
|
|
43
|
+
ctx.globalAlpha = (color & 0xff) / 255;
|
|
44
|
+
if (color >>> 8 === 0xffffff)
|
|
45
|
+
ctx.drawImage(src, sx, sy, sw, sh, 0, 0, 1, 1);
|
|
46
|
+
else
|
|
47
|
+
ctx.drawImage(this.tinted(src, sx, sy, sw, sh, color), 0, 0, sw, sh, 0, 0, 1, 1);
|
|
48
|
+
if (flash > 0) {
|
|
49
|
+
ctx.globalAlpha *= Math.min(1, flash);
|
|
50
|
+
ctx.drawImage(this.whiteSilhouette(src, sx, sy, sw, sh), 0, 0, sw, sh, 0, 0, 1, 1);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
setBlend(mode) {
|
|
54
|
+
this.blendMode = mode;
|
|
55
|
+
this.ctx.globalCompositeOperation = mode === "add" ? "lighter" : "source-over";
|
|
56
|
+
}
|
|
57
|
+
setClip(rect) {
|
|
58
|
+
const ctx = this.ctx;
|
|
59
|
+
// Canvas clips only shrink, so each change restores to the unclipped state first.
|
|
60
|
+
if (this.clipped) {
|
|
61
|
+
ctx.restore();
|
|
62
|
+
this.clipped = false;
|
|
63
|
+
this.setBlend(this.blendMode);
|
|
64
|
+
}
|
|
65
|
+
if (!rect)
|
|
66
|
+
return;
|
|
67
|
+
ctx.save();
|
|
68
|
+
ctx.setTransform(1, 0, 0, 1, 0, 0);
|
|
69
|
+
ctx.beginPath();
|
|
70
|
+
ctx.rect(rect.x, rect.y, rect.w, rect.h);
|
|
71
|
+
ctx.clip();
|
|
72
|
+
this.clipped = true;
|
|
73
|
+
}
|
|
74
|
+
end() {
|
|
75
|
+
this.setClip(null);
|
|
76
|
+
this.ctx.setTransform(1, 0, 0, 1, 0, 0);
|
|
77
|
+
this.ctx.globalAlpha = 1;
|
|
78
|
+
}
|
|
79
|
+
resize() {
|
|
80
|
+
// Canvas resize resets context state; it's reapplied in begin().
|
|
81
|
+
this.smoothing = undefined;
|
|
82
|
+
}
|
|
83
|
+
invalidate() {
|
|
84
|
+
// Canvas 2D reads sources directly; nothing is cached.
|
|
85
|
+
}
|
|
86
|
+
dispose() { }
|
|
87
|
+
/** The source region multiplied by `color`'s RGB, keeping the source's alpha. */
|
|
88
|
+
tinted(src, x, y, w, h, color) {
|
|
89
|
+
const scratch = this.scratchCanvas(w, h);
|
|
90
|
+
const sctx = scratch.getContext("2d");
|
|
91
|
+
if (!sctx)
|
|
92
|
+
return scratch;
|
|
93
|
+
sctx.clearRect(0, 0, w, h);
|
|
94
|
+
sctx.globalCompositeOperation = "source-over";
|
|
95
|
+
sctx.drawImage(src, x, y, w, h, 0, 0, w, h);
|
|
96
|
+
sctx.globalCompositeOperation = "multiply";
|
|
97
|
+
sctx.fillStyle = rgbaToCss(color | 0xff);
|
|
98
|
+
sctx.fillRect(0, 0, w, h);
|
|
99
|
+
// multiply filled the transparent pixels too; cut back to the source's shape.
|
|
100
|
+
sctx.globalCompositeOperation = "destination-in";
|
|
101
|
+
sctx.drawImage(src, x, y, w, h, 0, 0, w, h);
|
|
102
|
+
sctx.globalCompositeOperation = "source-over";
|
|
103
|
+
return scratch;
|
|
104
|
+
}
|
|
105
|
+
scratchCanvas(w, h) {
|
|
106
|
+
if (!this.scratch)
|
|
107
|
+
this.scratch = typeof OffscreenCanvas !== "undefined" ? new OffscreenCanvas(w, h) : document.createElement("canvas");
|
|
108
|
+
if (this.scratch.width < w)
|
|
109
|
+
this.scratch.width = w;
|
|
110
|
+
if (this.scratch.height < h)
|
|
111
|
+
this.scratch.height = h;
|
|
112
|
+
return this.scratch;
|
|
113
|
+
}
|
|
114
|
+
whiteSilhouette(src, x, y, w, h) {
|
|
115
|
+
const scratch = this.scratchCanvas(w, h);
|
|
116
|
+
const sctx = scratch.getContext("2d");
|
|
117
|
+
if (!sctx)
|
|
118
|
+
return scratch;
|
|
119
|
+
sctx.clearRect(0, 0, w, h);
|
|
120
|
+
sctx.globalCompositeOperation = "source-over";
|
|
121
|
+
sctx.drawImage(src, x, y, w, h, 0, 0, w, h);
|
|
122
|
+
sctx.globalCompositeOperation = "source-in";
|
|
123
|
+
sctx.fillStyle = "#fff";
|
|
124
|
+
sctx.fillRect(0, 0, w, h);
|
|
125
|
+
return scratch;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
//# sourceMappingURL=canvas2d.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"canvas2d.js","sourceRoot":"","sources":["../../src/render/canvas2d.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEvC;;;;GAIG;AACH,MAAM,OAAO,eAAe;IACjB,IAAI,GAAG,IAAa,CAAC;IACrB,GAAG,CAAa;IACR,GAAG,CAA2B;IACvC,KAAK,GAAG,CAAC,CAAC;IACV,SAAS,CAAsB;IAC/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@@
|
|
|
1
|
+
/** A colour: CSS hex string (`#rgb`, `#rgba`, `#rrggbb`, `#rrggbbaa`) or a number `0xRRGGBBAA`. */
|
|
2
|
+
export type Color = string | number;
|
|
3
|
+
/** Normalise a colour to `0xRRGGBBAA` (unsigned). Hex strings are cached; other CSS colours resolve through the browser. */
|
|
4
|
+
export declare function toRGBA(color: Color): number;
|
|
5
|
+
/** `0xRRGGBBAA` to a CSS colour string. */
|
|
6
|
+
export declare function rgbaToCss(rgba: number, alphaScale?: number): string;
|
|
7
|
+
//# sourceMappingURL=color.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"color.d.ts","sourceRoot":"","sources":["../../src/render/color.ts"],"names":[],"mappings":"AAAA,mGAAmG;AACnG,MAAM,MAAM,KAAK,GAAG,MAAM,GAAG,MAAM,CAAC;AAIpC,4HAA4H;AAC5H,wBAAgB,MAAM,CAAC,KAAK,EAAE,KAAK,GAAG,MAAM,CAQ3C;AA8BD,2CAA2C;AAC3C,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,SAAI,GAAG,MAAM,CAG9D"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
const cache = new Map();
|
|
2
|
+
/** Normalise a colour to `0xRRGGBBAA` (unsigned). Hex strings are cached; other CSS colours resolve through the browser. */
|
|
3
|
+
export function toRGBA(color) {
|
|
4
|
+
if (typeof color === "number")
|
|
5
|
+
return color >>> 0;
|
|
6
|
+
const hit = cache.get(color);
|
|
7
|
+
if (hit !== undefined)
|
|
8
|
+
return hit;
|
|
9
|
+
const value = parse(color);
|
|
10
|
+
if (cache.size > 512)
|
|
11
|
+
cache.clear();
|
|
12
|
+
cache.set(color, value);
|
|
13
|
+
return value;
|
|
14
|
+
}
|
|
15
|
+
function parse(input) {
|
|
16
|
+
let hex = input.trim();
|
|
17
|
+
if (hex.startsWith("#")) {
|
|
18
|
+
hex = hex.slice(1);
|
|
19
|
+
if (hex.length === 3 || hex.length === 4)
|
|
20
|
+
hex = [...hex].map((c) => c + c).join("");
|
|
21
|
+
if (hex.length === 6)
|
|
22
|
+
hex += "ff";
|
|
23
|
+
if (hex.length === 8 && /^[0-9a-f]{8}$/i.test(hex))
|
|
24
|
+
return Number.parseInt(hex, 16) >>> 0;
|
|
25
|
+
}
|
|
26
|
+
return parseCss(input);
|
|
27
|
+
}
|
|
28
|
+
let probe;
|
|
29
|
+
/** Any other CSS colour (named, rgb(), hsl()…): let the browser resolve it once. */
|
|
30
|
+
function parseCss(input) {
|
|
31
|
+
if (probe === undefined) {
|
|
32
|
+
const canvas = typeof OffscreenCanvas !== "undefined" ? new OffscreenCanvas(1, 1) : document.createElement("canvas");
|
|
33
|
+
probe = canvas.getContext("2d", { willReadFrequently: true });
|
|
34
|
+
}
|
|
35
|
+
if (!probe)
|
|
36
|
+
throw new Error(`Cannot parse colour "${input}" without a 2D canvas; use hex`);
|
|
37
|
+
probe.clearRect(0, 0, 1, 1);
|
|
38
|
+
probe.fillStyle = "#000";
|
|
39
|
+
probe.fillStyle = input;
|
|
40
|
+
probe.fillRect(0, 0, 1, 1);
|
|
41
|
+
const [r = 0, g = 0, b = 0, a = 0] = probe.getImageData(0, 0, 1, 1).data;
|
|
42
|
+
return ((r << 24) | (g << 16) | (b << 8) | a) >>> 0;
|
|
43
|
+
}
|
|
44
|
+
/** `0xRRGGBBAA` to a CSS colour string. */
|
|
45
|
+
export function rgbaToCss(rgba, alphaScale = 1) {
|
|
46
|
+
const a = ((rgba & 0xff) / 255) * alphaScale;
|
|
47
|
+
return `rgba(${rgba >>> 24},${(rgba >>> 16) & 0xff},${(rgba >>> 8) & 0xff},${a})`;
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=color.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"color.js","sourceRoot":"","sources":["../../src/render/color.ts"],"names":[],"mappings":"AAGA,MAAM,KAAK,GAAG,IAAI,GAAG,EAAkB,CAAC;AAExC,4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AAG,GAAG,CAAC,GAAG,UAAU,CAAC;IAC7C,OAAO,QAAQ,IAAI,KAAK,EAAE,IAAI,CAAC,IAAI,KAAK,EAAE,CAAC,GAAG,IAAI,IAAI,CAAC,IAAI,KAAK,CAAC,CAAC,GAAG,IAAI,IAAI,CAAC,GAAG,CAAC;AACpF,CAAC"}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import type { Backend, BlendMode, Matrix, RawContext, TextureSource } from "./backend.js";
|
|
2
|
+
import type { BitmapFont } from "./bitmap-font.js";
|
|
3
|
+
import { type Color } from "./color.js";
|
|
4
|
+
/** A rectangular region of an image, in source pixels. */
|
|
5
|
+
export interface Frame {
|
|
6
|
+
image: TextureSource;
|
|
7
|
+
x: number;
|
|
8
|
+
y: number;
|
|
9
|
+
w: number;
|
|
10
|
+
h: number;
|
|
11
|
+
}
|
|
12
|
+
export interface SpriteDrawOptions {
|
|
13
|
+
/** Anchor as a fraction of the frame size. Default [0.5, 0.5] (centre). */
|
|
14
|
+
origin?: readonly [number, number];
|
|
15
|
+
scaleX?: number;
|
|
16
|
+
scaleY?: number;
|
|
17
|
+
/** Radians. */
|
|
18
|
+
rotation?: number;
|
|
19
|
+
flipX?: boolean;
|
|
20
|
+
flipY?: boolean;
|
|
21
|
+
/** Multiplied with the global alpha. */
|
|
22
|
+
alpha?: number;
|
|
23
|
+
/** Colour multiplier. Default white. */
|
|
24
|
+
tint?: Color;
|
|
25
|
+
/** 0..1 mix toward white, e.g. hit flashes. */
|
|
26
|
+
flash?: number;
|
|
27
|
+
/** Linear filtering for this sprite. Default: the game's setting (off when `pixelArt`). */
|
|
28
|
+
smooth?: boolean;
|
|
29
|
+
}
|
|
30
|
+
export interface TextDrawOptions {
|
|
31
|
+
/** A `BitmapFont`, or a CSS font such as "16px monospace". Default: debuff sans, the built-in pixel font. */
|
|
32
|
+
font?: string | BitmapFont | undefined;
|
|
33
|
+
color?: Color;
|
|
34
|
+
align?: "left" | "center" | "right";
|
|
35
|
+
baseline?: "top" | "middle" | "bottom";
|
|
36
|
+
alpha?: number;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Immediate-mode drawing in logical units, the same API on WebGL2 and Canvas 2D (ADR 0007).
|
|
40
|
+
* Everything batches automatically; call order is draw order.
|
|
41
|
+
*/
|
|
42
|
+
export declare class Draw {
|
|
43
|
+
private backend;
|
|
44
|
+
/** Default filtering for images (false for pixel art). */
|
|
45
|
+
smooth: boolean;
|
|
46
|
+
/** Global alpha multiplier for subsequent draws. */
|
|
47
|
+
alpha: number;
|
|
48
|
+
/** Quads (sprites, rects, glyph runs…) submitted this frame. Reset each frame; for diagnostics. */
|
|
49
|
+
quads: number;
|
|
50
|
+
/** Preallocated transform stack: push/pop copy six numbers and never allocate. */
|
|
51
|
+
private readonly stack;
|
|
52
|
+
private depth;
|
|
53
|
+
private readonly m;
|
|
54
|
+
private readonly frames;
|
|
55
|
+
private readonly clips;
|
|
56
|
+
private readonly tmp;
|
|
57
|
+
private readonly textCache;
|
|
58
|
+
private circleTexture;
|
|
59
|
+
private backingW;
|
|
60
|
+
private backingH;
|
|
61
|
+
/** @internal */
|
|
62
|
+
constructor(backend: Backend,
|
|
63
|
+
/** Default filtering for images (false for pixel art). */
|
|
64
|
+
smooth: boolean);
|
|
65
|
+
/** Which backend is active. */
|
|
66
|
+
get kind(): "webgl2" | "2d";
|
|
67
|
+
/** Draw calls this frame: batched GPU calls on WebGL2, one per quad on Canvas 2D. */
|
|
68
|
+
get drawCalls(): number;
|
|
69
|
+
/** Raw `WebGL2RenderingContext` or `CanvasRenderingContext2D`. Mixing raw calls with `draw` calls requires care. */
|
|
70
|
+
get raw(): RawContext;
|
|
71
|
+
push(): void;
|
|
72
|
+
pop(): void;
|
|
73
|
+
translate(x: number, y: number): void;
|
|
74
|
+
scale(x: number, y?: number): void;
|
|
75
|
+
rotate(radians: number): void;
|
|
76
|
+
/**
|
|
77
|
+
* Run `fn` with drawing restricted to a rectangle (in current units), then restore. Nested clips
|
|
78
|
+
* intersect. Clips are axis-aligned on screen: under rotation the rectangle's screen bounds are used.
|
|
79
|
+
*/
|
|
80
|
+
clip(x: number, y: number, w: number, h: number, fn: () => void): void;
|
|
81
|
+
/** Run `fn` with the camera's view applied, then restore. */
|
|
82
|
+
withCamera(camera: {
|
|
83
|
+
view(): Matrix;
|
|
84
|
+
}, fn: () => void): void;
|
|
85
|
+
blend(mode: BlendMode): void;
|
|
86
|
+
rect(x: number, y: number, w: number, h: number, color: Color): void;
|
|
87
|
+
/** Filled circle (antialiased). */
|
|
88
|
+
circle(x: number, y: number, radius: number, color: Color): void;
|
|
89
|
+
line(x1: number, y1: number, x2: number, y2: number, width: number, color: Color): void;
|
|
90
|
+
/** Draw an image frame (or a whole image) at `x, y`, anchored by `origin`. Allocation-free hot path. */
|
|
91
|
+
sprite(frame: Frame | TextureSource, x: number, y: number, o?: SpriteDrawOptions): void;
|
|
92
|
+
/** Text, rasterised once and cached as a texture (crisp at the current render scale). */
|
|
93
|
+
text(text: string, x: number, y: number, o?: TextDrawOptions): void;
|
|
94
|
+
/**
|
|
95
|
+
* The logical box `text()` fills for this string and font, so layouts can align and centre without
|
|
96
|
+
* guessing. Same cache as `text()`, so measuring then drawing rasterises once.
|
|
97
|
+
*/
|
|
98
|
+
measure(text: string, font?: string | BitmapFont): {
|
|
99
|
+
w: number;
|
|
100
|
+
h: number;
|
|
101
|
+
};
|
|
102
|
+
private bitmapText;
|
|
103
|
+
/** Re-upload a source whose pixels changed (e.g. a canvas you draw into). */
|
|
104
|
+
invalidate(src: TextureSource): void;
|
|
105
|
+
/** @internal */
|
|
106
|
+
renderScale: number;
|
|
107
|
+
/** @internal */
|
|
108
|
+
begin(clear: Color, width: number, height: number, scale: number): void;
|
|
109
|
+
/** @internal Reset transform and blend between scene and afterRender hooks. */
|
|
110
|
+
reset(): void;
|
|
111
|
+
/** @internal */
|
|
112
|
+
end(): void;
|
|
113
|
+
/** @internal Release GPU resources and listeners. */
|
|
114
|
+
dispose(): void;
|
|
115
|
+
/** @internal */
|
|
116
|
+
resize(w: number, h: number): void;
|
|
117
|
+
/** @internal Switch to a backend that finished loading (the Canvas 2D fallback), at the current size. */
|
|
118
|
+
setBackend(backend: Backend): void;
|
|
119
|
+
/** tmp = current matrix × (translate(x, y) · scale(w, h)): maps the unit square to the rect. */
|
|
120
|
+
private local;
|
|
121
|
+
private wholeImage;
|
|
122
|
+
private withAlpha;
|
|
123
|
+
private circle64;
|
|
124
|
+
}
|
|
125
|
+
//# sourceMappingURL=draw.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"draw.d.ts","sourceRoot":"","sources":["../../src/render/draw.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,SAAS,EAAY,MAAM,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AACpG,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,EAAE,KAAK,KAAK,EAAU,MAAM,YAAY,CAAC;AAGhD,0DAA0D;AAC1D,MAAM,WAAW,KAAK;IACpB,KAAK,EAAE,aAAa,CAAC;IACrB,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;CACX;AAED,MAAM,WAAW,iBAAiB;IAChC,2EAA2E;IAC3E,MAAM,CAAC,EAAE,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACnC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,eAAe;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,wCAAwC;IACxC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,wCAAwC;IACxC,IAAI,CAAC,EAAE,KAAK,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