{
  "$schema": "https://registry.buildy.tw/schema/registry-item.json",
  "dependencies": [],
  "description": "jinja2 helpers (class merge, variants, attributes) used by every template",
  "devDependencies": [],
  "digest": "0.1.0",
  "files": [
    {
      "content": "# Code generated by packages/kit-compose/src/server-organisms.ts from packages/compose-gen/specs (compose-gen organism emitters on kit-compose). DO NOT EDIT.\n\"\"\"The helpers of the codegen-x organism templates for Jinja2 (blocks/<organism>.html.j2, called with `p` and `children`):\n`register(env, root)` adds them as og_* globals to the kit + compose Environment.\"\"\"\n\nfrom __future__ import annotations\n\nimport functools\nfrom typing import Any\n\nfrom jinja2 import Environment, pass_environment\nfrom jinja2.runtime import Undefined\nfrom markupsafe import Markup\n\nfrom . import runtime as rt\n\n\ndef _plain(v: Any) -> Any:\n    if isinstance(v, Undefined):\n        return None\n    if isinstance(v, list):\n        return [_plain(x) for x in v]\n    return v\n\n\ndef _wrap(f: Any, safe: bool = False) -> Any:\n    @functools.wraps(f)\n    def call(*args: Any) -> Any:\n        out = f(*[_plain(a) for a in args])\n        return Markup(out) if safe else out\n    return call\n\n\n@pass_environment\ndef _include(env: Environment, name: Any, vars: Any) -> Markup:\n    return Markup(env.get_template(str(name)).render(_plain(vars) or {}))\n\n\ndef _merge(a: Any, b: Any) -> dict:\n    return {**(_plain(a) or {}), **(_plain(b) or {})}\n\n\n_NAMES = {\n    \"and\": \"and_\", \"or\": \"or_\", \"def\": \"def_\", \"len\": \"len_\", \"str\": \"str_\", \"range\": \"range_\", \"max\": \"max_\", \"min\": \"min_\", \"round\": \"round_\", \"html\": \"html_\",\n}\n_PLAIN = [\n    \"get\", \"field\", \"s\", \"text\", \"html\", \"t\", \"n\", \"i\", \"eq\", \"lt\", \"gt\", \"le\", \"ge\", \"add\", \"sub\", \"mul\", \"div\", \"and\", \"or\", \"coalesce\", \"def\", \"l\",\n    \"len\", \"spread\", \"str\", \"has\", \"cnv\", \"tpl\", \"num\", \"money\", \"at\", \"page_window\", \"fit_cols\", \"uniq\", \"words\", \"nbsp\", \"nth\", \"range\",\n    \"max\", \"min\", \"round\", \"count\", \"where\", \"match\", \"pick\", \"sum_by\", \"first_of\", \"max_by\", \"css\", \"attrs\", \"is_set_str\", \"default_if_empty\",\n    \"map_or\", \"int_map_or\", \"bool_str\", \"concat_trim\", \"cn\", \"resolve_tag\", \"title_tag\", \"compose\", \"recipe\", \"preset\", \"url\", \"srcset\", \"style\", \"slot\", \"markup\",\n]\n\n\ndef register(env: Environment, root: str) -> Environment:\n    \"\"\"registers the og_* helpers of the organism templates (blocks/*) on an Environment whose loader also finds the\n    compositions (compose/*) and the kit primitives (ui/*); root holds blocks/recipes, blocks/presets and icons/\"\"\"\n    rt.set_root(root)\n    for name in _PLAIN:\n        env.globals[\"og_\" + name] = _wrap(getattr(rt, _NAMES.get(name, name)))\n    env.globals[\"og_attr_html\"] = _wrap(rt.attr_html, safe=True)\n    env.globals[\"og_lucide\"] = _wrap(rt.lucide, safe=True)\n    env.globals[\"og_include\"] = _include\n    env.globals[\"og_merge\"] = _merge\n    return env\n",
      "path": "compose_organisms/__init__.py",
      "target": "compose_organisms/__init__.py"
    },
    {
      "content": "# Code generated by packages/kit-compose/src/server-organisms.ts from packages/compose-gen/specs (compose-gen organism emitters on kit-compose). DO NOT EDIT.\n\"\"\"cn: class fragments joined with tailwind-merge conflict resolution (the last class of a group wins, and a class removes\nthe earlier classes of the groups it overrides: p-2 removes px-4, not the reverse). Port of cn_merge.go.\"\"\"\n\nfrom __future__ import annotations\n\n_DISPLAY = {\"block\", \"inline\", \"inline-block\", \"inline-flex\", \"flex\", \"grid\", \"contents\", \"hidden\"}\n_PREFIXES = [\n    (\"gap-x-\", \"gap-x\"), (\"gap-y-\", \"gap-y\"), (\"items-\", \"align-items\"), (\"justify-\", \"justify-content\"),\n    (\"self-\", \"align-self\"), (\"content-\", \"align-content\"), (\"overflow-x-\", \"overflow-x\"), (\"overflow-y-\", \"overflow-y\"),\n    (\"inset-x-\", \"inset-x\"), (\"inset-y-\", \"inset-y\"), (\"min-w-\", \"min-width\"), (\"min-h-\", \"min-height\"),\n    (\"max-w-\", \"max-width\"), (\"max-h-\", \"max-height\"), (\"shadow-\", \"shadow\"), (\"ring-\", \"ring\"), (\"rounded-\", \"rounded\"),\n    (\"leading-\", \"leading\"), (\"tracking-\", \"tracking\"), (\"opacity-\", \"opacity\"), (\"z-\", \"z\"), (\"top-\", \"top\"),\n    (\"right-\", \"right\"), (\"bottom-\", \"bottom\"), (\"left-\", \"left\"),\n]\n_TEXT_SIZES = {\"text-xs\", \"text-sm\", \"text-base\", \"text-lg\", \"text-xl\"} | {f\"text-{n}xl\" for n in range(2, 10)}\n_WEIGHTS = {f\"font-{w}\" for w in (\"thin\", \"extralight\", \"light\", \"normal\", \"medium\", \"semibold\", \"bold\", \"extrabold\", \"black\")}\n\n\ndef _is_number(s: str) -> bool:\n    if s.startswith(\"[\"):\n        return True\n    return s != \"\" and all(c in \"0123456789.\" for c in s)\n\n\ndef _split_variant(token: str) -> tuple[str, str]:\n    depth, cut = 0, -1\n    for i, c in enumerate(token):\n        if c == \"[\":\n            depth += 1\n        elif c == \"]\":\n            depth = max(0, depth - 1)\n        elif c == \":\" and depth == 0:\n            cut = i\n    core = token if cut == -1 else token[cut + 1:]\n    core = core[1:] if core.startswith(\"!\") else core\n    return (\"\" if cut == -1 else token[:cut + 1]), core\n\n\ndef _has_direction(core: str, kind: str) -> bool:\n    return any(core.startswith(kind + d) for d in (\"x-\", \"y-\", \"t-\", \"r-\", \"b-\", \"l-\", \"s-\", \"e-\"))\n\n\ndef _space_axis(core: str, kind: str, n: str) -> list[str]:\n    if core.startswith(kind + \"x-\"):\n        return [f\"{n}-x\", f\"{n}-r\", f\"{n}-l\", f\"{n}-s\", f\"{n}-e\"]\n    if core.startswith(kind + \"y-\"):\n        return [f\"{n}-y\", f\"{n}-t\", f\"{n}-b\"]\n    for s in \"trbl\":\n        if core.startswith(kind + s + \"-\"):\n            return [f\"{n}-{s}\"]\n    return []\n\n\ndef _groups(core: str) -> list[str]:\n    if core in _DISPLAY:\n        return [\"display\"]\n    if core in (\"flex-row\", \"flex-col\", \"flex-row-reverse\", \"flex-col-reverse\"):\n        return [\"flex-direction\"]\n    if core in (\"static\", \"relative\", \"absolute\", \"fixed\", \"sticky\"):\n        return [\"position\"]\n    if core in (\"isolate\", \"isolation-auto\"):\n        return [\"isolation\"]\n    for kind in (\"inset-ring\", \"ring\"):\n        if core == kind:\n            return [kind + \"-width\"]\n        if core.startswith(kind + \"-\"):\n            return [kind + (\"-width\" if _is_number(core[len(kind) + 1:]) else \"-color\")]\n    for p, g in _PREFIXES:\n        if core.startswith(p):\n            return [g]\n    if core.startswith(\"gap-\"):\n        return [\"gap\", \"gap-x\", \"gap-y\"]\n    if core.startswith(\"inset-\"):\n        return [\"inset\", \"inset-x\", \"inset-y\", \"top\", \"right\", \"bottom\", \"left\"]\n    if core.startswith(\"overflow-\"):\n        return [\"overflow\", \"overflow-x\", \"overflow-y\"]\n    if core == \"border\" or (core.startswith(\"border-\") and _is_number(core[7:])):\n        return [\"border-width\"] + [f\"border-w-{s}\" for s in \"xytrblse\"]\n    if len(core) >= 8 and core.startswith(\"border-\") and core[7] in \"xytrblse\" and (len(core) == 8 or (core[8] == \"-\" and _is_number(core[9:]))):\n        side = core[7]\n        if side == \"x\":\n            return [\"border-w-x\", \"border-w-r\", \"border-w-l\", \"border-w-s\", \"border-w-e\"]\n        if side == \"y\":\n            return [\"border-w-y\", \"border-w-t\", \"border-w-b\"]\n        return [\"border-w-\" + side]\n    if core in (\"text-left\", \"text-center\", \"text-right\", \"text-justify\", \"text-start\", \"text-end\"):\n        return [\"text-align\"]\n    if core == \"rounded\":\n        return [\"rounded\"]\n    if core in (\"shadow\", \"shadow-none\"):\n        return [\"shadow\"]\n    if core in (\"flex-1\", \"flex-auto\", \"flex-none\", \"flex-initial\"):\n        return [\"flex-size\", \"flex-grow\", \"flex-shrink\", \"flex-basis\"]\n    if core == \"grow\" or core.startswith(\"grow-\"):\n        return [\"flex-grow\"]\n    if core in (\"shrink\", \"shrink-0\"):\n        return [\"flex-shrink\"]\n    if core.startswith(\"size-\"):\n        return [\"size\", \"width\", \"height\"]\n    if core.startswith(\"w-\"):\n        return [\"width\"]\n    if core.startswith(\"h-\"):\n        return [\"height\"]\n    for kind, n in ((\"p\", \"padding\"), (\"m\", \"margin\")):\n        if core.startswith(kind + \"-\") and not _has_direction(core, kind):\n            return [n] + [f\"{n}-{s}\" for s in \"xytrblse\"]\n        axis = _space_axis(core, kind, n)\n        if axis:\n            return axis\n    if core.startswith(\"bg-\"):\n        return [\"bg\"]\n    if core in _TEXT_SIZES or (core.startswith(\"text-[\") and len(core) > 6 and (core[6].isdigit() or core[6] == \".\")):\n        return [\"text-size\", \"leading\"]\n    if core.startswith(\"text-\"):\n        return [\"text-color\"]\n    if core in _WEIGHTS:\n        return [\"font-weight\"]\n    return []\n\n\ndef merge(classes: list[str]) -> str:\n    kept: list[tuple[str, str]] = []\n    for chunk in classes:\n        for token in str(chunk).split():\n            prefix, core = _split_variant(token)\n            key = \"\"\n            removes: list[str] = []\n            if core:\n                g = _groups(core)\n                if g:\n                    key, removes = prefix + g[0], g[1:]\n                else:\n                    key = \"=\" + token\n            if key:\n                drop = {key} | {prefix + r for r in removes}\n                kept = [it for it in kept if it[1] not in drop]\n            kept.append((token, key))\n    return \" \".join(t for t, _ in kept)\n",
      "path": "compose_organisms/cn_merge.py",
      "target": "compose_organisms/cn_merge.py"
    },
    {
      "content": "# Code generated by packages/kit-compose/src/server-organisms.ts from packages/compose-gen/specs (compose-gen organism emitters on kit-compose). DO NOT EDIT.\n\"\"\"The helpers of the generated templates. Values are the JSON shapes of the TypeScript props (str, int/float, bool,\nNone, list, dict) read with the rules of the TypeScript output: JS truthiness, strict equality, String(), clsx +\ntailwind-merge. Every helper is None-safe, like `?.`. Port of the Go runtime (dyn.go, expr.go, utils.go) and of the PHP\nruntime of the Twig package, so every static runtime prints the same DOM.\"\"\"\n\nfrom __future__ import annotations\n\nimport html\nimport json\nimport math\nimport os\nimport re\nfrom typing import Any\n\nfrom .cn_merge import merge\n\n_ROOT = \"\"\n_JSON: dict[str, Any] = {}\n\n\ndef set_root(root: str) -> None:\n    global _ROOT\n    _ROOT = root\n\n\ndef load_json(path: str) -> Any:\n    if path not in _JSON:\n        with open(os.path.join(_ROOT, path), encoding=\"utf-8\") as f:\n            _JSON[path] = json.load(f)\n    return _JSON[path]\n\n\n# ------------------------------------------------------------------ values\n\ndef _num(v: Any) -> bool:\n    return isinstance(v, (int, float)) and not isinstance(v, bool)\n\n\ndef get(v: Any, path: list) -> Any:\n    \"\"\"a path of fields: get(plan, ['price', 'amount']); `length` of a list or a text is its size\"\"\"\n    for k in path:\n        k = str(k)\n        if isinstance(v, list):\n            if k == \"length\":\n                v = len(v)\n            elif k.isdigit() and int(k) < len(v):\n                v = v[int(k)]\n            else:\n                return None\n        elif isinstance(v, dict):\n            v = v.get(k)\n        elif isinstance(v, str) and k == \"length\":\n            v = len(v)\n        else:\n            return None\n    return v\n\n\ndef field(item: Any, name: str, zero: Any) -> Any:\n    \"\"\"a field of a brick record: the JSON key matched without regard to case, as Go json does\"\"\"\n    if not isinstance(item, dict):\n        return zero\n    if name in item:\n        return zero if item[name] is None else item[name]\n    for k, v in item.items():\n        if str(k).lower() == name.lower():\n            return zero if v is None else v\n    return zero\n\n\ndef fmt_num(f: Any) -> str:\n    \"\"\"String(n) of JavaScript for the numbers the views print\"\"\"\n    if isinstance(f, int):\n        return str(f)\n    if math.isnan(f):\n        return \"NaN\"\n    if math.isinf(f):\n        return \"Infinity\" if f > 0 else \"-Infinity\"\n    if f == math.floor(f) and abs(f) < 1e21:\n        return \"%d\" % int(f)\n    return repr(f)\n\n\ndef s(v: Any) -> str:\n    if v is None:\n        return \"\"\n    if isinstance(v, str):\n        return v\n    if isinstance(v, bool):\n        return \"true\" if v else \"false\"\n    if _num(v):\n        return fmt_num(v)\n    return json.dumps(v, separators=(\",\", \":\"), ensure_ascii=False)\n\n\ndef text(v: Any) -> str:\n    \"\"\"what a text node shows: nothing for None and booleans\"\"\"\n    return \"\" if isinstance(v, bool) else s(v)\n\n\n_ENTITIES = {\"&\": \"&amp;\", \"<\": \"&lt;\", \">\": \"&gt;\", '\"': \"&quot;\", \"'\": \"&#39;\"}\n\n\ndef html_(v: Any) -> str:\n    \"\"\"the markup an html node prints (with |safe): the trusted markup ({\"__html\": \"...\"}, a TrustedHtml prop) as it is; any other\n    value is text, escaped (& < > \" ' as entities, like htmlOf of the TypeScript runtimes)\"\"\"\n    if isinstance(v, dict) and isinstance(v.get(\"__html\"), str):\n        return v[\"__html\"]\n    return \"\".join(_ENTITIES.get(c, c) for c in text(v))\n\n\ndef slot(v: Any) -> str:\n    \"\"\"a slot prop printed in place (|safe): the markup the calling template captured ({\"__html\": ...}, made by markup()) as it\n    is; any other value (a plain string from a caller) is text, escaped\"\"\"\n    return html_(v)\n\n\ndef markup(v: Any) -> dict:\n    \"\"\"captured markup (a fill of a slot) as a TrustedHtml marker, which slot() prints as it is\"\"\"\n    return {\"__html\": \"\" if v is None else str(v)}\n\n\n# ------------------------------------------------------------------ output safety (assets/ts/safe.ts, test/safety-vectors.json)\n\nNAMED_ENTITIES = {\n    \"Tab\": \"\\t\", \"NewLine\": \"\\n\", \"colon\": \":\", \"sol\": \"/\", \"bsol\": \"\\\\\", \"lpar\": \"(\", \"rpar\": \")\", \"amp\": \"&\", \"lt\": \"<\", \"gt\": \">\",\n    \"quot\": '\"', \"apos\": \"'\", \"nbsp\": \"\\u00a0\", \"period\": \".\", \"comma\": \",\", \"excl\": \"!\", \"num\": \"#\", \"quest\": \"?\", \"equals\": \"=\",\n    \"plus\": \"+\", \"semi\": \";\", \"percnt\": \"%\", \"lowbar\": \"_\", \"ast\": \"*\", \"commat\": \"@\", \"dollar\": \"$\", \"Hat\": \"^\", \"grave\": \"`\",\n    \"lsqb\": \"[\", \"rsqb\": \"]\", \"lcub\": \"{\", \"rcub\": \"}\", \"verbar\": \"|\", \"vert\": \"|\",\n}\nURL_SCHEMES = [\"http\", \"https\", \"mailto\", \"tel\"]\nURL_ATTRS = [\"href\", \"src\", \"action\", \"formaction\", \"poster\", \"cite\", \"background\", \"data\", \"xlink:href\"]\nIMAGE_ATTRS = [\"src\", \"poster\", \"background\"]\n_ENTITY = re.compile(r\"&(?:#[xX]([0-9a-fA-F]{1,8});?|#([0-9]{1,10});?|([a-zA-Z][a-zA-Z0-9]{0,31});)\")\n_DATA_IMAGE = re.compile(r\"^data:image/(png|jpeg|gif|webp|avif|svg\\+xml)[;,]\")\n\n\ndef _from_code(n: int) -> str:\n    return chr(n) if 0 < n <= 0x10FFFF and not (0xD800 <= n <= 0xDFFF) else \"\\ufffd\"\n\n\ndef decode_entities(v: str) -> str:\n    \"\"\"character references decoded as a browser would (numeric with or without ;, the named ones of NAMED_ENTITIES), up to 3 rounds\"\"\"\n    def one(m: \"re.Match[str]\") -> str:\n        if m.group(1) is not None:\n            return _from_code(int(m.group(1), 16))\n        if m.group(2) is not None:\n            return _from_code(int(m.group(2), 10))\n        return NAMED_ENTITIES.get(m.group(3), m.group(0))\n    i = 0\n    while i < 3 and \"&\" in v:\n        v = _ENTITY.sub(one, v)\n        i += 1\n    return v\n\n\ndef _compact(v: str) -> str:\n    return re.sub(r\"[\\x00-\\x20\\x7f]+\", \"\", decode_entities(v))\n\n\ndef is_safe_url(v: str, image: bool = False) -> bool:\n    \"\"\"true when the URL is allowed: no scheme and not //host, or http(s), mailto, tel; an image also data:image/*\"\"\"\n    k = _compact(v)\n    if re.match(r\"^[/\\\\]{2}\", k):\n        return False\n    m = re.match(r\"^([a-zA-Z][a-zA-Z0-9+.\\-]*):\", k)\n    if not m:\n        # no scheme: a path, unless a \":\" comes before any \"/\" (as written or decoded), as templ.URL\n        return not re.match(r\"^[^/]*:\", k) and not re.match(r\"^[^/]*:\", v)\n    scheme = m.group(1).lower()\n    if scheme == \"data\":\n        return image and bool(_DATA_IMAGE.match(k.lower()))\n    return scheme in URL_SCHEMES\n\n\ndef _str(v: Any) -> str:\n    return v if isinstance(v, str) else fmt_num(v) if _num(v) else \"\"\n\n\ndef url(v: Any, image: bool = False) -> str:\n    \"\"\"a URL attribute value: the value when allowed, else ''\"\"\"\n    x = _str(v)\n    return x if is_safe_url(x, image) else \"\"\n\n\ndef srcset_urls(v: str) -> list:\n    \"\"\"the URLs of a srcset, candidate by candidate\"\"\"\n    x, out, i = decode_entities(v), [], 0\n    n = len(x)\n    ws = lambda c: c in \"\\t\\n\\f\\r \"  # noqa: E731\n    while i < n:\n        while i < n and (ws(x[i]) or x[i] == \",\"):\n            i += 1\n        if i >= n:\n            break\n        j = i\n        while j < n and not ws(x[j]):\n            j += 1\n        u = x[i:j]\n        cut = re.search(r\",+$\", u)\n        if cut:\n            out.append(u[: -len(cut.group(0))])\n            i = j\n            continue\n        out.append(u)\n        depth = 0\n        while j < n and (depth > 0 or x[j] != \",\"):\n            if x[j] == \"(\":\n                depth += 1\n            elif x[j] == \")\":\n                depth = max(0, depth - 1)\n            j += 1\n        i = j + 1\n    return out\n\n\ndef srcset(v: Any) -> str:\n    \"\"\"a srcset value: the value when every candidate is an allowed image URL, else ''\"\"\"\n    x = _str(v)\n    return x if all(is_safe_url(u, True) for u in srcset_urls(x)) else \"\"\n\n\ndef style(v: Any) -> str:\n    \"\"\"a style value: '' when a url(...) is not an image URL or it holds a script form or a CSS escape, else the value\"\"\"\n    x = _str(v)\n    d, k = decode_entities(x), _compact(x).lower()\n    if \"\\\\\" in d or re.search(r\"expression\\(|javascript:|vbscript:|-moz-binding|behavior:\", k):\n        return \"\"\n    for m in re.finditer(r\"url\\(([^)]*)\\)?\", d, re.I):\n        arg = re.sub(r\"^(['\\\"])(.*)\\1$\", r\"\\2\", m.group(1).strip(\" \\t\\n\\r\\f\\v\"), flags=re.S)\n        if not is_safe_url(arg, True):\n            return \"\"\n    return x\n\n\ndef css_value(v: Any) -> str:\n    \"\"\"a value of an inline style declaration (the css op): kept when plain (numbers, words, %, #, +, -, ., commas, spaces), else ''\"\"\"\n    x = _str(v)\n    return x if re.fullmatch(r\"[-+.%#a-zA-Z0-9 ,]*\", x) else \"\"\n\n\ndef is_safe_attr_name(name: str) -> bool:\n    \"\"\"an attribute name that may be printed: a valid name, not an event handler (on*)\"\"\"\n    return bool(re.fullmatch(r\"[a-zA-Z_:][-a-zA-Z0-9_:.]*\", name)) and not re.match(r\"on\", name, re.I)\n\n\ndef attr_value(name: str, v: Any) -> Any:\n    \"\"\"the value of attribute name as it may be printed: URL, srcset and style checked\"\"\"\n    n = name.lower()\n    if n in (\"srcset\", \"imagesrcset\"):\n        return srcset(v)\n    if n == \"style\":\n        return style(v)\n    if n in URL_ATTRS:\n        return url(v, n in IMAGE_ATTRS)\n    return v\n\n\ndef t(v: Any) -> bool:\n    \"\"\"JS truthiness: None, False, 0, NaN and '' are false\"\"\"\n    if v is None:\n        return False\n    if isinstance(v, bool):\n        return v\n    if isinstance(v, str):\n        return v != \"\"\n    if _num(v):\n        return v != 0 and not math.isnan(v)\n    return True\n\n\ndef n(v: Any) -> float:\n    if _num(v):\n        return float(v)\n    if isinstance(v, bool):\n        return 1.0 if v else 0.0\n    if isinstance(v, str):\n        try:\n            return float(v.strip())\n        except ValueError:\n            return 0.0\n    return 0.0\n\n\ndef _round_half_away(f: float) -> float:\n    return math.copysign(math.floor(abs(f) + 0.5), f)\n\n\ndef i(v: Any) -> int:\n    return int(_round_half_away(n(v)))\n\n\ndef eq(a: Any, b: Any) -> bool:\n    \"\"\"strict equality (===)\"\"\"\n    if _num(a) or _num(b):\n        return _num(a) and _num(b) and float(a) == float(b)\n    if a is None:\n        return b is None\n    if isinstance(a, bool) or isinstance(b, bool):\n        return isinstance(a, bool) and isinstance(b, bool) and a == b\n    if isinstance(a, str):\n        return isinstance(b, str) and a == b\n    return False\n\n\ndef _cmp(a: Any, b: Any) -> int | None:\n    if isinstance(a, str) and isinstance(b, str):\n        return (a > b) - (a < b)\n    if a is None or b is None:\n        return None\n    x, y = n(a), n(b)\n    return (x > y) - (x < y)\n\n\ndef lt(a, b): c = _cmp(a, b); return c is not None and c < 0\ndef gt(a, b): c = _cmp(a, b); return c is not None and c > 0\ndef le(a, b): c = _cmp(a, b); return c is not None and c <= 0\ndef ge(a, b): c = _cmp(a, b); return c is not None and c >= 0\n\n\ndef add(a: Any, b: Any) -> Any:\n    if isinstance(a, str) or isinstance(b, str):\n        return s(a) + s(b)\n    return n(a) + n(b)\n\n\ndef sub(a, b): return n(a) - n(b)\ndef mul(a, b): return n(a) * n(b)\n\n\ndef div(a: Any, b: Any) -> float:\n    x, y = n(a), n(b)\n    if y == 0:\n        return math.nan if x == 0 or math.isnan(x) else math.copysign(math.inf, x) * math.copysign(1, y)\n    return x / y\n\n\ndef and_(vs: list) -> Any:\n    last = None\n    for v in vs:\n        if not t(v):\n            return v\n        last = v\n    return last\n\n\ndef or_(vs: list) -> Any:\n    last = None\n    for v in vs:\n        if t(v):\n            return v\n        last = v\n    return last\n\n\ndef coalesce(vs: list) -> Any:\n    return next((v for v in vs if v is not None), None)\n\n\ndef def_(v: Any, d: Any) -> Any:\n    \"\"\"a prop with its default: the default when the prop is None or missing\"\"\"\n    return d if v is None else v\n\n\ndef l(v: Any) -> list:\n    return v if isinstance(v, list) else []\n\n\ndef len_(v: Any) -> int:\n    return len(v) if isinstance(v, str) else len(l(v))\n\n\ndef spread(base: Any, fields: dict) -> dict:\n    out = dict(base) if isinstance(base, dict) else {}\n    out.update(fields)\n    return out\n\n\ndef str_(v: Any) -> Any:\n    return None if v is None else s(v)\n\n\ndef has(v: Any) -> bool:\n    return v is not None\n\n\ndef cnv(vs: list) -> str:\n    return merge([s(v) for v in vs if t(v)])\n\n\ndef tpl(tmpl: Any, vals: list) -> str:\n    return re.sub(r\"\\{(\\d+)\\}\", lambda m: s(vals[int(m.group(1))]) if int(m.group(1)) < len(vals) else \"\", s(tmpl))\n\n\ndef _group(f: float, decimals: int) -> str:\n    whole, _, frac = f\"{abs(f):.{decimals}f}\".partition(\".\")\n    out = f\"{int(whole):,}\"\n    frac = frac.rstrip(\"0\")\n    if frac:\n        out += \".\" + frac\n    if f < 0 and out != \"0\":\n        out = \"-\" + out\n    return out\n\n\ndef num(v: Any) -> str:\n    return _group(n(v), 3)\n\n\n_CURRENCY = {\"USD\": \"$\", \"EUR\": \"\\u20ac\", \"GBP\": \"\\u00a3\", \"JPY\": \"\\u00a5\", \"INR\": \"\\u20b9\", \"CAD\": \"CA$\", \"AUD\": \"A$\"}\n\n\ndef minor_digits(c: str) -> int:\n    return 0 if c in (\"JPY\", \"KRW\") else 2\n\n\ndef money(amount: Any, currency: Any) -> str:\n    \"\"\"integer minor units (Codex v0.4: 1250 = 12.50) -> \"$12.50\"; whole amounts without the fraction\"\"\"\n    c = s(currency)\n    sym = _CURRENCY.get(c, c + \"\\u00a0\")\n    minor = int(_round_half_away(n(amount)))\n    sign = \"-\" if minor < 0 else \"\"\n    minor = abs(minor)\n    d = minor_digits(c)\n    whole, rest = divmod(minor, 10 ** d)\n    out = sign + sym + _group(float(whole), 0)\n    if d and rest:\n        out += \".\" + str(rest).zfill(d)\n    return out\n\n\ndef at(d: Any, key: Any) -> str:\n    v = get(d, [s(key)])\n    return s(v) if v is not None else s(key)\n\n\ndef page_window(page_v: Any, pages_v: Any) -> list:\n    page, pages = int(n(page_v)), int(n(pages_v))\n    keep = {x for x in (1, pages, page - 1, page, page + 1) if 1 <= x <= pages}\n    out: list = []\n    prev = 0\n    for x in range(1, pages + 1):\n        if x not in keep:\n            continue\n        if x - prev > 1:\n            out.append(None)\n        out.append(x)\n        prev = x\n    return out\n\n\ndef fit_cols(cols_v: Any, n_v: Any) -> str:\n    cols, cnt = s(cols_v), int(n(n_v))\n    m = re.fullmatch(r\"(-?\\d+)-(-?\\d+)\", cols)\n    if not m:\n        return cols\n    lo, hi = int(m.group(1)), int(m.group(2))\n    if cnt >= hi:\n        return cols\n    known = {\"1-2\", \"1-3\", \"1-4\", \"2-3\", \"2-4\", \"2-6\", \"3-6\"}\n    for k in range(max(lo, cnt), lo, -1):\n        if f\"{lo}-{k}\" in known:\n            return f\"{lo}-{k}\"\n    return str(min(max(cnt, 1), lo))\n\n\ndef uniq(v: Any) -> str:\n    parts = s(v).split(\", \")\n    return \", \".join(p for idx, p in enumerate(parts) if idx == 0 or p.lower() != parts[idx - 1].lower())\n\n\ndef words(v: Any) -> list: return s(v).split(\" \")\ndef nbsp(v: Any) -> str: return s(v).replace(\" \", \"\\u00a0\")\n\n\ndef nth(lst: Any, idx: Any) -> Any:\n    xs, k = l(lst), int(n(idx))\n    return xs[k] if 0 <= k < len(xs) else None\n\n\ndef range_(c: Any) -> list: return list(range(max(0, int(n(c)))))\ndef max_(vs: list) -> float: return max([-math.inf] + [n(v) for v in vs])\ndef min_(vs: list) -> float: return min([math.inf] + [n(v) for v in vs])\ndef round_(v: Any) -> float: return float(math.floor(n(v) + 0.5))\n\n\ndef count(items: Any, f: Any) -> int:\n    return sum(1 for it in l(items) if t(get(it, [s(f)])))\n\n\ndef where(items: Any, f: Any, value: Any) -> list:\n    if not t(value):\n        return l(items)\n    return [it for it in l(items) if eq(get(it, [s(f)]), value)]\n\n\ndef match(items: Any, f: Any, query: Any) -> list:\n    if not t(query):\n        return l(items)\n    q = s(query).lower()\n    return [it for it in l(items) if q in s(get(it, [s(f)])).lower()]\n\n\ndef pick(items: Any, ident: Any) -> Any:\n    return next((it for it in l(items) if eq(get(it, [\"id\"]), ident)), None)\n\n\ndef sum_by(items: Any, a: str, b: str) -> float:\n    return sum((n(get(it, [a])) * n(get(it, [b])) for it in l(items)), 0.0)\n\n\ndef first_of(items: Any, f: str) -> Any:\n    xs = l(items)\n    if not xs:\n        return \"\"\n    v = get(xs[0], [f])\n    return \"\" if v is None else v\n\n\ndef max_by(items: Any, f: str) -> float:\n    return max([0.0] + [n(get(it, [f])) for it in l(items)])\n\n\ndef css(triples: list) -> str:\n    return \";\".join(s(triples[k]) + \":\" + css_value(triples[k + 1]) + s(triples[k + 2]) for k in range(0, len(triples) - 2, 3))\n\n\ndef _compound_hits(c: dict, pick_: Any) -> bool:\n    return all(pick_(k) in str(w).split(\"|\") for k, w in c.items() if k != \"class\")\n\n\ndef recipe(path: str, sel: dict) -> str:\n    \"\"\"the class string of a recipe table for a selection (organisms: base, each key, the matching compounds)\"\"\"\n    r = load_json(path)\n\n    def pick_(k: str) -> str:\n        v = s(sel.get(k)).strip()\n        return v or str((r.get(\"defaults\") or {}).get(k, \"\")).strip()\n\n    parts = [str(r.get(\"base\", \"\"))]\n    parts += [str((r.get(\"byKey\") or {}).get(k, {}).get(pick_(k), \"\")) for k in r.get(\"keys\", [])]\n    parts += [str(c.get(\"class\", \"\")) for c in r.get(\"compound\", []) or [] if _compound_hits(c, pick_)]\n    return merge([p.strip() for p in parts if p.strip()])\n\n\ndef preset(path: str, keys: list) -> Any:\n    return get(get(load_json(path), [\"values\"]), keys)\n\n\ndef attrs(kv: list) -> dict:\n    \"\"\"free DOM attributes from (name, value) pairs, as React prints them\"\"\"\n    out: dict = {}\n    for k in range(0, len(kv) - 1, 2):\n        name, v = s(kv[k]), kv[k + 1]\n        if v is None or not is_safe_attr_name(name):\n            continue\n        if not isinstance(v, bool):\n            v = attr_value(name, v)\n        if isinstance(v, bool):\n            if name.startswith(\"data-\") or name.startswith(\"aria-\"):\n                out[name] = s(v)\n            elif v:\n                out[name] = True\n            continue\n        out[name] = s(v)\n    return out\n\n\ndef attr_html(a: Any) -> str:\n    \"\"\"an attribute map as markup: ` name=\"value\"`, a bare name for True, nothing for None and False\"\"\"\n    if not isinstance(a, dict):\n        return \"\"\n    out = \"\"\n    for k, v in a.items():\n        if v is None or v is False or not is_safe_attr_name(str(k)):\n            continue\n        name = str(k)\n        out += f\" {name}\" if v is True else f' {name}=\"{html.escape(s(attr_value(name, v)), quote=True)}\"'\n    return out\n\n\n# ------------------------------------------------------------------ bricks (expr.go, utils.go, tags.go)\n\ndef is_set_str(v: Any) -> bool: return s(v).strip() != \"\"\n\n\ndef default_if_empty(v: Any, fallback: str) -> str:\n    x = s(v).strip()\n    return x or fallback\n\n\ndef map_or(v: Any, mapping: dict, fallback: str, lower: bool = False) -> str:\n    x = s(v).strip()\n    if lower:\n        x = x.lower()\n    return str(mapping[x]) if x in mapping else fallback\n\n\ndef int_map_or(v: Any, mapping: dict, fallback: str) -> str:\n    k = i(v)\n    return str(mapping[k]) if k in mapping else fallback\n\n\ndef bool_str(v: Any) -> str: return \"true\" if t(v) else \"false\"\ndef concat_trim(parts: list) -> str: return \"\".join(s(p).strip() for p in parts)\ndef cn(parts: list) -> str: return merge([s(p) for p in parts])\n\n\ndef compose(path: str, selection: dict, extra: list) -> str:\n    \"\"\"the brick class contract: recipe base, the selected variants (defaults for empty), compounds, then the tail\"\"\"\n    r = load_json(path)\n    defaults = r.get(\"defaults\") or {}\n\n    def pick_(k: str) -> str:\n        c = s(selection.get(k)).strip()\n        return c or str(defaults.get(k, \"\")).strip()\n\n    parts = [str(r[\"base\"]).strip()] if str(r.get(\"base\", \"\")).strip() else []\n    for key in r.get(\"keys\", []):\n        choices = (r.get(\"byKey\") or {}).get(key)\n        if choices is None:\n            continue\n        choice = pick_(key)\n        if not choice:\n            if choices:\n                raise ValueError(f\"[compose] missing default for key {key}\")\n            continue\n        if str(choices.get(choice, \"\")).strip():\n            parts.append(str(choices[choice]))\n    for c in r.get(\"compound\", []) or []:\n        if _compound_hits(c, pick_) and str(c.get(\"class\", \"\")).strip():\n            parts.append(str(c[\"class\"]))\n    return cn(parts + list(extra))\n\n\ndef resolve_tag(tag: Any, fallback: str, allowed: list) -> str:\n    x = s(tag).strip().lower()\n    return x if x and x in allowed else fallback\n\n\ndef title_tag(level: Any) -> str:\n    k = i(level)\n    return f\"h{k}\" if 1 <= k <= 6 else \"h2\"\n\n\ndef lucide(name: Any) -> str:\n    \"\"\"the inner markup of a Lucide glyph: its nodes with attributes in name order (circle for an unknown name)\"\"\"\n    icons = load_json(\"icons/lucide-icons.json\")[\"icons\"]\n    nodes = icons.get(s(name)) or icons[\"circle\"]\n    out = \"\"\n    for tag, a in nodes:\n        out += \"<\" + tag + \"\".join(f' {k}=\"{html.escape(str(a[k]), quote=True)}\"' for k in sorted(a)) + \"></\" + tag + \">\"\n    return out\n",
      "path": "compose_organisms/runtime.py",
      "target": "compose_organisms/runtime.py"
    },
    {
      "content": "Jinja2>=3.1,<4\nMarkupSafe>=2.1\n",
      "path": "requirements.txt",
      "target": "requirements.txt"
    },
    {
      "content": "# Code generated by @ui8kit/codegen. DO NOT EDIT.\n\"\"\"UI8Kit primitives for Jinja2.\n\n`environment()` returns a Jinja2 Environment over the generated folder with\nthe `ui_*` helpers and one `<name>_classes(p)` global per part (the\nserver-composition escape hatch: Jinja2 has no asChild).\n\nTemplates are `ui/<brick>/<part>.html.j2`, rendered with `p` (canonical\nPascalCase props, e.g. {\"Variant\": \"outline\", \"Class\": \"...\", \"Attrs\": {...}})\nand `children` (pre-rendered markup).\n\nSECURITY: `children` is printed with `|safe` — it is trusted HTML. Never pass\nunescaped user input as `children`; escape it first (markupsafe.escape) or\nrender it through another template. Props are always autoescaped.\n\"\"\"\n\nfrom __future__ import annotations\n\nimport functools\nimport os\nfrom typing import Any\n\nfrom jinja2 import ChainableUndefined, Environment, FileSystemLoader\nfrom jinja2.runtime import Undefined\nfrom markupsafe import Markup\n\nfrom . import runtime as rt\nfrom .classes import CLASS_EXPRESSIONS\n\nROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))\n\n\ndef _plain(v: Any) -> Any:\n    if isinstance(v, Undefined):\n        return None\n    if isinstance(v, list):\n        return [_plain(x) for x in v]\n    return v\n\n\ndef _wrap(f: Any, safe: bool = False) -> Any:\n    @functools.wraps(f)\n    def call(*args: Any) -> Any:\n        out = f(*[_plain(a) for a in args])\n        return Markup(out) if safe else out\n\n    return call\n\n\n_NAMES = {\"def\": \"def_\"}\n_PLAIN = [\n    \"def\", \"field\", \"s\", \"truthy\", \"eq\", \"is_set_str\", \"default_if_empty\", \"map_or\", \"int_map_or\",\n    \"bool_str\", \"opt_bool_str\", \"concat_trim\", \"cn\", \"compose\", \"resolve_tag\", \"safe_url\", \"has_attr\",\n]\nVOID_TAGS = frozenset(\n    [\"area\", \"base\", \"br\", \"col\", \"embed\", \"hr\", \"img\", \"input\", \"link\", \"meta\", \"param\", \"source\", \"track\", \"wbr\"]\n)\n\n\ndef environment(root: str | None = None, **options: Any) -> Environment:\n    \"\"\"An Environment over the generated jinja2 folder (autoescape on, chainable undefined).\"\"\"\n    root = root or ROOT\n    rt.set_root(root)\n    env = Environment(loader=FileSystemLoader(root), autoescape=True, undefined=ChainableUndefined, **options)\n    for name in _PLAIN:\n        env.globals[\"ui_\" + name] = _wrap(getattr(rt, _NAMES.get(name, name)))\n    env.globals[\"ui_attr_html\"] = _wrap(rt.attr_html, safe=True)\n    env.globals[\"ui_is_void\"] = lambda t: str(t) in VOID_TAGS\n    for name, source in CLASS_EXPRESSIONS.items():\n        env.globals[name] = _classes_fn(env, source)\n    return env\n\n\ndef _classes_fn(env: Environment, source: str) -> Any:\n    expr = env.compile_expression(source)\n\n    def classes(p: Any = None) -> str:\n        \"\"\"Composes the part's classes without rendering (recipe → static → extra → state → Class).\"\"\"\n        return str(expr(p=_plain(p) or {}) or \"\")\n\n    return classes\n",
      "path": "ui8kit_jinja/__init__.py",
      "target": "ui8kit_jinja/__init__.py"
    },
    {
      "content": "# Code generated by @ui8kit/codegen. DO NOT EDIT.\n\"\"\"Classes contract of every part as a Jinja expression over `p`.\n\n`environment()` registers each entry as a global `<name>_classes(p)` — the\nserver-composition escape hatch for custom root elements (no asChild in\nJinja2): `<a class=\"{{ button_classes({'Variant': 'outline'}) }}\" href=\"/x\">`.\n\"\"\"\n\nCLASS_EXPRESSIONS = {\n    \"box_classes\": \"ui_cn([ui_def(p['Class'], '')])\",\n    \"text_classes\": \"ui_cn([ui_def(p['Class'], '')])\",\n    \"button_classes\": \"ui_cn([ui_def(p['Class'], '')])\",\n    \"link_classes\": \"ui_cn([ui_def(p['Class'], '')])\",\n    \"label_classes\": \"ui_cn([ui_def(p['Class'], '')])\",\n    \"form_classes\": \"ui_cn([ui_def(p['Class'], '')])\",\n    \"input_classes\": \"ui_cn([ui_def(p['Class'], '')])\",\n    \"textarea_classes\": \"ui_cn([ui_def(p['Class'], '')])\",\n    \"select_classes\": \"ui_cn(['pr-2', ui_def(p['Class'], '')])\",\n    \"checkbox_classes\": \"ui_cn([ui_def(p['Class'], '')])\",\n    \"radio_classes\": \"ui_cn([ui_def(p['Class'], '')])\",\n    \"switch_classes\": \"ui_cn([ui_def(p['Class'], '')])\",\n    \"image_classes\": \"ui_cn([ui_def(p['Class'], '')])\",\n    \"picture_classes\": \"ui_cn([ui_def(p['Class'], '')])\",\n    \"icon_classes\": \"ui_compose('ui/icon/icon.variants.json', {'size': ui_def(p['Size'], '')}, [ui_def(p['Class'], '')])\",\n    \"dialog_classes\": \"ui_cn([ui_def(p['Class'], '')])\",\n    \"disclosure_classes\": \"ui_cn([ui_def(p['Class'], '')])\",\n    \"summary_classes\": \"ui_cn([ui_def(p['Class'], '')])\",\n    \"meter_classes\": \"ui_cn([ui_def(p['Class'], '')])\",\n    \"progress_classes\": \"ui_cn([ui_def(p['Class'], '')])\",\n    \"separator_classes\": \"ui_cn([ui_def(p['Class'], '')])\",\n}\n",
      "path": "ui8kit_jinja/classes.py",
      "target": "ui8kit_jinja/classes.py"
    },
    {
      "content": "# Code generated by @ui8kit/codegen. DO NOT EDIT.\n\"\"\"cn: class fragments joined with tailwind-merge conflict resolution (the last class of a group wins, and a class removes\nthe earlier classes of the groups it overrides: p-2 removes px-4, not the reverse). Port of cn_merge.go.\"\"\"\n\nfrom __future__ import annotations\n\n_DISPLAY = {\"block\", \"inline\", \"inline-block\", \"inline-flex\", \"flex\", \"grid\", \"contents\", \"hidden\"}\n_PREFIXES = [\n    (\"gap-x-\", \"gap-x\"), (\"gap-y-\", \"gap-y\"), (\"items-\", \"align-items\"), (\"justify-\", \"justify-content\"),\n    (\"self-\", \"align-self\"), (\"content-\", \"align-content\"), (\"overflow-x-\", \"overflow-x\"), (\"overflow-y-\", \"overflow-y\"),\n    (\"inset-x-\", \"inset-x\"), (\"inset-y-\", \"inset-y\"), (\"min-w-\", \"min-width\"), (\"min-h-\", \"min-height\"),\n    (\"max-w-\", \"max-width\"), (\"max-h-\", \"max-height\"), (\"shadow-\", \"shadow\"), (\"ring-\", \"ring\"), (\"rounded-\", \"rounded\"),\n    (\"leading-\", \"leading\"), (\"tracking-\", \"tracking\"), (\"opacity-\", \"opacity\"), (\"z-\", \"z\"), (\"top-\", \"top\"),\n    (\"right-\", \"right\"), (\"bottom-\", \"bottom\"), (\"left-\", \"left\"),\n]\n_TEXT_SIZES = {\"text-xs\", \"text-sm\", \"text-base\", \"text-lg\", \"text-xl\"} | {f\"text-{n}xl\" for n in range(2, 10)}\n_WEIGHTS = {f\"font-{w}\" for w in (\"thin\", \"extralight\", \"light\", \"normal\", \"medium\", \"semibold\", \"bold\", \"extrabold\", \"black\")}\n\n\ndef _is_number(s: str) -> bool:\n    if s.startswith(\"[\"):\n        return True\n    return s != \"\" and all(c in \"0123456789.\" for c in s)\n\n\ndef _split_variant(token: str) -> tuple[str, str]:\n    depth, cut = 0, -1\n    for i, c in enumerate(token):\n        if c == \"[\":\n            depth += 1\n        elif c == \"]\":\n            depth = max(0, depth - 1)\n        elif c == \":\" and depth == 0:\n            cut = i\n    core = token if cut == -1 else token[cut + 1:]\n    core = core[1:] if core.startswith(\"!\") else core\n    return (\"\" if cut == -1 else token[:cut + 1]), core\n\n\ndef _has_direction(core: str, kind: str) -> bool:\n    return any(core.startswith(kind + d) for d in (\"x-\", \"y-\", \"t-\", \"r-\", \"b-\", \"l-\", \"s-\", \"e-\"))\n\n\ndef _space_axis(core: str, kind: str, n: str) -> list[str]:\n    if core.startswith(kind + \"x-\"):\n        return [f\"{n}-x\", f\"{n}-r\", f\"{n}-l\", f\"{n}-s\", f\"{n}-e\"]\n    if core.startswith(kind + \"y-\"):\n        return [f\"{n}-y\", f\"{n}-t\", f\"{n}-b\"]\n    for s in \"trbl\":\n        if core.startswith(kind + s + \"-\"):\n            return [f\"{n}-{s}\"]\n    return []\n\n\ndef _groups(core: str) -> list[str]:\n    if core in _DISPLAY:\n        return [\"display\"]\n    if core in (\"flex-row\", \"flex-col\", \"flex-row-reverse\", \"flex-col-reverse\"):\n        return [\"flex-direction\"]\n    if core in (\"static\", \"relative\", \"absolute\", \"fixed\", \"sticky\"):\n        return [\"position\"]\n    if core in (\"isolate\", \"isolation-auto\"):\n        return [\"isolation\"]\n    if core in (\"object-contain\", \"object-cover\", \"object-fill\", \"object-none\", \"object-scale-down\"):\n        return [\"object-fit\"]\n    if core in (\"object-bottom\", \"object-center\", \"object-left\", \"object-left-bottom\", \"object-left-top\", \"object-right\", \"object-right-bottom\", \"object-right-top\", \"object-top\"):\n        return [\"object-position\"]\n    if core.startswith(\"aspect-\"):\n        return [\"aspect\"]\n    # ring-offset-N (width) and ring-offset-<color> are their own groups\n    if core.startswith(\"ring-offset-\"):\n        return [\"ring-offset-width\" if _is_number(core[12:]) else \"ring-offset-color\"]\n    for kind in (\"inset-ring\", \"ring\"):\n        if core == kind:\n            return [kind + \"-width\"]\n        if core.startswith(kind + \"-\"):\n            return [kind + (\"-width\" if _is_number(core[len(kind) + 1:]) else \"-color\")]\n    for p, g in _PREFIXES:\n        if core.startswith(p):\n            return [g]\n    if core.startswith(\"gap-\"):\n        return [\"gap\", \"gap-x\", \"gap-y\"]\n    if core.startswith(\"inset-\"):\n        return [\"inset\", \"inset-x\", \"inset-y\", \"top\", \"right\", \"bottom\", \"left\"]\n    if core.startswith(\"overflow-\"):\n        return [\"overflow\", \"overflow-x\", \"overflow-y\"]\n    if core == \"border\" or (core.startswith(\"border-\") and _is_number(core[7:])):\n        return [\"border-width\"] + [f\"border-w-{s}\" for s in \"xytrblse\"]\n    if len(core) >= 8 and core.startswith(\"border-\") and core[7] in \"xytrblse\" and (len(core) == 8 or (core[8] == \"-\" and _is_number(core[9:]))):\n        side = core[7]\n        if side == \"x\":\n            return [\"border-w-x\", \"border-w-r\", \"border-w-l\", \"border-w-s\", \"border-w-e\"]\n        if side == \"y\":\n            return [\"border-w-y\", \"border-w-t\", \"border-w-b\"]\n        return [\"border-w-\" + side]\n    if core in (\"text-left\", \"text-center\", \"text-right\", \"text-justify\", \"text-start\", \"text-end\"):\n        return [\"text-align\"]\n    if core == \"rounded\":\n        return [\"rounded\"]\n    if core in (\"shadow\", \"shadow-none\"):\n        return [\"shadow\"]\n    if core in (\"flex-1\", \"flex-auto\", \"flex-none\", \"flex-initial\"):\n        return [\"flex-size\", \"flex-grow\", \"flex-shrink\", \"flex-basis\"]\n    if core == \"grow\" or core.startswith(\"grow-\"):\n        return [\"flex-grow\"]\n    if core in (\"shrink\", \"shrink-0\"):\n        return [\"flex-shrink\"]\n    if core.startswith(\"size-\"):\n        return [\"size\", \"width\", \"height\"]\n    if core.startswith(\"w-\"):\n        return [\"width\"]\n    if core.startswith(\"h-\"):\n        return [\"height\"]\n    for kind, n in ((\"p\", \"padding\"), (\"m\", \"margin\")):\n        if core.startswith(kind + \"-\") and not _has_direction(core, kind):\n            return [n] + [f\"{n}-{s}\" for s in \"xytrblse\"]\n        axis = _space_axis(core, kind, n)\n        if axis:\n            return axis\n    if core.startswith(\"bg-\"):\n        return [\"bg\"]\n    if core in _TEXT_SIZES or (core.startswith(\"text-[\") and len(core) > 6 and (core[6].isdigit() or core[6] == \".\")):\n        return [\"text-size\", \"leading\"]\n    if core.startswith(\"text-\"):\n        return [\"text-color\"]\n    if core in _WEIGHTS:\n        return [\"font-weight\"]\n    return []\n\n\ndef merge(classes: list[str]) -> str:\n    kept: list[tuple[str, str]] = []\n    for chunk in classes:\n        for token in str(chunk).split():\n            prefix, core = _split_variant(token)\n            key = \"\"\n            removes: list[str] = []\n            if core:\n                g = _groups(core)\n                if g:\n                    key, removes = prefix + g[0], g[1:]\n                else:\n                    key = \"=\" + token\n            if key:\n                drop = {key} | {prefix + r for r in removes}\n                kept = [it for it in kept if it[1] not in drop]\n            kept.append((token, key))\n    return \" \".join(t for t, _ in kept)\n",
      "path": "ui8kit_jinja/cn_merge.py",
      "target": "ui8kit_jinja/cn_merge.py"
    },
    {
      "content": "# Code generated by @ui8kit/codegen. DO NOT EDIT.\n\"\"\"Helpers of the generated Jinja2 templates (registered as `ui_*` globals).\n\nPorted from the xgen Jinja2 runtime (tag xgen-archive-2026-10-23,\nxgen/runtimes/jinja2/assets/py/ui8kit_jinja/runtime.py), trimmed to the brick\nhelpers the 17 primitives use. Semantics mirror the canonical renderer\n(src/domain/render.ts) and runtime/go: trimmed strings, decision tables,\nrecipe composition, tailwind-merge-style class merging. Every helper is\nNone-safe.\n\"\"\"\n\nfrom __future__ import annotations\n\nimport html\nimport re\nimport json\nimport math\nimport os\nfrom typing import Any\n\nfrom .cn_merge import merge\n\n_ROOT = \"\"\n_JSON: dict[str, Any] = {}\n\n\ndef set_root(root: str) -> None:\n    global _ROOT\n    _ROOT = root\n\n\ndef load_json(path: str) -> Any:\n    if path not in _JSON:\n        with open(os.path.join(_ROOT, path), encoding=\"utf-8\") as f:\n            _JSON[path] = json.load(f)\n    return _JSON[path]\n\n\ndef _num(v: Any) -> bool:\n    return isinstance(v, (int, float)) and not isinstance(v, bool)\n\n\ndef def_(v: Any, d: Any) -> Any:\n    \"\"\"a prop with its default: the default when the prop is None or missing\"\"\"\n    return d if v is None else v\n\n\ndef field(item: Any, name: str, zero: Any) -> Any:\n    \"\"\"a field of a record item; the key is matched without regard to case (as Go json does)\"\"\"\n    if not isinstance(item, dict):\n        return zero\n    if name in item:\n        return zero if item[name] is None else item[name]\n    for k, v in item.items():\n        if str(k).lower() == name.lower():\n            return zero if v is None else v\n    return zero\n\n\ndef fmt_num(f: Any) -> str:\n    \"\"\"String(n) of JavaScript\"\"\"\n    if isinstance(f, int):\n        return str(f)\n    if math.isnan(f):\n        return \"NaN\"\n    if math.isinf(f):\n        return \"Infinity\" if f > 0 else \"-Infinity\"\n    if f == math.floor(f) and abs(f) < 1e21:\n        return \"%d\" % int(f)\n    return repr(f)\n\n\ndef s(v: Any) -> str:\n    if v is None:\n        return \"\"\n    if isinstance(v, str):\n        return v\n    if isinstance(v, bool):\n        return \"true\" if v else \"false\"\n    if _num(v):\n        return fmt_num(v)\n    return json.dumps(v, separators=(\",\", \":\"), ensure_ascii=False)\n\n\ndef truthy(v: Any) -> bool:\n    \"\"\"canonical truthiness (render.ts): string non-blank, number > 0, bool itself\"\"\"\n    if v is None:\n        return False\n    if isinstance(v, bool):\n        return v\n    if isinstance(v, str):\n        return v.strip() != \"\"\n    if _num(v):\n        return v > 0\n    return bool(v)\n\n\ndef eq(a: Any, b: Any) -> bool:\n    \"\"\"strict equality (===)\"\"\"\n    if _num(a) or _num(b):\n        return _num(a) and _num(b) and float(a) == float(b)\n    if a is None:\n        return b is None\n    if isinstance(a, bool) or isinstance(b, bool):\n        return isinstance(a, bool) and isinstance(b, bool) and a == b\n    if isinstance(a, str):\n        return isinstance(b, str) and a == b\n    return False\n\n\nURL_ATTRS = frozenset([\"href\", \"src\", \"action\", \"formaction\", \"poster\", \"cite\", \"background\", \"xlink:href\"])\n\n\n_DATA_IMAGE = re.compile(r\"^data:image/(png|jpeg|gif|webp|avif|svg\\+xml)[;,]\")\n\n\ndef safe_url(v: Any, data_image: bool = False) -> str:\n    \"\"\"URL attribute value: \"\" for javascript:, vbscript: and data: (ASCII whitespace/control chars removed, case-insensitive);\n    data_image (only <img src>) allows data:image/(png|jpeg|gif|webp|avif|svg+xml).\"\"\"\n    t = s(v)\n    k = \"\".join(c for c in t if ord(c) > 0x20).lower()\n    if data_image and _DATA_IMAGE.match(k):\n        return t\n    return \"\" if k.startswith((\"javascript:\", \"vbscript:\", \"data:\")) else t\n\n\ndef has_attr(a: Any, name: str) -> bool:\n    \"\"\"the caller's Attrs set name (case-insensitive): Attrs win over the named attribute\"\"\"\n    return isinstance(a, dict) and any(str(k).lower() == name for k in a)\n\n\ndef attr_html(a: Any, img: bool = False, blank: Any = ()) -> str:\n    \"\"\"the Attrs escape hatch as markup: ` name=\"value\"`, a bare name for True, nothing for None and False;\n    an unsafe URL (data:image allowed in <img src> when img) or a blank optional attribute (blank) is omitted\"\"\"\n    if not isinstance(a, dict):\n        return \"\"\n    blank = list(blank or ())\n    out = \"\"\n    for k, v in a.items():\n        if v is None or v is False:\n            continue\n        key = str(k).lower()\n        if isinstance(v, str) and v.strip() == \"\" and key in blank:\n            continue\n        if isinstance(v, str) and v != \"\" and key in URL_ATTRS and safe_url(v, img and key == \"src\") == \"\":\n            continue\n        name = html.escape(str(k), quote=True)\n        out += f\" {name}\" if v is True else f' {name}=\"{html.escape(s(v), quote=True)}\"'\n    return out\n\n\ndef is_set_str(v: Any) -> bool:\n    return s(v).strip() != \"\"\n\n\ndef default_if_empty(v: Any, fallback: str) -> str:\n    x = s(v).strip()\n    return x or fallback\n\n\ndef map_or(v: Any, mapping: dict, fallback: str, lower: bool = False) -> str:\n    x = s(v).strip()\n    if lower:\n        x = x.lower()\n    return str(mapping[x]) if x in mapping else fallback\n\n\ndef int_map_or(v: Any, mapping: dict, fallback: str) -> str:\n    try:\n        k = int(v)\n    except (TypeError, ValueError):\n        k = 0\n    return str(mapping[k]) if k in mapping else fallback\n\n\ndef bool_str(v: Any) -> str:\n    return \"true\" if truthy(v) else \"false\"\n\n\ndef opt_bool_str(v: Any) -> str:\n    \"\"\"Tri-state ARIA state: \"true\"/\"false\" when set, \"\" when None (attribute omitted).\"\"\"\n    return \"\" if v is None else (\"true\" if truthy(v) else \"false\")\n\n\ndef concat_trim(parts: list) -> str:\n    return \"\".join(s(p).strip() for p in parts)\n\n\ndef cn(parts: list) -> str:\n    return merge([s(p) for p in parts])\n\n\ndef _compound_hits(c: dict, pick_: Any) -> bool:\n    return all(pick_(k) in str(w).split(\"|\") for k, w in c.items() if k != \"class\")\n\n\ndef compose(path: str, selection: dict, extra: list) -> str:\n    \"\"\"the brick class contract: recipe base, the selected variants (defaults for empty), compounds, then the tail\"\"\"\n    r = load_json(path)\n    defaults = r.get(\"defaults\") or {}\n\n    def pick_(k: str) -> str:\n        c = s(selection.get(k)).strip()\n        return c or str(defaults.get(k, \"\")).strip()\n\n    parts = [str(r[\"base\"]).strip()] if str(r.get(\"base\", \"\")).strip() else []\n    for key in r.get(\"keys\", []):\n        choices = (r.get(\"byKey\") or {}).get(key)\n        if choices is None:\n            continue\n        choice = pick_(key)\n        if not choice:\n            if choices:\n                raise ValueError(f\"[compose] missing default for key {key}\")\n            continue\n        if str(choices.get(choice, \"\")).strip():\n            parts.append(str(choices[choice]))\n    for c in r.get(\"compound\", []) or []:\n        if _compound_hits(c, pick_) and str(c.get(\"class\", \"\")).strip():\n            parts.append(str(c[\"class\"]))\n    return cn(parts + list(extra))\n\n\ndef resolve_tag(tag: Any, fallback: str, allowed: list) -> str:\n    x = s(tag).strip().lower()\n    return x if x and x in allowed else fallback\n",
      "path": "ui8kit_jinja/runtime.py",
      "target": "ui8kit_jinja/runtime.py"
    }
  ],
  "meta": {
    "category": "utils",
    "kind": "utils",
    "tags": [
      "jinja2",
      "utils"
    ]
  },
  "name": "utils",
  "registryDependencies": [],
  "runtime": "jinja2",
  "title": "Utils",
  "type": "registry:utils"
}
