@constela/runtime 2.0.8 → 2.0.10

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
@@ -509,6 +509,7 @@ interface RenderContext {
509
509
  query: Record<string, string>;
510
510
  path: string;
511
511
  };
512
+ styles?: Record<string, StylePreset>;
512
513
  }
513
514
  declare function render(node: CompiledNode, ctx: RenderContext): Node;
514
515
 
package/dist/index.js CHANGED
@@ -974,6 +974,7 @@ var GLOBAL_FUNCTIONS = {
974
974
  getRadarAxes: (labels, cx, cy, radius) => getRadarAxes(labels, cx, cy, radius),
975
975
  // Chart helpers - Utilities
976
976
  getChartBounds: (data, valueKey) => getChartBounds(data, valueKey),
977
+ scaleChartY: (value, boundsMin, boundsMax, height, paddingTop, paddingBottom) => scaleChartY(value, boundsMin, boundsMax, height, paddingTop, paddingBottom),
977
978
  generateTicks: (min, max, count) => generateTicks(min, max, count),
978
979
  // Chart helpers - Data aggregation
979
980
  binData: (data, valueKey, binCount) => binData(data, valueKey, binCount),
@@ -1330,6 +1331,20 @@ function scaleValue(value, domainMin, domainMax, rangeMin, rangeMax) {
1330
1331
  const normalized = (value - domainMin) / (domainMax - domainMin);
1331
1332
  return rangeMin + normalized * (rangeMax - rangeMin);
1332
1333
  }
1334
+ function scaleChartY(value, boundsMin, boundsMax, height, paddingTop, paddingBottom) {
1335
+ if (typeof value !== "number" || typeof boundsMin !== "number" || typeof boundsMax !== "number" || typeof height !== "number" || typeof paddingTop !== "number" || typeof paddingBottom !== "number") {
1336
+ return void 0;
1337
+ }
1338
+ const drawableHeight = height - paddingTop - paddingBottom;
1339
+ if (drawableHeight <= 0) {
1340
+ return paddingTop;
1341
+ }
1342
+ if (boundsMax === boundsMin) {
1343
+ return paddingTop + drawableHeight / 2;
1344
+ }
1345
+ const normalized = (value - boundsMin) / (boundsMax - boundsMin);
1346
+ return paddingTop + drawableHeight * (1 - normalized);
1347
+ }
1333
1348
  function getBarDimensions(data, index, width, height, gap, orientation) {
1334
1349
  if (!Array.isArray(data) || data.length === 0) {
1335
1350
  return void 0;
@@ -15171,7 +15186,7 @@ function renderElement(node, ctx) {
15171
15186
  }
15172
15187
  } else {
15173
15188
  const cleanup = createEffect(() => {
15174
- const value = evaluate(propValue, { state: ctx.state, locals: ctx.locals, ...ctx.refs && { refs: ctx.refs }, ...ctx.imports && { imports: ctx.imports }, ...ctx.route && { route: ctx.route } });
15189
+ const value = evaluate(propValue, { state: ctx.state, locals: ctx.locals, ...ctx.refs && { refs: ctx.refs }, ...ctx.imports && { imports: ctx.imports }, ...ctx.route && { route: ctx.route }, ...ctx.styles && { styles: ctx.styles } });
15175
15190
  applyProp(el, propName, value, useSvgNamespace);
15176
15191
  });
15177
15192
  ctx.cleanups?.push(cleanup);
@@ -15226,7 +15241,7 @@ function applyProp(el, propName, value, isSvg = false) {
15226
15241
  function renderText(node, ctx) {
15227
15242
  const textNode = document.createTextNode("");
15228
15243
  const cleanup = createEffect(() => {
15229
- const value = evaluate(node.value, { state: ctx.state, locals: ctx.locals, ...ctx.refs && { refs: ctx.refs }, ...ctx.imports && { imports: ctx.imports }, ...ctx.route && { route: ctx.route } });
15244
+ const value = evaluate(node.value, { state: ctx.state, locals: ctx.locals, ...ctx.refs && { refs: ctx.refs }, ...ctx.imports && { imports: ctx.imports }, ...ctx.route && { route: ctx.route }, ...ctx.styles && { styles: ctx.styles } });
15230
15245
  textNode.textContent = formatValue(value);
15231
15246
  });
15232
15247
  ctx.cleanups?.push(cleanup);
@@ -15247,7 +15262,7 @@ function renderIf(node, ctx) {
15247
15262
  let currentBranch = "none";
15248
15263
  let branchCleanups = [];
15249
15264
  const effectCleanup = createEffect(() => {
15250
- const condition = evaluate(node.condition, { state: ctx.state, locals: ctx.locals, ...ctx.refs && { refs: ctx.refs }, ...ctx.imports && { imports: ctx.imports }, ...ctx.route && { route: ctx.route } });
15265
+ const condition = evaluate(node.condition, { state: ctx.state, locals: ctx.locals, ...ctx.refs && { refs: ctx.refs }, ...ctx.imports && { imports: ctx.imports }, ...ctx.route && { route: ctx.route }, ...ctx.styles && { styles: ctx.styles } });
15251
15266
  const shouldShowThen = Boolean(condition);
15252
15267
  const newBranch = shouldShowThen ? "then" : node.else ? "else" : "none";
15253
15268
  if (newBranch !== currentBranch) {
@@ -15325,7 +15340,7 @@ function renderEach(node, ctx) {
15325
15340
  let currentNodes = [];
15326
15341
  let itemCleanups = [];
15327
15342
  const effectCleanup = createEffect(() => {
15328
- const items = evaluate(node.items, { state: ctx.state, locals: ctx.locals, ...ctx.refs && { refs: ctx.refs }, ...ctx.imports && { imports: ctx.imports }, ...ctx.route && { route: ctx.route } });
15343
+ const items = evaluate(node.items, { state: ctx.state, locals: ctx.locals, ...ctx.refs && { refs: ctx.refs }, ...ctx.imports && { imports: ctx.imports }, ...ctx.route && { route: ctx.route }, ...ctx.styles && { styles: ctx.styles } });
15329
15344
  if (!hasKey || !node.key) {
15330
15345
  for (const cleanup of itemCleanups) {
15331
15346
  cleanup();
@@ -15384,7 +15399,8 @@ function renderEach(node, ctx) {
15384
15399
  locals: tempLocals,
15385
15400
  ...ctx.refs && { refs: ctx.refs },
15386
15401
  ...ctx.imports && { imports: ctx.imports },
15387
- ...ctx.route && { route: ctx.route }
15402
+ ...ctx.route && { route: ctx.route },
15403
+ ...ctx.styles && { styles: ctx.styles }
15388
15404
  });
15389
15405
  if (seenKeys.has(keyValue)) {
15390
15406
  if (typeof process !== "undefined" && process.env?.["NODE_ENV"] !== "production") {
@@ -15476,7 +15492,7 @@ function renderMarkdown(node, ctx) {
15476
15492
  const container = document.createElement("div");
15477
15493
  container.className = "constela-markdown";
15478
15494
  const cleanup = createEffect(() => {
15479
- const content = evaluate(node.content, { state: ctx.state, locals: ctx.locals, ...ctx.refs && { refs: ctx.refs }, ...ctx.imports && { imports: ctx.imports }, ...ctx.route && { route: ctx.route } });
15495
+ const content = evaluate(node.content, { state: ctx.state, locals: ctx.locals, ...ctx.refs && { refs: ctx.refs }, ...ctx.imports && { imports: ctx.imports }, ...ctx.route && { route: ctx.route }, ...ctx.styles && { styles: ctx.styles } });
15480
15496
  const html6 = parseMarkdown(String(content ?? ""));
15481
15497
  container.innerHTML = html6;
15482
15498
  });
@@ -15491,8 +15507,8 @@ function renderCode(node, ctx) {
15491
15507
  container.appendChild(pre);
15492
15508
  pre.appendChild(codeEl);
15493
15509
  const cleanup = createEffect(() => {
15494
- const language = String(evaluate(node.language, { state: ctx.state, locals: ctx.locals, ...ctx.refs && { refs: ctx.refs }, ...ctx.imports && { imports: ctx.imports }, ...ctx.route && { route: ctx.route } }) ?? "plaintext");
15495
- const content = String(evaluate(node.content, { state: ctx.state, locals: ctx.locals, ...ctx.refs && { refs: ctx.refs }, ...ctx.imports && { imports: ctx.imports }, ...ctx.route && { route: ctx.route } }) ?? "");
15510
+ const language = String(evaluate(node.language, { state: ctx.state, locals: ctx.locals, ...ctx.refs && { refs: ctx.refs }, ...ctx.imports && { imports: ctx.imports }, ...ctx.route && { route: ctx.route }, ...ctx.styles && { styles: ctx.styles } }) ?? "plaintext");
15511
+ const content = String(evaluate(node.content, { state: ctx.state, locals: ctx.locals, ...ctx.refs && { refs: ctx.refs }, ...ctx.imports && { imports: ctx.imports }, ...ctx.route && { route: ctx.route }, ...ctx.styles && { styles: ctx.styles } }) ?? "");
15496
15512
  codeEl.className = `language-${language || "plaintext"}`;
15497
15513
  codeEl.dataset["language"] = language || "plaintext";
15498
15514
  container.dataset["language"] = language || "plaintext";
@@ -15557,6 +15573,7 @@ function createLocalStateStore(stateDefs, ctx) {
15557
15573
  };
15558
15574
  if (ctx.route) evalCtx.route = ctx.route;
15559
15575
  if (ctx.imports) evalCtx.imports = ctx.imports;
15576
+ if (ctx.styles) evalCtx.styles = ctx.styles;
15560
15577
  initialValue = evaluate(initial, evalCtx);
15561
15578
  } else {
15562
15579
  initialValue = initial;
@@ -15678,7 +15695,9 @@ function createApp(program, mount) {
15678
15695
  actions,
15679
15696
  locals: {},
15680
15697
  cleanups,
15681
- refs
15698
+ refs,
15699
+ ...program.importData && { imports: program.importData },
15700
+ ...program.styles && { styles: program.styles }
15682
15701
  };
15683
15702
  const rootNode = render(program.view, ctx);
15684
15703
  mount.appendChild(rootNode);
@@ -15902,6 +15921,7 @@ function createLocalStateStore2(stateDefs, ctx) {
15902
15921
  };
15903
15922
  if (ctx.route) evalCtx.route = ctx.route;
15904
15923
  if (ctx.imports) evalCtx.imports = ctx.imports;
15924
+ if (ctx.styles) evalCtx.styles = ctx.styles;
15905
15925
  initialValue = evaluate(initial, evalCtx);
15906
15926
  } else {
15907
15927
  initialValue = initial;
@@ -16007,7 +16027,8 @@ function hydrateApp(options) {
16007
16027
  cleanups,
16008
16028
  refs,
16009
16029
  ...program.importData && { imports: program.importData },
16010
- ...route && { route }
16030
+ ...route && { route },
16031
+ ...program.styles && { styles: program.styles }
16011
16032
  };
16012
16033
  const firstChild = container.firstElementChild;
16013
16034
  if (firstChild) {
@@ -16155,7 +16176,8 @@ function hydrateElement(node, el, ctx) {
16155
16176
  state: ctx.state,
16156
16177
  locals: ctx.locals,
16157
16178
  ...ctx.imports && { imports: ctx.imports },
16158
- ...ctx.route && { route: ctx.route }
16179
+ ...ctx.route && { route: ctx.route },
16180
+ ...ctx.styles && { styles: ctx.styles }
16159
16181
  });
16160
16182
  applyProp2(el, propName, value);
16161
16183
  });
@@ -16225,7 +16247,8 @@ function hydrateChildren(children, parent, ctx) {
16225
16247
  state: ctx.state,
16226
16248
  locals: ctx.locals,
16227
16249
  ...ctx.imports && { imports: ctx.imports },
16228
- ...ctx.route && { route: ctx.route }
16250
+ ...ctx.route && { route: ctx.route },
16251
+ ...ctx.styles && { styles: ctx.styles }
16229
16252
  });
16230
16253
  const clientBranch = Boolean(clientCondition) ? "then" : ifNode.else ? "else" : "none";
16231
16254
  const ssrInfo = ifMarkerIndex < ifMarkers.length ? ifMarkers[ifMarkerIndex] : null;
@@ -16258,7 +16281,8 @@ function hydrateChildren(children, parent, ctx) {
16258
16281
  state: ctx.state,
16259
16282
  locals: ctx.locals,
16260
16283
  ...ctx.imports && { imports: ctx.imports },
16261
- ...ctx.route && { route: ctx.route }
16284
+ ...ctx.route && { route: ctx.route },
16285
+ ...ctx.styles && { styles: ctx.styles }
16262
16286
  });
16263
16287
  const itemCount = Array.isArray(items) ? items.length : 0;
16264
16288
  if (itemCount > 0) {
@@ -16287,7 +16311,8 @@ function hydrateTextGroup(nodes, textNode, ctx) {
16287
16311
  state: ctx.state,
16288
16312
  locals: ctx.locals,
16289
16313
  ...ctx.imports && { imports: ctx.imports },
16290
- ...ctx.route && { route: ctx.route }
16314
+ ...ctx.route && { route: ctx.route },
16315
+ ...ctx.styles && { styles: ctx.styles }
16291
16316
  });
16292
16317
  combinedText += formatValue2(value);
16293
16318
  }
@@ -16328,7 +16353,8 @@ function hydrateText(node, textNode, ctx) {
16328
16353
  state: ctx.state,
16329
16354
  locals: ctx.locals,
16330
16355
  ...ctx.imports && { imports: ctx.imports },
16331
- ...ctx.route && { route: ctx.route }
16356
+ ...ctx.route && { route: ctx.route },
16357
+ ...ctx.styles && { styles: ctx.styles }
16332
16358
  });
16333
16359
  textNode.textContent = formatValue2(value);
16334
16360
  });
@@ -16358,7 +16384,8 @@ function hydrateIf(node, initialDomNode, ctx, branchInfo) {
16358
16384
  state: ctx.state,
16359
16385
  locals: ctx.locals,
16360
16386
  ...ctx.imports && { imports: ctx.imports },
16361
- ...ctx.route && { route: ctx.route }
16387
+ ...ctx.route && { route: ctx.route },
16388
+ ...ctx.styles && { styles: ctx.styles }
16362
16389
  });
16363
16390
  currentBranch = Boolean(initialCondition) ? "then" : node.else ? "else" : "none";
16364
16391
  }
@@ -16380,7 +16407,8 @@ function hydrateIf(node, initialDomNode, ctx, branchInfo) {
16380
16407
  state: ctx.state,
16381
16408
  locals: ctx.locals,
16382
16409
  ...ctx.imports && { imports: ctx.imports },
16383
- ...ctx.route && { route: ctx.route }
16410
+ ...ctx.route && { route: ctx.route },
16411
+ ...ctx.styles && { styles: ctx.styles }
16384
16412
  });
16385
16413
  const shouldShowThen = Boolean(condition);
16386
16414
  const newBranch = shouldShowThen ? "then" : node.else ? "else" : "none";
@@ -16405,7 +16433,8 @@ function hydrateIf(node, initialDomNode, ctx, branchInfo) {
16405
16433
  actions: ctx.actions,
16406
16434
  locals: ctx.locals,
16407
16435
  cleanups: localCleanups,
16408
- ...ctx.imports && { imports: ctx.imports }
16436
+ ...ctx.imports && { imports: ctx.imports },
16437
+ ...ctx.styles && { styles: ctx.styles }
16409
16438
  };
16410
16439
  if (newBranch === "then") {
16411
16440
  currentNode = render(node.then, branchCtx);
@@ -16446,7 +16475,8 @@ function hydrateIfWithoutDom(node, parent, nextSibling, ctx, branchInfo) {
16446
16475
  state: ctx.state,
16447
16476
  locals: ctx.locals,
16448
16477
  ...ctx.imports && { imports: ctx.imports },
16449
- ...ctx.route && { route: ctx.route }
16478
+ ...ctx.route && { route: ctx.route },
16479
+ ...ctx.styles && { styles: ctx.styles }
16450
16480
  });
16451
16481
  const shouldShowThen = Boolean(condition);
16452
16482
  const newBranch = shouldShowThen ? "then" : node.else ? "else" : "none";
@@ -16472,7 +16502,8 @@ function hydrateIfWithoutDom(node, parent, nextSibling, ctx, branchInfo) {
16472
16502
  locals: ctx.locals,
16473
16503
  cleanups: localCleanups,
16474
16504
  ...ctx.imports && { imports: ctx.imports },
16475
- ...ctx.route && { route: ctx.route }
16505
+ ...ctx.route && { route: ctx.route },
16506
+ ...ctx.styles && { styles: ctx.styles }
16476
16507
  };
16477
16508
  if (newBranch === "then") {
16478
16509
  currentNode = render(node.then, branchCtx);
@@ -16512,7 +16543,8 @@ function hydrateEachEmpty(node, parent, insertBefore, ctx) {
16512
16543
  state: ctx.state,
16513
16544
  locals: ctx.locals,
16514
16545
  ...ctx.imports && { imports: ctx.imports },
16515
- ...ctx.route && { route: ctx.route }
16546
+ ...ctx.route && { route: ctx.route },
16547
+ ...ctx.styles && { styles: ctx.styles }
16516
16548
  });
16517
16549
  if (!hasKey || !node.key) {
16518
16550
  for (const cleanup of itemCleanups) {
@@ -16540,7 +16572,8 @@ function hydrateEachEmpty(node, parent, insertBefore, ctx) {
16540
16572
  actions: ctx.actions,
16541
16573
  locals: itemLocals,
16542
16574
  cleanups: localCleanups,
16543
- ...ctx.imports && { imports: ctx.imports }
16575
+ ...ctx.imports && { imports: ctx.imports },
16576
+ ...ctx.styles && { styles: ctx.styles }
16544
16577
  };
16545
16578
  const itemNode = render(node.body, itemCtx);
16546
16579
  currentNodes.push(itemNode);
@@ -16573,7 +16606,8 @@ function hydrateEachEmpty(node, parent, insertBefore, ctx) {
16573
16606
  state: ctx.state,
16574
16607
  locals: tempLocals,
16575
16608
  ...ctx.imports && { imports: ctx.imports },
16576
- ...ctx.route && { route: ctx.route }
16609
+ ...ctx.route && { route: ctx.route },
16610
+ ...ctx.styles && { styles: ctx.styles }
16577
16611
  });
16578
16612
  if (seenKeys.has(keyValue)) {
16579
16613
  if (typeof process !== "undefined" && process.env?.["NODE_ENV"] !== "production") {
@@ -16603,7 +16637,8 @@ function hydrateEachEmpty(node, parent, insertBefore, ctx) {
16603
16637
  actions: ctx.actions,
16604
16638
  locals: reactiveLocals,
16605
16639
  cleanups: localCleanups,
16606
- ...ctx.imports && { imports: ctx.imports }
16640
+ ...ctx.imports && { imports: ctx.imports },
16641
+ ...ctx.styles && { styles: ctx.styles }
16607
16642
  };
16608
16643
  const itemNode = render(node.body, itemCtx);
16609
16644
  const newState = {
@@ -16665,7 +16700,8 @@ function hydrateEach(node, firstItemDomNode, ctx) {
16665
16700
  state: ctx.state,
16666
16701
  locals: ctx.locals,
16667
16702
  ...ctx.imports && { imports: ctx.imports },
16668
- ...ctx.route && { route: ctx.route }
16703
+ ...ctx.route && { route: ctx.route },
16704
+ ...ctx.styles && { styles: ctx.styles }
16669
16705
  });
16670
16706
  let isFirstRun = true;
16671
16707
  if (Array.isArray(initialItems) && initialItems.length > 0) {
@@ -16683,7 +16719,8 @@ function hydrateEach(node, firstItemDomNode, ctx) {
16683
16719
  state: ctx.state,
16684
16720
  locals: tempLocals,
16685
16721
  ...ctx.imports && { imports: ctx.imports },
16686
- ...ctx.route && { route: ctx.route }
16722
+ ...ctx.route && { route: ctx.route },
16723
+ ...ctx.styles && { styles: ctx.styles }
16687
16724
  });
16688
16725
  if (seenKeys.has(keyValue)) {
16689
16726
  if (typeof process !== "undefined" && process.env?.["NODE_ENV"] !== "production") {
@@ -16755,7 +16792,8 @@ function hydrateEach(node, firstItemDomNode, ctx) {
16755
16792
  state: ctx.state,
16756
16793
  locals: ctx.locals,
16757
16794
  ...ctx.imports && { imports: ctx.imports },
16758
- ...ctx.route && { route: ctx.route }
16795
+ ...ctx.route && { route: ctx.route },
16796
+ ...ctx.styles && { styles: ctx.styles }
16759
16797
  });
16760
16798
  if (isFirstRun) {
16761
16799
  isFirstRun = false;
@@ -16787,7 +16825,8 @@ function hydrateEach(node, firstItemDomNode, ctx) {
16787
16825
  actions: ctx.actions,
16788
16826
  locals: itemLocals,
16789
16827
  cleanups: localCleanups,
16790
- ...ctx.imports && { imports: ctx.imports }
16828
+ ...ctx.imports && { imports: ctx.imports },
16829
+ ...ctx.styles && { styles: ctx.styles }
16791
16830
  };
16792
16831
  const itemNode = render(node.body, itemCtx);
16793
16832
  currentNodes.push(itemNode);
@@ -16820,7 +16859,8 @@ function hydrateEach(node, firstItemDomNode, ctx) {
16820
16859
  state: ctx.state,
16821
16860
  locals: tempLocals,
16822
16861
  ...ctx.imports && { imports: ctx.imports },
16823
- ...ctx.route && { route: ctx.route }
16862
+ ...ctx.route && { route: ctx.route },
16863
+ ...ctx.styles && { styles: ctx.styles }
16824
16864
  });
16825
16865
  if (seenKeys.has(keyValue)) {
16826
16866
  if (typeof process !== "undefined" && process.env?.["NODE_ENV"] !== "production") {
@@ -16850,7 +16890,8 @@ function hydrateEach(node, firstItemDomNode, ctx) {
16850
16890
  actions: ctx.actions,
16851
16891
  locals: reactiveLocals,
16852
16892
  cleanups: localCleanups,
16853
- ...ctx.imports && { imports: ctx.imports }
16893
+ ...ctx.imports && { imports: ctx.imports },
16894
+ ...ctx.styles && { styles: ctx.styles }
16854
16895
  };
16855
16896
  const itemNode = render(node.body, itemCtx);
16856
16897
  const newState = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@constela/runtime",
3
- "version": "2.0.8",
3
+ "version": "2.0.10",
4
4
  "description": "Runtime DOM renderer for Constela UI framework",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -18,7 +18,7 @@
18
18
  "dompurify": "^3.3.1",
19
19
  "marked": "^17.0.1",
20
20
  "shiki": "^3.20.0",
21
- "@constela/compiler": "0.15.11",
21
+ "@constela/compiler": "0.15.12",
22
22
  "@constela/core": "0.18.5"
23
23
  },
24
24
  "devDependencies": {