@pibbl/core 0.0.2 → 0.0.3-alpha.90.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (285) hide show
  1. package/THIRD_PARTY_NOTICES.txt +81 -0
  2. package/dist/features/textures/index.d.ts +12 -2
  3. package/dist/features/textures/index.js +33 -1
  4. package/dist/features/textures/index.js.map +2 -2
  5. package/dist/features/textures/lib/chemical-field.d.ts +56 -0
  6. package/dist/features/textures/lib/chemical-field.js +154 -0
  7. package/dist/features/textures/lib/chemical-field.js.map +7 -0
  8. package/dist/features/textures/lib/chemical-recipes.d.ts +119 -0
  9. package/dist/features/textures/lib/chemical-recipes.js +275 -0
  10. package/dist/features/textures/lib/chemical-recipes.js.map +7 -0
  11. package/dist/features/textures/lib/definitions.d.ts +3 -18
  12. package/dist/features/textures/lib/definitions.js +15 -20
  13. package/dist/features/textures/lib/definitions.js.map +2 -2
  14. package/dist/features/textures/lib/geometric-patterns.d.ts +149 -0
  15. package/dist/features/textures/lib/geometric-patterns.js +305 -0
  16. package/dist/features/textures/lib/geometric-patterns.js.map +7 -0
  17. package/dist/features/textures/lib/gray-scott.d.ts +55 -0
  18. package/dist/features/textures/lib/gray-scott.js +39 -0
  19. package/dist/features/textures/lib/gray-scott.js.map +7 -0
  20. package/dist/features/textures/lib/patterns.d.ts +123 -0
  21. package/dist/features/textures/lib/patterns.js +344 -0
  22. package/dist/features/textures/lib/patterns.js.map +7 -0
  23. package/dist/features/textures/lib/reaction-diffusion.d.ts +3 -2
  24. package/dist/features/textures/lib/reaction-diffusion.js +9 -20
  25. package/dist/features/textures/lib/reaction-diffusion.js.map +2 -2
  26. package/dist/features/textures/lib/simulation.d.ts +10 -4
  27. package/dist/features/textures/lib/simulation.js +23 -13
  28. package/dist/features/textures/lib/simulation.js.map +2 -2
  29. package/dist/features/viz/index.d.ts +68 -6
  30. package/dist/features/viz/index.js +164 -2
  31. package/dist/features/viz/index.js.map +2 -2
  32. package/dist/features/viz/inspection/bar.d.ts +79 -0
  33. package/dist/features/viz/inspection/bar.js +49 -0
  34. package/dist/features/viz/inspection/bar.js.map +7 -0
  35. package/dist/features/viz/inspection/candle.d.ts +156 -0
  36. package/dist/features/viz/inspection/candle.js +120 -0
  37. package/dist/features/viz/inspection/candle.js.map +7 -0
  38. package/dist/features/viz/inspection/capture-types.d.ts +65 -0
  39. package/dist/features/viz/inspection/capture.d.ts +16 -0
  40. package/dist/features/viz/inspection/capture.js +49 -0
  41. package/dist/features/viz/inspection/capture.js.map +7 -0
  42. package/dist/features/viz/inspection/handler.d.ts +36 -0
  43. package/dist/features/viz/inspection/handler.js +91 -0
  44. package/dist/features/viz/inspection/handler.js.map +7 -0
  45. package/dist/features/viz/inspection/ohlc-bar.d.ts +132 -0
  46. package/dist/features/viz/inspection/ohlc-bar.js +118 -0
  47. package/dist/features/viz/inspection/ohlc-bar.js.map +7 -0
  48. package/dist/features/viz/inspection/owned-ref.d.ts +16 -0
  49. package/dist/features/viz/inspection/owned-ref.js +99 -0
  50. package/dist/features/viz/inspection/owned-ref.js.map +7 -0
  51. package/dist/features/viz/inspection/painted-point.d.ts +22 -0
  52. package/dist/features/viz/inspection/painted-point.js +29 -0
  53. package/dist/features/viz/inspection/painted-point.js.map +7 -0
  54. package/dist/features/viz/inspection/queries.d.ts +100 -0
  55. package/dist/features/viz/inspection/queries.js +192 -0
  56. package/dist/features/viz/inspection/queries.js.map +7 -0
  57. package/dist/features/viz/inspection/query-types.d.ts +177 -0
  58. package/dist/features/viz/inspection/volume.d.ts +104 -0
  59. package/dist/features/viz/inspection/volume.js +95 -0
  60. package/dist/features/viz/inspection/volume.js.map +7 -0
  61. package/dist/features/viz/inspection.d.ts +19 -0
  62. package/dist/features/viz/inspection.js +54 -0
  63. package/dist/features/viz/inspection.js.map +7 -0
  64. package/dist/features/viz/inspection.mjs +1 -0
  65. package/dist/features/viz/lib/area-series.d.ts +62 -0
  66. package/dist/features/viz/lib/area-series.js +120 -0
  67. package/dist/features/viz/lib/area-series.js.map +7 -0
  68. package/dist/features/viz/lib/axis.js +1 -1
  69. package/dist/features/viz/lib/axis.js.map +2 -2
  70. package/dist/features/viz/lib/bar-series.d.ts +3 -1
  71. package/dist/features/viz/lib/bar-series.js +16 -1
  72. package/dist/features/viz/lib/bar-series.js.map +2 -2
  73. package/dist/features/viz/lib/baseline-series.d.ts +55 -0
  74. package/dist/features/viz/lib/baseline-series.js +136 -0
  75. package/dist/features/viz/lib/baseline-series.js.map +7 -0
  76. package/dist/features/viz/lib/candlestick-series.d.ts +62 -0
  77. package/dist/features/viz/lib/candlestick-series.js +150 -0
  78. package/dist/features/viz/lib/candlestick-series.js.map +7 -0
  79. package/dist/features/viz/lib/censored-point-series.d.ts +71 -0
  80. package/dist/features/viz/lib/censored-point-series.js +129 -0
  81. package/dist/features/viz/lib/censored-point-series.js.map +7 -0
  82. package/dist/features/viz/lib/color-context.d.ts +4 -0
  83. package/dist/features/viz/lib/color-context.js +41 -0
  84. package/dist/features/viz/lib/color-context.js.map +7 -0
  85. package/dist/features/viz/lib/color-math.d.ts +4 -0
  86. package/dist/features/viz/lib/color-math.js +31 -0
  87. package/dist/features/viz/lib/color-math.js.map +7 -0
  88. package/dist/features/viz/lib/color-types.d.ts +53 -0
  89. package/dist/features/viz/lib/curve-definition.d.ts +49 -0
  90. package/dist/features/viz/lib/curve-definition.js +148 -0
  91. package/dist/features/viz/lib/curve-definition.js.map +7 -0
  92. package/dist/features/viz/lib/diverging-color-scale.d.ts +11 -0
  93. package/dist/features/viz/lib/diverging-color-scale.js +51 -0
  94. package/dist/features/viz/lib/diverging-color-scale.js.map +7 -0
  95. package/dist/features/viz/lib/domain-navigation.d.ts +40 -0
  96. package/dist/features/viz/lib/domain-navigation.js +77 -0
  97. package/dist/features/viz/lib/domain-navigation.js.map +7 -0
  98. package/dist/features/viz/lib/editable-chart-elements.d.ts +178 -0
  99. package/dist/features/viz/lib/editable-chart-elements.js +733 -0
  100. package/dist/features/viz/lib/editable-chart-elements.js.map +7 -0
  101. package/dist/features/viz/lib/financial-aggregation.d.ts +127 -0
  102. package/dist/features/viz/lib/financial-aggregation.js +116 -0
  103. package/dist/features/viz/lib/financial-aggregation.js.map +7 -0
  104. package/dist/features/viz/lib/financial-autoscale.d.ts +64 -0
  105. package/dist/features/viz/lib/financial-autoscale.js +61 -0
  106. package/dist/features/viz/lib/financial-autoscale.js.map +7 -0
  107. package/dist/features/viz/lib/financial-comparison.d.ts +62 -0
  108. package/dist/features/viz/lib/financial-comparison.js +98 -0
  109. package/dist/features/viz/lib/financial-comparison.js.map +7 -0
  110. package/dist/features/viz/lib/financial-geometry.d.ts +77 -0
  111. package/dist/features/viz/lib/financial-geometry.js +67 -0
  112. package/dist/features/viz/lib/financial-geometry.js.map +7 -0
  113. package/dist/features/viz/lib/financial-indicators.d.ts +114 -0
  114. package/dist/features/viz/lib/financial-indicators.js +135 -0
  115. package/dist/features/viz/lib/financial-indicators.js.map +7 -0
  116. package/dist/features/viz/lib/financial-oscillators.d.ts +171 -0
  117. package/dist/features/viz/lib/financial-oscillators.js +265 -0
  118. package/dist/features/viz/lib/financial-oscillators.js.map +7 -0
  119. package/dist/features/viz/lib/graph/bipartite.d.ts +14 -0
  120. package/dist/features/viz/lib/graph/bipartite.js +250 -0
  121. package/dist/features/viz/lib/graph/bipartite.js.map +7 -0
  122. package/dist/features/viz/lib/graph/chord.d.ts +44 -0
  123. package/dist/features/viz/lib/graph/chord.js +348 -0
  124. package/dist/features/viz/lib/graph/chord.js.map +7 -0
  125. package/dist/features/viz/lib/graph/dependency.d.ts +26 -0
  126. package/dist/features/viz/lib/graph/dependency.js +141 -0
  127. package/dist/features/viz/lib/graph/dependency.js.map +7 -0
  128. package/dist/features/viz/lib/graph/force.d.ts +28 -0
  129. package/dist/features/viz/lib/graph/force.js +580 -0
  130. package/dist/features/viz/lib/graph/force.js.map +7 -0
  131. package/dist/features/viz/lib/graph/hierarchy.d.ts +21 -0
  132. package/dist/features/viz/lib/graph/hierarchy.js +112 -0
  133. package/dist/features/viz/lib/graph/hierarchy.js.map +7 -0
  134. package/dist/features/viz/lib/graph/icicle.d.ts +16 -0
  135. package/dist/features/viz/lib/graph/icicle.js +153 -0
  136. package/dist/features/viz/lib/graph/icicle.js.map +7 -0
  137. package/dist/features/viz/lib/graph/matrix.d.ts +30 -0
  138. package/dist/features/viz/lib/graph/matrix.js +243 -0
  139. package/dist/features/viz/lib/graph/matrix.js.map +7 -0
  140. package/dist/features/viz/lib/graph/neighborhood.d.ts +11 -0
  141. package/dist/features/viz/lib/graph/neighborhood.js +281 -0
  142. package/dist/features/viz/lib/graph/neighborhood.js.map +7 -0
  143. package/dist/features/viz/lib/graph/routes.d.ts +35 -0
  144. package/dist/features/viz/lib/graph/routes.js +102 -0
  145. package/dist/features/viz/lib/graph/routes.js.map +7 -0
  146. package/dist/features/viz/lib/graph/sankey.d.ts +44 -0
  147. package/dist/features/viz/lib/graph/sankey.js +341 -0
  148. package/dist/features/viz/lib/graph/sankey.js.map +7 -0
  149. package/dist/features/viz/lib/graph/shared.d.ts +59 -0
  150. package/dist/features/viz/lib/graph/shared.js +296 -0
  151. package/dist/features/viz/lib/graph/shared.js.map +7 -0
  152. package/dist/features/viz/lib/graph/tree.d.ts +11 -0
  153. package/dist/features/viz/lib/graph/tree.js +232 -0
  154. package/dist/features/viz/lib/graph/tree.js.map +7 -0
  155. package/dist/features/viz/lib/graph/treemap.d.ts +20 -0
  156. package/dist/features/viz/lib/graph/treemap.js +227 -0
  157. package/dist/features/viz/lib/graph/treemap.js.map +7 -0
  158. package/dist/features/viz/lib/graph/types.d.ts +1097 -0
  159. package/dist/features/viz/lib/hover-data.d.ts +1 -1
  160. package/dist/features/viz/lib/hover-data.js +5 -2
  161. package/dist/features/viz/lib/hover-data.js.map +2 -2
  162. package/dist/features/viz/lib/interval-band-series.d.ts +49 -0
  163. package/dist/features/viz/lib/interval-band-series.js +136 -0
  164. package/dist/features/viz/lib/interval-band-series.js.map +7 -0
  165. package/dist/features/viz/lib/interval-diamond-series.d.ts +43 -0
  166. package/dist/features/viz/lib/interval-diamond-series.js +124 -0
  167. package/dist/features/viz/lib/interval-diamond-series.js.map +7 -0
  168. package/dist/features/viz/lib/interval-series.d.ts +79 -0
  169. package/dist/features/viz/lib/interval-series.js +158 -0
  170. package/dist/features/viz/lib/interval-series.js.map +7 -0
  171. package/dist/features/viz/lib/line-series.d.ts +1 -1
  172. package/dist/features/viz/lib/line-series.js +47 -28
  173. package/dist/features/viz/lib/line-series.js.map +2 -2
  174. package/dist/features/viz/lib/linear-scale.js +1 -1
  175. package/dist/features/viz/lib/linear-scale.js.map +2 -2
  176. package/dist/features/viz/lib/monotone-curve.d.ts +11 -0
  177. package/dist/features/viz/lib/monotone-curve.js +63 -0
  178. package/dist/features/viz/lib/monotone-curve.js.map +7 -0
  179. package/dist/features/viz/lib/numeric-range-interpolation.d.ts +15 -0
  180. package/dist/features/viz/lib/numeric-range-interpolation.js +36 -0
  181. package/dist/features/viz/lib/numeric-range-interpolation.js.map +7 -0
  182. package/dist/features/viz/lib/ohlc-bar-series.d.ts +55 -0
  183. package/dist/features/viz/lib/ohlc-bar-series.js +168 -0
  184. package/dist/features/viz/lib/ohlc-bar-series.js.map +7 -0
  185. package/dist/features/viz/lib/paired-series.d.ts +44 -0
  186. package/dist/features/viz/lib/paired-series.js +93 -0
  187. package/dist/features/viz/lib/paired-series.js.map +7 -0
  188. package/dist/features/viz/lib/plot-series.js +11 -6
  189. package/dist/features/viz/lib/plot-series.js.map +2 -2
  190. package/dist/features/viz/lib/plot-types.d.ts +4 -3
  191. package/dist/features/viz/lib/point-series.d.ts +1 -1
  192. package/dist/features/viz/lib/point-series.js +36 -9
  193. package/dist/features/viz/lib/point-series.js.map +2 -2
  194. package/dist/features/viz/lib/point-types.d.ts +5 -2
  195. package/dist/features/viz/lib/scale-context.d.ts +1 -1
  196. package/dist/features/viz/lib/scale-ticks.js +21 -6
  197. package/dist/features/viz/lib/scale-ticks.js.map +2 -2
  198. package/dist/features/viz/lib/sequential-color-scale.d.ts +11 -0
  199. package/dist/features/viz/lib/sequential-color-scale.js +49 -0
  200. package/dist/features/viz/lib/sequential-color-scale.js.map +7 -0
  201. package/dist/features/viz/lib/series-position.d.ts +12 -0
  202. package/dist/features/viz/lib/series-position.js +44 -0
  203. package/dist/features/viz/lib/series-position.js.map +7 -0
  204. package/dist/features/viz/lib/step-curves.d.ts +19 -0
  205. package/dist/features/viz/lib/step-curves.js +53 -0
  206. package/dist/features/viz/lib/step-curves.js.map +7 -0
  207. package/dist/features/viz/lib/threshold-color-scale.d.ts +43 -0
  208. package/dist/features/viz/lib/threshold-color-scale.js +59 -0
  209. package/dist/features/viz/lib/threshold-color-scale.js.map +7 -0
  210. package/dist/features/viz/lib/trading-time-mapping.d.ts +32 -0
  211. package/dist/features/viz/lib/trading-time-mapping.js +89 -0
  212. package/dist/features/viz/lib/trading-time-mapping.js.map +7 -0
  213. package/dist/features/viz/lib/trading-time-scale.d.ts +83 -0
  214. package/dist/features/viz/lib/trading-time-scale.js +96 -0
  215. package/dist/features/viz/lib/trading-time-scale.js.map +7 -0
  216. package/dist/features/viz/lib/trajectory-series.d.ts +71 -0
  217. package/dist/features/viz/lib/trajectory-series.js +111 -0
  218. package/dist/features/viz/lib/trajectory-series.js.map +7 -0
  219. package/dist/features/viz/lib/types.d.ts +20 -4
  220. package/dist/features/viz/lib/use-continuous-scale.js +6 -1
  221. package/dist/features/viz/lib/use-continuous-scale.js.map +2 -2
  222. package/dist/features/viz/lib/volume-series.d.ts +59 -0
  223. package/dist/features/viz/lib/volume-series.js +117 -0
  224. package/dist/features/viz/lib/volume-series.js.map +7 -0
  225. package/dist/features/viz/lib/weighted-point-series.d.ts +71 -0
  226. package/dist/features/viz/lib/weighted-point-series.js +169 -0
  227. package/dist/features/viz/lib/weighted-point-series.js.map +7 -0
  228. package/dist/filters/backdrop-contrast-gpu.d.ts +5 -0
  229. package/dist/filters/backdrop-contrast-gpu.js +33 -0
  230. package/dist/filters/backdrop-contrast-gpu.js.map +7 -0
  231. package/dist/filters/backdrop-contrast.d.ts +21 -0
  232. package/dist/filters/backdrop-contrast.js +61 -0
  233. package/dist/filters/backdrop-contrast.js.map +7 -0
  234. package/dist/filters/emboss-gpu.d.ts +4 -0
  235. package/dist/filters/emboss-gpu.js +39 -0
  236. package/dist/filters/emboss-gpu.js.map +7 -0
  237. package/dist/filters/emboss.d.ts +32 -0
  238. package/dist/filters/emboss.js +106 -0
  239. package/dist/filters/emboss.js.map +7 -0
  240. package/dist/filters/filter-executor.d.ts +11 -4
  241. package/dist/filters/filter-executor.js +104 -49
  242. package/dist/filters/filter-executor.js.map +2 -2
  243. package/dist/filters/reflection-gpu.d.ts +3 -1
  244. package/dist/filters/reflection-gpu.js +5 -2
  245. package/dist/filters/reflection-gpu.js.map +2 -2
  246. package/dist/filters/render-backdrop-contrast-boundary.d.ts +31 -0
  247. package/dist/filters/render-backdrop-contrast-boundary.js +116 -0
  248. package/dist/filters/render-backdrop-contrast-boundary.js.map +7 -0
  249. package/dist/filters/render-emboss-boundary.d.ts +13 -0
  250. package/dist/filters/render-emboss-boundary.js +131 -0
  251. package/dist/filters/render-emboss-boundary.js.map +7 -0
  252. package/dist/filters.d.ts +9 -5
  253. package/dist/filters.js +4 -0
  254. package/dist/filters.js.map +2 -2
  255. package/dist/index.d.ts +2 -0
  256. package/dist/index.js +3 -0
  257. package/dist/index.js.map +2 -2
  258. package/dist/internal.d.ts +2 -0
  259. package/dist/internal.js +4 -0
  260. package/dist/internal.js.map +2 -2
  261. package/dist/lib/events/event-facade.d.ts +13 -0
  262. package/dist/lib/events/event-facade.js +23 -0
  263. package/dist/lib/events/event-facade.js.map +2 -2
  264. package/dist/lib/events/propagation.js +19 -14
  265. package/dist/lib/events/propagation.js.map +2 -2
  266. package/dist/lib/execute-render.js +13 -0
  267. package/dist/lib/execute-render.js.map +2 -2
  268. package/dist/lib/recording/recording.d.ts +43 -0
  269. package/dist/lib/recording/recording.js +555 -0
  270. package/dist/lib/recording/recording.js.map +7 -0
  271. package/dist/lib/recording/types.d.ts +118 -0
  272. package/dist/lib/recording/wasm-bytes.d.ts +1 -0
  273. package/dist/lib/recording/wasm-bytes.js +5 -0
  274. package/dist/lib/recording/wasm-bytes.js.map +7 -0
  275. package/dist/lib/recording/worker-source.d.ts +1 -0
  276. package/dist/lib/recording/worker-source.js +5 -0
  277. package/dist/lib/recording/worker-source.js.map +7 -0
  278. package/dist/lib/render-transaction.d.ts +5 -2
  279. package/dist/lib/render-transaction.js +23 -1
  280. package/dist/lib/render-transaction.js.map +2 -2
  281. package/dist/lib/series-inspection-frame.d.ts +18 -0
  282. package/dist/lib/series-inspection-frame.js +70 -0
  283. package/dist/lib/series-inspection-frame.js.map +7 -0
  284. package/dist/lib/types.d.ts +6 -0
  285. package/package.json +10 -2
