@pictogrammers/element-esbuild 0.0.13 → 0.0.15

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.
@@ -1,2281 +1,15 @@
1
1
  #!/usr/bin/env node
2
2
  import { createRequire } from 'node:module'; const require = createRequire(import.meta.url);
3
-
4
- // scripts/element-start.ts
5
- import { context } from "esbuild";
6
-
7
- // node_modules/chokidar/index.js
8
- import { EventEmitter } from "node:events";
9
- import { stat as statcb, Stats } from "node:fs";
10
- import { readdir as readdir2, stat as stat3 } from "node:fs/promises";
11
- import * as sp2 from "node:path";
12
-
13
- // node_modules/readdirp/index.js
14
- import { lstat, readdir, realpath, stat } from "node:fs/promises";
15
- import { join as pjoin, relative as prelative, resolve as presolve, sep as psep } from "node:path";
16
- import { Readable } from "node:stream";
17
- var EntryTypes = {
18
- FILE_TYPE: "files",
19
- DIR_TYPE: "directories",
20
- FILE_DIR_TYPE: "files_directories",
21
- EVERYTHING_TYPE: "all"
22
- };
23
- var defaultOptions = {
24
- root: ".",
25
- fileFilter: (_entryInfo) => true,
26
- directoryFilter: (_entryInfo) => true,
27
- type: EntryTypes.FILE_TYPE,
28
- lstat: false,
29
- depth: 2147483648,
30
- alwaysStat: false,
31
- highWaterMark: 4096
32
- };
33
- Object.freeze(defaultOptions);
34
- var RECURSIVE_ERROR_CODE = "READDIRP_RECURSIVE_ERROR";
35
- var NORMAL_FLOW_ERRORS = /* @__PURE__ */ new Set(["ENOENT", "EPERM", "EACCES", "ELOOP", RECURSIVE_ERROR_CODE]);
36
- var ALL_TYPES = [
37
- EntryTypes.DIR_TYPE,
38
- EntryTypes.EVERYTHING_TYPE,
39
- EntryTypes.FILE_DIR_TYPE,
40
- EntryTypes.FILE_TYPE
41
- ];
42
- var DIR_TYPES = /* @__PURE__ */ new Set([
43
- EntryTypes.DIR_TYPE,
44
- EntryTypes.EVERYTHING_TYPE,
45
- EntryTypes.FILE_DIR_TYPE
46
- ]);
47
- var FILE_TYPES = /* @__PURE__ */ new Set([
48
- EntryTypes.EVERYTHING_TYPE,
49
- EntryTypes.FILE_DIR_TYPE,
50
- EntryTypes.FILE_TYPE
51
- ]);
52
- var isNormalFlowError = (error) => NORMAL_FLOW_ERRORS.has(error.code);
53
- var wantBigintFsStats = process.platform === "win32";
54
- var emptyFn = (_entryInfo) => true;
55
- var normalizeFilter = (filter) => {
56
- if (filter === void 0)
57
- return emptyFn;
58
- if (typeof filter === "function")
59
- return filter;
60
- if (typeof filter === "string") {
61
- const fl = filter.trim();
62
- return (entry) => entry.basename === fl;
63
- }
64
- if (Array.isArray(filter)) {
65
- const trItems = filter.map((item) => item.trim());
66
- return (entry) => trItems.some((f) => entry.basename === f);
67
- }
68
- return emptyFn;
69
- };
70
- var ReaddirpStream = class extends Readable {
71
- parents;
72
- reading;
73
- parent;
74
- _stat;
75
- _maxDepth;
76
- _wantsDir;
77
- _wantsFile;
78
- _wantsEverything;
79
- _root;
80
- _isDirent;
81
- _statsProp;
82
- _rdOptions;
83
- _fileFilter;
84
- _directoryFilter;
85
- constructor(options = {}) {
86
- super({
87
- objectMode: true,
88
- autoDestroy: true,
89
- highWaterMark: options.highWaterMark
90
- });
91
- const opts = { ...defaultOptions, ...options };
92
- const { root: root2, type } = opts;
93
- this._fileFilter = normalizeFilter(opts.fileFilter);
94
- this._directoryFilter = normalizeFilter(opts.directoryFilter);
95
- const statMethod = opts.lstat ? lstat : stat;
96
- if (wantBigintFsStats) {
97
- this._stat = (path) => statMethod(path, { bigint: true });
98
- } else {
99
- this._stat = statMethod;
100
- }
101
- this._maxDepth = opts.depth != null && Number.isSafeInteger(opts.depth) ? opts.depth : defaultOptions.depth;
102
- this._wantsDir = type ? DIR_TYPES.has(type) : false;
103
- this._wantsFile = type ? FILE_TYPES.has(type) : false;
104
- this._wantsEverything = type === EntryTypes.EVERYTHING_TYPE;
105
- this._root = presolve(root2);
106
- this._isDirent = !opts.alwaysStat;
107
- this._statsProp = this._isDirent ? "dirent" : "stats";
108
- this._rdOptions = { encoding: "utf8", withFileTypes: this._isDirent };
109
- this.parents = [this._exploreDir(root2, 1)];
110
- this.reading = false;
111
- this.parent = void 0;
112
- }
113
- async _read(batch) {
114
- if (this.reading)
115
- return;
116
- this.reading = true;
117
- try {
118
- while (!this.destroyed && batch > 0) {
119
- const par = this.parent;
120
- const fil = par && par.files;
121
- if (fil && fil.length > 0) {
122
- const { path, depth } = par;
123
- const slice = fil.splice(0, batch).map((dirent) => this._formatEntry(dirent, path));
124
- const awaited = await Promise.all(slice);
125
- for (const entry of awaited) {
126
- if (!entry)
127
- continue;
128
- if (this.destroyed)
129
- return;
130
- const entryType = await this._getEntryType(entry);
131
- if (entryType === "directory" && this._directoryFilter(entry)) {
132
- if (depth <= this._maxDepth) {
133
- this.parents.push(this._exploreDir(entry.fullPath, depth + 1));
134
- }
135
- if (this._wantsDir) {
136
- this.push(entry);
137
- batch--;
138
- }
139
- } else if ((entryType === "file" || this._includeAsFile(entry)) && this._fileFilter(entry)) {
140
- if (this._wantsFile) {
141
- this.push(entry);
142
- batch--;
143
- }
144
- }
145
- }
146
- } else {
147
- const parent = this.parents.pop();
148
- if (!parent) {
149
- this.push(null);
150
- break;
151
- }
152
- this.parent = await parent;
153
- if (this.destroyed)
154
- return;
155
- }
156
- }
157
- } catch (error) {
158
- this.destroy(error);
159
- } finally {
160
- this.reading = false;
161
- }
162
- }
163
- async _exploreDir(path, depth) {
164
- let files;
165
- try {
166
- files = await readdir(path, this._rdOptions);
167
- } catch (error) {
168
- this._onError(error);
169
- }
170
- return { files, depth, path };
171
- }
172
- async _formatEntry(dirent, path) {
173
- let entry;
174
- const basename3 = this._isDirent ? dirent.name : dirent;
175
- try {
176
- const fullPath = presolve(pjoin(path, basename3));
177
- entry = { path: prelative(this._root, fullPath), fullPath, basename: basename3 };
178
- entry[this._statsProp] = this._isDirent ? dirent : await this._stat(fullPath);
179
- } catch (err) {
180
- this._onError(err);
181
- return;
182
- }
183
- return entry;
184
- }
185
- _onError(err) {
186
- if (isNormalFlowError(err) && !this.destroyed) {
187
- this.emit("warn", err);
188
- } else {
189
- this.destroy(err);
190
- }
191
- }
192
- async _getEntryType(entry) {
193
- if (!entry && this._statsProp in entry) {
194
- return "";
195
- }
196
- const stats = entry[this._statsProp];
197
- if (stats.isFile())
198
- return "file";
199
- if (stats.isDirectory())
200
- return "directory";
201
- if (stats && stats.isSymbolicLink()) {
202
- const full = entry.fullPath;
203
- try {
204
- const entryRealPath = await realpath(full);
205
- const entryRealPathStats = await lstat(entryRealPath);
206
- if (entryRealPathStats.isFile()) {
207
- return "file";
208
- }
209
- if (entryRealPathStats.isDirectory()) {
210
- const len = entryRealPath.length;
211
- if (full.startsWith(entryRealPath) && full.substr(len, 1) === psep) {
212
- const recursiveError = new Error(`Circular symlink detected: "${full}" points to "${entryRealPath}"`);
213
- recursiveError.code = RECURSIVE_ERROR_CODE;
214
- return this._onError(recursiveError);
215
- }
216
- return "directory";
217
- }
218
- } catch (error) {
219
- this._onError(error);
220
- return "";
221
- }
222
- }
223
- }
224
- _includeAsFile(entry) {
225
- const stats = entry && entry[this._statsProp];
226
- return stats && this._wantsEverything && !stats.isDirectory();
227
- }
228
- };
229
- function readdirp(root2, options = {}) {
230
- let type = options.entryType || options.type;
231
- if (type === "both")
232
- type = EntryTypes.FILE_DIR_TYPE;
233
- if (type)
234
- options.type = type;
235
- if (!root2) {
236
- throw new Error("readdirp: root argument is required. Usage: readdirp(root, options)");
237
- } else if (typeof root2 !== "string") {
238
- throw new TypeError("readdirp: root argument must be a string. Usage: readdirp(root, options)");
239
- } else if (type && !ALL_TYPES.includes(type)) {
240
- throw new Error(`readdirp: Invalid type passed. Use one of ${ALL_TYPES.join(", ")}`);
241
- }
242
- options.root = root2;
243
- return new ReaddirpStream(options);
244
- }
245
-
246
- // node_modules/chokidar/handler.js
247
- import { watch as fs_watch, unwatchFile, watchFile } from "node:fs";
248
- import { realpath as fsrealpath, lstat as lstat2, open, stat as stat2 } from "node:fs/promises";
249
- import { type as osType } from "node:os";
250
- import * as sp from "node:path";
251
- var STR_DATA = "data";
252
- var STR_END = "end";
253
- var STR_CLOSE = "close";
254
- var EMPTY_FN = () => {
255
- };
256
- var pl = process.platform;
257
- var isWindows = pl === "win32";
258
- var isMacos = pl === "darwin";
259
- var isLinux = pl === "linux";
260
- var isFreeBSD = pl === "freebsd";
261
- var isIBMi = osType() === "OS400";
262
- var EVENTS = {
263
- ALL: "all",
264
- READY: "ready",
265
- ADD: "add",
266
- CHANGE: "change",
267
- ADD_DIR: "addDir",
268
- UNLINK: "unlink",
269
- UNLINK_DIR: "unlinkDir",
270
- RAW: "raw",
271
- ERROR: "error"
272
- };
273
- var EV = EVENTS;
274
- var THROTTLE_MODE_WATCH = "watch";
275
- var statMethods = { lstat: lstat2, stat: stat2 };
276
- var KEY_LISTENERS = "listeners";
277
- var KEY_ERR = "errHandlers";
278
- var KEY_RAW = "rawEmitters";
279
- var HANDLER_KEYS = [KEY_LISTENERS, KEY_ERR, KEY_RAW];
280
- var binaryExtensions = /* @__PURE__ */ new Set([
281
- "3dm",
282
- "3ds",
283
- "3g2",
284
- "3gp",
285
- "7z",
286
- "a",
287
- "aac",
288
- "adp",
289
- "afdesign",
290
- "afphoto",
291
- "afpub",
292
- "ai",
293
- "aif",
294
- "aiff",
295
- "alz",
296
- "ape",
297
- "apk",
298
- "appimage",
299
- "ar",
300
- "arj",
301
- "asf",
302
- "au",
303
- "avi",
304
- "bak",
305
- "baml",
306
- "bh",
307
- "bin",
308
- "bk",
309
- "bmp",
310
- "btif",
311
- "bz2",
312
- "bzip2",
313
- "cab",
314
- "caf",
315
- "cgm",
316
- "class",
317
- "cmx",
318
- "cpio",
319
- "cr2",
320
- "cur",
321
- "dat",
322
- "dcm",
323
- "deb",
324
- "dex",
325
- "djvu",
326
- "dll",
327
- "dmg",
328
- "dng",
329
- "doc",
330
- "docm",
331
- "docx",
332
- "dot",
333
- "dotm",
334
- "dra",
335
- "DS_Store",
336
- "dsk",
337
- "dts",
338
- "dtshd",
339
- "dvb",
340
- "dwg",
341
- "dxf",
342
- "ecelp4800",
343
- "ecelp7470",
344
- "ecelp9600",
345
- "egg",
346
- "eol",
347
- "eot",
348
- "epub",
349
- "exe",
350
- "f4v",
351
- "fbs",
352
- "fh",
353
- "fla",
354
- "flac",
355
- "flatpak",
356
- "fli",
357
- "flv",
358
- "fpx",
359
- "fst",
360
- "fvt",
361
- "g3",
362
- "gh",
363
- "gif",
364
- "graffle",
365
- "gz",
366
- "gzip",
367
- "h261",
368
- "h263",
369
- "h264",
370
- "icns",
371
- "ico",
372
- "ief",
373
- "img",
374
- "ipa",
375
- "iso",
376
- "jar",
377
- "jpeg",
378
- "jpg",
379
- "jpgv",
380
- "jpm",
381
- "jxr",
382
- "key",
383
- "ktx",
384
- "lha",
385
- "lib",
386
- "lvp",
387
- "lz",
388
- "lzh",
389
- "lzma",
390
- "lzo",
391
- "m3u",
392
- "m4a",
393
- "m4v",
394
- "mar",
395
- "mdi",
396
- "mht",
397
- "mid",
398
- "midi",
399
- "mj2",
400
- "mka",
401
- "mkv",
402
- "mmr",
403
- "mng",
404
- "mobi",
405
- "mov",
406
- "movie",
407
- "mp3",
408
- "mp4",
409
- "mp4a",
410
- "mpeg",
411
- "mpg",
412
- "mpga",
413
- "mxu",
414
- "nef",
415
- "npx",
416
- "numbers",
417
- "nupkg",
418
- "o",
419
- "odp",
420
- "ods",
421
- "odt",
422
- "oga",
423
- "ogg",
424
- "ogv",
425
- "otf",
426
- "ott",
427
- "pages",
428
- "pbm",
429
- "pcx",
430
- "pdb",
431
- "pdf",
432
- "pea",
433
- "pgm",
434
- "pic",
435
- "png",
436
- "pnm",
437
- "pot",
438
- "potm",
439
- "potx",
440
- "ppa",
441
- "ppam",
442
- "ppm",
443
- "pps",
444
- "ppsm",
445
- "ppsx",
446
- "ppt",
447
- "pptm",
448
- "pptx",
449
- "psd",
450
- "pya",
451
- "pyc",
452
- "pyo",
453
- "pyv",
454
- "qt",
455
- "rar",
456
- "ras",
457
- "raw",
458
- "resources",
459
- "rgb",
460
- "rip",
461
- "rlc",
462
- "rmf",
463
- "rmvb",
464
- "rpm",
465
- "rtf",
466
- "rz",
467
- "s3m",
468
- "s7z",
469
- "scpt",
470
- "sgi",
471
- "shar",
472
- "snap",
473
- "sil",
474
- "sketch",
475
- "slk",
476
- "smv",
477
- "snk",
478
- "so",
479
- "stl",
480
- "suo",
481
- "sub",
482
- "swf",
483
- "tar",
484
- "tbz",
485
- "tbz2",
486
- "tga",
487
- "tgz",
488
- "thmx",
489
- "tif",
490
- "tiff",
491
- "tlz",
492
- "ttc",
493
- "ttf",
494
- "txz",
495
- "udf",
496
- "uvh",
497
- "uvi",
498
- "uvm",
499
- "uvp",
500
- "uvs",
501
- "uvu",
502
- "viv",
503
- "vob",
504
- "war",
505
- "wav",
506
- "wax",
507
- "wbmp",
508
- "wdp",
509
- "weba",
510
- "webm",
511
- "webp",
512
- "whl",
513
- "wim",
514
- "wm",
515
- "wma",
516
- "wmv",
517
- "wmx",
518
- "woff",
519
- "woff2",
520
- "wrm",
521
- "wvx",
522
- "xbm",
523
- "xif",
524
- "xla",
525
- "xlam",
526
- "xls",
527
- "xlsb",
528
- "xlsm",
529
- "xlsx",
530
- "xlt",
531
- "xltm",
532
- "xltx",
533
- "xm",
534
- "xmind",
535
- "xpi",
536
- "xpm",
537
- "xwd",
538
- "xz",
539
- "z",
540
- "zip",
541
- "zipx"
542
- ]);
543
- var isBinaryPath = (filePath) => binaryExtensions.has(sp.extname(filePath).slice(1).toLowerCase());
544
- var foreach = (val, fn) => {
545
- if (val instanceof Set) {
546
- val.forEach(fn);
547
- } else {
548
- fn(val);
549
- }
550
- };
551
- var addAndConvert = (main, prop, item) => {
552
- let container = main[prop];
553
- if (!(container instanceof Set)) {
554
- main[prop] = container = /* @__PURE__ */ new Set([container]);
555
- }
556
- container.add(item);
557
- };
558
- var clearItem = (cont) => (key) => {
559
- const set = cont[key];
560
- if (set instanceof Set) {
561
- set.clear();
562
- } else {
563
- delete cont[key];
564
- }
565
- };
566
- var delFromSet = (main, prop, item) => {
567
- const container = main[prop];
568
- if (container instanceof Set) {
569
- container.delete(item);
570
- } else if (container === item) {
571
- delete main[prop];
572
- }
573
- };
574
- var isEmptySet = (val) => val instanceof Set ? val.size === 0 : !val;
575
- var FsWatchInstances = /* @__PURE__ */ new Map();
576
- function createFsWatchInstance(path, options, listener, errHandler, emitRaw) {
577
- const handleEvent = (rawEvent, evPath) => {
578
- listener(path);
579
- emitRaw(rawEvent, evPath, { watchedPath: path });
580
- if (evPath && path !== evPath) {
581
- fsWatchBroadcast(sp.resolve(path, evPath), KEY_LISTENERS, sp.join(path, evPath));
582
- }
583
- };
584
- try {
585
- return fs_watch(path, {
586
- persistent: options.persistent
587
- }, handleEvent);
588
- } catch (error) {
589
- errHandler(error);
590
- return void 0;
591
- }
592
- }
593
- var fsWatchBroadcast = (fullPath, listenerType, val1, val2, val3) => {
594
- const cont = FsWatchInstances.get(fullPath);
595
- if (!cont)
596
- return;
597
- foreach(cont[listenerType], (listener) => {
598
- listener(val1, val2, val3);
599
- });
600
- };
601
- var setFsWatchListener = (path, fullPath, options, handlers) => {
602
- const { listener, errHandler, rawEmitter } = handlers;
603
- let cont = FsWatchInstances.get(fullPath);
604
- let watcher;
605
- if (!options.persistent) {
606
- watcher = createFsWatchInstance(path, options, listener, errHandler, rawEmitter);
607
- if (!watcher)
608
- return;
609
- return watcher.close.bind(watcher);
610
- }
611
- if (cont) {
612
- addAndConvert(cont, KEY_LISTENERS, listener);
613
- addAndConvert(cont, KEY_ERR, errHandler);
614
- addAndConvert(cont, KEY_RAW, rawEmitter);
615
- } else {
616
- watcher = createFsWatchInstance(
617
- path,
618
- options,
619
- fsWatchBroadcast.bind(null, fullPath, KEY_LISTENERS),
620
- errHandler,
621
- // no need to use broadcast here
622
- fsWatchBroadcast.bind(null, fullPath, KEY_RAW)
623
- );
624
- if (!watcher)
625
- return;
626
- watcher.on(EV.ERROR, async (error) => {
627
- const broadcastErr = fsWatchBroadcast.bind(null, fullPath, KEY_ERR);
628
- if (cont)
629
- cont.watcherUnusable = true;
630
- if (isWindows && error.code === "EPERM") {
631
- try {
632
- const fd = await open(path, "r");
633
- await fd.close();
634
- broadcastErr(error);
635
- } catch (err) {
636
- }
637
- } else {
638
- broadcastErr(error);
639
- }
640
- });
641
- cont = {
642
- listeners: listener,
643
- errHandlers: errHandler,
644
- rawEmitters: rawEmitter,
645
- watcher
646
- };
647
- FsWatchInstances.set(fullPath, cont);
648
- }
649
- return () => {
650
- delFromSet(cont, KEY_LISTENERS, listener);
651
- delFromSet(cont, KEY_ERR, errHandler);
652
- delFromSet(cont, KEY_RAW, rawEmitter);
653
- if (isEmptySet(cont.listeners)) {
654
- cont.watcher.close();
655
- FsWatchInstances.delete(fullPath);
656
- HANDLER_KEYS.forEach(clearItem(cont));
657
- cont.watcher = void 0;
658
- Object.freeze(cont);
659
- }
660
- };
661
- };
662
- var FsWatchFileInstances = /* @__PURE__ */ new Map();
663
- var setFsWatchFileListener = (path, fullPath, options, handlers) => {
664
- const { listener, rawEmitter } = handlers;
665
- let cont = FsWatchFileInstances.get(fullPath);
666
- const copts = cont && cont.options;
667
- if (copts && (copts.persistent < options.persistent || copts.interval > options.interval)) {
668
- unwatchFile(fullPath);
669
- cont = void 0;
670
- }
671
- if (cont) {
672
- addAndConvert(cont, KEY_LISTENERS, listener);
673
- addAndConvert(cont, KEY_RAW, rawEmitter);
674
- } else {
675
- cont = {
676
- listeners: listener,
677
- rawEmitters: rawEmitter,
678
- options,
679
- watcher: watchFile(fullPath, options, (curr, prev) => {
680
- foreach(cont.rawEmitters, (rawEmitter2) => {
681
- rawEmitter2(EV.CHANGE, fullPath, { curr, prev });
682
- });
683
- const currmtime = curr.mtimeMs;
684
- if (curr.size !== prev.size || currmtime > prev.mtimeMs || currmtime === 0) {
685
- foreach(cont.listeners, (listener2) => listener2(path, curr));
686
- }
687
- })
688
- };
689
- FsWatchFileInstances.set(fullPath, cont);
690
- }
691
- return () => {
692
- delFromSet(cont, KEY_LISTENERS, listener);
693
- delFromSet(cont, KEY_RAW, rawEmitter);
694
- if (isEmptySet(cont.listeners)) {
695
- FsWatchFileInstances.delete(fullPath);
696
- unwatchFile(fullPath);
697
- cont.options = cont.watcher = void 0;
698
- Object.freeze(cont);
699
- }
700
- };
701
- };
702
- var NodeFsHandler = class {
703
- fsw;
704
- _boundHandleError;
705
- constructor(fsW) {
706
- this.fsw = fsW;
707
- this._boundHandleError = (error) => fsW._handleError(error);
708
- }
709
- /**
710
- * Watch file for changes with fs_watchFile or fs_watch.
711
- * @param path to file or dir
712
- * @param listener on fs change
713
- * @returns closer for the watcher instance
714
- */
715
- _watchWithNodeFs(path, listener) {
716
- const opts = this.fsw.options;
717
- const directory = sp.dirname(path);
718
- const basename3 = sp.basename(path);
719
- const parent = this.fsw._getWatchedDir(directory);
720
- parent.add(basename3);
721
- const absolutePath = sp.resolve(path);
722
- const options = {
723
- persistent: opts.persistent
724
- };
725
- if (!listener)
726
- listener = EMPTY_FN;
727
- let closer;
728
- if (opts.usePolling) {
729
- const enableBin = opts.interval !== opts.binaryInterval;
730
- options.interval = enableBin && isBinaryPath(basename3) ? opts.binaryInterval : opts.interval;
731
- closer = setFsWatchFileListener(path, absolutePath, options, {
732
- listener,
733
- rawEmitter: this.fsw._emitRaw
734
- });
735
- } else {
736
- closer = setFsWatchListener(path, absolutePath, options, {
737
- listener,
738
- errHandler: this._boundHandleError,
739
- rawEmitter: this.fsw._emitRaw
740
- });
741
- }
742
- return closer;
743
- }
744
- /**
745
- * Watch a file and emit add event if warranted.
746
- * @returns closer for the watcher instance
747
- */
748
- _handleFile(file, stats, initialAdd) {
749
- if (this.fsw.closed) {
750
- return;
751
- }
752
- const dirname5 = sp.dirname(file);
753
- const basename3 = sp.basename(file);
754
- const parent = this.fsw._getWatchedDir(dirname5);
755
- let prevStats = stats;
756
- if (parent.has(basename3))
757
- return;
758
- const listener = async (path, newStats) => {
759
- if (!this.fsw._throttle(THROTTLE_MODE_WATCH, file, 5))
760
- return;
761
- if (!newStats || newStats.mtimeMs === 0) {
762
- try {
763
- const newStats2 = await stat2(file);
764
- if (this.fsw.closed)
765
- return;
766
- const at = newStats2.atimeMs;
767
- const mt = newStats2.mtimeMs;
768
- if (!at || at <= mt || mt !== prevStats.mtimeMs) {
769
- this.fsw._emit(EV.CHANGE, file, newStats2);
770
- }
771
- if ((isMacos || isLinux || isFreeBSD) && prevStats.ino !== newStats2.ino) {
772
- this.fsw._closeFile(path);
773
- prevStats = newStats2;
774
- const closer2 = this._watchWithNodeFs(file, listener);
775
- if (closer2)
776
- this.fsw._addPathCloser(path, closer2);
777
- } else {
778
- prevStats = newStats2;
779
- }
780
- } catch (error) {
781
- this.fsw._remove(dirname5, basename3);
782
- }
783
- } else if (parent.has(basename3)) {
784
- const at = newStats.atimeMs;
785
- const mt = newStats.mtimeMs;
786
- if (!at || at <= mt || mt !== prevStats.mtimeMs) {
787
- this.fsw._emit(EV.CHANGE, file, newStats);
788
- }
789
- prevStats = newStats;
790
- }
791
- };
792
- const closer = this._watchWithNodeFs(file, listener);
793
- if (!(initialAdd && this.fsw.options.ignoreInitial) && this.fsw._isntIgnored(file)) {
794
- if (!this.fsw._throttle(EV.ADD, file, 0))
795
- return;
796
- this.fsw._emit(EV.ADD, file, stats);
797
- }
798
- return closer;
799
- }
800
- /**
801
- * Handle symlinks encountered while reading a dir.
802
- * @param entry returned by readdirp
803
- * @param directory path of dir being read
804
- * @param path of this item
805
- * @param item basename of this item
806
- * @returns true if no more processing is needed for this entry.
807
- */
808
- async _handleSymlink(entry, directory, path, item) {
809
- if (this.fsw.closed) {
810
- return;
811
- }
812
- const full = entry.fullPath;
813
- const dir = this.fsw._getWatchedDir(directory);
814
- if (!this.fsw.options.followSymlinks) {
815
- this.fsw._incrReadyCount();
816
- let linkPath;
817
- try {
818
- linkPath = await fsrealpath(path);
819
- } catch (e) {
820
- this.fsw._emitReady();
821
- return true;
822
- }
823
- if (this.fsw.closed)
824
- return;
825
- if (dir.has(item)) {
826
- if (this.fsw._symlinkPaths.get(full) !== linkPath) {
827
- this.fsw._symlinkPaths.set(full, linkPath);
828
- this.fsw._emit(EV.CHANGE, path, entry.stats);
829
- }
830
- } else {
831
- dir.add(item);
832
- this.fsw._symlinkPaths.set(full, linkPath);
833
- this.fsw._emit(EV.ADD, path, entry.stats);
834
- }
835
- this.fsw._emitReady();
836
- return true;
837
- }
838
- if (this.fsw._symlinkPaths.has(full)) {
839
- return true;
840
- }
841
- this.fsw._symlinkPaths.set(full, true);
842
- }
843
- _handleRead(directory, initialAdd, wh, target, dir, depth, throttler) {
844
- directory = sp.join(directory, "");
845
- const throttleKey = target ? `${directory}:${target}` : directory;
846
- throttler = this.fsw._throttle("readdir", throttleKey, 1e3);
847
- if (!throttler)
848
- return;
849
- const previous = this.fsw._getWatchedDir(wh.path);
850
- const current = /* @__PURE__ */ new Set();
851
- let stream = this.fsw._readdirp(directory, {
852
- fileFilter: (entry) => wh.filterPath(entry),
853
- directoryFilter: (entry) => wh.filterDir(entry)
854
- });
855
- if (!stream)
856
- return;
857
- stream.on(STR_DATA, async (entry) => {
858
- if (this.fsw.closed) {
859
- stream = void 0;
860
- return;
861
- }
862
- const item = entry.path;
863
- let path = sp.join(directory, item);
864
- current.add(item);
865
- if (entry.stats.isSymbolicLink() && await this._handleSymlink(entry, directory, path, item)) {
866
- return;
867
- }
868
- if (this.fsw.closed) {
869
- stream = void 0;
870
- return;
871
- }
872
- if (item === target || !target && !previous.has(item)) {
873
- this.fsw._incrReadyCount();
874
- path = sp.join(dir, sp.relative(dir, path));
875
- this._addToNodeFs(path, initialAdd, wh, depth + 1);
876
- }
877
- }).on(EV.ERROR, this._boundHandleError);
878
- return new Promise((resolve3, reject) => {
879
- if (!stream)
880
- return reject();
881
- stream.once(STR_END, () => {
882
- if (this.fsw.closed) {
883
- stream = void 0;
884
- return;
885
- }
886
- const wasThrottled = throttler ? throttler.clear() : false;
887
- resolve3(void 0);
888
- previous.getChildren().filter((item) => {
889
- return item !== directory && !current.has(item);
890
- }).forEach((item) => {
891
- this.fsw._remove(directory, item);
892
- });
893
- stream = void 0;
894
- if (wasThrottled)
895
- this._handleRead(directory, false, wh, target, dir, depth, throttler);
896
- });
897
- });
898
- }
899
- /**
900
- * Read directory to add / remove files from `@watched` list and re-read it on change.
901
- * @param dir fs path
902
- * @param stats
903
- * @param initialAdd
904
- * @param depth relative to user-supplied path
905
- * @param target child path targeted for watch
906
- * @param wh Common watch helpers for this path
907
- * @param realpath
908
- * @returns closer for the watcher instance.
909
- */
910
- async _handleDir(dir, stats, initialAdd, depth, target, wh, realpath2) {
911
- const parentDir = this.fsw._getWatchedDir(sp.dirname(dir));
912
- const tracked = parentDir.has(sp.basename(dir));
913
- if (!(initialAdd && this.fsw.options.ignoreInitial) && !target && !tracked) {
914
- this.fsw._emit(EV.ADD_DIR, dir, stats);
915
- }
916
- parentDir.add(sp.basename(dir));
917
- this.fsw._getWatchedDir(dir);
918
- let throttler;
919
- let closer;
920
- const oDepth = this.fsw.options.depth;
921
- if ((oDepth == null || depth <= oDepth) && !this.fsw._symlinkPaths.has(realpath2)) {
922
- if (!target) {
923
- await this._handleRead(dir, initialAdd, wh, target, dir, depth, throttler);
924
- if (this.fsw.closed)
925
- return;
926
- }
927
- closer = this._watchWithNodeFs(dir, (dirPath, stats2) => {
928
- if (stats2 && stats2.mtimeMs === 0)
929
- return;
930
- this._handleRead(dirPath, false, wh, target, dir, depth, throttler);
931
- });
932
- }
933
- return closer;
934
- }
935
- /**
936
- * Handle added file, directory, or glob pattern.
937
- * Delegates call to _handleFile / _handleDir after checks.
938
- * @param path to file or ir
939
- * @param initialAdd was the file added at watch instantiation?
940
- * @param priorWh depth relative to user-supplied path
941
- * @param depth Child path actually targeted for watch
942
- * @param target Child path actually targeted for watch
943
- */
944
- async _addToNodeFs(path, initialAdd, priorWh, depth, target) {
945
- const ready = this.fsw._emitReady;
946
- if (this.fsw._isIgnored(path) || this.fsw.closed) {
947
- ready();
948
- return false;
949
- }
950
- const wh = this.fsw._getWatchHelpers(path);
951
- if (priorWh) {
952
- wh.filterPath = (entry) => priorWh.filterPath(entry);
953
- wh.filterDir = (entry) => priorWh.filterDir(entry);
954
- }
955
- try {
956
- const stats = await statMethods[wh.statMethod](wh.watchPath);
957
- if (this.fsw.closed)
958
- return;
959
- if (this.fsw._isIgnored(wh.watchPath, stats)) {
960
- ready();
961
- return false;
962
- }
963
- const follow = this.fsw.options.followSymlinks;
964
- let closer;
965
- if (stats.isDirectory()) {
966
- const absPath = sp.resolve(path);
967
- const targetPath = follow ? await fsrealpath(path) : path;
968
- if (this.fsw.closed)
969
- return;
970
- closer = await this._handleDir(wh.watchPath, stats, initialAdd, depth, target, wh, targetPath);
971
- if (this.fsw.closed)
972
- return;
973
- if (absPath !== targetPath && targetPath !== void 0) {
974
- this.fsw._symlinkPaths.set(absPath, targetPath);
975
- }
976
- } else if (stats.isSymbolicLink()) {
977
- const targetPath = follow ? await fsrealpath(path) : path;
978
- if (this.fsw.closed)
979
- return;
980
- const parent = sp.dirname(wh.watchPath);
981
- this.fsw._getWatchedDir(parent).add(wh.watchPath);
982
- this.fsw._emit(EV.ADD, wh.watchPath, stats);
983
- closer = await this._handleDir(parent, stats, initialAdd, depth, path, wh, targetPath);
984
- if (this.fsw.closed)
985
- return;
986
- if (targetPath !== void 0) {
987
- this.fsw._symlinkPaths.set(sp.resolve(path), targetPath);
988
- }
989
- } else {
990
- closer = this._handleFile(wh.watchPath, stats, initialAdd);
991
- }
992
- ready();
993
- if (closer)
994
- this.fsw._addPathCloser(path, closer);
995
- return false;
996
- } catch (error) {
997
- if (this.fsw._handleError(error)) {
998
- ready();
999
- return path;
1000
- }
1001
- }
1002
- }
1003
- };
1004
-
1005
- // node_modules/chokidar/index.js
1006
- var SLASH = "/";
1007
- var SLASH_SLASH = "//";
1008
- var ONE_DOT = ".";
1009
- var TWO_DOTS = "..";
1010
- var STRING_TYPE = "string";
1011
- var BACK_SLASH_RE = /\\/g;
1012
- var DOUBLE_SLASH_RE = /\/\//g;
1013
- var DOT_RE = /\..*\.(sw[px])$|~$|\.subl.*\.tmp/;
1014
- var REPLACER_RE = /^\.[/\\]/;
1015
- function arrify(item) {
1016
- return Array.isArray(item) ? item : [item];
1017
- }
1018
- var isMatcherObject = (matcher) => typeof matcher === "object" && matcher !== null && !(matcher instanceof RegExp);
1019
- function createPattern(matcher) {
1020
- if (typeof matcher === "function")
1021
- return matcher;
1022
- if (typeof matcher === "string")
1023
- return (string) => matcher === string;
1024
- if (matcher instanceof RegExp)
1025
- return (string) => matcher.test(string);
1026
- if (typeof matcher === "object" && matcher !== null) {
1027
- return (string) => {
1028
- if (matcher.path === string)
1029
- return true;
1030
- if (matcher.recursive) {
1031
- const relative3 = sp2.relative(matcher.path, string);
1032
- if (!relative3) {
1033
- return false;
1034
- }
1035
- return !relative3.startsWith("..") && !sp2.isAbsolute(relative3);
1036
- }
1037
- return false;
1038
- };
1039
- }
1040
- return () => false;
1041
- }
1042
- function normalizePath(path) {
1043
- if (typeof path !== "string")
1044
- throw new Error("string expected");
1045
- path = sp2.normalize(path);
1046
- path = path.replace(/\\/g, "/");
1047
- let prepend = false;
1048
- if (path.startsWith("//"))
1049
- prepend = true;
1050
- path = path.replace(DOUBLE_SLASH_RE, "/");
1051
- if (prepend)
1052
- path = "/" + path;
1053
- return path;
1054
- }
1055
- function matchPatterns(patterns, testString, stats) {
1056
- const path = normalizePath(testString);
1057
- for (let index = 0; index < patterns.length; index++) {
1058
- const pattern = patterns[index];
1059
- if (pattern(path, stats)) {
1060
- return true;
1061
- }
1062
- }
1063
- return false;
1064
- }
1065
- function anymatch(matchers, testString) {
1066
- if (matchers == null) {
1067
- throw new TypeError("anymatch: specify first argument");
1068
- }
1069
- const matchersArray = arrify(matchers);
1070
- const patterns = matchersArray.map((matcher) => createPattern(matcher));
1071
- if (testString == null) {
1072
- return (testString2, stats) => {
1073
- return matchPatterns(patterns, testString2, stats);
1074
- };
1075
- }
1076
- return matchPatterns(patterns, testString);
1077
- }
1078
- var unifyPaths = (paths_) => {
1079
- const paths = arrify(paths_).flat();
1080
- if (!paths.every((p) => typeof p === STRING_TYPE)) {
1081
- throw new TypeError(`Non-string provided as watch path: ${paths}`);
1082
- }
1083
- return paths.map(normalizePathToUnix);
1084
- };
1085
- var toUnix = (string) => {
1086
- let str = string.replace(BACK_SLASH_RE, SLASH);
1087
- let prepend = false;
1088
- if (str.startsWith(SLASH_SLASH)) {
1089
- prepend = true;
1090
- }
1091
- str = str.replace(DOUBLE_SLASH_RE, SLASH);
1092
- if (prepend) {
1093
- str = SLASH + str;
1094
- }
1095
- return str;
1096
- };
1097
- var normalizePathToUnix = (path) => toUnix(sp2.normalize(toUnix(path)));
1098
- var normalizeIgnored = (cwd = "") => (path) => {
1099
- if (typeof path === "string") {
1100
- return normalizePathToUnix(sp2.isAbsolute(path) ? path : sp2.join(cwd, path));
1101
- } else {
1102
- return path;
1103
- }
1104
- };
1105
- var getAbsolutePath = (path, cwd) => {
1106
- if (sp2.isAbsolute(path)) {
1107
- return path;
1108
- }
1109
- return sp2.join(cwd, path);
1110
- };
1111
- var EMPTY_SET = Object.freeze(/* @__PURE__ */ new Set());
1112
- var DirEntry = class {
1113
- path;
1114
- _removeWatcher;
1115
- items;
1116
- constructor(dir, removeWatcher) {
1117
- this.path = dir;
1118
- this._removeWatcher = removeWatcher;
1119
- this.items = /* @__PURE__ */ new Set();
1120
- }
1121
- add(item) {
1122
- const { items } = this;
1123
- if (!items)
1124
- return;
1125
- if (item !== ONE_DOT && item !== TWO_DOTS)
1126
- items.add(item);
1127
- }
1128
- async remove(item) {
1129
- const { items } = this;
1130
- if (!items)
1131
- return;
1132
- items.delete(item);
1133
- if (items.size > 0)
1134
- return;
1135
- const dir = this.path;
1136
- try {
1137
- await readdir2(dir);
1138
- } catch (err) {
1139
- if (this._removeWatcher) {
1140
- this._removeWatcher(sp2.dirname(dir), sp2.basename(dir));
1141
- }
1142
- }
1143
- }
1144
- has(item) {
1145
- const { items } = this;
1146
- if (!items)
1147
- return;
1148
- return items.has(item);
1149
- }
1150
- getChildren() {
1151
- const { items } = this;
1152
- if (!items)
1153
- return [];
1154
- return [...items.values()];
1155
- }
1156
- dispose() {
1157
- this.items.clear();
1158
- this.path = "";
1159
- this._removeWatcher = EMPTY_FN;
1160
- this.items = EMPTY_SET;
1161
- Object.freeze(this);
1162
- }
1163
- };
1164
- var STAT_METHOD_F = "stat";
1165
- var STAT_METHOD_L = "lstat";
1166
- var WatchHelper = class {
1167
- fsw;
1168
- path;
1169
- watchPath;
1170
- fullWatchPath;
1171
- dirParts;
1172
- followSymlinks;
1173
- statMethod;
1174
- constructor(path, follow, fsw) {
1175
- this.fsw = fsw;
1176
- const watchPath = path;
1177
- this.path = path = path.replace(REPLACER_RE, "");
1178
- this.watchPath = watchPath;
1179
- this.fullWatchPath = sp2.resolve(watchPath);
1180
- this.dirParts = [];
1181
- this.dirParts.forEach((parts) => {
1182
- if (parts.length > 1)
1183
- parts.pop();
1184
- });
1185
- this.followSymlinks = follow;
1186
- this.statMethod = follow ? STAT_METHOD_F : STAT_METHOD_L;
1187
- }
1188
- entryPath(entry) {
1189
- return sp2.join(this.watchPath, sp2.relative(this.watchPath, entry.fullPath));
1190
- }
1191
- filterPath(entry) {
1192
- const { stats } = entry;
1193
- if (stats && stats.isSymbolicLink())
1194
- return this.filterDir(entry);
1195
- const resolvedPath = this.entryPath(entry);
1196
- return this.fsw._isntIgnored(resolvedPath, stats) && this.fsw._hasReadPermissions(stats);
1197
- }
1198
- filterDir(entry) {
1199
- return this.fsw._isntIgnored(this.entryPath(entry), entry.stats);
1200
- }
1201
- };
1202
- var FSWatcher = class extends EventEmitter {
1203
- closed;
1204
- options;
1205
- _closers;
1206
- _ignoredPaths;
1207
- _throttled;
1208
- _streams;
1209
- _symlinkPaths;
1210
- _watched;
1211
- _pendingWrites;
1212
- _pendingUnlinks;
1213
- _readyCount;
1214
- _emitReady;
1215
- _closePromise;
1216
- _userIgnored;
1217
- _readyEmitted;
1218
- _emitRaw;
1219
- _boundRemove;
1220
- _nodeFsHandler;
1221
- // Not indenting methods for history sake; for now.
1222
- constructor(_opts = {}) {
1223
- super();
1224
- this.closed = false;
1225
- this._closers = /* @__PURE__ */ new Map();
1226
- this._ignoredPaths = /* @__PURE__ */ new Set();
1227
- this._throttled = /* @__PURE__ */ new Map();
1228
- this._streams = /* @__PURE__ */ new Set();
1229
- this._symlinkPaths = /* @__PURE__ */ new Map();
1230
- this._watched = /* @__PURE__ */ new Map();
1231
- this._pendingWrites = /* @__PURE__ */ new Map();
1232
- this._pendingUnlinks = /* @__PURE__ */ new Map();
1233
- this._readyCount = 0;
1234
- this._readyEmitted = false;
1235
- const awf = _opts.awaitWriteFinish;
1236
- const DEF_AWF = { stabilityThreshold: 2e3, pollInterval: 100 };
1237
- const opts = {
1238
- // Defaults
1239
- persistent: true,
1240
- ignoreInitial: false,
1241
- ignorePermissionErrors: false,
1242
- interval: 100,
1243
- binaryInterval: 300,
1244
- followSymlinks: true,
1245
- usePolling: false,
1246
- // useAsync: false,
1247
- atomic: true,
1248
- // NOTE: overwritten later (depends on usePolling)
1249
- ..._opts,
1250
- // Change format
1251
- ignored: _opts.ignored ? arrify(_opts.ignored) : arrify([]),
1252
- awaitWriteFinish: awf === true ? DEF_AWF : typeof awf === "object" ? { ...DEF_AWF, ...awf } : false
1253
- };
1254
- if (isIBMi)
1255
- opts.usePolling = true;
1256
- if (opts.atomic === void 0)
1257
- opts.atomic = !opts.usePolling;
1258
- const envPoll = process.env.CHOKIDAR_USEPOLLING;
1259
- if (envPoll !== void 0) {
1260
- const envLower = envPoll.toLowerCase();
1261
- if (envLower === "false" || envLower === "0")
1262
- opts.usePolling = false;
1263
- else if (envLower === "true" || envLower === "1")
1264
- opts.usePolling = true;
1265
- else
1266
- opts.usePolling = !!envLower;
1267
- }
1268
- const envInterval = process.env.CHOKIDAR_INTERVAL;
1269
- if (envInterval)
1270
- opts.interval = Number.parseInt(envInterval, 10);
1271
- let readyCalls = 0;
1272
- this._emitReady = () => {
1273
- readyCalls++;
1274
- if (readyCalls >= this._readyCount) {
1275
- this._emitReady = EMPTY_FN;
1276
- this._readyEmitted = true;
1277
- process.nextTick(() => this.emit(EVENTS.READY));
1278
- }
1279
- };
1280
- this._emitRaw = (...args) => this.emit(EVENTS.RAW, ...args);
1281
- this._boundRemove = this._remove.bind(this);
1282
- this.options = opts;
1283
- this._nodeFsHandler = new NodeFsHandler(this);
1284
- Object.freeze(opts);
1285
- }
1286
- _addIgnoredPath(matcher) {
1287
- if (isMatcherObject(matcher)) {
1288
- for (const ignored of this._ignoredPaths) {
1289
- if (isMatcherObject(ignored) && ignored.path === matcher.path && ignored.recursive === matcher.recursive) {
1290
- return;
1291
- }
1292
- }
1293
- }
1294
- this._ignoredPaths.add(matcher);
1295
- }
1296
- _removeIgnoredPath(matcher) {
1297
- this._ignoredPaths.delete(matcher);
1298
- if (typeof matcher === "string") {
1299
- for (const ignored of this._ignoredPaths) {
1300
- if (isMatcherObject(ignored) && ignored.path === matcher) {
1301
- this._ignoredPaths.delete(ignored);
1302
- }
1303
- }
1304
- }
1305
- }
1306
- // Public methods
1307
- /**
1308
- * Adds paths to be watched on an existing FSWatcher instance.
1309
- * @param paths_ file or file list. Other arguments are unused
1310
- */
1311
- add(paths_, _origAdd, _internal) {
1312
- const { cwd } = this.options;
1313
- this.closed = false;
1314
- this._closePromise = void 0;
1315
- let paths = unifyPaths(paths_);
1316
- if (cwd) {
1317
- paths = paths.map((path) => {
1318
- const absPath = getAbsolutePath(path, cwd);
1319
- return absPath;
1320
- });
1321
- }
1322
- paths.forEach((path) => {
1323
- this._removeIgnoredPath(path);
1324
- });
1325
- this._userIgnored = void 0;
1326
- if (!this._readyCount)
1327
- this._readyCount = 0;
1328
- this._readyCount += paths.length;
1329
- Promise.all(paths.map(async (path) => {
1330
- const res = await this._nodeFsHandler._addToNodeFs(path, !_internal, void 0, 0, _origAdd);
1331
- if (res)
1332
- this._emitReady();
1333
- return res;
1334
- })).then((results) => {
1335
- if (this.closed)
1336
- return;
1337
- results.forEach((item) => {
1338
- if (item)
1339
- this.add(sp2.dirname(item), sp2.basename(_origAdd || item));
1340
- });
1341
- });
1342
- return this;
1343
- }
1344
- /**
1345
- * Close watchers or start ignoring events from specified paths.
1346
- */
1347
- unwatch(paths_) {
1348
- if (this.closed)
1349
- return this;
1350
- const paths = unifyPaths(paths_);
1351
- const { cwd } = this.options;
1352
- paths.forEach((path) => {
1353
- if (!sp2.isAbsolute(path) && !this._closers.has(path)) {
1354
- if (cwd)
1355
- path = sp2.join(cwd, path);
1356
- path = sp2.resolve(path);
1357
- }
1358
- this._closePath(path);
1359
- this._addIgnoredPath(path);
1360
- if (this._watched.has(path)) {
1361
- this._addIgnoredPath({
1362
- path,
1363
- recursive: true
1364
- });
1365
- }
1366
- this._userIgnored = void 0;
1367
- });
1368
- return this;
1369
- }
1370
- /**
1371
- * Close watchers and remove all listeners from watched paths.
1372
- */
1373
- close() {
1374
- if (this._closePromise) {
1375
- return this._closePromise;
1376
- }
1377
- this.closed = true;
1378
- this.removeAllListeners();
1379
- const closers = [];
1380
- this._closers.forEach((closerList) => closerList.forEach((closer) => {
1381
- const promise = closer();
1382
- if (promise instanceof Promise)
1383
- closers.push(promise);
1384
- }));
1385
- this._streams.forEach((stream) => stream.destroy());
1386
- this._userIgnored = void 0;
1387
- this._readyCount = 0;
1388
- this._readyEmitted = false;
1389
- this._watched.forEach((dirent) => dirent.dispose());
1390
- this._closers.clear();
1391
- this._watched.clear();
1392
- this._streams.clear();
1393
- this._symlinkPaths.clear();
1394
- this._throttled.clear();
1395
- this._closePromise = closers.length ? Promise.all(closers).then(() => void 0) : Promise.resolve();
1396
- return this._closePromise;
1397
- }
1398
- /**
1399
- * Expose list of watched paths
1400
- * @returns for chaining
1401
- */
1402
- getWatched() {
1403
- const watchList = {};
1404
- this._watched.forEach((entry, dir) => {
1405
- const key = this.options.cwd ? sp2.relative(this.options.cwd, dir) : dir;
1406
- const index = key || ONE_DOT;
1407
- watchList[index] = entry.getChildren().sort();
1408
- });
1409
- return watchList;
1410
- }
1411
- emitWithAll(event, args) {
1412
- this.emit(event, ...args);
1413
- if (event !== EVENTS.ERROR)
1414
- this.emit(EVENTS.ALL, event, ...args);
1415
- }
1416
- // Common helpers
1417
- // --------------
1418
- /**
1419
- * Normalize and emit events.
1420
- * Calling _emit DOES NOT MEAN emit() would be called!
1421
- * @param event Type of event
1422
- * @param path File or directory path
1423
- * @param stats arguments to be passed with event
1424
- * @returns the error if defined, otherwise the value of the FSWatcher instance's `closed` flag
1425
- */
1426
- async _emit(event, path, stats) {
1427
- if (this.closed)
1428
- return;
1429
- const opts = this.options;
1430
- if (isWindows)
1431
- path = sp2.normalize(path);
1432
- if (opts.cwd)
1433
- path = sp2.relative(opts.cwd, path);
1434
- const args = [path];
1435
- if (stats != null)
1436
- args.push(stats);
1437
- const awf = opts.awaitWriteFinish;
1438
- let pw;
1439
- if (awf && (pw = this._pendingWrites.get(path))) {
1440
- pw.lastChange = /* @__PURE__ */ new Date();
1441
- return this;
1442
- }
1443
- if (opts.atomic) {
1444
- if (event === EVENTS.UNLINK) {
1445
- this._pendingUnlinks.set(path, [event, ...args]);
1446
- setTimeout(() => {
1447
- this._pendingUnlinks.forEach((entry, path2) => {
1448
- this.emit(...entry);
1449
- this.emit(EVENTS.ALL, ...entry);
1450
- this._pendingUnlinks.delete(path2);
1451
- });
1452
- }, typeof opts.atomic === "number" ? opts.atomic : 100);
1453
- return this;
1454
- }
1455
- if (event === EVENTS.ADD && this._pendingUnlinks.has(path)) {
1456
- event = EVENTS.CHANGE;
1457
- this._pendingUnlinks.delete(path);
1458
- }
1459
- }
1460
- if (awf && (event === EVENTS.ADD || event === EVENTS.CHANGE) && this._readyEmitted) {
1461
- const awfEmit = (err, stats2) => {
1462
- if (err) {
1463
- event = EVENTS.ERROR;
1464
- args[0] = err;
1465
- this.emitWithAll(event, args);
1466
- } else if (stats2) {
1467
- if (args.length > 1) {
1468
- args[1] = stats2;
1469
- } else {
1470
- args.push(stats2);
1471
- }
1472
- this.emitWithAll(event, args);
1473
- }
1474
- };
1475
- this._awaitWriteFinish(path, awf.stabilityThreshold, event, awfEmit);
1476
- return this;
1477
- }
1478
- if (event === EVENTS.CHANGE) {
1479
- const isThrottled = !this._throttle(EVENTS.CHANGE, path, 50);
1480
- if (isThrottled)
1481
- return this;
1482
- }
1483
- if (opts.alwaysStat && stats === void 0 && (event === EVENTS.ADD || event === EVENTS.ADD_DIR || event === EVENTS.CHANGE)) {
1484
- const fullPath = opts.cwd ? sp2.join(opts.cwd, path) : path;
1485
- let stats2;
1486
- try {
1487
- stats2 = await stat3(fullPath);
1488
- } catch (err) {
1489
- }
1490
- if (!stats2 || this.closed)
1491
- return;
1492
- args.push(stats2);
1493
- }
1494
- this.emitWithAll(event, args);
1495
- return this;
1496
- }
1497
- /**
1498
- * Common handler for errors
1499
- * @returns The error if defined, otherwise the value of the FSWatcher instance's `closed` flag
1500
- */
1501
- _handleError(error) {
1502
- const code = error && error.code;
1503
- if (error && code !== "ENOENT" && code !== "ENOTDIR" && (!this.options.ignorePermissionErrors || code !== "EPERM" && code !== "EACCES")) {
1504
- this.emit(EVENTS.ERROR, error);
1505
- }
1506
- return error || this.closed;
1507
- }
1508
- /**
1509
- * Helper utility for throttling
1510
- * @param actionType type being throttled
1511
- * @param path being acted upon
1512
- * @param timeout duration of time to suppress duplicate actions
1513
- * @returns tracking object or false if action should be suppressed
1514
- */
1515
- _throttle(actionType, path, timeout) {
1516
- if (!this._throttled.has(actionType)) {
1517
- this._throttled.set(actionType, /* @__PURE__ */ new Map());
1518
- }
1519
- const action = this._throttled.get(actionType);
1520
- if (!action)
1521
- throw new Error("invalid throttle");
1522
- const actionPath = action.get(path);
1523
- if (actionPath) {
1524
- actionPath.count++;
1525
- return false;
1526
- }
1527
- let timeoutObject;
1528
- const clear = () => {
1529
- const item = action.get(path);
1530
- const count = item ? item.count : 0;
1531
- action.delete(path);
1532
- clearTimeout(timeoutObject);
1533
- if (item)
1534
- clearTimeout(item.timeoutObject);
1535
- return count;
1536
- };
1537
- timeoutObject = setTimeout(clear, timeout);
1538
- const thr = { timeoutObject, clear, count: 0 };
1539
- action.set(path, thr);
1540
- return thr;
1541
- }
1542
- _incrReadyCount() {
1543
- return this._readyCount++;
1544
- }
1545
- /**
1546
- * Awaits write operation to finish.
1547
- * Polls a newly created file for size variations. When files size does not change for 'threshold' milliseconds calls callback.
1548
- * @param path being acted upon
1549
- * @param threshold Time in milliseconds a file size must be fixed before acknowledging write OP is finished
1550
- * @param event
1551
- * @param awfEmit Callback to be called when ready for event to be emitted.
1552
- */
1553
- _awaitWriteFinish(path, threshold, event, awfEmit) {
1554
- const awf = this.options.awaitWriteFinish;
1555
- if (typeof awf !== "object")
1556
- return;
1557
- const pollInterval = awf.pollInterval;
1558
- let timeoutHandler;
1559
- let fullPath = path;
1560
- if (this.options.cwd && !sp2.isAbsolute(path)) {
1561
- fullPath = sp2.join(this.options.cwd, path);
1562
- }
1563
- const now = /* @__PURE__ */ new Date();
1564
- const writes = this._pendingWrites;
1565
- function awaitWriteFinishFn(prevStat) {
1566
- statcb(fullPath, (err, curStat) => {
1567
- if (err || !writes.has(path)) {
1568
- if (err && err.code !== "ENOENT")
1569
- awfEmit(err);
1570
- return;
1571
- }
1572
- const now2 = Number(/* @__PURE__ */ new Date());
1573
- if (prevStat && curStat.size !== prevStat.size) {
1574
- writes.get(path).lastChange = now2;
1575
- }
1576
- const pw = writes.get(path);
1577
- const df = now2 - pw.lastChange;
1578
- if (df >= threshold) {
1579
- writes.delete(path);
1580
- awfEmit(void 0, curStat);
1581
- } else {
1582
- timeoutHandler = setTimeout(awaitWriteFinishFn, pollInterval, curStat);
1583
- }
1584
- });
1585
- }
1586
- if (!writes.has(path)) {
1587
- writes.set(path, {
1588
- lastChange: now,
1589
- cancelWait: () => {
1590
- writes.delete(path);
1591
- clearTimeout(timeoutHandler);
1592
- return event;
1593
- }
1594
- });
1595
- timeoutHandler = setTimeout(awaitWriteFinishFn, pollInterval);
1596
- }
1597
- }
1598
- /**
1599
- * Determines whether user has asked to ignore this path.
1600
- */
1601
- _isIgnored(path, stats) {
1602
- if (this.options.atomic && DOT_RE.test(path))
1603
- return true;
1604
- if (!this._userIgnored) {
1605
- const { cwd } = this.options;
1606
- const ign = this.options.ignored;
1607
- const ignored = (ign || []).map(normalizeIgnored(cwd));
1608
- const ignoredPaths = [...this._ignoredPaths];
1609
- const list = [...ignoredPaths.map(normalizeIgnored(cwd)), ...ignored];
1610
- this._userIgnored = anymatch(list, void 0);
1611
- }
1612
- return this._userIgnored(path, stats);
1613
- }
1614
- _isntIgnored(path, stat4) {
1615
- return !this._isIgnored(path, stat4);
1616
- }
1617
- /**
1618
- * Provides a set of common helpers and properties relating to symlink handling.
1619
- * @param path file or directory pattern being watched
1620
- */
1621
- _getWatchHelpers(path) {
1622
- return new WatchHelper(path, this.options.followSymlinks, this);
1623
- }
1624
- // Directory helpers
1625
- // -----------------
1626
- /**
1627
- * Provides directory tracking objects
1628
- * @param directory path of the directory
1629
- */
1630
- _getWatchedDir(directory) {
1631
- const dir = sp2.resolve(directory);
1632
- if (!this._watched.has(dir))
1633
- this._watched.set(dir, new DirEntry(dir, this._boundRemove));
1634
- return this._watched.get(dir);
1635
- }
1636
- // File helpers
1637
- // ------------
1638
- /**
1639
- * Check for read permissions: https://stackoverflow.com/a/11781404/1358405
1640
- */
1641
- _hasReadPermissions(stats) {
1642
- if (this.options.ignorePermissionErrors)
1643
- return true;
1644
- return Boolean(Number(stats.mode) & 256);
1645
- }
1646
- /**
1647
- * Handles emitting unlink events for
1648
- * files and directories, and via recursion, for
1649
- * files and directories within directories that are unlinked
1650
- * @param directory within which the following item is located
1651
- * @param item base path of item/directory
1652
- */
1653
- _remove(directory, item, isDirectory) {
1654
- const path = sp2.join(directory, item);
1655
- const fullPath = sp2.resolve(path);
1656
- isDirectory = isDirectory != null ? isDirectory : this._watched.has(path) || this._watched.has(fullPath);
1657
- if (!this._throttle("remove", path, 100))
1658
- return;
1659
- if (!isDirectory && this._watched.size === 1) {
1660
- this.add(directory, item, true);
1661
- }
1662
- const wp = this._getWatchedDir(path);
1663
- const nestedDirectoryChildren = wp.getChildren();
1664
- nestedDirectoryChildren.forEach((nested) => this._remove(path, nested));
1665
- const parent = this._getWatchedDir(directory);
1666
- const wasTracked = parent.has(item);
1667
- parent.remove(item);
1668
- if (this._symlinkPaths.has(fullPath)) {
1669
- this._symlinkPaths.delete(fullPath);
1670
- }
1671
- let relPath = path;
1672
- if (this.options.cwd)
1673
- relPath = sp2.relative(this.options.cwd, path);
1674
- if (this.options.awaitWriteFinish && this._pendingWrites.has(relPath)) {
1675
- const event = this._pendingWrites.get(relPath).cancelWait();
1676
- if (event === EVENTS.ADD)
1677
- return;
1678
- }
1679
- this._watched.delete(path);
1680
- this._watched.delete(fullPath);
1681
- const eventName = isDirectory ? EVENTS.UNLINK_DIR : EVENTS.UNLINK;
1682
- if (wasTracked && !this._isIgnored(path))
1683
- this._emit(eventName, path);
1684
- this._closePath(path);
1685
- }
1686
- /**
1687
- * Closes all watchers for a path
1688
- */
1689
- _closePath(path) {
1690
- this._closeFile(path);
1691
- const dir = sp2.dirname(path);
1692
- this._getWatchedDir(dir).remove(sp2.basename(path));
1693
- }
1694
- /**
1695
- * Closes only file-specific watchers
1696
- */
1697
- _closeFile(path) {
1698
- const closers = this._closers.get(path);
1699
- if (!closers)
1700
- return;
1701
- closers.forEach((closer) => closer());
1702
- this._closers.delete(path);
1703
- }
1704
- _addPathCloser(path, closer) {
1705
- if (!closer)
1706
- return;
1707
- let list = this._closers.get(path);
1708
- if (!list) {
1709
- list = [];
1710
- this._closers.set(path, list);
1711
- }
1712
- list.push(closer);
1713
- }
1714
- _readdirp(root2, opts) {
1715
- if (this.closed)
1716
- return;
1717
- const options = { type: EVENTS.ALL, alwaysStat: true, lstat: true, ...opts, depth: 0 };
1718
- let stream = readdirp(root2, options);
1719
- this._streams.add(stream);
1720
- stream.once(STR_CLOSE, () => {
1721
- stream = void 0;
1722
- });
1723
- stream.once(STR_END, () => {
1724
- if (stream) {
1725
- this._streams.delete(stream);
1726
- stream = void 0;
1727
- }
1728
- });
1729
- return stream;
1730
- }
1731
- };
1732
- function watch(paths, options = {}) {
1733
- const watcher = new FSWatcher(options);
1734
- watcher.add(paths);
1735
- return watcher;
1736
- }
1737
- var chokidar_default = { watch, FSWatcher };
1738
-
1739
- // scripts/element-start.ts
1740
- import { pathToFileURL, fileURLToPath } from "node:url";
1741
- import { join as join5, sep as sep3, dirname as dirname4 } from "node:path";
1742
- import { copyFile, readFile as readFile4, writeFile as writeFile2 } from "node:fs/promises";
1743
-
1744
- // scripts/fileExists.ts
1745
- import { access } from "node:fs/promises";
1746
- import { constants } from "node:fs";
1747
- async function fileExists(filePath) {
1748
- try {
1749
- await access(filePath, constants.F_OK);
1750
- return true;
1751
- } catch (error) {
1752
- return false;
1753
- }
1754
- }
1755
-
1756
- // scripts/folderExists.ts
1757
- import { access as access2 } from "node:fs/promises";
1758
- import { constants as constants2 } from "node:fs";
1759
- async function folderExists(folderPath) {
1760
- try {
1761
- await access2(folderPath, constants2.F_OK);
1762
- return true;
1763
- } catch (error) {
1764
- return false;
1765
- }
1766
- }
1767
-
1768
- // scripts/playgroundPlugin.ts
1769
- import { join as join3 } from "node:path";
1770
-
1771
- // scripts/getDirectories.ts
1772
- import { readdir as readdir3 } from "node:fs/promises";
1773
- async function getDirectories(dirPath) {
1774
- const directories = [];
1775
- try {
1776
- const entries = await readdir3(dirPath, { withFileTypes: true });
1777
- for (const entry of entries) {
1778
- if (entry.isDirectory()) {
1779
- directories.push(entry.name);
1780
- }
1781
- }
1782
- } catch (err) {
1783
- console.error("Error reading directory:", err);
1784
- }
1785
- return directories;
1786
- }
1787
-
1788
- // scripts/playgroundPlugin.ts
1789
- import { readFile } from "node:fs/promises";
1790
-
1791
- // scripts/capitalizeFirstChracter.ts
1792
- function capitalizeFirstCharacter(str) {
1793
- if (!str) {
1794
- return str;
1795
- }
1796
- return str.charAt(0).toUpperCase() + str.slice(1);
1797
- }
1798
-
1799
- // scripts/camelToDash.ts
1800
- function camelToDash(str) {
1801
- return str.replace(/([a-zA-Z])(?=[A-Z])/g, "$1-").toLowerCase();
1802
- }
1803
-
1804
- // scripts/playgroundPlugin.ts
1805
- var red = (text) => `\x1B[31m${text}\x1B[0m`;
1806
- var rootDir = process.cwd();
1807
- var srcDir = "src";
1808
- var componentsDir = "components";
1809
- function playgroundPlugin(options) {
1810
- return {
1811
- name: "playground-plugin",
1812
- setup(build) {
1813
- const entryPointName = "playground-entry";
1814
- const virtualNamespace = "playground-module";
1815
- build.onResolve({ filter: new RegExp(`^${entryPointName}$`) }, (args) => {
1816
- return {
1817
- path: entryPointName,
1818
- namespace: virtualNamespace
1819
- };
1820
- });
1821
- build.onLoad({ filter: /.*/, namespace: virtualNamespace }, async (args) => {
1822
- const entryPoints = [];
1823
- const namespaces = await getDirectories(join3(srcDir, componentsDir));
1824
- if (namespaces.length === 0) {
1825
- console.log(red('Missing at least 1 namespace folder under "src/components/"'));
1826
- process.exit();
1827
- }
1828
- const meta = [];
1829
- for (let namespace of namespaces) {
1830
- const metaNamespace = {
1831
- namespace,
1832
- components: []
1833
- };
1834
- meta.push(metaNamespace);
1835
- const namespaceDir = join3(srcDir, componentsDir, namespace);
1836
- const components = await getDirectories(namespaceDir);
1837
- for (let component of components) {
1838
- if (await fileExists(join3(srcDir, componentsDir, namespace, component, `${component}.ts`))) {
1839
- let readme = "";
1840
- if (await fileExists(join3(srcDir, componentsDir, namespace, component, "README.md"))) {
1841
- readme = await readFile(join3(srcDir, componentsDir, namespace, component, "README.md"), "utf8");
1842
- }
1843
- const metaComponent = {
1844
- namespace,
1845
- component,
1846
- tag: `${namespace}-${camelToDash(component)}`,
1847
- examples: [],
1848
- className: "",
1849
- classExtends: "",
1850
- readme
1851
- };
1852
- entryPoints.push(`import '${componentsDir}/${namespace}/${component}/${component}';`);
1853
- if (await folderExists(join3(namespaceDir, component, "__examples__"))) {
1854
- const examples = await getDirectories(join3(namespaceDir, component, "__examples__"));
1855
- for (let example of examples) {
1856
- if (await fileExists(join3(namespaceDir, component, "__examples__", example, `${example}.ts`))) {
1857
- entryPoints.push(`import '${componentsDir}/${namespace}/${component}/__examples__/${example}/${example}';`);
1858
- metaComponent.examples.push({
1859
- namespace,
1860
- component,
1861
- example,
1862
- tag: `x-${namespace}-${camelToDash(component)}-${camelToDash(example)}`,
1863
- className: `X${capitalizeFirstCharacter(namespace)}${capitalizeFirstCharacter(component)}${capitalizeFirstCharacter(example)}`
1864
- });
1865
- } else {
1866
- console.log(red(`Missing ${componentsDir}/${namespace}/${component}/__examples__/${example}/${example}.ts`));
1867
- }
1868
- }
1869
- }
1870
- const data = await readFile(join3(srcDir, componentsDir, namespace, component, `${component}.ts`), "utf8");
1871
- const matches = data.match(/class (\w+) extends (\w+)/);
1872
- if (!matches) {
1873
- console.log(red(`Component "${namespace}-${component}" must extend HtmlElement or base class`));
1874
- process.exit();
1875
- }
1876
- metaComponent.className = matches[1];
1877
- metaComponent.classExtends = matches[2];
1878
- metaNamespace.components.push(metaComponent);
1879
- }
1880
- }
1881
- }
1882
- options.after(meta);
1883
- return {
1884
- contents: entryPoints.join("\n"),
1885
- resolveDir: join3(process.cwd(), srcDir)
1886
- };
1887
- });
1888
- }
1889
- };
1890
- }
1891
-
1892
- // scripts/htmlDependentsPlugin.ts
1893
- import { sep as sep2 } from "node:path";
1894
- import { readFile as readFile2 } from "node:fs/promises";
1895
-
1896
- // scripts/dashToCamel.ts
1897
- function dashToCamel(str) {
1898
- return str.replace(/-([a-z])/g, (m) => m[1].toUpperCase());
1899
- }
1900
-
1901
- // scripts/htmlDependentsPlugin.ts
1902
- var root = process.cwd();
1903
- var rootDepth = root.split(sep2).length;
1904
- var htmlDependentsPlugin = {
1905
- name: "html-dependents-plugin",
1906
- setup(build) {
1907
- build.onLoad({ filter: /\.html$/ }, async (args) => {
1908
- const parts = args.path.split(sep2).splice(rootDepth);
1909
- const [src, componentsDir2, currentNamspace, currentComponent, ...file] = parts;
1910
- const contents = await readFile2(args.path, "utf8");
1911
- const matches = contents.matchAll(/<\/(?<namespace>\w+)-(?<value>[^>]+)/g);
1912
- const components = /* @__PURE__ */ new Map();
1913
- for (const match of matches) {
1914
- const { namespace, value } = match.groups;
1915
- const component = dashToCamel(value);
1916
- components.set(`${namespace}-${component}`, [namespace, component]);
1917
- }
1918
- const imports = [];
1919
- components.forEach(([namespace, component]) => {
1920
- const depth = parts.length - 4;
1921
- const backPaths = new Array(depth).fill("..");
1922
- if (namespace === currentNamspace) {
1923
- if (component === currentComponent) {
1924
- return;
1925
- }
1926
- imports.push(`import './${backPaths.join("/")}/${component}/${component}';`);
1927
- } else {
1928
- imports.push(`import './${backPaths.join("/")}/${namespace}/${component}/${component}';`);
1929
- }
1930
- });
1931
- imports.push(`export default \`${contents}\`;`);
1932
- return {
1933
- contents: imports.join("\n"),
1934
- loader: "js"
1935
- };
1936
- });
1937
- }
1938
- };
1939
-
1940
- // scripts/rebuildNotifyPlugin.ts
1941
- var green = (text) => `\x1B[32m${text}\x1B[0m`;
1942
- var rebuildNotifyPlugin = {
1943
- name: "rebuild-notify",
1944
- setup(build) {
1945
- build.onEnd((result) => {
1946
- if (result.errors.length > 0) {
1947
- console.error(`Build ended with ${result.errors.length} errors`);
1948
- } else {
1949
- console.log(green("Build succeeded!"));
1950
- }
1951
- });
1952
- }
1953
- };
1954
-
1955
- // scripts/createPlaygroundIndex.ts
1956
- import { join as join4 } from "node:path";
1957
- import { readFile as readFile3 } from "node:fs/promises";
1958
- async function createPlaygroundIndex({
1959
- mode,
1960
- rootDir: rootDir2,
1961
- srcDir: srcDir2,
1962
- indexFile,
1963
- defaultDir,
1964
- playgroundFile,
1965
- title,
1966
- repo,
1967
- repoComponent,
1968
- navigation,
1969
- namespaces
1970
- }) {
1971
- let indexContent = "";
1972
- if (await fileExists(join4(rootDir2, srcDir2, indexFile))) {
1973
- indexContent = await readFile3(join4(rootDir2, srcDir2, indexFile), "utf8");
1974
- } else {
1975
- indexContent = await readFile3(join4(defaultDir, playgroundFile), "utf8");
1976
- }
1977
- indexContent = indexContent.replace(
1978
- "<title>Default</title>",
1979
- `<title>${title ?? "Default"}</title>`
1980
- );
1981
- indexContent = indexContent.replace(
1982
- "<h1>Default</h1>",
1983
- `<h1>${title ?? "Default"}</h1>`
1984
- );
1985
- const navItems = structuredClone(navigation ?? []);
1986
- for (let navItem of navItems) {
1987
- navItem.items = [];
1988
- }
1989
- let defaultItem;
1990
- if (navItems.length === 0) {
1991
- defaultItem = { label: "Components", items: [] };
1992
- navItems.push(defaultItem);
1993
- } else {
1994
- defaultItem = navItems.find((x) => !x.extends && !x.components && !x.namespaces);
1995
- if (!defaultItem) {
1996
- defaultItem = { label: "Other", items: [] };
1997
- navItems.push(defaultItem);
1998
- }
1999
- }
2000
- const componentMap = /* @__PURE__ */ new Map();
2001
- namespaces.forEach(({ components }) => {
2002
- components.forEach(({ component, namespace, tag, readme, examples, className, classExtends }) => {
2003
- componentMap.set(className, {
2004
- className,
2005
- // MyComponent
2006
- classExtends,
2007
- // MyModal
2008
- component,
2009
- // component
2010
- namespace,
2011
- // my
2012
- tag,
2013
- // my-component
2014
- readme,
2015
- // # My Component
2016
- examples: examples.map((example) => example.className)
2017
- });
2018
- examples.forEach((example) => {
2019
- componentMap.set(example.className, {
2020
- className: example.className,
2021
- // XMyComponentBasic
2022
- classExtends: example.classExtends,
2023
- // HtmlElement
2024
- component: example.component,
2025
- // myComponentBasic
2026
- namespace: example.namespace,
2027
- // x
2028
- tag: example.tag,
2029
- // x-my-component-basic
2030
- example: example.example
2031
- // Basic
2032
- });
2033
- });
2034
- for (let navItem of navItems) {
2035
- if (navItem.include && navItem.include.includes(className)) {
2036
- navItem.items.push({
2037
- namespace,
2038
- component,
2039
- className,
2040
- tag
2041
- });
2042
- return;
2043
- }
2044
- }
2045
- for (let navItem of navItems) {
2046
- if (navItem === defaultItem) {
2047
- continue;
2048
- }
2049
- if (navItem.exclude && navItem.exclude.includes(className)) {
2050
- continue;
2051
- }
2052
- if (navItem.namespaces && !navItem.namespaces.includes(namespace)) {
2053
- continue;
2054
- }
2055
- if (navItem.extends && !navItem.extends.includes(classExtends)) {
2056
- continue;
2057
- }
2058
- navItem.items.push({
2059
- namespace,
2060
- component,
2061
- className,
2062
- tag
2063
- });
2064
- return;
2065
- }
2066
- defaultItem.items.push({
2067
- namespace,
2068
- component,
2069
- examples,
2070
- className,
2071
- tag
2072
- });
2073
- });
2074
- });
2075
- indexContent = indexContent.replace(/([ ]*)<!-- \[Navigation\] -->/, (match, indent) => {
2076
- return navItems.map(({ label, items }) => {
2077
- return [
2078
- indent,
2079
- `<div>${label}</div>`,
2080
- "<ul>",
2081
- items.map(({ component, namespace, tag, className }) => {
2082
- return [
2083
- `<li data-tag="${tag}" data-class-name="${className}" data-component="${component}"><a href="#${tag}">${component}</a></li>`
2084
- ].join(`
2085
- ${indent}`);
2086
- }).join(`
2087
- ${indent}`),
2088
- "</ul>"
2089
- ].join(`
2090
- ${indent}`);
2091
- }).join(`
2092
- ${indent}`);
2093
- });
2094
- if (repo) {
2095
- const github = "M12,2A10,10 0 0,0 2,12C2,16.42 4.87,20.17 8.84,21.5C9.34,21.58 9.5,21.27 9.5,21C9.5,20.77 9.5,20.14 9.5,19.31C6.73,19.91 6.14,17.97 6.14,17.97C5.68,16.81 5.03,16.5 5.03,16.5C4.12,15.88 5.1,15.9 5.1,15.9C6.1,15.97 6.63,16.93 6.63,16.93C7.5,18.45 8.97,18 9.54,17.76C9.63,17.11 9.89,16.67 10.17,16.42C7.95,16.17 5.62,15.31 5.62,11.5C5.62,10.39 6,9.5 6.65,8.79C6.55,8.54 6.2,7.5 6.75,6.15C6.75,6.15 7.59,5.88 9.5,7.17C10.29,6.95 11.15,6.84 12,6.84C12.85,6.84 13.71,6.95 14.5,7.17C16.41,5.88 17.25,6.15 17.25,6.15C17.8,7.5 17.45,8.54 17.35,8.79C18,9.5 18.38,10.39 18.38,11.5C18.38,15.32 16.04,16.16 13.81,16.41C14.17,16.72 14.5,17.33 14.5,18.26C14.5,19.6 14.5,20.68 14.5,21C14.5,21.27 14.66,21.59 15.17,21.5C19.14,20.16 22,16.42 22,12A10,10 0 0,0 12,2Z";
2096
- const generic = "M6,2H18A2,2 0 0,1 20,4V20A2,2 0 0,1 18,22H6A2,2 0 0,1 4,20V4A2,2 0 0,1 6,2M12.75,13.5C15.5,13.5 16.24,11.47 16.43,10.4C17.34,10.11 18,9.26 18,8.25C18,7 17,6 15.75,6C14.5,6 13.5,7 13.5,8.25C13.5,9.19 14.07,10 14.89,10.33C14.67,11 14,12 12,12C10.62,12 9.66,12.35 9,12.84V8.87C9.87,8.56 10.5,7.73 10.5,6.75C10.5,5.5 9.5,4.5 8.25,4.5C7,4.5 6,5.5 6,6.75C6,7.73 6.63,8.56 7.5,8.87V15.13C6.63,15.44 6,16.27 6,17.25C6,18.5 7,19.5 8.25,19.5C9.5,19.5 10.5,18.5 10.5,17.25C10.5,16.32 9.94,15.5 9.13,15.18C9.41,14.5 10.23,13.5 12.75,13.5M8.25,16.5A0.75,0.75 0 0,1 9,17.25A0.75,0.75 0 0,1 8.25,18A0.75,0.75 0 0,1 7.5,17.25A0.75,0.75 0 0,1 8.25,16.5M8.25,6A0.75,0.75 0 0,1 9,6.75A0.75,0.75 0 0,1 8.25,7.5A0.75,0.75 0 0,1 7.5,6.75A0.75,0.75 0 0,1 8.25,6M15.75,7.5A0.75,0.75 0 0,1 16.5,8.25A0.75,0.75 0 0,1 15.75,9A0.75,0.75 0 0,1 15,8.25A0.75,0.75 0 0,1 15.75,7.5Z";
2097
- const repoIcon = repo.includes("github.com") ? github : generic;
2098
- indexContent = indexContent.replace(/([ ]*)<!-- \[Repo\] -->/, (match, indent) => {
2099
- return [
2100
- indent,
2101
- `<a href="${repo}">`,
2102
- ' <svg viewBox="0 0 24 24">',
2103
- ` <path fill="currentColor" d="${repoIcon}" />`,
2104
- " </svg>",
2105
- " <span>View Repo</span>",
2106
- "</a>"
2107
- ].join(`
2108
- ${indent}`);
2109
- });
2110
- indexContent = indexContent.replace(/const repo = '';/, (match) => {
2111
- return `const repo = '${repo}';`;
2112
- });
2113
- indexContent = indexContent.replace(/const repoComponent = '';/, (match) => {
2114
- return `const repoComponent = '${repoComponent.replace(/\$repo/g, repo)}';`;
2115
- });
2116
- indexContent = indexContent.replace(/const repoIcon = '';/, (match) => {
2117
- return `const repoIcon = '${repoIcon}';`;
2118
- });
2119
- }
2120
- if (mode === "dev") {
2121
- indexContent = indexContent.replace(/([ ]*)<!-- \[info\] -->/, (match, indent) => {
2122
- return [
2123
- indent,
2124
- "<p>This page is generated from <code>npm start</code>. To render only specific components use <code>npm start c-button</code>.</p>"
2125
- ].join(`
2126
- ${indent}`);
2127
- });
2128
- }
2129
- const classNames = [...componentMap.keys()];
2130
- indexContent = indexContent.replace(/([ ]*)const componentMap = new Map\(\);/, (match, indent) => {
2131
- return [
2132
- `${indent}const componentMap = new Map();`,
2133
- ...classNames.map((className) => {
2134
- const data = componentMap.get(className);
2135
- return `componentMap.set('${className}', ${JSON.stringify(data)});`;
2136
- })
2137
- ].join(`${indent}
2138
- `);
2139
- });
2140
- indexContent = indexContent.replace(/([ ]*)const navigation = \[\];/, (match, indent) => {
2141
- return `${indent}const navigation = ${JSON.stringify(navItems, null, " ")};`;
2142
- });
2143
- return indexContent;
2144
- }
2145
-
2146
- // scripts/element-start.ts
2147
- (async () => {
2148
- const plugins = [htmlDependentsPlugin, rebuildNotifyPlugin];
2149
- const bold = (text) => `\x1B[1m${text}\x1B[0m`;
2150
- const green2 = (text) => `\x1B[32m${text}\x1B[0m`;
2151
- const red2 = (text) => `\x1B[31m${text}\x1B[0m`;
2152
- const __filename = fileURLToPath(import.meta.url);
2153
- const __dirname = dirname4(__filename);
2154
- const defaultDir = join5(__dirname, "..", "default");
2155
- const configFile = "element.config.ts";
2156
- const rootDir2 = process.cwd();
2157
- const publishDir = "publish";
2158
- const fullConfigPath = pathToFileURL(configFile);
2159
- if (!await fileExists(configFile)) {
2160
- console.log(red2("Missing element.config.ts in root."), "Add with content:");
2161
- console.log("export default {");
2162
- console.log(` namespace: 'hello',`);
2163
- console.log("}");
2164
- process.exit();
2165
- }
2166
- const config = await import(fullConfigPath.href);
2167
- const {
2168
- namespace,
2169
- title,
2170
- navigation,
2171
- repo,
2172
- repoComponent
2173
- } = config.default;
2174
- const distDir = "dist";
2175
- const srcDir2 = "src";
2176
- const componentsDir2 = "components";
2177
- const entryPoints = [];
2178
- if (namespace) {
2179
- console.log(green2("Building app..."));
2180
- entryPoints.push(`./${srcDir2}/${componentsDir2}/${namespace}/app/app.ts`);
2181
- const indexFile = "index.html";
2182
- if (await fileExists(join5(rootDir2, srcDir2, indexFile))) {
2183
- await copyFile(
2184
- join5(rootDir2, srcDir2, indexFile),
2185
- join5(rootDir2, distDir, indexFile)
2186
- );
2187
- } else {
2188
- let indexContent = await readFile4(join5(defaultDir, indexFile), "utf8");
2189
- indexContent = indexContent.replace(
2190
- "<title>Default</title>",
2191
- `<title>${title ?? "Default"}</title>`
2192
- );
2193
- indexContent = indexContent.replace(
2194
- "<namespace-app></namespace-app>",
2195
- `<${namespace}-app></${namespace}-app>`
2196
- );
2197
- await writeFile2(join5(rootDir2, distDir, indexFile), indexContent);
2198
- }
2199
- const faviconSvg = "favicon.svg";
2200
- if (await fileExists(join5(rootDir2, srcDir2, faviconSvg))) {
2201
- await copyFile(
2202
- join5(rootDir2, srcDir2, faviconSvg),
2203
- join5(rootDir2, distDir, faviconSvg)
2204
- );
2205
- } else {
2206
- await copyFile(
2207
- join5(defaultDir, faviconSvg),
2208
- join5(rootDir2, distDir, faviconSvg)
2209
- );
2210
- }
2211
- } else {
2212
- console.log(green2("Building components..."));
2213
- if (!await folderExists(join5(srcDir2, componentsDir2))) {
2214
- console.log(red2('Missing required "src/components" directory.'));
2215
- process.exit();
2216
- }
2217
- const playgroundFile = "playground.html";
2218
- const indexFile = "index.html";
2219
- entryPoints.push("playground-entry");
2220
- plugins.push(
2221
- playgroundPlugin({
2222
- after: async (namespaces) => {
2223
- const indexContent = await createPlaygroundIndex({
2224
- mode: "dev",
2225
- rootDir: rootDir2,
2226
- srcDir: srcDir2,
2227
- indexFile,
2228
- defaultDir,
2229
- playgroundFile,
2230
- title,
2231
- repo,
2232
- repoComponent,
2233
- navigation,
2234
- namespaces
2235
- });
2236
- await writeFile2(join5(rootDir2, distDir, indexFile), indexContent);
2237
- }
2238
- })
2239
- );
2240
- }
2241
- let ctx = await context({
2242
- entryPoints,
2243
- outfile: `./${distDir}/main.js`,
2244
- bundle: true,
2245
- format: "esm",
2246
- // Use ES Modules
2247
- target: "es2024",
2248
- // Target ES6 syntax
2249
- minify: false,
2250
- loader: {
2251
- ".css": "text"
2252
- },
2253
- plugins
2254
- });
2255
- await ctx.rebuild();
2256
- const watcher = chokidar_default.watch("src", {
2257
- ignoreInitial: true
2258
- // Don't trigger on startup
2259
- });
2260
- watcher.on("all", async (event, path) => {
2261
- if (!namespace) {
2262
- const parts = path.split(sep3);
2263
- if (parts.length > 4 && parts[0] === srcDir2 && parts[1] === componentsDir2) {
2264
- console.log(`Copy "${parts.slice(2).join("/")}" to publish/*`);
2265
- await copyFile(join5(rootDir2, ...parts), join5(rootDir2, publishDir, ...parts.slice(2)));
2266
- }
2267
- }
2268
- try {
2269
- await ctx.rebuild();
2270
- } catch (e) {
2271
- console.error("Rebuild failed:", e);
2272
- }
2273
- });
2274
- let { port } = await ctx.serve({
2275
- servedir: distDir
2276
- });
2277
- console.log(green2("Dev server started at"), `localhost:${port}`);
2278
- })();
3
+ import{context as ts}from"esbuild";import{EventEmitter as Re}from"node:events";import{stat as Ce}from"node:fs";import{readdir as ve,stat as Ie}from"node:fs/promises";import*as m from"node:path";import{lstat as yt,readdir as qt,realpath as Jt,stat as Xt}from"node:fs/promises";import{join as Qt,relative as te,resolve as Et,sep as ee}from"node:path";import{Readable as se}from"node:stream";var A={FILE_TYPE:"files",DIR_TYPE:"directories",FILE_DIR_TYPE:"files_directories",EVERYTHING_TYPE:"all"},nt={root:".",fileFilter:i=>!0,directoryFilter:i=>!0,type:A.FILE_TYPE,lstat:!1,depth:2147483648,alwaysStat:!1,highWaterMark:4096};Object.freeze(nt);var Dt="READDIRP_RECURSIVE_ERROR",ie=new Set(["ENOENT","EPERM","EACCES","ELOOP",Dt]),Pt=[A.DIR_TYPE,A.EVERYTHING_TYPE,A.FILE_DIR_TYPE,A.FILE_TYPE],ne=new Set([A.DIR_TYPE,A.EVERYTHING_TYPE,A.FILE_DIR_TYPE]),re=new Set([A.EVERYTHING_TYPE,A.FILE_DIR_TYPE,A.FILE_TYPE]),oe=i=>ie.has(i.code),ae=process.platform==="win32",xt=i=>!0,bt=i=>{if(i===void 0)return xt;if(typeof i=="function")return i;if(typeof i=="string"){let t=i.trim();return e=>e.basename===t}if(Array.isArray(i)){let t=i.map(e=>e.trim());return e=>t.some(n=>e.basename===n)}return xt},rt=class extends se{parents;reading;parent;_stat;_maxDepth;_wantsDir;_wantsFile;_wantsEverything;_root;_isDirent;_statsProp;_rdOptions;_fileFilter;_directoryFilter;constructor(t={}){super({objectMode:!0,autoDestroy:!0,highWaterMark:t.highWaterMark});let e={...nt,...t},{root:n,type:s}=e;this._fileFilter=bt(e.fileFilter),this._directoryFilter=bt(e.directoryFilter);let a=e.lstat?yt:Xt;ae?this._stat=c=>a(c,{bigint:!0}):this._stat=a,this._maxDepth=e.depth!=null&&Number.isSafeInteger(e.depth)?e.depth:nt.depth,this._wantsDir=s?ne.has(s):!1,this._wantsFile=s?re.has(s):!1,this._wantsEverything=s===A.EVERYTHING_TYPE,this._root=Et(n),this._isDirent=!e.alwaysStat,this._statsProp=this._isDirent?"dirent":"stats",this._rdOptions={encoding:"utf8",withFileTypes:this._isDirent},this.parents=[this._exploreDir(n,1)],this.reading=!1,this.parent=void 0}async _read(t){if(!this.reading){this.reading=!0;try{for(;!this.destroyed&&t>0;){let e=this.parent,n=e&&e.files;if(n&&n.length>0){let{path:s,depth:a}=e,c=n.splice(0,t).map(r=>this._formatEntry(r,s)),o=await Promise.all(c);for(let r of o){if(!r)continue;if(this.destroyed)return;let d=await this._getEntryType(r);d==="directory"&&this._directoryFilter(r)?(a<=this._maxDepth&&this.parents.push(this._exploreDir(r.fullPath,a+1)),this._wantsDir&&(this.push(r),t--)):(d==="file"||this._includeAsFile(r))&&this._fileFilter(r)&&this._wantsFile&&(this.push(r),t--)}}else{let s=this.parents.pop();if(!s){this.push(null);break}if(this.parent=await s,this.destroyed)return}}}catch(e){this.destroy(e)}finally{this.reading=!1}}}async _exploreDir(t,e){let n;try{n=await qt(t,this._rdOptions)}catch(s){this._onError(s)}return{files:n,depth:e,path:t}}async _formatEntry(t,e){let n,s=this._isDirent?t.name:t;try{let a=Et(Qt(e,s));n={path:te(this._root,a),fullPath:a,basename:s},n[this._statsProp]=this._isDirent?t:await this._stat(a)}catch(a){this._onError(a);return}return n}_onError(t){oe(t)&&!this.destroyed?this.emit("warn",t):this.destroy(t)}async _getEntryType(t){if(!t&&this._statsProp in t)return"";let e=t[this._statsProp];if(e.isFile())return"file";if(e.isDirectory())return"directory";if(e&&e.isSymbolicLink()){let n=t.fullPath;try{let s=await Jt(n),a=await yt(s);if(a.isFile())return"file";if(a.isDirectory()){let c=s.length;if(n.startsWith(s)&&n.substr(c,1)===ee){let o=new Error(`Circular symlink detected: "${n}" points to "${s}"`);return o.code=Dt,this._onError(o)}return"directory"}}catch(s){return this._onError(s),""}}}_includeAsFile(t){let e=t&&t[this._statsProp];return e&&this._wantsEverything&&!e.isDirectory()}};function Rt(i,t={}){let e=t.entryType||t.type;if(e==="both"&&(e=A.FILE_DIR_TYPE),e&&(t.type=e),i){if(typeof i!="string")throw new TypeError("readdirp: root argument must be a string. Usage: readdirp(root, options)");if(e&&!Pt.includes(e))throw new Error(`readdirp: Invalid type passed. Use one of ${Pt.join(", ")}`)}else throw new Error("readdirp: root argument is required. Usage: readdirp(root, options)");return t.root=i,new rt(t)}import{watch as ce,unwatchFile as Ct,watchFile as le}from"node:fs";import{realpath as ot,lstat as he,open as fe,stat as It}from"node:fs/promises";import{type as de}from"node:os";import*as P from"node:path";var pe="data",lt="end",$t="close",J=()=>{};var X=process.platform,ht=X==="win32",ue=X==="darwin",me=X==="linux",_e=X==="freebsd",Tt=de()==="OS400",D={ALL:"all",READY:"ready",ADD:"add",CHANGE:"change",ADD_DIR:"addDir",UNLINK:"unlink",UNLINK_DIR:"unlinkDir",RAW:"raw",ERROR:"error"},F=D,we="watch",ge={lstat:he,stat:It},j="listeners",B="errHandlers",H="rawEmitters",ye=[j,B,H],Ee=new Set(["3dm","3ds","3g2","3gp","7z","a","aac","adp","afdesign","afphoto","afpub","ai","aif","aiff","alz","ape","apk","appimage","ar","arj","asf","au","avi","bak","baml","bh","bin","bk","bmp","btif","bz2","bzip2","cab","caf","cgm","class","cmx","cpio","cr2","cur","dat","dcm","deb","dex","djvu","dll","dmg","dng","doc","docm","docx","dot","dotm","dra","DS_Store","dsk","dts","dtshd","dvb","dwg","dxf","ecelp4800","ecelp7470","ecelp9600","egg","eol","eot","epub","exe","f4v","fbs","fh","fla","flac","flatpak","fli","flv","fpx","fst","fvt","g3","gh","gif","graffle","gz","gzip","h261","h263","h264","icns","ico","ief","img","ipa","iso","jar","jpeg","jpg","jpgv","jpm","jxr","key","ktx","lha","lib","lvp","lz","lzh","lzma","lzo","m3u","m4a","m4v","mar","mdi","mht","mid","midi","mj2","mka","mkv","mmr","mng","mobi","mov","movie","mp3","mp4","mp4a","mpeg","mpg","mpga","mxu","nef","npx","numbers","nupkg","o","odp","ods","odt","oga","ogg","ogv","otf","ott","pages","pbm","pcx","pdb","pdf","pea","pgm","pic","png","pnm","pot","potm","potx","ppa","ppam","ppm","pps","ppsm","ppsx","ppt","pptm","pptx","psd","pya","pyc","pyo","pyv","qt","rar","ras","raw","resources","rgb","rip","rlc","rmf","rmvb","rpm","rtf","rz","s3m","s7z","scpt","sgi","shar","snap","sil","sketch","slk","smv","snk","so","stl","suo","sub","swf","tar","tbz","tbz2","tga","tgz","thmx","tif","tiff","tlz","ttc","ttf","txz","udf","uvh","uvi","uvm","uvp","uvs","uvu","viv","vob","war","wav","wax","wbmp","wdp","weba","webm","webp","whl","wim","wm","wma","wmv","wmx","woff","woff2","wrm","wvx","xbm","xif","xla","xlam","xls","xlsb","xlsm","xlsx","xlt","xltm","xltx","xm","xmind","xpi","xpm","xwd","xz","z","zip","zipx"]),Pe=i=>Ee.has(P.extname(i).slice(1).toLowerCase()),ct=(i,t)=>{i instanceof Set?i.forEach(t):t(i)},U=(i,t,e)=>{let n=i[t];n instanceof Set||(i[t]=n=new Set([n])),n.add(e)},xe=i=>t=>{let e=i[t];e instanceof Set?e.clear():delete i[t]},G=(i,t,e)=>{let n=i[t];n instanceof Set?n.delete(e):n===e&&delete i[t]},At=i=>i instanceof Set?i.size===0:!i,K=new Map;function vt(i,t,e,n,s){let a=(c,o)=>{e(i),s(c,o,{watchedPath:i}),o&&i!==o&&Z(P.resolve(i,o),j,P.join(i,o))};try{return ce(i,{persistent:t.persistent},a)}catch(c){n(c);return}}var Z=(i,t,e,n,s)=>{let a=K.get(i);a&&ct(a[t],c=>{c(e,n,s)})},be=(i,t,e,n)=>{let{listener:s,errHandler:a,rawEmitter:c}=n,o=K.get(t),r;if(!e.persistent)return r=vt(i,e,s,a,c),r?r.close.bind(r):void 0;if(o)U(o,j,s),U(o,B,a),U(o,H,c);else{if(r=vt(i,e,Z.bind(null,t,j),a,Z.bind(null,t,H)),!r)return;r.on(F.ERROR,async d=>{let f=Z.bind(null,t,B);if(o&&(o.watcherUnusable=!0),ht&&d.code==="EPERM")try{await(await fe(i,"r")).close(),f(d)}catch{}else f(d)}),o={listeners:s,errHandlers:a,rawEmitters:c,watcher:r},K.set(t,o)}return()=>{G(o,j,s),G(o,B,a),G(o,H,c),At(o.listeners)&&(o.watcher.close(),K.delete(t),ye.forEach(xe(o)),o.watcher=void 0,Object.freeze(o))}},at=new Map,De=(i,t,e,n)=>{let{listener:s,rawEmitter:a}=n,c=at.get(t),o=c&&c.options;return o&&(o.persistent<e.persistent||o.interval>e.interval)&&(Ct(t),c=void 0),c?(U(c,j,s),U(c,H,a)):(c={listeners:s,rawEmitters:a,options:e,watcher:le(t,e,(r,d)=>{ct(c.rawEmitters,h=>{h(F.CHANGE,t,{curr:r,prev:d})});let f=r.mtimeMs;(r.size!==d.size||f>d.mtimeMs||f===0)&&ct(c.listeners,h=>h(i,r))})},at.set(t,c)),()=>{G(c,j,s),G(c,H,a),At(c.listeners)&&(at.delete(t),Ct(t),c.options=c.watcher=void 0,Object.freeze(c))}},q=class{fsw;_boundHandleError;constructor(t){this.fsw=t,this._boundHandleError=e=>t._handleError(e)}_watchWithNodeFs(t,e){let n=this.fsw.options,s=P.dirname(t),a=P.basename(t);this.fsw._getWatchedDir(s).add(a);let o=P.resolve(t),r={persistent:n.persistent};e||(e=J);let d;if(n.usePolling){let f=n.interval!==n.binaryInterval;r.interval=f&&Pe(a)?n.binaryInterval:n.interval,d=De(t,o,r,{listener:e,rawEmitter:this.fsw._emitRaw})}else d=be(t,o,r,{listener:e,errHandler:this._boundHandleError,rawEmitter:this.fsw._emitRaw});return d}_handleFile(t,e,n){if(this.fsw.closed)return;let s=P.dirname(t),a=P.basename(t),c=this.fsw._getWatchedDir(s),o=e;if(c.has(a))return;let r=async(f,h)=>{if(this.fsw._throttle(we,t,5)){if(!h||h.mtimeMs===0)try{let l=await It(t);if(this.fsw.closed)return;let p=l.atimeMs,u=l.mtimeMs;if((!p||p<=u||u!==o.mtimeMs)&&this.fsw._emit(F.CHANGE,t,l),(ue||me||_e)&&o.ino!==l.ino){this.fsw._closeFile(f),o=l;let g=this._watchWithNodeFs(t,r);g&&this.fsw._addPathCloser(f,g)}else o=l}catch{this.fsw._remove(s,a)}else if(c.has(a)){let l=h.atimeMs,p=h.mtimeMs;(!l||l<=p||p!==o.mtimeMs)&&this.fsw._emit(F.CHANGE,t,h),o=h}}},d=this._watchWithNodeFs(t,r);if(!(n&&this.fsw.options.ignoreInitial)&&this.fsw._isntIgnored(t)){if(!this.fsw._throttle(F.ADD,t,0))return;this.fsw._emit(F.ADD,t,e)}return d}async _handleSymlink(t,e,n,s){if(this.fsw.closed)return;let a=t.fullPath,c=this.fsw._getWatchedDir(e);if(!this.fsw.options.followSymlinks){this.fsw._incrReadyCount();let o;try{o=await ot(n)}catch{return this.fsw._emitReady(),!0}return this.fsw.closed?void 0:(c.has(s)?this.fsw._symlinkPaths.get(a)!==o&&(this.fsw._symlinkPaths.set(a,o),this.fsw._emit(F.CHANGE,n,t.stats)):(c.add(s),this.fsw._symlinkPaths.set(a,o),this.fsw._emit(F.ADD,n,t.stats)),this.fsw._emitReady(),!0)}if(this.fsw._symlinkPaths.has(a))return!0;this.fsw._symlinkPaths.set(a,!0)}_handleRead(t,e,n,s,a,c,o){t=P.join(t,"");let r=s?`${t}:${s}`:t;if(o=this.fsw._throttle("readdir",r,1e3),!o)return;let d=this.fsw._getWatchedDir(n.path),f=new Set,h=this.fsw._readdirp(t,{fileFilter:l=>n.filterPath(l),directoryFilter:l=>n.filterDir(l)});if(h)return h.on(pe,async l=>{if(this.fsw.closed){h=void 0;return}let p=l.path,u=P.join(t,p);if(f.add(p),!(l.stats.isSymbolicLink()&&await this._handleSymlink(l,t,u,p))){if(this.fsw.closed){h=void 0;return}(p===s||!s&&!d.has(p))&&(this.fsw._incrReadyCount(),u=P.join(a,P.relative(a,u)),this._addToNodeFs(u,e,n,c+1))}}).on(F.ERROR,this._boundHandleError),new Promise((l,p)=>{if(!h)return p();h.once(lt,()=>{if(this.fsw.closed){h=void 0;return}let u=o?o.clear():!1;l(void 0),d.getChildren().filter(g=>g!==t&&!f.has(g)).forEach(g=>{this.fsw._remove(t,g)}),h=void 0,u&&this._handleRead(t,!1,n,s,a,c,o)})})}async _handleDir(t,e,n,s,a,c,o){let r=this.fsw._getWatchedDir(P.dirname(t)),d=r.has(P.basename(t));!(n&&this.fsw.options.ignoreInitial)&&!a&&!d&&this.fsw._emit(F.ADD_DIR,t,e),r.add(P.basename(t)),this.fsw._getWatchedDir(t);let f,h,l=this.fsw.options.depth;if((l==null||s<=l)&&!this.fsw._symlinkPaths.has(o)){if(!a&&(await this._handleRead(t,n,c,a,t,s,f),this.fsw.closed))return;h=this._watchWithNodeFs(t,(p,u)=>{u&&u.mtimeMs===0||this._handleRead(p,!1,c,a,t,s,f)})}return h}async _addToNodeFs(t,e,n,s,a){let c=this.fsw._emitReady;if(this.fsw._isIgnored(t)||this.fsw.closed)return c(),!1;let o=this.fsw._getWatchHelpers(t);n&&(o.filterPath=r=>n.filterPath(r),o.filterDir=r=>n.filterDir(r));try{let r=await ge[o.statMethod](o.watchPath);if(this.fsw.closed)return;if(this.fsw._isIgnored(o.watchPath,r))return c(),!1;let d=this.fsw.options.followSymlinks,f;if(r.isDirectory()){let h=P.resolve(t),l=d?await ot(t):t;if(this.fsw.closed||(f=await this._handleDir(o.watchPath,r,e,s,a,o,l),this.fsw.closed))return;h!==l&&l!==void 0&&this.fsw._symlinkPaths.set(h,l)}else if(r.isSymbolicLink()){let h=d?await ot(t):t;if(this.fsw.closed)return;let l=P.dirname(o.watchPath);if(this.fsw._getWatchedDir(l).add(o.watchPath),this.fsw._emit(F.ADD,o.watchPath,r),f=await this._handleDir(l,r,e,s,t,o,h),this.fsw.closed)return;h!==void 0&&this.fsw._symlinkPaths.set(P.resolve(t),h)}else f=this._handleFile(o.watchPath,r,e);return c(),f&&this.fsw._addPathCloser(t,f),!1}catch(r){if(this.fsw._handleError(r))return c(),t}}};var ft="/",$e="//",Wt=".",Te="..",Ae="string",Fe=/\\/g,kt=/\/\//g,Ne=/\..*\.(sw[px])$|~$|\.subl.*\.tmp/,Se=/^\.[/\\]/;function Q(i){return Array.isArray(i)?i:[i]}var dt=i=>typeof i=="object"&&i!==null&&!(i instanceof RegExp);function Me(i){return typeof i=="function"?i:typeof i=="string"?t=>i===t:i instanceof RegExp?t=>i.test(t):typeof i=="object"&&i!==null?t=>{if(i.path===t)return!0;if(i.recursive){let e=m.relative(i.path,t);return e?!e.startsWith("..")&&!m.isAbsolute(e):!1}return!1}:()=>!1}function We(i){if(typeof i!="string")throw new Error("string expected");i=m.normalize(i),i=i.replace(/\\/g,"/");let t=!1;return i.startsWith("//")&&(t=!0),i=i.replace(kt,"/"),t&&(i="/"+i),i}function Ft(i,t,e){let n=We(t);for(let s=0;s<i.length;s++){let a=i[s];if(a(n,e))return!0}return!1}function ke(i,t){if(i==null)throw new TypeError("anymatch: specify first argument");let n=Q(i).map(s=>Me(s));return t==null?(s,a)=>Ft(n,s,a):Ft(n,t)}var Nt=i=>{let t=Q(i).flat();if(!t.every(e=>typeof e===Ae))throw new TypeError(`Non-string provided as watch path: ${t}`);return t.map(Lt)},St=i=>{let t=i.replace(Fe,ft),e=!1;return t.startsWith($e)&&(e=!0),t=t.replace(kt,ft),e&&(t=ft+t),t},Lt=i=>St(m.normalize(St(i))),Mt=(i="")=>t=>typeof t=="string"?Lt(m.isAbsolute(t)?t:m.join(i,t)):t,Le=(i,t)=>m.isAbsolute(i)?i:m.join(t,i),je=Object.freeze(new Set),pt=class{path;_removeWatcher;items;constructor(t,e){this.path=t,this._removeWatcher=e,this.items=new Set}add(t){let{items:e}=this;e&&t!==Wt&&t!==Te&&e.add(t)}async remove(t){let{items:e}=this;if(!e||(e.delete(t),e.size>0))return;let n=this.path;try{await ve(n)}catch{this._removeWatcher&&this._removeWatcher(m.dirname(n),m.basename(n))}}has(t){let{items:e}=this;if(e)return e.has(t)}getChildren(){let{items:t}=this;return t?[...t.values()]:[]}dispose(){this.items.clear(),this.path="",this._removeWatcher=J,this.items=je,Object.freeze(this)}},Oe="stat",ze="lstat",ut=class{fsw;path;watchPath;fullWatchPath;dirParts;followSymlinks;statMethod;constructor(t,e,n){this.fsw=n;let s=t;this.path=t=t.replace(Se,""),this.watchPath=s,this.fullWatchPath=m.resolve(s),this.dirParts=[],this.dirParts.forEach(a=>{a.length>1&&a.pop()}),this.followSymlinks=e,this.statMethod=e?Oe:ze}entryPath(t){return m.join(this.watchPath,m.relative(this.watchPath,t.fullPath))}filterPath(t){let{stats:e}=t;if(e&&e.isSymbolicLink())return this.filterDir(t);let n=this.entryPath(t);return this.fsw._isntIgnored(n,e)&&this.fsw._hasReadPermissions(e)}filterDir(t){return this.fsw._isntIgnored(this.entryPath(t),t.stats)}},tt=class extends Re{closed;options;_closers;_ignoredPaths;_throttled;_streams;_symlinkPaths;_watched;_pendingWrites;_pendingUnlinks;_readyCount;_emitReady;_closePromise;_userIgnored;_readyEmitted;_emitRaw;_boundRemove;_nodeFsHandler;constructor(t={}){super(),this.closed=!1,this._closers=new Map,this._ignoredPaths=new Set,this._throttled=new Map,this._streams=new Set,this._symlinkPaths=new Map,this._watched=new Map,this._pendingWrites=new Map,this._pendingUnlinks=new Map,this._readyCount=0,this._readyEmitted=!1;let e=t.awaitWriteFinish,n={stabilityThreshold:2e3,pollInterval:100},s={persistent:!0,ignoreInitial:!1,ignorePermissionErrors:!1,interval:100,binaryInterval:300,followSymlinks:!0,usePolling:!1,atomic:!0,...t,ignored:t.ignored?Q(t.ignored):Q([]),awaitWriteFinish:e===!0?n:typeof e=="object"?{...n,...e}:!1};Tt&&(s.usePolling=!0),s.atomic===void 0&&(s.atomic=!s.usePolling);let a=process.env.CHOKIDAR_USEPOLLING;if(a!==void 0){let r=a.toLowerCase();r==="false"||r==="0"?s.usePolling=!1:r==="true"||r==="1"?s.usePolling=!0:s.usePolling=!!r}let c=process.env.CHOKIDAR_INTERVAL;c&&(s.interval=Number.parseInt(c,10));let o=0;this._emitReady=()=>{o++,o>=this._readyCount&&(this._emitReady=J,this._readyEmitted=!0,process.nextTick(()=>this.emit(D.READY)))},this._emitRaw=(...r)=>this.emit(D.RAW,...r),this._boundRemove=this._remove.bind(this),this.options=s,this._nodeFsHandler=new q(this),Object.freeze(s)}_addIgnoredPath(t){if(dt(t)){for(let e of this._ignoredPaths)if(dt(e)&&e.path===t.path&&e.recursive===t.recursive)return}this._ignoredPaths.add(t)}_removeIgnoredPath(t){if(this._ignoredPaths.delete(t),typeof t=="string")for(let e of this._ignoredPaths)dt(e)&&e.path===t&&this._ignoredPaths.delete(e)}add(t,e,n){let{cwd:s}=this.options;this.closed=!1,this._closePromise=void 0;let a=Nt(t);return s&&(a=a.map(c=>Le(c,s))),a.forEach(c=>{this._removeIgnoredPath(c)}),this._userIgnored=void 0,this._readyCount||(this._readyCount=0),this._readyCount+=a.length,Promise.all(a.map(async c=>{let o=await this._nodeFsHandler._addToNodeFs(c,!n,void 0,0,e);return o&&this._emitReady(),o})).then(c=>{this.closed||c.forEach(o=>{o&&this.add(m.dirname(o),m.basename(e||o))})}),this}unwatch(t){if(this.closed)return this;let e=Nt(t),{cwd:n}=this.options;return e.forEach(s=>{!m.isAbsolute(s)&&!this._closers.has(s)&&(n&&(s=m.join(n,s)),s=m.resolve(s)),this._closePath(s),this._addIgnoredPath(s),this._watched.has(s)&&this._addIgnoredPath({path:s,recursive:!0}),this._userIgnored=void 0}),this}close(){if(this._closePromise)return this._closePromise;this.closed=!0,this.removeAllListeners();let t=[];return this._closers.forEach(e=>e.forEach(n=>{let s=n();s instanceof Promise&&t.push(s)})),this._streams.forEach(e=>e.destroy()),this._userIgnored=void 0,this._readyCount=0,this._readyEmitted=!1,this._watched.forEach(e=>e.dispose()),this._closers.clear(),this._watched.clear(),this._streams.clear(),this._symlinkPaths.clear(),this._throttled.clear(),this._closePromise=t.length?Promise.all(t).then(()=>{}):Promise.resolve(),this._closePromise}getWatched(){let t={};return this._watched.forEach((e,n)=>{let a=(this.options.cwd?m.relative(this.options.cwd,n):n)||Wt;t[a]=e.getChildren().sort()}),t}emitWithAll(t,e){this.emit(t,...e),t!==D.ERROR&&this.emit(D.ALL,t,...e)}async _emit(t,e,n){if(this.closed)return;let s=this.options;ht&&(e=m.normalize(e)),s.cwd&&(e=m.relative(s.cwd,e));let a=[e];n!=null&&a.push(n);let c=s.awaitWriteFinish,o;if(c&&(o=this._pendingWrites.get(e)))return o.lastChange=new Date,this;if(s.atomic){if(t===D.UNLINK)return this._pendingUnlinks.set(e,[t,...a]),setTimeout(()=>{this._pendingUnlinks.forEach((r,d)=>{this.emit(...r),this.emit(D.ALL,...r),this._pendingUnlinks.delete(d)})},typeof s.atomic=="number"?s.atomic:100),this;t===D.ADD&&this._pendingUnlinks.has(e)&&(t=D.CHANGE,this._pendingUnlinks.delete(e))}if(c&&(t===D.ADD||t===D.CHANGE)&&this._readyEmitted){let r=(d,f)=>{d?(t=D.ERROR,a[0]=d,this.emitWithAll(t,a)):f&&(a.length>1?a[1]=f:a.push(f),this.emitWithAll(t,a))};return this._awaitWriteFinish(e,c.stabilityThreshold,t,r),this}if(t===D.CHANGE&&!this._throttle(D.CHANGE,e,50))return this;if(s.alwaysStat&&n===void 0&&(t===D.ADD||t===D.ADD_DIR||t===D.CHANGE)){let r=s.cwd?m.join(s.cwd,e):e,d;try{d=await Ie(r)}catch{}if(!d||this.closed)return;a.push(d)}return this.emitWithAll(t,a),this}_handleError(t){let e=t&&t.code;return t&&e!=="ENOENT"&&e!=="ENOTDIR"&&(!this.options.ignorePermissionErrors||e!=="EPERM"&&e!=="EACCES")&&this.emit(D.ERROR,t),t||this.closed}_throttle(t,e,n){this._throttled.has(t)||this._throttled.set(t,new Map);let s=this._throttled.get(t);if(!s)throw new Error("invalid throttle");let a=s.get(e);if(a)return a.count++,!1;let c,o=()=>{let d=s.get(e),f=d?d.count:0;return s.delete(e),clearTimeout(c),d&&clearTimeout(d.timeoutObject),f};c=setTimeout(o,n);let r={timeoutObject:c,clear:o,count:0};return s.set(e,r),r}_incrReadyCount(){return this._readyCount++}_awaitWriteFinish(t,e,n,s){let a=this.options.awaitWriteFinish;if(typeof a!="object")return;let c=a.pollInterval,o,r=t;this.options.cwd&&!m.isAbsolute(t)&&(r=m.join(this.options.cwd,t));let d=new Date,f=this._pendingWrites;function h(l){Ce(r,(p,u)=>{if(p||!f.has(t)){p&&p.code!=="ENOENT"&&s(p);return}let g=Number(new Date);l&&u.size!==l.size&&(f.get(t).lastChange=g);let E=f.get(t);g-E.lastChange>=e?(f.delete(t),s(void 0,u)):o=setTimeout(h,c,u)})}f.has(t)||(f.set(t,{lastChange:d,cancelWait:()=>(f.delete(t),clearTimeout(o),n)}),o=setTimeout(h,c))}_isIgnored(t,e){if(this.options.atomic&&Ne.test(t))return!0;if(!this._userIgnored){let{cwd:n}=this.options,a=(this.options.ignored||[]).map(Mt(n)),o=[...[...this._ignoredPaths].map(Mt(n)),...a];this._userIgnored=ke(o,void 0)}return this._userIgnored(t,e)}_isntIgnored(t,e){return!this._isIgnored(t,e)}_getWatchHelpers(t){return new ut(t,this.options.followSymlinks,this)}_getWatchedDir(t){let e=m.resolve(t);return this._watched.has(e)||this._watched.set(e,new pt(e,this._boundRemove)),this._watched.get(e)}_hasReadPermissions(t){return this.options.ignorePermissionErrors?!0:!!(Number(t.mode)&256)}_remove(t,e,n){let s=m.join(t,e),a=m.resolve(s);if(n=n??(this._watched.has(s)||this._watched.has(a)),!this._throttle("remove",s,100))return;!n&&this._watched.size===1&&this.add(t,e,!0),this._getWatchedDir(s).getChildren().forEach(l=>this._remove(s,l));let r=this._getWatchedDir(t),d=r.has(e);r.remove(e),this._symlinkPaths.has(a)&&this._symlinkPaths.delete(a);let f=s;if(this.options.cwd&&(f=m.relative(this.options.cwd,s)),this.options.awaitWriteFinish&&this._pendingWrites.has(f)&&this._pendingWrites.get(f).cancelWait()===D.ADD)return;this._watched.delete(s),this._watched.delete(a);let h=n?D.UNLINK_DIR:D.UNLINK;d&&!this._isIgnored(s)&&this._emit(h,s),this._closePath(s)}_closePath(t){this._closeFile(t);let e=m.dirname(t);this._getWatchedDir(e).remove(m.basename(t))}_closeFile(t){let e=this._closers.get(t);e&&(e.forEach(n=>n()),this._closers.delete(t))}_addPathCloser(t,e){if(!e)return;let n=this._closers.get(t);n||(n=[],this._closers.set(t,n)),n.push(e)}_readdirp(t,e){if(this.closed)return;let n={type:D.ALL,alwaysStat:!0,lstat:!0,...e,depth:0},s=Rt(t,n);return this._streams.add(s),s.once($t,()=>{s=void 0}),s.once(lt,()=>{s&&(this._streams.delete(s),s=void 0)}),s}};function He(i,t={}){let e=new tt(t);return e.add(i),e}var jt={watch:He,FSWatcher:tt};import{pathToFileURL as es,fileURLToPath as ss}from"node:url";import{join as x,sep as wt,dirname as is}from"node:path";import{copyFile as V,cp as ns,readFile as rs,writeFile as Kt}from"node:fs/promises";import{access as Ye}from"node:fs/promises";import{constants as Ue}from"node:fs";async function N(i){try{return await Ye(i,Ue.F_OK),!0}catch{return!1}}import{access as Ge}from"node:fs/promises";import{constants as Ve}from"node:fs";async function Y(i){try{return await Ge(i,Ve.F_OK),!0}catch{return!1}}import{join as M}from"node:path";import{readdir as Be}from"node:fs/promises";async function O(i){let t=[];try{let e=await Be(i,{withFileTypes:!0});for(let n of e)n.isDirectory()&&t.push(n.name)}catch(e){console.error("Error reading directory:",e)}return t}import{readFile as Ot}from"node:fs/promises";function et(i){return i&&i.charAt(0).toUpperCase()+i.slice(1)}function st(i){return i.replace(/([a-zA-Z])(?=[A-Z])/g,"$1-").toLowerCase()}var mt=i=>`\x1B[31m${i}\x1B[0m`,Ys=process.cwd();var z="src",k="components";function zt(i){return{name:"playground-plugin",setup(t){let e="playground-entry",n="playground-module";t.onResolve({filter:new RegExp(`^${e}$`)},s=>({path:e,namespace:n})),t.onLoad({filter:/.*/,namespace:n},async s=>{let a=[],c=await O(M(z,k));c.length===0&&(console.log(mt('Missing at least 1 namespace folder under "src/components/"')),process.exit());let o=[];for(let r of c){let d={namespace:r,components:[]};o.push(d);let f=M(z,k,r),h=await O(f);for(let l of h)if(await N(M(z,k,r,l,`${l}.ts`))){let p="";await N(M(z,k,r,l,"README.md"))&&(p=await Ot(M(z,k,r,l,"README.md"),"utf8"));let u={namespace:r,component:l,tag:`${r}-${st(l)}`,examples:[],className:"",classExtends:"",readme:p};if(a.push(`import '${k}/${r}/${l}/${l}';`),await Y(M(f,l,"__examples__"))){let _=await O(M(f,l,"__examples__"));for(let w of _)await N(M(f,l,"__examples__",w,`${w}.ts`))?(a.push(`import '${k}/${r}/${l}/__examples__/${w}/${w}';`),u.examples.push({namespace:r,component:l,example:w,tag:`x-${r}-${st(l)}-${st(w)}`,className:`X${et(r)}${et(l)}${et(w)}`})):console.log(mt(`Missing ${k}/${r}/${l}/__examples__/${w}/${w}.ts`))}let E=(await Ot(M(z,k,r,l,`${l}.ts`),"utf8")).match(/class (\w+) extends (\w+)/);E||(console.log(mt(`Component "${r}-${l}" must extend HtmlElement or base class`)),process.exit()),u.className=E[1],u.classExtends=E[2],d.components.push(u)}}return i.after(o),{contents:a.join(`
4
+ `),resolveDir:M(process.cwd(),z)}})}}}import{sep as Yt}from"node:path";import{readFile as Ke}from"node:fs/promises";function Ht(i){return i.replace(/-([a-z])/g,t=>t[1].toUpperCase())}var Ze="node_modules",qe=process.cwd(),Je=qe.split(Yt).length,Xe=i=>`\x1B[31m${i}\x1B[0m`;function Ut({localNamespaces:i,externalNamespaces:t}){return{name:"html-dependents-plugin",setup(e){e.onLoad({filter:/\.html$/},async n=>{let s=n.path.split(Yt).splice(Je),[a,c,o,r,...d]=s,f=await Ke(n.path,"utf8"),h=f.matchAll(/<\/(?<namespace>\w+)-(?<value>[^>]+)/g),l=new Map;for(let u of h){let{namespace:g,value:E}=u.groups,_=Ht(E);l.set(`${g}-${_}`,[g,_])}let p=[];return l.forEach(([u,g])=>{let E=s.length-4,_=new Array(E).fill("..");if(u===o){if(g===r)return;p.push(`import './${_.join("/")}/${g}/${g}';`)}else if(i.includes(u))p.push(`import './${_.join("/")}/${u}/${g}/${g}';`);else if(t.has(u)){_.push(".."),_.push(".."),_.push("..");let w=t.get(u);p.push(`import './${_.join("/")}/${Ze}/${w}/${u}/${g}/${g}';`)}else console.log(Xe(`Unable to find namespace folder "${u}". Possibly missing 'external' in element.config.ts`)),process.exit()}),p.push(`export default \`${f}\`;`),{contents:p.join(`
5
+ `),loader:"js"}})}}}var Qe=i=>`\x1B[32m${i}\x1B[0m`,Gt={name:"rebuild-notify",setup(i){i.onEnd(t=>{t.errors.length>0?console.error(`Build ended with ${t.errors.length} errors`):console.log(Qe("Build succeeded!"))})}};import{join as _t}from"node:path";import{readFile as Vt}from"node:fs/promises";async function Bt({mode:i,rootDir:t,srcDir:e,indexFile:n,defaultDir:s,playgroundFile:a,title:c,repo:o,repoComponent:r,navigation:d,namespaces:f}){let h="";await N(_t(t,e,n))?h=await Vt(_t(t,e,n),"utf8"):h=await Vt(_t(s,a),"utf8"),h=h.replace("<title>Default</title>",`<title>${c??"Default"}</title>`),h=h.replace("<h1>Default</h1>",`<h1>${c??"Default"}</h1>`);let l=structuredClone(d??[]);for(let E of l)E.items=[];let p;l.length===0?(p={label:"Components",items:[]},l.push(p)):(p=l.find(E=>!E.extends&&!E.components&&!E.namespaces),p||(p={label:"Other",items:[]},l.push(p)));let u=new Map;if(f.forEach(({components:E})=>{E.forEach(({component:_,namespace:w,tag:I,readme:C,examples:R,className:$,classExtends:L})=>{u.set($,{className:$,classExtends:L,component:_,namespace:w,tag:I,readme:C,examples:R.map(y=>y.className)}),R.forEach(y=>{u.set(y.className,{className:y.className,classExtends:y.classExtends,component:y.component,namespace:y.namespace,tag:y.tag,example:y.example})});for(let y of l)if(y.include&&y.include.includes($)){y.items.push({namespace:w,component:_,className:$,tag:I});return}for(let y of l)if(y!==p&&!(y.exclude&&y.exclude.includes($))&&!(y.namespaces&&!y.namespaces.includes(w))&&!(y.extends&&!y.extends.includes(L))){y.items.push({namespace:w,component:_,className:$,tag:I});return}p.items.push({namespace:w,component:_,examples:R,className:$,tag:I})})}),h=h.replace(/([ ]*)<!-- \[Navigation\] -->/,(E,_)=>l.map(({label:w,items:I})=>[_,`<div>${w}</div>`,"<ul>",I.map(({component:C,namespace:R,tag:$,className:L})=>[`<li data-tag="${$}" data-class-name="${L}" data-component="${C}"><a href="#${$}">${C}</a></li>`].join(`
6
+ ${_}`)).join(`
7
+ ${_}`),"</ul>"].join(`
8
+ ${_}`)).join(`
9
+ ${_}`)),o){let w=o.includes("github.com")?"M12,2A10,10 0 0,0 2,12C2,16.42 4.87,20.17 8.84,21.5C9.34,21.58 9.5,21.27 9.5,21C9.5,20.77 9.5,20.14 9.5,19.31C6.73,19.91 6.14,17.97 6.14,17.97C5.68,16.81 5.03,16.5 5.03,16.5C4.12,15.88 5.1,15.9 5.1,15.9C6.1,15.97 6.63,16.93 6.63,16.93C7.5,18.45 8.97,18 9.54,17.76C9.63,17.11 9.89,16.67 10.17,16.42C7.95,16.17 5.62,15.31 5.62,11.5C5.62,10.39 6,9.5 6.65,8.79C6.55,8.54 6.2,7.5 6.75,6.15C6.75,6.15 7.59,5.88 9.5,7.17C10.29,6.95 11.15,6.84 12,6.84C12.85,6.84 13.71,6.95 14.5,7.17C16.41,5.88 17.25,6.15 17.25,6.15C17.8,7.5 17.45,8.54 17.35,8.79C18,9.5 18.38,10.39 18.38,11.5C18.38,15.32 16.04,16.16 13.81,16.41C14.17,16.72 14.5,17.33 14.5,18.26C14.5,19.6 14.5,20.68 14.5,21C14.5,21.27 14.66,21.59 15.17,21.5C19.14,20.16 22,16.42 22,12A10,10 0 0,0 12,2Z":"M6,2H18A2,2 0 0,1 20,4V20A2,2 0 0,1 18,22H6A2,2 0 0,1 4,20V4A2,2 0 0,1 6,2M12.75,13.5C15.5,13.5 16.24,11.47 16.43,10.4C17.34,10.11 18,9.26 18,8.25C18,7 17,6 15.75,6C14.5,6 13.5,7 13.5,8.25C13.5,9.19 14.07,10 14.89,10.33C14.67,11 14,12 12,12C10.62,12 9.66,12.35 9,12.84V8.87C9.87,8.56 10.5,7.73 10.5,6.75C10.5,5.5 9.5,4.5 8.25,4.5C7,4.5 6,5.5 6,6.75C6,7.73 6.63,8.56 7.5,8.87V15.13C6.63,15.44 6,16.27 6,17.25C6,18.5 7,19.5 8.25,19.5C9.5,19.5 10.5,18.5 10.5,17.25C10.5,16.32 9.94,15.5 9.13,15.18C9.41,14.5 10.23,13.5 12.75,13.5M8.25,16.5A0.75,0.75 0 0,1 9,17.25A0.75,0.75 0 0,1 8.25,18A0.75,0.75 0 0,1 7.5,17.25A0.75,0.75 0 0,1 8.25,16.5M8.25,6A0.75,0.75 0 0,1 9,6.75A0.75,0.75 0 0,1 8.25,7.5A0.75,0.75 0 0,1 7.5,6.75A0.75,0.75 0 0,1 8.25,6M15.75,7.5A0.75,0.75 0 0,1 16.5,8.25A0.75,0.75 0 0,1 15.75,9A0.75,0.75 0 0,1 15,8.25A0.75,0.75 0 0,1 15.75,7.5Z";h=h.replace(/([ ]*)<!-- \[Repo\] -->/,(I,C)=>[C,`<a href="${o}">`,' <svg viewBox="0 0 24 24">',` <path fill="currentColor" d="${w}" />`," </svg>"," <span>View Repo</span>","</a>"].join(`
10
+ ${C}`)),h=h.replace(/const repo = '';/,I=>`const repo = '${o}';`),h=h.replace(/const repoComponent = '';/,I=>`const repoComponent = '${r.replace(/\$repo/g,o)}';`),h=h.replace(/const repoIcon = '';/,I=>`const repoIcon = '${w}';`)}i==="dev"&&(h=h.replace(/([ ]*)<!-- \[info\] -->/,(E,_)=>[_,"<p>This page is generated from <code>npm start</code>. To render only specific components use <code>npm start c-button</code>.</p>"].join(`
11
+ ${_}`)));let g=[...u.keys()];return h=h.replace(/([ ]*)const componentMap = new Map\(\);/,(E,_)=>[`${_}const componentMap = new Map();`,...g.map(w=>{let I=u.get(w);return`componentMap.set('${w}', ${JSON.stringify(I)});`})].join(`${_}
12
+ `)),h=h.replace(/([ ]*)const navigation = \[\];/,(E,_)=>`${_}const navigation = ${JSON.stringify(l,null," ")};`),h}(async()=>{let i=[Gt],t=T=>`\x1B[1m${T}\x1B[0m`,e=T=>`\x1B[32m${T}\x1B[0m`,n=T=>`\x1B[31m${T}\x1B[0m`,s=ss(import.meta.url),a=is(s),c=x(a,"..","default"),o="element.config.ts",r=process.cwd(),d="publish",f=es(o);await N(o)||(console.log(n("Missing element.config.ts in root."),"Add with content:"),console.log("export default {"),console.log(" namespace: 'hello',"),console.log("}"),process.exit());let h=await import(f.href),{namespace:l,external:p,title:u,navigation:g,repo:E,repoComponent:_,copy:w}=h.default,I="node_modules",C="dist",R="src",$="components",L=[];if(l){console.log(e("Building app...")),L.push(`./${R}/${$}/${l}/app/app.ts`);let T=await O(x(r,R,$)),W=new Map;for(let S of p??[])(await O(x(r,I,...S.split("/")))).forEach(gt=>{gt!==I&&W.set(gt,S)});i.push(Ut({localNamespaces:T,externalNamespaces:W}));let b="index.html";if(await N(x(r,R,b)))await V(x(r,R,b),x(r,C,b));else{let S=await rs(x(c,b),"utf8");S=S.replace("<title>Default</title>",`<title>${u??"Default"}</title>`),S=S.replace("<namespace-app></namespace-app>",`<${l}-app></${l}-app>`),await Kt(x(r,C,b),S)}let v="favicon.svg";await N(x(r,R,v))?await V(x(r,R,v),x(r,C,v)):await V(x(c,v),x(r,C,v))}else{console.log(e("Building components...")),await Y(x(R,$))||(console.log(n('Missing required "src/components" directory.')),process.exit());let T="playground.html",W="index.html";L.push("playground-entry"),i.push(zt({after:async b=>{let v=await Bt({mode:"dev",rootDir:r,srcDir:R,indexFile:W,defaultDir:c,playgroundFile:T,title:u,repo:E,repoComponent:_,navigation:g,namespaces:b});await Kt(x(r,C,W),v)}}))}let y=await ts({entryPoints:L,outfile:`./${C}/main.js`,bundle:!0,format:"esm",target:"es2024",sourcemap:!0,minify:!1,loader:{".css":"text"},plugins:i});await y.rebuild(),(w??[]).forEach(async({from:T,to:W})=>{let b=W.split(wt),v=T.split(wt);v[v.length-1]===""&&(console.log(n('element.config.ts "copy" "from" should not end with a "/". Ex: "assets" not "assets/".')),process.exit()),b[b.length-1]===""&&(console.log(n('element.config.ts "copy" "to" should not end with a "/". Ex: "assets" not "assets/".')),process.exit()),await Y(x(r,R,...v))?await ns(x(r,R,...v),x(r,C,...b),{recursive:!0}):await N(x(r,R,...v))&&await V(x(r,R,...v),x(r,C,...b))}),jt.watch("src",{ignoreInitial:!0}).on("all",async(T,W)=>{if(!l){let b=W.split(wt);b.length>4&&b[0]===R&&b[1]===$&&(console.log(`Copy "${b.slice(2).join("/")}" to publish/*`),await V(x(r,...b),x(r,d,...b.slice(2)))),(T==="change"||T==="add")&&((w??[]).array.forEach(async({from:v,to:S})=>{let it=b.slice(1).join("/");it.startsWith(v)&&console.log("copy after",it,v,S)}),await Y(x(r,...b)))}try{await y.rebuild()}catch(b){console.error("Rebuild failed:",b)}});let{port:Zt}=await y.serve({servedir:C});console.log(e("Dev server started at"),`localhost:${Zt}`)})();
2279
13
  /*! Bundled license information:
2280
14
 
2281
15
  chokidar/index.js: