@darajs/ui-causal-graph-editor 0.4.8

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 (223) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +12 -0
  3. package/dist/CanvasPool.5cd3cdcd.js +30 -0
  4. package/dist/SharedSystems.140ebe02.js +1905 -0
  5. package/dist/WebGLRenderer.6ede660f.js +2241 -0
  6. package/dist/WebGPURenderer.f884c756.js +1544 -0
  7. package/dist/browserAll.2dcaa9f7.js +953 -0
  8. package/dist/colorToUniform.7c604fe6.js +76 -0
  9. package/dist/index.a01cfc5f.js +61895 -0
  10. package/dist/index.js +35 -0
  11. package/dist/index.umd.cjs +10287 -0
  12. package/dist/init.73e5c5e2.js +2602 -0
  13. package/dist/style.css +1 -0
  14. package/dist/types/graph-viewer/causal-graph-editor.d.ts +58 -0
  15. package/dist/types/graph-viewer/causal-graph-editor.d.ts.map +1 -0
  16. package/dist/types/graph-viewer/storybook/stories-utils.d.ts +1247 -0
  17. package/dist/types/graph-viewer/storybook/stories-utils.d.ts.map +1 -0
  18. package/dist/types/graph-viewer/utils/use-iterate-edges.d.ts +32 -0
  19. package/dist/types/graph-viewer/utils/use-iterate-edges.d.ts.map +1 -0
  20. package/dist/types/graph-viewer/utils/use-iterate-nodes.d.ts +32 -0
  21. package/dist/types/graph-viewer/utils/use-iterate-nodes.d.ts.map +1 -0
  22. package/dist/types/index.d.ts +32 -0
  23. package/dist/types/index.d.ts.map +1 -0
  24. package/dist/types/jest-setup.d.ts +18 -0
  25. package/dist/types/jest-setup.d.ts.map +1 -0
  26. package/dist/types/node-hierarchy-builder/index.d.ts +19 -0
  27. package/dist/types/node-hierarchy-builder/index.d.ts.map +1 -0
  28. package/dist/types/node-hierarchy-builder/layer-divider.d.ts +15 -0
  29. package/dist/types/node-hierarchy-builder/layer-divider.d.ts.map +1 -0
  30. package/dist/types/node-hierarchy-builder/layer-label-editor.d.ts +24 -0
  31. package/dist/types/node-hierarchy-builder/layer-label-editor.d.ts.map +1 -0
  32. package/dist/types/node-hierarchy-builder/layer.d.ts +35 -0
  33. package/dist/types/node-hierarchy-builder/layer.d.ts.map +1 -0
  34. package/dist/types/node-hierarchy-builder/node-hierarchy-builder.d.ts +27 -0
  35. package/dist/types/node-hierarchy-builder/node-hierarchy-builder.d.ts.map +1 -0
  36. package/dist/types/node-hierarchy-builder/node.d.ts +21 -0
  37. package/dist/types/node-hierarchy-builder/node.d.ts.map +1 -0
  38. package/dist/types/node-hierarchy-builder/shared.d.ts +93 -0
  39. package/dist/types/node-hierarchy-builder/shared.d.ts.map +1 -0
  40. package/dist/types/shared/causal-graph-store.d.ts +118 -0
  41. package/dist/types/shared/causal-graph-store.d.ts.map +1 -0
  42. package/dist/types/shared/editor-overlay/buttons/add-node-button.d.ts +25 -0
  43. package/dist/types/shared/editor-overlay/buttons/add-node-button.d.ts.map +1 -0
  44. package/dist/types/shared/editor-overlay/buttons/center-graph-button.d.ts +7 -0
  45. package/dist/types/shared/editor-overlay/buttons/center-graph-button.d.ts.map +1 -0
  46. package/dist/types/shared/editor-overlay/buttons/collapse-all-button.d.ts +7 -0
  47. package/dist/types/shared/editor-overlay/buttons/collapse-all-button.d.ts.map +1 -0
  48. package/dist/types/shared/editor-overlay/buttons/collapse-expand-button.d.ts +26 -0
  49. package/dist/types/shared/editor-overlay/buttons/collapse-expand-button.d.ts.map +1 -0
  50. package/dist/types/shared/editor-overlay/buttons/drag-mode-button.d.ts +27 -0
  51. package/dist/types/shared/editor-overlay/buttons/drag-mode-button.d.ts.map +1 -0
  52. package/dist/types/shared/editor-overlay/buttons/index.d.ts +24 -0
  53. package/dist/types/shared/editor-overlay/buttons/index.d.ts.map +1 -0
  54. package/dist/types/shared/editor-overlay/buttons/recalculate-layout-button.d.ts +7 -0
  55. package/dist/types/shared/editor-overlay/buttons/recalculate-layout-button.d.ts.map +1 -0
  56. package/dist/types/shared/editor-overlay/buttons/save-image-button.d.ts +7 -0
  57. package/dist/types/shared/editor-overlay/buttons/save-image-button.d.ts.map +1 -0
  58. package/dist/types/shared/editor-overlay/buttons/soft-edge-arrow-button.d.ts +19 -0
  59. package/dist/types/shared/editor-overlay/buttons/soft-edge-arrow-button.d.ts.map +1 -0
  60. package/dist/types/shared/editor-overlay/floating-elements.d.ts +29 -0
  61. package/dist/types/shared/editor-overlay/floating-elements.d.ts.map +1 -0
  62. package/dist/types/shared/editor-overlay/index.d.ts +22 -0
  63. package/dist/types/shared/editor-overlay/index.d.ts.map +1 -0
  64. package/dist/types/shared/editor-overlay/legend/index.d.ts +19 -0
  65. package/dist/types/shared/editor-overlay/legend/index.d.ts.map +1 -0
  66. package/dist/types/shared/editor-overlay/legend/legend-data.d.ts +49 -0
  67. package/dist/types/shared/editor-overlay/legend/legend-data.d.ts.map +1 -0
  68. package/dist/types/shared/editor-overlay/legend/legend-list.d.ts +6 -0
  69. package/dist/types/shared/editor-overlay/legend/legend-list.d.ts.map +1 -0
  70. package/dist/types/shared/editor-overlay/legend/legend.d.ts +7 -0
  71. package/dist/types/shared/editor-overlay/legend/legend.d.ts.map +1 -0
  72. package/dist/types/shared/editor-overlay/overlay.d.ts +42 -0
  73. package/dist/types/shared/editor-overlay/overlay.d.ts.map +1 -0
  74. package/dist/types/shared/editor-overlay/panel-content/edge/edge-editor.d.ts +8 -0
  75. package/dist/types/shared/editor-overlay/panel-content/edge/edge-editor.d.ts.map +1 -0
  76. package/dist/types/shared/editor-overlay/panel-content/edge/edge-info-content.d.ts +41 -0
  77. package/dist/types/shared/editor-overlay/panel-content/edge/edge-info-content.d.ts.map +1 -0
  78. package/dist/types/shared/editor-overlay/panel-content/edge/editor-props.d.ts +35 -0
  79. package/dist/types/shared/editor-overlay/panel-content/edge/editor-props.d.ts.map +1 -0
  80. package/dist/types/shared/editor-overlay/panel-content/edge/encoder-editor.d.ts +23 -0
  81. package/dist/types/shared/editor-overlay/panel-content/edge/encoder-editor.d.ts.map +1 -0
  82. package/dist/types/shared/editor-overlay/panel-content/edge/index.d.ts +18 -0
  83. package/dist/types/shared/editor-overlay/panel-content/edge/index.d.ts.map +1 -0
  84. package/dist/types/shared/editor-overlay/panel-content/edge/pag-editor.d.ts +23 -0
  85. package/dist/types/shared/editor-overlay/panel-content/edge/pag-editor.d.ts.map +1 -0
  86. package/dist/types/shared/editor-overlay/panel-content/edge/resolver-editor.d.ts +7 -0
  87. package/dist/types/shared/editor-overlay/panel-content/edge/resolver-editor.d.ts.map +1 -0
  88. package/dist/types/shared/editor-overlay/panel-content/edge/sections/constraint-editor.d.ts +27 -0
  89. package/dist/types/shared/editor-overlay/panel-content/edge/sections/constraint-editor.d.ts.map +1 -0
  90. package/dist/types/shared/editor-overlay/panel-content/edge/sections/description-editor.d.ts +15 -0
  91. package/dist/types/shared/editor-overlay/panel-content/edge/sections/description-editor.d.ts.map +1 -0
  92. package/dist/types/shared/editor-overlay/panel-content/edge/sections/direction-editor.d.ts +21 -0
  93. package/dist/types/shared/editor-overlay/panel-content/edge/sections/direction-editor.d.ts.map +1 -0
  94. package/dist/types/shared/editor-overlay/panel-content/edge/sections/edge-type-editor.d.ts +17 -0
  95. package/dist/types/shared/editor-overlay/panel-content/edge/sections/edge-type-editor.d.ts.map +1 -0
  96. package/dist/types/shared/editor-overlay/panel-content/edge/sections/index.d.ts +19 -0
  97. package/dist/types/shared/editor-overlay/panel-content/edge/sections/index.d.ts.map +1 -0
  98. package/dist/types/shared/editor-overlay/panel-content/index.d.ts +20 -0
  99. package/dist/types/shared/editor-overlay/panel-content/index.d.ts.map +1 -0
  100. package/dist/types/shared/editor-overlay/panel-content/node/index.d.ts +18 -0
  101. package/dist/types/shared/editor-overlay/panel-content/node/index.d.ts.map +1 -0
  102. package/dist/types/shared/editor-overlay/panel-content/node/label-editor.d.ts +11 -0
  103. package/dist/types/shared/editor-overlay/panel-content/node/label-editor.d.ts.map +1 -0
  104. package/dist/types/shared/editor-overlay/panel-content/node/node-info-content.d.ts +34 -0
  105. package/dist/types/shared/editor-overlay/panel-content/node/node-info-content.d.ts.map +1 -0
  106. package/dist/types/shared/editor-overlay/panel-content/panel-content.d.ts +17 -0
  107. package/dist/types/shared/editor-overlay/panel-content/panel-content.d.ts.map +1 -0
  108. package/dist/types/shared/editor-overlay/panel-content/panel-title.d.ts +12 -0
  109. package/dist/types/shared/editor-overlay/panel-content/panel-title.d.ts.map +1 -0
  110. package/dist/types/shared/editor-overlay/panel-content/styled.d.ts +9 -0
  111. package/dist/types/shared/editor-overlay/panel-content/styled.d.ts.map +1 -0
  112. package/dist/types/shared/editor-overlay/positional-divs.d.ts +25 -0
  113. package/dist/types/shared/editor-overlay/positional-divs.d.ts.map +1 -0
  114. package/dist/types/shared/editor-overlay/search-bar/index.d.ts +19 -0
  115. package/dist/types/shared/editor-overlay/search-bar/index.d.ts.map +1 -0
  116. package/dist/types/shared/editor-overlay/search-bar/search-bar.d.ts +21 -0
  117. package/dist/types/shared/editor-overlay/search-bar/search-bar.d.ts.map +1 -0
  118. package/dist/types/shared/editor-overlay/search-bar/use-search.d.ts +32 -0
  119. package/dist/types/shared/editor-overlay/search-bar/use-search.d.ts.map +1 -0
  120. package/dist/types/shared/editor-overlay/zoom-prompt.d.ts +9 -0
  121. package/dist/types/shared/editor-overlay/zoom-prompt.d.ts.map +1 -0
  122. package/dist/types/shared/graph-context.d.ts +26 -0
  123. package/dist/types/shared/graph-context.d.ts.map +1 -0
  124. package/dist/types/shared/graph-layout/circular-layout.d.ts +32 -0
  125. package/dist/types/shared/graph-layout/circular-layout.d.ts.map +1 -0
  126. package/dist/types/shared/graph-layout/common.d.ts +96 -0
  127. package/dist/types/shared/graph-layout/common.d.ts.map +1 -0
  128. package/dist/types/shared/graph-layout/custom-layout.d.ts +36 -0
  129. package/dist/types/shared/graph-layout/custom-layout.d.ts.map +1 -0
  130. package/dist/types/shared/graph-layout/fcose-layout.d.ts +132 -0
  131. package/dist/types/shared/graph-layout/fcose-layout.d.ts.map +1 -0
  132. package/dist/types/shared/graph-layout/force-atlas-layout.d.ts +103 -0
  133. package/dist/types/shared/graph-layout/force-atlas-layout.d.ts.map +1 -0
  134. package/dist/types/shared/graph-layout/index.d.ts +25 -0
  135. package/dist/types/shared/graph-layout/index.d.ts.map +1 -0
  136. package/dist/types/shared/graph-layout/marketing-layout.d.ts +63 -0
  137. package/dist/types/shared/graph-layout/marketing-layout.d.ts.map +1 -0
  138. package/dist/types/shared/graph-layout/planar-layout.d.ts +67 -0
  139. package/dist/types/shared/graph-layout/planar-layout.d.ts.map +1 -0
  140. package/dist/types/shared/graph-layout/spring-layout.d.ts +101 -0
  141. package/dist/types/shared/graph-layout/spring-layout.d.ts.map +1 -0
  142. package/dist/types/shared/graph-layout/worker/circular.d.ts +5 -0
  143. package/dist/types/shared/graph-layout/worker/circular.d.ts.map +1 -0
  144. package/dist/types/shared/graph-layout/worker/client.d.ts +22 -0
  145. package/dist/types/shared/graph-layout/worker/client.d.ts.map +1 -0
  146. package/dist/types/shared/graph-layout/worker/fcose.d.ts +18 -0
  147. package/dist/types/shared/graph-layout/worker/fcose.d.ts.map +1 -0
  148. package/dist/types/shared/graph-layout/worker/force-atlas.d.ts +5 -0
  149. package/dist/types/shared/graph-layout/worker/force-atlas.d.ts.map +1 -0
  150. package/dist/types/shared/graph-layout/worker/marketing.d.ts +5 -0
  151. package/dist/types/shared/graph-layout/worker/marketing.d.ts.map +1 -0
  152. package/dist/types/shared/graph-layout/worker/planar.d.ts +5 -0
  153. package/dist/types/shared/graph-layout/worker/planar.d.ts.map +1 -0
  154. package/dist/types/shared/graph-layout/worker/spring.d.ts +19 -0
  155. package/dist/types/shared/graph-layout/worker/spring.d.ts.map +1 -0
  156. package/dist/types/shared/graph-layout/worker/worker.d.ts +27 -0
  157. package/dist/types/shared/graph-layout/worker/worker.d.ts.map +1 -0
  158. package/dist/types/shared/parsers.d.ts +43 -0
  159. package/dist/types/shared/parsers.d.ts.map +1 -0
  160. package/dist/types/shared/pointer-context.d.ts +20 -0
  161. package/dist/types/shared/pointer-context.d.ts.map +1 -0
  162. package/dist/types/shared/rendering/background.d.ts +48 -0
  163. package/dist/types/shared/rendering/background.d.ts.map +1 -0
  164. package/dist/types/shared/rendering/colors.d.ts +27 -0
  165. package/dist/types/shared/rendering/colors.d.ts.map +1 -0
  166. package/dist/types/shared/rendering/edge/curve.d.ts +51 -0
  167. package/dist/types/shared/rendering/edge/curve.d.ts.map +1 -0
  168. package/dist/types/shared/rendering/edge/definitions.d.ts +73 -0
  169. package/dist/types/shared/rendering/edge/definitions.d.ts.map +1 -0
  170. package/dist/types/shared/rendering/edge/edge-object.d.ts +93 -0
  171. package/dist/types/shared/rendering/edge/edge-object.d.ts.map +1 -0
  172. package/dist/types/shared/rendering/edge/index.d.ts +19 -0
  173. package/dist/types/shared/rendering/edge/index.d.ts.map +1 -0
  174. package/dist/types/shared/rendering/edge/symbols.d.ts +40 -0
  175. package/dist/types/shared/rendering/edge/symbols.d.ts.map +1 -0
  176. package/dist/types/shared/rendering/edge/utils.d.ts +27 -0
  177. package/dist/types/shared/rendering/edge/utils.d.ts.map +1 -0
  178. package/dist/types/shared/rendering/engine.d.ts +436 -0
  179. package/dist/types/shared/rendering/engine.d.ts.map +1 -0
  180. package/dist/types/shared/rendering/grouping/group-container-object.d.ts +56 -0
  181. package/dist/types/shared/rendering/grouping/group-container-object.d.ts.map +1 -0
  182. package/dist/types/shared/rendering/grouping/index.d.ts +2 -0
  183. package/dist/types/shared/rendering/grouping/index.d.ts.map +1 -0
  184. package/dist/types/shared/rendering/node/definitions.d.ts +59 -0
  185. package/dist/types/shared/rendering/node/definitions.d.ts.map +1 -0
  186. package/dist/types/shared/rendering/node/index.d.ts +20 -0
  187. package/dist/types/shared/rendering/node/index.d.ts.map +1 -0
  188. package/dist/types/shared/rendering/node/node-object.d.ts +78 -0
  189. package/dist/types/shared/rendering/node/node-object.d.ts.map +1 -0
  190. package/dist/types/shared/rendering/node/utils.d.ts +33 -0
  191. package/dist/types/shared/rendering/node/utils.d.ts.map +1 -0
  192. package/dist/types/shared/rendering/svg.d.ts +26 -0
  193. package/dist/types/shared/rendering/svg.d.ts.map +1 -0
  194. package/dist/types/shared/rendering/text.d.ts +33 -0
  195. package/dist/types/shared/rendering/text.d.ts.map +1 -0
  196. package/dist/types/shared/rendering/texture-cache.d.ts +47 -0
  197. package/dist/types/shared/rendering/texture-cache.d.ts.map +1 -0
  198. package/dist/types/shared/rendering/use-render-engine.d.ts +115 -0
  199. package/dist/types/shared/rendering/use-render-engine.d.ts.map +1 -0
  200. package/dist/types/shared/rendering/utils.d.ts +27 -0
  201. package/dist/types/shared/rendering/utils.d.ts.map +1 -0
  202. package/dist/types/shared/serializer.d.ts +39 -0
  203. package/dist/types/shared/serializer.d.ts.map +1 -0
  204. package/dist/types/shared/settings-context.d.ts +56 -0
  205. package/dist/types/shared/settings-context.d.ts.map +1 -0
  206. package/dist/types/shared/styles.d.ts +4 -0
  207. package/dist/types/shared/styles.d.ts.map +1 -0
  208. package/dist/types/shared/use-causal-graph-editor.d.ts +22 -0
  209. package/dist/types/shared/use-causal-graph-editor.d.ts.map +1 -0
  210. package/dist/types/shared/use-drag-mode.d.ts +33 -0
  211. package/dist/types/shared/use-drag-mode.d.ts.map +1 -0
  212. package/dist/types/shared/use-edge-encoder.d.ts +45 -0
  213. package/dist/types/shared/use-edge-encoder.d.ts.map +1 -0
  214. package/dist/types/shared/use-graph-tooltip.d.ts +15 -0
  215. package/dist/types/shared/use-graph-tooltip.d.ts.map +1 -0
  216. package/dist/types/shared/use-pane-visibility.d.ts +12 -0
  217. package/dist/types/shared/use-pane-visibility.d.ts.map +1 -0
  218. package/dist/types/shared/utils.d.ts +79 -0
  219. package/dist/types/shared/utils.d.ts.map +1 -0
  220. package/dist/types/types.d.ts +277 -0
  221. package/dist/types/types.d.ts.map +1 -0
  222. package/dist/webworkerAll.2e3715a5.js +7 -0
  223. package/package.json +120 -0
