@lark-apaas/coding-preset-vite-react 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (93) hide show
  1. package/LICENSE +13 -0
  2. package/lib/index.d.ts +52 -0
  3. package/lib/index.d.ts.map +1 -0
  4. package/lib/index.js +410 -0
  5. package/lib/index.js.map +1 -0
  6. package/lib/plugins/capabilities.d.ts +23 -0
  7. package/lib/plugins/capabilities.d.ts.map +1 -0
  8. package/lib/plugins/capabilities.js +151 -0
  9. package/lib/plugins/capabilities.js.map +1 -0
  10. package/lib/plugins/dev-logs.d.ts +44 -0
  11. package/lib/plugins/dev-logs.d.ts.map +1 -0
  12. package/lib/plugins/dev-logs.js +544 -0
  13. package/lib/plugins/dev-logs.js.map +1 -0
  14. package/lib/plugins/error-overlay.d.ts +19 -0
  15. package/lib/plugins/error-overlay.d.ts.map +1 -0
  16. package/lib/plugins/error-overlay.js +136 -0
  17. package/lib/plugins/error-overlay.js.map +1 -0
  18. package/lib/plugins/fonts-mirror.d.ts +14 -0
  19. package/lib/plugins/fonts-mirror.d.ts.map +1 -0
  20. package/lib/plugins/fonts-mirror.js +70 -0
  21. package/lib/plugins/fonts-mirror.js.map +1 -0
  22. package/lib/plugins/health.d.ts +19 -0
  23. package/lib/plugins/health.d.ts.map +1 -0
  24. package/lib/plugins/health.js +36 -0
  25. package/lib/plugins/health.js.map +1 -0
  26. package/lib/plugins/hmr-timing.d.ts +13 -0
  27. package/lib/plugins/hmr-timing.d.ts.map +1 -0
  28. package/lib/plugins/hmr-timing.js +93 -0
  29. package/lib/plugins/hmr-timing.js.map +1 -0
  30. package/lib/plugins/html-minify.d.ts +18 -0
  31. package/lib/plugins/html-minify.d.ts.map +1 -0
  32. package/lib/plugins/html-minify.js +100 -0
  33. package/lib/plugins/html-minify.js.map +1 -0
  34. package/lib/plugins/module-alias.d.ts +12 -0
  35. package/lib/plugins/module-alias.d.ts.map +1 -0
  36. package/lib/plugins/module-alias.js +78 -0
  37. package/lib/plugins/module-alias.js.map +1 -0
  38. package/lib/plugins/og-meta.d.ts +21 -0
  39. package/lib/plugins/og-meta.d.ts.map +1 -0
  40. package/lib/plugins/og-meta.js +60 -0
  41. package/lib/plugins/og-meta.js.map +1 -0
  42. package/lib/plugins/polyfill.d.ts +11 -0
  43. package/lib/plugins/polyfill.d.ts.map +1 -0
  44. package/lib/plugins/polyfill.js +140 -0
  45. package/lib/plugins/polyfill.js.map +1 -0
  46. package/lib/plugins/routes.d.ts +26 -0
  47. package/lib/plugins/routes.d.ts.map +1 -0
  48. package/lib/plugins/routes.js +265 -0
  49. package/lib/plugins/routes.js.map +1 -0
  50. package/lib/plugins/slardar.d.ts +24 -0
  51. package/lib/plugins/slardar.d.ts.map +1 -0
  52. package/lib/plugins/slardar.js +74 -0
  53. package/lib/plugins/slardar.js.map +1 -0
  54. package/lib/plugins/static-assets.d.ts +10 -0
  55. package/lib/plugins/static-assets.d.ts.map +1 -0
  56. package/lib/plugins/static-assets.js +297 -0
  57. package/lib/plugins/static-assets.js.map +1 -0
  58. package/lib/plugins/view-context.d.ts +22 -0
  59. package/lib/plugins/view-context.d.ts.map +1 -0
  60. package/lib/plugins/view-context.js +132 -0
  61. package/lib/plugins/view-context.js.map +1 -0
  62. package/lib/plugins/vite-client-patch.d.ts +4 -0
  63. package/lib/plugins/vite-client-patch.d.ts.map +1 -0
  64. package/lib/plugins/vite-client-patch.js +37 -0
  65. package/lib/plugins/vite-client-patch.js.map +1 -0
  66. package/lib/plugins/ws-watchdog.d.ts +22 -0
  67. package/lib/plugins/ws-watchdog.d.ts.map +1 -0
  68. package/lib/plugins/ws-watchdog.js +103 -0
  69. package/lib/plugins/ws-watchdog.js.map +1 -0
  70. package/lib/polyfills/index.d.ts +15 -0
  71. package/lib/polyfills/index.d.ts.map +1 -0
  72. package/lib/polyfills/index.js +36 -0
  73. package/lib/polyfills/index.js.map +1 -0
  74. package/lib/utils/normalize-base-path.d.ts +37 -0
  75. package/lib/utils/normalize-base-path.d.ts.map +1 -0
  76. package/lib/utils/normalize-base-path.js +57 -0
  77. package/lib/utils/normalize-base-path.js.map +1 -0
  78. package/lib/utils/snapdom-proxy.d.ts +12 -0
  79. package/lib/utils/snapdom-proxy.d.ts.map +1 -0
  80. package/lib/utils/snapdom-proxy.js +75 -0
  81. package/lib/utils/snapdom-proxy.js.map +1 -0
  82. package/package.json +63 -0
  83. package/src/empty.css +1 -0
  84. package/src/inspector-stub.js +6 -0
  85. package/src/module-alias/clsx.mjs +8 -0
  86. package/src/module-alias/echarts-for-react.mjs +130 -0
  87. package/src/module-alias/echarts.mjs +43 -0
  88. package/src/module-alias/registry_echarts_theme.mjs +390 -0
  89. package/src/overlay/components.js +94 -0
  90. package/src/overlay/index.js +443 -0
  91. package/src/overlay/vite-client.js +555 -0
  92. package/src/polyfills/index.ts +35 -0
  93. package/src/runtime/ws-watchdog-client.mjs +148 -0
