@pairdraw/design-jsx 0.20.0 → 0.21.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.
@@ -17,7 +17,7 @@ import { parseCSSGridTracks, parseCSSNumber, parseCSSShadows } from "@pairdraw/s
17
17
  import { autoLayoutSizingFields, fillSizingFields, parseAutoLayoutDirection, parseCounterAxisAlign, parsePrimaryAxisAlign } from "@pairdraw/scene-graph/layout";
18
18
  import { normalizeEffects } from "@pairdraw/scene-graph/effects";
19
19
  import { finiteNumberSchema } from "@pairdraw/scene-graph/primitives";
20
- import { setInstanceOverride } from "@pairdraw/scene-graph/instances/overrides";
20
+ import { ownInstanceOverrides, setInstanceOverride } from "@pairdraw/scene-graph/instances/overrides";
21
21
  import { createDefaultNode, textLayerName } from "@pairdraw/scene-graph/node-defaults";
22
22
  import { parsePluginVectorPath, parseSVGPathData } from "@pairdraw/scene-graph/parse-path";
23
23
  import { mergeVectorNetworks, transformVectorNetwork } from "@pairdraw/scene-graph/vector-network";
@@ -123,12 +123,12 @@ function forNormalize(effect) {
123
123
  return shadow;
124
124
  }
125
125
  /** `effects` takes structured effects; `shadow` appends its shadows and `blur` a layer blur. */
