@aippy/vite-plugins 0.4.0-dev.3 → 0.4.0-dev.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,423 @@
1
+ import { extractAssetsFromContent as e, generateConstantName as t, processAssetURL as n } from "./utils/index.js";
2
+ import { a as r, c as i, i as a, l as o, n as s, o as c, r as l, s as u, t as d } from "./wrapper-keys-BPP5iTGM.js";
3
+ import { promises as f } from "fs";
4
+ import p from "path";
5
+ import { parse as m } from "@babel/parser";
6
+ import h from "@babel/traverse";
7
+ import * as g from "@babel/types";
8
+ import _ from "@babel/generator";
9
+ //#region src/asset-constants/generator-utils.ts
10
+ function v(e) {
11
+ if (!e || typeof e != "object" || Array.isArray(e)) return !1;
12
+ let t = e;
13
+ return typeof t.schemaVersion == "number" && !!t.assets && typeof t.assets == "object" && !Array.isArray(t.assets);
14
+ }
15
+ var y = [
16
+ "",
17
+ "-",
18
+ "--",
19
+ "tbd",
20
+ "todo",
21
+ "none",
22
+ "n/a",
23
+ "null",
24
+ "pending",
25
+ "not-generated",
26
+ "待生成",
27
+ "待制作"
28
+ ];
29
+ function b(e) {
30
+ if (!e || Buffer.byteLength(e) > 4096 || /[\x00-\x08\x0b\x0c\x0e-\x1f\x7f-\x9f\uFEFF]/.test(e) || /[\s\\]/u.test(e) || e.startsWith("//") || /%(?![0-9a-f]{2})/i.test(e.split("?")[0]) || /%(?![0-9a-f]{2})/i.test(e.split("#")[1] ?? "")) return !1;
31
+ if (!/^[a-z][a-z0-9+.-]*:/i.test(e)) {
32
+ if (e.split(/[?#]/, 1)[0].split("/", 1)[0].includes(":")) return !1;
33
+ let t = e.split(/[?#]/, 1)[0].replace(/%([0-9a-f]{2})/gi, (e, t) => String.fromCharCode(Number.parseInt(t, 16)));
34
+ if (!t || t.endsWith("/") || y.includes(t.trim().toLowerCase())) return !1;
35
+ if (t.includes("/")) return !0;
36
+ let n = t.lastIndexOf(".");
37
+ return n > 0 && n < t.length - 1;
38
+ }
39
+ if (!/^https?:\/\//i.test(e)) return !1;
40
+ let t = e.slice(e.indexOf("://") + 3).split(/[/?#]/, 1)[0];
41
+ if (!t || t.includes("%")) return !1;
42
+ try {
43
+ let t = new URL(e);
44
+ return !!t.hostname && !t.username && !t.password;
45
+ } catch {
46
+ return !1;
47
+ }
48
+ }
49
+ function x(e) {
50
+ let t = /* @__PURE__ */ new Map();
51
+ for (let [n, r] of Object.entries(e)) typeof r != "string" || !b(r) || t.has(r) || t.set(r, n);
52
+ return t;
53
+ }
54
+ function S(e, t, n = {}) {
55
+ let r = { ...n }, i = new Set(Object.keys(r));
56
+ for (let [e, n] of t.entries()) i.has(n) || Object.values(r).includes(e) || (r[n] = e, i.add(n));
57
+ for (let t of e.values()) {
58
+ let e = Object.entries(r).find(([, e]) => e === t.originalUri);
59
+ if (e) {
60
+ t.constantName = e[0];
61
+ continue;
62
+ }
63
+ let n = t.constantName, a = n, o = 2;
64
+ for (; i.has(a);) a = `${n}_${o++}`;
65
+ i.add(a), t.constantName = a, r[a] = t.originalUri;
66
+ }
67
+ return JSON.stringify(r, null, 2) + "\n";
68
+ }
69
+ function C(e) {
70
+ let t = /* @__PURE__ */ new Map();
71
+ try {
72
+ if (!e.trim()) return t;
73
+ let n = JSON.parse(e);
74
+ if (v(n)) throw Error("assets: single-file asset plan is not supported");
75
+ if (!n || typeof n != "object" || Array.isArray(n)) throw Error("assets: URL dictionary object required");
76
+ for (let [e, r] of Object.entries(n)) typeof r == "string" && t.set(r, e);
77
+ t.size > 0 && console.log(`📋 Found ${t.size} existing constants in assets.json`);
78
+ } catch (e) {
79
+ throw e instanceof Error && e.message.startsWith("assets:") ? e : Error("assets: invalid JSON syntax");
80
+ }
81
+ return t;
82
+ }
83
+ function w(e, t, n, r) {
84
+ let i = Array.from(n.values()).filter((e) => t.has(e.originalUri)).length, a = e - i;
85
+ console.log(a > 0 ? `✅ Generated ${e} asset constants (${a} new, ${i} reused) in ${r}` : e > 0 ? `✅ Generated ${e} asset constants (all reused from existing) in ${r}` : "✅ No asset constants found");
86
+ }
87
+ //#endregion
88
+ //#region src/asset-constants/index.ts
89
+ var T = typeof h == "function" ? h : h.default, E = typeof _ == "function" ? _ : _.default, D = class extends Error {}, O = class {
90
+ constructor(e = {}) {
91
+ o(this, "options", void 0), o(this, "assets", /* @__PURE__ */ new Map()), o(this, "existingAssets", /* @__PURE__ */ new Map()), o(this, "flat", {}), o(this, "fileCache", new r()), o(this, "planKeys", void 0), o(this, "implementationPaths", /* @__PURE__ */ new Set()), o(this, "referencedFiles", /* @__PURE__ */ new Set()), this.options = {
92
+ extensions: [
93
+ ".png",
94
+ ".jpg",
95
+ ".jpeg",
96
+ ".gif",
97
+ ".svg",
98
+ ".mp4",
99
+ ".mp3",
100
+ ".wav",
101
+ ".ogg",
102
+ ".webm"
103
+ ],
104
+ srcDir: "src",
105
+ outputFile: "src/config/assets.json",
106
+ devMode: !1,
107
+ ...e
108
+ };
109
+ }
110
+ clearCache() {
111
+ this.fileCache.clear();
112
+ }
113
+ generateConstantName(e) {
114
+ let n = /* @__PURE__ */ new Set([
115
+ ...Array.from(this.assets.values()).map((e) => e.constantName),
116
+ ...Array.from(this.existingAssets.values()),
117
+ ...this.planKeys ?? []
118
+ ]);
119
+ return t(e, n);
120
+ }
121
+ async scanTsFile(t) {
122
+ try {
123
+ let n = await this.fileCache.read(t), r = [], i = e(n, "js", this.options.extensions), a = /* @__PURE__ */ new Set([...Object.keys(this.flat), ...this.planKeys ?? []]);
124
+ if (i.some((e) => a.has(e))) {
125
+ let r = s(n, t, this.options.srcDir, this.options.outputFile);
126
+ i = e(r, "js", this.options.extensions);
127
+ }
128
+ let o = n.split("\n"), c = x(this.flat);
129
+ i = i.filter((e) => n.includes(`"${e}"`) || n.includes(`'${e}'`)), i.forEach((e) => {
130
+ if (this.isImplementationReference(t, e)) return;
131
+ let n = this.generateConstantName(e), i = o.findIndex((t) => t.includes(e)) + 1;
132
+ r.push({
133
+ originalUri: e,
134
+ constantName: n,
135
+ filePath: t,
136
+ line: i,
137
+ column: 1
138
+ });
139
+ });
140
+ let l = new Set(r.map((e) => e.originalUri));
141
+ for (let [e, i] of c) l.has(e) || !n.includes(`"${e}"`) && !n.includes(`'${e}'`) || r.push({
142
+ originalUri: e,
143
+ constantName: i,
144
+ filePath: t,
145
+ line: 1,
146
+ column: 1
147
+ });
148
+ return r;
149
+ } catch (e) {
150
+ return console.warn(`Warning: Failed to scan ${t}:`, e), [];
151
+ }
152
+ }
153
+ async scanAllTsFiles() {
154
+ let e = this.options.srcDir;
155
+ this.referencedFiles.clear();
156
+ try {
157
+ let t = await u(e, [".ts", ".tsx"]);
158
+ for (let e of t) {
159
+ if (e.endsWith("assets.json") || e.endsWith("assets.ts")) continue;
160
+ let t = await this.scanTsFile(e), n = x(this.flat);
161
+ t.forEach((e) => {
162
+ let t = n.get(e.originalUri);
163
+ t ? e.constantName = t : this.existingAssets.has(e.originalUri) && (e.constantName = this.existingAssets.get(e.originalUri)), this.referencedFiles.add(e.filePath);
164
+ let r = e.originalUri;
165
+ this.assets.has(r) || this.assets.set(r, e);
166
+ });
167
+ }
168
+ } catch (e) {
169
+ console.error("Error scanning TypeScript files:", e);
170
+ }
171
+ }
172
+ async readExistingAssetsFile() {
173
+ try {
174
+ return await f.readFile(this.options.outputFile, "utf-8");
175
+ } catch (e) {
176
+ if (e.code === "ENOENT") return "";
177
+ throw new D("Unable to read assets.json: " + String(e));
178
+ }
179
+ }
180
+ sidecarPath() {
181
+ return p.resolve(this.options.srcDir, "..", "assets-plan.json");
182
+ }
183
+ async parseExistingAssets() {
184
+ let e = await this.readExistingAssetsFile();
185
+ if (e.trim()) {
186
+ let t;
187
+ try {
188
+ t = JSON.parse(e);
189
+ } catch {
190
+ throw new D("assets: invalid JSON syntax");
191
+ }
192
+ if (v(t)) throw new D("assets: single-file asset plan is not supported");
193
+ if (!t || typeof t != "object" || Array.isArray(t)) throw new D("assets: URL dictionary object required");
194
+ this.flat = { ...t };
195
+ }
196
+ try {
197
+ this.existingAssets = C(e);
198
+ } catch (e) {
199
+ throw new D(e instanceof Error ? e.message : "assets: invalid JSON syntax");
200
+ }
201
+ await this.readSidecar();
202
+ }
203
+ async readSidecar() {
204
+ let e = "";
205
+ try {
206
+ e = await f.readFile(this.sidecarPath(), "utf-8");
207
+ } catch (e) {
208
+ e.code !== "ENOENT" && console.warn("assets: unable to read assets-plan.json; continuing with the dictionary only");
209
+ return;
210
+ }
211
+ if (!e.trim()) return;
212
+ let t;
213
+ try {
214
+ t = JSON.parse(e);
215
+ } catch {
216
+ console.warn("assets: assets-plan.json is not valid JSON; continuing with the dictionary only");
217
+ return;
218
+ }
219
+ if (!v(t)) {
220
+ console.warn("assets: assets-plan.json is not a plan; continuing with the dictionary only");
221
+ return;
222
+ }
223
+ let n = t.assets;
224
+ this.planKeys = Object.keys(n);
225
+ let r = p.resolve(this.options.srcDir, "..");
226
+ for (let e of Object.values(n)) {
227
+ let t = e?.implementation?.path;
228
+ typeof t == "string" && t && this.implementationPaths.add(p.resolve(r, t));
229
+ }
230
+ }
231
+ isImplementationReference(e, t) {
232
+ if (!this.implementationPaths.size || /^[a-z][a-z0-9+.-]*:/i.test(t) || t.startsWith("//")) return !1;
233
+ let n = t.split(/[?#]/)[0], r = n.startsWith("@/") ? p.resolve(this.options.srcDir, n.slice(2)) : p.resolve(p.dirname(e), n);
234
+ return this.implementationPaths.has(r);
235
+ }
236
+ async generateAssetsFile() {
237
+ await this.parseExistingAssets(), await this.scanAllTsFiles();
238
+ let e = S(this.assets, this.existingAssets, this.flat);
239
+ try {
240
+ let t = p.dirname(this.options.outputFile);
241
+ await f.mkdir(t, { recursive: !0 }), await f.writeFile(this.options.outputFile, e, "utf-8"), await this.generateAssetsWrapper();
242
+ } catch (e) {
243
+ throw new D("Unable to write the asset dictionary or wrapper: " + String(e));
244
+ }
245
+ w(this.assets.size, this.existingAssets, this.assets, this.options.outputFile);
246
+ }
247
+ async generateAssetsWrapper() {
248
+ let e = this.options.outputFile.replace(/\.json$/, ".ts"), t = `// 🍎 Auto-generated wrapper for assets.json
249
+ // This file handles iOS image replacement via asset-interceptor.js
250
+ import assetsData from "./${p.basename(this.options.outputFile)}";
251
+
252
+ // Batch process all asset URLs for potential replacements
253
+ // sessionStorage may contain __aippy_asset_overrides__ with multiple image mappings
254
+ (window as any).getReplacedAssets?.(assetsData);
255
+
256
+ export default assetsData;
257
+ `;
258
+ await f.writeFile(e, t, "utf-8"), console.log(` ✓ Generated assets wrapper: ${p.relative(process.cwd(), e)}`);
259
+ }
260
+ getAssets() {
261
+ return Array.from(this.assets.values());
262
+ }
263
+ replaceLiteral(e, t, n) {
264
+ let r = /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(n), i = g.memberExpression(g.identifier(t), r ? g.identifier(n) : g.stringLiteral(n), !r);
265
+ if ((g.isObjectProperty(e.parent) || g.isObjectMethod(e.parent) || g.isClassProperty(e.parent) || g.isClassMethod(e.parent)) && e.key === "key" && (e.parent.computed = !0), e.parent && g.isJSXAttribute(e.parent)) return e.replaceWith(g.jsxExpressionContainer(i)), !0;
266
+ try {
267
+ g.validate(e.parent, e.key, i);
268
+ } catch {
269
+ return !1;
270
+ }
271
+ return e.replaceWith(i), !0;
272
+ }
273
+ async replaceUrisInFile(e, t) {
274
+ try {
275
+ let r = await this.fileCache.read(e), i = m(r, {
276
+ sourceType: "module",
277
+ plugins: [
278
+ "typescript",
279
+ "jsx",
280
+ "decorators-legacy"
281
+ ]
282
+ }), o = !1, s = this.options.outputFile.replace(/\.json$/, ".ts"), u = c(s, this.options.srcDir), h = l(e, this.options.srcDir, this.options.outputFile), _ = a(i, h), v = "assetsData", y = !1, b, x = /* @__PURE__ */ new Set();
283
+ T(i, {
284
+ Identifier: (e) => {
285
+ x.add(e.node.name);
286
+ },
287
+ ImportDeclaration: (e) => {
288
+ if (!(!h.has(e.node.source.value) || e.node.importKind === "type")) for (let t of e.node.specifiers) {
289
+ if (t.importKind === "type") continue;
290
+ let n = e.scope.getBinding(t.local.name);
291
+ d(t) && (v = t.local.name, y = !0, b = n);
292
+ }
293
+ }
294
+ });
295
+ let S = !1;
296
+ if (y && T(i, { StringLiteral: (r) => {
297
+ !g.isImportDeclaration(r.parent) && !_(r) && !this.isImplementationReference(e, r.node.value) && t.has(n(r.node.value)) && r.scope.getBinding(v) !== b && (S = !0);
298
+ } }), !y && x.has(v) || S) {
299
+ let e = "aippyAssetsData";
300
+ for (let t = 2; x.has(e); t++) e = `aippyAssetsData${t}`;
301
+ S && b.scope.rename(v, e), v = e;
302
+ }
303
+ if (T(i, { StringLiteral: (r) => {
304
+ let i = r.node.value;
305
+ if (this.isImplementationReference(e, i) || _(r) || g.isImportDeclaration(r.parent) || g.isExportNamedDeclaration(r.parent) || g.isExportAllDeclaration(r.parent) || r.findParent((e) => g.isTSType(e.node) || g.isTSInterfaceBody(e.node))) return;
306
+ let a = n(i);
307
+ if (t.has(a)) {
308
+ let e = t.get(a);
309
+ this.replaceLiteral(r, v, e) && (r.skip(), o = !0);
310
+ }
311
+ } }), !o) return;
312
+ if (!y) {
313
+ let e = g.importDeclaration([g.importDefaultSpecifier(g.identifier(v))], g.stringLiteral(u));
314
+ i.program.body.unshift(e);
315
+ }
316
+ let C = E(i, {
317
+ retainLines: !1,
318
+ comments: !0,
319
+ compact: !1
320
+ }, r);
321
+ await f.writeFile(e, C.code, "utf-8"), this.fileCache.invalidate(e), console.log(` ✓ Replaced URIs in ${p.relative(process.cwd(), e)}`);
322
+ } catch (t) {
323
+ console.warn(`Warning: Failed to replace URIs in ${e}:`, t);
324
+ }
325
+ }
326
+ async replaceAllUris() {
327
+ let e = /* @__PURE__ */ new Map(), t = /* @__PURE__ */ new Set();
328
+ for (let t of this.assets.values()) e.set(t.originalUri, t.constantName);
329
+ for (let e of this.referencedFiles) t.add(e);
330
+ for (let n of t) await this.replaceUrisInFile(n, e);
331
+ }
332
+ needsRewrite() {
333
+ return this.assets.size > 0;
334
+ }
335
+ async cleanupUnusedConstants() {
336
+ if (!this.planKeys) try {
337
+ let e = await this.readExistingAssetsFile();
338
+ if (!e.trim()) return;
339
+ let t = /* @__PURE__ */ new Map();
340
+ try {
341
+ let n = JSON.parse(e);
342
+ for (let [e, r] of Object.entries(n)) typeof r == "string" && t.set(e, r);
343
+ } catch (e) {
344
+ console.warn("Warning: Failed to parse assets.json:", e);
345
+ return;
346
+ }
347
+ if (t.size === 0) return;
348
+ let n = /* @__PURE__ */ new Set(), r = await u(this.options.srcDir, [".ts", ".tsx"]);
349
+ for (let e of r) if (!(e.endsWith("assets.json") || e.endsWith("assets.ts"))) try {
350
+ let r = await this.fileCache.read(e);
351
+ for (let e of t.keys()) r.includes(e) && n.add(e);
352
+ } catch (t) {
353
+ console.warn(`Warning: Failed to read ${e}:`, t);
354
+ }
355
+ let i = [];
356
+ for (let e of t.keys()) n.has(e) || i.push(e);
357
+ if (i.length > 0) {
358
+ console.log(`🧹 Removing ${i.length} unused constant(s):`), i.forEach((e) => {
359
+ console.log(` - ${e}`);
360
+ });
361
+ let e = [];
362
+ for (let n of i) {
363
+ let r = t.get(n);
364
+ r && e.push(r);
365
+ }
366
+ for (let t of e) this.assets.delete(t);
367
+ } else console.log("✅ All constants are in use");
368
+ } catch (e) {
369
+ console.warn("Warning: Failed to cleanup unused constants:", e);
370
+ }
371
+ }
372
+ async upgradeJsonImportsToTs() {
373
+ let e = this.options.outputFile.replace(/\.json$/, ".ts"), t = c(e, this.options.srcDir), n = await u(this.options.srcDir, [".ts", ".tsx"]), r = 0;
374
+ for (let a of n) if (!(a.endsWith("assets.ts") || a.endsWith("assets.json"))) try {
375
+ let n = await this.fileCache.read(a), o = i(a, this.options.outputFile) + ".json", s = i(a, e), l = c(this.options.outputFile, this.options.srcDir) + ".json";
376
+ if (!n.includes(o) && !n.includes(s) && !n.includes(l)) continue;
377
+ let u = m(n, {
378
+ sourceType: "module",
379
+ plugins: [
380
+ "typescript",
381
+ "jsx",
382
+ "decorators-legacy"
383
+ ]
384
+ }), d = !1;
385
+ if (T(u, { ImportDeclaration: (e) => {
386
+ let n = e.node.source.value;
387
+ (n === o || n === s || n === l) && (e.node.source.value = t, d = !0);
388
+ } }), d) {
389
+ let e = E(u, {
390
+ retainLines: !1,
391
+ comments: !0,
392
+ compact: !1
393
+ }, n);
394
+ await f.writeFile(a, e.code, "utf-8"), this.fileCache.invalidate(a), console.log(` ✓ Upgraded import in ${p.relative(process.cwd(), a)} → ${t}`), r++;
395
+ }
396
+ } catch (e) {
397
+ console.warn(`Warning: Failed to upgrade imports in ${a}:`, e);
398
+ }
399
+ r > 0 && console.log(`✅ Upgraded ${r} file(s) to use ${t}`);
400
+ }
401
+ };
402
+ function k(e = {}) {
403
+ return {
404
+ name: "vite-plugin-asset-constants",
405
+ apply: "build",
406
+ enforce: "pre",
407
+ async buildStart() {
408
+ if (!e.devMode) return;
409
+ let t = new O(e);
410
+ try {
411
+ await t.generateAssetsFile();
412
+ let e = t.getAssets();
413
+ t.needsRewrite() && (console.log(`📦 Found ${e.length} asset references:`), e.forEach((e) => {
414
+ console.log(` ${e.constantName} = '${e.originalUri}' (${p.relative(process.cwd(), e.filePath)}:${e.line})`);
415
+ }), console.log("\n🔄 Replacing URIs with constants..."), await t.replaceAllUris(), console.log("✅ URI replacement completed!")), console.log("\n🧹 Checking for unused constants..."), await t.cleanupUnusedConstants(), await t.generateAssetsFile(), console.log("\n🔄 Upgrading assets.json imports to assets.ts..."), await t.upgradeJsonImportsToTs(), console.log("✅ Asset constants finalized!\n"), t.clearCache();
416
+ } catch (e) {
417
+ console.error("❌ Error in asset constants plugin:", e), e instanceof D && this.error(e.message);
418
+ }
419
+ }
420
+ };
421
+ }
422
+ //#endregion
423
+ export { k as t };
@@ -1,5 +1,5 @@
1
1
  import { extractAssetsFromContent as e, findProjectRoot as t, generateConstantName as n, isValidAsset as r, processAssetURL as i } from "../utils/index.js";
2
- import { assetConstantsPlugin as a } from "../asset-constants/index.js";
3
- import { t as o } from "../aippy-preload-DtngFmJ5.js";
2
+ import { t as a } from "../asset-constants-bI4rQJpw.js";
3
+ import { t as o } from "../aippy-preload-DZsYdwMm.js";
4
4
  import { t as s } from "../aippy-tagger-By5socAS.js";
5
5
  export { o as aippyPreloadPlugin, s as aippyTaggerPlugin, a as assetConstantsPlugin, a as default, e as extractAssetsFromContent, t as findProjectRoot, n as generateConstantName, r as isValidAsset, i as processAssetURL };
@@ -0,0 +1,126 @@
1
+ import { promises as e } from "fs";
2
+ import t from "path";
3
+ import { parse as n } from "@babel/parser";
4
+ import r from "@babel/traverse";
5
+ import * as i from "@babel/types";
6
+ //#region \0@oxc-project+runtime@0.144.0/helpers/esm/typeof.js
7
+ function a(e) {
8
+ "@babel/helpers - typeof";
9
+ return a = typeof Symbol == "function" && typeof Symbol.iterator == "symbol" ? function(e) {
10
+ return typeof e;
11
+ } : function(e) {
12
+ return e && typeof Symbol == "function" && e.constructor === Symbol && e !== Symbol.prototype ? "symbol" : typeof e;
13
+ }, a(e);
14
+ }
15
+ //#endregion
16
+ //#region \0@oxc-project+runtime@0.144.0/helpers/esm/toPrimitive.js
17
+ function o(e, t) {
18
+ if (a(e) != "object" || !e) return e;
19
+ var n = e[Symbol.toPrimitive];
20
+ if (n !== void 0) {
21
+ var r = n.call(e, t || "default");
22
+ if (a(r) != "object") return r;
23
+ throw TypeError("@@toPrimitive must return a primitive value.");
24
+ }
25
+ return (t === "string" ? String : Number)(e);
26
+ }
27
+ //#endregion
28
+ //#region \0@oxc-project+runtime@0.144.0/helpers/esm/toPropertyKey.js
29
+ function s(e) {
30
+ var t = o(e, "string");
31
+ return a(t) == "symbol" ? t : t + "";
32
+ }
33
+ //#endregion
34
+ //#region \0@oxc-project+runtime@0.144.0/helpers/esm/defineProperty.js
35
+ function c(e, t, n) {
36
+ return (t = s(t)) in e ? Object.defineProperty(e, t, {
37
+ value: n,
38
+ enumerable: !0,
39
+ configurable: !0,
40
+ writable: !0
41
+ }) : e[t] = n, e;
42
+ }
43
+ //#endregion
44
+ //#region src/utils/file-scanner.ts
45
+ async function l(n, r) {
46
+ let i = [];
47
+ try {
48
+ let a = await e.readdir(n, { withFileTypes: !0 });
49
+ for (let e of a) {
50
+ let a = t.join(n, e.name);
51
+ if (e.isDirectory()) {
52
+ let e = await l(a, r);
53
+ i.push(...e);
54
+ } else if (e.isFile()) {
55
+ let n = t.extname(e.name);
56
+ r.includes(n) && i.push(a);
57
+ }
58
+ }
59
+ } catch (e) {
60
+ console.warn(`Warning: Failed to read directory ${n}:`, e);
61
+ }
62
+ return i;
63
+ }
64
+ function u(e, n) {
65
+ let r = t.relative(t.dirname(e), n).replace(/\.(ts|tsx|js|jsx|json)$/, "");
66
+ return r.startsWith(".") ? r : `./${r}`;
67
+ }
68
+ function d(e, n) {
69
+ return `@/${t.relative(n, e).replace(/\.(ts|tsx|js|jsx|json)$/, "")}`;
70
+ }
71
+ var f = class {
72
+ constructor() {
73
+ c(this, "cache", /* @__PURE__ */ new Map());
74
+ }
75
+ async read(t) {
76
+ if (this.cache.has(t)) return this.cache.get(t);
77
+ let n = await e.readFile(t, "utf-8");
78
+ return this.cache.set(t, n), n;
79
+ }
80
+ invalidate(e) {
81
+ this.cache.delete(e);
82
+ }
83
+ clear() {
84
+ this.cache.clear();
85
+ }
86
+ }, p = typeof r == "function" ? r : r.default;
87
+ function m(e) {
88
+ return i.isImportDefaultSpecifier(e) || i.isImportSpecifier(e) && (i.isIdentifier(e.imported, { name: "default" }) || i.isStringLiteral(e.imported, { value: "default" }));
89
+ }
90
+ function h(e, t) {
91
+ let n = /* @__PURE__ */ new Set();
92
+ return p(e, { ImportDeclaration: (e) => {
93
+ if (!(!t.has(e.node.source.value) || e.node.importKind === "type")) for (let t of e.node.specifiers) t.importKind !== "type" && m(t) && n.add(e.scope.getBinding(t.local.name));
94
+ } }), (e) => {
95
+ let t = e.parent;
96
+ return (i.isMemberExpression(t) || i.isOptionalMemberExpression(t)) && t.computed && e.key === "property" && i.isIdentifier(t.object) && n.has(e.scope.getBinding(t.object.name));
97
+ };
98
+ }
99
+ function g(e, t, n) {
100
+ let r = n.replace(/\.json$/, ".ts"), i = d(r, t), a = u(e, r);
101
+ return /* @__PURE__ */ new Set([
102
+ i,
103
+ i + ".ts",
104
+ a,
105
+ a + ".ts",
106
+ u(e, n) + ".json",
107
+ "@/config/assets.json"
108
+ ]);
109
+ }
110
+ function _(e, t, r, i) {
111
+ let a = n(e, {
112
+ sourceType: "module",
113
+ plugins: [
114
+ "typescript",
115
+ "jsx",
116
+ "decorators-legacy"
117
+ ]
118
+ }), o = h(a, g(t, r, i)), s = [];
119
+ p(a, { StringLiteral: (e) => {
120
+ o(e) && s.push([e.node.start, e.node.end]);
121
+ } });
122
+ for (let [t, n] of s.sort((e, t) => t[0] - e[0])) e = e.slice(0, t) + " ".repeat(n - t) + e.slice(n);
123
+ return e;
124
+ }
125
+ //#endregion
126
+ export { f as a, u as c, h as i, c as l, _ as n, d as o, g as r, l as s, m as t };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aippy/vite-plugins",
3
- "version": "0.4.0-dev.3",
3
+ "version": "0.4.0-dev.5",
4
4
  "description": "Vite plugins for Aippy projects - Asset management and component tagging",
5
5
  "private": false,
6
6
  "type": "module",
@@ -27,13 +27,11 @@
27
27
  "./utils": {
28
28
  "import": "./dist/utils/index.js",
29
29
  "types": "./dist/utils.d.ts"
30
- },
31
- "./assets.schema.json": "./src/asset-constants/assets.schema.json"
30
+ }
32
31
  },
33
32
  "files": [
34
33
  "dist",
35
- "README.md",
36
- "src/asset-constants/assets.schema.json"
34
+ "README.md"
37
35
  ],
38
36
  "publishConfig": {
39
37
  "access": "public"
@@ -1,53 +0,0 @@
1
- export interface AssetError {
2
- stage: string;
3
- code: string;
4
- message: string;
5
- retryable: boolean;
6
- }
7
- export interface AssetParams {
8
- width?: number;
9
- height?: number;
10
- durationSeconds?: number;
11
- loop?: boolean;
12
- }
13
- export interface AssetImplementation {
14
- method: 'svg' | 'canvas' | 'css' | 'synth' | 'animation' | 'three';
15
- description: string;
16
- status: 'planned' | 'ready';
17
- path?: string;
18
- symbol?: string;
19
- }
20
- export interface AssetEntry {
21
- type: string;
22
- source: 'generated' | 'user' | 'existing' | 'code';
23
- replaceable: boolean;
24
- description: string;
25
- params?: AssetParams;
26
- generation?: {
27
- action: 'generate' | 'reuse';
28
- prompt: string;
29
- };
30
- status: 'planned' | 'ready' | 'failed' | 'skipped' | 'degraded';
31
- url?: string;
32
- output?: {
33
- format?: string;
34
- width?: number;
35
- height?: number;
36
- durationSeconds?: number;
37
- };
38
- error?: AssetError;
39
- implementation?: AssetImplementation;
40
- }
41
- export interface AssetManifest {
42
- schemaVersion: 1;
43
- artStyle: string;
44
- assets: Record<string, AssetEntry>;
45
- planningError?: AssetError;
46
- legacyInventory?: string;
47
- legacyPlaceholderKeys?: string[];
48
- }
49
- export type AssetDocument = AssetManifest | Record<string, string>;
50
- export declare function isManifest(doc: AssetDocument): doc is AssetManifest;
51
- export declare function parseAssetDocument(content: string): AssetDocument;
52
- export declare function assetUrlMap(document: AssetDocument): Record<string, string>;
53
- export declare function inferExistingType(uri: string): string;