@auspex-ai/next 0.0.0-stage → 1.4.1
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/LICENSE +202 -0
- package/README.md +49 -2
- package/dist/config.cjs +700 -0
- package/dist/config.d.cts +54 -0
- package/dist/config.d.mts +54 -0
- package/dist/config.mjs +691 -0
- package/dist/icon-name-loader.cjs +1156 -0
- package/dist/index.cjs +169 -0
- package/dist/index.d.cts +41 -0
- package/dist/index.d.mts +41 -0
- package/dist/index.mjs +146 -0
- package/dist/register-names-cli.mjs +390 -0
- package/dist/rolldown-runtime-VH7oDXx4.cjs +28 -0
- package/dist/svg-name-loader.cjs +18 -0
- package/dist/transform-Dc5diC_P.cjs +441 -0
- package/package.json +76 -3
|
@@ -0,0 +1,441 @@
|
|
|
1
|
+
//#region \0rolldown/runtime.js
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
10
|
+
key = keys[i];
|
|
11
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
12
|
+
get: ((k) => from[k]).bind(null, key),
|
|
13
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp(target, "default", {
|
|
19
|
+
value: mod,
|
|
20
|
+
enumerable: true
|
|
21
|
+
}) : target, mod));
|
|
22
|
+
//#endregion
|
|
23
|
+
let node_path = require("node:path");
|
|
24
|
+
node_path = __toESM(node_path, 1);
|
|
25
|
+
let node_crypto = require("node:crypto");
|
|
26
|
+
let node_fs = require("node:fs");
|
|
27
|
+
let _babel_parser = require("@babel/parser");
|
|
28
|
+
require("magic-string");
|
|
29
|
+
//#region ../build-names/src/element-ref.ts
|
|
30
|
+
const ALPHABET = "abcdefghijklmnopqrstuvwxyz234567";
|
|
31
|
+
const REF_LENGTH = 12;
|
|
32
|
+
/** RFC 4648 の base32 を小文字・パディング無しにしたもの */
|
|
33
|
+
function base32(bytes) {
|
|
34
|
+
let out = "";
|
|
35
|
+
let bits = 0;
|
|
36
|
+
let acc = 0;
|
|
37
|
+
for (const b of bytes) {
|
|
38
|
+
acc = acc << 8 | b;
|
|
39
|
+
bits += 8;
|
|
40
|
+
while (bits >= 5) {
|
|
41
|
+
out += ALPHABET[acc >>> bits - 5 & 31];
|
|
42
|
+
bits -= 5;
|
|
43
|
+
}
|
|
44
|
+
acc &= (1 << bits) - 1;
|
|
45
|
+
}
|
|
46
|
+
if (bits > 0) out += ALPHABET[acc << 5 - bits & 31];
|
|
47
|
+
return out;
|
|
48
|
+
}
|
|
49
|
+
/** 名前の参照(`^[a-z2-7]{12}$`)。ビルド鍵は UTF-8 のバイト列として HMAC の鍵にする */
|
|
50
|
+
function nameRef(key, name, kind) {
|
|
51
|
+
return base32((0, node_crypto.createHmac)("sha256", Buffer.from(key, "utf8")).update(`${kind}:${name}`).digest()).slice(0, REF_LENGTH);
|
|
52
|
+
}
|
|
53
|
+
/** sha256(ビルド鍵)の先頭 16 文字(16 進)。秘密ではなく(先頭 64 bit から鍵は戻せない)、キャッシュやオプションに残ってよい */
|
|
54
|
+
function keyIdOf(key) {
|
|
55
|
+
return (0, node_crypto.createHash)("sha256").update(key, "utf8").digest("hex").slice(0, 16);
|
|
56
|
+
}
|
|
57
|
+
//#endregion
|
|
58
|
+
//#region ../build-names/src/log.ts
|
|
59
|
+
const WARNED = Symbol.for("auspex.warned");
|
|
60
|
+
const PREFIX = "[auspex]";
|
|
61
|
+
const consoleLogger = {
|
|
62
|
+
info: (m) => console.log(`${PREFIX} ${m}`),
|
|
63
|
+
warn: (m) => console.warn(`${PREFIX} ${m}`)
|
|
64
|
+
};
|
|
65
|
+
/** `id` の警告を、このプロセスでまだ出していなければ出す(出したら true) */
|
|
66
|
+
function warnOnce(id, message, logger = consoleLogger) {
|
|
67
|
+
const g = globalThis;
|
|
68
|
+
const seen = g[WARNED] ?? /* @__PURE__ */ new Set();
|
|
69
|
+
g[WARNED] = seen;
|
|
70
|
+
if (seen.has(id)) return false;
|
|
71
|
+
seen.add(id);
|
|
72
|
+
logger.warn(message);
|
|
73
|
+
return true;
|
|
74
|
+
}
|
|
75
|
+
//#endregion
|
|
76
|
+
//#region ../build-names/src/icon-name/shared.ts
|
|
77
|
+
let downgraded = 0;
|
|
78
|
+
let exitHooked = false;
|
|
79
|
+
/** 参照を書くはずだったのに 'strip' に落ちたモジュールの数を、プロセスの終わり(最善努力)にログへ出す */
|
|
80
|
+
function countDowngrade() {
|
|
81
|
+
downgraded++;
|
|
82
|
+
if (exitHooked) return;
|
|
83
|
+
exitHooked = true;
|
|
84
|
+
process.once("exit", () => {
|
|
85
|
+
console.warn(`[auspex] ビルド鍵が無い、または withAuspex() が見た鍵と違うため、参照を書かなかったモジュール: ${downgraded} 件`);
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
/** 断片を原子的に書く(一時ファイル + rename)。書けなくてもビルドは続ける */
|
|
89
|
+
function writeFragment(dir, file, fragment) {
|
|
90
|
+
const name = `${(0, node_crypto.createHash)("sha256").update(file).digest("hex").slice(0, 16)}.json`;
|
|
91
|
+
const target = node_path.default.join(dir, name);
|
|
92
|
+
const tmp = `${target}.${process.pid}.${Math.random().toString(36).slice(2)}.tmp`;
|
|
93
|
+
try {
|
|
94
|
+
(0, node_fs.mkdirSync)(dir, { recursive: true });
|
|
95
|
+
(0, node_fs.writeFileSync)(tmp, JSON.stringify(fragment));
|
|
96
|
+
(0, node_fs.renameSync)(tmp, target);
|
|
97
|
+
} catch (e) {
|
|
98
|
+
warnOnce("fragment-write", `[auspex] 名前の断片を書けなかった(${dir}: ${e.message})。この名前は登録されない`);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* 参照を書くモードのとき、鍵を確かめて参照の計算を返す。鍵が無い・`options.keyId` と違うときは null
|
|
103
|
+
* (古い参照を書かず 'strip' に落ちる。警告は 1 回、数はプロセスの終わりに出す)。'strip' のモードは null(警告なし)
|
|
104
|
+
*/
|
|
105
|
+
function refOfFromEnv(options) {
|
|
106
|
+
if (options.elementNames !== "refs") return null;
|
|
107
|
+
const key = process.env.AUSPEX_BUILD_KEY;
|
|
108
|
+
if (key && (options.keyId === void 0 || keyIdOf(key) === options.keyId)) return (name, kind) => nameRef(key, name, kind);
|
|
109
|
+
countDowngrade();
|
|
110
|
+
warnOnce("loader-key-mismatch", key ? "[auspex] AUSPEX_BUILD_KEY が withAuspex() の読み込み時と違う(next.config を読んだ後に変わった)ため、参照を書かない" : "[auspex] AUSPEX_BUILD_KEY が読めないため、参照を書かない(ワーカーに環境変数が届いていない可能性がある)");
|
|
111
|
+
return null;
|
|
112
|
+
}
|
|
113
|
+
//#endregion
|
|
114
|
+
//#region ../build-names/src/icon-name/transform.ts
|
|
115
|
+
/** 書く属性。@auspex-ai/core の ICON_REF_ATTR(読む側)と同じ値(test/ で一致を確かめる) */
|
|
116
|
+
const ICON_REF_ATTR = "data-auspex-icon-ref";
|
|
117
|
+
/** #12 の旧属性(平文の名前)。今は書かず、手書きのものを消すだけ */
|
|
118
|
+
const LEGACY_ICON_ATTR = "data-auspex-icon";
|
|
119
|
+
const ATTR = ICON_REF_ATTR;
|
|
120
|
+
/** 自分の名前を使わない汎用名(名前は呼び出し側の props か、外から渡された値で決まる) */
|
|
121
|
+
const GENERIC = /^(Icon|Icons|IconBase|BaseIcon|Svg|SvgIcon|IconWrapper|Glyph|StyledSvg)$/;
|
|
122
|
+
/** アイコンらしい名前(呼び出し側の名前 props を拾う対象、根に返すと自分の名前を渡す対象) */
|
|
123
|
+
const ICONISH = /Icon|Svg|Glyph/;
|
|
124
|
+
/** 名前を表す props。type は汎用名の要素だけ(<Button type="submit"> 等を拾わないため) */
|
|
125
|
+
const NAME_PROPS = [
|
|
126
|
+
"name",
|
|
127
|
+
"icon",
|
|
128
|
+
"iconName",
|
|
129
|
+
"glyph"
|
|
130
|
+
];
|
|
131
|
+
const NAME_PROPS_GENERIC = [...NAME_PROPS, "type"];
|
|
132
|
+
const SKIP_KEYS = /* @__PURE__ */ new Set([
|
|
133
|
+
"loc",
|
|
134
|
+
"start",
|
|
135
|
+
"end",
|
|
136
|
+
"extra",
|
|
137
|
+
"range",
|
|
138
|
+
"leadingComments",
|
|
139
|
+
"trailingComments",
|
|
140
|
+
"innerComments"
|
|
141
|
+
]);
|
|
142
|
+
/** AST を深さ優先でたどる。stopAtFunctions なら入れ子の関数の中には入らない */
|
|
143
|
+
function walk(node, visit, stopAtFunctions = false, root = true) {
|
|
144
|
+
visit(node);
|
|
145
|
+
if (stopAtFunctions && !root && /Function|ClassMethod/.test(node.type)) return;
|
|
146
|
+
for (const key of Object.keys(node)) {
|
|
147
|
+
if (SKIP_KEYS.has(key)) continue;
|
|
148
|
+
const v = node[key];
|
|
149
|
+
if (Array.isArray(v)) {
|
|
150
|
+
for (const c of v) if (c && typeof c.type === "string") walk(c, visit, stopAtFunctions, false);
|
|
151
|
+
} else if (v && typeof v.type === "string") walk(v, visit, stopAtFunctions, false);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
function calleeName(c) {
|
|
155
|
+
if (c.type === "Identifier") return c.name;
|
|
156
|
+
if (c.type === "MemberExpression" && c.property.type === "Identifier") return c.property.name;
|
|
157
|
+
return "";
|
|
158
|
+
}
|
|
159
|
+
/** forwardRef(...) / memo(...) / 型注釈の包みを剥がして関数を取り出す */
|
|
160
|
+
function unwrapFn(e) {
|
|
161
|
+
let n = e;
|
|
162
|
+
while (n && (n.type === "TSAsExpression" || n.type === "TSSatisfiesExpression" || n.type === "ParenthesizedExpression")) n = n.expression;
|
|
163
|
+
if (!n) return null;
|
|
164
|
+
if (n.type === "ArrowFunctionExpression" || n.type === "FunctionExpression") return n;
|
|
165
|
+
if (n.type === "CallExpression" && ["forwardRef", "memo"].includes(calleeName(n.callee))) {
|
|
166
|
+
const [arg] = n.arguments;
|
|
167
|
+
return arg && arg.type !== "SpreadElement" && arg.type !== "ArgumentPlaceholder" ? unwrapFn(arg) : null;
|
|
168
|
+
}
|
|
169
|
+
return null;
|
|
170
|
+
}
|
|
171
|
+
function tagName(o) {
|
|
172
|
+
if (o.name.type === "JSXIdentifier") return o.name.name;
|
|
173
|
+
if (o.name.type === "JSXMemberExpression") return o.name.property.name;
|
|
174
|
+
return "";
|
|
175
|
+
}
|
|
176
|
+
/** ビルド時に値が決まる文字列: リテラル / 式を含まないテンプレートリテラル / 両辺がそうである条件式 */
|
|
177
|
+
function isStaticString(e) {
|
|
178
|
+
if (!e) return false;
|
|
179
|
+
switch (e.type) {
|
|
180
|
+
case "StringLiteral": return true;
|
|
181
|
+
case "TemplateLiteral": return e.expressions.length === 0;
|
|
182
|
+
case "ConditionalExpression": return isStaticString(e.consequent) && isStaticString(e.alternate);
|
|
183
|
+
case "ParenthesizedExpression": return isStaticString(e.expression);
|
|
184
|
+
default: return false;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
/** アイコンらしい要素で、名前を表す props が静的な文字列ならその式を返す */
|
|
188
|
+
function staticNameProp(o) {
|
|
189
|
+
const tag = tagName(o);
|
|
190
|
+
if (!/^[A-Z]/.test(tag) || !ICONISH.test(tag)) return null;
|
|
191
|
+
const props = GENERIC.test(tag) ? NAME_PROPS_GENERIC : NAME_PROPS;
|
|
192
|
+
for (const a of o.attributes) {
|
|
193
|
+
if (a.type !== "JSXAttribute" || a.name.type !== "JSXIdentifier" || !props.includes(a.name.name) || !a.value) continue;
|
|
194
|
+
const v = a.value.type === "JSXExpressionContainer" ? a.value.expression : a.value;
|
|
195
|
+
if (isStaticString(v)) return v;
|
|
196
|
+
}
|
|
197
|
+
return null;
|
|
198
|
+
}
|
|
199
|
+
/** 名前を表す props を受け取るコンポーネントは汎用とみなす */
|
|
200
|
+
function takesNameProp(fn) {
|
|
201
|
+
const [p0] = fn.params;
|
|
202
|
+
return p0?.type === "ObjectPattern" && p0.properties.some((p) => p.type === "ObjectProperty" && p.key.type === "Identifier" && NAME_PROPS_GENERIC.includes(p.key.name));
|
|
203
|
+
}
|
|
204
|
+
function collectComponents(program, file) {
|
|
205
|
+
const comps = [];
|
|
206
|
+
const base = node_path.default.basename(file).replace(/\.[^.]+$/, "");
|
|
207
|
+
walk(program, (n) => {
|
|
208
|
+
if (n.type === "FunctionDeclaration" && n.id) comps.push({
|
|
209
|
+
fn: n,
|
|
210
|
+
name: n.id.name,
|
|
211
|
+
isClass: false
|
|
212
|
+
});
|
|
213
|
+
else if (n.type === "VariableDeclarator" && n.id.type === "Identifier") {
|
|
214
|
+
const fn = unwrapFn(n.init);
|
|
215
|
+
if (fn) comps.push({
|
|
216
|
+
fn,
|
|
217
|
+
name: n.id.name,
|
|
218
|
+
isClass: false
|
|
219
|
+
});
|
|
220
|
+
} else if (n.type === "ObjectProperty" && !n.computed) {
|
|
221
|
+
const fn = unwrapFn(n.value);
|
|
222
|
+
const key = n.key.type === "Identifier" ? n.key.name : n.key.type === "StringLiteral" ? n.key.value : null;
|
|
223
|
+
if (fn && key) comps.push({
|
|
224
|
+
fn,
|
|
225
|
+
name: key,
|
|
226
|
+
isClass: false
|
|
227
|
+
});
|
|
228
|
+
} else if (n.type === "ExportDefaultDeclaration") {
|
|
229
|
+
const d = n.declaration;
|
|
230
|
+
const fn = d.type === "FunctionDeclaration" ? d.id ? null : d : unwrapFn(d);
|
|
231
|
+
if (fn) comps.push({
|
|
232
|
+
fn,
|
|
233
|
+
name: base,
|
|
234
|
+
isClass: false
|
|
235
|
+
});
|
|
236
|
+
} else if (n.type === "ClassDeclaration" && n.id) {
|
|
237
|
+
const render = n.body.body.find((m) => m.type === "ClassMethod" && m.key.type === "Identifier" && m.key.name === "render");
|
|
238
|
+
if (render) comps.push({
|
|
239
|
+
fn: render,
|
|
240
|
+
name: n.id.name,
|
|
241
|
+
isClass: true
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
});
|
|
245
|
+
return comps;
|
|
246
|
+
}
|
|
247
|
+
/** コンポーネントが返す根の要素(return / 式本体 / 条件式の両辺 / && の右辺 / フラグメントの最初の要素) */
|
|
248
|
+
function rootsOf(fn) {
|
|
249
|
+
const roots = [];
|
|
250
|
+
const add = (e) => {
|
|
251
|
+
let n = e;
|
|
252
|
+
while (n && (n.type === "ParenthesizedExpression" || n.type === "TSAsExpression")) n = n.expression;
|
|
253
|
+
if (!n) return;
|
|
254
|
+
if (n.type === "JSXElement") roots.push({ jsx: n.openingElement });
|
|
255
|
+
else if (n.type === "ConditionalExpression") {
|
|
256
|
+
add(n.consequent);
|
|
257
|
+
add(n.alternate);
|
|
258
|
+
} else if (n.type === "LogicalExpression") add(n.right);
|
|
259
|
+
else if (n.type === "JSXFragment") {
|
|
260
|
+
const first = n.children.find((c) => c.type === "JSXElement");
|
|
261
|
+
if (first) roots.push({ jsx: first.openingElement });
|
|
262
|
+
} else if (n.type === "CallExpression" && [
|
|
263
|
+
"createElement",
|
|
264
|
+
"jsx",
|
|
265
|
+
"jsxs",
|
|
266
|
+
"_jsx",
|
|
267
|
+
"_jsxs"
|
|
268
|
+
].includes(calleeName(n.callee)) && n.arguments[0]?.type === "StringLiteral" && n.arguments[0].value === "svg") roots.push({ call: n });
|
|
269
|
+
};
|
|
270
|
+
if (fn.body.type !== "BlockStatement") add(fn.body);
|
|
271
|
+
else walk(fn.body, (n) => n.type === "ReturnStatement" && add(n.argument), true);
|
|
272
|
+
return roots;
|
|
273
|
+
}
|
|
274
|
+
const startOf = (n) => n.start ?? 0;
|
|
275
|
+
const endOf = (n) => n.end ?? 0;
|
|
276
|
+
/** JS/TS のソースを解析する(解析できなければ null。ビルドはバンドラ側のエラーに任せる) */
|
|
277
|
+
function parseSource(source, file) {
|
|
278
|
+
const ext = node_path.default.extname(file);
|
|
279
|
+
try {
|
|
280
|
+
return (0, _babel_parser.parse)(source, {
|
|
281
|
+
sourceType: "module",
|
|
282
|
+
plugins: ext === ".ts" ? ["typescript"] : ext === ".tsx" ? ["typescript", "jsx"] : ["jsx"]
|
|
283
|
+
}).program;
|
|
284
|
+
} catch {
|
|
285
|
+
return null;
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
/** アイコンに関係しうるファイルか(解析する前の絞り込み) */
|
|
289
|
+
function mayHaveIcons(source) {
|
|
290
|
+
return /svg|Icon|Glyph/.test(source);
|
|
291
|
+
}
|
|
292
|
+
/**
|
|
293
|
+
* アイコン名の参照の書き込みを `s` に積む(要素名の変換と同じ MagicString に積めるよう分けている。手書きの属性の削除は
|
|
294
|
+
* 先に stripHandWritten で積む)。参照を書いた名前を返す
|
|
295
|
+
*/
|
|
296
|
+
function applyIconNames(program, source, file, s, refOf) {
|
|
297
|
+
const touched = /* @__PURE__ */ new Set();
|
|
298
|
+
const written = /* @__PURE__ */ new Set();
|
|
299
|
+
const refLiteral = (name) => {
|
|
300
|
+
written.add(name);
|
|
301
|
+
return JSON.stringify(refOf(name));
|
|
302
|
+
};
|
|
303
|
+
/** 静的な文字列の式を、各リテラルを参照に置き換えた式にする(名前は written に残る) */
|
|
304
|
+
const refExpr = (e) => {
|
|
305
|
+
switch (e.type) {
|
|
306
|
+
case "StringLiteral": return refLiteral(e.value);
|
|
307
|
+
case "TemplateLiteral": return refLiteral(e.quasis[0]?.value.cooked ?? "");
|
|
308
|
+
case "ConditionalExpression": return `${source.slice(startOf(e.test), endOf(e.test))} ? ${refExpr(e.consequent)} : ${refExpr(e.alternate)}`;
|
|
309
|
+
case "ParenthesizedExpression": return `(${refExpr(e.expression)})`;
|
|
310
|
+
default: return "undefined";
|
|
311
|
+
}
|
|
312
|
+
};
|
|
313
|
+
for (const { fn, name, isClass } of collectComponents(program, file)) {
|
|
314
|
+
const roots = rootsOf(fn);
|
|
315
|
+
const svgRoots = roots.flatMap((r) => "jsx" in r && tagName(r.jsx) === "svg" ? [r.jsx] : []);
|
|
316
|
+
const callRoots = roots.flatMap((r) => "call" in r ? [r.call] : []);
|
|
317
|
+
const iconishRoots = roots.flatMap((r) => "jsx" in r && /^[A-Z]/.test(tagName(r.jsx)) && ICONISH.test(tagName(r.jsx)) ? [r.jsx] : []);
|
|
318
|
+
if (!svgRoots.length && !callRoots.length && !iconishRoots.length) continue;
|
|
319
|
+
const generic = GENERIC.test(name) || !isClass && takesNameProp(fn);
|
|
320
|
+
let passed = null;
|
|
321
|
+
const [p0] = fn.params;
|
|
322
|
+
if (isClass) passed = `this.props?.[${JSON.stringify(ATTR)}]`;
|
|
323
|
+
else if (p0?.type === "ObjectPattern") {
|
|
324
|
+
s.appendRight(startOf(p0) + 1, ` ${JSON.stringify(ATTR)}: __auspexIcon,`);
|
|
325
|
+
passed = "__auspexIcon";
|
|
326
|
+
} else if (p0?.type === "Identifier") passed = `${p0.name}?.[${JSON.stringify(ATTR)}]`;
|
|
327
|
+
let cached;
|
|
328
|
+
const iconValue = () => {
|
|
329
|
+
if (cached === void 0) {
|
|
330
|
+
const own = generic ? "undefined" : refLiteral(name);
|
|
331
|
+
cached = passed ? `${passed} ?? ${own}` : own;
|
|
332
|
+
}
|
|
333
|
+
return cached;
|
|
334
|
+
};
|
|
335
|
+
for (const o of svgRoots) {
|
|
336
|
+
if (touched.has(o)) continue;
|
|
337
|
+
s.appendLeft(endOf(o.name), ` ${ATTR}={${iconValue()}}`);
|
|
338
|
+
touched.add(o);
|
|
339
|
+
}
|
|
340
|
+
for (const call of callRoots) {
|
|
341
|
+
const props = call.arguments[1];
|
|
342
|
+
const entry = `${JSON.stringify(ATTR)}: ${iconValue()}`;
|
|
343
|
+
if (!props) {
|
|
344
|
+
const tagArg = call.arguments[0];
|
|
345
|
+
if (tagArg) s.appendLeft(endOf(tagArg), `, { ${entry} }`);
|
|
346
|
+
} else if (props.type === "NullLiteral") s.overwrite(startOf(props), endOf(props), `{ ${entry} }`);
|
|
347
|
+
else if (props.type === "ObjectExpression") s.appendRight(startOf(props) + 1, ` ${entry},`);
|
|
348
|
+
else {
|
|
349
|
+
s.prependLeft(startOf(props), "{ ...");
|
|
350
|
+
s.appendRight(endOf(props), `, ${entry} }`);
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
for (const o of iconishRoots) {
|
|
354
|
+
if (touched.has(o) || staticNameProp(o)) continue;
|
|
355
|
+
if (generic && !passed) continue;
|
|
356
|
+
s.appendLeft(endOf(o.name), ` ${ATTR}={${generic ? passed : iconValue()}}`);
|
|
357
|
+
touched.add(o);
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
walk(program, (n) => {
|
|
361
|
+
if (n.type !== "JSXOpeningElement" || touched.has(n)) return;
|
|
362
|
+
const v = staticNameProp(n);
|
|
363
|
+
if (!v) return;
|
|
364
|
+
s.appendLeft(endOf(n.name), ` ${ATTR}={${refExpr(v)}}`);
|
|
365
|
+
touched.add(n);
|
|
366
|
+
});
|
|
367
|
+
return [...written];
|
|
368
|
+
}
|
|
369
|
+
/** .svg のソースから手書きの data-auspex-icon・data-auspex-icon-ref を消す(SVGR が props にして HTML に載せるため) */
|
|
370
|
+
const HAND_WRITTEN_SVG_ATTR = /\s+data-auspex-icon(?:-ref)?\s*=\s*(?:"[^"]*"|'[^']*')/g;
|
|
371
|
+
/**
|
|
372
|
+
* .svg ファイル(SVGR の前段)。手書きの属性を消し、`refOf` があれば根の <svg> にファイル名の参照を書く
|
|
373
|
+
* (strip のみのときは書かない)。変更が無ければ null。書いた名前は `name`
|
|
374
|
+
*/
|
|
375
|
+
function transformSvgFile(source, file, refOf) {
|
|
376
|
+
const stripped = source.replace(HAND_WRITTEN_SVG_ATTR, "");
|
|
377
|
+
const name = node_path.default.basename(file).replace(/\.svg$/i, "").replace(/[^A-Za-z0-9_:-]/g, "-").slice(0, 64);
|
|
378
|
+
if (!refOf || !name || !/<svg\b/.test(stripped)) return stripped === source ? null : {
|
|
379
|
+
code: stripped,
|
|
380
|
+
name: null
|
|
381
|
+
};
|
|
382
|
+
return {
|
|
383
|
+
code: stripped.replace(/<svg\b/, `<svg ${ATTR}="${refOf(name)}"`),
|
|
384
|
+
name
|
|
385
|
+
};
|
|
386
|
+
}
|
|
387
|
+
//#endregion
|
|
388
|
+
Object.defineProperty(exports, "ICON_REF_ATTR", {
|
|
389
|
+
enumerable: true,
|
|
390
|
+
get: function() {
|
|
391
|
+
return ICON_REF_ATTR;
|
|
392
|
+
}
|
|
393
|
+
});
|
|
394
|
+
Object.defineProperty(exports, "LEGACY_ICON_ATTR", {
|
|
395
|
+
enumerable: true,
|
|
396
|
+
get: function() {
|
|
397
|
+
return LEGACY_ICON_ATTR;
|
|
398
|
+
}
|
|
399
|
+
});
|
|
400
|
+
Object.defineProperty(exports, "__toESM", {
|
|
401
|
+
enumerable: true,
|
|
402
|
+
get: function() {
|
|
403
|
+
return __toESM;
|
|
404
|
+
}
|
|
405
|
+
});
|
|
406
|
+
Object.defineProperty(exports, "applyIconNames", {
|
|
407
|
+
enumerable: true,
|
|
408
|
+
get: function() {
|
|
409
|
+
return applyIconNames;
|
|
410
|
+
}
|
|
411
|
+
});
|
|
412
|
+
Object.defineProperty(exports, "mayHaveIcons", {
|
|
413
|
+
enumerable: true,
|
|
414
|
+
get: function() {
|
|
415
|
+
return mayHaveIcons;
|
|
416
|
+
}
|
|
417
|
+
});
|
|
418
|
+
Object.defineProperty(exports, "parseSource", {
|
|
419
|
+
enumerable: true,
|
|
420
|
+
get: function() {
|
|
421
|
+
return parseSource;
|
|
422
|
+
}
|
|
423
|
+
});
|
|
424
|
+
Object.defineProperty(exports, "refOfFromEnv", {
|
|
425
|
+
enumerable: true,
|
|
426
|
+
get: function() {
|
|
427
|
+
return refOfFromEnv;
|
|
428
|
+
}
|
|
429
|
+
});
|
|
430
|
+
Object.defineProperty(exports, "transformSvgFile", {
|
|
431
|
+
enumerable: true,
|
|
432
|
+
get: function() {
|
|
433
|
+
return transformSvgFile;
|
|
434
|
+
}
|
|
435
|
+
});
|
|
436
|
+
Object.defineProperty(exports, "writeFragment", {
|
|
437
|
+
enumerable: true,
|
|
438
|
+
get: function() {
|
|
439
|
+
return writeFragment;
|
|
440
|
+
}
|
|
441
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,79 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@auspex-ai/next",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "1.4.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"sideEffects": false,
|
|
6
|
+
"license": "Apache-2.0",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/NA-LUDENS/auspex.git",
|
|
10
|
+
"directory": "packages/next"
|
|
11
|
+
},
|
|
12
|
+
"publishConfig": {
|
|
13
|
+
"access": "public"
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist"
|
|
17
|
+
],
|
|
18
|
+
"exports": {
|
|
19
|
+
".": {
|
|
20
|
+
"types": "./dist/index.d.mts",
|
|
21
|
+
"import": "./dist/index.mjs",
|
|
22
|
+
"require": "./dist/index.cjs"
|
|
23
|
+
},
|
|
24
|
+
"./config": {
|
|
25
|
+
"types": "./dist/config.d.mts",
|
|
26
|
+
"import": "./dist/config.mjs",
|
|
27
|
+
"require": "./dist/config.cjs"
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
"bin": {
|
|
31
|
+
"auspex-register-names": "./dist/register-names-cli.mjs"
|
|
32
|
+
},
|
|
33
|
+
"main": "./dist/index.cjs",
|
|
34
|
+
"module": "./dist/index.mjs",
|
|
35
|
+
"types": "./dist/index.d.mts",
|
|
36
|
+
"dependencies": {
|
|
37
|
+
"@auspex-ai/core": "^1.4.1",
|
|
38
|
+
"@babel/parser": "^7.29.8",
|
|
39
|
+
"magic-string": "^1.4.1"
|
|
40
|
+
},
|
|
41
|
+
"peerDependencies": {
|
|
42
|
+
"next": ">=14",
|
|
43
|
+
"react": ">=18",
|
|
44
|
+
"google-auth-library": ">=9"
|
|
45
|
+
},
|
|
46
|
+
"devDependencies": {
|
|
47
|
+
"@auspex-ai/build-names": "0.0.0",
|
|
48
|
+
"@babel/types": "^7.29.8",
|
|
49
|
+
"@svgr/webpack": "^8.1.0",
|
|
50
|
+
"@types/node": "^22.20.3",
|
|
51
|
+
"@types/react": "^19.3.0",
|
|
52
|
+
"@types/react-dom": "^19.3.0",
|
|
53
|
+
"google-auth-library": "^11.2.0",
|
|
54
|
+
"lucide-react": "^1.46.0",
|
|
55
|
+
"next": "^16.4.1",
|
|
56
|
+
"playwright": "^1.63.0",
|
|
57
|
+
"react": "^19.3.0",
|
|
58
|
+
"react-dom": "^19.3.0",
|
|
59
|
+
"rolldown": "^1.2.8",
|
|
60
|
+
"styled-components": "^6.5.3",
|
|
61
|
+
"tsdown": "^0.23.0",
|
|
62
|
+
"typescript": "^7.0.2",
|
|
63
|
+
"vitest": "^5.0.1"
|
|
64
|
+
},
|
|
65
|
+
"peerDependenciesMeta": {
|
|
66
|
+
"google-auth-library": {
|
|
67
|
+
"optional": true
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
"scripts": {
|
|
71
|
+
"build": "tsdown",
|
|
72
|
+
"dev": "tsdown --watch",
|
|
73
|
+
"lint": "biome check .",
|
|
74
|
+
"typecheck": "tsc --noEmit",
|
|
75
|
+
"test": "vitest run --project unit",
|
|
76
|
+
"test:integration": "vitest run --project integration",
|
|
77
|
+
"test:acceptance": "vitest run --project acceptance"
|
|
78
|
+
}
|
|
6
79
|
}
|