@muhammara/native-core 7.0.0 → 7.1.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.
@@ -132,10 +132,22 @@ function resolveFontSize(options = {}, fallback) {
132
132
  return size;
133
133
  }
134
134
 
135
+ /**
136
+ * Remove the breakable whitespace that ends a text; a non-breaking space
137
+ * (U+00A0) stays, as in Wasm.
138
+ * @private
139
+ * @param {string} value - The text.
140
+ * @returns {string} The trimmed text.
141
+ */
142
+ function trimBreakableEnd(value) {
143
+ return value.replace(/(?:(?!\u00a0)\s)+$/, "");
144
+ }
145
+
135
146
  exports.ANNOTATION_PREFIX = ANNOTATION_PREFIX;
136
147
  exports.PAGE_CONTEXT_STATE = PAGE_CONTEXT_STATE;
137
148
  exports.cloneOptions = cloneOptions;
138
149
  exports.resolveFontSize = resolveFontSize;
150
+ exports.trimBreakableEnd = trimBreakableEnd;
139
151
  exports.appendPDFPageFromPDFWithAnnotations =
140
152
  appendPDFPageFromPDFWithAnnotations;
141
153
  exports.appendPDFPagesFromPDFWithAnnotations =
@@ -1,4 +1,3 @@
1
- const muhammara = require("../muhammara");
2
1
  const { Colorspace } = require("../recipe-constants");
3
2
 
