@parseo/shared 1.0.1 → 1.0.3
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/extract.d.ts.map +1 -1
- package/dist/extract.js +38 -27
- package/package.json +9 -2
package/dist/extract.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extract.d.ts","sourceRoot":"","sources":["../src/extract.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAe,MAAM,YAAY,CAAC;AAWlE,wBAAsB,gBAAgB,CACpC,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,QAAQ,EAAE,CAAC,CAqErB;AAED,wBAAgB,SAAS,CAAC,KAAK,EAAE,QAAQ,EAAE,GAAG,QAAQ,EAAE,CAgCvD;AA+BD,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAC,CAEhE;AAED,gEAAgE;AAChE,MAAM,WAAW,UAAU;IACzB,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;;;GAIG;AACH,wBAAsB,kBAAkB,CACtC,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,MAAM,EAAE,EACf,IAAI,CAAC,EAAE;IAAE,OAAO,CAAC,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAA;CAAE,GAC5C,OAAO,CAAC,UAAU,EAAE,CAAC,
|
|
1
|
+
{"version":3,"file":"extract.d.ts","sourceRoot":"","sources":["../src/extract.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAe,MAAM,YAAY,CAAC;AAWlE,wBAAsB,gBAAgB,CACpC,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,QAAQ,EAAE,CAAC,CAqErB;AAED,wBAAgB,SAAS,CAAC,KAAK,EAAE,QAAQ,EAAE,GAAG,QAAQ,EAAE,CAgCvD;AA+BD,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAC,CAEhE;AAED,gEAAgE;AAChE,MAAM,WAAW,UAAU;IACzB,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;;;GAIG;AACH,wBAAsB,kBAAkB,CACtC,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,MAAM,EAAE,EACf,IAAI,CAAC,EAAE;IAAE,OAAO,CAAC,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAA;CAAE,GAC5C,OAAO,CAAC,UAAU,EAAE,CAAC,CA8FvB"}
|
package/dist/extract.js
CHANGED
|
@@ -171,37 +171,48 @@ export async function extractFilledRects(buffer, pages, opts) {
|
|
|
171
171
|
];
|
|
172
172
|
}
|
|
173
173
|
else if (op === OPS.constructPath) {
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
width: Math.round(absW * 100) / 100,
|
|
189
|
-
height: Math.round(absH * 100) / 100,
|
|
190
|
-
page: pageNum,
|
|
191
|
-
});
|
|
192
|
-
}
|
|
193
|
-
argIdx += 4;
|
|
174
|
+
// pdfjs-dist v5: args = [paintOp, [Float32Array], bounds]
|
|
175
|
+
// Float32Array is interleaved [subOp, coords...] where:
|
|
176
|
+
// 0=moveTo(x,y), 1=lineTo(x,y), 2=curveTo(6 coords), 4=closePath
|
|
177
|
+
const pathData = args[1]?.[0];
|
|
178
|
+
if (!(pathData instanceof Float32Array))
|
|
179
|
+
continue;
|
|
180
|
+
// Collect all points to detect rectangle-like shapes
|
|
181
|
+
const points = [];
|
|
182
|
+
let j = 0;
|
|
183
|
+
while (j < pathData.length) {
|
|
184
|
+
const subOp = pathData[j];
|
|
185
|
+
if (subOp === 0 || subOp === 1) { // moveTo / lineTo
|
|
186
|
+
points.push([pathData[j + 1], pathData[j + 2]]);
|
|
187
|
+
j += 3;
|
|
194
188
|
}
|
|
195
|
-
else if (subOp ===
|
|
196
|
-
|
|
189
|
+
else if (subOp === 2) { // curveTo
|
|
190
|
+
j += 7;
|
|
197
191
|
}
|
|
198
|
-
else if (subOp ===
|
|
199
|
-
|
|
192
|
+
else if (subOp === 4) { // closePath
|
|
193
|
+
j += 1;
|
|
200
194
|
}
|
|
201
|
-
else
|
|
202
|
-
|
|
195
|
+
else {
|
|
196
|
+
j += 1;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
if (points.length >= 2) {
|
|
200
|
+
const xs = points.map(p => p[0]);
|
|
201
|
+
const ys = points.map(p => p[1]);
|
|
202
|
+
const rx = Math.min(...xs), ry = Math.min(...ys);
|
|
203
|
+
const rw = Math.max(...xs) - rx, rh = Math.max(...ys) - ry;
|
|
204
|
+
const absW = Math.abs(rw), absH = Math.abs(rh);
|
|
205
|
+
if (absW >= minSize && absW <= maxSize && absH >= minSize && absH <= maxSize) {
|
|
206
|
+
const tx = currentTransform[0] * rx + currentTransform[2] * ry + currentTransform[4];
|
|
207
|
+
const ty = currentTransform[1] * rx + currentTransform[3] * ry + currentTransform[5];
|
|
208
|
+
results.push({
|
|
209
|
+
x: Math.round(tx * 100) / 100,
|
|
210
|
+
y: Math.round((viewport.height - ty) * 100) / 100,
|
|
211
|
+
width: Math.round(absW * 100) / 100,
|
|
212
|
+
height: Math.round(absH * 100) / 100,
|
|
213
|
+
page: pageNum,
|
|
214
|
+
});
|
|
203
215
|
}
|
|
204
|
-
// closePath has no args
|
|
205
216
|
}
|
|
206
217
|
}
|
|
207
218
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@parseo/shared",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -11,6 +11,13 @@
|
|
|
11
11
|
}
|
|
12
12
|
},
|
|
13
13
|
"license": "MIT",
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "https://github.com/PabloZimmermann/parseo",
|
|
17
|
+
"directory": "packages/shared"
|
|
18
|
+
},
|
|
19
|
+
"homepage": "https://github.com/PabloZimmermann/parseo#readme",
|
|
20
|
+
"bugs": "https://github.com/PabloZimmermann/parseo/issues",
|
|
14
21
|
"publishConfig": {
|
|
15
22
|
"access": "public"
|
|
16
23
|
},
|
|
@@ -21,6 +28,6 @@
|
|
|
21
28
|
"build": "tsc"
|
|
22
29
|
},
|
|
23
30
|
"dependencies": {
|
|
24
|
-
"pdfjs-dist": "^
|
|
31
|
+
"pdfjs-dist": "^5.7.284"
|
|
25
32
|
}
|
|
26
33
|
}
|