@bill_nee/dwg-reader 0.0.0-stage → 1.0.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.
Files changed (99) hide show
  1. package/LICENSE +615 -0
  2. package/cordis.patch.yml +3 -0
  3. package/icon.svg +15 -0
  4. package/lib/index.js +355 -0
  5. package/locale/en.json +6 -0
  6. package/locale/zh.json +6 -0
  7. package/package.json +32 -4
  8. package/vendor/libredwg-web/lib/converter/converter.js +1102 -0
  9. package/vendor/libredwg-web/lib/converter/dwgColorToMLeaderRawColor.js +55 -0
  10. package/vendor/libredwg-web/lib/converter/entityConverter.js +2050 -0
  11. package/vendor/libredwg-web/lib/converter/index.js +3 -0
  12. package/vendor/libredwg-web/lib/converter/utils.js +46 -0
  13. package/vendor/libredwg-web/lib/database/classes/class.js +2 -0
  14. package/vendor/libredwg-web/lib/database/classes/index.js +2 -0
  15. package/vendor/libredwg-web/lib/database/codepage.js +101 -0
  16. package/vendor/libredwg-web/lib/database/common.js +2 -0
  17. package/vendor/libredwg-web/lib/database/database.js +2 -0
  18. package/vendor/libredwg-web/lib/database/entities/3dface.js +2 -0
  19. package/vendor/libredwg-web/lib/database/entities/arc.js +2 -0
  20. package/vendor/libredwg-web/lib/database/entities/arcAlignedText.js +2 -0
  21. package/vendor/libredwg-web/lib/database/entities/attdef.js +2 -0
  22. package/vendor/libredwg-web/lib/database/entities/attrib.js +2 -0
  23. package/vendor/libredwg-web/lib/database/entities/circle.js +2 -0
  24. package/vendor/libredwg-web/lib/database/entities/dimension.js +70 -0
  25. package/vendor/libredwg-web/lib/database/entities/ellipse.js +2 -0
  26. package/vendor/libredwg-web/lib/database/entities/entity.js +2 -0
  27. package/vendor/libredwg-web/lib/database/entities/hatch.js +54 -0
  28. package/vendor/libredwg-web/lib/database/entities/image.js +2 -0
  29. package/vendor/libredwg-web/lib/database/entities/index.js +38 -0
  30. package/vendor/libredwg-web/lib/database/entities/insert.js +2 -0
  31. package/vendor/libredwg-web/lib/database/entities/leader.js +2 -0
  32. package/vendor/libredwg-web/lib/database/entities/line.js +2 -0
  33. package/vendor/libredwg-web/lib/database/entities/lwpolyline.js +2 -0
  34. package/vendor/libredwg-web/lib/database/entities/mline.js +2 -0
  35. package/vendor/libredwg-web/lib/database/entities/mtext.js +2 -0
  36. package/vendor/libredwg-web/lib/database/entities/multileader.js +2 -0
  37. package/vendor/libredwg-web/lib/database/entities/ole2frame.js +2 -0
  38. package/vendor/libredwg-web/lib/database/entities/oleframe.js +2 -0
  39. package/vendor/libredwg-web/lib/database/entities/point.js +2 -0
  40. package/vendor/libredwg-web/lib/database/entities/polyline.js +19 -0
  41. package/vendor/libredwg-web/lib/database/entities/proxy.js +10 -0
  42. package/vendor/libredwg-web/lib/database/entities/ray.js +2 -0
  43. package/vendor/libredwg-web/lib/database/entities/section.js +2 -0
  44. package/vendor/libredwg-web/lib/database/entities/shape.js +2 -0
  45. package/vendor/libredwg-web/lib/database/entities/solid.js +2 -0
  46. package/vendor/libredwg-web/lib/database/entities/solid3d.js +2 -0
  47. package/vendor/libredwg-web/lib/database/entities/spline.js +2 -0
  48. package/vendor/libredwg-web/lib/database/entities/table.js +2 -0
  49. package/vendor/libredwg-web/lib/database/entities/text.js +23 -0
  50. package/vendor/libredwg-web/lib/database/entities/tolerance.js +2 -0
  51. package/vendor/libredwg-web/lib/database/entities/trace.js +2 -0
  52. package/vendor/libredwg-web/lib/database/entities/vertex.js +2 -0
  53. package/vendor/libredwg-web/lib/database/entities/viewport.js +2 -0
  54. package/vendor/libredwg-web/lib/database/entities/wipeout.js +2 -0
  55. package/vendor/libredwg-web/lib/database/entities/xline.js +2 -0
  56. package/vendor/libredwg-web/lib/database/header/header.js +2 -0
  57. package/vendor/libredwg-web/lib/database/header/index.js +3 -0
  58. package/vendor/libredwg-web/lib/database/header/variables.js +217 -0
  59. package/vendor/libredwg-web/lib/database/index.js +12 -0
  60. package/vendor/libredwg-web/lib/database/objects/common.js +2 -0
  61. package/vendor/libredwg-web/lib/database/objects/dictionary.js +19 -0
  62. package/vendor/libredwg-web/lib/database/objects/imageDef.js +2 -0
  63. package/vendor/libredwg-web/lib/database/objects/index.js +11 -0
  64. package/vendor/libredwg-web/lib/database/objects/layerFilter.js +2 -0
  65. package/vendor/libredwg-web/lib/database/objects/layerIndex.js +2 -0
  66. package/vendor/libredwg-web/lib/database/objects/layout.js +2 -0
  67. package/vendor/libredwg-web/lib/database/objects/mleaderStyle.js +2 -0
  68. package/vendor/libredwg-web/lib/database/objects/plotSetting.js +2 -0
  69. package/vendor/libredwg-web/lib/database/objects/spatialFilter.js +2 -0
  70. package/vendor/libredwg-web/lib/database/objects/xrecord.js +2 -0
  71. package/vendor/libredwg-web/lib/database/shared/index.js +2 -0
  72. package/vendor/libredwg-web/lib/database/shared/xdata.js +2 -0
  73. package/vendor/libredwg-web/lib/database/tables/appId.js +2 -0
  74. package/vendor/libredwg-web/lib/database/tables/blockRecord.js +2 -0
  75. package/vendor/libredwg-web/lib/database/tables/dimStyle.js +2 -0
  76. package/vendor/libredwg-web/lib/database/tables/index.js +9 -0
  77. package/vendor/libredwg-web/lib/database/tables/layer.js +2 -0
  78. package/vendor/libredwg-web/lib/database/tables/ltype.js +2 -0
  79. package/vendor/libredwg-web/lib/database/tables/style.js +2 -0
  80. package/vendor/libredwg-web/lib/database/tables/table.js +2 -0
  81. package/vendor/libredwg-web/lib/database/tables/vport.js +2 -0
  82. package/vendor/libredwg-web/lib/database/textEscapes.js +19 -0
  83. package/vendor/libredwg-web/lib/database/version.js +260 -0
  84. package/vendor/libredwg-web/lib/index.js +4 -0
  85. package/vendor/libredwg-web/lib/libredwg.js +1271 -0
  86. package/vendor/libredwg-web/lib/svg/box2d.js +104 -0
  87. package/vendor/libredwg-web/lib/svg/bspline.js +95 -0
  88. package/vendor/libredwg-web/lib/svg/color.js +371 -0
  89. package/vendor/libredwg-web/lib/svg/index.js +2 -0
  90. package/vendor/libredwg-web/lib/svg/polyline.js +70 -0
  91. package/vendor/libredwg-web/lib/svg/svgConverter.js +540 -0
  92. package/vendor/libredwg-web/lib/svg/transformBoundingBoxAndElement.js +20 -0
  93. package/vendor/libredwg-web/lib/svg/vector.js +27 -0
  94. package/vendor/libredwg-web/lib/types/common.js +2 -0
  95. package/vendor/libredwg-web/lib/types/enums.js +390 -0
  96. package/vendor/libredwg-web/lib/types/index.js +3 -0
  97. package/vendor/libredwg-web/wasm/libredwg-web.js +2 -0
  98. package/vendor/libredwg-web/wasm/libredwg-web.wasm +0 -0
  99. package/README.md +0 -3
