plitejs 0.0.1 → 54.0.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (854) hide show
  1. package/LICENSE +4 -1
  2. package/README.md +83 -0
  3. package/dist/annotations/index.d.ts +2 -0
  4. package/dist/annotations/index.js +2 -0
  5. package/dist/annotations/store.d.ts +50 -0
  6. package/dist/annotations/store.js +244 -0
  7. package/dist/authored/authored.d.ts +116 -0
  8. package/dist/authored/authored.js +1271 -0
  9. package/dist/authored/changes.js +365 -0
  10. package/dist/authored/comparison.d.ts +41 -0
  11. package/dist/authored/comparison.js +270 -0
  12. package/dist/authored/decision-window.js +42 -0
  13. package/dist/authored/decision.js +306 -0
  14. package/dist/authored/facts/admission.js +388 -0
  15. package/dist/authored/facts/compact.d.ts +2 -0
  16. package/dist/authored/facts/compact.js +91 -0
  17. package/dist/authored/facts/dependencies.d.ts +5 -0
  18. package/dist/authored/facts/dependencies.js +66 -0
  19. package/dist/authored/facts/editing.js +12 -0
  20. package/dist/authored/facts/facts.d.ts +8 -0
  21. package/dist/authored/facts/facts.js +535 -0
  22. package/dist/authored/facts/records.d.ts +28 -0
  23. package/dist/authored/facts/records.js +226 -0
  24. package/dist/authored/facts/settle.js +529 -0
  25. package/dist/authored/format.d.ts +34 -0
  26. package/dist/authored/format.js +175 -0
  27. package/dist/authored/index.d.ts +9 -0
  28. package/dist/authored/index.js +5 -0
  29. package/dist/authored/ledger/book.js +809 -0
  30. package/dist/authored/ledger/cards.js +223 -0
  31. package/dist/authored/ledger/ledger.js +830 -0
  32. package/dist/authored/ledger/level.js +1081 -0
  33. package/dist/authored/ledger/links.js +20 -0
  34. package/dist/authored/ledger/pairs.js +334 -0
  35. package/dist/authored/ledger/places.js +524 -0
  36. package/dist/authored/ledger/preview-lens.js +252 -0
  37. package/dist/authored/ledger/projection.js +163 -0
  38. package/dist/authored/ledger/roots.js +11 -0
  39. package/dist/authored/ledger/runs.js +480 -0
  40. package/dist/authored/ledger/slots.js +330 -0
  41. package/dist/authored/ledger/work.js +66 -0
  42. package/dist/authored/refusal.d.ts +33 -0
  43. package/dist/authored/refusal.js +188 -0
  44. package/dist/authored/resolve-schema.js +62 -0
  45. package/dist/authored/tree/alignment.js +456 -0
  46. package/dist/authored/tree/carried.js +205 -0
  47. package/dist/authored/tree/command-values.js +344 -0
  48. package/dist/authored/tree/cuts.js +320 -0
  49. package/dist/authored/tree/grid.js +49 -0
  50. package/dist/authored/tree/halves.js +120 -0
  51. package/dist/authored/tree/holders.js +345 -0
  52. package/dist/authored/tree/holds.js +135 -0
  53. package/dist/authored/tree/layers.d.ts +49 -0
  54. package/dist/authored/tree/layers.js +354 -0
  55. package/dist/authored/tree/marks.d.ts +136 -0
  56. package/dist/authored/tree/marks.js +263 -0
  57. package/dist/authored/tree/proposed.js +212 -0
  58. package/dist/authored/tree/readiness.js +545 -0
  59. package/dist/authored/tree/record-completion.js +423 -0
  60. package/dist/authored/tree/record.js +2908 -0
  61. package/dist/authored/tree/reserves.js +449 -0
  62. package/dist/authored/tree/resolve.d.ts +9 -0
  63. package/dist/authored/tree/resolve.js +1860 -0
  64. package/dist/authored/tree/shown.js +153 -0
  65. package/dist/authored/tree/spare-lines.js +119 -0
  66. package/dist/authored/tree/spares.js +61 -0
  67. package/dist/authored/types.d.ts +177 -0
  68. package/dist/core/anchor-state.d.ts +15 -0
  69. package/dist/core/anchor-state.js +792 -0
  70. package/dist/core/anchor.d.ts +34 -0
  71. package/dist/core/anchor.js +843 -0
  72. package/dist/core/authored-document-capability.d.ts +106 -0
  73. package/dist/core/authored-document-capability.js +6 -0
  74. package/dist/core/authored-runtime.d.ts +10 -0
  75. package/dist/core/authored-runtime.js +67 -0
  76. package/dist/core/authored-veto.d.ts +30 -0
  77. package/dist/core/authored-veto.js +6 -0
  78. package/dist/core/change/builder.d.ts +546 -0
  79. package/dist/core/change/builder.js +1120 -0
  80. package/dist/core/change/carried-projection.js +1518 -0
  81. package/dist/core/change/carried-run.d.ts +26 -0
  82. package/dist/core/change/carried-run.js +251 -0
  83. package/dist/core/change/carry-program.js +537 -0
  84. package/dist/core/change/classification.d.ts +22 -0
  85. package/dist/core/change/classification.js +205 -0
  86. package/dist/core/change/cross-rule.js +238 -0
  87. package/dist/core/change/cross.js +577 -0
  88. package/dist/core/change/document-change.d.ts +137 -0
  89. package/dist/core/change/document-change.js +872 -0
  90. package/dist/core/change/document-index.d.ts +117 -0
  91. package/dist/core/change/document-index.js +542 -0
  92. package/dist/core/change/draft-facts.js +323 -0
  93. package/dist/core/change/enclosure.d.ts +12 -0
  94. package/dist/core/change/enclosure.js +272 -0
  95. package/dist/core/change/join.js +751 -0
  96. package/dist/core/change/json.d.ts +4 -0
  97. package/dist/core/change/json.js +26 -0
  98. package/dist/core/change/lazy-root.d.ts +1 -0
  99. package/dist/core/change/lazy-root.js +73 -0
  100. package/dist/core/change/lineage.d.ts +49 -0
  101. package/dist/core/change/lineage.js +390 -0
  102. package/dist/core/change/mapping.d.ts +31 -0
  103. package/dist/core/change/mapping.js +186 -0
  104. package/dist/core/change/new-letters.d.ts +14 -0
  105. package/dist/core/change/new-letters.js +139 -0
  106. package/dist/core/change/range-association.js +10 -0
  107. package/dist/core/change/read-back.d.ts +7 -0
  108. package/dist/core/change/read-back.js +7 -0
  109. package/dist/core/change/record.d.ts +59 -0
  110. package/dist/core/change/record.js +346 -0
  111. package/dist/core/change/retraction.js +97 -0
  112. package/dist/core/change/root-change.d.ts +180 -0
  113. package/dist/core/change/root-change.js +3544 -0
  114. package/dist/core/change/slice-facts.js +89 -0
  115. package/dist/core/change/text-splices.js +98 -0
  116. package/dist/core/change/tokens.d.ts +97 -0
  117. package/dist/core/change/tokens.js +449 -0
  118. package/dist/core/change/transform.d.ts +36 -0
  119. package/dist/core/change/transform.js +97 -0
  120. package/dist/core/change/wrap-fidelity.js +295 -0
  121. package/dist/core/change-events.js +223 -0
  122. package/dist/core/clone.js +28 -0
  123. package/dist/core/command-definition.d.ts +25 -0
  124. package/dist/core/command-definition.js +48 -0
  125. package/dist/core/command-document.d.ts +4 -0
  126. package/dist/core/command-document.js +20 -0
  127. package/dist/core/command-frame.js +628 -0
  128. package/dist/core/command-registry.d.ts +36 -0
  129. package/dist/core/command-registry.js +283 -0
  130. package/dist/core/commit-publication.js +40 -0
  131. package/dist/core/commit.d.ts +26 -0
  132. package/dist/core/commit.js +686 -0
  133. package/dist/core/composition-stamp.d.ts +14 -0
  134. package/dist/core/composition-stamp.js +79 -0
  135. package/dist/core/content-completion.d.ts +4 -0
  136. package/dist/core/content-completion.js +343 -0
  137. package/dist/core/content-landing.js +124 -0
  138. package/dist/core/content-slice-roots.js +36 -0
  139. package/dist/core/content-slice.d.ts +38 -0
  140. package/dist/core/content-slice.js +253 -0
  141. package/dist/core/content.js +18 -0
  142. package/dist/core/correction.js +25 -0
  143. package/dist/core/default-storage.js +53 -0
  144. package/dist/core/document-admission.d.ts +4 -0
  145. package/dist/core/document-admission.js +64 -0
  146. package/dist/core/document-change.d.ts +3 -0
  147. package/dist/core/document-recorder.d.ts +6 -0
  148. package/dist/core/document-recorder.js +67 -0
  149. package/dist/core/document-shape.d.ts +68 -0
  150. package/dist/core/document-shape.js +173 -0
  151. package/dist/core/document-view-read.d.ts +16 -0
  152. package/dist/core/document-view-read.js +36 -0
  153. package/dist/core/draft-track.d.ts +3 -0
  154. package/dist/core/draft-track.js +90 -0
  155. package/dist/core/editor-commands.d.ts +99 -0
  156. package/dist/core/editor-commands.js +505 -0
  157. package/dist/core/editor-lifecycle-api.d.ts +8 -0
  158. package/dist/core/editor-lifecycle-api.js +219 -0
  159. package/dist/core/editor-lifetime.js +12 -0
  160. package/dist/core/editor-owner.d.ts +24 -0
  161. package/dist/core/editor-owner.js +78 -0
  162. package/dist/core/editor-read-execution.d.ts +6 -0
  163. package/dist/core/editor-read-execution.js +64 -0
  164. package/dist/core/editor-read-runtime.js +176 -0
  165. package/dist/core/editor-reads.d.ts +128 -0
  166. package/dist/core/editor-reads.js +63 -0
  167. package/dist/core/editor-runtime.d.ts +112 -0
  168. package/dist/core/editor-runtime.js +20 -0
  169. package/dist/core/editor-schema.d.ts +314 -0
  170. package/dist/core/editor-schema.js +2295 -0
  171. package/dist/core/editor-view-lifetime.js +23 -0
  172. package/dist/core/element-owned-root-index.d.ts +4 -0
  173. package/dist/core/element-owned-root-index.js +353 -0
  174. package/dist/core/get-content-slice.js +118 -0
  175. package/dist/core/get-fragment.js +22 -0
  176. package/dist/core/identity-owner.js +697 -0
  177. package/dist/core/import-content-slice.js +26 -0
  178. package/dist/core/initial-value.js +87 -0
  179. package/dist/core/insert-limit.js +81 -0
  180. package/dist/core/is-empty-element.js +20 -0
  181. package/dist/core/json-fingerprint.js +16 -0
  182. package/dist/core/landing.d.ts +11 -0
  183. package/dist/core/landing.js +279 -0
  184. package/dist/core/lifecycle-error.d.ts +11 -0
  185. package/dist/core/lifecycle-error.js +68 -0
  186. package/dist/core/listener-state.d.ts +1 -0
  187. package/dist/core/listener-state.js +59 -0
  188. package/dist/core/measured-sequence.d.ts +43 -0
  189. package/dist/core/measured-sequence.js +404 -0
  190. package/dist/core/missing-reference.js +15 -0
  191. package/dist/core/native-grouping-input.js +8 -0
  192. package/dist/core/node-property-mutation.js +10 -0
  193. package/dist/core/node-selection.js +85 -0
  194. package/dist/core/node-write-veto.d.ts +37 -0
  195. package/dist/core/node-write-veto.js +17 -0
  196. package/dist/core/persisted-document.d.ts +6 -0
  197. package/dist/core/persisted-document.js +39 -0
  198. package/dist/core/persistent-map.js +139 -0
  199. package/dist/core/plain-text.d.ts +32 -0
  200. package/dist/core/plain-text.js +92 -0
  201. package/dist/core/plugin-dispatch.d.ts +21 -0
  202. package/dist/core/plugin-dispatch.js +166 -0
  203. package/dist/core/plugin-point.d.ts +6 -0
  204. package/dist/core/plugin-point.js +21 -0
  205. package/dist/core/plugin-registry.d.ts +78 -0
  206. package/dist/core/plugin-registry.js +485 -0
  207. package/dist/core/plugin-slot.d.ts +23 -0
  208. package/dist/core/plugin-slot.js +30 -0
  209. package/dist/core/plugin.d.ts +125 -0
  210. package/dist/core/plugin.js +1485 -0
  211. package/dist/core/prefix-occupant-join.js +52 -0
  212. package/dist/core/profiling.js +18 -0
  213. package/dist/core/property-validity.d.ts +14 -0
  214. package/dist/core/property-validity.js +65 -0
  215. package/dist/core/public-root.d.ts +10 -0
  216. package/dist/core/public-root.js +50 -0
  217. package/dist/core/public-state.d.ts +191 -0
  218. package/dist/core/public-state.js +6772 -0
  219. package/dist/core/read-definition.js +22 -0
  220. package/dist/core/read-registry.js +127 -0
  221. package/dist/core/record-store.d.ts +12 -0
  222. package/dist/core/record-store.js +297 -0
  223. package/dist/core/refusal.d.ts +1 -0
  224. package/dist/core/refusal.js +40 -0
  225. package/dist/core/representation.d.ts +11 -0
  226. package/dist/core/representation.js +844 -0
  227. package/dist/core/resolved-token-cursor.d.ts +21 -0
  228. package/dist/core/resolved-token-cursor.js +294 -0
  229. package/dist/core/root-entries.js +121 -0
  230. package/dist/core/root-ownership.d.ts +19 -0
  231. package/dist/core/root-ownership.js +354 -0
  232. package/dist/core/root-target.d.ts +7 -0
  233. package/dist/core/root-target.js +281 -0
  234. package/dist/core/same-result.d.ts +18 -0
  235. package/dist/core/same-result.js +96 -0
  236. package/dist/core/schema-compiler.d.ts +345 -0
  237. package/dist/core/schema-compiler.js +3166 -0
  238. package/dist/core/schema-contribution-registry.d.ts +12 -0
  239. package/dist/core/schema-contribution-registry.js +88 -0
  240. package/dist/core/schema-definition.d.ts +307 -0
  241. package/dist/core/schema-definition.js +628 -0
  242. package/dist/core/schema-source.internal.d.ts +49 -0
  243. package/dist/core/schema-validation.d.ts +11 -0
  244. package/dist/core/schema-validation.js +85 -0
  245. package/dist/core/screen-reader-announcement.d.ts +13 -0
  246. package/dist/core/screen-reader-announcement.js +17 -0
  247. package/dist/core/selection-protocol.d.ts +38 -0
  248. package/dist/core/selection-protocol.js +523 -0
  249. package/dist/core/selection-state.js +9 -0
  250. package/dist/core/semantic-update-method.d.ts +11 -0
  251. package/dist/core/semantic-update-method.js +26 -0
  252. package/dist/core/set-root.d.ts +3 -0
  253. package/dist/core/set-root.js +244 -0
  254. package/dist/core/slice-end-matter.js +77 -0
  255. package/dist/core/slice-fit/compiled-slice-fitter.d.ts +56 -0
  256. package/dist/core/slice-fit/compiled-slice-fitter.js +2087 -0
  257. package/dist/core/slice-fit/fit-report.d.ts +36 -0
  258. package/dist/core/slice-fit/fit-report.js +122 -0
  259. package/dist/core/slice-fit/frontier.js +98 -0
  260. package/dist/core/slice-fit/origin.js +57 -0
  261. package/dist/core/slice-fit/provenance.d.ts +30 -0
  262. package/dist/core/slice-fit/provenance.js +245 -0
  263. package/dist/core/slice-identities.js +21 -0
  264. package/dist/core/slice-landing-types.d.ts +61 -0
  265. package/dist/core/slice-landing.js +124 -0
  266. package/dist/core/snapshot-index.d.ts +13 -0
  267. package/dist/core/snapshot-index.js +860 -0
  268. package/dist/core/state-field.d.ts +12 -0
  269. package/dist/core/state-field.js +102 -0
  270. package/dist/core/state-fields.js +36 -0
  271. package/dist/core/survival.js +61 -0
  272. package/dist/core/target-runtime.d.ts +5 -0
  273. package/dist/core/target-runtime.js +42 -0
  274. package/dist/core/transaction-values.d.ts +47 -0
  275. package/dist/core/transaction-values.js +66 -0
  276. package/dist/core/transfer-guard.js +299 -0
  277. package/dist/core/transfer-types.d.ts +170 -0
  278. package/dist/core/transfer.d.ts +72 -0
  279. package/dist/core/transfer.js +655 -0
  280. package/dist/core/tx-only.d.ts +64 -0
  281. package/dist/core/tx-only.js +84 -0
  282. package/dist/core/unique-values.js +298 -0
  283. package/dist/core/update-context.js +28 -0
  284. package/dist/core/update-policy.d.ts +17 -0
  285. package/dist/core/update-policy.js +45 -0
  286. package/dist/core/value-codec.d.ts +35 -0
  287. package/dist/core/value-codec.js +240 -0
  288. package/dist/core/view-carets.d.ts +39 -0
  289. package/dist/core/view-carets.js +676 -0
  290. package/dist/core/view-presentation.d.ts +9 -0
  291. package/dist/core/view-presentation.js +70 -0
  292. package/dist/core/work.d.ts +192 -0
  293. package/dist/core/work.js +122 -0
  294. package/dist/core/writable-text.js +37 -0
  295. package/dist/create-editor.d.ts +187 -0
  296. package/dist/create-editor.js +281 -0
  297. package/dist/diff/index.d.ts +4 -0
  298. package/dist/diff/index.js +2 -0
  299. package/dist/diff/lib/compare.d.ts +33 -0
  300. package/dist/diff/lib/compare.js +459 -0
  301. package/dist/diff/lib/comparison-align.js +324 -0
  302. package/dist/diff/lib/comparison-index.js +160 -0
  303. package/dist/diff/lib/comparison-internal.js +108 -0
  304. package/dist/diff/lib/comparison-matcher.js +1221 -0
  305. package/dist/diff/lib/comparison-moves.js +151 -0
  306. package/dist/diff/lib/comparison-plan.js +556 -0
  307. package/dist/diff/lib/comparison-types.d.ts +174 -0
  308. package/dist/diff/lib/index.d.ts +3 -0
  309. package/dist/dom/dom-soft-line-end.d.ts +3 -0
  310. package/dist/dom/dom-soft-line-end.js +295 -0
  311. package/dist/dom/index.d.ts +19 -0
  312. package/dist/dom/index.js +16 -0
  313. package/dist/dom/internal/index.d.ts +15 -0
  314. package/dist/dom/plugin/data-transfer-format.d.ts +90 -0
  315. package/dist/dom/plugin/data-transfer-format.js +525 -0
  316. package/dist/dom/plugin/dom-clipboard-runtime.d.ts +50 -0
  317. package/dist/dom/plugin/dom-clipboard-runtime.js +482 -0
  318. package/dist/dom/plugin/dom-coverage.d.ts +140 -0
  319. package/dist/dom/plugin/dom-coverage.js +443 -0
  320. package/dist/dom/plugin/dom-drag-scroll.js +176 -0
  321. package/dist/dom/plugin/dom-drag.d.ts +54 -0
  322. package/dist/dom/plugin/dom-drag.js +507 -0
  323. package/dist/dom/plugin/dom-editor.d.ts +421 -0
  324. package/dist/dom/plugin/dom-editor.js +1316 -0
  325. package/dist/dom/plugin/dom-event-range-targets.js +39 -0
  326. package/dist/dom/plugin/dom-geometry.d.ts +11 -0
  327. package/dist/dom/plugin/dom-geometry.js +888 -0
  328. package/dist/dom/plugin/dom-input-runtime.d.ts +1 -0
  329. package/dist/dom/plugin/dom-input-runtime.js +571 -0
  330. package/dist/dom/plugin/dom-integrity-observer.js +436 -0
  331. package/dist/dom/plugin/dom-node-path.js +61 -0
  332. package/dist/dom/plugin/dom-phase-scheduler.d.ts +1 -0
  333. package/dist/dom/plugin/dom-phase-scheduler.js +284 -0
  334. package/dist/dom/plugin/dom-root-runtime.d.ts +10 -0
  335. package/dist/dom/plugin/dom-root-runtime.js +716 -0
  336. package/dist/dom/plugin/dom-sync-mutation-ownership.d.ts +1 -0
  337. package/dist/dom/plugin/dom-sync-mutation-ownership.js +120 -0
  338. package/dist/dom/plugin/dom-text-flow-index.js +396 -0
  339. package/dist/dom/plugin/dom-text-freshness.js +188 -0
  340. package/dist/dom/plugin/dom-text-proofs.d.ts +2 -0
  341. package/dist/dom/plugin/dom-text-proofs.js +350 -0
  342. package/dist/dom/plugin/dom-view-caret.js +28 -0
  343. package/dist/dom/plugin/with-dom.d.ts +53 -0
  344. package/dist/dom/plugin/with-dom.js +101 -0
  345. package/dist/dom/utils/constants.d.ts +5 -0
  346. package/dist/dom/utils/constants.js +5 -0
  347. package/dist/dom/utils/diff-text.d.ts +51 -0
  348. package/dist/dom/utils/diff-text.js +264 -0
  349. package/dist/dom/utils/dom.d.ts +104 -0
  350. package/dist/dom/utils/dom.js +257 -0
  351. package/dist/dom/utils/drag-session.d.ts +2 -0
  352. package/dist/dom/utils/drag-session.js +115 -0
  353. package/dist/dom/utils/drop-indicator.d.ts +18 -0
  354. package/dist/dom/utils/drop-indicator.js +36 -0
  355. package/dist/dom/utils/environment.d.ts +12 -0
  356. package/dist/dom/utils/environment.js +118 -0
  357. package/dist/dom/utils/hotkey-match.d.ts +36 -0
  358. package/dist/dom/utils/hotkey-match.js +208 -0
  359. package/dist/dom/utils/hotkeys.d.ts +32 -0
  360. package/dist/dom/utils/hotkeys.js +121 -0
  361. package/dist/dom/utils/key.d.ts +14 -0
  362. package/dist/dom/utils/key.js +18 -0
  363. package/dist/dom/utils/plite-dom-markers.d.ts +26 -0
  364. package/dist/dom/utils/plite-dom-markers.js +25 -0
  365. package/dist/dom/utils/selection-writes.d.ts +18 -0
  366. package/dist/dom/utils/selection-writes.js +63 -0
  367. package/dist/dom/utils/weak-maps.d.ts +2 -0
  368. package/dist/dom/utils/weak-maps.js +51 -0
  369. package/dist/editor/above.js +30 -0
  370. package/dist/editor/add-mark.js +79 -0
  371. package/dist/editor/adjacent-character-point.js +120 -0
  372. package/dist/editor/after.js +37 -0
  373. package/dist/editor/before.js +124 -0
  374. package/dist/editor/block-void-break.js +20 -0
  375. package/dist/editor/correct-document.js +225 -0
  376. package/dist/editor/delete-backward.js +64 -0
  377. package/dist/editor/delete-forward.js +11 -0
  378. package/dist/editor/delete-fragment.js +40 -0
  379. package/dist/editor/edges.js +5 -0
  380. package/dist/editor/element-read-only.js +35 -0
  381. package/dist/editor/end.d.ts +7 -0
  382. package/dist/editor/end.js +5 -0
  383. package/dist/editor/exit-break.js +51 -0
  384. package/dist/editor/first.js +8 -0
  385. package/dist/editor/get-void.js +9 -0
  386. package/dist/editor/has-blocks.js +6 -0
  387. package/dist/editor/has-inlines.js +6 -0
  388. package/dist/editor/has-path.js +5 -0
  389. package/dist/editor/has-texts.js +5 -0
  390. package/dist/editor/insert-break.js +77 -0
  391. package/dist/editor/insert-default-child.js +55 -0
  392. package/dist/editor/insert-soft-break.js +14 -0
  393. package/dist/editor/insert-text.js +83 -0
  394. package/dist/editor/is-block.js +5 -0
  395. package/dist/editor/is-edge.js +5 -0
  396. package/dist/editor/is-editor.js +13 -0
  397. package/dist/editor/is-empty.js +6 -0
  398. package/dist/editor/is-end.js +9 -0
  399. package/dist/editor/is-start.js +9 -0
  400. package/dist/editor/last.js +20 -0
  401. package/dist/editor/leaf.js +9 -0
  402. package/dist/editor/levels.js +21 -0
  403. package/dist/editor/next.js +46 -0
  404. package/dist/editor/node.js +9 -0
  405. package/dist/editor/nodes.js +106 -0
  406. package/dist/editor/parent.js +14 -0
  407. package/dist/editor/path.js +26 -0
  408. package/dist/editor/point.js +52 -0
  409. package/dist/editor/positions.js +322 -0
  410. package/dist/editor/previous.js +48 -0
  411. package/dist/editor/project-range.js +6 -0
  412. package/dist/editor/range.js +12 -0
  413. package/dist/editor/remove-mark.js +65 -0
  414. package/dist/editor/should-merge-nodes-remove-prev-node.js +11 -0
  415. package/dist/editor/string.js +35 -0
  416. package/dist/editor/toggle-mark.js +71 -0
  417. package/dist/editor/unhang-range.js +71 -0
  418. package/dist/editor-runtime-view.d.ts +33 -0
  419. package/dist/editor-runtime-view.js +788 -0
  420. package/dist/history/history-carets.js +127 -0
  421. package/dist/history/history-character-map.js +425 -0
  422. package/dist/history/history-codec.js +176 -0
  423. package/dist/history/history-merge-policy.js +164 -0
  424. package/dist/history/history-plugin.d.ts +71 -0
  425. package/dist/history/history-plugin.js +814 -0
  426. package/dist/history/history-replay.js +799 -0
  427. package/dist/history/history-selection.js +75 -0
  428. package/dist/history/history-state.js +1287 -0
  429. package/dist/history/history.d.ts +112 -0
  430. package/dist/history/history.js +29 -0
  431. package/dist/history/index.d.ts +4 -0
  432. package/dist/history/index.js +3 -0
  433. package/dist/hyperscript/creators.d.ts +51 -0
  434. package/dist/hyperscript/creators.js +173 -0
  435. package/dist/hyperscript/hyperscript.d.ts +36 -0
  436. package/dist/hyperscript/hyperscript.js +66 -0
  437. package/dist/hyperscript/index.d.ts +20 -0
  438. package/dist/hyperscript/index.js +9 -0
  439. package/dist/hyperscript/tokens.d.ts +31 -0
  440. package/dist/hyperscript/tokens.js +63 -0
  441. package/dist/index.d.ts +51 -0
  442. package/dist/index.js +35 -0
  443. package/dist/interfaces/decoration.d.ts +35 -0
  444. package/dist/interfaces/editor.d.ts +2783 -0
  445. package/dist/interfaces/editor.js +348 -0
  446. package/dist/interfaces/element.d.ts +66 -0
  447. package/dist/interfaces/element.js +34 -0
  448. package/dist/interfaces/index.d.ts +13 -0
  449. package/dist/interfaces/json.d.ts +7 -0
  450. package/dist/interfaces/location.d.ts +50 -0
  451. package/dist/interfaces/location.js +26 -0
  452. package/dist/interfaces/node.d.ts +306 -0
  453. package/dist/interfaces/node.js +339 -0
  454. package/dist/interfaces/path.d.ts +118 -0
  455. package/dist/interfaces/path.js +116 -0
  456. package/dist/interfaces/point.d.ts +45 -0
  457. package/dist/interfaces/point.js +32 -0
  458. package/dist/interfaces/range.d.ts +80 -0
  459. package/dist/interfaces/range.js +85 -0
  460. package/dist/interfaces/schema-validation.d.ts +33 -0
  461. package/dist/interfaces/schema.d.ts +870 -0
  462. package/dist/interfaces/selection.d.ts +61 -0
  463. package/dist/interfaces/selection.js +106 -0
  464. package/dist/interfaces/text.d.ts +68 -0
  465. package/dist/interfaces/text.js +52 -0
  466. package/dist/interfaces/transforms/node.d.ts +222 -0
  467. package/dist/interfaces/transforms/selection.d.ts +48 -0
  468. package/dist/interfaces/transforms/text.d.ts +58 -0
  469. package/dist/internal/browser-protocol.d.ts +5 -0
  470. package/dist/internal/browser-protocol.js +5 -0
  471. package/dist/internal/document-range.d.ts +9 -0
  472. package/dist/internal/document-range.js +31 -0
  473. package/dist/internal/editor-options.d.ts +37 -0
  474. package/dist/internal/editor-options.js +36 -0
  475. package/dist/internal/fail-invariant.d.ts +4 -0
  476. package/dist/internal/fail-invariant.js +6 -0
  477. package/dist/internal/get-defined.js +7 -0
  478. package/dist/internal/index.d.ts +54 -0
  479. package/dist/internal/index.js +52 -0
  480. package/dist/internal/law-check.js +7 -0
  481. package/dist/internal/range-text-marks.js +31 -0
  482. package/dist/internal/root-location.d.ts +23 -0
  483. package/dist/internal/root-location.js +86 -0
  484. package/dist/internal/text-run.d.ts +13 -0
  485. package/dist/internal/text-run.js +44 -0
  486. package/dist/internal/view/annotation-store-metrics.d.ts +11 -0
  487. package/dist/internal/view/annotation-store-metrics.js +12 -0
  488. package/dist/internal/view/mapped-view-store.js +121 -0
  489. package/dist/internal/view/stable-id-mapped-source.js +467 -0
  490. package/dist/internal/view/view-source.d.ts +20 -0
  491. package/dist/pagination/index.d.ts +175 -0
  492. package/dist/pagination/index.js +694 -0
  493. package/dist/pagination/page-composition.internal.js +313 -0
  494. package/dist/pagination/page-geometry.internal.js +99 -0
  495. package/dist/pagination/page-layout-engine-invalidation.internal.js +20 -0
  496. package/dist/pagination/page-mount-plan.js +84 -0
  497. package/dist/pagination/paged-view-lines.js +163 -0
  498. package/dist/pagination/react.d.ts +35 -0
  499. package/dist/pagination/react.js +1103 -0
  500. package/dist/range-projection.d.ts +7 -0
  501. package/dist/range-projection.js +50 -0
  502. package/dist/react/components/dom-coverage-boundary.d.ts +14 -0
  503. package/dist/react/components/dom-coverage-boundary.js +143 -0
  504. package/dist/react/components/editable-descendant-binding.js +70 -0
  505. package/dist/react/components/editable-dom-commit-fence.js +107 -0
  506. package/dist/react/components/editable-element-placement.d.ts +2 -0
  507. package/dist/react/components/editable-element-placement.js +117 -0
  508. package/dist/react/components/editable-external-text.js +47 -0
  509. package/dist/react/components/editable-node-equality.js +25 -0
  510. package/dist/react/components/editable-rendered-element.d.ts +3 -0
  511. package/dist/react/components/editable-rendered-element.js +61 -0
  512. package/dist/react/components/editable-text-blocks.d.ts +192 -0
  513. package/dist/react/components/editable-text-blocks.js +896 -0
  514. package/dist/react/components/editable-text-containers.d.ts +3 -0
  515. package/dist/react/components/editable-text-containers.js +28 -0
  516. package/dist/react/components/editable-text-flow.js +1039 -0
  517. package/dist/react/components/editable-text-pieces.d.ts +7 -0
  518. package/dist/react/components/editable-text-pieces.js +193 -0
  519. package/dist/react/components/editable-text.d.ts +80 -0
  520. package/dist/react/components/editable-text.js +322 -0
  521. package/dist/react/components/editable.d.ts +35 -0
  522. package/dist/react/components/editable.js +406 -0
  523. package/dist/react/components/editor-announcement-live-region.js +113 -0
  524. package/dist/react/components/plite-element.d.ts +18 -0
  525. package/dist/react/components/plite-element.js +54 -0
  526. package/dist/react/components/plite-leaf.d.ts +18 -0
  527. package/dist/react/components/plite-leaf.js +21 -0
  528. package/dist/react/components/plite-placeholder.d.ts +19 -0
  529. package/dist/react/components/plite-placeholder.js +39 -0
  530. package/dist/react/components/plite-spacer.js +14 -0
  531. package/dist/react/components/plite-text.d.ts +23 -0
  532. package/dist/react/components/plite-text.js +32 -0
  533. package/dist/react/components/plite-void-shell.js +49 -0
  534. package/dist/react/components/plite.d.ts +45 -0
  535. package/dist/react/components/plite.js +297 -0
  536. package/dist/react/components/text-string.js +18 -0
  537. package/dist/react/components/windowed-editable.internal.js +51 -0
  538. package/dist/react/components/zero-width-string.js +26 -0
  539. package/dist/react/context.js +11 -0
  540. package/dist/react/decoration-context.d.ts +2 -0
  541. package/dist/react/decoration-context.js +22 -0
  542. package/dist/react/decoration-source.d.ts +11 -0
  543. package/dist/react/decoration-source.js +1030 -0
  544. package/dist/react/dom-text-sync.d.ts +24 -0
  545. package/dist/react/dom-text-sync.js +48 -0
  546. package/dist/react/editable/android-composition.d.ts +3 -0
  547. package/dist/react/editable/android-composition.js +496 -0
  548. package/dist/react/editable/browser-handle.js +515 -0
  549. package/dist/react/editable/caret-engine.js +681 -0
  550. package/dist/react/editable/clipboard-input-strategy.js +632 -0
  551. package/dist/react/editable/composition-lease.d.ts +3 -0
  552. package/dist/react/editable/composition-lease.js +350 -0
  553. package/dist/react/editable/composition-state.js +716 -0
  554. package/dist/react/editable/content-root-boundaries.js +79 -0
  555. package/dist/react/editable/content-root-coordinate-navigation.js +28 -0
  556. package/dist/react/editable/content-root-navigation-actions.js +190 -0
  557. package/dist/react/editable/content-root-navigation.js +819 -0
  558. package/dist/react/editable/content-root-owner-target.js +36 -0
  559. package/dist/react/editable/content-root-owners.js +191 -0
  560. package/dist/react/editable/content-root-vertical-geometry.js +60 -0
  561. package/dist/react/editable/decoration-repair-bridge.js +29 -0
  562. package/dist/react/editable/dom-coverage-selection.js +158 -0
  563. package/dist/react/editable/dom-coverage-vertical-selection.js +446 -0
  564. package/dist/react/editable/dom-input-event.js +14 -0
  565. package/dist/react/editable/dom-repair-queue.d.ts +7 -0
  566. package/dist/react/editable/dom-repair-queue.js +543 -0
  567. package/dist/react/editable/dom-repair-text.js +47 -0
  568. package/dist/react/editable/editable-command-types.d.ts +1 -0
  569. package/dist/react/editable/editable-dom-runtime.d.ts +66 -0
  570. package/dist/react/editable/editable-dom-runtime.js +1022 -0
  571. package/dist/react/editable/editing-epoch-adapter.js +46 -0
  572. package/dist/react/editable/editing-kernel.d.ts +7 -0
  573. package/dist/react/editable/editing-kernel.js +593 -0
  574. package/dist/react/editable/external-text-binding.js +43 -0
  575. package/dist/react/editable/external-text-runtime.d.ts +5 -0
  576. package/dist/react/editable/external-text-runtime.js +851 -0
  577. package/dist/react/editable/history-focus.js +71 -0
  578. package/dist/react/editable/history-keyboard.d.ts +4 -0
  579. package/dist/react/editable/history-keyboard.js +9 -0
  580. package/dist/react/editable/input-controller.d.ts +7 -0
  581. package/dist/react/editable/input-controller.js +175 -0
  582. package/dist/react/editable/input-history.js +21 -0
  583. package/dist/react/editable/input-router.js +742 -0
  584. package/dist/react/editable/input-state.d.ts +18 -0
  585. package/dist/react/editable/input-state.js +330 -0
  586. package/dist/react/editable/input-target.js +30 -0
  587. package/dist/react/editable/install-browser-handle.d.ts +12 -0
  588. package/dist/react/editable/install-browser-handle.js +18 -0
  589. package/dist/react/editable/interaction-owner.js +88 -0
  590. package/dist/react/editable/keyboard-input-strategy.js +730 -0
  591. package/dist/react/editable/line-boundary.js +37 -0
  592. package/dist/react/editable/model-input-strategy.d.ts +9 -0
  593. package/dist/react/editable/model-input-strategy.js +242 -0
  594. package/dist/react/editable/model-selection-dom-preference.js +11 -0
  595. package/dist/react/editable/mutation-block-editing.js +48 -0
  596. package/dist/react/editable/mutation-controller.d.ts +32 -0
  597. package/dist/react/editable/mutation-controller.js +632 -0
  598. package/dist/react/editable/mutation-full-block-editing.d.ts +2 -0
  599. package/dist/react/editable/mutation-full-block-editing.js +44 -0
  600. package/dist/react/editable/mutation-history.d.ts +3 -0
  601. package/dist/react/editable/mutation-history.js +146 -0
  602. package/dist/react/editable/native-input-strategy.js +86 -0
  603. package/dist/react/editable/native-text-input-delta.js +40 -0
  604. package/dist/react/editable/placed-drag.js +177 -0
  605. package/dist/react/editable/plite-string-coordinate-placement.js +46 -0
  606. package/dist/react/editable/press-fence.d.ts +2 -0
  607. package/dist/react/editable/press-fence.js +70 -0
  608. package/dist/react/editable/projected-clipboard.js +123 -0
  609. package/dist/react/editable/projected-native-affordance.js +30 -0
  610. package/dist/react/editable/projected-selection-target.js +13 -0
  611. package/dist/react/editable/render-contract-monitor.d.ts +3 -0
  612. package/dist/react/editable/render-contract-monitor.js +152 -0
  613. package/dist/react/editable/root-interaction-controller.js +1400 -0
  614. package/dist/react/editable/root-interaction-dom-selection-replay.js +40 -0
  615. package/dist/react/editable/root-interaction-resolver.js +116 -0
  616. package/dist/react/editable/root-selector-sources.js +90 -0
  617. package/dist/react/editable/runtime-android-engine.js +40 -0
  618. package/dist/react/editable/runtime-before-input-events.js +671 -0
  619. package/dist/react/editable/runtime-browser-handle-events.js +40 -0
  620. package/dist/react/editable/runtime-clipboard-events.js +169 -0
  621. package/dist/react/editable/runtime-composition-events.js +163 -0
  622. package/dist/react/editable/runtime-drag-events.js +136 -0
  623. package/dist/react/editable/runtime-editor-api.d.ts +20 -0
  624. package/dist/react/editable/runtime-editor-api.js +21 -0
  625. package/dist/react/editable/runtime-event-engine.js +213 -0
  626. package/dist/react/editable/runtime-focus-mouse-events.js +264 -0
  627. package/dist/react/editable/runtime-input-events.js +166 -0
  628. package/dist/react/editable/runtime-kernel-trace.js +185 -0
  629. package/dist/react/editable/runtime-keyboard-events.js +333 -0
  630. package/dist/react/editable/runtime-live-state.js +44 -0
  631. package/dist/react/editable/runtime-mutation-state.js +11 -0
  632. package/dist/react/editable/runtime-repair-engine.js +118 -0
  633. package/dist/react/editable/runtime-root-engine.js +244 -0
  634. package/dist/react/editable/runtime-root-lifecycle.js +118 -0
  635. package/dist/react/editable/runtime-root-selection-export.js +38 -0
  636. package/dist/react/editable/runtime-root-selection-import.js +54 -0
  637. package/dist/react/editable/runtime-root-state.js +62 -0
  638. package/dist/react/editable/runtime-selection-engine.js +260 -0
  639. package/dist/react/editable/runtime-selection-state.js +12 -0
  640. package/dist/react/editable/runtime-target-bridge.js +29 -0
  641. package/dist/react/editable/schema-runtime-invalidation.js +26 -0
  642. package/dist/react/editable/selection-change-listener.js +99 -0
  643. package/dist/react/editable/selection-claim.d.ts +3 -0
  644. package/dist/react/editable/selection-claim.js +398 -0
  645. package/dist/react/editable/selection-controller.d.ts +8 -0
  646. package/dist/react/editable/selection-controller.js +693 -0
  647. package/dist/react/editable/selection-dom-range.js +84 -0
  648. package/dist/react/editable/selection-projected-dom.js +156 -0
  649. package/dist/react/editable/selection-reconciler.js +630 -0
  650. package/dist/react/editable/selection-runtime.js +89 -0
  651. package/dist/react/editable/selection-side-effect-policy.js +20 -0
  652. package/dist/react/editable/selection-triple-click.js +48 -0
  653. package/dist/react/editable/selection-void-target.js +172 -0
  654. package/dist/react/editable/set-root-endpoints.js +75 -0
  655. package/dist/react/editable/soft-line-end-delete.js +106 -0
  656. package/dist/react/editable/text-direction.js +82 -0
  657. package/dist/react/editable/typed-text.d.ts +17 -0
  658. package/dist/react/editable/typed-text.js +89 -0
  659. package/dist/react/editable/unread-press.d.ts +2 -0
  660. package/dist/react/editable/unread-press.js +86 -0
  661. package/dist/react/editable/view-caret-restore.js +128 -0
  662. package/dist/react/editable/view-lines.d.ts +7 -0
  663. package/dist/react/editable/view-lines.js +166 -0
  664. package/dist/react/external-text.d.ts +131 -0
  665. package/dist/react/history-step-views.d.ts +4 -0
  666. package/dist/react/history-step-views.js +119 -0
  667. package/dist/react/hooks/android-input-manager/android-input-manager.d.ts +7 -0
  668. package/dist/react/hooks/android-input-manager/android-input-manager.js +716 -0
  669. package/dist/react/hooks/android-input-manager/use-android-input-manager.js +53 -0
  670. package/dist/react/hooks/focus-plite-editable.js +116 -0
  671. package/dist/react/hooks/use-claim-editable-dom-commit.d.ts +12 -0
  672. package/dist/react/hooks/use-claim-editable-dom-commit.js +31 -0
  673. package/dist/react/hooks/use-drop-indicator.d.ts +9 -0
  674. package/dist/react/hooks/use-drop-indicator.js +14 -0
  675. package/dist/react/hooks/use-editable-clip.d.ts +18 -0
  676. package/dist/react/hooks/use-editable-clip.js +31 -0
  677. package/dist/react/hooks/use-editable-layout-pass.js +53 -0
  678. package/dist/react/hooks/use-editor-composing.d.ts +7 -0
  679. package/dist/react/hooks/use-editor-composing.js +12 -0
  680. package/dist/react/hooks/use-editor-context.d.ts +10 -0
  681. package/dist/react/hooks/use-editor-context.js +18 -0
  682. package/dist/react/hooks/use-editor-dom-scope.d.ts +27 -0
  683. package/dist/react/hooks/use-editor-dom-scope.js +23 -0
  684. package/dist/react/hooks/use-editor-focused.d.ts +7 -0
  685. package/dist/react/hooks/use-editor-focused.js +12 -0
  686. package/dist/react/hooks/use-editor-read-only.d.ts +25 -0
  687. package/dist/react/hooks/use-editor-read-only.js +19 -0
  688. package/dist/react/hooks/use-editor-runtime-state.d.ts +18 -0
  689. package/dist/react/hooks/use-editor-runtime-state.js +38 -0
  690. package/dist/react/hooks/use-editor-selection.d.ts +10 -0
  691. package/dist/react/hooks/use-editor-selection.js +13 -0
  692. package/dist/react/hooks/use-editor-selector.d.ts +38 -0
  693. package/dist/react/hooks/use-editor-selector.js +265 -0
  694. package/dist/react/hooks/use-editor-view-state.d.ts +16 -0
  695. package/dist/react/hooks/use-editor-view-state.js +20 -0
  696. package/dist/react/hooks/use-editor.d.ts +26 -0
  697. package/dist/react/hooks/use-editor.js +27 -0
  698. package/dist/react/hooks/use-element-path.d.ts +7 -0
  699. package/dist/react/hooks/use-element-path.js +36 -0
  700. package/dist/react/hooks/use-element-selected.d.ts +26 -0
  701. package/dist/react/hooks/use-element-selected.js +91 -0
  702. package/dist/react/hooks/use-element.d.ts +13 -0
  703. package/dist/react/hooks/use-element.js +17 -0
  704. package/dist/react/hooks/use-generic-selector.js +91 -0
  705. package/dist/react/hooks/use-hydrated.js +12 -0
  706. package/dist/react/hooks/use-isomorphic-layout-effect.js +9 -0
  707. package/dist/react/hooks/use-node-selector.d.ts +40 -0
  708. package/dist/react/hooks/use-node-selector.js +102 -0
  709. package/dist/react/hooks/use-plite-annotation-store.d.ts +21 -0
  710. package/dist/react/hooks/use-plite-annotation-store.js +61 -0
  711. package/dist/react/hooks/use-plite-annotations.d.ts +9 -0
  712. package/dist/react/hooks/use-plite-annotations.js +16 -0
  713. package/dist/react/hooks/use-plite-child-root.d.ts +14 -0
  714. package/dist/react/hooks/use-plite-child-root.js +38 -0
  715. package/dist/react/hooks/use-plite-content-root.d.ts +21 -0
  716. package/dist/react/hooks/use-plite-content-root.js +26 -0
  717. package/dist/react/hooks/use-plite-history.d.ts +43 -0
  718. package/dist/react/hooks/use-plite-history.js +137 -0
  719. package/dist/react/hooks/use-plite-node-ref.js +513 -0
  720. package/dist/react/hooks/use-plite-root-chrome.d.ts +34 -0
  721. package/dist/react/hooks/use-plite-root-chrome.js +98 -0
  722. package/dist/react/hooks/use-plite-runtime.d.ts +86 -0
  723. package/dist/react/hooks/use-plite-runtime.js +433 -0
  724. package/dist/react/hooks/use-runtime-focus-state.js +37 -0
  725. package/dist/react/hooks/use-selection-geometry.d.ts +12 -0
  726. package/dist/react/hooks/use-selection-geometry.js +39 -0
  727. package/dist/react/hooks/use-selection-view.d.ts +14 -0
  728. package/dist/react/hooks/use-selection-view.js +14 -0
  729. package/dist/react/hooks/use-state-field.d.ts +26 -0
  730. package/dist/react/hooks/use-state-field.js +38 -0
  731. package/dist/react/inactive-selection.js +175 -0
  732. package/dist/react/index.d.ts +97 -0
  733. package/dist/react/index.js +72 -0
  734. package/dist/react/plugin/react-editor.d.ts +20 -0
  735. package/dist/react/plugin/react-editor.js +6 -0
  736. package/dist/react/plugin/with-react.d.ts +108 -0
  737. package/dist/react/plugin/with-react.js +58 -0
  738. package/dist/react/range-geometry.d.ts +38 -0
  739. package/dist/react/range-geometry.js +481 -0
  740. package/dist/react/render-profiler.js +20 -0
  741. package/dist/react/root-key.js +12 -0
  742. package/dist/react/shell-runtime.js +29 -0
  743. package/dist/react/update-policy.d.ts +10 -0
  744. package/dist/react/update-policy.js +15 -0
  745. package/dist/react/utils/environment.js +5 -0
  746. package/dist/react/view-boundary-graph-core.d.ts +1 -0
  747. package/dist/react/view-boundary-graph-core.js +208 -0
  748. package/dist/react/view-boundary-graph.js +105 -0
  749. package/dist/react/view-selection-decoration.js +97 -0
  750. package/dist/react/view-selection.js +184 -0
  751. package/dist/react/viewport-boundary.js +45 -0
  752. package/dist/react/viewport-commands.d.ts +1 -0
  753. package/dist/react/viewport-commands.js +17 -0
  754. package/dist/react/viewport-plan.d.ts +2 -0
  755. package/dist/react/viewport-plan.js +77 -0
  756. package/dist/react/virtualized/use-virtualized-root-plan.js +148 -0
  757. package/dist/react/virtualized.d.ts +15 -0
  758. package/dist/react/virtualized.js +70 -0
  759. package/dist/testing/createDataTransfer.d.ts +4 -0
  760. package/dist/testing/createDataTransfer.js +13 -0
  761. package/dist/testing/index.d.ts +9 -0
  762. package/dist/testing/index.js +9 -0
  763. package/dist/testing/jsx.d.ts +181 -0
  764. package/dist/testing/jsx.js +82 -0
  765. package/dist/transforms-node/insert-nodes.js +143 -0
  766. package/dist/transforms-node/lift-nodes.js +117 -0
  767. package/dist/transforms-node/merge-nodes.js +180 -0
  768. package/dist/transforms-node/move-nodes.js +58 -0
  769. package/dist/transforms-node/remove-nodes.js +86 -0
  770. package/dist/transforms-node/replace-children.js +117 -0
  771. package/dist/transforms-node/set-nodes.js +188 -0
  772. package/dist/transforms-node/split-nodes.js +258 -0
  773. package/dist/transforms-node/unset-nodes.js +10 -0
  774. package/dist/transforms-node/unwrap-nodes.js +182 -0
  775. package/dist/transforms-node/wrap-nodes.js +250 -0
  776. package/dist/transforms-selection/collapse.js +20 -0
  777. package/dist/transforms-selection/deselect.js +8 -0
  778. package/dist/transforms-selection/move.js +35 -0
  779. package/dist/transforms-selection/select.js +59 -0
  780. package/dist/transforms-selection/set-point.js +32 -0
  781. package/dist/transforms-selection/set-selection.js +52 -0
  782. package/dist/transforms-text/delete-text-collapsed-path-targets.js +102 -0
  783. package/dist/transforms-text/delete-text-grid.js +402 -0
  784. package/dist/transforms-text/delete-text-inline-points.js +82 -0
  785. package/dist/transforms-text/delete-text-plan.js +55 -0
  786. package/dist/transforms-text/delete-text-removal.js +153 -0
  787. package/dist/transforms-text/delete-text-structural-cleanup.js +130 -0
  788. package/dist/transforms-text/delete-text-whole-blocks.js +70 -0
  789. package/dist/transforms-text/delete-text.js +804 -0
  790. package/dist/transforms-text/full-document-range.js +12 -0
  791. package/dist/transforms-text/insert-text.js +314 -0
  792. package/dist/types/types.d.ts +13 -0
  793. package/dist/utils/format-debug-value.d.ts +8 -0
  794. package/dist/utils/format-debug-value.js +31 -0
  795. package/dist/utils/get-default-insert-location.js +19 -0
  796. package/dist/utils/is-object.d.ts +4 -0
  797. package/dist/utils/is-object.js +4 -0
  798. package/dist/utils/match-path.js +8 -0
  799. package/dist/utils/node-keys.d.ts +15 -0
  800. package/dist/utils/node-keys.js +179 -0
  801. package/dist/utils/node-match.js +9 -0
  802. package/dist/utils/string.js +283 -0
  803. package/dist/yjs/core/addresses.js +98 -0
  804. package/dist/yjs/core/ancestor-properties.js +56 -0
  805. package/dist/yjs/core/attributes.js +21 -0
  806. package/dist/yjs/core/awareness-adapter.d.ts +5 -0
  807. package/dist/yjs/core/awareness-adapter.js +399 -0
  808. package/dist/yjs/core/awareness-relative-selection.js +22 -0
  809. package/dist/yjs/core/awareness.js +25 -0
  810. package/dist/yjs/core/binding.d.ts +3 -0
  811. package/dist/yjs/core/binding.js +128 -0
  812. package/dist/yjs/core/boundaries.js +453 -0
  813. package/dist/yjs/core/canonical-split.js +130 -0
  814. package/dist/yjs/core/change-bridge.js +124 -0
  815. package/dist/yjs/core/change-regions.js +119 -0
  816. package/dist/yjs/core/controller-registry.js +70 -0
  817. package/dist/yjs/core/controller.d.ts +6 -0
  818. package/dist/yjs/core/controller.js +1282 -0
  819. package/dist/yjs/core/document.js +1499 -0
  820. package/dist/yjs/core/editor-adapter.d.ts +18 -0
  821. package/dist/yjs/core/editor-adapter.js +145 -0
  822. package/dist/yjs/core/editor-only-roots.js +53 -0
  823. package/dist/yjs/core/editor-types.d.ts +1 -0
  824. package/dist/yjs/core/enclosures.js +410 -0
  825. package/dist/yjs/core/event-change-bridge.js +3642 -0
  826. package/dist/yjs/core/index.d.ts +4 -0
  827. package/dist/yjs/core/joined-lines.js +81 -0
  828. package/dist/yjs/core/joins.js +587 -0
  829. package/dist/yjs/core/json-equality.js +31 -0
  830. package/dist/yjs/core/keys.js +29 -0
  831. package/dist/yjs/core/letter-scripts.js +449 -0
  832. package/dist/yjs/core/new-letters.js +300 -0
  833. package/dist/yjs/core/path.js +25 -0
  834. package/dist/yjs/core/plugin.d.ts +107 -0
  835. package/dist/yjs/core/plugin.js +206 -0
  836. package/dist/yjs/core/record.js +4 -0
  837. package/dist/yjs/core/replacement.js +165 -0
  838. package/dist/yjs/core/retraction.js +132 -0
  839. package/dist/yjs/core/root-owners.js +110 -0
  840. package/dist/yjs/core/root-projection-index.js +428 -0
  841. package/dist/yjs/core/schema-metadata.js +88 -0
  842. package/dist/yjs/core/selection.js +34 -0
  843. package/dist/yjs/core/set-valued-attributes.js +57 -0
  844. package/dist/yjs/core/shared-effect-log.d.ts +4 -0
  845. package/dist/yjs/core/shared-effect-log.js +674 -0
  846. package/dist/yjs/core/text-runs.js +1596 -0
  847. package/dist/yjs/core/types.d.ts +76 -0
  848. package/dist/yjs/index.d.ts +5 -0
  849. package/dist/yjs/index.js +3 -0
  850. package/dist/yjs/react/index.d.ts +6 -0
  851. package/dist/yjs/react/index.js +4 -0
  852. package/dist/yjs/react/useYjs.d.ts +25 -0
  853. package/dist/yjs/react/useYjs.js +85 -0
  854. package/package.json +191 -43
