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

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 (404) hide show
  1. package/LICENSES.md +40 -0
  2. package/README.md +165 -12
  3. package/android/build.gradle +8 -1
  4. package/android/src/main/java/com/nanoicons/NanoIconFonts.kt +31 -0
  5. package/android/src/main/java/com/nanoicons/NanoIconView.kt +103 -19
  6. package/android/src/main/java/com/nanoicons/NanoIconViewManager.kt +42 -18
  7. package/android/src/main/java/com/nanoicons/NanoIconsFontLoaderModule.kt +72 -11
  8. package/android/src/main/jni/CMakeLists.txt +38 -0
  9. package/android/src/main/jni/RNNanoIconsSpec.h +19 -0
  10. package/common/cpp/react/renderer/components/RNNanoIconsSpec/NanoIconViewComponentDescriptor.h +11 -0
  11. package/common/cpp/react/renderer/components/RNNanoIconsSpec/NanoIconViewShadowNode.cpp +46 -0
  12. package/common/cpp/react/renderer/components/RNNanoIconsSpec/NanoIconViewShadowNode.h +41 -0
  13. package/ios/NanoIconFontResolver.h +5 -0
  14. package/ios/NanoIconFontResolver.mm +32 -0
  15. package/ios/NanoIconInlineBaseline.h +4 -0
  16. package/ios/NanoIconInlineBaseline.mm +190 -0
  17. package/ios/NanoIconView.h +1 -4
  18. package/ios/NanoIconView.mm +178 -162
  19. package/ios/NanoIconsFontLoader.mm +10 -32
  20. package/lib/commonjs/cli/build.d.ts +16 -3
  21. package/lib/commonjs/cli/build.js +108 -25
  22. package/lib/commonjs/cli/buildSymbols.d.ts +26 -0
  23. package/lib/commonjs/cli/buildSymbols.js +134 -0
  24. package/lib/commonjs/cli/config.d.ts +4 -2
  25. package/lib/commonjs/cli/config.js +4 -4
  26. package/lib/commonjs/cli/expoConfig.d.ts +6 -2
  27. package/lib/commonjs/cli/expoConfig.js +37 -13
  28. package/lib/commonjs/cli/index.d.ts +7 -5
  29. package/lib/commonjs/cli/index.js +27 -14
  30. package/lib/commonjs/cli/link.d.ts +19 -3
  31. package/lib/commonjs/cli/link.js +311 -45
  32. package/lib/commonjs/cli/logger.js +9 -7
  33. package/lib/commonjs/metro/fontRebuildWatcher.d.ts +62 -0
  34. package/lib/commonjs/metro/fontRebuildWatcher.js +174 -0
  35. package/lib/commonjs/metro/index.d.ts +35 -0
  36. package/lib/commonjs/metro/index.js +92 -0
  37. package/lib/commonjs/metro/symbolRebuildWatcher.d.ts +19 -0
  38. package/lib/commonjs/metro/symbolRebuildWatcher.js +76 -0
  39. package/lib/commonjs/plugin/src/buildFonts.d.ts +3 -3
  40. package/lib/commonjs/plugin/src/buildFonts.js +5 -15
  41. package/lib/commonjs/plugin/src/buildSymbols.d.ts +3 -0
  42. package/lib/commonjs/plugin/src/buildSymbols.js +18 -0
  43. package/lib/commonjs/plugin/src/index.d.ts +2 -2
  44. package/lib/commonjs/plugin/src/index.js +10 -4
  45. package/lib/commonjs/plugin/src/types.d.ts +44 -3
  46. package/lib/commonjs/plugin/src/withNanoIconsDrawableLinking.d.ts +8 -0
  47. package/lib/commonjs/plugin/src/withNanoIconsDrawableLinking.js +29 -0
  48. package/lib/commonjs/plugin/src/withNanoIconsFontLinking.d.ts +1 -1
  49. package/lib/commonjs/plugin/src/withNanoIconsFontLinking.js +6 -13
  50. package/lib/commonjs/plugin/src/withNanoIconsSymbolLinking.d.ts +8 -0
  51. package/lib/commonjs/plugin/src/withNanoIconsSymbolLinking.js +37 -0
  52. package/lib/commonjs/scripts/cli.js +64 -23
  53. package/lib/commonjs/src/core/flatten/arcs.d.ts +2 -0
  54. package/lib/commonjs/src/core/flatten/arcs.js +136 -0
  55. package/lib/commonjs/src/core/flatten/document.d.ts +35 -0
  56. package/lib/commonjs/src/core/flatten/document.js +164 -0
  57. package/lib/commonjs/src/core/flatten/dom.d.ts +24 -0
  58. package/lib/commonjs/src/core/flatten/dom.js +221 -0
  59. package/lib/commonjs/src/core/flatten/element.d.ts +12 -0
  60. package/lib/commonjs/src/core/flatten/element.js +97 -0
  61. package/lib/commonjs/src/core/flatten/geometry.d.ts +21 -0
  62. package/lib/commonjs/src/core/flatten/geometry.js +85 -0
  63. package/lib/commonjs/src/core/flatten/index.d.ts +2 -0
  64. package/lib/commonjs/src/core/flatten/index.js +11 -0
  65. package/lib/commonjs/src/core/flatten/inherit.d.ts +13 -0
  66. package/lib/commonjs/src/core/flatten/inherit.js +249 -0
  67. package/lib/commonjs/src/core/flatten/path.d.ts +19 -0
  68. package/lib/commonjs/src/core/flatten/path.js +439 -0
  69. package/lib/commonjs/src/core/flatten/pathops.d.ts +14 -0
  70. package/lib/commonjs/src/core/flatten/pathops.js +236 -0
  71. package/lib/commonjs/src/core/flatten/shape.d.ts +29 -0
  72. package/lib/commonjs/src/core/flatten/shape.js +415 -0
  73. package/lib/commonjs/src/core/flatten/stages/clip-path.d.ts +4 -0
  74. package/lib/commonjs/src/core/flatten/stages/clip-path.js +20 -0
  75. package/lib/commonjs/src/core/flatten/stages/collapse.d.ts +2 -0
  76. package/lib/commonjs/src/core/flatten/stages/collapse.js +86 -0
  77. package/lib/commonjs/src/core/flatten/stages/defs.d.ts +4 -0
  78. package/lib/commonjs/src/core/flatten/stages/defs.js +49 -0
  79. package/lib/commonjs/src/core/flatten/stages/discard.d.ts +4 -0
  80. package/lib/commonjs/src/core/flatten/stages/discard.js +50 -0
  81. package/lib/commonjs/src/core/flatten/stages/fill-rule.d.ts +2 -0
  82. package/lib/commonjs/src/core/flatten/stages/fill-rule.js +7 -0
  83. package/lib/commonjs/src/core/flatten/stages/nested-svg.d.ts +2 -0
  84. package/lib/commonjs/src/core/flatten/stages/nested-svg.js +131 -0
  85. package/lib/commonjs/src/core/flatten/stages/opacity.d.ts +2 -0
  86. package/lib/commonjs/src/core/flatten/stages/opacity.js +7 -0
  87. package/lib/commonjs/src/core/flatten/stages/shapes.d.ts +7 -0
  88. package/lib/commonjs/src/core/flatten/stages/shapes.js +37 -0
  89. package/lib/commonjs/src/core/flatten/stages/stroke.d.ts +3 -0
  90. package/lib/commonjs/src/core/flatten/stages/stroke.js +34 -0
  91. package/lib/commonjs/src/core/flatten/stages/styles.d.ts +2 -0
  92. package/lib/commonjs/src/core/flatten/stages/styles.js +29 -0
  93. package/lib/commonjs/src/core/flatten/stages/use.d.ts +4 -0
  94. package/lib/commonjs/src/core/flatten/stages/use.js +80 -0
  95. package/lib/commonjs/src/core/flatten/stages/validate.d.ts +2 -0
  96. package/lib/commonjs/src/core/flatten/stages/validate.js +39 -0
  97. package/lib/commonjs/src/core/flatten/stages.d.ts +2 -0
  98. package/lib/commonjs/src/core/flatten/stages.js +40 -0
  99. package/lib/commonjs/src/core/flatten/transform.d.ts +35 -0
  100. package/lib/commonjs/src/core/flatten/transform.js +221 -0
  101. package/lib/commonjs/src/core/font/compile.d.ts +2 -1
  102. package/lib/commonjs/src/core/font/compile.js +19 -7
  103. package/lib/commonjs/src/core/font/metrics.js +7 -0
  104. package/lib/commonjs/src/core/font/quadratic.d.ts +2 -0
  105. package/lib/commonjs/src/core/font/quadratic.js +33 -0
  106. package/lib/commonjs/src/core/glyph/merge.d.ts +7 -0
  107. package/lib/commonjs/src/core/glyph/merge.js +59 -0
  108. package/lib/commonjs/src/core/glyph/parse.d.ts +27 -0
  109. package/lib/commonjs/src/core/{svg/svg_dom.js → glyph/parse.js} +21 -77
  110. package/lib/commonjs/src/core/{svg/layers.d.ts → glyph/placement.d.ts} +1 -13
  111. package/lib/commonjs/src/core/{svg/layers.js → glyph/placement.js} +0 -17
  112. package/lib/commonjs/src/core/glyph/validate.d.ts +8 -0
  113. package/lib/commonjs/src/core/glyph/validate.js +33 -0
  114. package/lib/commonjs/src/core/pathkit/contours.d.ts +75 -0
  115. package/lib/commonjs/src/core/{svg/svg_pathops.js → pathkit/contours.js} +79 -301
  116. package/lib/commonjs/src/core/pathkit/evenodd.d.ts +12 -0
  117. package/lib/commonjs/src/core/pathkit/evenodd.js +37 -0
  118. package/lib/commonjs/src/core/pathkit/load.d.ts +2 -0
  119. package/lib/commonjs/src/core/pathkit/load.js +26 -0
  120. package/lib/commonjs/src/core/pathkit/types.d.ts +69 -0
  121. package/lib/commonjs/src/core/pathkit/types.js +2 -0
  122. package/lib/commonjs/src/core/pathkit/winding.d.ts +4 -0
  123. package/lib/commonjs/src/core/pathkit/winding.js +59 -0
  124. package/lib/commonjs/src/core/pipeline/config.d.ts +2 -0
  125. package/lib/commonjs/src/core/pipeline/config.js +6 -0
  126. package/lib/commonjs/src/core/pipeline/iconPool.d.ts +14 -0
  127. package/lib/commonjs/src/core/pipeline/iconPool.js +109 -0
  128. package/lib/commonjs/src/core/pipeline/index.d.ts +5 -3
  129. package/lib/commonjs/src/core/pipeline/index.js +8 -5
  130. package/lib/commonjs/src/core/pipeline/prepare.d.ts +20 -0
  131. package/lib/commonjs/src/core/pipeline/prepare.js +74 -0
  132. package/lib/commonjs/src/core/pipeline/prepareIcon.d.ts +25 -0
  133. package/lib/commonjs/src/core/pipeline/prepareIcon.js +81 -0
  134. package/lib/commonjs/src/core/pipeline/prepareSvg.d.ts +6 -0
  135. package/lib/commonjs/src/core/pipeline/prepareSvg.js +11 -0
  136. package/lib/commonjs/src/core/pipeline/prepareSymbol.d.ts +26 -0
  137. package/lib/commonjs/src/core/pipeline/prepareSymbol.js +79 -0
  138. package/lib/commonjs/src/core/pipeline/prepareWorker.d.ts +1 -0
  139. package/lib/commonjs/src/core/pipeline/prepareWorker.js +12 -0
  140. package/lib/commonjs/src/core/pipeline/preparedSvgCache.d.ts +6 -0
  141. package/lib/commonjs/src/core/pipeline/preparedSvgCache.js +44 -0
  142. package/lib/commonjs/src/core/pipeline/runFontPipeline.d.ts +22 -0
  143. package/lib/commonjs/src/core/pipeline/runFontPipeline.js +111 -0
  144. package/lib/commonjs/src/core/pipeline/runSymbolPipeline.d.ts +54 -0
  145. package/lib/commonjs/src/core/pipeline/runSymbolPipeline.js +161 -0
  146. package/lib/commonjs/src/core/symbols/contents.d.ts +2 -0
  147. package/lib/commonjs/src/core/symbols/contents.js +15 -0
  148. package/lib/commonjs/src/core/symbols/knockout.d.ts +3 -0
  149. package/lib/commonjs/src/core/symbols/knockout.js +51 -0
  150. package/lib/commonjs/src/core/symbols/layers.d.ts +36 -0
  151. package/lib/commonjs/src/core/symbols/layers.js +182 -0
  152. package/lib/commonjs/src/core/symbols/template.d.ts +22 -0
  153. package/lib/commonjs/src/core/symbols/template.js +140 -0
  154. package/lib/commonjs/src/core/symbols/vectorDrawable.d.ts +11 -0
  155. package/lib/commonjs/src/core/symbols/vectorDrawable.js +66 -0
  156. package/lib/commonjs/src/core/types.d.ts +3 -92
  157. package/lib/commonjs/src/utils/fingerPrint.d.ts +19 -1
  158. package/lib/commonjs/src/utils/fingerPrint.js +29 -3
  159. package/lib/commonjs/src/utils/fontIdentity.d.ts +4 -0
  160. package/lib/commonjs/src/utils/fontIdentity.js +24 -0
  161. package/lib/commonjs/src/utils/naming.d.ts +10 -0
  162. package/lib/commonjs/src/utils/naming.js +49 -0
  163. package/lib/commonjs/src/utils/packageVersion.d.ts +2 -0
  164. package/lib/commonjs/src/utils/packageVersion.js +37 -0
  165. package/lib/commonjs/src/utils/parse.d.ts +0 -1
  166. package/lib/commonjs/src/utils/parse.js +0 -8
  167. package/lib/commonjs/src/utils/svgPatterns.d.ts +38 -0
  168. package/lib/commonjs/src/utils/svgPatterns.js +46 -0
  169. package/lib/module/const/codegenPrimitives.js +1 -2
  170. package/lib/module/const/colors.js +1 -2
  171. package/lib/module/createNanoIconsSet.js +1 -2
  172. package/lib/module/createNanoIconsSet.native.js +38 -28
  173. package/lib/module/createNanoIconsSet.shared.js +15 -9
  174. package/lib/module/createNanoIconsSet.web.js +22 -8
  175. package/lib/module/devServerFont.js +30 -0
  176. package/lib/module/devServerFont.web.js +25 -0
  177. package/lib/module/fontIntegrity.js +99 -0
  178. package/lib/module/index.js +1 -1
  179. package/lib/module/index.node.js +1 -2
  180. package/lib/module/loadDynamicFont.js +20 -10
  181. package/lib/module/nativeFontLoader.js +3 -0
  182. package/lib/module/nativeFontLoader.web.js +3 -0
  183. package/lib/module/specs/NanoIconViewNativeComponent.ts +9 -6
  184. package/lib/module/specs/NativeNanoIconsFontLoader.js +1 -2
  185. package/lib/module/symbols/index.android.js +42 -0
  186. package/lib/module/symbols/index.ios.js +35 -0
  187. package/lib/module/symbols/index.js +35 -0
  188. package/lib/module/symbols/index.native.js +12 -0
  189. package/lib/module/symbols/types.js +1 -0
  190. package/lib/module/types.js +1 -2
  191. package/lib/module/utils/fingerPrint.js +20 -5
  192. package/lib/module/utils/fontIdentity.js +20 -0
  193. package/lib/module/utils/glyphRuntime.js +36 -3
  194. package/lib/module/utils/naming.js +46 -0
  195. package/lib/module/utils/packageVersion.js +29 -0
  196. package/lib/module/utils/parse.js +1 -9
  197. package/lib/module/utils/runtimeLog.js +12 -0
  198. package/lib/module/utils/shallowEqualColor.js +1 -2
  199. package/lib/module/utils/svgPatterns.js +49 -0
  200. package/lib/module/utils/validateLayerColor.js +24 -0
  201. package/lib/typescript/src/core/flatten/arcs.d.ts +3 -0
  202. package/lib/typescript/src/core/flatten/document.d.ts +36 -0
  203. package/lib/typescript/src/core/flatten/dom.d.ts +25 -0
  204. package/lib/typescript/src/core/flatten/element.d.ts +13 -0
  205. package/lib/typescript/src/core/flatten/geometry.d.ts +22 -0
  206. package/lib/typescript/src/core/flatten/index.d.ts +3 -0
  207. package/lib/typescript/src/core/flatten/inherit.d.ts +14 -0
  208. package/lib/typescript/src/core/flatten/path.d.ts +20 -0
  209. package/lib/typescript/src/core/flatten/pathops.d.ts +15 -0
  210. package/lib/typescript/src/core/flatten/shape.d.ts +30 -0
  211. package/lib/typescript/src/core/flatten/stages/clip-path.d.ts +5 -0
  212. package/lib/typescript/src/core/flatten/stages/collapse.d.ts +3 -0
  213. package/lib/typescript/src/core/flatten/stages/defs.d.ts +5 -0
  214. package/lib/typescript/src/core/flatten/stages/discard.d.ts +5 -0
  215. package/lib/typescript/src/core/flatten/stages/fill-rule.d.ts +3 -0
  216. package/lib/typescript/src/core/flatten/stages/nested-svg.d.ts +3 -0
  217. package/lib/typescript/src/core/flatten/stages/opacity.d.ts +3 -0
  218. package/lib/typescript/src/core/flatten/stages/shapes.d.ts +8 -0
  219. package/lib/typescript/src/core/flatten/stages/stroke.d.ts +4 -0
  220. package/lib/typescript/src/core/flatten/stages/styles.d.ts +3 -0
  221. package/lib/typescript/src/core/flatten/stages/use.d.ts +5 -0
  222. package/lib/typescript/src/core/flatten/stages/validate.d.ts +3 -0
  223. package/lib/typescript/src/core/flatten/stages.d.ts +3 -0
  224. package/lib/typescript/src/core/flatten/transform.d.ts +36 -0
  225. package/lib/typescript/src/core/glyph/merge.d.ts +8 -0
  226. package/lib/typescript/src/core/glyph/parse.d.ts +28 -0
  227. package/lib/typescript/src/core/{svg/layers.d.ts → glyph/placement.d.ts} +2 -14
  228. package/lib/typescript/src/core/glyph/validate.d.ts +9 -0
  229. package/lib/typescript/src/core/pathkit/contours.d.ts +76 -0
  230. package/lib/typescript/src/core/pathkit/evenodd.d.ts +13 -0
  231. package/lib/typescript/src/core/pathkit/load.d.ts +3 -0
  232. package/lib/typescript/src/core/pathkit/types.d.ts +70 -0
  233. package/lib/typescript/src/core/pathkit/winding.d.ts +5 -0
  234. package/lib/typescript/src/core/symbols/contents.d.ts +3 -0
  235. package/lib/typescript/src/core/symbols/knockout.d.ts +4 -0
  236. package/lib/typescript/src/core/symbols/layers.d.ts +37 -0
  237. package/lib/typescript/src/core/symbols/template.d.ts +23 -0
  238. package/lib/typescript/src/core/symbols/vectorDrawable.d.ts +12 -0
  239. package/lib/typescript/src/core/types.d.ts +3 -92
  240. package/lib/typescript/src/devServerFont.d.ts +4 -0
  241. package/lib/typescript/src/devServerFont.web.d.ts +4 -0
  242. package/lib/typescript/src/fontIntegrity.d.ts +24 -0
  243. package/lib/typescript/src/index.d.ts +1 -0
  244. package/lib/typescript/src/loadDynamicFont.d.ts +1 -0
  245. package/lib/typescript/src/nativeFontLoader.d.ts +2 -0
  246. package/lib/typescript/src/nativeFontLoader.web.d.ts +3 -0
  247. package/lib/typescript/src/specs/NanoIconViewNativeComponent.d.ts +6 -5
  248. package/lib/typescript/src/specs/NativeNanoIconsFontLoader.d.ts +1 -0
  249. package/lib/typescript/src/symbols/index.android.d.ts +33 -0
  250. package/lib/typescript/src/symbols/index.d.ts +31 -0
  251. package/lib/typescript/src/symbols/index.ios.d.ts +31 -0
  252. package/lib/typescript/src/symbols/index.native.d.ts +8 -0
  253. package/lib/typescript/src/symbols/types.d.ts +24 -0
  254. package/lib/typescript/src/types.d.ts +7 -0
  255. package/lib/typescript/src/utils/fingerPrint.d.ts +19 -1
  256. package/lib/typescript/src/utils/fontIdentity.d.ts +5 -0
  257. package/lib/typescript/src/utils/glyphRuntime.d.ts +3 -1
  258. package/lib/typescript/src/utils/naming.d.ts +11 -0
  259. package/lib/typescript/src/utils/packageVersion.d.ts +3 -0
  260. package/lib/typescript/src/utils/parse.d.ts +0 -1
  261. package/lib/typescript/src/utils/runtimeLog.d.ts +5 -0
  262. package/lib/typescript/src/utils/svgPatterns.d.ts +39 -0
  263. package/lib/typescript/src/utils/validateLayerColor.d.ts +3 -0
  264. package/metro.js +1 -0
  265. package/package.json +37 -11
  266. package/react-native-nano-icons.podspec +4 -1
  267. package/react-native.config.js +10 -0
  268. package/src/specs/NanoIconViewNativeComponent.ts +9 -6
  269. package/src/specs/NativeNanoIconsFontLoader.ts +1 -0
  270. package/lib/commonjs/src/core/pipeline/managers.d.ts +0 -11
  271. package/lib/commonjs/src/core/pipeline/managers.js +0 -104
  272. package/lib/commonjs/src/core/pipeline/run.d.ts +0 -14
  273. package/lib/commonjs/src/core/pipeline/run.js +0 -189
  274. package/lib/commonjs/src/core/svg/svg_dom.d.ts +0 -51
  275. package/lib/commonjs/src/core/svg/svg_pathops.d.ts +0 -32
  276. package/lib/module/const/codegenPrimitives.js.map +0 -1
  277. package/lib/module/const/colors.js.map +0 -1
  278. package/lib/module/core/font/compile.js +0 -81
  279. package/lib/module/core/font/compile.js.map +0 -1
  280. package/lib/module/core/font/metrics.js +0 -37
  281. package/lib/module/core/font/metrics.js.map +0 -1
  282. package/lib/module/core/pipeline/config.js +0 -20
  283. package/lib/module/core/pipeline/config.js.map +0 -1
  284. package/lib/module/core/pipeline/index.js +0 -5
  285. package/lib/module/core/pipeline/index.js.map +0 -1
  286. package/lib/module/core/pipeline/managers.js +0 -94
  287. package/lib/module/core/pipeline/managers.js.map +0 -1
  288. package/lib/module/core/pipeline/run.js +0 -204
  289. package/lib/module/core/pipeline/run.js.map +0 -1
  290. package/lib/module/core/shims/pathops.py +0 -181
  291. package/lib/module/core/shims/picosvg-0.22.3-py3-none-any.whl +0 -0
  292. package/lib/module/core/svg/layers.js +0 -85
  293. package/lib/module/core/svg/layers.js.map +0 -1
  294. package/lib/module/core/svg/svg_dom.js +0 -170
  295. package/lib/module/core/svg/svg_dom.js.map +0 -1
  296. package/lib/module/core/svg/svg_pathops.js +0 -750
  297. package/lib/module/core/svg/svg_pathops.js.map +0 -1
  298. package/lib/module/core/tsconfig.json +0 -32
  299. package/lib/module/core/types.js +0 -2
  300. package/lib/module/core/types.js.map +0 -1
  301. package/lib/module/createNanoIconsSet.js.map +0 -1
  302. package/lib/module/createNanoIconsSet.native.js.map +0 -1
  303. package/lib/module/createNanoIconsSet.shared.js.map +0 -1
  304. package/lib/module/createNanoIconsSet.web.js.map +0 -1
  305. package/lib/module/index.js.map +0 -1
  306. package/lib/module/index.node.js.map +0 -1
  307. package/lib/module/loadDynamicFont.js.map +0 -1
  308. package/lib/module/specs/NativeNanoIconsFontLoader.js.map +0 -1
  309. package/lib/module/types.js.map +0 -1
  310. package/lib/module/utils/fingerPrint.js.map +0 -1
  311. package/lib/module/utils/glyphRuntime.js.map +0 -1
  312. package/lib/module/utils/parse.js.map +0 -1
  313. package/lib/module/utils/shallowEqualColor.js.map +0 -1
  314. package/lib/typescript/__tests__/build.unit.test.d.ts +0 -3
  315. package/lib/typescript/__tests__/build.unit.test.d.ts.map +0 -1
  316. package/lib/typescript/__tests__/clippath.e2e.test.d.ts +0 -3
  317. package/lib/typescript/__tests__/clippath.e2e.test.d.ts.map +0 -1
  318. package/lib/typescript/__tests__/fingerprint.unit.test.d.ts +0 -3
  319. package/lib/typescript/__tests__/fingerprint.unit.test.d.ts.map +0 -1
  320. package/lib/typescript/__tests__/glyphRuntime.unit.test.d.ts +0 -2
  321. package/lib/typescript/__tests__/glyphRuntime.unit.test.d.ts.map +0 -1
  322. package/lib/typescript/__tests__/link.unit.test.d.ts +0 -3
  323. package/lib/typescript/__tests__/link.unit.test.d.ts.map +0 -1
  324. package/lib/typescript/__tests__/loadDynamicFont.unit.test.d.ts +0 -2
  325. package/lib/typescript/__tests__/loadDynamicFont.unit.test.d.ts.map +0 -1
  326. package/lib/typescript/__tests__/pipeline.e2e.test.d.ts +0 -3
  327. package/lib/typescript/__tests__/pipeline.e2e.test.d.ts.map +0 -1
  328. package/lib/typescript/__tests__/placement.unit.test.d.ts +0 -3
  329. package/lib/typescript/__tests__/placement.unit.test.d.ts.map +0 -1
  330. package/lib/typescript/__tests__/svg_dom.unit.test.d.ts +0 -3
  331. package/lib/typescript/__tests__/svg_dom.unit.test.d.ts.map +0 -1
  332. package/lib/typescript/cli/build.d.ts +0 -32
  333. package/lib/typescript/cli/build.d.ts.map +0 -1
  334. package/lib/typescript/cli/link.d.ts +0 -12
  335. package/lib/typescript/cli/link.d.ts.map +0 -1
  336. package/lib/typescript/cli/logger.d.ts +0 -28
  337. package/lib/typescript/cli/logger.d.ts.map +0 -1
  338. package/lib/typescript/src/const/codegenPrimitives.d.ts.map +0 -1
  339. package/lib/typescript/src/const/colors.d.ts.map +0 -1
  340. package/lib/typescript/src/core/font/compile.d.ts +0 -21
  341. package/lib/typescript/src/core/font/compile.d.ts.map +0 -1
  342. package/lib/typescript/src/core/font/metrics.d.ts +0 -2
  343. package/lib/typescript/src/core/font/metrics.d.ts.map +0 -1
  344. package/lib/typescript/src/core/pipeline/config.d.ts +0 -16
  345. package/lib/typescript/src/core/pipeline/config.d.ts.map +0 -1
  346. package/lib/typescript/src/core/pipeline/index.d.ts +0 -4
  347. package/lib/typescript/src/core/pipeline/index.d.ts.map +0 -1
  348. package/lib/typescript/src/core/pipeline/managers.d.ts +0 -12
  349. package/lib/typescript/src/core/pipeline/managers.d.ts.map +0 -1
  350. package/lib/typescript/src/core/pipeline/run.d.ts +0 -15
  351. package/lib/typescript/src/core/pipeline/run.d.ts.map +0 -1
  352. package/lib/typescript/src/core/svg/layers.d.ts.map +0 -1
  353. package/lib/typescript/src/core/svg/svg_dom.d.ts +0 -52
  354. package/lib/typescript/src/core/svg/svg_dom.d.ts.map +0 -1
  355. package/lib/typescript/src/core/svg/svg_pathops.d.ts +0 -33
  356. package/lib/typescript/src/core/svg/svg_pathops.d.ts.map +0 -1
  357. package/lib/typescript/src/core/types.d.ts.map +0 -1
  358. package/lib/typescript/src/createNanoIconsSet.d.ts.map +0 -1
  359. package/lib/typescript/src/createNanoIconsSet.native.d.ts.map +0 -1
  360. package/lib/typescript/src/createNanoIconsSet.shared.d.ts.map +0 -1
  361. package/lib/typescript/src/createNanoIconsSet.web.d.ts.map +0 -1
  362. package/lib/typescript/src/index.d.ts.map +0 -1
  363. package/lib/typescript/src/index.node.d.ts.map +0 -1
  364. package/lib/typescript/src/loadDynamicFont.d.ts.map +0 -1
  365. package/lib/typescript/src/specs/NanoIconViewNativeComponent.d.ts.map +0 -1
  366. package/lib/typescript/src/specs/NativeNanoIconsFontLoader.d.ts.map +0 -1
  367. package/lib/typescript/src/types.d.ts.map +0 -1
  368. package/lib/typescript/src/utils/fingerPrint.d.ts.map +0 -1
  369. package/lib/typescript/src/utils/glyphRuntime.d.ts.map +0 -1
  370. package/lib/typescript/src/utils/parse.d.ts.map +0 -1
  371. package/lib/typescript/src/utils/shallowEqualColor.d.ts.map +0 -1
  372. package/plugin/src/buildFonts.ts +0 -42
  373. package/plugin/src/index.ts +0 -21
  374. package/plugin/src/types.ts +0 -42
  375. package/plugin/src/withNanoIconsFontLinking.ts +0 -136
  376. package/plugin/tsconfig.json +0 -9
  377. package/scripts/cli.ts +0 -63
  378. package/scripts/tsconfig.json +0 -25
  379. package/src/const/colors.ts +0 -150
  380. package/src/core/font/compile.ts +0 -99
  381. package/src/core/font/metrics.ts +0 -44
  382. package/src/core/pipeline/config.ts +0 -25
  383. package/src/core/pipeline/index.ts +0 -3
  384. package/src/core/pipeline/managers.ts +0 -132
  385. package/src/core/pipeline/run.ts +0 -274
  386. package/src/core/shims/pathops.py +0 -181
  387. package/src/core/shims/picosvg-0.22.3-py3-none-any.whl +0 -0
  388. package/src/core/svg/layers.ts +0 -110
  389. package/src/core/svg/svg_dom.ts +0 -194
  390. package/src/core/svg/svg_pathops.ts +0 -1040
  391. package/src/core/tsconfig.json +0 -32
  392. package/src/core/types.ts +0 -157
  393. package/src/createNanoIconsSet.native.tsx +0 -192
  394. package/src/createNanoIconsSet.shared.tsx +0 -174
  395. package/src/createNanoIconsSet.tsx +0 -20
  396. package/src/createNanoIconsSet.web.tsx +0 -109
  397. package/src/index.node.ts +0 -14
  398. package/src/index.ts +0 -6
  399. package/src/loadDynamicFont.ts +0 -162
  400. package/src/types.ts +0 -31
  401. package/src/utils/fingerPrint.ts +0 -20
  402. package/src/utils/glyphRuntime.ts +0 -46
  403. package/src/utils/parse.ts +0 -67
  404. package/src/utils/shallowEqualColor.ts +0 -17
