@johnoscott/isometric-engine 0.0.0-stage → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (310) hide show
  1. package/EDITOR-GUIDE.md +317 -0
  2. package/LICENSE +21 -0
  3. package/LICENSES/ajv.txt +22 -0
  4. package/LICENSES/lucide-static.txt +43 -0
  5. package/LICENSES/yaml.txt +13 -0
  6. package/README.md +62 -2
  7. package/assets/app.css +265 -0
  8. package/assets/default-theme.yaml +99 -0
  9. package/assets/icons.svg +1 -0
  10. package/assets/marks.css +35 -0
  11. package/assets/skin.css +181 -0
  12. package/iso-editor.d.ts +4 -0
  13. package/iso-editor.js +550 -0
  14. package/iso-render.d.ts +3 -0
  15. package/iso-render.js +388 -0
  16. package/iso-systems.d.ts +4 -0
  17. package/iso-systems.js +389 -0
  18. package/js/iso-core/compile-schema.js +22 -0
  19. package/js/iso-core/depth.js +55 -0
  20. package/js/iso-core/errors.js +65 -0
  21. package/js/iso-core/glyphs.js +100 -0
  22. package/js/iso-core/index.js +55 -0
  23. package/js/iso-core/kernel.js +158 -0
  24. package/js/iso-core/metrics.json +1 -0
  25. package/js/iso-core/package.json +6 -0
  26. package/js/iso-core/parse.js +79 -0
  27. package/js/iso-core/schema-errors.js +170 -0
  28. package/js/iso-core/shims/crypto.js +125 -0
  29. package/js/iso-core/shims/path.js +49 -0
  30. package/js/iso-core/svg-dom.js +144 -0
  31. package/js/iso-core/theme.js +48 -0
  32. package/js/iso-core/vdom.js +48 -0
  33. package/js/iso-editor/adapter.js +0 -0
  34. package/js/iso-editor/clipboard.js +152 -0
  35. package/js/iso-editor/commands.js +173 -0
  36. package/js/iso-editor/complete.js +55 -0
  37. package/js/iso-editor/doc.js +182 -0
  38. package/js/iso-editor/index.js +105 -0
  39. package/js/iso-editor/model.js +210 -0
  40. package/js/iso-editor/outline.js +111 -0
  41. package/js/iso-editor/package.json +6 -0
  42. package/js/iso-editor/path.js +19 -0
  43. package/js/iso-editor/providers.js +96 -0
  44. package/js/iso-editor/schema-nav.js +117 -0
  45. package/js/iso-editor/splice.js +441 -0
  46. package/js/iso-editor/storage-keys.js +6 -0
  47. package/js/iso-editor/ui/actions.js +116 -0
  48. package/js/iso-editor/ui/canvas-layer.js +0 -0
  49. package/js/iso-editor/ui/canvas.js +1205 -0
  50. package/js/iso-editor/ui/clip.js +133 -0
  51. package/js/iso-editor/ui/dialog.js +26 -0
  52. package/js/iso-editor/ui/flat-canvas.js +54 -0
  53. package/js/iso-editor/ui/icons.js +15 -0
  54. package/js/iso-editor/ui/keys.js +26 -0
  55. package/js/iso-editor/ui/later.js +28 -0
  56. package/js/iso-editor/ui/layer.js +11 -0
  57. package/js/iso-editor/ui/menu.js +105 -0
  58. package/js/iso-editor/ui/monaco-entry.js +2 -0
  59. package/js/iso-editor/ui/mount-kit.js +0 -0
  60. package/js/iso-editor/ui/mount.js +767 -0
  61. package/js/iso-editor/ui/pane.js +0 -0
  62. package/js/iso-editor/ui/part.js +0 -0
  63. package/js/iso-editor/ui/plain-icons.js +34 -0
  64. package/js/iso-editor/ui/props.js +314 -0
  65. package/js/iso-editor/ui/scope-css.js +81 -0
  66. package/js/iso-editor/ui/setup.js +145 -0
  67. package/js/iso-editor/ui/text.js +323 -0
  68. package/js/iso-editor/ui/tree.js +728 -0
  69. package/js/iso-editor/validate.js +33 -0
  70. package/js/iso-editor/window/protocol.js +8 -0
  71. package/js/iso-objects/assemble.js +43 -0
  72. package/js/iso-objects/assets.js +88 -0
  73. package/js/iso-objects/board.js +162 -0
  74. package/js/iso-objects/compile.js +60 -0
  75. package/js/iso-objects/css.js +154 -0
  76. package/js/iso-objects/flat.js +696 -0
  77. package/js/iso-objects/focus.js +16 -0
  78. package/js/iso-objects/geometry.js +76 -0
  79. package/js/iso-objects/index.js +93 -0
  80. package/js/iso-objects/kinds.js +12 -0
  81. package/js/iso-objects/labels.js +325 -0
  82. package/js/iso-objects/package.json +6 -0
  83. package/js/iso-objects/place.js +347 -0
  84. package/js/iso-objects/route.js +461 -0
  85. package/js/iso-objects/scene.js +350 -0
  86. package/js/iso-objects/steps.js +246 -0
  87. package/js/iso-objects/types.js +0 -0
  88. package/js/iso-systems/catalog.js +42 -0
  89. package/js/iso-systems/compile.js +34 -0
  90. package/js/iso-systems/css.js +8 -0
  91. package/js/iso-systems/index.js +16 -0
  92. package/js/iso-systems/nodes.js +124 -0
  93. package/js/iso-systems/package.json +6 -0
  94. package/js/iso-systems/schema.json +311 -0
  95. package/js/iso-systems/validate.js +35 -0
  96. package/js/iso-viewer/bundle.js +20 -0
  97. package/js/iso-viewer/card-motion.js +228 -0
  98. package/js/iso-viewer/dom.js +14 -0
  99. package/js/iso-viewer/dual-view.js +212 -0
  100. package/js/iso-viewer/flat-view.js +124 -0
  101. package/js/iso-viewer/history.js +990 -0
  102. package/js/iso-viewer/index.js +98 -0
  103. package/js/iso-viewer/morph.js +192 -0
  104. package/js/iso-viewer/overlay.js +199 -0
  105. package/js/iso-viewer/package.json +6 -0
  106. package/js/iso-viewer/page.js +138 -0
  107. package/js/iso-viewer/player.js +409 -0
  108. package/js/iso-viewer/still.js +81 -0
  109. package/js/iso-viewer/timeline-contract.js +14 -0
  110. package/js/iso-viewer/timeline-engine.js +475 -0
  111. package/js/iso-viewer/timeline-export.js +36 -0
  112. package/js/iso-viewer/timeline-scale.js +116 -0
  113. package/js/iso-viewer/timeline-scope.js +58 -0
  114. package/js/iso-viewer/timeline-search.js +216 -0
  115. package/js/iso-viewer/timeline-time.js +55 -0
  116. package/js/iso-viewer/view-css.js +68 -0
  117. package/js/iso-viewer/viewport.js +177 -0
  118. package/package.json +502 -4
  119. package/src/iso-core/compile-schema.ts +23 -0
  120. package/src/iso-core/depth.ts +56 -0
  121. package/src/iso-core/errors.ts +73 -0
  122. package/src/iso-core/glyphs.ts +108 -0
  123. package/src/iso-core/index.ts +27 -0
  124. package/src/iso-core/kernel.ts +163 -0
  125. package/src/iso-core/metrics.json +1 -0
  126. package/src/iso-core/package.json +6 -0
  127. package/src/iso-core/parse.ts +91 -0
  128. package/src/iso-core/schema-errors.ts +163 -0
  129. package/src/iso-core/shims/crypto.ts +37 -0
  130. package/src/iso-core/shims/path.ts +24 -0
  131. package/src/iso-core/svg-dom.ts +103 -0
  132. package/src/iso-core/theme.ts +64 -0
  133. package/src/iso-core/vdom.ts +41 -0
  134. package/src/iso-editor/adapter.ts +128 -0
  135. package/src/iso-editor/clipboard.ts +163 -0
  136. package/src/iso-editor/commands.ts +191 -0
  137. package/src/iso-editor/complete.ts +73 -0
  138. package/src/iso-editor/doc.ts +207 -0
  139. package/src/iso-editor/index.ts +67 -0
  140. package/src/iso-editor/model.ts +234 -0
  141. package/src/iso-editor/outline.ts +126 -0
  142. package/src/iso-editor/package.json +6 -0
  143. package/src/iso-editor/path.ts +18 -0
  144. package/src/iso-editor/providers.ts +113 -0
  145. package/src/iso-editor/schema-nav.ts +129 -0
  146. package/src/iso-editor/splice.ts +472 -0
  147. package/src/iso-editor/storage-keys.ts +6 -0
  148. package/src/iso-editor/ui/actions.ts +119 -0
  149. package/src/iso-editor/ui/app.css +230 -0
  150. package/src/iso-editor/ui/canvas-layer.ts +56 -0
  151. package/src/iso-editor/ui/canvas.ts +1071 -0
  152. package/src/iso-editor/ui/clip.ts +97 -0
  153. package/src/iso-editor/ui/dialog.ts +25 -0
  154. package/src/iso-editor/ui/flat-canvas.ts +51 -0
  155. package/src/iso-editor/ui/icons.ts +21 -0
  156. package/src/iso-editor/ui/keys.ts +30 -0
  157. package/src/iso-editor/ui/later.ts +22 -0
  158. package/src/iso-editor/ui/layer.ts +7 -0
  159. package/src/iso-editor/ui/marks.css +35 -0
  160. package/src/iso-editor/ui/menu.ts +67 -0
  161. package/src/iso-editor/ui/monaco-entry.ts +6 -0
  162. package/src/iso-editor/ui/mount-kit.ts +35 -0
  163. package/src/iso-editor/ui/mount.ts +684 -0
  164. package/src/iso-editor/ui/pane.ts +45 -0
  165. package/src/iso-editor/ui/part.ts +45 -0
  166. package/src/iso-editor/ui/plain-icons.ts +83 -0
  167. package/src/iso-editor/ui/props.ts +347 -0
  168. package/src/iso-editor/ui/scope-css.ts +65 -0
  169. package/src/iso-editor/ui/setup.ts +144 -0
  170. package/src/iso-editor/ui/skin.css +181 -0
  171. package/src/iso-editor/ui/text.ts +262 -0
  172. package/src/iso-editor/ui/tree.ts +657 -0
  173. package/src/iso-editor/validate.ts +62 -0
  174. package/src/iso-editor/window/protocol.ts +33 -0
  175. package/src/iso-objects/assemble.ts +57 -0
  176. package/src/iso-objects/assets.ts +122 -0
  177. package/src/iso-objects/board.ts +169 -0
  178. package/src/iso-objects/compile.ts +76 -0
  179. package/src/iso-objects/css.ts +163 -0
  180. package/src/iso-objects/flat.ts +653 -0
  181. package/src/iso-objects/focus.ts +14 -0
  182. package/src/iso-objects/geometry.ts +86 -0
  183. package/src/iso-objects/index.ts +33 -0
  184. package/src/iso-objects/kinds.ts +56 -0
  185. package/src/iso-objects/labels.ts +310 -0
  186. package/src/iso-objects/package.json +6 -0
  187. package/src/iso-objects/place.ts +318 -0
  188. package/src/iso-objects/route.ts +444 -0
  189. package/src/iso-objects/scene.ts +376 -0
  190. package/src/iso-objects/steps.ts +234 -0
  191. package/src/iso-objects/types.ts +68 -0
  192. package/src/iso-systems/catalog.ts +31 -0
  193. package/src/iso-systems/compile.ts +39 -0
  194. package/src/iso-systems/css.ts +9 -0
  195. package/src/iso-systems/index.ts +12 -0
  196. package/src/iso-systems/nodes.ts +126 -0
  197. package/src/iso-systems/package.json +6 -0
  198. package/src/iso-systems/schema.json +311 -0
  199. package/src/iso-systems/validate.ts +34 -0
  200. package/src/iso-viewer/bundle.ts +15 -0
  201. package/src/iso-viewer/card-motion.ts +237 -0
  202. package/src/iso-viewer/dom.ts +13 -0
  203. package/src/iso-viewer/dual-view.ts +212 -0
  204. package/src/iso-viewer/flat-view.ts +127 -0
  205. package/src/iso-viewer/history.ts +781 -0
  206. package/src/iso-viewer/index.ts +40 -0
  207. package/src/iso-viewer/morph.ts +191 -0
  208. package/src/iso-viewer/overlay.ts +212 -0
  209. package/src/iso-viewer/package.json +6 -0
  210. package/src/iso-viewer/page.ts +150 -0
  211. package/src/iso-viewer/player.ts +321 -0
  212. package/src/iso-viewer/still.ts +74 -0
  213. package/src/iso-viewer/timeline-contract.ts +342 -0
  214. package/src/iso-viewer/timeline-engine.ts +420 -0
  215. package/src/iso-viewer/timeline-export.ts +31 -0
  216. package/src/iso-viewer/timeline-scale.ts +129 -0
  217. package/src/iso-viewer/timeline-scope.ts +56 -0
  218. package/src/iso-viewer/timeline-search.ts +198 -0
  219. package/src/iso-viewer/timeline-time.ts +54 -0
  220. package/src/iso-viewer/view-css.ts +59 -0
  221. package/src/iso-viewer/viewport.ts +142 -0
  222. package/types/iso-core/compile-schema.d.ts +11 -0
  223. package/types/iso-core/depth.d.ts +6 -0
  224. package/types/iso-core/errors.d.ts +24 -0
  225. package/types/iso-core/glyphs.d.ts +19 -0
  226. package/types/iso-core/index.d.ts +17 -0
  227. package/types/iso-core/kernel.d.ts +130 -0
  228. package/types/iso-core/metrics.json +1 -0
  229. package/types/iso-core/parse.d.ts +18 -0
  230. package/types/iso-core/schema-errors.d.ts +14 -0
  231. package/types/iso-core/shims/crypto.d.ts +9 -0
  232. package/types/iso-core/svg-dom.d.ts +15 -0
  233. package/types/iso-core/theme.d.ts +38 -0
  234. package/types/iso-core/vdom.d.ts +26 -0
  235. package/types/iso-editor/adapter.d.ts +145 -0
  236. package/types/iso-editor/clipboard.d.ts +23 -0
  237. package/types/iso-editor/commands.d.ts +32 -0
  238. package/types/iso-editor/complete.d.ts +25 -0
  239. package/types/iso-editor/doc.d.ts +50 -0
  240. package/types/iso-editor/index.d.ts +57 -0
  241. package/types/iso-editor/model.d.ts +96 -0
  242. package/types/iso-editor/outline.d.ts +28 -0
  243. package/types/iso-editor/path.d.ts +7 -0
  244. package/types/iso-editor/providers.d.ts +43 -0
  245. package/types/iso-editor/schema-nav.d.ts +34 -0
  246. package/types/iso-editor/splice.d.ts +53 -0
  247. package/types/iso-editor/storage-keys.d.ts +5 -0
  248. package/types/iso-editor/ui/actions.d.ts +23 -0
  249. package/types/iso-editor/ui/canvas-layer.d.ts +65 -0
  250. package/types/iso-editor/ui/canvas.d.ts +279 -0
  251. package/types/iso-editor/ui/clip.d.ts +14 -0
  252. package/types/iso-editor/ui/dialog.d.ts +7 -0
  253. package/types/iso-editor/ui/flat-canvas.d.ts +2 -0
  254. package/types/iso-editor/ui/icons.d.ts +5 -0
  255. package/types/iso-editor/ui/keys.d.ts +7 -0
  256. package/types/iso-editor/ui/later.d.ts +12 -0
  257. package/types/iso-editor/ui/layer.d.ts +2 -0
  258. package/types/iso-editor/ui/menu.d.ts +21 -0
  259. package/types/iso-editor/ui/mount-kit.d.ts +31 -0
  260. package/types/iso-editor/ui/mount.d.ts +146 -0
  261. package/types/iso-editor/ui/pane.d.ts +60 -0
  262. package/types/iso-editor/ui/part.d.ts +40 -0
  263. package/types/iso-editor/ui/plain-icons.d.ts +10 -0
  264. package/types/iso-editor/ui/props.d.ts +57 -0
  265. package/types/iso-editor/ui/scope-css.d.ts +5 -0
  266. package/types/iso-editor/ui/setup.d.ts +40 -0
  267. package/types/iso-editor/ui/text.d.ts +19 -0
  268. package/types/iso-editor/ui/tree.d.ts +100 -0
  269. package/types/iso-editor/validate.d.ts +36 -0
  270. package/types/iso-editor/window/protocol.d.ts +60 -0
  271. package/types/iso-objects/assemble.d.ts +35 -0
  272. package/types/iso-objects/assets.d.ts +49 -0
  273. package/types/iso-objects/board.d.ts +36 -0
  274. package/types/iso-objects/compile.d.ts +35 -0
  275. package/types/iso-objects/css.d.ts +16 -0
  276. package/types/iso-objects/flat.d.ts +130 -0
  277. package/types/iso-objects/focus.d.ts +1 -0
  278. package/types/iso-objects/geometry.d.ts +59 -0
  279. package/types/iso-objects/index.d.ts +26 -0
  280. package/types/iso-objects/kinds.d.ts +53 -0
  281. package/types/iso-objects/labels.d.ts +92 -0
  282. package/types/iso-objects/place.d.ts +25 -0
  283. package/types/iso-objects/route.d.ts +67 -0
  284. package/types/iso-objects/scene.d.ts +63 -0
  285. package/types/iso-objects/steps.d.ts +90 -0
  286. package/types/iso-objects/types.d.ts +140 -0
  287. package/types/iso-systems/catalog.d.ts +4 -0
  288. package/types/iso-systems/compile.d.ts +6 -0
  289. package/types/iso-systems/css.d.ts +3 -0
  290. package/types/iso-systems/index.d.ts +5 -0
  291. package/types/iso-systems/nodes.d.ts +3 -0
  292. package/types/iso-viewer/card-motion.d.ts +56 -0
  293. package/types/iso-viewer/dom.d.ts +1 -0
  294. package/types/iso-viewer/dual-view.d.ts +44 -0
  295. package/types/iso-viewer/flat-view.d.ts +25 -0
  296. package/types/iso-viewer/history.d.ts +91 -0
  297. package/types/iso-viewer/index.d.ts +31 -0
  298. package/types/iso-viewer/morph.d.ts +28 -0
  299. package/types/iso-viewer/overlay.d.ts +135 -0
  300. package/types/iso-viewer/page.d.ts +13 -0
  301. package/types/iso-viewer/still.d.ts +26 -0
  302. package/types/iso-viewer/timeline-contract.d.ts +345 -0
  303. package/types/iso-viewer/timeline-engine.d.ts +20 -0
  304. package/types/iso-viewer/timeline-export.d.ts +5 -0
  305. package/types/iso-viewer/timeline-scale.d.ts +44 -0
  306. package/types/iso-viewer/timeline-scope.d.ts +33 -0
  307. package/types/iso-viewer/timeline-search.d.ts +52 -0
  308. package/types/iso-viewer/timeline-time.d.ts +8 -0
  309. package/types/iso-viewer/view-css.d.ts +7 -0
  310. package/types/iso-viewer/viewport.d.ts +50 -0