@@ -0,0 +1,1544 @@
1
+ import { S as w, a3 as R, E as l, a4 as ne, a0 as P, a5 as T, q as S, p as oe, B as E, a6 as v, w as A, a7 as y, a8 as ae, a9 as ue, l as L, M as k, J as D, Q as ce, W as de, O as he, K as H, z, b as U, e as B, aa as pe, n as le } from "./index.a01cfc5f.js";
2
+ import { b as fe, l as ge } from "./colorToUniform.7c604fe6.js";
3
+ import { c as me, u as _e, U as be, B as ye, G as xe, e as Ge, R as Be, t as Se, S as Pe, a as Te } from "./SharedSystems.140ebe02.js";
4
+ import { C as M } from "./CanvasPool.5cd3cdcd.js";
5
+ import "react";
6
+ import "styled-components";
7
+ import "react-dom";
8
+ const x = w.for2d();
9
+ class F {
10
+ start(e, t, r) {
11
+ const s = e.renderer, i = s.encoder, n = r.gpuProgram;
12
+ this._shader = r, this._geometry = t, i.setGeometry(t, n), x.blendMode = "normal", s.pipeline.getPipeline(
13
+ t,
14
+ n,
15
+ x
16
+ );
17
+ const o = s.globalUniforms.bindGroup;
18
+ i.resetBindGroup(1), i.setBindGroup(0, o, n);
19
+ }
20
+ execute(e, t) {
21
+ const r = this._shader.gpuProgram, s = e.renderer, i = s.encoder;
22
+ if (!t.bindGroup) {
23
+ const u = t.textures;
24
+ t.bindGroup = R(u.textures, u.count);
25
+ }
26
+ x.blendMode = t.blendMode;
27
+ const n = s.bindGroup.getBindGroup(
28
+ t.bindGroup,
29
+ r,
30
+ 1
31
+ ), o = s.pipeline.getPipeline(
32
+ this._geometry,
33
+ r,
34
+ x
35
+ );
36
+ t.bindGroup._touch(s.textureGC.count), i.setPipeline(o), i.renderPassEncoder.setBindGroup(1, n), i.renderPassEncoder.drawIndexed(t.size, 1, t.start);
37
+ }
38
+ }
39
+ F.extension = {
40
+ type: [
41
+ l.WebGPUPipesAdaptor
42
+ ],
43
+ name: "batch"
44
+ };
45
+ class O {
46
+ constructor(e) {
47
+ this._hash = /* @__PURE__ */ Object.create(null), this._renderer = e, this._renderer.renderableGC.addManagedHash(this, "_hash");
48
+ }
49
+ contextChange(e) {
50
+ this._gpu = e;
51
+ }
52
+ getBindGroup(e, t, r) {
53
+ return e._updateKey(), this._hash[e._key] || this._createBindGroup(e, t, r);
54
+ }
55
+ _createBindGroup(e, t, r) {
56
+ var h;
57
+ const s = this._gpu.device, i = t.layout[r], n = [], o = this._renderer;
58
+ for (const g in i) {
59
+ const p = (h = e.resources[g]) != null ? h : e.resources[i[g]];
60
+ let f;
61
+ if (p._resourceType === "uniformGroup") {
62
+ const d = p;
63
+ o.ubo.updateUniformGroup(d);
64
+ const b = d.buffer;
65
+ f = {
66
+ buffer: o.buffer.getGPUBuffer(b),
67
+ offset: 0,
68
+ size: b.descriptor.size
69
+ };
70
+ } else if (p._resourceType === "buffer") {
71
+ const d = p;
72
+ f = {
73
+ buffer: o.buffer.getGPUBuffer(d),
74
+ offset: 0,
75
+ size: d.descriptor.size
76
+ };
77
+ } else if (p._resourceType === "bufferResource") {
78
+ const d = p;
79
+ f = {
80
+ buffer: o.buffer.getGPUBuffer(d.buffer),
81
+ offset: d.offset,
82
+ size: d.size
83
+ };
84
+ } else if (p._resourceType === "textureSampler") {
85
+ const d = p;
86
+ f = o.texture.getGpuSampler(d);
87
+ } else if (p._resourceType === "textureSource") {
88
+ const d = p;
89
+ f = o.texture.getGpuSource(d).createView({});
90
+ }
91
+ n.push({
92
+ binding: i[g],
93
+ resource: f
94
+ });
95
+ }
96
+ const u = o.shader.getProgramData(t).bindGroups[r], c = s.createBindGroup({
97
+ layout: u,
98
+ entries: n
99
+ });
100
+ return this._hash[e._key] = c, c;
101
+ }
102
+ destroy() {
103
+ for (const e of Object.keys(this._hash))
104
+ this._hash[e] = null;
105
+ this._hash = null, this._renderer = null;
106
+ }
107
+ }
108
+ O.extension = {
109
+ type: [
110
+ l.WebGPUSystem
111
+ ],
112
+ name: "bindGroup"
113
+ };
114
+ class W {
115
+ constructor(e) {
116
+ this._gpuBuffers = /* @__PURE__ */ Object.create(null), this._managedBuffers = [], e.renderableGC.addManagedHash(this, "_gpuBuffers");
117
+ }
118
+ contextChange(e) {
119
+ this._gpu = e;
120
+ }
121
+ getGPUBuffer(e) {
122
+ return this._gpuBuffers[e.uid] || this.createGPUBuffer(e);
123
+ }
124
+ updateBuffer(e) {
125
+ const t = this._gpuBuffers[e.uid] || this.createGPUBuffer(e), r = e.data;
126
+ return e._updateID && r && (e._updateID = 0, this._gpu.device.queue.writeBuffer(
127
+ t,
128
+ 0,
129
+ r.buffer,
130
+ 0,
131
+ (e._updateSize || r.byteLength) + 3 & -4
132
+ )), t;
133
+ }
134
+ destroyAll() {
135
+ for (const e in this._gpuBuffers)
136
+ this._gpuBuffers[e].destroy();
137
+ this._gpuBuffers = {};
138
+ }
139
+ createGPUBuffer(e) {
140
+ this._gpuBuffers[e.uid] || (e.on("update", this.updateBuffer, this), e.on("change", this.onBufferChange, this), e.on("destroy", this.onBufferDestroy, this), this._managedBuffers.push(e));
141
+ const t = this._gpu.device.createBuffer(e.descriptor);
142
+ return e._updateID = 0, e.data && (ne(e.data.buffer, t.getMappedRange()), t.unmap()), this._gpuBuffers[e.uid] = t, t;
143
+ }
144
+ onBufferChange(e) {
145
+ this._gpuBuffers[e.uid].destroy(), e._updateID = 0, this._gpuBuffers[e.uid] = this.createGPUBuffer(e);
146
+ }
147
+ onBufferDestroy(e) {
148
+ this._managedBuffers.splice(this._managedBuffers.indexOf(e), 1), this._destroyBuffer(e);
149
+ }
150
+ destroy() {
151
+ this._managedBuffers.forEach((e) => this._destroyBuffer(e)), this._managedBuffers = null, this._gpuBuffers = null;
152
+ }
153
+ _destroyBuffer(e) {
154
+ this._gpuBuffers[e.uid].destroy(), e.off("update", this.updateBuffer, this), e.off("change", this.onBufferChange, this), e.off("destroy", this.onBufferDestroy, this), this._gpuBuffers[e.uid] = null;
155
+ }
156
+ }
157
+ W.extension = {
158
+ type: [
159
+ l.WebGPUSystem
160
+ ],
161
+ name: "buffer"
162
+ };
163
+ class Ce {
164
+ constructor({ minUniformOffsetAlignment: e }) {
165
+ this._minUniformOffsetAlignment = 256, this.byteIndex = 0, this._minUniformOffsetAlignment = e, this.data = new Float32Array(65535);
166
+ }
167
+ clear() {
168
+ this.byteIndex = 0;
169
+ }
170
+ addEmptyGroup(e) {
171
+ if (e > this._minUniformOffsetAlignment / 4)
172
+ throw new Error(`UniformBufferBatch: array is too large: ${e * 4}`);
173
+ const t = this.byteIndex;
174
+ let r = t + e * 4;
175
+ if (r = Math.ceil(r / this._minUniformOffsetAlignment) * this._minUniformOffsetAlignment, r > this.data.length * 4)
176
+ throw new Error("UniformBufferBatch: ubo batch got too big");
177
+ return this.byteIndex = r, t;
178
+ }
179
+ addGroup(e) {
180
+ const t = this.addEmptyGroup(e.length);
181
+ for (let r = 0; r < e.length; r++)
182
+ this.data[t / 4 + r] = e[r];
183
+ return t;
184
+ }
185
+ destroy() {
186
+ this._buffer.destroy(), this._buffer = null, this.data = null;
187
+ }
188
+ }
189
+ class I {
190
+ constructor(e) {
191
+ this._colorMaskCache = 15, this._renderer = e;
192
+ }
193
+ setMask(e) {
194
+ this._colorMaskCache !== e && (this._colorMaskCache = e, this._renderer.pipeline.setColorMask(e));
195
+ }
196
+ destroy() {
197
+ this._renderer = null, this._colorMaskCache = null;
198
+ }
199
+ }
200
+ I.extension = {
201
+ type: [
202
+ l.WebGPUSystem
203
+ ],
204
+ name: "colorMask"
205
+ };
206
+ class C {
207
+ constructor(e) {
208
+ this._renderer = e;
209
+ }
210
+ async init(e) {
211
+ return this._initPromise ? this._initPromise : (this._initPromise = this._createDeviceAndAdaptor(e).then((t) => {
212
+ this.gpu = t, this._renderer.runners.contextChange.emit(this.gpu);
213
+ }), this._initPromise);
214
+ }
215
+ contextChange(e) {
216
+ this._renderer.gpu = e;
217
+ }
218
+ async _createDeviceAndAdaptor(e) {
219
+ const t = await P.get().getNavigator().gpu.requestAdapter({
220
+ powerPreference: e.powerPreference,
221
+ forceFallbackAdapter: e.forceFallbackAdapter
222
+ }), r = [
223
+ "texture-compression-bc",
224
+ "texture-compression-astc",
225
+ "texture-compression-etc2"
226
+ ].filter((i) => t.features.has(i)), s = await t.requestDevice({
227
+ requiredFeatures: r
228
+ });
229
+ return { adapter: t, device: s };
230
+ }
231
+ destroy() {
232
+ this.gpu = null, this._renderer = null;
233
+ }
234
+ }
235
+ C.extension = {
236
+ type: [
237
+ l.WebGPUSystem
238
+ ],
239
+ name: "device"
240
+ };
241
+ C.defaultOptions = {
242
+ powerPreference: void 0,
243
+ forceFallbackAdapter: !1
244
+ };
245
+ class V {
246
+ constructor(e) {
247
+ this._boundBindGroup = /* @__PURE__ */ Object.create(null), this._boundVertexBuffer = /* @__PURE__ */ Object.create(null), this._renderer = e;
248
+ }
249
+ renderStart() {
250
+ this.commandFinished = new Promise((e) => {
251
+ this._resolveCommandFinished = e;
252
+ }), this.commandEncoder = this._renderer.gpu.device.createCommandEncoder();
253
+ }
254
+ beginRenderPass(e) {
255
+ this.endRenderPass(), this._clearCache(), this.renderPassEncoder = this.commandEncoder.beginRenderPass(e.descriptor);
256
+ }
257
+ endRenderPass() {
258
+ this.renderPassEncoder && this.renderPassEncoder.end(), this.renderPassEncoder = null;
259
+ }
260
+ setViewport(e) {
261
+ this.renderPassEncoder.setViewport(e.x, e.y, e.width, e.height, 0, 1);
262
+ }
263
+ setPipelineFromGeometryProgramAndState(e, t, r, s) {
264
+ const i = this._renderer.pipeline.getPipeline(e, t, r, s);
265
+ this.setPipeline(i);
266
+ }
267
+ setPipeline(e) {
268
+ this._boundPipeline !== e && (this._boundPipeline = e, this.renderPassEncoder.setPipeline(e));
269
+ }
270
+ _setVertexBuffer(e, t) {
271
+ this._boundVertexBuffer[e] !== t && (this._boundVertexBuffer[e] = t, this.renderPassEncoder.setVertexBuffer(e, this._renderer.buffer.updateBuffer(t)));
272
+ }
273
+ _setIndexBuffer(e) {
274
+ if (this._boundIndexBuffer === e)
275
+ return;
276
+ this._boundIndexBuffer = e;
277
+ const t = e.data.BYTES_PER_ELEMENT === 2 ? "uint16" : "uint32";
278
+ this.renderPassEncoder.setIndexBuffer(this._renderer.buffer.updateBuffer(e), t);
279
+ }
280
+ resetBindGroup(e) {
281
+ this._boundBindGroup[e] = null;
282
+ }
283
+ setBindGroup(e, t, r) {
284
+ if (this._boundBindGroup[e] === t)
285
+ return;
286
+ this._boundBindGroup[e] = t, t._touch(this._renderer.textureGC.count);
287
+ const s = this._renderer.bindGroup.getBindGroup(t, r, e);
288
+ this.renderPassEncoder.setBindGroup(e, s);
289
+ }
290
+ setGeometry(e, t) {
291
+ const r = this._renderer.pipeline.getBufferNamesToBind(e, t);
292
+ for (const s in r)
293
+ this._setVertexBuffer(s, e.attributes[r[s]].buffer);
294
+ e.indexBuffer && this._setIndexBuffer(e.indexBuffer);
295
+ }
296
+ _setShaderBindGroups(e, t) {
297
+ for (const r in e.groups) {
298
+ const s = e.groups[r];
299
+ t || this._syncBindGroup(s), this.setBindGroup(r, s, e.gpuProgram);
300
+ }
301
+ }
302
+ _syncBindGroup(e) {
303
+ for (const t in e.resources) {
304
+ const r = e.resources[t];
305
+ r.isUniformGroup && this._renderer.ubo.updateUniformGroup(r);
306
+ }
307
+ }
308
+ draw(e) {
309
+ const { geometry: t, shader: r, state: s, topology: i, size: n, start: o, instanceCount: u, skipSync: c } = e;
310
+ this.setPipelineFromGeometryProgramAndState(t, r.gpuProgram, s, i), this.setGeometry(t, r.gpuProgram), this._setShaderBindGroups(r, c), t.indexBuffer ? this.renderPassEncoder.drawIndexed(
311
+ n || t.indexBuffer.data.length,
312
+ u || t.instanceCount,
313
+ o || 0
314
+ ) : this.renderPassEncoder.draw(n || t.getSize(), u || t.instanceCount, o || 0);
315
+ }
316
+ finishRenderPass() {
317
+ this.renderPassEncoder && (this.renderPassEncoder.end(), this.renderPassEncoder = null);
318
+ }
319
+ postrender() {
320
+ this.finishRenderPass(), this._gpu.device.queue.submit([this.commandEncoder.finish()]), this._resolveCommandFinished(), this.commandEncoder = null;
321
+ }
322
+ restoreRenderPass() {
323
+ const e = this._renderer.renderTarget.adaptor.getDescriptor(
324
+ this._renderer.renderTarget.renderTarget,
325
+ !1,
326
+ [0, 0, 0, 1]
327
+ );
328
+ this.renderPassEncoder = this.commandEncoder.beginRenderPass(e);
329
+ const t = this._boundPipeline, r = { ...this._boundVertexBuffer }, s = this._boundIndexBuffer, i = { ...this._boundBindGroup };
330
+ this._clearCache();
331
+ const n = this._renderer.renderTarget.viewport;
332
+ this.renderPassEncoder.setViewport(n.x, n.y, n.width, n.height, 0, 1), this.setPipeline(t);
333
+ for (const o in r)
334
+ this._setVertexBuffer(o, r[o]);
335
+ for (const o in i)
336
+ this.setBindGroup(o, i[o], null);
337
+ this._setIndexBuffer(s);
338
+ }
339
+ _clearCache() {
340
+ for (let e = 0; e < 16; e++)
341
+ this._boundBindGroup[e] = null, this._boundVertexBuffer[e] = null;
342
+ this._boundIndexBuffer = null, this._boundPipeline = null;
343
+ }
344
+ destroy() {
345
+ this._renderer = null, this._gpu = null, this._boundBindGroup = null, this._boundVertexBuffer = null, this._boundIndexBuffer = null, this._boundPipeline = null;
346
+ }
347
+ contextChange(e) {
348
+ this._gpu = e;
349
+ }
350
+ }
351
+ V.extension = {
352
+ type: [l.WebGPUSystem],
353
+ name: "encoder",
354
+ priority: 1
355
+ };
356
+ class N {
357
+ constructor(e) {
358
+ this._renderTargetStencilState = /* @__PURE__ */ Object.create(null), this._renderer = e, e.renderTarget.onRenderTargetChange.add(this);
359
+ }
360
+ onRenderTargetChange(e) {
361
+ let t = this._renderTargetStencilState[e.uid];
362
+ t || (t = this._renderTargetStencilState[e.uid] = {
363
+ stencilMode: T.DISABLED,
364
+ stencilReference: 0
365
+ }), this._activeRenderTarget = e, this.setStencilMode(t.stencilMode, t.stencilReference);
366
+ }
367
+ setStencilMode(e, t) {
368
+ const r = this._renderTargetStencilState[this._activeRenderTarget.uid];
369
+ r.stencilMode = e, r.stencilReference = t;
370
+ const s = this._renderer;
371
+ s.pipeline.setStencilMode(e), s.encoder.renderPassEncoder.setStencilReference(t);
372
+ }
373
+ destroy() {
374
+ this._renderer.renderTarget.onRenderTargetChange.remove(this), this._renderer = null, this._activeRenderTarget = null, this._renderTargetStencilState = null;
375
+ }
376
+ }
377
+ N.extension = {
378
+ type: [
379
+ l.WebGPUSystem
380
+ ],
381
+ name: "stencil"
382
+ };
383
+ const G = {
384
+ i32: { align: 4, size: 4 },
385
+ u32: { align: 4, size: 4 },
386
+ f32: { align: 4, size: 4 },
387
+ f16: { align: 2, size: 2 },
388
+ "vec2<i32>": { align: 8, size: 8 },
389
+ "vec2<u32>": { align: 8, size: 8 },
390
+ "vec2<f32>": { align: 8, size: 8 },
391
+ "vec2<f16>": { align: 4, size: 4 },
392
+ "vec3<i32>": { align: 16, size: 12 },
393
+ "vec3<u32>": { align: 16, size: 12 },
394
+ "vec3<f32>": { align: 16, size: 12 },
395
+ "vec3<f16>": { align: 8, size: 6 },
396
+ "vec4<i32>": { align: 16, size: 16 },
397
+ "vec4<u32>": { align: 16, size: 16 },
398
+ "vec4<f32>": { align: 16, size: 16 },
399
+ "vec4<f16>": { align: 8, size: 8 },
400
+ "mat2x2<f32>": { align: 8, size: 16 },
401
+ "mat2x2<f16>": { align: 4, size: 8 },
402
+ "mat3x2<f32>": { align: 8, size: 24 },
403
+ "mat3x2<f16>": { align: 4, size: 12 },
404
+ "mat4x2<f32>": { align: 8, size: 32 },
405
+ "mat4x2<f16>": { align: 4, size: 16 },
406
+ "mat2x3<f32>": { align: 16, size: 32 },
407
+ "mat2x3<f16>": { align: 8, size: 16 },
408
+ "mat3x3<f32>": { align: 16, size: 48 },
409
+ "mat3x3<f16>": { align: 8, size: 24 },
410
+ "mat4x3<f32>": { align: 16, size: 64 },
411
+ "mat4x3<f16>": { align: 8, size: 32 },
412
+ "mat2x4<f32>": { align: 16, size: 32 },
413
+ "mat2x4<f16>": { align: 8, size: 16 },
414
+ "mat3x4<f32>": { align: 16, size: 48 },
415
+ "mat3x4<f16>": { align: 8, size: 24 },
416
+ "mat4x4<f32>": { align: 16, size: 64 },
417
+ "mat4x4<f16>": { align: 8, size: 32 }
418
+ };
419
+ function ve(a) {
420
+ const e = a.map((r) => ({
421
+ data: r,
422
+ offset: 0,
423
+ size: 0
424
+ }));
425
+ let t = 0;
426
+ for (let r = 0; r < e.length; r++) {
427
+ const s = e[r];
428
+ let i = G[s.data.type].size;
429
+ const n = G[s.data.type].align;
430
+ if (!G[s.data.type])
431
+ throw new Error(`[Pixi.js] WebGPU UniformBuffer: Unknown type ${s.data.type}`);
432
+ s.data.size > 1 && (i = Math.max(i, n) * s.data.size), t = Math.ceil(t / n) * n, s.size = i, s.offset = t, t += i;
433
+ }
434
+ return t = Math.ceil(t / 16) * 16, { uboElements: e, size: t };
435
+ }
436
+ function Ue(a, e) {
437
+ const { size: t, align: r } = G[a.data.type], s = (r - t) / 4;
438
+ return `
439
+ v = uv.${a.data.name};
440
+ ${e !== 0 ? `offset += ${e};` : ""}
441
+
442
+ arrayOffset = offset;
443
+
444
+ t = 0;
445
+
446
+ for(var i=0; i < ${a.data.size * (t / 4)}; i++)
447
+ {
448
+ for(var j = 0; j < ${t / 4}; j++)
449
+ {
450
+ data[arrayOffset++] = v[t++];
451
+ }
452
+ ${s !== 0 ? `arrayOffset += ${s};` : ""}
453
+ }
454
+ `;
455
+ }
456
+ function Me(a) {
457
+ return me(
458
+ a,
459
+ "uboWgsl",
460
+ Ue,
461
+ _e
462
+ );
463
+ }
464
+ class j extends be {
465
+ constructor() {
466
+ super({
467
+ createUboElements: ve,
468
+ generateUboSync: Me
469
+ });
470
+ }
471
+ }
472
+ j.extension = {
473
+ type: [l.WebGPUSystem],
474
+ name: "ubo"
475
+ };
476
+ const _ = 128;
477
+ class K {
478
+ constructor(e) {
479
+ this._bindGroupHash = /* @__PURE__ */ Object.create(null), this._buffers = [], this._bindGroups = [], this._bufferResources = [], this._renderer = e, this._renderer.renderableGC.addManagedHash(this, "_bindGroupHash"), this._batchBuffer = new Ce({ minUniformOffsetAlignment: _ });
480
+ const t = 256 / _;
481
+ for (let r = 0; r < t; r++) {
482
+ let s = S.UNIFORM | S.COPY_DST;
483
+ r === 0 && (s |= S.COPY_SRC), this._buffers.push(new oe({
484
+ data: this._batchBuffer.data,
485
+ usage: s
486
+ }));
487
+ }
488
+ }
489
+ renderEnd() {
490
+ this._uploadBindGroups(), this._resetBindGroups();
491
+ }
492
+ _resetBindGroups() {
493
+ for (const e in this._bindGroupHash)
494
+ this._bindGroupHash[e] = null;
495
+ this._batchBuffer.clear();
496
+ }
497
+ getUniformBindGroup(e, t) {
498
+ if (!t && this._bindGroupHash[e.uid])
499
+ return this._bindGroupHash[e.uid];
500
+ this._renderer.ubo.ensureUniformGroup(e);
501
+ const r = e.buffer.data, s = this._batchBuffer.addEmptyGroup(r.length);
502
+ return this._renderer.ubo.syncUniformGroup(e, this._batchBuffer.data, s / 4), this._bindGroupHash[e.uid] = this._getBindGroup(s / _), this._bindGroupHash[e.uid];
503
+ }
504
+ getUboResource(e) {
505
+ this._renderer.ubo.updateUniformGroup(e);
506
+ const t = e.buffer.data, r = this._batchBuffer.addGroup(t);
507
+ return this._getBufferResource(r / _);
508
+ }
509
+ getArrayBindGroup(e) {
510
+ const t = this._batchBuffer.addGroup(e);
511
+ return this._getBindGroup(t / _);
512
+ }
513
+ getArrayBufferResource(e) {
514
+ const r = this._batchBuffer.addGroup(e) / _;
515
+ return this._getBufferResource(r);
516
+ }
517
+ _getBufferResource(e) {
518
+ if (!this._bufferResources[e]) {
519
+ const t = this._buffers[e % 2];
520
+ this._bufferResources[e] = new ye({
521
+ buffer: t,
522
+ offset: (e / 2 | 0) * 256,
523
+ size: _
524
+ });
525
+ }
526
+ return this._bufferResources[e];
527
+ }
528
+ _getBindGroup(e) {
529
+ if (!this._bindGroups[e]) {
530
+ const t = new E({
531
+ 0: this._getBufferResource(e)
532
+ });
533
+ this._bindGroups[e] = t;
534
+ }
535
+ return this._bindGroups[e];
536
+ }
537
+ _uploadBindGroups() {
538
+ const e = this._renderer.buffer, t = this._buffers[0];
539
+ t.update(this._batchBuffer.byteIndex), e.updateBuffer(t);
540
+ const r = this._renderer.gpu.device.createCommandEncoder();
541
+ for (let s = 1; s < this._buffers.length; s++) {
542
+ const i = this._buffers[s];
543
+ r.copyBufferToBuffer(
544
+ e.getGPUBuffer(t),
545
+ _,
546
+ e.getGPUBuffer(i),
547
+ 0,
548
+ this._batchBuffer.byteIndex
549
+ );
550
+ }
551
+ this._renderer.gpu.device.queue.submit([r.finish()]);
552
+ }
553
+ destroy() {
554
+ for (let e = 0; e < this._bindGroups.length; e++)
555
+ this._bindGroups[e].destroy();
556
+ this._bindGroups = null, this._bindGroupHash = null;
557
+ for (let e = 0; e < this._buffers.length; e++)
558
+ this._buffers[e].destroy();
559
+ this._buffers = null;
560
+ for (let e = 0; e < this._bufferResources.length; e++)
561
+ this._bufferResources[e].destroy();
562
+ this._bufferResources = null, this._batchBuffer.destroy(), this._bindGroupHash = null, this._renderer = null;
563
+ }
564
+ }
565
+ K.extension = {
566
+ type: [
567
+ l.WebGPUPipes
568
+ ],
569
+ name: "uniformBatch"
570
+ };
571
+ const we = {
572
+ "point-list": 0,
573
+ "line-list": 1,
574
+ "line-strip": 2,
575
+ "triangle-list": 3,
576
+ "triangle-strip": 4
577
+ };
578
+ function Re(a, e, t, r, s) {
579
+ return a << 24 | e << 16 | t << 10 | r << 5 | s;
580
+ }
581
+ function Ee(a, e, t, r) {
582
+ return t << 6 | a << 3 | r << 1 | e;
583
+ }
584
+ class q {
585
+ constructor(e) {
586
+ this._moduleCache = /* @__PURE__ */ Object.create(null), this._bufferLayoutsCache = /* @__PURE__ */ Object.create(null), this._bindingNamesCache = /* @__PURE__ */ Object.create(null), this._pipeCache = /* @__PURE__ */ Object.create(null), this._pipeStateCaches = /* @__PURE__ */ Object.create(null), this._colorMask = 15, this._multisampleCount = 1, this._renderer = e;
587
+ }
588
+ contextChange(e) {
589
+ this._gpu = e, this.setStencilMode(T.DISABLED), this._updatePipeHash();
590
+ }
591
+ setMultisampleCount(e) {
592
+ this._multisampleCount !== e && (this._multisampleCount = e, this._updatePipeHash());
593
+ }
594
+ setRenderTarget(e) {
595
+ this._multisampleCount = e.msaaSamples, this._depthStencilAttachment = e.descriptor.depthStencilAttachment ? 1 : 0, this._updatePipeHash();
596
+ }
597
+ setColorMask(e) {
598
+ this._colorMask !== e && (this._colorMask = e, this._updatePipeHash());
599
+ }
600
+ setStencilMode(e) {
601
+ this._stencilMode !== e && (this._stencilMode = e, this._stencilState = xe[e], this._updatePipeHash());
602
+ }
603
+ setPipeline(e, t, r, s) {
604
+ const i = this.getPipeline(e, t, r);
605
+ s.setPipeline(i);
606
+ }
607
+ getPipeline(e, t, r, s) {
608
+ e._layoutKey || (Ge(e, t.attributeData), this._generateBufferKey(e)), s = s || e.topology;
609
+ const i = Re(
610
+ e._layoutKey,
611
+ t._layoutKey,
612
+ r.data,
613
+ r._blendModeId,
614
+ we[s]
615
+ );
616
+ return this._pipeCache[i] ? this._pipeCache[i] : (this._pipeCache[i] = this._createPipeline(e, t, r, s), this._pipeCache[i]);
617
+ }
618
+ _createPipeline(e, t, r, s) {
619
+ const i = this._gpu.device, n = this._createVertexBufferLayouts(e, t), o = this._renderer.state.getColorTargets(r);
620
+ o[0].writeMask = this._stencilMode === T.RENDERING_MASK_ADD ? 0 : this._colorMask;
621
+ const u = this._renderer.shader.getProgramData(t).pipeline, c = {
622
+ vertex: {
623
+ module: this._getModule(t.vertex.source),
624
+ entryPoint: t.vertex.entryPoint,
625
+ buffers: n
626
+ },
627
+ fragment: {
628
+ module: this._getModule(t.fragment.source),
629
+ entryPoint: t.fragment.entryPoint,
630
+ targets: o
631
+ },
632
+ primitive: {
633
+ topology: s,
634
+ cullMode: r.cullMode
635
+ },
636
+ layout: u,
637
+ multisample: {
638
+ count: this._multisampleCount
639
+ },
640
+ label: "PIXI Pipeline"
641
+ };
642
+ return this._depthStencilAttachment && (c.depthStencil = {
643
+ ...this._stencilState,
644
+ format: "depth24plus-stencil8",
645
+ depthWriteEnabled: r.depthTest,
646
+ depthCompare: r.depthTest ? "less" : "always"
647
+ }), i.createRenderPipeline(c);
648
+ }
649
+ _getModule(e) {
650
+ return this._moduleCache[e] || this._createModule(e);
651
+ }
652
+ _createModule(e) {
653
+ const t = this._gpu.device;
654
+ return this._moduleCache[e] = t.createShaderModule({
655
+ code: e
656
+ }), this._moduleCache[e];
657
+ }
658
+ _generateBufferKey(e) {
659
+ const t = [];
660
+ let r = 0;
661
+ const s = Object.keys(e.attributes).sort();
662
+ for (let n = 0; n < s.length; n++) {
663
+ const o = e.attributes[s[n]];
664
+ t[r++] = o.offset, t[r++] = o.format, t[r++] = o.stride, t[r++] = o.instance;
665
+ }
666
+ const i = t.join("|");
667
+ return e._layoutKey = v(i, "geometry"), e._layoutKey;
668
+ }
669
+ _generateAttributeLocationsKey(e) {
670
+ const t = [];
671
+ let r = 0;
672
+ const s = Object.keys(e.attributeData).sort();
673
+ for (let n = 0; n < s.length; n++) {
674
+ const o = e.attributeData[s[n]];
675
+ t[r++] = o.location;
676
+ }
677
+ const i = t.join("|");
678
+ return e._attributeLocationsKey = v(i, "programAttributes"), e._attributeLocationsKey;
679
+ }
680
+ getBufferNamesToBind(e, t) {
681
+ const r = e._layoutKey << 16 | t._attributeLocationsKey;
682
+ if (this._bindingNamesCache[r])
683
+ return this._bindingNamesCache[r];
684
+ const s = this._createVertexBufferLayouts(e, t), i = /* @__PURE__ */ Object.create(null), n = t.attributeData;
685
+ for (let o = 0; o < s.length; o++)
686
+ for (const u in n)
687
+ if (n[u].location === o) {
688
+ i[o] = u;
689
+ break;
690
+ }
691
+ return this._bindingNamesCache[r] = i, i;
692
+ }
693
+ _createVertexBufferLayouts(e, t) {
694
+ t._attributeLocationsKey || this._generateAttributeLocationsKey(t);
695
+ const r = e._layoutKey << 16 | t._attributeLocationsKey;
696
+ if (this._bufferLayoutsCache[r])
697
+ return this._bufferLayoutsCache[r];
698
+ const s = [];
699
+ return e.buffers.forEach((i) => {
700
+ var u;
701
+ const n = {
702
+ arrayStride: 0,
703
+ stepMode: "vertex",
704
+ attributes: []
705
+ }, o = n.attributes;
706
+ for (const c in t.attributeData) {
707
+ const h = e.attributes[c];
708
+ ((u = h.divisor) != null ? u : 1) !== 1 && A(`Attribute ${c} has an invalid divisor value of '${h.divisor}'. WebGPU only supports a divisor value of 1`), h.buffer === i && (n.arrayStride = h.stride, n.stepMode = h.instance ? "instance" : "vertex", o.push({
709
+ shaderLocation: t.attributeData[c].location,
710
+ offset: h.offset,
711
+ format: h.format
712
+ }));
713
+ }
714
+ o.length && s.push(n);
715
+ }), this._bufferLayoutsCache[r] = s, s;
716
+ }
717
+ _updatePipeHash() {
718
+ const e = Ee(
719
+ this._stencilMode,
720
+ this._multisampleCount,
721
+ this._colorMask,
722
+ this._depthStencilAttachment
723
+ );
724
+ this._pipeStateCaches[e] || (this._pipeStateCaches[e] = /* @__PURE__ */ Object.create(null)), this._pipeCache = this._pipeStateCaches[e];
725
+ }
726
+ destroy() {
727
+ this._renderer = null, this._bufferLayoutsCache = null;
728
+ }
729
+ }
730
+ q.extension = {
731
+ type: [l.WebGPUSystem],
732
+ name: "pipeline"
733
+ };
734
+ class Ae {
735
+ constructor() {
736
+ this.contexts = [], this.msaaTextures = [], this.msaaSamples = 1;
737
+ }
738
+ }
739
+ class Le {
740
+ init(e, t) {
741
+ this._renderer = e, this._renderTargetSystem = t;
742
+ }
743
+ copyToTexture(e, t, r, s, i) {
744
+ const n = this._renderer, o = this._getGpuColorTexture(
745
+ e
746
+ ), u = n.texture.getGpuSource(
747
+ t.source
748
+ );
749
+ return n.encoder.commandEncoder.copyTextureToTexture(
750
+ {
751
+ texture: o,
752
+ origin: r
753
+ },
754
+ {
755
+ texture: u,
756
+ origin: i
757
+ },
758
+ s
759
+ ), t;
760
+ }
761
+ startRenderPass(e, t = !0, r, s) {
762
+ const n = this._renderTargetSystem.getGpuRenderTarget(e), o = this.getDescriptor(e, t, r);
763
+ n.descriptor = o, this._renderer.pipeline.setRenderTarget(n), this._renderer.encoder.beginRenderPass(n), this._renderer.encoder.setViewport(s);
764
+ }
765
+ finishRenderPass() {
766
+ this._renderer.encoder.endRenderPass();
767
+ }
768
+ _getGpuColorTexture(e) {
769
+ const t = this._renderTargetSystem.getGpuRenderTarget(e);
770
+ return t.contexts[0] ? t.contexts[0].getCurrentTexture() : this._renderer.texture.getGpuSource(
771
+ e.colorTextures[0].source
772
+ );
773
+ }
774
+ getDescriptor(e, t, r) {
775
+ typeof t == "boolean" && (t = t ? y.ALL : y.NONE);
776
+ const s = this._renderTargetSystem, i = s.getGpuRenderTarget(e), n = e.colorTextures.map(
777
+ (c, h) => {
778
+ const g = i.contexts[h];
779
+ let p, f;
780
+ g ? p = g.getCurrentTexture().createView() : p = this._renderer.texture.getGpuSource(c).createView({
781
+ mipLevelCount: 1
782
+ }), i.msaaTextures[h] && (f = p, p = this._renderer.texture.getTextureView(
783
+ i.msaaTextures[h]
784
+ ));
785
+ const d = t & y.COLOR ? "clear" : "load";
786
+ return r != null || (r = s.defaultClearColor), {
787
+ view: p,
788
+ resolveTarget: f,
789
+ clearValue: r,
790
+ storeOp: "store",
791
+ loadOp: d
792
+ };
793
+ }
794
+ );
795
+ let o;
796
+ if ((e.stencil || e.depth) && !e.depthStencilTexture && (e.ensureDepthStencilTexture(), e.depthStencilTexture.source.sampleCount = i.msaa ? 4 : 1), e.depthStencilTexture) {
797
+ const c = t & y.STENCIL ? "clear" : "load", h = t & y.DEPTH ? "clear" : "load";
798
+ o = {
799
+ view: this._renderer.texture.getGpuSource(e.depthStencilTexture.source).createView(),
800
+ stencilStoreOp: "store",
801
+ stencilLoadOp: c,
802
+ depthClearValue: 1,
803
+ depthLoadOp: h,
804
+ depthStoreOp: "store"
805
+ };
806
+ }
807
+ return {
808
+ colorAttachments: n,
809
+ depthStencilAttachment: o
810
+ };
811
+ }
812
+ clear(e, t = !0, r, s) {
813
+ if (!t)
814
+ return;
815
+ const { gpu: i, encoder: n } = this._renderer, o = i.device;
816
+ if (n.commandEncoder === null) {
817
+ const c = o.createCommandEncoder(), h = this.getDescriptor(e, t, r), g = c.beginRenderPass(h);
818
+ g.setViewport(s.x, s.y, s.width, s.height, 0, 1), g.end();
819
+ const p = c.finish();
820
+ o.queue.submit([p]);
821
+ } else
822
+ this.startRenderPass(e, t, r, s);
823
+ }
824
+ initGpuRenderTarget(e) {
825
+ e.isRoot = !0;
826
+ const t = new Ae();
827
+ return e.colorTextures.forEach((r, s) => {
828
+ if (ae.test(r.resource)) {
829
+ const i = r.resource.getContext(
830
+ "webgpu"
831
+ ), n = r.transparent ? "premultiplied" : "opaque";
832
+ try {
833
+ i.configure({
834
+ device: this._renderer.gpu.device,
835
+ usage: GPUTextureUsage.TEXTURE_BINDING | GPUTextureUsage.COPY_DST | GPUTextureUsage.RENDER_ATTACHMENT | GPUTextureUsage.COPY_SRC,
836
+ format: "bgra8unorm",
837
+ alphaMode: n
838
+ });
839
+ } catch (o) {
840
+ console.error(o);
841
+ }
842
+ t.contexts[s] = i;
843
+ }
844
+ if (t.msaa = r.source.antialias, r.source.antialias) {
845
+ const i = new ue({
846
+ width: 0,
847
+ height: 0,
848
+ sampleCount: 4
849
+ });
850
+ t.msaaTextures[s] = i;
851
+ }
852
+ }), t.msaa && (t.msaaSamples = 4, e.depthStencilTexture && (e.depthStencilTexture.source.sampleCount = 4)), t;
853
+ }
854
+ destroyGpuRenderTarget(e) {
855
+ e.contexts.forEach((t) => {
856
+ t.unconfigure();
857
+ }), e.msaaTextures.forEach((t) => {
858
+ t.destroy();
859
+ }), e.msaaTextures.length = 0, e.contexts.length = 0;
860
+ }
861
+ ensureDepthStencilTexture(e) {
862
+ const t = this._renderTargetSystem.getGpuRenderTarget(e);
863
+ e.depthStencilTexture && t.msaa && (e.depthStencilTexture.source.sampleCount = 4);
864
+ }
865
+ resizeGpuRenderTarget(e) {
866
+ const t = this._renderTargetSystem.getGpuRenderTarget(e);
867
+ t.width = e.width, t.height = e.height, t.msaa && e.colorTextures.forEach((r, s) => {
868
+ const i = t.msaaTextures[s];
869
+ i == null || i.resize(
870
+ r.source.width,
871
+ r.source.height,
872
+ r.source._resolution
873
+ );
874
+ });
875
+ }
876
+ }
877
+ class Y extends Be {
878
+ constructor(e) {
879
+ super(e), this.adaptor = new Le(), this.adaptor.init(e, this);
880
+ }
881
+ }
882
+ Y.extension = {
883
+ type: [l.WebGPUSystem],
884
+ name: "renderTarget"
885
+ };
886
+ class $ {
887
+ constructor() {
888
+ this._gpuProgramData = /* @__PURE__ */ Object.create(null);
889
+ }
890
+ contextChange(e) {
891
+ this._gpu = e, this.maxTextures = e.device.limits.maxSampledTexturesPerShaderStage;
892
+ }
893
+ getProgramData(e) {
894
+ return this._gpuProgramData[e._layoutKey] || this._createGPUProgramData(e);
895
+ }
896
+ _createGPUProgramData(e) {
897
+ const t = this._gpu.device, r = e.gpuLayout.map((i) => t.createBindGroupLayout({ entries: i })), s = { bindGroupLayouts: r };
898
+ return this._gpuProgramData[e._layoutKey] = {
899
+ bindGroups: r,
900
+ pipeline: t.createPipelineLayout(s)
901
+ }, this._gpuProgramData[e._layoutKey];
902
+ }
903
+ destroy() {
904
+ this._gpu = null, this._gpuProgramData = null;
905
+ }
906
+ }
907
+ $.extension = {
908
+ type: [
909
+ l.WebGPUSystem
910
+ ],
911
+ name: "shader"
912
+ };
913
+ const m = {};
914
+ m.normal = {
915
+ alpha: {
916
+ srcFactor: "one",
917
+ dstFactor: "one-minus-src-alpha",
918
+ operation: "add"
919
+ },
920
+ color: {
921
+ srcFactor: "one",
922
+ dstFactor: "one-minus-src-alpha",
923
+ operation: "add"
924
+ }
925
+ };
926
+ m.add = {
927
+ alpha: {
928
+ srcFactor: "src-alpha",
929
+ dstFactor: "one-minus-src-alpha",
930
+ operation: "add"
931
+ },
932
+ color: {
933
+ srcFactor: "one",
934
+ dstFactor: "one",
935
+ operation: "add"
936
+ }
937
+ };
938
+ m.multiply = {
939
+ alpha: {
940
+ srcFactor: "one",
941
+ dstFactor: "one-minus-src-alpha",
942
+ operation: "add"
943
+ },
944
+ color: {
945
+ srcFactor: "dst",
946
+ dstFactor: "one-minus-src-alpha",
947
+ operation: "add"
948
+ }
949
+ };
950
+ m.screen = {
951
+ alpha: {
952
+ srcFactor: "one",
953
+ dstFactor: "one-minus-src-alpha",
954
+ operation: "add"
955
+ },
956
+ color: {
957
+ srcFactor: "one",
958
+ dstFactor: "one-minus-src",
959
+ operation: "add"
960
+ }
961
+ };
962
+ m.overlay = {
963
+ alpha: {
964
+ srcFactor: "one",
965
+ dstFactor: "one-minus-src-alpha",
966
+ operation: "add"
967
+ },
968
+ color: {
969
+ srcFactor: "one",
970
+ dstFactor: "one-minus-src",
971
+ operation: "add"
972
+ }
973
+ };
974
+ m.none = {
975
+ alpha: {
976
+ srcFactor: "one",
977
+ dstFactor: "one-minus-src-alpha",
978
+ operation: "add"
979
+ },
980
+ color: {
981
+ srcFactor: "zero",
982
+ dstFactor: "zero",
983
+ operation: "add"
984
+ }
985
+ };
986
+ m["normal-npm"] = {
987
+ alpha: {
988
+ srcFactor: "one",
989
+ dstFactor: "one-minus-src-alpha",
990
+ operation: "add"
991
+ },
992
+ color: {
993
+ srcFactor: "src-alpha",
994
+ dstFactor: "one-minus-src-alpha",
995
+ operation: "add"
996
+ }
997
+ };
998
+ m["add-npm"] = {
999
+ alpha: {
1000
+ srcFactor: "one",
1001
+ dstFactor: "one",
1002
+ operation: "add"
1003
+ },
1004
+ color: {
1005
+ srcFactor: "src-alpha",
1006
+ dstFactor: "one",
1007
+ operation: "add"
1008
+ }
1009
+ };
1010
+ m["screen-npm"] = {
1011
+ alpha: {
1012
+ srcFactor: "one",
1013
+ dstFactor: "one-minus-src-alpha",
1014
+ operation: "add"
1015
+ },
1016
+ color: {
1017
+ srcFactor: "src-alpha",
1018
+ dstFactor: "one-minus-src",
1019
+ operation: "add"
1020
+ }
1021
+ };
1022
+ m.erase = {
1023
+ alpha: {
1024
+ srcFactor: "zero",
1025
+ dstFactor: "one-minus-src-alpha",
1026
+ operation: "add"
1027
+ },
1028
+ color: {
1029
+ srcFactor: "zero",
1030
+ dstFactor: "one-minus-src",
1031
+ operation: "add"
1032
+ }
1033
+ };
1034
+ m.min = {
1035
+ alpha: {
1036
+ srcFactor: "one",
1037
+ dstFactor: "one",
1038
+ operation: "min"
1039
+ },
1040
+ color: {
1041
+ srcFactor: "one",
1042
+ dstFactor: "one",
1043
+ operation: "min"
1044
+ }
1045
+ };
1046
+ m.max = {
1047
+ alpha: {
1048
+ srcFactor: "one",
1049
+ dstFactor: "one",
1050
+ operation: "max"
1051
+ },
1052
+ color: {
1053
+ srcFactor: "one",
1054
+ dstFactor: "one",
1055
+ operation: "max"
1056
+ }
1057
+ };
1058
+ class X {
1059
+ constructor() {
1060
+ this.defaultState = new w(), this.defaultState.blend = !0;
1061
+ }
1062
+ contextChange(e) {
1063
+ this.gpu = e;
1064
+ }
1065
+ getColorTargets(e) {
1066
+ return [
1067
+ {
1068
+ format: "bgra8unorm",
1069
+ writeMask: 0,
1070
+ blend: m[e.blendMode] || m.normal
1071
+ }
1072
+ ];
1073
+ }
1074
+ destroy() {
1075
+ this.gpu = null;
1076
+ }
1077
+ }
1078
+ X.extension = {
1079
+ type: [
1080
+ l.WebGPUSystem
1081
+ ],
1082
+ name: "state"
1083
+ };
1084
+ const ke = {
1085
+ type: "image",
1086
+ upload(a, e, t) {
1087
+ const r = a.resource, s = (a.pixelWidth | 0) * (a.pixelHeight | 0), i = r.byteLength / s;
1088
+ t.device.queue.writeTexture(
1089
+ { texture: e },
1090
+ r,
1091
+ {
1092
+ offset: 0,
1093
+ rowsPerImage: a.pixelHeight,
1094
+ bytesPerRow: a.pixelHeight * i
1095
+ },
1096
+ {
1097
+ width: a.pixelWidth,
1098
+ height: a.pixelHeight,
1099
+ depthOrArrayLayers: 1
1100
+ }
1101
+ );
1102
+ }
1103
+ }, J = {
1104
+ "bc1-rgba-unorm": { blockBytes: 8, blockWidth: 4, blockHeight: 4 },
1105
+ "bc2-rgba-unorm": { blockBytes: 16, blockWidth: 4, blockHeight: 4 },
1106
+ "bc3-rgba-unorm": { blockBytes: 16, blockWidth: 4, blockHeight: 4 },
1107
+ "bc7-rgba-unorm": { blockBytes: 16, blockWidth: 4, blockHeight: 4 },
1108
+ "etc1-rgb-unorm": { blockBytes: 8, blockWidth: 4, blockHeight: 4 },
1109
+ "etc2-rgba8unorm": { blockBytes: 16, blockWidth: 4, blockHeight: 4 },
1110
+ "astc-4x4-unorm": { blockBytes: 16, blockWidth: 4, blockHeight: 4 }
1111
+ }, De = { blockBytes: 4, blockWidth: 1, blockHeight: 1 }, He = {
1112
+ type: "compressed",
1113
+ upload(a, e, t) {
1114
+ let r = a.pixelWidth, s = a.pixelHeight;
1115
+ const i = J[a.format] || De;
1116
+ for (let n = 0; n < a.resource.length; n++) {
1117
+ const o = a.resource[n], u = Math.ceil(r / i.blockWidth) * i.blockBytes;
1118
+ t.device.queue.writeTexture(
1119
+ {
1120
+ texture: e,
1121
+ mipLevel: n
1122
+ },
1123
+ o,
1124
+ {
1125
+ offset: 0,
1126
+ bytesPerRow: u
1127
+ },
1128
+ {
1129
+ width: Math.ceil(r / i.blockWidth) * i.blockWidth,
1130
+ height: Math.ceil(s / i.blockHeight) * i.blockHeight,
1131
+ depthOrArrayLayers: 1
1132
+ }
1133
+ ), r = Math.max(r >> 1, 1), s = Math.max(s >> 1, 1);
1134
+ }
1135
+ }
1136
+ }, Q = {
1137
+ type: "image",
1138
+ upload(a, e, t) {
1139
+ const r = a.resource;
1140
+ if (!r)
1141
+ return;
1142
+ const s = Math.min(e.width, a.resourceWidth || a.pixelWidth), i = Math.min(e.height, a.resourceHeight || a.pixelHeight), n = a.alphaMode === "premultiply-alpha-on-upload";
1143
+ t.device.queue.copyExternalImageToTexture(
1144
+ { source: r },
1145
+ { texture: e, premultipliedAlpha: n },
1146
+ {
1147
+ width: s,
1148
+ height: i
1149
+ }
1150
+ );
1151
+ }
1152
+ }, ze = {
1153
+ type: "video",
1154
+ upload(a, e, t) {
1155
+ Q.upload(a, e, t);
1156
+ }
1157
+ };
1158
+ class Fe {
1159
+ constructor(e) {
1160
+ this.device = e, this.sampler = e.createSampler({ minFilter: "linear" }), this.pipelines = {};
1161
+ }
1162
+ _getMipmapPipeline(e) {
1163
+ let t = this.pipelines[e];
1164
+ return t || (this.mipmapShaderModule || (this.mipmapShaderModule = this.device.createShaderModule({
1165
+ code: `
1166
+ var<private> pos : array<vec2<f32>, 3> = array<vec2<f32>, 3>(
1167
+ vec2<f32>(-1.0, -1.0), vec2<f32>(-1.0, 3.0), vec2<f32>(3.0, -1.0));
1168
+
1169
+ struct VertexOutput {
1170
+ @builtin(position) position : vec4<f32>,
1171
+ @location(0) texCoord : vec2<f32>,
1172
+ };
1173
+
1174
+ @vertex
1175
+ fn vertexMain(@builtin(vertex_index) vertexIndex : u32) -> VertexOutput {
1176
+ var output : VertexOutput;
1177
+ output.texCoord = pos[vertexIndex] * vec2<f32>(0.5, -0.5) + vec2<f32>(0.5);
1178
+ output.position = vec4<f32>(pos[vertexIndex], 0.0, 1.0);
1179
+ return output;
1180
+ }
1181
+
1182
+ @group(0) @binding(0) var imgSampler : sampler;
1183
+ @group(0) @binding(1) var img : texture_2d<f32>;
1184
+
1185
+ @fragment
1186
+ fn fragmentMain(@location(0) texCoord : vec2<f32>) -> @location(0) vec4<f32> {
1187
+ return textureSample(img, imgSampler, texCoord);
1188
+ }
1189
+ `
1190
+ })), t = this.device.createRenderPipeline({
1191
+ layout: "auto",
1192
+ vertex: {
1193
+ module: this.mipmapShaderModule,
1194
+ entryPoint: "vertexMain"
1195
+ },
1196
+ fragment: {
1197
+ module: this.mipmapShaderModule,
1198
+ entryPoint: "fragmentMain",
1199
+ targets: [{ format: e }]
1200
+ }
1201
+ }), this.pipelines[e] = t), t;
1202
+ }
1203
+ generateMipmap(e) {
1204
+ const t = this._getMipmapPipeline(e.format);
1205
+ if (e.dimension === "3d" || e.dimension === "1d")
1206
+ throw new Error("Generating mipmaps for non-2d textures is currently unsupported!");
1207
+ let r = e;
1208
+ const s = e.depthOrArrayLayers || 1, i = e.usage & GPUTextureUsage.RENDER_ATTACHMENT;
1209
+ if (!i) {
1210
+ const u = {
1211
+ size: {
1212
+ width: Math.ceil(e.width / 2),
1213
+ height: Math.ceil(e.height / 2),
1214
+ depthOrArrayLayers: s
1215
+ },
1216
+ format: e.format,
1217
+ usage: GPUTextureUsage.TEXTURE_BINDING | GPUTextureUsage.COPY_SRC | GPUTextureUsage.RENDER_ATTACHMENT,
1218
+ mipLevelCount: e.mipLevelCount - 1
1219
+ };
1220
+ r = this.device.createTexture(u);
1221
+ }
1222
+ const n = this.device.createCommandEncoder({}), o = t.getBindGroupLayout(0);
1223
+ for (let u = 0; u < s; ++u) {
1224
+ let c = e.createView({
1225
+ baseMipLevel: 0,
1226
+ mipLevelCount: 1,
1227
+ dimension: "2d",
1228
+ baseArrayLayer: u,
1229
+ arrayLayerCount: 1
1230
+ }), h = i ? 1 : 0;
1231
+ for (let g = 1; g < e.mipLevelCount; ++g) {
1232
+ const p = r.createView({
1233
+ baseMipLevel: h++,
1234
+ mipLevelCount: 1,
1235
+ dimension: "2d",
1236
+ baseArrayLayer: u,
1237
+ arrayLayerCount: 1
1238
+ }), f = n.beginRenderPass({
1239
+ colorAttachments: [{
1240
+ view: p,
1241
+ storeOp: "store",
1242
+ loadOp: "clear",
1243
+ clearValue: { r: 0, g: 0, b: 0, a: 0 }
1244
+ }]
1245
+ }), d = this.device.createBindGroup({
1246
+ layout: o,
1247
+ entries: [{
1248
+ binding: 0,
1249
+ resource: this.sampler
1250
+ }, {
1251
+ binding: 1,
1252
+ resource: c
1253
+ }]
1254
+ });
1255
+ f.setPipeline(t), f.setBindGroup(0, d), f.draw(3, 1, 0, 0), f.end(), c = p;
1256
+ }
1257
+ }
1258
+ if (!i) {
1259
+ const u = {
1260
+ width: Math.ceil(e.width / 2),
1261
+ height: Math.ceil(e.height / 2),
1262
+ depthOrArrayLayers: s
1263
+ };
1264
+ for (let c = 1; c < e.mipLevelCount; ++c)
1265
+ n.copyTextureToTexture({
1266
+ texture: r,
1267
+ mipLevel: c - 1
1268
+ }, {
1269
+ texture: e,
1270
+ mipLevel: c
1271
+ }, u), u.width = Math.ceil(u.width / 2), u.height = Math.ceil(u.height / 2);
1272
+ }
1273
+ return this.device.queue.submit([n.finish()]), i || r.destroy(), e;
1274
+ }
1275
+ }
1276
+ class Z {
1277
+ constructor(e) {
1278
+ this.managedTextures = [], this._gpuSources = /* @__PURE__ */ Object.create(null), this._gpuSamplers = /* @__PURE__ */ Object.create(null), this._bindGroupHash = /* @__PURE__ */ Object.create(null), this._textureViewHash = /* @__PURE__ */ Object.create(null), this._uploads = {
1279
+ image: Q,
1280
+ buffer: ke,
1281
+ video: ze,
1282
+ compressed: He
1283
+ }, this._renderer = e, e.renderableGC.addManagedHash(this, "_gpuSources"), e.renderableGC.addManagedHash(this, "_gpuSamplers"), e.renderableGC.addManagedHash(this, "_bindGroupHash"), e.renderableGC.addManagedHash(this, "_textureViewHash");
1284
+ }
1285
+ contextChange(e) {
1286
+ this._gpu = e;
1287
+ }
1288
+ initSource(e) {
1289
+ if (e.autoGenerateMipmaps) {
1290
+ const u = Math.max(e.pixelWidth, e.pixelHeight);
1291
+ e.mipLevelCount = Math.floor(Math.log2(u)) + 1;
1292
+ }
1293
+ let t = GPUTextureUsage.TEXTURE_BINDING | GPUTextureUsage.COPY_DST;
1294
+ e.uploadMethodId !== "compressed" && (t |= GPUTextureUsage.RENDER_ATTACHMENT, t |= GPUTextureUsage.COPY_SRC);
1295
+ const r = J[e.format] || { blockBytes: 4, blockWidth: 1, blockHeight: 1 }, s = Math.ceil(e.pixelWidth / r.blockWidth) * r.blockWidth, i = Math.ceil(e.pixelHeight / r.blockHeight) * r.blockHeight, n = {
1296
+ label: e.label,
1297
+ size: { width: s, height: i },
1298
+ format: e.format,
1299
+ sampleCount: e.sampleCount,
1300
+ mipLevelCount: e.mipLevelCount,
1301
+ dimension: e.dimension,
1302
+ usage: t
1303
+ }, o = this._gpu.device.createTexture(n);
1304
+ return this._gpuSources[e.uid] = o, this.managedTextures.includes(e) || (e.on("update", this.onSourceUpdate, this), e.on("resize", this.onSourceResize, this), e.on("destroy", this.onSourceDestroy, this), e.on("unload", this.onSourceUnload, this), e.on("updateMipmaps", this.onUpdateMipmaps, this), this.managedTextures.push(e)), this.onSourceUpdate(e), o;
1305
+ }
1306
+ onSourceUpdate(e) {
1307
+ const t = this.getGpuSource(e);
1308
+ !t || (this._uploads[e.uploadMethodId] && this._uploads[e.uploadMethodId].upload(e, t, this._gpu), e.autoGenerateMipmaps && e.mipLevelCount > 1 && this.onUpdateMipmaps(e));
1309
+ }
1310
+ onSourceUnload(e) {
1311
+ const t = this._gpuSources[e.uid];
1312
+ t && (this._gpuSources[e.uid] = null, t.destroy());
1313
+ }
1314
+ onUpdateMipmaps(e) {
1315
+ this._mipmapGenerator || (this._mipmapGenerator = new Fe(this._gpu.device));
1316
+ const t = this.getGpuSource(e);
1317
+ this._mipmapGenerator.generateMipmap(t);
1318
+ }
1319
+ onSourceDestroy(e) {
1320
+ e.off("update", this.onSourceUpdate, this), e.off("unload", this.onSourceUnload, this), e.off("destroy", this.onSourceDestroy, this), e.off("resize", this.onSourceResize, this), e.off("updateMipmaps", this.onUpdateMipmaps, this), this.managedTextures.splice(this.managedTextures.indexOf(e), 1), this.onSourceUnload(e);
1321
+ }
1322
+ onSourceResize(e) {
1323
+ const t = this._gpuSources[e.uid];
1324
+ t ? (t.width !== e.pixelWidth || t.height !== e.pixelHeight) && (this._textureViewHash[e.uid] = null, this._bindGroupHash[e.uid] = null, this.onSourceUnload(e), this.initSource(e)) : this.initSource(e);
1325
+ }
1326
+ _initSampler(e) {
1327
+ return this._gpuSamplers[e._resourceId] = this._gpu.device.createSampler(e), this._gpuSamplers[e._resourceId];
1328
+ }
1329
+ getGpuSampler(e) {
1330
+ return this._gpuSamplers[e._resourceId] || this._initSampler(e);
1331
+ }
1332
+ getGpuSource(e) {
1333
+ return this._gpuSources[e.uid] || this.initSource(e);
1334
+ }
1335
+ getTextureBindGroup(e) {
1336
+ var t;
1337
+ return (t = this._bindGroupHash[e.uid]) != null ? t : this._createTextureBindGroup(e);
1338
+ }
1339
+ _createTextureBindGroup(e) {
1340
+ const t = e.source;
1341
+ return this._bindGroupHash[e.uid] = new E({
1342
+ 0: t,
1343
+ 1: t.style,
1344
+ 2: new L({
1345
+ uTextureMatrix: { type: "mat3x3<f32>", value: e.textureMatrix.mapCoord }
1346
+ })
1347
+ }), this._bindGroupHash[e.uid];
1348
+ }
1349
+ getTextureView(e) {
1350
+ var r;
1351
+ const t = e.source;
1352
+ return (r = this._textureViewHash[t.uid]) != null ? r : this._createTextureView(t);
1353
+ }
1354
+ _createTextureView(e) {
1355
+ return this._textureViewHash[e.uid] = this.getGpuSource(e).createView(), this._textureViewHash[e.uid];
1356
+ }
1357
+ generateCanvas(e) {
1358
+ const t = this._renderer, r = t.gpu.device.createCommandEncoder(), s = P.get().createCanvas();
1359
+ s.width = e.source.pixelWidth, s.height = e.source.pixelHeight;
1360
+ const i = s.getContext("webgpu");
1361
+ return i.configure({
1362
+ device: t.gpu.device,
1363
+ usage: GPUTextureUsage.COPY_DST | GPUTextureUsage.COPY_SRC,
1364
+ format: P.get().getNavigator().gpu.getPreferredCanvasFormat(),
1365
+ alphaMode: "premultiplied"
1366
+ }), r.copyTextureToTexture({
1367
+ texture: t.texture.getGpuSource(e.source),
1368
+ origin: {
1369
+ x: 0,
1370
+ y: 0
1371
+ }
1372
+ }, {
1373
+ texture: i.getCurrentTexture()
1374
+ }, {
1375
+ width: s.width,
1376
+ height: s.height
1377
+ }), t.gpu.device.queue.submit([r.finish()]), s;
1378
+ }
1379
+ getPixels(e) {
1380
+ const t = this.generateCanvas(e), r = M.getOptimalCanvasAndContext(t.width, t.height), s = r.context;
1381
+ s.drawImage(t, 0, 0);
1382
+ const { width: i, height: n } = t, o = s.getImageData(0, 0, i, n), u = new Uint8ClampedArray(o.data.buffer);
1383
+ return M.returnCanvasAndContext(r), { pixels: u, width: i, height: n };
1384
+ }
1385
+ destroy() {
1386
+ this.managedTextures.slice().forEach((e) => this.onSourceDestroy(e)), this.managedTextures = null;
1387
+ for (const e of Object.keys(this._bindGroupHash)) {
1388
+ const t = Number(e), r = this._bindGroupHash[t];
1389
+ r == null || r.destroy(), this._bindGroupHash[t] = null;
1390
+ }
1391
+ this._gpu = null, this._mipmapGenerator = null, this._gpuSources = null, this._bindGroupHash = null, this._textureViewHash = null, this._gpuSamplers = null;
1392
+ }
1393
+ }
1394
+ Z.extension = {
1395
+ type: [
1396
+ l.WebGPUSystem
1397
+ ],
1398
+ name: "texture"
1399
+ };
1400
+ class ee {
1401
+ init() {
1402
+ const e = new L({
1403
+ uTransformMatrix: { value: new k(), type: "mat3x3<f32>" },
1404
+ uColor: { value: new Float32Array([1, 1, 1, 1]), type: "vec4<f32>" },
1405
+ uRound: { value: 0, type: "f32" }
1406
+ }), t = D({
1407
+ name: "graphics",
1408
+ bits: [
1409
+ ce,
1410
+ de(he()),
1411
+ fe,
1412
+ H
1413
+ ]
1414
+ });
1415
+ this.shader = new z({
1416
+ gpuProgram: t,
1417
+ resources: {
1418
+ localUniforms: e
1419
+ }
1420
+ });
1421
+ }
1422
+ execute(e, t) {
1423
+ const r = t.context, s = r.customShader || this.shader, i = e.renderer, n = i.graphicsContext, {
1424
+ batcher: o,
1425
+ instructions: u
1426
+ } = n.getContextRenderData(r), c = i.encoder;
1427
+ c.setPipelineFromGeometryProgramAndState(
1428
+ o.geometry,
1429
+ s.gpuProgram,
1430
+ e.state
1431
+ ), c.setGeometry(o.geometry, s.gpuProgram);
1432
+ const h = i.globalUniforms.bindGroup;
1433
+ c.setBindGroup(0, h, s.gpuProgram);
1434
+ const g = i.renderPipes.uniformBatch.getUniformBindGroup(s.resources.localUniforms, !0);
1435
+ c.setBindGroup(2, g, s.gpuProgram);
1436
+ const p = u.instructions;
1437
+ for (let f = 0; f < u.instructionSize; f++) {
1438
+ const d = p[f];
1439
+ if (s.groups[1] = d.bindGroup, !d.gpuBindGroup) {
1440
+ const b = d.textures;
1441
+ d.bindGroup = R(b.textures, b.count), d.gpuBindGroup = i.bindGroup.getBindGroup(
1442
+ d.bindGroup,
1443
+ s.gpuProgram,
1444
+ 1
1445
+ );
1446
+ }
1447
+ c.setBindGroup(1, d.bindGroup, s.gpuProgram), c.renderPassEncoder.drawIndexed(d.size, 1, d.start);
1448
+ }
1449
+ }
1450
+ destroy() {
1451
+ this.shader.destroy(!0), this.shader = null;
1452
+ }
1453
+ }
1454
+ ee.extension = {
1455
+ type: [
1456
+ l.WebGPUPipesAdaptor
1457
+ ],
1458
+ name: "graphics"
1459
+ };
1460
+ class te {
1461
+ init() {
1462
+ const e = D({
1463
+ name: "mesh",
1464
+ bits: [
1465
+ ge,
1466
+ Se,
1467
+ H
1468
+ ]
1469
+ });
1470
+ this._shader = new z({
1471
+ gpuProgram: e,
1472
+ resources: {
1473
+ uTexture: U.EMPTY._source,
1474
+ uSampler: U.EMPTY._source.style,
1475
+ textureUniforms: {
1476
+ uTextureMatrix: { type: "mat3x3<f32>", value: new k() }
1477
+ }
1478
+ }
1479
+ });
1480
+ }
1481
+ execute(e, t) {
1482
+ const r = e.renderer;
1483
+ let s = t._shader;
1484
+ if (!s)
1485
+ s = this._shader, s.groups[2] = r.texture.getTextureBindGroup(t.texture);
1486
+ else if (!s.gpuProgram) {
1487
+ A("Mesh shader has no gpuProgram", t.shader);
1488
+ return;
1489
+ }
1490
+ const i = s.gpuProgram;
1491
+ if (i.autoAssignGlobalUniforms && (s.groups[0] = r.globalUniforms.bindGroup), i.autoAssignLocalUniforms) {
1492
+ const n = e.localUniforms;
1493
+ s.groups[1] = r.renderPipes.uniformBatch.getUniformBindGroup(n, !0);
1494
+ }
1495
+ r.encoder.draw({
1496
+ geometry: t._geometry,
1497
+ shader: s,
1498
+ state: t.state
1499
+ });
1500
+ }
1501
+ destroy() {
1502
+ this._shader.destroy(!0), this._shader = null;
1503
+ }
1504
+ }
1505
+ te.extension = {
1506
+ type: [
1507
+ l.WebGPUPipesAdaptor
1508
+ ],
1509
+ name: "mesh"
1510
+ };
1511
+ const Oe = [
1512
+ ...Pe,
1513
+ j,
1514
+ V,
1515
+ C,
1516
+ W,
1517
+ Z,
1518
+ Y,
1519
+ $,
1520
+ X,
1521
+ q,
1522
+ I,
1523
+ N,
1524
+ O
1525
+ ], We = [...Te, K], Ie = [F, te, ee], re = [], se = [], ie = [];
1526
+ B.handleByNamedList(l.WebGPUSystem, re);
1527
+ B.handleByNamedList(l.WebGPUPipes, se);
1528
+ B.handleByNamedList(l.WebGPUPipesAdaptor, ie);
1529
+ B.add(...Oe, ...We, ...Ie);
1530
+ class Je extends pe {
1531
+ constructor() {
1532
+ const e = {
1533
+ name: "webgpu",
1534
+ type: le.WEBGPU,
1535
+ systems: re,
1536
+ renderPipes: se,
1537
+ renderPipeAdaptors: ie
1538
+ };
1539
+ super(e);
1540
+ }
1541
+ }
1542
+ export {
1543
+ Je as WebGPURenderer
1544
+ };