@@ -0,0 +1,103 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.wsWatchdogPlugin = wsWatchdogPlugin;
37
+ const fs = __importStar(require("node:fs"));
38
+ const path = __importStar(require("node:path"));
39
+ const CLIENT_RUNTIME_PATH = '/@ws-watchdog.js';
40
+ function resolveClientRuntimePath() {
41
+ const candidates = [
42
+ path.resolve(__dirname, '../../src/runtime/ws-watchdog-client.mjs'), // lib/plugins → src/runtime
43
+ path.resolve(__dirname, '../runtime/ws-watchdog-client.mjs'), // src/plugins → src/runtime
44
+ ];
45
+ return candidates.find((p) => fs.existsSync(p)) ?? null;
46
+ }
47
+ function wsWatchdogPlugin(options = {}) {
48
+ const { pingEvent = 'ws-watchdog:ping', pongEvent = 'ws-watchdog:pong', clientBasePath = '', } = options;
49
+ const watchdogPath = clientBasePath + CLIENT_RUNTIME_PATH;
50
+ return {
51
+ name: 'miaoda-ws-watchdog',
52
+ apply: 'serve',
53
+ configureServer(server) {
54
+ server.ws.on(pingEvent, (data, client) => {
55
+ if (typeof data?.t !== 'number')
56
+ return;
57
+ client.send(pongEvent, { echo: data.t });
58
+ });
59
+ // 直出 plain .mjs,跳过 server.transformRequest;no-cache 让升降级即时生效
60
+ server.middlewares.use((req, res, next) => {
61
+ if (req.url !== watchdogPath)
62
+ return next();
63
+ const clientPath = resolveClientRuntimePath();
64
+ if (!clientPath) {
65
+ res.statusCode = 500;
66
+ res.end('// ws-watchdog client not found');
67
+ return;
68
+ }
69
+ try {
70
+ let code = fs.readFileSync(clientPath, 'utf-8');
71
+ const env = {
72
+ 'process.env.FORCE_FRAMEWORK_DOMAIN_MAIN': JSON.stringify(process.env.FORCE_FRAMEWORK_DOMAIN_MAIN ?? ''),
73
+ 'process.env.CLIENT_BASE_PATH': JSON.stringify(clientBasePath),
74
+ };
75
+ for (const [k, v] of Object.entries(env)) {
76
+ code = code.replace(new RegExp(k.replace(/\./g, '\\.'), 'g'), v);
77
+ }
78
+ res.setHeader('Content-Type', 'application/javascript');
79
+ res.setHeader('Cache-Control', 'no-cache');
80
+ res.end(code);
81
+ }
82
+ catch (e) {
83
+ console.error('[miaoda-ws-watchdog] serve failed:', e);
84
+ res.statusCode = 500;
85
+ res.end(`// error: ${e instanceof Error ? e.message : String(e)}`);
86
+ }
87
+ });
88
+ },
89
+ transformIndexHtml() {
90
+ const tags = [
91
+ {
92
+ tag: 'script',
93
+ attrs: { type: 'module', src: watchdogPath },
94
+ // head-prepend:尽早注入,避免业务代码先和外壳完成握手才出 watchdog
95
+ injectTo: 'head-prepend',
96
+ },
97
+ ];
98
+ return tags;
99
+ },
100
+ };
101
+ }
102
+ exports.default = wsWatchdogPlugin;
103
+ //# sourceMappingURL=ws-watchdog.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ws-watchdog.js","sourceRoot":"","sources":["../../src/plugins/ws-watchdog.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiCA,4CA6DC;AA9FD,4CAA8B;AAC9B,gDAAkC;AAGlC,MAAM,mBAAmB,GAAG,kBAAkB,CAAC;AAqB/C,SAAS,wBAAwB;IAC/B,MAAM,UAAU,GAAG;QACjB,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,0CAA0C,CAAC,EAAE,4BAA4B;QACjG,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,mCAAmC,CAAC,EAAU,4BAA4B;KACnG,CAAC;IACF,OAAO,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC;AAC1D,CAAC;AAED,SAAgB,gBAAgB,CAAC,UAAm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AAM,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;wBACzC,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC;oBACnE,CAAC;oBACD,GAAG,CAAC,SAAS,CAAC,cAAc,EAAE,wBAAwB,CAAC,CAAC;oBACxD,GAAG,CAAC,SAAS,CAAC,eAAe,EAAE,UAAU,CAAC,CAAC;oBAC3C,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;gBAChB,CAAC;gBAAC,OAAO,CAAC,EAAE,CAAC;oBACX,OAAO,CAAC,KAAK,CAAC,oCAAoC,EAAE,CAAC,CAAC,CAAC;oBACvD,GAAG,CAAC,UAAU,GAAG,GAAG,CAAC;oBACrB,GAAG,CAAC,GAAG,CAAC,aAAa,CAAC,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;gBACrE,CAAC;YACH,CAAC,CAAC,CAAC;QACL,CAAC;QAED,kBAAkB;YAChB,MAAM,IAAI,GAAwB;gBAChC;oBACE,GAAG,EAAE,QAAQ;oBACb,KAAK,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,YAAY,EAAE;oBAC5C,8CAA8C;oBAC9C,QAAQ,EAAE,cAAc;iBACzB;aACF,CAAC;YACF,OAAO,IAAI,CAAC;QACd,CAAC;KACF,CAAC;AACJ,CAAC;AAED,kBAAe,gBAAgB,CAAC"}
@@ -0,0 +1,15 @@
1
+ /**
2
+ * iOS 兼容性 Polyfills
3
+ *
4
+ * 使用 core-js 提供 iOS 15.4 以下版本需要的 polyfill
5
+ * 此文件会被单独打包成 polyfills.js,按需加载
6
+ */
7
+ import 'core-js/actual/array/at';
8
+ import 'core-js/actual/string/at';
9
+ import 'core-js/actual/array/find-last';
10
+ import 'core-js/actual/array/find-last-index';
11
+ import 'core-js/actual/object/has-own';
12
+ import 'core-js/actual/promise/any';
13
+ import 'core-js/actual/aggregate-error';
14
+ import 'core-js/actual/structured-clone';
15
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/polyfills/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,yBAAyB,CAAC;AACjC,OAAO,0BAA0B,CAAC;AAClC,OAAO,gCAAgC,CAAC;AACxC,OAAO,sCAAsC,CAAC;AAC9C,OAAO,+BAA+B,CAAC;AACvC,OAAO,4BAA4B,CAAC;AACpC,OAAO,gCAAgC,CAAC;AACxC,OAAO,iCAAiC,CAAC"}
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ /**
3
+ * iOS 兼容性 Polyfills
4
+ *
5
+ * 使用 core-js 提供 iOS 15.4 以下版本需要的 polyfill
6
+ * 此文件会被单独打包成 polyfills.js,按需加载
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ // ECMAScript polyfills (core-js)
10
+ require("core-js/actual/array/at");
11
+ require("core-js/actual/string/at");
12
+ require("core-js/actual/array/find-last");
13
+ require("core-js/actual/array/find-last-index");
14
+ require("core-js/actual/object/has-own");
15
+ require("core-js/actual/promise/any");
16
+ require("core-js/actual/aggregate-error");
17
+ require("core-js/actual/structured-clone");
18
+ // Web Crypto API polyfill (不在 core-js 范围内)
19
+ if (typeof crypto !== 'undefined' && typeof crypto.randomUUID !== 'function') {
20
+ Object.defineProperty(crypto, 'randomUUID', {
21
+ value: function randomUUID() {
22
+ const bytes = new Uint8Array(16);
23
+ crypto.getRandomValues(bytes);
24
+ bytes[6] = (bytes[6] & 0x0f) | 0x40;
25
+ bytes[8] = (bytes[8] & 0x3f) | 0x80;
26
+ let hex = '';
27
+ for (let i = 0; i < 16; i++) {
28
+ hex += (bytes[i] < 16 ? '0' : '') + bytes[i].toString(16);
29
+ }
30
+ return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
31
+ },
32
+ writable: true,
33
+ configurable: true,
34
+ });
35
+ }
36
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/polyfills/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;AAEH,iCAAiC;AACjC,mCAAiC;AACjC,oCAAkC;AAClC,0CAAwC;AACxC,gDAA8C;AAC9C,yCAAuC;AACvC,sCAAoC;AACpC,0CAAwC;AACxC,2CAAyC;AAEzC,2CAA2C;AAC3C,IAAI,OAAO,MAAM,KAAK,WAAW,IAAI,OAAO,MAAM,CAAC,UAAU,KAAK,UAAU,EAAE,CAAC;IAC7E,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,YAAY,EAAE;QAC1C,KAAK,EAAE,SAAS,UAAU;YACxB,MAAM,KAAK,GAAG,IAAI,UAAU,CAAC,EAAE,CAAC,CAAC;YACjC,MAAM,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC;YAC9B,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,IAAI,CAAC;YACpC,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,IAAI,CAAC;YACpC,IAAI,GAAG,GAAG,EAAE,CAAC;YACb,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC;gBAC5B,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;YAC5D,CAAC;YACD,OAAO,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,GAAG,CAAC,KAAK,CAAC,EAAE,EAAE,EAAE,CAAC,IAAI,GAAG,CAAC,KAAK,CAAC,EAAE,EAAE,EAAE,CAAC,IAAI,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,EAAE,CAAC;QAC7G,CAAC;QACD,QAAQ,EAAE,IAAI;QACd,YAAY,EAAE,IAAI;KACnB,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,37 @@
1
+ /**
2
+ * 标准化 base path(**路径语义**,强制 `/` 前缀):
3
+ * - 空 / undefined → 空字符串
4
+ * - 前面强制加 `/`
5
+ * - 去掉尾部 `/`
6
+ *
7
+ * 适用:`CLIENT_BASE_PATH` 这种部署路径(一定以 `/` 开头)。
8
+ * **不要**用在 `ASSETS_CDN_PATH` 上 —— CDN 是完整 URL,强加 `/` 会变成
9
+ * `/https://cdn.foo.com/...` 直接破掉。URL 场景用 `normalizeBasePathWithoutTrailingSlash`。
10
+ *
11
+ * 例:
12
+ * normalizeBasePath('') === ''
13
+ * normalizeBasePath('/') === ''
14
+ * normalizeBasePath('foo') === '/foo'
15
+ * normalizeBasePath('/foo/') === '/foo'
16
+ * normalizeBasePath('/app/x/') === '/app/x'
17
+ */
18
+ export declare function normalizeBasePath(input: string | undefined): string;
19
+ /**
20
+ * 标准化 base path(**URL-safe**,只去尾斜杠不加首斜杠):
21
+ * - 空 / undefined / 单独 `/` → 空字符串
22
+ * - 去掉尾部 `/`
23
+ * - 完整 URL(含 scheme)原样保留
24
+ * - 相对路径不强加 `/` 前缀
25
+ *
26
+ * 适用:`ASSETS_CDN_PATH` 这种可能是完整 URL(`https://cdn.foo.com/x`)
27
+ * 也可能是路径(`/app/x`)的字段。
28
+ *
29
+ * 例:
30
+ * normalizeBasePathWithoutTrailingSlash('') === ''
31
+ * normalizeBasePathWithoutTrailingSlash('/') === ''
32
+ * normalizeBasePathWithoutTrailingSlash('/app/x/') === '/app/x'
33
+ * normalizeBasePathWithoutTrailingSlash('https://cdn.foo.com/x/') === 'https://cdn.foo.com/x'
34
+ * normalizeBasePathWithoutTrailingSlash('https://cdn.foo.com/x') === 'https://cdn.foo.com/x'
35
+ */
36
+ export declare function normalizeBasePathWithoutTrailingSlash(input: string | undefined): string;
37
+ //# sourceMappingURL=normalize-base-path.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"normalize-base-path.d.ts","sourceRoot":"","sources":["../../src/utils/normalize-base-path.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,CAMnE;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,qCAAqC,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,CAKvF"}
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.normalizeBasePath = normalizeBasePath;
4
+ exports.normalizeBasePathWithoutTrailingSlash = normalizeBasePathWithoutTrailingSlash;
5
+ /**
6
+ * 标准化 base path(**路径语义**,强制 `/` 前缀):
7
+ * - 空 / undefined → 空字符串
8
+ * - 前面强制加 `/`
9
+ * - 去掉尾部 `/`
10
+ *
11
+ * 适用:`CLIENT_BASE_PATH` 这种部署路径(一定以 `/` 开头)。
12
+ * **不要**用在 `ASSETS_CDN_PATH` 上 —— CDN 是完整 URL,强加 `/` 会变成
13
+ * `/https://cdn.foo.com/...` 直接破掉。URL 场景用 `normalizeBasePathWithoutTrailingSlash`。
14
+ *
15
+ * 例:
16
+ * normalizeBasePath('') === ''
17
+ * normalizeBasePath('/') === ''
18
+ * normalizeBasePath('foo') === '/foo'
19
+ * normalizeBasePath('/foo/') === '/foo'
20
+ * normalizeBasePath('/app/x/') === '/app/x'
21
+ */
22
+ function normalizeBasePath(input) {
23
+ if (!input)
24
+ return '';
25
+ let p = input.trim();
26
+ if (!p || p === '/')
27
+ return '';
28
+ if (!p.startsWith('/'))
29
+ p = '/' + p;
30
+ return p.replace(/\/+$/, '');
31
+ }
32
+ /**
33
+ * 标准化 base path(**URL-safe**,只去尾斜杠不加首斜杠):
34
+ * - 空 / undefined / 单独 `/` → 空字符串
35
+ * - 去掉尾部 `/`
36
+ * - 完整 URL(含 scheme)原样保留
37
+ * - 相对路径不强加 `/` 前缀
38
+ *
39
+ * 适用:`ASSETS_CDN_PATH` 这种可能是完整 URL(`https://cdn.foo.com/x`)
40
+ * 也可能是路径(`/app/x`)的字段。
41
+ *
42
+ * 例:
43
+ * normalizeBasePathWithoutTrailingSlash('') === ''
44
+ * normalizeBasePathWithoutTrailingSlash('/') === ''
45
+ * normalizeBasePathWithoutTrailingSlash('/app/x/') === '/app/x'
46
+ * normalizeBasePathWithoutTrailingSlash('https://cdn.foo.com/x/') === 'https://cdn.foo.com/x'
47
+ * normalizeBasePathWithoutTrailingSlash('https://cdn.foo.com/x') === 'https://cdn.foo.com/x'
48
+ */
49
+ function normalizeBasePathWithoutTrailingSlash(input) {
50
+ if (!input)
51
+ return '';
52
+ const p = input.trim();
53
+ if (!p || p === '/')
54
+ return '';
55
+ return p.replace(/\/+$/, '');
56
+ }
57
+ //# sourceMappingURL=normalize-base-path.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"normalize-base-path.js","sourceRoot":"","sources":["../../src/utils/normalize-base-path.ts"],"names":[],"mappings":";;AAiBA,8CAMC;AAmBD,sFAKC;AA/CD;;;;;;;;;;;;;;;;GAgBG;AACH,SAAgB,iBAAiB,CAAC,KAAyB;IACzD,IAAI,CAAC,KAAK;QAAE,OAAO,EAAE,CAAC;IACtB,IAAI,CAAC,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC;IACrB,IAAI,CAAC,CAAC,IAAI,CAAC,KAAK,GAAG;QAAE,OAAO,EAAE,CAAC;IAC/B,IAAI,CAAC,CAAC,CAAC,UAAU,CAAC,GAAG,CAAC;QAAE,CAAC,GAAG,GAAG,GAAG,CAAC,CAAC;IACpC,OAAO,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;AAC/B,CAAC;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,SAAgB,qCAAqC,CAAC,KAAyB;IAC7E,IAAI,CAAC,KAAK;QAAE,OAAO,EAAE,CAAC;IACtB,MAAM,CAAC,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC;IACvB,IAAI,CAAC,CAAC,IAAI,CAAC,KAAK,GAAG;QAAE,OAAO,EAAE,CAAC;IAC/B,OAAO,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;AAC/B,CAAC"}
@@ -0,0 +1,12 @@
1
+ import type { Connect } from 'vite';
2
+ /**
3
+ * `/dev/snapdom-proxy?url=<encoded>` 转发到目标 URL,带上 request cookie。
4
+ * 给客户端截图(snapdom)库做跨域兜底用。仅 dev。
5
+ */
6
+ export interface SnapDomMiddlewareOptions {
7
+ proxyUrl?: string;
8
+ baseUrl?: string;
9
+ }
10
+ export declare function registerSnapDomProxyMiddleware(middlewares: Connect.Server, options?: SnapDomMiddlewareOptions): void;
11
+ export default registerSnapDomProxyMiddleware;
12
+ //# sourceMappingURL=snapdom-proxy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"snapdom-proxy.d.ts","sourceRoot":"","sources":["../../src/utils/snapdom-proxy.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAEpC;;;GAGG;AACH,MAAM,WAAW,wBAAwB;IACvC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,wBAAgB,8BAA8B,CAC5C,WAAW,EAAE,OAAO,CAAC,MAAM,EAC3B,OAAO,GAAE,wBAA6B,GACrC,IAAI,CAsCN;AAED,eAAe,8BAA8B,CAAC"}
@@ -0,0 +1,75 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.registerSnapDomProxyMiddleware = registerSnapDomProxyMiddleware;
37
+ const path = __importStar(require("node:path"));
38
+ function registerSnapDomProxyMiddleware(middlewares, options = {}) {
39
+ const { proxyUrl = '/dev/snapdom-proxy', baseUrl = '/' } = options;
40
+ const targetUrl = path.join(baseUrl, proxyUrl);
41
+ middlewares.use(async (req, res, next) => {
42
+ if (req.method !== 'GET' || !req.url?.startsWith(targetUrl)) {
43
+ return next();
44
+ }
45
+ try {
46
+ const url = new URL(req.url, `http://${req.headers.host}`);
47
+ let targetParam = url.searchParams.get('url');
48
+ if (!targetParam) {
49
+ res.statusCode = 400;
50
+ res.setHeader('Content-Type', 'application/json');
51
+ res.end(JSON.stringify({ error: 'Missing url parameter' }));
52
+ return;
53
+ }
54
+ targetParam = decodeURIComponent(targetParam);
55
+ const response = await fetch(targetParam, {
56
+ headers: { cookie: req.headers.cookie || '' },
57
+ });
58
+ const contentType = response.headers.get('content-type');
59
+ if (contentType)
60
+ res.setHeader('Content-Type', contentType);
61
+ const buffer = await response.arrayBuffer();
62
+ res.end(Buffer.from(buffer));
63
+ }
64
+ catch (error) {
65
+ res.statusCode = 500;
66
+ res.setHeader('Content-Type', 'application/json');
67
+ res.end(JSON.stringify({
68
+ error: 'Proxy request failed',
69
+ message: error.message,
70
+ }));
71
+ }
72
+ });
73
+ }
74
+ exports.default = registerSnapDomProxyMiddleware;
75
+ //# sourceMappingURL=snapdom-proxy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"snapdom-proxy.js","sourceRoot":"","sources":["../../src/utils/snapdom-proxy.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAYA,wEAyCC;AArDD,gDAAkC;AAYlC,SAAgB,8BAA8B,CAC5C,WAA2B,EAC3B,UAAoC,EAAE;IAEtC,MAAM,EAAE,QAAQ,GAAG,oBAAoB,EAAE,OAAO,GAAG,GAAG,EAAE,GAAG,OAAO,CAAC;IACnE,MAAM,SAAS,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;IAE/C,WAAW,CAAC,GAAG,CAAC,KAAK,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE;QACvC,IAAI,GAAG,CAAC,MAAM,KAAK,KAAK,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,UAAU,CAAC,SAAS,C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,CACL,IAAI,CAAC,SAAS,CAAC;gBACb,KAAK,EAAE,sBAAsB;gBAC7B,OAAO,EAAG,KAAe,CAAC,OAAO;aAClC,CAAC,CACH,CAAC;QACJ,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC;AAED,kBAAe,8BAA8B,CAAC"}
package/package.json ADDED
@@ -0,0 +1,63 @@
1
+ {
2
+ "name": "@lark-apaas/coding-preset-vite-react",
3
+ "version": "0.1.0",
4
+ "description": "Vite 8 preset for miaoda-coding vite-react (jsPage) templates — pure frontend, no fullstack baggage",
5
+ "main": "./lib/index.js",
6
+ "types": "./lib/index.d.ts",
7
+ "files": [
8
+ "lib",
9
+ "src/empty.css",
10
+ "src/inspector-stub.js",
11
+ "src/module-alias",
12
+ "src/overlay",
13
+ "src/polyfills",
14
+ "src/runtime"
15
+ ],
16
+ "scripts": {
17
+ "build": "tsc || true",
18
+ "watch": "tsc --watch",
19
+ "typecheck": "tsc --noEmit",
20
+ "test": "vitest run",
21
+ "test:watch": "vitest",
22
+ "prepublishOnly": "npm run build"
23
+ },
24
+ "dependencies": {
25
+ "@babel/parser": "^7.28.0",
26
+ "@babel/traverse": "^7.28.0",
27
+ "@babel/types": "^7.28.0",
28
+ "@lark-apaas/vite-inspector-plugin": "^1.0.3",
29
+ "@tailwindcss/vite": "^4.3.0",
30
+ "@vitejs/plugin-react": "^6.0.0",
31
+ "clsx": "^2.1.1",
32
+ "core-js": "^3.40.0",
33
+ "echarts": "^6.0.0",
34
+ "echarts-for-react": "^3.0.2",
35
+ "html-minifier-terser": "^7.2.0",
36
+ "tailwind-merge": "^2.5.5"
37
+ },
38
+ "peerDependencies": {
39
+ "react": ">=18.0.0",
40
+ "react-dom": ">=18.0.0",
41
+ "vite": "^8.0.0"
42
+ },
43
+ "devDependencies": {
44
+ "@types/babel__traverse": "^7.20.0",
45
+ "@types/html-minifier-terser": "^7.0.2",
46
+ "@types/node": "^22.0.0",
47
+ "typescript": "^5.6.0",
48
+ "vite": "^8.0.0",
49
+ "vitest": "^3.0.0"
50
+ },
51
+ "publishConfig": {
52
+ "access": "public",
53
+ "registry": "https://registry.npmjs.org/"
54
+ },
55
+ "keywords": [
56
+ "miaoda",
57
+ "coding-preset",
58
+ "vite",
59
+ "react",
60
+ "jspage"
61
+ ],
62
+ "license": "MIT"
63
+ }
package/src/empty.css ADDED
@@ -0,0 +1 @@
1
+ /* Empty CSS stub for production builds - inspector styles are dev-only */
@@ -0,0 +1,6 @@
1
+ // Empty stub for @lark-apaas/miaoda-inspector in production mode
2
+ // The inspector is only used in development
3
+
4
+ export const MiaodaInspector = () => null;
5
+ export const defaultUIConfig = {};
6
+ export const isOutgoingMessage = () => false;
@@ -0,0 +1,8 @@
1
+ import cls from 'clsx';
2
+ import { twMerge } from 'tailwind-merge';
3
+
4
+ export function clsx(...args) {
5
+ return twMerge(cls(...args));
6
+ }
7
+
8
+ export default clsx;
@@ -0,0 +1,130 @@
1
+ import React from 'react';
2
+ import OriginalReactECharts from 'echarts-for-react';
3
+ import Color from 'colorjs.io';
4
+ import './echarts.mjs';
5
+
6
+ /**
7
+ * Convert HSL/HSLA color to hex or rgba
8
+ */
9
+ export function convertColorToHex(color) {
10
+ if (typeof color !== 'string') return color;
11
+
12
+ const trimmed = color.trim();
13
+ if (!trimmed.startsWith('hsl')) {
14
+ return color;
15
+ }
16
+
17
+ try {
18
+ const colorObj = new Color(trimmed);
19
+
20
+ if (colorObj.alpha < 1) {
21
+ return colorObj.to('srgb').toString({ format: 'rgba' });
22
+ } else {
23
+ return colorObj.to('srgb').toString({ format: 'hex' });
24
+ }
25
+ } catch (error) {
26
+ console.warn(`Failed to convert color: ${color}`, error);
27
+ return color;
28
+ }
29
+ }
30
+
31
+ function convertColorValue(propValue, visited) {
32
+ if (typeof propValue === 'string') {
33
+ return convertColorToHex(propValue);
34
+ }
35
+ if (Array.isArray(propValue)) {
36
+ return propValue.map((item) =>
37
+ typeof item === 'string' ? convertColorToHex(item) : transformColors(item, visited)
38
+ );
39
+ }
40
+ return transformColors(propValue, visited);
41
+ }
42
+
43
+ /**
44
+ * Deep traverse object to transform all HSL colors in 'color' property
45
+ */
46
+ export function transformColors(value, visited = new WeakSet()) {
47
+ if (value === null || value === undefined) return value;
48
+ if (typeof value !== 'object') return value;
49
+ if (visited.has(value)) return value;
50
+ if (value instanceof Date || value instanceof RegExp) return value;
51
+
52
+ visited.add(value);
53
+
54
+ if (Array.isArray(value)) {
55
+ return value.map((item) => transformColors(item, visited));
56
+ }
57
+
58
+ const result = {};
59
+ for (const key in value) {
60
+ if (!Object.prototype.hasOwnProperty.call(value, key)) continue;
61
+
62
+ const propValue = value[key];
63
+
64
+ if (key === 'color') {
65
+ if (typeof propValue === 'function') {
66
+ result[key] = (...args) => convertColorValue(propValue(...args), visited);
67
+ } else {
68
+ result[key] = convertColorValue(propValue, visited);
69
+ }
70
+ } else {
71
+ result[key] = transformColors(propValue, visited);
72
+ }
73
+ }
74
+
75
+ return result;
76
+ }
77
+
78
+ /**
79
+ * Remove label.color and emphasis.label.color from funnel series
80
+ * to let ECharts use default contrast colors
81
+ */
82
+ function removeFunnelLabelColor(option) {
83
+ if (!Array.isArray(option.series)) return option;
84
+
85
+ const series = option.series.map((item) => {
86
+ if (item?.type !== 'funnel') return item;
87
+
88
+ let result = { ...item };
89
+
90
+ // remove label.color
91
+ if (result.label && typeof result.label === 'object') {
92
+ const { color: _, ...labelRest } = result.label;
93
+ result = { ...result, label: labelRest };
94
+ }
95
+
96
+ // remove emphasis.label.color
97
+ const emphasis = result.emphasis;
98
+ if (emphasis?.label && typeof emphasis.label === 'object') {
99
+ const { color: _, ...emphasisLabelRest } = emphasis.label;
100
+ result = { ...result, emphasis: { ...emphasis, label: emphasisLabelRest } };
101
+ }
102
+
103
+ return result;
104
+ });
105
+
106
+ return { ...option, series };
107
+ }
108
+
109
+ /**
110
+ * EChartsReact wrapper component
111
+ * - Automatically converts HSL colors to hex in option
112
+ * - Removes label.color from funnel series
113
+ */
114
+ export class EChartsReact extends React.Component {
115
+ render() {
116
+ const { option, ...rest } = this.props;
117
+
118
+ const transformedOption = option
119
+ ? removeFunnelLabelColor(transformColors(option))
120
+ : option;
121
+
122
+ return React.createElement(OriginalReactECharts, {
123
+ option: transformedOption,
124
+ ...rest,
125
+ });
126
+ }
127
+ }
128
+
129
+ export * from 'echarts-for-react';
130
+ export default EChartsReact;
@@ -0,0 +1,43 @@
1
+ import * as echartsNamespace from 'echarts';
2
+ export { echartsNamespace as echarts };
3
+ export * from 'echarts';
4
+
5
+ import * as echarts from 'echarts';
6
+ import { registerTheme } from 'echarts';
7
+ import { getShadcnEChartsTheme } from './registry_echarts_theme.mjs';
8
+
9
+ let isRegistered = false;
10
+ let isWindowMounted = false;
11
+
12
+ /**
13
+ * Mount echarts to window for debugging
14
+ */
15
+ export function registerEchartsToWindow() {
16
+ if (isWindowMounted || typeof globalThis.window === 'undefined') {
17
+ return;
18
+ }
19
+ isWindowMounted = true;
20
+ globalThis.echarts = echarts;
21
+ }
22
+
23
+ export function resgisterEchartsTheme() {
24
+ // Register ud theme, only register once globally
25
+ if (isRegistered || typeof document === 'undefined') {
26
+ return;
27
+ }
28
+ isRegistered = true;
29
+ // After bundling main.js defer execution, css will be loaded
30
+ registerTheme('ud', getShadcnEChartsTheme());
31
+
32
+ if (process.env.NODE_ENV === 'development') {
33
+ // Listen for HMR update completion to re-register theme
34
+ if (import.meta.hot) {
35
+ import.meta.hot.on('vite:afterUpdate', () => {
36
+ registerTheme('ud', getShadcnEChartsTheme());
37
+ });
38
+ }
39
+ }
40
+ }
41
+
42
+ registerEchartsToWindow();
43
+ resgisterEchartsTheme();