@segnavia/render 0.5.0 → 0.7.0
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/book-pdf.js +15 -8
- package/dist/book-render.js +3 -2
- package/dist/browser-jpeg.js +42 -0
- package/dist/color/black-point.js +11 -8
- package/dist/color/engine.js +9 -2
- package/dist/color/interpolation.js +11 -1
- package/dist/color/profile.js +17 -7
- package/dist/color/tables.js +47 -13
- package/dist/color/types.js +4 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +42 -14
- package/dist/options.d.ts +34 -0
- package/dist/overflow.js +123 -0
- package/dist/page-paper.js +12 -7
- package/dist/pages-pdf.js +7 -4
- package/dist/press/adapter.js +97 -42
- package/dist/press/color-policy.js +12 -3
- package/dist/press/content.js +28 -20
- package/dist/press/image.js +327 -0
- package/dist/press/policy.js +27 -10
- package/dist/press/report.js +24 -13
- package/dist/press/sample-shading.js +9 -19
- package/dist/press/types.d.ts +7 -2
- package/dist/press/visitor.js +32 -30
- package/package.json +4 -4
package/dist/press/visitor.js
CHANGED
|
@@ -13,7 +13,7 @@ function rememberRef(state, object) {
|
|
|
13
13
|
state.references.add(label);
|
|
14
14
|
return false;
|
|
15
15
|
}
|
|
16
|
-
function visitContent(state, object, replace, enclosing, replay = false, nestResources = true) {
|
|
16
|
+
function visitContent(state, object, replace, enclosing, replay = false, nestResources = true, context = "none") {
|
|
17
17
|
if (!object) return;
|
|
18
18
|
const seenRef = rememberRef(state, object);
|
|
19
19
|
const found = stream(state, object);
|
|
@@ -23,9 +23,10 @@ function visitContent(state, object, replace, enclosing, replay = false, nestRes
|
|
|
23
23
|
const seen = seenRef || seenStream;
|
|
24
24
|
if (seen && !replay) return;
|
|
25
25
|
const own = found.dict.lookupMaybe(key("Resources"), PDFDict);
|
|
26
|
-
|
|
27
|
-
state.actions?.
|
|
28
|
-
|
|
26
|
+
const mask = state.maskSources.get(found) ?? context;
|
|
27
|
+
if (!seen) state.actions?.group(found.dict, found, mask);
|
|
28
|
+
state.actions?.content(object, found, replace, own ?? enclosing, mask);
|
|
29
|
+
if (nestResources && !seen) visitResources(state, own, mask);
|
|
29
30
|
}
|
|
30
31
|
function visitSoftMask(state, object, enclosing) {
|
|
31
32
|
const graphicsState = dictionary(state, object);
|
|
@@ -34,8 +35,9 @@ function visitSoftMask(state, object, enclosing) {
|
|
|
34
35
|
const source = stream(state, sourceObject);
|
|
35
36
|
if (!graphicsState || !mask || !source || !sourceObject) return;
|
|
36
37
|
state.actions?.softMask?.(graphicsState, mask, source, source.dict.lookupMaybe(key("Resources"), PDFDict) ?? enclosing);
|
|
37
|
-
|
|
38
|
-
|
|
38
|
+
const context = nameOf(mask.get(key("S"))) === "Alpha" ? "alpha" : "luminosity";
|
|
39
|
+
state.maskSources.set(source, context);
|
|
40
|
+
visitContent(state, sourceObject, (replacement) => mask?.set(key("G"), replacement), enclosing, false, true, context);
|
|
39
41
|
}
|
|
40
42
|
function visitAppearances(state, page, enclosing) {
|
|
41
43
|
const annotations = resolved(state, page.get(key("Annots")));
|
|
@@ -57,69 +59,69 @@ function visitAppearances(state, page, enclosing) {
|
|
|
57
59
|
}
|
|
58
60
|
}
|
|
59
61
|
}
|
|
60
|
-
function visitFunction(state, object) {
|
|
62
|
+
function visitFunction(state, object, context) {
|
|
61
63
|
const fn = dictionary(state, object);
|
|
62
64
|
if (fn && state.functions.has(fn)) return;
|
|
63
65
|
if (fn) state.functions.add(fn);
|
|
64
66
|
const type = fn ? numberOf(fn, "FunctionType") : void 0;
|
|
65
67
|
const functions = type === 3 ? fn?.lookupMaybe(key("Functions"), PDFArray) : void 0;
|
|
66
68
|
const decision = shadingFunctionAction(type, Boolean(fn), type !== 3 || Boolean(functions));
|
|
67
|
-
state.actions?.function(fn, decision);
|
|
68
|
-
for (let index = 0; index < (functions?.size() ?? 0); index++) visitFunction(state, functions?.get(index));
|
|
69
|
+
state.actions?.function(fn, decision, context);
|
|
70
|
+
for (let index = 0; index < (functions?.size() ?? 0); index++) visitFunction(state, functions?.get(index), context);
|
|
69
71
|
}
|
|
70
|
-
function visitShading(state, shading, pattern) {
|
|
71
|
-
if (state.actions?.shading(shading, pattern)) visitFunction(state, shading.get(key("Function")));
|
|
72
|
+
function visitShading(state, shading, pattern, context) {
|
|
73
|
+
if (state.actions?.shading(shading, pattern, context)) visitFunction(state, shading.get(key("Function")), context);
|
|
72
74
|
}
|
|
73
|
-
function visitShadings(state, resources) {
|
|
75
|
+
function visitShadings(state, resources, context) {
|
|
74
76
|
const shadings = resources.lookupMaybe(key("Shading"), PDFDict);
|
|
75
77
|
for (const [, object] of shadings?.entries() ?? []) {
|
|
76
78
|
const found = dictionary(state, object);
|
|
77
|
-
if (found) visitShading(state, found);
|
|
79
|
+
if (found) visitShading(state, found, void 0, context);
|
|
78
80
|
}
|
|
79
81
|
}
|
|
80
|
-
function visitPatterns(state, resources) {
|
|
82
|
+
function visitPatterns(state, resources, context) {
|
|
81
83
|
const patterns = resources.lookupMaybe(key("Pattern"), PDFDict);
|
|
82
84
|
for (const [name, object] of patterns?.entries() ?? []) {
|
|
83
85
|
const found = dictionary(state, object);
|
|
84
86
|
if (!found) continue;
|
|
85
87
|
if (numberOf(found, "PatternType") === 2) {
|
|
86
88
|
const shading = dictionary(state, found.get(key("Shading")));
|
|
87
|
-
if (shading) visitShading(state, shading, found);
|
|
88
|
-
} else visitContent(state, object, (replacement) => patterns?.set(name, replacement), found.lookupMaybe(key("Resources"), PDFDict) ?? resources);
|
|
89
|
-
visitResources(state, found.lookupMaybe(key("Resources"), PDFDict));
|
|
89
|
+
if (shading) visitShading(state, shading, found, context);
|
|
90
|
+
} else visitContent(state, object, (replacement) => patterns?.set(name, replacement), found.lookupMaybe(key("Resources"), PDFDict) ?? resources, false, true, context);
|
|
91
|
+
visitResources(state, found.lookupMaybe(key("Resources"), PDFDict), context);
|
|
90
92
|
}
|
|
91
93
|
}
|
|
92
94
|
function visitGraphicsStates(state, resources) {
|
|
93
95
|
const graphicsStates = resources.lookupMaybe(key("ExtGState"), PDFDict);
|
|
94
96
|
for (const [, object] of graphicsStates?.entries() ?? []) visitSoftMask(state, object, resources);
|
|
95
97
|
}
|
|
96
|
-
function visitXObjects(state, resources) {
|
|
98
|
+
function visitXObjects(state, resources, context) {
|
|
97
99
|
const xObjects = resources.lookupMaybe(key("XObject"), PDFDict);
|
|
98
100
|
for (const [name, object] of xObjects?.entries() ?? []) {
|
|
99
101
|
const found = stream(state, object);
|
|
100
102
|
if (!found) continue;
|
|
101
|
-
if (nameOf(found.dict.get(key("Subtype"))) === "Image") state.actions?.image(found);
|
|
102
|
-
else visitContent(state, object, (replacement) => xObjects?.set(name, replacement), found.dict.lookupMaybe(key("Resources"), PDFDict) ?? resources);
|
|
103
|
+
if (nameOf(found.dict.get(key("Subtype"))) === "Image") state.actions?.image(found, context, (replacement) => xObjects?.set(name, replacement));
|
|
104
|
+
else visitContent(state, object, (replacement) => xObjects?.set(name, replacement), found.dict.lookupMaybe(key("Resources"), PDFDict) ?? resources, false, true, context);
|
|
103
105
|
}
|
|
104
106
|
}
|
|
105
|
-
function visitFonts(state, resources) {
|
|
107
|
+
function visitFonts(state, resources, context) {
|
|
106
108
|
const fonts = resources.lookupMaybe(key("Font"), PDFDict);
|
|
107
109
|
for (const [, object] of fonts?.entries() ?? []) {
|
|
108
110
|
const font = dictionary(state, object);
|
|
109
111
|
if (!font || nameOf(font.get(key("Subtype"))) !== "Type3") continue;
|
|
110
112
|
const charProcs = font.lookupMaybe(key("CharProcs"), PDFDict);
|
|
111
|
-
for (const [name, glyph] of charProcs?.entries() ?? []) visitContent(state, glyph, (replacement) => charProcs?.set(name, replacement), font.lookupMaybe(key("Resources"), PDFDict) ?? resources);
|
|
112
|
-
visitResources(state, font.lookupMaybe(key("Resources"), PDFDict));
|
|
113
|
+
for (const [name, glyph] of charProcs?.entries() ?? []) visitContent(state, glyph, (replacement) => charProcs?.set(name, replacement), font.lookupMaybe(key("Resources"), PDFDict) ?? resources, false, true, context);
|
|
114
|
+
visitResources(state, font.lookupMaybe(key("Resources"), PDFDict), context);
|
|
113
115
|
}
|
|
114
116
|
}
|
|
115
|
-
function visitResources(state, resources) {
|
|
117
|
+
function visitResources(state, resources, context = "none") {
|
|
116
118
|
if (!resources || state.resources.has(resources)) return;
|
|
117
119
|
state.resources.add(resources);
|
|
118
120
|
visitGraphicsStates(state, resources);
|
|
119
|
-
visitXObjects(state, resources);
|
|
120
|
-
visitFonts(state, resources);
|
|
121
|
-
visitShadings(state, resources);
|
|
122
|
-
visitPatterns(state, resources);
|
|
121
|
+
visitXObjects(state, resources, context);
|
|
122
|
+
visitFonts(state, resources, context);
|
|
123
|
+
visitShadings(state, resources, context);
|
|
124
|
+
visitPatterns(state, resources, context);
|
|
123
125
|
}
|
|
124
126
|
function visitPageContents(state, page, contents, pageResources) {
|
|
125
127
|
const replay = Boolean(state.actions?.replayPageContents);
|
|
@@ -147,7 +149,7 @@ function traverse(document, maskSources, actions) {
|
|
|
147
149
|
streams: /* @__PURE__ */ new WeakSet()
|
|
148
150
|
};
|
|
149
151
|
for (const page of document.getPages()) {
|
|
150
|
-
actions?.group(page.node, void 0,
|
|
152
|
+
actions?.group(page.node, void 0, "none");
|
|
151
153
|
const pageResources = page.node.Resources();
|
|
152
154
|
visitPageContents(state, page.node, page.node.Contents(), pageResources);
|
|
153
155
|
visitResources(state, pageResources);
|
|
@@ -155,7 +157,7 @@ function traverse(document, maskSources, actions) {
|
|
|
155
157
|
}
|
|
156
158
|
}
|
|
157
159
|
function walkPressGraph(document, actions) {
|
|
158
|
-
const maskSources = /* @__PURE__ */ new
|
|
160
|
+
const maskSources = /* @__PURE__ */ new WeakMap();
|
|
159
161
|
traverse(document, maskSources);
|
|
160
162
|
traverse(document, maskSources, actions);
|
|
161
163
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@segnavia/render",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -26,9 +26,9 @@
|
|
|
26
26
|
}
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@segnavia/format": "0.
|
|
30
|
-
"@segnavia/frame": "0.
|
|
31
|
-
"@segnavia/html": "0.
|
|
29
|
+
"@segnavia/format": "0.7.0",
|
|
30
|
+
"@segnavia/frame": "0.7.0",
|
|
31
|
+
"@segnavia/html": "0.7.0",
|
|
32
32
|
"playwright-core": "1.55.1",
|
|
33
33
|
"pdf-lib": "^1.17.1"
|
|
34
34
|
}
|