@dongmingzhixiu/vuexir-compiler 0.2.3 → 0.3.0
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/codegen/compose.js +23 -3
- package/package.json +1 -1
package/dist/codegen/compose.js
CHANGED
|
@@ -320,9 +320,28 @@ class NavTest {
|
|
|
320
320
|
}
|
|
321
321
|
`;
|
|
322
322
|
/* ================= IR → Compose 生成 ================= */
|
|
323
|
-
/**
|
|
323
|
+
/**
|
|
324
|
+
* 颜色 → Compose Color 表达式。
|
|
325
|
+
* 支持 #rgb/#rrggbb 与 rgb()/rgba()(rgba 必须带 alpha,否则会拼出 `0xFFRGBA(...)` 这种非法字面量)。
|
|
326
|
+
*/
|
|
324
327
|
function colorExpr(c) {
|
|
325
|
-
const
|
|
328
|
+
const raw = c.trim();
|
|
329
|
+
const fn = raw.match(/^rgba?\(([^)]+)\)$/i);
|
|
330
|
+
if (fn) {
|
|
331
|
+
const parts = fn[1].split(',').map((t) => Number(t.trim()));
|
|
332
|
+
const [r, g, b] = parts;
|
|
333
|
+
const a = parts.length > 3 && Number.isFinite(parts[3]) ? parts[3] : 1;
|
|
334
|
+
if ([r, g, b].every((n) => Number.isFinite(n))) {
|
|
335
|
+
const hex = `FF${Math.round(r).toString(16).padStart(2, '0')}${Math.round(g)
|
|
336
|
+
.toString(16)
|
|
337
|
+
.padStart(2, '0')}${Math.round(b).toString(16).padStart(2, '0')}`.toUpperCase();
|
|
338
|
+
const alpha = `0x${Math.round(a * 255)
|
|
339
|
+
.toString(16)
|
|
340
|
+
.padStart(2, '0')}`.toUpperCase();
|
|
341
|
+
return `Color(0x${alpha.slice(2)}${hex.slice(2)})`;
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
const hex = raw.replace('#', '').toUpperCase();
|
|
326
345
|
const full = hex.length === 3 ? hex.split('').map((h) => h + h).join('') : hex;
|
|
327
346
|
return `Color(0xFF${full.padEnd(6, '0')})`;
|
|
328
347
|
}
|
|
@@ -590,7 +609,8 @@ function inlineHandlerKotlin(fn) {
|
|
|
590
609
|
return null;
|
|
591
610
|
}
|
|
592
611
|
}
|
|
593
|
-
|
|
612
|
+
// 单个 lambda 内联:多语句必须用 '; ' 连接(裸换行会让 `clickable { a\nb = c }` 语法错)
|
|
613
|
+
return out.length > 0 ? out.join('; ') : null;
|
|
594
614
|
}
|
|
595
615
|
/** 点击事件 → Kotlin 表达式(A5:onSet 内联赋值;onClick 模式识别:自增减/路由 push/无参 handler 内联/其他 JS TODO) */
|
|
596
616
|
function kotlinClickAction(p, ctx, loop) {
|