@@ -0,0 +1,32 @@
1
+ import type { SignalValue } from "../lib/signals/types.js";
2
+ import { type PibblFilter } from "../lib/style/filter-types.js";
3
+ import { type TexturePaint } from "../lib/textures/texture-protocol.js";
4
+ /** Directional lighting of grayscale texture height. See {@link emboss}. */
5
+ export interface PibblEmbossFilterOptions {
6
+ /** Local texture placement region with finite coordinates and positive dimensions. See {@link TexturePaint}. */
7
+ readonly region: Readonly<{
8
+ /** Horizontal origin in local logical coordinates. See {@link PibblEmbossFilterOptions}. */
9
+ x: number;
10
+ /** Vertical origin in local logical coordinates. See {@link PibblEmbossFilterOptions}. */
11
+ y: number;
12
+ /** Positive logical region width. See {@link PibblEmbossFilterOptions}. */
13
+ width: number;
14
+ /** Positive logical region height. See {@link PibblEmbossFilterOptions}. */
15
+ height: number;
16
+ }>;
17
+ /** Height range in logical pixels, finite 0–32; default 3. See {@link emboss}. */
18
+ readonly depth?: SignalValue<number>;
19
+ /** Lighting strength, finite 0–1; default 1. Zero bypasses processing. See {@link emboss}. */
20
+ readonly strength?: SignalValue<number>;
21
+ /** Nonzero finite direction toward the light in local coordinates; default [-0.6, -0.8]. See {@link emboss}. */
22
+ readonly direction?: readonly [number, number];
23
+ }
24
+ /**
25
+ * Lights captured pixels using normals derived from a grayscale texture height map.
26
+ * Flat heights are neutral; opposing slopes brighten and darken without changing alpha or geometry.
27
+ * @param map - Mounted height texture, luminance times alpha; white is high. See {@link TexturePaint}.
28
+ * @param options - Local placement, height depth, strength, and light direction. See {@link PibblEmbossFilterOptions}.
29
+ * @returns A filter descriptor for style.filter. See {@link PibblFilter}.
30
+ * @see {@link PibblEmbossFilterOptions}
31
+ */
32
+ export declare function emboss(map: SignalValue<TexturePaint>, options: PibblEmbossFilterOptions): PibblFilter;
@@ -0,0 +1,106 @@
1
+ import { isSignal } from "../lib/signals/graph.js";
2
+ import { layoutDiagnostic } from "../lib/style/diagnostics.js";
3
+ import {
4
+ PIBBL_FILTER_EXECUTOR
5
+ } from "../lib/style/filter-types.js";
6
+ import {
7
+ borrowTextureRaster,
8
+ validateTexturePaint
9
+ } from "../lib/textures/texture-protocol.js";
10
+ import {
11
+ filterBoundaryExecutor
12
+ } from "./filter-executor.js";
13
+ import { processEmboss } from "./render-emboss-boundary.js";
14
+ const definitions = /* @__PURE__ */ new WeakMap();
15
+ const executor = {
16
+ prepare(value, property, context) {
17
+ const definition = definitions.get(value);
18
+ if (!definition)
19
+ throw new Error(
20
+ "An emboss filter was created by an incompatible Pibbl runtime."
21
+ );
22
+ const { options } = definition;
23
+ const fail = (key, value2, reason) => layoutDiagnostic({
24
+ component: context.component,
25
+ property: `${property}.${key}`,
26
+ value: value2,
27
+ algorithm: context.algorithm,
28
+ constraints: context.constraints,
29
+ reason
30
+ });
31
+ const numeric = (key, fallback, maximum) => {
32
+ const input = options[key];
33
+ const value2 = input === void 0 ? fallback : isSignal(input) ? input.get() : input;
34
+ if (typeof value2 !== "number" || !Number.isFinite(value2) || value2 < 0 || value2 > maximum)
35
+ throw fail(key, value2, `must be finite within 0..${maximum}`);
36
+ return value2;
37
+ };
38
+ const depth = numeric("depth", 3, 32), strength = numeric("strength", 1, 1);
39
+ const direction = options.direction ?? [-0.6, -0.8];
40
+ if (!Array.isArray(direction) || direction.length !== 2 || !direction.every(
41
+ (value2) => typeof value2 === "number" && Number.isFinite(value2)
42
+ ) || Math.hypot(...direction) === 0)
43
+ throw fail(
44
+ "direction",
45
+ direction,
46
+ "must contain two finite components with nonzero length"
47
+ );
48
+ const length = Math.hypot(...direction);
49
+ const candidate = options.region;
50
+ if (!candidate || typeof candidate !== "object")
51
+ throw fail(
52
+ "region",
53
+ candidate,
54
+ "must contain finite coordinates and positive dimensions"
55
+ );
56
+ const { x, y, width, height } = candidate;
57
+ if (![x, y, width, height].every(
58
+ (value2) => typeof value2 === "number" && Number.isFinite(value2)
59
+ ) || width <= 0 || height <= 0)
60
+ throw fail(
61
+ "region",
62
+ candidate,
63
+ "must contain finite coordinates and positive dimensions"
64
+ );
65
+ const region = { x, y, width, height };
66
+ const map = isSignal(definition.map) ? definition.map.get() : definition.map;
67
+ try {
68
+ validateTexturePaint(map);
69
+ if (strength !== 0 && depth !== 0)
70
+ borrowTextureRaster(map, () => void 0);
71
+ } catch (error) {
72
+ throw fail(
73
+ "map",
74
+ map,
75
+ error instanceof Error ? error.message : String(error)
76
+ );
77
+ }
78
+ const settings = {
79
+ opacity: strength,
80
+ depth,
81
+ threshold: 0,
82
+ softness: 1,
83
+ direction: [direction[0] / length, direction[1] / length]
84
+ };
85
+ return Object.freeze({
86
+ executor: filterBoundaryExecutor,
87
+ reverseInfluence: (output) => ({ ...output }),
88
+ process: strength === 0 || depth === 0 ? void 0 : (source, windows) => processEmboss(source, windows, map, settings, region)
89
+ });
90
+ },
91
+ render: filterBoundaryExecutor.render
92
+ };
93
+ function emboss(map, options) {
94
+ const frozen = Object.freeze({
95
+ ...options,
96
+ region: Object.freeze({ ...options.region }),
97
+ direction: options.direction && Object.freeze([...options.direction])
98
+ });
99
+ const value = Object.freeze({ [PIBBL_FILTER_EXECUTOR]: executor });
100
+ definitions.set(value, { map, options: frozen });
101
+ return value;
102
+ }
103
+ export {
104
+ emboss
105
+ };
106
+ //# sourceMappingURL=emboss.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/filters/emboss.ts"],
4
+ "sourcesContent": ["import { isSignal } from \"../lib/signals/graph.js\";\nimport type { SignalValue } from \"../lib/signals/types.js\";\nimport { layoutDiagnostic } from \"../lib/style/diagnostics.js\";\nimport {\n PIBBL_FILTER_EXECUTOR,\n type PibblFilter,\n type PibblFilterExecutor,\n} from \"../lib/style/filter-types.js\";\nimport {\n borrowTextureRaster,\n validateTexturePaint,\n type TexturePaint,\n} from \"../lib/textures/texture-protocol.js\";\nimport {\n filterBoundaryExecutor,\n type CustomPreparedFilter,\n} from \"./filter-executor.js\";\nimport { processEmboss } from \"./render-emboss-boundary.js\";\n\n/** Directional lighting of grayscale texture height. See {@link emboss}. */\nexport interface PibblEmbossFilterOptions {\n /** Local texture placement region with finite coordinates and positive dimensions. See {@link TexturePaint}. */\n readonly region: Readonly<{\n /** Horizontal origin in local logical coordinates. See {@link PibblEmbossFilterOptions}. */\n x: number;\n /** Vertical origin in local logical coordinates. See {@link PibblEmbossFilterOptions}. */\n y: number;\n /** Positive logical region width. See {@link PibblEmbossFilterOptions}. */\n width: number;\n /** Positive logical region height. See {@link PibblEmbossFilterOptions}. */\n height: number;\n }>;\n /** Height range in logical pixels, finite 0\u201332; default 3. See {@link emboss}. */\n readonly depth?: SignalValue<number>;\n /** Lighting strength, finite 0\u20131; default 1. Zero bypasses processing. See {@link emboss}. */\n readonly strength?: SignalValue<number>;\n /** Nonzero finite direction toward the light in local coordinates; default [-0.6, -0.8]. See {@link emboss}. */\n readonly direction?: readonly [number, number];\n}\nconst definitions = new WeakMap<\n PibblFilter,\n {\n map: SignalValue<TexturePaint>;\n options: Readonly<PibblEmbossFilterOptions>;\n }\n>();\nconst executor: PibblFilterExecutor = {\n prepare(value, property, context) {\n const definition = definitions.get(value);\n if (!definition)\n throw new Error(\n \"An emboss filter was created by an incompatible Pibbl runtime.\",\n );\n const { options } = definition;\n const fail = (key: string, value: unknown, reason: string) =>\n layoutDiagnostic({\n component: context.component,\n property: `${property}.${key}`,\n value,\n algorithm: context.algorithm,\n constraints: context.constraints,\n reason,\n });\n const numeric = (\n key: \"depth\" | \"strength\",\n fallback: number,\n maximum: number,\n ) => {\n const input = options[key];\n const value =\n input === undefined ? fallback : isSignal(input) ? input.get() : input;\n if (\n typeof value !== \"number\" ||\n !Number.isFinite(value) ||\n value < 0 ||\n value > maximum\n )\n throw fail(key, value, `must be finite within 0..${maximum}`);\n return value;\n };\n const depth = numeric(\"depth\", 3, 32),\n strength = numeric(\"strength\", 1, 1);\n const direction: unknown = options.direction ?? [-0.6, -0.8];\n if (\n !Array.isArray(direction) ||\n direction.length !== 2 ||\n !direction.every(\n (value) => typeof value === \"number\" && Number.isFinite(value),\n ) ||\n Math.hypot(...direction) === 0\n )\n throw fail(\n \"direction\",\n direction,\n \"must contain two finite components with nonzero length\",\n );\n const length = Math.hypot(...direction);\n const candidate: unknown = options.region;\n if (!candidate || typeof candidate !== \"object\")\n throw fail(\n \"region\",\n candidate,\n \"must contain finite coordinates and positive dimensions\",\n );\n const { x, y, width, height } = candidate as {\n x: number;\n y: number;\n width: number;\n height: number;\n };\n if (\n ![x, y, width, height].every(\n (value) => typeof value === \"number\" && Number.isFinite(value),\n ) ||\n width <= 0 ||\n height <= 0\n )\n throw fail(\n \"region\",\n candidate,\n \"must contain finite coordinates and positive dimensions\",\n );\n const region = { x, y, width, height };\n const map = isSignal(definition.map)\n ? definition.map.get()\n : definition.map;\n try {\n validateTexturePaint(map);\n if (strength !== 0 && depth !== 0)\n borrowTextureRaster(map, () => undefined);\n } catch (error) {\n throw fail(\n \"map\",\n map,\n error instanceof Error ? error.message : String(error),\n );\n }\n const settings = {\n opacity: strength,\n depth,\n threshold: 0,\n softness: 1,\n direction: [direction[0] / length, direction[1] / length] as const,\n };\n return Object.freeze({\n executor: filterBoundaryExecutor,\n reverseInfluence: (output) => ({ ...output }),\n process:\n strength === 0 || depth === 0\n ? undefined\n : (source, windows) =>\n processEmboss(source, windows, map, settings, region),\n } satisfies CustomPreparedFilter);\n },\n render: filterBoundaryExecutor.render,\n};\n/**\n * Lights captured pixels using normals derived from a grayscale texture height map.\n * Flat heights are neutral; opposing slopes brighten and darken without changing alpha or geometry.\n * @param map - Mounted height texture, luminance times alpha; white is high. See {@link TexturePaint}.\n * @param options - Local placement, height depth, strength, and light direction. See {@link PibblEmbossFilterOptions}.\n * @returns A filter descriptor for style.filter. See {@link PibblFilter}.\n * @see {@link PibblEmbossFilterOptions}\n */\nexport function emboss(\n map: SignalValue<TexturePaint>,\n options: PibblEmbossFilterOptions,\n): PibblFilter {\n const frozen = Object.freeze({\n ...options,\n region: Object.freeze({ ...options.region }),\n direction:\n options.direction &&\n (Object.freeze([...options.direction]) as readonly [number, number]),\n });\n const value = Object.freeze({ [PIBBL_FILTER_EXECUTOR]: executor });\n definitions.set(value, { map, options: frozen });\n return value;\n}\n"],
5
+ "mappings": "AAAA,SAAS,gBAAgB;AAEzB,SAAS,wBAAwB;AACjC;AAAA,EACE;AAAA,OAGK;AACP;AAAA,EACE;AAAA,EACA;AAAA,OAEK;AACP;AAAA,EACE;AAAA,OAEK;AACP,SAAS,qBAAqB;AAsB9B,MAAM,cAAc,oBAAI,QAMtB;AACF,MAAM,WAAgC;AAAA,EACpC,QAAQ,OAAO,UAAU,SAAS;AAChC,UAAM,aAAa,YAAY,IAAI,KAAK;AACxC,QAAI,CAAC;AACH,YAAM,IAAI;AAAA,QACR;AAAA,MACF;AACF,UAAM,EAAE,QAAQ,IAAI;AACpB,UAAM,OAAO,CAAC,KAAaA,QAAgB,WACzC,iBAAiB;AAAA,MACf,WAAW,QAAQ;AAAA,MACnB,UAAU,GAAG,QAAQ,IAAI,GAAG;AAAA,MAC5B,OAAAA;AAAA,MACA,WAAW,QAAQ;AAAA,MACnB,aAAa,QAAQ;AAAA,MACrB;AAAA,IACF,CAAC;AACH,UAAM,UAAU,CACd,KAC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,UAAU;AAC9B,4BAAoB,KAAK,MAAM,MAAS;AAAA,IAC5C,SAAS,OAAO;AACd,YAAM;AAAA,QACJ;AAAA,QACA;AAAA,QACA,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;AAAA,MACvD;AAAA,IACF;AACA,UAAM,WAAW;AAAA,MACf,SAAS;AAAA,MACT;AAAA,MACA,WAAW;AAAA,MACX,UAAU;AAAA,MACV,WAAW,CAAC,UAAU,CAAC,IAAI,QAAQ,UAAU,CAAC,IAAI,MAAM;AAAA,IAC1D;AACA,WAAO,OAAO,OAAO;AAAA,MACnB,UAAU;AAAA,MACV,kBAAkB,CAAC,YAAY,EAAE,GAAG,OAAO;AAAA,MAC3C,SACE,aAAa,KAAK,UAAU,IACxB,SACA,CAAC,QAAQ,YACP,cAAc,QAAQ,SAAS,KAAK,UAAU,MAAM;AAAA,IAC9D,CAAgC;AAAA,EAClC;AAAA,EACA,QAAQ,uBAAuB;AACjC;AASO,SAAS,OACd,KACA,SACa;AACb,QAAM,SAAS,OAAO,OAAO;AAAA,IAC3B,GAAG;AAAA,IACH,QAAQ,OAAO,OAAO,EAAE,GAAG,QAAQ,OAAO,CAAC;AAAA,IAC3C,WACE,QAAQ,aACP,OAAO,OAAO,CAAC,GAAG,QAAQ,SAAS,CAAC;AAAA,EACzC,CAAC;AACD,QAAM,QAAQ,OAAO,OAAO,EAAE,CAAC,qBAAqB,GAAG,SAAS,CAAC;AACjE,cAAY,IAAI,OAAO,EAAE,KAAK,SAAS,OAAO,CAAC;AAC/C,SAAO;AACT;",
6
+ "names": ["value"]
7
+ }
@@ -1,6 +1,12 @@
1
- import type { TexturePaint } from '../lib/textures/texture-protocol.js';
2
- import type { FilterWindows, PixelBounds } from '../lib/filter/filter-region.js';
3
- import type { PibblFilterBoundaryExecutor, PreparedPibblFilter } from '../lib/style/filter-types.js';
1
+ import type { TexturePaint } from "../lib/textures/texture-protocol.js";
2
+ import type { Canvas } from "../lib/types.js";
3
+ import type { FilterWindows, PixelBounds } from "../lib/filter/filter-region.js";
4
+ import type { PibblFilterBoundaryExecutor, PreparedPibblFilter } from "../lib/style/filter-types.js";
5
+ /** Backing-pixel projection of the already-painted current render target. */
6
+ export interface FilterBackdrop {
7
+ readonly canvas: Canvas;
8
+ readonly transform: DOMMatrix;
9
+ }
4
10
  /** An operation-owned pass. The shared executor knows nothing about its inputs. */
