daftari 3.13.1 → 3.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (250) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/dist/distill/propose.d.ts.map +1 -1
  3. package/dist/distill/propose.js +10 -3
  4. package/dist/distill/propose.js.map +1 -1
  5. package/dist/extract/index.d.ts +16 -0
  6. package/dist/extract/index.d.ts.map +1 -0
  7. package/dist/extract/index.js +95 -0
  8. package/dist/extract/index.js.map +1 -0
  9. package/dist/extract/normalize.d.ts +7 -0
  10. package/dist/extract/normalize.d.ts.map +1 -0
  11. package/dist/extract/normalize.js +52 -0
  12. package/dist/extract/normalize.js.map +1 -0
  13. package/dist/extract/office.d.ts +63 -0
  14. package/dist/extract/office.d.ts.map +1 -0
  15. package/dist/extract/office.js +763 -0
  16. package/dist/extract/office.js.map +1 -0
  17. package/dist/extract/pdf.d.ts +16 -0
  18. package/dist/extract/pdf.d.ts.map +1 -0
  19. package/dist/extract/pdf.js +196 -0
  20. package/dist/extract/pdf.js.map +1 -0
  21. package/dist/extract/types.d.ts +55 -0
  22. package/dist/extract/types.d.ts.map +1 -0
  23. package/dist/extract/types.js +47 -0
  24. package/dist/extract/types.js.map +1 -0
  25. package/dist/extract/worker.d.ts +2 -0
  26. package/dist/extract/worker.d.ts.map +1 -0
  27. package/dist/extract/worker.js +57 -0
  28. package/dist/extract/worker.js.map +1 -0
  29. package/dist/integrations/engine.d.ts +174 -3
  30. package/dist/integrations/engine.d.ts.map +1 -1
  31. package/dist/integrations/engine.js +184 -16
  32. package/dist/integrations/engine.js.map +1 -1
  33. package/dist/integrations/google.d.ts +2 -1
  34. package/dist/integrations/google.d.ts.map +1 -1
  35. package/dist/integrations/google.js +12 -117
  36. package/dist/integrations/google.js.map +1 -1
  37. package/dist/integrations/http-json.d.ts +27 -0
  38. package/dist/integrations/http-json.d.ts.map +1 -0
  39. package/dist/integrations/http-json.js +148 -0
  40. package/dist/integrations/http-json.js.map +1 -0
  41. package/dist/integrations/microsoft.d.ts +22 -0
  42. package/dist/integrations/microsoft.d.ts.map +1 -0
  43. package/dist/integrations/microsoft.js +1780 -0
  44. package/dist/integrations/microsoft.js.map +1 -0
  45. package/dist/integrations/microsoft.ui.d.ts +18 -0
  46. package/dist/integrations/microsoft.ui.d.ts.map +1 -0
  47. package/dist/integrations/microsoft.ui.js +131 -0
  48. package/dist/integrations/microsoft.ui.js.map +1 -0
  49. package/dist/integrations/oauth.d.ts.map +1 -1
  50. package/dist/integrations/oauth.js +10 -2
  51. package/dist/integrations/oauth.js.map +1 -1
  52. package/dist/integrations/queue.d.ts +1 -1
  53. package/dist/integrations/queue.d.ts.map +1 -1
  54. package/dist/integrations/queue.js +23 -1
  55. package/dist/integrations/queue.js.map +1 -1
  56. package/dist/integrations/routes.d.ts +26 -0
  57. package/dist/integrations/routes.d.ts.map +1 -1
  58. package/dist/integrations/routes.js +502 -8
  59. package/dist/integrations/routes.js.map +1 -1
  60. package/dist/integrations/runtime.d.ts +14 -2
  61. package/dist/integrations/runtime.d.ts.map +1 -1
  62. package/dist/integrations/runtime.js +39 -7
  63. package/dist/integrations/runtime.js.map +1 -1
  64. package/dist/integrations/state.d.ts +1 -1
  65. package/dist/integrations/state.d.ts.map +1 -1
  66. package/dist/integrations/state.js +48 -8
  67. package/dist/integrations/state.js.map +1 -1
  68. package/dist/integrations/types.d.ts +54 -3
  69. package/dist/integrations/types.d.ts.map +1 -1
  70. package/dist/integrations/types.js +21 -1
  71. package/dist/integrations/types.js.map +1 -1
  72. package/dist/search/watcher.d.ts.map +1 -1
  73. package/dist/search/watcher.js +3 -22
  74. package/dist/search/watcher.js.map +1 -1
  75. package/dist/serve/index.d.ts.map +1 -1
  76. package/dist/serve/index.js +7 -0
  77. package/dist/serve/index.js.map +1 -1
  78. package/dist/sleep/index.js +2 -2
  79. package/dist/sleep/report.js +1 -1
  80. package/dist/sleep/report.js.map +1 -1
  81. package/dist/sleep/tension-scan.d.ts.map +1 -1
  82. package/dist/sleep/tension-scan.js +0 -0
  83. package/dist/sleep/tension-scan.js.map +1 -1
  84. package/dist/storage/local.d.ts +1 -0
  85. package/dist/storage/local.d.ts.map +1 -1
  86. package/dist/storage/local.js +8 -1
  87. package/dist/storage/local.js.map +1 -1
  88. package/dist/utils/config.d.ts +8 -1
  89. package/dist/utils/config.d.ts.map +1 -1
  90. package/dist/utils/config.js +143 -19
  91. package/dist/utils/config.js.map +1 -1
  92. package/dist/view/pages.d.ts.map +1 -1
  93. package/dist/view/pages.js +11 -0
  94. package/dist/view/pages.js.map +1 -1
  95. package/dist/view/render.d.ts.map +1 -1
  96. package/dist/view/render.js +37 -2
  97. package/dist/view/render.js.map +1 -1
  98. package/package.json +8 -3
  99. package/src/integrations/microsoft/assets/VENDORING.md +109 -0
  100. package/src/integrations/microsoft/assets/glue.js +244 -0
  101. package/src/integrations/microsoft/assets/picker-serializer.js +99 -0
  102. package/src/integrations/microsoft/assets/vendor/msal-browser/app/IPublicClientApplication.mjs +91 -0
  103. package/src/integrations/microsoft/assets/vendor/msal-browser/app/PublicClientApplication.mjs +355 -0
  104. package/src/integrations/microsoft/assets/vendor/msal-browser/broker/nativeBroker/NativeStatusCodes.mjs +15 -0
  105. package/src/integrations/microsoft/assets/vendor/msal-browser/broker/nativeBroker/PlatformAuthDOMHandler.mjs +153 -0
  106. package/src/integrations/microsoft/assets/vendor/msal-browser/broker/nativeBroker/PlatformAuthExtensionHandler.mjs +271 -0
  107. package/src/integrations/microsoft/assets/vendor/msal-browser/broker/nativeBroker/PlatformAuthProvider.mjs +95 -0
  108. package/src/integrations/microsoft/assets/vendor/msal-browser/cache/AccountManager.mjs +49 -0
  109. package/src/integrations/microsoft/assets/vendor/msal-browser/cache/AsyncMemoryStorage.mjs +144 -0
  110. package/src/integrations/microsoft/assets/vendor/msal-browser/cache/BrowserCacheManager.mjs +1465 -0
  111. package/src/integrations/microsoft/assets/vendor/msal-browser/cache/CacheHelpers.mjs +45 -0
  112. package/src/integrations/microsoft/assets/vendor/msal-browser/cache/CacheKeys.mjs +32 -0
  113. package/src/integrations/microsoft/assets/vendor/msal-browser/cache/CookieStorage.mjs +94 -0
  114. package/src/integrations/microsoft/assets/vendor/msal-browser/cache/DatabaseStorage.mjs +208 -0
  115. package/src/integrations/microsoft/assets/vendor/msal-browser/cache/EncryptedData.mjs +13 -0
  116. package/src/integrations/microsoft/assets/vendor/msal-browser/cache/LocalStorage.mjs +319 -0
  117. package/src/integrations/microsoft/assets/vendor/msal-browser/cache/MemoryStorage.mjs +48 -0
  118. package/src/integrations/microsoft/assets/vendor/msal-browser/cache/SessionStorage.mjs +46 -0
  119. package/src/integrations/microsoft/assets/vendor/msal-browser/cache/TokenCache.mjs +220 -0
  120. package/src/integrations/microsoft/assets/vendor/msal-browser/config/Configuration.mjs +138 -0
  121. package/src/integrations/microsoft/assets/vendor/msal-browser/controllers/NestedAppAuthController.mjs +483 -0
  122. package/src/integrations/microsoft/assets/vendor/msal-browser/controllers/StandardController.mjs +1532 -0
  123. package/src/integrations/microsoft/assets/vendor/msal-browser/crypto/BrowserCrypto.mjs +354 -0
  124. package/src/integrations/microsoft/assets/vendor/msal-browser/crypto/CryptoOps.mjs +146 -0
  125. package/src/integrations/microsoft/assets/vendor/msal-browser/crypto/PkceGenerator.mjs +63 -0
  126. package/src/integrations/microsoft/assets/vendor/msal-browser/crypto/SignedHttpRequest.mjs +50 -0
  127. package/src/integrations/microsoft/assets/vendor/msal-browser/crypto/TokenBindingKeyManager.mjs +156 -0
  128. package/src/integrations/microsoft/assets/vendor/msal-browser/encode/Base64Decode.mjs +43 -0
  129. package/src/integrations/microsoft/assets/vendor/msal-browser/encode/Base64Encode.mjs +47 -0
  130. package/src/integrations/microsoft/assets/vendor/msal-browser/error/BrowserAuthError.mjs +26 -0
  131. package/src/integrations/microsoft/assets/vendor/msal-browser/error/BrowserAuthErrorCodes.mjs +65 -0
  132. package/src/integrations/microsoft/assets/vendor/msal-browser/error/BrowserConfigurationAuthError.mjs +24 -0
  133. package/src/integrations/microsoft/assets/vendor/msal-browser/error/BrowserConfigurationAuthErrorCodes.mjs +11 -0
  134. package/src/integrations/microsoft/assets/vendor/msal-browser/error/NativeAuthError.mjs +79 -0
  135. package/src/integrations/microsoft/assets/vendor/msal-browser/error/NativeAuthErrorCodes.mjs +12 -0
  136. package/src/integrations/microsoft/assets/vendor/msal-browser/error/NestedAppAuthError.mjs +25 -0
  137. package/src/integrations/microsoft/assets/vendor/msal-browser/event/EventHandler.mjs +110 -0
  138. package/src/integrations/microsoft/assets/vendor/msal-browser/event/EventMessage.mjs +60 -0
  139. package/src/integrations/microsoft/assets/vendor/msal-browser/event/EventType.mjs +30 -0
  140. package/src/integrations/microsoft/assets/vendor/msal-browser/index.mjs +48 -0
  141. package/src/integrations/microsoft/assets/vendor/msal-browser/interaction_client/BaseInteractionClient.mjs +150 -0
  142. package/src/integrations/microsoft/assets/vendor/msal-browser/interaction_client/HybridSpaAuthorizationCodeClient.mjs +16 -0
  143. package/src/integrations/microsoft/assets/vendor/msal-browser/interaction_client/PlatformAuthInteractionClient.mjs +734 -0
  144. package/src/integrations/microsoft/assets/vendor/msal-browser/interaction_client/PopupClient.mjs +528 -0
  145. package/src/integrations/microsoft/assets/vendor/msal-browser/interaction_client/RedirectClient.mjs +464 -0
  146. package/src/integrations/microsoft/assets/vendor/msal-browser/interaction_client/SilentAuthCodeClient.mjs +85 -0
  147. package/src/integrations/microsoft/assets/vendor/msal-browser/interaction_client/SilentCacheClient.mjs +58 -0
  148. package/src/integrations/microsoft/assets/vendor/msal-browser/interaction_client/SilentIframeClient.mjs +255 -0
  149. package/src/integrations/microsoft/assets/vendor/msal-browser/interaction_client/SilentRefreshClient.mjs +77 -0
  150. package/src/integrations/microsoft/assets/vendor/msal-browser/interaction_client/StandardInteractionClient.mjs +217 -0
  151. package/src/integrations/microsoft/assets/vendor/msal-browser/interaction_handler/InteractionHandler.mjs +95 -0
  152. package/src/integrations/microsoft/assets/vendor/msal-browser/interaction_handler/SilentHandler.mjs +71 -0
  153. package/src/integrations/microsoft/assets/vendor/msal-browser/naa/BridgeError.mjs +11 -0
  154. package/src/integrations/microsoft/assets/vendor/msal-browser/naa/BridgeProxy.mjs +152 -0
  155. package/src/integrations/microsoft/assets/vendor/msal-browser/naa/BridgeStatusCode.mjs +18 -0
  156. package/src/integrations/microsoft/assets/vendor/msal-browser/naa/mapping/NestedAppAuthAdapter.mjs +239 -0
  157. package/src/integrations/microsoft/assets/vendor/msal-browser/navigation/NavigationClient.mjs +47 -0
  158. package/src/integrations/microsoft/assets/vendor/msal-browser/network/FetchClient.mjs +153 -0
  159. package/src/integrations/microsoft/assets/vendor/msal-browser/operatingcontext/BaseOperatingContext.mjs +112 -0
  160. package/src/integrations/microsoft/assets/vendor/msal-browser/operatingcontext/NestedAppOperatingContext.mjs +79 -0
  161. package/src/integrations/microsoft/assets/vendor/msal-browser/operatingcontext/StandardOperatingContext.mjs +50 -0
  162. package/src/integrations/microsoft/assets/vendor/msal-browser/packageMetadata.mjs +7 -0
  163. package/src/integrations/microsoft/assets/vendor/msal-browser/popup_relay/constants.mjs +20 -0
  164. package/src/integrations/microsoft/assets/vendor/msal-browser/popup_relay/relayClient.mjs +113 -0
  165. package/src/integrations/microsoft/assets/vendor/msal-browser/protocol/Authorize.mjs +326 -0
  166. package/src/integrations/microsoft/assets/vendor/msal-browser/request/RequestHelpers.mjs +143 -0
  167. package/src/integrations/microsoft/assets/vendor/msal-browser/response/ResponseHandler.mjs +45 -0
  168. package/src/integrations/microsoft/assets/vendor/msal-browser/telemetry/BrowserPerformanceClient.mjs +126 -0
  169. package/src/integrations/microsoft/assets/vendor/msal-browser/telemetry/BrowserPerformanceEvents.mjs +133 -0
  170. package/src/integrations/microsoft/assets/vendor/msal-browser/telemetry/BrowserPerformanceMeasurement.mjs +96 -0
  171. package/src/integrations/microsoft/assets/vendor/msal-browser/telemetry/BrowserRootPerformanceEvents.mjs +53 -0
  172. package/src/integrations/microsoft/assets/vendor/msal-browser/utils/BrowserConstants.mjs +220 -0
  173. package/src/integrations/microsoft/assets/vendor/msal-browser/utils/BrowserProtocolUtils.mjs +27 -0
  174. package/src/integrations/microsoft/assets/vendor/msal-browser/utils/BrowserUtils.mjs +364 -0
  175. package/src/integrations/microsoft/assets/vendor/msal-browser/utils/Helpers.mjs +19 -0
  176. package/src/integrations/microsoft/assets/vendor/msal-browser/utils/MsalFrameStatsUtils.mjs +38 -0
  177. package/src/integrations/microsoft/assets/vendor/msal-browser/webBrokerBridge/PendingRequestRegistry.mjs +63 -0
  178. package/src/integrations/microsoft/assets/vendor/msal-browser/webBrokerBridge/WebBrokerBridgeError.mjs +38 -0
  179. package/src/integrations/microsoft/assets/vendor/msal-browser/webBrokerBridge/WebBrokerBridgeErrorMap.mjs +57 -0
  180. package/src/integrations/microsoft/assets/vendor/msal-common/account/AccountInfo.mjs +91 -0
  181. package/src/integrations/microsoft/assets/vendor/msal-common/account/AuthToken.mjs +70 -0
  182. package/src/integrations/microsoft/assets/vendor/msal-common/account/CcsCredential.mjs +12 -0
  183. package/src/integrations/microsoft/assets/vendor/msal-common/account/ClientInfo.mjs +43 -0
  184. package/src/integrations/microsoft/assets/vendor/msal-common/account/TokenClaims.mjs +24 -0
  185. package/src/integrations/microsoft/assets/vendor/msal-common/authority/Authority.mjs +988 -0
  186. package/src/integrations/microsoft/assets/vendor/msal-common/authority/AuthorityFactory.mjs +41 -0
  187. package/src/integrations/microsoft/assets/vendor/msal-common/authority/AuthorityMetadata.mjs +158 -0
  188. package/src/integrations/microsoft/assets/vendor/msal-common/authority/AuthorityOptions.mjs +20 -0
  189. package/src/integrations/microsoft/assets/vendor/msal-common/authority/AuthorityType.mjs +16 -0
  190. package/src/integrations/microsoft/assets/vendor/msal-common/authority/CloudInstanceDiscoveryErrorResponse.mjs +12 -0
  191. package/src/integrations/microsoft/assets/vendor/msal-common/authority/CloudInstanceDiscoveryResponse.mjs +12 -0
  192. package/src/integrations/microsoft/assets/vendor/msal-common/authority/OpenIdConfigResponse.mjs +14 -0
  193. package/src/integrations/microsoft/assets/vendor/msal-common/authority/ProtocolMode.mjs +26 -0
  194. package/src/integrations/microsoft/assets/vendor/msal-common/authority/RegionDiscovery.mjs +116 -0
  195. package/src/integrations/microsoft/assets/vendor/msal-common/cache/CacheManager.mjs +1202 -0
  196. package/src/integrations/microsoft/assets/vendor/msal-common/cache/persistence/TokenCacheContext.mjs +29 -0
  197. package/src/integrations/microsoft/assets/vendor/msal-common/cache/utils/AccountEntityUtils.mjs +222 -0
  198. package/src/integrations/microsoft/assets/vendor/msal-common/cache/utils/CacheHelpers.mjs +294 -0
  199. package/src/integrations/microsoft/assets/vendor/msal-common/client/AuthorizationCodeClient.mjs +289 -0
  200. package/src/integrations/microsoft/assets/vendor/msal-common/client/RefreshTokenClient.mjs +262 -0
  201. package/src/integrations/microsoft/assets/vendor/msal-common/client/SilentFlowClient.mjs +142 -0
  202. package/src/integrations/microsoft/assets/vendor/msal-common/config/ClientConfiguration.mjs +111 -0
  203. package/src/integrations/microsoft/assets/vendor/msal-common/constants/AADServerParamKeys.mjs +74 -0
  204. package/src/integrations/microsoft/assets/vendor/msal-common/crypto/DpopProofGenerator.mjs +152 -0
  205. package/src/integrations/microsoft/assets/vendor/msal-common/crypto/ICrypto.mjs +52 -0
  206. package/src/integrations/microsoft/assets/vendor/msal-common/crypto/ITokenBindingKeyManager.mjs +27 -0
  207. package/src/integrations/microsoft/assets/vendor/msal-common/crypto/JoseHeader.mjs +72 -0
  208. package/src/integrations/microsoft/assets/vendor/msal-common/crypto/PopTokenGenerator.mjs +109 -0
  209. package/src/integrations/microsoft/assets/vendor/msal-common/error/AuthError.mjs +31 -0
  210. package/src/integrations/microsoft/assets/vendor/msal-common/error/AuthErrorCodes.mjs +13 -0
  211. package/src/integrations/microsoft/assets/vendor/msal-common/error/CacheError.mjs +44 -0
  212. package/src/integrations/microsoft/assets/vendor/msal-common/error/CacheErrorCodes.mjs +10 -0
  213. package/src/integrations/microsoft/assets/vendor/msal-common/error/ClientAuthError.mjs +26 -0
  214. package/src/integrations/microsoft/assets/vendor/msal-common/error/ClientAuthErrorCodes.mjs +46 -0
  215. package/src/integrations/microsoft/assets/vendor/msal-common/error/ClientConfigurationError.mjs +23 -0
  216. package/src/integrations/microsoft/assets/vendor/msal-common/error/ClientConfigurationErrorCodes.mjs +38 -0
  217. package/src/integrations/microsoft/assets/vendor/msal-common/error/InteractionRequiredAuthError.mjs +73 -0
  218. package/src/integrations/microsoft/assets/vendor/msal-common/error/InteractionRequiredAuthErrorCodes.mjs +53 -0
  219. package/src/integrations/microsoft/assets/vendor/msal-common/error/JoseHeaderError.mjs +24 -0
  220. package/src/integrations/microsoft/assets/vendor/msal-common/error/JoseHeaderErrorCodes.mjs +12 -0
  221. package/src/integrations/microsoft/assets/vendor/msal-common/error/NetworkError.mjs +34 -0
  222. package/src/integrations/microsoft/assets/vendor/msal-common/error/PlatformBrokerError.mjs +48 -0
  223. package/src/integrations/microsoft/assets/vendor/msal-common/error/ServerError.mjs +22 -0
  224. package/src/integrations/microsoft/assets/vendor/msal-common/index-browser.mjs +79 -0
  225. package/src/integrations/microsoft/assets/vendor/msal-common/logger/Logger.mjs +291 -0
  226. package/src/integrations/microsoft/assets/vendor/msal-common/network/INetworkModule.mjs +20 -0
  227. package/src/integrations/microsoft/assets/vendor/msal-common/network/RequestThumbprint.mjs +27 -0
  228. package/src/integrations/microsoft/assets/vendor/msal-common/network/ThrottlingUtils.mjs +91 -0
  229. package/src/integrations/microsoft/assets/vendor/msal-common/packageMetadata.mjs +7 -0
  230. package/src/integrations/microsoft/assets/vendor/msal-common/protocol/Authorize.mjs +239 -0
  231. package/src/integrations/microsoft/assets/vendor/msal-common/protocol/Token.mjs +148 -0
  232. package/src/integrations/microsoft/assets/vendor/msal-common/request/AuthenticationHeaderParser.mjs +63 -0
  233. package/src/integrations/microsoft/assets/vendor/msal-common/request/BaseAuthRequest.mjs +37 -0
  234. package/src/integrations/microsoft/assets/vendor/msal-common/request/RequestParameterBuilder.mjs +529 -0
  235. package/src/integrations/microsoft/assets/vendor/msal-common/request/ScopeSet.mjs +204 -0
  236. package/src/integrations/microsoft/assets/vendor/msal-common/response/ResponseHandler.mjs +432 -0
  237. package/src/integrations/microsoft/assets/vendor/msal-common/telemetry/performance/PerformanceClient.mjs +557 -0
  238. package/src/integrations/microsoft/assets/vendor/msal-common/telemetry/performance/PerformanceEvent.mjs +68 -0
  239. package/src/integrations/microsoft/assets/vendor/msal-common/telemetry/performance/PerformanceEvents.mjs +73 -0
  240. package/src/integrations/microsoft/assets/vendor/msal-common/telemetry/performance/StubPerformanceClient.mjs +61 -0
  241. package/src/integrations/microsoft/assets/vendor/msal-common/telemetry/server/ServerTelemetryManager.mjs +297 -0
  242. package/src/integrations/microsoft/assets/vendor/msal-common/url/UrlString.mjs +164 -0
  243. package/src/integrations/microsoft/assets/vendor/msal-common/utils/ClientAssertionUtils.mjs +21 -0
  244. package/src/integrations/microsoft/assets/vendor/msal-common/utils/Constants.mjs +304 -0
  245. package/src/integrations/microsoft/assets/vendor/msal-common/utils/FunctionWrappers.mjs +95 -0
  246. package/src/integrations/microsoft/assets/vendor/msal-common/utils/ObjectUtils.mjs +27 -0
  247. package/src/integrations/microsoft/assets/vendor/msal-common/utils/ProtocolUtils.mjs +76 -0
  248. package/src/integrations/microsoft/assets/vendor/msal-common/utils/StringUtils.mjs +82 -0
  249. package/src/integrations/microsoft/assets/vendor/msal-common/utils/TimeUtils.mjs +75 -0
  250. package/src/integrations/microsoft/assets/vendor/msal-common/utils/UrlUtils.mjs +128 -0
