ucode-agent 1.60.0 → 1.60.1
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/package.json +1 -1
- package/src/tools/files.js +22 -0
package/package.json
CHANGED
package/src/tools/files.js
CHANGED
|
@@ -228,6 +228,27 @@ export function assetImport(abs, text) {
|
|
|
228
228
|
'instead — <link rel="stylesheet" href="…"> for a stylesheet, an <img> or a plain URL for an image.';
|
|
229
229
|
}
|
|
230
230
|
|
|
231
|
+
/**
|
|
232
|
+
* A page styled with Tailwind classes that never loads Tailwind.
|
|
233
|
+
*
|
|
234
|
+
* A live build wrote a 27 KB page of "flex px-4 bg-[var(--bg)]" and a
|
|
235
|
+
* stylesheet of colour tokens only: every class was ignored and the app came
|
|
236
|
+
* out as bare browser defaults, with nothing failing to tell anyone. When a
|
|
237
|
+
* page leans on those classes and has no Tailwind of its own, the browser
|
|
238
|
+
* build is added to its head, so the page looks the way it was written.
|
|
239
|
+
*/
|
|
240
|
+
const TAILWIND_CLASS = /^(?:-?(?:m|p)[trblxy]?-\S+|flex|grid|hidden|block|inline-flex|items-\S+|justify-\S+|gap-\S+|space-[xy]-\S+|(?:min-|max-)?[wh]-\S+|text-\S+|bg-\S+|rounded(?:-\S+)?|border(?:-\S+)?|shadow(?:-\S+)?|font-\S+|leading-\S+|tracking-\S+|(?:sm|md|lg|xl|hover|focus|dark):\S+)$/;
|
|
241
|
+
export function withTailwind(html) {
|
|
242
|
+
if (/tailwindcss|cdn\.tailwind/i.test(html) || !/<\/head>/i.test(html)) return html;
|
|
243
|
+
let count = 0;
|
|
244
|
+
for (const [, list] of html.matchAll(/class="([^"]*)"/g)) {
|
|
245
|
+
for (const token of list.split(/\s+/)) if (TAILWIND_CLASS.test(token)) count++;
|
|
246
|
+
if (count >= 12) break;
|
|
247
|
+
}
|
|
248
|
+
if (count < 12) return html;
|
|
249
|
+
return html.replace(/<\/head>/i, ' <script src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"></script>\n</head>');
|
|
250
|
+
}
|
|
251
|
+
|
|
231
252
|
/** The note for that, appended to a write's result like a parse problem is. */
|
|
232
253
|
const pageNote = (target, text) => {
|
|
233
254
|
const problem = assetImport(target.abs, text);
|
|
@@ -355,6 +376,7 @@ export async function readFiles({ paths, limit = READ_LINES }) {
|
|
|
355
376
|
/** Write one file, returning the rows that show what changed. */
|
|
356
377
|
async function put(target, content, { diffMax = 16 } = {}) {
|
|
357
378
|
const attempted = `writing ${target.show}`;
|
|
379
|
+
if (/\.html?$/i.test(target.abs)) content = withTailwind(content);
|
|
358
380
|
|
|
359
381
|
// Read what is there before clobbering it, so an overwrite can be shown as
|
|
360
382
|
// an actual diff rather than as a claim that something changed.
|