tailwind-hyperclay 0.1.2 → 0.1.3
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/index.js +17 -13
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -80,16 +80,12 @@ export function extractCandidates(html) {
|
|
|
80
80
|
return Array.from(candidates);
|
|
81
81
|
}
|
|
82
82
|
|
|
83
|
-
function
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
return url.pathname.slice(13, -4); // extract app name between /tailwindcss/ and .css
|
|
90
|
-
}
|
|
91
|
-
} catch {}
|
|
92
|
-
return null;
|
|
83
|
+
function getTailwindName(urlString) {
|
|
84
|
+
// Match relative path: /tailwindcss/name.css
|
|
85
|
+
// Or full URL: https://hyperclay.com/tailwindcss/name.css
|
|
86
|
+
// With optional query params (?v=123) or fragments (#section)
|
|
87
|
+
const match = urlString.match(/^(?:https:\/\/hyperclay\.com)?\/tailwindcss\/([^?#]+)\.css(?:[?#].*)?$/);
|
|
88
|
+
return match ? match[1] : null;
|
|
93
89
|
}
|
|
94
90
|
|
|
95
91
|
function extractHrefs(html) {
|
|
@@ -102,19 +98,27 @@ function extractHrefs(html) {
|
|
|
102
98
|
return hrefs;
|
|
103
99
|
}
|
|
104
100
|
|
|
101
|
+
export function getTailwindCssName(html) {
|
|
102
|
+
for (const href of extractHrefs(html)) {
|
|
103
|
+
const name = getTailwindName(href);
|
|
104
|
+
if (name) return name;
|
|
105
|
+
}
|
|
106
|
+
return null;
|
|
107
|
+
}
|
|
108
|
+
|
|
105
109
|
export function hasTailwindLink(html, appName) {
|
|
106
|
-
return extractHrefs(html).some(url =>
|
|
110
|
+
return extractHrefs(html).some(url => getTailwindName(url) === appName);
|
|
107
111
|
}
|
|
108
112
|
|
|
109
113
|
export function hasAnyTailwindLink(html) {
|
|
110
|
-
return extractHrefs(html).some(url =>
|
|
114
|
+
return extractHrefs(html).some(url => getTailwindName(url) !== null);
|
|
111
115
|
}
|
|
112
116
|
|
|
113
117
|
export function replaceTailwindLink(html, newName) {
|
|
114
118
|
return html.replace(
|
|
115
119
|
/(href\s*=\s*["'])([^"']+)(["'])/gi,
|
|
116
120
|
(match, prefix, url, suffix) => {
|
|
117
|
-
if (
|
|
121
|
+
if (getTailwindName(url) !== null) {
|
|
118
122
|
return `${prefix}https://hyperclay.com/tailwindcss/${newName}.css${suffix}`;
|
|
119
123
|
}
|
|
120
124
|
return match;
|