@sybz-components/utils 1.0.21 → 1.0.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/vite.cjs CHANGED
@@ -1,13 +1,14 @@
1
1
  'use strict';
2
2
 
3
3
  const node_module = require('node:module');
4
+ const node_fs = require('node:fs');
5
+ const node_path = require('node:path');
4
6
  const codeInspectorPlugin = require('code-inspector-plugin');
5
7
  const tailwindcss = require('@tailwindcss/vite');
6
8
  const vueJsx = require('@vitejs/plugin-vue-jsx');
7
9
  const gitCommitLog = require('./gitCommitLog.cjs');
8
- require('node:child_process');
9
- require('node:fs');
10
- require('node:path');
10
+ const postcss = require('./postcss.cjs');
11
+ const node_child_process = require('node:child_process');
11
12
 
12
13
  var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
13
14
  function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
@@ -15,18 +16,620 @@ function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'defau
15
16
  const tailwindcss__default = /*#__PURE__*/_interopDefaultCompat(tailwindcss);
16
17
  const vueJsx__default = /*#__PURE__*/_interopDefaultCompat(vueJsx);
17
18
 
19
+ const DEFAULT_METHODS$1 = ["log", "info", "warn", "error", "debug"];
20
+ const GO_TO_EDITORS = /* @__PURE__ */ new Set(["code", "code-insiders", "cursor", "vscodium", "windsurf", "trae"]);
21
+ const SOURCE_RE$1 = /\.(?:[cm]?[jt]sx?|vue)$/;
22
+ const SCRIPT_RE$1 = /<script\b[^>]*>([\s\S]*?)<\/script>/g;
23
+ const IDENTIFIER_RE = /[\w$]/;
24
+ const METHOD_RE = /[A-Za-z]/;
25
+ const normalizePath = (value) => value.replace(/\\/g, "/");
26
+ const countNewlines = (value) => {
27
+ let count = 0;
28
+ for (let index = 0; index < value.length; index++) {
29
+ if (value[index] === "\n") count++;
30
+ }
31
+ return count;
32
+ };
33
+ const createMatcher = (matcher) => {
34
+ if (!matcher) return void 0;
35
+ const matchers = Array.isArray(matcher) ? matcher : [matcher];
36
+ return (value) => matchers.some((item) => {
37
+ if (item instanceof RegExp) {
38
+ item.lastIndex = 0;
39
+ return item.test(value);
40
+ }
41
+ return value.includes(item);
42
+ });
43
+ };
44
+ const findConsoleCalls = (code, methods) => {
45
+ const calls = [];
46
+ let state = "code";
47
+ for (let index = 0; index < code.length; index++) {
48
+ const char = code[index];
49
+ const next = code[index + 1];
50
+ if (state === "line-comment") {
51
+ if (char === "\n") state = "code";
52
+ continue;
53
+ }
54
+ if (state === "block-comment") {
55
+ if (char === "*" && next === "/") {
56
+ state = "code";
57
+ index++;
58
+ }
59
+ continue;
60
+ }
61
+ if (state === "single" || state === "double") {
62
+ if (char === "\\") {
63
+ index++;
64
+ continue;
65
+ }
66
+ if (state === "single" && char === "'" || state === "double" && char === '"') state = "code";
67
+ continue;
68
+ }
69
+ if (state === "template") {
70
+ if (char === "\\") {
71
+ index++;
72
+ continue;
73
+ }
74
+ if (char === "`") state = "code";
75
+ continue;
76
+ }
77
+ if (char === "/" && next === "/") {
78
+ state = "line-comment";
79
+ index++;
80
+ continue;
81
+ }
82
+ if (char === "/" && next === "*") {
83
+ state = "block-comment";
84
+ index++;
85
+ continue;
86
+ }
87
+ if (char === "'") {
88
+ state = "single";
89
+ continue;
90
+ }
91
+ if (char === '"') {
92
+ state = "double";
93
+ continue;
94
+ }
95
+ if (char === "`") {
96
+ state = "template";
97
+ continue;
98
+ }
99
+ if (!code.startsWith("console", index)) continue;
100
+ if (index > 0 && (IDENTIFIER_RE.test(code[index - 1]) || code[index - 1] === ".")) continue;
101
+ let cursor = index + 7;
102
+ while (/\s/.test(code[cursor] || "")) cursor++;
103
+ if (code[cursor] === "?" && code[cursor + 1] === ".") cursor += 2;
104
+ else if (code[cursor] === ".") cursor++;
105
+ else continue;
106
+ while (/\s/.test(code[cursor] || "")) cursor++;
107
+ const methodStart = cursor;
108
+ while (METHOD_RE.test(code[cursor] || "")) cursor++;
109
+ const method = code.slice(methodStart, cursor);
110
+ if (!methods.has(method)) continue;
111
+ while (/\s/.test(code[cursor] || "")) cursor++;
112
+ if (code[cursor] !== "(") continue;
113
+ calls.push({ start: index, paren: cursor, method });
114
+ index = cursor;
115
+ }
116
+ return calls;
117
+ };
118
+ const findClosingParen = (code, openIndex) => {
119
+ let state = "code";
120
+ let depth = 0;
121
+ for (let index = openIndex; index < code.length; index++) {
122
+ const char = code[index];
123
+ const next = code[index + 1];
124
+ if (state === "line-comment") {
125
+ if (char === "\n") state = "code";
126
+ continue;
127
+ }
128
+ if (state === "block-comment") {
129
+ if (char === "*" && next === "/") {
130
+ state = "code";
131
+ index++;
132
+ }
133
+ continue;
134
+ }
135
+ if (state === "single") {
136
+ if (char === "\\") index++;
137
+ else if (char === "'") state = "code";
138
+ continue;
139
+ }
140
+ if (state === "double") {
141
+ if (char === "\\") index++;
142
+ else if (char === '"') state = "code";
143
+ continue;
144
+ }
145
+ if (state === "template") {
146
+ if (char === "\\") {
147
+ index++;
148
+ } else if (char === "`") {
149
+ state = "code";
150
+ }
151
+ continue;
152
+ }
153
+ if (char === "'") {
154
+ state = "single";
155
+ continue;
156
+ }
157
+ if (char === '"') {
158
+ state = "double";
159
+ continue;
160
+ }
161
+ if (char === "`") {
162
+ state = "template";
163
+ continue;
164
+ }
165
+ if (char === "/" && next === "/") {
166
+ state = "line-comment";
167
+ index++;
168
+ continue;
169
+ }
170
+ if (char === "/" && next === "*") {
171
+ state = "block-comment";
172
+ index++;
173
+ continue;
174
+ }
175
+ if (char === "(") depth++;
176
+ else if (char === ")") {
177
+ depth--;
178
+ if (depth === 0) return index;
179
+ }
180
+ }
181
+ return -1;
182
+ };
183
+ const createStaticPrefix = (context, line) => {
184
+ var _a;
185
+ const format = (_a = context.options.format) != null ? _a : (source, lineNumber) => `[${source}:${lineNumber}]`;
186
+ try {
187
+ const prefix = format(context.file, line);
188
+ return prefix ? JSON.stringify(prefix) : "";
189
+ } catch (e) {
190
+ return JSON.stringify(`[${context.file}:${line}]`);
191
+ }
192
+ };
193
+ const createJumpPrefix = (context, line) => {
194
+ var _a;
195
+ return `(typeof window === 'undefined' ? '' : window.location.origin) + '/s/${(_a = context.fileId) == null ? void 0 : _a.toString(36)}/${line.toString(36)}'`;
196
+ };
197
+ const injectConsoleSource = (code, context) => {
198
+ const calls = findConsoleCalls(code, context.methods);
199
+ if (!calls.length) return code;
200
+ let result = code;
201
+ for (let index = calls.length - 1; index >= 0; index--) {
202
+ const call = calls[index];
203
+ const line = context.lineOffset + countNewlines(code.slice(0, call.start));
204
+ const prefix = context.jump ? createJumpPrefix(context, line) : createStaticPrefix(context, line);
205
+ if (!prefix) continue;
206
+ const closeParen = findClosingParen(result, call.paren);
207
+ if (closeParen === -1) continue;
208
+ let insertAt = closeParen;
209
+ while (insertAt > call.paren + 1 && /\s/.test(result[insertAt - 1])) insertAt--;
210
+ const hasArguments = result.slice(call.paren + 1, insertAt).trim().length > 0;
211
+ const before = result.slice(0, insertAt);
212
+ const separator = hasArguments ? before.endsWith(",") ? " " : ", " : "";
213
+ result = result.slice(0, insertAt) + separator + prefix + result.slice(insertAt);
214
+ }
215
+ return result;
216
+ };
217
+ const injectVueSource = (code, context) => {
218
+ let output = "";
219
+ let cursor = 0;
220
+ let changed = false;
221
+ SCRIPT_RE$1.lastIndex = 0;
222
+ let match;
223
+ while (match = SCRIPT_RE$1.exec(code)) {
224
+ const scriptTag = match[0];
225
+ const content = match[1];
226
+ const contentStart = match.index + scriptTag.indexOf(">") + 1;
227
+ const contentEnd = contentStart + content.length;
228
+ const lineOffset = countNewlines(code.slice(0, contentStart)) + 1;
229
+ const transformed = injectConsoleSource(content, { ...context, lineOffset });
230
+ output += code.slice(cursor, contentStart) + transformed;
231
+ cursor = contentEnd;
232
+ if (transformed !== content) changed = true;
233
+ }
234
+ if (!changed) return code;
235
+ return output + code.slice(cursor);
236
+ };
237
+ const launchEditor = (editor, file, line) => new Promise((resolvePromise, reject) => {
238
+ const position = `${file}:${line}:1`;
239
+ const args = GO_TO_EDITORS.has(editor) ? ["-g", position] : [position];
240
+ try {
241
+ const child = node_child_process.spawn(editor, args, {
242
+ detached: true,
243
+ stdio: "ignore",
244
+ windowsHide: true,
245
+ shell: process.platform === "win32"
246
+ });
247
+ child.once("spawn", () => {
248
+ child.unref();
249
+ resolvePromise();
250
+ });
251
+ child.once("error", reject);
252
+ } catch (error) {
253
+ reject(error);
254
+ }
255
+ });
256
+ const createOpenMiddleware = (root, editor, fileIds) => {
257
+ const rootPrefix = root.endsWith(node_path.sep) ? root : `${root}${node_path.sep}`;
258
+ return (request, response) => {
259
+ const [idPart, linePart] = (request.url || "/").replace(/^\/+/, "").split("/");
260
+ const file = fileIds.get(parseInt(idPart, 36)) || "";
261
+ const line = Math.max(1, parseInt(linePart, 36) || 1);
262
+ const absolutePath = node_path.resolve(root, file);
263
+ if (!file || !absolutePath.startsWith(rootPrefix) || !node_fs.existsSync(absolutePath)) {
264
+ response.statusCode = 404;
265
+ response.end("Source file not found");
266
+ return;
267
+ }
268
+ launchEditor(editor, absolutePath, line).then(() => {
269
+ response.statusCode = 200;
270
+ response.setHeader("Content-Type", "text/html; charset=utf-8");
271
+ response.end(
272
+ `<!doctype html><meta charset="utf-8"><title>Sybz</title><body><script>try { window.close(); } catch (error) {} document.body.textContent = ${JSON.stringify(
273
+ `\u5DF2\u6253\u5F00 ${file}:${line}\uFF08${editor}\uFF09`
274
+ )};<\/script></body>`
275
+ );
276
+ }).catch((error) => {
277
+ response.statusCode = 500;
278
+ response.setHeader("Content-Type", "text/plain; charset=utf-8");
279
+ response.end(`\u65E0\u6CD5\u6253\u5F00\u7F16\u8F91\u5668 ${editor}\uFF1A${String(error)}`);
280
+ });
281
+ };
282
+ };
283
+ const createConsoleSource = (options = {}) => {
284
+ var _a, _b;
285
+ let root = process.cwd();
286
+ let isServe = false;
287
+ const editor = (_a = options.editor) != null ? _a : "code";
288
+ const methods = new Set((_b = options.methods) != null ? _b : DEFAULT_METHODS$1);
289
+ const include = createMatcher(options.include);
290
+ const exclude = createMatcher(options.exclude);
291
+ const fileIds = /* @__PURE__ */ new Map();
292
+ const fileIdByName = /* @__PURE__ */ new Map();
293
+ let nextFileId = 1;
294
+ const getFileId = (file) => {
295
+ const cached = fileIdByName.get(file);
296
+ if (cached) return cached;
297
+ const id = nextFileId++;
298
+ fileIdByName.set(file, id);
299
+ fileIds.set(id, file);
300
+ return id;
301
+ };
302
+ return {
303
+ name: "sybz:console-source",
304
+ apply: options.build ? void 0 : "serve",
305
+ enforce: "pre",
306
+ configResolved(config) {
307
+ root = config.root;
308
+ isServe = config.command === "serve";
309
+ },
310
+ configureServer(server) {
311
+ if (options.jump === false) return;
312
+ server.middlewares.use("/s", createOpenMiddleware(root, editor, fileIds));
313
+ },
314
+ transform(code, id) {
315
+ if (!code) return;
316
+ if (!id || id.startsWith("\0") || id.startsWith("virtual:")) return;
317
+ const normalizedId = normalizePath(id);
318
+ if (normalizedId.includes("/node_modules/") || normalizedId.includes("/.vitepress/cache/") || normalizedId.includes("/.vitepress/dist/")) {
319
+ return;
320
+ }
321
+ const cleanId = id.split("?")[0];
322
+ if (!cleanId || !node_path.isAbsolute(cleanId) || !SOURCE_RE$1.test(cleanId)) return;
323
+ if (cleanId.includes(".d.ts")) return;
324
+ const file = normalizePath(node_path.relative(root, cleanId));
325
+ if (!file || file.startsWith("..") || file.startsWith("/")) return;
326
+ if (include && !include(file) && !include(id)) return;
327
+ if ((exclude == null ? void 0 : exclude(file)) || (exclude == null ? void 0 : exclude(id))) return;
328
+ const jump = isServe && options.jump !== false;
329
+ const context = {
330
+ file,
331
+ fileId: jump ? getFileId(file) : void 0,
332
+ lineOffset: 1,
333
+ methods,
334
+ options,
335
+ jump
336
+ };
337
+ const transformed = cleanId.endsWith(".vue") ? injectVueSource(code, context) : injectConsoleSource(code, context);
338
+ if (transformed === code) return;
339
+ return { code: transformed, map: null };
340
+ }
341
+ };
342
+ };
343
+
344
+ const DEFAULT_METHODS = [
345
+ "log",
346
+ "info",
347
+ "warn",
348
+ "error",
349
+ "debug",
350
+ "trace",
351
+ "dir",
352
+ "dirxml",
353
+ "table",
354
+ "group",
355
+ "groupCollapsed",
356
+ "groupEnd",
357
+ "time",
358
+ "timeEnd",
359
+ "timeLog",
360
+ "count",
361
+ "countReset",
362
+ "assert",
363
+ "clear",
364
+ "profile",
365
+ "profileEnd"
366
+ ];
367
+ const DEFAULT_PRESERVE = ["[build git info]"];
368
+ const DEFAULT_PRESERVE_COMMENT = "@sybz-keep-console";
369
+ const SOURCE_RE = /\.(?:[cm]?[jt]sx?|vue)$/;
370
+ const SCRIPT_RE = /<script\b[^>]*>([\s\S]*?)<\/script>/g;
371
+ const matchesPattern = (source, pattern) => {
372
+ if (typeof pattern === "string") return source.includes(pattern);
373
+ pattern.lastIndex = 0;
374
+ return pattern.test(source);
375
+ };
376
+ const hasPreserveComment = (code, start, end, marker) => {
377
+ const lineStart = code.lastIndexOf("\n", start) + 1;
378
+ const lineEnd = code.indexOf("\n", end);
379
+ const currentLine = code.slice(lineStart, lineEnd === -1 ? code.length : lineEnd);
380
+ if (currentLine.includes(marker)) return true;
381
+ if (lineStart <= 1) return false;
382
+ const previousLineEnd = lineStart - 1;
383
+ const previousLineStart = code.lastIndexOf("\n", previousLineEnd - 1) + 1;
384
+ return code.slice(previousLineStart, previousLineEnd).includes(marker);
385
+ };
386
+ const removeConsoleCalls = (code, context) => {
387
+ const calls = findConsoleCalls(code, context.methods);
388
+ if (!calls.length) return code;
389
+ let result = code;
390
+ for (let index = calls.length - 1; index >= 0; index--) {
391
+ const call = calls[index];
392
+ const closeParen = findClosingParen(result, call.paren);
393
+ if (closeParen === -1 || context.preserveMethods.has(call.method)) continue;
394
+ const source = result.slice(call.start, closeParen + 1);
395
+ if (context.preserve.some((pattern) => matchesPattern(source, pattern))) continue;
396
+ if (context.comment && hasPreserveComment(result, call.start, closeParen, context.comment)) continue;
397
+ result = result.slice(0, call.start) + "void 0" + result.slice(closeParen + 1);
398
+ }
399
+ return result;
400
+ };
401
+ const removeConsoleFromVue = (code, context) => {
402
+ let output = "";
403
+ let cursor = 0;
404
+ let changed = false;
405
+ SCRIPT_RE.lastIndex = 0;
406
+ let match;
407
+ while (match = SCRIPT_RE.exec(code)) {
408
+ const scriptTag = match[0];
409
+ const content = match[1];
410
+ const contentStart = match.index + scriptTag.indexOf(">") + 1;
411
+ const transformed = removeConsoleCalls(content, context);
412
+ output += code.slice(cursor, contentStart) + transformed;
413
+ cursor = contentStart + content.length;
414
+ if (transformed !== content) changed = true;
415
+ }
416
+ if (!changed) return code;
417
+ return output + code.slice(cursor);
418
+ };
419
+ const createRemoveConsole = (options = {}) => {
420
+ var _a, _b, _c, _d;
421
+ let root = process.cwd();
422
+ const methods = new Set((_a = options.methods) != null ? _a : DEFAULT_METHODS);
423
+ const preserveMethods = new Set((_b = options.preserveMethods) != null ? _b : []);
424
+ const preserve = [...DEFAULT_PRESERVE, ...(_c = options.preserve) != null ? _c : []];
425
+ const comment = options.preserveComment === false ? false : (_d = options.preserveComment) != null ? _d : DEFAULT_PRESERVE_COMMENT;
426
+ const include = createMatcher(options.include);
427
+ const exclude = createMatcher(options.exclude);
428
+ return {
429
+ name: "sybz:remove-console",
430
+ apply: "build",
431
+ enforce: "pre",
432
+ configResolved(config) {
433
+ root = config.root;
434
+ },
435
+ transform(code, id) {
436
+ if (!code) return;
437
+ if (!id || id.startsWith("\0") || id.startsWith("virtual:")) return;
438
+ const normalizedId = normalizePath(id);
439
+ if (!options.transformNodeModules && normalizedId.includes("/node_modules/")) return;
440
+ if (normalizedId.includes("/.vitepress/cache/") || normalizedId.includes("/.vitepress/dist/")) return;
441
+ const cleanId = id.split("?")[0];
442
+ if (!cleanId || !node_path.isAbsolute(cleanId) || !SOURCE_RE.test(cleanId)) return;
443
+ if (cleanId.includes(".d.ts")) return;
444
+ const file = normalizePath(node_path.relative(root, cleanId));
445
+ if (!file || file.startsWith("..") || file.startsWith("/")) return;
446
+ if (include && !include(file) && !include(id)) return;
447
+ if ((exclude == null ? void 0 : exclude(file)) || (exclude == null ? void 0 : exclude(id))) return;
448
+ const context = { methods, preserveMethods, preserve, comment };
449
+ const transformed = cleanId.endsWith(".vue") ? removeConsoleFromVue(code, context) : removeConsoleCalls(code, context);
450
+ if (transformed === code) return;
451
+ return { code: transformed, map: null };
452
+ }
453
+ };
454
+ };
455
+
456
+ const POSITION_STYLES = {
457
+ "top-left": "top:24px;left:24px;",
458
+ "top-right": "top:24px;right:24px;",
459
+ "bottom-left": "bottom:24px;left:24px;",
460
+ "bottom-right": "bottom:24px;right:24px;"
461
+ };
462
+ const formatBuildTime$1 = (date) => {
463
+ const pad = (value) => String(value).padStart(2, "0");
464
+ return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())} ${pad(date.getHours())}:${pad(
465
+ date.getMinutes()
466
+ )}:${pad(date.getSeconds())}`;
467
+ };
468
+ const createVersion = () => `${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 8)}`;
469
+ const joinBase = (base, file) => {
470
+ if (/^(?:[a-z]+:)?\/\//i.test(file) || file.startsWith("/")) return file;
471
+ const normalizedBase = base.endsWith("/") ? base : `${base}/`;
472
+ return `${normalizedBase}${file.replace(/^\.?\//, "")}`;
473
+ };
474
+ const createClientScript = (options) => {
475
+ var _a;
476
+ return `(function () {
477
+ var currentVersion = window.__SYBZ_VERSION__;
478
+ if (!currentVersion || typeof window.fetch !== 'function') return;
479
+ var versionUrl = ${JSON.stringify(options.versionUrl)};
480
+ var interval = ${JSON.stringify(options.interval)};
481
+ var text = ${JSON.stringify(options.text)};
482
+ var reloadText = ${JSON.stringify(options.reloadText)};
483
+ var positionStyle = ${JSON.stringify((_a = POSITION_STYLES[options.position]) != null ? _a : POSITION_STYLES["bottom-right"])};
484
+ var prompt = ${JSON.stringify(options.prompt)};
485
+ var eventName = ${JSON.stringify(options.eventName)};
486
+ var notified = false;
487
+
488
+ function showUpdate() {
489
+ if (!document.body) return;
490
+
491
+ var box = document.createElement('div');
492
+ box.setAttribute('role', 'status');
493
+ box.setAttribute('aria-live', 'polite');
494
+ box.style.cssText = 'position:fixed;' + positionStyle + 'box-sizing:border-box;z-index:99999;display:flex;align-items:center;gap:12px;padding:12px 16px;border:1px solid #e5e7eb;border-radius:10px;background:#fff;color:#1f2937;box-shadow:0 8px 24px rgba(15,23,42,.18);font:14px/1.5 -apple-system,BlinkMacSystemFont,"Segoe UI",sans-serif;';
495
+
496
+ var label = document.createElement('span');
497
+ label.textContent = text;
498
+
499
+ var button = document.createElement('button');
500
+ button.type = 'button';
501
+ button.textContent = reloadText;
502
+ button.style.cssText = 'flex:none;box-sizing:border-box;width:auto;border:0;border-radius:6px;background:#2f6fed;color:#fff;padding:8px 14px;font:inherit;cursor:pointer;';
503
+ button.onclick = function () { window.location.reload(); };
504
+
505
+ box.appendChild(label);
506
+ box.appendChild(button);
507
+ document.body.appendChild(box);
508
+ }
509
+
510
+ function notify(data) {
511
+ if (notified) return;
512
+ notified = true;
513
+
514
+ var detail = { version: data.version, currentVersion: currentVersion };
515
+ var event;
516
+ try {
517
+ event = new CustomEvent(eventName, { detail: detail, cancelable: true });
518
+ } catch (error) {
519
+ event = document.createEvent('CustomEvent');
520
+ event.initCustomEvent(eventName, false, true, detail);
521
+ }
522
+
523
+ var handled = false;
524
+ try { handled = !window.dispatchEvent(event); } catch (error) {}
525
+ if (!handled && prompt) showUpdate();
526
+ }
527
+
528
+ function checkVersion() {
529
+ if (notified) return;
530
+ var separator = versionUrl.indexOf('?') === -1 ? '?' : '&';
531
+ window.fetch(versionUrl + separator + 't=' + Date.now(), { cache: 'no-store' })
532
+ .then(function (response) { return response.ok ? response.json() : null; })
533
+ .then(function (data) {
534
+ if (data && data.version && data.version !== currentVersion) notify(data);
535
+ })
536
+ .catch(function () {});
537
+ }
538
+
539
+ window.setInterval(checkVersion, interval);
540
+ window.setTimeout(checkVersion, 1000);
541
+ window.addEventListener('focus', checkVersion);
542
+ document.addEventListener('visibilitychange', function () {
543
+ if (!document.hidden) checkVersion();
544
+ });
545
+ })();`;
546
+ };
547
+ const createVersionCheck = (options = {}) => {
548
+ var _a, _b;
549
+ let version = (_a = options.version) != null ? _a : createVersion();
550
+ let buildTime = formatBuildTime$1(/* @__PURE__ */ new Date());
551
+ const interval = Math.max(1e3, Number(options.interval) || 5 * 60 * 1e3);
552
+ const versionFile = ((_b = options.versionFile) != null ? _b : "version.json").replace(/^\/+/, "");
553
+ let config;
554
+ let disabled = false;
555
+ return {
556
+ name: "sybz:version-check",
557
+ apply: "build",
558
+ configResolved(resolvedConfig) {
559
+ var _a2, _b2;
560
+ config = resolvedConfig;
561
+ disabled = Boolean(((_a2 = config.build) == null ? void 0 : _a2.lib) || ((_b2 = config.build) == null ? void 0 : _b2.ssr));
562
+ },
563
+ buildStart() {
564
+ if (!options.version) version = createVersion();
565
+ buildTime = formatBuildTime$1(/* @__PURE__ */ new Date());
566
+ },
567
+ generateBundle() {
568
+ if (disabled) return;
569
+ this.emitFile({
570
+ type: "asset",
571
+ fileName: versionFile,
572
+ source: JSON.stringify({ version, buildTime })
573
+ });
574
+ },
575
+ transformIndexHtml() {
576
+ var _a2, _b2, _c, _d, _e;
577
+ if (disabled) return;
578
+ const versionUrl = (_a2 = options.versionUrl) != null ? _a2 : joinBase((config == null ? void 0 : config.base) || "/", versionFile);
579
+ return [
580
+ {
581
+ tag: "meta",
582
+ attrs: { name: "sybz-version", content: version },
583
+ injectTo: "head"
584
+ },
585
+ {
586
+ tag: "script",
587
+ children: `window.__SYBZ_VERSION__ = ${JSON.stringify(version)};`,
588
+ injectTo: "head"
589
+ },
590
+ {
591
+ tag: "script",
592
+ children: createClientScript({
593
+ versionUrl,
594
+ interval,
595
+ text: (_b2 = options.text) != null ? _b2 : "\u53D1\u73B0\u65B0\u7248\u672C\uFF0C\u8BF7\u5237\u65B0\u9875\u9762",
596
+ reloadText: (_c = options.reloadText) != null ? _c : "\u5237\u65B0",
597
+ position: (_d = options.position) != null ? _d : "bottom-right",
598
+ prompt: options.prompt !== false,
599
+ eventName: (_e = options.eventName) != null ? _e : "sybz:version-update"
600
+ }),
601
+ injectTo: "body"
602
+ }
603
+ ];
604
+ }
605
+ };
606
+ };
607
+
18
608
  const require2 = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('vite.cjs', document.baseURI).href)));
