@servlyadmin/runtime-core 0.1.37 → 0.1.38
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/chunk-5O72RMSO.js +305 -0
- package/dist/index.cjs +197 -14
- package/dist/index.js +40 -5
- package/dist/{tailwind-DMUQ7TOT.js → tailwind-4IK6HZC6.js} +15 -3
- package/package.json +1 -1
- package/dist/chunk-SMHCCKAZ.js +0 -157
- package/dist/index.d.cts +0 -1975
- package/dist/index.d.ts +0 -1975
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
// src/tailwind.ts
|
|
2
|
+
var DEFAULT_TAILWIND_CDN = "https://cdn.tailwindcss.com";
|
|
3
|
+
var TAILWIND_CACHE_KEY = "servly-tailwind-loaded";
|
|
4
|
+
var tailwindInjected = false;
|
|
5
|
+
var tailwindScript = null;
|
|
6
|
+
var foucStyleElement = null;
|
|
7
|
+
var tailwindReadyPromise = null;
|
|
8
|
+
var tailwindReadyResolve = null;
|
|
9
|
+
var FOUC_PREVENTION_CSS = `
|
|
10
|
+
.servly-component:not(.servly-ready),
|
|
11
|
+
[data-servly-id]:not(.servly-ready) {
|
|
12
|
+
visibility: hidden !important;
|
|
13
|
+
}
|
|
14
|
+
.servly-fouc-hidden {
|
|
15
|
+
visibility: hidden !important;
|
|
16
|
+
}
|
|
17
|
+
`;
|
|
18
|
+
function wasTailwindPreviouslyLoaded() {
|
|
19
|
+
if (typeof localStorage === "undefined") return false;
|
|
20
|
+
try {
|
|
21
|
+
return localStorage.getItem(TAILWIND_CACHE_KEY) === "true";
|
|
22
|
+
} catch {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
function markTailwindAsLoaded() {
|
|
27
|
+
if (typeof localStorage === "undefined") return;
|
|
28
|
+
try {
|
|
29
|
+
localStorage.setItem(TAILWIND_CACHE_KEY, "true");
|
|
30
|
+
} catch {
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
function preloadTailwind(cdnUrl, usePlayCdn) {
|
|
34
|
+
if (typeof document === "undefined") return;
|
|
35
|
+
if (document.querySelector("link[data-servly-tailwind-preload]")) return;
|
|
36
|
+
const url = cdnUrl || DEFAULT_TAILWIND_CDN;
|
|
37
|
+
const fullUrl = usePlayCdn ? `${url}?plugins=forms,typography,aspect-ratio` : url;
|
|
38
|
+
const link = document.createElement("link");
|
|
39
|
+
link.rel = "preload";
|
|
40
|
+
link.as = "script";
|
|
41
|
+
link.href = fullUrl;
|
|
42
|
+
link.setAttribute("data-servly-tailwind-preload", "true");
|
|
43
|
+
if (document.head.firstChild) {
|
|
44
|
+
document.head.insertBefore(link, document.head.firstChild);
|
|
45
|
+
} else {
|
|
46
|
+
document.head.appendChild(link);
|
|
47
|
+
}
|
|
48
|
+
const dnsPrefetch = document.createElement("link");
|
|
49
|
+
dnsPrefetch.rel = "dns-prefetch";
|
|
50
|
+
dnsPrefetch.href = "https://cdn.tailwindcss.com";
|
|
51
|
+
document.head.appendChild(dnsPrefetch);
|
|
52
|
+
}
|
|
53
|
+
function preventFOUC() {
|
|
54
|
+
if (typeof document === "undefined") return;
|
|
55
|
+
if (foucStyleElement) return;
|
|
56
|
+
const wasLoaded = wasTailwindPreviouslyLoaded();
|
|
57
|
+
foucStyleElement = document.createElement("style");
|
|
58
|
+
foucStyleElement.id = "servly-fouc-prevention";
|
|
59
|
+
foucStyleElement.textContent = FOUC_PREVENTION_CSS;
|
|
60
|
+
if (document.head.firstChild) {
|
|
61
|
+
document.head.insertBefore(foucStyleElement, document.head.firstChild);
|
|
62
|
+
} else {
|
|
63
|
+
document.head.appendChild(foucStyleElement);
|
|
64
|
+
}
|
|
65
|
+
if (wasLoaded) {
|
|
66
|
+
setTimeout(() => {
|
|
67
|
+
if (window.tailwind) {
|
|
68
|
+
removeFOUCPrevention();
|
|
69
|
+
}
|
|
70
|
+
}, 100);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
function removeFOUCPrevention() {
|
|
74
|
+
if (foucStyleElement && foucStyleElement.parentNode) {
|
|
75
|
+
foucStyleElement.parentNode.removeChild(foucStyleElement);
|
|
76
|
+
foucStyleElement = null;
|
|
77
|
+
}
|
|
78
|
+
if (typeof document !== "undefined") {
|
|
79
|
+
document.querySelectorAll(".servly-component, [data-servly-id]").forEach((el) => {
|
|
80
|
+
el.classList.add("servly-ready");
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
function markElementReady(element) {
|
|
85
|
+
element.classList.add("servly-ready");
|
|
86
|
+
element.classList.remove("servly-fouc-hidden");
|
|
87
|
+
}
|
|
88
|
+
function isTailwindReady() {
|
|
89
|
+
if (typeof window === "undefined") return false;
|
|
90
|
+
return tailwindInjected && !!window.tailwind;
|
|
91
|
+
}
|
|
92
|
+
function waitForTailwind() {
|
|
93
|
+
if (isTailwindReady()) {
|
|
94
|
+
return Promise.resolve();
|
|
95
|
+
}
|
|
96
|
+
if (tailwindReadyPromise) {
|
|
97
|
+
return tailwindReadyPromise;
|
|
98
|
+
}
|
|
99
|
+
tailwindReadyPromise = new Promise((resolve) => {
|
|
100
|
+
tailwindReadyResolve = resolve;
|
|
101
|
+
});
|
|
102
|
+
return tailwindReadyPromise;
|
|
103
|
+
}
|
|
104
|
+
function injectTailwind(config = {}) {
|
|
105
|
+
return new Promise((resolve, reject) => {
|
|
106
|
+
if (tailwindInjected && tailwindScript) {
|
|
107
|
+
resolve();
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
if (typeof document === "undefined") {
|
|
111
|
+
resolve();
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
const {
|
|
115
|
+
cdnUrl = DEFAULT_TAILWIND_CDN,
|
|
116
|
+
config: tailwindConfig,
|
|
117
|
+
plugins = [],
|
|
118
|
+
usePlayCdn = false,
|
|
119
|
+
onReady,
|
|
120
|
+
onError,
|
|
121
|
+
preventFOUC: shouldPreventFOUC = true,
|
|
122
|
+
enablePreload = true
|
|
123
|
+
} = config;
|
|
124
|
+
if (shouldPreventFOUC) {
|
|
125
|
+
preventFOUC();
|
|
126
|
+
}
|
|
127
|
+
if (enablePreload) {
|
|
128
|
+
preloadTailwind(cdnUrl, usePlayCdn);
|
|
129
|
+
}
|
|
130
|
+
if (window.tailwind) {
|
|
131
|
+
tailwindInjected = true;
|
|
132
|
+
markTailwindAsLoaded();
|
|
133
|
+
if (shouldPreventFOUC) {
|
|
134
|
+
removeFOUCPrevention();
|
|
135
|
+
}
|
|
136
|
+
if (tailwindReadyResolve) {
|
|
137
|
+
tailwindReadyResolve();
|
|
138
|
+
tailwindReadyResolve = null;
|
|
139
|
+
}
|
|
140
|
+
config.onReady?.();
|
|
141
|
+
resolve();
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
const script = document.createElement("script");
|
|
145
|
+
script.src = usePlayCdn ? `${cdnUrl}?plugins=forms,typography,aspect-ratio` : cdnUrl;
|
|
146
|
+
script.async = true;
|
|
147
|
+
script.crossOrigin = "anonymous";
|
|
148
|
+
script.onload = () => {
|
|
149
|
+
tailwindInjected = true;
|
|
150
|
+
tailwindScript = script;
|
|
151
|
+
markTailwindAsLoaded();
|
|
152
|
+
if (tailwindConfig && window.tailwind) {
|
|
153
|
+
window.tailwind.config = tailwindConfig;
|
|
154
|
+
}
|
|
155
|
+
const delay = wasTailwindPreviouslyLoaded() ? 10 : 50;
|
|
156
|
+
setTimeout(() => {
|
|
157
|
+
if (shouldPreventFOUC) {
|
|
158
|
+
removeFOUCPrevention();
|
|
159
|
+
}
|
|
160
|
+
if (tailwindReadyResolve) {
|
|
161
|
+
tailwindReadyResolve();
|
|
162
|
+
tailwindReadyResolve = null;
|
|
163
|
+
}
|
|
164
|
+
onReady?.();
|
|
165
|
+
resolve();
|
|
166
|
+
}, delay);
|
|
167
|
+
};
|
|
168
|
+
script.onerror = (event) => {
|
|
169
|
+
const error = new Error(`Failed to load Tailwind CSS from ${cdnUrl}`);
|
|
170
|
+
if (shouldPreventFOUC) {
|
|
171
|
+
removeFOUCPrevention();
|
|
172
|
+
}
|
|
173
|
+
if (tailwindReadyResolve) {
|
|
174
|
+
tailwindReadyResolve();
|
|
175
|
+
tailwindReadyResolve = null;
|
|
176
|
+
}
|
|
177
|
+
onError?.(error);
|
|
178
|
+
reject(error);
|
|
179
|
+
};
|
|
180
|
+
document.head.appendChild(script);
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
function removeTailwind() {
|
|
184
|
+
if (tailwindScript && tailwindScript.parentNode) {
|
|
185
|
+
tailwindScript.parentNode.removeChild(tailwindScript);
|
|
186
|
+
tailwindScript = null;
|
|
187
|
+
tailwindInjected = false;
|
|
188
|
+
tailwindReadyPromise = null;
|
|
189
|
+
tailwindReadyResolve = null;
|
|
190
|
+
delete window.tailwind;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
function isTailwindLoaded() {
|
|
194
|
+
return tailwindInjected || !!window.tailwind;
|
|
195
|
+
}
|
|
196
|
+
function getTailwind() {
|
|
197
|
+
return window.tailwind;
|
|
198
|
+
}
|
|
199
|
+
function updateTailwindConfig(config) {
|
|
200
|
+
if (window.tailwind) {
|
|
201
|
+
window.tailwind.config = {
|
|
202
|
+
...window.tailwind.config,
|
|
203
|
+
...config
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
function addCustomStyles(css, id) {
|
|
208
|
+
if (typeof document === "undefined") {
|
|
209
|
+
throw new Error("addCustomStyles can only be used in browser environment");
|
|
210
|
+
}
|
|
211
|
+
const styleId = id || `servly-custom-styles-${Date.now()}`;
|
|
212
|
+
let existingStyle = document.getElementById(styleId);
|
|
213
|
+
if (existingStyle) {
|
|
214
|
+
existingStyle.textContent = css;
|
|
215
|
+
return existingStyle;
|
|
216
|
+
}
|
|
217
|
+
const style = document.createElement("style");
|
|
218
|
+
style.id = styleId;
|
|
219
|
+
style.textContent = css;
|
|
220
|
+
document.head.appendChild(style);
|
|
221
|
+
return style;
|
|
222
|
+
}
|
|
223
|
+
function removeCustomStyles(id) {
|
|
224
|
+
if (typeof document === "undefined") return;
|
|
225
|
+
const style = document.getElementById(id);
|
|
226
|
+
if (style && style.parentNode) {
|
|
227
|
+
style.parentNode.removeChild(style);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
var DEFAULT_SERVLY_TAILWIND_CONFIG = {
|
|
231
|
+
theme: {
|
|
232
|
+
extend: {
|
|
233
|
+
// Add any Servly-specific theme extensions here
|
|
234
|
+
}
|
|
235
|
+
},
|
|
236
|
+
// Safelist common dynamic classes
|
|
237
|
+
safelist: [
|
|
238
|
+
// Spacing
|
|
239
|
+
{ pattern: /^(p|m|gap)-/ },
|
|
240
|
+
// Sizing
|
|
241
|
+
{ pattern: /^(w|h|min-w|min-h|max-w|max-h)-/ },
|
|
242
|
+
// Flexbox
|
|
243
|
+
{ pattern: /^(flex|justify|items|self)-/ },
|
|
244
|
+
// Grid
|
|
245
|
+
{ pattern: /^(grid|col|row)-/ },
|
|
246
|
+
// Colors
|
|
247
|
+
{ pattern: /^(bg|text|border|ring)-/ },
|
|
248
|
+
// Typography
|
|
249
|
+
{ pattern: /^(font|text|leading|tracking)-/ },
|
|
250
|
+
// Borders
|
|
251
|
+
{ pattern: /^(rounded|border)-/ },
|
|
252
|
+
// Effects
|
|
253
|
+
{ pattern: /^(shadow|opacity|blur)-/ },
|
|
254
|
+
// Transforms
|
|
255
|
+
{ pattern: /^(scale|rotate|translate|skew)-/ },
|
|
256
|
+
// Transitions
|
|
257
|
+
{ pattern: /^(transition|duration|ease|delay)-/ }
|
|
258
|
+
]
|
|
259
|
+
};
|
|
260
|
+
async function initServlyTailwind(customConfig) {
|
|
261
|
+
const config = customConfig ? { ...DEFAULT_SERVLY_TAILWIND_CONFIG, ...customConfig } : DEFAULT_SERVLY_TAILWIND_CONFIG;
|
|
262
|
+
await injectTailwind({
|
|
263
|
+
config,
|
|
264
|
+
usePlayCdn: true
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
var injectTailwindStyles = initServlyTailwind;
|
|
268
|
+
var tailwind_default = {
|
|
269
|
+
injectTailwind,
|
|
270
|
+
injectTailwindStyles,
|
|
271
|
+
removeTailwind,
|
|
272
|
+
isTailwindLoaded,
|
|
273
|
+
isTailwindReady,
|
|
274
|
+
waitForTailwind,
|
|
275
|
+
getTailwind,
|
|
276
|
+
updateTailwindConfig,
|
|
277
|
+
addCustomStyles,
|
|
278
|
+
removeCustomStyles,
|
|
279
|
+
initServlyTailwind,
|
|
280
|
+
preventFOUC,
|
|
281
|
+
removeFOUCPrevention,
|
|
282
|
+
markElementReady,
|
|
283
|
+
preloadTailwind,
|
|
284
|
+
DEFAULT_SERVLY_TAILWIND_CONFIG
|
|
285
|
+
};
|
|
286
|
+
|
|
287
|
+
export {
|
|
288
|
+
preloadTailwind,
|
|
289
|
+
preventFOUC,
|
|
290
|
+
removeFOUCPrevention,
|
|
291
|
+
markElementReady,
|
|
292
|
+
isTailwindReady,
|
|
293
|
+
waitForTailwind,
|
|
294
|
+
injectTailwind,
|
|
295
|
+
removeTailwind,
|
|
296
|
+
isTailwindLoaded,
|
|
297
|
+
getTailwind,
|
|
298
|
+
updateTailwindConfig,
|
|
299
|
+
addCustomStyles,
|
|
300
|
+
removeCustomStyles,
|
|
301
|
+
DEFAULT_SERVLY_TAILWIND_CONFIG,
|
|
302
|
+
initServlyTailwind,
|
|
303
|
+
injectTailwindStyles,
|
|
304
|
+
tailwind_default
|
|
305
|
+
};
|
package/dist/index.cjs
CHANGED
|
@@ -31,10 +31,102 @@ __export(tailwind_exports, {
|
|
|
31
31
|
injectTailwind: () => injectTailwind,
|
|
32
32
|
injectTailwindStyles: () => injectTailwindStyles,
|
|
33
33
|
isTailwindLoaded: () => isTailwindLoaded,
|
|
34
|
+
isTailwindReady: () => isTailwindReady,
|
|
35
|
+
markElementReady: () => markElementReady,
|
|
36
|
+
preloadTailwind: () => preloadTailwind,
|
|
37
|
+
preventFOUC: () => preventFOUC,
|
|
34
38
|
removeCustomStyles: () => removeCustomStyles,
|
|
39
|
+
removeFOUCPrevention: () => removeFOUCPrevention,
|
|
35
40
|
removeTailwind: () => removeTailwind,
|
|
36
|
-
updateTailwindConfig: () => updateTailwindConfig
|
|
41
|
+
updateTailwindConfig: () => updateTailwindConfig,
|
|
42
|
+
waitForTailwind: () => waitForTailwind
|
|
37
43
|
});
|
|
44
|
+
function wasTailwindPreviouslyLoaded() {
|
|
45
|
+
if (typeof localStorage === "undefined") return false;
|
|
46
|
+
try {
|
|
47
|
+
return localStorage.getItem(TAILWIND_CACHE_KEY) === "true";
|
|
48
|
+
} catch {
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
function markTailwindAsLoaded() {
|
|
53
|
+
if (typeof localStorage === "undefined") return;
|
|
54
|
+
try {
|
|
55
|
+
localStorage.setItem(TAILWIND_CACHE_KEY, "true");
|
|
56
|
+
} catch {
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
function preloadTailwind(cdnUrl, usePlayCdn) {
|
|
60
|
+
if (typeof document === "undefined") return;
|
|
61
|
+
if (document.querySelector("link[data-servly-tailwind-preload]")) return;
|
|
62
|
+
const url = cdnUrl || DEFAULT_TAILWIND_CDN;
|
|
63
|
+
const fullUrl = usePlayCdn ? `${url}?plugins=forms,typography,aspect-ratio` : url;
|
|
64
|
+
const link = document.createElement("link");
|
|
65
|
+
link.rel = "preload";
|
|
66
|
+
link.as = "script";
|
|
67
|
+
link.href = fullUrl;
|
|
68
|
+
link.setAttribute("data-servly-tailwind-preload", "true");
|
|
69
|
+
if (document.head.firstChild) {
|
|
70
|
+
document.head.insertBefore(link, document.head.firstChild);
|
|
71
|
+
} else {
|
|
72
|
+
document.head.appendChild(link);
|
|
73
|
+
}
|
|
74
|
+
const dnsPrefetch = document.createElement("link");
|
|
75
|
+
dnsPrefetch.rel = "dns-prefetch";
|
|
76
|
+
dnsPrefetch.href = "https://cdn.tailwindcss.com";
|
|
77
|
+
document.head.appendChild(dnsPrefetch);
|
|
78
|
+
}
|
|
79
|
+
function preventFOUC() {
|
|
80
|
+
if (typeof document === "undefined") return;
|
|
81
|
+
if (foucStyleElement) return;
|
|
82
|
+
const wasLoaded = wasTailwindPreviouslyLoaded();
|
|
83
|
+
foucStyleElement = document.createElement("style");
|
|
84
|
+
foucStyleElement.id = "servly-fouc-prevention";
|
|
85
|
+
foucStyleElement.textContent = FOUC_PREVENTION_CSS;
|
|
86
|
+
if (document.head.firstChild) {
|
|
87
|
+
document.head.insertBefore(foucStyleElement, document.head.firstChild);
|
|
88
|
+
} else {
|
|
89
|
+
document.head.appendChild(foucStyleElement);
|
|
90
|
+
}
|
|
91
|
+
if (wasLoaded) {
|
|
92
|
+
setTimeout(() => {
|
|
93
|
+
if (window.tailwind) {
|
|
94
|
+
removeFOUCPrevention();
|
|
95
|
+
}
|
|
96
|
+
}, 100);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
function removeFOUCPrevention() {
|
|
100
|
+
if (foucStyleElement && foucStyleElement.parentNode) {
|
|
101
|
+
foucStyleElement.parentNode.removeChild(foucStyleElement);
|
|
102
|
+
foucStyleElement = null;
|
|
103
|
+
}
|
|
104
|
+
if (typeof document !== "undefined") {
|
|
105
|
+
document.querySelectorAll(".servly-component, [data-servly-id]").forEach((el) => {
|
|
106
|
+
el.classList.add("servly-ready");
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
function markElementReady(element) {
|
|
111
|
+
element.classList.add("servly-ready");
|
|
112
|
+
element.classList.remove("servly-fouc-hidden");
|
|
113
|
+
}
|
|
114
|
+
function isTailwindReady() {
|
|
115
|
+
if (typeof window === "undefined") return false;
|
|
116
|
+
return tailwindInjected && !!window.tailwind;
|
|
117
|
+
}
|
|
118
|
+
function waitForTailwind() {
|
|
119
|
+
if (isTailwindReady()) {
|
|
120
|
+
return Promise.resolve();
|
|
121
|
+
}
|
|
122
|
+
if (tailwindReadyPromise) {
|
|
123
|
+
return tailwindReadyPromise;
|
|
124
|
+
}
|
|
125
|
+
tailwindReadyPromise = new Promise((resolve) => {
|
|
126
|
+
tailwindReadyResolve = resolve;
|
|
127
|
+
});
|
|
128
|
+
return tailwindReadyPromise;
|
|
129
|
+
}
|
|
38
130
|
function injectTailwind(config = {}) {
|
|
39
131
|
return new Promise((resolve, reject) => {
|
|
40
132
|
if (tailwindInjected && tailwindScript) {
|
|
@@ -45,34 +137,69 @@ function injectTailwind(config = {}) {
|
|
|
45
137
|
resolve();
|
|
46
138
|
return;
|
|
47
139
|
}
|
|
48
|
-
if (window.tailwind) {
|
|
49
|
-
tailwindInjected = true;
|
|
50
|
-
config.onReady?.();
|
|
51
|
-
resolve();
|
|
52
|
-
return;
|
|
53
|
-
}
|
|
54
140
|
const {
|
|
55
141
|
cdnUrl = DEFAULT_TAILWIND_CDN,
|
|
56
142
|
config: tailwindConfig,
|
|
57
143
|
plugins = [],
|
|
58
144
|
usePlayCdn = false,
|
|
59
145
|
onReady,
|
|
60
|
-
onError
|
|
146
|
+
onError,
|
|
147
|
+
preventFOUC: shouldPreventFOUC = true,
|
|
148
|
+
enablePreload = true
|
|
61
149
|
} = config;
|
|
150
|
+
if (shouldPreventFOUC) {
|
|
151
|
+
preventFOUC();
|
|
152
|
+
}
|
|
153
|
+
if (enablePreload) {
|
|
154
|
+
preloadTailwind(cdnUrl, usePlayCdn);
|
|
155
|
+
}
|
|
156
|
+
if (window.tailwind) {
|
|
157
|
+
tailwindInjected = true;
|
|
158
|
+
markTailwindAsLoaded();
|
|
159
|
+
if (shouldPreventFOUC) {
|
|
160
|
+
removeFOUCPrevention();
|
|
161
|
+
}
|
|
162
|
+
if (tailwindReadyResolve) {
|
|
163
|
+
tailwindReadyResolve();
|
|
164
|
+
tailwindReadyResolve = null;
|
|
165
|
+
}
|
|
166
|
+
config.onReady?.();
|
|
167
|
+
resolve();
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
62
170
|
const script = document.createElement("script");
|
|
63
171
|
script.src = usePlayCdn ? `${cdnUrl}?plugins=forms,typography,aspect-ratio` : cdnUrl;
|
|
64
172
|
script.async = true;
|
|
173
|
+
script.crossOrigin = "anonymous";
|
|
65
174
|
script.onload = () => {
|
|
66
175
|
tailwindInjected = true;
|
|
67
176
|
tailwindScript = script;
|
|
177
|
+
markTailwindAsLoaded();
|
|
68
178
|
if (tailwindConfig && window.tailwind) {
|
|
69
179
|
window.tailwind.config = tailwindConfig;
|
|
70
180
|
}
|
|
71
|
-
|
|
72
|
-
|
|
181
|
+
const delay = wasTailwindPreviouslyLoaded() ? 10 : 50;
|
|
182
|
+
setTimeout(() => {
|
|
183
|
+
if (shouldPreventFOUC) {
|
|
184
|
+
removeFOUCPrevention();
|
|
185
|
+
}
|
|
186
|
+
if (tailwindReadyResolve) {
|
|
187
|
+
tailwindReadyResolve();
|
|
188
|
+
tailwindReadyResolve = null;
|
|
189
|
+
}
|
|
190
|
+
onReady?.();
|
|
191
|
+
resolve();
|
|
192
|
+
}, delay);
|
|
73
193
|
};
|
|
74
194
|
script.onerror = (event) => {
|
|
75
195
|
const error = new Error(`Failed to load Tailwind CSS from ${cdnUrl}`);
|
|
196
|
+
if (shouldPreventFOUC) {
|
|
197
|
+
removeFOUCPrevention();
|
|
198
|
+
}
|
|
199
|
+
if (tailwindReadyResolve) {
|
|
200
|
+
tailwindReadyResolve();
|
|
201
|
+
tailwindReadyResolve = null;
|
|
202
|
+
}
|
|
76
203
|
onError?.(error);
|
|
77
204
|
reject(error);
|
|
78
205
|
};
|
|
@@ -84,6 +211,8 @@ function removeTailwind() {
|
|
|
84
211
|
tailwindScript.parentNode.removeChild(tailwindScript);
|
|
85
212
|
tailwindScript = null;
|
|
86
213
|
tailwindInjected = false;
|
|
214
|
+
tailwindReadyPromise = null;
|
|
215
|
+
tailwindReadyResolve = null;
|
|
87
216
|
delete window.tailwind;
|
|
88
217
|
}
|
|
89
218
|
}
|
|
@@ -131,13 +260,26 @@ async function initServlyTailwind(customConfig) {
|
|
|
131
260
|
usePlayCdn: true
|
|
132
261
|
});
|
|
133
262
|
}
|
|
134
|
-
var DEFAULT_TAILWIND_CDN, tailwindInjected, tailwindScript, DEFAULT_SERVLY_TAILWIND_CONFIG, injectTailwindStyles, tailwind_default;
|
|
263
|
+
var DEFAULT_TAILWIND_CDN, TAILWIND_CACHE_KEY, tailwindInjected, tailwindScript, foucStyleElement, tailwindReadyPromise, tailwindReadyResolve, FOUC_PREVENTION_CSS, DEFAULT_SERVLY_TAILWIND_CONFIG, injectTailwindStyles, tailwind_default;
|
|
135
264
|
var init_tailwind = __esm({
|
|
136
265
|
"src/tailwind.ts"() {
|
|
137
266
|
"use strict";
|
|
138
267
|
DEFAULT_TAILWIND_CDN = "https://cdn.tailwindcss.com";
|
|
268
|
+
TAILWIND_CACHE_KEY = "servly-tailwind-loaded";
|
|
139
269
|
tailwindInjected = false;
|
|
140
270
|
tailwindScript = null;
|
|
271
|
+
foucStyleElement = null;
|
|
272
|
+
tailwindReadyPromise = null;
|
|
273
|
+
tailwindReadyResolve = null;
|
|
274
|
+
FOUC_PREVENTION_CSS = `
|
|
275
|
+
.servly-component:not(.servly-ready),
|
|
276
|
+
[data-servly-id]:not(.servly-ready) {
|
|
277
|
+
visibility: hidden !important;
|
|
278
|
+
}
|
|
279
|
+
.servly-fouc-hidden {
|
|
280
|
+
visibility: hidden !important;
|
|
281
|
+
}
|
|
282
|
+
`;
|
|
141
283
|
DEFAULT_SERVLY_TAILWIND_CONFIG = {
|
|
142
284
|
theme: {
|
|
143
285
|
extend: {
|
|
@@ -174,11 +316,17 @@ var init_tailwind = __esm({
|
|
|
174
316
|
injectTailwindStyles,
|
|
175
317
|
removeTailwind,
|
|
176
318
|
isTailwindLoaded,
|
|
319
|
+
isTailwindReady,
|
|
320
|
+
waitForTailwind,
|
|
177
321
|
getTailwind,
|
|
178
322
|
updateTailwindConfig,
|
|
179
323
|
addCustomStyles,
|
|
180
324
|
removeCustomStyles,
|
|
181
325
|
initServlyTailwind,
|
|
326
|
+
preventFOUC,
|
|
327
|
+
removeFOUCPrevention,
|
|
328
|
+
markElementReady,
|
|
329
|
+
preloadTailwind,
|
|
182
330
|
DEFAULT_SERVLY_TAILWIND_CONFIG
|
|
183
331
|
};
|
|
184
332
|
}
|
|
@@ -462,16 +610,21 @@ __export(index_exports, {
|
|
|
462
610
|
isIconRegistered: () => isIconRegistered,
|
|
463
611
|
isIconSetSupported: () => isIconSetSupported,
|
|
464
612
|
isTailwindLoaded: () => isTailwindLoaded,
|
|
613
|
+
isTailwindReady: () => isTailwindReady,
|
|
465
614
|
isValidSpecifier: () => isValidSpecifier,
|
|
615
|
+
markElementReady: () => markElementReady,
|
|
466
616
|
navigateTo: () => navigateTo,
|
|
467
617
|
parseVersion: () => parseVersion,
|
|
468
618
|
prefetchComponents: () => prefetchComponents,
|
|
469
619
|
preloadIcons: () => preloadIcons,
|
|
620
|
+
preloadTailwind: () => preloadTailwind,
|
|
621
|
+
preventFOUC: () => preventFOUC,
|
|
470
622
|
processStyles: () => processStyles,
|
|
471
623
|
registerIcon: () => registerIcon,
|
|
472
624
|
registerIcons: () => registerIcons,
|
|
473
625
|
removeClass: () => removeClass,
|
|
474
626
|
removeCustomStyles: () => removeCustomStyles,
|
|
627
|
+
removeFOUCPrevention: () => removeFOUCPrevention,
|
|
475
628
|
removeLocalStorage: () => removeLocalStorage,
|
|
476
629
|
removeSessionStorage: () => removeSessionStorage,
|
|
477
630
|
removeTailwind: () => removeTailwind,
|
|
@@ -506,7 +659,8 @@ __export(index_exports, {
|
|
|
506
659
|
updateStyles: () => updateStyles,
|
|
507
660
|
updateTailwindConfig: () => updateTailwindConfig,
|
|
508
661
|
validateAssertion: () => validateAssertion,
|
|
509
|
-
validateProps: () => validateProps
|
|
662
|
+
validateProps: () => validateProps,
|
|
663
|
+
waitForTailwind: () => waitForTailwind
|
|
510
664
|
});
|
|
511
665
|
module.exports = __toCommonJS(index_exports);
|
|
512
666
|
|
|
@@ -3438,7 +3592,30 @@ function resolveComponentViewInputs(bindings, context, parentInputs) {
|
|
|
3438
3592
|
case "static":
|
|
3439
3593
|
case "value":
|
|
3440
3594
|
case "constant":
|
|
3441
|
-
|
|
3595
|
+
if (binding.value && typeof binding.value === "object" && Array.isArray(binding.value.plugins)) {
|
|
3596
|
+
const plugins = binding.value.plugins;
|
|
3597
|
+
resolved[key] = (event) => {
|
|
3598
|
+
for (const plugin of plugins) {
|
|
3599
|
+
const pluginType = plugin.type || plugin.key;
|
|
3600
|
+
if (pluginType === "executeCode" && plugin.code) {
|
|
3601
|
+
try {
|
|
3602
|
+
const fn = new Function(
|
|
3603
|
+
"event",
|
|
3604
|
+
"props",
|
|
3605
|
+
"state",
|
|
3606
|
+
"context",
|
|
3607
|
+
plugin.code
|
|
3608
|
+
);
|
|
3609
|
+
fn(event, context.props || {}, context.state || {}, context.context || {});
|
|
3610
|
+
} catch (error) {
|
|
3611
|
+
console.error("[Servly] executeCode error:", error);
|
|
3612
|
+
}
|
|
3613
|
+
}
|
|
3614
|
+
}
|
|
3615
|
+
};
|
|
3616
|
+
} else {
|
|
3617
|
+
resolved[key] = binding.value;
|
|
3618
|
+
}
|
|
3442
3619
|
break;
|
|
3443
3620
|
case "state":
|
|
3444
3621
|
if (binding.path && context.state) {
|
|
@@ -5236,16 +5413,21 @@ init_tailwind();
|
|
|
5236
5413
|
isIconRegistered,
|
|
5237
5414
|
isIconSetSupported,
|
|
5238
5415
|
isTailwindLoaded,
|
|
5416
|
+
isTailwindReady,
|
|
5239
5417
|
isValidSpecifier,
|
|
5418
|
+
markElementReady,
|
|
5240
5419
|
navigateTo,
|
|
5241
5420
|
parseVersion,
|
|
5242
5421
|
prefetchComponents,
|
|
5243
5422
|
preloadIcons,
|
|
5423
|
+
preloadTailwind,
|
|
5424
|
+
preventFOUC,
|
|
5244
5425
|
processStyles,
|
|
5245
5426
|
registerIcon,
|
|
5246
5427
|
registerIcons,
|
|
5247
5428
|
removeClass,
|
|
5248
5429
|
removeCustomStyles,
|
|
5430
|
+
removeFOUCPrevention,
|
|
5249
5431
|
removeLocalStorage,
|
|
5250
5432
|
removeSessionStorage,
|
|
5251
5433
|
removeTailwind,
|
|
@@ -5280,5 +5462,6 @@ init_tailwind();
|
|
|
5280
5462
|
updateStyles,
|
|
5281
5463
|
updateTailwindConfig,
|
|
5282
5464
|
validateAssertion,
|
|
5283
|
-
validateProps
|
|
5465
|
+
validateProps,
|
|
5466
|
+
waitForTailwind
|
|
5284
5467
|
});
|