fabric 7.3.1 → 7.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (314) hide show
  1. package/CHANGELOG.md +40 -27
  2. package/dist/_virtual/{_@oxc-project_runtime@0.122.0 → _@oxc-project_runtime@0.126.0}/helpers/defineProperty.mjs +1 -1
  3. package/{dist-extensions/_virtual/_@oxc-project_runtime@0.122.0 → dist/_virtual/_@oxc-project_runtime@0.126.0}/helpers/toPrimitive.mjs +1 -1
  4. package/dist/_virtual/{_@oxc-project_runtime@0.122.0 → _@oxc-project_runtime@0.126.0}/helpers/toPropertyKey.mjs +1 -1
  5. package/{dist-extensions/_virtual/_@oxc-project_runtime@0.122.0 → dist/_virtual/_@oxc-project_runtime@0.126.0}/helpers/typeof.mjs +1 -1
  6. package/dist/index.js +88 -66
  7. package/dist/index.js.map +1 -1
  8. package/dist/index.min.js +35 -35
  9. package/dist/index.min.js.map +1 -1
  10. package/dist/index.min.mjs +37 -37
  11. package/dist/index.min.mjs.map +1 -1
  12. package/dist/index.mjs +88 -66
  13. package/dist/index.mjs.map +1 -1
  14. package/dist/index.node.cjs +83 -62
  15. package/dist/index.node.cjs.map +1 -1
  16. package/dist/index.node.mjs +83 -62
  17. package/dist/index.node.mjs.map +1 -1
  18. package/dist/package.min.mjs +1 -1
  19. package/dist/package.mjs +1 -1
  20. package/dist/src/Collection.min.mjs +1 -1
  21. package/dist/src/Collection.mjs +1 -1
  22. package/dist/src/LayoutManager/LayoutManager.min.mjs +1 -1
  23. package/dist/src/LayoutManager/LayoutManager.mjs +1 -1
  24. package/dist/src/LayoutManager/LayoutStrategies/ClipPathLayout.min.mjs +1 -1
  25. package/dist/src/LayoutManager/LayoutStrategies/ClipPathLayout.mjs +1 -1
  26. package/dist/src/LayoutManager/LayoutStrategies/FitContentLayout.min.mjs +1 -1
  27. package/dist/src/LayoutManager/LayoutStrategies/FitContentLayout.mjs +1 -1
  28. package/dist/src/LayoutManager/LayoutStrategies/FixedLayout.min.mjs +1 -1
  29. package/dist/src/LayoutManager/LayoutStrategies/FixedLayout.mjs +1 -1
  30. package/dist/src/LayoutManager/LayoutStrategies/LayoutStrategy.min.mjs +1 -1
  31. package/dist/src/LayoutManager/LayoutStrategies/LayoutStrategy.mjs +1 -1
  32. package/dist/src/Observable.min.mjs +1 -1
  33. package/dist/src/Observable.mjs +1 -1
  34. package/dist/src/Pattern/Pattern.min.mjs +1 -1
  35. package/dist/src/Pattern/Pattern.mjs +1 -1
  36. package/dist/src/Shadow.min.mjs +1 -1
  37. package/dist/src/Shadow.mjs +1 -1
  38. package/dist/src/brushes/BaseBrush.min.mjs +1 -1
  39. package/dist/src/brushes/BaseBrush.mjs +1 -1
  40. package/dist/src/brushes/CircleBrush.min.mjs +1 -1
  41. package/dist/src/brushes/CircleBrush.mjs +1 -1
  42. package/dist/src/brushes/PencilBrush.min.mjs +1 -1
  43. package/dist/src/brushes/PencilBrush.mjs +1 -1
  44. package/dist/src/brushes/SprayBrush.min.mjs +1 -1
  45. package/dist/src/brushes/SprayBrush.mjs +1 -1
  46. package/dist/src/cache.min.mjs +1 -1
  47. package/dist/src/cache.mjs +1 -1
  48. package/dist/src/canvas/Canvas.min.mjs +1 -1
  49. package/dist/src/canvas/Canvas.mjs +1 -1
  50. package/dist/src/canvas/DOMManagers/CanvasDOMManager.min.mjs +1 -1
  51. package/dist/src/canvas/DOMManagers/CanvasDOMManager.mjs +1 -1
  52. package/dist/src/canvas/DOMManagers/StaticCanvasDOMManager.min.mjs +1 -1
  53. package/dist/src/canvas/DOMManagers/StaticCanvasDOMManager.mjs +1 -1
  54. package/dist/src/canvas/SelectableCanvas.min.mjs +1 -1
  55. package/dist/src/canvas/SelectableCanvas.mjs +1 -1
  56. package/dist/src/canvas/StaticCanvas.d.ts +1 -1
  57. package/dist/src/canvas/StaticCanvas.d.ts.map +1 -1
  58. package/dist/src/canvas/StaticCanvas.min.mjs +5 -5
  59. package/dist/src/canvas/StaticCanvas.min.mjs.map +1 -1
  60. package/dist/src/canvas/StaticCanvas.mjs +4 -4
  61. package/dist/src/canvas/StaticCanvas.mjs.map +1 -1
  62. package/dist/src/canvas/TextEditingManager.min.mjs +1 -1
  63. package/dist/src/canvas/TextEditingManager.mjs +1 -1
  64. package/dist/src/color/Color.min.mjs +1 -1
  65. package/dist/src/color/Color.mjs +1 -1
  66. package/dist/src/config.min.mjs +1 -1
  67. package/dist/src/config.mjs +1 -1
  68. package/dist/src/controls/Control.min.mjs +1 -1
  69. package/dist/src/controls/Control.mjs +1 -1
  70. package/dist/src/filters/BaseFilter.min.mjs +1 -1
  71. package/dist/src/filters/BaseFilter.mjs +1 -1
  72. package/dist/src/filters/BlendColor.min.mjs +1 -1
  73. package/dist/src/filters/BlendColor.mjs +1 -1
  74. package/dist/src/filters/BlendImage.min.mjs +1 -1
  75. package/dist/src/filters/BlendImage.mjs +1 -1
  76. package/dist/src/filters/Blur.min.mjs +1 -1
  77. package/dist/src/filters/Blur.mjs +1 -1
  78. package/dist/src/filters/Brightness.min.mjs +1 -1
  79. package/dist/src/filters/Brightness.mjs +1 -1
  80. package/dist/src/filters/Canvas2dFilterBackend.min.mjs +1 -1
  81. package/dist/src/filters/Canvas2dFilterBackend.mjs +1 -1
  82. package/dist/src/filters/ColorMatrix.min.mjs +1 -1
  83. package/dist/src/filters/ColorMatrix.mjs +1 -1
  84. package/dist/src/filters/ColorMatrixFilters.min.mjs +1 -1
  85. package/dist/src/filters/ColorMatrixFilters.mjs +1 -1
  86. package/dist/src/filters/Composed.min.mjs +1 -1
  87. package/dist/src/filters/Composed.mjs +1 -1
  88. package/dist/src/filters/Contrast.min.mjs +1 -1
  89. package/dist/src/filters/Contrast.mjs +1 -1
  90. package/dist/src/filters/Convolute.min.mjs +1 -1
  91. package/dist/src/filters/Convolute.min.mjs.map +1 -1
  92. package/dist/src/filters/Convolute.mjs +1 -1
  93. package/dist/src/filters/Gamma.min.mjs +1 -1
  94. package/dist/src/filters/Gamma.mjs +1 -1
  95. package/dist/src/filters/Grayscale.min.mjs +1 -1
  96. package/dist/src/filters/Grayscale.mjs +1 -1
  97. package/dist/src/filters/HueRotation.min.mjs +1 -1
  98. package/dist/src/filters/HueRotation.mjs +1 -1
  99. package/dist/src/filters/Invert.min.mjs +1 -1
  100. package/dist/src/filters/Invert.mjs +1 -1
  101. package/dist/src/filters/Noise.min.mjs +1 -1
  102. package/dist/src/filters/Noise.mjs +1 -1
  103. package/dist/src/filters/Pixelate.min.mjs +1 -1
  104. package/dist/src/filters/Pixelate.mjs +1 -1
  105. package/dist/src/filters/RemoveColor.min.mjs +1 -1
  106. package/dist/src/filters/RemoveColor.mjs +1 -1
  107. package/dist/src/filters/Resize.min.mjs +2 -2
  108. package/dist/src/filters/Resize.min.mjs.map +1 -1
  109. package/dist/src/filters/Resize.mjs +2 -2
  110. package/dist/src/filters/Resize.mjs.map +1 -1
  111. package/dist/src/filters/Saturation.min.mjs +1 -1
  112. package/dist/src/filters/Saturation.mjs +1 -1
  113. package/dist/src/filters/Vibrance.min.mjs +1 -1
  114. package/dist/src/filters/Vibrance.mjs +1 -1
  115. package/dist/src/filters/WebGLFilterBackend.min.mjs +1 -1
  116. package/dist/src/filters/WebGLFilterBackend.mjs +1 -1
  117. package/dist/src/gradient/Gradient.d.ts.map +1 -1
  118. package/dist/src/gradient/Gradient.min.mjs +4 -4
  119. package/dist/src/gradient/Gradient.min.mjs.map +1 -1
  120. package/dist/src/gradient/Gradient.mjs +6 -2
  121. package/dist/src/gradient/Gradient.mjs.map +1 -1
  122. package/dist/src/gradient/typedefs.d.ts +7 -7
  123. package/dist/src/parser/applyViewboxTransform.d.ts.map +1 -1
  124. package/dist/src/parser/applyViewboxTransform.min.mjs +1 -1
  125. package/dist/src/parser/applyViewboxTransform.min.mjs.map +1 -1
  126. package/dist/src/parser/applyViewboxTransform.mjs +2 -4
  127. package/dist/src/parser/applyViewboxTransform.mjs.map +1 -1
  128. package/dist/src/shapes/ActiveSelection.min.mjs +1 -1
  129. package/dist/src/shapes/ActiveSelection.mjs +1 -1
  130. package/dist/src/shapes/Circle.min.mjs +2 -2
  131. package/dist/src/shapes/Circle.min.mjs.map +1 -1
  132. package/dist/src/shapes/Circle.mjs +1 -1
  133. package/dist/src/shapes/Ellipse.min.mjs +1 -1
  134. package/dist/src/shapes/Ellipse.mjs +1 -1
  135. package/dist/src/shapes/Group.min.mjs +1 -1
  136. package/dist/src/shapes/Group.mjs +1 -1
  137. package/dist/src/shapes/IText/DraggableTextDelegate.min.mjs +1 -1
  138. package/dist/src/shapes/IText/DraggableTextDelegate.mjs +1 -1
  139. package/dist/src/shapes/IText/IText.d.ts.map +1 -1
  140. package/dist/src/shapes/IText/IText.min.mjs +1 -1
  141. package/dist/src/shapes/IText/IText.min.mjs.map +1 -1
  142. package/dist/src/shapes/IText/IText.mjs +3 -3
  143. package/dist/src/shapes/IText/IText.mjs.map +1 -1
  144. package/dist/src/shapes/IText/ITextBehavior.min.mjs +1 -1
  145. package/dist/src/shapes/IText/ITextBehavior.mjs +1 -1
  146. package/dist/src/shapes/IText/ITextClickBehavior.min.mjs +1 -1
  147. package/dist/src/shapes/IText/ITextClickBehavior.mjs +1 -1
  148. package/dist/src/shapes/Image.min.mjs +1 -1
  149. package/dist/src/shapes/Image.mjs +1 -1
  150. package/dist/src/shapes/Line.min.mjs +1 -1
  151. package/dist/src/shapes/Line.mjs +1 -1
  152. package/dist/src/shapes/Object/FabricObjectSVGExportMixin.d.ts.map +1 -1
  153. package/dist/src/shapes/Object/FabricObjectSVGExportMixin.min.mjs +2 -2
  154. package/dist/src/shapes/Object/FabricObjectSVGExportMixin.min.mjs.map +1 -1
  155. package/dist/src/shapes/Object/FabricObjectSVGExportMixin.mjs +11 -26
  156. package/dist/src/shapes/Object/FabricObjectSVGExportMixin.mjs.map +1 -1
  157. package/dist/src/shapes/Object/InteractiveObject.d.ts.map +1 -1
  158. package/dist/src/shapes/Object/InteractiveObject.min.mjs +1 -1
  159. package/dist/src/shapes/Object/InteractiveObject.min.mjs.map +1 -1
  160. package/dist/src/shapes/Object/InteractiveObject.mjs +7 -6
  161. package/dist/src/shapes/Object/InteractiveObject.mjs.map +1 -1
  162. package/dist/src/shapes/Object/Object.min.mjs +1 -1
  163. package/dist/src/shapes/Object/Object.mjs +1 -1
  164. package/dist/src/shapes/Object/ObjectGeometry.d.ts.map +1 -1
  165. package/dist/src/shapes/Object/ObjectGeometry.min.mjs +1 -1
  166. package/dist/src/shapes/Object/ObjectGeometry.min.mjs.map +1 -1
  167. package/dist/src/shapes/Object/ObjectGeometry.mjs +6 -2
  168. package/dist/src/shapes/Object/ObjectGeometry.mjs.map +1 -1
  169. package/dist/src/shapes/Object/types/FabricObjectProps.d.ts +1 -1
  170. package/dist/src/shapes/Path.min.mjs +1 -1
  171. package/dist/src/shapes/Path.mjs +1 -1
  172. package/dist/src/shapes/Polygon.min.mjs +1 -1
  173. package/dist/src/shapes/Polygon.mjs +1 -1
  174. package/dist/src/shapes/Polyline.min.mjs +1 -1
  175. package/dist/src/shapes/Polyline.mjs +1 -1
  176. package/dist/src/shapes/Rect.min.mjs +1 -1
  177. package/dist/src/shapes/Rect.mjs +1 -1
  178. package/dist/src/shapes/Text/StyledText.min.mjs +1 -1
  179. package/dist/src/shapes/Text/StyledText.mjs +1 -1
  180. package/dist/src/shapes/Text/Text.d.ts +4 -4
  181. package/dist/src/shapes/Text/Text.min.mjs +1 -1
  182. package/dist/src/shapes/Text/Text.min.mjs.map +1 -1
  183. package/dist/src/shapes/Text/Text.mjs +3 -3
  184. package/dist/src/shapes/Text/Text.mjs.map +1 -1
  185. package/dist/src/shapes/Text/TextSVGExportMixin.d.ts.map +1 -1
  186. package/dist/src/shapes/Text/TextSVGExportMixin.min.mjs +2 -2
  187. package/dist/src/shapes/Text/TextSVGExportMixin.min.mjs.map +1 -1
  188. package/dist/src/shapes/Text/TextSVGExportMixin.mjs +14 -7
  189. package/dist/src/shapes/Text/TextSVGExportMixin.mjs.map +1 -1
  190. package/dist/src/shapes/Textbox.d.ts.map +1 -1
  191. package/dist/src/shapes/Textbox.min.mjs +2 -2
  192. package/dist/src/shapes/Textbox.min.mjs.map +1 -1
  193. package/dist/src/shapes/Textbox.mjs +2 -3
  194. package/dist/src/shapes/Textbox.mjs.map +1 -1
  195. package/dist/src/shapes/Triangle.min.mjs +1 -1
  196. package/dist/src/shapes/Triangle.mjs +1 -1
  197. package/dist/src/util/animation/AnimationBase.min.mjs +1 -1
  198. package/dist/src/util/animation/AnimationBase.mjs +1 -1
  199. package/dist/src/util/animation/easing.min.mjs +1 -1
  200. package/dist/src/util/animation/easing.min.mjs.map +1 -1
  201. package/dist/src/util/animation/easing.mjs +1 -1
  202. package/dist/src/util/animation/easing.mjs.map +1 -1
  203. package/dist/src/util/internals/applyCanvasTransform.d.ts +1 -1
  204. package/dist/src/util/internals/applyCanvasTransform.min.mjs.map +1 -1
  205. package/dist/src/util/internals/applyCanvasTransform.mjs +1 -1
  206. package/dist/src/util/internals/applyCanvasTransform.mjs.map +1 -1
  207. package/dist/src/util/internals/svgExportCheck.d.ts +4 -0
  208. package/dist/src/util/internals/svgExportCheck.d.ts.map +1 -0
  209. package/dist/src/util/internals/svgExportCheck.min.mjs +2 -0
  210. package/dist/src/util/internals/svgExportCheck.min.mjs.map +1 -0
  211. package/dist/src/util/internals/svgExportCheck.mjs +12 -0
  212. package/dist/src/util/internals/svgExportCheck.mjs.map +1 -0
  213. package/dist/src/util/misc/matrix.d.ts +14 -0
  214. package/dist/src/util/misc/matrix.d.ts.map +1 -1
  215. package/dist/src/util/misc/matrix.min.mjs +1 -1
  216. package/dist/src/util/misc/matrix.min.mjs.map +1 -1
  217. package/dist/src/util/misc/matrix.mjs +15 -1
  218. package/dist/src/util/misc/matrix.mjs.map +1 -1
  219. package/dist/src/util/misc/mergeClipPaths.d.ts +1 -1
  220. package/dist/src/util/misc/mergeClipPaths.min.mjs.map +1 -1
  221. package/dist/src/util/misc/mergeClipPaths.mjs +1 -1
  222. package/dist/src/util/misc/mergeClipPaths.mjs.map +1 -1
  223. package/dist/src/util/misc/objectEnlive.min.mjs.map +1 -1
  224. package/dist/src/util/misc/objectEnlive.mjs +1 -1
  225. package/dist/src/util/misc/objectEnlive.mjs.map +1 -1
  226. package/dist/src/util/misc/projectStroke/StrokeLineJoinProjections.min.mjs +1 -1
  227. package/dist/src/util/misc/projectStroke/StrokeLineJoinProjections.min.mjs.map +1 -1
  228. package/dist/src/util/misc/projectStroke/StrokeLineJoinProjections.mjs +1 -1
  229. package/dist/src/util/misc/svgParsing.d.ts +2 -2
  230. package/dist/src/util/misc/svgParsing.d.ts.map +1 -1
  231. package/dist/src/util/misc/svgParsing.min.mjs +1 -1
  232. package/dist/src/util/misc/svgParsing.min.mjs.map +1 -1
  233. package/dist/src/util/misc/svgParsing.mjs +8 -3
  234. package/dist/src/util/misc/svgParsing.mjs.map +1 -1
  235. package/dist/src/util/path/index.d.ts.map +1 -1
  236. package/dist/src/util/path/index.min.mjs +1 -1
  237. package/dist/src/util/path/index.min.mjs.map +1 -1
  238. package/dist/src/util/path/index.mjs +2 -1
  239. package/dist/src/util/path/index.mjs.map +1 -1
  240. package/dist/src/util/path/regex.min.mjs.map +1 -1
  241. package/dist/src/util/path/regex.mjs +1 -1
  242. package/dist/src/util/path/regex.mjs.map +1 -1
  243. package/dist-extensions/_virtual/{_@oxc-project_runtime@0.122.0 → _@oxc-project_runtime@0.126.0}/helpers/defineProperty.mjs +1 -1
  244. package/{dist/_virtual/_@oxc-project_runtime@0.122.0 → dist-extensions/_virtual/_@oxc-project_runtime@0.126.0}/helpers/toPrimitive.mjs +1 -1
  245. package/dist-extensions/_virtual/{_@oxc-project_runtime@0.122.0 → _@oxc-project_runtime@0.126.0}/helpers/toPropertyKey.mjs +1 -1
  246. package/{dist/_virtual/_@oxc-project_runtime@0.122.0 → dist-extensions/_virtual/_@oxc-project_runtime@0.126.0}/helpers/typeof.mjs +1 -1
  247. package/dist-extensions/aligning_guidelines/index.mjs +1 -1
  248. package/dist-extensions/cropping_controls/croppingHandlers.mjs +1 -7
  249. package/dist-extensions/cropping_controls/croppingHandlers.mjs.map +1 -1
  250. package/dist-extensions/extensions/cropping_controls/croppingHandlers.d.ts.map +1 -1
  251. package/dist-extensions/fabric-extensions.min.js +1 -1
  252. package/dist-extensions/fabric-extensions.min.js.map +1 -1
  253. package/dist-extensions/src/canvas/StaticCanvas.d.ts +1 -1
  254. package/dist-extensions/src/canvas/StaticCanvas.d.ts.map +1 -1
  255. package/dist-extensions/src/gradient/Gradient.d.ts.map +1 -1
  256. package/dist-extensions/src/gradient/typedefs.d.ts +7 -7
  257. package/dist-extensions/src/parser/applyViewboxTransform.d.ts.map +1 -1
  258. package/dist-extensions/src/shapes/IText/IText.d.ts.map +1 -1
  259. package/dist-extensions/src/shapes/Object/FabricObjectSVGExportMixin.d.ts.map +1 -1
  260. package/dist-extensions/src/shapes/Object/InteractiveObject.d.ts.map +1 -1
  261. package/dist-extensions/src/shapes/Object/ObjectGeometry.d.ts.map +1 -1
  262. package/dist-extensions/src/shapes/Object/types/FabricObjectProps.d.ts +1 -1
  263. package/dist-extensions/src/shapes/Text/Text.d.ts +4 -4
  264. package/dist-extensions/src/shapes/Text/TextSVGExportMixin.d.ts.map +1 -1
  265. package/dist-extensions/src/shapes/Textbox.d.ts.map +1 -1
  266. package/dist-extensions/src/util/internals/applyCanvasTransform.d.ts +1 -1
  267. package/dist-extensions/src/util/internals/svgExportCheck.d.ts +4 -0
  268. package/dist-extensions/src/util/internals/svgExportCheck.d.ts.map +1 -0
  269. package/dist-extensions/src/util/misc/matrix.d.ts +14 -0
  270. package/dist-extensions/src/util/misc/matrix.d.ts.map +1 -1
  271. package/dist-extensions/src/util/misc/mergeClipPaths.d.ts +1 -1
  272. package/dist-extensions/src/util/misc/svgParsing.d.ts +2 -2
  273. package/dist-extensions/src/util/misc/svgParsing.d.ts.map +1 -1
  274. package/dist-extensions/src/util/path/index.d.ts.map +1 -1
  275. package/extensions/cropping_controls/croppingHandlers.ts +13 -19
  276. package/package.json +10 -10
  277. package/src/LayoutManager/README.md +3 -3
  278. package/src/canvas/StaticCanvas.spec.ts +19 -0
  279. package/src/canvas/StaticCanvas.ts +7 -3
  280. package/src/filters/Resize.ts +1 -1
  281. package/src/gradient/Gradient.spec.ts +60 -1
  282. package/src/gradient/Gradient.ts +9 -2
  283. package/src/gradient/typedefs.ts +7 -7
  284. package/src/parser/applyViewboxTransform.ts +2 -4
  285. package/src/shapes/IText/IText.ts +1 -2
  286. package/src/shapes/IText/ITextBehavior.test.ts +6 -6
  287. package/src/shapes/Object/FabricObject.spec.ts +3 -2
  288. package/src/shapes/Object/FabricObjectSVGExportMixin.ts +47 -37
  289. package/src/shapes/Object/InteractiveObject.ts +13 -3
  290. package/src/shapes/Object/Object-interactivity.spec.ts +126 -7
  291. package/src/shapes/Object/ObjectGeometry.spec.ts +10 -1
  292. package/src/shapes/Object/ObjectGeometry.ts +10 -3
  293. package/src/shapes/Object/objectSvgExport.spec.ts +27 -0
  294. package/src/shapes/Object/types/FabricObjectProps.ts +1 -1
  295. package/src/shapes/Text/Text.spec.ts +25 -0
  296. package/src/shapes/Text/Text.ts +5 -5
  297. package/src/shapes/Text/TextSVGExportMixin.ts +25 -11
  298. package/src/shapes/Textbox.ts +1 -2
  299. package/src/util/animation/animations.spec.ts +1 -1
  300. package/src/util/animation/easing.ts +1 -1
  301. package/src/util/internals/applyCanvasTransform.ts +1 -1
  302. package/src/util/internals/svgExportCheck.ts +20 -0
  303. package/src/util/misc/matrix.spec.ts +52 -0
  304. package/src/util/misc/matrix.ts +16 -0
  305. package/src/util/misc/mergeClipPaths.ts +1 -1
  306. package/src/util/misc/objectEnlive.ts +1 -1
  307. package/src/util/misc/svgParsing.ts +22 -10
  308. package/src/util/path/index.ts +3 -2
  309. package/src/util/path/regex.ts +1 -1
  310. package/src/util/typeAssertions.spec.ts +1 -1
  311. /package/dist/_virtual/{_@oxc-project_runtime@0.122.0 → _@oxc-project_runtime@0.126.0}/helpers/defineProperty.min.mjs +0 -0
  312. /package/dist/_virtual/{_@oxc-project_runtime@0.122.0 → _@oxc-project_runtime@0.126.0}/helpers/toPrimitive.min.mjs +0 -0
  313. /package/dist/_virtual/{_@oxc-project_runtime@0.122.0 → _@oxc-project_runtime@0.126.0}/helpers/toPropertyKey.min.mjs +0 -0
  314. /package/dist/_virtual/{_@oxc-project_runtime@0.122.0 → _@oxc-project_runtime@0.126.0}/helpers/typeof.min.mjs +0 -0
