@mathscan/math-exercise-engine 1.2.3 → 1.2.4

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.mjs CHANGED
@@ -265,6 +265,10 @@ const HEX_COLOR_REGEX = /^#([0-9A-Fa-f]{3}|[0-9A-Fa-f]{6})$/;
265
265
  const isNumberLineHighlightColor = (value) => NUMBER_LINE_HIGHLIGHT_COLORS.includes(value) || HEX_COLOR_REGEX.test(value);
266
266
  const highlightColorMessage = (block) => `${block}: color must be one of ${NUMBER_LINE_HIGHLIGHT_COLORS.join(", ")} or a hex value (e.g. "#3B82F6")`;
267
267
  const NUMBER_LINE_DRAG_MODES = ["axis", "inputs"];
268
+ const DEFAULT_TABLE_BORDER_COLOR = "#7c6cf2";
269
+ const isTableBorderColor = (value) => value.toLowerCase() === "transparent" || HEX_COLOR_REGEX.test(value);
270
+ const TABLE_BORDER_COLOR_ERROR = 'TABLE: bordercolor must be "transparent" or a hex value (e.g. "#E67E22" or "#F00")';
271
+ const TableBorderColorSchema = z.string({ message: TABLE_BORDER_COLOR_ERROR }).refine(isTableBorderColor, { message: TABLE_BORDER_COLOR_ERROR }).default(DEFAULT_TABLE_BORDER_COLOR);
268
272
  function getFractionKey(widgetId, part) {
269
273
  return `${widgetId}__${part}`;
270
274
  }
@@ -2534,12 +2538,14 @@ function createTableRow(cells, backgroundColor) {
2534
2538
  const TableBlockSchema = z.object({
2535
2539
  type: z.literal(AST_TYPES.TABLE_BLOCK),
2536
2540
  cols: z.number().int().positive(),
2541
+ borderColor: TableBorderColorSchema,
2537
2542
  rows: z.array(TableRowSchema).min(1)
2538
2543
  });
2539
- function createTableBlock(cols, rows) {
2544
+ function createTableBlock(cols, rows, borderColor) {
2540
2545
  return TableBlockSchema.parse({
2541
2546
  type: AST_TYPES.TABLE_BLOCK,
2542
2547
  cols,
2548
+ borderColor,
2543
2549
  rows
2544
2550
  });
2545
2551
  }
@@ -3484,8 +3490,10 @@ class NaturalDSLVisitor extends BaseCstVisitor {
3484
3490
  table(ctx) {
3485
3491
  const params = this.visit(ctx.parameterList);
3486
3492
  const cols = params.cols;
3493
+ const borderColorParam = params.bordercolor;
3494
+ const borderColor = borderColorParam === void 0 ? void 0 : String(borderColorParam);
3487
3495
  const rows = ctx.row.map((r) => this.visit(r));
3488
- return createTableBlock(cols, rows);
3496
+ return createTableBlock(cols, rows, borderColor);
3489
3497
  }
3490
3498
  row(ctx) {
3491
3499
  const params = ctx.parameterList ? this.visit(ctx.parameterList) : {};
@@ -4280,6 +4288,7 @@ const TableItemSchema = z.object({
4280
4288
  id: z.string(),
4281
4289
  type: z.literal(JSON_TYPES.TABLE),
4282
4290
  cols: z.number().int().positive(),
4291
+ borderColor: TableBorderColorSchema,
4283
4292
  rows: z.array(TableRowItemSchema)
4284
4293
  });
4285
4294
  const NumberLinePositionItemSchema = z.object({
@@ -10864,6 +10873,7 @@ function transformTable(table, idGenerator, inlineDragIds) {
10864
10873
  id: idGenerator.generate(JSON_TYPES.TABLE),
10865
10874
  type: JSON_TYPES.TABLE,
10866
10875
  cols: table.cols,
10876
+ borderColor: table.borderColor,
10867
10877
  rows
10868
10878
  };
10869
10879
  }
@@ -20625,7 +20635,10 @@ const LayoutRenderer = ({
20625
20635
  )) });
20626
20636
  case JSON_TYPES.TABLE: {
20627
20637
  const totalRows = item.rows.length;
20628
- return /* @__PURE__ */ jsx("div", { className: "exercise-table-container", children: /* @__PURE__ */ jsx("table", { className: "exercise-table", children: /* @__PURE__ */ jsx("tbody", { children: item.rows.map((row, rowIndex) => /* @__PURE__ */ jsx("tr", { className: "exercise-table-row", style: { backgroundColor: row.backgroundColor }, children: row.cells.map((cell) => {
20638
+ const tableStyle = {
20639
+ "--exercise-table-border-color": item.borderColor ?? DEFAULT_TABLE_BORDER_COLOR
20640
+ };
20641
+ return /* @__PURE__ */ jsx("div", { className: "exercise-table-container", style: tableStyle, children: /* @__PURE__ */ jsx("table", { className: "exercise-table", children: /* @__PURE__ */ jsx("tbody", { children: item.rows.map((row, rowIndex) => /* @__PURE__ */ jsx("tr", { className: "exercise-table-row", style: { backgroundColor: row.backgroundColor }, children: row.cells.map((cell) => {
20629
20642
  const rowspan = cell.rowspan || 1;
20630
20643
  const isLastRow = rowIndex + rowspan - 1 >= totalRows - 1;
20631
20644
  return /* @__PURE__ */ jsx(
@@ -21332,6 +21345,7 @@ export {
21332
21345
  ColorTextInlineSchema,
21333
21346
  ColorTextSchema,
21334
21347
  ContentBlockSchema,
21348
+ DEFAULT_TABLE_BORDER_COLOR,
21335
21349
  DisplayInlineNodeSchema,
21336
21350
  DragOptionsJSONSchema,
21337
21351
  DragOptionsToolSchema,