@bino-bi/bn-template-engine 1.0.0-next.30 → 1.0.0-next.32

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 (145) hide show
  1. package/dist/bn-template-engine/bn-template-engine.esm.js +1 -1
  2. package/dist/bn-template-engine/{p-64803a42.entry.js → p-14d021be.entry.js} +1 -1
  3. package/dist/bn-template-engine/p-225cd474.entry.js +1 -0
  4. package/dist/bn-template-engine/p-58b10778.entry.js +1 -0
  5. package/dist/bn-template-engine/{p-40ba7f43.entry.js → p-7d475277.entry.js} +1 -1
  6. package/dist/bn-template-engine/p-9f3cbc5f.entry.js +1 -0
  7. package/dist/bn-template-engine/p-BNCLKXjM.js +1 -0
  8. package/dist/bn-template-engine/{p-B8AjeKja.js → p-BTbeDWM9.js} +1 -1
  9. package/dist/bn-template-engine/{p-Z2rUaSh_.js → p-BjR3nkhl.js} +1 -1
  10. package/dist/bn-template-engine/p-CHZ50kEY.js +1 -0
  11. package/dist/bn-template-engine/p-CJfJQT0m.js +1 -0
  12. package/dist/bn-template-engine/p-ce39e111.entry.js +1 -0
  13. package/dist/cjs/bn-annotation-layer_30.cjs.entry.js +191 -68
  14. package/dist/cjs/bn-grid.cjs.entry.js +465 -34
  15. package/dist/cjs/bn-image.cjs.entry.js +2 -2
  16. package/dist/cjs/bn-internationalization.cjs.entry.js +2 -2
  17. package/dist/cjs/bn-ruleset.cjs.entry.js +2 -2
  18. package/dist/cjs/bn-template-engine.cjs.js +1 -1
  19. package/dist/cjs/bn-text.cjs.entry.js +3 -3
  20. package/dist/cjs/loader.cjs.js +1 -1
  21. package/dist/cjs/{diagnostics-C4Ggts3w.js → localFrame-P5SDUOto.js} +90 -1
  22. package/dist/cjs/{withBodyObserver-BK4idxqG.js → withBodyObserver-B1_hmuUz.js} +1 -1
  23. package/dist/cjs/{withHasError-CqvcS23z.js → withHasError-3kR2tdhJ.js} +4 -0
  24. package/dist/cjs/{withStyled-70D4Isgt.js → withStyled-Ds3e64Nz.js} +1 -1
  25. package/dist/cjs/{withTranslation-C6Pye2CM.js → withTranslation-Cjvvs3gL.js} +2 -2
  26. package/dist/collection/components/bn-chart-bubble/bn-chart-bubble.js +32 -2
  27. package/dist/collection/components/bn-chart-bullet/bn-chart-bullet.js +32 -2
  28. package/dist/collection/components/bn-chart-bullet/utils/BulletChart.js +3 -1
  29. package/dist/collection/components/bn-chart-scatter/bn-chart-scatter.js +32 -2
  30. package/dist/collection/components/bn-chart-structure/bn-chart-structure-renderer/bn-chart-structure-renderer.js +1 -1
  31. package/dist/collection/components/bn-chart-structure/bn-chart-structure.js +33 -2
  32. package/dist/collection/components/bn-chart-time/bn-chart-time-renderer/bn-chart-time-renderer.js +1 -1
  33. package/dist/collection/components/bn-chart-time/bn-chart-time.js +33 -2
  34. package/dist/collection/components/bn-grid/bn-grid.js +454 -26
  35. package/dist/collection/components/bn-grid/utils/cellLayout.js +111 -0
  36. package/dist/collection/components/bn-table/bn-table.js +39 -2
  37. package/dist/collection/stores/componentStyles.js +4 -0
  38. package/dist/collection/utils/layoutState/baseline.js +67 -0
  39. package/dist/collection/utils/layoutState/index.js +2 -0
  40. package/dist/collection/utils/layoutState/localFrame.js +87 -0
  41. package/dist/collection/utils/layoutState/svgChartElements.js +6 -2
  42. package/dist/collection/utils/xy/XYFrame.js +3 -1
  43. package/dist/components/bn-annotation-layer.js +1 -1
  44. package/dist/components/bn-annotation-list.js +1 -1
  45. package/dist/components/bn-asset.js +1 -1
  46. package/dist/components/bn-body.js +1 -1
  47. package/dist/components/bn-card.js +1 -1
  48. package/dist/components/bn-chart-bubble-renderer.js +1 -1
  49. package/dist/components/bn-chart-bubble.js +1 -1
  50. package/dist/components/bn-chart-bullet-renderer.js +1 -1
  51. package/dist/components/bn-chart-bullet.js +1 -1
  52. package/dist/components/bn-chart-scatter-renderer.js +1 -1
  53. package/dist/components/bn-chart-scatter.js +1 -1
  54. package/dist/components/bn-chart-structure-renderer.js +1 -1
  55. package/dist/components/bn-chart-structure.js +1 -1
  56. package/dist/components/bn-chart-time-renderer.js +1 -1
  57. package/dist/components/bn-chart-time.js +1 -1
  58. package/dist/components/bn-component-style.js +1 -1
  59. package/dist/components/bn-context.js +1 -1
  60. package/dist/components/bn-dataset.js +1 -1
  61. package/dist/components/bn-datasource.js +1 -1
  62. package/dist/components/bn-footer.js +1 -1
  63. package/dist/components/bn-grid.js +1 -1
  64. package/dist/components/bn-image.js +1 -1
  65. package/dist/components/bn-internationalization.js +1 -1
  66. package/dist/components/bn-layout-card.js +1 -1
  67. package/dist/components/bn-layout-page.js +1 -1
  68. package/dist/components/bn-message.js +1 -1
  69. package/dist/components/bn-page.js +1 -1
  70. package/dist/components/bn-ruleset.js +1 -1
  71. package/dist/components/bn-scaling-group.js +1 -1
  72. package/dist/components/bn-table-renderer.js +1 -1
  73. package/dist/components/bn-table.js +1 -1
  74. package/dist/components/bn-text.js +1 -1
  75. package/dist/components/bn-title.js +1 -1
  76. package/dist/components/bn-tree.js +1 -1
  77. package/dist/components/p-0gehv1XG.js +1 -0
  78. package/dist/components/{p-Bs-YxJEt.js → p-8a2-IS-y.js} +1 -1
  79. package/dist/components/p-B2jqpOF9.js +1 -0
  80. package/dist/components/{p-BWBHlztH.js → p-BPJsmv3o.js} +1 -1
  81. package/dist/components/{p-BXrPfAvP.js → p-BVtD8O36.js} +1 -1
  82. package/dist/components/p-BcOud3dQ.js +1 -0
  83. package/dist/components/{p-DsOaqeTN.js → p-BoUkFdpu.js} +1 -1
  84. package/dist/components/p-BohXdw3-.js +1 -0
  85. package/dist/components/p-C6XrNN2m.js +1 -0
  86. package/dist/components/{p-Dm55bMs2.js → p-CDoSPw-I.js} +1 -1
  87. package/dist/components/p-CMCnX0iM.js +1 -0
  88. package/dist/components/{p-Ds_BSK8v.js → p-ClGOhg6P.js} +1 -1
  89. package/dist/components/p-CujsXn-l.js +1 -0
  90. package/dist/components/{p-Ba9PUiBp.js → p-D4FY_yoG.js} +1 -1
  91. package/dist/components/{p-DIyUaSBg.js → p-D6cWoDk1.js} +1 -1
  92. package/dist/components/p-D7X69xMg.js +1 -0
  93. package/dist/components/{p-B1nL0yOa.js → p-DSkyHSIL.js} +1 -1
  94. package/dist/components/{p-BSV_vyqs.js → p-De82WP7z.js} +1 -1
  95. package/dist/components/p-DyO09Jk6.js +1 -0
  96. package/dist/components/{p-WzaayhTX.js → p-Ku08TQL1.js} +1 -1
  97. package/dist/components/p-t4xPltK2.js +1 -0
  98. package/dist/components/{p-ey23VlID.js → p-yH-XxIy9.js} +1 -1
  99. package/dist/components/{p-X9hpquOX.js → p-z56_ZQ42.js} +1 -1
  100. package/dist/components/{p-B7uwck1J.js → p-zf8cTH63.js} +1 -1
  101. package/dist/esm/bn-annotation-layer_30.entry.js +140 -17
  102. package/dist/esm/bn-grid.entry.js +456 -25
  103. package/dist/esm/bn-image.entry.js +2 -2
  104. package/dist/esm/bn-internationalization.entry.js +2 -2
  105. package/dist/esm/bn-ruleset.entry.js +2 -2
  106. package/dist/esm/bn-template-engine.js +1 -1
  107. package/dist/esm/bn-text.entry.js +3 -3
  108. package/dist/esm/loader.js +1 -1
  109. package/dist/esm/{diagnostics-Cyqy1zDT.js → localFrame-IW84cmdb.js} +90 -2
  110. package/dist/esm/{withBodyObserver-JcRB9OPQ.js → withBodyObserver-CAnnvrE_.js} +1 -1
  111. package/dist/esm/{withHasError-l3cMN-oP.js → withHasError-Cj_MzZ8Q.js} +4 -0
  112. package/dist/esm/{withStyled-DGOiR00Q.js → withStyled-B-cbWCe2.js} +1 -1
  113. package/dist/esm/{withTranslation-BpO8BC5B.js → withTranslation-_8q-7Y9C.js} +2 -2
  114. package/dist/schemas/theme.schema.json +14 -0
  115. package/dist/types/components/bn-chart-bubble/bn-chart-bubble.d.ts +6 -1
  116. package/dist/types/components/bn-chart-bullet/bn-chart-bullet.d.ts +6 -1
  117. package/dist/types/components/bn-chart-scatter/bn-chart-scatter.d.ts +6 -1
  118. package/dist/types/components/bn-chart-structure/bn-chart-structure.d.ts +6 -1
  119. package/dist/types/components/bn-chart-time/bn-chart-time.d.ts +6 -1
  120. package/dist/types/components/bn-grid/bn-grid.d.ts +79 -3
  121. package/dist/types/components/bn-grid/utils/cellLayout.d.ts +47 -0
  122. package/dist/types/components/bn-table/bn-table.d.ts +8 -1
  123. package/dist/types/components.d.ts +94 -7
  124. package/dist/types/stores/componentStyles.d.ts +6 -0
  125. package/dist/types/utils/layoutState/baseline.d.ts +17 -0
  126. package/dist/types/utils/layoutState/index.d.ts +2 -0
  127. package/dist/types/utils/layoutState/localFrame.d.ts +17 -0
  128. package/dist/types/utils/layoutState/svgChartElements.d.ts +3 -1
  129. package/dist/types/utils/layoutState/types.d.ts +12 -2
  130. package/package.json +1 -1
  131. package/dist/bn-template-engine/p-132ad556.entry.js +0 -1
  132. package/dist/bn-template-engine/p-17d71782.entry.js +0 -1
  133. package/dist/bn-template-engine/p-467871f3.entry.js +0 -1
  134. package/dist/bn-template-engine/p-CrT83eO4.js +0 -1
  135. package/dist/bn-template-engine/p-D_DzKxRV.js +0 -1
  136. package/dist/bn-template-engine/p-c41c0a1b.entry.js +0 -1
  137. package/dist/bn-template-engine/p-yc69rwuH.js +0 -1
  138. package/dist/components/p-BDS_jiow.js +0 -1
  139. package/dist/components/p-BIIDTtcR.js +0 -1
  140. package/dist/components/p-BVKLCz2k.js +0 -1
  141. package/dist/components/p-CkW23yp2.js +0 -1
  142. package/dist/components/p-DUHp_9X-.js +0 -1
  143. package/dist/components/p-Dq1AzGKX.js +0 -1
  144. package/dist/components/p-U3zkcEJZ.js +0 -1
  145. package/dist/components/p-jbp6YiHf.js +0 -1