5
11
  export interface CustomPreparedFilter extends PreparedPibblFilter {
6
12
  readonly reverseInfluence: (output: Readonly<PixelBounds>, density: number) => PixelBounds;
@@ -16,6 +22,7 @@ export interface CustomPreparedFilter extends PreparedPibblFilter {
16
22
  }>;
17
23
  }>;
18
24
  readonly fuseWithPrevious?: (previous: CustomPreparedFilter) => CustomPreparedFilter | undefined;
19
- readonly process?: (source: OffscreenCanvas, windows: FilterWindows) => ImageBitmap;
25
+ readonly needsBackdrop?: boolean;
26
+ readonly process?: (source: OffscreenCanvas, windows: FilterWindows, backdrop?: FilterBackdrop) => ImageBitmap;
20
27
  }
21
28
  export declare const filterBoundaryExecutor: PibblFilterBoundaryExecutor;
@@ -1,8 +1,11 @@
1
1
  import { GLOBAL_STATE } from "../lib/global-state.js";
2
2
  import { getOptionalService } from "../lib/optional-services.js";
3
+ import { getCurrentPaintTransform } from "../lib/render-target.js";
3
4
  import { enterPrimitivePresentation } from "../lib/primitive-presentation.js";
4
5
  import { renderFilterBoundary } from "../lib/filter/render-filter-boundary.js";