@@ -0,0 +1,104 @@
1
+ /**
2
+ * Represents a 2D axis-aligned bounding box.
3
+ */
4
+ export class Box2D {
5
+ min;
6
+ max;
7
+ valid;
8
+ constructor() {
9
+ this.min = { x: Infinity, y: Infinity };
10
+ this.max = { x: -Infinity, y: -Infinity };
11
+ this.valid = false;
12
+ }
13
+ /**
14
+ * Expands the bounding box to include a given point.
15
+ *
16
+ * @param point - The point to include in the bounding box.
17
+ * @returns This bounding box after expansion.
18
+ */
19
+ expandByPoint(point) {
20
+ this.min.x = Math.min(this.min.x, point.x);
21
+ this.min.y = Math.min(this.min.y, point.y);
22
+ this.max.x = Math.max(this.max.x, point.x);
23
+ this.max.y = Math.max(this.max.y, point.y);
24
+ this.valid = true;
25
+ return this;
26
+ }
27
+ /**
28
+ * Applies a scaling and translation transformation to this bounding box.
29
+ *
30
+ * @param scale - The scaling factors in x and y directions.
31
+ * @param translation - The translation offsets in x and y directions.
32
+ * @returns This bounding box after transformation.
33
+ */
34
+ transform(scale, translation) {
35
+ const corners = this.getCorners().map(p => ({
36
+ x: p.x * scale.x + translation.x,
37
+ y: p.y * scale.y + translation.y
38
+ }));
39
+ this.reset();
40
+ for (const pt of corners) {
41
+ this.expandByPoint(pt);
42
+ }
43
+ return this;
44
+ }
45
+ /**
46
+ * Applies a rotation around a specific point to this bounding box.
47
+ *
48
+ * @param angleInRad - The angle of rotation in radians.
49
+ * @param point - The center of rotation.
50
+ * @returns This bounding box after rotation.
51
+ */
52
+ rotate(angleInRad, point) {
53
+ const cos = Math.cos(angleInRad);
54
+ const sin = Math.sin(angleInRad);
55
+ const corners = this.getCorners().map(p => {
56
+ const dx = p.x - point.x;
57
+ const dy = p.y - point.y;
58
+ return {
59
+ x: point.x + dx * cos - dy * sin,
60
+ y: point.y + dx * sin + dy * cos
61
+ };
62
+ });
63
+ this.reset();
64
+ for (const pt of corners) {
65
+ this.expandByPoint(pt);
66
+ }
67
+ return this;
68
+ }
69
+ /**
70
+ * Creates a deep copy of this bounding box.
71
+ *
72
+ * @returns A new instance of Box2D with the same properties.
73
+ */
74
+ clone() {
75
+ const box = new Box2D();
76
+ box.min = { x: this.min.x, y: this.min.y };
77
+ box.max = { x: this.max.x, y: this.max.y };
78
+ box.valid = this.valid;
79
+ return box;
80
+ }
81
+ /**
82
+ * Resets this bounding box to its initial unbounded state.
83
+ */
84
+ reset() {
85
+ this.min = { x: Infinity, y: Infinity };
86
+ this.max = { x: -Infinity, y: -Infinity };
87
+ this.valid = false;
88
+ }
89
+ /**
90
+ * Retrieves the four corner points of the bounding box.
91
+ *
92
+ * @returns An array of corner points in the order:
93
+ * bottom-left, top-left, bottom-right, top-right.
94
+ */
95
+ getCorners() {
96
+ return [
97
+ { x: this.min.x, y: this.min.y },
98
+ { x: this.min.x, y: this.max.y },
99
+ { x: this.max.x, y: this.min.y },
100
+ { x: this.max.x, y: this.max.y }
101
+ ];
102
+ }
103
+ }
104
+ //# sourceMappingURL=box2d.js.map
@@ -0,0 +1,95 @@
1
+ /**
2
+ * Copied and ported to code standard as the b-spline library is not maintained any longer.
3
+ * Source:
4
+ * https://github.com/thibauts/b-spline
5
+ * Copyright (c) 2015 Thibaut Séguy <thibaut.seguy@gmail.com>
6
+ *
7
+ * B-spline evaluator with optional weights and knot vector.
8
+ * Returns a point on the curve given parameter t ∈ [0,1].
9
+ */
10
+ export function evaluateBSpline(t, degree, points, knots, weights) {
11
+ const n = points.length; // Number of control points
12
+ if (n === 0)
13
+ throw new Error('points must not be empty');
14
+ const d = points[0].length; // Dimensionality
15
+ if (t < 0 || t > 1) {
16
+ throw new Error(`t out of bounds [0,1]: ${t}`);
17
+ }
18
+ if (degree < 1) {
19
+ throw new Error('degree must be at least 1 (linear)');
20
+ }
21
+ if (degree > n - 1) {
22
+ throw new Error('degree must be less than or equal to point count - 1');
23
+ }
24
+ const weightsSafe = weights ?? new Array(n).fill(1);
25
+ const knotsSafe = knots ??
26
+ (() => {
27
+ const result = [];
28
+ for (let i = 0; i < n + degree + 1; i++) {
29
+ result.push(i);
30
+ }
31
+ return result;
32
+ })();
33
+ if (knotsSafe.length !== n + degree + 1) {
34
+ throw new Error('bad knot vector length');
35
+ }
36
+ const domain = [degree, knotsSafe.length - 1 - degree];
37
+ const low = knotsSafe[domain[0]];
38
+ const high = knotsSafe[domain[1]];
39
+ t = t * (high - low) + low;
40
+ t = Math.max(t, low);
41
+ t = Math.min(t, high);
42
+ let s = domain[0];
43
+ for (; s < domain[1]; s++) {
44
+ if (t >= knotsSafe[s] && t <= knotsSafe[s + 1]) {
45
+ break;
46
+ }
47
+ }
48
+ // Homogeneous coordinates
49
+ const v = new Array(n);
50
+ for (let i = 0; i < n; i++) {
51
+ v[i] = new Array(d + 1);
52
+ for (let j = 0; j < d; j++) {
53
+ v[i][j] = points[i][j] * weightsSafe[i];
54
+ }
55
+ v[i][d] = weightsSafe[i];
56
+ }
57
+ // De Boor algorithm
58
+ for (let l = 1; l <= degree + 1; l++) {
59
+ for (let i = s; i > s - degree - 1 + l; i--) {
60
+ const denom = knotsSafe[i + degree + 1 - l] - knotsSafe[i];
61
+ const alpha = denom === 0 ? 0 : (t - knotsSafe[i]) / denom;
62
+ for (let j = 0; j < d + 1; j++) {
63
+ v[i][j] = (1 - alpha) * v[i - 1][j] + alpha * v[i][j];
64
+ }
65
+ }
66
+ }
67
+ const result = new Array(d);
68
+ for (let i = 0; i < d; i++) {
69
+ result[i] = round10(v[s][i] / v[s][d], -9);
70
+ }
71
+ return result;
72
+ }
73
+ /**
74
+ * Rounds a number to a specified exponent of 10.
75
+ * Equivalent to shifting the decimal point, rounding, then shifting back.
76
+ *
77
+ * @param value - The number to round.
78
+ * @param exp - The exponent (e.g., -1 for 1 decimal place, -9 for nanometers).
79
+ * @returns The rounded number.
80
+ */
81
+ function round10(value, exp) {
82
+ if (exp === 0 || exp === undefined) {
83
+ return Math.round(value);
84
+ }
85
+ if (isNaN(value) || !Number.isInteger(exp)) {
86
+ return NaN;
87
+ }
88
+ // Shift
89
+ const [base, exponent = '0'] = value.toString().split('e');
90
+ const shifted = Math.round(Number(`${base}e${+exponent - exp}`));
91
+ // Shift back
92
+ const [shiftedBase, shiftedExp = '0'] = shifted.toString().split('e');
93
+ return Number(`${shiftedBase}e${+shiftedExp + exp}`);
94
+ }
95
+ //# sourceMappingURL=bspline.js.map
@@ -0,0 +1,371 @@
1
+ const _colorKeywords = {
2
+ aliceblue: 0xf0f8ff,
3
+ antiquewhite: 0xfaebd7,
4
+ aqua: 0x00ffff,
5
+ aquamarine: 0x7fffd4,
6
+ azure: 0xf0ffff,
7
+ beige: 0xf5f5dc,
8
+ bisque: 0xffe4c4,
9
+ black: 0x000000,
10
+ blanchedalmond: 0xffebcd,
11
+ blue: 0x0000ff,
12
+ blueviolet: 0x8a2be2,
13
+ brown: 0xa52a2a,
14
+ burlywood: 0xdeb887,
15
+ cadetblue: 0x5f9ea0,
16
+ chartreuse: 0x7fff00,
17
+ chocolate: 0xd2691e,
18
+ coral: 0xff7f50,
19
+ cornflowerblue: 0x6495ed,
20
+ cornsilk: 0xfff8dc,
21
+ crimson: 0xdc143c,
22
+ cyan: 0x00ffff,
23
+ darkblue: 0x00008b,
24
+ darkcyan: 0x008b8b,
25
+ darkgoldenrod: 0xb8860b,
26
+ darkgray: 0xa9a9a9,
27
+ darkgreen: 0x006400,
28
+ darkkhaki: 0xbdb76b,
29
+ darkmagenta: 0x8b008b,
30
+ darkolivegreen: 0x556b2f,
31
+ darkorange: 0xff8c00,
32
+ darkorchid: 0x9932cc,
33
+ darkred: 0x8b0000,
34
+ darksalmon: 0xe9967a,
35
+ darkseagreen: 0x8fbc8f,
36
+ darkslateblue: 0x483d8b,
37
+ darkslategray: 0x2f4f4f,
38
+ darkturquoise: 0x00ced1,
39
+ darkviolet: 0x9400d3,
40
+ deeppink: 0xff1493,
41
+ deepskyblue: 0x00bfff,
42
+ dimgrey: 0x696969,
43
+ dodgerblue: 0x1e90ff,
44
+ firebrick: 0xb22222,
45
+ floralwhite: 0xfffaf0,
46
+ forestgreen: 0x228b22,
47
+ fuchsia: 0xff00ff,
48
+ gainsboro: 0xdcdcdc,
49
+ ghostwhite: 0xf8f8ff,
50
+ gold: 0xffd700,
51
+ goldenrod: 0xdaa520,
52
+ gray: 0x808080,
53
+ green: 0x008000,
54
+ greenyellow: 0xadff2f,
55
+ grey: 0x808080,
56
+ honeydew: 0xf0fff0,
57
+ hotpink: 0xff69b4,
58
+ indianred: 0xcd5c5c,
59
+ indigo: 0x4b0082,
60
+ ivory: 0xfffff0,
61
+ khaki: 0xf0e68c,
62
+ lavender: 0xe6e6fa,
63
+ lavenderblush: 0xfff0f5,
64
+ lawngreen: 0x7cfc00,
65
+ lemonchiffon: 0xfffacd,
66
+ lightblue: 0xadd8e6,
67
+ lightcoral: 0xf08080,
68
+ lightcyan: 0xe0ffff,
69
+ lightgoldenrodyellow: 0xfafad2,
70
+ lightgray: 0xd3d3d3,
71
+ lightgreen: 0x90ee90,
72
+ lightgrey: 0xd3d3d3,
73
+ lightpink: 0xffb6c1,
74
+ lightsalmon: 0xffa07a,
75
+ lightseagreen: 0x20b2aa,
76
+ lightskyblue: 0x87cefa,
77
+ lightslategray: 0x778899,
78
+ lightslategrey: 0x778899,
79
+ lightsteelblue: 0xb0c4de,
80
+ lightyellow: 0xffffe0,
81
+ lime: 0x00ff00,
82
+ limegreen: 0x32cd32,
83
+ linen: 0xfaf0e6,
84
+ magenta: 0xff00ff,
85
+ maroon: 0x800000,
86
+ mediumaquamarine: 0x66cdaa,
87
+ mediumblue: 0x0000cd,
88
+ mediumorchid: 0xba55d3,
89
+ mediumpurple: 0x9370db,
90
+ mediumseagreen: 0x3cb371,
91
+ mediumslateblue: 0x7b68ee,
92
+ mediumspringgreen: 0x00fa9a,
93
+ mediumturquoise: 0x48d1cc,
94
+ mediumvioletred: 0xc71585,
95
+ midnightblue: 0x191970,
96
+ mintcream: 0xf5fffa,
97
+ mistyrose: 0xffe4e1,
98
+ moccasin: 0xffe4b5,
99
+ navajowhite: 0xffdead,
100
+ navy: 0x000080,
101
+ oldlace: 0xfdf5e6,
102
+ olive: 0x808000,
103
+ olivedrab: 0x6b8e23,
104
+ orange: 0xffa500,
105
+ orangered: 0xff4500,
106
+ orchid: 0xda70d6,
107
+ palegoldenrod: 0xeee8aa,
108
+ palegreen: 0x98fb98,
109
+ paleturquoise: 0xafeeee,
110
+ palevioletred: 0xdb7093,
111
+ papayawhip: 0xffefd5,
112
+ peachpuff: 0xffdab9,
113
+ peru: 0xcd853f,
114
+ pink: 0xffc0cb,
115
+ plum: 0xdda0dd,
116
+ powderblue: 0xb0e0e6,
117
+ purple: 0x800080,
118
+ rebeccapurple: 0x663399,
119
+ red: 0xff0000,
120
+ rosybrown: 0xbc8f8f,
121
+ royalblue: 0x4169e1,
122
+ saddlebrown: 0x8b4513,
123
+ salmon: 0xfa8072,
124
+ sandybrown: 0xf4a460,
125
+ seagreen: 0x2e8b57,
126
+ seashell: 0xfff5ee,
127
+ sienna: 0xa0522d,
128
+ silver: 0xc0c0c0,
129
+ skyblue: 0x87ceeb,
130
+ slateblue: 0x6a5acd,
131
+ slategrey: 0x708090,
132
+ snow: 0xfffafa,
133
+ springgreen: 0x00ff7f,
134
+ steelblue: 0x4682b4,
135
+ tan: 0xd2b48c,
136
+ teal: 0x008080,
137
+ thistle: 0xd8bfd8,
138
+ tomato: 0xff6347,
139
+ turquoise: 0x40e0d0,
140
+ violet: 0xee82ee,
141
+ wheat: 0xf5deb3,
142
+ white: 0xffffff,
143
+ whitesmoke: 0xf5f5f5,
144
+ yellow: 0xffff00,
145
+ yellowgreen: 0x9acd32
146
+ };
147
+ /**
148
+ * AutoCAD files sometimes use an indexed color value between 1 and 255 inclusive.
149
+ * Each value corresponds to a color. index 1 is red, that is 16711680 or 0xFF0000.
150
+ * index 0 and 256, while included in this array, are actually reserved for inheritance
151
+ * values in AutoCAD so they should not be used for index color lookups.
152
+ */
153
+ const AUTO_CAD_COLOR_INDEX = [
154
+ 0, 16711680, 16776960, 65280, 65535, 255, 16711935, 16777215, 8421504,
155
+ 12632256, 16711680, 16744319, 13369344, 13395558, 10027008, 10046540, 8323072,
156
+ 8339263, 4980736, 4990502, 16727808, 16752511, 13382400, 13401958, 10036736,
157
+ 10051404, 8331008, 8343359, 4985600, 4992806, 16744192, 16760703, 13395456,
158
+ 13408614, 10046464, 10056268, 8339200, 8347455, 4990464, 4995366, 16760576,
159
+ 16768895, 13408512, 13415014, 10056192, 10061132, 8347392, 8351551, 4995328,
160
+ 4997670, 16776960, 16777087, 13421568, 13421670, 10000384, 10000460, 8355584,
161
+ 8355647, 5000192, 5000230, 12582656, 14679935, 10079232, 11717734, 7510016,
162
+ 8755276, 6258432, 7307071, 3755008, 4344870, 8388352, 12582783, 6736896,
163
+ 10079334, 5019648, 7510092, 4161280, 6258495, 2509824, 3755046, 4194048,
164
+ 10485631, 3394560, 8375398, 2529280, 6264908, 2064128, 5209919, 1264640,
165
+ 3099686, 65280, 8388479, 52224, 6736998, 38912, 5019724, 32512, 4161343,
166
+ 19456, 2509862, 65343, 8388511, 52275, 6737023, 38950, 5019743, 32543,
167
+ 4161359, 19475, 2509871, 65407, 8388543, 52326, 6737049, 38988, 5019762,
168
+ 32575, 4161375, 19494, 2509881, 65471, 8388575, 52377, 6737074, 39026,
169
+ 5019781, 32607, 4161391, 19513, 2509890, 65535, 8388607, 52428, 6737100,
170
+ 39064, 5019800, 32639, 4161407, 19532, 2509900, 49151, 8380415, 39372,
171
+ 6730444, 29336, 5014936, 24447, 4157311, 14668, 2507340, 32767, 8372223,
172
+ 26316, 6724044, 19608, 5010072, 16255, 4153215, 9804, 2505036, 16383, 8364031,
173
+ 13260, 6717388, 9880, 5005208, 8063, 4149119, 4940, 2502476, 255, 8355839,
174
+ 204, 6710988, 152, 5000344, 127, 4145023, 76, 2500172, 4129023, 10452991,
175
+ 3342540, 8349388, 2490520, 6245528, 2031743, 5193599, 1245260, 3089996,
176
+ 8323327, 12550143, 6684876, 10053324, 4980888, 7490712, 4128895, 6242175,
177
+ 2490444, 3745356, 12517631, 14647295, 10027212, 11691724, 7471256, 8735896,
178
+ 6226047, 7290751, 3735628, 4335180, 16711935, 16744447, 13369548, 13395660,
179
+ 9961624, 9981080, 8323199, 8339327, 4980812, 4990540, 16711871, 16744415,
180
+ 13369497, 13395634, 9961586, 9981061, 8323167, 8339311, 4980793, 4990530,
181
+ 16711807, 16744383, 13369446, 13395609, 9961548, 9981042, 8323135, 8339295,
182
+ 4980774, 4990521, 16711743, 16744351, 13369395, 13395583, 9961510, 9981023,
183
+ 8323103, 8339279, 4980755, 4990511, 3355443, 5987163, 8684676, 11382189,
184
+ 14079702, 16777215, 0
185
+ ];
186
+ function clamp(value, min, max) {
187
+ return Math.max(min, Math.min(max, value));
188
+ }
189
+ export class Color {
190
+ _colorIndex;
191
+ _color;
192
+ _colorName;
193
+ static NAMES = _colorKeywords;
194
+ constructor() {
195
+ this._colorIndex = 256;
196
+ this._color = null;
197
+ this._colorName = null;
198
+ }
199
+ get color() {
200
+ return this._color;
201
+ }
202
+ set color(value) {
203
+ if (value == null) {
204
+ this._color = null;
205
+ }
206
+ else {
207
+ this._color = Math.round(clamp(value, 0, 256 * 256 * 256 - 1));
208
+ this._colorIndex = this.getColorIndexByValue(this._color);
209
+ this._colorName = this.getColorNameByValue(this._color);
210
+ }
211
+ }
212
+ get hexColor() {
213
+ // Ensure the number is a valid RGB value
214
+ if (this._color && this._color > 0 && this._color <= 0xffffff) {
215
+ let hexString = this._color.toString(16).toUpperCase();
216
+ // Pad the string with leading zeros if necessary
217
+ while (hexString.length < 6) {
218
+ hexString = '0' + hexString;
219
+ }
220
+ return `0x${hexString}`;
221
+ }
222
+ return '';
223
+ }
224
+ get cssColor() {
225
+ return `rgb(${this.red},${this.green},${this.blue})`;
226
+ }
227
+ get red() {
228
+ return this.color != null ? (this.color >> 16) & 255 : null;
229
+ }
230
+ get green() {
231
+ return this.color != null ? (this.color >> 8) & 255 : null;
232
+ }
233
+ get blue() {
234
+ return this.color != null ? this.color & 255 : null;
235
+ }
236
+ /**
237
+ * AutoCAD color index value. The index value will be in the range 0 to 256. 0 and 256 are special values.
238
+ * If value less than 0 is set, 0 will be used. If value greater than 256 is set, 256 will be used.
239
+ * - 0 indicates that the entity uses the color of the BlockReference that's displaying it. If the entity
240
+ * is not displayed through a block reference (for example, it is directly owned by the model space
241
+ * block table record) and its color is 0, then it will display as though its color were 7.
242
+ * - 256 indicates that the entity uses the color specified in the layer table record it references.
243
+ */
244
+ get colorIndex() {
245
+ return this._colorIndex;
246
+ }
247
+ set colorIndex(value) {
248
+ if (value == null) {
249
+ this._colorIndex = null;
250
+ }
251
+ else {
252
+ this._colorIndex = clamp(value, 0, 256);
253
+ this._color = AUTO_CAD_COLOR_INDEX[value];
254
+ this._colorName = this.getColorNameByValue(this._color);
255
+ }
256
+ }
257
+ get colorName() {
258
+ return this._colorName;
259
+ }
260
+ set colorName(value) {
261
+ if (value) {
262
+ const color = _colorKeywords[value.toLowerCase()];
263
+ if (color !== undefined) {
264
+ // red
265
+ this._colorName = value;
266
+ this._color = color;
267
+ this._colorIndex = this.getColorIndexByValue(this._color);
268
+ }
269
+ else {
270
+ // unknown color
271
+ console.warn('Unknown color: ' + value);
272
+ }
273
+ }
274
+ else {
275
+ this._colorName = null;
276
+ }
277
+ }
278
+ get hasColorName() {
279
+ return this._colorName == null;
280
+ }
281
+ get hasColorIndex() {
282
+ return this._colorIndex == null;
283
+ }
284
+ get isByLayer() {
285
+ return this.colorIndex == 256;
286
+ }
287
+ setByLayer() {
288
+ this.colorIndex = 256;
289
+ return this;
290
+ }
291
+ get isByBlock() {
292
+ return this.colorIndex == 0;
293
+ }
294
+ setByBlock() {
295
+ this.colorIndex = 0;
296
+ return this;
297
+ }
298
+ setScalar(scalar) {
299
+ this.setRGB(scalar, scalar, scalar);
300
+ return this;
301
+ }
302
+ setRGB(r, g, b) {
303
+ const red = Math.round(clamp(r, 0, 255));
304
+ const green = Math.round(clamp(g, 0, 255));
305
+ const blue = Math.round(clamp(b, 0, 255));
306
+ this.color = (red << 16) + (green << 8) + blue;
307
+ return this;
308
+ }
309
+ setColorName(style) {
310
+ const color = _colorKeywords[style.toLowerCase()];
311
+ if (color !== undefined) {
312
+ // red
313
+ this.color = color;
314
+ }
315
+ else {
316
+ // unknown color
317
+ console.warn('Unknown color ' + style);
318
+ }
319
+ return this;
320
+ }
321
+ clone() {
322
+ const clonedColor = new Color();
323
+ clonedColor.colorIndex = this.colorIndex;
324
+ clonedColor.color = this.color;
325
+ clonedColor._colorName = this._colorName;
326
+ return this;
327
+ }
328
+ copy(color) {
329
+ this.colorIndex = color.colorIndex;
330
+ this.color = color.color;
331
+ this._colorName = color._colorName;
332
+ return this;
333
+ }
334
+ equals(c) {
335
+ return (c.color == this.color &&
336
+ c.colorIndex == this.colorIndex &&
337
+ c._colorName == this._colorName);
338
+ }
339
+ toString() {
340
+ if (this.isByLayer) {
341
+ return 'ByLayer';
342
+ }
343
+ else if (this.isByBlock) {
344
+ return 'ByBlock';
345
+ }
346
+ else if (this.colorName) {
347
+ return this.colorName;
348
+ }
349
+ else {
350
+ return this.hexColor;
351
+ }
352
+ }
353
+ getColorNameByValue(target) {
354
+ for (const [key, value] of Object.entries(_colorKeywords)) {
355
+ if (value === target) {
356
+ return key;
357
+ }
358
+ }
359
+ return null;
360
+ }
361
+ getColorIndexByValue(target) {
362
+ const length = AUTO_CAD_COLOR_INDEX.length - 1;
363
+ for (let index = 1; index < length; ++index) {
364
+ if (AUTO_CAD_COLOR_INDEX[index] === target) {
365
+ return index;
366
+ }
367
+ }
368
+ return null;
369
+ }
370
+ }
371
+ //# sourceMappingURL=color.js.map
@@ -0,0 +1,2 @@
1
+ export * from './svgConverter.js';
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,70 @@
1
+ import { Vector2D } from './vector.js';
2
+ export function createPolylineArcPoints(from, to, bulge, resolution = 5) {
3
+ let theta;
4
+ let a;
5
+ let b;
6
+ if (bulge < 0) {
7
+ theta = Math.atan(-bulge) * 4;
8
+ a = new Vector2D(from.x, from.y);
9
+ b = new Vector2D(to.x, to.y);
10
+ }
11
+ else {
12
+ theta = Math.atan(bulge) * 4;
13
+ a = new Vector2D(to.x, to.y);
14
+ b = new Vector2D(from.x, from.y);
15
+ }
16
+ const ab = b.sub(a);
17
+ const lengthAB = ab.length();
18
+ const c = a.add(ab.multiply(0.5));
19
+ const lengthCD = Math.abs(lengthAB / 2 / Math.tan(theta / 2));
20
+ const normAB = ab.norm();
21
+ const rotated = new Vector2D(normAB.x * Math.cos(Math.PI / 2) - normAB.y * Math.sin(Math.PI / 2), normAB.y * Math.cos(Math.PI / 2) + normAB.x * Math.sin(Math.PI / 2));
22
+ const d = theta < Math.PI
23
+ ? c.add(rotated.multiply(-lengthCD))
24
+ : c.add(rotated.multiply(lengthCD));
25
+ const startAngle = (Math.atan2(b.y - d.y, b.x - d.x) / Math.PI) * 180;
26
+ let endAngle = (Math.atan2(a.y - d.y, a.x - d.x) / Math.PI) * 180;
27
+ if (endAngle < startAngle) {
28
+ endAngle += 360;
29
+ }
30
+ const r = b.sub(d).length();
31
+ const startInter = Math.floor(startAngle / resolution) * resolution + resolution;
32
+ const endInter = Math.ceil(endAngle / resolution) * resolution - resolution;
33
+ const points = [];
34
+ for (let i = startInter; i <= endInter; i += resolution) {
35
+ const angleRad = (i / 180) * Math.PI;
36
+ const point = d.add(new Vector2D(Math.cos(angleRad) * r, Math.sin(angleRad) * r));
37
+ points.push(point);
38
+ }
39
+ if (bulge < 0) {
40
+ points.reverse();
41
+ }
42
+ return points;
43
+ }
44
+ export function interpolatePolyline(entity, closed = false) {
45
+ let points = [];
46
+ const vertices = entity.vertices.map(v => {
47
+ return {
48
+ x: v.x,
49
+ y: v.y,
50
+ bulge: v.bulge
51
+ };
52
+ });
53
+ if (closed) {
54
+ vertices.push(vertices[0]);
55
+ }
56
+ for (let i = 0, len = vertices.length; i < len - 1; ++i) {
57
+ const from = vertices[i];
58
+ const to = vertices[i + 1];
59
+ points.push(from);
60
+ if (vertices[i].bulge) {
61
+ points = points.concat(createPolylineArcPoints(from, to, entity.vertices[i].bulge));
62
+ }
63
+ // The last iteration of the for loop
64
+ if (i === len - 2) {
65
+ points.push(to);
66
+ }
67
+ }
68
+ return points;
69
+ }
70
+ //# sourceMappingURL=polyline.js.map