three-stdlib 2.35.3 → 2.35.4

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 (514) hide show
  1. package/_polyfill/CapsuleGeometry.cjs +20 -17
  2. package/_polyfill/CapsuleGeometry.cjs.map +1 -1
  3. package/_polyfill/CapsuleGeometry.js +20 -17
  4. package/_polyfill/CapsuleGeometry.js.map +1 -1
  5. package/_polyfill/constants.cjs +1 -1
  6. package/_polyfill/constants.cjs.map +1 -1
  7. package/_polyfill/constants.js +1 -1
  8. package/_polyfill/constants.js.map +1 -1
  9. package/animation/AnimationClipCreator.cjs +13 -13
  10. package/animation/AnimationClipCreator.cjs.map +1 -1
  11. package/animation/AnimationClipCreator.js +13 -13
  12. package/animation/AnimationClipCreator.js.map +1 -1
  13. package/animation/CCDIKSolver.cjs +11 -11
  14. package/animation/CCDIKSolver.cjs.map +1 -1
  15. package/animation/CCDIKSolver.js +12 -12
  16. package/animation/CCDIKSolver.js.map +1 -1
  17. package/animation/MMDAnimationHelper.cjs +1 -1
  18. package/animation/MMDAnimationHelper.cjs.map +1 -1
  19. package/animation/MMDAnimationHelper.js +1 -1
  20. package/animation/MMDAnimationHelper.js.map +1 -1
  21. package/animation/MMDPhysics.cjs +4 -4
  22. package/animation/MMDPhysics.cjs.map +1 -1
  23. package/animation/MMDPhysics.js +4 -4
  24. package/animation/MMDPhysics.js.map +1 -1
  25. package/controls/ArcballControls.cjs +2 -2
  26. package/controls/ArcballControls.cjs.map +1 -1
  27. package/controls/ArcballControls.js +3 -3
  28. package/controls/ArcballControls.js.map +1 -1
  29. package/controls/FirstPersonControls.cjs +1 -1
  30. package/controls/FirstPersonControls.cjs.map +1 -1
  31. package/controls/FirstPersonControls.js +1 -1
  32. package/controls/FirstPersonControls.js.map +1 -1
  33. package/controls/OrbitControls.cjs +2 -2
  34. package/controls/OrbitControls.cjs.map +1 -1
  35. package/controls/OrbitControls.js +3 -3
  36. package/controls/OrbitControls.js.map +1 -1
  37. package/controls/PointerLockControls.cjs +2 -2
  38. package/controls/PointerLockControls.cjs.map +1 -1
  39. package/controls/PointerLockControls.js +3 -3
  40. package/controls/PointerLockControls.js.map +1 -1
  41. package/csm/CSM.cjs +4 -4
  42. package/csm/CSM.cjs.map +1 -1
  43. package/csm/CSM.js +5 -5
  44. package/csm/CSM.js.map +1 -1
  45. package/csm/CSMFrustum.cjs +1 -1
  46. package/csm/CSMFrustum.cjs.map +1 -1
  47. package/csm/CSMFrustum.js +2 -2
  48. package/csm/CSMFrustum.js.map +1 -1
  49. package/deprecated/Geometry.cjs +722 -715
  50. package/deprecated/Geometry.cjs.map +1 -1
  51. package/deprecated/Geometry.js +723 -716
  52. package/deprecated/Geometry.js.map +1 -1
  53. package/effects/AnaglyphEffect.cjs +2 -1
  54. package/effects/AnaglyphEffect.cjs.map +1 -1
  55. package/effects/AnaglyphEffect.js +3 -2
  56. package/effects/AnaglyphEffect.js.map +1 -1
  57. package/effects/OutlineEffect.cjs +2 -1
  58. package/effects/OutlineEffect.cjs.map +1 -1
  59. package/effects/OutlineEffect.js +3 -2
  60. package/effects/OutlineEffect.js.map +1 -1
  61. package/effects/ParallaxBarrierEffect.cjs +2 -1
  62. package/effects/ParallaxBarrierEffect.cjs.map +1 -1
  63. package/effects/ParallaxBarrierEffect.js +3 -2
  64. package/effects/ParallaxBarrierEffect.js.map +1 -1
  65. package/exporters/DRACOExporter.cjs +133 -122
  66. package/exporters/DRACOExporter.cjs.map +1 -1
  67. package/exporters/DRACOExporter.d.ts +23 -21
  68. package/exporters/DRACOExporter.js +133 -122
  69. package/exporters/DRACOExporter.js.map +1 -1
  70. package/exporters/GLTFExporter.cjs +170 -167
  71. package/exporters/GLTFExporter.cjs.map +1 -1
  72. package/exporters/GLTFExporter.js +170 -167
  73. package/exporters/GLTFExporter.js.map +1 -1
  74. package/geometries/LightningStrike.cjs +524 -515
  75. package/geometries/LightningStrike.cjs.map +1 -1
  76. package/geometries/LightningStrike.js +524 -515
  77. package/geometries/LightningStrike.js.map +1 -1
  78. package/geometries/RoundedBoxGeometry.cjs +1 -1
  79. package/geometries/RoundedBoxGeometry.cjs.map +1 -1
  80. package/geometries/RoundedBoxGeometry.js +2 -2
  81. package/geometries/RoundedBoxGeometry.js.map +1 -1
  82. package/helpers/RaycasterHelper.cjs +2 -2
  83. package/helpers/RaycasterHelper.cjs.map +1 -1
  84. package/helpers/RaycasterHelper.js +3 -3
  85. package/helpers/RaycasterHelper.js.map +1 -1
  86. package/helpers/VertexNormalsHelper.cjs +3 -3
  87. package/helpers/VertexNormalsHelper.cjs.map +1 -1
  88. package/helpers/VertexNormalsHelper.js +4 -4
  89. package/helpers/VertexNormalsHelper.js.map +1 -1
  90. package/helpers/VertexTangentsHelper.cjs +2 -2
  91. package/helpers/VertexTangentsHelper.cjs.map +1 -1
  92. package/helpers/VertexTangentsHelper.js +3 -3
  93. package/helpers/VertexTangentsHelper.js.map +1 -1
  94. package/interactive/InteractiveGroup.cjs +1 -1
  95. package/interactive/InteractiveGroup.cjs.map +1 -1
  96. package/interactive/InteractiveGroup.js +2 -2
  97. package/interactive/InteractiveGroup.js.map +1 -1
  98. package/interactive/SelectionBox.cjs +15 -15
  99. package/interactive/SelectionBox.cjs.map +1 -1
  100. package/interactive/SelectionBox.js +16 -16
  101. package/interactive/SelectionBox.js.map +1 -1
  102. package/libs/chevrotain.cjs +1 -1
  103. package/libs/chevrotain.cjs.map +1 -1
  104. package/libs/chevrotain.js +1 -1
  105. package/libs/chevrotain.js.map +1 -1
  106. package/libs/lottie.cjs +1 -1
  107. package/libs/lottie.cjs.map +1 -1
  108. package/libs/lottie.js +1 -1
  109. package/libs/lottie.js.map +1 -1
  110. package/libs/opentype.cjs +1 -1
  111. package/libs/opentype.cjs.map +1 -1
  112. package/libs/opentype.js +1 -1
  113. package/libs/opentype.js.map +1 -1
  114. package/lights/LightProbeGenerator.cjs +5 -5
  115. package/lights/LightProbeGenerator.cjs.map +1 -1
  116. package/lights/LightProbeGenerator.js +5 -5
  117. package/lights/LightProbeGenerator.js.map +1 -1
  118. package/lights/RectAreaLightUniformsLib.cjs +3 -3
  119. package/lights/RectAreaLightUniformsLib.cjs.map +1 -1
  120. package/lights/RectAreaLightUniformsLib.js +3 -3
  121. package/lights/RectAreaLightUniformsLib.js.map +1 -1
  122. package/lines/LineMaterial.cjs +2 -1
  123. package/lines/LineMaterial.cjs.map +1 -1
  124. package/lines/LineMaterial.js +3 -2
  125. package/lines/LineMaterial.js.map +1 -1
  126. package/lines/LineSegments2.cjs +13 -13
  127. package/lines/LineSegments2.cjs.map +1 -1
  128. package/lines/LineSegments2.js +14 -14
  129. package/lines/LineSegments2.js.map +1 -1
  130. package/lines/LineSegmentsGeometry.cjs +2 -2
  131. package/lines/LineSegmentsGeometry.cjs.map +1 -1
  132. package/lines/LineSegmentsGeometry.js +3 -3
  133. package/lines/LineSegmentsGeometry.js.map +1 -1
  134. package/lines/Wireframe.cjs +3 -3
  135. package/lines/Wireframe.cjs.map +1 -1
  136. package/lines/Wireframe.js +4 -4
  137. package/lines/Wireframe.js.map +1 -1
  138. package/loaders/BasisTextureLoader.cjs +441 -435
  139. package/loaders/BasisTextureLoader.cjs.map +1 -1
  140. package/loaders/BasisTextureLoader.js +441 -435
  141. package/loaders/BasisTextureLoader.js.map +1 -1
  142. package/loaders/EXRLoader.cjs +2 -1
  143. package/loaders/EXRLoader.cjs.map +1 -1
  144. package/loaders/EXRLoader.js +3 -2
  145. package/loaders/EXRLoader.js.map +1 -1
  146. package/loaders/FBXLoader.cjs +2 -2
  147. package/loaders/FBXLoader.cjs.map +1 -1
  148. package/loaders/FBXLoader.js +2 -2
  149. package/loaders/FBXLoader.js.map +1 -1
  150. package/loaders/FontLoader.cjs +2 -2
  151. package/loaders/FontLoader.cjs.map +1 -1
  152. package/loaders/FontLoader.d.ts +2 -2
  153. package/loaders/FontLoader.js +2 -2
  154. package/loaders/FontLoader.js.map +1 -1
  155. package/loaders/GLTFLoader.cjs +2 -2
  156. package/loaders/GLTFLoader.cjs.map +1 -1
  157. package/loaders/GLTFLoader.js +2 -2
  158. package/loaders/GLTFLoader.js.map +1 -1
  159. package/loaders/KTX2Loader.cjs +377 -374
  160. package/loaders/KTX2Loader.cjs.map +1 -1
  161. package/loaders/KTX2Loader.js +377 -374
  162. package/loaders/KTX2Loader.js.map +1 -1
  163. package/loaders/LDrawLoader.cjs +5 -4
  164. package/loaders/LDrawLoader.cjs.map +1 -1
  165. package/loaders/LDrawLoader.js +6 -5
  166. package/loaders/LDrawLoader.js.map +1 -1
  167. package/loaders/OBJLoader.cjs +5 -5
  168. package/loaders/OBJLoader.cjs.map +1 -1
  169. package/loaders/OBJLoader.js +6 -6
  170. package/loaders/OBJLoader.js.map +1 -1
  171. package/loaders/PRWMLoader.cjs +46 -43
  172. package/loaders/PRWMLoader.cjs.map +1 -1
  173. package/loaders/PRWMLoader.js +46 -43
  174. package/loaders/PRWMLoader.js.map +1 -1
  175. package/loaders/SVGLoader.cjs +1694 -1688
  176. package/loaders/SVGLoader.cjs.map +1 -1
  177. package/loaders/SVGLoader.js +1694 -1688
  178. package/loaders/SVGLoader.js.map +1 -1
  179. package/loaders/XLoader.cjs +1 -1
  180. package/loaders/XLoader.cjs.map +1 -1
  181. package/loaders/XLoader.js +1 -1
  182. package/loaders/XLoader.js.map +1 -1
  183. package/math/Capsule.cjs +3 -3
  184. package/math/Capsule.cjs.map +1 -1
  185. package/math/Capsule.js +3 -3
  186. package/math/Capsule.js.map +1 -1
  187. package/math/ColorConverter.cjs +9 -9
  188. package/math/ColorConverter.cjs.map +1 -1
  189. package/math/ColorConverter.js +9 -9
  190. package/math/ColorConverter.js.map +1 -1
  191. package/math/ConvexHull.cjs +53 -50
  192. package/math/ConvexHull.cjs.map +1 -1
  193. package/math/ConvexHull.js +53 -50
  194. package/math/ConvexHull.js.map +1 -1
  195. package/math/ImprovedNoise.cjs +1 -1
  196. package/math/ImprovedNoise.cjs.map +1 -1
  197. package/math/ImprovedNoise.js +1 -1
  198. package/math/ImprovedNoise.js.map +1 -1
  199. package/math/MeshSurfaceSampler.cjs +2 -2
  200. package/math/MeshSurfaceSampler.cjs.map +1 -1
  201. package/math/MeshSurfaceSampler.js +2 -2
  202. package/math/MeshSurfaceSampler.js.map +1 -1
  203. package/math/OBB.cjs +14 -14
  204. package/math/OBB.cjs.map +1 -1
  205. package/math/OBB.js +15 -15
  206. package/math/OBB.js.map +1 -1
  207. package/math/Octree.cjs +7 -7
  208. package/math/Octree.cjs.map +1 -1
  209. package/math/Octree.js +8 -8
  210. package/math/Octree.js.map +1 -1
  211. package/misc/ConvexObjectBreaker.cjs +271 -268
  212. package/misc/ConvexObjectBreaker.cjs.map +1 -1
  213. package/misc/ConvexObjectBreaker.js +272 -269
  214. package/misc/ConvexObjectBreaker.js.map +1 -1
  215. package/misc/Gyroscope.cjs +6 -6
  216. package/misc/Gyroscope.cjs.map +1 -1
  217. package/misc/Gyroscope.js +7 -7
  218. package/misc/Gyroscope.js.map +1 -1
  219. package/modifiers/CurveModifier.cjs +1 -1
  220. package/modifiers/CurveModifier.cjs.map +1 -1
  221. package/modifiers/CurveModifier.js +2 -2
  222. package/modifiers/CurveModifier.js.map +1 -1
  223. package/modifiers/SimplifyModifier.cjs +2 -2
  224. package/modifiers/SimplifyModifier.cjs.map +1 -1
  225. package/modifiers/SimplifyModifier.js +2 -2
  226. package/modifiers/SimplifyModifier.js.map +1 -1
  227. package/objects/BatchedMesh.cjs +2 -2
  228. package/objects/BatchedMesh.cjs.map +1 -1
  229. package/objects/BatchedMesh.js +3 -3
  230. package/objects/BatchedMesh.js.map +1 -1
  231. package/objects/GroundProjectedEnv.cjs +2 -1
  232. package/objects/GroundProjectedEnv.cjs.map +1 -1
  233. package/objects/GroundProjectedEnv.js +3 -2
  234. package/objects/GroundProjectedEnv.js.map +1 -1
  235. package/objects/Lensflare.cjs +209 -206
  236. package/objects/Lensflare.cjs.map +1 -1
  237. package/objects/Lensflare.js +209 -206
  238. package/objects/Lensflare.js.map +1 -1
  239. package/objects/Reflector.cjs +154 -146
  240. package/objects/Reflector.cjs.map +1 -1
  241. package/objects/Reflector.js +154 -146
  242. package/objects/Reflector.js.map +1 -1
  243. package/objects/ReflectorForSSRPass.cjs +183 -180
  244. package/objects/ReflectorForSSRPass.cjs.map +1 -1
  245. package/objects/ReflectorForSSRPass.js +183 -180
  246. package/objects/ReflectorForSSRPass.js.map +1 -1
  247. package/objects/Refractor.cjs +164 -161
  248. package/objects/Refractor.cjs.map +1 -1
  249. package/objects/Refractor.js +164 -161
  250. package/objects/Refractor.js.map +1 -1
  251. package/objects/ShadowMesh.cjs +1 -1
  252. package/objects/ShadowMesh.cjs.map +1 -1
  253. package/objects/ShadowMesh.js +2 -2
  254. package/objects/ShadowMesh.js.map +1 -1
  255. package/objects/Sky.cjs +35 -32
  256. package/objects/Sky.cjs.map +1 -1
  257. package/objects/Sky.d.ts +100 -6
  258. package/objects/Sky.js +35 -32
  259. package/objects/Sky.js.map +1 -1
  260. package/objects/Water.cjs +2 -1
  261. package/objects/Water.cjs.map +1 -1
  262. package/objects/Water.js +3 -2
  263. package/objects/Water.js.map +1 -1
  264. package/objects/Water2.cjs +143 -140
  265. package/objects/Water2.cjs.map +1 -1
  266. package/objects/Water2.js +143 -140
  267. package/objects/Water2.js.map +1 -1
  268. package/package.json +1 -1
  269. package/postprocessing/SAOPass.cjs +267 -264
  270. package/postprocessing/SAOPass.cjs.map +1 -1
  271. package/postprocessing/SAOPass.js +267 -264
  272. package/postprocessing/SAOPass.js.map +1 -1
  273. package/postprocessing/SSAOPass.cjs +253 -250
  274. package/postprocessing/SSAOPass.cjs.map +1 -1
  275. package/postprocessing/SSAOPass.js +253 -250
  276. package/postprocessing/SSAOPass.js.map +1 -1
  277. package/postprocessing/SSRPass.cjs +379 -376
  278. package/postprocessing/SSRPass.cjs.map +1 -1
  279. package/postprocessing/SSRPass.js +379 -376
  280. package/postprocessing/SSRPass.js.map +1 -1
  281. package/postprocessing/UnrealBloomPass.cjs +205 -202
  282. package/postprocessing/UnrealBloomPass.cjs.map +1 -1
  283. package/postprocessing/UnrealBloomPass.js +205 -202
  284. package/postprocessing/UnrealBloomPass.js.map +1 -1
  285. package/renderers/CSS2DRenderer.cjs +5 -5
  286. package/renderers/CSS2DRenderer.cjs.map +1 -1
  287. package/renderers/CSS2DRenderer.js +5 -5
  288. package/renderers/CSS2DRenderer.js.map +1 -1
  289. package/renderers/CSS3DRenderer.cjs +5 -5
  290. package/renderers/CSS3DRenderer.cjs.map +1 -1
  291. package/renderers/CSS3DRenderer.js +6 -6
  292. package/renderers/CSS3DRenderer.js.map +1 -1
  293. package/shaders/ACESFilmicToneMappingShader.cjs +71 -46
  294. package/shaders/ACESFilmicToneMappingShader.cjs.map +1 -1
  295. package/shaders/ACESFilmicToneMappingShader.js +71 -46
  296. package/shaders/ACESFilmicToneMappingShader.js.map +1 -1
  297. package/shaders/AfterimageShader.cjs +41 -22
  298. package/shaders/AfterimageShader.cjs.map +1 -1
  299. package/shaders/AfterimageShader.js +41 -22
  300. package/shaders/AfterimageShader.js.map +1 -1
  301. package/shaders/BasicShader.cjs +20 -6
  302. package/shaders/BasicShader.cjs.map +1 -1
  303. package/shaders/BasicShader.js +20 -6
  304. package/shaders/BasicShader.js.map +1 -1
  305. package/shaders/BleachBypassShader.cjs +46 -26
  306. package/shaders/BleachBypassShader.cjs.map +1 -1
  307. package/shaders/BleachBypassShader.js +46 -26
  308. package/shaders/BleachBypassShader.js.map +1 -1
  309. package/shaders/BlendShader.cjs +33 -19
  310. package/shaders/BlendShader.cjs.map +1 -1
  311. package/shaders/BlendShader.js +33 -19
  312. package/shaders/BlendShader.js.map +1 -1
  313. package/shaders/BokehShader.cjs +117 -90
  314. package/shaders/BokehShader.cjs.map +1 -1
  315. package/shaders/BokehShader.js +117 -90
  316. package/shaders/BokehShader.js.map +1 -1
  317. package/shaders/BokehShader2.cjs +333 -232
  318. package/shaders/BokehShader2.cjs.map +1 -1
  319. package/shaders/BokehShader2.js +333 -232
  320. package/shaders/BokehShader2.js.map +1 -1
  321. package/shaders/BrightnessContrastShader.cjs +38 -22
  322. package/shaders/BrightnessContrastShader.cjs.map +1 -1
  323. package/shaders/BrightnessContrastShader.js +38 -22
  324. package/shaders/BrightnessContrastShader.js.map +1 -1
  325. package/shaders/ColorCorrectionShader.cjs +35 -21
  326. package/shaders/ColorCorrectionShader.cjs.map +1 -1
  327. package/shaders/ColorCorrectionShader.js +35 -21
  328. package/shaders/ColorCorrectionShader.js.map +1 -1
  329. package/shaders/ColorifyShader.cjs +34 -19
  330. package/shaders/ColorifyShader.cjs.map +1 -1
  331. package/shaders/ColorifyShader.js +34 -19
  332. package/shaders/ColorifyShader.js.map +1 -1
  333. package/shaders/ConvolutionShader.cjs +43 -24
  334. package/shaders/ConvolutionShader.cjs.map +1 -1
  335. package/shaders/ConvolutionShader.js +43 -24
  336. package/shaders/ConvolutionShader.js.map +1 -1
  337. package/shaders/CopyShader.cjs +30 -16
  338. package/shaders/CopyShader.cjs.map +1 -1
  339. package/shaders/CopyShader.js +30 -16
  340. package/shaders/CopyShader.js.map +1 -1
  341. package/shaders/DOFMipMapShader.cjs +38 -21
  342. package/shaders/DOFMipMapShader.cjs.map +1 -1
  343. package/shaders/DOFMipMapShader.js +38 -21
  344. package/shaders/DOFMipMapShader.js.map +1 -1
  345. package/shaders/DepthLimitedBlurShader.cjs +98 -69
  346. package/shaders/DepthLimitedBlurShader.cjs.map +1 -1
  347. package/shaders/DepthLimitedBlurShader.js +98 -69
  348. package/shaders/DepthLimitedBlurShader.js.map +1 -1
  349. package/shaders/DigitalGlitch.cjs +70 -59
  350. package/shaders/DigitalGlitch.cjs.map +1 -1
  351. package/shaders/DigitalGlitch.js +70 -59
  352. package/shaders/DigitalGlitch.js.map +1 -1
  353. package/shaders/DotScreenShader.cjs +49 -28
  354. package/shaders/DotScreenShader.cjs.map +1 -1
  355. package/shaders/DotScreenShader.js +49 -28
  356. package/shaders/DotScreenShader.js.map +1 -1
  357. package/shaders/FXAAShader.cjs +1098 -1089
  358. package/shaders/FXAAShader.cjs.map +1 -1
  359. package/shaders/FXAAShader.js +1098 -1089
  360. package/shaders/FXAAShader.js.map +1 -1
  361. package/shaders/FilmShader.cjs +57 -29
  362. package/shaders/FilmShader.cjs.map +1 -1
  363. package/shaders/FilmShader.js +57 -29
  364. package/shaders/FilmShader.js.map +1 -1
  365. package/shaders/FocusShader.cjs +70 -43
  366. package/shaders/FocusShader.cjs.map +1 -1
  367. package/shaders/FocusShader.js +70 -43
  368. package/shaders/FocusShader.js.map +1 -1
  369. package/shaders/FreiChenShader.cjs +74 -53
  370. package/shaders/FreiChenShader.cjs.map +1 -1
  371. package/shaders/FreiChenShader.js +74 -53
  372. package/shaders/FreiChenShader.js.map +1 -1
  373. package/shaders/FresnelShader.cjs +55 -35
  374. package/shaders/FresnelShader.cjs.map +1 -1
  375. package/shaders/FresnelShader.js +55 -35
  376. package/shaders/FresnelShader.js.map +1 -1
  377. package/shaders/GammaCorrectionShader.cjs +33 -19
  378. package/shaders/GammaCorrectionShader.cjs.map +1 -1
  379. package/shaders/GammaCorrectionShader.js +33 -19
  380. package/shaders/GammaCorrectionShader.js.map +1 -1
  381. package/shaders/GodRaysShader.cjs +193 -116
  382. package/shaders/GodRaysShader.cjs.map +1 -1
  383. package/shaders/GodRaysShader.js +193 -116
  384. package/shaders/GodRaysShader.js.map +1 -1
  385. package/shaders/HalftoneShader.cjs +270 -192
  386. package/shaders/HalftoneShader.cjs.map +1 -1
  387. package/shaders/HalftoneShader.js +270 -192
  388. package/shaders/HalftoneShader.js.map +1 -1
  389. package/shaders/HorizontalTiltShiftShader.cjs +43 -27
  390. package/shaders/HorizontalTiltShiftShader.cjs.map +1 -1
  391. package/shaders/HorizontalTiltShiftShader.js +43 -27
  392. package/shaders/HorizontalTiltShiftShader.js.map +1 -1
  393. package/shaders/HueSaturationShader.cjs +47 -31
  394. package/shaders/HueSaturationShader.cjs.map +1 -1
  395. package/shaders/HueSaturationShader.js +47 -31
  396. package/shaders/HueSaturationShader.js.map +1 -1
  397. package/shaders/KaleidoShader.cjs +37 -24
  398. package/shaders/KaleidoShader.cjs.map +1 -1
  399. package/shaders/KaleidoShader.js +37 -24
  400. package/shaders/KaleidoShader.js.map +1 -1
  401. package/shaders/LuminosityHighPassShader.cjs +43 -24
  402. package/shaders/LuminosityHighPassShader.cjs.map +1 -1
  403. package/shaders/LuminosityHighPassShader.js +43 -24
  404. package/shaders/LuminosityHighPassShader.js.map +1 -1
  405. package/shaders/LuminosityShader.cjs +34 -17
  406. package/shaders/LuminosityShader.cjs.map +1 -1
  407. package/shaders/LuminosityShader.js +34 -17
  408. package/shaders/LuminosityShader.js.map +1 -1
  409. package/shaders/MirrorShader.cjs +39 -26
  410. package/shaders/MirrorShader.cjs.map +1 -1
  411. package/shaders/MirrorShader.js +39 -26
  412. package/shaders/MirrorShader.js.map +1 -1
  413. package/shaders/NormalMapShader.cjs +36 -21
  414. package/shaders/NormalMapShader.cjs.map +1 -1
  415. package/shaders/NormalMapShader.js +36 -21
  416. package/shaders/NormalMapShader.js.map +1 -1
  417. package/shaders/ParallaxShader.cjs +147 -97
  418. package/shaders/ParallaxShader.cjs.map +1 -1
  419. package/shaders/ParallaxShader.js +147 -97
  420. package/shaders/ParallaxShader.js.map +1 -1
  421. package/shaders/PixelShader.cjs +31 -18
  422. package/shaders/PixelShader.cjs.map +1 -1
  423. package/shaders/PixelShader.js +31 -18
  424. package/shaders/PixelShader.js.map +1 -1
  425. package/shaders/RGBShiftShader.cjs +33 -20
  426. package/shaders/RGBShiftShader.cjs.map +1 -1
  427. package/shaders/RGBShiftShader.js +33 -20
  428. package/shaders/RGBShiftShader.js.map +1 -1
  429. package/shaders/SAOShader.cjs +154 -117
  430. package/shaders/SAOShader.cjs.map +1 -1
  431. package/shaders/SAOShader.js +154 -117
  432. package/shaders/SAOShader.js.map +1 -1
  433. package/shaders/SMAAShader.cjs +358 -270
  434. package/shaders/SMAAShader.cjs.map +1 -1
  435. package/shaders/SMAAShader.js +358 -270
  436. package/shaders/SMAAShader.js.map +1 -1
  437. package/shaders/SSAOShader.cjs +236 -142
  438. package/shaders/SSAOShader.cjs.map +1 -1
  439. package/shaders/SSAOShader.js +236 -142
  440. package/shaders/SSAOShader.js.map +1 -1
  441. package/shaders/SSRShader.cjs +4 -4
  442. package/shaders/SSRShader.cjs.map +1 -1
  443. package/shaders/SSRShader.js +4 -4
  444. package/shaders/SSRShader.js.map +1 -1
  445. package/shaders/SepiaShader.cjs +36 -20
  446. package/shaders/SepiaShader.cjs.map +1 -1
  447. package/shaders/SepiaShader.js +36 -20
  448. package/shaders/SepiaShader.js.map +1 -1
  449. package/shaders/SobelOperatorShader.cjs +64 -37
  450. package/shaders/SobelOperatorShader.cjs.map +1 -1
  451. package/shaders/SobelOperatorShader.js +64 -37
  452. package/shaders/SobelOperatorShader.js.map +1 -1
  453. package/shaders/TechnicolorShader.cjs +29 -16
  454. package/shaders/TechnicolorShader.cjs.map +1 -1
  455. package/shaders/TechnicolorShader.js +29 -16
  456. package/shaders/TechnicolorShader.js.map +1 -1
  457. package/shaders/ToneMapShader.cjs +55 -35
  458. package/shaders/ToneMapShader.cjs.map +1 -1
  459. package/shaders/ToneMapShader.js +55 -35
  460. package/shaders/ToneMapShader.js.map +1 -1
  461. package/shaders/ToonShader.cjs +275 -165
  462. package/shaders/ToonShader.cjs.map +1 -1
  463. package/shaders/ToonShader.js +275 -165
  464. package/shaders/ToonShader.js.map +1 -1
  465. package/shaders/TriangleBlurShader.cjs +50 -27
  466. package/shaders/TriangleBlurShader.cjs.map +1 -1
  467. package/shaders/TriangleBlurShader.js +50 -27
  468. package/shaders/TriangleBlurShader.js.map +1 -1
  469. package/shaders/UnpackDepthRGBAShader.cjs +32 -17
  470. package/shaders/UnpackDepthRGBAShader.cjs.map +1 -1
  471. package/shaders/UnpackDepthRGBAShader.js +32 -17
  472. package/shaders/UnpackDepthRGBAShader.js.map +1 -1
  473. package/shaders/VerticalTiltShiftShader.cjs +43 -27
  474. package/shaders/VerticalTiltShiftShader.cjs.map +1 -1
  475. package/shaders/VerticalTiltShiftShader.js +43 -27
  476. package/shaders/VerticalTiltShiftShader.js.map +1 -1
  477. package/shaders/VignetteShader.cjs +43 -27
  478. package/shaders/VignetteShader.cjs.map +1 -1
  479. package/shaders/VignetteShader.js +43 -27
  480. package/shaders/VignetteShader.js.map +1 -1
  481. package/shaders/VolumeShader.cjs +264 -213
  482. package/shaders/VolumeShader.cjs.map +1 -1
  483. package/shaders/VolumeShader.js +264 -213
  484. package/shaders/VolumeShader.js.map +1 -1
  485. package/shaders/WaterRefractionShader.cjs +63 -35
  486. package/shaders/WaterRefractionShader.cjs.map +1 -1
  487. package/shaders/WaterRefractionShader.js +63 -35
  488. package/shaders/WaterRefractionShader.js.map +1 -1
  489. package/utils/GeometryCompressionUtils.cjs +2 -1
  490. package/utils/GeometryCompressionUtils.cjs.map +1 -1
  491. package/utils/GeometryCompressionUtils.js +3 -2
  492. package/utils/GeometryCompressionUtils.js.map +1 -1
  493. package/utils/RoughnessMipmapper.cjs +3 -3
  494. package/utils/RoughnessMipmapper.cjs.map +1 -1
  495. package/utils/RoughnessMipmapper.js +4 -4
  496. package/utils/RoughnessMipmapper.js.map +1 -1
  497. package/webxr/ARButton.cjs +109 -106
  498. package/webxr/ARButton.cjs.map +1 -1
  499. package/webxr/ARButton.d.ts +4 -3
  500. package/webxr/ARButton.js +109 -106
  501. package/webxr/ARButton.js.map +1 -1
  502. package/webxr/OculusHandPointerModel.cjs +2 -2
  503. package/webxr/OculusHandPointerModel.cjs.map +1 -1
  504. package/webxr/OculusHandPointerModel.js +2 -2
  505. package/webxr/OculusHandPointerModel.js.map +1 -1
  506. package/webxr/VRButton.cjs +98 -95
  507. package/webxr/VRButton.cjs.map +1 -1
  508. package/webxr/VRButton.d.ts +6 -5
  509. package/webxr/VRButton.js +98 -95
  510. package/webxr/VRButton.js.map +1 -1
  511. package/webxr/XRHandPrimitiveModel.cjs +2 -2
  512. package/webxr/XRHandPrimitiveModel.cjs.map +1 -1
  513. package/webxr/XRHandPrimitiveModel.js +3 -3
  514. package/webxr/XRHandPrimitiveModel.js.map +1 -1
