@skyvexsoftware/stratos-sdk 0.1.15 → 0.1.16
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/vite/css-inject.js +11 -2
- package/package.json +1 -1
package/dist/vite/css-inject.js
CHANGED
|
@@ -30,12 +30,21 @@ export function cssInject() {
|
|
|
30
30
|
const jsEntry = Object.values(bundle).find((chunk) => chunk.type === "chunk" && chunk.isEntry);
|
|
31
31
|
if (!jsEntry || jsEntry.type !== "chunk")
|
|
32
32
|
return;
|
|
33
|
-
//
|
|
33
|
+
// Export the CSS as __STRATOS_PLUGIN_CSS__ so the shell's PluginHost
|
|
34
|
+
// can inject/remove it based on plugin lifecycle (mount/unmount).
|
|
35
|
+
//
|
|
36
|
+
// Also self-inject via IIFE for backwards compatibility with older shells
|
|
37
|
+
// that don't manage plugin CSS lifecycle. The IIFE tags its <style> with
|
|
38
|
+
// data-plugin-css-fallback so the new shell can remove it when it takes over.
|
|
34
39
|
const escaped = cssContent
|
|
35
40
|
.replace(/\\/g, "\\\\")
|
|
36
41
|
.replace(/`/g, "\\`")
|
|
37
42
|
.replace(/\$/g, "\\$");
|
|
38
|
-
const injection =
|
|
43
|
+
const injection = [
|
|
44
|
+
`export const __STRATOS_PLUGIN_CSS__ = \`${escaped}\`;`,
|
|
45
|
+
`(function(){try{var s=document.createElement("style");s.textContent=\`${escaped}\`;s.setAttribute("data-plugin-css-fallback","");document.head.appendChild(s)}catch(e){}})();`,
|
|
46
|
+
"",
|
|
47
|
+
].join("\n");
|
|
39
48
|
jsEntry.code = injection + jsEntry.code;
|
|
40
49
|
// Remove the separate CSS files
|
|
41
50
|
for (const name of cssAssets) {
|