@sixb/core 0.2.4 → 0.2.6
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/dist/actions/index.js +41 -40
- package/dist/actions/index.js.map +1 -1
- package/dist/actions/validation.d.ts.map +1 -1
- package/dist/agents/errors.d.ts +1 -1
- package/dist/agents/errors.d.ts.map +1 -1
- package/dist/agents/execution.d.ts +50 -3
- package/dist/agents/execution.d.ts.map +1 -1
- package/dist/agents/ids.d.ts +2 -0
- package/dist/agents/ids.d.ts.map +1 -1
- package/dist/agents/index.d.ts +7 -5
- package/dist/agents/index.d.ts.map +1 -1
- package/dist/agents/index.js +74 -50
- package/dist/agents/index.js.map +1 -1
- package/dist/agents/model-routing.d.ts +5 -2
- package/dist/agents/model-routing.d.ts.map +1 -1
- package/dist/agents/queued-turn.d.ts +16 -0
- package/dist/agents/queued-turn.d.ts.map +1 -0
- package/dist/agents/request.d.ts +120 -1
- package/dist/agents/request.d.ts.map +1 -1
- package/dist/agents/run-after-finish.d.ts +10 -0
- package/dist/agents/run-after-finish.d.ts.map +1 -1
- package/dist/agents/run-artifacts.d.ts +0 -38
- package/dist/agents/run-artifacts.d.ts.map +1 -1
- package/dist/agents/run-events.d.ts +10 -1
- package/dist/agents/run-events.d.ts.map +1 -1
- package/dist/agents/run-session-children.d.ts.map +1 -1
- package/dist/agents/run-session-http.d.ts.map +1 -1
- package/dist/agents/run-session-serve.d.ts.map +1 -1
- package/dist/agents/run-session.d.ts +14 -1
- package/dist/agents/run-session.d.ts.map +1 -1
- package/dist/agents/run-turn.d.ts +9 -1
- package/dist/agents/run-turn.d.ts.map +1 -1
- package/dist/agents/streams/index.d.ts +1 -1
- package/dist/agents/streams/index.d.ts.map +1 -1
- package/dist/agents/streams/index.js +1 -1
- package/dist/agents/streams/internal.d.ts +2 -1
- package/dist/agents/streams/internal.d.ts.map +1 -1
- package/dist/agents/streams/internal.js +22 -2
- package/dist/agents/streams/internal.js.map +1 -1
- package/dist/agents/streams/protocol.d.ts +53 -0
- package/dist/agents/streams/protocol.d.ts.map +1 -1
- package/dist/agents/streams/steps.d.ts +24 -0
- package/dist/agents/streams/steps.d.ts.map +1 -0
- package/dist/agents/thread-access.d.ts +44 -2
- package/dist/agents/thread-access.d.ts.map +1 -1
- package/dist/agents/turn-answered.d.ts +7 -0
- package/dist/agents/turn-answered.d.ts.map +1 -0
- package/dist/agents/validation.d.ts +1 -1
- package/dist/agents/validation.d.ts.map +1 -1
- package/dist/artifacts/canvas-display.d.ts +3 -5
- package/dist/artifacts/canvas-display.d.ts.map +1 -1
- package/dist/artifacts/comments.d.ts +14 -3
- package/dist/artifacts/comments.d.ts.map +1 -1
- package/dist/artifacts/document-fill.d.ts +18 -0
- package/dist/artifacts/document-fill.d.ts.map +1 -0
- package/dist/artifacts/errors.d.ts +1 -1
- package/dist/artifacts/errors.d.ts.map +1 -1
- package/dist/artifacts/events.d.ts +3 -2
- package/dist/artifacts/events.d.ts.map +1 -1
- package/dist/artifacts/execution.d.ts +40 -4
- package/dist/artifacts/execution.d.ts.map +1 -1
- package/dist/artifacts/frames/assets.d.ts +8 -1
- package/dist/artifacts/frames/assets.d.ts.map +1 -1
- package/dist/artifacts/frames/document-data.d.ts +98 -0
- package/dist/artifacts/frames/document-data.d.ts.map +1 -0
- package/dist/artifacts/frames/entries.d.ts +12 -7
- package/dist/artifacts/frames/entries.d.ts.map +1 -1
- package/dist/artifacts/frames/index.d.ts +2 -1
- package/dist/artifacts/frames/index.d.ts.map +1 -1
- package/dist/artifacts/frames/index.js +22 -13
- package/dist/artifacts/frames/index.js.map +4 -4
- package/dist/artifacts/frames/kit.d.ts +15 -0
- package/dist/artifacts/frames/kit.d.ts.map +1 -1
- package/dist/artifacts/frames/protocol.d.ts +12 -1
- package/dist/artifacts/frames/protocol.d.ts.map +1 -1
- package/dist/artifacts/frames/runtime.d.ts +24 -4
- package/dist/artifacts/frames/runtime.d.ts.map +1 -1
- package/dist/artifacts/index.d.ts +3 -1
- package/dist/artifacts/index.d.ts.map +1 -1
- package/dist/artifacts/index.js +9 -3
- package/dist/artifacts/index.js.map +3 -3
- package/dist/artifacts/live/blocks.d.ts +62 -0
- package/dist/artifacts/live/blocks.d.ts.map +1 -0
- package/dist/artifacts/live/board.d.ts +6 -0
- package/dist/artifacts/live/board.d.ts.map +1 -1
- package/dist/artifacts/live/document.d.ts +12 -0
- package/dist/artifacts/live/document.d.ts.map +1 -1
- package/dist/artifacts/live/index.d.ts +2 -0
- package/dist/artifacts/live/index.d.ts.map +1 -1
- package/dist/artifacts/live/index.js +148 -44
- package/dist/artifacts/live/index.js.map +3 -3
- package/dist/artifacts/live/page.d.ts +49 -0
- package/dist/artifacts/live/page.d.ts.map +1 -0
- package/dist/artifacts/live/protocol.d.ts +5 -0
- package/dist/artifacts/live/protocol.d.ts.map +1 -1
- package/dist/artifacts/live/server.d.ts +2 -2
- package/dist/artifacts/live/server.d.ts.map +1 -1
- package/dist/artifacts/live/server.js +29 -24
- package/dist/artifacts/live/server.js.map +1 -1
- package/dist/artifacts/live/state.d.ts +4 -1
- package/dist/artifacts/live/state.d.ts.map +1 -1
- package/dist/artifacts/outline.d.ts +16 -0
- package/dist/artifacts/outline.d.ts.map +1 -1
- package/dist/artifacts/paper.d.ts +22 -0
- package/dist/artifacts/paper.d.ts.map +1 -0
- package/dist/artifacts/pdf-job.d.ts +9 -0
- package/dist/artifacts/pdf-job.d.ts.map +1 -0
- package/dist/artifacts/publish/fields.d.ts +25 -0
- package/dist/artifacts/publish/fields.d.ts.map +1 -0
- package/dist/artifacts/publish/index.d.ts +2 -1
- package/dist/artifacts/publish/index.d.ts.map +1 -1
- package/dist/artifacts/publish/index.js +32 -23
- package/dist/artifacts/publish/index.js.map +1 -1
- package/dist/artifacts/publish/merge.d.ts +7 -6
- package/dist/artifacts/publish/merge.d.ts.map +1 -1
- package/dist/artifacts/publish/pdf.d.ts +28 -0
- package/dist/artifacts/publish/pdf.d.ts.map +1 -0
- package/dist/artifacts/publish/previews.d.ts +12 -20
- package/dist/artifacts/publish/previews.d.ts.map +1 -1
- package/dist/artifacts/publish/publish.d.ts.map +1 -1
- package/dist/artifacts/publish/queries.d.ts +6 -1
- package/dist/artifacts/publish/queries.d.ts.map +1 -1
- package/dist/artifacts/publish/query-answers.d.ts +5 -2
- package/dist/artifacts/publish/query-answers.d.ts.map +1 -1
- package/dist/artifacts/publish/validate/document-html.d.ts +24 -0
- package/dist/artifacts/publish/validate/document-html.d.ts.map +1 -0
- package/dist/artifacts/publish/validate/document.d.ts +5 -3
- package/dist/artifacts/publish/validate/document.d.ts.map +1 -1
- package/dist/artifacts/queries.d.ts +16 -2
- package/dist/artifacts/queries.d.ts.map +1 -1
- package/dist/artifacts/run-query.d.ts.map +1 -1
- package/dist/auth/index.js +6 -6
- package/dist/authorization/event-visibility.d.ts.map +1 -1
- package/dist/authorization/index.js +2 -2
- package/dist/blob-storage/index.js +1 -1
- package/dist/bootstrap/index.js +50 -48
- package/dist/bootstrap/index.js.map +2 -2
- package/dist/calendar.d.ts +55 -0
- package/dist/calendar.d.ts.map +1 -0
- package/dist/calendar.js +19 -0
- package/dist/calendar.js.map +9 -0
- package/dist/{chunk-5a4a52tq.js → chunk-0pmpwn3g.js} +18 -2
- package/dist/chunk-0pmpwn3g.js.map +10 -0
- package/dist/{chunk-0k3r5kb3.js → chunk-394zjzjs.js} +20 -10
- package/dist/{chunk-0k3r5kb3.js.map → chunk-394zjzjs.js.map} +5 -5
- package/dist/{chunk-stmxh0hv.js → chunk-3neam1y5.js} +2 -2
- package/dist/{chunk-zeykm8my.js → chunk-3qtk0070.js} +16 -42
- package/dist/chunk-3qtk0070.js.map +14 -0
- package/dist/{chunk-p8pgnq8d.js → chunk-425ydk65.js} +5 -5
- package/dist/{chunk-p351afzm.js → chunk-5sswe5ej.js} +2 -2
- package/dist/{chunk-a6fjkcne.js → chunk-60662fyv.js} +54 -28
- package/dist/{chunk-a6fjkcne.js.map → chunk-60662fyv.js.map} +7 -6
- package/dist/{chunk-e0hnbb1m.js → chunk-61zptves.js} +1 -1
- package/dist/chunk-6hfbz4d0.js +98 -0
- package/dist/chunk-6hfbz4d0.js.map +10 -0
- package/dist/{chunk-3zagkr6w.js → chunk-7mhbs9yy.js} +4 -4
- package/dist/{chunk-3zagkr6w.js.map → chunk-7mhbs9yy.js.map} +1 -1
- package/dist/{chunk-gxwy4c3s.js → chunk-7r9mqpva.js} +570 -104
- package/dist/chunk-7r9mqpva.js.map +47 -0
- package/dist/{chunk-3014rfjz.js → chunk-88xeh6zx.js} +28 -8
- package/dist/{chunk-3014rfjz.js.map → chunk-88xeh6zx.js.map} +4 -4
- package/dist/{chunk-9nsjjd44.js → chunk-8tv3qd65.js} +2 -1
- package/dist/chunk-8tv3qd65.js.map +12 -0
- package/dist/chunk-90nqenq8.js +386 -0
- package/dist/chunk-90nqenq8.js.map +14 -0
- package/dist/{chunk-fe6r7yhg.js → chunk-92wrka15.js} +1 -1
- package/dist/{chunk-w1wq7gfr.js → chunk-9c9yknwt.js} +464 -29
- package/dist/{chunk-w1wq7gfr.js.map → chunk-9c9yknwt.js.map} +7 -7
- package/dist/{chunk-q9nkpr8k.js → chunk-9tpmfh3n.js} +1 -1
- package/dist/chunk-9wr3yajk.js.map +2 -2
- package/dist/{chunk-rtm1jq00.js → chunk-ats8y3d9.js} +1202 -246
- package/dist/{chunk-rtm1jq00.js.map → chunk-ats8y3d9.js.map} +16 -14
- package/dist/{chunk-td26wjr5.js → chunk-bcz9dxtf.js} +17 -47
- package/dist/chunk-bcz9dxtf.js.map +12 -0
- package/dist/chunk-bqr703h4.js +1799 -0
- package/dist/chunk-bqr703h4.js.map +13 -0
- package/dist/{chunk-sysnvjce.js → chunk-brhp9d97.js} +2 -2
- package/dist/{chunk-8a8k38tz.js → chunk-brybqw5k.js} +1 -1
- package/dist/{chunk-rsxb14an.js → chunk-bs1sd0e0.js} +12 -8
- package/dist/chunk-bs1sd0e0.js.map +18 -0
- package/dist/{chunk-eptrvnby.js → chunk-c29729me.js} +42 -3
- package/dist/chunk-c29729me.js.map +12 -0
- package/dist/{chunk-855w9nvw.js → chunk-cg7cygfj.js} +1 -1
- package/dist/chunk-dq3t5sr3.js +114 -0
- package/dist/chunk-dq3t5sr3.js.map +11 -0
- package/dist/{chunk-t24yktqr.js → chunk-dvgc56n2.js} +20 -4
- package/dist/{chunk-t24yktqr.js.map → chunk-dvgc56n2.js.map} +5 -5
- package/dist/{chunk-r2psmn42.js → chunk-eg6xqef7.js} +1 -1
- package/dist/{chunk-7kpqntgw.js → chunk-f05994as.js} +1 -1
- package/dist/{chunk-msyevpp3.js → chunk-fmgf9h5e.js} +38 -14
- package/dist/chunk-fmgf9h5e.js.map +22 -0
- package/dist/{chunk-b9qfh2ya.js → chunk-fzbhybya.js} +29 -2
- package/dist/chunk-fzbhybya.js.map +11 -0
- package/dist/{chunk-t0s7b3d1.js → chunk-gaj8djsw.js} +251 -6
- package/dist/chunk-gaj8djsw.js.map +13 -0
- package/dist/{chunk-2bn6813a.js → chunk-grt2j5vp.js} +2 -2
- package/dist/{chunk-s7xqfxs9.js → chunk-hkbks1xm.js} +3 -1
- package/dist/{chunk-s7xqfxs9.js.map → chunk-hkbks1xm.js.map} +3 -3
- package/dist/chunk-hn2r7z41.js.map +1 -1
- package/dist/{chunk-rtdrm592.js → chunk-htdzx40w.js} +2 -2
- package/dist/{chunk-bc3y6gff.js → chunk-jka26v8c.js} +1 -1
- package/dist/{chunk-yy914zfr.js → chunk-jt012fxq.js} +772 -98
- package/dist/chunk-jt012fxq.js.map +34 -0
- package/dist/{chunk-48c1z8nj.js → chunk-kft7mp7z.js} +28 -3
- package/dist/chunk-kft7mp7z.js.map +10 -0
- package/dist/chunk-mbwsgjn7.js +40 -0
- package/dist/chunk-mbwsgjn7.js.map +11 -0
- package/dist/{chunk-wa05txmk.js → chunk-n1hbwc6y.js} +51 -8
- package/dist/chunk-n1hbwc6y.js.map +12 -0
- package/dist/{chunk-n4zzaf6q.js → chunk-nxysqbt0.js} +4 -2
- package/dist/chunk-nxysqbt0.js.map +10 -0
- package/dist/{chunk-6ef4esq4.js → chunk-pqj8vff9.js} +4 -4
- package/dist/chunk-pvpq483h.js.map +2 -2
- package/dist/{chunk-mzx71snp.js → chunk-q7g9cqwt.js} +7 -2
- package/dist/{chunk-mzx71snp.js.map → chunk-q7g9cqwt.js.map} +3 -3
- package/dist/{chunk-n68vz95m.js → chunk-qbd282aa.js} +2 -2
- package/dist/{chunk-e91fmg6t.js → chunk-qsa7nw6f.js} +2 -1
- package/dist/{chunk-e91fmg6t.js.map → chunk-qsa7nw6f.js.map} +3 -3
- package/dist/{chunk-rsrc7vtw.js → chunk-s8xxef60.js} +240 -46
- package/dist/chunk-s8xxef60.js.map +50 -0
- package/dist/{chunk-r9rtavg9.js → chunk-t19wjmnc.js} +7 -7
- package/dist/{chunk-vzkxqf8h.js → chunk-tapdssb5.js} +50 -6
- package/dist/chunk-tapdssb5.js.map +23 -0
- package/dist/{chunk-dhkc9b23.js → chunk-v8a1qjzp.js} +1 -1
- package/dist/{chunk-hvbvq7p4.js → chunk-vs2s3p8n.js} +731 -10
- package/dist/chunk-vs2s3p8n.js.map +20 -0
- package/dist/chunk-vtjzwymr.js.map +2 -2
- package/dist/{chunk-8t2ynwg0.js → chunk-wzcjhv54.js} +31 -1
- package/dist/{chunk-8t2ynwg0.js.map → chunk-wzcjhv54.js.map} +3 -3
- package/dist/{chunk-8tqnsx3q.js → chunk-xavet0qs.js} +5 -3
- package/dist/{chunk-8tqnsx3q.js.map → chunk-xavet0qs.js.map} +3 -3
- package/dist/{chunk-8bns0y68.js → chunk-xf76csps.js} +5 -5
- package/dist/{chunk-cwdzcv37.js → chunk-xrmbhap8.js} +2 -2
- package/dist/{chunk-cwdzcv37.js.map → chunk-xrmbhap8.js.map} +2 -2
- package/dist/{chunk-f6ahf5gf.js → chunk-xxfj0rr2.js} +20 -5
- package/dist/chunk-xxfj0rr2.js.map +13 -0
- package/dist/{chunk-3hzhcfsv.js → chunk-y8fwm3z2.js} +2 -2
- package/dist/{chunk-3hzhcfsv.js.map → chunk-y8fwm3z2.js.map} +3 -3
- package/dist/{chunk-smnt672s.js → chunk-ygvay56w.js} +20 -4
- package/dist/chunk-ygvay56w.js.map +10 -0
- package/dist/{chunk-evj5jxz3.js → chunk-ykchk644.js} +63 -15
- package/dist/{chunk-evj5jxz3.js.map → chunk-ykchk644.js.map} +7 -7
- package/dist/{chunk-vepea5c3.js → chunk-ym1bqd98.js} +6 -6
- package/dist/{chunk-yv8hv4wq.js → chunk-z4jqb44a.js} +3 -1
- package/dist/chunk-z4jqb44a.js.map +10 -0
- package/dist/connectors/connection-handles.d.ts +9 -0
- package/dist/connectors/connection-handles.d.ts.map +1 -0
- package/dist/connectors/connections/authorizations.d.ts +9 -0
- package/dist/connectors/connections/authorizations.d.ts.map +1 -1
- package/dist/connectors/connections/capability.d.ts +11 -0
- package/dist/connectors/connections/capability.d.ts.map +1 -1
- package/dist/connectors/connections/events.d.ts +17 -0
- package/dist/connectors/connections/events.d.ts.map +1 -0
- package/dist/connectors/connections/internal.d.ts +2 -1
- package/dist/connectors/connections/internal.d.ts.map +1 -1
- package/dist/connectors/connections/internal.js +8 -4
- package/dist/connectors/connections/internal.js.map +1 -1
- package/dist/connectors/connections/runs.d.ts +3 -0
- package/dist/connectors/connections/runs.d.ts.map +1 -1
- package/dist/connectors/connections/service.d.ts +13 -1
- package/dist/connectors/connections/service.d.ts.map +1 -1
- package/dist/connectors/execution.d.ts +14 -2
- package/dist/connectors/execution.d.ts.map +1 -1
- package/dist/connectors/index.d.ts +1 -1
- package/dist/connectors/index.d.ts.map +1 -1
- package/dist/connectors/service.d.ts +5 -1
- package/dist/connectors/service.d.ts.map +1 -1
- package/dist/connectors/types.d.ts +22 -1
- package/dist/connectors/types.d.ts.map +1 -1
- package/dist/datasets/write.js +1 -1
- package/dist/deploy/index.d.ts +1 -1
- package/dist/deploy/index.d.ts.map +1 -1
- package/dist/deploy/internal.js +3 -2
- package/dist/deploy/internal.js.map +3 -3
- package/dist/deploy/services.d.ts.map +1 -1
- package/dist/deploy/types.d.ts +22 -2
- package/dist/deploy/types.d.ts.map +1 -1
- package/dist/events/definitions.d.ts +4 -0
- package/dist/events/definitions.d.ts.map +1 -1
- package/dist/events/execution.d.ts +8 -1
- package/dist/events/execution.d.ts.map +1 -1
- package/dist/events/index.d.ts +2 -2
- package/dist/events/index.d.ts.map +1 -1
- package/dist/events/index.js +3 -3
- package/dist/events/outbox-dispatcher.d.ts +7 -0
- package/dist/events/outbox-dispatcher.d.ts.map +1 -1
- package/dist/events/scope.d.ts +1 -0
- package/dist/events/scope.d.ts.map +1 -1
- package/dist/events/scope.js +1 -1
- package/dist/events/selectors/builder.d.ts +9 -1
- package/dist/events/selectors/builder.d.ts.map +1 -1
- package/dist/events/selectors/index.d.ts +2 -2
- package/dist/events/selectors/index.d.ts.map +1 -1
- package/dist/events/selectors/index.js +2 -2
- package/dist/events/selectors/predicate.d.ts.map +1 -1
- package/dist/events/selectors/types.d.ts +18 -3
- package/dist/events/selectors/types.d.ts.map +1 -1
- package/dist/events/types/artifacts.d.ts +7 -1
- package/dist/events/types/artifacts.d.ts.map +1 -1
- package/dist/events/types/connectors.d.ts +32 -0
- package/dist/events/types/connectors.d.ts.map +1 -0
- package/dist/events/types/index.d.ts +3 -1
- package/dist/events/types/index.d.ts.map +1 -1
- package/dist/events/types/syncs.d.ts +4 -0
- package/dist/events/types/syncs.d.ts.map +1 -1
- package/dist/execution/agent.js +43 -42
- package/dist/execution/agent.js.map +1 -1
- package/dist/execution/authorization.d.ts +5 -0
- package/dist/execution/authorization.d.ts.map +1 -1
- package/dist/execution/authorized-object-reader.d.ts +4 -0
- package/dist/execution/authorized-object-reader.d.ts.map +1 -1
- package/dist/execution/object-reader-ontology.d.ts +3 -0
- package/dist/execution/object-reader-ontology.d.ts.map +1 -1
- package/dist/execution/primitive.js +41 -40
- package/dist/execution/primitive.js.map +1 -1
- package/dist/execution/request.d.ts +1 -1
- package/dist/execution/request.d.ts.map +1 -1
- package/dist/execution/request.js +39 -38
- package/dist/execution/request.js.map +3 -3
- package/dist/execution/scopes.d.ts +8 -0
- package/dist/execution/scopes.d.ts.map +1 -1
- package/dist/execution/script.d.ts +7 -0
- package/dist/execution/script.d.ts.map +1 -0
- package/dist/execution/types.d.ts +16 -1
- package/dist/execution/types.d.ts.map +1 -1
- package/dist/http/api-routes.d.ts.map +1 -1
- package/dist/http/index.js +1 -1
- package/dist/index.d.ts +13 -12
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +74 -70
- package/dist/index.js.map +1 -1
- package/dist/lake-storage/index.js +1 -1
- package/dist/lineage/executors.d.ts +1 -1
- package/dist/lineage/executors.d.ts.map +1 -1
- package/dist/maintenance/index.js +2 -2
- package/dist/materialization/event-envelopes.d.ts +3 -3
- package/dist/materialization/event-envelopes.d.ts.map +1 -1
- package/dist/materialization/events.d.ts +6 -0
- package/dist/materialization/events.d.ts.map +1 -1
- package/dist/materialization/index.js +1 -1
- package/dist/materialization/model.d.ts +6 -0
- package/dist/materialization/model.d.ts.map +1 -1
- package/dist/materializer/index.js +24 -23
- package/dist/materializer/index.js.map +1 -1
- package/dist/materializer/projections/replace.d.ts.map +1 -1
- package/dist/materializer/projections/replacement-plan.d.ts +2 -0
- package/dist/materializer/projections/replacement-plan.d.ts.map +1 -1
- package/dist/materializer/shared/normalize.d.ts +1 -0
- package/dist/materializer/shared/normalize.d.ts.map +1 -1
- package/dist/models/audio/runtime.d.ts.map +1 -1
- package/dist/models/audio/types.d.ts +19 -0
- package/dist/models/audio/types.d.ts.map +1 -1
- package/dist/models/execution/index.js +22 -21
- package/dist/models/execution/index.js.map +1 -1
- package/dist/models/index.d.ts +1 -1
- package/dist/models/index.d.ts.map +1 -1
- package/dist/objects/index.js +41 -40
- package/dist/objects/index.js.map +1 -1
- package/dist/objects/query/executor.d.ts +3 -1
- package/dist/objects/query/executor.d.ts.map +1 -1
- package/dist/objects/query/explain.d.ts +3 -1
- package/dist/objects/query/explain.d.ts.map +1 -1
- package/dist/objects/query/index.d.ts +1 -1
- package/dist/objects/query/index.d.ts.map +1 -1
- package/dist/objects/query/index.js +21 -20
- package/dist/objects/query/index.js.map +1 -1
- package/dist/objects/query/link-query-clearance.d.ts +3 -0
- package/dist/objects/query/link-query-clearance.d.ts.map +1 -1
- package/dist/objects/query/links.d.ts +1 -1
- package/dist/objects/query/links.d.ts.map +1 -1
- package/dist/objects/query/validate.d.ts +17 -0
- package/dist/objects/query/validate.d.ts.map +1 -1
- package/dist/objects/sdk/runtime-query-executor.d.ts +1 -1
- package/dist/objects/sdk/runtime-query-executor.d.ts.map +1 -1
- package/dist/ontology/index.js +3 -3
- package/dist/ontology/internal.js +3 -3
- package/dist/pipelines/index.js +27 -26
- package/dist/pipelines/index.js.map +1 -1
- package/dist/projections/builders.d.ts +7 -1
- package/dist/projections/builders.d.ts.map +1 -1
- package/dist/projections/index.d.ts +1 -1
- package/dist/projections/index.d.ts.map +1 -1
- package/dist/projections/internal.js +22 -21
- package/dist/projections/internal.js.map +1 -1
- package/dist/projections/types.d.ts +10 -0
- package/dist/projections/types.d.ts.map +1 -1
- package/dist/projections/validation.d.ts.map +1 -1
- package/dist/queues/in-memory.d.ts +3 -2
- package/dist/queues/in-memory.d.ts.map +1 -1
- package/dist/queues/index.d.ts +1 -1
- package/dist/queues/index.d.ts.map +1 -1
- package/dist/queues/index.js +1 -1
- package/dist/queues/types.d.ts +40 -13
- package/dist/queues/types.d.ts.map +1 -1
- package/dist/runtime/host.d.ts +13 -0
- package/dist/runtime/host.d.ts.map +1 -1
- package/dist/runtime/internal.d.ts +1 -0
- package/dist/runtime/internal.d.ts.map +1 -1
- package/dist/runtime/internal.js +47 -25
- package/dist/runtime/internal.js.map +4 -3
- package/dist/runtime/locale.d.ts +0 -2
- package/dist/runtime/locale.d.ts.map +1 -1
- package/dist/runtime/resolve-definitions.d.ts +1 -1
- package/dist/runtime/resolve-definitions.d.ts.map +1 -1
- package/dist/runtime/script.d.ts +39 -0
- package/dist/runtime/script.d.ts.map +1 -0
- package/dist/runtime/sixb.d.ts +2 -2
- package/dist/runtime/sixb.d.ts.map +1 -1
- package/dist/sandboxes/auth.d.ts +26 -4
- package/dist/sandboxes/auth.d.ts.map +1 -1
- package/dist/sandboxes/index.d.ts +3 -1
- package/dist/sandboxes/index.d.ts.map +1 -1
- package/dist/sandboxes/index.js +5 -5
- package/dist/schedules/builders.d.ts.map +1 -1
- package/dist/schedules/index.js +3 -3
- package/dist/schedules/runtime.d.ts.map +1 -1
- package/dist/schedules/validation.d.ts +2 -0
- package/dist/schedules/validation.d.ts.map +1 -1
- package/dist/security/view-conditions.d.ts.map +1 -1
- package/dist/shares/internal.js +19 -18
- package/dist/shares/internal.js.map +2 -2
- package/dist/storage/agents/errors.d.ts +1 -1
- package/dist/storage/agents/errors.d.ts.map +1 -1
- package/dist/storage/agents/in-memory.d.ts +43 -1
- package/dist/storage/agents/in-memory.d.ts.map +1 -1
- package/dist/storage/agents/index.d.ts +2 -2
- package/dist/storage/agents/index.d.ts.map +1 -1
- package/dist/storage/agents/provider.d.ts +54 -11
- package/dist/storage/agents/provider.d.ts.map +1 -1
- package/dist/storage/agents/provider.js +41 -5
- package/dist/storage/agents/provider.js.map +1 -1
- package/dist/storage/agents/types.d.ts +291 -3
- package/dist/storage/agents/types.d.ts.map +1 -1
- package/dist/storage/ai-cost/analytics.d.ts +3 -2
- package/dist/storage/ai-cost/analytics.d.ts.map +1 -1
- package/dist/storage/ai-cost/provider.js +4 -3
- package/dist/storage/ai-cost/provider.js.map +1 -1
- package/dist/storage/ai-cost/types.d.ts +5 -1
- package/dist/storage/ai-cost/types.d.ts.map +1 -1
- package/dist/storage/artifacts/in-memory.d.ts +7 -1
- package/dist/storage/artifacts/in-memory.d.ts.map +1 -1
- package/dist/storage/artifacts/index.d.ts +1 -1
- package/dist/storage/artifacts/index.d.ts.map +1 -1
- package/dist/storage/artifacts/record.d.ts +5 -2
- package/dist/storage/artifacts/record.d.ts.map +1 -1
- package/dist/storage/artifacts/types.d.ts +41 -0
- package/dist/storage/artifacts/types.d.ts.map +1 -1
- package/dist/storage/executions/provider.d.ts +3 -3
- package/dist/storage/executions/provider.d.ts.map +1 -1
- package/dist/storage/executions/provider.js +1 -1
- package/dist/storage/executions/types.d.ts +6 -0
- package/dist/storage/executions/types.d.ts.map +1 -1
- package/dist/storage/executions/validation.d.ts.map +1 -1
- package/dist/storage/file-upload-sessions/provider.js +7 -7
- package/dist/storage/index.d.ts +4 -4
- package/dist/storage/index.d.ts.map +1 -1
- package/dist/storage/index.js +30 -25
- package/dist/storage/index.js.map +1 -1
- package/dist/storage/internal.d.ts +1 -1
- package/dist/storage/internal.d.ts.map +1 -1
- package/dist/storage/internal.js +12 -10
- package/dist/storage/internal.js.map +2 -2
- package/dist/storage/ontology/in-memory/replacement-plans.d.ts +2 -0
- package/dist/storage/ontology/in-memory/replacement-plans.d.ts.map +1 -1
- package/dist/storage/ontology/provider.js +1 -1
- package/dist/storage/ontology/replacement-plans.d.ts +8 -0
- package/dist/storage/ontology/replacement-plans.d.ts.map +1 -1
- package/dist/storage/operation-scope.d.ts.map +1 -1
- package/dist/storage/operation-scope.js +1 -1
- package/dist/storage/sync-runs/idempotency.d.ts.map +1 -1
- package/dist/storage/sync-runs/in-memory.d.ts +2 -1
- package/dist/storage/sync-runs/in-memory.d.ts.map +1 -1
- package/dist/storage/sync-runs/index.d.ts +1 -1
- package/dist/storage/sync-runs/index.d.ts.map +1 -1
- package/dist/storage/sync-runs/types.d.ts +27 -2
- package/dist/storage/sync-runs/types.d.ts.map +1 -1
- package/dist/storage/workflow-runs/provider.js +7 -7
- package/dist/syncs/accounts.d.ts +36 -0
- package/dist/syncs/accounts.d.ts.map +1 -0
- package/dist/syncs/builders.d.ts.map +1 -1
- package/dist/syncs/connections.d.ts +36 -0
- package/dist/syncs/connections.d.ts.map +1 -0
- package/dist/syncs/execution.d.ts +14 -4
- package/dist/syncs/execution.d.ts.map +1 -1
- package/dist/syncs/index.d.ts +2 -1
- package/dist/syncs/index.d.ts.map +1 -1
- package/dist/syncs/index.js +28 -27
- package/dist/syncs/index.js.map +1 -1
- package/dist/syncs/request.d.ts +16 -2
- package/dist/syncs/request.d.ts.map +1 -1
- package/dist/syncs/run-dispatch.d.ts +14 -2
- package/dist/syncs/run-dispatch.d.ts.map +1 -1
- package/dist/testing/agent-approval-storage-contract.d.ts.map +1 -1
- package/dist/testing/agent-execution.d.ts +3 -0
- package/dist/testing/agent-execution.d.ts.map +1 -1
- package/dist/testing/agent-inbox-storage-contract.d.ts +15 -0
- package/dist/testing/agent-inbox-storage-contract.d.ts.map +1 -0
- package/dist/testing/agent-storage-contract.d.ts.map +1 -1
- package/dist/testing/ai-cost-storage-contract.d.ts.map +1 -1
- package/dist/testing/artifact-storage-contract.d.ts.map +1 -1
- package/dist/testing/execution-storage-contract.d.ts.map +1 -1
- package/dist/testing/index.d.ts +1 -0
- package/dist/testing/index.d.ts.map +1 -1
- package/dist/testing/index.js +6589 -4627
- package/dist/testing/index.js.map +13 -12
- package/dist/testing/materializer-storage-contract.d.ts.map +1 -1
- package/dist/testing/queues-contract.d.ts.map +1 -1
- package/dist/testing/run-claim-storage-contract.d.ts.map +1 -1
- package/dist/webhooks/connections.d.ts +3 -4
- package/dist/webhooks/connections.d.ts.map +1 -1
- package/dist/webhooks/index.d.ts +1 -1
- package/dist/webhooks/index.d.ts.map +1 -1
- package/dist/webhooks/internal.js +22 -54
- package/dist/webhooks/internal.js.map +3 -3
- package/dist/webhooks/types.d.ts +2 -11
- package/dist/webhooks/types.d.ts.map +1 -1
- package/dist/workers/index.js +66 -13
- package/dist/workers/index.js.map +4 -4
- package/dist/workers/queue-worker.d.ts +5 -0
- package/dist/workers/queue-worker.d.ts.map +1 -1
- package/dist/workers/queued-run-dispatch.d.ts.map +1 -1
- package/dist/workers/worker.d.ts +8 -0
- package/dist/workers/worker.d.ts.map +1 -1
- package/dist/workflows/index.js +50 -48
- package/dist/workflows/index.js.map +1 -1
- package/package.json +12 -1
- package/src/actions/validation.ts +3 -1
- package/src/agents/README.md +6 -2
- package/src/agents/children.ts +6 -0
- package/src/agents/errors.ts +3 -0
- package/src/agents/execution.ts +331 -43
- package/src/agents/ids.ts +5 -0
- package/src/agents/index.ts +22 -4
- package/src/agents/model-routing.ts +25 -9
- package/src/agents/queued-turn.ts +46 -0
- package/src/agents/request.ts +1444 -210
- package/src/agents/run-after-finish.ts +259 -2
- package/src/agents/run-artifacts.ts +3 -93
- package/src/agents/run-events.ts +256 -34
- package/src/agents/run-session-children.ts +13 -2
- package/src/agents/run-session-http.ts +9 -2
- package/src/agents/run-session-serve.ts +2 -8
- package/src/agents/run-session.ts +142 -3
- package/src/agents/run-turn.ts +148 -23
- package/src/agents/streams/index.ts +3 -0
- package/src/agents/streams/internal.ts +12 -0
- package/src/agents/streams/protocol.ts +109 -1
- package/src/agents/streams/steps.ts +131 -0
- package/src/agents/thread-access.ts +57 -2
- package/src/agents/turn-answered.ts +31 -0
- package/src/agents/validation.ts +2 -0
- package/src/artifacts/canvas-display.ts +4 -6
- package/src/artifacts/comments.ts +70 -17
- package/src/artifacts/document-fill.ts +103 -0
- package/src/artifacts/errors.ts +2 -0
- package/src/artifacts/events.ts +4 -1
- package/src/artifacts/execution.ts +265 -31
- package/src/artifacts/frames/assets.ts +42 -7
- package/src/artifacts/frames/document-data.ts +353 -0
- package/src/artifacts/frames/entries.ts +22 -16
- package/src/artifacts/frames/grants.ts +2 -2
- package/src/artifacts/frames/index.ts +3 -0
- package/src/artifacts/frames/kit.ts +102 -0
- package/src/artifacts/frames/protocol.ts +12 -1
- package/src/artifacts/frames/runtime.ts +413 -6
- package/src/artifacts/index.ts +3 -0
- package/src/artifacts/live/blocks.ts +889 -0
- package/src/artifacts/live/board.ts +195 -42
- package/src/artifacts/live/document.ts +170 -5
- package/src/artifacts/live/index.ts +7 -0
- package/src/artifacts/live/page.ts +807 -0
- package/src/artifacts/live/protocol.ts +5 -0
- package/src/artifacts/live/server.ts +2 -2
- package/src/artifacts/live/state.ts +9 -4
- package/src/artifacts/outline.ts +17 -0
- package/src/artifacts/paper.ts +173 -0
- package/src/artifacts/pdf-job.ts +11 -0
- package/src/artifacts/publish/fields.ts +177 -0
- package/src/artifacts/publish/index.ts +6 -1
- package/src/artifacts/publish/merge.ts +28 -15
- package/src/artifacts/publish/pdf.ts +82 -0
- package/src/artifacts/publish/previews.ts +24 -34
- package/src/artifacts/publish/publish.ts +26 -3
- package/src/artifacts/publish/queries.ts +20 -4
- package/src/artifacts/publish/query-answers.ts +14 -3
- package/src/artifacts/publish/validate/document-html.ts +245 -0
- package/src/artifacts/publish/validate/document.ts +34 -3
- package/src/artifacts/queries.ts +59 -13
- package/src/artifacts/run-query.ts +5 -2
- package/src/authorization/event-visibility.ts +13 -0
- package/src/calendar.ts +195 -0
- package/src/connectors/connection-handles.ts +71 -0
- package/src/connectors/connections/authorizations.ts +50 -2
- package/src/connectors/connections/capability.ts +40 -0
- package/src/connectors/connections/events.ts +57 -0
- package/src/connectors/connections/internal.ts +3 -0
- package/src/connectors/connections/runs.ts +5 -0
- package/src/connectors/connections/service.ts +93 -6
- package/src/connectors/execution.ts +35 -8
- package/src/connectors/index.ts +3 -0
- package/src/connectors/service.ts +23 -0
- package/src/connectors/types.ts +29 -1
- package/src/deploy/index.ts +1 -0
- package/src/deploy/services.ts +1 -0
- package/src/deploy/types.ts +30 -2
- package/src/events/definitions.ts +14 -0
- package/src/events/execution.ts +51 -4
- package/src/events/index.ts +8 -0
- package/src/events/outbox-dispatcher.ts +12 -2
- package/src/events/scope.ts +3 -0
- package/src/events/selectors/builder.ts +49 -0
- package/src/events/selectors/index.ts +5 -0
- package/src/events/selectors/predicate.ts +2 -0
- package/src/events/selectors/types.ts +30 -1
- package/src/events/types/artifacts.ts +7 -1
- package/src/events/types/connectors.ts +36 -0
- package/src/events/types/index.ts +7 -0
- package/src/events/types/syncs.ts +4 -0
- package/src/execution/authorization.ts +45 -0
- package/src/execution/authorized-object-reader.ts +33 -5
- package/src/execution/durable.ts +2 -0
- package/src/execution/object-reader-ontology.ts +6 -0
- package/src/execution/request.ts +1 -0
- package/src/execution/scopes.ts +24 -0
- package/src/execution/script.ts +27 -0
- package/src/execution/types.ts +7 -1
- package/src/http/api-routes.ts +33 -0
- package/src/index.ts +39 -4
- package/src/lineage/executors.ts +3 -1
- package/src/materialization/event-envelopes.ts +10 -5
- package/src/materialization/events.ts +2 -0
- package/src/materialization/model.ts +6 -0
- package/src/materializer/README.md +10 -0
- package/src/materializer/projections/replace.ts +42 -1
- package/src/materializer/projections/replacement-plan.ts +44 -4
- package/src/materializer/shared/normalize.ts +4 -0
- package/src/models/audio/runtime.ts +57 -14
- package/src/models/audio/types.ts +20 -0
- package/src/models/index.ts +1 -0
- package/src/objects/query/executor.ts +4 -0
- package/src/objects/query/explain.ts +5 -0
- package/src/objects/query/index.ts +1 -0
- package/src/objects/query/link-query-clearance.ts +4 -1
- package/src/objects/query/links.ts +5 -1
- package/src/objects/query/validate.ts +33 -1
- package/src/objects/sdk/runtime-query-executor.ts +7 -3
- package/src/projections/builders.ts +20 -0
- package/src/projections/index.ts +1 -0
- package/src/projections/registry.ts +1 -0
- package/src/projections/revision.ts +2 -0
- package/src/projections/types.ts +11 -0
- package/src/projections/validation.ts +6 -0
- package/src/queues/in-memory.ts +5 -0
- package/src/queues/index.ts +3 -1
- package/src/queues/types.ts +45 -14
- package/src/runtime/host.ts +125 -11
- package/src/runtime/internal.ts +1 -0
- package/src/runtime/locale.ts +0 -10
- package/src/runtime/resolve-definitions.ts +4 -1
- package/src/runtime/script.ts +62 -0
- package/src/runtime/sixb.ts +15 -5
- package/src/sandboxes/README.md +3 -1
- package/src/sandboxes/auth.ts +32 -4
- package/src/sandboxes/index.ts +15 -1
- package/src/schedules/builders.ts +4 -1
- package/src/schedules/runtime.ts +3 -0
- package/src/schedules/validation.ts +20 -2
- package/src/security/view-conditions.ts +2 -1
- package/src/storage/agents/errors.ts +1 -0
- package/src/storage/agents/in-memory.ts +500 -7
- package/src/storage/agents/index.ts +26 -0
- package/src/storage/agents/provider.ts +454 -15
- package/src/storage/agents/types.ts +315 -3
- package/src/storage/ai-cost/analytics.ts +22 -43
- package/src/storage/ai-cost/types.ts +5 -1
- package/src/storage/artifacts/in-memory.ts +52 -6
- package/src/storage/artifacts/index.ts +2 -0
- package/src/storage/artifacts/record.ts +33 -4
- package/src/storage/artifacts/types.ts +44 -0
- package/src/storage/executions/provider.ts +22 -2
- package/src/storage/executions/types.ts +2 -0
- package/src/storage/executions/validation.ts +27 -0
- package/src/storage/index.ts +29 -0
- package/src/storage/internal.ts +1 -0
- package/src/storage/ontology/in-memory/replacement-plans.ts +22 -0
- package/src/storage/ontology/replacement-plans.ts +6 -0
- package/src/storage/operation-scope.ts +2 -0
- package/src/storage/sync-runs/idempotency.ts +1 -0
- package/src/storage/sync-runs/in-memory.ts +43 -1
- package/src/storage/sync-runs/index.ts +1 -0
- package/src/storage/sync-runs/types.ts +30 -1
- package/src/syncs/accounts.ts +85 -0
- package/src/syncs/builders.ts +18 -1
- package/src/syncs/connections.ts +123 -0
- package/src/syncs/execution.ts +64 -22
- package/src/syncs/index.ts +3 -0
- package/src/syncs/request.ts +81 -23
- package/src/syncs/run-dispatch.ts +69 -7
- package/src/testing/agent-approval-storage-contract.ts +123 -0
- package/src/testing/agent-execution.ts +45 -2
- package/src/testing/agent-inbox-storage-contract.ts +874 -0
- package/src/testing/agent-storage-contract.ts +965 -103
- package/src/testing/ai-cost-storage-contract.ts +80 -0
- package/src/testing/artifact-storage-contract.ts +201 -4
- package/src/testing/execution-storage-contract.ts +31 -0
- package/src/testing/index.ts +5 -0
- package/src/testing/materializer-storage-contract.ts +139 -1
- package/src/testing/queues-contract.ts +22 -0
- package/src/testing/run-claim-storage-contract.ts +116 -0
- package/src/webhooks/connections.ts +9 -50
- package/src/webhooks/index.ts +0 -2
- package/src/webhooks/types.ts +2 -13
- package/src/workers/README.md +4 -1
- package/src/workers/lost-runs.ts +1 -0
- package/src/workers/queue-worker.ts +16 -5
- package/src/workers/queued-run-dispatch.ts +8 -1
- package/src/workers/worker.ts +67 -7
- package/dist/chunk-3z1vxzcm.js +0 -234
- package/dist/chunk-3z1vxzcm.js.map +0 -12
- package/dist/chunk-48c1z8nj.js.map +0 -10
- package/dist/chunk-58geavnf.js +0 -29
- package/dist/chunk-58geavnf.js.map +0 -10
- package/dist/chunk-5a4a52tq.js.map +0 -10
- package/dist/chunk-9nsjjd44.js.map +0 -12
- package/dist/chunk-b9qfh2ya.js.map +0 -11
- package/dist/chunk-eptrvnby.js.map +0 -12
- package/dist/chunk-f6ahf5gf.js.map +0 -13
- package/dist/chunk-gxwy4c3s.js.map +0 -47
- package/dist/chunk-hvbvq7p4.js.map +0 -18
- package/dist/chunk-m2jerfef.js +0 -474
- package/dist/chunk-m2jerfef.js.map +0 -11
- package/dist/chunk-msyevpp3.js.map +0 -22
- package/dist/chunk-n4zzaf6q.js.map +0 -10
- package/dist/chunk-rsrc7vtw.js.map +0 -49
- package/dist/chunk-rsxb14an.js.map +0 -18
- package/dist/chunk-smnt672s.js.map +0 -10
- package/dist/chunk-t0s7b3d1.js.map +0 -13
- package/dist/chunk-td26wjr5.js.map +0 -13
- package/dist/chunk-vzkxqf8h.js.map +0 -23
- package/dist/chunk-wa05txmk.js.map +0 -11
- package/dist/chunk-yv8hv4wq.js.map +0 -10
- package/dist/chunk-yy914zfr.js.map +0 -30
- package/dist/chunk-zeykm8my.js.map +0 -14
- /package/dist/{chunk-stmxh0hv.js.map → chunk-3neam1y5.js.map} +0 -0
- /package/dist/{chunk-p8pgnq8d.js.map → chunk-425ydk65.js.map} +0 -0
- /package/dist/{chunk-p351afzm.js.map → chunk-5sswe5ej.js.map} +0 -0
- /package/dist/{chunk-e0hnbb1m.js.map → chunk-61zptves.js.map} +0 -0
- /package/dist/{chunk-fe6r7yhg.js.map → chunk-92wrka15.js.map} +0 -0
- /package/dist/{chunk-q9nkpr8k.js.map → chunk-9tpmfh3n.js.map} +0 -0
- /package/dist/{chunk-sysnvjce.js.map → chunk-brhp9d97.js.map} +0 -0
- /package/dist/{chunk-8a8k38tz.js.map → chunk-brybqw5k.js.map} +0 -0
- /package/dist/{chunk-855w9nvw.js.map → chunk-cg7cygfj.js.map} +0 -0
- /package/dist/{chunk-r2psmn42.js.map → chunk-eg6xqef7.js.map} +0 -0
- /package/dist/{chunk-7kpqntgw.js.map → chunk-f05994as.js.map} +0 -0
- /package/dist/{chunk-2bn6813a.js.map → chunk-grt2j5vp.js.map} +0 -0
- /package/dist/{chunk-rtdrm592.js.map → chunk-htdzx40w.js.map} +0 -0
- /package/dist/{chunk-bc3y6gff.js.map → chunk-jka26v8c.js.map} +0 -0
- /package/dist/{chunk-6ef4esq4.js.map → chunk-pqj8vff9.js.map} +0 -0
- /package/dist/{chunk-n68vz95m.js.map → chunk-qbd282aa.js.map} +0 -0
- /package/dist/{chunk-r9rtavg9.js.map → chunk-t19wjmnc.js.map} +0 -0
- /package/dist/{chunk-dhkc9b23.js.map → chunk-v8a1qjzp.js.map} +0 -0
- /package/dist/{chunk-8bns0y68.js.map → chunk-xf76csps.js.map} +0 -0
- /package/dist/{chunk-vepea5c3.js.map → chunk-ym1bqd98.js.map} +0 -0
|
@@ -0,0 +1,1799 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import {
|
|
3
|
+
CANVAS_FILE2,
|
|
4
|
+
parseCanvas2,
|
|
5
|
+
formatCanvas2
|
|
6
|
+
} from "./chunk-bz5bnjjt.js";
|
|
7
|
+
|
|
8
|
+
// src/artifacts/live/document.ts
|
|
9
|
+
import * as Y3 from "yjs";
|
|
10
|
+
|
|
11
|
+
// src/artifacts/live/blocks.ts
|
|
12
|
+
import { fromMarkdown } from "mdast-util-from-markdown";
|
|
13
|
+
import { gfmFromMarkdown, gfmToMarkdown } from "mdast-util-gfm";
|
|
14
|
+
import { toMarkdown } from "mdast-util-to-markdown";
|
|
15
|
+
import { gfm } from "micromark-extension-gfm";
|
|
16
|
+
import * as Y from "yjs";
|
|
17
|
+
|
|
18
|
+
// src/artifacts/live/diff.ts
|
|
19
|
+
var MAX_EDITS = 1000;
|
|
20
|
+
function diffSequences(a, b) {
|
|
21
|
+
let start = 0;
|
|
22
|
+
while (start < a.length && start < b.length && a[start] === b[start])
|
|
23
|
+
start += 1;
|
|
24
|
+
let aEnd = a.length;
|
|
25
|
+
let bEnd = b.length;
|
|
26
|
+
while (aEnd > start && bEnd > start && a[aEnd - 1] === b[bEnd - 1]) {
|
|
27
|
+
aEnd -= 1;
|
|
28
|
+
bEnd -= 1;
|
|
29
|
+
}
|
|
30
|
+
if (start === aEnd && start === bEnd)
|
|
31
|
+
return [];
|
|
32
|
+
if (start === aEnd || start === bEnd)
|
|
33
|
+
return [{ aStart: start, aEnd, bStart: start, bEnd }];
|
|
34
|
+
return shortestEdits(a.slice(start, aEnd), b.slice(start, bEnd), start) ?? [
|
|
35
|
+
{ aStart: start, aEnd, bStart: start, bEnd }
|
|
36
|
+
];
|
|
37
|
+
}
|
|
38
|
+
function reached(frontier, k) {
|
|
39
|
+
return frontier.x[k + frontier.d] ?? -1;
|
|
40
|
+
}
|
|
41
|
+
function fromAbove(previous, k, d) {
|
|
42
|
+
if (!previous)
|
|
43
|
+
return true;
|
|
44
|
+
return k === -d || k !== d && reached(previous, k - 1) < reached(previous, k + 1);
|
|
45
|
+
}
|
|
46
|
+
function shortestEdits(a, b, shift) {
|
|
47
|
+
const n = a.length;
|
|
48
|
+
const m = b.length;
|
|
49
|
+
const frontiers = [];
|
|
50
|
+
for (let d = 0;d <= Math.min(n + m, MAX_EDITS); d += 1) {
|
|
51
|
+
const previous = frontiers.at(-1);
|
|
52
|
+
const frontier = { d, x: new Int32Array(2 * d + 1) };
|
|
53
|
+
for (let k = -d;k <= d; k += 2) {
|
|
54
|
+
let x = !previous ? 0 : fromAbove(previous, k, d) ? reached(previous, k + 1) : reached(previous, k - 1) + 1;
|
|
55
|
+
let y = x - k;
|
|
56
|
+
while (x < n && y < m && a[x] === b[y]) {
|
|
57
|
+
x += 1;
|
|
58
|
+
y += 1;
|
|
59
|
+
}
|
|
60
|
+
frontier.x[k + d] = x;
|
|
61
|
+
if (x >= n && y >= m) {
|
|
62
|
+
frontiers.push(frontier);
|
|
63
|
+
return backtrack(frontiers, n, m, shift);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
frontiers.push(frontier);
|
|
67
|
+
}
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
70
|
+
function backtrack(frontiers, n, m, shift) {
|
|
71
|
+
const edits = [];
|
|
72
|
+
let x = n;
|
|
73
|
+
let y = m;
|
|
74
|
+
for (let d = frontiers.length - 1;d > 0; d -= 1) {
|
|
75
|
+
const previous = frontiers[d - 1];
|
|
76
|
+
const k = x - y;
|
|
77
|
+
const down = fromAbove(previous, k, d);
|
|
78
|
+
const previousK = down ? k + 1 : k - 1;
|
|
79
|
+
const px = previous ? reached(previous, previousK) : 0;
|
|
80
|
+
const py = px - previousK;
|
|
81
|
+
const ex = down ? px : px + 1;
|
|
82
|
+
const ey = down ? py + 1 : py;
|
|
83
|
+
edits.push({ aStart: shift + px, aEnd: shift + ex, bStart: shift + py, bEnd: shift + ey });
|
|
84
|
+
x = px;
|
|
85
|
+
y = py;
|
|
86
|
+
}
|
|
87
|
+
const hunks = [];
|
|
88
|
+
for (const edit of edits.reverse()) {
|
|
89
|
+
const last = hunks.at(-1);
|
|
90
|
+
if (last && last.aEnd === edit.aStart && last.bEnd === edit.bStart) {
|
|
91
|
+
hunks[hunks.length - 1] = { ...last, aEnd: edit.aEnd, bEnd: edit.bEnd };
|
|
92
|
+
} else {
|
|
93
|
+
hunks.push(edit);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return hunks;
|
|
97
|
+
}
|
|
98
|
+
function textLines(text) {
|
|
99
|
+
return text.match(/[^\n]*\n|[^\n]+$/g) ?? [];
|
|
100
|
+
}
|
|
101
|
+
function diffText(from, to) {
|
|
102
|
+
if (from === to)
|
|
103
|
+
return [];
|
|
104
|
+
const a = textLines(from);
|
|
105
|
+
const b = textLines(to);
|
|
106
|
+
const aOffsets = offsetsOf(a);
|
|
107
|
+
const bOffsets = offsetsOf(b);
|
|
108
|
+
return diffSequences(a, b).map((hunk) => {
|
|
109
|
+
let start = aOffsets[hunk.aStart] ?? 0;
|
|
110
|
+
let end = aOffsets[hunk.aEnd] ?? from.length;
|
|
111
|
+
let insertStart = bOffsets[hunk.bStart] ?? 0;
|
|
112
|
+
let insertEnd = bOffsets[hunk.bEnd] ?? to.length;
|
|
113
|
+
while (start < end && insertStart < insertEnd && from[start] === to[insertStart]) {
|
|
114
|
+
start += 1;
|
|
115
|
+
insertStart += 1;
|
|
116
|
+
}
|
|
117
|
+
while (start < end && insertStart < insertEnd && from[end - 1] === to[insertEnd - 1]) {
|
|
118
|
+
end -= 1;
|
|
119
|
+
insertEnd -= 1;
|
|
120
|
+
}
|
|
121
|
+
return { start, end, insert: to.slice(insertStart, insertEnd) };
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
function offsetsOf(lines) {
|
|
125
|
+
const offsets = [0];
|
|
126
|
+
for (const line of lines)
|
|
127
|
+
offsets.push((offsets.at(-1) ?? 0) + line.length);
|
|
128
|
+
return offsets;
|
|
129
|
+
}
|
|
130
|
+
function mergeText(base, ours, theirs) {
|
|
131
|
+
if (ours === theirs || theirs === base)
|
|
132
|
+
return ours;
|
|
133
|
+
if (ours === base)
|
|
134
|
+
return theirs;
|
|
135
|
+
return mergeSequences(textLines(base), textLines(ours), textLines(theirs), (b, o, t) => [
|
|
136
|
+
mergeSequences([...b.join("")], [...o.join("")], [...t.join("")], interleave).join("")
|
|
137
|
+
]).join("");
|
|
138
|
+
}
|
|
139
|
+
function mergeSequences(base, ours, theirs, conflict) {
|
|
140
|
+
const oursHunks = diffSequences(base, ours);
|
|
141
|
+
const theirsHunks = diffSequences(base, theirs);
|
|
142
|
+
const merged = [];
|
|
143
|
+
let at = 0;
|
|
144
|
+
let i = 0;
|
|
145
|
+
let j = 0;
|
|
146
|
+
while (i < oursHunks.length || j < theirsHunks.length) {
|
|
147
|
+
const start = Math.min(oursHunks[i]?.aStart ?? Infinity, theirsHunks[j]?.aStart ?? Infinity);
|
|
148
|
+
let end = start;
|
|
149
|
+
const regionOurs = [];
|
|
150
|
+
const regionTheirs = [];
|
|
151
|
+
for (;; ) {
|
|
152
|
+
const o = oursHunks[i];
|
|
153
|
+
if (o && (o.aStart < end || o.aStart === start)) {
|
|
154
|
+
regionOurs.push(o);
|
|
155
|
+
end = Math.max(end, o.aEnd);
|
|
156
|
+
i += 1;
|
|
157
|
+
continue;
|
|
158
|
+
}
|
|
159
|
+
const t = theirsHunks[j];
|
|
160
|
+
if (t && (t.aStart < end || t.aStart === start)) {
|
|
161
|
+
regionTheirs.push(t);
|
|
162
|
+
end = Math.max(end, t.aEnd);
|
|
163
|
+
j += 1;
|
|
164
|
+
continue;
|
|
165
|
+
}
|
|
166
|
+
break;
|
|
167
|
+
}
|
|
168
|
+
merged.push(...base.slice(at, start));
|
|
169
|
+
const oursRun = sideOf(base, ours, regionOurs, start, end);
|
|
170
|
+
const theirsRun = sideOf(base, theirs, regionTheirs, start, end);
|
|
171
|
+
if (regionTheirs.length === 0 || sameRun(oursRun, theirsRun))
|
|
172
|
+
merged.push(...oursRun);
|
|
173
|
+
else if (regionOurs.length === 0)
|
|
174
|
+
merged.push(...theirsRun);
|
|
175
|
+
else
|
|
176
|
+
merged.push(...conflict(base.slice(start, end), oursRun, theirsRun));
|
|
177
|
+
at = end;
|
|
178
|
+
}
|
|
179
|
+
merged.push(...base.slice(at));
|
|
180
|
+
return merged;
|
|
181
|
+
}
|
|
182
|
+
function interleave(base, ours, theirs) {
|
|
183
|
+
const deleted = new Set;
|
|
184
|
+
const inserted = new Map;
|
|
185
|
+
for (const [side, run] of [
|
|
186
|
+
["ours", ours],
|
|
187
|
+
["theirs", theirs]
|
|
188
|
+
]) {
|
|
189
|
+
for (const hunk of diffSequences(base, run)) {
|
|
190
|
+
for (let index = hunk.aStart;index < hunk.aEnd; index += 1)
|
|
191
|
+
deleted.add(index);
|
|
192
|
+
const at = inserted.get(hunk.aStart) ?? { ours: [], theirs: [] };
|
|
193
|
+
at[side].push(...run.slice(hunk.bStart, hunk.bEnd));
|
|
194
|
+
inserted.set(hunk.aStart, at);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
const merged = [];
|
|
198
|
+
for (let index = 0;index <= base.length; index += 1) {
|
|
199
|
+
const at = inserted.get(index);
|
|
200
|
+
if (at) {
|
|
201
|
+
merged.push(...at.ours);
|
|
202
|
+
if (!sameRun(at.ours, at.theirs))
|
|
203
|
+
merged.push(...at.theirs);
|
|
204
|
+
}
|
|
205
|
+
if (index < base.length && !deleted.has(index))
|
|
206
|
+
merged.push(base[index]);
|
|
207
|
+
}
|
|
208
|
+
return merged;
|
|
209
|
+
}
|
|
210
|
+
function sideOf(base, side, hunks, start, end) {
|
|
211
|
+
const first = hunks[0];
|
|
212
|
+
const last = hunks.at(-1);
|
|
213
|
+
if (!first || !last)
|
|
214
|
+
return base.slice(start, end);
|
|
215
|
+
const sideStart = first.bStart - (first.aStart - start);
|
|
216
|
+
const sideEnd = last.bEnd + (end - last.aEnd);
|
|
217
|
+
return side.slice(sideStart, sideEnd);
|
|
218
|
+
}
|
|
219
|
+
function sameRun(left, right) {
|
|
220
|
+
return left.length === right.length && left.every((value, index) => value === right[index]);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
// src/artifacts/live/blocks.ts
|
|
224
|
+
var CALLOUT = /^\s*\[!(note|tip|important|warning|caution)\][ \t]*\n?/i;
|
|
225
|
+
var FRONT_MATTER = /^---[ \t]*\n[\s\S]*?\n(?:---|\.\.\.)[ \t]*(?:\n|$)/;
|
|
226
|
+
var MODELLED_INLINE = new Set([
|
|
227
|
+
"text",
|
|
228
|
+
"strong",
|
|
229
|
+
"emphasis",
|
|
230
|
+
"delete",
|
|
231
|
+
"inlineCode",
|
|
232
|
+
"link",
|
|
233
|
+
"break"
|
|
234
|
+
]);
|
|
235
|
+
var CELL_BREAK = /^<br\s*\/?>$/i;
|
|
236
|
+
var MARKS_OF = {
|
|
237
|
+
strong: "bold",
|
|
238
|
+
emphasis: "italic",
|
|
239
|
+
delete: "strike"
|
|
240
|
+
};
|
|
241
|
+
var PHRASING_OF = {
|
|
242
|
+
bold: "strong",
|
|
243
|
+
italic: "emphasis",
|
|
244
|
+
strike: "delete"
|
|
245
|
+
};
|
|
246
|
+
function markdownToBlocks2(markdown) {
|
|
247
|
+
const frontMatter = FRONT_MATTER.exec(markdown)?.[0];
|
|
248
|
+
const body = frontMatter ? markdown.slice(frontMatter.length) : markdown;
|
|
249
|
+
const tree = fromMarkdown(body, { extensions: [gfm()], mdastExtensions: [gfmFromMarkdown()] });
|
|
250
|
+
const source = (node) => body.slice(node.position?.start.offset ?? 0, node.position?.end.offset ?? 0);
|
|
251
|
+
const raw = (node, nested = false) => ({
|
|
252
|
+
type: "markdown",
|
|
253
|
+
attrs: {
|
|
254
|
+
source: !nested ? source(node) : node.type === "html" ? node.value : toMarkdown(node, { extensions: [gfmToMarkdown()] }).trimEnd()
|
|
255
|
+
}
|
|
256
|
+
});
|
|
257
|
+
const inlineRaw = (node) => ({
|
|
258
|
+
type: "markdownInline",
|
|
259
|
+
attrs: { source: source(node) }
|
|
260
|
+
});
|
|
261
|
+
const inline = (nodes, marks = [], inCell = false) => nodes.flatMap((node) => {
|
|
262
|
+
switch (node.type) {
|
|
263
|
+
case "text":
|
|
264
|
+
return node.value ? [text(node.value, marks)] : [];
|
|
265
|
+
case "strong":
|
|
266
|
+
case "emphasis":
|
|
267
|
+
case "delete":
|
|
268
|
+
if (!modelledThroughout(node))
|
|
269
|
+
return [inlineRaw(node)];
|
|
270
|
+
return inline(node.children, [...marks, { type: MARKS_OF[node.type] }], inCell);
|
|
271
|
+
case "inlineCode":
|
|
272
|
+
return [text(node.value, [...marks, { type: "code" }])];
|
|
273
|
+
case "link":
|
|
274
|
+
if (!modelledThroughout(node))
|
|
275
|
+
return [inlineRaw(node)];
|
|
276
|
+
return inline(node.children, [...marks, link(node.url, node.title ?? null)], inCell);
|
|
277
|
+
case "break":
|
|
278
|
+
return [{ type: "hardBreak" }];
|
|
279
|
+
case "html":
|
|
280
|
+
if (inCell && CELL_BREAK.test(node.value))
|
|
281
|
+
return [{ type: "hardBreak" }];
|
|
282
|
+
return [inlineRaw(node)];
|
|
283
|
+
default:
|
|
284
|
+
return [inlineRaw(node)];
|
|
285
|
+
}
|
|
286
|
+
});
|
|
287
|
+
const paragraph = (node) => {
|
|
288
|
+
const [only] = node.children;
|
|
289
|
+
if (node.children.length === 1 && only?.type === "image")
|
|
290
|
+
return image(only);
|
|
291
|
+
return block("paragraph", undefined, inline(node.children));
|
|
292
|
+
};
|
|
293
|
+
const list = (node, nested) => {
|
|
294
|
+
const checked = (item) => item.checked !== null && item.checked !== undefined;
|
|
295
|
+
const task = node.children.some(checked);
|
|
296
|
+
if (task && !node.children.every(checked))
|
|
297
|
+
return raw(node, nested);
|
|
298
|
+
const items = node.children.map((item) => listItem(item, task));
|
|
299
|
+
if (task)
|
|
300
|
+
return block("taskList", undefined, items);
|
|
301
|
+
if (node.ordered)
|
|
302
|
+
return block("orderedList", { start: node.start ?? 1 }, items);
|
|
303
|
+
return block("bulletList", undefined, items);
|
|
304
|
+
};
|
|
305
|
+
const listItem = (node, task) => {
|
|
306
|
+
const children = blocks(node.children, true);
|
|
307
|
+
const content = children[0]?.type === "paragraph" ? children : [block("paragraph"), ...children];
|
|
308
|
+
return task ? block("taskItem", { checked: node.checked === true }, content) : block("listItem", undefined, content);
|
|
309
|
+
};
|
|
310
|
+
const blockquote = (node) => {
|
|
311
|
+
const [first] = node.children;
|
|
312
|
+
const marker = first?.type === "paragraph" ? first.children[0] : undefined;
|
|
313
|
+
const match = marker?.type === "text" ? CALLOUT.exec(marker.value) : null;
|
|
314
|
+
if (!match || first?.type !== "paragraph" || marker?.type !== "text") {
|
|
315
|
+
return block("blockquote", undefined, nonEmpty(blocks(node.children, true)));
|
|
316
|
+
}
|
|
317
|
+
const rest = marker.value.slice(match[0].length);
|
|
318
|
+
const opening = {
|
|
319
|
+
...first,
|
|
320
|
+
children: [...rest ? [{ ...marker, value: rest }] : [], ...first.children.slice(1)]
|
|
321
|
+
};
|
|
322
|
+
const content = [
|
|
323
|
+
...opening.children.length > 0 ? [paragraph(opening)] : [],
|
|
324
|
+
...blocks(node.children.slice(1), true)
|
|
325
|
+
];
|
|
326
|
+
return block("callout", { kind: match[1].toLowerCase() }, nonEmpty(content));
|
|
327
|
+
};
|
|
328
|
+
const table = (node) => block("table", undefined, node.children.map((row, index) => block("tableRow", undefined, row.children.map((cell, column) => block(index === 0 ? "tableHeader" : "tableCell", { colspan: 1, rowspan: 1, align: node.align?.[column] ?? null }, [block("paragraph", undefined, inline(cell.children, [], true))])))));
|
|
329
|
+
const code = (node) => block("codeBlock", { language: node.lang ?? null, meta: node.meta ?? null }, node.value ? [text(node.value)] : []);
|
|
330
|
+
const blocks = (nodes, nested = false) => nodes.flatMap((node) => {
|
|
331
|
+
switch (node.type) {
|
|
332
|
+
case "paragraph":
|
|
333
|
+
return [paragraph(node)];
|
|
334
|
+
case "heading":
|
|
335
|
+
return [block("heading", { level: node.depth }, inline(node.children))];
|
|
336
|
+
case "thematicBreak":
|
|
337
|
+
return [{ type: "horizontalRule" }];
|
|
338
|
+
case "blockquote":
|
|
339
|
+
return [blockquote(node)];
|
|
340
|
+
case "list":
|
|
341
|
+
return [list(node, nested)];
|
|
342
|
+
case "code":
|
|
343
|
+
return [code(node)];
|
|
344
|
+
case "table":
|
|
345
|
+
return [table(node)];
|
|
346
|
+
default:
|
|
347
|
+
return [raw(node, nested)];
|
|
348
|
+
}
|
|
349
|
+
});
|
|
350
|
+
const content = blocks(tree.children);
|
|
351
|
+
if (frontMatter)
|
|
352
|
+
content.unshift(block("markdown", { source: frontMatter.trimEnd() }));
|
|
353
|
+
return block("doc", undefined, nonEmpty(content));
|
|
354
|
+
}
|
|
355
|
+
function modelledThroughout(node) {
|
|
356
|
+
if (!MODELLED_INLINE.has(node.type))
|
|
357
|
+
return false;
|
|
358
|
+
return !("children" in node) || node.children.every(modelledThroughout);
|
|
359
|
+
}
|
|
360
|
+
function link(href, title) {
|
|
361
|
+
return { type: "link", attrs: { href, target: null, rel: null, class: null, title } };
|
|
362
|
+
}
|
|
363
|
+
function image(node) {
|
|
364
|
+
return {
|
|
365
|
+
type: "image",
|
|
366
|
+
attrs: { src: node.url, alt: node.alt ?? null, title: node.title ?? null }
|
|
367
|
+
};
|
|
368
|
+
}
|
|
369
|
+
function text(value, marks = []) {
|
|
370
|
+
return marks.length > 0 ? { type: "text", text: value, marks } : { type: "text", text: value };
|
|
371
|
+
}
|
|
372
|
+
function block(type, attrs, content = []) {
|
|
373
|
+
return {
|
|
374
|
+
type,
|
|
375
|
+
...attrs ? { attrs } : {},
|
|
376
|
+
...content.length > 0 ? { content } : {}
|
|
377
|
+
};
|
|
378
|
+
}
|
|
379
|
+
function nonEmpty(content) {
|
|
380
|
+
return content.length > 0 ? [...content] : [block("paragraph")];
|
|
381
|
+
}
|
|
382
|
+
function blocksToMarkdown2(doc) {
|
|
383
|
+
const sources = [];
|
|
384
|
+
const nonce = placeholderNonce(doc);
|
|
385
|
+
const verbatim = (source) => {
|
|
386
|
+
sources.push(source);
|
|
387
|
+
return `${nonce}${sources.length - 1}x`;
|
|
388
|
+
};
|
|
389
|
+
const phrasing = (nodes = [], inCell = false) => {
|
|
390
|
+
const out = [];
|
|
391
|
+
for (const node of nodes) {
|
|
392
|
+
if (node.type === "hardBreak") {
|
|
393
|
+
out.push(inCell ? { type: "html", value: "<br>" } : { type: "break" });
|
|
394
|
+
continue;
|
|
395
|
+
}
|
|
396
|
+
if (node.type === "markdownInline") {
|
|
397
|
+
out.push({ type: "html", value: verbatim(String(node.attrs?.source ?? "")) });
|
|
398
|
+
continue;
|
|
399
|
+
}
|
|
400
|
+
if (node.type !== "text" || !node.text)
|
|
401
|
+
continue;
|
|
402
|
+
const marks = node.marks ?? [];
|
|
403
|
+
let leaf = marks.some((mark) => mark.type === "code") ? { type: "inlineCode", value: node.text } : { type: "text", value: node.text };
|
|
404
|
+
for (const mark of [...marks].reverse()) {
|
|
405
|
+
if (mark.type === "link") {
|
|
406
|
+
leaf = {
|
|
407
|
+
type: "link",
|
|
408
|
+
url: String(mark.attrs?.href ?? ""),
|
|
409
|
+
title: typeof mark.attrs?.title === "string" ? mark.attrs.title : null,
|
|
410
|
+
children: [leaf]
|
|
411
|
+
};
|
|
412
|
+
} else if (PHRASING_OF[mark.type]) {
|
|
413
|
+
leaf = { type: PHRASING_OF[mark.type], children: [leaf] };
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
out.push(leaf);
|
|
417
|
+
}
|
|
418
|
+
return joinPhrasing(out);
|
|
419
|
+
};
|
|
420
|
+
const flow = (nodes = []) => nodes.flatMap((node) => {
|
|
421
|
+
switch (node.type) {
|
|
422
|
+
case "paragraph":
|
|
423
|
+
return [{ type: "paragraph", children: phrasing(node.content) }];
|
|
424
|
+
case "heading":
|
|
425
|
+
return [
|
|
426
|
+
{
|
|
427
|
+
type: "heading",
|
|
428
|
+
depth: clampLevel(node.attrs?.level),
|
|
429
|
+
children: phrasing(node.content)
|
|
430
|
+
}
|
|
431
|
+
];
|
|
432
|
+
case "horizontalRule":
|
|
433
|
+
return [{ type: "thematicBreak" }];
|
|
434
|
+
case "blockquote":
|
|
435
|
+
return [{ type: "blockquote", children: flow(node.content) }];
|
|
436
|
+
case "callout": {
|
|
437
|
+
const kind = String(node.attrs?.kind ?? "note").toUpperCase();
|
|
438
|
+
const [first, ...rest] = flow(node.content);
|
|
439
|
+
const marker = { type: "html", value: verbatim(`[!${kind}]`) };
|
|
440
|
+
const opening = first?.type === "paragraph" ? {
|
|
441
|
+
type: "paragraph",
|
|
442
|
+
children: [marker, { type: "text", value: `
|
|
443
|
+
` }, ...first.children]
|
|
444
|
+
} : { type: "paragraph", children: [marker] };
|
|
445
|
+
const children = first?.type === "paragraph" ? rest : first ? [first, ...rest] : rest;
|
|
446
|
+
return [
|
|
447
|
+
{ type: "blockquote", children: [opening, ...children] }
|
|
448
|
+
];
|
|
449
|
+
}
|
|
450
|
+
case "bulletList":
|
|
451
|
+
case "orderedList":
|
|
452
|
+
case "taskList":
|
|
453
|
+
return [
|
|
454
|
+
{
|
|
455
|
+
type: "list",
|
|
456
|
+
ordered: node.type === "orderedList",
|
|
457
|
+
...node.type === "orderedList" ? { start: Number(node.attrs?.start ?? 1) } : {},
|
|
458
|
+
spread: false,
|
|
459
|
+
children: (node.content ?? []).map((item) => ({
|
|
460
|
+
type: "listItem",
|
|
461
|
+
spread: (item.content ?? []).some((child, index) => index > 0 && child.type === "markdown"),
|
|
462
|
+
checked: node.type === "taskList" ? item.attrs?.checked === true : null,
|
|
463
|
+
children: flow(item.content)
|
|
464
|
+
}))
|
|
465
|
+
}
|
|
466
|
+
];
|
|
467
|
+
case "codeBlock":
|
|
468
|
+
return [
|
|
469
|
+
{
|
|
470
|
+
type: "code",
|
|
471
|
+
lang: typeof node.attrs?.language === "string" ? node.attrs.language : null,
|
|
472
|
+
meta: typeof node.attrs?.meta === "string" ? node.attrs.meta : null,
|
|
473
|
+
value: (node.content ?? []).map((each) => each.text ?? "").join("")
|
|
474
|
+
}
|
|
475
|
+
];
|
|
476
|
+
case "image":
|
|
477
|
+
return [
|
|
478
|
+
{
|
|
479
|
+
type: "paragraph",
|
|
480
|
+
children: [
|
|
481
|
+
{
|
|
482
|
+
type: "image",
|
|
483
|
+
url: String(node.attrs?.src ?? ""),
|
|
484
|
+
alt: typeof node.attrs?.alt === "string" ? node.attrs.alt : null,
|
|
485
|
+
title: typeof node.attrs?.title === "string" ? node.attrs.title : null
|
|
486
|
+
}
|
|
487
|
+
]
|
|
488
|
+
}
|
|
489
|
+
];
|
|
490
|
+
case "table": {
|
|
491
|
+
const rows = node.content ?? [];
|
|
492
|
+
return [
|
|
493
|
+
{
|
|
494
|
+
type: "table",
|
|
495
|
+
align: (rows[0]?.content ?? []).map((cell) => alignOf(cell.attrs?.align)),
|
|
496
|
+
children: rows.map((row) => ({
|
|
497
|
+
type: "tableRow",
|
|
498
|
+
children: (row.content ?? []).map((cell) => ({
|
|
499
|
+
type: "tableCell",
|
|
500
|
+
children: phrasing((cell.content ?? []).flatMap((each, index) => [
|
|
501
|
+
...index > 0 ? [{ type: "hardBreak" }] : [],
|
|
502
|
+
...each.content ?? []
|
|
503
|
+
]), true)
|
|
504
|
+
}))
|
|
505
|
+
}))
|
|
506
|
+
}
|
|
507
|
+
];
|
|
508
|
+
}
|
|
509
|
+
case "markdown":
|
|
510
|
+
return [{ type: "html", value: verbatim(String(node.attrs?.source ?? "")) }];
|
|
511
|
+
default:
|
|
512
|
+
return [];
|
|
513
|
+
}
|
|
514
|
+
});
|
|
515
|
+
const written = toMarkdown({ type: "root", children: flow(doc.content) }, {
|
|
516
|
+
extensions: [gfmToMarkdown({ tablePipeAlign: false })],
|
|
517
|
+
bullet: "-",
|
|
518
|
+
emphasis: "*",
|
|
519
|
+
strong: "*",
|
|
520
|
+
rule: "-",
|
|
521
|
+
fences: true,
|
|
522
|
+
listItemIndent: "one"
|
|
523
|
+
});
|
|
524
|
+
return written.replace(TABLE_DELIMITER_ROW, (row) => row.replace(/(:?)-+(:?)/g, "$1---$2")).replace(new RegExp(`${nonce}(\\d+)x`, "g"), (_, index) => sources[Number(index)] ?? "");
|
|
525
|
+
}
|
|
526
|
+
function placeholderNonce(doc) {
|
|
527
|
+
const words = [];
|
|
528
|
+
const collect = (node) => {
|
|
529
|
+
if (node.text)
|
|
530
|
+
words.push(node.text);
|
|
531
|
+
for (const value of Object.values(node.attrs ?? {})) {
|
|
532
|
+
if (typeof value === "string")
|
|
533
|
+
words.push(value);
|
|
534
|
+
}
|
|
535
|
+
for (const child of node.content ?? [])
|
|
536
|
+
collect(child);
|
|
537
|
+
};
|
|
538
|
+
collect(doc);
|
|
539
|
+
const all = words.join(`
|
|
540
|
+
`);
|
|
541
|
+
let nonce = "sixbverbatim";
|
|
542
|
+
while (all.includes(nonce))
|
|
543
|
+
nonce += "q";
|
|
544
|
+
return nonce;
|
|
545
|
+
}
|
|
546
|
+
var TABLE_DELIMITER_ROW = /^\|(?: *:?-+:? *\|)+$/gm;
|
|
547
|
+
function joinPhrasing(nodes) {
|
|
548
|
+
const joined = [];
|
|
549
|
+
for (const node of nodes) {
|
|
550
|
+
const last = joined.at(-1);
|
|
551
|
+
if (last && node.type === last.type && "children" in node && "children" in last) {
|
|
552
|
+
const sameLink = node.type !== "link" || last.type === "link" && node.url === last.url && node.title === last.title;
|
|
553
|
+
if (sameLink) {
|
|
554
|
+
last.children.push(...node.children);
|
|
555
|
+
last.children = joinPhrasing(last.children);
|
|
556
|
+
continue;
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
if (last?.type === "text" && node.type === "text") {
|
|
560
|
+
last.value += node.value;
|
|
561
|
+
continue;
|
|
562
|
+
}
|
|
563
|
+
joined.push(node);
|
|
564
|
+
}
|
|
565
|
+
return joined;
|
|
566
|
+
}
|
|
567
|
+
function clampLevel(level) {
|
|
568
|
+
const value = Number(level);
|
|
569
|
+
return Number.isInteger(value) ? Math.min(6, Math.max(1, value)) : 1;
|
|
570
|
+
}
|
|
571
|
+
function alignOf(align) {
|
|
572
|
+
return align === "left" || align === "right" || align === "center" ? align : null;
|
|
573
|
+
}
|
|
574
|
+
function blocksToY(nodes) {
|
|
575
|
+
const children = [];
|
|
576
|
+
let run = [];
|
|
577
|
+
const flush = () => {
|
|
578
|
+
if (run.length === 0)
|
|
579
|
+
return;
|
|
580
|
+
const text = new Y.XmlText;
|
|
581
|
+
let at = 0;
|
|
582
|
+
for (const node of run) {
|
|
583
|
+
const value = node.text ?? "";
|
|
584
|
+
text.insert(at, value, marksAttributes(node.marks));
|
|
585
|
+
at += value.length;
|
|
586
|
+
}
|
|
587
|
+
children.push(text);
|
|
588
|
+
run = [];
|
|
589
|
+
};
|
|
590
|
+
for (const node of nodes) {
|
|
591
|
+
if (node.type === "text") {
|
|
592
|
+
run.push(node);
|
|
593
|
+
continue;
|
|
594
|
+
}
|
|
595
|
+
flush();
|
|
596
|
+
const element = new Y.XmlElement(node.type);
|
|
597
|
+
for (const [key, value] of Object.entries(node.attrs ?? {})) {
|
|
598
|
+
if (value !== null && value !== undefined)
|
|
599
|
+
element.setAttribute(key, value);
|
|
600
|
+
}
|
|
601
|
+
const content = blocksToY(node.content ?? []);
|
|
602
|
+
if (content.length > 0)
|
|
603
|
+
element.insert(0, content);
|
|
604
|
+
children.push(element);
|
|
605
|
+
}
|
|
606
|
+
flush();
|
|
607
|
+
return children;
|
|
608
|
+
}
|
|
609
|
+
function marksAttributes(marks = []) {
|
|
610
|
+
return Object.fromEntries(marks.map((mark) => [mark.type, { ...mark.attrs }]));
|
|
611
|
+
}
|
|
612
|
+
function blocksFromY(children) {
|
|
613
|
+
return children.flatMap((child) => {
|
|
614
|
+
if (child instanceof Y.XmlText) {
|
|
615
|
+
return child.toDelta().filter((op) => typeof op.insert === "string" && op.insert !== "").map((op) => {
|
|
616
|
+
const marks = Object.entries(op.attributes ?? {}).map(([name, attrs]) => {
|
|
617
|
+
const type = name.split("--")[0];
|
|
618
|
+
const values = attrs && typeof attrs === "object" ? attrs : {};
|
|
619
|
+
return Object.keys(values).length > 0 ? { type, attrs: values } : { type };
|
|
620
|
+
});
|
|
621
|
+
return text(op.insert, marks);
|
|
622
|
+
});
|
|
623
|
+
}
|
|
624
|
+
if (!(child instanceof Y.XmlElement))
|
|
625
|
+
return [];
|
|
626
|
+
const attrs = child.getAttributes();
|
|
627
|
+
const content = blocksFromY(child.toArray());
|
|
628
|
+
return [
|
|
629
|
+
{
|
|
630
|
+
type: child.nodeName,
|
|
631
|
+
...Object.keys(attrs).length > 0 ? { attrs } : {},
|
|
632
|
+
...content.length > 0 ? { content } : {}
|
|
633
|
+
}
|
|
634
|
+
];
|
|
635
|
+
});
|
|
636
|
+
}
|
|
637
|
+
function markdownFragment(markdown) {
|
|
638
|
+
const fragment = new Y.XmlFragment;
|
|
639
|
+
fragment.insert(0, blocksToY(markdownToBlocks2(markdown).content ?? []));
|
|
640
|
+
return fragment;
|
|
641
|
+
}
|
|
642
|
+
function fragmentMarkdown(fragment) {
|
|
643
|
+
return blocksToMarkdown2({ type: "doc", content: blocksFromY(fragment.toArray()) });
|
|
644
|
+
}
|
|
645
|
+
function patchFragment(fragment, markdown) {
|
|
646
|
+
patchBlocks(fragment, markdownToBlocks2(markdown).content ?? []);
|
|
647
|
+
}
|
|
648
|
+
function patchBlocks(parent, next, options = {}) {
|
|
649
|
+
const current = blocksFromY(parent.toArray());
|
|
650
|
+
const key = options.key ?? ((node) => JSON.stringify(normalized(node)));
|
|
651
|
+
const shell = options.shell ?? ((node) => key({ ...node, content: [] }));
|
|
652
|
+
const hunks = diffSequences(current.map(key), next.map(key));
|
|
653
|
+
for (const hunk of hunks.reverse()) {
|
|
654
|
+
const removed = hunk.aEnd - hunk.aStart;
|
|
655
|
+
const added = hunk.bEnd - hunk.bStart;
|
|
656
|
+
const pairs = Array.from({ length: removed === added ? removed : 0 }, (_, at) => ({
|
|
657
|
+
element: parent.get(hunk.aStart + at),
|
|
658
|
+
before: current[hunk.aStart + at],
|
|
659
|
+
after: next[hunk.bStart + at]
|
|
660
|
+
}));
|
|
661
|
+
if (pairs.length > 0 && pairs.every(({ element, before, after }) => element instanceof Y.XmlElement && holdsBlocks(before) && holdsBlocks(after) && shell(before) === shell(after))) {
|
|
662
|
+
for (const { element, after } of pairs) {
|
|
663
|
+
patchBlocks(element, after.content ?? [], options);
|
|
664
|
+
}
|
|
665
|
+
continue;
|
|
666
|
+
}
|
|
667
|
+
if (pairs.length > 0 && pairs.every(({ element, before, after }) => element instanceof Y.XmlElement && holdsWordsAlone(element, before) && holdsWordsAlone(null, after) && shell(before) === shell(after))) {
|
|
668
|
+
for (const { element, after } of pairs)
|
|
669
|
+
patchWords(element, after);
|
|
670
|
+
continue;
|
|
671
|
+
}
|
|
672
|
+
if (removed > 0)
|
|
673
|
+
parent.delete(hunk.aStart, removed);
|
|
674
|
+
if (added > 0)
|
|
675
|
+
parent.insert(hunk.aStart, blocksToY(next.slice(hunk.bStart, hunk.bEnd)));
|
|
676
|
+
}
|
|
677
|
+
}
|
|
678
|
+
function holdsWordsAlone(element, node) {
|
|
679
|
+
if (!node.content?.every((each) => each.type === "text")) {
|
|
680
|
+
return node.content === undefined && (element === null || element.length <= 1);
|
|
681
|
+
}
|
|
682
|
+
if (element === null)
|
|
683
|
+
return true;
|
|
684
|
+
const children = element.toArray();
|
|
685
|
+
return children.length === 1 && children[0] instanceof Y.XmlText;
|
|
686
|
+
}
|
|
687
|
+
function patchWords(element, next) {
|
|
688
|
+
const attrs = Object.fromEntries(Object.entries(next.attrs ?? {}).filter(([, value]) => value !== null && value !== undefined));
|
|
689
|
+
for (const [name, value] of Object.entries(element.getAttributes())) {
|
|
690
|
+
if (!(name in attrs))
|
|
691
|
+
element.removeAttribute(name);
|
|
692
|
+
else if (value !== attrs[name])
|
|
693
|
+
element.setAttribute(name, attrs[name]);
|
|
694
|
+
}
|
|
695
|
+
for (const [name, value] of Object.entries(attrs)) {
|
|
696
|
+
if (!element.hasAttribute(name))
|
|
697
|
+
element.setAttribute(name, value);
|
|
698
|
+
}
|
|
699
|
+
const existing = element.get(0);
|
|
700
|
+
if (!(existing instanceof Y.XmlText)) {
|
|
701
|
+
const fresh = blocksToY(next.content ?? []);
|
|
702
|
+
if (fresh.length > 0)
|
|
703
|
+
element.insert(0, fresh);
|
|
704
|
+
return;
|
|
705
|
+
}
|
|
706
|
+
const characters = (nodes) => nodes.flatMap((node) => {
|
|
707
|
+
const marks = JSON.stringify(marksAttributes(node.marks));
|
|
708
|
+
return [...node.text ?? ""].map((character) => ({ character, marks, node }));
|
|
709
|
+
});
|
|
710
|
+
const before = characters(blocksFromY([existing]));
|
|
711
|
+
const after = characters(next.content ?? []);
|
|
712
|
+
const same = (left, right) => left.character === right.character && left.marks === right.marks;
|
|
713
|
+
let start = 0;
|
|
714
|
+
while (start < before.length && start < after.length && same(before[start], after[start]))
|
|
715
|
+
start += 1;
|
|
716
|
+
let end = 0;
|
|
717
|
+
while (end < before.length - start && end < after.length - start && same(before[before.length - 1 - end], after[after.length - 1 - end]))
|
|
718
|
+
end += 1;
|
|
719
|
+
const units = (run) => run.reduce((sum, each) => sum + each.character.length, 0);
|
|
720
|
+
const from = units(before.slice(0, start));
|
|
721
|
+
const removed = units(before.slice(start, before.length - end));
|
|
722
|
+
if (removed > 0)
|
|
723
|
+
existing.delete(from, removed);
|
|
724
|
+
let at = from;
|
|
725
|
+
const inserted = after.slice(start, after.length - end);
|
|
726
|
+
for (let index = 0;index < inserted.length; ) {
|
|
727
|
+
const marks = inserted[index]?.marks;
|
|
728
|
+
let run = "";
|
|
729
|
+
let node = inserted[index]?.node;
|
|
730
|
+
while (index < inserted.length && inserted[index]?.marks === marks) {
|
|
731
|
+
run += inserted[index]?.character;
|
|
732
|
+
node = inserted[index]?.node;
|
|
733
|
+
index += 1;
|
|
734
|
+
}
|
|
735
|
+
existing.insert(at, run, marksAttributes(node.marks));
|
|
736
|
+
at += run.length;
|
|
737
|
+
}
|
|
738
|
+
}
|
|
739
|
+
function holdsBlocks(node) {
|
|
740
|
+
return (node.content?.length ?? 0) > 0 && node.content?.every((each) => each.type !== "text") === true;
|
|
741
|
+
}
|
|
742
|
+
function mergeBlockLists(base, ours, theirs, comparison) {
|
|
743
|
+
const keys = new WeakMap;
|
|
744
|
+
const key = (node) => {
|
|
745
|
+
let known = keys.get(node);
|
|
746
|
+
if (known === undefined) {
|
|
747
|
+
known = comparison.key(node);
|
|
748
|
+
keys.set(node, known);
|
|
749
|
+
}
|
|
750
|
+
return known;
|
|
751
|
+
};
|
|
752
|
+
const merge = (base, ours, theirs) => {
|
|
753
|
+
const baseKeys = base.map(key);
|
|
754
|
+
const oursKeys = ours.map(key);
|
|
755
|
+
const theirsKeys = theirs.map(key);
|
|
756
|
+
if (sameKeys(oursKeys, baseKeys))
|
|
757
|
+
return [...theirs];
|
|
758
|
+
if (sameKeys(theirsKeys, baseKeys) || sameKeys(oursKeys, theirsKeys))
|
|
759
|
+
return [...ours];
|
|
760
|
+
const byKey = new Map;
|
|
761
|
+
for (const node of [...theirs, ...ours, ...base]) {
|
|
762
|
+
const list = byKey.get(key(node));
|
|
763
|
+
if (list)
|
|
764
|
+
list.push(node);
|
|
765
|
+
else
|
|
766
|
+
byKey.set(key(node), [node]);
|
|
767
|
+
}
|
|
768
|
+
const firstOf = (list) => {
|
|
769
|
+
const map = new Map;
|
|
770
|
+
for (const node of list)
|
|
771
|
+
if (!map.has(key(node)))
|
|
772
|
+
map.set(key(node), node);
|
|
773
|
+
return map;
|
|
774
|
+
};
|
|
775
|
+
const [baseOf, oursOf, theirsOf] = [firstOf(base), firstOf(ours), firstOf(theirs)];
|
|
776
|
+
const one = (b, o, t) => {
|
|
777
|
+
const shell = comparison.shell(t);
|
|
778
|
+
if (comparison.shell(b) !== shell || comparison.shell(o) !== shell)
|
|
779
|
+
return null;
|
|
780
|
+
if (holdsBlocks(b) && holdsBlocks(o) && holdsBlocks(t)) {
|
|
781
|
+
return { ...t, content: merge(b.content ?? [], o.content ?? [], t.content ?? []) };
|
|
782
|
+
}
|
|
783
|
+
return comparison.mergeLeaf(b, o, t);
|
|
784
|
+
};
|
|
785
|
+
const merged = mergeSequences(baseKeys, oursKeys, theirsKeys, (b, o, t) => {
|
|
786
|
+
if (b.length === o.length && o.length === t.length) {
|
|
787
|
+
const each = b.map((k, at) => one(baseOf.get(k), oursOf.get(o[at]), theirsOf.get(t[at])));
|
|
788
|
+
if (each.every((node) => node !== null)) {
|
|
789
|
+
return each.map((node) => {
|
|
790
|
+
const k = key(node);
|
|
791
|
+
byKey.set(k, [node, ...byKey.get(k) ?? []]);
|
|
792
|
+
return k;
|
|
793
|
+
});
|
|
794
|
+
}
|
|
795
|
+
}
|
|
796
|
+
return interleave(b, o, t);
|
|
797
|
+
});
|
|
798
|
+
const taken = new Map;
|
|
799
|
+
return merged.map((k) => {
|
|
800
|
+
const at = taken.get(k) ?? 0;
|
|
801
|
+
taken.set(k, at + 1);
|
|
802
|
+
const nodes = byKey.get(k) ?? [];
|
|
803
|
+
return nodes[at] ?? nodes[0];
|
|
804
|
+
});
|
|
805
|
+
};
|
|
806
|
+
return merge(base, ours, theirs);
|
|
807
|
+
}
|
|
808
|
+
function sameKeys(left, right) {
|
|
809
|
+
return left.length === right.length && left.every((key, at) => key === right[at]);
|
|
810
|
+
}
|
|
811
|
+
function mergeMarkdownBlocks(base, ours, theirs) {
|
|
812
|
+
const key = (node) => JSON.stringify(normalized(node));
|
|
813
|
+
return mergeBlockLists(markdownToBlocks2(base).content ?? [], ours, markdownToBlocks2(theirs).content ?? [], {
|
|
814
|
+
key,
|
|
815
|
+
shell: (node) => key({ ...node, content: [] }),
|
|
816
|
+
mergeLeaf: (b, o, t) => {
|
|
817
|
+
const written = (node) => blocksToMarkdown2({ type: "doc", content: [node] });
|
|
818
|
+
const [merged, ...more] = markdownToBlocks2(mergeText(written(b), written(o), written(t))).content ?? [];
|
|
819
|
+
if (!merged || more.length > 0 || merged.type !== t.type)
|
|
820
|
+
return null;
|
|
821
|
+
return merged;
|
|
822
|
+
}
|
|
823
|
+
});
|
|
824
|
+
}
|
|
825
|
+
function normalized(node) {
|
|
826
|
+
const attrs = Object.fromEntries(Object.entries(node.attrs ?? {}).filter(([, value]) => value !== null && value !== undefined));
|
|
827
|
+
return {
|
|
828
|
+
type: node.type,
|
|
829
|
+
...Object.keys(attrs).length > 0 ? { attrs } : {},
|
|
830
|
+
...node.text !== undefined ? { text: node.text } : {},
|
|
831
|
+
...node.marks?.length ? { marks: node.marks.map((mark) => normalized(mark)) } : {},
|
|
832
|
+
...node.content?.length ? { content: node.content.map(normalized) } : {}
|
|
833
|
+
};
|
|
834
|
+
}
|
|
835
|
+
|
|
836
|
+
// src/artifacts/live/page.ts
|
|
837
|
+
import { defaultTreeAdapter, parse, parseFragment } from "parse5";
|
|
838
|
+
import * as Y2 from "yjs";
|
|
839
|
+
var PAGE_MARK_TAGS2 = [
|
|
840
|
+
"a",
|
|
841
|
+
"span",
|
|
842
|
+
"strong",
|
|
843
|
+
"b",
|
|
844
|
+
"em",
|
|
845
|
+
"i",
|
|
846
|
+
"u",
|
|
847
|
+
"s",
|
|
848
|
+
"del",
|
|
849
|
+
"ins",
|
|
850
|
+
"mark",
|
|
851
|
+
"small",
|
|
852
|
+
"sub",
|
|
853
|
+
"sup",
|
|
854
|
+
"code",
|
|
855
|
+
"abbr",
|
|
856
|
+
"cite",
|
|
857
|
+
"q",
|
|
858
|
+
"dfn",
|
|
859
|
+
"kbd",
|
|
860
|
+
"samp",
|
|
861
|
+
"var",
|
|
862
|
+
"time",
|
|
863
|
+
"data",
|
|
864
|
+
"bdi",
|
|
865
|
+
"bdo"
|
|
866
|
+
];
|
|
867
|
+
var PAGE_TEXT_TAGS2 = new Set([
|
|
868
|
+
"p",
|
|
869
|
+
"h1",
|
|
870
|
+
"h2",
|
|
871
|
+
"h3",
|
|
872
|
+
"h4",
|
|
873
|
+
"h5",
|
|
874
|
+
"h6",
|
|
875
|
+
"li",
|
|
876
|
+
"td",
|
|
877
|
+
"th",
|
|
878
|
+
"dt",
|
|
879
|
+
"dd",
|
|
880
|
+
"figcaption",
|
|
881
|
+
"blockquote",
|
|
882
|
+
"caption",
|
|
883
|
+
"pre",
|
|
884
|
+
"summary",
|
|
885
|
+
"legend",
|
|
886
|
+
"address"
|
|
887
|
+
]);
|
|
888
|
+
var OPAQUE = new Set([
|
|
889
|
+
"script",
|
|
890
|
+
"style",
|
|
891
|
+
"template",
|
|
892
|
+
"noscript",
|
|
893
|
+
"svg",
|
|
894
|
+
"math",
|
|
895
|
+
"canvas",
|
|
896
|
+
"video",
|
|
897
|
+
"audio",
|
|
898
|
+
"iframe",
|
|
899
|
+
"object",
|
|
900
|
+
"embed",
|
|
901
|
+
"picture",
|
|
902
|
+
"select",
|
|
903
|
+
"textarea",
|
|
904
|
+
"input",
|
|
905
|
+
"button",
|
|
906
|
+
"form",
|
|
907
|
+
"hr",
|
|
908
|
+
"colgroup",
|
|
909
|
+
"col",
|
|
910
|
+
"wbr",
|
|
911
|
+
"br"
|
|
912
|
+
]);
|
|
913
|
+
var PHRASING = new Set([
|
|
914
|
+
...PAGE_MARK_TAGS2,
|
|
915
|
+
"br",
|
|
916
|
+
"wbr",
|
|
917
|
+
"img",
|
|
918
|
+
"svg",
|
|
919
|
+
"math",
|
|
920
|
+
"input",
|
|
921
|
+
"button",
|
|
922
|
+
"select",
|
|
923
|
+
"textarea",
|
|
924
|
+
"label",
|
|
925
|
+
"output",
|
|
926
|
+
"meter",
|
|
927
|
+
"progress",
|
|
928
|
+
"picture",
|
|
929
|
+
"canvas",
|
|
930
|
+
"video",
|
|
931
|
+
"audio",
|
|
932
|
+
"iframe",
|
|
933
|
+
"object",
|
|
934
|
+
"embed",
|
|
935
|
+
"font",
|
|
936
|
+
"nobr",
|
|
937
|
+
"ruby",
|
|
938
|
+
"rt",
|
|
939
|
+
"rp",
|
|
940
|
+
"slot"
|
|
941
|
+
]);
|
|
942
|
+
var MARK_RANK = new Map(PAGE_MARK_TAGS2.map((tag, at) => [tag, at]));
|
|
943
|
+
var COLLAPSIBLE = /[ \t\n\r\f]+/g;
|
|
944
|
+
function pageBlocks(source) {
|
|
945
|
+
const document = parse(source, { sourceCodeLocationInfo: true });
|
|
946
|
+
const html = document.childNodes.find(isElement);
|
|
947
|
+
const body = html?.childNodes.find((child) => isElement(child) && child.tagName === "body");
|
|
948
|
+
const start = body?.sourceCodeLocation?.startTag?.endOffset;
|
|
949
|
+
if (!body || start === undefined)
|
|
950
|
+
return null;
|
|
951
|
+
const children = body.childNodes;
|
|
952
|
+
for (const child of children) {
|
|
953
|
+
const location = child.sourceCodeLocation;
|
|
954
|
+
if (!location || location.startOffset < start)
|
|
955
|
+
return null;
|
|
956
|
+
}
|
|
957
|
+
const end = body.sourceCodeLocation?.endTag?.startOffset;
|
|
958
|
+
const past = (child) => end !== undefined && endOf(child) > end && !(isText(child) && child.value.trim() === "");
|
|
959
|
+
if (children.some(past))
|
|
960
|
+
return null;
|
|
961
|
+
const read = childBlocks(children, source, start, { stray: true });
|
|
962
|
+
if (!read)
|
|
963
|
+
return null;
|
|
964
|
+
const page = {
|
|
965
|
+
head: source.slice(0, start),
|
|
966
|
+
blocks: read.blocks,
|
|
967
|
+
tail: source.slice(start + read.length - read.trailing.length)
|
|
968
|
+
};
|
|
969
|
+
return pageHtml(page) === source ? page : null;
|
|
970
|
+
}
|
|
971
|
+
function childBlocks(children, source, from, options) {
|
|
972
|
+
const blocks = [];
|
|
973
|
+
let at = from;
|
|
974
|
+
let before = "";
|
|
975
|
+
let stray = null;
|
|
976
|
+
const flushStray = () => {
|
|
977
|
+
if (!stray)
|
|
978
|
+
return;
|
|
979
|
+
blocks.push(rawBlock(source.slice(stray.start, stray.end), before));
|
|
980
|
+
before = "";
|
|
981
|
+
stray = null;
|
|
982
|
+
};
|
|
983
|
+
for (const child of children) {
|
|
984
|
+
const start = startOf(child);
|
|
985
|
+
const end = endOf(child);
|
|
986
|
+
if (start !== at)
|
|
987
|
+
return null;
|
|
988
|
+
at = end;
|
|
989
|
+
if (isText(child)) {
|
|
990
|
+
if (child.value.trim() === "" && !stray) {
|
|
991
|
+
before += source.slice(start, end);
|
|
992
|
+
continue;
|
|
993
|
+
}
|
|
994
|
+
if (!options.stray)
|
|
995
|
+
return null;
|
|
996
|
+
stray = { start: stray?.start ?? start, end };
|
|
997
|
+
continue;
|
|
998
|
+
}
|
|
999
|
+
if (stray) {
|
|
1000
|
+
if (!options.stray)
|
|
1001
|
+
return null;
|
|
1002
|
+
flushStray();
|
|
1003
|
+
}
|
|
1004
|
+
const block = blockOf(child, source, before);
|
|
1005
|
+
if (!block)
|
|
1006
|
+
return null;
|
|
1007
|
+
blocks.push(block);
|
|
1008
|
+
before = "";
|
|
1009
|
+
}
|
|
1010
|
+
flushStray();
|
|
1011
|
+
return { blocks, trailing: before, length: at - from };
|
|
1012
|
+
}
|
|
1013
|
+
function blockOf(node, source, before) {
|
|
1014
|
+
const slice = source.slice(startOf(node), endOf(node));
|
|
1015
|
+
if (!isElement(node))
|
|
1016
|
+
return rawBlock(slice, before);
|
|
1017
|
+
const tag = node.tagName;
|
|
1018
|
+
const location = node.sourceCodeLocation;
|
|
1019
|
+
if (!location?.startTag || !locatedThroughout(node) || isOpaque(node)) {
|
|
1020
|
+
return rawBlock(slice, before);
|
|
1021
|
+
}
|
|
1022
|
+
if (tag === "img")
|
|
1023
|
+
return { type: "image", attrs: { source: slice, before } };
|
|
1024
|
+
const open = source.slice(location.startTag.startOffset, location.startTag.endOffset);
|
|
1025
|
+
const close = location.endTag ? source.slice(location.endTag.startOffset, location.endTag.endOffset) : "";
|
|
1026
|
+
const innerStart = location.startTag.endOffset;
|
|
1027
|
+
const innerEnd = location.endTag?.startOffset ?? endOf(node);
|
|
1028
|
+
const inner = source.slice(innerStart, innerEnd);
|
|
1029
|
+
const empty = node.childNodes.every((child) => isText(child) && child.value.trim() === "");
|
|
1030
|
+
if (!empty || PAGE_TEXT_TAGS2.has(tag)) {
|
|
1031
|
+
const content = inlineOf(node.childNodes, source, tag === "pre");
|
|
1032
|
+
const words = content?.some((each) => each.type === "text" && /[^ ]/.test(each.text ?? ""));
|
|
1033
|
+
if (content && (words || PAGE_TEXT_TAGS2.has(tag))) {
|
|
1034
|
+
const block = {
|
|
1035
|
+
type: "textBlock",
|
|
1036
|
+
attrs: { tag, open, close, before, inner },
|
|
1037
|
+
...content.length > 0 ? { content } : {}
|
|
1038
|
+
};
|
|
1039
|
+
return innerOf(block, tag) === inner ? block : rawBlock(slice, before);
|
|
1040
|
+
}
|
|
1041
|
+
}
|
|
1042
|
+
if (empty)
|
|
1043
|
+
return rawBlock(slice, before);
|
|
1044
|
+
const read = childBlocks(node.childNodes, source, innerStart, { stray: false });
|
|
1045
|
+
if (!read || read.blocks.length === 0)
|
|
1046
|
+
return rawBlock(slice, before);
|
|
1047
|
+
const box = {
|
|
1048
|
+
type: "box",
|
|
1049
|
+
attrs: { tag, open, close, before, end: read.trailing },
|
|
1050
|
+
content: read.blocks
|
|
1051
|
+
};
|
|
1052
|
+
return writeBlock(box, null) === before + slice ? box : rawBlock(slice, before);
|
|
1053
|
+
}
|
|
1054
|
+
function rawBlock(source, before) {
|
|
1055
|
+
return { type: "raw", attrs: { source, before } };
|
|
1056
|
+
}
|
|
1057
|
+
function inlineOf(children, source, pre) {
|
|
1058
|
+
const nodes = [];
|
|
1059
|
+
const visit = (each, marks) => {
|
|
1060
|
+
for (const child of each) {
|
|
1061
|
+
const slice = () => source.slice(startOf(child), endOf(child));
|
|
1062
|
+
if (isText(child)) {
|
|
1063
|
+
nodes.push(textNode(child.value, marks));
|
|
1064
|
+
continue;
|
|
1065
|
+
}
|
|
1066
|
+
if (!isElement(child)) {
|
|
1067
|
+
nodes.push({ type: "rawInline", attrs: { source: slice(), hidden: true } });
|
|
1068
|
+
continue;
|
|
1069
|
+
}
|
|
1070
|
+
const tag = child.tagName;
|
|
1071
|
+
const location = child.sourceCodeLocation;
|
|
1072
|
+
if (!location?.startTag || !PHRASING.has(tag) && !isCustom(tag))
|
|
1073
|
+
return false;
|
|
1074
|
+
if (!locatedThroughout(child))
|
|
1075
|
+
return false;
|
|
1076
|
+
if (tag === "br") {
|
|
1077
|
+
nodes.push({ type: "hardBreak", attrs: { source: slice() } });
|
|
1078
|
+
continue;
|
|
1079
|
+
}
|
|
1080
|
+
const markable = MARK_RANK.has(tag) && !isLive(child) && !marks.some((mark) => mark.type === tag) && child.childNodes.length > 0 && holdsOnlyInline(child) && formatsWords(child);
|
|
1081
|
+
if (!markable) {
|
|
1082
|
+
if (!holdsOnlyInline(child) && !isOpaque(child))
|
|
1083
|
+
return false;
|
|
1084
|
+
nodes.push({ type: "rawInline", attrs: { source: slice() } });
|
|
1085
|
+
continue;
|
|
1086
|
+
}
|
|
1087
|
+
const open = source.slice(location.startTag.startOffset, location.startTag.endOffset);
|
|
1088
|
+
const close = location.endTag ? source.slice(location.endTag.startOffset, location.endTag.endOffset) : "";
|
|
1089
|
+
if (!visit(child.childNodes, [...marks, { type: tag, attrs: { open, close } }]))
|
|
1090
|
+
return false;
|
|
1091
|
+
}
|
|
1092
|
+
return true;
|
|
1093
|
+
};
|
|
1094
|
+
if (!visit(children, []))
|
|
1095
|
+
return null;
|
|
1096
|
+
return joinTexts(pre ? nodes : collapsed(nodes));
|
|
1097
|
+
}
|
|
1098
|
+
function formatsWords(node) {
|
|
1099
|
+
const rank = node.attrs.length > 0 ? MARK_RANK.get(node.tagName) ?? -1 : -1;
|
|
1100
|
+
return node.childNodes.every((child) => {
|
|
1101
|
+
if (!isElement(child))
|
|
1102
|
+
return true;
|
|
1103
|
+
if (child.tagName === "br")
|
|
1104
|
+
return true;
|
|
1105
|
+
return (MARK_RANK.get(child.tagName) ?? -1) > rank && !isLive(child) && formatsWords(child);
|
|
1106
|
+
});
|
|
1107
|
+
}
|
|
1108
|
+
function holdsOnlyInline(node) {
|
|
1109
|
+
if (isOpaque(node))
|
|
1110
|
+
return true;
|
|
1111
|
+
return node.childNodes.every((child) => {
|
|
1112
|
+
if (!isElement(child))
|
|
1113
|
+
return true;
|
|
1114
|
+
return (PHRASING.has(child.tagName) || isCustom(child.tagName)) && holdsOnlyInline(child);
|
|
1115
|
+
});
|
|
1116
|
+
}
|
|
1117
|
+
function collapsed(nodes) {
|
|
1118
|
+
const out = [];
|
|
1119
|
+
let after = true;
|
|
1120
|
+
const trimEnd = () => {
|
|
1121
|
+
for (let at = out.length - 1;at >= 0; at -= 1) {
|
|
1122
|
+
const node = out[at];
|
|
1123
|
+
if (node.type === "rawInline" && node.attrs?.hidden)
|
|
1124
|
+
continue;
|
|
1125
|
+
if (node.type !== "text")
|
|
1126
|
+
return;
|
|
1127
|
+
const text = (node.text ?? "").replace(/ $/, "");
|
|
1128
|
+
out[at] = { ...node, text };
|
|
1129
|
+
return;
|
|
1130
|
+
}
|
|
1131
|
+
};
|
|
1132
|
+
for (const node of nodes) {
|
|
1133
|
+
if (node.type === "text") {
|
|
1134
|
+
let text = (node.text ?? "").replace(COLLAPSIBLE, " ");
|
|
1135
|
+
if (after)
|
|
1136
|
+
text = text.replace(/^ /, "");
|
|
1137
|
+
if (text === "")
|
|
1138
|
+
continue;
|
|
1139
|
+
after = text.endsWith(" ");
|
|
1140
|
+
out.push({ ...node, text });
|
|
1141
|
+
continue;
|
|
1142
|
+
}
|
|
1143
|
+
if (node.type === "hardBreak") {
|
|
1144
|
+
trimEnd();
|
|
1145
|
+
after = true;
|
|
1146
|
+
} else if (!(node.type === "rawInline" && node.attrs?.hidden)) {
|
|
1147
|
+
after = false;
|
|
1148
|
+
}
|
|
1149
|
+
out.push(node);
|
|
1150
|
+
}
|
|
1151
|
+
trimEnd();
|
|
1152
|
+
return out;
|
|
1153
|
+
}
|
|
1154
|
+
function joinTexts(nodes) {
|
|
1155
|
+
const out = [];
|
|
1156
|
+
for (const node of nodes) {
|
|
1157
|
+
const last = out.at(-1);
|
|
1158
|
+
if (node.type === "text" && node.text === "")
|
|
1159
|
+
continue;
|
|
1160
|
+
if (node.type === "text" && last?.type === "text" && sameMarks(last.marks, node.marks)) {
|
|
1161
|
+
out[out.length - 1] = { ...last, text: `${last.text ?? ""}${node.text ?? ""}` };
|
|
1162
|
+
continue;
|
|
1163
|
+
}
|
|
1164
|
+
out.push(node.type === "rawInline" ? { type: node.type, attrs: { source: node.attrs?.source } } : node);
|
|
1165
|
+
}
|
|
1166
|
+
return out;
|
|
1167
|
+
}
|
|
1168
|
+
function textNode(text, marks) {
|
|
1169
|
+
return marks.length > 0 ? { type: "text", text, marks } : { type: "text", text };
|
|
1170
|
+
}
|
|
1171
|
+
function pageHtml(page) {
|
|
1172
|
+
return page.head + writeChildren(page.blocks, null) + page.tail;
|
|
1173
|
+
}
|
|
1174
|
+
function writeChildren(blocks, parentBefore) {
|
|
1175
|
+
let previous = null;
|
|
1176
|
+
let out = "";
|
|
1177
|
+
for (const block of blocks) {
|
|
1178
|
+
const before = stringAttr(block, "before") ?? previous ?? (parentBefore ? indented(parentBefore) : "");
|
|
1179
|
+
out += writeBlock(block, before);
|
|
1180
|
+
previous = before;
|
|
1181
|
+
}
|
|
1182
|
+
return out;
|
|
1183
|
+
}
|
|
1184
|
+
function writeBlock(block, spaced) {
|
|
1185
|
+
const before = spaced ?? stringAttr(block, "before") ?? "";
|
|
1186
|
+
switch (block.type) {
|
|
1187
|
+
case "box": {
|
|
1188
|
+
const tag = stringAttr(block, "tag") ?? "div";
|
|
1189
|
+
const end = stringAttr(block, "end") ?? (before.includes(`
|
|
1190
|
+
`) ? before : "");
|
|
1191
|
+
const children = writeChildren(block.content ?? [], before);
|
|
1192
|
+
return `${before}${openOf(block, tag)}${children}${end}${closeOf(block, tag)}`;
|
|
1193
|
+
}
|
|
1194
|
+
case "textBlock": {
|
|
1195
|
+
const tag = stringAttr(block, "tag") ?? "p";
|
|
1196
|
+
return `${before}${openOf(block, tag)}${innerOf(block, tag)}${closeOf(block, tag)}`;
|
|
1197
|
+
}
|
|
1198
|
+
default:
|
|
1199
|
+
return `${before}${stringAttr(block, "source") ?? ""}`;
|
|
1200
|
+
}
|
|
1201
|
+
}
|
|
1202
|
+
function openOf(block, tag) {
|
|
1203
|
+
return stringAttr(block, "open") ?? `<${tag}>`;
|
|
1204
|
+
}
|
|
1205
|
+
function closeOf(block, tag) {
|
|
1206
|
+
const close = stringAttr(block, "close");
|
|
1207
|
+
return close === null ? `</${tag}>` : close;
|
|
1208
|
+
}
|
|
1209
|
+
function innerOf(block, tag) {
|
|
1210
|
+
const words = inlineHtml(block.content ?? []);
|
|
1211
|
+
const written = tag === "pre" && /^\r?\n/.test(words) ? `
|
|
1212
|
+
${words}` : words;
|
|
1213
|
+
const inner = stringAttr(block, "inner");
|
|
1214
|
+
if (inner !== null && canonicalInner(inner, tag) === written)
|
|
1215
|
+
return inner;
|
|
1216
|
+
return written;
|
|
1217
|
+
}
|
|
1218
|
+
var canonical = new Map;
|
|
1219
|
+
var CANONICAL_LIMIT = 20000;
|
|
1220
|
+
function canonicalInner(inner, tag) {
|
|
1221
|
+
const key = `${tag}\x00${inner}`;
|
|
1222
|
+
const known = canonical.get(key);
|
|
1223
|
+
if (known !== undefined) {
|
|
1224
|
+
canonical.delete(key);
|
|
1225
|
+
canonical.set(key, known);
|
|
1226
|
+
return known;
|
|
1227
|
+
}
|
|
1228
|
+
if (canonical.size >= CANONICAL_LIMIT)
|
|
1229
|
+
canonical.delete(canonical.keys().next().value);
|
|
1230
|
+
const content = wordsOf(inner, tag);
|
|
1231
|
+
const html = content ? inlineHtml(content) : null;
|
|
1232
|
+
const written = html !== null && tag === "pre" && /^\r?\n/.test(html) ? `
|
|
1233
|
+
${html}` : html;
|
|
1234
|
+
canonical.set(key, written);
|
|
1235
|
+
return written;
|
|
1236
|
+
}
|
|
1237
|
+
function wordsOf(inner, tag) {
|
|
1238
|
+
const words = tag === "pre" ? inner.replace(/^\r?\n/, "") : inner;
|
|
1239
|
+
const context = defaultTreeAdapter.createElement(tag, HTML_NAMESPACE, []);
|
|
1240
|
+
const fragment = parseFragment(context, words, { sourceCodeLocationInfo: true });
|
|
1241
|
+
return inlineOf(fragment.childNodes, words, tag === "pre");
|
|
1242
|
+
}
|
|
1243
|
+
function inlineHtml(nodes) {
|
|
1244
|
+
let out = "";
|
|
1245
|
+
let open = [];
|
|
1246
|
+
for (const node of nodes) {
|
|
1247
|
+
const marks = sortedMarks(node.type === "text" ? node.marks ?? [] : []);
|
|
1248
|
+
let common = 0;
|
|
1249
|
+
while (common < open.length && common < marks.length && sameMark(open[common], marks[common])) {
|
|
1250
|
+
common += 1;
|
|
1251
|
+
}
|
|
1252
|
+
const keep = node.type === "text" ? common : open.length;
|
|
1253
|
+
for (const mark of open.slice(keep).reverse())
|
|
1254
|
+
out += markClose(mark);
|
|
1255
|
+
open = open.slice(0, keep);
|
|
1256
|
+
if (node.type !== "text") {
|
|
1257
|
+
out += stringAttr(node, "source") ?? (node.type === "hardBreak" ? "<br>" : "");
|
|
1258
|
+
continue;
|
|
1259
|
+
}
|
|
1260
|
+
for (const mark of marks.slice(common))
|
|
1261
|
+
out += markOpen(mark);
|
|
1262
|
+
open = [...open, ...marks.slice(common)];
|
|
1263
|
+
out += escapeText(node.text ?? "");
|
|
1264
|
+
}
|
|
1265
|
+
for (const mark of open.reverse())
|
|
1266
|
+
out += markClose(mark);
|
|
1267
|
+
return out;
|
|
1268
|
+
}
|
|
1269
|
+
function markOpen(mark) {
|
|
1270
|
+
const open = mark.attrs?.open;
|
|
1271
|
+
return typeof open === "string" && open !== "" ? open : `<${mark.type}>`;
|
|
1272
|
+
}
|
|
1273
|
+
function markClose(mark) {
|
|
1274
|
+
const close = mark.attrs?.close;
|
|
1275
|
+
return typeof close === "string" && close !== "" ? close : `</${mark.type}>`;
|
|
1276
|
+
}
|
|
1277
|
+
function sortedMarks(marks) {
|
|
1278
|
+
return [...marks].sort((left, right) => (MARK_RANK.get(left.type) ?? 99) - (MARK_RANK.get(right.type) ?? 99));
|
|
1279
|
+
}
|
|
1280
|
+
function sameMark(left, right) {
|
|
1281
|
+
return left !== undefined && right !== undefined && left.type === right.type && left.attrs?.open === right.attrs?.open && left.attrs?.close === right.attrs?.close;
|
|
1282
|
+
}
|
|
1283
|
+
function sameMarks(left, right) {
|
|
1284
|
+
const a = sortedMarks(left ?? []);
|
|
1285
|
+
const b = sortedMarks(right ?? []);
|
|
1286
|
+
return a.length === b.length && a.every((mark, at) => sameMark(mark, b[at]));
|
|
1287
|
+
}
|
|
1288
|
+
function escapeText(text) {
|
|
1289
|
+
return text.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/\u00A0/g, " ");
|
|
1290
|
+
}
|
|
1291
|
+
function indented(before) {
|
|
1292
|
+
const line = before.lastIndexOf(`
|
|
1293
|
+
`);
|
|
1294
|
+
return line < 0 ? "" : `${before.slice(line)} `;
|
|
1295
|
+
}
|
|
1296
|
+
function stringAttr(node, name) {
|
|
1297
|
+
const value = node.attrs?.[name];
|
|
1298
|
+
return typeof value === "string" ? value : null;
|
|
1299
|
+
}
|
|
1300
|
+
var PAGE_BODY2 = "body";
|
|
1301
|
+
function pageEntry(source) {
|
|
1302
|
+
const page = pageBlocks(source);
|
|
1303
|
+
if (!page)
|
|
1304
|
+
return null;
|
|
1305
|
+
const entry = new Y2.Map;
|
|
1306
|
+
const body = new Y2.XmlFragment;
|
|
1307
|
+
body.insert(0, blocksToY(page.blocks));
|
|
1308
|
+
entry.set("head", page.head);
|
|
1309
|
+
entry.set(PAGE_BODY2, body);
|
|
1310
|
+
entry.set("tail", page.tail);
|
|
1311
|
+
return entry;
|
|
1312
|
+
}
|
|
1313
|
+
var PAGE_PATCH = {
|
|
1314
|
+
key: (node) => writeBlock(node, ""),
|
|
1315
|
+
shell: (node) => `${node.type}\x00${stringAttr(node, "open")}\x00${stringAttr(node, "close")}`
|
|
1316
|
+
};
|
|
1317
|
+
function mergePageSources(base, ours, theirs) {
|
|
1318
|
+
const oursHtml = typeof ours === "string" ? ours : pageHtml(ours);
|
|
1319
|
+
if (oursHtml === base || oursHtml === theirs)
|
|
1320
|
+
return theirs;
|
|
1321
|
+
if (theirs === base)
|
|
1322
|
+
return oursHtml;
|
|
1323
|
+
const [b, o, t] = [
|
|
1324
|
+
pageBlocks(base),
|
|
1325
|
+
typeof ours === "string" ? pageBlocks(ours) : ours,
|
|
1326
|
+
pageBlocks(theirs)
|
|
1327
|
+
];
|
|
1328
|
+
if (!b || !o || !t)
|
|
1329
|
+
return null;
|
|
1330
|
+
return pageHtml({
|
|
1331
|
+
head: mergeText(b.head, o.head, t.head),
|
|
1332
|
+
blocks: mergeBlockLists(b.blocks, o.blocks, t.blocks, { ...PAGE_PATCH, mergeLeaf: mergeWords }),
|
|
1333
|
+
tail: mergeText(b.tail, o.tail, t.tail)
|
|
1334
|
+
});
|
|
1335
|
+
}
|
|
1336
|
+
function mergeWords(base, ours, theirs) {
|
|
1337
|
+
if (theirs.type !== "textBlock")
|
|
1338
|
+
return null;
|
|
1339
|
+
const tag = stringAttr(theirs, "tag") ?? "p";
|
|
1340
|
+
const inner = mergeText(innerOf(base, tag), innerOf(ours, tag), innerOf(theirs, tag));
|
|
1341
|
+
const content = wordsOf(inner, tag);
|
|
1342
|
+
if (!content)
|
|
1343
|
+
return null;
|
|
1344
|
+
const merged = {
|
|
1345
|
+
type: "textBlock",
|
|
1346
|
+
attrs: { ...theirs.attrs, inner },
|
|
1347
|
+
...content.length > 0 ? { content } : {}
|
|
1348
|
+
};
|
|
1349
|
+
return innerOf(merged, tag) === inner ? merged : null;
|
|
1350
|
+
}
|
|
1351
|
+
function isPageEntry2(entry) {
|
|
1352
|
+
return entry instanceof Y2.Map && entry.get(PAGE_BODY2) instanceof Y2.XmlFragment;
|
|
1353
|
+
}
|
|
1354
|
+
function pageEntryHtml2(entry) {
|
|
1355
|
+
return pageHtml(pageEntryBlocks(entry));
|
|
1356
|
+
}
|
|
1357
|
+
function pageEntryBlocks(entry) {
|
|
1358
|
+
const body = entry.get(PAGE_BODY2);
|
|
1359
|
+
return {
|
|
1360
|
+
head: String(entry.get("head") ?? ""),
|
|
1361
|
+
blocks: blocksFromY(body.toArray()),
|
|
1362
|
+
tail: String(entry.get("tail") ?? "")
|
|
1363
|
+
};
|
|
1364
|
+
}
|
|
1365
|
+
function patchPageEntry(entry, source) {
|
|
1366
|
+
const page = pageBlocks(source);
|
|
1367
|
+
if (!page)
|
|
1368
|
+
return false;
|
|
1369
|
+
if (entry.get("head") !== page.head)
|
|
1370
|
+
entry.set("head", page.head);
|
|
1371
|
+
if (entry.get("tail") !== page.tail)
|
|
1372
|
+
entry.set("tail", page.tail);
|
|
1373
|
+
const body = entry.get(PAGE_BODY2);
|
|
1374
|
+
patchBlocks(body, page.blocks, PAGE_PATCH);
|
|
1375
|
+
respace(body, page.blocks);
|
|
1376
|
+
return true;
|
|
1377
|
+
}
|
|
1378
|
+
function respace(parent, next) {
|
|
1379
|
+
const elements = parent.toArray();
|
|
1380
|
+
if (elements.length !== next.length)
|
|
1381
|
+
return;
|
|
1382
|
+
elements.forEach((element, at) => {
|
|
1383
|
+
const block = next[at];
|
|
1384
|
+
if (!(element instanceof Y2.XmlElement) || element.nodeName !== block.type)
|
|
1385
|
+
return;
|
|
1386
|
+
for (const name of ["before", "end"]) {
|
|
1387
|
+
const value = block.attrs?.[name];
|
|
1388
|
+
if (typeof value === "string" && element.getAttribute(name) !== value) {
|
|
1389
|
+
element.setAttribute(name, value);
|
|
1390
|
+
}
|
|
1391
|
+
}
|
|
1392
|
+
if (block.type === "box")
|
|
1393
|
+
respace(element, block.content ?? []);
|
|
1394
|
+
});
|
|
1395
|
+
}
|
|
1396
|
+
var HTML_NAMESPACE = "http://www.w3.org/1999/xhtml";
|
|
1397
|
+
function isElement(node) {
|
|
1398
|
+
return "tagName" in node;
|
|
1399
|
+
}
|
|
1400
|
+
function isText(node) {
|
|
1401
|
+
return node.nodeName === "#text";
|
|
1402
|
+
}
|
|
1403
|
+
function isCustom(tag) {
|
|
1404
|
+
return tag.includes("-");
|
|
1405
|
+
}
|
|
1406
|
+
function isLive(node) {
|
|
1407
|
+
return node.attrs.some((attribute) => attribute.name === "data-sixb-field" || attribute.name === "data-sixb-each");
|
|
1408
|
+
}
|
|
1409
|
+
function isOpaque(node) {
|
|
1410
|
+
return OPAQUE.has(node.tagName) || isCustom(node.tagName) || node.namespaceURI !== HTML_NAMESPACE || isLive(node);
|
|
1411
|
+
}
|
|
1412
|
+
function locatedThroughout(node) {
|
|
1413
|
+
return node.childNodes.every((child) => child.sourceCodeLocation !== undefined && child.sourceCodeLocation !== null && (!isElement(child) || locatedThroughout(child)));
|
|
1414
|
+
}
|
|
1415
|
+
function startOf(node) {
|
|
1416
|
+
return node.sourceCodeLocation?.startOffset ?? -1;
|
|
1417
|
+
}
|
|
1418
|
+
function endOf(node) {
|
|
1419
|
+
if (!isElement(node))
|
|
1420
|
+
return node.sourceCodeLocation?.endOffset ?? -1;
|
|
1421
|
+
const location = node.sourceCodeLocation;
|
|
1422
|
+
if (!location)
|
|
1423
|
+
return -1;
|
|
1424
|
+
if (location.endTag || !location.startTag)
|
|
1425
|
+
return location.endOffset;
|
|
1426
|
+
const last = node.childNodes.at(-1);
|
|
1427
|
+
return last ? Math.max(location.startTag.endOffset, endOf(last)) : location.startTag.endOffset;
|
|
1428
|
+
}
|
|
1429
|
+
|
|
1430
|
+
// src/artifacts/live/document.ts
|
|
1431
|
+
var LIVE_FILES2 = "files";
|
|
1432
|
+
var LIVE_ARTIFACT = "artifact";
|
|
1433
|
+
var LIVE_TEXT_EXTENSIONS = new Set([
|
|
1434
|
+
"html",
|
|
1435
|
+
"htm",
|
|
1436
|
+
"css",
|
|
1437
|
+
"js",
|
|
1438
|
+
"mjs",
|
|
1439
|
+
"json",
|
|
1440
|
+
"md",
|
|
1441
|
+
"markdown",
|
|
1442
|
+
"txt",
|
|
1443
|
+
"csv",
|
|
1444
|
+
"svg",
|
|
1445
|
+
"xml"
|
|
1446
|
+
]);
|
|
1447
|
+
function isLiveTextPath(path) {
|
|
1448
|
+
const extension = /\.([^./]+)$/.exec(path)?.[1]?.toLowerCase();
|
|
1449
|
+
return extension !== undefined && LIVE_TEXT_EXTENSIONS.has(extension);
|
|
1450
|
+
}
|
|
1451
|
+
var CANVAS_TEXT_KEYS = new Set(["text", "title", "label"]);
|
|
1452
|
+
var MARKDOWN_ENTRY = "document.md";
|
|
1453
|
+
var PAGE_ENTRY = "document.html";
|
|
1454
|
+
function structuredPath(kind) {
|
|
1455
|
+
if (kind === "canvas")
|
|
1456
|
+
return CANVAS_FILE2;
|
|
1457
|
+
return kind === "document" ? MARKDOWN_ENTRY : undefined;
|
|
1458
|
+
}
|
|
1459
|
+
function createArtifactDocument(kind, files, options = {}) {
|
|
1460
|
+
const doc = new Y3.Doc;
|
|
1461
|
+
if (options.clientID !== undefined)
|
|
1462
|
+
doc.clientID = options.clientID;
|
|
1463
|
+
doc.transact(() => {
|
|
1464
|
+
doc.getMap(LIVE_ARTIFACT).set("kind", kind);
|
|
1465
|
+
const map = doc.getMap(LIVE_FILES2);
|
|
1466
|
+
for (const path of [...files.keys()].sort()) {
|
|
1467
|
+
const file = files.get(path);
|
|
1468
|
+
map.set(path, entryOf(kind, path, file));
|
|
1469
|
+
}
|
|
1470
|
+
});
|
|
1471
|
+
return doc;
|
|
1472
|
+
}
|
|
1473
|
+
function documentKind(doc) {
|
|
1474
|
+
const kind = doc.getMap(LIVE_ARTIFACT).get("kind");
|
|
1475
|
+
if (typeof kind !== "string")
|
|
1476
|
+
throw new Error("[Sixb] This document holds no artifact.");
|
|
1477
|
+
return kind;
|
|
1478
|
+
}
|
|
1479
|
+
function documentFiles2(doc) {
|
|
1480
|
+
const files = new Map;
|
|
1481
|
+
doc.getMap(LIVE_FILES2).forEach((entry, path) => {
|
|
1482
|
+
const text = textOf(entry);
|
|
1483
|
+
files.set(path, text === undefined ? { file: entry } : { text });
|
|
1484
|
+
});
|
|
1485
|
+
return new Map([...files].sort(([left], [right]) => left < right ? -1 : 1));
|
|
1486
|
+
}
|
|
1487
|
+
function readChange2(doc, change) {
|
|
1488
|
+
const files = doc.getMap(LIVE_FILES2);
|
|
1489
|
+
const changes = [];
|
|
1490
|
+
const collect = (events) => {
|
|
1491
|
+
for (const event of events) {
|
|
1492
|
+
changes.push({
|
|
1493
|
+
target: event.target,
|
|
1494
|
+
keys: event.target === files ? [...event.keysChanged] : [],
|
|
1495
|
+
inserted: event.target instanceof Y3.XmlFragment ? event.changes.delta.flatMap((part) => Array.isArray(part.insert) ? part.insert : []) : []
|
|
1496
|
+
});
|
|
1497
|
+
}
|
|
1498
|
+
};
|
|
1499
|
+
files.observeDeep(collect);
|
|
1500
|
+
try {
|
|
1501
|
+
change();
|
|
1502
|
+
} finally {
|
|
1503
|
+
files.unobserveDeep(collect);
|
|
1504
|
+
}
|
|
1505
|
+
const whole = new Set;
|
|
1506
|
+
const blocks = new Map;
|
|
1507
|
+
const blockOf = (fragment, child) => {
|
|
1508
|
+
if (!(child instanceof Y3.XmlElement || child instanceof Y3.XmlText))
|
|
1509
|
+
return;
|
|
1510
|
+
const set = blocks.get(fragment) ?? new Set;
|
|
1511
|
+
set.add(child);
|
|
1512
|
+
blocks.set(fragment, set);
|
|
1513
|
+
};
|
|
1514
|
+
for (const { target, keys, inserted } of changes) {
|
|
1515
|
+
if (target === files) {
|
|
1516
|
+
for (const key of keys)
|
|
1517
|
+
whole.add(key);
|
|
1518
|
+
continue;
|
|
1519
|
+
}
|
|
1520
|
+
const path = [];
|
|
1521
|
+
for (let type = target;type && type !== files; ) {
|
|
1522
|
+
path.unshift(type);
|
|
1523
|
+
type = type.parent;
|
|
1524
|
+
}
|
|
1525
|
+
const [entry] = path;
|
|
1526
|
+
const key = entry?._item?.parentSub;
|
|
1527
|
+
if (!entry || typeof key !== "string")
|
|
1528
|
+
continue;
|
|
1529
|
+
const fragment = entry instanceof Y3.XmlFragment ? entry : isPageEntry2(entry) ? entry.get(PAGE_BODY2) : null;
|
|
1530
|
+
const at = fragment ? path.indexOf(fragment) : -1;
|
|
1531
|
+
if (!fragment || at < 0) {
|
|
1532
|
+
whole.add(key);
|
|
1533
|
+
} else if (target === fragment) {
|
|
1534
|
+
for (const child of inserted)
|
|
1535
|
+
blockOf(fragment, child);
|
|
1536
|
+
} else {
|
|
1537
|
+
blockOf(fragment, path[at + 1]);
|
|
1538
|
+
}
|
|
1539
|
+
}
|
|
1540
|
+
for (const key of whole)
|
|
1541
|
+
textOf(files.get(key));
|
|
1542
|
+
for (const [fragment, children] of blocks) {
|
|
1543
|
+
const content = blocksFromY([...children].filter((child) => child.parent === fragment));
|
|
1544
|
+
if (isPageEntry2(fragment.parent))
|
|
1545
|
+
pageHtml({ head: "", blocks: content, tail: "" });
|
|
1546
|
+
else
|
|
1547
|
+
blocksToMarkdown2({ type: "doc", content });
|
|
1548
|
+
}
|
|
1549
|
+
}
|
|
1550
|
+
function documentCanvas2(doc) {
|
|
1551
|
+
const entry = doc.getMap(LIVE_FILES2).get(CANVAS_FILE2);
|
|
1552
|
+
if (!(entry instanceof Y3.Map))
|
|
1553
|
+
return null;
|
|
1554
|
+
return {
|
|
1555
|
+
items: entry.get("items"),
|
|
1556
|
+
order: entry.get("order")
|
|
1557
|
+
};
|
|
1558
|
+
}
|
|
1559
|
+
function mergeIntoDocument2(doc, base, next, origin) {
|
|
1560
|
+
const kind = documentKind(doc);
|
|
1561
|
+
const structured = structuredPath(kind);
|
|
1562
|
+
doc.transact(() => {
|
|
1563
|
+
const files = doc.getMap(LIVE_FILES2);
|
|
1564
|
+
for (const [path, file] of next) {
|
|
1565
|
+
const before = base.get(path);
|
|
1566
|
+
if (before && sameFile(before, file))
|
|
1567
|
+
continue;
|
|
1568
|
+
const current = files.get(path);
|
|
1569
|
+
if ("file" in file) {
|
|
1570
|
+
if (!sameRef(current, file.file))
|
|
1571
|
+
files.set(path, file.file);
|
|
1572
|
+
continue;
|
|
1573
|
+
}
|
|
1574
|
+
const currentText = textOf(current);
|
|
1575
|
+
const baseText = before && "text" in before ? before.text : currentText;
|
|
1576
|
+
if (current instanceof Y3.XmlFragment) {
|
|
1577
|
+
if (currentText === baseText)
|
|
1578
|
+
patchFragment(current, file.text);
|
|
1579
|
+
else {
|
|
1580
|
+
patchBlocks(current, mergeMarkdownBlocks(baseText ?? "", blocksFromY(current.toArray()), file.text));
|
|
1581
|
+
}
|
|
1582
|
+
continue;
|
|
1583
|
+
}
|
|
1584
|
+
const page = kind === "document" && path === PAGE_ENTRY;
|
|
1585
|
+
if (isPageEntry2(current) || page && current instanceof Y3.Text) {
|
|
1586
|
+
const merged = mergePageSources(baseText ?? "", isPageEntry2(current) ? pageEntryBlocks(current) : currentText ?? "", file.text) ?? mergeText(baseText ?? "", currentText ?? "", file.text);
|
|
1587
|
+
if (isPageEntry2(current)) {
|
|
1588
|
+
if (!patchPageEntry(current, merged))
|
|
1589
|
+
files.set(path, new Y3.Text(merged));
|
|
1590
|
+
} else {
|
|
1591
|
+
const entry = pageEntry(merged);
|
|
1592
|
+
if (entry)
|
|
1593
|
+
files.set(path, entry);
|
|
1594
|
+
else
|
|
1595
|
+
patchText(current, merged);
|
|
1596
|
+
}
|
|
1597
|
+
continue;
|
|
1598
|
+
}
|
|
1599
|
+
if (path === structured) {
|
|
1600
|
+
if (current instanceof Y3.Map && mergeCanvas(current, baseText ?? "", file.text))
|
|
1601
|
+
continue;
|
|
1602
|
+
} else if (current instanceof Y3.Text) {
|
|
1603
|
+
patchText(current, mergeText(baseText ?? "", current.toString(), file.text));
|
|
1604
|
+
continue;
|
|
1605
|
+
}
|
|
1606
|
+
files.set(path, entryOf(kind, path, file));
|
|
1607
|
+
}
|
|
1608
|
+
for (const path of base.keys()) {
|
|
1609
|
+
if (!next.has(path))
|
|
1610
|
+
files.delete(path);
|
|
1611
|
+
}
|
|
1612
|
+
}, origin);
|
|
1613
|
+
}
|
|
1614
|
+
function holdPage(doc, clientID) {
|
|
1615
|
+
if (doc.getMap(LIVE_ARTIFACT).get("kind") !== "document")
|
|
1616
|
+
return;
|
|
1617
|
+
const entry = doc.getMap(LIVE_FILES2).get(PAGE_ENTRY);
|
|
1618
|
+
if (!(entry instanceof Y3.Text))
|
|
1619
|
+
return;
|
|
1620
|
+
const page = pageEntry(entry.toString());
|
|
1621
|
+
if (!page)
|
|
1622
|
+
return;
|
|
1623
|
+
const made = new Y3.Doc;
|
|
1624
|
+
made.clientID = clientID;
|
|
1625
|
+
Y3.applyUpdate(made, Y3.encodeStateAsUpdate(doc));
|
|
1626
|
+
const before = Y3.encodeStateVector(made);
|
|
1627
|
+
made.getMap(LIVE_FILES2).set(PAGE_ENTRY, page);
|
|
1628
|
+
Y3.applyUpdate(doc, Y3.encodeStateAsUpdate(made, before));
|
|
1629
|
+
made.destroy();
|
|
1630
|
+
}
|
|
1631
|
+
function entryOf(kind, path, file) {
|
|
1632
|
+
if ("file" in file)
|
|
1633
|
+
return { ...file.file };
|
|
1634
|
+
if (kind === "document" && path === PAGE_ENTRY)
|
|
1635
|
+
return pageEntry(file.text) ?? new Y3.Text(file.text);
|
|
1636
|
+
if (path === structuredPath(kind)) {
|
|
1637
|
+
if (kind === "document")
|
|
1638
|
+
return markdownFragment(file.text);
|
|
1639
|
+
const parsed = parseCanvas2(file.text);
|
|
1640
|
+
if ("canvas" in parsed)
|
|
1641
|
+
return canvasStructure(parsed.canvas.items);
|
|
1642
|
+
}
|
|
1643
|
+
return new Y3.Text(file.text);
|
|
1644
|
+
}
|
|
1645
|
+
function textOf(entry) {
|
|
1646
|
+
if (entry instanceof Y3.Text)
|
|
1647
|
+
return entry.toString();
|
|
1648
|
+
if (isPageEntry2(entry))
|
|
1649
|
+
return pageEntryHtml2(entry);
|
|
1650
|
+
if (entry instanceof Y3.Map)
|
|
1651
|
+
return canvasText(entry);
|
|
1652
|
+
if (entry instanceof Y3.XmlFragment)
|
|
1653
|
+
return fragmentMarkdown(entry);
|
|
1654
|
+
return;
|
|
1655
|
+
}
|
|
1656
|
+
function sameFile(left, right) {
|
|
1657
|
+
if ("text" in left)
|
|
1658
|
+
return "text" in right && left.text === right.text;
|
|
1659
|
+
return "file" in right && sameRef(left.file, right.file);
|
|
1660
|
+
}
|
|
1661
|
+
function sameRef(entry, file) {
|
|
1662
|
+
if (typeof entry !== "object" || entry === null || entry instanceof Y3.AbstractType)
|
|
1663
|
+
return false;
|
|
1664
|
+
return JSON.stringify(sortedEntries(entry)) === JSON.stringify(sortedEntries(file));
|
|
1665
|
+
}
|
|
1666
|
+
function sortedEntries(value) {
|
|
1667
|
+
return Object.entries(value).sort(([left], [right]) => left < right ? -1 : 1);
|
|
1668
|
+
}
|
|
1669
|
+
function patchText(text, to) {
|
|
1670
|
+
const edits = diffText(text.toString(), to);
|
|
1671
|
+
for (const edit of edits.reverse()) {
|
|
1672
|
+
if (edit.end > edit.start)
|
|
1673
|
+
text.delete(edit.start, edit.end - edit.start);
|
|
1674
|
+
if (edit.insert)
|
|
1675
|
+
text.insert(edit.start, edit.insert);
|
|
1676
|
+
}
|
|
1677
|
+
}
|
|
1678
|
+
function patchArray(array, to) {
|
|
1679
|
+
const hunks = diffSequences(array.toArray(), to);
|
|
1680
|
+
for (const hunk of hunks.reverse()) {
|
|
1681
|
+
if (hunk.aEnd > hunk.aStart)
|
|
1682
|
+
array.delete(hunk.aStart, hunk.aEnd - hunk.aStart);
|
|
1683
|
+
if (hunk.bEnd > hunk.bStart)
|
|
1684
|
+
array.insert(hunk.aStart, to.slice(hunk.bStart, hunk.bEnd));
|
|
1685
|
+
}
|
|
1686
|
+
}
|
|
1687
|
+
function canvasStructure(items) {
|
|
1688
|
+
const structure = new Y3.Map;
|
|
1689
|
+
const byId = new Y3.Map;
|
|
1690
|
+
for (const item of items)
|
|
1691
|
+
byId.set(item.id, canvasItemMap2(item));
|
|
1692
|
+
const order = new Y3.Array;
|
|
1693
|
+
order.push(items.map((item) => item.id));
|
|
1694
|
+
structure.set("items", byId);
|
|
1695
|
+
structure.set("order", order);
|
|
1696
|
+
return structure;
|
|
1697
|
+
}
|
|
1698
|
+
function canvasItemMap2(item) {
|
|
1699
|
+
const map = new Y3.Map;
|
|
1700
|
+
for (const [key, value] of Object.entries(item)) {
|
|
1701
|
+
if (value !== undefined)
|
|
1702
|
+
map.set(key, itemValue(key, value));
|
|
1703
|
+
}
|
|
1704
|
+
return map;
|
|
1705
|
+
}
|
|
1706
|
+
function itemValue(key, value) {
|
|
1707
|
+
return CANVAS_TEXT_KEYS.has(key) && typeof value === "string" ? new Y3.Text(value) : value;
|
|
1708
|
+
}
|
|
1709
|
+
function canvasItemObject2(map) {
|
|
1710
|
+
const item = {};
|
|
1711
|
+
map.forEach((value, key) => {
|
|
1712
|
+
item[key] = value instanceof Y3.Text ? value.toString() : value;
|
|
1713
|
+
});
|
|
1714
|
+
return item;
|
|
1715
|
+
}
|
|
1716
|
+
function canvasText(structure) {
|
|
1717
|
+
const byId = structure.get("items");
|
|
1718
|
+
const order = structure.get("order");
|
|
1719
|
+
const ids = [];
|
|
1720
|
+
const seen = new Set;
|
|
1721
|
+
for (const id of [...order.toArray(), ...[...byId.keys()].sort()]) {
|
|
1722
|
+
if (seen.has(id) || !byId.has(id))
|
|
1723
|
+
continue;
|
|
1724
|
+
const item = byId.get(id);
|
|
1725
|
+
if (unwritten(item))
|
|
1726
|
+
continue;
|
|
1727
|
+
seen.add(id);
|
|
1728
|
+
ids.push(id);
|
|
1729
|
+
}
|
|
1730
|
+
const items = ids.map((id) => canvasItemObject2(byId.get(id)));
|
|
1731
|
+
const joined = (end) => typeof end !== "string" || seen.has(end);
|
|
1732
|
+
const kept = items.filter((item) => item.type !== "arrow" || joined(item.from) && joined(item.to));
|
|
1733
|
+
return formatCanvas2({ items: kept });
|
|
1734
|
+
}
|
|
1735
|
+
function unwritten(item) {
|
|
1736
|
+
const type = item.get("type");
|
|
1737
|
+
if (type !== "note" && type !== "text")
|
|
1738
|
+
return false;
|
|
1739
|
+
const text = item.get("text");
|
|
1740
|
+
return (text instanceof Y3.Text ? text.toString() : typeof text === "string" ? text : "").trim() === "";
|
|
1741
|
+
}
|
|
1742
|
+
function mergeCanvas(structure, baseText, nextText) {
|
|
1743
|
+
const next = parseCanvas2(nextText);
|
|
1744
|
+
if (!("canvas" in next))
|
|
1745
|
+
return false;
|
|
1746
|
+
const parsedBase = parseCanvas2(baseText);
|
|
1747
|
+
const base = "canvas" in parsedBase ? parsedBase.canvas.items : [];
|
|
1748
|
+
const byId = structure.get("items");
|
|
1749
|
+
const order = structure.get("order");
|
|
1750
|
+
const baseById = new Map(base.map((item) => [item.id, item]));
|
|
1751
|
+
const nextById = new Map(next.canvas.items.map((item) => [item.id, item]));
|
|
1752
|
+
for (const [id, item] of nextById) {
|
|
1753
|
+
const before = baseById.get(id);
|
|
1754
|
+
const current = byId.get(id);
|
|
1755
|
+
if (!before || !current) {
|
|
1756
|
+
if (!before)
|
|
1757
|
+
byId.set(id, canvasItemMap2(item));
|
|
1758
|
+
continue;
|
|
1759
|
+
}
|
|
1760
|
+
mergeCanvasItem2(current, before, item);
|
|
1761
|
+
}
|
|
1762
|
+
for (const id of baseById.keys()) {
|
|
1763
|
+
if (!nextById.has(id))
|
|
1764
|
+
byId.delete(id);
|
|
1765
|
+
}
|
|
1766
|
+
const merged = mergeSequences(base.map((item) => item.id), order.toArray(), next.canvas.items.map((item) => item.id), interleave);
|
|
1767
|
+
const seen = new Set;
|
|
1768
|
+
patchArray(order, merged.filter((id) => {
|
|
1769
|
+
if (seen.has(id) || !byId.has(id))
|
|
1770
|
+
return false;
|
|
1771
|
+
seen.add(id);
|
|
1772
|
+
return true;
|
|
1773
|
+
}));
|
|
1774
|
+
return true;
|
|
1775
|
+
}
|
|
1776
|
+
function mergeCanvasItem2(current, base, next) {
|
|
1777
|
+
const before = base;
|
|
1778
|
+
const after = next;
|
|
1779
|
+
for (const key of new Set([...Object.keys(before), ...Object.keys(after)])) {
|
|
1780
|
+
const was = before[key];
|
|
1781
|
+
const value = after[key];
|
|
1782
|
+
if (JSON.stringify(was) === JSON.stringify(value))
|
|
1783
|
+
continue;
|
|
1784
|
+
if (value === undefined) {
|
|
1785
|
+
current.delete(key);
|
|
1786
|
+
continue;
|
|
1787
|
+
}
|
|
1788
|
+
const words = current.get(key);
|
|
1789
|
+
if (CANVAS_TEXT_KEYS.has(key) && typeof value === "string" && words instanceof Y3.Text) {
|
|
1790
|
+
patchText(words, mergeText(typeof was === "string" ? was : "", words.toString(), value));
|
|
1791
|
+
continue;
|
|
1792
|
+
}
|
|
1793
|
+
current.set(key, itemValue(key, value));
|
|
1794
|
+
}
|
|
1795
|
+
}
|
|
1796
|
+
|
|
1797
|
+
export { mergeText, markdownToBlocks2, blocksToMarkdown2, PAGE_MARK_TAGS2, PAGE_TEXT_TAGS2, PAGE_BODY2, isPageEntry2, pageEntryHtml2, LIVE_FILES2, isLiveTextPath, createArtifactDocument, documentFiles2, readChange2, documentCanvas2, mergeIntoDocument2, holdPage, canvasItemMap2, canvasItemObject2, mergeCanvasItem2 };
|
|
1798
|
+
|
|
1799
|
+
//# debugId=9170A2751E5F5FCC64756E2164756E21
|