@servlyadmin/runtime-core 0.1.39 → 0.1.41

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.
@@ -145,7 +145,8 @@ function injectTailwind(config = {}) {
145
145
  if (enablePreload) {
146
146
  preloadTailwind(cdnUrl, usePlayCdn);
147
147
  }
148
- if (window.tailwind) {
148
+ const existingScript = document.querySelector('script[src*="tailwindcss.com"]');
149
+ if (existingScript || window.tailwind) {
149
150
  tailwindInjected = true;
150
151
  markTailwindAsLoaded();
151
152
  if (shouldPreventFOUC) {
@@ -209,7 +210,32 @@ function removeTailwind() {
209
210
  }
210
211
  }
211
212
  function isTailwindLoaded() {
212
- return tailwindInjected || !!window.tailwind;
213
+ if (typeof window === "undefined") return false;
214
+ if (window.tailwind) {
215
+ return true;
216
+ }
217
+ if (typeof document !== "undefined") {
218
+ try {
219
+ for (const sheet of document.styleSheets) {
220
+ try {
221
+ const rules = sheet.cssRules || sheet.rules;
222
+ if (rules) {
223
+ for (let i = 0; i < Math.min(rules.length, 100); i++) {
224
+ const rule = rules[i];
225
+ if (rule instanceof CSSStyleRule) {
226
+ if (rule.selectorText?.match(/^\.(flex|grid|p-|m-|w-|h-|bg-|text-)/)) {
227
+ return true;
228
+ }
229
+ }
230
+ }
231
+ }
232
+ } catch {
233
+ }
234
+ }
235
+ } catch {
236
+ }
237
+ }
238
+ return tailwindInjected;
213
239
  }
214
240
  function getTailwind() {
215
241
  return window.tailwind;
@@ -222,6 +248,40 @@ function updateTailwindConfig(config) {
222
248
  };
223
249
  }
224
250
  }
251
+ function refreshTailwind() {
252
+ if (typeof window === "undefined" || typeof document === "undefined") return;
253
+ const tw = window.tailwind;
254
+ if (tw && typeof tw.refresh === "function") {
255
+ tw.refresh();
256
+ return;
257
+ }
258
+ const servlyElements = document.querySelectorAll("[data-servly-id]");
259
+ servlyElements.forEach((el) => {
260
+ el.classList.add("__tw-refresh__");
261
+ queueMicrotask(() => {
262
+ el.classList.remove("__tw-refresh__");
263
+ });
264
+ });
265
+ document.body.classList.add("__tw-refresh__");
266
+ queueMicrotask(() => {
267
+ document.body.classList.remove("__tw-refresh__");
268
+ });
269
+ }
270
+ function scheduleRefresh(delayMs = 0) {
271
+ if (typeof window === "undefined") return;
272
+ const doRefresh = () => {
273
+ if (window.tailwind) {
274
+ refreshTailwind();
275
+ } else {
276
+ setTimeout(doRefresh, 100);
277
+ }
278
+ };
279
+ if (delayMs === 0) {
280
+ requestAnimationFrame(doRefresh);
281
+ } else {
282
+ setTimeout(doRefresh, delayMs);
283
+ }
284
+ }
225
285
  function addCustomStyles(css, id) {
226
286
  if (typeof document === "undefined") {
227
287
  throw new Error("addCustomStyles can only be used in browser environment");
@@ -292,6 +352,8 @@ var tailwind_default = {
292
352
  waitForTailwind,
293
353
  getTailwind,
294
354
  updateTailwindConfig,
355
+ refreshTailwind,
356
+ scheduleRefresh,
295
357
  addCustomStyles,
296
358
  removeCustomStyles,
297
359
  initServlyTailwind,
@@ -314,6 +376,8 @@ export {
314
376
  isTailwindLoaded,
315
377
  getTailwind,
316
378
  updateTailwindConfig,
379
+ refreshTailwind,
380
+ scheduleRefresh,
317
381
  addCustomStyles,
318
382
  removeCustomStyles,
319
383
  DEFAULT_SERVLY_TAILWIND_CONFIG,
package/dist/index.cjs CHANGED
@@ -35,9 +35,11 @@ __export(tailwind_exports, {
35
35
  markElementReady: () => markElementReady,
36
36
  preloadTailwind: () => preloadTailwind,
37
37
  preventFOUC: () => preventFOUC,
38
+ refreshTailwind: () => refreshTailwind,
38
39
  removeCustomStyles: () => removeCustomStyles,
39
40
  removeFOUCPrevention: () => removeFOUCPrevention,
40
41
  removeTailwind: () => removeTailwind,
42
+ scheduleRefresh: () => scheduleRefresh,
41
43
  updateTailwindConfig: () => updateTailwindConfig,
42
44
  waitForTailwind: () => waitForTailwind
43
45
  });
@@ -171,7 +173,8 @@ function injectTailwind(config = {}) {
171
173
  if (enablePreload) {
172
174
  preloadTailwind(cdnUrl, usePlayCdn);
173
175
  }
174
- if (window.tailwind) {
176
+ const existingScript = document.querySelector('script[src*="tailwindcss.com"]');
177
+ if (existingScript || window.tailwind) {
175
178
  tailwindInjected = true;
176
179
  markTailwindAsLoaded();
177
180
  if (shouldPreventFOUC) {
@@ -235,7 +238,32 @@ function removeTailwind() {
235
238
  }
236
239
  }
237
240
  function isTailwindLoaded() {
238
- return tailwindInjected || !!window.tailwind;
241
+ if (typeof window === "undefined") return false;
242
+ if (window.tailwind) {
243
+ return true;
244
+ }
245
+ if (typeof document !== "undefined") {
246
+ try {
247
+ for (const sheet of document.styleSheets) {
248
+ try {
249
+ const rules = sheet.cssRules || sheet.rules;
250
+ if (rules) {
251
+ for (let i = 0; i < Math.min(rules.length, 100); i++) {
252
+ const rule = rules[i];
253
+ if (rule instanceof CSSStyleRule) {
254
+ if (rule.selectorText?.match(/^\.(flex|grid|p-|m-|w-|h-|bg-|text-)/)) {
255
+ return true;
256
+ }
257
+ }
258
+ }
259
+ }
260
+ } catch {
261
+ }
262
+ }
263
+ } catch {
264
+ }
265
+ }
266
+ return tailwindInjected;
239
267
  }
240
268
  function getTailwind() {
241
269
  return window.tailwind;
@@ -248,6 +276,40 @@ function updateTailwindConfig(config) {
248
276
  };
249
277
  }
250
278
  }
279
+ function refreshTailwind() {
280
+ if (typeof window === "undefined" || typeof document === "undefined") return;
281
+ const tw = window.tailwind;
282
+ if (tw && typeof tw.refresh === "function") {
283
+ tw.refresh();
284
+ return;
285
+ }
286
+ const servlyElements = document.querySelectorAll("[data-servly-id]");
287
+ servlyElements.forEach((el) => {
288
+ el.classList.add("__tw-refresh__");
289
+ queueMicrotask(() => {
290
+ el.classList.remove("__tw-refresh__");
291
+ });
292
+ });
293
+ document.body.classList.add("__tw-refresh__");
294
+ queueMicrotask(() => {
295
+ document.body.classList.remove("__tw-refresh__");
296
+ });
297
+ }
298
+ function scheduleRefresh(delayMs = 0) {
299
+ if (typeof window === "undefined") return;
300
+ const doRefresh = () => {
301
+ if (window.tailwind) {
302
+ refreshTailwind();
303
+ } else {
304
+ setTimeout(doRefresh, 100);
305
+ }
306
+ };
307
+ if (delayMs === 0) {
308
+ requestAnimationFrame(doRefresh);
309
+ } else {
310
+ setTimeout(doRefresh, delayMs);
311
+ }
312
+ }
251
313
  function addCustomStyles(css, id) {
252
314
  if (typeof document === "undefined") {
253
315
  throw new Error("addCustomStyles can only be used in browser environment");
@@ -338,6 +400,8 @@ var init_tailwind = __esm({
338
400
  waitForTailwind,
339
401
  getTailwind,
340
402
  updateTailwindConfig,
403
+ refreshTailwind,
404
+ scheduleRefresh,
341
405
  addCustomStyles,
342
406
  removeCustomStyles,
343
407
  initServlyTailwind,
@@ -638,6 +702,7 @@ __export(index_exports, {
638
702
  preloadTailwind: () => preloadTailwind,
639
703
  preventFOUC: () => preventFOUC,
640
704
  processStyles: () => processStyles,
705
+ refreshTailwind: () => refreshTailwind,
641
706
  registerIcon: () => registerIcon,
642
707
  registerIcons: () => registerIcons,
643
708
  removeClass: () => removeClass,
@@ -665,6 +730,7 @@ __export(index_exports, {
665
730
  runAllTests: () => runAllTests,
666
731
  runTestCase: () => runTestCase,
667
732
  satisfiesVersion: () => satisfiesVersion,
733
+ scheduleRefresh: () => scheduleRefresh,
668
734
  setIconCdnEnabled: () => setIconCdnEnabled,
669
735
  setInCache: () => setInCache,
670
736
  setLocalStorage: () => setLocalStorage,
@@ -3301,11 +3367,9 @@ var tailwindAutoInjected = false;
3301
3367
  function ensureTailwind() {
3302
3368
  if (tailwindAutoInjected || typeof document === "undefined") return;
3303
3369
  tailwindAutoInjected = true;
3304
- if (!isTailwindLoaded()) {
3305
- injectTailwind({ usePlayCdn: true }).catch((err) => {
3306
- console.warn("Failed to auto-inject Tailwind CSS:", err);
3307
- });
3308
- }
3370
+ injectTailwind({ usePlayCdn: true }).catch((err) => {
3371
+ console.warn("Failed to auto-inject Tailwind CSS:", err);
3372
+ });
3309
3373
  }
3310
3374
  var COMPONENT_TO_TAG = {
3311
3375
  container: "div",
@@ -4037,6 +4101,9 @@ function render(options) {
4037
4101
  }
4038
4102
  }
4039
4103
  }
4104
+ if (!options.disableTailwind) {
4105
+ scheduleRefresh();
4106
+ }
4040
4107
  const duration = performance.now() - startTime;
4041
4108
  const memoryAfter = memorySampler.sample();
4042
4109
  const longTasks = longTaskObserver.stop();
@@ -5441,6 +5508,7 @@ init_tailwind();
5441
5508
  preloadTailwind,
5442
5509
  preventFOUC,
5443
5510
  processStyles,
5511
+ refreshTailwind,
5444
5512
  registerIcon,
5445
5513
  registerIcons,
5446
5514
  removeClass,
@@ -5468,6 +5536,7 @@ init_tailwind();
5468
5536
  runAllTests,
5469
5537
  runTestCase,
5470
5538
  satisfiesVersion,
5539
+ scheduleRefresh,
5471
5540
  setIconCdnEnabled,
5472
5541
  setInCache,
5473
5542
  setLocalStorage,