@iksnerd/blazon 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (503) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +264 -2
  3. package/THIRD-PARTY-NOTICES.md +60 -0
  4. package/bin/blazon.js +4 -0
  5. package/dist/builder/site-builder.d.ts +10 -0
  6. package/dist/builder/site-builder.d.ts.map +1 -0
  7. package/dist/chunks/site-builder-vpzUWoiA.js +13777 -0
  8. package/dist/cli/commands/approvals.d.ts +8 -0
  9. package/dist/cli/commands/approvals.d.ts.map +1 -0
  10. package/dist/cli/commands/build.d.ts +8 -0
  11. package/dist/cli/commands/build.d.ts.map +1 -0
  12. package/dist/cli/commands/check.d.ts +33 -0
  13. package/dist/cli/commands/check.d.ts.map +1 -0
  14. package/dist/cli/commands/cwd.d.ts +14 -0
  15. package/dist/cli/commands/cwd.d.ts.map +1 -0
  16. package/dist/cli/commands/dev.d.ts +5 -0
  17. package/dist/cli/commands/dev.d.ts.map +1 -0
  18. package/dist/cli/commands/doctor.d.ts +34 -0
  19. package/dist/cli/commands/doctor.d.ts.map +1 -0
  20. package/dist/cli/commands/drift.d.ts +11 -0
  21. package/dist/cli/commands/drift.d.ts.map +1 -0
  22. package/dist/cli/commands/explain.d.ts +5 -0
  23. package/dist/cli/commands/explain.d.ts.map +1 -0
  24. package/dist/cli/commands/init.d.ts +46 -0
  25. package/dist/cli/commands/init.d.ts.map +1 -0
  26. package/dist/cli/commands/mcp-check.d.ts +57 -0
  27. package/dist/cli/commands/mcp-check.d.ts.map +1 -0
  28. package/dist/cli/commands/mcp.d.ts +13 -0
  29. package/dist/cli/commands/mcp.d.ts.map +1 -0
  30. package/dist/cli/commands/pin.d.ts +7 -0
  31. package/dist/cli/commands/pin.d.ts.map +1 -0
  32. package/dist/cli/commands/plugin.d.ts +32 -0
  33. package/dist/cli/commands/plugin.d.ts.map +1 -0
  34. package/dist/cli/commands/preview.d.ts +5 -0
  35. package/dist/cli/commands/preview.d.ts.map +1 -0
  36. package/dist/cli/commands/tokens.d.ts +5 -0
  37. package/dist/cli/commands/tokens.d.ts.map +1 -0
  38. package/dist/cli/errors.d.ts +53 -0
  39. package/dist/cli/errors.d.ts.map +1 -0
  40. package/dist/cli/handlers/brand.d.ts +7 -0
  41. package/dist/cli/handlers/brand.d.ts.map +1 -0
  42. package/dist/cli/handlers/can.d.ts +7 -0
  43. package/dist/cli/handlers/can.d.ts.map +1 -0
  44. package/dist/cli/handlers/fonts.d.ts +4 -0
  45. package/dist/cli/handlers/fonts.d.ts.map +1 -0
  46. package/dist/cli/handlers/get.d.ts +7 -0
  47. package/dist/cli/handlers/get.d.ts.map +1 -0
  48. package/dist/cli/handlers/index.d.ts +8 -0
  49. package/dist/cli/handlers/index.d.ts.map +1 -0
  50. package/dist/cli/handlers/list.d.ts +7 -0
  51. package/dist/cli/handlers/list.d.ts.map +1 -0
  52. package/dist/cli/handlers/logo.d.ts +4 -0
  53. package/dist/cli/handlers/logo.d.ts.map +1 -0
  54. package/dist/cli/handlers/rules.d.ts +10 -0
  55. package/dist/cli/handlers/rules.d.ts.map +1 -0
  56. package/dist/cli/handlers/types.d.ts +17 -0
  57. package/dist/cli/handlers/types.d.ts.map +1 -0
  58. package/dist/cli/help.d.ts +18 -0
  59. package/dist/cli/help.d.ts.map +1 -0
  60. package/dist/cli/index.d.ts +2 -0
  61. package/dist/cli/index.d.ts.map +1 -0
  62. package/dist/cli/index.js +3850 -0
  63. package/dist/cli/init-flow.d.ts +24 -0
  64. package/dist/cli/init-flow.d.ts.map +1 -0
  65. package/dist/cli/init-ui.d.ts +20 -0
  66. package/dist/cli/init-ui.d.ts.map +1 -0
  67. package/dist/cli/json.d.ts +18 -0
  68. package/dist/cli/json.d.ts.map +1 -0
  69. package/dist/cli/operations.d.ts +11 -0
  70. package/dist/cli/operations.d.ts.map +1 -0
  71. package/dist/cli/options.d.ts +8 -0
  72. package/dist/cli/options.d.ts.map +1 -0
  73. package/dist/cli/project.d.ts +8 -0
  74. package/dist/cli/project.d.ts.map +1 -0
  75. package/dist/cli/read.d.ts +13 -0
  76. package/dist/cli/read.d.ts.map +1 -0
  77. package/dist/cli/where.d.ts +10 -0
  78. package/dist/cli/where.d.ts.map +1 -0
  79. package/dist/core/assets/categories.d.ts +47 -0
  80. package/dist/core/assets/categories.d.ts.map +1 -0
  81. package/dist/core/assets/fields.d.ts +12 -0
  82. package/dist/core/assets/fields.d.ts.map +1 -0
  83. package/dist/core/assets/image-size.d.ts +10 -0
  84. package/dist/core/assets/image-size.d.ts.map +1 -0
  85. package/dist/core/assets/measure.d.ts +22 -0
  86. package/dist/core/assets/measure.d.ts.map +1 -0
  87. package/dist/core/assets/scanner.d.ts +26 -0
  88. package/dist/core/assets/scanner.d.ts.map +1 -0
  89. package/dist/core/assets/sidecar.d.ts +22 -0
  90. package/dist/core/assets/sidecar.d.ts.map +1 -0
  91. package/dist/core/blazon-pin.d.ts +36 -0
  92. package/dist/core/blazon-pin.d.ts.map +1 -0
  93. package/dist/core/brand/export.d.ts +128 -0
  94. package/dist/core/brand/export.d.ts.map +1 -0
  95. package/dist/core/brand/schema.d.ts +1000 -0
  96. package/dist/core/brand/schema.d.ts.map +1 -0
  97. package/dist/core/brand-theme.d.ts +16 -0
  98. package/dist/core/brand-theme.d.ts.map +1 -0
  99. package/dist/core/checker/approvals.d.ts +15 -0
  100. package/dist/core/checker/approvals.d.ts.map +1 -0
  101. package/dist/core/checker/cascade.d.ts +8 -0
  102. package/dist/core/checker/cascade.d.ts.map +1 -0
  103. package/dist/core/checker/catalogue.d.ts +593 -0
  104. package/dist/core/checker/catalogue.d.ts.map +1 -0
  105. package/dist/core/checker/contrast.d.ts +30 -0
  106. package/dist/core/checker/contrast.d.ts.map +1 -0
  107. package/dist/core/checker/duplicates.d.ts +3 -0
  108. package/dist/core/checker/duplicates.d.ts.map +1 -0
  109. package/dist/core/checker/fixes.d.ts +6 -0
  110. package/dist/core/checker/fixes.d.ts.map +1 -0
  111. package/dist/core/checker/font-meta.d.ts +8 -0
  112. package/dist/core/checker/font-meta.d.ts.map +1 -0
  113. package/dist/core/checker/index.d.ts +23 -0
  114. package/dist/core/checker/index.d.ts.map +1 -0
  115. package/dist/core/checker/location.d.ts +7 -0
  116. package/dist/core/checker/location.d.ts.map +1 -0
  117. package/dist/core/checker/logo-rules.d.ts +19 -0
  118. package/dist/core/checker/logo-rules.d.ts.map +1 -0
  119. package/dist/core/checker/logo-surfaces.d.ts +7 -0
  120. package/dist/core/checker/logo-surfaces.d.ts.map +1 -0
  121. package/dist/core/checker/page-tokens.d.ts +5 -0
  122. package/dist/core/checker/page-tokens.d.ts.map +1 -0
  123. package/dist/core/checker/print.d.ts +9 -0
  124. package/dist/core/checker/print.d.ts.map +1 -0
  125. package/dist/core/checker/proportion.d.ts +3 -0
  126. package/dist/core/checker/proportion.d.ts.map +1 -0
  127. package/dist/core/checker/review.d.ts +40 -0
  128. package/dist/core/checker/review.d.ts.map +1 -0
  129. package/dist/core/checker/source.d.ts +4 -0
  130. package/dist/core/checker/source.d.ts.map +1 -0
  131. package/dist/core/checker/spdx.d.ts +8 -0
  132. package/dist/core/checker/spdx.d.ts.map +1 -0
  133. package/dist/core/checker/tier.d.ts +3 -0
  134. package/dist/core/checker/tier.d.ts.map +1 -0
  135. package/dist/core/checker/usage.d.ts +4 -0
  136. package/dist/core/checker/usage.d.ts.map +1 -0
  137. package/dist/core/checker/variables.d.ts +8 -0
  138. package/dist/core/checker/variables.d.ts.map +1 -0
  139. package/dist/core/colors.d.ts +10 -0
  140. package/dist/core/colors.d.ts.map +1 -0
  141. package/dist/core/config/defaults.d.ts +3 -0
  142. package/dist/core/config/defaults.d.ts.map +1 -0
  143. package/dist/core/config/index.d.ts +15 -0
  144. package/dist/core/config/index.d.ts.map +1 -0
  145. package/dist/core/config/validate.d.ts +21 -0
  146. package/dist/core/config/validate.d.ts.map +1 -0
  147. package/dist/core/config/vocabulary.d.ts +10 -0
  148. package/dist/core/config/vocabulary.d.ts.map +1 -0
  149. package/dist/core/confine.d.ts +25 -0
  150. package/dist/core/confine.d.ts.map +1 -0
  151. package/dist/core/docs/directives.d.ts +152 -0
  152. package/dist/core/docs/directives.d.ts.map +1 -0
  153. package/dist/core/docs/parser.d.ts +7 -0
  154. package/dist/core/docs/parser.d.ts.map +1 -0
  155. package/dist/core/docs/sections.d.ts +11 -0
  156. package/dist/core/docs/sections.d.ts.map +1 -0
  157. package/dist/core/drift/compare.d.ts +30 -0
  158. package/dist/core/drift/compare.d.ts.map +1 -0
  159. package/dist/core/drift/read.d.ts +22 -0
  160. package/dist/core/drift/read.d.ts.map +1 -0
  161. package/dist/core/email-signature.d.ts +35 -0
  162. package/dist/core/email-signature.d.ts.map +1 -0
  163. package/dist/core/emit.d.ts +22 -0
  164. package/dist/core/emit.d.ts.map +1 -0
  165. package/dist/core/fonts.d.ts +43 -0
  166. package/dist/core/fonts.d.ts.map +1 -0
  167. package/dist/core/icons/icon-sets.d.ts +22 -0
  168. package/dist/core/icons/icon-sets.d.ts.map +1 -0
  169. package/dist/core/index.d.ts +9 -0
  170. package/dist/core/index.d.ts.map +1 -0
  171. package/dist/core/init/answers.d.ts +45 -0
  172. package/dist/core/init/answers.d.ts.map +1 -0
  173. package/dist/core/init/from-site/apply.d.ts +7 -0
  174. package/dist/core/init/from-site/apply.d.ts.map +1 -0
  175. package/dist/core/init/from-site/clean-colors.d.ts +21 -0
  176. package/dist/core/init/from-site/clean-colors.d.ts.map +1 -0
  177. package/dist/core/init/from-site/colors.d.ts +10 -0
  178. package/dist/core/init/from-site/colors.d.ts.map +1 -0
  179. package/dist/core/init/from-site/context.d.ts +24 -0
  180. package/dist/core/init/from-site/context.d.ts.map +1 -0
  181. package/dist/core/init/from-site/fonts.d.ts +10 -0
  182. package/dist/core/init/from-site/fonts.d.ts.map +1 -0
  183. package/dist/core/init/from-site/html.d.ts +10 -0
  184. package/dist/core/init/from-site/html.d.ts.map +1 -0
  185. package/dist/core/init/from-site/index.d.ts +6 -0
  186. package/dist/core/init/from-site/index.d.ts.map +1 -0
  187. package/dist/core/init/from-site/inspect.d.ts +4 -0
  188. package/dist/core/init/from-site/inspect.d.ts.map +1 -0
  189. package/dist/core/init/from-site/logo.d.ts +20 -0
  190. package/dist/core/init/from-site/logo.d.ts.map +1 -0
  191. package/dist/core/init/from-site/sections/colors.d.ts +4 -0
  192. package/dist/core/init/from-site/sections/colors.d.ts.map +1 -0
  193. package/dist/core/init/from-site/sections/config.d.ts +10 -0
  194. package/dist/core/init/from-site/sections/config.d.ts.map +1 -0
  195. package/dist/core/init/from-site/sections/directives.d.ts +3 -0
  196. package/dist/core/init/from-site/sections/directives.d.ts.map +1 -0
  197. package/dist/core/init/from-site/sections/fonts.d.ts +8 -0
  198. package/dist/core/init/from-site/sections/fonts.d.ts.map +1 -0
  199. package/dist/core/init/from-site/sections/intro.d.ts +4 -0
  200. package/dist/core/init/from-site/sections/intro.d.ts.map +1 -0
  201. package/dist/core/init/from-site/sections/logo.d.ts +9 -0
  202. package/dist/core/init/from-site/sections/logo.d.ts.map +1 -0
  203. package/dist/core/init/from-site/sections/placeholder.d.ts +5 -0
  204. package/dist/core/init/from-site/sections/placeholder.d.ts.map +1 -0
  205. package/dist/core/init/from-site/tree.d.ts +14 -0
  206. package/dist/core/init/from-site/tree.d.ts.map +1 -0
  207. package/dist/core/init/from-site/types.d.ts +37 -0
  208. package/dist/core/init/from-site/types.d.ts.map +1 -0
  209. package/dist/core/init/palette.d.ts +34 -0
  210. package/dist/core/init/palette.d.ts.map +1 -0
  211. package/dist/core/init/prompts.d.ts +78 -0
  212. package/dist/core/init/prompts.d.ts.map +1 -0
  213. package/dist/core/init/shared/google-fonts.d.ts +4 -0
  214. package/dist/core/init/shared/google-fonts.d.ts.map +1 -0
  215. package/dist/core/init/shared/hex.d.ts +6 -0
  216. package/dist/core/init/shared/hex.d.ts.map +1 -0
  217. package/dist/core/init/shared/svg.d.ts +3 -0
  218. package/dist/core/init/shared/svg.d.ts.map +1 -0
  219. package/dist/core/init/vocabulary.d.ts +42 -0
  220. package/dist/core/init/vocabulary.d.ts.map +1 -0
  221. package/dist/core/inputs.d.ts +25 -0
  222. package/dist/core/inputs.d.ts.map +1 -0
  223. package/dist/core/logo/lockup.d.ts +54 -0
  224. package/dist/core/logo/lockup.d.ts.map +1 -0
  225. package/dist/core/logo.d.ts +23 -0
  226. package/dist/core/logo.d.ts.map +1 -0
  227. package/dist/core/mcp-config.d.ts +65 -0
  228. package/dist/core/mcp-config.d.ts.map +1 -0
  229. package/dist/core/operations/check.d.ts +8 -0
  230. package/dist/core/operations/check.d.ts.map +1 -0
  231. package/dist/core/operations/index.d.ts +7 -0
  232. package/dist/core/operations/index.d.ts.map +1 -0
  233. package/dist/core/operations/limits.d.ts +6 -0
  234. package/dist/core/operations/limits.d.ts.map +1 -0
  235. package/dist/core/operations/list.d.ts +8 -0
  236. package/dist/core/operations/list.d.ts.map +1 -0
  237. package/dist/core/operations/project.d.ts +10 -0
  238. package/dist/core/operations/project.d.ts.map +1 -0
  239. package/dist/core/operations/types.d.ts +96 -0
  240. package/dist/core/operations/types.d.ts.map +1 -0
  241. package/dist/core/operations/validate.d.ts +4 -0
  242. package/dist/core/operations/validate.d.ts.map +1 -0
  243. package/dist/core/order.d.ts +9 -0
  244. package/dist/core/order.d.ts.map +1 -0
  245. package/dist/core/outputs.d.ts +22 -0
  246. package/dist/core/outputs.d.ts.map +1 -0
  247. package/dist/core/package-name.d.ts +3 -0
  248. package/dist/core/package-name.d.ts.map +1 -0
  249. package/dist/core/package-root.d.ts +3 -0
  250. package/dist/core/package-root.d.ts.map +1 -0
  251. package/dist/core/plugin-name.d.ts +27 -0
  252. package/dist/core/plugin-name.d.ts.map +1 -0
  253. package/dist/core/preflight.d.ts +10 -0
  254. package/dist/core/preflight.d.ts.map +1 -0
  255. package/dist/core/read/can.d.ts +44 -0
  256. package/dist/core/read/can.d.ts.map +1 -0
  257. package/dist/core/read/fonts.d.ts +47 -0
  258. package/dist/core/read/fonts.d.ts.map +1 -0
  259. package/dist/core/read/index.d.ts +8 -0
  260. package/dist/core/read/index.d.ts.map +1 -0
  261. package/dist/core/read/list.d.ts +28 -0
  262. package/dist/core/read/list.d.ts.map +1 -0
  263. package/dist/core/read/logo.d.ts +34 -0
  264. package/dist/core/read/logo.d.ts.map +1 -0
  265. package/dist/core/read/lookup.d.ts +9 -0
  266. package/dist/core/read/lookup.d.ts.map +1 -0
  267. package/dist/core/read/rules.d.ts +80 -0
  268. package/dist/core/read/rules.d.ts.map +1 -0
  269. package/dist/core/read/token.d.ts +46 -0
  270. package/dist/core/read/token.d.ts.map +1 -0
  271. package/dist/core/shipped-names.d.ts +9 -0
  272. package/dist/core/shipped-names.d.ts.map +1 -0
  273. package/dist/core/starter.d.ts +31 -0
  274. package/dist/core/starter.d.ts.map +1 -0
  275. package/dist/core/suggest.d.ts +7 -0
  276. package/dist/core/suggest.d.ts.map +1 -0
  277. package/dist/core/tokens/alias.d.ts +18 -0
  278. package/dist/core/tokens/alias.d.ts.map +1 -0
  279. package/dist/core/tokens/contexts.d.ts +10 -0
  280. package/dist/core/tokens/contexts.d.ts.map +1 -0
  281. package/dist/core/tokens/formatters/css.d.ts +15 -0
  282. package/dist/core/tokens/formatters/css.d.ts.map +1 -0
  283. package/dist/core/tokens/formatters/json.d.ts +4 -0
  284. package/dist/core/tokens/formatters/json.d.ts.map +1 -0
  285. package/dist/core/tokens/formatters/tailwind.d.ts +37 -0
  286. package/dist/core/tokens/formatters/tailwind.d.ts.map +1 -0
  287. package/dist/core/tokens/formatters/ts.d.ts +6 -0
  288. package/dist/core/tokens/formatters/ts.d.ts.map +1 -0
  289. package/dist/core/tokens/groups.d.ts +44 -0
  290. package/dist/core/tokens/groups.d.ts.map +1 -0
  291. package/dist/core/tokens/key-lines.d.ts +8 -0
  292. package/dist/core/tokens/key-lines.d.ts.map +1 -0
  293. package/dist/core/tokens/load.d.ts +12 -0
  294. package/dist/core/tokens/load.d.ts.map +1 -0
  295. package/dist/core/tokens/merge.d.ts +17 -0
  296. package/dist/core/tokens/merge.d.ts.map +1 -0
  297. package/dist/core/tokens/names.d.ts +5 -0
  298. package/dist/core/tokens/names.d.ts.map +1 -0
  299. package/dist/core/tokens/resolve.d.ts +8 -0
  300. package/dist/core/tokens/resolve.d.ts.map +1 -0
  301. package/dist/core/tokens/resolver/compile.d.ts +17 -0
  302. package/dist/core/tokens/resolver/compile.d.ts.map +1 -0
  303. package/dist/core/tokens/resolver/inputs.d.ts +7 -0
  304. package/dist/core/tokens/resolver/inputs.d.ts.map +1 -0
  305. package/dist/core/tokens/resolver/parse.d.ts +34 -0
  306. package/dist/core/tokens/resolver/parse.d.ts.map +1 -0
  307. package/dist/core/tokens/resolver/sources.d.ts +17 -0
  308. package/dist/core/tokens/resolver/sources.d.ts.map +1 -0
  309. package/dist/core/tokens/shadcn.d.ts +43 -0
  310. package/dist/core/tokens/shadcn.d.ts.map +1 -0
  311. package/dist/core/tokens/theme.d.ts +17 -0
  312. package/dist/core/tokens/theme.d.ts.map +1 -0
  313. package/dist/core/tokens/values/color.d.ts +2 -0
  314. package/dist/core/tokens/values/color.d.ts.map +1 -0
  315. package/dist/core/tokens/values/composite.d.ts +7 -0
  316. package/dist/core/tokens/values/composite.d.ts.map +1 -0
  317. package/dist/core/tokens/values/font.d.ts +3 -0
  318. package/dist/core/tokens/values/font.d.ts.map +1 -0
  319. package/dist/core/tokens/values/index.d.ts +9 -0
  320. package/dist/core/tokens/values/index.d.ts.map +1 -0
  321. package/dist/core/tokens/values/shared.d.ts +5 -0
  322. package/dist/core/tokens/values/shared.d.ts.map +1 -0
  323. package/dist/core/tokens/values/simple.d.ts +3 -0
  324. package/dist/core/tokens/values/simple.d.ts.map +1 -0
  325. package/dist/core/tokens/values/units.d.ts +3 -0
  326. package/dist/core/tokens/values/units.d.ts.map +1 -0
  327. package/dist/core/tokens/walk.d.ts +30 -0
  328. package/dist/core/tokens/walk.d.ts.map +1 -0
  329. package/dist/core/version.d.ts +3 -0
  330. package/dist/core/version.d.ts.map +1 -0
  331. package/dist/index.d.ts +27 -0
  332. package/dist/index.d.ts.map +1 -0
  333. package/dist/index.js +40 -0
  334. package/dist/plugins/host/admit.d.ts +35 -0
  335. package/dist/plugins/host/admit.d.ts.map +1 -0
  336. package/dist/plugins/host/call.d.ts +59 -0
  337. package/dist/plugins/host/call.d.ts.map +1 -0
  338. package/dist/plugins/host/check.d.ts +54 -0
  339. package/dist/plugins/host/check.d.ts.map +1 -0
  340. package/dist/plugins/host/scrub.d.ts +17 -0
  341. package/dist/plugins/host/scrub.d.ts.map +1 -0
  342. package/dist/plugins/index.d.ts +14 -0
  343. package/dist/plugins/index.d.ts.map +1 -0
  344. package/dist/plugins/pins/interpreter.d.ts +49 -0
  345. package/dist/plugins/pins/interpreter.d.ts.map +1 -0
  346. package/dist/plugins/pins/lock.d.ts +47 -0
  347. package/dist/plugins/pins/lock.d.ts.map +1 -0
  348. package/dist/plugins/pins/pin.d.ts +65 -0
  349. package/dist/plugins/pins/pin.d.ts.map +1 -0
  350. package/dist/plugins/pins/shipped.d.ts +40 -0
  351. package/dist/plugins/pins/shipped.d.ts.map +1 -0
  352. package/dist/plugins/roles/breaker.d.ts +18 -0
  353. package/dist/plugins/roles/breaker.d.ts.map +1 -0
  354. package/dist/plugins/roles/check-cases.d.ts +4 -0
  355. package/dist/plugins/roles/check-cases.d.ts.map +1 -0
  356. package/dist/plugins/roles/dev.d.ts +35 -0
  357. package/dist/plugins/roles/dev.d.ts.map +1 -0
  358. package/dist/plugins/roles/fixes.d.ts +24 -0
  359. package/dist/plugins/roles/fixes.d.ts.map +1 -0
  360. package/dist/plugins/roles/gate.d.ts +26 -0
  361. package/dist/plugins/roles/gate.d.ts.map +1 -0
  362. package/dist/plugins/roles/integrate.d.ts +12 -0
  363. package/dist/plugins/roles/integrate.d.ts.map +1 -0
  364. package/dist/plugins/roles/roles.d.ts +69 -0
  365. package/dist/plugins/roles/roles.d.ts.map +1 -0
  366. package/dist/plugins/wire/environment.d.ts +9 -0
  367. package/dist/plugins/wire/environment.d.ts.map +1 -0
  368. package/dist/plugins/wire/forms.d.ts +13 -0
  369. package/dist/plugins/wire/forms.d.ts.map +1 -0
  370. package/dist/plugins/wire/limits.d.ts +11 -0
  371. package/dist/plugins/wire/limits.d.ts.map +1 -0
  372. package/dist/plugins/wire/manifest.d.ts +31 -0
  373. package/dist/plugins/wire/manifest.d.ts.map +1 -0
  374. package/dist/plugins/wire/profile.d.ts +36 -0
  375. package/dist/plugins/wire/profile.d.ts.map +1 -0
  376. package/dist/plugins/wire/text.d.ts +14 -0
  377. package/dist/plugins/wire/text.d.ts.map +1 -0
  378. package/dist/server/assets.d.ts +13 -0
  379. package/dist/server/assets.d.ts.map +1 -0
  380. package/dist/server/coalesce.d.ts +12 -0
  381. package/dist/server/coalesce.d.ts.map +1 -0
  382. package/dist/server/data-script.d.ts +8 -0
  383. package/dist/server/data-script.d.ts.map +1 -0
  384. package/dist/server/dev-server.d.ts +34 -0
  385. package/dist/server/dev-server.d.ts.map +1 -0
  386. package/dist/server/editor-guard.d.ts +13 -0
  387. package/dist/server/editor-guard.d.ts.map +1 -0
  388. package/dist/server/error-reporter.d.ts +11 -0
  389. package/dist/server/error-reporter.d.ts.map +1 -0
  390. package/dist/server/icon-sets.d.ts +9 -0
  391. package/dist/server/icon-sets.d.ts.map +1 -0
  392. package/dist/server/plugin.d.ts +4 -0
  393. package/dist/server/plugin.d.ts.map +1 -0
  394. package/dist/server/preview-guard.d.ts +11 -0
  395. package/dist/server/preview-guard.d.ts.map +1 -0
  396. package/dist/types/assets.d.ts +130 -0
  397. package/dist/types/assets.d.ts.map +1 -0
  398. package/dist/types/catalog.d.ts +95 -0
  399. package/dist/types/catalog.d.ts.map +1 -0
  400. package/dist/types/config.d.ts +97 -0
  401. package/dist/types/config.d.ts.map +1 -0
  402. package/dist/types/data.d.ts +38 -0
  403. package/dist/types/data.d.ts.map +1 -0
  404. package/dist/types/docs.d.ts +47 -0
  405. package/dist/types/docs.d.ts.map +1 -0
  406. package/dist/types/findings.d.ts +18 -0
  407. package/dist/types/findings.d.ts.map +1 -0
  408. package/dist/types/index.d.ts +13 -0
  409. package/dist/types/index.d.ts.map +1 -0
  410. package/dist/types/parsed.d.ts +86 -0
  411. package/dist/types/parsed.d.ts.map +1 -0
  412. package/dist/types/theme.d.ts +19 -0
  413. package/dist/types/theme.d.ts.map +1 -0
  414. package/dist/types/tokens.d.ts +101 -0
  415. package/dist/types/tokens.d.ts.map +1 -0
  416. package/dist/ui/assets/geist-OFL.txt +93 -0
  417. package/dist/ui/assets/geist-cyrillic-ext-wght-normal-DjL33-gN.woff2 +0 -0
  418. package/dist/ui/assets/geist-cyrillic-wght-normal-BEAKL7Jp.woff2 +0 -0
  419. package/dist/ui/assets/geist-latin-ext-wght-normal-DC-KSUi6.woff2 +0 -0
  420. package/dist/ui/assets/geist-latin-wght-normal-BgDaEnEv.woff2 +0 -0
  421. package/dist/ui/assets/geist-vietnamese-wght-normal-6IgcOCM7.woff2 +0 -0
  422. package/dist/ui/assets/index-BdbihVvH.js +77 -0
  423. package/dist/ui/assets/index-DluSqfla.css +2 -0
  424. package/dist/ui/index.html +14 -0
  425. package/package.json +151 -4
  426. package/plugins/blazon.brand-deck/README.md +38 -0
  427. package/plugins/blazon.brand-deck/bin/blazon-blazon.brand-deck./360/237/224/214 +2695 -0
  428. package/plugins/blazon.brand-deck/package.json +3 -0
  429. package/plugins/blazon.copy/README.md +29 -0
  430. package/plugins/blazon.copy/bin/blazon-blazon.copy./360/237/224/214 +438 -0
  431. package/plugins/blazon.copy/package.json +3 -0
  432. package/plugins/blazon.favicons/README.md +13 -0
  433. package/plugins/blazon.favicons/bin/blazon-blazon.favicons./360/237/224/214 +8816 -0
  434. package/plugins/blazon.favicons/package.json +3 -0
  435. package/plugins/blazon.logo-geometry/README.md +5 -0
  436. package/plugins/blazon.logo-geometry/bin/blazon-blazon.logo-geometry./360/237/224/214 +1522 -0
  437. package/plugins/blazon.logo-geometry/package.json +3 -0
  438. package/plugins/blazon.logo-kit/README.md +5 -0
  439. package/plugins/blazon.logo-kit/bin/blazon-blazon.logo-kit./360/237/224/214 +617 -0
  440. package/plugins/blazon.logo-kit/package.json +3 -0
  441. package/plugins/blazon.office-template/README.md +29 -0
  442. package/plugins/blazon.office-template/bin/blazon-blazon.office-template./360/237/224/214 +1788 -0
  443. package/plugins/blazon.office-template/package.json +3 -0
  444. package/plugins/blazon.platform-tokens/README.md +22 -0
  445. package/plugins/blazon.platform-tokens/bin/blazon-blazon.platform-tokens./360/237/224/214 +8418 -0
  446. package/plugins/blazon.platform-tokens/package.json +3 -0
  447. package/plugins/blazon.press-kit/README.md +17 -0
  448. package/plugins/blazon.press-kit/bin/blazon-blazon.press-kit./360/237/224/214 +897 -0
  449. package/plugins/blazon.press-kit/package.json +3 -0
  450. package/plugins/blazon.print-book/README.md +38 -0
  451. package/plugins/blazon.print-book/bin/blazon-blazon.print-book./360/237/224/214 +9262 -0
  452. package/plugins/blazon.print-book/package.json +3 -0
  453. package/plugins/blazon.social-cards/README.md +5 -0
  454. package/plugins/blazon.social-cards/bin/blazon-blazon.social-cards./360/237/224/214 +1165 -0
  455. package/plugins/blazon.social-cards/package.json +3 -0
  456. package/plugins/shipped.lock +75 -0
  457. package/template/AGENTS.md +55 -0
  458. package/template/CLAUDE.md +1 -0
  459. package/template/assets/backgrounds/aurora.json +5 -0
  460. package/template/assets/backgrounds/aurora.svg +39 -0
  461. package/template/assets/construction/blazon-mark.json +9 -0
  462. package/template/assets/construction/blazon-mark.svg +54 -0
  463. package/template/assets/icons/arrow-right.json +5 -0
  464. package/template/assets/icons/arrow-right.svg +1 -0
  465. package/template/assets/icons/check.json +5 -0
  466. package/template/assets/icons/check.svg +1 -0
  467. package/template/assets/icons/download.json +5 -0
  468. package/template/assets/icons/download.svg +1 -0
  469. package/template/assets/icons/file.json +5 -0
  470. package/template/assets/icons/file.svg +1 -0
  471. package/template/assets/icons/token.json +5 -0
  472. package/template/assets/icons/token.svg +1 -0
  473. package/template/assets/icons/warning.json +5 -0
  474. package/template/assets/icons/warning.svg +1 -0
  475. package/template/assets/logos/blazon-bone.json +6 -0
  476. package/template/assets/logos/blazon-bone.svg +1 -0
  477. package/template/assets/logos/blazon-graphite.json +6 -0
  478. package/template/assets/logos/blazon-graphite.svg +1 -0
  479. package/template/assets/logos/blazon-mark.json +6 -0
  480. package/template/assets/logos/blazon-mark.svg +1 -0
  481. package/template/blazon.json +104 -0
  482. package/template/blazon.resolver.json +46 -0
  483. package/template/docs/01-principles.md +47 -0
  484. package/template/docs/02-logo.md +43 -0
  485. package/template/docs/03-color.md +79 -0
  486. package/template/docs/04-type.md +36 -0
  487. package/template/docs/05-form.md +80 -0
  488. package/template/docs/06-layout.md +28 -0
  489. package/template/docs/07-icons.md +22 -0
  490. package/template/docs/08-diagrams.md +20 -0
  491. package/template/docs/09-social.md +21 -0
  492. package/template/docs/10-applications.md +20 -0
  493. package/template/docs/11-voice.md +74 -0
  494. package/template/docs/12-web.md +167 -0
  495. package/template/fonts/IBMPlexMono-Regular-latin.woff2 +0 -0
  496. package/template/fonts/IBMPlexMono-SemiBold-latin.woff2 +0 -0
  497. package/template/fonts/OFL.txt +93 -0
  498. package/template/tokens/colors.json +257 -0
  499. package/template/tokens/form.json +199 -0
  500. package/template/tokens/social.json +26 -0
  501. package/template/tokens/spacing.json +65 -0
  502. package/template/tokens/theme/dark.json +121 -0
  503. package/template/tokens/typography.json +233 -0