@@ -2,9 +2,9 @@
2
2
 
3
3
  var index = require('./index-DGis1BzT.js');
4
4
  var index$1 = require('./index.cjs.js');
5
- var diagnostics = require('./diagnostics-C4Ggts3w.js');
6
- var withHasError = require('./withHasError-CqvcS23z.js');
7
- var withStyled = require('./withStyled-70D4Isgt.js');
5
+ var localFrame = require('./localFrame-P5SDUOto.js');
6
+ var withHasError = require('./withHasError-3kR2tdhJ.js');
7
+ var withStyled = require('./withStyled-Ds3e64Nz.js');
8
8
 
9
9
  /**
10
10
  * Header configuration types and parsing utilities for bn-grid component.
@@ -121,8 +121,132 @@ function validateHeadersJson(json) {
121
121
  }
122
122
  }
123
123
 
124
+ /**
125
+ * Cell size and alignment for bn-grid: the accepted values, their CSS, and
126
+ * the offsets that line up the baselines of the components in a row or column.
127
+ */
128
+ const CELL_SIZES = ["auto", "equal"];
129
+ const VERTICAL_ALIGNS = ["top", "center", "bottom", "baseline"];
130
+ const HORIZONTAL_ALIGNS = ["left", "center", "right", "baseline"];
131
+ /** justify-content of a flex column cell. Baseline cells start at the top and are padded down. */
132
+ const JUSTIFY = {
133
+ top: "flex-start",
134
+ center: "center",
135
+ bottom: "flex-end",
136
+ baseline: "flex-start",
137
+ };
138
+ /**
139
+ * align-items of a flex column cell. `left` stretches: a chart measures the
140
+ * width of its wrapper, and flex-start would shrink that wrapper.
141
+ */
142
+ const ALIGN = {
143
+ left: "stretch",
144
+ center: "center",
145
+ right: "flex-end",
146
+ baseline: "stretch",
147
+ };
148
+ /** Parses `cell-captions`: a JSON object from slot name to caption text. `undefined` when invalid. */
149
+ function parseCaptions(json) {
150
+ if (json === undefined || json.trim() === "")
151
+ return {};
152
+ let parsed;
153
+ try {
154
+ parsed = JSON.parse(json);
155
+ }
156
+ catch (_a) {
157
+ return undefined;
158
+ }
159
+ if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed))
160
+ return undefined;
161
+ const captions = {};
162
+ for (const [slot, text] of Object.entries(parsed)) {
163
+ if (typeof text !== "string")
164
+ return undefined;
165
+ if (text !== "")
166
+ captions[slot] = text;
167
+ }
168
+ return captions;
169
+ }
170
+ const round2 = (value) => Math.round(value * 100) / 100;
171
+ /**
172
+ * Offsets that put every baseline of a row on the lowest one, and every
173
+ * baseline of a column on the rightmost one. A cell without a baseline on an
174
+ * axis goes to the bottom (vertical) or stays left (horizontal).
175
+ */
176
+ function baselineOffsets(cells, vertical, horizontal) {
177
+ const offsets = {};
178
+ for (const cell of cells)
179
+ offsets[cell.slot] = {};
180
+ const line = (key, value, applied, set) => {
181
+ var _a;
182
+ const groups = new Map();
183
+ for (const cell of cells)
184
+ groups.set(cell[key], [...((_a = groups.get(cell[key])) !== null && _a !== void 0 ? _a : []), cell]);
185
+ for (const group of groups.values()) {
186
+ // where each baseline would be without an offset
187
+ const natural = group.map((cell) => {
188
+ const v = value(cell);
189
+ return v === undefined ? undefined : v - applied(cell);
190
+ });
191
+ const known = natural.filter((v) => v !== undefined);
192
+ const target = known.length > 0 ? Math.max(...known) : 0;
193
+ const pads = natural.map((v) => (v === undefined ? undefined : round2(target - v)));
194
+ const largest = Math.max(0, ...pads.filter((pad) => pad !== undefined));
195
+ group.forEach((cell, index) => set(offsets[cell.slot], pads[index], largest));
196
+ }
197
+ };
198
+ if (vertical) {
199
+ line("row", (cell) => cell.y, (cell) => cell.top, (offset, pad) => {
200
+ if (pad === undefined)
201
+ offset.bottom = true;
202
+ else
203
+ offset.top = pad;
204
+ });
205
+ }
206
+ if (horizontal) {
207
+ line("column", (cell) => cell.x, (cell) => cell.left, (offset, pad, largest) => {
208
+ if (pad !== undefined)
209
+ offset.left = pad;
210
+ const right = round2(largest - (pad !== null && pad !== void 0 ? pad : 0));
211
+ if (right > 0)
212
+ offset.right = right;
213
+ });
214
+ }
215
+ return offsets;
216
+ }
217
+ /** Two offset maps place every cell within half a px of each other. */
218
+ function sameOffsets(a, b) {
219
+ var _a, _b, _c, _d, _e, _f, _g, _h;
220
+ const slots = new Set([...Object.keys(a), ...Object.keys(b)]);
221
+ for (const slot of slots) {
222
+ const x = (_a = a[slot]) !== null && _a !== void 0 ? _a : {};
223
+ const y = (_b = b[slot]) !== null && _b !== void 0 ? _b : {};
224
+ if (Boolean(x.bottom) !== Boolean(y.bottom))
225
+ return false;
226
+ if (Math.abs(((_c = x.top) !== null && _c !== void 0 ? _c : 0) - ((_d = y.top) !== null && _d !== void 0 ? _d : 0)) >= 0.5)
227
+ return false;
228
+ if (Math.abs(((_e = x.left) !== null && _e !== void 0 ? _e : 0) - ((_f = y.left) !== null && _f !== void 0 ? _f : 0)) >= 0.5)
229
+ return false;
230
+ if (Math.abs(((_g = x.right) !== null && _g !== void 0 ? _g : 0) - ((_h = y.right) !== null && _h !== void 0 ? _h : 0)) >= 0.5)
231
+ return false;
232
+ }
233
+ return true;
234
+ }
235
+
124
236
  const bnGridCss = () => `:host{display:inline-block;font-family:var(--bn-font-family, "Noto Sans", sans-serif);font-size:var(--bn-font-size, 13.3333px);color:var(--bn-font-color, #000000)}.grid-container{display:inline-grid;box-sizing:border-box}.grid-title{font-weight:normal;padding-bottom:8px}.grid-header{display:flex;align-items:flex-end;box-sizing:border-box}.grid-header-row{justify-content:flex-end;padding-right:8px}.grid-header-col{white-space:nowrap;justify-content:flex-start}.grid-cell{position:relative;box-sizing:border-box}`;
