@muhammara/native-core 7.0.0-alpha.1 → 7.0.0-beta.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/README.md +4 -0
- package/index.js +45 -0
- package/lib/Recipe.js +163 -56
- package/lib/recipe/annotation.js +53 -4
- package/lib/recipe/appendPage.js +38 -16
- package/lib/recipe/graphics-state.js +20 -0
- package/lib/recipe/image.js +4 -0
- package/lib/recipe/info.js +71 -73
- package/lib/recipe/insertPage.js +20 -17
- package/lib/recipe/page.js +808 -11
- package/lib/recipe/parameters.js +2 -0
- package/lib/recipe/replaceText.js +66 -0
- package/lib/recipe/shapes.js +22 -1
- package/lib/recipe/split.js +2 -6
- package/lib/recipe/text.helper.js +1 -1
- package/lib/recipe/text.js +106 -8
- package/lib/recipe/utils.js +31 -27
- package/lib/recipe/vector-polygon.js +11 -0
- package/lib/recipe/vector.helper.js +15 -3
- package/lib/recipe/vector.js +108 -10
- package/lib/recipe-info.js +10 -0
- package/muhammara.d.ts +543 -89
- package/package.json +1 -1
package/lib/recipe/vector.js
CHANGED
|
@@ -12,6 +12,8 @@
|
|
|
12
12
|
// DecimalColor component values range from 0 to 255.
|
|
13
13
|
// PercentColor component values range from 1 to 100.
|
|
14
14
|
|
|
15
|
+
const { linkPdf } = require("./annotation");
|
|
16
|
+
|
|
15
17
|
/**
|
|
16
18
|
* Draw a circle
|
|
17
19
|
* @name circle
|
|
@@ -74,7 +76,8 @@ exports.circle = function circle(x, y, radius, options = {}) {
|
|
|
74
76
|
diameter,
|
|
75
77
|
diameter,
|
|
76
78
|
pathOptions,
|
|
77
|
-
(ctx) => {
|
|
79
|
+
(ctx, xObject) => {
|
|
80
|
+
ctx.gs(xObject.getGsName(pathOptions.strokeGsId));
|
|
78
81
|
ctx
|
|
79
82
|
.d(pathOptions.dash, pathOptions.dashPhase)
|
|
80
83
|
.drawCircle(
|
|
@@ -88,6 +91,8 @@ exports.circle = function circle(x, y, radius, options = {}) {
|
|
|
88
91
|
},
|
|
89
92
|
);
|
|
90
93
|
}
|
|
94
|
+
if (options.link)
|
|
95
|
+
this.link(options.link, x - radius, y - radius, diameter, diameter);
|
|
91
96
|
return this;
|
|
92
97
|
};
|
|
93
98
|
|
|
@@ -173,6 +178,7 @@ exports.rectangle = function rectangle(x, y, width, height, options = {}) {
|
|
|
173
178
|
height,
|
|
174
179
|
pathOptions,
|
|
175
180
|
(ctx, xObject) => {
|
|
181
|
+
ctx.gs(xObject.getGsName(pathOptions.strokeGsId));
|
|
176
182
|
// ... requires adjusting the internal drawing to accomodate line thickness.
|
|
177
183
|
const margin = pathOptions.width;
|
|
178
184
|
xObject.stroke(colorModel);
|
|
@@ -203,6 +209,11 @@ exports.rectangle = function rectangle(x, y, width, height, options = {}) {
|
|
|
203
209
|
},
|
|
204
210
|
);
|
|
205
211
|
}
|
|
212
|
+
if (options.link) {
|
|
213
|
+
if (options.useGivenCoords)
|
|
214
|
+
linkPdf(this, options.link, x, y, width, height);
|
|
215
|
+
else this.link(options.link, x, y, width, height);
|
|
216
|
+
}
|
|
206
217
|
|
|
207
218
|
return this;
|
|
208
219
|
};
|
|
@@ -362,6 +373,7 @@ exports.ellipse = function ellipse(cx, cy, rx, ry, options = {}) {
|
|
|
362
373
|
height,
|
|
363
374
|
pathOptions,
|
|
364
375
|
(ctx, xObject) => {
|
|
376
|
+
ctx.gs(xObject.getGsName(pathOptions.strokeGsId));
|
|
365
377
|
const margin = pathOptions.width / 2;
|
|
366
378
|
xObject.stroke(colorModel);
|
|
367
379
|
ctx.w(pathOptions.width).d(pathOptions.dash, pathOptions.dashPhase);
|
|
@@ -378,6 +390,7 @@ exports.ellipse = function ellipse(cx, cy, rx, ry, options = {}) {
|
|
|
378
390
|
},
|
|
379
391
|
);
|
|
380
392
|
}
|
|
393
|
+
if (options.link) this.link(options.link, cx - rx, cy - ry, width, height);
|
|
381
394
|
return this;
|
|
382
395
|
};
|
|
383
396
|
|
|
@@ -518,6 +531,7 @@ exports.arc = function arc(
|
|
|
518
531
|
diameter,
|
|
519
532
|
pathOptions,
|
|
520
533
|
(ctx, xObject) => {
|
|
534
|
+
ctx.gs(xObject.getGsName(pathOptions.strokeGsId));
|
|
521
535
|
const margin = pathOptions.width / 2;
|
|
522
536
|
xObject.stroke(colorModel);
|
|
523
537
|
ctx.w(pathOptions.width).d(pathOptions.dash, pathOptions.dashPhase);
|
|
@@ -532,34 +546,118 @@ exports.arc = function arc(
|
|
|
532
546
|
);
|
|
533
547
|
}
|
|
534
548
|
|
|
549
|
+
if (options.link)
|
|
550
|
+
this.link(options.link, x - radius, y - radius, diameter, diameter);
|
|
551
|
+
return this;
|
|
552
|
+
};
|
|
553
|
+
|
|
554
|
+
/**
|
|
555
|
+
* Draw a closed sector of a circle.
|
|
556
|
+
* @name pie
|
|
557
|
+
* @function
|
|
558
|
+
* @memberof Recipe#
|
|
559
|
+
* @param {number} x - the x coordinate of the pie center point
|
|
560
|
+
* @param {number} y - the y coordinate of the pie center point
|
|
561
|
+
* @param {number} radius - the distance from the center point to the arc
|
|
562
|
+
* @param {number} [startAngle=0] - the start of the arc in degree units
|
|
563
|
+
* @param {number} [endAngle=360] - the end of the arc in degree units
|
|
564
|
+
* @param {Object} [options] - The path options.
|
|
565
|
+
* @returns {Recipe} The recipe instance.
|
|
566
|
+
*/
|
|
567
|
+
exports.pie = function pie(x, y, radius, startAngle, endAngle, options = {}) {
|
|
568
|
+
return this.arc(x, y, radius, startAngle, endAngle, {
|
|
569
|
+
...options,
|
|
570
|
+
sector: true,
|
|
571
|
+
});
|
|
572
|
+
};
|
|
573
|
+
|
|
574
|
+
/**
|
|
575
|
+
* Set the line style for the current page content context.
|
|
576
|
+
* @name lineStyle
|
|
577
|
+
* @function
|
|
578
|
+
* @memberof Recipe#
|
|
579
|
+
* @param {Recipe.LineStyleOptions} [options] - The line style options.
|
|
580
|
+
* @param {number} [options.width] - The line width.
|
|
581
|
+
* @param {number} [options.lineWidth] - Alias for width.
|
|
582
|
+
* @param {number} [options.cap] - The PDF line cap style.
|
|
583
|
+
* @param {number} [options.join] - The PDF line join style.
|
|
584
|
+
* @param {number} [options.miterLimit] - The miter limit.
|
|
585
|
+
* @param {number[]} [options.dash] - The dash pattern.
|
|
586
|
+
* @param {number} [options.dashPhase] - The dash pattern phase.
|
|
587
|
+
* @returns {Recipe} The recipe instance.
|
|
588
|
+
*/
|
|
589
|
+
exports.lineStyle = function lineStyle(options = {}) {
|
|
590
|
+
this.current = this.current || {};
|
|
591
|
+
this.current.lineStyle = this.current.lineStyle || {};
|
|
592
|
+
|
|
593
|
+
if (options.width !== undefined || options.lineWidth !== undefined) {
|
|
594
|
+
const width = options.width ?? options.lineWidth;
|
|
595
|
+
this.current.lineStyle.width = width;
|
|
596
|
+
this.pageContext.w(width);
|
|
597
|
+
}
|
|
598
|
+
if (options.cap !== undefined) {
|
|
599
|
+
this.current.lineStyle.cap = options.cap;
|
|
600
|
+
this.pageContext.J(options.cap);
|
|
601
|
+
}
|
|
602
|
+
if (options.join !== undefined) {
|
|
603
|
+
this.current.lineStyle.join = options.join;
|
|
604
|
+
this.pageContext.j(options.join);
|
|
605
|
+
}
|
|
606
|
+
if (options.miterLimit !== undefined) {
|
|
607
|
+
this.current.lineStyle.miterLimit = options.miterLimit;
|
|
608
|
+
this.pageContext.M(options.miterLimit);
|
|
609
|
+
}
|
|
610
|
+
if (options.dash !== undefined || options.dashPhase !== undefined) {
|
|
611
|
+
const dash = options.dash ?? this.current.lineStyle.dash ?? [];
|
|
612
|
+
const dashPhase =
|
|
613
|
+
options.dashPhase ?? this.current.lineStyle.dashPhase ?? 0;
|
|
614
|
+
this.current.lineStyle.dash = dash;
|
|
615
|
+
this.current.lineStyle.dashPhase = dashPhase;
|
|
616
|
+
}
|
|
617
|
+
return this._setLineStyle(options);
|
|
618
|
+
};
|
|
619
|
+
|
|
620
|
+
exports._setLineStyle = function _setLineStyle(options = {}) {
|
|
621
|
+
if (options.width !== undefined || options.lineWidth !== undefined)
|
|
622
|
+
this.pageContext.w(options.width ?? options.lineWidth);
|
|
623
|
+
if (options.cap !== undefined) this.pageContext.J(options.cap);
|
|
624
|
+
if (options.join !== undefined) this.pageContext.j(options.join);
|
|
625
|
+
if (options.miterLimit !== undefined) this.pageContext.M(options.miterLimit);
|
|
626
|
+
if (options.dash !== undefined || options.dashPhase !== undefined)
|
|
627
|
+
this.pageContext.d(
|
|
628
|
+
options.dash ?? this.current.lineStyle.dash ?? [],
|
|
629
|
+
options.dashPhase ?? this.current.lineStyle.dashPhase ?? 0,
|
|
630
|
+
);
|
|
535
631
|
return this;
|
|
536
632
|
};
|
|
537
633
|
|
|
538
634
|
/**
|
|
539
635
|
* Set the line width.
|
|
540
636
|
*
|
|
541
|
-
* This compatibility method currently has no effect.
|
|
542
637
|
* @name lineWidth
|
|
543
638
|
* @function
|
|
544
639
|
* @memberof Recipe#
|
|
545
|
-
* @param {number} width - The
|
|
640
|
+
* @param {number} width - The line width.
|
|
546
641
|
* @returns {Recipe} The recipe instance.
|
|
547
642
|
*/
|
|
548
|
-
exports.lineWidth = function lineWidth() {
|
|
549
|
-
return this;
|
|
643
|
+
exports.lineWidth = function lineWidth(width) {
|
|
644
|
+
return this.lineStyle({ width });
|
|
550
645
|
};
|
|
551
646
|
|
|
552
647
|
/**
|
|
553
|
-
* Set
|
|
648
|
+
* Set fill and stroke opacity.
|
|
554
649
|
*
|
|
555
|
-
*
|
|
556
|
-
* @name fillOpacity
|
|
650
|
+
* @name opacity
|
|
557
651
|
* @function
|
|
558
652
|
* @memberof Recipe#
|
|
559
|
-
* @param {number}
|
|
653
|
+
* @param {number} value - The requested opacity from 0 (transparent) to 1 (opaque).
|
|
560
654
|
* @returns {Recipe} The recipe instance.
|
|
561
655
|
*/
|
|
562
|
-
exports.
|
|
656
|
+
exports.opacity = function opacity(value) {
|
|
657
|
+
if (!Number.isFinite(value) || value < 0 || value > 1) {
|
|
658
|
+
throw new RangeError("Opacity must be a finite number between 0 and 1");
|
|
659
|
+
}
|
|
660
|
+
this.current.opacity = value;
|
|
563
661
|
return this;
|
|
564
662
|
};
|
|
565
663
|
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// Metadata fields accepted by Recipe constructor options and info().
|
|
2
|
+
var recipeInfoKeys = Object.freeze({
|
|
3
|
+
author: "author",
|
|
4
|
+
title: "title",
|
|
5
|
+
subject: "subject",
|
|
6
|
+
keywords: "keywords",
|
|
7
|
+
});
|
|
8
|
+
var standardInfoKeys = Object.freeze(Object.values(recipeInfoKeys));
|
|
9
|
+
|
|
10
|
+
module.exports = { recipeInfoKeys, standardInfoKeys };
|