@kevisual/router 0.2.4 → 0.2.5
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/app.js +123 -112
- package/dist/commander.d.ts +2 -0
- package/dist/commander.js +90 -89
- package/dist/opencode.js +84 -84
- package/dist/router-browser.js +85 -85
- package/dist/router-simple.js +136 -95
- package/dist/router.js +119 -108
- package/dist/ws.js +34 -23
- package/package.json +1 -1
- package/src/commander.ts +4 -1
package/dist/router-simple.js
CHANGED
|
@@ -30,7 +30,7 @@ var __toESM = (mod, isNodeMode, target) => {
|
|
|
30
30
|
};
|
|
31
31
|
var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
|
|
32
32
|
|
|
33
|
-
// node_modules/path-to-regexp/dist/index.js
|
|
33
|
+
// ../../node_modules/.pnpm/path-to-regexp@8.4.0/node_modules/path-to-regexp/dist/index.js
|
|
34
34
|
var require_dist = __commonJS((exports) => {
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
36
|
exports.PathError = exports.TokenData = undefined;
|
|
@@ -43,17 +43,8 @@ var require_dist = __commonJS((exports) => {
|
|
|
43
43
|
var NOOP_VALUE = (value) => value;
|
|
44
44
|
var ID_START = /^[$_\p{ID_Start}]$/u;
|
|
45
45
|
var ID_CONTINUE = /^[$\u200c\u200d\p{ID_Continue}]$/u;
|
|
46
|
-
var
|
|
47
|
-
|
|
48
|
-
"}": "}",
|
|
49
|
-
"(": "(",
|
|
50
|
-
")": ")",
|
|
51
|
-
"[": "[",
|
|
52
|
-
"]": "]",
|
|
53
|
-
"+": "+",
|
|
54
|
-
"?": "?",
|
|
55
|
-
"!": "!"
|
|
56
|
-
};
|
|
46
|
+
var ID = /^[$_\p{ID_Start}][$\u200c\u200d\p{ID_Continue}]*$/u;
|
|
47
|
+
var SIMPLE_TOKENS = "{}()[]+?!";
|
|
57
48
|
function escapeText(str) {
|
|
58
49
|
return str.replace(/[{}()\[\]+?!:*\\]/g, "\\$&");
|
|
59
50
|
}
|
|
@@ -94,8 +85,8 @@ var require_dist = __commonJS((exports) => {
|
|
|
94
85
|
} while (ID_CONTINUE.test(chars[index]));
|
|
95
86
|
} else if (chars[index] === '"') {
|
|
96
87
|
let quoteStart = index;
|
|
97
|
-
while (index
|
|
98
|
-
if (chars[index] === '"') {
|
|
88
|
+
while (index < chars.length) {
|
|
89
|
+
if (chars[++index] === '"') {
|
|
99
90
|
index++;
|
|
100
91
|
quoteStart = 0;
|
|
101
92
|
break;
|
|
@@ -114,18 +105,17 @@ var require_dist = __commonJS((exports) => {
|
|
|
114
105
|
return value;
|
|
115
106
|
}
|
|
116
107
|
while (index < chars.length) {
|
|
117
|
-
const value = chars[index];
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
tokens.push({ type, index: index++, value });
|
|
108
|
+
const value = chars[index++];
|
|
109
|
+
if (SIMPLE_TOKENS.includes(value)) {
|
|
110
|
+
tokens.push({ type: value, index, value });
|
|
121
111
|
} else if (value === "\\") {
|
|
122
|
-
tokens.push({ type: "escape", index
|
|
112
|
+
tokens.push({ type: "escape", index, value: chars[index++] });
|
|
123
113
|
} else if (value === ":") {
|
|
124
|
-
tokens.push({ type: "param", index
|
|
114
|
+
tokens.push({ type: "param", index, value: name() });
|
|
125
115
|
} else if (value === "*") {
|
|
126
|
-
tokens.push({ type: "wildcard", index
|
|
116
|
+
tokens.push({ type: "wildcard", index, value: name() });
|
|
127
117
|
} else {
|
|
128
|
-
tokens.push({ type: "char", index
|
|
118
|
+
tokens.push({ type: "char", index, value });
|
|
129
119
|
}
|
|
130
120
|
}
|
|
131
121
|
tokens.push({ type: "end", index, value: "" });
|
|
@@ -261,107 +251,159 @@ var require_dist = __commonJS((exports) => {
|
|
|
261
251
|
}
|
|
262
252
|
function pathToRegexp(path, options = {}) {
|
|
263
253
|
const { delimiter = DEFAULT_DELIMITER, end = true, sensitive = false, trailing = true } = options;
|
|
264
|
-
const
|
|
265
|
-
const
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
const
|
|
269
|
-
|
|
270
|
-
|
|
254
|
+
const root = new SourceNode("^");
|
|
255
|
+
const paths = [path];
|
|
256
|
+
let combinations = 0;
|
|
257
|
+
while (paths.length) {
|
|
258
|
+
const path2 = paths.shift();
|
|
259
|
+
if (Array.isArray(path2)) {
|
|
260
|
+
paths.push(...path2);
|
|
261
|
+
continue;
|
|
271
262
|
}
|
|
263
|
+
const data = typeof path2 === "object" ? path2 : parse(path2, options);
|
|
264
|
+
flatten(data.tokens, 0, [], (tokens) => {
|
|
265
|
+
if (combinations++ >= 256) {
|
|
266
|
+
throw new PathError("Too many path combinations", data.originalPath);
|
|
267
|
+
}
|
|
268
|
+
let node = root;
|
|
269
|
+
for (const part of toRegExpSource(tokens, delimiter, data.originalPath)) {
|
|
270
|
+
node = node.add(part.source, part.key);
|
|
271
|
+
}
|
|
272
|
+
node.add("");
|
|
273
|
+
});
|
|
272
274
|
}
|
|
273
|
-
|
|
275
|
+
const keys = [];
|
|
276
|
+
let pattern = toRegExp(root, keys);
|
|
274
277
|
if (trailing)
|
|
275
|
-
pattern +=
|
|
276
|
-
pattern += end ? "$" :
|
|
277
|
-
|
|
278
|
-
return { regexp, keys };
|
|
279
|
-
}
|
|
280
|
-
function pathsToArray(paths, init) {
|
|
281
|
-
if (Array.isArray(paths)) {
|
|
282
|
-
for (const p of paths)
|
|
283
|
-
pathsToArray(p, init);
|
|
284
|
-
} else {
|
|
285
|
-
init.push(paths);
|
|
286
|
-
}
|
|
287
|
-
return init;
|
|
278
|
+
pattern += "(?:" + escape(delimiter) + "$)?";
|
|
279
|
+
pattern += end ? "$" : "(?=" + escape(delimiter) + "|$)";
|
|
280
|
+
return { regexp: new RegExp(pattern, sensitive ? "" : "i"), keys };
|
|
288
281
|
}
|
|
289
|
-
function
|
|
290
|
-
if (
|
|
291
|
-
|
|
282
|
+
function toRegExp(node, keys) {
|
|
283
|
+
if (node.key)
|
|
284
|
+
keys.push(node.key);
|
|
285
|
+
const children = Object.keys(node.children);
|
|
286
|
+
const text = children.map((id) => toRegExp(node.children[id], keys)).join("|");
|
|
287
|
+
return node.source + (children.length < 2 ? text : `(?:${text})`);
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
class SourceNode {
|
|
291
|
+
constructor(source, key) {
|
|
292
|
+
this.source = source;
|
|
293
|
+
this.key = key;
|
|
294
|
+
this.children = Object.create(null);
|
|
292
295
|
}
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
296
|
+
add(source, key) {
|
|
297
|
+
var _a;
|
|
298
|
+
const id = source + ":" + (key ? key.name : "");
|
|
299
|
+
return (_a = this.children)[id] || (_a[id] = new SourceNode(source, key));
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
function flatten(tokens, index, result, callback) {
|
|
303
|
+
while (index < tokens.length) {
|
|
304
|
+
const token = tokens[index++];
|
|
305
|
+
if (token.type === "group") {
|
|
306
|
+
flatten(token.tokens, 0, result.slice(), (seq) => flatten(tokens, index, seq, callback));
|
|
307
|
+
continue;
|
|
297
308
|
}
|
|
298
|
-
|
|
299
|
-
init.push(token);
|
|
309
|
+
result.push(token);
|
|
300
310
|
}
|
|
301
|
-
|
|
311
|
+
callback(result);
|
|
302
312
|
}
|
|
303
|
-
function toRegExpSource(tokens, delimiter,
|
|
304
|
-
let result =
|
|
313
|
+
function toRegExpSource(tokens, delimiter, originalPath) {
|
|
314
|
+
let result = [];
|
|
305
315
|
let backtrack = "";
|
|
306
|
-
let
|
|
307
|
-
|
|
316
|
+
let wildcardBacktrack = "";
|
|
317
|
+
let prevCaptureType = 0;
|
|
318
|
+
let hasSegmentCapture = 0;
|
|
319
|
+
let index = 0;
|
|
320
|
+
function hasInSegment(index2, type) {
|
|
321
|
+
while (index2 < tokens.length) {
|
|
322
|
+
const token = tokens[index2++];
|
|
323
|
+
if (token.type === type)
|
|
324
|
+
return true;
|
|
325
|
+
if (token.type === "text") {
|
|
326
|
+
if (token.value.includes(delimiter))
|
|
327
|
+
break;
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
return false;
|
|
331
|
+
}
|
|
332
|
+
function peekText(index2) {
|
|
333
|
+
let result2 = "";
|
|
334
|
+
while (index2 < tokens.length) {
|
|
335
|
+
const token = tokens[index2++];
|
|
336
|
+
if (token.type !== "text")
|
|
337
|
+
break;
|
|
338
|
+
result2 += token.value;
|
|
339
|
+
}
|
|
340
|
+
return result2;
|
|
341
|
+
}
|
|
342
|
+
while (index < tokens.length) {
|
|
343
|
+
const token = tokens[index++];
|
|
308
344
|
if (token.type === "text") {
|
|
309
|
-
result
|
|
345
|
+
result.push({ source: escape(token.value) });
|
|
310
346
|
backtrack += token.value;
|
|
311
|
-
|
|
347
|
+
if (prevCaptureType === 2)
|
|
348
|
+
wildcardBacktrack += token.value;
|
|
349
|
+
if (token.value.includes(delimiter))
|
|
350
|
+
hasSegmentCapture = 0;
|
|
312
351
|
continue;
|
|
313
352
|
}
|
|
314
353
|
if (token.type === "param" || token.type === "wildcard") {
|
|
315
|
-
if (
|
|
354
|
+
if (prevCaptureType && !backtrack) {
|
|
316
355
|
throw new PathError(`Missing text before "${token.name}" ${token.type}`, originalPath);
|
|
317
356
|
}
|
|
318
357
|
if (token.type === "param") {
|
|
319
|
-
result
|
|
358
|
+
result.push({
|
|
359
|
+
source: hasSegmentCapture ? `(${negate(delimiter, backtrack)}+?)` : hasInSegment(index, "wildcard") ? `(${negate(delimiter, peekText(index))}+?)` : `(${negate(delimiter, "")}+?)`,
|
|
360
|
+
key: token
|
|
361
|
+
});
|
|
362
|
+
hasSegmentCapture |= prevCaptureType = 1;
|
|
320
363
|
} else {
|
|
321
|
-
result
|
|
364
|
+
result.push({
|
|
365
|
+
source: hasSegmentCapture & 2 ? `(${negate(backtrack, "")}+?)` : hasSegmentCapture & 1 ? `(${negate(wildcardBacktrack, "")}+?)` : wildcardBacktrack ? `(${negate(wildcardBacktrack, "")}+?|${negate(delimiter, "")}+?)` : `([^]+?)`,
|
|
366
|
+
key: token
|
|
367
|
+
});
|
|
368
|
+
wildcardBacktrack = "";
|
|
369
|
+
hasSegmentCapture |= prevCaptureType = 2;
|
|
322
370
|
}
|
|
323
|
-
keys.push(token);
|
|
324
371
|
backtrack = "";
|
|
325
|
-
isSafeSegmentParam = false;
|
|
326
372
|
continue;
|
|
327
373
|
}
|
|
374
|
+
throw new TypeError(`Unknown token type: ${token.type}`);
|
|
328
375
|
}
|
|
329
376
|
return result;
|
|
330
377
|
}
|
|
331
|
-
function negate(
|
|
332
|
-
if (
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
return `
|
|
341
|
-
}
|
|
342
|
-
function stringifyTokens(tokens) {
|
|
378
|
+
function negate(a, b) {
|
|
379
|
+
if (b.length > a.length)
|
|
380
|
+
return negate(b, a);
|
|
381
|
+
if (a === b)
|
|
382
|
+
b = "";
|
|
383
|
+
if (b.length > 1)
|
|
384
|
+
return `(?:(?!${escape(a)}|${escape(b)})[^])`;
|
|
385
|
+
if (a.length > 1)
|
|
386
|
+
return `(?:(?!${escape(a)})[^${escape(b)}])`;
|
|
387
|
+
return `[^${escape(a + b)}]`;
|
|
388
|
+
}
|
|
389
|
+
function stringifyTokens(tokens, index) {
|
|
343
390
|
let value = "";
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
const isSafe = isNameSafe(value2) && isNextNameSafe(tokens[i]);
|
|
347
|
-
return isSafe ? value2 : JSON.stringify(value2);
|
|
348
|
-
}
|
|
349
|
-
while (i < tokens.length) {
|
|
350
|
-
const token = tokens[i++];
|
|
391
|
+
while (index < tokens.length) {
|
|
392
|
+
const token = tokens[index++];
|
|
351
393
|
if (token.type === "text") {
|
|
352
394
|
value += escapeText(token.value);
|
|
353
395
|
continue;
|
|
354
396
|
}
|
|
355
397
|
if (token.type === "group") {
|
|
356
|
-
value +=
|
|
398
|
+
value += "{" + stringifyTokens(token.tokens, 0) + "}";
|
|
357
399
|
continue;
|
|
358
400
|
}
|
|
359
401
|
if (token.type === "param") {
|
|
360
|
-
value +=
|
|
402
|
+
value += ":" + stringifyName(token.name, tokens[index]);
|
|
361
403
|
continue;
|
|
362
404
|
}
|
|
363
405
|
if (token.type === "wildcard") {
|
|
364
|
-
value +=
|
|
406
|
+
value += "*" + stringifyName(token.name, tokens[index]);
|
|
365
407
|
continue;
|
|
366
408
|
}
|
|
367
409
|
throw new TypeError(`Unknown token type: ${token.type}`);
|
|
@@ -369,16 +411,15 @@ var require_dist = __commonJS((exports) => {
|
|
|
369
411
|
return value;
|
|
370
412
|
}
|
|
371
413
|
function stringify(data) {
|
|
372
|
-
return stringifyTokens(data.tokens);
|
|
414
|
+
return stringifyTokens(data.tokens, 0);
|
|
373
415
|
}
|
|
374
|
-
function
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
return true;
|
|
416
|
+
function stringifyName(name, next) {
|
|
417
|
+
if (!ID.test(name))
|
|
418
|
+
return JSON.stringify(name);
|
|
419
|
+
if ((next === null || next === undefined ? undefined : next.type) === "text" && ID_CONTINUE.test(next.value[0])) {
|
|
420
|
+
return JSON.stringify(name);
|
|
421
|
+
}
|
|
422
|
+
return name;
|
|
382
423
|
}
|
|
383
424
|
});
|
|
384
425
|
|