125
237
 
238
+ /** Elements in a slot that show nothing, so they are not what a cell aligns on. */
239
+ const CONFIG_ELEMENTS = new Set([
240
+ "bn-asset",
241
+ "bn-component-style",
242
+ "bn-dataset",
243
+ "bn-datasource",
244
+ "bn-internationalization",
245
+ "bn-ruleset",
246
+ "bn-scaling-group",
247
+ ]);
248
+ /** A pass that keeps changing the offsets stops after this many: a component whose baseline follows its width could chase it. */
249
+ const MAX_ADJUSTMENTS = 5;
126
250
  const Grid = class {
127
251
  validateRowHeaders(newValue) {
128
252
  const errId = "ERR_rowHeaders";
@@ -154,9 +278,48 @@ const Grid = class {
154
278
  }
155
279
  this.updateGridConfig();
156
280
  }
281
+ validateCellHeight(newValue) {
282
+ this.resolvedHeight = this.validateChoice("cell-height", "ERR_cellHeight", newValue, CELL_SIZES, "auto");
283
+ }
284
+ validateCellWidth(newValue) {
285
+ this.resolvedWidth = this.validateChoice("cell-width", "ERR_cellWidth", newValue, CELL_SIZES, "auto");
286
+ }
287
+ validateCellVerticalAlign(newValue) {
288
+ this.resolvedVertical = this.validateChoice("cell-vertical-align", "ERR_cellVerticalAlign", newValue, VERTICAL_ALIGNS, "top");
289
+ this.schedule();
290
+ }
291
+ validateCellHorizontalAlign(newValue) {
292
+ this.resolvedHorizontal = this.validateChoice("cell-horizontal-align", "ERR_cellHorizontalAlign", newValue, HORIZONTAL_ALIGNS, "left");
293
+ this.schedule();
294
+ }
295
+ validateCellCaptions(newValue) {
296
+ const captions = parseCaptions(newValue);
297
+ if (captions) {
298
+ this.errors.remove("ERR_cellCaptions");
299
+ }
300
+ else {
301
+ this.errors.addOrReplace({
302
+ id: "ERR_cellCaptions",
303
+ type: "error",
304
+ message: "cell-captions: not a JSON object from slot name to text.",
305
+ });
306
+ }
307
+ this.captions = captions !== null && captions !== void 0 ? captions : {};
308
+ }
157
309
  constructor(hostRef) {
158
310
  index.registerInstance(this, hostRef);
159
311
  this.gridConfig = { rows: [], columns: [] };
312
+ this.resolvedHeight = "auto";
313
+ this.resolvedWidth = "auto";
314
+ this.resolvedVertical = "top";
315
+ this.resolvedHorizontal = "left";
316
+ this.captions = {};
317
+ /** Per slot: how far the baseline pass moved the content. */
318
+ this.offsets = {};
319
+ this.observed = new WeakSet();
320
+ this.scheduled = false;
321
+ this.run = 0;
322
+ this.adjustments = 0;
160
323
  /**
161
324
  * Title displayed at top-left of the grid.
162
325
  */
@@ -193,31 +356,220 @@ const Grid = class {
193
356
  * Gap between cells. Accepts CSS values (e.g., '0px', '8px').
194
357
  */
195
358
  this.cellGap = "0px";
359
+ /**
360
+ * Height of the data rows: `auto` (default) sizes each row to its content,
361
+ * `equal` gives every data row the height of the tallest one.
362
+ */
363
+ this.cellHeight = "auto";
364
+ /**
365
+ * Width of the data columns: `auto` (default) sizes each column to its
366
+ * content, `equal` makes the grid as wide as its container and gives every
367
+ * data column the same share of it.
368
+ */
369
+ this.cellWidth = "auto";
370
+ /**
371
+ * Vertical position of the content in a cell: `top` (default), `center`,
372
+ * `bottom`, or `baseline`. `baseline` lines up the components of a row on
373
+ * their baseline (the axis of a chart, the bottom of a table header); a
374
+ * component without one goes to the bottom.
375
+ */
376
+ this.cellVerticalAlign = "top";
377
+ /**
378
+ * Horizontal position of the content in a cell: `left` (default),
379
+ * `center`, `right`, or `baseline`. `baseline` lines up the components of
380
+ * a column on their baseline (the vertical axis of a chart, the first value
381
+ * column of a table); a component without one stays left.
382
+ */
383
+ this.cellHorizontalAlign = "left";
384
+ /**
385
+ * JSON object from slot name to a caption, drawn top left in the cell above
386
+ * its content: '{"0-0": "Berlin", "0-1": "Cologne"}'. Alignment moves the
387
+ * content, never the caption. The style section `bn-grid` sets its font.
388
+ */
389
+ this.cellCaptions = "";
390
+ /**
391
+ * Aligns the baselines after the next paint. The grid counts as working
392
+ * until then, so a printer does not print a half-aligned grid.
393
+ */
394
+ this.schedule = () => {
395
+ if (!this.isBaselineMode()) {
396
+ // drop a pass in flight, so it cannot write offsets of the old mode back
397
+ this.run++;
398
+ if (Object.keys(this.offsets).length > 0)
399
+ this.offsets = {};
400
+ return;
401
+ }
402
+ if (this.scheduled)
403
+ return;
404
+ this.scheduled = true;
405
+ this.holdStatus(new Promise((resolve) => {
406
+ requestAnimationFrame(() => {
407
+ this.scheduled = false;
408
+ this.align()
409
+ .catch((e) => console.error("bn-grid: aligning the baselines failed", e))
410
+ .finally(resolve);
411
+ });
412
+ }));
413
+ };
196
414
  withStyled.withStyled(this);
197
- withHasError.withComponentStatus(this);
415
+ this.holdStatus = withHasError.withComponentStatus(this);
198
416
  this.errors = withHasError.withHasError(this);
199
417
  this.componentStyle = withStyled.withComponentStyle(this);
200
418
  }
419
+ connectedCallback() {
420
+ var _a;
421
+ this.observed = new WeakSet();
422
+ this.resizeObserver = new ResizeObserver(this.schedule);
423
+ // a child can be added, moved to another slot or replaced, in a morphing preview for example
424
+ this.mutationObserver = new MutationObserver(this.schedule);
425
+ this.mutationObserver.observe(this.element, {
426
+ childList: true,
427
+ subtree: true,
428
+ attributes: true,
429
+ attributeFilter: ["slot"],
430
+ });
431
+ // a caption in a late web font changes its height
432
+ (_a = document.fonts) === null || _a === void 0 ? void 0 : _a.addEventListener("loadingdone", this.schedule);
433
+ }
434
+ disconnectedCallback() {
435
+ var _a, _b, _c;
436
+ (_a = this.resizeObserver) === null || _a === void 0 ? void 0 : _a.disconnect();
437
+ (_b = this.mutationObserver) === null || _b === void 0 ? void 0 : _b.disconnect();
438
+ (_c = document.fonts) === null || _c === void 0 ? void 0 : _c.removeEventListener("loadingdone", this.schedule);
439
+ this.run++;
440
+ }
441
+ /** Captions, headers, gap or style can move a cell without resizing its component. */
442
+ componentDidRender() {
443
+ this.schedule();
444
+ }
445
+ validateChoice(attribute, errId, value, allowed, fallback) {
446
+ if (value === undefined || value === null || value === "") {
447
+ this.errors.remove(errId);
448
+ return fallback;
449
+ }
450
+ if (allowed.includes(value)) {
451
+ this.errors.remove(errId);
452
+ return value;
453
+ }
454
+ this.errors.addOrReplace({
455
+ id: errId,
456
+ type: "error",
457
+ message: `${attribute}: "${value}" is not one of ${allowed.join(", ")}.`,
458
+ });
459
+ return fallback;
460
+ }
461
+ isBaselineMode() {
462
+ return this.resolvedVertical === "baseline" || this.resolvedHorizontal === "baseline";
463
+ }
464
+ /** The first visual component in a slot, or the slotted element itself. */
465
+ visualIn(slot) {
466
+ var _a;
467
+ const slotted = Array.from(this.element.children).find((child) => child.getAttribute("slot") === slot);
468
+ if (!slotted)
469
+ return undefined;
470
+ const isVisual = (el) => el.localName.startsWith("bn-") && !CONFIG_ELEMENTS.has(el.localName);
471
+ if (isVisual(slotted))
472
+ return slotted;
473
+ return (_a = Array.from(slotted.querySelectorAll("*")).find(isVisual)) !== null && _a !== void 0 ? _a : undefined;
474
+ }
475
+ async align() {
476
+ var _a;
477
+ const run = ++this.run;
478
+ if (!this.element.isConnected || !this.isBaselineMode())
479
+ return;
480
+ const { rows, columns } = this.gridConfig;
481
+ const slots = rows.flatMap((row, rowIndex) => columns.map((column, columnIndex) => ({ slot: getSlotName(row, column), row: rowIndex, column: columnIndex })));
482
+ const visuals = slots.map(({ slot }) => this.visualIn(slot));
483
+ await Promise.all(visuals.map((visual) => { var _a; return (_a = visual === null || visual === void 0 ? void 0 : visual.componentOnReady) === null || _a === void 0 ? void 0 : _a.call(visual); }));
484
+ if (run !== this.run)
485
+ return;
486
+ visuals.forEach((visual) => visual && this.observe(visual));
487
+ const baselines = await Promise.all(visuals.map((visual) => typeof (visual === null || visual === void 0 ? void 0 : visual.getBaseline) === "function" ? visual.getBaseline().catch(() => ({})) : Promise.resolve({})));
488
+ if (run !== this.run)
489
+ return;
490
+ const frame = localFrame.localFrameOf(this.element);
491
+ // by value, not by selector: a header id can hold any character
492
+ const wrappers = new Map();
493
+ (_a = this.element.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelectorAll(".grid-slot").forEach((el) => {
494
+ var _a;
495
+ wrappers.set((_a = el.getAttribute("data-slot")) !== null && _a !== void 0 ? _a : "", el);
496
+ });
497
+ const cells = slots.map(({ slot, row, column }, index) => {
498
+ const visual = visuals[index];
499
+ const baseline = baselines[index];
500
+ // what is drawn now, not what is in the state: a render can still be pending
501
+ const wrapper = wrappers.get(slot);
502
+ const applied = (property) => parseFloat((wrapper === null || wrapper === void 0 ? void 0 : wrapper.style.getPropertyValue(property)) || "0") || 0;
503
+ const cell = { slot, row, column, top: applied("padding-top"), left: applied("margin-left") };
504
+ if (visual) {
505
+ const box = frame.toLocal(visual.getBoundingClientRect());
506
+ if (baseline.y !== undefined)
507
+ cell.y = box.y + baseline.y;
508
+ if (baseline.x !== undefined)
509
+ cell.x = box.x + baseline.x;
510
+ }
511
+ return cell;
512
+ });
513
+ const next = baselineOffsets(cells, this.resolvedVertical === "baseline", this.resolvedHorizontal === "baseline");
514
+ if (sameOffsets(next, this.offsets)) {
515
+ this.adjustments = 0;
516
+ return;
517
+ }
518
+ if (this.adjustments >= MAX_ADJUSTMENTS) {
519
+ console.warn("bn-grid: the baselines did not settle; the cells keep their last alignment.");
520
+ // giving up changes nothing, so nothing runs again until the next outside change, which gets a fresh budget
521
+ this.adjustments = 0;
522
+ return;
523
+ }
524
+ this.adjustments++;
525
+ this.offsets = next;
526
+ // check once more after the new offsets are drawn; the status stays held until then
527
+ this.schedule();
528
+ }
529
+ /** A chart redraws inside its shadow roots, where the host and a mutation observer on it see nothing. */
530
+ observe(visual) {
531
+ var _a;
532
+ if (!this.observed.has(visual)) {
533
+ this.observed.add(visual);
534
+ (_a = this.resizeObserver) === null || _a === void 0 ? void 0 : _a.observe(visual);
535
+ }
536
+ const walk = (root) => {
537
+ var _a;
538
+ if (!root)
539
+ return;
540
+ if (!this.observed.has(root)) {
541
+ this.observed.add(root);
542
+ (_a = this.mutationObserver) === null || _a === void 0 ? void 0 : _a.observe(root, {
543
+ childList: true,
544
+ subtree: true,
545
+ attributes: true,
546
+ attributeFilter: ["x1", "y1", "x2", "y2", "x", "y", "width", "height", "transform", "style", "class"],
547
+ });
548
+ }
549
+ root.querySelectorAll("*").forEach((el) => walk(el.shadowRoot));
550
+ };
551
+ walk(visual.shadowRoot);
552
+ }
201
553
  /**
202
554
  * Lazily generates this grid's layout state: host box (context- and
203
555
  * component-relative, CSS px), the grid region and row/column counts. With
204
- * `detail: "full"` the title, every header and every data cell (with its
205
- * slot name) is listed with its geometry.
556
+ * `detail: "full"` the title, every header, every data cell and every
557
+ * caption (with its slot name) is listed with its geometry.
206
558
  *
207
559
  * @param options - `{ detail: "summary" | "full" }`, default `"summary"`
208
560
  */
209
561
  async getLayoutState(options) {
210
562
  var _a, _b, _c, _d;
211
563
  const detail = (_a = options === null || options === void 0 ? void 0 : options.detail) !== null && _a !== void 0 ? _a : "summary";
212
- const origins = diagnostics.originsFor(this.element);
564
+ const origins = localFrame.originsFor(this.element);
213
565
  const fontSizePx = this.componentStyle(($) => { var _a; return ((_a = $["global"]) === null || _a === void 0 ? void 0 : _a["fontSizePx"]) || 13.3333; });
214
566
  const { rows, columns } = this.gridConfig;
215
567
  const state = {
216
568
  version: index$1.LAYOUT_STATE_VERSION,
217
569
  tag: this.element.localName,
218
- id: diagnostics.resolveStandaloneId(this.element),
570
+ id: localFrame.resolveStandaloneId(this.element),
219
571
  slot: (_b = this.element.getAttribute("slot")) !== null && _b !== void 0 ? _b : undefined,
220
- rect: diagnostics.measure(this.element, origins),
572
+ rect: localFrame.measure(this.element, origins),
221
573
  em: { fontSizePx, appliedScaleFactor: 1 },
222
574
  regions: [],
223
575
  metadata: {
@@ -226,11 +578,11 @@ const Grid = class {
226
578
  columnCount: columns.length,
227
579
  cellCount: rows.length * columns.length,
228
580
  },
229
- diagnostics: diagnostics.readDiagnostics(this.element),
581
+ diagnostics: localFrame.readDiagnostics(this.element),
230
582
  };
231
583
  const container = (_c = this.element.shadowRoot) === null || _c === void 0 ? void 0 : _c.querySelector(".grid-container");
232
584
  if (container)
233
- state.regions.push({ id: "grid", rect: diagnostics.measure(container, origins) });
585
+ state.regions.push({ id: "grid", rect: localFrame.measure(container, origins) });
234
586
  if (detail !== "full" || !container) {
235
587
  return state;
236
588
  }
@@ -238,7 +590,7 @@ const Grid = class {
238
590
  const push = (entry) => elements.push(entry);
239
591
  const title = container.querySelector(".grid-title");
240
592
  if (title) {
241
- push({ kind: "gridTitle", label: ((_d = title.textContent) === null || _d === void 0 ? void 0 : _d.trim()) || undefined, rect: diagnostics.measure(title, origins) });
593
+ push({ kind: "gridTitle", label: ((_d = title.textContent) === null || _d === void 0 ? void 0 : _d.trim()) || undefined, rect: localFrame.measure(title, origins) });
242
594
  }
243
595
  container.querySelectorAll(".grid-header-col").forEach((header, index) => {
244
596
  var _a, _b;
@@ -246,7 +598,7 @@ const Grid = class {
246
598
  kind: "gridHeader",
247
599
  columnId: (_a = columns[index]) === null || _a === void 0 ? void 0 : _a.id,
248
600
  label: ((_b = header.textContent) === null || _b === void 0 ? void 0 : _b.trim()) || undefined,
249
- rect: diagnostics.measure(header, origins),
601
+ rect: localFrame.measure(header, origins),
250
602
  });
251
603
  });
252
604
  container.querySelectorAll(".grid-header-row").forEach((header, index) => {
@@ -255,7 +607,7 @@ const Grid = class {
255
607
  kind: "gridHeader",
256
608
  rowId: (_a = rows[index]) === null || _a === void 0 ? void 0 : _a.id,
257
609
  label: ((_b = header.textContent) === null || _b === void 0 ? void 0 : _b.trim()) || undefined,
258
- rect: diagnostics.measure(header, origins),
610
+ rect: localFrame.measure(header, origins),
259
611
  });
260
612
  });
261
613
  // Data cells render row-major (see renderDataCells), so index i maps to
@@ -267,7 +619,16 @@ const Grid = class {
267
619
  rowId: columns.length > 0 ? (_a = rows[Math.floor(index / columns.length)]) === null || _a === void 0 ? void 0 : _a.id : undefined,
268
620
  columnId: columns.length > 0 ? (_b = columns[index % columns.length]) === null || _b === void 0 ? void 0 : _b.id : undefined,
269
621
  slot: (_d = (_c = cell.querySelector("slot")) === null || _c === void 0 ? void 0 : _c.getAttribute("name")) !== null && _d !== void 0 ? _d : undefined,
270
- rect: diagnostics.measure(cell, origins),
622
+ rect: localFrame.measure(cell, origins),
623
+ });
624
+ });
625
+ container.querySelectorAll(".grid-caption").forEach((caption) => {
626
+ var _a, _b, _c, _d;
627
+ push({
628
+ kind: "gridCaption",
629
+ slot: (_c = (_b = (_a = caption.parentElement) === null || _a === void 0 ? void 0 : _a.querySelector("slot")) === null || _b === void 0 ? void 0 : _b.getAttribute("name")) !== null && _c !== void 0 ? _c : undefined,
630
+ label: ((_d = caption.textContent) === null || _d === void 0 ? void 0 : _d.trim()) || undefined,
631
+ rect: localFrame.measure(caption, origins),
271
632
  });
272
633
  });
273
634
  state.elements = elements;
@@ -282,6 +643,11 @@ const Grid = class {
282
643
  componentWillLoad() {
283
644
  this.validateRowHeaders(this.rowHeaders);
284
645
  this.validateColumnHeaders(this.columnHeaders);
646
+ this.validateCellHeight(this.cellHeight);
647
+ this.validateCellWidth(this.cellWidth);
648
+ this.validateCellVerticalAlign(this.cellVerticalAlign);
649
+ this.validateCellHorizontalAlign(this.cellHorizontalAlign);
650
+ this.validateCellCaptions(this.cellCaptions);
285
651
  }
286
652
  updateGridConfig() {
287
653
  this.gridConfig = parseGridConfig(this.rowHeaders, this.columnHeaders);
@@ -300,10 +666,11 @@ const Grid = class {
300
666
  if (this.shouldShowRowHeaders()) {
301
667
  cols.push(this.rowHeaderWidth);
302
668
  }
303
- // Add columns for each data column (auto-size to content)
669
+ // Add columns for each data column: auto-size to content, or all as wide as the widest
304
670
  const numCols = this.gridConfig.columns.length || 1;
305
671
  for (let i = 0; i < numCols; i++) {
306
- cols.push("auto");
672
+ // minmax(0, 1fr): an equal column must not grow past its share to fit wide content
673
+ cols.push(this.resolvedWidth === "equal" ? "minmax(0, 1fr)" : "auto");
307
674
  }
308
675
  return cols.join(" ");
309
676
  }
@@ -317,10 +684,10 @@ const Grid = class {
317
684
  if (this.shouldShowColumnHeaders()) {
318
685
  rows.push("auto");
319
686
  }
320
- // Add rows for each data row (auto-size to content)
687
+ // Add rows for each data row: auto-size to content, or all as high as the highest
321
688
  const numRows = this.gridConfig.rows.length || 1;
322
689
  for (let i = 0; i < numRows; i++) {
323
- rows.push("auto");
690
+ rows.push(this.resolvedHeight === "equal" ? "1fr" : "auto");
324
691
  }
325
692
  return rows.join(" ");
326
693
  }
@@ -377,19 +744,70 @@ const Grid = class {
377
744
  const slotName = getSlotName(row, col);
378
745
  const isNotFirstCol = colIndex > 0;
379
746
  const isNotFirstRow = rowIndex > 0;
380
- cells.push(index.h("div", { key: `cell-${slotName}`, class: "grid-cell", style: {
381
- "grid-column": String(startCol + colIndex),
382
- "grid-row": String(startRow + rowIndex),
383
- "border-left": isNotFirstCol ? borderStyle : "none",
384
- "border-top": isNotFirstRow ? borderStyle : "none",
385
- "padding-left": isNotFirstCol ? `${style.cellPadding + 4}px` : "0",
386
- "padding-top": isNotFirstRow ? `${style.cellPadding + 4}px` : "0",
387
- } }, index.h("slot", { name: slotName })));
747
+ cells.push(index.h("div", { key: `cell-${slotName}`, class: "grid-cell", style: Object.assign({ "grid-column": String(startCol + colIndex), "grid-row": String(startRow + rowIndex), "border-left": isNotFirstCol ? borderStyle : "none", "border-top": isNotFirstRow ? borderStyle : "none", "padding-left": isNotFirstCol ? `${style.cellPadding + 4}px` : "0", "padding-top": isNotFirstRow ? `${style.cellPadding + 4}px` : "0" }, this.cellAlignStyle()) }, this.renderCellContent(slotName, style)));
388
748
  });
389
749
  });