126
- function applyEffectOverrides(props, o) {
126
+ function applyEffectOverrides(props, o, profile = "srgb") {
127
127
  if (Array.isArray(props.effects) && props.effects.length > 0) {
128
128
  const effects = parseScriptInput("effects", effectsSchema, props.effects).map(forNormalize);
129
129
  o.effects = normalizeEffects(effects);
130
130
  }
131
- const shadows = typeof props.shadow === "string" ? parseCSSShadows(props.shadow) : [];
131
+ const shadows = typeof props.shadow === "string" ? parseCSSShadows(props.shadow, profile) : [];
132
132
  if (shadows.length > 0) o.effects = [...o.effects ?? [], ...shadows];
133
133
  if (typeof props.blur === "number") o.effects = [...o.effects ?? [], {
134
134
  type: "LAYER_BLUR",
@@ -232,10 +232,10 @@ function applySizeOverrides(props, o, parentLayout) {
232
232
  * Sets the layer's fills, moving each shader paint's preset into the layer's plugin data,
233
233
  * where a shader paint keeps it.
234
234
  */
235
- function setFills(values, o) {
235
+ function setFills(values, o, profile) {
236
236
  const shaders = [];
237
- const fills = values.filter((value) => typeof value !== "string" || tryParseColor(value) !== null).map((value) => {
238
- const fill = fillFromValue(value);
237
+ const fills = values.filter((value) => typeof value !== "string" || tryParseColor(value, profile) !== null).map((value) => {
238
+ const fill = fillFromValue(value, profile);
239
239
  if (!isShaderFill(fill)) return fill;
240
240
  const { shader, ...paint } = fill;
241
241
  if (paint.imageHash) shaders.push(shader);
@@ -245,17 +245,17 @@ function setFills(values, o) {
245
245
  o.fills = fills;
246
246
  if (shaders.length > 0) o.pluginData = withShaderPaints({ pluginData: o.pluginData ?? [] }, fills, shaders);
247
247
  }
248
- function applyFillOverride(props, o) {
248
+ function applyFillOverride(props, o, profile) {
249
249
  if (Array.isArray(props.fills) && props.fills.length === 0) {
250
250
  o.fills = [];
251
251
  return;
252
252
  }
253
253
  if (Array.isArray(props.fills)) {
254
- setFills(props.fills.filter(isFillValue), o);
254
+ setFills(props.fills.filter(isFillValue), o, profile);
255
255
  return;
256
256
  }
257
257
  const bg = designJSXProp(props, "bg");
258
- if (isFillValue(bg)) setFills([bg], o);
258
+ if (isFillValue(bg)) setFills([bg], o, profile);
259
259
  }
260
260
  function applyCornerOverrides(props, o) {
261
261
  const rounded = props.rounded ?? props.cornerRadius ?? props.borderRadius;
@@ -269,9 +269,9 @@ function applyCornerOverrides(props, o) {
269
269
  }
270
270
  if (props.cornerSmoothing !== void 0) o.cornerSmoothing = props.cornerSmoothing;
271
271
  }
272
- function applyVisualOverrides(props, o) {
273
- applyFillOverride(props, o);
274
- applyStrokeOverrides(props, o);
272
+ function applyVisualOverrides(props, o, profile) {
273
+ applyFillOverride(props, o, profile);
274
+ applyStrokeOverrides(props, o, profile);
275
275
  applyCornerOverrides(props, o);
276
276
  if (props.opacity !== void 0) o.opacity = props.opacity;
277
277
  applyTransformOverrides(props, o);
@@ -399,7 +399,7 @@ function applyLayoutOverrides(props, o, w, h, isText, parentLayout) {
399
399
  applyPaddingOverrides(props, o);
400
400
  if (props.grow !== void 0) o.layoutGrow = props.grow;
401
401
  }
402
- function applyTextStyleOverrides(props, o) {
402
+ function applyTextStyleOverrides(props, o, profile) {
403
403
  const fontSize = designJSXProp(props, "size");
404
404
  if (typeof fontSize === "number") o.fontSize = fontSize;
405
405
  const fontFamily = designJSXProp(props, "font");
@@ -408,14 +408,14 @@ function applyTextStyleOverrides(props, o) {
408
408
  if (typeof props.italic === "boolean") o.italic = props.italic;
409
409
  if (typeof weight === "number") o.fontWeight = weight;
410
410
  else if (typeof weight === "string") o.fontWeight = WEIGHT_MAP[weight] ?? 400;
411
- if (typeof props.color === "string" || isColor(props.color)) o.fills = [colorToFill(props.color)];
411
+ if (typeof props.color === "string" || isColor(props.color)) o.fills = [colorToFill(props.color, profile)];
412
412
  const lineHeight = props.lineHeight === "auto" ? null : textLengthProp(props.lineHeight);
413
413
  if (lineHeight !== void 0) o.lineHeight = lineHeight;
414
414
  const letterSpacing = textLengthProp(props.letterSpacing);
415
415
  if (letterSpacing) o.letterSpacing = letterSpacing;
416
416
  const textDecoration = TEXT_DECORATION.parse(props.textDecoration);
417
417
  if (textDecoration) o.textDecoration = textDecoration;
418
- applyTextDetailOverrides(props, o);
418
+ applyTextDetailOverrides(props, o, profile);
419
419
  const textCase = TEXT_CASE.parse(props.textCase);
420
420
  if (textCase) o.textCase = textCase;
421
421
  if (props.maxLines !== void 0) {
@@ -441,8 +441,8 @@ function applyTextAutoResize(props, o, parentLayout) {
441
441
  else if (hasExplicitWidth || isInsideAutoLayout && fillsParent) o.textAutoResize = "HEIGHT";
442
442
  else o.textAutoResize = "WIDTH_AND_HEIGHT";
443
443
  }
444
- function applyTextOverrides(props, o, parentLayout) {
445
- applyTextStyleOverrides(props, o);
444
+ function applyTextOverrides(props, o, parentLayout, profile) {
445
+ applyTextStyleOverrides(props, o, profile);
446
446
  const direction = parseDirection(props.dir);
447
447
  if (direction) o.textDirection = direction;
448
448
  applyTextAutoResize(props, o, parentLayout);
@@ -484,15 +484,15 @@ function shapeOverrides(nodeType, props) {
484
484
  }
485
485
  return o;
486
486
  }
487
- function propsToOverrides(props, isText, parentLayout) {
487
+ function propsToOverrides(props, isText, parentLayout, profile = "srgb") {
488
488
  const layer = readLayerProps(normalizeStyleProps(props));
489
489
  const o = {};
490
490
  if (layer.name) o.name = layer.name;
491
491
  const { w, h } = applySizeOverrides(layer, o, parentLayout);
492
- applyVisualOverrides(layer, o);
492
+ applyVisualOverrides(layer, o, profile);
493
493
  applyLayoutOverrides(layer, o, w, h, isText, parentLayout);
494
- if (isText) applyTextOverrides(layer, o, parentLayout);
495
- applyEffectOverrides(layer, o);
494
+ if (isText) applyTextOverrides(layer, o, parentLayout, profile);
495
+ applyEffectOverrides(layer, o, profile);
496
496
  applyStateOverrides(layer, o);
497
497
  return o;
498
498
  }
@@ -766,7 +766,7 @@ function renderOwnLayerElement(graph, tree, parentId, element) {
766
766
  });
767
767
  const parentLayout = graph.getNode(parentId)?.layoutMode ?? "NONE";
768
768
  const layer = omitBy({
769
- ...propsToOverrides(readElementProps(element.layer, props), false, parentLayout),
769
+ ...propsToOverrides(readElementProps(element.layer, props), false, parentLayout, graph.documentColorSpace),
770
770
  ...modes && { variableModes: modes }
771
771
  }, (value) => value === void 0);
772
772
  const node = element.render(graph, {
@@ -914,7 +914,7 @@ async function renderInstanceNode(graph, tree, parentId, refs) {
914
914
  throw new Error(`<Instance> component not found: ${typeof ref === "string" || typeof ref === "number" ? String(ref) : ""}`);
915
915
  }
916
916
  const overrides = {
917
- ...propsToOverrides(props, false, parentLayout),
917
+ ...propsToOverrides(props, false, parentLayout, graph.documentColorSpace),
918
918
  ...layerMetadata(modes, bound.references)
919
919
  };
920
920
  const layout = overrides.layoutMode ?? component.layoutMode;
@@ -928,7 +928,7 @@ async function renderInstanceNode(graph, tree, parentId, refs) {
928
928
  }
929
929
  const instance = graph.createInstance(component.id, parentId, overrides) ?? graph.createNode("FRAME", parentId);
930
930
  try {
931
- for (const [field, value] of Object.entries(overrides)) setInstanceOverride(instance.instanceOverrides, instance.id, instance.id, field, value);
931
+ for (const [field, value] of Object.entries(overrides)) setInstanceOverride(ownInstanceOverrides(instance), instance.id, instance.id, field, value);
932
932
  graph.updateNode(instance.id, { instanceOverrides: instance.instanceOverrides });
933
933
  applyBindings(graph, instance.id, bindings);
934
934
  applyInstanceOverrides(graph, instance, tree.props.overrides);
@@ -969,7 +969,7 @@ function applyInstanceOverrides(graph, instance, overridesProp) {
969
969
  const child = descendants.find((n) => n.name === childName);
970
970
  if (!child || !(prop in child)) continue;
971
971
  graph.updateNode(child.id, { [prop]: value });
972
- setInstanceOverride(instance.instanceOverrides, instance.id, child.id, prop, value);
972
+ setInstanceOverride(ownInstanceOverrides(instance), instance.id, child.id, prop, value);
973
973
  mutated = true;
974
974
  }
975
975
  if (mutated) graph.updateNode(instance.id, { instanceOverrides: instance.instanceOverrides });
@@ -1009,12 +1009,12 @@ function elementOverrides(graph, nodeType, tree, parentId) {
1009
1009
  };
1010
1010
  const { props, bindings } = preparePropsForRender(graph, bound.props, isText, layer);
1011
1011
  const overrides = {
1012
- ...propsToOverrides(props, isText, parentLayout),
1012
+ ...propsToOverrides(props, isText, parentLayout, graph.documentColorSpace),
1013
1013
  ...shapeOverrides(nodeType, props),
1014
1014
  ...layerMetadata(modes, bound.references)
1015
1015
  };
1016
1016
  if (isText) {
1017
- const spanOverrides = (spanProps) => propsToOverrides(preparePropsForRender(graph, spanProps, true, layer).props, true, "NONE");
1017
+ const spanOverrides = (spanProps) => propsToOverrides(preparePropsForRender(graph, spanProps, true, layer).props, true, "NONE", graph.documentColorSpace);
1018
1018
  Object.assign(overrides, textContentFields(tree, props, overrides, spanOverrides));
1019
1019
  if (overrides.name) overrides.autoRename = false;
1020
1020
  else if (overrides.text !== void 0) overrides.name = textLayerName("TEXT", overrides.text);