ranuts 0.4.0-alpha.2 → 0.4.0-alpha.3

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 (43) hide show
  1. package/CLAUDE.md +40 -4
  2. package/README.md +11 -16
  3. package/README.zh-CN.md +11 -16
  4. package/dist/{color-Bh_QUad2.js → color-DPV7TsVU.js} +1 -1
  5. package/dist/i18n-Bq-f7htr.js +1 -0
  6. package/dist/index.js +1 -1
  7. package/dist/src/node/index.js +1 -1
  8. package/dist/src/utils/async.d.ts +30 -0
  9. package/dist/src/utils/behavior.d.ts +0 -14
  10. package/dist/src/utils/bom.d.ts +2 -22
  11. package/dist/src/utils/color.d.ts +75 -0
  12. package/dist/src/utils/device.d.ts +0 -1
  13. package/dist/src/utils/dom.d.ts +5 -2
  14. package/dist/src/utils/event.d.ts +34 -0
  15. package/dist/src/utils/i18n/index.js +1 -1
  16. package/dist/src/utils/index.d.ts +16 -13
  17. package/dist/src/utils/index.js +1 -1
  18. package/dist/src/utils/number.d.ts +60 -0
  19. package/dist/src/utils/obj.d.ts +0 -11
  20. package/dist/src/utils/placement.d.ts +40 -0
  21. package/dist/src/utils/str.d.ts +0 -8
  22. package/dist/src/utils/time.d.ts +33 -1
  23. package/dist/src/utils/visual/application.d.ts +10 -0
  24. package/dist/src/utils/visual/index.d.ts +5 -2
  25. package/dist/src/utils/visual/index.js +1 -1
  26. package/dist/src/utils/visual/render/filter.d.ts +43 -0
  27. package/dist/src/utils/visual/render/render.d.ts +6 -0
  28. package/dist/src/utils/visual/render/renderTarget.d.ts +13 -0
  29. package/dist/src/utils/visual/render/utils/earcut.d.ts +45 -0
  30. package/dist/src/utils/visual/render/webGlRenderer.d.ts +4 -0
  31. package/dist/test/utils/color-grade.test.d.ts +1 -0
  32. package/dist/test/utils/event.test.d.ts +1 -0
  33. package/dist/test/utils/interp.test.d.ts +1 -0
  34. package/dist/test/utils/placement.test.d.ts +1 -0
  35. package/dist/test/utils/visual/filter.test.d.ts +1 -0
  36. package/dist/umd/index.umd.cjs +1 -1
  37. package/dist/umd/node/node.umd.cjs +1 -1
  38. package/dist/umd/utils/utils.umd.cjs +1 -1
  39. package/dist/utils-CYrYCt5o.js +1 -0
  40. package/docs/API.md +41 -17
  41. package/package.json +24 -13
  42. package/dist/i18n-D1p8_7wC.js +0 -1
  43. package/dist/utils-vTF6lLZZ.js +0 -1
