react-native-nano-icons 0.2.1 → 1.0.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (325) hide show
  1. package/LICENSES.md +40 -0
  2. package/README.md +41 -10
  3. package/android/src/main/java/com/nanoicons/NanoIconFonts.kt +31 -0
  4. package/android/src/main/java/com/nanoicons/NanoIconView.kt +50 -15
  5. package/android/src/main/java/com/nanoicons/NanoIconsFontLoaderModule.kt +72 -11
  6. package/ios/NanoIconFontResolver.h +5 -0
  7. package/ios/NanoIconFontResolver.mm +32 -0
  8. package/ios/NanoIconView.h +0 -4
  9. package/ios/NanoIconView.mm +62 -57
  10. package/ios/NanoIconsFontLoader.mm +10 -32
  11. package/lib/commonjs/cli/build.d.ts +11 -3
  12. package/lib/commonjs/cli/build.js +86 -25
  13. package/lib/commonjs/cli/config.d.ts +1 -1
  14. package/lib/commonjs/cli/config.js +1 -1
  15. package/lib/commonjs/cli/expoConfig.d.ts +3 -2
  16. package/lib/commonjs/cli/expoConfig.js +22 -9
  17. package/lib/commonjs/cli/index.d.ts +5 -5
  18. package/lib/commonjs/cli/index.js +16 -14
  19. package/lib/commonjs/cli/link.d.ts +4 -3
  20. package/lib/commonjs/cli/link.js +127 -45
  21. package/lib/commonjs/cli/logger.js +9 -7
  22. package/lib/commonjs/plugin/src/buildFonts.d.ts +3 -3
  23. package/lib/commonjs/plugin/src/buildFonts.js +5 -15
  24. package/lib/commonjs/plugin/src/index.d.ts +2 -2
  25. package/lib/commonjs/plugin/src/index.js +2 -2
  26. package/lib/commonjs/plugin/src/types.d.ts +10 -1
  27. package/lib/commonjs/plugin/src/withNanoIconsFontLinking.d.ts +1 -1
  28. package/lib/commonjs/plugin/src/withNanoIconsFontLinking.js +6 -13
  29. package/lib/commonjs/scripts/cli.js +46 -23
  30. package/lib/commonjs/src/core/flatten/arcs.d.ts +2 -0
  31. package/lib/commonjs/src/core/flatten/arcs.js +136 -0
  32. package/lib/commonjs/src/core/flatten/document.d.ts +35 -0
  33. package/lib/commonjs/src/core/flatten/document.js +164 -0
  34. package/lib/commonjs/src/core/flatten/dom.d.ts +24 -0
  35. package/lib/commonjs/src/core/flatten/dom.js +221 -0
  36. package/lib/commonjs/src/core/flatten/element.d.ts +12 -0
  37. package/lib/commonjs/src/core/flatten/element.js +97 -0
  38. package/lib/commonjs/src/core/flatten/geometry.d.ts +21 -0
  39. package/lib/commonjs/src/core/flatten/geometry.js +85 -0
  40. package/lib/commonjs/src/core/flatten/index.d.ts +2 -0
  41. package/lib/commonjs/src/core/flatten/index.js +11 -0
  42. package/lib/commonjs/src/core/flatten/inherit.d.ts +13 -0
  43. package/lib/commonjs/src/core/flatten/inherit.js +249 -0
  44. package/lib/commonjs/src/core/flatten/path.d.ts +19 -0
  45. package/lib/commonjs/src/core/flatten/path.js +439 -0
  46. package/lib/commonjs/src/core/flatten/pathops.d.ts +14 -0
  47. package/lib/commonjs/src/core/flatten/pathops.js +236 -0
  48. package/lib/commonjs/src/core/flatten/shape.d.ts +29 -0
  49. package/lib/commonjs/src/core/flatten/shape.js +415 -0
  50. package/lib/commonjs/src/core/flatten/stages/clip-path.d.ts +4 -0
  51. package/lib/commonjs/src/core/flatten/stages/clip-path.js +20 -0
  52. package/lib/commonjs/src/core/flatten/stages/collapse.d.ts +2 -0
  53. package/lib/commonjs/src/core/flatten/stages/collapse.js +86 -0
  54. package/lib/commonjs/src/core/flatten/stages/defs.d.ts +4 -0
  55. package/lib/commonjs/src/core/flatten/stages/defs.js +49 -0
  56. package/lib/commonjs/src/core/flatten/stages/discard.d.ts +4 -0
  57. package/lib/commonjs/src/core/flatten/stages/discard.js +50 -0
  58. package/lib/commonjs/src/core/flatten/stages/fill-rule.d.ts +2 -0
  59. package/lib/commonjs/src/core/flatten/stages/fill-rule.js +7 -0
  60. package/lib/commonjs/src/core/flatten/stages/nested-svg.d.ts +2 -0
  61. package/lib/commonjs/src/core/flatten/stages/nested-svg.js +131 -0
  62. package/lib/commonjs/src/core/flatten/stages/opacity.d.ts +2 -0
  63. package/lib/commonjs/src/core/flatten/stages/opacity.js +7 -0
  64. package/lib/commonjs/src/core/flatten/stages/shapes.d.ts +7 -0
  65. package/lib/commonjs/src/core/flatten/stages/shapes.js +37 -0
  66. package/lib/commonjs/src/core/flatten/stages/stroke.d.ts +3 -0
  67. package/lib/commonjs/src/core/flatten/stages/stroke.js +34 -0
  68. package/lib/commonjs/src/core/flatten/stages/styles.d.ts +2 -0
  69. package/lib/commonjs/src/core/flatten/stages/styles.js +29 -0
  70. package/lib/commonjs/src/core/flatten/stages/use.d.ts +4 -0
  71. package/lib/commonjs/src/core/flatten/stages/use.js +80 -0
  72. package/lib/commonjs/src/core/flatten/stages/validate.d.ts +2 -0
  73. package/lib/commonjs/src/core/flatten/stages/validate.js +39 -0
  74. package/lib/commonjs/src/core/flatten/stages.d.ts +2 -0
  75. package/lib/commonjs/src/core/flatten/stages.js +40 -0
  76. package/lib/commonjs/src/core/flatten/transform.d.ts +35 -0
  77. package/lib/commonjs/src/core/flatten/transform.js +221 -0
  78. package/lib/commonjs/src/core/font/compile.d.ts +2 -1
  79. package/lib/commonjs/src/core/font/compile.js +21 -7
  80. package/lib/commonjs/src/core/font/metrics.js +7 -0
  81. package/lib/commonjs/src/core/font/quadratic.d.ts +1 -0
  82. package/lib/commonjs/src/core/font/quadratic.js +31 -0
  83. package/lib/commonjs/src/core/glyph/merge.d.ts +7 -0
  84. package/lib/commonjs/src/core/glyph/merge.js +57 -0
  85. package/lib/commonjs/src/core/glyph/parse.d.ts +26 -0
  86. package/lib/commonjs/src/core/{svg/svg_dom.js → glyph/parse.js} +21 -77
  87. package/lib/commonjs/src/core/{svg/layers.d.ts → glyph/placement.d.ts} +1 -13
  88. package/lib/commonjs/src/core/{svg/layers.js → glyph/placement.js} +0 -17
  89. package/lib/commonjs/src/core/glyph/validate.d.ts +8 -0
  90. package/lib/commonjs/src/core/glyph/validate.js +33 -0
  91. package/lib/commonjs/src/core/pathkit/contours.d.ts +74 -0
  92. package/lib/commonjs/src/core/{svg/svg_pathops.js → pathkit/contours.js} +72 -312
  93. package/lib/commonjs/src/core/pathkit/evenodd.d.ts +12 -0
  94. package/lib/commonjs/src/core/pathkit/evenodd.js +51 -0
  95. package/lib/commonjs/src/core/pathkit/load.d.ts +2 -0
  96. package/lib/commonjs/src/core/pathkit/load.js +26 -0
  97. package/lib/commonjs/src/core/pathkit/types.d.ts +69 -0
  98. package/lib/commonjs/src/core/pathkit/types.js +2 -0
  99. package/lib/commonjs/src/core/pipeline/config.d.ts +1 -0
  100. package/lib/commonjs/src/core/pipeline/iconPool.d.ts +3 -0
  101. package/lib/commonjs/src/core/pipeline/iconPool.js +51 -0
  102. package/lib/commonjs/src/core/pipeline/index.d.ts +3 -3
  103. package/lib/commonjs/src/core/pipeline/index.js +6 -5
  104. package/lib/commonjs/src/core/pipeline/prepare.d.ts +19 -0
  105. package/lib/commonjs/src/core/pipeline/prepare.js +56 -0
  106. package/lib/commonjs/src/core/pipeline/prepareIcon.d.ts +22 -0
  107. package/lib/commonjs/src/core/pipeline/prepareIcon.js +78 -0
  108. package/lib/commonjs/src/core/pipeline/prepareWorker.d.ts +1 -0
  109. package/lib/commonjs/src/core/pipeline/prepareWorker.js +12 -0
  110. package/lib/commonjs/src/core/pipeline/{run.d.ts → runFontPipeline.d.ts} +7 -4
  111. package/lib/commonjs/src/core/pipeline/runFontPipeline.js +109 -0
  112. package/lib/commonjs/src/core/types.d.ts +3 -92
  113. package/lib/commonjs/src/utils/fingerPrint.d.ts +8 -1
  114. package/lib/commonjs/src/utils/fingerPrint.js +8 -1
  115. package/lib/commonjs/src/utils/fontIdentity.d.ts +4 -0
  116. package/lib/commonjs/src/utils/fontIdentity.js +24 -0
  117. package/lib/commonjs/src/utils/packageVersion.d.ts +2 -0
  118. package/lib/commonjs/src/utils/packageVersion.js +37 -0
  119. package/lib/commonjs/src/utils/parse.d.ts +0 -1
  120. package/lib/commonjs/src/utils/parse.js +0 -8
  121. package/lib/commonjs/src/utils/svgPatterns.d.ts +38 -0
  122. package/lib/commonjs/src/utils/svgPatterns.js +46 -0
  123. package/lib/module/const/codegenPrimitives.js +1 -2
  124. package/lib/module/const/colors.js +1 -2
  125. package/lib/module/createNanoIconsSet.js +1 -2
  126. package/lib/module/createNanoIconsSet.native.js +11 -4
  127. package/lib/module/createNanoIconsSet.shared.js +12 -7
  128. package/lib/module/createNanoIconsSet.web.js +7 -5
  129. package/lib/module/fontIntegrity.js +99 -0
  130. package/lib/module/index.js +1 -1
  131. package/lib/module/index.node.js +1 -2
  132. package/lib/module/loadDynamicFont.js +14 -7
  133. package/lib/module/nativeFontLoader.js +3 -0
  134. package/lib/module/nativeFontLoader.web.js +3 -0
  135. package/lib/module/specs/NativeNanoIconsFontLoader.js +1 -2
  136. package/lib/module/types.js +1 -2
  137. package/lib/module/utils/fingerPrint.js +3 -3
  138. package/lib/module/utils/fontIdentity.js +20 -0
  139. package/lib/module/utils/glyphRuntime.js +1 -2
  140. package/lib/module/utils/packageVersion.js +29 -0
  141. package/lib/module/utils/parse.js +1 -9
  142. package/lib/module/utils/runtimeLog.js +12 -0
  143. package/lib/module/utils/shallowEqualColor.js +1 -2
  144. package/lib/module/utils/svgPatterns.js +49 -0
  145. package/lib/typescript/src/core/flatten/arcs.d.ts +3 -0
  146. package/lib/typescript/src/core/flatten/document.d.ts +36 -0
  147. package/lib/typescript/src/core/flatten/dom.d.ts +25 -0
  148. package/lib/typescript/src/core/flatten/element.d.ts +13 -0
  149. package/lib/typescript/src/core/flatten/geometry.d.ts +22 -0
  150. package/lib/typescript/src/core/flatten/index.d.ts +3 -0
  151. package/lib/typescript/src/core/flatten/inherit.d.ts +14 -0
  152. package/lib/typescript/src/core/flatten/path.d.ts +20 -0
  153. package/lib/typescript/src/core/flatten/pathops.d.ts +15 -0
  154. package/lib/typescript/src/core/flatten/shape.d.ts +30 -0
  155. package/lib/typescript/src/core/flatten/stages/clip-path.d.ts +5 -0
  156. package/lib/typescript/src/core/flatten/stages/collapse.d.ts +3 -0
  157. package/lib/typescript/src/core/flatten/stages/defs.d.ts +5 -0
  158. package/lib/typescript/src/core/flatten/stages/discard.d.ts +5 -0
  159. package/lib/typescript/src/core/flatten/stages/fill-rule.d.ts +3 -0
  160. package/lib/typescript/src/core/flatten/stages/nested-svg.d.ts +3 -0
  161. package/lib/typescript/src/core/flatten/stages/opacity.d.ts +3 -0
  162. package/lib/typescript/src/core/flatten/stages/shapes.d.ts +8 -0
  163. package/lib/typescript/src/core/flatten/stages/stroke.d.ts +4 -0
  164. package/lib/typescript/src/core/flatten/stages/styles.d.ts +3 -0
  165. package/lib/typescript/src/core/flatten/stages/use.d.ts +5 -0
  166. package/lib/typescript/src/core/flatten/stages/validate.d.ts +3 -0
  167. package/lib/typescript/src/core/flatten/stages.d.ts +3 -0
  168. package/lib/typescript/src/core/flatten/transform.d.ts +36 -0
  169. package/lib/typescript/src/core/glyph/merge.d.ts +8 -0
  170. package/lib/typescript/src/core/glyph/parse.d.ts +27 -0
  171. package/lib/typescript/src/core/{svg/layers.d.ts → glyph/placement.d.ts} +2 -14
  172. package/lib/typescript/src/core/glyph/validate.d.ts +9 -0
  173. package/lib/typescript/src/core/pathkit/contours.d.ts +75 -0
  174. package/lib/typescript/src/core/pathkit/evenodd.d.ts +13 -0
  175. package/lib/typescript/src/core/pathkit/load.d.ts +3 -0
  176. package/lib/typescript/src/core/pathkit/types.d.ts +70 -0
  177. package/lib/typescript/src/core/types.d.ts +3 -92
  178. package/lib/typescript/src/fontIntegrity.d.ts +24 -0
  179. package/lib/typescript/src/index.d.ts +1 -0
  180. package/lib/typescript/src/nativeFontLoader.d.ts +2 -0
  181. package/lib/typescript/src/nativeFontLoader.web.d.ts +3 -0
  182. package/lib/typescript/src/specs/NativeNanoIconsFontLoader.d.ts +1 -0
  183. package/lib/typescript/src/types.d.ts +5 -0
  184. package/lib/typescript/src/utils/fingerPrint.d.ts +8 -1
  185. package/lib/typescript/src/utils/fontIdentity.d.ts +5 -0
  186. package/lib/typescript/src/utils/packageVersion.d.ts +3 -0
  187. package/lib/typescript/src/utils/parse.d.ts +0 -1
  188. package/lib/typescript/src/utils/runtimeLog.d.ts +5 -0
  189. package/lib/typescript/src/utils/svgPatterns.d.ts +39 -0
  190. package/package.json +13 -11
  191. package/src/specs/NativeNanoIconsFontLoader.ts +1 -0
  192. package/lib/commonjs/src/core/pipeline/managers.d.ts +0 -11
  193. package/lib/commonjs/src/core/pipeline/managers.js +0 -104
  194. package/lib/commonjs/src/core/pipeline/run.js +0 -189
  195. package/lib/commonjs/src/core/svg/svg_dom.d.ts +0 -51
  196. package/lib/commonjs/src/core/svg/svg_pathops.d.ts +0 -32
  197. package/lib/module/const/codegenPrimitives.js.map +0 -1
  198. package/lib/module/const/colors.js.map +0 -1
  199. package/lib/module/core/font/compile.js +0 -81
  200. package/lib/module/core/font/compile.js.map +0 -1
  201. package/lib/module/core/font/metrics.js +0 -37
  202. package/lib/module/core/font/metrics.js.map +0 -1
  203. package/lib/module/core/pipeline/config.js +0 -20
  204. package/lib/module/core/pipeline/config.js.map +0 -1
  205. package/lib/module/core/pipeline/index.js +0 -5
  206. package/lib/module/core/pipeline/index.js.map +0 -1
  207. package/lib/module/core/pipeline/managers.js +0 -94
  208. package/lib/module/core/pipeline/managers.js.map +0 -1
  209. package/lib/module/core/pipeline/run.js +0 -204
  210. package/lib/module/core/pipeline/run.js.map +0 -1
  211. package/lib/module/core/shims/pathops.py +0 -181
  212. package/lib/module/core/shims/picosvg-0.22.3-py3-none-any.whl +0 -0
  213. package/lib/module/core/svg/layers.js +0 -85
  214. package/lib/module/core/svg/layers.js.map +0 -1
  215. package/lib/module/core/svg/svg_dom.js +0 -170
  216. package/lib/module/core/svg/svg_dom.js.map +0 -1
  217. package/lib/module/core/svg/svg_pathops.js +0 -750
  218. package/lib/module/core/svg/svg_pathops.js.map +0 -1
  219. package/lib/module/core/tsconfig.json +0 -32
  220. package/lib/module/core/types.js +0 -2
  221. package/lib/module/core/types.js.map +0 -1
  222. package/lib/module/createNanoIconsSet.js.map +0 -1
  223. package/lib/module/createNanoIconsSet.native.js.map +0 -1
  224. package/lib/module/createNanoIconsSet.shared.js.map +0 -1
  225. package/lib/module/createNanoIconsSet.web.js.map +0 -1
  226. package/lib/module/index.js.map +0 -1
  227. package/lib/module/index.node.js.map +0 -1
  228. package/lib/module/loadDynamicFont.js.map +0 -1
  229. package/lib/module/specs/NativeNanoIconsFontLoader.js.map +0 -1
  230. package/lib/module/types.js.map +0 -1
  231. package/lib/module/utils/fingerPrint.js.map +0 -1
  232. package/lib/module/utils/glyphRuntime.js.map +0 -1
  233. package/lib/module/utils/parse.js.map +0 -1
  234. package/lib/module/utils/shallowEqualColor.js.map +0 -1
  235. package/lib/typescript/__tests__/build.unit.test.d.ts +0 -3
  236. package/lib/typescript/__tests__/build.unit.test.d.ts.map +0 -1
  237. package/lib/typescript/__tests__/clippath.e2e.test.d.ts +0 -3
  238. package/lib/typescript/__tests__/clippath.e2e.test.d.ts.map +0 -1
  239. package/lib/typescript/__tests__/fingerprint.unit.test.d.ts +0 -3
  240. package/lib/typescript/__tests__/fingerprint.unit.test.d.ts.map +0 -1
  241. package/lib/typescript/__tests__/glyphRuntime.unit.test.d.ts +0 -2
  242. package/lib/typescript/__tests__/glyphRuntime.unit.test.d.ts.map +0 -1
  243. package/lib/typescript/__tests__/link.unit.test.d.ts +0 -3
  244. package/lib/typescript/__tests__/link.unit.test.d.ts.map +0 -1
  245. package/lib/typescript/__tests__/loadDynamicFont.unit.test.d.ts +0 -2
  246. package/lib/typescript/__tests__/loadDynamicFont.unit.test.d.ts.map +0 -1
  247. package/lib/typescript/__tests__/pipeline.e2e.test.d.ts +0 -3
  248. package/lib/typescript/__tests__/pipeline.e2e.test.d.ts.map +0 -1
  249. package/lib/typescript/__tests__/placement.unit.test.d.ts +0 -3
  250. package/lib/typescript/__tests__/placement.unit.test.d.ts.map +0 -1
  251. package/lib/typescript/__tests__/svg_dom.unit.test.d.ts +0 -3
  252. package/lib/typescript/__tests__/svg_dom.unit.test.d.ts.map +0 -1
  253. package/lib/typescript/cli/build.d.ts +0 -32
  254. package/lib/typescript/cli/build.d.ts.map +0 -1
  255. package/lib/typescript/cli/link.d.ts +0 -12
  256. package/lib/typescript/cli/link.d.ts.map +0 -1
  257. package/lib/typescript/cli/logger.d.ts +0 -28
  258. package/lib/typescript/cli/logger.d.ts.map +0 -1
  259. package/lib/typescript/src/const/codegenPrimitives.d.ts.map +0 -1
  260. package/lib/typescript/src/const/colors.d.ts.map +0 -1
  261. package/lib/typescript/src/core/font/compile.d.ts +0 -21
  262. package/lib/typescript/src/core/font/compile.d.ts.map +0 -1
  263. package/lib/typescript/src/core/font/metrics.d.ts +0 -2
  264. package/lib/typescript/src/core/font/metrics.d.ts.map +0 -1
  265. package/lib/typescript/src/core/pipeline/config.d.ts +0 -16
  266. package/lib/typescript/src/core/pipeline/config.d.ts.map +0 -1
  267. package/lib/typescript/src/core/pipeline/index.d.ts +0 -4
  268. package/lib/typescript/src/core/pipeline/index.d.ts.map +0 -1
  269. package/lib/typescript/src/core/pipeline/managers.d.ts +0 -12
  270. package/lib/typescript/src/core/pipeline/managers.d.ts.map +0 -1
  271. package/lib/typescript/src/core/pipeline/run.d.ts +0 -15
  272. package/lib/typescript/src/core/pipeline/run.d.ts.map +0 -1
  273. package/lib/typescript/src/core/svg/layers.d.ts.map +0 -1
  274. package/lib/typescript/src/core/svg/svg_dom.d.ts +0 -52
  275. package/lib/typescript/src/core/svg/svg_dom.d.ts.map +0 -1
  276. package/lib/typescript/src/core/svg/svg_pathops.d.ts +0 -33
  277. package/lib/typescript/src/core/svg/svg_pathops.d.ts.map +0 -1
  278. package/lib/typescript/src/core/types.d.ts.map +0 -1
  279. package/lib/typescript/src/createNanoIconsSet.d.ts.map +0 -1
  280. package/lib/typescript/src/createNanoIconsSet.native.d.ts.map +0 -1
  281. package/lib/typescript/src/createNanoIconsSet.shared.d.ts.map +0 -1
  282. package/lib/typescript/src/createNanoIconsSet.web.d.ts.map +0 -1
  283. package/lib/typescript/src/index.d.ts.map +0 -1
  284. package/lib/typescript/src/index.node.d.ts.map +0 -1
  285. package/lib/typescript/src/loadDynamicFont.d.ts.map +0 -1
  286. package/lib/typescript/src/specs/NanoIconViewNativeComponent.d.ts.map +0 -1
  287. package/lib/typescript/src/specs/NativeNanoIconsFontLoader.d.ts.map +0 -1
  288. package/lib/typescript/src/types.d.ts.map +0 -1
  289. package/lib/typescript/src/utils/fingerPrint.d.ts.map +0 -1
  290. package/lib/typescript/src/utils/glyphRuntime.d.ts.map +0 -1
  291. package/lib/typescript/src/utils/parse.d.ts.map +0 -1
  292. package/lib/typescript/src/utils/shallowEqualColor.d.ts.map +0 -1
  293. package/plugin/src/buildFonts.ts +0 -42
  294. package/plugin/src/index.ts +0 -21
  295. package/plugin/src/types.ts +0 -42
  296. package/plugin/src/withNanoIconsFontLinking.ts +0 -136
  297. package/plugin/tsconfig.json +0 -9
  298. package/scripts/cli.ts +0 -63
  299. package/scripts/tsconfig.json +0 -25
  300. package/src/const/colors.ts +0 -150
  301. package/src/core/font/compile.ts +0 -99
  302. package/src/core/font/metrics.ts +0 -44
  303. package/src/core/pipeline/config.ts +0 -25
  304. package/src/core/pipeline/index.ts +0 -3
  305. package/src/core/pipeline/managers.ts +0 -132
  306. package/src/core/pipeline/run.ts +0 -274
  307. package/src/core/shims/pathops.py +0 -181
  308. package/src/core/shims/picosvg-0.22.3-py3-none-any.whl +0 -0
  309. package/src/core/svg/layers.ts +0 -110
  310. package/src/core/svg/svg_dom.ts +0 -194
  311. package/src/core/svg/svg_pathops.ts +0 -1040
  312. package/src/core/tsconfig.json +0 -32
  313. package/src/core/types.ts +0 -157
  314. package/src/createNanoIconsSet.native.tsx +0 -192
  315. package/src/createNanoIconsSet.shared.tsx +0 -174
  316. package/src/createNanoIconsSet.tsx +0 -20
  317. package/src/createNanoIconsSet.web.tsx +0 -109
  318. package/src/index.node.ts +0 -14
  319. package/src/index.ts +0 -6
  320. package/src/loadDynamicFont.ts +0 -162
  321. package/src/types.ts +0 -31
  322. package/src/utils/fingerPrint.ts +0 -20
  323. package/src/utils/glyphRuntime.ts +0 -46
  324. package/src/utils/parse.ts +0 -67
  325. package/src/utils/shallowEqualColor.ts +0 -17
