diorama-js 0.1.1 → 0.2.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.cjs +112 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +7 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +112 -5
- package/dist/index.js.map +1 -1
- package/dist/react.cjs +115 -6
- package/dist/react.cjs.map +1 -1
- package/dist/react.d.cts +10 -0
- package/dist/react.d.ts +10 -0
- package/dist/react.js +115 -6
- package/dist/react.js.map +1 -1
- package/dist/svelte.cjs +113 -5
- package/dist/svelte.cjs.map +1 -1
- package/dist/svelte.d.cts +10 -0
- package/dist/svelte.d.ts +10 -0
- package/dist/svelte.js +113 -5
- package/dist/svelte.js.map +1 -1
- package/dist/vue.cjs +115 -6
- package/dist/vue.cjs.map +1 -1
- package/dist/vue.d.cts +8 -0
- package/dist/vue.d.ts +8 -0
- package/dist/vue.js +115 -6
- package/dist/vue.js.map +1 -1
- package/package.json +1 -1
package/dist/svelte.cjs
CHANGED
|
@@ -623,6 +623,7 @@ function analyzeProject(project, overrideType, overrideEntry) {
|
|
|
623
623
|
hasBareImports: hasBareImports(files),
|
|
624
624
|
isVite
|
|
625
625
|
});
|
|
626
|
+
const usesTailwind = usesTailwindCSS(files);
|
|
626
627
|
return {
|
|
627
628
|
type,
|
|
628
629
|
entryPoint: htmlEntry,
|
|
@@ -631,7 +632,8 @@ function analyzeProject(project, overrideType, overrideEntry) {
|
|
|
631
632
|
hasJSX,
|
|
632
633
|
hasTypeScript,
|
|
633
634
|
jsEntryPoint: jsEntry,
|
|
634
|
-
isVite
|
|
635
|
+
isVite,
|
|
636
|
+
usesTailwind
|
|
635
637
|
};
|
|
636
638
|
}
|
|
637
639
|
function detectProjectType(input) {
|
|
@@ -653,6 +655,17 @@ function hasBareImports(files) {
|
|
|
653
655
|
}
|
|
654
656
|
return false;
|
|
655
657
|
}
|
|
658
|
+
function usesTailwindCSS(files) {
|
|
659
|
+
for (const [path, content] of files) {
|
|
660
|
+
if (/(?:^|\/)tailwind\.config\.(?:js|cjs|mjs|ts)$/.test(path)) {
|
|
661
|
+
return true;
|
|
662
|
+
}
|
|
663
|
+
if (path.endsWith(".css") && /@tailwind\b|@apply\b/.test(content)) {
|
|
664
|
+
return true;
|
|
665
|
+
}
|
|
666
|
+
}
|
|
667
|
+
return false;
|
|
668
|
+
}
|
|
656
669
|
|
|
657
670
|
// src/core/sandbox.ts
|
|
658
671
|
function buildErrorHTML(message) {
|
|
@@ -1737,20 +1750,25 @@ var ASSET_IMPORT_EXTENSIONS = {
|
|
|
1737
1750
|
".otf": "font/otf"
|
|
1738
1751
|
};
|
|
1739
1752
|
function assembleHTML(options) {
|
|
1740
|
-
const { project, config, transformedFiles, cdnProvider } = options;
|
|
1753
|
+
const { project, config, transformedFiles, cdnProvider, tailwind = "auto" } = options;
|
|
1741
1754
|
const files = transformedFiles ?? project.files;
|
|
1755
|
+
let result;
|
|
1742
1756
|
switch (config.type) {
|
|
1743
1757
|
case "static":
|
|
1744
|
-
|
|
1758
|
+
result = assembleStatic(files, project, config);
|
|
1759
|
+
break;
|
|
1745
1760
|
case "static-esm":
|
|
1746
1761
|
case "jsx":
|
|
1747
1762
|
case "typescript":
|
|
1748
1763
|
case "jsx-typescript":
|
|
1749
1764
|
case "vite":
|
|
1750
|
-
|
|
1765
|
+
result = assembleESM(files, project, config, cdnProvider);
|
|
1766
|
+
break;
|
|
1751
1767
|
default:
|
|
1752
1768
|
throw new AssemblyError(`Unsupported project type: ${config.type}`);
|
|
1753
1769
|
}
|
|
1770
|
+
result.html = applyTailwindRuntime(result.html, project, config, tailwind);
|
|
1771
|
+
return result;
|
|
1754
1772
|
}
|
|
1755
1773
|
function assembleStatic(files, project, config) {
|
|
1756
1774
|
let html = files.get(config.entryPoint);
|
|
@@ -2076,6 +2094,94 @@ ${css}`);
|
|
|
2076
2094
|
}
|
|
2077
2095
|
return { css: cssChunks.join("\n\n"), links };
|
|
2078
2096
|
}
|
|
2097
|
+
var TAILWIND_DIRECTIVE_RE = /@tailwind\b|@apply\b/;
|
|
2098
|
+
var TAILWIND_CDN_URL = "https://cdn.tailwindcss.com";
|
|
2099
|
+
function hasTailwindDirectives(css) {
|
|
2100
|
+
return TAILWIND_DIRECTIVE_RE.test(css);
|
|
2101
|
+
}
|
|
2102
|
+
function applyTailwindRuntime(html, project, config, tailwind) {
|
|
2103
|
+
const enabled = tailwind === true || tailwind === "auto" && (config.usesTailwind ?? usesTailwindCSS(project.files));
|
|
2104
|
+
if (!enabled) return html;
|
|
2105
|
+
html = html.replace(
|
|
2106
|
+
/<style>([\s\S]*?)<\/style>/g,
|
|
2107
|
+
(match, css) => hasTailwindDirectives(css) ? `<style type="text/tailwindcss">${css}</style>` : match
|
|
2108
|
+
);
|
|
2109
|
+
let injection = `<script src="${TAILWIND_CDN_URL}"></script>`;
|
|
2110
|
+
const configObject = extractTailwindConfig(project.files);
|
|
2111
|
+
if (configObject) {
|
|
2112
|
+
injection += `
|
|
2113
|
+
<script>tailwind.config = ${configObject};</script>`;
|
|
2114
|
+
}
|
|
2115
|
+
return injectIntoHead(html, injection);
|
|
2116
|
+
}
|
|
2117
|
+
function extractTailwindConfig(files) {
|
|
2118
|
+
let source;
|
|
2119
|
+
for (const [path, content] of files) {
|
|
2120
|
+
if (/(?:^|\/)tailwind\.config\.(?:js|cjs|mjs|ts)$/.test(path)) {
|
|
2121
|
+
source = content;
|
|
2122
|
+
break;
|
|
2123
|
+
}
|
|
2124
|
+
}
|
|
2125
|
+
if (!source) return null;
|
|
2126
|
+
const object = extractBalancedObject(source);
|
|
2127
|
+
if (!object || !isSafeConfigObject(object)) return null;
|
|
2128
|
+
return object;
|
|
2129
|
+
}
|
|
2130
|
+
function extractBalancedObject(source) {
|
|
2131
|
+
const opener = source.match(/(?:export\s+default|module\.exports\s*=)\s*\{/);
|
|
2132
|
+
if (!opener || opener.index === void 0) return null;
|
|
2133
|
+
const start = opener.index + opener[0].length - 1;
|
|
2134
|
+
let depth = 0;
|
|
2135
|
+
let str = null;
|
|
2136
|
+
let lineComment = false;
|
|
2137
|
+
let blockComment = false;
|
|
2138
|
+
for (let i = start; i < source.length; i++) {
|
|
2139
|
+
const c = source[i];
|
|
2140
|
+
const n = source[i + 1];
|
|
2141
|
+
if (lineComment) {
|
|
2142
|
+
if (c === "\n") lineComment = false;
|
|
2143
|
+
continue;
|
|
2144
|
+
}
|
|
2145
|
+
if (blockComment) {
|
|
2146
|
+
if (c === "*" && n === "/") {
|
|
2147
|
+
blockComment = false;
|
|
2148
|
+
i++;
|
|
2149
|
+
}
|
|
2150
|
+
continue;
|
|
2151
|
+
}
|
|
2152
|
+
if (str) {
|
|
2153
|
+
if (c === "\\") {
|
|
2154
|
+
i++;
|
|
2155
|
+
continue;
|
|
2156
|
+
}
|
|
2157
|
+
if (c === str) str = null;
|
|
2158
|
+
continue;
|
|
2159
|
+
}
|
|
2160
|
+
if (c === "/" && n === "/") {
|
|
2161
|
+
lineComment = true;
|
|
2162
|
+
i++;
|
|
2163
|
+
continue;
|
|
2164
|
+
}
|
|
2165
|
+
if (c === "/" && n === "*") {
|
|
2166
|
+
blockComment = true;
|
|
2167
|
+
i++;
|
|
2168
|
+
continue;
|
|
2169
|
+
}
|
|
2170
|
+
if (c === '"' || c === "'" || c === "`") {
|
|
2171
|
+
str = c;
|
|
2172
|
+
continue;
|
|
2173
|
+
}
|
|
2174
|
+
if (c === "{") depth++;
|
|
2175
|
+
else if (c === "}") {
|
|
2176
|
+
depth--;
|
|
2177
|
+
if (depth === 0) return source.slice(start, i + 1);
|
|
2178
|
+
}
|
|
2179
|
+
}
|
|
2180
|
+
return null;
|
|
2181
|
+
}
|
|
2182
|
+
function isSafeConfigObject(object) {
|
|
2183
|
+
return !(/\brequire\s*\(/.test(object) || /\bimport\b/.test(object) || /=>/.test(object) || /\bfunction\b/.test(object) || /`/.test(object) || /\bprocess\b/.test(object) || /\b__dirname\b|\b__filename\b/.test(object));
|
|
2184
|
+
}
|
|
2079
2185
|
function injectImportMetaEnv(files) {
|
|
2080
2186
|
const shim = `if(!import.meta.env){Object.defineProperty(import.meta,'env',{value:{MODE:'production',BASE_URL:'/',PROD:true,DEV:false,SSR:false}});}`;
|
|
2081
2187
|
for (const [path, content] of files) {
|
|
@@ -2186,7 +2292,8 @@ var Diorama = class {
|
|
|
2186
2292
|
project,
|
|
2187
2293
|
config,
|
|
2188
2294
|
transformedFiles: files,
|
|
2189
|
-
cdnProvider: this.options.cdnProvider
|
|
2295
|
+
cdnProvider: this.options.cdnProvider,
|
|
2296
|
+
tailwind: options.tailwind ?? "auto"
|
|
2190
2297
|
});
|
|
2191
2298
|
return { html: html2, usesESM: usesESM2, repoName: repoName2 };
|
|
2192
2299
|
};
|
|
@@ -2306,6 +2413,7 @@ function dioramaAction(node, params) {
|
|
|
2306
2413
|
height: opts.height ?? "500px",
|
|
2307
2414
|
frame: opts.frame,
|
|
2308
2415
|
expand: opts.expand,
|
|
2416
|
+
tailwind: opts.tailwind,
|
|
2309
2417
|
onLoad: opts.onLoad,
|
|
2310
2418
|
onError: opts.onError
|
|
2311
2419
|
});
|