@servlyadmin/runtime-core 0.1.40 → 0.1.42

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.
@@ -120,12 +120,15 @@ function waitForTailwind(timeoutMs = 3e3) {
120
120
  return tailwindReadyPromise;
121
121
  }
122
122
  function injectTailwind(config = {}) {
123
+ console.log("[Servly Tailwind] injectTailwind called");
123
124
  return new Promise((resolve, reject) => {
124
125
  if (tailwindInjected && tailwindScript) {
126
+ console.log("[Servly Tailwind] Already injected, skipping");
125
127
  resolve();
126
128
  return;
127
129
  }
128
130
  if (typeof document === "undefined") {
131
+ console.log("[Servly Tailwind] Not in browser, skipping");
129
132
  resolve();
130
133
  return;
131
134
  }
@@ -139,13 +142,17 @@ function injectTailwind(config = {}) {
139
142
  preventFOUC: shouldPreventFOUC = true,
140
143
  enablePreload = true
141
144
  } = config;
145
+ console.log("[Servly Tailwind] Config:", { cdnUrl, usePlayCdn, shouldPreventFOUC });
142
146
  if (shouldPreventFOUC) {
143
147
  preventFOUC();
144
148
  }
145
149
  if (enablePreload) {
146
150
  preloadTailwind(cdnUrl, usePlayCdn);
147
151
  }
148
- if (window.tailwind) {
152
+ const existingScript = document.querySelector('script[src*="tailwindcss.com"]');
153
+ console.log("[Servly Tailwind] Existing script check:", { existingScript: !!existingScript, windowTailwind: !!window.tailwind });
154
+ if (existingScript || window.tailwind) {
155
+ console.log("[Servly Tailwind] Tailwind already exists");
149
156
  tailwindInjected = true;
150
157
  markTailwindAsLoaded();
151
158
  if (shouldPreventFOUC) {
@@ -159,11 +166,14 @@ function injectTailwind(config = {}) {
159
166
  resolve();
160
167
  return;
161
168
  }
169
+ const scriptUrl = usePlayCdn ? `${cdnUrl}?plugins=forms,typography,aspect-ratio` : cdnUrl;
170
+ console.log("[Servly Tailwind] Creating script with URL:", scriptUrl);
162
171
  const script = document.createElement("script");
163
- script.src = usePlayCdn ? `${cdnUrl}?plugins=forms,typography,aspect-ratio` : cdnUrl;
172
+ script.src = scriptUrl;
164
173
  script.async = true;
165
174
  script.crossOrigin = "anonymous";
166
175
  script.onload = () => {
176
+ console.log("[Servly Tailwind] Script loaded successfully!");
167
177
  tailwindInjected = true;
168
178
  tailwindScript = script;
169
179
  markTailwindAsLoaded();
@@ -184,6 +194,7 @@ function injectTailwind(config = {}) {
184
194
  }, delay);
185
195
  };
186
196
  script.onerror = (event) => {
197
+ console.error("[Servly Tailwind] Script failed to load:", event);
187
198
  const error = new Error(`Failed to load Tailwind CSS from ${cdnUrl}`);
188
199
  if (shouldPreventFOUC) {
189
200
  removeFOUCPrevention();
@@ -195,7 +206,9 @@ function injectTailwind(config = {}) {
195
206
  onError?.(error);
196
207
  reject(error);
197
208
  };
209
+ console.log("[Servly Tailwind] Appending script to head");
198
210
  document.head.appendChild(script);
211
+ console.log("[Servly Tailwind] Script appended, head now has:", document.head.querySelectorAll("script").length, "scripts");
199
212
  });
200
213
  }
201
214
  function removeTailwind() {
@@ -209,7 +222,32 @@ function removeTailwind() {
209
222
  }
210
223
  }
211
224
  function isTailwindLoaded() {
212
- return tailwindInjected || !!window.tailwind;
225
+ if (typeof window === "undefined") return false;
226
+ if (window.tailwind) {
227
+ return true;
228
+ }
229
+ if (typeof document !== "undefined") {
230
+ try {
231
+ for (const sheet of document.styleSheets) {
232
+ try {
233
+ const rules = sheet.cssRules || sheet.rules;
234
+ if (rules) {
235
+ for (let i = 0; i < Math.min(rules.length, 100); i++) {
236
+ const rule = rules[i];
237
+ if (rule instanceof CSSStyleRule) {
238
+ if (rule.selectorText?.match(/^\.(flex|grid|p-|m-|w-|h-|bg-|text-)/)) {
239
+ return true;
240
+ }
241
+ }
242
+ }
243
+ }
244
+ } catch {
245
+ }
246
+ }
247
+ } catch {
248
+ }
249
+ }
250
+ return tailwindInjected;
213
251
  }
214
252
  function getTailwind() {
215
253
  return window.tailwind;
@@ -223,18 +261,37 @@ function updateTailwindConfig(config) {
223
261
  }
224
262
  }
225
263
  function refreshTailwind() {
226
- if (typeof window === "undefined") return;
264
+ if (typeof window === "undefined" || typeof document === "undefined") return;
227
265
  const tw = window.tailwind;
228
266
  if (tw && typeof tw.refresh === "function") {
229
267
  tw.refresh();
268
+ return;
230
269
  }
270
+ const servlyElements = document.querySelectorAll("[data-servly-id]");
271
+ servlyElements.forEach((el) => {
272
+ el.classList.add("__tw-refresh__");
273
+ queueMicrotask(() => {
274
+ el.classList.remove("__tw-refresh__");
275
+ });
276
+ });
277
+ document.body.classList.add("__tw-refresh__");
278
+ queueMicrotask(() => {
279
+ document.body.classList.remove("__tw-refresh__");
280
+ });
231
281
  }
232
282
  function scheduleRefresh(delayMs = 0) {
233
283
  if (typeof window === "undefined") return;
284
+ const doRefresh = () => {
285
+ if (window.tailwind) {
286
+ refreshTailwind();
287
+ } else {
288
+ setTimeout(doRefresh, 100);
289
+ }
290
+ };
234
291
  if (delayMs === 0) {
235
- requestAnimationFrame(() => refreshTailwind());
292
+ requestAnimationFrame(doRefresh);
236
293
  } else {
237
- setTimeout(() => refreshTailwind(), delayMs);
294
+ setTimeout(doRefresh, delayMs);
238
295
  }
239
296
  }
240
297
  function addCustomStyles(css, id) {
package/dist/index.cjs CHANGED
@@ -148,12 +148,15 @@ function waitForTailwind(timeoutMs = 3e3) {
148
148
  return tailwindReadyPromise;
149
149
  }
150
150
  function injectTailwind(config = {}) {
151
+ console.log("[Servly Tailwind] injectTailwind called");
151
152
  return new Promise((resolve, reject) => {
152
153
  if (tailwindInjected && tailwindScript) {
154
+ console.log("[Servly Tailwind] Already injected, skipping");
153
155
  resolve();
154
156
  return;
155
157
  }
156
158
  if (typeof document === "undefined") {
159
+ console.log("[Servly Tailwind] Not in browser, skipping");
157
160
  resolve();
158
161
  return;
159
162
  }
@@ -167,13 +170,17 @@ function injectTailwind(config = {}) {
167
170
  preventFOUC: shouldPreventFOUC = true,
168
171
  enablePreload = true
169
172
  } = config;
173
+ console.log("[Servly Tailwind] Config:", { cdnUrl, usePlayCdn, shouldPreventFOUC });
170
174
  if (shouldPreventFOUC) {
171
175
  preventFOUC();
172
176
  }
173
177
  if (enablePreload) {
174
178
  preloadTailwind(cdnUrl, usePlayCdn);
175
179
  }
176
- if (window.tailwind) {
180
+ const existingScript = document.querySelector('script[src*="tailwindcss.com"]');
181
+ console.log("[Servly Tailwind] Existing script check:", { existingScript: !!existingScript, windowTailwind: !!window.tailwind });
182
+ if (existingScript || window.tailwind) {
183
+ console.log("[Servly Tailwind] Tailwind already exists");
177
184
  tailwindInjected = true;
178
185
  markTailwindAsLoaded();
179
186
  if (shouldPreventFOUC) {
@@ -187,11 +194,14 @@ function injectTailwind(config = {}) {
187
194
  resolve();
188
195
  return;
189
196
  }
197
+ const scriptUrl = usePlayCdn ? `${cdnUrl}?plugins=forms,typography,aspect-ratio` : cdnUrl;
198
+ console.log("[Servly Tailwind] Creating script with URL:", scriptUrl);
190
199
  const script = document.createElement("script");
191
- script.src = usePlayCdn ? `${cdnUrl}?plugins=forms,typography,aspect-ratio` : cdnUrl;
200
+ script.src = scriptUrl;
192
201
  script.async = true;
193
202
  script.crossOrigin = "anonymous";
194
203
  script.onload = () => {
204
+ console.log("[Servly Tailwind] Script loaded successfully!");
195
205
  tailwindInjected = true;
196
206
  tailwindScript = script;
197
207
  markTailwindAsLoaded();
@@ -212,6 +222,7 @@ function injectTailwind(config = {}) {
212
222
  }, delay);
213
223
  };
214
224
  script.onerror = (event) => {
225
+ console.error("[Servly Tailwind] Script failed to load:", event);
215
226
  const error = new Error(`Failed to load Tailwind CSS from ${cdnUrl}`);
216
227
  if (shouldPreventFOUC) {
217
228
  removeFOUCPrevention();
@@ -223,7 +234,9 @@ function injectTailwind(config = {}) {
223
234
  onError?.(error);
224
235
  reject(error);
225
236
  };
237
+ console.log("[Servly Tailwind] Appending script to head");
226
238
  document.head.appendChild(script);
239
+ console.log("[Servly Tailwind] Script appended, head now has:", document.head.querySelectorAll("script").length, "scripts");
227
240
  });
228
241
  }
229
242
  function removeTailwind() {
@@ -237,7 +250,32 @@ function removeTailwind() {
237
250
  }
238
251
  }
239
252
  function isTailwindLoaded() {
240
- return tailwindInjected || !!window.tailwind;
253
+ if (typeof window === "undefined") return false;
254
+ if (window.tailwind) {
255
+ return true;
256
+ }
257
+ if (typeof document !== "undefined") {
258
+ try {
259
+ for (const sheet of document.styleSheets) {
260
+ try {
261
+ const rules = sheet.cssRules || sheet.rules;
262
+ if (rules) {
263
+ for (let i = 0; i < Math.min(rules.length, 100); i++) {
264
+ const rule = rules[i];
265
+ if (rule instanceof CSSStyleRule) {
266
+ if (rule.selectorText?.match(/^\.(flex|grid|p-|m-|w-|h-|bg-|text-)/)) {
267
+ return true;
268
+ }
269
+ }
270
+ }
271
+ }
272
+ } catch {
273
+ }
274
+ }
275
+ } catch {
276
+ }
277
+ }
278
+ return tailwindInjected;
241
279
  }
242
280
  function getTailwind() {
243
281
  return window.tailwind;
@@ -251,18 +289,37 @@ function updateTailwindConfig(config) {
251
289
  }
252
290
  }
253
291
  function refreshTailwind() {
254
- if (typeof window === "undefined") return;
292
+ if (typeof window === "undefined" || typeof document === "undefined") return;
255
293
  const tw = window.tailwind;
256
294
  if (tw && typeof tw.refresh === "function") {
257
295
  tw.refresh();
296
+ return;
258
297
  }
298
+ const servlyElements = document.querySelectorAll("[data-servly-id]");
299
+ servlyElements.forEach((el) => {
300
+ el.classList.add("__tw-refresh__");
301
+ queueMicrotask(() => {
302
+ el.classList.remove("__tw-refresh__");
303
+ });
304
+ });
305
+ document.body.classList.add("__tw-refresh__");
306
+ queueMicrotask(() => {
307
+ document.body.classList.remove("__tw-refresh__");
308
+ });
259
309
  }
260
310
  function scheduleRefresh(delayMs = 0) {
261
311
  if (typeof window === "undefined") return;
312
+ const doRefresh = () => {
313
+ if (window.tailwind) {
314
+ refreshTailwind();
315
+ } else {
316
+ setTimeout(doRefresh, 100);
317
+ }
318
+ };
262
319
  if (delayMs === 0) {
263
- requestAnimationFrame(() => refreshTailwind());
320
+ requestAnimationFrame(doRefresh);
264
321
  } else {
265
- setTimeout(() => refreshTailwind(), delayMs);
322
+ setTimeout(doRefresh, delayMs);
266
323
  }
267
324
  }
268
325
  function addCustomStyles(css, id) {
@@ -3322,11 +3379,9 @@ var tailwindAutoInjected = false;
3322
3379
  function ensureTailwind() {
3323
3380
  if (tailwindAutoInjected || typeof document === "undefined") return;
3324
3381
  tailwindAutoInjected = true;
3325
- if (!isTailwindLoaded()) {
3326
- injectTailwind({ usePlayCdn: true }).catch((err) => {
3327
- console.warn("Failed to auto-inject Tailwind CSS:", err);
3328
- });
3329
- }
3382
+ injectTailwind({ usePlayCdn: true }).catch((err) => {
3383
+ console.warn("Failed to auto-inject Tailwind CSS:", err);
3384
+ });
3330
3385
  }
3331
3386
  var COMPONENT_TO_TAG = {
3332
3387
  container: "div",
package/dist/index.d.cts CHANGED
@@ -1774,6 +1774,7 @@ declare function injectTailwind(config?: TailwindConfig): Promise<void>;
1774
1774
  declare function removeTailwind(): void;
1775
1775
  /**
1776
1776
  * Check if Tailwind CSS is loaded
1777
+ * Checks for both CDN (window.tailwind) and build-time Tailwind (style rules)
1777
1778
  */
1778
1779
  declare function isTailwindLoaded(): boolean;
1779
1780
  /**
@@ -1787,7 +1788,7 @@ declare function updateTailwindConfig(config: Record<string, any>): void;
1787
1788
  /**
1788
1789
  * Trigger Tailwind to refresh/rescan the DOM
1789
1790
  * This is needed when content is rendered after Tailwind CDN loads
1790
- * The Play CDN exposes tailwind.refresh() for this purpose
1791
+ * Uses multiple strategies to ensure Tailwind processes new content
1791
1792
  */
1792
1793
  declare function refreshTailwind(): void;
1793
1794
  /**
package/dist/index.d.ts CHANGED
@@ -1774,6 +1774,7 @@ declare function injectTailwind(config?: TailwindConfig): Promise<void>;
1774
1774
  declare function removeTailwind(): void;
1775
1775
  /**
1776
1776
  * Check if Tailwind CSS is loaded
1777
+ * Checks for both CDN (window.tailwind) and build-time Tailwind (style rules)
1777
1778
  */
1778
1779
  declare function isTailwindLoaded(): boolean;
1779
1780
  /**
@@ -1787,7 +1788,7 @@ declare function updateTailwindConfig(config: Record<string, any>): void;
1787
1788
  /**
1788
1789
  * Trigger Tailwind to refresh/rescan the DOM
1789
1790
  * This is needed when content is rendered after Tailwind CDN loads
1790
- * The Play CDN exposes tailwind.refresh() for this purpose
1791
+ * Uses multiple strategies to ensure Tailwind processes new content
1791
1792
  */
1792
1793
  declare function refreshTailwind(): void;
1793
1794
  /**
package/dist/index.js CHANGED
@@ -17,7 +17,7 @@ import {
17
17
  scheduleRefresh,
18
18
  updateTailwindConfig,
19
19
  waitForTailwind
20
- } from "./chunk-YYJF3UI2.js";
20
+ } from "./chunk-L5RPU26D.js";
21
21
  import {
22
22
  buildRegistryFromBundle,
23
23
  collectAllDependencies,
@@ -2645,11 +2645,9 @@ var tailwindAutoInjected = false;
2645
2645
  function ensureTailwind() {
2646
2646
  if (tailwindAutoInjected || typeof document === "undefined") return;
2647
2647
  tailwindAutoInjected = true;
2648
- if (!isTailwindLoaded()) {
2649
- injectTailwind({ usePlayCdn: true }).catch((err) => {
2650
- console.warn("Failed to auto-inject Tailwind CSS:", err);
2651
- });
2652
- }
2648
+ injectTailwind({ usePlayCdn: true }).catch((err) => {
2649
+ console.warn("Failed to auto-inject Tailwind CSS:", err);
2650
+ });
2653
2651
  }
2654
2652
  var COMPONENT_TO_TAG = {
2655
2653
  container: "div",
@@ -3615,7 +3613,7 @@ async function createServlyRenderer(options) {
3615
3613
  container = containerOption;
3616
3614
  }
3617
3615
  if (shouldInjectTailwind) {
3618
- const { initServlyTailwind: initServlyTailwind2 } = await import("./tailwind-XB76THS4.js");
3616
+ const { initServlyTailwind: initServlyTailwind2 } = await import("./tailwind-MU3YZM2C.js");
3619
3617
  await initServlyTailwind2(tailwindConfig);
3620
3618
  }
3621
3619
  const activeRenders = [];
@@ -18,7 +18,7 @@ import {
18
18
  tailwind_default,
19
19
  updateTailwindConfig,
20
20
  waitForTailwind
21
- } from "./chunk-YYJF3UI2.js";
21
+ } from "./chunk-L5RPU26D.js";
22
22
  export {
23
23
  DEFAULT_SERVLY_TAILWIND_CONFIG,
24
24
  addCustomStyles,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@servlyadmin/runtime-core",
3
- "version": "0.1.40",
3
+ "version": "0.1.42",
4
4
  "description": "Framework-agnostic core renderer for Servly components",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",