@kirejs/fivem 0.2.3 → 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/AGENT.md +27 -0
- package/dist/cjs/index.js +210 -195
- package/dist/esm/index.js +210 -195
- package/llms.txt +54 -0
- package/package.json +3 -3
package/AGENT.md
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# FiveM + Kire — agent guide
|
|
2
|
+
|
|
3
|
+
> For AI assistants working in this package. Part of the [Kire](https://github.com/drysius/kire) monorepo — see the repository root `CLAUDE.md` for architecture and conventions.
|
|
4
|
+
|
|
5
|
+
**Package:** `@kirejs/fivem`
|
|
6
|
+
|
|
7
|
+
FiveM NUI integration — render NUI pages and answer updates via RegisterNuiCallback (no HTTP server).
|
|
8
|
+
|
|
9
|
+
## Primary API
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
import { kireFivem } from "@kirejs/fivem";
|
|
13
|
+
|
|
14
|
+
const fivem = kireFivem({ views, wire: { instance: wire } });
|
|
15
|
+
RegisterNuiCallback(fivem.path, fivem.handler);
|
|
16
|
+
SendNuiMessage(JSON.stringify({ type: "page", html: await fivem.render("counter") }));
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Notes
|
|
20
|
+
|
|
21
|
+
- NUI client uses FiveMTransport; see the create-kire `fivem` template.
|
|
22
|
+
|
|
23
|
+
## Conventions
|
|
24
|
+
|
|
25
|
+
- Bun + Biome (tabs, strict TS). Run `bun test` and `bunx biome check` before finishing.
|
|
26
|
+
- `noExplicitAny` is off — use `any` without `biome-ignore` suppressions.
|
|
27
|
+
- Keep this file and `README.md` in sync with the code.
|
package/dist/cjs/index.js
CHANGED
|
@@ -111,12 +111,14 @@ function kirewirePlugin(kirewire, options = {}) {
|
|
|
111
111
|
}
|
|
112
112
|
const scriptUrl = options.scriptUrl ?? "/kirewire.js";
|
|
113
113
|
const updatePath = options.path ?? "/_wire";
|
|
114
|
+
const wsAttr = options.wsPath ? ` data-kirewire-ws="${options.wsPath}"` : "";
|
|
115
|
+
const channelAttr = options.channel ? ` data-kirewire-channel="${options.channel}"` : "";
|
|
114
116
|
kire.directive({
|
|
115
117
|
name: "kirewireScripts",
|
|
116
118
|
description: "Inject the Kirewire client runtime script tag.",
|
|
117
119
|
example: "@kirewireScripts",
|
|
118
120
|
onCall: (api) => {
|
|
119
|
-
api.append(`<script src="${scriptUrl}" data-kirewire-url="${updatePath}" defer></script>`);
|
|
121
|
+
api.append(`<script src="${scriptUrl}" data-kirewire-url="${updatePath}"${wsAttr}${channelAttr} defer></script>`);
|
|
120
122
|
}
|
|
121
123
|
});
|
|
122
124
|
}
|
|
@@ -138,6 +140,170 @@ class FiveMBroadcaster {
|
|
|
138
140
|
this.sendNuiMessage(JSON.stringify({ type: "kirewire:push", push }));
|
|
139
141
|
}
|
|
140
142
|
}
|
|
143
|
+
// core/src/utils/regex.ts
|
|
144
|
+
var NullProtoObj = function() {
|
|
145
|
+
return Object.create(null);
|
|
146
|
+
};
|
|
147
|
+
var TAG_OPEN_REGEX = /^<([a-zA-Z0-9_\-:.]+)/;
|
|
148
|
+
var TAG_CLOSE_REGEX = /^<\/([a-zA-Z0-9_\-:.]+)>/;
|
|
149
|
+
var ATTR_NAME_BREAK_REGEX = /\s|=|>|\/|\(/;
|
|
150
|
+
var WHITESPACE_REGEX = /\s/;
|
|
151
|
+
var HTML_VOID_TAGS = new Set([
|
|
152
|
+
"area",
|
|
153
|
+
"base",
|
|
154
|
+
"br",
|
|
155
|
+
"col",
|
|
156
|
+
"embed",
|
|
157
|
+
"hr",
|
|
158
|
+
"img",
|
|
159
|
+
"input",
|
|
160
|
+
"link",
|
|
161
|
+
"meta",
|
|
162
|
+
"param",
|
|
163
|
+
"source",
|
|
164
|
+
"track",
|
|
165
|
+
"wbr"
|
|
166
|
+
]);
|
|
167
|
+
var DIRECTIVE_NAME_REGEX = /^@([a-zA-Z0-9_\-.:]+)/;
|
|
168
|
+
var JS_IDENTIFIER_REGEX = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/;
|
|
169
|
+
var INTERPOLATION_PURE_REGEX = /^\s*\{\{\s*(.*?)\s*\}\}\s*$/;
|
|
170
|
+
var INTERPOLATION_GLOBAL_REGEX = /\{\{\s*(.*?)\s*\}\}/g;
|
|
171
|
+
var RESERVED_KEYWORDS_REGEX = /^(?:break|case|catch|class|const|continue|debugger|default|delete|do|else|export|extends|finally|for|function|if|import|in|instanceof|new|return|super|switch|this|throw|try|typeof|var|void|while|with|yield|enum|await|true|false|null|of)$/;
|
|
172
|
+
var HTML_ESCAPE_CHECK_REGEX = /[&<>"']/;
|
|
173
|
+
var HTML_ESCAPE_GLOBAL_REGEX = /[&<>"']/g;
|
|
174
|
+
var INTERPOLATION_START_REGEX = /{{/;
|
|
175
|
+
var WILDCARD_CHAR_REGEX = /\*/;
|
|
176
|
+
var AWAIT_KEYWORD_REGEX = /\bawait\b/g;
|
|
177
|
+
var QUOTED_STR_CHECK_REGEX = /^['"]/;
|
|
178
|
+
var STRIP_QUOTES_REGEX = /^['"]|['"]$/g;
|
|
179
|
+
function createFastMatcher(list) {
|
|
180
|
+
const sources = list.map((item) => {
|
|
181
|
+
if (item instanceof RegExp)
|
|
182
|
+
return item.source;
|
|
183
|
+
if (item.includes("*")) {
|
|
184
|
+
const parts = item.split("*");
|
|
185
|
+
const escapedParts = parts.map((p) => p.replace(/[.*+?^${}()|[\]\\]/g, (m) => `\\${m}`));
|
|
186
|
+
return escapedParts.join(".*");
|
|
187
|
+
}
|
|
188
|
+
return item.replace(/[.*+?^${}()|[\]\\]/g, (m) => `\\${m}`);
|
|
189
|
+
});
|
|
190
|
+
sources.sort((a, b) => b.length - a.length);
|
|
191
|
+
return new RegExp(`(?:${sources.join("|")})`);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
// core/src/utils/html.ts
|
|
195
|
+
var ESCAPE_MAP = {
|
|
196
|
+
"&": "&",
|
|
197
|
+
"<": "<",
|
|
198
|
+
">": ">",
|
|
199
|
+
'"': """,
|
|
200
|
+
"'": "'"
|
|
201
|
+
};
|
|
202
|
+
function escapeHtml(unsafe) {
|
|
203
|
+
if (unsafe === null || unsafe === undefined)
|
|
204
|
+
return "";
|
|
205
|
+
const type = typeof unsafe;
|
|
206
|
+
if (type === "number" || type === "boolean")
|
|
207
|
+
return String(unsafe);
|
|
208
|
+
if (type === "object" && typeof unsafe.toHtml === "function") {
|
|
209
|
+
return unsafe.toHtml();
|
|
210
|
+
}
|
|
211
|
+
const s = type === "string" ? unsafe : String(unsafe);
|
|
212
|
+
const n = s.length;
|
|
213
|
+
if (n <= 16) {
|
|
214
|
+
for (let i = 0;i < n; i++) {
|
|
215
|
+
const c = s.charCodeAt(i);
|
|
216
|
+
if (c === 38 || c === 60 || c === 62 || c === 34 || c === 39) {
|
|
217
|
+
return s.replace(HTML_ESCAPE_GLOBAL_REGEX, (m) => ESCAPE_MAP[m]);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
return s;
|
|
221
|
+
}
|
|
222
|
+
if (!HTML_ESCAPE_CHECK_REGEX.test(s))
|
|
223
|
+
return s;
|
|
224
|
+
return s.replace(HTML_ESCAPE_GLOBAL_REGEX, (m) => ESCAPE_MAP[m]);
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
// core/src/compiler/attr-codegen.ts
|
|
228
|
+
class AttrCodegen {
|
|
229
|
+
scanner;
|
|
230
|
+
onAsync;
|
|
231
|
+
usesEscape = false;
|
|
232
|
+
mixedAttrIdents = new Set;
|
|
233
|
+
interpRx = new RegExp(INTERPOLATION_GLOBAL_REGEX.source, "g");
|
|
234
|
+
constructor(scanner, onAsync) {
|
|
235
|
+
this.scanner = scanner;
|
|
236
|
+
this.onAsync = onAsync;
|
|
237
|
+
}
|
|
238
|
+
reset() {
|
|
239
|
+
this.usesEscape = false;
|
|
240
|
+
this.mixedAttrIdents.clear();
|
|
241
|
+
}
|
|
242
|
+
esc(str) {
|
|
243
|
+
return "`" + str.replace(/\\/g, "\\\\").replace(/`/g, "\\`").replace(/\$/g, "\\$") + "`";
|
|
244
|
+
}
|
|
245
|
+
escapeChunk(str) {
|
|
246
|
+
return str.replace(/\\/g, "\\\\").replace(/`/g, "\\`").replace(/\$/g, "\\$");
|
|
247
|
+
}
|
|
248
|
+
parseAttrCode(val) {
|
|
249
|
+
if (!INTERPOLATION_START_REGEX.test(val))
|
|
250
|
+
return val;
|
|
251
|
+
const pureMatch = val.match(INTERPOLATION_PURE_REGEX);
|
|
252
|
+
if (pureMatch)
|
|
253
|
+
return pureMatch[1];
|
|
254
|
+
this.usesEscape = true;
|
|
255
|
+
const res = val.replace(INTERPOLATION_GLOBAL_REGEX, (_, expr) => {
|
|
256
|
+
this.collectExpressionIdents(expr);
|
|
257
|
+
return `\${$escape(${expr})}`;
|
|
258
|
+
});
|
|
259
|
+
return `\`${res}\``;
|
|
260
|
+
}
|
|
261
|
+
parseHtmlAttrCode(val) {
|
|
262
|
+
if (!INTERPOLATION_START_REGEX.test(val))
|
|
263
|
+
return this.esc(escapeHtml(val));
|
|
264
|
+
const pureMatch = val.match(INTERPOLATION_PURE_REGEX);
|
|
265
|
+
if (pureMatch) {
|
|
266
|
+
const expr = pureMatch[1];
|
|
267
|
+
if (this.scanner.containsAwait(expr))
|
|
268
|
+
this.onAsync();
|
|
269
|
+
this.usesEscape = true;
|
|
270
|
+
return `$escape(${expr})`;
|
|
271
|
+
}
|
|
272
|
+
this.usesEscape = true;
|
|
273
|
+
let out = "";
|
|
274
|
+
let lastIndex = 0;
|
|
275
|
+
const rx = this.interpRx;
|
|
276
|
+
rx.lastIndex = 0;
|
|
277
|
+
let match;
|
|
278
|
+
while ((match = rx.exec(val)) !== null) {
|
|
279
|
+
const literalChunk = val.slice(lastIndex, match.index);
|
|
280
|
+
if (literalChunk)
|
|
281
|
+
out += this.escapeChunk(escapeHtml(literalChunk));
|
|
282
|
+
const expr = match[1] || "";
|
|
283
|
+
this.collectExpressionIdents(expr);
|
|
284
|
+
if (this.scanner.containsAwait(expr))
|
|
285
|
+
this.onAsync();
|
|
286
|
+
out += `\${$escape(${expr})}`;
|
|
287
|
+
lastIndex = match.index + match[0].length;
|
|
288
|
+
}
|
|
289
|
+
const tail = val.slice(lastIndex);
|
|
290
|
+
if (tail)
|
|
291
|
+
out += this.escapeChunk(escapeHtml(tail));
|
|
292
|
+
return `\`${out}\``;
|
|
293
|
+
}
|
|
294
|
+
collectExpressionIdents(expr) {
|
|
295
|
+
const rx = /[a-zA-Z_$][a-zA-Z0-9_$]*/g;
|
|
296
|
+
let m;
|
|
297
|
+
while ((m = rx.exec(expr)) !== null) {
|
|
298
|
+
const id = m[0];
|
|
299
|
+
if (RESERVED_KEYWORDS_REGEX.test(id))
|
|
300
|
+
continue;
|
|
301
|
+
if (expr[m.index - 1] === ".")
|
|
302
|
+
continue;
|
|
303
|
+
this.mixedAttrIdents.add(id);
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
}
|
|
141
307
|
// core/src/lexer/balance.ts
|
|
142
308
|
function findInterpolationEnd(template, from, close) {
|
|
143
309
|
let inQuote = null;
|
|
@@ -260,90 +426,6 @@ function parseArgs(argsStr) {
|
|
|
260
426
|
return args;
|
|
261
427
|
}
|
|
262
428
|
|
|
263
|
-
// core/src/utils/regex.ts
|
|
264
|
-
var NullProtoObj = function() {
|
|
265
|
-
return Object.create(null);
|
|
266
|
-
};
|
|
267
|
-
var TAG_OPEN_REGEX = /^<([a-zA-Z0-9_\-:.]+)/;
|
|
268
|
-
var TAG_CLOSE_REGEX = /^<\/([a-zA-Z0-9_\-:.]+)>/;
|
|
269
|
-
var ATTR_NAME_BREAK_REGEX = /\s|=|>|\/|\(/;
|
|
270
|
-
var WHITESPACE_REGEX = /\s/;
|
|
271
|
-
var HTML_VOID_TAGS = new Set([
|
|
272
|
-
"area",
|
|
273
|
-
"base",
|
|
274
|
-
"br",
|
|
275
|
-
"col",
|
|
276
|
-
"embed",
|
|
277
|
-
"hr",
|
|
278
|
-
"img",
|
|
279
|
-
"input",
|
|
280
|
-
"link",
|
|
281
|
-
"meta",
|
|
282
|
-
"param",
|
|
283
|
-
"source",
|
|
284
|
-
"track",
|
|
285
|
-
"wbr"
|
|
286
|
-
]);
|
|
287
|
-
var DIRECTIVE_NAME_REGEX = /^@([a-zA-Z0-9_\-.:]+)/;
|
|
288
|
-
var JS_IDENTIFIER_REGEX = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/;
|
|
289
|
-
var INTERPOLATION_PURE_REGEX = /^\s*\{\{\s*(.*?)\s*\}\}\s*$/;
|
|
290
|
-
var INTERPOLATION_GLOBAL_REGEX = /\{\{\s*(.*?)\s*\}\}/g;
|
|
291
|
-
var RESERVED_KEYWORDS_REGEX = /^(?:break|case|catch|class|const|continue|debugger|default|delete|do|else|export|extends|finally|for|function|if|import|in|instanceof|new|return|super|switch|this|throw|try|typeof|var|void|while|with|yield|enum|await|true|false|null|of)$/;
|
|
292
|
-
var HTML_ESCAPE_CHECK_REGEX = /[&<>"']/;
|
|
293
|
-
var HTML_ESCAPE_GLOBAL_REGEX = /[&<>"']/g;
|
|
294
|
-
var INTERPOLATION_START_REGEX = /{{/;
|
|
295
|
-
var WILDCARD_CHAR_REGEX = /\*/;
|
|
296
|
-
var AWAIT_KEYWORD_REGEX = /\bawait\b/g;
|
|
297
|
-
var QUOTED_STR_CHECK_REGEX = /^['"]/;
|
|
298
|
-
var STRIP_QUOTES_REGEX = /^['"]|['"]$/g;
|
|
299
|
-
function createFastMatcher(list) {
|
|
300
|
-
const sources = list.map((item) => {
|
|
301
|
-
if (item instanceof RegExp)
|
|
302
|
-
return item.source;
|
|
303
|
-
if (item.includes("*")) {
|
|
304
|
-
const parts = item.split("*");
|
|
305
|
-
const escapedParts = parts.map((p) => p.replace(/[.*+?^${}()|[\]\\]/g, (m) => `\\${m}`));
|
|
306
|
-
return escapedParts.join(".*");
|
|
307
|
-
}
|
|
308
|
-
return item.replace(/[.*+?^${}()|[\]\\]/g, (m) => `\\${m}`);
|
|
309
|
-
});
|
|
310
|
-
sources.sort((a, b) => b.length - a.length);
|
|
311
|
-
return new RegExp(`(?:${sources.join("|")})`);
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
// core/src/utils/html.ts
|
|
315
|
-
var ESCAPE_MAP = {
|
|
316
|
-
"&": "&",
|
|
317
|
-
"<": "<",
|
|
318
|
-
">": ">",
|
|
319
|
-
'"': """,
|
|
320
|
-
"'": "'"
|
|
321
|
-
};
|
|
322
|
-
function escapeHtml(unsafe) {
|
|
323
|
-
if (unsafe === null || unsafe === undefined)
|
|
324
|
-
return "";
|
|
325
|
-
const type = typeof unsafe;
|
|
326
|
-
if (type === "number" || type === "boolean")
|
|
327
|
-
return String(unsafe);
|
|
328
|
-
if (type === "object" && typeof unsafe.toHtml === "function") {
|
|
329
|
-
return unsafe.toHtml();
|
|
330
|
-
}
|
|
331
|
-
const s = type === "string" ? unsafe : String(unsafe);
|
|
332
|
-
const n = s.length;
|
|
333
|
-
if (n <= 16) {
|
|
334
|
-
for (let i = 0;i < n; i++) {
|
|
335
|
-
const c = s.charCodeAt(i);
|
|
336
|
-
if (c === 38 || c === 60 || c === 62 || c === 34 || c === 39) {
|
|
337
|
-
return s.replace(HTML_ESCAPE_GLOBAL_REGEX, (m) => ESCAPE_MAP[m]);
|
|
338
|
-
}
|
|
339
|
-
}
|
|
340
|
-
return s;
|
|
341
|
-
}
|
|
342
|
-
if (!HTML_ESCAPE_CHECK_REGEX.test(s))
|
|
343
|
-
return s;
|
|
344
|
-
return s.replace(HTML_ESCAPE_GLOBAL_REGEX, (m) => ESCAPE_MAP[m]);
|
|
345
|
-
}
|
|
346
|
-
|
|
347
429
|
// core/src/utils/base64.ts
|
|
348
430
|
function hasNodeBuffer() {
|
|
349
431
|
return typeof Buffer !== "undefined" && typeof Buffer.from === "function";
|
|
@@ -534,87 +616,6 @@ function resolveSourceLocation(map, genLine, genCol) {
|
|
|
534
616
|
return bestMatch;
|
|
535
617
|
}
|
|
536
618
|
|
|
537
|
-
// core/src/compiler/attr-codegen.ts
|
|
538
|
-
class AttrCodegen {
|
|
539
|
-
scanner;
|
|
540
|
-
onAsync;
|
|
541
|
-
usesEscape = false;
|
|
542
|
-
mixedAttrIdents = new Set;
|
|
543
|
-
interpRx = new RegExp(INTERPOLATION_GLOBAL_REGEX.source, "g");
|
|
544
|
-
constructor(scanner, onAsync) {
|
|
545
|
-
this.scanner = scanner;
|
|
546
|
-
this.onAsync = onAsync;
|
|
547
|
-
}
|
|
548
|
-
reset() {
|
|
549
|
-
this.usesEscape = false;
|
|
550
|
-
this.mixedAttrIdents.clear();
|
|
551
|
-
}
|
|
552
|
-
esc(str) {
|
|
553
|
-
return "`" + str.replace(/\\/g, "\\\\").replace(/`/g, "\\`").replace(/\$/g, "\\$") + "`";
|
|
554
|
-
}
|
|
555
|
-
escapeChunk(str) {
|
|
556
|
-
return str.replace(/\\/g, "\\\\").replace(/`/g, "\\`").replace(/\$/g, "\\$");
|
|
557
|
-
}
|
|
558
|
-
parseAttrCode(val) {
|
|
559
|
-
if (!INTERPOLATION_START_REGEX.test(val))
|
|
560
|
-
return val;
|
|
561
|
-
const pureMatch = val.match(INTERPOLATION_PURE_REGEX);
|
|
562
|
-
if (pureMatch)
|
|
563
|
-
return pureMatch[1];
|
|
564
|
-
this.usesEscape = true;
|
|
565
|
-
const res = val.replace(INTERPOLATION_GLOBAL_REGEX, (_, expr) => {
|
|
566
|
-
this.collectExpressionIdents(expr);
|
|
567
|
-
return `\${$escape(${expr})}`;
|
|
568
|
-
});
|
|
569
|
-
return "`" + res + "`";
|
|
570
|
-
}
|
|
571
|
-
parseHtmlAttrCode(val) {
|
|
572
|
-
if (!INTERPOLATION_START_REGEX.test(val))
|
|
573
|
-
return this.esc(escapeHtml(val));
|
|
574
|
-
const pureMatch = val.match(INTERPOLATION_PURE_REGEX);
|
|
575
|
-
if (pureMatch) {
|
|
576
|
-
const expr = pureMatch[1];
|
|
577
|
-
if (this.scanner.containsAwait(expr))
|
|
578
|
-
this.onAsync();
|
|
579
|
-
this.usesEscape = true;
|
|
580
|
-
return `$escape(${expr})`;
|
|
581
|
-
}
|
|
582
|
-
this.usesEscape = true;
|
|
583
|
-
let out = "";
|
|
584
|
-
let lastIndex = 0;
|
|
585
|
-
const rx = this.interpRx;
|
|
586
|
-
rx.lastIndex = 0;
|
|
587
|
-
let match;
|
|
588
|
-
while ((match = rx.exec(val)) !== null) {
|
|
589
|
-
const literalChunk = val.slice(lastIndex, match.index);
|
|
590
|
-
if (literalChunk)
|
|
591
|
-
out += this.escapeChunk(escapeHtml(literalChunk));
|
|
592
|
-
const expr = match[1] || "";
|
|
593
|
-
this.collectExpressionIdents(expr);
|
|
594
|
-
if (this.scanner.containsAwait(expr))
|
|
595
|
-
this.onAsync();
|
|
596
|
-
out += `\${$escape(${expr})}`;
|
|
597
|
-
lastIndex = match.index + match[0].length;
|
|
598
|
-
}
|
|
599
|
-
const tail = val.slice(lastIndex);
|
|
600
|
-
if (tail)
|
|
601
|
-
out += this.escapeChunk(escapeHtml(tail));
|
|
602
|
-
return "`" + out + "`";
|
|
603
|
-
}
|
|
604
|
-
collectExpressionIdents(expr) {
|
|
605
|
-
const rx = /[a-zA-Z_$][a-zA-Z0-9_$]*/g;
|
|
606
|
-
let m;
|
|
607
|
-
while ((m = rx.exec(expr)) !== null) {
|
|
608
|
-
const id = m[0];
|
|
609
|
-
if (RESERVED_KEYWORDS_REGEX.test(id))
|
|
610
|
-
continue;
|
|
611
|
-
if (expr[m.index - 1] === ".")
|
|
612
|
-
continue;
|
|
613
|
-
this.mixedAttrIdents.add(id);
|
|
614
|
-
}
|
|
615
|
-
}
|
|
616
|
-
}
|
|
617
|
-
|
|
618
619
|
// core/src/compiler/js-scanner.ts
|
|
619
620
|
class JsScanner {
|
|
620
621
|
containsAwait(code) {
|
|
@@ -2955,7 +2956,14 @@ var checks_default = (kire) => {
|
|
|
2955
2956
|
signature: [`expr:any`],
|
|
2956
2957
|
children: true,
|
|
2957
2958
|
relatedTo: [`for`, `each`, `foreach`, `forelse`],
|
|
2958
|
-
closeBy: [
|
|
2959
|
+
closeBy: [
|
|
2960
|
+
`endempty`,
|
|
2961
|
+
`endfor`,
|
|
2962
|
+
`endeach`,
|
|
2963
|
+
`endforeach`,
|
|
2964
|
+
`endforelse`,
|
|
2965
|
+
`end`
|
|
2966
|
+
],
|
|
2959
2967
|
description: "Fallback branch for empty collections or falsy values, often used alongside @for or @each.",
|
|
2960
2968
|
example: `@empty(items)
|
|
2961
2969
|
<p>No items</p>
|
|
@@ -3171,7 +3179,6 @@ var loop_default = (kire) => {
|
|
|
3171
3179
|
const id = api.uid("fe");
|
|
3172
3180
|
const relatedNodes = api.node.related || [];
|
|
3173
3181
|
const hasEmptyBranch = relatedNodes.some((n) => n?.name === "empty");
|
|
3174
|
-
const exposeKey = key ? true : api.fullBody.includes("$loop") || api.allIdentifiers.has("$loop");
|
|
3175
3182
|
const exposeLoop = api.fullBody.includes("$loop") || api.allIdentifiers.has("$loop");
|
|
3176
3183
|
api.write(`{
|
|
3177
3184
|
const _src${id} = ${source};
|
|
@@ -3595,7 +3602,6 @@ var KireDirectives = {
|
|
|
3595
3602
|
natives_default(kire);
|
|
3596
3603
|
}
|
|
3597
3604
|
};
|
|
3598
|
-
|
|
3599
3605
|
// core/src/lexer/cursor.ts
|
|
3600
3606
|
class Cursor {
|
|
3601
3607
|
template;
|
|
@@ -3659,7 +3665,6 @@ class Cursor {
|
|
|
3659
3665
|
this.column = this.baseColumn;
|
|
3660
3666
|
}
|
|
3661
3667
|
}
|
|
3662
|
-
|
|
3663
3668
|
// core/src/lexer/lexer.ts
|
|
3664
3669
|
class Lexer extends Cursor {
|
|
3665
3670
|
kire;
|
|
@@ -3929,7 +3934,13 @@ class Lexer extends Cursor {
|
|
|
3929
3934
|
this.reportError(hasOpenDirective ? `@${rawName} does not close the current block` : `@${rawName} has no matching opening directive`, this.cursor, this.cursor + rawName.length + 1, loc);
|
|
3930
3935
|
}
|
|
3931
3936
|
this.advance(rawName.length + 1);
|
|
3932
|
-
this.addNode({
|
|
3937
|
+
this.addNode({
|
|
3938
|
+
type: "directive",
|
|
3939
|
+
name: rawName,
|
|
3940
|
+
args: [],
|
|
3941
|
+
children: [],
|
|
3942
|
+
loc
|
|
3943
|
+
});
|
|
3933
3944
|
return true;
|
|
3934
3945
|
}
|
|
3935
3946
|
const name = matchedName;
|
|
@@ -4218,7 +4229,11 @@ class Lexer extends Cursor {
|
|
|
4218
4229
|
end++;
|
|
4219
4230
|
}
|
|
4220
4231
|
if (end > this.cursor) {
|
|
4221
|
-
this.addNode({
|
|
4232
|
+
this.addNode({
|
|
4233
|
+
type: "text",
|
|
4234
|
+
content: this.slice(this.cursor, end),
|
|
4235
|
+
loc
|
|
4236
|
+
});
|
|
4222
4237
|
this.advance(end - this.cursor);
|
|
4223
4238
|
} else {
|
|
4224
4239
|
this.addNode({ type: "text", content: this.char(), loc });
|
|
@@ -4269,29 +4284,6 @@ function createKireFunction(_kire, execute, meta) {
|
|
|
4269
4284
|
return fn;
|
|
4270
4285
|
}
|
|
4271
4286
|
|
|
4272
|
-
// core/src/utils/browser.ts
|
|
4273
|
-
var throwNoAPI = (name) => {
|
|
4274
|
-
return () => {
|
|
4275
|
-
throw new Error(`Platform API '${name}' is not available in browser. Provide it via store or use virtual files.`);
|
|
4276
|
-
};
|
|
4277
|
-
};
|
|
4278
|
-
var platform = {
|
|
4279
|
-
readFile: throwNoAPI("readFile"),
|
|
4280
|
-
exists: () => false,
|
|
4281
|
-
readDir: throwNoAPI("readDir"),
|
|
4282
|
-
stat: throwNoAPI("stat"),
|
|
4283
|
-
writeFile: throwNoAPI("writeFile"),
|
|
4284
|
-
resolve: (...args) => args.join("/").replace(/\/+/g, "/"),
|
|
4285
|
-
join: (...args) => args.join("/").replace(/\/+/g, "/"),
|
|
4286
|
-
isAbsolute: (path) => path.startsWith("/") || path.startsWith("http"),
|
|
4287
|
-
relative: (_from, to) => to,
|
|
4288
|
-
cwd: () => "/",
|
|
4289
|
-
env: (_key) => {
|
|
4290
|
-
return;
|
|
4291
|
-
},
|
|
4292
|
-
isProd: () => false
|
|
4293
|
-
};
|
|
4294
|
-
|
|
4295
4287
|
// core/src/utils/attributes-bag.ts
|
|
4296
4288
|
function classString(input) {
|
|
4297
4289
|
if (input == null || input === false)
|
|
@@ -4429,6 +4421,29 @@ function createAttributes(attrs = {}) {
|
|
|
4429
4421
|
return new KireAttributes(attrs);
|
|
4430
4422
|
}
|
|
4431
4423
|
|
|
4424
|
+
// core/src/utils/browser.ts
|
|
4425
|
+
var throwNoAPI = (name) => {
|
|
4426
|
+
return () => {
|
|
4427
|
+
throw new Error(`Platform API '${name}' is not available in browser. Provide it via store or use virtual files.`);
|
|
4428
|
+
};
|
|
4429
|
+
};
|
|
4430
|
+
var platform = {
|
|
4431
|
+
readFile: throwNoAPI("readFile"),
|
|
4432
|
+
exists: () => false,
|
|
4433
|
+
readDir: throwNoAPI("readDir"),
|
|
4434
|
+
stat: throwNoAPI("stat"),
|
|
4435
|
+
writeFile: throwNoAPI("writeFile"),
|
|
4436
|
+
resolve: (...args) => args.join("/").replace(/\/+/g, "/"),
|
|
4437
|
+
join: (...args) => args.join("/").replace(/\/+/g, "/"),
|
|
4438
|
+
isAbsolute: (path) => path.startsWith("/") || path.startsWith("http"),
|
|
4439
|
+
relative: (_from, to) => to,
|
|
4440
|
+
cwd: () => "/",
|
|
4441
|
+
env: (_key) => {
|
|
4442
|
+
return;
|
|
4443
|
+
},
|
|
4444
|
+
isProd: () => false
|
|
4445
|
+
};
|
|
4446
|
+
|
|
4432
4447
|
// core/src/utils/error.ts
|
|
4433
4448
|
var SOURCE_MAP_PREFIX = "//# sourceMappingURL=data:application/json;charset=utf-8;base64,";
|
|
4434
4449
|
var STACK_FRAME_REGEX = /^\s*at\s+(?:(.*?)\s+\()?(.+?):(\d+):(\d+)\)?$/;
|
package/dist/esm/index.js
CHANGED
|
@@ -67,12 +67,14 @@ function kirewirePlugin(kirewire, options = {}) {
|
|
|
67
67
|
}
|
|
68
68
|
const scriptUrl = options.scriptUrl ?? "/kirewire.js";
|
|
69
69
|
const updatePath = options.path ?? "/_wire";
|
|
70
|
+
const wsAttr = options.wsPath ? ` data-kirewire-ws="${options.wsPath}"` : "";
|
|
71
|
+
const channelAttr = options.channel ? ` data-kirewire-channel="${options.channel}"` : "";
|
|
70
72
|
kire.directive({
|
|
71
73
|
name: "kirewireScripts",
|
|
72
74
|
description: "Inject the Kirewire client runtime script tag.",
|
|
73
75
|
example: "@kirewireScripts",
|
|
74
76
|
onCall: (api) => {
|
|
75
|
-
api.append(`<script src="${scriptUrl}" data-kirewire-url="${updatePath}" defer></script>`);
|
|
77
|
+
api.append(`<script src="${scriptUrl}" data-kirewire-url="${updatePath}"${wsAttr}${channelAttr} defer></script>`);
|
|
76
78
|
}
|
|
77
79
|
});
|
|
78
80
|
}
|
|
@@ -94,6 +96,170 @@ class FiveMBroadcaster {
|
|
|
94
96
|
this.sendNuiMessage(JSON.stringify({ type: "kirewire:push", push }));
|
|
95
97
|
}
|
|
96
98
|
}
|
|
99
|
+
// core/src/utils/regex.ts
|
|
100
|
+
var NullProtoObj = function() {
|
|
101
|
+
return Object.create(null);
|
|
102
|
+
};
|
|
103
|
+
var TAG_OPEN_REGEX = /^<([a-zA-Z0-9_\-:.]+)/;
|
|
104
|
+
var TAG_CLOSE_REGEX = /^<\/([a-zA-Z0-9_\-:.]+)>/;
|
|
105
|
+
var ATTR_NAME_BREAK_REGEX = /\s|=|>|\/|\(/;
|
|
106
|
+
var WHITESPACE_REGEX = /\s/;
|
|
107
|
+
var HTML_VOID_TAGS = new Set([
|
|
108
|
+
"area",
|
|
109
|
+
"base",
|
|
110
|
+
"br",
|
|
111
|
+
"col",
|
|
112
|
+
"embed",
|
|
113
|
+
"hr",
|
|
114
|
+
"img",
|
|
115
|
+
"input",
|
|
116
|
+
"link",
|
|
117
|
+
"meta",
|
|
118
|
+
"param",
|
|
119
|
+
"source",
|
|
120
|
+
"track",
|
|
121
|
+
"wbr"
|
|
122
|
+
]);
|
|
123
|
+
var DIRECTIVE_NAME_REGEX = /^@([a-zA-Z0-9_\-.:]+)/;
|
|
124
|
+
var JS_IDENTIFIER_REGEX = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/;
|
|
125
|
+
var INTERPOLATION_PURE_REGEX = /^\s*\{\{\s*(.*?)\s*\}\}\s*$/;
|
|
126
|
+
var INTERPOLATION_GLOBAL_REGEX = /\{\{\s*(.*?)\s*\}\}/g;
|
|
127
|
+
var RESERVED_KEYWORDS_REGEX = /^(?:break|case|catch|class|const|continue|debugger|default|delete|do|else|export|extends|finally|for|function|if|import|in|instanceof|new|return|super|switch|this|throw|try|typeof|var|void|while|with|yield|enum|await|true|false|null|of)$/;
|
|
128
|
+
var HTML_ESCAPE_CHECK_REGEX = /[&<>"']/;
|
|
129
|
+
var HTML_ESCAPE_GLOBAL_REGEX = /[&<>"']/g;
|
|
130
|
+
var INTERPOLATION_START_REGEX = /{{/;
|
|
131
|
+
var WILDCARD_CHAR_REGEX = /\*/;
|
|
132
|
+
var AWAIT_KEYWORD_REGEX = /\bawait\b/g;
|
|
133
|
+
var QUOTED_STR_CHECK_REGEX = /^['"]/;
|
|
134
|
+
var STRIP_QUOTES_REGEX = /^['"]|['"]$/g;
|
|
135
|
+
function createFastMatcher(list) {
|
|
136
|
+
const sources = list.map((item) => {
|
|
137
|
+
if (item instanceof RegExp)
|
|
138
|
+
return item.source;
|
|
139
|
+
if (item.includes("*")) {
|
|
140
|
+
const parts = item.split("*");
|
|
141
|
+
const escapedParts = parts.map((p) => p.replace(/[.*+?^${}()|[\]\\]/g, (m) => `\\${m}`));
|
|
142
|
+
return escapedParts.join(".*");
|
|
143
|
+
}
|
|
144
|
+
return item.replace(/[.*+?^${}()|[\]\\]/g, (m) => `\\${m}`);
|
|
145
|
+
});
|
|
146
|
+
sources.sort((a, b) => b.length - a.length);
|
|
147
|
+
return new RegExp(`(?:${sources.join("|")})`);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// core/src/utils/html.ts
|
|
151
|
+
var ESCAPE_MAP = {
|
|
152
|
+
"&": "&",
|
|
153
|
+
"<": "<",
|
|
154
|
+
">": ">",
|
|
155
|
+
'"': """,
|
|
156
|
+
"'": "'"
|
|
157
|
+
};
|
|
158
|
+
function escapeHtml(unsafe) {
|
|
159
|
+
if (unsafe === null || unsafe === undefined)
|
|
160
|
+
return "";
|
|
161
|
+
const type = typeof unsafe;
|
|
162
|
+
if (type === "number" || type === "boolean")
|
|
163
|
+
return String(unsafe);
|
|
164
|
+
if (type === "object" && typeof unsafe.toHtml === "function") {
|
|
165
|
+
return unsafe.toHtml();
|
|
166
|
+
}
|
|
167
|
+
const s = type === "string" ? unsafe : String(unsafe);
|
|
168
|
+
const n = s.length;
|
|
169
|
+
if (n <= 16) {
|
|
170
|
+
for (let i = 0;i < n; i++) {
|
|
171
|
+
const c = s.charCodeAt(i);
|
|
172
|
+
if (c === 38 || c === 60 || c === 62 || c === 34 || c === 39) {
|
|
173
|
+
return s.replace(HTML_ESCAPE_GLOBAL_REGEX, (m) => ESCAPE_MAP[m]);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
return s;
|
|
177
|
+
}
|
|
178
|
+
if (!HTML_ESCAPE_CHECK_REGEX.test(s))
|
|
179
|
+
return s;
|
|
180
|
+
return s.replace(HTML_ESCAPE_GLOBAL_REGEX, (m) => ESCAPE_MAP[m]);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
// core/src/compiler/attr-codegen.ts
|
|
184
|
+
class AttrCodegen {
|
|
185
|
+
scanner;
|
|
186
|
+
onAsync;
|
|
187
|
+
usesEscape = false;
|
|
188
|
+
mixedAttrIdents = new Set;
|
|
189
|
+
interpRx = new RegExp(INTERPOLATION_GLOBAL_REGEX.source, "g");
|
|
190
|
+
constructor(scanner, onAsync) {
|
|
191
|
+
this.scanner = scanner;
|
|
192
|
+
this.onAsync = onAsync;
|
|
193
|
+
}
|
|
194
|
+
reset() {
|
|
195
|
+
this.usesEscape = false;
|
|
196
|
+
this.mixedAttrIdents.clear();
|
|
197
|
+
}
|
|
198
|
+
esc(str) {
|
|
199
|
+
return "`" + str.replace(/\\/g, "\\\\").replace(/`/g, "\\`").replace(/\$/g, "\\$") + "`";
|
|
200
|
+
}
|
|
201
|
+
escapeChunk(str) {
|
|
202
|
+
return str.replace(/\\/g, "\\\\").replace(/`/g, "\\`").replace(/\$/g, "\\$");
|
|
203
|
+
}
|
|
204
|
+
parseAttrCode(val) {
|
|
205
|
+
if (!INTERPOLATION_START_REGEX.test(val))
|
|
206
|
+
return val;
|
|
207
|
+
const pureMatch = val.match(INTERPOLATION_PURE_REGEX);
|
|
208
|
+
if (pureMatch)
|
|
209
|
+
return pureMatch[1];
|
|
210
|
+
this.usesEscape = true;
|
|
211
|
+
const res = val.replace(INTERPOLATION_GLOBAL_REGEX, (_, expr) => {
|
|
212
|
+
this.collectExpressionIdents(expr);
|
|
213
|
+
return `\${$escape(${expr})}`;
|
|
214
|
+
});
|
|
215
|
+
return `\`${res}\``;
|
|
216
|
+
}
|
|
217
|
+
parseHtmlAttrCode(val) {
|
|
218
|
+
if (!INTERPOLATION_START_REGEX.test(val))
|
|
219
|
+
return this.esc(escapeHtml(val));
|
|
220
|
+
const pureMatch = val.match(INTERPOLATION_PURE_REGEX);
|
|
221
|
+
if (pureMatch) {
|
|
222
|
+
const expr = pureMatch[1];
|
|
223
|
+
if (this.scanner.containsAwait(expr))
|
|
224
|
+
this.onAsync();
|
|
225
|
+
this.usesEscape = true;
|
|
226
|
+
return `$escape(${expr})`;
|
|
227
|
+
}
|
|
228
|
+
this.usesEscape = true;
|
|
229
|
+
let out = "";
|
|
230
|
+
let lastIndex = 0;
|
|
231
|
+
const rx = this.interpRx;
|
|
232
|
+
rx.lastIndex = 0;
|
|
233
|
+
let match;
|
|
234
|
+
while ((match = rx.exec(val)) !== null) {
|
|
235
|
+
const literalChunk = val.slice(lastIndex, match.index);
|
|
236
|
+
if (literalChunk)
|
|
237
|
+
out += this.escapeChunk(escapeHtml(literalChunk));
|
|
238
|
+
const expr = match[1] || "";
|
|
239
|
+
this.collectExpressionIdents(expr);
|
|
240
|
+
if (this.scanner.containsAwait(expr))
|
|
241
|
+
this.onAsync();
|
|
242
|
+
out += `\${$escape(${expr})}`;
|
|
243
|
+
lastIndex = match.index + match[0].length;
|
|
244
|
+
}
|
|
245
|
+
const tail = val.slice(lastIndex);
|
|
246
|
+
if (tail)
|
|
247
|
+
out += this.escapeChunk(escapeHtml(tail));
|
|
248
|
+
return `\`${out}\``;
|
|
249
|
+
}
|
|
250
|
+
collectExpressionIdents(expr) {
|
|
251
|
+
const rx = /[a-zA-Z_$][a-zA-Z0-9_$]*/g;
|
|
252
|
+
let m;
|
|
253
|
+
while ((m = rx.exec(expr)) !== null) {
|
|
254
|
+
const id = m[0];
|
|
255
|
+
if (RESERVED_KEYWORDS_REGEX.test(id))
|
|
256
|
+
continue;
|
|
257
|
+
if (expr[m.index - 1] === ".")
|
|
258
|
+
continue;
|
|
259
|
+
this.mixedAttrIdents.add(id);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
}
|
|
97
263
|
// core/src/lexer/balance.ts
|
|
98
264
|
function findInterpolationEnd(template, from, close) {
|
|
99
265
|
let inQuote = null;
|
|
@@ -216,90 +382,6 @@ function parseArgs(argsStr) {
|
|
|
216
382
|
return args;
|
|
217
383
|
}
|
|
218
384
|
|
|
219
|
-
// core/src/utils/regex.ts
|
|
220
|
-
var NullProtoObj = function() {
|
|
221
|
-
return Object.create(null);
|
|
222
|
-
};
|
|
223
|
-
var TAG_OPEN_REGEX = /^<([a-zA-Z0-9_\-:.]+)/;
|
|
224
|
-
var TAG_CLOSE_REGEX = /^<\/([a-zA-Z0-9_\-:.]+)>/;
|
|
225
|
-
var ATTR_NAME_BREAK_REGEX = /\s|=|>|\/|\(/;
|
|
226
|
-
var WHITESPACE_REGEX = /\s/;
|
|
227
|
-
var HTML_VOID_TAGS = new Set([
|
|
228
|
-
"area",
|
|
229
|
-
"base",
|
|
230
|
-
"br",
|
|
231
|
-
"col",
|
|
232
|
-
"embed",
|
|
233
|
-
"hr",
|
|
234
|
-
"img",
|
|
235
|
-
"input",
|
|
236
|
-
"link",
|
|
237
|
-
"meta",
|
|
238
|
-
"param",
|
|
239
|
-
"source",
|
|
240
|
-
"track",
|
|
241
|
-
"wbr"
|
|
242
|
-
]);
|
|
243
|
-
var DIRECTIVE_NAME_REGEX = /^@([a-zA-Z0-9_\-.:]+)/;
|
|
244
|
-
var JS_IDENTIFIER_REGEX = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/;
|
|
245
|
-
var INTERPOLATION_PURE_REGEX = /^\s*\{\{\s*(.*?)\s*\}\}\s*$/;
|
|
246
|
-
var INTERPOLATION_GLOBAL_REGEX = /\{\{\s*(.*?)\s*\}\}/g;
|
|
247
|
-
var RESERVED_KEYWORDS_REGEX = /^(?:break|case|catch|class|const|continue|debugger|default|delete|do|else|export|extends|finally|for|function|if|import|in|instanceof|new|return|super|switch|this|throw|try|typeof|var|void|while|with|yield|enum|await|true|false|null|of)$/;
|
|
248
|
-
var HTML_ESCAPE_CHECK_REGEX = /[&<>"']/;
|
|
249
|
-
var HTML_ESCAPE_GLOBAL_REGEX = /[&<>"']/g;
|
|
250
|
-
var INTERPOLATION_START_REGEX = /{{/;
|
|
251
|
-
var WILDCARD_CHAR_REGEX = /\*/;
|
|
252
|
-
var AWAIT_KEYWORD_REGEX = /\bawait\b/g;
|
|
253
|
-
var QUOTED_STR_CHECK_REGEX = /^['"]/;
|
|
254
|
-
var STRIP_QUOTES_REGEX = /^['"]|['"]$/g;
|
|
255
|
-
function createFastMatcher(list) {
|
|
256
|
-
const sources = list.map((item) => {
|
|
257
|
-
if (item instanceof RegExp)
|
|
258
|
-
return item.source;
|
|
259
|
-
if (item.includes("*")) {
|
|
260
|
-
const parts = item.split("*");
|
|
261
|
-
const escapedParts = parts.map((p) => p.replace(/[.*+?^${}()|[\]\\]/g, (m) => `\\${m}`));
|
|
262
|
-
return escapedParts.join(".*");
|
|
263
|
-
}
|
|
264
|
-
return item.replace(/[.*+?^${}()|[\]\\]/g, (m) => `\\${m}`);
|
|
265
|
-
});
|
|
266
|
-
sources.sort((a, b) => b.length - a.length);
|
|
267
|
-
return new RegExp(`(?:${sources.join("|")})`);
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
// core/src/utils/html.ts
|
|
271
|
-
var ESCAPE_MAP = {
|
|
272
|
-
"&": "&",
|
|
273
|
-
"<": "<",
|
|
274
|
-
">": ">",
|
|
275
|
-
'"': """,
|
|
276
|
-
"'": "'"
|
|
277
|
-
};
|
|
278
|
-
function escapeHtml(unsafe) {
|
|
279
|
-
if (unsafe === null || unsafe === undefined)
|
|
280
|
-
return "";
|
|
281
|
-
const type = typeof unsafe;
|
|
282
|
-
if (type === "number" || type === "boolean")
|
|
283
|
-
return String(unsafe);
|
|
284
|
-
if (type === "object" && typeof unsafe.toHtml === "function") {
|
|
285
|
-
return unsafe.toHtml();
|
|
286
|
-
}
|
|
287
|
-
const s = type === "string" ? unsafe : String(unsafe);
|
|
288
|
-
const n = s.length;
|
|
289
|
-
if (n <= 16) {
|
|
290
|
-
for (let i = 0;i < n; i++) {
|
|
291
|
-
const c = s.charCodeAt(i);
|
|
292
|
-
if (c === 38 || c === 60 || c === 62 || c === 34 || c === 39) {
|
|
293
|
-
return s.replace(HTML_ESCAPE_GLOBAL_REGEX, (m) => ESCAPE_MAP[m]);
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
return s;
|
|
297
|
-
}
|
|
298
|
-
if (!HTML_ESCAPE_CHECK_REGEX.test(s))
|
|
299
|
-
return s;
|
|
300
|
-
return s.replace(HTML_ESCAPE_GLOBAL_REGEX, (m) => ESCAPE_MAP[m]);
|
|
301
|
-
}
|
|
302
|
-
|
|
303
385
|
// core/src/utils/base64.ts
|
|
304
386
|
function hasNodeBuffer() {
|
|
305
387
|
return typeof Buffer !== "undefined" && typeof Buffer.from === "function";
|
|
@@ -490,87 +572,6 @@ function resolveSourceLocation(map, genLine, genCol) {
|
|
|
490
572
|
return bestMatch;
|
|
491
573
|
}
|
|
492
574
|
|
|
493
|
-
// core/src/compiler/attr-codegen.ts
|
|
494
|
-
class AttrCodegen {
|
|
495
|
-
scanner;
|
|
496
|
-
onAsync;
|
|
497
|
-
usesEscape = false;
|
|
498
|
-
mixedAttrIdents = new Set;
|
|
499
|
-
interpRx = new RegExp(INTERPOLATION_GLOBAL_REGEX.source, "g");
|
|
500
|
-
constructor(scanner, onAsync) {
|
|
501
|
-
this.scanner = scanner;
|
|
502
|
-
this.onAsync = onAsync;
|
|
503
|
-
}
|
|
504
|
-
reset() {
|
|
505
|
-
this.usesEscape = false;
|
|
506
|
-
this.mixedAttrIdents.clear();
|
|
507
|
-
}
|
|
508
|
-
esc(str) {
|
|
509
|
-
return "`" + str.replace(/\\/g, "\\\\").replace(/`/g, "\\`").replace(/\$/g, "\\$") + "`";
|
|
510
|
-
}
|
|
511
|
-
escapeChunk(str) {
|
|
512
|
-
return str.replace(/\\/g, "\\\\").replace(/`/g, "\\`").replace(/\$/g, "\\$");
|
|
513
|
-
}
|
|
514
|
-
parseAttrCode(val) {
|
|
515
|
-
if (!INTERPOLATION_START_REGEX.test(val))
|
|
516
|
-
return val;
|
|
517
|
-
const pureMatch = val.match(INTERPOLATION_PURE_REGEX);
|
|
518
|
-
if (pureMatch)
|
|
519
|
-
return pureMatch[1];
|
|
520
|
-
this.usesEscape = true;
|
|
521
|
-
const res = val.replace(INTERPOLATION_GLOBAL_REGEX, (_, expr) => {
|
|
522
|
-
this.collectExpressionIdents(expr);
|
|
523
|
-
return `\${$escape(${expr})}`;
|
|
524
|
-
});
|
|
525
|
-
return "`" + res + "`";
|
|
526
|
-
}
|
|
527
|
-
parseHtmlAttrCode(val) {
|
|
528
|
-
if (!INTERPOLATION_START_REGEX.test(val))
|
|
529
|
-
return this.esc(escapeHtml(val));
|
|
530
|
-
const pureMatch = val.match(INTERPOLATION_PURE_REGEX);
|
|
531
|
-
if (pureMatch) {
|
|
532
|
-
const expr = pureMatch[1];
|
|
533
|
-
if (this.scanner.containsAwait(expr))
|
|
534
|
-
this.onAsync();
|
|
535
|
-
this.usesEscape = true;
|
|
536
|
-
return `$escape(${expr})`;
|
|
537
|
-
}
|
|
538
|
-
this.usesEscape = true;
|
|
539
|
-
let out = "";
|
|
540
|
-
let lastIndex = 0;
|
|
541
|
-
const rx = this.interpRx;
|
|
542
|
-
rx.lastIndex = 0;
|
|
543
|
-
let match;
|
|
544
|
-
while ((match = rx.exec(val)) !== null) {
|
|
545
|
-
const literalChunk = val.slice(lastIndex, match.index);
|
|
546
|
-
if (literalChunk)
|
|
547
|
-
out += this.escapeChunk(escapeHtml(literalChunk));
|
|
548
|
-
const expr = match[1] || "";
|
|
549
|
-
this.collectExpressionIdents(expr);
|
|
550
|
-
if (this.scanner.containsAwait(expr))
|
|
551
|
-
this.onAsync();
|
|
552
|
-
out += `\${$escape(${expr})}`;
|
|
553
|
-
lastIndex = match.index + match[0].length;
|
|
554
|
-
}
|
|
555
|
-
const tail = val.slice(lastIndex);
|
|
556
|
-
if (tail)
|
|
557
|
-
out += this.escapeChunk(escapeHtml(tail));
|
|
558
|
-
return "`" + out + "`";
|
|
559
|
-
}
|
|
560
|
-
collectExpressionIdents(expr) {
|
|
561
|
-
const rx = /[a-zA-Z_$][a-zA-Z0-9_$]*/g;
|
|
562
|
-
let m;
|
|
563
|
-
while ((m = rx.exec(expr)) !== null) {
|
|
564
|
-
const id = m[0];
|
|
565
|
-
if (RESERVED_KEYWORDS_REGEX.test(id))
|
|
566
|
-
continue;
|
|
567
|
-
if (expr[m.index - 1] === ".")
|
|
568
|
-
continue;
|
|
569
|
-
this.mixedAttrIdents.add(id);
|
|
570
|
-
}
|
|
571
|
-
}
|
|
572
|
-
}
|
|
573
|
-
|
|
574
575
|
// core/src/compiler/js-scanner.ts
|
|
575
576
|
class JsScanner {
|
|
576
577
|
containsAwait(code) {
|
|
@@ -2911,7 +2912,14 @@ var checks_default = (kire) => {
|
|
|
2911
2912
|
signature: [`expr:any`],
|
|
2912
2913
|
children: true,
|
|
2913
2914
|
relatedTo: [`for`, `each`, `foreach`, `forelse`],
|
|
2914
|
-
closeBy: [
|
|
2915
|
+
closeBy: [
|
|
2916
|
+
`endempty`,
|
|
2917
|
+
`endfor`,
|
|
2918
|
+
`endeach`,
|
|
2919
|
+
`endforeach`,
|
|
2920
|
+
`endforelse`,
|
|
2921
|
+
`end`
|
|
2922
|
+
],
|
|
2915
2923
|
description: "Fallback branch for empty collections or falsy values, often used alongside @for or @each.",
|
|
2916
2924
|
example: `@empty(items)
|
|
2917
2925
|
<p>No items</p>
|
|
@@ -3127,7 +3135,6 @@ var loop_default = (kire) => {
|
|
|
3127
3135
|
const id = api.uid("fe");
|
|
3128
3136
|
const relatedNodes = api.node.related || [];
|
|
3129
3137
|
const hasEmptyBranch = relatedNodes.some((n) => n?.name === "empty");
|
|
3130
|
-
const exposeKey = key ? true : api.fullBody.includes("$loop") || api.allIdentifiers.has("$loop");
|
|
3131
3138
|
const exposeLoop = api.fullBody.includes("$loop") || api.allIdentifiers.has("$loop");
|
|
3132
3139
|
api.write(`{
|
|
3133
3140
|
const _src${id} = ${source};
|
|
@@ -3551,7 +3558,6 @@ var KireDirectives = {
|
|
|
3551
3558
|
natives_default(kire);
|
|
3552
3559
|
}
|
|
3553
3560
|
};
|
|
3554
|
-
|
|
3555
3561
|
// core/src/lexer/cursor.ts
|
|
3556
3562
|
class Cursor {
|
|
3557
3563
|
template;
|
|
@@ -3615,7 +3621,6 @@ class Cursor {
|
|
|
3615
3621
|
this.column = this.baseColumn;
|
|
3616
3622
|
}
|
|
3617
3623
|
}
|
|
3618
|
-
|
|
3619
3624
|
// core/src/lexer/lexer.ts
|
|
3620
3625
|
class Lexer extends Cursor {
|
|
3621
3626
|
kire;
|
|
@@ -3885,7 +3890,13 @@ class Lexer extends Cursor {
|
|
|
3885
3890
|
this.reportError(hasOpenDirective ? `@${rawName} does not close the current block` : `@${rawName} has no matching opening directive`, this.cursor, this.cursor + rawName.length + 1, loc);
|
|
3886
3891
|
}
|
|
3887
3892
|
this.advance(rawName.length + 1);
|
|
3888
|
-
this.addNode({
|
|
3893
|
+
this.addNode({
|
|
3894
|
+
type: "directive",
|
|
3895
|
+
name: rawName,
|
|
3896
|
+
args: [],
|
|
3897
|
+
children: [],
|
|
3898
|
+
loc
|
|
3899
|
+
});
|
|
3889
3900
|
return true;
|
|
3890
3901
|
}
|
|
3891
3902
|
const name = matchedName;
|
|
@@ -4174,7 +4185,11 @@ class Lexer extends Cursor {
|
|
|
4174
4185
|
end++;
|
|
4175
4186
|
}
|
|
4176
4187
|
if (end > this.cursor) {
|
|
4177
|
-
this.addNode({
|
|
4188
|
+
this.addNode({
|
|
4189
|
+
type: "text",
|
|
4190
|
+
content: this.slice(this.cursor, end),
|
|
4191
|
+
loc
|
|
4192
|
+
});
|
|
4178
4193
|
this.advance(end - this.cursor);
|
|
4179
4194
|
} else {
|
|
4180
4195
|
this.addNode({ type: "text", content: this.char(), loc });
|
|
@@ -4225,29 +4240,6 @@ function createKireFunction(_kire, execute, meta) {
|
|
|
4225
4240
|
return fn;
|
|
4226
4241
|
}
|
|
4227
4242
|
|
|
4228
|
-
// core/src/utils/browser.ts
|
|
4229
|
-
var throwNoAPI = (name) => {
|
|
4230
|
-
return () => {
|
|
4231
|
-
throw new Error(`Platform API '${name}' is not available in browser. Provide it via store or use virtual files.`);
|
|
4232
|
-
};
|
|
4233
|
-
};
|
|
4234
|
-
var platform = {
|
|
4235
|
-
readFile: throwNoAPI("readFile"),
|
|
4236
|
-
exists: () => false,
|
|
4237
|
-
readDir: throwNoAPI("readDir"),
|
|
4238
|
-
stat: throwNoAPI("stat"),
|
|
4239
|
-
writeFile: throwNoAPI("writeFile"),
|
|
4240
|
-
resolve: (...args) => args.join("/").replace(/\/+/g, "/"),
|
|
4241
|
-
join: (...args) => args.join("/").replace(/\/+/g, "/"),
|
|
4242
|
-
isAbsolute: (path) => path.startsWith("/") || path.startsWith("http"),
|
|
4243
|
-
relative: (_from, to) => to,
|
|
4244
|
-
cwd: () => "/",
|
|
4245
|
-
env: (_key) => {
|
|
4246
|
-
return;
|
|
4247
|
-
},
|
|
4248
|
-
isProd: () => false
|
|
4249
|
-
};
|
|
4250
|
-
|
|
4251
4243
|
// core/src/utils/attributes-bag.ts
|
|
4252
4244
|
function classString(input) {
|
|
4253
4245
|
if (input == null || input === false)
|
|
@@ -4385,6 +4377,29 @@ function createAttributes(attrs = {}) {
|
|
|
4385
4377
|
return new KireAttributes(attrs);
|
|
4386
4378
|
}
|
|
4387
4379
|
|
|
4380
|
+
// core/src/utils/browser.ts
|
|
4381
|
+
var throwNoAPI = (name) => {
|
|
4382
|
+
return () => {
|
|
4383
|
+
throw new Error(`Platform API '${name}' is not available in browser. Provide it via store or use virtual files.`);
|
|
4384
|
+
};
|
|
4385
|
+
};
|
|
4386
|
+
var platform = {
|
|
4387
|
+
readFile: throwNoAPI("readFile"),
|
|
4388
|
+
exists: () => false,
|
|
4389
|
+
readDir: throwNoAPI("readDir"),
|
|
4390
|
+
stat: throwNoAPI("stat"),
|
|
4391
|
+
writeFile: throwNoAPI("writeFile"),
|
|
4392
|
+
resolve: (...args) => args.join("/").replace(/\/+/g, "/"),
|
|
4393
|
+
join: (...args) => args.join("/").replace(/\/+/g, "/"),
|
|
4394
|
+
isAbsolute: (path) => path.startsWith("/") || path.startsWith("http"),
|
|
4395
|
+
relative: (_from, to) => to,
|
|
4396
|
+
cwd: () => "/",
|
|
4397
|
+
env: (_key) => {
|
|
4398
|
+
return;
|
|
4399
|
+
},
|
|
4400
|
+
isProd: () => false
|
|
4401
|
+
};
|
|
4402
|
+
|
|
4388
4403
|
// core/src/utils/error.ts
|
|
4389
4404
|
var SOURCE_MAP_PREFIX = "//# sourceMappingURL=data:application/json;charset=utf-8;base64,";
|
|
4390
4405
|
var STACK_FRAME_REGEX = /^\s*at\s+(?:(.*?)\s+\()?(.+?):(\d+):(\d+)\)?$/;
|
package/llms.txt
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# @kirejs/fivem — Kire + Kirewire for FiveM NUI
|
|
2
|
+
|
|
3
|
+
> Wires a Kire engine and Kirewire into a FiveM resource, where the NUI browser talks to the server through `RegisterNuiCallback` instead of HTTP.
|
|
4
|
+
|
|
5
|
+
FiveM has no HTTP server for the UI. The NUI page (a browser embedded in the game) posts Kirewire updates to a NUI callback, and the resource replies with the usual `{ snapshot, html, effects }`. `kireFivem(opts)` builds the Kire engine, loads `kirewirePlugin`, and returns the pieces you plug into FiveM natives. Requires `@kirejs/wire` and `kire`.
|
|
6
|
+
|
|
7
|
+
## API
|
|
8
|
+
|
|
9
|
+
- **`kireFivem(options)`** — returns `{ engine, render, handler, path, broadcaster }`.
|
|
10
|
+
- `engine` — the configured `Kire` instance (yours via `options.engine`, or a new one built from `views`).
|
|
11
|
+
- `render(view, data?)` — renders a `.kire` view to HTML (`engine.view`); may return a Promise. Use it to push the initial NUI page.
|
|
12
|
+
- `handler` — a `NuiCallback`; pass to `RegisterNuiCallback(path, handler)`. Internally `createFiveMHandler(wire, () => engine.fork())`, so each call gets a request-scoped fork.
|
|
13
|
+
- `path` — NUI callback name, default `"_wire"`.
|
|
14
|
+
- `broadcaster(sendNuiMessage)` — builds a `FiveMBroadcaster` from the host's `SendNuiMessage` (it receives a JSON string). Pass it to `new Kirewire({ broadcaster })` for server-to-NUI push effects.
|
|
15
|
+
- **`createFiveMHandler`, `FiveMBroadcaster`** — re-exported from `@kirejs/wire` for manual wiring.
|
|
16
|
+
- **Types** — `KireFivemOptions`, `PluginEntry` (a plugin or `[plugin, options]`).
|
|
17
|
+
|
|
18
|
+
## Options (`KireFivemOptions`)
|
|
19
|
+
|
|
20
|
+
- `views` (required) — directory holding the `.kire` NUI views.
|
|
21
|
+
- `wire` (required) — `{ instance, path?, scriptUrl? }`: the `Kirewire` instance, callback name (default `_wire`), and the URL the NUI page loads the client runtime from (default `/kirewire.js`).
|
|
22
|
+
- `extension` (default `kire`), `production`, `engine` (reuse an existing engine), `plugins` (plugin or `[plugin, opts]` entries), `globals` (exposed to every view).
|
|
23
|
+
|
|
24
|
+
## Usage
|
|
25
|
+
|
|
26
|
+
```ts
|
|
27
|
+
import { Kirewire } from "@kirejs/wire";
|
|
28
|
+
import { kireFivem } from "@kirejs/fivem";
|
|
29
|
+
|
|
30
|
+
const wire = new Kirewire({ secret: "change-me" });
|
|
31
|
+
wire.component(Counter);
|
|
32
|
+
|
|
33
|
+
const fivem = kireFivem({ views: "views", wire: { instance: wire } });
|
|
34
|
+
RegisterNuiCallback(fivem.path, fivem.handler);
|
|
35
|
+
|
|
36
|
+
// push the initial page to the NUI browser
|
|
37
|
+
SendNuiMessage(JSON.stringify({ type: "page", html: await fivem.render("counter") }));
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Push effects (server to NUI):
|
|
41
|
+
|
|
42
|
+
```ts
|
|
43
|
+
const broadcaster = fivem.broadcaster((json) => SendNuiMessage(json));
|
|
44
|
+
// give `broadcaster` to the Kirewire constructor options
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Notes
|
|
48
|
+
|
|
49
|
+
- Not HTTP: there is no route and no `res.view`. You deliver the initial HTML via `SendNuiMessage`; later updates flow through the registered NUI callback.
|
|
50
|
+
- The NUI page must be able to load the Kirewire client script at `scriptUrl` (ship it with the NUI files) and its transport must post to the same callback `path`.
|
|
51
|
+
- `render` may be async depending on the engine; always `await` it.
|
|
52
|
+
- `wire.path` has no leading slash; the plugin is configured internally with `/${path}`.
|
|
53
|
+
- `handler` forks the engine per call, so per-request globals do not leak between calls.
|
|
54
|
+
- Keep one `Kirewire` instance for the resource lifetime; component state lives there.
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kirejs/fivem",
|
|
3
3
|
"description": "FiveM (NUI) integration for Kire + Kirewire — render NUI pages and handle updates via RegisterNuiCallback.",
|
|
4
|
-
"version": "0.2.
|
|
4
|
+
"version": "0.2.5",
|
|
5
5
|
"main": "./dist/cjs/index.js",
|
|
6
6
|
"module": "./dist/esm/index.js",
|
|
7
7
|
"types": "./dist/types/index.d.ts",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"author": "drysius",
|
|
29
29
|
"license": "MIT",
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@kirejs/wire": "0.2.
|
|
32
|
-
"kire": "0.2.
|
|
31
|
+
"@kirejs/wire": "0.2.5",
|
|
32
|
+
"kire": "0.2.5"
|
|
33
33
|
}
|
|
34
34
|
}
|