@@ -0,0 +1,3166 @@
1
+ import { getDefined } from "../internal/get-defined.js";
2
+ import { countCoreWork } from "./work.js";
3
+ import { cloneFrozen } from "./clone.js";
4
+ import { jsonEqual } from "./change/json.js";
5
+ import { profileCoreDuration } from "./profiling.js";
6
+ import { failInvariant } from "../internal/fail-invariant.js";
7
+ import { readSchemaIdentity } from "./document-shape.js";
8
+ //#region src/core/schema-compiler.ts
9
+ const BUILT_IN_GROUPS = [
10
+ "all",
11
+ "block",
12
+ "element",
13
+ "inline",
14
+ "text",
15
+ "textBlock"
16
+ ];
17
+ const BUILT_IN_GROUP_SET = new Set(BUILT_IN_GROUPS);
18
+ const COMPLETE_SCHEMA_COMMON_FIELDS = ["root"];
19
+ const COMPLETE_SCHEMA_LINEAGE_FIELDS = ["id", "version"];
20
+ const COMPLETE_SCHEMA_FIELDS = [...COMPLETE_SCHEMA_COMMON_FIELDS, ...COMPLETE_SCHEMA_LINEAGE_FIELDS];
21
+ const RESERVED_PRIMARY_ROOT = "main";
22
+ const RESERVED_PROPERTY_KEYS = /* @__PURE__ */ new Set([
23
+ "__proto__",
24
+ "children",
25
+ "constructor",
26
+ "prototype",
27
+ "text",
28
+ "type"
29
+ ]);
30
+ const UNKNOWN_TYPE = "\0unknown-schema-type";
31
+ const DEFAULT_DERIVED_EDITOR_SCHEMA = Object.freeze({
32
+ elements: Object.freeze({ paragraph: Object.freeze({ content: Object.freeze({
33
+ allowed: Object.freeze({ kind: "text" }),
34
+ default: "text",
35
+ min: 1
36
+ }) }) }),
37
+ root: Object.freeze({
38
+ allowed: Object.freeze({
39
+ kind: "not",
40
+ rule: Object.freeze({ kind: "text" })
41
+ }),
42
+ default: Object.freeze({ type: "paragraph" })
43
+ }),
44
+ unknown: "preserve"
45
+ });
46
+ const DEFAULT_DERIVED_EDITOR_SCHEMA_RECORD = Object.freeze({
47
+ contribution: DEFAULT_DERIVED_EDITOR_SCHEMA,
48
+ pluginName: "core:derived-base-schema"
49
+ });
50
+ const isCompleteSchemaDeclaration = (declaration) => Object.hasOwn(declaration, "root");
51
+ const isDerivedSchemaDefinition = (definition) => !Object.hasOwn(definition, "id") && !Object.hasOwn(definition, "version");
52
+ const createDerivedBaseSchemaRecord = (explicitRecords) => {
53
+ if (!explicitRecords.some(({ contribution }) => Object.hasOwn(contribution.elements ?? {}, "paragraph"))) {
54
+ const inlineTypes = [...new Set(explicitRecords.flatMap(({ contribution }) => Object.entries(contribution.elements ?? {}).filter(([, element]) => element.inline === true || isInlineVoid(element.void)).map(([type]) => type)))].sort((left, right) => left.localeCompare(right));
55
+ if (inlineTypes.length === 0) return DEFAULT_DERIVED_EDITOR_SCHEMA_RECORD;
56
+ return Object.freeze({
57
+ contribution: Object.freeze({
58
+ ...DEFAULT_DERIVED_EDITOR_SCHEMA,
59
+ elements: Object.freeze({ paragraph: Object.freeze({ content: Object.freeze({
60
+ allowed: Object.freeze({
61
+ kind: "any",
62
+ rules: Object.freeze([Object.freeze({ kind: "text" }), Object.freeze({
63
+ kind: "types",
64
+ types: Object.freeze(inlineTypes)
65
+ })])
66
+ }),
67
+ default: "text",
68
+ min: 1
69
+ }) }) })
70
+ }),
71
+ pluginName: DEFAULT_DERIVED_EDITOR_SCHEMA_RECORD.pluginName
72
+ });
73
+ }
74
+ return Object.freeze({
75
+ contribution: Object.freeze({
76
+ ...DEFAULT_DERIVED_EDITOR_SCHEMA,
77
+ elements: Object.freeze({})
78
+ }),
79
+ pluginName: DEFAULT_DERIVED_EDITOR_SCHEMA_RECORD.pluginName
80
+ });
81
+ };
82
+ /**
83
+ * Exact equality for schema identities, including absent metadata.
84
+ *
85
+ * @internal
86
+ */
87
+ const areEditorSchemaIdentitiesEqual = (left, right) => left === right || left !== null && right !== null && left.kind === right.kind && left.fingerprint === right.fingerprint && (left.kind === "derived" || right.kind === "named" && left.id === right.id && left.version === right.version);
88
+ const refuseSchemaIdentity = () => {
89
+ throw new TypeError("Not a schema identity.");
90
+ };
91
+ /** @internal */
92
+ const readEditorSchemaIdentity = (value) => {
93
+ try {
94
+ return readSchemaIdentity(value, refuseSchemaIdentity, "schema");
95
+ } catch {
96
+ return;
97
+ }
98
+ };
99
+ var EditorSchemaCompileError = class extends Error {
100
+ diagnostics;
101
+ constructor(diagnostics) {
102
+ const sorted = [...diagnostics].sort((left, right) => left.path.localeCompare(right.path) || left.code.localeCompare(right.code) || left.message.localeCompare(right.message) || left.plugins.join("\0").localeCompare(right.plugins.join("\0")));
103
+ super(sorted.map(({ message }) => message).join("\n"));
104
+ this.name = "EditorSchemaCompileError";
105
+ this.diagnostics = Object.freeze(sorted.map((diagnostic) => Object.freeze({
106
+ ...diagnostic,
107
+ plugins: Object.freeze([...new Set(diagnostic.plugins)].sort())
108
+ })));
109
+ }
110
+ };
111
+ const getCompiledSchemaWrapperPlanKey = (parentProgramId, childType) => `${parentProgramId}\u0000${childType ?? "\0text"}`;
112
+ const COMPILED_WRAPPER_PLAN_CACHE = /* @__PURE__ */ new WeakMap();
113
+ const orderedCompiledAllowedTypes = (program) => {
114
+ const preferred = program.defaultPlan?.kind === "element" ? program.defaultPlan.type : null;
115
+ return [...preferred ? [preferred] : [], ...[...program.allowedElementTypes].filter((type) => type !== preferred).sort((left, right) => left.localeCompare(right))];
116
+ };
117
+ /** Resolve and revision-cache one shortest grammar-only wrapper chain. */
118
+ const resolveCompiledSchemaWrapperPlan = (schema, parentProgramId, childType) => {
119
+ const preservedUnknown = childType !== null && schema.unknown === "preserve" && !schema.elements.byType.has(childType);
120
+ const key = getCompiledSchemaWrapperPlanKey(parentProgramId, preservedUnknown ? UNKNOWN_TYPE : childType);
121
+ const direct = schema.elements.wrapperPlans.get(key);
122
+ if (direct) return direct;
123
+ let cache = COMPILED_WRAPPER_PLAN_CACHE.get(schema);
124
+ if (!cache) {
125
+ cache = /* @__PURE__ */ new Map();
126
+ COMPILED_WRAPPER_PLAN_CACHE.set(schema, cache);
127
+ }
128
+ if (cache.has(key)) return cache.get(key) ?? null;
129
+ return profileCoreDuration("schema-wrapper-plan-search", () => {
130
+ const parent = schema.elements.contentPrograms.get(parentProgramId);
131
+ if (!parent) {
132
+ cache.set(key, null);
133
+ return null;
134
+ }
135
+ if (preservedUnknown && parent.allowsUnknownElements) {
136
+ const plan = Object.freeze([]);
137
+ cache.set(key, plan);
138
+ return plan;
139
+ }
140
+ const queue = orderedCompiledAllowedTypes(parent).map((type) => ({
141
+ path: [type],
142
+ type
143
+ }));
144
+ const seen = new Set(queue.map(({ type }) => type));
145
+ for (const current of queue) {
146
+ const content = schema.elements.contentPrograms.get(`element:${current.type}`);
147
+ if (!content) continue;
148
+ if (childType === null ? content.allowsText : content.allowedElementTypes.has(childType) || preservedUnknown && content.allowsUnknownElements) {
149
+ const plan = Object.freeze(current.path);
150
+ cache.set(key, plan);
151
+ return plan;
152
+ }
153
+ for (const type of orderedCompiledAllowedTypes(content)) {
154
+ if (seen.has(type)) continue;
155
+ seen.add(type);
156
+ queue.push({
157
+ path: [...current.path, type],
158
+ type
159
+ });
160
+ }
161
+ }
162
+ cache.set(key, null);
163
+ return null;
164
+ });
165
+ };
166
+ const CANONICAL_VOID_CONTENT = Object.freeze({
167
+ allowed: Object.freeze({ kind: "text" }),
168
+ default: "text",
169
+ max: 1,
170
+ min: 1
171
+ });
172
+ const immutableCollectionMutation = () => {
173
+ throw new Error("Compiled editor schemas are immutable.");
174
+ };
175
+ const freezeMap = (source) => {
176
+ const map = new Map(source);
177
+ const immutable = new Proxy(map, { get(target, property) {
178
+ if (property === "clear" || property === "delete" || property === "set") return immutableCollectionMutation;
179
+ if (property === "forEach") return (callback, thisArg) => {
180
+ target.forEach((value, key) => {
181
+ callback.call(thisArg, value, key, immutable);
182
+ });
183
+ };
184
+ const value = Reflect.get(target, property, target);
185
+ return typeof value === "function" ? value.bind(target) : value;
186
+ } });
187
+ return Object.freeze(immutable);
188
+ };
189
+ const freezeSet = (source) => {
190
+ const set = new Set(source);
191
+ const immutable = new Proxy(set, { get(target, property) {
192
+ if (property === "add" || property === "clear" || property === "delete") return immutableCollectionMutation;
193
+ if (property === "forEach") return (callback, thisArg) => {
194
+ target.forEach((value) => {
195
+ callback.call(thisArg, value, value, immutable);
196
+ });
197
+ };
198
+ const value = Reflect.get(target, property, target);
199
+ return typeof value === "function" ? value.bind(target) : value;
200
+ } });
201
+ return Object.freeze(immutable);
202
+ };
203
+ const freezeSetMap = (source) => freezeMap(new Map([...source].sort(([left], [right]) => left.localeCompare(right)).map(([key, values]) => [key, freezeSet(values)])));
204
+ const referencesOf = ({ references }, { path, pluginName }) => {
205
+ if (!references) return void 0;
206
+ const { key, map } = references;
207
+ if (typeof key !== "string" || typeof map !== "function") compileFailure("invalid-schema-declaration", `Schema declaration at ${path}.references must have a string key and a map function.`, [pluginName], `${path}.references`);
208
+ return Object.freeze({
209
+ key,
210
+ map
211
+ });
212
+ };
213
+ const compileFailure = (code, message, sources, path) => {
214
+ const plugins = sources.map((source) => typeof source === "string" ? source : source.pluginName);
215
+ throw new EditorSchemaCompileError([Object.freeze({
216
+ code,
217
+ plugins,
218
+ message,
219
+ path
220
+ })]);
221
+ };
222
+ const assertSchemaDeclarationOwnership = (records) => {
223
+ const diagnostics = [];
224
+ for (const { contribution, pluginName } of records) {
225
+ if (isCompleteSchemaDeclaration(contribution)) {
226
+ for (const field of COMPLETE_SCHEMA_COMMON_FIELDS) {
227
+ if (Object.hasOwn(contribution, field)) continue;
228
+ diagnostics.push(Object.freeze({
229
+ code: "missing-complete-schema-field",
230
+ plugins: Object.freeze([pluginName]),
231
+ message: `Complete schema definition "${pluginName}" must own schema field "${field}".`,
232
+ path: `schema.${field}`
233
+ }));
234
+ }
235
+ if (Object.hasOwn(contribution, "id") || Object.hasOwn(contribution, "version")) for (const field of ["id", "version"]) {
236
+ if (Object.hasOwn(contribution, field)) continue;
237
+ diagnostics.push(Object.freeze({
238
+ code: "missing-complete-schema-field",
239
+ plugins: Object.freeze([pluginName]),
240
+ message: `Named schema definition "${pluginName}" must own schema field "${field}".`,
241
+ path: `schema.${field}`
242
+ }));
243
+ }
244
+ continue;
245
+ }
246
+ for (const field of COMPLETE_SCHEMA_FIELDS) {
247
+ if (!Object.hasOwn(contribution, field)) continue;
248
+ diagnostics.push(Object.freeze({
249
+ code: "partial-schema-complete-field",
250
+ plugins: Object.freeze([pluginName]),
251
+ message: `Partial schema contribution "${pluginName}" cannot declare complete schema field "${field}".`,
252
+ path: `schema.${field}`
253
+ }));
254
+ }
255
+ }
256
+ if (diagnostics.length > 0) throw new EditorSchemaCompileError(diagnostics);
257
+ };
258
+ const collectSchemaKeyDiagnostics = (records) => {
259
+ const diagnostics = [];
260
+ const reportShape = (pluginName, path, shape) => {
261
+ diagnostics.push(Object.freeze({
262
+ code: "invalid-schema-shape",
263
+ plugins: Object.freeze([pluginName]),
264
+ message: `Schema declaration at ${path} must be ${shape}.`,
265
+ path
266
+ }));
267
+ };
268
+ const object = (value, pluginName, path) => {
269
+ if (value === null || typeof value !== "object" || Array.isArray(value)) {
270
+ reportShape(pluginName, path, "a plain object");
271
+ return null;
272
+ }
273
+ const prototype = Object.getPrototypeOf(value);
274
+ if (!(prototype === Object.prototype || prototype === null || Object.getPrototypeOf(prototype) === null)) {
275
+ reportShape(pluginName, path, "a plain object");
276
+ return null;
277
+ }
278
+ return value;
279
+ };
280
+ const array = (value, pluginName, path) => {
281
+ if (Array.isArray(value)) return value;
282
+ reportShape(pluginName, path, "an array");
283
+ return null;
284
+ };
285
+ const check = (value, allowed, pluginName, path, options = {}) => {
286
+ const record = object(value, pluginName, path);
287
+ if (!record) return null;
288
+ const supported = new Set(allowed);
289
+ const supportedNonEnumerable = new Set(options.nonEnumerable);
290
+ for (const key of Reflect.ownKeys(record)) {
291
+ const descriptor = Object.getOwnPropertyDescriptor(record, key);
292
+ if (typeof key === "symbol" && options.symbols) continue;
293
+ const supportedKey = typeof key === "string" && supported.has(key);
294
+ const supportedHiddenKey = typeof key === "string" && descriptor?.enumerable === false && supportedNonEnumerable.has(key);
295
+ if (supportedKey && (descriptor?.enumerable !== false || supportedHiddenKey)) continue;
296
+ const label = typeof key === "symbol" ? `[${String(key)}]` : key;
297
+ diagnostics.push(Object.freeze({
298
+ code: "unknown-schema-key",
299
+ plugins: Object.freeze([pluginName]),
300
+ message: `Schema declaration at ${path} does not support key "${String(key)}".`,
301
+ path: `${path}.${label}`
302
+ }));
303
+ }
304
+ return record;
305
+ };
306
+ const visitDescriptor = (value, owner, path) => {
307
+ const descriptor = check(value, [
308
+ "default",
309
+ "generate",
310
+ "item",
311
+ "kind",
312
+ "omitDefault",
313
+ "required",
314
+ "validate",
315
+ "validationVersion",
316
+ "values"
317
+ ], owner, path, { nonEnumerable: ["generate", "validate"] });
318
+ if (!descriptor) return;
319
+ if (descriptor.item !== void 0) visitDescriptor(descriptor.item, owner, `${path}.item`);
320
+ };
321
+ const visitTarget = (value, owner, path) => {
322
+ if (value === null) return;
323
+ const target = object(value, owner, path);
324
+ if (!target) return;
325
+ const keys = target.kind === "and" || target.kind === "or" ? ["kind", "targets"] : target.kind === "group" ? ["group", "kind"] : target.kind === "not" || target.kind === "parent" ? ["kind", "target"] : target.kind === "root" ? ["kind", "root"] : target.kind === "type" ? ["kind", "type"] : target.kind === "types" ? ["kind", "types"] : ["kind"];
326
+ check(target, keys, owner, path);
327
+ if (target.targets !== void 0) array(target.targets, owner, `${path}.targets`)?.forEach((child, index) => {
328
+ visitTarget(child, owner, `${path}.targets.${index}`);
329
+ });
330
+ if (target.types !== void 0) array(target.types, owner, `${path}.types`);
331
+ if (target.target !== void 0) visitTarget(target.target, owner, `${path}.target`);
332
+ };
333
+ const visitContentRule = (value, owner, path) => {
334
+ const rule = object(value, owner, path);
335
+ if (!rule) return;
336
+ const keys = rule.kind === "all" || rule.kind === "any" ? ["kind", "rules"] : rule.kind === "group" ? ["group", "kind"] : rule.kind === "not" ? ["kind", "rule"] : rule.kind === "type" ? ["kind", "type"] : rule.kind === "types" ? ["kind", "types"] : ["kind"];
337
+ check(rule, keys, owner, path);
338
+ if (rule.rules !== void 0) array(rule.rules, owner, `${path}.rules`)?.forEach((child, index) => {
339
+ visitContentRule(child, owner, `${path}.rules.${index}`);
340
+ });
341
+ if (rule.types !== void 0) array(rule.types, owner, `${path}.types`);
342
+ if (rule.rule !== void 0) visitContentRule(rule.rule, owner, `${path}.rule`);
343
+ };
344
+ const visitContent = (value, owner, path) => {
345
+ const content = check(value, [
346
+ "allowed",
347
+ "default",
348
+ "max",
349
+ "min",
350
+ "prefix"
351
+ ], owner, path);
352
+ if (!content) return;
353
+ visitContentRule(content.allowed, owner, `${path}.allowed`);
354
+ if (content.default && content.default !== "text") {
355
+ const entry = check(content.default, ["properties", "type"], owner, `${path}.default`);
356
+ if (entry?.properties !== void 0) object(entry.properties, owner, `${path}.default.properties`);
357
+ }
358
+ if (content.prefix !== void 0) array(content.prefix, owner, `${path}.prefix`)?.forEach((slot, index) => {
359
+ const at = `${path}.prefix.${index}`;
360
+ const entry = check(slot, ["element", "properties"], owner, at);
361
+ if (!entry) return;
362
+ if (entry.element !== void 0 && typeof entry.element !== "string") check(entry.element, [
363
+ "kind",
364
+ "source",
365
+ "type"
366
+ ], owner, `${at}.element`);
367
+ if (entry.properties !== void 0) object(entry.properties, owner, `${at}.properties`);
368
+ });
369
+ };
370
+ const visitContentRoot = (value, owner, path, targeted) => {
371
+ if (!targeted && typeof value === "object" && value !== null && Object.hasOwn(value, "allowed")) {
372
+ visitContent(value, owner, path);
373
+ return;
374
+ }
375
+ const root = check(value, targeted ? [
376
+ "content",
377
+ "ownership",
378
+ "slot",
379
+ "structure",
380
+ "target"
381
+ ] : [
382
+ "content",
383
+ "ownership",
384
+ "structure"
385
+ ], owner, path);
386
+ if (!root) return;
387
+ visitContent(root.content, owner, `${path}.content`);
388
+ if (root.structure !== void 0) check(root.structure, ["kind"], owner, `${path}.structure`);
389
+ if (root.target !== void 0) visitTarget(root.target, owner, `${path}.target`);
390
+ };
391
+ for (const { contribution, pluginName } of records) {
392
+ const declaration = check(contribution, isCompleteSchemaDeclaration(contribution) ? [
393
+ "contentRoots",
394
+ "elements",
395
+ "groups",
396
+ "id",
397
+ "properties",
398
+ "records",
399
+ "root",
400
+ "roots",
401
+ "unknown",
402
+ "version"
403
+ ] : [
404
+ "contentRoots",
405
+ "elements",
406
+ "groups",
407
+ "properties",
408
+ "records",
409
+ "roots"
410
+ ], pluginName, "schema");
411
+ if (!declaration) continue;
412
+ const elements = declaration.elements === void 0 ? null : object(declaration.elements, pluginName, "elements");
413
+ for (const [type, value] of Object.entries(elements ?? {})) {
414
+ const path = `elements.${type}`;
415
+ const element = check(value, [
416
+ "atom",
417
+ "content",
418
+ "contentRoots",
419
+ "groups",
420
+ "inline",
421
+ "isolating",
422
+ "markableVoid",
423
+ "object",
424
+ "ownsExit",
425
+ "properties",
426
+ "readOnly",
427
+ "selectable",
428
+ "slice",
429
+ "structure",
430
+ "void"
431
+ ], pluginName, path);
432
+ if (!element) continue;
433
+ if (element.content !== void 0) visitContent(element.content, pluginName, `${path}.content`);
434
+ if (element.groups !== void 0) array(element.groups, pluginName, `${path}.groups`);
435
+ const contentRoots = element.contentRoots === void 0 ? null : object(element.contentRoots, pluginName, `${path}.contentRoots`);
436
+ for (const [slot, contentRoot] of Object.entries(contentRoots ?? {})) visitContentRoot(contentRoot, pluginName, `${path}.contentRoots.${slot}`, false);
437
+ const properties = element.properties === void 0 ? null : object(element.properties, pluginName, `${path}.properties`);
438
+ for (const [key, descriptor] of Object.entries(properties ?? {})) visitDescriptor(descriptor, pluginName, `${path}.properties.${key}`);
439
+ if (element.slice !== void 0) check(element.slice, [
440
+ "endMatter",
441
+ "preserveContext",
442
+ "replaceWhenCovered"
443
+ ], pluginName, `${path}.slice`);
444
+ if (element.structure !== void 0) {
445
+ const structure = object(element.structure, pluginName, `${path}.structure`);
446
+ const keys = structure?.kind === "outline" ? ["kind", "level"] : structure?.kind === "list" ? [
447
+ "depth",
448
+ "kind",
449
+ "membership"
450
+ ] : structure?.kind === "grid" ? [
451
+ "columnSpan",
452
+ "kind",
453
+ "role",
454
+ "rowSpan"
455
+ ] : [
456
+ "columnSpan",
457
+ "depth",
458
+ "kind",
459
+ "level",
460
+ "membership",
461
+ "role",
462
+ "rowSpan"
463
+ ];
464
+ check(element.structure, keys, pluginName, `${path}.structure`);
465
+ }
466
+ }
467
+ const groups = declaration.groups === void 0 ? null : object(declaration.groups, pluginName, "groups");
468
+ for (const [group, value] of Object.entries(groups ?? {})) {
469
+ const groupPath = `groups.${group}`;
470
+ const groupDeclaration = check(value, ["extends"], pluginName, groupPath);
471
+ if (groupDeclaration?.extends !== void 0) array(groupDeclaration.extends, pluginName, `${groupPath}.extends`);
472
+ }
473
+ if (declaration.root !== void 0) visitContent(declaration.root, pluginName, "root");
474
+ const roots = declaration.roots === void 0 ? null : object(declaration.roots, pluginName, "roots");
475
+ for (const [name, value] of Object.entries(roots ?? {})) visitContent(value, pluginName, `roots.${name}`);
476
+ const recordSets = declaration.records === void 0 ? null : object(declaration.records, pluginName, "records");
477
+ for (const [name, value] of Object.entries(recordSets ?? {})) check(value, ["history"], pluginName, `records.${name}`);
478
+ if (declaration.contentRoots !== void 0) array(declaration.contentRoots, pluginName, "contentRoots")?.forEach((value, index) => {
479
+ visitContentRoot(value, pluginName, `contentRoots.${index}`, true);
480
+ });
481
+ if (declaration.properties !== void 0) array(declaration.properties, pluginName, "properties")?.forEach((value, index) => {
482
+ const path = `properties.${index}`;
483
+ const property = object(value, pluginName, path);
484
+ const placement = property?.placement;
485
+ if (!property) return;
486
+ check(property, placement === "text" ? [
487
+ "copy",
488
+ "exclusive",
489
+ "inclusive",
490
+ "key",
491
+ "placement",
492
+ "role",
493
+ "split",
494
+ "target",
495
+ "typeChange",
496
+ "value"
497
+ ] : [
498
+ "copy",
499
+ "key",
500
+ "landing",
501
+ "placement",
502
+ "references",
503
+ "role",
504
+ "split",
505
+ "target",
506
+ "typeChange",
507
+ "unique",
508
+ "value"
509
+ ], pluginName, path, { symbols: true });
510
+ if (property.exclusive !== void 0) array(property.exclusive, pluginName, `${path}.exclusive`)?.forEach((innerValue, groupIndex) => {
511
+ const groupPath = `${path}.exclusive.${groupIndex}`;
512
+ const group = check(innerValue, ["id", "kind"], pluginName, groupPath);
513
+ if (group && (typeof group.id !== "string" || group.id.length === 0 || group.kind !== "exclusive")) diagnostics.push(Object.freeze({
514
+ code: "invalid-schema-declaration",
515
+ plugins: Object.freeze([pluginName]),
516
+ message: `Schema declaration at ${groupPath} must be an exclusive property group with a non-empty id.`,
517
+ path: groupPath
518
+ }));
519
+ });
520
+ if (property.key !== null && typeof property.key === "object" && !Array.isArray(property.key)) check(property.key, ["kind", "prefix"], pluginName, `${path}.key`);
521
+ if (property.references !== void 0) check(property.references, ["key", "map"], pluginName, `${path}.references`);
522
+ visitDescriptor(property.value, pluginName, `${path}.value`);
523
+ if (property.target !== void 0) visitTarget(property.target, pluginName, `${path}.target`);
524
+ });
525
+ }
526
+ if (diagnostics.length > 0) throw new EditorSchemaCompileError(diagnostics);
527
+ };
528
+ const collectSchemaOwnershipConflictDiagnostics = (records) => {
529
+ const diagnostics = [];
530
+ const collect = (code, label, pathFor, declarationsFor) => {
531
+ const sources = /* @__PURE__ */ new Map();
532
+ for (const record of records) for (const [key, value] of Object.entries(declarationsFor(record.contribution) ?? {})) {
533
+ const source = {
534
+ pluginName: record.pluginName,
535
+ path: pathFor(key),
536
+ value
537
+ };
538
+ sources.set(key, [...sources.get(key) ?? [], source]);
539
+ }
540
+ for (const [key, owners] of sources) {
541
+ if (owners.length < 2) continue;
542
+ const names = owners.map(({ pluginName }) => pluginName);
543
+ const ownership = names.length === 2 ? `both "${names[0]}" and "${names[1]}"` : `plugins ${names.map((name) => `"${name}"`).join(", ")}`;
544
+ diagnostics.push(Object.freeze({
545
+ code,
546
+ plugins: Object.freeze(names),
547
+ message: `Schema ${label} "${key}" is owned by ${ownership}.`,
548
+ path: pathFor(key)
549
+ }));
550
+ }
551
+ };
552
+ collect("duplicate-group", "group", (key) => `groups.${key}`, ({ groups }) => groups);
553
+ collect("duplicate-element-type", "element type", (key) => `elements.${key}`, ({ elements }) => elements);
554
+ collect("duplicate-root", "root", (key) => `roots.${key}.content`, ({ roots }) => roots);
555
+ if (diagnostics.length > 0) throw new EditorSchemaCompileError(diagnostics);
556
+ };
557
+ function assertName(value, label, source) {
558
+ if (typeof value !== "string" || value.length === 0) compileFailure("invalid-name", `${label} must be a non-empty string.`, [source], source.path);
559
+ }
560
+ const canonicalJson = (value, owner = "Schema value", ancestors = /* @__PURE__ */ new Set()) => {
561
+ if (value === null || typeof value === "boolean" || typeof value === "string") return value;
562
+ if (typeof value === "number") {
563
+ if (Number.isFinite(value) && !Object.is(value, -0)) return value;
564
+ throw new Error(`${owner} must contain only finite JSON numbers, not -0.`);
565
+ }
566
+ if (typeof value !== "object") throw new Error(`${owner} must be JSON data.`);
567
+ if (ancestors.has(value)) throw new Error(`${owner} cannot be cyclic.`);
568
+ const prototype = Object.getPrototypeOf(value);
569
+ if (!Array.isArray(value) && prototype !== Object.prototype && prototype !== null) throw new Error(`${owner} must use plain JSON objects.`);
570
+ ancestors.add(value);
571
+ try {
572
+ if (Array.isArray(value)) return Object.freeze(Array.from(value, (item) => canonicalJson(item, owner, ancestors)));
573
+ return Object.freeze(Object.fromEntries(Object.keys(value).sort().map((key) => [key, canonicalJson(value[key], owner, ancestors)])));
574
+ } finally {
575
+ ancestors.delete(value);
576
+ }
577
+ };
578
+ const stableStringify = (value) => JSON.stringify(canonicalJson(value));
579
+ const omitFalseOwnsExit = ({ ownsExit, ...behavior }) => Object.freeze(ownsExit ? {
580
+ ...behavior,
581
+ ownsExit
582
+ } : behavior);
583
+ const ownsExitByKind = (behavior) => behavior.void || behavior.object;
584
+ const declaredContractBehavior = ({ ownsExit, ...behavior }) => Object.freeze(ownsExit && !ownsExitByKind(behavior) ? {
585
+ ...behavior,
586
+ ownsExit
587
+ } : behavior);
588
+ const canonicalSchemaElementBehavior = (behavior) => ({
589
+ ...omitFalseOwnsExit(behavior),
590
+ editableIsland: false
591
+ });
592
+ /**
593
+ * Exact 64-bit FNV-1a over JavaScript UTF-16 code units.
594
+ *
595
+ * @internal
596
+ */
597
+ const hashSchemaIdentityString = (value) => {
598
+ let high = 3421674724;
599
+ let low = 2216829733;
600
+ for (let index = 0; index < value.length; index++) {
601
+ low = (low ^ value.charCodeAt(index)) >>> 0;
602
+ const lowProduct = low * 435;
603
+ const carry = Math.floor(lowProduct / 4294967296);
604
+ high = Math.imul(high, 435) + Math.imul(low, 256) + carry >>> 0;
605
+ low = lowProduct >>> 0;
606
+ }
607
+ return `${high.toString(16).padStart(8, "0")}${low.toString(16).padStart(8, "0")}`;
608
+ };
609
+ const canonicalDeclaration = (value, key = null, ancestors = /* @__PURE__ */ new Set()) => {
610
+ if (value === null || typeof value === "boolean" || typeof value === "number" || typeof value === "string") return value;
611
+ if (typeof value === "function") return "[function]";
612
+ if (typeof value !== "object") return `[${typeof value}]`;
613
+ if (ancestors.has(value)) return "[cycle]";
614
+ ancestors.add(value);
615
+ try {
616
+ if (Array.isArray(value)) {
617
+ const items = value.map((item) => canonicalDeclaration(item, null, ancestors));
618
+ if (key === "extends" || key === "groups" || key === "properties" || key === "rules" || key === "targets" || key === "types") return items.sort((left, right) => JSON.stringify(left).localeCompare(JSON.stringify(right)));
619
+ return items;
620
+ }
621
+ const record = value;
622
+ const isRuntimeValidation = (property) => property === "validate" && key !== "references" && typeof Object.getOwnPropertyDescriptor(record, property)?.value === "function";
623
+ const result = Object.fromEntries(Object.keys(record).filter((property) => !isRuntimeValidation(property)).sort().map((property) => {
624
+ const descriptor = Object.getOwnPropertyDescriptor(record, property);
625
+ return [property, descriptor && Object.hasOwn(descriptor, "value") ? canonicalDeclaration(descriptor.value, property, ancestors) : "[accessor]"];
626
+ }));
627
+ const exceptionalKeys = Reflect.ownKeys(record).filter((property) => {
628
+ if (isRuntimeValidation(property)) return false;
629
+ if (typeof property === "symbol") return true;
630
+ return Object.getOwnPropertyDescriptor(record, property)?.enumerable === false;
631
+ }).map((property) => {
632
+ const descriptor = Object.getOwnPropertyDescriptor(record, property);
633
+ return {
634
+ key: String(property),
635
+ kind: typeof property === "symbol" ? "symbol" : "non-enumerable",
636
+ value: descriptor && Object.hasOwn(descriptor, "value") ? canonicalDeclaration(descriptor.value, null, ancestors) : "[accessor]"
637
+ };
638
+ }).sort((left, right) => `${left.kind}:${left.key}`.localeCompare(`${right.kind}:${right.key}`));
639
+ if (exceptionalKeys.length > 0) result["\0schemaOwnKeys"] = exceptionalKeys;
640
+ if (result.kind === "set" && Array.isArray(result.default)) result.default = [...new Map(result.default.map((item) => [JSON.stringify(item), item]))].sort(([left], [right]) => left.localeCompare(right)).map(([, item]) => item);
641
+ return result;
642
+ } finally {
643
+ ancestors.delete(value);
644
+ }
645
+ };
646
+ const SCHEMA_CONTRIBUTION_DECLARATION_KEYS = /* @__PURE__ */ new WeakMap();
647
+ const remapSchemaType = (type, renames) => renames.get(type) ?? type;
648
+ const remapSchemaContentRule = (rule, renames) => {
649
+ switch (rule.kind) {
650
+ case "type": return Object.freeze({
651
+ kind: "type",
652
+ type: remapSchemaType(rule.type, renames)
653
+ });
654
+ case "types": return Object.freeze({
655
+ kind: "types",
656
+ types: Object.freeze(rule.types.map((type) => remapSchemaType(type, renames)))
657
+ });
658
+ case "all":
659
+ case "any": return Object.freeze({
660
+ kind: rule.kind,
661
+ rules: Object.freeze(rule.rules.map((child) => remapSchemaContentRule(child, renames)))
662
+ });
663
+ case "not": return Object.freeze({
664
+ kind: "not",
665
+ rule: remapSchemaContentRule(rule.rule, renames)
666
+ });
667
+ case "group":
668
+ case "open":
669
+ case "text": return rule;
670
+ }
671
+ return failInvariant("Unexpected schema content rule");
672
+ };
673
+ const remapSchemaContent = (content, renames) => Object.freeze({
674
+ ...content,
675
+ allowed: remapSchemaContentRule(content.allowed, renames),
676
+ ...content.prefix ? { prefix: Object.freeze(content.prefix.map((slot) => Object.freeze({
677
+ ...slot,
678
+ element: typeof slot.element === "string" ? remapSchemaType(slot.element, renames) : Object.freeze({
679
+ ...slot.element,
680
+ type: remapSchemaType(slot.element.type, renames)
681
+ })
682
+ }))) } : {},
683
+ ...content.default && content.default !== "text" ? { default: Object.freeze({
684
+ ...content.default,
685
+ type: remapSchemaType(content.default.type, renames)
686
+ }) } : {}
687
+ });
688
+ const remapSchemaTarget = (target, renames) => {
689
+ switch (target.kind) {
690
+ case "type": return Object.freeze({
691
+ kind: "type",
692
+ type: remapSchemaType(target.type, renames)
693
+ });
694
+ case "types": return Object.freeze({
695
+ kind: "types",
696
+ types: Object.freeze(target.types.map((type) => remapSchemaType(type, renames)))
697
+ });
698
+ case "and":
699
+ case "or": return Object.freeze({
700
+ kind: target.kind,
701
+ targets: Object.freeze(target.targets.map((child) => remapSchemaTarget(child, renames)))
702
+ });
703
+ case "not":
704
+ case "parent": return Object.freeze({
705
+ kind: target.kind,
706
+ target: remapSchemaTarget(target.target, renames)
707
+ });
708
+ case "group":
709
+ case "root": return target;
710
+ }
711
+ return failInvariant("Unexpected schema target");
712
+ };
713
+ const remapSchemaContentRootInput = (input, renames) => "allowed" in input ? remapSchemaContent(input, renames) : Object.freeze({
714
+ ...input,
715
+ content: remapSchemaContent(input.content, renames)
716
+ });
717
+ const overriddenPropertyIds = /* @__PURE__ */ new WeakMap();
718
+ const compiledSchemaPropertyIdentity = Symbol("schema.property.identity");
719
+ const prepareEditorSchemaRecords = (records) => {
720
+ const completeRecords = records.some(({ contribution }) => isCompleteSchemaDeclaration(contribution)) ? records : Object.freeze([...records, createDerivedBaseSchemaRecord(records)]);
721
+ const overrides = completeRecords.flatMap(({ contribution, pluginName }) => (contribution.overrides ?? []).map((override) => ({
722
+ pluginName,
723
+ override
724
+ })));
725
+ if (overrides.length === 0) return completeRecords;
726
+ const elementOwners = /* @__PURE__ */ new Map();
727
+ for (const record of completeRecords) for (const type of Object.keys(record.contribution.elements ?? {})) elementOwners.set(`${record.pluginName}\u0000${type}`, type);
728
+ const elementPatches = /* @__PURE__ */ new Map();
729
+ const propertyPatches = /* @__PURE__ */ new Map();
730
+ const claimedFacets = /* @__PURE__ */ new Map();
731
+ const claim = (key, pluginName) => {
732
+ const known = claimedFacets.get(key);
733
+ if (known) throw new Error(`Schema override facet "${key}" is owned by both "${known}" and "${pluginName}".`);
734
+ claimedFacets.set(key, pluginName);
735
+ };
736
+ for (const { pluginName, override } of overrides) {
737
+ if (override.kind === "element") {
738
+ const key = `${override.source}\u0000${override.element}`;
739
+ if (!elementOwners.has(key)) throw new Error(`Schema override from "${pluginName}" targets unknown element "${override.source}:${override.element}".`);
740
+ if (override.type !== void 0 && (typeof override.type !== "string" || override.type.length === 0)) throw new Error(`Schema element type override from "${pluginName}" must be a non-empty string.`);
741
+ for (const facet of [
742
+ "content",
743
+ "groups",
744
+ "type"
745
+ ]) if (override[facet] !== void 0) claim(`element:${override.source}:${override.element}:${facet}`, pluginName);
746
+ elementPatches.set(key, Object.freeze({
747
+ ...elementPatches.get(key),
748
+ ...override.content ? { content: override.content } : {},
749
+ ...override.groups ? { groups: override.groups } : {},
750
+ ...override.type !== void 0 ? { type: override.type } : {}
751
+ }));
752
+ continue;
753
+ }
754
+ const key = `${override.source}\u0000${override.id}`;
755
+ for (const facet of ["target"]) if (override[facet] !== void 0) claim(`property:${override.source}:${override.id}:${facet}`, pluginName);
756
+ propertyPatches.set(key, Object.freeze({
757
+ ...propertyPatches.get(key),
758
+ ...override.target !== void 0 ? { target: override.target } : {}
759
+ }));
760
+ }
761
+ const renames = /* @__PURE__ */ new Map();
762
+ for (const [ownerKey, patch] of elementPatches) {
763
+ if (patch.type === void 0) continue;
764
+ const original = getDefined(elementOwners.get(ownerKey));
765
+ renames.set(original, patch.type);
766
+ }
767
+ const finalTypes = /* @__PURE__ */ new Map();
768
+ for (const [ownerKey, original] of elementOwners) {
769
+ const finalType = renames.get(original) ?? original;
770
+ const known = finalTypes.get(finalType);
771
+ if (known && known !== ownerKey) throw new Error(`Schema element type override produces duplicate final type "${finalType}".`);
772
+ finalTypes.set(finalType, ownerKey);
773
+ }
774
+ const usedPropertyPatches = /* @__PURE__ */ new Set();
775
+ const prepared = completeRecords.map(({ contribution, pluginName }) => {
776
+ const { overrides: _overrides, ...declaration } = contribution;
777
+ const promotedProperties = [];
778
+ const elements = Object.fromEntries(Object.entries(declaration.elements ?? {}).map(([type, element]) => {
779
+ const patch = elementPatches.get(`${pluginName}\u0000${type}`);
780
+ const finalType = patch?.type ?? type;
781
+ const content = patch?.content ?? element.content;
782
+ const propertyEntries = Object.entries(element.properties ?? {}).flatMap(([key, descriptor]) => {
783
+ const originalTarget = Object.freeze({
784
+ kind: "type",
785
+ type
786
+ });
787
+ const id = getCompiledSchemaPropertyId({
788
+ key,
789
+ placement: "element",
790
+ target: originalTarget
791
+ });
792
+ const patchKey = `${pluginName}\u0000${id}`;
793
+ const propertyPatch = propertyPatches.get(patchKey);
794
+ if (propertyPatch) usedPropertyPatches.add(patchKey);
795
+ if (propertyPatch && Object.hasOwn(propertyPatch, "target") && propertyPatch.target === null) throw new Error(`Schema property override "${pluginName}:${id}" cannot remove an element-property target.`);
796
+ const finalTarget = remapSchemaTarget(propertyPatch && Object.hasOwn(propertyPatch, "target") ? getDefined(propertyPatch.target) : originalTarget, renames);
797
+ const preparedDescriptor = Object.freeze(Object.create(Object.getPrototypeOf(descriptor), Object.getOwnPropertyDescriptors(descriptor)));
798
+ if (propertyPatch || finalType !== type) overriddenPropertyIds.set(preparedDescriptor, id);
799
+ if (finalTarget.kind === "type" && finalTarget.type === finalType) return [[key, preparedDescriptor]];
800
+ const promotedProperty = Object.freeze({
801
+ copy: "preserve",
802
+ key,
803
+ landing: "preserve",
804
+ placement: "element",
805
+ role: "content",
806
+ split: defaultSplitOf(preparedDescriptor),
807
+ target: finalTarget,
808
+ typeChange: "drop",
809
+ value: preparedDescriptor
810
+ });
811
+ overriddenPropertyIds.set(promotedProperty, id);
812
+ promotedProperties.push(promotedProperty);
813
+ return [];
814
+ });
815
+ const properties = element.properties ? Object.freeze(Object.fromEntries(propertyEntries)) : void 0;
816
+ return [finalType, Object.freeze({
817
+ ...element,
818
+ ...properties ? { properties } : {},
819
+ ...content ? { content: remapSchemaContent(content, renames) } : {},
820
+ ...patch?.groups ? { groups: Object.freeze([...patch.groups]) } : {},
821
+ ...element.contentRoots ? { contentRoots: Object.freeze(Object.fromEntries(Object.entries(element.contentRoots).map(([slot, root]) => [slot, remapSchemaContentRootInput(root, renames)]))) } : {}
822
+ })];
823
+ }));
824
+ const properties = [...(declaration.properties ?? []).map((property) => {
825
+ const id = getCompiledSchemaPropertyId(property);
826
+ const patchKey = `${pluginName}\u0000${id}`;
827
+ const patch = propertyPatches.get(patchKey);
828
+ if (patch) usedPropertyPatches.add(patchKey);
829
+ if (patch && Object.hasOwn(patch, "target") && patch.target === null && property.placement === "element") throw new Error(`Schema property override "${pluginName}:${id}" cannot remove an element-property target.`);
830
+ const target = patch && Object.hasOwn(patch, "target") ? patch.target : property.target;
831
+ const preparedProperty = {
832
+ ...property,
833
+ ...target ? { target: remapSchemaTarget(target, renames) } : { target: void 0 }
834
+ };
835
+ if (patch || getCompiledSchemaPropertyId(preparedProperty) !== id) overriddenPropertyIds.set(preparedProperty, id);
836
+ return Object.freeze(preparedProperty);
837
+ }), ...promotedProperties];
838
+ return Object.freeze({
839
+ contribution: Object.freeze({
840
+ ...declaration,
841
+ ...declaration.elements ? { elements: Object.freeze(elements) } : {},
842
+ ...properties.length > 0 ? { properties: Object.freeze(properties) } : {},
843
+ ...declaration.contentRoots ? { contentRoots: Object.freeze(declaration.contentRoots.map((root) => Object.freeze({
844
+ ...root,
845
+ content: remapSchemaContent(root.content, renames),
846
+ target: remapSchemaTarget(root.target, renames)
847
+ }))) } : {},
848
+ ...declaration.root ? { root: remapSchemaContent(declaration.root, renames) } : {},
849
+ ...declaration.roots ? { roots: Object.freeze(Object.fromEntries(Object.entries(declaration.roots).map(([name, root]) => [name, remapSchemaContent(root, renames)]))) } : {}
850
+ }),
851
+ pluginName
852
+ });
853
+ });
854
+ for (const key of propertyPatches.keys()) if (!usedPropertyPatches.has(key)) throw new Error(`Schema override targets unknown property "${key}".`);
855
+ return Object.freeze(prepared);
856
+ };
857
+ const getSchemaContributionDeclarationKey = (contribution) => {
858
+ const known = SCHEMA_CONTRIBUTION_DECLARATION_KEYS.get(contribution);
859
+ if (known) return known;
860
+ const key = hashSchemaIdentityString(JSON.stringify(canonicalDeclaration(contribution)));
861
+ SCHEMA_CONTRIBUTION_DECLARATION_KEYS.set(contribution, key);
862
+ return key;
863
+ };
864
+ const getEditorSchemaDeclarationKey = (records) => {
865
+ const prepared = prepareEditorSchemaRecords(records);
866
+ assertSchemaDeclarationOwnership(prepared);
867
+ const declarations = prepared.map(({ contribution, pluginName }) => ({
868
+ contribution: getSchemaContributionDeclarationKey(contribution),
869
+ pluginName
870
+ })).sort((left, right) => JSON.stringify(left).localeCompare(JSON.stringify(right)));
871
+ return `schema-declaration:${hashSchemaIdentityString(JSON.stringify(declarations))}`;
872
+ };
873
+ const sortedStrings = (values) => [...new Set(values)].sort((left, right) => left.localeCompare(right));
874
+ const schemaVoidKinds = {
875
+ block: true,
876
+ inline: true,
877
+ "markable-inline": true
878
+ };
879
+ const isSchemaVoidKind = (value) => typeof value === "string" && Object.hasOwn(schemaVoidKinds, value);
880
+ const isInlineVoid = (kind) => kind === "inline" || kind === "markable-inline";
881
+ const compileElementBehavior = (source) => {
882
+ const input = source.value;
883
+ const voidKind = input.void ?? null;
884
+ if (voidKind !== null && !isSchemaVoidKind(voidKind)) compileFailure("invalid-element-behavior", `Schema element at ${source.path} has invalid void kind "${voidKind}".`, [source], source.path);
885
+ const inlineFromVoid = isInlineVoid(voidKind ?? void 0);
886
+ if (inlineFromVoid && input.inline === false) compileFailure("invalid-element-behavior", `Schema element at ${source.path} cannot declare an inline void as block.`, [source], source.path);
887
+ const inline = input.inline ?? inlineFromVoid;
888
+ const selectable = input.selectable ?? true;
889
+ const atom = input.atom ?? isSchemaVoidKind(voidKind);
890
+ const object = input.object ?? false;
891
+ const ownsExit = input.ownsExit ?? false;
892
+ const ownedByKind = ownsExitByKind({
893
+ object,
894
+ void: isSchemaVoidKind(voidKind)
895
+ });
896
+ if (ownsExit && (inline || ownedByKind)) compileFailure("invalid-element-behavior", `Schema element at ${source.path} declares ownsExit, which only a block text element can declare; voids and objects always own their exit.`, [source], `${source.path}.ownsExit`);
897
+ if (object && (inline || voidKind !== null || atom || !selectable || input.isolating === false || Object.hasOwn(input.slice ?? {}, "preserveContext"))) compileFailure("invalid-element-behavior", `Schema element at ${source.path} has incompatible object behavior.`, [source], `${source.path}.object`);
898
+ const gridBoundary = input.structure?.kind === "grid" && input.structure.role !== "row";
899
+ if (gridBoundary && input.isolating === false) compileFailure("invalid-element-behavior", `Schema element at ${source.path} is a grid or grid cell, which is always isolating.`, [source], `${source.path}.isolating`);
900
+ return Object.freeze({
901
+ atom,
902
+ inline,
903
+ isolating: object || gridBoundary || (input.isolating ?? false),
904
+ markableVoid: input.markableVoid ?? voidKind === "markable-inline",
905
+ object,
906
+ ownsExit: ownsExit || ownedByKind,
907
+ readOnly: input.readOnly ?? false,
908
+ selectable,
909
+ void: isSchemaVoidKind(voidKind),
910
+ voidKind
911
+ });
912
+ };
913
+ const resolveGroupClosure = (group, parents, cache, visiting = []) => {
914
+ const cached = cache.get(group);
915
+ if (cached) return cached;
916
+ const cycleIndex = visiting.indexOf(group);
917
+ if (cycleIndex !== -1) {
918
+ const cycle = [...visiting.slice(cycleIndex), group];
919
+ compileFailure("group-cycle", `Schema groups contain a cycle: ${cycle.join(" -> ")}.`, [], `groups.${group}`);
920
+ }
921
+ const result = /* @__PURE__ */ new Set([group]);
922
+ for (const parent of parents.get(group) ?? []) for (const inherited of resolveGroupClosure(parent, parents, cache, [...visiting, group])) result.add(inherited);
923
+ const frozen = freezeSet(result);
924
+ cache.set(group, frozen);
925
+ return frozen;
926
+ };
927
+ const resolveMembership = (direct, parents, cache) => {
928
+ const result = /* @__PURE__ */ new Set();
929
+ for (const group of direct) for (const inherited of resolveGroupClosure(group, parents, cache)) result.add(inherited);
930
+ return result;
931
+ };
932
+ const compileContentRule = (rule, source, elementTypes, groups, textGroups, unknownPolicy) => {
933
+ switch (rule.kind) {
934
+ case "open": return {
935
+ allowsText: true,
936
+ allowsUnknownElements: unknownPolicy === "preserve",
937
+ types: new Set(elementTypes)
938
+ };
939
+ case "text": return {
940
+ allowsText: true,
941
+ allowsUnknownElements: false,
942
+ types: /* @__PURE__ */ new Set()
943
+ };
944
+ case "type":
945
+ if (!elementTypes.has(rule.type)) compileFailure("unknown-element-type", `Schema content at ${source.path} references unknown element type "${rule.type}".`, [source], source.path);
946
+ return {
947
+ allowsText: false,
948
+ allowsUnknownElements: false,
949
+ types: /* @__PURE__ */ new Set([rule.type])
950
+ };
951
+ case "types": {
952
+ const types = /* @__PURE__ */ new Set();
953
+ for (const type of rule.types) {
954
+ if (!elementTypes.has(type)) compileFailure("unknown-element-type", `Schema content at ${source.path} references unknown element type "${type}".`, [source], source.path);
955
+ types.add(type);
956
+ }
957
+ return {
958
+ allowsText: false,
959
+ allowsUnknownElements: false,
960
+ types
961
+ };
962
+ }
963
+ case "group": {
964
+ const members = groups.get(rule.group);
965
+ if (!members) compileFailure("unknown-group", `Schema content at ${source.path} references unknown group "${rule.group}".`, [source], source.path);
966
+ return {
967
+ allowsText: textGroups.has(rule.group),
968
+ allowsUnknownElements: false,
969
+ types: new Set(members)
970
+ };
971
+ }
972
+ case "not": {
973
+ const excluded = compileContentRule(rule.rule, source, elementTypes, groups, textGroups, unknownPolicy);
974
+ return {
975
+ allowsText: !excluded.allowsText,
976
+ allowsUnknownElements: unknownPolicy === "preserve" && !excluded.allowsUnknownElements,
977
+ types: new Set([...elementTypes].filter((type) => !excluded.types.has(type)))
978
+ };
979
+ }
980
+ case "any": {
981
+ const result = {
982
+ allowsText: false,
983
+ allowsUnknownElements: false,
984
+ types: /* @__PURE__ */ new Set()
985
+ };
986
+ for (const child of rule.rules) {
987
+ const compiled = compileContentRule(child, source, elementTypes, groups, textGroups, unknownPolicy);
988
+ result.allowsText ||= compiled.allowsText;
989
+ result.allowsUnknownElements ||= compiled.allowsUnknownElements;
990
+ for (const type of compiled.types) result.types.add(type);
991
+ }
992
+ return result;
993
+ }
994
+ case "all": {
995
+ let allowsText = true;
996
+ let allowsUnknownElements = unknownPolicy === "preserve";
997
+ let types = new Set(elementTypes);
998
+ for (const child of rule.rules) {
999
+ const compiled = compileContentRule(child, source, elementTypes, groups, textGroups, unknownPolicy);
1000
+ allowsText &&= compiled.allowsText;
1001
+ allowsUnknownElements &&= compiled.allowsUnknownElements;
1002
+ types = new Set([...types].filter((type) => compiled.types.has(type)));
1003
+ }
1004
+ return {
1005
+ allowsText,
1006
+ allowsUnknownElements,
1007
+ types
1008
+ };
1009
+ }
1010
+ }
1011
+ return failInvariant("Unexpected schema content rule");
1012
+ };
1013
+ const compileContent = (source, elementTypes, inlineTypes, groups, textGroups, unknownPolicy) => {
1014
+ const { value } = source;
1015
+ const min = value.min ?? 0;
1016
+ const max = value.max ?? null;
1017
+ if (!Number.isSafeInteger(min) || min < 0) compileFailure("invalid-cardinality", `Schema content at ${source.path} has invalid minimum ${min}.`, [source], source.path);
1018
+ if (max !== null && (!Number.isSafeInteger(max) || max < min)) compileFailure("invalid-cardinality", `Schema content at ${source.path} has invalid maximum ${max}.`, [source], source.path);
1019
+ const allowed = compileContentRule(value.allowed, source, elementTypes, groups, textGroups, unknownPolicy);
1020
+ let defaultPlan = null;
1021
+ if (value.default === "text") {
1022
+ if (!allowed.allowsText) compileFailure("invalid-content-default", `Schema content at ${source.path} defaults to text, but text is not allowed.`, [source], source.path);
1023
+ defaultPlan = Object.freeze({ kind: "text" });
1024
+ } else if (value.default) {
1025
+ if (!elementTypes.has(value.default.type)) compileFailure("unknown-element-type", `Schema content at ${source.path} defaults to unknown element type "${value.default.type}".`, [source], source.path);
1026
+ if (!allowed.types.has(value.default.type)) compileFailure("invalid-content-default", `Schema content at ${source.path} defaults to disallowed element type "${value.default.type}".`, [source], source.path);
1027
+ defaultPlan = Object.freeze({
1028
+ kind: "element",
1029
+ ...value.default.properties ? { properties: Object.freeze({ ...value.default.properties }) } : {},
1030
+ type: value.default.type
1031
+ });
1032
+ } else if (min > 0) {
1033
+ const candidateCount = allowed.types.size + (allowed.allowsText ? 1 : 0);
1034
+ if (candidateCount === 1 && allowed.allowsText) defaultPlan = Object.freeze({ kind: "text" });
1035
+ else if (candidateCount === 1) defaultPlan = Object.freeze({
1036
+ kind: "element",
1037
+ type: allowed.types.values().next().value
1038
+ });
1039
+ else {
1040
+ const candidates = sortedStrings(allowed.types);
1041
+ compileFailure("ambiguous-content-default", candidates.length === 0 ? `Required schema content at ${source.path} has no constructible default.` : `Required schema content at ${source.path} needs an explicit default; candidates are ${candidates.join(", ")}.`, [source], source.path);
1042
+ }
1043
+ }
1044
+ const remainder = {
1045
+ allowedElementTypes: allowed.types,
1046
+ allowsText: allowed.allowsText,
1047
+ allowsUnknownElements: allowed.allowsUnknownElements,
1048
+ defaultPlan,
1049
+ max,
1050
+ min,
1051
+ source
1052
+ };
1053
+ if (!value.prefix) return remainder;
1054
+ if (value.prefix.length === 0) compileFailure("invalid-content-prefix", `Schema content at ${source.path} needs at least one required prefix slot.`, [source], `${source.path}.prefix`);
1055
+ const prefix = value.prefix.map((slot, index) => {
1056
+ const type = typeof slot.element === "string" ? slot.element : slot.element.type;
1057
+ const path = `${source.path}.prefix.${index}`;
1058
+ if (!elementTypes.has(type)) compileFailure("unknown-element-type", `Schema content at ${path} references unknown element type "${type}".`, [source], path);
1059
+ if (inlineTypes.has(type)) compileFailure("invalid-content-prefix", `Schema content at ${path} puts inline element "${type}" in a prefix slot, which holds a block.`, [source], path);
1060
+ return Object.freeze({
1061
+ type,
1062
+ properties: Object.freeze({ ...slot.properties })
1063
+ });
1064
+ });
1065
+ return {
1066
+ ...remainder,
1067
+ allowedElementTypes: /* @__PURE__ */ new Set([...remainder.allowedElementTypes, ...prefix.map(({ type }) => type)]),
1068
+ max: remainder.max === null ? null : remainder.max + prefix.length,
1069
+ min: remainder.min + prefix.length,
1070
+ prefix: Object.freeze(prefix),
1071
+ remainder
1072
+ };
1073
+ };
1074
+ /**
1075
+ * Whether completion can reach an element's minimum in canonical children
1076
+ * within its maximum, or the counts that refuse it. An empty stretch that
1077
+ * admits text holds one empty text; a text default then merges into it, an
1078
+ * inline default arrives with a spacer text after it, and a block default
1079
+ * replaces the empty text with itself.
1080
+ */
1081
+ const canonicalMinimumReach = (program, isInline) => {
1082
+ const anchor = program.allowsText && (program.max === null || program.max > 0) ? 1 : 0;
1083
+ const plan = program.defaultPlan;
1084
+ if (program.min <= anchor || !plan) return null;
1085
+ if (plan.kind === "text") return {
1086
+ min: program.min,
1087
+ reached: `only ${anchor}`
1088
+ };
1089
+ if (!isInline(plan.type)) return null;
1090
+ const count = 2 * Math.ceil((program.min - 1) / 2) + 1;
1091
+ return program.max === null || count <= program.max ? null : {
1092
+ min: program.min,
1093
+ reached: `${count}, past its maximum of ${program.max},`
1094
+ };
1095
+ };
1096
+ const freezeContentProgram = (program) => Object.freeze({
1097
+ allowedElementTypes: freezeSet(program.allowedElementTypes),
1098
+ allowsText: program.allowsText,
1099
+ allowsUnknownElements: program.allowsUnknownElements,
1100
+ defaultPlan: program.defaultPlan,
1101
+ max: program.max,
1102
+ min: program.min,
1103
+ ...program.prefix ? { prefix: program.prefix } : {},
1104
+ ...program.remainder ? { remainder: freezeContentProgram(program.remainder) } : {}
1105
+ });
1106
+ const cloneTarget = (target, source, elementTypes, groups, roots) => {
1107
+ switch (target.kind) {
1108
+ case "type":
1109
+ if (!elementTypes.has(target.type)) compileFailure("unknown-element-type", `Schema target at ${source.path} references unknown element type "${target.type}".`, [source], source.path);
1110
+ return Object.freeze({
1111
+ kind: "type",
1112
+ type: target.type
1113
+ });
1114
+ case "types": {
1115
+ const types = sortedStrings(target.types);
1116
+ if (types.length === 0) compileFailure("invalid-target", `Schema target at ${source.path} must reference at least one type.`, [source], source.path);
1117
+ for (const type of types) if (!elementTypes.has(type)) compileFailure("unknown-element-type", `Schema target at ${source.path} references unknown element type "${type}".`, [source], source.path);
1118
+ return Object.freeze({
1119
+ kind: "types",
1120
+ types: Object.freeze(types)
1121
+ });
1122
+ }
1123
+ case "group":
1124
+ if (!groups.has(target.group)) compileFailure("unknown-group", `Schema target at ${source.path} references unknown group "${target.group}".`, [source], source.path);
1125
+ return Object.freeze({
1126
+ group: target.group,
1127
+ kind: "group"
1128
+ });
1129
+ case "root":
1130
+ if (target.root === RESERVED_PRIMARY_ROOT) compileFailure("reserved-primary-root", "Schema targets cannot expose the internal primary root name \"main\".", [source], source.path);
1131
+ if (target.root !== null && !roots.has(target.root)) compileFailure("unknown-root", `Schema target at ${source.path} references unknown root "${target.root}".`, [source], source.path);
1132
+ return Object.freeze({
1133
+ kind: "root",
1134
+ root: target.root
1135
+ });
1136
+ case "parent": return Object.freeze({
1137
+ kind: "parent",
1138
+ target: cloneTarget(target.target, source, elementTypes, groups, roots)
1139
+ });
1140
+ case "not": return Object.freeze({
1141
+ kind: "not",
1142
+ target: cloneTarget(target.target, source, elementTypes, groups, roots)
1143
+ });
1144
+ case "and":
1145
+ case "or": {
1146
+ if (target.targets.length < 2) compileFailure("invalid-target", `Schema target ${target.kind} at ${source.path} needs at least two operands.`, [source], source.path);
1147
+ const targets = target.targets.map((child) => cloneTarget(child, source, elementTypes, groups, roots));
1148
+ targets.sort((left, right) => canonicalTarget(left).localeCompare(canonicalTarget(right)));
1149
+ return Object.freeze({
1150
+ kind: target.kind,
1151
+ targets: Object.freeze(targets)
1152
+ });
1153
+ }
1154
+ }
1155
+ return failInvariant("Unexpected schema target");
1156
+ };
1157
+ const cloneElementTarget = (target, source, elementTypes, groups, roots) => {
1158
+ const cloned = cloneTarget(target, source, elementTypes, groups, roots);
1159
+ const hasContextualTarget = (candidate) => {
1160
+ if (candidate.kind === "parent" || candidate.kind === "root") return true;
1161
+ if (candidate.kind === "not") return hasContextualTarget(candidate.target);
1162
+ if (candidate.kind === "and" || candidate.kind === "or") return candidate.targets.some(hasContextualTarget);
1163
+ return false;
1164
+ };
1165
+ if (hasContextualTarget(cloned)) compileFailure("invalid-content-root-target", `Schema content root target at ${source.path} must select element types without parent or root context.`, [source], source.path);
1166
+ return cloned;
1167
+ };
1168
+ const canonicalTarget = (target) => {
1169
+ if (!target) return "all";
1170
+ switch (target.kind) {
1171
+ case "type": return `type:${JSON.stringify(target.type)}`;
1172
+ case "types": return `types:${JSON.stringify(sortedStrings(target.types))}`;
1173
+ case "group": return `group:${JSON.stringify(target.group)}`;
1174
+ case "root": return `root:${JSON.stringify(target.root)}`;
1175
+ case "parent": return `parent(${canonicalTarget(target.target)})`;
1176
+ case "not": return `not(${canonicalTarget(target.target)})`;
1177
+ case "and":
1178
+ case "or": return `${target.kind}(${target.targets.map(canonicalTarget).sort().join(",")})`;
1179
+ }
1180
+ return failInvariant("Unexpected schema target");
1181
+ };
1182
+ const matchesCompiledSchemaTarget = (schema, target, context) => {
1183
+ if (!target) return true;
1184
+ switch (target.kind) {
1185
+ case "type": return context.type === target.type;
1186
+ case "types": return target.types.includes(context.type);
1187
+ case "group": return schema.elements.groups.get(target.group)?.has(context.type) ?? false;
1188
+ case "root": return context.root === target.root;
1189
+ case "parent": {
1190
+ const [parent, ...ancestors] = context.ancestors ?? [];
1191
+ return parent ? matchesCompiledSchemaTarget(schema, target.target, {
1192
+ ancestors,
1193
+ root: context.root,
1194
+ type: parent
1195
+ }) : false;
1196
+ }
1197
+ case "not": return !matchesCompiledSchemaTarget(schema, target.target, context);
1198
+ case "and": return target.targets.every((child) => matchesCompiledSchemaTarget(schema, child, context));
1199
+ case "or": return target.targets.some((child) => matchesCompiledSchemaTarget(schema, child, context));
1200
+ }
1201
+ return failInvariant("Unexpected schema target");
1202
+ };
1203
+ const collectTargetAtoms = (target, types, groups) => {
1204
+ if (!target) return;
1205
+ switch (target.kind) {
1206
+ case "type":
1207
+ types.add(target.type);
1208
+ break;
1209
+ case "types":
1210
+ for (const type of target.types) types.add(type);
1211
+ break;
1212
+ case "group":
1213
+ groups.add(target.group);
1214
+ break;
1215
+ case "parent":
1216
+ case "not":
1217
+ collectTargetAtoms(target.target, types, groups);
1218
+ break;
1219
+ case "and":
1220
+ case "or":
1221
+ for (const child of target.targets) collectTargetAtoms(child, types, groups);
1222
+ break;
1223
+ case "root": break;
1224
+ }
1225
+ };
1226
+ const getTargetDepth = (target) => {
1227
+ if (!target) return 0;
1228
+ if (target.kind === "parent") return 1 + getTargetDepth(target.target);
1229
+ if (target.kind === "not") return getTargetDepth(target.target);
1230
+ if (target.kind === "and" || target.kind === "or") return Math.max(0, ...target.targets.map(getTargetDepth));
1231
+ return 0;
1232
+ };
1233
+ const representativeTypes = (schema, targets) => {
1234
+ const exactTypes = /* @__PURE__ */ new Set();
1235
+ const groupNames = /* @__PURE__ */ new Set();
1236
+ for (const target of targets) collectTargetAtoms(target, exactTypes, groupNames);
1237
+ const representatives = /* @__PURE__ */ new Map();
1238
+ const types = [...schema.elements.byType.keys(), ...schema.unknown === "preserve" ? [UNKNOWN_TYPE] : []];
1239
+ for (const type of types) {
1240
+ const signature = [...[...exactTypes].sort().map((candidate) => type === candidate), ...[...groupNames].sort().map((group) => schema.elements.groups.get(group)?.has(type) ?? false)].join(",");
1241
+ if (!representatives.has(signature)) representatives.set(signature, type);
1242
+ }
1243
+ return [...representatives.values()];
1244
+ };
1245
+ const targetCombinationIsSatisfiable = (schema, targets, fixedType, cache) => {
1246
+ const roots = [null, ...schema.roots.keys()];
1247
+ const depth = Math.max(0, ...targets.map(getTargetDepth));
1248
+ if (fixedType && depth === 0) return roots.some((root) => targets.every((target) => matchesCompiledSchemaTarget(schema, target, {
1249
+ ancestors: [],
1250
+ root,
1251
+ type: fixedType
1252
+ })));
1253
+ const cacheKey = `${fixedType ?? "*"}\u0000${targets.map(canonicalTarget).sort().join("")}`;
1254
+ const cached = cache?.get(cacheKey);
1255
+ if (cached !== void 0) return cached;
1256
+ const types = representativeTypes(schema, targets);
1257
+ const currentTypes = fixedType ? [fixedType] : types;
1258
+ const visitAncestors = (currentType, root, ancestors, remaining) => {
1259
+ const context = {
1260
+ ancestors,
1261
+ root,
1262
+ type: currentType
1263
+ };
1264
+ if (targets.every((target) => matchesCompiledSchemaTarget(schema, target, context))) return true;
1265
+ if (remaining === 0) return false;
1266
+ return types.some((type) => visitAncestors(currentType, root, [...ancestors, type], remaining - 1));
1267
+ };
1268
+ const result = currentTypes.some((type) => roots.some((root) => visitAncestors(type, root, [], depth)));
1269
+ cache?.set(cacheKey, result);
1270
+ return result;
1271
+ };
1272
+ const canonicalizePropertyValue = (descriptor, value, source) => {
1273
+ let canonical;
1274
+ if (descriptor.kind === "set") {
1275
+ if (!Array.isArray(value)) compileFailure("invalid-property-default", `Set property default at ${source.path} must be an array.`, [source], source.path);
1276
+ const itemDescriptor = descriptor.item;
1277
+ if (!itemDescriptor) compileFailure("invalid-property-descriptor", `Set property at ${source.path} needs an item descriptor.`, [source], source.path);
1278
+ const items = /* @__PURE__ */ new Map();
1279
+ for (const item of value) {
1280
+ const compiled = canonicalizePropertyValue(getDefined(itemDescriptor), item, source);
1281
+ items.set(stableStringify(compiled), compiled);
1282
+ }
1283
+ canonical = Object.freeze([...items].sort(([left], [right]) => left.localeCompare(right)).map(([, item]) => item));
1284
+ } else {
1285
+ try {
1286
+ canonical = canonicalJson(value);
1287
+ } catch (error) {
1288
+ compileFailure("invalid-property-default", `Schema property default at ${source.path} is not JSON: ${error.message}`, [source], source.path);
1289
+ }
1290
+ if (!(descriptor.kind === "json" || descriptor.kind === "boolean" && typeof canonical === "boolean" || descriptor.kind === "enum" && typeof canonical === "string" && descriptor.values.includes(canonical) || descriptor.kind === "number" && typeof canonical === "number" || descriptor.kind === "string" && typeof canonical === "string")) compileFailure("invalid-property-default", `Schema property default at ${source.path} does not match kind "${descriptor.kind}".`, [source], source.path);
1291
+ }
1292
+ if (descriptor.validate) {
1293
+ let valid = false;
1294
+ try {
1295
+ valid = descriptor.validate(canonical);
1296
+ } catch (error) {
1297
+ compileFailure("property-validation-failure", `Schema property validation at ${source.path} threw: ${error.message}`, [source], source.path);
1298
+ }
1299
+ if (!valid) compileFailure("property-validation-failure", `Schema property default at ${source.path} fails custom validation.`, [source], source.path);
1300
+ }
1301
+ return canonical;
1302
+ };
1303
+ const clonePropertyDescriptor = (descriptor, source) => {
1304
+ if (![
1305
+ "boolean",
1306
+ "enum",
1307
+ "json",
1308
+ "number",
1309
+ "set",
1310
+ "string"
1311
+ ].includes(descriptor.kind) || typeof descriptor.omitDefault !== "boolean" || descriptor.required !== void 0 && typeof descriptor.required !== "boolean") compileFailure("invalid-property-descriptor", `Schema property at ${source.path} has an invalid value descriptor.`, [source], source.path);
1312
+ const hasValidate = Object.hasOwn(descriptor, "validate");
1313
+ const hasValidationVersion = Object.hasOwn(descriptor, "validationVersion");
1314
+ const hasGenerate = Object.hasOwn(descriptor, "generate");
1315
+ if (hasValidate !== hasValidationVersion) compileFailure("invalid-property-validation", `Schema property validation at ${source.path} must declare validate and validationVersion together.`, [source], source.path);
1316
+ if (hasValidate) {
1317
+ if (typeof descriptor.validate !== "function") compileFailure("invalid-property-validation", `Schema property validation at ${source.path} must provide a validator function.`, [source], source.path);
1318
+ if (typeof descriptor.validationVersion !== "number" || !Number.isSafeInteger(descriptor.validationVersion) || descriptor.validationVersion < 1) compileFailure("invalid-property-validation", `Schema property validationVersion at ${source.path} must be a positive integer.`, [source], source.path);
1319
+ }
1320
+ if (hasGenerate && typeof descriptor.generate !== "function") compileFailure("invalid-property-generator", `Schema property generator at ${source.path} must be a function.`, [source], source.path);
1321
+ let item;
1322
+ let values;
1323
+ if (descriptor.kind === "set") {
1324
+ const rawItem = descriptor.item;
1325
+ if (!rawItem) compileFailure("invalid-property-descriptor", `Set property at ${source.path} needs an item descriptor.`, [source], source.path);
1326
+ item = clonePropertyDescriptor(getDefined(rawItem), source);
1327
+ } else if (descriptor.kind === "enum") {
1328
+ const rawValues = descriptor.values;
1329
+ if (!Array.isArray(rawValues) || rawValues.length === 0 || rawValues.some((value) => typeof value !== "string" || value.length === 0) || new Set(rawValues).size !== rawValues.length) compileFailure("invalid-property-descriptor", `Enum property at ${source.path} needs unique non-empty string values.`, [source], source.path);
1330
+ values = Object.freeze([...getDefined(rawValues)]);
1331
+ }
1332
+ const hasDefault = Object.hasOwn(descriptor, "default");
1333
+ let defaultValue;
1334
+ if (hasDefault) defaultValue = canonicalizePropertyValue(Object.freeze({
1335
+ ...descriptor,
1336
+ ...item ? { item } : {},
1337
+ ...values ? { values } : {}
1338
+ }), descriptor.default, source);
1339
+ if (descriptor.omitDefault && !hasDefault) compileFailure("invalid-property-default", `Schema property at ${source.path} cannot omit a missing default.`, [source], source.path);
1340
+ if (descriptor.required && (hasDefault || descriptor.omitDefault)) compileFailure("invalid-property-default", `Schema property at ${source.path} cannot combine required with default or omitDefault.`, [source], source.path);
1341
+ if (hasGenerate && (hasDefault || descriptor.omitDefault || descriptor.required)) compileFailure("invalid-property-generator", `Schema property at ${source.path} cannot combine generate with default, omitDefault, or required.`, [source], source.path);
1342
+ const cloned = {
1343
+ ...hasDefault ? { default: defaultValue } : {},
1344
+ ...item ? { item } : {},
1345
+ kind: descriptor.kind,
1346
+ omitDefault: descriptor.omitDefault,
1347
+ required: descriptor.required ?? false,
1348
+ ...hasValidationVersion ? { validationVersion: descriptor.validationVersion } : {},
1349
+ ...values ? { values } : {}
1350
+ };
1351
+ if (descriptor.validate) Object.defineProperty(cloned, "validate", {
1352
+ enumerable: false,
1353
+ value: descriptor.validate
1354
+ });
1355
+ if (descriptor.generate) Object.defineProperty(cloned, "generate", {
1356
+ enumerable: false,
1357
+ value: descriptor.generate
1358
+ });
1359
+ return Object.freeze(cloned);
1360
+ };
1361
+ const propertyKeyLabel = (key) => typeof key === "string" ? key : `${key.prefix}*`;
1362
+ const unwrittenAs = (descriptor, value) => {
1363
+ if (descriptor.generate !== void 0) return "filled";
1364
+ if (!Object.hasOwn(descriptor, "default") || !jsonEqual(value, descriptor.default)) return null;
1365
+ return descriptor.omitDefault ? "left-out" : "filled";
1366
+ };
1367
+ /** Canonical persisted identity for one schema property declaration. */
1368
+ const getCompiledSchemaPropertyId = (declaration) => {
1369
+ const reflected = Reflect.get(declaration, compiledSchemaPropertyIdentity);
1370
+ const overridden = overriddenPropertyIds.get(declaration) ?? (typeof reflected === "string" ? reflected : void 0);
1371
+ if (overridden) return overridden;
1372
+ const selector = typeof declaration.key === "string" ? `exact:${declaration.key}` : `prefix:${declaration.key.prefix}`;
1373
+ return `${declaration.placement}:${propertyKeyLabel(declaration.key)}@${hashSchemaIdentityString(`${selector}\u0000${canonicalTarget(declaration.target ?? null)}`)}`;
1374
+ };
1375
+ /**
1376
+ * Preserve one authored property's semantic identity after lowering.
1377
+ *
1378
+ * @internal
1379
+ */
1380
+ const preserveCompiledSchemaPropertyIdentity = (property, authored) => {
1381
+ const preserved = { ...property };
1382
+ Object.defineProperty(preserved, compiledSchemaPropertyIdentity, { value: getCompiledSchemaPropertyId(authored) });
1383
+ return Object.freeze(preserved);
1384
+ };
1385
+ const propertySelectorsOverlap = (left, right) => {
1386
+ if (typeof left === "string") return typeof right === "string" ? left === right : left.startsWith(right.prefix);
1387
+ if (typeof right === "string") return right.startsWith(left.prefix);
1388
+ return left.prefix.startsWith(right.prefix) || right.prefix.startsWith(left.prefix);
1389
+ };
1390
+ const validatePropertyKey = (key, placement, source) => {
1391
+ if (typeof key === "string") {
1392
+ assertName(key, "Schema property key", source);
1393
+ if (RESERVED_PROPERTY_KEYS.has(key)) compileFailure("reserved-property-key", `Schema ${placement} property at ${source.path} cannot claim reserved key "${key}".`, [source], source.path);
1394
+ return key;
1395
+ }
1396
+ assertName(key.prefix, "Schema property key prefix", source);
1397
+ const conflict = [...RESERVED_PROPERTY_KEYS].find((reservedKey) => reservedKey.startsWith(key.prefix));
1398
+ if (conflict) compileFailure("reserved-property-key", `Schema ${placement} property prefix "${key.prefix}" claims reserved key "${conflict}".`, [source], source.path);
1399
+ return Object.freeze({
1400
+ kind: "prefix",
1401
+ prefix: key.prefix
1402
+ });
1403
+ };
1404
+ const canonicalDescriptor = (descriptor) => ({
1405
+ ...Object.hasOwn(descriptor, "default") ? { default: canonicalJson(descriptor.default) } : {},
1406
+ ...descriptor.kind === "set" ? { item: canonicalDescriptor(descriptor.item) } : {},
1407
+ ...descriptor.kind === "enum" ? { values: descriptor.values } : {},
1408
+ kind: descriptor.kind,
1409
+ ..."generated" in descriptor && descriptor.generated || "generate" in descriptor && descriptor.generate ? { generated: true } : {},
1410
+ omitDefault: descriptor.omitDefault,
1411
+ required: descriptor.required,
1412
+ ...descriptor.validationVersion ? { validationVersion: descriptor.validationVersion } : {}
1413
+ });
1414
+ const compilePropertyLookup = (properties, placement) => {
1415
+ const exact = /* @__PURE__ */ new Map();
1416
+ const prefixes = /* @__PURE__ */ new Map();
1417
+ for (const property of properties) {
1418
+ if (property.placement !== placement) continue;
1419
+ const map = typeof property.key === "string" ? exact : prefixes;
1420
+ const key = typeof property.key === "string" ? property.key : property.key.prefix;
1421
+ const values = map.get(key) ?? [];
1422
+ values.push(property.id);
1423
+ map.set(key, values);
1424
+ }
1425
+ return Object.freeze({
1426
+ exact: freezeMap(new Map([...exact].sort(([left], [right]) => left.localeCompare(right)).map(([key, values]) => [key, Object.freeze(values.sort())]))),
1427
+ prefixes: Object.freeze([...prefixes].sort(([left], [right]) => right.length - left.length || left.localeCompare(right)).map(([prefix, propertyIds]) => Object.freeze({
1428
+ prefix,
1429
+ propertyIds: Object.freeze(propertyIds.sort())
1430
+ })))
1431
+ });
1432
+ };
1433
+ const resolveCompiledSchemaProperty = (schema, placement, key, context) => {
1434
+ const lookup = schema.properties.lookup[placement];
1435
+ for (const id of lookup.exact.get(key) ?? []) {
1436
+ const property = schema.properties.byId.get(id);
1437
+ if (property && matchesCompiledSchemaTarget(schema, property.target, context)) return property;
1438
+ }
1439
+ for (const { prefix, propertyIds } of lookup.prefixes) {
1440
+ if (!key.startsWith(prefix)) continue;
1441
+ for (const id of propertyIds) {
1442
+ const property = schema.properties.byId.get(id);
1443
+ if (property && matchesCompiledSchemaTarget(schema, property.target, context)) return property;
1444
+ }
1445
+ }
1446
+ return null;
1447
+ };
1448
+ const getCompiledPropertyMergeStrategy = (schema, placement, key, context) => resolveCompiledSchemaProperty(schema, placement, key, context)?.merge ?? null;
1449
+ const getCompiledPropertyCandidates = (schema, placement, key) => {
1450
+ const lookup = schema.properties.lookup[placement];
1451
+ return [...lookup.exact.get(key) ?? [], ...lookup.prefixes.flatMap(({ prefix, propertyIds }) => key.startsWith(prefix) ? propertyIds : [])].flatMap((id) => {
1452
+ const property = schema.properties.byId.get(id);
1453
+ return property ? [property] : [];
1454
+ });
1455
+ };
1456
+ const mixesMerges = (schema, ids) => {
1457
+ const merges = new Set(ids.map((id) => schema.properties.byId.get(id)?.merge));
1458
+ return merges.has("set") && merges.has("replace");
1459
+ };
1460
+ const placeDependentKeysBySchema = /* @__PURE__ */ new WeakMap();
1461
+ /** @internal */
1462
+ const isPlaceDependentElementProperty = (schema, key) => {
1463
+ let byKey = placeDependentKeysBySchema.get(schema);
1464
+ if (byKey === void 0) {
1465
+ byKey = /* @__PURE__ */ new Map();
1466
+ placeDependentKeysBySchema.set(schema, byKey);
1467
+ }
1468
+ let answer = byKey.get(key);
1469
+ if (answer === void 0) {
1470
+ answer = mixesMerges(schema, getCompiledPropertyCandidates(schema, "element", key).map(({ id }) => id));
1471
+ byKey.set(key, answer);
1472
+ }
1473
+ return answer;
1474
+ };
1475
+ const placeDependentBySchema = /* @__PURE__ */ new WeakMap();
1476
+ /** @internal */
1477
+ const hasPlaceDependentElementProperty = (schema) => {
1478
+ const cached = placeDependentBySchema.get(schema);
1479
+ if (cached !== void 0) return cached;
1480
+ const { exact, prefixes } = schema.properties.lookup.element;
1481
+ const prefixIdsOf = (key) => prefixes.flatMap(({ prefix, propertyIds }) => key.startsWith(prefix) ? propertyIds : []);
1482
+ const result = [...exact.keys()].some((key) => isPlaceDependentElementProperty(schema, key)) || prefixes.some(({ prefix }) => mixesMerges(schema, prefixIdsOf(prefix)));
1483
+ placeDependentBySchema.set(schema, result);
1484
+ return result;
1485
+ };
1486
+ const toCompiledTargetContext = (type, { ancestors = [], root } = {}) => ({
1487
+ ancestors: ancestors.flatMap((ancestor) => typeof ancestor.type === "string" && ancestor.type.length > 0 ? [ancestor.type] : []),
1488
+ root: root === void 0 || root === "main" ? null : root,
1489
+ type
1490
+ });
1491
+ const toCompiledNodeContext = (node, ancestors, root) => {
1492
+ const typeOf = (at) => typeof at?.type === "string" ? at.type : "";
1493
+ return typeof node.text === "string" ? toCompiledTargetContext(typeOf(ancestors[0]), {
1494
+ ancestors: ancestors.slice(1),
1495
+ root
1496
+ }) : toCompiledTargetContext(typeOf(node), {
1497
+ ancestors,
1498
+ root
1499
+ });
1500
+ };
1501
+ const tracksPlacesBySchema = /* @__PURE__ */ new WeakMap();
1502
+ const readsParentsBySchema = /* @__PURE__ */ new WeakMap();
1503
+ const targetReadsParent = (target) => {
1504
+ switch (target.kind) {
1505
+ case "and":
1506
+ case "or": return target.targets.some(targetReadsParent);
1507
+ case "not": return targetReadsParent(target.target);
1508
+ case "parent": return true;
1509
+ default: return false;
1510
+ }
1511
+ };
1512
+ /** @internal */
1513
+ const propertyTargetsReadParents = (schema) => {
1514
+ const cached = readsParentsBySchema.get(schema);
1515
+ if (cached !== void 0) return cached;
1516
+ const reads = [...schema.properties.byId.values()].some((property) => property.target !== null && targetReadsParent(property.target));
1517
+ readsParentsBySchema.set(schema, reads);
1518
+ return reads;
1519
+ };
1520
+ /**
1521
+ * Whether some declaration's target can fail at one place where its node
1522
+ * can stand and hold at another, so moving the node can leave its value
1523
+ * where the key has no place. For each type the node can have (a text's is
1524
+ * its parent's, which an undeclared element can be where the schema
1525
+ * preserves one), the target's context atoms, `parent` and `root`, take
1526
+ * every truth assignment, and a target whose answer changes tracks places.
1527
+ * Atoms count as independent, so the answer errs toward tracking.
1528
+ *
1529
+ * @internal
1530
+ */
1531
+ const tracksPlaces = (schema) => {
1532
+ const cached = tracksPlacesBySchema.get(schema);
1533
+ if (cached !== void 0) return cached;
1534
+ const types = [...schema.elements.byType.keys(), ...schema.unknown === "preserve" ? [UNKNOWN_TYPE] : []];
1535
+ const atomsOf = (target, atoms) => {
1536
+ if (target.kind === "and" || target.kind === "or") for (const child of target.targets) atomsOf(child, atoms);
1537
+ else if (target.kind === "not") atomsOf(target.target, atoms);
1538
+ else if (target.kind === "parent" || target.kind === "root") atoms.add(canonicalTarget(target));
1539
+ return atoms;
1540
+ };
1541
+ const holds = (target, type, truth) => {
1542
+ switch (target.kind) {
1543
+ case "and": return target.targets.every((child) => holds(child, type, truth));
1544
+ case "or": return target.targets.some((child) => holds(child, type, truth));
1545
+ case "not": return !holds(target.target, type, truth);
1546
+ case "type": return target.type === type;
1547
+ case "types": return target.types.includes(type);
1548
+ case "group": return schema.elements.groups.get(target.group)?.has(type) ?? false;
1549
+ default: return getDefined(truth.get(canonicalTarget(target)));
1550
+ }
1551
+ };
1552
+ const varies = (target, placement) => {
1553
+ const atoms = [...atomsOf(target, /* @__PURE__ */ new Set())];
1554
+ if (atoms.length > 12) return true;
1555
+ const answers = /* @__PURE__ */ new Set();
1556
+ for (const type of types) {
1557
+ for (let mask = 0; mask < 1 << atoms.length; mask += 1) answers.add(holds(target, type, new Map(atoms.map((atom, bit) => [atom, (mask >> bit) % 2 === 1]))));
1558
+ if (placement === "element" && answers.size > 1) return true;
1559
+ if (placement === "element") answers.clear();
1560
+ }
1561
+ return answers.size > 1;
1562
+ };
1563
+ const tracks = [...schema.properties.byId.values()].some((property) => property.target !== null && varies(property.target, property.placement));
1564
+ tracksPlacesBySchema.set(schema, tracks);
1565
+ return tracks;
1566
+ };
1567
+ const leftOutDefaultOf = ({ descriptor }) => unwrittenAs(descriptor, descriptor.default) === "left-out" ? stableStringify(descriptor.default) : null;
1568
+ const assertPropertyAgreesAcrossPlaces = (properties) => {
1569
+ properties.forEach((left, index) => {
1570
+ for (const right of properties.slice(index + 1)) {
1571
+ if (left.placement !== right.placement || !propertySelectorsOverlap(left.key, right.key)) continue;
1572
+ const keys = [...new Set([left.key, right.key].map(propertyKeyLabel))];
1573
+ const label = `${left.placement} property ${keys.map((key) => `"${key}"`).join(" and ")}`;
1574
+ const owners = `in declarations from "${left.owner}" and "${right.owner}"`;
1575
+ if (left.lifecycle.split !== right.lifecycle.split) compileFailure("property-split-by-place", `Schema ${label} drops on a split in one place and keeps in another, ${owners}.`, [left.source, right.source], right.source.path);
1576
+ if (left.lifecycle.unique || right.lifecycle.unique) compileFailure("property-unique-declared-twice", `Schema ${label} is unique, so it takes one declaration, but ${left.source.path} from "${left.owner}" and ${right.source.path} from "${right.owner}" both declare it.`, [left.source, right.source], right.source.path);
1577
+ if ((left.exclusiveGroupIds.length > 0 || right.exclusiveGroupIds.length > 0) && leftOutDefaultOf(left) !== leftOutDefaultOf(right)) compileFailure("exclusive-property-default-by-place", `Schema ${label} is an exclusive group member whose default differs by place, ${owners}.`, [left.source, right.source], right.source.path);
1578
+ }
1579
+ });
1580
+ };
1581
+ const compileEditorSchemaInternal = (inputRecords, revision) => {
1582
+ if (!Number.isSafeInteger(revision) || revision < 0) compileFailure("invalid-schema-revision", "Compiled schema revision must be a non-negative integer.", [], "revision");
1583
+ assertSchemaDeclarationOwnership(inputRecords);
1584
+ collectSchemaKeyDiagnostics(inputRecords);
1585
+ const explicitRecords = [...inputRecords].sort((left, right) => left.pluginName.localeCompare(right.pluginName));
1586
+ const duplicatePlugin = explicitRecords.find((record, index) => explicitRecords[index - 1]?.pluginName === record.pluginName);
1587
+ if (duplicatePlugin) compileFailure("duplicate-schema-contribution", `Editor plugin "${duplicatePlugin.pluginName}" contributes schema more than once.`, [duplicatePlugin.pluginName], "schema");
1588
+ const complete = explicitRecords.filter(({ contribution }) => isCompleteSchemaDeclaration(contribution));
1589
+ if (complete.length > 1) compileFailure("duplicate-complete-schema", `Schema contributions contain multiple complete schemas: ${complete.map(({ pluginName }) => pluginName).join(", ")}.`, complete.map(({ pluginName }) => pluginName), "schema");
1590
+ const derivedBaseRecord = createDerivedBaseSchemaRecord(explicitRecords);
1591
+ const completeRecord = complete[0] ?? derivedBaseRecord;
1592
+ const records = (complete.length === 0 ? [...explicitRecords, derivedBaseRecord] : explicitRecords).sort((left, right) => left.pluginName.localeCompare(right.pluginName));
1593
+ collectSchemaOwnershipConflictDiagnostics(records);
1594
+ const definition = completeRecord.contribution;
1595
+ const identitySource = {
1596
+ pluginName: completeRecord.pluginName,
1597
+ path: "schema",
1598
+ value: definition
1599
+ };
1600
+ const derived = isDerivedSchemaDefinition(definition);
1601
+ if (!derived) {
1602
+ assertName(definition.id, "Editor schema id", identitySource);
1603
+ if (typeof definition.version !== "number" || !Number.isSafeInteger(definition.version) || definition.version < 1) compileFailure("invalid-schema-version", `Editor schema "${definition.id}" version must be a positive integer.`, [identitySource], "schema.version");
1604
+ }
1605
+ const unknownPolicy = definition.unknown ?? "reject";
1606
+ if (unknownPolicy !== "preserve" && unknownPolicy !== "reject") compileFailure("invalid-unknown-policy", `${derived ? "Derived editor schema" : `Editor schema "${definition.id}"`} unknown policy must be "preserve" or "reject".`, [identitySource], "schema.unknown");
1607
+ const groupParents = new Map(BUILT_IN_GROUPS.map((group) => [group, Object.freeze([])]));
1608
+ const groupSources = /* @__PURE__ */ new Map();
1609
+ for (const record of records) for (const [group, declaration] of Object.entries(record.contribution.groups ?? {}).sort(([left], [right]) => left.localeCompare(right))) {
1610
+ const source = {
1611
+ pluginName: record.pluginName,
1612
+ path: `groups.${group}`,
1613
+ value: declaration
1614
+ };
1615
+ assertName(group, "Schema group name", source);
1616
+ if (BUILT_IN_GROUP_SET.has(group)) compileFailure("reserved-group", `Schema group "${group}" is compiler-owned and cannot be redeclared.`, [source], source.path);
1617
+ const known = groupSources.get(group);
1618
+ if (known) compileFailure("duplicate-group", `Schema group "${group}" is owned by both "${known.pluginName}" and "${record.pluginName}".`, [known, source], source.path);
1619
+ const parents = sortedStrings(declaration.extends ?? []);
1620
+ groupSources.set(group, source);
1621
+ groupParents.set(group, Object.freeze(parents));
1622
+ }
1623
+ for (const [group, parents] of groupParents) for (const parent of parents) if (!groupParents.has(parent)) {
1624
+ const source = getDefined(groupSources.get(group));
1625
+ compileFailure("unknown-group", `Schema group "${group}" extends unknown group "${parent}".`, source ? [source] : [], `groups.${group}`);
1626
+ }
1627
+ const groupClosure = /* @__PURE__ */ new Map();
1628
+ for (const group of [...groupParents.keys()].sort()) resolveGroupClosure(group, groupParents, groupClosure);
1629
+ const mutableElements = /* @__PURE__ */ new Map();
1630
+ for (const record of records) for (const [type, input] of Object.entries(record.contribution.elements ?? {}).sort(([left], [right]) => left.localeCompare(right))) {
1631
+ const source = {
1632
+ pluginName: record.pluginName,
1633
+ path: `elements.${type}`,
1634
+ value: input
1635
+ };
1636
+ assertName(type, "Schema element type", source);
1637
+ const known = mutableElements.get(type);
1638
+ if (known) compileFailure("duplicate-element-type", `Schema element type "${type}" is owned by both "${known.source.pluginName}" and "${record.pluginName}".`, [known.source, source], source.path);
1639
+ const behavior = compileElementBehavior(source);
1640
+ const derivesVoidContent = behavior.void;
1641
+ if (derivesVoidContent && input.content) compileFailure("redundant-void-content", `Schema element "${type}" derives its canonical empty text child from void kind "${behavior.voidKind}" and cannot declare content.`, [source], `${source.path}.content`);
1642
+ if (!derivesVoidContent && !input.content) compileFailure("missing-element-content", `Schema element "${type}" must declare content explicitly. Use schema.content.open() for intentionally open content.`, [source], `${source.path}.content`);
1643
+ const elementContent = derivesVoidContent ? CANONICAL_VOID_CONTENT : getDefined(input.content);
1644
+ const directGroups = /* @__PURE__ */ new Set([
1645
+ "all",
1646
+ "element",
1647
+ behavior.inline ? "inline" : "block"
1648
+ ]);
1649
+ for (const group of input.groups ?? []) {
1650
+ if (!groupParents.has(group)) compileFailure("unknown-group", `Schema element "${type}" references unknown group "${group}".`, [source], source.path);
1651
+ if (group === "text" || group === "inline" || group === "block") compileFailure("invalid-built-in-group", `Schema element "${type}" cannot declare compiler-owned group "${group}". Element and text membership is derived from the element definition.`, [source], source.path);
1652
+ directGroups.add(group);
1653
+ }
1654
+ mutableElements.set(type, {
1655
+ behavior,
1656
+ content: elementContent,
1657
+ contentRoots: new Map(Object.entries(input.contentRoots ?? {}).map(([slot, contentRoot]) => [slot, {
1658
+ pluginName: record.pluginName,
1659
+ path: `${source.path}.contentRoots.${slot}`,
1660
+ value: Object.hasOwn(contentRoot, "allowed") ? Object.freeze({
1661
+ content: contentRoot,
1662
+ ownership: "shared"
1663
+ }) : contentRoot
1664
+ }])),
1665
+ directGroups,
1666
+ input,
1667
+ source,
1668
+ type
1669
+ });
1670
+ }
1671
+ const elementTypes = new Set(mutableElements.keys());
1672
+ const inlineTypes = new Set([...mutableElements].flatMap(([type, element]) => element.behavior.inline ? [type] : []));
1673
+ const textGroups = resolveMembership(/* @__PURE__ */ new Set([
1674
+ "all",
1675
+ "inline",
1676
+ "text"
1677
+ ]), groupParents, groupClosure);
1678
+ const getMemberships = () => {
1679
+ const memberships = /* @__PURE__ */ new Map();
1680
+ for (const [type, element] of mutableElements) memberships.set(type, resolveMembership(element.directGroups, groupParents, groupClosure));
1681
+ return memberships;
1682
+ };
1683
+ const toGroupMembers = (memberships) => {
1684
+ const groups = new Map([...groupParents.keys()].map((group) => [group, /* @__PURE__ */ new Set()]));
1685
+ for (const [type, names] of memberships) for (const group of names) groups.get(group)?.add(type);
1686
+ return groups;
1687
+ };
1688
+ const initialMemberships = getMemberships();
1689
+ for (const [type, names] of initialMemberships) {
1690
+ const element = getDefined(mutableElements.get(type));
1691
+ if (names.has("text") || names.has("inline") !== element.behavior.inline || element.behavior.inline && names.has("block")) {
1692
+ const { source } = element;
1693
+ compileFailure("invalid-built-in-group", `Schema element "${type}" has compiler-owned group membership that contradicts its behavior.`, [source], source.path);
1694
+ }
1695
+ }
1696
+ const initialGroups = toGroupMembers(initialMemberships);
1697
+ for (const element of mutableElements.values()) if (!element.behavior.inline) {
1698
+ const source = {
1699
+ pluginName: element.source.pluginName,
1700
+ path: `${element.source.path}.content`,
1701
+ value: element.content
1702
+ };
1703
+ if (compileContent(source, elementTypes, inlineTypes, initialGroups, textGroups, unknownPolicy).allowsText && !element.behavior.void) element.directGroups.add("textBlock");
1704
+ else if (element.input.ownsExit) compileFailure("invalid-element-behavior", `Schema element "${element.type}" declares ownsExit but is not a text block.`, [element.source], `${element.source.path}.ownsExit`);
1705
+ }
1706
+ const memberships = getMemberships();
1707
+ const mutableGroups = toGroupMembers(memberships);
1708
+ const rootsByName = /* @__PURE__ */ new Map();
1709
+ const recordSets = /* @__PURE__ */ new Map();
1710
+ const primaryRoot = {
1711
+ pluginName: completeRecord.pluginName,
1712
+ path: "root",
1713
+ value: definition.root
1714
+ };
1715
+ for (const record of records) {
1716
+ for (const [name, root] of Object.entries(record.contribution.roots ?? {}).sort(([left], [right]) => left.localeCompare(right))) {
1717
+ const source = {
1718
+ pluginName: record.pluginName,
1719
+ path: `roots.${name}`,
1720
+ value: root
1721
+ };
1722
+ assertName(name, "Schema root name", source);
1723
+ if (name === RESERVED_PRIMARY_ROOT) compileFailure("reserved-primary-root", "Named schema roots cannot declare \"main\"; use the singular root field.", [source], source.path);
1724
+ const known = rootsByName.get(name);
1725
+ if (known) compileFailure("duplicate-root", `Schema root "${name}" is owned by both "${known.pluginName}" and "${record.pluginName}".`, [known, source], source.path);
1726
+ rootsByName.set(name, source);
1727
+ }
1728
+ for (const [name, set] of Object.entries(record.contribution.records ?? {}).sort(([left], [right]) => left.localeCompare(right))) {
1729
+ const source = {
1730
+ pluginName: record.pluginName,
1731
+ path: `records.${name}`,
1732
+ value: set
1733
+ };
1734
+ assertName(name, "Schema record set name", source);
1735
+ if (set.history !== void 0 && set.history !== "retain") compileFailure("invalid-record-set-history", `Schema record set "${name}" history must be "retain" when set.`, [source], `records.${name}.history`);
1736
+ const known = recordSets.get(name);
1737
+ if (known) compileFailure("duplicate-record-set", `Schema record set "${name}" is declared by both "${known.pluginName}" and "${record.pluginName}".`, [known.pluginName, record.pluginName], source.path);
1738
+ recordSets.set(name, {
1739
+ history: set.history ?? "undo",
1740
+ pluginName: record.pluginName
1741
+ });
1742
+ }
1743
+ }
1744
+ const rootNames = new Set(rootsByName.keys());
1745
+ const targetSchema = {
1746
+ elements: {
1747
+ byType: mutableElements,
1748
+ groups: mutableGroups
1749
+ },
1750
+ roots: rootsByName,
1751
+ unknown: unknownPolicy
1752
+ };
1753
+ const targetSatisfiabilityCache = /* @__PURE__ */ new Map();
1754
+ const assertContentRoot = (root, source) => {
1755
+ if (root.ownership !== "exclusive" && root.ownership !== "shared") compileFailure("invalid-content-root-ownership", `Schema content root at ${source.path} ownership must be "exclusive" or "shared".`, [source], `${source.path}.ownership`);
1756
+ if (root.structure === void 0) return;
1757
+ if (root.structure?.kind !== "set") compileFailure("invalid-content-root-structure", `Schema content root at ${source.path} structure must be { kind: "set" }.`, [source], `${source.path}.structure`);
1758
+ if (root.ownership !== "exclusive") compileFailure("invalid-content-root-structure", `Schema content root at ${source.path} declares a set, which needs ownership "exclusive".`, [source], `${source.path}.structure`);
1759
+ };
1760
+ for (const element of mutableElements.values()) for (const [slot, root] of element.contentRoots) {
1761
+ assertName(slot, "Schema content root slot", root);
1762
+ assertContentRoot(root.value, root);
1763
+ }
1764
+ for (const record of records) for (const [index, contribution] of (record.contribution.contentRoots ?? []).entries()) {
1765
+ const source = {
1766
+ pluginName: record.pluginName,
1767
+ path: `contentRoots.${index}`,
1768
+ value: contribution
1769
+ };
1770
+ assertName(contribution.slot, "Schema content root slot", source);
1771
+ assertContentRoot(contribution, source);
1772
+ const projectedTarget = cloneElementTarget(contribution.target, {
1773
+ ...source,
1774
+ path: `${source.path}.target`
1775
+ }, elementTypes, mutableGroups, rootNames);
1776
+ let matched = false;
1777
+ for (const [type, element] of mutableElements) {
1778
+ if (!targetCombinationIsSatisfiable(targetSchema, [projectedTarget], type, targetSatisfiabilityCache)) continue;
1779
+ matched = true;
1780
+ const previous = element.contentRoots.get(contribution.slot);
1781
+ if (previous) compileFailure("content-root-slot-conflict", `Schema content root slot "${contribution.slot}" for element type "${type}" is declared by both "${previous.pluginName}" and "${record.pluginName}".`, [previous, source], source.path);
1782
+ element.contentRoots.set(contribution.slot, Object.freeze({
1783
+ pluginName: record.pluginName,
1784
+ path: source.path,
1785
+ value: Object.freeze({
1786
+ content: contribution.content,
1787
+ ownership: contribution.ownership,
1788
+ ...contribution.structure ? { structure: contribution.structure } : {}
1789
+ })
1790
+ }));
1791
+ }
1792
+ if (!matched) compileFailure("unsatisfied-content-root-target", `Schema content root slot "${contribution.slot}" at ${source.path} does not target any element type.`, [source], `${source.path}.target`);
1793
+ }
1794
+ for (const element of mutableElements.values()) for (const root of element.contentRoots.values()) if (root.value.structure && !element.behavior.void) compileFailure("invalid-content-root-structure", `Schema content root at ${root.path} declares a set, which needs a void owner, and element type "${element.type}" is not void.`, [root], `${root.path}.structure`);
1795
+ const mutablePrograms = /* @__PURE__ */ new Map();
1796
+ for (const element of mutableElements.values()) {
1797
+ const source = {
1798
+ pluginName: element.source.pluginName,
1799
+ path: `${element.source.path}.content`,
1800
+ value: element.content
1801
+ };
1802
+ const program = compileContent(source, elementTypes, inlineTypes, mutableGroups, textGroups, unknownPolicy);
1803
+ const blockChildTypes = sortedStrings([...program.allowedElementTypes].filter((type) => mutableElements.get(type)?.behavior.inline === false));
1804
+ const inlineChildTypes = sortedStrings([...program.allowedElementTypes].filter((type) => mutableElements.get(type)?.behavior.inline));
1805
+ if (element.behavior.inline && blockChildTypes.length > 0) {
1806
+ const blockChildren = blockChildTypes.length === 1 ? `block child type "${blockChildTypes[0]}"` : `block child types ${blockChildTypes.map((type) => `"${type}"`).join(", ")}`;
1807
+ compileFailure("inline-content-rejects-blocks", `Schema inline element "${element.type}" allows ${blockChildren}, but inline element content can contain only text and inline elements.`, [source, ...blockChildTypes.map((type) => getDefined(mutableElements.get(type)).source)], source.path);
1808
+ }
1809
+ if (element.behavior.inline && program.allowsUnknownElements) compileFailure("inline-content-rejects-unknown-elements", `Schema inline element "${element.type}" allows unknown element children, but undeclared elements cannot be proven inline.`, [source], source.path);
1810
+ if (inlineChildTypes.length > 0) {
1811
+ const inlineChildren = inlineChildTypes.length === 1 ? `inline child type "${inlineChildTypes[0]}"` : `inline child types ${inlineChildTypes.map((type) => `"${type}"`).join(", ")}`;
1812
+ if (!program.allowsText) compileFailure("inline-content-requires-text", `Schema element "${element.type}" allows ${inlineChildren}, but canonical inline content requires text spacers.`, [source], source.path);
1813
+ if (program.max !== null && program.max < 3) compileFailure("inline-content-requires-spacers", `Schema element "${element.type}" allows ${inlineChildren}, but maximum content cardinality ${program.max} cannot fit one inline child and its two canonical text spacers.`, [source], source.path);
1814
+ }
1815
+ const reach = canonicalMinimumReach(program.remainder ?? program, (type) => Boolean(mutableElements.get(type)?.behavior.inline));
1816
+ if (reach !== null) compileFailure("unconstructible-content-minimum", `Schema element "${element.type}" requires ${reach.min} children after any prefix, but canonical content reaches ${reach.reached} with its default.`, [source], source.path);
1817
+ mutablePrograms.set(`element:${element.type}`, program);
1818
+ for (const [slot, root] of element.contentRoots) {
1819
+ const contentSource = {
1820
+ pluginName: root.pluginName,
1821
+ path: `${root.path}.content`,
1822
+ value: root.value.content
1823
+ };
1824
+ assertName(slot, "Schema content root slot", contentSource);
1825
+ const innerProgram = compileContent(contentSource, elementTypes, inlineTypes, mutableGroups, textGroups, unknownPolicy);
1826
+ if (innerProgram.allowsText) compileFailure("text-in-root-content", `Projected root grammar at ${contentSource.path} cannot allow text nodes.`, [contentSource], contentSource.path);
1827
+ if (root.value.structure) {
1828
+ const joinable = [...innerProgram.allowedElementTypes].find((type) => {
1829
+ const behavior = mutableElements.get(type)?.behavior;
1830
+ return !behavior?.object && !behavior?.void;
1831
+ });
1832
+ if (joinable !== void 0 || innerProgram.allowsUnknownElements) compileFailure("invalid-content-root-structure", `Schema content root at ${root.path} declares a set, whose members must each be an object or a void element, and ${joinable === void 0 ? "an unknown element" : `"${joinable}"`} is neither.`, [root], `${root.path}.structure`);
1833
+ }
1834
+ mutablePrograms.set(`contentRoot:${element.type}:${slot}`, innerProgram);
1835
+ }
1836
+ }
1837
+ const primaryProgram = compileContent(primaryRoot, elementTypes, inlineTypes, mutableGroups, textGroups, unknownPolicy);
1838
+ if (primaryProgram.allowsText) compileFailure("text-in-root-content", "The primary root grammar cannot allow text nodes.", [primaryRoot], primaryRoot.path);
1839
+ mutablePrograms.set("root", primaryProgram);
1840
+ for (const [name, source] of [...rootsByName].sort(([left], [right]) => left.localeCompare(right))) {
1841
+ const program = compileContent(source, elementTypes, inlineTypes, mutableGroups, textGroups, unknownPolicy);
1842
+ if (program.allowsText) compileFailure("text-in-root-content", `Named root "${name}" grammar cannot allow text nodes.`, [source], source.path);
1843
+ mutablePrograms.set(`root:${name}`, program);
1844
+ }
1845
+ const constructible = /* @__PURE__ */ new Set();
1846
+ const constructing = [];
1847
+ const validateElementConstruction = (type) => {
1848
+ if (constructible.has(type)) return;
1849
+ const cycleIndex = constructing.indexOf(type);
1850
+ if (cycleIndex !== -1) {
1851
+ const cycle = [...constructing.slice(cycleIndex), type];
1852
+ const element = getDefined(mutableElements.get(type));
1853
+ compileFailure("cyclic-content-default", `Schema construction defaults contain a cycle: ${cycle.join(" -> ")}.`, [element.source], element.source.path);
1854
+ }
1855
+ constructing.push(type);
1856
+ const contentRootProgramIds = [...mutableElements.get(type)?.contentRoots.keys() ?? []].map((slot) => `contentRoot:${type}:${slot}`);
1857
+ for (const programId of [`element:${type}`, ...contentRootProgramIds]) {
1858
+ const program = mutablePrograms.get(programId);
1859
+ const plan = program?.defaultPlan;
1860
+ if (plan?.kind === "element") validateElementConstruction(plan.type);
1861
+ for (const slot of program?.prefix ?? []) validateElementConstruction(slot.type);
1862
+ }
1863
+ constructing.pop();
1864
+ constructible.add(type);
1865
+ };
1866
+ for (const program of mutablePrograms.values()) {
1867
+ if (program.defaultPlan?.kind === "element") validateElementConstruction(program.defaultPlan.type);
1868
+ for (const slot of program.prefix ?? []) validateElementConstruction(slot.type);
1869
+ }
1870
+ const frozenPrograms = /* @__PURE__ */ new Map();
1871
+ const defaultPlans = /* @__PURE__ */ new Map();
1872
+ for (const [id, program] of [...mutablePrograms].sort(([left], [right]) => left.localeCompare(right))) {
1873
+ const frozen = freezeContentProgram(program);
1874
+ frozenPrograms.set(id, frozen);
1875
+ if (frozen.defaultPlan) defaultPlans.set(id, frozen.defaultPlan);
1876
+ }
1877
+ const mutableProperties = [];
1878
+ const addProperty = (raw, key, placement, target, lifecycle, source, exclusiveGroupIds = []) => {
1879
+ const clonedKey = validatePropertyKey(key, placement, source);
1880
+ const clonedTarget = target ? cloneTarget(target, source, elementTypes, mutableGroups, rootNames) : null;
1881
+ const descriptor = clonePropertyDescriptor("value" in raw ? raw.value : raw, source);
1882
+ const role = "value" in raw ? raw.role : "content";
1883
+ const references = "value" in raw && raw.placement === "element" ? referencesOf(raw, source) : void 0;
1884
+ const semanticId = overriddenPropertyIds.get(raw) ?? Reflect.get(raw, compiledSchemaPropertyIdentity);
1885
+ const rawCopy = lifecycle.copy;
1886
+ if (rawCopy !== void 0 && rawCopy !== "drop" && rawCopy !== "preserve") compileFailure("invalid-property-copy", `Schema property at ${source.path} has invalid copy policy.`, [source], source.path);
1887
+ const copy = rawCopy === "drop" ? "drop" : "preserve";
1888
+ const rawLanding = lifecycle.landing ?? "preserve";
1889
+ if (rawLanding !== "adopt" && rawLanding !== "preserve" && rawLanding !== "rebase") compileFailure("invalid-property-landing", `Schema property at ${source.path} has invalid landing policy.`, [source], source.path);
1890
+ if (copy === "drop" && descriptor.required) compileFailure("invalid-property-copy", `Schema property at ${source.path} required cannot use copy: drop.`, [source], source.path);
1891
+ if (role !== "content" && role !== "metadata") compileFailure("invalid-property-role", `Schema property at ${source.path} has invalid role.`, [source], source.path);
1892
+ const { unique } = lifecycle;
1893
+ const uniqueRefusal = unique === void 0 ? null : uniqueRefusalOf({
1894
+ copy,
1895
+ key: clonedKey,
1896
+ landing: rawLanding,
1897
+ role,
1898
+ split: lifecycle.split,
1899
+ typeChange: lifecycle.typeChange,
1900
+ unique,
1901
+ value: descriptor
1902
+ });
1903
+ if (uniqueRefusal) compileFailure("invalid-property-unique", `Schema property at ${source.path} ${uniqueRefusal}.`, [source], source.path);
1904
+ mutableProperties.push({
1905
+ descriptor,
1906
+ exclusiveGroupIds: Object.freeze([...new Set(exclusiveGroupIds)].sort((left, right) => left.localeCompare(right))),
1907
+ key: clonedKey,
1908
+ lifecycle: Object.freeze({
1909
+ copy,
1910
+ inclusive: lifecycle.inclusive,
1911
+ ...rawLanding === "adopt" || rawLanding === "rebase" ? { landing: rawLanding } : {},
1912
+ split: lifecycle.split,
1913
+ typeChange: lifecycle.typeChange,
1914
+ ...unique === void 0 ? {} : { unique: true }
1915
+ }),
1916
+ merge: descriptor.kind === "set" ? "set" : "replace",
1917
+ owner: source.pluginName,
1918
+ placement,
1919
+ ...references ? { references } : {},
1920
+ role,
1921
+ ...semanticId ? { semanticId } : {},
1922
+ source,
1923
+ target: clonedTarget
1924
+ });
1925
+ };
1926
+ for (const element of mutableElements.values()) for (const [key, descriptor] of Object.entries(element.input.properties ?? {}).sort(([left], [right]) => left.localeCompare(right))) {
1927
+ const source = {
1928
+ pluginName: element.source.pluginName,
1929
+ path: `${element.source.path}.properties.${key}`,
1930
+ value: descriptor
1931
+ };
1932
+ addProperty(descriptor, key, "element", Object.freeze({
1933
+ kind: "type",
1934
+ type: element.type
1935
+ }), Object.freeze({
1936
+ copy: "preserve",
1937
+ inclusive: null,
1938
+ split: defaultSplitOf(descriptor),
1939
+ typeChange: "drop"
1940
+ }), source);
1941
+ }
1942
+ for (const record of records) for (const [index, property] of (record.contribution.properties ?? []).entries()) {
1943
+ const source = {
1944
+ pluginName: record.pluginName,
1945
+ path: `properties.${index}`,
1946
+ value: property
1947
+ };
1948
+ if (property.placement === "element") {
1949
+ const elementProperty = property;
1950
+ if (!elementProperty.target) compileFailure("missing-property-target", `Schema element property at ${source.path} requires a target.`, [source], source.path);
1951
+ addProperty(property, property.key, "element", elementProperty.target, Object.freeze({
1952
+ copy: property.copy,
1953
+ inclusive: null,
1954
+ landing: property.landing,
1955
+ split: property.split,
1956
+ typeChange: property.typeChange,
1957
+ ...Object.hasOwn(property, "unique") ? { unique: property.unique } : {}
1958
+ }), source);
1959
+ } else if (property.placement === "text") {
1960
+ const textProperty = property;
1961
+ addProperty(property, property.key, "text", textProperty.target ?? null, Object.freeze({
1962
+ copy: property.copy,
1963
+ inclusive: textProperty.inclusive,
1964
+ split: property.split,
1965
+ typeChange: property.typeChange
1966
+ }), source, (textProperty.exclusive ?? []).map(({ id }) => id));
1967
+ } else compileFailure("invalid-property-placement", `Schema property at ${source.path} has invalid placement.`, [source], source.path);
1968
+ }
1969
+ const selectorDiagnostics = [];
1970
+ for (let leftIndex = 0; leftIndex < mutableProperties.length; leftIndex++) {
1971
+ const left = mutableProperties[leftIndex];
1972
+ for (let rightIndex = leftIndex + 1; rightIndex < mutableProperties.length; rightIndex++) {
1973
+ const right = mutableProperties[rightIndex];
1974
+ if (left.placement !== right.placement || !propertySelectorsOverlap(left.key, right.key) || !targetCombinationIsSatisfiable(targetSchema, [left.target, right.target], void 0, targetSatisfiabilityCache)) continue;
1975
+ selectorDiagnostics.push(Object.freeze({
1976
+ code: "property-selector-conflict",
1977
+ plugins: Object.freeze([left.owner, right.owner]),
1978
+ message: `Schema ${left.placement} property selectors "${propertyKeyLabel(left.key)}" and "${propertyKeyLabel(right.key)}" overlap in declarations from "${left.owner}" and "${right.owner}".`,
1979
+ path: right.source.path
1980
+ }));
1981
+ }
1982
+ }
1983
+ if (selectorDiagnostics.length > 0) throw new EditorSchemaCompileError(selectorDiagnostics);
1984
+ assertPropertyAgreesAcrossPlaces(mutableProperties);
1985
+ const referencesRefusalOf = ({ descriptor, key, lifecycle, target }, references) => {
1986
+ if (lifecycle.unique) return `is unique, so it cannot reference "${references.key}"`;
1987
+ if (typeof key !== "string") return "references elements, so it needs an exact key";
1988
+ if (!isPlaceFreeTarget(target)) return "references elements, so it must target element types alone";
1989
+ if (Object.hasOwn(descriptor, "default")) return "references elements, so it cannot have a default value";
1990
+ if (!mutableProperties.some((property) => property.key === references.key && property.lifecycle.unique && property.descriptor.kind === "string")) return `references "${references.key}", which names no unique string element property`;
1991
+ return null;
1992
+ };
1993
+ for (const property of mutableProperties) {
1994
+ const { references, source } = property;
1995
+ const refusal = references && referencesRefusalOf(property, references);
1996
+ if (refusal) compileFailure("invalid-property-references", `Schema property at ${source.path} ${refusal}.`, [source], source.path);
1997
+ }
1998
+ const compiledProperties = mutableProperties.map((property) => {
1999
+ const id = property.semanticId ?? getCompiledSchemaPropertyId(property);
2000
+ return Object.freeze({
2001
+ descriptor: property.descriptor,
2002
+ exclusiveGroupIds: property.exclusiveGroupIds,
2003
+ id,
2004
+ key: property.key,
2005
+ lifecycle: property.lifecycle,
2006
+ merge: property.merge,
2007
+ owner: property.owner,
2008
+ placement: property.placement,
2009
+ ...property.references ? { references: property.references } : {},
2010
+ role: property.role,
2011
+ target: property.target
2012
+ });
2013
+ }).sort((left, right) => left.id.localeCompare(right.id));
2014
+ const byId = /* @__PURE__ */ new Map();
2015
+ for (const property of compiledProperties) {
2016
+ if (byId.has(property.id)) compileFailure("property-id-collision", `Compiled schema property ID collision for "${property.id}".`, [property.owner], "properties");
2017
+ byId.set(property.id, property);
2018
+ }
2019
+ const membersByExclusiveGroup = /* @__PURE__ */ new Map();
2020
+ for (const property of compiledProperties) for (const groupId of property.exclusiveGroupIds) {
2021
+ const members = membersByExclusiveGroup.get(groupId) ?? /* @__PURE__ */ new Set();
2022
+ members.add(property.id);
2023
+ membersByExclusiveGroup.set(groupId, members);
2024
+ }
2025
+ const conflictsByPropertyId = /* @__PURE__ */ new Map();
2026
+ for (const property of compiledProperties) {
2027
+ const conflicts = /* @__PURE__ */ new Set();
2028
+ for (const groupId of property.exclusiveGroupIds) for (const memberId of membersByExclusiveGroup.get(groupId) ?? []) if (memberId !== property.id) conflicts.add(memberId);
2029
+ conflictsByPropertyId.set(property.id, conflicts);
2030
+ }
2031
+ const propertyIdsByElement = new Map([...elementTypes].map((type) => [type, /* @__PURE__ */ new Set()]));
2032
+ const textIdsByParent = new Map([...elementTypes].map((type) => [type, /* @__PURE__ */ new Set()]));
2033
+ for (const property of compiledProperties) {
2034
+ const destination = property.placement === "element" ? propertyIdsByElement : textIdsByParent;
2035
+ const { target } = property;
2036
+ const directTypes = !target ? elementTypes : target.kind === "type" ? [target.type] : target.kind === "types" ? target.types : target.kind === "group" ? targetSchema.elements.groups.get(target.group) ?? [] : null;
2037
+ if (directTypes) {
2038
+ for (const type of directTypes) destination.get(type)?.add(property.id);
2039
+ continue;
2040
+ }
2041
+ for (const type of elementTypes) if (targetCombinationIsSatisfiable(targetSchema, [property.target], type, targetSatisfiabilityCache)) getDefined(destination.get(type)).add(property.id);
2042
+ }
2043
+ const referencedKeys = new Set(mutableProperties.flatMap(({ references }) => references ? [references.key] : []));
2044
+ const namesThroughReference = (property) => property.references !== void 0 || property.lifecycle.unique === true && typeof property.key === "string" && referencedKeys.has(property.key);
2045
+ const refuseFixedReference = (program, holder, path, key) => compileFailure("invalid-property-references", `Schema content ${holder} at ${path} cannot fix "${key}", because a reference names elements through it.`, [program.source], `${path}.properties.${key}`);
2046
+ for (const program of mutablePrograms.values()) {
2047
+ const plan = program.defaultPlan;
2048
+ if (plan?.kind === "element") {
2049
+ const path = `${program.source.path}.default`;
2050
+ for (const key of Object.keys(plan.properties ?? {})) for (const id of propertyIdsByElement.get(plan.type) ?? []) {
2051
+ const property = byId.get(id);
2052
+ if (property?.placement === "element" && property.key === key && namesThroughReference(property)) refuseFixedReference(program, "default", path, key);
2053
+ }
2054
+ }
2055
+ for (const [index, slot] of (program.prefix ?? []).entries()) {
2056
+ const path = `${program.source.path}.prefix.${index}`;
2057
+ const allowedIds = propertyIdsByElement.get(slot.type) ?? /* @__PURE__ */ new Set();
2058
+ for (const [key, value] of Object.entries(slot.properties)) {
2059
+ const candidates = [...allowedIds].map((id) => byId.get(id)).filter((property) => property?.placement === "element" && property.key === key);
2060
+ if (candidates.length !== 1) compileFailure("invalid-content-prefix-property", `Schema content slot at ${path} does not own one element property "${key}" on "${slot.type}".`, [program.source], `${path}.properties.${key}`);
2061
+ const candidate = candidates[0];
2062
+ const source = {
2063
+ ...program.source,
2064
+ path: `${path}.properties.${key}`,
2065
+ value
2066
+ };
2067
+ if (namesThroughReference(candidate)) refuseFixedReference(program, "slot", path, key);
2068
+ const canonical = canonicalizePropertyValue(candidate.descriptor, value, source);
2069
+ if (stableStringify(canonical) !== stableStringify(value)) compileFailure("invalid-content-prefix-property", `Schema content slot property "${key}" at ${path} must use its canonical value.`, [program.source], source.path);
2070
+ }
2071
+ for (const id of allowedIds) {
2072
+ const property = byId.get(id);
2073
+ if (property?.placement === "element" && typeof property.key === "string" && property.descriptor.required && !Object.hasOwn(property.descriptor, "default") && !property.descriptor.generate && !Object.hasOwn(slot.properties, property.key) && (property.target === null || property.target.kind === "type")) compileFailure("missing-content-prefix-property", `Schema content slot at ${path} needs required property "${property.key}" on "${slot.type}".`, [program.source], `${path}.properties.${property.key}`);
2074
+ }
2075
+ }
2076
+ }
2077
+ const compiledElements = /* @__PURE__ */ new Map();
2078
+ const compileStructureProperty = (element, propertyIds, key, field, numeric) => {
2079
+ const path = `${element.source.path}.structure.${field}`;
2080
+ if (typeof key !== "string" || key.length === 0) compileFailure("invalid-structure-property", `Schema element "${element.type}" structure field "${field}" must reference a non-empty element property key.`, [element.source], path);
2081
+ const propertyKey = key;
2082
+ const candidates = [...propertyIds].flatMap((id) => {
2083
+ const property = byId.get(id);
2084
+ return property?.placement === "element" && property.key === propertyKey ? [property] : [];
2085
+ });
2086
+ if (candidates.length !== 1) compileFailure("invalid-structure-property", `Schema element "${element.type}" structure field "${field}" must reference exactly one property allowed on that element.`, [element.source], path);
2087
+ const [property] = candidates;
2088
+ if (numeric && property.descriptor.kind !== "number") compileFailure("invalid-structure-property", `Schema element "${element.type}" structure field "${field}" must reference a number property.`, [element.source], path);
2089
+ return Object.freeze({
2090
+ id: property.id,
2091
+ key: propertyKey,
2092
+ kind: "schema-property",
2093
+ placement: "element"
2094
+ });
2095
+ };
2096
+ const compileElementStructure = (element, propertyIds) => {
2097
+ const { structure } = element.input;
2098
+ if (!structure) return null;
2099
+ switch (structure.kind) {
2100
+ case "outline": return Object.freeze({
2101
+ kind: "outline",
2102
+ level: compileStructureProperty(element, propertyIds, structure.level, "level", true)
2103
+ });
2104
+ case "list": return Object.freeze({
2105
+ depth: compileStructureProperty(element, propertyIds, structure.depth, "depth", true),
2106
+ kind: "list",
2107
+ membership: structure.membership === void 0 ? null : compileStructureProperty(element, propertyIds, structure.membership, "membership", false)
2108
+ });
2109
+ case "grid":
2110
+ if (structure.role !== "cell" && (structure.columnSpan !== void 0 || structure.rowSpan !== void 0)) compileFailure("invalid-structure-grid", `Schema element "${element.type}" can declare grid spans only for the "cell" role.`, [element.source], `${element.source.path}.structure`);
2111
+ if (structure.role !== "cell" && structure.role !== "grid" && structure.role !== "row") compileFailure("invalid-structure-grid", `Schema element "${element.type}" has an invalid grid role.`, [element.source], `${element.source.path}.structure.role`);
2112
+ return Object.freeze({
2113
+ columnSpan: structure.columnSpan === void 0 ? null : compileStructureProperty(element, propertyIds, structure.columnSpan, "columnSpan", true),
2114
+ kind: "grid",
2115
+ role: structure.role,
2116
+ rowSpan: structure.rowSpan === void 0 ? null : compileStructureProperty(element, propertyIds, structure.rowSpan, "rowSpan", true)
2117
+ });
2118
+ default: return compileFailure("invalid-structure-kind", `Schema element "${element.type}" has an unknown logical structure kind.`, [element.source], `${element.source.path}.structure.kind`);
2119
+ }
2120
+ };
2121
+ for (const [type, element] of [...mutableElements].sort(([left], [right]) => left.localeCompare(right))) {
2122
+ const propertyIds = freezeSet(propertyIdsByElement.get(type) ?? /* @__PURE__ */ new Set());
2123
+ const materializedPropertyIds = freezeSet(new Set([...propertyIds].filter((id) => {
2124
+ const descriptor = byId.get(id)?.descriptor;
2125
+ return !!descriptor && (Object.hasOwn(descriptor, "default") || !!descriptor.generate);
2126
+ })));
2127
+ const contentRoots = freezeMap(new Map([...element.contentRoots].sort(([left], [right]) => left.localeCompare(right)).map(([slot, root]) => [slot, Object.freeze({
2128
+ content: getDefined(frozenPrograms.get(`contentRoot:${type}:${slot}`)),
2129
+ ownership: root.value.ownership,
2130
+ structure: root.value.structure ? Object.freeze({ kind: root.value.structure.kind }) : null
2131
+ })])));
2132
+ const explicitPreserveContext = Object.hasOwn(element.input.slice ?? {}, "preserveContext");
2133
+ if (explicitPreserveContext && (element.behavior.atom || element.behavior.void)) compileFailure("invalid-slice-policy", `Schema element "${type}" cannot preserve slice context because it does not expose editable child content.`, [element.source], `${element.source.path}.slice.preserveContext`);
2134
+ const preserveContext = element.input.slice?.preserveContext ?? false;
2135
+ const endMatter = element.input.slice?.endMatter ?? false;
2136
+ if (Object.hasOwn(element.input.slice ?? {}, "endMatter") && (element.behavior.inline || element.behavior.void || explicitPreserveContext)) compileFailure("invalid-slice-policy", `Schema element "${type}" cannot declare end matter on an inline or void element or beside preserveContext.`, [element.source], `${element.source.path}.slice.endMatter`);
2137
+ compiledElements.set(type, Object.freeze({
2138
+ behavior: element.behavior,
2139
+ content: getDefined(frozenPrograms.get(`element:${type}`)),
2140
+ contentRoots,
2141
+ construction: Object.freeze({
2142
+ materializedPropertyIds,
2143
+ propertyIds
2144
+ }),
2145
+ groups: freezeSet(memberships.get(type) ?? /* @__PURE__ */ new Set()),
2146
+ propertyIds,
2147
+ slice: Object.freeze({
2148
+ endMatter,
2149
+ preserveContext,
2150
+ replaceWhenCovered: element.input.slice?.replaceWhenCovered ?? !preserveContext
2151
+ }),
2152
+ structure: compileElementStructure(element, propertyIds),
2153
+ type
2154
+ }));
2155
+ }
2156
+ const allowedChildren = /* @__PURE__ */ new Map();
2157
+ const allowedParents = new Map([...elementTypes].map((type) => [type, /* @__PURE__ */ new Set()]));
2158
+ for (const [id, program] of frozenPrograms) {
2159
+ allowedChildren.set(id, program.allowedElementTypes);
2160
+ for (const type of program.allowedElementTypes) allowedParents.get(type)?.add(id);
2161
+ }
2162
+ const wrapperPlans = /* @__PURE__ */ new Map();
2163
+ for (const [programId, program] of frozenPrograms) {
2164
+ const emptyPlan = Object.freeze([]);
2165
+ if (program.allowsText) wrapperPlans.set(getCompiledSchemaWrapperPlanKey(programId, null), emptyPlan);
2166
+ for (const type of program.allowedElementTypes) wrapperPlans.set(getCompiledSchemaWrapperPlanKey(programId, type), emptyPlan);
2167
+ }
2168
+ const roots = /* @__PURE__ */ new Map();
2169
+ for (const name of sortedStrings(rootNames)) roots.set(name, Object.freeze({
2170
+ content: getDefined(frozenPrograms.get(`root:${name}`)),
2171
+ name
2172
+ }));
2173
+ const elementLookup = compilePropertyLookup(compiledProperties, "element");
2174
+ const textLookup = compilePropertyLookup(compiledProperties, "text");
2175
+ const mergeStrategies = new Map(compiledProperties.map((property) => [property.id, property.merge]));
2176
+ const lifecycle = new Map(compiledProperties.map((property) => [property.id, property.lifecycle]));
2177
+ const canonicalModel = {
2178
+ elements: [...compiledElements].map(([type, element]) => ({
2179
+ behavior: canonicalSchemaElementBehavior(declaredContractBehavior(element.behavior)),
2180
+ content: element.content ? canonicalContentProgram(element.content) : null,
2181
+ contentRoots: [...element.contentRoots].map(([slot, root]) => ({
2182
+ content: canonicalContentProgram(root.content),
2183
+ ownership: root.ownership,
2184
+ slot
2185
+ })),
2186
+ construction: {
2187
+ materializedPropertyIds: sortedStrings(element.construction.materializedPropertyIds),
2188
+ propertyIds: sortedStrings(element.construction.propertyIds)
2189
+ },
2190
+ groups: sortedStrings(element.groups),
2191
+ slice: contractSlicePolicy(element.slice),
2192
+ ...element.structure ? { structure: element.structure } : {},
2193
+ type
2194
+ })),
2195
+ groups: [...mutableGroups].sort(([left], [right]) => left.localeCompare(right)).map(([group, members]) => ({
2196
+ group,
2197
+ members: sortedStrings(members)
2198
+ })),
2199
+ properties: compiledProperties.map((property) => ({
2200
+ descriptor: canonicalDescriptor(property.descriptor),
2201
+ exclusiveGroupIds: property.exclusiveGroupIds,
2202
+ id: property.id,
2203
+ key: typeof property.key === "string" ? { exact: property.key } : { prefix: property.key.prefix },
2204
+ lifecycle: property.lifecycle,
2205
+ merge: property.merge,
2206
+ placement: property.placement,
2207
+ ...property.references ? { references: { key: property.references.key } } : {},
2208
+ role: property.role,
2209
+ target: canonicalTarget(property.target)
2210
+ })),
2211
+ root: canonicalContentProgram(primaryProgram),
2212
+ roots: [...roots].map(([name, root]) => ({
2213
+ ...canonicalContentProgram(root.content),
2214
+ name
2215
+ })),
2216
+ ...storageRevisionOf(compiledProperties),
2217
+ unknown: unknownPolicy
2218
+ };
2219
+ const fingerprint = `fnv1a64:${hashSchemaIdentityString(stableStringify(canonicalModel))}`;
2220
+ const vocabulary = Object.freeze({
2221
+ elementTypes: Object.freeze(sortedStrings(elementTypes)),
2222
+ groupNames: Object.freeze(sortedStrings(groupParents.keys())),
2223
+ propertyIds: Object.freeze(compiledProperties.map(({ id }) => id)),
2224
+ rootNames: Object.freeze(sortedStrings(rootNames))
2225
+ });
2226
+ const frozenGroups = freezeSetMap(mutableGroups);
2227
+ const elements = Object.freeze({
2228
+ allowedChildren: freezeMap(allowedChildren),
2229
+ allowedParents: freezeSetMap(allowedParents),
2230
+ byType: freezeMap(compiledElements),
2231
+ contentPrograms: freezeMap(frozenPrograms),
2232
+ defaultPlans: freezeMap(defaultPlans),
2233
+ groups: frozenGroups,
2234
+ textGroups: freezeSet(textGroups),
2235
+ wrapperPlans: freezeMap(wrapperPlans)
2236
+ });
2237
+ for (const property of mutableProperties) {
2238
+ const refusal = property.lifecycle.unique ? retypeDropOf({
2239
+ elements,
2240
+ unknown: unknownPolicy
2241
+ }, property, (type) => !compiledElements.get(type)?.behavior.void) : null;
2242
+ if (refusal) compileFailure("invalid-property-unique", `Schema property at ${property.source.path} unique needs ${refusal}.`, [property.source], property.source.path);
2243
+ }
2244
+ return Object.freeze({
2245
+ diagnostics: Object.freeze([]),
2246
+ elements,
2247
+ identity: derived ? Object.freeze({
2248
+ fingerprint,
2249
+ kind: "derived"
2250
+ }) : Object.freeze({
2251
+ fingerprint,
2252
+ id: definition.id,
2253
+ kind: "named",
2254
+ version: definition.version
2255
+ }),
2256
+ primaryRoot: Object.freeze({
2257
+ content: getDefined(frozenPrograms.get("root")),
2258
+ name: null
2259
+ }),
2260
+ properties: Object.freeze({
2261
+ byId: freezeMap(byId),
2262
+ conflictsByPropertyId: freezeSetMap(conflictsByPropertyId),
2263
+ elementAllowedByType: freezeSetMap(propertyIdsByElement),
2264
+ lifecycle: freezeMap(lifecycle),
2265
+ lookup: Object.freeze({
2266
+ element: elementLookup,
2267
+ text: textLookup
2268
+ }),
2269
+ mergeStrategies: freezeMap(mergeStrategies),
2270
+ membersByExclusiveGroup: freezeSetMap(membersByExclusiveGroup),
2271
+ textAllowedByParentType: freezeSetMap(textIdsByParent)
2272
+ }),
2273
+ recordSets: freezeMap(new Map([...recordSets].map(([name, { history }]) => [name, Object.freeze({ history })]))),
2274
+ revision,
2275
+ roots: freezeMap(roots),
2276
+ unknown: unknownPolicy,
2277
+ vocabulary
2278
+ });
2279
+ };
2280
+ const compileEditorSchemaContributions = (records, options = {}) => profileCoreDuration("schema-compile", () => compileEditorSchemaInternal(prepareEditorSchemaRecords(records), options.revision ?? 0));
2281
+ const collectRuntimePropertyDescriptors = (records) => {
2282
+ const descriptors = /* @__PURE__ */ new Map();
2283
+ for (const record of records) {
2284
+ for (const [type, element] of Object.entries(record.contribution.elements ?? {})) for (const [key, descriptor] of Object.entries(element.properties ?? {})) descriptors.set(overriddenPropertyIds.get(descriptor) ?? getCompiledSchemaPropertyId({
2285
+ key,
2286
+ placement: "element",
2287
+ target: Object.freeze({
2288
+ kind: "type",
2289
+ type
2290
+ })
2291
+ }), Object.freeze({
2292
+ descriptor,
2293
+ source: {
2294
+ pluginName: record.pluginName,
2295
+ path: `elements.${type}.properties.${key}`,
2296
+ value: descriptor
2297
+ }
2298
+ }));
2299
+ for (const [index, property] of (record.contribution.properties ?? []).entries()) {
2300
+ const source = {
2301
+ pluginName: record.pluginName,
2302
+ path: `properties.${index}`,
2303
+ value: property
2304
+ };
2305
+ const references = property.placement === "element" ? referencesOf(property, source) : void 0;
2306
+ descriptors.set(getCompiledSchemaPropertyId(property), Object.freeze({
2307
+ descriptor: property.value,
2308
+ ...references ? { references } : {},
2309
+ source
2310
+ }));
2311
+ }
2312
+ }
2313
+ return descriptors;
2314
+ };
2315
+ const getRuntimeValidationBinding = (descriptor) => {
2316
+ const validate = Reflect.get(descriptor, "validate");
2317
+ return typeof validate === "function" ? validate : null;
2318
+ };
2319
+ const getRuntimeGeneratorBinding = (descriptor) => {
2320
+ const generate = Reflect.get(descriptor, "generate");
2321
+ return typeof generate === "function" ? generate : null;
2322
+ };
2323
+ const haveEquivalentRuntimeValidationBindings = (left, right) => {
2324
+ if (getRuntimeValidationBinding(left) !== getRuntimeValidationBinding(right) || getRuntimeGeneratorBinding(left) !== getRuntimeGeneratorBinding(right)) return false;
2325
+ if (left.kind !== "set" || right.kind !== "set") return left.kind === right.kind;
2326
+ const leftItem = left.item;
2327
+ const rightItem = right.item;
2328
+ return Boolean(leftItem && rightItem && haveEquivalentRuntimeValidationBindings(leftItem, rightItem));
2329
+ };
2330
+ const replaceCompiledPropertyDescriptors = (schema, descriptors, revision) => {
2331
+ const byId = /* @__PURE__ */ new Map();
2332
+ for (const [id, { references: _references, ...property }] of schema.properties.byId) {
2333
+ const runtime = descriptors.get(id);
2334
+ if (!runtime) throw new Error(`Missing runtime schema property descriptor "${id}".`);
2335
+ byId.set(id, Object.freeze({
2336
+ ...property,
2337
+ descriptor: runtime.descriptor,
2338
+ ...runtime.references ? { references: runtime.references } : {}
2339
+ }));
2340
+ }
2341
+ return Object.freeze({
2342
+ ...schema,
2343
+ properties: Object.freeze({
2344
+ ...schema.properties,
2345
+ byId: freezeMap(byId)
2346
+ }),
2347
+ revision
2348
+ });
2349
+ };
2350
+ const toStructuralPropertyDescriptor = (descriptor) => {
2351
+ const item = descriptor.kind === "set" ? toStructuralPropertyDescriptor(descriptor.item) : null;
2352
+ const values = descriptor.kind === "enum" ? descriptor.values : null;
2353
+ return Object.freeze({
2354
+ ...Object.hasOwn(descriptor, "default") ? { default: descriptor.default } : {},
2355
+ ...item ? { item } : {},
2356
+ ...descriptor.generate ? { generated: true } : {},
2357
+ kind: descriptor.kind,
2358
+ omitDefault: descriptor.omitDefault,
2359
+ required: descriptor.required,
2360
+ ...descriptor.validationVersion ? { validationVersion: descriptor.validationVersion } : {},
2361
+ ...values ? { values } : {}
2362
+ });
2363
+ };
2364
+ /**
2365
+ * Cache only structural schema data, never live validator closures.
2366
+ *
2367
+ * @internal
2368
+ */
2369
+ const stripCompiledEditorSchemaRuntimeValidations = (schema) => {
2370
+ const byId = /* @__PURE__ */ new Map();
2371
+ for (const [id, property] of schema.properties.byId) {
2372
+ const { references, ...structural } = property;
2373
+ byId.set(id, Object.freeze({
2374
+ ...structural,
2375
+ descriptor: toStructuralPropertyDescriptor(property.descriptor),
2376
+ ...references ? { references: { key: references.key } } : {}
2377
+ }));
2378
+ }
2379
+ return Object.freeze({
2380
+ ...schema,
2381
+ properties: Object.freeze({
2382
+ ...schema.properties,
2383
+ byId: freezeMap(byId)
2384
+ })
2385
+ });
2386
+ };
2387
+ const isBoundTo = (schema, current, revision) => schema.revision === revision && schema.properties.byId.size === current.size && [...schema.properties.byId].every(([id, property]) => {
2388
+ const runtime = current.get(id);
2389
+ return Boolean(runtime && (property.references === void 0 ? runtime.references === void 0 : "map" in property.references && property.references.map === runtime.references?.map) && haveEquivalentRuntimeValidationBindings(property.descriptor, runtime.descriptor));
2390
+ });
2391
+ /**
2392
+ * Bind one reused structural schema to the current configuration.
2393
+ *
2394
+ * @internal
2395
+ */
2396
+ const rebindCompiledEditorSchemaRuntimeValidations = (schema, records, revision) => {
2397
+ const current = collectRuntimePropertyDescriptors(records);
2398
+ if (isBoundTo(schema, current, revision)) return schema;
2399
+ const descriptors = /* @__PURE__ */ new Map();
2400
+ for (const id of schema.properties.byId.keys()) {
2401
+ const runtime = current.get(id);
2402
+ if (!runtime) throw new Error(`Missing current schema property descriptor "${id}".`);
2403
+ descriptors.set(id, {
2404
+ ...runtime,
2405
+ descriptor: clonePropertyDescriptor(runtime.descriptor, runtime.source)
2406
+ });
2407
+ }
2408
+ return replaceCompiledPropertyDescriptors(schema, descriptors, revision);
2409
+ };
2410
+ const EDITOR_SCHEMA_CONTRACT_FORMAT = 1;
2411
+ const canonicalContentProgram = (program) => ({
2412
+ allowedElementTypes: sortedStrings(program.allowedElementTypes),
2413
+ allowsText: program.allowsText,
2414
+ allowsUnknownElements: program.allowsUnknownElements,
2415
+ defaultPlan: program.defaultPlan,
2416
+ max: program.max,
2417
+ min: program.min,
2418
+ ...program.prefix ? { prefix: program.prefix } : {},
2419
+ ...program.remainder ? { remainder: canonicalContentProgram(program.remainder) } : {}
2420
+ });
2421
+ /**
2422
+ * The split policy of an element property whose declaration names none, so a
2423
+ * split never copies a generated value onto its second half.
2424
+ */
2425
+ const defaultSplitOf = (descriptor) => descriptor.generate ? "drop" : "preserve";
2426
+ /** Whether `target` holds wherever a node of its types stands. */
2427
+ const isPlaceFreeTarget = (target) => {
2428
+ if (!target) return true;
2429
+ switch (target.kind) {
2430
+ case "parent":
2431
+ case "root": return false;
2432
+ case "not": return isPlaceFreeTarget(target.target);
2433
+ case "and":
2434
+ case "or": return target.targets.every(isPlaceFreeTarget);
2435
+ default: return true;
2436
+ }
2437
+ };
2438
+ /**
2439
+ * Whether a write can store the value `property` generates for the blocks a
2440
+ * pending change can need: an element property with an exact key, a value
2441
+ * other than a set, a target that reads neither its parent nor the root, and
2442
+ * no content role, since a rejected split compares content values, which an
2443
+ * `as` member would hide.
2444
+ */
2445
+ const isSupportedGeneratedElementProperty = (property) => property.placement === "element" && ("generated" in property.descriptor && property.descriptor.generated === true || "generate" in property.descriptor && typeof property.descriptor.generate === "function") && typeof property.key === "string" && property.descriptor.kind !== "set" && isPlaceFreeTarget(property.target) && property.role !== "content";
2446
+ const uniqueRefusalOf = (declaration) => {
2447
+ if (declaration.unique !== true) return "unique must be true";
2448
+ if (typeof declaration.value.generate !== "function") return "unique needs a generator";
2449
+ if (declaration.value.kind === "set") return "unique cannot hold a set";
2450
+ if (typeof declaration.key !== "string") return "unique needs an exact key";
2451
+ if (declaration.copy !== "drop") return "unique requires copy: drop";
2452
+ if (declaration.split !== "drop") return "unique requires split: drop";
2453
+ if (declaration.landing !== "preserve") return "unique requires landing: preserve";
2454
+ if (declaration.typeChange !== "preserve-if-allowed") return "unique requires typeChange: preserve-if-allowed";
2455
+ if (declaration.role !== "metadata") return "unique requires role: metadata";
2456
+ return null;
2457
+ };
2458
+ const contentPlaceOf = (programId) => {
2459
+ const [kind, type, slot] = programId.split(":");
2460
+ if (kind === "root") return type ? `root "${type}"` : "the root";
2461
+ if (kind === "contentRoot") return `content root "${slot}" of "${type}"`;
2462
+ return `element "${type}"`;
2463
+ };
2464
+ /**
2465
+ * The requirement `property` misses, which lets a retype drop its value, or
2466
+ * null when it meets them all: metadata under an exact key whose target holds
2467
+ * wherever its types stand and on every type that can take a held type's
2468
+ * place. A retype keeps a node's place, so each content, a root's included,
2469
+ * that admits a held type that `binds` admits only held types, counting an
2470
+ * undeclared type wherever the schema preserves one, and an undeclared element
2471
+ * admits every type.
2472
+ */
2473
+ const retypeDropOf = (schema, property, binds = () => true) => {
2474
+ if (property.placement !== "element" || property.role !== "metadata" || typeof property.key !== "string") return "element metadata under an exact key";
2475
+ if (!isPlaceFreeTarget(property.target)) return "a target that holds wherever its types stand";
2476
+ const holds = (type) => matchesCompiledSchemaTarget(schema, property.target, {
2477
+ root: null,
2478
+ type
2479
+ });
2480
+ const preserves = schema.unknown === "preserve";
2481
+ const places = [...schema.elements.contentPrograms].map(([programId, program]) => [contentPlaceOf(programId), [...program.allowedElementTypes, ...preserves && program.allowsUnknownElements ? [UNKNOWN_TYPE] : []]]);
2482
+ if (places.some(([, types]) => types.includes(UNKNOWN_TYPE))) places.push(["an undeclared element", [...schema.elements.byType.keys(), UNKNOWN_TYPE]]);
2483
+ for (const [place, types] of places) {
2484
+ const held = types.find((type) => holds(type) && binds(type));
2485
+ const missed = types.find((type) => !holds(type));
2486
+ if (held !== void 0 && missed !== void 0) return `a target that holds on every type that can take a held type's place, but ${place} admits "${held}" and ${missed === UNKNOWN_TYPE ? "an undeclared type" : `"${missed}"`}`;
2487
+ }
2488
+ return null;
2489
+ };
2490
+ const SPLIT_KEYS = /* @__PURE__ */ new WeakMap();
2491
+ const splitKeysOf = (schema) => {
2492
+ let keys = SPLIT_KEYS.get(schema);
2493
+ if (!keys) {
2494
+ const declarations = /* @__PURE__ */ new Map();
2495
+ for (const property of schema.properties.byId.values()) {
2496
+ if (typeof property.key !== "string") continue;
2497
+ declarations.set(property.key, [...declarations.get(property.key) ?? [], property]);
2498
+ }
2499
+ const dropped = [...declarations].filter(([, properties]) => properties.every((property) => property.placement === "element" && property.lifecycle.split === "drop"));
2500
+ keys = {
2501
+ dropped: new Set(dropped.map(([key]) => key)),
2502
+ handover: new Set(dropped.flatMap(([key, properties]) => properties.every((property) => !retypeDropOf(schema, property)) ? [key] : []))
2503
+ };
2504
+ SPLIT_KEYS.set(schema, keys);
2505
+ }
2506
+ return keys;
2507
+ };
2508
+ /**
2509
+ * Element keys a split leaves off its second half, such as Plate's block id,
2510
+ * which generates there instead: every declaration of the key drops it on
2511
+ * split, content keys included. Two lines of a split always differ on them,
2512
+ * so comparing an emptied line with a split line ignores every one.
2513
+ */
2514
+ const splitDroppedKeysOf = (schema) => splitKeysOf(schema).dropped;
2515
+ /**
2516
+ * Those of {@link splitDroppedKeysOf} no retype can drop, so a line can take
2517
+ * their values from the line whose place it takes. Only element metadata
2518
+ * passes, so no content value moves.
2519
+ */
2520
+ const handoverKeysOf = (schema) => splitKeysOf(schema).handover;
2521
+ const UNIQUE_PROPERTIES = /* @__PURE__ */ new WeakMap();
2522
+ const uniquePropertiesOf = (schema) => {
2523
+ let byKey = UNIQUE_PROPERTIES.get(schema);
2524
+ if (!byKey) {
2525
+ byKey = new Map([...schema.properties.byId.values()].flatMap((property) => property.lifecycle.unique && typeof property.key === "string" ? [[property.key, property]] : []));
2526
+ UNIQUE_PROPERTIES.set(schema, byKey);
2527
+ }
2528
+ return byKey;
2529
+ };
2530
+ const UNIQUE_CROSSINGS = /* @__PURE__ */ new WeakMap();
2531
+ /**
2532
+ * Whether one of the types `from` and `to` holds a unique key the other does
2533
+ * not, so a retype between them replaces the element the value names.
2534
+ */
2535
+ const crossesUniqueTarget = (schema, from, to) => {
2536
+ let crossings = UNIQUE_CROSSINGS.get(schema);
2537
+ if (!crossings) {
2538
+ crossings = /* @__PURE__ */ new Map();
2539
+ UNIQUE_CROSSINGS.set(schema, crossings);
2540
+ }
2541
+ const pair = JSON.stringify([from, to]);
2542
+ let crosses = crossings.get(pair);
2543
+ if (crosses === void 0) {
2544
+ crosses = false;
2545
+ for (const property of uniquePropertiesOf(schema).values()) {
2546
+ countCoreWork("uniqueCrossingChecks");
2547
+ if (matchesCompiledSchemaTarget(schema, property.target, {
2548
+ root: null,
2549
+ type: from
2550
+ }) !== matchesCompiledSchemaTarget(schema, property.target, {
2551
+ root: null,
2552
+ type: to
2553
+ })) {
2554
+ crosses = true;
2555
+ break;
2556
+ }
2557
+ }
2558
+ crossings.set(pair, crosses);
2559
+ }
2560
+ return crosses;
2561
+ };
2562
+ const holdsUniqueKey = (schema, type, key) => {
2563
+ const property = uniquePropertiesOf(schema).get(key);
2564
+ return property !== void 0 && matchesCompiledSchemaTarget(schema, property.target, {
2565
+ root: null,
2566
+ type
2567
+ });
2568
+ };
2569
+ const storageRevisionOf = (properties) => {
2570
+ let revision;
2571
+ for (const property of properties) {
2572
+ if (isSupportedGeneratedElementProperty(property)) return { storageRevision: 2 };
2573
+ if (property.descriptor.omitDefault) revision = 1;
2574
+ }
2575
+ return revision === void 0 ? {} : { storageRevision: revision };
2576
+ };
2577
+ const freezeSortedStrings = (values) => Object.freeze(sortedStrings(values));
2578
+ const mapEntries = (source, map) => Object.freeze([...source].sort(([left], [right]) => left.localeCompare(right)).map(([key, value]) => Object.freeze([key, map(value)])));
2579
+ const contractContentProgram = (program) => Object.freeze({
2580
+ allowedElementTypes: freezeSortedStrings(program.allowedElementTypes),
2581
+ allowsText: program.allowsText,
2582
+ allowsUnknownElements: program.allowsUnknownElements,
2583
+ defaultPlan: program.defaultPlan,
2584
+ max: program.max,
2585
+ min: program.min,
2586
+ ...program.prefix ? { prefix: program.prefix } : {},
2587
+ ...program.remainder ? { remainder: contractContentProgram(program.remainder) } : {}
2588
+ });
2589
+ const contractContentRoot = (root) => Object.freeze({
2590
+ content: contractContentProgram(root.content),
2591
+ ownership: root.ownership,
2592
+ ...root.structure ? { structure: root.structure } : {}
2593
+ });
2594
+ const contractSlicePolicy = ({ endMatter, ...policy }) => Object.freeze({
2595
+ ...policy,
2596
+ ...endMatter ? { endMatter: true } : {}
2597
+ });
2598
+ const contractElement = (element) => Object.freeze({
2599
+ behavior: declaredContractBehavior(element.behavior),
2600
+ content: element.content ? contractContentProgram(element.content) : null,
2601
+ contentRoots: mapEntries(element.contentRoots, contractContentRoot),
2602
+ construction: Object.freeze({
2603
+ materializedPropertyIds: freezeSortedStrings(element.construction.materializedPropertyIds),
2604
+ propertyIds: freezeSortedStrings(element.construction.propertyIds)
2605
+ }),
2606
+ groups: freezeSortedStrings(element.groups),
2607
+ propertyIds: freezeSortedStrings(element.propertyIds),
2608
+ slice: contractSlicePolicy(element.slice),
2609
+ ...element.structure ? { structure: element.structure } : {},
2610
+ type: element.type
2611
+ });
2612
+ const contractRoot = (root) => Object.freeze({
2613
+ content: contractContentProgram(root.content),
2614
+ name: root.name
2615
+ });
2616
+ const contractStringSets = (source) => mapEntries(source, freezeSortedStrings);
2617
+ /** Serialize one compiled schema into deterministic validator-free JSON data. */
2618
+ const createEditorSchemaContract = (schema) => {
2619
+ const structural = stripCompiledEditorSchemaRuntimeValidations(schema);
2620
+ return cloneFrozen({
2621
+ diagnostics: structural.diagnostics,
2622
+ elements: Object.freeze({
2623
+ allowedChildren: contractStringSets(structural.elements.allowedChildren),
2624
+ allowedParents: contractStringSets(structural.elements.allowedParents),
2625
+ byType: Object.freeze([...structural.elements.byType.values()].sort((left, right) => left.type.localeCompare(right.type)).map(contractElement)),
2626
+ contentPrograms: mapEntries(structural.elements.contentPrograms, contractContentProgram),
2627
+ defaultPlans: mapEntries(structural.elements.defaultPlans, (value) => value),
2628
+ groups: contractStringSets(structural.elements.groups),
2629
+ textGroups: freezeSortedStrings(structural.elements.textGroups),
2630
+ wrapperPlans: mapEntries(structural.elements.wrapperPlans, (value) => Object.freeze([...value]))
2631
+ }),
2632
+ fingerprint: structural.identity.fingerprint,
2633
+ formatVersion: EDITOR_SCHEMA_CONTRACT_FORMAT,
2634
+ identity: structural.identity,
2635
+ primaryRoot: contractRoot(structural.primaryRoot),
2636
+ properties: Object.freeze({
2637
+ byId: Object.freeze([...structural.properties.byId.values()].sort((left, right) => left.id.localeCompare(right.id))),
2638
+ conflictsByPropertyId: contractStringSets(structural.properties.conflictsByPropertyId),
2639
+ elementAllowedByType: contractStringSets(structural.properties.elementAllowedByType),
2640
+ lifecycle: mapEntries(structural.properties.lifecycle, (value) => value),
2641
+ lookup: Object.freeze({
2642
+ element: Object.freeze({
2643
+ exact: mapEntries(structural.properties.lookup.element.exact, (value) => Object.freeze([...value])),
2644
+ prefixes: structural.properties.lookup.element.prefixes
2645
+ }),
2646
+ text: Object.freeze({
2647
+ exact: mapEntries(structural.properties.lookup.text.exact, (value) => Object.freeze([...value])),
2648
+ prefixes: structural.properties.lookup.text.prefixes
2649
+ })
2650
+ }),
2651
+ mergeStrategies: mapEntries(structural.properties.mergeStrategies, (value) => value),
2652
+ membersByExclusiveGroup: contractStringSets(structural.properties.membersByExclusiveGroup),
2653
+ textAllowedByParentType: contractStringSets(structural.properties.textAllowedByParentType)
2654
+ }),
2655
+ revision: structural.revision,
2656
+ ...storageRevisionOf(structural.properties.byId.values()),
2657
+ roots: Object.freeze([...structural.roots.values()].sort((left, right) => (left.name ?? "").localeCompare(right.name ?? "")).map(contractRoot)),
2658
+ unknown: structural.unknown,
2659
+ vocabulary: structural.vocabulary
2660
+ });
2661
+ };
2662
+ const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
2663
+ const isStringArray = (value) => Array.isArray(value) && value.every((item) => typeof item === "string");
2664
+ const isContractEntryArray = (value, isValue) => Array.isArray(value) && value.every((entry) => Array.isArray(entry) && entry.length === 2 && typeof entry[0] === "string" && isValue(entry[1]));
2665
+ const isContractConstructionPlan = (value) => isRecord(value) && (value.kind === "text" || value.kind === "element" && typeof value.type === "string" && (value.properties === void 0 || isRecord(value.properties)));
2666
+ const isContractContentProgram = (value) => isRecord(value) && isStringArray(value.allowedElementTypes) && typeof value.allowsText === "boolean" && typeof value.allowsUnknownElements === "boolean" && (value.defaultPlan === null || isContractConstructionPlan(value.defaultPlan)) && Number.isSafeInteger(value.min) && value.min >= 0 && (value.max === null || Number.isSafeInteger(value.max) && value.max >= value.min) && (value.prefix === void 0 || Array.isArray(value.prefix) && value.prefix.length > 0 && value.prefix.every((slot) => isRecord(slot) && typeof slot.type === "string" && isRecord(slot.properties)) && isContractContentProgram(value.remainder)) && (value.prefix !== void 0 || value.remainder === void 0);
2667
+ const isContractContentRoot = (value) => isRecord(value) && isContractContentProgram(value.content) && (value.ownership === "exclusive" || value.ownership === "shared") && (value.structure === void 0 || isRecord(value.structure) && value.structure.kind === "set");
2668
+ const isContractElementBehavior = (value) => isRecord(value) && [
2669
+ "atom",
2670
+ "inline",
2671
+ "isolating",
2672
+ "markableVoid",
2673
+ "object",
2674
+ "readOnly",
2675
+ "selectable",
2676
+ "void"
2677
+ ].every((key) => typeof value[key] === "boolean") && (value.ownsExit === void 0 || value.ownsExit === true) && (value.voidKind === null || isSchemaVoidKind(value.voidKind));
2678
+ const isContractStructureProperty = (value) => isRecord(value) && typeof value.id === "string" && typeof value.key === "string" && value.kind === "schema-property" && value.placement === "element";
2679
+ const isContractElementStructure = (value) => {
2680
+ if (!isRecord(value)) return false;
2681
+ switch (value.kind) {
2682
+ case "outline": return isContractStructureProperty(value.level);
2683
+ case "list": return isContractStructureProperty(value.depth) && (value.membership === null || isContractStructureProperty(value.membership));
2684
+ case "grid": return (value.role === "cell" || value.role === "grid" || value.role === "row") && (value.columnSpan === null || isContractStructureProperty(value.columnSpan)) && (value.rowSpan === null || isContractStructureProperty(value.rowSpan));
2685
+ default: return false;
2686
+ }
2687
+ };
2688
+ const isContractElement = (value) => isRecord(value) && typeof value.type === "string" && isContractElementBehavior(value.behavior) && (value.content === null || isContractContentProgram(value.content)) && isContractEntryArray(value.contentRoots, isContractContentRoot) && isRecord(value.construction) && isStringArray(value.construction.materializedPropertyIds) && isStringArray(value.construction.propertyIds) && isStringArray(value.groups) && isStringArray(value.propertyIds) && isRecord(value.slice) && (value.slice.endMatter === void 0 || typeof value.slice.endMatter === "boolean") && typeof value.slice.preserveContext === "boolean" && typeof value.slice.replaceWhenCovered === "boolean" && (value.structure === void 0 || isContractElementStructure(value.structure));
2689
+ const isContractRoot = (value) => isRecord(value) && (value.name === null || typeof value.name === "string") && isContractContentProgram(value.content);
2690
+ const isContractJsonValue = (value, seen = /* @__PURE__ */ new WeakSet()) => {
2691
+ if (value === null || typeof value === "string" || typeof value === "boolean") return true;
2692
+ if (typeof value === "number") return Number.isFinite(value);
2693
+ if (typeof value !== "object" || seen.has(value)) return false;
2694
+ seen.add(value);
2695
+ const valid = Array.isArray(value) ? value.every((item) => isContractJsonValue(item, seen)) : Object.values(value).every((item) => isContractJsonValue(item, seen));
2696
+ seen.delete(value);
2697
+ return valid;
2698
+ };
2699
+ const isContractTarget = (value, seen = /* @__PURE__ */ new WeakSet()) => {
2700
+ if (!isRecord(value) || seen.has(value)) return false;
2701
+ seen.add(value);
2702
+ let valid;
2703
+ switch (value.kind) {
2704
+ case "and":
2705
+ case "or":
2706
+ valid = Array.isArray(value.targets) && value.targets.every((item) => isContractTarget(item, seen));
2707
+ break;
2708
+ case "group":
2709
+ valid = typeof value.group === "string";
2710
+ break;
2711
+ case "not":
2712
+ case "parent":
2713
+ valid = isContractTarget(value.target, seen);
2714
+ break;
2715
+ case "root":
2716
+ valid = value.root === null || typeof value.root === "string";
2717
+ break;
2718
+ case "type":
2719
+ valid = typeof value.type === "string";
2720
+ break;
2721
+ case "types":
2722
+ valid = isStringArray(value.types);
2723
+ break;
2724
+ default: return false;
2725
+ }
2726
+ seen.delete(value);
2727
+ return valid;
2728
+ };
2729
+ const isContractDescriptor = (value, seen = /* @__PURE__ */ new WeakSet()) => {
2730
+ if (!isRecord(value) || seen.has(value) || ![
2731
+ "boolean",
2732
+ "enum",
2733
+ "json",
2734
+ "number",
2735
+ "set",
2736
+ "string"
2737
+ ].includes(String(value.kind)) || typeof value.omitDefault !== "boolean" || typeof value.required !== "boolean") return false;
2738
+ seen.add(value);
2739
+ if (Object.hasOwn(value, "default") && !isContractJsonValue(value.default)) return false;
2740
+ if (value.generated !== void 0 && value.generated !== true) return false;
2741
+ const hasDefault = Object.hasOwn(value, "default");
2742
+ if (value.required && (hasDefault || value.omitDefault)) return false;
2743
+ if (value.generated && (hasDefault || value.omitDefault || value.required)) return false;
2744
+ if (value.validationVersion !== void 0 && (!Number.isSafeInteger(value.validationVersion) || value.validationVersion < 1)) return false;
2745
+ if (value.kind === "enum" && !isStringArray(value.values)) return false;
2746
+ if (value.kind === "set" && !isContractDescriptor(value.item, seen)) return false;
2747
+ seen.delete(value);
2748
+ return true;
2749
+ };
2750
+ const isContractLanding = (value) => value === void 0 || value === "adopt" || value === "rebase";
2751
+ const isContractUnique = (value) => value === void 0 || value === true;
2752
+ const isContractProperty = (value) => isRecord(value) && isContractDescriptor(value.descriptor) && isStringArray(value.exclusiveGroupIds) && typeof value.id === "string" && (typeof value.key === "string" || isRecord(value.key) && value.key.kind === "prefix" && typeof value.key.prefix === "string") && isRecord(value.lifecycle) && (value.lifecycle.copy === "drop" || value.lifecycle.copy === "preserve") && (value.lifecycle.inclusive === null || typeof value.lifecycle.inclusive === "boolean") && isContractLanding(value.lifecycle.landing) && (value.lifecycle.split === "drop" || value.lifecycle.split === "preserve") && (value.lifecycle.typeChange === "drop" || value.lifecycle.typeChange === "preserve-if-allowed") && isContractUnique(value.lifecycle.unique) && (value.merge === "replace" || value.merge === "set") && typeof value.owner === "string" && (value.placement === "element" || value.placement === "text") && (value.references === void 0 || value.placement === "element" && isRecord(value.references) && Object.keys(value.references).length === 1 && typeof value.references.key === "string") && (value.role === "content" || value.role === "metadata") && (value.target === null || isContractTarget(value.target));
2753
+ const isContractLookup = (value) => isRecord(value) && isContractEntryArray(value.exact, isStringArray) && Array.isArray(value.prefixes) && value.prefixes.every((prefix) => isRecord(prefix) && typeof prefix.prefix === "string" && isStringArray(prefix.propertyIds));
2754
+ const isContractLifecycle = (value) => isRecord(value) && (value.copy === "drop" || value.copy === "preserve") && (value.inclusive === null || typeof value.inclusive === "boolean") && isContractLanding(value.landing) && (value.split === "drop" || value.split === "preserve") && (value.typeChange === "drop" || value.typeChange === "preserve-if-allowed") && isContractUnique(value.unique);
2755
+ const isContractVocabulary = (value) => isRecord(value) && [
2756
+ "elementTypes",
2757
+ "groupNames",
2758
+ "propertyIds",
2759
+ "rootNames"
2760
+ ].every((key) => isStringArray(value[key]));
2761
+ const isEditorSchemaContractShape = (value) => {
2762
+ const { elements } = value;
2763
+ const { properties } = value;
2764
+ return Array.isArray(value.diagnostics) && value.diagnostics.every((diagnostic) => isRecord(diagnostic) && typeof diagnostic.code === "string" && isStringArray(diagnostic.plugins) && typeof diagnostic.message === "string" && typeof diagnostic.path === "string") && isRecord(elements) && isContractEntryArray(elements.allowedChildren, isStringArray) && isContractEntryArray(elements.allowedParents, isStringArray) && Array.isArray(elements.byType) && elements.byType.every(isContractElement) && isContractEntryArray(elements.contentPrograms, isContractContentProgram) && isContractEntryArray(elements.defaultPlans, isContractConstructionPlan) && isContractEntryArray(elements.groups, isStringArray) && isStringArray(elements.textGroups) && isContractEntryArray(elements.wrapperPlans, isStringArray) && isRecord(properties) && Array.isArray(properties.byId) && properties.byId.every(isContractProperty) && isContractEntryArray(properties.conflictsByPropertyId, isStringArray) && isContractEntryArray(properties.elementAllowedByType, isStringArray) && isContractEntryArray(properties.lifecycle, isContractLifecycle) && isRecord(properties.lookup) && isContractLookup(properties.lookup.element) && isContractLookup(properties.lookup.text) && isContractEntryArray(properties.mergeStrategies, (item) => ["replace", "set"].includes(String(item))) && isContractEntryArray(properties.membersByExclusiveGroup, isStringArray) && isContractEntryArray(properties.textAllowedByParentType, isStringArray) && isContractRoot(value.primaryRoot) && Array.isArray(value.roots) && value.roots.every(isContractRoot) && (value.storageRevision === void 0 || value.storageRevision === 1 || value.storageRevision === 2) && isContractVocabulary(value.vocabulary);
2765
+ };
2766
+ const editorSchemaContractFingerprint = (contract) => {
2767
+ const content = canonicalContentProgram;
2768
+ const rootContent = canonicalContentProgram;
2769
+ const canonicalModel = {
2770
+ elements: [...contract.elements.byType].sort((left, right) => left.type.localeCompare(right.type)).map((element) => ({
2771
+ behavior: canonicalSchemaElementBehavior(element.behavior),
2772
+ content: element.content ? content(element.content) : null,
2773
+ contentRoots: [...element.contentRoots].sort(([left], [right]) => left.localeCompare(right)).map(([slot, root]) => ({
2774
+ content: content(root.content),
2775
+ ownership: root.ownership,
2776
+ slot
2777
+ })),
2778
+ construction: {
2779
+ materializedPropertyIds: sortedStrings(element.construction.materializedPropertyIds),
2780
+ propertyIds: sortedStrings(element.construction.propertyIds)
2781
+ },
2782
+ groups: sortedStrings(element.groups),
2783
+ slice: element.slice,
2784
+ ...element.structure ? { structure: element.structure } : {},
2785
+ type: element.type
2786
+ })),
2787
+ groups: [...contract.elements.groups].sort(([left], [right]) => left.localeCompare(right)).map(([group, members]) => ({
2788
+ group,
2789
+ members: sortedStrings(members)
2790
+ })),
2791
+ properties: [...contract.properties.byId].sort((left, right) => left.id.localeCompare(right.id)).map((property) => ({
2792
+ descriptor: canonicalDescriptor(property.descriptor),
2793
+ exclusiveGroupIds: sortedStrings(property.exclusiveGroupIds),
2794
+ id: property.id,
2795
+ key: typeof property.key === "string" ? { exact: property.key } : { prefix: property.key.prefix },
2796
+ lifecycle: property.lifecycle,
2797
+ merge: property.merge,
2798
+ placement: property.placement,
2799
+ ...property.references ? { references: { key: property.references.key } } : {},
2800
+ role: property.role,
2801
+ target: canonicalTarget(property.target)
2802
+ })),
2803
+ root: rootContent(contract.primaryRoot.content),
2804
+ roots: [...contract.roots].sort((left, right) => (left.name ?? "").localeCompare(right.name ?? "")).map((root) => ({
2805
+ ...rootContent(root.content),
2806
+ name: root.name
2807
+ })),
2808
+ ...contract.storageRevision === void 0 ? {} : { storageRevision: contract.storageRevision },
2809
+ unknown: contract.unknown
2810
+ };
2811
+ return `fnv1a64:${hashSchemaIdentityString(stableStringify(canonicalModel))}`;
2812
+ };
2813
+ /** Strictly recognize a generated schema contract before runtime use. */
2814
+ const readEditorSchemaContract = (value) => {
2815
+ if (!isRecord(value)) return void 0;
2816
+ if (value.formatVersion !== EDITOR_SCHEMA_CONTRACT_FORMAT) return void 0;
2817
+ if (typeof value.fingerprint !== "string" || value.fingerprint.length === 0) return;
2818
+ const identity = readEditorSchemaIdentity(value.identity);
2819
+ if (!identity || identity.fingerprint !== value.fingerprint) return void 0;
2820
+ if (!isRecord(value.elements) || !isRecord(value.properties)) return;
2821
+ if (!isRecord(value.primaryRoot) || !Array.isArray(value.roots)) return;
2822
+ if (!isRecord(value.vocabulary) || !Array.isArray(value.diagnostics)) return;
2823
+ if (!Number.isSafeInteger(value.revision) || value.revision < 0) return;
2824
+ if (value.unknown !== "preserve" && value.unknown !== "reject") return;
2825
+ if (!isEditorSchemaContractShape(value)) return void 0;
2826
+ const contract = value;
2827
+ return editorSchemaContractFingerprint(contract) === contract.fingerprint ? contract : void 0;
2828
+ };
2829
+ const contractContentIncludes = (previous, next) => {
2830
+ const nextTypes = new Set(next.allowedElementTypes);
2831
+ if (stableStringify(previous.prefix ?? null) !== stableStringify(next.prefix ?? null)) return false;
2832
+ if (previous.remainder && next.remainder) return contractContentIncludes(previous.remainder, next.remainder);
2833
+ if (previous.remainder || next.remainder) return false;
2834
+ return previous.allowedElementTypes.every((type) => nextTypes.has(type)) && (!previous.allowsText || next.allowsText) && (!previous.allowsUnknownElements || next.allowsUnknownElements) && next.min <= previous.min && (next.max === null || previous.max !== null && next.max >= previous.max);
2835
+ };
2836
+ const contractElementRenameSignature = (element) => {
2837
+ const { construction: _construction, propertyIds: _propertyIds, type: _type, ...shape } = element;
2838
+ return stableStringify(shape);
2839
+ };
2840
+ const contractPropertyKey = (key) => typeof key === "string" ? key : `${key.prefix}*`;
2841
+ const contractPropertyRenameSignature = (property) => {
2842
+ const { id: _id, key: _key, owner: _owner, ...shape } = property;
2843
+ return stableStringify(shape);
2844
+ };
2845
+ const contractPropertySemanticSignature = (property) => {
2846
+ const { key: _key, owner: _owner, ...shape } = property;
2847
+ return stableStringify(shape);
2848
+ };
2849
+ const contractPropertyRequired = (property) => property.descriptor.required;
2850
+ const contractPropertyRequiresMaterialization = (property) => contractPropertyRequired(property) || property.descriptor.generated === true || Object.hasOwn(property.descriptor, "default") && !property.descriptor.omitDefault;
2851
+ const pairContractRenames = (removed, added, signature) => {
2852
+ const removedByShape = /* @__PURE__ */ new Map();
2853
+ const addedByShape = /* @__PURE__ */ new Map();
2854
+ for (const value of removed) {
2855
+ const shape = signature(value);
2856
+ removedByShape.set(shape, [...removedByShape.get(shape) ?? [], value]);
2857
+ }
2858
+ for (const value of added) {
2859
+ const shape = signature(value);
2860
+ addedByShape.set(shape, [...addedByShape.get(shape) ?? [], value]);
2861
+ }
2862
+ const pairs = [];
2863
+ for (const [shape, previous] of removedByShape) {
2864
+ const next = addedByShape.get(shape);
2865
+ if (previous.length === 1 && next?.length === 1) pairs.push([previous[0], next[0]]);
2866
+ }
2867
+ return pairs;
2868
+ };
2869
+ const contractChange = (kind, path, impact, identity = {}) => Object.freeze({
2870
+ impact,
2871
+ kind,
2872
+ path,
2873
+ ...identity
2874
+ });
2875
+ /** Classify structural compatibility without inventing a semantic migration. */
2876
+ const diffEditorSchemaContracts = (previousInput, nextInput) => {
2877
+ const previous = readEditorSchemaContract(previousInput);
2878
+ const next = readEditorSchemaContract(nextInput);
2879
+ if (!previous || !next) throw new Error("Cannot diff an invalid generated editor schema contract.");
2880
+ const changes = [];
2881
+ const previousElements = new Map(previous.elements.byType.map((element) => [element.type, element]));
2882
+ const nextElements = new Map(next.elements.byType.map((element) => [element.type, element]));
2883
+ const removedElements = [...previousElements.values()].filter(({ type }) => !nextElements.has(type));
2884
+ const addedElements = [...nextElements.values()].filter(({ type }) => !previousElements.has(type));
2885
+ const elementRenames = pairContractRenames(removedElements, addedElements, contractElementRenameSignature);
2886
+ const renamedElementFrom = new Set(elementRenames.map(([value]) => value));
2887
+ const renamedElementTo = new Set(elementRenames.map(([, value]) => value));
2888
+ for (const [from, to] of elementRenames) changes.push(contractChange("element-renamed", `elements.${from.type}`, "migration-required", {
2889
+ from: from.type,
2890
+ to: to.type
2891
+ }));
2892
+ for (const element of removedElements) {
2893
+ if (renamedElementFrom.has(element)) continue;
2894
+ changes.push(contractChange("element-removed", `elements.${element.type}`, "migration-required", { from: element.type }));
2895
+ }
2896
+ for (const element of addedElements) {
2897
+ if (renamedElementTo.has(element)) continue;
2898
+ changes.push(contractChange("element-added", `elements.${element.type}`, "compatible", { to: element.type }));
2899
+ }
2900
+ for (const [type, before] of previousElements) {
2901
+ const after = nextElements.get(type);
2902
+ if (!after || stableStringify(before) === stableStringify(after)) continue;
2903
+ const { construction: _beforeConstruction, content: beforeContent, propertyIds: _beforePropertyIds, ...beforeRest } = before;
2904
+ const { construction: _afterConstruction, content: afterContent, propertyIds: _afterPropertyIds, ...afterRest } = after;
2905
+ if (stableStringify(beforeRest) !== stableStringify(afterRest)) changes.push(contractChange("element-changed", `elements.${type}`, "migration-required"));
2906
+ if (stableStringify(beforeContent) !== stableStringify(afterContent)) {
2907
+ const expanded = beforeContent !== null && afterContent !== null && contractContentIncludes(beforeContent, afterContent);
2908
+ changes.push(contractChange(expanded ? "element-content-expanded" : "element-content-restricted", `elements.${type}.content`, expanded ? "compatible" : "migration-required"));
2909
+ }
2910
+ }
2911
+ const previousProperties = new Map(previous.properties.byId.map((property) => [property.id, property]));
2912
+ const nextProperties = new Map(next.properties.byId.map((property) => [property.id, property]));
2913
+ const removedProperties = [...previousProperties.values()].filter((property) => !nextProperties.has(property.id));
2914
+ const addedProperties = [...nextProperties.values()].filter((property) => !previousProperties.has(property.id));
2915
+ const propertyRenames = pairContractRenames(removedProperties, addedProperties, contractPropertyRenameSignature);
2916
+ const renamedPropertyFrom = new Set(propertyRenames.map(([value]) => value));
2917
+ const renamedPropertyTo = new Set(propertyRenames.map(([, value]) => value));
2918
+ for (const [from, to] of propertyRenames) changes.push(contractChange("property-renamed", `properties.${from.id}`, "migration-required", {
2919
+ from: contractPropertyKey(from.key),
2920
+ to: contractPropertyKey(to.key)
2921
+ }));
2922
+ for (const property of removedProperties) {
2923
+ if (renamedPropertyFrom.has(property)) continue;
2924
+ changes.push(contractChange("property-removed", `properties.${property.id}`, "migration-required", { from: contractPropertyKey(property.key) }));
2925
+ }
2926
+ for (const property of addedProperties) {
2927
+ if (renamedPropertyTo.has(property)) continue;
2928
+ const required = contractPropertyRequired(property);
2929
+ const requiresMigration = contractPropertyRequiresMaterialization(property);
2930
+ changes.push(contractChange(required ? "property-required" : "property-added", `properties.${property.id}`, requiresMigration ? "migration-required" : "compatible", { to: contractPropertyKey(property.key) }));
2931
+ }
2932
+ for (const [id, before] of previousProperties) {
2933
+ const after = nextProperties.get(id);
2934
+ if (!after) continue;
2935
+ const beforeKey = contractPropertyKey(before.key);
2936
+ const afterKey = contractPropertyKey(after.key);
2937
+ if (beforeKey !== afterKey) changes.push(contractChange("property-renamed", `properties.${before.id}`, "migration-required", {
2938
+ from: beforeKey,
2939
+ to: afterKey
2940
+ }));
2941
+ if (contractPropertySemanticSignature(before) === contractPropertySemanticSignature(after)) continue;
2942
+ const becameRequired = !contractPropertyRequired(before) && contractPropertyRequired(after);
2943
+ const leavesDefaultOut = !before.descriptor.omitDefault && contractPropertySemanticSignature({
2944
+ ...before,
2945
+ descriptor: {
2946
+ ...before.descriptor,
2947
+ omitDefault: true
2948
+ }
2949
+ }) === contractPropertySemanticSignature(after);
2950
+ changes.push(contractChange(becameRequired ? "property-required" : "property-changed", `properties.${before.id}`, leavesDefaultOut ? "compatible" : "migration-required"));
2951
+ }
2952
+ const compareRoot = (path, before, after) => {
2953
+ if (!before && after) changes.push(contractChange("root-added", path, "compatible"));
2954
+ else if (before && !after) changes.push(contractChange("root-removed", path, "migration-required"));
2955
+ else if (before && after && stableStringify(before) !== stableStringify(after)) {
2956
+ if (before.name !== after.name) changes.push(contractChange("root-changed", path, "migration-required"));
2957
+ if (stableStringify(before.content) !== stableStringify(after.content)) {
2958
+ const expanded = contractContentIncludes(before.content, after.content);
2959
+ changes.push(contractChange(expanded ? "root-content-expanded" : "root-content-restricted", `${path}.content`, expanded ? "compatible" : "migration-required"));
2960
+ }
2961
+ }
2962
+ };
2963
+ compareRoot("roots.main", previous.primaryRoot, next.primaryRoot);
2964
+ const previousRoots = new Map(previous.roots.map((root) => [root.name ?? "main", root]));
2965
+ const nextRoots = new Map(next.roots.map((root) => [root.name ?? "main", root]));
2966
+ for (const name of /* @__PURE__ */ new Set([...previousRoots.keys(), ...nextRoots.keys()])) {
2967
+ if (name === "main") continue;
2968
+ compareRoot(`roots.${name}`, previousRoots.get(name), nextRoots.get(name));
2969
+ }
2970
+ if (previous.storageRevision !== next.storageRevision) {
2971
+ const leftNothingOut = previous.storageRevision === void 0 && next.storageRevision === 1 && !previous.properties.byId.some(({ descriptor }) => descriptor.omitDefault);
2972
+ changes.push(contractChange("storage-revision-changed", "storageRevision", leftNothingOut ? "compatible" : "migration-required", {
2973
+ from: String(previous.storageRevision ?? 0),
2974
+ to: String(next.storageRevision ?? 0)
2975
+ }));
2976
+ }
2977
+ if (previous.unknown !== next.unknown) {
2978
+ const expanded = previous.unknown === "reject" && next.unknown === "preserve";
2979
+ changes.push(contractChange(expanded ? "unknown-policy-expanded" : "unknown-policy-restricted", "unknown", expanded ? "compatible" : "migration-required", {
2980
+ from: previous.unknown,
2981
+ to: next.unknown
2982
+ }));
2983
+ }
2984
+ const sorted = Object.freeze(changes.sort((left, right) => left.path.localeCompare(right.path) || left.kind.localeCompare(right.kind)));
2985
+ return Object.freeze({
2986
+ changes: sorted,
2987
+ fromFingerprint: previous.fingerprint,
2988
+ requiresMigration: sorted.some(({ impact }) => impact === "migration-required"),
2989
+ toFingerprint: next.fingerprint
2990
+ });
2991
+ };
2992
+ const restoreContentProgram = (program) => {
2993
+ const { remainder, ...rest } = program;
2994
+ return Object.freeze({
2995
+ ...rest,
2996
+ allowedElementTypes: freezeSet(program.allowedElementTypes),
2997
+ ...remainder ? { remainder: restoreContentProgram(remainder) } : {}
2998
+ });
2999
+ };
3000
+ const restoreContentRoot = (root) => Object.freeze({
3001
+ content: restoreContentProgram(root.content),
3002
+ ownership: root.ownership,
3003
+ structure: root.structure ? Object.freeze({ kind: root.structure.kind }) : null
3004
+ });
3005
+ const restoreRoot = (root) => Object.freeze({
3006
+ content: restoreContentProgram(root.content),
3007
+ name: root.name
3008
+ });
3009
+ const restoreEntries = (entries, map) => freezeMap(new Map(entries.map(([key, value]) => [key, map(value)])));
3010
+ const restoreStringSets = (entries) => restoreEntries(entries, freezeSet);
3011
+ const restoreElement = (element, compiledBehavior) => Object.freeze({
3012
+ ...element,
3013
+ behavior: compiledBehavior,
3014
+ content: element.content ? restoreContentProgram(element.content) : null,
3015
+ contentRoots: restoreEntries(element.contentRoots, restoreContentRoot),
3016
+ construction: Object.freeze({
3017
+ materializedPropertyIds: freezeSet(element.construction.materializedPropertyIds),
3018
+ propertyIds: freezeSet(element.construction.propertyIds)
3019
+ }),
3020
+ groups: freezeSet(element.groups),
3021
+ propertyIds: freezeSet(element.propertyIds),
3022
+ slice: Object.freeze({
3023
+ ...element.slice,
3024
+ endMatter: element.slice.endMatter ?? false
3025
+ }),
3026
+ structure: element.structure ?? null
3027
+ });
3028
+ /** Restore a generated structural contract and bind current live validators. */
3029
+ const restoreEditorSchemaContract = (input, records, revision) => {
3030
+ const contract = readEditorSchemaContract(input);
3031
+ if (!contract) throw new Error("Invalid generated editor schema contract.");
3032
+ const compiled = compileEditorSchemaContributions(records, { revision: contract.revision });
3033
+ const expected = createEditorSchemaContract(compiled);
3034
+ if (stableStringify(expected) !== stableStringify(contract)) throw new Error("Generated editor schema contract does not match its source contributions.");
3035
+ const byType = freezeMap(new Map(contract.elements.byType.map((element) => [element.type, restoreElement(element, compiled.elements.byType.get(element.type)?.behavior ?? failInvariant(`Missing compiled element "${element.type}"`))])));
3036
+ const byId = freezeMap(new Map(contract.properties.byId.map((property) => [property.id, property])));
3037
+ const structural = Object.freeze({
3038
+ diagnostics: contract.diagnostics,
3039
+ elements: Object.freeze({
3040
+ allowedChildren: restoreStringSets(contract.elements.allowedChildren),
3041
+ allowedParents: restoreStringSets(contract.elements.allowedParents),
3042
+ byType,
3043
+ contentPrograms: restoreEntries(contract.elements.contentPrograms, restoreContentProgram),
3044
+ defaultPlans: restoreEntries(contract.elements.defaultPlans, (value) => value),
3045
+ groups: restoreStringSets(contract.elements.groups),
3046
+ textGroups: freezeSet(contract.elements.textGroups),
3047
+ wrapperPlans: restoreEntries(contract.elements.wrapperPlans, (value) => Object.freeze([...value]))
3048
+ }),
3049
+ identity: contract.identity,
3050
+ primaryRoot: restoreRoot(contract.primaryRoot),
3051
+ properties: Object.freeze({
3052
+ byId,
3053
+ conflictsByPropertyId: restoreStringSets(contract.properties.conflictsByPropertyId),
3054
+ elementAllowedByType: restoreStringSets(contract.properties.elementAllowedByType),
3055
+ lifecycle: restoreEntries(contract.properties.lifecycle, (value) => value),
3056
+ lookup: Object.freeze({
3057
+ element: Object.freeze({
3058
+ exact: restoreEntries(contract.properties.lookup.element.exact, (value) => Object.freeze([...value])),
3059
+ prefixes: contract.properties.lookup.element.prefixes
3060
+ }),
3061
+ text: Object.freeze({
3062
+ exact: restoreEntries(contract.properties.lookup.text.exact, (value) => Object.freeze([...value])),
3063
+ prefixes: contract.properties.lookup.text.prefixes
3064
+ })
3065
+ }),
3066
+ mergeStrategies: restoreEntries(contract.properties.mergeStrategies, (value) => value),
3067
+ membersByExclusiveGroup: restoreStringSets(contract.properties.membersByExclusiveGroup),
3068
+ textAllowedByParentType: restoreStringSets(contract.properties.textAllowedByParentType)
3069
+ }),
3070
+ recordSets: compiled.recordSets,
3071
+ revision: contract.revision,
3072
+ roots: freezeMap(new Map(contract.roots.map((root) => [getDefined(root.name), restoreRoot(root)]))),
3073
+ unknown: contract.unknown,
3074
+ vocabulary: contract.vocabulary
3075
+ });
3076
+ return rebindCompiledEditorSchemaRuntimeValidations(structural, records, revision ?? contract.revision);
3077
+ };
3078
+ const canonicalCompiledContent = (content) => content ? canonicalContentProgram(content) : null;
3079
+ const canonicalCompiledElement = (element) => element ? {
3080
+ behavior: element.behavior,
3081
+ content: canonicalCompiledContent(element.content),
3082
+ contentRoots: [...element.contentRoots].map(([slot, root]) => ({
3083
+ content: canonicalCompiledContent(root.content),
3084
+ ownership: root.ownership,
3085
+ slot
3086
+ })),
3087
+ groups: sortedStrings(element.groups),
3088
+ propertyIds: sortedStrings(element.propertyIds),
3089
+ slice: element.slice,
3090
+ ...element.structure ? { structure: element.structure } : {}
3091
+ } : null;
3092
+ const canonicalCompiledConstruction = (element) => element ? {
3093
+ content: canonicalCompiledContent(element.content),
3094
+ contentRoots: [...element.contentRoots].map(([slot, root]) => ({
3095
+ content: canonicalCompiledContent(root.content),
3096
+ ownership: root.ownership,
3097
+ slot
3098
+ })),
3099
+ materializedPropertyIds: sortedStrings(element.construction.materializedPropertyIds),
3100
+ propertyIds: sortedStrings(element.construction.propertyIds)
3101
+ } : null;
3102
+ const canonicalCompiledProperty = (property) => property ? {
3103
+ descriptor: canonicalDescriptor(property.descriptor),
3104
+ key: property.key,
3105
+ lifecycle: property.lifecycle,
3106
+ merge: property.merge,
3107
+ placement: property.placement,
3108
+ ...property.references ? { references: { key: property.references.key } } : {},
3109
+ role: property.role,
3110
+ target: canonicalTarget(property.target)
3111
+ } : null;
3112
+ const canonicalCompiledPropertyConstruction = (property) => property && property.placement === "element" && Object.hasOwn(property.descriptor, "default") ? {
3113
+ default: canonicalJson(property.descriptor.default),
3114
+ omitDefault: property.descriptor.omitDefault,
3115
+ required: property.descriptor.required
3116
+ } : null;
3117
+ const getPropertyAffectedElementTypes = (schema, propertyIds, placement) => {
3118
+ if (!schema || propertyIds.length === 0) return [];
3119
+ const affected = /* @__PURE__ */ new Set();
3120
+ for (const propertyId of propertyIds) {
3121
+ const property = schema.properties.byId.get(propertyId);
3122
+ if (!property || placement && property.placement !== placement) continue;
3123
+ const allowedByType = property.placement === "element" ? schema.properties.elementAllowedByType : schema.properties.textAllowedByParentType;
3124
+ for (const [type, allowedPropertyIds] of allowedByType) if (allowedPropertyIds.has(propertyId)) affected.add(type);
3125
+ }
3126
+ return [...affected];
3127
+ };
3128
+ const canonicalCompiledRoot = (root) => root ? canonicalCompiledContent(root.content) : null;
3129
+ const changedKeys = (keys, changed) => [...new Set(keys)].filter(changed);
3130
+ /** Compare two compiled publications without treating live validators as data. */
3131
+ const createCompiledEditorSchemaDelta = (previous, next) => {
3132
+ if (previous === next) return null;
3133
+ const elementTypes = sortedStrings([...previous?.elements.byType.keys() ?? [], ...next?.elements.byType.keys() ?? []]);
3134
+ const propertyIds = sortedStrings([...previous?.properties.byId.keys() ?? [], ...next?.properties.byId.keys() ?? []]);
3135
+ const rootNames = sortedStrings([...previous?.roots.keys() ?? [], ...next?.roots.keys() ?? []]);
3136
+ const unknownPolicyChanged = previous?.unknown !== next?.unknown;
3137
+ const changedPropertyIds = unknownPolicyChanged ? propertyIds : changedKeys(propertyIds, (id) => stableStringify(canonicalCompiledProperty(previous?.properties.byId.get(id) ?? null)) !== stableStringify(canonicalCompiledProperty(next?.properties.byId.get(id) ?? null)));
3138
+ const directChangedElementTypes = unknownPolicyChanged ? elementTypes : changedKeys(elementTypes, (type) => !Object.is(stableStringify(canonicalCompiledElement(previous?.elements.byType.get(type) ?? null)), stableStringify(canonicalCompiledElement(next?.elements.byType.get(type) ?? null))));
3139
+ const changedElementTypes = sortedStrings([
3140
+ ...directChangedElementTypes,
3141
+ ...getPropertyAffectedElementTypes(previous, changedPropertyIds),
3142
+ ...getPropertyAffectedElementTypes(next, changedPropertyIds)
3143
+ ]);
3144
+ const constructionPropertyIds = changedPropertyIds.filter((id) => stableStringify(canonicalCompiledPropertyConstruction(previous?.properties.byId.get(id) ?? null)) !== stableStringify(canonicalCompiledPropertyConstruction(next?.properties.byId.get(id) ?? null)));
3145
+ const directChangedConstructionTypes = unknownPolicyChanged ? elementTypes : changedKeys(elementTypes, (type) => stableStringify(canonicalCompiledConstruction(previous?.elements.byType.get(type) ?? null)) !== stableStringify(canonicalCompiledConstruction(next?.elements.byType.get(type) ?? null)));
3146
+ const changedConstructionTypes = sortedStrings([
3147
+ ...directChangedConstructionTypes,
3148
+ ...getPropertyAffectedElementTypes(previous, constructionPropertyIds, "element"),
3149
+ ...getPropertyAffectedElementTypes(next, constructionPropertyIds, "element")
3150
+ ]);
3151
+ const roots = [null, ...rootNames];
3152
+ const changedRoots = unknownPolicyChanged ? roots : changedKeys(roots, (name) => {
3153
+ const previousRoot = name ? previous?.roots.get(name) ?? null : previous?.primaryRoot ?? null;
3154
+ const nextRoot = name ? next?.roots.get(name) ?? null : next?.primaryRoot ?? null;
3155
+ return stableStringify(canonicalCompiledRoot(previousRoot)) !== stableStringify(canonicalCompiledRoot(nextRoot));
3156
+ });
3157
+ if (changedElementTypes.length === 0 && changedConstructionTypes.length === 0 && changedPropertyIds.length === 0 && changedRoots.length === 0) return null;
3158
+ return Object.freeze({
3159
+ constructionTypes: Object.freeze(changedConstructionTypes),
3160
+ elementTypes: Object.freeze(changedElementTypes),
3161
+ propertyIds: Object.freeze(changedPropertyIds),
3162
+ roots: Object.freeze(changedRoots)
3163
+ });
3164
+ };
3165
+ //#endregion
3166
+ export { EditorSchemaCompileError, areEditorSchemaIdentitiesEqual, canonicalJson, compileEditorSchemaContributions, createCompiledEditorSchemaDelta, createEditorSchemaContract, crossesUniqueTarget, defaultSplitOf, diffEditorSchemaContracts, getCompiledPropertyCandidates, getCompiledPropertyMergeStrategy, getCompiledSchemaPropertyId, getEditorSchemaDeclarationKey, handoverKeysOf, hasPlaceDependentElementProperty, hashSchemaIdentityString, holdsUniqueKey, isPlaceDependentElementProperty, isSupportedGeneratedElementProperty, matchesCompiledSchemaTarget, preserveCompiledSchemaPropertyIdentity, propertyTargetsReadParents, readEditorSchemaContract, readEditorSchemaIdentity, rebindCompiledEditorSchemaRuntimeValidations, resolveCompiledSchemaProperty, resolveCompiledSchemaWrapperPlan, restoreEditorSchemaContract, splitDroppedKeysOf, stripCompiledEditorSchemaRuntimeValidations, toCompiledNodeContext, toCompiledTargetContext, tracksPlaces, uniquePropertiesOf, uniqueRefusalOf, unwrittenAs };