omni-viewer-core 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 (387) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +80 -0
  3. package/THIRD_PARTY_NOTICES.md +49 -0
  4. package/dist/assets/audio-engine/audio_engine.mjs +2 -0
  5. package/dist/assets/audio-engine/audio_engine.wasm +0 -0
  6. package/dist/assets/pdfjs/pdf.worker.min.mjs +21 -0
  7. package/dist/host/index.d.ts +133 -0
  8. package/dist/host/index.js +10 -0
  9. package/dist/i18n/catalog.en.d.ts +1 -0
  10. package/dist/i18n/catalog.en.js +411 -0
  11. package/dist/i18n/catalog.ko.d.ts +1 -0
  12. package/dist/i18n/catalog.ko.js +68 -0
  13. package/dist/i18n/index.d.ts +18 -0
  14. package/dist/i18n/index.js +41 -0
  15. package/dist/licenses/emscripten.txt +101 -0
  16. package/dist/licenses/kissfft.txt +28 -0
  17. package/dist/licenses/pdfjs-dist.txt +177 -0
  18. package/dist/parsers/a2l/index.d.ts +1 -0
  19. package/dist/parsers/a2l/index.js +1 -0
  20. package/dist/parsers/archive/index.d.ts +22 -0
  21. package/dist/parsers/archive/index.js +46 -0
  22. package/dist/parsers/archive/model.d.ts +29 -0
  23. package/dist/parsers/archive/model.js +1 -0
  24. package/dist/parsers/archive/worker.d.ts +21 -0
  25. package/dist/parsers/archive/worker.js +1 -0
  26. package/dist/parsers/arxml/index.d.ts +1 -0
  27. package/dist/parsers/arxml/index.js +1 -0
  28. package/dist/parsers/asc/index.d.ts +1 -0
  29. package/dist/parsers/asc/index.js +1 -0
  30. package/dist/parsers/audio/index.d.ts +9 -0
  31. package/dist/parsers/audio/index.js +46 -0
  32. package/dist/parsers/automotive/index.d.ts +33 -0
  33. package/dist/parsers/automotive/index.js +973 -0
  34. package/dist/parsers/blf/index.d.ts +1 -0
  35. package/dist/parsers/blf/index.js +1 -0
  36. package/dist/parsers/csv/delimiter.d.ts +31 -0
  37. package/dist/parsers/csv/delimiter.js +151 -0
  38. package/dist/parsers/csv/index.d.ts +30 -0
  39. package/dist/parsers/csv/index.js +108 -0
  40. package/dist/parsers/csv/parseText.d.ts +20 -0
  41. package/dist/parsers/csv/parseText.js +108 -0
  42. package/dist/parsers/csv/sort.d.ts +26 -0
  43. package/dist/parsers/csv/sort.js +224 -0
  44. package/dist/parsers/csv/statistics.d.ts +49 -0
  45. package/dist/parsers/csv/statistics.js +150 -0
  46. package/dist/parsers/dbc/index.d.ts +56 -0
  47. package/dist/parsers/dbc/index.js +94 -0
  48. package/dist/parsers/doc-binary/index.d.ts +35 -0
  49. package/dist/parsers/doc-binary/index.js +267 -0
  50. package/dist/parsers/doc-binary/vscode-parser.d.ts +142 -0
  51. package/dist/parsers/doc-binary/vscode-parser.js +3747 -0
  52. package/dist/parsers/excel/index.d.ts +17 -0
  53. package/dist/parsers/excel/index.js +406 -0
  54. package/dist/parsers/excel/model.d.ts +80 -0
  55. package/dist/parsers/excel/model.js +48 -0
  56. package/dist/parsers/excel/serialize.d.ts +3 -0
  57. package/dist/parsers/excel/serialize.js +78 -0
  58. package/dist/parsers/hdf5/index.d.ts +75 -0
  59. package/dist/parsers/hdf5/index.js +658 -0
  60. package/dist/parsers/hdf5/node.d.ts +21 -0
  61. package/dist/parsers/hdf5/node.js +95 -0
  62. package/dist/parsers/json/index.d.ts +15 -0
  63. package/dist/parsers/json/index.js +102 -0
  64. package/dist/parsers/json/model.d.ts +42 -0
  65. package/dist/parsers/json/model.js +140 -0
  66. package/dist/parsers/json/parse.d.ts +22 -0
  67. package/dist/parsers/json/parse.js +279 -0
  68. package/dist/parsers/json/tokenizer.d.ts +17 -0
  69. package/dist/parsers/json/tokenizer.js +175 -0
  70. package/dist/parsers/jsonl/index.d.ts +14 -0
  71. package/dist/parsers/jsonl/index.js +18 -0
  72. package/dist/parsers/jsonl/model.d.ts +23 -0
  73. package/dist/parsers/jsonl/model.js +1 -0
  74. package/dist/parsers/jsonl/parse.d.ts +7 -0
  75. package/dist/parsers/jsonl/parse.js +34 -0
  76. package/dist/parsers/markdown/index.d.ts +37 -0
  77. package/dist/parsers/markdown/index.js +59 -0
  78. package/dist/parsers/mat/index.d.ts +31 -0
  79. package/dist/parsers/mat/index.js +426 -0
  80. package/dist/parsers/mermaid/index.d.ts +5 -0
  81. package/dist/parsers/mermaid/index.js +3 -0
  82. package/dist/parsers/mf4/index.d.ts +1 -0
  83. package/dist/parsers/mf4/index.js +1 -0
  84. package/dist/parsers/parquet/index.d.ts +21 -0
  85. package/dist/parsers/parquet/index.js +68 -0
  86. package/dist/parsers/pcap/index.d.ts +1 -0
  87. package/dist/parsers/pcap/index.js +1 -0
  88. package/dist/parsers/pcapng/index.d.ts +1 -0
  89. package/dist/parsers/pcapng/index.js +1 -0
  90. package/dist/parsers/plantuml/index.d.ts +5 -0
  91. package/dist/parsers/plantuml/index.js +4 -0
  92. package/dist/parsers/ppt-binary/index.d.ts +5 -0
  93. package/dist/parsers/ppt-binary/index.js +62 -0
  94. package/dist/parsers/ppt-binary/pptBinaryBuildContext.d.ts +12 -0
  95. package/dist/parsers/ppt-binary/pptBinaryBuildContext.js +40 -0
  96. package/dist/parsers/ppt-binary/pptBinaryContainer.d.ts +4 -0
  97. package/dist/parsers/ppt-binary/pptBinaryContainer.js +174 -0
  98. package/dist/parsers/ppt-binary/pptBinaryTypes.d.ts +125 -0
  99. package/dist/parsers/ppt-binary/pptBinaryTypes.js +1 -0
  100. package/dist/parsers/ppt-binary/pptSlideLayouts.d.ts +9 -0
  101. package/dist/parsers/ppt-binary/pptSlideLayouts.js +510 -0
  102. package/dist/parsers/ppt-binary/vscode-parser.d.ts +116 -0
  103. package/dist/parsers/ppt-binary/vscode-parser.js +2853 -0
  104. package/dist/parsers/ppt-binary/vscode.d.ts +4 -0
  105. package/dist/parsers/ppt-binary/vscode.js +12 -0
  106. package/dist/parsers/pptx/index.d.ts +15 -0
  107. package/dist/parsers/pptx/index.js +88 -0
  108. package/dist/parsers/pptx/vscode-parser.d.ts +167 -0
  109. package/dist/parsers/pptx/vscode-parser.js +1503 -0
  110. package/dist/parsers/pptx/vscode.d.ts +4 -0
  111. package/dist/parsers/pptx/vscode.js +18 -0
  112. package/dist/parsers/pptx/zip-reader.d.ts +3 -0
  113. package/dist/parsers/pptx/zip-reader.js +20 -0
  114. package/dist/parsers/proto/index.d.ts +90 -0
  115. package/dist/parsers/proto/index.js +197 -0
  116. package/dist/parsers/psd/index.d.ts +16 -0
  117. package/dist/parsers/psd/index.js +10 -0
  118. package/dist/parsers/shapefile/dbf.d.ts +23 -0
  119. package/dist/parsers/shapefile/dbf.js +112 -0
  120. package/dist/parsers/shapefile/index.d.ts +44 -0
  121. package/dist/parsers/shapefile/index.js +119 -0
  122. package/dist/parsers/shapefile/reproject.d.ts +10 -0
  123. package/dist/parsers/shapefile/reproject.js +41 -0
  124. package/dist/parsers/slide-model.d.ts +106 -0
  125. package/dist/parsers/slide-model.js +1 -0
  126. package/dist/parsers/toml/index.d.ts +15 -0
  127. package/dist/parsers/toml/index.js +18 -0
  128. package/dist/parsers/toml/model.d.ts +15 -0
  129. package/dist/parsers/toml/model.js +1 -0
  130. package/dist/parsers/toml/parse.d.ts +16 -0
  131. package/dist/parsers/toml/parse.js +266 -0
  132. package/dist/parsers/types.d.ts +103 -0
  133. package/dist/parsers/types.js +106 -0
  134. package/dist/parsers/video/index.d.ts +6 -0
  135. package/dist/parsers/video/index.js +2 -0
  136. package/dist/parsers/yaml/index.d.ts +16 -0
  137. package/dist/parsers/yaml/index.js +58 -0
  138. package/dist/parsers/yaml/model.d.ts +22 -0
  139. package/dist/parsers/yaml/model.js +1 -0
  140. package/dist/parsers/yaml/self-loading.d.ts +3 -0
  141. package/dist/parsers/yaml/self-loading.js +19 -0
  142. package/dist/parsers/zip-scan.d.ts +8 -0
  143. package/dist/parsers/zip-scan.js +80 -0
  144. package/dist/registry/container.d.ts +17 -0
  145. package/dist/registry/container.js +49 -0
  146. package/dist/registry/index.d.ts +133 -0
  147. package/dist/registry/index.js +348 -0
  148. package/dist/registry/probe.d.ts +3 -0
  149. package/dist/registry/probe.js +177 -0
  150. package/dist/registry/sniff.d.ts +17 -0
  151. package/dist/registry/sniff.js +57 -0
  152. package/dist/styles/archive.css +10 -0
  153. package/dist/styles/audio.css +66 -0
  154. package/dist/styles/automotive.css +1 -0
  155. package/dist/styles/csv.css +262 -0
  156. package/dist/styles/excel.css +212 -0
  157. package/dist/styles/fallback.css +48 -0
  158. package/dist/styles/hdf5.css +3 -0
  159. package/dist/styles/hwp.css +12 -0
  160. package/dist/styles/image.css +115 -0
  161. package/dist/styles/json.css +342 -0
  162. package/dist/styles/jsonl.css +1 -0
  163. package/dist/styles/markdown.css +10 -0
  164. package/dist/styles/mat.css +2 -0
  165. package/dist/styles/mermaid.css +1 -0
  166. package/dist/styles/parquet.css +2 -0
  167. package/dist/styles/pdf.css +551 -0
  168. package/dist/styles/plantuml.css +1 -0
  169. package/dist/styles/ppt.css +1 -0
  170. package/dist/styles/proto.css +2 -0
  171. package/dist/styles/psd.css +1 -0
  172. package/dist/styles/shapefile.css +25 -0
  173. package/dist/styles/toml.css +1 -0
  174. package/dist/styles/video.css +74 -0
  175. package/dist/styles/word.css +685 -0
  176. package/dist/styles/yaml.css +1 -0
  177. package/dist/viewers/a2l/index.d.ts +15 -0
  178. package/dist/viewers/a2l/index.js +5 -0
  179. package/dist/viewers/archive/archive-preview-decoder.d.ts +4 -0
  180. package/dist/viewers/archive/archive-preview-decoder.js +223 -0
  181. package/dist/viewers/archive/controller.d.ts +24 -0
  182. package/dist/viewers/archive/controller.js +18 -0
  183. package/dist/viewers/archive/index.d.ts +25 -0
  184. package/dist/viewers/archive/index.js +230 -0
  185. package/dist/viewers/archive/preview.d.ts +2 -0
  186. package/dist/viewers/archive/preview.js +2 -0
  187. package/dist/viewers/archive/styles.d.ts +1 -0
  188. package/dist/viewers/archive/styles.js +11 -0
  189. package/dist/viewers/arxml/index.d.ts +15 -0
  190. package/dist/viewers/arxml/index.js +5 -0
  191. package/dist/viewers/asc/index.d.ts +15 -0
  192. package/dist/viewers/asc/index.js +5 -0
  193. package/dist/viewers/audio/controller.d.ts +33 -0
  194. package/dist/viewers/audio/controller.js +49 -0
  195. package/dist/viewers/audio/engine.d.ts +44 -0
  196. package/dist/viewers/audio/engine.js +108 -0
  197. package/dist/viewers/audio/index.d.ts +92 -0
  198. package/dist/viewers/audio/index.js +448 -0
  199. package/dist/viewers/audio/self-loading.d.ts +7 -0
  200. package/dist/viewers/audio/self-loading.js +42 -0
  201. package/dist/viewers/audio/styles.d.ts +1 -0
  202. package/dist/viewers/audio/styles.js +73 -0
  203. package/dist/viewers/automotive/index.d.ts +8 -0
  204. package/dist/viewers/automotive/index.js +152 -0
  205. package/dist/viewers/automotive/styles.d.ts +1 -0
  206. package/dist/viewers/automotive/styles.js +1 -0
  207. package/dist/viewers/avro/index.d.ts +15 -0
  208. package/dist/viewers/avro/index.js +5 -0
  209. package/dist/viewers/bag/index.d.ts +15 -0
  210. package/dist/viewers/bag/index.js +5 -0
  211. package/dist/viewers/blf/index.d.ts +15 -0
  212. package/dist/viewers/blf/index.js +5 -0
  213. package/dist/viewers/csv/controller.d.ts +126 -0
  214. package/dist/viewers/csv/controller.js +598 -0
  215. package/dist/viewers/csv/index.d.ts +48 -0
  216. package/dist/viewers/csv/index.js +846 -0
  217. package/dist/viewers/csv/styles.d.ts +1 -0
  218. package/dist/viewers/csv/styles.js +267 -0
  219. package/dist/viewers/db3/index.d.ts +15 -0
  220. package/dist/viewers/db3/index.js +5 -0
  221. package/dist/viewers/dbc/index.d.ts +15 -0
  222. package/dist/viewers/dbc/index.js +5 -0
  223. package/dist/viewers/diagram.d.ts +14 -0
  224. package/dist/viewers/diagram.js +95 -0
  225. package/dist/viewers/excel/controller.d.ts +108 -0
  226. package/dist/viewers/excel/controller.js +548 -0
  227. package/dist/viewers/excel/grid.d.ts +28 -0
  228. package/dist/viewers/excel/grid.js +99 -0
  229. package/dist/viewers/excel/index.d.ts +37 -0
  230. package/dist/viewers/excel/index.js +620 -0
  231. package/dist/viewers/excel/self-loading.d.ts +6 -0
  232. package/dist/viewers/excel/self-loading.js +13 -0
  233. package/dist/viewers/excel/styles.d.ts +1 -0
  234. package/dist/viewers/excel/styles.js +216 -0
  235. package/dist/viewers/fallback/index.d.ts +17 -0
  236. package/dist/viewers/fallback/index.js +130 -0
  237. package/dist/viewers/fallback/styles.d.ts +1 -0
  238. package/dist/viewers/fallback/styles.js +49 -0
  239. package/dist/viewers/hdf5/index.d.ts +19 -0
  240. package/dist/viewers/hdf5/index.js +170 -0
  241. package/dist/viewers/hdf5/styles.d.ts +1 -0
  242. package/dist/viewers/hdf5/styles.js +4 -0
  243. package/dist/viewers/hwp/controller.d.ts +19 -0
  244. package/dist/viewers/hwp/controller.js +22 -0
  245. package/dist/viewers/hwp/index.d.ts +39 -0
  246. package/dist/viewers/hwp/index.js +271 -0
  247. package/dist/viewers/hwp/self-loading.d.ts +2 -0
  248. package/dist/viewers/hwp/self-loading.js +6 -0
  249. package/dist/viewers/hwp/styles.d.ts +1 -0
  250. package/dist/viewers/hwp/styles.js +13 -0
  251. package/dist/viewers/image/controller.d.ts +210 -0
  252. package/dist/viewers/image/controller.js +336 -0
  253. package/dist/viewers/image/decode.d.ts +54 -0
  254. package/dist/viewers/image/decode.js +150 -0
  255. package/dist/viewers/image/index.d.ts +38 -0
  256. package/dist/viewers/image/index.js +749 -0
  257. package/dist/viewers/image/limits.d.ts +18 -0
  258. package/dist/viewers/image/limits.js +20 -0
  259. package/dist/viewers/image/styles.d.ts +1 -0
  260. package/dist/viewers/image/styles.js +119 -0
  261. package/dist/viewers/json/controller.d.ts +89 -0
  262. package/dist/viewers/json/controller.js +411 -0
  263. package/dist/viewers/json/index.d.ts +25 -0
  264. package/dist/viewers/json/index.js +503 -0
  265. package/dist/viewers/json/styles.d.ts +1 -0
  266. package/dist/viewers/json/styles.js +346 -0
  267. package/dist/viewers/json/transforms.d.ts +27 -0
  268. package/dist/viewers/json/transforms.js +253 -0
  269. package/dist/viewers/jsonl/controller.d.ts +48 -0
  270. package/dist/viewers/jsonl/controller.js +136 -0
  271. package/dist/viewers/jsonl/index.d.ts +22 -0
  272. package/dist/viewers/jsonl/index.js +184 -0
  273. package/dist/viewers/jsonl/styles.d.ts +1 -0
  274. package/dist/viewers/jsonl/styles.js +1 -0
  275. package/dist/viewers/markdown/controller.d.ts +50 -0
  276. package/dist/viewers/markdown/controller.js +62 -0
  277. package/dist/viewers/markdown/index.d.ts +64 -0
  278. package/dist/viewers/markdown/index.js +425 -0
  279. package/dist/viewers/markdown/math.d.ts +21 -0
  280. package/dist/viewers/markdown/math.js +100 -0
  281. package/dist/viewers/markdown/self-loading.d.ts +5 -0
  282. package/dist/viewers/markdown/self-loading.js +48 -0
  283. package/dist/viewers/markdown/styles.d.ts +1 -0
  284. package/dist/viewers/markdown/styles.js +11 -0
  285. package/dist/viewers/mat/index.d.ts +19 -0
  286. package/dist/viewers/mat/index.js +113 -0
  287. package/dist/viewers/mat/styles.d.ts +1 -0
  288. package/dist/viewers/mat/styles.js +3 -0
  289. package/dist/viewers/media.d.ts +9 -0
  290. package/dist/viewers/media.js +77 -0
  291. package/dist/viewers/mermaid/index.d.ts +17 -0
  292. package/dist/viewers/mermaid/index.js +6 -0
  293. package/dist/viewers/mermaid/self-loading.d.ts +2 -0
  294. package/dist/viewers/mermaid/self-loading.js +2 -0
  295. package/dist/viewers/mf4/index.d.ts +15 -0
  296. package/dist/viewers/mf4/index.js +5 -0
  297. package/dist/viewers/parquet/controller.d.ts +37 -0
  298. package/dist/viewers/parquet/controller.js +26 -0
  299. package/dist/viewers/parquet/index.d.ts +23 -0
  300. package/dist/viewers/parquet/index.js +134 -0
  301. package/dist/viewers/parquet/styles.d.ts +1 -0
  302. package/dist/viewers/parquet/styles.js +3 -0
  303. package/dist/viewers/pcap/index.d.ts +15 -0
  304. package/dist/viewers/pcap/index.js +5 -0
  305. package/dist/viewers/pcapng/index.d.ts +15 -0
  306. package/dist/viewers/pcapng/index.js +5 -0
  307. package/dist/viewers/pdf/controller.d.ts +120 -0
  308. package/dist/viewers/pdf/controller.js +191 -0
  309. package/dist/viewers/pdf/editing.d.ts +26 -0
  310. package/dist/viewers/pdf/editing.js +265 -0
  311. package/dist/viewers/pdf/index.d.ts +88 -0
  312. package/dist/viewers/pdf/index.js +1400 -0
  313. package/dist/viewers/pdf/self-loading.d.ts +6 -0
  314. package/dist/viewers/pdf/self-loading.js +14 -0
  315. package/dist/viewers/pdf/styles.d.ts +1 -0
  316. package/dist/viewers/pdf/styles.js +555 -0
  317. package/dist/viewers/plantuml/index.d.ts +17 -0
  318. package/dist/viewers/plantuml/index.js +6 -0
  319. package/dist/viewers/plantuml/self-loading.d.ts +2 -0
  320. package/dist/viewers/plantuml/self-loading.js +2 -0
  321. package/dist/viewers/ppt/chart.d.ts +8 -0
  322. package/dist/viewers/ppt/chart.js +83 -0
  323. package/dist/viewers/ppt/controller.d.ts +34 -0
  324. package/dist/viewers/ppt/controller.js +27 -0
  325. package/dist/viewers/ppt/index.d.ts +33 -0
  326. package/dist/viewers/ppt/index.js +101 -0
  327. package/dist/viewers/ppt/render.d.ts +5 -0
  328. package/dist/viewers/ppt/render.js +144 -0
  329. package/dist/viewers/ppt/self-loading.d.ts +9 -0
  330. package/dist/viewers/ppt/self-loading.js +4 -0
  331. package/dist/viewers/ppt/styles.d.ts +1 -0
  332. package/dist/viewers/ppt/styles.js +1 -0
  333. package/dist/viewers/proto/index.d.ts +17 -0
  334. package/dist/viewers/proto/index.js +170 -0
  335. package/dist/viewers/proto/styles.d.ts +1 -0
  336. package/dist/viewers/proto/styles.js +2 -0
  337. package/dist/viewers/psd/index.d.ts +27 -0
  338. package/dist/viewers/psd/index.js +39 -0
  339. package/dist/viewers/psd/self-loading.d.ts +10 -0
  340. package/dist/viewers/psd/self-loading.js +20 -0
  341. package/dist/viewers/psd/styles.d.ts +1 -0
  342. package/dist/viewers/psd/styles.js +1 -0
  343. package/dist/viewers/reqif/index.d.ts +15 -0
  344. package/dist/viewers/reqif/index.js +5 -0
  345. package/dist/viewers/shapefile/index.d.ts +35 -0
  346. package/dist/viewers/shapefile/index.js +336 -0
  347. package/dist/viewers/shapefile/self-loading.d.ts +7 -0
  348. package/dist/viewers/shapefile/self-loading.js +32 -0
  349. package/dist/viewers/shapefile/styles.d.ts +1 -0
  350. package/dist/viewers/shapefile/styles.js +28 -0
  351. package/dist/viewers/stp/index.d.ts +15 -0
  352. package/dist/viewers/stp/index.js +5 -0
  353. package/dist/viewers/structured-styles.d.ts +1 -0
  354. package/dist/viewers/structured-styles.js +1 -0
  355. package/dist/viewers/structured.d.ts +36 -0
  356. package/dist/viewers/structured.js +138 -0
  357. package/dist/viewers/toml/controller.d.ts +38 -0
  358. package/dist/viewers/toml/controller.js +61 -0
  359. package/dist/viewers/toml/index.d.ts +18 -0
  360. package/dist/viewers/toml/index.js +34 -0
  361. package/dist/viewers/types.d.ts +36 -0
  362. package/dist/viewers/types.js +9 -0
  363. package/dist/viewers/video/controller.d.ts +29 -0
  364. package/dist/viewers/video/controller.js +54 -0
  365. package/dist/viewers/video/index.d.ts +18 -0
  366. package/dist/viewers/video/index.js +305 -0
  367. package/dist/viewers/video/styles.d.ts +1 -0
  368. package/dist/viewers/video/styles.js +79 -0
  369. package/dist/viewers/word/controller.d.ts +19 -0
  370. package/dist/viewers/word/controller.js +22 -0
  371. package/dist/viewers/word/docx-preprocess.d.ts +63 -0
  372. package/dist/viewers/word/docx-preprocess.js +136 -0
  373. package/dist/viewers/word/index.d.ts +32 -0
  374. package/dist/viewers/word/index.js +187 -0
  375. package/dist/viewers/word/normalize-docx.d.ts +2 -0
  376. package/dist/viewers/word/normalize-docx.js +50 -0
  377. package/dist/viewers/word/paginate.d.ts +1 -0
  378. package/dist/viewers/word/paginate.js +1035 -0
  379. package/dist/viewers/word/self-loading.d.ts +2 -0
  380. package/dist/viewers/word/self-loading.js +7 -0
  381. package/dist/viewers/word/styles.d.ts +1 -0
  382. package/dist/viewers/word/styles.js +686 -0
  383. package/dist/viewers/yaml/controller.d.ts +42 -0
  384. package/dist/viewers/yaml/controller.js +41 -0
  385. package/dist/viewers/yaml/index.d.ts +21 -0
  386. package/dist/viewers/yaml/index.js +20 -0
  387. package/package.json +375 -0
