@agent-native/creative-context 0.0.0-beta-20260820202238

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 (695) hide show
  1. package/README.md +154 -0
  2. package/agent-native.eject.json +41 -0
  3. package/agent-native.package.json +119 -0
  4. package/dist/actions/confirm-canonical-logo.d.ts +6 -0
  5. package/dist/actions/confirm-canonical-logo.d.ts.map +1 -0
  6. package/dist/actions/confirm-canonical-logo.js +19 -0
  7. package/dist/actions/confirm-canonical-logo.js.map +1 -0
  8. package/dist/actions/continue-context-import.d.ts +22 -0
  9. package/dist/actions/continue-context-import.d.ts.map +1 -0
  10. package/dist/actions/continue-context-import.js +13 -0
  11. package/dist/actions/continue-context-import.js.map +1 -0
  12. package/dist/actions/creative-context-a2a.d.ts +10 -0
  13. package/dist/actions/creative-context-a2a.d.ts.map +1 -0
  14. package/dist/actions/creative-context-a2a.js +66 -0
  15. package/dist/actions/creative-context-a2a.js.map +1 -0
  16. package/dist/actions/get-brand-profile.d.ts +33 -0
  17. package/dist/actions/get-brand-profile.d.ts.map +1 -0
  18. package/dist/actions/get-brand-profile.js +13 -0
  19. package/dist/actions/get-brand-profile.js.map +1 -0
  20. package/dist/actions/get-context-import-status.d.ts +22 -0
  21. package/dist/actions/get-context-import-status.d.ts.map +1 -0
  22. package/dist/actions/get-context-import-status.js +12 -0
  23. package/dist/actions/get-context-import-status.js.map +1 -0
  24. package/dist/actions/get-context-item.d.ts +2 -0
  25. package/dist/actions/get-context-item.d.ts.map +1 -0
  26. package/dist/actions/get-context-item.js +2 -0
  27. package/dist/actions/get-context-item.js.map +1 -0
  28. package/dist/actions/get-context-pack.d.ts +7 -0
  29. package/dist/actions/get-context-pack.d.ts.map +1 -0
  30. package/dist/actions/get-context-pack.js +12 -0
  31. package/dist/actions/get-context-pack.js.map +1 -0
  32. package/dist/actions/get-creative-context.d.ts +157 -0
  33. package/dist/actions/get-creative-context.d.ts.map +1 -0
  34. package/dist/actions/get-creative-context.js +148 -0
  35. package/dist/actions/get-creative-context.js.map +1 -0
  36. package/dist/actions/get-google-picker-session.d.ts +10 -0
  37. package/dist/actions/get-google-picker-session.d.ts.map +1 -0
  38. package/dist/actions/get-google-picker-session.js +38 -0
  39. package/dist/actions/get-google-picker-session.js.map +1 -0
  40. package/dist/actions/index.d.ts +3 -0
  41. package/dist/actions/index.d.ts.map +1 -0
  42. package/dist/actions/index.js +73 -0
  43. package/dist/actions/index.js.map +1 -0
  44. package/dist/actions/infer-brand-dna.d.ts +52 -0
  45. package/dist/actions/infer-brand-dna.d.ts.map +1 -0
  46. package/dist/actions/infer-brand-dna.js +13 -0
  47. package/dist/actions/infer-brand-dna.js.map +1 -0
  48. package/dist/actions/list-canonical-logo-candidates.d.ts +9 -0
  49. package/dist/actions/list-canonical-logo-candidates.d.ts.map +1 -0
  50. package/dist/actions/list-canonical-logo-candidates.js +82 -0
  51. package/dist/actions/list-canonical-logo-candidates.js.map +1 -0
  52. package/dist/actions/list-context-connections.d.ts +22 -0
  53. package/dist/actions/list-context-connections.d.ts.map +1 -0
  54. package/dist/actions/list-context-connections.js +43 -0
  55. package/dist/actions/list-context-connections.js.map +1 -0
  56. package/dist/actions/list-context-memberships.d.ts +11 -0
  57. package/dist/actions/list-context-memberships.d.ts.map +1 -0
  58. package/dist/actions/list-context-memberships.js +47 -0
  59. package/dist/actions/list-context-memberships.js.map +1 -0
  60. package/dist/actions/list-context-packs.d.ts +10 -0
  61. package/dist/actions/list-context-packs.d.ts.map +1 -0
  62. package/dist/actions/list-context-packs.js +16 -0
  63. package/dist/actions/list-context-packs.js.map +1 -0
  64. package/dist/actions/list-context-sources.d.ts +12 -0
  65. package/dist/actions/list-context-sources.d.ts.map +1 -0
  66. package/dist/actions/list-context-sources.js +20 -0
  67. package/dist/actions/list-context-sources.js.map +1 -0
  68. package/dist/actions/list-context-suggestions.d.ts +13 -0
  69. package/dist/actions/list-context-suggestions.d.ts.map +1 -0
  70. package/dist/actions/list-context-suggestions.js +28 -0
  71. package/dist/actions/list-context-suggestions.js.map +1 -0
  72. package/dist/actions/list-creative-contexts.d.ts +12 -0
  73. package/dist/actions/list-creative-contexts.d.ts.map +1 -0
  74. package/dist/actions/list-creative-contexts.js +28 -0
  75. package/dist/actions/list-creative-contexts.js.map +1 -0
  76. package/dist/actions/manage-brand-profile.d.ts +28 -0
  77. package/dist/actions/manage-brand-profile.d.ts.map +1 -0
  78. package/dist/actions/manage-brand-profile.js +47 -0
  79. package/dist/actions/manage-brand-profile.js.map +1 -0
  80. package/dist/actions/manage-context-membership.d.ts +64 -0
  81. package/dist/actions/manage-context-membership.d.ts.map +1 -0
  82. package/dist/actions/manage-context-membership.js +70 -0
  83. package/dist/actions/manage-context-membership.js.map +1 -0
  84. package/dist/actions/manage-context-pack.d.ts +36 -0
  85. package/dist/actions/manage-context-pack.d.ts.map +1 -0
  86. package/dist/actions/manage-context-pack.js +71 -0
  87. package/dist/actions/manage-context-pack.js.map +1 -0
  88. package/dist/actions/manage-context-source.d.ts +51 -0
  89. package/dist/actions/manage-context-source.d.ts.map +1 -0
  90. package/dist/actions/manage-context-source.js +130 -0
  91. package/dist/actions/manage-context-source.js.map +1 -0
  92. package/dist/actions/manage-creative-context.d.ts +28 -0
  93. package/dist/actions/manage-creative-context.d.ts.map +1 -0
  94. package/dist/actions/manage-creative-context.js +65 -0
  95. package/dist/actions/manage-creative-context.js.map +1 -0
  96. package/dist/actions/manage-layout-template.d.ts +13 -0
  97. package/dist/actions/manage-layout-template.d.ts.map +1 -0
  98. package/dist/actions/manage-layout-template.js +43 -0
  99. package/dist/actions/manage-layout-template.js.map +1 -0
  100. package/dist/actions/preview-context-import.d.ts +23 -0
  101. package/dist/actions/preview-context-import.d.ts.map +1 -0
  102. package/dist/actions/preview-context-import.js +57 -0
  103. package/dist/actions/preview-context-import.js.map +1 -0
  104. package/dist/actions/process-context-purge.d.ts +37 -0
  105. package/dist/actions/process-context-purge.d.ts.map +1 -0
  106. package/dist/actions/process-context-purge.js +20 -0
  107. package/dist/actions/process-context-purge.js.map +1 -0
  108. package/dist/actions/propose-brand-dna.d.ts +15 -0
  109. package/dist/actions/propose-brand-dna.d.ts.map +1 -0
  110. package/dist/actions/propose-brand-dna.js +19 -0
  111. package/dist/actions/propose-brand-dna.js.map +1 -0
  112. package/dist/actions/propose-canonical-logo.d.ts +9 -0
  113. package/dist/actions/propose-canonical-logo.d.ts.map +1 -0
  114. package/dist/actions/propose-canonical-logo.js +16 -0
  115. package/dist/actions/propose-canonical-logo.js.map +1 -0
  116. package/dist/actions/publish-brand-dna.d.ts +13 -0
  117. package/dist/actions/publish-brand-dna.d.ts.map +1 -0
  118. package/dist/actions/publish-brand-dna.js +23 -0
  119. package/dist/actions/publish-brand-dna.js.map +1 -0
  120. package/dist/actions/recommend-context-roots.d.ts +14 -0
  121. package/dist/actions/recommend-context-roots.d.ts.map +1 -0
  122. package/dist/actions/recommend-context-roots.js +22 -0
  123. package/dist/actions/recommend-context-roots.js.map +1 -0
  124. package/dist/actions/record-context-feedback.d.ts +10 -0
  125. package/dist/actions/record-context-feedback.d.ts.map +1 -0
  126. package/dist/actions/record-context-feedback.js +14 -0
  127. package/dist/actions/record-context-feedback.js.map +1 -0
  128. package/dist/actions/review-context-items.d.ts +35 -0
  129. package/dist/actions/review-context-items.d.ts.map +1 -0
  130. package/dist/actions/review-context-items.js +65 -0
  131. package/dist/actions/review-context-items.js.map +1 -0
  132. package/dist/actions/run-embedding-bakeoff.d.ts +15 -0
  133. package/dist/actions/run-embedding-bakeoff.d.ts.map +1 -0
  134. package/dist/actions/run-embedding-bakeoff.js +72 -0
  135. package/dist/actions/run-embedding-bakeoff.js.map +1 -0
  136. package/dist/actions/search-creative-context.d.ts +80 -0
  137. package/dist/actions/search-creative-context.d.ts.map +1 -0
  138. package/dist/actions/search-creative-context.js +42 -0
  139. package/dist/actions/search-creative-context.js.map +1 -0
  140. package/dist/actions/set-brand-dna.d.ts +15 -0
  141. package/dist/actions/set-brand-dna.d.ts.map +1 -0
  142. package/dist/actions/set-brand-dna.js +19 -0
  143. package/dist/actions/set-brand-dna.js.map +1 -0
  144. package/dist/actions/start-context-enrichment.d.ts +25 -0
  145. package/dist/actions/start-context-enrichment.d.ts.map +1 -0
  146. package/dist/actions/start-context-enrichment.js +48 -0
  147. package/dist/actions/start-context-enrichment.js.map +1 -0
  148. package/dist/actions/start-context-import.d.ts +24 -0
  149. package/dist/actions/start-context-import.d.ts.map +1 -0
  150. package/dist/actions/start-context-import.js +37 -0
  151. package/dist/actions/start-context-import.js.map +1 -0
  152. package/dist/client/CreativeContextChip.d.ts +18 -0
  153. package/dist/client/CreativeContextChip.d.ts.map +1 -0
  154. package/dist/client/CreativeContextChip.js +80 -0
  155. package/dist/client/CreativeContextChip.js.map +1 -0
  156. package/dist/client/CreativeContextPanel.d.ts +73 -0
  157. package/dist/client/CreativeContextPanel.d.ts.map +1 -0
  158. package/dist/client/CreativeContextPanel.js +1171 -0
  159. package/dist/client/CreativeContextPanel.js.map +1 -0
  160. package/dist/client/CreativeContextSettingsLink.d.ts +4 -0
  161. package/dist/client/CreativeContextSettingsLink.d.ts.map +1 -0
  162. package/dist/client/CreativeContextSettingsLink.js +8 -0
  163. package/dist/client/CreativeContextSettingsLink.js.map +1 -0
  164. package/dist/client/CreativeContextShareTab.d.ts +56 -0
  165. package/dist/client/CreativeContextShareTab.d.ts.map +1 -0
  166. package/dist/client/CreativeContextShareTab.js +213 -0
  167. package/dist/client/CreativeContextShareTab.js.map +1 -0
  168. package/dist/client/actions.d.ts +474 -0
  169. package/dist/client/actions.d.ts.map +1 -0
  170. package/dist/client/actions.js +411 -0
  171. package/dist/client/actions.js.map +1 -0
  172. package/dist/client/agent-tab.d.ts +10 -0
  173. package/dist/client/agent-tab.d.ts.map +1 -0
  174. package/dist/client/agent-tab.js +32 -0
  175. package/dist/client/agent-tab.js.map +1 -0
  176. package/dist/client/application-state.d.ts +24 -0
  177. package/dist/client/application-state.d.ts.map +1 -0
  178. package/dist/client/application-state.js +111 -0
  179. package/dist/client/application-state.js.map +1 -0
  180. package/dist/client/google-slides-picker.d.ts +19 -0
  181. package/dist/client/google-slides-picker.d.ts.map +1 -0
  182. package/dist/client/google-slides-picker.js +106 -0
  183. package/dist/client/google-slides-picker.js.map +1 -0
  184. package/dist/client/index.d.ts +10 -0
  185. package/dist/client/index.d.ts.map +1 -0
  186. package/dist/client/index.js +10 -0
  187. package/dist/client/index.js.map +1 -0
  188. package/dist/client/messages.d.ts +5 -0
  189. package/dist/client/messages.d.ts.map +1 -0
  190. package/dist/client/messages.js +1158 -0
  191. package/dist/client/messages.js.map +1 -0
  192. package/dist/connectors/context.d.ts +9 -0
  193. package/dist/connectors/context.d.ts.map +1 -0
  194. package/dist/connectors/context.js +59 -0
  195. package/dist/connectors/context.js.map +1 -0
  196. package/dist/connectors/document-parser.d.ts +2 -0
  197. package/dist/connectors/document-parser.d.ts.map +1 -0
  198. package/dist/connectors/document-parser.js +2 -0
  199. package/dist/connectors/document-parser.js.map +1 -0
  200. package/dist/connectors/figma-native.d.ts +18 -0
  201. package/dist/connectors/figma-native.d.ts.map +1 -0
  202. package/dist/connectors/figma-native.js +883 -0
  203. package/dist/connectors/figma-native.js.map +1 -0
  204. package/dist/connectors/figma.d.ts +10 -0
  205. package/dist/connectors/figma.d.ts.map +1 -0
  206. package/dist/connectors/figma.js +166 -0
  207. package/dist/connectors/figma.js.map +1 -0
  208. package/dist/connectors/google-slides-native.d.ts +58 -0
  209. package/dist/connectors/google-slides-native.d.ts.map +1 -0
  210. package/dist/connectors/google-slides-native.js +1118 -0
  211. package/dist/connectors/google-slides-native.js.map +1 -0
  212. package/dist/connectors/google-slides.d.ts +15 -0
  213. package/dist/connectors/google-slides.d.ts.map +1 -0
  214. package/dist/connectors/google-slides.js +895 -0
  215. package/dist/connectors/google-slides.js.map +1 -0
  216. package/dist/connectors/index.d.ts +21 -0
  217. package/dist/connectors/index.d.ts.map +1 -0
  218. package/dist/connectors/index.js +45 -0
  219. package/dist/connectors/index.js.map +1 -0
  220. package/dist/connectors/manual.d.ts +9 -0
  221. package/dist/connectors/manual.d.ts.map +1 -0
  222. package/dist/connectors/manual.js +91 -0
  223. package/dist/connectors/manual.js.map +1 -0
  224. package/dist/connectors/normalize.d.ts +42 -0
  225. package/dist/connectors/normalize.d.ts.map +1 -0
  226. package/dist/connectors/normalize.js +335 -0
  227. package/dist/connectors/normalize.js.map +1 -0
  228. package/dist/connectors/notion.d.ts +10 -0
  229. package/dist/connectors/notion.d.ts.map +1 -0
  230. package/dist/connectors/notion.js +393 -0
  231. package/dist/connectors/notion.js.map +1 -0
  232. package/dist/connectors/private-artifacts.d.ts +39 -0
  233. package/dist/connectors/private-artifacts.d.ts.map +1 -0
  234. package/dist/connectors/private-artifacts.js +175 -0
  235. package/dist/connectors/private-artifacts.js.map +1 -0
  236. package/dist/connectors/provider-response.d.ts +20 -0
  237. package/dist/connectors/provider-response.d.ts.map +1 -0
  238. package/dist/connectors/provider-response.js +98 -0
  239. package/dist/connectors/provider-response.js.map +1 -0
  240. package/dist/connectors/recommendations.d.ts +25 -0
  241. package/dist/connectors/recommendations.d.ts.map +1 -0
  242. package/dist/connectors/recommendations.js +172 -0
  243. package/dist/connectors/recommendations.js.map +1 -0
  244. package/dist/connectors/registry.d.ts +10 -0
  245. package/dist/connectors/registry.d.ts.map +1 -0
  246. package/dist/connectors/registry.js +34 -0
  247. package/dist/connectors/registry.js.map +1 -0
  248. package/dist/connectors/rendered-design.d.ts +68 -0
  249. package/dist/connectors/rendered-design.d.ts.map +1 -0
  250. package/dist/connectors/rendered-design.js +362 -0
  251. package/dist/connectors/rendered-design.js.map +1 -0
  252. package/dist/connectors/rendered-page.d.ts +115 -0
  253. package/dist/connectors/rendered-page.d.ts.map +1 -0
  254. package/dist/connectors/rendered-page.js +1036 -0
  255. package/dist/connectors/rendered-page.js.map +1 -0
  256. package/dist/connectors/smart-defaults.d.ts +9 -0
  257. package/dist/connectors/smart-defaults.d.ts.map +1 -0
  258. package/dist/connectors/smart-defaults.js +72 -0
  259. package/dist/connectors/smart-defaults.js.map +1 -0
  260. package/dist/connectors/types.d.ts +79 -0
  261. package/dist/connectors/types.d.ts.map +1 -0
  262. package/dist/connectors/types.js +2 -0
  263. package/dist/connectors/types.js.map +1 -0
  264. package/dist/connectors/upload.d.ts +9 -0
  265. package/dist/connectors/upload.d.ts.map +1 -0
  266. package/dist/connectors/upload.js +440 -0
  267. package/dist/connectors/upload.js.map +1 -0
  268. package/dist/connectors/website.d.ts +20 -0
  269. package/dist/connectors/website.d.ts.map +1 -0
  270. package/dist/connectors/website.js +616 -0
  271. package/dist/connectors/website.js.map +1 -0
  272. package/dist/embeddings/index.d.ts +3 -0
  273. package/dist/embeddings/index.d.ts.map +1 -0
  274. package/dist/embeddings/index.js +3 -0
  275. package/dist/embeddings/index.js.map +1 -0
  276. package/dist/embeddings/providers.d.ts +2 -0
  277. package/dist/embeddings/providers.d.ts.map +1 -0
  278. package/dist/embeddings/providers.js +2 -0
  279. package/dist/embeddings/providers.js.map +1 -0
  280. package/dist/embeddings/types.d.ts +2 -0
  281. package/dist/embeddings/types.d.ts.map +1 -0
  282. package/dist/embeddings/types.js +2 -0
  283. package/dist/embeddings/types.js.map +1 -0
  284. package/dist/eval/acceptance-fixtures.d.ts +3 -0
  285. package/dist/eval/acceptance-fixtures.d.ts.map +1 -0
  286. package/dist/eval/acceptance-fixtures.js +84 -0
  287. package/dist/eval/acceptance-fixtures.js.map +1 -0
  288. package/dist/eval/acceptance.d.ts +114 -0
  289. package/dist/eval/acceptance.d.ts.map +1 -0
  290. package/dist/eval/acceptance.js +260 -0
  291. package/dist/eval/acceptance.js.map +1 -0
  292. package/dist/eval/fixtures.d.ts +16 -0
  293. package/dist/eval/fixtures.d.ts.map +1 -0
  294. package/dist/eval/fixtures.js +119 -0
  295. package/dist/eval/fixtures.js.map +1 -0
  296. package/dist/eval/index.d.ts +63 -0
  297. package/dist/eval/index.d.ts.map +1 -0
  298. package/dist/eval/index.js +174 -0
  299. package/dist/eval/index.js.map +1 -0
  300. package/dist/index.d.ts +5 -0
  301. package/dist/index.d.ts.map +1 -0
  302. package/dist/index.js +5 -0
  303. package/dist/index.js.map +1 -0
  304. package/dist/jobs/background-worker.d.ts +31 -0
  305. package/dist/jobs/background-worker.d.ts.map +1 -0
  306. package/dist/jobs/background-worker.js +315 -0
  307. package/dist/jobs/background-worker.js.map +1 -0
  308. package/dist/jobs/import-runner.d.ts +3 -0
  309. package/dist/jobs/import-runner.d.ts.map +1 -0
  310. package/dist/jobs/import-runner.js +613 -0
  311. package/dist/jobs/import-runner.js.map +1 -0
  312. package/dist/jobs/index.d.ts +9 -0
  313. package/dist/jobs/index.d.ts.map +1 -0
  314. package/dist/jobs/index.js +8 -0
  315. package/dist/jobs/index.js.map +1 -0
  316. package/dist/jobs/progress.d.ts +3 -0
  317. package/dist/jobs/progress.d.ts.map +1 -0
  318. package/dist/jobs/progress.js +30 -0
  319. package/dist/jobs/progress.js.map +1 -0
  320. package/dist/jobs/rebuild.d.ts +13 -0
  321. package/dist/jobs/rebuild.d.ts.map +1 -0
  322. package/dist/jobs/rebuild.js +178 -0
  323. package/dist/jobs/rebuild.js.map +1 -0
  324. package/dist/jobs/server-worker.d.ts +16 -0
  325. package/dist/jobs/server-worker.d.ts.map +1 -0
  326. package/dist/jobs/server-worker.js +262 -0
  327. package/dist/jobs/server-worker.js.map +1 -0
  328. package/dist/jobs/store-adapter.d.ts +3 -0
  329. package/dist/jobs/store-adapter.d.ts.map +1 -0
  330. package/dist/jobs/store-adapter.js +37 -0
  331. package/dist/jobs/store-adapter.js.map +1 -0
  332. package/dist/jobs/types.d.ts +138 -0
  333. package/dist/jobs/types.d.ts.map +1 -0
  334. package/dist/jobs/types.js +2 -0
  335. package/dist/jobs/types.js.map +1 -0
  336. package/dist/jobs/worker.d.ts +27 -0
  337. package/dist/jobs/worker.d.ts.map +1 -0
  338. package/dist/jobs/worker.js +90 -0
  339. package/dist/jobs/worker.js.map +1 -0
  340. package/dist/media-url.d.ts +7 -0
  341. package/dist/media-url.d.ts.map +1 -0
  342. package/dist/media-url.js +15 -0
  343. package/dist/media-url.js.map +1 -0
  344. package/dist/native-artifact-reassembly.d.ts +25 -0
  345. package/dist/native-artifact-reassembly.d.ts.map +1 -0
  346. package/dist/native-artifact-reassembly.js +262 -0
  347. package/dist/native-artifact-reassembly.js.map +1 -0
  348. package/dist/native-artifact.d.ts +88 -0
  349. package/dist/native-artifact.d.ts.map +1 -0
  350. package/dist/native-artifact.js +86 -0
  351. package/dist/native-artifact.js.map +1 -0
  352. package/dist/schema/index.d.ts +7111 -0
  353. package/dist/schema/index.d.ts.map +1 -0
  354. package/dist/schema/index.js +469 -0
  355. package/dist/schema/index.js.map +1 -0
  356. package/dist/schema/migrations.d.ts +10 -0
  357. package/dist/schema/migrations.d.ts.map +1 -0
  358. package/dist/schema/migrations.js +333 -0
  359. package/dist/schema/migrations.js.map +1 -0
  360. package/dist/search/fusion.d.ts +2 -0
  361. package/dist/search/fusion.d.ts.map +1 -0
  362. package/dist/search/fusion.js +2 -0
  363. package/dist/search/fusion.js.map +1 -0
  364. package/dist/search/mode.d.ts +4 -0
  365. package/dist/search/mode.d.ts.map +1 -0
  366. package/dist/search/mode.js +13 -0
  367. package/dist/search/mode.js.map +1 -0
  368. package/dist/search/postgres-fts.d.ts +2 -0
  369. package/dist/search/postgres-fts.d.ts.map +1 -0
  370. package/dist/search/postgres-fts.js +2 -0
  371. package/dist/search/postgres-fts.js.map +1 -0
  372. package/dist/server/brand-context.d.ts +15 -0
  373. package/dist/server/brand-context.d.ts.map +1 -0
  374. package/dist/server/brand-context.js +149 -0
  375. package/dist/server/brand-context.js.map +1 -0
  376. package/dist/server/context.d.ts +77 -0
  377. package/dist/server/context.d.ts.map +1 -0
  378. package/dist/server/context.js +63 -0
  379. package/dist/server/context.js.map +1 -0
  380. package/dist/server/enrichment.d.ts +24 -0
  381. package/dist/server/enrichment.d.ts.map +1 -0
  382. package/dist/server/enrichment.js +138 -0
  383. package/dist/server/enrichment.js.map +1 -0
  384. package/dist/server/generation-artifact-access.d.ts +21 -0
  385. package/dist/server/generation-artifact-access.d.ts.map +1 -0
  386. package/dist/server/generation-artifact-access.js +113 -0
  387. package/dist/server/generation-artifact-access.js.map +1 -0
  388. package/dist/server/generation-context.d.ts +220 -0
  389. package/dist/server/generation-context.d.ts.map +1 -0
  390. package/dist/server/generation-context.js +432 -0
  391. package/dist/server/generation-context.js.map +1 -0
  392. package/dist/server/index.d.ts +27 -0
  393. package/dist/server/index.d.ts.map +1 -0
  394. package/dist/server/index.js +115 -0
  395. package/dist/server/index.js.map +1 -0
  396. package/dist/server/isolated-a2a.d.ts +175 -0
  397. package/dist/server/isolated-a2a.d.ts.map +1 -0
  398. package/dist/server/isolated-a2a.js +312 -0
  399. package/dist/server/isolated-a2a.js.map +1 -0
  400. package/dist/server/media.d.ts +15 -0
  401. package/dist/server/media.d.ts.map +1 -0
  402. package/dist/server/media.js +108 -0
  403. package/dist/server/media.js.map +1 -0
  404. package/dist/server/native-resource-capture.d.ts +78 -0
  405. package/dist/server/native-resource-capture.d.ts.map +1 -0
  406. package/dist/server/native-resource-capture.js +94 -0
  407. package/dist/server/native-resource-capture.js.map +1 -0
  408. package/dist/server/prompt-provider.d.ts +5 -0
  409. package/dist/server/prompt-provider.d.ts.map +1 -0
  410. package/dist/server/prompt-provider.js +59 -0
  411. package/dist/server/prompt-provider.js.map +1 -0
  412. package/dist/server/public-serialization.d.ts +160 -0
  413. package/dist/server/public-serialization.d.ts.map +1 -0
  414. package/dist/server/public-serialization.js +108 -0
  415. package/dist/server/public-serialization.js.map +1 -0
  416. package/dist/server/resource-paths.d.ts +3 -0
  417. package/dist/server/resource-paths.d.ts.map +1 -0
  418. package/dist/server/resource-paths.js +5 -0
  419. package/dist/server/resource-paths.js.map +1 -0
  420. package/dist/server/retrieval.d.ts +83 -0
  421. package/dist/server/retrieval.d.ts.map +1 -0
  422. package/dist/server/retrieval.js +445 -0
  423. package/dist/server/retrieval.js.map +1 -0
  424. package/dist/server/safe-native-preview.d.ts +15 -0
  425. package/dist/server/safe-native-preview.d.ts.map +1 -0
  426. package/dist/server/safe-native-preview.js +148 -0
  427. package/dist/server/safe-native-preview.js.map +1 -0
  428. package/dist/store/brand.d.ts +47 -0
  429. package/dist/store/brand.d.ts.map +1 -0
  430. package/dist/store/brand.js +346 -0
  431. package/dist/store/brand.js.map +1 -0
  432. package/dist/store/content.d.ts +134 -0
  433. package/dist/store/content.d.ts.map +1 -0
  434. package/dist/store/content.js +1677 -0
  435. package/dist/store/content.js.map +1 -0
  436. package/dist/store/contexts.d.ts +216 -0
  437. package/dist/store/contexts.d.ts.map +1 -0
  438. package/dist/store/contexts.js +1346 -0
  439. package/dist/store/contexts.js.map +1 -0
  440. package/dist/store/generation.d.ts +28 -0
  441. package/dist/store/generation.d.ts.map +1 -0
  442. package/dist/store/generation.js +140 -0
  443. package/dist/store/generation.js.map +1 -0
  444. package/dist/store/helpers.d.ts +12 -0
  445. package/dist/store/helpers.d.ts.map +1 -0
  446. package/dist/store/helpers.js +41 -0
  447. package/dist/store/helpers.js.map +1 -0
  448. package/dist/store/index.d.ts +11 -0
  449. package/dist/store/index.d.ts.map +1 -0
  450. package/dist/store/index.js +11 -0
  451. package/dist/store/index.js.map +1 -0
  452. package/dist/store/inference.d.ts +57 -0
  453. package/dist/store/inference.d.ts.map +1 -0
  454. package/dist/store/inference.js +279 -0
  455. package/dist/store/inference.js.map +1 -0
  456. package/dist/store/jobs.d.ts +80 -0
  457. package/dist/store/jobs.d.ts.map +1 -0
  458. package/dist/store/jobs.js +428 -0
  459. package/dist/store/jobs.js.map +1 -0
  460. package/dist/store/native-artifact-summary.d.ts +7 -0
  461. package/dist/store/native-artifact-summary.d.ts.map +1 -0
  462. package/dist/store/native-artifact-summary.js +10 -0
  463. package/dist/store/native-artifact-summary.js.map +1 -0
  464. package/dist/store/packs.d.ts +36 -0
  465. package/dist/store/packs.d.ts.map +1 -0
  466. package/dist/store/packs.js +438 -0
  467. package/dist/store/packs.js.map +1 -0
  468. package/dist/store/purge.d.ts +16 -0
  469. package/dist/store/purge.d.ts.map +1 -0
  470. package/dist/store/purge.js +354 -0
  471. package/dist/store/purge.js.map +1 -0
  472. package/dist/store/sources.d.ts +76 -0
  473. package/dist/store/sources.d.ts.map +1 -0
  474. package/dist/store/sources.js +525 -0
  475. package/dist/store/sources.js.map +1 -0
  476. package/dist/store/suggestions.d.ts +29 -0
  477. package/dist/store/suggestions.d.ts.map +1 -0
  478. package/dist/store/suggestions.js +270 -0
  479. package/dist/store/suggestions.js.map +1 -0
  480. package/dist/types.d.ts +578 -0
  481. package/dist/types.d.ts.map +1 -0
  482. package/dist/types.js +10 -0
  483. package/dist/types.js.map +1 -0
  484. package/dist/untrusted-reference.d.ts +8 -0
  485. package/dist/untrusted-reference.d.ts.map +1 -0
  486. package/dist/untrusted-reference.js +19 -0
  487. package/dist/untrusted-reference.js.map +1 -0
  488. package/dist/vector/index.d.ts +2 -0
  489. package/dist/vector/index.d.ts.map +1 -0
  490. package/dist/vector/index.js +2 -0
  491. package/dist/vector/index.js.map +1 -0
  492. package/dist/vector/pgvector.d.ts +2 -0
  493. package/dist/vector/pgvector.d.ts.map +1 -0
  494. package/dist/vector/pgvector.js +2 -0
  495. package/dist/vector/pgvector.js.map +1 -0
  496. package/docs/evaluation.md +92 -0
  497. package/docs/llms-full.txt +168 -0
  498. package/docs/llms.txt +76 -0
  499. package/docs/skills/creative-context/SKILL.md +90 -0
  500. package/package.json +100 -0
  501. package/src/actions/agent-input-schemas.spec.ts +46 -0
  502. package/src/actions/confirm-canonical-logo.ts +20 -0
  503. package/src/actions/continue-context-import.ts +15 -0
  504. package/src/actions/creative-context-a2a.spec.ts +162 -0
  505. package/src/actions/creative-context-a2a.ts +88 -0
  506. package/src/actions/get-brand-profile.ts +16 -0
  507. package/src/actions/get-context-import-status.ts +13 -0
  508. package/src/actions/get-context-item.ts +1 -0
  509. package/src/actions/get-context-pack.ts +14 -0
  510. package/src/actions/get-creative-context.spec.ts +435 -0
  511. package/src/actions/get-creative-context.ts +197 -0
  512. package/src/actions/get-google-picker-session.spec.ts +62 -0
  513. package/src/actions/get-google-picker-session.ts +45 -0
  514. package/src/actions/index.ts +75 -0
  515. package/src/actions/infer-brand-dna.ts +15 -0
  516. package/src/actions/job-public-serialization.spec.ts +143 -0
  517. package/src/actions/list-canonical-logo-candidates.ts +121 -0
  518. package/src/actions/list-context-connections.spec.ts +23 -0
  519. package/src/actions/list-context-connections.ts +51 -0
  520. package/src/actions/list-context-memberships.ts +56 -0
  521. package/src/actions/list-context-packs.ts +17 -0
  522. package/src/actions/list-context-sources.ts +21 -0
  523. package/src/actions/list-context-suggestions.ts +30 -0
  524. package/src/actions/list-creative-contexts.spec.ts +38 -0
  525. package/src/actions/list-creative-contexts.ts +32 -0
  526. package/src/actions/manage-brand-profile.ts +58 -0
  527. package/src/actions/manage-context-membership.ts +80 -0
  528. package/src/actions/manage-context-pack.ts +81 -0
  529. package/src/actions/manage-context-source.ts +151 -0
  530. package/src/actions/manage-creative-context.ts +73 -0
  531. package/src/actions/manage-layout-template.ts +51 -0
  532. package/src/actions/preview-context-import.spec.ts +64 -0
  533. package/src/actions/preview-context-import.ts +61 -0
  534. package/src/actions/process-context-purge.ts +28 -0
  535. package/src/actions/propose-brand-dna.ts +22 -0
  536. package/src/actions/propose-canonical-logo.ts +19 -0
  537. package/src/actions/publish-brand-dna.ts +25 -0
  538. package/src/actions/recommend-context-roots.ts +24 -0
  539. package/src/actions/record-context-feedback.ts +16 -0
  540. package/src/actions/review-context-items.ts +69 -0
  541. package/src/actions/run-embedding-bakeoff.ts +90 -0
  542. package/src/actions/search-creative-context.ts +48 -0
  543. package/src/actions/set-brand-dna.ts +22 -0
  544. package/src/actions/start-context-enrichment.ts +52 -0
  545. package/src/actions/start-context-import.ts +38 -0
  546. package/src/client/CreativeContextChip.spec.ts +59 -0
  547. package/src/client/CreativeContextChip.tsx +243 -0
  548. package/src/client/CreativeContextPanel.tsx +3600 -0
  549. package/src/client/CreativeContextSettingsLink.tsx +30 -0
  550. package/src/client/CreativeContextShareTab.spec.ts +70 -0
  551. package/src/client/CreativeContextShareTab.tsx +666 -0
  552. package/src/client/actions.spec.ts +177 -0
  553. package/src/client/actions.ts +1024 -0
  554. package/src/client/agent-tab.tsx +56 -0
  555. package/src/client/application-state.spec.ts +46 -0
  556. package/src/client/application-state.ts +158 -0
  557. package/src/client/google-slides-picker.spec.ts +36 -0
  558. package/src/client/google-slides-picker.ts +146 -0
  559. package/src/client/index.ts +102 -0
  560. package/src/client/messages.ts +1370 -0
  561. package/src/client/source-config.spec.ts +166 -0
  562. package/src/connectors/connectors.spec.ts +778 -0
  563. package/src/connectors/context.ts +83 -0
  564. package/src/connectors/document-parser.ts +5 -0
  565. package/src/connectors/figma-native.ts +1192 -0
  566. package/src/connectors/figma-native.visual.spec.ts +221 -0
  567. package/src/connectors/figma.spec.ts +812 -0
  568. package/src/connectors/figma.ts +257 -0
  569. package/src/connectors/fixtures/google-slides-native.json +353 -0
  570. package/src/connectors/google-slides-native.spec.ts +804 -0
  571. package/src/connectors/google-slides-native.ts +1656 -0
  572. package/src/connectors/google-slides-native.visual.spec.ts +119 -0
  573. package/src/connectors/google-slides.ts +1171 -0
  574. package/src/connectors/index.ts +112 -0
  575. package/src/connectors/manual.ts +132 -0
  576. package/src/connectors/normalize.spec.ts +144 -0
  577. package/src/connectors/normalize.ts +475 -0
  578. package/src/connectors/notion.ts +529 -0
  579. package/src/connectors/private-artifacts.spec.ts +95 -0
  580. package/src/connectors/private-artifacts.ts +248 -0
  581. package/src/connectors/provider-response.ts +144 -0
  582. package/src/connectors/recommendations.ts +237 -0
  583. package/src/connectors/registry.ts +48 -0
  584. package/src/connectors/rendered-design.spec.ts +171 -0
  585. package/src/connectors/rendered-design.ts +495 -0
  586. package/src/connectors/rendered-page.spec.ts +388 -0
  587. package/src/connectors/rendered-page.ts +1387 -0
  588. package/src/connectors/smart-defaults.spec.ts +135 -0
  589. package/src/connectors/smart-defaults.ts +87 -0
  590. package/src/connectors/types.ts +113 -0
  591. package/src/connectors/upload.spec.ts +175 -0
  592. package/src/connectors/upload.ts +548 -0
  593. package/src/connectors/website.spec.ts +465 -0
  594. package/src/connectors/website.ts +777 -0
  595. package/src/embeddings/index.ts +2 -0
  596. package/src/embeddings/providers.spec.ts +73 -0
  597. package/src/embeddings/providers.ts +1 -0
  598. package/src/embeddings/types.ts +6 -0
  599. package/src/eval/acceptance-fixtures.ts +97 -0
  600. package/src/eval/acceptance.spec.ts +92 -0
  601. package/src/eval/acceptance.ts +371 -0
  602. package/src/eval/connectors-golden.spec.ts +421 -0
  603. package/src/eval/eval.spec.ts +166 -0
  604. package/src/eval/fixtures/README.md +17 -0
  605. package/src/eval/fixtures/figma-brand-system-v1.json +140 -0
  606. package/src/eval/fixtures/figma-brand-system-v2.json +127 -0
  607. package/src/eval/fixtures/launch-hero.png +0 -0
  608. package/src/eval/fixtures/launch-system-v1.pptx +0 -0
  609. package/src/eval/fixtures/launch-system-v2.pptx +0 -0
  610. package/src/eval/fixtures/notion-brand-root.json +218 -0
  611. package/src/eval/fixtures/pricing-hero.png +0 -0
  612. package/src/eval/fixtures/rendered-brand-page.html +76 -0
  613. package/src/eval/fixtures.spec.ts +43 -0
  614. package/src/eval/fixtures.ts +136 -0
  615. package/src/eval/index.ts +291 -0
  616. package/src/eval/library-flow.acceptance.spec.tsx +145 -0
  617. package/src/index.ts +4 -0
  618. package/src/jobs/background-worker.ts +423 -0
  619. package/src/jobs/import-runner.spec.ts +582 -0
  620. package/src/jobs/import-runner.ts +791 -0
  621. package/src/jobs/index.ts +40 -0
  622. package/src/jobs/progress.ts +37 -0
  623. package/src/jobs/rebuild.ts +245 -0
  624. package/src/jobs/server-worker.spec.ts +181 -0
  625. package/src/jobs/server-worker.ts +354 -0
  626. package/src/jobs/store-adapter.ts +52 -0
  627. package/src/jobs/types.ts +147 -0
  628. package/src/jobs/worker.ts +152 -0
  629. package/src/manifest.spec.ts +26 -0
  630. package/src/media-url.ts +17 -0
  631. package/src/native-artifact-reassembly.spec.ts +386 -0
  632. package/src/native-artifact-reassembly.ts +406 -0
  633. package/src/native-artifact.ts +102 -0
  634. package/src/schema/index.ts +527 -0
  635. package/src/schema/migrations.spec.ts +41 -0
  636. package/src/schema/migrations.ts +338 -0
  637. package/src/search/fusion.spec.ts +21 -0
  638. package/src/search/fusion.ts +1 -0
  639. package/src/search/mode.spec.ts +28 -0
  640. package/src/search/mode.ts +21 -0
  641. package/src/search/postgres-fts.spec.ts +63 -0
  642. package/src/search/postgres-fts.ts +1 -0
  643. package/src/server/brand-context.spec.ts +43 -0
  644. package/src/server/brand-context.ts +160 -0
  645. package/src/server/context.ts +162 -0
  646. package/src/server/enrichment.spec.ts +94 -0
  647. package/src/server/enrichment.ts +166 -0
  648. package/src/server/generation-artifact-access.spec.ts +104 -0
  649. package/src/server/generation-artifact-access.ts +217 -0
  650. package/src/server/generation-context-a2a.spec.ts +282 -0
  651. package/src/server/generation-context-off.spec.ts +213 -0
  652. package/src/server/generation-context.spec.ts +124 -0
  653. package/src/server/generation-context.ts +639 -0
  654. package/src/server/index.spec.ts +30 -0
  655. package/src/server/index.ts +163 -0
  656. package/src/server/isolated-a2a.spec.ts +184 -0
  657. package/src/server/isolated-a2a.ts +416 -0
  658. package/src/server/media.spec.ts +120 -0
  659. package/src/server/media.ts +136 -0
  660. package/src/server/native-resource-capture.spec.ts +121 -0
  661. package/src/server/native-resource-capture.ts +198 -0
  662. package/src/server/prompt-provider.spec.ts +78 -0
  663. package/src/server/prompt-provider.ts +73 -0
  664. package/src/server/public-serialization.spec.ts +150 -0
  665. package/src/server/public-serialization.ts +130 -0
  666. package/src/server/resource-paths.spec.ts +9 -0
  667. package/src/server/resource-paths.ts +5 -0
  668. package/src/server/retrieval-vector.spec.ts +180 -0
  669. package/src/server/retrieval.ts +590 -0
  670. package/src/server/safe-native-preview.spec.ts +29 -0
  671. package/src/server/safe-native-preview.ts +199 -0
  672. package/src/store/access.integration.spec.ts +3523 -0
  673. package/src/store/brand.ts +458 -0
  674. package/src/store/content.ts +2317 -0
  675. package/src/store/contexts.ts +1840 -0
  676. package/src/store/generation.ts +226 -0
  677. package/src/store/helpers.ts +53 -0
  678. package/src/store/index.ts +10 -0
  679. package/src/store/inference.spec.ts +84 -0
  680. package/src/store/inference.ts +339 -0
  681. package/src/store/invariants.spec.ts +119 -0
  682. package/src/store/jobs.ts +674 -0
  683. package/src/store/native-artifact-summary.ts +13 -0
  684. package/src/store/packs.ts +721 -0
  685. package/src/store/purge.ts +463 -0
  686. package/src/store/sources.spec.ts +102 -0
  687. package/src/store/sources.ts +692 -0
  688. package/src/store/suggestions.ts +361 -0
  689. package/src/types.ts +671 -0
  690. package/src/untrusted-reference.spec.ts +22 -0
  691. package/src/untrusted-reference.ts +24 -0
  692. package/src/vector/index.ts +1 -0
  693. package/src/vector/pgvector.spec.ts +115 -0
  694. package/src/vector/pgvector.ts +1 -0
  695. package/tsconfig.json +31 -0
