@stacksjs/stx 0.2.491 → 0.2.492
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/cli.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
2
|
// @bun
|
|
3
|
-
import"./chunk-2pph3dh0.js";import"./chunk-c57j92td.js";import"./chunk-rmavqxd8.js";import"./chunk-v7vkqg8f.js";import"./chunk-d4k4nyj0.js";import{U}from"./chunk-jws8btr5.js";import"./chunk-b77v56fz.js";import"./chunk-qmcmjdy7.js";import"./chunk-1erc0vrb.js";import"./chunk-kzg3h5wg.js";import"./chunk-e6y6s7q8.js";import"./chunk-kp4mzspk.js";import"./chunk-cp7hph6f.js";import"./chunk-0egg3666.js";import"./chunk-298s08st.js";import"./chunk-67actssw.js";import"./chunk-z9tvn738.js";import"./chunk-z9fz5dby.js";import"./chunk-g3hn7ncc.js";import"./chunk-71bbv43t.js";import"./chunk-52fcqzmc.js";import"./chunk-25m2wqsd.js";import"./chunk-rhrv2j36.js";import"./chunk-h6q8jafh.js";import"./chunk-2b1zg7xp.js";import"./chunk-01rz8h7x.js";import"./chunk-jnf8vt18.js";import"./chunk-1v86h5vn.js";import"./chunk-nfd56dgj.js";import"./chunk-6mqb6vf7.js";import"./chunk-ft6k76e4.js";import"./chunk-1c407nky.js";import"./chunk-3s9s1mdt.js";import"./chunk-s9mq9x2k.js";import"./chunk-2hc5mbw8.js";import{mt,ht}from"./chunk-7c18zqdc.js";import"./chunk-zxkzdbcv.js";import"./chunk-bt58m9y8.js";import"./chunk-vp827ah7.js";import"./chunk-3mynjdqr.js";import"./chunk-vg9dyc4y.js";import"./chunk-zv0vgamy.js";import"./chunk-8fb1mqw1.js";import"./chunk-q21e52cb.js";import"./chunk-4tb1mqr8.js";import{Ks,Xs,Gs,Js,hr,Ys,Zs,Qs,yr,br,Cn,$n,En}from"./chunk-z7bqn398.js";import"./chunk-ze9vhhvc.js";import"./chunk-er7y8hk9.js";import{yi}from"./chunk-szry3s17.js";import{u}from"./chunk-cg8hg6cs.js";import{spawn as R}from"child_process";import S from"fs";import M from"os";import f from"path";import n from"process";import{CLI as V}from"@stacksjs/clapp";var j="0.2.
|
|
3
|
+
import"./chunk-2pph3dh0.js";import"./chunk-c57j92td.js";import"./chunk-rmavqxd8.js";import"./chunk-v7vkqg8f.js";import"./chunk-d4k4nyj0.js";import{U}from"./chunk-jws8btr5.js";import"./chunk-b77v56fz.js";import"./chunk-qmcmjdy7.js";import"./chunk-1erc0vrb.js";import"./chunk-kzg3h5wg.js";import"./chunk-e6y6s7q8.js";import"./chunk-kp4mzspk.js";import"./chunk-cp7hph6f.js";import"./chunk-0egg3666.js";import"./chunk-298s08st.js";import"./chunk-67actssw.js";import"./chunk-z9tvn738.js";import"./chunk-z9fz5dby.js";import"./chunk-g3hn7ncc.js";import"./chunk-71bbv43t.js";import"./chunk-52fcqzmc.js";import"./chunk-25m2wqsd.js";import"./chunk-rhrv2j36.js";import"./chunk-h6q8jafh.js";import"./chunk-2b1zg7xp.js";import"./chunk-01rz8h7x.js";import"./chunk-jnf8vt18.js";import"./chunk-1v86h5vn.js";import"./chunk-nfd56dgj.js";import"./chunk-6mqb6vf7.js";import"./chunk-ft6k76e4.js";import"./chunk-1c407nky.js";import"./chunk-3s9s1mdt.js";import"./chunk-s9mq9x2k.js";import"./chunk-2hc5mbw8.js";import{mt,ht}from"./chunk-7c18zqdc.js";import"./chunk-zxkzdbcv.js";import"./chunk-bt58m9y8.js";import"./chunk-vp827ah7.js";import"./chunk-3mynjdqr.js";import"./chunk-vg9dyc4y.js";import"./chunk-zv0vgamy.js";import"./chunk-8fb1mqw1.js";import"./chunk-q21e52cb.js";import"./chunk-4tb1mqr8.js";import{Ks,Xs,Gs,Js,hr,Ys,Zs,Qs,yr,br,Cn,$n,En}from"./chunk-z7bqn398.js";import"./chunk-ze9vhhvc.js";import"./chunk-er7y8hk9.js";import{yi}from"./chunk-szry3s17.js";import{u}from"./chunk-cg8hg6cs.js";import{spawn as R}from"child_process";import S from"fs";import M from"os";import f from"path";import n from"process";import{CLI as V}from"@stacksjs/clapp";var j="0.2.492";var __dirname="/home/runner/work/stx/stx/packages/stx/bin",y=new V("stx");function B(h){let p=typeof h==="string"?Number.parseInt(h,10):h;if(Number.isNaN(p))return{isValid:!1,error:"Port must be a valid number",suggestion:"Try using a number between 1024 and 65535"};if(p<1024||p>65535)return{isValid:!1,error:"Port must be between 1024 and 65535",suggestion:"Try using a port between 1024 and 65535"};return{isValid:!0}}function A(h){try{if(!S.existsSync(h)){let x=f.dirname(h),t=f.basename(h);if(S.existsSync(x)){let o=S.readdirSync(x).filter((s)=>s.toLowerCase().includes(t.toLowerCase().substring(0,3))||s.endsWith(".stx")||s.endsWith(".md")),i=o.length>0?`File not found. Similar files in ${x}: ${o.slice(0,3).join(", ")}`:`File not found. Directory ${x} exists but doesn't contain the specified file.`;return{isValid:!1,error:`File does not exist: ${h}`,suggestion:i}}return{isValid:!1,error:`File does not exist: ${h}`,suggestion:"Check the file path and try again"}}if(S.statSync(h).isDirectory())return{isValid:!1,error:`Expected file but got directory: ${h}`,suggestion:"Specify a .stx or .md file path"};return{isValid:!0}}catch(p){return{isValid:!1,error:`Cannot access file: ${h}`,suggestion:"Check file permissions and path"}}}function z(h){let p=typeof h==="string"?Number.parseInt(h,10):h;if(Number.isNaN(p))return{isValid:!1,error:"Timeout must be a valid number",suggestion:"Specify timeout in milliseconds (e.g., 5000 for 5 seconds)"};if(p<100)return{isValid:!1,error:"Timeout too short (minimum 100ms)",suggestion:"Use a timeout of at least 100ms"};if(p>300000)return{isValid:!1,error:"Timeout too long (maximum 5 minutes)",suggestion:"Use a timeout of less than 300000ms (5 minutes)"};return{isValid:!0}}var O=(h)=>h.includes("*")||h.includes("?")||h.includes("{")||h.includes("["),H=(h)=>h.endsWith(".stx")||h.endsWith(".md");function F(h,p=1){if(console.error(`\u274C ${h.error}`),h.suggestion)console.error(`\uD83D\uDCA1 suggestion: ${h.suggestion}`);n.exit(p)}function L(h){if(!h)return;let p;try{p=JSON.parse(h)}catch(x){console.error(`\u274C --info-plist is not valid JSON: ${x.message}`),n.exit(1)}if(typeof p!=="object"||p===null||Array.isArray(p))console.error(`\u274C --info-plist must be a JSON object, e.g. '{"NSFocusStatusUsageDescription":"\u2026"}'`),n.exit(1);for(let[x,t]of Object.entries(p))if(typeof t!=="string"&&typeof t!=="number"&&typeof t!=="boolean")console.error(`\u274C --info-plist value for "${x}" must be a string, number or boolean`),n.exit(1);return p}async function G(h,p){try{let x=["test"],t=[];if(h&&h.length>0)for(let c of h)if(O(c))try{let r=await Array.fromAsync(new Bun.Glob(c).scan({onlyFiles:!0,absolute:!0}));if(r.length===0)console.warn(`Warning: No files found matching pattern: ${c}`);else if(t.push(...r),p.verbose)console.log(`Found ${r.length} file(s) matching pattern: ${c}`)}catch(r){return console.error(`Error expanding glob pattern ${c}:`,r),!1}else t.push(c);if(t.length===0)return console.error("Error: No test files found matching the provided patterns."),!1;if(x.push(...t),p.filter)x.push("--pattern",p.filter);if(p.timeout)x.push("--timeout",p.timeout.toString());if(p.reporter&&p.reporter!=="default")if(p.reporter==="junit"){let c=f.join(M.tmpdir(),`stx-test-report-${Date.now()}.xml`);x.push("--reporter",p.reporter),x.push("--reporter-outfile",c)}else console.warn(`Warning: Reporter '${p.reporter}' is not supported. Using default reporter.`);if(p.coverage)x.push("--coverage");if(p.watch)x.push("--watch");x.push("--preload",f.join(__dirname,"../../../test-utils/happy-dom.ts"));let e={...n.env,STX_TEST_MODE:"true",STX_TEST_UI:p.ui?"true":"false",STX_TEST_VERBOSE:p.verbose?"true":"false"},o="bun";if(p.verbose)console.log(`Running: ${o} ${x.join(" ")}`);let i=performance.now(),s=R(o,x,{stdio:"inherit",shell:!1,env:e});return new Promise((c)=>{s.on("close",(r)=>{let d=((performance.now()-i)/1000).toFixed(2);if(r===0)c(!0);else c(!1)}),n.on("SIGINT",()=>{console.log(`
|
|
4
4
|
Test run interrupted`),s.kill("SIGINT"),n.exit(1)})})}catch(x){return console.error("Error running tests:",x instanceof Error?x.message:String(x)),!1}}var J=n.argv.length>=3&&(H(n.argv[2])&&S.existsSync(n.argv[2])||O(n.argv[2]));if(J){let h=n.argv[2],p={port:3000,watch:!0,cache:!0,markdown:{syntaxHighlighting:{enabled:!0,serverSide:!0,defaultTheme:"github-dark",highlightUnknownLanguages:!0}}};for(let x=3;x<n.argv.length;x++){let t=n.argv[x];if(t==="--port"&&x+1<n.argv.length){let e=B(n.argv[++x]);if(!e.isValid)F(e);p.port=Number.parseInt(n.argv[x],10)}else if(t==="--no-watch")p.watch=!1;else if(t==="--highlight-theme"&&x+1<n.argv.length){if(!p.markdown)p.markdown={};if(!p.markdown.syntaxHighlighting)p.markdown.syntaxHighlighting={};p.markdown.syntaxHighlighting.defaultTheme=n.argv[++x]}else if(t==="--no-highlight"){if(!p.markdown)p.markdown={};if(!p.markdown.syntaxHighlighting)p.markdown.syntaxHighlighting={};p.markdown.syntaxHighlighting.enabled=!1}else if(t==="--no-highlight-unknown"){if(!p.markdown)p.markdown={};if(!p.markdown.syntaxHighlighting)p.markdown.syntaxHighlighting={};p.markdown.syntaxHighlighting.highlightUnknownLanguages=!1}else if(t==="--no-cache")p.cache=!1;else if(t==="--native")p.native=!0}if(O(h))try{let x=await Array.fromAsync(new Bun.Glob(h).scan({onlyFiles:!0,absolute:!0})),t=h.endsWith(".stx")?x.filter((s)=>s.endsWith(".stx")):h.endsWith(".md")?x.filter((s)=>s.endsWith(".md")):x.filter((s)=>s.endsWith(".stx")||s.endsWith(".md")),e=h.split("*")[0].replace(/\/$/,"")||".",o=f.resolve(e);try{let s=new Bun.Glob("**/*.stx"),r=(await Array.fromAsync(s.scan({cwd:o,onlyFiles:!0,absolute:!0}))).filter((l)=>/\[.+\]/.test(f.basename(l)));for(let l of r)if(!t.includes(l))t.push(l)}catch{}if(t.length===0)console.error(`Error: No STX or Markdown files found matching pattern: ${h}`),n.exit(1);if(!await $n(t,p))n.exit(1)}catch(x){console.error("Failed to process files:",x),n.exit(1)}else Cn(h,p).catch((x)=>{console.error("Failed to start dev server:",x),n.exit(1)})}else{let h=function(t,e){let o=[];for(let i=0;i<=e.length;i++)o[i]=[i];for(let i=0;i<=t.length;i++)o[0][i]=i;for(let i=1;i<=e.length;i++)for(let s=1;s<=t.length;s++)if(e.charAt(i-1)===t.charAt(s-1))o[i][s]=o[i-1][s-1];else o[i][s]=Math.min(o[i-1][s-1]+1,o[i][s-1]+1,o[i-1][s]+1);return o[e.length][t.length]};y.command("docs","Generate documentation for components, templates, and directives").option("--output <dir>","Output directory for documentation",{default:"docs"}).option("--format <format>","Documentation format (markdown, html, json)",{default:"markdown"}).option("--components-dir <dir>","Components directory",{default:"components"}).option("--templates-dir <dir>","Templates directory",{default:"."}).option("--no-components","Disable components documentation").option("--no-templates","Disable templates documentation").option("--no-directives","Disable directives documentation").option("--extra-content <content>","Extra content to include in documentation").example("stx docs --output docs --format html").action(async(t)=>{try{if(await Js(t))console.log("Documentation generated successfully."),n.exit(0);else console.error("Documentation generation failed."),n.exit(1)}catch(e){console.error("Error generating documentation:",e),n.exit(1)}}),y.command("iconify <command>","Generate Iconify icon packages").option("--output <dir>","Output directory for generated packages",{default:"packages"}).option("--icons <icons>","Comma-separated list of specific icons to generate").example("stx iconify list").example("stx iconify generate mdi").example("stx iconify generate lucide --icons home,settings,user").action(async(t,e)=>{try{let{fetchCollections:o,generatePackage:i}=await import("./chunk-t61vdbje.js");if(t==="list"){console.log(`
|
|
5
5
|
\uD83D\uDCDA Fetching available icon collections...
|
|
6
6
|
`);let s=await o(),c=Object.entries(s).sort((r,l)=>l[1].total-r[1].total);console.log(`Available collections:
|
|
@@ -34,6 +34,7 @@ declare class NativeTextDecoder {
|
|
|
34
34
|
* spaces as `+`, everything else outside the unreserved set percent-encoded.
|
|
35
35
|
*/
|
|
36
36
|
declare class NativeURLSearchParams {
|
|
37
|
+
static linked(query: string, owner: (query: string) => void): NativeURLSearchParams;
|
|
37
38
|
constructor(init?: string | Record<string, unknown> | Iterable<[unknown, unknown]> | NativeURLSearchParams);
|
|
38
39
|
get size(): number;
|
|
39
40
|
append(name: string, value: unknown): void;
|
|
@@ -50,4 +51,41 @@ declare class NativeURLSearchParams {
|
|
|
50
51
|
[Symbol.iterator](): IterableIterator<[string, string]>;
|
|
51
52
|
toString(): string;
|
|
52
53
|
}
|
|
54
|
+
/**
|
|
55
|
+
* `URL`, which JavaScriptCore does not have either: it is a web API.
|
|
56
|
+
* Sign-in code shared with web pages reads and builds addresses with it (an
|
|
57
|
+
* authorize URL's query, the address a sign-in sheet came back to), and on a
|
|
58
|
+
* native screen it threw. Absolute and relative parsing, special schemes and
|
|
59
|
+
* custom ones (`hqtraining://m/login`), and a live `searchParams`, as a
|
|
60
|
+
* browser's. Hostnames are kept as given, lower-cased: no IDNA mapping.
|
|
61
|
+
*/
|
|
62
|
+
declare class NativeURL {
|
|
63
|
+
constructor(input: string | { href: string }, base?: string | { href: string });
|
|
64
|
+
static canParse(input: string, base?: string): boolean;
|
|
65
|
+
static parse(input: string, base?: string): NativeURL | null;
|
|
66
|
+
get protocol(): string;
|
|
67
|
+
get username(): string;
|
|
68
|
+
set username(value: string);
|
|
69
|
+
get password(): string;
|
|
70
|
+
set password(value: string);
|
|
71
|
+
get hostname(): string;
|
|
72
|
+
set hostname(value: string);
|
|
73
|
+
get port(): string;
|
|
74
|
+
set port(value: string | number);
|
|
75
|
+
get host(): string;
|
|
76
|
+
set host(value: string);
|
|
77
|
+
get origin(): string;
|
|
78
|
+
get pathname(): string;
|
|
79
|
+
set pathname(value: string);
|
|
80
|
+
get search(): string;
|
|
81
|
+
set search(value: string);
|
|
82
|
+
get searchParams(): NativeURLSearchParams;
|
|
83
|
+
get hash(): string;
|
|
84
|
+
set hash(value: string);
|
|
85
|
+
get href(): string;
|
|
86
|
+
set href(value: string);
|
|
87
|
+
toString(): string;
|
|
88
|
+
toJSON(): string;
|
|
89
|
+
}
|
|
53
90
|
export { NativeURLSearchParams };
|
|
91
|
+
export { NativeURL };
|
|
@@ -80,6 +80,15 @@ class NativeTextDecoder {
|
|
|
80
80
|
|
|
81
81
|
class NativeURLSearchParams {
|
|
82
82
|
list = [];
|
|
83
|
+
owner = null;
|
|
84
|
+
static linked(query, owner) {
|
|
85
|
+
const params = new NativeURLSearchParams(query);
|
|
86
|
+
params.owner = owner;
|
|
87
|
+
return params;
|
|
88
|
+
}
|
|
89
|
+
changed() {
|
|
90
|
+
this.owner?.(this.toString());
|
|
91
|
+
}
|
|
83
92
|
constructor(init) {
|
|
84
93
|
if (init == null)
|
|
85
94
|
return;
|
|
@@ -115,9 +124,11 @@ class NativeURLSearchParams {
|
|
|
115
124
|
}
|
|
116
125
|
append(name, value) {
|
|
117
126
|
this.list.push([String(name), String(value)]);
|
|
127
|
+
this.changed();
|
|
118
128
|
}
|
|
119
129
|
delete(name) {
|
|
120
130
|
this.list = this.list.filter(([key]) => key !== name);
|
|
131
|
+
this.changed();
|
|
121
132
|
}
|
|
122
133
|
get(name) {
|
|
123
134
|
return this.list.find(([key]) => key === name)?.[1] ?? null;
|
|
@@ -136,9 +147,11 @@ class NativeURLSearchParams {
|
|
|
136
147
|
}
|
|
137
148
|
this.list[at] = [String(name), String(value)];
|
|
138
149
|
this.list = this.list.filter(([key], index) => key !== name || index === at);
|
|
150
|
+
this.changed();
|
|
139
151
|
}
|
|
140
152
|
sort() {
|
|
141
153
|
this.list.sort((a, b) => a[0] < b[0] ? -1 : a[0] > b[0] ? 1 : 0);
|
|
154
|
+
this.changed();
|
|
142
155
|
}
|
|
143
156
|
forEach(callback) {
|
|
144
157
|
for (const [name, value] of [...this.list])
|
|
@@ -162,6 +175,267 @@ class NativeURLSearchParams {
|
|
|
162
175
|
}
|
|
163
176
|
|
|
164
177
|
export { NativeURLSearchParams };
|
|
178
|
+
const SPECIAL_SCHEMES = { "http:": "80", "https:": "443", "ws:": "80", "wss:": "443", "ftp:": "21", "file:": "" };
|
|
179
|
+
function escapeURLPart(text, unsafe) {
|
|
180
|
+
let out = "";
|
|
181
|
+
for (const char of text)
|
|
182
|
+
if (char.charCodeAt(0) > 126 || char.charCodeAt(0) < 33 || unsafe.test(char))
|
|
183
|
+
out += encodeURIComponent(char);
|
|
184
|
+
else
|
|
185
|
+
out += char;
|
|
186
|
+
return out;
|
|
187
|
+
}
|
|
188
|
+
function removeDotSegments(path) {
|
|
189
|
+
const segments = path.split("/"), out = [];
|
|
190
|
+
for (let i = 0;i < segments.length; i++) {
|
|
191
|
+
const segment = segments[i], last = i === segments.length - 1;
|
|
192
|
+
if (segment === "." || segment.toLowerCase() === "%2e") {
|
|
193
|
+
if (last)
|
|
194
|
+
out.push("");
|
|
195
|
+
continue;
|
|
196
|
+
}
|
|
197
|
+
if (segment === ".." || /^(?:\.|%2e){2}$/i.test(segment)) {
|
|
198
|
+
if (out.length > 1)
|
|
199
|
+
out.pop();
|
|
200
|
+
if (last)
|
|
201
|
+
out.push("");
|
|
202
|
+
continue;
|
|
203
|
+
}
|
|
204
|
+
out.push(segment);
|
|
205
|
+
}
|
|
206
|
+
return out.join("/");
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
class NativeURL {
|
|
210
|
+
parts;
|
|
211
|
+
params = null;
|
|
212
|
+
constructor(input, base) {
|
|
213
|
+
const text = typeof input === "string" ? input : String(input?.href ?? input), baseParts = base === void 0 ? null : NativeURL.parts(typeof base === "string" ? base : String(base?.href ?? base), null);
|
|
214
|
+
if (base !== void 0 && !baseParts)
|
|
215
|
+
throw TypeError(`Invalid base URL: ${String(base)}`);
|
|
216
|
+
const parts = NativeURL.parts(text, baseParts);
|
|
217
|
+
if (!parts)
|
|
218
|
+
throw TypeError(`Invalid URL: ${text}`);
|
|
219
|
+
this.parts = parts;
|
|
220
|
+
}
|
|
221
|
+
static canParse(input, base) {
|
|
222
|
+
try {
|
|
223
|
+
new NativeURL(input, base);
|
|
224
|
+
return !0;
|
|
225
|
+
} catch {
|
|
226
|
+
return !1;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
static parse(input, base) {
|
|
230
|
+
try {
|
|
231
|
+
return new NativeURL(input, base);
|
|
232
|
+
} catch {
|
|
233
|
+
return null;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
static parts(input, base) {
|
|
237
|
+
const text = String(input).replace(/[\t\n\r]/g, "").trim(), scheme = /^([a-z][a-z\d+.-]*):/i.exec(text);
|
|
238
|
+
if (scheme) {
|
|
239
|
+
const protocol = `${scheme[1].toLowerCase()}:`, rest = text.slice(scheme[0].length);
|
|
240
|
+
if (base && base.protocol === protocol && protocol in SPECIAL_SCHEMES && !/^[/\\]/.test(rest))
|
|
241
|
+
return NativeURL.relative(rest, base);
|
|
242
|
+
return NativeURL.absolute(protocol, rest);
|
|
243
|
+
}
|
|
244
|
+
if (!base)
|
|
245
|
+
return null;
|
|
246
|
+
return NativeURL.relative(text, base);
|
|
247
|
+
}
|
|
248
|
+
static absolute(protocol, rest) {
|
|
249
|
+
const special = protocol in SPECIAL_SCHEMES, parts = { protocol, username: "", password: "", hostname: "", port: "", authority: !1, pathname: "", query: null, fragment: null };
|
|
250
|
+
let remaining = rest;
|
|
251
|
+
const hashAt = remaining.indexOf("#");
|
|
252
|
+
if (hashAt !== -1) {
|
|
253
|
+
parts.fragment = remaining.slice(hashAt + 1);
|
|
254
|
+
remaining = remaining.slice(0, hashAt);
|
|
255
|
+
}
|
|
256
|
+
const queryAt = remaining.indexOf("?");
|
|
257
|
+
if (queryAt !== -1) {
|
|
258
|
+
parts.query = remaining.slice(queryAt + 1);
|
|
259
|
+
remaining = remaining.slice(0, queryAt);
|
|
260
|
+
}
|
|
261
|
+
if (special || remaining.startsWith("//")) {
|
|
262
|
+
parts.authority = !0;
|
|
263
|
+
remaining = parts.protocol === "file:" ? remaining.replace(/^[/\\]{2}/, "") : special ? remaining.replace(/^[/\\]*/, "") : remaining.slice(2);
|
|
264
|
+
const end = remaining.search(special ? /[/\\]/ : /\//), authority = end === -1 ? remaining : remaining.slice(0, end);
|
|
265
|
+
remaining = end === -1 ? "" : remaining.slice(end);
|
|
266
|
+
if (!NativeURL.authority(parts, authority, special))
|
|
267
|
+
return null;
|
|
268
|
+
}
|
|
269
|
+
parts.pathname = NativeURL.path(remaining, parts);
|
|
270
|
+
return NativeURL.finish(parts);
|
|
271
|
+
}
|
|
272
|
+
static authority(parts, authority, special) {
|
|
273
|
+
const at = authority.lastIndexOf("@");
|
|
274
|
+
if (at !== -1) {
|
|
275
|
+
const info = authority.slice(0, at), colon = info.indexOf(":");
|
|
276
|
+
parts.username = escapeURLPart(colon === -1 ? info : info.slice(0, colon), /[ "#<>?`{}/:;=@[\\\]^|]/);
|
|
277
|
+
parts.password = colon === -1 ? "" : escapeURLPart(info.slice(colon + 1), /[ "#<>?`{}/:;=@[\\\]^|]/);
|
|
278
|
+
}
|
|
279
|
+
const host = at === -1 ? authority : authority.slice(at + 1), portAt = host.startsWith("[") ? host.indexOf(":", host.indexOf("]")) : host.lastIndexOf(":"), hostname = portAt === -1 ? host : host.slice(0, portAt), port = portAt === -1 ? "" : host.slice(portAt + 1);
|
|
280
|
+
if (port && (!/^\d+$/.test(port) || Number(port) > 65535))
|
|
281
|
+
return !1;
|
|
282
|
+
if (/[\s#%/:<>?@[\\\]^|]/.test(hostname.replace(/^\[[\da-f:.]+\]$/i, "")))
|
|
283
|
+
return !1;
|
|
284
|
+
if (special && parts.protocol !== "file:" && !hostname)
|
|
285
|
+
return !1;
|
|
286
|
+
parts.hostname = special ? hostname.toLowerCase() : hostname;
|
|
287
|
+
parts.port = port === "" ? "" : String(Number(port));
|
|
288
|
+
if (parts.port === SPECIAL_SCHEMES[parts.protocol])
|
|
289
|
+
parts.port = "";
|
|
290
|
+
return !0;
|
|
291
|
+
}
|
|
292
|
+
static path(path, parts) {
|
|
293
|
+
const special = parts.protocol in SPECIAL_SCHEMES;
|
|
294
|
+
let out = special ? path.replace(/\\/g, "/") : path;
|
|
295
|
+
if (!parts.authority && !out.startsWith("/"))
|
|
296
|
+
return escapeURLPart(out, /[ "<>`]/);
|
|
297
|
+
if (special && !out.startsWith("/"))
|
|
298
|
+
out = `/${out}`;
|
|
299
|
+
return escapeURLPart(removeDotSegments(out), /[ "#<>?`{}]/);
|
|
300
|
+
}
|
|
301
|
+
static finish(parts) {
|
|
302
|
+
const special = parts.protocol in SPECIAL_SCHEMES;
|
|
303
|
+
if (parts.query !== null)
|
|
304
|
+
parts.query = escapeURLPart(parts.query, special ? /[ "#<>']/ : /[ "#<>]/);
|
|
305
|
+
if (parts.fragment !== null)
|
|
306
|
+
parts.fragment = escapeURLPart(parts.fragment, /[ "<>`]/);
|
|
307
|
+
return parts;
|
|
308
|
+
}
|
|
309
|
+
static relative(input, base) {
|
|
310
|
+
const special = base.protocol in SPECIAL_SCHEMES;
|
|
311
|
+
if (!base.authority && !base.pathname.startsWith("/")) {
|
|
312
|
+
if (!input.startsWith("#"))
|
|
313
|
+
return null;
|
|
314
|
+
return { ...base, fragment: escapeURLPart(input.slice(1), /[ "<>`]/) };
|
|
315
|
+
}
|
|
316
|
+
if (special ? /^[/\\]{2}/.test(input) : input.startsWith("//"))
|
|
317
|
+
return NativeURL.absolute(base.protocol, input);
|
|
318
|
+
const parts = { ...base, query: base.query, fragment: null };
|
|
319
|
+
let remaining = input;
|
|
320
|
+
const hashAt = remaining.indexOf("#");
|
|
321
|
+
if (hashAt !== -1) {
|
|
322
|
+
parts.fragment = remaining.slice(hashAt + 1);
|
|
323
|
+
remaining = remaining.slice(0, hashAt);
|
|
324
|
+
}
|
|
325
|
+
const queryAt = remaining.indexOf("?");
|
|
326
|
+
if (queryAt !== -1) {
|
|
327
|
+
parts.query = remaining.slice(queryAt + 1);
|
|
328
|
+
remaining = remaining.slice(0, queryAt);
|
|
329
|
+
} else if (remaining)
|
|
330
|
+
parts.query = null;
|
|
331
|
+
if (remaining) {
|
|
332
|
+
const absolutePath = special ? /^[/\\]/.test(remaining) : remaining.startsWith("/"), directory = base.pathname.slice(0, base.pathname.lastIndexOf("/") + 1) || "/";
|
|
333
|
+
parts.pathname = NativeURL.path(absolutePath ? remaining : directory + remaining, parts);
|
|
334
|
+
}
|
|
335
|
+
return NativeURL.finish(parts);
|
|
336
|
+
}
|
|
337
|
+
get protocol() {
|
|
338
|
+
return this.parts.protocol;
|
|
339
|
+
}
|
|
340
|
+
get username() {
|
|
341
|
+
return this.parts.username;
|
|
342
|
+
}
|
|
343
|
+
set username(value) {
|
|
344
|
+
this.parts.username = escapeURLPart(String(value), /[ "#<>?`{}/:;=@[\\\]^|]/);
|
|
345
|
+
}
|
|
346
|
+
get password() {
|
|
347
|
+
return this.parts.password;
|
|
348
|
+
}
|
|
349
|
+
set password(value) {
|
|
350
|
+
this.parts.password = escapeURLPart(String(value), /[ "#<>?`{}/:;=@[\\\]^|]/);
|
|
351
|
+
}
|
|
352
|
+
get hostname() {
|
|
353
|
+
return this.parts.hostname;
|
|
354
|
+
}
|
|
355
|
+
set hostname(value) {
|
|
356
|
+
const special = this.parts.protocol in SPECIAL_SCHEMES, next = String(value);
|
|
357
|
+
if (/[\s#%/:<>?@[\\\]^|]/.test(next) || special && !next)
|
|
358
|
+
return;
|
|
359
|
+
this.parts.hostname = special ? next.toLowerCase() : next;
|
|
360
|
+
}
|
|
361
|
+
get port() {
|
|
362
|
+
return this.parts.port;
|
|
363
|
+
}
|
|
364
|
+
set port(value) {
|
|
365
|
+
const digits = /^\d*/.exec(String(value))[0];
|
|
366
|
+
if (digits === "") {
|
|
367
|
+
if (String(value) === "")
|
|
368
|
+
this.parts.port = "";
|
|
369
|
+
return;
|
|
370
|
+
}
|
|
371
|
+
if (Number(digits) > 65535)
|
|
372
|
+
return;
|
|
373
|
+
const port = String(Number(digits));
|
|
374
|
+
this.parts.port = port === SPECIAL_SCHEMES[this.parts.protocol] ? "" : port;
|
|
375
|
+
}
|
|
376
|
+
get host() {
|
|
377
|
+
return this.parts.port ? `${this.parts.hostname}:${this.parts.port}` : this.parts.hostname;
|
|
378
|
+
}
|
|
379
|
+
set host(value) {
|
|
380
|
+
const parts = { ...this.parts };
|
|
381
|
+
if (NativeURL.authority(parts, String(value), this.parts.protocol in SPECIAL_SCHEMES)) {
|
|
382
|
+
this.parts.hostname = parts.hostname;
|
|
383
|
+
this.parts.port = parts.port;
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
get origin() {
|
|
387
|
+
const { protocol } = this.parts;
|
|
388
|
+
return protocol in SPECIAL_SCHEMES && protocol !== "file:" ? `${protocol}//${this.host}` : "null";
|
|
389
|
+
}
|
|
390
|
+
get pathname() {
|
|
391
|
+
return this.parts.pathname;
|
|
392
|
+
}
|
|
393
|
+
set pathname(value) {
|
|
394
|
+
if (!this.parts.authority && !this.parts.pathname.startsWith("/"))
|
|
395
|
+
return;
|
|
396
|
+
this.parts.pathname = NativeURL.path(String(value), this.parts);
|
|
397
|
+
}
|
|
398
|
+
get search() {
|
|
399
|
+
return this.parts.query ? `?${this.parts.query}` : "";
|
|
400
|
+
}
|
|
401
|
+
set search(value) {
|
|
402
|
+
const next = String(value).replace(/^\?/, "");
|
|
403
|
+
this.parts.query = next === "" ? null : NativeURL.finish({ ...this.parts, query: next, fragment: null }).query;
|
|
404
|
+
this.params = null;
|
|
405
|
+
}
|
|
406
|
+
get searchParams() {
|
|
407
|
+
this.params ??= NativeURLSearchParams.linked(this.parts.query ?? "", (query) => {
|
|
408
|
+
this.parts.query = query === "" ? null : query;
|
|
409
|
+
});
|
|
410
|
+
return this.params;
|
|
411
|
+
}
|
|
412
|
+
get hash() {
|
|
413
|
+
return this.parts.fragment ? `#${this.parts.fragment}` : "";
|
|
414
|
+
}
|
|
415
|
+
set hash(value) {
|
|
416
|
+
const next = String(value).replace(/^#/, "");
|
|
417
|
+
this.parts.fragment = next === "" ? null : escapeURLPart(next, /[ "<>`]/);
|
|
418
|
+
}
|
|
419
|
+
get href() {
|
|
420
|
+
const { protocol, username, password, authority, pathname, query, fragment } = this.parts, credentials = username || password ? `${username}${password ? `:${password}` : ""}@` : "";
|
|
421
|
+
return `${protocol}${authority ? `//${credentials}${this.host}` : ""}${pathname}${query === null ? "" : `?${query}`}${fragment === null ? "" : `#${fragment}`}`;
|
|
422
|
+
}
|
|
423
|
+
set href(value) {
|
|
424
|
+
const parts = NativeURL.parts(String(value), null);
|
|
425
|
+
if (!parts)
|
|
426
|
+
throw TypeError(`Invalid URL: ${String(value)}`);
|
|
427
|
+
this.parts = parts;
|
|
428
|
+
this.params = null;
|
|
429
|
+
}
|
|
430
|
+
toString() {
|
|
431
|
+
return this.href;
|
|
432
|
+
}
|
|
433
|
+
toJSON() {
|
|
434
|
+
return this.href;
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
export { NativeURL };
|
|
165
439
|
export function installJSCGlobals(target = globalThis) {
|
|
166
440
|
const listeners = new Map, addEventListener = (name, listener) => {
|
|
167
441
|
const group = listeners.get(name) ?? new Set;
|
|
@@ -184,6 +458,7 @@ export function installJSCGlobals(target = globalThis) {
|
|
|
184
458
|
target.removeEventListener ??= removeEventListener;
|
|
185
459
|
target.dispatchEvent ??= dispatchEvent;
|
|
186
460
|
target.URLSearchParams ??= NativeURLSearchParams;
|
|
461
|
+
target.URL ??= NativeURL;
|
|
187
462
|
target.TextEncoder ??= NativeTextEncoder;
|
|
188
463
|
target.TextDecoder ??= NativeTextDecoder;
|
|
189
464
|
target.performance ??= { now: () => Date.now() };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stacksjs/stx",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.2.
|
|
4
|
+
"version": "0.2.492",
|
|
5
5
|
"description": "A performant UI Framework. Powered by Bun.",
|
|
6
6
|
"author": "Chris Breuer <chris@stacksjs.org>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -122,12 +122,12 @@
|
|
|
122
122
|
"dependencies": {
|
|
123
123
|
"@stacksjs/ts-css": "^0.3.2",
|
|
124
124
|
"@stacksjs/clapp": "^0.2.16",
|
|
125
|
-
"@stacksjs/desktop": "0.2.
|
|
126
|
-
"@stacksjs/sanitizer": "0.2.
|
|
125
|
+
"@stacksjs/desktop": "0.2.492",
|
|
126
|
+
"@stacksjs/sanitizer": "0.2.492",
|
|
127
127
|
"@stacksjs/ts-i18n": "^0.1.11",
|
|
128
|
-
"bun-plugin-stx": "0.2.
|
|
128
|
+
"bun-plugin-stx": "0.2.492",
|
|
129
129
|
"bunfig": "^0.15.19",
|
|
130
|
-
"stx-router": "0.2.
|
|
130
|
+
"stx-router": "0.2.492",
|
|
131
131
|
"ts-broadcasting": "^0.0.11",
|
|
132
132
|
"ts-images": "^0.2.22",
|
|
133
133
|
"ts-syntax-highlighter": "^0.2.1"
|