@chialab/pdfjs-lib 1.0.0-alpha.21 → 1.0.0-alpha.23

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.
@@ -25118,7 +25118,7 @@ var SvgCanvasContext = class {
25118
25118
  constructor(width, height, canvas) {
25119
25119
  __publicField(this, "_width");
25120
25120
  __publicField(this, "_height");
25121
- __publicField(this, "_canvas");
25121
+ __publicField(this, "_canvas", null);
25122
25122
  __publicField(this, "_ctx", null);
25123
25123
  __publicField(this, "_currentStyle", {
25124
25124
  strokeStyle: "#000000",
@@ -25147,7 +25147,7 @@ var SvgCanvasContext = class {
25147
25147
  __publicField(this, "_transformMatrixStack", []);
25148
25148
  __publicField(this, "_root");
25149
25149
  __publicField(this, "_defs");
25150
- __publicField(this, "_currentGroup");
25150
+ __publicField(this, "_currentGroup", null);
25151
25151
  __publicField(this, "_currentElement", null);
25152
25152
  __publicField(this, "_currentMarked", null);
25153
25153
  __publicField(this, "_transformMatrix", new DOMMatrix([1, 0, 0, 1, 0, 0]));
@@ -25177,6 +25177,9 @@ var SvgCanvasContext = class {
25177
25177
  this.resetTransform();
25178
25178
  }
25179
25179
  get canvas() {
25180
+ if (!this._canvas) {
25181
+ throw new Error("Canvas is destroyed");
25182
+ }
25180
25183
  return this._canvas;
25181
25184
  }
25182
25185
  get fillStyle() {
@@ -25275,13 +25278,13 @@ var SvgCanvasContext = class {
25275
25278
  resize(width, height) {
25276
25279
  this._width = width;
25277
25280
  this._height = height;
25278
- this._canvas.width = width;
25279
- this._canvas.height = height;
25281
+ this.canvas.width = width;
25282
+ this.canvas.height = height;
25280
25283
  this._root.attrs.width = width;
25281
25284
  this._root.attrs.height = height;
25282
25285
  }
25283
25286
  save() {
25284
- this._groupStack.push(this._currentGroup);
25287
+ this._groupStack.push(this._currentGroup ?? this._root);
25285
25288
  this._currentGroup = this._ensureTransformationGroup();
25286
25289
  this._styleStack.push(this._getStyleState());
25287
25290
  this._transformMatrixStack.push(this.getTransform());
@@ -25753,10 +25756,10 @@ var SvgCanvasContext = class {
25753
25756
  return;
25754
25757
  }
25755
25758
  if (!this._currentMarked) {
25756
- this._addNode(node, this._currentGroup);
25759
+ this._addNode(node, this._currentGroup ?? this._root);
25757
25760
  return;
25758
25761
  }
25759
- let group = this._currentGroup;
25762
+ let group = this._currentGroup ?? this._root;
25760
25763
  if (this._currentMarked.elements.length === 0) {
25761
25764
  const markedStackToAdd = [this._currentMarked];
25762
25765
  let i;
@@ -25997,11 +26000,27 @@ var SvgCanvasContext = class {
25997
26000
  }
25998
26001
  _clearCanvas() {
25999
26002
  this._defs.children = [];
26000
- this._root.children = [this._defs];
26003
+ this._addNode(this._defs, this._root);
26001
26004
  this._currentGroup = this._root;
26002
26005
  this._groupStack = [];
26003
26006
  this._parents.clear();
26004
26007
  }
26008
+ destroy() {
26009
+ this.canvas.width = 0;
26010
+ this.canvas.height = 0;
26011
+ this._styleStack = [];
26012
+ this._groupStack = [];
26013
+ this._markedStack = [];
26014
+ this._transformMatrixStack = [];
26015
+ this._ctx = null;
26016
+ this._canvas = null;
26017
+ this._currentGroup = null;
26018
+ this._currentElement = null;
26019
+ this._currentMarked = null;
26020
+ this._currentPosition = {};
26021
+ this._transformMatrix = new DOMMatrix();
26022
+ this._parents.clear();
26023
+ }
26005
26024
  };
26006
26025
  async function createSvgContext(width, height) {
26007
26026
  const canvas = await createCanvas(width, height);
@@ -26020,6 +26039,11 @@ async function toSvgNode(ctx) {
26020
26039
  async function toSvgString(ctx) {
26021
26040
  return renderSvgNode(await toSvgNode(ctx));
26022
26041
  }
26042
+ function destroySvgContext(ctx) {
26043
+ if (ctx instanceof SvgCanvasContext) {
26044
+ ctx.destroy();
26045
+ }
26046
+ }
26023
26047
 
26024
26048
  // src/lib/PDFPageProxy.ts
26025
26049
  async function loadNodeCanvasFactory() {
@@ -26871,6 +26895,7 @@ export {
26871
26895
  createSvgContext,
26872
26896
  createTextLayer,
26873
26897
  createValidAbsoluteUrl,
26898
+ destroySvgContext,
26874
26899
  fetchData,
26875
26900
  getDocument,
26876
26901
  getFilenameFromUrl,
@@ -158,8 +158,10 @@ export declare class SvgCanvasContext {
158
158
  protected _addPathCommand(command: string): void;
159
159
  protected _applyText(text: string, x: number, y: number, action: 'fill'): void;
160
160
  protected _clearCanvas(): void;
161
+ destroy(): void;
161
162
  }
162
163
  export declare function createSvgContext(width: number, height: number): Promise<CanvasRenderingContext2D>;
163
164
  export declare function toSvgNode(ctx: CanvasRenderingContext2D): Promise<SvgRoot>;
164
165
  export declare function toSvgString(ctx: CanvasRenderingContext2D): Promise<string>;
166
+ export declare function destroySvgContext(ctx: CanvasRenderingContext2D): void;
165
167
  export {};
@@ -24162,7 +24162,7 @@ var SvgCanvasContext = class {
24162
24162
  constructor(width, height, canvas) {
24163
24163
  __publicField(this, "_width");
24164
24164
  __publicField(this, "_height");
24165
- __publicField(this, "_canvas");
24165
+ __publicField(this, "_canvas", null);
24166
24166
  __publicField(this, "_ctx", null);
24167
24167
  __publicField(this, "_currentStyle", {
24168
24168
  strokeStyle: "#000000",
@@ -24191,7 +24191,7 @@ var SvgCanvasContext = class {
24191
24191
  __publicField(this, "_transformMatrixStack", []);
24192
24192
  __publicField(this, "_root");
24193
24193
  __publicField(this, "_defs");
24194
- __publicField(this, "_currentGroup");
24194
+ __publicField(this, "_currentGroup", null);
24195
24195
  __publicField(this, "_currentElement", null);
24196
24196
  __publicField(this, "_currentMarked", null);
24197
24197
  __publicField(this, "_transformMatrix", new DOMMatrix([1, 0, 0, 1, 0, 0]));
@@ -24221,6 +24221,9 @@ var SvgCanvasContext = class {
24221
24221
  this.resetTransform();
24222
24222
  }
24223
24223
  get canvas() {
24224
+ if (!this._canvas) {
24225
+ throw new Error("Canvas is destroyed");
24226
+ }
24224
24227
  return this._canvas;
24225
24228
  }
24226
24229
  get fillStyle() {
@@ -24319,13 +24322,13 @@ var SvgCanvasContext = class {
24319
24322
  resize(width, height) {
24320
24323
  this._width = width;
24321
24324
  this._height = height;
24322
- this._canvas.width = width;
24323
- this._canvas.height = height;
24325
+ this.canvas.width = width;
24326
+ this.canvas.height = height;
24324
24327
  this._root.attrs.width = width;
24325
24328
  this._root.attrs.height = height;
24326
24329
  }
24327
24330
  save() {
24328
- this._groupStack.push(this._currentGroup);
24331
+ this._groupStack.push(this._currentGroup ?? this._root);
24329
24332
  this._currentGroup = this._ensureTransformationGroup();
24330
24333
  this._styleStack.push(this._getStyleState());
24331
24334
  this._transformMatrixStack.push(this.getTransform());
@@ -24797,10 +24800,10 @@ var SvgCanvasContext = class {
24797
24800
  return;
24798
24801
  }
24799
24802
  if (!this._currentMarked) {
24800
- this._addNode(node, this._currentGroup);
24803
+ this._addNode(node, this._currentGroup ?? this._root);
24801
24804
  return;
24802
24805
  }
24803
- let group = this._currentGroup;
24806
+ let group = this._currentGroup ?? this._root;
24804
24807
  if (this._currentMarked.elements.length === 0) {
24805
24808
  const markedStackToAdd = [this._currentMarked];
24806
24809
  let i;
@@ -25041,11 +25044,27 @@ var SvgCanvasContext = class {
25041
25044
  }
25042
25045
  _clearCanvas() {
25043
25046
  this._defs.children = [];
25044
- this._root.children = [this._defs];
25047
+ this._addNode(this._defs, this._root);
25045
25048
  this._currentGroup = this._root;
25046
25049
  this._groupStack = [];
25047
25050
  this._parents.clear();
25048
25051
  }
25052
+ destroy() {
25053
+ this.canvas.width = 0;
25054
+ this.canvas.height = 0;
25055
+ this._styleStack = [];
25056
+ this._groupStack = [];
25057
+ this._markedStack = [];
25058
+ this._transformMatrixStack = [];
25059
+ this._ctx = null;
25060
+ this._canvas = null;
25061
+ this._currentGroup = null;
25062
+ this._currentElement = null;
25063
+ this._currentMarked = null;
25064
+ this._currentPosition = {};
25065
+ this._transformMatrix = new DOMMatrix();
25066
+ this._parents.clear();
25067
+ }
25049
25068
  };
25050
25069
  async function createSvgContext(width, height) {
25051
25070
  const canvas = await createCanvas(width, height);
@@ -25064,6 +25083,11 @@ async function toSvgNode(ctx) {
25064
25083
  async function toSvgString(ctx) {
25065
25084
  return renderSvgNode(await toSvgNode(ctx));
25066
25085
  }
25086
+ function destroySvgContext(ctx) {
25087
+ if (ctx instanceof SvgCanvasContext) {
25088
+ ctx.destroy();
25089
+ }
25090
+ }
25067
25091
 
25068
25092
  // src/lib/PDFPageProxy.ts
25069
25093
  async function loadNodeCanvasFactory() {
@@ -25915,6 +25939,7 @@ export {
25915
25939
  createSvgContext,
25916
25940
  createTextLayer,
25917
25941
  createValidAbsoluteUrl,
25942
+ destroySvgContext,
25918
25943
  fetchData,
25919
25944
  getDocument,
25920
25945
  getFilenameFromUrl,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@chialab/pdfjs-lib",
3
3
  "description": "A custom Mozilla's PDF.js build with better Node support and extras.",
4
- "version": "1.0.0-alpha.21",
4
+ "version": "1.0.0-alpha.23",
5
5
  "type": "module",
6
6
  "author": "Chialab <dev@chialab.it>",
7
7
  "license": "MIT",