@zntc/core 0.1.0

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/index.js ADDED
@@ -0,0 +1,3637 @@
1
+ import { createRequire } from "node:module";
2
+ var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
3
+ var __require = /* @__PURE__ */ createRequire(import.meta.url);
4
+
5
+ // ../../node_modules/.bun/detect-libc@2.1.2/node_modules/detect-libc/lib/process.js
6
+ var require_process = __commonJS((exports, module) => {
7
+ var isLinux = () => process.platform === "linux";
8
+ var report = null;
9
+ var getReport = () => {
10
+ if (!report) {
11
+ if (isLinux() && process.report) {
12
+ const orig = process.report.excludeNetwork;
13
+ process.report.excludeNetwork = true;
14
+ report = process.report.getReport();
15
+ process.report.excludeNetwork = orig;
16
+ } else {
17
+ report = {};
18
+ }
19
+ }
20
+ return report;
21
+ };
22
+ module.exports = { isLinux, getReport };
23
+ });
24
+
25
+ // ../../node_modules/.bun/detect-libc@2.1.2/node_modules/detect-libc/lib/filesystem.js
26
+ var require_filesystem = __commonJS((exports, module) => {
27
+ var fs = __require("fs");
28
+ var LDD_PATH = "/usr/bin/ldd";
29
+ var SELF_PATH = "/proc/self/exe";
30
+ var MAX_LENGTH = 2048;
31
+ var readFileSync4 = (path) => {
32
+ const fd = fs.openSync(path, "r");
33
+ const buffer = Buffer.alloc(MAX_LENGTH);
34
+ const bytesRead = fs.readSync(fd, buffer, 0, MAX_LENGTH, 0);
35
+ fs.close(fd, () => {});
36
+ return buffer.subarray(0, bytesRead);
37
+ };
38
+ var readFile = (path) => new Promise((resolve2, reject) => {
39
+ fs.open(path, "r", (err, fd) => {
40
+ if (err) {
41
+ reject(err);
42
+ } else {
43
+ const buffer = Buffer.alloc(MAX_LENGTH);
44
+ fs.read(fd, buffer, 0, MAX_LENGTH, 0, (_, bytesRead) => {
45
+ resolve2(buffer.subarray(0, bytesRead));
46
+ fs.close(fd, () => {});
47
+ });
48
+ }
49
+ });
50
+ });
51
+ module.exports = {
52
+ LDD_PATH,
53
+ SELF_PATH,
54
+ readFileSync: readFileSync4,
55
+ readFile
56
+ };
57
+ });
58
+
59
+ // ../../node_modules/.bun/detect-libc@2.1.2/node_modules/detect-libc/lib/elf.js
60
+ var require_elf = __commonJS((exports, module) => {
61
+ var interpreterPath = (elf) => {
62
+ if (elf.length < 64) {
63
+ return null;
64
+ }
65
+ if (elf.readUInt32BE(0) !== 2135247942) {
66
+ return null;
67
+ }
68
+ if (elf.readUInt8(4) !== 2) {
69
+ return null;
70
+ }
71
+ if (elf.readUInt8(5) !== 1) {
72
+ return null;
73
+ }
74
+ const offset = elf.readUInt32LE(32);
75
+ const size = elf.readUInt16LE(54);
76
+ const count = elf.readUInt16LE(56);
77
+ for (let i = 0;i < count; i++) {
78
+ const headerOffset = offset + i * size;
79
+ const type = elf.readUInt32LE(headerOffset);
80
+ if (type === 3) {
81
+ const fileOffset = elf.readUInt32LE(headerOffset + 8);
82
+ const fileSize = elf.readUInt32LE(headerOffset + 32);
83
+ return elf.subarray(fileOffset, fileOffset + fileSize).toString().replace(/\0.*$/g, "");
84
+ }
85
+ }
86
+ return null;
87
+ };
88
+ module.exports = {
89
+ interpreterPath
90
+ };
91
+ });
92
+
93
+ // ../../node_modules/.bun/detect-libc@2.1.2/node_modules/detect-libc/lib/detect-libc.js
94
+ var require_detect_libc = __commonJS((exports, module) => {
95
+ var childProcess = __require("child_process");
96
+ var { isLinux, getReport } = require_process();
97
+ var { LDD_PATH, SELF_PATH, readFile, readFileSync: readFileSync4 } = require_filesystem();
98
+ var { interpreterPath } = require_elf();
99
+ var cachedFamilyInterpreter;
100
+ var cachedFamilyFilesystem;
101
+ var cachedVersionFilesystem;
102
+ var command = "getconf GNU_LIBC_VERSION 2>&1 || true; ldd --version 2>&1 || true";
103
+ var commandOut = "";
104
+ var safeCommand = () => {
105
+ if (!commandOut) {
106
+ return new Promise((resolve2) => {
107
+ childProcess.exec(command, (err, out) => {
108
+ commandOut = err ? " " : out;
109
+ resolve2(commandOut);
110
+ });
111
+ });
112
+ }
113
+ return commandOut;
114
+ };
115
+ var safeCommandSync = () => {
116
+ if (!commandOut) {
117
+ try {
118
+ commandOut = childProcess.execSync(command, { encoding: "utf8" });
119
+ } catch (_err) {
120
+ commandOut = " ";
121
+ }
122
+ }
123
+ return commandOut;
124
+ };
125
+ var GLIBC = "glibc";
126
+ var RE_GLIBC_VERSION = /LIBC[a-z0-9 \-).]*?(\d+\.\d+)/i;
127
+ var MUSL = "musl";
128
+ var isFileMusl = (f) => f.includes("libc.musl-") || f.includes("ld-musl-");
129
+ var familyFromReport = () => {
130
+ const report = getReport();
131
+ if (report.header && report.header.glibcVersionRuntime) {
132
+ return GLIBC;
133
+ }
134
+ if (Array.isArray(report.sharedObjects)) {
135
+ if (report.sharedObjects.some(isFileMusl)) {
136
+ return MUSL;
137
+ }
138
+ }
139
+ return null;
140
+ };
141
+ var familyFromCommand = (out) => {
142
+ const [getconf, ldd1] = out.split(/[\r\n]+/);
143
+ if (getconf && getconf.includes(GLIBC)) {
144
+ return GLIBC;
145
+ }
146
+ if (ldd1 && ldd1.includes(MUSL)) {
147
+ return MUSL;
148
+ }
149
+ return null;
150
+ };
151
+ var familyFromInterpreterPath = (path) => {
152
+ if (path) {
153
+ if (path.includes("/ld-musl-")) {
154
+ return MUSL;
155
+ } else if (path.includes("/ld-linux-")) {
156
+ return GLIBC;
157
+ }
158
+ }
159
+ return null;
160
+ };
161
+ var getFamilyFromLddContent = (content) => {
162
+ content = content.toString();
163
+ if (content.includes("musl")) {
164
+ return MUSL;
165
+ }
166
+ if (content.includes("GNU C Library")) {
167
+ return GLIBC;
168
+ }
169
+ return null;
170
+ };
171
+ var familyFromFilesystem = async () => {
172
+ if (cachedFamilyFilesystem !== undefined) {
173
+ return cachedFamilyFilesystem;
174
+ }
175
+ cachedFamilyFilesystem = null;
176
+ try {
177
+ const lddContent = await readFile(LDD_PATH);
178
+ cachedFamilyFilesystem = getFamilyFromLddContent(lddContent);
179
+ } catch (e) {}
180
+ return cachedFamilyFilesystem;
181
+ };
182
+ var familyFromFilesystemSync = () => {
183
+ if (cachedFamilyFilesystem !== undefined) {
184
+ return cachedFamilyFilesystem;
185
+ }
186
+ cachedFamilyFilesystem = null;
187
+ try {
188
+ const lddContent = readFileSync4(LDD_PATH);
189
+ cachedFamilyFilesystem = getFamilyFromLddContent(lddContent);
190
+ } catch (e) {}
191
+ return cachedFamilyFilesystem;
192
+ };
193
+ var familyFromInterpreter = async () => {
194
+ if (cachedFamilyInterpreter !== undefined) {
195
+ return cachedFamilyInterpreter;
196
+ }
197
+ cachedFamilyInterpreter = null;
198
+ try {
199
+ const selfContent = await readFile(SELF_PATH);
200
+ const path = interpreterPath(selfContent);
201
+ cachedFamilyInterpreter = familyFromInterpreterPath(path);
202
+ } catch (e) {}
203
+ return cachedFamilyInterpreter;
204
+ };
205
+ var familyFromInterpreterSync = () => {
206
+ if (cachedFamilyInterpreter !== undefined) {
207
+ return cachedFamilyInterpreter;
208
+ }
209
+ cachedFamilyInterpreter = null;
210
+ try {
211
+ const selfContent = readFileSync4(SELF_PATH);
212
+ const path = interpreterPath(selfContent);
213
+ cachedFamilyInterpreter = familyFromInterpreterPath(path);
214
+ } catch (e) {}
215
+ return cachedFamilyInterpreter;
216
+ };
217
+ var family = async () => {
218
+ let family2 = null;
219
+ if (isLinux()) {
220
+ family2 = await familyFromInterpreter();
221
+ if (!family2) {
222
+ family2 = await familyFromFilesystem();
223
+ if (!family2) {
224
+ family2 = familyFromReport();
225
+ }
226
+ if (!family2) {
227
+ const out = await safeCommand();
228
+ family2 = familyFromCommand(out);
229
+ }
230
+ }
231
+ }
232
+ return family2;
233
+ };
234
+ var familySync = () => {
235
+ let family2 = null;
236
+ if (isLinux()) {
237
+ family2 = familyFromInterpreterSync();
238
+ if (!family2) {
239
+ family2 = familyFromFilesystemSync();
240
+ if (!family2) {
241
+ family2 = familyFromReport();
242
+ }
243
+ if (!family2) {
244
+ const out = safeCommandSync();
245
+ family2 = familyFromCommand(out);
246
+ }
247
+ }
248
+ }
249
+ return family2;
250
+ };
251
+ var isNonGlibcLinux = async () => isLinux() && await family() !== GLIBC;
252
+ var isNonGlibcLinuxSync = () => isLinux() && familySync() !== GLIBC;
253
+ var versionFromFilesystem = async () => {
254
+ if (cachedVersionFilesystem !== undefined) {
255
+ return cachedVersionFilesystem;
256
+ }
257
+ cachedVersionFilesystem = null;
258
+ try {
259
+ const lddContent = await readFile(LDD_PATH);
260
+ const versionMatch = lddContent.match(RE_GLIBC_VERSION);
261
+ if (versionMatch) {
262
+ cachedVersionFilesystem = versionMatch[1];
263
+ }
264
+ } catch (e) {}
265
+ return cachedVersionFilesystem;
266
+ };
267
+ var versionFromFilesystemSync = () => {
268
+ if (cachedVersionFilesystem !== undefined) {
269
+ return cachedVersionFilesystem;
270
+ }
271
+ cachedVersionFilesystem = null;
272
+ try {
273
+ const lddContent = readFileSync4(LDD_PATH);
274
+ const versionMatch = lddContent.match(RE_GLIBC_VERSION);
275
+ if (versionMatch) {
276
+ cachedVersionFilesystem = versionMatch[1];
277
+ }
278
+ } catch (e) {}
279
+ return cachedVersionFilesystem;
280
+ };
281
+ var versionFromReport = () => {
282
+ const report = getReport();
283
+ if (report.header && report.header.glibcVersionRuntime) {
284
+ return report.header.glibcVersionRuntime;
285
+ }
286
+ return null;
287
+ };
288
+ var versionSuffix = (s) => s.trim().split(/\s+/)[1];
289
+ var versionFromCommand = (out) => {
290
+ const [getconf, ldd1, ldd2] = out.split(/[\r\n]+/);
291
+ if (getconf && getconf.includes(GLIBC)) {
292
+ return versionSuffix(getconf);
293
+ }
294
+ if (ldd1 && ldd2 && ldd1.includes(MUSL)) {
295
+ return versionSuffix(ldd2);
296
+ }
297
+ return null;
298
+ };
299
+ var version = async () => {
300
+ let version2 = null;
301
+ if (isLinux()) {
302
+ version2 = await versionFromFilesystem();
303
+ if (!version2) {
304
+ version2 = versionFromReport();
305
+ }
306
+ if (!version2) {
307
+ const out = await safeCommand();
308
+ version2 = versionFromCommand(out);
309
+ }
310
+ }
311
+ return version2;
312
+ };
313
+ var versionSync = () => {
314
+ let version2 = null;
315
+ if (isLinux()) {
316
+ version2 = versionFromFilesystemSync();
317
+ if (!version2) {
318
+ version2 = versionFromReport();
319
+ }
320
+ if (!version2) {
321
+ const out = safeCommandSync();
322
+ version2 = versionFromCommand(out);
323
+ }
324
+ }
325
+ return version2;
326
+ };
327
+ module.exports = {
328
+ GLIBC,
329
+ MUSL,
330
+ family,
331
+ familySync,
332
+ isNonGlibcLinux,
333
+ isNonGlibcLinuxSync,
334
+ version,
335
+ versionSync
336
+ };
337
+ });
338
+
339
+ // ../../node_modules/.bun/lightningcss@1.32.0/node_modules/lightningcss/node/browserslistToTargets.js
340
+ var require_browserslistToTargets = __commonJS((exports, module) => {
341
+ var BROWSER_MAPPING = {
342
+ and_chr: "chrome",
343
+ and_ff: "firefox",
344
+ ie_mob: "ie",
345
+ op_mob: "opera",
346
+ and_qq: null,
347
+ and_uc: null,
348
+ baidu: null,
349
+ bb: null,
350
+ kaios: null,
351
+ op_mini: null
352
+ };
353
+ function browserslistToTargets(browserslist) {
354
+ let targets = {};
355
+ for (let browser of browserslist) {
356
+ let [name, v] = browser.split(" ");
357
+ if (BROWSER_MAPPING[name] === null) {
358
+ continue;
359
+ }
360
+ let version = parseVersion(v);
361
+ if (version == null) {
362
+ continue;
363
+ }
364
+ if (targets[name] == null || version < targets[name]) {
365
+ targets[name] = version;
366
+ }
367
+ }
368
+ return targets;
369
+ }
370
+ function parseVersion(version) {
371
+ let [major, minor = 0, patch = 0] = version.split("-")[0].split(".").map((v) => parseInt(v, 10));
372
+ if (isNaN(major) || isNaN(minor) || isNaN(patch)) {
373
+ return null;
374
+ }
375
+ return major << 16 | minor << 8 | patch;
376
+ }
377
+ module.exports = browserslistToTargets;
378
+ });
379
+
380
+ // ../../node_modules/.bun/lightningcss@1.32.0/node_modules/lightningcss/node/composeVisitors.js
381
+ var require_composeVisitors = __commonJS((exports, module) => {
382
+ function composeVisitors(visitors) {
383
+ if (visitors.length === 1) {
384
+ return visitors[0];
385
+ }
386
+ if (visitors.some((v) => typeof v === "function")) {
387
+ return (opts) => {
388
+ let v = visitors.map((v2) => typeof v2 === "function" ? v2(opts) : v2);
389
+ return composeVisitors(v);
390
+ };
391
+ }
392
+ let res = {};
393
+ composeSimpleVisitors(res, visitors, "StyleSheet");
394
+ composeSimpleVisitors(res, visitors, "StyleSheetExit");
395
+ composeObjectVisitors(res, visitors, "Rule", ruleVisitor, wrapCustomAndUnknownAtRule);
396
+ composeObjectVisitors(res, visitors, "RuleExit", ruleVisitor, wrapCustomAndUnknownAtRule);
397
+ composeObjectVisitors(res, visitors, "Declaration", declarationVisitor, wrapCustomProperty);
398
+ composeObjectVisitors(res, visitors, "DeclarationExit", declarationVisitor, wrapCustomProperty);
399
+ composeSimpleVisitors(res, visitors, "Url");
400
+ composeSimpleVisitors(res, visitors, "Color");
401
+ composeSimpleVisitors(res, visitors, "Image");
402
+ composeSimpleVisitors(res, visitors, "ImageExit");
403
+ composeSimpleVisitors(res, visitors, "Length");
404
+ composeSimpleVisitors(res, visitors, "Angle");
405
+ composeSimpleVisitors(res, visitors, "Ratio");
406
+ composeSimpleVisitors(res, visitors, "Resolution");
407
+ composeSimpleVisitors(res, visitors, "Time");
408
+ composeSimpleVisitors(res, visitors, "CustomIdent");
409
+ composeSimpleVisitors(res, visitors, "DashedIdent");
410
+ composeArrayFunctions(res, visitors, "MediaQuery");
411
+ composeArrayFunctions(res, visitors, "MediaQueryExit");
412
+ composeSimpleVisitors(res, visitors, "SupportsCondition");
413
+ composeSimpleVisitors(res, visitors, "SupportsConditionExit");
414
+ composeArrayFunctions(res, visitors, "Selector");
415
+ composeTokenVisitors(res, visitors, "Token", "token", false);
416
+ composeTokenVisitors(res, visitors, "Function", "function", false);
417
+ composeTokenVisitors(res, visitors, "FunctionExit", "function", true);
418
+ composeTokenVisitors(res, visitors, "Variable", "var", false);
419
+ composeTokenVisitors(res, visitors, "VariableExit", "var", true);
420
+ composeTokenVisitors(res, visitors, "EnvironmentVariable", "env", false);
421
+ composeTokenVisitors(res, visitors, "EnvironmentVariableExit", "env", true);
422
+ return res;
423
+ }
424
+ module.exports = composeVisitors;
425
+ function wrapCustomAndUnknownAtRule(k, f) {
426
+ if (k === "unknown") {
427
+ return (value) => f({ type: "unknown", value });
428
+ }
429
+ if (k === "custom") {
430
+ return (value) => f({ type: "custom", value });
431
+ }
432
+ return f;
433
+ }
434
+ function wrapCustomProperty(k, f) {
435
+ return k === "custom" ? (value) => f({ property: "custom", value }) : f;
436
+ }
437
+ function ruleVisitor(f, item) {
438
+ if (typeof f === "object") {
439
+ if (item.type === "unknown") {
440
+ let v = f.unknown;
441
+ if (typeof v === "object") {
442
+ v = v[item.value.name];
443
+ }
444
+ return v?.(item.value);
445
+ }
446
+ if (item.type === "custom") {
447
+ let v = f.custom;
448
+ if (typeof v === "object") {
449
+ v = v[item.value.name];
450
+ }
451
+ return v?.(item.value);
452
+ }
453
+ return f[item.type]?.(item);
454
+ }
455
+ return f?.(item);
456
+ }
457
+ function declarationVisitor(f, item) {
458
+ if (typeof f === "object") {
459
+ let name = item.property;
460
+ if (item.property === "unparsed") {
461
+ name = item.value.propertyId.property;
462
+ } else if (item.property === "custom") {
463
+ let v = f.custom;
464
+ if (typeof v === "object") {
465
+ v = v[item.value.name];
466
+ }
467
+ return v?.(item.value);
468
+ }
469
+ return f[name]?.(item);
470
+ }
471
+ return f?.(item);
472
+ }
473
+ function extractObjectsOrFunctions(visitors, key) {
474
+ let values = [];
475
+ let hasFunction = false;
476
+ let allKeys = new Set;
477
+ for (let visitor of visitors) {
478
+ let v = visitor[key];
479
+ if (v) {
480
+ if (typeof v === "function") {
481
+ hasFunction = true;
482
+ } else {
483
+ for (let key2 in v) {
484
+ allKeys.add(key2);
485
+ }
486
+ }
487
+ values.push(v);
488
+ }
489
+ }
490
+ return [values, hasFunction, allKeys];
491
+ }
492
+ function composeObjectVisitors(res, visitors, key, apply, wrapKey) {
493
+ let [values, hasFunction, allKeys] = extractObjectsOrFunctions(visitors, key);
494
+ if (values.length === 0) {
495
+ return;
496
+ }
497
+ if (values.length === 1) {
498
+ res[key] = values[0];
499
+ return;
500
+ }
501
+ let f = createArrayVisitor(visitors, (visitor, item) => apply(visitor[key], item));
502
+ if (hasFunction) {
503
+ res[key] = f;
504
+ } else {
505
+ let v = {};
506
+ for (let k of allKeys) {
507
+ v[k] = wrapKey(k, f);
508
+ }
509
+ res[key] = v;
510
+ }
511
+ }
512
+ function composeTokenVisitors(res, visitors, key, type, isExit) {
513
+ let [values, hasFunction, allKeys] = extractObjectsOrFunctions(visitors, key);
514
+ if (values.length === 0) {
515
+ return;
516
+ }
517
+ if (values.length === 1) {
518
+ res[key] = values[0];
519
+ return;
520
+ }
521
+ let f = createTokenVisitor(visitors, type, isExit);
522
+ if (hasFunction) {
523
+ res[key] = f;
524
+ } else {
525
+ let v = {};
526
+ for (let key2 of allKeys) {
527
+ v[key2] = f;
528
+ }
529
+ res[key] = v;
530
+ }
531
+ }
532
+ function createTokenVisitor(visitors, type, isExit) {
533
+ let v = createArrayVisitor(visitors, (visitor, item) => {
534
+ let f;
535
+ switch (item.type) {
536
+ case "token":
537
+ f = visitor.Token;
538
+ if (typeof f === "object") {
539
+ f = f[item.value.type];
540
+ }
541
+ break;
542
+ case "function":
543
+ f = isExit ? visitor.FunctionExit : visitor.Function;
544
+ if (typeof f === "object") {
545
+ f = f[item.value.name];
546
+ }
547
+ break;
548
+ case "var":
549
+ f = isExit ? visitor.VariableExit : visitor.Variable;
550
+ break;
551
+ case "env":
552
+ f = isExit ? visitor.EnvironmentVariableExit : visitor.EnvironmentVariable;
553
+ if (typeof f === "object") {
554
+ let name;
555
+ switch (item.value.name.type) {
556
+ case "ua":
557
+ case "unknown":
558
+ name = item.value.name.value;
559
+ break;
560
+ case "custom":
561
+ name = item.value.name.ident;
562
+ break;
563
+ }
564
+ f = f[name];
565
+ }
566
+ break;
567
+ case "color":
568
+ f = visitor.Color;
569
+ break;
570
+ case "url":
571
+ f = visitor.Url;
572
+ break;
573
+ case "length":
574
+ f = visitor.Length;
575
+ break;
576
+ case "angle":
577
+ f = visitor.Angle;
578
+ break;
579
+ case "time":
580
+ f = visitor.Time;
581
+ break;
582
+ case "resolution":
583
+ f = visitor.Resolution;
584
+ break;
585
+ case "dashed-ident":
586
+ f = visitor.DashedIdent;
587
+ break;
588
+ }
589
+ if (!f) {
590
+ return;
591
+ }
592
+ let res = f(item.value);
593
+ switch (item.type) {
594
+ case "color":
595
+ case "url":
596
+ case "length":
597
+ case "angle":
598
+ case "time":
599
+ case "resolution":
600
+ case "dashed-ident":
601
+ if (Array.isArray(res)) {
602
+ res = res.map((value) => ({ type: item.type, value }));
603
+ } else if (res) {
604
+ res = { type: item.type, value: res };
605
+ }
606
+ break;
607
+ }
608
+ return res;
609
+ });
610
+ return (value) => v({ type, value });
611
+ }
612
+ function extractFunctions(visitors, key) {
613
+ let functions = [];
614
+ for (let visitor of visitors) {
615
+ let f = visitor[key];
616
+ if (f) {
617
+ functions.push(f);
618
+ }
619
+ }
620
+ return functions;
621
+ }
622
+ function composeSimpleVisitors(res, visitors, key) {
623
+ let functions = extractFunctions(visitors, key);
624
+ if (functions.length === 0) {
625
+ return;
626
+ }
627
+ if (functions.length === 1) {
628
+ res[key] = functions[0];
629
+ return;
630
+ }
631
+ res[key] = (arg) => {
632
+ let mutated = false;
633
+ for (let f of functions) {
634
+ let res2 = f(arg);
635
+ if (res2) {
636
+ arg = res2;
637
+ mutated = true;
638
+ }
639
+ }
640
+ return mutated ? arg : undefined;
641
+ };
642
+ }
643
+ function composeArrayFunctions(res, visitors, key) {
644
+ let functions = extractFunctions(visitors, key);
645
+ if (functions.length === 0) {
646
+ return;
647
+ }
648
+ if (functions.length === 1) {
649
+ res[key] = functions[0];
650
+ return;
651
+ }
652
+ res[key] = createArrayVisitor(functions, (f, item) => f(item));
653
+ }
654
+ function createArrayVisitor(visitors, apply) {
655
+ let seen = new Bitset(visitors.length);
656
+ return (arg) => {
657
+ let arr = [arg];
658
+ let mutated = false;
659
+ seen.clear();
660
+ for (let i = 0;i < arr.length; i++) {
661
+ for (let v = 0;v < visitors.length && i < arr.length; ) {
662
+ if (seen.get(v)) {
663
+ v++;
664
+ continue;
665
+ }
666
+ let item = arr[i];
667
+ let visitor = visitors[v];
668
+ let res = apply(visitor, item);
669
+ if (Array.isArray(res)) {
670
+ if (res.length === 0) {
671
+ arr.splice(i, 1);
672
+ } else if (res.length === 1) {
673
+ arr[i] = res[0];
674
+ } else {
675
+ arr.splice(i, 1, ...res);
676
+ }
677
+ mutated = true;
678
+ seen.set(v);
679
+ v = 0;
680
+ } else if (res) {
681
+ arr[i] = res;
682
+ mutated = true;
683
+ seen.set(v);
684
+ v = 0;
685
+ } else {
686
+ v++;
687
+ }
688
+ }
689
+ }
690
+ if (!mutated) {
691
+ return;
692
+ }
693
+ return arr.length === 1 ? arr[0] : arr;
694
+ };
695
+ }
696
+
697
+ class Bitset {
698
+ constructor(maxBits = 32) {
699
+ this.bits = 0;
700
+ this.more = maxBits > 32 ? new Uint32Array(Math.ceil((maxBits - 32) / 32)) : null;
701
+ }
702
+ get(bit) {
703
+ if (bit >= 32 && this.more) {
704
+ let i = Math.floor((bit - 32) / 32);
705
+ let b = bit % 32;
706
+ return Boolean(this.more[i] & 1 << b);
707
+ } else {
708
+ return Boolean(this.bits & 1 << bit);
709
+ }
710
+ }
711
+ set(bit) {
712
+ if (bit >= 32 && this.more) {
713
+ let i = Math.floor((bit - 32) / 32);
714
+ let b = bit % 32;
715
+ this.more[i] |= 1 << b;
716
+ } else {
717
+ this.bits |= 1 << bit;
718
+ }
719
+ }
720
+ clear() {
721
+ this.bits = 0;
722
+ if (this.more) {
723
+ this.more.fill(0);
724
+ }
725
+ }
726
+ }
727
+ });
728
+
729
+ // ../../node_modules/.bun/lightningcss@1.32.0/node_modules/lightningcss/node/flags.js
730
+ var require_flags = __commonJS((exports) => {
731
+ exports.Features = {
732
+ Nesting: 1,
733
+ NotSelectorList: 2,
734
+ DirSelector: 4,
735
+ LangSelectorList: 8,
736
+ IsSelector: 16,
737
+ TextDecorationThicknessPercent: 32,
738
+ MediaIntervalSyntax: 64,
739
+ MediaRangeSyntax: 128,
740
+ CustomMediaQueries: 256,
741
+ ClampFunction: 512,
742
+ ColorFunction: 1024,
743
+ OklabColors: 2048,
744
+ LabColors: 4096,
745
+ P3Colors: 8192,
746
+ HexAlphaColors: 16384,
747
+ SpaceSeparatedColorNotation: 32768,
748
+ FontFamilySystemUi: 65536,
749
+ DoublePositionGradients: 131072,
750
+ VendorPrefixes: 262144,
751
+ LogicalProperties: 524288,
752
+ LightDark: 1048576,
753
+ Selectors: 31,
754
+ MediaQueries: 448,
755
+ Colors: 1113088
756
+ };
757
+ });
758
+
759
+ // ../../node_modules/.bun/lightningcss@1.32.0/node_modules/lightningcss/node/index.js
760
+ var require_node = __commonJS((exports, module) => {
761
+ var parts = [process.platform, process.arch];
762
+ if (process.platform === "linux") {
763
+ const { MUSL, familySync } = require_detect_libc();
764
+ const family = familySync();
765
+ if (family === MUSL) {
766
+ parts.push("musl");
767
+ } else if (process.arch === "arm") {
768
+ parts.push("gnueabihf");
769
+ } else {
770
+ parts.push("gnu");
771
+ }
772
+ } else if (process.platform === "win32") {
773
+ parts.push("msvc");
774
+ }
775
+ var native;
776
+ try {
777
+ native = __require(`lightningcss-${parts.join("-")}`);
778
+ } catch (err) {
779
+ native = __require(`../lightningcss.${parts.join("-")}.node`);
780
+ }
781
+ exports.transform = wrap(native.transform);
782
+ exports.transformStyleAttribute = wrap(native.transformStyleAttribute);
783
+ exports.bundle = wrap(native.bundle);
784
+ exports.bundleAsync = wrap(native.bundleAsync);
785
+ exports.browserslistToTargets = require_browserslistToTargets();
786
+ exports.composeVisitors = require_composeVisitors();
787
+ exports.Features = require_flags().Features;
788
+ function wrap(call) {
789
+ return (options) => {
790
+ if (typeof options.visitor === "function") {
791
+ let deps = [];
792
+ options.visitor = options.visitor({
793
+ addDependency(dep) {
794
+ deps.push(dep);
795
+ }
796
+ });
797
+ let result = call(options);
798
+ if (result instanceof Promise) {
799
+ result = result.then((res) => {
800
+ if (deps.length) {
801
+ res.dependencies ??= [];
802
+ res.dependencies.push(...deps);
803
+ }
804
+ return res;
805
+ });
806
+ } else if (deps.length) {
807
+ result.dependencies ??= [];
808
+ result.dependencies.push(...deps);
809
+ }
810
+ return result;
811
+ } else {
812
+ return call(options);
813
+ }
814
+ };
815
+ }
816
+ });
817
+
818
+ // index.ts
819
+ import { createRequire as createRequire3 } from "module";
820
+ import { existsSync as existsSync3, mkdirSync, writeFileSync as writeFileSync2 } from "fs";
821
+ import { join as join3, dirname as dirname3, resolve as resolve2 } from "path";
822
+ import { fileURLToPath } from "url";
823
+
824
+ // src/platforms.ts
825
+ var PLATFORMS = [
826
+ {
827
+ name: "linux-x64-gnu",
828
+ npmOs: "linux",
829
+ npmCpu: "x64",
830
+ npmLibc: "glibc",
831
+ zigTarget: "x86_64-linux-gnu",
832
+ ghaRunner: "ubuntu-latest"
833
+ },
834
+ {
835
+ name: "linux-arm64-gnu",
836
+ npmOs: "linux",
837
+ npmCpu: "arm64",
838
+ npmLibc: "glibc",
839
+ zigTarget: "aarch64-linux-gnu",
840
+ ghaRunner: "ubuntu-24.04-arm"
841
+ },
842
+ {
843
+ name: "linux-x64-musl",
844
+ npmOs: "linux",
845
+ npmCpu: "x64",
846
+ npmLibc: "musl",
847
+ zigTarget: "x86_64-linux-musl",
848
+ ghaRunner: "ubuntu-latest"
849
+ },
850
+ {
851
+ name: "linux-arm64-musl",
852
+ npmOs: "linux",
853
+ npmCpu: "arm64",
854
+ npmLibc: "musl",
855
+ zigTarget: "aarch64-linux-musl",
856
+ ghaRunner: "ubuntu-24.04-arm"
857
+ },
858
+ {
859
+ name: "darwin-x64",
860
+ npmOs: "darwin",
861
+ npmCpu: "x64",
862
+ zigTarget: "x86_64-macos",
863
+ ghaRunner: "macos-15-intel"
864
+ },
865
+ {
866
+ name: "darwin-arm64",
867
+ npmOs: "darwin",
868
+ npmCpu: "arm64",
869
+ zigTarget: "aarch64-macos",
870
+ ghaRunner: "macos-latest"
871
+ },
872
+ {
873
+ name: "win32-x64-msvc",
874
+ npmOs: "win32",
875
+ npmCpu: "x64",
876
+ zigTarget: "x86_64-windows-msvc",
877
+ ghaRunner: "windows-latest"
878
+ },
879
+ {
880
+ name: "win32-arm64-msvc",
881
+ npmOs: "win32",
882
+ npmCpu: "arm64",
883
+ zigTarget: "aarch64-windows-msvc",
884
+ ghaRunner: "windows-11-arm"
885
+ },
886
+ {
887
+ name: "win32-ia32-msvc",
888
+ npmOs: "win32",
889
+ npmCpu: "ia32",
890
+ zigTarget: "x86-windows-msvc",
891
+ ghaRunner: "windows-latest"
892
+ }
893
+ ];
894
+ function subPackageName(platform) {
895
+ return `@zntc/core-${platform.name}`;
896
+ }
897
+ function formatSupportedPlatforms() {
898
+ const groups = new Map;
899
+ for (const p of PLATFORMS) {
900
+ const key = `${p.npmOs}-${p.npmCpu}`;
901
+ if (!groups.has(key))
902
+ groups.set(key, []);
903
+ if (p.npmLibc)
904
+ groups.get(key).push(p.npmLibc);
905
+ }
906
+ return Array.from(groups, ([key, libcs]) => libcs.length > 0 ? `${key} (${libcs.join("/")})` : key).join(", ");
907
+ }
908
+
909
+ // ../shared/compat-engines.ts
910
+ var FEATURES = [
911
+ "arrow",
912
+ "class",
913
+ "template_literal",
914
+ "destructuring",
915
+ "for_of",
916
+ "spread",
917
+ "object_extensions",
918
+ "default_params",
919
+ "block_scoping",
920
+ "generator",
921
+ "new_target",
922
+ "exponentiation",
923
+ "async_await",
924
+ "object_spread",
925
+ "optional_catch_binding",
926
+ "nullish_coalescing",
927
+ "optional_chaining",
928
+ "logical_assignment",
929
+ "class_static_block",
930
+ "class_private_method",
931
+ "class_private_field",
932
+ "top_level_await",
933
+ "hashbang",
934
+ "using",
935
+ "regex_sticky",
936
+ "regex_dotall",
937
+ "regex_named_groups",
938
+ "unicode_brace_escape"
939
+ ];
940
+ var SUPPORT = {
941
+ arrow: {
942
+ chrome: [45, 0],
943
+ firefox: [22, 0],
944
+ safari: [10, 0],
945
+ edge: [12, 0],
946
+ node: [4, 0],
947
+ deno: [1, 0],
948
+ ios: [10, 0]
949
+ },
950
+ class: {
951
+ chrome: [49, 0],
952
+ firefox: [45, 0],
953
+ safari: [10, 1],
954
+ edge: [13, 0],
955
+ node: [6, 0],
956
+ deno: [1, 0],
957
+ ios: [10, 3]
958
+ },
959
+ template_literal: {
960
+ chrome: [41, 0],
961
+ firefox: [34, 0],
962
+ safari: [9, 0],
963
+ edge: [12, 0],
964
+ node: [4, 0],
965
+ deno: [1, 0],
966
+ ios: [9, 0]
967
+ },
968
+ destructuring: {
969
+ chrome: [49, 0],
970
+ firefox: [41, 0],
971
+ safari: [8, 0],
972
+ edge: [14, 0],
973
+ node: [6, 0],
974
+ deno: [1, 0],
975
+ ios: [8, 0]
976
+ },
977
+ for_of: {
978
+ chrome: [38, 0],
979
+ firefox: [13, 0],
980
+ safari: [7, 0],
981
+ edge: [12, 0],
982
+ node: [0, 12],
983
+ deno: [1, 0],
984
+ ios: [7, 0],
985
+ hermes: [0, 7]
986
+ },
987
+ spread: {
988
+ chrome: [46, 0],
989
+ firefox: [27, 0],
990
+ safari: [10, 0],
991
+ edge: [13, 0],
992
+ node: [5, 0],
993
+ deno: [1, 0],
994
+ ios: [10, 0],
995
+ hermes: [0, 7]
996
+ },
997
+ object_extensions: {
998
+ chrome: [43, 0],
999
+ firefox: [34, 0],
1000
+ safari: [9, 0],
1001
+ edge: [12, 0],
1002
+ node: [4, 0],
1003
+ deno: [1, 0],
1004
+ ios: [9, 0],
1005
+ hermes: [0, 7]
1006
+ },
1007
+ default_params: {
1008
+ chrome: [49, 0],
1009
+ firefox: [15, 0],
1010
+ safari: [10, 0],
1011
+ edge: [14, 0],
1012
+ node: [6, 0],
1013
+ deno: [1, 0],
1014
+ ios: [10, 0]
1015
+ },
1016
+ block_scoping: {
1017
+ chrome: [49, 0],
1018
+ firefox: [51, 0],
1019
+ safari: [11, 0],
1020
+ edge: [14, 0],
1021
+ node: [6, 0],
1022
+ deno: [1, 0],
1023
+ ios: [11, 0]
1024
+ },
1025
+ generator: {
1026
+ chrome: [50, 0],
1027
+ firefox: [53, 0],
1028
+ safari: [10, 0],
1029
+ edge: [13, 0],
1030
+ node: [6, 0],
1031
+ deno: [1, 0],
1032
+ ios: [10, 0]
1033
+ },
1034
+ new_target: {
1035
+ chrome: [46, 0],
1036
+ firefox: [41, 0],
1037
+ safari: [10, 0],
1038
+ edge: [14, 0],
1039
+ node: [5, 0],
1040
+ deno: [1, 0],
1041
+ ios: [10, 0]
1042
+ },
1043
+ exponentiation: {
1044
+ chrome: [52, 0],
1045
+ firefox: [52, 0],
1046
+ safari: [10, 1],
1047
+ edge: [14, 0],
1048
+ node: [7, 0],
1049
+ deno: [1, 0],
1050
+ ios: [10, 3],
1051
+ hermes: [0, 7]
1052
+ },
1053
+ async_await: {
1054
+ chrome: [55, 0],
1055
+ firefox: [52, 0],
1056
+ safari: [11, 0],
1057
+ edge: [15, 0],
1058
+ node: [7, 6],
1059
+ deno: [1, 0],
1060
+ ios: [11, 0]
1061
+ },
1062
+ object_spread: {
1063
+ chrome: [60, 0],
1064
+ firefox: [55, 0],
1065
+ safari: [11, 1],
1066
+ edge: [79, 0],
1067
+ node: [8, 3],
1068
+ deno: [1, 0],
1069
+ ios: [11, 3],
1070
+ hermes: [0, 7]
1071
+ },
1072
+ optional_catch_binding: {
1073
+ chrome: [66, 0],
1074
+ firefox: [58, 0],
1075
+ safari: [11, 1],
1076
+ edge: [79, 0],
1077
+ node: [10, 0],
1078
+ deno: [1, 0],
1079
+ ios: [11, 3],
1080
+ hermes: [0, 12]
1081
+ },
1082
+ nullish_coalescing: {
1083
+ chrome: [80, 0],
1084
+ firefox: [72, 0],
1085
+ safari: [13, 1],
1086
+ edge: [80, 0],
1087
+ node: [14, 0],
1088
+ deno: [1, 0],
1089
+ ios: [13, 4],
1090
+ hermes: [0, 7]
1091
+ },
1092
+ optional_chaining: {
1093
+ chrome: [91, 0],
1094
+ firefox: [74, 0],
1095
+ safari: [13, 1],
1096
+ edge: [91, 0],
1097
+ node: [16, 9],
1098
+ deno: [1, 9],
1099
+ ios: [13, 4],
1100
+ hermes: [0, 12]
1101
+ },
1102
+ logical_assignment: {
1103
+ chrome: [85, 0],
1104
+ firefox: [79, 0],
1105
+ safari: [14, 0],
1106
+ edge: [85, 0],
1107
+ node: [15, 0],
1108
+ deno: [1, 2],
1109
+ ios: [14, 0],
1110
+ hermes: [0, 7]
1111
+ },
1112
+ class_static_block: {
1113
+ chrome: [94, 0],
1114
+ firefox: [93, 0],
1115
+ safari: [16, 4],
1116
+ edge: [94, 0],
1117
+ node: [16, 11],
1118
+ deno: [1, 14],
1119
+ ios: [16, 4]
1120
+ },
1121
+ class_private_method: {
1122
+ chrome: [84, 0],
1123
+ firefox: [90, 0],
1124
+ safari: [15, 0],
1125
+ edge: [84, 0],
1126
+ node: [14, 6],
1127
+ deno: [1, 0],
1128
+ ios: [15, 0]
1129
+ },
1130
+ class_private_field: {
1131
+ chrome: [74, 0],
1132
+ firefox: [90, 0],
1133
+ safari: [14, 1],
1134
+ edge: [79, 0],
1135
+ node: [12, 0],
1136
+ deno: [1, 0],
1137
+ ios: [14, 5]
1138
+ },
1139
+ hashbang: {
1140
+ chrome: [74, 0],
1141
+ firefox: [67, 0],
1142
+ safari: [13, 1],
1143
+ edge: [79, 0],
1144
+ node: [12, 0],
1145
+ deno: [1, 0],
1146
+ ios: [13, 4],
1147
+ hermes: [0, 7]
1148
+ },
1149
+ using: {}
1150
+ };
1151
+ function verGte(a, b) {
1152
+ if (a[0] !== b[0])
1153
+ return a[0] > b[0];
1154
+ return a[1] >= b[1];
1155
+ }
1156
+ function isSupported(feature, engine, ver) {
1157
+ const min = SUPPORT[feature]?.[engine];
1158
+ if (!min)
1159
+ return false;
1160
+ return verGte(ver, min);
1161
+ }
1162
+ function computeUnsupportedFromEngines(engines) {
1163
+ let bits = 0;
1164
+ for (let i = 0;i < FEATURES.length; i++) {
1165
+ const feature = FEATURES[i];
1166
+ let anyUnsupported = false;
1167
+ for (const ev of engines) {
1168
+ if (!isSupported(feature, ev.engine, [ev.major, ev.minor])) {
1169
+ anyUnsupported = true;
1170
+ break;
1171
+ }
1172
+ }
1173
+ if (anyUnsupported)
1174
+ bits |= 1 << i;
1175
+ }
1176
+ return bits;
1177
+ }
1178
+ // ../shared/index.ts
1179
+ var ES_TARGET_BITS = {
1180
+ es5: 268435455,
1181
+ es2015: 117438464,
1182
+ es2016: 117436416,
1183
+ es2017: 117432320,
1184
+ es2018: 16760832,
1185
+ es2019: 16744448,
1186
+ es2020: 16646144,
1187
+ es2021: 16515072,
1188
+ es2022: 12582912,
1189
+ es2023: 8388608,
1190
+ es2024: 8388608,
1191
+ es2025: 0,
1192
+ esnext: 0
1193
+ };
1194
+ function isPlainObject(value) {
1195
+ return value !== null && typeof value === "object" && !Array.isArray(value);
1196
+ }
1197
+ function validateTsConfigRaw(raw) {
1198
+ if (raw === undefined)
1199
+ return;
1200
+ let config;
1201
+ try {
1202
+ config = JSON.parse(raw);
1203
+ } catch (err) {
1204
+ const reason = err instanceof Error ? err.message : String(err);
1205
+ throw new Error(`failed to parse --tsconfig-raw: ${reason}`);
1206
+ }
1207
+ if (!isPlainObject(config)) {
1208
+ throw new Error("failed to parse --tsconfig-raw: expected a JSON object");
1209
+ }
1210
+ }
1211
+ function buildOptionsJson(opts = {}, unsupportedOverride) {
1212
+ const payload = {};
1213
+ if (opts.target)
1214
+ payload.target = opts.target;
1215
+ if (unsupportedOverride !== undefined && unsupportedOverride !== 0)
1216
+ payload.unsupported = unsupportedOverride;
1217
+ if (opts.flow)
1218
+ payload.flow = true;
1219
+ if (opts.jsxInJs)
1220
+ payload.jsxInJs = true;
1221
+ if (opts.reactRefresh)
1222
+ payload.reactRefresh = true;
1223
+ if (opts.reactRefreshHookSignatures)
1224
+ payload.reactRefreshHookSignatures = true;
1225
+ if (opts.jsx !== undefined) {
1226
+ payload.jsx = opts.jsx === "automatic-dev" ? "automatic_dev" : opts.jsx;
1227
+ }
1228
+ if (opts.jsxFactory)
1229
+ payload.jsxFactory = opts.jsxFactory;
1230
+ if (opts.jsxFragment)
1231
+ payload.jsxFragment = opts.jsxFragment;
1232
+ if (opts.jsxImportSource)
1233
+ payload.jsxImportSource = opts.jsxImportSource;
1234
+ if (opts.dropConsole)
1235
+ payload.dropConsole = true;
1236
+ if (opts.dropDebugger)
1237
+ payload.dropDebugger = true;
1238
+ if (opts.asciiOnly)
1239
+ payload.asciiOnly = true;
1240
+ if (opts.charsetUtf8)
1241
+ payload.charsetUtf8 = true;
1242
+ if (opts.experimentalDecorators)
1243
+ payload.experimentalDecorators = true;
1244
+ if (opts.emitDecoratorMetadata)
1245
+ payload.emitDecoratorMetadata = true;
1246
+ if (opts.useDefineForClassFields === false)
1247
+ payload.useDefineForClassFields = false;
1248
+ if (opts.verbatimModuleSyntax !== undefined)
1249
+ payload.verbatimModuleSyntax = opts.verbatimModuleSyntax;
1250
+ if (opts.tsconfigPath)
1251
+ payload.tsconfigPath = opts.tsconfigPath;
1252
+ if (opts.tsconfigRaw)
1253
+ payload.tsconfigRaw = opts.tsconfigRaw;
1254
+ if (opts.format)
1255
+ payload.format = opts.format;
1256
+ if (opts.quotes)
1257
+ payload.quotes = opts.quotes;
1258
+ if (opts.platform === "react-native")
1259
+ payload.platform = "react_native";
1260
+ else if (opts.platform)
1261
+ payload.platform = opts.platform;
1262
+ if (opts.minifyWhitespace || opts.minify)
1263
+ payload.minifyWhitespace = true;
1264
+ if (opts.minifyIdentifiers || opts.minify)
1265
+ payload.minifyIdentifiers = true;
1266
+ if (opts.minifySyntax || opts.minify)
1267
+ payload.minifySyntax = true;
1268
+ if (opts.sourcemap)
1269
+ payload.sourcemap = true;
1270
+ if (opts.sourcemapDebugIds)
1271
+ payload.sourcemapDebugIds = true;
1272
+ if (opts.sourcesContent === false)
1273
+ payload.sourcesContent = false;
1274
+ if (opts.sourceRoot)
1275
+ payload.sourceRoot = opts.sourceRoot;
1276
+ if (opts.define && opts.define.length > 0)
1277
+ payload.define = opts.define;
1278
+ if (opts.stopAfter)
1279
+ payload.stopAfter = opts.stopAfter;
1280
+ return JSON.stringify(payload);
1281
+ }
1282
+ function parseBrowserslistEntry(entry) {
1283
+ const m = entry.trim().match(/^(\S+)\s+([\d.]+)(?:-[\d.]+)?$/);
1284
+ if (!m)
1285
+ return null;
1286
+ const name = m[1].toLowerCase();
1287
+ const versionStr = m[2];
1288
+ const [majStr, minStr = "0"] = versionStr.split(".");
1289
+ const major = parseInt(majStr, 10);
1290
+ const minor = parseInt(minStr, 10);
1291
+ if (Number.isNaN(major))
1292
+ return null;
1293
+ const map = {
1294
+ chrome: "chrome",
1295
+ and_chr: "chrome",
1296
+ firefox: "firefox",
1297
+ and_ff: "firefox",
1298
+ safari: "safari",
1299
+ ios_saf: "ios",
1300
+ edge: "edge",
1301
+ node: "node",
1302
+ deno: "deno",
1303
+ opera: "opera",
1304
+ op_mob: "opera",
1305
+ hermes: "hermes"
1306
+ };
1307
+ const engine = map[name];
1308
+ if (!engine)
1309
+ return null;
1310
+ return { engine, major, minor };
1311
+ }
1312
+ function browserslistToUnsupported(entries) {
1313
+ const engines = [];
1314
+ for (const e of entries) {
1315
+ const parsed = parseBrowserslistEntry(e);
1316
+ if (parsed)
1317
+ engines.push(parsed);
1318
+ }
1319
+ if (engines.length === 0)
1320
+ return 0;
1321
+ return computeUnsupportedFromEngines(engines);
1322
+ }
1323
+
1324
+ // src/runtime-polyfills.ts
1325
+ import { readFileSync } from "node:fs";
1326
+ import { createRequire as createRequire2 } from "node:module";
1327
+ import { dirname, resolve } from "node:path";
1328
+ var runtimeRequireOverride = null;
1329
+ function getRuntimeRequire() {
1330
+ return runtimeRequireOverride ?? createRequire2(import.meta.url);
1331
+ }
1332
+ var ES_TARGETS = new Set([
1333
+ "es5",
1334
+ "es2015",
1335
+ "es2016",
1336
+ "es2017",
1337
+ "es2018",
1338
+ "es2019",
1339
+ "es2020",
1340
+ "es2021",
1341
+ "es2022",
1342
+ "es2023",
1343
+ "es2024",
1344
+ "es2025",
1345
+ "esnext"
1346
+ ]);
1347
+ var DEVICE_TARGET_RE = /\b(?:iphone|ipad|ipod|galaxy|pixel|nexus|oneplus|xiaomi|redmi|huawei|motorola|moto)\b/i;
1348
+ var RUNTIME_POLYFILL_FEATURE_MODULES = [
1349
+ { feature: "aggregate_error", module: "es.aggregate-error" },
1350
+ { feature: "aggregate_error", module: "es.aggregate-error.cause" },
1351
+ { feature: "array_buffer", module: "es.array-buffer.constructor" },
1352
+ { feature: "array_buffer_detached", module: "es.array-buffer.detached" },
1353
+ { feature: "array_buffer_is_view", module: "es.array-buffer.is-view" },
1354
+ { feature: "array_buffer_slice", module: "es.array-buffer.slice" },
1355
+ { feature: "array_buffer_transfer", module: "es.array-buffer.transfer" },
1356
+ {
1357
+ feature: "array_buffer_transfer_to_fixed_length",
1358
+ module: "es.array-buffer.transfer-to-fixed-length"
1359
+ },
1360
+ { feature: "array_at", module: "es.array.at" },
1361
+ { feature: "array_concat", module: "es.array.concat" },
1362
+ { feature: "array_copy_within", module: "es.array.copy-within" },
1363
+ { feature: "array_every", module: "es.array.every" },
1364
+ { feature: "array_fill", module: "es.array.fill" },
1365
+ { feature: "array_filter", module: "es.array.filter" },
1366
+ { feature: "array_find", module: "es.array.find" },
1367
+ { feature: "array_find_index", module: "es.array.find-index" },
1368
+ { feature: "array_find_last", module: "es.array.find-last" },
1369
+ { feature: "array_find_last_index", module: "es.array.find-last-index" },
1370
+ { feature: "array_flat", module: "es.array.flat" },
1371
+ { feature: "array_flat_map", module: "es.array.flat-map" },
1372
+ { feature: "array_for_each", module: "es.array.for-each" },
1373
+ { feature: "array_from", module: "es.array.from" },
1374
+ { feature: "array_from_async", module: "es.array.from-async" },
1375
+ { feature: "array_includes", module: "es.array.includes" },
1376
+ { feature: "array_index_of", module: "es.array.index-of" },
1377
+ { feature: "array_is_array", module: "es.array.is-array" },
1378
+ { feature: "array_join", module: "es.array.join" },
1379
+ { feature: "array_last_index_of", module: "es.array.last-index-of" },
1380
+ { feature: "array_map", module: "es.array.map" },
1381
+ { feature: "array_of", module: "es.array.of" },
1382
+ { feature: "array_push", module: "es.array.push" },
1383
+ { feature: "array_reduce", module: "es.array.reduce" },
1384
+ { feature: "array_reduce_right", module: "es.array.reduce-right" },
1385
+ { feature: "array_reverse", module: "es.array.reverse" },
1386
+ { feature: "array_slice", module: "es.array.slice" },
1387
+ { feature: "array_some", module: "es.array.some" },
1388
+ { feature: "array_sort", module: "es.array.sort" },
1389
+ { feature: "array_splice", module: "es.array.splice" },
1390
+ { feature: "array_to_reversed", module: "es.array.to-reversed" },
1391
+ { feature: "array_to_sorted", module: "es.array.to-sorted" },
1392
+ { feature: "array_to_spliced", module: "es.array.to-spliced" },
1393
+ { feature: "array_unshift", module: "es.array.unshift" },
1394
+ { feature: "array_with", module: "es.array.with" },
1395
+ { feature: "async_disposable_stack", module: "es.async-disposable-stack.constructor" },
1396
+ { feature: "data_view", module: "es.data-view" },
1397
+ { feature: "data_view_get_float16", module: "es.data-view.get-float16" },
1398
+ { feature: "data_view_set_float16", module: "es.data-view.set-float16" },
1399
+ { feature: "date_now", module: "es.date.now" },
1400
+ { feature: "date_to_iso_string", module: "es.date.to-iso-string" },
1401
+ { feature: "disposable_stack", module: "es.disposable-stack.constructor" },
1402
+ { feature: "error_is_error", module: "es.error.is-error" },
1403
+ { feature: "escape", module: "es.escape" },
1404
+ { feature: "function_bind", module: "es.function.bind" },
1405
+ { feature: "global_this", module: "es.global-this" },
1406
+ { feature: "iterator", module: "es.iterator.constructor" },
1407
+ { feature: "iterator_drop", module: "es.iterator.drop" },
1408
+ { feature: "iterator_every", module: "es.iterator.every" },
1409
+ { feature: "iterator_filter", module: "es.iterator.filter" },
1410
+ { feature: "iterator_find", module: "es.iterator.find" },
1411
+ { feature: "iterator_flat_map", module: "es.iterator.flat-map" },
1412
+ { feature: "iterator_for_each", module: "es.iterator.for-each" },
1413
+ { feature: "iterator_from", module: "es.iterator.from" },
1414
+ { feature: "iterator_map", module: "es.iterator.map" },
1415
+ { feature: "iterator_reduce", module: "es.iterator.reduce" },
1416
+ { feature: "iterator_some", module: "es.iterator.some" },
1417
+ { feature: "iterator_take", module: "es.iterator.take" },
1418
+ { feature: "iterator_to_array", module: "es.iterator.to-array" },
1419
+ { feature: "json_is_raw_json", module: "es.json.is-raw-json" },
1420
+ { feature: "json_parse", module: "es.json.parse" },
1421
+ { feature: "json_raw_json", module: "es.json.raw-json" },
1422
+ { feature: "json_stringify", module: "es.json.stringify" },
1423
+ { feature: "map", module: "es.map" },
1424
+ { feature: "map_get_or_insert", module: "es.map.get-or-insert" },
1425
+ { feature: "map_get_or_insert_computed", module: "es.map.get-or-insert-computed" },
1426
+ { feature: "map_group_by", module: "es.map.group-by" },
1427
+ { feature: "math_acosh", module: "es.math.acosh" },
1428
+ { feature: "math_asinh", module: "es.math.asinh" },
1429
+ { feature: "math_atanh", module: "es.math.atanh" },
1430
+ { feature: "math_cbrt", module: "es.math.cbrt" },
1431
+ { feature: "math_clz32", module: "es.math.clz32" },
1432
+ { feature: "math_cosh", module: "es.math.cosh" },
1433
+ { feature: "math_expm1", module: "es.math.expm1" },
1434
+ { feature: "math_f16round", module: "es.math.f16round" },
1435
+ { feature: "math_fround", module: "es.math.fround" },
1436
+ { feature: "math_hypot", module: "es.math.hypot" },
1437
+ { feature: "math_imul", module: "es.math.imul" },
1438
+ { feature: "math_log10", module: "es.math.log10" },
1439
+ { feature: "math_log1p", module: "es.math.log1p" },
1440
+ { feature: "math_log2", module: "es.math.log2" },
1441
+ { feature: "math_sign", module: "es.math.sign" },
1442
+ { feature: "math_sinh", module: "es.math.sinh" },
1443
+ { feature: "math_sum_precise", module: "es.math.sum-precise" },
1444
+ { feature: "math_tanh", module: "es.math.tanh" },
1445
+ { feature: "math_trunc", module: "es.math.trunc" },
1446
+ { feature: "number_constructor", module: "es.number.constructor" },
1447
+ { feature: "number_epsilon", module: "es.number.epsilon" },
1448
+ { feature: "number_is_finite", module: "es.number.is-finite" },
1449
+ { feature: "number_is_integer", module: "es.number.is-integer" },
1450
+ { feature: "number_is_nan", module: "es.number.is-nan" },
1451
+ { feature: "number_is_safe_integer", module: "es.number.is-safe-integer" },
1452
+ { feature: "number_max_safe_integer", module: "es.number.max-safe-integer" },
1453
+ { feature: "number_min_safe_integer", module: "es.number.min-safe-integer" },
1454
+ { feature: "number_parse_float", module: "es.number.parse-float" },
1455
+ { feature: "number_parse_int", module: "es.number.parse-int" },
1456
+ { feature: "number_to_exponential", module: "es.number.to-exponential" },
1457
+ { feature: "number_to_fixed", module: "es.number.to-fixed" },
1458
+ { feature: "number_to_precision", module: "es.number.to-precision" },
1459
+ { feature: "object_assign", module: "es.object.assign" },
1460
+ { feature: "object_create", module: "es.object.create" },
1461
+ { feature: "object_define_getter", module: "es.object.define-getter" },
1462
+ { feature: "object_define_properties", module: "es.object.define-properties" },
1463
+ { feature: "object_define_property", module: "es.object.define-property" },
1464
+ { feature: "object_define_setter", module: "es.object.define-setter" },
1465
+ { feature: "object_entries", module: "es.object.entries" },
1466
+ { feature: "object_freeze", module: "es.object.freeze" },
1467
+ { feature: "object_from_entries", module: "es.object.from-entries" },
1468
+ {
1469
+ feature: "object_get_own_property_descriptor",
1470
+ module: "es.object.get-own-property-descriptor"
1471
+ },
1472
+ {
1473
+ feature: "object_get_own_property_descriptors",
1474
+ module: "es.object.get-own-property-descriptors"
1475
+ },
1476
+ { feature: "object_get_own_property_names", module: "es.object.get-own-property-names" },
1477
+ { feature: "object_get_prototype_of", module: "es.object.get-prototype-of" },
1478
+ { feature: "object_group_by", module: "es.object.group-by" },
1479
+ { feature: "object_has_own", module: "es.object.has-own" },
1480
+ { feature: "object_is", module: "es.object.is" },
1481
+ { feature: "object_is_extensible", module: "es.object.is-extensible" },
1482
+ { feature: "object_is_frozen", module: "es.object.is-frozen" },
1483
+ { feature: "object_is_sealed", module: "es.object.is-sealed" },
1484
+ { feature: "object_keys", module: "es.object.keys" },
1485
+ { feature: "object_lookup_getter", module: "es.object.lookup-getter" },
1486
+ { feature: "object_lookup_setter", module: "es.object.lookup-setter" },
1487
+ { feature: "object_prevent_extensions", module: "es.object.prevent-extensions" },
1488
+ { feature: "object_proto", module: "es.object.proto" },
1489
+ { feature: "object_seal", module: "es.object.seal" },
1490
+ { feature: "object_set_prototype_of", module: "es.object.set-prototype-of" },
1491
+ { feature: "object_values", module: "es.object.values" },
1492
+ { feature: "parse_float", module: "es.parse-float" },
1493
+ { feature: "parse_int", module: "es.parse-int" },
1494
+ { feature: "set", module: "es.set" },
1495
+ { feature: "set_difference", module: "es.set.difference.v2" },
1496
+ { feature: "set_intersection", module: "es.set.intersection.v2" },
1497
+ { feature: "set_is_disjoint_from", module: "es.set.is-disjoint-from.v2" },
1498
+ { feature: "set_is_subset_of", module: "es.set.is-subset-of.v2" },
1499
+ { feature: "set_is_superset_of", module: "es.set.is-superset-of.v2" },
1500
+ { feature: "set_symmetric_difference", module: "es.set.symmetric-difference.v2" },
1501
+ { feature: "set_union", module: "es.set.union.v2" },
1502
+ { feature: "promise", module: "es.promise" },
1503
+ { feature: "promise_all_settled", module: "es.promise.all-settled" },
1504
+ { feature: "promise_any", module: "es.promise.any" },
1505
+ { feature: "promise_finally", module: "es.promise.finally" },
1506
+ { feature: "promise_try", module: "es.promise.try" },
1507
+ { feature: "promise_with_resolvers", module: "es.promise.with-resolvers" },
1508
+ { feature: "reflect_apply", module: "es.reflect.apply" },
1509
+ { feature: "reflect_construct", module: "es.reflect.construct" },
1510
+ { feature: "reflect_define_property", module: "es.reflect.define-property" },
1511
+ { feature: "reflect_delete_property", module: "es.reflect.delete-property" },
1512
+ { feature: "reflect_get", module: "es.reflect.get" },
1513
+ {
1514
+ feature: "reflect_get_own_property_descriptor",
1515
+ module: "es.reflect.get-own-property-descriptor"
1516
+ },
1517
+ { feature: "reflect_get_prototype_of", module: "es.reflect.get-prototype-of" },
1518
+ { feature: "reflect_has", module: "es.reflect.has" },
1519
+ { feature: "reflect_is_extensible", module: "es.reflect.is-extensible" },
1520
+ { feature: "reflect_own_keys", module: "es.reflect.own-keys" },
1521
+ { feature: "reflect_prevent_extensions", module: "es.reflect.prevent-extensions" },
1522
+ { feature: "reflect_set", module: "es.reflect.set" },
1523
+ { feature: "reflect_set_prototype_of", module: "es.reflect.set-prototype-of" },
1524
+ { feature: "regexp_escape", module: "es.regexp.escape" },
1525
+ { feature: "regexp_flags", module: "es.regexp.flags" },
1526
+ { feature: "regexp_sticky", module: "es.regexp.sticky" },
1527
+ { feature: "regexp_dot_all", module: "es.regexp.dot-all" },
1528
+ { feature: "structured_clone", module: "web.structured-clone" },
1529
+ { feature: "string_anchor", module: "es.string.anchor" },
1530
+ { feature: "string_big", module: "es.string.big" },
1531
+ { feature: "string_blink", module: "es.string.blink" },
1532
+ { feature: "string_bold", module: "es.string.bold" },
1533
+ { feature: "string_code_point_at", module: "es.string.code-point-at" },
1534
+ { feature: "string_ends_with", module: "es.string.ends-with" },
1535
+ { feature: "string_fixed", module: "es.string.fixed" },
1536
+ { feature: "string_fontcolor", module: "es.string.fontcolor" },
1537
+ { feature: "string_fontsize", module: "es.string.fontsize" },
1538
+ { feature: "string_from_code_point", module: "es.string.from-code-point" },
1539
+ { feature: "string_includes", module: "es.string.includes" },
1540
+ { feature: "string_is_well_formed", module: "es.string.is-well-formed" },
1541
+ { feature: "string_italics", module: "es.string.italics" },
1542
+ { feature: "string_link", module: "es.string.link" },
1543
+ { feature: "string_match_all", module: "es.string.match-all" },
1544
+ { feature: "string_pad_end", module: "es.string.pad-end" },
1545
+ { feature: "string_pad_start", module: "es.string.pad-start" },
1546
+ { feature: "string_raw", module: "es.string.raw" },
1547
+ { feature: "string_repeat", module: "es.string.repeat" },
1548
+ { feature: "string_replace_all", module: "es.string.replace-all" },
1549
+ { feature: "string_small", module: "es.string.small" },
1550
+ { feature: "string_starts_with", module: "es.string.starts-with" },
1551
+ { feature: "string_strike", module: "es.string.strike" },
1552
+ { feature: "string_sub", module: "es.string.sub" },
1553
+ { feature: "string_substr", module: "es.string.substr" },
1554
+ { feature: "string_sup", module: "es.string.sup" },
1555
+ { feature: "string_to_well_formed", module: "es.string.to-well-formed" },
1556
+ { feature: "string_trim", module: "es.string.trim" },
1557
+ { feature: "string_trim_end", module: "es.string.trim-end" },
1558
+ { feature: "string_trim_start", module: "es.string.trim-start" },
1559
+ { feature: "suppressed_error", module: "es.suppressed-error.constructor" },
1560
+ { feature: "symbol", module: "es.symbol" },
1561
+ { feature: "symbol_async_dispose", module: "es.symbol.async-dispose" },
1562
+ { feature: "symbol_async_iterator", module: "es.symbol.async-iterator" },
1563
+ { feature: "symbol_description", module: "es.symbol.description" },
1564
+ { feature: "symbol_dispose", module: "es.symbol.dispose" },
1565
+ { feature: "symbol_has_instance", module: "es.symbol.has-instance" },
1566
+ { feature: "symbol_is_concat_spreadable", module: "es.symbol.is-concat-spreadable" },
1567
+ { feature: "symbol_iterator", module: "es.symbol.iterator" },
1568
+ { feature: "symbol_match", module: "es.symbol.match" },
1569
+ { feature: "symbol_match_all", module: "es.symbol.match-all" },
1570
+ { feature: "symbol_replace", module: "es.symbol.replace" },
1571
+ { feature: "symbol_search", module: "es.symbol.search" },
1572
+ { feature: "symbol_species", module: "es.symbol.species" },
1573
+ { feature: "symbol_split", module: "es.symbol.split" },
1574
+ { feature: "symbol_to_primitive", module: "es.symbol.to-primitive" },
1575
+ { feature: "symbol_to_string_tag", module: "es.symbol.to-string-tag" },
1576
+ { feature: "symbol_unscopables", module: "es.symbol.unscopables" },
1577
+ { feature: "typed_array_float32", module: "es.typed-array.float32-array" },
1578
+ { feature: "typed_array_float64", module: "es.typed-array.float64-array" },
1579
+ { feature: "typed_array_int8", module: "es.typed-array.int8-array" },
1580
+ { feature: "typed_array_int16", module: "es.typed-array.int16-array" },
1581
+ { feature: "typed_array_int32", module: "es.typed-array.int32-array" },
1582
+ { feature: "typed_array_uint8", module: "es.typed-array.uint8-array" },
1583
+ { feature: "typed_array_uint8_clamped", module: "es.typed-array.uint8-clamped-array" },
1584
+ { feature: "typed_array_uint16", module: "es.typed-array.uint16-array" },
1585
+ { feature: "typed_array_uint32", module: "es.typed-array.uint32-array" },
1586
+ { feature: "typed_array_at", module: "es.typed-array.at" },
1587
+ { feature: "typed_array_copy_within", module: "es.typed-array.copy-within" },
1588
+ { feature: "typed_array_every", module: "es.typed-array.every" },
1589
+ { feature: "typed_array_fill", module: "es.typed-array.fill" },
1590
+ { feature: "typed_array_filter", module: "es.typed-array.filter" },
1591
+ { feature: "typed_array_find", module: "es.typed-array.find" },
1592
+ { feature: "typed_array_find_index", module: "es.typed-array.find-index" },
1593
+ { feature: "typed_array_find_last", module: "es.typed-array.find-last" },
1594
+ { feature: "typed_array_find_last_index", module: "es.typed-array.find-last-index" },
1595
+ { feature: "typed_array_for_each", module: "es.typed-array.for-each" },
1596
+ { feature: "typed_array_from", module: "es.typed-array.from" },
1597
+ { feature: "typed_array_includes", module: "es.typed-array.includes" },
1598
+ { feature: "typed_array_index_of", module: "es.typed-array.index-of" },
1599
+ { feature: "typed_array_join", module: "es.typed-array.join" },
1600
+ { feature: "typed_array_last_index_of", module: "es.typed-array.last-index-of" },
1601
+ { feature: "typed_array_map", module: "es.typed-array.map" },
1602
+ { feature: "typed_array_of", module: "es.typed-array.of" },
1603
+ { feature: "typed_array_reduce", module: "es.typed-array.reduce" },
1604
+ { feature: "typed_array_reduce_right", module: "es.typed-array.reduce-right" },
1605
+ { feature: "typed_array_reverse", module: "es.typed-array.reverse" },
1606
+ { feature: "typed_array_set", module: "es.typed-array.set" },
1607
+ { feature: "typed_array_slice", module: "es.typed-array.slice" },
1608
+ { feature: "typed_array_some", module: "es.typed-array.some" },
1609
+ { feature: "typed_array_sort", module: "es.typed-array.sort" },
1610
+ { feature: "typed_array_subarray", module: "es.typed-array.subarray" },
1611
+ { feature: "typed_array_to_reversed", module: "es.typed-array.to-reversed" },
1612
+ { feature: "typed_array_to_sorted", module: "es.typed-array.to-sorted" },
1613
+ { feature: "typed_array_with", module: "es.typed-array.with" },
1614
+ { feature: "uint8_array_from_base64", module: "es.uint8-array.from-base64" },
1615
+ { feature: "uint8_array_from_hex", module: "es.uint8-array.from-hex" },
1616
+ { feature: "uint8_array_set_from_base64", module: "es.uint8-array.set-from-base64" },
1617
+ { feature: "uint8_array_set_from_hex", module: "es.uint8-array.set-from-hex" },
1618
+ { feature: "uint8_array_to_base64", module: "es.uint8-array.to-base64" },
1619
+ { feature: "uint8_array_to_hex", module: "es.uint8-array.to-hex" },
1620
+ { feature: "unescape", module: "es.unescape" },
1621
+ { feature: "weak_map", module: "es.weak-map" },
1622
+ { feature: "weak_map_get_or_insert", module: "es.weak-map.get-or-insert" },
1623
+ { feature: "weak_map_get_or_insert_computed", module: "es.weak-map.get-or-insert-computed" },
1624
+ { feature: "weak_set", module: "es.weak-set" },
1625
+ { feature: "web_atob", module: "web.atob" },
1626
+ { feature: "web_btoa", module: "web.btoa" },
1627
+ { feature: "web_dom_collections_for_each", module: "web.dom-collections.for-each" },
1628
+ { feature: "web_dom_collections_iterator", module: "web.dom-collections.iterator" },
1629
+ { feature: "web_dom_exception", module: "web.dom-exception.constructor" },
1630
+ { feature: "web_immediate", module: "web.immediate" },
1631
+ { feature: "web_queue_microtask", module: "web.queue-microtask" },
1632
+ { feature: "web_self", module: "web.self" },
1633
+ { feature: "web_timers", module: "web.timers" },
1634
+ { feature: "web_url", module: "web.url" },
1635
+ { feature: "web_url_can_parse", module: "web.url.can-parse" },
1636
+ { feature: "web_url_parse", module: "web.url.parse" },
1637
+ { feature: "web_url_to_json", module: "web.url.to-json" },
1638
+ { feature: "web_url_search_params", module: "web.url-search-params" },
1639
+ { feature: "web_url_search_params_delete", module: "web.url-search-params.delete" },
1640
+ { feature: "web_url_search_params_has", module: "web.url-search-params.has" },
1641
+ { feature: "web_url_search_params_size", module: "web.url-search-params.size" }
1642
+ ];
1643
+ var RUNTIME_POLYFILL_CANDIDATE_MODULES = RUNTIME_POLYFILL_FEATURE_MODULES.map((item) => item.module);
1644
+ var coreJsCompatCache;
1645
+ var coreJsVersionCache;
1646
+ function isEsTarget(target) {
1647
+ return target !== undefined && ES_TARGETS.has(target);
1648
+ }
1649
+ function loadCoreJsCompat() {
1650
+ if (coreJsCompatCache !== undefined) {
1651
+ if (coreJsCompatCache)
1652
+ return coreJsCompatCache;
1653
+ throwCoreJsCompatMissing();
1654
+ }
1655
+ try {
1656
+ const req = getRuntimeRequire();
1657
+ coreJsCompatCache = req("core-js-compat");
1658
+ return coreJsCompatCache;
1659
+ } catch {
1660
+ coreJsCompatCache = null;
1661
+ throwCoreJsCompatMissing();
1662
+ }
1663
+ }
1664
+ function throwCoreJsCompatMissing() {
1665
+ throw new Error("@zntc/core: runtimePolyfills requires the optional 'core-js-compat' package. Install it with `bun add core-js core-js-compat`.");
1666
+ }
1667
+ function readInstalledCoreJsVersion() {
1668
+ if (coreJsVersionCache !== undefined)
1669
+ return coreJsVersionCache ?? undefined;
1670
+ try {
1671
+ const req = getRuntimeRequire();
1672
+ const pkgPath = req.resolve("core-js/package.json");
1673
+ const pkg = JSON.parse(readFileSync(pkgPath, "utf8"));
1674
+ coreJsVersionCache = pkg.version ?? null;
1675
+ } catch {
1676
+ coreJsVersionCache = null;
1677
+ }
1678
+ return coreJsVersionCache ?? undefined;
1679
+ }
1680
+ function assertNotPhysicalDeviceTarget(raw) {
1681
+ if (!DEVICE_TARGET_RE.test(raw))
1682
+ return;
1683
+ throw new Error(`@zntc/core: unsupported runtime target '${raw}'. Physical device names are not supported; use Browserslist targets such as 'ios_saf 12', 'chrome >= 85', or 'node 18'.`);
1684
+ }
1685
+ function assertNotCompactRuntimeTarget(raw) {
1686
+ const compact = raw.match(/^(ios_saf|ios|safari|chrome|android|samsung|hermes|node)v?\d+(?:\.\d+)*$/i);
1687
+ if (!compact)
1688
+ return;
1689
+ throw new Error(`@zntc/core: unsupported runtime target '${raw}'. Compact runtime target shorthands are not supported; use Browserslist targets such as 'ios_saf 12', 'chrome >= 85', or 'node 18'.`);
1690
+ }
1691
+ function assertBrowserslistRuntimeTarget(raw) {
1692
+ if (!/^(?:hermes|react-native|reactnative)\b/i.test(raw))
1693
+ return;
1694
+ throw new Error(`@zntc/core: unsupported runtime target '${raw}'. runtimePolyfills.targets follows Rspack/SWC env.targets and accepts Browserslist queries; use platform: 'react-native' for the default Hermes runtime target.`);
1695
+ }
1696
+ function normalizeRuntimeTargetString(raw) {
1697
+ const value = raw.trim();
1698
+ assertNotPhysicalDeviceTarget(value);
1699
+ assertNotCompactRuntimeTarget(value);
1700
+ assertBrowserslistRuntimeTarget(value);
1701
+ return value;
1702
+ }
1703
+ function normalizeRuntimeTargets(targets) {
1704
+ if (Array.isArray(targets))
1705
+ return targets.map(normalizeRuntimeTargetString);
1706
+ return normalizeRuntimeTargetString(targets);
1707
+ }
1708
+ function normalizeBuildTargetForRuntime(target) {
1709
+ if (!target || isEsTarget(target))
1710
+ return;
1711
+ const nodeTarget = target.match(/^node(\d+(?:\.\d+)*)$/i);
1712
+ if (nodeTarget)
1713
+ return { node: nodeTarget[1] };
1714
+ const hermesTarget = target.match(/^hermes(\d+(?:\.\d+)*)$/i);
1715
+ if (hermesTarget)
1716
+ return { hermes: hermesTarget[1] };
1717
+ return normalizeRuntimeTargets(target);
1718
+ }
1719
+ function defaultRuntimeTargets(options) {
1720
+ if (options.platform === "node") {
1721
+ const [major, minor = "0"] = process.versions.node.split(".");
1722
+ return { node: `${major}.${minor}` };
1723
+ }
1724
+ if (options.platform === "react-native")
1725
+ return { hermes: "0.7" };
1726
+ return "defaults";
1727
+ }
1728
+ function chooseRuntimeTargets(options, runtime) {
1729
+ const raw = runtime.targets ?? (options.browserslist ? options.browserslist : undefined);
1730
+ if (raw !== undefined)
1731
+ return normalizeRuntimeTargets(raw);
1732
+ const target = normalizeBuildTargetForRuntime(options.target);
1733
+ if (target !== undefined)
1734
+ return target;
1735
+ return defaultRuntimeTargets(options);
1736
+ }
1737
+ function normalizeCoreJsModuleName(raw) {
1738
+ let value = raw.trim();
1739
+ if (value.startsWith("core-js/modules/"))
1740
+ value = value.slice("core-js/modules/".length);
1741
+ if (value.endsWith(".js"))
1742
+ value = value.slice(0, -3);
1743
+ if (!/^(?:es|web)\.[a-z0-9.-]+$/i.test(value)) {
1744
+ throw new Error(`@zntc/core: invalid core-js module '${raw}'. Expected e.g. 'es.string.replace-all'.`);
1745
+ }
1746
+ return value;
1747
+ }
1748
+ function normalizeRuntimePolyfillOptions(options) {
1749
+ const raw = options.runtimePolyfills;
1750
+ if (raw === undefined || raw === "off")
1751
+ return null;
1752
+ const runtime = typeof raw === "string" ? { mode: raw } : { ...raw };
1753
+ const mode = runtime.mode ?? "auto";
1754
+ if (mode !== "auto" && mode !== "usage" && mode !== "entry") {
1755
+ throw new Error("@zntc/core: runtimePolyfills.mode must be 'auto', 'usage', or 'entry'.");
1756
+ }
1757
+ const provider = runtime.provider ?? "core-js";
1758
+ if (provider !== "core-js") {
1759
+ throw new Error("@zntc/core: runtimePolyfills.provider currently supports only 'core-js'.");
1760
+ }
1761
+ return {
1762
+ mode,
1763
+ provider,
1764
+ targets: chooseRuntimeTargets(options, runtime),
1765
+ include: (runtime.include ?? []).map(normalizeCoreJsModuleName),
1766
+ exclude: (runtime.exclude ?? []).map(normalizeCoreJsModuleName),
1767
+ proposals: runtime.proposals === true,
1768
+ coreJsVersion: runtime.coreJs ?? options.coreJs ?? readInstalledCoreJsVersion()
1769
+ };
1770
+ }
1771
+ function computeCoreJsCompatModules(targets, modules, options = {}) {
1772
+ const compat = loadCoreJsCompat();
1773
+ const result = compat({
1774
+ targets,
1775
+ modules,
1776
+ version: options.version,
1777
+ proposals: options.proposals
1778
+ });
1779
+ return result.list.map(normalizeCoreJsModuleName).sort();
1780
+ }
1781
+ function buildCoreJsResolver(entryPoints) {
1782
+ const override = runtimeRequireOverride;
1783
+ const requires = [];
1784
+ if (override) {
1785
+ requires.push(override);
1786
+ } else {
1787
+ const entry = entryPoints[0];
1788
+ if (entry)
1789
+ requires.push(createRequire2(resolve(dirname(resolve(entry)), "package.json")));
1790
+ requires.push(createRequire2(import.meta.url));
1791
+ }
1792
+ return (moduleName) => {
1793
+ const specifier = `core-js/modules/${moduleName}.js`;
1794
+ let firstError;
1795
+ for (const req of requires) {
1796
+ try {
1797
+ return req.resolve(specifier);
1798
+ } catch (err) {
1799
+ firstError ??= err instanceof Error ? err.message : String(err);
1800
+ }
1801
+ }
1802
+ throw new Error(`@zntc/core: runtimePolyfills could not resolve '${specifier}'. Install core-js with \`bun add core-js\`.
1803
+ ${firstError ?? ""}`);
1804
+ };
1805
+ }
1806
+ function uniqueSorted(values) {
1807
+ return [...new Set(values)].sort();
1808
+ }
1809
+ function resolveRuntimeModules(modules, resolveCoreJs) {
1810
+ return uniqueSorted(modules).map((moduleName) => ({
1811
+ module: moduleName,
1812
+ path: resolveCoreJs(moduleName)
1813
+ }));
1814
+ }
1815
+ function applyRuntimePolyfillsToNapiOptions(napiOptions, options) {
1816
+ delete napiOptions.runtimePolyfills;
1817
+ delete napiOptions.coreJs;
1818
+ if (options.target && !isEsTarget(options.target))
1819
+ delete napiOptions.target;
1820
+ const runtime = normalizeRuntimePolyfillOptions(options);
1821
+ if (!runtime)
1822
+ return { cleanup: () => {}, modules: [] };
1823
+ const exclude = new Set(runtime.exclude);
1824
+ const includeModules = runtime.include.filter((moduleName) => !exclude.has(moduleName));
1825
+ const resolveCoreJs = buildCoreJsResolver(options.entryPoints);
1826
+ const includeResolved = resolveRuntimeModules(includeModules, resolveCoreJs);
1827
+ if (runtime.mode === "entry") {
1828
+ const entryModules = computeCoreJsCompatModules(runtime.targets, /^(?:es|web)\./, {
1829
+ version: runtime.coreJsVersion,
1830
+ proposals: runtime.proposals
1831
+ }).filter((moduleName) => !exclude.has(moduleName));
1832
+ const entryResolved = resolveRuntimeModules(entryModules, resolveCoreJs);
1833
+ if (entryResolved.length === 0 && includeResolved.length === 0) {
1834
+ return { cleanup: () => {}, modules: [] };
1835
+ }
1836
+ napiOptions.runtimePolyfillPlan = {
1837
+ mode: "entry",
1838
+ entry: entryResolved,
1839
+ include: includeResolved,
1840
+ exclude: runtime.exclude
1841
+ };
1842
+ return {
1843
+ cleanup: () => {},
1844
+ modules: uniqueSorted([...entryResolved, ...includeResolved].map((item) => item.module))
1845
+ };
1846
+ }
1847
+ const targetCandidateSet = new Set(computeCoreJsCompatModules(runtime.targets, RUNTIME_POLYFILL_CANDIDATE_MODULES, {
1848
+ version: runtime.coreJsVersion,
1849
+ proposals: runtime.proposals
1850
+ }).filter((moduleName) => !exclude.has(moduleName)));
1851
+ const candidates = [];
1852
+ for (const item of RUNTIME_POLYFILL_FEATURE_MODULES) {
1853
+ if (!targetCandidateSet.has(item.module))
1854
+ continue;
1855
+ candidates.push({
1856
+ feature: item.feature,
1857
+ module: item.module,
1858
+ path: resolveCoreJs(item.module)
1859
+ });
1860
+ }
1861
+ if (candidates.length === 0 && includeResolved.length === 0) {
1862
+ return { cleanup: () => {}, modules: [] };
1863
+ }
1864
+ napiOptions.runtimePolyfillPlan = {
1865
+ mode: "usage",
1866
+ candidates,
1867
+ include: includeResolved,
1868
+ exclude: runtime.exclude
1869
+ };
1870
+ return {
1871
+ cleanup: () => {},
1872
+ modules: uniqueSorted([...candidates, ...includeResolved].map((item) => item.module))
1873
+ };
1874
+ }
1875
+
1876
+ // src/config-loader.ts
1877
+ import { randomBytes } from "node:crypto";
1878
+ import { existsSync, readFileSync as readFileSync2, unlinkSync, writeFileSync } from "node:fs";
1879
+ import { dirname as dirname2, extname, join, resolve as pathResolve } from "node:path";
1880
+ import { pathToFileURL } from "node:url";
1881
+ var CONFIG_EXT_PRIORITY = [".ts", ".mts", ".cts", ".mjs", ".js", ".cjs", ".json"];
1882
+ var TS_EXTS = new Set(CONFIG_EXT_PRIORITY.slice(0, 3));
1883
+ var JS_EXTS = new Set(CONFIG_EXT_PRIORITY.slice(3, 6));
1884
+ async function loadConfig(filePath, env) {
1885
+ const absPath = pathResolve(filePath);
1886
+ return loadConfigWithExtends(absPath, env, new Set);
1887
+ }
1888
+ async function loadConfigWithExtends(absPath, env, visited) {
1889
+ if (visited.has(absPath)) {
1890
+ throw new Error(`@zntc/core: circular extends detected at ${absPath} (chain: ${[...visited, absPath].join(" → ")})`);
1891
+ }
1892
+ visited.add(absPath);
1893
+ const raw = await loadModuleDefault(absPath, "config");
1894
+ const resolved = await resolveConfigValue(raw, env, absPath);
1895
+ const extendsField = resolved.extends;
1896
+ if (extendsField === undefined)
1897
+ return resolved;
1898
+ const extendsPaths = Array.isArray(extendsField) ? extendsField : [extendsField];
1899
+ const baseDir = dirname2(absPath);
1900
+ let merged = {};
1901
+ for (const extPath of extendsPaths) {
1902
+ const resolvedExt = pathResolve(baseDir, extPath);
1903
+ const base = await loadConfigWithExtends(resolvedExt, env, new Set(visited));
1904
+ merged = mergeUserConfigs(merged, base);
1905
+ }
1906
+ const { extends: _extends, ...currentWithoutExtends } = resolved;
1907
+ return mergeUserConfigs(merged, currentWithoutExtends);
1908
+ }
1909
+ function defaultConfigEnv() {
1910
+ return {
1911
+ command: "bundle",
1912
+ mode: "production",
1913
+ env: process.env
1914
+ };
1915
+ }
1916
+ async function resolveConfigValue(raw, env, absPath) {
1917
+ if (typeof raw !== "function") {
1918
+ return raw;
1919
+ }
1920
+ const result = await raw(env ?? defaultConfigEnv());
1921
+ if (!isPlainObject(result)) {
1922
+ const got = Array.isArray(result) ? "array" : typeof result;
1923
+ throw new Error(`@zntc/core: functional config must return an object (got ${got}) from ${absPath}`);
1924
+ }
1925
+ return result;
1926
+ }
1927
+ async function loadModuleDefault(absPath, kind, options) {
1928
+ const allowArray = options?.allowArray === true;
1929
+ const ext = extname(absPath).toLowerCase();
1930
+ if (ext === ".json") {
1931
+ const raw = readFileOrThrowNotFound(absPath);
1932
+ try {
1933
+ return JSON.parse(raw);
1934
+ } catch (err) {
1935
+ const reason = err instanceof Error ? err.message : String(err);
1936
+ throw new Error(`@zntc/core: failed to parse JSON ${kind} ${absPath}: ${reason}`);
1937
+ }
1938
+ }
1939
+ if (TS_EXTS.has(ext)) {
1940
+ return await loadTsModule(absPath, kind, allowArray);
1941
+ }
1942
+ if (JS_EXTS.has(ext)) {
1943
+ try {
1944
+ return await importAndResolveDefault(absPath, { allowArray });
1945
+ } catch (err) {
1946
+ if (err instanceof Error) {
1947
+ err.message = err.message.replace("module not found", `${kind} file not found`).replace(/module must be an object or function/, `${kind} must export an object or function`);
1948
+ }
1949
+ throw err;
1950
+ }
1951
+ }
1952
+ throw new Error(`@zntc/core: unsupported ${kind} extension "${ext}" for ${absPath}. Supported: .ts/.mts/.cts/.mjs/.js/.cjs/.json`);
1953
+ }
1954
+ async function loadTsModule(absPath, kind, allowArray) {
1955
+ init();
1956
+ const source = readFileOrThrowNotFound(absPath);
1957
+ const parseFilename = absPath.endsWith(".cts") ? absPath.slice(0, -4) + ".ts" : absPath;
1958
+ const result = transpile(source, {
1959
+ filename: parseFilename,
1960
+ format: "esm"
1961
+ });
1962
+ if (result.errors) {
1963
+ throw new Error(`@zntc/core: ${kind} compile failed in ${absPath}
1964
+ ${result.errors}`);
1965
+ }
1966
+ const tmpName = `.zntc-${kind}.bundled-${randomBytes(6).toString("hex")}.mjs`;
1967
+ const tmpPath = join(dirname2(absPath), tmpName);
1968
+ writeFileSync(tmpPath, result.code, "utf8");
1969
+ try {
1970
+ return await importAndResolveDefault(tmpPath, { allowArray });
1971
+ } finally {
1972
+ try {
1973
+ unlinkSync(tmpPath);
1974
+ } catch (err) {
1975
+ const reason = err instanceof Error ? err.message : String(err);
1976
+ console.warn(`@zntc/core: failed to remove tmp ${kind} ${tmpPath}: ${reason}`);
1977
+ }
1978
+ }
1979
+ }
1980
+ async function importAndResolveDefault(absPath, options) {
1981
+ const allowArray = options?.allowArray === true;
1982
+ const url = pathToFileURL(absPath).href;
1983
+ let mod;
1984
+ try {
1985
+ mod = await import(url);
1986
+ } catch (err) {
1987
+ const code = err?.code;
1988
+ if (code === "ERR_MODULE_NOT_FOUND" || code === "ENOENT") {
1989
+ throw new Error(`@zntc/core: module not found: ${absPath}`);
1990
+ }
1991
+ throw err;
1992
+ }
1993
+ const value = mod.default ?? mod;
1994
+ const valueType = typeof value;
1995
+ const isArray = Array.isArray(value);
1996
+ const validObject = valueType === "object" && value !== null && (allowArray || !isArray);
1997
+ if (valueType !== "function" && !validObject) {
1998
+ const got = value === null ? "null" : isArray ? "array" : valueType;
1999
+ throw new Error(`@zntc/core: module must be an object or function (got ${got}) from ${absPath}`);
2000
+ }
2001
+ return value;
2002
+ }
2003
+ function readFileOrThrowNotFound(absPath) {
2004
+ try {
2005
+ return readFileSync2(absPath, "utf8");
2006
+ } catch (err) {
2007
+ if (err.code === "ENOENT") {
2008
+ throw new Error(`@zntc/core: config file not found: ${absPath}`);
2009
+ }
2010
+ throw err;
2011
+ }
2012
+ }
2013
+ function readFileIfExists(absPath) {
2014
+ try {
2015
+ return readFileSync2(absPath, "utf8");
2016
+ } catch (err) {
2017
+ const code = err.code;
2018
+ if (code === "ENOENT" || code === "ENOTDIR")
2019
+ return null;
2020
+ throw err;
2021
+ }
2022
+ }
2023
+ function findConfigPath(cwd) {
2024
+ for (const ext of CONFIG_EXT_PRIORITY) {
2025
+ const candidate = join(cwd, `zntc.config${ext}`);
2026
+ if (existsSync(candidate))
2027
+ return candidate;
2028
+ }
2029
+ return null;
2030
+ }
2031
+ function findModeConfigPath(cwd, mode) {
2032
+ if (!mode)
2033
+ return null;
2034
+ for (const ext of CONFIG_EXT_PRIORITY) {
2035
+ const candidate = join(cwd, `zntc.config.${mode}${ext}`);
2036
+ if (existsSync(candidate))
2037
+ return candidate;
2038
+ }
2039
+ return null;
2040
+ }
2041
+ function mergeUserConfigs(base, mode) {
2042
+ const merged = { ...base };
2043
+ for (const key of Object.keys(mode)) {
2044
+ const modeVal = mode[key];
2045
+ if (modeVal === undefined)
2046
+ continue;
2047
+ if (key === "plugins" && Array.isArray(modeVal) && Array.isArray(merged.plugins)) {
2048
+ merged.plugins = [...merged.plugins, ...modeVal];
2049
+ continue;
2050
+ }
2051
+ const baseVal = base[key];
2052
+ if (typeof baseVal === "object" && baseVal !== null && !Array.isArray(baseVal) && typeof modeVal === "object" && modeVal !== null && !Array.isArray(modeVal)) {
2053
+ merged[key] = {
2054
+ ...baseVal,
2055
+ ...modeVal
2056
+ };
2057
+ continue;
2058
+ }
2059
+ merged[key] = modeVal;
2060
+ }
2061
+ return merged;
2062
+ }
2063
+ // src/load-env.ts
2064
+ import { resolve as pathResolve2 } from "node:path";
2065
+ function parseDotenvLine(line) {
2066
+ const trimmed = line.trim();
2067
+ if (!trimmed || trimmed.startsWith("#"))
2068
+ return null;
2069
+ const eqIdx = trimmed.indexOf("=");
2070
+ if (eqIdx <= 0)
2071
+ return null;
2072
+ const key = trimmed.slice(0, eqIdx).trim();
2073
+ if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(key))
2074
+ return null;
2075
+ let value = trimmed.slice(eqIdx + 1).trim();
2076
+ const quoted = value.startsWith('"') && value.endsWith('"') || value.startsWith("'") && value.endsWith("'");
2077
+ if (quoted) {
2078
+ value = value.slice(1, -1);
2079
+ } else {
2080
+ value = value.replace(/\s+#.*$/, "");
2081
+ }
2082
+ return [key, value];
2083
+ }
2084
+ function parseDotenvFile(filePath) {
2085
+ const content = readFileIfExists(filePath);
2086
+ if (content === null)
2087
+ return {};
2088
+ const out = {};
2089
+ for (const line of content.split(/\r?\n/)) {
2090
+ const parsed = parseDotenvLine(line);
2091
+ if (parsed)
2092
+ out[parsed[0]] = parsed[1];
2093
+ }
2094
+ return out;
2095
+ }
2096
+ function loadEnv(mode, envDir, prefixes = ["VITE_", "ZNTC_"]) {
2097
+ const prefixList = Array.isArray(prefixes) ? prefixes : [prefixes];
2098
+ const dir = pathResolve2(envDir);
2099
+ const files = [`.env`, `.env.local`, `.env.${mode}`, `.env.${mode}.local`];
2100
+ const merged = {};
2101
+ for (const file of files) {
2102
+ Object.assign(merged, parseDotenvFile(`${dir}/${file}`));
2103
+ }
2104
+ const filtered = {};
2105
+ for (const [key, value] of Object.entries(merged)) {
2106
+ if (prefixList.some((p) => key.startsWith(p))) {
2107
+ filtered[key] = value;
2108
+ }
2109
+ }
2110
+ return filtered;
2111
+ }
2112
+ function envToDefine(env, mode, baseUrl = "/") {
2113
+ const envObject = {
2114
+ MODE: mode,
2115
+ PROD: mode === "production",
2116
+ DEV: mode !== "production",
2117
+ SSR: false,
2118
+ BASE_URL: baseUrl
2119
+ };
2120
+ for (const [key, value] of Object.entries(env))
2121
+ envObject[key] = value;
2122
+ const define = {
2123
+ "import.meta.env": JSON.stringify(envObject)
2124
+ };
2125
+ for (const [key, value] of Object.entries(envObject)) {
2126
+ define[`import.meta.env.${key}`] = JSON.stringify(value);
2127
+ }
2128
+ return define;
2129
+ }
2130
+ // src/typo-suggest.ts
2131
+ function levenshtein(a, b) {
2132
+ if (a.length === 0)
2133
+ return b.length;
2134
+ if (b.length === 0)
2135
+ return a.length;
2136
+ const [s, l] = a.length <= b.length ? [a, b] : [b, a];
2137
+ let prev = Array.from({ length: s.length + 1 });
2138
+ let curr = Array.from({ length: s.length + 1 });
2139
+ for (let i = 0;i <= s.length; i++)
2140
+ prev[i] = i;
2141
+ for (let i = 1;i <= l.length; i++) {
2142
+ curr[0] = i;
2143
+ for (let j = 1;j <= s.length; j++) {
2144
+ const cost = l.charCodeAt(i - 1) === s.charCodeAt(j - 1) ? 0 : 1;
2145
+ curr[j] = Math.min(prev[j] + 1, curr[j - 1] + 1, prev[j - 1] + cost);
2146
+ }
2147
+ [prev, curr] = [curr, prev];
2148
+ }
2149
+ return prev[s.length];
2150
+ }
2151
+ function suggestKey(unknown, known, threshold = 2) {
2152
+ if (!unknown || known.length === 0)
2153
+ return null;
2154
+ const adjusted = Math.min(threshold, Math.max(1, Math.ceil(unknown.length / 3)));
2155
+ let best = null;
2156
+ let bestDist = adjusted + 1;
2157
+ for (const candidate of known) {
2158
+ const d = levenshtein(unknown, candidate);
2159
+ if (d > adjusted)
2160
+ continue;
2161
+ if (d < bestDist || d === bestDist && best !== null && candidate < best) {
2162
+ best = candidate;
2163
+ bestDist = d;
2164
+ }
2165
+ }
2166
+ return best;
2167
+ }
2168
+ function warnUnknownKeys(config, known, options = {}) {
2169
+ const result = [];
2170
+ const knownSet = new Set(known);
2171
+ for (const key of Object.keys(config)) {
2172
+ if (knownSet.has(key))
2173
+ continue;
2174
+ const suggestion = suggestKey(key, known);
2175
+ result.push({ unknown: key, suggestion });
2176
+ if (!options.silent) {
2177
+ const where = options.sourceLabel ? ` (${options.sourceLabel})` : "";
2178
+ const hint = suggestion ? ` — did you mean '${suggestion}'?` : "";
2179
+ console.warn(`@zntc/core: unknown config key '${key}'${where}${hint}`);
2180
+ }
2181
+ }
2182
+ return result;
2183
+ }
2184
+ var KNOWN_CONFIG_KEYS = [
2185
+ "entryPoints",
2186
+ "outdir",
2187
+ "outfile",
2188
+ "outbase",
2189
+ "format",
2190
+ "platform",
2191
+ "target",
2192
+ "browserslist",
2193
+ "runtimePolyfills",
2194
+ "coreJs",
2195
+ "jsx",
2196
+ "jsxDev",
2197
+ "jsxFactory",
2198
+ "jsxFragment",
2199
+ "jsxImportSource",
2200
+ "jsxInJs",
2201
+ "jsxSideEffects",
2202
+ "minify",
2203
+ "minifyWhitespace",
2204
+ "minifyIdentifiers",
2205
+ "minifySyntax",
2206
+ "sourcemap",
2207
+ "sourcemapMode",
2208
+ "sourcemapDebugIds",
2209
+ "sourcesContent",
2210
+ "sourceRoot",
2211
+ "external",
2212
+ "alias",
2213
+ "define",
2214
+ "server",
2215
+ "loader",
2216
+ "conditions",
2217
+ "nodePaths",
2218
+ "moduleSpecifierMap",
2219
+ "resolveExtensions",
2220
+ "mainFields",
2221
+ "packagesExternal",
2222
+ "preserveSymlinks",
2223
+ "resolveSymlinkSiblings",
2224
+ "disableHierarchicalLookup",
2225
+ "splitting",
2226
+ "outputExports",
2227
+ "preserveModules",
2228
+ "preserveModulesRoot",
2229
+ "inlineDynamicImports",
2230
+ "manualChunks",
2231
+ "minChunkSize",
2232
+ "metafile",
2233
+ "treeShaking",
2234
+ "shimMissingExports",
2235
+ "keepNames",
2236
+ "drop",
2237
+ "dropConsole",
2238
+ "dropDebugger",
2239
+ "dropLabels",
2240
+ "banner",
2241
+ "footer",
2242
+ "intro",
2243
+ "outro",
2244
+ "inject",
2245
+ "pure",
2246
+ "legalComments",
2247
+ "entryNames",
2248
+ "chunkNames",
2249
+ "assetNames",
2250
+ "experimentalDecorators",
2251
+ "emitDecoratorMetadata",
2252
+ "useDefineForClassFields",
2253
+ "verbatimModuleSyntax",
2254
+ "tsconfigPath",
2255
+ "tsconfigRaw",
2256
+ "globalName",
2257
+ "globals",
2258
+ "publicPath",
2259
+ "charsetUtf8",
2260
+ "asciiOnly",
2261
+ "quotes",
2262
+ "compiler",
2263
+ "mf",
2264
+ "flow",
2265
+ "plugins",
2266
+ "logLevel",
2267
+ "logLimit",
2268
+ "lineLimit",
2269
+ "profile",
2270
+ "profileFormat",
2271
+ "profileLevel",
2272
+ "tokenizeFormat",
2273
+ "stopAfter",
2274
+ "ignoreAnnotations",
2275
+ "watchDelay",
2276
+ "jobs",
2277
+ "codegenTransform",
2278
+ "extends",
2279
+ "root",
2280
+ "projectRoot",
2281
+ "entry",
2282
+ "dev",
2283
+ "outDir",
2284
+ "bundler",
2285
+ "resolver",
2286
+ "transformer",
2287
+ "serializer",
2288
+ "symbolicator",
2289
+ "watchFolders"
2290
+ ];
2291
+ // src/workspace.ts
2292
+ import { existsSync as existsSync2, readdirSync, readFileSync as readFileSync3 } from "node:fs";
2293
+ import { basename, join as join2, resolve as pathResolve3 } from "node:path";
2294
+ var CONFIG_EXT_PRIORITY_LOCAL = [".ts", ".mts", ".cts", ".mjs", ".js", ".cjs", ".json"];
2295
+ function defineWorkspace(input) {
2296
+ return input;
2297
+ }
2298
+ var WORKSPACE_EXT_PRIORITY = CONFIG_EXT_PRIORITY_LOCAL;
2299
+ function findWorkspacePath(cwd) {
2300
+ for (const ext of WORKSPACE_EXT_PRIORITY) {
2301
+ const p = join2(cwd, `zntc.workspace${ext}`);
2302
+ if (existsSync2(p))
2303
+ return p;
2304
+ }
2305
+ return null;
2306
+ }
2307
+ async function loadWorkspace(filePath, env) {
2308
+ const absPath = pathResolve3(filePath);
2309
+ const raw = await loadModuleDefault(absPath, "workspace", { allowArray: true });
2310
+ const entries = typeof raw === "function" ? await raw(env ?? defaultConfigEnv()) : raw;
2311
+ if (!Array.isArray(entries)) {
2312
+ const got = entries === null ? "null" : typeof entries;
2313
+ throw new Error(`@zntc/core: workspace must export an array (got ${got}) from ${absPath}`);
2314
+ }
2315
+ for (let i = 0;i < entries.length; i += 1) {
2316
+ const e = entries[i];
2317
+ if (typeof e === "string") {
2318
+ if (!e.length) {
2319
+ throw new Error(`@zntc/core: workspace[${i}] is empty string in ${absPath}`);
2320
+ }
2321
+ continue;
2322
+ }
2323
+ if (!isPlainObject(e)) {
2324
+ throw new Error(`@zntc/core: workspace[${i}] must be a string or object (got ${Array.isArray(e) ? "array" : e === null ? "null" : typeof e}) in ${absPath}`);
2325
+ }
2326
+ const name = e.name;
2327
+ if (typeof name !== "string" || !name) {
2328
+ throw new Error(`@zntc/core: workspace[${i}] inline entry requires non-empty 'name' in ${absPath}`);
2329
+ }
2330
+ }
2331
+ return entries;
2332
+ }
2333
+ function identifyWorkspaceEntries(entries, rootDir) {
2334
+ const seen = new Set;
2335
+ const out = [];
2336
+ const push = (w) => {
2337
+ if (seen.has(w.cwd))
2338
+ return;
2339
+ seen.add(w.cwd);
2340
+ out.push(w);
2341
+ };
2342
+ for (const entry of entries) {
2343
+ if (typeof entry === "string") {
2344
+ if (entry.includes("*")) {
2345
+ for (const dir of expandGlob(entry, rootDir)) {
2346
+ push({ name: detectPackageName(dir), cwd: dir, source: "glob", inlineConfig: null });
2347
+ }
2348
+ } else {
2349
+ const abs = pathResolve3(rootDir, entry);
2350
+ push({ name: detectPackageName(abs), cwd: abs, source: "path", inlineConfig: null });
2351
+ }
2352
+ continue;
2353
+ }
2354
+ const { name, ...rest } = entry;
2355
+ push({
2356
+ name,
2357
+ cwd: rootDir,
2358
+ source: "inline",
2359
+ inlineConfig: rest
2360
+ });
2361
+ }
2362
+ return out;
2363
+ }
2364
+ async function loadIdentifiedConfig(w, env) {
2365
+ if (w.inlineConfig)
2366
+ return w.inlineConfig;
2367
+ const configPath = findConfigPath(w.cwd);
2368
+ return configPath ? await loadConfig(configPath, env) : {};
2369
+ }
2370
+ function expandGlob(pattern, rootDir) {
2371
+ if (pattern.includes("**")) {
2372
+ throw new Error(`@zntc/core: workspace glob '**' is not supported (got '${pattern}'). Use single-level '*' patterns.`);
2373
+ }
2374
+ const lastSep = pattern.lastIndexOf("/");
2375
+ if (lastSep === -1) {
2376
+ return enumerateDirs(rootDir, pattern);
2377
+ }
2378
+ const dirPart = pattern.slice(0, lastSep);
2379
+ const namePart = pattern.slice(lastSep + 1);
2380
+ if (dirPart.includes("*")) {
2381
+ throw new Error(`@zntc/core: workspace glob with '*' in directory part is not supported (got '${pattern}'). Use trailing-only '*'.`);
2382
+ }
2383
+ if (!namePart.includes("*")) {
2384
+ return [pathResolve3(rootDir, pattern)];
2385
+ }
2386
+ const baseDir = pathResolve3(rootDir, dirPart);
2387
+ return enumerateDirs(baseDir, namePart);
2388
+ }
2389
+ function enumerateDirs(baseDir, namePattern) {
2390
+ if (!existsSync2(baseDir))
2391
+ return [];
2392
+ const matcher = makeStarMatcher(namePattern);
2393
+ const out = [];
2394
+ for (const d of readdirSync(baseDir, { withFileTypes: true })) {
2395
+ if (!d.isDirectory())
2396
+ continue;
2397
+ if (d.name.startsWith("."))
2398
+ continue;
2399
+ if (d.name === "node_modules")
2400
+ continue;
2401
+ if (matcher(d.name))
2402
+ out.push(join2(baseDir, d.name));
2403
+ }
2404
+ out.sort();
2405
+ return out;
2406
+ }
2407
+ function makeStarMatcher(pattern) {
2408
+ if (pattern === "*")
2409
+ return () => true;
2410
+ const escaped = pattern.replace(/[.+?^${}()|[\]\\]/g, "\\$&").replace(/\*/g, ".*");
2411
+ const re = new RegExp("^" + escaped + "$");
2412
+ return (s) => re.test(s);
2413
+ }
2414
+ function detectPackageName(absDir) {
2415
+ const pkgPath = join2(absDir, "package.json");
2416
+ if (existsSync2(pkgPath)) {
2417
+ try {
2418
+ const pkg = JSON.parse(readFileSync3(pkgPath, "utf8"));
2419
+ if (typeof pkg.name === "string" && pkg.name)
2420
+ return pkg.name;
2421
+ } catch {}
2422
+ }
2423
+ return basename(absDir);
2424
+ }
2425
+ function filterWorkspaces(workspaces, filter) {
2426
+ if (!filter)
2427
+ return workspaces;
2428
+ const filtered = workspaces.filter((w) => w.name === filter);
2429
+ if (filtered.length === 0) {
2430
+ const available = workspaces.map((w) => w.name).join(", ");
2431
+ throw new Error(`@zntc/core: --workspace='${filter}' matched 0 entries (available: ${available || "<none>"})`);
2432
+ }
2433
+ return filtered;
2434
+ }
2435
+ // index.ts
2436
+ var UTF8_DECODER = new TextDecoder("utf-8");
2437
+ function attachTextGetter(file) {
2438
+ let cachedContents;
2439
+ let cachedText;
2440
+ Object.defineProperty(file, "text", {
2441
+ get() {
2442
+ if (cachedContents !== file.contents) {
2443
+ cachedContents = file.contents;
2444
+ cachedText = UTF8_DECODER.decode(cachedContents);
2445
+ }
2446
+ return cachedText;
2447
+ },
2448
+ enumerable: false,
2449
+ configurable: true
2450
+ });
2451
+ return file;
2452
+ }
2453
+ function wrapOutputFiles(result) {
2454
+ for (const file of result.outputFiles)
2455
+ attachTextGetter(file);
2456
+ return result;
2457
+ }
2458
+ var native = null;
2459
+ function detectLinuxLibc() {
2460
+ if (process.platform !== "linux")
2461
+ return;
2462
+ try {
2463
+ const report = process.report?.getReport();
2464
+ if (report?.header?.glibcVersionRuntime)
2465
+ return "glibc";
2466
+ } catch {}
2467
+ return "musl";
2468
+ }
2469
+ function getPlatformPackage() {
2470
+ const { platform, arch } = process;
2471
+ const libc = detectLinuxLibc();
2472
+ const match = PLATFORMS.find((p) => p.npmOs === platform && p.npmCpu === arch && p.npmLibc === libc);
2473
+ return match ? subPackageName(match) : null;
2474
+ }
2475
+ function findAddon() {
2476
+ const __dirname2 = dirname3(fileURLToPath(import.meta.url));
2477
+ const platformPkg = getPlatformPackage();
2478
+ const zigOut = join3(__dirname2, "../../zig-out/lib/zntc.node");
2479
+ if (existsSync3(zigOut))
2480
+ return zigOut;
2481
+ const zigOut2 = join3(__dirname2, "../../../zig-out/lib/zntc.node");
2482
+ if (existsSync3(zigOut2))
2483
+ return zigOut2;
2484
+ if (platformPkg) {
2485
+ try {
2486
+ const nodeRequire = createRequire3(import.meta.url);
2487
+ return nodeRequire.resolve(platformPkg);
2488
+ } catch {}
2489
+ }
2490
+ const local = join3(__dirname2, "zntc.node");
2491
+ if (existsSync3(local))
2492
+ return local;
2493
+ const parent = join3(__dirname2, "../zntc.node");
2494
+ if (existsSync3(parent))
2495
+ return parent;
2496
+ const expected = platformPkg ? ` (expected sub-package: ${platformPkg})` : "";
2497
+ throw new Error(`@zntc/core: native binary not found for ${process.platform}-${process.arch}${expected}. ` + `Supported: ${formatSupportedPlatforms()}. ` + "For development run `zig build napi`. " + "If your platform should be supported, please open an issue.");
2498
+ }
2499
+ function defineConfig(config) {
2500
+ return config;
2501
+ }
2502
+ function init(addonPath) {
2503
+ if (native)
2504
+ return;
2505
+ const path = addonPath ?? findAddon();
2506
+ const nodeRequire = createRequire3(import.meta.url);
2507
+ native = nodeRequire(path);
2508
+ }
2509
+ function ensureNative() {
2510
+ init();
2511
+ return native;
2512
+ }
2513
+ var _browserslist = null;
2514
+ var _browserslistResolved = false;
2515
+ function loadBrowserslist() {
2516
+ if (_browserslistResolved)
2517
+ return _browserslist;
2518
+ _browserslistResolved = true;
2519
+ try {
2520
+ const req = createRequire3(import.meta.url);
2521
+ const name = "browserslist";
2522
+ _browserslist = req(name);
2523
+ } catch {
2524
+ _browserslist = null;
2525
+ }
2526
+ return _browserslist;
2527
+ }
2528
+ function resolveUnsupported(options) {
2529
+ if (options.browserslist) {
2530
+ const bl = loadBrowserslist();
2531
+ if (!bl) {
2532
+ throw new Error("@zntc/core: 'browserslist' option requires the 'browserslist' package. Install it: bun add browserslist");
2533
+ }
2534
+ return browserslistToUnsupported(bl(options.browserslist));
2535
+ }
2536
+ return options.target ? ES_TARGET_BITS[options.target] ?? 0 : 0;
2537
+ }
2538
+
2539
+ class TsconfigCache {
2540
+ _handle;
2541
+ constructor() {
2542
+ this._handle = ensureNative().createTsconfigCache();
2543
+ }
2544
+ clear() {
2545
+ this._handle.clear();
2546
+ }
2547
+ get size() {
2548
+ return this._handle.size();
2549
+ }
2550
+ [Symbol.dispose]() {
2551
+ this._handle.clear();
2552
+ }
2553
+ static _unwrap(c) {
2554
+ return c._handle;
2555
+ }
2556
+ }
2557
+ function transpile(source, options = {}) {
2558
+ if (!source)
2559
+ throw new Error("@zntc/core: empty source");
2560
+ validateTsConfigRaw(options.tsconfigRaw);
2561
+ const optionsJson = buildOptionsJson(options, resolveUnsupported(options));
2562
+ return ensureNative().transpile(source, options.filename ?? "input.js", optionsJson, options.cache ? TsconfigCache._unwrap(options.cache) : undefined);
2563
+ }
2564
+ function tokenize(source, options = {}) {
2565
+ if (!source)
2566
+ throw new Error("@zntc/core: empty source");
2567
+ return ensureNative().tokenize(source, options.filename ?? "input.js");
2568
+ }
2569
+ function configureProfile(profile, level) {
2570
+ ensureNative().configureProfile(profile, level);
2571
+ }
2572
+ function profileReport(format = "table") {
2573
+ return ensureNative().profileReport(format);
2574
+ }
2575
+ function normalizePluginFailure(pluginName, hookName, thrown, fallbackFile) {
2576
+ let message = "Plugin hook failed";
2577
+ let file = fallbackFile ?? undefined;
2578
+ let line;
2579
+ let column;
2580
+ if (typeof thrown === "string") {
2581
+ message = thrown;
2582
+ } else if (thrown && typeof thrown === "object") {
2583
+ const err = thrown;
2584
+ if (typeof err.message === "string")
2585
+ message = err.message;
2586
+ else if (typeof err.text === "string")
2587
+ message = err.text;
2588
+ else
2589
+ message = String(thrown);
2590
+ const loc = err.loc;
2591
+ const fileCandidate = loc?.file ?? err.id ?? err.file ?? err.fileName;
2592
+ if (typeof fileCandidate === "string" && fileCandidate.length > 0)
2593
+ file = fileCandidate;
2594
+ const lineCandidate = loc?.line ?? err.line ?? err.lineNumber;
2595
+ const columnCandidate = loc?.column ?? err.column ?? err.columnNumber;
2596
+ if (typeof lineCandidate === "number" && Number.isFinite(lineCandidate))
2597
+ line = lineCandidate;
2598
+ if (typeof columnCandidate === "number" && Number.isFinite(columnCandidate)) {
2599
+ column = columnCandidate;
2600
+ }
2601
+ } else if (thrown != null) {
2602
+ message = String(thrown);
2603
+ }
2604
+ return {
2605
+ __zntcPluginFailure: true,
2606
+ pluginName,
2607
+ hookName,
2608
+ message,
2609
+ ...file ? { file } : {},
2610
+ ...line !== undefined ? { line } : {},
2611
+ ...column !== undefined ? { column } : {}
2612
+ };
2613
+ }
2614
+ function pluginFailureText(failure) {
2615
+ const location = failure.file && failure.line !== undefined ? ` (${failure.file}:${failure.line}:${failure.column ?? 0})` : failure.file ? ` (${failure.file})` : "";
2616
+ return `Plugin "${failure.pluginName}" failed in ${failure.hookName}: ${failure.message}${location}`;
2617
+ }
2618
+ function pluginFailureToDiagnostic(failure) {
2619
+ return {
2620
+ code: "plugin_error",
2621
+ text: pluginFailureText(failure),
2622
+ ...failure.file ? { location: { file: failure.file, line: failure.line, column: failure.column } } : {}
2623
+ };
2624
+ }
2625
+ function serializePluginSourceMap(map) {
2626
+ if (map == null)
2627
+ return null;
2628
+ if (typeof map === "string") {
2629
+ try {
2630
+ JSON.parse(map);
2631
+ } catch (err) {
2632
+ throw new Error(`Invalid sourcemap: ${err instanceof Error ? err.message : String(err)}`);
2633
+ }
2634
+ return map;
2635
+ }
2636
+ if (typeof map !== "object") {
2637
+ throw new Error(`Invalid sourcemap: expected object, string, null, or undefined`);
2638
+ }
2639
+ try {
2640
+ return JSON.stringify(map);
2641
+ } catch (err) {
2642
+ throw new Error(`Invalid sourcemap: ${err instanceof Error ? err.message : String(err)}`);
2643
+ }
2644
+ }
2645
+ function isPromiseLike(value) {
2646
+ return value != null && (typeof value === "object" || typeof value === "function") && typeof value.then === "function";
2647
+ }
2648
+ function silenceUnsupportedSyncPromise(value) {
2649
+ Promise.resolve(value).catch(() => {});
2650
+ }
2651
+ function syncPluginPromiseFailure(pluginName, hookName, file) {
2652
+ return normalizePluginFailure(pluginName, hookName, new Error("buildSync() does not support async plugin hooks. Return a synchronous value or use build() instead."), file);
2653
+ }
2654
+ function isPluginFailureResult(value) {
2655
+ return Boolean(value && typeof value === "object" && value.__zntcPluginFailure === true);
2656
+ }
2657
+ function safeSerializeSourceMap(map) {
2658
+ try {
2659
+ return { ok: true, map: serializePluginSourceMap(map) };
2660
+ } catch (err) {
2661
+ return { ok: false, err };
2662
+ }
2663
+ }
2664
+ function mapMaybePromise(value, mapper) {
2665
+ if (isPromiseLike(value))
2666
+ return Promise.resolve(value).then(mapper);
2667
+ return mapper(value);
2668
+ }
2669
+ function collectPluginRegistry(plugins) {
2670
+ const registry = {
2671
+ hooks: {
2672
+ resolveId: [],
2673
+ load: [],
2674
+ transform: [],
2675
+ renderChunk: [],
2676
+ resolveContext: []
2677
+ },
2678
+ generateBundleCallbacks: [],
2679
+ buildStartCallbacks: [],
2680
+ buildEndCallbacks: [],
2681
+ closeBundleCallbacks: [],
2682
+ astFunctionHooks: [],
2683
+ lifecycleFailures: []
2684
+ };
2685
+ for (const plugin of plugins) {
2686
+ const build = {
2687
+ onResolve(opts, cb) {
2688
+ registry.hooks.resolveId.push({
2689
+ pluginName: plugin.name,
2690
+ filter: opts.filter,
2691
+ callback: cb
2692
+ });
2693
+ },
2694
+ onLoad(opts, cb) {
2695
+ registry.hooks.load.push({ pluginName: plugin.name, filter: opts.filter, callback: cb });
2696
+ },
2697
+ onTransform(opts, cb) {
2698
+ registry.hooks.transform.push({
2699
+ pluginName: plugin.name,
2700
+ filter: opts.filter,
2701
+ callback: cb
2702
+ });
2703
+ },
2704
+ onRenderChunk(opts, cb) {
2705
+ registry.hooks.renderChunk.push({
2706
+ pluginName: plugin.name,
2707
+ filter: opts.filter,
2708
+ callback: cb
2709
+ });
2710
+ },
2711
+ onGenerateBundle(cb) {
2712
+ registry.generateBundleCallbacks.push({ pluginName: plugin.name, callback: cb });
2713
+ },
2714
+ onBuildStart(cb) {
2715
+ registry.buildStartCallbacks.push({ pluginName: plugin.name, callback: cb });
2716
+ },
2717
+ onBuildEnd(cb) {
2718
+ registry.buildEndCallbacks.push({ pluginName: plugin.name, callback: cb });
2719
+ },
2720
+ onCloseBundle(cb) {
2721
+ registry.closeBundleCallbacks.push({ pluginName: plugin.name, callback: cb });
2722
+ },
2723
+ onAstFunction(opts, cb) {
2724
+ registry.astFunctionHooks.push({
2725
+ pluginName: plugin.name,
2726
+ filter: opts.filter,
2727
+ callback: cb
2728
+ });
2729
+ },
2730
+ onResolveContext(opts, cb) {
2731
+ registry.hooks.resolveContext.push({
2732
+ pluginName: plugin.name,
2733
+ filter: opts.filter,
2734
+ callback: cb
2735
+ });
2736
+ }
2737
+ };
2738
+ plugin.setup(build);
2739
+ }
2740
+ return registry;
2741
+ }
2742
+ var pluginArgBuilders = {
2743
+ resolveId: (arg1, arg2) => [arg1, { path: arg1, importer: arg2 }],
2744
+ load: (arg1, _) => [arg1, { path: arg1 }],
2745
+ renderChunk: (arg1, arg2) => [arg2 ?? "", { code: arg1, chunk: arg2 }]
2746
+ };
2747
+ function lifecycleHookSpec(reg, hookName, arg1) {
2748
+ switch (hookName) {
2749
+ case "generateBundle": {
2750
+ const outputs = arg1;
2751
+ for (const file of outputs)
2752
+ attachTextGetter(file);
2753
+ return {
2754
+ callbacks: reg.generateBundleCallbacks,
2755
+ arg: outputs,
2756
+ surfaceFailures: false
2757
+ };
2758
+ }
2759
+ case "buildStart":
2760
+ return { callbacks: reg.buildStartCallbacks, arg: undefined, surfaceFailures: false };
2761
+ case "buildEnd": {
2762
+ const msg = arg1;
2763
+ return {
2764
+ callbacks: reg.buildEndCallbacks,
2765
+ arg: msg && msg.length > 0 ? new Error(msg) : undefined,
2766
+ surfaceFailures: true
2767
+ };
2768
+ }
2769
+ case "closeBundle":
2770
+ return { callbacks: reg.closeBundleCallbacks, arg: undefined, surfaceFailures: true };
2771
+ default:
2772
+ return null;
2773
+ }
2774
+ }
2775
+ function* dispatchHook(reg, hookName, arg1, arg2) {
2776
+ if (hookName === "astFunction") {
2777
+ if (reg.astFunctionHooks.length === 0)
2778
+ return null;
2779
+ let info;
2780
+ try {
2781
+ info = JSON.parse(arg1);
2782
+ } catch {
2783
+ return null;
2784
+ }
2785
+ for (const h of reg.astFunctionHooks) {
2786
+ if (!h.filter.test(info.sourcePath))
2787
+ continue;
2788
+ const result = yield {
2789
+ callback: () => h.callback(info),
2790
+ pluginName: h.pluginName,
2791
+ hookName: "astFunction",
2792
+ fallbackFile: info.sourcePath
2793
+ };
2794
+ if (isPluginFailureResult(result))
2795
+ return result;
2796
+ if (result != null)
2797
+ return result;
2798
+ }
2799
+ return null;
2800
+ }
2801
+ if (hookName === "resolveContext") {
2802
+ if (reg.hooks.resolveContext.length === 0)
2803
+ return null;
2804
+ let args;
2805
+ try {
2806
+ args = JSON.parse(arg1);
2807
+ } catch {
2808
+ return null;
2809
+ }
2810
+ for (const h of reg.hooks.resolveContext) {
2811
+ if (!h.filter.test(args.dir))
2812
+ continue;
2813
+ const result = yield {
2814
+ callback: () => h.callback(args),
2815
+ pluginName: h.pluginName,
2816
+ hookName: "resolveContext",
2817
+ fallbackFile: args.importer
2818
+ };
2819
+ if (isPluginFailureResult(result))
2820
+ return result;
2821
+ if (result != null)
2822
+ return result;
2823
+ }
2824
+ return null;
2825
+ }
2826
+ {
2827
+ const spec = lifecycleHookSpec(reg, hookName, arg1);
2828
+ if (spec) {
2829
+ let firstFailure = null;
2830
+ for (const { pluginName, callback } of spec.callbacks) {
2831
+ const result = yield {
2832
+ callback: () => callback(spec.arg),
2833
+ pluginName,
2834
+ hookName
2835
+ };
2836
+ if (isPluginFailureResult(result) && firstFailure == null)
2837
+ firstFailure = result;
2838
+ }
2839
+ if (spec.surfaceFailures) {
2840
+ if (firstFailure)
2841
+ reg.lifecycleFailures.push(firstFailure);
2842
+ return null;
2843
+ }
2844
+ return firstFailure;
2845
+ }
2846
+ }
2847
+ if (hookName === "transform" || hookName === "renderChunk") {
2848
+ const hookList2 = reg.hooks[hookName];
2849
+ if (!hookList2)
2850
+ return null;
2851
+ let currentCode = arg1;
2852
+ let changed = false;
2853
+ const sourceMaps = [];
2854
+ for (const h of hookList2) {
2855
+ if (!h.filter.test(arg2 ?? ""))
2856
+ continue;
2857
+ const cbArgs2 = hookName === "transform" ? { code: currentCode, path: arg2 } : { code: currentCode, chunk: arg2 };
2858
+ const result = yield {
2859
+ callback: () => h.callback(cbArgs2),
2860
+ pluginName: h.pluginName,
2861
+ hookName,
2862
+ fallbackFile: arg2
2863
+ };
2864
+ if (isPluginFailureResult(result))
2865
+ return result;
2866
+ if (result != null) {
2867
+ const obj = result;
2868
+ const newCode = typeof result === "string" ? result : obj.code;
2869
+ if (typeof newCode === "string") {
2870
+ currentCode = newCode;
2871
+ changed = true;
2872
+ }
2873
+ if (hookName === "transform" && typeof result === "object" && "map" in obj) {
2874
+ const r = safeSerializeSourceMap(obj.map);
2875
+ if (!r.ok)
2876
+ return normalizePluginFailure(h.pluginName, hookName, r.err, arg2);
2877
+ if (r.map != null)
2878
+ sourceMaps.push(r.map);
2879
+ }
2880
+ }
2881
+ }
2882
+ return changed ? { code: currentCode, ...sourceMaps.length > 0 ? { maps: sourceMaps } : {} } : null;
2883
+ }
2884
+ const hookList = reg.hooks[hookName];
2885
+ if (!hookList)
2886
+ return null;
2887
+ const buildArgs = pluginArgBuilders[hookName];
2888
+ if (!buildArgs)
2889
+ return null;
2890
+ const [filterTarget, cbArgs] = buildArgs(arg1, arg2);
2891
+ for (const h of hookList) {
2892
+ if (!h.filter.test(filterTarget))
2893
+ continue;
2894
+ const fallbackFile = hookName === "resolveId" ? arg2 : filterTarget;
2895
+ const result = yield {
2896
+ callback: () => h.callback(cbArgs),
2897
+ pluginName: h.pluginName,
2898
+ hookName,
2899
+ fallbackFile
2900
+ };
2901
+ if (isPluginFailureResult(result))
2902
+ return result;
2903
+ if (result != null) {
2904
+ if (hookName === "load" && typeof result === "object" && "map" in result) {
2905
+ const r = safeSerializeSourceMap(result.map);
2906
+ if (!r.ok)
2907
+ return normalizePluginFailure(h.pluginName, hookName, r.err, fallbackFile);
2908
+ return { ...result, ...r.map != null ? { map: r.map } : { map: undefined } };
2909
+ }
2910
+ return result;
2911
+ }
2912
+ }
2913
+ return null;
2914
+ }
2915
+ async function driveDispatchAsync(gen) {
2916
+ let r = gen.next();
2917
+ while (!r.done) {
2918
+ const call = r.value;
2919
+ let value;
2920
+ try {
2921
+ value = await call.callback();
2922
+ } catch (err) {
2923
+ value = normalizePluginFailure(call.pluginName, call.hookName, err, call.fallbackFile);
2924
+ }
2925
+ r = gen.next(value);
2926
+ }
2927
+ return r.value;
2928
+ }
2929
+ function driveDispatchSync(gen) {
2930
+ let r = gen.next();
2931
+ while (!r.done) {
2932
+ const call = r.value;
2933
+ let value;
2934
+ try {
2935
+ const raw = call.callback();
2936
+ if (isPromiseLike(raw)) {
2937
+ silenceUnsupportedSyncPromise(raw);
2938
+ value = syncPluginPromiseFailure(call.pluginName, call.hookName, call.fallbackFile);
2939
+ } else {
2940
+ value = raw;
2941
+ }
2942
+ } catch (err) {
2943
+ value = normalizePluginFailure(call.pluginName, call.hookName, err, call.fallbackFile);
2944
+ }
2945
+ r = gen.next(value);
2946
+ }
2947
+ return r.value;
2948
+ }
2949
+ function createPluginDispatcher(plugins) {
2950
+ const reg = collectPluginRegistry(plugins);
2951
+ const dispatcher = function dispatcher2(hookName, arg1, arg2) {
2952
+ return driveDispatchAsync(dispatchHook(reg, hookName, arg1, arg2));
2953
+ };
2954
+ dispatcher.takeLifecycleFailures = () => reg.lifecycleFailures.splice(0);
2955
+ return dispatcher;
2956
+ }
2957
+ function createSyncPluginDispatcher(plugins) {
2958
+ const reg = collectPluginRegistry(plugins);
2959
+ const dispatcher = function dispatcher2(hookName, arg1, arg2) {
2960
+ return driveDispatchSync(dispatchHook(reg, hookName, arg1, arg2));
2961
+ };
2962
+ dispatcher.takeLifecycleFailures = () => reg.lifecycleFailures.splice(0);
2963
+ return dispatcher;
2964
+ }
2965
+ function arrayAliasToPlugin(aliasArray) {
2966
+ return {
2967
+ name: "zntc:array-alias",
2968
+ setup(build) {
2969
+ build.onResolve({ filter: /.*/ }, (args) => {
2970
+ for (const { find, replacement } of aliasArray) {
2971
+ if (find instanceof RegExp) {
2972
+ if (args.path.search(find) !== -1) {
2973
+ return { path: args.path.replace(find, replacement) };
2974
+ }
2975
+ } else if (args.path === find || args.path.startsWith(find + "/")) {
2976
+ return { path: args.path.replace(find, replacement) };
2977
+ }
2978
+ }
2979
+ return null;
2980
+ });
2981
+ }
2982
+ };
2983
+ }
2984
+ function resolveDispatcher(options, mode = "async") {
2985
+ const arrayAlias = Array.isArray(options.alias) ? options.alias : null;
2986
+ const userPlugins = options.plugins ?? [];
2987
+ const allPlugins = arrayAlias ? [arrayAliasToPlugin(arrayAlias), ...userPlugins] : userPlugins;
2988
+ if (allPlugins.length === 0)
2989
+ return null;
2990
+ return mode === "sync" ? createSyncPluginDispatcher(allPlugins) : createPluginDispatcher(allPlugins);
2991
+ }
2992
+ function isBrowserLikeBuildPlatform(platform) {
2993
+ return platform === undefined || platform === "browser" || platform === "react-native";
2994
+ }
2995
+ function withDefaultBuildDefines(options) {
2996
+ const define = { ...options.define };
2997
+ const browserLike = isBrowserLikeBuildPlatform(options.platform) || options.minifySyntax === true;
2998
+ if (browserLike && define["process.env.NODE_ENV"] === undefined) {
2999
+ define["process.env.NODE_ENV"] = options.devMode ? '"development"' : '"production"';
3000
+ }
3001
+ if (options.platform === "react-native" && define.__DEV__ === undefined) {
3002
+ define.__DEV__ = options.devMode ? "true" : "false";
3003
+ }
3004
+ return Object.keys(define).length > 0 ? define : undefined;
3005
+ }
3006
+ function withDefaultAppBuildDefines(options) {
3007
+ const define = { ...options.define };
3008
+ if (define["process.env.NODE_ENV"] === undefined) {
3009
+ define["process.env.NODE_ENV"] = (options.mode ?? "production") === "production" ? '"production"' : '"development"';
3010
+ }
3011
+ return define;
3012
+ }
3013
+ function prepareNapiOptions(options) {
3014
+ const napiOptions = { ...options };
3015
+ const define = withDefaultBuildDefines(options);
3016
+ if (define)
3017
+ napiOptions.define = define;
3018
+ delete napiOptions.write;
3019
+ delete napiOptions.outdir;
3020
+ delete napiOptions.plugins;
3021
+ delete napiOptions.allowOverwrite;
3022
+ if (Array.isArray(napiOptions.alias))
3023
+ delete napiOptions.alias;
3024
+ delete napiOptions.manualChunks;
3025
+ if (options.manualChunks) {
3026
+ napiOptions._manualChunks = options.manualChunks;
3027
+ }
3028
+ delete napiOptions.mf;
3029
+ if (options.mf) {
3030
+ napiOptions.mfRaw = JSON.stringify(options.mf);
3031
+ }
3032
+ if (options.blockList) {
3033
+ napiOptions.blockList = options.blockList.map((p) => {
3034
+ if (p instanceof RegExp)
3035
+ return p.source;
3036
+ if (typeof p === "string")
3037
+ return p;
3038
+ throw new TypeError(`blockList entries must be RegExp or string, got ${typeof p}`);
3039
+ });
3040
+ }
3041
+ if (options.browserslist) {
3042
+ napiOptions.unsupported = resolveUnsupported({ browserslist: options.browserslist });
3043
+ delete napiOptions.browserslist;
3044
+ }
3045
+ if (options.target && !isEsTarget(options.target)) {
3046
+ delete napiOptions.target;
3047
+ }
3048
+ delete napiOptions.compiler;
3049
+ const sc = options.compiler?.styledComponents;
3050
+ if (sc !== undefined && sc !== false) {
3051
+ napiOptions.styledComponents = true;
3052
+ if (typeof sc === "object") {
3053
+ if (sc.ssr === false)
3054
+ napiOptions.styledComponentsSsr = false;
3055
+ if (sc.minify === true)
3056
+ napiOptions.styledComponentsMinify = true;
3057
+ if (sc.fileName === false)
3058
+ napiOptions.styledComponentsFileName = false;
3059
+ if (sc.pure === true)
3060
+ napiOptions.styledComponentsPure = true;
3061
+ if (typeof sc.namespace === "string" && sc.namespace.length > 0) {
3062
+ napiOptions.styledComponentsNamespace = sc.namespace;
3063
+ }
3064
+ if (Array.isArray(sc.meaninglessFileNames)) {
3065
+ napiOptions.styledComponentsMeaninglessFileNames = sc.meaninglessFileNames;
3066
+ }
3067
+ if (Array.isArray(sc.topLevelImportPaths)) {
3068
+ napiOptions.styledComponentsTopLevelImportPaths = sc.topLevelImportPaths;
3069
+ }
3070
+ if (sc.cssProp === true)
3071
+ napiOptions.styledComponentsCssProp = true;
3072
+ }
3073
+ }
3074
+ const em = options.compiler?.emotion;
3075
+ if (em !== undefined && em !== false) {
3076
+ napiOptions.emotion = true;
3077
+ if (typeof em === "object") {
3078
+ if (em.autoLabel === false) {
3079
+ napiOptions.emotionAutoLabel = "never";
3080
+ } else if (em.autoLabel === true) {
3081
+ napiOptions.emotionAutoLabel = "always";
3082
+ } else if (typeof em.autoLabel === "string") {
3083
+ napiOptions.emotionAutoLabel = em.autoLabel;
3084
+ }
3085
+ if (em.sourceMap === true)
3086
+ napiOptions.emotionSourceMap = true;
3087
+ if (typeof em.labelFormat === "string" && em.labelFormat.length > 0) {
3088
+ napiOptions.emotionLabelFormat = em.labelFormat;
3089
+ }
3090
+ const extras = collectEmotionImportMapExtras(em.importMap);
3091
+ if (extras.css.length > 0)
3092
+ napiOptions.emotionExtraCssSources = extras.css;
3093
+ if (extras.styled.length > 0)
3094
+ napiOptions.emotionExtraStyledSources = extras.styled;
3095
+ }
3096
+ }
3097
+ const runtimePolyfills = applyRuntimePolyfillsToNapiOptions(napiOptions, {
3098
+ entryPoints: options.entryPoints,
3099
+ platform: options.platform,
3100
+ target: options.target,
3101
+ browserslist: options.browserslist,
3102
+ runtimePolyfills: options.runtimePolyfills,
3103
+ coreJs: options.coreJs,
3104
+ runBeforeMain: options.runBeforeMain,
3105
+ resolveExtensions: options.resolveExtensions
3106
+ });
3107
+ return { napiOptions, cleanup: runtimePolyfills.cleanup };
3108
+ }
3109
+ var EMOTION_CSS_CANONICAL_SOURCES = new Set([
3110
+ "@emotion/react",
3111
+ "@emotion/css",
3112
+ "@emotion/core",
3113
+ "@emotion/native",
3114
+ "@emotion/primitives",
3115
+ "@emotion/primitives-core"
3116
+ ]);
3117
+ function collectEmotionImportMapExtras(importMap) {
3118
+ const css = new Set;
3119
+ const styled = new Set;
3120
+ if (!importMap)
3121
+ return { css: [], styled: [] };
3122
+ for (const [source, locals] of Object.entries(importMap)) {
3123
+ for (const spec of Object.values(locals)) {
3124
+ const [pkg, exportName] = spec.canonicalImport;
3125
+ if (pkg === "@emotion/styled" && exportName === "default") {
3126
+ styled.add(source);
3127
+ } else if (EMOTION_CSS_CANONICAL_SOURCES.has(pkg)) {
3128
+ css.add(source);
3129
+ }
3130
+ }
3131
+ }
3132
+ return { css: [...css], styled: [...styled] };
3133
+ }
3134
+ function postProcessCssOutputs(result, options) {
3135
+ if (!options.minify)
3136
+ return;
3137
+ let lcss;
3138
+ try {
3139
+ lcss = require_node();
3140
+ } catch {
3141
+ return;
3142
+ }
3143
+ for (const file of result.outputFiles) {
3144
+ if (!file.path.endsWith(".css"))
3145
+ continue;
3146
+ try {
3147
+ const transformed = lcss.transform({
3148
+ code: file.contents,
3149
+ minify: true,
3150
+ filename: file.path
3151
+ });
3152
+ file.contents = transformed.code;
3153
+ } catch {}
3154
+ }
3155
+ }
3156
+ function writeOutputFiles(result, options) {
3157
+ const shouldWrite = options.write ?? (options.outdir != null || options.outfile != null);
3158
+ if (!shouldWrite)
3159
+ return;
3160
+ if (!options.allowOverwrite && options.outfile) {
3161
+ const outResolved = resolve2(options.outfile);
3162
+ for (const entry of options.entryPoints) {
3163
+ if (resolve2(entry) === outResolved) {
3164
+ throw new Error(`@zntc/core: output file '${options.outfile}' would overwrite input file (set allowOverwrite: true to permit)`);
3165
+ }
3166
+ }
3167
+ }
3168
+ const createdDirs = new Set;
3169
+ const outfileResolved = options.outfile ? resolve2(options.outfile) : null;
3170
+ for (const file of result.outputFiles) {
3171
+ let outPath;
3172
+ if (outfileResolved && file.path === "bundle.js") {
3173
+ outPath = outfileResolved;
3174
+ } else if (outfileResolved && file.path.endsWith(".map")) {
3175
+ outPath = outfileResolved + ".map";
3176
+ } else if (options.outdir) {
3177
+ outPath = join3(resolve2(options.outdir), file.path);
3178
+ } else {
3179
+ outPath = resolve2(file.path);
3180
+ }
3181
+ const dir = dirname3(outPath);
3182
+ if (!createdDirs.has(dir)) {
3183
+ mkdirSync(dir, { recursive: true });
3184
+ createdDirs.add(dir);
3185
+ }
3186
+ writeFileSync2(outPath, file.contents);
3187
+ }
3188
+ }
3189
+ async function build(options) {
3190
+ const n = ensureNative();
3191
+ if (!options.entryPoints?.length)
3192
+ throw new Error("@zntc/core: entryPoints is required");
3193
+ validateTsConfigRaw(options.tsconfigRaw);
3194
+ if (options.output && options.output.length >= 2) {
3195
+ return buildMultiFormat(options);
3196
+ }
3197
+ const { napiOptions, cleanup } = prepareNapiOptions(options);
3198
+ const dispatcher = resolveDispatcher(options);
3199
+ if (dispatcher)
3200
+ napiOptions._pluginDispatcher = dispatcher;
3201
+ try {
3202
+ const result = wrapOutputFiles(await n.build(napiOptions));
3203
+ if (dispatcher) {
3204
+ for (const failure of dispatcher.takeLifecycleFailures()) {
3205
+ result.errors.push(pluginFailureToDiagnostic(failure));
3206
+ }
3207
+ }
3208
+ postProcessCssOutputs(result, options);
3209
+ writeOutputFiles(result, options);
3210
+ if (dispatcher) {
3211
+ await dispatcher("closeBundle", undefined, null);
3212
+ for (const failure of dispatcher.takeLifecycleFailures()) {
3213
+ result.errors.push(pluginFailureToDiagnostic(failure));
3214
+ }
3215
+ }
3216
+ return result;
3217
+ } finally {
3218
+ cleanup();
3219
+ }
3220
+ }
3221
+ function buildSync(options) {
3222
+ const n = ensureNative();
3223
+ if (!options.entryPoints?.length)
3224
+ throw new Error("@zntc/core: entryPoints is required");
3225
+ validateTsConfigRaw(options.tsconfigRaw);
3226
+ const { napiOptions, cleanup } = prepareNapiOptions(options);
3227
+ const dispatcher = resolveDispatcher(options, "sync");
3228
+ if (dispatcher)
3229
+ napiOptions._pluginDispatcherSync = dispatcher;
3230
+ try {
3231
+ const result = wrapOutputFiles(n.buildSync(napiOptions));
3232
+ if (dispatcher) {
3233
+ for (const failure of dispatcher.takeLifecycleFailures()) {
3234
+ result.errors.push(pluginFailureToDiagnostic(failure));
3235
+ }
3236
+ }
3237
+ postProcessCssOutputs(result, options);
3238
+ writeOutputFiles(result, options);
3239
+ if (dispatcher) {
3240
+ dispatcher("closeBundle", undefined, null);
3241
+ for (const failure of dispatcher.takeLifecycleFailures()) {
3242
+ result.errors.push(pluginFailureToDiagnostic(failure));
3243
+ }
3244
+ }
3245
+ return result;
3246
+ } finally {
3247
+ cleanup();
3248
+ }
3249
+ }
3250
+
3251
+ class BuildInstance {
3252
+ #base;
3253
+ #closed = false;
3254
+ constructor(base) {
3255
+ this.#base = base;
3256
+ }
3257
+ get closed() {
3258
+ return this.#closed;
3259
+ }
3260
+ async write(output = {}) {
3261
+ this.#assertOpen();
3262
+ return build(mergeOutput(this.#base, output));
3263
+ }
3264
+ async generate(output = {}) {
3265
+ this.#assertOpen();
3266
+ return build({ ...mergeOutput(this.#base, output), write: false });
3267
+ }
3268
+ async close() {
3269
+ this.#closed = true;
3270
+ }
3271
+ #assertOpen() {
3272
+ if (this.#closed)
3273
+ throw new Error("@zntc/core: BuildInstance is closed");
3274
+ }
3275
+ }
3276
+ function mergeOutput(base, out) {
3277
+ const merged = { ...base };
3278
+ if (out.format !== undefined)
3279
+ merged.format = out.format;
3280
+ if (out.dir !== undefined)
3281
+ merged.outdir = out.dir;
3282
+ if (out.file !== undefined)
3283
+ merged.outfile = out.file;
3284
+ if (out.globals !== undefined)
3285
+ merged.globals = out.globals;
3286
+ return merged;
3287
+ }
3288
+ async function zntc(options) {
3289
+ if (!options.entryPoints?.length)
3290
+ throw new Error("@zntc/core: entryPoints is required");
3291
+ validateTsConfigRaw(options.tsconfigRaw);
3292
+ return new BuildInstance(options);
3293
+ }
3294
+ async function buildMultiFormat(options) {
3295
+ const outputs = options.output;
3296
+ const { output: _omit, ...baseOpts } = options;
3297
+ const aggregated = {
3298
+ outputFiles: [],
3299
+ errors: [],
3300
+ warnings: [],
3301
+ outputsByFormat: []
3302
+ };
3303
+ for (const cfg of outputs) {
3304
+ const r = await build(mergeOutput(baseOpts, cfg));
3305
+ aggregated.errors.push(...r.errors);
3306
+ aggregated.warnings.push(...r.warnings);
3307
+ aggregated.outputsByFormat.push({
3308
+ format: cfg.format ?? "esm",
3309
+ outputFiles: r.outputFiles
3310
+ });
3311
+ }
3312
+ if (aggregated.outputsByFormat.length > 0) {
3313
+ aggregated.outputFiles = aggregated.outputsByFormat[0].outputFiles;
3314
+ }
3315
+ return aggregated;
3316
+ }
3317
+ function buildAppSync(options = {}) {
3318
+ const n = ensureNative();
3319
+ const { publicDir, compiler, ...rest } = options;
3320
+ return wrapOutputFiles(n.buildAppSync({
3321
+ ...rest,
3322
+ define: withDefaultAppBuildDefines(options),
3323
+ ...publicDir === false ? { disablePublicDir: true } : publicDir !== undefined ? { publicDir } : {},
3324
+ ...buildCompilerNapiFields(compiler)
3325
+ }));
3326
+ }
3327
+ function buildCompilerNapiFields(compiler) {
3328
+ const out = {};
3329
+ const sc = compiler?.styledComponents;
3330
+ if (sc !== undefined && sc !== false)
3331
+ out.styledComponents = true;
3332
+ if (typeof sc === "object") {
3333
+ if (sc.ssr === false)
3334
+ out.styledComponentsSsr = false;
3335
+ if (sc.minify === true)
3336
+ out.styledComponentsMinify = true;
3337
+ if (sc.fileName === false)
3338
+ out.styledComponentsFileName = false;
3339
+ if (sc.pure === true)
3340
+ out.styledComponentsPure = true;
3341
+ if (typeof sc.namespace === "string" && sc.namespace.length > 0) {
3342
+ out.styledComponentsNamespace = sc.namespace;
3343
+ }
3344
+ if (Array.isArray(sc.meaninglessFileNames)) {
3345
+ out.styledComponentsMeaninglessFileNames = sc.meaninglessFileNames;
3346
+ }
3347
+ if (Array.isArray(sc.topLevelImportPaths)) {
3348
+ out.styledComponentsTopLevelImportPaths = sc.topLevelImportPaths;
3349
+ }
3350
+ if (sc.cssProp === true)
3351
+ out.styledComponentsCssProp = true;
3352
+ }
3353
+ const em = compiler?.emotion;
3354
+ if (em !== undefined && em !== false)
3355
+ out.emotion = true;
3356
+ if (typeof em === "object") {
3357
+ if (em.autoLabel === false)
3358
+ out.emotionAutoLabel = "never";
3359
+ else if (em.autoLabel === true)
3360
+ out.emotionAutoLabel = "always";
3361
+ else if (typeof em.autoLabel === "string")
3362
+ out.emotionAutoLabel = em.autoLabel;
3363
+ if (em.sourceMap === true)
3364
+ out.emotionSourceMap = true;
3365
+ if (typeof em.labelFormat === "string" && em.labelFormat.length > 0) {
3366
+ out.emotionLabelFormat = em.labelFormat;
3367
+ }
3368
+ const extras = collectEmotionImportMapExtras(em.importMap);
3369
+ if (extras.css.length > 0)
3370
+ out.emotionExtraCssSources = extras.css;
3371
+ if (extras.styled.length > 0)
3372
+ out.emotionExtraStyledSources = extras.styled;
3373
+ }
3374
+ return out;
3375
+ }
3376
+ function prepareAppDevSync(options = {}) {
3377
+ const n = ensureNative();
3378
+ const { publicDir, ...rest } = options;
3379
+ return n.prepareAppDevSync({
3380
+ ...rest,
3381
+ ...publicDir === false ? { disablePublicDir: true } : publicDir !== undefined ? { publicDir } : {}
3382
+ });
3383
+ }
3384
+ function close() {
3385
+ native = null;
3386
+ }
3387
+ function benchmark(options) {
3388
+ if (!options.source && !options.file) {
3389
+ throw new Error("@zntc/core.benchmark: 'source' or 'file' is required");
3390
+ }
3391
+ if (!Array.isArray(options.phases) || options.phases.length === 0) {
3392
+ throw new Error("@zntc/core.benchmark: 'phases' must be a non-empty string array");
3393
+ }
3394
+ return ensureNative().benchmark({
3395
+ source: options.source,
3396
+ file: options.file,
3397
+ filename: options.filename ?? "input.js",
3398
+ phases: options.phases,
3399
+ iterations: options.iterations ?? 100,
3400
+ warmup: options.warmup ?? 10
3401
+ });
3402
+ }
3403
+ function extractHandler(hook) {
3404
+ if (hook == null)
3405
+ return;
3406
+ if (typeof hook === "function")
3407
+ return hook;
3408
+ if (typeof hook === "object" && typeof hook.handler === "function") {
3409
+ return hook.handler;
3410
+ }
3411
+ return;
3412
+ }
3413
+ function normalizeVitePluginSourceMap(map, onDrop) {
3414
+ if (map == null)
3415
+ return;
3416
+ if (typeof map === "object") {
3417
+ const obj = map;
3418
+ const ver = typeof obj.version === "string" ? Number(obj.version) : obj.version;
3419
+ if (ver !== 3) {
3420
+ onDrop(`version=${String(obj.version)} (expected 3)`);
3421
+ return;
3422
+ }
3423
+ if (!Array.isArray(obj.sources)) {
3424
+ onDrop(`missing sources array`);
3425
+ return;
3426
+ }
3427
+ if (typeof obj.mappings !== "string") {
3428
+ onDrop(`missing mappings string`);
3429
+ return;
3430
+ }
3431
+ }
3432
+ try {
3433
+ return serializePluginSourceMap(map) ?? undefined;
3434
+ } catch (err) {
3435
+ onDrop(err instanceof Error ? err.message : String(err));
3436
+ return;
3437
+ }
3438
+ }
3439
+ function createRollupPluginContext(pluginName) {
3440
+ return {
3441
+ error(error) {
3442
+ throw error;
3443
+ },
3444
+ warn(message) {
3445
+ console.warn(`@zntc/core [${pluginName}]: ${typeof message === "string" ? message : String(message)}`);
3446
+ },
3447
+ addWatchFile(_id) {},
3448
+ resolve(_source, _importer, _options) {
3449
+ throw new Error(`@zntc/core [${pluginName}]: this.resolve() is not supported by vitePlugin() adapter yet ` + `(graph mutation surface missing). Use alias config or another plugin's resolveId hook.`);
3450
+ },
3451
+ emitFile(_file) {
3452
+ throw new Error(`@zntc/core [${pluginName}]: this.emitFile() is not supported by vitePlugin() adapter yet.`);
3453
+ }
3454
+ };
3455
+ }
3456
+ function createDropWarner(context) {
3457
+ const seen = new Set;
3458
+ return (reason) => {
3459
+ if (seen.has(reason))
3460
+ return;
3461
+ seen.add(reason);
3462
+ context.warn(`sourcemap dropped: ${reason}`);
3463
+ };
3464
+ }
3465
+ function vitePlugin(rollupPlugin) {
3466
+ return {
3467
+ name: rollupPlugin.name,
3468
+ setup(build2) {
3469
+ const context = createRollupPluginContext(rollupPlugin.name);
3470
+ const onDropSourceMap = createDropWarner(context);
3471
+ const resolveId = extractHandler(rollupPlugin.resolveId);
3472
+ if (resolveId) {
3473
+ build2.onResolve({ filter: /.*/ }, (args) => {
3474
+ const result = resolveId.call(context, args.path, args.importer);
3475
+ return mapMaybePromise(result, (result2) => {
3476
+ if (result2 == null)
3477
+ return null;
3478
+ if (typeof result2 === "string")
3479
+ return { path: result2 };
3480
+ if (typeof result2 === "object" && "id" in result2) {
3481
+ return { path: result2.id, external: result2.external };
3482
+ }
3483
+ return null;
3484
+ });
3485
+ });
3486
+ }
3487
+ const load = extractHandler(rollupPlugin.load);
3488
+ if (load) {
3489
+ build2.onLoad({ filter: /.*/ }, (args) => {
3490
+ const result = load.call(context, args.path);
3491
+ return mapMaybePromise(result, (result2) => {
3492
+ if (result2 == null)
3493
+ return null;
3494
+ if (typeof result2 === "string")
3495
+ return { contents: result2 };
3496
+ if (typeof result2 === "object" && "code" in result2) {
3497
+ return {
3498
+ contents: result2.code,
3499
+ map: normalizeVitePluginSourceMap(result2.map, onDropSourceMap)
3500
+ };
3501
+ }
3502
+ return null;
3503
+ });
3504
+ });
3505
+ }
3506
+ const transform = extractHandler(rollupPlugin.transform);
3507
+ if (transform) {
3508
+ build2.onTransform({ filter: /.*/ }, (args) => {
3509
+ const result = transform.call(context, args.code, args.path);
3510
+ return mapMaybePromise(result, (result2) => {
3511
+ if (result2 == null)
3512
+ return null;
3513
+ if (typeof result2 === "string")
3514
+ return { code: result2 };
3515
+ if (typeof result2 === "object" && "code" in result2) {
3516
+ return {
3517
+ code: result2.code,
3518
+ map: normalizeVitePluginSourceMap(result2.map, onDropSourceMap)
3519
+ };
3520
+ }
3521
+ return null;
3522
+ });
3523
+ });
3524
+ }
3525
+ const renderChunk = extractHandler(rollupPlugin.renderChunk);
3526
+ if (renderChunk) {
3527
+ build2.onRenderChunk({ filter: /.*/ }, (args) => {
3528
+ const result = renderChunk.call(context, args.code, args.chunk);
3529
+ return mapMaybePromise(result, (result2) => {
3530
+ if (result2 == null)
3531
+ return null;
3532
+ if (typeof result2 === "string")
3533
+ return { code: result2 };
3534
+ if (typeof result2 === "object" && "code" in result2) {
3535
+ return { code: result2.code };
3536
+ }
3537
+ return null;
3538
+ });
3539
+ });
3540
+ }
3541
+ const generateBundle = extractHandler(rollupPlugin.generateBundle);
3542
+ if (generateBundle) {
3543
+ build2.onGenerateBundle((outputs) => generateBundle.call(context, outputs));
3544
+ }
3545
+ const buildStart = extractHandler(rollupPlugin.buildStart);
3546
+ if (buildStart) {
3547
+ build2.onBuildStart(() => buildStart.call(context));
3548
+ }
3549
+ const buildEnd = extractHandler(rollupPlugin.buildEnd);
3550
+ if (buildEnd) {
3551
+ build2.onBuildEnd((err) => buildEnd.call(context, err));
3552
+ }
3553
+ const closeBundle = extractHandler(rollupPlugin.closeBundle);
3554
+ if (closeBundle) {
3555
+ build2.onCloseBundle(() => closeBundle.call(context));
3556
+ }
3557
+ }
3558
+ };
3559
+ }
3560
+ function watch(options) {
3561
+ const n = ensureNative();
3562
+ const { napiOptions: nativeOpts, cleanup } = prepareNapiOptions(options);
3563
+ const dispatcher = resolveDispatcher(options);
3564
+ if (dispatcher) {
3565
+ nativeOpts._pluginDispatcher = dispatcher;
3566
+ const dispatchCloseBundle = () => {
3567
+ dispatcher("closeBundle", undefined, null).catch(() => {});
3568
+ };
3569
+ const wrapWatchCallback = (callback) => (event) => {
3570
+ Promise.resolve().then(() => callback?.(event)).finally(dispatchCloseBundle).catch(() => {});
3571
+ };
3572
+ nativeOpts.onReady = wrapWatchCallback(options.onReady);
3573
+ nativeOpts.onRebuild = wrapWatchCallback(options.onRebuild);
3574
+ }
3575
+ let handle;
3576
+ try {
3577
+ handle = n.watch(nativeOpts);
3578
+ } catch (err) {
3579
+ cleanup();
3580
+ throw err;
3581
+ }
3582
+ return {
3583
+ stop() {
3584
+ try {
3585
+ handle.stop();
3586
+ } finally {
3587
+ cleanup();
3588
+ }
3589
+ },
3590
+ getBundleSourceMap() {
3591
+ return handle.getBundleSourceMap();
3592
+ },
3593
+ getHmrSourceMap(moduleId) {
3594
+ return handle.getHmrSourceMap(moduleId);
3595
+ }
3596
+ };
3597
+ }
3598
+ export {
3599
+ zntc,
3600
+ watch,
3601
+ warnUnknownKeys,
3602
+ vitePlugin,
3603
+ validateTsConfigRaw,
3604
+ transpile,
3605
+ tokenize,
3606
+ suggestKey,
3607
+ profileReport,
3608
+ prepareAppDevSync,
3609
+ mergeUserConfigs,
3610
+ loadWorkspace,
3611
+ loadModuleDefault,
3612
+ loadIdentifiedConfig,
3613
+ loadEnv,
3614
+ loadConfig,
3615
+ isPlainObject,
3616
+ init,
3617
+ importAndResolveDefault,
3618
+ identifyWorkspaceEntries,
3619
+ findWorkspacePath,
3620
+ findModeConfigPath,
3621
+ findConfigPath,
3622
+ filterWorkspaces,
3623
+ envToDefine,
3624
+ defineWorkspace,
3625
+ defineConfig,
3626
+ defaultConfigEnv,
3627
+ configureProfile,
3628
+ close,
3629
+ buildSync,
3630
+ buildAppSync,
3631
+ build,
3632
+ benchmark,
3633
+ WORKSPACE_EXT_PRIORITY,
3634
+ TsconfigCache,
3635
+ KNOWN_CONFIG_KEYS,
3636
+ BuildInstance
3637
+ };