@hyperbook/markdown 0.64.0 → 0.64.1

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.
@@ -381,6 +381,22 @@ hyperbook.python = (function () {
381
381
  const numeric = Number(value);
382
382
  return Number.isFinite(numeric) ? numeric : fallback;
383
383
  };
384
+ const toPlainBoolean = (value, fallback = false) => {
385
+ if (value === null || value === undefined) return fallback;
386
+ if (typeof value === "boolean") return value;
387
+ if (typeof value === "number") return value !== 0;
388
+ if (typeof value === "bigint") return value !== 0n;
389
+ if (typeof value === "string") {
390
+ const normalized = value.trim().toLowerCase();
391
+ if (!normalized) return fallback;
392
+ if (["false", "0", "no", "off"].includes(normalized)) return false;
393
+ if (["true", "1", "yes", "on"].includes(normalized)) return true;
394
+ }
395
+ if (typeof value.toJs === "function") {
396
+ return toPlainBoolean(value.toJs({ pyproxies: [] }), fallback);
397
+ }
398
+ return Boolean(value);
399
+ };
384
400
  const fontSizeToCanvasUnits = (value) => {
385
401
  const numeric = toPlainNumber(value, Number.NaN);
386
402
  if (!Number.isFinite(numeric) || numeric === 0) {
@@ -1026,28 +1042,21 @@ hyperbook.python = (function () {
1026
1042
  let writeMove = move;
1027
1043
  let writeAlign = align;
1028
1044
  let writeFont = font;
1029
-
1030
- if (isWriteKwargsObject(writeAlign)) {
1031
- const kwargs = toPlainObject(writeAlign);
1032
- if (kwargs) {
1033
- if (hasOwn(kwargs, "arg")) writeText = kwargs.arg;
1034
- else if (hasOwn(kwargs, "text")) writeText = kwargs.text;
1035
- if (hasOwn(kwargs, "move")) writeMove = kwargs.move;
1036
- if (hasOwn(kwargs, "align")) writeAlign = kwargs.align;
1037
- if (hasOwn(kwargs, "font")) writeFont = kwargs.font;
1038
- }
1039
- }
1040
- if (isWriteKwargsObject(writeFont)) {
1041
- const kwargs = toPlainObject(writeFont);
1042
- if (kwargs) {
1043
- if (hasOwn(kwargs, "arg")) writeText = kwargs.arg;
1044
- else if (hasOwn(kwargs, "text")) writeText = kwargs.text;
1045
- if (hasOwn(kwargs, "move")) writeMove = kwargs.move;
1046
- if (hasOwn(kwargs, "align")) writeAlign = kwargs.align;
1047
- if (hasOwn(kwargs, "font")) writeFont = kwargs.font;
1048
- }
1049
- writeFont = null;
1050
- }
1045
+ const applyWriteKwargs = (candidate) => {
1046
+ if (!isWriteKwargsObject(candidate)) return;
1047
+ const kwargs = toPlainObject(candidate);
1048
+ if (!kwargs) return;
1049
+ if (hasOwn(kwargs, "arg")) writeText = kwargs.arg;
1050
+ else if (hasOwn(kwargs, "text")) writeText = kwargs.text;
1051
+ if (hasOwn(kwargs, "move")) writeMove = kwargs.move;
1052
+ if (hasOwn(kwargs, "align")) writeAlign = kwargs.align;
1053
+ if (hasOwn(kwargs, "font")) writeFont = kwargs.font;
1054
+ };
1055
+ applyWriteKwargs(writeText);
1056
+ applyWriteKwargs(writeMove);
1057
+ applyWriteKwargs(writeAlign);
1058
+ applyWriteKwargs(writeFont);
1059
+ if (isWriteKwargsObject(writeFont)) writeFont = null;
1051
1060
 
1052
1061
  let family = currentFontFamily;
1053
1062
  let size = fontSize;
@@ -1080,7 +1089,7 @@ hyperbook.python = (function () {
1080
1089
  },
1081
1090
  ],
1082
1091
  });
1083
- if (Boolean(writeMove)) {
1092
+ if (toPlainBoolean(writeMove, false)) {
1084
1093
  const metrics = measureTurtleText(String(writeText), family, size, style);
1085
1094
  const left = metrics.left || 0;
1086
1095
  const right = metrics.right || metrics.width || 0;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hyperbook/markdown",
3
- "version": "0.64.0",
3
+ "version": "0.64.1",
4
4
  "author": "Mike Barkmin",
5
5
  "homepage": "https://github.com/openpatch/hyperbook#readme",
6
6
  "license": "MIT",