@aippy/vite-plugins 0.4.0-dev.3 → 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.
- package/README.md +6 -2
- package/dist/aippy-preload/index.js +1 -1
- package/dist/{aippy-preload-DtngFmJ5.js → aippy-preload-BjhVTEKH.js} +63 -74
- package/dist/asset-constants/generator-utils.d.ts +27 -0
- package/dist/asset-constants/index.js +168 -102
- package/dist/asset-constants/wrapper-keys.d.ts +1 -0
- package/dist/generator-utils-VznlFF00.js +228 -0
- package/dist/index/index.js +1 -1
- package/package.json +3 -5
- package/dist/asset-constants/manifest.d.ts +0 -53
- package/dist/generator-utils-CFYv7n_h.js +0 -435
- package/src/asset-constants/assets.schema.json +0 -239
|
@@ -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 };
|
package/dist/index/index.js
CHANGED
|
@@ -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
2
|
import { assetConstantsPlugin as a } from "../asset-constants/index.js";
|
|
3
|
-
import { t as o } from "../aippy-preload-
|
|
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.
|
|
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,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;
|