@pairdraw/dom-css 0.19.2 → 0.20.0

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.
@@ -1,13 +1,13 @@
1
1
  import { serializeHTML } from "./behaviours/states/tailwind.js";
2
2
  import { isEqual } from "es-toolkit/predicate";
3
3
  import { isValid, toUint8Array } from "js-base64";
4
- import { DEFAULT_FONT_FAMILY, TRANSPARENT } from "@pairdraw/scene-graph/constants";
4
+ import { TRANSPARENT } from "@pairdraw/scene-graph/constants";
5
5
  import { computeImageHash } from "@pairdraw/scene-graph/images";
6
6
  import { autoLayoutSizingFields, fillSizingFields, layoutSizing, textAutoResizeFor } from "@pairdraw/scene-graph/layout";
7
7
  import { countBy } from "es-toolkit/array";
8
8
  import { blurRadiusForSigma } from "@pairdraw/scene-graph/geometry";
9
9
  import { pick } from "es-toolkit";
10
- import { parseCSSAlignItems, parseCSSAlignSelf, parseCSSBackgroundImages, parseCSSColor, parseCSSFlexDirection, parseCSSFontFamilies, parseCSSFontFamily, parseCSSJustifyContent, parseCSSLetterSpacing, parseCSSLineHeight, parseCSSNumber, parseCSSShadows } from "@pairdraw/scene-graph/css";
10
+ import { GENERIC_FONT_FAMILIES_BY_CLASS, genericFontFamilyClass, parseCSSAlignItems, parseCSSAlignSelf, parseCSSBackgroundImages, parseCSSColor, parseCSSFlexDirection, parseCSSFontFamilies, parseCSSFontFamily, parseCSSJustifyContent, parseCSSLetterSpacing, parseCSSLineHeight, parseCSSNumber, parseCSSShadows } from "@pairdraw/scene-graph/css";
11
11
  import { SceneGraph } from "@pairdraw/scene-graph";
12
12
  import { normalizeEffects } from "@pairdraw/scene-graph/effects";
13
13
  import { textLayerName } from "@pairdraw/scene-graph/node-defaults";
@@ -466,35 +466,8 @@ function mergeCSSText(...parts) {
466
466
  }
467
467
  //#endregion
468
468
  //#region src/import/fonts.ts
469
- /** CSS generic families, by the concrete face class they stand for. */
470
- const GENERIC_FAMILIES = {
471
- "sans-serif": "sans-serif",
472
- "ui-sans-serif": "sans-serif",
473
- "system-ui": "sans-serif",
474
- "-apple-system": "sans-serif",
475
- blinkmacsystemfont: "sans-serif",
476
- serif: "serif",
477
- "ui-serif": "serif",
478
- monospace: "monospace",
479
- "ui-monospace": "monospace"
480
- };
481
- /** Known system faces of each class, best first. The app bundles Inter for sans-serif. */
482
- const DEFAULT_FAMILIES = {
483
- "sans-serif": [DEFAULT_FONT_FAMILY],
484
- serif: [
485
- "Georgia",
486
- "Times New Roman",
487
- "Times"
488
- ],
489
- monospace: [
490
- "Menlo",
491
- "SF Mono",
492
- "Consolas",
493
- "Courier New"
494
- ]
495
- };
496
469
  function defaultFamily(kind, options) {
497
- const candidates = DEFAULT_FAMILIES[kind];
470
+ const candidates = GENERIC_FONT_FAMILIES_BY_CLASS[kind];
498
471
  return (options.isAvailable ? candidates.find((family) => options.isAvailable?.(family)) : null) ?? candidates[0];
499
472
  }
500
473
  /**
@@ -504,8 +477,8 @@ function defaultFamily(kind, options) {
504
477
  */
505
478
  function resolveFontFamilyStack(value, options = {}) {
506
479
  for (const family of parseCSSFontFamilies(value)) {
507
- const generic = GENERIC_FAMILIES[family.trim().toLowerCase()];
508
- if (generic) return defaultFamily(generic, options);
480
+ const kind = genericFontFamilyClass(family);
481
+ if (kind) return defaultFamily(kind, options);
509
482
  if (options.isAvailable && !options.isAvailable(family)) continue;
510
483
  return family;
511
484
  }
@@ -857,9 +830,12 @@ const IMAGE_SOURCE_URL_KEY = "image-source-url";
857
830
  * by half its blur length, which the canvas draws from the radius that gives that sigma.
858
831
  */
859
832
  function cssShadows(value) {
860
- return parseCSSShadows(value).map((effect) => effect.type === "SHADER" ? effect : {
861
- ...effect,
862
- radius: blurRadiusForSigma(effect.radius / 2)
833
+ return parseCSSShadows(value).map((effect) => {
834
+ if (effect.type !== "DROP_SHADOW" && effect.type !== "INNER_SHADOW") return effect;
835
+ return {
836
+ ...effect,
837
+ radius: blurRadiusForSigma(effect.radius / 2)
838
+ };
863
839
  });
864
840
  }
865
841
  /**
@@ -1105,11 +1081,11 @@ function applyImageFill(graph, node, element, style) {
1105
1081
  const source = element.attrs.src;
1106
1082
  const bytes = bytesFromDataURL(source);
1107
1083
  if (!bytes) {
1108
- if (source) node.pluginData.push({
1084
+ if (source) node.pluginData = [...node.pluginData, {
1109
1085
  pluginId: DOM_CSS_PLUGIN_ID,
1110
1086
  key: IMAGE_SOURCE_URL_KEY,
1111
1087
  value: source
1112
- });
1088
+ }];
1113
1089
  return;
1114
1090
  }
1115
1091
  const imageHash = computeImageHash(bytes);