@@ -0,0 +1,749 @@
1
+ // Image viewer — DOM renderer consuming ImageController (DESIGN.md §3-②,
2
+ // docs/viewers/image.md). CSP rules: no eval, no inline handlers, no innerHTML.
3
+ // Mount is async and renders inside a shadow root by default (§6).
4
+ //
5
+ // Optional services (image.md §2, I8): `save` (Save As PNG), `writeback`
6
+ // (out of v1 scope), `backgroundRemoval`, `spriteDetection`. All degrade — the
7
+ // tool renders disabled with a reason, never hidden. The four current platforms
8
+ // gate `save` in their smoke, but core keeps degraded mode for future hosts.
9
+ import { MountAbortedError, VIEWER_ROOT_CLASS } from '../types.js';
10
+ import { createImageController, filterToCss, makeAnnotation } from './controller.js';
11
+ import { decodeImage } from './decode.js';
12
+ import { canvasEditable, IMAGE_LIMITS } from './limits.js';
13
+ import { imageViewerCss } from './styles.js';
14
+ export { createImageController } from './controller.js';
15
+ export { decodeImage, detectImageMime, isSvgText, isAnimated } from './decode.js';
16
+ export { IMAGE_LIMITS, canvasEditable } from './limits.js';
17
+ export { imageViewerCss } from './styles.js';
18
+ /** Viewer metadata — single source for the registry codegen (DESIGN.md §7). */
19
+ export const IMAGE_VIEWER_META = {
20
+ id: 'image',
21
+ displayNameKey: 'image.title',
22
+ extensions: ['jpg', 'jpeg', 'png', 'gif', 'bmp', 'webp', 'svg'],
23
+ priority: 15,
24
+ requiredServices: [],
25
+ optionalServices: ['save', 'writeback', 'backgroundRemoval', 'spriteDetection'],
26
+ inputOwnership: 'borrows'
27
+ };
28
+ /**
29
+ * Export file name (image.md I7): the edited image always saves as PNG, so the
30
+ * proposed name is coerced to `.png` regardless of the source extension. This
31
+ * is an intentional compatibility change — the UI announces it.
32
+ */
33
+ export function imageExportFileName(sourceName) {
34
+ const stem = sourceName.replace(/\.[^./\\]+$/, '') || sourceName;
35
+ return `${stem}-edited.png`;
36
+ }
37
+ const PRESET_KEYS = {
38
+ original: 'image.preset.original',
39
+ bright: 'image.preset.bright',
40
+ dark: 'image.preset.dark',
41
+ vintage: 'image.preset.vintage',
42
+ bw: 'image.preset.bw'
43
+ };
44
+ export async function mountImageViewer(input, container, ctx, options = {}) {
45
+ if (options.signal?.aborted)
46
+ throw new MountAbortedError();
47
+ const controller = createImageController();
48
+ const isolation = options.styleIsolation ?? 'shadow';
49
+ let root;
50
+ if (isolation === 'shadow' && typeof container.attachShadow === 'function') {
51
+ root = container.shadowRoot ?? container.attachShadow({ mode: 'open' });
52
+ const style = document.createElement('style');
53
+ style.textContent = imageViewerCss;
54
+ root.appendChild(style);
55
+ }
56
+ else {
57
+ container.classList.add(VIEWER_ROOT_CLASS, 'omni-viewer--image');
58
+ root = container;
59
+ }
60
+ const t = ctx.i18n.t.bind(ctx.i18n);
61
+ const disposers = [];
62
+ let toastTimer = null;
63
+ let decoded = null;
64
+ const el = (tag, className, text) => {
65
+ const node = document.createElement(tag);
66
+ if (className)
67
+ node.className = className;
68
+ if (text !== undefined)
69
+ node.textContent = text;
70
+ return node;
71
+ };
72
+ const on = (target, type, handler) => {
73
+ target.addEventListener(type, handler);
74
+ disposers.push(() => target.removeEventListener(type, handler));
75
+ };
76
+ // jsdom (and canvas-less environments) throw from getContext — treat as
77
+ // "no 2d context available" so rendering degrades instead of crashing.
78
+ const ctx2d = (canvas) => {
79
+ try {
80
+ return canvas.getContext('2d');
81
+ }
82
+ catch {
83
+ return null;
84
+ }
85
+ };
86
+ const button = (label, ariaLabel) => {
87
+ const b = el('button', undefined, label);
88
+ b.type = 'button';
89
+ if (ariaLabel)
90
+ b.setAttribute('aria-label', ariaLabel);
91
+ return b;
92
+ };
93
+ // --- static frame -------------------------------------------------------
94
+ const frame = el('div', 'omni-image');
95
+ const toolbar = el('div', 'omni-image__toolbar');
96
+ const zoomOutBtn = button('−', t('image.zoomOut'));
97
+ const zoomInBtn = button('+', t('image.zoomIn'));
98
+ const fitBtn = button(t('image.fit'));
99
+ const actualBtn = button('100%');
100
+ const zoomLabel = el('span', 'omni-image__meta');
101
+ const rotateBtn = button('⟳', t('image.rotate'));
102
+ const flipHBtn = button('⇋', t('image.flipH'));
103
+ const flipVBtn = button('⇅', t('image.flipV'));
104
+ const gridBtn = button(t('image.grid'));
105
+ const resetBtn = button(t('image.reset'));
106
+ const presetSelect = el('select');
107
+ presetSelect.setAttribute('aria-label', t('image.filter'));
108
+ for (const key of ['original', 'bright', 'dark', 'vintage', 'bw']) {
109
+ const opt = el('option', undefined, t(PRESET_KEYS[key]));
110
+ opt.value = key;
111
+ presetSelect.appendChild(opt);
112
+ }
113
+ const bgBtn = button(t('image.tool.removeBackground'));
114
+ const spriteBtn = button(t('image.tool.detectSprites'));
115
+ const saveBtn = button(t('image.saveAsPng'));
116
+ const spacer = el('span', 'omni-image__spacer');
117
+ const meta = el('span', 'omni-image__meta');
118
+ on(zoomOutBtn, 'click', () => controller.dispatch({ type: 'zoom-out' }));
119
+ on(zoomInBtn, 'click', () => controller.dispatch({ type: 'zoom-in' }));
120
+ on(fitBtn, 'click', () => controller.dispatch({ type: 'fit' }));
121
+ on(actualBtn, 'click', () => controller.dispatch({ type: 'actual-size' }));
122
+ on(rotateBtn, 'click', () => controller.dispatch({ type: 'rotate-cw' }));
123
+ on(flipHBtn, 'click', () => controller.dispatch({ type: 'flip-h' }));
124
+ on(flipVBtn, 'click', () => controller.dispatch({ type: 'flip-v' }));
125
+ on(gridBtn, 'click', () => controller.dispatch({ type: 'toggle-grid' }));
126
+ on(resetBtn, 'click', () => controller.dispatch({ type: 'reset' }));
127
+ on(presetSelect, 'change', () => controller.dispatch({ type: 'set-preset', preset: presetSelect.value }));
128
+ wireOptionalService(bgBtn, ctx.backgroundRemoval, 'image.tool.removeBackground.unavailable', () => runBackgroundRemoval());
129
+ wireOptionalService(spriteBtn, ctx.spriteDetection, 'image.tool.detectSprites.unavailable', () => runSpriteDetection());
130
+ if (ctx.save) {
131
+ on(saveBtn, 'click', () => void saveAsPng(ctx.save));
132
+ }
133
+ else {
134
+ saveBtn.disabled = true;
135
+ saveBtn.title = t('common.noFileSave');
136
+ }
137
+ function wireOptionalService(btn, service, unavailableKey, run) {
138
+ if (service) {
139
+ on(btn, 'click', run);
140
+ }
141
+ else {
142
+ btn.disabled = true;
143
+ btn.title = t(unavailableKey);
144
+ }
145
+ }
146
+ toolbar.append(zoomOutBtn, zoomInBtn, fitBtn, actualBtn, zoomLabel, rotateBtn, flipHBtn, flipVBtn, gridBtn, presetSelect, resetBtn, bgBtn, spriteBtn, saveBtn, spacer, meta);
147
+ const diagnosticsBar = el('div', 'omni-image__diagnostics');
148
+ const stage = el('div', 'omni-image__stage');
149
+ const canvasWrap = el('div', 'omni-image__canvas-wrap');
150
+ const baseCanvas = el('canvas');
151
+ const overlay = el('canvas', 'omni-image__overlay');
152
+ overlay.tabIndex = 0;
153
+ overlay.setAttribute('role', 'img');
154
+ const ariaLive = el('div', 'omni-image__aria-live');
155
+ ariaLive.setAttribute('aria-live', 'polite');
156
+ canvasWrap.append(baseCanvas, overlay);
157
+ stage.append(canvasWrap, ariaLive);
158
+ frame.append(toolbar, diagnosticsBar, stage);
159
+ root.appendChild(frame);
160
+ function showToast(message) {
161
+ frame.querySelector('.omni-image__toast')?.remove();
162
+ const toast = el('div', 'omni-image__toast', message);
163
+ frame.appendChild(toast);
164
+ if (toastTimer)
165
+ clearTimeout(toastTimer);
166
+ toastTimer = setTimeout(() => toast.remove(), 1600);
167
+ }
168
+ // --- annotation drawing (pointer) --------------------------------------
169
+ let drawing = null;
170
+ function toSourceCoords(ev) {
171
+ const rect = overlay.getBoundingClientRect();
172
+ const m = controller.state.meta;
173
+ const nw = m?.width ?? overlay.width;
174
+ const nh = m?.height ?? overlay.height;
175
+ // Maps display → source via the bounding-box ratio. Rotation-aware
176
+ // inverse mapping is a follow-up (image.md I5); accurate at rotation 0.
177
+ const x = rect.width ? ((ev.clientX - rect.left) / rect.width) * nw : 0;
178
+ const y = rect.height ? ((ev.clientY - rect.top) / rect.height) * nh : 0;
179
+ return { x, y };
180
+ }
181
+ on(overlay, 'pointerdown', (ev) => {
182
+ const state = controller.state;
183
+ if (!state.editingEnabled || state.status === 'failed')
184
+ return;
185
+ overlay.focus();
186
+ const p = toSourceCoords(ev);
187
+ if (state.tool === 'select') {
188
+ controller.dispatch({ type: 'select-annotation', id: hitTest(p, state.annotations) });
189
+ return;
190
+ }
191
+ if (state.tool === 'text') {
192
+ const text = ''; // inline text entry (no window.prompt — image.md §3)
193
+ const ann = makeAnnotation({ type: 'text', x: p.x, y: p.y, text, style: { ...state.style } });
194
+ controller.dispatch({ type: 'add-annotation', annotation: ann });
195
+ startTextEdit(ann.id);
196
+ return;
197
+ }
198
+ drawing = { startX: p.x, startY: p.y };
199
+ if (state.tool === 'brush' || state.tool === 'eraser') {
200
+ drawing.stroke = [{ x: p.x, y: p.y }];
201
+ }
202
+ overlay.setPointerCapture?.(ev.pointerId);
203
+ });
204
+ on(overlay, 'pointermove', (ev) => {
205
+ if (!drawing)
206
+ return;
207
+ const p = toSourceCoords(ev);
208
+ if (drawing.stroke) {
209
+ drawing.stroke.push({ x: p.x, y: p.y });
210
+ renderOverlay(controller.state, drawing);
211
+ }
212
+ else {
213
+ renderOverlay(controller.state, drawing, p);
214
+ }
215
+ });
216
+ on(overlay, 'pointerup', (ev) => {
217
+ if (!drawing)
218
+ return;
219
+ const state = controller.state;
220
+ const p = toSourceCoords(ev);
221
+ const s = { ...state.style };
222
+ let ann = null;
223
+ if (drawing.stroke) {
224
+ drawing.stroke.push({ x: p.x, y: p.y });
225
+ ann = makeAnnotation({ type: 'stroke', points: drawing.stroke, erase: state.tool === 'eraser', style: s });
226
+ }
227
+ else if (state.tool === 'rectangle' || state.tool === 'circle') {
228
+ const x = Math.min(drawing.startX, p.x);
229
+ const y = Math.min(drawing.startY, p.y);
230
+ const w = Math.abs(p.x - drawing.startX);
231
+ const h = Math.abs(p.y - drawing.startY);
232
+ if (w > 1 && h > 1)
233
+ ann = makeAnnotation({ type: state.tool, x, y, w, h, style: s });
234
+ }
235
+ else if (state.tool === 'line') {
236
+ ann = makeAnnotation({ type: 'line', x1: drawing.startX, y1: drawing.startY, x2: p.x, y2: p.y, style: s });
237
+ }
238
+ drawing = null;
239
+ if (ann)
240
+ controller.dispatch({ type: 'add-annotation', annotation: ann });
241
+ else
242
+ renderAll(controller.state);
243
+ });
244
+ // Keyboard editing (image.md I5): delete / escape / arrow nudge.
245
+ on(overlay, 'keydown', (ev) => {
246
+ const e = ev;
247
+ const state = controller.state;
248
+ if (e.key === 'Delete' || e.key === 'Backspace') {
249
+ if (state.selectedId) {
250
+ e.preventDefault();
251
+ controller.dispatch({ type: 'delete-annotation' });
252
+ }
253
+ }
254
+ else if (e.key === 'Escape') {
255
+ controller.dispatch({ type: 'select-annotation', id: null });
256
+ }
257
+ else if (e.key.startsWith('Arrow') && state.selectedId) {
258
+ e.preventDefault();
259
+ const step = e.shiftKey ? 10 : 1;
260
+ const dx = e.key === 'ArrowLeft' ? -step : e.key === 'ArrowRight' ? step : 0;
261
+ const dy = e.key === 'ArrowUp' ? -step : e.key === 'ArrowDown' ? step : 0;
262
+ controller.dispatch({ type: 'move-annotation', dx, dy });
263
+ }
264
+ });
265
+ // Global keyboard shortcuts (not while typing in an input).
266
+ on(frame, 'keydown', (ev) => {
267
+ const e = ev;
268
+ const target = e.target;
269
+ if (target && (target.tagName === 'INPUT' || target.tagName === 'SELECT'))
270
+ return;
271
+ if ((e.ctrlKey || e.metaKey) && e.key.toLowerCase() === 'z') {
272
+ e.preventDefault();
273
+ controller.dispatch({ type: 'undo' });
274
+ }
275
+ else if ((e.ctrlKey || e.metaKey) && e.key.toLowerCase() === 's') {
276
+ e.preventDefault();
277
+ if (ctx.save)
278
+ void saveAsPng(ctx.save);
279
+ }
280
+ else if (!e.ctrlKey && !e.metaKey) {
281
+ if (e.key === '+' || e.key === '=')
282
+ controller.dispatch({ type: 'zoom-in' });
283
+ else if (e.key === '-')
284
+ controller.dispatch({ type: 'zoom-out' });
285
+ else if (e.key === '0')
286
+ controller.dispatch({ type: 'actual-size' });
287
+ else if (e.key.toLowerCase() === 'f')
288
+ controller.dispatch({ type: 'fit' });
289
+ else if (e.key.toLowerCase() === 'r')
290
+ controller.dispatch({ type: 'rotate-cw' });
291
+ }
292
+ });
293
+ function startTextEdit(id) {
294
+ const ann = controller.state.annotations.find((a) => a.id === id);
295
+ if (!ann || ann.type !== 'text')
296
+ return;
297
+ const inputEl = el('input');
298
+ inputEl.type = 'text';
299
+ inputEl.value = ann.text;
300
+ inputEl.style.position = 'absolute';
301
+ const rect = overlay.getBoundingClientRect();
302
+ const m = controller.state.meta;
303
+ const sx = m && m.width ? rect.width / m.width : 1;
304
+ const sy = m && m.height ? rect.height / m.height : 1;
305
+ inputEl.style.left = `${ann.x * sx}px`;
306
+ inputEl.style.top = `${ann.y * sy}px`;
307
+ canvasWrap.appendChild(inputEl);
308
+ inputEl.focus();
309
+ let done = false;
310
+ const finish = (commit) => {
311
+ if (done)
312
+ return;
313
+ done = true;
314
+ if (commit && inputEl.value) {
315
+ controller.dispatch({ type: 'update-annotation', id, patch: { text: inputEl.value } });
316
+ }
317
+ else {
318
+ controller.dispatch({ type: 'delete-annotation', id });
319
+ }
320
+ inputEl.remove();
321
+ };
322
+ inputEl.addEventListener('keydown', (e) => {
323
+ e.stopPropagation();
324
+ if (e.key === 'Enter') {
325
+ e.preventDefault();
326
+ finish(true);
327
+ }
328
+ else if (e.key === 'Escape') {
329
+ e.preventDefault();
330
+ finish(false);
331
+ }
332
+ });
333
+ inputEl.addEventListener('blur', () => finish(true));
334
+ }
335
+ // --- optional service runners ------------------------------------------
336
+ async function runBackgroundRemoval() {
337
+ const service = ctx.backgroundRemoval;
338
+ if (!service || !decoded?.source)
339
+ return;
340
+ showToast(t('image.bgRemoval.working'));
341
+ try {
342
+ const src = readRgba(decoded.source);
343
+ if (!src)
344
+ return;
345
+ const out = await service.removeBackground(src);
346
+ paintRgba(out);
347
+ renderAll(controller.state);
348
+ }
349
+ catch (error) {
350
+ ctx.logger.log('error', `bg removal failed: ${String(error)}`);
351
+ showToast(t('image.bgRemoval.failed'));
352
+ }
353
+ }
354
+ async function runSpriteDetection() {
355
+ const service = ctx.spriteDetection;
356
+ if (!service || !decoded?.source)
357
+ return;
358
+ showToast(t('image.spriteDetection.working'));
359
+ try {
360
+ const src = readRgba(decoded.source);
361
+ if (!src)
362
+ return;
363
+ const contours = await service.detectSprites(src);
364
+ // v1: overlay the detected boxes for visual confirmation.
365
+ renderOverlay(controller.state, null, undefined, contours.map((c) => c.box));
366
+ }
367
+ catch (error) {
368
+ ctx.logger.log('error', `sprite detection failed: ${String(error)}`);
369
+ showToast(t('image.spriteDetection.failed'));
370
+ }
371
+ }
372
+ function readRgba(source) {
373
+ const c = document.createElement('canvas');
374
+ c.width = source.width;
375
+ c.height = source.height;
376
+ const g = ctx2d(c);
377
+ if (!g)
378
+ return null;
379
+ g.drawImage(source, 0, 0);
380
+ try {
381
+ const img = g.getImageData(0, 0, c.width, c.height);
382
+ return { width: c.width, height: c.height, data: img.data };
383
+ }
384
+ catch {
385
+ return null;
386
+ }
387
+ }
388
+ function paintRgba(rgba) {
389
+ const g = ctx2d(baseCanvas);
390
+ if (!g)
391
+ return;
392
+ baseCanvas.width = rgba.width;
393
+ baseCanvas.height = rgba.height;
394
+ const imgData = g.createImageData(rgba.width, rgba.height);
395
+ imgData.data.set(rgba.data);
396
+ g.putImageData(imgData, 0, 0);
397
+ }
398
+ // --- Save As PNG (compose transform + filter + annotations) ------------
399
+ async function saveAsPng(service) {
400
+ const state = controller.state;
401
+ if (!decoded?.source || !state.meta || !state.editingEnabled)
402
+ return;
403
+ try {
404
+ const blob = await composePng(decoded.source, state);
405
+ if (!blob)
406
+ return;
407
+ const bytes = new Uint8Array(await blob.arrayBuffer());
408
+ const name = imageExportFileName(input.fileName);
409
+ await service.saveFile(name, bytes, 'image/png');
410
+ showToast(t('common.saved', { name }));
411
+ }
412
+ catch (error) {
413
+ ctx.logger.log('error', `image save failed: ${String(error)}`);
414
+ showToast(t('common.saveFailed'));
415
+ }
416
+ }
417
+ // --- state-driven rendering --------------------------------------------
418
+ function renderAll(state) {
419
+ // Toolbar reflected state
420
+ zoomLabel.textContent = `${Math.round(state.zoom * 100)}%`;
421
+ fitBtn.setAttribute('aria-pressed', String(state.fitMode));
422
+ flipHBtn.setAttribute('aria-pressed', String(state.flipH));
423
+ flipVBtn.setAttribute('aria-pressed', String(state.flipV));
424
+ gridBtn.setAttribute('aria-pressed', String(state.grid.visible));
425
+ presetSelect.value = state.preset ?? 'original';
426
+ zoomInBtn.disabled = state.zoom >= 5;
427
+ zoomOutBtn.disabled = state.zoom <= 0.1;
428
+ const editDisabled = !state.editingEnabled || state.status === 'failed';
429
+ for (const b of [rotateBtn, flipHBtn, flipVBtn, presetSelect, bgBtn, spriteBtn]) {
430
+ b.disabled = editDisabled || (b === bgBtn && !ctx.backgroundRemoval) || (b === spriteBtn && !ctx.spriteDetection);
431
+ }
432
+ if (ctx.save)
433
+ saveBtn.disabled = editDisabled;
434
+ if (state.meta) {
435
+ meta.textContent = `${state.meta.width}×${state.meta.height} · ${mimeShort(state.meta.mime)} · ${formatBytes(state.meta.byteLength)}`;
436
+ }
437
+ else {
438
+ meta.textContent = '';
439
+ }
440
+ // Diagnostics
441
+ diagnosticsBar.replaceChildren();
442
+ const hasNotices = state.diagnostics.length > 0 || state.failure;
443
+ diagnosticsBar.style.display = hasNotices ? '' : 'none';
444
+ if (state.failure) {
445
+ diagnosticsBar.appendChild(el('div', 'omni-image__diag-error', t(state.failure.messageKey, state.failure.args)));
446
+ }
447
+ for (const d of state.diagnostics) {
448
+ diagnosticsBar.appendChild(el('div', undefined, t(d.messageKey, d.args)));
449
+ }
450
+ // View transform (display-only; not exported)
451
+ const transforms = [`scale(${state.zoom})`, `rotate(${state.rotation}deg)`];
452
+ if (state.flipH)
453
+ transforms.push('scaleX(-1)');
454
+ if (state.flipV)
455
+ transforms.push('scaleY(-1)');
456
+ canvasWrap.style.transform = transforms.join(' ');
457
+ baseCanvas.style.filter = filterToCss(state.filter);
458
+ // aria-live summary
459
+ ariaLive.textContent = t('image.status', {
460
+ zoom: Math.round(state.zoom * 100),
461
+ rotation: state.rotation
462
+ });
463
+ overlay.setAttribute('aria-label', input.fileName + (state.meta ? ` ${state.meta.width}×${state.meta.height}` : ''));
464
+ renderOverlay(state, null);
465
+ }
466
+ function renderOverlay(state, pending, pendingEnd, boxes) {
467
+ if (!state.meta)
468
+ return; // nothing decoded yet — skip canvas work entirely
469
+ const g = ctx2d(overlay);
470
+ if (!g)
471
+ return;
472
+ overlay.width = state.meta.width;
473
+ overlay.height = state.meta.height;
474
+ g.clearRect(0, 0, overlay.width, overlay.height);
475
+ if (state.grid.visible)
476
+ drawGrid(g, state);
477
+ for (const a of state.annotations)
478
+ drawAnnotation(g, a, a.id === state.selectedId);
479
+ if (pending)
480
+ drawPending(g, state, pending, pendingEnd);
481
+ if (boxes) {
482
+ g.strokeStyle = '#3bd6e2';
483
+ g.lineWidth = 2;
484
+ for (const b of boxes)
485
+ g.strokeRect(b.x, b.y, b.width, b.height);
486
+ }
487
+ }
488
+ // Subscribe + first paint
489
+ const unsubscribe = controller.subscribe(renderAll);
490
+ // --- decode (async, abortable) -----------------------------------------
491
+ const decodeOpts = {};
492
+ if (options.signal)
493
+ decodeOpts.signal = options.signal;
494
+ if (options.maxInputBytes !== undefined)
495
+ decodeOpts.maxInputBytes = options.maxInputBytes;
496
+ if (options.maxDecodedPixels !== undefined)
497
+ decodeOpts.maxDecodedPixels = options.maxDecodedPixels;
498
+ decoded = await decodeImage({ fileName: input.fileName, data: input.data }, decodeOpts);
499
+ if (options.signal?.aborted) {
500
+ decoded.dispose();
501
+ cleanup();
502
+ throw new MountAbortedError();
503
+ }
504
+ const load = decoded.load;
505
+ if (load.status === 'failed') {
506
+ controller.setDocument({ status: 'failed', failure: load.failure, diagnostics: load.diagnostics });
507
+ }
508
+ else {
509
+ const doc = load.document;
510
+ const editable = canvasEditable(doc.width, doc.height, {
511
+ ...IMAGE_LIMITS,
512
+ ...(options.maxInputBytes ? { maxInputBytes: options.maxInputBytes } : {})
513
+ });
514
+ const diags = [...load.diagnostics];
515
+ if (!editable) {
516
+ diags.push({ severity: 'warning', code: 'canvas-limit', messageKey: 'diag.image.limit-exceeded.canvas' });
517
+ }
518
+ // Paint the decoded bitmap into the base canvas at natural size.
519
+ baseCanvas.width = doc.width;
520
+ baseCanvas.height = doc.height;
521
+ const g = ctx2d(baseCanvas);
522
+ if (g && decoded.source)
523
+ g.drawImage(decoded.source, 0, 0);
524
+ controller.setDocument({
525
+ status: editable ? load.status : 'partial',
526
+ diagnostics: diags,
527
+ meta: doc,
528
+ editingEnabled: editable
529
+ });
530
+ }
531
+ function cleanup() {
532
+ unsubscribe();
533
+ for (const dispose of disposers)
534
+ dispose();
535
+ disposers.length = 0;
536
+ if (toastTimer)
537
+ clearTimeout(toastTimer);
538
+ decoded?.dispose();
539
+ decoded = null;
540
+ if (root instanceof ShadowRoot) {
541
+ root.replaceChildren();
542
+ }
543
+ else {
544
+ root.replaceChildren();
545
+ root.classList.remove(VIEWER_ROOT_CLASS, 'omni-viewer--image');
546
+ }
547
+ }
548
+ return {
549
+ dispose: cleanup,
550
+ isDirty: () => controller.state.dirty
551
+ };
552
+ }
553
+ // --- pure-ish drawing helpers ----------------------------------------------
554
+ function hitTest(p, annotations) {
555
+ // Topmost annotation whose bounding box contains the point.
556
+ for (let i = annotations.length - 1; i >= 0; i--) {
557
+ const a = annotations[i];
558
+ const box = boundingBox(a);
559
+ if (p.x >= box.x && p.x <= box.x + box.w && p.y >= box.y && p.y <= box.y + box.h)
560
+ return a.id;
561
+ }
562
+ return null;
563
+ }
564
+ function boundingBox(a) {
565
+ switch (a.type) {
566
+ case 'rectangle':
567
+ case 'circle':
568
+ return { x: a.x, y: a.y, w: a.w, h: a.h };
569
+ case 'line':
570
+ return { x: Math.min(a.x1, a.x2), y: Math.min(a.y1, a.y2), w: Math.abs(a.x2 - a.x1), h: Math.abs(a.y2 - a.y1) };
571
+ case 'text':
572
+ return { x: a.x, y: a.y - a.style.fontSize, w: Math.max(20, a.text.length * a.style.fontSize * 0.6), h: a.style.fontSize * 1.4 };
573
+ case 'stroke': {
574
+ const xs = a.points.map((q) => q.x);
575
+ const ys = a.points.map((q) => q.y);
576
+ const x = Math.min(...xs), y = Math.min(...ys);
577
+ return { x, y, w: Math.max(...xs) - x, h: Math.max(...ys) - y };
578
+ }
579
+ }
580
+ }
581
+ function drawGrid(g, state) {
582
+ const { grid, meta } = state;
583
+ if (!meta)
584
+ return;
585
+ g.strokeStyle = 'rgba(255,255,255,0.4)';
586
+ g.lineWidth = 1;
587
+ let stepX, stepY;
588
+ if (grid.mode === 'cell-size') {
589
+ stepX = grid.cellWidth;
590
+ stepY = grid.cellHeight;
591
+ }
592
+ else {
593
+ stepX = meta.width / grid.cols;
594
+ stepY = meta.height / grid.rows;
595
+ }
596
+ if (stepX <= 0 || stepY <= 0)
597
+ return;
598
+ for (let x = stepX; x < meta.width; x += stepX) {
599
+ g.beginPath();
600
+ g.moveTo(x, 0);
601
+ g.lineTo(x, meta.height);
602
+ g.stroke();
603
+ }
604
+ for (let y = stepY; y < meta.height; y += stepY) {
605
+ g.beginPath();
606
+ g.moveTo(0, y);
607
+ g.lineTo(meta.width, y);
608
+ g.stroke();
609
+ }
610
+ }
611
+ function drawAnnotation(g, a, selected) {
612
+ g.save();
613
+ g.strokeStyle = a.style.color;
614
+ g.fillStyle = a.style.color;
615
+ g.lineWidth = a.type === 'stroke' ? a.style.brushSize : 2;
616
+ g.globalAlpha = a.style.borderOpacity;
617
+ switch (a.type) {
618
+ case 'rectangle':
619
+ if (a.style.fillOpacity > 0) {
620
+ g.globalAlpha = a.style.fillOpacity;
621
+ g.fillRect(a.x, a.y, a.w, a.h);
622
+ g.globalAlpha = a.style.borderOpacity;
623
+ }
624
+ g.strokeRect(a.x, a.y, a.w, a.h);
625
+ break;
626
+ case 'circle':
627
+ g.beginPath();
628
+ g.ellipse(a.x + a.w / 2, a.y + a.h / 2, a.w / 2, a.h / 2, 0, 0, Math.PI * 2);
629
+ if (a.style.fillOpacity > 0) {
630
+ g.globalAlpha = a.style.fillOpacity;
631
+ g.fill();
632
+ g.globalAlpha = a.style.borderOpacity;
633
+ }
634
+ g.stroke();
635
+ break;
636
+ case 'line':
637
+ g.beginPath();
638
+ g.moveTo(a.x1, a.y1);
639
+ g.lineTo(a.x2, a.y2);
640
+ g.stroke();
641
+ break;
642
+ case 'text':
643
+ g.globalAlpha = 1;
644
+ g.font = `${a.style.fontSize}px sans-serif`;
645
+ g.fillText(a.text, a.x, a.y);
646
+ break;
647
+ case 'stroke':
648
+ g.globalAlpha = a.erase ? 1 : a.style.borderOpacity;
649
+ g.globalCompositeOperation = a.erase ? 'destination-out' : 'source-over';
650
+ g.lineCap = 'round';
651
+ g.lineJoin = 'round';
652
+ g.beginPath();
653
+ a.points.forEach((p, i) => (i === 0 ? g.moveTo(p.x, p.y) : g.lineTo(p.x, p.y)));
654
+ g.stroke();
655
+ break;
656
+ }
657
+ g.restore();
658
+ if (selected) {
659
+ const box = boundingBox(a);
660
+ g.save();
661
+ g.strokeStyle = '#3b82f6';
662
+ g.setLineDash([4, 3]);
663
+ g.strokeRect(box.x - 2, box.y - 2, box.w + 4, box.h + 4);
664
+ g.restore();
665
+ }
666
+ }
667
+ function drawPending(g, state, pending, end) {
668
+ g.save();
669
+ g.strokeStyle = state.style.color;
670
+ g.lineWidth = state.tool === 'brush' || state.tool === 'eraser' ? state.style.brushSize : 2;
671
+ if (pending.stroke) {
672
+ g.lineCap = 'round';
673
+ g.beginPath();
674
+ pending.stroke.forEach((p, i) => (i === 0 ? g.moveTo(p.x, p.y) : g.lineTo(p.x, p.y)));
675
+ g.stroke();
676
+ }
677
+ else if (end) {
678
+ if (state.tool === 'rectangle') {
679
+ g.strokeRect(pending.startX, pending.startY, end.x - pending.startX, end.y - pending.startY);
680
+ }
681
+ else if (state.tool === 'circle') {
682
+ g.beginPath();
683
+ g.ellipse((pending.startX + end.x) / 2, (pending.startY + end.y) / 2, Math.abs(end.x - pending.startX) / 2, Math.abs(end.y - pending.startY) / 2, 0, 0, Math.PI * 2);
684
+ g.stroke();
685
+ }
686
+ else if (state.tool === 'line') {
687
+ g.beginPath();
688
+ g.moveTo(pending.startX, pending.startY);
689
+ g.lineTo(end.x, end.y);
690
+ g.stroke();
691
+ }
692
+ }
693
+ g.restore();
694
+ }
695
+ /**
696
+ * Compose the export PNG in *source pixel* coordinates (image.md §5): rotation/
697
+ * flip/filter and every annotation are baked in; grid and sprite overlays are
698
+ * not. The original bytes are never mutated.
699
+ */
700
+ async function composePng(source, state) {
701
+ const swap = state.rotation === 90 || state.rotation === 270;
702
+ const outW = swap ? source.height : source.width;
703
+ const outH = swap ? source.width : source.height;
704
+ const canvas = document.createElement('canvas');
705
+ canvas.width = outW;
706
+ canvas.height = outH;
707
+ let g = null;
708
+ try {
709
+ g = canvas.getContext('2d');
710
+ }
711
+ catch {
712
+ g = null;
713
+ }
714
+ if (!g)
715
+ return null;
716
+ g.save();
717
+ g.translate(outW / 2, outH / 2);
718
+ g.rotate((state.rotation * Math.PI) / 180);
719
+ g.scale(state.flipH ? -1 : 1, state.flipV ? -1 : 1);
720
+ if ('filter' in g)
721
+ g.filter = filterToCss(state.filter);
722
+ g.drawImage(source, -source.width / 2, -source.height / 2);
723
+ g.restore();
724
+ // Annotations are already in source coordinates; draw them over the composed
725
+ // image in the same source space (before rotation would misplace them, so we
726
+ // draw into a second pass aligned to the un-rotated source, then… v1 keeps it
727
+ // simple: annotations are composed at rotation 0). For rotated exports the
728
+ // annotation overlay alignment is a follow-up (image.md §5 fixture work).
729
+ if ('filter' in g)
730
+ g.filter = 'none';
731
+ for (const a of state.annotations)
732
+ drawAnnotation(g, a, false);
733
+ return await new Promise((resolve) => {
734
+ if (typeof canvas.toBlob === 'function')
735
+ canvas.toBlob(resolve, 'image/png');
736
+ else
737
+ resolve(null);
738
+ });
739
+ }
740
+ function mimeShort(mime) {
741
+ return mime.replace('image/', '').toUpperCase();
742
+ }
743
+ function formatBytes(bytes) {
744
+ if (bytes < 1024)
745
+ return `${bytes} B`;
746
+ if (bytes < 1024 * 1024)
747
+ return `${(bytes / 1024).toFixed(1)} KiB`;
748
+ return `${(bytes / (1024 * 1024)).toFixed(1)} MiB`;
749
+ }