@@ -0,0 +1,1656 @@
1
+ import type {
2
+ NativeCreativeArtifact,
3
+ NativeCreativeArtifactFidelityReport,
4
+ } from "../native-artifact.js";
5
+ import type { ContextMediaInput } from "../types.js";
6
+
7
+ const SLIDE_WIDTH = 960;
8
+ const MAX_INLINE_HTML_BYTES = 128 * 1024;
9
+ const INLINE_PART_TARGET_BYTES = 120 * 1024;
10
+
11
+ type AffineTransform = [number, number, number, number, number, number];
12
+ const IDENTITY_TRANSFORM: AffineTransform = [1, 0, 0, 1, 0, 0];
13
+ const TEXT_INSET_PX = 9.6;
14
+
15
+ type JsonObject = Record<string, unknown>;
16
+
17
+ export interface SlidesNativeAssetRequest {
18
+ sourceUrl: string;
19
+ provenanceUrl?: string;
20
+ presentationId: string;
21
+ slideObjectId: string;
22
+ elementObjectId: string;
23
+ revisionId?: string;
24
+ kind: "image" | "fallback";
25
+ bounds: SlidesNativeBounds;
26
+ }
27
+
28
+ export interface SlidesNativeFallbackRequest {
29
+ presentationId: string;
30
+ slideObjectId: string;
31
+ elementObjectId: string;
32
+ revisionId?: string;
33
+ bounds: SlidesNativeBounds;
34
+ reason: string;
35
+ }
36
+
37
+ export interface SlidesNativeBounds {
38
+ x: number;
39
+ y: number;
40
+ width: number;
41
+ height: number;
42
+ }
43
+
44
+ export interface CompiledGoogleSlide {
45
+ objectId: string;
46
+ html: string;
47
+ plainText: string;
48
+ lexicalText: string;
49
+ media: ContextMediaInput[];
50
+ nativeArtifact: NativeCreativeArtifact;
51
+ childArtifacts: CompiledGoogleSlideChild[];
52
+ }
53
+
54
+ export interface CompiledGoogleSlideChild {
55
+ externalId: string;
56
+ objectId: string;
57
+ html: string;
58
+ lexicalText: string;
59
+ nativeArtifact: NativeCreativeArtifact;
60
+ }
61
+
62
+ export interface GoogleSlidesNativeCompileOptions {
63
+ presentationId: string;
64
+ revisionId?: string;
65
+ resolveAsset: (
66
+ request: SlidesNativeAssetRequest,
67
+ ) => Promise<ContextMediaInput & { id: string; url: string }>;
68
+ resolveFallback?: (
69
+ request: SlidesNativeFallbackRequest,
70
+ ) => Promise<(ContextMediaInput & { id: string; url: string }) | null>;
71
+ }
72
+
73
+ type FidelityBucket = "exact" | "approximated" | "imageFallback";
74
+
75
+ interface CompileState {
76
+ presentationId: string;
77
+ revisionId?: string;
78
+ slideObjectId: string;
79
+ pageWidth: number;
80
+ pageHeight: number;
81
+ canvasScale: number;
82
+ themeColors: Map<string, string>;
83
+ media: ContextMediaInput[];
84
+ assetRefs: string[];
85
+ plainText: string[];
86
+ fidelity: NativeCreativeArtifactFidelityReport;
87
+ resolveAsset: GoogleSlidesNativeCompileOptions["resolveAsset"];
88
+ resolveFallback?: GoogleSlidesNativeCompileOptions["resolveFallback"];
89
+ }
90
+
91
+ interface CompileStateSnapshot {
92
+ media: number;
93
+ assetRefs: number;
94
+ exact: number;
95
+ approximated: number;
96
+ approximatedReasons: number;
97
+ imageFallback: number;
98
+ imageFallbackReasons: number;
99
+ }
100
+
101
+ export async function compileGoogleSlidesPresentation(
102
+ presentation: JsonObject,
103
+ options: GoogleSlidesNativeCompileOptions,
104
+ ): Promise<CompiledGoogleSlide[]> {
105
+ const pageSize = record(presentation.pageSize);
106
+ const pageWidth = dimensionToPx(record(pageSize?.width)) || SLIDE_WIDTH;
107
+ const pageHeight = dimensionToPx(record(pageSize?.height)) || 540;
108
+ const masters = objectMap(presentation.masters);
109
+ const layouts = objectMap(presentation.layouts);
110
+ const slides = array(presentation.slides);
111
+ const compiled: CompiledGoogleSlide[] = [];
112
+
113
+ for (const value of slides) {
114
+ const slide = record(value);
115
+ const objectId = text(slide?.objectId);
116
+ if (!slide || !objectId) continue;
117
+ const slideProperties = record(slide.slideProperties);
118
+ const layout = layouts.get(text(slideProperties?.layoutObjectId) ?? "");
119
+ const layoutProperties = record(layout?.layoutProperties);
120
+ const master = masters.get(
121
+ text(slideProperties?.masterObjectId) ??
122
+ text(layoutProperties?.masterObjectId) ??
123
+ "",
124
+ );
125
+ const themeColors = resolveThemeColors(master, layout, slide);
126
+ const state: CompileState = {
127
+ presentationId: options.presentationId,
128
+ revisionId: options.revisionId,
129
+ slideObjectId: objectId,
130
+ pageWidth,
131
+ pageHeight,
132
+ canvasScale: Math.min(SLIDE_WIDTH / pageWidth, 540 / pageHeight),
133
+ themeColors,
134
+ media: [],
135
+ assetRefs: [],
136
+ plainText: [],
137
+ fidelity: emptyFidelityReport(),
138
+ resolveAsset: options.resolveAsset,
139
+ resolveFallback: options.resolveFallback,
140
+ };
141
+ const pageElements = inheritedPageElements(master, layout, slide);
142
+ const rendered: Array<{
143
+ objectId: string;
144
+ html: string;
145
+ bounds: SlidesNativeBounds;
146
+ transform: AffineTransform;
147
+ fidelity: NativeCreativeArtifactFidelityReport;
148
+ }> = [];
149
+
150
+ for (let index = 0; index < pageElements.length; index++) {
151
+ const resolved = pageElements[index]!;
152
+ const element = resolved.element;
153
+ const snapshot = snapshotCompileState(state);
154
+ let result = await compilePageElement(
155
+ element,
156
+ state,
157
+ index,
158
+ resolved,
159
+ IDENTITY_TRANSFORM,
160
+ );
161
+ if (!result) continue;
162
+ if (Buffer.byteLength(result, "utf8") > INLINE_PART_TARGET_BYTES) {
163
+ restoreCompileState(state, snapshot);
164
+ const baseStyle = elementCss(element, index, state.canvasScale);
165
+ result = await compileFallback(
166
+ element,
167
+ state,
168
+ elementBounds(
169
+ element,
170
+ state.pageWidth,
171
+ state.pageHeight,
172
+ IDENTITY_TRANSFORM,
173
+ ),
174
+ "Element native markup exceeded the inline artifact budget.",
175
+ baseStyle,
176
+ );
177
+ }
178
+ rendered.push({
179
+ objectId: text(element.objectId) ?? `element-${index + 1}`,
180
+ html: result,
181
+ bounds: elementBounds(
182
+ element,
183
+ state.pageWidth,
184
+ state.pageHeight,
185
+ IDENTITY_TRANSFORM,
186
+ ),
187
+ transform: elementTransform(element),
188
+ fidelity: fidelitySince(state, snapshot),
189
+ });
190
+ }
191
+
192
+ const background = pageBackground(master, layout, slide, themeColors);
193
+ if (background.approximationReason) {
194
+ state.fidelity.approximated.count += 1;
195
+ state.fidelity.approximated.reasons.push({
196
+ nodeId: `${objectId}:background`,
197
+ nodeName: "Slide background",
198
+ nodeType: "pageBackground",
199
+ reasons: [background.approximationReason],
200
+ });
201
+ }
202
+ const rootStyle = css({
203
+ position: "relative",
204
+ width: `${SLIDE_WIDTH}px`,
205
+ height: "540px",
206
+ overflow: "hidden",
207
+ background: "#ffffff",
208
+ "transform-origin": "0 0",
209
+ });
210
+ const canvasStyle = css({
211
+ position: "absolute",
212
+ left: `${round((SLIDE_WIDTH - pageWidth * state.canvasScale) / 2)}px`,
213
+ top: `${round((540 - pageHeight * state.canvasScale) / 2)}px`,
214
+ width: `${round(pageWidth * state.canvasScale)}px`,
215
+ height: `${round(pageHeight * state.canvasScale)}px`,
216
+ overflow: "hidden",
217
+ background: background.css,
218
+ });
219
+ const assembledHtml = slideHtml(
220
+ objectId,
221
+ rootStyle,
222
+ canvasStyle,
223
+ rendered.map((entry) => entry.html).join(""),
224
+ );
225
+ const plainText = state.plainText.join("\n").replace(/\s+/g, " ").trim();
226
+ const rootExternalId = `${options.presentationId}:${objectId}`;
227
+ const childArtifacts: CompiledGoogleSlideChild[] = [];
228
+ let html = assembledHtml;
229
+ const nativeArtifact: NativeCreativeArtifact = {
230
+ schemaVersion: 1,
231
+ app: "slides",
232
+ format: "slides-html",
233
+ rootExternalId,
234
+ sourceBounds: { x: 0, y: 0, width: pageWidth, height: pageHeight },
235
+ fidelityReport: state.fidelity,
236
+ ...(state.assetRefs.length
237
+ ? { assetRefs: [...new Set(state.assetRefs)] }
238
+ : {}),
239
+ };
240
+ if (Buffer.byteLength(assembledHtml, "utf8") > MAX_INLINE_HTML_BYTES) {
241
+ const children = rendered.map((entry, index) => {
242
+ const externalId = `${rootExternalId}:native-part:${index + 1}`;
243
+ const childAssetRefs = assetRefsFromHtml(entry.html);
244
+ childArtifacts.push({
245
+ externalId,
246
+ objectId: entry.objectId,
247
+ html: entry.html,
248
+ lexicalText: lexicalIndexText(entry.html, ""),
249
+ nativeArtifact: {
250
+ schemaVersion: 1,
251
+ app: "slides",
252
+ format: "slides-html",
253
+ rootExternalId: externalId,
254
+ sourceBounds: entry.bounds,
255
+ fidelityReport: entry.fidelity,
256
+ ...(childAssetRefs.length ? { assetRefs: childAssetRefs } : {}),
257
+ },
258
+ });
259
+ return {
260
+ externalId,
261
+ sourceNodeId: entry.objectId,
262
+ bounds: entry.bounds,
263
+ transform: entry.transform,
264
+ zOrder: index,
265
+ };
266
+ });
267
+ nativeArtifact.childExternalIds = children.map(
268
+ (child) => child.externalId,
269
+ );
270
+ nativeArtifact.assetRefs = undefined;
271
+ nativeArtifact.manifest = {
272
+ kind: "hierarchical-artboard",
273
+ children,
274
+ };
275
+ html = slideHtml(
276
+ objectId,
277
+ rootStyle,
278
+ canvasStyle,
279
+ children
280
+ .map(
281
+ (child) =>
282
+ `<div data-creative-context-child="${escapeAttr(child.externalId)}"></div>`,
283
+ )
284
+ .join(""),
285
+ );
286
+ }
287
+ if (Buffer.byteLength(html, "utf8") > MAX_INLINE_HTML_BYTES) {
288
+ throw new Error(
289
+ `Compiled slide shell ${objectId} exceeds the ${MAX_INLINE_HTML_BYTES} byte inline HTML limit.`,
290
+ );
291
+ }
292
+ compiled.push({
293
+ objectId,
294
+ html,
295
+ plainText,
296
+ lexicalText: lexicalIndexText(assembledHtml, plainText),
297
+ media: state.media,
298
+ nativeArtifact,
299
+ childArtifacts,
300
+ });
301
+ }
302
+ return compiled;
303
+ }
304
+
305
+ function slideHtml(
306
+ objectId: string,
307
+ rootStyle: string,
308
+ canvasStyle: string,
309
+ content: string,
310
+ ): string {
311
+ return `<div class="fmd-slide google-slides-native" data-source-slide-id="${escapeAttr(objectId)}" style="${rootStyle}"><div class="google-slides-source-canvas" style="${canvasStyle}">${content}</div></div>`;
312
+ }
313
+
314
+ function snapshotCompileState(state: CompileState): CompileStateSnapshot {
315
+ return {
316
+ media: state.media.length,
317
+ assetRefs: state.assetRefs.length,
318
+ exact: state.fidelity.exact.count,
319
+ approximated: state.fidelity.approximated.count,
320
+ approximatedReasons: state.fidelity.approximated.reasons.length,
321
+ imageFallback: state.fidelity.imageFallback.count,
322
+ imageFallbackReasons: state.fidelity.imageFallback.reasons.length,
323
+ };
324
+ }
325
+
326
+ function restoreCompileState(
327
+ state: CompileState,
328
+ snapshot: CompileStateSnapshot,
329
+ ): void {
330
+ state.media.length = snapshot.media;
331
+ state.assetRefs.length = snapshot.assetRefs;
332
+ state.fidelity.exact.count = snapshot.exact;
333
+ state.fidelity.approximated.count = snapshot.approximated;
334
+ state.fidelity.approximated.reasons.length = snapshot.approximatedReasons;
335
+ state.fidelity.imageFallback.count = snapshot.imageFallback;
336
+ state.fidelity.imageFallback.reasons.length = snapshot.imageFallbackReasons;
337
+ }
338
+
339
+ function fidelitySince(
340
+ state: CompileState,
341
+ snapshot: CompileStateSnapshot,
342
+ ): NativeCreativeArtifactFidelityReport {
343
+ return {
344
+ exact: { count: state.fidelity.exact.count - snapshot.exact },
345
+ approximated: {
346
+ count: state.fidelity.approximated.count - snapshot.approximated,
347
+ reasons: state.fidelity.approximated.reasons.slice(
348
+ snapshot.approximatedReasons,
349
+ ),
350
+ },
351
+ imageFallback: {
352
+ count: state.fidelity.imageFallback.count - snapshot.imageFallback,
353
+ reasons: state.fidelity.imageFallback.reasons.slice(
354
+ snapshot.imageFallbackReasons,
355
+ ),
356
+ },
357
+ };
358
+ }
359
+
360
+ function inheritedPageElements(
361
+ master: JsonObject | undefined,
362
+ layout: JsonObject | undefined,
363
+ slide: JsonObject,
364
+ ): Array<{
365
+ element: JsonObject;
366
+ inherited: JsonObject[];
367
+ local?: JsonObject;
368
+ }> {
369
+ const masterElements = pageElementMap(master?.pageElements);
370
+ const layoutElements = pageElementMap(layout?.pageElements);
371
+ const slideElements = pageElementMap(slide.pageElements);
372
+ const masterPlaceholders = placeholderMap(masterElements);
373
+ const layoutPlaceholders = placeholderMap(layoutElements);
374
+ const claimedLayout = new Set<string>();
375
+ const claimedMaster = new Set<string>();
376
+ const output: Array<{
377
+ element: JsonObject;
378
+ inherited: JsonObject[];
379
+ local?: JsonObject;
380
+ }> = [];
381
+
382
+ for (const element of slideElements.values()) {
383
+ const placeholder = elementPlaceholder(element);
384
+ const layoutElement = resolvePlaceholder(
385
+ placeholder,
386
+ layoutElements,
387
+ layoutPlaceholders,
388
+ );
389
+ const masterElement =
390
+ resolvePlaceholder(
391
+ elementPlaceholder(layoutElement),
392
+ masterElements,
393
+ masterPlaceholders,
394
+ ) ?? resolvePlaceholder(placeholder, masterElements, masterPlaceholders);
395
+ const layoutId = text(layoutElement?.objectId);
396
+ const masterId = text(masterElement?.objectId);
397
+ if (layoutId) claimedLayout.add(layoutId);
398
+ if (masterId) claimedMaster.add(masterId);
399
+ output.push({
400
+ element: mergeElement(masterElement, layoutElement, element),
401
+ inherited: [masterElement, layoutElement].filter(
402
+ (entry): entry is JsonObject => Boolean(entry),
403
+ ),
404
+ local: element,
405
+ });
406
+ }
407
+ const inheritedDecorations = [
408
+ ...[...masterElements.values()]
409
+ .filter(
410
+ (element) =>
411
+ !elementPlaceholder(element) &&
412
+ !claimedMaster.has(text(element.objectId) ?? ""),
413
+ )
414
+ .map((element) => ({ element, inherited: [] })),
415
+ ...[...layoutElements.values()]
416
+ .filter(
417
+ (element) =>
418
+ !elementPlaceholder(element) &&
419
+ !claimedLayout.has(text(element.objectId) ?? ""),
420
+ )
421
+ .map((element) => ({ element, inherited: [] })),
422
+ ];
423
+ return [...inheritedDecorations, ...output];
424
+ }
425
+
426
+ async function compilePageElement(
427
+ element: JsonObject,
428
+ state: CompileState,
429
+ zOrder: number,
430
+ resolved: { inherited: JsonObject[]; local?: JsonObject },
431
+ parentTransform: AffineTransform,
432
+ ): Promise<string | null> {
433
+ const objectId = text(element.objectId) ?? `element-${zOrder + 1}`;
434
+ const absoluteTransform = multiplyTransforms(
435
+ parentTransform,
436
+ elementTransform(element),
437
+ );
438
+ const bounds = elementBounds(
439
+ element,
440
+ state.pageWidth,
441
+ state.pageHeight,
442
+ parentTransform,
443
+ );
444
+ const absorbAxisAlignedScale =
445
+ !record(element.elementGroup) &&
446
+ !record(element.line) &&
447
+ shouldAbsorbAxisAlignedScale(element);
448
+ const baseStyle = elementCss(
449
+ element,
450
+ zOrder,
451
+ state.canvasScale,
452
+ absorbAxisAlignedScale,
453
+ );
454
+ if (record(element.wordArt)) {
455
+ return compileFallback(
456
+ element,
457
+ state,
458
+ bounds,
459
+ "WordArt requires raster fidelity.",
460
+ baseStyle,
461
+ );
462
+ }
463
+ if (record(element.sheetsChart)) {
464
+ return compileFallback(
465
+ element,
466
+ state,
467
+ bounds,
468
+ "Linked Sheets chart is indivisible.",
469
+ baseStyle,
470
+ );
471
+ }
472
+ if (record(element.video)) {
473
+ return compileFallback(
474
+ element,
475
+ state,
476
+ bounds,
477
+ "Video poster is indivisible.",
478
+ baseStyle,
479
+ );
480
+ }
481
+ const image = record(element.image);
482
+ if (image) {
483
+ const sourceUrl = text(image.contentUrl);
484
+ if (!sourceUrl) {
485
+ return compileFallback(
486
+ element,
487
+ state,
488
+ bounds,
489
+ "Image has no retrievable content URL.",
490
+ baseStyle,
491
+ );
492
+ }
493
+ const asset = await state.resolveAsset({
494
+ sourceUrl,
495
+ provenanceUrl: safeSourceUrl(text(image.sourceUrl)),
496
+ presentationId: state.presentationId,
497
+ slideObjectId: state.slideObjectId,
498
+ elementObjectId: objectId,
499
+ revisionId: state.revisionId,
500
+ kind: "image",
501
+ bounds,
502
+ });
503
+ state.media.push(asset);
504
+ state.assetRefs.push(asset.url);
505
+ const reasons = imageApproximationReasons(image);
506
+ markFidelity(
507
+ state,
508
+ reasons.length ? "approximated" : "exact",
509
+ element,
510
+ reasons,
511
+ );
512
+ return imageMarkup(element, image, asset.url, baseStyle, state.themeColors);
513
+ }
514
+ const table = record(element.table);
515
+ if (table) {
516
+ const reasons = tableApproximationReasons(table);
517
+ markFidelity(
518
+ state,
519
+ reasons.length ? "approximated" : "exact",
520
+ element,
521
+ reasons,
522
+ );
523
+ return tableMarkup(element, table, state, baseStyle);
524
+ }
525
+ const group = record(element.elementGroup);
526
+ if (group) {
527
+ const children = array(group.children);
528
+ const content: string[] = [];
529
+ for (let index = 0; index < children.length; index++) {
530
+ const child = record(children[index]);
531
+ if (!child) continue;
532
+ const childMarkup = await compilePageElement(
533
+ child,
534
+ state,
535
+ index,
536
+ { inherited: [] },
537
+ absoluteTransform,
538
+ );
539
+ if (childMarkup) content.push(childMarkup);
540
+ }
541
+ markFidelity(state, "exact", element, []);
542
+ return `<div class="gslide-group" data-source-object-id="${escapeAttr(objectId)}" style="${baseStyle}">${content.join("")}</div>`;
543
+ }
544
+ const shape = record(element.shape);
545
+ if (shape) {
546
+ const localShape = record(resolved.local?.shape) ?? shape;
547
+ const shapeType =
548
+ text(localShape.shapeType) ?? text(shape.shapeType) ?? "RECT";
549
+ if (!SUPPORTED_SHAPES.has(shapeType)) {
550
+ return compileFallback(
551
+ element,
552
+ state,
553
+ bounds,
554
+ `Unsupported shape type ${shapeType}.`,
555
+ baseStyle,
556
+ );
557
+ }
558
+ const reasons = shapeApproximationReasons(
559
+ shapeType,
560
+ localShape,
561
+ resolved.inherited,
562
+ );
563
+ markFidelity(
564
+ state,
565
+ reasons.length ? "approximated" : "exact",
566
+ element,
567
+ reasons,
568
+ );
569
+ return shapeMarkup(
570
+ element,
571
+ localShape,
572
+ state,
573
+ baseStyle,
574
+ resolved.inherited,
575
+ );
576
+ }
577
+ const line = record(element.line);
578
+ if (line) {
579
+ const lineType = text(line.lineType) ?? "STRAIGHT_CONNECTOR_1";
580
+ const properties = record(line.lineProperties);
581
+ if (
582
+ !lineType.startsWith("STRAIGHT") ||
583
+ (text(properties?.startArrow) ?? "NONE") !== "NONE" ||
584
+ (text(properties?.endArrow) ?? "NONE") !== "NONE"
585
+ ) {
586
+ return compileFallback(
587
+ element,
588
+ state,
589
+ bounds,
590
+ "Curved, bent, and arrowed lines require raster fidelity.",
591
+ baseStyle,
592
+ );
593
+ }
594
+ const dashStyle = text(properties?.dashStyle) ?? "SOLID";
595
+ markFidelity(
596
+ state,
597
+ dashStyle === "SOLID" ? "exact" : "approximated",
598
+ element,
599
+ dashStyle === "SOLID"
600
+ ? []
601
+ : ["Google line dash spacing is approximated by CSS."],
602
+ );
603
+ return lineMarkup(element, line, state, baseStyle);
604
+ }
605
+ return compileFallback(
606
+ element,
607
+ state,
608
+ bounds,
609
+ "Unsupported Google Slides page element.",
610
+ baseStyle,
611
+ );
612
+ }
613
+
614
+ async function compileFallback(
615
+ element: JsonObject,
616
+ state: CompileState,
617
+ bounds: SlidesNativeBounds,
618
+ reason: string,
619
+ baseStyle: string,
620
+ ): Promise<string> {
621
+ const objectId = text(element.objectId) ?? "unsupported-element";
622
+ const fallback = state.resolveFallback
623
+ ? await state.resolveFallback({
624
+ presentationId: state.presentationId,
625
+ slideObjectId: state.slideObjectId,
626
+ elementObjectId: objectId,
627
+ revisionId: state.revisionId,
628
+ bounds,
629
+ reason,
630
+ })
631
+ : null;
632
+ if (!fallback) {
633
+ throw new Error(
634
+ `Localized raster fallback for ${objectId} was unavailable: ${reason}`,
635
+ );
636
+ }
637
+ markFidelity(state, "imageFallback", element, [reason]);
638
+ state.media.push(fallback);
639
+ state.assetRefs.push(fallback.url);
640
+ return `<div class="gslide-element gslide-image-fallback" data-source-object-id="${escapeAttr(objectId)}" data-fallback-reason="${escapeAttr(reason)}" style="${baseStyle}"><img alt="${escapeAttr(`Raster fallback for ${objectId}`)}" src="${escapeAttr(fallback.url)}" style="width:100%;height:100%;display:block"/></div>`;
641
+ }
642
+
643
+ function shapeMarkup(
644
+ element: JsonObject,
645
+ shape: JsonObject,
646
+ state: CompileState,
647
+ baseStyle: string,
648
+ inherited: JsonObject[],
649
+ ): string {
650
+ const objectId = text(element.objectId) ?? "shape";
651
+ const properties = resolvedShapeProperties(inherited, shape);
652
+ const shapeType = text(shape.shapeType) ?? "RECT";
653
+ const geometry = shapeGeometryCss(shapeType);
654
+ const fill = fillCss(
655
+ record(properties.shapeBackgroundFill),
656
+ state.themeColors,
657
+ );
658
+ const outline = outlineCss(record(properties.outline), state.themeColors);
659
+ const textContent = compileRichText(record(shape.text), state, inherited);
660
+ const textScaleCompensation = textScaleCompensationCss(element);
661
+ const alignment = text(properties.contentAlignment) ?? "TOP";
662
+ const justifyContent =
663
+ alignment === "MIDDLE"
664
+ ? "center"
665
+ : alignment === "BOTTOM"
666
+ ? "flex-end"
667
+ : "flex-start";
668
+ const overflow = shapeType === "TEXT_BOX" ? "visible" : "hidden";
669
+ return `<div class="gslide-element gslide-shape gslide-shape-${escapeAttr(shapeType.toLowerCase())}" data-source-object-id="${escapeAttr(objectId)}" style="${baseStyle};${fill};${outline};${geometry};overflow:${overflow}"><div class="gslide-text" style="${textScaleCompensation};box-sizing:border-box;overflow:${overflow};display:flex;flex-direction:column;justify-content:${justifyContent};padding:${TEXT_INSET_PX}px">${textContent}</div></div>`;
670
+ }
671
+
672
+ function textScaleCompensationCss(element: JsonObject): string {
673
+ if (shouldAbsorbAxisAlignedScale(element)) {
674
+ return css({ width: "100%", height: "100%" });
675
+ }
676
+ const [a, b, c, d] = elementTransform(element);
677
+ const scaleX = Math.hypot(a, b) || 1;
678
+ const determinant = a * d - b * c;
679
+ const scaleY = Math.abs(determinant / scaleX) || 1;
680
+ return css({
681
+ width: `${round(scaleX * 100)}%`,
682
+ height: `${round(scaleY * 100)}%`,
683
+ transform: `scale(${round(1 / scaleX)},${round(1 / scaleY)})`,
684
+ "transform-origin": "0 0",
685
+ });
686
+ }
687
+
688
+ function compileRichText(
689
+ textObject: JsonObject | null,
690
+ state: CompileState,
691
+ inherited: JsonObject[],
692
+ ): string {
693
+ const elements = array(textObject?.textElements);
694
+ const paragraphs: Array<{
695
+ style: JsonObject;
696
+ runs: string[];
697
+ bullet?: string;
698
+ bulletStyle?: JsonObject;
699
+ }> = [];
700
+ let nestingLevel = 0;
701
+ let current = {
702
+ style: inheritedParagraphStyle(inherited, nestingLevel),
703
+ runs: [] as string[],
704
+ bullet: undefined as string | undefined,
705
+ bulletStyle: undefined as JsonObject | undefined,
706
+ };
707
+ const flush = () => {
708
+ if (current.runs.length || paragraphs.length === 0)
709
+ paragraphs.push(current);
710
+ current = {
711
+ style: inheritedParagraphStyle(inherited, nestingLevel),
712
+ runs: [],
713
+ bullet: undefined,
714
+ bulletStyle: undefined,
715
+ };
716
+ };
717
+ for (const value of elements) {
718
+ const entry = record(value);
719
+ const marker = record(entry?.paragraphMarker);
720
+ if (marker) {
721
+ if (current.runs.length) flush();
722
+ nestingLevel = Math.max(
723
+ 0,
724
+ Math.round(number(record(marker.bullet)?.nestingLevel) ?? 0),
725
+ );
726
+ current.style = deepMerge(
727
+ {},
728
+ inheritedParagraphStyle(inherited, nestingLevel),
729
+ record(marker.style) ?? {},
730
+ );
731
+ const bullet = record(marker.bullet);
732
+ current.bullet = text(bullet?.glyph);
733
+ current.bulletStyle = resolveBulletStyle(
734
+ textObject,
735
+ bullet,
736
+ nestingLevel,
737
+ );
738
+ continue;
739
+ }
740
+ const run = record(entry?.textRun) ?? record(entry?.autoText);
741
+ if (!run) continue;
742
+ const content =
743
+ rawText(run.content) ?? rawText(record(entry?.autoText)?.content) ?? "";
744
+ const segments = content.split("\n");
745
+ for (let index = 0; index < segments.length; index++) {
746
+ const segment = segments[index]!;
747
+ if (segment) {
748
+ state.plainText.push(segment.replaceAll("\u000b", "\n"));
749
+ const style = textRunCss(
750
+ deepMerge(
751
+ {},
752
+ inheritedTextStyle(inherited, nestingLevel),
753
+ record(run.style) ?? {},
754
+ ),
755
+ state.themeColors,
756
+ );
757
+ const span = `<span style="${style}">${escapeTextRun(segment)}</span>`;
758
+ current.runs.push(span);
759
+ }
760
+ if (index < segments.length - 1) flush();
761
+ }
762
+ }
763
+ if (current.runs.length) flush();
764
+ if (!paragraphs.length) return "";
765
+ return paragraphs
766
+ .map(
767
+ (paragraph) =>
768
+ `<p style="margin:0;${paragraphCss(paragraph.style, Boolean(paragraph.bullet))}">${paragraph.bullet ? `<span class="gslide-bullet" style="${bulletLayoutCss(paragraph.style)};${textRunCss(paragraph.bulletStyle ?? {}, state.themeColors)}">${escapeHtml(paragraph.bullet)}&nbsp;</span>` : ""}${paragraph.runs.join("") || "<br>"}</p>`,
769
+ )
770
+ .join("");
771
+ }
772
+
773
+ function resolveBulletStyle(
774
+ textObject: JsonObject | null,
775
+ bullet: JsonObject | null,
776
+ nestingLevel: number,
777
+ ): JsonObject | undefined {
778
+ if (!bullet) return undefined;
779
+ const lists = record(textObject?.lists);
780
+ const list = record(lists?.[text(bullet.listId) ?? ""]);
781
+ const levels = record(list?.nestingLevel);
782
+ const inherited = record(levels?.[String(nestingLevel)]);
783
+ const style = deepMerge(
784
+ {},
785
+ record(inherited?.bulletStyle) ?? {},
786
+ record(bullet.bulletStyle) ?? {},
787
+ );
788
+ return Object.keys(style).length ? style : undefined;
789
+ }
790
+
791
+ function inheritedParagraphStyle(
792
+ inherited: JsonObject[],
793
+ nestingLevel: number,
794
+ ): JsonObject {
795
+ return deepMerge(
796
+ {},
797
+ ...inherited.map(
798
+ (entry) => placeholderTextDefaults(entry, nestingLevel).paragraphStyle,
799
+ ),
800
+ );
801
+ }
802
+
803
+ function inheritedTextStyle(
804
+ inherited: JsonObject[],
805
+ nestingLevel: number,
806
+ ): JsonObject {
807
+ return deepMerge(
808
+ {},
809
+ ...inherited.map(
810
+ (entry) => placeholderTextDefaults(entry, nestingLevel).textStyle,
811
+ ),
812
+ );
813
+ }
814
+
815
+ function placeholderTextDefaults(
816
+ element: JsonObject,
817
+ nestingLevel: number,
818
+ ): { paragraphStyle: JsonObject; textStyle: JsonObject } {
819
+ const textObject = record(record(element.shape)?.text);
820
+ let activeLevel = 0;
821
+ let matchingParagraph: JsonObject = {};
822
+ let matchingText: JsonObject = {};
823
+ for (const value of array(textObject?.textElements)) {
824
+ const entry = record(value);
825
+ const marker = record(entry?.paragraphMarker);
826
+ if (marker) {
827
+ activeLevel = Math.max(
828
+ 0,
829
+ Math.round(number(record(marker.bullet)?.nestingLevel) ?? 0),
830
+ );
831
+ if (activeLevel === nestingLevel) {
832
+ matchingParagraph = deepMerge(
833
+ {},
834
+ matchingParagraph,
835
+ record(marker.style) ?? {},
836
+ );
837
+ }
838
+ continue;
839
+ }
840
+ const run = record(entry?.textRun) ?? record(entry?.autoText);
841
+ if (run && activeLevel === nestingLevel) {
842
+ matchingText = deepMerge({}, matchingText, record(run.style) ?? {});
843
+ if (Object.keys(matchingText).length > 0) break;
844
+ }
845
+ }
846
+ return { paragraphStyle: matchingParagraph, textStyle: matchingText };
847
+ }
848
+
849
+ function imageMarkup(
850
+ element: JsonObject,
851
+ image: JsonObject,
852
+ url: string,
853
+ baseStyle: string,
854
+ theme: Map<string, string>,
855
+ ): string {
856
+ const objectId = text(element.objectId) ?? "image";
857
+ const properties = record(image.imageProperties);
858
+ const crop =
859
+ record(properties?.cropProperties) ?? record(image.cropProperties);
860
+ const left = clamp(number(crop?.leftOffset) ?? 0, 0, 0.99);
861
+ const right = clamp(number(crop?.rightOffset) ?? 0, 0, 0.99);
862
+ const top = clamp(number(crop?.topOffset) ?? 0, 0, 0.99);
863
+ const bottom = clamp(number(crop?.bottomOffset) ?? 0, 0, 0.99);
864
+ const visibleWidth = Math.max(0.01, 1 - left - right);
865
+ const visibleHeight = Math.max(0.01, 1 - top - bottom);
866
+ const imageStyle = css({
867
+ position: "absolute",
868
+ left: `${round((-left / visibleWidth) * 100)}%`,
869
+ top: `${round((-top / visibleHeight) * 100)}%`,
870
+ width: `${round((1 / visibleWidth) * 100)}%`,
871
+ height: `${round((1 / visibleHeight) * 100)}%`,
872
+ "object-fit": "fill",
873
+ ...(number(properties?.transparency) !== undefined
874
+ ? {
875
+ opacity: String(
876
+ round(1 - clamp(number(properties?.transparency) ?? 0, 0, 1)),
877
+ ),
878
+ }
879
+ : {}),
880
+ ...imageFilterCss(properties),
881
+ });
882
+ const outline = outlineCss(record(properties?.outline), theme);
883
+ const alt = [text(element.title), text(element.description)]
884
+ .filter(Boolean)
885
+ .join(" — ");
886
+ return `<div class="gslide-element gslide-image" data-source-object-id="${escapeAttr(objectId)}" style="${baseStyle};overflow:hidden;${outline}"><img src="${escapeAttr(url)}" alt="${escapeAttr(alt)}" style="${imageStyle}"/></div>`;
887
+ }
888
+
889
+ function tableMarkup(
890
+ element: JsonObject,
891
+ table: JsonObject,
892
+ state: CompileState,
893
+ baseStyle: string,
894
+ ): string {
895
+ const objectId = text(element.objectId) ?? "table";
896
+ const rows = array(table.tableRows);
897
+ const columnWidths = array(table.tableColumns).map((value) =>
898
+ dimensionToPx(record(record(value)?.columnWidth)),
899
+ );
900
+ const totalColumnWidth = columnWidths.reduce((sum, width) => sum + width, 0);
901
+ const body = rows
902
+ .map((rowValue) => {
903
+ const row = record(rowValue);
904
+ let columnIndex = 0;
905
+ const rowHeight = dimensionToPx(record(row?.rowHeight));
906
+ return `<tr${rowHeight ? ` style="height:${round(rowHeight * state.canvasScale)}px"` : ""}>${array(
907
+ row?.tableCells,
908
+ )
909
+ .map((cellValue) => {
910
+ const cell = record(cellValue);
911
+ const properties = record(cell?.tableCellProperties);
912
+ const fill = fillCss(
913
+ record(properties?.tableCellBackgroundFill),
914
+ state.themeColors,
915
+ );
916
+ const colSpan = Math.max(
917
+ 1,
918
+ Math.round(number(cell?.columnSpan) ?? 1),
919
+ );
920
+ const rowSpan = Math.max(1, Math.round(number(cell?.rowSpan) ?? 1));
921
+ const width = columnWidths
922
+ .slice(columnIndex, columnIndex + colSpan)
923
+ .reduce((sum, value) => sum + value, 0);
924
+ columnIndex += colSpan;
925
+ const contentAlignment = text(properties?.contentAlignment) ?? "TOP";
926
+ const verticalAlign =
927
+ contentAlignment === "MIDDLE"
928
+ ? "middle"
929
+ : contentAlignment === "BOTTOM"
930
+ ? "bottom"
931
+ : "top";
932
+ return `<td colspan="${colSpan}" rowspan="${rowSpan}" style="${fill};border:1px solid transparent;padding:4px;vertical-align:${verticalAlign}${width && totalColumnWidth ? `;width:${round((width / totalColumnWidth) * 100)}%` : ""}">${compileRichText(record(cell?.text), state, [])}</td>`;
933
+ })
934
+ .join("")}</tr>`;
935
+ })
936
+ .join("");
937
+ return `<div class="gslide-element gslide-table" data-source-object-id="${escapeAttr(objectId)}" style="${baseStyle};overflow:hidden"><table style="width:100%;height:100%;border-collapse:collapse;table-layout:fixed">${body}</table></div>`;
938
+ }
939
+
940
+ function lineMarkup(
941
+ element: JsonObject,
942
+ line: JsonObject,
943
+ state: CompileState,
944
+ baseStyle: string,
945
+ ): string {
946
+ const objectId = text(element.objectId) ?? "line";
947
+ const properties = record(line.lineProperties);
948
+ const weight = Math.max(1, dimensionToPx(record(properties?.weight)));
949
+ const lineFill = record(properties?.lineFill);
950
+ const color =
951
+ lineFill?.propertyState === "NOT_RENDERED"
952
+ ? "transparent"
953
+ : opaqueColor(
954
+ record(record(lineFill?.solidFill)?.color),
955
+ state.themeColors,
956
+ );
957
+ const dash = text(properties?.dashStyle) ?? "SOLID";
958
+ const size = record(element.size);
959
+ const width = dimensionToPx(record(size?.width));
960
+ const height = dimensionToPx(record(size?.height));
961
+ const [a, b, c, d, e, f] = elementTransform(element);
962
+ const deltaX = (a * width + c * height) * state.canvasScale;
963
+ const deltaY = (b * width + d * height) * state.canvasScale;
964
+ const length = Math.hypot(deltaX, deltaY);
965
+ const angle = (Math.atan2(deltaY, deltaX) * 180) / Math.PI;
966
+ const geometry = css({
967
+ width: `${round(length)}px`,
968
+ height: "0",
969
+ transform: `translate(${round(e * state.canvasScale)}px,${round(f * state.canvasScale)}px) rotate(${round(angle)}deg)`,
970
+ "transform-origin": "0 0",
971
+ });
972
+ return `<div class="gslide-element gslide-line" data-source-object-id="${escapeAttr(objectId)}" style="${baseStyle};${geometry};border-top:${round(weight)}px ${dash === "SOLID" ? "solid" : "dashed"} ${color}"></div>`;
973
+ }
974
+
975
+ function pageBackground(
976
+ master: JsonObject | undefined,
977
+ layout: JsonObject | undefined,
978
+ slide: JsonObject,
979
+ theme: Map<string, string>,
980
+ ): { css: string; approximationReason?: string } {
981
+ for (const page of [slide, layout, master]) {
982
+ const properties = record(page?.pageProperties);
983
+ const fill = record(properties?.pageBackgroundFill);
984
+ if (fill?.propertyState === "INHERIT") continue;
985
+ if (fill?.propertyState === "NOT_RENDERED") return { css: "transparent" };
986
+ if (fill && record(fill.solidFill)) {
987
+ return { css: fillValue(fill, theme) };
988
+ }
989
+ if (fill) {
990
+ return {
991
+ css: "transparent",
992
+ approximationReason:
993
+ "Non-solid page backgrounds are omitted from editable HTML.",
994
+ };
995
+ }
996
+ }
997
+ return { css: "#ffffff" };
998
+ }
999
+
1000
+ function elementCss(
1001
+ element: JsonObject,
1002
+ zOrder: number,
1003
+ scale: number,
1004
+ absorbAxisAlignedScale = false,
1005
+ ): string {
1006
+ const size = record(element.size);
1007
+ const transform = elementTransform(element);
1008
+ const [a, b, c, d, e, f] = transform;
1009
+ const widthScale = absorbAxisAlignedScale ? a : 1;
1010
+ const heightScale = absorbAxisAlignedScale ? d : 1;
1011
+ return css({
1012
+ position: "absolute",
1013
+ left: "0",
1014
+ top: "0",
1015
+ width: `${round(dimensionToPx(record(size?.width)) * scale * widthScale)}px`,
1016
+ height: `${round(dimensionToPx(record(size?.height)) * scale * heightScale)}px`,
1017
+ transform: `matrix(${round(absorbAxisAlignedScale ? 1 : a)},${round(b)},${round(c)},${round(absorbAxisAlignedScale ? 1 : d)},${round(e * scale)},${round(f * scale)})`,
1018
+ "transform-origin": "0 0",
1019
+ "z-index": String(zOrder),
1020
+ "box-sizing": "border-box",
1021
+ });
1022
+ }
1023
+
1024
+ function shouldAbsorbAxisAlignedScale(element: JsonObject): boolean {
1025
+ const [a, b, c, d] = elementTransform(element);
1026
+ return a > 0 && d > 0 && Math.abs(b) < 0.000_001 && Math.abs(c) < 0.000_001;
1027
+ }
1028
+
1029
+ function elementBounds(
1030
+ element: JsonObject,
1031
+ pageWidth: number,
1032
+ pageHeight: number,
1033
+ parentTransform: AffineTransform,
1034
+ ): SlidesNativeBounds {
1035
+ const size = record(element.size);
1036
+ const [a, b, c, d, e, f] = multiplyTransforms(
1037
+ parentTransform,
1038
+ elementTransform(element),
1039
+ );
1040
+ const width = dimensionToPx(record(size?.width));
1041
+ const height = dimensionToPx(record(size?.height));
1042
+ const points = [
1043
+ [e, f],
1044
+ [a * width + e, b * width + f],
1045
+ [c * height + e, d * height + f],
1046
+ [a * width + c * height + e, b * width + d * height + f],
1047
+ ];
1048
+ const xs = points.map(([x]) => x!);
1049
+ const ys = points.map(([, y]) => y!);
1050
+ const left = clamp(Math.min(...xs), 0, pageWidth);
1051
+ const top = clamp(Math.min(...ys), 0, pageHeight);
1052
+ const right = clamp(Math.max(...xs), left, pageWidth);
1053
+ const bottom = clamp(Math.max(...ys), top, pageHeight);
1054
+ return {
1055
+ x: round(left),
1056
+ y: round(top),
1057
+ width: round(right - left),
1058
+ height: round(bottom - top),
1059
+ };
1060
+ }
1061
+
1062
+ function elementTransform(element: JsonObject): AffineTransform {
1063
+ const transform = record(element.transform);
1064
+ if (!transform) return IDENTITY_TRANSFORM;
1065
+ return [
1066
+ number(transform.scaleX) ?? 0,
1067
+ number(transform?.shearY) ?? 0,
1068
+ number(transform?.shearX) ?? 0,
1069
+ number(transform.scaleY) ?? 0,
1070
+ dimensionToPx({
1071
+ magnitude: number(transform?.translateX) ?? 0,
1072
+ unit: text(transform?.unit) ?? "EMU",
1073
+ }),
1074
+ dimensionToPx({
1075
+ magnitude: number(transform?.translateY) ?? 0,
1076
+ unit: text(transform?.unit) ?? "EMU",
1077
+ }),
1078
+ ];
1079
+ }
1080
+
1081
+ function multiplyTransforms(
1082
+ parent: AffineTransform,
1083
+ local: AffineTransform,
1084
+ ): AffineTransform {
1085
+ const [pa, pb, pc, pd, pe, pf] = parent;
1086
+ const [la, lb, lc, ld, le, lf] = local;
1087
+ return [
1088
+ pa * la + pc * lb,
1089
+ pb * la + pd * lb,
1090
+ pa * lc + pc * ld,
1091
+ pb * lc + pd * ld,
1092
+ pa * le + pc * lf + pe,
1093
+ pb * le + pd * lf + pf,
1094
+ ];
1095
+ }
1096
+
1097
+ function fillCss(fill: JsonObject | null, theme: Map<string, string>): string {
1098
+ if (!fill || fill.propertyState === "NOT_RENDERED")
1099
+ return "background:transparent";
1100
+ return `background:${fillValue(fill, theme)}`;
1101
+ }
1102
+
1103
+ function fillValue(fill: JsonObject, theme: Map<string, string>): string {
1104
+ const solid = record(fill.solidFill);
1105
+ if (!solid) return "transparent";
1106
+ const color = opaqueColor(solid.color, theme);
1107
+ const alpha = clamp(number(solid.alpha) ?? 1, 0, 1);
1108
+ if (alpha === 1) return color;
1109
+ const channels = color
1110
+ .slice(1)
1111
+ .match(/.{2}/g)
1112
+ ?.map((value) => Number.parseInt(value, 16));
1113
+ return channels?.length === 3
1114
+ ? `rgba(${channels[0]},${channels[1]},${channels[2]},${round(alpha)})`
1115
+ : color;
1116
+ }
1117
+
1118
+ function outlineCss(
1119
+ outline: JsonObject | null,
1120
+ theme: Map<string, string>,
1121
+ ): string {
1122
+ if (!outline || outline.propertyState === "NOT_RENDERED")
1123
+ return "border:none";
1124
+ const weight = dimensionToPx(record(outline.weight));
1125
+ const color = opaqueColor(
1126
+ record(record(outline.outlineFill)?.solidFill)?.color,
1127
+ theme,
1128
+ );
1129
+ const dash = text(outline.dashStyle);
1130
+ return `border:${round(weight || 1)}px ${dash && dash !== "SOLID" ? "dashed" : "solid"} ${color}`;
1131
+ }
1132
+
1133
+ function textRunCss(style: JsonObject, theme: Map<string, string>): string {
1134
+ const size = dimensionToPx(record(style.fontSize));
1135
+ const weightedFont = record(style.weightedFontFamily);
1136
+ const family = safeFont(
1137
+ text(weightedFont?.fontFamily) ?? text(style.fontFamily),
1138
+ );
1139
+ const foreground = opaqueColor(
1140
+ record(style.foregroundColor)?.opaqueColor,
1141
+ theme,
1142
+ );
1143
+ const background = record(record(style.backgroundColor)?.opaqueColor);
1144
+ const decorations = [
1145
+ style.underline === true ? "underline" : "",
1146
+ style.strikethrough === true ? "line-through" : "",
1147
+ ].filter(Boolean);
1148
+ return css({
1149
+ ...(family ? { "font-family": family } : {}),
1150
+ ...(size ? { "font-size": `${round(size)}px` } : {}),
1151
+ ...(style.bold === true ? { "font-weight": "700" } : {}),
1152
+ ...(number(weightedFont?.weight)
1153
+ ? { "font-weight": String(Math.round(number(weightedFont?.weight)!)) }
1154
+ : {}),
1155
+ ...(style.italic === true ? { "font-style": "italic" } : {}),
1156
+ ...(decorations.length ? { "text-decoration": decorations.join(" ") } : {}),
1157
+ ...(style.smallCaps === true ? { "font-variant": "small-caps" } : {}),
1158
+ ...(text(style.baselineOffset) === "SUPERSCRIPT"
1159
+ ? { "vertical-align": "super" }
1160
+ : text(style.baselineOffset) === "SUBSCRIPT"
1161
+ ? { "vertical-align": "sub" }
1162
+ : {}),
1163
+ ...(background
1164
+ ? {
1165
+ "background-color": opaqueColor(background, theme),
1166
+ }
1167
+ : {}),
1168
+ color: foreground,
1169
+ });
1170
+ }
1171
+
1172
+ function paragraphCss(style: JsonObject, hasBullet = false): string {
1173
+ const alignment = text(style.alignment);
1174
+ const lineSpacing = number(style.lineSpacing);
1175
+ const indentStart = dimensionToPx(record(style.indentStart));
1176
+ const indentFirstLine = dimensionToPx(record(style.indentFirstLine));
1177
+ return css({
1178
+ ...(alignment ? { "text-align": paragraphAlignment(alignment) } : {}),
1179
+ ...(lineSpacing ? { "line-height": String(round(lineSpacing / 100)) } : {}),
1180
+ ...(record(style.indentStart)
1181
+ ? {
1182
+ "padding-left": `${round(indentStart)}px`,
1183
+ }
1184
+ : {}),
1185
+ ...(record(style.indentEnd)
1186
+ ? {
1187
+ "padding-right": `${round(dimensionToPx(record(style.indentEnd)))}px`,
1188
+ }
1189
+ : {}),
1190
+ ...(!hasBullet && record(style.indentFirstLine)
1191
+ ? {
1192
+ "text-indent": `${round(indentFirstLine - indentStart)}px`,
1193
+ }
1194
+ : {}),
1195
+ ...(text(style.direction) === "RIGHT_TO_LEFT"
1196
+ ? { direction: "rtl" }
1197
+ : text(style.direction) === "LEFT_TO_RIGHT"
1198
+ ? { direction: "ltr" }
1199
+ : {}),
1200
+ ...(record(style.spaceAbove)
1201
+ ? { "padding-top": `${round(dimensionToPx(record(style.spaceAbove)))}px` }
1202
+ : {}),
1203
+ ...(record(style.spaceBelow)
1204
+ ? {
1205
+ "padding-bottom": `${round(dimensionToPx(record(style.spaceBelow)))}px`,
1206
+ }
1207
+ : {}),
1208
+ });
1209
+ }
1210
+
1211
+ function bulletLayoutCss(style: JsonObject): string {
1212
+ const indentStart = dimensionToPx(record(style.indentStart));
1213
+ const indentFirstLine = dimensionToPx(record(style.indentFirstLine));
1214
+ const hangingWidth = Math.max(
1215
+ 0,
1216
+ TEXT_INSET_PX + indentStart - indentFirstLine,
1217
+ );
1218
+ return css({
1219
+ display: "inline-block",
1220
+ margin: `0 0 0 -${round(hangingWidth)}px`,
1221
+ width: `${round(hangingWidth)}px`,
1222
+ });
1223
+ }
1224
+
1225
+ function paragraphAlignment(value: string): string {
1226
+ switch (value) {
1227
+ case "JUSTIFIED":
1228
+ case "DISTRIBUTED":
1229
+ return "justify";
1230
+ case "CENTER":
1231
+ return "center";
1232
+ case "END":
1233
+ return "end";
1234
+ case "START":
1235
+ default:
1236
+ return "start";
1237
+ }
1238
+ }
1239
+
1240
+ function shapeGeometryCss(shapeType: string): string {
1241
+ switch (shapeType) {
1242
+ case "ELLIPSE":
1243
+ return "border-radius:50%";
1244
+ case "ROUND_RECTANGLE":
1245
+ return "border-radius:12%";
1246
+ case "DIAMOND":
1247
+ return "clip-path:polygon(50% 0,100% 50%,50% 100%,0 50%)";
1248
+ case "TRIANGLE":
1249
+ return "clip-path:polygon(50% 0,100% 100%,0 100%)";
1250
+ case "PARALLELOGRAM":
1251
+ return "clip-path:polygon(20% 0,100% 0,80% 100%,0 100%)";
1252
+ case "HEXAGON":
1253
+ return "clip-path:polygon(25% 0,75% 0,100% 50%,75% 100%,25% 100%,0 50%)";
1254
+ default:
1255
+ return "";
1256
+ }
1257
+ }
1258
+
1259
+ function resolveThemeColors(
1260
+ ...pages: Array<JsonObject | undefined>
1261
+ ): Map<string, string> {
1262
+ const result = new Map<string, string>();
1263
+ for (const page of pages) {
1264
+ const properties = record(page?.pageProperties);
1265
+ const scheme = record(properties?.colorScheme);
1266
+ for (const value of array(scheme?.colors)) {
1267
+ const entry = record(value);
1268
+ const type = text(entry?.type);
1269
+ const color = record(entry?.color);
1270
+ if (type && color) result.set(type, opaqueColor(color, result));
1271
+ }
1272
+ }
1273
+ return result;
1274
+ }
1275
+
1276
+ function opaqueColor(value: unknown, theme: Map<string, string>): string {
1277
+ const color = record(value);
1278
+ const rgb =
1279
+ record(color?.rgbColor) ??
1280
+ (color &&
1281
+ [color.red, color.green, color.blue].some(
1282
+ (channel) => typeof channel === "number",
1283
+ )
1284
+ ? color
1285
+ : null);
1286
+ if (rgb) {
1287
+ const channels = [rgb.red, rgb.green, rgb.blue].map((channel) =>
1288
+ Math.round(clamp(number(channel) ?? 0, 0, 1) * 255),
1289
+ );
1290
+ return `#${channels.map((channel) => channel.toString(16).padStart(2, "0")).join("")}`;
1291
+ }
1292
+ return theme.get(text(color?.themeColor) ?? "") ?? "#000000";
1293
+ }
1294
+
1295
+ function imageFilterCss(properties: JsonObject | null): Record<string, string> {
1296
+ if (!properties) return {};
1297
+ const filters: string[] = [];
1298
+ const brightness = number(properties.brightness);
1299
+ const contrast = number(properties.contrast);
1300
+ if (brightness !== undefined) {
1301
+ filters.push(`brightness(${round(Math.max(0, 1 + brightness))})`);
1302
+ }
1303
+ if (contrast !== undefined) {
1304
+ filters.push(`contrast(${round(Math.max(0, 1 + contrast))})`);
1305
+ }
1306
+ return filters.length ? { filter: filters.join(" ") } : {};
1307
+ }
1308
+
1309
+ function imageApproximationReasons(image: JsonObject): string[] {
1310
+ const properties = record(image.imageProperties);
1311
+ const reasons: string[] = [];
1312
+ if (record(properties?.recolor)) {
1313
+ reasons.push("Image recolor is not representable by the safe CSS subset.");
1314
+ }
1315
+ if (record(properties?.shadow)) {
1316
+ reasons.push("Image shadow is omitted from editable HTML.");
1317
+ }
1318
+ if (
1319
+ record(properties?.outline) &&
1320
+ (text(record(properties?.outline)?.dashStyle) ?? "SOLID") !== "SOLID"
1321
+ ) {
1322
+ reasons.push("Image outline dash spacing is approximated by CSS.");
1323
+ }
1324
+ if (
1325
+ number(properties?.brightness) !== undefined ||
1326
+ number(properties?.contrast) !== undefined
1327
+ ) {
1328
+ reasons.push(
1329
+ "Image brightness and contrast use CSS filter approximations.",
1330
+ );
1331
+ }
1332
+ return reasons;
1333
+ }
1334
+
1335
+ function tableApproximationReasons(table: JsonObject): string[] {
1336
+ const reasons: string[] = [];
1337
+ if (
1338
+ array(table.horizontalBorderRows).length > 0 ||
1339
+ array(table.verticalBorderRows).length > 0
1340
+ ) {
1341
+ reasons.push(
1342
+ "Table border grids are preserved as editable cells with simplified borders.",
1343
+ );
1344
+ }
1345
+ return reasons;
1346
+ }
1347
+
1348
+ function shapeApproximationReasons(
1349
+ shapeType: string,
1350
+ shape: JsonObject,
1351
+ inherited: JsonObject[],
1352
+ ): string[] {
1353
+ const reasons: string[] = [];
1354
+ if (APPROXIMATED_SHAPES.has(shapeType)) {
1355
+ reasons.push(`${shapeType} uses an editable CSS geometry approximation.`);
1356
+ }
1357
+ const properties = resolvedShapeProperties(inherited, shape);
1358
+ if (record(properties.shadow)) {
1359
+ reasons.push("Shape shadow is omitted from editable HTML.");
1360
+ }
1361
+ if (
1362
+ record(properties.outline) &&
1363
+ (text(record(properties.outline)?.dashStyle) ?? "SOLID") !== "SOLID"
1364
+ ) {
1365
+ reasons.push("Shape outline dash spacing is approximated by CSS.");
1366
+ }
1367
+ const autofit = record(properties.autofit);
1368
+ if (autofit && (text(autofit.autofitType) ?? "NONE") !== "NONE") {
1369
+ reasons.push("Google Slides text autofit is approximated by clipping.");
1370
+ }
1371
+ if (record(properties.link) || containsTextLink(record(shape.text))) {
1372
+ reasons.push(
1373
+ "Interactive links are intentionally omitted from imported code.",
1374
+ );
1375
+ }
1376
+ return reasons;
1377
+ }
1378
+
1379
+ function resolvedShapeProperties(
1380
+ inherited: JsonObject[],
1381
+ shape: JsonObject,
1382
+ ): JsonObject {
1383
+ return deepMerge(
1384
+ {},
1385
+ ...[
1386
+ ...inherited.map(
1387
+ (entry) => record(record(entry.shape)?.shapeProperties) ?? {},
1388
+ ),
1389
+ record(shape.shapeProperties) ?? {},
1390
+ ].map(omitInheritedProperties),
1391
+ );
1392
+ }
1393
+
1394
+ function omitInheritedProperties(value: JsonObject): JsonObject {
1395
+ const output: JsonObject = {};
1396
+ for (const [key, child] of Object.entries(value)) {
1397
+ const childRecord = record(child);
1398
+ if (childRecord?.propertyState === "INHERIT") continue;
1399
+ output[key] = childRecord ? omitInheritedProperties(childRecord) : child;
1400
+ }
1401
+ return output;
1402
+ }
1403
+
1404
+ function containsTextLink(textObject: JsonObject | null): boolean {
1405
+ return array(textObject?.textElements).some((value) => {
1406
+ const entry = record(value);
1407
+ const run = record(entry?.textRun) ?? record(entry?.autoText);
1408
+ return Boolean(record(record(run?.style)?.link));
1409
+ });
1410
+ }
1411
+
1412
+ function markFidelity(
1413
+ state: CompileState,
1414
+ bucket: FidelityBucket,
1415
+ element: JsonObject,
1416
+ reasons: string[],
1417
+ ): void {
1418
+ state.fidelity[bucket].count += 1;
1419
+ if (bucket === "exact") return;
1420
+ state.fidelity[bucket].reasons.push({
1421
+ nodeId: text(element.objectId) ?? "unknown",
1422
+ nodeName:
1423
+ text(element.title) ?? text(element.objectId) ?? "Unnamed element",
1424
+ nodeType: elementType(element),
1425
+ reasons,
1426
+ });
1427
+ }
1428
+
1429
+ function elementType(element: JsonObject): string {
1430
+ return (
1431
+ [
1432
+ "wordArt",
1433
+ "sheetsChart",
1434
+ "video",
1435
+ "image",
1436
+ "table",
1437
+ "elementGroup",
1438
+ "shape",
1439
+ "line",
1440
+ ].find((key) => record(element[key])) ?? "unknown"
1441
+ );
1442
+ }
1443
+
1444
+ function emptyFidelityReport(): NativeCreativeArtifactFidelityReport {
1445
+ return {
1446
+ exact: { count: 0 },
1447
+ approximated: { count: 0, reasons: [] },
1448
+ imageFallback: { count: 0, reasons: [] },
1449
+ };
1450
+ }
1451
+
1452
+ function lexicalIndexText(html: string, plainText: string): string {
1453
+ const tokens = new Set<string>();
1454
+ for (const match of html.matchAll(
1455
+ /#[0-9a-f]{6}\b|font-family:[^;\"]+|class="([^"]+)"/gi,
1456
+ )) {
1457
+ const value = (match[1] ?? match[0]).trim();
1458
+ for (const token of value.split(/\s+/))
1459
+ if (token) tokens.add(token.slice(0, 100));
1460
+ if (tokens.size >= 200) break;
1461
+ }
1462
+ return [plainText.slice(0, 20_000), [...tokens].join(" ")]
1463
+ .filter(Boolean)
1464
+ .join("\n")
1465
+ .slice(0, 24_000);
1466
+ }
1467
+
1468
+ function assetRefsFromHtml(html: string): string[] {
1469
+ return [
1470
+ ...new Set(
1471
+ [...html.matchAll(/\s(?:src|href)="([^"]+)"/gi)]
1472
+ .map((match) => match[1] ?? "")
1473
+ .filter(Boolean)
1474
+ .map((value) => value.replace(/&amp;/g, "&")),
1475
+ ),
1476
+ ].sort();
1477
+ }
1478
+
1479
+ function mergeElement(...elements: Array<JsonObject | undefined>): JsonObject {
1480
+ return deepMerge(
1481
+ {},
1482
+ ...elements.filter((value): value is JsonObject => Boolean(value)),
1483
+ );
1484
+ }
1485
+
1486
+ function pageElementMap(value: unknown): Map<string, JsonObject> {
1487
+ const result = new Map<string, JsonObject>();
1488
+ for (const valueEntry of array(value)) {
1489
+ const entry = record(valueEntry);
1490
+ const id = text(entry?.objectId);
1491
+ if (entry && id) result.set(id, entry);
1492
+ }
1493
+ return result;
1494
+ }
1495
+
1496
+ function placeholderMap(
1497
+ elements: Map<string, JsonObject>,
1498
+ ): Map<string, JsonObject> {
1499
+ const result = new Map<string, JsonObject>();
1500
+ for (const element of elements.values()) {
1501
+ const placeholder = elementPlaceholder(element);
1502
+ const type = text(placeholder?.type);
1503
+ if (type) result.set(`${type}:${number(placeholder?.index) ?? 0}`, element);
1504
+ }
1505
+ return result;
1506
+ }
1507
+
1508
+ function resolvePlaceholder(
1509
+ placeholder: JsonObject | null,
1510
+ elements: Map<string, JsonObject>,
1511
+ placeholders: Map<string, JsonObject>,
1512
+ ): JsonObject | undefined {
1513
+ if (!placeholder) return undefined;
1514
+ const parentObjectId = text(placeholder.parentObjectId);
1515
+ if (parentObjectId && elements.has(parentObjectId))
1516
+ return elements.get(parentObjectId);
1517
+ const type = text(placeholder.type);
1518
+ return type
1519
+ ? placeholders.get(`${type}:${number(placeholder.index) ?? 0}`)
1520
+ : undefined;
1521
+ }
1522
+
1523
+ function elementPlaceholder(
1524
+ element: JsonObject | undefined,
1525
+ ): JsonObject | null {
1526
+ return record(record(element?.shape)?.placeholder);
1527
+ }
1528
+
1529
+ function objectMap(value: unknown): Map<string, JsonObject> {
1530
+ const result = new Map<string, JsonObject>();
1531
+ for (const entryValue of array(value)) {
1532
+ const entry = record(entryValue);
1533
+ const id = text(entry?.objectId);
1534
+ if (entry && id) result.set(id, entry);
1535
+ }
1536
+ return result;
1537
+ }
1538
+
1539
+ function dimensionToPx(value: JsonObject | null): number {
1540
+ if (!value) return 0;
1541
+ const magnitude = number(value.magnitude) ?? 0;
1542
+ switch ((text(value.unit) ?? "EMU").toUpperCase()) {
1543
+ case "PT":
1544
+ return (magnitude * 96) / 72;
1545
+ case "PX":
1546
+ return magnitude;
1547
+ case "EMU":
1548
+ default:
1549
+ return (magnitude * 96) / 914_400;
1550
+ }
1551
+ }
1552
+
1553
+ function deepMerge(target: JsonObject, ...sources: JsonObject[]): JsonObject {
1554
+ for (const source of sources) {
1555
+ for (const [key, value] of Object.entries(source)) {
1556
+ const child = record(value);
1557
+ target[key] = child
1558
+ ? deepMerge({ ...(record(target[key]) ?? {}) }, child)
1559
+ : Array.isArray(value)
1560
+ ? value
1561
+ : value;
1562
+ }
1563
+ }
1564
+ return target;
1565
+ }
1566
+
1567
+ function css(values: Record<string, string>): string {
1568
+ return Object.entries(values)
1569
+ .filter(([, value]) => value !== "")
1570
+ .map(([key, value]) => `${key}:${value}`)
1571
+ .join(";");
1572
+ }
1573
+
1574
+ function safeFont(value: string | undefined): string | undefined {
1575
+ if (!value) return undefined;
1576
+ const safe = value
1577
+ .replace(/[^A-Za-z0-9 _-]/g, "")
1578
+ .trim()
1579
+ .slice(0, 100);
1580
+ return safe ? `'${safe}'` : undefined;
1581
+ }
1582
+
1583
+ function safeSourceUrl(value: string | undefined): string | undefined {
1584
+ if (!value) return undefined;
1585
+ try {
1586
+ const url = new URL(value);
1587
+ return url.protocol === "https:" ? value : undefined;
1588
+ } catch {
1589
+ return undefined;
1590
+ }
1591
+ }
1592
+
1593
+ function escapeHtml(value: string): string {
1594
+ return value
1595
+ .replace(/&/g, "&amp;")
1596
+ .replace(/</g, "&lt;")
1597
+ .replace(/>/g, "&gt;")
1598
+ .replace(/\"/g, "&quot;")
1599
+ .replace(/'/g, "&#39;");
1600
+ }
1601
+
1602
+ function escapeTextRun(value: string): string {
1603
+ return value.split("\u000b").map(escapeHtml).join("<br>");
1604
+ }
1605
+
1606
+ const escapeAttr = escapeHtml;
1607
+
1608
+ function round(value: number): number {
1609
+ return Math.round(value * 1_000) / 1_000;
1610
+ }
1611
+
1612
+ function clamp(value: number, min: number, max: number): number {
1613
+ return Math.min(max, Math.max(min, value));
1614
+ }
1615
+
1616
+ function record(value: unknown): JsonObject | null {
1617
+ return value && typeof value === "object" && !Array.isArray(value)
1618
+ ? (value as JsonObject)
1619
+ : null;
1620
+ }
1621
+
1622
+ function array(value: unknown): unknown[] {
1623
+ return Array.isArray(value) ? value : [];
1624
+ }
1625
+
1626
+ function text(value: unknown): string | undefined {
1627
+ return typeof value === "string" && value.trim() ? value : undefined;
1628
+ }
1629
+
1630
+ function rawText(value: unknown): string | undefined {
1631
+ return typeof value === "string" ? value : undefined;
1632
+ }
1633
+
1634
+ function number(value: unknown): number | undefined {
1635
+ return typeof value === "number" && Number.isFinite(value)
1636
+ ? value
1637
+ : undefined;
1638
+ }
1639
+
1640
+ const SUPPORTED_SHAPES = new Set([
1641
+ "RECT",
1642
+ "TEXT_BOX",
1643
+ "ELLIPSE",
1644
+ "ROUND_RECTANGLE",
1645
+ "DIAMOND",
1646
+ "TRIANGLE",
1647
+ "PARALLELOGRAM",
1648
+ "HEXAGON",
1649
+ ]);
1650
+
1651
+ const APPROXIMATED_SHAPES = new Set([
1652
+ "DIAMOND",
1653
+ "TRIANGLE",
1654
+ "PARALLELOGRAM",
1655
+ "HEXAGON",
1656
+ ]);