@aippy/vite-plugins 0.4.0-dev.2 → 0.4.0-dev.4

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,228 @@
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
+ //#region src/asset-constants/generator-utils.ts
127
+ function v(e) {
128
+ if (!e || typeof e != "object" || Array.isArray(e)) return !1;
129
+ let t = e;
130
+ return typeof t.schemaVersion == "number" && !!t.assets && typeof t.assets == "object" && !Array.isArray(t.assets);
131
+ }
132
+ var y = [
133
+ "",
134
+ "-",
135
+ "--",
136
+ "tbd",
137
+ "todo",
138
+ "none",
139
+ "n/a",
140
+ "null",
141
+ "pending",
142
+ "not-generated",
143
+ "待生成",
144
+ "待制作"
145
+ ];
146
+ function b(e) {
147
+ 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;
148
+ if (!/^[a-z][a-z0-9+.-]*:/i.test(e)) {
149
+ if (e.split(/[?#]/, 1)[0].split("/", 1)[0].includes(":")) return !1;
150
+ let t = e.split(/[?#]/, 1)[0].replace(/%([0-9a-f]{2})/gi, (e, t) => String.fromCharCode(Number.parseInt(t, 16)));
151
+ if (!t || t.endsWith("/") || y.includes(t.trim().toLowerCase())) return !1;
152
+ if (t.includes("/")) return !0;
153
+ let n = t.lastIndexOf(".");
154
+ return n > 0 && n < t.length - 1;
155
+ }
156
+ if (!/^https?:\/\//i.test(e)) return !1;
157
+ let t = e.slice(e.indexOf("://") + 3).split(/[/?#]/, 1)[0];
158
+ if (!t || t.includes("%")) return !1;
159
+ try {
160
+ let t = new URL(e);
161
+ return !!t.hostname && !t.username && !t.password;
162
+ } catch {
163
+ return !1;
164
+ }
165
+ }
166
+ function x(e) {
167
+ let t = /* @__PURE__ */ new Map();
168
+ for (let [n, r] of Object.entries(e)) {
169
+ if (typeof r != "string" || !b(r)) continue;
170
+ let e = t.get(r) ?? [];
171
+ e.push(n), t.set(r, e);
172
+ }
173
+ return t;
174
+ }
175
+ function S(e) {
176
+ if (!e.startsWith("aippy-asset:")) return;
177
+ let t = e.slice(12), n = t.indexOf(":");
178
+ if (n <= 0 || n === t.length - 1) return;
179
+ let r;
180
+ try {
181
+ r = decodeURIComponent(t.slice(0, n));
182
+ } catch {
183
+ return;
184
+ }
185
+ let i = t.slice(n + 1);
186
+ if (!(!r || !b(i))) return {
187
+ key: r,
188
+ url: i
189
+ };
190
+ }
191
+ function C(e) {
192
+ return e.includes("aippy-asset:") ? e.replace(/aippy-asset:[^\s'"`<>()]*?:(?=https?:\/\/)/g, "").replace(/aippy-asset:[^:\s'"`<>()]+:/g, "") : e;
193
+ }
194
+ function w(e, t, n = {}) {
195
+ let r = { ...n }, i = new Set(Object.keys(r));
196
+ for (let [e, n] of t.entries()) i.has(n) || Object.values(r).includes(e) || (r[n] = e, i.add(n));
197
+ for (let t of e.values()) {
198
+ let e = Object.entries(r).find(([, e]) => e === t.originalUri);
199
+ if (e) {
200
+ t.constantName = e[0];
201
+ continue;
202
+ }
203
+ let n = t.constantName, a = n, o = 2;
204
+ for (; i.has(a);) a = `${n}_${o++}`;
205
+ i.add(a), t.constantName = a, r[a] = t.originalUri;
206
+ }
207
+ return JSON.stringify(r, null, 2) + "\n";
208
+ }
209
+ function T(e) {
210
+ let t = /* @__PURE__ */ new Map();
211
+ try {
212
+ if (!e.trim()) return t;
213
+ let n = JSON.parse(e);
214
+ if (v(n)) throw Error("assets: single-file asset plan is not supported");
215
+ if (!n || typeof n != "object" || Array.isArray(n)) throw Error("assets: URL dictionary object required");
216
+ for (let [e, r] of Object.entries(n)) typeof r == "string" && t.set(r, e);
217
+ t.size > 0 && console.log(`📋 Found ${t.size} existing constants in assets.json`);
218
+ } catch (e) {
219
+ throw e instanceof Error && e.message.startsWith("assets:") ? e : Error("assets: invalid JSON syntax");
220
+ }
221
+ return t;
222
+ }
223
+ function E(e, t, n, r) {
224
+ let i = Array.from(n.values()).filter((e) => t.has(e.originalUri)).length, a = e - i;
225
+ 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");
226
+ }
227
+ //#endregion
228
+ export { S as a, m as c, h as d, f, c as g, u as h, E as i, _ as l, l as m, w as n, T as o, d as p, v as r, C as s, x as t, g as u };
@@ -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 { t as a } from "../asset-constants-BUK7zWRd.js";
3
- import { t as o } from "../aippy-preload-Dhhw3O6d.js";
2
+ import { assetConstantsPlugin as a } from "../asset-constants/index.js";
3
+ import { t as o } from "../aippy-preload-BjhVTEKH.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 };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aippy/vite-plugins",
3
- "version": "0.4.0-dev.2",
3
+ "version": "0.4.0-dev.4",
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,170 +0,0 @@
1
- import { extractAssetsFromContent as e } from "./utils/index.js";
2
- import { d as t, i as n, o as r, r as i, t as a } from "./manifest-DQGCd9CQ.js";
3
- import { promises as o } from "fs";
4
- import s from "path";
5
- //#region src/aippy-preload/scanner-utils.ts
6
- async function c(t) {
7
- let n = [], r = [s.join(process.cwd(), "index.html")];
8
- for (let i of r) try {
9
- let r = await o.readFile(i, "utf-8"), a = e(r, "html", t);
10
- n.push(...a);
11
- } catch {
12
- console.warn("⚠️ No index.html found in project root");
13
- }
14
- return n;
15
- }
16
- async function l(a, c) {
17
- let l = [], u = s.resolve(a, "config/assets.json"), d;
18
- try {
19
- let e = n(await o.readFile(u, "utf8"));
20
- i(e) && (d = e);
21
- } catch {}
22
- let f = await t(a, [
23
- ".ts",
24
- ".tsx",
25
- ".js",
26
- ".jsx"
27
- ]);
28
- for (let t of f) try {
29
- if (d && s.resolve(t) === u.replace(/\.json$/, ".ts")) continue;
30
- let n = await o.readFile(t, "utf-8"), i = e(n, "js", c);
31
- d && i.some((e) => Object.hasOwn(d.assets, e)) && (i = e(r(n, t, a, u), "js", c)), l.push(...i);
32
- } catch (e) {
33
- console.warn(`⚠️ Failed to read JS file: ${t}`, e);
34
- }
35
- return l;
36
- }
37
- async function u(n, r) {
38
- let i = [], a = await t(n, [
39
- ".css",
40
- ".scss",
41
- ".sass",
42
- ".less"
43
- ]);
44
- for (let t of a) try {
45
- let n = await o.readFile(t, "utf-8"), a = e(n, "css", r);
46
- i.push(...a);
47
- } catch (e) {
48
- console.warn(`⚠️ Failed to read CSS file: ${t}`, e);
49
- }
50
- return i;
51
- }
52
- async function d(r, c) {
53
- let l = [], u = await t(r, [".json"]);
54
- for (let t of u) try {
55
- let r = await o.readFile(t, "utf-8");
56
- if (s.basename(t) === "assets.json") {
57
- let e = JSON.parse(r);
58
- if (e && Object.prototype.hasOwnProperty.call(e, "schemaVersion")) {
59
- let e = n(r);
60
- if (i(e)) {
61
- l.push(...Object.values(a(e)));
62
- continue;
63
- }
64
- }
65
- }
66
- let u = e(r, "js", c);
67
- l.push(...u);
68
- } catch (e) {
69
- console.warn(`⚠️ Failed to read JSON file: ${t}`, e);
70
- }
71
- return l;
72
- }
73
- async function f(e, t, n) {
74
- console.log("🔍 Scanning source files for static assets...");
75
- let r = [];
76
- if (n) {
77
- console.log("🔍 Deep scanning source file contents...");
78
- let [n, i, a, o] = await Promise.all([
79
- c(t),
80
- l(e, t),
81
- u(e, t),
82
- d(e, t)
83
- ]);
84
- r.push(...n, ...i, ...a, ...o);
85
- }
86
- return [...new Set(r)];
87
- }
88
- //#endregion
89
- //#region src/aippy-preload/html-utils.ts
90
- var p = "<head>", m = 6;
91
- function h(e) {
92
- return e.map((e) => ` <meta content="${e}" name="aippy:preload">`).join("\n");
93
- }
94
- function g(e, t) {
95
- let n = e.indexOf(p);
96
- if (n === -1) throw Error("Could not find <head> tag in HTML");
97
- let r = n + m;
98
- return e.slice(0, r) + "\n" + t + "\n" + e.slice(r);
99
- }
100
- function _(e) {
101
- let t = e.length;
102
- if (console.log(`📁 Found ${t} static ${t === 1 ? "asset" : "assets"} in source files`), t === 0) {
103
- console.log("⚠️ No static assets found in source files.");
104
- return;
105
- }
106
- console.log(`📋 ${t === 1 ? "Asset" : "Assets"} found:`), e.forEach((e) => console.log(` - ${e}`));
107
- }
108
- function v(e) {
109
- console.log(`✅ Injected ${e} preload meta ${e === 1 ? "tag" : "tags"} into index.html`);
110
- }
111
- //#endregion
112
- //#region src/aippy-preload/index.ts
113
- var y = 3, b = 1e3;
114
- function x(e) {
115
- return new Promise((t) => setTimeout(t, e));
116
- }
117
- async function S(e, t = y, n = b) {
118
- for (let r = 1; r <= t; r++) try {
119
- return await o.readFile(e, "utf-8");
120
- } catch (e) {
121
- if (e.code === "ENOENT") {
122
- if (r < t) {
123
- console.log(`⏳ index.html not found, waiting ${n}ms before retry (attempt ${r}/${t})...`), await x(n);
124
- continue;
125
- }
126
- return console.log(`⚠️ index.html not found after ${t} attempts, skipping preload injection.`), null;
127
- }
128
- return console.error("❌ Error reading index.html:", e), null;
129
- }
130
- return null;
131
- }
132
- function C(e = {}) {
133
- let t = {
134
- extensions: [
135
- ".png",
136
- ".jpg",
137
- ".jpeg",
138
- ".gif",
139
- ".svg",
140
- ".mp4",
141
- ".mp3",
142
- ".wav",
143
- ".ogg",
144
- ".webm"
145
- ],
146
- srcDir: "src",
147
- outDir: "dist",
148
- deepScan: !0,
149
- ...e
150
- };
151
- return {
152
- name: "vite-plugin-aippy-preload",
153
- apply: "build",
154
- enforce: "post",
155
- async writeBundle() {
156
- try {
157
- let e = await f(t.srcDir, t.extensions, t.deepScan);
158
- if (_(e), e.length === 0) return;
159
- let n = s.join(t.outDir, "index.html"), r = await S(n);
160
- if (r === null) return;
161
- let i = g(r, h(e));
162
- await o.writeFile(n, i, "utf-8"), v(e.length);
163
- } catch (e) {
164
- console.error("❌ Error in aippy preload plugin:", e);
165
- }
166
- }
167
- };
168
- }
169
- //#endregion
170
- export { C as t };
@@ -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;