@bitbybit-dev/base 0.19.9 → 0.20.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/api/inputs/base-inputs.d.ts +35 -0
- package/lib/api/inputs/base-inputs.js +19 -1
- package/lib/api/inputs/dates-inputs.d.ts +216 -0
- package/lib/api/inputs/dates-inputs.js +271 -0
- package/lib/api/inputs/index.d.ts +1 -0
- package/lib/api/inputs/index.js +1 -0
- package/lib/api/inputs/inputs.d.ts +1 -0
- package/lib/api/inputs/inputs.js +1 -0
- package/lib/api/inputs/point-inputs.d.ts +23 -0
- package/lib/api/inputs/point-inputs.js +22 -0
- package/lib/api/inputs/text-inputs.d.ts +106 -0
- package/lib/api/inputs/text-inputs.js +141 -0
- package/lib/api/inputs/vector-inputs.d.ts +20 -0
- package/lib/api/inputs/vector-inputs.js +21 -0
- package/lib/api/models/index.d.ts +1 -0
- package/lib/api/models/index.js +1 -0
- package/lib/api/models/simplex.d.ts +206 -0
- package/lib/api/models/simplex.js +112 -0
- package/lib/api/models/text/bucket.d.ts +2 -0
- package/lib/api/models/text/bucket.js +2 -0
- package/lib/api/models/text/index.d.ts +1 -0
- package/lib/api/models/text/index.js +1 -0
- package/lib/api/models/text/vector-char-data.d.ts +19 -0
- package/lib/api/models/text/vector-char-data.js +13 -0
- package/lib/api/models/text/vector-text-data.d.ts +19 -0
- package/lib/api/models/text/vector-text-data.js +13 -0
- package/lib/api/services/dates.d.ts +367 -0
- package/lib/api/services/dates.js +450 -0
- package/lib/api/services/index.d.ts +1 -0
- package/lib/api/services/index.js +1 -0
- package/lib/api/services/point.d.ts +21 -1
- package/lib/api/services/point.js +79 -1
- package/lib/api/services/text.d.ts +24 -0
- package/lib/api/services/text.js +157 -0
- package/lib/api/services/vector.d.ts +9 -0
- package/lib/api/services/vector.js +11 -0
- package/package.json +1 -1
package/lib/api/services/text.js
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
|
+
import * as Inputs from "../inputs";
|
|
2
|
+
import { defaultsVectorParams } from "../models/simplex";
|
|
1
3
|
/**
|
|
2
4
|
* Contains various text methods.
|
|
3
5
|
*/
|
|
4
6
|
export class TextBitByBit {
|
|
7
|
+
constructor(point) {
|
|
8
|
+
this.point = point;
|
|
9
|
+
}
|
|
5
10
|
/**
|
|
6
11
|
* Creates a text
|
|
7
12
|
* @param inputs a text
|
|
@@ -81,4 +86,156 @@ export class TextBitByBit {
|
|
|
81
86
|
return typeof inputs.values[number] !== "undefined" ? inputs.values[number] : match;
|
|
82
87
|
});
|
|
83
88
|
}
|
|
89
|
+
/**
|
|
90
|
+
* Creates a vector segments for character and includes width and height information
|
|
91
|
+
* @param inputs a text
|
|
92
|
+
* @returns width, height and segments as json
|
|
93
|
+
* @group vector
|
|
94
|
+
* @shortname vector char
|
|
95
|
+
* @drawable false
|
|
96
|
+
*/
|
|
97
|
+
vectorChar(inputs) {
|
|
98
|
+
const { xOffset, yOffset, font, input, height, extrudeOffset } = this.vectorParamsChar(inputs);
|
|
99
|
+
let code = input.charCodeAt(0);
|
|
100
|
+
if (!code || !font[code]) {
|
|
101
|
+
code = 63;
|
|
102
|
+
}
|
|
103
|
+
const glyph = [].concat(font[code]);
|
|
104
|
+
const ratio = (height - extrudeOffset) / font.height;
|
|
105
|
+
const extrudeYOffset = (extrudeOffset / 2);
|
|
106
|
+
const width = glyph.shift() * ratio;
|
|
107
|
+
const paths = [];
|
|
108
|
+
let polyline = [];
|
|
109
|
+
for (let i = 0, il = glyph.length; i < il; i += 2) {
|
|
110
|
+
const gx = ratio * glyph[i] + xOffset;
|
|
111
|
+
const gy = ratio * glyph[i + 1] + yOffset + extrudeYOffset;
|
|
112
|
+
if (glyph[i] !== undefined) {
|
|
113
|
+
polyline.push([gx, 0, gy]);
|
|
114
|
+
continue;
|
|
115
|
+
}
|
|
116
|
+
paths.push(polyline);
|
|
117
|
+
polyline = [];
|
|
118
|
+
i--;
|
|
119
|
+
}
|
|
120
|
+
if (polyline.length) {
|
|
121
|
+
paths.push(polyline);
|
|
122
|
+
}
|
|
123
|
+
return { width, height, paths };
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Creates a vector text lines for a given text and includes width and height information
|
|
127
|
+
* @param inputs a text as string
|
|
128
|
+
* @returns segments
|
|
129
|
+
* @group vector
|
|
130
|
+
* @shortname vector text
|
|
131
|
+
* @drawable false
|
|
132
|
+
*/
|
|
133
|
+
vectorText(inputs) {
|
|
134
|
+
const { xOffset, yOffset, height, align, extrudeOffset, lineSpacing, letterSpacing } = Object.assign({}, defaultsVectorParams, inputs);
|
|
135
|
+
const text = inputs.text;
|
|
136
|
+
if (typeof text !== "string")
|
|
137
|
+
throw new Error("text must be a string");
|
|
138
|
+
// NOTE: Just like CSS letter-spacing, the spacing could be positive or negative
|
|
139
|
+
const extraLetterSpacing = (height * letterSpacing);
|
|
140
|
+
// manage the list of lines
|
|
141
|
+
let maxWidth = 0; // keep track of max width for final alignment
|
|
142
|
+
let line = { width: 0, height: 0, chars: [] };
|
|
143
|
+
let lines = [];
|
|
144
|
+
const pushLine = () => {
|
|
145
|
+
maxWidth = Math.max(maxWidth, line.width);
|
|
146
|
+
if (line.chars.length)
|
|
147
|
+
lines.push(line);
|
|
148
|
+
line = { width: 0, height: 0, chars: [] };
|
|
149
|
+
};
|
|
150
|
+
// convert the text into a list of vector lines
|
|
151
|
+
let x = xOffset;
|
|
152
|
+
let y = yOffset;
|
|
153
|
+
let vchar;
|
|
154
|
+
const il = text.length;
|
|
155
|
+
for (let i = 0; i < il; i++) {
|
|
156
|
+
const character = text[i];
|
|
157
|
+
if (character === "\n") {
|
|
158
|
+
pushLine();
|
|
159
|
+
// reset x and y for a new line
|
|
160
|
+
x = xOffset;
|
|
161
|
+
y -= height * lineSpacing;
|
|
162
|
+
continue;
|
|
163
|
+
}
|
|
164
|
+
// convert the character
|
|
165
|
+
vchar = this.vectorChar({ xOffset: x, yOffset: y, height, extrudeOffset, char: character });
|
|
166
|
+
const width = vchar.width + extraLetterSpacing;
|
|
167
|
+
x += width;
|
|
168
|
+
// update current line
|
|
169
|
+
line.width += width;
|
|
170
|
+
line.height = Math.max(line.height, vchar.height);
|
|
171
|
+
if (character !== " ") {
|
|
172
|
+
line.chars = line.chars.concat(vchar);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
if (line.chars.length)
|
|
176
|
+
pushLine();
|
|
177
|
+
// align all lines as requested
|
|
178
|
+
lines = lines.map((line) => {
|
|
179
|
+
const diff = maxWidth - line.width;
|
|
180
|
+
if (align === Inputs.Base.horizontalAlignEnum.right) {
|
|
181
|
+
return this.translateLine({ x: diff }, line);
|
|
182
|
+
}
|
|
183
|
+
else if (align === Inputs.Base.horizontalAlignEnum.center) {
|
|
184
|
+
return this.translateLine({ x: diff / 2 }, line);
|
|
185
|
+
}
|
|
186
|
+
else {
|
|
187
|
+
return line;
|
|
188
|
+
}
|
|
189
|
+
});
|
|
190
|
+
if (inputs.centerOnOrigin) {
|
|
191
|
+
const pointsFlat = [];
|
|
192
|
+
// flatten the lines into a single array of points
|
|
193
|
+
lines.forEach((line) => {
|
|
194
|
+
line.chars.forEach((vchar) => {
|
|
195
|
+
vchar.paths.forEach((path) => {
|
|
196
|
+
pointsFlat.push(...path);
|
|
197
|
+
});
|
|
198
|
+
});
|
|
199
|
+
});
|
|
200
|
+
const bbox = this.point.boundingBoxOfPoints({
|
|
201
|
+
points: pointsFlat,
|
|
202
|
+
});
|
|
203
|
+
lines.forEach((line) => {
|
|
204
|
+
line.chars.forEach((vchar) => {
|
|
205
|
+
vchar.paths = vchar.paths.map((path) => {
|
|
206
|
+
const pts = this.point.translatePoints({
|
|
207
|
+
points: path,
|
|
208
|
+
translation: [
|
|
209
|
+
-bbox.center[0],
|
|
210
|
+
-bbox.center[1],
|
|
211
|
+
-bbox.center[2],
|
|
212
|
+
],
|
|
213
|
+
});
|
|
214
|
+
return pts;
|
|
215
|
+
});
|
|
216
|
+
return vchar;
|
|
217
|
+
});
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
return lines;
|
|
221
|
+
}
|
|
222
|
+
vectorParamsChar(inputs) {
|
|
223
|
+
const params = Object.assign({}, defaultsVectorParams, inputs);
|
|
224
|
+
params.input = inputs.char || params.char;
|
|
225
|
+
return params;
|
|
226
|
+
}
|
|
227
|
+
translateLine(options, line) {
|
|
228
|
+
const { x, y } = Object.assign({ x: 0, y: 0 }, options);
|
|
229
|
+
line.chars = line.chars.map((vchar) => {
|
|
230
|
+
vchar.paths = vchar.paths.map((path) => {
|
|
231
|
+
const pts = this.point.translatePoints({
|
|
232
|
+
points: path,
|
|
233
|
+
translation: [x, 0, y],
|
|
234
|
+
});
|
|
235
|
+
return pts;
|
|
236
|
+
});
|
|
237
|
+
return vchar;
|
|
238
|
+
});
|
|
239
|
+
return line;
|
|
240
|
+
}
|
|
84
241
|
}
|
|
@@ -28,6 +28,15 @@ export declare class Vector {
|
|
|
28
28
|
* @drawable false
|
|
29
29
|
*/
|
|
30
30
|
removeConsecutiveDuplicateVectors(inputs: Inputs.Vector.RemoveConsecutiveDuplicateVectorsDto): number[][];
|
|
31
|
+
/**
|
|
32
|
+
* Checks if two vectors are the same within a given tolerance
|
|
33
|
+
* @param inputs Contains two vectors and a tolerance value
|
|
34
|
+
* @returns Boolean indicating if vectors are the same
|
|
35
|
+
* @group validate
|
|
36
|
+
* @shortname vectors the same
|
|
37
|
+
* @drawable false
|
|
38
|
+
*/
|
|
39
|
+
vectorsTheSame(inputs: Inputs.Vector.VectorsTheSameDto): boolean;
|
|
31
40
|
/**
|
|
32
41
|
* Measures the angle between two vectors in degrees
|
|
33
42
|
* @param inputs Contains two vectors represented as number arrays
|
|
@@ -30,6 +30,17 @@ export class Vector {
|
|
|
30
30
|
removeConsecutiveDuplicateVectors(inputs) {
|
|
31
31
|
return this.geometryHelper.removeConsecutiveVectorDuplicates(inputs.vectors, inputs.checkFirstAndLast, inputs.tolerance);
|
|
32
32
|
}
|
|
33
|
+
/**
|
|
34
|
+
* Checks if two vectors are the same within a given tolerance
|
|
35
|
+
* @param inputs Contains two vectors and a tolerance value
|
|
36
|
+
* @returns Boolean indicating if vectors are the same
|
|
37
|
+
* @group validate
|
|
38
|
+
* @shortname vectors the same
|
|
39
|
+
* @drawable false
|
|
40
|
+
*/
|
|
41
|
+
vectorsTheSame(inputs) {
|
|
42
|
+
return this.geometryHelper.vectorsTheSame(inputs.vec1, inputs.vec2, inputs.tolerance);
|
|
43
|
+
}
|
|
33
44
|
/**
|
|
34
45
|
* Measures the angle between two vectors in degrees
|
|
35
46
|
* @param inputs Contains two vectors represented as number arrays
|