@deot/docs-playground 1.1.3 → 1.1.5

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.
@@ -1,215 +0,0 @@
1
- import { t as SASS_CDN_URL } from "./cdn-DEvdGJu2.js";
2
- import { watch } from "vue";
3
- //#region packages/playground/src/core/scss.ts
4
- var SCHEME = "docs-playground";
5
- var STYLE_EXTS = [".scss", ".sass"];
6
- var VUE_SCSS_STYLE_RE = /<style\b[^>]*\blang\s*=\s*(['"]?)s[ac]ss\1/i;
7
- var LANG_ATTR_RE = /\s*lang\s*=\s*(['"]?)s[ac]ss\1/i;
8
- var SCSS_ERROR_MARK = "[playground-sass]";
9
- var INJECT_START = "/* docs-playground-scss-start */";
10
- var INJECT_END = "/* docs-playground-scss-end */";
11
- var EMPTY_JS = "export default {}\n";
12
- var boundStores = /* @__PURE__ */ new WeakSet();
13
- var wrappedCompilers = /* @__PURE__ */ new WeakSet();
14
- var loadedSass;
15
- var loadPromise;
16
- var fileCode = (value) => typeof value === "string" ? value : value.code;
17
- var playgroundPath = (url) => decodeURIComponent(url.pathname.replace(/^\/+/u, ""));
18
- var toPlaygroundUrl = (filename) => new URL(`${SCHEME}:///${filename.replace(/^\/+/u, "")}`);
19
- var basename = (path) => path.split("/").pop() || path;
20
- var scssSyntax = (filename, lang) => lang === "sass" || /\.sass$/i.test(filename) ? "indented" : "scss";
21
- var errorText = (item) => item instanceof Error ? item.message : String(item);
22
- var isScssFile = (filename) => /\.s[ac]ss$/i.test(filename);
23
- var vueSourceNeedsScss = (source) => VUE_SCSS_STYLE_RE.test(source);
24
- var resolveSassModule = async (url) => {
25
- const mod = await import(
26
- /* @vite-ignore */
27
- url
28
- );
29
- const sass = typeof mod.compileString === "function" ? mod : mod.default;
30
- if (typeof sass?.compileString !== "function") throw new Error(`Sass module at ${url} does not export compileString`);
31
- return sass;
32
- };
33
- var loadSass = () => {
34
- loadPromise ??= (() => resolveSassModule(SASS_CDN_URL))().then((sass) => {
35
- loadedSass = sass;
36
- return sass;
37
- });
38
- return loadPromise;
39
- };
40
- var isScssPartial = (filename) => isScssFile(filename) && basename(filename).startsWith("_");
41
- var filesNeedScss = (files) => Object.entries(files).some(([filename, value]) => isScssFile(filename) || /\.vue$/i.test(filename) && vueSourceNeedsScss(fileCode(value)));
42
- var whenSassReady = (files, run) => {
43
- if (!filesNeedScss(files) || loadedSass) run();
44
- else loadSass().then(run);
45
- };
46
- var toPlaygroundFileMap = (files) => Object.fromEntries(Object.entries(files).map(([filename, value]) => [filename, fileCode(value)]));
47
- var formatScssError = (filename, message) => `${SCSS_ERROR_MARK} ${filename}: ${message}`;
48
- var scssFail = (filename, error) => formatScssError(filename, errorText(error));
49
- var withUnderscore = (path) => {
50
- const base = basename(path);
51
- if (base.startsWith("_")) return path;
52
- return `${path.slice(0, -base.length)}_${base}`;
53
- };
54
- var matchFileKey = (files, path) => [
55
- path,
56
- path.startsWith("src/") ? path : `src/${path}`,
57
- path.replace(/^src\//u, "")
58
- ].find((key) => files[key] !== void 0);
59
- var stylesheetCandidates = (requestPath) => {
60
- if (isScssFile(requestPath)) return [requestPath, withUnderscore(requestPath)];
61
- return STYLE_EXTS.flatMap((ext) => [
62
- `${requestPath}${ext}`,
63
- withUnderscore(`${requestPath}${ext}`),
64
- `${requestPath}/index${ext}`,
65
- withUnderscore(`${requestPath}/index${ext}`)
66
- ]);
67
- };
68
- var resolvePlaygroundStylesheet = (files, requestPath) => {
69
- const found = [...new Set(stylesheetCandidates(requestPath).map((path) => matchFileKey(files, path)).filter((key) => Boolean(key)))];
70
- if (found.length > 1) throw new Error(`Ambiguous Sass import "${requestPath}": ${found.join(", ")}`);
71
- return found[0] ?? null;
72
- };
73
- var createPlaygroundImporter = (getFiles) => ({
74
- canonicalize(url, context) {
75
- if (/^[a-zA-Z][\w+.-]*:/u.test(url) && !url.startsWith(`${SCHEME}:`)) return null;
76
- try {
77
- const resolved = resolvePlaygroundStylesheet(getFiles(), playgroundPath(new URL(url, context.containingUrl ?? toPlaygroundUrl(""))));
78
- return resolved ? toPlaygroundUrl(resolved) : null;
79
- } catch {
80
- return null;
81
- }
82
- },
83
- load(canonicalUrl) {
84
- const files = getFiles();
85
- const key = playgroundPath(canonicalUrl);
86
- return files[key] === void 0 ? null : {
87
- contents: files[key],
88
- syntax: scssSyntax(key)
89
- };
90
- }
91
- });
92
- var compileScssSource = (source, filename, sass, files, lang) => {
93
- const importer = createPlaygroundImporter(() => files);
94
- return sass.compileString(source, {
95
- syntax: scssSyntax(filename, lang),
96
- url: toPlaygroundUrl(filename),
97
- importer,
98
- importers: [importer]
99
- }).css;
100
- };
101
- var rewriteVueSfcStyles = (source, filename, parse, sass, files) => {
102
- const scssStyles = parse(source, { filename }).descriptor.styles.filter((style) => style.lang === "scss" || style.lang === "sass");
103
- if (!scssStyles.length) return {
104
- code: source,
105
- errors: []
106
- };
107
- const errors = [];
108
- let code = source;
109
- for (const style of [...scssStyles].sort((left, right) => right.loc.start.offset - left.loc.start.offset)) {
110
- const before = code.slice(0, style.loc.start.offset);
111
- const after = code.slice(style.loc.end.offset);
112
- const openStart = before.lastIndexOf("<style");
113
- if (openStart < 0) {
114
- errors.push(formatScssError(filename, "unable to locate <style> opening tag"));
115
- continue;
116
- }
117
- try {
118
- const css = compileScssSource(style.content, filename, sass, files, style.lang);
119
- code = `${before.slice(0, openStart)}${before.slice(openStart).replace(LANG_ATTR_RE, "")}${css}${after}`;
120
- } catch (error) {
121
- errors.push(scssFail(filename, error));
122
- }
123
- }
124
- return {
125
- code,
126
- errors
127
- };
128
- };
129
- var appendParseErrors = (result, errors) => errors.length ? {
130
- ...result,
131
- errors: [...result.errors, ...errors.map((item) => new Error(item))]
132
- } : result;
133
- var wrapCompiler = (compiler, getFiles) => {
134
- if (wrappedCompilers.has(compiler)) return compiler;
135
- const originalParse = compiler.parse.bind(compiler);
136
- const wrapped = { ...compiler };
137
- wrapped.parse = ((source, options) => {
138
- const filename = options?.filename || "anonymous.vue";
139
- if (!vueSourceNeedsScss(source)) return originalParse(source, options);
140
- const rewritten = loadedSass ? rewriteVueSfcStyles(source, filename, originalParse, loadedSass, getFiles()) : {
141
- code: source,
142
- errors: [formatScssError(filename, "compiler is not loaded")]
143
- };
144
- return appendParseErrors(originalParse(rewritten.errors.length ? source : rewritten.code, options), rewritten.errors);
145
- });
146
- wrappedCompilers.add(wrapped);
147
- return wrapped;
148
- };
149
- var withInjectedCss = (css, extra) => {
150
- const start = css.indexOf(INJECT_START);
151
- const end = start < 0 ? -1 : css.indexOf(INJECT_END, start);
152
- const base = (start < 0 ? css : `${css.slice(0, start)}${end >= 0 ? css.slice(end + 30) : ""}`).trimEnd();
153
- if (!extra.trim()) return base;
154
- const block = `${INJECT_START}\n${extra.trim()}\n${INJECT_END}`;
155
- return base ? `${base}\n${block}` : block;
156
- };
157
- var isStandaloneScssError = (item) => {
158
- const text = errorText(item);
159
- return text.startsWith(SCSS_ERROR_MARK) && /\.s[ac]ss:/i.test(text);
160
- };
161
- var syncScssErrors = (store, scssErrors) => {
162
- const next = [...scssErrors, ...store.errors.filter((item) => !isStandaloneScssError(item))];
163
- if (next.map(String).join("\0") === store.errors.map(String).join("\0")) return;
164
- store.errors = next;
165
- };
166
- var applyStandaloneScss = (store, sass = loadedSass) => {
167
- if (!sass) return [];
168
- const fileMap = toPlaygroundFileMap(store.files);
169
- const errors = [];
170
- const injected = [];
171
- for (const [filename, file] of Object.entries(store.files)) {
172
- if (!isScssFile(filename) || !file.compiled) continue;
173
- try {
174
- const css = compileScssSource(file.code, filename, sass, fileMap);
175
- file.compiled.css = css;
176
- file.compiled.js = EMPTY_JS;
177
- file.compiled.ssr = EMPTY_JS;
178
- if (!isScssPartial(filename) && css.trim()) injected.push(css);
179
- } catch (error) {
180
- errors.push(scssFail(filename, error));
181
- }
182
- }
183
- const main = store.files[store.mainFile];
184
- if (main?.compiled) {
185
- const next = withInjectedCss(main.compiled.css || "", injected.join("\n"));
186
- if (next !== (main.compiled.css || "")) main.compiled.css = next;
187
- }
188
- syncScssErrors(store, errors);
189
- return errors;
190
- };
191
- var bindPlaygroundScss = (store) => {
192
- if (boundStores.has(store)) return;
193
- boundStores.add(store);
194
- const getFiles = () => toPlaygroundFileMap(store.files);
195
- const installCompiler = () => {
196
- if (typeof store.compiler?.parse === "function") store.compiler = wrapCompiler(store.compiler, getFiles);
197
- };
198
- installCompiler();
199
- watch(() => store.compiler, installCompiler);
200
- watch(() => [
201
- store.mainFile,
202
- store.files[store.mainFile]?.compiled?.css,
203
- store.errors.map(String).join("\0"),
204
- Object.entries(store.files).filter(([filename]) => isScssFile(filename)).map(([filename, file]) => `${filename}:${file.code}`).join("\n")
205
- ].join("\0"), () => {
206
- if (loadedSass) applyStandaloneScss(store);
207
- });
208
- const originalSetFiles = store.setFiles.bind(store);
209
- store.setFiles = async (newFiles, mainFile) => {
210
- if (filesNeedScss(newFiles) && !loadedSass) await loadSass();
211
- return originalSetFiles(newFiles, mainFile);
212
- };
213
- };
214
- //#endregion
215
- export { compileScssSource as n, whenSassReady as r, bindPlaygroundScss as t };
@@ -1,233 +0,0 @@
1
- const require_cdn = require("./cdn-Czve5_9b.cjs");
2
- let vue = require("vue");
3
- //#region packages/playground/src/core/scss.ts
4
- var SCHEME = "docs-playground";
5
- var STYLE_EXTS = [".scss", ".sass"];
6
- var VUE_SCSS_STYLE_RE = /<style\b[^>]*\blang\s*=\s*(['"]?)s[ac]ss\1/i;
7
- var LANG_ATTR_RE = /\s*lang\s*=\s*(['"]?)s[ac]ss\1/i;
8
- var SCSS_ERROR_MARK = "[playground-sass]";
9
- var INJECT_START = "/* docs-playground-scss-start */";
10
- var INJECT_END = "/* docs-playground-scss-end */";
11
- var EMPTY_JS = "export default {}\n";
12
- var boundStores = /* @__PURE__ */ new WeakSet();
13
- var wrappedCompilers = /* @__PURE__ */ new WeakSet();
14
- var testLoader;
15
- var loadedSass;
16
- var loadPromise;
17
- var fileCode = (value) => typeof value === "string" ? value : value.code;
18
- var playgroundPath = (url) => decodeURIComponent(url.pathname.replace(/^\/+/u, ""));
19
- var toPlaygroundUrl = (filename) => new URL(`${SCHEME}:///${filename.replace(/^\/+/u, "")}`);
20
- var basename = (path) => path.split("/").pop() || path;
21
- var scssSyntax = (filename, lang) => lang === "sass" || /\.sass$/i.test(filename) ? "indented" : "scss";
22
- var errorText = (item) => item instanceof Error ? item.message : String(item);
23
- var isScssFile = (filename) => /\.s[ac]ss$/i.test(filename);
24
- var vueSourceNeedsScss = (source) => VUE_SCSS_STYLE_RE.test(source);
25
- var resolveSassModule = async (url) => {
26
- const mod = await import(
27
- /* @vite-ignore */
28
- url
29
- );
30
- const sass = typeof mod.compileString === "function" ? mod : mod.default;
31
- if (typeof sass?.compileString !== "function") throw new Error(`Sass module at ${url} does not export compileString`);
32
- return sass;
33
- };
34
- var loadSass = () => {
35
- loadPromise ??= (testLoader ?? (() => resolveSassModule(require_cdn.SASS_CDN_URL)))().then((sass) => {
36
- loadedSass = sass;
37
- return sass;
38
- });
39
- return loadPromise;
40
- };
41
- var isScssPartial = (filename) => isScssFile(filename) && basename(filename).startsWith("_");
42
- var filesNeedScss = (files) => Object.entries(files).some(([filename, value]) => isScssFile(filename) || /\.vue$/i.test(filename) && vueSourceNeedsScss(fileCode(value)));
43
- var whenSassReady = (files, run) => {
44
- if (!filesNeedScss(files) || loadedSass) run();
45
- else loadSass().then(run);
46
- };
47
- var toPlaygroundFileMap = (files) => Object.fromEntries(Object.entries(files).map(([filename, value]) => [filename, fileCode(value)]));
48
- var formatScssError = (filename, message) => `${SCSS_ERROR_MARK} ${filename}: ${message}`;
49
- var scssFail = (filename, error) => formatScssError(filename, errorText(error));
50
- var withUnderscore = (path) => {
51
- const base = basename(path);
52
- if (base.startsWith("_")) return path;
53
- return `${path.slice(0, -base.length)}_${base}`;
54
- };
55
- var matchFileKey = (files, path) => [
56
- path,
57
- path.startsWith("src/") ? path : `src/${path}`,
58
- path.replace(/^src\//u, "")
59
- ].find((key) => files[key] !== void 0);
60
- var stylesheetCandidates = (requestPath) => {
61
- if (isScssFile(requestPath)) return [requestPath, withUnderscore(requestPath)];
62
- return STYLE_EXTS.flatMap((ext) => [
63
- `${requestPath}${ext}`,
64
- withUnderscore(`${requestPath}${ext}`),
65
- `${requestPath}/index${ext}`,
66
- withUnderscore(`${requestPath}/index${ext}`)
67
- ]);
68
- };
69
- var resolvePlaygroundStylesheet = (files, requestPath) => {
70
- const found = [...new Set(stylesheetCandidates(requestPath).map((path) => matchFileKey(files, path)).filter((key) => Boolean(key)))];
71
- if (found.length > 1) throw new Error(`Ambiguous Sass import "${requestPath}": ${found.join(", ")}`);
72
- return found[0] ?? null;
73
- };
74
- var createPlaygroundImporter = (getFiles) => ({
75
- canonicalize(url, context) {
76
- if (/^[a-zA-Z][\w+.-]*:/u.test(url) && !url.startsWith(`${SCHEME}:`)) return null;
77
- try {
78
- const resolved = resolvePlaygroundStylesheet(getFiles(), playgroundPath(new URL(url, context.containingUrl ?? toPlaygroundUrl(""))));
79
- return resolved ? toPlaygroundUrl(resolved) : null;
80
- } catch {
81
- return null;
82
- }
83
- },
84
- load(canonicalUrl) {
85
- const files = getFiles();
86
- const key = playgroundPath(canonicalUrl);
87
- return files[key] === void 0 ? null : {
88
- contents: files[key],
89
- syntax: scssSyntax(key)
90
- };
91
- }
92
- });
93
- var compileScssSource = (source, filename, sass, files, lang) => {
94
- const importer = createPlaygroundImporter(() => files);
95
- return sass.compileString(source, {
96
- syntax: scssSyntax(filename, lang),
97
- url: toPlaygroundUrl(filename),
98
- importer,
99
- importers: [importer]
100
- }).css;
101
- };
102
- var rewriteVueSfcStyles = (source, filename, parse, sass, files) => {
103
- const scssStyles = parse(source, { filename }).descriptor.styles.filter((style) => style.lang === "scss" || style.lang === "sass");
104
- if (!scssStyles.length) return {
105
- code: source,
106
- errors: []
107
- };
108
- const errors = [];
109
- let code = source;
110
- for (const style of [...scssStyles].sort((left, right) => right.loc.start.offset - left.loc.start.offset)) {
111
- const before = code.slice(0, style.loc.start.offset);
112
- const after = code.slice(style.loc.end.offset);
113
- const openStart = before.lastIndexOf("<style");
114
- if (openStart < 0) {
115
- errors.push(formatScssError(filename, "unable to locate <style> opening tag"));
116
- continue;
117
- }
118
- try {
119
- const css = compileScssSource(style.content, filename, sass, files, style.lang);
120
- code = `${before.slice(0, openStart)}${before.slice(openStart).replace(LANG_ATTR_RE, "")}${css}${after}`;
121
- } catch (error) {
122
- errors.push(scssFail(filename, error));
123
- }
124
- }
125
- return {
126
- code,
127
- errors
128
- };
129
- };
130
- var appendParseErrors = (result, errors) => errors.length ? {
131
- ...result,
132
- errors: [...result.errors, ...errors.map((item) => new Error(item))]
133
- } : result;
134
- var wrapCompiler = (compiler, getFiles) => {
135
- if (wrappedCompilers.has(compiler)) return compiler;
136
- const originalParse = compiler.parse.bind(compiler);
137
- const wrapped = { ...compiler };
138
- wrapped.parse = ((source, options) => {
139
- const filename = options?.filename || "anonymous.vue";
140
- if (!vueSourceNeedsScss(source)) return originalParse(source, options);
141
- const rewritten = loadedSass ? rewriteVueSfcStyles(source, filename, originalParse, loadedSass, getFiles()) : {
142
- code: source,
143
- errors: [formatScssError(filename, "compiler is not loaded")]
144
- };
145
- return appendParseErrors(originalParse(rewritten.errors.length ? source : rewritten.code, options), rewritten.errors);
146
- });
147
- wrappedCompilers.add(wrapped);
148
- return wrapped;
149
- };
150
- var withInjectedCss = (css, extra) => {
151
- const start = css.indexOf(INJECT_START);
152
- const end = start < 0 ? -1 : css.indexOf(INJECT_END, start);
153
- const base = (start < 0 ? css : `${css.slice(0, start)}${end >= 0 ? css.slice(end + 30) : ""}`).trimEnd();
154
- if (!extra.trim()) return base;
155
- const block = `${INJECT_START}\n${extra.trim()}\n${INJECT_END}`;
156
- return base ? `${base}\n${block}` : block;
157
- };
158
- var isStandaloneScssError = (item) => {
159
- const text = errorText(item);
160
- return text.startsWith(SCSS_ERROR_MARK) && /\.s[ac]ss:/i.test(text);
161
- };
162
- var syncScssErrors = (store, scssErrors) => {
163
- const next = [...scssErrors, ...store.errors.filter((item) => !isStandaloneScssError(item))];
164
- if (next.map(String).join("\0") === store.errors.map(String).join("\0")) return;
165
- store.errors = next;
166
- };
167
- var applyStandaloneScss = (store, sass = loadedSass) => {
168
- if (!sass) return [];
169
- const fileMap = toPlaygroundFileMap(store.files);
170
- const errors = [];
171
- const injected = [];
172
- for (const [filename, file] of Object.entries(store.files)) {
173
- if (!isScssFile(filename) || !file.compiled) continue;
174
- try {
175
- const css = compileScssSource(file.code, filename, sass, fileMap);
176
- file.compiled.css = css;
177
- file.compiled.js = EMPTY_JS;
178
- file.compiled.ssr = EMPTY_JS;
179
- if (!isScssPartial(filename) && css.trim()) injected.push(css);
180
- } catch (error) {
181
- errors.push(scssFail(filename, error));
182
- }
183
- }
184
- const main = store.files[store.mainFile];
185
- if (main?.compiled) {
186
- const next = withInjectedCss(main.compiled.css || "", injected.join("\n"));
187
- if (next !== (main.compiled.css || "")) main.compiled.css = next;
188
- }
189
- syncScssErrors(store, errors);
190
- return errors;
191
- };
192
- var bindPlaygroundScss = (store) => {
193
- if (boundStores.has(store)) return;
194
- boundStores.add(store);
195
- const getFiles = () => toPlaygroundFileMap(store.files);
196
- const installCompiler = () => {
197
- if (typeof store.compiler?.parse === "function") store.compiler = wrapCompiler(store.compiler, getFiles);
198
- };
199
- installCompiler();
200
- (0, vue.watch)(() => store.compiler, installCompiler);
201
- (0, vue.watch)(() => [
202
- store.mainFile,
203
- store.files[store.mainFile]?.compiled?.css,
204
- store.errors.map(String).join("\0"),
205
- Object.entries(store.files).filter(([filename]) => isScssFile(filename)).map(([filename, file]) => `${filename}:${file.code}`).join("\n")
206
- ].join("\0"), () => {
207
- if (loadedSass) applyStandaloneScss(store);
208
- });
209
- const originalSetFiles = store.setFiles.bind(store);
210
- store.setFiles = async (newFiles, mainFile) => {
211
- if (filesNeedScss(newFiles) && !loadedSass) await loadSass();
212
- return originalSetFiles(newFiles, mainFile);
213
- };
214
- };
215
- //#endregion
216
- Object.defineProperty(exports, "bindPlaygroundScss", {
217
- enumerable: true,
218
- get: function() {
219
- return bindPlaygroundScss;
220
- }
221
- });
222
- Object.defineProperty(exports, "compileScssSource", {
223
- enumerable: true,
224
- get: function() {
225
- return compileScssSource;
226
- }
227
- });
228
- Object.defineProperty(exports, "whenSassReady", {
229
- enumerable: true,
230
- get: function() {
231
- return whenSassReady;
232
- }
233
- });