390
750
  }
391
751
  return cells;
392
752
  }
753
+ /** Flex column only when the content is not at the default top left: a block cell stays a block. */
754
+ cellAlignStyle() {
755
+ if (this.resolvedVertical === "top" && this.resolvedHorizontal === "left")
756
+ return {};
757
+ return {
758
+ display: "flex",
759
+ "flex-direction": "column",
760
+ "justify-content": JUSTIFY[this.resolvedVertical],
761
+ "align-items": ALIGN[this.resolvedHorizontal],
762
+ };
763
+ }
764
+ /**
765
+ * The caption, then the slot in a wrapper: auto margins move the wrapper
766
+ * below the caption (the caption stays at the top), and padding or a margin
767
+ * moves it onto the baseline. Without alignment the wrapper is a plain block.
768
+ */
769
+ renderCellContent(slotName, style) {
770
+ const text = this.captions[slotName];
771
+ const caption = text !== undefined ? (index.h("div", { class: "grid-caption", style: {
772
+ "font-size": `${style.captionFontSize}px`,
773
+ "font-weight": String(style.captionFontWeight),
774
+ color: style.captionColor,
775
+ "margin-bottom": `${style.captionGap}px`,
776
+ "align-self": "flex-start",
777
+ } }, text)) : null;
778
+ // the slot always has the same parent: a chart observes its parent's size and keeps that element
779
+ const wrapper = {};
780
+ if (this.resolvedVertical !== "top" || this.resolvedHorizontal !== "left") {
781
+ // as wide as the cell, so a chart measures the cell; the horizontal alignment happens inside
782
+ wrapper["align-self"] = "stretch";
783
+ if (this.resolvedHorizontal === "center" || this.resolvedHorizontal === "right") {
784
+ wrapper.display = "flex";
785
+ wrapper["flex-direction"] = "column";
786
+ wrapper["align-items"] = ALIGN[this.resolvedHorizontal];
787
+ }
788
+ }
789
+ if (this.resolvedVertical === "center") {
790
+ wrapper["margin-top"] = "auto";
791
+ wrapper["margin-bottom"] = "auto";
792
+ }
793
+ else if (this.resolvedVertical === "bottom") {
794
+ wrapper["margin-top"] = "auto";
795
+ }
796
+ const offset = this.offsets[slotName];
797
+ if (offset === null || offset === void 0 ? void 0 : offset.bottom)
798
+ wrapper["margin-top"] = "auto";
799
+ if (offset === null || offset === void 0 ? void 0 : offset.top)
800
+ wrapper["padding-top"] = `${offset.top}px`;
801
+ // margins, not padding: a chart measures this box, and every box of a column keeps the same width
802
+ if (offset === null || offset === void 0 ? void 0 : offset.left)
803
+ wrapper["margin-left"] = `${offset.left}px`;
804
+ if (offset === null || offset === void 0 ? void 0 : offset.right)
805
+ wrapper["margin-right"] = `${offset.right}px`;
806
+ return [
807
+ caption,
808
+ index.h("div", { class: "grid-slot", "data-slot": slotName, style: wrapper }, index.h("slot", { name: slotName })),
809
+ ];
810
+ }
393
811
  getFontStyles() {
394
812
  return this.componentStyle(($) => {
395
813
  var _a, _b, _c, _d;
@@ -402,13 +820,11 @@ const Grid = class {
402
820
  });
403
821
  }
404
822
  render() {
405
- const gridContainerStyle = {
406
- display: "inline-grid",
407
- "grid-template-columns": this.getGridTemplateColumns(),
408
- "grid-template-rows": this.getGridTemplateRows(),
409
- gap: this.cellGap,
410
- };
411
- return (index.h(index.Host, { key: '866de326e2061abf7412529359321353c1bf39d8', style: this.getFontStyles() }, index.h("div", { key: 'e3f6e16ecf4ae07f947fb35d1a10c16fddefd994', class: "grid-container", style: gridContainerStyle }, this.renderTitle(), this.renderColumnHeaders(), this.renderDataCells()), index.h("slot", { key: '8300412918e5d35ebfcaabdb4aa1ca05e4242707' })));
823
+ // Equal columns share the width of the grid's container. In an inline grid they
824
+ // would only be as wide as their content, and charts measure that width.
825
+ const fill = this.resolvedWidth === "equal";
826
+ const gridContainerStyle = Object.assign(Object.assign({ display: fill ? "grid" : "inline-grid" }, (fill ? { width: "100%" } : {})), { "grid-template-columns": this.getGridTemplateColumns(), "grid-template-rows": this.getGridTemplateRows(), gap: this.cellGap });
827
+ return (index.h(index.Host, { key: '3fcfe5d215a02a65652c00e37a2873377b708043', style: fill ? Object.assign(Object.assign({}, this.getFontStyles()), { display: "block" }) : this.getFontStyles() }, index.h("div", { key: '55a2ae64a80a2f660601eaddbb5bd6e90e224796', class: "grid-container", style: gridContainerStyle }, this.renderTitle(), this.renderColumnHeaders(), this.renderDataCells()), index.h("slot", { key: '1c47b472d38b8e12a42e7f1609466681cdde98f3' })));
412
828
  }
413
829
  get element() { return index.getElement(this); }
414
830
  static get watchers() { return {
@@ -417,6 +833,21 @@ const Grid = class {
417
833
  }],
418
834
  "columnHeaders": [{
419
835
  "validateColumnHeaders": 0
836
+ }],
837
+ "cellHeight": [{
838
+ "validateCellHeight": 0
839
+ }],
840
+ "cellWidth": [{
841
+ "validateCellWidth": 0
842
+ }],
843
+ "cellVerticalAlign": [{
844
+ "validateCellVerticalAlign": 0
845
+ }],
846
+ "cellHorizontalAlign": [{
847
+ "validateCellHorizontalAlign": 0
848
+ }],
849
+ "cellCaptions": [{
850
+ "validateCellCaptions": 0
420
851
  }]
421
852
  }; }