@@ -0,0 +1,14 @@
1
+ import type { PathKitModule } from '../pathkit/types';
2
+ import type { SvgCommand } from './path';
3
+ import type { Affine2D } from './transform';
4
+ export declare class PathOpsError extends Error {
5
+ }
6
+ export declare function createPathOps(PathKit: PathKitModule): {
7
+ union(cmdSeqs: readonly SvgCommand[][], fillRules: readonly string[]): SvgCommand[];
8
+ intersection(cmdSeqs: readonly SvgCommand[][], fillRules: readonly string[]): SvgCommand[];
9
+ removeOverlaps(cmds: Iterable<SvgCommand>, fillRule: string): SvgCommand[];
10
+ transformCmds(cmds: Iterable<SvgCommand>, affine: Affine2D): SvgCommand[];
11
+ strokeCmds(cmds: Iterable<SvgCommand>, svgLinecap: string, svgLinejoin: string, strokeWidth: number, strokeMiterlimit: number, _tolerance: number, dashArray?: readonly number[], dashOffset?: number): SvgCommand[];
12
+ pathArea(cmds: Iterable<SvgCommand>, fillRule: string): number;
13
+ };
14
+ export type PathOps = ReturnType<typeof createPathOps>;
@@ -0,0 +1,236 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PathOpsError = void 0;
4
+ exports.createPathOps = createPathOps;
5
+ const contours_1 = require("../pathkit/contours");
6
+ class PathOpsError extends Error {
7
+ }
8
+ exports.PathOpsError = PathOpsError;
9
+ function createPathOps(PathKit) {
10
+ const V = (0, contours_1.verbMap)(PathKit);
11
+ const FILL = (0, contours_1.fillTypes)(PathKit);
12
+ const Caps = PathKit.StrokeCap ?? {};
13
+ const Joins = PathKit.StrokeJoin ?? {};
14
+ const Ops = PathKit.PathOp ?? {};
15
+ const LINE_CAP = {
16
+ butt: Caps.BUTT ?? 0,
17
+ round: Caps.ROUND ?? 1,
18
+ square: Caps.SQUARE ?? 2,
19
+ };
20
+ const LINE_JOIN = {
21
+ miter: Joins.MITER ?? 0,
22
+ round: Joins.ROUND ?? 1,
23
+ bevel: Joins.BEVEL ?? 2,
24
+ };
25
+ const OP_UNION = Ops.UNION ?? 0;
26
+ const OP_INTERSECT = Ops.INTERSECT ?? 1;
27
+ function fillTypeFor(fillRule) {
28
+ if (fillRule === 'nonzero')
29
+ return FILL.WINDING;
30
+ if (fillRule === 'evenodd')
31
+ return FILL.EVENODD;
32
+ throw new Error(`Invalid fill rule: ${fillRule}`);
33
+ }
34
+ function dispose(h) {
35
+ h.p.delete?.();
36
+ }
37
+ function fromCommands(cmds, fillRule) {
38
+ const p = PathKit.NewPath();
39
+ p.setFillType(fillTypeFor(fillRule));
40
+ const moves = [];
41
+ for (const [cmd, args] of cmds) {
42
+ switch (cmd) {
43
+ case 'M':
44
+ p.moveTo(args[0], args[1]);
45
+ moves.push((0, contours_1.normPt)([args[0], args[1]]));
46
+ break;
47
+ case 'L':
48
+ p.lineTo(args[0], args[1]);
49
+ break;
50
+ case 'Q':
51
+ p.quadTo(args[0], args[1], args[2], args[3]);
52
+ break;
53
+ case 'C':
54
+ p.cubicTo(args[0], args[1], args[2], args[3], args[4], args[5]);
55
+ break;
56
+ case 'Z':
57
+ p.close();
58
+ break;
59
+ default:
60
+ p.delete?.();
61
+ throw new Error(`No mapping to Skia for "${cmd} ${args}"`);
62
+ }
63
+ }
64
+ return { p, moves };
65
+ }
66
+ function normalizedCmds(h) {
67
+ const p2 = PathKit.FromSVGString(h.p.toSVGString());
68
+ const cmds = p2 ? p2.toCmds() : [];
69
+ p2?.delete?.();
70
+ return cmds;
71
+ }
72
+ function simplifyToWinding(h) {
73
+ try {
74
+ h.p.simplify();
75
+ const p2 = PathKit.FromSVGString(h.p.toSVGString());
76
+ if (p2) {
77
+ h.p.delete?.();
78
+ h.p = p2;
79
+ }
80
+ }
81
+ catch { }
82
+ h.p.setFillType(FILL.WINDING);
83
+ }
84
+ function toCommands(h) {
85
+ const cmds = (0, contours_1.canonicalContourCmds)(normalizedCmds(h), h.moves, h.moves.length === 0, V);
86
+ const out = [];
87
+ for (const cmd of cmds) {
88
+ const v = cmd[0];
89
+ if (v === V.MOVE)
90
+ out.push(['M', [cmd[1], cmd[2]]]);
91
+ else if (v === V.LINE)
92
+ out.push(['L', [cmd[1], cmd[2]]]);
93
+ else if (v === V.QUAD)
94
+ out.push(['Q', [cmd[1], cmd[2], cmd[3], cmd[4]]]);
95
+ else if (v === V.CUBIC)
96
+ out.push(['C', [cmd[1], cmd[2], cmd[3], cmd[4], cmd[5], cmd[6]]]);
97
+ else if (v === V.CLOSE)
98
+ out.push(['Z', []]);
99
+ else
100
+ throw new Error(`Unexpected verb in cmds: ${v}`);
101
+ }
102
+ return out;
103
+ }
104
+ function combine(a, b, op) {
105
+ try {
106
+ const out = PathKit.MakeFromOp(a.p, b.p, op);
107
+ if (!out)
108
+ return null;
109
+ return { p: out, moves: (0, contours_1.mergeMoves)(a.moves, b.moves) };
110
+ }
111
+ catch {
112
+ return null;
113
+ }
114
+ }
115
+ function doPathop(op, cmdSeqs, fillRules) {
116
+ if (!cmdSeqs.length) {
117
+ return [];
118
+ }
119
+ let skPath = fromCommands(cmdSeqs[0], fillRules[0]);
120
+ try {
121
+ for (let i = 1; i < cmdSeqs.length; i++) {
122
+ const skPath2 = fromCommands(cmdSeqs[i], fillRules[i]);
123
+ const merged = combine(skPath, skPath2, op);
124
+ dispose(skPath2);
125
+ if (merged === null) {
126
+ throw new PathOpsError('operation did not succeed');
127
+ }
128
+ // the result keeps its own fill rule until simplify resolves it below:
129
+ // relabelling it nonzero here would leave hole contours wound as if
130
+ // they still subtract, and simplify would then discard them
131
+ dispose(skPath);
132
+ skPath = merged;
133
+ }
134
+ simplifyToWinding(skPath);
135
+ return toCommands(skPath);
136
+ }
137
+ finally {
138
+ dispose(skPath);
139
+ }
140
+ }
141
+ return {
142
+ union(cmdSeqs, fillRules) {
143
+ return doPathop(OP_UNION, cmdSeqs, fillRules);
144
+ },
145
+ intersection(cmdSeqs, fillRules) {
146
+ return doPathop(OP_INTERSECT, cmdSeqs, fillRules);
147
+ },
148
+ // simplified path filled using the "nonzero" winding rule
149
+ removeOverlaps(cmds, fillRule) {
150
+ const h = fromCommands(cmds, fillRule);
151
+ try {
152
+ simplifyToWinding(h);
153
+ return toCommands(h);
154
+ }
155
+ finally {
156
+ dispose(h);
157
+ }
158
+ },
159
+ transformCmds(cmds, affine) {
160
+ const h = fromCommands(cmds, 'nonzero');
161
+ const { a, b, c, d, e, f } = affine;
162
+ const p = PathKit.NewPath(h.p);
163
+ p.transform(a, c, e, b, d, f, 0, 0, 1);
164
+ const transformed = {
165
+ p,
166
+ moves: h.moves.map(([x, y]) => (0, contours_1.normPt)([a * x + c * y + e, b * x + d * y + f])),
167
+ };
168
+ try {
169
+ return toCommands(transformed);
170
+ }
171
+ finally {
172
+ dispose(h);
173
+ dispose(transformed);
174
+ }
175
+ },
176
+ // a path that is a shape with its stroke applied; fill with nonzero
177
+ strokeCmds(cmds, svgLinecap, svgLinejoin, strokeWidth, strokeMiterlimit, _tolerance, dashArray = [], dashOffset = 0.0) {
178
+ const cap = LINE_CAP[svgLinecap];
179
+ if (cap === undefined) {
180
+ throw new Error(`Unsupported cap ${svgLinecap}`);
181
+ }
182
+ const join = LINE_JOIN[svgLinejoin];
183
+ if (join === undefined) {
184
+ throw new Error(`Unsupported join ${svgLinejoin}`);
185
+ }
186
+ // the input path's fill_rule doesn't affect the stroked result
187
+ const h = fromCommands(cmds, 'nonzero');
188
+ const work = PathKit.NewPath(h.p);
189
+ let strokedPath;
190
+ try {
191
+ if (dashArray.length === 2 && typeof work.dash === 'function') {
192
+ work.dash(Number(dashArray[0]), Number(dashArray[1]), dashOffset || 0);
193
+ }
194
+ let stroked = work.stroke({
195
+ width: strokeWidth,
196
+ cap,
197
+ join,
198
+ miter_limit: strokeMiterlimit,
199
+ });
200
+ if (!stroked || typeof stroked.toCmds !== 'function')
201
+ stroked = work;
202
+ if (stroked !== work)
203
+ work.delete?.();
204
+ strokedPath = stroked;
205
+ }
206
+ catch {
207
+ strokedPath = work;
208
+ }
209
+ const result = { p: strokedPath, moves: [] };
210
+ try {
211
+ simplifyToWinding(result);
212
+ return toCommands(result);
213
+ }
214
+ finally {
215
+ dispose(h);
216
+ dispose(result);
217
+ }
218
+ },
219
+ // the path's absolute area
220
+ pathArea(cmds, fillRule) {
221
+ const h = fromCommands(cmds, fillRule);
222
+ try {
223
+ simplifyToWinding(h);
224
+ try {
225
+ return (0, contours_1.contoursArea)(normalizedCmds(h), V);
226
+ }
227
+ catch {
228
+ return 0.0;
229
+ }
230
+ }
231
+ finally {
232
+ dispose(h);
233
+ }
234
+ },
235
+ };
236
+ }
@@ -0,0 +1,29 @@
1
+ import { XEl } from './dom';
2
+ import type { PathOps } from './pathops';
3
+ import type { SvgCommand } from './path';
4
+ import { Affine2D } from './transform';
5
+ export declare function isShapeTag(tag: string): boolean;
6
+ export type Shape = {
7
+ tag: string;
8
+ fields: Record<string, string | number>;
9
+ };
10
+ export declare function shapeStr(shape: Shape, name: string): string;
11
+ export declare function cloneShape(shape: Shape): Shape;
12
+ export declare function shapesEqual(a: Shape, b: Shape): boolean;
13
+ export declare function fromElement(el: XEl, inheritedAttrib?: Record<string, string>): Shape;
14
+ export declare function toElement(shape: Shape, inheritedAttrib?: Record<string, string>): XEl;
15
+ export declare function resetFields(shape: Shape, pred: (fieldName: string) => boolean): void;
16
+ export declare function pathFromCommands(cmds: Iterable<SvgCommand>): Shape;
17
+ export declare function asPath(shape: Shape): Shape;
18
+ export declare function shapeCmdSeq(shape: Shape): SvgCommand[];
19
+ export declare function absoluteShape(shape: Shape): Shape;
20
+ export declare function explicitLinesExpandShorthand(shape: Shape): Shape;
21
+ export declare function applyTransform(shape: Shape, transform: Affine2D, ops: PathOps): Shape;
22
+ export declare function removeOverlaps(shape: Shape, ops: PathOps): Shape;
23
+ export declare function strokeCommands(shape: Shape, tolerance: number, ops: PathOps): SvgCommand[];
24
+ export declare function parseCssDeclarations(style: string, output: Record<string, string>, propertyNames?: ReadonlySet<string>): string;
25
+ export declare function applyStyleAttribute(shape: Shape): Shape;
26
+ export declare function mightPaint(shape: Shape, ops: PathOps): boolean;
27
+ export declare function normalizeOpacity(shape: Shape): void;
28
+ export declare function roundShapeFloats(shape: Shape, ndigits: number): void;
29
+ export declare function removeEmptySubpaths(shape: Shape, ops: PathOps): void;
@@ -0,0 +1,415 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isShapeTag = isShapeTag;
4
+ exports.shapeStr = shapeStr;
5
+ exports.cloneShape = cloneShape;
6
+ exports.shapesEqual = shapesEqual;
7
+ exports.fromElement = fromElement;
8
+ exports.toElement = toElement;
9
+ exports.resetFields = resetFields;
10
+ exports.pathFromCommands = pathFromCommands;
11
+ exports.asPath = asPath;
12
+ exports.shapeCmdSeq = shapeCmdSeq;
13
+ exports.absoluteShape = absoluteShape;
14
+ exports.explicitLinesExpandShorthand = explicitLinesExpandShorthand;
15
+ exports.applyTransform = applyTransform;
16
+ exports.removeOverlaps = removeOverlaps;
17
+ exports.strokeCommands = strokeCommands;
18
+ exports.parseCssDeclarations = parseCssDeclarations;
19
+ exports.applyStyleAttribute = applyStyleAttribute;
20
+ exports.mightPaint = mightPaint;
21
+ exports.normalizeOpacity = normalizeOpacity;
22
+ exports.roundShapeFloats = roundShapeFloats;
23
+ exports.removeEmptySubpaths = removeEmptySubpaths;
24
+ const geometry_1 = require("./geometry");
25
+ const dom_1 = require("./dom");
26
+ const inherit_1 = require("./inherit");
27
+ const path_1 = require("./path");
28
+ const svgPatterns_1 = require("../../utils/svgPatterns");
29
+ const f = (name, type, dflt) => ({ name, type, default: dflt });
30
+ // dataclass field order of SVGShape - drives to_element attribute order
31
+ const COMMON_FIELDS = [
32
+ f('id', 'str', ''),
33
+ f('clip_path', 'str', (0, inherit_1.attribDefault)('clip-path')),
34
+ f('clip_rule', 'str', (0, inherit_1.attribDefault)('clip-rule')),
35
+ f('fill', 'str', (0, inherit_1.attribDefault)('fill')),
36
+ f('fill_opacity', 'float', (0, inherit_1.attribDefault)('fill-opacity')),
37
+ f('fill_rule', 'str', (0, inherit_1.attribDefault)('fill-rule')),
38
+ f('stroke', 'str', (0, inherit_1.attribDefault)('stroke')),
39
+ f('stroke_width', 'float', (0, inherit_1.attribDefault)('stroke-width')),
40
+ f('stroke_linecap', 'str', (0, inherit_1.attribDefault)('stroke-linecap')),
41
+ f('stroke_linejoin', 'str', (0, inherit_1.attribDefault)('stroke-linejoin')),
42
+ f('stroke_miterlimit', 'float', (0, inherit_1.attribDefault)('stroke-miterlimit')),
43
+ f('stroke_dasharray', 'str', (0, inherit_1.attribDefault)('stroke-dasharray')),
44
+ f('stroke_dashoffset', 'float', (0, inherit_1.attribDefault)('stroke-dashoffset')),
45
+ f('stroke_opacity', 'float', (0, inherit_1.attribDefault)('stroke-opacity')),
46
+ f('opacity', 'float', (0, inherit_1.attribDefault)('opacity')),
47
+ f('transform', 'str', (0, inherit_1.attribDefault)('transform')),
48
+ f('style', 'str', (0, inherit_1.attribDefault)('style')),
49
+ f('display', 'str', (0, inherit_1.attribDefault)('display')),
50
+ ];
51
+ const TAG_FIELDS = {
52
+ path: [f('d', 'str', '')],
53
+ circle: [f('r', 'float', 0), f('cx', 'float', 0), f('cy', 'float', 0)],
54
+ ellipse: [
55
+ f('rx', 'float', 0),
56
+ f('ry', 'float', 0),
57
+ f('cx', 'float', 0),
58
+ f('cy', 'float', 0),
59
+ ],
60
+ line: [
61
+ f('x1', 'float', 0),
62
+ f('y1', 'float', 0),
63
+ f('x2', 'float', 0),
64
+ f('y2', 'float', 0),
65
+ ],
66
+ polygon: [f('points', 'str', '')],
67
+ polyline: [f('points', 'str', '')],
68
+ rect: [
69
+ f('x', 'float', 0),
70
+ f('y', 'float', 0),
71
+ f('width', 'float', 0),
72
+ f('height', 'float', 0),
73
+ f('rx', 'float', 0),
74
+ f('ry', 'float', 0),
75
+ ],
76
+ };
77
+ const SHAPE_TAGS = new Set(Object.keys(TAG_FIELDS));
78
+ function isShapeTag(tag) {
79
+ return SHAPE_TAGS.has((0, dom_1.stripNs)(tag));
80
+ }
81
+ function shapeFields(tag) {
82
+ const extra = TAG_FIELDS[tag];
83
+ if (!extra)
84
+ throw new Error(`Bad tag <${tag}>`);
85
+ return [...COMMON_FIELDS, ...extra];
86
+ }
87
+ function newShape(tag) {
88
+ const fields = {};
89
+ for (const field of shapeFields(tag)) {
90
+ fields[field.name] = field.default;
91
+ }
92
+ return { tag, fields };
93
+ }
94
+ function shapeStr(shape, name) {
95
+ return shape.fields[name];
96
+ }
97
+ function shapeNum(shape, name) {
98
+ return shape.fields[name];
99
+ }
100
+ function cloneShape(shape) {
101
+ return { tag: shape.tag, fields: { ...shape.fields } };
102
+ }
103
+ function shapesEqual(a, b) {
104
+ if (a.tag !== b.tag)
105
+ return false;
106
+ for (const field of shapeFields(a.tag)) {
107
+ if (a.fields[field.name] !== b.fields[field.name])
108
+ return false;
109
+ }
110
+ return true;
111
+ }
112
+ function parseFloatStrict(raw, tag, attr) {
113
+ const value = Number(raw.trim());
114
+ if (Number.isNaN(value)) {
115
+ throw new Error(`${attr}="${raw}" on <${tag}> is not a number (units other than px are not supported)`);
116
+ }
117
+ return value;
118
+ }
119
+ function fromElement(el, inheritedAttrib = {}) {
120
+ if (!isShapeTag(el.tag)) {
121
+ throw new Error(`Bad tag <${el.tag}>`);
122
+ }
123
+ const tag = (0, dom_1.stripNs)(el.tag);
124
+ const attrs = { ...inheritedAttrib };
125
+ for (const [name, value] of el.attrib) {
126
+ attrs[name] = value;
127
+ }
128
+ const shape = newShape(tag);
129
+ for (const field of shapeFields(tag)) {
130
+ const raw = attrs[(0, inherit_1.attrName)(field.name)];
131
+ if (raw === undefined || !raw.trim())
132
+ continue;
133
+ shape.fields[field.name] =
134
+ field.type === 'float'
135
+ ? parseFloatStrict(raw, tag, (0, inherit_1.attrName)(field.name))
136
+ : raw;
137
+ }
138
+ if (tag === 'rect') {
139
+ rectPostInit(shape);
140
+ }
141
+ return shape;
142
+ }
143
+ // SVGRect.__post_init__
144
+ function rectPostInit(shape) {
145
+ if (!shapeNum(shape, 'rx'))
146
+ shape.fields.rx = shapeNum(shape, 'ry');
147
+ if (!shapeNum(shape, 'ry'))
148
+ shape.fields.ry = shapeNum(shape, 'rx');
149
+ shape.fields.rx = Math.min(shapeNum(shape, 'rx'), shapeNum(shape, 'width') / 2);
150
+ shape.fields.ry = Math.min(shapeNum(shape, 'ry'), shapeNum(shape, 'height') / 2);
151
+ }
152
+ function toElement(shape, inheritedAttrib = {}) {
153
+ const el = new dom_1.XEl((0, dom_1.svgTag)(shape.tag));
154
+ for (const field of shapeFields(shape.tag)) {
155
+ const attr = (0, inherit_1.attrName)(field.name);
156
+ const fieldValue = shape.fields[field.name];
157
+ // omit attributes whose value == the respective default,
158
+ // unless it's != from the attribute value inherited from context
159
+ const attribValue = typeof fieldValue === 'number' ? (0, geometry_1.ntos)(fieldValue) : fieldValue;
160
+ if (attr in inheritedAttrib) {
161
+ if (attribValue === inheritedAttrib[attr])
162
+ continue;
163
+ }
164
+ else if (fieldValue === field.default) {
165
+ continue;
166
+ }
167
+ el.attrib.set(attr, attribValue);
168
+ }
169
+ return el;
170
+ }
171
+ function resetFields(shape, pred) {
172
+ for (const field of shapeFields(shape.tag)) {
173
+ if (pred(field.name)) {
174
+ shape.fields[field.name] = field.default;
175
+ }
176
+ }
177
+ }
178
+ // ---- geometry ----
179
+ function copyCommonFields(target, source) {
180
+ for (const field of COMMON_FIELDS) {
181
+ target.fields[field.name] = source.fields[field.name];
182
+ }
183
+ }
184
+ function pathFromD(d) {
185
+ const path = newShape('path');
186
+ path.fields.d = d;
187
+ return path;
188
+ }
189
+ function pathFromCommands(cmds) {
190
+ return pathFromD((0, path_1.buildD)(cmds));
191
+ }
192
+ function asPath(shape) {
193
+ if (shape.tag === 'path') {
194
+ return shape;
195
+ }
196
+ const fields = shape.fields;
197
+ let d = '';
198
+ const add = (cmd, ...args) => {
199
+ d = (0, path_1.addCmdToD)(d, cmd, args);
200
+ };
201
+ const addArc = (rx, ry, x, y, large = 0) => {
202
+ const snippet = (0, path_1.pathSegment)('A', rx, ry, 0, large, 1, x, y);
203
+ d = d ? `${d} ${snippet}` : snippet;
204
+ };
205
+ switch (shape.tag) {
206
+ case 'circle':
207
+ case 'ellipse': {
208
+ const rx = (shape.tag === 'circle' ? fields.r : fields.rx);
209
+ const ry = (shape.tag === 'circle' ? fields.r : fields.ry);
210
+ const cx = fields.cx;
211
+ const cy = fields.cy;
212
+ // arc doesn't seem to like being a complete shape, draw two halves
213
+ add('M', cx + rx, cy);
214
+ addArc(rx, ry, cx - rx, cy, 1);
215
+ addArc(rx, ry, cx + rx, cy, 1);
216
+ d = `${d} Z`;
217
+ break;
218
+ }
219
+ case 'line': {
220
+ add('M', fields.x1, fields.y1);
221
+ add('L', fields.x2, fields.y2);
222
+ break;
223
+ }
224
+ case 'polygon': {
225
+ d = fields.points ? `M${fields.points} Z` : '';
226
+ break;
227
+ }
228
+ case 'polyline': {
229
+ d = fields.points ? `M${fields.points}` : '';
230
+ break;
231
+ }
232
+ case 'rect': {
233
+ const x = fields.x;
234
+ const y = fields.y;
235
+ const w = fields.width;
236
+ const h = fields.height;
237
+ const rx = fields.rx;
238
+ const ry = fields.ry;
239
+ add('M', x + rx, y);
240
+ add('H', x + w - rx);
241
+ if (rx > 0)
242
+ addArc(rx, ry, x + w, y + ry);
243
+ add('V', y + h - ry);
244
+ if (rx > 0)
245
+ addArc(rx, ry, x + w - rx, y + h);
246
+ add('H', x + rx);
247
+ if (rx > 0)
248
+ addArc(rx, ry, x, y + h - ry);
249
+ add('V', y + ry);
250
+ if (rx > 0)
251
+ addArc(rx, ry, x + rx, y);
252
+ d = `${d} Z`;
253
+ break;
254
+ }
255
+ default:
256
+ throw new Error(`as_path not implemented for <${shape.tag}>`);
257
+ }
258
+ const path = pathFromD(d);
259
+ copyCommonFields(path, shape);
260
+ return path;
261
+ }
262
+ // hHvV -> lL, S/T -> C/Q, relative -> absolute, arcs -> cubics
263
+ function shapeCmdSeq(shape) {
264
+ return (0, path_1.asCmdSeq)(shapeStr(asPath(shape), 'd'));
265
+ }
266
+ function absoluteShape(shape) {
267
+ // only meaningful for path
268
+ if (shape.tag !== 'path')
269
+ return shape;
270
+ const target = cloneShape(shape);
271
+ target.fields.d = (0, path_1.absolutePath)(shapeStr(target, 'd'));
272
+ return target;
273
+ }
274
+ function explicitLinesExpandShorthand(shape) {
275
+ if (shape.tag !== 'path')
276
+ return shape;
277
+ const target = cloneShape(shape);
278
+ target.fields.d = (0, path_1.expandShorthand)((0, path_1.explicitLines)(shapeStr(target, 'd')));
279
+ return target;
280
+ }
281
+ function applyTransform(shape, transform, ops) {
282
+ let target = asPath(shape);
283
+ if (target === shape) {
284
+ target = cloneShape(target);
285
+ }
286
+ let cmds = [['M', [0, 0]]];
287
+ if (!transform.isDegenerate()) {
288
+ cmds = ops.transformCmds(shapeCmdSeq(shape), transform);
289
+ }
290
+ target.fields.d = (0, path_1.buildD)(cmds);
291
+ return target;
292
+ }
293
+ function removeOverlaps(shape, ops) {
294
+ const cmds = ops.removeOverlaps(shapeCmdSeq(shape), shapeStr(shape, 'fill_rule'));
295
+ const target = cloneShape(asPath(shape));
296
+ // simplified paths follow the 'nonzero' winding rule
297
+ target.fields.fill_rule = 'nonzero';
298
+ target.fields.clip_rule = 'nonzero';
299
+ target.fields.d = (0, path_1.buildD)(cmds);
300
+ return target;
301
+ }
302
+ function strokeCommands(shape, tolerance, ops) {
303
+ let dashArray = [];
304
+ const dasharray = shapeStr(shape, 'stroke_dasharray');
305
+ if (dasharray !== 'none') {
306
+ dashArray = dasharray
307
+ .split(svgPatterns_1.DASHARRAY_SEPARATOR)
308
+ .filter((v) => v)
309
+ .map((v) => parseFloatStrict(v, shape.tag, 'stroke-dasharray'));
310
+ }
311
+ // odd number of dash values is repeated to yield an even count
312
+ if (dashArray.length % 2 !== 0) {
313
+ dashArray = [...dashArray, ...dashArray];
314
+ }
315
+ return ops.strokeCmds(shapeCmdSeq(shape), shapeStr(shape, 'stroke_linecap'), shapeStr(shape, 'stroke_linejoin'), shapeNum(shape, 'stroke_width'), shapeNum(shape, 'stroke_miterlimit'), tolerance, dashArray, shapeNum(shape, 'stroke_dashoffset'));
316
+ }
317
+ // CSS in "style" attribute -> equivalent SVG attributes on the shape
318
+ function parseCssDeclarations(style, output, propertyNames) {
319
+ const unparsed = [];
320
+ for (let declaration of style.split(';')) {
321
+ declaration = declaration.trim();
322
+ const colonCount = (declaration.match(/:/g) ?? []).length;
323
+ if (colonCount === 1) {
324
+ const [rawName, rawValue] = declaration.split(':');
325
+ const propertyName = rawName.trim();
326
+ const value = rawValue.trim();
327
+ if (propertyNames === undefined || propertyNames.has(propertyName)) {
328
+ output[propertyName] = value;
329
+ }
330
+ else {
331
+ unparsed.push(declaration);
332
+ }
333
+ }
334
+ else if (declaration) {
335
+ throw new Error(`Invalid CSS declaration syntax: ${declaration}`);
336
+ }
337
+ }
338
+ return unparsed.length ? unparsed.join('; ') + ';' : '';
339
+ }
340
+ function applyStyleAttribute(shape) {
341
+ const target = cloneShape(shape);
342
+ const style = shapeStr(target, 'style');
343
+ if (style) {
344
+ const fields = shapeFields(target.tag);
345
+ const attrTypes = new Map(fields.map((fd) => [(0, inherit_1.attrName)(fd.name), fd]));
346
+ const rawAttrs = {};
347
+ const unparsedStyle = parseCssDeclarations(style, rawAttrs, new Set(attrTypes.keys()));
348
+ for (const [attr, rawValue] of Object.entries(rawAttrs)) {
349
+ const field = attrTypes.get(attr);
350
+ target.fields[field.name] =
351
+ field.type === 'float'
352
+ ? parseFloatStrict(rawValue, target.tag, attr)
353
+ : rawValue;
354
+ }
355
+ target.fields.style = unparsedStyle;
356
+ }
357
+ return target;
358
+ }
359
+ // False if we're sure this shape will not paint. True if it *might* paint.
360
+ function mightPaint(shape, ops) {
361
+ const styled = applyStyleAttribute(shape);
362
+ if (shapeStr(styled, 'display') === 'none')
363
+ return false;
364
+ const visible = (fill, opacity) => fill !== 'none' && shapeNum(styled, 'opacity') * opacity !== 0;
365
+ // if all you do is move the pen around you can't draw
366
+ const cmds = shapeCmdSeq(shape);
367
+ if (cmds.every(([c]) => c.toUpperCase() === 'M'))
368
+ return false;
369
+ // Does it look like the stroke is visible?
370
+ if (visible(shapeStr(styled, 'stroke'), shapeNum(styled, 'stroke_opacity')) &&
371
+ shapeNum(styled, 'stroke_width') !== 0) {
372
+ return true;
373
+ }
374
+ // No stroke; if the shape is hidden we can't draw
375
+ if (!visible(shapeStr(styled, 'fill'), shapeNum(styled, 'fill_opacity'))) {
376
+ return false;
377
+ }
378
+ // Only shapes with area paint
379
+ return ops.pathArea(shapeCmdSeq(styled), shapeStr(styled, 'fill_rule')) > 0;
380
+ }
381
+ // Merge '{fill,stroke}_opacity' with generic 'opacity' when possible
382
+ function normalizeOpacity(shape) {
383
+ if (shapeStr(shape, 'fill') === 'none' &&
384
+ shapeStr(shape, 'stroke') === 'none') {
385
+ return;
386
+ }
387
+ for (const [fillAttr, opacityAttr] of [
388
+ ['fill', 'stroke_opacity'],
389
+ ['stroke', 'fill_opacity'],
390
+ ]) {
391
+ if (shapeStr(shape, fillAttr) === 'none') {
392
+ shape.fields.opacity =
393
+ shapeNum(shape, 'opacity') * shapeNum(shape, opacityAttr);
394
+ shape.fields[opacityAttr] = 1.0;
395
+ }
396
+ }
397
+ }
398
+ function roundShapeFloats(shape, ndigits) {
399
+ for (const field of shapeFields(shape.tag)) {
400
+ const value = shape.fields[field.name];
401
+ if (field.type === 'float' && typeof value === 'number') {
402
+ shape.fields[field.name] = (0, geometry_1.pythonRound)(value, ndigits);
403
+ }
404
+ }
405
+ if (shape.tag === 'path') {
406
+ shape.fields.d = (0, path_1.roundFloatsD)(shapeStr(shape, 'd'), ndigits);
407
+ }
408
+ }
409
+ function removeEmptySubpaths(shape, ops) {
410
+ if (shape.tag !== 'path')
411
+ return;
412
+ shape.fields.d = (0, path_1.subpaths)(shapeStr(shape, 'd'))
413
+ .filter((sub) => mightPaint(pathFromD(sub), ops))
414
+ .join(' ');
415
+ }