dsh-figmark 1.0.1 → 1.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.
- package/lib/client.js +637 -208
- package/lib/client.pdf.js +22 -16
- package/lib/index.js +20 -0
- package/market/index.json +2 -2
- package/package.json +1 -1
package/lib/client.pdf.js
CHANGED
|
@@ -25856,7 +25856,7 @@ while (prev === _win[++scan] && prev === _win[++scan] && prev === _win[++scan] &
|
|
|
25856
25856
|
* @param transform - `[a b c d e f]`, user space → page units.
|
|
25857
25857
|
* @returns the placed geometry.
|
|
25858
25858
|
*/
|
|
25859
|
-
function place(mark, transform) {
|
|
25859
|
+
function place(mark, transform, unit) {
|
|
25860
25860
|
const scale = unitScale(transform);
|
|
25861
25861
|
const radians = (mark.rotation ?? 0) * Math.PI / 180;
|
|
25862
25862
|
const box = pointsBox(mark.points);
|
|
@@ -25867,10 +25867,11 @@ while (prev === _win[++scan] && prev === _win[++scan] && prev === _win[++scan] &
|
|
|
25867
25867
|
if (mark.kind === "rect" || mark.kind === "ellipse") {
|
|
25868
25868
|
if (turned) points = turnedRing(mark.kind, mark.points, centre, radians);
|
|
25869
25869
|
} else if (spins) points = mark.points.map((point) => turnAround(point, centre, radians));
|
|
25870
|
+
const weight = (mark.weight ?? 1) * unit;
|
|
25870
25871
|
return {
|
|
25871
25872
|
points: points.map((point) => toUserSpace(transform, point)),
|
|
25872
|
-
width: STROKE_WIDTH / scale,
|
|
25873
|
-
head: ARROW_HEAD / scale,
|
|
25873
|
+
width: STROKE_WIDTH * weight / scale,
|
|
25874
|
+
head: ARROW_HEAD * weight / scale,
|
|
25874
25875
|
turned
|
|
25875
25876
|
};
|
|
25876
25877
|
}
|
|
@@ -25962,13 +25963,14 @@ while (prev === _win[++scan] && prev === _win[++scan] && prev === _win[++scan] &
|
|
|
25962
25963
|
* @param rect - the box the appearance is drawn in.
|
|
25963
25964
|
* @returns the content stream operators.
|
|
25964
25965
|
*/
|
|
25965
|
-
function pointContent(mark, placed, rect) {
|
|
25966
|
+
function pointContent(mark, placed, rect, unit) {
|
|
25966
25967
|
const point = placed.points[0];
|
|
25967
25968
|
/* v8 ignore next -- a point mark carries exactly the one coordinate it was placed at. */
|
|
25968
25969
|
if (point === void 0) return "";
|
|
25969
25970
|
const [x, y] = [point[0] - rect.x, point[1] - rect.y];
|
|
25970
|
-
const
|
|
25971
|
-
const
|
|
25971
|
+
const base = Math.max(placed.width / (STROKE_WIDTH * unit), 1e-4);
|
|
25972
|
+
const radius = POINT_RADIUS / base;
|
|
25973
|
+
const dot = POINT_DOT_RADIUS / base;
|
|
25972
25974
|
const ring = ellipsePath(x, y, radius, radius);
|
|
25973
25975
|
const centre = ellipsePath(x, y, dot, dot);
|
|
25974
25976
|
return `${colorOperators(mark.color, "RG")} ${num(placed.width)} w 1 J ${ring} S ${colorOperators(mark.color, "rg")} ${centre} f`;
|
|
@@ -26013,8 +26015,8 @@ while (prev === _win[++scan] && prev === _win[++scan] && prev === _win[++scan] &
|
|
|
26013
26015
|
* @returns the appearance stream reference, or undefined when the mark draws
|
|
26014
26016
|
* nothing a stream is needed for.
|
|
26015
26017
|
*/
|
|
26016
|
-
function appearance(context, mark, placed, rect) {
|
|
26017
|
-
const content = mark.kind === "point" ? pointContent(mark, placed, rect) : strokeContent(mark, placed, rect);
|
|
26018
|
+
function appearance(context, mark, placed, rect, unit) {
|
|
26019
|
+
const content = mark.kind === "point" ? pointContent(mark, placed, rect, unit) : strokeContent(mark, placed, rect);
|
|
26018
26020
|
if (content === "") return void 0;
|
|
26019
26021
|
const dictionary = import_cjs.PDFDict.withContext(context);
|
|
26020
26022
|
dictionary.set(import_cjs.PDFName.of("Type"), import_cjs.PDFName.of("XObject"));
|
|
@@ -26053,11 +26055,11 @@ while (prev === _win[++scan] && prev === _win[++scan] && prev === _win[++scan] &
|
|
|
26053
26055
|
* @param transform - `[a b c d e f]`, user space → page units.
|
|
26054
26056
|
* @returns the annotation dictionary.
|
|
26055
26057
|
*/
|
|
26056
|
-
function annotation(context, mark, transform) {
|
|
26057
|
-
const placed = place(mark, transform);
|
|
26058
|
+
function annotation(context, mark, transform, unit) {
|
|
26059
|
+
const placed = place(mark, transform, unit);
|
|
26058
26060
|
if (mark.points[0] === void 0 || placed.points[0] === void 0) throw new Error("an annotation mark needs at least one coordinate pair");
|
|
26059
26061
|
const rect = boundsOf(drawnPoints(mark, placed), placed.width * 2);
|
|
26060
|
-
const box = mark.kind === "point" ? boundsOf(placed.points, POINT_RADIUS * 2) : rect;
|
|
26062
|
+
const box = mark.kind === "point" ? boundsOf(placed.points, POINT_RADIUS * unit * 2) : rect;
|
|
26061
26063
|
const dictionary = import_cjs.PDFDict.withContext(context);
|
|
26062
26064
|
dictionary.set(import_cjs.PDFName.of("Type"), import_cjs.PDFName.of("Annot"));
|
|
26063
26065
|
dictionary.set(import_cjs.PDFName.of("Subtype"), import_cjs.PDFName.of(annotationSubtype(mark)));
|
|
@@ -26101,7 +26103,7 @@ while (prev === _win[++scan] && prev === _win[++scan] && prev === _win[++scan] &
|
|
|
26101
26103
|
dictionary.set(import_cjs.PDFName.of("LE"), endings);
|
|
26102
26104
|
}
|
|
26103
26105
|
}
|
|
26104
|
-
const stream = appearance(context, mark, placed, box);
|
|
26106
|
+
const stream = appearance(context, mark, placed, box, unit);
|
|
26105
26107
|
if (stream !== void 0) {
|
|
26106
26108
|
const streams = import_cjs.PDFDict.withContext(context);
|
|
26107
26109
|
streams.set(import_cjs.PDFName.of("N"), stream);
|
|
@@ -26149,7 +26151,10 @@ while (prev === _win[++scan] && prev === _win[++scan] && prev === _win[++scan] &
|
|
|
26149
26151
|
const page = document.getPage(input.page - 1);
|
|
26150
26152
|
if (input.marks.length === 0) continue;
|
|
26151
26153
|
const annots = pageAnnots(document.context, page);
|
|
26152
|
-
for (const mark of input.marks)
|
|
26154
|
+
for (const mark of input.marks) {
|
|
26155
|
+
const unit = input.unit ?? 1;
|
|
26156
|
+
annots.push(document.context.register(annotation(document.context, mark, input.transform, unit)));
|
|
26157
|
+
}
|
|
26153
26158
|
}
|
|
26154
26159
|
return await document.save();
|
|
26155
26160
|
}
|
|
@@ -50273,7 +50278,7 @@ fn fs_main(in : VertexOutput) -> @location(0) vec4<f32> {
|
|
|
50273
50278
|
});
|
|
50274
50279
|
try {
|
|
50275
50280
|
const pages = markedPages(marks);
|
|
50276
|
-
const annotatedPdf = await annotatePdf(bytes, await annotateInputs(pdf, pages));
|
|
50281
|
+
const annotatedPdf = await annotatePdf(bytes, await annotateInputs(pdf, pages, props.figureUnit));
|
|
50277
50282
|
const saved = await seats.save(address, input, annotatedPdf);
|
|
50278
50283
|
autosave.cancel();
|
|
50279
50284
|
writtenSignature.current = signature(input);
|
|
@@ -50455,14 +50460,15 @@ fn fs_main(in : VertexOutput) -> @location(0) vec4<f32> {
|
|
|
50455
50460
|
* @param pages - the marked pages.
|
|
50456
50461
|
* @returns one input per page, each with its marks and its user-space transform.
|
|
50457
50462
|
*/
|
|
50458
|
-
async function annotateInputs(pdf, pages) {
|
|
50463
|
+
async function annotateInputs(pdf, pages, unitOf) {
|
|
50459
50464
|
const inputs = [];
|
|
50460
50465
|
for (const entry of pages) {
|
|
50461
50466
|
const size = await pdf.size(entry.page);
|
|
50462
50467
|
inputs.push({
|
|
50463
50468
|
page: entry.page,
|
|
50464
50469
|
transform: size.transform,
|
|
50465
|
-
marks: entry.marks
|
|
50470
|
+
marks: entry.marks,
|
|
50471
|
+
unit: unitOf(size.width, size.height)
|
|
50466
50472
|
});
|
|
50467
50473
|
}
|
|
50468
50474
|
return inputs;
|
package/lib/index.js
CHANGED
|
@@ -260,6 +260,19 @@ function annotationTargetsFigure(document, figurePath) {
|
|
|
260
260
|
return basename(document.figure.path).toLowerCase() === basename(figurePath).toLowerCase();
|
|
261
261
|
}
|
|
262
262
|
//#endregion
|
|
263
|
+
//#region src/shared/annotation.ts
|
|
264
|
+
/** Thinnest stroke a mark can be drawn at, as a multiple of the default width. */
|
|
265
|
+
const WEIGHT_MIN = .5;
|
|
266
|
+
/**
|
|
267
|
+
* Hold a stroke weight inside the range the painter can draw.
|
|
268
|
+
*
|
|
269
|
+
* @param value - the weight to hold.
|
|
270
|
+
* @returns the value, pulled to the nearest end of the range.
|
|
271
|
+
*/
|
|
272
|
+
function clampWeight(value) {
|
|
273
|
+
return Math.min(4, Math.max(WEIGHT_MIN, value));
|
|
274
|
+
}
|
|
275
|
+
//#endregion
|
|
263
276
|
//#region src/host/store.ts
|
|
264
277
|
/**
|
|
265
278
|
* Reading and writing one figure's annotation sidecar.
|
|
@@ -332,6 +345,11 @@ function readAnchor(value) {
|
|
|
332
345
|
* @returns the angle in degrees, or undefined when absent.
|
|
333
346
|
* @throws {Error} when the field is present but is not a usable angle.
|
|
334
347
|
*/
|
|
348
|
+
function readWeight(value) {
|
|
349
|
+
if (value === void 0) return void 0;
|
|
350
|
+
if (typeof value !== "number" || !Number.isFinite(value)) throw new Error("annotation mark weight must be a finite multiple of the default width");
|
|
351
|
+
return clampWeight(value);
|
|
352
|
+
}
|
|
335
353
|
function readRotation(value) {
|
|
336
354
|
if (value === void 0) return void 0;
|
|
337
355
|
if (typeof value !== "number" || !Number.isFinite(value)) throw new Error("annotation mark rotation must be a finite number of degrees");
|
|
@@ -377,6 +395,7 @@ function readMark(value, index, figure) {
|
|
|
377
395
|
if (page !== void 0 && figure.pageCount !== void 0 && page > figure.pageCount) throw new Error(`annotation mark ${index} is on page ${page} of a ${figure.pageCount}-page document`);
|
|
378
396
|
const anchor = readAnchor(raw["anchor"]);
|
|
379
397
|
const rotation = readRotation(raw["rotation"]);
|
|
398
|
+
const weight = readWeight(raw["weight"]);
|
|
380
399
|
return {
|
|
381
400
|
id: raw["id"],
|
|
382
401
|
kind,
|
|
@@ -385,6 +404,7 @@ function readMark(value, index, figure) {
|
|
|
385
404
|
...typeof raw["detail"] === "string" ? { detail: raw["detail"] } : {},
|
|
386
405
|
...page === void 0 ? {} : { page },
|
|
387
406
|
...rotation === void 0 ? {} : { rotation },
|
|
407
|
+
...weight === void 0 ? {} : { weight },
|
|
388
408
|
...anchor === void 0 ? {} : { anchor }
|
|
389
409
|
};
|
|
390
410
|
}
|
package/market/index.json
CHANGED