@ng-native/fabric 0.6.0 → 0.7.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.
package/dist/css.d.ts CHANGED
@@ -299,6 +299,11 @@ export interface DeferredDeclaration {
299
299
  readonly unit: 'em' | 'vw' | 'vh' | 'vmin' | 'vmax';
300
300
  readonly factor: number;
301
301
  readonly offset?: number;
302
+ /**
303
+ * A unitless line-height: the node renders `factor` em, and what it hands down is the number,
304
+ * which each text under it multiplies its own font size by. See `LineHeightMultiple`.
305
+ */
306
+ readonly multiple?: true;
302
307
  };
303
308
  /**
304
309
  * A structured value - a transform list, a shadow, a filter - with lengths like `compute`'s
package/dist/css.js CHANGED
@@ -1226,6 +1226,40 @@ function emptyCacheFor(epoch, generation) {
1226
1226
  tokens: NO_TOKENS,
1227
1227
  };
1228
1228
  }
1229
+ function isMultiple(value) {
1230
+ return typeof value === 'object' && value !== null && 'multiple' in value;
1231
+ }
1232
+ /** A line-height as points, for a node of font size `size`: what an em of it comes to. */
1233
+ function lineHeightPoints(line, size) {
1234
+ const points = line.multiple * (typeof size === 'number' ? size : DEFAULT_FONT_SIZE);
1235
+ return Math.round(points * 1000) / 1000;
1236
+ }
1237
+ /** A node's style with a unitless line-height it set or inherited worked out against its font size. */
1238
+ function settleLineHeight(style) {
1239
+ const line = style['lineHeight'];
1240
+ if (isMultiple(line))
1241
+ style['lineHeight'] = lineHeightPoints(line, style['fontSize']);
1242
+ }
1243
+ /** The styles of nodes with no rules, by the map they inherit, for one that hands down a multiple. */
1244
+ const unstyledStyles = new WeakMap();
1245
+ /**
1246
+ * The style of a node no rule matches: what it inherits, with a unitless line-height worked out
1247
+ * against its font size, which an inline style can set. The same object where there is none.
1248
+ */
1249
+ function unstyledStyle(inherited, inline) {
1250
+ const line = inherited['lineHeight'];
1251
+ if (!isMultiple(line))
1252
+ return inherited;
1253
+ const size = inline?.['fontSize'];
1254
+ if (typeof size === 'number')
1255
+ return { ...inherited, lineHeight: lineHeightPoints(line, size) };
1256
+ let style = unstyledStyles.get(inherited);
1257
+ if (!style) {
1258
+ style = { ...inherited, lineHeight: lineHeightPoints(line, inherited['fontSize']) };
1259
+ unstyledStyles.set(inherited, style);
1260
+ }
1261
+ return style;
1262
+ }
1229
1263
  /**
1230
1264
  * What this node's children inherit: the parent's map, overlaid with any inheritable value the
1231
1265
  * node set itself. Copied on first write only, so a node that sets none hands the same object on
@@ -1722,7 +1756,7 @@ export class StyleResolver {
1722
1756
  generation: this.generation,
1723
1757
  context: {},
1724
1758
  parentContext,
1725
- style: parentInherited,
1759
+ style: unstyledStyle(parentInherited, inline),
1726
1760
  inherited: inline ? inheritFrom(parentInherited, inline) : parentInherited,
1727
1761
  tokens,
1728
1762
  };
@@ -1892,6 +1926,7 @@ export class StyleResolver {
1892
1926
  if (own['pointerEvents'] === 'inherit')
1893
1927
  delete own['pointerEvents'];
1894
1928
  const style = { ...parentInherited, ...own };
1929
+ settleLineHeight(style);
1895
1930
  const inherited = decorate(style, inheritFrom(parentInherited, own), own);
1896
1931
  const rtl = (style['direction'] ?? this.conditions.direction) === 'rtl';
1897
1932
  const important = importantNames(result, () => TWIN[rtl ? 'rtl' : 'ltr']);
@@ -2233,9 +2268,11 @@ export class StyleResolver {
2233
2268
  }
2234
2269
  /** A length relative to the viewport or to the font size in scope. */
2235
2270
  computed(declaration, own, parentInherited) {
2236
- const { unit, factor, offset = 0 } = declaration.compute;
2271
+ const { unit, factor, offset = 0, multiple } = declaration.compute;
2237
2272
  if (unit !== 'em')
2238
2273
  return this.viewportLength(unit, factor) + offset;
2274
+ if (multiple && !offset)
2275
+ return { multiple: factor };
2239
2276
  // The font size in scope. On `font-size` itself that is the inherited size rather than the
2240
2277
  // one being computed, which is what makes a nested `1.5em` compound as on the web.
2241
2278
  const base = declaration.props.includes('fontSize')