@segnavia/render 0.1.0 → 0.2.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/color/binary.js +27 -0
- package/dist/color/black-point.js +121 -0
- package/dist/color/engine.js +18 -0
- package/dist/color/interpolation.js +74 -0
- package/dist/color/profile.js +98 -0
- package/dist/color/spaces.js +138 -0
- package/dist/color/tables.js +255 -0
- package/dist/color/types.js +21 -0
- package/dist/deck-pdf.js +152 -0
- package/dist/errors.d.ts +8 -0
- package/dist/errors.js +9 -0
- package/dist/index.d.ts +14 -8
- package/dist/index.js +87 -76
- package/dist/page-paper.js +94 -0
- package/dist/pages-imposition.js +65 -0
- package/dist/pages-pdf.js +66 -0
- package/dist/pdf-compose.js +35 -0
- package/dist/pdf-geometry.js +27 -0
- package/dist/press/adapter.js +145 -0
- package/dist/press/color-policy.js +31 -0
- package/dist/press/content.js +269 -0
- package/dist/press/pdf-objects.js +88 -0
- package/dist/press/policy.js +120 -0
- package/dist/press/report.js +79 -0
- package/dist/press/types.d.ts +16 -0
- package/dist/press/visitor.js +140 -0
- package/package.json +3 -3
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { shadingFunctionAction } from "./policy.js";
|
|
2
|
+
import { dictionaryOf, nameOf, numberOf, rawStreamOf } from "./pdf-objects.js";
|
|
3
|
+
import { PDFArray, PDFDict, PDFName, PDFRef } from "pdf-lib";
|
|
4
|
+
//#region src/press/visitor.ts
|
|
5
|
+
const key = (name) => PDFName.of(name);
|
|
6
|
+
const resolved = (state, object) => object instanceof PDFRef ? state.document.context.lookup(object) : object;
|
|
7
|
+
const dictionary = (state, object) => dictionaryOf(resolved(state, object));
|
|
8
|
+
const stream = (state, object) => rawStreamOf(resolved(state, object));
|
|
9
|
+
function visitContent(state, object, replace) {
|
|
10
|
+
if (!object) return;
|
|
11
|
+
if (object instanceof PDFRef) {
|
|
12
|
+
const label = object.toString();
|
|
13
|
+
if (state.references.has(label)) return;
|
|
14
|
+
state.references.add(label);
|
|
15
|
+
}
|
|
16
|
+
const found = stream(state, object);
|
|
17
|
+
if (!found || state.streams.has(found)) return;
|
|
18
|
+
state.streams.add(found);
|
|
19
|
+
state.actions?.group(found.dict, found, state.maskSources.has(found));
|
|
20
|
+
state.actions?.content(object, found, replace);
|
|
21
|
+
visitResources(state, found.dict.lookupMaybe(key("Resources"), PDFDict));
|
|
22
|
+
}
|
|
23
|
+
function visitSoftMask(state, object) {
|
|
24
|
+
const mask = dictionary(state, dictionary(state, object)?.get(key("SMask")));
|
|
25
|
+
const sourceObject = mask?.get(key("G"));
|
|
26
|
+
const source = stream(state, sourceObject);
|
|
27
|
+
if (!source || !sourceObject) return;
|
|
28
|
+
state.maskSources.add(source);
|
|
29
|
+
visitContent(state, sourceObject, (replacement) => mask?.set(key("G"), replacement));
|
|
30
|
+
}
|
|
31
|
+
function visitAppearances(state, page) {
|
|
32
|
+
const annotations = resolved(state, page.get(key("Annots")));
|
|
33
|
+
if (!(annotations instanceof PDFArray)) return;
|
|
34
|
+
for (let index = 0; index < annotations.size(); index++) {
|
|
35
|
+
const appearance = dictionary(state, dictionary(state, annotations.get(index))?.get(key("AP")));
|
|
36
|
+
for (const name of [
|
|
37
|
+
"N",
|
|
38
|
+
"R",
|
|
39
|
+
"D"
|
|
40
|
+
]) {
|
|
41
|
+
const object = appearance?.get(key(name));
|
|
42
|
+
if (!object) continue;
|
|
43
|
+
if (stream(state, object)) visitContent(state, object, (replacement) => appearance?.set(key(name), replacement));
|
|
44
|
+
else {
|
|
45
|
+
const states = dictionary(state, object);
|
|
46
|
+
for (const [stateName, stateObject] of states?.entries() ?? []) visitContent(state, stateObject, (replacement) => states?.set(stateName, replacement));
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
function visitFunction(state, object) {
|
|
52
|
+
const fn = dictionary(state, object);
|
|
53
|
+
if (fn && state.functions.has(fn)) return;
|
|
54
|
+
if (fn) state.functions.add(fn);
|
|
55
|
+
const type = fn ? numberOf(fn, "FunctionType") : void 0;
|
|
56
|
+
const functions = type === 3 ? fn?.lookupMaybe(key("Functions"), PDFArray) : void 0;
|
|
57
|
+
const decision = shadingFunctionAction(type, Boolean(fn), type !== 3 || Boolean(functions));
|
|
58
|
+
state.actions?.function(fn, decision);
|
|
59
|
+
for (let index = 0; index < (functions?.size() ?? 0); index++) visitFunction(state, functions?.get(index));
|
|
60
|
+
}
|
|
61
|
+
function visitShading(state, shading) {
|
|
62
|
+
if (state.actions?.shading(shading)) visitFunction(state, shading.get(key("Function")));
|
|
63
|
+
}
|
|
64
|
+
function visitShadings(state, resources) {
|
|
65
|
+
const shadings = resources.lookupMaybe(key("Shading"), PDFDict);
|
|
66
|
+
for (const [, object] of shadings?.entries() ?? []) {
|
|
67
|
+
const found = dictionary(state, object);
|
|
68
|
+
if (found) visitShading(state, found);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
function visitPatterns(state, resources) {
|
|
72
|
+
const patterns = resources.lookupMaybe(key("Pattern"), PDFDict);
|
|
73
|
+
for (const [name, object] of patterns?.entries() ?? []) {
|
|
74
|
+
const found = dictionary(state, object);
|
|
75
|
+
if (!found) continue;
|
|
76
|
+
if (numberOf(found, "PatternType") === 2) {
|
|
77
|
+
const shading = dictionary(state, found.get(key("Shading")));
|
|
78
|
+
if (shading) visitShading(state, shading);
|
|
79
|
+
} else visitContent(state, object, (replacement) => patterns?.set(name, replacement));
|
|
80
|
+
visitResources(state, found.lookupMaybe(key("Resources"), PDFDict));
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
function visitGraphicsStates(state, resources) {
|
|
84
|
+
const graphicsStates = resources.lookupMaybe(key("ExtGState"), PDFDict);
|
|
85
|
+
for (const [, object] of graphicsStates?.entries() ?? []) visitSoftMask(state, object);
|
|
86
|
+
}
|
|
87
|
+
function visitXObjects(state, resources) {
|
|
88
|
+
const xObjects = resources.lookupMaybe(key("XObject"), PDFDict);
|
|
89
|
+
for (const [name, object] of xObjects?.entries() ?? []) {
|
|
90
|
+
const found = stream(state, object);
|
|
91
|
+
if (!found) continue;
|
|
92
|
+
if (nameOf(found.dict.get(key("Subtype"))) === "Image") state.actions?.image(found);
|
|
93
|
+
else visitContent(state, object, (replacement) => xObjects?.set(name, replacement));
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
function visitFonts(state, resources) {
|
|
97
|
+
const fonts = resources.lookupMaybe(key("Font"), PDFDict);
|
|
98
|
+
for (const [, object] of fonts?.entries() ?? []) {
|
|
99
|
+
const font = dictionary(state, object);
|
|
100
|
+
if (!font || nameOf(font.get(key("Subtype"))) !== "Type3") continue;
|
|
101
|
+
const charProcs = font.lookupMaybe(key("CharProcs"), PDFDict);
|
|
102
|
+
for (const [name, glyph] of charProcs?.entries() ?? []) visitContent(state, glyph, (replacement) => charProcs?.set(name, replacement));
|
|
103
|
+
visitResources(state, font.lookupMaybe(key("Resources"), PDFDict));
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
function visitResources(state, resources) {
|
|
107
|
+
if (!resources || state.resources.has(resources)) return;
|
|
108
|
+
state.resources.add(resources);
|
|
109
|
+
visitShadings(state, resources);
|
|
110
|
+
visitPatterns(state, resources);
|
|
111
|
+
visitGraphicsStates(state, resources);
|
|
112
|
+
visitXObjects(state, resources);
|
|
113
|
+
visitFonts(state, resources);
|
|
114
|
+
}
|
|
115
|
+
function traverse(document, maskSources, actions) {
|
|
116
|
+
const state = {
|
|
117
|
+
document,
|
|
118
|
+
maskSources,
|
|
119
|
+
actions,
|
|
120
|
+
functions: /* @__PURE__ */ new WeakSet(),
|
|
121
|
+
references: /* @__PURE__ */ new Set(),
|
|
122
|
+
resources: /* @__PURE__ */ new WeakSet(),
|
|
123
|
+
streams: /* @__PURE__ */ new WeakSet()
|
|
124
|
+
};
|
|
125
|
+
for (const page of document.getPages()) {
|
|
126
|
+
actions?.group(page.node, void 0, false);
|
|
127
|
+
const contents = page.node.Contents();
|
|
128
|
+
if (contents instanceof PDFArray) for (let index = 0; index < contents.size(); index++) visitContent(state, contents.get(index), (replacement) => contents.set(index, replacement));
|
|
129
|
+
else visitContent(state, contents, (replacement) => page.node.set(key("Contents"), replacement));
|
|
130
|
+
visitResources(state, page.node.Resources());
|
|
131
|
+
visitAppearances(state, page.node);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
function walkPressGraph(document, actions) {
|
|
135
|
+
const maskSources = /* @__PURE__ */ new WeakSet();
|
|
136
|
+
traverse(document, maskSources);
|
|
137
|
+
traverse(document, maskSources, actions);
|
|
138
|
+
}
|
|
139
|
+
//#endregion
|
|
140
|
+
export { walkPressGraph };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@segnavia/render",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -26,8 +26,8 @@
|
|
|
26
26
|
}
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@segnavia/format": "0.
|
|
30
|
-
"@segnavia/frame": "0.
|
|
29
|
+
"@segnavia/format": "0.2.0",
|
|
30
|
+
"@segnavia/frame": "0.2.0",
|
|
31
31
|
"playwright-core": "1.55.1",
|
|
32
32
|
"pdf-lib": "^1.17.1"
|
|
33
33
|
}
|