5
- import { compileNativeFilters } from "./native-operations.js";
6
+ import {
7
+ compileNativeFilters
8
+ } from "./native-operations.js";
6
9
  import { assertNativeCanvasFilter } from "./native-canvas-filter.js";
7
10
  const SCRATCH = /* @__PURE__ */ Symbol("pibbl.filter-pass-scratch");
8
11
  class PassScratch {
@@ -24,11 +27,17 @@ class PassScratch {
24
27
  if (success || !this.committed) this.dispose();
25
28
  }
26
29
  target(index, width, height) {
27
- const canvas = this.surfaces[index] ??= new OffscreenCanvas(width, height);
30
+ const canvas = this.surfaces[index] ??= new OffscreenCanvas(
31
+ width,
32
+ height
33
+ );
28
34
  if (canvas.width !== width) canvas.width = width;
29
35
  if (canvas.height !== height) canvas.height = height;
30
36
  const context = canvas.getContext("2d");
31
- if (!context) throw new Error("Filter passes require an OffscreenCanvas 2D scratch target.");
37
+ if (!context)
38
+ throw new Error(
39
+ "Filter passes require an OffscreenCanvas 2D scratch target."
40
+ );
32
41
  context.reset();
33
42
  return context;
34
43
  }
@@ -60,58 +69,104 @@ const filterBoundaryExecutor = {
60
69
  }
61
70
  return;
62
71
  }