@@ -0,0 +1,323 @@
1
+ import * as monacoMain from "monaco-editor/editor/editor.main.js";
2
+ import "monaco-editor/languages/definitions/yaml/register.js";
3
+ const monaco = monacoMain;
4
+ const THREAD_URL = typeof __SE_EDITOR_THREAD__ === "string" ? __SE_EDITOR_THREAD__ : "editor.worker.js";
5
+ const threads = /* @__PURE__ */ new Set();
6
+ self.MonacoEnvironment = {
7
+ getWorker: () => {
8
+ const w = new Worker(new URL(THREAD_URL, import.meta.url));
9
+ threads.add(w);
10
+ return w;
11
+ }
12
+ };
13
+ function monacoStyles() {
14
+ if (typeof __SE_MONACO_CSS__ !== "string") return;
15
+ const href = new URL(__SE_MONACO_CSS__, import.meta.url).href;
16
+ if ([...document.querySelectorAll('link[rel="stylesheet"]')].some((l2) => l2.href === href)) return;
17
+ const l = document.createElement("link");
18
+ l.rel = "stylesheet";
19
+ l.href = href;
20
+ l.dataset.editor = "monaco";
21
+ document.head.append(l);
22
+ }
23
+ const liveThreads = () => threads.size;
24
+ const owners = /* @__PURE__ */ new Map();
25
+ let providers = [];
26
+ const rangeIn = (m, a, b) => {
27
+ const s = m.getPositionAt(a), e = m.getPositionAt(b);
28
+ return new monaco.Range(s.lineNumber, s.column, e.lineNumber, e.column);
29
+ };
30
+ function registerProviders() {
31
+ if (providers.length) return;
32
+ const K = monaco.languages.CompletionItemKind;
33
+ providers = [monaco.languages.registerCompletionItemProvider("yaml", {
34
+ triggerCharacters: [" ", ":", "-", "[", ",", "{"],
35
+ provideCompletionItems(m, position) {
36
+ if (!owners.has(m)) return { suggestions: [] };
37
+ const s = owners.get(m).opts.services, c = s.completionAt(s.docFor(m.getValue()), m.getOffsetAt(position));
38
+ const r = rangeIn(m, c.from, m.getOffsetAt(position));
39
+ return {
40
+ suggestions: c.items.map((it, i) => ({
41
+ label: it.label,
42
+ kind: it.kind === "key" ? K.Property : it.kind === "ref" ? K.Reference : it.kind === "snippet" ? K.Snippet : K.EnumMember,
43
+ insertText: it.insert,
44
+ insertTextRules: it.snippet ? monaco.languages.CompletionItemInsertTextRule.InsertAsSnippet : void 0,
45
+ detail: it.detail,
46
+ documentation: it.doc ? { value: it.doc } : void 0,
47
+ sortText: String(i).padStart(3, "0"),
48
+ range: r
49
+ }))
50
+ };
51
+ }
52
+ }), monaco.languages.registerHoverProvider("yaml", {
53
+ provideHover(m, position) {
54
+ const s = owners.get(m)?.opts.services, h = s ? s.hoverAt(s.docFor(m.getValue()), m.getOffsetAt(position)) : null;
55
+ return h ? { range: rangeIn(m, h.from, h.to), contents: h.parts.map((value) => ({ value })) } : null;
56
+ }
57
+ }), monaco.languages.registerDefinitionProvider("yaml", {
58
+ provideDefinition(m, position) {
59
+ const s = owners.get(m)?.opts.services, d = s ? s.definitionAt(s.docFor(m.getValue()), m.getOffsetAt(position)) : null;
60
+ if (!d) return null;
61
+ if ("open" in d) {
62
+ owners.get(m).opts.onOpen?.(d.open);
63
+ return null;
64
+ }
65
+ return [{ uri: m.uri, range: rangeIn(m, d.from, d.to) }];
66
+ }
67
+ })];
68
+ }
69
+ function textPane(el, doc, opts) {
70
+ monacoStyles();
71
+ const editor = monaco.editor.create(el, {
72
+ // v0.4.1: the file as it is (a pane added after mount)
73
+ // two columns a level, never tabs (the default), whatever the file's own indentation (it is never detected)
74
+ value: doc.text,
75
+ language: "yaml",
76
+ automaticLayout: true,
77
+ minimap: { enabled: false },
78
+ fontSize: 12.5,
79
+ tabSize: 2,
80
+ detectIndentation: false,
81
+ scrollBeyondLastLine: false,
82
+ renderWhitespace: "none",
83
+ fixedOverflowWidgets: true,
84
+ // nothing that needs Monaco's thread: no link detection, colour decorators, occurrence or unicode highlights
85
+ links: false,
86
+ colorDecorators: false,
87
+ occurrencesHighlight: "off",
88
+ selectionHighlight: false,
89
+ unicodeHighlight: { ambiguousCharacters: false, invisibleCharacters: false, nonBasicASCII: false },
90
+ quickSuggestions: { other: true, comments: false, strings: true },
91
+ suggestOnTriggerCharacters: true,
92
+ wordBasedSuggestions: "off",
93
+ suggest: { showWords: false, snippetsPreventQuickSuggestions: false },
94
+ hover: { delay: 250 },
95
+ fontFamily: 'ui-monospace, "SF Mono", Menlo, monospace'
96
+ });
97
+ const model = editor.getModel();
98
+ model.updateOptions({ tabSize: 2 });
99
+ const range = rangeIn;
100
+ owners.set(model, { doc, opts });
101
+ registerProviders();
102
+ const toSel = (ss) => (ss ?? []).map((s) => ({ anchor: model.getOffsetAt(s.getSelectionStart()), head: model.getOffsetAt(s.getPosition()) }));
103
+ const fromSel = (ts) => ts.map((s) => {
104
+ const a = model.getPositionAt(s.anchor), h = model.getPositionAt(s.head);
105
+ return new monaco.Selection(a.lineNumber, a.column, h.lineNumber, h.column);
106
+ });
107
+ let muted = false;
108
+ let lastSel = [];
109
+ let resyncs = 0;
110
+ const resync = () => {
111
+ if (model.getValue() === doc.text) return;
112
+ resyncs++;
113
+ console.warn("editor: the Monaco pane and the model disagreed; the pane was put right");
114
+ const sel = editor.getSelections();
115
+ muted = true;
116
+ model.setValue(doc.text);
117
+ muted = false;
118
+ if (sel) editor.setSelections(sel);
119
+ };
120
+ model.onDidChangeContent((e) => {
121
+ if (muted) return;
122
+ if (e.isUndoing || e.isRedoing) {
123
+ muted = true;
124
+ model.setValue(doc.text);
125
+ muted = false;
126
+ if (e.isUndoing) doc.undo();
127
+ else doc.redo();
128
+ return;
129
+ }
130
+ const step = e.changes.map((c) => ({ start: c.rangeOffset, end: c.rangeOffset + c.rangeLength, text: c.text }));
131
+ const after = toSel(editor.getSelections());
132
+ doc.typed(step, { before: lastSel, after }, "monaco");
133
+ lastSel = after;
134
+ resync();
135
+ });
136
+ editor.onDidChangeCursorSelection((e) => {
137
+ if (muted) return;
138
+ lastSel = toSel(editor.getSelections());
139
+ if (editor.hasTextFocus()) doc.textSel = lastSel;
140
+ if (e.reason === monaco.editor.CursorChangeReason.Explicit) doc.seal();
141
+ });
142
+ editor.onDidBlurEditorText(() => doc.seal());
143
+ doc.on((c) => {
144
+ if (c.origin === "text" && c.kind === "do" && c.source === "monaco") return;
145
+ muted = true;
146
+ try {
147
+ if (c.kind === "load") model.setValue(doc.text);
148
+ else for (const step of c.steps) model.applyEdits([...step].sort((a, b) => a.start - b.start).map((x) => ({ range: range(model, x.start, x.end), text: x.text })));
149
+ if (Array.isArray(c.textSel) && (c.kind === "undo" || c.kind === "redo")) editor.setSelections(fromSel(c.textSel));
150
+ else if (c.kind !== "load" && c.origin !== "text" && c.steps[0]?.[0]) editor.revealLineInCenterIfOutsideViewport(model.getPositionAt(c.steps[0][0].start).lineNumber);
151
+ } finally {
152
+ muted = false;
153
+ }
154
+ lastSel = toSel(editor.getSelections());
155
+ resync();
156
+ });
157
+ let selDecos = editor.createDecorationsCollection([]);
158
+ const showSelection = (paths, move) => {
159
+ const ranges = paths.map((p) => opts.services.rangeOfPath(doc.doc, p)).filter((r) => !!r).map(([a, b]) => range(model, a, b));
160
+ selDecos.clear();
161
+ selDecos = editor.createDecorationsCollection(ranges.map((r) => ({ range: r, options: { className: "sel-range", isWholeLine: false, overviewRuler: { color: "#7f9cf580", position: monaco.editor.OverviewRulerLane.Center } } })));
162
+ if (move && ranges[0] && !editor.hasTextFocus()) {
163
+ muted = true;
164
+ editor.setPosition({ lineNumber: ranges[0].startLineNumber, column: ranges[0].startColumn });
165
+ muted = false;
166
+ editor.revealRangeInCenterIfOutsideViewport(ranges[0]);
167
+ }
168
+ };
169
+ doc.onSelect((c) => {
170
+ if (c.origin !== "text" || !editor.hasTextFocus()) showSelection(c.paths, c.origin !== "text");
171
+ else selDecos.clear();
172
+ });
173
+ let caretTimer = 0;
174
+ editor.onDidChangeCursorPosition(() => {
175
+ if (muted || !editor.hasTextFocus()) return;
176
+ clearTimeout(caretTimer);
177
+ caretTimer = window.setTimeout(() => {
178
+ const p = editor.getPosition();
179
+ if (!p) return;
180
+ const a = doc.doc.at(model.getOffsetAt(p));
181
+ doc.select(a.path.length ? [a.path] : [], "text");
182
+ }, 120);
183
+ });
184
+ editor.addCommand(monaco.KeyMod.CtrlCmd | monaco.KeyCode.KeyZ, () => doc.undo());
185
+ editor.addCommand(monaco.KeyMod.CtrlCmd | monaco.KeyMod.Shift | monaco.KeyCode.KeyZ, () => doc.redo());
186
+ editor.addCommand(monaco.KeyMod.CtrlCmd | monaco.KeyCode.KeyY, () => doc.redo());
187
+ editor.addCommand(monaco.KeyMod.CtrlCmd | monaco.KeyCode.KeyS, () => opts.onSave?.());
188
+ editor.addCommand(monaco.KeyMod.CtrlCmd | monaco.KeyMod.Shift | monaco.KeyCode.KeyS, () => opts.onSaveAs?.());
189
+ return {
190
+ id: "monaco",
191
+ el,
192
+ editor,
193
+ model,
194
+ monaco,
195
+ resyncs: () => resyncs,
196
+ showSelection,
197
+ hasFocus: () => editor.hasTextFocus(),
198
+ focus: () => editor.focus(),
199
+ goToOffset(off) {
200
+ const p = model.getPositionAt(off);
201
+ editor.setPosition(p);
202
+ editor.revealPositionInCenter(p);
203
+ editor.focus();
204
+ },
205
+ caret() {
206
+ const p = editor.getPosition();
207
+ return p ? { line: p.lineNumber, col: p.column } : void 0;
208
+ },
209
+ onCaret(fn) {
210
+ editor.onDidChangeCursorPosition(fn);
211
+ },
212
+ setTheme: (dark) => monaco.editor.setTheme(paneTheme(dark, el)),
213
+ setReadOnly: (ro) => editor.updateOptions({ readOnly: ro, readOnlyMessage: { value: "Read-only" } }),
214
+ dispose() {
215
+ clearTimeout(caretTimer);
216
+ owners.delete(model);
217
+ editor.dispose();
218
+ model.dispose();
219
+ if (!owners.size) {
220
+ for (const p of providers) p.dispose();
221
+ providers = [];
222
+ for (const w of threads) w.terminate();
223
+ threads.clear();
224
+ }
225
+ },
226
+ goTo(path) {
227
+ showSelection([path], true);
228
+ const r = opts.services.rangeOfPath(doc.doc, path);
229
+ if (r) {
230
+ const p = model.getPositionAt(r[0]);
231
+ editor.setPosition(p);
232
+ editor.revealPositionInCenter(p);
233
+ }
234
+ editor.focus();
235
+ },
236
+ setProblems(ps) {
237
+ monaco.editor.setModelMarkers(model, "problems", ps.map((p) => ({
238
+ severity: p.severity === "error" ? monaco.MarkerSeverity.Error : monaco.MarkerSeverity.Warning,
239
+ message: p.message + (p.hint ? `
240
+ ${p.hint}` : ""),
241
+ startLineNumber: p.startLine,
242
+ startColumn: p.startCol,
243
+ endLineNumber: p.endLine,
244
+ endColumn: p.endCol,
245
+ source: p.file ?? void 0
246
+ })));
247
+ },
248
+ pathAtCaret() {
249
+ const p = editor.getPosition();
250
+ return p ? doc.doc.at(model.getOffsetAt(p)).path : [];
251
+ }
252
+ };
253
+ }
254
+ function paneTheme(dark, within = document.body) {
255
+ const probe = document.createElement("div");
256
+ probe.style.display = "none";
257
+ within.append(probe);
258
+ const tok = (v, prop = "color") => {
259
+ probe.style[prop] = `var(${v})`;
260
+ const c = getComputedStyle(probe)[prop];
261
+ return hex(c);
262
+ };
263
+ const t = {
264
+ bg: tok("--surface", "backgroundColor"),
265
+ ink: tok("--ink"),
266
+ ink2: tok("--ink-2"),
267
+ ink3: tok("--ink-3"),
268
+ line: tok("--line", "backgroundColor"),
269
+ accent: tok("--accent"),
270
+ tint: tok("--accent-tint", "backgroundColor"),
271
+ hover: tok("--surface-2", "backgroundColor")
272
+ };
273
+ probe.remove();
274
+ const name = dark ? "iso-dark" : "iso-light";
275
+ monaco.editor.defineTheme(name, {
276
+ base: dark ? "vs-dark" : "vs",
277
+ inherit: true,
278
+ rules: [],
279
+ colors: {
280
+ "editor.background": t.bg,
281
+ "editor.foreground": t.ink,
282
+ "editorLineNumber.foreground": t.ink3,
283
+ "editorLineNumber.activeForeground": t.ink2,
284
+ "editorCursor.foreground": t.accent,
285
+ "editor.selectionBackground": t.tint,
286
+ "editor.lineHighlightBackground": t.hover,
287
+ "editorWidget.background": t.bg,
288
+ "editorWidget.border": t.line,
289
+ "editorSuggestWidget.background": t.bg,
290
+ "editorSuggestWidget.border": t.line,
291
+ "editorSuggestWidget.selectedBackground": t.tint,
292
+ "editorHoverWidget.background": t.bg,
293
+ "editorHoverWidget.border": t.line,
294
+ "focusBorder": t.accent,
295
+ "editorIndentGuide.background1": t.line,
296
+ // the selected row of a list (suggestions, hover actions): the ink on the accent tint
297
+ "editorSuggestWidget.selectedForeground": t.ink,
298
+ "editorSuggestWidget.foreground": t.ink,
299
+ "editorSuggestWidget.highlightForeground": t.accent,
300
+ "editorSuggestWidget.focusHighlightForeground": t.accent,
301
+ "list.activeSelectionForeground": t.ink,
302
+ "list.activeSelectionBackground": t.tint,
303
+ "list.focusForeground": t.ink,
304
+ "list.focusBackground": t.tint,
305
+ "list.hoverBackground": t.hover,
306
+ "quickInputList.focusForeground": t.ink,
307
+ "list.activeSelectionIconForeground": t.ink2,
308
+ "editorSuggestWidget.selectedIconForeground": t.ink2
309
+ }
310
+ });
311
+ return name;
312
+ }
313
+ function hex(c) {
314
+ const m = /rgba?\((\d+),\s*(\d+),\s*(\d+)/.exec(c);
315
+ if (!m) return "#000000";
316
+ return "#" + [m[1], m[2], m[3]].map((x) => Number(x).toString(16).padStart(2, "0")).join("");
317
+ }
318
+ export {
319
+ liveThreads,
320
+ monaco,
321
+ paneTheme,
322
+ textPane
323
+ };