@rkmodules/rules 0.0.101 → 0.0.102

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.cjs.js CHANGED
@@ -269,6 +269,74 @@ function getItem(tree, path, index) {
269
269
  return branch[index];
270
270
  }
271
271
  }
272
+ /**
273
+ * gets number of dimensions (max depth of the tree) and their sizes (group sizes at each level)
274
+ * @param tree
275
+ * @returns
276
+ */
277
+ function treeStats(tree) {
278
+ var paths = getPaths(tree);
279
+ var dimensions = 0;
280
+ var branchSizes = {};
281
+ paths.forEach(function (path) {
282
+ var _a;
283
+ var segments = path.split(";").map(function (seg) { return parseInt(seg, 10); });
284
+ // find max depth, which is the number of dimensions
285
+ dimensions = Math.max(dimensions, segments.length);
286
+ segments.forEach(function (seg, index) {
287
+ if (!index)
288
+ return;
289
+ var prefix = segments.slice(0, index).join(";");
290
+ if (!branchSizes[prefix]) {
291
+ branchSizes[prefix] = 1;
292
+ }
293
+ else {
294
+ branchSizes[prefix] += 1;
295
+ }
296
+ });
297
+ branchSizes[path] = ((_a = getBranch(tree, path)) === null || _a === void 0 ? void 0 : _a.length) || 0;
298
+ });
299
+ return { dimensions: dimensions, branchSizes: branchSizes };
300
+ }
301
+ function normalizePaths(tree) {
302
+ var paths = getPaths(tree);
303
+ var spaths = paths.map(function (p) { return p.split(";").map(function (seg) { return parseInt(seg, 10); }); });
304
+ var maxLength = Math.max.apply(Math, __spreadArray([], __read(spaths.map(function (p) { return p.length; })), false));
305
+ var lastSPath;
306
+ var lastNPath;
307
+ var npaths = [];
308
+ spaths.forEach(function (p, index) {
309
+ if (index === 0) {
310
+ // start with a full zero path
311
+ lastNPath = Array(maxLength).fill(0);
312
+ npaths.push(lastNPath.join(";"));
313
+ }
314
+ else {
315
+ // start with all zeros
316
+ var n = Array(maxLength).fill(0);
317
+ for (var i = 0; i < maxLength; i++) {
318
+ if (p[i] > lastSPath[i]) {
319
+ // increment the segment, all the rest are zeros, so we can stop
320
+ n[i] = lastNPath[i] + 1;
321
+ break;
322
+ }
323
+ else {
324
+ // same segment, copy over
325
+ n[i] = lastNPath[i];
326
+ }
327
+ }
328
+ lastNPath = n;
329
+ npaths.push(lastNPath.join(";"));
330
+ }
331
+ lastSPath = p;
332
+ });
333
+ var normalized = {};
334
+ paths.forEach(function (path, index) {
335
+ var branch = getBranch(tree, path);
336
+ normalized[npaths[index]] = branch || [];
337
+ });
338
+ return normalized;
339
+ }
272
340
  function forEachBranch(tree, fn) {
273
341
  var paths = getPaths(tree);
274
342
  paths.forEach(function (path, i) {
@@ -7301,6 +7369,7 @@ exports.mapTree = mapTree;
7301
7369
  exports.mapTreeBranch = mapTreeBranch;
7302
7370
  exports.nAryOnTree = nAryOnTree;
7303
7371
  exports.nAryOnTreeBranch = nAryOnTreeBranch;
7372
+ exports.normalizePaths = normalizePaths;
7304
7373
  exports.normalizeVarDef = normalizeVarDef;
7305
7374
  exports.parseReference = parseReference;
7306
7375
  exports.primitives = primitives;
@@ -7310,6 +7379,7 @@ exports.simplifyTree = simplifyTree$1;
7310
7379
  exports.toArray = toArray;
7311
7380
  exports.topSort = topSort;
7312
7381
  exports.treeSize = treeSize;
7382
+ exports.treeStats = treeStats;
7313
7383
  exports.trimTree = trimTree;
7314
7384
  exports.uid = uid$1;
7315
7385
  exports.useDraggableNode = useDraggableNode;