@@ -0,0 +1,40 @@
1
+ export type Placement = 'top' | 'bottom' | 'left' | 'right';
2
+ export interface PlacementRect {
3
+ top: number;
4
+ left: number;
5
+ width: number;
6
+ height: number;
7
+ }
8
+ export interface ComputePlacementOptions {
9
+ /** Anchor (trigger) rect, in viewport coordinates (e.g. `getBoundingClientRect()`). */
10
+ anchor: PlacementRect;
11
+ /** The floating panel's own size. */
12
+ floating: {
13
+ width: number;
14
+ height: number;
15
+ };
16
+ /** Preferred side. Flips to the opposite side when it lacks room and the opposite side has more. */
17
+ placement: Placement;
18
+ /** Gap kept between the anchor and the floating panel, in px. */
19
+ offset?: number;
20
+ /** Region the panel must stay inside, in viewport coordinates. Defaults to the window viewport. */
21
+ boundary?: PlacementRect;
22
+ /** Minimum gap kept between the panel and the boundary edge when shifting, in px. */
23
+ padding?: number;
24
+ }
25
+ export interface ComputedPlacement {
26
+ top: number;
27
+ left: number;
28
+ /** The side actually used, after flip. */
29
+ placement: Placement;
30
+ }
31
+ /**
32
+ * Position a floating panel relative to an anchor rect: flips to the opposite
33
+ * side when the preferred side doesn't have room and the opposite side has
34
+ * more, then shifts along the cross axis to stay within `boundary`. Mirrors
35
+ * Floating UI's `flip`/`shift` middleware, minus the dependency.
36
+ *
37
+ * Coordinates are viewport-relative throughout (same space as `anchor`); the
38
+ * caller adds `scrollX`/`scrollY` when writing `position: absolute` styles.
39
+ */
40
+ export declare const computePlacement: (options: ComputePlacementOptions) => ComputedPlacement;
@@ -12,16 +12,8 @@ export declare const strParse: (str?: string, sep?: string | RegExp, eq?: string
12
12
  * @return {string} the resulting plain text
13
13
  */
14
14
  export declare const clearBr: (str?: string) => string;
15
- /**
16
- * @description: Parse a string into XML using the given MIME type
17
- * @param {string} xmlStr
18
- * @param {DOMParserSupportedType} format
19
- * @return {Document}
20
- */
21
- export declare const str2Xml: (xmlStr: string, format?: DOMParserSupportedType) => HTMLElement | undefined;
22
15
  export declare const isString: (obj: unknown) => boolean;
23
16
  export declare function randomString(len?: number): string;
24
- export declare function changeHumpToLowerCase(str: string): string;
25
17
  interface ClearStrOption {
26
18
  urlencoded?: boolean;
27
19
  }
@@ -25,7 +25,7 @@ export type DateInput = number | string | Date;
25
25
  * ```ts
26
26
  * formatDate(); // '2026-07-25 14:30:00'
27
27
  * formatDate(1753425000000, 'YYYY/MM/DD'); // '2026/07/25'
28
- * formatDate(new Date(), 'YYYY[年]MM[月]DD[日] hh:mm a'); // '2026 年 07 月 25 日 02:30 pm' (escaped literals)
28
+ * formatDate(new Date(), 'YYYY[年]MM[月]DD[日] hh:mm a'); // '2026年07月25日 02:30 pm' (escaped literals)
29
29
  * ```
30
30
  */
31
31
  export declare const formatDate: (value?: DateInput, pattern?: string) => string;
@@ -70,6 +70,38 @@ export declare const formatDuration: (seconds: number) => string;
70
70
  * @return {string}
71
71
  */
72
72
  export declare const timeFormat: (time: number) => string;
73
+ /**
74
+ * @description: Parse a WebVTT/SRT-style timestamp — `HH:MM:SS.mmm` or `MM:SS.mmm` (the hour
75
+ * component is optional) — into seconds. The inverse of [`formatDuration`](#formatduration),
76
+ * for anything that reads cue timings back out of subtitle/thumbnail-sprite manifests rather
77
+ * than formatting a duration for display.
78
+ * @param {string} raw the timestamp text, e.g. `'00:01:05.250'` or `'01:05.250'`
79
+ * @return {number | undefined} seconds, or `undefined` when `raw` doesn't match the pattern
80
+ * @example
81
+ * ```ts
82
+ * parseVttTimestamp('00:00:05.000'); // 5
83
+ * parseVttTimestamp('01:05.250'); // 65.25
84
+ * parseVttTimestamp('01:00:00.000'); // 3600
85
+ * parseVttTimestamp('not a timestamp'); // undefined
86
+ * ```
87
+ */
88
+ export declare const parseVttTimestamp: (raw: string) => number | undefined;
89
+ /**
90
+ * @description: Parse a WebVTT cue timing line — `<start> --> <end>`, optionally followed by
91
+ * cue settings (`align:start line:0`) after the end timestamp, which are ignored. Built on
92
+ * [`parseVttTimestamp`](#parsevtttimestamp) for each side.
93
+ * @param {string} line the timing line, e.g. `'00:00:00.000 --> 00:00:05.000 align:start line:0'`
94
+ * @return {{ start: number; end: number } | undefined} `undefined` when either side fails to parse
95
+ * @example
96
+ * ```ts
97
+ * parseVttCueTiming('00:00:00.000 --> 00:00:05.000'); // { start: 0, end: 5 }
98
+ * parseVttCueTiming('00:00:05.000 --> 00:00:10.000 align:start line:0'); // { start: 5, end: 10 }
99
+ * ```
100
+ */
101
+ export declare const parseVttCueTiming: (line: string) => {
102
+ start: number;
103
+ end: number;
104
+ } | undefined;
73
105
  /** `'compact'` is ours; the other three are `Intl.RelativeTimeFormat` styles. */
74
106
  export type RelativeStyle = 'long' | 'short' | 'narrow' | 'compact';
75
107
  export interface FormatRelativeOptions {
@@ -1,5 +1,6 @@
1
1
  import { Container } from '@/utils/visual/vertex/container';
2
2
  import { EventSystem } from '@/utils/visual/event';
3
+ import type { Filter } from '@/utils/visual/render/filter';
3
4
  import type { IApplicationOptions } from '@/utils/visual/types';
4
5
  export declare class Application {
5
6
  private readonly renderer;
@@ -21,6 +22,15 @@ export declare class Application {
21
22
  * app.start();
22
23
  */
23
24
  static create(options: IApplicationOptions): Promise<Application>;
25
+ /**
26
+ * Full-screen post-processing passes applied after the scene is drawn, in order. WebGL only
27
+ * (the Canvas backend ignores them).
28
+ *
29
+ * @example
30
+ * app.filters = [new ColorAdjustFilter({ saturation: 1.4, contrast: 1.1 })];
31
+ */
32
+ get filters(): Filter[];
33
+ set filters(filters: Filter[]);
24
34
  render(): void;
25
35
  start(): void;
26
36
  stop(): void;
@@ -1,7 +1,10 @@
1
1
  import { Application } from '@/utils/visual/application';
2
2
  import { Container } from '@/utils/visual/vertex/container';
3
3
  import { Graphics } from '@/utils/visual/graphics/graphics';
4
+ import { ColorAdjustFilter, Filter } from '@/utils/visual/render/filter';
5
+ import { WebGLRenderTarget } from '@/utils/visual/render/renderTarget';
4
6
  import { BYTES_PER_VERTEX, LINE_CAP, LINE_JOIN, MAX_VERTEX_COUNT, RENDERER_TYPE, SHAPE_TYPE } from '@/utils/visual/enums';
5
7
  import type { IApplicationOptions, IFillStyleOptions, ILineStyleOptions } from '@/utils/visual/types';
6
- export { Application, Container, Graphics, SHAPE_TYPE, LINE_CAP, LINE_JOIN, RENDERER_TYPE, MAX_VERTEX_COUNT, BYTES_PER_VERTEX, };
7
- export type { IApplicationOptions, IFillStyleOptions, ILineStyleOptions };
8
+ import type { ColorAdjustOptions } from '@/utils/visual/render/filter';
9
+ export { Application, Container, Graphics, Filter, ColorAdjustFilter, WebGLRenderTarget, SHAPE_TYPE, LINE_CAP, LINE_JOIN, RENDERER_TYPE, MAX_VERTEX_COUNT, BYTES_PER_VERTEX, };
10
+ export type { IApplicationOptions, IFillStyleOptions, ILineStyleOptions, ColorAdjustOptions };
@@ -1 +1 @@
1
- import{i as t,n as e,r as s,t as i}from"../../../enums-BAgbyGdH.js";var r,n=/* @__PURE__ */function(t){return t.RECTANGLE="rectangle",t.POLYGON="polygon",t.CIRCLE="circle",t.ELLIPSE="ellipse",t.ROUNDED_RECTANGLE="rounded rectangle",t}({}),a=/* @__PURE__ */function(t){return t.BUTT="butt",t.ROUND="round",t.SQUARE="square",t}({}),h=/* @__PURE__ */function(t){return t.MITER="miter",t.BEVEL="bevel",t.ROUND="round",t}({}),o=/* @__PURE__ */function(t){return t.WEB_GL="webgl",t.CANVAS="canvas",t.WEB_GPU="webgpu",t}({}),c=65536,l=12,u=class{},p=class extends u{x;y;width;height;type=n.RECTANGLE;constructor(t=0,e=0,s=0,i=0){super(),this.x=t,this.y=e,this.width=s,this.height=i}contains(t){return t.x>this.x&&t.x<this.x+this.width&&t.y>this.y&&t.y<this.y+this.height}},f=class{canvasEle;screen=new p;constructor(t){const{view:e}=t;this.canvasEle=e,this.screen.width=e.width,this.screen.height=e.height}resizeView(t,e){this.canvasEle.width=t,this.canvasEle.height=e}async init(){return Promise.resolve()}},d=class extends f{ctx;backgroundColor;backgroundAlpha;constructor(t){super(t),t.debug;const{backgroundColor:e,backgroundAlpha:s}=t;this.backgroundColor=e,this.backgroundAlpha=s,this.ctx=this.canvasEle.getContext("2d")}render(t){t.updateTransform(),this.ctx.save(),this.ctx.clearRect(0,0,this.screen.width,this.screen.height),this.backgroundAlpha&&(this.ctx.globalAlpha=this.backgroundAlpha),this.backgroundColor&&(this.ctx.fillStyle=this.backgroundColor),this.ctx.fillRect(0,0,this.screen.width,this.screen.height),t.renderCanvasRecursive(this),this.ctx.restore()}},x=(t,e)=>{if(e.worldAlpha<=0||!e.visible)return;e.buildBatches(t);const s=e.children;for(let i=0;i<s.length;i++)x(t,s[i])},g=(t,e)=>{if(e.worldAlpha<=0||!e.visible)return;e.updateBatches(t);const s=e.children;for(let i=0;i<s.length;i++)g(t,s[i])},y=class{vertexCount=0;indexCount=0;rgba=0;vertexStart=0;indexStart=0},v=class{style;vertexStart=0;indexStart=0;vertexCount=0;indexCount=0;constructor(t){this.style=t}start(t,e){this.vertexStart=t,this.indexStart=e}end(t,e){this.vertexCount=t,this.indexCount=e}},m=class{idx=0;reset(){this.idx=0}},b=class extends m{batches=[];constructor(){super()}getOne(){return this.batches[this.idx]||(this.batches[this.idx]=new w),this.batches[this.idx++]}},w=class extends y{vertexOffset=0;indexOffset=0;graphics;packVertices(t,e){const s=this.graphics.geometry.vertices.data,i=this.vertexOffset;for(let r=0;r<this.vertexCount;r++){const n=s[2*(i+r)],a=s[2*(i+r)+1],{a:h,b:o,c:c,d:l,tx:u,ty:p}=this.graphics.worldTransform,f=h*n+c*a+u,d=o*n+l*a+p,x=3*(this.vertexStart+r);t[x]=f,t[x+1]=d,e[x+2]=this.rgba}}packIndices(t){const e=this.graphics.geometry.indices.data,s=this.indexOffset;for(let i=0;i<this.indexCount;i++)t[this.indexStart+i]=e[i+s]+this.vertexStart}updateVertices(t){const e=this.graphics.geometry.vertices.data,s=this.vertexOffset,{a:i,b:r,c:n,d:a,tx:h,ty:o}=this.graphics.worldTransform;for(let c=0;c<this.vertexCount;c++){const l=e[2*(s+c)],u=e[2*(s+c)+1],p=3*(this.vertexStart+c);t[p]=i*l+n*u+h,t[p+1]=r*l+a*u+o}}},M=new class{batchesMap={graphics:new b};get(t){return this.batchesMap[t].getOne()}reset(){Object.values(this.batchesMap).forEach(t=>{t.reset()})}},P=class extends f{builtVersion=-1;vertexCount=0;indexCount=0;batches=[];batchesCount=0;vertFloatView;vertIntView;indexBuffer;curVertBufferLength=0;curIndexBufferLength=0;constructor(t){super(t);const e=/* @__PURE__ */new ArrayBuffer(3072);this.vertFloatView=new Float32Array(e),this.vertIntView=new Uint32Array(e),this.indexBuffer=/* @__PURE__ */new Uint32Array(256)}addBatch(t){t.vertexStart=this.vertexCount,t.indexStart=this.indexCount,this.vertexCount+=t.vertexCount,this.indexCount+=t.indexCount,this.batches[this.batchesCount]=t,this.batchesCount++}startBuild(){this.vertexCount=0,this.indexCount=0,this.batchesCount=0,M.reset()}buildEnd(){this.resizeBufferIfNeeded(),this.packData()}resizeBufferIfNeeded(){if(12*this.vertexCount>this.vertFloatView.byteLength){const t=new ArrayBuffer(12*this.vertexCount);this.vertFloatView=new Float32Array(t),this.vertIntView=new Uint32Array(t)}this.indexCount>this.indexBuffer.length&&(this.indexBuffer=new Uint32Array(this.indexCount))}packData(){for(let t=0;t<this.batchesCount;t++){const e=this.batches[t];this.batches[t]=void 0,e?.packVertices(this.vertFloatView,this.vertIntView),e?.packIndices(this.indexBuffer)}}updateChildrenTransform(t){t.sortChildren();const e=t.transform.shouldUpdateLocalTransform;if(t.transform.updateLocalTransform(),e){const{a:e,b:s,c:i,d:r,tx:n,ty:a}=t.transform.localTransform;this.setRootTransform(e,s,i,r,n,a)}t.worldAlpha=t.alpha;const s=t.children;for(let i=0;i<s.length;i++)s[i].updateTransform()}render(t){this.updateChildrenTransform(t),this.builtVersion!==t.structureVersion?(this.startBuild(),x(this,t),this.buildEnd(),this.builtVersion=t.structureVersion):g(this.vertFloatView,t),this.updateBuffer(),this.draw()}},T="\nprecision highp float;\nattribute vec2 a_position;\nattribute vec4 a_color;\nvarying vec4 v_color;\nuniform mat3 u_root_transform;\nuniform mat3 u_projection_matrix;\nvoid main(){\n v_color = a_color;\n gl_Position = vec4((u_projection_matrix * u_root_transform * vec3(a_position, 1.0)).xy, 0.0, 1.0);\n}\n".trim(),_="\nprecision mediump float;\nvarying vec4 v_color;\nvoid main(){\n gl_FragColor = v_color;\n}\n".trim(),E=(t,e,s)=>{const i=t.createShader(e);if(t.shaderSource(i,s),t.compileShader(i),t.getShaderParameter(i,t.COMPILE_STATUS))return i;{const e=t.getShaderInfoLog(i);throw t.deleteShader(i),console.error(`shader compilation failed: ${e}`),new Error(`shader compilation failed: ${e}`)}},B=t=>{const e=t.gl,s=((t,e,s)=>{const i=t.createProgram();if(!i)throw console.error("failed to create the program"),new Error("failed to create the program");if(t.attachShader(i,e),t.attachShader(i,s),t.linkProgram(i),!t.getProgramParameter(i,t.LINK_STATUS)){const r=t.getProgramInfoLog(i);throw console.error(`link failed: ${r}`),t.deleteProgram(i),t.deleteShader(e),t.deleteShader(s),new Error(`link failed: ${r}`)}return t.useProgram(i),i})(e,E(e,e.VERTEX_SHADER,T),E(e,e.FRAGMENT_SHADER,_));return e.enable(e.BLEND),e.blendFunc(e.ONE,e.ONE_MINUS_SRC_ALPHA),s},A=/* @__PURE__ */new Map,I=t=>{const e=A.get(t);if(e)return e;let s;if(/^#?[0-9a-fA-F]{3}$/.test(t)){const e=t.replace("#","");s=[parseInt(e[0]+e[0],16),parseInt(e[1]+e[1],16),parseInt(e[2]+e[2],16)]}else if(/^#?[0-9a-fA-F]{6}$/.test(t)){const e=parseInt(t.replace("#",""),16);s=[e>>16&255,e>>8&255,255&e]}else s=(t=>{if(void 0===r&&(r="undefined"!=typeof document?document.createElement("canvas").getContext("2d"):null),!r)return[0,0,0];r.fillStyle="#000",r.fillStyle=t,r.fillRect(0,0,1,1);const[e,s,i]=r.getImageData(0,0,1,1).data;return[e,s,i]})(t);return A.set(t,s),s},S=(t,e)=>{const[s,i,r]=I(t).map(t=>Math.round(t*e));let n=0;return n+=Math.round(255*e)<<24,n+=r<<16,n+=i<<8,n+=s,n},C=t=>{const[e,s,i]=I(t);return[e/255,s/255,i/255]},L=class extends P{gl;program;glVertexBuffer;glIndexBuffer;unifLoc;constructor(t){super(t),t.debug,this.gl=this.canvasEle.getContext("webgl",{antialias:!0}),this.gl.getExtension("OES_element_index_uint"),this.program=B(this),this.glVertexBuffer=this.gl.createBuffer(),this.glIndexBuffer=this.gl.createBuffer(),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.glVertexBuffer),this.gl.bindBuffer(this.gl.ELEMENT_ARRAY_BUFFER,this.glIndexBuffer),((t,e)=>{const s=t.getAttribLocation(e,"a_position");t.vertexAttribPointer(s,2,t.FLOAT,!1,12,0),t.enableVertexAttribArray(s);const i=t.getAttribLocation(e,"a_color");t.vertexAttribPointer(i,4,t.UNSIGNED_BYTE,!0,12,8),t.enableVertexAttribArray(i)})(this.gl,this.program),this.unifLoc={u_root_transform:this.gl.getUniformLocation(this.program,"u_root_transform"),u_projection_matrix:this.gl.getUniformLocation(this.program,"u_projection_matrix")};const e=t.backgroundAlpha??0,[s,i,r]=C(t.backgroundColor??"");this.gl.clearColor(s*e,i*e,r*e,e),this.setRootTransform(1,0,0,1,0,0),this.setProjectionMatrix()}setProjectionMatrix(){const t=1/this.canvasEle.width*2,e=1/this.canvasEle.height*2;this.gl.uniformMatrix3fv(this.unifLoc.u_projection_matrix,!1,new Float32Array([t,0,0,0,-e,0,-1,1,1]))}setRootTransform(t,e,s,i,r,n){this.gl.uniformMatrix3fv(this.unifLoc.u_root_transform,!1,new Float32Array([t,e,0,s,i,0,r,n,1]))}updateBuffer(){const t=this.gl;t.bindBuffer(t.ARRAY_BUFFER,this.glVertexBuffer),t.bufferData(t.ARRAY_BUFFER,this.vertFloatView,t.DYNAMIC_DRAW),t.bindBuffer(t.ELEMENT_ARRAY_BUFFER,this.glIndexBuffer),t.bufferData(t.ELEMENT_ARRAY_BUFFER,this.indexBuffer,t.DYNAMIC_DRAW)}draw(){const t=this.gl;t.clear(t.COLOR_BUFFER_BIT),t.drawElements(t.TRIANGLES,this.indexCount,t.UNSIGNED_INT,0)}},R=class extends P{gpu;device;pipeline;renderPassDescriptor;options;gpuVertexBuffer;gpuIndexBuffer;projectionMatBuffer;stageMatBuffer;uniformBindGroup;constructor(t){super(t),t.debug,this.options=t,this.gpu=this.canvasEle.getContext("webgpu"),this.curVertBufferLength=256,this.curIndexBufferLength=256}async init(){await this.initDevice(),this.initGpuBuffer(),this.initRenderPassDescriptor(),this.createPipeline(),this.initUniformBindGroup(),this.setRootTransform(1,0,0,1,0,0),this.setProjectionMatrix()}draw(){const{device:t,renderPassDescriptor:e,gpuVertexBuffer:s,gpuIndexBuffer:i,gpu:r,uniformBindGroup:n,indexCount:a,pipeline:h}=this,o=t.createCommandEncoder(),c=[...e.colorAttachments];c?.[0]?.view&&(c[0].view=r.getCurrentTexture().createView());const l=o.beginRenderPass(e);l.setPipeline(h),l.setVertexBuffer(0,s),l.setIndexBuffer(i,"uint32"),l.setBindGroup(0,n),l.drawIndexed(a),l.end();const u=o.finish();t.queue.submit([u])}initUniformBindGroup(){const t=this.device;this.stageMatBuffer=t.createBuffer({label:"stage-matrix-uniform-buffer",size:12*Float32Array.BYTES_PER_ELEMENT,usage:GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST}),this.projectionMatBuffer=t.createBuffer({label:"projection-matrix-uniform-buffer",size:12*Float32Array.BYTES_PER_ELEMENT,usage:GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST}),this.uniformBindGroup=this.device.createBindGroup({label:"my-uniform-bind-group",layout:this.pipeline.getBindGroupLayout(0),entries:[{binding:0,resource:{buffer:this.stageMatBuffer}},{binding:1,resource:{buffer:this.projectionMatBuffer}}]})}initGpuBuffer(){const t=this.device;this.gpuVertexBuffer=t.createBuffer({label:"my-gpu-vertex-buffer",size:12*this.curVertBufferLength,usage:GPUBufferUsage.VERTEX|GPUBufferUsage.COPY_DST}),this.gpuIndexBuffer=t.createBuffer({label:"my-gpu-index-buffer",size:this.curIndexBufferLength*Uint32Array.BYTES_PER_ELEMENT,usage:GPUBufferUsage.INDEX|GPUBufferUsage.COPY_DST})}updateBuffer(){const t=this.device;this.vertexCount>this.curVertBufferLength&&(this.gpuVertexBuffer.destroy(),this.gpuVertexBuffer=t.createBuffer({label:"my-gpu-vertex-buffer",size:12*this.vertexCount,usage:GPUBufferUsage.VERTEX|GPUBufferUsage.COPY_DST}),this.curVertBufferLength=this.vertexCount),t.queue.writeBuffer(this.gpuVertexBuffer,0,this.vertFloatView.buffer),this.indexCount>this.curIndexBufferLength&&(this.gpuIndexBuffer.destroy(),this.gpuIndexBuffer=t.createBuffer({label:"my-gpu-index-buffer",size:this.indexCount*Uint32Array.BYTES_PER_ELEMENT,usage:GPUBufferUsage.INDEX|GPUBufferUsage.COPY_DST}),this.curIndexBufferLength=this.indexCount),t.queue.writeBuffer(this.gpuIndexBuffer,0,this.indexBuffer.buffer)}setRootTransform(t,e,s,i,r,n){this.device.queue.writeBuffer(this.stageMatBuffer,0,new Float32Array([t,e,0,0,s,i,0,0,r,n,1,0]))}setProjectionMatrix(){const t=1/this.canvasEle.width*2,e=1/this.canvasEle.height*2;this.device.queue.writeBuffer(this.projectionMatBuffer,0,new Float32Array([t,0,0,0,0,-e,0,0,-1,1,1,0]))}createPipeline(){this.pipeline=this.device.createRenderPipeline({layout:"auto",label:"my-render-pipeline",vertex:{module:this.device.createShaderModule({code:"\n@group(0) @binding(0) var<uniform> u_root_transform: mat3x3<f32>;\n@group(0) @binding(1) var<uniform> u_projection_matrix: mat3x3<f32>;\n\nstruct VertOutput {\n @builtin(position) v_position: vec4<f32>,\n @location(0) v_color : vec4<f32>,\n};\n\n@vertex\nfn main(\n @location(0) a_position: vec2<f32>,\n @location(1) a_color: vec4<f32>,\n) -> VertOutput {\n let v_position = vec4<f32>((u_projection_matrix * u_root_transform * vec3<f32>(a_position, 1.0)).xy, 0.0, 1.0);\n\n let v_color = a_color;\n\n return VertOutput(v_position, v_color);\n}\n",label:"my-vert-shader-module"}),entryPoint:"main",buffers:[{arrayStride:12,attributes:[{shaderLocation:0,format:"float32x2",offset:0},{shaderLocation:1,format:"unorm8x4",offset:2*Float32Array.BYTES_PER_ELEMENT}]}]},fragment:{module:this.device.createShaderModule({code:"\n@fragment\nfn main(\n @location(0) v_color : vec4<f32>,\n) -> @location(0) vec4<f32> {\n return v_color;\n}\n",label:"my-frag-shader-module"}),entryPoint:"main",targets:[{format:navigator.gpu.getPreferredCanvasFormat(),blend:{alpha:{srcFactor:"one",dstFactor:"one-minus-src-alpha",operation:"add"},color:{srcFactor:"one",dstFactor:"one-minus-src-alpha",operation:"add"}}}]},primitive:{topology:"triangle-list"}})}async initDevice(){const t=await((await navigator.gpu.requestAdapter())?.requestDevice());t&&(this.gpu.configure({device:t,format:navigator.gpu.getPreferredCanvasFormat(),alphaMode:"premultiplied"}),this.device=t)}initRenderPassDescriptor(){const{backgroundColor:t="",backgroundAlpha:e=1}=this.options,s=e,[i,r,n]=C(t).map(t=>t*s);this.renderPassDescriptor={label:"my-render-pass-descriptor",colorAttachments:[{view:this.gpu.getCurrentTexture().createView(),storeOp:"store",loadOp:"clear",clearValue:[i,r,n,s]}]}}},U=class t{x;y;constructor(t=0,e=0){this.x=t,this.y=e}set(t=0,e=t){this.x=t,this.y=e}clone=()=>new t(this.x,this.y)},F=class{_x;_y;cb;constructor(t,e=0,s=0){this._x=e,this._y=s,this.cb=t}set(t=0,e=t){this._x=t,this._y=e,this.cb(this._x,this._y)}get x(){return this._x}set x(t){this._x!==t&&(this._x=t,this.cb(this._x,this._y))}get y(){return this._y}set y(t){this._y!==t&&(this._y=t,this.cb(this._x,this._y))}},N=class t{a;b;c;d;tx;ty;array=null;constructor(t=1,e=0,s=0,i=1,r=0,n=0){this.a=t,this.b=e,this.c=s,this.d=i,this.tx=r,this.ty=n}set=(t,e,s,i,r,n)=>(this.a=t,this.b=e,this.c=s,this.d=i,this.tx=r,this.ty=n,this);append=t=>{const{a:e,b:s,c:i,d:r,tx:n,ty:a}=this,{a:h,b:o,c:c,d:l,tx:u,ty:p}=t;return this.a=e*h+i*o,this.b=s*h+r*o,this.c=e*c+i*l,this.d=s*c+r*l,this.tx=e*u+i*p+n,this.ty=s*u+r*p+a,this};fromArray=t=>{this.a=t[0],this.b=t[1],this.c=t[3],this.d=t[4],this.tx=t[2],this.ty=t[5]};translate=(t,e)=>(this.tx+=t,this.ty+=e,this);scale=(t,e)=>(this.a*=t,this.d*=e,this.c*=t,this.b*=e,this.tx*=t,this.ty*=e,this);setTransform=(t,e,s,i,r,n,a,h,o)=>(this.a=Math.cos(a+o)*r,this.b=Math.sin(a+o)*r,this.c=-Math.sin(a-h)*n,this.d=Math.cos(a-h)*n,this.tx=t-(s*this.a+i*this.c),this.ty=e-(s*this.b+i*this.d),this);rotate=t=>{const e=Math.cos(t),s=Math.sin(t),i=this.a,r=this.c,n=this.tx;return this.a=i*e-this.b*s,this.b=i*s+this.b*e,this.c=r*e-this.d*s,this.d=r*s+this.d*e,this.tx=n*e-this.ty*s,this.ty=n*s+this.ty*e,this};equals=t=>t.a===this.a&&t.b===this.b&&t.c===this.c&&t.d===this.d&&t.tx===this.tx&&t.ty===this.ty;identity=()=>(this.a=1,this.b=0,this.c=0,this.d=1,this.tx=0,this.ty=0,this);decompose=t=>{const s=this.a,i=this.b,r=this.c,n=this.d,a=t.pivot,h=-Math.atan2(-r,n),o=Math.atan2(i,s),c=Math.abs(h+o);return c<1e-5||Math.abs(e-c)<1e-5?(t.rotation=o,t.skew.x=t.skew.y=0):(t.rotation=0,t.skew.x=h,t.skew.y=o),t.scale.x=Math.sqrt(s*s+i*i),t.scale.y=Math.sqrt(r*r+n*n),t.position.x=this.tx+(a.x*s+a.y*r),t.position.y=this.ty+(a.x*i+a.y*n),t};apply=t=>{const e=new U,s=t.x,i=t.y;return e.x=this.a*s+this.c*i+this.tx,e.y=this.b*s+this.d*i+this.ty,e};applyInverse=t=>{const e=new U,s=1/(this.a*this.d+this.c*-this.b),i=t.x,r=t.y;return e.x=this.d*s*i+-this.c*s*r+(this.ty*this.c-this.tx*this.d)*s,e.y=this.a*s*r+-this.b*s*i+(-this.ty*this.a+this.tx*this.b)*s,e};prepend=t=>{const{a:e,b:s,c:i,d:r,tx:n,ty:a}=t,{a:h,b:o,c:c,d:l,tx:u,ty:p}=this;return this.a=e*h+i*o,this.b=s*h+r*o,this.c=e*c+i*l,this.d=s*c+r*l,this.tx=e*u+i*p+n,this.ty=s*u+r*p+a,this};clone=()=>{const e=new t;return e.a=this.a,e.b=this.b,e.c=this.c,e.d=this.d,e.tx=this.tx,e.ty=this.ty,e};toArray=(t,e)=>{this.array||(this.array=/* @__PURE__ */new Float32Array(9));const s=e||this.array;return t?(s[0]=this.a,s[1]=this.b,s[2]=0,s[3]=this.c,s[4]=this.d,s[5]=0,s[6]=this.tx,s[7]=this.ty,s[8]=1):(s[0]=this.a,s[1]=this.c,s[2]=this.tx,s[3]=this.b,s[4]=this.d,s[5]=this.ty,s[6]=0,s[7]=0,s[8]=1),s}},V=class{localTransform=new N;worldTransform=new N;position;scale;pivot;skew;_rotation=0;rotateMatrix=new N;skewMatrix=new N;scaleMatrix=new N;localMatrix=new N;shouldUpdateLocalTransform=!1;worldId=0;parentId=0;constructor(){this.position=new F(this.onChange),this.scale=new F(this.onScaleChange,1,1),this.pivot=new F(this.onChange),this.skew=new F(this.onSkewChange)}get rotation(){return this._rotation}set rotation(t){this._rotation=t,this.rotateMatrix.set(Math.cos(this.rotation),Math.sin(this.rotation),-Math.sin(this.rotation),Math.cos(this.rotation),0,0),this.shouldUpdateLocalTransform=!0}onSkewChange=(t,e)=>{this.skewMatrix.set(Math.cos(e),Math.sin(e),Math.sin(t),Math.cos(t),0,0),this.shouldUpdateLocalTransform=!0};onScaleChange=(t,e)=>{this.scaleMatrix.set(t,0,0,e,0,0),this.shouldUpdateLocalTransform=!0};onChange=()=>{this.shouldUpdateLocalTransform=!0};updateLocalTransform(){if(!this.shouldUpdateLocalTransform)return;const{a:t,b:e,c:s,d:i}=this.localMatrix.set(1,0,0,1,0,0).append(this.rotateMatrix).append(this.skewMatrix).append(this.scaleMatrix),r=t*this.pivot.x+s*this.pivot.y,n=e*this.pivot.x+i*this.pivot.y,a=this.position.x-r,h=this.position.y-n;this.localTransform.set(t,e,s,i,a,h),this.shouldUpdateLocalTransform=!1,this.parentId=-1}updateTransform(t){if(this.updateLocalTransform(),this.parentId!==t.worldId){const{a:e,b:s,c:i,d:r,tx:n,ty:a}=t.worldTransform,{a:h,b:o,c:c,d:l,tx:u,ty:p}=this.localTransform;this.worldTransform.set(e*h+i*o,s*h+r*o,e*c+i*l,s*c+r*l,e*u+i*p+n,s*u+r*p+a),this.parentId=t.worldId,this.worldId++}}},D=class extends t{_zIndex=0;parent=void 0;visible=!0;transform=new V;alpha=1;worldAlpha=1;hitArea=null;cursor="auto";get zIndex(){return this._zIndex}set zIndex(t){this._zIndex=t,this.parent&&(this.parent.isSort=!0)}get position(){return this.transform.position}get localTransform(){return this.transform.localTransform}get worldTransform(){return this.transform.worldTransform}get x(){return this.position.x}set x(t){this.transform.position.x=t}get y(){return this.position.y}set y(t){this.transform.position.y=t}get scale(){return this.transform.scale}get pivot(){return this.transform.pivot}get skew(){return this.transform.skew}get rotation(){return this.transform.rotation}set rotation(t){this.transform.rotation=t}get angle(){return this.transform.rotation*s}set angle(t){this.transform.rotation=t*i}updateTransform(){const t=this.parent?.transform||new V;this.transform.updateTransform(t),this.worldAlpha=this.alpha*(this.parent?.worldAlpha||1)}addEventListener=(t,e,s)=>{const i="boolean"==typeof s&&s||"object"==typeof s&&s.capture?`${t}capture`:t;"object"==typeof s&&s.once?this.once(i,e):this.tap(i,e)};removeEventListener=(t,e,s)=>{const i=s?`${t}capture`:t;this.off(i,e)}},k=class extends D{isSort=!1;type="container";children=[];worldId=0;batches=[];batchCount=0;structureVersion=0;constructor(){super()}markStructureDirty=()=>{let t=this.parent??this;for(;t.parent;)t=t.parent;t.structureVersion++};addChild=t=>{t.parent?.removeChild(t),this.children.push(t),t.parent=this,this.isSort=!0,this.markStructureDirty()};removeChild=t=>{for(let e=0;e<this.children.length;e++)if(this.children[e]===t)return this.children.splice(e,1),t.parent=void 0,void this.markStructureDirty()};sortChildren=()=>{this.isSort&&(this.children.sort((t,e)=>t.zIndex-e.zIndex),this.isSort=!1)};renderCanvas(t){}renderCanvasRecursive=t=>{if(!(this.worldAlpha<=0)&&this.visible){this.renderCanvas(t);for(let e=0;e<this.children.length;e++)this.children[e].renderCanvasRecursive(t)}};updateTransform=()=>{this.sortChildren();const t=this.parent?.transform||new V;if(this.transform.updateTransform(t),this.worldAlpha=(this.parent?.worldAlpha||1)*this.alpha,!(this.worldAlpha<=0)&&this.visible)for(let e=0;e<this.children.length;e++)this.children[e].updateTransform()};containsPoint=t=>!!this.hitArea&&this.hitArea.contains(t);buildBatches(t){}updateBatches(t){}},O=/* @__PURE__ */function(t){return t[t.NONE=0]="NONE",t[t.CAPTURING=1]="CAPTURING",t[t.AT_TARGET=2]="AT_TARGET",t[t.BUBBLING=3]="BUBBLING",t}({}),G=class{isTrusted=!0;timeStamp=0;type="mousemove";button=0;buttons=0;global=new U;propagationStopped=!1;eventPhase=0;target=new k;currentTarget=new k;stopPropagation(){this.propagationStopped=!0}},j=class{rootContainer;hasFoundTarget=!1;hitTarget=null;cursor="auto";eventHandlerMap={};pressTargetsMap={};overTargets=[];constructor(t){this.rootContainer=t,this.eventHandlerMap.mousemove=this.fireMouseMove,this.eventHandlerMap.mousedown=this.fireMouseDown,this.eventHandlerMap.mouseup=this.fireMouseUp}hitTestRecursive=(t,e)=>{if(!t.visible)return;if(this.hasFoundTarget)return;for(let i=t.children.length-1;i>=0;i--){const s=t.children[i];this.hitTestRecursive(s,e)}if(this.hasFoundTarget)return;const s=t.worldTransform.applyInverse(e);t.containsPoint(s)&&(this.hitTarget=t,this.hasFoundTarget=!0)};hitTest=t=>(this.hasFoundTarget=!1,this.hitTarget=null,this.hitTestRecursive(this.rootContainer,t),this.hitTarget);fireEvent=t=>{this.eventHandlerMap[t.type]?.(t)};fireMouseMove=t=>{const e=this.hitTest(t.global),s=this.overTargets.length>0?this.overTargets[this.overTargets.length-1]:null;if(s&&s!==e&&(t.target=s,t.type="mouseout",this.dispatchEvent(t),!e||!this.composePath(e).includes(s)))if(t.type="mouseleave",t.eventPhase=O.AT_TARGET,e){let i=s;for(;i&&!this.composePath(e).includes(i);)t.target=i,t.currentTarget=t.target,t.target.call(`${t.type}capture`,t),t.target.call(t.type,t),i=i.parent}else for(let i=this.overTargets.length-1;i>=0;i--)t.target=this.overTargets[i],t.currentTarget=t.target,t.target.call(`${t.type}capture`,t),t.target.call(t.type,t);if(e&&s!==e){t.target=e,t.type="mouseover",this.dispatchEvent(t);const i=this.composePath(e);if(t.type="mouseenter",t.eventPhase=O.AT_TARGET,s){let e=i.length-1;for(;e>=0&&!this.composePath(s).includes(i[e]);e--);for(let s=e+1;s<i.length;s++)t.target=i[s],t.currentTarget=t.target,t.target.call(`${t.type}capture`,t),t.target.call(t.type,t)}else for(let e=0;e<i.length;e++)t.target=i[e],t.currentTarget=t.target,t.target.call(`${t.type}capture`,t),t.target.call(t.type,t)}e&&(t.target=e,t.type="mousemove",this.dispatchEvent(t)),this.overTargets=e?this.composePath(e):[],this.cursor=e?e.cursor:"auto"};fireMouseDown=t=>{const e=this.hitTest(t.global);e&&(t.target=e,this.dispatchEvent(t),this.pressTargetsMap[t.button]=this.composePath(e))};fireMouseUp=t=>{const e=this.hitTest(t.global);if(!e)return;t.target=e,this.dispatchEvent(t);const s=this.pressTargetsMap[t.button];if(!s)return;let i=s[s.length-1];const r=this.composePath(e);for(;i&&!r.includes(i);)i.parent&&(i=i.parent);t.type="click",t.target=i,this.dispatchEvent(t),delete this.pressTargetsMap[t.button]};notifyTarget=t=>{t.eventPhase===O.CAPTURING?t.currentTarget.call(`${t.type}capture`,t):t.currentTarget.call(t.type,t)};propagate=t=>{const e=this.composePath(t.target);t.eventPhase=O.CAPTURING;for(let s=0;s<e.length-1;s++)if(t.currentTarget=e[s],this.notifyTarget(t),t.propagationStopped)return;if(t.eventPhase=O.AT_TARGET,t.currentTarget=t.target,t.currentTarget.call(`${t.type}capture`,t),!t.propagationStopped&&(t.currentTarget.call(t.type,t),!t.propagationStopped)){t.eventPhase=O.BUBBLING;for(let s=e.length-2;s>=0;s--)if(t.currentTarget=e[s],this.notifyTarget(t),t.propagationStopped)return}};dispatchEvent=t=>{t.propagationStopped=!1,this.propagate(t)};composePath=t=>{const e=[];let s=t;for(;s;)e.unshift(s),s=s.parent;return e}},Y=class{canvasEle;eventBoundary;rootEvent=new G;constructor(t,e){this.canvasEle=t,this.eventBoundary=new j(e),this.addEvents()}addEvents=()=>{this.canvasEle.addEventListener("pointermove",this.onPointerMove,!0),this.canvasEle.addEventListener("pointerleave",this.onPointerLeave,!0),this.canvasEle.addEventListener("pointerdown",this.onPointerDown,!0),this.canvasEle.addEventListener("pointerup",this.onPointerup,!0)};onPointerMove=t=>{this.bootstrapEvent(t),this.eventBoundary.fireEvent(this.rootEvent),this.setCursor()};onPointerLeave=()=>{this.eventBoundary.overTargets=[]};onPointerDown=t=>{this.bootstrapEvent(t),this.eventBoundary.fireEvent(this.rootEvent)};onPointerup=t=>{this.bootstrapEvent(t),this.eventBoundary.fireEvent(this.rootEvent)};bootstrapEvent=t=>{this.rootEvent.isTrusted=t.isTrusted,this.rootEvent.timeStamp=performance.now(),this.rootEvent.type=t.type.replace("pointer","mouse"),this.rootEvent.button=t.button,this.rootEvent.buttons=t.buttons,this.rootEvent.global.x=t.offsetX,this.rootEvent.global.y=t.offsetY};setCursor=()=>{this.canvasEle.style.cursor=this.eventBoundary.cursor}},z=class t{renderer;stage;view;animationFrameId;eventSystem;constructor(t){const{view:e=document.createElement("canvas")}=t;this.view=e,this.renderer=(t=>{const{prefer:e}=t;switch(e){case o.CANVAS:return new d(t);case o.WEB_GL:return new L(t);case o.WEB_GPU:return new R(t);default:return new d(t)}})({...t,view:e}),this.stage=new k,this.eventSystem=new Y(this.view,this.stage)}static async create(e){const s=new t(e);return await s.renderer.init(),s}render(){this.renderer.render(this.stage)}start(){const t=()=>{this.render(),this.animationFrameId=requestAnimationFrame(t)};t()}stop(){this.animationFrameId&&(cancelAnimationFrame(this.animationFrameId),this.animationFrameId=void 0)}},q=class extends u{points=[];closeStroke=!1;type=n.POLYGON;constructor(t=[]){super(),this.points=t}isIntersect(t,e,s,i,r,n){if(i>e&&n>e)return!1;if(i<e&&n<e)return!1;if(s<t&&r<t)return!1;if(s>t&&r>t)return!0;return r-(r-s)/(i-n)*(e-n)>t}contains(t){const e=this.points.length;let s=0;for(let h=2;h<=e-2;h+=2){const e=this.points[h-2],i=this.points[h-1],r=this.points[h],n=this.points[h+1];this.isIntersect(t.x,t.y,e,i,r,n)&&s++}const i=this.points[0],r=this.points[1],n=this.points[e-2],a=this.points[e-1];return this.isIntersect(t.x,t.y,i,r,n,a)&&s++,s%2!=0}},Z=class t{color="#ffffff";alpha=1;visible=!1;constructor(){this.reset()}clone(){const e=new t;return e.color=this.color,e.alpha=this.alpha,e.visible=this.visible,e}reset(){this.color="#ffffff",this.alpha=1,this.visible=!1}},$=class t extends Z{width=0;cap=a.BUTT;join=h.MITER;miterLimit=10;clone(){const e=new t;return e.color=this.color,e.alpha=this.alpha,e.visible=this.visible,e.width=this.width,e.cap=this.cap,e.join=this.join,e.miterLimit=this.miterLimit,e}reset(){super.reset(),this.color="#ffffff",this.width=0,this.cap=a.BUTT,this.join=h.MITER,this.miterLimit=10}},X=class{shape;lineStyle;fillStyle;vertices=[];constructor(t,e,s){this.shape=t,this.lineStyle=s,this.fillStyle=e}},H=class{_oldLength=-1;_length=0;curMaxLen=16;float32=new Float32Array(16);_data;get length(){return this._length}concat(t){const e=this._length+t.length;for(;e>this.curMaxLen;)this.expandCapacity();for(let s=0;s<t.length;s++)this.float32[this._length]=t[s],this._length++}push(t){this._length>=this.curMaxLen&&this.expandCapacity(),this.float32[this._length]=t,this._length++}expandCapacity(){this.curMaxLen*=2;const t=new Float32Array(this.curMaxLen);t.set(this.float32),this.float32=t}get data(){return this._oldLength!==this._length&&(this._data=new Float32Array(this.float32.buffer,0,this._length),this._oldLength=this._length),this._data}clear(){this._length=0}},W=class{_oldLength=-1;_length=0;curMaxLen=8;int32=new Uint32Array(8);_data;get length(){return this._length}concat(t){const e=this.length+t.length;for(;e>this.curMaxLen;)this.expandCapacity();for(let s=0;s<t.length;s++)this.int32[this._length]=t[s],this._length++}concatUInt16(t){const e=this.length+t.length;for(;e>this.curMaxLen;)this.expandCapacity();this.int32.set(t,this._length),this._length=e}expandCapacity(){this.curMaxLen*=2;const t=new Uint32Array(this.curMaxLen);t.set(this.int32),this.int32=t}get data(){return this._oldLength!==this._length&&(this._data=new Uint32Array(this.int32.buffer,0,this._length),this._oldLength=this._length),this._data}clear(){this._length=0}},Q=/* @__PURE__ */new Set,J=!1;function K(t,e,s=2){const i=e&&e.length,r=i?e[0]*s:t.length;Q.size&&Q.clear();let n=tt(t,0,r,s,!0);const a=[];if(!n||n.next===n.prev)return a;let h=0,o=0,c=0;if(i&&(n=function(t,e,s,i){const r=[];for(let n=0,a=e.length;n<a;n++){const s=tt(t,e[n]*i,n<a-1?e[n+1]*i:t.length,i,!1);s===s.next&&Q.add(s),r.push(Et(s))}r.sort(ot),function(t,e){const s=Math.ceil((t+2*e)/lt)+e+2;ut.length<4*s&&(ut=new Float64Array(4*s));pt=0}(t.length/i,e.length),xt(s,s),ht=!0;for(let n=0;n<r.length;n++)s=ct(r[n],s);return ht=!1,et(s)}(t,e,n,s)),t.length>80*s){h=t[0],o=t[1];let e=h,i=o;for(let n=s;n<r;n+=s){const s=t[n],r=t[n+1];s<h&&(h=s),r<o&&(o=r),s>e&&(e=s),r>i&&(i=r)}c=Math.max(e-h,i-o),c=0!==c?32767/c:0}return st(n,a,h,o,c),a}function tt(t,e,s,i,r){let n=null;if(r===function(t,e,s,i){let r=0;for(let n=e,a=s-i;n<s;n+=i)r+=(t[a]-t[n])*(t[n+1]+t[a+1]),a=n;return r}(t,e,s,i)>0)for(let a=e;a<s;a+=i)n=Ft(a/i|0,t[a],t[a+1],n);else for(let a=s-i;a>=e;a-=i)n=Ft(a/i|0,t[a],t[a+1],n);return n&&St(n,n.next)&&(Nt(n),n=n.next),n}function et(t,e=t){const s=e===t;let i,r=t;do{i=!1,r===r.next||0!==Q.size&&Q.has(r)||!St(r,r.next)&&0!==It(r.prev,r,r.next)?(s||r!==e)&&(r=r.next,i=!s):((s||r===e)&&(e=r.prev),J=!0,Nt(r),r=r.prev,i=!0)}while(i||r!==e);return e}function st(t,e,s,i,r){r&&function(t,e,s,i){let r=t,n=0;do{r.z=_t(r.x,r.y,e,s,i),mt[n++]=r,r=r.next}while(r!==t);!function(t){if(t<=32){for(let e=1;e<t;e++){const t=mt[e],s=t.z;let i=e-1;for(;i>=0&&mt[i].z>s;)mt[i+1]=mt[i],i--;mt[i+1]=t}return}wt.length<t&&(wt=new Uint32Array(t),Mt=new Uint32Array(t),bt=new Array(t));for(let e=0;e<t;e++)wt[e]=mt[e].z;Tt(t,mt,wt,bt,Mt,0),Tt(t,bt,Mt,mt,wt,8),Tt(t,mt,wt,bt,Mt,16),Tt(t,bt,Mt,mt,wt,24)}(n);let a=null;for(let h=0;h<n;h++){const t=mt[h];t.prevZ=a,a&&(a.nextZ=t),a=t}a.nextZ=null}(t,s,i,r);let n=t,a=!1;for(;t.prev!==t.next;){const h=t.prev,o=t.next;if(It(h,t,o)<0&&(r?rt(t,s,i,r):it(t)))e.push(h.i,t.i,o.i),Nt(t),t=o,n=o;else if((t=o)===n){if(J=!1,t=et(t),J){n=t;continue}if(!a){n=t=nt(t,e),a=!0;continue}at(t,e,s,i,r);break}}}function it(t){const e=t.prev,s=t,i=t.next,r=e.x,n=s.x,a=i.x,h=e.y,o=s.y,c=i.y,l=Math.min(r,n,a),u=Math.min(h,o,c),p=Math.max(r,n,a),f=Math.max(h,o,c);let d=i.next;for(;d!==e;){if(d.x>=l&&d.x<=p&&d.y>=u&&d.y<=f&&(r!==d.x||h!==d.y)&&Bt(r,h,n,o,a,c,d.x,d.y)&&It(d.prev,d,d.next)>=0)return!1;d=d.next}return!0}function rt(t,e,s,i){const r=t.prev,n=t,a=t.next,h=r.x,o=n.x,c=a.x,l=r.y,u=n.y,p=a.y,f=Math.min(h,o,c),d=Math.min(l,u,p),x=Math.max(h,o,c),g=Math.max(l,u,p),y=_t(f,d,e,s,i),v=_t(x,g,e,s,i);let m=t.prevZ;for(;m&&m.z>=y;){if(m.x>=f&&m.x<=x&&m.y>=d&&m.y<=g&&m!==a&&(h!==m.x||l!==m.y)&&Bt(h,l,o,u,c,p,m.x,m.y)&&It(m.prev,m,m.next)>=0)return!1;m=m.prevZ}let b=t.nextZ;for(;b&&b.z<=v;){if(b.x>=f&&b.x<=x&&b.y>=d&&b.y<=g&&b!==a&&(h!==b.x||l!==b.y)&&Bt(h,l,o,u,c,p,b.x,b.y)&&It(b.prev,b,b.next)>=0)return!1;b=b.nextZ}return!0}function nt(t,e){let s=t,i=!1;do{const r=s.prev,n=s.next.next;Ct(r,s,s.next,n,!1)&&Rt(r,n)&&Rt(n,r)&&(e.push(r.i,s.i,n.i),Nt(s),Nt(s.next),s=t=n,i=!0),s=s.next}while(s!==t);return i?et(s):s}function at(t,e,s,i,r){let n=t;do{let t=n.next.next;for(;t!==n.prev;){if(n.i!==t.i&&At(n,t)){let a=Ut(n,t);return n=et(n,n.next),a=et(a,a.next),st(n,e,s,i,r),void st(a,e,s,i,r)}t=t.next}n=n.next}while(n!==t)}var ht=!1;function ot(t,e){return t.x-e.x||t.y-e.y||(t.next.y-t.y)/(t.next.x-t.x)-(e.next.y-e.y)/(e.next.x-e.x)}function ct(t,e){const s=function(t,e){let s=e;const i=t.x,r=t.y;let n,a=-1/0;if(St(t,s))return s;for(let p=0,f=0;p<pt;p++,f+=4){if(r<ut[f+1]||r>ut[f+3]||ut[f]>i||ut[f+2]<=a)continue;const e=gt(p);s=yt(p);do{if(s.prev.next===s){if(St(t,s.next))return s.next;if(r<=s.y&&r>=s.next.y&&s.next.y!==s.y){const t=s.x+(r-s.y)*(s.next.x-s.x)/(s.next.y-s.y);if(t<=i&&t>a&&(a=t,n=s.x<s.next.x?s:s.next,t===i))return n}}s=s.next}while(s!==e)}if(!n)return null;const h=n.x,o=n.y,c=Math.min(r,o),l=Math.max(r,o);let u=1/0;for(let p=0,f=0;p<pt;p++,f+=4){if(ut[f+2]<h||ut[f]>i||ut[f+3]<c||ut[f+1]>l)continue;const e=gt(p);s=yt(p);do{if(s.prev.next===s&&i>=s.x&&s.x>=h&&i!==s.x&&Bt(r<o?i:a,r,h,o,r<o?a:i,r,s.x,s.y)){const e=Math.abs(r-s.y)/(i-s.x);(Rt(s,t)||s.y===r&&s.next.y===r&&s.next.x>i)&&(e<u||e===u&&(s.x>n.x||s.x===n.x&&vt(n,s)))&&(n=s,u=e)}s=s.next}while(s!==e)}return n}(t,e);if(!s)return e;const i=Ut(s,t);return xt(s,i.next.next),et(i,i.next),et(s,s.next)}var lt=16,ut=/* @__PURE__ */new Float64Array(0),pt=0,ft=[],dt=[];function xt(t,e){let s=t;do{const t=pt++;ft[t]=s;let i=1/0,r=1/0,n=-1/0,a=-1/0,h=0;do{const e=s.next;s.z=t,s.x<i&&(i=s.x),s.x>n&&(n=s.x),s.y<r&&(r=s.y),s.y>a&&(a=s.y),e.x<i&&(i=e.x),e.x>n&&(n=e.x),e.y<r&&(r=e.y),e.y>a&&(a=e.y),s=e}while(++h<lt&&s!==e);dt[t]=s;const o=4*t;ut[o]=i,ut[o+1]=r,ut[o+2]=n,ut[o+3]=a}while(s!==e)}function gt(t){let e=dt[t];for(;e.prev.next!==e;)e=e.next;return dt[t]=e,e}function yt(t){let e=ft[t];for(;e.prev.next!==e;)e=e.next;return ft[t]=e,e}function vt(t,e){return It(t.prev,t,e.prev)<0&&It(e.next,t,t.next)<0}var mt=[],bt=[],wt=/* @__PURE__ */new Uint32Array(0),Mt=/* @__PURE__ */new Uint32Array(0),Pt=/* @__PURE__ */new Uint32Array(256);function Tt(t,e,s,i,r,n){Pt.fill(0);for(let h=0;h<t;h++)Pt[s[h]>>>n&255]++;let a=0;for(let h=0;h<256;h++){const t=Pt[h];Pt[h]=a,a+=t}for(let h=0;h<t;h++){const t=s[h],a=Pt[t>>>n&255]++;i[a]=e[h],r[a]=t}}function _t(t,e,s,i,r){return(t=1431655765&((t=858993459&((t=252645135&((t=16711935&((t=(t-s)*r|0)|t<<8))|t<<4))|t<<2))|t<<1))|(e=1431655765&((e=858993459&((e=252645135&((e=16711935&((e=(e-i)*r|0)|e<<8))|e<<4))|e<<2))|e<<1))<<1}function Et(t){let e=t,s=t;do{(e.x<s.x||e.x===s.x&&e.y<s.y)&&(s=e),e=e.next}while(e!==t);return s}function Bt(t,e,s,i,r,n,a,h){return(r-a)*(e-h)>=(t-a)*(n-h)&&(t-a)*(i-h)>=(s-a)*(e-h)&&(s-a)*(n-h)>=(r-a)*(i-h)}function At(t,e){const s=St(t,e)&&It(t.prev,t,t.next)>0&&It(e.prev,e,e.next)>0;return t.next.i!==e.i&&(s||Rt(t,e)&&Rt(e,t)&&(0!==It(t.prev,t,e.prev)||0!==It(t,e.prev,e)))&&!function(t,e){const s=Math.min(t.x,e.x),i=Math.max(t.x,e.x),r=Math.min(t.y,e.y),n=Math.max(t.y,e.y);let a=t;do{const h=a.next;if(a.x>i&&h.x>i||a.x<s&&h.x<s||a.y>n&&h.y>n||a.y<r&&h.y<r)a=h;else{if(a.i!==t.i&&h.i!==t.i&&a.i!==e.i&&h.i!==e.i&&Ct(a,h,t,e))return!0;a=h}}while(a!==t);return!1}(t,e)&&(s||function(t,e){let s=t,i=!1;const r=(t.x+e.x)/2,n=(t.y+e.y)/2;do{const t=s.next;s.y>n!=t.y>n&&r<(t.x-s.x)*(n-s.y)/(t.y-s.y)+s.x&&(i=!i),s=t}while(s!==t);return i}(t,e))}function It(t,e,s){return(e.y-t.y)*(s.x-e.x)-(e.x-t.x)*(s.y-e.y)}function St(t,e){return t.x===e.x&&t.y===e.y}function Ct(t,e,s,i,r=!0){const n=It(t,e,s),a=It(t,e,i),h=It(s,i,t),o=It(s,i,e);return(n>0&&a<0||n<0&&a>0)&&(h>0&&o<0||h<0&&o>0)||!!r&&(!(0!==n||!Lt(t,s,e))||(!(0!==a||!Lt(t,i,e))||(!(0!==h||!Lt(s,t,i))||!(0!==o||!Lt(s,e,i)))))}function Lt(t,e,s){return e.x<=Math.max(t.x,s.x)&&e.x>=Math.min(t.x,s.x)&&e.y<=Math.max(t.y,s.y)&&e.y>=Math.min(t.y,s.y)}function Rt(t,e){return It(t.prev,t,t.next)<0?It(t,e,t.next)>=0&&It(t,t.prev,e)>=0:It(t,e,t.prev)<0||It(t,t.next,e)<0}function Ut(t,e){const s=Vt(t.i,t.x,t.y),i=Vt(e.i,e.x,e.y),r=t.next,n=e.prev;return t.next=e,e.prev=t,s.next=r,r.prev=s,i.next=s,s.prev=i,n.next=i,i.prev=n,i}function Ft(t,e,s,i){const r=Vt(t,e,s);return i?(r.next=i.next,r.prev=i,i.next.prev=r,i.next=r):(r.prev=r,r.next=r),r}function Nt(t){t.next.prev=t.prev,t.prev.next=t.next,t.prevZ&&(t.prevZ.nextZ=t.nextZ),t.nextZ&&(t.nextZ.prevZ=t.prevZ),ht&&function(t,e){const s=4*t.z;e.x<ut[s]&&(ut[s]=e.x),e.y<ut[s+1]&&(ut[s+1]=e.y),e.x>ut[s+2]&&(ut[s+2]=e.x),e.y>ut[s+3]&&(ut[s+3]=e.y)}(t.prev,t.next)}function Vt(t,e,s){return{i:t,x:e,y:s,prev:null,next:null,z:0,prevZ:null,nextZ:null}}var Dt=class extends u{x;y;radius;type=n.CIRCLE;constructor(t=0,e=0,s=0){super(),this.x=t,this.y=e,this.radius=s}contains(t){return(t.x-this.x)*(t.x-this.x)+(t.y-this.y)*(t.y-this.y)<this.radius*this.radius}},kt=class extends u{x;y;radiusX;radiusY;type=n.ELLIPSE;constructor(t=0,e=0,s=0,i=0){super(),this.x=t,this.y=e,this.radiusX=s,this.radiusY=i}contains(t){return(t.x-this.x)*(t.x-this.x)/(this.radiusX*this.radiusX)+(t.y-this.y)*(t.y-this.y)/(this.radiusY*this.radiusY)<1}},Ot=class extends u{x;y;width;height;radius;type=n.ROUNDED_RECTANGLE;constructor(t=0,e=0,s=0,i=0,r=20){super(),this.x=t,this.y=e,this.width=s,this.height=i;const n=Math.min(s,i)/2;this.radius=r>n?n:r}contains(t){if(!(t.x>this.x&&t.x<this.x+this.width&&t.y>this.y&&t.y<this.y+this.height))return!1;const e=this.x+this.radius,s=this.y+this.radius;if(t.x<e&&t.y<s)return(t.x-e)*(t.x-e)+(t.y-s)*(t.y-s)<this.radius*this.radius;const i=this.x+this.radius,r=this.y+this.height-this.radius;if(t.x<i&&t.y>r)return(t.x-i)*(t.x-i)+(t.y-r)*(t.y-r)<this.radius*this.radius;const n=this.x+this.width-this.radius,a=this.y+this.radius;if(t.x>n&&t.y<a)return(t.x-n)*(t.x-n)+(t.y-a)*(t.y-a)<this.radius*this.radius;const h=this.x+this.width-this.radius,o=this.y+this.height-this.radius;return!(t.x>h&&t.y<o)||(t.x-h)*(t.x-h)+(t.y-o)*(t.y-o)<this.radius*this.radius}},Gt=t=>{const{shape:e,vertices:s}=t;if(e instanceof p){const{x:t,y:i,width:r,height:n}=e;s.push(t,i,t+r,i,t+r,i+n,t,i+n)}e instanceof Dt&&((t,e)=>{const{x:s,y:i,radius:r}=t,n=2*Math.PI*r,a=Math.min(Math.ceil(n/5),2048);for(let h=0;h<a;h++){const t=h/a*Math.PI*2,n=s+r*Math.cos(t),o=i+r*Math.sin(t);e.vertices.push(n,o)}})(e,t),e instanceof Ot&&((t,e)=>{const{x:s,y:i,width:r,height:n,radius:a}=t,h=2*Math.PI*a/4,o=Math.min(Math.ceil(h/4),2048);for(let c=0;c<o;c++){const t=c/o*Math.PI*.5,h=a*Math.cos(t),l=a*Math.sin(t);e.vertices.push(s+r-a+h,i+n-a+l)}for(let c=0;c<o;c++){const t=c/o*Math.PI*.5+Math.PI/2,r=a*Math.cos(t),h=a*Math.sin(t);e.vertices.push(s+a+r,i+n-a+h)}for(let c=0;c<o;c++){const t=c/o*Math.PI*.5+Math.PI,r=a*Math.cos(t),n=a*Math.sin(t);e.vertices.push(s+a+r,i+a+n)}for(let c=0;c<o;c++){const t=c/o*Math.PI*.5+1.5*Math.PI,n=a*Math.cos(t),h=a*Math.sin(t);e.vertices.push(s+r-a+n,i+a+h)}})(e,t),e instanceof kt&&((t,e)=>{const{x:s,y:i,radiusX:r,radiusY:n}=t,a=Math.PI*Math.sqrt(2*(r*r+n*n)),h=Math.min(Math.ceil(a/5),2048);for(let o=0;o<h;o++){const t=o/h*Math.PI*2,a=s+r*Math.cos(t),c=i+n*Math.sin(t);e.vertices.push(a,c)}})(e,t),e instanceof q&&(t.vertices=e.points)},jt=t=>{const e=[],s=t.length/2+1;for(let i=1;i<s-1;i++)e.push(0,i,i+1);return e.push(0,s-1,1),e},Yt=(t,e)=>{const{shape:s,vertices:i,fillStyle:r}=t,n=new v(r);if(e.batchParts.push(n),n.start(e.vertices.length/2,e.indices.length),s instanceof p&&(e.vertices.concat(i),e.indices.concat([0,1,2,0,2,3]),n.end(4,6)),s instanceof Dt){const{x:t,y:r}=s;e.vertices.push(t),e.vertices.push(r),e.vertices.concat(i);const a=jt(i);e.indices.concat(a),n.end(i.length/2+1,a.length)}if(s instanceof Ot){const{x:t,y:r,width:a,height:h}=s;e.vertices.push(t+a/2),e.vertices.push(r+h/2),e.vertices.concat(i);const o=jt(i);e.indices.concat(o),n.end(i.length/2+1,o.length)}if(s instanceof kt){const{x:t,y:r}=s;e.vertices.push(t),e.vertices.push(r),e.vertices.concat(i);const a=jt(i);e.indices.concat(a),n.end(i.length/2+1,a.length)}if(s instanceof q){e.vertices.concat(i);const t=K(i);e.indices.concat(t),n.end(i.length/2,t.length)}},zt=(t,e,s,i,r,n,a,h)=>{let o=0,c=0,l=0,u=0,p=0,f=0;if(Math.abs(s-t)<=Number.EPSILON)o=1,c=0,p=s;else{const r=(i-e)/(s-t);o=r,c=-1,p=-(i-r*s)}if(Math.abs(a-r)<=Number.EPSILON)l=1,u=0,f=a;else{const t=(h-n)/(a-r);l=t,u=-1,f=-(h-t*a)}return[(p*u-c*f)/(o*u-c*l),(o*f-p*l)/(o*u-c*l)]},qt=(t,e,s)=>{const i=e,r=-t,n=s/2/Math.sqrt(t*t+e*e);return[i*n,r*n]},Zt=(t,e,s,i,r,n,a,h)=>{const o=s-t,c=i-e,l=r-t,u=n-e;let p=0;p=0===o?c>0?.5*Math.PI:1.5*Math.PI:0===c?o>0?0:Math.PI:o>=0&&c>=0?Math.atan(c/o):o<=0&&c>=0?Math.atan(-o/c)+.5*Math.PI:o<=0&&c<=0?Math.atan(c/o)+Math.PI:Math.atan(o/-c)+1.5*Math.PI;let f=0;f=0===l?u>0?.5*Math.PI:1.5*Math.PI:0===u?l>0?0:Math.PI:l>=0&&u>=0?Math.atan(u/l):l<=0&&u>=0?Math.atan(-l/u)+.5*Math.PI:l<=0&&u<=0?Math.atan(u/l)+Math.PI:Math.atan(l/-u)+1.5*Math.PI,p>f&&(p-=2*Math.PI);const d=Math.sqrt((s-t)*(s-t)+(i-e)*(i-e)),x=2*Math.PI*d/3,g=a.length/2;a.push(t,e,s,i);for(let y=1;y<x;y++){const s=p+y/x*(f-p),i=t+d*Math.cos(s),r=e+d*Math.sin(s);a.push(i,r)}a.push(r,n);for(let y=1;y<a.length/2-g-1;y++)h.push(0+g,y+g,y+1+g)},$t=(t,e)=>{const{vertices:s,shape:i,lineStyle:r}=t,{width:n,cap:o,join:c,miterLimit:l}=r;let u=0,p=!1;if(i instanceof q?i.closeStroke&&(p=!0):p=!0,p){const t=s[0],e=s[1],i=s[s.length-2],r=s[s.length-1];Math.abs(t-i)<1e-4&&Math.abs(e-r)<1e-4&&(s.pop(),s.pop());const n=(t+s[s.length-2])/2,a=(e+s[s.length-1])/2;s.unshift(n,a),s.push(n,a)}const f=new v(r);e.batchParts.push(f),f.start(e.vertices.length/2,e.indices.length);const d=[],x=[],g=s[0],y=s[1],m=s[2],b=s[3],[w,M]=qt(m-g,b-y,n);if(!p){if(o===a.SQUARE){const t=M,e=-w;d.push(g+w,y+M,g+w+t,y+M+e,g-w+t,y-M+e,g-w,y-M),x.push(0,1,2,0,2,3)}o===a.ROUND&&Zt(g,y,g-w,y-M,g+w,y+M,d,x),a.BUTT}u=d.length/2,d.push(g-w,y-M,g+w,y+M);for(let a=2;a<s.length-2;a+=2){const t=s[a-2],e=s[a-1],i=s[a],r=s[a+1],o=s[a+2],p=s[a+3],[f,g]=qt(i-t,r-e,n),[y,v]=qt(o-i,p-r,n),m=i-t,b=r-e,w=o-i,M=p-r,P=w*b-m*M,T=m*w+b*M;if(Math.abs(P)<.001*Math.abs(T)){d.push(i+f,r+g,i-f,r-g),x.push(0+u,1+u,2+u,0+u,2+u,3+u),u=d.length/2,T>0?d.push(i-f,r-g,i+f,r+g):(c===h.ROUND&&(Zt(i,r,i+f,r+g,i-f,r-g,d,x),u=d.length/2),c===h.BEVEL||h.MITER,d.push(i+f,r+g,i-f,r-g));continue}const[_,E]=zt(t+f,e+g,i+f,r+g,i+y,r+v,o+y,p+v),[B,A]=zt(t-f,e-g,i-f,r-g,i-y,r-v,o-y,p-v);let I=c;c===h.MITER&&(((B-_)**2+(A-E)**2)/n**2<=l**2||(I=h.BEVEL));const S=m*m+b*b+(n/2)**2,C=w*w+M*M+(n/2)**2;(B-i)**2+(A-r)**2<Math.min(S,C)?(I===h.BEVEL&&(P>0?(d.push(_,E,i-f,r-g),x.push(0+u,1+u,2+u,0+u,2+u,3+u),u=d.length/2,d.push(_,E,i-f,r-g,i-y,r-v),x.push(0+u,1+u,2+u),u=d.length/2,d.push(i-y,r-v,_,E)):(d.push(i+f,r+g,B,A),x.push(0+u,1+u,2+u,0+u,2+u,3+u),u=d.length/2,d.push(B,A,i+f,r+g,i+y,r+v),x.push(0+u,1+u,2+u),u=d.length/2,d.push(B,A,i+y,r+v))),I===h.MITER&&(d.push(_,E,B,A),x.push(0+u,1+u,2+u,0+u,2+u,3+u),u=d.length/2,d.push(B,A,_,E)),I===h.ROUND&&(P<0?(d.push(i+f,r+g,B,A),x.push(0+u,1+u,2+u,0+u,2+u,3+u),u=d.length/2,d.push(B,A,i+f,r+g,i,r),x.push(0+u,1+u,2+u),u=d.length/2,d.push(B,A,i+y,r+v,i,r),x.push(0+u,1+u,2+u),u=d.length/2,Zt(i,r,i+f,r+g,i+y,r+v,d,x),u=d.length/2,d.push(B,A,i+y,r+v)):(d.push(_,E,i-f,r-g),x.push(0+u,1+u,2+u,0+u,2+u,3+u),u=d.length/2,d.push(_,E,i-f,r-g,i,r),x.push(0+u,1+u,2+u),u=d.length/2,d.push(_,E,i-y,r-v,i,r),x.push(0+u,1+u,2+u),u=d.length/2,Zt(i,r,i-y,r-v,i-f,r-g,d,x),u=d.length/2,d.push(i-y,r-v,_,E)))):(d.push(i+f,r+g,i-f,r-g),x.push(0+u,1+u,2+u,0+u,2+u,3+u),u=d.length/2,I===h.BEVEL&&(P>0?(d.push(i,r,i-f,r-g,i-y,r-v),x.push(0+u,1+u,2+u)):(d.push(i,r,i+f,r+g,i+y,r+v),x.push(0+u,1+u,2+u))),I===h.MITER&&(P>0?(d.push(i,r,i-f,r-g,B,A,i-y,r-v),x.push(0+u,1+u,2+u,0+u,2+u,3+u)):(d.push(i,r,i+f,r+g,_,E,i+y,r+v),x.push(0+u,1+u,2+u,0+u,2+u,3+u))),I===h.ROUND&&(P>0?Zt(i,r,i-y,r-v,i-f,r-g,d,x):Zt(i,r,i+f,r+g,i+y,r+v,d,x)),u=d.length/2,d.push(i-y,r-v,i+y,r+v))}const P=s[s.length-2],T=s[s.length-1],_=s[s.length-4],E=s[s.length-3],[B,A]=qt(P-_,T-E,n);if(d.push(P+B,T+A,P-B,T-A),x.push(0+u,1+u,2+u,0+u,2+u,3+u),u=d.length/2,!p){const t=s[s.length-2],e=s[s.length-1],i=s[s.length-4],r=s[s.length-3],[h,c]=qt(t-i,e-r,n);if(o===a.SQUARE){const s=-c,i=h;d.push(t+h,e+c,t+h+s,e+c+i,t-h+s,e-c+i,t-h,e-c),x.push(0+u,1+u,2+u,0+u,2+u,3+u)}o===a.ROUND&&Zt(t,e,t+h,e+c,t-h,e-c,d,x)}e.vertices.concat(d),e.indices.concat(x),f.end(d.length/2,x.length)},Xt=class{graphicsData=[];dirty=!1;shapeIndex=0;batchParts=[];vertices=new H;indices=new W;drawShape(t,e,s){const i=new X(t,e,s);this.graphicsData.push(i),this.dirty=!0}containsPoint(t){for(let e=0;e<this.graphicsData.length;e++){const{shape:s,fillStyle:i}=this.graphicsData[e];if(i.visible&&s.contains(t))return!0}return!1}buildVerticesAndTriangulate(){if(this.dirty){this.dirty=!1;for(let t=this.shapeIndex;t<this.graphicsData.length;t++){const e=this.graphicsData[t];Gt(e),e.fillStyle.visible&&Yt(e,this),e.lineStyle.visible&&$t(e,this)}this.shapeIndex=this.graphicsData.length}}clear(){this.graphicsData=[],this.vertices.clear(),this.indices.clear(),this.batchParts=[],this.shapeIndex=0,this.dirty=!1}},Ht=class extends k{_lineStyle=new $;_fillStyle=new Z;geometry=new Xt;currentPath=new q;type;constructor(){super(),this.type="graphics"}lineStyle(t,e="#000000",s=1){if(this.startPoly(),"object"==typeof t)Object.assign(this._lineStyle,t);else{const i={width:t,color:e,alpha:s};Object.assign(this._lineStyle,i)}return this._lineStyle.visible=!0,this}resetLineStyle=()=>{this._lineStyle.reset()};drawShape=t=>(this.geometry.drawShape(t,this._fillStyle.clone(),this._lineStyle.clone()),this.markStructureDirty(),this);startPoly=()=>{this.currentPath.points.length>2&&this.drawShape(this.currentPath),this.currentPath=new q};beginFill=(t="#000000",e=1)=>(this.startPoly(),this._fillStyle.color=t,this._fillStyle.alpha=e,this._fillStyle.alpha>0&&(this._fillStyle.visible=!0),this);endFill=()=>(this.startPoly(),this._fillStyle.reset(),this);drawRect=(t,e,s,i)=>this.drawShape(new p(t,e,s,i));drawCircle=(t,e,s)=>this.drawShape(new Dt(t,e,s));drawRoundedRect=(t,e,s,i,r)=>this.drawShape(new Ot(t,e,s,i,r));drawEllipse=(t,e,s,i)=>this.drawShape(new kt(t,e,s,i));drawPolygon=t=>{const e=new q(t);return e.closeStroke=!0,this.drawShape(e)};moveTo=(t,e)=>(this.startPoly(),this.currentPath.points[0]=t,this.currentPath.points[1]=e,this);lineTo=(t,e)=>{if(0===this.currentPath.points.length)return this.moveTo(t,e),this;const s=this.currentPath.points,i=s[s.length-2],r=s[s.length-1];return i===t&&r===e||s.push(t,e),this};closePath=()=>(this.currentPath.closeStroke=!0,this.startPoly(),this);containsPoint=t=>this.hitArea?this.hitArea.contains(t):this.geometry.containsPoint(t);quadraticCurveTo=(t,e,s,i)=>{const r=this.currentPath.points.length;0===r&&(this.currentPath.points=[0,0]);const n=this.currentPath.points[r-2],a=this.currentPath.points[r-1],h=t,o=e,c=s,l=i,u=((t,e,s,i,r,n)=>{const a=2*(t-2*s+r),h=-2*(t-s),o=2*(e-2*i+n),c=-2*(e-i),l=a*a+o*o,u=2*(a*h+o*c),p=h*h+c*c,f=Math.sqrt((4*l*p-u*u)/4),d=(l/2+u/4)*Math.sqrt((l+u/2)*(l+u/2)+f*f)+f*f/2*Math.log(Math.abs(l+u/2+Math.sqrt((l+u/2)*(l+u/2)+f*f))),x=u/4*Math.sqrt(u*u/4+f*f)+f*f/2*Math.log(u/2+Math.sqrt(u*u/4+f*f));return 1/(Math.sqrt(l)*l)*(d-x)})(n,a,h,o,c,l);let p=Math.ceil(u/10);p>2048&&(p=2048),p<8&&(p=8);for(let f=1;f<=p;f++){const t=f/p,e=(1-t)*(1-t)*n+2*t*(1-t)*h+t*t*c,s=(1-t)*(1-t)*a+2*t*(1-t)*o+t*t*l;this.currentPath.points.push(e,s)}return this};bezierCurveTo=(t,e,s,i,r,n)=>{const a=this.currentPath.points.length;0===a&&(this.currentPath.points=[0,0]);const h=this.currentPath.points[a-2],o=this.currentPath.points[a-1],c=t,l=e,u=s,p=i,f=r,d=n,x=((t,e,s,i,r,n,a,h)=>{let o=t,c=e,l=0;for(let u=1;u<=10;u++){const p=u/10,f=(1-p)*(1-p)*(1-p)*t+3*p*(1-p)*(1-p)*s+3*p*p*(1-p)*r+p*p*p*a,d=(1-p)*(1-p)*(1-p)*e+3*p*(1-p)*(1-p)*i+3*p*p*(1-p)*n+p*p*p*h,x=f-o,g=d-c;l+=Math.sqrt(x*x+g*g),o=f,c=d}return l})(h,o,c,l,u,p,f,d);let g=Math.ceil(x/10);g>2048&&(g=2048),g<8&&(g=8);for(let y=1;y<=g;y++){const t=y/g,e=(1-t)*(1-t)*(1-t)*h+3*t*(1-t)*(1-t)*c+3*t*t*(1-t)*u+t*t*t*f,s=(1-t)*(1-t)*(1-t)*o+3*t*(1-t)*(1-t)*l+3*t*t*(1-t)*p+t*t*t*d;this.currentPath.points.push(e,s)}return this};arc=(t,e,s,i,r,n=!1)=>{if(!n){for(;r<i;)r+=2*Math.PI;r-i>2*Math.PI&&(r=i+2*Math.PI)}if(n){for(;r>i;)i+=2*Math.PI;i-r>2*Math.PI&&(r=i-2*Math.PI)}const a=r-i;if(0===a)return this;const h=t+Math.cos(i)*s,o=e+Math.sin(i)*s;this.lineTo(h,o);const c=Math.abs(a)*s;let l=Math.ceil(c/10);l>2048&&(l=2048),l<8&&(l=8);for(let u=1;u<=l;u++){const r=i+a*(u/l),n=t+Math.cos(r)*s,h=e+Math.sin(r)*s;this.lineTo(n,h)}return this};arcTo=(t,e,s,i,r)=>{if(!this.currentPath)return this;const n=this.currentPath.points.length;if(0===n||0===r)return this.lineTo(t,e),this;const a=this.currentPath.points[n-1]-e,h=this.currentPath.points[n-2]-t,o=i-e,c=s-t,l=a*c-h*o,u=Math.abs(l);if(u<1e-8)return this.lineTo(t,e),this;const p=a*a+h*h,f=o*o+c*c,d=a*o+h*c,x=r*Math.sqrt(p)/u,g=r*Math.sqrt(f)/u,y=x*d/p,v=g*d/f,m=x*c+g*h,b=x*o+g*a,w=h*(g+y),M=a*(g+y),P=c*(x+v),T=o*(x+v),_=Math.atan2(M-b,w-m),E=Math.atan2(T-b,P-m),B=h*o>c*a;return this.arc(m+t,b+e,r,_,E,B)};clear=()=>(this.geometry.clear(),this._lineStyle.reset(),this._fillStyle.reset(),this.currentPath=new q,this.batches=[],this.batchCount=0,this.markStructureDirty(),this);renderCanvas=t=>{this.startPoly();const e=t.ctx,{a:s,b:i,c:r,d:n,tx:a,ty:h}=this.transform.worldTransform;e.setTransform(s,i,r,n,a,h);const o=this.geometry.graphicsData;for(let c=0;c<o.length;c++){const{lineStyle:t,fillStyle:s,shape:i}=o[c];if(s.visible&&(e.fillStyle=s.color),t.visible&&(e.lineWidth=t.width,e.lineCap=t.cap,e.lineJoin=t.join,e.strokeStyle=t.color),e.beginPath(),i instanceof p){const{x:r,y:n,width:a,height:h}=i;s.visible&&(e.globalAlpha=s.alpha*this.worldAlpha,e.fillRect(r,n,a,h)),t.visible&&(e.globalAlpha=t.alpha*this.worldAlpha,e.strokeRect(r,n,a,h))}if(i instanceof Dt){const{x:r,y:n,radius:a}=i;e.arc(r,n,a,0,2*Math.PI),s.visible&&(e.globalAlpha=s.alpha*this.worldAlpha,e.fill()),t.visible&&(e.globalAlpha=t.alpha*this.worldAlpha,e.stroke())}if(i instanceof Ot){const{x:r,y:n,width:a,height:h,radius:o}=i;e.moveTo(r+o,n),e.arc(r+o,n+o,o,1.5*Math.PI,Math.PI,!0),e.lineTo(r,n+h-o),e.arc(r+o,n+h-o,o,Math.PI,Math.PI/2,!0),e.lineTo(r+a-o,n+h),e.arc(r+a-o,n+h-o,o,Math.PI/2,0,!0),e.lineTo(r+a,n+o),e.arc(r+a-o,n+o,o,0,1.5*Math.PI,!0),e.closePath(),s.visible&&(e.globalAlpha=s.alpha*this.worldAlpha,e.fill()),t.visible&&(e.globalAlpha=t.alpha*this.worldAlpha,e.stroke())}if(i instanceof kt){const{x:r,y:n,radiusX:a,radiusY:h}=i;e.ellipse(r,n,a,h,0,0,2*Math.PI),s.visible&&(e.globalAlpha=s.alpha*this.worldAlpha,e.fill()),t.visible&&(e.globalAlpha=t.alpha*this.worldAlpha,e.stroke())}if(i instanceof q){const{points:r,closeStroke:n}=i;e.moveTo(r[0],r[1]);for(let t=2;t<r.length;t+=2)e.lineTo(r[t],r[t+1]);n&&e.closePath(),s.visible&&(e.globalAlpha=s.alpha*this.worldAlpha,e.fill()),t.visible&&(e.globalAlpha=t.alpha*this.worldAlpha,e.stroke())}}};buildBatches=t=>{this.startPoly(),this.worldId=this.transform.worldId,this.geometry.buildVerticesAndTriangulate();const e=this.geometry.batchParts;for(let s=0;s<e.length;s++){const{style:i,vertexStart:r,vertexCount:n,indexStart:a,indexCount:h}=e[s],{color:o,alpha:c}=i,l=S(o,c*this.worldAlpha),u=M.get(this.type);u.vertexCount=n,u.indexCount=h,u.rgba=l,u.vertexOffset=r,u.indexOffset=a,u.graphics=this,this.batches[s]=u,t.addBatch(this.batches[s])}this.batchCount=e.length};updateBatches=t=>{if(this.worldId!==this.transform.worldId){this.worldId=this.transform.worldId;for(let e=0;e<this.batchCount;e++)this.batches[e].updateVertices(t)}}};export{z as Application,l as BYTES_PER_VERTEX,k as Container,Ht as Graphics,a as LINE_CAP,h as LINE_JOIN,c as MAX_VERTEX_COUNT,o as RENDERER_TYPE,n as SHAPE_TYPE};
1
+ import{i as t,n as e,r as s,t as r}from"../../../enums-BAgbyGdH.js";var i,n=/* @__PURE__ */function(t){return t.RECTANGLE="rectangle",t.POLYGON="polygon",t.CIRCLE="circle",t.ELLIPSE="ellipse",t.ROUNDED_RECTANGLE="rounded rectangle",t}({}),a=/* @__PURE__ */function(t){return t.BUTT="butt",t.ROUND="round",t.SQUARE="square",t}({}),h=/* @__PURE__ */function(t){return t.MITER="miter",t.BEVEL="bevel",t.ROUND="round",t}({}),o=/* @__PURE__ */function(t){return t.WEB_GL="webgl",t.CANVAS="canvas",t.WEB_GPU="webgpu",t}({}),l=65536,c=12,u=class{},f=class extends u{x;y;width;height;type=n.RECTANGLE;constructor(t=0,e=0,s=0,r=0){super(),this.x=t,this.y=e,this.width=s,this.height=r}contains(t){return t.x>this.x&&t.x<this.x+this.width&&t.y>this.y&&t.y<this.y+this.height}},p=class{canvasEle;screen=new f;filters=[];constructor(t){const{view:e}=t;this.canvasEle=e,this.screen.width=e.width,this.screen.height=e.height}resizeView(t,e){this.canvasEle.width=t,this.canvasEle.height=e}async init(){return Promise.resolve()}},d=class extends p{ctx;backgroundColor;backgroundAlpha;constructor(t){super(t),t.debug;const{backgroundColor:e,backgroundAlpha:s}=t;this.backgroundColor=e,this.backgroundAlpha=s,this.ctx=this.canvasEle.getContext("2d")}render(t){t.updateTransform(),this.ctx.save(),this.ctx.clearRect(0,0,this.screen.width,this.screen.height),this.backgroundAlpha&&(this.ctx.globalAlpha=this.backgroundAlpha),this.backgroundColor&&(this.ctx.fillStyle=this.backgroundColor),this.ctx.fillRect(0,0,this.screen.width,this.screen.height),t.renderCanvasRecursive(this),this.ctx.restore()}},g=(t,e)=>{if(e.worldAlpha<=0||!e.visible)return;e.buildBatches(t);const s=e.children;for(let r=0;r<s.length;r++)g(t,s[r])},x=(t,e)=>{if(e.worldAlpha<=0||!e.visible)return;e.updateBatches(t);const s=e.children;for(let r=0;r<s.length;r++)x(t,s[r])},v=class{vertexCount=0;indexCount=0;rgba=0;vertexStart=0;indexStart=0},y=class{style;vertexStart=0;indexStart=0;vertexCount=0;indexCount=0;constructor(t){this.style=t}start(t,e){this.vertexStart=t,this.indexStart=e}end(t,e){this.vertexCount=t,this.indexCount=e}},m=class{idx=0;reset(){this.idx=0}},b=class extends m{batches=[];constructor(){super()}getOne(){return this.batches[this.idx]||(this.batches[this.idx]=new w),this.batches[this.idx++]}},w=class extends v{vertexOffset=0;indexOffset=0;graphics;packVertices(t,e){const s=this.graphics.geometry.vertices.data,r=this.vertexOffset;for(let i=0;i<this.vertexCount;i++){const n=s[2*(r+i)],a=s[2*(r+i)+1],{a:h,b:o,c:l,d:c,tx:u,ty:f}=this.graphics.worldTransform,p=h*n+l*a+u,d=o*n+c*a+f,g=3*(this.vertexStart+i);t[g]=p,t[g+1]=d,e[g+2]=this.rgba}}packIndices(t){const e=this.graphics.geometry.indices.data,s=this.indexOffset;for(let r=0;r<this.indexCount;r++)t[this.indexStart+r]=e[r+s]+this.vertexStart}updateVertices(t){const e=this.graphics.geometry.vertices.data,s=this.vertexOffset,{a:r,b:i,c:n,d:a,tx:h,ty:o}=this.graphics.worldTransform;for(let l=0;l<this.vertexCount;l++){const c=e[2*(s+l)],u=e[2*(s+l)+1],f=3*(this.vertexStart+l);t[f]=r*c+n*u+h,t[f+1]=i*c+a*u+o}}},E=new class{batchesMap={graphics:new b};get(t){return this.batchesMap[t].getOne()}reset(){Object.values(this.batchesMap).forEach(t=>{t.reset()})}},_=class extends p{builtVersion=-1;vertexCount=0;indexCount=0;batches=[];batchesCount=0;vertFloatView;vertIntView;indexBuffer;curVertBufferLength=0;curIndexBufferLength=0;constructor(t){super(t);const e=/* @__PURE__ */new ArrayBuffer(3072);this.vertFloatView=new Float32Array(e),this.vertIntView=new Uint32Array(e),this.indexBuffer=/* @__PURE__ */new Uint32Array(256)}addBatch(t){t.vertexStart=this.vertexCount,t.indexStart=this.indexCount,this.vertexCount+=t.vertexCount,this.indexCount+=t.indexCount,this.batches[this.batchesCount]=t,this.batchesCount++}startBuild(){this.vertexCount=0,this.indexCount=0,this.batchesCount=0,E.reset()}buildEnd(){this.resizeBufferIfNeeded(),this.packData()}resizeBufferIfNeeded(){if(12*this.vertexCount>this.vertFloatView.byteLength){const t=new ArrayBuffer(12*this.vertexCount);this.vertFloatView=new Float32Array(t),this.vertIntView=new Uint32Array(t)}this.indexCount>this.indexBuffer.length&&(this.indexBuffer=new Uint32Array(this.indexCount))}packData(){for(let t=0;t<this.batchesCount;t++){const e=this.batches[t];this.batches[t]=void 0,e?.packVertices(this.vertFloatView,this.vertIntView),e?.packIndices(this.indexBuffer)}}updateChildrenTransform(t){t.sortChildren();const e=t.transform.shouldUpdateLocalTransform;if(t.transform.updateLocalTransform(),e){const{a:e,b:s,c:r,d:i,tx:n,ty:a}=t.transform.localTransform;this.setRootTransform(e,s,r,i,n,a)}t.worldAlpha=t.alpha;const s=t.children;for(let r=0;r<s.length;r++)s[r].updateTransform()}render(t){this.updateChildrenTransform(t),this.builtVersion!==t.structureVersion?(this.startBuild(),g(this,t),this.buildEnd(),this.builtVersion=t.structureVersion):x(this.vertFloatView,t),this.updateBuffer(),this.draw()}},M="\nprecision highp float;\nattribute vec2 a_position;\nattribute vec4 a_color;\nvarying vec4 v_color;\nuniform mat3 u_root_transform;\nuniform mat3 u_projection_matrix;\nvoid main(){\n v_color = a_color;\n gl_Position = vec4((u_projection_matrix * u_root_transform * vec3(a_position, 1.0)).xy, 0.0, 1.0);\n}\n".trim(),T="\nprecision mediump float;\nvarying vec4 v_color;\nvoid main(){\n gl_FragColor = v_color;\n}\n".trim(),P=(t,e,s)=>{const r=t.createShader(e);if(t.shaderSource(r,s),t.compileShader(r),t.getShaderParameter(r,t.COMPILE_STATUS))return r;{const e=t.getShaderInfoLog(r);throw t.deleteShader(r),console.error(`shader compilation failed: ${e}`),new Error(`shader compilation failed: ${e}`)}},A=(t,e)=>{const s=t.getAttribLocation(e,"a_position");t.vertexAttribPointer(s,2,t.FLOAT,!1,12,0),t.enableVertexAttribArray(s);const r=t.getAttribLocation(e,"a_color");t.vertexAttribPointer(r,4,t.UNSIGNED_BYTE,!0,12,8),t.enableVertexAttribArray(r)},B=t=>{const e=t.gl,s=((t,e,s)=>{const r=t.createProgram();if(!r)throw console.error("failed to create the program"),new Error("failed to create the program");if(t.attachShader(r,e),t.attachShader(r,s),t.linkProgram(r),!t.getProgramParameter(r,t.LINK_STATUS)){const i=t.getProgramInfoLog(r);throw console.error(`link failed: ${i}`),t.deleteProgram(r),t.deleteShader(e),t.deleteShader(s),new Error(`link failed: ${i}`)}return t.useProgram(r),r})(e,P(e,e.VERTEX_SHADER,M),P(e,e.FRAGMENT_SHADER,T));return e.enable(e.BLEND),e.blendFunc(e.ONE,e.ONE_MINUS_SRC_ALPHA),s},I=/* @__PURE__ */new Map,R=t=>{const e=I.get(t);if(e)return e;let s;if(/^#?[0-9a-fA-F]{3}$/.test(t)){const e=t.replace("#","");s=[parseInt(e[0]+e[0],16),parseInt(e[1]+e[1],16),parseInt(e[2]+e[2],16)]}else if(/^#?[0-9a-fA-F]{6}$/.test(t)){const e=parseInt(t.replace("#",""),16);s=[e>>16&255,e>>8&255,255&e]}else s=(t=>{if(void 0===i&&(i="undefined"!=typeof document?document.createElement("canvas").getContext("2d"):null),!i)return[0,0,0];i.fillStyle="#000",i.fillStyle=t,i.fillRect(0,0,1,1);const[e,s,r]=i.getImageData(0,0,1,1).data;return[e,s,r]})(t);return I.set(t,s),s},S=(t,e)=>{const[s,r,i]=R(t).map(t=>Math.round(t*e));let n=0;return n+=Math.round(255*e)<<24,n+=i<<16,n+=r<<8,n+=s,n},C=t=>{const[e,s,r]=R(t);return[e/255,s/255,r/255]},U=class{gl;framebuffer;texture;width=0;height=0;constructor(t){this.gl=t;const e=this.gl;this.texture=e.createTexture(),e.bindTexture(e.TEXTURE_2D,this.texture),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),this.framebuffer=e.createFramebuffer(),e.bindFramebuffer(e.FRAMEBUFFER,this.framebuffer),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,this.texture,0),e.bindFramebuffer(e.FRAMEBUFFER,null)}resize(t,e){if(t===this.width&&e===this.height)return;this.width=t,this.height=e;const s=this.gl;s.bindTexture(s.TEXTURE_2D,this.texture),s.texImage2D(s.TEXTURE_2D,0,s.RGBA,t,e,0,s.RGBA,s.UNSIGNED_BYTE,null)}bind(){const t=this.gl;t.bindFramebuffer(t.FRAMEBUFFER,this.framebuffer),t.viewport(0,0,this.width,this.height)}dispose(){this.gl.deleteFramebuffer(this.framebuffer),this.gl.deleteTexture(this.texture)}},L=class extends _{gl;program;glVertexBuffer;glIndexBuffer;unifLoc;targetA;targetB;quadBuffer;constructor(t){super(t),t.debug,this.gl=this.canvasEle.getContext("webgl",{antialias:!0}),this.gl.getExtension("OES_element_index_uint"),this.program=B(this),this.glVertexBuffer=this.gl.createBuffer(),this.glIndexBuffer=this.gl.createBuffer(),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.glVertexBuffer),this.gl.bindBuffer(this.gl.ELEMENT_ARRAY_BUFFER,this.glIndexBuffer),A(this.gl,this.program),this.unifLoc={u_root_transform:this.gl.getUniformLocation(this.program,"u_root_transform"),u_projection_matrix:this.gl.getUniformLocation(this.program,"u_projection_matrix")};const e=t.backgroundAlpha??0,[s,r,i]=C(t.backgroundColor??"");this.gl.clearColor(s*e,r*e,i*e,e),this.setRootTransform(1,0,0,1,0,0),this.setProjectionMatrix()}setProjectionMatrix(){const t=1/this.canvasEle.width*2,e=1/this.canvasEle.height*2;this.gl.uniformMatrix3fv(this.unifLoc.u_projection_matrix,!1,new Float32Array([t,0,0,0,-e,0,-1,1,1]))}setRootTransform(t,e,s,r,i,n){this.gl.uniformMatrix3fv(this.unifLoc.u_root_transform,!1,new Float32Array([t,e,0,s,r,0,i,n,1]))}updateBuffer(){const t=this.gl;t.bindBuffer(t.ARRAY_BUFFER,this.glVertexBuffer),t.bufferData(t.ARRAY_BUFFER,this.vertFloatView,t.DYNAMIC_DRAW),t.bindBuffer(t.ELEMENT_ARRAY_BUFFER,this.glIndexBuffer),t.bufferData(t.ELEMENT_ARRAY_BUFFER,this.indexBuffer,t.DYNAMIC_DRAW)}draw(){const t=this.gl,e=this.canvasEle.width,s=this.canvasEle.height;if(0===this.filters.length)return t.bindFramebuffer(t.FRAMEBUFFER,null),t.viewport(0,0,e,s),t.clear(t.COLOR_BUFFER_BIT),void t.drawElements(t.TRIANGLES,this.indexCount,t.UNSIGNED_INT,0);this.ensurePostResources(e,s);const r=this.targetA,i=this.targetB;r.bind(),t.clear(t.COLOR_BUFFER_BIT),t.drawElements(t.TRIANGLES,this.indexCount,t.UNSIGNED_INT,0);let n=r,a=i;for(let h=0;h<this.filters.length;h++){const r=h===this.filters.length-1;if(this.filters[h].apply(t,this.quadBuffer,n.texture,r?null:a,e,s),!r){const t=n;n=a,a=t}}t.useProgram(this.program),t.bindBuffer(t.ARRAY_BUFFER,this.glVertexBuffer),t.bindBuffer(t.ELEMENT_ARRAY_BUFFER,this.glIndexBuffer),A(t,this.program)}ensurePostResources(t,e){const s=this.gl;this.quadBuffer||(this.quadBuffer=s.createBuffer(),s.bindBuffer(s.ARRAY_BUFFER,this.quadBuffer),s.bufferData(s.ARRAY_BUFFER,new Float32Array([-1,-1,1,-1,-1,1,1,1]),s.STATIC_DRAW),this.targetA=new U(s),this.targetB=new U(s)),this.targetA?.resize(t,e),this.targetB?.resize(t,e)}},F=class extends _{gpu;device;pipeline;renderPassDescriptor;options;gpuVertexBuffer;gpuIndexBuffer;projectionMatBuffer;stageMatBuffer;uniformBindGroup;constructor(t){super(t),t.debug,this.options=t,this.gpu=this.canvasEle.getContext("webgpu"),this.curVertBufferLength=256,this.curIndexBufferLength=256}async init(){await this.initDevice(),this.initGpuBuffer(),this.initRenderPassDescriptor(),this.createPipeline(),this.initUniformBindGroup(),this.setRootTransform(1,0,0,1,0,0),this.setProjectionMatrix()}draw(){const{device:t,renderPassDescriptor:e,gpuVertexBuffer:s,gpuIndexBuffer:r,gpu:i,uniformBindGroup:n,indexCount:a,pipeline:h}=this,o=t.createCommandEncoder(),l=[...e.colorAttachments];l?.[0]?.view&&(l[0].view=i.getCurrentTexture().createView());const c=o.beginRenderPass(e);c.setPipeline(h),c.setVertexBuffer(0,s),c.setIndexBuffer(r,"uint32"),c.setBindGroup(0,n),c.drawIndexed(a),c.end();const u=o.finish();t.queue.submit([u])}initUniformBindGroup(){const t=this.device;this.stageMatBuffer=t.createBuffer({label:"stage-matrix-uniform-buffer",size:12*Float32Array.BYTES_PER_ELEMENT,usage:GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST}),this.projectionMatBuffer=t.createBuffer({label:"projection-matrix-uniform-buffer",size:12*Float32Array.BYTES_PER_ELEMENT,usage:GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST}),this.uniformBindGroup=this.device.createBindGroup({label:"my-uniform-bind-group",layout:this.pipeline.getBindGroupLayout(0),entries:[{binding:0,resource:{buffer:this.stageMatBuffer}},{binding:1,resource:{buffer:this.projectionMatBuffer}}]})}initGpuBuffer(){const t=this.device;this.gpuVertexBuffer=t.createBuffer({label:"my-gpu-vertex-buffer",size:12*this.curVertBufferLength,usage:GPUBufferUsage.VERTEX|GPUBufferUsage.COPY_DST}),this.gpuIndexBuffer=t.createBuffer({label:"my-gpu-index-buffer",size:this.curIndexBufferLength*Uint32Array.BYTES_PER_ELEMENT,usage:GPUBufferUsage.INDEX|GPUBufferUsage.COPY_DST})}updateBuffer(){const t=this.device;this.vertexCount>this.curVertBufferLength&&(this.gpuVertexBuffer.destroy(),this.gpuVertexBuffer=t.createBuffer({label:"my-gpu-vertex-buffer",size:12*this.vertexCount,usage:GPUBufferUsage.VERTEX|GPUBufferUsage.COPY_DST}),this.curVertBufferLength=this.vertexCount),t.queue.writeBuffer(this.gpuVertexBuffer,0,this.vertFloatView.buffer),this.indexCount>this.curIndexBufferLength&&(this.gpuIndexBuffer.destroy(),this.gpuIndexBuffer=t.createBuffer({label:"my-gpu-index-buffer",size:this.indexCount*Uint32Array.BYTES_PER_ELEMENT,usage:GPUBufferUsage.INDEX|GPUBufferUsage.COPY_DST}),this.curIndexBufferLength=this.indexCount),t.queue.writeBuffer(this.gpuIndexBuffer,0,this.indexBuffer.buffer)}setRootTransform(t,e,s,r,i,n){this.device.queue.writeBuffer(this.stageMatBuffer,0,new Float32Array([t,e,0,0,s,r,0,0,i,n,1,0]))}setProjectionMatrix(){const t=1/this.canvasEle.width*2,e=1/this.canvasEle.height*2;this.device.queue.writeBuffer(this.projectionMatBuffer,0,new Float32Array([t,0,0,0,0,-e,0,0,-1,1,1,0]))}createPipeline(){this.pipeline=this.device.createRenderPipeline({layout:"auto",label:"my-render-pipeline",vertex:{module:this.device.createShaderModule({code:"\n@group(0) @binding(0) var<uniform> u_root_transform: mat3x3<f32>;\n@group(0) @binding(1) var<uniform> u_projection_matrix: mat3x3<f32>;\n\nstruct VertOutput {\n @builtin(position) v_position: vec4<f32>,\n @location(0) v_color : vec4<f32>,\n};\n\n@vertex\nfn main(\n @location(0) a_position: vec2<f32>,\n @location(1) a_color: vec4<f32>,\n) -> VertOutput {\n let v_position = vec4<f32>((u_projection_matrix * u_root_transform * vec3<f32>(a_position, 1.0)).xy, 0.0, 1.0);\n\n let v_color = a_color;\n\n return VertOutput(v_position, v_color);\n}\n",label:"my-vert-shader-module"}),entryPoint:"main",buffers:[{arrayStride:12,attributes:[{shaderLocation:0,format:"float32x2",offset:0},{shaderLocation:1,format:"unorm8x4",offset:2*Float32Array.BYTES_PER_ELEMENT}]}]},fragment:{module:this.device.createShaderModule({code:"\n@fragment\nfn main(\n @location(0) v_color : vec4<f32>,\n) -> @location(0) vec4<f32> {\n return v_color;\n}\n",label:"my-frag-shader-module"}),entryPoint:"main",targets:[{format:navigator.gpu.getPreferredCanvasFormat(),blend:{alpha:{srcFactor:"one",dstFactor:"one-minus-src-alpha",operation:"add"},color:{srcFactor:"one",dstFactor:"one-minus-src-alpha",operation:"add"}}}]},primitive:{topology:"triangle-list"}})}async initDevice(){const t=await((await navigator.gpu.requestAdapter())?.requestDevice());t&&(this.gpu.configure({device:t,format:navigator.gpu.getPreferredCanvasFormat(),alphaMode:"premultiplied"}),this.device=t)}initRenderPassDescriptor(){const{backgroundColor:t="",backgroundAlpha:e=1}=this.options,s=e,[r,i,n]=C(t).map(t=>t*s);this.renderPassDescriptor={label:"my-render-pass-descriptor",colorAttachments:[{view:this.gpu.getCurrentTexture().createView(),storeOp:"store",loadOp:"clear",clearValue:[r,i,n,s]}]}}},D=class t{x;y;constructor(t=0,e=0){this.x=t,this.y=e}set(t=0,e=t){this.x=t,this.y=e}clone=()=>new t(this.x,this.y)},N=class{_x;_y;cb;constructor(t,e=0,s=0){this._x=e,this._y=s,this.cb=t}set(t=0,e=t){this._x=t,this._y=e,this.cb(this._x,this._y)}get x(){return this._x}set x(t){this._x!==t&&(this._x=t,this.cb(this._x,this._y))}get y(){return this._y}set y(t){this._y!==t&&(this._y=t,this.cb(this._x,this._y))}},V=class t{a;b;c;d;tx;ty;array=null;constructor(t=1,e=0,s=0,r=1,i=0,n=0){this.a=t,this.b=e,this.c=s,this.d=r,this.tx=i,this.ty=n}set=(t,e,s,r,i,n)=>(this.a=t,this.b=e,this.c=s,this.d=r,this.tx=i,this.ty=n,this);append=t=>{const{a:e,b:s,c:r,d:i,tx:n,ty:a}=this,{a:h,b:o,c:l,d:c,tx:u,ty:f}=t;return this.a=e*h+r*o,this.b=s*h+i*o,this.c=e*l+r*c,this.d=s*l+i*c,this.tx=e*u+r*f+n,this.ty=s*u+i*f+a,this};fromArray=t=>{this.a=t[0],this.b=t[1],this.c=t[3],this.d=t[4],this.tx=t[2],this.ty=t[5]};translate=(t,e)=>(this.tx+=t,this.ty+=e,this);scale=(t,e)=>(this.a*=t,this.d*=e,this.c*=t,this.b*=e,this.tx*=t,this.ty*=e,this);setTransform=(t,e,s,r,i,n,a,h,o)=>(this.a=Math.cos(a+o)*i,this.b=Math.sin(a+o)*i,this.c=-Math.sin(a-h)*n,this.d=Math.cos(a-h)*n,this.tx=t-(s*this.a+r*this.c),this.ty=e-(s*this.b+r*this.d),this);rotate=t=>{const e=Math.cos(t),s=Math.sin(t),r=this.a,i=this.c,n=this.tx;return this.a=r*e-this.b*s,this.b=r*s+this.b*e,this.c=i*e-this.d*s,this.d=i*s+this.d*e,this.tx=n*e-this.ty*s,this.ty=n*s+this.ty*e,this};equals=t=>t.a===this.a&&t.b===this.b&&t.c===this.c&&t.d===this.d&&t.tx===this.tx&&t.ty===this.ty;identity=()=>(this.a=1,this.b=0,this.c=0,this.d=1,this.tx=0,this.ty=0,this);decompose=t=>{const s=this.a,r=this.b,i=this.c,n=this.d,a=t.pivot,h=-Math.atan2(-i,n),o=Math.atan2(r,s),l=Math.abs(h+o);return l<1e-5||Math.abs(e-l)<1e-5?(t.rotation=o,t.skew.x=t.skew.y=0):(t.rotation=0,t.skew.x=h,t.skew.y=o),t.scale.x=Math.sqrt(s*s+r*r),t.scale.y=Math.sqrt(i*i+n*n),t.position.x=this.tx+(a.x*s+a.y*i),t.position.y=this.ty+(a.x*r+a.y*n),t};apply=t=>{const e=new D,s=t.x,r=t.y;return e.x=this.a*s+this.c*r+this.tx,e.y=this.b*s+this.d*r+this.ty,e};applyInverse=t=>{const e=new D,s=1/(this.a*this.d+this.c*-this.b),r=t.x,i=t.y;return e.x=this.d*s*r+-this.c*s*i+(this.ty*this.c-this.tx*this.d)*s,e.y=this.a*s*i+-this.b*s*r+(-this.ty*this.a+this.tx*this.b)*s,e};prepend=t=>{const{a:e,b:s,c:r,d:i,tx:n,ty:a}=t,{a:h,b:o,c:l,d:c,tx:u,ty:f}=this;return this.a=e*h+r*o,this.b=s*h+i*o,this.c=e*l+r*c,this.d=s*l+i*c,this.tx=e*u+r*f+n,this.ty=s*u+i*f+a,this};clone=()=>{const e=new t;return e.a=this.a,e.b=this.b,e.c=this.c,e.d=this.d,e.tx=this.tx,e.ty=this.ty,e};toArray=(t,e)=>{this.array||(this.array=/* @__PURE__ */new Float32Array(9));const s=e||this.array;return t?(s[0]=this.a,s[1]=this.b,s[2]=0,s[3]=this.c,s[4]=this.d,s[5]=0,s[6]=this.tx,s[7]=this.ty,s[8]=1):(s[0]=this.a,s[1]=this.c,s[2]=this.tx,s[3]=this.b,s[4]=this.d,s[5]=this.ty,s[6]=0,s[7]=0,s[8]=1),s}},O=class{localTransform=new V;worldTransform=new V;position;scale;pivot;skew;_rotation=0;rotateMatrix=new V;skewMatrix=new V;scaleMatrix=new V;localMatrix=new V;shouldUpdateLocalTransform=!1;worldId=0;parentId=0;constructor(){this.position=new N(this.onChange),this.scale=new N(this.onScaleChange,1,1),this.pivot=new N(this.onChange),this.skew=new N(this.onSkewChange)}get rotation(){return this._rotation}set rotation(t){this._rotation=t,this.rotateMatrix.set(Math.cos(this.rotation),Math.sin(this.rotation),-Math.sin(this.rotation),Math.cos(this.rotation),0,0),this.shouldUpdateLocalTransform=!0}onSkewChange=(t,e)=>{this.skewMatrix.set(Math.cos(e),Math.sin(e),Math.sin(t),Math.cos(t),0,0),this.shouldUpdateLocalTransform=!0};onScaleChange=(t,e)=>{this.scaleMatrix.set(t,0,0,e,0,0),this.shouldUpdateLocalTransform=!0};onChange=()=>{this.shouldUpdateLocalTransform=!0};updateLocalTransform(){if(!this.shouldUpdateLocalTransform)return;const{a:t,b:e,c:s,d:r}=this.localMatrix.set(1,0,0,1,0,0).append(this.rotateMatrix).append(this.skewMatrix).append(this.scaleMatrix),i=t*this.pivot.x+s*this.pivot.y,n=e*this.pivot.x+r*this.pivot.y,a=this.position.x-i,h=this.position.y-n;this.localTransform.set(t,e,s,r,a,h),this.shouldUpdateLocalTransform=!1,this.parentId=-1}updateTransform(t){if(this.updateLocalTransform(),this.parentId!==t.worldId){const{a:e,b:s,c:r,d:i,tx:n,ty:a}=t.worldTransform,{a:h,b:o,c:l,d:c,tx:u,ty:f}=this.localTransform;this.worldTransform.set(e*h+r*o,s*h+i*o,e*l+r*c,s*l+i*c,e*u+r*f+n,s*u+i*f+a),this.parentId=t.worldId,this.worldId++}}},G=class extends t{_zIndex=0;parent=void 0;visible=!0;transform=new O;alpha=1;worldAlpha=1;hitArea=null;cursor="auto";get zIndex(){return this._zIndex}set zIndex(t){this._zIndex=t,this.parent&&(this.parent.isSort=!0)}get position(){return this.transform.position}get localTransform(){return this.transform.localTransform}get worldTransform(){return this.transform.worldTransform}get x(){return this.position.x}set x(t){this.transform.position.x=t}get y(){return this.position.y}set y(t){this.transform.position.y=t}get scale(){return this.transform.scale}get pivot(){return this.transform.pivot}get skew(){return this.transform.skew}get rotation(){return this.transform.rotation}set rotation(t){this.transform.rotation=t}get angle(){return this.transform.rotation*s}set angle(t){this.transform.rotation=t*r}updateTransform(){const t=this.parent?.transform||new O;this.transform.updateTransform(t),this.worldAlpha=this.alpha*(this.parent?.worldAlpha||1)}addEventListener=(t,e,s)=>{const r="boolean"==typeof s&&s||"object"==typeof s&&s.capture?`${t}capture`:t;"object"==typeof s&&s.once?this.once(r,e):this.tap(r,e)};removeEventListener=(t,e,s)=>{const r=s?`${t}capture`:t;this.off(r,e)}},k=class extends G{isSort=!1;type="container";children=[];worldId=0;batches=[];batchCount=0;structureVersion=0;constructor(){super()}markStructureDirty=()=>{let t=this.parent??this;for(;t.parent;)t=t.parent;t.structureVersion++};addChild=t=>{t.parent?.removeChild(t),this.children.push(t),t.parent=this,this.isSort=!0,this.markStructureDirty()};removeChild=t=>{for(let e=0;e<this.children.length;e++)if(this.children[e]===t)return this.children.splice(e,1),t.parent=void 0,void this.markStructureDirty()};sortChildren=()=>{this.isSort&&(this.children.sort((t,e)=>t.zIndex-e.zIndex),this.isSort=!1)};renderCanvas(t){}renderCanvasRecursive=t=>{if(!(this.worldAlpha<=0)&&this.visible){this.renderCanvas(t);for(let e=0;e<this.children.length;e++)this.children[e].renderCanvasRecursive(t)}};updateTransform=()=>{this.sortChildren();const t=this.parent?.transform||new O;if(this.transform.updateTransform(t),this.worldAlpha=(this.parent?.worldAlpha||1)*this.alpha,!(this.worldAlpha<=0)&&this.visible)for(let e=0;e<this.children.length;e++)this.children[e].updateTransform()};containsPoint=t=>!!this.hitArea&&this.hitArea.contains(t);buildBatches(t){}updateBatches(t){}},Y=/* @__PURE__ */function(t){return t[t.NONE=0]="NONE",t[t.CAPTURING=1]="CAPTURING",t[t.AT_TARGET=2]="AT_TARGET",t[t.BUBBLING=3]="BUBBLING",t}({}),z=class{isTrusted=!0;timeStamp=0;type="mousemove";button=0;buttons=0;global=new D;propagationStopped=!1;eventPhase=0;target=new k;currentTarget=new k;stopPropagation(){this.propagationStopped=!0}},q=class{rootContainer;hasFoundTarget=!1;hitTarget=null;cursor="auto";eventHandlerMap={};pressTargetsMap={};overTargets=[];constructor(t){this.rootContainer=t,this.eventHandlerMap.mousemove=this.fireMouseMove,this.eventHandlerMap.mousedown=this.fireMouseDown,this.eventHandlerMap.mouseup=this.fireMouseUp}hitTestRecursive=(t,e)=>{if(!t.visible)return;if(this.hasFoundTarget)return;for(let r=t.children.length-1;r>=0;r--){const s=t.children[r];this.hitTestRecursive(s,e)}if(this.hasFoundTarget)return;const s=t.worldTransform.applyInverse(e);t.containsPoint(s)&&(this.hitTarget=t,this.hasFoundTarget=!0)};hitTest=t=>(this.hasFoundTarget=!1,this.hitTarget=null,this.hitTestRecursive(this.rootContainer,t),this.hitTarget);fireEvent=t=>{this.eventHandlerMap[t.type]?.(t)};fireMouseMove=t=>{const e=this.hitTest(t.global),s=this.overTargets.length>0?this.overTargets[this.overTargets.length-1]:null;if(s&&s!==e&&(t.target=s,t.type="mouseout",this.dispatchEvent(t),!e||!this.composePath(e).includes(s)))if(t.type="mouseleave",t.eventPhase=Y.AT_TARGET,e){let r=s;for(;r&&!this.composePath(e).includes(r);)t.target=r,t.currentTarget=t.target,t.target.call(`${t.type}capture`,t),t.target.call(t.type,t),r=r.parent}else for(let r=this.overTargets.length-1;r>=0;r--)t.target=this.overTargets[r],t.currentTarget=t.target,t.target.call(`${t.type}capture`,t),t.target.call(t.type,t);if(e&&s!==e){t.target=e,t.type="mouseover",this.dispatchEvent(t);const r=this.composePath(e);if(t.type="mouseenter",t.eventPhase=Y.AT_TARGET,s){let e=r.length-1;for(;e>=0&&!this.composePath(s).includes(r[e]);e--);for(let s=e+1;s<r.length;s++)t.target=r[s],t.currentTarget=t.target,t.target.call(`${t.type}capture`,t),t.target.call(t.type,t)}else for(let e=0;e<r.length;e++)t.target=r[e],t.currentTarget=t.target,t.target.call(`${t.type}capture`,t),t.target.call(t.type,t)}e&&(t.target=e,t.type="mousemove",this.dispatchEvent(t)),this.overTargets=e?this.composePath(e):[],this.cursor=e?e.cursor:"auto"};fireMouseDown=t=>{const e=this.hitTest(t.global);e&&(t.target=e,this.dispatchEvent(t),this.pressTargetsMap[t.button]=this.composePath(e))};fireMouseUp=t=>{const e=this.hitTest(t.global);if(!e)return;t.target=e,this.dispatchEvent(t);const s=this.pressTargetsMap[t.button];if(!s)return;let r=s[s.length-1];const i=this.composePath(e);for(;r&&!i.includes(r);)r.parent&&(r=r.parent);t.type="click",t.target=r,this.dispatchEvent(t),delete this.pressTargetsMap[t.button]};notifyTarget=t=>{t.eventPhase===Y.CAPTURING?t.currentTarget.call(`${t.type}capture`,t):t.currentTarget.call(t.type,t)};propagate=t=>{const e=this.composePath(t.target);t.eventPhase=Y.CAPTURING;for(let s=0;s<e.length-1;s++)if(t.currentTarget=e[s],this.notifyTarget(t),t.propagationStopped)return;if(t.eventPhase=Y.AT_TARGET,t.currentTarget=t.target,t.currentTarget.call(`${t.type}capture`,t),!t.propagationStopped&&(t.currentTarget.call(t.type,t),!t.propagationStopped)){t.eventPhase=Y.BUBBLING;for(let s=e.length-2;s>=0;s--)if(t.currentTarget=e[s],this.notifyTarget(t),t.propagationStopped)return}};dispatchEvent=t=>{t.propagationStopped=!1,this.propagate(t)};composePath=t=>{const e=[];let s=t;for(;s;)e.unshift(s),s=s.parent;return e}},j=class{canvasEle;eventBoundary;rootEvent=new z;constructor(t,e){this.canvasEle=t,this.eventBoundary=new q(e),this.addEvents()}addEvents=()=>{this.canvasEle.addEventListener("pointermove",this.onPointerMove,!0),this.canvasEle.addEventListener("pointerleave",this.onPointerLeave,!0),this.canvasEle.addEventListener("pointerdown",this.onPointerDown,!0),this.canvasEle.addEventListener("pointerup",this.onPointerup,!0)};onPointerMove=t=>{this.bootstrapEvent(t),this.eventBoundary.fireEvent(this.rootEvent),this.setCursor()};onPointerLeave=()=>{this.eventBoundary.overTargets=[]};onPointerDown=t=>{this.bootstrapEvent(t),this.eventBoundary.fireEvent(this.rootEvent)};onPointerup=t=>{this.bootstrapEvent(t),this.eventBoundary.fireEvent(this.rootEvent)};bootstrapEvent=t=>{this.rootEvent.isTrusted=t.isTrusted,this.rootEvent.timeStamp=performance.now(),this.rootEvent.type=t.type.replace("pointer","mouse"),this.rootEvent.button=t.button,this.rootEvent.buttons=t.buttons,this.rootEvent.global.x=t.offsetX,this.rootEvent.global.y=t.offsetY};setCursor=()=>{this.canvasEle.style.cursor=this.eventBoundary.cursor}},X=class t{renderer;stage;view;animationFrameId;eventSystem;constructor(t){const{view:e=document.createElement("canvas")}=t;this.view=e,this.renderer=(t=>{const{prefer:e}=t;switch(e){case o.CANVAS:return new d(t);case o.WEB_GL:return new L(t);case o.WEB_GPU:return new F(t);default:return new d(t)}})({...t,view:e}),this.stage=new k,this.eventSystem=new j(this.view,this.stage)}static async create(e){const s=new t(e);return await s.renderer.init(),s}get filters(){return this.renderer.filters}set filters(t){this.renderer.filters=t}render(){this.renderer.render(this.stage)}start(){const t=()=>{this.render(),this.animationFrameId=requestAnimationFrame(t)};t()}stop(){this.animationFrameId&&(cancelAnimationFrame(this.animationFrameId),this.animationFrameId=void 0)}},Z=class extends u{points=[];closeStroke=!1;type=n.POLYGON;constructor(t=[]){super(),this.points=t}isIntersect(t,e,s,r,i,n){if(r>e&&n>e)return!1;if(r<e&&n<e)return!1;if(s<t&&i<t)return!1;if(s>t&&i>t)return!0;return i-(i-s)/(r-n)*(e-n)>t}contains(t){const e=this.points.length;let s=0;for(let h=2;h<=e-2;h+=2){const e=this.points[h-2],r=this.points[h-1],i=this.points[h],n=this.points[h+1];this.isIntersect(t.x,t.y,e,r,i,n)&&s++}const r=this.points[0],i=this.points[1],n=this.points[e-2],a=this.points[e-1];return this.isIntersect(t.x,t.y,r,i,n,a)&&s++,s%2!=0}},$=class t{color="#ffffff";alpha=1;visible=!1;constructor(){this.reset()}clone(){const e=new t;return e.color=this.color,e.alpha=this.alpha,e.visible=this.visible,e}reset(){this.color="#ffffff",this.alpha=1,this.visible=!1}},H=class t extends ${width=0;cap=a.BUTT;join=h.MITER;miterLimit=10;clone(){const e=new t;return e.color=this.color,e.alpha=this.alpha,e.visible=this.visible,e.width=this.width,e.cap=this.cap,e.join=this.join,e.miterLimit=this.miterLimit,e}reset(){super.reset(),this.color="#ffffff",this.width=0,this.cap=a.BUTT,this.join=h.MITER,this.miterLimit=10}},W=class{shape;lineStyle;fillStyle;vertices=[];constructor(t,e,s){this.shape=t,this.lineStyle=s,this.fillStyle=e}},Q=class{_oldLength=-1;_length=0;curMaxLen=16;float32=new Float32Array(16);_data;get length(){return this._length}concat(t){const e=this._length+t.length;for(;e>this.curMaxLen;)this.expandCapacity();for(let s=0;s<t.length;s++)this.float32[this._length]=t[s],this._length++}push(t){this._length>=this.curMaxLen&&this.expandCapacity(),this.float32[this._length]=t,this._length++}expandCapacity(){this.curMaxLen*=2;const t=new Float32Array(this.curMaxLen);t.set(this.float32),this.float32=t}get data(){return this._oldLength!==this._length&&(this._data=new Float32Array(this.float32.buffer,0,this._length),this._oldLength=this._length),this._data}clear(){this._length=0}},K=class{_oldLength=-1;_length=0;curMaxLen=8;int32=/* @__PURE__ */new Uint32Array(8);_data;get length(){return this._length}concat(t){const e=this.length+t.length;for(;e>this.curMaxLen;)this.expandCapacity();for(let s=0;s<t.length;s++)this.int32[this._length]=t[s],this._length++}concatUInt16(t){const e=this.length+t.length;for(;e>this.curMaxLen;)this.expandCapacity();this.int32.set(t,this._length),this._length=e}expandCapacity(){this.curMaxLen*=2;const t=new Uint32Array(this.curMaxLen);t.set(this.int32),this.int32=t}get data(){return this._oldLength!==this._length&&(this._data=new Uint32Array(this.int32.buffer,0,this._length),this._oldLength=this._length),this._data}clear(){this._length=0}},J=/* @__PURE__ */new Set,tt=!1;function et(t,e,s=2){const r=e&&e.length,i=r?e[0]*s:t.length;J.size&&J.clear();let n=st(t,0,i,s,!0);const a=[];if(!n||n.next===n.prev)return a;let h=0,o=0,l=0;if(r&&(n=function(t,e,s,r){const i=[];for(let n=0,a=e.length;n<a;n++){const s=st(t,e[n]*r,n<a-1?e[n+1]*r:t.length,r,!1);s===s.next&&J.add(s),i.push(Bt(s))}i.sort(ct),function(t,e){const s=Math.ceil((t+2*e)/ft)+e+2;pt.length<4*s&&(pt=new Float64Array(4*s));dt=0}(t.length/r,e.length),vt(s,s),lt=!0;for(let n=0;n<i.length;n++)s=ut(i[n],s);return lt=!1,rt(s)}(t,e,n,s)),t.length>80*s){h=t[0],o=t[1];let e=h,r=o;for(let n=s;n<i;n+=s){const s=t[n],i=t[n+1];s<h&&(h=s),i<o&&(o=i),s>e&&(e=s),i>r&&(r=i)}l=Math.max(e-h,r-o),l=0!==l?32767/l:0}return it(n,a,h,o,l),a}function st(t,e,s,r,i){let n=null;if(i===function(t,e,s,r){let i=0;for(let n=e,a=s-r;n<s;n+=r)i+=(t[a]-t[n])*(t[n+1]+t[a+1]),a=n;return i}(t,e,s,r)>0)for(let a=e;a<s;a+=r)n=Nt(a/r|0,t[a],t[a+1],n);else for(let a=s-r;a>=e;a-=r)n=Nt(a/r|0,t[a],t[a+1],n);return n&&Ct(n,n.next)&&(Vt(n),n=n.next),n}function rt(t,e=t){const s=e===t;let r,i=t;do{r=!1,i===i.next||0!==J.size&&J.has(i)||!Ct(i,i.next)&&0!==St(i.prev,i,i.next)?(s||i!==e)&&(i=i.next,r=!s):((s||i===e)&&(e=i.prev),tt=!0,Vt(i),i=i.prev,r=!0)}while(r||i!==e);return e}function it(t,e,s,r,i){i&&function(t,e,s,r){let i=t,n=0;do{i.z=At(i.x,i.y,e,s,r),wt[n++]=i,i=i.next}while(i!==t);!function(t){if(t<=32){for(let e=1;e<t;e++){const t=wt[e],s=t.z;let r=e-1;for(;r>=0&&wt[r].z>s;)wt[r+1]=wt[r],r--;wt[r+1]=t}return}_t.length<t&&(_t=new Uint32Array(t),Mt=new Uint32Array(t),Et=Array.from({length:t}));for(let e=0;e<t;e++)_t[e]=wt[e].z;Pt(t,wt,_t,Et,Mt,0),Pt(t,Et,Mt,wt,_t,8),Pt(t,wt,_t,Et,Mt,16),Pt(t,Et,Mt,wt,_t,24)}(n);let a=null;for(let h=0;h<n;h++){const t=wt[h];t.prevZ=a,a&&(a.nextZ=t),a=t}a.nextZ=null}(t,s,r,i);let n=t,a=!1;for(;t.prev!==t.next;){const h=t.prev,o=t.next;if(St(h,t,o)<0&&(i?at(t,s,r,i):nt(t)))e.push(h.i,t.i,o.i),Vt(t),t=o,n=o;else if((t=o)===n){if(tt=!1,t=rt(t),tt){n=t;continue}if(!a){n=t=ht(t,e),a=!0;continue}ot(t,e,s,r,i);break}}}function nt(t){const e=t.prev,s=t,r=t.next,i=e.x,n=s.x,a=r.x,h=e.y,o=s.y,l=r.y,c=Math.min(i,n,a),u=Math.min(h,o,l),f=Math.max(i,n,a),p=Math.max(h,o,l);let d=r.next;for(;d!==e;){if(d.x>=c&&d.x<=f&&d.y>=u&&d.y<=p&&(i!==d.x||h!==d.y)&&It(i,h,n,o,a,l,d.x,d.y)&&St(d.prev,d,d.next)>=0)return!1;d=d.next}return!0}function at(t,e,s,r){const i=t.prev,n=t,a=t.next,h=i.x,o=n.x,l=a.x,c=i.y,u=n.y,f=a.y,p=Math.min(h,o,l),d=Math.min(c,u,f),g=Math.max(h,o,l),x=Math.max(c,u,f),v=At(p,d,e,s,r),y=At(g,x,e,s,r);let m=t.prevZ;for(;m&&m.z>=v;){if(m.x>=p&&m.x<=g&&m.y>=d&&m.y<=x&&m!==a&&(h!==m.x||c!==m.y)&&It(h,c,o,u,l,f,m.x,m.y)&&St(m.prev,m,m.next)>=0)return!1;m=m.prevZ}let b=t.nextZ;for(;b&&b.z<=y;){if(b.x>=p&&b.x<=g&&b.y>=d&&b.y<=x&&b!==a&&(h!==b.x||c!==b.y)&&It(h,c,o,u,l,f,b.x,b.y)&&St(b.prev,b,b.next)>=0)return!1;b=b.nextZ}return!0}function ht(t,e){let s=t,r=!1;do{const i=s.prev,n=s.next.next;Ut(i,s,s.next,n,!1)&&Ft(i,n)&&Ft(n,i)&&(e.push(i.i,s.i,n.i),Vt(s),Vt(s.next),s=t=n,r=!0),s=s.next}while(s!==t);return r?rt(s):s}function ot(t,e,s,r,i){let n=t;do{let t=n.next.next;for(;t!==n.prev;){if(n.i!==t.i&&Rt(n,t)){let a=Dt(n,t);return n=rt(n,n.next),a=rt(a,a.next),it(n,e,s,r,i),void it(a,e,s,r,i)}t=t.next}n=n.next}while(n!==t)}var lt=!1;function ct(t,e){return t.x-e.x||t.y-e.y||(t.next.y-t.y)/(t.next.x-t.x)-(e.next.y-e.y)/(e.next.x-e.x)}function ut(t,e){const s=function(t,e){let s=e;const r=t.x,i=t.y;let n,a=-1/0;if(Ct(t,s))return s;for(let f=0,p=0;f<dt;f++,p+=4){if(i<pt[p+1]||i>pt[p+3]||pt[p]>r||pt[p+2]<=a)continue;const e=yt(f);s=mt(f);do{if(s.prev.next===s){if(Ct(t,s.next))return s.next;if(i<=s.y&&i>=s.next.y&&s.next.y!==s.y){const t=s.x+(i-s.y)*(s.next.x-s.x)/(s.next.y-s.y);if(t<=r&&t>a&&(a=t,n=s.x<s.next.x?s:s.next,t===r))return n}}s=s.next}while(s!==e)}if(!n)return null;const h=n.x,o=n.y,l=Math.min(i,o),c=Math.max(i,o);let u=1/0;for(let f=0,p=0;f<dt;f++,p+=4){if(pt[p+2]<h||pt[p]>r||pt[p+3]<l||pt[p+1]>c)continue;const e=yt(f);s=mt(f);do{if(s.prev.next===s&&r>=s.x&&s.x>=h&&r!==s.x&&It(i<o?r:a,i,h,o,i<o?a:r,i,s.x,s.y)){const e=Math.abs(i-s.y)/(r-s.x);(Ft(s,t)||s.y===i&&s.next.y===i&&s.next.x>r)&&(e<u||e===u&&(s.x>n.x||s.x===n.x&&bt(n,s)))&&(n=s,u=e)}s=s.next}while(s!==e)}return n}(t,e);if(!s)return e;const r=Dt(s,t);return vt(s,r.next.next),rt(r,r.next),rt(s,s.next)}var ft=16,pt=/* @__PURE__ */new Float64Array(0),dt=0,gt=[],xt=[];function vt(t,e){let s=t;do{const t=dt++;gt[t]=s;let r=1/0,i=1/0,n=-1/0,a=-1/0,h=0;do{const e=s.next;s.z=t,s.x<r&&(r=s.x),s.x>n&&(n=s.x),s.y<i&&(i=s.y),s.y>a&&(a=s.y),e.x<r&&(r=e.x),e.x>n&&(n=e.x),e.y<i&&(i=e.y),e.y>a&&(a=e.y),s=e}while(++h<ft&&s!==e);xt[t]=s;const o=4*t;pt[o]=r,pt[o+1]=i,pt[o+2]=n,pt[o+3]=a}while(s!==e)}function yt(t){let e=xt[t];for(;e.prev.next!==e;)e=e.next;return xt[t]=e,e}function mt(t){let e=gt[t];for(;e.prev.next!==e;)e=e.next;return gt[t]=e,e}function bt(t,e){return St(t.prev,t,e.prev)<0&&St(e.next,t,t.next)<0}var wt=[],Et=[],_t=/* @__PURE__ */new Uint32Array(0),Mt=/* @__PURE__ */new Uint32Array(0),Tt=/* @__PURE__ */new Uint32Array(256);function Pt(t,e,s,r,i,n){Tt.fill(0);for(let h=0;h<t;h++)Tt[s[h]>>>n&255]++;let a=0;for(let h=0;h<256;h++){const t=Tt[h];Tt[h]=a,a+=t}for(let h=0;h<t;h++){const t=s[h],a=Tt[t>>>n&255]++;r[a]=e[h],i[a]=t}}function At(t,e,s,r,i){let n=(t-s)*i|0,a=(e-r)*i|0;return n=16711935&(n|n<<8),n=252645135&(n|n<<4),n=858993459&(n|n<<2),n=1431655765&(n|n<<1),a=16711935&(a|a<<8),a=252645135&(a|a<<4),a=858993459&(a|a<<2),a=1431655765&(a|a<<1),n|a<<1}function Bt(t){let e=t,s=t;do{(e.x<s.x||e.x===s.x&&e.y<s.y)&&(s=e),e=e.next}while(e!==t);return s}function It(t,e,s,r,i,n,a,h){return(i-a)*(e-h)>=(t-a)*(n-h)&&(t-a)*(r-h)>=(s-a)*(e-h)&&(s-a)*(n-h)>=(i-a)*(r-h)}function Rt(t,e){const s=Ct(t,e)&&St(t.prev,t,t.next)>0&&St(e.prev,e,e.next)>0;return t.next.i!==e.i&&(s||Ft(t,e)&&Ft(e,t)&&(0!==St(t.prev,t,e.prev)||0!==St(t,e.prev,e)))&&!function(t,e){const s=Math.min(t.x,e.x),r=Math.max(t.x,e.x),i=Math.min(t.y,e.y),n=Math.max(t.y,e.y);let a=t;do{const h=a.next;if(a.x>r&&h.x>r||a.x<s&&h.x<s||a.y>n&&h.y>n||a.y<i&&h.y<i)a=h;else{if(a.i!==t.i&&h.i!==t.i&&a.i!==e.i&&h.i!==e.i&&Ut(a,h,t,e))return!0;a=h}}while(a!==t);return!1}(t,e)&&(s||function(t,e){let s=t,r=!1;const i=(t.x+e.x)/2,n=(t.y+e.y)/2;do{const t=s.next;s.y>n!=t.y>n&&i<(t.x-s.x)*(n-s.y)/(t.y-s.y)+s.x&&(r=!r),s=t}while(s!==t);return r}(t,e))}function St(t,e,s){return(e.y-t.y)*(s.x-e.x)-(e.x-t.x)*(s.y-e.y)}function Ct(t,e){return t.x===e.x&&t.y===e.y}function Ut(t,e,s,r,i=!0){const n=St(t,e,s),a=St(t,e,r),h=St(s,r,t),o=St(s,r,e);return(n>0&&a<0||n<0&&a>0)&&(h>0&&o<0||h<0&&o>0)||!!i&&(!(0!==n||!Lt(t,s,e))||(!(0!==a||!Lt(t,r,e))||(!(0!==h||!Lt(s,t,r))||!(0!==o||!Lt(s,e,r)))))}function Lt(t,e,s){return e.x<=Math.max(t.x,s.x)&&e.x>=Math.min(t.x,s.x)&&e.y<=Math.max(t.y,s.y)&&e.y>=Math.min(t.y,s.y)}function Ft(t,e){return St(t.prev,t,t.next)<0?St(t,e,t.next)>=0&&St(t,t.prev,e)>=0:St(t,e,t.prev)<0||St(t,t.next,e)<0}function Dt(t,e){const s=Ot(t.i,t.x,t.y),r=Ot(e.i,e.x,e.y),i=t.next,n=e.prev;return t.next=e,e.prev=t,s.next=i,i.prev=s,r.next=s,s.prev=r,n.next=r,r.prev=n,r}function Nt(t,e,s,r){const i=Ot(t,e,s);return r?(i.next=r.next,i.prev=r,r.next.prev=i,r.next=i):(i.prev=i,i.next=i),i}function Vt(t){t.next.prev=t.prev,t.prev.next=t.next,t.prevZ&&(t.prevZ.nextZ=t.nextZ),t.nextZ&&(t.nextZ.prevZ=t.prevZ),lt&&function(t,e){const s=4*t.z;e.x<pt[s]&&(pt[s]=e.x),e.y<pt[s+1]&&(pt[s+1]=e.y),e.x>pt[s+2]&&(pt[s+2]=e.x),e.y>pt[s+3]&&(pt[s+3]=e.y)}(t.prev,t.next)}function Ot(t,e,s){return{i:t,x:e,y:s,prev:null,next:null,z:0,prevZ:null,nextZ:null}}var Gt=class extends u{x;y;radius;type=n.CIRCLE;constructor(t=0,e=0,s=0){super(),this.x=t,this.y=e,this.radius=s}contains(t){return(t.x-this.x)*(t.x-this.x)+(t.y-this.y)*(t.y-this.y)<this.radius*this.radius}},kt=class extends u{x;y;radiusX;radiusY;type=n.ELLIPSE;constructor(t=0,e=0,s=0,r=0){super(),this.x=t,this.y=e,this.radiusX=s,this.radiusY=r}contains(t){return(t.x-this.x)*(t.x-this.x)/(this.radiusX*this.radiusX)+(t.y-this.y)*(t.y-this.y)/(this.radiusY*this.radiusY)<1}},Yt=class extends u{x;y;width;height;radius;type=n.ROUNDED_RECTANGLE;constructor(t=0,e=0,s=0,r=0,i=20){super(),this.x=t,this.y=e,this.width=s,this.height=r;const n=Math.min(s,r)/2;this.radius=i>n?n:i}contains(t){if(!(t.x>this.x&&t.x<this.x+this.width&&t.y>this.y&&t.y<this.y+this.height))return!1;const e=this.x+this.radius,s=this.y+this.radius;if(t.x<e&&t.y<s)return(t.x-e)*(t.x-e)+(t.y-s)*(t.y-s)<this.radius*this.radius;const r=this.x+this.radius,i=this.y+this.height-this.radius;if(t.x<r&&t.y>i)return(t.x-r)*(t.x-r)+(t.y-i)*(t.y-i)<this.radius*this.radius;const n=this.x+this.width-this.radius,a=this.y+this.radius;if(t.x>n&&t.y<a)return(t.x-n)*(t.x-n)+(t.y-a)*(t.y-a)<this.radius*this.radius;const h=this.x+this.width-this.radius,o=this.y+this.height-this.radius;return!(t.x>h&&t.y<o)||(t.x-h)*(t.x-h)+(t.y-o)*(t.y-o)<this.radius*this.radius}},zt=t=>{const{shape:e,vertices:s}=t;if(e instanceof f){const{x:t,y:r,width:i,height:n}=e;s.push(t,r,t+i,r,t+i,r+n,t,r+n)}e instanceof Gt&&((t,e)=>{const{x:s,y:r,radius:i}=t,n=2*Math.PI*i,a=Math.min(Math.ceil(n/5),2048);for(let h=0;h<a;h++){const t=h/a*Math.PI*2,n=s+i*Math.cos(t),o=r+i*Math.sin(t);e.vertices.push(n,o)}})(e,t),e instanceof Yt&&((t,e)=>{const{x:s,y:r,width:i,height:n,radius:a}=t,h=2*Math.PI*a/4,o=Math.min(Math.ceil(h/4),2048);for(let l=0;l<o;l++){const t=l/o*Math.PI*.5,h=a*Math.cos(t),c=a*Math.sin(t);e.vertices.push(s+i-a+h,r+n-a+c)}for(let l=0;l<o;l++){const t=l/o*Math.PI*.5+Math.PI/2,i=a*Math.cos(t),h=a*Math.sin(t);e.vertices.push(s+a+i,r+n-a+h)}for(let l=0;l<o;l++){const t=l/o*Math.PI*.5+Math.PI,i=a*Math.cos(t),n=a*Math.sin(t);e.vertices.push(s+a+i,r+a+n)}for(let l=0;l<o;l++){const t=l/o*Math.PI*.5+1.5*Math.PI,n=a*Math.cos(t),h=a*Math.sin(t);e.vertices.push(s+i-a+n,r+a+h)}})(e,t),e instanceof kt&&((t,e)=>{const{x:s,y:r,radiusX:i,radiusY:n}=t,a=Math.PI*Math.sqrt(2*(i*i+n*n)),h=Math.min(Math.ceil(a/5),2048);for(let o=0;o<h;o++){const t=o/h*Math.PI*2,a=s+i*Math.cos(t),l=r+n*Math.sin(t);e.vertices.push(a,l)}})(e,t),e instanceof Z&&(t.vertices=e.points)},qt=t=>{const e=[],s=t.length/2+1;for(let r=1;r<s-1;r++)e.push(0,r,r+1);return e.push(0,s-1,1),e},jt=(t,e)=>{const{shape:s,vertices:r,fillStyle:i}=t,n=new y(i);if(e.batchParts.push(n),n.start(e.vertices.length/2,e.indices.length),s instanceof f&&(e.vertices.concat(r),e.indices.concat([0,1,2,0,2,3]),n.end(4,6)),s instanceof Gt){const{x:t,y:i}=s;e.vertices.push(t),e.vertices.push(i),e.vertices.concat(r);const a=qt(r);e.indices.concat(a),n.end(r.length/2+1,a.length)}if(s instanceof Yt){const{x:t,y:i,width:a,height:h}=s;e.vertices.push(t+a/2),e.vertices.push(i+h/2),e.vertices.concat(r);const o=qt(r);e.indices.concat(o),n.end(r.length/2+1,o.length)}if(s instanceof kt){const{x:t,y:i}=s;e.vertices.push(t),e.vertices.push(i),e.vertices.concat(r);const a=qt(r);e.indices.concat(a),n.end(r.length/2+1,a.length)}if(s instanceof Z){e.vertices.concat(r);const t=et(r);e.indices.concat(t),n.end(r.length/2,t.length)}},Xt=(t,e,s,r,i,n,a,h)=>{let o=0,l=0,c=0,u=0,f=0,p=0;if(Math.abs(s-t)<=Number.EPSILON)o=1,l=0,f=s;else{const i=(r-e)/(s-t);o=i,l=-1,f=-(r-i*s)}if(Math.abs(a-i)<=Number.EPSILON)c=1,u=0,p=a;else{const t=(h-n)/(a-i);c=t,u=-1,p=-(h-t*a)}return[(f*u-l*p)/(o*u-l*c),(o*p-f*c)/(o*u-l*c)]},Zt=(t,e,s)=>{const r=e,i=-t,n=s/2/Math.sqrt(t*t+e*e);return[r*n,i*n]},$t=(t,e,s,r,i,n,a,h)=>{const o=s-t,l=r-e,c=i-t,u=n-e;let f=0;f=0===o?l>0?.5*Math.PI:1.5*Math.PI:0===l?o>0?0:Math.PI:o>=0&&l>=0?Math.atan(l/o):o<=0&&l>=0?Math.atan(-o/l)+.5*Math.PI:o<=0&&l<=0?Math.atan(l/o)+Math.PI:Math.atan(o/-l)+1.5*Math.PI;let p=0;p=0===c?u>0?.5*Math.PI:1.5*Math.PI:0===u?c>0?0:Math.PI:c>=0&&u>=0?Math.atan(u/c):c<=0&&u>=0?Math.atan(-c/u)+.5*Math.PI:c<=0&&u<=0?Math.atan(u/c)+Math.PI:Math.atan(c/-u)+1.5*Math.PI,f>p&&(f-=2*Math.PI);const d=Math.sqrt((s-t)*(s-t)+(r-e)*(r-e)),g=2*Math.PI*d/3,x=a.length/2;a.push(t,e,s,r);for(let v=1;v<g;v++){const s=f+v/g*(p-f),r=t+d*Math.cos(s),i=e+d*Math.sin(s);a.push(r,i)}a.push(i,n);for(let v=1;v<a.length/2-x-1;v++)h.push(0+x,v+x,v+1+x)},Ht=(t,e)=>{const{vertices:s,shape:r,lineStyle:i}=t,{width:n,cap:o,join:l,miterLimit:c}=i;let u=0,f=!1;if(r instanceof Z?r.closeStroke&&(f=!0):f=!0,f){const t=s[0],e=s[1],r=s[s.length-2],i=s[s.length-1];Math.abs(t-r)<1e-4&&Math.abs(e-i)<1e-4&&(s.pop(),s.pop());const n=(t+s[s.length-2])/2,a=(e+s[s.length-1])/2;s.unshift(n,a),s.push(n,a)}const p=new y(i);e.batchParts.push(p),p.start(e.vertices.length/2,e.indices.length);const d=[],g=[],x=s[0],v=s[1],m=s[2],b=s[3],[w,E]=Zt(m-x,b-v,n);if(!f){if(o===a.SQUARE){const t=E,e=-w;d.push(x+w,v+E,x+w+t,v+E+e,x-w+t,v-E+e,x-w,v-E),g.push(0,1,2,0,2,3)}o===a.ROUND&&$t(x,v,x-w,v-E,x+w,v+E,d,g),a.BUTT}u=d.length/2,d.push(x-w,v-E,x+w,v+E);for(let a=2;a<s.length-2;a+=2){const t=s[a-2],e=s[a-1],r=s[a],i=s[a+1],o=s[a+2],f=s[a+3],[p,x]=Zt(r-t,i-e,n),[v,y]=Zt(o-r,f-i,n),m=r-t,b=i-e,w=o-r,E=f-i,_=w*b-m*E,M=m*w+b*E;if(Math.abs(_)<.001*Math.abs(M)){d.push(r+p,i+x,r-p,i-x),g.push(0+u,1+u,2+u,0+u,2+u,3+u),u=d.length/2,M>0?d.push(r-p,i-x,r+p,i+x):(l===h.ROUND&&($t(r,i,r+p,i+x,r-p,i-x,d,g),u=d.length/2),l===h.BEVEL||h.MITER,d.push(r+p,i+x,r-p,i-x));continue}const[T,P]=Xt(t+p,e+x,r+p,i+x,r+v,i+y,o+v,f+y),[A,B]=Xt(t-p,e-x,r-p,i-x,r-v,i-y,o-v,f-y);let I=l;l===h.MITER&&(((A-T)**2+(B-P)**2)/n**2<=c**2||(I=h.BEVEL));const R=m*m+b*b+(n/2)**2,S=w*w+E*E+(n/2)**2;(A-r)**2+(B-i)**2<Math.min(R,S)?(I===h.BEVEL&&(_>0?(d.push(T,P,r-p,i-x),g.push(0+u,1+u,2+u,0+u,2+u,3+u),u=d.length/2,d.push(T,P,r-p,i-x,r-v,i-y),g.push(0+u,1+u,2+u),u=d.length/2,d.push(r-v,i-y,T,P)):(d.push(r+p,i+x,A,B),g.push(0+u,1+u,2+u,0+u,2+u,3+u),u=d.length/2,d.push(A,B,r+p,i+x,r+v,i+y),g.push(0+u,1+u,2+u),u=d.length/2,d.push(A,B,r+v,i+y))),I===h.MITER&&(d.push(T,P,A,B),g.push(0+u,1+u,2+u,0+u,2+u,3+u),u=d.length/2,d.push(A,B,T,P)),I===h.ROUND&&(_<0?(d.push(r+p,i+x,A,B),g.push(0+u,1+u,2+u,0+u,2+u,3+u),u=d.length/2,d.push(A,B,r+p,i+x,r,i),g.push(0+u,1+u,2+u),u=d.length/2,d.push(A,B,r+v,i+y,r,i),g.push(0+u,1+u,2+u),u=d.length/2,$t(r,i,r+p,i+x,r+v,i+y,d,g),u=d.length/2,d.push(A,B,r+v,i+y)):(d.push(T,P,r-p,i-x),g.push(0+u,1+u,2+u,0+u,2+u,3+u),u=d.length/2,d.push(T,P,r-p,i-x,r,i),g.push(0+u,1+u,2+u),u=d.length/2,d.push(T,P,r-v,i-y,r,i),g.push(0+u,1+u,2+u),u=d.length/2,$t(r,i,r-v,i-y,r-p,i-x,d,g),u=d.length/2,d.push(r-v,i-y,T,P)))):(d.push(r+p,i+x,r-p,i-x),g.push(0+u,1+u,2+u,0+u,2+u,3+u),u=d.length/2,I===h.BEVEL&&(_>0?(d.push(r,i,r-p,i-x,r-v,i-y),g.push(0+u,1+u,2+u)):(d.push(r,i,r+p,i+x,r+v,i+y),g.push(0+u,1+u,2+u))),I===h.MITER&&(_>0?(d.push(r,i,r-p,i-x,A,B,r-v,i-y),g.push(0+u,1+u,2+u,0+u,2+u,3+u)):(d.push(r,i,r+p,i+x,T,P,r+v,i+y),g.push(0+u,1+u,2+u,0+u,2+u,3+u))),I===h.ROUND&&(_>0?$t(r,i,r-v,i-y,r-p,i-x,d,g):$t(r,i,r+p,i+x,r+v,i+y,d,g)),u=d.length/2,d.push(r-v,i-y,r+v,i+y))}const _=s[s.length-2],M=s[s.length-1],T=s[s.length-4],P=s[s.length-3],[A,B]=Zt(_-T,M-P,n);if(d.push(_+A,M+B,_-A,M-B),g.push(0+u,1+u,2+u,0+u,2+u,3+u),u=d.length/2,!f){const t=s[s.length-2],e=s[s.length-1],r=s[s.length-4],i=s[s.length-3],[h,l]=Zt(t-r,e-i,n);if(o===a.SQUARE){const s=-l,r=h;d.push(t+h,e+l,t+h+s,e+l+r,t-h+s,e-l+r,t-h,e-l),g.push(0+u,1+u,2+u,0+u,2+u,3+u)}o===a.ROUND&&$t(t,e,t+h,e+l,t-h,e-l,d,g)}e.vertices.concat(d),e.indices.concat(g),p.end(d.length/2,g.length)},Wt=class{graphicsData=[];dirty=!1;shapeIndex=0;batchParts=[];vertices=new Q;indices=new K;drawShape(t,e,s){const r=new W(t,e,s);this.graphicsData.push(r),this.dirty=!0}containsPoint(t){for(let e=0;e<this.graphicsData.length;e++){const{shape:s,fillStyle:r}=this.graphicsData[e];if(r.visible&&s.contains(t))return!0}return!1}buildVerticesAndTriangulate(){if(this.dirty){this.dirty=!1;for(let t=this.shapeIndex;t<this.graphicsData.length;t++){const e=this.graphicsData[t];zt(e),e.fillStyle.visible&&jt(e,this),e.lineStyle.visible&&Ht(e,this)}this.shapeIndex=this.graphicsData.length}}clear(){this.graphicsData=[],this.vertices.clear(),this.indices.clear(),this.batchParts=[],this.shapeIndex=0,this.dirty=!1}},Qt=class extends k{_lineStyle=new H;_fillStyle=new $;geometry=new Wt;currentPath=new Z;type;constructor(){super(),this.type="graphics"}lineStyle(t,e="#000000",s=1){if(this.startPoly(),"object"==typeof t)Object.assign(this._lineStyle,t);else{const r={width:t,color:e,alpha:s};Object.assign(this._lineStyle,r)}return this._lineStyle.visible=!0,this}resetLineStyle=()=>{this._lineStyle.reset()};drawShape=t=>(this.geometry.drawShape(t,this._fillStyle.clone(),this._lineStyle.clone()),this.markStructureDirty(),this);startPoly=()=>{this.currentPath.points.length>2&&this.drawShape(this.currentPath),this.currentPath=new Z};beginFill=(t="#000000",e=1)=>(this.startPoly(),this._fillStyle.color=t,this._fillStyle.alpha=e,this._fillStyle.alpha>0&&(this._fillStyle.visible=!0),this);endFill=()=>(this.startPoly(),this._fillStyle.reset(),this);drawRect=(t,e,s,r)=>this.drawShape(new f(t,e,s,r));drawCircle=(t,e,s)=>this.drawShape(new Gt(t,e,s));drawRoundedRect=(t,e,s,r,i)=>this.drawShape(new Yt(t,e,s,r,i));drawEllipse=(t,e,s,r)=>this.drawShape(new kt(t,e,s,r));drawPolygon=t=>{const e=new Z(t);return e.closeStroke=!0,this.drawShape(e)};moveTo=(t,e)=>(this.startPoly(),this.currentPath.points[0]=t,this.currentPath.points[1]=e,this);lineTo=(t,e)=>{if(0===this.currentPath.points.length)return this.moveTo(t,e),this;const s=this.currentPath.points,r=s[s.length-2],i=s[s.length-1];return r===t&&i===e||s.push(t,e),this};closePath=()=>(this.currentPath.closeStroke=!0,this.startPoly(),this);containsPoint=t=>this.hitArea?this.hitArea.contains(t):this.geometry.containsPoint(t);quadraticCurveTo=(t,e,s,r)=>{const i=this.currentPath.points.length;0===i&&(this.currentPath.points=[0,0]);const n=this.currentPath.points[i-2],a=this.currentPath.points[i-1],h=t,o=e,l=s,c=r,u=((t,e,s,r,i,n)=>{const a=2*(t-2*s+i),h=-2*(t-s),o=2*(e-2*r+n),l=-2*(e-r),c=a*a+o*o,u=2*(a*h+o*l),f=h*h+l*l,p=Math.sqrt((4*c*f-u*u)/4),d=(c/2+u/4)*Math.sqrt((c+u/2)*(c+u/2)+p*p)+p*p/2*Math.log(Math.abs(c+u/2+Math.sqrt((c+u/2)*(c+u/2)+p*p))),g=u/4*Math.sqrt(u*u/4+p*p)+p*p/2*Math.log(u/2+Math.sqrt(u*u/4+p*p));return 1/(Math.sqrt(c)*c)*(d-g)})(n,a,h,o,l,c);let f=Math.ceil(u/10);f>2048&&(f=2048),f<8&&(f=8);for(let p=1;p<=f;p++){const t=p/f,e=(1-t)*(1-t)*n+2*t*(1-t)*h+t*t*l,s=(1-t)*(1-t)*a+2*t*(1-t)*o+t*t*c;this.currentPath.points.push(e,s)}return this};bezierCurveTo=(t,e,s,r,i,n)=>{const a=this.currentPath.points.length;0===a&&(this.currentPath.points=[0,0]);const h=this.currentPath.points[a-2],o=this.currentPath.points[a-1],l=t,c=e,u=s,f=r,p=i,d=n,g=((t,e,s,r,i,n,a,h)=>{let o=t,l=e,c=0;for(let u=1;u<=10;u++){const f=u/10,p=(1-f)*(1-f)*(1-f)*t+3*f*(1-f)*(1-f)*s+3*f*f*(1-f)*i+f*f*f*a,d=(1-f)*(1-f)*(1-f)*e+3*f*(1-f)*(1-f)*r+3*f*f*(1-f)*n+f*f*f*h,g=p-o,x=d-l;c+=Math.sqrt(g*g+x*x),o=p,l=d}return c})(h,o,l,c,u,f,p,d);let x=Math.ceil(g/10);x>2048&&(x=2048),x<8&&(x=8);for(let v=1;v<=x;v++){const t=v/x,e=(1-t)*(1-t)*(1-t)*h+3*t*(1-t)*(1-t)*l+3*t*t*(1-t)*u+t*t*t*p,s=(1-t)*(1-t)*(1-t)*o+3*t*(1-t)*(1-t)*c+3*t*t*(1-t)*f+t*t*t*d;this.currentPath.points.push(e,s)}return this};arc=(t,e,s,r,i,n=!1)=>{if(!n){for(;i<r;)i+=2*Math.PI;i-r>2*Math.PI&&(i=r+2*Math.PI)}if(n){for(;i>r;)r+=2*Math.PI;r-i>2*Math.PI&&(i=r-2*Math.PI)}const a=i-r;if(0===a)return this;const h=t+Math.cos(r)*s,o=e+Math.sin(r)*s;this.lineTo(h,o);const l=Math.abs(a)*s;let c=Math.ceil(l/10);c>2048&&(c=2048),c<8&&(c=8);for(let u=1;u<=c;u++){const i=r+a*(u/c),n=t+Math.cos(i)*s,h=e+Math.sin(i)*s;this.lineTo(n,h)}return this};arcTo=(t,e,s,r,i)=>{if(!this.currentPath)return this;const n=this.currentPath.points.length;if(0===n||0===i)return this.lineTo(t,e),this;const a=this.currentPath.points[n-1]-e,h=this.currentPath.points[n-2]-t,o=r-e,l=s-t,c=a*l-h*o,u=Math.abs(c);if(u<1e-8)return this.lineTo(t,e),this;const f=a*a+h*h,p=o*o+l*l,d=a*o+h*l,g=i*Math.sqrt(f)/u,x=i*Math.sqrt(p)/u,v=g*d/f,y=x*d/p,m=g*l+x*h,b=g*o+x*a,w=h*(x+v),E=a*(x+v),_=l*(g+y),M=o*(g+y),T=Math.atan2(E-b,w-m),P=Math.atan2(M-b,_-m),A=h*o>l*a;return this.arc(m+t,b+e,i,T,P,A)};clear=()=>(this.geometry.clear(),this._lineStyle.reset(),this._fillStyle.reset(),this.currentPath=new Z,this.batches=[],this.batchCount=0,this.markStructureDirty(),this);renderCanvas=t=>{this.startPoly();const e=t.ctx,{a:s,b:r,c:i,d:n,tx:a,ty:h}=this.transform.worldTransform;e.setTransform(s,r,i,n,a,h);const o=this.geometry.graphicsData;for(let l=0;l<o.length;l++){const{lineStyle:t,fillStyle:s,shape:r}=o[l];if(s.visible&&(e.fillStyle=s.color),t.visible&&(e.lineWidth=t.width,e.lineCap=t.cap,e.lineJoin=t.join,e.strokeStyle=t.color),e.beginPath(),r instanceof f){const{x:i,y:n,width:a,height:h}=r;s.visible&&(e.globalAlpha=s.alpha*this.worldAlpha,e.fillRect(i,n,a,h)),t.visible&&(e.globalAlpha=t.alpha*this.worldAlpha,e.strokeRect(i,n,a,h))}if(r instanceof Gt){const{x:i,y:n,radius:a}=r;e.arc(i,n,a,0,2*Math.PI),s.visible&&(e.globalAlpha=s.alpha*this.worldAlpha,e.fill()),t.visible&&(e.globalAlpha=t.alpha*this.worldAlpha,e.stroke())}if(r instanceof Yt){const{x:i,y:n,width:a,height:h,radius:o}=r;e.moveTo(i+o,n),e.arc(i+o,n+o,o,1.5*Math.PI,Math.PI,!0),e.lineTo(i,n+h-o),e.arc(i+o,n+h-o,o,Math.PI,Math.PI/2,!0),e.lineTo(i+a-o,n+h),e.arc(i+a-o,n+h-o,o,Math.PI/2,0,!0),e.lineTo(i+a,n+o),e.arc(i+a-o,n+o,o,0,1.5*Math.PI,!0),e.closePath(),s.visible&&(e.globalAlpha=s.alpha*this.worldAlpha,e.fill()),t.visible&&(e.globalAlpha=t.alpha*this.worldAlpha,e.stroke())}if(r instanceof kt){const{x:i,y:n,radiusX:a,radiusY:h}=r;e.ellipse(i,n,a,h,0,0,2*Math.PI),s.visible&&(e.globalAlpha=s.alpha*this.worldAlpha,e.fill()),t.visible&&(e.globalAlpha=t.alpha*this.worldAlpha,e.stroke())}if(r instanceof Z){const{points:i,closeStroke:n}=r;e.moveTo(i[0],i[1]);for(let t=2;t<i.length;t+=2)e.lineTo(i[t],i[t+1]);n&&e.closePath(),s.visible&&(e.globalAlpha=s.alpha*this.worldAlpha,e.fill()),t.visible&&(e.globalAlpha=t.alpha*this.worldAlpha,e.stroke())}}};buildBatches=t=>{this.startPoly(),this.worldId=this.transform.worldId,this.geometry.buildVerticesAndTriangulate();const e=this.geometry.batchParts;for(let s=0;s<e.length;s++){const{style:r,vertexStart:i,vertexCount:n,indexStart:a,indexCount:h}=e[s],{color:o,alpha:l}=r,c=S(o,l*this.worldAlpha),u=E.get(this.type);u.vertexCount=n,u.indexCount=h,u.rgba=c,u.vertexOffset=i,u.indexOffset=a,u.graphics=this,this.batches[s]=u,t.addBatch(this.batches[s])}this.batchCount=e.length};updateBatches=t=>{if(this.worldId!==this.transform.worldId){this.worldId=this.transform.worldId;for(let e=0;e<this.batchCount;e++)this.batches[e].updateVertices(t)}}};function Kt(t,e,s){const r=t.createShader(s);if(t.shaderSource(r,e),t.compileShader(r),!t.getShaderParameter(r,t.COMPILE_STATUS)){const e=t.getShaderInfoLog(r);throw t.deleteShader(r),new Error(`Filter shader compile failed: ${e}`)}return r}var Jt=class{uniforms;fragmentSource;program=null;aPos=-1;locs=/* @__PURE__ */new Map;constructor(t="\nprecision mediump float;\nuniform sampler2D u_texture;\nvarying vec2 v_uv;\nvoid main() {\n gl_FragColor = texture2D(u_texture, v_uv);\n}",e={}){this.fragmentSource=t,this.uniforms=e}ensureProgram(t){if(this.program)return this.program;const e=t.createProgram();if(t.attachShader(e,Kt(t,"\nattribute vec2 a_pos;\nvarying vec2 v_uv;\nvoid main() {\n v_uv = a_pos * 0.5 + 0.5;\n gl_Position = vec4(a_pos, 0.0, 1.0);\n}",t.VERTEX_SHADER)),t.attachShader(e,Kt(t,this.fragmentSource,t.FRAGMENT_SHADER)),t.linkProgram(e),!t.getProgramParameter(e,t.LINK_STATUS))throw new Error(`Filter program link failed: ${t.getProgramInfoLog(e)}`);return this.program=e,this.aPos=t.getAttribLocation(e,"a_pos"),e}loc(t,e){return this.locs.has(e)||this.locs.set(e,t.getUniformLocation(this.program,e)),this.locs.get(e)??null}apply(t,e,s,r,i,n){const a=this.ensureProgram(t);r?r.bind():(t.bindFramebuffer(t.FRAMEBUFFER,null),t.viewport(0,0,i,n)),t.useProgram(a),t.bindBuffer(t.ARRAY_BUFFER,e),t.enableVertexAttribArray(this.aPos),t.vertexAttribPointer(this.aPos,2,t.FLOAT,!1,0,0),t.activeTexture(t.TEXTURE0),t.bindTexture(t.TEXTURE_2D,s);const h=this.loc(t,"u_texture");h&&t.uniform1i(h,0);const o=this.loc(t,"u_resolution");o&&t.uniform2f(o,i,n);for(const l in this.uniforms){const e=this.loc(t,l);if(!e)continue;const s=this.uniforms[l];"number"==typeof s?t.uniform1f(e,s):2===s.length?t.uniform2fv(e,s):3===s.length?t.uniform3fv(e,s):4===s.length&&t.uniform4fv(e,s)}t.clear(t.COLOR_BUFFER_BIT),t.drawArrays(t.TRIANGLE_STRIP,0,4)}dispose(t){this.program&&t.deleteProgram(this.program),this.program=null,this.locs.clear()}},te=class extends Jt{constructor(t={}){super("\nprecision mediump float;\nuniform sampler2D u_texture;\nuniform float u_brightness;\nuniform float u_contrast;\nuniform float u_saturation;\nvarying vec2 v_uv;\nvoid main() {\n vec4 c = texture2D(u_texture, v_uv);\n vec3 rgb = (c.rgb - 0.5) * u_contrast + 0.5 + u_brightness;\n float grey = dot(rgb, vec3(0.2125, 0.7154, 0.0721));\n rgb = mix(vec3(grey), rgb, u_saturation);\n gl_FragColor = vec4(clamp(rgb, 0.0, 1.0), c.a);\n}",{u_brightness:t.brightness??0,u_contrast:t.contrast??1,u_saturation:t.saturation??1})}set brightness(t){this.uniforms.u_brightness=t}set contrast(t){this.uniforms.u_contrast=t}set saturation(t){this.uniforms.u_saturation=t}};export{X as Application,c as BYTES_PER_VERTEX,te as ColorAdjustFilter,k as Container,Jt as Filter,Qt as Graphics,a as LINE_CAP,h as LINE_JOIN,l as MAX_VERTEX_COUNT,o as RENDERER_TYPE,n as SHAPE_TYPE,U as WebGLRenderTarget};
@@ -0,0 +1,43 @@
1
+ import type { WebGLRenderTarget } from '@/utils/visual/render/renderTarget';
2
+ type UniformValue = number | number[];
3
+ /**
4
+ * A full-screen post-processing pass. Sample the previous pass through `u_texture` (and
5
+ * optionally `u_resolution`), transform it, and write the result. Compose several on a
6
+ * renderer to build effects (colour grade, blur, invert, …).
7
+ */
8
+ export declare class Filter {
9
+ uniforms: Record<string, UniformValue>;
10
+ private readonly fragmentSource;
11
+ private program;
12
+ private aPos;
13
+ private locs;
14
+ constructor(fragmentSource?: string, uniforms?: Record<string, UniformValue>);
15
+ private ensureProgram;
16
+ private loc;
17
+ /**
18
+ * Run the pass: read `inputTexture`, write to `output` (a render target, or `null` for the
19
+ * canvas). `quadBuffer` is a shared [-1,1] quad (8 floats). Restores nothing — the renderer
20
+ * re-binds its batch state afterwards.
21
+ */
22
+ apply(gl: WebGLRenderingContext, quadBuffer: WebGLBuffer, inputTexture: WebGLTexture, output: WebGLRenderTarget | null, width: number, height: number): void;
23
+ dispose(gl: WebGLRenderingContext): void;
24
+ }
25
+ export interface ColorAdjustOptions {
26
+ /** Additive brightness, 0 = unchanged. */
27
+ brightness?: number;
28
+ /** Multiplicative contrast, 1 = unchanged. */
29
+ contrast?: number;
30
+ /** Saturation, 1 = unchanged, 0 = greyscale, >1 = more saturated. */
31
+ saturation?: number;
32
+ }
33
+ /**
34
+ * A ready-made colour-grade filter: brightness, contrast and saturation. Mirrors the
35
+ * `brightnessContrast` / `saturation` helpers in `ranuts/utils` on the GPU.
36
+ */
37
+ export declare class ColorAdjustFilter extends Filter {
38
+ constructor(options?: ColorAdjustOptions);
39
+ set brightness(v: number);
40
+ set contrast(v: number);
41
+ set saturation(v: number);
42
+ }
43
+ export {};
@@ -1,9 +1,15 @@
1
1
  import { Rectangle } from '@/utils/visual/shape/rectangle';
2
2
  import type { Container } from '@/utils/visual/vertex/container';
3
+ import type { Filter } from '@/utils/visual/render/filter';
3
4
  import type { IApplicationOptions } from '@/utils/visual/types';
4
5
  export declare abstract class Renderer {
5
6
  canvasEle: HTMLCanvasElement;
6
7
  screen: Rectangle;
8
+ /**
9
+ * Full-screen post-processing passes, applied in order after the scene is drawn. Only the
10
+ * WebGL backend runs them today; the Canvas backend ignores them.
11
+ */
12
+ filters: Filter[];
7
13
  constructor(options: IApplicationOptions);
8
14
  resizeView(width: number, height: number): void;
9
15
  abstract render(rootContainer: Container): void;
@@ -0,0 +1,13 @@
1
+ export declare class WebGLRenderTarget {
2
+ private readonly gl;
3
+ readonly framebuffer: WebGLFramebuffer;
4
+ readonly texture: WebGLTexture;
5
+ width: number;
6
+ height: number;
7
+ constructor(gl: WebGLRenderingContext);
8
+ /** Resize the backing texture; a no-op when the size is unchanged. */
9
+ resize(width: number, height: number): void;
10
+ /** Make this the active draw target and set the viewport to its size. */
11
+ bind(): void;
12
+ dispose(): void;
13
+ }
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Triangulate a polygon given as a flat array of vertex coordinates.
3
+ *
4
+ * @param data flat array of vertex coordinates
5
+ * @param holeIndices indices (in vertices, not coordinates) where each hole ring starts
6
+ * @param dim number of coordinates per vertex in `data`
7
+ * @returns triangles as triplets of vertex indices into `data`
8
+ * @example earcut([10,0, 0,50, 60,60, 70,10]); // [1,0,3, 3,2,1]
9
+ */
10
+ export default function earcut(data: ArrayLike<number>, holeIndices?: ArrayLike<number> | null, dim?: number): number[];
11
+ /**
12
+ * Return the relative difference between the polygon area and the area of its triangulation —
13
+ * a value near 0 means a correct triangulation. Useful for verifying output in tests.
14
+ *
15
+ * @param dim number of coordinates per vertex in `data`
16
+ * @param triangles output of {@link earcut}
17
+ * @example deviation(data, holes, dim, earcut(data, holes, dim)); // ~0 if correct
18
+ */
19
+ export declare function deviation(data: ArrayLike<number>, holeIndices: ArrayLike<number> | null, dim: number, triangles: ArrayLike<number>): number;
20
+ /**
21
+ * Turn a polygon in multi-dimensional array form (e.g. as in GeoJSON) into the flat form Earcut accepts.
22
+ *
23
+ * @param data array of rings; the first ring is the outer contour, the rest are holes
24
+ * @example const {vertices, holes, dimensions} = flatten(geojson.coordinates);
25
+ */
26
+ export declare function flatten(data: ReadonlyArray<ReadonlyArray<ArrayLike<number>>>): {
27
+ vertices: number[];
28
+ holes: number[];
29
+ dimensions: number;
30
+ };
31
+ /**
32
+ * Refine a triangulation toward the constrained Delaunay triangulation by legalizing every
33
+ * interior edge in place with Lawson flips — maximizing the minimum angle and removing most
34
+ * slivers. An optional post-pass for {@link earcut} output, or any manifold triangle-index array
35
+ * indexing into `coords`. Adapted from delaunator's edge legalization.
36
+ *
37
+ * Uses non-robust predicates: float input is fine, and the worst case is a not-quite-Delaunay
38
+ * edge, never an invalid mesh.
39
+ *
40
+ * @param triangles triangle indices, as returned by {@link earcut}; mutated in place
41
+ * @param coords the flat vertex coordinates passed to {@link earcut}
42
+ * @param dim number of coordinates per vertex in `coords`
43
+ * @example refine(earcut(data), data);
44
+ */
45
+ export declare function refine(triangles: number[], coords: ArrayLike<number>, dim?: number): void;
@@ -6,9 +6,13 @@ export declare class WebGLRenderer extends BatchRenderer {
6
6
  private glVertexBuffer;
7
7
  private glIndexBuffer;
8
8
  private unifLoc;
9
+ private targetA?;
10
+ private targetB?;
11
+ private quadBuffer?;
9
12
  constructor(options: IApplicationOptions);
10
13
  protected setProjectionMatrix(): void;
11
14
  protected setRootTransform(a: number, b: number, c: number, d: number, tx: number, ty: number): void;
12
15
  protected updateBuffer(): void;
13
16
  protected draw(): void;
17
+ private ensurePostResources;
14
18
  }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};