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,40 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.flattenDocument = flattenDocument;
4
+ const collapse_1 = require("./stages/collapse");
5
+ const discard_1 = require("./stages/discard");
6
+ const fill_rule_1 = require("./stages/fill-rule");
7
+ const nested_svg_1 = require("./stages/nested-svg");
8
+ const opacity_1 = require("./stages/opacity");
9
+ const shapes_1 = require("./stages/shapes");
10
+ const styles_1 = require("./stages/styles");
11
+ const use_1 = require("./stages/use");
12
+ const validate_1 = require("./stages/validate");
13
+ function flattenDocument(doc, ndigits = 3) {
14
+ doc.syncTree();
15
+ // Discard useless content
16
+ (0, discard_1.removeNonSvgContent)(doc);
17
+ // (processing instructions and comments are dropped at parse time)
18
+ (0, discard_1.removeAnonymousSymbols)(doc);
19
+ (0, discard_1.removeTitleMetaDesc)(doc);
20
+ // Simplify things that simplify in isolation
21
+ (0, styles_1.applyStyleAttributes)(doc);
22
+ (0, nested_svg_1.resolveNestedSvgs)(doc);
23
+ (0, shapes_1.shapesToPaths)(doc);
24
+ (0, shapes_1.expandShorthandCommands)(doc);
25
+ (0, use_1.resolveUse)(doc);
26
+ // Simplify things that do not simplify in isolation
27
+ (0, collapse_1.collapse)(doc);
28
+ // Tidy up
29
+ (0, fill_rule_1.evenoddToNonzeroWinding)(doc);
30
+ (0, opacity_1.normalizeOpacities)(doc);
31
+ (0, shapes_1.absoluteCoordinates)(doc);
32
+ (0, shapes_1.roundFloats)(doc, ndigits);
33
+ // remove empty subpaths *after* rounding
34
+ (0, shapes_1.dropEmptySubpaths)(doc);
35
+ (0, shapes_1.removeUnpaintedShapes)(doc);
36
+ const violations = (0, validate_1.validateFlattened)(doc);
37
+ if (violations.length) {
38
+ throw new Error(violations.join('; '));
39
+ }
40
+ }
@@ -0,0 +1,35 @@
1
+ import type { Pt, Rect } from './geometry';
2
+ export declare class Affine2D {
3
+ readonly a: number;
4
+ readonly b: number;
5
+ readonly c: number;
6
+ readonly d: number;
7
+ readonly e: number;
8
+ readonly f: number;
9
+ constructor(a: number, b: number, c: number, d: number, e: number, f: number);
10
+ private static readonly _identity;
11
+ private static readonly _degenerate;
12
+ static identity(): Affine2D;
13
+ static degenerate(): Affine2D;
14
+ static fromString(rawTransform: string): Affine2D;
15
+ values(): [number, number, number, number, number, number];
16
+ equals(other: Affine2D): boolean;
17
+ toString(): string;
18
+ matMul(other: Affine2D): Affine2D;
19
+ matrix(a: number, b: number, c: number, d: number, e: number, f: number): Affine2D;
20
+ translate(tx: number, ty?: number): Affine2D;
21
+ getTranslate(): [number, number];
22
+ scale(sx: number, sy?: number): Affine2D;
23
+ rotate(a: number, cx?: number, cy?: number): Affine2D;
24
+ skewx(a: number): Affine2D;
25
+ skewy(a: number): Affine2D;
26
+ determinant(): number;
27
+ isDegenerate(): boolean;
28
+ inverse(): Affine2D;
29
+ mapPoint(p: Pt): Pt;
30
+ mapVector(v: Pt): Pt;
31
+ static composeLtr(affines: readonly Affine2D[]): Affine2D;
32
+ private static readonly _ALIGN_VALUES;
33
+ private static readonly _MEET_OR_SLICE;
34
+ static rectToRect(src: Rect, dst: Rect, preserveAspectRatio?: string): Affine2D;
35
+ }
@@ -0,0 +1,221 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Affine2D = void 0;
4
+ const svgPatterns_1 = require("../../utils/svgPatterns");
5
+ const RADIAN_ARG_OPS = new Set(['rotate', 'skewx', 'skewy']);
6
+ const geometry_1 = require("./geometry");
7
+ // 2D affine transform, viewed as a matrix:
8
+ //
9
+ // a c e
10
+ // b d f
11
+ class Affine2D {
12
+ a;
13
+ b;
14
+ c;
15
+ d;
16
+ e;
17
+ f;
18
+ constructor(a, b, c, d, e, f) {
19
+ this.a = a;
20
+ this.b = b;
21
+ this.c = c;
22
+ this.d = d;
23
+ this.e = e;
24
+ this.f = f;
25
+ }
26
+ static _identity = new Affine2D(1, 0, 0, 1, 0, 0);
27
+ static _degenerate = new Affine2D(0, 0, 0, 0, 0, 0);
28
+ static identity() {
29
+ return Affine2D._identity;
30
+ }
31
+ static degenerate() {
32
+ return Affine2D._degenerate;
33
+ }
34
+ static fromString(rawTransform) {
35
+ let transform = Affine2D.identity();
36
+ const re = new RegExp(svgPatterns_1.TRANSFORM_FUNCTION);
37
+ let match;
38
+ while ((match = re.exec(rawTransform)) !== null) {
39
+ const op = match[1].toLowerCase();
40
+ const args = match[2]
41
+ .trim()
42
+ .split(svgPatterns_1.TRANSFORM_ARG_SEPARATOR)
43
+ .map((p) => parseFloat(p));
44
+ if (RADIAN_ARG_OPS.has(op)) {
45
+ args[0] = (args[0] * Math.PI) / 180;
46
+ }
47
+ switch (op) {
48
+ case 'matrix':
49
+ transform = transform.matrix(args[0], args[1], args[2], args[3], args[4], args[5]);
50
+ break;
51
+ case 'translate':
52
+ transform = transform.translate(args[0], args[1]);
53
+ break;
54
+ case 'scale':
55
+ transform = transform.scale(args[0], args[1]);
56
+ break;
57
+ case 'rotate':
58
+ transform = transform.rotate(args[0], args[1], args[2]);
59
+ break;
60
+ case 'skewx':
61
+ transform = transform.skewx(args[0]);
62
+ break;
63
+ case 'skewy':
64
+ transform = transform.skewy(args[0]);
65
+ break;
66
+ }
67
+ }
68
+ return transform;
69
+ }
70
+ values() {
71
+ return [this.a, this.b, this.c, this.d, this.e, this.f];
72
+ }
73
+ equals(other) {
74
+ return (this.a === other.a &&
75
+ this.b === other.b &&
76
+ this.c === other.c &&
77
+ this.d === other.d &&
78
+ this.e === other.e &&
79
+ this.f === other.f);
80
+ }
81
+ toString() {
82
+ const [tx, ty] = this.getTranslate();
83
+ if (this.equals(Affine2D.identity().translate(tx, ty))) {
84
+ return `translate(${[tx, ty].map(geometry_1.ntos).join(', ')})`;
85
+ }
86
+ return `matrix(${this.values().map(geometry_1.ntos).join(' ')})`;
87
+ }
88
+ // product self × other: maps by other before applying self
89
+ matMul(other) {
90
+ return new Affine2D(this.a * other.a + this.c * other.b, this.b * other.a + this.d * other.b, this.a * other.c + this.c * other.d, this.b * other.c + this.d * other.d, this.a * other.e + this.c * other.f + this.e, this.b * other.e + this.d * other.f + this.f);
91
+ }
92
+ matrix(a, b, c, d, e, f) {
93
+ return this.matMul(new Affine2D(a, b, c, d, e, f));
94
+ }
95
+ translate(tx, ty = 0) {
96
+ if (tx === 0 && ty === 0) {
97
+ return this;
98
+ }
99
+ return this.matrix(1, 0, 0, 1, tx, ty);
100
+ }
101
+ getTranslate() {
102
+ return [this.e, this.f];
103
+ }
104
+ scale(sx, sy) {
105
+ if (sy === undefined) {
106
+ sy = sx;
107
+ }
108
+ return this.matrix(sx, 0, 0, sy, 0, 0);
109
+ }
110
+ // angle in radians
111
+ rotate(a, cx = 0.0, cy = 0.0) {
112
+ return this.translate(cx, cy)
113
+ .matrix(Math.cos(a), Math.sin(a), -Math.sin(a), Math.cos(a), 0, 0)
114
+ .translate(-cx, -cy);
115
+ }
116
+ // angle in radians
117
+ skewx(a) {
118
+ return this.matrix(1, 0, Math.tan(a), 1, 0, 0);
119
+ }
120
+ // angle in radians
121
+ skewy(a) {
122
+ return this.matrix(1, Math.tan(a), 0, 1, 0, 0);
123
+ }
124
+ determinant() {
125
+ return this.a * this.d - this.b * this.c;
126
+ }
127
+ isDegenerate() {
128
+ return Math.abs(this.determinant()) <= Number.EPSILON;
129
+ }
130
+ inverse() {
131
+ if (this.equals(Affine2D.identity())) {
132
+ return this;
133
+ }
134
+ else if (this.isDegenerate()) {
135
+ return Affine2D.degenerate();
136
+ }
137
+ const det = this.determinant();
138
+ const a = this.d / det;
139
+ const b = -this.b / det;
140
+ const c = -this.c / det;
141
+ const d = this.a / det;
142
+ const e = -a * this.e - c * this.f;
143
+ const f = -b * this.e - d * this.f;
144
+ return new Affine2D(a, b, c, d, e, f);
145
+ }
146
+ mapPoint(p) {
147
+ return {
148
+ x: this.a * p.x + this.c * p.y + this.e,
149
+ y: this.b * p.x + this.d * p.y + this.f,
150
+ };
151
+ }
152
+ // like mapPoint but treats translation as zero
153
+ mapVector(v) {
154
+ return {
155
+ x: this.a * v.x + this.c * v.y,
156
+ y: this.b * v.x + this.d * v.y,
157
+ };
158
+ }
159
+ // merged transform equivalent to applying transforms left-to-right
160
+ static composeLtr(affines) {
161
+ let result = Affine2D.identity();
162
+ for (let i = affines.length - 1; i >= 0; i--) {
163
+ result = result.matMul(affines[i]);
164
+ }
165
+ return result;
166
+ }
167
+ static _ALIGN_VALUES = new Set([
168
+ 'none',
169
+ 'xminymin',
170
+ 'xminymid',
171
+ 'xminymax',
172
+ 'xmidymin',
173
+ 'xmidymid',
174
+ 'xmidymax',
175
+ 'xmaxymin',
176
+ 'xmaxymid',
177
+ 'xmaxymax',
178
+ ]);
179
+ static _MEET_OR_SLICE = new Set(['meet', 'slice']);
180
+ // scale and translate src Rect onto dst Rect, honoring preserveAspectRatio
181
+ // https://www.w3.org/TR/SVG/coords.html#ComputingAViewportsTransform
182
+ static rectToRect(src, dst, preserveAspectRatio = 'none') {
183
+ if ((0, geometry_1.rectEmpty)(src)) {
184
+ return Affine2D.identity();
185
+ }
186
+ if ((0, geometry_1.rectEmpty)(dst)) {
187
+ return new Affine2D(0, 0, 0, 0, 0, 0);
188
+ }
189
+ let sx = dst.w / src.w;
190
+ let sy = dst.h / src.h;
191
+ const normalized = preserveAspectRatio.toLowerCase().trim();
192
+ const spaceIdx = normalized.indexOf(' ');
193
+ const align = spaceIdx === -1 ? normalized : normalized.slice(0, spaceIdx);
194
+ const meetOrSlice = spaceIdx === -1 ? '' : normalized.slice(spaceIdx + 1).trim();
195
+ if (!Affine2D._ALIGN_VALUES.has(align) ||
196
+ (meetOrSlice && !Affine2D._MEET_OR_SLICE.has(meetOrSlice))) {
197
+ throw new Error(`Invalid preserveAspectRatio: ${preserveAspectRatio}`);
198
+ }
199
+ if (align !== 'none') {
200
+ sx = sy = meetOrSlice.includes('slice')
201
+ ? Math.max(sx, sy)
202
+ : Math.min(sx, sy);
203
+ }
204
+ let tx = dst.x - src.x * sx;
205
+ let ty = dst.y - src.y * sy;
206
+ if (align.includes('xmid')) {
207
+ tx += (dst.w - src.w * sx) / 2;
208
+ }
209
+ else if (align.includes('xmax')) {
210
+ tx += dst.w - src.w * sx;
211
+ }
212
+ if (align.includes('ymid')) {
213
+ ty += (dst.h - src.h * sy) / 2;
214
+ }
215
+ else if (align.includes('ymax')) {
216
+ ty += dst.h - src.h * sy;
217
+ }
218
+ return new Affine2D(sx, 0, 0, sy, tx, ty);
219
+ }
220
+ }
221
+ exports.Affine2D = Affine2D;
@@ -17,4 +17,5 @@ export declare function compileTtfFromGlyphs(opts: {
17
17
  ascent: number;
18
18
  descent: number;
19
19
  lineGap?: number;
20
- }): Promise<void>;
20
+ }): Promise<Buffer>;
21
+ export declare function compileWoff2FromTtf(ttfBuffer: Buffer): Promise<Buffer>;
@@ -5,12 +5,18 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.parseCompileTtfFromGlyphsError = parseCompileTtfFromGlyphsError;
7
7
  exports.compileTtfFromGlyphs = compileTtfFromGlyphs;