63
- if (operations.every((operation) => "css" in operation)) {
64
- renderFilterBoundary({ component: input.component, filters: operations, presentation: input.presentation }, input.renderSubtree);
72
+ if (operations.every(
73
+ (operation) => "css" in operation
74
+ )) {
75
+ renderFilterBoundary(
76
+ {
77
+ component: input.component,
78
+ filters: operations,
79
+ presentation: input.presentation
80
+ },
81
+ input.renderSubtree
82
+ );
65
83
  return;
66
84
  }
67
- const bounds = operations.map((operation) => "css" in operation ? operation : {
68
- executor: filterBoundaryExecutor,
69
- css: () => "none",
70
- reverseInfluence: operation.reverseInfluence
71
- });
72
- renderFilterBoundary({
73
- component: input.component,
74
- filters: bounds,
75
- presentation: input.presentation,
76
- process(source, result, windows) {
77
- const instance = GLOBAL_STATE.currentPibblInstance;
78
- if (!instance) throw new Error("Filter processing requires an active Pibbl instance.");
79
- const scratch = getOptionalService(instance, SCRATCH, () => new PassScratch(instance));
80
- scratch.used = true;
81
- let current = source, pass = 0;
82
- let native = [];
83
- const target = () => scratch.target(pass++ % 2, source.width, source.height);
84
- const applyNative = () => {
85
- if (!native.length) return;
86
- const context = target();
87
- assertNativeCanvasFilter(context, compileNativeFilters(native, windows.density), input.component, () => {
88
- for (const operation of native) if (operation.onRejected) {
89
- assertNativeCanvasFilter(context, operation.css(windows.density), input.component, operation.onRejected);
90
- }
91
- });
92
- context.drawImage(current, 0, 0);
93
- current = context.canvas;
94
- native = [];
95
- };
96
- for (const operation of operations) {
97
- if ("css" in operation) {
98
- native.push(operation);
99
- continue;
100
- }
101
- applyNative();
102
- const bitmap = operation.process(current, windows);
103
- try {
85
+ const parent = operations.some(
86
+ (operation) => "needsBackdrop" in operation && operation.needsBackdrop
87
+ ) ? GLOBAL_STATE.renderContext : void 0;
88
+ const parentTarget = parent ? GLOBAL_STATE.renderTarget : void 0;
89
+ const paint = parent ? getCurrentPaintTransform() : void 0;
90
+ const boundaryPaint = paint && input.presentation?.transform ? paint.multiply(input.presentation.transform) : paint;
91
+ const bounds = operations.map(
92
+ (operation) => "css" in operation ? operation : {
93
+ executor: filterBoundaryExecutor,
94
+ css: () => "none",
95
+ reverseInfluence: operation.reverseInfluence
96
+ }
97
+ );
98
+ renderFilterBoundary(
99
+ {
100
+ component: input.component,
101
+ filters: bounds,
102
+ presentation: input.presentation,
103
+ process(source, result, windows) {
104
+ const instance = GLOBAL_STATE.currentPibblInstance;
105
+ if (!instance)
106
+ throw new Error(
107
+ "Filter processing requires an active Pibbl instance."
108
+ );
109
+ const scratch = getOptionalService(
110
+ instance,
111
+ SCRATCH,
112
+ () => new PassScratch(instance)
113
+ );
114
+ scratch.used = true;
115
+ let current = source, pass = 0;
116
+ let native = [];
117
+ const target = () => scratch.target(pass++ % 2, source.width, source.height);
118
+ const applyNative = () => {
119
+ if (!native.length) return;
104
120
  const context = target();
105
- context.drawImage(bitmap, 0, 0);
121
+ assertNativeCanvasFilter(
122
+ context,
123
+ compileNativeFilters(native, windows.density),
124
+ input.component,
125
+ () => {
126
+ for (const operation of native)
127
+ if (operation.onRejected) {
128
+ assertNativeCanvasFilter(
129
+ context,
130
+ operation.css(windows.density),
131
+ input.component,
132
+ operation.onRejected
133
+ );
134
+ }
135
+ }
136
+ );
137
+ context.drawImage(current, 0, 0);
106
138
  current = context.canvas;
107
- } finally {
108
- bitmap.close();
139
+ native = [];
140
+ };
141
+ for (const operation of operations) {
142
+ if ("css" in operation) {
143
+ native.push(operation);
144
+ continue;
145
+ }
146
+ applyNative();
147
+ const backdrop = parent && parentTarget && boundaryPaint ? {
148
+ canvas: parent.canvas,
149
+ transform: windows.source.renderTransform.multiply(boundaryPaint.inverse()).multiply(parentTarget.inverseRenderTransform)
150
+ } : void 0;
151
+ const bitmap = operation.process(current, windows, backdrop);
152
+ try {
153
+ const context = target();
154
+ context.drawImage(bitmap, 0, 0);
155
+ current = context.canvas;
156
+ } finally {
157
+ bitmap.close();
158
+ }
109
159
  }
160
+ applyNative();
161
+ result.drawImage(
162
+ current,
163
+ windows.sourceToOutputX,
164
+ windows.sourceToOutputY
165
+ );
110
166
  }
111
- applyNative();
112
- result.drawImage(current, windows.sourceToOutputX, windows.sourceToOutputY);
113
- }
114
- }, input.renderSubtree);
167
+ },
168
+ input.renderSubtree
169
+ );
115
170
  }
116
171
  };
117
172
  export {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/filters/filter-executor.ts"],
4
- "sourcesContent": ["import type { TexturePaint } from '../lib/textures/texture-protocol.js';\nimport { GLOBAL_STATE } from '../lib/global-state.js';\nimport { getOptionalService } from '../lib/optional-services.js';\nimport { enterPrimitivePresentation } from '../lib/primitive-presentation.js';\nimport { renderFilterBoundary } from '../lib/filter/render-filter-boundary.js';\nimport type { FilterWindows, PixelBounds } from '../lib/filter/filter-region.js';\nimport type { PibblFilterBoundaryExecutor, PreparedPibblFilter } from '../lib/style/filter-types.js';\nimport type { PibblInstance } from '../lib/types.js';\nimport { compileNativeFilters, type NativePreparedFilter } from './native-operations.js';\nimport { assertNativeCanvasFilter } from './native-canvas-filter.js';\n\n/** An operation-owned pass. The shared executor knows nothing about its inputs. */\nexport interface CustomPreparedFilter extends PreparedPibblFilter {\n readonly reverseInfluence: (output: Readonly<PixelBounds>, density: number) => PixelBounds;\n /** Private fusion capability; no concrete GPU implementation enters this module. */\n readonly textureWarp?: Readonly<{ map: TexturePaint; strength: number; region: Readonly<{x:number;y:number;width:number;height:number}> }>;\n readonly fuseWithPrevious?: (previous: CustomPreparedFilter) => CustomPreparedFilter | undefined;\n readonly process?: (source: OffscreenCanvas, windows: FilterWindows) => ImageBitmap;\n}\ntype Operation = NativePreparedFilter | CustomPreparedFilter;\nconst SCRATCH = Symbol('pibbl.filter-pass-scratch');\nclass PassScratch {\n private readonly surfaces: OffscreenCanvas[] = [];\n used = false;\n private committed = false;\n constructor(private readonly instance: PibblInstance) {}\n beginRender(): void { this.used = false; }\n endRender(success: boolean): void {\n if (success && this.used) { this.committed = true; return; }\n if (success || !this.committed) this.dispose();\n }\n target(index: number, width: number, height: number): OffscreenCanvasRenderingContext2D {\n const canvas = this.surfaces[index] ??= new OffscreenCanvas(width, height);\n if (canvas.width !== width) canvas.width = width;\n if (canvas.height !== height) canvas.height = height;\n const context = canvas.getContext('2d');\n if (!context) throw new Error('Filter passes require an OffscreenCanvas 2D scratch target.');\n context.reset();\n return context;\n }\n dispose(): void {\n for (const canvas of this.surfaces) { canvas.width = 0; canvas.height = 0; }\n this.surfaces.length = 0;\n this.instance.optionalServices.delete(SCRATCH);\n }\n}\n\nexport const filterBoundaryExecutor: PibblFilterBoundaryExecutor = {\n render(input) {\n const operations: Operation[] = [];\n for (const operation of input.filters as readonly Operation[]) {\n if (!('css' in operation) && !operation.process) continue;\n const previous = operations.at(-1);\n const fused = previous && !('css' in previous) && !('css' in operation)\n ? operation.fuseWithPrevious?.(previous) : undefined;\n if (fused) operations[operations.length - 1] = fused;\n else operations.push(operation);\n }\n if (!operations.length) {\n const release = enterPrimitivePresentation(input.presentation);\n try { input.renderSubtree(); } finally { release(); }\n return;\n }\n if (operations.every((operation): operation is NativePreparedFilter => 'css' in operation)) {\n renderFilterBoundary({ component: input.component, filters: operations, presentation: input.presentation }, input.renderSubtree);\n return;\n }\n const bounds = operations.map(operation => 'css' in operation ? operation : {\n executor: filterBoundaryExecutor, css: () => 'none', reverseInfluence: operation.reverseInfluence,\n });\n renderFilterBoundary({\n component: input.component, filters: bounds, presentation: input.presentation,\n process(source, result, windows) {\n const instance = GLOBAL_STATE.currentPibblInstance;\n if (!instance) throw new Error('Filter processing requires an active Pibbl instance.');\n const scratch = getOptionalService(instance, SCRATCH, () => new PassScratch(instance));\n scratch.used = true;\n let current = source, pass = 0;\n let native: NativePreparedFilter[] = [];\n const target = () => scratch.target(pass++ % 2, source.width, source.height);\n const applyNative = () => {\n if (!native.length) return;\n const context = target();\n assertNativeCanvasFilter(context, compileNativeFilters(native, windows.density), input.component, () => {\n for (const operation of native) if (operation.onRejected) {\n assertNativeCanvasFilter(context, operation.css(windows.density), input.component, operation.onRejected);\n }\n });\n context.drawImage(current, 0, 0);\n current = context.canvas;\n native = [];\n };\n for (const operation of operations) {\n if ('css' in operation) { native.push(operation); continue; }\n applyNative();\n const bitmap = operation.process!(current, windows);\n try {\n const context = target(); context.drawImage(bitmap, 0, 0); current = context.canvas;\n } finally { bitmap.close(); }\n }\n applyNative();\n result.drawImage(current, windows.sourceToOutputX, windows.sourceToOutputY);\n },\n }, input.renderSubtree);\n },\n};\n"],
5
- "mappings": "AACA,SAAS,oBAAoB;AAC7B,SAAS,0BAA0B;AACnC,SAAS,kCAAkC;AAC3C,SAAS,4BAA4B;AAIrC,SAAS,4BAAuD;AAChE,SAAS,gCAAgC;AAWzC,MAAM,UAAU,uBAAO,2BAA2B;AAClD,MAAM,YAAY;AAAA,EAIhB,YAA6B,UAAyB;AAAzB;AAAA,EAA0B;AAAA,EAA1B;AAAA,EAHZ,WAA8B,CAAC;AAAA,EAChD,OAAO;AAAA,EACC,YAAY;AAAA,EAEpB,cAAoB;AAAE,SAAK,OAAO;AAAA,EAAO;AAAA,EACzC,UAAU,SAAwB;AAChC,QAAI,WAAW,KAAK,MAAM;AAAE,WAAK,YAAY;AAAM;AAAA,IAAQ;AAC3D,QAAI,WAAW,CAAC,KAAK,UAAW,MAAK,QAAQ;AAAA,EAC/C;AAAA,EACA,OAAO,OAAe,OAAe,QAAmD;AACtF,UAAM,SAAS,KAAK,SAAS,KAAK,MAAM,IAAI,gBAAgB,OAAO,MAAM;AACzE,QAAI,OAAO,UAAU,M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": ["import type { TexturePaint } from \"../lib/textures/texture-protocol.js\";\nimport { GLOBAL_STATE } from \"../lib/global-state.js\";\nimport { getOptionalService } from \"../lib/optional-services.js\";\nimport { getCurrentPaintTransform } from \"../lib/render-target.js\";\nimport type { Canvas } from \"../lib/types.js\";\nimport { enterPrimitivePresentation } from \"../lib/primitive-presentation.js\";\nimport { renderFilterBoundary } from \"../lib/filter/render-filter-boundary.js\";\nimport type {\n FilterWindows,\n PixelBounds,\n} from \"../lib/filter/filter-region.js\";\nimport type {\n PibblFilterBoundaryExecutor,\n PreparedPibblFilter,\n} from \"../lib/style/filter-types.js\";\nimport type { PibblInstance } from \"../lib/types.js\";\nimport {\n compileNativeFilters,\n type NativePreparedFilter,\n} from \"./native-operations.js\";\nimport { assertNativeCanvasFilter } from \"./native-canvas-filter.js\";\n\n/** Backing-pixel projection of the already-painted current render target. */\nexport interface FilterBackdrop {\n readonly canvas: Canvas;\n readonly transform: DOMMatrix;\n}\n\n/** An operation-owned pass. The shared executor knows nothing about its inputs. */\nexport interface CustomPreparedFilter extends PreparedPibblFilter {\n readonly reverseInfluence: (\n output: Readonly<PixelBounds>,\n density: number,\n ) => PixelBounds;\n /** Private fusion capability; no concrete GPU implementation enters this module. */\n readonly textureWarp?: Readonly<{\n map: TexturePaint;\n strength: number;\n region: Readonly<{ x: number; y: number; width: number; height: number }>;\n }>;\n readonly fuseWithPrevious?: (\n previous: CustomPreparedFilter,\n ) => CustomPreparedFilter | undefined;\n readonly needsBackdrop?: boolean;\n readonly process?: (\n source: OffscreenCanvas,\n windows: FilterWindows,\n backdrop?: FilterBackdrop,\n ) => ImageBitmap;\n}\ntype Operation = NativePreparedFilter | CustomPreparedFilter;\nconst SCRATCH = Symbol(\"pibbl.filter-pass-scratch\");\nclass PassScratch {\n private readonly surfaces: OffscreenCanvas[] = [];\n used = false;\n private committed = false;\n constructor(private readonly instance: PibblInstance) {}\n beginRender(): void {\n this.used = false;\n }\n endRender(success: boolean): void {\n if (success && this.used) {\n this.committed = true;\n return;\n }\n if (success || !this.committed) this.dispose();\n }\n target(\n index: number,\n width: number,\n height: number,\n ): OffscreenCanvasRenderingContext2D {\n const canvas = (this.surfaces[index] ??= new OffscreenCanvas(\n width,\n height,\n ));\n if (canvas.width !== width) canvas.width = width;\n if (canvas.height !== height) canvas.height = height;\n const context = canvas.getContext(\"2d\");\n if (!context)\n throw new Error(\n \"Filter passes require an OffscreenCanvas 2D scratch target.\",\n );\n context.reset();\n return context;\n }\n dispose(): void {\n for (const canvas of this.surfaces) {\n canvas.width = 0;\n canvas.height = 0;\n }\n this.surfaces.length = 0;\n this.instance.optionalServices.delete(SCRATCH);\n }\n}\n\nexport const filterBoundaryExecutor: PibblFilterBoundaryExecutor = {\n render(input) {\n const operations: Operation[] = [];\n for (const operation of input.filters as readonly Operation[]) {\n if (!(\"css\" in operation) && !operation.process) continue;\n const previous = operations.at(-1);\n const fused =\n previous && !(\"css\" in previous) && !(\"css\" in operation)\n ? operation.fuseWithPrevious?.(previous)\n : undefined;\n if (fused) operations[operations.length - 1] = fused;\n else operations.push(operation);\n }\n if (!operations.length) {\n const release = enterPrimitivePresentation(input.presentation);\n try {\n input.renderSubtree();\n } finally {\n release();\n }\n return;\n }\n if (\n operations.every(\n (operation): operation is NativePreparedFilter => \"css\" in operation,\n )\n ) {\n renderFilterBoundary(\n {\n component: input.component,\n filters: operations,\n presentation: input.presentation,\n },\n input.renderSubtree,\n );\n return;\n }\n // Snapshot the parent projection before capture switches the current render target.\n const parent = operations.some(\n (operation) => \"needsBackdrop\" in operation && operation.needsBackdrop,\n )\n ? GLOBAL_STATE.renderContext\n : undefined;\n const parentTarget = parent ? GLOBAL_STATE.renderTarget : undefined;\n const paint = parent ? getCurrentPaintTransform() : undefined;\n const boundaryPaint =\n paint && input.presentation?.transform\n ? paint.multiply(input.presentation.transform)\n : paint;\n const bounds = operations.map((operation) =>\n \"css\" in operation\n ? operation\n : {\n executor: filterBoundaryExecutor,\n css: () => \"none\",\n reverseInfluence: operation.reverseInfluence,\n },\n );\n renderFilterBoundary(\n {\n component: input.component,\n filters: bounds,\n presentation: input.presentation,\n process(source, result, windows) {\n const instance = GLOBAL_STATE.currentPibblInstance;\n if (!instance)\n throw new Error(\n \"Filter processing requires an active Pibbl instance.\",\n );\n const scratch = getOptionalService(\n instance,\n SCRATCH,\n () => new PassScratch(instance),\n );\n scratch.used = true;\n let current = source,\n pass = 0;\n let native: NativePreparedFilter[] = [];\n const target = () =>\n scratch.target(pass++ % 2, source.width, source.height);\n const applyNative = () => {\n if (!native.length) return;\n const context = target();\n assertNativeCanvasFilter(\n context,\n compileNativeFilters(native, windows.density),\n input.component,\n () => {\n for (const operation of native)\n if (operation.onRejected) {\n assertNativeCanvasFilter(\n context,\n operation.css(windows.density),\n input.component,\n operation.onRejected,\n );\n }\n },\n );\n context.drawImage(current, 0, 0);\n current = context.canvas;\n native = [];\n };\n for (const operation of operations) {\n if (\"css\" in operation) {\n native.push(operation);\n continue;\n }\n applyNative();\n const backdrop =\n parent && parentTarget && boundaryPaint\n ? {\n canvas: parent.canvas,\n transform: windows.source.renderTransform\n .multiply(boundaryPaint.inverse())\n .multiply(parentTarget.inverseRenderTransform),\n }\n : undefined;\n const bitmap = operation.process!(current, windows, backdrop);\n try {\n const context = target();\n context.drawImage(bitmap, 0, 0);\n current = context.canvas;\n } finally {\n bitmap.close();\n }\n }\n applyNative();\n result.drawImage(\n current,\n windows.sourceToOutputX,\n windows.sourceToOutputY,\n );\n },\n },\n input.renderSubtree,\n );\n },\n};\n"],
5
+ "mappings": "AACA,SAAS,oBAAoB;AAC7B,SAAS,0BAA0B;AACnC,SAAS,gCAAgC;AAEzC,SAAS,kCAAkC;AAC3C,SAAS,4BAA4B;AAUrC;AAAA,EACE;AAAA,OAEK;AACP,SAAS,gCAAgC;AA+BzC,MAAM,UAAU,uBAAO,2BAA2B;AAClD,MAAM,YAAY;AAAA,EAIhB,YAA6B,UAAyB;AAAzB;AAAA,EAA0B;AAAA,EAA1B;AAAA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,OAAO;AAAA,cAC5C,MAAM;AAAA,cACN,MAAM;AACJ,2BAAW,aAAa;AACtB,sBAAI,UAAU,YAAY;AACxB;AAAA,sBACE;AAAA,sBACA,UAAU,IAAI,QAAQ,OAAO;AAAA,sBAC7B,MAAM;AAAA,sBACN,UAAU;AAAA,oBACZ;AAAA,kBACF;AAAA,cACJ;AAAA,YACF;AACA,oBAAQ,UAAU,SAAS,GAAG,CAAC;AAC/B,sBAAU,QAAQ;AAClB,qBAAS,CAAC;AAAA,UACZ;AACA,qBAAW,aAAa,YAAY;AAClC,gBAAI,SAAS,WAAW;AACtB,qBAAO,KAAK,SAAS;AACrB;AAAA,YACF;AACA,wBAAY;AACZ,kBAAM,WACJ,UAAU,gBAAgB,gBACtB;AAAA,cACE,QAAQ,OAAO;AAAA,cACf,WAAW,QAAQ,OAAO,gBACvB,SAAS,cAAc,QAAQ,CAAC,EAChC,SAAS,aAAa,sBAAsB;AAAA,YACjD,IACA;AACN,kBAAM,SAAS,UAAU,QAAS,SAAS,SAAS,QAAQ;AAC5D,gBAAI;AACF,oBAAM,UAAU,OAAO;AACvB,sBAAQ,UAAU,QAAQ,GAAG,CAAC;AAC9B,wBAAU,QAAQ;AAAA,YACpB,UAAE;AACA,qBAAO,MAAM;AAAA,YACf;AAAA,UACF;AACA,sBAAY;AACZ,iBAAO;AAAA,YACL;AAAA,YACA,QAAQ;AAAA,YACR,QAAQ;AAAA,UACV;AAAA,QACF;AAAA,MACF;AAAA,MACA,MAAM;AAAA,IACR;AAAA,EACF;AACF;",
6
6
  "names": []
7
7
  }
@@ -19,6 +19,7 @@ export interface ReflectionSettings {
19
19
  readonly threshold: number;
20
20
  readonly softness: number;
21
21
  readonly direction: readonly [number, number];
22
+ readonly depth?: number;
22
23
  }
23
24
  export type ReflectionLight = {
24
25
  readonly color: string;
@@ -35,6 +36,7 @@ export interface ReflectionWarp {
35
36
  /** Optional synchronous image processor; scene pixels are never read back. */
36
37
  export declare class ReflectionGpu {
37
38
  private readonly callbacks;
39
+ private readonly fragment;
38
40
  private readonly canvas;
39
41
  private gl;
40
42
  private resources;
@@ -46,7 +48,7 @@ export declare class ReflectionGpu {
46
48
  private lost;
47
49
  private readonly onContextLost;
48
50
  private readonly onContextRestored;
49
- constructor(callbacks?: Readonly<ReflectionGpuCallbacks>);
51
+ constructor(callbacks?: Readonly<ReflectionGpuCallbacks>, fragment?: string);
50
52
  get isContextLost(): boolean;
51
53
  private acquireResources;
52
54
  apply(source: OffscreenCanvas, map: BorrowedTextureRaster, light: ReflectionLight, settings: ReflectionSettings, coordinates: ReflectionCoordinates, warp?: ReflectionWarp): ImageBitmap;
@@ -38,12 +38,14 @@ void main() {
38
38
  }
39
39
  `;
40
40
  class ReflectionGpu {
41
- constructor(callbacks = {}) {
41
+ constructor(callbacks = {}, fragment = fragmentSource) {
42
42
  this.callbacks = callbacks;
43
+ this.fragment = fragment;
43
44
  this.canvas.addEventListener("webglcontextlost", this.onContextLost);
44
45
  this.canvas.addEventListener("webglcontextrestored", this.onContextRestored);
45
46
  }
46
47
  callbacks;
48
+ fragment;
47
49
  canvas = new OffscreenCanvas(1, 1);
48
50
  gl;
49
51
  resources;
@@ -80,7 +82,7 @@ class ReflectionGpu {
80
82
  let fragment;
81
83
  let program = null;
82
84
  try {
83
- fragment = compile(gl, gl.FRAGMENT_SHADER, fragmentSource);
85
+ fragment = compile(gl, gl.FRAGMENT_SHADER, this.fragment);
84
86
  program = gl.createProgram();
85
87
  if (!program) throw new Error("Could not allocate reflection program.");
86
88
  gl.attachShader(program, vertex);
@@ -186,6 +188,7 @@ class ReflectionGpu {
186
188
  placement("warpOrigin", "warpSize", "warpRotation", warp?.map.placement ?? map.placement, warp?.region ?? coordinates.region, warp?.map.width ?? map.width, warp?.map.height ?? map.height);
187
189
  gl.uniform2f(uniform("warpStrength"), (warp?.strength ?? 0) * coordinates.density / source.width, (warp?.strength ?? 0) * coordinates.density / source.height);
188
190
  gl.uniform2f(uniform("direction"), settings.direction[0], settings.direction[1]);
191
+ gl.uniform1f(uniform("depth"), settings.depth ?? 0);
189
192
  gl.uniform1f(uniform("opacity"), settings.opacity);
190
193
  gl.uniform1f(uniform("threshold"), settings.threshold);
191
194
  gl.uniform1f(uniform("softness"), settings.softness);
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/filters/reflection-gpu.ts"],
4
- "sourcesContent": ["import type { BorrowedTextureRaster, TexturePlacement } from '../lib/textures/texture-protocol.js';\n\nexport interface ReflectionCoordinates {\n readonly originX: number;\n readonly originY: number;\n readonly density: number;\n readonly region: Readonly<{ x: number; y: number; width: number; height: number }>;\n}\nexport interface ReflectionGpuCallbacks {\n readonly onContextLost?: () => void;\n readonly onContextRestored?: () => void;\n}\nconst vertexSource = `#version 300 es\nin vec2 p;\nout vec2 uv;\nvoid main() { uv = vec2((p.x + 1.) * .5, 1. - (p.y + 1.) * .5); gl_Position = vec4(p, 0, 1); }\n`;\nexport interface ReflectionSettings {\n readonly opacity: number; readonly threshold: number; readonly softness: number;\n readonly direction: readonly [number, number];\n}\nexport type ReflectionLight = { readonly color: string } | { readonly image: HTMLImageElement | ImageBitmap } | { readonly raster: BorrowedTextureRaster };\nexport interface ReflectionWarp { readonly map: BorrowedTextureRaster; readonly strength: number; readonly region: ReflectionCoordinates['region']; }\nconst fragmentSource = `#version 300 es\nprecision highp float;\nuniform sampler2D scene, map, lightMap, warpMap;\nuniform vec2 logicalOrigin, logicalSize, mapOrigin, tileSize, lightOrigin, lightSize, warpOrigin, warpSize, warpStrength, direction;\nuniform float rotation, lightRotation, warpRotation, opacity, threshold, softness;\nin vec2 uv;\nout vec4 outputColor;\nfloat decode(float c) { float b=c*255.; return (b-128.)/(b<128.?128.:127.); }\nvec2 coordinates(vec2 origin, vec2 size, float angle) {\n vec2 p=logicalOrigin+uv*logicalSize-origin;\n float c=cos(angle),s=sin(angle);\n return vec2(c*p.x+s*p.y,-s*p.x+c*p.y)/size;\n}\nvec4 sourcePixel(ivec2 p) {\n ivec2 size=textureSize(scene,0);\n if(any(lessThan(p,ivec2(0)))||any(greaterThanEqual(p,size))) return vec4(0);\n return texelFetch(scene,p,0);\n}\nvec4 sourceSample(vec2 p) {\n vec2 pixel=p*vec2(textureSize(scene,0))-.5;\n ivec2 base=ivec2(floor(pixel)); vec2 f=fract(pixel);\n return mix(mix(sourcePixel(base),sourcePixel(base+ivec2(1,0)),f.x),mix(sourcePixel(base+ivec2(0,1)),sourcePixel(base+ivec2(1,1)),f.x),f.y);\n}\nvoid main() {\n vec4 warp=texture(warpMap,coordinates(warpOrigin,warpSize,warpRotation));\n vec4 base=sourceSample(uv+vec2(decode(warp.r),decode(warp.g))*warp.a*warpStrength);\n vec4 field=texture(map,coordinates(mapOrigin,tileSize,rotation));\n vec2 slope=vec2(decode(field.r),decode(field.g));\n float coverage=smoothstep(threshold,threshold+softness,dot(slope,direction))*field.a*opacity;\n vec4 light=texture(lightMap,coordinates(lightOrigin,lightSize,lightRotation)+slope*.035);\n float amount=coverage*light.a;\n outputColor=vec4(base.rgb*(1.-amount)+base.a*light.rgb*amount,base.a);\n}\n`;\n\n/** Optional synchronous image processor; scene pixels are never read back. */\nexport class ReflectionGpu {\n private readonly canvas = new OffscreenCanvas(1, 1);\n private gl: WebGL2RenderingContext | undefined;\n private resources: ReflectionResources | undefined;\n private readonly maps = new Map<object, { texture: WebGLTexture; revision: number }>();\n private readonly directKey = {};\n private colorCanvas: OffscreenCanvas | undefined;\n private directRevision = 0;\n private disposed = false;\n private lost = false;\n private readonly onContextLost = (event: Event): void => {\n event.preventDefault();\n if (this.disposed || this.lost) return;\n this.lost = true;\n this.releaseResources(false);\n this.callbacks.onContextLost?.();\n };\n private readonly onContextRestored = (): void => {\n if (this.disposed || !this.lost) return;\n this.lost = false;\n this.callbacks.onContextRestored?.();\n };\n\n constructor(private readonly callbacks: Readonly<ReflectionGpuCallbacks> = {}) {\n this.canvas.addEventListener('webglcontextlost', this.onContextLost);\n this.canvas.addEventListener('webglcontextrestored', this.onContextRestored);\n }\n\n get isContextLost(): boolean {\n return this.lost || this.gl?.isContextLost() === true;\n }\n\n private acquireResources(): ReflectionResources {\n if (this.disposed) throw new Error('Cannot use a disposed reflection processor.');\n if (this.isContextLost) throw new Error('Reflection WebGL2 context was lost.');\n if (this.resources) return this.resources;\n const gl = this.canvas.getContext('webgl2', { premultipliedAlpha: true, preserveDrawingBuffer: false });\n if (!gl) throw new Error('Reflection requires OffscreenCanvas WebGL2 support.');\n if (gl.isContextLost()) throw new Error('Reflection WebGL2 context was lost.');\n this.gl = gl;\n const vertex = compile(gl, gl.VERTEX_SHADER, vertexSource);\n let fragment: WebGLShader | undefined;\n let program: WebGLProgram | null = null;\n try {\n fragment = compile(gl, gl.FRAGMENT_SHADER, fragmentSource);\n program = gl.createProgram();\n if (!program) throw new Error('Could not allocate reflection program.');\n gl.attachShader(program, vertex); gl.attachShader(program, fragment); gl.linkProgram(program);\n if (!gl.getProgramParameter(program, gl.LINK_STATUS)) throw new Error(`Reflection shader link failed: ${gl.getProgramInfoLog(program)}`);\n } catch (error) { if (program) gl.deleteProgram(program); throw error; }\n finally { gl.deleteShader(vertex); if (fragment) gl.deleteShader(fragment); }\n const vao = gl.createVertexArray(), buffer = gl.createBuffer();\n if (!vao || !buffer) { if (vao) gl.deleteVertexArray(vao); if (buffer) gl.deleteBuffer(buffer); gl.deleteProgram(program); throw new Error('Could not allocate reflection geometry.'); }\n gl.bindVertexArray(vao); gl.bindBuffer(gl.ARRAY_BUFFER, buffer);\n gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([-1, -1, 1, -1, -1, 1, 1, 1]), gl.STATIC_DRAW);\n const location = gl.getAttribLocation(program, 'p');\n gl.enableVertexAttribArray(location); gl.vertexAttribPointer(location, 2, gl.FLOAT, false, 0, 0);\n const source = gl.createTexture();\n if (!source) {\n if (source) gl.deleteTexture(source);\n gl.deleteBuffer(buffer); gl.deleteVertexArray(vao); gl.deleteProgram(program);\n throw new Error('Could not allocate reflection textures.');\n }\n const resources: ReflectionResources = { program, vao, buffer, source };\n gl.pixelStorei(gl.UNPACK_COLORSPACE_CONVERSION_WEBGL, gl.NONE);\n this.resources = resources;\n return resources;\n }\n\n apply(source: OffscreenCanvas, map: BorrowedTextureRaster, light: ReflectionLight, settings: ReflectionSettings, coordinates: ReflectionCoordinates, warp?: ReflectionWarp): ImageBitmap {\n const { gl, program, vao, source: sourceTexture } = this.acquireResourcesWithContext();\n const maximum = gl.getParameter(gl.MAX_TEXTURE_SIZE) as number;\n if (Math.max(source.width, source.height, map.width, map.height, warp?.map.width ?? 0, warp?.map.height ?? 0) > maximum) throw new RangeError('Reflection target exceeds WebGL2 maximum texture size.');\n if (this.canvas.width !== source.width) this.canvas.width = source.width;\n if (this.canvas.height !== source.height) this.canvas.height = source.height;\n gl.viewport(0, 0, source.width, source.height); gl.useProgram(program); gl.bindVertexArray(vao);\n this.upload(gl, 0, sourceTexture, source, true, false);\n const uploaded = new Map<object, number>();\n const bind = (unit: number, raster: {source: TexImageSource; width:number; height:number; resource:object; revision:number; placement:Readonly<TexturePlacement>}) => {\n if (Math.max(raster.width,raster.height)>maximum) throw new RangeError('Reflection light exceeds WebGL2 maximum texture size.');\n let cached=this.maps.get(raster.resource);\n if (!cached) {\n const texture=gl.createTexture(); if(!texture) throw new Error('Could not allocate reflection input texture.');\n cached={texture,revision:-1}; this.maps.set(raster.resource,cached);\n }\n this.upload(gl,unit,cached.texture,raster.source,false,raster.placement.mode!=='stretch',cached.revision!==raster.revision && uploaded.get(raster.resource)!==raster.revision);\n uploaded.set(raster.resource,raster.revision);\n };\n bind(1,map); bind(3,warp?.map ?? map);\n let lightPlacement: Readonly<TexturePlacement> = {mode:'stretch'};\n let lightWidth=1,lightHeight=1;\n if ('raster' in light) { bind(2,light.raster); lightPlacement=light.raster.placement; lightWidth=light.raster.width; lightHeight=light.raster.height; }\n else {\n let image: TexImageSource;\n if ('color' in light) {\n const canvas=this.colorCanvas ??= new OffscreenCanvas(1,1);\n const ctx=canvas.getContext('2d'); if(!ctx) throw new Error('Reflection colors require Canvas 2D.');\n ctx.clearRect(0,0,1,1); ctx.fillStyle=light.color; ctx.fillRect(0,0,1,1); image=canvas;\n } else { image=light.image; lightWidth='naturalWidth' in light.image?light.image.naturalWidth:light.image.width; lightHeight='naturalHeight' in light.image?light.image.naturalHeight:light.image.height; }\n bind(2,{source:image,width:lightWidth,height:lightHeight,resource:this.directKey,revision:++this.directRevision,placement:lightPlacement});\n }\n const uniform=(name:string)=>gl.getUniformLocation(program,name);\n const placement=(origin:string,size:string,angle:string,value:Readonly<TexturePlacement>,region:ReflectionCoordinates['region'],width:number,height:number)=>{\n gl.uniform2f(uniform(origin),region.x+(value.offsetX??0),region.y+(value.offsetY??0));\n gl.uniform2f(uniform(size),value.mode==='stretch'?region.width:value.tileWidth??width,value.mode==='stretch'?region.height:value.tileHeight??height);\n gl.uniform1f(uniform(angle),(value.rotation??0)*Math.PI/180);\n };\n gl.uniform1i(uniform('scene'),0); gl.uniform1i(uniform('map'),1); gl.uniform1i(uniform('lightMap'),2); gl.uniform1i(uniform('warpMap'),3);\n gl.uniform2f(uniform('logicalOrigin'),coordinates.originX,coordinates.originY);\n gl.uniform2f(uniform('logicalSize'),source.width/coordinates.density,source.height/coordinates.density);\n placement('mapOrigin','tileSize','rotation',map.placement,coordinates.region,map.width,map.height);\n placement('lightOrigin','lightSize','lightRotation',lightPlacement,coordinates.region,lightWidth,lightHeight);\n placement('warpOrigin','warpSize','warpRotation',warp?.map.placement??map.placement,warp?.region??coordinates.region,warp?.map.width??map.width,warp?.map.height??map.height);\n gl.uniform2f(uniform('warpStrength'),(warp?.strength??0)*coordinates.density/source.width,(warp?.strength??0)*coordinates.density/source.height);\n gl.uniform2f(uniform('direction'),settings.direction[0],settings.direction[1]);\n gl.uniform1f(uniform('opacity'),settings.opacity); gl.uniform1f(uniform('threshold'),settings.threshold); gl.uniform1f(uniform('softness'),settings.softness);\n gl.drawArrays(gl.TRIANGLE_STRIP,0,4);\n if(this.isContextLost) throw new Error('Reflection WebGL2 context was lost.');\n const error=gl.getError(); if(error!==gl.NO_ERROR) throw new Error(`Reflection GPU processing failed (${error}).`);\n for(const [resource,revision] of uploaded) this.maps.get(resource)!.revision=revision;\n return this.canvas.transferToImageBitmap();\n }\n private acquireResourcesWithContext(): ReflectionResources & { gl: WebGL2RenderingContext } {\n const resources = this.acquireResources();\n const gl = this.gl;\n if (!gl || gl.isContextLost()) throw new Error('Reflection WebGL2 context was lost.');\n return { ...resources, gl };\n }\n private upload(gl: WebGL2RenderingContext, unit: number, texture: WebGLTexture, canvas: TexImageSource, premultiply: boolean, repeat: boolean, upload = true): void {\n gl.activeTexture(gl.TEXTURE0 + unit); gl.bindTexture(gl.TEXTURE_2D, texture);\n gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);\n gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);\n gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, repeat ? gl.REPEAT : gl.CLAMP_TO_EDGE);\n gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, repeat ? gl.REPEAT : gl.CLAMP_TO_EDGE);\n gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, premultiply);\n if (upload) gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, canvas);\n }\n retainMaps(resources: ReadonlySet<object>): void {\n const gl = this.gl;\n for (const [resource, cached] of this.maps) {\n if (resource !== this.directKey && !resources.has(resource)) { if (gl && !gl.isContextLost()) gl.deleteTexture(cached.texture); this.maps.delete(resource); }\n }\n }\n private releaseResources(deleteResources: boolean): void {\n const gl = this.gl;\n const resources = this.resources;\n this.resources = undefined;\n if (gl && !gl.isContextLost() && deleteResources) {\n gl.deleteTexture(resources?.source ?? null);\n for (const cached of this.maps.values()) gl.deleteTexture(cached.texture);\n if (resources) { gl.deleteBuffer(resources.buffer); gl.deleteVertexArray(resources.vao); gl.deleteProgram(resources.program); }\n }\n this.maps.clear();\n }\n dispose(): void {\n if (this.disposed) return;\n this.disposed = true;\n this.canvas.removeEventListener('webglcontextlost', this.onContextLost);\n this.canvas.removeEventListener('webglcontextrestored', this.onContextRestored);\n this.releaseResources(true);\n this.canvas.width = 0; this.canvas.height = 0;\n if(this.colorCanvas) this.colorCanvas.width=this.colorCanvas.height=0;\n this.colorCanvas=undefined;\n }\n}\ninterface ReflectionResources {\n readonly program: WebGLProgram;\n readonly vao: WebGLVertexArrayObject;\n readonly buffer: WebGLBuffer;\n readonly source: WebGLTexture;\n}\nfunction compile(gl: WebGL2RenderingContext, kind: number, source: string): WebGLShader {\n const shader = gl.createShader(kind);\n if (!shader) throw new Error('Could not allocate reflection shader.');\n gl.shaderSource(shader, source); gl.compileShader(shader);\n if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {\n const error = gl.getShaderInfoLog(shader); gl.deleteShader(shader);\n throw new Error(`Reflection shader compile failed: ${error}`);\n }\n return shader;\n}\n"],
5
- "mappings": "AAYA,MAAM,eAAe;AAAA;AAAA;AAAA;AAAA;AAWrB,MAAM,iBAAiB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAoChB,MAAM,cAAc;AAAA,EAuBzB,YAA6B,YAA8C,CAAC,GAAG;AAAlD;AAC3B,SAAK,OAAO,iBAAiB,oBAAoB,KAAK,aAAa;AACnE,SAAK,OAAO,iBAAiB,wBAAwB,KAAK,iBAAiB;AAAA,EAC7E;AAAA,EAH6B;AAAA,EAtBZ,SAAS,IAAI,gBAAgB,GAAG,CAAC;AAAA,EAC1C;AAAA,EACA;AAAA,EACS,OAAO,oBA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MAAM,CAAC,GAAG,cAAc,KAAK,iBAAiB;AAChD,SAAG,cAAc,WAAW,UAAU,IAAI;AAC1C,iBAAW,UAAU,KAAK,KAAK,OAAO,EAAG,IAAG,cAAc,OAAO,OAAO;AACxE,UAAI,WAAW;AAAE,WAAG,aAAa,UAAU,MAAM;AAAG,WAAG,kBAAkB,UAAU,GAAG;AAAG,WAAG,cAAc,UAAU,OAAO;AAAA,MAAG;AAAA,IAChI;AACA,SAAK,KAAK,MAAM;AAAA,EAClB;AAAA,EACA,UAAgB;AACd,QAAI,KAAK,SAAU;AACnB,SAAK,WAAW;AAChB,SAAK,OAAO,oBAAoB,oBAAoB,KAAK,aAAa;AACtE,SAAK,OAAO,oBAAoB,wBAAwB,KAAK,iBAAiB;AAC9E,SAAK,iBAAiB,IAAI;AAC1B,SAAK,OAAO,QAAQ;AAAG,SAAK,OAAO,SAAS;AAC5C,QAAG,KAAK,YAAa,MAAK,YAAY,QAAM,KAAK,YAAY,SAAO;AACpE,SAAK,cAAY;AAAA,EACnB;AACF;AAOA,SAAS,QAAQ,IAA4B,MAAc,QAA6B;AACtF,QAAM,SAAS,GAAG,aAAa,IAAI;AACnC,MAAI,CAAC,OAAQ,OAAM,IAAI,MAAM,uCAAuC;AACpE,KAAG,aAAa,QAAQ,MAAM;AAAG,KAAG,cAAc,MAAM;AACxD,MAAI,CAAC,GAAG,mBAAmB,QAAQ,GAAG,cAAc,GAAG;AACrD,UAAM,QAAQ,GAAG,iBAAiB,MAAM;AAAG,OAAG,aAAa,MAAM;AACjE,UAAM,IAAI,MAAM,qCAAqC,KAAK,EAAE;AAAA,EAC9D;AACA,SAAO;AACT;",
4
+ "sourcesContent": ["import type { BorrowedTextureRaster, TexturePlacement } from '../lib/textures/texture-protocol.js';\n\nexport interface ReflectionCoordinates {\n readonly originX: number;\n readonly originY: number;\n readonly density: number;\n readonly region: Readonly<{ x: number; y: number; width: number; height: number }>;\n}\nexport interface ReflectionGpuCallbacks {\n readonly onContextLost?: () => void;\n readonly onContextRestored?: () => void;\n}\nconst vertexSource = `#version 300 es\nin vec2 p;\nout vec2 uv;\nvoid main() { uv = vec2((p.x + 1.) * .5, 1. - (p.y + 1.) * .5); gl_Position = vec4(p, 0, 1); }\n`;\nexport interface ReflectionSettings {\n readonly opacity: number; readonly threshold: number; readonly softness: number;\n readonly direction: readonly [number, number];\n readonly depth?: number;\n}\nexport type ReflectionLight = { readonly color: string } | { readonly image: HTMLImageElement | ImageBitmap } | { readonly raster: BorrowedTextureRaster };\nexport interface ReflectionWarp { readonly map: BorrowedTextureRaster; readonly strength: number; readonly region: ReflectionCoordinates['region']; }\nconst fragmentSource = `#version 300 es\nprecision highp float;\nuniform sampler2D scene, map, lightMap, warpMap;\nuniform vec2 logicalOrigin, logicalSize, mapOrigin, tileSize, lightOrigin, lightSize, warpOrigin, warpSize, warpStrength, direction;\nuniform float rotation, lightRotation, warpRotation, opacity, threshold, softness;\nin vec2 uv;\nout vec4 outputColor;\nfloat decode(float c) { float b=c*255.; return (b-128.)/(b<128.?128.:127.); }\nvec2 coordinates(vec2 origin, vec2 size, float angle) {\n vec2 p=logicalOrigin+uv*logicalSize-origin;\n float c=cos(angle),s=sin(angle);\n return vec2(c*p.x+s*p.y,-s*p.x+c*p.y)/size;\n}\nvec4 sourcePixel(ivec2 p) {\n ivec2 size=textureSize(scene,0);\n if(any(lessThan(p,ivec2(0)))||any(greaterThanEqual(p,size))) return vec4(0);\n return texelFetch(scene,p,0);\n}\nvec4 sourceSample(vec2 p) {\n vec2 pixel=p*vec2(textureSize(scene,0))-.5;\n ivec2 base=ivec2(floor(pixel)); vec2 f=fract(pixel);\n return mix(mix(sourcePixel(base),sourcePixel(base+ivec2(1,0)),f.x),mix(sourcePixel(base+ivec2(0,1)),sourcePixel(base+ivec2(1,1)),f.x),f.y);\n}\nvoid main() {\n vec4 warp=texture(warpMap,coordinates(warpOrigin,warpSize,warpRotation));\n vec4 base=sourceSample(uv+vec2(decode(warp.r),decode(warp.g))*warp.a*warpStrength);\n vec4 field=texture(map,coordinates(mapOrigin,tileSize,rotation));\n vec2 slope=vec2(decode(field.r),decode(field.g));\n float coverage=smoothstep(threshold,threshold+softness,dot(slope,direction))*field.a*opacity;\n vec4 light=texture(lightMap,coordinates(lightOrigin,lightSize,lightRotation)+slope*.035);\n float amount=coverage*light.a;\n outputColor=vec4(base.rgb*(1.-amount)+base.a*light.rgb*amount,base.a);\n}\n`;\n\n/** Optional synchronous image processor; scene pixels are never read back. */\nexport class ReflectionGpu {\n private readonly canvas = new OffscreenCanvas(1, 1);\n private gl: WebGL2RenderingContext | undefined;\n private resources: ReflectionResources | undefined;\n private readonly maps = new Map<object, { texture: WebGLTexture; revision: number }>();\n private readonly directKey = {};\n private colorCanvas: OffscreenCanvas | undefined;\n private directRevision = 0;\n private disposed = false;\n private lost = false;\n private readonly onContextLost = (event: Event): void => {\n event.preventDefault();\n if (this.disposed || this.lost) return;\n this.lost = true;\n this.releaseResources(false);\n this.callbacks.onContextLost?.();\n };\n private readonly onContextRestored = (): void => {\n if (this.disposed || !this.lost) return;\n this.lost = false;\n this.callbacks.onContextRestored?.();\n };\n\n constructor(private readonly callbacks: Readonly<ReflectionGpuCallbacks> = {}, private readonly fragment = fragmentSource) {\n this.canvas.addEventListener('webglcontextlost', this.onContextLost);\n this.canvas.addEventListener('webglcontextrestored', this.onContextRestored);\n }\n\n get isContextLost(): boolean {\n return this.lost || this.gl?.isContextLost() === true;\n }\n\n private acquireResources(): ReflectionResources {\n if (this.disposed) throw new Error('Cannot use a disposed reflection processor.');\n if (this.isContextLost) throw new Error('Reflection WebGL2 context was lost.');\n if (this.resources) return this.resources;\n const gl = this.canvas.getContext('webgl2', { premultipliedAlpha: true, preserveDrawingBuffer: false });\n if (!gl) throw new Error('Reflection requires OffscreenCanvas WebGL2 support.');\n if (gl.isContextLost()) throw new Error('Reflection WebGL2 context was lost.');\n this.gl = gl;\n const vertex = compile(gl, gl.VERTEX_SHADER, vertexSource);\n let fragment: WebGLShader | undefined;\n let program: WebGLProgram | null = null;\n try {\n fragment = compile(gl, gl.FRAGMENT_SHADER, this.fragment);\n program = gl.createProgram();\n if (!program) throw new Error('Could not allocate reflection program.');\n gl.attachShader(program, vertex); gl.attachShader(program, fragment); gl.linkProgram(program);\n if (!gl.getProgramParameter(program, gl.LINK_STATUS)) throw new Error(`Reflection shader link failed: ${gl.getProgramInfoLog(program)}`);\n } catch (error) { if (program) gl.deleteProgram(program); throw error; }\n finally { gl.deleteShader(vertex); if (fragment) gl.deleteShader(fragment); }\n const vao = gl.createVertexArray(), buffer = gl.createBuffer();\n if (!vao || !buffer) { if (vao) gl.deleteVertexArray(vao); if (buffer) gl.deleteBuffer(buffer); gl.deleteProgram(program); throw new Error('Could not allocate reflection geometry.'); }\n gl.bindVertexArray(vao); gl.bindBuffer(gl.ARRAY_BUFFER, buffer);\n gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([-1, -1, 1, -1, -1, 1, 1, 1]), gl.STATIC_DRAW);\n const location = gl.getAttribLocation(program, 'p');\n gl.enableVertexAttribArray(location); gl.vertexAttribPointer(location, 2, gl.FLOAT, false, 0, 0);\n const source = gl.createTexture();\n if (!source) {\n if (source) gl.deleteTexture(source);\n gl.deleteBuffer(buffer); gl.deleteVertexArray(vao); gl.deleteProgram(program);\n throw new Error('Could not allocate reflection textures.');\n }\n const resources: ReflectionResources = { program, vao, buffer, source };\n gl.pixelStorei(gl.UNPACK_COLORSPACE_CONVERSION_WEBGL, gl.NONE);\n this.resources = resources;\n return resources;\n }\n\n apply(source: OffscreenCanvas, map: BorrowedTextureRaster, light: ReflectionLight, settings: ReflectionSettings, coordinates: ReflectionCoordinates, warp?: ReflectionWarp): ImageBitmap {\n const { gl, program, vao, source: sourceTexture } = this.acquireResourcesWithContext();\n const maximum = gl.getParameter(gl.MAX_TEXTURE_SIZE) as number;\n if (Math.max(source.width, source.height, map.width, map.height, warp?.map.width ?? 0, warp?.map.height ?? 0) > maximum) throw new RangeError('Reflection target exceeds WebGL2 maximum texture size.');\n if (this.canvas.width !== source.width) this.canvas.width = source.width;\n if (this.canvas.height !== source.height) this.canvas.height = source.height;\n gl.viewport(0, 0, source.width, source.height); gl.useProgram(program); gl.bindVertexArray(vao);\n this.upload(gl, 0, sourceTexture, source, true, false);\n const uploaded = new Map<object, number>();\n const bind = (unit: number, raster: {source: TexImageSource; width:number; height:number; resource:object; revision:number; placement:Readonly<TexturePlacement>}) => {\n if (Math.max(raster.width,raster.height)>maximum) throw new RangeError('Reflection light exceeds WebGL2 maximum texture size.');\n let cached=this.maps.get(raster.resource);\n if (!cached) {\n const texture=gl.createTexture(); if(!texture) throw new Error('Could not allocate reflection input texture.');\n cached={texture,revision:-1}; this.maps.set(raster.resource,cached);\n }\n this.upload(gl,unit,cached.texture,raster.source,false,raster.placement.mode!=='stretch',cached.revision!==raster.revision && uploaded.get(raster.resource)!==raster.revision);\n uploaded.set(raster.resource,raster.revision);\n };\n bind(1,map); bind(3,warp?.map ?? map);\n let lightPlacement: Readonly<TexturePlacement> = {mode:'stretch'};\n let lightWidth=1,lightHeight=1;\n if ('raster' in light) { bind(2,light.raster); lightPlacement=light.raster.placement; lightWidth=light.raster.width; lightHeight=light.raster.height; }\n else {\n let image: TexImageSource;\n if ('color' in light) {\n const canvas=this.colorCanvas ??= new OffscreenCanvas(1,1);\n const ctx=canvas.getContext('2d'); if(!ctx) throw new Error('Reflection colors require Canvas 2D.');\n ctx.clearRect(0,0,1,1); ctx.fillStyle=light.color; ctx.fillRect(0,0,1,1); image=canvas;\n } else { image=light.image; lightWidth='naturalWidth' in light.image?light.image.naturalWidth:light.image.width; lightHeight='naturalHeight' in light.image?light.image.naturalHeight:light.image.height; }\n bind(2,{source:image,width:lightWidth,height:lightHeight,resource:this.directKey,revision:++this.directRevision,placement:lightPlacement});\n }\n const uniform=(name:string)=>gl.getUniformLocation(program,name);\n const placement=(origin:string,size:string,angle:string,value:Readonly<TexturePlacement>,region:ReflectionCoordinates['region'],width:number,height:number)=>{\n gl.uniform2f(uniform(origin),region.x+(value.offsetX??0),region.y+(value.offsetY??0));\n gl.uniform2f(uniform(size),value.mode==='stretch'?region.width:value.tileWidth??width,value.mode==='stretch'?region.height:value.tileHeight??height);\n gl.uniform1f(uniform(angle),(value.rotation??0)*Math.PI/180);\n };\n gl.uniform1i(uniform('scene'),0); gl.uniform1i(uniform('map'),1); gl.uniform1i(uniform('lightMap'),2); gl.uniform1i(uniform('warpMap'),3);\n gl.uniform2f(uniform('logicalOrigin'),coordinates.originX,coordinates.originY);\n gl.uniform2f(uniform('logicalSize'),source.width/coordinates.density,source.height/coordinates.density);\n placement('mapOrigin','tileSize','rotation',map.placement,coordinates.region,map.width,map.height);\n placement('lightOrigin','lightSize','lightRotation',lightPlacement,coordinates.region,lightWidth,lightHeight);\n placement('warpOrigin','warpSize','warpRotation',warp?.map.placement??map.placement,warp?.region??coordinates.region,warp?.map.width??map.width,warp?.map.height??map.height);\n gl.uniform2f(uniform('warpStrength'),(warp?.strength??0)*coordinates.density/source.width,(warp?.strength??0)*coordinates.density/source.height);\n gl.uniform2f(uniform('direction'),settings.direction[0],settings.direction[1]);\n gl.uniform1f(uniform('depth'),settings.depth ?? 0);\n gl.uniform1f(uniform('opacity'),settings.opacity); gl.uniform1f(uniform('threshold'),settings.threshold); gl.uniform1f(uniform('softness'),settings.softness);\n gl.drawArrays(gl.TRIANGLE_STRIP,0,4);\n if(this.isContextLost) throw new Error('Reflection WebGL2 context was lost.');\n const error=gl.getError(); if(error!==gl.NO_ERROR) throw new Error(`Reflection GPU processing failed (${error}).`);\n for(const [resource,revision] of uploaded) this.maps.get(resource)!.revision=revision;\n return this.canvas.transferToImageBitmap();\n }\n private acquireResourcesWithContext(): ReflectionResources & { gl: WebGL2RenderingContext } {\n const resources = this.acquireResources();\n const gl = this.gl;\n if (!gl || gl.isContextLost()) throw new Error('Reflection WebGL2 context was lost.');\n return { ...resources, gl };\n }\n private upload(gl: WebGL2RenderingContext, unit: number, texture: WebGLTexture, canvas: TexImageSource, premultiply: boolean, repeat: boolean, upload = true): void {\n gl.activeTexture(gl.TEXTURE0 + unit); gl.bindTexture(gl.TEXTURE_2D, texture);\n gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);\n gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);\n gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, repeat ? gl.REPEAT : gl.CLAMP_TO_EDGE);\n gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, repeat ? gl.REPEAT : gl.CLAMP_TO_EDGE);\n gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, premultiply);\n if (upload) gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, canvas);\n }\n retainMaps(resources: ReadonlySet<object>): void {\n const gl = this.gl;\n for (const [resource, cached] of this.maps) {\n if (resource !== this.directKey && !resources.has(resource)) { if (gl && !gl.isContextLost()) gl.deleteTexture(cached.texture); this.maps.delete(resource); }\n }\n }\n private releaseResources(deleteResources: boolean): void {\n const gl = this.gl;\n const resources = this.resources;\n this.resources = undefined;\n if (gl && !gl.isContextLost() && deleteResources) {\n gl.deleteTexture(resources?.source ?? null);\n for (const cached of this.maps.values()) gl.deleteTexture(cached.texture);\n if (resources) { gl.deleteBuffer(resources.buffer); gl.deleteVertexArray(resources.vao); gl.deleteProgram(resources.program); }\n }\n this.maps.clear();\n }\n dispose(): void {\n if (this.disposed) return;\n this.disposed = true;\n this.canvas.removeEventListener('webglcontextlost', this.onContextLost);\n this.canvas.removeEventListener('webglcontextrestored', this.onContextRestored);\n this.releaseResources(true);\n this.canvas.width = 0; this.canvas.height = 0;\n if(this.colorCanvas) this.colorCanvas.width=this.colorCanvas.height=0;\n this.colorCanvas=undefined;\n }\n}\ninterface ReflectionResources {\n readonly program: WebGLProgram;\n readonly vao: WebGLVertexArrayObject;\n readonly buffer: WebGLBuffer;\n readonly source: WebGLTexture;\n}\nfunction compile(gl: WebGL2RenderingContext, kind: number, source: string): WebGLShader {\n const shader = gl.createShader(kind);\n if (!shader) throw new Error('Could not allocate reflection shader.');\n gl.shaderSource(shader, source); gl.compileShader(shader);\n if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {\n const error = gl.getShaderInfoLog(shader); gl.deleteShader(shader);\n throw new Error(`Reflection shader compile failed: ${error}`);\n }\n return shader;\n}\n"],
5
+ "mappings": "AAYA,MAAM,eAAe;AAAA;AAAA;AAAA;AAAA;AAYrB,MAAM,iBAAiB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAoChB,MAAM,cAAc;AAAA,EAuBzB,YAA6B,YAA8C,CAAC,GAAoB,WAAW,gBAAgB;AAA9F;AAAmE;AAC9F,SAAK,OAAO,iBAAiB,oBAAoB,KAAK,aAAa;AACnE,SAAK,OAAO,iBAAiB,wBAAwB,KAAK,iBAAiB;AAAA,EAC7E;AAAA,EAH6B;AAAA,EAAmE;AAAA,EAtB/E,SAAS,IAAI,gBAAgB,GAAG,CAAC;AAAA,EAC1C;AAAA,EACA;AAAA,EACS,OAAO,oBAAI,IAAyD;AAAA,EACpE,YAAY,CAAC;AAAA,EACtB;AAAA,EACA,iBAAiB;AAAA,EACjB,WAAW;AAAA,EACX,OAAO;AAAA,EACE,gBAAgB,CAAC,UAAuB;AACvD,UAAM,eAAe;AACrB,QAAI,KAAK,YAAY,KAAK,KAAM;AAChC,SAAK,OAAO;AACZ,SAAK,iBAAiB,KAAK;AAC3B,SAAK,UAAU,gBAAgB;AAAA,EACjC;AAAA,EACiB,oBAAoB,MAAY;AAC/C,QAAI,KAAK,YAAY,CAAC,KAAK,K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