19
609
  const virtualTailwindId = "virtual:sybz-tailwind";
20
610
  const resolvedVirtualTailwindId = `\0${virtualTailwindId}`;
21
- const createTailwindEntry = () => {
611
+ const virtualTailwindNoPreflightId = "virtual:sybz-tailwind-no-preflight.css";
612
+ const resolvedVirtualTailwindNoPreflightId = `\0${virtualTailwindNoPreflightId}`;
613
+ const createTailwindEntry = (preflight = false) => {
22
614
  const tailwindCssPath = require2.resolve("tailwindcss/index.css");
615
+ const tailwindThemePath = require2.resolve("tailwindcss/theme.css");
616
+ const tailwindUtilitiesPath = require2.resolve("tailwindcss/utilities.css");
23
617
  return {
24
618
  name: "sybz-tailwind-entry",
25
619
  resolveId(id) {
26
620
  if (id === virtualTailwindId) return resolvedVirtualTailwindId;
621
+ if (id === virtualTailwindNoPreflightId) return resolvedVirtualTailwindNoPreflightId;
27
622
  },
28
623
  load(id) {
29
- if (id === resolvedVirtualTailwindId) return `import ${JSON.stringify(tailwindCssPath)}`;
624
+ if (id === resolvedVirtualTailwindId) {
625
+ return preflight ? `import ${JSON.stringify(tailwindCssPath)}` : `import ${JSON.stringify(virtualTailwindNoPreflightId)}`;
626
+ }
627
+ if (id === resolvedVirtualTailwindNoPreflightId) {
628
+ return [
629
+ `@import ${JSON.stringify(tailwindThemePath)} layer(theme);`,
630
+ `@import ${JSON.stringify(tailwindUtilitiesPath)} layer(utilities);`
631
+ ].join("\n");
632
+ }
30
633
  },
31
634
  transformIndexHtml: {
32
635
  order: "pre",
@@ -73,14 +676,79 @@ const createBuildTime = (metaName = "buildTime") => {
73
676
  }
74
677
  };
75
678
  };
679
+ const POSTCSS_CONFIG_FILES = ["postcss.config.js", "postcss.config.cjs", "postcss.config.mjs", "postcss.config.ts"];
680
+ const loadLegacyPlugin = (options) => {
681
+ let mod;
682
+ try {
683
+ mod = require2("@vitejs/plugin-legacy");
684
+ } catch (e) {
685
+ throw new Error(
686
+ "[sybz-components] \u542F\u7528 compat \u9700\u8981\u5B89\u88C5\u4E0E\u5F53\u524D Vite \u7248\u672C\u5339\u914D\u7684 @vitejs/plugin-legacy\uFF0C\u4F8B\u5982\uFF1Apnpm add -D @vitejs/plugin-legacy"
687
+ );
688
+ }
689
+ const factory = typeof mod === "function" ? mod : mod.default;
690
+ if (!factory) {
691
+ throw new Error("[sybz-components] @vitejs/plugin-legacy \u5BFC\u51FA\u683C\u5F0F\u5F02\u5E38\uFF0C\u8BF7\u68C0\u67E5\u5B89\u88C5\u7248\u672C\u3002");
692
+ }
693
+ return factory(options);
694
+ };
695
+ const createCompatPlugin = (options) => ({
696
+ name: "sybz:compat",
697
+ enforce: "post",
698
+ config(config) {
699
+ var _a, _b, _c, _d;
700
+ if ((_a = config.build) == null ? void 0 : _a.lib) return;
701
+ const buildTarget = (_b = options.buildTarget) != null ? _b : "chrome60";
702
+ const result = {
703
+ build: {
704
+ target: buildTarget,
705
+ cssTarget: buildTarget
706
+ },
707
+ optimizeDeps: {
708
+ esbuildOptions: { target: buildTarget }
709
+ }
710
+ };
711
+ if (options.postcss !== false) {
712
+ if ((_c = config.css) == null ? void 0 : _c.postcss) {
713
+ console.warn(
714
+ "[sybz-components] \u5DF2\u5B58\u5728 css.postcss \u914D\u7F6E\uFF0C\u5DF2\u8DF3\u8FC7\u81EA\u52A8 PostCSS \u6CE8\u5165\uFF1B\u8BF7\u624B\u52A8\u5408\u5E76 createSybzCompatPostcssPlugins()\u3002"
715
+ );
716
+ } else {
717
+ const root = (_d = config.root) != null ? _d : process.cwd();
718
+ const hasPostcssConfig = POSTCSS_CONFIG_FILES.some((file) => node_fs.existsSync(node_path.resolve(root, file)));
719
+ if (hasPostcssConfig) {
720
+ console.warn(
721
+ "[sybz-components] \u68C0\u6D4B\u5230 postcss.config\uFF0C\u5DF2\u8DF3\u8FC7\u81EA\u52A8 PostCSS \u6CE8\u5165\uFF1B\u8BF7\u624B\u52A8\u5408\u5E76 createSybzCompatPostcssPlugins()\u3002"
722
+ );
723
+ } else {
724
+ result.css = {
725
+ postcss: {
726
+ plugins: postcss.createSybzCompatPostcssPlugins({ browsers: options.browsers })
727
+ }
728
+ };
729
+ }
730
+ }
731
+ }
732
+ return result;
733
+ }
734
+ });
76
735
  const sybzVitePlugins = (options = {}) => {
736
+ var _a;
77
737
  const plugins = [];
78
738
  if (options.vueJsx !== false) {
79
739
  plugins.push(vueJsx__default(typeof options.vueJsx === "object" ? options.vueJsx : {}));
80
740
  }
81
741
  if (options.tailwind !== false) {
82
742
  plugins.push(...tailwindcss__default(typeof options.tailwind === "object" ? options.tailwind : {}));
83
- if (options.tailwindCss !== false) plugins.push(createTailwindEntry());
743
+ if (options.tailwindCss !== false) plugins.push(createTailwindEntry(options.tailwindPreflight === true));
744
+ }
745
+ if (options.consoleSource) {
746
+ const consoleSourceOptions = typeof options.consoleSource === "object" ? options.consoleSource : {};
747
+ const inspectorOptions = typeof options.codeInspector === "object" ? options.codeInspector : void 0;
748
+ plugins.push(createConsoleSource({ editor: inspectorOptions == null ? void 0 : inspectorOptions.editor, ...consoleSourceOptions }));
749
+ }
750
+ if (options.removeConsole !== false) {
751
+ plugins.push(createRemoveConsole(typeof options.removeConsole === "object" ? options.removeConsole : {}));
84
752
  }
85
753
  if (options.codeInspector !== false) {
86
754
  plugins.push(createCodeInspector(typeof options.codeInspector === "object" ? options.codeInspector : {}));
@@ -91,6 +759,18 @@ const sybzVitePlugins = (options = {}) => {
91
759
  if (options.buildTime !== false) {
92
760
  plugins.push(createBuildTime(typeof options.buildTime === "object" ? options.buildTime.metaName : void 0));
93
761
  }
762
+ if (options.versionCheck !== false) {
763
+ plugins.push(createVersionCheck(typeof options.versionCheck === "object" ? options.versionCheck : {}));
764
+ }
765
+ if (options.compat) {
766
+ const compat = typeof options.compat === "object" ? options.compat : {};
767
+ plugins.push(createCompatPlugin(compat));
768
+ if (compat.legacy !== false) {
769
+ const legacy = compat.legacy && typeof compat.legacy !== "boolean" ? compat.legacy : loadLegacyPlugin({ targets: (_a = compat.targets) != null ? _a : postcss.SYBZ_COMPAT_BROWSERS });
770
+ if (Array.isArray(legacy)) plugins.push(...legacy);
771
+ else plugins.push(legacy);
772
+ }
773
+ }
94
774
  return plugins;
95
775
  };
96
776