modern-monaco 0.0.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js ADDED
@@ -0,0 +1,635 @@
1
+ // src/lsp/index.ts
2
+ var builtinProviders = {
3
+ html: {
4
+ // @ts-expect-error 'setup.js' is generated at build time
5
+ import: () => import("./lsp/html/setup.js")
6
+ },
7
+ css: {
8
+ aliases: ["less", "sass"],
9
+ // @ts-expect-error 'setup.js' is generated at build time
10
+ import: () => import("./lsp/css/setup.js")
11
+ },
12
+ json: {
13
+ // @ts-expect-error 'setup.js' is generated at build time
14
+ import: () => import("./lsp/json/setup.js")
15
+ },
16
+ typescript: {
17
+ aliases: ["javascript", "jsx", "tsx"],
18
+ // @ts-expect-error 'setup.js' is generated at build time
19
+ import: () => import("./lsp/typescript/setup.js")
20
+ }
21
+ };
22
+ function createWebWorker(url, name) {
23
+ let workerUrl = url;
24
+ if (url.origin !== location.origin) {
25
+ workerUrl = URL.createObjectURL(new Blob([`import "${url.href}"`], { type: "application/javascript" }));
26
+ }
27
+ return new Worker(workerUrl, {
28
+ type: "module",
29
+ name: name ?? url.pathname.slice(1).split("/").slice(-2).join("/")
30
+ });
31
+ }
32
+ function margeProviders(config) {
33
+ return { ...builtinProviders, ...config?.providers };
34
+ }
35
+
36
+ // src/syntaxes/(html)json-script-tag.json
37
+ var html_json_script_tag_default = {
38
+ name: "JSON Script Tag in HTML",
39
+ scopeName: "text.html.json-script-tag",
40
+ injectTo: [
41
+ "text.html.basic"
42
+ ],
43
+ injectionSelector: "L:text.html.basic -comment",
44
+ patterns: [
45
+ {
46
+ begin: `(<)(script)\\b(?=[^>]*type=(importmap|'importmap'|"importmap"|json|'json'|"json"|'application/json'|"application/json"))(?![^/>]*/>\\s*$)`,
47
+ beginCaptures: {
48
+ "1": {
49
+ name: "punctuation.definition.tag.begin.html"
50
+ },
51
+ "2": {
52
+ name: "entity.name.tag.html"
53
+ }
54
+ },
55
+ end: "(</)(script)(>)",
56
+ endCaptures: {
57
+ "1": {
58
+ name: "punctuation.definition.tag.begin.html"
59
+ },
60
+ "2": {
61
+ name: "entity.name.tag.html"
62
+ },
63
+ "3": {
64
+ name: "punctuation.definition.tag.end.html"
65
+ }
66
+ },
67
+ patterns: [
68
+ {
69
+ name: "entity.other.attribute-name.html",
70
+ match: "\\b([a-zA-Z\\-:_]+)"
71
+ },
72
+ {
73
+ name: "punctuation.separator.key-value.html",
74
+ match: "="
75
+ },
76
+ {
77
+ name: "string.quoted.double.html",
78
+ match: `("|').*?("|')`
79
+ },
80
+ {
81
+ begin: "(>)",
82
+ beginCaptures: {
83
+ "0": {
84
+ name: "meta.tag.metadata.json.start.html"
85
+ },
86
+ "1": {
87
+ name: "punctuation.definition.tag.end.html"
88
+ }
89
+ },
90
+ end: "(?=<\/script>)",
91
+ endCaptures: {
92
+ "0": {
93
+ name: "meta.tag.metadata.json.end.html"
94
+ }
95
+ },
96
+ patterns: [
97
+ {
98
+ include: "source.json"
99
+ }
100
+ ]
101
+ }
102
+ ]
103
+ }
104
+ ]
105
+ };
106
+
107
+ // src/syntaxes/(js)inline-html.json
108
+ var js_inline_html_default = {
109
+ $license: "https://github.com/pushqrdx/vscode-inline-html/blob/master/LICENSE",
110
+ name: "Inline HTML in JavaScript",
111
+ scopeName: "text.html.inline",
112
+ injectTo: [
113
+ "source.js",
114
+ "source.jsx",
115
+ "source.ts",
116
+ "source.tsx"
117
+ ],
118
+ injectionSelector: "L:source.js -comment -string, L:source.jsx -comment -string, L:source.ts -comment -string, L:source.tsx -comment -string, L:source.js (string.quoted.double.html, string.quoted.single.html), L:source.jsx (string.quoted.double.html, string.quoted.single.html), L:source.js.jsx (string.quoted.double.html, string.quoted.single.html), L:source.ts (string.quoted.double.html, string.quoted.single.html), L:source.tsx (string.quoted.double.html, string.quoted.single.html)",
119
+ injections: {
120
+ "L:source": {
121
+ patterns: [
122
+ {
123
+ match: "<",
124
+ name: "invalid.illegal.bad-angle-bracket.html"
125
+ }
126
+ ]
127
+ }
128
+ },
129
+ patterns: [
130
+ {
131
+ contentName: "meta.embedded.block.html",
132
+ begin: "(?ix)(\\s*?(\\w+\\.)?(?:html|/\\*\\s*html\\s*\\*/)\\s*)(`)",
133
+ beginCaptures: {
134
+ "0": {
135
+ name: "string.template.ts, punctuation.definition.string.template.begin.ts"
136
+ },
137
+ "1": {
138
+ name: "entity.name.function.tagged-template.ts"
139
+ }
140
+ },
141
+ end: "(`)",
142
+ endCaptures: {
143
+ "0": {
144
+ name: "string.template.ts, punctuation.definition.string.template.end.ts"
145
+ }
146
+ },
147
+ patterns: [
148
+ {
149
+ include: "source.ts#template-substitution-element"
150
+ },
151
+ {
152
+ include: "text.html.basic"
153
+ }
154
+ ]
155
+ },
156
+ {
157
+ include: "source.ts#template-substitution-element"
158
+ }
159
+ ]
160
+ };
161
+
162
+ // src/syntaxes/(js)inline-css.json
163
+ var js_inline_css_default = {
164
+ $license: "https://github.com/pushqrdx/vscode-inline-html/blob/master/LICENSE",
165
+ name: "Inline CSS in JavaScript",
166
+ scopeName: "source.css.inline",
167
+ injectTo: [
168
+ "source.js",
169
+ "source.jsx",
170
+ "source.ts",
171
+ "source.tsx"
172
+ ],
173
+ injectionSelector: "L:source.js -comment -string, L:source.jsx -comment -string, L:source.ts -comment -string, L:source.tsx -comment -string",
174
+ patterns: [
175
+ {
176
+ contentName: "meta.embedded.block.css",
177
+ begin: "(?ix)(\\s*?(\\w+\\.)?(?:css|/\\*\\s*css\\s*\\*/)\\s*)(`)",
178
+ beginCaptures: {
179
+ "0": {
180
+ name: "string.template.ts, punctuation.definition.string.template.begin.ts"
181
+ },
182
+ "1": {
183
+ name: "entity.name.function.tagged-template.ts"
184
+ }
185
+ },
186
+ end: "(`)",
187
+ endCaptures: {
188
+ "0": {
189
+ name: "string.template.ts, punctuation.definition.string.template.end.ts"
190
+ }
191
+ },
192
+ patterns: [
193
+ {
194
+ include: "source.ts#template-substitution-element"
195
+ },
196
+ {
197
+ include: "source.css"
198
+ }
199
+ ]
200
+ },
201
+ {
202
+ include: "source.ts#template-substitution-element"
203
+ }
204
+ ]
205
+ };
206
+
207
+ // src/syntaxes/index.ts
208
+ var syntaxes_default = [
209
+ html_json_script_tag_default,
210
+ js_inline_html_default,
211
+ js_inline_css_default
212
+ ];
213
+
214
+ // src/index.ts
215
+ import { getLanguageIdFromPath, initShiki, setDefaultWasmLoader, tmGrammars } from "./shiki.js";
216
+ import { initShikiMonacoTokenizer, registerShikiMonacoTokenizer } from "./shiki.js";
217
+ import { render } from "./shiki.js";
218
+ import { getWasmInstance } from "./shiki-wasm.js";
219
+ import { ErrorNotFound, Workspace } from "./workspace.js";
220
+
221
+ // src/util.ts
222
+ var enc = new TextEncoder();
223
+ var dec = new TextDecoder();
224
+ function decode(data) {
225
+ return data instanceof Uint8Array ? dec.decode(data) : data;
226
+ }
227
+ function debunce(fn, delay = 500) {
228
+ let timer = null;
229
+ return () => {
230
+ if (timer !== null) {
231
+ clearTimeout(timer);
232
+ }
233
+ timer = setTimeout(() => {
234
+ timer = null;
235
+ fn();
236
+ }, delay);
237
+ };
238
+ }
239
+
240
+ // src/index.ts
241
+ setDefaultWasmLoader(getWasmInstance);
242
+ var editorProps = [
243
+ "autoDetectHighContrast",
244
+ "automaticLayout",
245
+ "contextmenu",
246
+ "cursorBlinking",
247
+ "cursorSmoothCaretAnimation",
248
+ "cursorStyle",
249
+ "cursorWidth",
250
+ "fontFamily",
251
+ "fontLigatures",
252
+ "fontSize",
253
+ "fontVariations",
254
+ "fontWeight",
255
+ "letterSpacing",
256
+ "lineHeight",
257
+ "lineNumbers",
258
+ "lineNumbersMinChars",
259
+ "matchBrackets",
260
+ "minimap",
261
+ "mouseStyle",
262
+ "multiCursorModifier",
263
+ "padding",
264
+ "readOnly",
265
+ "readOnlyMessage",
266
+ "rulers",
267
+ "scrollbar",
268
+ "stickyScroll",
269
+ "tabSize",
270
+ "theme",
271
+ "wordWrap"
272
+ ];
273
+ var preloadGrammars = [
274
+ "html",
275
+ "css",
276
+ "javascript",
277
+ "json"
278
+ ];
279
+ async function loadMonaco(highlighter, workspace, lsp, onDidEditorWorkerReady) {
280
+ const monaco = await import("./editor-core.js");
281
+ const lspProviders = margeProviders(lsp);
282
+ workspace?.init(monaco);
283
+ if (!document.getElementById("monaco-editor-core-css")) {
284
+ const styleEl = document.createElement("style");
285
+ styleEl.id = "monaco-editor-core-css";
286
+ styleEl.media = "screen";
287
+ styleEl.textContent = monaco.CSS;
288
+ document.head.appendChild(styleEl);
289
+ }
290
+ Reflect.set(globalThis, "MonacoEnvironment", {
291
+ getWorker: async (_workerId, label) => {
292
+ let provider = lspProviders[label];
293
+ if (!provider) {
294
+ provider = Object.values(lspProviders).find((p) => p.aliases?.includes(label));
295
+ }
296
+ const url = provider ? (await provider.import()).getWorkerUrl() : monaco.getWorkerUrl();
297
+ if (label === "typescript") {
298
+ const tsVersion = lsp?.typescript?.tsVersion;
299
+ if (tsVersion && (url.hostname === "esm.sh" || url.hostname.endsWith(".esm.sh"))) {
300
+ url.searchParams.set("deps", `typescript@${tsVersion}`);
301
+ }
302
+ }
303
+ const worker = createWebWorker(url, void 0);
304
+ if (!provider) {
305
+ const onMessage = (e) => {
306
+ onDidEditorWorkerReady?.();
307
+ worker.removeEventListener("message", onMessage);
308
+ };
309
+ worker.addEventListener("message", onMessage);
310
+ }
311
+ return worker;
312
+ },
313
+ getLanguageIdFromUri: (uri) => getLanguageIdFromPath(uri.path)
314
+ });
315
+ monaco.editor.registerLinkOpener({
316
+ async open(link) {
317
+ if ((link.scheme === "https" || link.scheme === "http") && monaco.editor.getModel(link)) {
318
+ return true;
319
+ }
320
+ return false;
321
+ }
322
+ });
323
+ monaco.editor.registerEditorOpener({
324
+ openCodeEditor: async (editor, resource, selectionOrPosition) => {
325
+ if (workspace && resource.scheme === "file") {
326
+ try {
327
+ await workspace._openTextDocument(resource.toString(), editor, selectionOrPosition);
328
+ return true;
329
+ } catch (err) {
330
+ if (err instanceof ErrorNotFound) {
331
+ return false;
332
+ }
333
+ throw err;
334
+ }
335
+ }
336
+ try {
337
+ const model = monaco.editor.getModel(resource);
338
+ if (model) {
339
+ editor.setModel(model);
340
+ if (selectionOrPosition) {
341
+ if ("startLineNumber" in selectionOrPosition) {
342
+ editor.setSelection(selectionOrPosition);
343
+ } else {
344
+ editor.setPosition(selectionOrPosition);
345
+ }
346
+ const pos = editor.getPosition();
347
+ if (pos) {
348
+ const svp = editor.getScrolledVisiblePosition(new monaco.Position(pos.lineNumber - 7, pos.column));
349
+ if (svp) {
350
+ editor.setScrollTop(svp.top);
351
+ }
352
+ }
353
+ }
354
+ const isHttpUrl = resource.scheme === "https" || resource.scheme === "http";
355
+ editor.updateOptions({ readOnly: isHttpUrl });
356
+ return true;
357
+ }
358
+ } catch (error) {
359
+ }
360
+ return false;
361
+ }
362
+ });
363
+ if (globalThis.navigator?.userAgent?.includes("Macintosh")) {
364
+ monaco.editor.addKeybindingRule({
365
+ keybinding: monaco.KeyMod.CtrlCmd | monaco.KeyCode.KeyK,
366
+ command: "editor.action.quickCommand"
367
+ });
368
+ }
369
+ const allLanguages = new Set(tmGrammars.filter((g) => !g.injectTo).map((g) => g.name));
370
+ allLanguages.forEach((id) => {
371
+ const languages = monaco.languages;
372
+ languages.register({ id, aliases: tmGrammars.find((g) => g.name === id)?.aliases });
373
+ languages.onLanguage(id, async () => {
374
+ const config = monaco.languageConfigurations[monaco.languageConfigurationAliases[id] ?? id];
375
+ const loadedGrammars = new Set(highlighter.getLoadedLanguages());
376
+ const reqiredGrammars = [id].concat(tmGrammars.find((g) => g.name === id)?.embedded ?? []).filter((id2) => !loadedGrammars.has(id2));
377
+ if (config) {
378
+ languages.setLanguageConfiguration(id, monaco.convertVscodeLanguageConfiguration(config));
379
+ }
380
+ if (reqiredGrammars.length > 0) {
381
+ await highlighter.loadGrammarFromCDN(...reqiredGrammars);
382
+ }
383
+ registerShikiMonacoTokenizer(monaco, highlighter, id);
384
+ let lspLabel = id;
385
+ let lspProvider = lspProviders[lspLabel];
386
+ if (!lspProvider) {
387
+ const alias = Object.entries(lspProviders).find(([, lsp2]) => lsp2.aliases?.includes(id));
388
+ if (alias) {
389
+ [lspLabel, lspProvider] = alias;
390
+ }
391
+ }
392
+ if (lspProvider) {
393
+ lspProvider.import().then(({ setup }) => setup(monaco, id, workspace, lsp?.[lspLabel], lsp?.formatting));
394
+ }
395
+ });
396
+ });
397
+ initShikiMonacoTokenizer(monaco, highlighter);
398
+ return monaco;
399
+ }
400
+ async function init(options) {
401
+ const langs = (options?.langs ?? []).concat(preloadGrammars, syntaxes_default);
402
+ const hightlighter = await initShiki({ ...options, langs });
403
+ return loadMonaco(hightlighter, options?.workspace, options?.lsp);
404
+ }
405
+ async function lazy(options, hydrate2) {
406
+ const workspace = options?.workspace;
407
+ let monacoCore = null;
408
+ let onDidEditorWorkerReady;
409
+ let editorWorkerPromise = new Promise((resolve) => {
410
+ onDidEditorWorkerReady = resolve;
411
+ });
412
+ function load(highlighter) {
413
+ if (monacoCore) {
414
+ return monacoCore;
415
+ }
416
+ return monacoCore = loadMonaco(highlighter, workspace, options?.lsp, onDidEditorWorkerReady).then((m) => monacoCore = m);
417
+ }
418
+ function setStyle(el, style) {
419
+ Object.assign(el.style, style);
420
+ }
421
+ customElements.define(
422
+ "monaco-editor",
423
+ class extends HTMLElement {
424
+ async connectedCallback() {
425
+ const renderOptions = {};
426
+ for (const attrName of this.getAttributeNames()) {
427
+ const key = editorProps.find((k) => k.toLowerCase() === attrName);
428
+ if (key) {
429
+ let value = this.getAttribute(attrName);
430
+ if (value === "") {
431
+ value = key === "minimap" || key === "stickyScroll" ? { enabled: true } : true;
432
+ } else {
433
+ value = value.trim();
434
+ if (value === "true") {
435
+ value = true;
436
+ } else if (value === "false") {
437
+ value = false;
438
+ } else if (value === "null") {
439
+ value = null;
440
+ } else if (/^\d+$/.test(value)) {
441
+ value = Number(value);
442
+ } else if (/^\{.+\}$/.test(value)) {
443
+ try {
444
+ value = JSON.parse(value);
445
+ } catch (error) {
446
+ value = void 0;
447
+ }
448
+ }
449
+ }
450
+ if (key === "padding") {
451
+ if (typeof value === "number") {
452
+ value = { top: value, bottom: value };
453
+ } else if (/^\d+\s+\d+$/.test(value)) {
454
+ const [top, bottom] = value.split(/\s+/);
455
+ if (top && bottom) {
456
+ value = { top: Number(top), bottom: Number(bottom) };
457
+ }
458
+ } else {
459
+ value = void 0;
460
+ }
461
+ }
462
+ if (key === "wordWrap" && (value === "on" || value === true)) {
463
+ value = "on";
464
+ }
465
+ if (value !== void 0) {
466
+ renderOptions[key] = value;
467
+ }
468
+ }
469
+ }
470
+ if (hydrate2) {
471
+ const optionsScript = this.children[0];
472
+ if (optionsScript && optionsScript.tagName === "SCRIPT" && optionsScript.className === "monaco-editor-options") {
473
+ const opts = JSON.parse(optionsScript.textContent);
474
+ if (opts.fontDigitWidth) {
475
+ Reflect.set(globalThis, "__monaco_maxDigitWidth", opts.fontDigitWidth);
476
+ }
477
+ Object.assign(renderOptions, opts);
478
+ optionsScript.remove();
479
+ }
480
+ }
481
+ setStyle(this, { display: "block", position: "relative" });
482
+ const width = Number(this.getAttribute("width"));
483
+ const height = Number(this.getAttribute("height"));
484
+ if (width > 0 && height > 0) {
485
+ setStyle(this, { width: `${width}px`, height: `${height}px` });
486
+ renderOptions.dimension = { width, height };
487
+ } else {
488
+ setStyle(this, { width: "100%", height: "100%" });
489
+ }
490
+ const containerEl = document.createElement("div");
491
+ containerEl.className = "monaco-editor-container";
492
+ containerEl.style.width = "100%";
493
+ containerEl.style.height = "100%";
494
+ this.appendChild(containerEl);
495
+ let filename = renderOptions.filename ?? this.getAttribute("file");
496
+ if (!filename && workspace) {
497
+ if (workspace.history.state.current) {
498
+ filename = workspace.history.state.current;
499
+ } else if (workspace.entryFile) {
500
+ filename = workspace.entryFile;
501
+ workspace.history.replace(filename);
502
+ } else {
503
+ const rootFiles = (await workspace.fs.readDirectory("/")).filter(([name, type]) => type === 1).map(([name]) => name);
504
+ filename = rootFiles.includes("index.html") ? "index.html" : rootFiles[0];
505
+ if (filename) {
506
+ workspace.history.replace(filename);
507
+ }
508
+ }
509
+ }
510
+ const langs = (options?.langs ?? []).concat(preloadGrammars, syntaxes_default);
511
+ if (renderOptions.language || filename) {
512
+ langs.push(renderOptions.language ?? getLanguageIdFromPath(filename) ?? "plaintext");
513
+ }
514
+ if (renderOptions.theme) {
515
+ renderOptions.theme = renderOptions.theme.toLowerCase().replace(/ +/g, "-");
516
+ }
517
+ const highlighter = await initShiki({
518
+ theme: renderOptions.theme,
519
+ ...options,
520
+ langs
521
+ });
522
+ let prerenderEl = hydrate2 ? this.querySelector(".monaco-editor-prerender") : void 0;
523
+ if (!prerenderEl && filename && workspace) {
524
+ try {
525
+ const code = await workspace.fs.readFile(filename);
526
+ const language = getLanguageIdFromPath(filename);
527
+ prerenderEl = containerEl.cloneNode(true);
528
+ prerenderEl.className = "monaco-editor-prerender";
529
+ prerenderEl.innerHTML = render(highlighter, {
530
+ ...renderOptions,
531
+ code: decode(code),
532
+ language
533
+ });
534
+ } catch (error) {
535
+ if (error instanceof ErrorNotFound) {
536
+ } else {
537
+ throw error;
538
+ }
539
+ }
540
+ }
541
+ if (prerenderEl) {
542
+ setStyle(prerenderEl, { position: "absolute", top: "0", left: "0" });
543
+ this.appendChild(prerenderEl);
544
+ if (filename && workspace) {
545
+ const viewState = await workspace.viewState.get(filename);
546
+ const scrollTop = viewState?.viewState.scrollTop ?? 0;
547
+ if (scrollTop) {
548
+ const mockEl = prerenderEl.querySelector(".mock-monaco-editor");
549
+ if (mockEl) {
550
+ mockEl.scrollTop = scrollTop;
551
+ }
552
+ }
553
+ }
554
+ }
555
+ async function createMonaco() {
556
+ const monaco = await load(highlighter);
557
+ const editor = monaco.editor.create(containerEl, renderOptions);
558
+ if (workspace) {
559
+ const storeViewState = () => {
560
+ const currentModel = editor.getModel();
561
+ if (currentModel?.uri.scheme === "file") {
562
+ const state = editor.saveViewState();
563
+ if (state) {
564
+ state.viewState.scrollTop ??= editor.getScrollTop();
565
+ workspace.viewState.save(currentModel.uri.toString(), Object.freeze(state));
566
+ }
567
+ }
568
+ };
569
+ editor.onDidChangeCursorSelection(debunce(storeViewState));
570
+ editor.onDidScrollChange(debunce(storeViewState));
571
+ workspace.history.onChange((state) => {
572
+ if (editor.getModel()?.uri.toString() !== state.current) {
573
+ workspace._openTextDocument(state.current, editor);
574
+ }
575
+ });
576
+ }
577
+ if (filename && workspace) {
578
+ try {
579
+ const model = await workspace._openTextDocument(filename, editor);
580
+ if (renderOptions.filename === filename && renderOptions.code && renderOptions.code !== model.getValue()) {
581
+ model.setValue(renderOptions.code);
582
+ }
583
+ } catch (error) {
584
+ if (error instanceof ErrorNotFound) {
585
+ if (renderOptions.code && renderOptions.filename) {
586
+ await workspace.fs.writeFile(renderOptions.filename, renderOptions.code);
587
+ workspace._openTextDocument(renderOptions.filename, editor);
588
+ } else {
589
+ editor.setModel(monaco.editor.createModel(""));
590
+ }
591
+ } else {
592
+ throw error;
593
+ }
594
+ }
595
+ } else if (renderOptions.code && (renderOptions.language || renderOptions.filename)) {
596
+ const model = monaco.editor.createModel(
597
+ renderOptions.code,
598
+ renderOptions.language,
599
+ renderOptions.filename
600
+ );
601
+ editor.setModel(model);
602
+ } else {
603
+ editor.setModel(monaco.editor.createModel(""));
604
+ }
605
+ if (prerenderEl) {
606
+ editorWorkerPromise.then(() => {
607
+ setTimeout(() => {
608
+ const animate = prerenderEl.animate?.([{ opacity: 1 }, { opacity: 0 }], { duration: 150 });
609
+ if (animate) {
610
+ animate.finished.then(() => prerenderEl.remove());
611
+ } else {
612
+ setTimeout(() => prerenderEl.remove(), 150);
613
+ }
614
+ }, 100);
615
+ });
616
+ }
617
+ }
618
+ await createMonaco();
619
+ }
620
+ }
621
+ );
622
+ await editorWorkerPromise;
623
+ return {
624
+ workspace
625
+ };
626
+ }
627
+ function hydrate(options) {
628
+ return lazy(options, true);
629
+ }
630
+ export {
631
+ Workspace,
632
+ hydrate,
633
+ init,
634
+ lazy
635
+ };
@@ -0,0 +1,43 @@
1
+ // src/lsp/css/setup.ts
2
+ import * as ls from "../language-service.js";
3
+ async function setup2(monaco, languageId, workspace, languageSettings, formattingOptions) {
4
+ const { tabSize, insertSpaces, insertFinalNewline, trimFinalNewlines } = formattingOptions ?? {};
5
+ const createData = {
6
+ language: languageId,
7
+ data: {
8
+ useDefaultDataProvider: true
9
+ // todo: custom data provider
10
+ },
11
+ format: {
12
+ tabSize,
13
+ insertFinalNewline,
14
+ insertSpaces,
15
+ preserveNewLines: !trimFinalNewlines,
16
+ newlineBetweenSelectors: true,
17
+ newlineBetweenRules: true,
18
+ spaceAroundSelectorSeparator: false,
19
+ braceStyle: "collapse"
20
+ }
21
+ };
22
+ const worker = monaco.editor.createWebWorker({
23
+ moduleId: "lsp/css/worker",
24
+ label: languageId,
25
+ createData,
26
+ host: ls.createHost(workspace)
27
+ });
28
+ ls.setup(monaco);
29
+ ls.enableBasicFeatures(languageId, worker, ["/", "-", ":", "("], workspace);
30
+ ls.enableCodeAction(languageId, worker);
31
+ ls.enableColorPresentation(languageId, worker);
32
+ ls.enableDocumentLinks(languageId, worker);
33
+ }
34
+ function getWorkerUrl() {
35
+ const i = () => import("./worker.js");
36
+ const m = getWorkerUrl.toString().match(/import\(['"](.+?)['"]\)/);
37
+ if (!m) throw new Error("worker url not found", { cause: i });
38
+ return new URL(m[1], import.meta.url);
39
+ }
40
+ export {
41
+ getWorkerUrl,
42
+ setup2 as setup
43
+ };