@@ -1,1816 +1,1822 @@
1
1
  import { Loader, FileLoader, Matrix3, Vector2, Vector3, ShapeUtils, Box2, Shape, Path, BufferGeometry, Float32BufferAttribute, ShapePath } from "three";
2
2
  const COLOR_SPACE_SVG = "srgb";
3
- class SVGLoader extends Loader {
4
- constructor(manager) {
5
- super(manager);
6
- this.defaultDPI = 90;
7
- this.defaultUnit = "px";
8
- }
9
- load(url, onLoad, onProgress, onError) {
10
- const scope = this;
11
- const loader = new FileLoader(scope.manager);
12
- loader.setPath(scope.path);
13
- loader.setRequestHeader(scope.requestHeader);
14
- loader.setWithCredentials(scope.withCredentials);
15
- loader.load(
16
- url,
17
- function(text) {
18
- try {
19
- onLoad(scope.parse(text));
20
- } catch (e) {
21
- if (onError) {
22
- onError(e);
23
- } else {
24
- console.error(e);
25
- }
26
- scope.manager.itemError(url);
27
- }
28
- },
29
- onProgress,
30
- onError
31
- );
32
- }
33
- parse(text) {
34
- const scope = this;
35
- function parseNode(node, style) {
36
- if (node.nodeType !== 1)
37
- return;
38
- const transform = getNodeTransform(node);
39
- let isDefsNode = false;
40
- let path = null;
41
- switch (node.nodeName) {
42
- case "svg":
43
- style = parseStyle(node, style);
44
- break;
45
- case "style":
46
- parseCSSStylesheet(node);
47
- break;
48
- case "g":
49
- style = parseStyle(node, style);
50
- break;
51
- case "path":
52
- style = parseStyle(node, style);
53
- if (node.hasAttribute("d"))
54
- path = parsePathNode(node);
55
- break;
56
- case "rect":
57
- style = parseStyle(node, style);
58
- path = parseRectNode(node);
59
- break;
60
- case "polygon":
61
- style = parseStyle(node, style);
62
- path = parsePolygonNode(node);
63
- break;
64
- case "polyline":
65
- style = parseStyle(node, style);
66
- path = parsePolylineNode(node);
67
- break;
68
- case "circle":
69
- style = parseStyle(node, style);
70
- path = parseCircleNode(node);
71
- break;
72
- case "ellipse":
73
- style = parseStyle(node, style);
74
- path = parseEllipseNode(node);
75
- break;
76
- case "line":
77
- style = parseStyle(node, style);
78
- path = parseLineNode(node);
79
- break;
80
- case "defs":
81
- isDefsNode = true;
82
- break;
83
- case "use":
84
- style = parseStyle(node, style);
85
- const href = node.getAttributeNS("http://www.w3.org/1999/xlink", "href") || "";
86
- const usedNodeId = href.substring(1);
87
- const usedNode = node.viewportElement.getElementById(usedNodeId);
88
- if (usedNode) {
89
- parseNode(usedNode, style);
90
- } else {
91
- console.warn("SVGLoader: 'use node' references non-existent node id: " + usedNodeId);
92
- }
93
- break;
94
- }
95
- if (path) {
96
- if (style.fill !== void 0 && style.fill !== "none") {
97
- path.color.setStyle(style.fill, COLOR_SPACE_SVG);
98
- }
99
- transformPath(path, currentTransform);
100
- paths.push(path);
101
- path.userData = { node, style };
102
- }
103
- const childNodes = node.childNodes;
104
- for (let i = 0; i < childNodes.length; i++) {
105
- const node2 = childNodes[i];
106
- if (isDefsNode && node2.nodeName !== "style" && node2.nodeName !== "defs") {
107
- continue;
108
- }
109
- parseNode(node2, style);
110
- }
111
- if (transform) {
112
- transformStack.pop();
113
- if (transformStack.length > 0) {
114
- currentTransform.copy(transformStack[transformStack.length - 1]);
115
- } else {
116
- currentTransform.identity();
117
- }
118
- }
3
+ const SVGLoader = /* @__PURE__ */ (() => {
4
+ class SVGLoader2 extends Loader {
5
+ constructor(manager) {
6
+ super(manager);
7
+ this.defaultDPI = 90;
8
+ this.defaultUnit = "px";
119
9
  }
120
- function parsePathNode(node) {
121
- const path = new ShapePath();
122
- const point = new Vector2();
123
- const control = new Vector2();
124
- const firstPoint = new Vector2();
125
- let isFirstPoint = true;
126
- let doSetFirstPoint = false;
127
- const d = node.getAttribute("d");
128
- if (d === "" || d === "none")
129
- return null;
130
- const commands = d.match(/[a-df-z][^a-df-z]*/gi);
131
- for (let i = 0, l = commands.length; i < l; i++) {
132
- const command = commands[i];
133
- const type = command.charAt(0);
134
- const data2 = command.slice(1).trim();
135
- if (isFirstPoint === true) {
136
- doSetFirstPoint = true;
137
- isFirstPoint = false;
138
- }
139
- let numbers;
140
- switch (type) {
141
- case "M":
142
- numbers = parseFloats(data2);
143
- for (let j = 0, jl = numbers.length; j < jl; j += 2) {
144
- point.x = numbers[j + 0];
145
- point.y = numbers[j + 1];
146
- control.x = point.x;
147
- control.y = point.y;
148
- if (j === 0) {
149
- path.moveTo(point.x, point.y);
150
- } else {
151
- path.lineTo(point.x, point.y);
152
- }
153
- if (j === 0)
154
- firstPoint.copy(point);
155
- }
156
- break;
157
- case "H":
158
- numbers = parseFloats(data2);
159
- for (let j = 0, jl = numbers.length; j < jl; j++) {
160
- point.x = numbers[j];
161
- control.x = point.x;
162
- control.y = point.y;
163
- path.lineTo(point.x, point.y);
164
- if (j === 0 && doSetFirstPoint === true)
165
- firstPoint.copy(point);
166
- }
167
- break;
168
- case "V":
169
- numbers = parseFloats(data2);
170
- for (let j = 0, jl = numbers.length; j < jl; j++) {
171
- point.y = numbers[j];
172
- control.x = point.x;
173
- control.y = point.y;
174
- path.lineTo(point.x, point.y);
175
- if (j === 0 && doSetFirstPoint === true)
176
- firstPoint.copy(point);
177
- }
178
- break;
179
- case "L":
180
- numbers = parseFloats(data2);
181
- for (let j = 0, jl = numbers.length; j < jl; j += 2) {
182
- point.x = numbers[j + 0];
183
- point.y = numbers[j + 1];
184
- control.x = point.x;
185
- control.y = point.y;
186
- path.lineTo(point.x, point.y);
187
- if (j === 0 && doSetFirstPoint === true)
188
- firstPoint.copy(point);
189
- }
190
- break;
191
- case "C":
192
- numbers = parseFloats(data2);
193
- for (let j = 0, jl = numbers.length; j < jl; j += 6) {
194
- path.bezierCurveTo(
195
- numbers[j + 0],
196
- numbers[j + 1],
197
- numbers[j + 2],
198
- numbers[j + 3],
199
- numbers[j + 4],
200
- numbers[j + 5]
201
- );
202
- control.x = numbers[j + 2];
203
- control.y = numbers[j + 3];
204
- point.x = numbers[j + 4];
205
- point.y = numbers[j + 5];
206
- if (j === 0 && doSetFirstPoint === true)
207
- firstPoint.copy(point);
10
+ load(url, onLoad, onProgress, onError) {
11
+ const scope = this;
12
+ const loader = new FileLoader(scope.manager);
13
+ loader.setPath(scope.path);
14
+ loader.setRequestHeader(scope.requestHeader);
15
+ loader.setWithCredentials(scope.withCredentials);
16
+ loader.load(
17
+ url,
18
+ function(text) {
19
+ try {
20
+ onLoad(scope.parse(text));
21
+ } catch (e) {
22
+ if (onError) {
23
+ onError(e);
24
+ } else {
25
+ console.error(e);
208
26
  }
27
+ scope.manager.itemError(url);
28
+ }
29
+ },
30
+ onProgress,
31
+ onError
32
+ );
33
+ }
34
+ parse(text) {
35
+ const scope = this;
36
+ function parseNode(node, style) {
37
+ if (node.nodeType !== 1)
38
+ return;
39
+ const transform = getNodeTransform(node);
40
+ let isDefsNode = false;
41
+ let path = null;
42
+ switch (node.nodeName) {
43
+ case "svg":
44
+ style = parseStyle(node, style);
209
45
  break;
210
- case "S":
211
- numbers = parseFloats(data2);
212
- for (let j = 0, jl = numbers.length; j < jl; j += 4) {
213
- path.bezierCurveTo(
214
- getReflection(point.x, control.x),
215
- getReflection(point.y, control.y),
216
- numbers[j + 0],
217
- numbers[j + 1],
218
- numbers[j + 2],
219
- numbers[j + 3]
220
- );
221
- control.x = numbers[j + 0];
222
- control.y = numbers[j + 1];
223
- point.x = numbers[j + 2];
224
- point.y = numbers[j + 3];
225
- if (j === 0 && doSetFirstPoint === true)
226
- firstPoint.copy(point);
227
- }
46
+ case "style":
47
+ parseCSSStylesheet(node);
228
48
  break;
229
- case "Q":
230
- numbers = parseFloats(data2);
231
- for (let j = 0, jl = numbers.length; j < jl; j += 4) {
232
- path.quadraticCurveTo(numbers[j + 0], numbers[j + 1], numbers[j + 2], numbers[j + 3]);
233
- control.x = numbers[j + 0];
234
- control.y = numbers[j + 1];
235
- point.x = numbers[j + 2];
236
- point.y = numbers[j + 3];
237
- if (j === 0 && doSetFirstPoint === true)
238
- firstPoint.copy(point);
239
- }
49
+ case "g":
50
+ style = parseStyle(node, style);
240
51
  break;
241
- case "T":
242
- numbers = parseFloats(data2);
243
- for (let j = 0, jl = numbers.length; j < jl; j += 2) {
244
- const rx = getReflection(point.x, control.x);
245
- const ry = getReflection(point.y, control.y);
246
- path.quadraticCurveTo(rx, ry, numbers[j + 0], numbers[j + 1]);
247
- control.x = rx;
248
- control.y = ry;
249
- point.x = numbers[j + 0];
250
- point.y = numbers[j + 1];
251
- if (j === 0 && doSetFirstPoint === true)
252
- firstPoint.copy(point);
253
- }
52
+ case "path":
53
+ style = parseStyle(node, style);
54
+ if (node.hasAttribute("d"))
55
+ path = parsePathNode(node);
254
56
  break;
255
- case "A":
256
- numbers = parseFloats(data2, [3, 4], 7);
257
- for (let j = 0, jl = numbers.length; j < jl; j += 7) {
258
- if (numbers[j + 5] == point.x && numbers[j + 6] == point.y)
259
- continue;
260
- const start = point.clone();
261
- point.x = numbers[j + 5];
262
- point.y = numbers[j + 6];
263
- control.x = point.x;
264
- control.y = point.y;
265
- parseArcCommand(
266
- path,
267
- numbers[j],
268
- numbers[j + 1],
269
- numbers[j + 2],
270
- numbers[j + 3],
271
- numbers[j + 4],
272
- start,
273
- point
274
- );
275
- if (j === 0 && doSetFirstPoint === true)
276
- firstPoint.copy(point);
277
- }
57
+ case "rect":
58
+ style = parseStyle(node, style);
59
+ path = parseRectNode(node);
278
60
  break;
279
- case "m":
280
- numbers = parseFloats(data2);
281
- for (let j = 0, jl = numbers.length; j < jl; j += 2) {
282
- point.x += numbers[j + 0];
283
- point.y += numbers[j + 1];
284
- control.x = point.x;
285
- control.y = point.y;
286
- if (j === 0) {
287
- path.moveTo(point.x, point.y);
288
- } else {
289
- path.lineTo(point.x, point.y);
290
- }
291
- if (j === 0)
292
- firstPoint.copy(point);
293
- }
61
+ case "polygon":
62
+ style = parseStyle(node, style);
63
+ path = parsePolygonNode(node);
294
64
  break;
295
- case "h":
296
- numbers = parseFloats(data2);
297
- for (let j = 0, jl = numbers.length; j < jl; j++) {
298
- point.x += numbers[j];
299
- control.x = point.x;
300
- control.y = point.y;
301
- path.lineTo(point.x, point.y);
302
- if (j === 0 && doSetFirstPoint === true)
303
- firstPoint.copy(point);
304
- }
65
+ case "polyline":
66
+ style = parseStyle(node, style);
67
+ path = parsePolylineNode(node);
305
68
  break;
306
- case "v":
307
- numbers = parseFloats(data2);
308
- for (let j = 0, jl = numbers.length; j < jl; j++) {
309
- point.y += numbers[j];
310
- control.x = point.x;
311
- control.y = point.y;
312
- path.lineTo(point.x, point.y);
313
- if (j === 0 && doSetFirstPoint === true)
314
- firstPoint.copy(point);
315
- }
69
+ case "circle":
70
+ style = parseStyle(node, style);
71
+ path = parseCircleNode(node);
316
72
  break;
317
- case "l":
318
- numbers = parseFloats(data2);
319
- for (let j = 0, jl = numbers.length; j < jl; j += 2) {
320
- point.x += numbers[j + 0];
321
- point.y += numbers[j + 1];
322
- control.x = point.x;
323
- control.y = point.y;
324
- path.lineTo(point.x, point.y);
325
- if (j === 0 && doSetFirstPoint === true)
326
- firstPoint.copy(point);
327
- }
73
+ case "ellipse":
74
+ style = parseStyle(node, style);
75
+ path = parseEllipseNode(node);
328
76
  break;
329
- case "c":
330
- numbers = parseFloats(data2);
331
- for (let j = 0, jl = numbers.length; j < jl; j += 6) {
332
- path.bezierCurveTo(
333
- point.x + numbers[j + 0],
334
- point.y + numbers[j + 1],
335
- point.x + numbers[j + 2],
336
- point.y + numbers[j + 3],
337
- point.x + numbers[j + 4],
338
- point.y + numbers[j + 5]
339
- );
340
- control.x = point.x + numbers[j + 2];
341
- control.y = point.y + numbers[j + 3];
342
- point.x += numbers[j + 4];
343
- point.y += numbers[j + 5];
344
- if (j === 0 && doSetFirstPoint === true)
345
- firstPoint.copy(point);
346
- }
77
+ case "line":
78
+ style = parseStyle(node, style);
79
+ path = parseLineNode(node);
347
80
  break;
348
- case "s":
349
- numbers = parseFloats(data2);
350
- for (let j = 0, jl = numbers.length; j < jl; j += 4) {
351
- path.bezierCurveTo(
352
- getReflection(point.x, control.x),
353
- getReflection(point.y, control.y),
354
- point.x + numbers[j + 0],
355
- point.y + numbers[j + 1],
356
- point.x + numbers[j + 2],
357
- point.y + numbers[j + 3]
358
- );
359
- control.x = point.x + numbers[j + 0];
360
- control.y = point.y + numbers[j + 1];
361
- point.x += numbers[j + 2];
362
- point.y += numbers[j + 3];
363
- if (j === 0 && doSetFirstPoint === true)
364
- firstPoint.copy(point);
365
- }
81
+ case "defs":
82
+ isDefsNode = true;
366
83
  break;
367
- case "q":
368
- numbers = parseFloats(data2);
369
- for (let j = 0, jl = numbers.length; j < jl; j += 4) {
370
- path.quadraticCurveTo(
371
- point.x + numbers[j + 0],
372
- point.y + numbers[j + 1],
373
- point.x + numbers[j + 2],
374
- point.y + numbers[j + 3]
375
- );
376
- control.x = point.x + numbers[j + 0];
377
- control.y = point.y + numbers[j + 1];
378
- point.x += numbers[j + 2];
379
- point.y += numbers[j + 3];
380
- if (j === 0 && doSetFirstPoint === true)
381
- firstPoint.copy(point);
382
- }
383
- break;
384
- case "t":
385
- numbers = parseFloats(data2);
386
- for (let j = 0, jl = numbers.length; j < jl; j += 2) {
387
- const rx = getReflection(point.x, control.x);
388
- const ry = getReflection(point.y, control.y);
389
- path.quadraticCurveTo(rx, ry, point.x + numbers[j + 0], point.y + numbers[j + 1]);
390
- control.x = rx;
391
- control.y = ry;
392
- point.x = point.x + numbers[j + 0];
393
- point.y = point.y + numbers[j + 1];
394
- if (j === 0 && doSetFirstPoint === true)
395
- firstPoint.copy(point);
396
- }
397
- break;
398
- case "a":
399
- numbers = parseFloats(data2, [3, 4], 7);
400
- for (let j = 0, jl = numbers.length; j < jl; j += 7) {
401
- if (numbers[j + 5] == 0 && numbers[j + 6] == 0)
402
- continue;
403
- const start = point.clone();
404
- point.x += numbers[j + 5];
405
- point.y += numbers[j + 6];
406
- control.x = point.x;
407
- control.y = point.y;
408
- parseArcCommand(
409
- path,
410
- numbers[j],
411
- numbers[j + 1],
412
- numbers[j + 2],
413
- numbers[j + 3],
414
- numbers[j + 4],
415
- start,
416
- point
417
- );
418
- if (j === 0 && doSetFirstPoint === true)
419
- firstPoint.copy(point);
420
- }
421
- break;
422
- case "Z":
423
- case "z":
424
- path.currentPath.autoClose = true;
425
- if (path.currentPath.curves.length > 0) {
426
- point.copy(firstPoint);
427
- path.currentPath.currentPoint.copy(point);
428
- isFirstPoint = true;
84
+ case "use":
85
+ style = parseStyle(node, style);
86
+ const href = node.getAttributeNS("http://www.w3.org/1999/xlink", "href") || "";
87
+ const usedNodeId = href.substring(1);
88
+ const usedNode = node.viewportElement.getElementById(usedNodeId);
89
+ if (usedNode) {
90
+ parseNode(usedNode, style);
91
+ } else {
92
+ console.warn("SVGLoader: 'use node' references non-existent node id: " + usedNodeId);
429
93
  }
430
94
  break;
431
- default:
432
- console.warn(command);
433
- }
434
- doSetFirstPoint = false;
435
- }
436
- return path;
437
- }
438
- function parseCSSStylesheet(node) {
439
- if (!node.sheet || !node.sheet.cssRules || !node.sheet.cssRules.length)
440
- return;
441
- for (let i = 0; i < node.sheet.cssRules.length; i++) {
442
- const stylesheet = node.sheet.cssRules[i];
443
- if (stylesheet.type !== 1)
444
- continue;
445
- const selectorList = stylesheet.selectorText.split(/,/gm).filter(Boolean).map((i2) => i2.trim());
446
- for (let j = 0; j < selectorList.length; j++) {
447
- const definitions = Object.fromEntries(Object.entries(stylesheet.style).filter(([, v]) => v !== ""));
448
- stylesheets[selectorList[j]] = Object.assign(stylesheets[selectorList[j]] || {}, definitions);
449
95
  }
450
- }
451
- }
452
- function parseArcCommand(path, rx, ry, x_axis_rotation, large_arc_flag, sweep_flag, start, end) {
453
- if (rx == 0 || ry == 0) {
454
- path.lineTo(end.x, end.y);
455
- return;
456
- }
457
- x_axis_rotation = x_axis_rotation * Math.PI / 180;
458
- rx = Math.abs(rx);
459
- ry = Math.abs(ry);
460
- const dx2 = (start.x - end.x) / 2;
461
- const dy2 = (start.y - end.y) / 2;
462
- const x1p = Math.cos(x_axis_rotation) * dx2 + Math.sin(x_axis_rotation) * dy2;
463
- const y1p = -Math.sin(x_axis_rotation) * dx2 + Math.cos(x_axis_rotation) * dy2;
464
- let rxs = rx * rx;
465
- let rys = ry * ry;
466
- const x1ps = x1p * x1p;
467
- const y1ps = y1p * y1p;
468
- const cr = x1ps / rxs + y1ps / rys;
469
- if (cr > 1) {
470
- const s = Math.sqrt(cr);
471
- rx = s * rx;
472
- ry = s * ry;
473
- rxs = rx * rx;
474
- rys = ry * ry;
475
- }
476
- const dq = rxs * y1ps + rys * x1ps;
477
- const pq = (rxs * rys - dq) / dq;
478
- let q = Math.sqrt(Math.max(0, pq));
479
- if (large_arc_flag === sweep_flag)
480
- q = -q;
481
- const cxp = q * rx * y1p / ry;
482
- const cyp = -q * ry * x1p / rx;
483
- const cx = Math.cos(x_axis_rotation) * cxp - Math.sin(x_axis_rotation) * cyp + (start.x + end.x) / 2;
484
- const cy = Math.sin(x_axis_rotation) * cxp + Math.cos(x_axis_rotation) * cyp + (start.y + end.y) / 2;
485
- const theta = svgAngle(1, 0, (x1p - cxp) / rx, (y1p - cyp) / ry);
486
- const delta = svgAngle((x1p - cxp) / rx, (y1p - cyp) / ry, (-x1p - cxp) / rx, (-y1p - cyp) / ry) % (Math.PI * 2);
487
- path.currentPath.absellipse(cx, cy, rx, ry, theta, theta + delta, sweep_flag === 0, x_axis_rotation);
488
- }
489
- function svgAngle(ux, uy, vx, vy) {
490
- const dot = ux * vx + uy * vy;
491
- const len = Math.sqrt(ux * ux + uy * uy) * Math.sqrt(vx * vx + vy * vy);
492
- let ang = Math.acos(Math.max(-1, Math.min(1, dot / len)));
493
- if (ux * vy - uy * vx < 0)
494
- ang = -ang;
495
- return ang;
496
- }
497
- function parseRectNode(node) {
498
- const x = parseFloatWithUnits(node.getAttribute("x") || 0);
499
- const y = parseFloatWithUnits(node.getAttribute("y") || 0);
500
- const rx = parseFloatWithUnits(node.getAttribute("rx") || node.getAttribute("ry") || 0);
501
- const ry = parseFloatWithUnits(node.getAttribute("ry") || node.getAttribute("rx") || 0);
502
- const w = parseFloatWithUnits(node.getAttribute("width"));
503
- const h = parseFloatWithUnits(node.getAttribute("height"));
504
- const bci = 1 - 0.551915024494;
505
- const path = new ShapePath();
506
- path.moveTo(x + rx, y);
507
- path.lineTo(x + w - rx, y);
508
- if (rx !== 0 || ry !== 0) {
509
- path.bezierCurveTo(x + w - rx * bci, y, x + w, y + ry * bci, x + w, y + ry);
510
- }
511
- path.lineTo(x + w, y + h - ry);
512
- if (rx !== 0 || ry !== 0) {
513
- path.bezierCurveTo(x + w, y + h - ry * bci, x + w - rx * bci, y + h, x + w - rx, y + h);
514
- }
515
- path.lineTo(x + rx, y + h);
516
- if (rx !== 0 || ry !== 0) {
517
- path.bezierCurveTo(x + rx * bci, y + h, x, y + h - ry * bci, x, y + h - ry);
518
- }
519
- path.lineTo(x, y + ry);
520
- if (rx !== 0 || ry !== 0) {
521
- path.bezierCurveTo(x, y + ry * bci, x + rx * bci, y, x + rx, y);
522
- }
523
- return path;
524
- }
525
- function parsePolygonNode(node) {
526
- function iterator(match, a, b) {
527
- const x = parseFloatWithUnits(a);
528
- const y = parseFloatWithUnits(b);
529
- if (index === 0) {
530
- path.moveTo(x, y);
531
- } else {
532
- path.lineTo(x, y);
96
+ if (path) {
97
+ if (style.fill !== void 0 && style.fill !== "none") {
98
+ path.color.setStyle(style.fill, COLOR_SPACE_SVG);
99
+ }
100
+ transformPath(path, currentTransform);
101
+ paths.push(path);
102
+ path.userData = { node, style };
533
103
  }
534
- index++;
535
- }
536
- const regex = /([+-]?\d*\.?\d+(?:e[+-]?\d+)?)(?:,|\s)([+-]?\d*\.?\d+(?:e[+-]?\d+)?)/g;
537
- const path = new ShapePath();
538
- let index = 0;
539
- node.getAttribute("points").replace(regex, iterator);
540
- path.currentPath.autoClose = true;
541
- return path;
542
- }
543
- function parsePolylineNode(node) {
544
- function iterator(match, a, b) {
545
- const x = parseFloatWithUnits(a);
546
- const y = parseFloatWithUnits(b);
547
- if (index === 0) {
548
- path.moveTo(x, y);
549
- } else {
550
- path.lineTo(x, y);
104
+ const childNodes = node.childNodes;
105
+ for (let i = 0; i < childNodes.length; i++) {
106
+ const node2 = childNodes[i];
107
+ if (isDefsNode && node2.nodeName !== "style" && node2.nodeName !== "defs") {
108
+ continue;
109
+ }
110
+ parseNode(node2, style);
551
111
  }
552
- index++;
553
- }
554
- const regex = /([+-]?\d*\.?\d+(?:e[+-]?\d+)?)(?:,|\s)([+-]?\d*\.?\d+(?:e[+-]?\d+)?)/g;
555
- const path = new ShapePath();
556
- let index = 0;
557
- node.getAttribute("points").replace(regex, iterator);
558
- path.currentPath.autoClose = false;
559
- return path;
560
- }
561
- function parseCircleNode(node) {
562
- const x = parseFloatWithUnits(node.getAttribute("cx") || 0);
563
- const y = parseFloatWithUnits(node.getAttribute("cy") || 0);
564
- const r = parseFloatWithUnits(node.getAttribute("r") || 0);
565
- const subpath = new Path();
566
- subpath.absarc(x, y, r, 0, Math.PI * 2);
567
- const path = new ShapePath();
568
- path.subPaths.push(subpath);
569
- return path;
570
- }
571
- function parseEllipseNode(node) {
572
- const x = parseFloatWithUnits(node.getAttribute("cx") || 0);
573
- const y = parseFloatWithUnits(node.getAttribute("cy") || 0);
574
- const rx = parseFloatWithUnits(node.getAttribute("rx") || 0);
575
- const ry = parseFloatWithUnits(node.getAttribute("ry") || 0);
576
- const subpath = new Path();
577
- subpath.absellipse(x, y, rx, ry, 0, Math.PI * 2);
578
- const path = new ShapePath();
579
- path.subPaths.push(subpath);
580
- return path;
581
- }
582
- function parseLineNode(node) {
583
- const x1 = parseFloatWithUnits(node.getAttribute("x1") || 0);
584
- const y1 = parseFloatWithUnits(node.getAttribute("y1") || 0);
585
- const x2 = parseFloatWithUnits(node.getAttribute("x2") || 0);
586
- const y2 = parseFloatWithUnits(node.getAttribute("y2") || 0);
587
- const path = new ShapePath();
588
- path.moveTo(x1, y1);
589
- path.lineTo(x2, y2);
590
- path.currentPath.autoClose = false;
591
- return path;
592
- }
593
- function parseStyle(node, style) {
594
- style = Object.assign({}, style);
595
- let stylesheetStyles = {};
596
- if (node.hasAttribute("class")) {
597
- const classSelectors = node.getAttribute("class").split(/\s/).filter(Boolean).map((i) => i.trim());
598
- for (let i = 0; i < classSelectors.length; i++) {
599
- stylesheetStyles = Object.assign(stylesheetStyles, stylesheets["." + classSelectors[i]]);
112
+ if (transform) {
113
+ transformStack.pop();
114
+ if (transformStack.length > 0) {
115
+ currentTransform.copy(transformStack[transformStack.length - 1]);
116
+ } else {
117
+ currentTransform.identity();
118
+ }
600
119
  }
601
120
  }
602
- if (node.hasAttribute("id")) {
603
- stylesheetStyles = Object.assign(stylesheetStyles, stylesheets["#" + node.getAttribute("id")]);
604
- }
605
- function addStyle(svgName, jsName, adjustFunction) {
606
- if (adjustFunction === void 0)
607
- adjustFunction = function copy(v) {
608
- if (v.startsWith("url"))
609
- console.warn("SVGLoader: url access in attributes is not implemented.");
610
- return v;
611
- };
612
- if (node.hasAttribute(svgName))
613
- style[jsName] = adjustFunction(node.getAttribute(svgName));
614
- if (stylesheetStyles[svgName])
615
- style[jsName] = adjustFunction(stylesheetStyles[svgName]);
616
- if (node.style && node.style[svgName] !== "")
617
- style[jsName] = adjustFunction(node.style[svgName]);
618
- }
619
- function clamp(v) {
620
- return Math.max(0, Math.min(1, parseFloatWithUnits(v)));
621
- }
622
- function positive(v) {
623
- return Math.max(0, parseFloatWithUnits(v));
624
- }
625
- addStyle("fill", "fill");
626
- addStyle("fill-opacity", "fillOpacity", clamp);
627
- addStyle("fill-rule", "fillRule");
628
- addStyle("opacity", "opacity", clamp);
629
- addStyle("stroke", "stroke");
630
- addStyle("stroke-opacity", "strokeOpacity", clamp);
631
- addStyle("stroke-width", "strokeWidth", positive);
632
- addStyle("stroke-linejoin", "strokeLineJoin");
633
- addStyle("stroke-linecap", "strokeLineCap");
634
- addStyle("stroke-miterlimit", "strokeMiterLimit", positive);
635
- addStyle("visibility", "visibility");
636
- return style;
637
- }
638
- function getReflection(a, b) {
639
- return a - (b - a);
640
- }
641
- function parseFloats(input, flags, stride) {
642
- if (typeof input !== "string") {
643
- throw new TypeError("Invalid input: " + typeof input);
644
- }
645
- const RE = {
646
- SEPARATOR: /[ \t\r\n\,.\-+]/,
647
- WHITESPACE: /[ \t\r\n]/,
648
- DIGIT: /[\d]/,
649
- SIGN: /[-+]/,
650
- POINT: /\./,
651
- COMMA: /,/,
652
- EXP: /e/i,
653
- FLAGS: /[01]/
654
- };
655
- const SEP = 0;
656
- const INT = 1;
657
- const FLOAT = 2;
658
- const EXP = 3;
659
- let state = SEP;
660
- let seenComma = true;
661
- let number = "", exponent = "";
662
- const result = [];
663
- function throwSyntaxError(current2, i, partial) {
664
- const error = new SyntaxError('Unexpected character "' + current2 + '" at index ' + i + ".");
665
- error.partial = partial;
666
- throw error;
667
- }
668
- function newNumber() {
669
- if (number !== "") {
670
- if (exponent === "")
671
- result.push(Number(number));
672
- else
673
- result.push(Number(number) * Math.pow(10, Number(exponent)));
674
- }
675
- number = "";
676
- exponent = "";
677
- }
678
- let current;
679
- const length = input.length;
680
- for (let i = 0; i < length; i++) {
681
- current = input[i];
682
- if (Array.isArray(flags) && flags.includes(result.length % stride) && RE.FLAGS.test(current)) {
683
- state = INT;
684
- number = current;
685
- newNumber();
686
- continue;
687
- }
688
- if (state === SEP) {
689
- if (RE.WHITESPACE.test(current)) {
690
- continue;
121
+ function parsePathNode(node) {
122
+ const path = new ShapePath();
123
+ const point = new Vector2();
124
+ const control = new Vector2();
125
+ const firstPoint = new Vector2();
126
+ let isFirstPoint = true;
127
+ let doSetFirstPoint = false;
128
+ const d = node.getAttribute("d");
129
+ if (d === "" || d === "none")
130
+ return null;
131
+ const commands = d.match(/[a-df-z][^a-df-z]*/gi);
132
+ for (let i = 0, l = commands.length; i < l; i++) {
133
+ const command = commands[i];
134
+ const type = command.charAt(0);
135
+ const data2 = command.slice(1).trim();
136
+ if (isFirstPoint === true) {
137
+ doSetFirstPoint = true;
138
+ isFirstPoint = false;
691
139
  }
692
- if (RE.DIGIT.test(current) || RE.SIGN.test(current)) {
693
- state = INT;
694
- number = current;
695
- continue;
140
+ let numbers;
141
+ switch (type) {
142
+ case "M":
143
+ numbers = parseFloats(data2);
144
+ for (let j = 0, jl = numbers.length; j < jl; j += 2) {
145
+ point.x = numbers[j + 0];
146
+ point.y = numbers[j + 1];
147
+ control.x = point.x;
148
+ control.y = point.y;
149
+ if (j === 0) {
150
+ path.moveTo(point.x, point.y);
151
+ } else {
152
+ path.lineTo(point.x, point.y);
153
+ }
154
+ if (j === 0)
155
+ firstPoint.copy(point);
156
+ }
157
+ break;
158
+ case "H":
159
+ numbers = parseFloats(data2);
160
+ for (let j = 0, jl = numbers.length; j < jl; j++) {
161
+ point.x = numbers[j];
162
+ control.x = point.x;
163
+ control.y = point.y;
164
+ path.lineTo(point.x, point.y);
165
+ if (j === 0 && doSetFirstPoint === true)
166
+ firstPoint.copy(point);
167
+ }
168
+ break;
169
+ case "V":
170
+ numbers = parseFloats(data2);
171
+ for (let j = 0, jl = numbers.length; j < jl; j++) {
172
+ point.y = numbers[j];
173
+ control.x = point.x;
174
+ control.y = point.y;
175
+ path.lineTo(point.x, point.y);
176
+ if (j === 0 && doSetFirstPoint === true)
177
+ firstPoint.copy(point);
178
+ }
179
+ break;
180
+ case "L":
181
+ numbers = parseFloats(data2);
182
+ for (let j = 0, jl = numbers.length; j < jl; j += 2) {
183
+ point.x = numbers[j + 0];
184
+ point.y = numbers[j + 1];
185
+ control.x = point.x;
186
+ control.y = point.y;
187
+ path.lineTo(point.x, point.y);
188
+ if (j === 0 && doSetFirstPoint === true)
189
+ firstPoint.copy(point);
190
+ }
191
+ break;
192
+ case "C":
193
+ numbers = parseFloats(data2);
194
+ for (let j = 0, jl = numbers.length; j < jl; j += 6) {
195
+ path.bezierCurveTo(
196
+ numbers[j + 0],
197
+ numbers[j + 1],
198
+ numbers[j + 2],
199
+ numbers[j + 3],
200
+ numbers[j + 4],
201
+ numbers[j + 5]
202
+ );
203
+ control.x = numbers[j + 2];
204
+ control.y = numbers[j + 3];
205
+ point.x = numbers[j + 4];
206
+ point.y = numbers[j + 5];
207
+ if (j === 0 && doSetFirstPoint === true)
208
+ firstPoint.copy(point);
209
+ }
210
+ break;
211
+ case "S":
212
+ numbers = parseFloats(data2);
213
+ for (let j = 0, jl = numbers.length; j < jl; j += 4) {
214
+ path.bezierCurveTo(
215
+ getReflection(point.x, control.x),
216
+ getReflection(point.y, control.y),
217
+ numbers[j + 0],
218
+ numbers[j + 1],
219
+ numbers[j + 2],
220
+ numbers[j + 3]
221
+ );
222
+ control.x = numbers[j + 0];
223
+ control.y = numbers[j + 1];
224
+ point.x = numbers[j + 2];
225
+ point.y = numbers[j + 3];
226
+ if (j === 0 && doSetFirstPoint === true)
227
+ firstPoint.copy(point);
228
+ }
229
+ break;
230
+ case "Q":
231
+ numbers = parseFloats(data2);
232
+ for (let j = 0, jl = numbers.length; j < jl; j += 4) {
233
+ path.quadraticCurveTo(numbers[j + 0], numbers[j + 1], numbers[j + 2], numbers[j + 3]);
234
+ control.x = numbers[j + 0];
235
+ control.y = numbers[j + 1];
236
+ point.x = numbers[j + 2];
237
+ point.y = numbers[j + 3];
238
+ if (j === 0 && doSetFirstPoint === true)
239
+ firstPoint.copy(point);
240
+ }
241
+ break;
242
+ case "T":
243
+ numbers = parseFloats(data2);
244
+ for (let j = 0, jl = numbers.length; j < jl; j += 2) {
245
+ const rx = getReflection(point.x, control.x);
246
+ const ry = getReflection(point.y, control.y);
247
+ path.quadraticCurveTo(rx, ry, numbers[j + 0], numbers[j + 1]);
248
+ control.x = rx;
249
+ control.y = ry;
250
+ point.x = numbers[j + 0];
251
+ point.y = numbers[j + 1];
252
+ if (j === 0 && doSetFirstPoint === true)
253
+ firstPoint.copy(point);
254
+ }
255
+ break;
256
+ case "A":
257
+ numbers = parseFloats(data2, [3, 4], 7);
258
+ for (let j = 0, jl = numbers.length; j < jl; j += 7) {
259
+ if (numbers[j + 5] == point.x && numbers[j + 6] == point.y)
260
+ continue;
261
+ const start = point.clone();
262
+ point.x = numbers[j + 5];
263
+ point.y = numbers[j + 6];
264
+ control.x = point.x;
265
+ control.y = point.y;
266
+ parseArcCommand(
267
+ path,
268
+ numbers[j],
269
+ numbers[j + 1],
270
+ numbers[j + 2],
271
+ numbers[j + 3],
272
+ numbers[j + 4],
273
+ start,
274
+ point
275
+ );
276
+ if (j === 0 && doSetFirstPoint === true)
277
+ firstPoint.copy(point);
278
+ }
279
+ break;
280
+ case "m":
281
+ numbers = parseFloats(data2);
282
+ for (let j = 0, jl = numbers.length; j < jl; j += 2) {
283
+ point.x += numbers[j + 0];
284
+ point.y += numbers[j + 1];
285
+ control.x = point.x;
286
+ control.y = point.y;
287
+ if (j === 0) {
288
+ path.moveTo(point.x, point.y);
289
+ } else {
290
+ path.lineTo(point.x, point.y);
291
+ }
292
+ if (j === 0)
293
+ firstPoint.copy(point);
294
+ }
295
+ break;
296
+ case "h":
297
+ numbers = parseFloats(data2);
298
+ for (let j = 0, jl = numbers.length; j < jl; j++) {
299
+ point.x += numbers[j];
300
+ control.x = point.x;
301
+ control.y = point.y;
302
+ path.lineTo(point.x, point.y);
303
+ if (j === 0 && doSetFirstPoint === true)
304
+ firstPoint.copy(point);
305
+ }
306
+ break;
307
+ case "v":
308
+ numbers = parseFloats(data2);
309
+ for (let j = 0, jl = numbers.length; j < jl; j++) {
310
+ point.y += numbers[j];
311
+ control.x = point.x;
312
+ control.y = point.y;
313
+ path.lineTo(point.x, point.y);
314
+ if (j === 0 && doSetFirstPoint === true)
315
+ firstPoint.copy(point);
316
+ }
317
+ break;
318
+ case "l":
319
+ numbers = parseFloats(data2);
320
+ for (let j = 0, jl = numbers.length; j < jl; j += 2) {
321
+ point.x += numbers[j + 0];
322
+ point.y += numbers[j + 1];
323
+ control.x = point.x;
324
+ control.y = point.y;
325
+ path.lineTo(point.x, point.y);
326
+ if (j === 0 && doSetFirstPoint === true)
327
+ firstPoint.copy(point);
328
+ }
329
+ break;
330
+ case "c":
331
+ numbers = parseFloats(data2);
332
+ for (let j = 0, jl = numbers.length; j < jl; j += 6) {
333
+ path.bezierCurveTo(
334
+ point.x + numbers[j + 0],
335
+ point.y + numbers[j + 1],
336
+ point.x + numbers[j + 2],
337
+ point.y + numbers[j + 3],
338
+ point.x + numbers[j + 4],
339
+ point.y + numbers[j + 5]
340
+ );
341
+ control.x = point.x + numbers[j + 2];
342
+ control.y = point.y + numbers[j + 3];
343
+ point.x += numbers[j + 4];
344
+ point.y += numbers[j + 5];
345
+ if (j === 0 && doSetFirstPoint === true)
346
+ firstPoint.copy(point);
347
+ }
348
+ break;
349
+ case "s":
350
+ numbers = parseFloats(data2);
351
+ for (let j = 0, jl = numbers.length; j < jl; j += 4) {
352
+ path.bezierCurveTo(
353
+ getReflection(point.x, control.x),
354
+ getReflection(point.y, control.y),
355
+ point.x + numbers[j + 0],
356
+ point.y + numbers[j + 1],
357
+ point.x + numbers[j + 2],
358
+ point.y + numbers[j + 3]
359
+ );
360
+ control.x = point.x + numbers[j + 0];
361
+ control.y = point.y + numbers[j + 1];
362
+ point.x += numbers[j + 2];
363
+ point.y += numbers[j + 3];
364
+ if (j === 0 && doSetFirstPoint === true)
365
+ firstPoint.copy(point);
366
+ }
367
+ break;
368
+ case "q":
369
+ numbers = parseFloats(data2);
370
+ for (let j = 0, jl = numbers.length; j < jl; j += 4) {
371
+ path.quadraticCurveTo(
372
+ point.x + numbers[j + 0],
373
+ point.y + numbers[j + 1],
374
+ point.x + numbers[j + 2],
375
+ point.y + numbers[j + 3]
376
+ );
377
+ control.x = point.x + numbers[j + 0];
378
+ control.y = point.y + numbers[j + 1];
379
+ point.x += numbers[j + 2];
380
+ point.y += numbers[j + 3];
381
+ if (j === 0 && doSetFirstPoint === true)
382
+ firstPoint.copy(point);
383
+ }
384
+ break;
385
+ case "t":
386
+ numbers = parseFloats(data2);
387
+ for (let j = 0, jl = numbers.length; j < jl; j += 2) {
388
+ const rx = getReflection(point.x, control.x);
389
+ const ry = getReflection(point.y, control.y);
390
+ path.quadraticCurveTo(rx, ry, point.x + numbers[j + 0], point.y + numbers[j + 1]);
391
+ control.x = rx;
392
+ control.y = ry;
393
+ point.x = point.x + numbers[j + 0];
394
+ point.y = point.y + numbers[j + 1];
395
+ if (j === 0 && doSetFirstPoint === true)
396
+ firstPoint.copy(point);
397
+ }
398
+ break;
399
+ case "a":
400
+ numbers = parseFloats(data2, [3, 4], 7);
401
+ for (let j = 0, jl = numbers.length; j < jl; j += 7) {
402
+ if (numbers[j + 5] == 0 && numbers[j + 6] == 0)
403
+ continue;
404
+ const start = point.clone();
405
+ point.x += numbers[j + 5];
406
+ point.y += numbers[j + 6];
407
+ control.x = point.x;
408
+ control.y = point.y;
409
+ parseArcCommand(
410
+ path,
411
+ numbers[j],
412
+ numbers[j + 1],
413
+ numbers[j + 2],
414
+ numbers[j + 3],
415
+ numbers[j + 4],
416
+ start,
417
+ point
418
+ );
419
+ if (j === 0 && doSetFirstPoint === true)
420
+ firstPoint.copy(point);
421
+ }
422
+ break;
423
+ case "Z":
424
+ case "z":
425
+ path.currentPath.autoClose = true;
426
+ if (path.currentPath.curves.length > 0) {
427
+ point.copy(firstPoint);
428
+ path.currentPath.currentPoint.copy(point);
429
+ isFirstPoint = true;
430
+ }
431
+ break;
432
+ default:
433
+ console.warn(command);
696
434
  }
697
- if (RE.POINT.test(current)) {
698
- state = FLOAT;
699
- number = current;
435
+ doSetFirstPoint = false;
436
+ }
437
+ return path;
438
+ }
439
+ function parseCSSStylesheet(node) {
440
+ if (!node.sheet || !node.sheet.cssRules || !node.sheet.cssRules.length)
441
+ return;
442
+ for (let i = 0; i < node.sheet.cssRules.length; i++) {
443
+ const stylesheet = node.sheet.cssRules[i];
444
+ if (stylesheet.type !== 1)
700
445
  continue;
701
- }
702
- if (RE.COMMA.test(current)) {
703
- if (seenComma) {
704
- throwSyntaxError(current, i, result);
705
- }
706
- seenComma = true;
446
+ const selectorList = stylesheet.selectorText.split(/,/gm).filter(Boolean).map((i2) => i2.trim());
447
+ for (let j = 0; j < selectorList.length; j++) {
448
+ const definitions = Object.fromEntries(Object.entries(stylesheet.style).filter(([, v]) => v !== ""));
449
+ stylesheets[selectorList[j]] = Object.assign(stylesheets[selectorList[j]] || {}, definitions);
707
450
  }
708
451
  }
709
- if (state === INT) {
710
- if (RE.DIGIT.test(current)) {
711
- number += current;
712
- continue;
452
+ }
453
+ function parseArcCommand(path, rx, ry, x_axis_rotation, large_arc_flag, sweep_flag, start, end) {
454
+ if (rx == 0 || ry == 0) {
455
+ path.lineTo(end.x, end.y);
456
+ return;
457
+ }
458
+ x_axis_rotation = x_axis_rotation * Math.PI / 180;
459
+ rx = Math.abs(rx);
460
+ ry = Math.abs(ry);
461
+ const dx2 = (start.x - end.x) / 2;
462
+ const dy2 = (start.y - end.y) / 2;
463
+ const x1p = Math.cos(x_axis_rotation) * dx2 + Math.sin(x_axis_rotation) * dy2;
464
+ const y1p = -Math.sin(x_axis_rotation) * dx2 + Math.cos(x_axis_rotation) * dy2;
465
+ let rxs = rx * rx;
466
+ let rys = ry * ry;
467
+ const x1ps = x1p * x1p;
468
+ const y1ps = y1p * y1p;
469
+ const cr = x1ps / rxs + y1ps / rys;
470
+ if (cr > 1) {
471
+ const s = Math.sqrt(cr);
472
+ rx = s * rx;
473
+ ry = s * ry;
474
+ rxs = rx * rx;
475
+ rys = ry * ry;
476
+ }
477
+ const dq = rxs * y1ps + rys * x1ps;
478
+ const pq = (rxs * rys - dq) / dq;
479
+ let q = Math.sqrt(Math.max(0, pq));
480
+ if (large_arc_flag === sweep_flag)
481
+ q = -q;
482
+ const cxp = q * rx * y1p / ry;
483
+ const cyp = -q * ry * x1p / rx;
484
+ const cx = Math.cos(x_axis_rotation) * cxp - Math.sin(x_axis_rotation) * cyp + (start.x + end.x) / 2;
485
+ const cy = Math.sin(x_axis_rotation) * cxp + Math.cos(x_axis_rotation) * cyp + (start.y + end.y) / 2;
486
+ const theta = svgAngle(1, 0, (x1p - cxp) / rx, (y1p - cyp) / ry);
487
+ const delta = svgAngle((x1p - cxp) / rx, (y1p - cyp) / ry, (-x1p - cxp) / rx, (-y1p - cyp) / ry) % (Math.PI * 2);
488
+ path.currentPath.absellipse(cx, cy, rx, ry, theta, theta + delta, sweep_flag === 0, x_axis_rotation);
489
+ }
490
+ function svgAngle(ux, uy, vx, vy) {
491
+ const dot = ux * vx + uy * vy;
492
+ const len = Math.sqrt(ux * ux + uy * uy) * Math.sqrt(vx * vx + vy * vy);
493
+ let ang = Math.acos(Math.max(-1, Math.min(1, dot / len)));
494
+ if (ux * vy - uy * vx < 0)
495
+ ang = -ang;
496
+ return ang;
497
+ }
498
+ function parseRectNode(node) {
499
+ const x = parseFloatWithUnits(node.getAttribute("x") || 0);
500
+ const y = parseFloatWithUnits(node.getAttribute("y") || 0);
501
+ const rx = parseFloatWithUnits(node.getAttribute("rx") || node.getAttribute("ry") || 0);
502
+ const ry = parseFloatWithUnits(node.getAttribute("ry") || node.getAttribute("rx") || 0);
503
+ const w = parseFloatWithUnits(node.getAttribute("width"));
504
+ const h = parseFloatWithUnits(node.getAttribute("height"));
505
+ const bci = 1 - 0.551915024494;
506
+ const path = new ShapePath();
507
+ path.moveTo(x + rx, y);
508
+ path.lineTo(x + w - rx, y);
509
+ if (rx !== 0 || ry !== 0) {
510
+ path.bezierCurveTo(x + w - rx * bci, y, x + w, y + ry * bci, x + w, y + ry);
511
+ }
512
+ path.lineTo(x + w, y + h - ry);
513
+ if (rx !== 0 || ry !== 0) {
514
+ path.bezierCurveTo(x + w, y + h - ry * bci, x + w - rx * bci, y + h, x + w - rx, y + h);
515
+ }
516
+ path.lineTo(x + rx, y + h);
517
+ if (rx !== 0 || ry !== 0) {
518
+ path.bezierCurveTo(x + rx * bci, y + h, x, y + h - ry * bci, x, y + h - ry);
519
+ }
520
+ path.lineTo(x, y + ry);
521
+ if (rx !== 0 || ry !== 0) {
522
+ path.bezierCurveTo(x, y + ry * bci, x + rx * bci, y, x + rx, y);
523
+ }
524
+ return path;
525
+ }
526
+ function parsePolygonNode(node) {
527
+ function iterator(match, a, b) {
528
+ const x = parseFloatWithUnits(a);
529
+ const y = parseFloatWithUnits(b);
530
+ if (index === 0) {
531
+ path.moveTo(x, y);
532
+ } else {
533
+ path.lineTo(x, y);
713
534
  }
714
- if (RE.POINT.test(current)) {
715
- number += current;
716
- state = FLOAT;
717
- continue;
535
+ index++;
536
+ }
537
+ const regex = /([+-]?\d*\.?\d+(?:e[+-]?\d+)?)(?:,|\s)([+-]?\d*\.?\d+(?:e[+-]?\d+)?)/g;
538
+ const path = new ShapePath();
539
+ let index = 0;
540
+ node.getAttribute("points").replace(regex, iterator);
541
+ path.currentPath.autoClose = true;
542
+ return path;
543
+ }
544
+ function parsePolylineNode(node) {
545
+ function iterator(match, a, b) {
546
+ const x = parseFloatWithUnits(a);
547
+ const y = parseFloatWithUnits(b);
548
+ if (index === 0) {
549
+ path.moveTo(x, y);
550
+ } else {
551
+ path.lineTo(x, y);
718
552
  }
719
- if (RE.EXP.test(current)) {
720
- state = EXP;
721
- continue;
553
+ index++;
554
+ }
555
+ const regex = /([+-]?\d*\.?\d+(?:e[+-]?\d+)?)(?:,|\s)([+-]?\d*\.?\d+(?:e[+-]?\d+)?)/g;
556
+ const path = new ShapePath();
557
+ let index = 0;
558
+ node.getAttribute("points").replace(regex, iterator);
559
+ path.currentPath.autoClose = false;
560
+ return path;
561
+ }
562
+ function parseCircleNode(node) {
563
+ const x = parseFloatWithUnits(node.getAttribute("cx") || 0);
564
+ const y = parseFloatWithUnits(node.getAttribute("cy") || 0);
565
+ const r = parseFloatWithUnits(node.getAttribute("r") || 0);
566
+ const subpath = new Path();
567
+ subpath.absarc(x, y, r, 0, Math.PI * 2);
568
+ const path = new ShapePath();
569
+ path.subPaths.push(subpath);
570
+ return path;
571
+ }
572
+ function parseEllipseNode(node) {
573
+ const x = parseFloatWithUnits(node.getAttribute("cx") || 0);
574
+ const y = parseFloatWithUnits(node.getAttribute("cy") || 0);
575
+ const rx = parseFloatWithUnits(node.getAttribute("rx") || 0);
576
+ const ry = parseFloatWithUnits(node.getAttribute("ry") || 0);
577
+ const subpath = new Path();
578
+ subpath.absellipse(x, y, rx, ry, 0, Math.PI * 2);
579
+ const path = new ShapePath();
580
+ path.subPaths.push(subpath);
581
+ return path;
582
+ }
583
+ function parseLineNode(node) {
584
+ const x1 = parseFloatWithUnits(node.getAttribute("x1") || 0);
585
+ const y1 = parseFloatWithUnits(node.getAttribute("y1") || 0);
586
+ const x2 = parseFloatWithUnits(node.getAttribute("x2") || 0);
587
+ const y2 = parseFloatWithUnits(node.getAttribute("y2") || 0);
588
+ const path = new ShapePath();
589
+ path.moveTo(x1, y1);
590
+ path.lineTo(x2, y2);
591
+ path.currentPath.autoClose = false;
592
+ return path;
593
+ }
594
+ function parseStyle(node, style) {
595
+ style = Object.assign({}, style);
596
+ let stylesheetStyles = {};
597
+ if (node.hasAttribute("class")) {
598
+ const classSelectors = node.getAttribute("class").split(/\s/).filter(Boolean).map((i) => i.trim());
599
+ for (let i = 0; i < classSelectors.length; i++) {
600
+ stylesheetStyles = Object.assign(stylesheetStyles, stylesheets["." + classSelectors[i]]);
722
601
  }
723
- if (RE.SIGN.test(current) && number.length === 1 && RE.SIGN.test(number[0])) {
724
- throwSyntaxError(current, i, result);
602
+ }
603
+ if (node.hasAttribute("id")) {
604
+ stylesheetStyles = Object.assign(stylesheetStyles, stylesheets["#" + node.getAttribute("id")]);
605
+ }
606
+ function addStyle(svgName, jsName, adjustFunction) {
607
+ if (adjustFunction === void 0)
608
+ adjustFunction = function copy(v) {
609
+ if (v.startsWith("url"))
610
+ console.warn("SVGLoader: url access in attributes is not implemented.");
611
+ return v;
612
+ };
613
+ if (node.hasAttribute(svgName))
614
+ style[jsName] = adjustFunction(node.getAttribute(svgName));
615
+ if (stylesheetStyles[svgName])
616
+ style[jsName] = adjustFunction(stylesheetStyles[svgName]);
617
+ if (node.style && node.style[svgName] !== "")
618
+ style[jsName] = adjustFunction(node.style[svgName]);
619
+ }
620
+ function clamp(v) {
621
+ return Math.max(0, Math.min(1, parseFloatWithUnits(v)));
622
+ }
623
+ function positive(v) {
624
+ return Math.max(0, parseFloatWithUnits(v));
625
+ }
626
+ addStyle("fill", "fill");
627
+ addStyle("fill-opacity", "fillOpacity", clamp);
628
+ addStyle("fill-rule", "fillRule");
629
+ addStyle("opacity", "opacity", clamp);
630
+ addStyle("stroke", "stroke");
631
+ addStyle("stroke-opacity", "strokeOpacity", clamp);
632
+ addStyle("stroke-width", "strokeWidth", positive);
633
+ addStyle("stroke-linejoin", "strokeLineJoin");
634
+ addStyle("stroke-linecap", "strokeLineCap");
635
+ addStyle("stroke-miterlimit", "strokeMiterLimit", positive);
636
+ addStyle("visibility", "visibility");
637
+ return style;
638
+ }
639
+ function getReflection(a, b) {
640
+ return a - (b - a);
641
+ }
642
+ function parseFloats(input, flags, stride) {
643
+ if (typeof input !== "string") {
644
+ throw new TypeError("Invalid input: " + typeof input);
645
+ }
646
+ const RE = {
647
+ SEPARATOR: /[ \t\r\n\,.\-+]/,
648
+ WHITESPACE: /[ \t\r\n]/,
649
+ DIGIT: /[\d]/,
650
+ SIGN: /[-+]/,
651
+ POINT: /\./,
652
+ COMMA: /,/,
653
+ EXP: /e/i,
654
+ FLAGS: /[01]/
655
+ };
656
+ const SEP = 0;
657
+ const INT = 1;
658
+ const FLOAT = 2;
659
+ const EXP = 3;
660
+ let state = SEP;
661
+ let seenComma = true;
662
+ let number = "", exponent = "";
663
+ const result = [];
664
+ function throwSyntaxError(current2, i, partial) {
665
+ const error = new SyntaxError('Unexpected character "' + current2 + '" at index ' + i + ".");
666
+ error.partial = partial;
667
+ throw error;
668
+ }
669
+ function newNumber() {
670
+ if (number !== "") {
671
+ if (exponent === "")
672
+ result.push(Number(number));
673
+ else
674
+ result.push(Number(number) * Math.pow(10, Number(exponent)));
725
675
  }
676
+ number = "";
677
+ exponent = "";
726
678
  }
727
- if (state === FLOAT) {
728
- if (RE.DIGIT.test(current)) {
729
- number += current;
679
+ let current;
680
+ const length = input.length;
681
+ for (let i = 0; i < length; i++) {
682
+ current = input[i];
683
+ if (Array.isArray(flags) && flags.includes(result.length % stride) && RE.FLAGS.test(current)) {
684
+ state = INT;
685
+ number = current;
686
+ newNumber();
730
687
  continue;
731
688
  }
732
- if (RE.EXP.test(current)) {
733
- state = EXP;
734
- continue;
689
+ if (state === SEP) {
690
+ if (RE.WHITESPACE.test(current)) {
691
+ continue;
692
+ }
693
+ if (RE.DIGIT.test(current) || RE.SIGN.test(current)) {
694
+ state = INT;
695
+ number = current;
696
+ continue;
697
+ }
698
+ if (RE.POINT.test(current)) {
699
+ state = FLOAT;
700
+ number = current;
701
+ continue;
702
+ }
703
+ if (RE.COMMA.test(current)) {
704
+ if (seenComma) {
705
+ throwSyntaxError(current, i, result);
706
+ }
707
+ seenComma = true;
708
+ }
735
709
  }
736
- if (RE.POINT.test(current) && number[number.length - 1] === ".") {
737
- throwSyntaxError(current, i, result);
710
+ if (state === INT) {
711
+ if (RE.DIGIT.test(current)) {
712
+ number += current;
713
+ continue;
714
+ }
715
+ if (RE.POINT.test(current)) {
716
+ number += current;
717
+ state = FLOAT;
718
+ continue;
719
+ }
720
+ if (RE.EXP.test(current)) {
721
+ state = EXP;
722
+ continue;
723
+ }
724
+ if (RE.SIGN.test(current) && number.length === 1 && RE.SIGN.test(number[0])) {
725
+ throwSyntaxError(current, i, result);
726
+ }
738
727
  }
739
- }
740
- if (state === EXP) {
741
- if (RE.DIGIT.test(current)) {
742
- exponent += current;
743
- continue;
728
+ if (state === FLOAT) {
729
+ if (RE.DIGIT.test(current)) {
730
+ number += current;
731
+ continue;
732
+ }
733
+ if (RE.EXP.test(current)) {
734
+ state = EXP;
735
+ continue;
736
+ }
737
+ if (RE.POINT.test(current) && number[number.length - 1] === ".") {
738
+ throwSyntaxError(current, i, result);
739
+ }
744
740
  }
745
- if (RE.SIGN.test(current)) {
746
- if (exponent === "") {
741
+ if (state === EXP) {
742
+ if (RE.DIGIT.test(current)) {
747
743
  exponent += current;
748
744
  continue;
749
745
  }
750
- if (exponent.length === 1 && RE.SIGN.test(exponent)) {
751
- throwSyntaxError(current, i, result);
746
+ if (RE.SIGN.test(current)) {
747
+ if (exponent === "") {
748
+ exponent += current;
749
+ continue;
750
+ }
751
+ if (exponent.length === 1 && RE.SIGN.test(exponent)) {
752
+ throwSyntaxError(current, i, result);
753
+ }
754
+ }
755
+ }
756
+ if (RE.WHITESPACE.test(current)) {
757
+ newNumber();
758
+ state = SEP;
759
+ seenComma = false;
760
+ } else if (RE.COMMA.test(current)) {
761
+ newNumber();
762
+ state = SEP;
763
+ seenComma = true;
764
+ } else if (RE.SIGN.test(current)) {
765
+ newNumber();
766
+ state = INT;
767
+ number = current;
768
+ } else if (RE.POINT.test(current)) {
769
+ newNumber();
770
+ state = FLOAT;
771
+ number = current;
772
+ } else {
773
+ throwSyntaxError(current, i, result);
774
+ }
775
+ }
776
+ newNumber();
777
+ return result;
778
+ }
779
+ const units = ["mm", "cm", "in", "pt", "pc", "px"];
780
+ const unitConversion = {
781
+ mm: {
782
+ mm: 1,
783
+ cm: 0.1,
784
+ in: 1 / 25.4,
785
+ pt: 72 / 25.4,
786
+ pc: 6 / 25.4,
787
+ px: -1
788
+ },
789
+ cm: {
790
+ mm: 10,
791
+ cm: 1,
792
+ in: 1 / 2.54,
793
+ pt: 72 / 2.54,
794
+ pc: 6 / 2.54,
795
+ px: -1
796
+ },
797
+ in: {
798
+ mm: 25.4,
799
+ cm: 2.54,
800
+ in: 1,
801
+ pt: 72,
802
+ pc: 6,
803
+ px: -1
804
+ },
805
+ pt: {
806
+ mm: 25.4 / 72,
807
+ cm: 2.54 / 72,
808
+ in: 1 / 72,
809
+ pt: 1,
810
+ pc: 6 / 72,
811
+ px: -1
812
+ },
813
+ pc: {
814
+ mm: 25.4 / 6,
815
+ cm: 2.54 / 6,
816
+ in: 1 / 6,
817
+ pt: 72 / 6,
818
+ pc: 1,
819
+ px: -1
820
+ },
821
+ px: {
822
+ px: 1
823
+ }
824
+ };
825
+ function parseFloatWithUnits(string) {
826
+ let theUnit = "px";
827
+ if (typeof string === "string" || string instanceof String) {
828
+ for (let i = 0, n = units.length; i < n; i++) {
829
+ const u = units[i];
830
+ if (string.endsWith(u)) {
831
+ theUnit = u;
832
+ string = string.substring(0, string.length - u.length);
833
+ break;
752
834
  }
753
835
  }
754
836
  }
755
- if (RE.WHITESPACE.test(current)) {
756
- newNumber();
757
- state = SEP;
758
- seenComma = false;
759
- } else if (RE.COMMA.test(current)) {
760
- newNumber();
761
- state = SEP;
762
- seenComma = true;
763
- } else if (RE.SIGN.test(current)) {
764
- newNumber();
765
- state = INT;
766
- number = current;
767
- } else if (RE.POINT.test(current)) {
768
- newNumber();
769
- state = FLOAT;
770
- number = current;
837
+ let scale = void 0;
838
+ if (theUnit === "px" && scope.defaultUnit !== "px") {
839
+ scale = unitConversion["in"][scope.defaultUnit] / scope.defaultDPI;
771
840
  } else {
772
- throwSyntaxError(current, i, result);
773
- }
774
- }
775
- newNumber();
776
- return result;
777
- }
778
- const units = ["mm", "cm", "in", "pt", "pc", "px"];
779
- const unitConversion = {
780
- mm: {
781
- mm: 1,
782
- cm: 0.1,
783
- in: 1 / 25.4,
784
- pt: 72 / 25.4,
785
- pc: 6 / 25.4,
786
- px: -1
787
- },
788
- cm: {
789
- mm: 10,
790
- cm: 1,
791
- in: 1 / 2.54,
792
- pt: 72 / 2.54,
793
- pc: 6 / 2.54,
794
- px: -1
795
- },
796
- in: {
797
- mm: 25.4,
798
- cm: 2.54,
799
- in: 1,
800
- pt: 72,
801
- pc: 6,
802
- px: -1
803
- },
804
- pt: {
805
- mm: 25.4 / 72,
806
- cm: 2.54 / 72,
807
- in: 1 / 72,
808
- pt: 1,
809
- pc: 6 / 72,
810
- px: -1
811
- },
812
- pc: {
813
- mm: 25.4 / 6,
814
- cm: 2.54 / 6,
815
- in: 1 / 6,
816
- pt: 72 / 6,
817
- pc: 1,
818
- px: -1
819
- },
820
- px: {
821
- px: 1
822
- }
823
- };
824
- function parseFloatWithUnits(string) {
825
- let theUnit = "px";
826
- if (typeof string === "string" || string instanceof String) {
827
- for (let i = 0, n = units.length; i < n; i++) {
828
- const u = units[i];
829
- if (string.endsWith(u)) {
830
- theUnit = u;
831
- string = string.substring(0, string.length - u.length);
832
- break;
841
+ scale = unitConversion[theUnit][scope.defaultUnit];
842
+ if (scale < 0) {
843
+ scale = unitConversion[theUnit]["in"] * scope.defaultDPI;
833
844
  }
834
845
  }
846
+ return scale * parseFloat(string);
835
847
  }
836
- let scale = void 0;
837
- if (theUnit === "px" && scope.defaultUnit !== "px") {
838
- scale = unitConversion["in"][scope.defaultUnit] / scope.defaultDPI;
839
- } else {
840
- scale = unitConversion[theUnit][scope.defaultUnit];
841
- if (scale < 0) {
842
- scale = unitConversion[theUnit]["in"] * scope.defaultDPI;
848
+ function getNodeTransform(node) {
849
+ if (!(node.hasAttribute("transform") || node.nodeName === "use" && (node.hasAttribute("x") || node.hasAttribute("y")))) {
850
+ return null;
843
851
  }
844
- }
845
- return scale * parseFloat(string);
846
- }
847
- function getNodeTransform(node) {
848
- if (!(node.hasAttribute("transform") || node.nodeName === "use" && (node.hasAttribute("x") || node.hasAttribute("y")))) {
849
- return null;
850
- }
851
- const transform = parseNodeTransform(node);
852
- if (transformStack.length > 0) {
853
- transform.premultiply(transformStack[transformStack.length - 1]);
854
- }
855
- currentTransform.copy(transform);
856
- transformStack.push(transform);
857
- return transform;
858
- }
859
- function parseNodeTransform(node) {
860
- const transform = new Matrix3();
861
- const currentTransform2 = tempTransform0;
862
- if (node.nodeName === "use" && (node.hasAttribute("x") || node.hasAttribute("y"))) {
863
- const tx = parseFloatWithUnits(node.getAttribute("x"));
864
- const ty = parseFloatWithUnits(node.getAttribute("y"));
865
- transform.translate(tx, ty);
866
- }
867
- if (node.hasAttribute("transform")) {
868
- const transformsTexts = node.getAttribute("transform").split(")");
869
- for (let tIndex = transformsTexts.length - 1; tIndex >= 0; tIndex--) {
870
- const transformText = transformsTexts[tIndex].trim();
871
- if (transformText === "")
872
- continue;
873
- const openParPos = transformText.indexOf("(");
874
- const closeParPos = transformText.length;
875
- if (openParPos > 0 && openParPos < closeParPos) {
876
- const transformType = transformText.slice(0, openParPos);
877
- const array = parseFloats(transformText.slice(openParPos + 1));
878
- currentTransform2.identity();
879
- switch (transformType) {
880
- case "translate":
881
- if (array.length >= 1) {
882
- const tx = array[0];
883
- let ty = 0;
884
- if (array.length >= 2) {
885
- ty = array[1];
852
+ const transform = parseNodeTransform(node);
853
+ if (transformStack.length > 0) {
854
+ transform.premultiply(transformStack[transformStack.length - 1]);
855
+ }
856
+ currentTransform.copy(transform);
857
+ transformStack.push(transform);
858
+ return transform;
859
+ }
860
+ function parseNodeTransform(node) {
861
+ const transform = new Matrix3();
862
+ const currentTransform2 = tempTransform0;
863
+ if (node.nodeName === "use" && (node.hasAttribute("x") || node.hasAttribute("y"))) {
864
+ const tx = parseFloatWithUnits(node.getAttribute("x"));
865
+ const ty = parseFloatWithUnits(node.getAttribute("y"));
866
+ transform.translate(tx, ty);
867
+ }
868
+ if (node.hasAttribute("transform")) {
869
+ const transformsTexts = node.getAttribute("transform").split(")");
870
+ for (let tIndex = transformsTexts.length - 1; tIndex >= 0; tIndex--) {
871
+ const transformText = transformsTexts[tIndex].trim();
872
+ if (transformText === "")
873
+ continue;
874
+ const openParPos = transformText.indexOf("(");
875
+ const closeParPos = transformText.length;
876
+ if (openParPos > 0 && openParPos < closeParPos) {
877
+ const transformType = transformText.slice(0, openParPos);
878
+ const array = parseFloats(transformText.slice(openParPos + 1));
879
+ currentTransform2.identity();
880
+ switch (transformType) {
881
+ case "translate":
882
+ if (array.length >= 1) {
883
+ const tx = array[0];
884
+ let ty = 0;
885
+ if (array.length >= 2) {
886
+ ty = array[1];
887
+ }
888
+ currentTransform2.translate(tx, ty);
886
889
  }
887
- currentTransform2.translate(tx, ty);
888
- }
889
- break;
890
- case "rotate":
891
- if (array.length >= 1) {
892
- let angle = 0;
893
- let cx = 0;
894
- let cy = 0;
895
- angle = array[0] * Math.PI / 180;
896
- if (array.length >= 3) {
897
- cx = array[1];
898
- cy = array[2];
890
+ break;
891
+ case "rotate":
892
+ if (array.length >= 1) {
893
+ let angle = 0;
894
+ let cx = 0;
895
+ let cy = 0;
896
+ angle = array[0] * Math.PI / 180;
897
+ if (array.length >= 3) {
898
+ cx = array[1];
899
+ cy = array[2];
900
+ }
901
+ tempTransform1.makeTranslation(-cx, -cy);
902
+ tempTransform2.makeRotation(angle);
903
+ tempTransform3.multiplyMatrices(tempTransform2, tempTransform1);
904
+ tempTransform1.makeTranslation(cx, cy);
905
+ currentTransform2.multiplyMatrices(tempTransform1, tempTransform3);
899
906
  }
900
- tempTransform1.makeTranslation(-cx, -cy);
901
- tempTransform2.makeRotation(angle);
902
- tempTransform3.multiplyMatrices(tempTransform2, tempTransform1);
903
- tempTransform1.makeTranslation(cx, cy);
904
- currentTransform2.multiplyMatrices(tempTransform1, tempTransform3);
905
- }
906
- break;
907
- case "scale":
908
- if (array.length >= 1) {
909
- const scaleX = array[0];
910
- let scaleY = scaleX;
911
- if (array.length >= 2) {
912
- scaleY = array[1];
907
+ break;
908
+ case "scale":
909
+ if (array.length >= 1) {
910
+ const scaleX = array[0];
911
+ let scaleY = scaleX;
912
+ if (array.length >= 2) {
913
+ scaleY = array[1];
914
+ }
915
+ currentTransform2.scale(scaleX, scaleY);
913
916
  }
914
- currentTransform2.scale(scaleX, scaleY);
915
- }
916
- break;
917
- case "skewX":
918
- if (array.length === 1) {
919
- currentTransform2.set(1, Math.tan(array[0] * Math.PI / 180), 0, 0, 1, 0, 0, 0, 1);
920
- }
921
- break;
922
- case "skewY":
923
- if (array.length === 1) {
924
- currentTransform2.set(1, 0, 0, Math.tan(array[0] * Math.PI / 180), 1, 0, 0, 0, 1);
925
- }
926
- break;
927
- case "matrix":
928
- if (array.length === 6) {
929
- currentTransform2.set(array[0], array[2], array[4], array[1], array[3], array[5], 0, 0, 1);
930
- }
931
- break;
917
+ break;
918
+ case "skewX":
919
+ if (array.length === 1) {
920
+ currentTransform2.set(1, Math.tan(array[0] * Math.PI / 180), 0, 0, 1, 0, 0, 0, 1);
921
+ }
922
+ break;
923
+ case "skewY":
924
+ if (array.length === 1) {
925
+ currentTransform2.set(1, 0, 0, Math.tan(array[0] * Math.PI / 180), 1, 0, 0, 0, 1);
926
+ }
927
+ break;
928
+ case "matrix":
929
+ if (array.length === 6) {
930
+ currentTransform2.set(array[0], array[2], array[4], array[1], array[3], array[5], 0, 0, 1);
931
+ }
932
+ break;
933
+ }
932
934
  }
935
+ transform.premultiply(currentTransform2);
933
936
  }
934
- transform.premultiply(currentTransform2);
935
937
  }
938
+ return transform;
936
939
  }
937
- return transform;
938
- }
939
- function transformPath(path, m) {
940
- function transfVec2(v2) {
941
- tempV3.set(v2.x, v2.y, 1).applyMatrix3(m);
942
- v2.set(tempV3.x, tempV3.y);
943
- }
944
- function transfEllipseGeneric(curve) {
945
- const a = curve.xRadius;
946
- const b = curve.yRadius;
947
- const cosTheta = Math.cos(curve.aRotation);
948
- const sinTheta = Math.sin(curve.aRotation);
949
- const v1 = new Vector3(a * cosTheta, a * sinTheta, 0);
950
- const v2 = new Vector3(-b * sinTheta, b * cosTheta, 0);
951
- const f1 = v1.applyMatrix3(m);
952
- const f2 = v2.applyMatrix3(m);
953
- const mF = tempTransform0.set(f1.x, f2.x, 0, f1.y, f2.y, 0, 0, 0, 1);
954
- const mFInv = tempTransform1.copy(mF).invert();
955
- const mFInvT = tempTransform2.copy(mFInv).transpose();
956
- const mQ = mFInvT.multiply(mFInv);
957
- const mQe = mQ.elements;
958
- const ed = eigenDecomposition(mQe[0], mQe[1], mQe[4]);
959
- const rt1sqrt = Math.sqrt(ed.rt1);
960
- const rt2sqrt = Math.sqrt(ed.rt2);
961
- curve.xRadius = 1 / rt1sqrt;
962
- curve.yRadius = 1 / rt2sqrt;
963
- curve.aRotation = Math.atan2(ed.sn, ed.cs);
964
- const isFullEllipse = (curve.aEndAngle - curve.aStartAngle) % (2 * Math.PI) < Number.EPSILON;
965
- if (!isFullEllipse) {
966
- const mDsqrt = tempTransform1.set(rt1sqrt, 0, 0, 0, rt2sqrt, 0, 0, 0, 1);
967
- const mRT = tempTransform2.set(ed.cs, ed.sn, 0, -ed.sn, ed.cs, 0, 0, 0, 1);
968
- const mDRF = mDsqrt.multiply(mRT).multiply(mF);
969
- const transformAngle = (phi) => {
970
- const { x: cosR, y: sinR } = new Vector3(Math.cos(phi), Math.sin(phi), 0).applyMatrix3(mDRF);
971
- return Math.atan2(sinR, cosR);
972
- };
973
- curve.aStartAngle = transformAngle(curve.aStartAngle);
974
- curve.aEndAngle = transformAngle(curve.aEndAngle);
940
+ function transformPath(path, m) {
941
+ function transfVec2(v2) {
942
+ tempV3.set(v2.x, v2.y, 1).applyMatrix3(m);
943
+ v2.set(tempV3.x, tempV3.y);
944
+ }
945
+ function transfEllipseGeneric(curve) {
946
+ const a = curve.xRadius;
947
+ const b = curve.yRadius;
948
+ const cosTheta = Math.cos(curve.aRotation);
949
+ const sinTheta = Math.sin(curve.aRotation);
950
+ const v1 = new Vector3(a * cosTheta, a * sinTheta, 0);
951
+ const v2 = new Vector3(-b * sinTheta, b * cosTheta, 0);
952
+ const f1 = v1.applyMatrix3(m);
953
+ const f2 = v2.applyMatrix3(m);
954
+ const mF = tempTransform0.set(f1.x, f2.x, 0, f1.y, f2.y, 0, 0, 0, 1);
955
+ const mFInv = tempTransform1.copy(mF).invert();
956
+ const mFInvT = tempTransform2.copy(mFInv).transpose();
957
+ const mQ = mFInvT.multiply(mFInv);
958
+ const mQe = mQ.elements;
959
+ const ed = eigenDecomposition(mQe[0], mQe[1], mQe[4]);
960
+ const rt1sqrt = Math.sqrt(ed.rt1);
961
+ const rt2sqrt = Math.sqrt(ed.rt2);
962
+ curve.xRadius = 1 / rt1sqrt;
963
+ curve.yRadius = 1 / rt2sqrt;
964
+ curve.aRotation = Math.atan2(ed.sn, ed.cs);
965
+ const isFullEllipse = (curve.aEndAngle - curve.aStartAngle) % (2 * Math.PI) < Number.EPSILON;
966
+ if (!isFullEllipse) {
967
+ const mDsqrt = tempTransform1.set(rt1sqrt, 0, 0, 0, rt2sqrt, 0, 0, 0, 1);
968
+ const mRT = tempTransform2.set(ed.cs, ed.sn, 0, -ed.sn, ed.cs, 0, 0, 0, 1);
969
+ const mDRF = mDsqrt.multiply(mRT).multiply(mF);
970
+ const transformAngle = (phi) => {
971
+ const { x: cosR, y: sinR } = new Vector3(Math.cos(phi), Math.sin(phi), 0).applyMatrix3(mDRF);
972
+ return Math.atan2(sinR, cosR);
973
+ };
974
+ curve.aStartAngle = transformAngle(curve.aStartAngle);
975
+ curve.aEndAngle = transformAngle(curve.aEndAngle);
976
+ if (isTransformFlipped(m)) {
977
+ curve.aClockwise = !curve.aClockwise;
978
+ }
979
+ }
980
+ }
981
+ function transfEllipseNoSkew(curve) {
982
+ const sx = getTransformScaleX(m);
983
+ const sy = getTransformScaleY(m);
984
+ curve.xRadius *= sx;
985
+ curve.yRadius *= sy;
986
+ const theta = sx > Number.EPSILON ? Math.atan2(m.elements[1], m.elements[0]) : Math.atan2(-m.elements[3], m.elements[4]);
987
+ curve.aRotation += theta;
975
988
  if (isTransformFlipped(m)) {
989
+ curve.aStartAngle *= -1;
990
+ curve.aEndAngle *= -1;
976
991
  curve.aClockwise = !curve.aClockwise;
977
992
  }
978
993
  }
979
- }
980
- function transfEllipseNoSkew(curve) {
981
- const sx = getTransformScaleX(m);
982
- const sy = getTransformScaleY(m);
983
- curve.xRadius *= sx;
984
- curve.yRadius *= sy;
985
- const theta = sx > Number.EPSILON ? Math.atan2(m.elements[1], m.elements[0]) : Math.atan2(-m.elements[3], m.elements[4]);
986
- curve.aRotation += theta;
987
- if (isTransformFlipped(m)) {
988
- curve.aStartAngle *= -1;
989
- curve.aEndAngle *= -1;
990
- curve.aClockwise = !curve.aClockwise;
991
- }
992
- }
993
- const subPaths = path.subPaths;
994
- for (let i = 0, n = subPaths.length; i < n; i++) {
995
- const subPath = subPaths[i];
996
- const curves = subPath.curves;
997
- for (let j = 0; j < curves.length; j++) {
998
- const curve = curves[j];
999
- if (curve.isLineCurve) {
1000
- transfVec2(curve.v1);
1001
- transfVec2(curve.v2);
1002
- } else if (curve.isCubicBezierCurve) {
1003
- transfVec2(curve.v0);
1004
- transfVec2(curve.v1);
1005
- transfVec2(curve.v2);
1006
- transfVec2(curve.v3);
1007
- } else if (curve.isQuadraticBezierCurve) {
1008
- transfVec2(curve.v0);
1009
- transfVec2(curve.v1);
1010
- transfVec2(curve.v2);
1011
- } else if (curve.isEllipseCurve) {
1012
- tempV2.set(curve.aX, curve.aY);
1013
- transfVec2(tempV2);
1014
- curve.aX = tempV2.x;
1015
- curve.aY = tempV2.y;
1016
- if (isTransformSkewed(m)) {
1017
- transfEllipseGeneric(curve);
1018
- } else {
1019
- transfEllipseNoSkew(curve);
994
+ const subPaths = path.subPaths;
995
+ for (let i = 0, n = subPaths.length; i < n; i++) {
996
+ const subPath = subPaths[i];
997
+ const curves = subPath.curves;
998
+ for (let j = 0; j < curves.length; j++) {
999
+ const curve = curves[j];
1000
+ if (curve.isLineCurve) {
1001
+ transfVec2(curve.v1);
1002
+ transfVec2(curve.v2);
1003
+ } else if (curve.isCubicBezierCurve) {
1004
+ transfVec2(curve.v0);
1005
+ transfVec2(curve.v1);
1006
+ transfVec2(curve.v2);
1007
+ transfVec2(curve.v3);
1008
+ } else if (curve.isQuadraticBezierCurve) {
1009
+ transfVec2(curve.v0);
1010
+ transfVec2(curve.v1);
1011
+ transfVec2(curve.v2);
1012
+ } else if (curve.isEllipseCurve) {
1013
+ tempV2.set(curve.aX, curve.aY);
1014
+ transfVec2(tempV2);
1015
+ curve.aX = tempV2.x;
1016
+ curve.aY = tempV2.y;
1017
+ if (isTransformSkewed(m)) {
1018
+ transfEllipseGeneric(curve);
1019
+ } else {
1020
+ transfEllipseNoSkew(curve);
1021
+ }
1020
1022
  }
1021
1023
  }
1022
1024
  }
1023
1025
  }
1024
- }
1025
- function isTransformFlipped(m) {
1026
- const te = m.elements;
1027
- return te[0] * te[4] - te[1] * te[3] < 0;
1028
- }
1029
- function isTransformSkewed(m) {
1030
- const te = m.elements;
1031
- const basisDot = te[0] * te[3] + te[1] * te[4];
1032
- if (basisDot === 0)
1033
- return false;
1034
- const sx = getTransformScaleX(m);
1035
- const sy = getTransformScaleY(m);
1036
- return Math.abs(basisDot / (sx * sy)) > Number.EPSILON;
1037
- }
1038
- function getTransformScaleX(m) {
1039
- const te = m.elements;
1040
- return Math.sqrt(te[0] * te[0] + te[1] * te[1]);
1041
- }
1042
- function getTransformScaleY(m) {
1043
- const te = m.elements;
1044
- return Math.sqrt(te[3] * te[3] + te[4] * te[4]);
1045
- }
1046
- function eigenDecomposition(A, B, C) {
1047
- let rt1, rt2, cs, sn, t;
1048
- const sm = A + C;
1049
- const df = A - C;
1050
- const rt = Math.sqrt(df * df + 4 * B * B);
1051
- if (sm > 0) {
1052
- rt1 = 0.5 * (sm + rt);
1053
- t = 1 / rt1;
1054
- rt2 = A * t * C - B * t * B;
1055
- } else if (sm < 0) {
1056
- rt2 = 0.5 * (sm - rt);
1057
- } else {
1058
- rt1 = 0.5 * rt;
1059
- rt2 = -0.5 * rt;
1060
- }
1061
- if (df > 0) {
1062
- cs = df + rt;
1063
- } else {
1064
- cs = df - rt;
1065
- }
1066
- if (Math.abs(cs) > 2 * Math.abs(B)) {
1067
- t = -2 * B / cs;
1068
- sn = 1 / Math.sqrt(1 + t * t);
1069
- cs = t * sn;
1070
- } else if (Math.abs(B) === 0) {
1071
- cs = 1;
1072
- sn = 0;
1073
- } else {
1074
- t = -0.5 * cs / B;
1075
- cs = 1 / Math.sqrt(1 + t * t);
1076
- sn = t * cs;
1077
- }
1078
- if (df > 0) {
1079
- t = cs;
1080
- cs = -sn;
1081
- sn = t;
1026
+ function isTransformFlipped(m) {
1027
+ const te = m.elements;
1028
+ return te[0] * te[4] - te[1] * te[3] < 0;
1082
1029
  }
1083
- return { rt1, rt2, cs, sn };
1030
+ function isTransformSkewed(m) {
1031
+ const te = m.elements;
1032
+ const basisDot = te[0] * te[3] + te[1] * te[4];
1033
+ if (basisDot === 0)
1034
+ return false;
1035
+ const sx = getTransformScaleX(m);
1036
+ const sy = getTransformScaleY(m);
1037
+ return Math.abs(basisDot / (sx * sy)) > Number.EPSILON;
1038
+ }
1039
+ function getTransformScaleX(m) {
1040
+ const te = m.elements;
1041
+ return Math.sqrt(te[0] * te[0] + te[1] * te[1]);
1042
+ }
1043
+ function getTransformScaleY(m) {
1044
+ const te = m.elements;
1045
+ return Math.sqrt(te[3] * te[3] + te[4] * te[4]);
1046
+ }
1047
+ function eigenDecomposition(A, B, C) {
1048
+ let rt1, rt2, cs, sn, t;
1049
+ const sm = A + C;
1050
+ const df = A - C;
1051
+ const rt = Math.sqrt(df * df + 4 * B * B);
1052
+ if (sm > 0) {
1053
+ rt1 = 0.5 * (sm + rt);
1054
+ t = 1 / rt1;
1055
+ rt2 = A * t * C - B * t * B;
1056
+ } else if (sm < 0) {
1057
+ rt2 = 0.5 * (sm - rt);
1058
+ } else {
1059
+ rt1 = 0.5 * rt;
1060
+ rt2 = -0.5 * rt;
1061
+ }
1062
+ if (df > 0) {
1063
+ cs = df + rt;
1064
+ } else {
1065
+ cs = df - rt;
1066
+ }
1067
+ if (Math.abs(cs) > 2 * Math.abs(B)) {
1068
+ t = -2 * B / cs;
1069
+ sn = 1 / Math.sqrt(1 + t * t);
1070
+ cs = t * sn;
1071
+ } else if (Math.abs(B) === 0) {
1072
+ cs = 1;
1073
+ sn = 0;
1074
+ } else {
1075
+ t = -0.5 * cs / B;
1076
+ cs = 1 / Math.sqrt(1 + t * t);
1077
+ sn = t * cs;
1078
+ }
1079
+ if (df > 0) {
1080
+ t = cs;
1081
+ cs = -sn;
1082
+ sn = t;
1083
+ }
1084
+ return { rt1, rt2, cs, sn };
1085
+ }
1086
+ const paths = [];
1087
+ const stylesheets = {};
1088
+ const transformStack = [];
1089
+ const tempTransform0 = new Matrix3();
1090
+ const tempTransform1 = new Matrix3();
1091
+ const tempTransform2 = new Matrix3();
1092
+ const tempTransform3 = new Matrix3();
1093
+ const tempV2 = new Vector2();
1094
+ const tempV3 = new Vector3();
1095
+ const currentTransform = new Matrix3();
1096
+ const xml = new DOMParser().parseFromString(text, "image/svg+xml");
1097
+ parseNode(xml.documentElement, {
1098
+ fill: "#000",
1099
+ fillOpacity: 1,
1100
+ strokeOpacity: 1,
1101
+ strokeWidth: 1,
1102
+ strokeLineJoin: "miter",
1103
+ strokeLineCap: "butt",
1104
+ strokeMiterLimit: 4
1105
+ });
1106
+ const data = { paths, xml: xml.documentElement };
1107
+ return data;
1084
1108
  }
1085
- const paths = [];
1086
- const stylesheets = {};
1087
- const transformStack = [];
1088
- const tempTransform0 = new Matrix3();
1089
- const tempTransform1 = new Matrix3();
1090
- const tempTransform2 = new Matrix3();
1091
- const tempTransform3 = new Matrix3();
1092
- const tempV2 = new Vector2();
1093
- const tempV3 = new Vector3();
1094
- const currentTransform = new Matrix3();
1095
- const xml = new DOMParser().parseFromString(text, "image/svg+xml");
1096
- parseNode(xml.documentElement, {
1097
- fill: "#000",
1098
- fillOpacity: 1,
1099
- strokeOpacity: 1,
1100
- strokeWidth: 1,
1101
- strokeLineJoin: "miter",
1102
- strokeLineCap: "butt",
1103
- strokeMiterLimit: 4
1104
- });
1105
- const data = { paths, xml: xml.documentElement };
1106
- return data;
1107
- }
1108
- static createShapes(shapePath) {
1109
- const BIGNUMBER = 999999999;
1110
- const IntersectionLocationType = {
1111
- ORIGIN: 0,
1112
- DESTINATION: 1,
1113
- BETWEEN: 2,
1114
- LEFT: 3,
1115
- RIGHT: 4,
1116
- BEHIND: 5,
1117
- BEYOND: 6
1118
- };
1119
- const classifyResult = {
1120
- loc: IntersectionLocationType.ORIGIN,
1121
- t: 0
1122
- };
1123
- function findEdgeIntersection(a0, a1, b0, b1) {
1124
- const x1 = a0.x;
1125
- const x2 = a1.x;
1126
- const x3 = b0.x;
1127
- const x4 = b1.x;
1128
- const y1 = a0.y;
1129
- const y2 = a1.y;
1130
- const y3 = b0.y;
1131
- const y4 = b1.y;
1132
- const nom1 = (x4 - x3) * (y1 - y3) - (y4 - y3) * (x1 - x3);
1133
- const nom2 = (x2 - x1) * (y1 - y3) - (y2 - y1) * (x1 - x3);
1134
- const denom = (y4 - y3) * (x2 - x1) - (x4 - x3) * (y2 - y1);
1135
- const t1 = nom1 / denom;
1136
- const t2 = nom2 / denom;
1137
- if (denom === 0 && nom1 !== 0 || t1 <= 0 || t1 >= 1 || t2 < 0 || t2 > 1) {
1138
- return null;
1139
- } else if (nom1 === 0 && denom === 0) {
1140
- for (let i = 0; i < 2; i++) {
1141
- classifyPoint(i === 0 ? b0 : b1, a0, a1);
1142
- if (classifyResult.loc == IntersectionLocationType.ORIGIN) {
1143
- const point = i === 0 ? b0 : b1;
1144
- return { x: point.x, y: point.y, t: classifyResult.t };
1145
- } else if (classifyResult.loc == IntersectionLocationType.BETWEEN) {
1146
- const x = +(x1 + classifyResult.t * (x2 - x1)).toPrecision(10);
1147
- const y = +(y1 + classifyResult.t * (y2 - y1)).toPrecision(10);
1148
- return { x, y, t: classifyResult.t };
1109
+ static createShapes(shapePath) {
1110
+ const BIGNUMBER = 999999999;
1111
+ const IntersectionLocationType = {
1112
+ ORIGIN: 0,
1113
+ DESTINATION: 1,
1114
+ BETWEEN: 2,
1115
+ LEFT: 3,
1116
+ RIGHT: 4,
1117
+ BEHIND: 5,
1118
+ BEYOND: 6
1119
+ };
1120
+ const classifyResult = {
1121
+ loc: IntersectionLocationType.ORIGIN,
1122
+ t: 0
1123
+ };
1124
+ function findEdgeIntersection(a0, a1, b0, b1) {
1125
+ const x1 = a0.x;
1126
+ const x2 = a1.x;
1127
+ const x3 = b0.x;
1128
+ const x4 = b1.x;
1129
+ const y1 = a0.y;
1130
+ const y2 = a1.y;
1131
+ const y3 = b0.y;
1132
+ const y4 = b1.y;
1133
+ const nom1 = (x4 - x3) * (y1 - y3) - (y4 - y3) * (x1 - x3);
1134
+ const nom2 = (x2 - x1) * (y1 - y3) - (y2 - y1) * (x1 - x3);
1135
+ const denom = (y4 - y3) * (x2 - x1) - (x4 - x3) * (y2 - y1);
1136
+ const t1 = nom1 / denom;
1137
+ const t2 = nom2 / denom;
1138
+ if (denom === 0 && nom1 !== 0 || t1 <= 0 || t1 >= 1 || t2 < 0 || t2 > 1) {
1139
+ return null;
1140
+ } else if (nom1 === 0 && denom === 0) {
1141
+ for (let i = 0; i < 2; i++) {
1142
+ classifyPoint(i === 0 ? b0 : b1, a0, a1);
1143
+ if (classifyResult.loc == IntersectionLocationType.ORIGIN) {
1144
+ const point = i === 0 ? b0 : b1;
1145
+ return { x: point.x, y: point.y, t: classifyResult.t };
1146
+ } else if (classifyResult.loc == IntersectionLocationType.BETWEEN) {
1147
+ const x = +(x1 + classifyResult.t * (x2 - x1)).toPrecision(10);
1148
+ const y = +(y1 + classifyResult.t * (y2 - y1)).toPrecision(10);
1149
+ return { x, y, t: classifyResult.t };
1150
+ }
1149
1151
  }
1150
- }
1151
- return null;
1152
- } else {
1153
- for (let i = 0; i < 2; i++) {
1154
- classifyPoint(i === 0 ? b0 : b1, a0, a1);
1155
- if (classifyResult.loc == IntersectionLocationType.ORIGIN) {
1156
- const point = i === 0 ? b0 : b1;
1157
- return { x: point.x, y: point.y, t: classifyResult.t };
1152
+ return null;
1153
+ } else {
1154
+ for (let i = 0; i < 2; i++) {
1155
+ classifyPoint(i === 0 ? b0 : b1, a0, a1);
1156
+ if (classifyResult.loc == IntersectionLocationType.ORIGIN) {
1157
+ const point = i === 0 ? b0 : b1;
1158
+ return { x: point.x, y: point.y, t: classifyResult.t };
1159
+ }
1158
1160
  }
1161
+ const x = +(x1 + t1 * (x2 - x1)).toPrecision(10);
1162
+ const y = +(y1 + t1 * (y2 - y1)).toPrecision(10);
1163
+ return { x, y, t: t1 };
1159
1164
  }
1160
- const x = +(x1 + t1 * (x2 - x1)).toPrecision(10);
1161
- const y = +(y1 + t1 * (y2 - y1)).toPrecision(10);
1162
- return { x, y, t: t1 };
1163
- }
1164
- }
1165
- function classifyPoint(p, edgeStart, edgeEnd) {
1166
- const ax = edgeEnd.x - edgeStart.x;
1167
- const ay = edgeEnd.y - edgeStart.y;
1168
- const bx = p.x - edgeStart.x;
1169
- const by = p.y - edgeStart.y;
1170
- const sa = ax * by - bx * ay;
1171
- if (p.x === edgeStart.x && p.y === edgeStart.y) {
1172
- classifyResult.loc = IntersectionLocationType.ORIGIN;
1173
- classifyResult.t = 0;
1174
- return;
1175
- }
1176
- if (p.x === edgeEnd.x && p.y === edgeEnd.y) {
1177
- classifyResult.loc = IntersectionLocationType.DESTINATION;
1178
- classifyResult.t = 1;
1179
- return;
1180
- }
1181
- if (sa < -Number.EPSILON) {
1182
- classifyResult.loc = IntersectionLocationType.LEFT;
1183
- return;
1184
- }
1185
- if (sa > Number.EPSILON) {
1186
- classifyResult.loc = IntersectionLocationType.RIGHT;
1187
- return;
1188
- }
1189
- if (ax * bx < 0 || ay * by < 0) {
1190
- classifyResult.loc = IntersectionLocationType.BEHIND;
1191
- return;
1192
- }
1193
- if (Math.sqrt(ax * ax + ay * ay) < Math.sqrt(bx * bx + by * by)) {
1194
- classifyResult.loc = IntersectionLocationType.BEYOND;
1195
- return;
1196
- }
1197
- let t;
1198
- if (ax !== 0) {
1199
- t = bx / ax;
1200
- } else {
1201
- t = by / ay;
1202
1165
  }
1203
- classifyResult.loc = IntersectionLocationType.BETWEEN;
1204
- classifyResult.t = t;
1205
- }
1206
- function getIntersections(path1, path2) {
1207
- const intersectionsRaw = [];
1208
- const intersections = [];
1209
- for (let index = 1; index < path1.length; index++) {
1210
- const path1EdgeStart = path1[index - 1];
1211
- const path1EdgeEnd = path1[index];
1212
- for (let index2 = 1; index2 < path2.length; index2++) {
1213
- const path2EdgeStart = path2[index2 - 1];
1214
- const path2EdgeEnd = path2[index2];
1215
- const intersection = findEdgeIntersection(path1EdgeStart, path1EdgeEnd, path2EdgeStart, path2EdgeEnd);
1216
- if (intersection !== null && intersectionsRaw.find(
1217
- (i) => i.t <= intersection.t + Number.EPSILON && i.t >= intersection.t - Number.EPSILON
1218
- ) === void 0) {
1219
- intersectionsRaw.push(intersection);
1220
- intersections.push(new Vector2(intersection.x, intersection.y));
1166
+ function classifyPoint(p, edgeStart, edgeEnd) {
1167
+ const ax = edgeEnd.x - edgeStart.x;
1168
+ const ay = edgeEnd.y - edgeStart.y;
1169
+ const bx = p.x - edgeStart.x;
1170
+ const by = p.y - edgeStart.y;
1171
+ const sa = ax * by - bx * ay;
1172
+ if (p.x === edgeStart.x && p.y === edgeStart.y) {
1173
+ classifyResult.loc = IntersectionLocationType.ORIGIN;
1174
+ classifyResult.t = 0;
1175
+ return;
1176
+ }
1177
+ if (p.x === edgeEnd.x && p.y === edgeEnd.y) {
1178
+ classifyResult.loc = IntersectionLocationType.DESTINATION;
1179
+ classifyResult.t = 1;
1180
+ return;
1181
+ }
1182
+ if (sa < -Number.EPSILON) {
1183
+ classifyResult.loc = IntersectionLocationType.LEFT;
1184
+ return;
1185
+ }
1186
+ if (sa > Number.EPSILON) {
1187
+ classifyResult.loc = IntersectionLocationType.RIGHT;
1188
+ return;
1189
+ }
1190
+ if (ax * bx < 0 || ay * by < 0) {
1191
+ classifyResult.loc = IntersectionLocationType.BEHIND;
1192
+ return;
1193
+ }
1194
+ if (Math.sqrt(ax * ax + ay * ay) < Math.sqrt(bx * bx + by * by)) {
1195
+ classifyResult.loc = IntersectionLocationType.BEYOND;
1196
+ return;
1197
+ }
1198
+ let t;
1199
+ if (ax !== 0) {
1200
+ t = bx / ax;
1201
+ } else {
1202
+ t = by / ay;
1203
+ }
1204
+ classifyResult.loc = IntersectionLocationType.BETWEEN;
1205
+ classifyResult.t = t;
1206
+ }
1207
+ function getIntersections(path1, path2) {
1208
+ const intersectionsRaw = [];
1209
+ const intersections = [];
1210
+ for (let index = 1; index < path1.length; index++) {
1211
+ const path1EdgeStart = path1[index - 1];
1212
+ const path1EdgeEnd = path1[index];
1213
+ for (let index2 = 1; index2 < path2.length; index2++) {
1214
+ const path2EdgeStart = path2[index2 - 1];
1215
+ const path2EdgeEnd = path2[index2];
1216
+ const intersection = findEdgeIntersection(path1EdgeStart, path1EdgeEnd, path2EdgeStart, path2EdgeEnd);
1217
+ if (intersection !== null && intersectionsRaw.find(
1218
+ (i) => i.t <= intersection.t + Number.EPSILON && i.t >= intersection.t - Number.EPSILON
1219
+ ) === void 0) {
1220
+ intersectionsRaw.push(intersection);
1221
+ intersections.push(new Vector2(intersection.x, intersection.y));
1222
+ }
1221
1223
  }
1222
1224
  }
1225
+ return intersections;
1226
+ }
1227
+ function getScanlineIntersections(scanline, boundingBox, paths) {
1228
+ const center = new Vector2();
1229
+ boundingBox.getCenter(center);
1230
+ const allIntersections = [];
1231
+ paths.forEach((path) => {
1232
+ if (path.boundingBox.containsPoint(center)) {
1233
+ const intersections = getIntersections(scanline, path.points);
1234
+ intersections.forEach((p) => {
1235
+ allIntersections.push({ identifier: path.identifier, isCW: path.isCW, point: p });
1236
+ });
1237
+ }
1238
+ });
1239
+ allIntersections.sort((i1, i2) => {
1240
+ return i1.point.x - i2.point.x;
1241
+ });
1242
+ return allIntersections;
1223
1243
  }
1224
- return intersections;
1225
- }
1226
- function getScanlineIntersections(scanline, boundingBox, paths) {
1227
- const center = new Vector2();
1228
- boundingBox.getCenter(center);
1229
- const allIntersections = [];
1230
- paths.forEach((path) => {
1231
- if (path.boundingBox.containsPoint(center)) {
1232
- const intersections = getIntersections(scanline, path.points);
1233
- intersections.forEach((p) => {
1234
- allIntersections.push({ identifier: path.identifier, isCW: path.isCW, point: p });
1235
- });
1244
+ function isHoleTo(simplePath, allPaths, scanlineMinX2, scanlineMaxX2, _fillRule) {
1245
+ if (_fillRule === null || _fillRule === void 0 || _fillRule === "") {
1246
+ _fillRule = "nonzero";
1236
1247
  }
1237
- });
1238
- allIntersections.sort((i1, i2) => {
1239
- return i1.point.x - i2.point.x;
1240
- });
1241
- return allIntersections;
1242
- }
1243
- function isHoleTo(simplePath, allPaths, scanlineMinX2, scanlineMaxX2, _fillRule) {
1244
- if (_fillRule === null || _fillRule === void 0 || _fillRule === "") {
1245
- _fillRule = "nonzero";
1246
- }
1247
- const centerBoundingBox = new Vector2();
1248
- simplePath.boundingBox.getCenter(centerBoundingBox);
1249
- const scanline = [new Vector2(scanlineMinX2, centerBoundingBox.y), new Vector2(scanlineMaxX2, centerBoundingBox.y)];
1250
- const scanlineIntersections = getScanlineIntersections(scanline, simplePath.boundingBox, allPaths);
1251
- scanlineIntersections.sort((i1, i2) => {
1252
- return i1.point.x - i2.point.x;
1253
- });
1254
- const baseIntersections = [];
1255
- const otherIntersections = [];
1256
- scanlineIntersections.forEach((i2) => {
1257
- if (i2.identifier === simplePath.identifier) {
1258
- baseIntersections.push(i2);
1259
- } else {
1260
- otherIntersections.push(i2);
1248
+ const centerBoundingBox = new Vector2();
1249
+ simplePath.boundingBox.getCenter(centerBoundingBox);
1250
+ const scanline = [
1251
+ new Vector2(scanlineMinX2, centerBoundingBox.y),
1252
+ new Vector2(scanlineMaxX2, centerBoundingBox.y)
1253
+ ];
1254
+ const scanlineIntersections = getScanlineIntersections(scanline, simplePath.boundingBox, allPaths);
1255
+ scanlineIntersections.sort((i1, i2) => {
1256
+ return i1.point.x - i2.point.x;
1257
+ });
1258
+ const baseIntersections = [];
1259
+ const otherIntersections = [];
1260
+ scanlineIntersections.forEach((i2) => {
1261
+ if (i2.identifier === simplePath.identifier) {
1262
+ baseIntersections.push(i2);
1263
+ } else {
1264
+ otherIntersections.push(i2);
1265
+ }
1266
+ });
1267
+ const firstXOfPath = baseIntersections[0].point.x;
1268
+ const stack = [];
1269
+ let i = 0;
1270
+ while (i < otherIntersections.length && otherIntersections[i].point.x < firstXOfPath) {
1271
+ if (stack.length > 0 && stack[stack.length - 1] === otherIntersections[i].identifier) {
1272
+ stack.pop();
1273
+ } else {
1274
+ stack.push(otherIntersections[i].identifier);
1275
+ }
1276
+ i++;
1261
1277
  }
1262
- });
1263
- const firstXOfPath = baseIntersections[0].point.x;
1264
- const stack = [];
1265
- let i = 0;
1266
- while (i < otherIntersections.length && otherIntersections[i].point.x < firstXOfPath) {
1267
- if (stack.length > 0 && stack[stack.length - 1] === otherIntersections[i].identifier) {
1268
- stack.pop();
1278
+ stack.push(simplePath.identifier);
1279
+ if (_fillRule === "evenodd") {
1280
+ const isHole = stack.length % 2 === 0 ? true : false;
1281
+ const isHoleFor = stack[stack.length - 2];
1282
+ return { identifier: simplePath.identifier, isHole, for: isHoleFor };
1283
+ } else if (_fillRule === "nonzero") {
1284
+ let isHole = true;
1285
+ let isHoleFor = null;
1286
+ let lastCWValue = null;
1287
+ for (let i2 = 0; i2 < stack.length; i2++) {
1288
+ const identifier = stack[i2];
1289
+ if (isHole) {
1290
+ lastCWValue = allPaths[identifier].isCW;
1291
+ isHole = false;
1292
+ isHoleFor = identifier;
1293
+ } else if (lastCWValue !== allPaths[identifier].isCW) {
1294
+ lastCWValue = allPaths[identifier].isCW;
1295
+ isHole = true;
1296
+ }
1297
+ }
1298
+ return { identifier: simplePath.identifier, isHole, for: isHoleFor };
1269
1299
  } else {
1270
- stack.push(otherIntersections[i].identifier);
1300
+ console.warn('fill-rule: "' + _fillRule + '" is currently not implemented.');
1271
1301
  }
1272
- i++;
1273
1302
  }
1274
- stack.push(simplePath.identifier);
1275
- if (_fillRule === "evenodd") {
1276
- const isHole = stack.length % 2 === 0 ? true : false;
1277
- const isHoleFor = stack[stack.length - 2];
1278
- return { identifier: simplePath.identifier, isHole, for: isHoleFor };
1279
- } else if (_fillRule === "nonzero") {
1280
- let isHole = true;
1281
- let isHoleFor = null;
1282
- let lastCWValue = null;
1283
- for (let i2 = 0; i2 < stack.length; i2++) {
1284
- const identifier = stack[i2];
1285
- if (isHole) {
1286
- lastCWValue = allPaths[identifier].isCW;
1287
- isHole = false;
1288
- isHoleFor = identifier;
1289
- } else if (lastCWValue !== allPaths[identifier].isCW) {
1290
- lastCWValue = allPaths[identifier].isCW;
1291
- isHole = true;
1303
+ let scanlineMinX = BIGNUMBER;
1304
+ let scanlineMaxX = -BIGNUMBER;
1305
+ let simplePaths = shapePath.subPaths.map((p) => {
1306
+ const points = p.getPoints();
1307
+ let maxY = -BIGNUMBER;
1308
+ let minY = BIGNUMBER;
1309
+ let maxX = -BIGNUMBER;
1310
+ let minX = BIGNUMBER;
1311
+ for (let i = 0; i < points.length; i++) {
1312
+ const p2 = points[i];
1313
+ if (p2.y > maxY) {
1314
+ maxY = p2.y;
1315
+ }
1316
+ if (p2.y < minY) {
1317
+ minY = p2.y;
1318
+ }
1319
+ if (p2.x > maxX) {
1320
+ maxX = p2.x;
1321
+ }
1322
+ if (p2.x < minX) {
1323
+ minX = p2.x;
1292
1324
  }
1293
1325
  }
1294
- return { identifier: simplePath.identifier, isHole, for: isHoleFor };
1295
- } else {
1296
- console.warn('fill-rule: "' + _fillRule + '" is currently not implemented.');
1297
- }
1298
- }
1299
- let scanlineMinX = BIGNUMBER;
1300
- let scanlineMaxX = -BIGNUMBER;
1301
- let simplePaths = shapePath.subPaths.map((p) => {
1302
- const points = p.getPoints();
1303
- let maxY = -BIGNUMBER;
1304
- let minY = BIGNUMBER;
1305
- let maxX = -BIGNUMBER;
1306
- let minX = BIGNUMBER;
1307
- for (let i = 0; i < points.length; i++) {
1308
- const p2 = points[i];
1309
- if (p2.y > maxY) {
1310
- maxY = p2.y;
1311
- }
1312
- if (p2.y < minY) {
1313
- minY = p2.y;
1314
- }
1315
- if (p2.x > maxX) {
1316
- maxX = p2.x;
1317
- }
1318
- if (p2.x < minX) {
1319
- minX = p2.x;
1326
+ if (scanlineMaxX <= maxX) {
1327
+ scanlineMaxX = maxX + 1;
1320
1328
  }
1321
- }
1322
- if (scanlineMaxX <= maxX) {
1323
- scanlineMaxX = maxX + 1;
1324
- }
1325
- if (scanlineMinX >= minX) {
1326
- scanlineMinX = minX - 1;
1327
- }
1329
+ if (scanlineMinX >= minX) {
1330
+ scanlineMinX = minX - 1;
1331
+ }
1332
+ return {
1333
+ curves: p.curves,
1334
+ points,
1335
+ isCW: ShapeUtils.isClockWise(points),
1336
+ identifier: -1,
1337
+ boundingBox: new Box2(new Vector2(minX, minY), new Vector2(maxX, maxY))
1338
+ };
1339
+ });
1340
+ simplePaths = simplePaths.filter((sp) => sp.points.length > 1);
1341
+ for (let identifier = 0; identifier < simplePaths.length; identifier++) {
1342
+ simplePaths[identifier].identifier = identifier;
1343
+ }
1344
+ const isAHole = simplePaths.map(
1345
+ (p) => isHoleTo(
1346
+ p,
1347
+ simplePaths,
1348
+ scanlineMinX,
1349
+ scanlineMaxX,
1350
+ shapePath.userData ? shapePath.userData.style.fillRule : void 0
1351
+ )
1352
+ );
1353
+ const shapesToReturn = [];
1354
+ simplePaths.forEach((p) => {
1355
+ const amIAHole = isAHole[p.identifier];
1356
+ if (!amIAHole.isHole) {
1357
+ const shape = new Shape();
1358
+ shape.curves = p.curves;
1359
+ const holes = isAHole.filter((h) => h.isHole && h.for === p.identifier);
1360
+ holes.forEach((h) => {
1361
+ const hole = simplePaths[h.identifier];
1362
+ const path = new Path();
1363
+ path.curves = hole.curves;
1364
+ shape.holes.push(path);
1365
+ });
1366
+ shapesToReturn.push(shape);
1367
+ }
1368
+ });
1369
+ return shapesToReturn;
1370
+ }
1371
+ static getStrokeStyle(width, color, lineJoin, lineCap, miterLimit) {
1372
+ width = width !== void 0 ? width : 1;
1373
+ color = color !== void 0 ? color : "#000";
1374
+ lineJoin = lineJoin !== void 0 ? lineJoin : "miter";
1375
+ lineCap = lineCap !== void 0 ? lineCap : "butt";
1376
+ miterLimit = miterLimit !== void 0 ? miterLimit : 4;
1328
1377
  return {
1329
- curves: p.curves,
1330
- points,
1331
- isCW: ShapeUtils.isClockWise(points),
1332
- identifier: -1,
1333
- boundingBox: new Box2(new Vector2(minX, minY), new Vector2(maxX, maxY))
1378
+ strokeColor: color,
1379
+ strokeWidth: width,
1380
+ strokeLineJoin: lineJoin,
1381
+ strokeLineCap: lineCap,
1382
+ strokeMiterLimit: miterLimit
1334
1383
  };
1335
- });
1336
- simplePaths = simplePaths.filter((sp) => sp.points.length > 1);
1337
- for (let identifier = 0; identifier < simplePaths.length; identifier++) {
1338
- simplePaths[identifier].identifier = identifier;
1339
1384
  }
1340
- const isAHole = simplePaths.map(
1341
- (p) => isHoleTo(
1342
- p,
1343
- simplePaths,
1344
- scanlineMinX,
1345
- scanlineMaxX,
1346
- shapePath.userData ? shapePath.userData.style.fillRule : void 0
1347
- )
1348
- );
1349
- const shapesToReturn = [];
1350
- simplePaths.forEach((p) => {
1351
- const amIAHole = isAHole[p.identifier];
1352
- if (!amIAHole.isHole) {
1353
- const shape = new Shape();
1354
- shape.curves = p.curves;
1355
- const holes = isAHole.filter((h) => h.isHole && h.for === p.identifier);
1356
- holes.forEach((h) => {
1357
- const hole = simplePaths[h.identifier];
1358
- const path = new Path();
1359
- path.curves = hole.curves;
1360
- shape.holes.push(path);
1361
- });
1362
- shapesToReturn.push(shape);
1385
+ static pointsToStroke(points, style, arcDivisions, minDistance) {
1386
+ const vertices = [];
1387
+ const normals = [];
1388
+ const uvs = [];
1389
+ if (SVGLoader2.pointsToStrokeWithBuffers(points, style, arcDivisions, minDistance, vertices, normals, uvs) === 0) {
1390
+ return null;
1363
1391
  }
1364
- });
1365
- return shapesToReturn;
1366
- }
1367
- static getStrokeStyle(width, color, lineJoin, lineCap, miterLimit) {
1368
- width = width !== void 0 ? width : 1;
1369
- color = color !== void 0 ? color : "#000";
1370
- lineJoin = lineJoin !== void 0 ? lineJoin : "miter";
1371
- lineCap = lineCap !== void 0 ? lineCap : "butt";
1372
- miterLimit = miterLimit !== void 0 ? miterLimit : 4;
1373
- return {
1374
- strokeColor: color,
1375
- strokeWidth: width,
1376
- strokeLineJoin: lineJoin,
1377
- strokeLineCap: lineCap,
1378
- strokeMiterLimit: miterLimit
1379
- };
1380
- }
1381
- static pointsToStroke(points, style, arcDivisions, minDistance) {
1382
- const vertices = [];
1383
- const normals = [];
1384
- const uvs = [];
1385
- if (SVGLoader.pointsToStrokeWithBuffers(points, style, arcDivisions, minDistance, vertices, normals, uvs) === 0) {
1386
- return null;
1392
+ const geometry = new BufferGeometry();
1393
+ geometry.setAttribute("position", new Float32BufferAttribute(vertices, 3));
1394
+ geometry.setAttribute("normal", new Float32BufferAttribute(normals, 3));
1395
+ geometry.setAttribute("uv", new Float32BufferAttribute(uvs, 2));
1396
+ return geometry;
1387
1397
  }
1388
- const geometry = new BufferGeometry();
1389
- geometry.setAttribute("position", new Float32BufferAttribute(vertices, 3));
1390
- geometry.setAttribute("normal", new Float32BufferAttribute(normals, 3));
1391
- geometry.setAttribute("uv", new Float32BufferAttribute(uvs, 2));
1392
- return geometry;
1393
- }
1394
- static pointsToStrokeWithBuffers(points, style, arcDivisions, minDistance, vertices, normals, uvs, vertexOffset) {
1395
- const tempV2_1 = new Vector2();
1396
- const tempV2_2 = new Vector2();
1397
- const tempV2_3 = new Vector2();
1398
- const tempV2_4 = new Vector2();
1399
- const tempV2_5 = new Vector2();
1400
- const tempV2_6 = new Vector2();
1401
- const tempV2_7 = new Vector2();
1402
- const lastPointL = new Vector2();
1403
- const lastPointR = new Vector2();
1404
- const point0L = new Vector2();
1405
- const point0R = new Vector2();
1406
- const currentPointL = new Vector2();
1407
- const currentPointR = new Vector2();
1408
- const nextPointL = new Vector2();
1409
- const nextPointR = new Vector2();
1410
- const innerPoint = new Vector2();
1411
- const outerPoint = new Vector2();
1412
- arcDivisions = arcDivisions !== void 0 ? arcDivisions : 12;
1413
- minDistance = minDistance !== void 0 ? minDistance : 1e-3;
1414
- vertexOffset = vertexOffset !== void 0 ? vertexOffset : 0;
1415
- points = removeDuplicatedPoints(points);
1416
- const numPoints = points.length;
1417
- if (numPoints < 2)
1418
- return 0;
1419
- const isClosed = points[0].equals(points[numPoints - 1]);
1420
- let currentPoint;
1421
- let previousPoint = points[0];
1422
- let nextPoint;
1423
- const strokeWidth2 = style.strokeWidth / 2;
1424
- const deltaU = 1 / (numPoints - 1);
1425
- let u0 = 0, u1;
1426
- let innerSideModified;
1427
- let joinIsOnLeftSide;
1428
- let isMiter;
1429
- let initialJoinIsOnLeftSide = false;
1430
- let numVertices = 0;
1431
- let currentCoordinate = vertexOffset * 3;
1432
- let currentCoordinateUV = vertexOffset * 2;
1433
- getNormal(points[0], points[1], tempV2_1).multiplyScalar(strokeWidth2);
1434
- lastPointL.copy(points[0]).sub(tempV2_1);
1435
- lastPointR.copy(points[0]).add(tempV2_1);
1436
- point0L.copy(lastPointL);
1437
- point0R.copy(lastPointR);
1438
- for (let iPoint = 1; iPoint < numPoints; iPoint++) {
1439
- currentPoint = points[iPoint];
1440
- if (iPoint === numPoints - 1) {
1441
- if (isClosed) {
1442
- nextPoint = points[1];
1443
- } else
1444
- nextPoint = void 0;
1445
- } else {
1446
- nextPoint = points[iPoint + 1];
1447
- }
1448
- const normal1 = tempV2_1;
1449
- getNormal(previousPoint, currentPoint, normal1);
1450
- tempV2_3.copy(normal1).multiplyScalar(strokeWidth2);
1451
- currentPointL.copy(currentPoint).sub(tempV2_3);
1452
- currentPointR.copy(currentPoint).add(tempV2_3);
1453
- u1 = u0 + deltaU;
1454
- innerSideModified = false;
1455
- if (nextPoint !== void 0) {
1456
- getNormal(currentPoint, nextPoint, tempV2_2);
1457
- tempV2_3.copy(tempV2_2).multiplyScalar(strokeWidth2);
1458
- nextPointL.copy(currentPoint).sub(tempV2_3);
1459
- nextPointR.copy(currentPoint).add(tempV2_3);
1460
- joinIsOnLeftSide = true;
1461
- tempV2_3.subVectors(nextPoint, previousPoint);
1462
- if (normal1.dot(tempV2_3) < 0) {
1463
- joinIsOnLeftSide = false;
1464
- }
1465
- if (iPoint === 1)
1466
- initialJoinIsOnLeftSide = joinIsOnLeftSide;
1467
- tempV2_3.subVectors(nextPoint, currentPoint);
1468
- tempV2_3.normalize();
1469
- const dot = Math.abs(normal1.dot(tempV2_3));
1470
- if (dot > Number.EPSILON) {
1471
- const miterSide = strokeWidth2 / dot;
1472
- tempV2_3.multiplyScalar(-miterSide);
1473
- tempV2_4.subVectors(currentPoint, previousPoint);
1474
- tempV2_5.copy(tempV2_4).setLength(miterSide).add(tempV2_3);
1475
- innerPoint.copy(tempV2_5).negate();
1476
- const miterLength2 = tempV2_5.length();
1477
- const segmentLengthPrev = tempV2_4.length();
1478
- tempV2_4.divideScalar(segmentLengthPrev);
1479
- tempV2_6.subVectors(nextPoint, currentPoint);
1480
- const segmentLengthNext = tempV2_6.length();
1481
- tempV2_6.divideScalar(segmentLengthNext);
1482
- if (tempV2_4.dot(innerPoint) < segmentLengthPrev && tempV2_6.dot(innerPoint) < segmentLengthNext) {
1483
- innerSideModified = true;
1398
+ static pointsToStrokeWithBuffers(points, style, arcDivisions, minDistance, vertices, normals, uvs, vertexOffset) {
1399
+ const tempV2_1 = new Vector2();
1400
+ const tempV2_2 = new Vector2();
1401
+ const tempV2_3 = new Vector2();
1402
+ const tempV2_4 = new Vector2();
1403
+ const tempV2_5 = new Vector2();
1404
+ const tempV2_6 = new Vector2();
1405
+ const tempV2_7 = new Vector2();
1406
+ const lastPointL = new Vector2();
1407
+ const lastPointR = new Vector2();
1408
+ const point0L = new Vector2();
1409
+ const point0R = new Vector2();
1410
+ const currentPointL = new Vector2();
1411
+ const currentPointR = new Vector2();
1412
+ const nextPointL = new Vector2();
1413
+ const nextPointR = new Vector2();
1414
+ const innerPoint = new Vector2();
1415
+ const outerPoint = new Vector2();
1416
+ arcDivisions = arcDivisions !== void 0 ? arcDivisions : 12;
1417
+ minDistance = minDistance !== void 0 ? minDistance : 1e-3;
1418
+ vertexOffset = vertexOffset !== void 0 ? vertexOffset : 0;
1419
+ points = removeDuplicatedPoints(points);
1420
+ const numPoints = points.length;
1421
+ if (numPoints < 2)
1422
+ return 0;
1423
+ const isClosed = points[0].equals(points[numPoints - 1]);
1424
+ let currentPoint;
1425
+ let previousPoint = points[0];
1426
+ let nextPoint;
1427
+ const strokeWidth2 = style.strokeWidth / 2;
1428
+ const deltaU = 1 / (numPoints - 1);
1429
+ let u0 = 0, u1;
1430
+ let innerSideModified;
1431
+ let joinIsOnLeftSide;
1432
+ let isMiter;
1433
+ let initialJoinIsOnLeftSide = false;
1434
+ let numVertices = 0;
1435
+ let currentCoordinate = vertexOffset * 3;
1436
+ let currentCoordinateUV = vertexOffset * 2;
1437
+ getNormal(points[0], points[1], tempV2_1).multiplyScalar(strokeWidth2);
1438
+ lastPointL.copy(points[0]).sub(tempV2_1);
1439
+ lastPointR.copy(points[0]).add(tempV2_1);
1440
+ point0L.copy(lastPointL);
1441
+ point0R.copy(lastPointR);
1442
+ for (let iPoint = 1; iPoint < numPoints; iPoint++) {
1443
+ currentPoint = points[iPoint];
1444
+ if (iPoint === numPoints - 1) {
1445
+ if (isClosed) {
1446
+ nextPoint = points[1];
1447
+ } else
1448
+ nextPoint = void 0;
1449
+ } else {
1450
+ nextPoint = points[iPoint + 1];
1451
+ }
1452
+ const normal1 = tempV2_1;
1453
+ getNormal(previousPoint, currentPoint, normal1);
1454
+ tempV2_3.copy(normal1).multiplyScalar(strokeWidth2);
1455
+ currentPointL.copy(currentPoint).sub(tempV2_3);
1456
+ currentPointR.copy(currentPoint).add(tempV2_3);
1457
+ u1 = u0 + deltaU;
1458
+ innerSideModified = false;
1459
+ if (nextPoint !== void 0) {
1460
+ getNormal(currentPoint, nextPoint, tempV2_2);
1461
+ tempV2_3.copy(tempV2_2).multiplyScalar(strokeWidth2);
1462
+ nextPointL.copy(currentPoint).sub(tempV2_3);
1463
+ nextPointR.copy(currentPoint).add(tempV2_3);
1464
+ joinIsOnLeftSide = true;
1465
+ tempV2_3.subVectors(nextPoint, previousPoint);
1466
+ if (normal1.dot(tempV2_3) < 0) {
1467
+ joinIsOnLeftSide = false;
1484
1468
  }
1485
- outerPoint.copy(tempV2_5).add(currentPoint);
1486
- innerPoint.add(currentPoint);
1487
- isMiter = false;
1488
- if (innerSideModified) {
1489
- if (joinIsOnLeftSide) {
1490
- nextPointR.copy(innerPoint);
1491
- currentPointR.copy(innerPoint);
1492
- } else {
1493
- nextPointL.copy(innerPoint);
1494
- currentPointL.copy(innerPoint);
1469
+ if (iPoint === 1)
1470
+ initialJoinIsOnLeftSide = joinIsOnLeftSide;
1471
+ tempV2_3.subVectors(nextPoint, currentPoint);
1472
+ tempV2_3.normalize();
1473
+ const dot = Math.abs(normal1.dot(tempV2_3));
1474
+ if (dot > Number.EPSILON) {
1475
+ const miterSide = strokeWidth2 / dot;
1476
+ tempV2_3.multiplyScalar(-miterSide);
1477
+ tempV2_4.subVectors(currentPoint, previousPoint);
1478
+ tempV2_5.copy(tempV2_4).setLength(miterSide).add(tempV2_3);
1479
+ innerPoint.copy(tempV2_5).negate();
1480
+ const miterLength2 = tempV2_5.length();
1481
+ const segmentLengthPrev = tempV2_4.length();
1482
+ tempV2_4.divideScalar(segmentLengthPrev);
1483
+ tempV2_6.subVectors(nextPoint, currentPoint);
1484
+ const segmentLengthNext = tempV2_6.length();
1485
+ tempV2_6.divideScalar(segmentLengthNext);
1486
+ if (tempV2_4.dot(innerPoint) < segmentLengthPrev && tempV2_6.dot(innerPoint) < segmentLengthNext) {
1487
+ innerSideModified = true;
1495
1488
  }
1496
- } else {
1497
- makeSegmentTriangles();
1498
- }
1499
- switch (style.strokeLineJoin) {
1500
- case "bevel":
1501
- makeSegmentWithBevelJoin(joinIsOnLeftSide, innerSideModified, u1);
1502
- break;
1503
- case "round":
1504
- createSegmentTrianglesWithMiddleSection(joinIsOnLeftSide, innerSideModified);
1489
+ outerPoint.copy(tempV2_5).add(currentPoint);
1490
+ innerPoint.add(currentPoint);
1491
+ isMiter = false;
1492
+ if (innerSideModified) {
1505
1493
  if (joinIsOnLeftSide) {
1506
- makeCircularSector(currentPoint, currentPointL, nextPointL, u1, 0);
1494
+ nextPointR.copy(innerPoint);
1495
+ currentPointR.copy(innerPoint);
1507
1496
  } else {
1508
- makeCircularSector(currentPoint, nextPointR, currentPointR, u1, 1);
1497
+ nextPointL.copy(innerPoint);
1498
+ currentPointL.copy(innerPoint);
1509
1499
  }
1510
- break;
1511
- case "miter":
1512
- case "miter-clip":
1513
- default:
1514
- const miterFraction = strokeWidth2 * style.strokeMiterLimit / miterLength2;
1515
- if (miterFraction < 1) {
1516
- if (style.strokeLineJoin !== "miter-clip") {
1517
- makeSegmentWithBevelJoin(joinIsOnLeftSide, innerSideModified, u1);
1518
- break;
1500
+ } else {
1501
+ makeSegmentTriangles();
1502
+ }
1503
+ switch (style.strokeLineJoin) {
1504
+ case "bevel":
1505
+ makeSegmentWithBevelJoin(joinIsOnLeftSide, innerSideModified, u1);
1506
+ break;
1507
+ case "round":
1508
+ createSegmentTrianglesWithMiddleSection(joinIsOnLeftSide, innerSideModified);
1509
+ if (joinIsOnLeftSide) {
1510
+ makeCircularSector(currentPoint, currentPointL, nextPointL, u1, 0);
1519
1511
  } else {
1520
- createSegmentTrianglesWithMiddleSection(joinIsOnLeftSide, innerSideModified);
1521
- if (joinIsOnLeftSide) {
1522
- tempV2_6.subVectors(outerPoint, currentPointL).multiplyScalar(miterFraction).add(currentPointL);
1523
- tempV2_7.subVectors(outerPoint, nextPointL).multiplyScalar(miterFraction).add(nextPointL);
1524
- addVertex(currentPointL, u1, 0);
1525
- addVertex(tempV2_6, u1, 0);
1526
- addVertex(currentPoint, u1, 0.5);
1527
- addVertex(currentPoint, u1, 0.5);
1528
- addVertex(tempV2_6, u1, 0);
1529
- addVertex(tempV2_7, u1, 0);
1530
- addVertex(currentPoint, u1, 0.5);
1531
- addVertex(tempV2_7, u1, 0);
1532
- addVertex(nextPointL, u1, 0);
1533
- } else {
1534
- tempV2_6.subVectors(outerPoint, currentPointR).multiplyScalar(miterFraction).add(currentPointR);
1535
- tempV2_7.subVectors(outerPoint, nextPointR).multiplyScalar(miterFraction).add(nextPointR);
1536
- addVertex(currentPointR, u1, 1);
1537
- addVertex(tempV2_6, u1, 1);
1538
- addVertex(currentPoint, u1, 0.5);
1539
- addVertex(currentPoint, u1, 0.5);
1540
- addVertex(tempV2_6, u1, 1);
1541
- addVertex(tempV2_7, u1, 1);
1542
- addVertex(currentPoint, u1, 0.5);
1543
- addVertex(tempV2_7, u1, 1);
1544
- addVertex(nextPointR, u1, 1);
1545
- }
1512
+ makeCircularSector(currentPoint, nextPointR, currentPointR, u1, 1);
1546
1513
  }
1547
- } else {
1548
- if (innerSideModified) {
1549
- if (joinIsOnLeftSide) {
1550
- addVertex(lastPointR, u0, 1);
1551
- addVertex(lastPointL, u0, 0);
1552
- addVertex(outerPoint, u1, 0);
1553
- addVertex(lastPointR, u0, 1);
1554
- addVertex(outerPoint, u1, 0);
1555
- addVertex(innerPoint, u1, 1);
1556
- } else {
1557
- addVertex(lastPointR, u0, 1);
1558
- addVertex(lastPointL, u0, 0);
1559
- addVertex(outerPoint, u1, 1);
1560
- addVertex(lastPointL, u0, 0);
1561
- addVertex(innerPoint, u1, 0);
1562
- addVertex(outerPoint, u1, 1);
1563
- }
1564
- if (joinIsOnLeftSide) {
1565
- nextPointL.copy(outerPoint);
1514
+ break;
1515
+ case "miter":
1516
+ case "miter-clip":
1517
+ default:
1518
+ const miterFraction = strokeWidth2 * style.strokeMiterLimit / miterLength2;
1519
+ if (miterFraction < 1) {
1520
+ if (style.strokeLineJoin !== "miter-clip") {
1521
+ makeSegmentWithBevelJoin(joinIsOnLeftSide, innerSideModified, u1);
1522
+ break;
1566
1523
  } else {
1567
- nextPointR.copy(outerPoint);
1524
+ createSegmentTrianglesWithMiddleSection(joinIsOnLeftSide, innerSideModified);
1525
+ if (joinIsOnLeftSide) {
1526
+ tempV2_6.subVectors(outerPoint, currentPointL).multiplyScalar(miterFraction).add(currentPointL);
1527
+ tempV2_7.subVectors(outerPoint, nextPointL).multiplyScalar(miterFraction).add(nextPointL);
1528
+ addVertex(currentPointL, u1, 0);
1529
+ addVertex(tempV2_6, u1, 0);
1530
+ addVertex(currentPoint, u1, 0.5);
1531
+ addVertex(currentPoint, u1, 0.5);
1532
+ addVertex(tempV2_6, u1, 0);
1533
+ addVertex(tempV2_7, u1, 0);
1534
+ addVertex(currentPoint, u1, 0.5);
1535
+ addVertex(tempV2_7, u1, 0);
1536
+ addVertex(nextPointL, u1, 0);
1537
+ } else {
1538
+ tempV2_6.subVectors(outerPoint, currentPointR).multiplyScalar(miterFraction).add(currentPointR);
1539
+ tempV2_7.subVectors(outerPoint, nextPointR).multiplyScalar(miterFraction).add(nextPointR);
1540
+ addVertex(currentPointR, u1, 1);
1541
+ addVertex(tempV2_6, u1, 1);
1542
+ addVertex(currentPoint, u1, 0.5);
1543
+ addVertex(currentPoint, u1, 0.5);
1544
+ addVertex(tempV2_6, u1, 1);
1545
+ addVertex(tempV2_7, u1, 1);
1546
+ addVertex(currentPoint, u1, 0.5);
1547
+ addVertex(tempV2_7, u1, 1);
1548
+ addVertex(nextPointR, u1, 1);
1549
+ }
1568
1550
  }
1569
1551
  } else {
1570
- if (joinIsOnLeftSide) {
1571
- addVertex(currentPointL, u1, 0);
1572
- addVertex(outerPoint, u1, 0);
1573
- addVertex(currentPoint, u1, 0.5);
1574
- addVertex(currentPoint, u1, 0.5);
1575
- addVertex(outerPoint, u1, 0);
1576
- addVertex(nextPointL, u1, 0);
1552
+ if (innerSideModified) {
1553
+ if (joinIsOnLeftSide) {
1554
+ addVertex(lastPointR, u0, 1);
1555
+ addVertex(lastPointL, u0, 0);
1556
+ addVertex(outerPoint, u1, 0);
1557
+ addVertex(lastPointR, u0, 1);
1558
+ addVertex(outerPoint, u1, 0);
1559
+ addVertex(innerPoint, u1, 1);
1560
+ } else {
1561
+ addVertex(lastPointR, u0, 1);
1562
+ addVertex(lastPointL, u0, 0);
1563
+ addVertex(outerPoint, u1, 1);
1564
+ addVertex(lastPointL, u0, 0);
1565
+ addVertex(innerPoint, u1, 0);
1566
+ addVertex(outerPoint, u1, 1);
1567
+ }
1568
+ if (joinIsOnLeftSide) {
1569
+ nextPointL.copy(outerPoint);
1570
+ } else {
1571
+ nextPointR.copy(outerPoint);
1572
+ }
1577
1573
  } else {
1578
- addVertex(currentPointR, u1, 1);
1579
- addVertex(outerPoint, u1, 1);
1580
- addVertex(currentPoint, u1, 0.5);
1581
- addVertex(currentPoint, u1, 0.5);
1582
- addVertex(outerPoint, u1, 1);
1583
- addVertex(nextPointR, u1, 1);
1574
+ if (joinIsOnLeftSide) {
1575
+ addVertex(currentPointL, u1, 0);
1576
+ addVertex(outerPoint, u1, 0);
1577
+ addVertex(currentPoint, u1, 0.5);
1578
+ addVertex(currentPoint, u1, 0.5);
1579
+ addVertex(outerPoint, u1, 0);
1580
+ addVertex(nextPointL, u1, 0);
1581
+ } else {
1582
+ addVertex(currentPointR, u1, 1);
1583
+ addVertex(outerPoint, u1, 1);
1584
+ addVertex(currentPoint, u1, 0.5);
1585
+ addVertex(currentPoint, u1, 0.5);
1586
+ addVertex(outerPoint, u1, 1);
1587
+ addVertex(nextPointR, u1, 1);
1588
+ }
1584
1589
  }
1590
+ isMiter = true;
1585
1591
  }
1586
- isMiter = true;
1587
- }
1588
- break;
1592
+ break;
1593
+ }
1594
+ } else {
1595
+ makeSegmentTriangles();
1589
1596
  }
1590
1597
  } else {
1591
1598
  makeSegmentTriangles();
1592
1599
  }
1593
- } else {
1594
- makeSegmentTriangles();
1595
- }
1596
- if (!isClosed && iPoint === numPoints - 1) {
1597
- addCapGeometry(points[0], point0L, point0R, joinIsOnLeftSide, true, u0);
1598
- }
1599
- u0 = u1;
1600
- previousPoint = currentPoint;
1601
- lastPointL.copy(nextPointL);
1602
- lastPointR.copy(nextPointR);
1603
- }
1604
- if (!isClosed) {
1605
- addCapGeometry(currentPoint, currentPointL, currentPointR, joinIsOnLeftSide, false, u1);
1606
- } else if (innerSideModified && vertices) {
1607
- let lastOuter = outerPoint;
1608
- let lastInner = innerPoint;
1609
- if (initialJoinIsOnLeftSide !== joinIsOnLeftSide) {
1610
- lastOuter = innerPoint;
1611
- lastInner = outerPoint;
1612
- }
1613
- if (joinIsOnLeftSide) {
1614
- if (isMiter || initialJoinIsOnLeftSide) {
1615
- lastInner.toArray(vertices, 0 * 3);
1616
- lastInner.toArray(vertices, 3 * 3);
1617
- if (isMiter) {
1618
- lastOuter.toArray(vertices, 1 * 3);
1619
- }
1600
+ if (!isClosed && iPoint === numPoints - 1) {
1601
+ addCapGeometry(points[0], point0L, point0R, joinIsOnLeftSide, true, u0);
1602
+ }
1603
+ u0 = u1;
1604
+ previousPoint = currentPoint;
1605
+ lastPointL.copy(nextPointL);
1606
+ lastPointR.copy(nextPointR);
1607
+ }
1608
+ if (!isClosed) {
1609
+ addCapGeometry(currentPoint, currentPointL, currentPointR, joinIsOnLeftSide, false, u1);
1610
+ } else if (innerSideModified && vertices) {
1611
+ let lastOuter = outerPoint;
1612
+ let lastInner = innerPoint;
1613
+ if (initialJoinIsOnLeftSide !== joinIsOnLeftSide) {
1614
+ lastOuter = innerPoint;
1615
+ lastInner = outerPoint;
1620
1616
  }
1621
- } else {
1622
- if (isMiter || !initialJoinIsOnLeftSide) {
1623
- lastInner.toArray(vertices, 1 * 3);
1624
- lastInner.toArray(vertices, 3 * 3);
1625
- if (isMiter) {
1626
- lastOuter.toArray(vertices, 0 * 3);
1617
+ if (joinIsOnLeftSide) {
1618
+ if (isMiter || initialJoinIsOnLeftSide) {
1619
+ lastInner.toArray(vertices, 0 * 3);
1620
+ lastInner.toArray(vertices, 3 * 3);
1621
+ if (isMiter) {
1622
+ lastOuter.toArray(vertices, 1 * 3);
1623
+ }
1624
+ }
1625
+ } else {
1626
+ if (isMiter || !initialJoinIsOnLeftSide) {
1627
+ lastInner.toArray(vertices, 1 * 3);
1628
+ lastInner.toArray(vertices, 3 * 3);
1629
+ if (isMiter) {
1630
+ lastOuter.toArray(vertices, 0 * 3);
1631
+ }
1627
1632
  }
1628
1633
  }
1629
1634
  }
1630
- }
1631
- return numVertices;
1632
- function getNormal(p1, p2, result) {
1633
- result.subVectors(p2, p1);
1634
- return result.set(-result.y, result.x).normalize();
1635
- }
1636
- function addVertex(position, u, v) {
1637
- if (vertices) {
1638
- vertices[currentCoordinate] = position.x;
1639
- vertices[currentCoordinate + 1] = position.y;
1640
- vertices[currentCoordinate + 2] = 0;
1641
- if (normals) {
1642
- normals[currentCoordinate] = 0;
1643
- normals[currentCoordinate + 1] = 0;
1644
- normals[currentCoordinate + 2] = 1;
1645
- }
1646
- currentCoordinate += 3;
1647
- if (uvs) {
1648
- uvs[currentCoordinateUV] = u;
1649
- uvs[currentCoordinateUV + 1] = v;
1650
- currentCoordinateUV += 2;
1635
+ return numVertices;
1636
+ function getNormal(p1, p2, result) {
1637
+ result.subVectors(p2, p1);
1638
+ return result.set(-result.y, result.x).normalize();
1639
+ }
1640
+ function addVertex(position, u, v) {
1641
+ if (vertices) {
1642
+ vertices[currentCoordinate] = position.x;
1643
+ vertices[currentCoordinate + 1] = position.y;
1644
+ vertices[currentCoordinate + 2] = 0;
1645
+ if (normals) {
1646
+ normals[currentCoordinate] = 0;
1647
+ normals[currentCoordinate + 1] = 0;
1648
+ normals[currentCoordinate + 2] = 1;
1649
+ }
1650
+ currentCoordinate += 3;
1651
+ if (uvs) {
1652
+ uvs[currentCoordinateUV] = u;
1653
+ uvs[currentCoordinateUV + 1] = v;
1654
+ currentCoordinateUV += 2;
1655
+ }
1656
+ }
1657
+ numVertices += 3;
1658
+ }
1659
+ function makeCircularSector(center, p1, p2, u, v) {
1660
+ tempV2_1.copy(p1).sub(center).normalize();
1661
+ tempV2_2.copy(p2).sub(center).normalize();
1662
+ let angle = Math.PI;
1663
+ const dot = tempV2_1.dot(tempV2_2);
1664
+ if (Math.abs(dot) < 1)
1665
+ angle = Math.abs(Math.acos(dot));
1666
+ angle /= arcDivisions;
1667
+ tempV2_3.copy(p1);
1668
+ for (let i = 0, il = arcDivisions - 1; i < il; i++) {
1669
+ tempV2_4.copy(tempV2_3).rotateAround(center, angle);
1670
+ addVertex(tempV2_3, u, v);
1671
+ addVertex(tempV2_4, u, v);
1672
+ addVertex(center, u, 0.5);
1673
+ tempV2_3.copy(tempV2_4);
1651
1674
  }
1652
- }
1653
- numVertices += 3;
1654
- }
1655
- function makeCircularSector(center, p1, p2, u, v) {
1656
- tempV2_1.copy(p1).sub(center).normalize();
1657
- tempV2_2.copy(p2).sub(center).normalize();
1658
- let angle = Math.PI;
1659
- const dot = tempV2_1.dot(tempV2_2);
1660
- if (Math.abs(dot) < 1)
1661
- angle = Math.abs(Math.acos(dot));
1662
- angle /= arcDivisions;
1663
- tempV2_3.copy(p1);
1664
- for (let i = 0, il = arcDivisions - 1; i < il; i++) {
1665
- tempV2_4.copy(tempV2_3).rotateAround(center, angle);
1666
- addVertex(tempV2_3, u, v);
1667
1675
  addVertex(tempV2_4, u, v);
1676
+ addVertex(p2, u, v);
1668
1677
  addVertex(center, u, 0.5);
1669
- tempV2_3.copy(tempV2_4);
1670
1678
  }
1671
- addVertex(tempV2_4, u, v);
1672
- addVertex(p2, u, v);
1673
- addVertex(center, u, 0.5);
1674
- }
1675
- function makeSegmentTriangles() {
1676
- addVertex(lastPointR, u0, 1);
1677
- addVertex(lastPointL, u0, 0);
1678
- addVertex(currentPointL, u1, 0);
1679
- addVertex(lastPointR, u0, 1);
1680
- addVertex(currentPointL, u1, 0);
1681
- addVertex(currentPointR, u1, 1);
1682
- }
1683
- function makeSegmentWithBevelJoin(joinIsOnLeftSide2, innerSideModified2, u) {
1684
- if (innerSideModified2) {
1685
- if (joinIsOnLeftSide2) {
1686
- addVertex(lastPointR, u0, 1);
1687
- addVertex(lastPointL, u0, 0);
1688
- addVertex(currentPointL, u1, 0);
1689
- addVertex(lastPointR, u0, 1);
1690
- addVertex(currentPointL, u1, 0);
1691
- addVertex(innerPoint, u1, 1);
1692
- addVertex(currentPointL, u, 0);
1693
- addVertex(nextPointL, u, 0);
1694
- addVertex(innerPoint, u, 0.5);
1695
- } else {
1696
- addVertex(lastPointR, u0, 1);
1697
- addVertex(lastPointL, u0, 0);
1698
- addVertex(currentPointR, u1, 1);
1699
- addVertex(lastPointL, u0, 0);
1700
- addVertex(innerPoint, u1, 0);
1701
- addVertex(currentPointR, u1, 1);
1702
- addVertex(currentPointR, u, 1);
1703
- addVertex(innerPoint, u, 0);
1704
- addVertex(nextPointR, u, 1);
1705
- }
1706
- } else {
1707
- if (joinIsOnLeftSide2) {
1708
- addVertex(currentPointL, u, 0);
1709
- addVertex(nextPointL, u, 0);
1710
- addVertex(currentPoint, u, 0.5);
1711
- } else {
1712
- addVertex(currentPointR, u, 1);
1713
- addVertex(nextPointR, u, 0);
1714
- addVertex(currentPoint, u, 0.5);
1715
- }
1716
- }
1717
- }
1718
- function createSegmentTrianglesWithMiddleSection(joinIsOnLeftSide2, innerSideModified2) {
1719
- if (innerSideModified2) {
1720
- if (joinIsOnLeftSide2) {
1721
- addVertex(lastPointR, u0, 1);
1722
- addVertex(lastPointL, u0, 0);
1723
- addVertex(currentPointL, u1, 0);
1724
- addVertex(lastPointR, u0, 1);
1725
- addVertex(currentPointL, u1, 0);
1726
- addVertex(innerPoint, u1, 1);
1727
- addVertex(currentPointL, u0, 0);
1728
- addVertex(currentPoint, u1, 0.5);
1729
- addVertex(innerPoint, u1, 1);
1730
- addVertex(currentPoint, u1, 0.5);
1731
- addVertex(nextPointL, u0, 0);
1732
- addVertex(innerPoint, u1, 1);
1679
+ function makeSegmentTriangles() {
1680
+ addVertex(lastPointR, u0, 1);
1681
+ addVertex(lastPointL, u0, 0);
1682
+ addVertex(currentPointL, u1, 0);
1683
+ addVertex(lastPointR, u0, 1);
1684
+ addVertex(currentPointL, u1, 0);
1685
+ addVertex(currentPointR, u1, 1);
1686
+ }
1687
+ function makeSegmentWithBevelJoin(joinIsOnLeftSide2, innerSideModified2, u) {
1688
+ if (innerSideModified2) {
1689
+ if (joinIsOnLeftSide2) {
1690
+ addVertex(lastPointR, u0, 1);
1691
+ addVertex(lastPointL, u0, 0);
1692
+ addVertex(currentPointL, u1, 0);
1693
+ addVertex(lastPointR, u0, 1);
1694
+ addVertex(currentPointL, u1, 0);
1695
+ addVertex(innerPoint, u1, 1);
1696
+ addVertex(currentPointL, u, 0);
1697
+ addVertex(nextPointL, u, 0);
1698
+ addVertex(innerPoint, u, 0.5);
1699
+ } else {
1700
+ addVertex(lastPointR, u0, 1);
1701
+ addVertex(lastPointL, u0, 0);
1702
+ addVertex(currentPointR, u1, 1);
1703
+ addVertex(lastPointL, u0, 0);
1704
+ addVertex(innerPoint, u1, 0);
1705
+ addVertex(currentPointR, u1, 1);
1706
+ addVertex(currentPointR, u, 1);
1707
+ addVertex(innerPoint, u, 0);
1708
+ addVertex(nextPointR, u, 1);
1709
+ }
1733
1710
  } else {
1734
- addVertex(lastPointR, u0, 1);
1735
- addVertex(lastPointL, u0, 0);
1736
- addVertex(currentPointR, u1, 1);
1737
- addVertex(lastPointL, u0, 0);
1738
- addVertex(innerPoint, u1, 0);
1739
- addVertex(currentPointR, u1, 1);
1740
- addVertex(currentPointR, u0, 1);
1741
- addVertex(innerPoint, u1, 0);
1742
- addVertex(currentPoint, u1, 0.5);
1743
- addVertex(currentPoint, u1, 0.5);
1744
- addVertex(innerPoint, u1, 0);
1745
- addVertex(nextPointR, u0, 1);
1711
+ if (joinIsOnLeftSide2) {
1712
+ addVertex(currentPointL, u, 0);
1713
+ addVertex(nextPointL, u, 0);
1714
+ addVertex(currentPoint, u, 0.5);
1715
+ } else {
1716
+ addVertex(currentPointR, u, 1);
1717
+ addVertex(nextPointR, u, 0);
1718
+ addVertex(currentPoint, u, 0.5);
1719
+ }
1746
1720
  }
1747
1721
  }
1748
- }
1749
- function addCapGeometry(center, p1, p2, joinIsOnLeftSide2, start, u) {
1750
- switch (style.strokeLineCap) {
1751
- case "round":
1752
- if (start) {
1753
- makeCircularSector(center, p2, p1, u, 0.5);
1722
+ function createSegmentTrianglesWithMiddleSection(joinIsOnLeftSide2, innerSideModified2) {
1723
+ if (innerSideModified2) {
1724
+ if (joinIsOnLeftSide2) {
1725
+ addVertex(lastPointR, u0, 1);
1726
+ addVertex(lastPointL, u0, 0);
1727
+ addVertex(currentPointL, u1, 0);
1728
+ addVertex(lastPointR, u0, 1);
1729
+ addVertex(currentPointL, u1, 0);
1730
+ addVertex(innerPoint, u1, 1);
1731
+ addVertex(currentPointL, u0, 0);
1732
+ addVertex(currentPoint, u1, 0.5);
1733
+ addVertex(innerPoint, u1, 1);
1734
+ addVertex(currentPoint, u1, 0.5);
1735
+ addVertex(nextPointL, u0, 0);
1736
+ addVertex(innerPoint, u1, 1);
1754
1737
  } else {
1755
- makeCircularSector(center, p1, p2, u, 0.5);
1738
+ addVertex(lastPointR, u0, 1);
1739
+ addVertex(lastPointL, u0, 0);
1740
+ addVertex(currentPointR, u1, 1);
1741
+ addVertex(lastPointL, u0, 0);
1742
+ addVertex(innerPoint, u1, 0);
1743
+ addVertex(currentPointR, u1, 1);
1744
+ addVertex(currentPointR, u0, 1);
1745
+ addVertex(innerPoint, u1, 0);
1746
+ addVertex(currentPoint, u1, 0.5);
1747
+ addVertex(currentPoint, u1, 0.5);
1748
+ addVertex(innerPoint, u1, 0);
1749
+ addVertex(nextPointR, u0, 1);
1756
1750
  }
1757
- break;
1758
- case "square":
1759
- if (start) {
1760
- tempV2_1.subVectors(p1, center);
1761
- tempV2_2.set(tempV2_1.y, -tempV2_1.x);
1762
- tempV2_3.addVectors(tempV2_1, tempV2_2).add(center);
1763
- tempV2_4.subVectors(tempV2_2, tempV2_1).add(center);
1764
- if (joinIsOnLeftSide2) {
1765
- tempV2_3.toArray(vertices, 1 * 3);
1766
- tempV2_4.toArray(vertices, 0 * 3);
1767
- tempV2_4.toArray(vertices, 3 * 3);
1751
+ }
1752
+ }
1753
+ function addCapGeometry(center, p1, p2, joinIsOnLeftSide2, start, u) {
1754
+ switch (style.strokeLineCap) {
1755
+ case "round":
1756
+ if (start) {
1757
+ makeCircularSector(center, p2, p1, u, 0.5);
1768
1758
  } else {
1769
- tempV2_3.toArray(vertices, 1 * 3);
1770
- uvs[3 * 2 + 1] === 1 ? tempV2_4.toArray(vertices, 3 * 3) : tempV2_3.toArray(vertices, 3 * 3);
1771
- tempV2_4.toArray(vertices, 0 * 3);
1759
+ makeCircularSector(center, p1, p2, u, 0.5);
1772
1760
  }
1773
- } else {
1774
- tempV2_1.subVectors(p2, center);
1775
- tempV2_2.set(tempV2_1.y, -tempV2_1.x);
1776
- tempV2_3.addVectors(tempV2_1, tempV2_2).add(center);
1777
- tempV2_4.subVectors(tempV2_2, tempV2_1).add(center);
1778
- const vl = vertices.length;
1779
- if (joinIsOnLeftSide2) {
1780
- tempV2_3.toArray(vertices, vl - 1 * 3);
1781
- tempV2_4.toArray(vertices, vl - 2 * 3);
1782
- tempV2_4.toArray(vertices, vl - 4 * 3);
1761
+ break;
1762
+ case "square":
1763
+ if (start) {
1764
+ tempV2_1.subVectors(p1, center);
1765
+ tempV2_2.set(tempV2_1.y, -tempV2_1.x);
1766
+ tempV2_3.addVectors(tempV2_1, tempV2_2).add(center);
1767
+ tempV2_4.subVectors(tempV2_2, tempV2_1).add(center);
1768
+ if (joinIsOnLeftSide2) {
1769
+ tempV2_3.toArray(vertices, 1 * 3);
1770
+ tempV2_4.toArray(vertices, 0 * 3);
1771
+ tempV2_4.toArray(vertices, 3 * 3);
1772
+ } else {
1773
+ tempV2_3.toArray(vertices, 1 * 3);
1774
+ uvs[3 * 2 + 1] === 1 ? tempV2_4.toArray(vertices, 3 * 3) : tempV2_3.toArray(vertices, 3 * 3);
1775
+ tempV2_4.toArray(vertices, 0 * 3);
1776
+ }
1783
1777
  } else {
1784
- tempV2_4.toArray(vertices, vl - 2 * 3);
1785
- tempV2_3.toArray(vertices, vl - 1 * 3);
1786
- tempV2_4.toArray(vertices, vl - 4 * 3);
1778
+ tempV2_1.subVectors(p2, center);
1779
+ tempV2_2.set(tempV2_1.y, -tempV2_1.x);
1780
+ tempV2_3.addVectors(tempV2_1, tempV2_2).add(center);
1781
+ tempV2_4.subVectors(tempV2_2, tempV2_1).add(center);
1782
+ const vl = vertices.length;
1783
+ if (joinIsOnLeftSide2) {
1784
+ tempV2_3.toArray(vertices, vl - 1 * 3);
1785
+ tempV2_4.toArray(vertices, vl - 2 * 3);
1786
+ tempV2_4.toArray(vertices, vl - 4 * 3);
1787
+ } else {
1788
+ tempV2_4.toArray(vertices, vl - 2 * 3);
1789
+ tempV2_3.toArray(vertices, vl - 1 * 3);
1790
+ tempV2_4.toArray(vertices, vl - 4 * 3);
1791
+ }
1787
1792
  }
1788
- }
1789
- break;
1790
- }
1791
- }
1792
- function removeDuplicatedPoints(points2) {
1793
- let dupPoints = false;
1794
- for (let i = 1, n = points2.length - 1; i < n; i++) {
1795
- if (points2[i].distanceTo(points2[i + 1]) < minDistance) {
1796
- dupPoints = true;
1797
- break;
1793
+ break;
1798
1794
  }
1799
1795
  }
1800
- if (!dupPoints)
1801
- return points2;
1802
- const newPoints = [];
1803
- newPoints.push(points2[0]);
1804
- for (let i = 1, n = points2.length - 1; i < n; i++) {
1805
- if (points2[i].distanceTo(points2[i + 1]) >= minDistance) {
1806
- newPoints.push(points2[i]);
1796
+ function removeDuplicatedPoints(points2) {
1797
+ let dupPoints = false;
1798
+ for (let i = 1, n = points2.length - 1; i < n; i++) {
1799
+ if (points2[i].distanceTo(points2[i + 1]) < minDistance) {
1800
+ dupPoints = true;
1801
+ break;
1802
+ }
1803
+ }
1804
+ if (!dupPoints)
1805
+ return points2;
1806
+ const newPoints = [];
1807
+ newPoints.push(points2[0]);
1808
+ for (let i = 1, n = points2.length - 1; i < n; i++) {
1809
+ if (points2[i].distanceTo(points2[i + 1]) >= minDistance) {
1810
+ newPoints.push(points2[i]);
1811
+ }
1807
1812
  }
1813
+ newPoints.push(points2[points2.length - 1]);
1814
+ return newPoints;
1808
1815
  }
1809
- newPoints.push(points2[points2.length - 1]);
1810
- return newPoints;
1811
1816
  }
1812
1817
  }
1813
- }
1818
+ return SVGLoader2;
1819
+ })();
1814
1820
  export {
1815
1821
  SVGLoader
1816
1822
  };