422
853
  };
@@ -1,8 +1,8 @@
1
1
  'use strict';
2
2
 
3
3
  var index = require('./index-DGis1BzT.js');
4
- var withStyled = require('./withStyled-70D4Isgt.js');
5
- var withHasError = require('./withHasError-CqvcS23z.js');
4
+ var withStyled = require('./withStyled-Ds3e64Nz.js');
5
+ var withHasError = require('./withHasError-3kR2tdhJ.js');
6
6
 
7
7
  const bnImageCss = () => `:host{display:inline-block;position:relative;overflow:hidden}img{max-width:100%;height:auto}`;
8
8
 
@@ -1,8 +1,8 @@
1
1
  'use strict';
2
2
 
3
3
  var index = require('./index-DGis1BzT.js');
4
- var withBodyObserver = require('./withBodyObserver-BK4idxqG.js');
5
- var withHasError = require('./withHasError-CqvcS23z.js');
4
+ var withBodyObserver = require('./withBodyObserver-B1_hmuUz.js');
5
+ var withHasError = require('./withHasError-3kR2tdhJ.js');
6
6
  var queryError = require('./queryError-BZjnIW_w.js');
7
7
 
8
8
  const bnInternationalizationCss = () => `bn-internationalization{display:none}`;
@@ -1,8 +1,8 @@
1
1
  'use strict';
2
2
 
3
3
  var index = require('./index-DGis1BzT.js');
4
- var withBodyObserver = require('./withBodyObserver-BK4idxqG.js');
5
- var withHasError = require('./withHasError-CqvcS23z.js');
4
+ var withBodyObserver = require('./withBodyObserver-B1_hmuUz.js');
5
+ var withHasError = require('./withHasError-3kR2tdhJ.js');
6
6
 
7
7
  const bnRulesetCss = () => `bn-ruleset{display:none}`;
8
8