@ryanyahya/opendoc 0.4.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.
- package/.agents/skills/opendoc-apply-comments/SKILL.md +30 -0
- package/.agents/skills/opendoc-apply-comments/agents/openai.yaml +4 -0
- package/.agents/skills/opendoc-create/SKILL.md +63 -0
- package/.agents/skills/opendoc-create/agents/openai.yaml +6 -0
- package/.agents/skills/opendoc-create-template/SKILL.md +50 -0
- package/.agents/skills/opendoc-create-template/agents/openai.yaml +4 -0
- package/.agents/skills/opendoc-create-template/references/structured-reports.md +11 -0
- package/.agents/skills/opendoc-create-theme/SKILL.md +40 -0
- package/.agents/skills/opendoc-create-theme/agents/openai.yaml +4 -0
- package/.agents/skills/opendoc-current-document/SKILL.md +32 -0
- package/.agents/skills/opendoc-current-document/agents/openai.yaml +4 -0
- package/.agents/skills/opendoc-current-document/references/context-fields.md +20 -0
- package/.agents/skills/opendoc-review-document/SKILL.md +60 -0
- package/.agents/skills/opendoc-review-document/agents/openai.yaml +4 -0
- package/AGENTS.md +69 -0
- package/CONTRIBUTING.md +38 -0
- package/LICENSE +21 -0
- package/README.md +179 -0
- package/SECURITY.md +9 -0
- package/THIRD_PARTY.md +49 -0
- package/VALIDATION.md +99 -0
- package/bin/opendoc.mjs +6 -0
- package/dist/assets/Markdown-sNZyjJi7.js +29 -0
- package/dist/assets/OpenDocSerif-Regular-D3OXs9A9.ttf +0 -0
- package/dist/assets/OpenDocSerif-Semibold-CjL9oDRo.ttf +0 -0
- package/dist/assets/geist-latin-ext-wght-italic-XgKbg5n7.woff2 +0 -0
- package/dist/assets/geist-latin-ext-wght-normal-DC-KSUi6.woff2 +0 -0
- package/dist/assets/geist-latin-wght-italic-dTnRTFFJ.woff2 +0 -0
- package/dist/assets/geist-latin-wght-normal-BgDaEnEv.woff2 +0 -0
- package/dist/assets/index-DdrZ6ozO.css +1 -0
- package/dist/assets/index-DgNBz7mL.js +39 -0
- package/dist/assets/pdf-B7Emtyld.js +54 -0
- package/dist/assets/pdf.worker.min-Dswkl-cV.mjs +29 -0
- package/dist/assets/wordmark-DsqLlZpb.png +0 -0
- package/dist/index.html +17 -0
- package/docs/APPEARANCE.md +21 -0
- package/docs/ASSETS.md +176 -0
- package/docs/AUTHORING.md +178 -0
- package/docs/HEADLESS.md +120 -0
- package/docs/MEDIA.md +112 -0
- package/docs/PROJECTS.md +55 -0
- package/docs/PROSE.md +15 -0
- package/docs/SELECTION.md +59 -0
- package/docs/TEMPLATES.md +55 -0
- package/docs/THEMES.md +106 -0
- package/node_modules/@formepdf/core/LICENSE +21 -0
- package/node_modules/@formepdf/core/README.md +53 -0
- package/node_modules/@formepdf/core/dist/attachments.d.ts +55 -0
- package/node_modules/@formepdf/core/dist/attachments.js +59 -0
- package/node_modules/@formepdf/core/dist/extract.d.ts +8 -0
- package/node_modules/@formepdf/core/dist/extract.js +56 -0
- package/node_modules/@formepdf/core/dist/index.d.ts +311 -0
- package/node_modules/@formepdf/core/dist/index.js +167 -0
- package/node_modules/@formepdf/core/dist/layout.d.ts +132 -0
- package/node_modules/@formepdf/core/dist/layout.js +240 -0
- package/node_modules/@formepdf/core/dist/shared/browserHelpers.d.ts +19 -0
- package/node_modules/@formepdf/core/dist/shared/browserHelpers.js +128 -0
- package/node_modules/@formepdf/core/package.json +35 -0
- package/node_modules/@formepdf/core/pkg-node/LICENSE +21 -0
- package/node_modules/@formepdf/core/pkg-node/README.md +84 -0
- package/node_modules/@formepdf/core/pkg-node/forme.d.ts +39 -0
- package/node_modules/@formepdf/core/pkg-node/forme.js +394 -0
- package/node_modules/@formepdf/core/pkg-node/forme_bg.wasm +0 -0
- package/node_modules/@formepdf/core/pkg-node/forme_bg.wasm.d.ts +21 -0
- package/node_modules/@formepdf/core/pkg-node/package.json +25 -0
- package/node_modules/@formepdf/react/README.md +70 -0
- package/node_modules/@formepdf/react/dist/charts.d.ts +72 -0
- package/node_modules/@formepdf/react/dist/charts.js +338 -0
- package/node_modules/@formepdf/react/dist/components.d.ts +533 -0
- package/node_modules/@formepdf/react/dist/components.js +608 -0
- package/node_modules/@formepdf/react/dist/expr.d.ts +20 -0
- package/node_modules/@formepdf/react/dist/expr.js +39 -0
- package/node_modules/@formepdf/react/dist/font.d.ts +2 -0
- package/node_modules/@formepdf/react/dist/font.js +1 -0
- package/node_modules/@formepdf/react/dist/index.d.ts +11 -0
- package/node_modules/@formepdf/react/dist/index.js +15 -0
- package/node_modules/@formepdf/react/dist/render.d.ts +12 -0
- package/node_modules/@formepdf/react/dist/render.js +15 -0
- package/node_modules/@formepdf/react/dist/serialize.d.ts +12 -0
- package/node_modules/@formepdf/react/dist/serialize.js +1470 -0
- package/node_modules/@formepdf/react/dist/stylesheet.d.ts +4 -0
- package/node_modules/@formepdf/react/dist/stylesheet.js +5 -0
- package/node_modules/@formepdf/react/dist/template-proxy.d.ts +38 -0
- package/node_modules/@formepdf/react/dist/template-proxy.js +100 -0
- package/node_modules/@formepdf/react/dist/types.d.ts +287 -0
- package/node_modules/@formepdf/react/dist/types.js +1 -0
- package/node_modules/@formepdf/react/package.json +41 -0
- package/node_modules/@formepdf/shared/README.md +7 -0
- package/node_modules/@formepdf/shared/dist/canvas.d.ts +6 -0
- package/node_modules/@formepdf/shared/dist/canvas.js +43 -0
- package/node_modules/@formepdf/shared/dist/charts.d.ts +100 -0
- package/node_modules/@formepdf/shared/dist/charts.js +98 -0
- package/node_modules/@formepdf/shared/dist/encode.d.ts +27 -0
- package/node_modules/@formepdf/shared/dist/encode.js +93 -0
- package/node_modules/@formepdf/shared/dist/font.d.ts +13 -0
- package/node_modules/@formepdf/shared/dist/font.js +52 -0
- package/node_modules/@formepdf/shared/dist/index.d.ts +10 -0
- package/node_modules/@formepdf/shared/dist/index.js +15 -0
- package/node_modules/@formepdf/shared/dist/parser.d.ts +30 -0
- package/node_modules/@formepdf/shared/dist/parser.js +756 -0
- package/node_modules/@formepdf/shared/dist/semantics.d.ts +15 -0
- package/node_modules/@formepdf/shared/dist/semantics.js +44 -0
- package/node_modules/@formepdf/shared/dist/style.d.ts +7 -0
- package/node_modules/@formepdf/shared/dist/style.js +1024 -0
- package/node_modules/@formepdf/shared/dist/types.d.ts +743 -0
- package/node_modules/@formepdf/shared/dist/types.js +2 -0
- package/node_modules/@formepdf/shared/package.json +35 -0
- package/node_modules/@types/node/LICENSE +21 -0
- package/node_modules/@types/node/README.md +15 -0
- package/node_modules/@types/node/assert/strict.d.ts +111 -0
- package/node_modules/@types/node/assert.d.ts +1078 -0
- package/node_modules/@types/node/async_hooks.d.ts +603 -0
- package/node_modules/@types/node/buffer.buffer.d.ts +472 -0
- package/node_modules/@types/node/buffer.d.ts +1934 -0
- package/node_modules/@types/node/child_process.d.ts +1476 -0
- package/node_modules/@types/node/cluster.d.ts +578 -0
- package/node_modules/@types/node/compatibility/disposable.d.ts +14 -0
- package/node_modules/@types/node/compatibility/index.d.ts +9 -0
- package/node_modules/@types/node/compatibility/indexable.d.ts +20 -0
- package/node_modules/@types/node/compatibility/iterators.d.ts +20 -0
- package/node_modules/@types/node/console.d.ts +452 -0
- package/node_modules/@types/node/constants.d.ts +21 -0
- package/node_modules/@types/node/crypto.d.ts +4545 -0
- package/node_modules/@types/node/dgram.d.ts +600 -0
- package/node_modules/@types/node/diagnostics_channel.d.ts +576 -0
- package/node_modules/@types/node/dns/promises.d.ts +503 -0
- package/node_modules/@types/node/dns.d.ts +923 -0
- package/node_modules/@types/node/domain.d.ts +170 -0
- package/node_modules/@types/node/events.d.ts +976 -0
- package/node_modules/@types/node/fs/promises.d.ts +1306 -0
- package/node_modules/@types/node/fs.d.ts +4463 -0
- package/node_modules/@types/node/globals.d.ts +172 -0
- package/node_modules/@types/node/globals.typedarray.d.ts +38 -0
- package/node_modules/@types/node/http.d.ts +2097 -0
- package/node_modules/@types/node/http2.d.ts +2843 -0
- package/node_modules/@types/node/https.d.ts +579 -0
- package/node_modules/@types/node/index.d.ts +98 -0
- package/node_modules/@types/node/inspector.d.ts +253 -0
- package/node_modules/@types/node/inspector.generated.d.ts +4052 -0
- package/node_modules/@types/node/module.d.ts +891 -0
- package/node_modules/@types/node/net.d.ts +1076 -0
- package/node_modules/@types/node/os.d.ts +506 -0
- package/node_modules/@types/node/package.json +145 -0
- package/node_modules/@types/node/path.d.ts +200 -0
- package/node_modules/@types/node/perf_hooks.d.ts +968 -0
- package/node_modules/@types/node/process.d.ts +2084 -0
- package/node_modules/@types/node/punycode.d.ts +117 -0
- package/node_modules/@types/node/querystring.d.ts +152 -0
- package/node_modules/@types/node/readline/promises.d.ts +161 -0
- package/node_modules/@types/node/readline.d.ts +594 -0
- package/node_modules/@types/node/repl.d.ts +428 -0
- package/node_modules/@types/node/sea.d.ts +162 -0
- package/node_modules/@types/node/sqlite.d.ts +722 -0
- package/node_modules/@types/node/stream/consumers.d.ts +38 -0
- package/node_modules/@types/node/stream/promises.d.ts +90 -0
- package/node_modules/@types/node/stream/web.d.ts +573 -0
- package/node_modules/@types/node/stream.d.ts +1694 -0
- package/node_modules/@types/node/string_decoder.d.ts +67 -0
- package/node_modules/@types/node/test.d.ts +2265 -0
- package/node_modules/@types/node/timers/promises.d.ts +108 -0
- package/node_modules/@types/node/timers.d.ts +287 -0
- package/node_modules/@types/node/tls.d.ts +1319 -0
- package/node_modules/@types/node/trace_events.d.ts +197 -0
- package/node_modules/@types/node/ts5.6/buffer.buffer.d.ts +468 -0
- package/node_modules/@types/node/ts5.6/globals.typedarray.d.ts +34 -0
- package/node_modules/@types/node/ts5.6/index.d.ts +98 -0
- package/node_modules/@types/node/tty.d.ts +208 -0
- package/node_modules/@types/node/url.d.ts +984 -0
- package/node_modules/@types/node/util.d.ts +2606 -0
- package/node_modules/@types/node/v8.d.ts +920 -0
- package/node_modules/@types/node/vm.d.ts +1053 -0
- package/node_modules/@types/node/wasi.d.ts +181 -0
- package/node_modules/@types/node/web-globals/abortcontroller.d.ts +34 -0
- package/node_modules/@types/node/web-globals/domexception.d.ts +68 -0
- package/node_modules/@types/node/web-globals/events.d.ts +97 -0
- package/node_modules/@types/node/web-globals/fetch.d.ts +55 -0
- package/node_modules/@types/node/web-globals/navigator.d.ts +22 -0
- package/node_modules/@types/node/web-globals/storage.d.ts +24 -0
- package/node_modules/@types/node/web-globals/streams.d.ts +22 -0
- package/node_modules/@types/node/worker_threads.d.ts +819 -0
- package/node_modules/@types/node/zlib.d.ts +747 -0
- package/node_modules/@types/react/LICENSE +21 -0
- package/node_modules/@types/react/README.md +15 -0
- package/node_modules/@types/react/canary.d.ts +129 -0
- package/node_modules/@types/react/compiler-runtime.d.ts +4 -0
- package/node_modules/@types/react/experimental.d.ts +184 -0
- package/node_modules/@types/react/global.d.ts +166 -0
- package/node_modules/@types/react/index.d.ts +4378 -0
- package/node_modules/@types/react/jsx-dev-runtime.d.ts +33 -0
- package/node_modules/@types/react/jsx-runtime.d.ts +24 -0
- package/node_modules/@types/react/package.json +210 -0
- package/node_modules/@types/react/ts5.0/canary.d.ts +129 -0
- package/node_modules/@types/react/ts5.0/experimental.d.ts +184 -0
- package/node_modules/@types/react/ts5.0/global.d.ts +166 -0
- package/node_modules/@types/react/ts5.0/index.d.ts +4365 -0
- package/node_modules/@types/react/ts5.0/jsx-dev-runtime.d.ts +33 -0
- package/node_modules/@types/react/ts5.0/jsx-runtime.d.ts +24 -0
- package/node_modules/csstype/LICENSE +19 -0
- package/node_modules/csstype/README.md +291 -0
- package/node_modules/csstype/index.d.ts +22569 -0
- package/node_modules/csstype/index.js.flow +6863 -0
- package/node_modules/csstype/package.json +70 -0
- package/node_modules/entities/LICENSE +11 -0
- package/node_modules/entities/decode.d.ts +1 -0
- package/node_modules/entities/decode.js +3 -0
- package/node_modules/entities/dist/commonjs/decode-codepoint.d.ts +19 -0
- package/node_modules/entities/dist/commonjs/decode-codepoint.d.ts.map +1 -0
- package/node_modules/entities/dist/commonjs/decode-codepoint.js +77 -0
- package/node_modules/entities/dist/commonjs/decode-codepoint.js.map +1 -0
- package/node_modules/entities/dist/commonjs/decode.d.ts +209 -0
- package/node_modules/entities/dist/commonjs/decode.d.ts.map +1 -0
- package/node_modules/entities/dist/commonjs/decode.js +511 -0
- package/node_modules/entities/dist/commonjs/decode.js.map +1 -0
- package/node_modules/entities/dist/commonjs/encode.d.ts +22 -0
- package/node_modules/entities/dist/commonjs/encode.d.ts.map +1 -0
- package/node_modules/entities/dist/commonjs/encode.js +73 -0
- package/node_modules/entities/dist/commonjs/encode.js.map +1 -0
- package/node_modules/entities/dist/commonjs/escape.d.ts +43 -0
- package/node_modules/entities/dist/commonjs/escape.d.ts.map +1 -0
- package/node_modules/entities/dist/commonjs/escape.js +121 -0
- package/node_modules/entities/dist/commonjs/escape.js.map +1 -0
- package/node_modules/entities/dist/commonjs/generated/decode-data-html.d.ts +2 -0
- package/node_modules/entities/dist/commonjs/generated/decode-data-html.d.ts.map +1 -0
- package/node_modules/entities/dist/commonjs/generated/decode-data-html.js +10 -0
- package/node_modules/entities/dist/commonjs/generated/decode-data-html.js.map +1 -0
- package/node_modules/entities/dist/commonjs/generated/decode-data-xml.d.ts +2 -0
- package/node_modules/entities/dist/commonjs/generated/decode-data-xml.d.ts.map +1 -0
- package/node_modules/entities/dist/commonjs/generated/decode-data-xml.js +10 -0
- package/node_modules/entities/dist/commonjs/generated/decode-data-xml.js.map +1 -0
- package/node_modules/entities/dist/commonjs/generated/encode-html.d.ts +8 -0
- package/node_modules/entities/dist/commonjs/generated/encode-html.d.ts.map +1 -0
- package/node_modules/entities/dist/commonjs/generated/encode-html.js +13 -0
- package/node_modules/entities/dist/commonjs/generated/encode-html.js.map +1 -0
- package/node_modules/entities/dist/commonjs/index.d.ts +96 -0
- package/node_modules/entities/dist/commonjs/index.d.ts.map +1 -0
- package/node_modules/entities/dist/commonjs/index.js +131 -0
- package/node_modules/entities/dist/commonjs/index.js.map +1 -0
- package/node_modules/entities/dist/commonjs/package.json +3 -0
- package/node_modules/entities/dist/esm/decode-codepoint.d.ts +19 -0
- package/node_modules/entities/dist/esm/decode-codepoint.d.ts.map +1 -0
- package/node_modules/entities/dist/esm/decode-codepoint.js +72 -0
- package/node_modules/entities/dist/esm/decode-codepoint.js.map +1 -0
- package/node_modules/entities/dist/esm/decode.d.ts +209 -0
- package/node_modules/entities/dist/esm/decode.d.ts.map +1 -0
- package/node_modules/entities/dist/esm/decode.js +497 -0
- package/node_modules/entities/dist/esm/decode.js.map +1 -0
- package/node_modules/entities/dist/esm/encode.d.ts +22 -0
- package/node_modules/entities/dist/esm/encode.d.ts.map +1 -0
- package/node_modules/entities/dist/esm/encode.js +69 -0
- package/node_modules/entities/dist/esm/encode.js.map +1 -0
- package/node_modules/entities/dist/esm/escape.d.ts +43 -0
- package/node_modules/entities/dist/esm/escape.d.ts.map +1 -0
- package/node_modules/entities/dist/esm/escape.js +117 -0
- package/node_modules/entities/dist/esm/escape.js.map +1 -0
- package/node_modules/entities/dist/esm/generated/decode-data-html.d.ts +2 -0
- package/node_modules/entities/dist/esm/generated/decode-data-html.d.ts.map +1 -0
- package/node_modules/entities/dist/esm/generated/decode-data-html.js +7 -0
- package/node_modules/entities/dist/esm/generated/decode-data-html.js.map +1 -0
- package/node_modules/entities/dist/esm/generated/decode-data-xml.d.ts +2 -0
- package/node_modules/entities/dist/esm/generated/decode-data-xml.d.ts.map +1 -0
- package/node_modules/entities/dist/esm/generated/decode-data-xml.js +7 -0
- package/node_modules/entities/dist/esm/generated/decode-data-xml.js.map +1 -0
- package/node_modules/entities/dist/esm/generated/encode-html.d.ts +8 -0
- package/node_modules/entities/dist/esm/generated/encode-html.d.ts.map +1 -0
- package/node_modules/entities/dist/esm/generated/encode-html.js +10 -0
- package/node_modules/entities/dist/esm/generated/encode-html.js.map +1 -0
- package/node_modules/entities/dist/esm/index.d.ts +96 -0
- package/node_modules/entities/dist/esm/index.d.ts.map +1 -0
- package/node_modules/entities/dist/esm/index.js +107 -0
- package/node_modules/entities/dist/esm/index.js.map +1 -0
- package/node_modules/entities/dist/esm/package.json +3 -0
- package/node_modules/entities/escape.d.ts +1 -0
- package/node_modules/entities/escape.js +3 -0
- package/node_modules/entities/package.json +118 -0
- package/node_modules/entities/readme.md +122 -0
- package/node_modules/entities/src/decode-codepoint.ts +81 -0
- package/node_modules/entities/src/decode.spec.ts +320 -0
- package/node_modules/entities/src/decode.ts +620 -0
- package/node_modules/entities/src/encode.spec.ts +78 -0
- package/node_modules/entities/src/encode.ts +77 -0
- package/node_modules/entities/src/escape.spec.ts +14 -0
- package/node_modules/entities/src/escape.ts +148 -0
- package/node_modules/entities/src/generated/.eslintrc.json +10 -0
- package/node_modules/entities/src/generated/decode-data-html.ts +8 -0
- package/node_modules/entities/src/generated/decode-data-xml.ts +8 -0
- package/node_modules/entities/src/generated/encode-html.ts +17 -0
- package/node_modules/entities/src/index.spec.ts +125 -0
- package/node_modules/entities/src/index.ts +188 -0
- package/node_modules/parse5/LICENSE +19 -0
- package/node_modules/parse5/README.md +38 -0
- package/node_modules/parse5/dist/cjs/common/doctype.d.ts +4 -0
- package/node_modules/parse5/dist/cjs/common/doctype.js +118 -0
- package/node_modules/parse5/dist/cjs/common/error-codes.d.ts +67 -0
- package/node_modules/parse5/dist/cjs/common/error-codes.js +66 -0
- package/node_modules/parse5/dist/cjs/common/foreign-content.d.ts +9 -0
- package/node_modules/parse5/dist/cjs/common/foreign-content.js +237 -0
- package/node_modules/parse5/dist/cjs/common/html.d.ts +289 -0
- package/node_modules/parse5/dist/cjs/common/html.js +528 -0
- package/node_modules/parse5/dist/cjs/common/token.d.ts +84 -0
- package/node_modules/parse5/dist/cjs/common/token.js +24 -0
- package/node_modules/parse5/dist/cjs/common/unicode.d.ts +42 -0
- package/node_modules/parse5/dist/cjs/common/unicode.js +70 -0
- package/node_modules/parse5/dist/cjs/index.d.ts +71 -0
- package/node_modules/parse5/dist/cjs/index.js +54 -0
- package/node_modules/parse5/dist/cjs/package.json +1 -0
- package/node_modules/parse5/dist/cjs/parser/formatting-element-list.d.ts +36 -0
- package/node_modules/parse5/dist/cjs/parser/formatting-element-list.js +114 -0
- package/node_modules/parse5/dist/cjs/parser/index.d.ts +221 -0
- package/node_modules/parse5/dist/cjs/parser/index.js +3240 -0
- package/node_modules/parse5/dist/cjs/parser/open-element-stack.d.ts +53 -0
- package/node_modules/parse5/dist/cjs/parser/open-element-stack.js +328 -0
- package/node_modules/parse5/dist/cjs/serializer/index.d.ts +60 -0
- package/node_modules/parse5/dist/cjs/serializer/index.js +172 -0
- package/node_modules/parse5/dist/cjs/tokenizer/index.d.ts +247 -0
- package/node_modules/parse5/dist/cjs/tokenizer/index.js +2714 -0
- package/node_modules/parse5/dist/cjs/tokenizer/preprocessor.d.ts +36 -0
- package/node_modules/parse5/dist/cjs/tokenizer/preprocessor.js +200 -0
- package/node_modules/parse5/dist/cjs/tree-adapters/default.d.ts +84 -0
- package/node_modules/parse5/dist/cjs/tree-adapters/default.js +176 -0
- package/node_modules/parse5/dist/cjs/tree-adapters/interface.d.ts +255 -0
- package/node_modules/parse5/dist/cjs/tree-adapters/interface.js +2 -0
- package/node_modules/parse5/dist/common/doctype.d.ts +4 -0
- package/node_modules/parse5/dist/common/doctype.js +114 -0
- package/node_modules/parse5/dist/common/error-codes.d.ts +67 -0
- package/node_modules/parse5/dist/common/error-codes.js +63 -0
- package/node_modules/parse5/dist/common/foreign-content.d.ts +9 -0
- package/node_modules/parse5/dist/common/foreign-content.js +228 -0
- package/node_modules/parse5/dist/common/html.d.ts +289 -0
- package/node_modules/parse5/dist/common/html.js +523 -0
- package/node_modules/parse5/dist/common/token.d.ts +84 -0
- package/node_modules/parse5/dist/common/token.js +20 -0
- package/node_modules/parse5/dist/common/unicode.d.ts +42 -0
- package/node_modules/parse5/dist/common/unicode.js +62 -0
- package/node_modules/parse5/dist/index.d.ts +71 -0
- package/node_modules/parse5/dist/index.js +42 -0
- package/node_modules/parse5/dist/parser/formatting-element-list.d.ts +36 -0
- package/node_modules/parse5/dist/parser/formatting-element-list.js +110 -0
- package/node_modules/parse5/dist/parser/index.d.ts +221 -0
- package/node_modules/parse5/dist/parser/index.js +3245 -0
- package/node_modules/parse5/dist/parser/open-element-stack.d.ts +53 -0
- package/node_modules/parse5/dist/parser/open-element-stack.js +324 -0
- package/node_modules/parse5/dist/serializer/index.d.ts +60 -0
- package/node_modules/parse5/dist/serializer/index.js +168 -0
- package/node_modules/parse5/dist/tokenizer/index.d.ts +247 -0
- package/node_modules/parse5/dist/tokenizer/index.js +2710 -0
- package/node_modules/parse5/dist/tokenizer/preprocessor.d.ts +36 -0
- package/node_modules/parse5/dist/tokenizer/preprocessor.js +196 -0
- package/node_modules/parse5/dist/tree-adapters/default.d.ts +84 -0
- package/node_modules/parse5/dist/tree-adapters/default.js +173 -0
- package/node_modules/parse5/dist/tree-adapters/interface.d.ts +255 -0
- package/node_modules/parse5/dist/tree-adapters/interface.js +1 -0
- package/node_modules/parse5/package.json +50 -0
- package/node_modules/undici-types/LICENSE +21 -0
- package/node_modules/undici-types/README.md +6 -0
- package/node_modules/undici-types/agent.d.ts +31 -0
- package/node_modules/undici-types/api.d.ts +43 -0
- package/node_modules/undici-types/balanced-pool.d.ts +29 -0
- package/node_modules/undici-types/cache.d.ts +36 -0
- package/node_modules/undici-types/client.d.ts +108 -0
- package/node_modules/undici-types/connector.d.ts +34 -0
- package/node_modules/undici-types/content-type.d.ts +21 -0
- package/node_modules/undici-types/cookies.d.ts +28 -0
- package/node_modules/undici-types/diagnostics-channel.d.ts +66 -0
- package/node_modules/undici-types/dispatcher.d.ts +256 -0
- package/node_modules/undici-types/env-http-proxy-agent.d.ts +21 -0
- package/node_modules/undici-types/errors.d.ts +149 -0
- package/node_modules/undici-types/eventsource.d.ts +61 -0
- package/node_modules/undici-types/fetch.d.ts +209 -0
- package/node_modules/undici-types/file.d.ts +39 -0
- package/node_modules/undici-types/filereader.d.ts +54 -0
- package/node_modules/undici-types/formdata.d.ts +108 -0
- package/node_modules/undici-types/global-dispatcher.d.ts +9 -0
- package/node_modules/undici-types/global-origin.d.ts +7 -0
- package/node_modules/undici-types/handlers.d.ts +15 -0
- package/node_modules/undici-types/header.d.ts +4 -0
- package/node_modules/undici-types/index.d.ts +71 -0
- package/node_modules/undici-types/interceptors.d.ts +17 -0
- package/node_modules/undici-types/mock-agent.d.ts +50 -0
- package/node_modules/undici-types/mock-client.d.ts +25 -0
- package/node_modules/undici-types/mock-errors.d.ts +12 -0
- package/node_modules/undici-types/mock-interceptor.d.ts +93 -0
- package/node_modules/undici-types/mock-pool.d.ts +25 -0
- package/node_modules/undici-types/package.json +55 -0
- package/node_modules/undici-types/patch.d.ts +33 -0
- package/node_modules/undici-types/pool-stats.d.ts +19 -0
- package/node_modules/undici-types/pool.d.ts +39 -0
- package/node_modules/undici-types/proxy-agent.d.ts +28 -0
- package/node_modules/undici-types/readable.d.ts +65 -0
- package/node_modules/undici-types/retry-agent.d.ts +8 -0
- package/node_modules/undici-types/retry-handler.d.ts +116 -0
- package/node_modules/undici-types/util.d.ts +18 -0
- package/node_modules/undici-types/webidl.d.ts +228 -0
- package/node_modules/undici-types/websocket.d.ts +150 -0
- package/package.json +80 -0
- package/scripts/rebuild-forme.mjs +61 -0
- package/src/app/AppearanceControl.tsx +44 -0
- package/src/app/AssetThemeDefaults.tsx +87 -0
- package/src/app/AssetsBrowser.tsx +273 -0
- package/src/app/CommentDock.tsx +108 -0
- package/src/app/CreateDocumentDialog.tsx +51 -0
- package/src/app/DocumentActions.tsx +69 -0
- package/src/app/DocumentCard.tsx +50 -0
- package/src/app/DocumentViewControl.tsx +31 -0
- package/src/app/DocumentsBrowser.tsx +70 -0
- package/src/app/ExportHistoryDialog.tsx +86 -0
- package/src/app/ExportMenu.tsx +127 -0
- package/src/app/GuideDialog.tsx +80 -0
- package/src/app/InspectionLayer.tsx +77 -0
- package/src/app/LogoUploadDialog.tsx +92 -0
- package/src/app/Markdown.tsx +34 -0
- package/src/app/MaterialsBrowser.tsx +149 -0
- package/src/app/PageNumberInput.tsx +56 -0
- package/src/app/Pdf.tsx +561 -0
- package/src/app/ProjectDialogs.tsx +100 -0
- package/src/app/Reader.tsx +769 -0
- package/src/app/SearchField.tsx +13 -0
- package/src/app/Sidebar.tsx +86 -0
- package/src/app/SkillIndex.tsx +30 -0
- package/src/app/TemplatesBrowser.tsx +149 -0
- package/src/app/ThemesBrowser.tsx +159 -0
- package/src/app/api.ts +47 -0
- package/src/app/appearance.ts +35 -0
- package/src/app/assets.css +139 -0
- package/src/app/catalogPreview.ts +20 -0
- package/src/app/colors.css +167 -0
- package/src/app/comment-dock.css +53 -0
- package/src/app/commentDrafts.ts +67 -0
- package/src/app/componentCorrection.ts +17 -0
- package/src/app/edit-workbench.css +87 -0
- package/src/app/editSession.ts +238 -0
- package/src/app/editorRecovery.ts +25 -0
- package/src/app/export-history.css +31 -0
- package/src/app/export.css +17 -0
- package/src/app/guideLinks.ts +21 -0
- package/src/app/guides.css +40 -0
- package/src/app/main.tsx +221 -0
- package/src/app/materials.css +53 -0
- package/src/app/pdfLoading.ts +12 -0
- package/src/app/pdfSelection.ts +112 -0
- package/src/app/projects.css +63 -0
- package/src/app/reader-toolbar.css +65 -0
- package/src/app/selection.css +150 -0
- package/src/app/sidebar.css +60 -0
- package/src/app/skills.css +7 -0
- package/src/app/style.css +1061 -0
- package/src/app/templates.css +49 -0
- package/src/app/themes.css +80 -0
- package/src/app/ui/Icon.tsx +92 -0
- package/src/app/ui/README.md +27 -0
- package/src/app/ui/fonts.css +36 -0
- package/src/app/ui/index.tsx +223 -0
- package/src/app/ui/ui.css +388 -0
- package/src/app/useReaderPreview.ts +19 -0
- package/src/app/useTextEditing.ts +155 -0
- package/src/assets/adapter.ts +122 -0
- package/src/assets/files.ts +378 -0
- package/src/assets/import-worker.ts +294 -0
- package/src/assets/imports.ts +124 -0
- package/src/assets/index.ts +60 -0
- package/src/assets/store.ts +798 -0
- package/src/assets/usage.ts +118 -0
- package/src/cli/check.ts +25 -0
- package/src/cli/init.ts +119 -0
- package/src/cli/lock.ts +34 -0
- package/src/cli/main.ts +118 -0
- package/src/cli/process.ts +19 -0
- package/src/cli/start.ts +96 -0
- package/src/cli/update.ts +348 -0
- package/src/cli/workspace.ts +94 -0
- package/src/document/index.tsx +641 -0
- package/src/document/page.tsx +53 -0
- package/src/document/text-targets.tsx +162 -0
- package/src/media/files.ts +124 -0
- package/src/media/render.ts +63 -0
- package/src/rendering/resolve-sources.ts +84 -0
- package/src/runtime/jsx-dev-runtime.ts +2 -0
- package/src/runtime/jsx-runtime.ts +2 -0
- package/src/runtime/paths.ts +12 -0
- package/src/server/assets-cli.ts +162 -0
- package/src/server/assets-http.ts +100 -0
- package/src/server/client.ts +50 -0
- package/src/server/clipboard.ts +22 -0
- package/src/server/comments-cli.ts +64 -0
- package/src/server/comments.ts +130 -0
- package/src/server/create-cli.ts +33 -0
- package/src/server/create.ts +228 -0
- package/src/server/dependencies.ts +91 -0
- package/src/server/documents.ts +143 -0
- package/src/server/edits.ts +249 -0
- package/src/server/export-batch.ts +105 -0
- package/src/server/export-errors.ts +2 -0
- package/src/server/export-file.ts +57 -0
- package/src/server/export-inputs.ts +66 -0
- package/src/server/export-preview.ts +69 -0
- package/src/server/export.ts +32 -0
- package/src/server/exports.ts +283 -0
- package/src/server/files.ts +21 -0
- package/src/server/guides.ts +71 -0
- package/src/server/index.ts +432 -0
- package/src/server/materials.ts +39 -0
- package/src/server/media-cli.ts +73 -0
- package/src/server/media-mutations.ts +168 -0
- package/src/server/pptx.ts +160 -0
- package/src/server/preflight.ts +129 -0
- package/src/server/projects-cli.ts +29 -0
- package/src/server/projects.ts +187 -0
- package/src/server/render-error.ts +9 -0
- package/src/server/render-source.ts +24 -0
- package/src/server/render.ts +48 -0
- package/src/server/review-cli.ts +40 -0
- package/src/server/review.ts +161 -0
- package/src/server/selection.ts +23 -0
- package/src/server/source-overrides.ts +97 -0
- package/src/server/templates-cli.ts +51 -0
- package/src/server/templates.ts +186 -0
- package/src/server/text-layout.ts +41 -0
- package/src/server/text-source.ts +307 -0
- package/src/server/themes-cli.ts +59 -0
- package/src/server/themes.ts +215 -0
- package/src/server/ttf2eot.d.ts +3 -0
- package/src/server/worker.ts +166 -0
- package/src/server/workspace.ts +242 -0
- package/src/shared/anchors.ts +69 -0
- package/src/shared/assets.ts +154 -0
- package/src/shared/export.ts +34 -0
- package/src/shared/media.ts +33 -0
- package/src/shared/projects.ts +19 -0
- package/src/shared/selection.ts +94 -0
- package/src/shared/skill-index.ts +14 -0
- package/src/shared/starters.ts +19 -0
- package/src/shared/templates.ts +18 -0
- package/src/shared/themes.ts +24 -0
- package/src/shared/types.ts +39 -0
- package/src/template/index.ts +27 -0
- package/src/themes/index.ts +3 -0
- package/src/themes/neutral.ts +20 -0
- package/src/themes/types.ts +110 -0
- package/starter/assets/brand/wordmark.png +0 -0
- package/starter/assets/fonts/InterUI-LICENSE.txt +93 -0
- package/starter/assets/fonts/InterUI-Medium.ttf +0 -0
- package/starter/assets/fonts/InterUI-Regular.ttf +0 -0
- package/starter/assets/fonts/InterUI-source.json +19 -0
- package/starter/assets/fonts/OpenDocMono-Regular.ttf +0 -0
- package/starter/assets/fonts/OpenDocSans-Italic.ttf +0 -0
- package/starter/assets/fonts/OpenDocSans-Regular.ttf +0 -0
- package/starter/assets/fonts/OpenDocSans-Semibold.ttf +0 -0
- package/starter/assets/fonts/OpenDocSans-SemiboldItalic.ttf +0 -0
- package/starter/assets/fonts/OpenDocSerif-Italic.ttf +0 -0
- package/starter/assets/fonts/OpenDocSerif-Regular.ttf +0 -0
- package/starter/assets/fonts/OpenDocSerif-Semibold.ttf +0 -0
- package/starter/assets/fonts/OpenDocSerif-SemiboldItalic.ttf +0 -0
- package/starter/assets/fonts/SourceCode-LICENSE.md +93 -0
- package/starter/assets/fonts/SourceSans-LICENSE.md +93 -0
- package/starter/assets/fonts/SourceSerif-LICENSE.md +93 -0
- package/starter/assets/fonts/geist/OFL.txt +93 -0
- package/starter/assets/fonts/geist/asset.json +7 -0
- package/starter/assets/fonts/geist/files/1a9874b3be0fc168692a3d2327bccb4d28835653d3b91537a755296a467a83e3.ttf +0 -0
- package/starter/assets/fonts/geist/files/a8eefb873ba9c9020665f8a98302697ce1f3b79ab2deef6ee508c0ca6a82e876.ttf +0 -0
- package/starter/assets/fonts/geist/files/ccce59465ae5c61930ada5453834f60500fbd95084d85db63e0e65fad0125455.ttf +0 -0
- package/starter/assets/fonts/geist/files/f5e95110d70593672515080bee9148463ada0a7f77b89ed65a3d43cb2b0ff83a.pdf +0 -0
- package/starter/assets/fonts/geist/revisions/9a2bc12fb2f23cb27bc227087e63e1407bb804ee0586480bd6b7966ec69fb474.json +60 -0
- package/starter/assets/fonts/inter/OFL.txt +93 -0
- package/starter/assets/fonts/inter/asset.json +7 -0
- package/starter/assets/fonts/inter/files/1b08e7fc267a5c7e1d614100f604b83e7e8a0be241f0f288faa2b3ac93a683ba.ttf +0 -0
- package/starter/assets/fonts/inter/files/5b6f0c6f26e5c554a64cdcc3a9b5d802b7f9aec6206f1dbcfcdcad7b5860a2a9.ttf +0 -0
- package/starter/assets/fonts/inter/files/957db8560d510a198a7d0333fae7b6b444b00c20801581126273978d778eb3c3.pdf +0 -0
- package/starter/assets/fonts/inter/files/b37284b5701b6b168dfc770aa1a4ac492106422fd3ba76bc7641e37434e8019c.ttf +0 -0
- package/starter/assets/fonts/inter/files/c1811d32ac0f6eed1bbf57529f2ecdfc6c717d48a969dd864942436315a1b198.ttf +0 -0
- package/starter/assets/fonts/inter/files/e7a1aaf7eda9f2fad4131725fa556265ec75ca7b2d756260173a040363e8d4f7.ttf +0 -0
- package/starter/assets/fonts/inter/files/ef8f755d933b9310804cc9152f1f18cb2ac460d6b05054ec913d889c9f11f79e.ttf +0 -0
- package/starter/assets/fonts/inter/revisions/600391517c413963b71e278a57c26c40366c81fa3939a6b9755f446206766d12.json +99 -0
- package/starter/assets/fonts/inter/source.json +57 -0
- package/starter/assets/fonts/lato/OFL.txt +93 -0
- package/starter/assets/fonts/lato/asset.json +7 -0
- package/starter/assets/fonts/lato/files/4a6b566dbb28adb473a8789ce5169306f42f0c8a070ac92bae93636f36348b0d.pdf +0 -0
- package/starter/assets/fonts/lato/files/5adeb6b334d8fb99ef053bc052b952773d544315e0e1d668a12c0ce8bd51375c.ttf +0 -0
- package/starter/assets/fonts/lato/files/62c1b7f0d2e74b45960154c3520efc337b553db0961bfdc950d5618334596cc8.ttf +0 -0
- package/starter/assets/fonts/lato/files/71b8b7decbe75a881ed267be539d402bd1e9420b799658aada4e0d1bd5af803c.ttf +0 -0
- package/starter/assets/fonts/lato/files/8a0aace75d33794eece4b28187bfc1df0bbd2888b5d8a56e01788c8d65d16be1.ttf +0 -0
- package/starter/assets/fonts/lato/files/d636e4683231f931eda222d588e944d082bfd3bdba02f928bee461c0f185b251.ttf +0 -0
- package/starter/assets/fonts/lato/files/e399c44efe1387100531d26c7e4800c5d12251b890d6654a3098c7c679cb1786.ttf +0 -0
- package/starter/assets/fonts/lato/revisions/49ccb93400a9d466fab7d9843b1ecf8916ec6d47a475dd79a597a22eb39616bc.json +99 -0
- package/starter/assets/fonts/lato/source.json +57 -0
- package/starter/assets/fonts/merriweather/OFL.txt +93 -0
- package/starter/assets/fonts/merriweather/asset.json +7 -0
- package/starter/assets/fonts/merriweather/files/1c54f91b910454251c4c2b7bd4e472e1abf265fba7ca3c0ef2eee2f41324099e.ttf +0 -0
- package/starter/assets/fonts/merriweather/files/8bde8da2bb7f0265e27ba0481f70bb48d0f98a976c145f2f239c648ddd6532e0.pdf +0 -0
- package/starter/assets/fonts/merriweather/files/90b7db4460fcd1a5ca49575c2668a793f3cd6447664d312a068d690e1c01e6bc.ttf +0 -0
- package/starter/assets/fonts/merriweather/files/afff81272b7653417bb6f8bef57add055b1f9fda36f27eba5f32b40752bd08da.ttf +0 -0
- package/starter/assets/fonts/merriweather/files/e029d3b71e5bae3877c73f4f2b15af28db16593d49b0aed2a328d37ff7075846.ttf +0 -0
- package/starter/assets/fonts/merriweather/files/e9864a6790bf712a04e20f3662b206a1535186ed3e877fd859dd5fb9682335df.ttf +0 -0
- package/starter/assets/fonts/merriweather/files/fa71baebdd20a7d0de2e5e445a5922530fe9e1d740efbe791f113b682d3cb093.ttf +0 -0
- package/starter/assets/fonts/merriweather/revisions/1888e390b3e4f38a3d7cd2dc1bb805aeb6ce13f986a97656f0265fd436bc91d2.json +99 -0
- package/starter/assets/fonts/merriweather/source.json +57 -0
- package/starter/assets/fonts/open-sans/OFL.txt +92 -0
- package/starter/assets/fonts/open-sans/asset.json +7 -0
- package/starter/assets/fonts/open-sans/files/1bc0594a83762b2c25d38915a34464b7fec6088298ca22d151757bf98d6700ec.ttf +0 -0
- package/starter/assets/fonts/open-sans/files/47ed1cfaa7ffca04a04ab850b2938fd52c09d1b44cfa3e2980878e166b0cbd87.ttf +0 -0
- package/starter/assets/fonts/open-sans/files/574939af301f07df8e21cfff279465c5981dd9d9cf62086f7515897df951c6f5.pdf +0 -0
- package/starter/assets/fonts/open-sans/files/6d3884d0d57c1b67e9c50c54eca7b69c535c114e76bd7a9cfda0258588185553.ttf +0 -0
- package/starter/assets/fonts/open-sans/files/733eb93b167e6d45de09aa768f6c0355647c2c26f5416dbc7407a08ed41e81c6.ttf +0 -0
- package/starter/assets/fonts/open-sans/files/75367e6da7d914eaed87883ba51b2a2b5816b5cdbb39f96ec5c81a5b032bfd5a.ttf +0 -0
- package/starter/assets/fonts/open-sans/files/ff4fdc11204e0edd14e9a0bb6c374b847a9093b0ec2c16702e03afca79ac4ef7.ttf +0 -0
- package/starter/assets/fonts/open-sans/revisions/bbbe3a4915b9bccbc883c0decb4097511c43b6bd09ae22a1516aff128c219bc5.json +99 -0
- package/starter/assets/fonts/open-sans/source.json +57 -0
- package/starter/assets/fonts/roboto/OFL.txt +93 -0
- package/starter/assets/fonts/roboto/asset.json +7 -0
- package/starter/assets/fonts/roboto/files/22d45d989248a624252b8382067ac56550212fa675dcdbaf12f03d297dd87a58.pdf +0 -0
- package/starter/assets/fonts/roboto/files/35757eaa996b3359022f47f164a67ee9eac04971af24c5b8fbd4b89e844ff190.ttf +0 -0
- package/starter/assets/fonts/roboto/files/4d3035883c531846bd1ce2dc89f36d932e72dc114f56062c7e3a9cdd74f3d3ea.ttf +0 -0
- package/starter/assets/fonts/roboto/files/be7639306a4fc4a02ce2ae2ff59eb1335e4db4a7379dd0a384ed7cc053817789.ttf +0 -0
- package/starter/assets/fonts/roboto/files/d2920cbb1b60a3fd11fbf22049286e43a6baf522d37fdf1e7c89562319bcfea5.ttf +0 -0
- package/starter/assets/fonts/roboto/files/dece7c71bbe61710787f0839c722c65e87355dd2eb4a823e6b5488121ff81e4b.ttf +0 -0
- package/starter/assets/fonts/roboto/files/f478ba88b0292e685e487901dfbb1401457d32d6ebee4030cdfd5698235bffa8.ttf +0 -0
- package/starter/assets/fonts/roboto/revisions/bda5e2d84c17313373dd2dbf3e64fe0dd450c7e1b59e6929e69557e122fe976e.json +99 -0
- package/starter/assets/fonts/roboto/source.json +57 -0
- package/starter/assets/logos/opendoc/asset.json +6 -0
- package/starter/assets/logos/opendoc/files/831d5ccd9eb6709cc8439ea257c03d81452e81a28a3d1eedbd6a3b7daff687b6.png +0 -0
- package/starter/assets/logos/opendoc/revisions/834dde8926ddb81de687254195a168bb13bfb77803307f1257de1f2228be63b2.json +33 -0
- package/starter/assets/ui-fonts/geist/OFL.txt +93 -0
- package/starter/assets/ui-fonts/geist/geist-latin-ext-wght-italic.woff2 +0 -0
- package/starter/assets/ui-fonts/geist/geist-latin-ext-wght-normal.woff2 +0 -0
- package/starter/assets/ui-fonts/geist/geist-latin-wght-italic.woff2 +0 -0
- package/starter/assets/ui-fonts/geist/geist-latin-wght-normal.woff2 +0 -0
- package/starter/assets/ui-fonts/geist/source.json +26 -0
- package/starter/documents/welcome/assets.json +7 -0
- package/starter/documents/welcome/index.tsx +160 -0
- package/starter/documents/welcome/media/.gitkeep +0 -0
- package/starter/documents/welcome/media/paper-architecture/image.png +0 -0
- package/starter/documents/welcome/media/paper-architecture/meta.json +9 -0
- package/starter/documents/welcome/media/paper-architecture/prompt.txt +1 -0
- package/starter/documents/welcome/media/studio-rhythm/chart.svg +2343 -0
- package/starter/documents/welcome/media/studio-rhythm/data.json +234 -0
- package/starter/documents/welcome/media/studio-rhythm/generation.json +9 -0
- package/starter/documents/welcome/media/studio-rhythm/image.png +0 -0
- package/starter/documents/welcome/media/studio-rhythm/meta.json +11 -0
- package/starter/documents/welcome/media/studio-rhythm/recipe.py +79 -0
- package/starter/documents/welcome/theme.tsx +5 -0
- package/starter/documents/welcome-presentation/assets.json +7 -0
- package/starter/documents/welcome-presentation/index.tsx +166 -0
- package/starter/documents/welcome-presentation/media/.gitkeep +0 -0
- package/starter/documents/welcome-presentation/media/paper-architecture/image.png +0 -0
- package/starter/documents/welcome-presentation/media/paper-architecture/meta.json +9 -0
- package/starter/documents/welcome-presentation/media/paper-architecture/prompt.txt +1 -0
- package/starter/documents/welcome-presentation/media/studio-rhythm/chart.svg +1336 -0
- package/starter/documents/welcome-presentation/media/studio-rhythm/data.json +234 -0
- package/starter/documents/welcome-presentation/media/studio-rhythm/generation.json +9 -0
- package/starter/documents/welcome-presentation/media/studio-rhythm/image.png +0 -0
- package/starter/documents/welcome-presentation/media/studio-rhythm/meta.json +13 -0
- package/starter/documents/welcome-presentation/media/studio-rhythm/recipe.py +49 -0
- package/starter/documents/welcome-presentation/theme.tsx +5 -0
- package/starter/projects.json +17 -0
- package/starter/templates/AGENTS.md +9 -0
- package/starter/templates/_shared/BusinessLogo.tsx +14 -0
- package/starter/templates/_shared/Pricing.tsx +40 -0
- package/starter/templates/_shared/commerce.ts +93 -0
- package/starter/templates/brand-guidelines/AGENTS.md +32 -0
- package/starter/templates/brand-guidelines/index.tsx +62 -0
- package/starter/templates/brand-guidelines/preview.tsx +181 -0
- package/starter/templates/brand-guidelines/starter.tsx +179 -0
- package/starter/templates/brand-guidelines/template.json +15 -0
- package/starter/templates/business-proposal/AGENTS.md +13 -0
- package/starter/templates/business-proposal/README.md +36 -0
- package/starter/templates/business-proposal/data.json +37 -0
- package/starter/templates/business-proposal/examples/long.json +142 -0
- package/starter/templates/business-proposal/examples/sparse.json +17 -0
- package/starter/templates/business-proposal/examples/typical.json +37 -0
- package/starter/templates/business-proposal/index.tsx +59 -0
- package/starter/templates/business-proposal/preview.tsx +47 -0
- package/starter/templates/business-proposal/schema.ts +14 -0
- package/starter/templates/business-proposal/starter.tsx +18 -0
- package/starter/templates/business-proposal/template.json +11 -0
- package/starter/templates/company-profile/AGENTS.md +48 -0
- package/starter/templates/company-profile/index.tsx +69 -0
- package/starter/templates/company-profile/preview.tsx +185 -0
- package/starter/templates/company-profile/starter.tsx +186 -0
- package/starter/templates/company-profile/template.json +15 -0
- package/starter/templates/consulting-report/AGENTS.md +11 -0
- package/starter/templates/consulting-report/README.md +13 -0
- package/starter/templates/consulting-report/RESEARCH.md +10 -0
- package/starter/templates/consulting-report/index.tsx +44 -0
- package/starter/templates/consulting-report/preview.tsx +39 -0
- package/starter/templates/consulting-report/starter.tsx +15 -0
- package/starter/templates/consulting-report/template.json +11 -0
- package/starter/templates/editorial-essay/AGENTS.md +11 -0
- package/starter/templates/editorial-essay/README.md +11 -0
- package/starter/templates/editorial-essay/index.tsx +30 -0
- package/starter/templates/editorial-essay/preview.tsx +26 -0
- package/starter/templates/editorial-essay/starter.tsx +15 -0
- package/starter/templates/editorial-essay/template.json +11 -0
- package/starter/templates/executive-brief/AGENTS.md +9 -0
- package/starter/templates/executive-brief/README.md +11 -0
- package/starter/templates/executive-brief/index.tsx +33 -0
- package/starter/templates/executive-brief/preview.tsx +37 -0
- package/starter/templates/executive-brief/starter.tsx +11 -0
- package/starter/templates/executive-brief/template.json +11 -0
- package/starter/templates/image-story/AGENTS.md +37 -0
- package/starter/templates/image-story/index.tsx +106 -0
- package/starter/templates/image-story/preview.tsx +33 -0
- package/starter/templates/image-story/starter.tsx +24 -0
- package/starter/templates/image-story/template.json +13 -0
- package/starter/templates/invoice/AGENTS.md +13 -0
- package/starter/templates/invoice/README.md +40 -0
- package/starter/templates/invoice/data.json +61 -0
- package/starter/templates/invoice/examples/long.json +241 -0
- package/starter/templates/invoice/examples/sparse.json +33 -0
- package/starter/templates/invoice/examples/typical.json +61 -0
- package/starter/templates/invoice/index.tsx +57 -0
- package/starter/templates/invoice/preview.tsx +12 -0
- package/starter/templates/invoice/schema.ts +45 -0
- package/starter/templates/invoice/starter.tsx +12 -0
- package/starter/templates/invoice/template.json +11 -0
- package/starter/templates/literary-text/AGENTS.md +9 -0
- package/starter/templates/literary-text/README.md +11 -0
- package/starter/templates/literary-text/index.tsx +31 -0
- package/starter/templates/literary-text/preview.tsx +20 -0
- package/starter/templates/literary-text/starter.tsx +11 -0
- package/starter/templates/literary-text/template.json +11 -0
- package/starter/templates/magazine-feature/AGENTS.md +11 -0
- package/starter/templates/magazine-feature/README.md +13 -0
- package/starter/templates/magazine-feature/index.tsx +41 -0
- package/starter/templates/magazine-feature/preview.tsx +34 -0
- package/starter/templates/magazine-feature/starter.tsx +15 -0
- package/starter/templates/magazine-feature/template.json +11 -0
- package/starter/templates/monthly-report/AGENTS.md +11 -0
- package/starter/templates/monthly-report/README.md +24 -0
- package/starter/templates/monthly-report/data.json +131 -0
- package/starter/templates/monthly-report/examples/long.json +519 -0
- package/starter/templates/monthly-report/examples/sparse.json +20 -0
- package/starter/templates/monthly-report/examples/typical.json +37 -0
- package/starter/templates/monthly-report/index.tsx +92 -0
- package/starter/templates/monthly-report/preview.tsx +14 -0
- package/starter/templates/monthly-report/schema.ts +127 -0
- package/starter/templates/monthly-report/starter.tsx +13 -0
- package/starter/templates/monthly-report/template.json +11 -0
- package/starter/templates/pitch-deck/AGENTS.md +32 -0
- package/starter/templates/pitch-deck/index.tsx +46 -0
- package/starter/templates/pitch-deck/preview.tsx +142 -0
- package/starter/templates/pitch-deck/starter.tsx +140 -0
- package/starter/templates/pitch-deck/template.json +15 -0
- package/starter/templates/proposal-deck/AGENTS.md +25 -0
- package/starter/templates/proposal-deck/index.tsx +52 -0
- package/starter/templates/proposal-deck/preview.tsx +172 -0
- package/starter/templates/proposal-deck/starter.tsx +168 -0
- package/starter/templates/proposal-deck/template.json +7 -0
- package/starter/templates/quotation/AGENTS.md +13 -0
- package/starter/templates/quotation/README.md +42 -0
- package/starter/templates/quotation/data.json +64 -0
- package/starter/templates/quotation/examples/long.json +272 -0
- package/starter/templates/quotation/examples/sparse.json +31 -0
- package/starter/templates/quotation/examples/typical.json +64 -0
- package/starter/templates/quotation/index.tsx +51 -0
- package/starter/templates/quotation/preview.tsx +12 -0
- package/starter/templates/quotation/schema.ts +27 -0
- package/starter/templates/quotation/starter.tsx +12 -0
- package/starter/templates/quotation/template.json +11 -0
- package/starter/templates/scientific-paper/AGENTS.md +11 -0
- package/starter/templates/scientific-paper/README.md +13 -0
- package/starter/templates/scientific-paper/index.tsx +47 -0
- package/starter/templates/scientific-paper/preview.tsx +43 -0
- package/starter/templates/scientific-paper/starter.tsx +15 -0
- package/starter/templates/scientific-paper/template.json +11 -0
- package/starter/themes/Specimen.tsx +54 -0
- package/starter/themes/civic-spectrum/components.tsx +92 -0
- package/starter/themes/civic-spectrum/design.md +70 -0
- package/starter/themes/civic-spectrum/index.ts +57 -0
- package/starter/themes/civic-spectrum/preview.tsx +66 -0
- package/starter/themes/field-manual/components.tsx +106 -0
- package/starter/themes/field-manual/design.md +72 -0
- package/starter/themes/field-manual/index.ts +57 -0
- package/starter/themes/field-manual/preview.tsx +82 -0
- package/starter/themes/index.ts +3 -0
- package/starter/themes/mckinsey-consulting/components.tsx +69 -0
- package/starter/themes/mckinsey-consulting/design.md +68 -0
- package/starter/themes/mckinsey-consulting/index.ts +60 -0
- package/starter/themes/mckinsey-consulting/preview.tsx +53 -0
- package/starter/themes/neutral/design.md +35 -0
- package/starter/themes/neutral/index.ts +21 -0
- package/starter/themes/neutral/preview.tsx +4 -0
- package/starter/themes/opendoc-neutral/components.tsx +77 -0
- package/starter/themes/opendoc-neutral/design.md +70 -0
- package/starter/themes/opendoc-neutral/index.ts +54 -0
- package/starter/themes/opendoc-neutral/preview.tsx +43 -0
- package/starter/themes/types.ts +3 -0
- package/tsconfig.workspace.json +24 -0
- package/vendor/formepdf/LICENSE +21 -0
- package/vendor/formepdf/README.md +97 -0
- package/vendor/formepdf/font-subset.patch +228 -0
- package/vendor/formepdf/text-writer.patch +507 -0
|
@@ -0,0 +1,432 @@
|
|
|
1
|
+
import { createServer, type IncomingMessage, type ServerResponse } from 'node:http';
|
|
2
|
+
import { WebSocket, WebSocketServer } from 'ws';
|
|
3
|
+
import { readFile, rm, stat } from 'node:fs/promises';
|
|
4
|
+
import { resolve, relative } from 'node:path';
|
|
5
|
+
import { createReadStream } from 'node:fs';
|
|
6
|
+
import { scanMaterials } from './materials';
|
|
7
|
+
import { AssetStore, AssetError } from '../assets/store';
|
|
8
|
+
import { handleAssetRequest } from './assets-http';
|
|
9
|
+
import { ownedFile, readMedia, mediaDirectory, localPath } from '../media/files';
|
|
10
|
+
import type { Materials } from '../shared/media';
|
|
11
|
+
import { randomBytes } from 'node:crypto';
|
|
12
|
+
import { watch } from 'chokidar';
|
|
13
|
+
import type { ViteDevServer } from 'vite';
|
|
14
|
+
import { builtClient } from './client';
|
|
15
|
+
import { GuideError, readGuide } from './guides';
|
|
16
|
+
import { Workspace } from './workspace';
|
|
17
|
+
import { atomicWrite } from './files';
|
|
18
|
+
import { addComment, changeComment, editComment, deleteComment, readComments, Conflict, withCommentLock } from './comments';
|
|
19
|
+
import { renameDocument, duplicateDocument, deleteDocument, restoreDocument } from './documents';
|
|
20
|
+
import { validId } from './render';
|
|
21
|
+
import { createDocument, listStarters, CreateDocumentError } from './create';
|
|
22
|
+
import { publishFile, ExportChangedError } from './export-file';
|
|
23
|
+
import { exportInfo } from '../shared/export';
|
|
24
|
+
import { readPresentationBytes } from './pptx';
|
|
25
|
+
import { ExportStore, ExportError, exportFormat } from './exports';
|
|
26
|
+
import { canCopyFile } from './clipboard';
|
|
27
|
+
import { getBlock, summarizeDocument } from '../shared/types';
|
|
28
|
+
import { anchorForSelection, getTextTarget } from '../shared/anchors';
|
|
29
|
+
import { readSelection } from './selection';
|
|
30
|
+
import { TextEditService } from './edits';
|
|
31
|
+
import { ThemeCatalog, readThemeGuide, themeFile } from './themes';
|
|
32
|
+
import { TemplateCatalog, createFromTemplate, readTemplateGuide } from './templates';
|
|
33
|
+
import { assignProject, createProject, deleteProject, ProjectError, readProjects, requireProject, updateProject } from './projects';
|
|
34
|
+
|
|
35
|
+
import { readAssetHead as selectedAssetHead, readAssetRevision as selectedAssetRevision } from '../assets/files';
|
|
36
|
+
import type { SelectedAsset } from '../shared/assets';
|
|
37
|
+
import { applicationRoot } from '../runtime/paths';
|
|
38
|
+
|
|
39
|
+
const root = process.cwd();
|
|
40
|
+
const workspace = new Workspace(root);
|
|
41
|
+
const edits = new TextEditService(root);
|
|
42
|
+
const exports = new ExportStore(root);
|
|
43
|
+
const assets = new AssetStore(root, () => workspace.list());
|
|
44
|
+
workspace.manualEditSummary = id => edits.summary(id);
|
|
45
|
+
const templates = new TemplateCatalog(root);
|
|
46
|
+
const themes = new ThemeCatalog(root);
|
|
47
|
+
const token = randomBytes(24).toString('hex');
|
|
48
|
+
const events = new WebSocketServer({ noServer: true, maxPayload: 1024 });
|
|
49
|
+
const production = process.argv.includes('--production') || process.env.NODE_ENV === 'production';
|
|
50
|
+
let vite: ViteDevServer | undefined;
|
|
51
|
+
let client: (req: IncomingMessage, res: ServerResponse) => void | Promise<void>;
|
|
52
|
+
let port = Number(process.env.OPENDOC_PORT ?? 4310);
|
|
53
|
+
if (!Number.isInteger(port) || port < 0 || port > 65535) throw new Error('OPENDOC_PORT must be an integer from 0 to 65535.');
|
|
54
|
+
let origin = '';
|
|
55
|
+
let materialsVersion = 0;
|
|
56
|
+
let materialCache: { version: number; result: Promise<Materials> } | undefined;
|
|
57
|
+
function materials() {
|
|
58
|
+
if (!materialCache || materialCache.version !== materialsVersion) materialCache = { version: materialsVersion, result: scanMaterials(root, workspace.list()) };
|
|
59
|
+
return materialCache.result.catch(error => { materialCache = undefined; throw error; });
|
|
60
|
+
}
|
|
61
|
+
function json(res: ServerResponse, value: unknown, status = 200) { res.writeHead(status, { 'Content-Type': 'application/json', 'Cache-Control': 'no-store' }); res.end(JSON.stringify(value)); }
|
|
62
|
+
async function body(req: IncomingMessage, limit = 32_000) {
|
|
63
|
+
if (!req.headers['content-type']?.startsWith('application/json')) throw new Error('Use application/json.');
|
|
64
|
+
const chunks: Buffer[] = [];
|
|
65
|
+
let size = 0;
|
|
66
|
+
for await (const chunk of req) {
|
|
67
|
+
const bytes = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);
|
|
68
|
+
size += bytes.length;
|
|
69
|
+
if (size > limit) throw new Error('Request too large.');
|
|
70
|
+
chunks.push(bytes);
|
|
71
|
+
}
|
|
72
|
+
let value;
|
|
73
|
+
try { value = JSON.parse(Buffer.concat(chunks).toString('utf8') || '{}'); }
|
|
74
|
+
catch { throw new Error('The request contains invalid JSON.'); }
|
|
75
|
+
if (!value || typeof value !== 'object' || Array.isArray(value)) throw new Error('Send a JSON object.');
|
|
76
|
+
return value;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const server = createServer(async (req, res) => {
|
|
80
|
+
if (req.headers.host !== `127.0.0.1:${port}` && req.headers.host !== `localhost:${port}`) { json(res, { error: 'Invalid host.' }, 403); return; }
|
|
81
|
+
try {
|
|
82
|
+
const url = new URL(req.url ?? '/', origin);
|
|
83
|
+
if (!url.pathname.startsWith('/api/')) { await client(req, res); return; }
|
|
84
|
+
if (!['GET', 'HEAD'].includes(req.method ?? 'GET')) {
|
|
85
|
+
const expectedOrigin = `http://${req.headers.host}`;
|
|
86
|
+
if ((req.headers.origin && req.headers.origin !== expectedOrigin) || req.headers['x-opendoc-token'] !== token) { json(res, { error: 'This write must come from the local OpenDoc session.' }, 403); return; }
|
|
87
|
+
}
|
|
88
|
+
if (req.method === 'GET' && url.pathname === '/api/session') { json(res, { token }); return; }
|
|
89
|
+
if (req.method === 'GET' && url.pathname === '/api/guides') { json(res, await readGuide(root, url.searchParams.get('path'))); return; }
|
|
90
|
+
if (await handleAssetRequest(root, assets, req, res, url, json, body, () => workspace.changed())) return;
|
|
91
|
+
if (req.method === 'GET' && url.pathname === '/api/exports/capabilities') { json(res, { copyFile: canCopyFile }); return; }
|
|
92
|
+
const exportRoute = url.pathname.match(/^\/api\/exports\/([a-f0-9-]+)(?:\/(download|open|reveal|copy|restore))?$/);
|
|
93
|
+
if (exportRoute) {
|
|
94
|
+
const [, exportId, action] = exportRoute;
|
|
95
|
+
if (req.method === 'DELETE' && !action) { await exports.remove(exportId); json(res, { ok: true }); return; }
|
|
96
|
+
if (req.method === 'POST' && action === 'restore') { json(res, await exports.restore(exportId)); return; }
|
|
97
|
+
if (req.method === 'POST' && action === 'reveal') { await exports.reveal(exportId); json(res, { ok: true }); return; }
|
|
98
|
+
if (req.method === 'POST' && action === 'copy') { await exports.copy(exportId); json(res, { ok: true }); return; }
|
|
99
|
+
if (req.method === 'GET' && !action) { json(res, { result: await exports.get(exportId) ?? null }); return; }
|
|
100
|
+
if (req.method === 'GET' && (action === 'download' || action === 'open')) {
|
|
101
|
+
const { result, bytes } = await exports.bytes(exportId);
|
|
102
|
+
const info = exportInfo(result.format);
|
|
103
|
+
res.writeHead(200, { 'Content-Type': info.mime, 'Content-Length': bytes.length, 'Content-Disposition': `${action === 'download' || result.format === 'pptx' ? 'attachment' : 'inline'}; filename="document${info.extension}"; filename*=UTF-8''${encodeURIComponent(result.filename).replace(/['()*]/g, character => `%${character.charCodeAt(0).toString(16)}`)}`, 'Cache-Control': 'no-store', 'X-Content-Type-Options': 'nosniff' });
|
|
104
|
+
res.end(bytes); return;
|
|
105
|
+
}
|
|
106
|
+
json(res, { error: 'Not found.' }, 404); return;
|
|
107
|
+
}
|
|
108
|
+
const saveExportRoute = url.pathname.match(/^\/api\/documents\/([a-z0-9-]+)\/exports$/);
|
|
109
|
+
if (saveExportRoute && req.method === 'GET') {
|
|
110
|
+
if (!workspace.states.has(saveExportRoute[1])) throw new ExportError('Document not found.', 404);
|
|
111
|
+
json(res, await exports.list(saveExportRoute[1])); return;
|
|
112
|
+
}
|
|
113
|
+
if (saveExportRoute && req.method === 'POST') {
|
|
114
|
+
const input = await body(req);
|
|
115
|
+
if (!input || typeof input !== 'object' || Array.isArray(input) || Object.keys(input).some(key => !['id', 'hash', 'filename', 'format'].includes(key))) throw new ExportError('Invalid export request.');
|
|
116
|
+
const documentId = saveExportRoute[1];
|
|
117
|
+
const format = exportFormat(input.format);
|
|
118
|
+
const result = await exports.save({ ...input, documentId, format }, async () => {
|
|
119
|
+
const state = workspace.states.get(documentId);
|
|
120
|
+
if (!state) throw new ExportError('Document not found.', 404);
|
|
121
|
+
if (state.status !== 'ready' || state.artifact?.hash !== input.hash) throw new ExportChangedError();
|
|
122
|
+
const revision = state.revision;
|
|
123
|
+
const output = workspace.output(documentId, input.hash);
|
|
124
|
+
if (!output) throw new ExportChangedError();
|
|
125
|
+
if (format === 'pptx' && output.artifact.format !== 'presentation') throw new ExportError('PowerPoint export is available for presentations only.');
|
|
126
|
+
const bytes = format === 'pptx' ? await readPresentationBytes(output.directory, input.hash) : await readFile(resolve(output.directory, 'document.pdf'));
|
|
127
|
+
return { bytes, assetBindings: output.artifact.assetBindings, assets: output.artifact.assets, isCurrent: () => workspace.states.get(documentId) === state && state.status === 'ready' && state.revision === revision && state.artifact?.hash === input.hash };
|
|
128
|
+
});
|
|
129
|
+
json(res, result); return;
|
|
130
|
+
}
|
|
131
|
+
if (req.method === 'GET' && url.pathname === '/api/documents') {
|
|
132
|
+
const states = workspace.list();
|
|
133
|
+
await Promise.all(states.map(async state => { state.manualEdit = await edits.summary(state.id); }));
|
|
134
|
+
json(res, url.searchParams.get('view') === 'summary' ? states.map(summarizeDocument) : states); return;
|
|
135
|
+
}
|
|
136
|
+
if (req.method === 'GET' && url.pathname === '/api/projects') { json(res, await readProjects(root)); return; }
|
|
137
|
+
const documentRoute = url.pathname.match(/^\/api\/documents\/([a-z0-9-]+)$/);
|
|
138
|
+
if (documentRoute && req.method === 'GET') {
|
|
139
|
+
const state = workspace.states.get(documentRoute[1]);
|
|
140
|
+
if (!state) { json(res, { error: 'Document not found.' }, 404); return; }
|
|
141
|
+
const manualEdit = await edits.summary(state.id);
|
|
142
|
+
// Read the live state after asynchronous metadata work so status/revision stay current.
|
|
143
|
+
const current = workspace.states.get(documentRoute[1]);
|
|
144
|
+
if (!current) { json(res, { error: 'Document not found.' }, 404); return; }
|
|
145
|
+
json(res, { ...current, manualEdit }); return;
|
|
146
|
+
}
|
|
147
|
+
if (documentRoute && req.method === 'PATCH') {
|
|
148
|
+
const renamed = await renameDocument(root, documentRoute[1], await body(req));
|
|
149
|
+
await workspace.refreshProjects(); json(res, renamed); return;
|
|
150
|
+
}
|
|
151
|
+
if (documentRoute && req.method === 'DELETE') {
|
|
152
|
+
const id = documentRoute[1];
|
|
153
|
+
const removed = await edits.withDocument(id, () => withCommentLock(root, id, () => deleteDocument(root, id)));
|
|
154
|
+
await workspace.refreshProjects(); json(res, removed); return;
|
|
155
|
+
}
|
|
156
|
+
const duplicateRoute = url.pathname.match(/^\/api\/documents\/([a-z0-9-]+)\/duplicate$/);
|
|
157
|
+
if (duplicateRoute && req.method === 'POST') {
|
|
158
|
+
const id = duplicateRoute[1];
|
|
159
|
+
const copied = await edits.withDocument(id, () => withCommentLock(root, id, () => duplicateDocument(root, id, workspace.states.get(id)?.artifact?.meta.title ?? id)));
|
|
160
|
+
await workspace.refreshProjects(); workspace.invalidate(copied.id); json(res, copied, 201); return;
|
|
161
|
+
}
|
|
162
|
+
const restoreRoute = url.pathname.match(/^\/api\/document-trash\/([a-f0-9-]+)\/restore$/);
|
|
163
|
+
if (restoreRoute && req.method === 'POST') {
|
|
164
|
+
const restored = await restoreDocument(root, restoreRoute[1]);
|
|
165
|
+
await workspace.refreshProjects(); workspace.invalidate(restored.id); json(res, restored); return;
|
|
166
|
+
}
|
|
167
|
+
if (req.method === 'POST' && url.pathname === '/api/projects') {
|
|
168
|
+
const project = await createProject(root, await body(req));
|
|
169
|
+
await workspace.refreshProjects(); json(res, project, 201); return;
|
|
170
|
+
}
|
|
171
|
+
const projectRoute = url.pathname.match(/^\/api\/projects\/([a-z0-9-]+)$/);
|
|
172
|
+
if (projectRoute && req.method === 'PATCH') {
|
|
173
|
+
const project = await updateProject(root, projectRoute[1], await body(req));
|
|
174
|
+
await workspace.refreshProjects(); json(res, project); return;
|
|
175
|
+
}
|
|
176
|
+
if (projectRoute && req.method === 'DELETE') {
|
|
177
|
+
await deleteProject(root, projectRoute[1]);
|
|
178
|
+
await workspace.refreshProjects(); json(res, { ok: true }); return;
|
|
179
|
+
}
|
|
180
|
+
const assignmentRoute = url.pathname.match(/^\/api\/documents\/([a-z0-9-]+)\/project$/);
|
|
181
|
+
if (assignmentRoute && req.method === 'PUT') {
|
|
182
|
+
const input = await body(req);
|
|
183
|
+
if (!input || typeof input !== 'object' || Array.isArray(input) || Object.keys(input).some(key => key !== 'projectId')) throw new ProjectError('Choose the document’s destination project.');
|
|
184
|
+
const assigned = await assignProject(root, assignmentRoute[1], input.projectId);
|
|
185
|
+
await workspace.refreshProjects(); json(res, assigned); return;
|
|
186
|
+
}
|
|
187
|
+
if (req.method === 'GET' && url.pathname === '/api/themes') { json(res, await themes.list()); return; }
|
|
188
|
+
const themeRoute = url.pathname.match(/^\/api\/themes\/([a-z0-9-]+)\/(preview|pdf|guide)$/);
|
|
189
|
+
if (themeRoute && req.method === 'GET') {
|
|
190
|
+
const [, id, action] = themeRoute;
|
|
191
|
+
if (action === 'guide') { json(res, { file: `themes/${id}/design.md`, markdown: await readThemeGuide(root, id) }); return; }
|
|
192
|
+
if (action === 'preview') { json(res, await themes.preview(id)); return; }
|
|
193
|
+
const bytes = await themes.pdf(id, url.searchParams.get('hash') ?? '');
|
|
194
|
+
res.writeHead(200, { 'Content-Type': 'application/pdf', 'Content-Length': bytes.length, 'Cache-Control': 'no-store' }); res.end(bytes); return;
|
|
195
|
+
}
|
|
196
|
+
if (req.method === 'GET' && url.pathname === '/api/templates') { json(res, await templates.list()); return; }
|
|
197
|
+
const templateRoute = url.pathname.match(/^\/api\/templates\/([a-z0-9-]+)\/(pdf|documents|guide|preview)$/);
|
|
198
|
+
if (templateRoute?.[2] === 'preview' && req.method === 'GET') { json(res, await templates.preview(templateRoute[1])); return; }
|
|
199
|
+
if (templateRoute?.[2] === 'guide' && req.method === 'GET') {
|
|
200
|
+
json(res, { file: `templates/${templateRoute[1]}/AGENTS.md`, markdown: await readTemplateGuide(root, templateRoute[1]) }); return;
|
|
201
|
+
}
|
|
202
|
+
if (templateRoute?.[2] === 'pdf' && req.method === 'GET') {
|
|
203
|
+
const bytes = await templates.pdf(templateRoute[1], url.searchParams.get('hash') ?? '');
|
|
204
|
+
res.writeHead(200, { 'Content-Type': 'application/pdf', 'Content-Length': bytes.length, 'Cache-Control': 'no-store' }); res.end(bytes); return;
|
|
205
|
+
}
|
|
206
|
+
if (templateRoute?.[2] === 'documents' && req.method === 'POST') {
|
|
207
|
+
const created = await createFromTemplate(root, templateRoute[1], await body(req));
|
|
208
|
+
await workspace.discover();
|
|
209
|
+
workspace.noteChange(resolve(root, 'documents', created.id, 'index.tsx'));
|
|
210
|
+
json(res, created, 201); return;
|
|
211
|
+
}
|
|
212
|
+
if (req.method === 'GET' && url.pathname === '/api/materials') { json(res, await materials()); return; }
|
|
213
|
+
const materialFile = url.pathname.match(/^\/api\/materials\/([^/]+)\/(image|file)$/);
|
|
214
|
+
if (req.method === 'GET' && materialFile) {
|
|
215
|
+
const [, id, action] = materialFile;
|
|
216
|
+
if (!validId(id) || !workspace.states.has(id)) throw new Error('Unknown document.');
|
|
217
|
+
const document = resolve(root, 'documents', id);
|
|
218
|
+
if (action === 'image') {
|
|
219
|
+
const asset = readMedia(document, url.searchParams.get('item') ?? '');
|
|
220
|
+
if (url.searchParams.get('hash') !== asset.hash) throw new Conflict('This image changed. Reload the media browser.');
|
|
221
|
+
res.writeHead(200, { 'Content-Type': asset.mime, 'Content-Length': asset.bytes.length, 'Cache-Control': 'private, max-age=31536000, immutable', 'X-Content-Type-Options': 'nosniff' });
|
|
222
|
+
res.end(asset.bytes); return;
|
|
223
|
+
}
|
|
224
|
+
const name = url.searchParams.get('path') ?? '';
|
|
225
|
+
localPath(name, 'Media path');
|
|
226
|
+
if (!name.startsWith('media/')) throw new Error('Only files inside this document’s media folder are available here.');
|
|
227
|
+
const file = ownedFile(document, name);
|
|
228
|
+
const info = await stat(file);
|
|
229
|
+
res.writeHead(200, { 'Content-Type': 'application/octet-stream', 'Content-Length': info.size, 'Content-Disposition': `attachment; filename*=UTF-8''${encodeURIComponent(name.split('/').at(-1)!)}`, 'X-Content-Type-Options': 'nosniff' });
|
|
230
|
+
const stream = createReadStream(file); stream.on('error', () => res.destroy()); stream.pipe(res); return;
|
|
231
|
+
}
|
|
232
|
+
if (req.method === 'GET' && url.pathname === '/api/starters') { json(res, { starters: listStarters() }); return; }
|
|
233
|
+
if (req.method === 'POST' && url.pathname === '/api/documents') {
|
|
234
|
+
const created = await createDocument(root, await body(req));
|
|
235
|
+
await workspace.discover();
|
|
236
|
+
workspace.noteChange(resolve(root, 'documents', created.id, 'index.tsx'));
|
|
237
|
+
json(res, created, 201); return;
|
|
238
|
+
}
|
|
239
|
+
if (req.method === 'GET' && url.pathname === '/api/events') {
|
|
240
|
+
// Stop older clients from reconnecting their HTTP-slot-consuming SSE stream.
|
|
241
|
+
res.writeHead(204, { 'Cache-Control': 'no-store' }); res.end(); return;
|
|
242
|
+
}
|
|
243
|
+
if (req.method === 'POST' && url.pathname === '/api/context') {
|
|
244
|
+
const value = await body(req);
|
|
245
|
+
if (value.documentId !== null && !workspace.states.has(value.documentId)) throw new Error('Unknown document.');
|
|
246
|
+
if (value.blockId !== null && typeof value.blockId !== 'string') throw new Error('Invalid block.');
|
|
247
|
+
const state = workspace.states.get(value.documentId);
|
|
248
|
+
if (value.blockId && !getBlock(state?.artifact, value.blockId)) {
|
|
249
|
+
const comments = await readComments(root, value.documentId);
|
|
250
|
+
if (!comments.some(c => c.blockId === value.blockId)) throw new Error('Unknown block.');
|
|
251
|
+
}
|
|
252
|
+
const contextPages = Math.max(state?.artifact?.pages.length ?? 1, value.draftPreview === true && state ? edits.previewPageCount(state.id) : 1);
|
|
253
|
+
if (!Number.isInteger(value.page) || value.page < 1 || value.page > contextPages) throw new Error('Invalid page.');
|
|
254
|
+
if (value.mediaId != null) {
|
|
255
|
+
if (!state) throw new Error('Choose the owning document first.');
|
|
256
|
+
mediaDirectory(resolve(root, 'documents', state.id), value.mediaId);
|
|
257
|
+
}
|
|
258
|
+
const projectId = state?.projectId ?? (value.projectId == null ? null : requireProject(await readProjects(root), value.projectId).id);
|
|
259
|
+
const themeId = state ? null : value.themeId ?? null;
|
|
260
|
+
if (themeId !== null) await themeFile(root, themeId, 'index.ts');
|
|
261
|
+
let selectedAsset: SelectedAsset | null = null;
|
|
262
|
+
// Library selection is independent observed context, and is cleared by document/theme navigation.
|
|
263
|
+
if (!state && !themeId && value.mediaId == null && value.selectedAsset != null) {
|
|
264
|
+
const requested = value.selectedAsset;
|
|
265
|
+
if (!requested || typeof requested !== 'object' || Array.isArray(requested)
|
|
266
|
+
|| Object.keys(requested).some(key => !['kind', 'id', 'revision', 'variation', 'face'].includes(key))) throw new Error('Invalid selected asset.');
|
|
267
|
+
const head = selectedAssetHead(root, requested.kind, requested.id);
|
|
268
|
+
const asset = selectedAssetRevision(root, requested.kind, requested.id, requested.revision ?? head.revision);
|
|
269
|
+
if (requested.variation !== undefined && (asset.kind !== 'logo' || !asset.variations.some(item => item.id === requested.variation))) throw new Error('Unknown logo variation.');
|
|
270
|
+
if (requested.face !== undefined && (asset.kind !== 'font' || !asset.faces.some(item => item.id === requested.face))) throw new Error('Unknown font face.');
|
|
271
|
+
selectedAsset = { kind: asset.kind, id: asset.id, revision: asset.revision,
|
|
272
|
+
...(requested.variation !== undefined ? { variation: requested.variation } : {}), ...(requested.face !== undefined ? { face: requested.face } : {}) };
|
|
273
|
+
}
|
|
274
|
+
const selection = readSelection(value.selection, value.blockId);
|
|
275
|
+
if (value.editing !== undefined && typeof value.editing !== 'boolean') throw new Error('Invalid editor state.');
|
|
276
|
+
if (value.pendingEdits !== undefined && (!Number.isInteger(value.pendingEdits) || value.pendingEdits < 0 || value.pendingEdits > 100)) throw new Error('Invalid pending edit count.');
|
|
277
|
+
if (value.draftPreview !== undefined && typeof value.draftPreview !== 'boolean') throw new Error('Invalid draft preview state.');
|
|
278
|
+
await workspace.setContext({ themeId, projectId, selectedAsset, documentId: value.documentId, blockId: value.blockId, page: value.page, mediaId: value.mediaId ?? null, selection, editing: value.editing ?? false, pendingEdits: value.pendingEdits ?? 0, draftPreview: value.draftPreview ?? false });
|
|
279
|
+
json(res, { ok: true }); return;
|
|
280
|
+
}
|
|
281
|
+
const draftPDF = url.pathname.match(/^\/api\/documents\/([^/]+)\/edits\/previews\/([a-f0-9-]+)\/pdf$/);
|
|
282
|
+
if (draftPDF && req.method === 'GET' && validId(draftPDF[1])) {
|
|
283
|
+
const bytes = await edits.previewPDF(draftPDF[1], draftPDF[2]);
|
|
284
|
+
res.writeHead(200, { 'Content-Type': 'application/pdf', 'Content-Length': bytes.length, 'Cache-Control': 'no-store' }); res.end(bytes); return;
|
|
285
|
+
}
|
|
286
|
+
const editPreview = url.pathname.match(/^\/api\/documents\/([^/]+)\/edits\/preview$/);
|
|
287
|
+
if (editPreview && req.method === 'POST' && validId(editPreview[1])) {
|
|
288
|
+
const state = workspace.states.get(editPreview[1]);
|
|
289
|
+
if (!state) { json(res, { error: 'Document not found.' }, 404); return; }
|
|
290
|
+
json(res, await edits.preview(state.id, await body(req, 256_000), state)); return;
|
|
291
|
+
}
|
|
292
|
+
const editRoute = url.pathname.match(/^\/api\/documents\/([^/]+)\/edits(?:\/([^/]+)\/undo)?$/);
|
|
293
|
+
if (editRoute && req.method === 'POST' && validId(editRoute[1])) {
|
|
294
|
+
const [, id, editId] = editRoute;
|
|
295
|
+
const state = workspace.states.get(id);
|
|
296
|
+
if (!state) { json(res, { error: 'Document not found.' }, 404); return; }
|
|
297
|
+
const input = await body(req, 256_000);
|
|
298
|
+
state.manualEdit = editId ? await edits.undo(id, editId) : await edits.apply(id, input, state);
|
|
299
|
+
const files = edits.changedFiles(id);
|
|
300
|
+
if (files.length) for (const file of files) workspace.noteChange(resolve(root, file));
|
|
301
|
+
else workspace.invalidate(id);
|
|
302
|
+
workspace.changed();
|
|
303
|
+
json(res, state); return;
|
|
304
|
+
}
|
|
305
|
+
const match = url.pathname.match(/^\/api\/documents\/([^/]+)\/(pdf|export|comments)(?:\/([^/]+))?$/);
|
|
306
|
+
if (!match || !validId(match[1])) { json(res, { error: 'Not found.' }, 404); return; }
|
|
307
|
+
const [, id, action, commentId] = match;
|
|
308
|
+
const state = workspace.states.get(id);
|
|
309
|
+
if (!state) { json(res, { error: 'Document not found.' }, 404); return; }
|
|
310
|
+
if (action === 'pdf' && req.method === 'GET') {
|
|
311
|
+
const output = workspace.output(id, url.searchParams.get('hash') ?? '');
|
|
312
|
+
if (!output) { json(res, { error: 'This preview was replaced. Reload the document.' }, 409); return; }
|
|
313
|
+
const bytes = await readFile(resolve(output.directory, 'document.pdf'));
|
|
314
|
+
res.writeHead(200, { 'Content-Type': 'application/pdf', 'Content-Length': bytes.length, 'Cache-Control': 'no-store' }); res.end(bytes); return;
|
|
315
|
+
}
|
|
316
|
+
if (action === 'export' && req.method === 'POST') {
|
|
317
|
+
const { hash, format: requestedFormat } = await body(req);
|
|
318
|
+
const format = exportFormat(requestedFormat), info = exportInfo(format);
|
|
319
|
+
if (state.status !== 'ready' || state.artifact?.hash !== hash) throw new Conflict('Wait for the current document to finish rendering before exporting.');
|
|
320
|
+
const output = workspace.output(id, hash)!;
|
|
321
|
+
const revision = state.revision;
|
|
322
|
+
if (format === 'pptx' && output.artifact.format !== 'presentation') throw new ExportError('PowerPoint export is available for presentations only.');
|
|
323
|
+
const bytes = format === 'pptx' ? await readPresentationBytes(output.directory, hash) : await readFile(resolve(output.directory, 'document.pdf'));
|
|
324
|
+
if (state.status !== 'ready' || state.revision !== revision) throw new Conflict('The document changed during export. Try again.');
|
|
325
|
+
await publishFile(root, id, bytes, format, () => workspace.states.get(id) === state && state.status === 'ready' && state.revision === revision && state.artifact?.hash === hash);
|
|
326
|
+
res.writeHead(200, { 'Content-Type': info.mime, 'Content-Length': bytes.length, 'Content-Disposition': `attachment; filename="${id}${info.extension}"`, 'Cache-Control': 'no-store' }); res.end(bytes); return;
|
|
327
|
+
}
|
|
328
|
+
if (action === 'comments') {
|
|
329
|
+
if (req.method === 'GET') { json(res, (await readComments(root, id)).filter(comment => comment.status !== 'deleted')); return; }
|
|
330
|
+
if (req.method === 'POST' && !commentId) {
|
|
331
|
+
const value = await body(req);
|
|
332
|
+
if (state.status !== 'ready' || state.artifact?.hash !== value.hash) throw new Conflict('The preview changed. Wait for the latest version before commenting.');
|
|
333
|
+
const block = getBlock(state.artifact, value.blockId);
|
|
334
|
+
if (!block) throw new Error('The selected block is no longer available.');
|
|
335
|
+
const selection = readSelection(value.selection, value.blockId);
|
|
336
|
+
if (selection && (selection.renderHash !== undefined && selection.renderHash !== value.hash
|
|
337
|
+
|| selection.revision !== undefined && selection.revision !== state.revision)) throw new Conflict('This selection changed. Select the phrase again before commenting.');
|
|
338
|
+
const anchor = anchorForSelection(state.artifact, selection);
|
|
339
|
+
if (selection?.targetId && !anchor && getTextTarget(state.artifact, selection.targetId)?.stable !== false) throw new Error('Select the phrase again before commenting.');
|
|
340
|
+
json(res, (await addComment(root, id, { blockId: block.id, text: value.text, quote: selection?.quote ?? block.text, anchor, exactQuote: !!selection?.quote })).filter(comment => comment.status !== 'deleted')); workspace.changed(); return;
|
|
341
|
+
}
|
|
342
|
+
if (req.method === 'PATCH' && commentId) {
|
|
343
|
+
const value = await body(req);
|
|
344
|
+
const comments = Object.hasOwn(value, 'text')
|
|
345
|
+
? await editComment(root, id, commentId, value.text, value.version)
|
|
346
|
+
: await changeComment(root, id, commentId, value.status, value.version);
|
|
347
|
+
json(res, comments.filter(comment => comment.status !== 'deleted')); workspace.changed(); return;
|
|
348
|
+
}
|
|
349
|
+
if (req.method === 'DELETE' && commentId) {
|
|
350
|
+
const value = await body(req);
|
|
351
|
+
json(res, (await deleteComment(root, id, commentId, value.version)).filter(comment => comment.status !== 'deleted')); workspace.changed(); return;
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
json(res, { error: 'Not found.' }, 404);
|
|
355
|
+
} catch (error) { json(res, { error: (error as NodeJS.ErrnoException).code === 'ENOENT' ? 'That local file is missing. Restore it or reload the library.' : error instanceof Error ? error.message : String(error) }, error instanceof CreateDocumentError || error instanceof ProjectError || error instanceof ExportError || error instanceof AssetError || error instanceof GuideError ? error.status : error instanceof Conflict || error instanceof ExportChangedError ? 409 : (error as NodeJS.ErrnoException).code === 'ENOENT' ? 404 : 400); }
|
|
356
|
+
});
|
|
357
|
+
|
|
358
|
+
// Upgraded sockets do not occupy the browser's six HTTP/1 request slots.
|
|
359
|
+
server.on('upgrade', (req, socket, head) => {
|
|
360
|
+
if (req.url?.split('?')[0] !== '/api/events') {
|
|
361
|
+
if (production) socket.destroy(); // Vite owns other upgrades in development.
|
|
362
|
+
return;
|
|
363
|
+
}
|
|
364
|
+
const host = req.headers.host;
|
|
365
|
+
if ((host !== `127.0.0.1:${port}` && host !== `localhost:${port}`) || req.headers.origin !== `http://${host}`) {
|
|
366
|
+
socket.end('HTTP/1.1 403 Forbidden\r\nConnection: close\r\n\r\n'); return;
|
|
367
|
+
}
|
|
368
|
+
events.handleUpgrade(req, socket, head, client => {
|
|
369
|
+
client.on('error', () => client.terminate());
|
|
370
|
+
client.send('connected');
|
|
371
|
+
});
|
|
372
|
+
});
|
|
373
|
+
|
|
374
|
+
if (production) client = await builtClient(applicationRoot);
|
|
375
|
+
else {
|
|
376
|
+
const { createServer: createViteServer } = await import('vite');
|
|
377
|
+
vite = await createViteServer({ root: applicationRoot, server: { middlewareMode: true, ws: { server } }, appType: 'spa' });
|
|
378
|
+
client = (req, res) => vite!.middlewares(req, res);
|
|
379
|
+
}
|
|
380
|
+
while (true) {
|
|
381
|
+
try {
|
|
382
|
+
await new Promise<void>((accept, reject) => { server.once('error', reject); server.listen(port, '127.0.0.1', () => { server.off('error', reject); accept(); }); }); break;
|
|
383
|
+
} catch (error) { if ((error as NodeJS.ErrnoException).code !== 'EADDRINUSE' || process.env.OPENDOC_PORT || port >= 4320) throw error; port++; }
|
|
384
|
+
}
|
|
385
|
+
const address = server.address();
|
|
386
|
+
if (address && typeof address === 'object') port = address.port;
|
|
387
|
+
origin = `http://127.0.0.1:${port}`;
|
|
388
|
+
await atomicWrite(resolve(root, '.opendoc/server.json'), JSON.stringify({ origin, token, pid: process.pid }, null, 2));
|
|
389
|
+
workspace.on('change', () => {
|
|
390
|
+
materialsVersion++;
|
|
391
|
+
for (const client of events.clients) if (client.readyState === WebSocket.OPEN) client.send('changed');
|
|
392
|
+
});
|
|
393
|
+
const watcher = watch([...new Set([root, resolve(applicationRoot, 'src'), resolve(applicationRoot, 'package.json'), resolve(applicationRoot, 'pnpm-lock.yaml'), resolve(applicationRoot, 'tsconfig.workspace.json')])], { ignoreInitial: true, ignored: path => {
|
|
394
|
+
const installed = relative(applicationRoot, path);
|
|
395
|
+
const rel = installed === '' || (!installed.startsWith('../') && installed !== '..') ? installed : relative(root, path);
|
|
396
|
+
return /(^|[/\\])(node_modules|\.git|\.opendoc|output|tmp|dist|tests)([/\\]|$)/.test(rel) || /\.forme-render-|\.tmp$/.test(rel);
|
|
397
|
+
} });
|
|
398
|
+
watcher.on('all', (_event, path) => {
|
|
399
|
+
if (relative(root, path) === 'projects.json') {
|
|
400
|
+
void workspace.refreshProjects().catch(error => workspace.emit('workspace-error', error)); return;
|
|
401
|
+
}
|
|
402
|
+
// Catalogs follow their own imports and asset bindings, including local data files.
|
|
403
|
+
void Promise.all([templates.noteChange(path), themes.noteChange(path)])
|
|
404
|
+
.then(() => workspace.changed()).catch(error => workspace.emit('workspace-error', error));
|
|
405
|
+
if (/^themes\/.*\.md$/.test(relative(root, path))) return;
|
|
406
|
+
if (path.endsWith('comments.json')) { workspace.changed(); return; }
|
|
407
|
+
// Documents may import modules or read local assets in any format (CSV, text,
|
|
408
|
+
// diagrams, and fonts included). Dependency handling decides what is affected.
|
|
409
|
+
workspace.noteChange(path);
|
|
410
|
+
});
|
|
411
|
+
workspace.on('workspace-error', error => console.error('Workspace refresh failed:', error));
|
|
412
|
+
await workspace.refresh();
|
|
413
|
+
console.log(`\nOpenDoc is running at ${origin}\nDocuments: ${resolve(root, 'documents')}\n`);
|
|
414
|
+
let closing = false;
|
|
415
|
+
async function close() {
|
|
416
|
+
if (closing) return; closing = true;
|
|
417
|
+
const stopped = new Promise<void>((accept, reject) => server.close(error => error ? reject(error) : accept()));
|
|
418
|
+
for (const client of events.clients) client.terminate();
|
|
419
|
+
events.close();
|
|
420
|
+
for (const client of vite?.ws.clients ?? []) client.socket.terminate();
|
|
421
|
+
// Complete accepted saves while their preview files and source watcher are still available.
|
|
422
|
+
await stopped;
|
|
423
|
+
await watcher.close();
|
|
424
|
+
await workspace.close(); await edits.close(); await templates.close(); await themes.close(); await vite?.close();
|
|
425
|
+
const sessionFile = resolve(root, '.opendoc/server.json');
|
|
426
|
+
const session = await readFile(sessionFile, 'utf8').then(JSON.parse, error => { if (error.code === 'ENOENT') return null; throw error; });
|
|
427
|
+
// Another process may now own the workspace session. Do not disconnect its CLI.
|
|
428
|
+
if (session?.pid === process.pid && session?.token === token) await rm(sessionFile, { force: true });
|
|
429
|
+
}
|
|
430
|
+
function shutdown() { if (closing) return; void close().then(() => process.exit(0), error => { console.error('OpenDoc could not finish closing:', error); process.exit(1); }); }
|
|
431
|
+
process.on('SIGINT', shutdown);
|
|
432
|
+
process.on('SIGTERM', shutdown);
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { readdir, lstat } from 'node:fs/promises';
|
|
2
|
+
import { resolve } from 'node:path';
|
|
3
|
+
import { readMedia, mediaFreshness, mediaId, hashBytes } from '../media/files';
|
|
4
|
+
import { validId } from './render';
|
|
5
|
+
import { documentName, type DocumentState } from '../shared/types';
|
|
6
|
+
import type { Materials, MediaItem } from '../shared/media';
|
|
7
|
+
|
|
8
|
+
/** Files remain the source of truth; this index is disposable and never edits an asset. */
|
|
9
|
+
export async function scanMaterials(root: string, documents: DocumentState[]): Promise<Materials> {
|
|
10
|
+
const media: MediaItem[] = [], issues: string[] = [];
|
|
11
|
+
for (const document of documents) {
|
|
12
|
+
if (!validId(document.id)) continue;
|
|
13
|
+
const base = resolve(root, 'documents', document.id);
|
|
14
|
+
const title = documentName(document);
|
|
15
|
+
const owner = { documentId: document.id, documentTitle: title };
|
|
16
|
+
try {
|
|
17
|
+
const folder = resolve(base, 'media');
|
|
18
|
+
const info = await lstat(folder);
|
|
19
|
+
if (info.isSymbolicLink() || !info.isDirectory()) throw new Error('media must be an ordinary folder.');
|
|
20
|
+
for (const dir of (await readdir(folder, { withFileTypes: true })).sort((a,b) => a.name.localeCompare(b.name))) {
|
|
21
|
+
if (dir.name.startsWith('.')) continue;
|
|
22
|
+
if (!dir.isDirectory() || !mediaId.test(dir.name)) { issues.push(`${document.id}/media/${dir.name}: use a media item folder with a lowercase hyphenated name.`); continue; }
|
|
23
|
+
const item: MediaItem = { ...owner, id: dir.name, folder: `documents/${document.id}/media/${dir.name}`, freshness: 'original', usedIn: [], usageKnown: document.status === 'ready' };
|
|
24
|
+
try {
|
|
25
|
+
const asset = readMedia(base, dir.name);
|
|
26
|
+
Object.assign(item, { meta: asset.meta, metadataRevision: hashBytes(Buffer.from(JSON.stringify(asset.meta))), hash: asset.hash, mime: asset.mime, width: asset.width, height: asset.height, bytes: asset.bytes.length }, mediaFreshness(asset));
|
|
27
|
+
} catch (error) { item.error = (error as Error).message; }
|
|
28
|
+
const uses = document.artifact?.media?.filter(use => use.item === dir.name) ?? [];
|
|
29
|
+
item.usedIn = [...new Set(uses.map(use => use.blockId).filter((id): id is string => !!id))].map(blockId => ({ blockId, pages: document.artifact!.pages.flatMap((page,index) => page.fragments.some(fragment => fragment.id === blockId) ? [index+1] : []) }));
|
|
30
|
+
// A bare Media component is still used even without a Figure feedback target.
|
|
31
|
+
if (uses.some(use => !use.blockId)) item.usedIn.push({blockId: '', pages: []});
|
|
32
|
+
media.push(item);
|
|
33
|
+
await new Promise<void>(accept => setImmediate(accept));
|
|
34
|
+
}
|
|
35
|
+
} catch (error) { if ((error as NodeJS.ErrnoException).code !== 'ENOENT') issues.push(`${document.id}: ${(error as Error).message}`); }
|
|
36
|
+
|
|
37
|
+
}
|
|
38
|
+
return { media, issues };
|
|
39
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { parseArgs } from 'node:util';
|
|
2
|
+
import { resolve } from 'node:path';
|
|
3
|
+
import { pathToFileURL } from 'node:url';
|
|
4
|
+
import { readFile, stat } from 'node:fs/promises';
|
|
5
|
+
import { documentEntry, validId } from './render';
|
|
6
|
+
import { atomicWrite } from './files';
|
|
7
|
+
import { readMedia, mediaFreshness, imageInfo, hashBytes } from '../media/files';
|
|
8
|
+
import type { GenerationRecord, } from '../media/files';
|
|
9
|
+
import type { MediaKind } from '../shared/media';
|
|
10
|
+
import { importMedia as importMediaUpload } from './media-mutations';
|
|
11
|
+
import { discoverDocumentIds } from './export-batch';
|
|
12
|
+
import { scanMaterials } from './materials';
|
|
13
|
+
|
|
14
|
+
/** Record only after generation and review; it is a provenance snapshot, not a generator. */
|
|
15
|
+
export async function recordMedia(root: string, documentId: string, id: string) {
|
|
16
|
+
const entry = await documentEntry(root, documentId);
|
|
17
|
+
const document = resolve(entry, '..');
|
|
18
|
+
const asset = readMedia(document, id);
|
|
19
|
+
const record: GenerationRecord = { version: 1, imageHash: asset.hash, inputs: asset.inputs, recordedAt: new Date().toISOString() };
|
|
20
|
+
// Re-read immediately before publishing so an input change cannot be recorded as reviewed.
|
|
21
|
+
const latest = readMedia(document, id);
|
|
22
|
+
if (latest.hash !== asset.hash || JSON.stringify(latest.inputs) !== JSON.stringify(asset.inputs)) throw new Error('Media inputs changed while recording. Generate and review the current version first.');
|
|
23
|
+
await atomicWrite(resolve(asset.directory, 'generation.json'), JSON.stringify(record, null, 2) + '\n');
|
|
24
|
+
return record;
|
|
25
|
+
}
|
|
26
|
+
export async function importMedia(root: string, documentId: string, id: string, file: string, title: string, description: string, kind = 'image') {
|
|
27
|
+
const input = resolve(file);
|
|
28
|
+
const inputInfo = await stat(input);
|
|
29
|
+
if (!inputInfo.isFile()) throw new Error('Choose a regular image file.');
|
|
30
|
+
if (inputInfo.size > 50_000_000) throw new Error('Keep an embedding image below 50 MB.');
|
|
31
|
+
const bytes = await readFile(input);
|
|
32
|
+
const info = imageInfo(bytes);
|
|
33
|
+
if (bytes.length > 50_000_000) throw new Error('Keep an embedding image below 50 MB.');
|
|
34
|
+
const name = info.mime === 'image/png' ? 'image.png' : 'image.jpg';
|
|
35
|
+
// Preserve the CLI's content-based input detection while sharing staged publication
|
|
36
|
+
// and full image decoding with the browser upload path.
|
|
37
|
+
const imported = await importMediaUpload(root, documentId, { id, title, description, kind: kind as MediaKind }, { filename: name, bytes });
|
|
38
|
+
return { ...imported, file: `documents/${documentId}/media/${id}/${name}`, hash: hashBytes(bytes) };
|
|
39
|
+
}
|
|
40
|
+
const usage = 'Usage: npx opendoc media list [<document>] [--json]\n npx opendoc media import <document> <media-id> --file <image> --title "Title" --description "Description" [--kind photo|illustration|chart|diagram|image]\n npx opendoc media record <document> <media-id>\n npx opendoc media check <document> <media-id>';
|
|
41
|
+
export async function runMediaCli(args: string[], root = process.cwd()): Promise<void> {
|
|
42
|
+
const { values, positionals } = parseArgs({ args: args[0] === '--' ? args.slice(1) : args, allowPositionals: true, options: {
|
|
43
|
+
file: { type: 'string' }, title: { type: 'string' }, description: { type: 'string' }, kind: { type: 'string' },
|
|
44
|
+
json: { type: 'boolean' }, help: { type: 'boolean', short: 'h' },
|
|
45
|
+
} });
|
|
46
|
+
if (values.help) { console.log(values.json ? JSON.stringify({ usage }, null, 2) : usage); return; }
|
|
47
|
+
const [action = 'list', doc, id] = positionals;
|
|
48
|
+
const importFlags = ['file', 'title', 'description', 'kind'];
|
|
49
|
+
if (action !== 'import' && Object.keys(values).some(key => importFlags.includes(key))) throw new Error(usage);
|
|
50
|
+
if (action === 'list' && positionals.length <= 2) {
|
|
51
|
+
if (doc !== undefined && !validId(doc)) throw new Error(usage);
|
|
52
|
+
const ids = doc === undefined ? await discoverDocumentIds(root) : [doc];
|
|
53
|
+
for (const documentId of ids) await documentEntry(root, documentId);
|
|
54
|
+
// Listing should not execute authored TSX. Without a render, usage remains explicitly unknown.
|
|
55
|
+
console.log(JSON.stringify(await scanMaterials(root, ids.map(id => ({ id, status: 'rendering' as const, revision: 0 }))), null, 2));
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
if (!validId(doc ?? '')) throw new Error(usage);
|
|
59
|
+
if (action === 'import' && positionals.length === 3 && values.file && values.title && values.description) {
|
|
60
|
+
console.log(JSON.stringify(await importMedia(root, doc, id, values.file, values.title, values.description, values.kind), null, 2));
|
|
61
|
+
} else if (action === 'record' && positionals.length === 3) {
|
|
62
|
+
console.log(JSON.stringify(await recordMedia(root, doc, id), null, 2));
|
|
63
|
+
} else if (action === 'check' && positionals.length === 3) {
|
|
64
|
+
const entry = await documentEntry(root, doc);
|
|
65
|
+
const media = readMedia(resolve(entry, '..'), id);
|
|
66
|
+
const status = mediaFreshness(media);
|
|
67
|
+
console.log(JSON.stringify({ meta: media.meta, ...status }, null, 2));
|
|
68
|
+
if (status.freshness === 'stale' || status.freshness === 'unrecorded') process.exitCode = 1;
|
|
69
|
+
} else throw new Error(usage);
|
|
70
|
+
}
|
|
71
|
+
if (process.argv[1] && import.meta.url === pathToFileURL(resolve(process.argv[1])).href) {
|
|
72
|
+
runMediaCli(process.argv.slice(2)).catch(error => { console.error(error instanceof Error ? error.message : String(error)); process.exitCode = 1; });
|
|
73
|
+
}
|