@@ -1,1040 +0,0 @@
1
- import type {
2
- Cmd,
3
- PathKitModule,
4
- VerbMap,
5
- WrappedPath,
6
- Point,
7
- } from '../types.js';
8
-
9
- //** */
10
-
11
- // ----- numeric helpers -----
12
- const EPS = 1e-2;
13
-
14
- // ✅ round-half-to-even (banker's rounding) at ndigits
15
- function roundN(x: number, ndigits = 3): number {
16
- const m = 10 ** ndigits;
17
- const s = x * m;
18
-
19
- // Handle very large values safely
20
- if (!Number.isFinite(s)) return x;
21
-
22
- const floor = Math.floor(s);
23
- const frac = s - floor;
24
-
25
- // floating tolerance for "exactly .5"
26
- const TIE_EPS = 1e-12;
27
-
28
- let roundedInt: number;
29
- if (Math.abs(frac - 0.5) < TIE_EPS) {
30
- // tie -> choose even
31
- roundedInt = floor % 2 === 0 ? floor : floor + 1;
32
- } else if (Math.abs(frac + 0.5) < TIE_EPS) {
33
- // negative tie case (rare due to floor behavior, but keep for completeness)
34
- const ceil = Math.ceil(s);
35
- roundedInt = ceil % 2 === 0 ? ceil : ceil - 1;
36
- } else {
37
- roundedInt = Math.round(s);
38
- }
39
-
40
- return roundedInt / m;
41
- }
42
-
43
- function normPt(p: Point): [number, number] {
44
- return [Math.round(p[0] * 10000) / 10000, Math.round(p[1] * 10000) / 10000];
45
- }
46
-
47
- function eqPt(a: Point, b: Point): boolean {
48
- const aa = normPt(a);
49
- const bb = normPt(b);
50
- return Math.abs(aa[0] - bb[0]) < EPS && Math.abs(aa[1] - bb[1]) < EPS;
51
- }
52
-
53
- function signedAreaPolyline(points: readonly Point[]): number {
54
- if (points.length < 3) return 0;
55
- let a = 0;
56
- for (let i = 0; i < points.length; i++) {
57
- const [x1, y1] = points[i]!;
58
- const [x2, y2] = points[(i + 1) % points.length]!;
59
- a += x1 * y2 - x2 * y1;
60
- }
61
- return a / 2;
62
- }
63
-
64
- function approxSignedAreaFromContourCmds(
65
- contourCmds: readonly Cmd[],
66
- VERB: VerbMap,
67
- steps = 24
68
- ): number {
69
- let cx = 0,
70
- cy = 0;
71
- let sx = 0,
72
- sy = 0;
73
- const pts: Point[] = [];
74
- const add = (x: number, y: number) => pts.push([x, y]);
75
-
76
- for (const cmd of contourCmds) {
77
- const v = cmd[0]!;
78
- if (v === VERB.MOVE) {
79
- cx = cmd[1]!;
80
- cy = cmd[2]!;
81
- sx = cx;
82
- sy = cy;
83
- add(cx, cy);
84
- } else if (v === VERB.LINE) {
85
- cx = cmd[1]!;
86
- cy = cmd[2]!;
87
- add(cx, cy);
88
- } else if (v === VERB.QUAD) {
89
- const x0 = cx,
90
- y0 = cy;
91
- const x1 = cmd[1]!,
92
- y1 = cmd[2]!;
93
- const x2 = cmd[3]!,
94
- y2 = cmd[4]!;
95
- for (let i = 1; i <= steps; i++) {
96
- const t = i / steps;
97
- const mt = 1 - t;
98
- const x = mt * mt * x0 + 2 * mt * t * x1 + t * t * x2;
99
- const y = mt * mt * y0 + 2 * mt * t * y1 + t * t * y2;
100
- add(x, y);
101
- }
102
- cx = x2;
103
- cy = y2;
104
- } else if (v === VERB.CUBIC) {
105
- const x0 = cx,
106
- y0 = cy;
107
- const x1 = cmd[1]!,
108
- y1 = cmd[2]!;
109
- const x2 = cmd[3]!,
110
- y2 = cmd[4]!;
111
- const x3 = cmd[5]!,
112
- y3 = cmd[6]!;
113
- for (let i = 1; i <= steps; i++) {
114
- const t = i / steps;
115
- const mt = 1 - t;
116
- const x =
117
- mt * mt * mt * x0 +
118
- 3 * mt * mt * t * x1 +
119
- 3 * mt * t * t * x2 +
120
- t * t * t * x3;
121
- const y =
122
- mt * mt * mt * y0 +
123
- 3 * mt * mt * t * y1 +
124
- 3 * mt * t * t * y2 +
125
- t * t * t * y3;
126
- add(x, y);
127
- }
128
- cx = x3;
129
- cy = y3;
130
- } else if (v === VERB.CLOSE) {
131
- add(sx, sy);
132
- }
133
- }
134
-
135
- if (
136
- pts.length &&
137
- (pts[0]![0] !== pts[pts.length - 1]![0] ||
138
- pts[0]![1] !== pts[pts.length - 1]![1])
139
- ) {
140
- pts.push([pts[0]![0], pts[0]![1]]);
141
- }
142
- return signedAreaPolyline(pts);
143
- }
144
-
145
- function splitContours(cmds: readonly Cmd[], VERB: VerbMap): Cmd[][] {
146
- const contours: Cmd[][] = [];
147
- let cur: Cmd[] | null = null;
148
- for (const cmd of cmds) {
149
- const v = cmd[0]!;
150
- if (v === VERB.MOVE) {
151
- if (cur && cur.length) contours.push(cur);
152
- cur = [cmd];
153
- } else if (cur) {
154
- cur.push(cmd);
155
- }
156
- }
157
- if (cur && cur.length) contours.push(cur);
158
- return contours;
159
- }
160
-
161
- function ensureClosed(contourCmds: readonly Cmd[], VERB: VerbMap): Cmd[] {
162
- return contourCmds.some((c) => c[0] === VERB.CLOSE)
163
- ? [...contourCmds]
164
- : [...contourCmds, [VERB.CLOSE]];
165
- }
166
-
167
- function explicitCloseWantedFromCmds(
168
- contourCmds: readonly Cmd[] | undefined,
169
- VERB: VerbMap
170
- ): boolean {
171
- if (!contourCmds?.length) return false;
172
- const m = contourCmds[0]!;
173
- if (m[0] !== VERB.MOVE) return false;
174
- const start: Point = [m[1]!, m[2]!];
175
-
176
- for (let i = contourCmds.length - 1; i >= 1; i--) {
177
- const cmd = contourCmds[i]!;
178
- const v = cmd[0]!;
179
- if (v === VERB.CLOSE) continue;
180
-
181
- let end: Point | null = null;
182
- if (v === VERB.LINE) end = [cmd[1]!, cmd[2]!];
183
- else if (v === VERB.QUAD) end = [cmd[3]!, cmd[4]!];
184
- else if (v === VERB.CUBIC) end = [cmd[5]!, cmd[6]!];
185
- else continue;
186
-
187
- return eqPt(end, start);
188
- }
189
- return false;
190
- }
191
-
192
- type SegmentL = { type: 'L'; start: Point; end: Point; synthetic: boolean };
193
- type SegmentQ = {
194
- type: 'Q';
195
- start: Point;
196
- ctrl: Point;
197
- end: Point;
198
- synthetic: boolean;
199
- };
200
- type SegmentC = {
201
- type: 'C';
202
- start: Point;
203
- c1: Point;
204
- c2: Point;
205
- end: Point;
206
- synthetic: boolean;
207
- };
208
- type Segment = SegmentL | SegmentQ | SegmentC;
209
-
210
- function contourToSegments(
211
- contourCmds: readonly Cmd[],
212
- VERB: VerbMap
213
- ): { start: Point; segs: Segment[] } {
214
- const c = ensureClosed(contourCmds, VERB);
215
- const move = c[0]!;
216
- const sx = move[1]!,
217
- sy = move[2]!;
218
-
219
- let last: Point = [sx, sy];
220
- const segs: Segment[] = [];
221
-
222
- for (let i = 1; i < c.length; i++) {
223
- const cmd = c[i]!;
224
- const v = cmd[0]!;
225
-
226
- if (v === VERB.LINE) {
227
- const end: Point = [cmd[1]!, cmd[2]!];
228
- segs.push({ type: 'L', start: last, end, synthetic: false });
229
- last = end;
230
- } else if (v === VERB.QUAD) {
231
- const ctrl: Point = [cmd[1]!, cmd[2]!];
232
- const end: Point = [cmd[3]!, cmd[4]!];
233
- segs.push({ type: 'Q', start: last, ctrl, end, synthetic: false });
234
- last = end;
235
- } else if (v === VERB.CUBIC) {
236
- const c1: Point = [cmd[1]!, cmd[2]!];
237
- const c2: Point = [cmd[3]!, cmd[4]!];
238
- const end: Point = [cmd[5]!, cmd[6]!];
239
- segs.push({ type: 'C', start: last, c1, c2, end, synthetic: false });
240
- last = end;
241
- } else if (v === VERB.CLOSE) {
242
- const end: Point = [sx, sy];
243
- if (!eqPt(last, end)) {
244
- segs.push({ type: 'L', start: last, end, synthetic: true });
245
- }
246
- last = end;
247
- }
248
- }
249
-
250
- return { start: [sx, sy], segs };
251
- }
252
-
253
- function applyClosePolicy(
254
- segs: Segment[],
255
- startPt: Point,
256
- explicitCloseWanted: boolean
257
- ): Segment[] {
258
- if (!segs.length) return segs;
259
-
260
- for (const s of segs) s.synthetic = false;
261
-
262
- const last = segs[segs.length - 1]!;
263
- const lastEnd = last.end;
264
- if (!eqPt(lastEnd, startPt)) {
265
- segs.push({ type: 'L', start: lastEnd, end: startPt, synthetic: false });
266
- }
267
-
268
- if (!explicitCloseWanted) {
269
- segs[segs.length - 1]!.synthetic = true;
270
- }
271
- return segs;
272
- }
273
-
274
- function segmentsToContourCmds(
275
- startPt: Point,
276
- segs: readonly Segment[],
277
- VERB: VerbMap
278
- ): Cmd[] {
279
- const out: Cmd[] = [[VERB.MOVE, roundN(startPt[0]), roundN(startPt[1])]];
280
- for (const s of segs) {
281
- if (s.synthetic) continue;
282
- if (s.type === 'L') {
283
- out.push([VERB.LINE, roundN(s.end[0]), roundN(s.end[1])]);
284
- } else if (s.type === 'Q') {
285
- out.push([
286
- VERB.QUAD,
287
- roundN(s.ctrl[0]),
288
- roundN(s.ctrl[1]),
289
- roundN(s.end[0]),
290
- roundN(s.end[1]),
291
- ]);
292
- } else {
293
- out.push([
294
- VERB.CUBIC,
295
- roundN(s.c1[0]),
296
- roundN(s.c1[1]),
297
- roundN(s.c2[0]),
298
- roundN(s.c2[1]),
299
- roundN(s.end[0]),
300
- roundN(s.end[1]),
301
- ]);
302
- }
303
- }
304
- out.push([VERB.CLOSE]);
305
- return out;
306
- }
307
-
308
- function reverseClosedContourKeepStart(
309
- contourCmds: readonly Cmd[],
310
- explicitCloseWanted: boolean,
311
- VERB: VerbMap
312
- ): Cmd[] {
313
- const { start, segs } = contourToSegments(contourCmds, VERB);
314
-
315
- const reversed: Segment[] = segs
316
- .slice()
317
- .reverse()
318
- .map((s) => {
319
- if (s.type === 'L') {
320
- return { type: 'L', start: s.end, end: s.start, synthetic: false };
321
- }
322
- if (s.type === 'Q') {
323
- return {
324
- type: 'Q',
325
- start: s.end,
326
- ctrl: s.ctrl,
327
- end: s.start,
328
- synthetic: false,
329
- };
330
- }
331
- return {
332
- type: 'C',
333
- start: s.end,
334
- c1: s.c2,
335
- c2: s.c1,
336
- end: s.start,
337
- synthetic: false,
338
- };
339
- });
340
-
341
- applyClosePolicy(reversed, start, explicitCloseWanted);
342
- return segmentsToContourCmds(start, reversed, VERB);
343
- }
344
-
345
- function rotateClosedContourToStart(
346
- contourCmds: readonly Cmd[],
347
- desiredStart: Point,
348
- explicitCloseWanted: boolean,
349
- VERB: VerbMap
350
- ): Cmd[] {
351
- const { segs } = contourToSegments(contourCmds, VERB);
352
-
353
- let idx = -1;
354
- for (let i = 0; i < segs.length; i++) {
355
- if (eqPt(segs[i]!.start, desiredStart)) {
356
- idx = i;
357
- break;
358
- }
359
- }
360
- if (idx === -1) {
361
- for (let i = 0; i < segs.length; i++) {
362
- if (eqPt(segs[i]!.end, desiredStart)) {
363
- idx = (i + 1) % segs.length;
364
- break;
365
- }
366
- }
367
- }
368
- if (idx === -1) return [...contourCmds];
369
-
370
- const rotated = segs.slice(idx).concat(segs.slice(0, idx));
371
- applyClosePolicy(rotated, desiredStart, explicitCloseWanted);
372
- return segmentsToContourCmds(desiredStart, rotated, VERB);
373
- }
374
-
375
- function cmdsToVerbPoints(
376
- cmds: readonly Cmd[],
377
- VERB: VerbMap
378
- ): Array<[number, Point[]]> {
379
- const out: Array<[number, Point[]]> = [];
380
- for (const cmd of cmds) {
381
- const v = cmd[0]!;
382
- if (v === VERB.MOVE) out.push([0, [[cmd[1]!, cmd[2]!]]]);
383
- else if (v === VERB.LINE) out.push([1, [[cmd[1]!, cmd[2]!]]]);
384
- else if (v === VERB.QUAD)
385
- out.push([
386
- 2,
387
- [
388
- [cmd[1]!, cmd[2]!],
389
- [cmd[3]!, cmd[4]!],
390
- ],
391
- ]);
392
- else if (v === VERB.CUBIC)
393
- out.push([
394
- 3,
395
- [
396
- [cmd[1]!, cmd[2]!],
397
- [cmd[3]!, cmd[4]!],
398
- [cmd[5]!, cmd[6]!],
399
- ],
400
- ]);
401
- else if (v === VERB.CLOSE) out.push([4, []]);
402
- else throw new Error(`Unexpected verb in cmds: ${v}`);
403
- }
404
- return out;
405
- }
406
-
407
- function wrapPath(pathkitPath: WrappedPath['p']): WrappedPath {
408
- return { p: pathkitPath, meta: { moves: [] } };
409
- }
410
-
411
- function cloneWrap(h: WrappedPath, PathKit: PathKitModule): WrappedPath {
412
- const p2 = PathKit.NewPath(h.p);
413
- const out = wrapPath(p2);
414
- out.meta.moves = h.meta?.moves ? h.meta.moves.map((m) => [m[0], m[1]]) : [];
415
- return out;
416
- }
417
-
418
- function mergeMoves(
419
- aMoves: readonly Point[] | undefined,
420
- bMoves: readonly Point[] | undefined
421
- ): Point[] {
422
- const out: Point[] = [];
423
- const pushUnique = (pt: Point) => {
424
- for (const existing of out) {
425
- if (eqPt(existing, pt)) return;
426
- }
427
- out.push(pt);
428
- };
429
- for (const m of aMoves || []) pushUnique(normPt(m));
430
- for (const m of bMoves || []) pushUnique(normPt(m));
431
- return out;
432
- }
433
-
434
- function bestStartMinYMinX(
435
- contourCmds: readonly Cmd[],
436
- VERB: VerbMap
437
- ): Point | null {
438
- let best: Point | null = null;
439
- for (const cmd of contourCmds) {
440
- const v = cmd[0]!;
441
- const add = (x: number, y: number) => {
442
- const p: Point = [x, y];
443
- if (!best) {
444
- best = p;
445
- return;
446
- }
447
- if (p[1] < best[1] - 1e-9) best = p;
448
- else if (Math.abs(p[1] - best[1]) < 1e-9 && p[0] < best[0] - 1e-9)
449
- best = p;
450
- };
451
-
452
- if (v === VERB.MOVE) add(cmd[1]!, cmd[2]!);
453
- else if (v === VERB.LINE) add(cmd[1]!, cmd[2]!);
454
- else if (v === VERB.QUAD) add(cmd[3]!, cmd[4]!);
455
- else if (v === VERB.CUBIC) add(cmd[5]!, cmd[6]!);
456
- }
457
- return best;
458
- }
459
-
460
- // ---------------------------------------------------------------------------
461
- // Containment helpers (module-level for reuse by fixPathWinding)
462
- // ---------------------------------------------------------------------------
463
-
464
- function buildVerbMap(PathKit: PathKitModule): VerbMap {
465
- return {
466
- MOVE: PathKit.MOVE_VERB ?? 0,
467
- LINE: PathKit.LINE_VERB ?? 1,
468
- QUAD: PathKit.QUAD_VERB ?? 2,
469
- CONIC: PathKit.CONIC_VERB ?? 3,
470
- CUBIC: PathKit.CUBIC_VERB ?? 4,
471
- CLOSE: PathKit.CLOSE_VERB ?? 5,
472
- };
473
- }
474
-
475
- /**
476
- * Convert contour commands to a polyline by sampling curves.
477
- * Used for ray-casting containment tests.
478
- */
479
- function contourToPolyline(
480
- contourCmds: readonly Cmd[],
481
- V: VerbMap,
482
- steps = 8
483
- ): Point[] {
484
- let cx = 0,
485
- cy = 0;
486
- let sx = 0,
487
- sy = 0;
488
- const pts: Point[] = [];
489
-
490
- for (const cmd of contourCmds) {
491
- const v = cmd[0]!;
492
- if (v === V.MOVE) {
493
- cx = cmd[1]!;
494
- cy = cmd[2]!;
495
- sx = cx;
496
- sy = cy;
497
- pts.push([cx, cy]);
498
- } else if (v === V.LINE) {
499
- cx = cmd[1]!;
500
- cy = cmd[2]!;
501
- pts.push([cx, cy]);
502
- } else if (v === V.QUAD) {
503
- const x0 = cx,
504
- y0 = cy;
505
- const x1 = cmd[1]!,
506
- y1 = cmd[2]!;
507
- const x2 = cmd[3]!,
508
- y2 = cmd[4]!;
509
- for (let i = 1; i <= steps; i++) {
510
- const t = i / steps;
511
- const mt = 1 - t;
512
- pts.push([
513
- mt * mt * x0 + 2 * mt * t * x1 + t * t * x2,
514
- mt * mt * y0 + 2 * mt * t * y1 + t * t * y2,
515
- ]);
516
- }
517
- cx = x2;
518
- cy = y2;
519
- } else if (v === V.CUBIC) {
520
- const x0 = cx,
521
- y0 = cy;
522
- const x1 = cmd[1]!,
523
- y1 = cmd[2]!;
524
- const x2 = cmd[3]!,
525
- y2 = cmd[4]!;
526
- const x3 = cmd[5]!,
527
- y3 = cmd[6]!;
528
- for (let i = 1; i <= steps; i++) {
529
- const t = i / steps;
530
- const mt = 1 - t;
531
- pts.push([
532
- mt * mt * mt * x0 +
533
- 3 * mt * mt * t * x1 +
534
- 3 * mt * t * t * x2 +
535
- t * t * t * x3,
536
- mt * mt * mt * y0 +
537
- 3 * mt * mt * t * y1 +
538
- 3 * mt * t * t * y2 +
539
- t * t * t * y3,
540
- ]);
541
- }
542
- cx = x3;
543
- cy = y3;
544
- } else if (v === V.CLOSE) {
545
- if (cx !== sx || cy !== sy) pts.push([sx, sy]);
546
- cx = sx;
547
- cy = sy;
548
- }
549
- }
550
- return pts;
551
- }
552
-
553
- /**
554
- * Ray-casting point-in-polygon test.
555
- */
556
- function pointInPolygon(px: number, py: number, poly: Point[]): boolean {
557
- let inside = false;
558
- for (let i = 0, j = poly.length - 1; i < poly.length; j = i++) {
559
- const [xi, yi] = poly[i]!;
560
- const [xj, yj] = poly[j]!;
561
- if (yi > py !== yj > py && px < ((xj - xi) * (py - yi)) / (yj - yi) + xi) {
562
- inside = !inside;
563
- }
564
- }
565
- return inside;
566
- }
567
-
568
- /**
569
- * Get a representative point on the contour boundary (midpoint of first segment).
570
- */
571
- function getContourSamplePoint(
572
- contourCmds: readonly Cmd[],
573
- V: VerbMap
574
- ): Point | null {
575
- let cx = 0,
576
- cy = 0;
577
- for (const cmd of contourCmds) {
578
- const v = cmd[0]!;
579
- if (v === V.MOVE) {
580
- cx = cmd[1]!;
581
- cy = cmd[2]!;
582
- } else if (v === V.LINE) {
583
- return [(cx + cmd[1]!) / 2, (cy + cmd[2]!) / 2];
584
- } else if (v === V.QUAD) {
585
- const t = 0.5,
586
- mt = 0.5;
587
- return [
588
- mt * mt * cx + 2 * mt * t * cmd[1]! + t * t * cmd[3]!,
589
- mt * mt * cy + 2 * mt * t * cmd[2]! + t * t * cmd[4]!,
590
- ];
591
- } else if (v === V.CUBIC) {
592
- const t = 0.5,
593
- mt = 0.5;
594
- return [
595
- mt ** 3 * cx +
596
- 3 * mt ** 2 * t * cmd[1]! +
597
- 3 * mt * t ** 2 * cmd[3]! +
598
- t ** 3 * cmd[5]!,
599
- mt ** 3 * cy +
600
- 3 * mt ** 2 * t * cmd[2]! +
601
- 3 * mt * t ** 2 * cmd[4]! +
602
- t ** 3 * cmd[6]!,
603
- ];
604
- }
605
- }
606
- return null;
607
- }
608
-
609
- /**
610
- * Apply containment-based winding fix to contour objects.
611
- * Even nesting depth = CCW (outer), odd = CW (hole).
612
- */
613
- function applyContainmentWinding(
614
- contourObjs: Array<{
615
- cmds: Cmd[];
616
- explicitCloseWanted: boolean;
617
- absA: number;
618
- }>,
619
- V: VerbMap
620
- ): void {
621
- const n = contourObjs.length;
622
- if (n === 0) return;
623
-
624
- const polylines = contourObjs.map((obj) => contourToPolyline(obj.cmds, V));
625
- const samplePts = contourObjs.map((obj) =>
626
- getContourSamplePoint(obj.cmds, V)
627
- );
628
- const depths = new Array<number>(n).fill(0);
629
-
630
- for (let i = 0; i < n; i++) {
631
- const pt = samplePts[i];
632
- if (!pt) continue;
633
- for (let j = 0; j < n; j++) {
634
- if (i === j) continue;
635
- if (pointInPolygon(pt[0], pt[1], polylines[j]!)) {
636
- depths[i] = (depths[i] ?? 0) + 1;
637
- }
638
- }
639
- }
640
-
641
- const ensureOrient = (
642
- obj: { cmds: Cmd[]; explicitCloseWanted: boolean },
643
- wantCCW: boolean
644
- ) => {
645
- const a = approxSignedAreaFromContourCmds(obj.cmds, V);
646
- const isCCW = a > 0;
647
- if (wantCCW !== isCCW) {
648
- obj.cmds = reverseClosedContourKeepStart(
649
- obj.cmds,
650
- obj.explicitCloseWanted,
651
- V
652
- );
653
- }
654
- };
655
-
656
- for (let i = 0; i < n; i++) {
657
- ensureOrient(contourObjs[i]!, depths[i]! % 2 === 0);
658
- }
659
- }
660
-
661
- /**
662
- * Convert a path `d` string with evenodd fill semantics to an equivalent
663
- * path that renders identically under nonzero winding.
664
- *
665
- * Steps:
666
- * 1. Parse via PathKit, set fill type to EVENODD, simplify (resolve topology)
667
- * 2. Split into contours, compute containment depths
668
- * 3. Fix winding: even depth = CCW (outer), odd depth = CW (hole)
669
- * 4. Reconstruct d string
670
- */
671
- export function convertEvenoddToWinding(
672
- PathKit: PathKitModule,
673
- d: string
674
- ): string {
675
- const V = buildVerbMap(PathKit);
676
-
677
- // 1. Parse and simplify with EVENODD fill type
678
- const p = PathKit.FromSVGString(d);
679
- if (!p) return d;
680
-
681
- const FILL_EVENODD =
682
- PathKit?.FillType?.EVENODD ?? PathKit?.FillType?.EVEN_ODD ?? 1;
683
- p.setFillType(FILL_EVENODD);
684
- p.simplify();
685
-
686
- // Get the simplified SVG string and re-parse for command access
687
- const simplified = p.toSVGString();
688
- p.delete?.();
689
-
690
- const p2 = PathKit.FromSVGString(simplified);
691
- if (!p2) return simplified;
692
-
693
- const cmds: Cmd[] = p2.toCmds();
694
- p2.delete?.();
695
-
696
- if (cmds.length === 0) return simplified;
697
-
698
- // 2. Split into contours
699
- const contourObjs = splitContours(cmds, V).map((c) => {
700
- const explicitCloseWanted = explicitCloseWantedFromCmds(c, V);
701
- const cc = ensureClosed(c, V);
702
- const a = approxSignedAreaFromContourCmds(cc, V);
703
- return { cmds: cc, absA: Math.abs(a), explicitCloseWanted };
704
- });
705
-
706
- contourObjs.sort((x, y) => y.absA - x.absA);
707
-
708
- // 3. Fix winding via containment analysis
709
- applyContainmentWinding(contourObjs, V);
710
-
711
- // 4. Reconstruct d string from fixed commands
712
- const allCmds = contourObjs.flatMap((x) => x.cmds);
713
- const parts: string[] = [];
714
- for (const cmd of allCmds) {
715
- const v = cmd[0]!;
716
- if (v === V.MOVE) parts.push(`M${roundN(cmd[1]!)} ${roundN(cmd[2]!)}`);
717
- else if (v === V.LINE) parts.push(`L${roundN(cmd[1]!)} ${roundN(cmd[2]!)}`);
718
- else if (v === V.QUAD)
719
- parts.push(
720
- `Q${roundN(cmd[1]!)} ${roundN(cmd[2]!)} ${roundN(cmd[3]!)} ${roundN(cmd[4]!)}`
721
- );
722
- else if (v === V.CUBIC)
723
- parts.push(
724
- `C${roundN(cmd[1]!)} ${roundN(cmd[2]!)} ${roundN(cmd[3]!)} ${roundN(cmd[4]!)} ${roundN(cmd[5]!)} ${roundN(cmd[6]!)}`
725
- );
726
- else if (v === V.CLOSE) parts.push('Z');
727
- }
728
-
729
- return parts.join(' ');
730
- }
731
-
732
- // proxy to for picosvg to interatc with pathkit
733
- export function buildPathopsBackend(PathKit: PathKitModule) {
734
- const VERB: VerbMap = buildVerbMap(PathKit);
735
-
736
- const FILL_EVENODD =
737
- PathKit?.FillType?.EVENODD ?? PathKit?.FillType?.EVEN_ODD ?? 1;
738
- const FILL_WINDING =
739
- PathKit?.FillType?.WINDING ?? PathKit?.FillType?.NONZERO ?? 0;
740
-
741
- function cmdsViaSvgRoundtrip(h: WrappedPath): Cmd[] {
742
- const svg = h.p.toSVGString();
743
- const p2 = PathKit.FromSVGString(svg);
744
- const cmds = p2 ? p2.toCmds() : [];
745
- if (p2) p2.delete?.();
746
- return cmds;
747
- }
748
-
749
- function normalizeSortRotateContours(
750
- cmds: Cmd[],
751
- h: WrappedPath,
752
- preferStrokeCanonical = false
753
- ): Cmd[] {
754
- const moves = (h.meta?.moves || []).map((m) => normPt([m[0], m[1]]));
755
- const used = new Array(moves.length).fill(false);
756
-
757
- // Build contour objects, but DO NOT normalize orientation yet.
758
- const contourObjs = splitContours(cmds, VERB).map((c) => {
759
- const explicitCloseWanted = explicitCloseWantedFromCmds(c, VERB);
760
- const cc = ensureClosed(c, VERB);
761
- const a = approxSignedAreaFromContourCmds(cc, VERB); // signed
762
- return { cmds: cc, absA: Math.abs(a), explicitCloseWanted };
763
- });
764
-
765
- // Big-to-small ordering gives deterministic outer→inner ordering.
766
- contourObjs.sort((x, y) => y.absA - x.absA);
767
-
768
- // Containment-based winding: compute nesting depth per contour via
769
- // ray-casting point-in-polygon. Even depth = outer (CCW), odd = hole (CW).
770
- applyContainmentWinding(contourObjs, VERB);
771
-
772
- // Rotate starts deterministically:
773
- // 1) If we have recorded MOVE points, try to rotate contour to a move point that lies on it.
774
- // 2) Otherwise, rotate to minY/minX point (helps stroke-ish paths)
775
- for (const obj of contourObjs) {
776
- let cc = obj.cmds;
777
-
778
- for (let i = 0; i < moves.length; i++) {
779
- if (used[i]) continue;
780
- const target = moves[i]!;
781
- const { segs } = contourToSegments(cc, VERB);
782
- const found = segs.some(
783
- (s) => eqPt(s.start, target) || eqPt(s.end, target)
784
- );
785
- if (found) {
786
- used[i] = true;
787
- cc = rotateClosedContourToStart(
788
- cc,
789
- target,
790
- obj.explicitCloseWanted,
791
- VERB
792
- );
793
- break;
794
- }
795
- }
796
-
797
- // If no move point was used, apply the deterministic start heuristic
798
- if (preferStrokeCanonical) {
799
- const best = bestStartMinYMinX(cc, VERB);
800
- if (best) {
801
- cc = rotateClosedContourToStart(
802
- cc,
803
- best,
804
- obj.explicitCloseWanted,
805
- VERB
806
- );
807
- }
808
- }
809
-
810
- obj.cmds = cc;
811
- }
812
-
813
- return contourObjs.flatMap((x) => x.cmds);
814
- }
815
-
816
- return {
817
- create_path(fillTypeInt: number): WrappedPath {
818
- const p = PathKit.NewPath();
819
- p.setFillType(fillTypeInt === 1 ? FILL_EVENODD : FILL_WINDING);
820
- return wrapPath(p);
821
- },
822
-
823
- clone_path(h: WrappedPath): WrappedPath {
824
- return cloneWrap(h, PathKit);
825
- },
826
-
827
- delete_path(h: WrappedPath): void {
828
- h?.p?.delete?.();
829
- },
830
-
831
- get_fill_type(h: WrappedPath): number {
832
- const ft = h.p.getFillType?.();
833
- return ft === FILL_EVENODD ? 1 : 0;
834
- },
835
-
836
- set_fill_type(h: WrappedPath, fillTypeInt: number): true {
837
- h.p.setFillType(fillTypeInt === 1 ? FILL_EVENODD : FILL_WINDING);
838
- return true;
839
- },
840
-
841
- move_to(h: WrappedPath, x: number, y: number): void {
842
- h.p.moveTo(x, y);
843
- h.meta.moves.push(normPt([x, y]));
844
- },
845
-
846
- line_to(h: WrappedPath, x: number, y: number): void {
847
- h.p.lineTo(x, y);
848
- },
849
-
850
- quad_to(
851
- h: WrappedPath,
852
- x1: number,
853
- y1: number,
854
- x2: number,
855
- y2: number
856
- ): void {
857
- h.p.quadTo(x1, y1, x2, y2);
858
- },
859
-
860
- cubic_to(
861
- h: WrappedPath,
862
- x1: number,
863
- y1: number,
864
- x2: number,
865
- y2: number,
866
- x3: number,
867
- y3: number
868
- ): void {
869
- h.p.cubicTo(x1, y1, x2, y2, x3, y3);
870
- },
871
-
872
- close(h: WrappedPath): void {
873
- h.p.close();
874
- },
875
-
876
- simplify(h: WrappedPath, fixWinding = false): boolean {
877
- try {
878
- // 1) simplify in place
879
- h.p.simplify();
880
-
881
- // 2) normalize representation via SVG roundtrip
882
- const svg = h.p.toSVGString();
883
- const p2 = PathKit.FromSVGString(svg);
884
- if (p2) {
885
- // replace underlying path handle
886
- h.p.delete?.();
887
- h.p = p2;
888
- }
889
-
890
- if (fixWinding) h.p.setFillType(FILL_WINDING);
891
- return true;
892
- } catch {
893
- return false;
894
- }
895
- },
896
-
897
- stroke(
898
- h: WrappedPath,
899
- width: number,
900
- capInt: number,
901
- joinInt: number,
902
- miterLimit: number,
903
- dashArray: unknown,
904
- dashOffset: number
905
- ): WrappedPath {
906
- const Caps = PathKit.StrokeCap ?? {};
907
- const Joins = PathKit.StrokeJoin ?? {};
908
-
909
- const cap =
910
- capInt === 1
911
- ? (Caps.ROUND ?? 1)
912
- : capInt === 2
913
- ? (Caps.SQUARE ?? 2)
914
- : (Caps.BUTT ?? 0);
915
-
916
- const join =
917
- joinInt === 1
918
- ? (Joins.ROUND ?? 1)
919
- : joinInt === 2
920
- ? (Joins.BEVEL ?? 2)
921
- : (Joins.MITER ?? 0);
922
-
923
- const work = PathKit.NewPath(h.p);
924
-
925
- try {
926
- if (
927
- Array.isArray(dashArray) &&
928
- dashArray.length === 2 &&
929
- typeof work.dash === 'function'
930
- ) {
931
- work.dash(
932
- Number(dashArray[0]),
933
- Number(dashArray[1]),
934
- dashOffset || 0
935
- );
936
- }
937
-
938
- let stroked = work.stroke({
939
- width,
940
- cap,
941
- join,
942
- miter_limit: miterLimit,
943
- });
944
- if (!stroked || typeof stroked.toCmds !== 'function') stroked = work;
945
-
946
- if (stroked !== work) work.delete?.();
947
-
948
- const wrapped = wrapPath(stroked);
949
- wrapped.meta.moves = [];
950
- return wrapped;
951
- } catch {
952
- const wrapped = wrapPath(work);
953
- wrapped.meta.moves = [];
954
- return wrapped;
955
- }
956
- },
957
-
958
- convert_conics_to_quads(_h: WrappedPath, _tol: number): void {
959
- // intentionally no-op
960
- },
961
-
962
- transform(
963
- h: WrappedPath,
964
- a: number,
965
- b: number,
966
- c: number,
967
- d: number,
968
- e: number,
969
- f: number
970
- ): WrappedPath {
971
- const p = PathKit.NewPath(h.p);
972
- p.transform(a, c, e, b, d, f, 0, 0, 1);
973
-
974
- const wrapped = wrapPath(p);
975
- wrapped.meta.moves = (h.meta?.moves || []).map(([x, y]) =>
976
- normPt([a * x + c * y + e, b * x + d * y + f])
977
- );
978
- return wrapped;
979
- },
980
-
981
- op(
982
- aHandle: WrappedPath,
983
- bHandle: WrappedPath,
984
- opInt: number
985
- ): WrappedPath | null {
986
- try {
987
- const Ops = PathKit.PathOp ?? {};
988
- const op =
989
- opInt === 1
990
- ? (Ops.INTERSECT ?? 1)
991
- : opInt === 2
992
- ? (Ops.DIFFERENCE ?? 2)
993
- : (Ops.UNION ?? 0);
994
-
995
- const out = PathKit.MakeFromOp(aHandle.p, bHandle.p, op);
996
- if (!out) return null;
997
-
998
- const wrapped = wrapPath(out);
999
- wrapped.meta.moves = mergeMoves(
1000
- aHandle.meta?.moves,
1001
- bHandle.meta?.moves
1002
- );
1003
- return wrapped;
1004
- } catch {
1005
- return null;
1006
- }
1007
- },
1008
-
1009
- bounds(h: WrappedPath): [number, number, number, number] {
1010
- const r = h.p.getBounds();
1011
- return [r.fLeft, r.fTop, r.fRight, r.fBottom];
1012
- },
1013
-
1014
- area(h: WrappedPath): number {
1015
- try {
1016
- const cmds = cmdsViaSvgRoundtrip(h);
1017
- const contours = splitContours(cmds, VERB);
1018
- let total = 0;
1019
- for (const c of contours) {
1020
- const cc = ensureClosed(c, VERB);
1021
- total += Math.abs(approxSignedAreaFromContourCmds(cc, VERB));
1022
- }
1023
- return total;
1024
- } catch {
1025
- return 0.0;
1026
- }
1027
- },
1028
-
1029
- iter_segments(h: WrappedPath): Array<[number, Point[]]> {
1030
- const cmds = cmdsViaSvgRoundtrip(h);
1031
- const preferStrokeCanonical = (h.meta?.moves?.length || 0) === 0;
1032
- const normalized = normalizeSortRotateContours(
1033
- cmds,
1034
- h,
1035
- preferStrokeCanonical
1036
- );
1037
- return cmdsToVerbPoints(normalized, VERB);
1038
- },
1039
- };
1040
- }