pa_font 0.3.1 → 0.3.2

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/paFont.js CHANGED
@@ -3328,8 +3328,6 @@ function layoutParagraph(fontInstance, text, options = {}, state = {}) {
3328
3328
  y: finalLayoutBox.contentBox.y,
3329
3329
  width: textWidth,
3330
3330
  height: textHeight,
3331
- viewportHeight: finalLayoutBox.contentBox.h,
3332
- maxScrollTop: Math.max(0, textHeight - finalLayoutBox.contentBox.h),
3333
3331
  lineCount: lines.length,
3334
3332
  bbox: textBBox,
3335
3333
  contentBox: { ...finalLayoutBox.contentBox },
@@ -3356,12 +3354,9 @@ function normalizeParagraphOptions(fontInstance, options = {}) {
3356
3354
  const width = normalizeDimension(options.width);
3357
3355
  const height = normalizeDimension(options.height);
3358
3356
  const gap = normalizeGap(options.gap);
3359
- const overflow = normalizeEnum(options.overflow, ["visible", "hidden"], "visible");
3360
- const overflowY = resolveOverflowY(options.overflowY, overflow);
3361
3357
  if (options.width != null && width == null) throw new TypeError("font.paragraph() option \"width\" must be a positive number.");
3362
3358
  if (options.height != null && height == null) throw new TypeError("font.paragraph() option \"height\" must be a positive number.");
3363
3359
  if (options.gap != null && gap == null) throw new TypeError("font.paragraph() option \"gap\" must be a non-negative number.");
3364
- if (overflowY === "scroll" && height == null) throw new TypeError("font.paragraph() option \"height\" is required when \"overflowY\" is \"scroll\".");
3365
3360
  const font = resolveCanvasFont(fontInstance, textOptions.size, options);
3366
3361
  return {
3367
3362
  ...textOptions,
@@ -3399,8 +3394,7 @@ function normalizeParagraphOptions(fontInstance, options = {}) {
3399
3394
  "break-all",
3400
3395
  "keep-all"
3401
3396
  ], wrapDefaults.wordBreak),
3402
- overflow,
3403
- overflowY,
3397
+ overflow: normalizeEnum(options.overflow, ["visible", "hidden"], "visible"),
3404
3398
  textOverflow: normalizeNullableEnum(options.textOverflow, ["clip", "ellipsis"], null),
3405
3399
  maxLines: normalizeMaxLines(options.maxLines),
3406
3400
  ellipsis: normalizeEllipsis(options.ellipsis),
@@ -3589,7 +3583,7 @@ function applyOverflowClamping(lines, options, layoutBox, measureWidth) {
3589
3583
  const contentWidth = layoutBox.contentWidth;
3590
3584
  const result = lines.map((line) => ({ ...line }));
3591
3585
  let lineLimit = options.maxLines;
3592
- if (shouldClampLinesToHeight(options) && layoutBox.clipContentHeight != null) {
3586
+ if (options.overflow === "hidden" && layoutBox.clipContentHeight != null) {
3593
3587
  const visibleLineCount = countVisibleLinesForHeight(result, options, layoutBox.clipContentHeight);
3594
3588
  lineLimit = lineLimit == null ? visibleLineCount : Math.min(lineLimit, visibleLineCount);
3595
3589
  }
@@ -3814,7 +3808,7 @@ function finalizeLayoutBox(layoutBox, options, textHeight) {
3814
3808
  x: layoutBox.contentX,
3815
3809
  y: layoutBox.contentY,
3816
3810
  w: layoutBox.contentWidth,
3817
- h: shouldClipToContentHeight(options) ? contentHeight : textHeight
3811
+ h: options.overflow === "hidden" ? contentHeight : textHeight
3818
3812
  }
3819
3813
  };
3820
3814
  }
@@ -3830,19 +3824,6 @@ function normalizeNullableEnum(value, supported, fallback) {
3830
3824
  if (value == null) return fallback;
3831
3825
  return typeof value === "string" && supported.includes(value) ? value : fallback;
3832
3826
  }
3833
- function resolveOverflowY(value, overflow) {
3834
- return normalizeEnum(value, [
3835
- "visible",
3836
- "hidden",
3837
- "scroll"
3838
- ], overflow === "hidden" ? "hidden" : "visible");
3839
- }
3840
- function shouldClampLinesToHeight(options) {
3841
- return options.overflowY === "hidden";
3842
- }
3843
- function shouldClipToContentHeight(options) {
3844
- return options.overflow === "hidden" || options.overflowY === "hidden" || options.overflowY === "scroll";
3845
- }
3846
3827
  function normalizeEllipsis(value) {
3847
3828
  if (value === false) return false;
3848
3829
  if (typeof value === "string") return value;
@@ -4279,7 +4260,6 @@ var paParagraph = class paParagraph {
4279
4260
  if (!ctx || typeof ctx.fillText !== "function") throw new TypeError("drawText() expects a CanvasRenderingContext2D.");
4280
4261
  const fill = options.fill !== false;
4281
4262
  const stroke = options.stroke === true;
4282
- const scrollTop = clampScrollTop(options.scrollTop, this.metrics.maxScrollTop);
4283
4263
  if (!fill && !stroke) return;
4284
4264
  this._syncLayoutWithContext(ctx);
4285
4265
  ctx.save();
@@ -4288,13 +4268,12 @@ var paParagraph = class paParagraph {
4288
4268
  ctx.textBaseline = "alphabetic";
4289
4269
  if (options.fillStyle != null) ctx.fillStyle = options.fillStyle;
4290
4270
  if (options.strokeStyle != null) ctx.strokeStyle = options.strokeStyle;
4291
- if (shouldClipParagraph(this.options) && this._state.layoutBox?.clipBox) {
4271
+ if (this.options.overflow === "hidden" && this._state.layoutBox?.clipBox) {
4292
4272
  const clipBox = this._state.layoutBox.clipBox;
4293
4273
  ctx.beginPath();
4294
4274
  ctx.rect(clipBox.x, clipBox.y, clipBox.w, clipBox.h);
4295
4275
  ctx.clip();
4296
4276
  }
4297
- if (scrollTop > 0) ctx.translate(0, -scrollTop);
4298
4277
  this._state.lines.forEach((line) => {
4299
4278
  line.fragments.forEach((fragment) => {
4300
4279
  if (fill) ctx.fillText(fragment.text, fragment.x, line.baseline);
@@ -4345,8 +4324,6 @@ var paParagraph = class paParagraph {
4345
4324
  this.metrics = {
4346
4325
  ...state.metrics,
4347
4326
  bbox: { ...state.metrics.bbox },
4348
- viewportHeight: state.metrics.viewportHeight,
4349
- maxScrollTop: state.metrics.maxScrollTop,
4350
4327
  contentBox: state.metrics.contentBox ? { ...state.metrics.contentBox } : void 0,
4351
4328
  paddingBox: state.metrics.paddingBox ? { ...state.metrics.paddingBox } : void 0,
4352
4329
  marginBox: state.metrics.marginBox ? { ...state.metrics.marginBox } : void 0,
@@ -4441,13 +4418,6 @@ function normalizeParagraphPointOptions(options = {}) {
4441
4418
  layout: options.layout ?? "current"
4442
4419
  };
4443
4420
  }
4444
- function shouldClipParagraph(options) {
4445
- return options.overflow === "hidden" || options.overflowY === "hidden" || options.overflowY === "scroll";
4446
- }
4447
- function clampScrollTop(value, maxScrollTop) {
4448
- if (!Number.isFinite(value) || value <= 0) return 0;
4449
- return Math.min(Number(value), maxScrollTop ?? 0);
4450
- }
4451
4421
  //#endregion
4452
4422
  //#region src/paFont/paFont.js
4453
4423
  var browserFontRegistrationId = 0;