@knowvah/dot-engine 2.12.2 → 2.12.4
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/api.js +12 -2
- package/dist/api.js.map +2 -2
- package/dist/common/clust-map.d.ts +16 -0
- package/dist/common/clust-map.d.ts.map +1 -0
- package/dist/common/compass-port.d.ts.map +1 -1
- package/dist/common/graph-init.d.ts.map +1 -1
- package/dist/common/htmltable-emit.d.ts +9 -6
- package/dist/common/htmltable-emit.d.ts.map +1 -1
- package/dist/common/htmltable-label.d.ts.map +1 -1
- package/dist/common/htmltable-lex.d.ts +3 -1
- package/dist/common/htmltable-lex.d.ts.map +1 -1
- package/dist/common/htmltable-parse-image.d.ts +23 -0
- package/dist/common/htmltable-parse-image.d.ts.map +1 -0
- package/dist/common/htmltable-parse-state.d.ts +4 -0
- package/dist/common/htmltable-parse-state.d.ts.map +1 -1
- package/dist/common/htmltable-parse.d.ts +33 -2
- package/dist/common/htmltable-parse.d.ts.map +1 -1
- package/dist/common/layers.d.ts +9 -0
- package/dist/common/layers.d.ts.map +1 -1
- package/dist/common/poly-gencode.d.ts.map +1 -1
- package/dist/common/poly-inside.d.ts.map +1 -1
- package/dist/common/splines-geom.d.ts +2 -1
- package/dist/common/splines-geom.d.ts.map +1 -1
- package/dist/common/splines-routespl.d.ts +3 -0
- package/dist/common/splines-routespl.d.ts.map +1 -1
- package/dist/common/xlabels-place.d.ts.map +1 -1
- package/dist/gvc/anchor.d.ts +17 -19
- package/dist/gvc/anchor.d.ts.map +1 -1
- package/dist/gvc/device-cluster.d.ts +9 -0
- package/dist/gvc/device-cluster.d.ts.map +1 -1
- package/dist/gvc/device.d.ts +2 -1
- package/dist/gvc/device.d.ts.map +1 -1
- package/dist/gvc/emit-walk.d.ts +7 -0
- package/dist/gvc/emit-walk.d.ts.map +1 -1
- package/dist/gvc/job.d.ts +13 -6
- package/dist/gvc/job.d.ts.map +1 -1
- package/dist/gvc/viewport.d.ts +14 -0
- package/dist/gvc/viewport.d.ts.map +1 -1
- package/dist/index.js +21767 -21607
- package/dist/index.js.map +4 -4
- package/dist/layout/dot/classify.d.ts.map +1 -1
- package/dist/layout/dot/compound.d.ts +0 -4
- package/dist/layout/dot/compound.d.ts.map +1 -1
- package/dist/layout/dot/edge-route-chain-views.d.ts +35 -0
- package/dist/layout/dot/edge-route-chain-views.d.ts.map +1 -0
- package/dist/layout/dot/edge-route-chain.d.ts +20 -16
- package/dist/layout/dot/edge-route-chain.d.ts.map +1 -1
- package/dist/layout/dot/edge-route-faithful.d.ts.map +1 -1
- package/dist/layout/dot/flat.d.ts +22 -7
- package/dist/layout/dot/flat.d.ts.map +1 -1
- package/dist/layout/dot/mincross-flat.d.ts +10 -1
- package/dist/layout/dot/mincross-flat.d.ts.map +1 -1
- package/dist/layout/dot/mincross.d.ts +6 -1
- package/dist/layout/dot/mincross.d.ts.map +1 -1
- package/dist/layout/dot/ns-subtree.d.ts +9 -6
- package/dist/layout/dot/ns-subtree.d.ts.map +1 -1
- package/dist/layout/dot/pack-components.d.ts +4 -3
- package/dist/layout/dot/pack-components.d.ts.map +1 -1
- package/dist/layout/dot/position-aux.d.ts +62 -20
- package/dist/layout/dot/position-aux.d.ts.map +1 -1
- package/dist/layout/dot/position-bbox.d.ts.map +1 -1
- package/dist/layout/dot/position-ycoords.d.ts.map +1 -1
- package/dist/layout/dot/position.d.ts.map +1 -1
- package/dist/layout/dot/rank-dot2.d.ts +7 -25
- package/dist/layout/dot/rank-dot2.d.ts.map +1 -1
- package/dist/layout/dot/self-loop.d.ts +11 -4
- package/dist/layout/dot/self-loop.d.ts.map +1 -1
- package/dist/layout/dot/splines-flat-multi.d.ts +11 -3
- package/dist/layout/dot/splines-flat-multi.d.ts.map +1 -1
- package/dist/layout/dot/splines-route.d.ts +6 -3
- package/dist/layout/dot/splines-route.d.ts.map +1 -1
- package/dist/layout/dot/straight-edges.d.ts.map +1 -1
- package/dist/layout/fdp/cluster-edges.d.ts.map +1 -1
- package/dist/layout/fdp/tlayout.d.ts +3 -0
- package/dist/layout/fdp/tlayout.d.ts.map +1 -1
- package/dist/layout/neato/__fixtures__/hier-imds.d.ts +5 -4
- package/dist/layout/neato/__fixtures__/hier-imds.d.ts.map +1 -1
- package/dist/layout/neato/__fixtures__/hier-majorization.d.ts +6 -5
- package/dist/layout/neato/__fixtures__/hier-majorization.d.ts.map +1 -1
- package/dist/layout/neato/conjgrad.d.ts +7 -6
- package/dist/layout/neato/conjgrad.d.ts.map +1 -1
- package/dist/layout/neato/matrix-ops-dense.d.ts +1 -6
- package/dist/layout/neato/matrix-ops-dense.d.ts.map +1 -1
- package/dist/layout/neato/matrix-ops.d.ts +0 -6
- package/dist/layout/neato/matrix-ops.d.ts.map +1 -1
- package/dist/layout/neato/quad-prog-vpsc.d.ts.map +1 -1
- package/dist/model/cgraph-ops.d.ts +7 -0
- package/dist/model/cgraph-ops.d.ts.map +1 -1
- package/dist/model/graph.d.ts +12 -2
- package/dist/model/graph.d.ts.map +1 -1
- package/dist/model/rankEntry.d.ts +3 -1
- package/dist/model/rankEntry.d.ts.map +1 -1
- package/dist/ortho/index.d.ts +0 -1
- package/dist/ortho/index.d.ts.map +1 -1
- package/dist/ortho/partition.d.ts +2 -4
- package/dist/ortho/partition.d.ts.map +1 -1
- package/dist/parser/builder.d.ts +11 -10
- package/dist/parser/builder.d.ts.map +1 -1
- package/dist/parser/graph-attr-syms.d.ts +35 -0
- package/dist/parser/graph-attr-syms.d.ts.map +1 -0
- package/dist/pathplan/route.d.ts +93 -0
- package/dist/pathplan/route.d.ts.map +1 -1
- package/dist/render/dot/agwrite.d.ts +27 -16
- package/dist/render/dot/agwrite.d.ts.map +1 -1
- package/dist/render/dot/attrs.d.ts +5 -0
- package/dist/render/dot/attrs.d.ts.map +1 -1
- package/dist/render/dot/types.d.ts +7 -2
- package/dist/render/dot/types.d.ts.map +1 -1
- package/dist/render/json-cluster-edge.d.ts +3 -2
- package/dist/render/json-cluster-edge.d.ts.map +1 -1
- package/dist/render/json.d.ts +7 -1
- package/dist/render/json.d.ts.map +1 -1
- package/dist/render/map.d.ts +14 -10
- package/dist/render/map.d.ts.map +1 -1
- package/dist/render/svg-graph.d.ts.map +1 -1
- package/dist/render/svg-id.d.ts +9 -0
- package/dist/render/svg-id.d.ts.map +1 -1
- package/dist/render.js +22009 -21849
- package/dist/render.js.map +4 -4
- package/dist/util/overflow.d.ts +37 -0
- package/dist/util/overflow.d.ts.map +1 -0
- package/dist/util/printf-round.d.ts +8 -0
- package/dist/util/printf-round.d.ts.map +1 -1
- package/package.json +3 -2
- package/src/common/clust-map.ts +58 -0
- package/src/common/compass-port.ts +36 -20
- package/src/common/graph-init.ts +11 -1
- package/src/common/htmltable-emit.ts +87 -7
- package/src/common/htmltable-label.ts +9 -4
- package/src/common/htmltable-lex.ts +5 -2
- package/src/common/htmltable-parse-image.ts +69 -0
- package/src/common/htmltable-parse-state.ts +6 -0
- package/src/common/htmltable-parse.ts +34 -44
- package/src/common/layers.ts +25 -4
- package/src/common/poly-gencode.ts +3 -11
- package/src/common/poly-inside.ts +11 -5
- package/src/common/splines-geom.ts +24 -6
- package/src/common/splines-routespl.ts +32 -0
- package/src/common/xlabels-place.ts +22 -4
- package/src/gvc/__fixtures__/rerender/abom-shift-pack.dot.plain.nofree.1 +19 -19
- package/src/gvc/__fixtures__/rerender/abom-shift-pack.dot.plain.nofree.2 +19 -19
- package/src/gvc/__fixtures__/rerender/abom-shift-pack.dot.plain.nofree.3 +19 -19
- package/src/gvc/__fixtures__/rerender/abom-shift-parity.dot.plain.nofree.2 +18 -18
- package/src/gvc/__fixtures__/rerender/abom-shift-parity.dot.plain.nofree.3 +12 -12
- package/src/gvc/__fixtures__/rerender/flat-rev-stale.dot.plain.nofree.1 +20 -20
- package/src/gvc/__fixtures__/rerender/flat-rev-stale.dot.plain.nofree.2 +31 -31
- package/src/gvc/__fixtures__/rerender/flat-rev-stale.dot.plain.nofree.3 +33 -33
- package/src/gvc/__fixtures__/rerender/multi-edge.dot.plain.nofree.1 +10 -10
- package/src/gvc/__fixtures__/rerender/multi-edge.dot.plain.nofree.2 +28 -28
- package/src/gvc/__fixtures__/rerender/multi-edge.dot.plain.nofree.3 +28 -28
- package/src/gvc/__fixtures__/rerender/multi-edge.dot.svg.nofree.1 +21 -28
- package/src/gvc/__fixtures__/rerender/multi-edge.dot.svg.nofree.2 +100 -102
- package/src/gvc/__fixtures__/rerender/multi-edge.dot.svg.nofree.3 +137 -139
- package/src/gvc/__fixtures__/rerender/nestedclust.dot.dot.nofree.1 +1 -1
- package/src/gvc/__fixtures__/rerender/nestedclust.dot.dot.nofree.2 +1 -1
- package/src/gvc/__fixtures__/rerender/nestedclust.dot.dot.nofree.3 +1 -1
- package/src/gvc/__fixtures__/rerender/nestedclust.dot.xdot.nofree.1 +3 -3
- package/src/gvc/__fixtures__/rerender/nestedclust.dot.xdot.nofree.2 +3 -3
- package/src/gvc/__fixtures__/rerender/nestedclust.dot.xdot.nofree.3 +3 -3
- package/src/gvc/__fixtures__/rerender/regen.sh +6 -0
- package/src/gvc/anchor.ts +18 -30
- package/src/gvc/device-cluster.ts +16 -0
- package/src/gvc/device.ts +20 -20
- package/src/gvc/emit-walk.ts +11 -1
- package/src/gvc/job.ts +17 -9
- package/src/gvc/viewport.ts +27 -6
- package/src/layout/dot/classify.ts +5 -2
- package/src/layout/dot/compound.ts +1 -21
- package/src/layout/dot/edge-route-chain-views.ts +120 -0
- package/src/layout/dot/edge-route-chain.ts +103 -117
- package/src/layout/dot/edge-route-faithful.ts +20 -5
- package/src/layout/dot/flat.ts +38 -17
- package/src/layout/dot/mincross-flat.ts +15 -5
- package/src/layout/dot/mincross.ts +6 -2
- package/src/layout/dot/ns-subtree.ts +11 -7
- package/src/layout/dot/pack-components.ts +6 -4
- package/src/layout/dot/position-aux.ts +112 -39
- package/src/layout/dot/position-bbox.ts +14 -1
- package/src/layout/dot/position-ycoords.ts +7 -1
- package/src/layout/dot/position.ts +4 -1
- package/src/layout/dot/rank-dot2.ts +13 -94
- package/src/layout/dot/self-loop.ts +29 -11
- package/src/layout/dot/splines-flat-multi.ts +12 -4
- package/src/layout/dot/splines-route.ts +10 -11
- package/src/layout/dot/straight-edges.ts +5 -3
- package/src/layout/fdp/cluster-edges.ts +2 -23
- package/src/layout/fdp/tlayout.ts +6 -5
- package/src/layout/neato/__fixtures__/conjgrad-d.json +1 -0
- package/src/layout/neato/__fixtures__/dim/hier-big-dim3.dot +141 -141
- package/src/layout/neato/__fixtures__/dim/hier-big-dim3.xdot +339 -339
- package/src/layout/neato/__fixtures__/dim/hier-big-dim4.dot +140 -140
- package/src/layout/neato/__fixtures__/dim/hier-big-dim4.xdot +323 -323
- package/src/layout/neato/__fixtures__/dim/hier-big-subset-dim3.dot +141 -141
- package/src/layout/neato/__fixtures__/dim/hier-big-subset-dim3.xdot +339 -339
- package/src/layout/neato/__fixtures__/dim/hier-big110-dim3.dot +251 -251
- package/src/layout/neato/__fixtures__/dim/hier-big110-dim3.xdot +535 -535
- package/src/layout/neato/__fixtures__/dim/hier-circuit-dim3.dot +14 -14
- package/src/layout/neato/__fixtures__/dim/hier-circuit-dim3.xdot +32 -32
- package/src/layout/neato/__fixtures__/dim/hier-dim4.dot +8 -8
- package/src/layout/neato/__fixtures__/dim/hier-dim4.xdot +14 -14
- package/src/layout/neato/__fixtures__/dim/hier-len-dim3.dot +17 -17
- package/src/layout/neato/__fixtures__/dim/hier-len-dim3.xdot +35 -35
- package/src/layout/neato/__fixtures__/dim/hier-noedge-big.dot +2 -2
- package/src/layout/neato/__fixtures__/dim/hier-noedge-big.xdot +2 -2
- package/src/layout/neato/__fixtures__/dim/hier-ring-dim3.dot +11 -11
- package/src/layout/neato/__fixtures__/dim/hier-ring-dim3.xdot +21 -21
- package/src/layout/neato/__fixtures__/dim/hier-star-dim3.dot +14 -14
- package/src/layout/neato/__fixtures__/dim/hier-star-dim3.xdot +26 -26
- package/src/layout/neato/__fixtures__/dim/hier-stresswt1-dim4.dot +13 -13
- package/src/layout/neato/__fixtures__/dim/hier-stresswt1-dim4.xdot +30 -30
- package/src/layout/neato/__fixtures__/dim/hier-subset-dim3.dot +10 -10
- package/src/layout/neato/__fixtures__/dim/hier-subset-dim3.xdot +19 -19
- package/src/layout/neato/__fixtures__/dim/smart-units.json +1 -1
- package/src/layout/neato/__fixtures__/hier/cases/dirnone.plain +10 -10
- package/src/layout/neato/__fixtures__/hier/cases/tdist.plain +12 -12
- package/src/layout/neato/__fixtures__/hier/hier-probe.plain +1 -1
- package/src/layout/neato/__fixtures__/hier/hier-probe.xdot +19 -19
- package/src/layout/neato/__fixtures__/hier-imds.ts +14 -13
- package/src/layout/neato/__fixtures__/hier-majorization.ts +24 -23
- package/src/layout/neato/__fixtures__/ipsep/ipsep-grid.xdot +20 -20
- package/src/layout/neato/__fixtures__/ipsep/ipsep-k6.xdot +8 -8
- package/src/layout/neato/__fixtures__/ipsep/ipsep-rand-len.xdot +34 -34
- package/src/layout/neato/__fixtures__/ipsep/ipsep-rand.xdot +32 -32
- package/src/layout/neato/__fixtures__/ipsep/ipsep-tree.xdot +18 -18
- package/src/layout/neato/__fixtures__/ipsep/kd-ipsep-len.xdot +13 -13
- package/src/layout/neato/__fixtures__/ipsep/kd-ipsep.xdot +12 -12
- package/src/layout/neato/__fixtures__/models/hier-circuit.xdot +33 -33
- package/src/layout/neato/__fixtures__/models/hier-default.xdot +30 -30
- package/src/layout/neato/__fixtures__/models/hier-mds-nolen.xdot +30 -30
- package/src/layout/neato/__fixtures__/models/hier-pin-disc-circuit.xdot +35 -35
- package/src/layout/neato/__fixtures__/models/hier-shortpath.xdot +30 -30
- package/src/layout/neato/conjgrad.ts +38 -35
- package/src/layout/neato/matrix-ops-dense.ts +2 -20
- package/src/layout/neato/matrix-ops.ts +0 -20
- package/src/layout/neato/quad-prog-vpsc.ts +7 -5
- package/src/layout/neato/smart-ini-x.ts +15 -15
- package/src/layout/neato/stress-subspace.ts +5 -5
- package/src/layout/sfdp/__fixtures__/dim/dim3-dimen3.dot +6 -6
- package/src/layout/sfdp/__fixtures__/dim/dim3.dot +6 -6
- package/src/layout/sfdp/__fixtures__/dim/dim4-dimen4.dot +6 -6
- package/src/layout/sfdp/__fixtures__/dim/overlap-prism-dim3.dot +6 -6
- package/src/layout/sfdp/__fixtures__/dim/regen.sh +2 -0
- package/src/model/cgraph-ops.ts +12 -0
- package/src/model/graph.ts +13 -2
- package/src/model/rankEntry.ts +3 -1
- package/src/ortho/index.ts +0 -1
- package/src/ortho/partition.ts +10 -22
- package/src/parser/builder.ts +67 -100
- package/src/parser/graph-attr-syms.ts +62 -0
- package/src/pathplan/route.ts +14 -4
- package/src/render/dot/agwrite.ts +47 -27
- package/src/render/dot/attrs.ts +6 -2
- package/src/render/dot/types.ts +7 -2
- package/src/render/json-cluster-edge.ts +8 -4
- package/src/render/json.ts +15 -8
- package/src/render/map.ts +49 -58
- package/src/render/svg-cluster.ts +3 -3
- package/src/render/svg-graph.ts +1 -3
- package/src/render/svg-helpers.ts +6 -6
- package/src/render/svg-id.ts +23 -5
- package/src/util/overflow.ts +74 -0
- package/src/util/printf-round.ts +11 -0
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Overflow-checked arithmetic helpers.
|
|
3
|
+
*
|
|
4
|
+
* @see lib/util/overflow.h
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Add two integers, clamping to lower and upper type bounds.
|
|
8
|
+
*
|
|
9
|
+
* Returns the sum `a + b`, or `INT_MAX`/`INT_MIN` on overflow/underflow. C's
|
|
10
|
+
* operands are `int`; the port applies the same three branches to its numbers
|
|
11
|
+
* as they are, with no int32 wrap of the inputs.
|
|
12
|
+
* @see lib/util/overflow.h:sadd_saturate
|
|
13
|
+
*/
|
|
14
|
+
export declare function saddSaturate(a: number, b: number): number;
|
|
15
|
+
/**
|
|
16
|
+
* Divide two double floating-point values, checking for overflow.
|
|
17
|
+
*
|
|
18
|
+
* Returns the quotient `n / d`, or `null` where C returns `true` and leaves
|
|
19
|
+
* `*res` as it was: the quotient is not finite (a zero or subnormal divisor,
|
|
20
|
+
* a non-finite operand, or a result past `DBL_MAX`). A call site writes C's
|
|
21
|
+
* "assign the fallback, then overwrite on success" as `fdivOverflow(n, d) ??
|
|
22
|
+
* fallback`; a zero quotient is a result, and `??` keeps it.
|
|
23
|
+
* @see lib/util/overflow.h:fdiv_overflow
|
|
24
|
+
*/
|
|
25
|
+
export declare function fdivOverflow(n: number, d: number): number | null;
|
|
26
|
+
/**
|
|
27
|
+
* Divide two floating-point values, checking for overflow.
|
|
28
|
+
*
|
|
29
|
+
* The `float` twin of {@link fdivOverflow}. C's parameters and quotient are
|
|
30
|
+
* `float`, so the operands and the quotient are rounded to float32: a
|
|
31
|
+
* quotient past `FLT_MAX` is an overflow here though it is finite as a
|
|
32
|
+
* double. Dividing two float32 values in double and rounding once gives
|
|
33
|
+
* IEEE single division's result (53 >= 2 * 24 + 2 bits).
|
|
34
|
+
* @see lib/util/overflow.h:fdivf_overflow
|
|
35
|
+
*/
|
|
36
|
+
export declare function fdivfOverflow(n: number, d: number): number | null;
|
|
37
|
+
//# sourceMappingURL=overflow.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"overflow.d.ts","sourceRoot":"","sources":["../../src/util/overflow.ts"],"names":[],"mappings":"AACA;;;;GAIG;AAMH;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAYzD;AAED;;;;;;;;;GASG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAShE;AAED;;;;;;;;;GASG;AACH,wBAAgB,aAAa,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CASjE"}
|
|
@@ -28,6 +28,14 @@
|
|
|
28
28
|
* @see lib/gvc/gvdevice.c:gvprintdouble
|
|
29
29
|
*/
|
|
30
30
|
export declare function printfFixed(v: number, decimals: number): string;
|
|
31
|
+
/**
|
|
32
|
+
* Format `v` as C's `%.0f` would: `printfFixed(v, 0)`, except that an exact
|
|
33
|
+
* negative zero keeps its sign and prints `-0`, as printf does. A negative
|
|
34
|
+
* value that rounds to zero already prints `-0` in both.
|
|
35
|
+
*
|
|
36
|
+
* @see plugin/core/gvrender_core_map.c:map_output_shape ("%.0f")
|
|
37
|
+
*/
|
|
38
|
+
export declare function printfFixed0(v: number): string;
|
|
31
39
|
/**
|
|
32
40
|
* Format `v` with `sig` significant digits, using the same notational
|
|
33
41
|
* contract as `Number.prototype.toPrecision(sig)` — fixed form when the
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"printf-round.d.ts","sourceRoot":"","sources":["../../src/util/printf-round.ts"],"names":[],"mappings":"AACA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAuEH;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAkB/D;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,SAAS,CAAC,CAAC,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAmCxD"}
|
|
1
|
+
{"version":3,"file":"printf-round.d.ts","sourceRoot":"","sources":["../../src/util/printf-round.ts"],"names":[],"mappings":"AACA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAuEH;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAkB/D;AAED;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAE9C;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,SAAS,CAAC,CAAC,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAmCxD"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@knowvah/dot-engine",
|
|
3
|
-
"version": "2.12.
|
|
3
|
+
"version": "2.12.4",
|
|
4
4
|
"description": "Faithful TypeScript port of Graphviz (dot, neato, fdp, sfdp, circo, twopi, osage, patchwork) — no C: no native binary, no WASM. Oracle-verified against the C implementation, runs in the browser.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"graphviz",
|
|
@@ -65,9 +65,10 @@
|
|
|
65
65
|
"typecheck": "tsc --noEmit --stableTypeOrdering",
|
|
66
66
|
"pretypecheck:ts7": "npm run parser:regen",
|
|
67
67
|
"typecheck:ts7": "tsgo --noEmit",
|
|
68
|
+
"codeql:gate": "bash test/tools/codeql-gate.sh",
|
|
68
69
|
"parser:regen": "peggy --format es --dts src/parser/dot.pegjs -o src/parser/dot.js",
|
|
69
70
|
"survey:setup": "sh test/corpus/gen-headless-gvbindir.sh",
|
|
70
|
-
"survey": "npm run survey:setup &&
|
|
71
|
+
"survey": "npm run survey:setup && PARITY_OUT=parity-rules.json tsx test/corpus/survey.ts",
|
|
71
72
|
"survey:fast": "SURVEY_MAX_PORT_MS=${SURVEY_MAX_PORT_MS:-60000} npm run survey",
|
|
72
73
|
"survey:gate": "tsx test/corpus/rules-gate.ts",
|
|
73
74
|
"survey:dashboard": "tsx test/corpus/dashboard.ts",
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
// SPDX-License-Identifier: EPL-2.0
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The flat cluster-name map dot's compound edges and fdp's cluster edges look
|
|
5
|
+
* cluster endpoints up in. cgraph keeps subgraph names per parent, so two
|
|
6
|
+
* clusters in the tree can share a name; C keeps the first and warns.
|
|
7
|
+
*
|
|
8
|
+
* @see lib/common/utils.c:fillMap, mkClustMap (1498-1525)
|
|
9
|
+
* @see lib/cgraph/id.c:agnameof
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import type { Graph } from '../model/graph.js';
|
|
13
|
+
import { LOCALNAMEPREFIX } from '../model/cgraph-ops.js';
|
|
14
|
+
import { agwarningf } from './agerr.js';
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* fillMap's state across the recursion. `anonKeyed` stands for C's key alias:
|
|
18
|
+
* agnameof returns one static buffer for every anonymous graph, and fillMap
|
|
19
|
+
* stores that pointer as the key, so once an anonymous cluster is in the map,
|
|
20
|
+
* every later anonymous cluster's dtmatch finds it. A cluster is anonymous
|
|
21
|
+
* here when its name starts with LOCALNAMEPREFIX, the test the dot writer
|
|
22
|
+
* uses; a source name `"%x"` is stored by cgraph and not aliased in C (#194).
|
|
23
|
+
* @see lib/cgraph/id.c:agnameof (static buf, 161-164)
|
|
24
|
+
*/
|
|
25
|
+
interface ClustMapState { map: Map<string, Graph>; anonKeyed: boolean }
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Map every cluster's name to its subgraph, preorder over the cluster tree
|
|
29
|
+
* (info.clust, 0-based here for C's GD_clust[1..n]). A second cluster with a
|
|
30
|
+
* name already in the map is ignored, with a warning.
|
|
31
|
+
* @see lib/common/utils.c:fillMap
|
|
32
|
+
*/
|
|
33
|
+
function fillMap(g: Graph, st: ClustMapState): void {
|
|
34
|
+
const n = g.info.n_cluster ?? 0;
|
|
35
|
+
for (let c = 0; c < n; c++) {
|
|
36
|
+
const cl = g.info.clust![c]!;
|
|
37
|
+
const s = cl.name;
|
|
38
|
+
const anon = s.startsWith(LOCALNAMEPREFIX);
|
|
39
|
+
if (st.map.has(s) || (anon && st.anonKeyed)) {
|
|
40
|
+
agwarningf(`Two clusters named ${s} - the second will be ignored`);
|
|
41
|
+
} else {
|
|
42
|
+
st.map.set(s, cl);
|
|
43
|
+
if (anon) st.anonKeyed = true;
|
|
44
|
+
}
|
|
45
|
+
fillMap(cl, st);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Build the name-to-cluster map for g's cluster tree. Assumes g's cluster
|
|
51
|
+
* tree (info.n_cluster, info.clust) is already built.
|
|
52
|
+
* @see lib/common/utils.c:mkClustMap
|
|
53
|
+
*/
|
|
54
|
+
export function mkClustMap(g: Graph): Map<string, Graph> {
|
|
55
|
+
const st: ClustMapState = { map: new Map<string, Graph>(), anonKeyed: false };
|
|
56
|
+
fillMap(g, st);
|
|
57
|
+
return st.map;
|
|
58
|
+
}
|
|
@@ -111,27 +111,40 @@ function invflipSide(side: number, rankdir: number): number {
|
|
|
111
111
|
|
|
112
112
|
// ---------------------------------------------------------------------------
|
|
113
113
|
// invflipAngle helpers
|
|
114
|
-
// @see lib/common/shapes.c:invflip_angle (line
|
|
114
|
+
// @see lib/common/shapes.c:invflip_angle (line 2607)
|
|
115
115
|
// ---------------------------------------------------------------------------
|
|
116
116
|
|
|
117
|
+
/** The RANKDIR_RL arm of invflip_angle, on ¼×π units; no match leaves the angle unchanged. */
|
|
117
118
|
function invflipAngleRL(angle: number): number {
|
|
118
|
-
if (angle ===
|
|
119
|
-
if (angle ===
|
|
120
|
-
if (angle ===
|
|
121
|
-
if (angle === 0)
|
|
122
|
-
if (angle ===
|
|
123
|
-
if (angle ===
|
|
119
|
+
if (angle === 4) return -2;
|
|
120
|
+
if (angle === 3) return -1;
|
|
121
|
+
if (angle === 2) return 0;
|
|
122
|
+
if (angle === 0) return 2;
|
|
123
|
+
if (angle === -1) return 3;
|
|
124
|
+
if (angle === -2) return 4;
|
|
124
125
|
return angle;
|
|
125
126
|
}
|
|
126
127
|
|
|
127
|
-
/**
|
|
128
|
+
/**
|
|
129
|
+
* Adjust theta for rankdir.
|
|
130
|
+
* @param angle Angle in units of ¼×π (C's `int`)
|
|
131
|
+
* @returns Computed angle in radians
|
|
132
|
+
* @see lib/common/shapes.c:invflip_angle (line 2607)
|
|
133
|
+
*/
|
|
128
134
|
function invflipAngle(angle: number, rankdir: number): number {
|
|
135
|
+
let a = angle;
|
|
129
136
|
switch (rankdir) {
|
|
130
|
-
case RANKDIR_BT:
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
137
|
+
case RANKDIR_BT:
|
|
138
|
+
// C: `angle *= -1` on an int, where 0 stays 0. In JS `-a` and `a * -1`
|
|
139
|
+
// turn 0 into -0, which would survive the conversion below; `0 - a`
|
|
140
|
+
// keeps it +0.
|
|
141
|
+
a = 0 - a;
|
|
142
|
+
break;
|
|
143
|
+
case RANKDIR_LR: a -= 2; break;
|
|
144
|
+
case RANKDIR_RL: a = invflipAngleRL(a); break;
|
|
145
|
+
default: break; // RANKDIR_TB: identity
|
|
134
146
|
}
|
|
147
|
+
return a * 0.25 * Math.PI;
|
|
135
148
|
}
|
|
136
149
|
|
|
137
150
|
// ---------------------------------------------------------------------------
|
|
@@ -165,7 +178,10 @@ function compassBbox(n: Node, bp: Box | null): BboxResult {
|
|
|
165
178
|
// ---------------------------------------------------------------------------
|
|
166
179
|
|
|
167
180
|
type DirectionResult = {
|
|
168
|
-
p: Point;
|
|
181
|
+
p: Point;
|
|
182
|
+
/** C's `int theta`, in units of ¼×π; invflipAngle converts it to radians. */
|
|
183
|
+
theta: number;
|
|
184
|
+
side: number;
|
|
169
185
|
constrain: boolean; clip: boolean; dyna: boolean;
|
|
170
186
|
defined: boolean; rv: number;
|
|
171
187
|
};
|
|
@@ -188,9 +204,9 @@ function dirUnrecognized(p: Point): DirectionResult {
|
|
|
188
204
|
function dirN(rest: string, b: Box, ctr: Point, sides: number): DirectionResult {
|
|
189
205
|
const base = { constrain: true, clip: false, dyna: false };
|
|
190
206
|
switch (rest) {
|
|
191
|
-
case '': return { ...base, p: { x: ctr.x, y: b.ur.y }, theta:
|
|
192
|
-
case 'e': return { ...base, p: { x: b.ur.x, y: b.ur.y }, theta:
|
|
193
|
-
case 'w': return { ...base, p: { x: b.ll.x, y: b.ur.y }, theta:
|
|
207
|
+
case '': return { ...base, p: { x: ctr.x, y: b.ur.y }, theta: 2, side: sides & TOP, defined: true, rv: 0 };
|
|
208
|
+
case 'e': return { ...base, p: { x: b.ur.x, y: b.ur.y }, theta: 1, side: sides & (TOP | RIGHT), defined: true, rv: 0 };
|
|
209
|
+
case 'w': return { ...base, p: { x: b.ll.x, y: b.ur.y }, theta: 3, side: sides & (TOP | LEFT), defined: true, rv: 0 };
|
|
194
210
|
default: return dirUnrecognized({ x: ctr.x, y: ctr.y });
|
|
195
211
|
}
|
|
196
212
|
}
|
|
@@ -198,9 +214,9 @@ function dirN(rest: string, b: Box, ctr: Point, sides: number): DirectionResult
|
|
|
198
214
|
function dirS(rest: string, b: Box, ctr: Point, sides: number): DirectionResult {
|
|
199
215
|
const base = { constrain: true, clip: false, dyna: false };
|
|
200
216
|
switch (rest) {
|
|
201
|
-
case '': return { ...base, p: { x: ctr.x, y: b.ll.y }, theta: -
|
|
202
|
-
case 'e': return { ...base, p: { x: b.ur.x, y: b.ll.y }, theta: -
|
|
203
|
-
case 'w': return { ...base, p: { x: b.ll.x, y: b.ll.y }, theta: -
|
|
217
|
+
case '': return { ...base, p: { x: ctr.x, y: b.ll.y }, theta: -2, side: sides & BOTTOM, defined: true, rv: 0 };
|
|
218
|
+
case 'e': return { ...base, p: { x: b.ur.x, y: b.ll.y }, theta: -1, side: sides & (BOTTOM | RIGHT), defined: true, rv: 0 };
|
|
219
|
+
case 'w': return { ...base, p: { x: b.ll.x, y: b.ll.y }, theta: -3, side: sides & (BOTTOM | LEFT), defined: true, rv: 0 };
|
|
204
220
|
default: return dirUnrecognized({ x: ctr.x, y: ctr.y });
|
|
205
221
|
}
|
|
206
222
|
}
|
|
@@ -212,7 +228,7 @@ function dirE(rest: string, b: Box, ctr: Point, sides: number): DirectionResult
|
|
|
212
228
|
|
|
213
229
|
function dirW(rest: string, b: Box, ctr: Point, sides: number): DirectionResult {
|
|
214
230
|
if (rest.length > 0) return dirUnrecognized(ctr);
|
|
215
|
-
return { p: { x: b.ll.x, y: ctr.y }, theta:
|
|
231
|
+
return { p: { x: b.ll.x, y: ctr.y }, theta: 4, side: sides & LEFT, constrain: true, clip: false, dyna: false, defined: true, rv: 0 };
|
|
216
232
|
}
|
|
217
233
|
|
|
218
234
|
// ---------------------------------------------------------------------------
|
package/src/common/graph-init.ts
CHANGED
|
@@ -29,6 +29,7 @@ import type { RatioKind } from '../model/layoutParams.js';
|
|
|
29
29
|
import { doGraphLabel } from '../layout/dot/graph-label.js';
|
|
30
30
|
import { mapbool, setClType, LOCAL, GLOBAL, NOCLUST } from '../layout/dot/rank.js';
|
|
31
31
|
import { cround } from './arith.js';
|
|
32
|
+
import { d2i } from '../util/math.js';
|
|
32
33
|
import { agwarningf } from './agerr.js';
|
|
33
34
|
import { setImageHooks, setImagePath } from './safefile.js';
|
|
34
35
|
|
|
@@ -119,10 +120,19 @@ function maptoken(p: string | undefined, names: string[], vals: number[]): numbe
|
|
|
119
120
|
* `nodesep` is a plain late_double; `ranksep` additionally honours the
|
|
120
121
|
* `equally` keyword (→ exact_ranksep) and a bare number that may be followed
|
|
121
122
|
* by text. Absent attrs yield POINTS(DEFAULT_*) = 18 / 36.
|
|
123
|
+
*
|
|
124
|
+
* GD_nodesep is an `int` (types.h), and POINTS is `(int)(f + .5)`: past
|
|
125
|
+
* INT_MAX that conversion is undefined in C, and the oracle's arm64 build
|
|
126
|
+
* saturates it (scalar fcvtzs). `d2i` is that saturation. Evidence: corpus
|
|
127
|
+
* 2758 (`nodesep=40000000`, 2.88e9 pt) makes native 16.1.1 report an aux
|
|
128
|
+
* edge of `2147483701.000000`, INT_MAX plus two 27-pt half widths (issue
|
|
129
|
+
* #162). Only nodesep is saturated here: the other POINTS sites (ranksep,
|
|
130
|
+
* size, page) have no such evidence.
|
|
122
131
|
* @see lib/common/input.c:665-681
|
|
123
132
|
*/
|
|
124
133
|
function parseSepAttrs(g: Graph): void {
|
|
125
|
-
|
|
134
|
+
// `points` already rounded, so d2i's truncation changes nothing below INT_MAX.
|
|
135
|
+
g.info.nodesep = d2i(points(lateDouble(g.attrs.get('nodesep'), DEFAULT_NODESEP, MIN_NODESEP)));
|
|
126
136
|
const p = g.attrs.get('ranksep');
|
|
127
137
|
let xf = DEFAULT_RANKSEP;
|
|
128
138
|
if (p !== undefined && p !== '') {
|
|
@@ -4,7 +4,8 @@
|
|
|
4
4
|
* HTML label rendering: emits a positioned HTML label (cell borders,
|
|
5
5
|
* text runs, table border) through the renderer plugin.
|
|
6
6
|
*
|
|
7
|
-
* emitHtmlLabel is the port of
|
|
7
|
+
* emitHtmlLabel is the port of emit_html_label (its obj push and pop).
|
|
8
|
+
* emitHtmlTbl is the port of emit_html_tbl.
|
|
8
9
|
* emitHtmlCell is the port of emit_html_cell.
|
|
9
10
|
*
|
|
10
11
|
* Decoration (bgcolor fill, per-side borders, anchors, rules) fires
|
|
@@ -12,6 +13,9 @@
|
|
|
12
13
|
* PlacedCell / PlacedHtml — mirroring C's conditional structure.
|
|
13
14
|
* Undecorated tables emit identically to before T6.
|
|
14
15
|
*
|
|
16
|
+
* @see lib/common/htmltable.c:emit_html_label
|
|
17
|
+
* @see lib/common/htmltable.c:allocObj
|
|
18
|
+
* @see lib/common/htmltable.c:freeObj
|
|
15
19
|
* @see lib/common/htmltable.c:emit_html_tbl
|
|
16
20
|
* @see lib/common/htmltable.c:emit_html_cell
|
|
17
21
|
* @see lib/common/htmltable.c:emit_htextspans
|
|
@@ -23,8 +27,8 @@
|
|
|
23
27
|
*/
|
|
24
28
|
|
|
25
29
|
import type { Point, Box } from '../model/geom.js';
|
|
26
|
-
import type { RenderJob } from '../gvc/job.js';
|
|
27
|
-
import { EMIT_CLUSTERS_LAST } from '../gvc/job.js';
|
|
30
|
+
import type { RenderJob, ObjState } from '../gvc/job.js';
|
|
31
|
+
import { EMIT_CLUSTERS_LAST, createObjState } from '../gvc/job.js';
|
|
28
32
|
import type { RendererPlugin } from '../gvc/context.js';
|
|
29
33
|
import type { TextSpan } from './emit-types.js';
|
|
30
34
|
import type { PlacedHtml, PlacedCell, PlacedLine, PlacedImage } from './htmltable-pos.js';
|
|
@@ -244,7 +248,7 @@ export function emitHtmlCell(
|
|
|
244
248
|
if (cell.nested !== undefined) {
|
|
245
249
|
// C: emit_html_cell recurses emit_html_tbl for an HTML_TBL child.
|
|
246
250
|
// @see lib/common/htmltable.c:emit_html_cell
|
|
247
|
-
|
|
251
|
+
emitHtmlTbl(cell.nested, pos, renderer, job);
|
|
248
252
|
} else if (cell.image !== undefined) {
|
|
249
253
|
emitHtmlImg(cell.image, pos, renderer, job);
|
|
250
254
|
} else {
|
|
@@ -254,7 +258,7 @@ export function emitHtmlCell(
|
|
|
254
258
|
}
|
|
255
259
|
|
|
256
260
|
// ---------------------------------------------------------------------------
|
|
257
|
-
//
|
|
261
|
+
// emitHtmlTbl — port of emit_html_tbl
|
|
258
262
|
// ---------------------------------------------------------------------------
|
|
259
263
|
|
|
260
264
|
/** Emit vrule/hrule rules for all ruled cells. */
|
|
@@ -276,14 +280,15 @@ function emitTableRules(
|
|
|
276
280
|
}
|
|
277
281
|
|
|
278
282
|
/**
|
|
279
|
-
* Emit a fully positioned HTML table label
|
|
283
|
+
* Emit a fully positioned HTML table: a label's top-level table, or one
|
|
284
|
+
* nested in a cell.
|
|
280
285
|
*
|
|
281
286
|
* Draw order mirrors C emit_html_tbl:
|
|
282
287
|
* 1. Open anchor 2. Table BGCOLOR 3. Rules 4. Border 5. Cells 6. Close anchor
|
|
283
288
|
*
|
|
284
289
|
* @see lib/common/htmltable.c:emit_html_tbl
|
|
285
290
|
*/
|
|
286
|
-
|
|
291
|
+
function emitHtmlTbl(
|
|
287
292
|
placed: PlacedHtml,
|
|
288
293
|
pos: Point,
|
|
289
294
|
renderer: RendererPlugin,
|
|
@@ -322,3 +327,78 @@ export function emitHtmlLabel(
|
|
|
322
327
|
endHtmlAnchor(renderer, job);
|
|
323
328
|
}
|
|
324
329
|
}
|
|
330
|
+
|
|
331
|
+
// ---------------------------------------------------------------------------
|
|
332
|
+
// emitHtmlLabel — port of emit_html_label
|
|
333
|
+
// ---------------------------------------------------------------------------
|
|
334
|
+
|
|
335
|
+
/**
|
|
336
|
+
* Push a new obj on the stack, used in common by all the label's html
|
|
337
|
+
* elements with anchors. It takes the paint fields push_obj_state defaults to
|
|
338
|
+
* the parent's, and inherits the parent's type, emit_state and object, and its
|
|
339
|
+
* url, tooltip, target and explicit_tooltip. Not its id, label or map points:
|
|
340
|
+
* a cell's emit_map_rect writes this obj's points, never the owner's.
|
|
341
|
+
* `parent` is job.obj (C reads it back as obj->parent), narrowed by the caller.
|
|
342
|
+
*
|
|
343
|
+
* @see lib/common/htmltable.c:allocObj
|
|
344
|
+
* @see lib/common/emit.c:push_obj_state
|
|
345
|
+
*/
|
|
346
|
+
function allocObj(job: RenderJob, parent: ObjState): void {
|
|
347
|
+
const obj = createObjState(parent.type);
|
|
348
|
+
obj.parent = parent;
|
|
349
|
+
obj.penColor = parent.penColor;
|
|
350
|
+
obj.fillColor = parent.fillColor;
|
|
351
|
+
obj.pen = parent.pen;
|
|
352
|
+
obj.fill = parent.fill;
|
|
353
|
+
obj.penWidth = parent.penWidth;
|
|
354
|
+
obj.gradientAngle = parent.gradientAngle;
|
|
355
|
+
obj.stopColor = parent.stopColor;
|
|
356
|
+
obj.emitState = parent.emitState;
|
|
357
|
+
obj.graphObj = parent.graphObj;
|
|
358
|
+
obj.url = parent.url;
|
|
359
|
+
obj.tooltip = parent.tooltip;
|
|
360
|
+
obj.target = parent.target;
|
|
361
|
+
obj.explicitTooltip = parent.explicitTooltip;
|
|
362
|
+
job.pushObj(obj);
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
/**
|
|
366
|
+
* Pop the label's obj. C clears url, tooltip, target and id first so that
|
|
367
|
+
* pop_obj_state does not free the parent's strings; nothing to do here.
|
|
368
|
+
*
|
|
369
|
+
* @see lib/common/htmltable.c:freeObj
|
|
370
|
+
*/
|
|
371
|
+
function freeObj(job: RenderJob): void {
|
|
372
|
+
job.popObj();
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
/**
|
|
376
|
+
* Emit a fully positioned HTML table label in its own obj state, so nothing
|
|
377
|
+
* the label writes on the obj (a cell's map rect) reaches the label's owner.
|
|
378
|
+
* The obj stack is as deep on return as on entry, even when the label throws.
|
|
379
|
+
*
|
|
380
|
+
* @see lib/common/htmltable.c:emit_html_label
|
|
381
|
+
*/
|
|
382
|
+
export function emitHtmlLabel(
|
|
383
|
+
placed: PlacedHtml,
|
|
384
|
+
pos: Point,
|
|
385
|
+
renderer: RendererPlugin,
|
|
386
|
+
job: RenderJob,
|
|
387
|
+
): void {
|
|
388
|
+
const parent = job.obj;
|
|
389
|
+
if (parent === null) {
|
|
390
|
+
// C always has an enclosing obj here (root, cluster, node or edge). The
|
|
391
|
+
// port's label emitters also run on a bare job with an empty obj stack
|
|
392
|
+
// (withLabelEmitState and gvrenderTextspan take `job.obj === null`; the
|
|
393
|
+
// renderOneLabel and renderClusterLabel cases of device.test.ts): with no
|
|
394
|
+
// owner there is nothing to shield, so emit without a push.
|
|
395
|
+
emitHtmlTbl(placed, pos, renderer, job);
|
|
396
|
+
return;
|
|
397
|
+
}
|
|
398
|
+
allocObj(job, parent);
|
|
399
|
+
try {
|
|
400
|
+
emitHtmlTbl(placed, pos, renderer, job);
|
|
401
|
+
} finally {
|
|
402
|
+
freeObj(job);
|
|
403
|
+
}
|
|
404
|
+
}
|
|
@@ -19,7 +19,7 @@ import { HtmlLexError } from './htmltable-lex.js';
|
|
|
19
19
|
import { labelStderr, type StderrLines } from './htmltable-attr-warn.js';
|
|
20
20
|
import { posHtmlLabel, type HtmlFontInfo, type PlacedHtml } from './htmltable-pos.js';
|
|
21
21
|
|
|
22
|
-
/** parseHTML's rv
|
|
22
|
+
/** parseHTML's rv once htmlerror or the lexer printed an error (`ctx->error`), with or without a label. */
|
|
23
23
|
const HTML_PARSE_FATAL = 3;
|
|
24
24
|
|
|
25
25
|
/** A built HTML label plus make_html_label's "problem" return value. */
|
|
@@ -48,9 +48,14 @@ export function makeHtmlLabelTo(
|
|
|
48
48
|
stderr: StderrLines,
|
|
49
49
|
): HtmlLabelResult {
|
|
50
50
|
const { fontname, fontsize, fontcolor, imageSizer, imageResolver, imageDpi, pencolor } = finfo;
|
|
51
|
-
let lbl: HtmlLabel,
|
|
51
|
+
let lbl: HtmlLabel, lexRv: number; // lexRv: clearHTMLlexer's `ctx->error ? 3 : ctx->warn`
|
|
52
52
|
try {
|
|
53
|
-
|
|
53
|
+
const parsed = parseHtmlLabelRv(content, stderr);
|
|
54
|
+
lbl = parsed.label;
|
|
55
|
+
// An error a rule reported without YYABORT (the image rule's) leaves the
|
|
56
|
+
// label: it is sized and drawn, and rv 3 makes make_label name the object.
|
|
57
|
+
// @see lib/common/htmllex.c:clearHTMLlexer
|
|
58
|
+
lexRv = parsed.error ? HTML_PARSE_FATAL : Number(parsed.warn);
|
|
54
59
|
} catch (e) {
|
|
55
60
|
// C aborts the HTML parse on a syntax error (YYABORT): parseHTML returns
|
|
56
61
|
// rv 3 (ctx->error) with no label, and make_html_label returns it with
|
|
@@ -63,7 +68,7 @@ export function makeHtmlLabelTo(
|
|
|
63
68
|
// which then flows table->cell->nested-table.
|
|
64
69
|
// @see lib/common/htmltable.c:1911 (getPenColor), :1406/:1556 (inheritance)
|
|
65
70
|
if (lbl.kind === 'table') inheritTablePenColor(lbl.table, pencolor);
|
|
66
|
-
const rv =
|
|
71
|
+
const rv = lexRv | sizeHtmlLabel(lbl, measurer, {
|
|
67
72
|
fontsize, fontname, imageSizer, imageResolver, imageDpi, stderr,
|
|
68
73
|
});
|
|
69
74
|
const placed = posHtmlLabel(lbl, { fontname, fontsize, fontcolor }, measurer);
|
|
@@ -161,11 +161,14 @@ const SYNTAX_ERROR = 'syntax error';
|
|
|
161
161
|
*/
|
|
162
162
|
export class HtmlLexError extends HtmlParseError {
|
|
163
163
|
readonly diagnostics: readonly string[];
|
|
164
|
+
/** Printed by `lexerror`, which unlike htmlerror and the expat path prints even when `ctx->error` is set. */
|
|
165
|
+
readonly unguarded: boolean;
|
|
164
166
|
|
|
165
|
-
constructor(tag: string, message: string, diagnostics: readonly string[]) {
|
|
167
|
+
constructor(tag: string, message: string, diagnostics: readonly string[], unguarded = false) {
|
|
166
168
|
super(tag);
|
|
167
169
|
this.message = message;
|
|
168
170
|
this.diagnostics = diagnostics;
|
|
171
|
+
this.unguarded = unguarded;
|
|
169
172
|
}
|
|
170
173
|
}
|
|
171
174
|
|
|
@@ -260,7 +263,7 @@ function checkTagToken(site: TokenSite): void {
|
|
|
260
263
|
}
|
|
261
264
|
if (KNOWN_TAGS.has(tag.name.toUpperCase())) return;
|
|
262
265
|
const text = `Unknown HTML element <${tag.name}> on line ${lineAt(src, tok.start)} `;
|
|
263
|
-
throw new HtmlLexError(tag.name.toUpperCase(), text, [`Error: ${text}`]);
|
|
266
|
+
throw new HtmlLexError(tag.name.toUpperCase(), text, [`Error: ${text}`], true);
|
|
264
267
|
}
|
|
265
268
|
|
|
266
269
|
/** The tokens one expat event gives the parser, after the errors C would hit. */
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
// SPDX-License-Identifier: EPL-2.0
|
|
2
|
+
/**
|
|
3
|
+
* The `image` rule of an HTML-like label's cell. Strings may stand before and
|
|
4
|
+
* after `<IMG>`: blank ones are ignored, and one with a non-space character is
|
|
5
|
+
* reported through `htmlerror` without `YYABORT`, so the parse goes on and the
|
|
6
|
+
* label keeps its image (parseHTML's rv is 3 with a label).
|
|
7
|
+
*
|
|
8
|
+
* @see lib/common/htmlparse.y:338-356
|
|
9
|
+
* @see lib/common/htmllex.c:52-59
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import type { HtmlCellContent, HtmlImage, OpenToken, Token } from './htmltable-types.js';
|
|
13
|
+
import type { ParseState } from './htmltable-parse-state.js';
|
|
14
|
+
import { consume, consumedTag, emitWarnings, peek } from './htmltable-parse-state.js';
|
|
15
|
+
import { htmlErrorAtToken } from './htmltable-lex.js';
|
|
16
|
+
import type { CellScan } from './htmltable-parse.js';
|
|
17
|
+
import { MSG_SYNTAX_ERROR, consumeClose, parseError, skipStrings } from './htmltable-parse.js';
|
|
18
|
+
|
|
19
|
+
/** @see lib/common/htmlparse.y:340 (image rule, mid-rule action) */
|
|
20
|
+
const MSG_TEXT_BEFORE_IMG = 'Syntax error: non-space string used before <IMG>';
|
|
21
|
+
/** @see lib/common/htmlparse.y:343 (image rule, final action) */
|
|
22
|
+
const MSG_TEXT_AFTER_IMG = 'Syntax error: non-space string used after <IMG>';
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* `htmlerror` called from a rule action that does not abort: with `tok` the
|
|
26
|
+
* lookahead the lexer last returned, print the message and its context unless
|
|
27
|
+
* an error was printed before, and set `ctx->error`. The lexer ran for `tok`
|
|
28
|
+
* first, so that token's warnings come out ahead of the message. Without a
|
|
29
|
+
* lookahead the lexer failed fetching it and set `ctx->error` itself, so its
|
|
30
|
+
* own error is the one reported.
|
|
31
|
+
* @see lib/common/htmllex.c:htmlerror
|
|
32
|
+
*/
|
|
33
|
+
const softError = (s: ParseState, tok: Token | undefined, message: string): void => {
|
|
34
|
+
if (tok === undefined) throw parseError(s, tok, message);
|
|
35
|
+
emitWarnings(s, tok);
|
|
36
|
+
if (s.error === true) return;
|
|
37
|
+
s.error = true;
|
|
38
|
+
for (const line of htmlErrorAtToken(message, tok)?.diagnostics ?? []) s.stderr?.write(`${line}\n`);
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
/** `T_img T_end_img` or `T_IMG`: the element itself. */
|
|
42
|
+
const parseImgContent = (s: ParseState, t: OpenToken): HtmlImage => {
|
|
43
|
+
consume(s);
|
|
44
|
+
const img: HtmlImage = {
|
|
45
|
+
kind: 'image',
|
|
46
|
+
src: t.attrs['src'] ?? '',
|
|
47
|
+
scale: t.attrs['scale'],
|
|
48
|
+
};
|
|
49
|
+
consumeClose(s, 'IMG');
|
|
50
|
+
return img;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* `image : opt_space T_IMG opt_space` as the cell's only child, entered at the
|
|
55
|
+
* IMG token. The leading `opt_space` is strings alone, so an IMG that follows
|
|
56
|
+
* a tag is a syntax error. Its nonSpace check runs with the IMG as lookahead.
|
|
57
|
+
* The trailing `opt_space` reduces at whatever token follows the strings, and
|
|
58
|
+
* the rule's final action runs there by default reduction: its check is
|
|
59
|
+
* reported at that token even when the token then fails the cell rule.
|
|
60
|
+
* @see lib/common/htmlparse.y:338-356
|
|
61
|
+
*/
|
|
62
|
+
export const scanCellImage = (s: ParseState, t: OpenToken, st: CellScan): HtmlCellContent[] => {
|
|
63
|
+
if (consumedTag(s, st.start)) throw parseError(s, t, MSG_SYNTAX_ERROR);
|
|
64
|
+
if (st.textNonSpace) softError(s, t, MSG_TEXT_BEFORE_IMG);
|
|
65
|
+
st.kind = 'image';
|
|
66
|
+
const img = parseImgContent(s, t);
|
|
67
|
+
if (skipStrings(s)) softError(s, peek(s), MSG_TEXT_AFTER_IMG);
|
|
68
|
+
return [img];
|
|
69
|
+
};
|
|
@@ -25,10 +25,16 @@ export interface ParseState {
|
|
|
25
25
|
warn?: boolean;
|
|
26
26
|
/** What the lexer wrote after its last token, printed when the parser asks for more. */
|
|
27
27
|
eof?: LexerOutput;
|
|
28
|
+
/** `ctx->error`: htmlerror printed from a rule that went on parsing; the label's rv is 3. */
|
|
29
|
+
error?: boolean;
|
|
28
30
|
}
|
|
29
31
|
|
|
30
32
|
export const peek = (s: ParseState): Token | undefined => s.tokens[s.pos];
|
|
31
33
|
|
|
34
|
+
/** True when a tag, not only strings, was consumed since `start` (an `opt_space` is strings alone). */
|
|
35
|
+
export const consumedTag = (s: ParseState, start: number): boolean =>
|
|
36
|
+
s.tokens.slice(start, s.pos).some((t) => t.type !== 'text');
|
|
37
|
+
|
|
32
38
|
/**
|
|
33
39
|
* Print what the C lexer wrote while lexing `tok`, once, and fold its `warn`
|
|
34
40
|
* into the label's rv.
|