@constela/runtime 2.0.3 → 2.0.5

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.
Files changed (2) hide show
  1. package/dist/index.js +40 -15
  2. package/package.json +1 -1
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
+ getLinePoints: (data, valueKey, width, height, padding) => getLinePoints(data, valueKey, width, height, padding),
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),
@@ -1591,6 +1592,24 @@ function getChartBounds(data, valueKey) {
1591
1592
  max: Math.max(...values)
1592
1593
  };
1593
1594
  }
1595
+ function getLinePoints(data, valueKey, width, height, padding) {
1596
+ if (!Array.isArray(data) || data.length === 0) return void 0;
1597
+ if (typeof valueKey !== "string") return void 0;
1598
+ if (typeof width !== "number" || typeof height !== "number") return void 0;
1599
+ const pad = typeof padding === "number" ? padding : 40;
1600
+ const bounds = getChartBounds(data, valueKey);
1601
+ if (!bounds) return void 0;
1602
+ const { min, max } = bounds;
1603
+ const chartWidth = width - pad * 2;
1604
+ const chartHeight = height - pad * 2;
1605
+ return data.map((item, idx) => {
1606
+ const value = item[valueKey];
1607
+ if (typeof value !== "number") return { x: 0, y: 0 };
1608
+ const x2 = pad + (data.length > 1 ? idx / (data.length - 1) * chartWidth : chartWidth / 2);
1609
+ const y2 = min === max ? pad + chartHeight / 2 : pad + chartHeight - scaleValue(value, min, max, 0, chartHeight);
1610
+ return { x: x2, y: y2 };
1611
+ });
1612
+ }
1594
1613
  function generateTicks(min, max, count) {
1595
1614
  if (typeof min !== "number" || typeof max !== "number" || typeof count !== "number") {
1596
1615
  return [];
@@ -16167,20 +16186,22 @@ function hydrateElement(node, el, ctx) {
16167
16186
  hydrateChildren(node.children, el, ctx);
16168
16187
  }
16169
16188
  }
16170
- function findSsrIfBranchMarker(parent, beforeNode) {
16171
- let current = beforeNode ? beforeNode.previousSibling : parent.lastChild;
16172
- while (current) {
16173
- if (current.nodeType === Node.COMMENT_NODE) {
16174
- const comment2 = current;
16175
- const text3 = comment2.textContent;
16176
- if (text3 === "if:then") return { branch: "then", marker: comment2 };
16177
- if (text3 === "if:else") return { branch: "else", marker: comment2 };
16178
- if (text3 === "if:none") return { branch: "none", marker: comment2 };
16189
+ function collectIfMarkers(parent) {
16190
+ const markers = [];
16191
+ for (let i = 0; i < parent.childNodes.length; i++) {
16192
+ const child = parent.childNodes[i];
16193
+ if (child.nodeType === Node.COMMENT_NODE) {
16194
+ const text3 = child.textContent;
16195
+ if (text3 === "if:then") {
16196
+ markers.push({ branch: "then", marker: child });
16197
+ } else if (text3 === "if:else") {
16198
+ markers.push({ branch: "else", marker: child });
16199
+ } else if (text3 === "if:none") {
16200
+ markers.push({ branch: "none", marker: child });
16201
+ }
16179
16202
  }
16180
- if (current.nodeType === Node.ELEMENT_NODE) break;
16181
- current = current.previousSibling;
16182
16203
  }
16183
- return null;
16204
+ return markers;
16184
16205
  }
16185
16206
  function hydrateChildren(children, parent, ctx) {
16186
16207
  const domChildren = [];
@@ -16190,6 +16211,8 @@ function hydrateChildren(children, parent, ctx) {
16190
16211
  domChildren.push(child);
16191
16212
  }
16192
16213
  }
16214
+ const ifMarkers = collectIfMarkers(parent);
16215
+ let ifMarkerIndex = 0;
16193
16216
  let domIndex = 0;
16194
16217
  for (let i = 0; i < children.length; i++) {
16195
16218
  const childNode = children[i];
@@ -16224,14 +16247,15 @@ function hydrateChildren(children, parent, ctx) {
16224
16247
  ...ctx.route && { route: ctx.route }
16225
16248
  });
16226
16249
  const clientBranch = Boolean(clientCondition) ? "then" : ifNode.else ? "else" : "none";
16227
- const domChild = domChildren[domIndex];
16228
- const ssrInfo = findSsrIfBranchMarker(parent, domChild || null);
16250
+ const ssrInfo = ifMarkerIndex < ifMarkers.length ? ifMarkers[ifMarkerIndex] : null;
16251
+ ifMarkerIndex++;
16229
16252
  const ssrBranch = ssrInfo?.branch ?? null;
16230
16253
  const ssrHasDom = ssrBranch === "then" || ssrBranch === "else";
16231
16254
  if (ssrInfo?.marker) {
16232
16255
  ssrInfo.marker.remove();
16233
16256
  }
16234
- if (ssrHasDom && domChild) {
16257
+ if (ssrHasDom && domChildren[domIndex]) {
16258
+ const domChild = domChildren[domIndex];
16235
16259
  hydrateIf(ifNode, domChild, ctx, { ssrBranch, clientBranch });
16236
16260
  domIndex++;
16237
16261
  } else if (ssrBranch === "none") {
@@ -16240,6 +16264,7 @@ function hydrateChildren(children, parent, ctx) {
16240
16264
  });
16241
16265
  } else {
16242
16266
  const hasDomForIf = Boolean(clientCondition) || Boolean(ifNode.else);
16267
+ const domChild = domChildren[domIndex];
16243
16268
  if (hasDomForIf && domChild) {
16244
16269
  hydrate(childNode, domChild, ctx);
16245
16270
  domIndex++;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@constela/runtime",
3
- "version": "2.0.3",
3
+ "version": "2.0.5",
4
4
  "description": "Runtime DOM renderer for Constela UI framework",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",