8
+ exports.compileWoff2FromTtf = compileWoff2FromTtf;
8
9
  const node_fs_1 = __importDefault(require("node:fs"));
9
10
  const node_path_1 = __importDefault(require("node:path"));
10
- const metrics_js_1 = require("./metrics.js");
11
+ const metrics_1 = require("./metrics");
11
12
  const svg2ttf_1 = __importDefault(require("svg2ttf"));
13
+ const fonteditor_core_1 = require("fonteditor-core");
14
+ const svgPatterns_1 = require("../../utils/svgPatterns");
15
+ const dom_1 = require("../flatten/dom");
16
+ const quadratic_1 = require("./quadratic");
17
+ const QUADRATIC_ERROR_BOUND_EM = 1 / 512;
12
18
  function escapeXml(s) {
13
- return s.replace(/&/g, '&amp;').replace(/"/g, '&quot;');
19
+ return s.replace(svgPatterns_1.XML_AMP, '&amp;').replace(svgPatterns_1.XML_QUOT, '&quot;');
14
20
  }
15
21
  /**
16
22
  * Build an SVG font XML string from pre-transformed glyph data.
@@ -20,11 +26,12 @@ function buildSvgFontXml(opts) {
20
26
  const glyphLines = glyphs.map((g) => {
21
27
  const hex = g.codepoint.toString(16);
22
28
  const name = `u${hex.padStart(4, '0')}`;
23
- return `<glyph glyph-name="${name}" unicode="&#x${hex};" horiz-adv-x="${g.advanceWidth}" d="${escapeXml(g.d)}"/>`;
29
+ const d = (0, quadratic_1.toQuadraticPath)(g.d, upm * QUADRATIC_ERROR_BOUND_EM);
30
+ return `<glyph glyph-name="${name}" unicode="&#x${hex};" horiz-adv-x="${g.advanceWidth}" d="${escapeXml(d)}"/>`;
24
31
  });
25
32
  return `<?xml version="1.0" standalone="no"?>
26
33
  <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
27
- <svg xmlns="http://www.w3.org/2000/svg">
34
+ <svg xmlns="${dom_1.SVG_NS}">
28
35
  <defs>
29
36
  <font id="${escapeXml(fontName)}" horiz-adv-x="${upm}">
30
37
  <font-face font-family="${escapeXml(fontName)}" units-per-em="${upm}" ascent="${ascent}" descent="${-Math.abs(descent)}"/>
@@ -36,7 +43,7 @@ ${glyphLines.join('\n')}
36
43
  }
37
44
  function parseCompileTtfFromGlyphsError(err, codepointToIcon) {
38
45
  const msg = err instanceof Error ? err.message : String(err);
39
- const cpMatch = msg.match(/glyph\s+"u([0-9a-fA-F]+)"/);
46
+ const cpMatch = msg.match(svgPatterns_1.GLYPH_CODEPOINT);
40
47
  if (cpMatch) {
41
48
  const cp = parseInt(cpMatch[1], 16);
42
49
  const iconName = codepointToIcon.get(cp);
@@ -63,9 +70,16 @@ async function compileTtfFromGlyphs(opts) {
63
70
  ascent,
64
71
  descent,
65
72
  });
66
- const ttfRaw = (0, svg2ttf_1.default)(svgFontString);
73
+ const ttfRaw = (0, svg2ttf_1.default)(svgFontString, { ts: 0 });
67
74
  const rawBuf = Buffer.from(ttfRaw.buffer);
68
- const fixedBuf = (0, metrics_js_1.forceTtfMetrics)(rawBuf, upm, ascent, descent, lineGap);
75
+ const fixedBuf = (0, metrics_1.forceTtfMetrics)(rawBuf, upm, ascent, descent, lineGap);
69
76
  node_fs_1.default.mkdirSync(node_path_1.default.dirname(outTtfPath), { recursive: true });
70
77
  node_fs_1.default.writeFileSync(outTtfPath, fixedBuf);
78
+ return fixedBuf;
79
+ }
80
+ let woff2Ready;
81
+ async function compileWoff2FromTtf(ttfBuffer) {
82
+ woff2Ready ??= fonteditor_core_1.woff2.init();
83
+ await woff2Ready;
84
+ return Buffer.from(fonteditor_core_1.woff2.encode(ttfBuffer));
71
85
  }
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.forceTtfMetrics = forceTtfMetrics;
4
4
  const fonteditor_core_1 = require("fonteditor-core");
5
+ const FIXED_TIMESTAMP_MS = Date.UTC(1970, 0, 1, 0, 0, 1);
5
6
  function forceTtfMetrics(ttfBuffer, upm, ascent, descent, lineGap) {
6
7
  const font = fonteditor_core_1.Font.create(ttfBuffer, {
7
8
  type: 'ttf',
@@ -27,6 +28,12 @@ function forceTtfMetrics(ttfBuffer, upm, ascent, descent, lineGap) {
27
28
  // misaligned vertically. The bitwise OR preserves all other existing style flags
28
29
  // (italic, bold, etc.) while ensuring this bit is always on.
29
30
  data['OS/2'].fsSelection = (data['OS/2'].fsSelection || 0) | (1 << 7);
31
+ data.head.created = FIXED_TIMESTAMP_MS;
32
+ data.head.modified = FIXED_TIMESTAMP_MS;
33
+ data.post.format = 3;
34
+ for (const glyph of data.glyf) {
35
+ delete glyph.name;
36
+ }
30
37
  font.set(data);
31
38
  const out = font.write({ type: 'ttf', hinting: false });
32
39
  return Buffer.from(out);
@@ -0,0 +1 @@
1
+ export declare function toQuadraticPath(d: string, errorBound: number): string;
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.toQuadraticPath = toQuadraticPath;
4
+ const cubic2quad = require('cubic2quad');
5
+ const COMMAND = /([MLQCZ])([^MLQCZ]*)/g;
6
+ const NUMBER = /-?(?:\d+\.?\d*|\.\d+)(?:e[-+]?\d+)?/gi;
7
+ function toQuadraticPath(d, errorBound) {
8
+ const out = [];
9
+ let x = 0;
10
+ let y = 0;
11
+ for (const [, cmd, rawArgs] of d.matchAll(COMMAND)) {
12
+ const args = (rawArgs.match(NUMBER) ?? []).map(Number);
13
+ if (cmd === 'C') {
14
+ for (let i = 0; i + 5 < args.length; i += 6) {
15
+ const quads = cubic2quad(x, y, args[i], args[i + 1], args[i + 2], args[i + 3], args[i + 4], args[i + 5], errorBound);
16
+ for (let j = 2; j + 3 < quads.length; j += 4) {
17
+ out.push(`Q${quads[j]} ${quads[j + 1]} ${quads[j + 2]} ${quads[j + 3]}`);
18
+ }
19
+ x = args[i + 4];
20
+ y = args[i + 5];
21
+ }
22
+ continue;
23
+ }
24
+ out.push(`${cmd}${rawArgs.trim()}`);
25
+ if (cmd !== 'Z' && args.length >= 2) {
26
+ x = args[args.length - 2];
27
+ y = args[args.length - 1];
28
+ }
29
+ }
30
+ return out.join('');
31
+ }
@@ -0,0 +1,7 @@
1
+ import type { NanoLogger } from '../types';
2
+ import type { ParsedPath } from './parse';
3
+ /**
4
+ * Merge consecutive same-color paths into single compound paths.
5
+ * Preserves z-order: only merges runs of adjacent paths with identical fill color.
6
+ */
7
+ export declare function mergeSameColorPaths(paths: ParsedPath[], logger?: NanoLogger): ParsedPath[];
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.mergeSameColorPaths = mergeSameColorPaths;
4
+ /**
5
+ * Concatenate multiple SVG path `d` strings into a single compound path.
6
+ * This preserves the exact geometry of each path (no boolean operations)
7
+ * while combining them into one glyph. Under nonzero winding, this renders
8
+ * identically to drawing each path separately with the same color.
9
+ */
10
+ function concatPathDs(ds) {
11
+ if (ds.length === 0)
12
+ return null;
13
+ if (ds.length === 1)
14
+ return ds[0];
15
+ return ds.join(' ');
16
+ }
17
+ /**
18
+ * Merge consecutive same-color paths into single compound paths.
19
+ * Preserves z-order: only merges runs of adjacent paths with identical fill color.
20
+ */
21
+ function mergeSameColorPaths(paths, logger) {
22
+ if (paths.length <= 1)
23
+ return paths;
24
+ const result = [];
25
+ let i = 0;
26
+ while (i < paths.length) {
27
+ const fill = paths[i].fill;
28
+ // Find consecutive run of same fill that are all mergeable.
29
+ // Paths converted from evenodd have compound hole structure and must not
30
+ // be merged — their CW hole contours would cancel CCW contours from
31
+ // adjacent paths, producing incorrect fill.
32
+ let j = i + 1;
33
+ if (!paths[i].noMerge) {
34
+ while (j < paths.length &&
35
+ paths[j].fill === fill &&
36
+ !paths[j].noMerge) {
37
+ j++;
38
+ }
39
+ }
40
+ if (j - i === 1) {
41
+ result.push(paths[i]);
42
+ }
43
+ else {
44
+ const group = paths.slice(i, j);
45
+ const merged = concatPathDs(group.map((p) => p.d));
46
+ if (merged) {
47
+ logger?.info(` ⊕ Merged ${group.length} same-color paths (fill=${fill})`);
48
+ result.push({ d: merged, fill });
49
+ }
50
+ else {
51
+ result.push(...group);
52
+ }
53
+ }
54
+ i = j;
55
+ }
56
+ return result;
57
+ }
@@ -0,0 +1,26 @@
1
+ import { type Element } from '@xmldom/xmldom';
2
+ export type ParsedPath = {
3
+ d: string;
4
+ fill: string | null;
5
+ fillRule?: 'evenodd';
6
+ noMerge?: boolean;
7
+ };
8
+ export type ParsedFlatSvg = {
9
+ viewBox: [number, number, number, number];
10
+ paths: ParsedPath[];
11
+ };
12
+ export declare function calculateOpColor(fill: string | null, opacity: number, el: Element): `rgba(${number},${number},${number},${number})`;
13
+ /**
14
+ * If a flattened path lost its initial moveto (e.g. an empty `Mx y z`
15
+ * subpath was dropped), prepend `M` using the path's last coordinate pair.
16
+ * For closed icon shapes the endpoint equals the start point.
17
+ */
18
+ export declare function sanitizePathData(d: string): {
19
+ d: string;
20
+ sanitized: boolean;
21
+ };
22
+ export declare function parseFlattenedSvg(flattenedSvg: string, options?: {
23
+ onSanitize?: (original: string) => void;
24
+ onMissingViewBox?: (assumed: [number, number, number, number]) => void;
25
+ }): ParsedFlatSvg;
26
+ export declare function shouldSkipPath(d: string, fill: string | null): boolean;
@@ -1,16 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parsePath = void 0;
4
3
  exports.calculateOpColor = calculateOpColor;
5
4
  exports.sanitizePathData = sanitizePathData;
6
5
  exports.parseFlattenedSvg = parseFlattenedSvg;
7
6
  exports.shouldSkipPath = shouldSkipPath;
8
- exports.validateSvg = validateSvg;
9
- exports.extractOriginalEvenoddDs = extractOriginalEvenoddDs;
10
- exports.restoreOriginalEvenoddDs = restoreOriginalEvenoddDs;
11
- exports.preprocessSvg = preprocessSvg;
12
7
  const xmldom_1 = require("@xmldom/xmldom");
13
8
  const parse_1 = require("../../utils/parse");
9
+ const svgPatterns_1 = require("../../utils/svgPatterns");
14
10
  // if the fill is implicit, walk ancestors for the first explicit fill value
15
11
  function resolveInheritedFill(el) {
16
12
  let current = el.parentElement;
@@ -30,18 +26,18 @@ function calculateOpColor(fill, opacity, el) {
30
26
  return `rgba(${r},${g},${b},${finalAlpha})`;
31
27
  }
32
28
  /**
33
- * If a flattened path lost its initial moveto (e.g. picosvg dropped an empty
34
- * `Mx y z` subpath), prepend `M` using the path's last coordinate pair.
29
+ * If a flattened path lost its initial moveto (e.g. an empty `Mx y z`
30
+ * subpath was dropped), prepend `M` using the path's last coordinate pair.
35
31
  * For closed icon shapes the endpoint equals the start point.
36
32
  */
37
33
  function sanitizePathData(d) {
38
34
  const trimmed = d.trim();
39
- if (!trimmed || /^[Mm]/.test(trimmed)) {
35
+ if (!trimmed || svgPatterns_1.SVG_MOVE_PREFIX.test(trimmed)) {
40
36
  return { d: trimmed, sanitized: false };
41
37
  }
42
38
  // Strip trailing close commands, then grab the last two numbers as x,y
43
- const withoutClose = trimmed.replace(/[Zz]\s*$/, '');
44
- const nums = withoutClose.match(/-?\d+(?:\.\d+)?/g);
39
+ const withoutClose = trimmed.replace(svgPatterns_1.SVG_TRAILING_CLOSE, '');
40
+ const nums = withoutClose.match(svgPatterns_1.SVG_NUMBER);
45
41
  if (!nums || nums.length < 2) {
46
42
  return { d: trimmed, sanitized: false };
47
43
  }
@@ -54,7 +50,7 @@ const parsePath = (p) => {
54
50
  const op = p.getAttribute('opacity');
55
51
  const fillOp = p.getAttribute('fill-opacity');
56
52
  const fill = p.getAttribute('fill');
57
- // picosvg may drop fill-rule but preserve clip-rule; treat either as evenodd
53
+ // flattening may drop fill-rule but preserve clip-rule; treat either as evenodd
58
54
  const fillRule = p.getAttribute('fill-rule') === 'evenodd' ||
59
55
  p.getAttribute('clip-rule') === 'evenodd'
60
56
  ? 'evenodd'
@@ -75,20 +71,27 @@ const parsePath = (p) => {
75
71
  fillRule,
76
72
  };
77
73
  };
78
- exports.parsePath = parsePath;
79
74
  function parseFlattenedSvg(flattenedSvg, options) {
80
75
  const doc = new xmldom_1.DOMParser().parseFromString(flattenedSvg, 'image/svg+xml');
81
76
  const svgEl = doc.documentElement;
82
77
  const viewBoxRaw = svgEl
83
78
  ?.getAttribute('viewBox')
84
- ?.split(/\s+/)
85
- .map(Number) ?? [0, 0, 100, 100];
86
- const viewBox = viewBoxRaw.length === 4 && viewBoxRaw.every(Number.isFinite)
87
- ? [viewBoxRaw[0], viewBoxRaw[1], viewBoxRaw[2], viewBoxRaw[3]]
88
- : [0, 0, 100, 100];
79
+ ?.split(svgPatterns_1.WHITESPACE)
80
+ .map(Number);
81
+ let viewBox;
82
+ if (viewBoxRaw?.length === 4 && viewBoxRaw.every(Number.isFinite)) {
83
+ viewBox = [viewBoxRaw[0], viewBoxRaw[1], viewBoxRaw[2], viewBoxRaw[3]];
84
+ }
85
+ else {
86
+ const width = parseFloat(svgEl?.getAttribute('width') ?? '');
87
+ const height = parseFloat(svgEl?.getAttribute('height') ?? '');
88
+ viewBox =
89
+ width > 0 && height > 0 ? [0, 0, width, height] : [0, 0, 100, 100];
90
+ options?.onMissingViewBox?.(viewBox);
91
+ }
89
92
  const pathEls = svgEl ? Array.from(svgEl.getElementsByTagName('path')) : [];
90
93
  const paths = pathEls
91
- .map(exports.parsePath)
94
+ .map(parsePath)
92
95
  .filter((p) => p.d.trim() !== '')
93
96
  .map((p) => {
94
97
  const { d, sanitized } = sanitizePathData(p.d);
@@ -104,62 +107,3 @@ function shouldSkipPath(d, fill) {
104
107
  const f = (fill ?? '').trim().toLowerCase();
105
108
  return f === 'transparent' || f === 'none';
106
109
  }
107
- function validateSvg(content) {
108
- if (/<mask[\s>]/i.test(content)) {
109
- return { valid: false, reason: '<mask> is not supported yet' };
110
- }
111
- if (/<filter[\s>]/i.test(content)) {
112
- return { valid: false, reason: '<filter> is not supported yet' };
113
- }
114
- if (/<image[\s>]/i.test(content)) {
115
- return {
116
- valid: false,
117
- reason: 'embedded raster <image> is not supported yet',
118
- };
119
- }
120
- return { valid: true };
121
- }
122
- /**
123
- * Extract the original `d` strings of evenodd paths from the raw SVG
124
- * BEFORE picosvg processes it. Picosvg's simplify (via our PathKit shim)
125
- * can drop contours from multi-subpath evenodd paths, so we preserve
126
- * the originals and apply our own winding conversion later.
127
- *
128
- * Returns one `d` string per evenodd path, in document order.
129
- */
130
- function extractOriginalEvenoddDs(svgContent) {
131
- if (!/<[^>]*fill-rule\s*=\s*["']evenodd/i.test(svgContent)) {
132
- return [];
133
- }
134
- const doc = new xmldom_1.DOMParser().parseFromString(svgContent, 'image/svg+xml');
135
- return Array.from(doc.getElementsByTagName('path')).reduce((acc, el) => {
136
- const isEvenOdd = el.getAttribute('fill-rule') === 'evenodd' ||
137
- el.getAttribute('clip-rule') === 'evenodd';
138
- if (!isEvenOdd)
139
- return acc;
140
- const d = el.getAttribute('d');
141
- if (d !== null && d !== '')
142
- acc.push(d);
143
- return acc;
144
- }, []);
145
- }
146
- /**
147
- * Replace picosvg's (potentially damaged) evenodd path data with the
148
- * preserved originals. Matches by position: the Nth evenodd path in
149
- * the parsed output gets the Nth original `d` string.
150
- */
151
- function restoreOriginalEvenoddDs(paths, originalDs) {
152
- let oi = 0;
153
- for (const p of paths) {
154
- if (p.fillRule === 'evenodd' && oi < originalDs.length) {
155
- p.d = originalDs[oi];
156
- oi++;
157
- }
158
- }
159
- }
160
- // ensure the svg has a xmlns attribute
161
- function preprocessSvg(content) {
162
- if (/xmlns\s*=/.test(content))
163
- return content;
164
- return content.replace(/<svg\b/, '<svg xmlns="http://www.w3.org/2000/svg"');
165
- }