4
3
  /**
@@ -62,7 +61,7 @@ exports._strokePolyline = function _strokePolyline(points, options) {
62
61
  // edited page resumes into a new context, so read the context afterwards.
63
62
  const pathOptions = this._getPathOptions(options);
64
63
  const context = this.pageContext;
65
- pathOptions.type = muhammara.DrawingPathType.STROKE;
64
+ pathOptions.type = this.muhammara.DrawingPathType.STROKE;
66
65
 
67
66
  if (pathOptions.stroke !== undefined) {
68
67
  pathOptions.color = pathOptions.stroke;
@@ -27,7 +27,7 @@
27
27
  * @param {number} [options.opacity] - The opacity
28
28
  * @param {number[]} [options.dash] - The dash pattern [dashSize, gapSize] or [dashAndGapSize]
29
29
  * @param {number} [options.dashPhase] - distance into dash pattern at which to start dash (default: 0, immediately)
30
- * @param {number} [options.rotation] - Accept: +/- 0 through 360. Default: 0
30
+ * @param {number} [options.rotation] - Clockwise rotation in degrees, +/- 0 through 360. Default: 0
31
31
  * @param {number[]} [options.rotationOrigin] - [originX, originY] Default: x, y
32
32
  * @param {Recipe.LineCap} [options.lineCap] - open line end style, a `Recipe.LineCap` value (default: 'round')
33
33
  * @param {Recipe.LineJoin} [options.lineJoin] - joined line end style, a `Recipe.LineJoin` value (default: 'round')
@@ -13,7 +13,6 @@
13
13
  // PercentColor component values range from 1 to 100.
14
14
 
15
15
  const { linkPdf } = require("./annotation");
16
- const muhammara = require("../muhammara");
17
16
  const { miterLimitOption } = require("../recipe-options");
18
17
 
19
18
  /**
@@ -44,7 +43,7 @@ exports.circle = function circle(x, y, radius, options = {}) {
44
43
 
45
44
  if (options.fill) {
46
45
  const pathOptions = this._getPathOptions(options, nx, ny);
47
- pathOptions.type = muhammara.DrawingPathType.FILL;
46
+ pathOptions.type = this.muhammara.DrawingPathType.FILL;
48
47
 
49
48
  if (pathOptions.fill !== undefined) {
50
49
  pathOptions.color = pathOptions.fill;
@@ -72,7 +71,7 @@ exports.circle = function circle(x, y, radius, options = {}) {
72
71
  }
73
72
  if (options.stroke || options.color || !options.fill) {
74
73
  const pathOptions = this._getPathOptions(options);
75
- pathOptions.type = muhammara.DrawingPathType.STROKE;
74
+ pathOptions.type = this.muhammara.DrawingPathType.STROKE;
76
75
 
77
76
  if (pathOptions.stroke !== undefined) {
78
77
  pathOptions.color = pathOptions.stroke;
@@ -129,7 +128,7 @@ exports.circle = function circle(x, y, radius, options = {}) {
129
128
  * @param {number} [options.lineWidth] - The line width
130
129
  * @param {number} [options.opacity] - The opacity
131
130
  * @param {number[]} [options.dash] - The dash style [number, number]
132
- * @param {number} [options.rotation] - Accept: +/- 0 through 360. Default: 0
131
+ * @param {number} [options.rotation] - Clockwise rotation in degrees, +/- 0 through 360. Default: 0
133
132
  * @param {number[]} [options.rotationOrigin] - [originX, originY] Default: x, y
134
133
  * @param {number|number[]} [options.borderRadius] - Radius size for rounded corners.
135
134
  * When a one to four number array can be used to give specific sizees to each corner.
@@ -152,7 +151,7 @@ exports.rectangle = function rectangle(x, y, width, height, options = {}) {
152
151
  pathOptions.useGivenCoords = options.useGivenCoords;
153
152
 
154
153
  if (options.fill) {
155
- pathOptions.type = muhammara.DrawingPathType.FILL;
154
+ pathOptions.type = this.muhammara.DrawingPathType.FILL;
156
155
 
157
156
  if (pathOptions.fill !== undefined) {
158
157
  pathOptions.color = pathOptions.fill;
@@ -188,7 +187,7 @@ exports.rectangle = function rectangle(x, y, width, height, options = {}) {
188
187
  }
189
188
 
190
189
  if (options.stroke || options.color || !options.fill) {
191
- pathOptions.type = muhammara.DrawingPathType.STROKE;
190
+ pathOptions.type = this.muhammara.DrawingPathType.STROKE;
192
191
 
193
192
  // The fill above may have replaced the color; stroke with `color`.
194
193
  colorModel =
@@ -362,7 +361,7 @@ function drawRoundedRectangle(
362
361
  * @param {number} [options.lineWidth] - The line width
363
362
  * @param {number} [options.opacity] - The opacity
364
363
  * @param {number[]} [options.dash] - The dash style [number, number]
365
- * @param {number} [options.rotation] - Accept: +/- 0 through 360. Default: 0
364
+ * @param {number} [options.rotation] - Clockwise rotation in degrees, +/- 0 through 360. Default: 0
366
365
  * @param {number[]} [options.rotationOrigin] - [originX, originY] Default: x, y
367
366
  * @returns {Recipe} The recipe instance.
368
367
  * @throws {TypeError} If no page is active.
@@ -544,7 +543,7 @@ function drawArc(ctx, x, y, radius, startAngle, endAngle, fromCenter = false) {
544
543
  * @param {number} [options.lineWidth] - The line width
545
544
  * @param {number} [options.opacity] - The opacity
546
545
  * @param {number[]} [options.dash] - The dash style [number, number]
547
- * @param {number} [options.rotation=0] - Accept: +/- 0 through 360.
546
+ * @param {number} [options.rotation=0] - Clockwise rotation in degrees, +/- 0 through 360.
548
547
  * @param {number[]} [options.rotationOrigin] - [originX, originY] Default: x, y
549
548
  * @returns {Recipe} The recipe instance.
550
549
  * @throws {TypeError} If no page is active.
@@ -320,7 +320,7 @@ var TextWrap = Object.freeze({
320
320
  CLIP: "clip",
321
321
  /** Drop the words that do not fit. */
322
322
  TRIM: "trim",
323
- /** Replace the text that does not fit with "...". */
323
+ /** Replace the text that does not fit with "…". */
324
324
  ELLIPSIS: "ellipsis",
325
325
  });
326
326
 