@@ -0,0 +1,1522 @@
1
+ #!/usr/bin/env node
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __copyProps = (to, from, except, desc) => {
9
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
10
+ key = keys[i];
11
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
12
+ get: ((k) => from[k]).bind(null, key),
13
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
14
+ });
15
+ }
16
+ return to;
17
+ };
18
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp(target, "default", {
19
+ value: mod,
20
+ enumerable: true
21
+ }) : target, mod));
22
+ let node_fs = require("node:fs");
23
+ node_fs = __toESM(node_fs, 1);
24
+ let node_path = require("node:path");
25
+ node_path = __toESM(node_path, 1);
26
+ let playwright_core = require("playwright-core");
27
+ /** What the findings may take on the wire, in bytes. The limit is 65,536; the rest is the envelope, the summary finding and a newline, with room to spare. */
28
+ var FINDINGS_BUDGET = 6e4;
29
+ var RANK = {
30
+ error: 0,
31
+ warning: 1,
32
+ info: 2
33
+ };
34
+ var rank = (severity) => RANK[severity] ?? 3;
35
+ var wire = (finding) => Buffer.byteLength(JSON.stringify(finding), "utf-8") + 1;
36
+ /**
37
+ * The findings as they are when they fit. When they do not, the first ones that fit, errors before warnings before notes and each
38
+ * group in the order it was found, then one `<name>/findings-left-out` warning that says how many are not shown. The summary is a
39
+ * warning so that it never hides that there were errors: the errors come first, and a run with any error is already failed.
40
+ */
41
+ function boundFindings(findings, name) {
42
+ let size = 0;
43
+ for (const finding of findings) size += wire(finding);
44
+ if (size <= 6e4) return findings;
45
+ const ordered = [...findings].sort((a, b) => rank(a.severity) - rank(b.severity));
46
+ const kept = [];
47
+ size = 0;
48
+ for (const finding of ordered) {
49
+ if (size + wire(finding) > 6e4) break;
50
+ size += wire(finding);
51
+ kept.push(finding);
52
+ }
53
+ const left = ordered.length - kept.length;
54
+ kept.push({
55
+ code: `${name}/findings-left-out`,
56
+ severity: "warning",
57
+ path: "findings",
58
+ message: `${left} more findings are not shown, because the answer would not fit the ${FINDINGS_BUDGET.toLocaleString("en-US")} bytes a plugin may print; fix the ones above and run again`
59
+ });
60
+ return kept;
61
+ }
62
+ /** The plugin cannot do what it was asked; the message is the reason blazon shows. */
63
+ var Cannot = class extends Error {};
64
+ /** The builder of a plugin's findings: `findingFor(NAME)('code', severity, path, message)` is a finding coded `NAME/code`. */
65
+ var findingFor = (name) => (code, severity, path, message) => ({
66
+ code: `${name}/${code}`,
67
+ severity,
68
+ path,
69
+ message
70
+ });
71
+ var isObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
72
+ /** The brand.json a plugin reads: the object when its format and version are the ones this reader understands, Cannot otherwise (RFC 0001: a reader checks both before it interprets anything). */
73
+ function requireBrand(raw) {
74
+ const shown = (value) => JSON.stringify(value) ?? "nothing";
75
+ if (!isObject(raw) || raw.format !== "blazon-brand") throw new Cannot(`the brand in the request is not a blazon brand: its format is ${shown(isObject(raw) ? raw.format : void 0)}, not "blazon-brand"`);
76
+ if (raw.version !== 1) throw new Cannot(`the brand in the request is version ${shown(raw.version)}; this reader understands version 1`);
77
+ return raw;
78
+ }
79
+ /** The request as an object of version 1, or Cannot with the reason. Its role and folders are for the plugin to check. */
80
+ function readRequest(text) {
81
+ let request;
82
+ try {
83
+ request = JSON.parse(text);
84
+ } catch {
85
+ throw new Cannot("the request is not JSON");
86
+ }
87
+ if (!isObject(request)) throw new Cannot("the request is not a JSON object");
88
+ if (request.v !== 1) throw new Cannot(`the request is version ${JSON.stringify(request.v)}; this plugin speaks version 1`);
89
+ return request;
90
+ }
91
+ /** The build request in `text`, or Cannot with the reason: version 1, the build role, a site_dir with an index.html and an out_dir that is a folder. The brand and options are not checked here. */
92
+ function buildJob(text) {
93
+ const request = readRequest(text);
94
+ if (request.type !== "build") throw new Cannot(`the request is for the ${String(request.type)} role; this plugin is a build plugin`);
95
+ const { site_dir: siteDir, out_dir: outDir } = request;
96
+ if (typeof siteDir !== "string" || !node_fs.default.existsSync(node_path.default.join(siteDir, "index.html"))) throw new Cannot("site_dir has no index.html");
97
+ if (typeof outDir !== "string" || !node_fs.default.statSync(outDir, { throwIfNoEntry: false })?.isDirectory()) throw new Cannot("out_dir is not a folder");
98
+ return {
99
+ siteDir,
100
+ outDir,
101
+ brand: request.brand ?? {},
102
+ options: request.options ?? {}
103
+ };
104
+ }
105
+ /**
106
+ * The entry: `--blazon-manifest` prints the manifest; otherwise one request on standard input gets the answer of `build` as
107
+ * JSON, or exit 2 with the reason as the first line of standard output. `failure` starts the reason for an error that is
108
+ * not a Cannot. `name` is the plugin's, for the summary when the findings are bounded to what a call may print (bound.ts). Returns the exit status.
109
+ */
110
+ async function runPlugin(argv, manifest, build, failure, name) {
111
+ if (argv[0] === "--blazon-manifest") {
112
+ process.stdout.write(`${JSON.stringify(manifest)}\n`);
113
+ return 0;
114
+ }
115
+ try {
116
+ const answer = await build(node_fs.default.readFileSync(0, "utf-8"));
117
+ const bounded = isObject(answer) && Array.isArray(answer.findings) ? {
118
+ ...answer,
119
+ findings: boundFindings(answer.findings, name)
120
+ } : answer;
121
+ process.stdout.write(`${JSON.stringify(bounded)}\n`);
122
+ return 0;
123
+ } catch (error) {
124
+ const reason = error instanceof Cannot ? error.message : `${failure}: ${String(error.message ?? error).split("\n")[0].slice(0, 500)}`;
125
+ process.stdout.write(`${reason}\n`);
126
+ return 2;
127
+ }
128
+ }
129
+ var INSTALL_HINT = "install Google Chrome, or set BLAZON_CHROME to a Chrome or Chromium program";
130
+ /**
131
+ * The browser: the program BLAZON_CHROME names, else the Google Chrome installed on this computer. It never downloads one.
132
+ * `what` completes "no browser to ...", such as "print with".
133
+ */
134
+ async function launchChrome(env, what) {
135
+ const named = env.BLAZON_CHROME;
136
+ if (named) {
137
+ if (!isProgram(named)) throw new Cannot(`no browser to ${what}: BLAZON_CHROME names ${named}, which is not a program; ${INSTALL_HINT}`);
138
+ return playwright_core.chromium.launch({ executablePath: named });
139
+ }
140
+ try {
141
+ return await playwright_core.chromium.launch({ channel: "chrome" });
142
+ } catch {
143
+ throw new Cannot(`no browser to ${what}: ${INSTALL_HINT}`);
144
+ }
145
+ }
146
+ function isProgram(file) {
147
+ try {
148
+ node_fs.default.accessSync(file, node_fs.default.constants.X_OK);
149
+ return node_fs.default.statSync(file).isFile();
150
+ } catch {
151
+ return false;
152
+ }
153
+ }
154
+ /** The file at `file` in the built site, or undefined when it is not there or leaves the site by a path or a link */
155
+ function siteFile(siteDir, file) {
156
+ const root = node_fs.default.realpathSync(siteDir);
157
+ const full = node_path.default.resolve(root, file);
158
+ if (!full.startsWith(root + node_path.default.sep) || !node_fs.default.existsSync(full) || !node_fs.default.statSync(full).isFile()) return void 0;
159
+ const real = node_fs.default.realpathSync(full);
160
+ return real.startsWith(root + node_path.default.sep) ? node_fs.default.readFileSync(real) : void 0;
161
+ }
162
+ /** A non-empty string (not only whitespace), or undefined. */
163
+ var text = (value) => typeof value === "string" && value.trim() !== "" ? value : void 0;
164
+ /** An asset's id, file, format and category (the first segment of the id when the entry has none); undefined when the entry lacks one of the first three. */
165
+ function readBaseAsset(raw) {
166
+ if (!isObject(raw)) return void 0;
167
+ const [id, file, format] = [
168
+ text(raw.id),
169
+ text(raw.file),
170
+ text(raw.format)
171
+ ];
172
+ if (!id || !file || !format) return void 0;
173
+ return {
174
+ id,
175
+ file,
176
+ format,
177
+ category: text(raw.category) ?? id.split("/")[0]
178
+ };
179
+ }
180
+ /** The formats this plugin measures. */
181
+ var MEASURED = [
182
+ "svg",
183
+ "png",
184
+ "webp"
185
+ ];
186
+ function readBrand(brand) {
187
+ const root = requireBrand(brand);
188
+ const assets = /* @__PURE__ */ new Map();
189
+ for (const raw of Array.isArray(root.assets) ? root.assets : []) {
190
+ const asset = readBaseAsset(raw);
191
+ if (asset) assets.set(asset.id, asset);
192
+ }
193
+ const accent = text((isObject(root.theme) && isObject(root.theme.roles) ? root.theme.roles : {}).accent);
194
+ return {
195
+ assets,
196
+ ...accent && { accent }
197
+ };
198
+ }
199
+ /** The ids of the logos to measure when the options name none: the `logos` category, in a format this plugin reads. */
200
+ var defaultLogos = (read) => [...read.assets.values()].filter((a) => a.category === "logos" && MEASURED.includes(a.format)).map((a) => a.id);
201
+ /** The logo uses something this reader does not draw, or has nothing to measure; the message says what. */
202
+ var Unsupported = class extends Error {};
203
+ /** The longest side the pixels are returned at. The grid is 256 cells, so this leaves the averaging plenty to work with. */
204
+ var MAX_SIDE = 1024;
205
+ /** Pictures larger than this many pixels are refused before the browser is asked to hold one. */
206
+ var MAX_PIXELS = 4e7;
207
+ var MEDIA = {
208
+ png: "image/png",
209
+ webp: "image/webp"
210
+ };
211
+ async function decodeRaster(browser, bytes, format, crop) {
212
+ const media = MEDIA[format];
213
+ if (!media) throw new Unsupported(`${format} is not a format this plugin reads; use SVG, PNG or WebP`);
214
+ const page = await browser.newPage();
215
+ try {
216
+ await page.route("**/*", (route) => route.request().url().startsWith("data:") ? route.continue() : route.abort());
217
+ await page.setContent("<!doctype html><meta charset=\"utf-8\">");
218
+ const result = await page.evaluate(async ({ source, region, max, limit }) => {
219
+ const image = new Image();
220
+ image.src = source;
221
+ try {
222
+ await image.decode();
223
+ } catch {
224
+ return { error: "the file is not a picture the browser can decode" };
225
+ }
226
+ const [natW, natH] = [image.naturalWidth, image.naturalHeight];
227
+ if (natW * natH > limit) return { error: `the picture is ${natW} by ${natH} pixels, over the ${limit} this plugin will decode` };
228
+ const [cx, cy, cw, ch] = region ?? [
229
+ 0,
230
+ 0,
231
+ natW,
232
+ natH
233
+ ];
234
+ const [sx, sy] = [Math.max(0, Math.min(natW - 1, Math.round(cx))), Math.max(0, Math.min(natH - 1, Math.round(cy)))];
235
+ const [sw, sh] = [Math.max(1, Math.min(natW - sx, Math.round(cw))), Math.max(1, Math.min(natH - sy, Math.round(ch)))];
236
+ const fit = Math.min(1, max / Math.max(sw, sh));
237
+ const [w, h] = [Math.max(1, Math.round(sw * fit)), Math.max(1, Math.round(sh * fit))];
238
+ const canvas = document.createElement("canvas");
239
+ canvas.width = w;
240
+ canvas.height = h;
241
+ const context = canvas.getContext("2d", { willReadFrequently: true });
242
+ context.imageSmoothingEnabled = true;
243
+ context.imageSmoothingQuality = "high";
244
+ context.drawImage(image, sx, sy, sw, sh, 0, 0, w, h);
245
+ const data = context.getImageData(0, 0, w, h).data;
246
+ let binary = "";
247
+ for (let i = 0; i < data.length; i += 32768) binary += String.fromCharCode(...data.subarray(i, i + 32768));
248
+ return {
249
+ width: w,
250
+ height: h,
251
+ data: btoa(binary)
252
+ };
253
+ }, {
254
+ source: `data:${media};base64,${bytes.toString("base64")}`,
255
+ region: crop ?? null,
256
+ max: MAX_SIDE,
257
+ limit: MAX_PIXELS
258
+ });
259
+ if ("error" in result) throw new Unsupported(result.error);
260
+ return {
261
+ width: result.width,
262
+ height: result.height,
263
+ rgba: new Uint8Array(Buffer.from(result.data, "base64"))
264
+ };
265
+ } finally {
266
+ await page.close();
267
+ }
268
+ }
269
+ var isTie = (value, digits) => {
270
+ const scaled = value * 2 ** (digits + 1);
271
+ return Number.isInteger(scaled) && Math.abs(scaled) % 2 === 1;
272
+ };
273
+ /** `value` rounded to `digits` decimal places, a tie to the even digit. */
274
+ function round(value, digits = 0) {
275
+ const factor = 10 ** digits;
276
+ if (isTie(value, digits)) {
277
+ const scaled = value * factor;
278
+ const floor = Math.floor(scaled);
279
+ return (floor % 2 === 0 ? floor : floor + 1) / factor;
280
+ }
281
+ return Number(value.toFixed(digits));
282
+ }
283
+ /** `value` with exactly `digits` decimal places, a tie to the even digit, as Python's `f"{value:.{digits}f}"`. */
284
+ function fixed(value, digits) {
285
+ const rounded = round(value, digits);
286
+ const text = rounded.toFixed(digits);
287
+ return Object.is(rounded, -0) || rounded === 0 && value < 0 ? `-${text.replace(/^-/, "")}` : text;
288
+ }
289
+ /** `fixed` with a leading + on a value that is not negative, as `f"{value:+.1f}"`. */
290
+ var signed = (value, digits) => {
291
+ const text = fixed(value, digits);
292
+ return text.startsWith("-") ? text : `+${text}`;
293
+ };
294
+ /** A coordinate in a figure: three places, the zeros after the point dropped. */
295
+ function coordinate(value) {
296
+ return fixed(value, 3).replace(/0+$/, "").replace(/\.$/, "");
297
+ }
298
+ /** Paint `label` into the cells whose centers a set of polygons covers, by the nonzero or the even-odd rule. */
299
+ function fillPolygons(grid, origin, scale, polygons, label, rule) {
300
+ const height = grid.length;
301
+ const width = grid[0].length;
302
+ const edges = [];
303
+ for (const polygon of polygons) {
304
+ const points = polygon.map(([px, py]) => [(px - origin[0]) * scale, (py - origin[1]) * scale]);
305
+ points.forEach(([x0, y0], k) => {
306
+ const [x1, y1] = points[(k + 1) % points.length];
307
+ if (y0 !== y1) edges.push([
308
+ x0,
309
+ y0,
310
+ x1,
311
+ y1
312
+ ]);
313
+ });
314
+ }
315
+ for (let row = 0; row < height; row++) {
316
+ const cy = row + .5;
317
+ const crossings = [];
318
+ for (const [x0, y0, x1, y1] of edges) if (y0 <= cy && cy < y1 || y1 <= cy && cy < y0) crossings.push([x0 + (cy - y0) * (x1 - x0) / (y1 - y0), y1 > y0 ? 1 : -1]);
319
+ crossings.sort((a, b) => a[0] - b[0] || a[1] - b[1]);
320
+ let winding = 0;
321
+ for (let k = 0; k < crossings.length - 1; k++) {
322
+ winding = rule === "evenodd" ? winding ^ 1 : winding + crossings[k][1];
323
+ if (winding !== 0) {
324
+ const start = Math.ceil(crossings[k][0] - .5);
325
+ const end = Math.ceil(crossings[k + 1][0] - .5);
326
+ for (let col = Math.max(start, 0); col < Math.min(end, width); col++) grid[row][col] = label;
327
+ }
328
+ }
329
+ }
330
+ }
331
+ /**
332
+ * The part of the artboard (or of the crop) that the ink's points span, so the grid is drawn at the same resolution however much padding
333
+ * the artwork has. Undefined when no shape reaches it.
334
+ */
335
+ function inkRegion(viewBox, shapes, crop) {
336
+ const [vx, vy, vw, vh] = crop ?? viewBox;
337
+ const points = shapes.flatMap((s) => s.polygons.flat());
338
+ if (points.length === 0) return void 0;
339
+ let [minX, minY, maxX, maxY] = [
340
+ Infinity,
341
+ Infinity,
342
+ -Infinity,
343
+ -Infinity
344
+ ];
345
+ for (const [x, y] of points) {
346
+ minX = Math.min(minX, x);
347
+ minY = Math.min(minY, y);
348
+ maxX = Math.max(maxX, x);
349
+ maxY = Math.max(maxY, y);
350
+ }
351
+ const [x0, y0, x1, y1] = [
352
+ Math.max(vx, minX),
353
+ Math.max(vy, minY),
354
+ Math.min(vx + vw, maxX),
355
+ Math.min(vy + vh, maxY)
356
+ ];
357
+ return x1 > x0 && y1 > y0 ? [
358
+ x0,
359
+ y0,
360
+ x1 - x0,
361
+ y1 - y0
362
+ ] : void 0;
363
+ }
364
+ /** Shapes drawn into a grid, and the region of the artwork the grid covers. */
365
+ function rasterize(viewBox, shapes, crop) {
366
+ const region = inkRegion(viewBox, shapes, crop);
367
+ if (!region) throw new Unsupported("the logo has nothing to measure: no ink in it");
368
+ const [vx, vy, vw, vh] = region;
369
+ const scale = 256 / Math.max(vw, vh);
370
+ const width = Math.max(1, round(vw * scale));
371
+ const height = Math.max(1, round(vh * scale));
372
+ const grid = Array.from({ length: height }, () => new Array(width).fill(0));
373
+ const labels = /* @__PURE__ */ new Map();
374
+ for (const shape of shapes) {
375
+ if (!labels.has(shape.fill)) labels.set(shape.fill, labels.size + 1);
376
+ fillPolygons(grid, [vx, vy], scale, shape.polygons, labels.get(shape.fill), shape.rule);
377
+ }
378
+ return {
379
+ grid,
380
+ region
381
+ };
382
+ }
383
+ /**
384
+ * A raster (RGBA bytes, row by row) as a grid. It is first scaled down to RESOLUTION cells on its longer side by averaging the pixels each
385
+ * cell covers. Then transparent (or, when the image has no transparency, the corner's color) is nothing, and the rest is labeled by its
386
+ * color, three bits a channel.
387
+ */
388
+ function labelRaster(rgba, width, height) {
389
+ const scale = 256 / Math.max(width, height);
390
+ const [w, h] = scale < 1 ? [Math.max(1, round(width * scale)), Math.max(1, round(height * scale))] : [width, height];
391
+ const pixels = scale < 1 ? boxScale(rgba, width, height, w, h) : rgba;
392
+ const total = w * h;
393
+ let transparent = 0;
394
+ for (let i = 0; i < total; i++) if (pixels[i * 4 + 3] < 128) transparent++;
395
+ const keyed = transparent > .02 * total;
396
+ const corner = [
397
+ pixels[0],
398
+ pixels[1],
399
+ pixels[2]
400
+ ];
401
+ const grid = Array.from({ length: h }, () => new Array(w).fill(0));
402
+ const labels = /* @__PURE__ */ new Map();
403
+ for (let i = 0; i < total; i++) {
404
+ const [r, g, b, a] = [
405
+ pixels[i * 4],
406
+ pixels[i * 4 + 1],
407
+ pixels[i * 4 + 2],
408
+ pixels[i * 4 + 3]
409
+ ];
410
+ if (!(keyed ? a >= 128 : Math.abs(r - corner[0]) + Math.abs(g - corner[1]) + Math.abs(b - corner[2]) > 60)) continue;
411
+ const key = r >> 5 << 6 | g >> 5 << 3 | b >> 5;
412
+ if (!labels.has(key)) labels.set(key, labels.size + 1);
413
+ grid[Math.floor(i / w)][i % w] = labels.get(key);
414
+ }
415
+ return grid;
416
+ }
417
+ /** RGBA pixels scaled to w by h by averaging, each output pixel the mean of the source area it covers, partial pixels in proportion. */
418
+ function boxScale(rgba, width, height, w, h) {
419
+ const out = new Uint8Array(w * h * 4);
420
+ const [sx, sy] = [width / w, height / h];
421
+ for (let oy = 0; oy < h; oy++) {
422
+ const [y0, y1] = [oy * sy, (oy + 1) * sy];
423
+ for (let ox = 0; ox < w; ox++) {
424
+ const [x0, x1] = [ox * sx, (ox + 1) * sx];
425
+ const sum = [
426
+ 0,
427
+ 0,
428
+ 0,
429
+ 0
430
+ ];
431
+ let weight = 0;
432
+ for (let y = Math.floor(y0); y < Math.min(height, Math.ceil(y1)); y++) {
433
+ const wy = Math.min(y + 1, y1) - Math.max(y, y0);
434
+ for (let x = Math.floor(x0); x < Math.min(width, Math.ceil(x1)); x++) {
435
+ const wgt = wy * (Math.min(x + 1, x1) - Math.max(x, x0));
436
+ const at = (y * width + x) * 4;
437
+ const a = rgba[at + 3] / 255;
438
+ sum[0] += rgba[at] * a * wgt;
439
+ sum[1] += rgba[at + 1] * a * wgt;
440
+ sum[2] += rgba[at + 2] * a * wgt;
441
+ sum[3] += rgba[at + 3] * wgt;
442
+ weight += wgt;
443
+ }
444
+ }
445
+ const alpha = sum[3] / weight;
446
+ const to = (ox + oy * w) * 4;
447
+ const coverage = alpha / 255;
448
+ out[to] = coverage > 0 ? Math.round(sum[0] / weight / coverage) : 0;
449
+ out[to + 1] = coverage > 0 ? Math.round(sum[1] / weight / coverage) : 0;
450
+ out[to + 2] = coverage > 0 ? Math.round(sum[2] / weight / coverage) : 0;
451
+ out[to + 3] = Math.round(alpha);
452
+ }
453
+ }
454
+ return out;
455
+ }
456
+ var CURVE_STEPS = 24;
457
+ var ARC_STEPS_PER_TURN = 96;
458
+ /** Points along a cubic or quadratic curve, not including its start. */
459
+ function bezier(start, controls, steps = CURVE_STEPS) {
460
+ const points = [];
461
+ for (let i = 1; i <= steps; i++) {
462
+ const t = i / steps;
463
+ let level = [start, ...controls];
464
+ while (level.length > 1) level = level.slice(1).map((b, k) => [(1 - t) * level[k][0] + t * b[0], (1 - t) * level[k][1] + t * b[1]]);
465
+ points.push(level[0]);
466
+ }
467
+ return points;
468
+ }
469
+ var angleBetween = (ux, uy, vx, vy) => {
470
+ const sign = ux * vy - uy * vx < 0 ? -1 : 1;
471
+ const dot = (ux * vx + uy * vy) / (Math.hypot(ux, uy) * Math.hypot(vx, vy));
472
+ return sign * Math.acos(Math.max(-1, Math.min(1, dot)));
473
+ };
474
+ /**
475
+ * Points along an elliptical arc from (x1, y1) to (x2, y2), not including the start, the last of them exactly (x2, y2). The endpoint form
476
+ * of the SVG arc command, turned into a center and swept in equal angle steps (SVG 1.1, appendix F.6).
477
+ */
478
+ function arcPoints(x1, y1, rxIn, ryIn, rotation, largeArc, sweep, x2, y2) {
479
+ if (x1 === x2 && y1 === y2) return [];
480
+ let rx = Math.abs(rxIn);
481
+ let ry = Math.abs(ryIn);
482
+ if (rx === 0 || ry === 0) return [[x2, y2]];
483
+ const phi = rotation * Math.PI / 180;
484
+ const [cos, sin] = [Math.cos(phi), Math.sin(phi)];
485
+ const [dx, dy] = [(x1 - x2) / 2, (y1 - y2) / 2];
486
+ const x1p = cos * dx + sin * dy;
487
+ const y1p = -sin * dx + cos * dy;
488
+ const lambda = x1p * x1p / (rx * rx) + y1p * y1p / (ry * ry);
489
+ if (lambda > 1) {
490
+ rx *= Math.sqrt(lambda);
491
+ ry *= Math.sqrt(lambda);
492
+ }
493
+ const numerator = rx * rx * ry * ry - rx * rx * y1p * y1p - ry * ry * x1p * x1p;
494
+ const denominator = rx * rx * y1p * y1p + ry * ry * x1p * x1p;
495
+ const coefficient = (largeArc === sweep ? -1 : 1) * Math.sqrt(Math.max(0, numerator / denominator));
496
+ const cxp = coefficient * rx * y1p / ry;
497
+ const cyp = -coefficient * ry * x1p / rx;
498
+ const cx = cos * cxp - sin * cyp + (x1 + x2) / 2;
499
+ const cy = sin * cxp + cos * cyp + (y1 + y2) / 2;
500
+ const theta = angleBetween(1, 0, (x1p - cxp) / rx, (y1p - cyp) / ry);
501
+ let delta = angleBetween((x1p - cxp) / rx, (y1p - cyp) / ry, (-x1p - cxp) / rx, (-y1p - cyp) / ry);
502
+ if (!sweep && delta > 0) delta -= 2 * Math.PI;
503
+ else if (sweep && delta < 0) delta += 2 * Math.PI;
504
+ const steps = Math.max(2, Math.ceil(Math.abs(delta) / (2 * Math.PI) * ARC_STEPS_PER_TURN));
505
+ const points = [];
506
+ for (let i = 1; i < steps; i++) {
507
+ const t = theta + delta * i / steps;
508
+ points.push([cos * rx * Math.cos(t) - sin * ry * Math.sin(t) + cx, sin * rx * Math.cos(t) + cos * ry * Math.sin(t) + cy]);
509
+ }
510
+ points.push([x2, y2]);
511
+ return points;
512
+ }
513
+ var NUMBER = /[-+]?(?:\d*\.\d+|\d+\.?)(?:[eE][-+]?\d+)?/y;
514
+ var COMMANDS = "MmLlHhVvCcSsQqTtZzAa";
515
+ /** A path's subpaths, or Unsupported saying what in the data cannot be read. */
516
+ function pathSubpaths(d) {
517
+ const subpaths = [];
518
+ let points = [];
519
+ let anchors = [];
520
+ let [x, y, startX, startY] = [
521
+ 0,
522
+ 0,
523
+ 0,
524
+ 0
525
+ ];
526
+ let lastControl;
527
+ let command;
528
+ let at = 0;
529
+ const skip = () => {
530
+ while (at < d.length && /[\s,]/.test(d[at])) at++;
531
+ };
532
+ const near = () => JSON.stringify(d.slice(at, at + 12).trim());
533
+ const number = () => {
534
+ skip();
535
+ NUMBER.lastIndex = at;
536
+ const match = NUMBER.exec(d);
537
+ if (!match) throw new Unsupported(`path data is cut short near ${near()}`);
538
+ at = NUMBER.lastIndex;
539
+ return Number(match[0]);
540
+ };
541
+ const flag = () => {
542
+ skip();
543
+ const ch = d[at];
544
+ if (ch !== "0" && ch !== "1") throw new Unsupported(`path data has an arc flag that is not 0 or 1 near ${near()}`);
545
+ at++;
546
+ return ch === "1";
547
+ };
548
+ const finish = () => {
549
+ if (points.length > 1) subpaths.push({
550
+ points,
551
+ anchors
552
+ });
553
+ points = [];
554
+ anchors = [];
555
+ };
556
+ for (;;) {
557
+ skip();
558
+ if (at >= d.length) break;
559
+ if (/[A-Za-z]/.test(d[at])) {
560
+ if (!COMMANDS.includes(d[at])) throw new Unsupported(`path data has the command ${d[at]} near ${near()}`);
561
+ command = d[at];
562
+ at++;
563
+ } else if (command === void 0) throw new Unsupported("path data does not start with a command");
564
+ const relative = command === command.toLowerCase();
565
+ const upper = command.toUpperCase();
566
+ if (upper === "Z") {
567
+ if (points.length > 0) [x, y] = [startX, startY];
568
+ finish();
569
+ lastControl = void 0;
570
+ skip();
571
+ if (at < d.length && !/[A-Za-z]/.test(d[at])) throw new Unsupported(`path data has numbers after a close near ${near()}`);
572
+ continue;
573
+ }
574
+ if (upper === "M") {
575
+ const [nx, ny] = [number(), number()];
576
+ [x, y] = relative ? [x + nx, y + ny] : [nx, ny];
577
+ finish();
578
+ [startX, startY] = [x, y];
579
+ points = [[x, y]];
580
+ anchors = [[x, y]];
581
+ command = relative ? "l" : "L";
582
+ lastControl = void 0;
583
+ continue;
584
+ }
585
+ if (upper === "L") {
586
+ const [nx, ny] = [number(), number()];
587
+ [x, y] = relative ? [x + nx, y + ny] : [nx, ny];
588
+ lastControl = void 0;
589
+ } else if (upper === "H") {
590
+ const nx = number();
591
+ x = relative ? x + nx : nx;
592
+ lastControl = void 0;
593
+ } else if (upper === "V") {
594
+ const ny = number();
595
+ y = relative ? y + ny : ny;
596
+ lastControl = void 0;
597
+ } else if (upper === "C" || upper === "S") {
598
+ let c1;
599
+ if (upper === "C") {
600
+ const [a, b] = [number(), number()];
601
+ c1 = relative ? [x + a, y + b] : [a, b];
602
+ } else c1 = lastControl ? [2 * x - lastControl[0], 2 * y - lastControl[1]] : [x, y];
603
+ const [c, e] = [number(), number()];
604
+ const [ex, ey] = [number(), number()];
605
+ const c2 = relative ? [x + c, y + e] : [c, e];
606
+ const end = relative ? [x + ex, y + ey] : [ex, ey];
607
+ points.push(...bezier([x, y], [
608
+ c1,
609
+ c2,
610
+ end
611
+ ]));
612
+ [x, y] = end;
613
+ anchors.push(end);
614
+ lastControl = c2;
615
+ continue;
616
+ } else if (upper === "Q" || upper === "T") {
617
+ let c1;
618
+ if (upper === "Q") {
619
+ const [a, b] = [number(), number()];
620
+ c1 = relative ? [x + a, y + b] : [a, b];
621
+ } else c1 = lastControl ? [2 * x - lastControl[0], 2 * y - lastControl[1]] : [x, y];
622
+ const [ex, ey] = [number(), number()];
623
+ const end = relative ? [x + ex, y + ey] : [ex, ey];
624
+ points.push(...bezier([x, y], [c1, end]));
625
+ [x, y] = end;
626
+ anchors.push(end);
627
+ lastControl = c1;
628
+ continue;
629
+ } else {
630
+ const [rx, ry, rotation] = [
631
+ number(),
632
+ number(),
633
+ number()
634
+ ];
635
+ const [largeArc, sweep] = [flag(), flag()];
636
+ const [ex, ey] = [number(), number()];
637
+ const end = relative ? [x + ex, y + ey] : [ex, ey];
638
+ points.push(...arcPoints(x, y, rx, ry, rotation, largeArc, sweep, end[0], end[1]));
639
+ [x, y] = end;
640
+ anchors.push(end);
641
+ lastControl = void 0;
642
+ continue;
643
+ }
644
+ points.push([x, y]);
645
+ anchors.push([x, y]);
646
+ }
647
+ finish();
648
+ return subpaths;
649
+ }
650
+ var IDENTITY = [
651
+ 1,
652
+ 0,
653
+ 0,
654
+ 1,
655
+ 0,
656
+ 0
657
+ ];
658
+ /** `outer` applied after `inner`. */
659
+ var compose = (outer, inner) => [
660
+ outer[0] * inner[0] + outer[2] * inner[1],
661
+ outer[1] * inner[0] + outer[3] * inner[1],
662
+ outer[0] * inner[2] + outer[2] * inner[3],
663
+ outer[1] * inner[2] + outer[3] * inner[3],
664
+ outer[0] * inner[4] + outer[2] * inner[5] + outer[4],
665
+ outer[1] * inner[4] + outer[3] * inner[5] + outer[5]
666
+ ];
667
+ var apply = (m, [x, y]) => [m[0] * x + m[2] * y + m[4], m[1] * x + m[3] * y + m[5]];
668
+ var FUNCTION = /\s*,?\s*([a-zA-Z]+)\s*\(([^)]*)\)/y;
669
+ /** The matrix a `transform` attribute stands for, or Unsupported saying what in it is not understood. */
670
+ function parseTransform(text, tag) {
671
+ let matrix = IDENTITY;
672
+ let at = 0;
673
+ const source = text.trim();
674
+ while (at < source.length) {
675
+ FUNCTION.lastIndex = at;
676
+ const found = FUNCTION.exec(source);
677
+ if (!found) throw new Unsupported(`transform on <${tag}> is not one this reader understands: ${JSON.stringify(text.slice(0, 60))}`);
678
+ at = FUNCTION.lastIndex;
679
+ const args = (found[2].match(/[-+]?(?:\d*\.\d+|\d+\.?)(?:[eE][-+]?\d+)?/g) ?? []).map(Number);
680
+ const need = (counts) => {
681
+ if (!counts.includes(args.length)) throw new Unsupported(`${found[1]}() in the transform on <${tag}> takes ${counts.join(" or ")} numbers, not ${args.length}`);
682
+ };
683
+ let next;
684
+ switch (found[1]) {
685
+ case "matrix":
686
+ need([6]);
687
+ next = args;
688
+ break;
689
+ case "translate":
690
+ need([1, 2]);
691
+ next = [
692
+ 1,
693
+ 0,
694
+ 0,
695
+ 1,
696
+ args[0],
697
+ args[1] ?? 0
698
+ ];
699
+ break;
700
+ case "scale":
701
+ need([1, 2]);
702
+ next = [
703
+ args[0],
704
+ 0,
705
+ 0,
706
+ args[1] ?? args[0],
707
+ 0,
708
+ 0
709
+ ];
710
+ break;
711
+ case "rotate": {
712
+ need([1, 3]);
713
+ const angle = args[0] * Math.PI / 180;
714
+ const [cos, sin] = [Math.cos(angle), Math.sin(angle)];
715
+ next = [
716
+ cos,
717
+ sin,
718
+ -sin,
719
+ cos,
720
+ 0,
721
+ 0
722
+ ];
723
+ if (args.length === 3) next = compose(compose([
724
+ 1,
725
+ 0,
726
+ 0,
727
+ 1,
728
+ args[1],
729
+ args[2]
730
+ ], next), [
731
+ 1,
732
+ 0,
733
+ 0,
734
+ 1,
735
+ -args[1],
736
+ -args[2]
737
+ ]);
738
+ break;
739
+ }
740
+ case "skewX":
741
+ need([1]);
742
+ next = [
743
+ 1,
744
+ 0,
745
+ Math.tan(args[0] * Math.PI / 180),
746
+ 1,
747
+ 0,
748
+ 0
749
+ ];
750
+ break;
751
+ case "skewY":
752
+ need([1]);
753
+ next = [
754
+ 1,
755
+ Math.tan(args[0] * Math.PI / 180),
756
+ 0,
757
+ 1,
758
+ 0,
759
+ 0
760
+ ];
761
+ break;
762
+ default: throw new Unsupported(`transform on <${tag}> has ${found[1]}(), which is not an SVG transform`);
763
+ }
764
+ matrix = compose(matrix, next);
765
+ }
766
+ return matrix;
767
+ }
768
+ /** The document is not something this reader can take apart; the message says where. */
769
+ var XmlError = class extends Error {};
770
+ var MAX_DEPTH = 200;
771
+ var ENTITIES = {
772
+ amp: "&",
773
+ lt: "<",
774
+ gt: ">",
775
+ quot: "\"",
776
+ apos: "'"
777
+ };
778
+ function decode(text) {
779
+ return text.replace(/&(#x[0-9a-fA-F]+|#[0-9]+|[a-zA-Z]+);/g, (whole, name) => {
780
+ if (name.startsWith("#")) {
781
+ const code = name[1] === "x" ? parseInt(name.slice(2), 16) : parseInt(name.slice(1), 10);
782
+ return Number.isInteger(code) && code > 0 && code <= 1114111 ? String.fromCodePoint(code) : whole;
783
+ }
784
+ return ENTITIES[name] ?? whole;
785
+ });
786
+ }
787
+ var local = (name) => name.slice(name.lastIndexOf(":") + 1);
788
+ /** Where `needle` first appears at or after `from`, or an XmlError saying what was left open. */
789
+ function after(text, needle, from, what) {
790
+ const at = text.indexOf(needle, from);
791
+ if (at < 0) throw new XmlError(`${what} is never closed`);
792
+ return at + needle.length;
793
+ }
794
+ /** The end of a `<!DOCTYPE ...>`, which may hold a bracketed subset with `>` inside it. Nothing in it is read. */
795
+ function afterDoctype(text, from) {
796
+ let depth = 0;
797
+ for (let at = from; at < text.length; at++) {
798
+ const ch = text[at];
799
+ if (ch === "[") depth++;
800
+ else if (ch === "]") depth--;
801
+ else if (ch === ">" && depth <= 0) return at + 1;
802
+ }
803
+ throw new XmlError("<!DOCTYPE is never closed");
804
+ }
805
+ var ATTRIBUTE = /([^\s=/>]+)\s*=\s*(?:"([^"]*)"|'([^']*)')/y;
806
+ /** The root element of a document. */
807
+ function parseXml(source) {
808
+ const text = source.charCodeAt(0) === 65279 ? source.slice(1) : source;
809
+ const stack = [];
810
+ let root;
811
+ let at = 0;
812
+ while (at < text.length) {
813
+ const open = text.indexOf("<", at);
814
+ if (open < 0) break;
815
+ if (text.startsWith("<!--", open)) at = after(text, "-->", open + 4, "a comment");
816
+ else if (text.startsWith("<![CDATA[", open)) at = after(text, "]]>", open + 9, "a CDATA section");
817
+ else if (text.startsWith("<?", open)) at = after(text, "?>", open + 2, "a processing instruction");
818
+ else if (text.startsWith("<!", open)) at = afterDoctype(text, open + 2);
819
+ else if (text.startsWith("</", open)) {
820
+ const end = after(text, ">", open + 2, "a closing tag");
821
+ const name = local(text.slice(open + 2, end - 1).trim());
822
+ const top = stack.pop();
823
+ if (!top || top.tag !== name) throw new XmlError(`</${name}> closes ${top ? `<${top.tag}>` : "nothing"}`);
824
+ at = end;
825
+ } else {
826
+ const named = /^<([^\s/>]+)/.exec(text.slice(open, open + 256));
827
+ if (!named) throw new XmlError("a < that opens no tag");
828
+ const element = {
829
+ tag: local(named[1]),
830
+ attrs: /* @__PURE__ */ new Map(),
831
+ children: []
832
+ };
833
+ let cursor = open + named[0].length;
834
+ for (;;) {
835
+ while (cursor < text.length && /\s/.test(text[cursor])) cursor++;
836
+ if (cursor >= text.length) throw new XmlError(`<${element.tag}> is never closed`);
837
+ if (text[cursor] === ">" || text[cursor] === "/" && text[cursor + 1] === ">") break;
838
+ ATTRIBUTE.lastIndex = cursor;
839
+ const attribute = ATTRIBUTE.exec(text);
840
+ if (!attribute) throw new XmlError(`<${element.tag}> has an attribute this reader cannot take apart near "${text.slice(cursor, cursor + 20)}"`);
841
+ const key = attribute[1];
842
+ if (!element.attrs.has(key)) element.attrs.set(key, decode(attribute[2] ?? attribute[3] ?? ""));
843
+ cursor = ATTRIBUTE.lastIndex;
844
+ }
845
+ const selfClosing = text[cursor] === "/";
846
+ const parent = stack[stack.length - 1];
847
+ if (parent) parent.children.push(element);
848
+ else if (root) throw new XmlError("there is more than one root element");
849
+ else root = element;
850
+ if (!selfClosing) {
851
+ stack.push(element);
852
+ if (stack.length > MAX_DEPTH) throw new XmlError(`elements are nested more than ${MAX_DEPTH} deep`);
853
+ }
854
+ at = cursor + (selfClosing ? 2 : 1);
855
+ }
856
+ }
857
+ if (stack.length > 0) throw new XmlError(`<${stack[stack.length - 1].tag}> is never closed`);
858
+ if (!root) throw new XmlError("there is no element");
859
+ return root;
860
+ }
861
+ var ELLIPSE_STEPS = 96;
862
+ var SKIPPED = /* @__PURE__ */ new Set([
863
+ "defs",
864
+ "clipPath",
865
+ "mask",
866
+ "symbol",
867
+ "title",
868
+ "desc",
869
+ "metadata",
870
+ "style",
871
+ "linearGradient",
872
+ "radialGradient",
873
+ "pattern",
874
+ "filter",
875
+ "marker"
876
+ ]);
877
+ var REFUSED = {
878
+ text: "<text> is live text: convert it to outlines in the design tool first",
879
+ tspan: "<tspan> is live text: convert it to outlines in the design tool first",
880
+ use: "<use> points at another element: expand it in the design tool first",
881
+ image: "<image> is a picture inside the logo: measure the logo, not a wrapper around a picture",
882
+ foreignObject: "<foreignObject> is not artwork"
883
+ };
884
+ var numbers = (text) => (text?.match(/[-+]?(?:\d*\.\d+|\d+\.?)(?:[eE][-+]?\d+)?/g) ?? []).map(Number);
885
+ function styleOf(element) {
886
+ const style = /* @__PURE__ */ new Map();
887
+ for (const part of (element.attrs.get("style") ?? "").split(";")) {
888
+ const colon = part.indexOf(":");
889
+ if (colon > 0) style.set(part.slice(0, colon).trim(), part.slice(colon + 1).trim());
890
+ }
891
+ return style;
892
+ }
893
+ /** A property of an element: its style, then its attribute. */
894
+ var property = (element, style, name) => style.get(name) ?? element.attrs.get(name);
895
+ var length = (element, name) => {
896
+ const value = Number(numbers(element.attrs.get(name))[0] ?? 0);
897
+ return Number.isFinite(value) ? value : 0;
898
+ };
899
+ /** The outline of a rectangle, with the corners rounded when rx or ry says so. */
900
+ function rectangle(element) {
901
+ const [x, y, w, h] = [
902
+ length(element, "x"),
903
+ length(element, "y"),
904
+ length(element, "width"),
905
+ length(element, "height")
906
+ ];
907
+ const corners = [
908
+ [x, y],
909
+ [x + w, y],
910
+ [x + w, y + h],
911
+ [x, y + h]
912
+ ];
913
+ const rawX = element.attrs.has("rx") ? length(element, "rx") : void 0;
914
+ const rawY = element.attrs.has("ry") ? length(element, "ry") : void 0;
915
+ const rx = Math.min(Math.abs(rawX ?? rawY ?? 0), w / 2);
916
+ const ry = Math.min(Math.abs(rawY ?? rawX ?? 0), h / 2);
917
+ if (rx <= 0 || ry <= 0) return {
918
+ polygon: corners,
919
+ anchors: corners
920
+ };
921
+ const quarter = ELLIPSE_STEPS / 4;
922
+ const polygon = [];
923
+ const corner = (cx, cy, from) => {
924
+ for (let k = 0; k <= quarter; k++) {
925
+ const t = (from + 90 * k / quarter) * Math.PI / 180;
926
+ polygon.push([cx + rx * Math.cos(t), cy + ry * Math.sin(t)]);
927
+ }
928
+ };
929
+ corner(x + w - rx, y + ry, -90);
930
+ corner(x + w - rx, y + h - ry, 0);
931
+ corner(x + rx, y + h - ry, 90);
932
+ corner(x + rx, y + ry, 180);
933
+ return {
934
+ polygon,
935
+ anchors: corners
936
+ };
937
+ }
938
+ function readViewBox(root) {
939
+ const given = numbers(root.attrs.get("viewBox"));
940
+ if (given.length >= 4) {
941
+ const [vx, vy, vw, vh] = given;
942
+ if (vw > 0 && vh > 0) return [
943
+ vx,
944
+ vy,
945
+ vw,
946
+ vh
947
+ ];
948
+ } else {
949
+ const [w, h] = [numbers(root.attrs.get("width"))[0] ?? 0, numbers(root.attrs.get("height"))[0] ?? 0];
950
+ if (w > 0 && h > 0) return [
951
+ 0,
952
+ 0,
953
+ w,
954
+ h
955
+ ];
956
+ }
957
+ throw new Unsupported("the SVG has no viewBox or size");
958
+ }
959
+ /** The SVG's viewBox and shapes, or Unsupported saying what could not be read. */
960
+ function readSvg(text) {
961
+ let root;
962
+ try {
963
+ root = parseXml(text);
964
+ } catch (error) {
965
+ if (error instanceof XmlError) throw new Unsupported(`not an SVG: ${error.message}`);
966
+ throw error;
967
+ }
968
+ if (root.tag !== "svg") throw new Unsupported(`not an SVG: the root element is ${root.tag}`);
969
+ const viewBox = readViewBox(root);
970
+ const shapes = [];
971
+ let stroked = 0;
972
+ let classed = false;
973
+ let styled = false;
974
+ const walk = (element, inherited) => {
975
+ const tag = element.tag;
976
+ if (tag === "style") styled = true;
977
+ if (SKIPPED.has(tag)) return;
978
+ const refusal = REFUSED[tag];
979
+ if (refusal) throw new Unsupported(refusal);
980
+ const style = styleOf(element);
981
+ if (property(element, style, "display") === "none") return;
982
+ const own = element.attrs.get("transform");
983
+ const matrix = own ? compose(inherited.matrix, parseTransform(own, tag)) : inherited.matrix;
984
+ const fillText = property(element, style, "fill");
985
+ const fill = fillText === void 0 ? inherited.fill : fillText.trim().toLowerCase();
986
+ const strokeText = property(element, style, "stroke");
987
+ const stroke = strokeText === void 0 ? inherited.stroke : strokeText.trim().toLowerCase();
988
+ const ruleText = property(element, style, "fill-rule");
989
+ const rule = ruleText === "evenodd" || ruleText === "nonzero" ? ruleText : inherited.rule;
990
+ const invisible = inherited.invisible || property(element, style, "visibility") === "hidden" || Number(property(element, style, "opacity") ?? 1) === 0 || Number(property(element, style, "fill-opacity") ?? 1) === 0;
991
+ if (element.attrs.has("class")) classed = true;
992
+ let polygons = [];
993
+ let anchors = [];
994
+ if (tag === "rect") {
995
+ const shape = rectangle(element);
996
+ polygons = [shape.polygon];
997
+ anchors = shape.anchors;
998
+ } else if (tag === "polygon" || tag === "polyline") {
999
+ const values = numbers(element.attrs.get("points"));
1000
+ const points = [];
1001
+ for (let i = 0; i + 1 < values.length; i += 2) points.push([values[i], values[i + 1]]);
1002
+ polygons = [points];
1003
+ anchors = [...points];
1004
+ } else if (tag === "circle" || tag === "ellipse") {
1005
+ const [cx, cy] = [length(element, "cx"), length(element, "cy")];
1006
+ const rx = element.attrs.has("r") ? length(element, "r") : length(element, "rx");
1007
+ const ry = element.attrs.has("r") ? length(element, "r") : length(element, "ry");
1008
+ polygons = [Array.from({ length: ELLIPSE_STEPS }, (_, k) => [cx + rx * Math.cos(2 * Math.PI * k / ELLIPSE_STEPS), cy + ry * Math.sin(2 * Math.PI * k / ELLIPSE_STEPS)])];
1009
+ anchors = [
1010
+ [cx - rx, cy],
1011
+ [cx + rx, cy],
1012
+ [cx, cy - ry],
1013
+ [cx, cy + ry]
1014
+ ];
1015
+ } else if (tag === "path") {
1016
+ const subpaths = pathSubpaths(element.attrs.get("d") ?? "");
1017
+ polygons = subpaths.map((s) => s.points);
1018
+ anchors = subpaths.flatMap((s) => s.anchors);
1019
+ }
1020
+ if (polygons.length > 0) {
1021
+ const painted = fill !== "none" && fill !== "transparent";
1022
+ if (stroke !== void 0 && stroke !== "none" && stroke !== "transparent") stroked++;
1023
+ if (painted && !invisible) {
1024
+ const move = (p) => apply(matrix, p);
1025
+ shapes.push({
1026
+ polygons: polygons.map((poly) => poly.map(move)),
1027
+ anchors: anchors.map(move),
1028
+ fill: fill || "#000000",
1029
+ rule: rule ?? "nonzero"
1030
+ });
1031
+ }
1032
+ }
1033
+ for (const child of element.children) walk(child, {
1034
+ fill,
1035
+ rule,
1036
+ stroke,
1037
+ matrix,
1038
+ invisible
1039
+ });
1040
+ };
1041
+ walk(root, {
1042
+ fill: void 0,
1043
+ rule: void 0,
1044
+ stroke: void 0,
1045
+ matrix: IDENTITY,
1046
+ invisible: false
1047
+ });
1048
+ const notes = [];
1049
+ if (classed && styled) notes.push("a <style> element colors shapes by class, which is not read: a shape it colors is measured in black, so the color scores may be off");
1050
+ if (stroked > 0) notes.push(`${stroked} shape${stroked === 1 ? " is" : "s are"} drawn with a stroke, which is not measured: outline strokes in the design tool to measure them`);
1051
+ if (shapes.length === 0 && stroked > 0) throw new Unsupported("the logo is drawn with strokes only, which are not measured: outline them in the design tool first");
1052
+ return {
1053
+ viewBox,
1054
+ shapes,
1055
+ notes
1056
+ };
1057
+ }
1058
+ var AXES = [
1059
+ "mirror-x",
1060
+ "mirror-y",
1061
+ "rot180",
1062
+ "rot90"
1063
+ ];
1064
+ var TOLERANCE = .97;
1065
+ /** The grid cut to the bounding box of its ink, or undefined when there is none. */
1066
+ function trim(grid) {
1067
+ let [top, bottom, left, right] = [
1068
+ Infinity,
1069
+ -1,
1070
+ Infinity,
1071
+ -1
1072
+ ];
1073
+ grid.forEach((row, r) => row.forEach((v, c) => {
1074
+ if (!v) return;
1075
+ top = Math.min(top, r);
1076
+ bottom = Math.max(bottom, r);
1077
+ left = Math.min(left, c);
1078
+ right = Math.max(right, c);
1079
+ }));
1080
+ return bottom < 0 ? void 0 : grid.slice(top, bottom + 1).map((row) => row.slice(left, right + 1));
1081
+ }
1082
+ /**
1083
+ * The silhouette and color agreement of two grids of one size: shared ink over all ink, and ink that also kept its label over all ink.
1084
+ * With `slack`, ink counts as shared when the other grid has ink within that many cells, which absorbs the anti-aliased edge of a raster.
1085
+ */
1086
+ function compare(a, b, slack) {
1087
+ const [height, width] = [a.length, a[0].length];
1088
+ let [inkA, inkB, both, same] = [
1089
+ 0,
1090
+ 0,
1091
+ 0,
1092
+ 0
1093
+ ];
1094
+ for (let r = 0; r < height; r++) for (let c = 0; c < width; c++) {
1095
+ if (a[r][c]) inkA++;
1096
+ if (b[r][c]) inkB++;
1097
+ }
1098
+ for (let r = 0; r < height; r++) for (let c = 0; c < width; c++) {
1099
+ if (!a[r][c]) continue;
1100
+ if (b[r][c]) {
1101
+ both++;
1102
+ if (a[r][c] === b[r][c]) same++;
1103
+ } else if (slack > 0) {
1104
+ let near = false;
1105
+ for (let rr = Math.max(r - slack, 0); rr < Math.min(r + slack + 1, height) && !near; rr++) for (let cc = Math.max(c - slack, 0); cc < Math.min(c + slack + 1, width); cc++) if (b[rr][cc]) {
1106
+ near = true;
1107
+ break;
1108
+ }
1109
+ if (near) both++;
1110
+ }
1111
+ }
1112
+ const union = inkA + inkB - both;
1113
+ return {
1114
+ silhouette: both / union,
1115
+ color: same / union
1116
+ };
1117
+ }
1118
+ /** The grid mirrored, flipped and turned, and for a square-ish grid the pair that rot90 compares. */
1119
+ function transforms(grid) {
1120
+ const [height, width] = [grid.length, grid[0].length];
1121
+ const out = {
1122
+ "mirror-x": grid.map((row) => [...row].reverse()),
1123
+ "mirror-y": [...grid].reverse(),
1124
+ rot180: [...grid].reverse().map((row) => [...row].reverse()),
1125
+ rot90: null
1126
+ };
1127
+ if (Math.abs(width - height) <= Math.max(2, .03 * Math.max(width, height))) {
1128
+ const n = Math.min(width, height);
1129
+ const source = grid.slice(0, n).map((row) => row.slice(0, n));
1130
+ out.rot90 = {
1131
+ source,
1132
+ turned: source.map((_, r) => source.map((__, c) => source[n - 1 - c][r]))
1133
+ };
1134
+ }
1135
+ return out;
1136
+ }
1137
+ /** Symmetry, balance and ink share of a grid. Unsupported when the grid has no ink. */
1138
+ function measureLabels(grid, tolerance = TOLERANCE, slack = 0) {
1139
+ const box = trim(grid);
1140
+ if (!box) throw new Unsupported("the logo has nothing to measure: no ink in it");
1141
+ const [height, width] = [box.length, box[0].length];
1142
+ const symmetry = {};
1143
+ for (const [axis, other] of Object.entries(transforms(box))) {
1144
+ if (other === null) {
1145
+ symmetry[axis] = null;
1146
+ continue;
1147
+ }
1148
+ const [source, turned] = Array.isArray(other) ? [box, other] : [other.source, other.turned];
1149
+ const score = compare(source, turned, slack);
1150
+ symmetry[axis] = {
1151
+ silhouette: round(score.silhouette, 4),
1152
+ color: round(score.color, 4)
1153
+ };
1154
+ }
1155
+ let [cells, sumX, sumY] = [
1156
+ 0,
1157
+ 0,
1158
+ 0
1159
+ ];
1160
+ box.forEach((row, r) => row.forEach((v, c) => {
1161
+ if (!v) return;
1162
+ cells++;
1163
+ sumX += c + .5;
1164
+ sumY += r + .5;
1165
+ }));
1166
+ return {
1167
+ axes: AXES.filter((axis) => symmetry[axis] && symmetry[axis].silhouette >= tolerance),
1168
+ symmetry,
1169
+ balance: {
1170
+ x: round((sumX / cells - width / 2) / width, 4),
1171
+ y: round((sumY / cells - height / 2) / height, 4)
1172
+ },
1173
+ ink: round(cells / (width * height), 4),
1174
+ aspect: round(width / height, 4),
1175
+ tolerance
1176
+ };
1177
+ }
1178
+ function gcd(a, b) {
1179
+ return b === 0 ? a : gcd(b, a % b);
1180
+ }
1181
+ /** The grid of an SVG's own points: the coarsest whole-number grid they all sit on, and the points off a stated grid. Only points inside `crop` count. */
1182
+ function gridReport(shapes, crop, stated) {
1183
+ const seen = /* @__PURE__ */ new Set();
1184
+ const points = [];
1185
+ for (const shape of shapes) for (const [x, y] of shape.anchors) {
1186
+ if (crop && !(crop[0] - 1e-9 <= x && x <= crop[0] + crop[2] + 1e-9 && crop[1] - 1e-9 <= y && y <= crop[1] + crop[3] + 1e-9)) continue;
1187
+ const key = `${x},${y}`;
1188
+ if (!seen.has(key)) {
1189
+ seen.add(key);
1190
+ points.push([x, y]);
1191
+ }
1192
+ }
1193
+ const whole = points.flatMap(([x, y]) => [Math.abs(x), Math.abs(y)]);
1194
+ let detected = null;
1195
+ if (whole.length > 0 && whole.every((v) => Math.abs(v - Math.round(v)) < 1e-6)) detected = whole.map(Math.round).reduce(gcd, 0) || null;
1196
+ const off = stated ? points.filter(([x, y]) => ![x, y].every((v) => Math.abs(v / stated - Math.round(v / stated)) * stated < 1e-6)).map(([x, y]) => ({
1197
+ x: round(x, 4),
1198
+ y: round(y, 4)
1199
+ })) : [];
1200
+ return {
1201
+ detected,
1202
+ stated: stated ?? null,
1203
+ off
1204
+ };
1205
+ }
1206
+ /** The ink's bounding box in the SVG's units. The grid covers `region`, so a cell is a fixed step. */
1207
+ function boxOf(grid, region) {
1208
+ const [vx, vy, vw, vh] = region;
1209
+ const [stepX, stepY] = [grid[0].length / vw, grid.length / vh];
1210
+ let [top, bottom, left, right] = [
1211
+ Infinity,
1212
+ -1,
1213
+ Infinity,
1214
+ -1
1215
+ ];
1216
+ grid.forEach((row, r) => row.forEach((v, c) => {
1217
+ if (!v) return;
1218
+ top = Math.min(top, r);
1219
+ bottom = Math.max(bottom, r);
1220
+ left = Math.min(left, c);
1221
+ right = Math.max(right, c);
1222
+ }));
1223
+ return {
1224
+ x: round(vx + left / stepX, 3),
1225
+ y: round(vy + top / stepY, 3),
1226
+ w: round((right - left + 1) / stepX, 3),
1227
+ h: round((bottom - top + 1) / stepY, 3)
1228
+ };
1229
+ }
1230
+ /** An SVG logo measured. `crop` is x, y, width, height in the SVG's units. */
1231
+ function analyzeSvg(text, options = {}) {
1232
+ const { viewBox, shapes, notes } = readSvg(text);
1233
+ const { grid, region } = rasterize(viewBox, shapes, options.crop);
1234
+ return {
1235
+ measurement: {
1236
+ ...measureLabels(grid, options.tolerance ?? .97),
1237
+ grid: gridReport(shapes, options.crop, options.grid),
1238
+ box: boxOf(grid, region)
1239
+ },
1240
+ notes
1241
+ };
1242
+ }
1243
+ /** A raster logo's grid measured, with a one-cell tolerance for its anti-aliased edge. It has no points, so no grid and no box. */
1244
+ function analyzeRaster(grid, options = {}) {
1245
+ return {
1246
+ ...measureLabels(grid, options.tolerance ?? .97, 1),
1247
+ grid: null
1248
+ };
1249
+ }
1250
+ var escape = (text) => text.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
1251
+ /** The figure for an SVG logo already measured, as text. The same measurement draws the same bytes. */
1252
+ function constructionSvg(svgText, result, accent, name) {
1253
+ const { viewBox } = readSvg(svgText);
1254
+ const { box } = result;
1255
+ const pad = Math.max(box.w, box.h) * .12;
1256
+ const [x0, y0] = [box.x - pad, box.y - pad];
1257
+ const [w, h] = [box.w + 2 * pad, box.h + 2 * pad];
1258
+ const captionHeight = Math.max(box.w, box.h) * .2;
1259
+ const unit = Math.max(box.w, box.h) / 100;
1260
+ const uri = `data:image/svg+xml;base64,${Buffer.from(svgText, "utf-8").toString("base64")}`;
1261
+ const total = coordinate(h + captionHeight);
1262
+ const parts = [
1263
+ `<svg xmlns="http://www.w3.org/2000/svg" viewBox="${coordinate(x0)} ${coordinate(y0)} ${coordinate(w)} ${total}" role="img" aria-label="${escape(name)} construction">`,
1264
+ `<rect x="${coordinate(x0)}" y="${coordinate(y0)}" width="${coordinate(w)}" height="${total}" fill="#ffffff"/>`,
1265
+ `<image x="${coordinate(viewBox[0])}" y="${coordinate(viewBox[1])}" width="${coordinate(viewBox[2])}" height="${coordinate(viewBox[3])}" href="${uri}"/>`
1266
+ ];
1267
+ const step = result.grid?.stated ?? result.grid?.detected;
1268
+ if (step) {
1269
+ const gridStroke = `stroke="${accent}" stroke-opacity="0.25" stroke-width="${coordinate(unit * .25)}"`;
1270
+ for (let k = Math.ceil(box.x / step - 1e-9); k * step <= box.x + box.w + 1e-9; k++) parts.push(`<line class="grid" x1="${coordinate(k * step)}" y1="${coordinate(box.y)}" x2="${coordinate(k * step)}" y2="${coordinate(box.y + box.h)}" ${gridStroke}/>`);
1271
+ for (let k = Math.ceil(box.y / step - 1e-9); k * step <= box.y + box.h + 1e-9; k++) parts.push(`<line class="grid" x1="${coordinate(box.x)}" y1="${coordinate(k * step)}" x2="${coordinate(box.x + box.w)}" y2="${coordinate(k * step)}" ${gridStroke}/>`);
1272
+ }
1273
+ parts.push(`<rect class="box" x="${coordinate(box.x)}" y="${coordinate(box.y)}" width="${coordinate(box.w)}" height="${coordinate(box.h)}" fill="none" stroke="${accent}" stroke-width="${coordinate(unit * .4)}"/>`);
1274
+ const [cx, cy] = [box.x + box.w / 2, box.y + box.h / 2];
1275
+ const dash = `stroke-dasharray="${coordinate(unit * 2)} ${coordinate(unit * 1.5)}"`;
1276
+ parts.push(`<line class="axis" x1="${coordinate(cx)}" y1="${coordinate(y0 + pad * .4)}" x2="${coordinate(cx)}" y2="${coordinate(box.y + box.h + pad * .6)}" stroke="${accent}" stroke-width="${coordinate(unit * .4)}" ${dash}/>`);
1277
+ parts.push(`<line class="axis" x1="${coordinate(x0 + pad * .4)}" y1="${coordinate(cy)}" x2="${coordinate(box.x + box.w + pad * .6)}" y2="${coordinate(cy)}" stroke="${accent}" stroke-width="${coordinate(unit * .4)}" ${dash}/>`);
1278
+ const [bx, by] = [cx + result.balance.x * box.w, cy + result.balance.y * box.h];
1279
+ parts.push(`<circle class="center" cx="${coordinate(cx)}" cy="${coordinate(cy)}" r="${coordinate(unit * 2.8)}" fill="none" stroke="${accent}" stroke-width="${coordinate(unit * .4)}"/>`);
1280
+ parts.push(`<circle class="mass" cx="${coordinate(bx)}" cy="${coordinate(by)}" r="${coordinate(unit * 1.6)}" fill="${accent}"/>`);
1281
+ const scores = AXES.flatMap((axis) => result.symmetry[axis] ? [`${axis} ${round(result.symmetry[axis].silhouette * 100)}%`] : []).join(" ");
1282
+ const lines = [
1283
+ `${name}: ${result.axes.join(", ") || `no axis at ${round(result.tolerance * 100)}% or more`}`,
1284
+ scores,
1285
+ `center of mass (dot) ${signed(result.balance.x * 100, 1)}% x, ${signed(result.balance.y * 100, 1)}% y from the box center (ring)${step ? ` · grid ${step}` : ""}`
1286
+ ];
1287
+ const size = unit * 3.2;
1288
+ lines.forEach((line, n) => parts.push(`<text x="${coordinate(x0 + pad * .5)}" y="${coordinate(y0 + h + size * (1.6 + 1.5 * n))}" font-family="Helvetica, Arial, sans-serif" font-size="${coordinate(size)}" fill="#1e1f21">${escape(line)}</text>`));
1289
+ parts.push("</svg>");
1290
+ return `${parts.join("\n")}\n`;
1291
+ }
1292
+ /** The plugin's name, which blazon's config names it by, and the prefix of its finding codes */
1293
+ var NAME = "blazon.logo-geometry";
1294
+ var MANIFEST = {
1295
+ v: 2,
1296
+ roles: ["build"],
1297
+ title: "Logo geometry",
1298
+ description: "Measures each logo's symmetry, balance and grid, checks the axes a brand requires, and draws the construction figure.",
1299
+ version: "1.0.0",
1300
+ timeout_ms: 6e4,
1301
+ env: [
1302
+ "BLAZON_CHROME",
1303
+ "HOME",
1304
+ "TMPDIR"
1305
+ ]
1306
+ };
1307
+ /** The job a build request asks for, or Cannot with the reason. The options are checked later, and wrong ones are findings. */
1308
+ function jobFor(text) {
1309
+ return buildJob(text);
1310
+ }
1311
+ var KEYS = [
1312
+ "logos",
1313
+ "require",
1314
+ "tolerance",
1315
+ "grid",
1316
+ "accent",
1317
+ "figures",
1318
+ "report"
1319
+ ];
1320
+ var LOGO_KEYS = [
1321
+ "id",
1322
+ "crop",
1323
+ "grid",
1324
+ "require",
1325
+ "tolerance"
1326
+ ];
1327
+ var finding = findingFor(NAME);
1328
+ var invalid = (message) => finding("option-invalid", "error", "options", message);
1329
+ /** A color safe to write into an attribute of the figure: a hex, a name, or rgb(), hsl() with plain numbers. */
1330
+ var isColor = (value) => /^(#[0-9a-fA-F]{3,8}|[a-zA-Z]{3,30}|(?:rgb|hsl)a?\([0-9\s.,%/-]{1,60}\))$/.test(value.trim());
1331
+ /**
1332
+ * The options as the plugin uses them, and an `option-invalid` finding for each thing wrong. Nothing here throws: the options are the
1333
+ * person's, not the request's. A wrong option is left at its default and the rest is measured.
1334
+ */
1335
+ function parseOptions(raw, known) {
1336
+ const findings = [];
1337
+ const options = {
1338
+ targets: void 0,
1339
+ figures: true,
1340
+ report: true,
1341
+ all: {
1342
+ require: [],
1343
+ tolerance: TOLERANCE
1344
+ }
1345
+ };
1346
+ if (!isObject(raw)) return {
1347
+ options,
1348
+ findings: [invalid("options must be an object")]
1349
+ };
1350
+ for (const key of Object.keys(raw)) if (!KEYS.includes(key)) findings.push(invalid(`unknown option "${key}"; the options are ${KEYS.join(", ")}`));
1351
+ const axes = (value, where) => {
1352
+ if (value === void 0) return void 0;
1353
+ if (!Array.isArray(value) || value.some((axis) => !AXES.includes(axis))) {
1354
+ findings.push(invalid(`${where} must be a list of ${AXES.join(", ")}`));
1355
+ return;
1356
+ }
1357
+ return [...new Set(value)];
1358
+ };
1359
+ const tolerance = (value, where) => {
1360
+ if (value === void 0) return void 0;
1361
+ if (typeof value !== "number" || !(value > 0 && value <= 1)) {
1362
+ findings.push(invalid(`${where} must be a number above 0 and at most 1`));
1363
+ return;
1364
+ }
1365
+ return value;
1366
+ };
1367
+ const grid = (value, where) => {
1368
+ if (value === void 0) return void 0;
1369
+ if (typeof value !== "number" || !Number.isFinite(value) || value <= 0) {
1370
+ findings.push(invalid(`${where} must be a number above 0`));
1371
+ return;
1372
+ }
1373
+ return value;
1374
+ };
1375
+ options.all.require = axes(raw.require, "require") ?? [];
1376
+ options.all.tolerance = tolerance(raw.tolerance, "tolerance") ?? .97;
1377
+ const all = grid(raw.grid, "grid");
1378
+ if (all !== void 0) options.all.grid = all;
1379
+ if (raw.accent !== void 0) {
1380
+ if (typeof raw.accent === "string" && isColor(raw.accent)) options.accent = raw.accent.trim();
1381
+ else findings.push(invalid("accent must be a color: #rrggbb, a color name, or rgb() or hsl() with numbers"));
1382
+ }
1383
+ for (const key of ["figures", "report"]) {
1384
+ if (raw[key] === void 0) continue;
1385
+ if (typeof raw[key] === "boolean") options[key] = raw[key];
1386
+ else findings.push(invalid(`${key} must be true or false`));
1387
+ }
1388
+ if (raw.logos !== void 0) {
1389
+ if (!Array.isArray(raw.logos)) findings.push(invalid("logos must be a list of asset ids, or of {id, crop?, grid?, require?, tolerance?}"));
1390
+ else {
1391
+ const targets = [];
1392
+ raw.logos.forEach((entry, index) => {
1393
+ const where = `logos[${index}]`;
1394
+ const item = typeof entry === "string" ? { id: entry } : entry;
1395
+ if (!isObject(item) || typeof item.id !== "string") return void findings.push(invalid(`${where} must be an asset id or an object with an id`));
1396
+ for (const key of Object.keys(item)) if (!LOGO_KEYS.includes(key)) findings.push(invalid(`${where} has unknown field "${key}"; the fields are ${LOGO_KEYS.join(", ")}`));
1397
+ if (!known.has(item.id)) return void findings.push(invalid(`${where} names ${JSON.stringify(item.id)}, which the brand has no asset for`));
1398
+ const target = {
1399
+ id: item.id,
1400
+ named: true,
1401
+ require: axes(item.require, `${where}.require`) ?? options.all.require,
1402
+ tolerance: tolerance(item.tolerance, `${where}.tolerance`) ?? options.all.tolerance
1403
+ };
1404
+ const own = grid(item.grid, `${where}.grid`) ?? options.all.grid;
1405
+ if (own !== void 0) target.grid = own;
1406
+ if (item.crop !== void 0) {
1407
+ const crop = item.crop;
1408
+ if (!Array.isArray(crop) || crop.length !== 4 || crop.some((v) => typeof v !== "number" || !Number.isFinite(v)) || crop[2] <= 0 || crop[3] <= 0) findings.push(invalid(`${where}.crop must be [x, y, width, height] with a width and height above 0`));
1409
+ else target.crop = crop;
1410
+ }
1411
+ targets.push(target);
1412
+ });
1413
+ options.targets = targets;
1414
+ }
1415
+ }
1416
+ return {
1417
+ options,
1418
+ findings
1419
+ };
1420
+ }
1421
+ var ACCENT = "#ff5a1f";
1422
+ var DEFAULT_REPORT = "geometry.json";
1423
+ /** The report as JSON with its keys in sorted order at every depth, so the same measurements are the same bytes. */
1424
+ function stable(value) {
1425
+ const sort = (v) => Array.isArray(v) ? v.map(sort) : v && typeof v === "object" ? Object.fromEntries(Object.entries(v).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0).map(([k, x]) => [k, sort(x)])) : v;
1426
+ return `${JSON.stringify(sort(value), null, 2)}\n`;
1427
+ }
1428
+ /** The file a logo's figure is written to: its name, or its whole id when another logo already has that name. */
1429
+ var figureName = (taken, id) => {
1430
+ const plain = `${node_path.default.basename(id)}-construction.svg`;
1431
+ return taken.has(plain) ? `${id.replace(/\//g, "-")}-construction.svg` : plain;
1432
+ };
1433
+ /** The findings a measurement earns: each required axis the logo lacks, and each point off a stated grid. */
1434
+ function judge(target, result) {
1435
+ const found = [];
1436
+ for (const axis of target.require) {
1437
+ if (result.axes.includes(axis)) continue;
1438
+ const score = result.symmetry[axis];
1439
+ found.push(finding("axis-not-held", "error", target.id, score ? `${target.id} lacks ${axis}: its silhouette scores ${fixed(score.silhouette, 2)} and ${fixed(target.tolerance, 2)} is needed` : `${target.id} cannot be tested for ${axis}: that axis is measured only on a logo that is nearly square`));
1440
+ }
1441
+ if (result.grid && result.grid.off.length > 0) {
1442
+ const shown = result.grid.off.slice(0, 5).map((p) => `(${p.x}, ${p.y})`).join(", ");
1443
+ const more = result.grid.off.length > 5 ? ` and ${result.grid.off.length - 5} more` : "";
1444
+ found.push(finding("off-grid", "warning", target.id, `${target.id} has ${result.grid.off.length} point${result.grid.off.length === 1 ? "" : "s"} off the grid of ${result.grid.stated}: ${shown}${more}`));
1445
+ }
1446
+ return found;
1447
+ }
1448
+ async function build(text) {
1449
+ const job = jobFor(text);
1450
+ const brand = readBrand(job.brand);
1451
+ const { options, findings } = parseOptions(job.options, new Set(brand.assets.keys()));
1452
+ const targets = options.targets ?? defaultLogos(brand).map((id) => ({
1453
+ id,
1454
+ named: false,
1455
+ ...options.all.grid !== void 0 && { grid: options.all.grid },
1456
+ require: options.all.require,
1457
+ tolerance: options.all.tolerance
1458
+ }));
1459
+ const accent = options.accent ?? brand.accent ?? ACCENT;
1460
+ const report = {};
1461
+ const figures = /* @__PURE__ */ new Map();
1462
+ const rasters = [];
1463
+ const cannot = (target, reason) => findings.push(finding("not-measured", target.named ? "error" : "warning", target.id, `${target.id} was not measured: ${reason}`));
1464
+ const keep = (target, result, notes) => {
1465
+ report[target.id] = result;
1466
+ findings.push(...judge(target, result));
1467
+ for (const note of notes) findings.push(finding("reading-limited", "warning", target.id, `${target.id}: ${note}`));
1468
+ };
1469
+ for (const target of targets) {
1470
+ const asset = brand.assets.get(target.id);
1471
+ const bytes = siteFile(job.siteDir, asset.file);
1472
+ if (!bytes) {
1473
+ findings.push(finding("file-missing", "error", target.id, `${target.id} is not in the built site at ${asset.file}`));
1474
+ continue;
1475
+ }
1476
+ if (asset.format === "svg") try {
1477
+ const svg = bytes.toString("utf-8");
1478
+ const { measurement, notes } = analyzeSvg(svg, {
1479
+ ...target.crop && { crop: target.crop },
1480
+ ...target.grid !== void 0 && { grid: target.grid },
1481
+ tolerance: target.tolerance
1482
+ });
1483
+ keep(target, measurement, notes);
1484
+ if (options.figures) figures.set(figureName(figures, target.id), constructionSvg(svg, measurement, accent, target.id));
1485
+ } catch (error) {
1486
+ if (!(error instanceof Unsupported)) throw error;
1487
+ cannot(target, error.message);
1488
+ }
1489
+ else if (asset.format === "png" || asset.format === "webp") rasters.push({
1490
+ target,
1491
+ bytes,
1492
+ format: asset.format
1493
+ });
1494
+ else cannot(target, `${asset.format} is not a format this plugin reads; use SVG, PNG or WebP`);
1495
+ }
1496
+ if (rasters.length > 0) {
1497
+ let browser;
1498
+ try {
1499
+ browser = await launchChrome(process.env, "read the PNG and WebP logos with");
1500
+ } catch (error) {
1501
+ if (!(error instanceof Cannot)) throw error;
1502
+ for (const { target } of rasters) findings.push(finding("raster-skipped", "warning", target.id, `${target.id} was not measured: ${error.message}`));
1503
+ }
1504
+ if (browser) try {
1505
+ for (const { target, bytes, format } of rasters) try {
1506
+ const pixels = await decodeRaster(browser, bytes, format, target.crop);
1507
+ keep(target, analyzeRaster(labelRaster(pixels.rgba, pixels.width, pixels.height), { tolerance: target.tolerance }), []);
1508
+ } catch (error) {
1509
+ if (!(error instanceof Unsupported)) throw error;
1510
+ cannot(target, error.message);
1511
+ }
1512
+ } finally {
1513
+ await browser.close();
1514
+ }
1515
+ }
1516
+ if (options.report && Object.keys(report).length > 0) node_fs.default.writeFileSync(node_path.default.join(job.outDir, DEFAULT_REPORT), stable(report));
1517
+ for (const [name, data] of figures) node_fs.default.writeFileSync(node_path.default.join(job.outDir, name), data);
1518
+ return { findings };
1519
+ }
1520
+ runPlugin(process.argv.slice(2), MANIFEST, build, "the logos could not be measured", NAME).then((code) => {
1521
+ process.exitCode = code;
1522
+ });