@@ -0,0 +1,763 @@
1
+ // src/extract/office.ts
2
+ // OOXML (Office Open XML) zip-container text extraction. U7 implements the
3
+ // .docx (WordprocessingML) driver; U8 extends this file with a .pptx
4
+ // (DrawingML) driver reusing the shared primitives below.
5
+ //
6
+ // Shared primitives (reusable across docx/pptx):
7
+ // - OLE-magic detection for IRM/password-protected containers (-> encrypted)
8
+ // - a declared-size-capped zip opener built on fflate's unzipSync filter
9
+ // (zip-bomb defense: caps are enforced on the DECLARED originalSize
10
+ // BEFORE any bytes are inflated)
11
+ // - a linear, non-DTD, non-entity-expanding XML tokenizer + tree builder
12
+ // - a single-pass XML entity decoder (named + numeric only)
13
+ //
14
+ // Docx-specific driver (WordprocessingML): walks word/document.xml (plus
15
+ // word/footnotes.xml / word/endnotes.xml) preserving the element set from
16
+ // design spec §3.1, and normalizes per §3.2.
17
+ //
18
+ // Security note: the tokenizer below is a hand-rolled linear scan over
19
+ // element boundaries. It never processes DOCTYPE/ENTITY declarations and
20
+ // never re-scans decoded entity output for further entities — there is no
21
+ // external-entity or entity-expansion surface here, unlike a general-purpose
22
+ // DTD-aware XML parser.
23
+ import { unzipSync } from "fflate";
24
+ // tsx's ESM resolve hook (dev/test only — see worker.ts's matching comment)
25
+ // doesn't reliably remap a ".js" specifier to its sibling ".ts" source for a
26
+ // *value* import resolved from inside a worker_threads realm, even though
27
+ // the same remapping works fine on the main thread. `Result`/`ExtractError`
28
+ // etc. above are type-only imports, erased at compile time, so they never
29
+ // hit this at runtime — but `ok`/`err`/`normalize` are real values this
30
+ // module calls, so resolve them via an exact-extension URL (matching this
31
+ // file's own extension) instead of a plain specifier.
32
+ const officeModuleSuffix = import.meta.url.endsWith(".ts") ? ".ts" : ".js";
33
+ const { ok, err } = (await import(new URL(`../frontmatter/types${officeModuleSuffix}`, import.meta.url).href));
34
+ const { normalize } = (await import(new URL(`./normalize${officeModuleSuffix}`, import.meta.url).href));
35
+ // ---------------------------------------------------------------------------
36
+ // Shared: OLE compound-file detection
37
+ // ---------------------------------------------------------------------------
38
+ const OLE_MAGIC = [0xd0, 0xcf, 0x11, 0xe0, 0xa1, 0xb1, 0x1a, 0xe1];
39
+ /**
40
+ * IRM/password-protected Office files are wrapped in an OLE2 compound file
41
+ * container (an `EncryptedPackage` stream), not a plain zip. We only need
42
+ * the magic-number check to classify this as `encrypted` — parsing the OLE
43
+ * structure itself is out of scope (spec §3.3).
44
+ */
45
+ export function isOleCompoundFile(bytes) {
46
+ if (bytes.length < OLE_MAGIC.length)
47
+ return false;
48
+ for (let i = 0; i < OLE_MAGIC.length; i += 1) {
49
+ if (bytes[i] !== OLE_MAGIC[i])
50
+ return false;
51
+ }
52
+ return true;
53
+ }
54
+ /**
55
+ * Opens a zip, decompressing ONLY the entries selected by `wanted`, and only
56
+ * if their DECLARED (pre-inflation) size fits within the per-entry and
57
+ * running total caps. The size check happens inside fflate's `filter`
58
+ * callback, which fires before that entry is inflated — an entry that fails
59
+ * the check is skipped and never decompressed, so a small physical file that
60
+ * declares a huge inflated size is caught without ever allocating for it.
61
+ *
62
+ * `wanted` is either an exact-name allowlist (docx's fixed part names:
63
+ * word/document.xml, word/footnotes.xml, word/endnotes.xml) or a predicate,
64
+ * for callers whose part names aren't known in advance — e.g. pptx's
65
+ * ppt/slides/slideN.xml for an a-priori-unknown N.
66
+ */
67
+ export function readOoxmlParts(bytes, limits, wanted) {
68
+ const isWanted = typeof wanted === "function" ? wanted : (name) => wanted.includes(name);
69
+ let total = 0;
70
+ let tooLarge = false;
71
+ let hasContentTypes = false;
72
+ let parts;
73
+ try {
74
+ parts = unzipSync(bytes, {
75
+ filter(info) {
76
+ if (info.name === "[Content_Types].xml") {
77
+ hasContentTypes = true;
78
+ return false; // presence check only; content is never needed
79
+ }
80
+ if (!isWanted(info.name))
81
+ return false;
82
+ if (info.originalSize > limits.maxInflatedBytesPerEntry) {
83
+ tooLarge = true;
84
+ return false;
85
+ }
86
+ total += info.originalSize;
87
+ if (total > limits.maxInflatedBytesTotal) {
88
+ tooLarge = true;
89
+ return false;
90
+ }
91
+ return true;
92
+ },
93
+ });
94
+ }
95
+ catch (e) {
96
+ return err({
97
+ reason: "malformed",
98
+ message: e instanceof Error ? e.message : String(e),
99
+ });
100
+ }
101
+ if (tooLarge) {
102
+ return err({ reason: "too_large", message: "declared inflated size exceeds extraction caps" });
103
+ }
104
+ if (!hasContentTypes) {
105
+ return err({ reason: "malformed", message: "missing [Content_Types].xml" });
106
+ }
107
+ return ok({ parts, hasContentTypes });
108
+ }
109
+ // ---------------------------------------------------------------------------
110
+ // Shared: XML entity decoding (single pass — no re-scan of decoded output)
111
+ // ---------------------------------------------------------------------------
112
+ const NAMED_ENTITIES = {
113
+ amp: "&",
114
+ lt: "<",
115
+ gt: ">",
116
+ quot: '"',
117
+ apos: "'",
118
+ };
119
+ const ENTITY_RE = /&(?:([a-zA-Z]+)|#(\d+)|#[xX]([0-9a-fA-F]+));/g;
120
+ /**
121
+ * Decodes only the standard named entities and numeric character references.
122
+ * A single global-regex pass scans the ORIGINAL string once; replacement
123
+ * text is never re-fed into the regex, so a crafted `&amp;lt;`-style payload
124
+ * cannot cascade into `<` — this is a deliberate defense against
125
+ * entity-expansion-style tricks, not just a decoding convenience.
126
+ */
127
+ export function decodeXmlEntities(text) {
128
+ return text.replace(ENTITY_RE, (whole, named, dec, hex) => {
129
+ if (named !== undefined) {
130
+ return Object.hasOwn(NAMED_ENTITIES, named) ? NAMED_ENTITIES[named] : whole;
131
+ }
132
+ const codePoint = dec !== undefined ? Number.parseInt(dec, 10) : Number.parseInt(hex ?? "", 16);
133
+ if (!Number.isFinite(codePoint) || codePoint < 0 || codePoint > 0x10ffff)
134
+ return whole;
135
+ try {
136
+ return String.fromCodePoint(codePoint);
137
+ }
138
+ catch {
139
+ return whole;
140
+ }
141
+ });
142
+ }
143
+ // ---------------------------------------------------------------------------
144
+ // Shared: linear XML tokenizer + minimal tree builder
145
+ // ---------------------------------------------------------------------------
146
+ function localName(rawName) {
147
+ const colon = rawName.indexOf(":");
148
+ return colon === -1 ? rawName : rawName.slice(colon + 1);
149
+ }
150
+ /**
151
+ * A linear scan over element boundaries. Deliberately NOT a DTD/entity-
152
+ * expanding parser: DOCTYPE/comment/CDATA/PI sections are skipped over
153
+ * structurally (so a stray `>` inside them doesn't desync the scan) but
154
+ * their contents are never interpreted — no entity declarations are ever
155
+ * read or expanded.
156
+ */
157
+ function* tokenizeXml(xml) {
158
+ const n = xml.length;
159
+ let i = 0;
160
+ while (i < n) {
161
+ const lt = xml.indexOf("<", i);
162
+ if (lt === -1) {
163
+ if (i < n)
164
+ yield { type: "text", text: xml.slice(i) };
165
+ return;
166
+ }
167
+ if (lt > i)
168
+ yield { type: "text", text: xml.slice(i, lt) };
169
+ if (xml.startsWith("<!--", lt)) {
170
+ const end = xml.indexOf("-->", lt + 4);
171
+ i = end === -1 ? n : end + 3;
172
+ continue;
173
+ }
174
+ if (xml.startsWith("<![CDATA[", lt)) {
175
+ const end = xml.indexOf("]]>", lt + 9);
176
+ const cdataText = xml.slice(lt + 9, end === -1 ? n : end);
177
+ if (cdataText.length > 0)
178
+ yield { type: "text", text: cdataText };
179
+ i = end === -1 ? n : end + 3;
180
+ continue;
181
+ }
182
+ if (xml.startsWith("<?", lt)) {
183
+ const end = xml.indexOf("?>", lt + 2);
184
+ i = end === -1 ? n : end + 2;
185
+ continue;
186
+ }
187
+ if (xml.startsWith("<!", lt)) {
188
+ // DOCTYPE or similar declaration. Skip structurally with bracket
189
+ // depth tracking so we don't desync on an internal subset — we never
190
+ // interpret anything inside it (no ENTITY expansion, ever).
191
+ let depth = 0;
192
+ let j = lt + 1;
193
+ for (; j < n; j += 1) {
194
+ if (xml[j] === "<")
195
+ depth += 1;
196
+ else if (xml[j] === ">") {
197
+ if (depth === 0)
198
+ break;
199
+ depth -= 1;
200
+ }
201
+ }
202
+ i = j + 1;
203
+ continue;
204
+ }
205
+ // Ordinary tag: find the terminating '>' respecting quoted attr values.
206
+ let j = lt + 1;
207
+ let quote = null;
208
+ while (j < n) {
209
+ const c = xml[j];
210
+ if (quote) {
211
+ if (c === quote)
212
+ quote = null;
213
+ }
214
+ else if (c === '"' || c === "'") {
215
+ quote = c;
216
+ }
217
+ else if (c === ">") {
218
+ break;
219
+ }
220
+ j += 1;
221
+ }
222
+ const inner = xml.slice(lt + 1, j);
223
+ i = j + 1;
224
+ if (inner.startsWith("/")) {
225
+ yield { type: "close", name: localName(inner.slice(1).trim()) };
226
+ continue;
227
+ }
228
+ const selfClosing = inner.endsWith("/");
229
+ const body = selfClosing ? inner.slice(0, -1) : inner;
230
+ const nameMatch = /^[^\s]+/.exec(body);
231
+ const rawName = nameMatch ? nameMatch[0] : body;
232
+ const attrsRaw = body.slice(rawName.length);
233
+ yield { type: "open", name: localName(rawName), attrsRaw, selfClosing };
234
+ }
235
+ }
236
+ export function isXmlElement(node) {
237
+ return "name" in node;
238
+ }
239
+ /** Parses XML into a minimal tree. Mismatched/unclosed tags are tolerated
240
+ * (we pop the stack to the nearest matching ancestor) since we only need a
241
+ * best-effort structural walk, not a validating parser. */
242
+ export function parseXml(xml) {
243
+ const root = { name: "#root", attrsRaw: "", children: [] };
244
+ const stack = [root];
245
+ for (const ev of tokenizeXml(xml)) {
246
+ const top = stack[stack.length - 1];
247
+ if (ev.type === "text") {
248
+ const decoded = decodeXmlEntities(ev.text);
249
+ if (decoded.length > 0)
250
+ top.children.push({ text: decoded });
251
+ }
252
+ else if (ev.type === "open") {
253
+ const el = { name: ev.name, attrsRaw: ev.attrsRaw, children: [] };
254
+ top.children.push(el);
255
+ if (!ev.selfClosing)
256
+ stack.push(el);
257
+ }
258
+ else {
259
+ for (let i = stack.length - 1; i > 0; i -= 1) {
260
+ if (stack[i].name === ev.name) {
261
+ stack.length = i;
262
+ break;
263
+ }
264
+ }
265
+ }
266
+ }
267
+ return root;
268
+ }
269
+ /** Reads an attribute by local name (prefix-agnostic: matches `w:id` or `id`). */
270
+ export function getAttr(el, localAttrName) {
271
+ const re = new RegExp(`(?:^|\\s)(?:[\\w.-]+:)?${localAttrName}\\s*=\\s*(?:"([^"]*)"|'([^']*)')`);
272
+ const m = re.exec(el.attrsRaw);
273
+ if (!m)
274
+ return undefined;
275
+ return decodeXmlEntities(m[1] ?? m[2] ?? "");
276
+ }
277
+ /** Collects run-level (inline) text under a w:p (or any element containing
278
+ * runs), applying the tracked-changes and text-box rules from spec §3.1.
279
+ * NOTE: this recurses with document nesting depth and has no explicit depth
280
+ * cap — it relies on V8's *catchable* `RangeError: Maximum call stack size
281
+ * exceeded` for a pathologically deep document, which propagates up through
282
+ * collectBlockLines/extractDocx to worker.ts's top-level `.catch` and is
283
+ * reported as `malformed`. This is not a bounded-recursion guard, just an
284
+ * accepted fallback — a future reader should not assume depth is enforced
285
+ * here. */
286
+ function collectRunText(el, refs) {
287
+ switch (el.name) {
288
+ case "del":
289
+ // Deleted content is dropped wholesale, including any nested runs.
290
+ return "";
291
+ case "t": {
292
+ let out = "";
293
+ for (const child of el.children) {
294
+ if (!isXmlElement(child))
295
+ out += child.text;
296
+ }
297
+ return out;
298
+ }
299
+ case "tab":
300
+ return "\t";
301
+ case "br":
302
+ return "\n";
303
+ case "footnoteReference":
304
+ case "endnoteReference": {
305
+ const id = getAttr(el, "id");
306
+ if (id !== undefined) {
307
+ refs.push({ kind: el.name === "footnoteReference" ? "footnote" : "endnote", id });
308
+ }
309
+ return "";
310
+ }
311
+ case "txbxContent":
312
+ return collectBlockLines(el, refs).join("\n");
313
+ case "tbl":
314
+ return collectTableLines(el, refs).join("\n");
315
+ default: {
316
+ let out = "";
317
+ for (const child of el.children) {
318
+ if (isXmlElement(child))
319
+ out += collectRunText(child, refs);
320
+ }
321
+ return out;
322
+ }
323
+ }
324
+ }
325
+ function collectTableLines(tbl, refs) {
326
+ const rows = [];
327
+ for (const child of tbl.children) {
328
+ if (!isXmlElement(child) || child.name !== "tr")
329
+ continue;
330
+ const cells = [];
331
+ for (const cellNode of child.children) {
332
+ if (!isXmlElement(cellNode) || cellNode.name !== "tc")
333
+ continue;
334
+ // Deliberately collapses a multi-paragraph cell to one line (joined by
335
+ // a single space): the output format is one line per table row, so a
336
+ // cell can't contribute its own line breaks. Same intent applies to
337
+ // buildNotesLines below, and should carry over to U8's pptx text
338
+ // boxes if those get a similar one-line-per-shape treatment.
339
+ const cellLines = collectBlockLines(cellNode, refs);
340
+ cells.push(cellLines.join(" ").replace(/\n+/g, " ").trim());
341
+ }
342
+ rows.push(cells.join(" | "));
343
+ }
344
+ return rows;
345
+ }
346
+ /** Walks a block-level container (document body, table cell, text box) and
347
+ * returns one string per paragraph/table-row, in document order. */
348
+ function collectBlockLines(container, refs) {
349
+ const lines = [];
350
+ for (const child of container.children) {
351
+ if (!isXmlElement(child))
352
+ continue;
353
+ if (child.name === "p") {
354
+ lines.push(collectRunText(child, refs));
355
+ }
356
+ else if (child.name === "tbl") {
357
+ lines.push(...collectTableLines(child, refs));
358
+ }
359
+ else {
360
+ lines.push(...collectBlockLines(child, refs));
361
+ }
362
+ }
363
+ return lines;
364
+ }
365
+ function indexNotesById(root, tagName) {
366
+ const map = new Map();
367
+ const walk = (el) => {
368
+ for (const child of el.children) {
369
+ if (!isXmlElement(child))
370
+ continue;
371
+ if (child.name === tagName) {
372
+ const id = getAttr(child, "id");
373
+ if (id !== undefined) {
374
+ // Same one-line-per-note collapse as collectTableLines' cell join
375
+ // above — a multi-paragraph footnote/endnote becomes one line.
376
+ const localRefs = [];
377
+ const lines = collectBlockLines(child, localRefs);
378
+ map.set(id, lines.join(" ").replace(/\n+/g, " ").trim());
379
+ }
380
+ }
381
+ else {
382
+ walk(child);
383
+ }
384
+ }
385
+ };
386
+ walk(root);
387
+ return map;
388
+ }
389
+ function buildNotesLines(refs, footnotesXml, endnotesXml) {
390
+ const footnoteMap = footnotesXml
391
+ ? indexNotesById(parseXml(footnotesXml), "footnote")
392
+ : new Map();
393
+ const endnoteMap = endnotesXml
394
+ ? indexNotesById(parseXml(endnotesXml), "endnote")
395
+ : new Map();
396
+ const lines = [];
397
+ for (const ref of refs) {
398
+ const map = ref.kind === "footnote" ? footnoteMap : endnoteMap;
399
+ const text = map.get(ref.id);
400
+ if (text && text.length > 0)
401
+ lines.push(text);
402
+ }
403
+ return lines;
404
+ }
405
+ const DOCX_DOCUMENT = "word/document.xml";
406
+ const DOCX_FOOTNOTES = "word/footnotes.xml";
407
+ const DOCX_ENDNOTES = "word/endnotes.xml";
408
+ // Deliberately lenient (non-fatal) decode: invalid byte sequences become
409
+ // U+FFFD replacement characters instead of throwing here. This is
410
+ // intentional, not an oversight — the final assembled text still passes
411
+ // through normalize()'s stricter guard (assertUtf8NoNul/containsNulByte in
412
+ // normalize.ts), which rejects a NUL byte before the result is returned, so
413
+ // the one guard that matters for downstream hashing is still enforced.
414
+ function decodeUtf8Lenient(bytes) {
415
+ return new TextDecoder("utf-8").decode(bytes);
416
+ }
417
+ /** Extracts normalized text from a .docx byte buffer per design spec §3.1/§3.2. */
418
+ export async function extractDocx(bytes, limits) {
419
+ if (isOleCompoundFile(bytes)) {
420
+ return {
421
+ ok: false,
422
+ error: {
423
+ reason: "encrypted",
424
+ message: "OLE compound-file container (IRM/password-protected)",
425
+ },
426
+ };
427
+ }
428
+ const partsResult = readOoxmlParts(bytes, limits, [DOCX_DOCUMENT, DOCX_FOOTNOTES, DOCX_ENDNOTES]);
429
+ if (!partsResult.ok)
430
+ return { ok: false, error: partsResult.error };
431
+ const { parts } = partsResult.value;
432
+ const documentBytes = parts[DOCX_DOCUMENT];
433
+ if (!documentBytes) {
434
+ return { ok: false, error: { reason: "malformed", message: `missing ${DOCX_DOCUMENT}` } };
435
+ }
436
+ const documentXml = decodeUtf8Lenient(documentBytes);
437
+ const footnotesXml = parts[DOCX_FOOTNOTES] ? decodeUtf8Lenient(parts[DOCX_FOOTNOTES]) : undefined;
438
+ const endnotesXml = parts[DOCX_ENDNOTES] ? decodeUtf8Lenient(parts[DOCX_ENDNOTES]) : undefined;
439
+ const refs = [];
440
+ const bodyLines = collectBlockLines(parseXml(documentXml), refs);
441
+ const notesLines = buildNotesLines(refs, footnotesXml, endnotesXml);
442
+ const allLines = [...bodyLines];
443
+ if (notesLines.length > 0) {
444
+ allLines.push("--- notes ---", ...notesLines);
445
+ }
446
+ const rawText = allLines.join("\n");
447
+ if (rawText.trim().length === 0) {
448
+ return { ok: false, error: { reason: "empty" } };
449
+ }
450
+ let text;
451
+ try {
452
+ text = normalize(rawText);
453
+ }
454
+ catch (e) {
455
+ return {
456
+ ok: false,
457
+ error: { reason: "malformed", message: e instanceof Error ? e.message : String(e) },
458
+ };
459
+ }
460
+ if (text.trim().length === 0) {
461
+ return { ok: false, error: { reason: "empty" } };
462
+ }
463
+ return { ok: true, value: { text } };
464
+ }
465
+ /** Worker dispatch entry point (matches the Handler shape in worker.ts). */
466
+ export async function handleDocx(request) {
467
+ return extractDocx(request.bytes, request.limits);
468
+ }
469
+ // ---------------------------------------------------------------------------
470
+ // Pptx driver (DrawingML / PresentationML)
471
+ // ---------------------------------------------------------------------------
472
+ const PPT_PRESENTATION = "ppt/presentation.xml";
473
+ const PPT_PRESENTATION_RELS = "ppt/_rels/presentation.xml.rels";
474
+ const SLIDE_RE = /^ppt\/slides\/slide\d+\.xml$/;
475
+ const SLIDE_RELS_RE = /^ppt\/slides\/_rels\/slide\d+\.xml\.rels$/;
476
+ const NOTES_RE = /^ppt\/notesSlides\/notesSlide\d+\.xml$/;
477
+ const NOTES_REL_TYPE_SUFFIX = "/relationships/notesSlide";
478
+ /** First direct child element matching `name` (local, prefix-stripped). */
479
+ function findChild(el, name) {
480
+ for (const child of el.children) {
481
+ if (isXmlElement(child) && child.name === name)
482
+ return child;
483
+ }
484
+ return undefined;
485
+ }
486
+ /** First descendant element matching `name`, depth-first. Used only for the
487
+ * table lookup inside a p:graphicFrame, which is a handful of levels deep
488
+ * and not worth hand-walking level by level. */
489
+ function findDescendant(el, name) {
490
+ for (const child of el.children) {
491
+ if (!isXmlElement(child))
492
+ continue;
493
+ if (child.name === name)
494
+ return child;
495
+ const found = findDescendant(child, name);
496
+ if (found)
497
+ return found;
498
+ }
499
+ return undefined;
500
+ }
501
+ /** Reads an `r:id`-style attribute — unlike `getAttr` (prefix-agnostic, so it
502
+ * would match a bare `id` attribute first if one is also present on the same
503
+ * element, which p:sldId's `id`+`r:id` pair actually has), this matches only
504
+ * the `r:`-prefixed relationship-id attribute. */
505
+ function getRAttr(el, localAttrName) {
506
+ const re = new RegExp(`(?:^|\\s)r:${localAttrName}\\s*=\\s*(?:"([^"]*)"|'([^']*)')`);
507
+ const m = re.exec(el.attrsRaw);
508
+ if (!m)
509
+ return undefined;
510
+ return decodeXmlEntities(m[1] ?? m[2] ?? "");
511
+ }
512
+ /** Parses a `.rels` part (`<Relationships><Relationship Id=… Type=… Target=…/>…`)
513
+ * into a map keyed by relationship id. */
514
+ function parseRelationships(xml) {
515
+ const map = new Map();
516
+ const relsEl = findChild(parseXml(xml), "Relationships");
517
+ if (!relsEl)
518
+ return map;
519
+ for (const child of relsEl.children) {
520
+ if (!isXmlElement(child) || child.name !== "Relationship")
521
+ continue;
522
+ const id = getAttr(child, "Id");
523
+ if (id === undefined)
524
+ continue;
525
+ map.set(id, {
526
+ id,
527
+ type: getAttr(child, "Type") ?? "",
528
+ target: getAttr(child, "Target") ?? "",
529
+ });
530
+ }
531
+ return map;
532
+ }
533
+ /** Resolves a Relationship `Target` (relative to the referencing part's own
534
+ * directory, per OPC conventions) into a package-absolute part name. */
535
+ function resolveRelTarget(basePartName, target) {
536
+ if (target.startsWith("/"))
537
+ return target.slice(1);
538
+ const baseDir = basePartName.split("/").slice(0, -1);
539
+ for (const seg of target.split("/")) {
540
+ if (seg === "" || seg === ".")
541
+ continue;
542
+ if (seg === "..")
543
+ baseDir.pop();
544
+ else
545
+ baseDir.push(seg);
546
+ }
547
+ return baseDir.join("/");
548
+ }
549
+ /** The `.rels` part name for a given package part, per OPC convention
550
+ * (`dir/_rels/file.ext.rels`). */
551
+ function relsPathFor(partName) {
552
+ const slash = partName.lastIndexOf("/");
553
+ const dir = slash === -1 ? "" : partName.slice(0, slash);
554
+ const file = slash === -1 ? partName : partName.slice(slash + 1);
555
+ return `${dir}/_rels/${file}.rels`;
556
+ }
557
+ /** Collects run-level text under an a:p (or any element containing runs):
558
+ * a:t is a text run, a:br is a line break. No tracked-changes/footnote
559
+ * analog exists in DrawingML, so this is simpler than docx's collectRunText.
560
+ * NOTE: like collectRunText/collectBlockLines above (~line 336), this — and
561
+ * collectParagraphsPptx, collectShapeTreeLines, and findDescendant below —
562
+ * recurses with document nesting depth and has no explicit depth cap. Same
563
+ * accepted fallback applies: a pathologically deep/nested slide relies on
564
+ * V8's catchable `RangeError: Maximum call stack size exceeded` propagating
565
+ * up to worker.ts's top-level `.catch`, reported as `malformed`. Not a
566
+ * bounded-recursion guard — a future reader should not assume depth is
567
+ * enforced here either. */
568
+ function collectRunTextPptx(el) {
569
+ switch (el.name) {
570
+ case "t": {
571
+ let out = "";
572
+ for (const child of el.children) {
573
+ if (!isXmlElement(child))
574
+ out += child.text;
575
+ }
576
+ return out;
577
+ }
578
+ case "br":
579
+ return "\n";
580
+ default: {
581
+ let out = "";
582
+ for (const child of el.children) {
583
+ if (isXmlElement(child))
584
+ out += collectRunTextPptx(child);
585
+ }
586
+ return out;
587
+ }
588
+ }
589
+ }
590
+ /** Walks a container (p:txBody, p:tc) for a:p paragraphs, one line each. */
591
+ function collectParagraphsPptx(container) {
592
+ const lines = [];
593
+ for (const child of container.children) {
594
+ if (!isXmlElement(child))
595
+ continue;
596
+ if (child.name === "p") {
597
+ lines.push(collectRunTextPptx(child));
598
+ }
599
+ else {
600
+ lines.push(...collectParagraphsPptx(child));
601
+ }
602
+ }
603
+ return lines;
604
+ }
605
+ /** DrawingML table (a:tbl/a:tr/a:tc): one line per row, cells joined " | ",
606
+ * matching docx's table-row convention (spec §3.2). */
607
+ function collectTableLinesPptx(tbl) {
608
+ const rows = [];
609
+ for (const child of tbl.children) {
610
+ if (!isXmlElement(child) || child.name !== "tr")
611
+ continue;
612
+ const cells = [];
613
+ for (const cellNode of child.children) {
614
+ if (!isXmlElement(cellNode) || cellNode.name !== "tc")
615
+ continue;
616
+ const cellLines = collectParagraphsPptx(cellNode);
617
+ cells.push(cellLines.join(" ").replace(/\n+/g, " ").trim());
618
+ }
619
+ rows.push(cells.join(" | "));
620
+ }
621
+ return rows;
622
+ }
623
+ /** Walks a shape tree (p:spTree, or a p:grpSp's own contents) in document
624
+ * order: p:sp contributes its p:txBody paragraphs, p:graphicFrame contributes
625
+ * its a:tbl (if any) as table rows, p:grpSp recurses. Other shape kinds
626
+ * (p:pic, p:cxnSp, …) contribute no text. */
627
+ function collectShapeTreeLines(container) {
628
+ const lines = [];
629
+ for (const child of container.children) {
630
+ if (!isXmlElement(child))
631
+ continue;
632
+ switch (child.name) {
633
+ case "sp": {
634
+ const txBody = findChild(child, "txBody");
635
+ if (txBody)
636
+ lines.push(...collectParagraphsPptx(txBody));
637
+ break;
638
+ }
639
+ case "grpSp":
640
+ lines.push(...collectShapeTreeLines(child));
641
+ break;
642
+ case "graphicFrame": {
643
+ const tbl = findDescendant(child, "tbl");
644
+ if (tbl)
645
+ lines.push(...collectTableLinesPptx(tbl));
646
+ break;
647
+ }
648
+ default:
649
+ break;
650
+ }
651
+ }
652
+ return lines;
653
+ }
654
+ /** Extracts the text lines from a p:sld or p:notes root's p:cSld/p:spTree. */
655
+ function extractSlideBodyLines(root) {
656
+ const cSld = findChild(root, "cSld");
657
+ const spTree = cSld ? findChild(cSld, "spTree") : undefined;
658
+ return spTree ? collectShapeTreeLines(spTree) : [];
659
+ }
660
+ /** Extracts normalized text from a .pptx byte buffer per design spec §3.1/§3.2.
661
+ * Reuses all the shared primitives above (readOoxmlParts, tokenizeXml/
662
+ * parseXml, decodeXmlEntities, getAttr, the OLE `encrypted` check,
663
+ * normalize()) — no zip/tokenizer logic is duplicated here. */
664
+ export async function extractPptx(bytes, limits, includeSpeakerNotes = true) {
665
+ if (isOleCompoundFile(bytes)) {
666
+ return {
667
+ ok: false,
668
+ error: {
669
+ reason: "encrypted",
670
+ message: "OLE compound-file container (IRM/password-protected)",
671
+ },
672
+ };
673
+ }
674
+ const partsResult = readOoxmlParts(bytes, limits, (name) => name === PPT_PRESENTATION ||
675
+ name === PPT_PRESENTATION_RELS ||
676
+ SLIDE_RE.test(name) ||
677
+ SLIDE_RELS_RE.test(name) ||
678
+ (includeSpeakerNotes && NOTES_RE.test(name)));
679
+ if (!partsResult.ok)
680
+ return { ok: false, error: partsResult.error };
681
+ const { parts } = partsResult.value;
682
+ const presentationBytes = parts[PPT_PRESENTATION];
683
+ if (!presentationBytes) {
684
+ return { ok: false, error: { reason: "malformed", message: `missing ${PPT_PRESENTATION}` } };
685
+ }
686
+ const presentationEl = findChild(parseXml(decodeUtf8Lenient(presentationBytes)), "presentation");
687
+ const sldIdLst = presentationEl ? findChild(presentationEl, "sldIdLst") : undefined;
688
+ const presentationRels = parts[PPT_PRESENTATION_RELS]
689
+ ? parseRelationships(decodeUtf8Lenient(parts[PPT_PRESENTATION_RELS]))
690
+ : new Map();
691
+ // Slide part names in PRESENTATION order (§3.1) — resolved via
692
+ // p:sldIdLst's r:id sequence through presentation.xml.rels, NOT via
693
+ // slideN.xml filename order (they can differ).
694
+ const orderedSlideParts = [];
695
+ if (sldIdLst) {
696
+ for (const child of sldIdLst.children) {
697
+ if (!isXmlElement(child) || child.name !== "sldId")
698
+ continue;
699
+ const rId = getRAttr(child, "id");
700
+ if (rId === undefined)
701
+ continue;
702
+ const rel = presentationRels.get(rId);
703
+ if (!rel)
704
+ continue;
705
+ orderedSlideParts.push(resolveRelTarget(PPT_PRESENTATION, rel.target));
706
+ }
707
+ }
708
+ const sections = [];
709
+ let visibleIndex = 0;
710
+ for (const slidePartName of orderedSlideParts) {
711
+ const slideBytes = parts[slidePartName];
712
+ if (!slideBytes)
713
+ continue;
714
+ const sldEl = findChild(parseXml(decodeUtf8Lenient(slideBytes)), "sld");
715
+ if (!sldEl)
716
+ continue;
717
+ if (getAttr(sldEl, "show") === "0")
718
+ continue; // hidden slide: excluded entirely (§3.1)
719
+ visibleIndex += 1;
720
+ const section = [`## Slide ${visibleIndex}`, ...extractSlideBodyLines(sldEl)];
721
+ if (includeSpeakerNotes) {
722
+ const slideRelsBytes = parts[relsPathFor(slidePartName)];
723
+ const slideRels = slideRelsBytes
724
+ ? parseRelationships(decodeUtf8Lenient(slideRelsBytes))
725
+ : new Map();
726
+ const notesRel = [...slideRels.values()].find((r) => r.type.endsWith(NOTES_REL_TYPE_SUFFIX));
727
+ const notesBytes = notesRel
728
+ ? parts[resolveRelTarget(slidePartName, notesRel.target)]
729
+ : undefined;
730
+ if (notesBytes) {
731
+ const notesEl = findChild(parseXml(decodeUtf8Lenient(notesBytes)), "notes");
732
+ const notesLines = notesEl ? extractSlideBodyLines(notesEl) : [];
733
+ if (notesLines.join("\n").trim().length > 0) {
734
+ section.push("[speaker notes]", ...notesLines);
735
+ }
736
+ }
737
+ }
738
+ sections.push(section.join("\n"));
739
+ }
740
+ const rawText = sections.join("\n");
741
+ if (rawText.trim().length === 0) {
742
+ return { ok: false, error: { reason: "empty" } };
743
+ }
744
+ let text;
745
+ try {
746
+ text = normalize(rawText);
747
+ }
748
+ catch (e) {
749
+ return {
750
+ ok: false,
751
+ error: { reason: "malformed", message: e instanceof Error ? e.message : String(e) },
752
+ };
753
+ }
754
+ if (text.trim().length === 0) {
755
+ return { ok: false, error: { reason: "empty" } };
756
+ }
757
+ return { ok: true, value: { text } };
758
+ }
759
+ /** Worker dispatch entry point (matches the Handler shape in worker.ts). */
760
+ export async function handlePptx(request) {
761
+ return extractPptx(request.bytes, request.limits, request.includeSpeakerNotes ?? true);
762
+ }
763
+ //# sourceMappingURL=office.js.map