@@ -0,0 +1,29 @@
1
+ Copyright (c) 1997,1998,2002,2007 Adobe Systems Incorporated
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a
4
+ copy of this documentation file to use, copy, publish, distribute,
5
+ sublicense, and/or sell copies of the documentation, and to permit
6
+ others to do the same, provided that:
7
+ - No modification, editing or other alteration of this document is
8
+ allowed; and
9
+ - The above copyright notice and this permission notice shall be
10
+ included in all copies of the documentation.
11
+
12
+ Permission is hereby granted, free of charge, to any person obtaining a
13
+ copy of this documentation file, to create their own derivative works
14
+ from the content of this document to use, copy, publish, distribute,
15
+ sublicense, and/or sell the derivative works, and to permit others to do
16
+ the same, provided that the derived work is not represented as being a
17
+ copy or version of this document.
18
+
19
+ Adobe shall not be liable to any party for any loss of revenue or profit
20
+ or for indirect, incidental, special, consequential, or other similar
21
+ damages, whether based on tort (including without limitation negligence
22
+ or strict liability), contract or other legal or equitable grounds even
23
+ if Adobe has been advised or had reason to know of the possibility of
24
+ such damages. The Adobe materials are provided on an "AS IS" basis.
25
+ Adobe specifically disclaims all express, statutory, or implied
26
+ warranties relating to the Adobe materials, including but not limited to
27
+ those concerning merchantability or fitness for a particular purpose or
28
+ non-infringement of any third party rights regarding the Adobe
29
+ materials.
package/muhammara.d.ts CHANGED
@@ -89,29 +89,74 @@ declare namespace muhammara {
89
89
  * no passwords are given.
90
90
  * @param originalPdfPath - The source PDF path.
91
91
  * @param newPdfPath - The output path.
92
- * @param options - The source password and the new encryption settings.
92
+ * @param options - The source password and the new encryption settings;
93
+ * `null` means no options.
93
94
  * @throws {TypeError} If the arguments are wrong, one side is a path and the
94
95
  * other a stream, or the PDF cannot be recrypted.
95
96
  */
96
97
  export function recrypt(
97
98
  originalPdfPath: FilePath,
98
99
  newPdfPath: FilePath,
99
- options?: PDFRecryptOptions,
100
+ options?: PDFRecryptOptions | null,
100
101
  ): void;
101
102
  /**
102
103
  * Writes a copy of a PDF stream with new encryption settings, or decrypted
103
104
  * when no passwords are given.
104
105
  * @param originalPdfStream - The source PDF.
105
106
  * @param newPdfStream - The output stream.
106
- * @param options - The source password and the new encryption settings.
107
+ * @param options - The source password and the new encryption settings;
108
+ * `null` means no options.
107
109
  * @throws {TypeError} If the arguments are wrong or the PDF cannot be
108
110
  * recrypted.
109
111
  */
110
112
  export function recrypt(
111
113
  originalPdfStream: PDFRStreamForFile | PDFRStreamForBuffer,
112
114
  newPdfStream: PDFWStreamForFile | PDFWStreamForBuffer,
113
- options?: PDFRecryptOptions,
115
+ options?: PDFRecryptOptions | null,
114
116
  ): void;
117
+ /**
118
+ * Like `recrypt()`, but re-encrypts on libuv's thread pool and returns a
119
+ * promise, so the event loop keeps running. A thread's jobs run one at a
120
+ * time, in call order, and its waiting jobs do not hold pool threads; jobs
121
+ * from different threads run in parallel. Relative paths are resolved when
122
+ * called, naming the files `recrypt()` would open at that moment.
123
+ * @param originalPdfPath - The source PDF path.
124
+ * @param newPdfPath - The output path.
125
+ * @param options - The source password and the new encryption settings;
126
+ * `null` means no options.
127
+ * @returns Resolves once the output is written; rejects with a TypeError if
128
+ * the PDF cannot be recrypted, or with an Error if the source or output
129
+ * path is relative and the working directory was removed, or if a path
130
+ * is too long for the system once made absolute.
131
+ * @throws {TypeError} If the arguments are wrong, or one side is a path and
132
+ * the other a stream.
133
+ */
134
+ export function recryptAsync(
135
+ originalPdfPath: FilePath,
136
+ newPdfPath: FilePath,
137
+ options?: PDFRecryptOptions | null,
138
+ ): Promise<void>;
139
+ /**
140
+ * Like `recrypt()`, but re-encrypts on libuv's thread pool and returns a
141
+ * promise. The source stream is read into memory when called, and the
142
+ * output is written to `newPdfStream` before the promise resolves; both
143
+ * steps run on the calling thread.
144
+ * @param originalPdfStream - The source PDF.
145
+ * @param newPdfStream - The output stream.
146
+ * @param options - The source password and the new encryption settings;
147
+ * `null` means no options.
148
+ * @returns Resolves once the output is written; rejects with a TypeError if
149
+ * the PDF cannot be recrypted, with an Error if the output stream was
150
+ * written to after the call, with a RangeError if the source or output is
151
+ * too large to hold in memory, with the error a stream threw, or with an
152
+ * Error if `log` is too long for the system once made absolute.
153
+ * @throws {TypeError} If the arguments are wrong.
154
+ */
155
+ export function recryptAsync(
156
+ originalPdfStream: PDFRStreamForFile | PDFRStreamForBuffer,
157
+ newPdfStream: PDFWStreamForFile | PDFWStreamForBuffer,
158
+ options?: PDFRecryptOptions | null,
159
+ ): Promise<void>;
115
160
 
116
161
  /**
117
162
  * A JavaScript output stream. `write` receives each chunk as a `Buffer` the
@@ -1395,7 +1440,8 @@ declare namespace muhammara {
1395
1440
  /**
1396
1441
  * Per-call extraction budget. Every field is clamped to a built-in ceiling,
1397
1442
  * so a caller may tighten a limit but never raise it above the default.
1398
- * Omitted fields keep the ceiling.
1443
+ * Omitted fields keep the ceiling. Independent of these, an extraction reads
1444
+ * at most 64 MiB of decoded content and throws past it.
1399
1445
  */
1400
1446
  export interface PDFExtractionLimits {
1401
1447
  /** Extracted elements or items. Default and ceiling: 100000. */
@@ -3467,6 +3513,7 @@ declare namespace muhammara {
3467
3513
  overflow?: TextOverflowCallback;
3468
3514
  layout?: number | string;
3469
3515
  opacity?: number;
3516
+ /** Clockwise rotation in degrees, around `rotationOrigin` or the text position. */
3470
3517
  rotation?: number;
3471
3518
  rotationOrigin?: readonly [number, number];
3472
3519
  font?: string;
@@ -3643,6 +3690,7 @@ declare namespace muhammara {
3643
3690
  }
3644
3691
 
3645
3692
  interface TransformOptions extends SkewOptions {
3693
+ /** Clockwise rotation in degrees, around `rotationOrigin`. */
3646
3694
  rotation?: number;
3647
3695
  rotationOrigin?: readonly [number, number];
3648
3696
  }
@@ -4174,7 +4222,7 @@ declare namespace muhammara {
4174
4222
  * "center center". Horizontal center moves the image left by half its width
4175
4223
  * and right moves it right by half; vertical center moves it up by half its
4176
4224
  * height and bottom moves it down by half from its top-left placement.
4177
- * @param options.rotation - Rotate the image, in degrees.
4225
+ * @param options.rotation - Clockwise rotation of the image, in degrees.
4178
4226
  * @param options.rotationOrigin - [x, y] of the rotation origin; the
4179
4227
  * bottom-left corner of the drawn image when omitted.
4180
4228
  * @param options.fill - Paint the image box beneath the image.
@@ -4434,7 +4482,8 @@ declare namespace muhammara {
4434
4482
  resumeContext(): Recipe;
4435
4483
  /**
4436
4484
  * Rotate subsequent content around a point in Recipe coordinates.
4437
- * @param degrees - Clockwise rotation in degrees.
4485
+ * @param degrees - Counter-clockwise rotation in degrees. The `rotation`
4486
+ * option of shapes, text, and images turns clockwise instead.
4438
4487
  * @param x - Rotation origin x coordinate; defaults to 0.
4439
4488
  * @param y - Rotation origin y coordinate; defaults to 0.
4440
4489
  * @returns The recipe instance.
@@ -4478,8 +4527,9 @@ declare namespace muhammara {
4478
4527
  * @param options.underline - Text markup annotation.
4479
4528
  * @param options.strikeOut - Text markup annotation.
4480
4529
  * @param options.html - Interpret text as html
4481
- * @param options.flow - Used to activate/deactivate text flow which is the; defaults to false.
4482
- * ability to use multiple calls to 'text' to create an overall text box.
4530
+ * @param options.flow - Used to activate/deactivate text flow which is the
4531
+ * ability to use multiple calls to 'text' to create an overall text box. Defaults to
4532
+ * `true` for a call without coordinates and `false` for a call with them.
4483
4533
  * @param options.layout - An identifier of the layout to be associated with given text.
4484
4534
  * @param options.overflow - Called when the text is going to exceed the area
4485
4535
  * of the given text object. Intended for column layouts. Its parameter is (self) where 'self' is the recipe handle so
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@muhammara/native-core",
3
- "version": "7.0.0",
3
+ "version": "7.1.1",
4
4
  "description": "Shared JavaScript API for MuhammaraJS native packages",
5
5
  "homepage": "https://muhammarajs.readthedocs.io/",
6
6
  "license": "Apache-2.0",
@@ -26,6 +26,7 @@
26
26
  "index.d.ts",
27
27
  "lib",
28
28
  "fonts",
29
+ "licenses",
29
30
  "muhammara.d.ts",
30
31
  "THIRD_PARTY_NOTICES.md"
31
32
  ],