@@ -1,2 +1,2 @@
1
- import{_defineProperty as e}from"../../_virtual/_@oxc-project_runtime@0.122.0/helpers/defineProperty.min.mjs";import{classRegistry as t}from"../ClassRegistry.min.mjs";import{BaseFilter as n}from"./BaseFilter.min.mjs";import{fragmentSource as r}from"./shaders/convolute.min.mjs";var i=class extends n{getCacheKey(){return`${this.type}_${Math.sqrt(this.matrix.length)}_${this.opaque?1:0}`}getFragmentSource(){return r[this.getCacheKey()]}applyTo2d(e){let t=e.imageData,n=t.data,r=this.matrix,i=Math.round(Math.sqrt(r.length)),a=Math.floor(i/2),o=t.width,s=t.height,c=e.ctx.createImageData(o,s),l=c.data,u=this.opaque?1:0,d,f,p,m,h,g,_,v,y,b,x,S,C;for(x=0;x<s;x++)for(b=0;b<o;b++){for(h=4*(x*o+b),d=0,f=0,p=0,m=0,C=0;C<i;C++)for(S=0;S<i;S++)_=x+C-a,g=b+S-a,_<0||_>=s||g<0||g>=o||(v=4*(_*o+g),y=r[C*i+S],d+=n[v]*y,f+=n[v+1]*y,p+=n[v+2]*y,u||(m+=n[v+3]*y));l[h]=d,l[h+1]=f,l[h+2]=p,l[h+3]=u?n[h+3]:m}e.imageData=c}sendUniformData(e,t){e.uniform1fv(t.uMatrix,this.matrix)}toObject(){return{...super.toObject(),opaque:this.opaque,matrix:[...this.matrix]}}};e(i,`type`,`Convolute`),e(i,`defaults`,{opaque:!1,matrix:[0,0,0,0,1,0,0,0,0]}),e(i,`uniformLocations`,[`uMatrix`,`uOpaque`,`uHalfSize`,`uSize`]),t.setClass(i);export{i as Convolute};
1
+ import{_defineProperty as e}from"../../_virtual/_@oxc-project_runtime@0.126.0/helpers/defineProperty.min.mjs";import{classRegistry as t}from"../ClassRegistry.min.mjs";import{BaseFilter as n}from"./BaseFilter.min.mjs";import{fragmentSource as r}from"./shaders/convolute.min.mjs";var i=class extends n{getCacheKey(){return`${this.type}_${Math.sqrt(this.matrix.length)}_${+!!this.opaque}`}getFragmentSource(){return r[this.getCacheKey()]}applyTo2d(e){let t=e.imageData,n=t.data,r=this.matrix,i=Math.round(Math.sqrt(r.length)),a=Math.floor(i/2),o=t.width,s=t.height,c=e.ctx.createImageData(o,s),l=c.data,u=+!!this.opaque,d,f,p,m,h,g,_,v,y,b,x,S,C;for(x=0;x<s;x++)for(b=0;b<o;b++){for(h=4*(x*o+b),d=0,f=0,p=0,m=0,C=0;C<i;C++)for(S=0;S<i;S++)_=x+C-a,g=b+S-a,_<0||_>=s||g<0||g>=o||(v=4*(_*o+g),y=r[C*i+S],d+=n[v]*y,f+=n[v+1]*y,p+=n[v+2]*y,u||(m+=n[v+3]*y));l[h]=d,l[h+1]=f,l[h+2]=p,l[h+3]=u?n[h+3]:m}e.imageData=c}sendUniformData(e,t){e.uniform1fv(t.uMatrix,this.matrix)}toObject(){return{...super.toObject(),opaque:this.opaque,matrix:[...this.matrix]}}};e(i,`type`,`Convolute`),e(i,`defaults`,{opaque:!1,matrix:[0,0,0,0,1,0,0,0,0]}),e(i,`uniformLocations`,[`uMatrix`,`uOpaque`,`uHalfSize`,`uSize`]),t.setClass(i);export{i as Convolute};
2
2
  //# sourceMappingURL=Convolute.min.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"Convolute.min.mjs","names":[],"sources":["../../../src/filters/Convolute.ts"],"sourcesContent":["import { BaseFilter } from './BaseFilter';\nimport type { T2DPipelineState, TWebGLUniformLocationMap } from './typedefs';\nimport { classRegistry } from '../ClassRegistry';\nimport { fragmentSource } from './shaders/convolute';\n\nexport type ConvoluteOwnProps = {\n opaque: boolean;\n matrix: number[];\n};\n\nexport const convoluteDefaultValues: ConvoluteOwnProps = {\n opaque: false,\n matrix: [0, 0, 0, 0, 1, 0, 0, 0, 0],\n};\n\n/**\n * Adapted from <a href=\"http://www.html5rocks.com/en/tutorials/canvas/imagefilters/\">html5rocks article</a>\n * @example <caption>Sharpen filter</caption>\n * const filter = new Convolute({\n * matrix: [ 0, -1, 0,\n * -1, 5, -1,\n * 0, -1, 0 ]\n * });\n * object.filters.push(filter);\n * object.applyFilters();\n * canvas.renderAll();\n * @example <caption>Blur filter</caption>\n * const filter = new Convolute({\n * matrix: [ 1/9, 1/9, 1/9,\n * 1/9, 1/9, 1/9,\n * 1/9, 1/9, 1/9 ]\n * });\n * object.filters.push(filter);\n * object.applyFilters();\n * canvas.renderAll();\n * @example <caption>Emboss filter</caption>\n * const filter = new Convolute({\n * matrix: [ 1, 1, 1,\n * 1, 0.7, -1,\n * -1, -1, -1 ]\n * });\n * object.filters.push(filter);\n * object.applyFilters();\n * canvas.renderAll();\n * @example <caption>Emboss filter with opaqueness</caption>\n * const filter = new Convolute({\n * opaque: true,\n * matrix: [ 1, 1, 1,\n * 1, 0.7, -1,\n * -1, -1, -1 ]\n * });\n * object.filters.push(filter);\n * object.applyFilters();\n * canvas.renderAll();\n */\nexport class Convolute extends BaseFilter<'Convolute', ConvoluteOwnProps> {\n /*\n * Opaque value (true/false)\n */\n declare opaque: ConvoluteOwnProps['opaque'];\n\n /*\n * matrix for the filter, max 9x9\n */\n declare matrix: ConvoluteOwnProps['matrix'];\n\n static type = 'Convolute';\n\n static defaults = convoluteDefaultValues;\n\n static uniformLocations = ['uMatrix', 'uOpaque', 'uHalfSize', 'uSize'];\n\n getCacheKey() {\n return `${this.type}_${Math.sqrt(this.matrix.length)}_${\n this.opaque ? 1 : 0\n }` as keyof typeof fragmentSource;\n }\n\n getFragmentSource() {\n return fragmentSource[this.getCacheKey()];\n }\n\n /**\n * Apply the Brightness operation to a Uint8ClampedArray representing the pixels of an image.\n *\n * @param {Object} options\n * @param {ImageData} options.imageData The Uint8ClampedArray to be filtered.\n */\n applyTo2d(options: T2DPipelineState) {\n const imageData = options.imageData,\n data = imageData.data,\n weights = this.matrix,\n side = Math.round(Math.sqrt(weights.length)),\n halfSide = Math.floor(side / 2),\n sw = imageData.width,\n sh = imageData.height,\n output = options.ctx.createImageData(sw, sh),\n dst = output.data,\n // go through the destination image pixels\n alphaFac = this.opaque ? 1 : 0;\n let r, g, b, a, dstOff, scx, scy, srcOff, wt, x, y, cx, cy;\n\n for (y = 0; y < sh; y++) {\n for (x = 0; x < sw; x++) {\n dstOff = (y * sw + x) * 4;\n // calculate the weighed sum of the source image pixels that\n // fall under the convolution matrix\n r = 0;\n g = 0;\n b = 0;\n a = 0;\n\n for (cy = 0; cy < side; cy++) {\n for (cx = 0; cx < side; cx++) {\n scy = y + cy - halfSide;\n scx = x + cx - halfSide;\n\n if (scy < 0 || scy >= sh || scx < 0 || scx >= sw) {\n continue;\n }\n\n srcOff = (scy * sw + scx) * 4;\n wt = weights[cy * side + cx];\n\n r += data[srcOff] * wt;\n g += data[srcOff + 1] * wt;\n b += data[srcOff + 2] * wt;\n\n if (!alphaFac) {\n a += data[srcOff + 3] * wt;\n }\n }\n }\n dst[dstOff] = r;\n dst[dstOff + 1] = g;\n dst[dstOff + 2] = b;\n if (!alphaFac) {\n dst[dstOff + 3] = a;\n } else {\n dst[dstOff + 3] = data[dstOff + 3];\n }\n }\n }\n options.imageData = output;\n }\n\n /**\n * Send data from this filter to its shader program's uniforms.\n *\n * @param {WebGLRenderingContext} gl The GL canvas context used to compile this filter's shader.\n * @param {Object} uniformLocations A map of string uniform names to WebGLUniformLocation objects\n */\n sendUniformData(\n gl: WebGLRenderingContext,\n uniformLocations: TWebGLUniformLocationMap,\n ) {\n gl.uniform1fv(uniformLocations.uMatrix, this.matrix);\n }\n\n /**\n * Returns object representation of an instance\n * @return {Object} Object representation of an instance\n */\n toObject() {\n return {\n ...super.toObject(),\n opaque: this.op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GAHV,EAGe,EAAK,EAAS,GAFd,EAMxB,EAAQ,UAAY,EAStB,gBACE,EACA,EAAA,CAEA,EAAG,WAAW,EAAiB,QAAS,KAAK,OAAA,CAO/C,UAAA,CACE,MAAO,CAAA,GACF,MAAM,UAAA,CACT,OAAQ,KAAK,OACb,OAAQ,CAAA,GAAI,KAAK,OAAA,CAAA,GAAA,EAAA,EArGd,OAAO,YAAA,CAAA,EAAA,EAEP,WA1DgD,CACvD,OAAA,CAAQ,EACR,OAAQ,CAAC,EAAG,EAAG,EAAG,EAAG,EAAG,EAAG,EAAG,EAAG,EAAA,CAAA,CAAA,CAAA,EAAA,EA0D1B,mBAAmB,CAAC,UAAW,UAAW,YAAa,QAAA,CAAA,CAsGhE,EAAc,SAAS,EAAA,CAAA,OAAA,KAAA"}
