pdfkit 0.17.1 → 0.17.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/CHANGELOG.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  ### Unreleased
4
4
 
5
+ ### [v0.17.2] - 2025-08-30
6
+
7
+ - Fix rendering lists that spans across pages
8
+
5
9
  ### [v0.17.1] - 2025-05-02
6
10
 
7
11
  - Fix null values in table cells rendering as `[object Object]`
package/js/pdfkit.es.js CHANGED
@@ -2981,12 +2981,14 @@ class LineWrapper extends EventEmitter {
2981
2981
  }
2982
2982
  emitLine();
2983
2983
  if (PDFNumber(this.document.y + lh) > this.maxY) {
2984
+ this.emit('sectionEnd', options, this);
2984
2985
  const shouldContinue = this.nextSection();
2985
2986
  if (!shouldContinue) {
2986
2987
  wc = 0;
2987
2988
  buffer = '';
2988
2989
  return false;
2989
2990
  }
2991
+ this.emit('sectionStart', options, this);
2990
2992
  }
2991
2993
  if (bk.required) {
2992
2994
  this.spaceLeft = this.lineWidth;
@@ -3019,7 +3021,6 @@ class LineWrapper extends EventEmitter {
3019
3021
  }
3020
3022
  }
3021
3023
  nextSection(options) {
3022
- this.emit('sectionEnd', options, this);
3023
3024
  if (++this.column > this.columns) {
3024
3025
  if (this.height != null) {
3025
3026
  return false;
@@ -3038,7 +3039,6 @@ class LineWrapper extends EventEmitter {
3038
3039
  this.document.y = this.startY;
3039
3040
  this.emit('columnBreak', options, this);
3040
3041
  }
3041
- this.emit('sectionStart', options, this);
3042
3042
  return true;
3043
3043
  }
3044
3044
  }
@@ -3046,6 +3046,15 @@ class LineWrapper extends EventEmitter {
3046
3046
  const {
3047
3047
  number
3048
3048
  } = PDFObject;
3049
+ function formatListLabel(n, listType) {
3050
+ if (listType === 'numbered') {
3051
+ return `${n}.`;
3052
+ }
3053
+ var letter = String.fromCharCode((n - 1) % 26 + 65);
3054
+ var times = Math.floor((n - 1) / 26 + 1);
3055
+ var text = Array(times + 1).join(letter);
3056
+ return `${text}.`;
3057
+ }
3049
3058
  var TextMixin = {
3050
3059
  initText() {
3051
3060
  this._line = this._line.bind(this);
@@ -3223,7 +3232,7 @@ var TextMixin = {
3223
3232
  this.y = y;
3224
3233
  return height;
3225
3234
  },
3226
- list(list, x, y, options, wrapper) {
3235
+ list(list, x, y, options) {
3227
3236
  options = this._initOptions(x, y, options);
3228
3237
  const listType = options.listType || 'bullet';
3229
3238
  const unit = Math.round(this._font.ascender / 1000 * this._fontSize);
@@ -3253,19 +3262,8 @@ var TextMixin = {
3253
3262
  }
3254
3263
  };
3255
3264
  flatten(list);
3256
- const label = function (n) {
3257
- switch (listType) {
3258
- case 'numbered':
3259
- return `${n}.`;
3260
- case 'lettered':
3261
- var letter = String.fromCharCode((n - 1) % 26 + 65);
3262
- var times = Math.floor((n - 1) / 26 + 1);
3263
- var text = Array(times + 1).join(letter);
3264
- return `${text}.`;
3265
- }
3266
- };
3267
3265
  const drawListItem = function (listItem, i) {
3268
- wrapper = new LineWrapper(this, options);
3266
+ const wrapper = new LineWrapper(this, options);
3269
3267
  wrapper.on('line', this._line);
3270
3268
  level = 1;
3271
3269
  wrapper.once('firstLine', () => {
@@ -3300,7 +3298,7 @@ var TextMixin = {
3300
3298
  break;
3301
3299
  case 'numbered':
3302
3300
  case 'lettered':
3303
- var text = label(numbers[i - 1]);
3301
+ var text = formatListLabel(numbers[i - 1], listType);
3304
3302
  this._fragment(text, this.x - indent, this.y, options);
3305
3303
  break;
3306
3304
  }
@@ -3373,11 +3371,11 @@ var TextMixin = {
3373
3371
  let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
3374
3372
  let wrapper = arguments.length > 2 ? arguments[2] : undefined;
3375
3373
  this._fragment(text, this.x, this.y, options);
3376
- const lineGap = options.lineGap || this._lineGap || 0;
3377
- if (!wrapper) {
3378
- this.x += this.widthOfString(text, options);
3379
- } else {
3374
+ if (wrapper) {
3375
+ const lineGap = options.lineGap || this._lineGap || 0;
3380
3376
  this.y += this.currentLineHeight(true) + lineGap;
3377
+ } else {
3378
+ this.x += this.widthOfString(text, options);
3381
3379
  }
3382
3380
  },
3383
3381
  _fragment(text, x, y, options) {