@kithinji/arcane 1.0.8 → 1.0.9
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/dist/browser/index.mjs +15 -28
- package/dist/browser/index.mjs.map +2 -2
- package/dist/node/index.cjs +191 -49
- package/dist/node/index.cjs.map +3 -3
- package/dist/node/index.mjs +188 -49
- package/dist/node/index.mjs.map +3 -3
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.node.d.ts +1 -1
- package/dist/types/index.node.d.ts.map +1 -1
- package/dist/types/inline/index.d.ts +2 -0
- package/dist/types/inline/index.d.ts.map +1 -0
- package/dist/types/inline/inline.d.ts +17 -0
- package/dist/types/inline/inline.d.ts.map +1 -0
- package/dist/types/style/style.d.ts +2 -2
- package/dist/types/style/style.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/index.node.ts +1 -1
- package/src/index.ts +1 -1
- package/src/inline/inline.ts +320 -0
- package/src/style/style.ts +42 -58
- package/src/inline-file/inline.ts +0 -90
- /package/src/{inline-file → inline}/index.ts +0 -0
package/dist/node/index.mjs
CHANGED
|
@@ -187,14 +187,9 @@ function processStyleObject(styleObj, cssRules) {
|
|
|
187
187
|
}
|
|
188
188
|
return result;
|
|
189
189
|
}
|
|
190
|
-
function style$(style
|
|
191
|
-
if (!context) {
|
|
192
|
-
throw new Error(
|
|
193
|
-
"style$ macro requires MacroContext. Ensure you're using this as a build-time macro."
|
|
194
|
-
);
|
|
195
|
-
}
|
|
190
|
+
function style$(style) {
|
|
196
191
|
const rStyle = style;
|
|
197
|
-
const value =
|
|
192
|
+
const value = this.resolveNodeValue(rStyle);
|
|
198
193
|
if (value == void 0) {
|
|
199
194
|
throw new Error(
|
|
200
195
|
`Could not resolve style object at build time. Ensure all values are statically analyzable (no runtime expressions, dynamic imports should be inlined).`
|
|
@@ -207,38 +202,30 @@ function style$(style, context) {
|
|
|
207
202
|
}
|
|
208
203
|
const cssRules = /* @__PURE__ */ new Map();
|
|
209
204
|
const classNameMap = processStyleObject(value, cssRules);
|
|
210
|
-
|
|
205
|
+
this.store.set("style_rules", Array.from(cssRules.values()));
|
|
211
206
|
const properties = Object.entries(classNameMap).map(
|
|
212
|
-
([key, className]) =>
|
|
213
|
-
|
|
214
|
-
|
|
207
|
+
([key, className]) => this.factory.createPropertyAssignment(
|
|
208
|
+
this.factory.createStringLiteral(key),
|
|
209
|
+
this.factory.createStringLiteral(className)
|
|
215
210
|
)
|
|
216
211
|
);
|
|
217
|
-
return
|
|
212
|
+
return this.factory.createObjectLiteralExpression(properties, true);
|
|
218
213
|
}
|
|
219
214
|
function apply$(...c) {
|
|
220
|
-
if (c.length < 1) {
|
|
221
|
-
throw new Error("apply$ requires at least one argument plus MacroContext");
|
|
222
|
-
}
|
|
223
|
-
const context = c.pop();
|
|
224
|
-
if (!context || !context.factory) {
|
|
225
|
-
throw new Error(
|
|
226
|
-
"apply$ macro requires MacroContext as the last argument. Ensure you're using this as a build-time macro."
|
|
227
|
-
);
|
|
228
|
-
}
|
|
229
215
|
const args = c;
|
|
216
|
+
const self = this;
|
|
230
217
|
if (args.length === 0) {
|
|
231
|
-
return
|
|
218
|
+
return self.factory.createObjectLiteralExpression(
|
|
232
219
|
[
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
220
|
+
self.factory.createPropertyAssignment(
|
|
221
|
+
self.factory.createIdentifier("className"),
|
|
222
|
+
self.factory.createStringLiteral("")
|
|
236
223
|
)
|
|
237
224
|
],
|
|
238
225
|
false
|
|
239
226
|
);
|
|
240
227
|
}
|
|
241
|
-
const f =
|
|
228
|
+
const f = self.factory;
|
|
242
229
|
function isTrue(e) {
|
|
243
230
|
return e.kind === ts.SyntaxKind.TrueKeyword;
|
|
244
231
|
}
|
|
@@ -261,8 +248,8 @@ function apply$(...c) {
|
|
|
261
248
|
}
|
|
262
249
|
if (!ts.isIdentifier(cur)) return null;
|
|
263
250
|
chain.unshift(cur.text);
|
|
264
|
-
const root =
|
|
265
|
-
let value =
|
|
251
|
+
const root = self.resolveIdentifier(f.createIdentifier(chain[0]));
|
|
252
|
+
let value = self.resolveNodeValue(root);
|
|
266
253
|
if (value == null) return null;
|
|
267
254
|
for (let i = 1; i < chain.length; i++) {
|
|
268
255
|
if (typeof value !== "object" || !(chain[i] in value)) {
|
|
@@ -376,75 +363,227 @@ function apply$(...c) {
|
|
|
376
363
|
);
|
|
377
364
|
}
|
|
378
365
|
|
|
379
|
-
// src/inline
|
|
366
|
+
// src/inline/inline.ts
|
|
380
367
|
import fs from "fs";
|
|
381
368
|
import path from "path";
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
369
|
+
var MIME_TYPES = {
|
|
370
|
+
".png": "image/png",
|
|
371
|
+
".jpg": "image/jpeg",
|
|
372
|
+
".jpeg": "image/jpeg",
|
|
373
|
+
".gif": "image/gif",
|
|
374
|
+
".svg": "image/svg+xml",
|
|
375
|
+
".webp": "image/webp",
|
|
376
|
+
".ico": "image/x-icon",
|
|
377
|
+
".bmp": "image/bmp",
|
|
378
|
+
".woff": "font/woff",
|
|
379
|
+
".woff2": "font/woff2",
|
|
380
|
+
".ttf": "font/ttf",
|
|
381
|
+
".otf": "font/otf",
|
|
382
|
+
".eot": "application/vnd.ms-fontobject",
|
|
383
|
+
".mp3": "audio/mpeg",
|
|
384
|
+
".wav": "audio/wav",
|
|
385
|
+
".ogg": "audio/ogg",
|
|
386
|
+
".mp4": "video/mp4",
|
|
387
|
+
".webm": "video/webm",
|
|
388
|
+
".pdf": "application/pdf",
|
|
389
|
+
".zip": "application/zip",
|
|
390
|
+
".txt": "text/plain",
|
|
391
|
+
".html": "text/html",
|
|
392
|
+
".css": "text/css",
|
|
393
|
+
".js": "text/javascript",
|
|
394
|
+
".json": "application/json",
|
|
395
|
+
".xml": "application/xml"
|
|
396
|
+
};
|
|
397
|
+
function getMimeType(filePath) {
|
|
398
|
+
const ext = path.extname(filePath).toLowerCase();
|
|
399
|
+
return MIME_TYPES[ext] || "application/octet-stream";
|
|
400
|
+
}
|
|
401
|
+
function resolveFilePath(filePath, context, macroName) {
|
|
388
402
|
const pathNode = filePath;
|
|
389
403
|
const resolvedPath = context.resolveNodeValue(pathNode);
|
|
390
404
|
if (typeof resolvedPath !== "string") {
|
|
391
405
|
throw new Error(
|
|
392
|
-
|
|
406
|
+
`${macroName} requires a string literal path, got: ${typeof resolvedPath}`
|
|
393
407
|
);
|
|
394
408
|
}
|
|
395
409
|
const sourceFile = context.sourceFile;
|
|
396
410
|
const sourceDir = path.dirname(sourceFile.fileName);
|
|
397
411
|
const absolutePath = path.resolve(sourceDir, resolvedPath);
|
|
412
|
+
return absolutePath;
|
|
413
|
+
}
|
|
414
|
+
function inlineFile$(filePath, options) {
|
|
415
|
+
const absolutePath = resolveFilePath(filePath, this, "inlineFile$");
|
|
416
|
+
const maxSize = options?.maxSize || 1024 * 1024;
|
|
398
417
|
let content;
|
|
399
418
|
try {
|
|
419
|
+
const stats = fs.statSync(absolutePath);
|
|
420
|
+
if (stats.size > maxSize) {
|
|
421
|
+
throw new Error(
|
|
422
|
+
`File "${absolutePath}" is too large (${stats.size} bytes). Maximum allowed: ${maxSize} bytes. Consider using uploadFile$ instead.`
|
|
423
|
+
);
|
|
424
|
+
}
|
|
400
425
|
content = fs.readFileSync(absolutePath, "utf-8");
|
|
401
426
|
} catch (error) {
|
|
427
|
+
if (error instanceof Error && "code" in error && error.code === "ENOENT") {
|
|
428
|
+
throw new Error(
|
|
429
|
+
`File not found: "${absolutePath}" (referenced in ${this.sourceFile.fileName})`
|
|
430
|
+
);
|
|
431
|
+
}
|
|
402
432
|
throw new Error(
|
|
403
433
|
`Failed to read file "${absolutePath}": ${error instanceof Error ? error.message : String(error)}`
|
|
404
434
|
);
|
|
405
435
|
}
|
|
406
|
-
return
|
|
436
|
+
return this.factory.createStringLiteral(content);
|
|
407
437
|
}
|
|
408
|
-
function inlineFiles$(filePaths,
|
|
409
|
-
if (!context) {
|
|
410
|
-
throw new Error(
|
|
411
|
-
"inlineFiles$ macro requires MacroContext. Ensure you're using this as a build-time macro."
|
|
412
|
-
);
|
|
413
|
-
}
|
|
438
|
+
function inlineFiles$(filePaths, options) {
|
|
414
439
|
const pathsNode = filePaths;
|
|
415
|
-
const resolvedPaths =
|
|
440
|
+
const resolvedPaths = this.resolveNodeValue(pathsNode);
|
|
416
441
|
if (!Array.isArray(resolvedPaths)) {
|
|
417
442
|
throw new Error(
|
|
418
|
-
`inlineFiles$
|
|
443
|
+
`inlineFiles$ requires an array of string literals, got: ${typeof resolvedPaths}`
|
|
419
444
|
);
|
|
420
445
|
}
|
|
421
|
-
const sourceFile =
|
|
446
|
+
const sourceFile = this.sourceFile;
|
|
422
447
|
const sourceDir = path.dirname(sourceFile.fileName);
|
|
448
|
+
const maxSize = options?.maxSize || 1024 * 1024;
|
|
423
449
|
const fileContents = [];
|
|
424
450
|
for (const filePath of resolvedPaths) {
|
|
425
451
|
if (typeof filePath !== "string") {
|
|
426
452
|
throw new Error(
|
|
427
|
-
`inlineFiles$
|
|
453
|
+
`inlineFiles$ requires all paths to be string literals, got: ${typeof filePath}`
|
|
428
454
|
);
|
|
429
455
|
}
|
|
430
456
|
const absolutePath = path.resolve(sourceDir, filePath);
|
|
431
457
|
try {
|
|
458
|
+
const stats = fs.statSync(absolutePath);
|
|
459
|
+
if (stats.size > maxSize) {
|
|
460
|
+
throw new Error(
|
|
461
|
+
`File "${absolutePath}" is too large (${stats.size} bytes). Maximum allowed: ${maxSize} bytes.`
|
|
462
|
+
);
|
|
463
|
+
}
|
|
432
464
|
const content = fs.readFileSync(absolutePath, "utf-8");
|
|
433
465
|
fileContents.push(content);
|
|
434
466
|
} catch (error) {
|
|
467
|
+
if (error instanceof Error && "code" in error && error.code === "ENOENT") {
|
|
468
|
+
throw new Error(
|
|
469
|
+
`File not found: "${absolutePath}" (referenced in ${sourceFile.fileName})`
|
|
470
|
+
);
|
|
471
|
+
}
|
|
435
472
|
throw new Error(
|
|
436
473
|
`Failed to read file "${absolutePath}": ${error instanceof Error ? error.message : String(error)}`
|
|
437
474
|
);
|
|
438
475
|
}
|
|
439
476
|
}
|
|
440
477
|
const elements = fileContents.map(
|
|
441
|
-
(content) =>
|
|
478
|
+
(content) => this.factory.createStringLiteral(content)
|
|
479
|
+
);
|
|
480
|
+
return this.factory.createArrayLiteralExpression(elements, true);
|
|
481
|
+
}
|
|
482
|
+
function inlineFileBase64$(filePath, options) {
|
|
483
|
+
const absolutePath = resolveFilePath(filePath, this, "inlineFileBase64$");
|
|
484
|
+
const maxSize = options?.maxSize || 100 * 1024;
|
|
485
|
+
let content;
|
|
486
|
+
try {
|
|
487
|
+
const stats = fs.statSync(absolutePath);
|
|
488
|
+
if (stats.size > maxSize) {
|
|
489
|
+
throw new Error(
|
|
490
|
+
`File "${absolutePath}" is too large (${stats.size} bytes). Maximum allowed: ${maxSize} bytes. Consider using uploadFile$ instead.`
|
|
491
|
+
);
|
|
492
|
+
}
|
|
493
|
+
const buffer = fs.readFileSync(absolutePath);
|
|
494
|
+
content = buffer.toString("base64");
|
|
495
|
+
} catch (error) {
|
|
496
|
+
if (error instanceof Error && "code" in error && error.code === "ENOENT") {
|
|
497
|
+
throw new Error(
|
|
498
|
+
`File not found: "${absolutePath}" (referenced in ${this.sourceFile.fileName})`
|
|
499
|
+
);
|
|
500
|
+
}
|
|
501
|
+
throw new Error(
|
|
502
|
+
`Failed to read file "${absolutePath}": ${error instanceof Error ? error.message : String(error)}`
|
|
503
|
+
);
|
|
504
|
+
}
|
|
505
|
+
return this.factory.createStringLiteral(content);
|
|
506
|
+
}
|
|
507
|
+
function inlineDataURL$(filePath, options) {
|
|
508
|
+
const absolutePath = resolveFilePath(filePath, this, "inlineDataURL$");
|
|
509
|
+
const maxSize = options?.maxSize || 100 * 1024;
|
|
510
|
+
let dataURL;
|
|
511
|
+
try {
|
|
512
|
+
const stats = fs.statSync(absolutePath);
|
|
513
|
+
if (stats.size > maxSize) {
|
|
514
|
+
throw new Error(
|
|
515
|
+
`File "${absolutePath}" is too large (${stats.size} bytes). Maximum allowed: ${maxSize} bytes. Consider using uploadFile$ instead.`
|
|
516
|
+
);
|
|
517
|
+
}
|
|
518
|
+
const mimeType = options?.mimeType || getMimeType(absolutePath);
|
|
519
|
+
const buffer = fs.readFileSync(absolutePath);
|
|
520
|
+
const base64 = buffer.toString("base64");
|
|
521
|
+
dataURL = `data:${mimeType};base64,${base64}`;
|
|
522
|
+
} catch (error) {
|
|
523
|
+
if (error instanceof Error && "code" in error && error.code === "ENOENT") {
|
|
524
|
+
throw new Error(
|
|
525
|
+
`File not found: "${absolutePath}" (referenced in ${this.sourceFile.fileName})`
|
|
526
|
+
);
|
|
527
|
+
}
|
|
528
|
+
throw new Error(
|
|
529
|
+
`Failed to read file "${absolutePath}": ${error instanceof Error ? error.message : String(error)}`
|
|
530
|
+
);
|
|
531
|
+
}
|
|
532
|
+
return this.factory.createStringLiteral(dataURL);
|
|
533
|
+
}
|
|
534
|
+
function inlineDataURLs$(filePaths, options) {
|
|
535
|
+
const pathsNode = filePaths;
|
|
536
|
+
const resolvedPaths = this.resolveNodeValue(pathsNode);
|
|
537
|
+
if (!Array.isArray(resolvedPaths)) {
|
|
538
|
+
throw new Error(
|
|
539
|
+
`inlineDataURLs$ requires an array of string literals, got: ${typeof resolvedPaths}`
|
|
540
|
+
);
|
|
541
|
+
}
|
|
542
|
+
const sourceFile = this.sourceFile;
|
|
543
|
+
const sourceDir = path.dirname(sourceFile.fileName);
|
|
544
|
+
const maxSize = options?.maxSize || 100 * 1024;
|
|
545
|
+
const dataURLs = [];
|
|
546
|
+
for (const filePath of resolvedPaths) {
|
|
547
|
+
if (typeof filePath !== "string") {
|
|
548
|
+
throw new Error(
|
|
549
|
+
`inlineDataURLs$ requires all paths to be string literals, got: ${typeof filePath}`
|
|
550
|
+
);
|
|
551
|
+
}
|
|
552
|
+
const absolutePath = path.resolve(sourceDir, filePath);
|
|
553
|
+
try {
|
|
554
|
+
const stats = fs.statSync(absolutePath);
|
|
555
|
+
if (stats.size > maxSize) {
|
|
556
|
+
throw new Error(
|
|
557
|
+
`File "${absolutePath}" is too large (${stats.size} bytes). Maximum allowed: ${maxSize} bytes.`
|
|
558
|
+
);
|
|
559
|
+
}
|
|
560
|
+
const mimeType = options?.mimeType || getMimeType(absolutePath);
|
|
561
|
+
const buffer = fs.readFileSync(absolutePath);
|
|
562
|
+
const base64 = buffer.toString("base64");
|
|
563
|
+
const dataURL = `data:${mimeType};base64,${base64}`;
|
|
564
|
+
dataURLs.push(dataURL);
|
|
565
|
+
} catch (error) {
|
|
566
|
+
if (error instanceof Error && "code" in error && error.code === "ENOENT") {
|
|
567
|
+
throw new Error(
|
|
568
|
+
`File not found: "${absolutePath}" (referenced in ${sourceFile.fileName})`
|
|
569
|
+
);
|
|
570
|
+
}
|
|
571
|
+
throw new Error(
|
|
572
|
+
`Failed to read file "${absolutePath}": ${error instanceof Error ? error.message : String(error)}`
|
|
573
|
+
);
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
const elements = dataURLs.map(
|
|
577
|
+
(dataURL) => this.factory.createStringLiteral(dataURL)
|
|
442
578
|
);
|
|
443
|
-
return
|
|
579
|
+
return this.factory.createArrayLiteralExpression(elements, true);
|
|
444
580
|
}
|
|
445
581
|
export {
|
|
446
582
|
apply$,
|
|
583
|
+
inlineDataURL$,
|
|
584
|
+
inlineDataURLs$,
|
|
447
585
|
inlineFile$,
|
|
586
|
+
inlineFileBase64$,
|
|
448
587
|
inlineFiles$,
|
|
449
588
|
style$
|
|
450
589
|
};
|
package/dist/node/index.mjs.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../src/style/style.ts", "../../src/inline
|
|
4
|
-
"sourcesContent": ["import { MacroContext } from \"@kithinji/pod\";\nimport ts from \"typescript\";\nimport { MapNamespaces } from \"./style_types\";\n\nconst UNITLESS_PROPS = new Set([\n \"z-index\",\n \"opacity\",\n \"flex-grow\",\n \"flex-shrink\",\n \"flex\",\n \"order\",\n \"font-weight\",\n \"line-height\",\n \"zoom\",\n \"column-count\",\n \"animation-iteration-count\",\n \"grid-column\",\n \"grid-row\",\n \"grid-column-start\",\n \"grid-column-end\",\n \"grid-row-start\",\n \"grid-row-end\",\n \"tab-size\",\n \"counter-increment\",\n \"counter-reset\",\n \"orphans\",\n \"widows\",\n]);\n\nconst DEV_MODE = process.env.NODE_ENV === \"development\";\n\nfunction simpleHash(str: string): string {\n let hash = 0;\n for (let i = 0; i < str.length; i++) {\n const char = str.charCodeAt(i);\n hash = (hash << 5) - hash + char;\n hash = hash & hash;\n }\n\n return Math.abs(hash).toString(36).padStart(8, \"0\").slice(0, 8);\n}\n\nfunction hashProperty(\n prop: string,\n value: string | number,\n cssRules: Map<string, string>\n): string {\n const input = `${prop}:${value}`;\n let hash = simpleHash(input);\n let className: string;\n\n if (DEV_MODE) {\n // Add readable hint in development\n const hint = prop\n .replace(/[^a-z]/gi, \"\")\n .slice(0, 3)\n .toLowerCase();\n className = `a-${hint}-${hash}`;\n } else {\n className = `a-${hash}`;\n }\n\n let attempt = 0;\n\n // Handle hash collisions\n while (cssRules.has(className)) {\n const existing = cssRules.get(className)!;\n const kebabProp = toKebabCase(prop);\n const normalizedValue = normalizeValue(prop, value);\n const expectedRule = `.${className} { ${kebabProp}: ${normalizedValue}; }`;\n\n // If the existing rule matches, it's the same style (deduplication)\n if (existing.includes(`${kebabProp}: ${normalizedValue}`)) {\n break;\n }\n\n // Collision detected, rehash\n hash = simpleHash(`${input}-${++attempt}`);\n className = DEV_MODE ? `a-${prop.slice(0, 3)}-${hash}` : `a-${hash}`;\n\n if (attempt > 100) {\n throw new Error(\n `Hash collision limit exceeded for property ${prop}:${value}`\n );\n }\n }\n\n return className;\n}\n\nfunction toKebabCase(str: string): string {\n // Handle vendor prefixes (webkit, moz, ms)\n if (str.match(/^(webkit|moz|ms)[A-Z]/)) {\n return \"-\" + str.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`);\n }\n\n // Handle CSS custom properties\n if (str.startsWith(\"--\")) {\n return str;\n }\n\n return str.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`);\n}\n\nfunction normalizeValue(prop: string, value: string | number): string {\n if (typeof value === \"number\") {\n const kebabProp = toKebabCase(prop);\n\n if (UNITLESS_PROPS.has(kebabProp)) {\n return String(value);\n }\n\n return `${value}px`;\n }\n\n return String(value);\n}\n\nfunction isPseudoOrMediaKey(key: string): boolean {\n return key.startsWith(\":\") || key.startsWith(\"@\") || key.startsWith(\"&\");\n}\n\nfunction validateStyleValue(value: any, path: string): void {\n if (value === null) {\n throw new Error(\n `Invalid style value at ${path}: null is not allowed. Use undefined or omit the property.`\n );\n }\n\n if (typeof value === \"function\") {\n throw new Error(\n `Invalid style value at ${path}: functions must be resolved at build time.`\n );\n }\n}\n\nfunction processStyleValue(\n prop: string,\n value: any,\n cssRules: Map<string, string>,\n path: string = prop\n): string {\n validateStyleValue(value, path);\n\n if (prop.startsWith(\"--\")) {\n const className = hashProperty(prop, value, cssRules);\n if (!cssRules.has(className)) {\n const cssRule = `.${className} { ${prop}: ${value}; }`;\n cssRules.set(className, cssRule);\n }\n return className;\n }\n\n const kebabProp = toKebabCase(prop);\n\n // Handle nested objects for pseudo-classes, media queries, etc.\n if (typeof value === \"object\" && !Array.isArray(value)) {\n const classes: string[] = [];\n\n for (const [nestedKey, nestedValue] of Object.entries(value)) {\n validateStyleValue(nestedValue, `${path}.${nestedKey}`);\n\n if (nestedKey === \"default\") {\n const normalizedValue = normalizeValue(\n prop,\n nestedValue as string | number\n );\n const className = hashProperty(prop, normalizedValue, cssRules);\n\n if (!cssRules.has(className)) {\n const cssRule = `.${className} { ${kebabProp}: ${normalizedValue}; }`;\n cssRules.set(className, cssRule);\n }\n\n classes.push(className);\n } else if (isPseudoOrMediaKey(nestedKey)) {\n const normalizedValue = normalizeValue(\n prop,\n nestedValue as string | number\n );\n const className = hashProperty(\n `${prop}${nestedKey}`,\n normalizedValue,\n cssRules\n );\n\n if (!cssRules.has(className)) {\n let cssRule: string;\n\n if (nestedKey.startsWith(\"@\")) {\n // Media query\n cssRule = `${nestedKey} { .${className} { ${kebabProp}: ${normalizedValue}; } }`;\n } else if (nestedKey.startsWith(\"&\")) {\n // Nesting selector (e.g., &:hover, & > div)\n const selector = nestedKey.slice(1);\n cssRule = `.${className}${selector} { ${kebabProp}: ${normalizedValue}; }`;\n } else {\n // Pseudo-class/element (e.g., :hover, ::before)\n cssRule = `.${className}${nestedKey} { ${kebabProp}: ${normalizedValue}; }`;\n }\n\n cssRules.set(className, cssRule);\n }\n\n classes.push(className);\n } else {\n throw new Error(\n `Invalid nested key \"${nestedKey}\" at ${path}. Expected \"default\", a pseudo-class (\":hover\"), media query (\"@media\"), or nesting selector (\"&\").`\n );\n }\n }\n\n return classes.join(\" \");\n }\n\n const normalizedValue = normalizeValue(prop, value);\n const className = hashProperty(prop, normalizedValue, cssRules);\n\n if (!cssRules.has(className)) {\n const cssRule = `.${className} { ${kebabProp}: ${normalizedValue}; }`;\n cssRules.set(className, cssRule);\n }\n\n return className;\n}\n\nfunction processStyleObject(\n styleObj: Record<string, any>,\n cssRules: Map<string, string>\n): Record<string, string> {\n const result: Record<string, string> = {};\n\n for (const [namespace, styles] of Object.entries(styleObj)) {\n if (typeof styles !== \"object\" || Array.isArray(styles)) {\n throw new Error(\n `Invalid style namespace \"${namespace}\": expected an object, got ${typeof styles}`\n );\n }\n\n const classes: string[] = [];\n\n for (const [prop, value] of Object.entries(styles)) {\n if (value === undefined) continue;\n\n const className = processStyleValue(\n prop,\n value,\n cssRules,\n `${namespace}.${prop}`\n );\n\n if (className) {\n classes.push(className);\n }\n }\n\n result[namespace] = classes.filter(Boolean).join(\" \");\n }\n\n return result;\n}\n\nexport function style$<const T extends Record<string, any>>(\n style: T,\n context?: MacroContext\n): MapNamespaces<T> {\n if (!context) {\n throw new Error(\n \"style$ macro requires MacroContext. Ensure you're using this as a build-time macro.\"\n );\n }\n\n const rStyle = style as unknown as ts.Node;\n const value = context.resolveNodeValue(rStyle);\n\n if (value == undefined) {\n throw new Error(\n `Could not resolve style object at build time. ` +\n `Ensure all values are statically analyzable (no runtime expressions, dynamic imports should be inlined).`\n );\n }\n\n if (typeof value !== \"object\" || Array.isArray(value)) {\n throw new Error(\n `style$ expects an object with style namespaces, got ${typeof value}`\n );\n }\n\n const cssRules = new Map<string, string>();\n const classNameMap = processStyleObject(value, cssRules);\n\n context.store.set(\"style_rules\", Array.from(cssRules.values()));\n\n const properties = Object.entries(classNameMap).map(([key, className]) =>\n context.factory.createPropertyAssignment(\n context.factory.createStringLiteral(key),\n context.factory.createStringLiteral(className)\n )\n );\n\n return context.factory.createObjectLiteralExpression(properties, true) as any;\n}\n\ntype Fragment =\n | { kind: \"static\"; value: string }\n | { kind: \"dynamic\"; expr: ts.Expression; stringSafe: boolean };\n\nexport function apply$(...c: any[]) {\n if (c.length < 1) {\n throw new Error(\"apply$ requires at least one argument plus MacroContext\");\n }\n\n const context = c.pop() as MacroContext;\n\n if (!context || !context.factory) {\n throw new Error(\n \"apply$ macro requires MacroContext as the last argument. Ensure you're using this as a build-time macro.\"\n );\n }\n\n const args = c as ts.Expression[];\n\n if (args.length === 0) {\n return context.factory.createObjectLiteralExpression(\n [\n context.factory.createPropertyAssignment(\n context.factory.createIdentifier(\"className\"),\n context.factory.createStringLiteral(\"\")\n ),\n ],\n false\n );\n }\n\n const f = context.factory;\n\n function isTrue(e: ts.Expression): boolean {\n return e.kind === ts.SyntaxKind.TrueKeyword;\n }\n\n function isFalse(e: ts.Expression): boolean {\n return e.kind === ts.SyntaxKind.FalseKeyword;\n }\n\n function isEmptyString(e: ts.Expression): boolean {\n return ts.isStringLiteral(e) && e.text === \"\";\n }\n\n function tryResolveStatic(expr: ts.Expression): string | null {\n // Try to resolve string literals directly\n if (ts.isStringLiteral(expr)) {\n return expr.text;\n }\n\n // Try to resolve property access chains (e.g., classes.button)\n if (!ts.isPropertyAccessExpression(expr)) return null;\n\n const chain: string[] = [];\n let cur: ts.Expression = expr;\n\n while (ts.isPropertyAccessExpression(cur)) {\n chain.unshift(cur.name.text);\n cur = cur.expression;\n }\n\n if (!ts.isIdentifier(cur)) return null;\n chain.unshift(cur.text);\n\n const root = context.resolveIdentifier(f.createIdentifier(chain[0]));\n let value = context.resolveNodeValue(root);\n\n if (value == null) return null;\n\n for (let i = 1; i < chain.length; i++) {\n if (typeof value !== \"object\" || !(chain[i] in value)) {\n return null;\n }\n value = value[chain[i]];\n }\n\n return typeof value === \"string\" ? value : null;\n }\n\n function build(expr: ts.Expression): Fragment {\n // Handle empty strings\n if (isEmptyString(expr)) {\n return { kind: \"static\", value: \"\" };\n }\n\n // Try static resolution first\n const s = tryResolveStatic(expr);\n if (s != null) {\n return { kind: \"static\", value: s };\n }\n\n // Handle: condition && \"class\"\n if (\n ts.isBinaryExpression(expr) &&\n expr.operatorToken.kind === ts.SyntaxKind.AmpersandAmpersandToken\n ) {\n if (isTrue(expr.left)) return build(expr.right);\n if (isFalse(expr.left)) return { kind: \"static\", value: \"\" };\n\n const rs = tryResolveStatic(expr.right);\n if (rs != null) {\n // Optimize to: [\"\", \"class\"][+condition]\n return {\n kind: \"dynamic\",\n stringSafe: true,\n expr: f.createElementAccessExpression(\n f.createArrayLiteralExpression([\n f.createStringLiteral(\"\"),\n f.createStringLiteral(rs),\n ]),\n f.createPrefixUnaryExpression(ts.SyntaxKind.PlusToken, expr.left)\n ),\n };\n }\n\n return { kind: \"dynamic\", expr, stringSafe: false };\n }\n\n // Handle: condition ? \"a\" : \"b\"\n if (ts.isConditionalExpression(expr)) {\n if (isTrue(expr.condition)) return build(expr.whenTrue);\n if (isFalse(expr.condition)) return build(expr.whenFalse);\n\n const t = tryResolveStatic(expr.whenTrue);\n const fv = tryResolveStatic(expr.whenFalse);\n\n if (t != null && fv != null) {\n // Optimize to: [\"b\", \"a\"][+condition]\n return {\n kind: \"dynamic\",\n stringSafe: true,\n expr: f.createElementAccessExpression(\n f.createArrayLiteralExpression([\n f.createStringLiteral(fv),\n f.createStringLiteral(t),\n ]),\n f.createPrefixUnaryExpression(\n ts.SyntaxKind.PlusToken,\n expr.condition\n )\n ),\n };\n }\n\n return { kind: \"dynamic\", expr, stringSafe: false };\n }\n\n return { kind: \"dynamic\", expr, stringSafe: false };\n }\n\n // Build and merge fragments\n const frags: Fragment[] = [];\n\n for (const arg of args) {\n const frag = build(arg);\n\n // Skip empty static values\n if (frag.kind === \"static\" && frag.value === \"\") {\n continue;\n }\n\n const last = frags[frags.length - 1];\n\n // Merge consecutive static fragments\n if (frag.kind === \"static\" && last?.kind === \"static\") {\n last.value += \" \" + frag.value;\n } else {\n frags.push(frag);\n }\n }\n\n // Generate final className expression\n let classExpr: ts.Expression;\n\n if (frags.length === 0) {\n // All classes were empty\n classExpr = f.createStringLiteral(\"\");\n } else if (frags.every((f) => f.kind === \"static\")) {\n // All static - compile to single string\n classExpr = f.createStringLiteral(\n frags\n .map((f) => f.value)\n .join(\" \")\n .trim()\n );\n } else {\n // Mixed static/dynamic - generate array.join(\" \")\n classExpr = f.createCallExpression(\n f.createPropertyAccessExpression(\n f.createArrayLiteralExpression(\n frags.map((frag) => {\n if (frag.kind === \"static\") {\n return f.createStringLiteral(frag.value);\n }\n if (frag.stringSafe) {\n return frag.expr;\n }\n // Wrap unsafe expressions in conditional: expr ? expr : \"\"\n return f.createConditionalExpression(\n frag.expr,\n undefined,\n frag.expr,\n undefined,\n f.createStringLiteral(\"\")\n );\n })\n ),\n \"join\"\n ),\n undefined,\n [f.createStringLiteral(\" \")]\n );\n }\n\n return f.createObjectLiteralExpression(\n [f.createPropertyAssignment(f.createIdentifier(\"className\"), classExpr)],\n false\n );\n}\n", "import { MacroContext } from \"@kithinji/pod\";\nimport ts from \"typescript\";\nimport fs from \"fs\";\nimport path from \"path\";\n\nexport function inlineFile$(filePath: string, context?: MacroContext): string {\n if (!context) {\n throw new Error(\n \"inlineFile$ macro requires MacroContext. Ensure you're using this as a build-time macro.\"\n );\n }\n\n const pathNode = filePath as unknown as ts.Node;\n const resolvedPath = context.resolveNodeValue(pathNode);\n\n if (typeof resolvedPath !== \"string\") {\n throw new Error(\n `inlineFile$ macro requires a string literal path, got: ${typeof resolvedPath}`\n );\n }\n\n const sourceFile = context.sourceFile;\n const sourceDir = path.dirname(sourceFile.fileName);\n const absolutePath = path.resolve(sourceDir, resolvedPath);\n\n let content: string;\n try {\n content = fs.readFileSync(absolutePath, \"utf-8\");\n } catch (error) {\n throw new Error(\n `Failed to read file \"${absolutePath}\": ${\n error instanceof Error ? error.message : String(error)\n }`\n );\n }\n\n return context.factory.createStringLiteral(content) as any;\n}\n\nexport function inlineFiles$(\n filePaths: string[],\n context?: MacroContext\n): string[] {\n if (!context) {\n throw new Error(\n \"inlineFiles$ macro requires MacroContext. Ensure you're using this as a build-time macro.\"\n );\n }\n\n const pathsNode = filePaths as unknown as ts.Node;\n const resolvedPaths = context.resolveNodeValue(pathsNode);\n\n if (!Array.isArray(resolvedPaths)) {\n throw new Error(\n `inlineFiles$ macro requires an array of string literals, got: ${typeof resolvedPaths}`\n );\n }\n\n const sourceFile = context.sourceFile;\n const sourceDir = path.dirname(sourceFile.fileName);\n\n const fileContents: string[] = [];\n\n for (const filePath of resolvedPaths) {\n if (typeof filePath !== \"string\") {\n throw new Error(\n `inlineFiles$ macro requires all paths to be string literals, got: ${typeof filePath}`\n );\n }\n\n const absolutePath = path.resolve(sourceDir, filePath);\n\n try {\n const content = fs.readFileSync(absolutePath, \"utf-8\");\n fileContents.push(content);\n } catch (error) {\n throw new Error(\n `Failed to read file \"${absolutePath}\": ${\n error instanceof Error ? error.message : String(error)\n }`\n );\n }\n }\n\n const elements = fileContents.map((content) =>\n context.factory.createStringLiteral(content)\n );\n\n return context.factory.createArrayLiteralExpression(elements, true) as any;\n}\n"],
|
|
5
|
-
"mappings": ";AACA,OAAO,QAAQ;AAGf,IA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GAAG,aAAa,cAAc,OAAO;AACrD,mBAAa,KAAK,OAAO;AAAA,IAC3B,SAAS,OAAO;AACd,YAAM,IAAI;AAAA,QACR,wBAAwB,YAAY,MAClC,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,CACvD;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAEA,QAAM,WAAW,aAAa;AAAA,IAAI,CAAC,YACjC,QAAQ,QAAQ,oBAAoB,OAAO;AAAA,EAC7C;AAEA,SAAO,QAAQ,QAAQ,6BAA6B,UAAU,IAAI;AACpE;",
|
|
3
|
+
"sources": ["../../src/style/style.ts", "../../src/inline/inline.ts"],
|
|
4
|
+
"sourcesContent": ["import { MacroContext } from \"@kithinji/pod\";\nimport ts from \"typescript\";\nimport { MapNamespaces } from \"./style_types\";\n\nconst UNITLESS_PROPS = new Set([\n \"z-index\",\n \"opacity\",\n \"flex-grow\",\n \"flex-shrink\",\n \"flex\",\n \"order\",\n \"font-weight\",\n \"line-height\",\n \"zoom\",\n \"column-count\",\n \"animation-iteration-count\",\n \"grid-column\",\n \"grid-row\",\n \"grid-column-start\",\n \"grid-column-end\",\n \"grid-row-start\",\n \"grid-row-end\",\n \"tab-size\",\n \"counter-increment\",\n \"counter-reset\",\n \"orphans\",\n \"widows\",\n]);\n\nconst DEV_MODE = process.env.NODE_ENV === \"development\";\n\nfunction simpleHash(str: string): string {\n let hash = 0;\n for (let i = 0; i < str.length; i++) {\n const char = str.charCodeAt(i);\n hash = (hash << 5) - hash + char;\n hash = hash & hash;\n }\n\n return Math.abs(hash).toString(36).padStart(8, \"0\").slice(0, 8);\n}\n\nfunction hashProperty(\n prop: string,\n value: string | number,\n cssRules: Map<string, string>,\n): string {\n const input = `${prop}:${value}`;\n let hash = simpleHash(input);\n let className: string;\n\n if (DEV_MODE) {\n // Add readable hint in development\n const hint = prop\n .replace(/[^a-z]/gi, \"\")\n .slice(0, 3)\n .toLowerCase();\n className = `a-${hint}-${hash}`;\n } else {\n className = `a-${hash}`;\n }\n\n let attempt = 0;\n\n // Handle hash collisions\n while (cssRules.has(className)) {\n const existing = cssRules.get(className)!;\n const kebabProp = toKebabCase(prop);\n const normalizedValue = normalizeValue(prop, value);\n const expectedRule = `.${className} { ${kebabProp}: ${normalizedValue}; }`;\n\n // If the existing rule matches, it's the same style (deduplication)\n if (existing.includes(`${kebabProp}: ${normalizedValue}`)) {\n break;\n }\n\n // Collision detected, rehash\n hash = simpleHash(`${input}-${++attempt}`);\n className = DEV_MODE ? `a-${prop.slice(0, 3)}-${hash}` : `a-${hash}`;\n\n if (attempt > 100) {\n throw new Error(\n `Hash collision limit exceeded for property ${prop}:${value}`,\n );\n }\n }\n\n return className;\n}\n\nfunction toKebabCase(str: string): string {\n // Handle vendor prefixes (webkit, moz, ms)\n if (str.match(/^(webkit|moz|ms)[A-Z]/)) {\n return \"-\" + str.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`);\n }\n\n // Handle CSS custom properties\n if (str.startsWith(\"--\")) {\n return str;\n }\n\n return str.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`);\n}\n\nfunction normalizeValue(prop: string, value: string | number): string {\n if (typeof value === \"number\") {\n const kebabProp = toKebabCase(prop);\n\n if (UNITLESS_PROPS.has(kebabProp)) {\n return String(value);\n }\n\n return `${value}px`;\n }\n\n return String(value);\n}\n\nfunction isPseudoOrMediaKey(key: string): boolean {\n return key.startsWith(\":\") || key.startsWith(\"@\") || key.startsWith(\"&\");\n}\n\nfunction validateStyleValue(value: any, path: string): void {\n if (value === null) {\n throw new Error(\n `Invalid style value at ${path}: null is not allowed. Use undefined or omit the property.`,\n );\n }\n\n if (typeof value === \"function\") {\n throw new Error(\n `Invalid style value at ${path}: functions must be resolved at build time.`,\n );\n }\n}\n\nfunction processStyleValue(\n prop: string,\n value: any,\n cssRules: Map<string, string>,\n path: string = prop,\n): string {\n validateStyleValue(value, path);\n\n if (prop.startsWith(\"--\")) {\n const className = hashProperty(prop, value, cssRules);\n if (!cssRules.has(className)) {\n const cssRule = `.${className} { ${prop}: ${value}; }`;\n cssRules.set(className, cssRule);\n }\n return className;\n }\n\n const kebabProp = toKebabCase(prop);\n\n // Handle nested objects for pseudo-classes, media queries, etc.\n if (typeof value === \"object\" && !Array.isArray(value)) {\n const classes: string[] = [];\n\n for (const [nestedKey, nestedValue] of Object.entries(value)) {\n validateStyleValue(nestedValue, `${path}.${nestedKey}`);\n\n if (nestedKey === \"default\") {\n const normalizedValue = normalizeValue(\n prop,\n nestedValue as string | number,\n );\n const className = hashProperty(prop, normalizedValue, cssRules);\n\n if (!cssRules.has(className)) {\n const cssRule = `.${className} { ${kebabProp}: ${normalizedValue}; }`;\n cssRules.set(className, cssRule);\n }\n\n classes.push(className);\n } else if (isPseudoOrMediaKey(nestedKey)) {\n const normalizedValue = normalizeValue(\n prop,\n nestedValue as string | number,\n );\n const className = hashProperty(\n `${prop}${nestedKey}`,\n normalizedValue,\n cssRules,\n );\n\n if (!cssRules.has(className)) {\n let cssRule: string;\n\n if (nestedKey.startsWith(\"@\")) {\n // Media query\n cssRule = `${nestedKey} { .${className} { ${kebabProp}: ${normalizedValue}; } }`;\n } else if (nestedKey.startsWith(\"&\")) {\n // Nesting selector (e.g., &:hover, & > div)\n const selector = nestedKey.slice(1);\n cssRule = `.${className}${selector} { ${kebabProp}: ${normalizedValue}; }`;\n } else {\n // Pseudo-class/element (e.g., :hover, ::before)\n cssRule = `.${className}${nestedKey} { ${kebabProp}: ${normalizedValue}; }`;\n }\n\n cssRules.set(className, cssRule);\n }\n\n classes.push(className);\n } else {\n throw new Error(\n `Invalid nested key \"${nestedKey}\" at ${path}. Expected \"default\", a pseudo-class (\":hover\"), media query (\"@media\"), or nesting selector (\"&\").`,\n );\n }\n }\n\n return classes.join(\" \");\n }\n\n const normalizedValue = normalizeValue(prop, value);\n const className = hashProperty(prop, normalizedValue, cssRules);\n\n if (!cssRules.has(className)) {\n const cssRule = `.${className} { ${kebabProp}: ${normalizedValue}; }`;\n cssRules.set(className, cssRule);\n }\n\n return className;\n}\n\nfunction processStyleObject(\n styleObj: Record<string, any>,\n cssRules: Map<string, string>,\n): Record<string, string> {\n const result: Record<string, string> = {};\n\n for (const [namespace, styles] of Object.entries(styleObj)) {\n if (typeof styles !== \"object\" || Array.isArray(styles)) {\n throw new Error(\n `Invalid style namespace \"${namespace}\": expected an object, got ${typeof styles}`,\n );\n }\n\n const classes: string[] = [];\n\n for (const [prop, value] of Object.entries(styles)) {\n if (value === undefined) continue;\n\n const className = processStyleValue(\n prop,\n value,\n cssRules,\n `${namespace}.${prop}`,\n );\n\n if (className) {\n classes.push(className);\n }\n }\n\n result[namespace] = classes.filter(Boolean).join(\" \");\n }\n\n return result;\n}\n\nexport function style$<const T extends Record<string, any>>(\n this: MacroContext,\n style: T,\n): MapNamespaces<T> {\n const rStyle = style as unknown as ts.Node;\n const value = this.resolveNodeValue(rStyle);\n\n if (value == undefined) {\n throw new Error(\n `Could not resolve style object at build time. ` +\n `Ensure all values are statically analyzable (no runtime expressions, dynamic imports should be inlined).`,\n );\n }\n\n if (typeof value !== \"object\" || Array.isArray(value)) {\n throw new Error(\n `style$ expects an object with style namespaces, got ${typeof value}`,\n );\n }\n\n const cssRules = new Map<string, string>();\n const classNameMap = processStyleObject(value, cssRules);\n\n this.store.set(\"style_rules\", Array.from(cssRules.values()));\n\n const properties = Object.entries(classNameMap).map(([key, className]) =>\n this.factory.createPropertyAssignment(\n this.factory.createStringLiteral(key),\n this.factory.createStringLiteral(className),\n ),\n );\n\n return this.factory.createObjectLiteralExpression(properties, true) as any;\n}\n\ntype Fragment =\n | { kind: \"static\"; value: string }\n | { kind: \"dynamic\"; expr: ts.Expression; stringSafe: boolean };\n\nexport function apply$(this: MacroContext, ...c: any[]) {\n const args = c as ts.Expression[];\n\n const self = this;\n\n if (args.length === 0) {\n return self.factory.createObjectLiteralExpression(\n [\n self.factory.createPropertyAssignment(\n self.factory.createIdentifier(\"className\"),\n self.factory.createStringLiteral(\"\"),\n ),\n ],\n false,\n );\n }\n\n const f = self.factory;\n\n function isTrue(e: ts.Expression): boolean {\n return e.kind === ts.SyntaxKind.TrueKeyword;\n }\n\n function isFalse(e: ts.Expression): boolean {\n return e.kind === ts.SyntaxKind.FalseKeyword;\n }\n\n function isEmptyString(e: ts.Expression): boolean {\n return ts.isStringLiteral(e) && e.text === \"\";\n }\n\n function tryResolveStatic(expr: ts.Expression): string | null {\n // Try to resolve string literals directly\n if (ts.isStringLiteral(expr)) {\n return expr.text;\n }\n\n // Try to resolve property access chains (e.g., classes.button)\n if (!ts.isPropertyAccessExpression(expr)) return null;\n\n const chain: string[] = [];\n let cur: ts.Expression = expr;\n\n while (ts.isPropertyAccessExpression(cur)) {\n chain.unshift(cur.name.text);\n cur = cur.expression;\n }\n\n if (!ts.isIdentifier(cur)) return null;\n chain.unshift(cur.text);\n\n const root = self.resolveIdentifier(f.createIdentifier(chain[0]));\n let value = self.resolveNodeValue(root);\n\n if (value == null) return null;\n\n for (let i = 1; i < chain.length; i++) {\n if (typeof value !== \"object\" || !(chain[i] in value)) {\n return null;\n }\n value = value[chain[i]];\n }\n\n return typeof value === \"string\" ? value : null;\n }\n\n function build(expr: ts.Expression): Fragment {\n // Handle empty strings\n if (isEmptyString(expr)) {\n return { kind: \"static\", value: \"\" };\n }\n\n // Try static resolution first\n const s = tryResolveStatic(expr);\n if (s != null) {\n return { kind: \"static\", value: s };\n }\n\n // Handle: condition && \"class\"\n if (\n ts.isBinaryExpression(expr) &&\n expr.operatorToken.kind === ts.SyntaxKind.AmpersandAmpersandToken\n ) {\n if (isTrue(expr.left)) return build(expr.right);\n if (isFalse(expr.left)) return { kind: \"static\", value: \"\" };\n\n const rs = tryResolveStatic(expr.right);\n if (rs != null) {\n // Optimize to: [\"\", \"class\"][+condition]\n return {\n kind: \"dynamic\",\n stringSafe: true,\n expr: f.createElementAccessExpression(\n f.createArrayLiteralExpression([\n f.createStringLiteral(\"\"),\n f.createStringLiteral(rs),\n ]),\n f.createPrefixUnaryExpression(ts.SyntaxKind.PlusToken, expr.left),\n ),\n };\n }\n\n return { kind: \"dynamic\", expr, stringSafe: false };\n }\n\n // Handle: condition ? \"a\" : \"b\"\n if (ts.isConditionalExpression(expr)) {\n if (isTrue(expr.condition)) return build(expr.whenTrue);\n if (isFalse(expr.condition)) return build(expr.whenFalse);\n\n const t = tryResolveStatic(expr.whenTrue);\n const fv = tryResolveStatic(expr.whenFalse);\n\n if (t != null && fv != null) {\n // Optimize to: [\"b\", \"a\"][+condition]\n return {\n kind: \"dynamic\",\n stringSafe: true,\n expr: f.createElementAccessExpression(\n f.createArrayLiteralExpression([\n f.createStringLiteral(fv),\n f.createStringLiteral(t),\n ]),\n f.createPrefixUnaryExpression(\n ts.SyntaxKind.PlusToken,\n expr.condition,\n ),\n ),\n };\n }\n\n return { kind: \"dynamic\", expr, stringSafe: false };\n }\n\n return { kind: \"dynamic\", expr, stringSafe: false };\n }\n\n // Build and merge fragments\n const frags: Fragment[] = [];\n\n for (const arg of args) {\n const frag = build(arg);\n\n // Skip empty static values\n if (frag.kind === \"static\" && frag.value === \"\") {\n continue;\n }\n\n const last = frags[frags.length - 1];\n\n // Merge consecutive static fragments\n if (frag.kind === \"static\" && last?.kind === \"static\") {\n last.value += \" \" + frag.value;\n } else {\n frags.push(frag);\n }\n }\n\n // Generate final className expression\n let classExpr: ts.Expression;\n\n if (frags.length === 0) {\n // All classes were empty\n classExpr = f.createStringLiteral(\"\");\n } else if (frags.every((f) => f.kind === \"static\")) {\n // All static - compile to single string\n classExpr = f.createStringLiteral(\n frags\n .map((f) => f.value)\n .join(\" \")\n .trim(),\n );\n } else {\n // Mixed static/dynamic - generate array.join(\" \")\n classExpr = f.createCallExpression(\n f.createPropertyAccessExpression(\n f.createArrayLiteralExpression(\n frags.map((frag) => {\n if (frag.kind === \"static\") {\n return f.createStringLiteral(frag.value);\n }\n if (frag.stringSafe) {\n return frag.expr;\n }\n // Wrap unsafe expressions in conditional: expr ? expr : \"\"\n return f.createConditionalExpression(\n frag.expr,\n undefined,\n frag.expr,\n undefined,\n f.createStringLiteral(\"\"),\n );\n }),\n ),\n \"join\",\n ),\n undefined,\n [f.createStringLiteral(\" \")],\n );\n }\n\n return f.createObjectLiteralExpression(\n [f.createPropertyAssignment(f.createIdentifier(\"className\"), classExpr)],\n false,\n );\n}\n", "import { MacroContext } from \"@kithinji/pod\";\nimport ts from \"typescript\";\nimport fs from \"fs\";\nimport path from \"path\";\n\nconst MIME_TYPES: Record<string, string> = {\n \".png\": \"image/png\",\n \".jpg\": \"image/jpeg\",\n \".jpeg\": \"image/jpeg\",\n \".gif\": \"image/gif\",\n \".svg\": \"image/svg+xml\",\n \".webp\": \"image/webp\",\n \".ico\": \"image/x-icon\",\n \".bmp\": \"image/bmp\",\n\n \".woff\": \"font/woff\",\n \".woff2\": \"font/woff2\",\n \".ttf\": \"font/ttf\",\n \".otf\": \"font/otf\",\n \".eot\": \"application/vnd.ms-fontobject\",\n\n \".mp3\": \"audio/mpeg\",\n \".wav\": \"audio/wav\",\n \".ogg\": \"audio/ogg\",\n \".mp4\": \"video/mp4\",\n \".webm\": \"video/webm\",\n\n \".pdf\": \"application/pdf\",\n \".zip\": \"application/zip\",\n\n \".txt\": \"text/plain\",\n \".html\": \"text/html\",\n \".css\": \"text/css\",\n \".js\": \"text/javascript\",\n \".json\": \"application/json\",\n \".xml\": \"application/xml\",\n};\n\nfunction getMimeType(filePath: string): string {\n const ext = path.extname(filePath).toLowerCase();\n return MIME_TYPES[ext] || \"application/octet-stream\";\n}\n\nfunction resolveFilePath(\n filePath: string,\n context: MacroContext,\n macroName: string,\n): string {\n const pathNode = filePath as unknown as ts.Node;\n const resolvedPath = context.resolveNodeValue(pathNode);\n\n if (typeof resolvedPath !== \"string\") {\n throw new Error(\n `${macroName} requires a string literal path, got: ${typeof resolvedPath}`,\n );\n }\n\n const sourceFile = context.sourceFile;\n const sourceDir = path.dirname(sourceFile.fileName);\n const absolutePath = path.resolve(sourceDir, resolvedPath);\n\n return absolutePath;\n}\n\nexport interface InlineFileOptions {\n maxSize?: number;\n}\n\nexport interface InlineDataURLOptions {\n maxSize?: number;\n mimeType?: string;\n}\n\nexport interface InlineBase64Options {\n maxSize?: number;\n}\n\nexport function inlineFile$(\n this: MacroContext,\n filePath: string,\n options?: InlineFileOptions,\n): string {\n const absolutePath = resolveFilePath(filePath, this, \"inlineFile$\");\n const maxSize = options?.maxSize || 1024 * 1024;\n\n let content: string;\n try {\n const stats = fs.statSync(absolutePath);\n\n if (stats.size > maxSize) {\n throw new Error(\n `File \"${absolutePath}\" is too large (${stats.size} bytes). Maximum allowed: ${maxSize} bytes. Consider using uploadFile$ instead.`,\n );\n }\n\n content = fs.readFileSync(absolutePath, \"utf-8\");\n } catch (error) {\n if (error instanceof Error && \"code\" in error && error.code === \"ENOENT\") {\n throw new Error(\n `File not found: \"${absolutePath}\" (referenced in ${this.sourceFile.fileName})`,\n );\n }\n throw new Error(\n `Failed to read file \"${absolutePath}\": ${\n error instanceof Error ? error.message : String(error)\n }`,\n );\n }\n\n return this.factory.createStringLiteral(content) as any;\n}\n\nexport function inlineFiles$(\n this: MacroContext,\n filePaths: string[],\n options?: InlineFileOptions,\n): string[] {\n const pathsNode = filePaths as unknown as ts.Node;\n const resolvedPaths = this.resolveNodeValue(pathsNode);\n\n if (!Array.isArray(resolvedPaths)) {\n throw new Error(\n `inlineFiles$ requires an array of string literals, got: ${typeof resolvedPaths}`,\n );\n }\n\n const sourceFile = this.sourceFile;\n const sourceDir = path.dirname(sourceFile.fileName);\n const maxSize = options?.maxSize || 1024 * 1024;\n\n const fileContents: string[] = [];\n\n for (const filePath of resolvedPaths) {\n if (typeof filePath !== \"string\") {\n throw new Error(\n `inlineFiles$ requires all paths to be string literals, got: ${typeof filePath}`,\n );\n }\n\n const absolutePath = path.resolve(sourceDir, filePath);\n\n try {\n const stats = fs.statSync(absolutePath);\n\n if (stats.size > maxSize) {\n throw new Error(\n `File \"${absolutePath}\" is too large (${stats.size} bytes). Maximum allowed: ${maxSize} bytes.`,\n );\n }\n\n const content = fs.readFileSync(absolutePath, \"utf-8\");\n fileContents.push(content);\n } catch (error) {\n if (\n error instanceof Error &&\n \"code\" in error &&\n error.code === \"ENOENT\"\n ) {\n throw new Error(\n `File not found: \"${absolutePath}\" (referenced in ${sourceFile.fileName})`,\n );\n }\n throw new Error(\n `Failed to read file \"${absolutePath}\": ${\n error instanceof Error ? error.message : String(error)\n }`,\n );\n }\n }\n\n const elements = fileContents.map((content) =>\n this.factory.createStringLiteral(content),\n );\n\n return this.factory.createArrayLiteralExpression(elements, true) as any;\n}\n\nexport function inlineFileBase64$(\n this: MacroContext,\n filePath: string,\n options?: InlineBase64Options,\n): string {\n const absolutePath = resolveFilePath(filePath, this, \"inlineFileBase64$\");\n const maxSize = options?.maxSize || 100 * 1024;\n\n let content: string;\n try {\n const stats = fs.statSync(absolutePath);\n\n if (stats.size > maxSize) {\n throw new Error(\n `File \"${absolutePath}\" is too large (${stats.size} bytes). Maximum allowed: ${maxSize} bytes. Consider using uploadFile$ instead.`,\n );\n }\n\n const buffer = fs.readFileSync(absolutePath);\n content = buffer.toString(\"base64\");\n } catch (error) {\n if (error instanceof Error && \"code\" in error && error.code === \"ENOENT\") {\n throw new Error(\n `File not found: \"${absolutePath}\" (referenced in ${this.sourceFile.fileName})`,\n );\n }\n throw new Error(\n `Failed to read file \"${absolutePath}\": ${\n error instanceof Error ? error.message : String(error)\n }`,\n );\n }\n\n return this.factory.createStringLiteral(content) as any;\n}\n\nexport function inlineDataURL$(\n this: MacroContext,\n filePath: string,\n options?: InlineDataURLOptions,\n): string {\n const absolutePath = resolveFilePath(filePath, this, \"inlineDataURL$\");\n const maxSize = options?.maxSize || 100 * 1024;\n\n let dataURL: string;\n try {\n const stats = fs.statSync(absolutePath);\n\n if (stats.size > maxSize) {\n throw new Error(\n `File \"${absolutePath}\" is too large (${stats.size} bytes). Maximum allowed: ${maxSize} bytes. Consider using uploadFile$ instead.`,\n );\n }\n\n const mimeType = options?.mimeType || getMimeType(absolutePath);\n const buffer = fs.readFileSync(absolutePath);\n const base64 = buffer.toString(\"base64\");\n\n dataURL = `data:${mimeType};base64,${base64}`;\n } catch (error) {\n if (error instanceof Error && \"code\" in error && error.code === \"ENOENT\") {\n throw new Error(\n `File not found: \"${absolutePath}\" (referenced in ${this.sourceFile.fileName})`,\n );\n }\n throw new Error(\n `Failed to read file \"${absolutePath}\": ${\n error instanceof Error ? error.message : String(error)\n }`,\n );\n }\n\n return this.factory.createStringLiteral(dataURL) as any;\n}\n\nexport function inlineDataURLs$(\n this: MacroContext,\n filePaths: string[],\n options?: InlineDataURLOptions,\n): string[] {\n const pathsNode = filePaths as unknown as ts.Node;\n const resolvedPaths = this.resolveNodeValue(pathsNode);\n\n if (!Array.isArray(resolvedPaths)) {\n throw new Error(\n `inlineDataURLs$ requires an array of string literals, got: ${typeof resolvedPaths}`,\n );\n }\n\n const sourceFile = this.sourceFile;\n const sourceDir = path.dirname(sourceFile.fileName);\n const maxSize = options?.maxSize || 100 * 1024;\n\n const dataURLs: string[] = [];\n\n for (const filePath of resolvedPaths) {\n if (typeof filePath !== \"string\") {\n throw new Error(\n `inlineDataURLs$ requires all paths to be string literals, got: ${typeof filePath}`,\n );\n }\n\n const absolutePath = path.resolve(sourceDir, filePath);\n\n try {\n const stats = fs.statSync(absolutePath);\n\n if (stats.size > maxSize) {\n throw new Error(\n `File \"${absolutePath}\" is too large (${stats.size} bytes). Maximum allowed: ${maxSize} bytes.`,\n );\n }\n\n const mimeType = options?.mimeType || getMimeType(absolutePath);\n const buffer = fs.readFileSync(absolutePath);\n const base64 = buffer.toString(\"base64\");\n\n const dataURL = `data:${mimeType};base64,${base64}`;\n dataURLs.push(dataURL);\n } catch (error) {\n if (\n error instanceof Error &&\n \"code\" in error &&\n error.code === \"ENOENT\"\n ) {\n throw new Error(\n `File not found: \"${absolutePath}\" (referenced in ${sourceFile.fileName})`,\n );\n }\n throw new Error(\n `Failed to read file \"${absolutePath}\": ${\n error instanceof Error ? error.message : String(error)\n }`,\n );\n }\n }\n\n const elements = dataURLs.map((dataURL) =>\n this.factory.createStringLiteral(dataURL),\n );\n\n return this.factory.createArrayLiteralExpression(elements, true) as any;\n}\n"],
|
|
5
|
+
"mappings": ";AACA,OAAO,QAAQ;AAGf,IAAM,iBAAiB,oBAAI,IAAI;AAAA,EAC7B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAC;AAED,IAAM,WAAW,QAAQ,IAAI,aAAa;AAE1C,SAAS,WAAW,KAAqB;AACvC,MAAI,OAAO;AACX,WAAS,IAAI,GAAG,IAAI,IAAI,QAAQ,KAAK;AACnC,UAAM,OAAO,IAAI,WAAW,CAAC;AAC7B,YAAQ,QAAQ,KAAK,OAAO;AAC5B,WAAO,OAAO;AAAA,EAChB;AAEA,SAAO,KAAK,IAAI,IAAI,EAAE,SAAS,EAAE,EAAE,SAAS,GAAG,GAAG,EAAE,MAAM,GAAG,CAAC;AAChE;AAEA,SAAS,aACP,MACA,OACA,UACQ;AACR,QAAM,QAAQ,GAAG,IAAI,IAAI,KAAK;AAC9B,MAAI,OAAO,WAAW,KAAK;AAC3B,MAAI;AAEJ,MAAI,UAAU;AAEZ,UAAM,OAAO,KACV,QAAQ,YAAY,EAAE,EACtB,MAAM,GAAG,CAAC,EACV,YAAY;AACf,gBAAY,KAAK,IAAI,IAAI,IAAI;AAAA,EAC/B,OAAO;AACL,gBAAY,KAAK,IAAI;AAAA,EACvB;AAEA,MAAI,UAAU;AAGd,SAAO,SAAS,IAAI,SAAS,GAAG;AAC9B,UAAM,WAAW,SAAS,IAAI,SAAS;AACvC,UAAM,YAAY,YAAY,IAAI;AAClC,UAAM,kBAAkB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,YAAY,YAAY,YAAY;AAC9D,YAAM,SAAS,GAAG,aAAa,YAAY;AAC3C,YAAM,SAAS,OAAO,SAAS,QAAQ;AAEvC,YAAM,UAAU,QAAQ,QAAQ,WAAW,MAAM;AACjD,eAAS,KAAK,OAAO;AAAA,IACvB,SAAS,OAAO;AACd,UACE,iBAAiB,SACjB,UAAU,SACV,MAAM,SAAS,UACf;AACA,cAAM,IAAI;AAAA,UACR,oBAAoB,YAAY,oBAAoB,WAAW,QAAQ;AAAA,QACzE;AAAA,MACF;AACA,YAAM,IAAI;AAAA,QACR,wBAAwB,YAAY,MAClC,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,CACvD;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAEA,QAAM,WAAW,SAAS;AAAA,IAAI,CAAC,YAC7B,KAAK,QAAQ,oBAAoB,OAAO;AAAA,EAC1C;AAEA,SAAO,KAAK,QAAQ,6BAA6B,UAAU,IAAI;AACjE;",
|
|
6
6
|
"names": ["path", "className", "normalizedValue", "f"]
|
|
7
7
|
}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.node.d.ts","sourceRoot":"","sources":["../../src/index.node.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,
|
|
1
|
+
{"version":3,"file":"index.node.d.ts","sourceRoot":"","sources":["../../src/index.node.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/inline/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { MacroContext } from "@kithinji/pod";
|
|
2
|
+
export interface InlineFileOptions {
|
|
3
|
+
maxSize?: number;
|
|
4
|
+
}
|
|
5
|
+
export interface InlineDataURLOptions {
|
|
6
|
+
maxSize?: number;
|
|
7
|
+
mimeType?: string;
|
|
8
|
+
}
|
|
9
|
+
export interface InlineBase64Options {
|
|
10
|
+
maxSize?: number;
|
|
11
|
+
}
|
|
12
|
+
export declare function inlineFile$(this: MacroContext, filePath: string, options?: InlineFileOptions): string;
|
|
13
|
+
export declare function inlineFiles$(this: MacroContext, filePaths: string[], options?: InlineFileOptions): string[];
|
|
14
|
+
export declare function inlineFileBase64$(this: MacroContext, filePath: string, options?: InlineBase64Options): string;
|
|
15
|
+
export declare function inlineDataURL$(this: MacroContext, filePath: string, options?: InlineDataURLOptions): string;
|
|
16
|
+
export declare function inlineDataURLs$(this: MacroContext, filePaths: string[], options?: InlineDataURLOptions): string[];
|
|
17
|
+
//# sourceMappingURL=inline.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inline.d.ts","sourceRoot":"","sources":["../../../src/inline/inline.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAgE7C,MAAM,WAAW,iBAAiB;IAChC,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,oBAAoB;IACnC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,mBAAmB;IAClC,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,wBAAgB,WAAW,CACzB,IAAI,EAAE,YAAY,EAClB,QAAQ,EAAE,MAAM,EAChB,OAAO,CAAC,EAAE,iBAAiB,GAC1B,MAAM,CA6BR;AAED,wBAAgB,YAAY,CAC1B,IAAI,EAAE,YAAY,EAClB,SAAS,EAAE,MAAM,EAAE,EACnB,OAAO,CAAC,EAAE,iBAAiB,GAC1B,MAAM,EAAE,CA2DV;AAED,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,YAAY,EAClB,QAAQ,EAAE,MAAM,EAChB,OAAO,CAAC,EAAE,mBAAmB,GAC5B,MAAM,CA8BR;AAED,wBAAgB,cAAc,CAC5B,IAAI,EAAE,YAAY,EAClB,QAAQ,EAAE,MAAM,EAChB,OAAO,CAAC,EAAE,oBAAoB,GAC7B,MAAM,CAiCR;AAED,wBAAgB,eAAe,CAC7B,IAAI,EAAE,YAAY,EAClB,SAAS,EAAE,MAAM,EAAE,EACnB,OAAO,CAAC,EAAE,oBAAoB,GAC7B,MAAM,EAAE,CA+DV"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { MacroContext } from "@kithinji/pod";
|
|
2
2
|
import ts from "typescript";
|
|
3
3
|
import { MapNamespaces } from "./style_types";
|
|
4
|
-
export declare function style$<const T extends Record<string, any>>(
|
|
5
|
-
export declare function apply$(...c: any[]): ts.ObjectLiteralExpression;
|
|
4
|
+
export declare function style$<const T extends Record<string, any>>(this: MacroContext, style: T): MapNamespaces<T>;
|
|
5
|
+
export declare function apply$(this: MacroContext, ...c: any[]): ts.ObjectLiteralExpression;
|
|
6
6
|
//# sourceMappingURL=style.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"style.d.ts","sourceRoot":"","sources":["../../../src/style/style.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAE,MAAM,YAAY,CAAC;AAC5B,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAoQ9C,wBAAgB,MAAM,CAAC,KAAK,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EACxD,
|
|
1
|
+
{"version":3,"file":"style.d.ts","sourceRoot":"","sources":["../../../src/style/style.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAE,MAAM,YAAY,CAAC;AAC5B,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAoQ9C,wBAAgB,MAAM,CAAC,KAAK,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EACxD,IAAI,EAAE,YAAY,EAClB,KAAK,EAAE,CAAC,GACP,aAAa,CAAC,CAAC,CAAC,CA8BlB;AAMD,wBAAgB,MAAM,CAAC,IAAI,EAAE,YAAY,EAAE,GAAG,CAAC,EAAE,GAAG,EAAE,8BA6MrD"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kithinji/arcane",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.9",
|
|
4
4
|
"description": "",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test": "echo \"Error: no test specified\" && exit 1",
|
|
@@ -28,6 +28,6 @@
|
|
|
28
28
|
"typescript": "^5.9.3"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@kithinji/pod": "^1.0.
|
|
31
|
+
"@kithinji/pod": "^1.0.34"
|
|
32
32
|
}
|
|
33
33
|
}
|
package/src/index.node.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export * from "./style";
|
|
2
|
-
export * from "./inline
|
|
2
|
+
export * from "./inline";
|
package/src/index.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export * from "./style";
|
|
2
|
-
export * from "./inline
|
|
2
|
+
export * from "./inline";
|