poseui 0.0.2 → 0.0.3

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/index.d.ts CHANGED
@@ -782,17 +782,17 @@ interface PoseElement<TProps extends Record<string, unknown>, TSchema extends St
782
782
  * Apply styles conditionally — predicate form or value-switch form.
783
783
  *
784
784
  * Predicate form (apply when true):
785
- * ```ts
785
+ * \`\`\`ts
786
786
  * .when(({ disabled }) => disabled, (b) => b.opacity(50).cursor_not_allowed())
787
- * ```
787
+ * \`\`\`
788
788
  *
789
789
  * Value form (switch on a prop key):
790
- * ```ts
790
+ * \`\`\`ts
791
791
  * .when("variant", {
792
792
  * primary: (b) => b.bg("indigo-600").text_color("white"),
793
793
  * secondary: (b) => b.bg("slate-200").text_color("slate-900"),
794
794
  * })
795
- * ```
795
+ * \`\`\`
796
796
  * Cases are Partial — unmatched values emit no classes.
797
797
  * Multiple .when() calls are independent and all evaluated at render time.
798
798
  */
@@ -808,7 +808,7 @@ interface PoseElement<TProps extends Record<string, unknown>, TSchema extends St
808
808
  child(fn: (props: TProps) => ChildValue): PoseElement<TProps, TSchema>;
809
809
  child(value: ChildValue): PoseElement<TProps, TSchema>;
810
810
  /**
811
- * Render to `{ html, css }` using UnoCSS + presetWind4.
811
+ * Render to \`{ html, css }\` using UnoCSS + presetWind4.
812
812
  * @example
813
813
  * const { html, css } = await card.render({ name: 'Ada' })
814
814
  */
package/dist/index.js CHANGED
@@ -35,7 +35,7 @@ function renderChild(child, props) {
35
35
  if (child != null && typeof child === "object" && "__pose" in child) return child(props);
36
36
  return child == null ? "" : String(child);
37
37
  }
38
- /** A tagless builder used inside .when() callbacks — only accumulates classes. */
38
+ /** A tagless builder used inside .when() callbacks — only accumulates classes and children. */
39
39
  function createBlankBuilder() {
40
40
  return createBuilder({
41
41
  tag: "div",
@@ -76,6 +76,7 @@ function createBuilder(state) {
76
76
  return buildHtml(result);
77
77
  }
78
78
  render.__pose = true;
79
+ render.__state = state;
79
80
  const el = render;
80
81
  Object.defineProperty(el, "classes", {
81
82
  get: () => state.classes,
@@ -464,20 +465,30 @@ function createBuilder(state) {
464
465
  el.stroke_w = (n) => dynCls(n, (v) => tw("stroke", v));
465
466
  el.sr_only = () => cls("sr-only");
466
467
  el.not_sr_only = () => cls("not-sr-only");
468
+ function applyBranch(getBranch) {
469
+ const classEntry = (props) => {
470
+ const branch = getBranch(props);
471
+ return branch ? resolveClasses(branch.classes, props) : "";
472
+ };
473
+ const childEntry = (props) => {
474
+ const branch = getBranch(props);
475
+ if (!branch) return null;
476
+ const branchState = branch.__state;
477
+ if (!branchState.children.length) return null;
478
+ return branchState.children.map((c) => typeof c === "function" ? c(props) : c);
479
+ };
480
+ return derive([classEntry], [childEntry]);
481
+ }
467
482
  el.when = (...args) => {
468
483
  if (typeof args[0] === "function") {
469
484
  const [pred, apply] = args;
470
- return derive([(props) => {
471
- if (!pred(props)) return "";
472
- return resolveClasses(apply(createBlankBuilder()).classes, props);
473
- }]);
485
+ return applyBranch((props) => pred(props) ? apply(createBlankBuilder()) : null);
474
486
  } else {
475
487
  const [key, cases] = args;
476
- return derive([(props) => {
488
+ return applyBranch((props) => {
477
489
  const branch = cases[props[key]];
478
- if (!branch) return "";
479
- return resolveClasses(branch(createBlankBuilder()).classes, props);
480
- }]);
490
+ return branch ? branch(createBlankBuilder()) : null;
491
+ });
481
492
  }
482
493
  };
483
494
  el.cls = (value) => typeof value === "function" ? derive([value]) : derive([value]);
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "poseui",
3
- "version": "0.0.2",
3
+ "version": "0.0.3",
4
4
  "description": "Type-safe HTML templating engine on steroids",
5
5
  "license": "MIT",
6
6
  "author": "Ryuz <ryuzer@proton.me>",
7
7
  "repository": {
8
8
  "type": "git",
9
- "url": "git+https://github.com/guarana-studio/poseui.git"
9
+ "url": "git+https://github.com/guarana-studio/pose.git"
10
10
  },
11
11
  "files": [
12
12
  "dist"