1
+ {"version":3,"file":"Convolute.min.mjs","names":[],"sources":["../../../src/filters/Convolute.ts"],"sourcesContent":["import { BaseFilter } from './BaseFilter';\nimport type { T2DPipelineState, TWebGLUniformLocationMap } from './typedefs';\nimport { classRegistry } from '../ClassRegistry';\nimport { fragmentSource } from './shaders/convolute';\n\nexport type ConvoluteOwnProps = {\n opaque: boolean;\n matrix: number[];\n};\n\nexport const convoluteDefaultValues: ConvoluteOwnProps = {\n opaque: false,\n matrix: [0, 0, 0, 0, 1, 0, 0, 0, 0],\n};\n\n/**\n * Adapted from <a href=\"http://www.html5rocks.com/en/tutorials/canvas/imagefilters/\">html5rocks article</a>\n * @example <caption>Sharpen filter</caption>\n * const filter = new Convolute({\n * matrix: [ 0, -1, 0,\n * -1, 5, -1,\n * 0, -1, 0 ]\n * });\n * object.filters.push(filter);\n * object.applyFilters();\n * canvas.renderAll();\n * @example <caption>Blur filter</caption>\n * const filter = new Convolute({\n * matrix: [ 1/9, 1/9, 1/9,\n * 1/9, 1/9, 1/9,\n * 1/9, 1/9, 1/9 ]\n * });\n * object.filters.push(filter);\n * object.applyFilters();\n * canvas.renderAll();\n * @example <caption>Emboss filter</caption>\n * const filter = new Convolute({\n * matrix: [ 1, 1, 1,\n * 1, 0.7, -1,\n * -1, -1, -1 ]\n * });\n * object.filters.push(filter);\n * object.applyFilters();\n * canvas.renderAll();\n * @example <caption>Emboss filter with opaqueness</caption>\n * const filter = new Convolute({\n * opaque: true,\n * matrix: [ 1, 1, 1,\n * 1, 0.7, -1,\n * -1, -1, -1 ]\n * });\n * object.filters.push(filter);\n * object.applyFilters();\n * canvas.renderAll();\n */\nexport class Convolute extends BaseFilter<'Convolute', ConvoluteOwnProps> {\n /*\n * Opaque value (true/false)\n */\n declare opaque: ConvoluteOwnProps['opaque'];\n\n /*\n * matrix for the filter, max 9x9\n */\n declare matrix: ConvoluteOwnProps['matrix'];\n\n static type = 'Convolute';\n\n static defaults = convoluteDefaultValues;\n\n static uniformLocations = ['uMatrix', 'uOpaque', 'uHalfSize', 'uSize'];\n\n getCacheKey() {\n return `${this.type}_${Math.sqrt(this.matrix.length)}_${\n this.opaque ? 1 : 0\n }` as keyof typeof fragmentSource;\n }\n\n getFragmentSource() {\n return fragmentSource[this.getCacheKey()];\n }\n\n /**\n * Apply the Brightness operation to a Uint8ClampedArray representing the pixels of an image.\n *\n * @param {Object} options\n * @param {ImageData} options.imageData The Uint8ClampedArray to be filtered.\n */\n applyTo2d(options: T2DPipelineState) {\n const imageData = options.imageData,\n data = imageData.data,\n weights = this.matrix,\n side = Math.round(Math.sqrt(weights.length)),\n halfSide = Math.floor(side / 2),\n sw = imageData.width,\n sh = imageData.height,\n output = options.ctx.createImageData(sw, sh),\n dst = output.data,\n // go through the destination image pixels\n alphaFac = this.opaque ? 1 : 0;\n let r, g, b, a, dstOff, scx, scy, srcOff, wt, x, y, cx, cy;\n\n for (y = 0; y < sh; y++) {\n for (x = 0; x < sw; x++) {\n dstOff = (y * sw + x) * 4;\n // calculate the weighed sum of the source image pixels that\n // fall under the convolution matrix\n r = 0;\n g = 0;\n b = 0;\n a = 0;\n\n for (cy = 0; cy < side; cy++) {\n for (cx = 0; cx < side; cx++) {\n scy = y + cy - halfSide;\n scx = x + cx - halfSide;\n\n if (scy < 0 || scy >= sh || scx < 0 || scx >= sw) {\n continue;\n }\n\n srcOff = (scy * sw + scx) * 4;\n wt = weights[cy * side + cx];\n\n r += data[srcOff] * wt;\n g += data[srcOff + 1] * wt;\n b += data[srcOff + 2] * wt;\n\n if (!alphaFac) {\n a += data[srcOff + 3] * wt;\n }\n }\n }\n dst[dstOff] = r;\n dst[dstOff + 1] = g;\n dst[dstOff + 2] = b;\n if (!alphaFac) {\n dst[dstOff + 3] = a;\n } else {\n dst[dstOff + 3] = data[dstOff + 3];\n }\n }\n }\n options.imageData = output;\n }\n\n /**\n * Send data from this filter to its shader program's uniforms.\n *\n * @param {WebGLRenderingContext} gl The GL canvas context used to compile this filter's shader.\n * @param {Object} uniformLocations A map of string uniform names to WebGLUniformLocation objects\n */\n sendUniformData(\n gl: WebGLRenderingContext,\n uniformLocations: TWebGLUniformLocationMap,\n ) {\n gl.uniform1fv(uniformLocations.uMatrix, this.matrix);\n }\n\n /**\n * Returns object representation of an instance\n * @return {Object} Object representation of an instance\n */\n toObject() {\n return {\n ...super.toObject(),\n opaque: this.opaque,\n matrix: [...this.matrix],\n };\n }\n}\n\nclassRegistry.setClass(Convolute);\n"],"mappings":"sRAuDA,IAAa,EAAb,cAA+B,CAAA,CAiB7B,aAAA,CACE,MAAO,GAAG,KAAK,KAAA,GAAQ,KAAK,KAAK,KAAK,OAAO,OAAA,CAAA,GAC3C,QAAK,SAIT,mBAAA,CACE,OAAO,EAAe,KAAK,aAAA,EAS7B,UAAU,EAAA,CACR,IAAM,EAAY,EAAQ,UACxB,EAAO,EAAU,KACjB,EAAU,KAAK,OACf,EAAO,KAAK,MAAM,KAAK,KAAK,EAAQ,OAAA,CAAA,CACpC,EAAW,KAAK,MAAM,EAAO,EAAA,CAC7B,EAAK,EAAU,MACf,EAAK,EAAU,OACf,EAAS,EAAQ,IAAI,gBAAgB,EAAI,EAAA,CACzC,EAAM,EAAO,KAEb,EA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-project_runtime@0.122.0/helpers/defineProperty.mjs";
1
+ import { _defineProperty } from "../../_virtual/_@oxc-project_runtime@0.126.0/helpers/defineProperty.mjs";
2
2
  import { classRegistry } from "../ClassRegistry.mjs";
3
3
  import { BaseFilter } from "./BaseFilter.mjs";
4
4
  import { fragmentSource } from "./shaders/convolute.mjs";
@@ -1,2 +1,2 @@
1
- import{_defineProperty as e}from"../../_virtual/_@oxc-project_runtime@0.122.0/helpers/defineProperty.min.mjs";import{classRegistry as t}from"../ClassRegistry.min.mjs";import{BaseFilter as n}from"./BaseFilter.min.mjs";import{fragmentSource as r}from"./shaders/gamma.min.mjs";const i=`Gamma`;var a=class extends n{getFragmentSource(){return r}constructor(e={}){super(e),this.gamma=e.gamma||this.constructor.defaults.gamma.concat()}applyTo2d({imageData:{data:e}}){let t=this.gamma,n=1/t[0],r=1/t[1],i=1/t[2];this.rgbValues||(this.rgbValues={r:new Uint8Array(256),g:new Uint8Array(256),b:new Uint8Array(256)});let a=this.rgbValues;for(let e=0;e<256;e++)a.r[e]=255*(e/255)**n,a.g[e]=255*(e/255)**r,a.b[e]=255*(e/255)**i;for(let t=0;t<e.length;t+=4)e[t]=a.r[e[t]],e[t+1]=a.g[e[t+1]],e[t+2]=a.b[e[t+2]]}sendUniformData(e,t){e.uniform3fv(t.uGamma,this.gamma)}isNeutralState(){let{gamma:e}=this;return e[0]===1&&e[1]===1&&e[2]===1}toObject(){return{type:i,gamma:this.gamma.concat()}}};e(a,`type`,i),e(a,`defaults`,{gamma:[1,1,1]}),e(a,`uniformLocations`,[`uGamma`]),t.setClass(a);export{a as Gamma};
1
+ import{_defineProperty as e}from"../../_virtual/_@oxc-project_runtime@0.126.0/helpers/defineProperty.min.mjs";import{classRegistry as t}from"../ClassRegistry.min.mjs";import{BaseFilter as n}from"./BaseFilter.min.mjs";import{fragmentSource as r}from"./shaders/gamma.min.mjs";const i=`Gamma`;var a=class extends n{getFragmentSource(){return r}constructor(e={}){super(e),this.gamma=e.gamma||this.constructor.defaults.gamma.concat()}applyTo2d({imageData:{data:e}}){let t=this.gamma,n=1/t[0],r=1/t[1],i=1/t[2];this.rgbValues||(this.rgbValues={r:new Uint8Array(256),g:new Uint8Array(256),b:new Uint8Array(256)});let a=this.rgbValues;for(let e=0;e<256;e++)a.r[e]=255*(e/255)**n,a.g[e]=255*(e/255)**r,a.b[e]=255*(e/255)**i;for(let t=0;t<e.length;t+=4)e[t]=a.r[e[t]],e[t+1]=a.g[e[t+1]],e[t+2]=a.b[e[t+2]]}sendUniformData(e,t){e.uniform3fv(t.uGamma,this.gamma)}isNeutralState(){let{gamma:e}=this;return e[0]===1&&e[1]===1&&e[2]===1}toObject(){return{type:i,gamma:this.gamma.concat()}}};e(a,`type`,i),e(a,`defaults`,{gamma:[1,1,1]}),e(a,`uniformLocations`,[`uGamma`]),t.setClass(a);export{a as Gamma};
2
2
  //# sourceMappingURL=Gamma.min.mjs.map
@@ -1,4 +1,4 @@
1
- import { _defineProperty } from "../../_virtual/_@oxc-project_runtime@0.122.0/helpers/defineProperty.mjs";
1
+ import { _defineProperty } from "../../_virtual/_@oxc-project_runtime@0.126.0/helpers/defineProperty.mjs";
2
2
  import { classRegistry } from "../ClassRegistry.mjs";
3
3
  import { BaseFilter } from "./BaseFilter.mjs";
4
4
  import { fragmentSource } from "./shaders/gamma.mjs";
@@ -1,2 +1,2 @@
1
- import{_defineProperty as e}from"../../_virtual/_@oxc-project_runtime@0.122.0/helpers/defineProperty.min.mjs";import{classRegistry as t}from"../ClassRegistry.min.mjs";import{BaseFilter as n}from"./BaseFilter.min.mjs";import{fragmentSource as r}from"./shaders/grayscale.min.mjs";var i=class extends n{applyTo2d({imageData:{data:e}}){for(let t,n=0;n<e.length;n+=4){let r=e[n],i=e[n+1],a=e[n+2];switch(this.mode){case`average`:t=(r+i+a)/3;break;case`lightness`:t=(Math.min(r,i,a)+Math.max(r,i,a))/2;break;case`luminosity`:t=.21*r+.72*i+.07*a}e[n+2]=e[n+1]=e[n]=t}}getCacheKey(){return`${this.type}_${this.mode}`}getFragmentSource(){return r[this.mode]}sendUniformData(e,t){e.uniform1i(t.uMode,1)}isNeutralState(){return!1}};e(i,`type`,`Grayscale`),e(i,`defaults`,{mode:`average`}),e(i,`uniformLocations`,[`uMode`]),t.setClass(i);export{i as Grayscale};
1
+ import{_defineProperty as e}from"../../_virtual/_@oxc-project_runtime@0.126.0/helpers/defineProperty.min.mjs";import{classRegistry as t}from"../ClassRegistry.min.mjs";import{BaseFilter as n}from"./BaseFilter.min.mjs";import{fragmentSource as r}from"./shaders/grayscale.min.mjs";var i=class extends n{applyTo2d({imageData:{data:e}}){for(let t,n=0;n<e.length;n+=4){let r=e[n],i=e[n+1],a=e[n+2];switch(this.mode){case`average`:t=(r+i+a)/3;break;case`lightness`:t=(Math.min(r,i,a)+Math.max(r,i,a))/2;break;case`luminosity`:t=.21*r+.72*i+.07*a}e[n+2]=e[n+1]=e[n]=t}}getCacheKey(){return`${this.type}_${this.mode}`}getFragmentSource(){return r[this.mode]}sendUniformData(e,t){e.uniform1i(t.uMode,1)}isNeutralState(){return!1}};e(i,`type`,`Grayscale`),e(i,`defaults`,{mode:`average`}),e(i,`uniformLocations`,[`uMode`]),t.setClass(i);export{i as Grayscale};
2
2
  //# sourceMappingURL=Grayscale.min.mjs.map
@@ -1,4 +1,4 @@
1
- import { _defineProperty } from "../../_virtual/_@oxc-project_runtime@0.122.0/helpers/defineProperty.mjs";
1
+ import { _defineProperty } from "../../_virtual/_@oxc-project_runtime@0.126.0/helpers/defineProperty.mjs";
2
2
  import { classRegistry } from "../ClassRegistry.mjs";
3
3
  import { BaseFilter } from "./BaseFilter.mjs";
4
4
  import { fragmentSource } from "./shaders/grayscale.mjs";
@@ -1,2 +1,2 @@
1
- import{_defineProperty as e}from"../../_virtual/_@oxc-project_runtime@0.122.0/helpers/defineProperty.min.mjs";import{classRegistry as t}from"../ClassRegistry.min.mjs";import{cos as n}from"../util/misc/cos.min.mjs";import{sin as r}from"../util/misc/sin.min.mjs";import{ColorMatrix as i,colorMatrixDefaultValues as a}from"./ColorMatrix.min.mjs";const o={...a,rotation:0};var s=class extends i{calculateMatrix(){let e=this.rotation*Math.PI,t=n(e),i=r(e),a=1/3,o=Math.sqrt(a)*i,s=1-t;this.matrix=[t+s/3,a*s-o,a*s+o,0,0,a*s+o,t+a*s,a*s-o,0,0,a*s-o,a*s+o,t+a*s,0,0,0,0,0,1,0]}isNeutralState(){return this.rotation===0}applyTo(e){this.calculateMatrix(),super.applyTo(e)}toObject(){return{type:this.type,rotation:this.rotation}}};e(s,`type`,`HueRotation`),e(s,`defaults`,o),t.setClass(s);export{s as HueRotation};
1
+ import{_defineProperty as e}from"../../_virtual/_@oxc-project_runtime@0.126.0/helpers/defineProperty.min.mjs";import{classRegistry as t}from"../ClassRegistry.min.mjs";import{cos as n}from"../util/misc/cos.min.mjs";import{sin as r}from"../util/misc/sin.min.mjs";import{ColorMatrix as i,colorMatrixDefaultValues as a}from"./ColorMatrix.min.mjs";const o={...a,rotation:0};var s=class extends i{calculateMatrix(){let e=this.rotation*Math.PI,t=n(e),i=r(e),a=1/3,o=Math.sqrt(a)*i,s=1-t;this.matrix=[t+s/3,a*s-o,a*s+o,0,0,a*s+o,t+a*s,a*s-o,0,0,a*s-o,a*s+o,t+a*s,0,0,0,0,0,1,0]}isNeutralState(){return this.rotation===0}applyTo(e){this.calculateMatrix(),super.applyTo(e)}toObject(){return{type:this.type,rotation:this.rotation}}};e(s,`type`,`HueRotation`),e(s,`defaults`,o),t.setClass(s);export{s as HueRotation};
2
2
  //# sourceMappingURL=HueRotation.min.mjs.map
@@ -1,4 +1,4 @@
1
- import { _defineProperty } from "../../_virtual/_@oxc-project_runtime@0.122.0/helpers/defineProperty.mjs";
1
+ import { _defineProperty } from "../../_virtual/_@oxc-project_runtime@0.126.0/helpers/defineProperty.mjs";
2
2
  import { classRegistry } from "../ClassRegistry.mjs";
3
3
  import { cos } from "../util/misc/cos.mjs";
4
4
  import { sin } from "../util/misc/sin.mjs";
@@ -1,2 +1,2 @@
1
- import{_defineProperty as e}from"../../_virtual/_@oxc-project_runtime@0.122.0/helpers/defineProperty.min.mjs";import{classRegistry as t}from"../ClassRegistry.min.mjs";import{BaseFilter as n}from"./BaseFilter.min.mjs";import{fragmentSource as r}from"./shaders/invert.min.mjs";var i=class extends n{applyTo2d({imageData:{data:e}}){for(let t=0;t<e.length;t+=4)e[t]=255-e[t],e[t+1]=255-e[t+1],e[t+2]=255-e[t+2],this.alpha&&(e[t+3]=255-e[t+3])}getFragmentSource(){return r}isNeutralState(){return!this.invert}sendUniformData(e,t){e.uniform1i(t.uInvert,Number(this.invert)),e.uniform1i(t.uAlpha,Number(this.alpha))}};e(i,`type`,`Invert`),e(i,`defaults`,{alpha:!1,invert:!0}),e(i,`uniformLocations`,[`uInvert`,`uAlpha`]),t.setClass(i);export{i as Invert};
1
+ import{_defineProperty as e}from"../../_virtual/_@oxc-project_runtime@0.126.0/helpers/defineProperty.min.mjs";import{classRegistry as t}from"../ClassRegistry.min.mjs";import{BaseFilter as n}from"./BaseFilter.min.mjs";import{fragmentSource as r}from"./shaders/invert.min.mjs";var i=class extends n{applyTo2d({imageData:{data:e}}){for(let t=0;t<e.length;t+=4)e[t]=255-e[t],e[t+1]=255-e[t+1],e[t+2]=255-e[t+2],this.alpha&&(e[t+3]=255-e[t+3])}getFragmentSource(){return r}isNeutralState(){return!this.invert}sendUniformData(e,t){e.uniform1i(t.uInvert,Number(this.invert)),e.uniform1i(t.uAlpha,Number(this.alpha))}};e(i,`type`,`Invert`),e(i,`defaults`,{alpha:!1,invert:!0}),e(i,`uniformLocations`,[`uInvert`,`uAlpha`]),t.setClass(i);export{i as Invert};
2
2
  //# sourceMappingURL=Invert.min.mjs.map
@@ -1,4 +1,4 @@
1
- import { _defineProperty } from "../../_virtual/_@oxc-project_runtime@0.122.0/helpers/defineProperty.mjs";
1
+ import { _defineProperty } from "../../_virtual/_@oxc-project_runtime@0.126.0/helpers/defineProperty.mjs";
2
2
  import { classRegistry } from "../ClassRegistry.mjs";
3
3
  import { BaseFilter } from "./BaseFilter.mjs";
4
4
  import { fragmentSource } from "./shaders/invert.mjs";
@@ -1,2 +1,2 @@
1
- import{_defineProperty as e}from"../../_virtual/_@oxc-project_runtime@0.122.0/helpers/defineProperty.min.mjs";import{classRegistry as t}from"../ClassRegistry.min.mjs";import{BaseFilter as n}from"./BaseFilter.min.mjs";import{fragmentSource as r}from"./shaders/noise.min.mjs";var i=class extends n{getFragmentSource(){return r}applyTo2d({imageData:{data:e}}){let t=this.noise;for(let n=0;n<e.length;n+=4){let r=(.5-Math.random())*t;e[n]+=r,e[n+1]+=r,e[n+2]+=r}}sendUniformData(e,t){e.uniform1f(t.uNoise,this.noise/255),e.uniform1f(t.uSeed,Math.random())}isNeutralState(){return this.noise===0}};e(i,`type`,`Noise`),e(i,`defaults`,{noise:0}),e(i,`uniformLocations`,[`uNoise`,`uSeed`]),t.setClass(i);export{i as Noise};
1
+ import{_defineProperty as e}from"../../_virtual/_@oxc-project_runtime@0.126.0/helpers/defineProperty.min.mjs";import{classRegistry as t}from"../ClassRegistry.min.mjs";import{BaseFilter as n}from"./BaseFilter.min.mjs";import{fragmentSource as r}from"./shaders/noise.min.mjs";var i=class extends n{getFragmentSource(){return r}applyTo2d({imageData:{data:e}}){let t=this.noise;for(let n=0;n<e.length;n+=4){let r=(.5-Math.random())*t;e[n]+=r,e[n+1]+=r,e[n+2]+=r}}sendUniformData(e,t){e.uniform1f(t.uNoise,this.noise/255),e.uniform1f(t.uSeed,Math.random())}isNeutralState(){return this.noise===0}};e(i,`type`,`Noise`),e(i,`defaults`,{noise:0}),e(i,`uniformLocations`,[`uNoise`,`uSeed`]),t.setClass(i);export{i as Noise};
2
2
  //# sourceMappingURL=Noise.min.mjs.map
@@ -1,4 +1,4 @@
1
- import { _defineProperty } from "../../_virtual/_@oxc-project_runtime@0.122.0/helpers/defineProperty.mjs";
1
+ import { _defineProperty } from "../../_virtual/_@oxc-project_runtime@0.126.0/helpers/defineProperty.mjs";
2
2
  import { classRegistry } from "../ClassRegistry.mjs";
3
3
  import { BaseFilter } from "./BaseFilter.mjs";
4
4
  import { fragmentSource } from "./shaders/noise.mjs";
@@ -1,2 +1,2 @@
1
- import{_defineProperty as e}from"../../_virtual/_@oxc-project_runtime@0.122.0/helpers/defineProperty.min.mjs";import{classRegistry as t}from"../ClassRegistry.min.mjs";import{BaseFilter as n}from"./BaseFilter.min.mjs";import{fragmentSource as r}from"./shaders/pixelate.min.mjs";var i=class extends n{applyTo2d({imageData:{data:e,width:t,height:n}}){for(let r=0;r<n;r+=this.blocksize)for(let i=0;i<t;i+=this.blocksize){let a=4*r*t+4*i,o=e[a],s=e[a+1],c=e[a+2],l=e[a+3];for(let a=r;a<Math.min(r+this.blocksize,n);a++)for(let n=i;n<Math.min(i+this.blocksize,t);n++){let r=4*a*t+4*n;e[r]=o,e[r+1]=s,e[r+2]=c,e[r+3]=l}}}isNeutralState(){return this.blocksize===1}getFragmentSource(){return r}sendUniformData(e,t){e.uniform1f(t.uBlocksize,this.blocksize)}};e(i,`type`,`Pixelate`),e(i,`defaults`,{blocksize:4}),e(i,`uniformLocations`,[`uBlocksize`]),t.setClass(i);export{i as Pixelate};
1
+ import{_defineProperty as e}from"../../_virtual/_@oxc-project_runtime@0.126.0/helpers/defineProperty.min.mjs";import{classRegistry as t}from"../ClassRegistry.min.mjs";import{BaseFilter as n}from"./BaseFilter.min.mjs";import{fragmentSource as r}from"./shaders/pixelate.min.mjs";var i=class extends n{applyTo2d({imageData:{data:e,width:t,height:n}}){for(let r=0;r<n;r+=this.blocksize)for(let i=0;i<t;i+=this.blocksize){let a=4*r*t+4*i,o=e[a],s=e[a+1],c=e[a+2],l=e[a+3];for(let a=r;a<Math.min(r+this.blocksize,n);a++)for(let n=i;n<Math.min(i+this.blocksize,t);n++){let r=4*a*t+4*n;e[r]=o,e[r+1]=s,e[r+2]=c,e[r+3]=l}}}isNeutralState(){return this.blocksize===1}getFragmentSource(){return r}sendUniformData(e,t){e.uniform1f(t.uBlocksize,this.blocksize)}};e(i,`type`,`Pixelate`),e(i,`defaults`,{blocksize:4}),e(i,`uniformLocations`,[`uBlocksize`]),t.setClass(i);export{i as Pixelate};
2
2
  //# sourceMappingURL=Pixelate.min.mjs.map
@@ -1,4 +1,4 @@
1
- import { _defineProperty } from "../../_virtual/_@oxc-project_runtime@0.122.0/helpers/defineProperty.mjs";
1
+ import { _defineProperty } from "../../_virtual/_@oxc-project_runtime@0.126.0/helpers/defineProperty.mjs";
2
2
  import { classRegistry } from "../ClassRegistry.mjs";
3
3
  import { BaseFilter } from "./BaseFilter.mjs";
4
4
  import { fragmentSource } from "./shaders/pixelate.mjs";
@@ -1,2 +1,2 @@
1
- import{_defineProperty as e}from"../../_virtual/_@oxc-project_runtime@0.122.0/helpers/defineProperty.min.mjs";import{classRegistry as t}from"../ClassRegistry.min.mjs";import{Color as n}from"../color/Color.min.mjs";import{BaseFilter as r}from"./BaseFilter.min.mjs";import{fragmentShader as i}from"./shaders/removeColor.min.mjs";var a=class extends r{getFragmentSource(){return i}applyTo2d({imageData:{data:e}}){let t=255*this.distance,r=new n(this.color).getSource(),i=[r[0]-t,r[1]-t,r[2]-t],a=[r[0]+t,r[1]+t,r[2]+t];for(let t=0;t<e.length;t+=4){let n=e[t],r=e[t+1],o=e[t+2];n>i[0]&&r>i[1]&&o>i[2]&&n<a[0]&&r<a[1]&&o<a[2]&&(e[t+3]=0)}}sendUniformData(e,t){let r=new n(this.color).getSource(),i=this.distance,a=[0+r[0]/255-i,0+r[1]/255-i,0+r[2]/255-i,1],o=[r[0]/255+i,r[1]/255+i,r[2]/255+i,1];e.uniform4fv(t.uLow,a),e.uniform4fv(t.uHigh,o)}};e(a,`type`,`RemoveColor`),e(a,`defaults`,{color:`#FFFFFF`,distance:.02,useAlpha:!1}),e(a,`uniformLocations`,[`uLow`,`uHigh`]),t.setClass(a);export{a as RemoveColor};
1
+ import{_defineProperty as e}from"../../_virtual/_@oxc-project_runtime@0.126.0/helpers/defineProperty.min.mjs";import{classRegistry as t}from"../ClassRegistry.min.mjs";import{Color as n}from"../color/Color.min.mjs";import{BaseFilter as r}from"./BaseFilter.min.mjs";import{fragmentShader as i}from"./shaders/removeColor.min.mjs";var a=class extends r{getFragmentSource(){return i}applyTo2d({imageData:{data:e}}){let t=255*this.distance,r=new n(this.color).getSource(),i=[r[0]-t,r[1]-t,r[2]-t],a=[r[0]+t,r[1]+t,r[2]+t];for(let t=0;t<e.length;t+=4){let n=e[t],r=e[t+1],o=e[t+2];n>i[0]&&r>i[1]&&o>i[2]&&n<a[0]&&r<a[1]&&o<a[2]&&(e[t+3]=0)}}sendUniformData(e,t){let r=new n(this.color).getSource(),i=this.distance,a=[0+r[0]/255-i,0+r[1]/255-i,0+r[2]/255-i,1],o=[r[0]/255+i,r[1]/255+i,r[2]/255+i,1];e.uniform4fv(t.uLow,a),e.uniform4fv(t.uHigh,o)}};e(a,`type`,`RemoveColor`),e(a,`defaults`,{color:`#FFFFFF`,distance:.02,useAlpha:!1}),e(a,`uniformLocations`,[`uLow`,`uHigh`]),t.setClass(a);export{a as RemoveColor};
2
2
  //# sourceMappingURL=RemoveColor.min.mjs.map
@@ -1,4 +1,4 @@
1
- import { _defineProperty } from "../../_virtual/_@oxc-project_runtime@0.122.0/helpers/defineProperty.mjs";
1
+ import { _defineProperty } from "../../_virtual/_@oxc-project_runtime@0.126.0/helpers/defineProperty.mjs";
2
2
  import { classRegistry } from "../ClassRegistry.mjs";
3
3
  import { Color } from "../color/Color.mjs";
4
4
  import { BaseFilter } from "./BaseFilter.mjs";
@@ -1,3 +1,3 @@
1
- import{_defineProperty as e}from"../../_virtual/_@oxc-project_runtime@0.122.0/helpers/defineProperty.min.mjs";import{classRegistry as t}from"../ClassRegistry.min.mjs";import{createCanvasElement as n}from"../util/misc/dom.min.mjs";import{isWebGLPipelineState as r}from"./utils.min.mjs";import{BaseFilter as i}from"./BaseFilter.min.mjs";var a=class extends i{sendUniformData(e,t){e.uniform2fv(t.uDelta,this.horizontal?[1/this.width,0]:[0,1/this.height]),e.uniform1fv(t.uTaps,this.taps)}getFilterWindow(){let e=this.tempScale;return Math.ceil(this.lanczosLobes/e)}getCacheKey(){let e=this.getFilterWindow();return`${this.type}_${e}`}getFragmentSource(){let e=this.getFilterWindow();return this.generateShader(e)}getTaps(){let e=this.lanczosCreate(this.lanczosLobes),t=this.tempScale,n=this.getFilterWindow(),r=Array(n);for(let i=1;i<=n;i++)r[i-1]=e(i*t);return r}generateShader(e){let t=Array(e);for(let n=1;n<=e;n++)t[n-1]=`${n}.0 * uDelta`;return`\n precision highp float;\n uniform sampler2D uTexture;\n uniform vec2 uDelta;\n varying vec2 vTexCoord;\n uniform float uTaps[${e}];\n void main() {\n vec4 color = texture2D(uTexture, vTexCoord);\n float sum = 1.0;\n ${t.map((e,t)=>`\n color += texture2D(uTexture, vTexCoord + ${e}) * uTaps[${t}] + texture2D(uTexture, vTexCoord - ${e}) * uTaps[${t}];\n sum += 2.0 * uTaps[${t}];\n `).join(`
2
- `)}\n gl_FragColor = color / sum;\n }\n `}applyToForWebgl(e){e.passes++,this.width=e.sourceWidth,this.horizontal=!0,this.dW=Math.round(this.width*this.scaleX),this.dH=e.sourceHeight,this.tempScale=this.dW/this.width,this.taps=this.getTaps(),e.destinationWidth=this.dW,super.applyTo(e),e.sourceWidth=e.destinationWidth,this.height=e.sourceHeight,this.horizontal=!1,this.dH=Math.round(this.height*this.scaleY),this.tempScale=this.dH/this.height,this.taps=this.getTaps(),e.destinationHeight=this.dH,super.applyTo(e),e.sourceHeight=e.destinationHeight}applyTo(e){r(e)?this.applyToForWebgl(e):this.applyTo2d(e)}isNeutralState(){return this.scaleX===1&&this.scaleY===1}lanczosCreate(e){return t=>{if(t>=e||t<=-e)return 0;if(t<1.1920929e-7&&t>-1.1920929e-7)return 1;let n=(t*=Math.PI)/e;return Math.sin(t)/t*Math.sin(n)/n}}applyTo2d(e){let t=e.imageData,n=this.scaleX,r=this.scaleY;this.rcpScaleX=1/n,this.rcpScaleY=1/r;let i=t.width,a=t.height,o=Math.round(i*n),s=Math.round(a*r),c;c=this.resizeType===`sliceHack`?this.sliceByTwo(e,i,a,o,s):this.resizeType===`hermite`?this.hermiteFastResize(e,i,a,o,s):this.resizeType===`bilinear`?this.bilinearFiltering(e,i,a,o,s):this.resizeType===`lanczos`?this.lanczosResize(e,i,a,o,s):new ImageData(o,s),e.imageData=c}sliceByTwo(e,t,r,i,a){let o=e.imageData,s=.5,c=!1,l=!1,u=t*s,d=r*s,f=e.filterBackend.resources,p=0,m=0,h=t,g=0;f.sliceByTwo||(f.sliceByTwo=n());let _=f.sliceByTwo;(_.width<1.5*t||_.height<r)&&(_.width=1.5*t,_.height=r);let v=_.getContext(`2d`);for(v.clearRect(0,0,1.5*t,r),v.putImageData(o,0,0),i=Math.floor(i),a=Math.floor(a);!c||!l;)t=u,r=d,i<Math.floor(u*s)?u=Math.floor(u*s):(u=i,c=!0),a<Math.floor(d*s)?d=Math.floor(d*s):(d=a,l=!0),v.drawImage(_,p,m,t,r,h,g,u,d),p=h,m=g,g+=d;return v.getImageData(p,m,i,a)}lanczosResize(e,t,n,r,i){let a=e.imageData.data,o=e.ctx.createImageData(r,i),s=o.data,c=this.lanczosCreate(this.lanczosLobes),l=this.rcpScaleX,u=this.rcpScaleY,d=2/this.rcpScaleX,f=2/this.rcpScaleY,p=Math.ceil(l*this.lanczosLobes/2),m=Math.ceil(u*this.lanczosLobes/2),h={},g={x:0,y:0},_={x:0,y:0};return function e(v){let y,b,x,S,C,w,T,E,D,O,k;for(g.x=(v+.5)*l,_.x=Math.floor(g.x),y=0;y<i;y++){for(g.y=(y+.5)*u,_.y=Math.floor(g.y),C=0,w=0,T=0,E=0,D=0,b=_.x-p;b<=_.x+p;b++)if(!(b<0||b>=t)){O=Math.floor(1e3*Math.abs(b-g.x)),h[O]||(h[O]={});for(let e=_.y-m;e<=_.y+m;e++)e<0||e>=n||(k=Math.floor(1e3*Math.abs(e-g.y)),h[O][k]||(h[O][k]=c(Math.sqrt((O*d)**2+(k*f)**2)/1e3)),x=h[O][k],x>0&&(S=4*(e*t+b),C+=x,w+=x*a[S],T+=x*a[S+1],E+=x*a[S+2],D+=x*a[S+3]))}S=4*(y*r+v),s[S]=w/C,s[S+1]=T/C,s[S+2]=E/C,s[S+3]=D/C}return++v<r?e(v):o}(0)}bilinearFiltering(e,t,n,r,i){let a,o,s,c,l,u,d,f,p,m,h,g,_,v=0,y=this.rcpScaleX,b=this.rcpScaleY,x=4*(t-1),S=e.imageData.data,C=e.ctx.createImageData(r,i),w=C.data;for(d=0;d<i;d++)for(f=0;f<r;f++)for(l=Math.floor(y*f),u=Math.floor(b*d),p=y*f-l,m=b*d-u,_=4*(u*t+l),h=0;h<4;h++)a=S[_+h],o=S[_+4+h],s=S[_+x+h],c=S[_+x+4+h],g=a*(1-p)*(1-m)+o*p*(1-m)+s*m*(1-p)+c*p*m,w[v++]=g;return C}hermiteFastResize(e,t,n,r,i){let a=this.rcpScaleX,o=this.rcpScaleY,s=Math.ceil(a/2),c=Math.ceil(o/2),l=e.imageData.data,u=e.ctx.createImageData(r,i),d=u.data;for(let e=0;e<i;e++)for(let n=0;n<r;n++){let i=4*(n+e*r),u=0,f=0,p=0,m=0,h=0,g=0,_=0,v=(e+.5)*o;for(let r=Math.floor(e*o);r<(e+1)*o;r++){let e=Math.abs(v-(r+.5))/c,i=(n+.5)*a,o=e*e;for(let e=Math.floor(n*a);e<(n+1)*a;e++){let n=Math.abs(i-(e+.5))/s,a=Math.sqrt(o+n*n);a>1&&a<-1||(u=2*a*a*a-3*a*a+1,u>0&&(n=4*(e+r*t),_+=u*l[n+3],p+=u,l[n+3]<255&&(u=u*l[n+3]/250),m+=u*l[n],h+=u*l[n+1],g+=u*l[n+2],f+=u))}}d[i]=m/f,d[i+1]=h/f,d[i+2]=g/f,d[i+3]=_/p}return u}};e(a,`type`,`Resize`),e(a,`defaults`,{resizeType:`hermite`,scaleX:1,scaleY:1,lanczosLobes:3}),e(a,`uniformLocations`,[`uDelta`,`uTaps`]),t.setClass(a);export{a as Resize};
1
+ import{_defineProperty as e}from"../../_virtual/_@oxc-project_runtime@0.126.0/helpers/defineProperty.min.mjs";import{classRegistry as t}from"../ClassRegistry.min.mjs";import{createCanvasElement as n}from"../util/misc/dom.min.mjs";import{isWebGLPipelineState as r}from"./utils.min.mjs";import{BaseFilter as i}from"./BaseFilter.min.mjs";var a=class extends i{sendUniformData(e,t){e.uniform2fv(t.uDelta,this.horizontal?[1/this.width,0]:[0,1/this.height]),e.uniform1fv(t.uTaps,this.taps)}getFilterWindow(){let e=this.tempScale;return Math.ceil(this.lanczosLobes/e)}getCacheKey(){let e=this.getFilterWindow();return`${this.type}_${e}`}getFragmentSource(){let e=this.getFilterWindow();return this.generateShader(e)}getTaps(){let e=this.lanczosCreate(this.lanczosLobes),t=this.tempScale,n=this.getFilterWindow(),r=Array(n);for(let i=1;i<=n;i++)r[i-1]=e(i*t);return r}generateShader(e){let t=Array(e);for(let n=1;n<=e;n++)t[n-1]=`${n}.0 * uDelta`;return`\n precision highp float;\n uniform sampler2D uTexture;\n uniform vec2 uDelta;\n varying vec2 vTexCoord;\n uniform float uTaps[${e}];\n void main() {\n vec4 color = texture2D(uTexture, vTexCoord);\n float sum = 1.0;\n ${t.map((e,t)=>`\n color += texture2D(uTexture, vTexCoord + ${e}) * uTaps[${t}] + texture2D(uTexture, vTexCoord - ${e}) * uTaps[${t}];\n sum += 2.0 * uTaps[${t}];\n `).join(`
2
+ `)}\n gl_FragColor = color / sum;\n }\n `}applyToForWebgl(e){e.passes++,this.width=e.sourceWidth,this.horizontal=!0,this.dW=Math.round(this.width*this.scaleX),this.dH=e.sourceHeight,this.tempScale=this.dW/this.width,this.taps=this.getTaps(),e.destinationWidth=this.dW,super.applyTo(e),e.sourceWidth=e.destinationWidth,this.height=e.sourceHeight,this.horizontal=!1,this.dH=Math.round(this.height*this.scaleY),this.tempScale=this.dH/this.height,this.taps=this.getTaps(),e.destinationHeight=this.dH,super.applyTo(e),e.sourceHeight=e.destinationHeight}applyTo(e){r(e)?this.applyToForWebgl(e):this.applyTo2d(e)}isNeutralState(){return this.scaleX===1&&this.scaleY===1}lanczosCreate(e){return t=>{if(t>=e||t<=-e)return 0;if(t<1.1920929e-7&&t>-1.1920929e-7)return 1;let n=(t*=Math.PI)/e;return Math.sin(t)/t*Math.sin(n)/n}}applyTo2d(e){let t=e.imageData,n=this.scaleX,r=this.scaleY;this.rcpScaleX=1/n,this.rcpScaleY=1/r;let i=t.width,a=t.height,o=Math.round(i*n),s=Math.round(a*r),c;c=this.resizeType===`sliceHack`?this.sliceByTwo(e,i,a,o,s):this.resizeType===`hermite`?this.hermiteFastResize(e,i,a,o,s):this.resizeType===`bilinear`?this.bilinearFiltering(e,i,a,o,s):this.resizeType===`lanczos`?this.lanczosResize(e,i,a,o,s):new ImageData(o,s),e.imageData=c}sliceByTwo(e,t,r,i,a){let o=e.imageData,s=.5,c=!1,l=!1,u=t*s,d=r*s,f=e.filterBackend.resources,p=0,m=0,h=t,g=0;f.sliceByTwo||(f.sliceByTwo=n());let _=f.sliceByTwo;(_.width<1.5*t||_.height<r)&&(_.width=1.5*t,_.height=r);let v=_.getContext(`2d`);for(v.clearRect(0,0,1.5*t,r),v.putImageData(o,0,0),i=Math.floor(i),a=Math.floor(a);!c||!l;)t=u,r=d,i<Math.floor(u*s)?u=Math.floor(u*s):(u=i,c=!0),a<Math.floor(d*s)?d=Math.floor(d*s):(d=a,l=!0),v.drawImage(_,p,m,t,r,h,g,u,d),p=h,m=g,g+=d;return v.getImageData(p,m,i,a)}lanczosResize(e,t,n,r,i){let a=e.imageData.data,o=e.ctx.createImageData(r,i),s=o.data,c=this.lanczosCreate(this.lanczosLobes),l=this.rcpScaleX,u=this.rcpScaleY,d=2/this.rcpScaleX,f=2/this.rcpScaleY,p=Math.ceil(l*this.lanczosLobes/2),m=Math.ceil(u*this.lanczosLobes/2),h={},g={x:0,y:0},_={x:0,y:0};return function e(v){let y,b,x,S,C,w,T,E,D,O,k;for(g.x=(v+.5)*l,_.x=Math.floor(g.x),y=0;y<i;y++){for(g.y=(y+.5)*u,_.y=Math.floor(g.y),C=0,w=0,T=0,E=0,D=0,b=_.x-p;b<=_.x+p;b++)if(!(b<0||b>=t)){O=Math.floor(1e3*Math.abs(b-g.x)),h[O]||(h[O]={});for(let e=_.y-m;e<=_.y+m;e++)e<0||e>=n||(k=Math.floor(1e3*Math.abs(e-g.y)),h[O][k]||(h[O][k]=c(Math.sqrt((O*d)**2+(k*f)**2)/1e3)),x=h[O][k],x>0&&(S=4*(e*t+b),C+=x,w+=x*a[S],T+=x*a[S+1],E+=x*a[S+2],D+=x*a[S+3]))}S=4*(y*r+v),s[S]=w/C,s[S+1]=T/C,s[S+2]=E/C,s[S+3]=D/C}return++v<r?e(v):o}(0)}bilinearFiltering(e,t,n,r,i){let a,o,s,c,l,u,d,f,p,m,h,g,_,v=0,y=this.rcpScaleX,b=this.rcpScaleY,x=4*(t-1),S=e.imageData.data,C=e.ctx.createImageData(r,i),w=C.data;for(d=0;d<i;d++)for(f=0;f<r;f++)for(l=Math.floor(y*f),u=Math.floor(b*d),p=y*f-l,m=b*d-u,_=4*(u*t+l),h=0;h<4;h++)a=S[_+h],o=S[_+4+h],s=S[_+x+h],c=S[_+x+4+h],g=a*(1-p)*(1-m)+o*p*(1-m)+s*m*(1-p)+c*p*m,w[v++]=g;return C}hermiteFastResize(e,t,n,r,i){let a=this.rcpScaleX,o=this.rcpScaleY,s=Math.ceil(a/2),c=Math.ceil(o/2),l=e.imageData.data,u=e.ctx.createImageData(r,i),d=u.data;for(let e=0;e<i;e++)for(let n=0;n<r;n++){let i=4*(n+e*r),u,f=0,p=0,m=0,h=0,g=0,_=0,v=(e+.5)*o;for(let r=Math.floor(e*o);r<(e+1)*o;r++){let e=Math.abs(v-(r+.5))/c,i=(n+.5)*a,o=e*e;for(let e=Math.floor(n*a);e<(n+1)*a;e++){let n=Math.abs(i-(e+.5))/s,a=Math.sqrt(o+n*n);a>1&&a<-1||(u=2*a*a*a-3*a*a+1,u>0&&(n=4*(e+r*t),_+=u*l[n+3],p+=u,l[n+3]<255&&(u=u*l[n+3]/250),m+=u*l[n],h+=u*l[n+1],g+=u*l[n+2],f+=u))}}d[i]=m/f,d[i+1]=h/f,d[i+2]=g/f,d[i+3]=_/p}return u}};e(a,`type`,`Resize`),e(a,`defaults`,{resizeType:`hermite`,scaleX:1,scaleY:1,lanczosLobes:3}),e(a,`uniformLocations`,[`uDelta`,`uTaps`]),t.setClass(a);export{a as Resize};
3
3
  //# sourceMappingURL=Resize.min.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"Resize.min.mjs","names":[],"sources":["../../../src/filters/Resize.ts"],"sourcesContent":["import { BaseFilter } from './BaseFilter';\nimport type {\n T2DPipelineState,\n TWebGLPipelineState,\n TWebGLUniformLocationMap,\n} from './typedefs';\nimport { isWebGLPipelineState } from './utils';\nimport { classRegistry } from '../ClassRegistry';\nimport { createCanvasElement } from '../util/misc/dom';\nimport type { XY } from '../Point';\n\nexport type TResizeType = 'bilinear' | 'hermite' | 'sliceHack' | 'lanczos';\n\nexport type ResizeOwnProps = {\n resizeType: TResizeType;\n scaleX: number;\n scaleY: number;\n lanczosLobes: number;\n};\n\nexport type ResizeSerializedProps = ResizeOwnProps;\n\nexport const resizeDefaultValues: ResizeOwnProps = {\n resizeType: 'hermite',\n scaleX: 1,\n scaleY: 1,\n lanczosLobes: 3,\n};\n\ntype ResizeDuring2DResize = Resize & {\n rcpScaleX: number;\n rcpScaleY: number;\n};\n\ntype ResizeDuringWEBGLResize = Resize & {\n rcpScaleX: number;\n rcpScaleY: number;\n horizontal: boolean;\n width: number;\n height: number;\n taps: number[];\n tempScale: number;\n dH: number;\n dW: number;\n};\n\n/**\n * Resize image filter class\n * @example\n * const filter = new Resize();\n * object.filters.push(filter);\n * object.applyFilters(canvas.renderAll.bind(canvas));\n */\nexport class Resize extends BaseFilter<'Resize', ResizeOwnProps> {\n /**\n * Resize type\n * for webgl resizeType is just lanczos, for canvas2d can be:\n * bilinear, hermite, sliceHack, lanczos.\n */\n declare resizeType: ResizeOwnProps['resizeType'];\n\n /**\n * Scale factor for resizing, x axis\n * @param {Number} scaleX\n */\n declare scaleX: ResizeOwnProps['scaleX'];\n\n /**\n * Scale factor for resizing, y axis\n * @param {Number} scaleY\n */\n declare scaleY: ResizeOwnProps['scaleY'];\n\n /**\n * LanczosLobes parameter for lanczos filter, valid for resizeType lanczos\n * @param {Number} lanczosLobes\n */\n declare lanczosLobes: ResizeOwnProps['lanczosLobes'];\n\n static type = 'Resize';\n\n static defaults = resizeDefaultValues;\n\n static uniformLocations = ['uDelta', 'uTaps'];\n\n /**\n * Send data from this filter to its shader program's uniforms.\n *\n * @param {WebGLRenderingContext} gl The GL canvas context used to compile this filter's shader.\n * @param {Object} uniformLocations A map of string uniform names to WebGLUniformLocation objects\n */\n sendUniformData(\n this: ResizeDuringWEBGLResize,\n gl: WebGLRenderingContext,\n uniformLocations: TWebGLUniformLocationMap,\n ) {\n gl.uniform2fv(\n uniformLocations.uDelta,\n this.horizontal ? [1 / this.width, 0] : [0, 1 / this.height],\n );\n gl.uniform1fv(uniformLocations.uTaps, this.taps);\n }\n\n getFilterWindow(this: ResizeDuringWEBGLResize) {\n const scale = this.tempScale;\n return Math.ceil(this.lanczosLobes / scale);\n }\n\n getCacheKey(this: ResizeDuringWEBGLResize): string {\n const filterWindow = this.getFilterWindow();\n return `${this.type}_${filterWindow}`;\n }\n\n getFragmentSource(this: ResizeDuringWEBGLResize): string {\n const filterWindow = this.getFilterWindow();\n return this.generateShader(filterWindow);\n }\n\n getTaps(this: ResizeDuringWEBGLResize) {\n const lobeFunction = this.lanczosCreate(this.lanczosLobes),\n scale = this.tempScale,\n filterWindow = this.getFilterWindow(),\n taps = new Array(filterWindow);\n for (let i = 1; i <= filterWindow; i++) {\n taps[i - 1] = lobeFunction(i * scale);\n }\n return taps;\n }\n\n /**\n * Generate vertex and shader sources from the necessary steps numbers\n * @param {Number} filterWindow\n */\n generateShader(filterWindow: number) {\n const offsets = new Array(filterWindow);\n for (let i = 1; i <= filterWindow; i++) {\n offsets[i - 1] = `${i}.0 * uDelta`;\n }\n return `\n precision highp float;\n uniform sampler2D uTexture;\n uniform vec2 uDelta;\n varying vec2 vTexCoord;\n uniform float uTaps[${filterWindow}];\n void main() {\n vec4 color = texture2D(uTexture, vTexCoord);\n float sum = 1.0;\n ${offsets\n .map(\n (offset, i) => `\n color += texture2D(uTexture, vTexCoord + ${offset}) * uTaps[${i}] + texture2D(uTexture, vTexCoord - ${offset}) * uTaps[${i}];\n sum += 2.0 * uTaps[${i}];\n `,\n )\n .join('\\n')}\n gl_FragColor = color / sum;\n }\n `;\n }\n\n applyToForWebgl(this: ResizeDuringWEBGLResize, options: TWebGLPipelineState) {\n options.passes++;\n this.width = options.sourceWidth;\n this.horizontal = true;\n this.dW = Math.round(this.width * this.scaleX);\n this.dH = options.sourceHeight;\n this.tempScale = this.dW / this.width;\n this.taps = this.getTaps();\n options.destinationWidth = this.dW;\n super.applyTo(options);\n options.sourceWidth = options.destinationWidth;\n\n this.height = options.sourceHeight;\n this.horizontal = false;\n this.dH = Math.round(this.height * this.scaleY);\n this.tempScale = this.dH / this.height;\n this.taps = this.getTaps();\n options.destinationHeight = this.dH;\n super.applyTo(options);\n options.sourceHeight = options.destinationHeight;\n }\n\n /**\n * Apply the resize filter to the image\n * Determines whether to use WebGL or Canvas2D based on the options.webgl flag.\n *\n * @param {Object} options\n * @param {Number} options.passes The number of filters remaining to be executed\n * @param {Boolean} options.webgl Whether to use webgl to render the filter.\n * @param {WebGLTexture} options.sourceTexture The texture setup as the source to be filtered.\n * @param {WebGLTexture} options.targetTexture The texture where filtered output should be drawn.\n * @param {WebGLRenderingContext} options.context The GL context used for rendering.\n * @param {Object} options.programCache A map of compiled shader programs, keyed by filter type.\n */\n applyTo(options: TWebGLPipelineState | T2DPipelineState) {\n if (isWebGLPipelineState(options)) {\n (this as unknown as ResizeDuringWEBGLResize).applyToForWebgl(options);\n } else {\n (this as unknown as ResizeDuring2DResize).applyTo2d(options);\n }\n }\n\n isNeutralState() {\n return this.scaleX === 1 && this.scaleY === 1;\n }\n\n lanczosCreate(lobes: number) {\n return (x: number) => {\n if (x >= lobes || x <= -lobes) {\n return 0.0;\n }\n if (x < 1.1920929e-7 && x > -1.1920929e-7) {\n return 1.0;\n }\n x *= Math.PI;\n const xx = x / lobes;\n return ((Math.sin(x) / x) * Math.sin(xx)) / xx;\n };\n }\n\n applyTo2d(this: ResizeDuring2DResize, options: T2DPipelineState) {\n const imageData = options.imageData,\n scaleX = this.scaleX,\n scaleY = this.scaleY;\n\n this.rcpScaleX = 1 / scaleX;\n this.rcpScaleY = 1 / scaleY;\n\n const oW = imageData.width;\n const oH = imageData.height;\n const dW = Math.round(oW * scaleX);\n const dH = Math.round(oH * scaleY);\n let newData: ImageData;\n\n if (this.resizeType === 'sliceHack') {\n newData = this.sliceByTwo(options, oW, oH, dW, dH);\n } else if (this.resizeType === 'hermite') {\n newData = this.hermiteFastResize(options, oW, oH, dW, dH);\n } else if (this.resizeType === 'bilinear') {\n newData = this.bilinearFiltering(options, oW, oH, dW, dH);\n } else if (this.resizeType === 'lanczos') {\n newData = this.lanczosResize(options, oW, oH, dW, dH);\n } else {\n // this should never trigger, is here just for safety net.\n newData = new ImageData(dW, dH);\n }\n options.imageData = newData;\n }\n\n /**\n * Filter sliceByTwo\n * @param {Object} canvasEl Canvas element to apply filter to\n * @param {Number} oW Original Width\n * @param {Number} oH Original Height\n * @param {Number} dW Destination Width\n * @param {Number} dH Destination Height\n * @returns {ImageData}\n */\n sliceByTwo(\n options: T2DPipelineState,\n oW: number,\n oH: number,\n dW: number,\n dH: number,\n ) {\n const imageData = options.imageData;\n const mult = 0.5;\n let doneW = false;\n let doneH = false;\n let stepW = oW * mult;\n let stepH = oH * mult;\n const resources = options.filterBackend.resources;\n let sX = 0;\n let sY = 0;\n const dX = oW;\n let dY = 0;\n if (!resources.sliceByTwo) {\n resources.sliceByTwo = createCanvasElement();\n }\n const tmpCanvas = resources.sliceByTwo;\n if (tmpCanvas.width < oW * 1.5 || tmpCanvas.height < oH) {\n tmpCanvas.width = oW * 1.5;\n tmpCanvas.height = oH;\n }\n const ctx = tmpCanvas.getContext('2d')!;\n ctx.clearRect(0, 0, oW * 1.5, oH);\n ctx.putImageData(imageData, 0, 0);\n\n dW = Math.floor(dW);\n dH = Math.floor(dH);\n\n while (!doneW || !doneH) {\n oW = stepW;\n oH = stepH;\n if (dW < Math.floor(stepW * mult)) {\n stepW = Math.floor(stepW * mult);\n } else {\n stepW = dW;\n doneW = true;\n }\n if (dH < Math.floor(stepH * mult)) {\n stepH = Math.floor(stepH * mult);\n } else {\n stepH = dH;\n doneH = true;\n }\n ctx.drawImage(tmpCanvas, sX, sY, oW, oH, dX, dY, stepW, stepH);\n sX = dX;\n sY = dY;\n dY += stepH;\n }\n return ctx.getImageData(sX, sY, dW, dH);\n }\n\n /**\n * Filter lanczosResize\n * @param {Object} canvasEl Canvas element to apply filter to\n * @param {Number} oW Original Width\n * @param {Number} oH Original Height\n * @param {Number} dW Destination Width\n * @param {Number} dH Destination Height\n * @returns {ImageData}\n */\n lanczosResize(\n this: ResizeDuring2DResize,\n options: T2DPipelineState,\n oW: number,\n oH: number,\n dW: number,\n dH: number,\n ): ImageData {\n function process(u: number): ImageData {\n let v, i, weight, idx, a, red, green, blue, alpha, fX, fY;\n center.x = (u + 0.5) * ratioX;\n icenter.x = Math.floor(center.x);\n for (v = 0; v < dH; v++) {\n center.y = (v + 0.5) * ratioY;\n icenter.y = Math.floor(center.y);\n a = 0;\n red = 0;\n green = 0;\n blue = 0;\n alpha = 0;\n for (i = icenter.x - range2X; i <= icenter.x + range2X; i++) {\n if (i < 0 || i >= oW) {\n continue;\n }\n fX = Math.floor(1000 * Math.abs(i - center.x));\n if (!cacheLanc[fX]) {\n cacheLanc[fX] = {};\n }\n for (let j = icenter.y - range2Y; j <= icenter.y + range2Y; j++) {\n if (j < 0 || j >= oH) {\n continue;\n }\n fY = Math.floor(1000 * Math.abs(j - center.y));\n if (!cacheLanc[fX][fY]) {\n cacheLanc[fX][fY] = lanczos(\n Math.sqrt(\n Math.pow(fX * rcpRatioX, 2) + Math.pow(fY * rcpRatioY, 2),\n ) / 1000,\n );\n }\n weight = cacheLanc[fX][fY];\n if (weight > 0) {\n idx = (j * oW + i) * 4;\n a += weight;\n red += weight * srcData[idx];\n green += weight * srcData[idx + 1];\n blue += weight * srcData[idx + 2];\n alpha += weight * srcData[idx + 3];\n }\n }\n }\n idx = (v * dW + u) * 4;\n destData[idx] = red / a;\n destData[idx + 1] = green / a;\n destData[idx + 2] = blue / a;\n destData[idx + 3] = alpha / a;\n }\n\n if (++u < dW) {\n return process(u);\n } else {\n return destImg;\n }\n }\n\n const srcData = options.imageData.data,\n destImg = options.ctx.createImageData(dW, dH),\n destData = destImg.data,\n lanczos = this.lanczosCreate(this.lanczosLobes),\n ratioX = this.rcpScaleX,\n ratioY = this.rcpScaleY,\n rcpRatioX = 2 / this.rcpScaleX,\n rcpRatioY = 2 / this.rcpScaleY,\n range2X = Math.ceil((ratioX * this.lanczosLobes) / 2),\n range2Y = Math.ceil((ratioY * this.lanczosLobes) / 2),\n cacheLanc: Record<number, Record<number, number>> = {},\n center: XY = { x: 0, y: 0 },\n icenter: XY = { x: 0, y: 0 };\n\n return process(0);\n }\n\n /**\n * bilinearFiltering\n * @param {Object} canvasEl Canvas element to apply filter to\n * @param {Number} oW Original Width\n * @param {Number} oH Original Height\n * @param {Number} dW Destination Width\n * @param {Number} dH Destination Height\n * @returns {ImageData}\n */\n bilinearFiltering(\n this: ResizeDuring2DResize,\n options: T2DPipelineState,\n oW: number,\n oH: number,\n dW: number,\n dH: number,\n ) {\n let a;\n let b;\n let c;\n let d;\n let x;\n let y;\n let i;\n let j;\n let xDiff;\n let yDiff;\n let chnl;\n let color;\n let offset = 0;\n let origPix;\n const ratioX = this.rcpScaleX;\n const ratioY = this.rcpScaleY;\n const w4 = 4 * (oW - 1);\n const img = options.imageData;\n const pixels = img.data;\n const destImage = options.ctx.createImageData(dW, dH);\n const destPixels = destImage.data;\n for (i = 0; i < dH; i++) {\n for (j = 0; j < dW; j++) {\n x = Math.floor(ratioX * j);\n y = Math.floor(ratioY * i);\n xDiff = ratioX * j - x;\n yDiff = ratioY * i - y;\n origPix = 4 * (y * oW + x);\n\n for (chnl = 0; chnl < 4; chnl++) {\n a = pixels[origPix + chnl];\n b = pixels[origPix + 4 + chnl];\n c = pixels[origPix + w4 + chnl];\n d = pixels[origPix + w4 + 4 + chnl];\n color =\n a * (1 - xDiff) * (1 - yDiff) +\n b * xDiff * (1 - yDiff) +\n c * yDiff * (1 - xDiff) +\n d * xDiff * yDiff;\n destPixels[offset++] = color;\n }\n }\n }\n return destImage;\n }\n\n /**\n * hermiteFastResize\n * @param {Object} canvasEl Canvas element to apply filter to\n * @param {Number} oW Original Width\n * @param {Number} oH Original Height\n * @param {Number} dW Destination Width\n * @param {Number} dH Destination Height\n * @returns {ImageData}\n */\n hermiteFastResize(\n this: ResizeDuring2DResize,\n options: T2DPipelineState,\n oW: number,\n oH: number,\n dW: number,\n dH: number,\n ) {\n const ratioW = this.rcpScaleX,\n ratioH = this.rcpScaleY,\n ratioWHalf = Math.ceil(ratioW / 2),\n ratioHHalf = Math.ceil(ratioH / 2),\n img = options.imageData,\n data = img.data,\n img2 = options.ctx.createImageData(dW, dH),\n data2 = img2.data;\n for (let j = 0; j < dH; j++) {\n for (let i = 0; i < dW; i++) {\n const x2 = (i + j * dW) * 4;\n let weight = 0;\n let weights = 0;\n let weightsAlpha = 0;\n let gxR = 0;\n let gxG = 0;\n let gxB = 0;\n let gxA = 0;\n const centerY = (j + 0.5) * ratioH;\n for (let yy = Math.floor(j * ratioH); yy < (j + 1) * ratioH; yy++) {\n const dy = Math.abs(centerY - (yy + 0.5)) / ratioHHalf,\n centerX = (i + 0.5) * ratioW,\n w0 = dy * dy;\n for (let xx = Math.floor(i * ratioW); xx < (i + 1) * ratioW; xx++) {\n let dx = Math.abs(centerX - (xx + 0.5)) / ratioWHalf;\n const w = Math.sqrt(w0 + dx * dx);\n\n if (w > 1 && w < -1) {\n continue;\n }\n //hermite filter\n weight = 2 * w * w * w - 3 * w * w + 1;\n if (weight > 0) {\n dx = 4 * (xx + yy * oW);\n //alpha\n gxA += weight * data[dx + 3];\n weightsAlpha += weight;\n //colors\n if (data[dx + 3] < 255) {\n weight = (weight * data[dx + 3]) / 250;\n }\n gxR += weight * data[dx];\n gxG += weight * data[dx + 1];\n gxB += weight * data[dx + 2];\n weights += weight;\n }\n }\n }\n data2[x2] = gxR / weights;\n data2[x2 + 1] = gxG / weights;\n data2[x2 + 2] = gxB / weights;\n data2[x2 + 3] = gxA / weightsAlpha;\n }\n }\n return img2;\n }\n}\n\nclassRegistry.setClass(Resize);\n"],"mappings":"+UAqDA,IAAa,EAAb,cAA4B,CAAA,CAsC1B,gBAEE,EACA,EAAA,CAEA,EAAG,WACD,EAAiB,OACjB,KAAK,WAAa,CAAC,EAAI,KAAK,MAAO,EAAA,CAAK,CAAC,EAAG,EAAI,KAAK,OAAA,CAAA,CAEvD,EAAG,WAAW,EAAiB,MAAO,KAAK,KAAA,CAG7C,iBAAA,CACE,IAAM,EAAQ,KAAK,UACnB,OAAO,KAAK,KAAK,KAAK,aAAe,EAAA,CAGvC,aAAA,CACE,IAAM,EAAe,KAAK,iBAAA,CAC1B,MAAO,GAAG,KAAK,KAAA,GAAQ,IAGzB,mBAAA,CACE,IAAM,EAAe,KAAK,iBAAA,CAC1B,OAAO,KAAK,eAAe,EAAA,CAG7B,SAAA,CACE,IAAM,EAAe,KAAK,cAAc,KAAK,aAAA,CAC3C,EAAQ,KAAK,UACb,EAAe,KAAK,iBAAA,CACpB,EAAW,MAAM,EAAA,CACnB,IAAK,IAAI,EAAI,EAAG,GAAK,EAAc,IACjC,EAAK,EAAI,GAAK,EAAa,EAAI,EAAA,CAEjC,OAAO,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I,EACjC,EAAS,IACX,EAAK,GAAK,EAAK,EAAK,GAEpB,GAAO,EAAS,EAAK,EAAK,GAC1B,GAAgB,EAEZ,EAAK,EAAK,GAAK,MACjB,EAAU,EAAS,EAAK,EAAK,GAAM,KAErC,GAAO,EAAS,EAAK,GACrB,GAAO,EAAS,EAAK,EAAK,GAC1B,GAAO,EAAS,EAAK,EAAK,GAC1B,GAAW,KAIjB,EAAM,GAAM,EAAM,EAClB,EAAM,EAAK,GAAK,EAAM,EACtB,EAAM,EAAK,GAAK,EAAM,EACtB,EAAM,EAAK,GAAK,EAAM,EAG1B,OAAO,IAAA,EAAA,EA5cF,OAAO,SAAA,CAAA,EAAA,EAEP,WA3D0C,CACjD,WAAY,UACZ,OAAQ,EACR,OAAQ,EACR,aAAc,EAAA,CAAA,CAAA,EAAA,EAyDP,mBAAmB,CAAC,SAAU,QAAA,CAAA,CA4cvC,EAAc,SAAS,EAAA,CAAA,OAAA,KAAA"}
1
+ {"version":3,"file":"Resize.min.mjs","names":[],"sources":["../../../src/filters/Resize.ts"],"sourcesContent":["import { BaseFilter } from './BaseFilter';\nimport type {\n T2DPipelineState,\n TWebGLPipelineState,\n TWebGLUniformLocationMap,\n} from './typedefs';\nimport { isWebGLPipelineState } from './utils';\nimport { classRegistry } from '../ClassRegistry';\nimport { createCanvasElement } from '../util/misc/dom';\nimport type { XY } from '../Point';\n\nexport type TResizeType = 'bilinear' | 'hermite' | 'sliceHack' | 'lanczos';\n\nexport type ResizeOwnProps = {\n resizeType: TResizeType;\n scaleX: number;\n scaleY: number;\n lanczosLobes: number;\n};\n\nexport type ResizeSerializedProps = ResizeOwnProps;\n\nexport const resizeDefaultValues: ResizeOwnProps = {\n resizeType: 'hermite',\n scaleX: 1,\n scaleY: 1,\n lanczosLobes: 3,\n};\n\ntype ResizeDuring2DResize = Resize & {\n rcpScaleX: number;\n rcpScaleY: number;\n};\n\ntype ResizeDuringWEBGLResize = Resize & {\n rcpScaleX: number;\n rcpScaleY: number;\n horizontal: boolean;\n width: number;\n height: number;\n taps: number[];\n tempScale: number;\n dH: number;\n dW: number;\n};\n\n/**\n * Resize image filter class\n * @example\n * const filter = new Resize();\n * object.filters.push(filter);\n * object.applyFilters(canvas.renderAll.bind(canvas));\n */\nexport class Resize extends BaseFilter<'Resize', ResizeOwnProps> {\n /**\n * Resize type\n * for webgl resizeType is just lanczos, for canvas2d can be:\n * bilinear, hermite, sliceHack, lanczos.\n */\n declare resizeType: ResizeOwnProps['resizeType'];\n\n /**\n * Scale factor for resizing, x axis\n * @param {Number} scaleX\n */\n declare scaleX: ResizeOwnProps['scaleX'];\n\n /**\n * Scale factor for resizing, y axis\n * @param {Number} scaleY\n */\n declare scaleY: ResizeOwnProps['scaleY'];\n\n /**\n * LanczosLobes parameter for lanczos filter, valid for resizeType lanczos\n * @param {Number} lanczosLobes\n */\n declare lanczosLobes: ResizeOwnProps['lanczosLobes'];\n\n static type = 'Resize';\n\n static defaults = resizeDefaultValues;\n\n static uniformLocations = ['uDelta', 'uTaps'];\n\n /**\n * Send data from this filter to its shader program's uniforms.\n *\n * @param {WebGLRenderingContext} gl The GL canvas context used to compile this filter's shader.\n * @param {Object} uniformLocations A map of string uniform names to WebGLUniformLocation objects\n */\n sendUniformData(\n this: ResizeDuringWEBGLResize,\n gl: WebGLRenderingContext,\n uniformLocations: TWebGLUniformLocationMap,\n ) {\n gl.uniform2fv(\n uniformLocations.uDelta,\n this.horizontal ? [1 / this.width, 0] : [0, 1 / this.height],\n );\n gl.uniform1fv(uniformLocations.uTaps, this.taps);\n }\n\n getFilterWindow(this: ResizeDuringWEBGLResize) {\n const scale = this.tempScale;\n return Math.ceil(this.lanczosLobes / scale);\n }\n\n getCacheKey(this: ResizeDuringWEBGLResize): string {\n const filterWindow = this.getFilterWindow();\n return `${this.type}_${filterWindow}`;\n }\n\n getFragmentSource(this: ResizeDuringWEBGLResize): string {\n const filterWindow = this.getFilterWindow();\n return this.generateShader(filterWindow);\n }\n\n getTaps(this: ResizeDuringWEBGLResize) {\n const lobeFunction = this.lanczosCreate(this.lanczosLobes),\n scale = this.tempScale,\n filterWindow = this.getFilterWindow(),\n taps = new Array(filterWindow);\n for (let i = 1; i <= filterWindow; i++) {\n taps[i - 1] = lobeFunction(i * scale);\n }\n return taps;\n }\n\n /**\n * Generate vertex and shader sources from the necessary steps numbers\n * @param {Number} filterWindow\n */\n generateShader(filterWindow: number) {\n const offsets = new Array(filterWindow);\n for (let i = 1; i <= filterWindow; i++) {\n offsets[i - 1] = `${i}.0 * uDelta`;\n }\n return `\n precision highp float;\n uniform sampler2D uTexture;\n uniform vec2 uDelta;\n varying vec2 vTexCoord;\n uniform float uTaps[${filterWindow}];\n void main() {\n vec4 color = texture2D(uTexture, vTexCoord);\n float sum = 1.0;\n ${offsets\n .map(\n (offset, i) => `\n color += texture2D(uTexture, vTexCoord + ${offset}) * uTaps[${i}] + texture2D(uTexture, vTexCoord - ${offset}) * uTaps[${i}];\n sum += 2.0 * uTaps[${i}];\n `,\n )\n .join('\\n')}\n gl_FragColor = color / sum;\n }\n `;\n }\n\n applyToForWebgl(this: ResizeDuringWEBGLResize, options: TWebGLPipelineState) {\n options.passes++;\n this.width = options.sourceWidth;\n this.horizontal = true;\n this.dW = Math.round(this.width * this.scaleX);\n this.dH = options.sourceHeight;\n this.tempScale = this.dW / this.width;\n this.taps = this.getTaps();\n options.destinationWidth = this.dW;\n super.applyTo(options);\n options.sourceWidth = options.destinationWidth;\n\n this.height = options.sourceHeight;\n this.horizontal = false;\n this.dH = Math.round(this.height * this.scaleY);\n this.tempScale = this.dH / this.height;\n this.taps = this.getTaps();\n options.destinationHeight = this.dH;\n super.applyTo(options);\n options.sourceHeight = options.destinationHeight;\n }\n\n /**\n * Apply the resize filter to the image\n * Determines whether to use WebGL or Canvas2D based on the options.webgl flag.\n *\n * @param {Object} options\n * @param {Number} options.passes The number of filters remaining to be executed\n * @param {Boolean} options.webgl Whether to use webgl to render the filter.\n * @param {WebGLTexture} options.sourceTexture The texture setup as the source to be filtered.\n * @param {WebGLTexture} options.targetTexture The texture where filtered output should be drawn.\n * @param {WebGLRenderingContext} options.context The GL context used for rendering.\n * @param {Object} options.programCache A map of compiled shader programs, keyed by filter type.\n */\n applyTo(options: TWebGLPipelineState | T2DPipelineState) {\n if (isWebGLPipelineState(options)) {\n (this as unknown as ResizeDuringWEBGLResize).applyToForWebgl(options);\n } else {\n (this as unknown as ResizeDuring2DResize).applyTo2d(options);\n }\n }\n\n isNeutralState() {\n return this.scaleX === 1 && this.scaleY === 1;\n }\n\n lanczosCreate(lobes: number) {\n return (x: number) => {\n if (x >= lobes || x <= -lobes) {\n return 0.0;\n }\n if (x < 1.1920929e-7 && x > -1.1920929e-7) {\n return 1.0;\n }\n x *= Math.PI;\n const xx = x / lobes;\n return ((Math.sin(x) / x) * Math.sin(xx)) / xx;\n };\n }\n\n applyTo2d(this: ResizeDuring2DResize, options: T2DPipelineState) {\n const imageData = options.imageData,\n scaleX = this.scaleX,\n scaleY = this.scaleY;\n\n this.rcpScaleX = 1 / scaleX;\n this.rcpScaleY = 1 / scaleY;\n\n const oW = imageData.width;\n const oH = imageData.height;\n const dW = Math.round(oW * scaleX);\n const dH = Math.round(oH * scaleY);\n let newData: ImageData;\n\n if (this.resizeType === 'sliceHack') {\n newData = this.sliceByTwo(options, oW, oH, dW, dH);\n } else if (this.resizeType === 'hermite') {\n newData = this.hermiteFastResize(options, oW, oH, dW, dH);\n } else if (this.resizeType === 'bilinear') {\n newData = this.bilinearFiltering(options, oW, oH, dW, dH);\n } else if (this.resizeType === 'lanczos') {\n newData = this.lanczosResize(options, oW, oH, dW, dH);\n } else {\n // this should never trigger, is here just for safety net.\n newData = new ImageData(dW, dH);\n }\n options.imageData = newData;\n }\n\n /**\n * Filter sliceByTwo\n * @param {Object} canvasEl Canvas element to apply filter to\n * @param {Number} oW Original Width\n * @param {Number} oH Original Height\n * @param {Number} dW Destination Width\n * @param {Number} dH Destination Height\n * @returns {ImageData}\n */\n sliceByTwo(\n options: T2DPipelineState,\n oW: number,\n oH: number,\n dW: number,\n dH: number,\n ) {\n const imageData = options.imageData;\n const mult = 0.5;\n let doneW = false;\n let doneH = false;\n let stepW = oW * mult;\n let stepH = oH * mult;\n const resources = options.filterBackend.resources;\n let sX = 0;\n let sY = 0;\n const dX = oW;\n let dY = 0;\n if (!resources.sliceByTwo) {\n resources.sliceByTwo = createCanvasElement();\n }\n const tmpCanvas = resources.sliceByTwo;\n if (tmpCanvas.width < oW * 1.5 || tmpCanvas.height < oH) {\n tmpCanvas.width = oW * 1.5;\n tmpCanvas.height = oH;\n }\n const ctx = tmpCanvas.getContext('2d')!;\n ctx.clearRect(0, 0, oW * 1.5, oH);\n ctx.putImageData(imageData, 0, 0);\n\n dW = Math.floor(dW);\n dH = Math.floor(dH);\n\n while (!doneW || !doneH) {\n oW = stepW;\n oH = stepH;\n if (dW < Math.floor(stepW * mult)) {\n stepW = Math.floor(stepW * mult);\n } else {\n stepW = dW;\n doneW = true;\n }\n if (dH < Math.floor(stepH * mult)) {\n stepH = Math.floor(stepH * mult);\n } else {\n stepH = dH;\n doneH = true;\n }\n ctx.drawImage(tmpCanvas, sX, sY, oW, oH, dX, dY, stepW, stepH);\n sX = dX;\n sY = dY;\n dY += stepH;\n }\n return ctx.getImageData(sX, sY, dW, dH);\n }\n\n /**\n * Filter lanczosResize\n * @param {Object} canvasEl Canvas element to apply filter to\n * @param {Number} oW Original Width\n * @param {Number} oH Original Height\n * @param {Number} dW Destination Width\n * @param {Number} dH Destination Height\n * @returns {ImageData}\n */\n lanczosResize(\n this: ResizeDuring2DResize,\n options: T2DPipelineState,\n oW: number,\n oH: number,\n dW: number,\n dH: number,\n ): ImageData {\n function process(u: number): ImageData {\n let v, i, weight, idx, a, red, green, blue, alpha, fX, fY;\n center.x = (u + 0.5) * ratioX;\n icenter.x = Math.floor(center.x);\n for (v = 0; v < dH; v++) {\n center.y = (v + 0.5) * ratioY;\n icenter.y = Math.floor(center.y);\n a = 0;\n red = 0;\n green = 0;\n blue = 0;\n alpha = 0;\n for (i = icenter.x - range2X; i <= icenter.x + range2X; i++) {\n if (i < 0 || i >= oW) {\n continue;\n }\n fX = Math.floor(1000 * Math.abs(i - center.x));\n if (!cacheLanc[fX]) {\n cacheLanc[fX] = {};\n }\n for (let j = icenter.y - range2Y; j <= icenter.y + range2Y; j++) {\n if (j < 0 || j >= oH) {\n continue;\n }\n fY = Math.floor(1000 * Math.abs(j - center.y));\n if (!cacheLanc[fX][fY]) {\n cacheLanc[fX][fY] = lanczos(\n Math.sqrt(\n Math.pow(fX * rcpRatioX, 2) + Math.pow(fY * rcpRatioY, 2),\n ) / 1000,\n );\n }\n weight = cacheLanc[fX][fY];\n if (weight > 0) {\n idx = (j * oW + i) * 4;\n a += weight;\n red += weight * srcData[idx];\n green += weight * srcData[idx + 1];\n blue += weight * srcData[idx + 2];\n alpha += weight * srcData[idx + 3];\n }\n }\n }\n idx = (v * dW + u) * 4;\n destData[idx] = red / a;\n destData[idx + 1] = green / a;\n destData[idx + 2] = blue / a;\n destData[idx + 3] = alpha / a;\n }\n\n if (++u < dW) {\n return process(u);\n } else {\n return destImg;\n }\n }\n\n const srcData = options.imageData.data,\n destImg = options.ctx.createImageData(dW, dH),\n destData = destImg.data,\n lanczos = this.lanczosCreate(this.lanczosLobes),\n ratioX = this.rcpScaleX,\n ratioY = this.rcpScaleY,\n rcpRatioX = 2 / this.rcpScaleX,\n rcpRatioY = 2 / this.rcpScaleY,\n range2X = Math.ceil((ratioX * this.lanczosLobes) / 2),\n range2Y = Math.ceil((ratioY * this.lanczosLobes) / 2),\n cacheLanc: Record<number, Record<number, number>> = {},\n center: XY = { x: 0, y: 0 },\n icenter: XY = { x: 0, y: 0 };\n\n return process(0);\n }\n\n /**\n * bilinearFiltering\n * @param {Object} canvasEl Canvas element to apply filter to\n * @param {Number} oW Original Width\n * @param {Number} oH Original Height\n * @param {Number} dW Destination Width\n * @param {Number} dH Destination Height\n * @returns {ImageData}\n */\n bilinearFiltering(\n this: ResizeDuring2DResize,\n options: T2DPipelineState,\n oW: number,\n oH: number,\n dW: number,\n dH: number,\n ) {\n let a;\n let b;\n let c;\n let d;\n let x;\n let y;\n let i;\n let j;\n let xDiff;\n let yDiff;\n let chnl;\n let color;\n let offset = 0;\n let origPix;\n const ratioX = this.rcpScaleX;\n const ratioY = this.rcpScaleY;\n const w4 = 4 * (oW - 1);\n const img = options.imageData;\n const pixels = img.data;\n const destImage = options.ctx.createImageData(dW, dH);\n const destPixels = destImage.data;\n for (i = 0; i < dH; i++) {\n for (j = 0; j < dW; j++) {\n x = Math.floor(ratioX * j);\n y = Math.floor(ratioY * i);\n xDiff = ratioX * j - x;\n yDiff = ratioY * i - y;\n origPix = 4 * (y * oW + x);\n\n for (chnl = 0; chnl < 4; chnl++) {\n a = pixels[origPix + chnl];\n b = pixels[origPix + 4 + chnl];\n c = pixels[origPix + w4 + chnl];\n d = pixels[origPix + w4 + 4 + chnl];\n color =\n a * (1 - xDiff) * (1 - yDiff) +\n b * xDiff * (1 - yDiff) +\n c * yDiff * (1 - xDiff) +\n d * xDiff * yDiff;\n destPixels[offset++] = color;\n }\n }\n }\n return destImage;\n }\n\n /**\n * hermiteFastResize\n * @param {Object} canvasEl Canvas element to apply filter to\n * @param {Number} oW Original Width\n * @param {Number} oH Original Height\n * @param {Number} dW Destination Width\n * @param {Number} dH Destination Height\n * @returns {ImageData}\n */\n hermiteFastResize(\n this: ResizeDuring2DResize,\n options: T2DPipelineState,\n oW: number,\n oH: number,\n dW: number,\n dH: number,\n ) {\n const ratioW = this.rcpScaleX,\n ratioH = this.rcpScaleY,\n ratioWHalf = Math.ceil(ratioW / 2),\n ratioHHalf = Math.ceil(ratioH / 2),\n img = options.imageData,\n data = img.data,\n img2 = options.ctx.createImageData(dW, dH),\n data2 = img2.data;\n for (let j = 0; j < dH; j++) {\n for (let i = 0; i < dW; i++) {\n const x2 = (i + j * dW) * 4;\n let weight: number;\n let weights = 0;\n let weightsAlpha = 0;\n let gxR = 0;\n let gxG = 0;\n let gxB = 0;\n let gxA = 0;\n const centerY = (j + 0.5) * ratioH;\n for (let yy = Math.floor(j * ratioH); yy < (j + 1) * ratioH; yy++) {\n const dy = Math.abs(centerY - (yy + 0.5)) / ratioHHalf,\n centerX = (i + 0.5) * ratioW,\n w0 = dy * dy;\n for (let xx = Math.floor(i * ratioW); xx < (i + 1) * ratioW; xx++) {\n let dx = Math.abs(centerX - (xx + 0.5)) / ratioWHalf;\n const w = Math.sqrt(w0 + dx * dx);\n\n if (w > 1 && w < -1) {\n continue;\n }\n //hermite filter\n weight = 2 * w * w * w - 3 * w * w + 1;\n if (weight > 0) {\n dx = 4 * (xx + yy * oW);\n //alpha\n gxA += weight * data[dx + 3];\n weightsAlpha += weight;\n //colors\n if (data[dx + 3] < 255) {\n weight = (weight * data[dx + 3]) / 250;\n }\n gxR += weight * data[dx];\n gxG += weight * data[dx + 1];\n gxB += weight * data[dx + 2];\n weights += weight;\n }\n }\n }\n data2[x2] = gxR / weights;\n data2[x2 + 1] = gxG / weights;\n data2[x2 + 2] = gxB / weights;\n data2[x2 + 3] = gxA / weightsAlpha;\n }\n }\n return img2;\n }\n}\n\nclassRegistry.setClass(Resize);\n"],"mappings":"+UAqDA,IAAa,EAAb,cAA4B,CAAA,CAsC1B,gBAEE,EACA,EAAA,CAEA,EAAG,WACD,EAAiB,OACjB,KAAK,WAAa,CAAC,EAAI,KAAK,MAAO,EAAA,CAAK,CAAC,EAAG,EAAI,KAAK,OAAA,CAAA,CAEvD,EAAG,WAAW,EAAiB,MAAO,KAAK,KAAA,CAG7C,iBAAA,CACE,IAAM,EAAQ,KAAK,UACnB,OAAO,KAAK,KAAK,KAAK,aAAe,EAAA,CAGvC,aAAA,CACE,IAAM,EAAe,KAAK,iBAAA,CAC1B,MAAO,GAAG,KAAK,KAAA,GAAQ,IAGzB,mBAAA,CACE,IAAM,EAAe,KAAK,iBAAA,CAC1B,OAAO,KAAK,eAAe,EAAA,CAG7B,SAAA,CACE,IAAM,EA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EAAQ,IAAM,CACjE,IAAI,EAAK,KAAK,IAAI,GAAW,EAAK,IAAA,CAAQ,EACpC,EAAI,KAAK,KAAK,EAAK,EAAK,EAAA,CAE1B,EAAI,GAAK,EAAA,KAIb,EAAS,EAAI,EAAI,EAAI,EAAI,EAAI,EAAI,EAAI,EACjC,EAAS,IACX,EAAK,GAAK,EAAK,EAAK,GAEpB,GAAO,EAAS,EAAK,EAAK,GAC1B,GAAgB,EAEZ,EAAK,EAAK,GAAK,MACjB,EAAU,EAAS,EAAK,EAAK,GAAM,KAErC,GAAO,EAAS,EAAK,GACrB,GAAO,EAAS,EAAK,EAAK,GAC1B,GAAO,EAAS,EAAK,EAAK,GAC1B,GAAW,KAIjB,EAAM,GAAM,EAAM,EAClB,EAAM,EAAK,GAAK,EAAM,EACtB,EAAM,EAAK,GAAK,EAAM,EACtB,EAAM,EAAK,GAAK,EAAM,EAG1B,OAAO,IAAA,EAAA,EA5cF,OAAO,SAAA,CAAA,EAAA,EAEP,WA3D0C,CACjD,WAAY,UACZ,OAAQ,EACR,OAAQ,EACR,aAAc,EAAA,CAAA,CAAA,EAAA,EAyDP,mBAAmB,CAAC,SAAU,QAAA,CAAA,CA4cvC,EAAc,SAAS,EAAA,CAAA,OAAA,KAAA"}
@@ -1,4 +1,4 @@
1
- import { _defineProperty } from "../../_virtual/_@oxc-project_runtime@0.122.0/helpers/defineProperty.mjs";
1
+ import { _defineProperty } from "../../_virtual/_@oxc-project_runtime@0.126.0/helpers/defineProperty.mjs";
2
2
  import { classRegistry } from "../ClassRegistry.mjs";
3
3
  import { createCanvasElement } from "../util/misc/dom.mjs";
4
4
  import { isWebGLPipelineState } from "./utils.mjs";
@@ -304,7 +304,7 @@ var Resize = class extends BaseFilter {
304
304
  const ratioW = this.rcpScaleX, ratioH = this.rcpScaleY, ratioWHalf = Math.ceil(ratioW / 2), ratioHHalf = Math.ceil(ratioH / 2), data = options.imageData.data, img2 = options.ctx.createImageData(dW, dH), data2 = img2.data;
305
305
  for (let j = 0; j < dH; j++) for (let i = 0; i < dW; i++) {
306
306
  const x2 = (i + j * dW) * 4;
307
- let weight = 0;
307
+ let weight;
308
308
  let weights = 0;
309
309
  let weightsAlpha = 0;
310
310
  let gxR = 0;
@@ -1 +1 @@
1
- {"version":3,"file":"Resize.mjs","names":[],"sources":["../../../src/filters/Resize.ts"],"sourcesContent":["import { BaseFilter } from './BaseFilter';\nimport type {\n T2DPipelineState,\n TWebGLPipelineState,\n TWebGLUniformLocationMap,\n} from './typedefs';\nimport { isWebGLPipelineState } from './utils';\nimport { classRegistry } from '../ClassRegistry';\nimport { createCanvasElement } from '../util/misc/dom';\nimport type { XY } from '../Point';\n\nexport type TResizeType = 'bilinear' | 'hermite' | 'sliceHack' | 'lanczos';\n\nexport type ResizeOwnProps = {\n resizeType: TResizeType;\n scaleX: number;\n scaleY: number;\n lanczosLobes: number;\n};\n\nexport type ResizeSerializedProps = ResizeOwnProps;\n\nexport const resizeDefaultValues: ResizeOwnProps = {\n resizeType: 'hermite',\n scaleX: 1,\n scaleY: 1,\n lanczosLobes: 3,\n};\n\ntype ResizeDuring2DResize = Resize & {\n rcpScaleX: number;\n rcpScaleY: number;\n};\n\ntype ResizeDuringWEBGLResize = Resize & {\n rcpScaleX: number;\n rcpScaleY: number;\n horizontal: boolean;\n width: number;\n height: number;\n taps: number[];\n tempScale: number;\n dH: number;\n dW: number;\n};\n\n/**\n * Resize image filter class\n * @example\n * const filter = new Resize();\n * object.filters.push(filter);\n * object.applyFilters(canvas.renderAll.bind(canvas));\n */\nexport class Resize extends BaseFilter<'Resize', ResizeOwnProps> {\n /**\n * Resize type\n * for webgl resizeType is just lanczos, for canvas2d can be:\n * bilinear, hermite, sliceHack, lanczos.\n */\n declare resizeType: ResizeOwnProps['resizeType'];\n\n /**\n * Scale factor for resizing, x axis\n * @param {Number} scaleX\n */\n declare scaleX: ResizeOwnProps['scaleX'];\n\n /**\n * Scale factor for resizing, y axis\n * @param {Number} scaleY\n */\n declare scaleY: ResizeOwnProps['scaleY'];\n\n /**\n * LanczosLobes parameter for lanczos filter, valid for resizeType lanczos\n * @param {Number} lanczosLobes\n */\n declare lanczosLobes: ResizeOwnProps['lanczosLobes'];\n\n static type = 'Resize';\n\n static defaults = resizeDefaultValues;\n\n static uniformLocations = ['uDelta', 'uTaps'];\n\n /**\n * Send data from this filter to its shader program's uniforms.\n *\n * @param {WebGLRenderingContext} gl The GL canvas context used to compile this filter's shader.\n * @param {Object} uniformLocations A map of string uniform names to WebGLUniformLocation objects\n */\n sendUniformData(\n this: ResizeDuringWEBGLResize,\n gl: WebGLRenderingContext,\n uniformLocations: TWebGLUniformLocationMap,\n ) {\n gl.uniform2fv(\n uniformLocations.uDelta,\n this.horizontal ? [1 / this.width, 0] : [0, 1 / this.height],\n );\n gl.uniform1fv(uniformLocations.uTaps, this.taps);\n }\n\n getFilterWindow(this: ResizeDuringWEBGLResize) {\n const scale = this.tempScale;\n return Math.ceil(this.lanczosLobes / scale);\n }\n\n getCacheKey(this: ResizeDuringWEBGLResize): string {\n const filterWindow = this.getFilterWindow();\n return `${this.type}_${filterWindow}`;\n }\n\n getFragmentSource(this: ResizeDuringWEBGLResize): string {\n const filterWindow = this.getFilterWindow();\n return this.generateShader(filterWindow);\n }\n\n getTaps(this: ResizeDuringWEBGLResize) {\n const lobeFunction = this.lanczosCreate(this.lanczosLobes),\n scale = this.tempScale,\n filterWindow = this.getFilterWindow(),\n taps = new Array(filterWindow);\n for (let i = 1; i <= filterWindow; i++) {\n taps[i - 1] = lobeFunction(i * scale);\n }\n return taps;\n }\n\n /**\n * Generate vertex and shader sources from the necessary steps numbers\n * @param {Number} filterWindow\n */\n generateShader(filterWindow: number) {\n const offsets = new Array(filterWindow);\n for (let i = 1; i <= filterWindow; i++) {\n offsets[i - 1] = `${i}.0 * uDelta`;\n }\n return `\n precision highp float;\n uniform sampler2D uTexture;\n uniform vec2 uDelta;\n varying vec2 vTexCoord;\n uniform float uTaps[${filterWindow}];\n void main() {\n vec4 color = texture2D(uTexture, vTexCoord);\n float sum = 1.0;\n ${offsets\n .map(\n (offset, i) => `\n color += texture2D(uTexture, vTexCoord + ${offset}) * uTaps[${i}] + texture2D(uTexture, vTexCoord - ${offset}) * uTaps[${i}];\n sum += 2.0 * uTaps[${i}];\n `,\n )\n .join('\\n')}\n gl_FragColor = color / sum;\n }\n `;\n }\n\n applyToForWebgl(this: ResizeDuringWEBGLResize, options: TWebGLPipelineState) {\n options.passes++;\n this.width = options.sourceWidth;\n this.horizontal = true;\n this.dW = Math.round(this.width * this.scaleX);\n this.dH = options.sourceHeight;\n this.tempScale = this.dW / this.width;\n this.taps = this.getTaps();\n options.destinationWidth = this.dW;\n super.applyTo(options);\n options.sourceWidth = options.destinationWidth;\n\n this.height = options.sourceHeight;\n this.horizontal = false;\n this.dH = Math.round(this.height * this.scaleY);\n this.tempScale = this.dH / this.height;\n this.taps = this.getTaps();\n options.destinationHeight = this.dH;\n super.applyTo(options);\n options.sourceHeight = options.destinationHeight;\n }\n\n /**\n * Apply the resize filter to the image\n * Determines whether to use WebGL or Canvas2D based on the options.webgl flag.\n *\n * @param {Object} options\n * @param {Number} options.passes The number of filters remaining to be executed\n * @param {Boolean} options.webgl Whether to use webgl to render the filter.\n * @param {WebGLTexture} options.sourceTexture The texture setup as the source to be filtered.\n * @param {WebGLTexture} options.targetTexture The texture where filtered output should be drawn.\n * @param {WebGLRenderingContext} options.context The GL context used for rendering.\n * @param {Object} options.programCache A map of compiled shader programs, keyed by filter type.\n */\n applyTo(options: TWebGLPipelineState | T2DPipelineState) {\n if (isWebGLPipelineState(options)) {\n (this as unknown as ResizeDuringWEBGLResize).applyToForWebgl(options);\n } else {\n (this as unknown as ResizeDuring2DResize).applyTo2d(options);\n }\n }\n\n isNeutralState() {\n return this.scaleX === 1 && this.scaleY === 1;\n }\n\n lanczosCreate(lobes: number) {\n return (x: number) => {\n if (x >= lobes || x <= -lobes) {\n return 0.0;\n }\n if (x < 1.1920929e-7 && x > -1.1920929e-7) {\n return 1.0;\n }\n x *= Math.PI;\n const xx = x / lobes;\n return ((Math.sin(x) / x) * Math.sin(xx)) / xx;\n };\n }\n\n applyTo2d(this: ResizeDuring2DResize, options: T2DPipelineState) {\n const imageData = options.imageData,\n scaleX = this.scaleX,\n scaleY = this.scaleY;\n\n this.rcpScaleX = 1 / scaleX;\n this.rcpScaleY = 1 / scaleY;\n\n const oW = imageData.width;\n const oH = imageData.height;\n const dW = Math.round(oW * scaleX);\n const dH = Math.round(oH * scaleY);\n let newData: ImageData;\n\n if (this.resizeType === 'sliceHack') {\n newData = this.sliceByTwo(options, oW, oH, dW, dH);\n } else if (this.resizeType === 'hermite') {\n newData = this.hermiteFastResize(options, oW, oH, dW, dH);\n } else if (this.resizeType === 'bilinear') {\n newData = this.bilinearFiltering(options, oW, oH, dW, dH);\n } else if (this.resizeType === 'lanczos') {\n newData = this.lanczosResize(options, oW, oH, dW, dH);\n } else {\n // this should never trigger, is here just for safety net.\n newData = new ImageData(dW, dH);\n }\n options.imageData = newData;\n }\n\n /**\n * Filter sliceByTwo\n * @param {Object} canvasEl Canvas element to apply filter to\n * @param {Number} oW Original Width\n * @param {Number} oH Original Height\n * @param {Number} dW Destination Width\n * @param {Number} dH Destination Height\n * @returns {ImageData}\n */\n sliceByTwo(\n options: T2DPipelineState,\n oW: number,\n oH: number,\n dW: number,\n dH: number,\n ) {\n const imageData = options.imageData;\n const mult = 0.5;\n let doneW = false;\n let doneH = false;\n let stepW = oW * mult;\n let stepH = oH * mult;\n const resources = options.filterBackend.resources;\n let sX = 0;\n let sY = 0;\n const dX = oW;\n let dY = 0;\n if (!resources.sliceByTwo) {\n resources.sliceByTwo = createCanvasElement();\n }\n const tmpCanvas = resources.sliceByTwo;\n if (tmpCanvas.width < oW * 1.5 || tmpCanvas.height < oH) {\n tmpCanvas.width = oW * 1.5;\n tmpCanvas.height = oH;\n }\n const ctx = tmpCanvas.getContext('2d')!;\n ctx.clearRect(0, 0, oW * 1.5, oH);\n ctx.putImageData(imageData, 0, 0);\n\n dW = Math.floor(dW);\n dH = Math.floor(dH);\n\n while (!doneW || !doneH) {\n oW = stepW;\n oH = stepH;\n if (dW < Math.floor(stepW * mult)) {\n stepW = Math.floor(stepW * mult);\n } else {\n stepW = dW;\n doneW = true;\n }\n if (dH < Math.floor(stepH * mult)) {\n stepH = Math.floor(stepH * mult);\n } else {\n stepH = dH;\n doneH = true;\n }\n ctx.drawImage(tmpCanvas, sX, sY, oW, oH, dX, dY, stepW, stepH);\n sX = dX;\n sY = dY;\n dY += stepH;\n }\n return ctx.getImageData(sX, sY, dW, dH);\n }\n\n /**\n * Filter lanczosResize\n * @param {Object} canvasEl Canvas element to apply filter to\n * @param {Number} oW Original Width\n * @param {Number} oH Original Height\n * @param {Number} dW Destination Width\n * @param {Number} dH Destination Height\n * @returns {ImageData}\n */\n lanczosResize(\n this: ResizeDuring2DResize,\n options: T2DPipelineState,\n oW: number,\n oH: number,\n dW: number,\n dH: number,\n ): ImageData {\n function process(u: number): ImageData {\n let v, i, weight, idx, a, red, green, blue, alpha, fX, fY;\n center.x = (u + 0.5) * ratioX;\n icenter.x = Math.floor(center.x);\n for (v = 0; v < dH; v++) {\n center.y = (v + 0.5) * ratioY;\n icenter.y = Math.floor(center.y);\n a = 0;\n red = 0;\n green = 0;\n blue = 0;\n alpha = 0;\n for (i = icenter.x - range2X; i <= icenter.x + range2X; i++) {\n if (i < 0 || i >= oW) {\n continue;\n }\n fX = Math.floor(1000 * Math.abs(i - center.x));\n if (!cacheLanc[fX]) {\n cacheLanc[fX] = {};\n }\n for (let j = icenter.y - range2Y; j <= icenter.y + range2Y; j++) {\n if (j < 0 || j >= oH) {\n continue;\n }\n fY = Math.floor(1000 * Math.abs(j - center.y));\n if (!cacheLanc[fX][fY]) {\n cacheLanc[fX][fY] = lanczos(\n Math.sqrt(\n Math.pow(fX * rcpRatioX, 2) + Math.pow(fY * rcpRatioY, 2),\n ) / 1000,\n );\n }\n weight = cacheLanc[fX][fY];\n if (weight > 0) {\n idx = (j * oW + i) * 4;\n a += weight;\n red += weight * srcData[idx];\n green += weight * srcData[idx + 1];\n blue += weight * srcData[idx + 2];\n alpha += weight * srcData[idx + 3];\n }\n }\n }\n idx = (v * dW + u) * 4;\n destData[idx] = red / a;\n destData[idx + 1] = green / a;\n destData[idx + 2] = blue / a;\n destData[idx + 3] = alpha / a;\n }\n\n if (++u < dW) {\n return process(u);\n } else {\n return destImg;\n }\n }\n\n const srcData = options.imageData.data,\n destImg = options.ctx.createImageData(dW, dH),\n destData = destImg.data,\n lanczos = this.lanczosCreate(this.lanczosLobes),\n ratioX = this.rcpScaleX,\n ratioY = this.rcpScaleY,\n rcpRatioX = 2 / this.rcpScaleX,\n rcpRatioY = 2 / this.rcpScaleY,\n range2X = Math.ceil((ratioX * this.lanczosLobes) / 2),\n range2Y = Math.ceil((ratioY * this.lanczosLobes) / 2),\n cacheLanc: Record<number, Record<number, number>> = {},\n center: XY = { x: 0, y: 0 },\n icenter: XY = { x: 0, y: 0 };\n\n return process(0);\n }\n\n /**\n * bilinearFiltering\n * @param {Object} canvasEl Canvas element to apply filter to\n * @param {Number} oW Original Width\n * @param {Number} oH Original Height\n * @param {Number} dW Destination Width\n * @param {Number} dH Destination Height\n * @returns {ImageData}\n */\n bilinearFiltering(\n this: ResizeDuring2DResize,\n options: T2DPipelineState,\n oW: number,\n oH: number,\n dW: number,\n dH: number,\n ) {\n let a;\n let b;\n let c;\n let d;\n let x;\n let y;\n let i;\n let j;\n let xDiff;\n let yDiff;\n let chnl;\n let color;\n let offset = 0;\n let origPix;\n const ratioX = this.rcpScaleX;\n const ratioY = this.rcpScaleY;\n const w4 = 4 * (oW - 1);\n const img = options.imageData;\n const pixels = img.data;\n const destImage = options.ctx.createImageData(dW, dH);\n const destPixels = destImage.data;\n for (i = 0; i < dH; i++) {\n for (j = 0; j < dW; j++) {\n x = Math.floor(ratioX * j);\n y = Math.floor(ratioY * i);\n xDiff = ratioX * j - x;\n yDiff = ratioY * i - y;\n origPix = 4 * (y * oW + x);\n\n for (chnl = 0; chnl < 4; chnl++) {\n a = pixels[origPix + chnl];\n b = pixels[origPix + 4 + chnl];\n c = pixels[origPix + w4 + chnl];\n d = pixels[origPix + w4 + 4 + chnl];\n color =\n a * (1 - xDiff) * (1 - yDiff) +\n b * xDiff * (1 - yDiff) +\n c * yDiff * (1 - xDiff) +\n d * xDiff * yDiff;\n destPixels[offset++] = color;\n }\n }\n }\n return destImage;\n }\n\n /**\n * hermiteFastResize\n * @param {Object} canvasEl Canvas element to apply filter to\n * @param {Number} oW Original Width\n * @param {Number} oH Original Height\n * @param {Number} dW Destination Width\n * @param {Number} dH Destination Height\n * @returns {ImageData}\n */\n hermiteFastResize(\n this: ResizeDuring2DResize,\n options: T2DPipelineState,\n oW: number,\n oH: number,\n dW: number,\n dH: number,\n ) {\n const ratioW = this.rcpScaleX,\n ratioH = this.rcpScaleY,\n ratioWHalf = Math.ceil(ratioW / 2),\n ratioHHalf = Math.ceil(ratioH / 2),\n img = options.imageData,\n data = img.data,\n img2 = options.ctx.createImageData(dW, dH),\n data2 = img2.data;\n for (let j = 0; j < dH; j++) {\n for (let i = 0; i < dW; i++) {\n const x2 = (i + j * dW) * 4;\n let weight = 0;\n let weights = 0;\n let weightsAlpha = 0;\n let gxR = 0;\n let gxG = 0;\n let gxB = 0;\n let gxA = 0;\n const centerY = (j + 0.5) * ratioH;\n for (let yy = Math.floor(j * ratioH); yy < (j + 1) * ratioH; yy++) {\n const dy = Math.abs(centerY - (yy + 0.5)) / ratioHHalf,\n centerX = (i + 0.5) * ratioW,\n w0 = dy * dy;\n for (let xx = Math.floor(i * ratioW); xx < (i + 1) * ratioW; xx++) {\n let dx = Math.abs(centerX - (xx + 0.5)) / ratioWHalf;\n const w = Math.sqrt(w0 + dx * dx);\n\n if (w > 1 && w < -1) {\n continue;\n }\n //hermite filter\n weight = 2 * w * w * w - 3 * w * w + 1;\n if (weight > 0) {\n dx = 4 * (xx + yy * oW);\n //alpha\n gxA += weight * data[dx + 3];\n weightsAlpha += weight;\n //colors\n if (data[dx + 3] < 255) {\n weight = (weight * data[dx + 3]) / 250;\n }\n gxR += weight * data[dx];\n gxG += weight * data[dx + 1];\n gxB += weight * data[dx + 2];\n weights += weight;\n }\n }\n }\n data2[x2] = gxR / weights;\n data2[x2 + 1] = gxG / weights;\n data2[x2 + 2] = gxB / weights;\n data2[x2 + 3] = gxA / weightsAlpha;\n }\n }\n return img2;\n }\n}\n\nclassRegistry.setClass(Resize);\n"],"mappings":";;;;;;AAsBA,MAAa,sBAAsC;CACjD,YAAY;CACZ,QAAQ;CACR,QAAQ;CACR,cAAc;CACf;;;;;;;;AA0BD,IAAa,SAAb,cAA4B,WAAqC;;;;;;;CAsC/D,gBAEE,IACA,kBACA;AACA,KAAG,WACD,iBAAiB,QACjB,KAAK,aAAa,CAAC,IAAI,KAAK,OAAO,EAAE,GAAG,CAAC,GAAG,IAAI,KAAK,OAAO,CAC7D;AACD,KAAG,WAAW,iBAAiB,OAAO,KAAK,KAAK;;CAGlD,kBAA+C;EAC7C,MAAM,QAAQ,KAAK;AACnB,SAAO,KAAK,KAAK,KAAK,eAAe,MAAM;;CAG7C,cAAmD;EACjD,MAAM,eAAe,KAAK,iBAAiB;AAC3C,SAAO,GAAG,KAAK,KAAK,GAAG;;CAGzB,oBAAyD;EACvD,MAAM,eAAe,KAAK,iBAAiB;AAC3C,SAAO,KAAK,eAAe,aAAa;;CAG1C,UAAuC;EACrC,MAAM,eAAe,KAAK,cAAc,KAAK,aAAa,EACxD,QAAQ,KAAK,WACb,eAAe,KAAK,iBAAiB,EACrC,OAAO,IAAI,MAAM,aAAa;AAChC,OAAK,IAAI,IAAI,GAAG,KAAK,cAAc,IACjC,MAAK,IAAI,KAAK,aAAa,IAAI,MAAM;AAEvC,SAAO;;;;;;CAOT,eAAe,cAAsB;EACnC,MAAM,UAAU,IAAI,MAAM,aAAa;AACvC,OAAK,IAAI,IAAI,GAAG,KAAK,cAAc,IACjC,SAAQ,IAAI,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AW,IAAI,MAAO;AAC5B,QAAK,IAAI,KAAK,KAAK,MAAM,IAAI,OAAO,EAAE,MAAM,IAAI,KAAK,QAAQ,MAAM;IACjE,MAAM,KAAK,KAAK,IAAI,WAAW,KAAK,IAAK,GAAG,YAC1C,WAAW,IAAI,MAAO,QACtB,KAAK,KAAK;AACZ,SAAK,IAAI,KAAK,KAAK,MAAM,IAAI,OAAO,EAAE,MAAM,IAAI,KAAK,QAAQ,MAAM;KACjE,IAAI,KAAK,KAAK,IAAI,WAAW,KAAK,IAAK,GAAG;KAC1C,MAAM,IAAI,KAAK,KAAK,KAAK,KAAK,GAAG;AAEjC,SAAI,IAAI,KAAK,IAAI,GACf;AAGF,cAAS,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI;AACrC,SAAI,SAAS,GAAG;AACd,WAAK,KAAK,KAAK,KAAK;AAEpB,aAAO,SAAS,KAAK,KAAK;AAC1B,sBAAgB;AAEhB,UAAI,KAAK,KAAK,KAAK,IACjB,UAAU,SAAS,KAAK,KAAK,KAAM;AAErC,aAAO,SAAS,KAAK;AACrB,aAAO,SAAS,KAAK,KAAK;AAC1B,aAAO,SAAS,KAAK,KAAK;AAC1B,iBAAW;;;;AAIjB,SAAM,MAAM,MAAM;AAClB,SAAM,KAAK,KAAK,MAAM;AACtB,SAAM,KAAK,KAAK,MAAM;AACtB,SAAM,KAAK,KAAK,MAAM;;AAG1B,SAAO;;;wBA5cF,QAAO,SAAS;wBAEhB,YAAW,oBAAoB;wBAE/B,oBAAmB,CAAC,UAAU,QAAQ,CAAC;AA4chD,cAAc,SAAS,OAAO"}
1
+ {"version":3,"file":"Resize.mjs","names":[],"sources":["../../../src/filters/Resize.ts"],"sourcesContent":["import { BaseFilter } from './BaseFilter';\nimport type {\n T2DPipelineState,\n TWebGLPipelineState,\n TWebGLUniformLocationMap,\n} from './typedefs';\nimport { isWebGLPipelineState } from './utils';\nimport { classRegistry } from '../ClassRegistry';\nimport { createCanvasElement } from '../util/misc/dom';\nimport type { XY } from '../Point';\n\nexport type TResizeType = 'bilinear' | 'hermite' | 'sliceHack' | 'lanczos';\n\nexport type ResizeOwnProps = {\n resizeType: TResizeType;\n scaleX: number;\n scaleY: number;\n lanczosLobes: number;\n};\n\nexport type ResizeSerializedProps = ResizeOwnProps;\n\nexport const resizeDefaultValues: ResizeOwnProps = {\n resizeType: 'hermite',\n scaleX: 1,\n scaleY: 1,\n lanczosLobes: 3,\n};\n\ntype ResizeDuring2DResize = Resize & {\n rcpScaleX: number;\n rcpScaleY: number;\n};\n\ntype ResizeDuringWEBGLResize = Resize & {\n rcpScaleX: number;\n rcpScaleY: number;\n horizontal: boolean;\n width: number;\n height: number;\n taps: number[];\n tempScale: number;\n dH: number;\n dW: number;\n};\n\n/**\n * Resize image filter class\n * @example\n * const filter = new Resize();\n * object.filters.push(filter);\n * object.applyFilters(canvas.renderAll.bind(canvas));\n */\nexport class Resize extends BaseFilter<'Resize', ResizeOwnProps> {\n /**\n * Resize type\n * for webgl resizeType is just lanczos, for canvas2d can be:\n * bilinear, hermite, sliceHack, lanczos.\n */\n declare resizeType: ResizeOwnProps['resizeType'];\n\n /**\n * Scale factor for resizing, x axis\n * @param {Number} scaleX\n */\n declare scaleX: ResizeOwnProps['scaleX'];\n\n /**\n * Scale factor for resizing, y axis\n * @param {Number} scaleY\n */\n declare scaleY: ResizeOwnProps['scaleY'];\n\n /**\n * LanczosLobes parameter for lanczos filter, valid for resizeType lanczos\n * @param {Number} lanczosLobes\n */\n declare lanczosLobes: ResizeOwnProps['lanczosLobes'];\n\n static type = 'Resize';\n\n static defaults = resizeDefaultValues;\n\n static uniformLocations = ['uDelta', 'uTaps'];\n\n /**\n * Send data from this filter to its shader program's uniforms.\n *\n * @param {WebGLRenderingContext} gl The GL canvas context used to compile this filter's shader.\n * @param {Object} uniformLocations A map of string uniform names to WebGLUniformLocation objects\n */\n sendUniformData(\n this: ResizeDuringWEBGLResize,\n gl: WebGLRenderingContext,\n uniformLocations: TWebGLUniformLocationMap,\n ) {\n gl.uniform2fv(\n uniformLocations.uDelta,\n this.horizontal ? [1 / this.width, 0] : [0, 1 / this.height],\n );\n gl.uniform1fv(uniformLocations.uTaps, this.taps);\n }\n\n getFilterWindow(this: ResizeDuringWEBGLResize) {\n const scale = this.tempScale;\n return Math.ceil(this.lanczosLobes / scale);\n }\n\n getCacheKey(this: ResizeDuringWEBGLResize): string {\n const filterWindow = this.getFilterWindow();\n return `${this.type}_${filterWindow}`;\n }\n\n getFragmentSource(this: ResizeDuringWEBGLResize): string {\n const filterWindow = this.getFilterWindow();\n return this.generateShader(filterWindow);\n }\n\n getTaps(this: ResizeDuringWEBGLResize) {\n const lobeFunction = this.lanczosCreate(this.lanczosLobes),\n scale = this.tempScale,\n filterWindow = this.getFilterWindow(),\n taps = new Array(filterWindow);\n for (let i = 1; i <= filterWindow; i++) {\n taps[i - 1] = lobeFunction(i * scale);\n }\n return taps;\n }\n\n /**\n * Generate vertex and shader sources from the necessary steps numbers\n * @param {Number} filterWindow\n */\n generateShader(filterWindow: number) {\n const offsets = new Array(filterWindow);\n for (let i = 1; i <= filterWindow; i++) {\n offsets[i - 1] = `${i}.0 * uDelta`;\n }\n return `\n precision highp float;\n uniform sampler2D uTexture;\n uniform vec2 uDelta;\n varying vec2 vTexCoord;\n uniform float uTaps[${filterWindow}];\n void main() {\n vec4 color = texture2D(uTexture, vTexCoord);\n float sum = 1.0;\n ${offsets\n .map(\n (offset, i) => `\n color += texture2D(uTexture, vTexCoord + ${offset}) * uTaps[${i}] + texture2D(uTexture, vTexCoord - ${offset}) * uTaps[${i}];\n sum += 2.0 * uTaps[${i}];\n `,\n )\n .join('\\n')}\n gl_FragColor = color / sum;\n }\n `;\n }\n\n applyToForWebgl(this: ResizeDuringWEBGLResize, options: TWebGLPipelineState) {\n options.passes++;\n this.width = options.sourceWidth;\n this.horizontal = true;\n this.dW = Math.round(this.width * this.scaleX);\n this.dH = options.sourceHeight;\n this.tempScale = this.dW / this.width;\n this.taps = this.getTaps();\n options.destinationWidth = this.dW;\n super.applyTo(options);\n options.sourceWidth = options.destinationWidth;\n\n this.height = options.sourceHeight;\n this.horizontal = false;\n this.dH = Math.round(this.height * this.scaleY);\n this.tempScale = this.dH / this.height;\n this.taps = this.getTaps();\n options.destinationHeight = this.dH;\n super.applyTo(options);\n options.sourceHeight = options.destinationHeight;\n }\n\n /**\n * Apply the resize filter to the image\n * Determines whether to use WebGL or Canvas2D based on the options.webgl flag.\n *\n * @param {Object} options\n * @param {Number} options.passes The number of filters remaining to be executed\n * @param {Boolean} options.webgl Whether to use webgl to render the filter.\n * @param {WebGLTexture} options.sourceTexture The texture setup as the source to be filtered.\n * @param {WebGLTexture} options.targetTexture The texture where filtered output should be drawn.\n * @param {WebGLRenderingContext} options.context The GL context used for rendering.\n * @param {Object} options.programCache A map of compiled shader programs, keyed by filter type.\n */\n applyTo(options: TWebGLPipelineState | T2DPipelineState) {\n if (isWebGLPipelineState(options)) {\n (this as unknown as ResizeDuringWEBGLResize).applyToForWebgl(options);\n } else {\n (this as unknown as ResizeDuring2DResize).applyTo2d(options);\n }\n }\n\n isNeutralState() {\n return this.scaleX === 1 && this.scaleY === 1;\n }\n\n lanczosCreate(lobes: number) {\n return (x: number) => {\n if (x >= lobes || x <= -lobes) {\n return 0.0;\n }\n if (x < 1.1920929e-7 && x > -1.1920929e-7) {\n return 1.0;\n }\n x *= Math.PI;\n const xx = x / lobes;\n return ((Math.sin(x) / x) * Math.sin(xx)) / xx;\n };\n }\n\n applyTo2d(this: ResizeDuring2DResize, options: T2DPipelineState) {\n const imageData = options.imageData,\n scaleX = this.scaleX,\n scaleY = this.scaleY;\n\n this.rcpScaleX = 1 / scaleX;\n this.rcpScaleY = 1 / scaleY;\n\n const oW = imageData.width;\n const oH = imageData.height;\n const dW = Math.round(oW * scaleX);\n const dH = Math.round(oH * scaleY);\n let newData: ImageData;\n\n if (this.resizeType === 'sliceHack') {\n newData = this.sliceByTwo(options, oW, oH, dW, dH);\n } else if (this.resizeType === 'hermite') {\n newData = this.hermiteFastResize(options, oW, oH, dW, dH);\n } else if (this.resizeType === 'bilinear') {\n newData = this.bilinearFiltering(options, oW, oH, dW, dH);\n } else if (this.resizeType === 'lanczos') {\n newData = this.lanczosResize(options, oW, oH, dW, dH);\n } else {\n // this should never trigger, is here just for safety net.\n newData = new ImageData(dW, dH);\n }\n options.imageData = newData;\n }\n\n /**\n * Filter sliceByTwo\n * @param {Object} canvasEl Canvas element to apply filter to\n * @param {Number} oW Original Width\n * @param {Number} oH Original Height\n * @param {Number} dW Destination Width\n * @param {Number} dH Destination Height\n * @returns {ImageData}\n */\n sliceByTwo(\n options: T2DPipelineState,\n oW: number,\n oH: number,\n dW: number,\n dH: number,\n ) {\n const imageData = options.imageData;\n const mult = 0.5;\n let doneW = false;\n let doneH = false;\n let stepW = oW * mult;\n let stepH = oH * mult;\n const resources = options.filterBackend.resources;\n let sX = 0;\n let sY = 0;\n const dX = oW;\n let dY = 0;\n if (!resources.sliceByTwo) {\n resources.sliceByTwo = createCanvasElement();\n }\n const tmpCanvas = resources.sliceByTwo;\n if (tmpCanvas.width < oW * 1.5 || tmpCanvas.height < oH) {\n tmpCanvas.width = oW * 1.5;\n tmpCanvas.height = oH;\n }\n const ctx = tmpCanvas.getContext('2d')!;\n ctx.clearRect(0, 0, oW * 1.5, oH);\n ctx.putImageData(imageData, 0, 0);\n\n dW = Math.floor(dW);\n dH = Math.floor(dH);\n\n while (!doneW || !doneH) {\n oW = stepW;\n oH = stepH;\n if (dW < Math.floor(stepW * mult)) {\n stepW = Math.floor(stepW * mult);\n } else {\n stepW = dW;\n doneW = true;\n }\n if (dH < Math.floor(stepH * mult)) {\n stepH = Math.floor(stepH * mult);\n } else {\n stepH = dH;\n doneH = true;\n }\n ctx.drawImage(tmpCanvas, sX, sY, oW, oH, dX, dY, stepW, stepH);\n sX = dX;\n sY = dY;\n dY += stepH;\n }\n return ctx.getImageData(sX, sY, dW, dH);\n }\n\n /**\n * Filter lanczosResize\n * @param {Object} canvasEl Canvas element to apply filter to\n * @param {Number} oW Original Width\n * @param {Number} oH Original Height\n * @param {Number} dW Destination Width\n * @param {Number} dH Destination Height\n * @returns {ImageData}\n */\n lanczosResize(\n this: ResizeDuring2DResize,\n options: T2DPipelineState,\n oW: number,\n oH: number,\n dW: number,\n dH: number,\n ): ImageData {\n function process(u: number): ImageData {\n let v, i, weight, idx, a, red, green, blue, alpha, fX, fY;\n center.x = (u + 0.5) * ratioX;\n icenter.x = Math.floor(center.x);\n for (v = 0; v < dH; v++) {\n center.y = (v + 0.5) * ratioY;\n icenter.y = Math.floor(center.y);\n a = 0;\n red = 0;\n green = 0;\n blue = 0;\n alpha = 0;\n for (i = icenter.x - range2X; i <= icenter.x + range2X; i++) {\n if (i < 0 || i >= oW) {\n continue;\n }\n fX = Math.floor(1000 * Math.abs(i - center.x));\n if (!cacheLanc[fX]) {\n cacheLanc[fX] = {};\n }\n for (let j = icenter.y - range2Y; j <= icenter.y + range2Y; j++) {\n if (j < 0 || j >= oH) {\n continue;\n }\n fY = Math.floor(1000 * Math.abs(j - center.y));\n if (!cacheLanc[fX][fY]) {\n cacheLanc[fX][fY] = lanczos(\n Math.sqrt(\n Math.pow(fX * rcpRatioX, 2) + Math.pow(fY * rcpRatioY, 2),\n ) / 1000,\n );\n }\n weight = cacheLanc[fX][fY];\n if (weight > 0) {\n idx = (j * oW + i) * 4;\n a += weight;\n red += weight * srcData[idx];\n green += weight * srcData[idx + 1];\n blue += weight * srcData[idx + 2];\n alpha += weight * srcData[idx + 3];\n }\n }\n }\n idx = (v * dW + u) * 4;\n destData[idx] = red / a;\n destData[idx + 1] = green / a;\n destData[idx + 2] = blue / a;\n destData[idx + 3] = alpha / a;\n }\n\n if (++u < dW) {\n return process(u);\n } else {\n return destImg;\n }\n }\n\n const srcData = options.imageData.data,\n destImg = options.ctx.createImageData(dW, dH),\n destData = destImg.data,\n lanczos = this.lanczosCreate(this.lanczosLobes),\n ratioX = this.rcpScaleX,\n ratioY = this.rcpScaleY,\n rcpRatioX = 2 / this.rcpScaleX,\n rcpRatioY = 2 / this.rcpScaleY,\n range2X = Math.ceil((ratioX * this.lanczosLobes) / 2),\n range2Y = Math.ceil((ratioY * this.lanczosLobes) / 2),\n cacheLanc: Record<number, Record<number, number>> = {},\n center: XY = { x: 0, y: 0 },\n icenter: XY = { x: 0, y: 0 };\n\n return process(0);\n }\n\n /**\n * bilinearFiltering\n * @param {Object} canvasEl Canvas element to apply filter to\n * @param {Number} oW Original Width\n * @param {Number} oH Original Height\n * @param {Number} dW Destination Width\n * @param {Number} dH Destination Height\n * @returns {ImageData}\n */\n bilinearFiltering(\n this: ResizeDuring2DResize,\n options: T2DPipelineState,\n oW: number,\n oH: number,\n dW: number,\n dH: number,\n ) {\n let a;\n let b;\n let c;\n let d;\n let x;\n let y;\n let i;\n let j;\n let xDiff;\n let yDiff;\n let chnl;\n let color;\n let offset = 0;\n let origPix;\n const ratioX = this.rcpScaleX;\n const ratioY = this.rcpScaleY;\n const w4 = 4 * (oW - 1);\n const img = options.imageData;\n const pixels = img.data;\n const destImage = options.ctx.createImageData(dW, dH);\n const destPixels = destImage.data;\n for (i = 0; i < dH; i++) {\n for (j = 0; j < dW; j++) {\n x = Math.floor(ratioX * j);\n y = Math.floor(ratioY * i);\n xDiff = ratioX * j - x;\n yDiff = ratioY * i - y;\n origPix = 4 * (y * oW + x);\n\n for (chnl = 0; chnl < 4; chnl++) {\n a = pixels[origPix + chnl];\n b = pixels[origPix + 4 + chnl];\n c = pixels[origPix + w4 + chnl];\n d = pixels[origPix + w4 + 4 + chnl];\n color =\n a * (1 - xDiff) * (1 - yDiff) +\n b * xDiff * (1 - yDiff) +\n c * yDiff * (1 - xDiff) +\n d * xDiff * yDiff;\n destPixels[offset++] = color;\n }\n }\n }\n return destImage;\n }\n\n /**\n * hermiteFastResize\n * @param {Object} canvasEl Canvas element to apply filter to\n * @param {Number} oW Original Width\n * @param {Number} oH Original Height\n * @param {Number} dW Destination Width\n * @param {Number} dH Destination Height\n * @returns {ImageData}\n */\n hermiteFastResize(\n this: ResizeDuring2DResize,\n options: T2DPipelineState,\n oW: number,\n oH: number,\n dW: number,\n dH: number,\n ) {\n const ratioW = this.rcpScaleX,\n ratioH = this.rcpScaleY,\n ratioWHalf = Math.ceil(ratioW / 2),\n ratioHHalf = Math.ceil(ratioH / 2),\n img = options.imageData,\n data = img.data,\n img2 = options.ctx.createImageData(dW, dH),\n data2 = img2.data;\n for (let j = 0; j < dH; j++) {\n for (let i = 0; i < dW; i++) {\n const x2 = (i + j * dW) * 4;\n let weight: number;\n let weights = 0;\n let weightsAlpha = 0;\n let gxR = 0;\n let gxG = 0;\n let gxB = 0;\n let gxA = 0;\n const centerY = (j + 0.5) * ratioH;\n for (let yy = Math.floor(j * ratioH); yy < (j + 1) * ratioH; yy++) {\n const dy = Math.abs(centerY - (yy + 0.5)) / ratioHHalf,\n centerX = (i + 0.5) * ratioW,\n w0 = dy * dy;\n for (let xx = Math.floor(i * ratioW); xx < (i + 1) * ratioW; xx++) {\n let dx = Math.abs(centerX - (xx + 0.5)) / ratioWHalf;\n const w = Math.sqrt(w0 + dx * dx);\n\n if (w > 1 && w < -1) {\n continue;\n }\n //hermite filter\n weight = 2 * w * w * w - 3 * w * w + 1;\n if (weight > 0) {\n dx = 4 * (xx + yy * oW);\n //alpha\n gxA += weight * data[dx + 3];\n weightsAlpha += weight;\n //colors\n if (data[dx + 3] < 255) {\n weight = (weight * data[dx + 3]) / 250;\n }\n gxR += weight * data[dx];\n gxG += weight * data[dx + 1];\n gxB += weight * data[dx + 2];\n weights += weight;\n }\n }\n }\n data2[x2] = gxR / weights;\n data2[x2 + 1] = gxG / weights;\n data2[x2 + 2] = gxB / weights;\n data2[x2 + 3] = gxA / weightsAlpha;\n }\n }\n return img2;\n }\n}\n\nclassRegistry.setClass(Resize);\n"],"mappings":";;;;;;AAsBA,MAAa,sBAAsC;CACjD,YAAY;CACZ,QAAQ;CACR,QAAQ;CACR,cAAc;CACf;;;;;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AAI,KAAK,IAAI,GACf;AAGF,cAAS,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI;AACrC,SAAI,SAAS,GAAG;AACd,WAAK,KAAK,KAAK,KAAK;AAEpB,aAAO,SAAS,KAAK,KAAK;AAC1B,sBAAgB;AAEhB,UAAI,KAAK,KAAK,KAAK,IACjB,UAAU,SAAS,KAAK,KAAK,KAAM;AAErC,aAAO,SAAS,KAAK;AACrB,aAAO,SAAS,KAAK,KAAK;AAC1B,aAAO,SAAS,KAAK,KAAK;AAC1B,iBAAW;;;;AAIjB,SAAM,MAAM,MAAM;AAClB,SAAM,KAAK,KAAK,MAAM;AACtB,SAAM,KAAK,KAAK,MAAM;AACtB,SAAM,KAAK,KAAK,MAAM;;AAG1B,SAAO;;;wBA5cF,QAAO,SAAS;wBAEhB,YAAW,oBAAoB;wBAE/B,oBAAmB,CAAC,UAAU,QAAQ,CAAC;AA4chD,cAAc,SAAS,OAAO"}
@@ -1,2 +1,2 @@
1
- import{_defineProperty as e}from"../../_virtual/_@oxc-project_runtime@0.122.0/helpers/defineProperty.min.mjs";import{classRegistry as t}from"../ClassRegistry.min.mjs";import{BaseFilter as n}from"./BaseFilter.min.mjs";import{fragmentSource as r}from"./shaders/saturation.min.mjs";var i=class extends n{getFragmentSource(){return r}applyTo2d({imageData:{data:e}}){let t=-this.saturation;for(let n=0;n<e.length;n+=4){let r=e[n],i=e[n+1],a=e[n+2],o=Math.max(r,i,a);e[n]+=o===r?0:(o-r)*t,e[n+1]+=o===i?0:(o-i)*t,e[n+2]+=o===a?0:(o-a)*t}}sendUniformData(e,t){e.uniform1f(t.uSaturation,-this.saturation)}isNeutralState(){return this.saturation===0}};e(i,`type`,`Saturation`),e(i,`defaults`,{saturation:0}),e(i,`uniformLocations`,[`uSaturation`]),t.setClass(i);export{i as Saturation};
1
+ import{_defineProperty as e}from"../../_virtual/_@oxc-project_runtime@0.126.0/helpers/defineProperty.min.mjs";import{classRegistry as t}from"../ClassRegistry.min.mjs";import{BaseFilter as n}from"./BaseFilter.min.mjs";import{fragmentSource as r}from"./shaders/saturation.min.mjs";var i=class extends n{getFragmentSource(){return r}applyTo2d({imageData:{data:e}}){let t=-this.saturation;for(let n=0;n<e.length;n+=4){let r=e[n],i=e[n+1],a=e[n+2],o=Math.max(r,i,a);e[n]+=o===r?0:(o-r)*t,e[n+1]+=o===i?0:(o-i)*t,e[n+2]+=o===a?0:(o-a)*t}}sendUniformData(e,t){e.uniform1f(t.uSaturation,-this.saturation)}isNeutralState(){return this.saturation===0}};e(i,`type`,`Saturation`),e(i,`defaults`,{saturation:0}),e(i,`uniformLocations`,[`uSaturation`]),t.setClass(i);export{i as Saturation};
2
2
  //# sourceMappingURL=Saturation.min.mjs.map
@@ -1,4 +1,4 @@
1
- import { _defineProperty } from "../../_virtual/_@oxc-project_runtime@0.122.0/helpers/defineProperty.mjs";
1
+ import { _defineProperty } from "../../_virtual/_@oxc-project_runtime@0.126.0/helpers/defineProperty.mjs";
2
2
  import { classRegistry } from "../ClassRegistry.mjs";
3
3
  import { BaseFilter } from "./BaseFilter.mjs";
4
4
  import { fragmentSource } from "./shaders/saturation.mjs";
@@ -1,2 +1,2 @@
1
- import{_defineProperty as e}from"../../_virtual/_@oxc-project_runtime@0.122.0/helpers/defineProperty.min.mjs";import{classRegistry as t}from"../ClassRegistry.min.mjs";import{BaseFilter as n}from"./BaseFilter.min.mjs";import{fragmentSource as r}from"./shaders/vibrance.min.mjs";var i=class extends n{getFragmentSource(){return r}applyTo2d({imageData:{data:e}}){let t=-this.vibrance;for(let n=0;n<e.length;n+=4){let r=e[n],i=e[n+1],a=e[n+2],o=Math.max(r,i,a),s=(r+i+a)/3,c=2*Math.abs(o-s)/255*t;e[n]+=o===r?0:(o-r)*c,e[n+1]+=o===i?0:(o-i)*c,e[n+2]+=o===a?0:(o-a)*c}}sendUniformData(e,t){e.uniform1f(t.uVibrance,-this.vibrance)}isNeutralState(){return this.vibrance===0}};e(i,`type`,`Vibrance`),e(i,`defaults`,{vibrance:0}),e(i,`uniformLocations`,[`uVibrance`]),t.setClass(i);export{i as Vibrance};
1
+ import{_defineProperty as e}from"../../_virtual/_@oxc-project_runtime@0.126.0/helpers/defineProperty.min.mjs";import{classRegistry as t}from"../ClassRegistry.min.mjs";import{BaseFilter as n}from"./BaseFilter.min.mjs";import{fragmentSource as r}from"./shaders/vibrance.min.mjs";var i=class extends n{getFragmentSource(){return r}applyTo2d({imageData:{data:e}}){let t=-this.vibrance;for(let n=0;n<e.length;n+=4){let r=e[n],i=e[n+1],a=e[n+2],o=Math.max(r,i,a),s=(r+i+a)/3,c=2*Math.abs(o-s)/255*t;e[n]+=o===r?0:(o-r)*c,e[n+1]+=o===i?0:(o-i)*c,e[n+2]+=o===a?0:(o-a)*c}}sendUniformData(e,t){e.uniform1f(t.uVibrance,-this.vibrance)}isNeutralState(){return this.vibrance===0}};e(i,`type`,`Vibrance`),e(i,`defaults`,{vibrance:0}),e(i,`uniformLocations`,[`uVibrance`]),t.setClass(i);export{i as Vibrance};
2
2
  //# sourceMappingURL=Vibrance.min.mjs.map
@@ -1,4 +1,4 @@
1
- import { _defineProperty } from "../../_virtual/_@oxc-project_runtime@0.122.0/helpers/defineProperty.mjs";
1
+ import { _defineProperty } from "../../_virtual/_@oxc-project_runtime@0.126.0/helpers/defineProperty.mjs";
2
2
  import { classRegistry } from "../ClassRegistry.mjs";
3
3
  import { BaseFilter } from "./BaseFilter.mjs";
4
4
  import { fragmentSource } from "./shaders/vibrance.mjs";
@@ -1,2 +1,2 @@
1
- import{_defineProperty as e}from"../../_virtual/_@oxc-project_runtime@0.122.0/helpers/defineProperty.min.mjs";import{config as t}from"../config.min.mjs";import{createCanvasElementFor as n}from"../util/misc/dom.min.mjs";var r=class{constructor({tileSize:n=t.textureSize}={}){e(this,`aPosition`,new Float32Array([0,0,0,1,1,0,1,1])),e(this,`resources`,{}),this.tileSize=n,this.setupGLContext(n,n),this.captureGPUInfo()}setupGLContext(e,t){this.dispose(),this.createWebGLCanvas(e,t)}createWebGLCanvas(e,t){let r=n({width:e,height:t}),i=r.getContext(`webgl`,{alpha:!0,premultipliedAlpha:!1,depth:!1,stencil:!1,antialias:!1});i&&(i.clearColor(0,0,0,0),this.canvas=r,this.gl=i)}applyFilters(e,t,n,r,i,a){let o=this.gl,s=i.getContext(`2d`);if(!o||!s)return;let c;a&&(c=this.getCachedTexture(a,t));let l={originalWidth:t.width||t.naturalWidth||0,originalHeight:t.height||t.naturalHeight||0,sourceWidth:n,sourceHeight:r,destinationWidth:n,destinationHeight:r,context:o,sourceTexture:this.createTexture(o,n,r,c?void 0:t),targetTexture:this.createTexture(o,n,r),originalTexture:c||this.createTexture(o,n,r,c?void 0:t),passes:e.length,webgl:!0,aPosition:this.aPosition,programCache:this.programCache,pass:0,filterBackend:this,targetCanvas:i},u=o.createFramebuffer();return o.bindFramebuffer(o.FRAMEBUFFER,u),e.forEach(e=>{e&&e.applyTo(l)}),function(e){let t=e.targetCanvas,n=t.width,r=t.height,i=e.destinationWidth,a=e.destinationHeight;n===i&&r===a||(t.width=i,t.height=a)}(l),this.copyGLTo2D(o,l),o.bindTexture(o.TEXTURE_2D,null),o.deleteTexture(l.sourceTexture),o.deleteTexture(l.targetTexture),o.deleteFramebuffer(u),s.setTransform(1,0,0,1,0,0),l}dispose(){this.canvas&&(this.canvas=null,this.gl=null),this.clearWebGLCaches()}clearWebGLCaches(){this.programCache={},this.textureCache={}}createTexture(e,t,n,r,i){let{NEAREST:a,TEXTURE_2D:o,RGBA:s,UNSIGNED_BYTE:c,CLAMP_TO_EDGE:l,TEXTURE_MAG_FILTER:u,TEXTURE_MIN_FILTER:d,TEXTURE_WRAP_S:f,TEXTURE_WRAP_T:p}=e,m=e.createTexture();return e.bindTexture(o,m),e.texParameteri(o,u,i||a),e.texParameteri(o,d,i||a),e.texParameteri(o,f,l),e.texParameteri(o,p,l),r?e.texImage2D(o,0,s,s,c,r):e.texImage2D(o,0,s,t,n,0,s,c,null),m}getCachedTexture(e,t,n){let{textureCache:r}=this;if(r[e])return r[e];{let i=this.createTexture(this.gl,t.width,t.height,t,n);return i&&(r[e]=i),i}}evictCachesForKey(e){this.textureCache[e]&&(this.gl.deleteTexture(this.textureCache[e]),delete this.textureCache[e])}copyGLTo2D(e,t){let n=e.canvas,r=t.targetCanvas,i=r.getContext(`2d`);if(!i)return;i.translate(0,r.height),i.scale(1,-1);let a=n.height-r.height;i.drawImage(n,0,a,r.width,r.height,0,0,r.width,r.height)}copyGLTo2DPutImageData(e,t){let n=t.targetCanvas.getContext(`2d`),r=t.destinationWidth,i=t.destinationHeight,a=r*i*4;if(!n)return;let o=new Uint8Array(this.imageBuffer,0,a),s=new Uint8ClampedArray(this.imageBuffer,0,a);e.readPixels(0,0,r,i,e.RGBA,e.UNSIGNED_BYTE,o);let c=new ImageData(s,r,i);n.putImageData(c,0,0)}captureGPUInfo(){if(this.gpuInfo)return this.gpuInfo;let e=this.gl,t={renderer:``,vendor:``};if(!e)return t;let n=e.getExtension(`WEBGL_debug_renderer_info`);if(n){let r=e.getParameter(n.UNMASKED_RENDERER_WEBGL),i=e.getParameter(n.UNMASKED_VENDOR_WEBGL);r&&(t.renderer=r.toLowerCase()),i&&(t.vendor=i.toLowerCase())}return this.gpuInfo=t,t}};export{r as WebGLFilterBackend};
1
+ import{_defineProperty as e}from"../../_virtual/_@oxc-project_runtime@0.126.0/helpers/defineProperty.min.mjs";import{config as t}from"../config.min.mjs";import{createCanvasElementFor as n}from"../util/misc/dom.min.mjs";var r=class{constructor({tileSize:n=t.textureSize}={}){e(this,`aPosition`,new Float32Array([0,0,0,1,1,0,1,1])),e(this,`resources`,{}),this.tileSize=n,this.setupGLContext(n,n),this.captureGPUInfo()}setupGLContext(e,t){this.dispose(),this.createWebGLCanvas(e,t)}createWebGLCanvas(e,t){let r=n({width:e,height:t}),i=r.getContext(`webgl`,{alpha:!0,premultipliedAlpha:!1,depth:!1,stencil:!1,antialias:!1});i&&(i.clearColor(0,0,0,0),this.canvas=r,this.gl=i)}applyFilters(e,t,n,r,i,a){let o=this.gl,s=i.getContext(`2d`);if(!o||!s)return;let c;a&&(c=this.getCachedTexture(a,t));let l={originalWidth:t.width||t.naturalWidth||0,originalHeight:t.height||t.naturalHeight||0,sourceWidth:n,sourceHeight:r,destinationWidth:n,destinationHeight:r,context:o,sourceTexture:this.createTexture(o,n,r,c?void 0:t),targetTexture:this.createTexture(o,n,r),originalTexture:c||this.createTexture(o,n,r,c?void 0:t),passes:e.length,webgl:!0,aPosition:this.aPosition,programCache:this.programCache,pass:0,filterBackend:this,targetCanvas:i},u=o.createFramebuffer();return o.bindFramebuffer(o.FRAMEBUFFER,u),e.forEach(e=>{e&&e.applyTo(l)}),function(e){let t=e.targetCanvas,n=t.width,r=t.height,i=e.destinationWidth,a=e.destinationHeight;n===i&&r===a||(t.width=i,t.height=a)}(l),this.copyGLTo2D(o,l),o.bindTexture(o.TEXTURE_2D,null),o.deleteTexture(l.sourceTexture),o.deleteTexture(l.targetTexture),o.deleteFramebuffer(u),s.setTransform(1,0,0,1,0,0),l}dispose(){this.canvas&&(this.canvas=null,this.gl=null),this.clearWebGLCaches()}clearWebGLCaches(){this.programCache={},this.textureCache={}}createTexture(e,t,n,r,i){let{NEAREST:a,TEXTURE_2D:o,RGBA:s,UNSIGNED_BYTE:c,CLAMP_TO_EDGE:l,TEXTURE_MAG_FILTER:u,TEXTURE_MIN_FILTER:d,TEXTURE_WRAP_S:f,TEXTURE_WRAP_T:p}=e,m=e.createTexture();return e.bindTexture(o,m),e.texParameteri(o,u,i||a),e.texParameteri(o,d,i||a),e.texParameteri(o,f,l),e.texParameteri(o,p,l),r?e.texImage2D(o,0,s,s,c,r):e.texImage2D(o,0,s,t,n,0,s,c,null),m}getCachedTexture(e,t,n){let{textureCache:r}=this;if(r[e])return r[e];{let i=this.createTexture(this.gl,t.width,t.height,t,n);return i&&(r[e]=i),i}}evictCachesForKey(e){this.textureCache[e]&&(this.gl.deleteTexture(this.textureCache[e]),delete this.textureCache[e])}copyGLTo2D(e,t){let n=e.canvas,r=t.targetCanvas,i=r.getContext(`2d`);if(!i)return;i.translate(0,r.height),i.scale(1,-1);let a=n.height-r.height;i.drawImage(n,0,a,r.width,r.height,0,0,r.width,r.height)}copyGLTo2DPutImageData(e,t){let n=t.targetCanvas.getContext(`2d`),r=t.destinationWidth,i=t.destinationHeight,a=r*i*4;if(!n)return;let o=new Uint8Array(this.imageBuffer,0,a),s=new Uint8ClampedArray(this.imageBuffer,0,a);e.readPixels(0,0,r,i,e.RGBA,e.UNSIGNED_BYTE,o);let c=new ImageData(s,r,i);n.putImageData(c,0,0)}captureGPUInfo(){if(this.gpuInfo)return this.gpuInfo;let e=this.gl,t={renderer:``,vendor:``};if(!e)return t;let n=e.getExtension(`WEBGL_debug_renderer_info`);if(n){let r=e.getParameter(n.UNMASKED_RENDERER_WEBGL),i=e.getParameter(n.UNMASKED_VENDOR_WEBGL);r&&(t.renderer=r.toLowerCase()),i&&(t.vendor=i.toLowerCase())}return this.gpuInfo=t,t}};export{r as WebGLFilterBackend};
2
2
  //# sourceMappingURL=WebGLFilterBackend.min.mjs.map
@@ -1,4 +1,4 @@
1
- import { _defineProperty } from "../../_virtual/_@oxc-project_runtime@0.122.0/helpers/defineProperty.mjs";
1
+ import { _defineProperty } from "../../_virtual/_@oxc-project_runtime@0.126.0/helpers/defineProperty.mjs";
2
2
  import { config } from "../config.mjs";
3
3
  import { createCanvasElementFor } from "../util/misc/dom.mjs";
4
4
  //#region src/filters/WebGLFilterBackend.ts
@@ -1 +1 @@
1
- {"version":3,"file":"Gradient.d.ts","sourceRoot":"","sources":["../../../src/gradient/Gradient.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAClE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAQ1C,OAAO,KAAK,EACV,SAAS,EACT,cAAc,EACd,eAAe,EACf,YAAY,EACZ,aAAa,EACb,UAAU,EACV,u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Ac;gBAEb,OAAO,EAAE,eAAe,CAAC,CAAC,CAAC;IA0BvC;;;;OAIG;IACH,YAAY,CAAC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;IAU/C;;;;OAIG;IACH,QAAQ,CACN,mBAAmB,CAAC,EAAE,CAAC,MAAM,IAAI,GAAG,MAAM,CAAC,EAAE,GAC5C,uBAAuB,CAAC,CAAC,CAAC;IAgB7B;;;;OAIG;IACH,KAAK,CACH,MAAM,EAAE,YAAY,EACpB,EACE,mBAAmB,EAAE,YAAY,GAClC,GAAE;QAAE,mBAAmB,CAAC,EAAE,MAAM,CAAA;KAAO;IAkI1C;;;;OAIG;IACH,MAAM,CAAC,GAAG,EAAE,wBAAwB,GAAG,cAAc;WAcxC,UAAU,CACrB,OAAO,EAAE,eAAe,CAAC,QAAQ,CAAC,GACjC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;WACjB,UAAU,CACrB,OAAO,EAAE,eAAe,CAAC,QAAQ,CAAC,GACjC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;IAe9B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAyCG;IACH,MAAM,CAAC,WAAW,CAChB,EAAE,EAAE,kBAAkB,EACtB,QAAQ,EAAE,YAAY,EACtB,UAAU,EAAE,UAAU,GACrB,QAAQ,CAAC,YAAY,CAAC;CA2B1B"}
@@ -1,5 +1,5 @@
1
- import{_defineProperty as e}from"../../_virtual/_@oxc-project_runtime@0.122.0/helpers/defineProperty.min.mjs";import{iMatrix as t}from"../constants.min.mjs";import{classRegistry as n}from"../ClassRegistry.min.mjs";import{uid as r}from"../util/internals/uid.min.mjs";import{pick as i}from"../util/misc/pick.min.mjs";import{matrixToSVG as a}from"../util/misc/svgExport.min.mjs";import{isPath as o}from"../util/typeAssertions.min.mjs";import{escapeXml as s}from"../util/lang_string.min.mjs";import{parseTransformAttribute as c}from"../parser/parseTransformAttribute.min.mjs";import{linearDefaultCoords as l,radialDefaultCoords as u}from"./constants.min.mjs";import{parseColorStops as d}from"./parser/parseColorStops.min.mjs";import{parseGradientUnits as f,parseType as p}from"./parser/misc.min.mjs";import{parseCoords as m}from"./parser/parseCoords.min.mjs";var h=class{constructor(e){let{type:t=`linear`,gradientUnits:n=`pixels`,coords:i={},colorStops:a=[],offsetX:o=0,offsetY:s=0,gradientTransform:c,id:d}=e||{};Object.assign(this,{type:t,gradientUnits:n,coords:{...t===`radial`?u:l,...i},colorStops:a,offsetX:o,offsetY:s,gradientTransform:c,id:d?`${d}_${r()}`:r()})}addColorStop(e){for(let t in e)this.colorStops.push({offset:parseFloat(t),color:e[t]});return this}toObject(e){return{...i(this,e),type:this.type,coords:{...this.coords},colorStops:this.colorStops.map(e=>({...e})),offsetX:this.offsetX,offsetY:this.offsetY,gradientUnits:this.gradientUnits,gradientTransform:this.gradientTransform?[...this.gradientTransform]:void 0}}toSVG(e,{additionalTransform:n}={}){let r=[],i=this.gradientTransform?this.gradientTransform.concat():t.concat(),c=this.gradientUnits===`pixels`?`userSpaceOnUse`:`objectBoundingBox`,l=this.colorStops.map(e=>({...e})).sort((e,t)=>e.offset-t.offset),u=-this.offsetX,d=-this.offsetY;c===`objectBoundingBox`?(u/=e.width,d/=e.height):(u+=e.width/2,d+=e.height/2),o(e)&&this.gradientUnits!==`percentage`&&(u-=e.pathOffset.x,d-=e.pathOffset.y),i[4]-=u,i[5]-=d;let f=[`id="SVGID_${s(String(this.id))}"`,`gradientUnits="${c}"`,`gradientTransform="${n?n+` `:``}${a(i)}"`,``].join(` `),p=e=>parseFloat(String(e));if(this.type===`linear`){let{x1:e,y1:t,x2:n,y2:i}=this.coords,a=p(e),o=p(t),s=p(n),c=p(i);r.push(`<linearGradient `,f,` x1="`,a,`" y1="`,o,`" x2="`,s,`" y2="`,c,`">
2
- `)}else if(this.type===`radial`){let{x1:e,y1:t,x2:n,y2:i,r1:a,r2:o}=this.coords,s=p(e),c=p(t),u=p(n),d=p(i),m=p(a),h=p(o),g=m>h;r.push(`<radialGradient `,f,` cx="`,g?s:u,`" cy="`,g?c:d,`" r="`,g?m:h,`" fx="`,g?u:s,`" fy="`,g?d:c,`">
3
- `),g&&(l.reverse(),l.forEach(e=>{e.offset=1-e.offset}));let _=Math.min(m,h);if(_>0){let e=_/Math.max(m,h);l.forEach(t=>{t.offset+=e*(1-t.offset)})}}return l.forEach(({color:e,offset:t})=>{r.push(`<stop offset="${100*t}%" style="stop-color:${e};"/>\n`)}),r.push(this.type===`linear`?`</linearGradient>`:`</radialGradient>`,`
4
- `),r.join(``)}toLive(e){let{x1:t,y1:n,x2:r,y2:i,r1:a,r2:o}=this.coords,s=this.type===`linear`?e.createLinearGradient(t,n,r,i):e.createRadialGradient(t,n,a,r,i,o);return this.colorStops.forEach(({color:e,offset:t})=>{s.addColorStop(t,e)}),s}static async fromObject(e){let{colorStops:t,gradientTransform:n}=e;return new this({...e,colorStops:t?t.map(e=>({...e})):void 0,gradientTransform:n?[...n]:void 0})}static fromElement(e,t,n){let r=f(e),i=t._findCenterFromElement();return new this({id:e.getAttribute(`id`)||void 0,type:p(e),coords:m(e,{width:n.viewBoxWidth||n.width,height:n.viewBoxHeight||n.height}),colorStops:d(e,n.opacity),gradientUnits:r,gradientTransform:c(e.getAttribute(`gradientTransform`)||``),...r===`pixels`?{offsetX:t.width/2-i.x,offsetY:t.height/2-i.y}:{offsetX:0,offsetY:0}})}};e(h,`type`,`Gradient`),n.setClass(h,`gradient`),n.setClass(h,`linear`),n.setClass(h,`radial`);export{h as Gradient};
1
+ import{_defineProperty as e}from"../../_virtual/_@oxc-project_runtime@0.126.0/helpers/defineProperty.min.mjs";import{iMatrix as t}from"../constants.min.mjs";import{classRegistry as n}from"../ClassRegistry.min.mjs";import{uid as r}from"../util/internals/uid.min.mjs";import{pick as i}from"../util/misc/pick.min.mjs";import{matrixToSVG as a}from"../util/misc/svgExport.min.mjs";import{isPath as o}from"../util/typeAssertions.min.mjs";import{escapeXml as s}from"../util/lang_string.min.mjs";import{isSafeSvgStyleValue as c}from"../util/internals/svgExportCheck.min.mjs";import{Color as l}from"../color/Color.min.mjs";import{parseTransformAttribute as u}from"../parser/parseTransformAttribute.min.mjs";import{linearDefaultCoords as d,radialDefaultCoords as f}from"./constants.min.mjs";import{parseColorStops as p}from"./parser/parseColorStops.min.mjs";import{parseGradientUnits as m,parseType as h}from"./parser/misc.min.mjs";import{parseCoords as g}from"./parser/parseCoords.min.mjs";var _=class{constructor(e){let{type:t=`linear`,gradientUnits:n=`pixels`,coords:i={},colorStops:a=[],offsetX:o=0,offsetY:s=0,gradientTransform:c,id:l}=e||{};Object.assign(this,{type:t,gradientUnits:n,coords:{...t===`radial`?f:d,...i},colorStops:a,offsetX:o,offsetY:s,gradientTransform:c,id:l?`${l}_${r()}`:r()})}addColorStop(e){for(let t in e)this.colorStops.push({offset:parseFloat(t),color:e[t]});return this}toObject(e){return{...i(this,e),type:this.type,coords:{...this.coords},colorStops:this.colorStops.map(e=>({...e})),offsetX:this.offsetX,offsetY:this.offsetY,gradientUnits:this.gradientUnits,gradientTransform:this.gradientTransform?[...this.gradientTransform]:void 0}}toSVG(e,{additionalTransform:n}={}){let r=[],i=this.gradientTransform?this.gradientTransform.concat():t.concat(),u=this.gradientUnits===`pixels`?`userSpaceOnUse`:`objectBoundingBox`,d=this.colorStops.map(e=>({...e})).sort((e,t)=>e.offset-t.offset),f=-this.offsetX,p=-this.offsetY;u===`objectBoundingBox`?(f/=e.width,p/=e.height):(f+=e.width/2,p+=e.height/2),o(e)&&this.gradientUnits!==`percentage`&&(f-=e.pathOffset.x,p-=e.pathOffset.y),i[4]-=f,i[5]-=p;let m=[`id="SVGID_${s(String(this.id))}"`,`gradientUnits="${u}"`,`gradientTransform="${n?n+` `:``}${a(i)}"`,``].join(` `),h=e=>parseFloat(String(e));if(this.type===`linear`){let{x1:e,y1:t,x2:n,y2:i}=this.coords,a=h(e),o=h(t),s=h(n),c=h(i);r.push(`<linearGradient `,m,` x1="`,a,`" y1="`,o,`" x2="`,s,`" y2="`,c,`">
2
+ `)}else if(this.type===`radial`){let{x1:e,y1:t,x2:n,y2:i,r1:a,r2:o}=this.coords,s=h(e),c=h(t),l=h(n),u=h(i),f=h(a),p=h(o),g=f>p;r.push(`<radialGradient `,m,` cx="`,g?s:l,`" cy="`,g?c:u,`" r="`,g?f:p,`" fx="`,g?l:s,`" fy="`,g?u:c,`">
3
+ `),g&&(d.reverse(),d.forEach(e=>{e.offset=1-e.offset}));let _=Math.min(f,p);if(_>0){let e=_/Math.max(f,p);d.forEach(t=>{t.offset+=e*(1-t.offset)})}}return d.forEach(({color:e,offset:t})=>{let n=String(e),i=c(n)?n:new l(n).toRgba();r.push(`<stop offset="${100*t}%" style="stop-color:${s(i)};"/>\n`)}),r.push(this.type===`linear`?`</linearGradient>`:`</radialGradient>`,`
4
+ `),r.join(``)}toLive(e){let{x1:t,y1:n,x2:r,y2:i,r1:a,r2:o}=this.coords,s=this.type===`linear`?e.createLinearGradient(t,n,r,i):e.createRadialGradient(t,n,a,r,i,o);return this.colorStops.forEach(({color:e,offset:t})=>{s.addColorStop(t,e)}),s}static async fromObject(e){let{colorStops:t,gradientTransform:n}=e;return new this({...e,colorStops:t?t.map(e=>({...e})):void 0,gradientTransform:n?[...n]:void 0})}static fromElement(e,t,n){let r=m(e),i=t._findCenterFromElement();return new this({id:e.getAttribute(`id`)||void 0,type:h(e),coords:g(e,{width:n.viewBoxWidth||n.width,height:n.viewBoxHeight||n.height}),colorStops:p(e,n.opacity),gradientUnits:r,gradientTransform:u(e.getAttribute(`gradientTransform`)||``),...r===`pixels`?{offsetX:t.width/2-i.x,offsetY:t.height/2-i.y}:{offsetX:0,offsetY:0}})}};e(_,`type`,`Gradient`),n.setClass(_,`gradient`),n.setClass(_,`linear`),n.setClass(_,`radial`);export{_ as Gradient};
5
5
  //# sourceMappingURL=Gradient.min.mjs.map