makerjs 0.18.2 → 0.19.2
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/browser.maker.js +249 -64
- package/dist/index.d.ts +37 -9
- package/dist/index.js +246 -63
- package/package.json +2 -1
- package/LICENSE +0 -202
- package/README.md +0 -172
package/dist/browser.maker.js
CHANGED
|
@@ -39,7 +39,7 @@ and limitations under the License.
|
|
|
39
39
|
* author: Dan Marshall / Microsoft Corporation
|
|
40
40
|
* maintainers: Dan Marshall <danmar@microsoft.com>
|
|
41
41
|
* homepage: https://maker.js.org
|
|
42
|
-
* version: 0.
|
|
42
|
+
* version: 0.19.2
|
|
43
43
|
*
|
|
44
44
|
* browserify:
|
|
45
45
|
* license: MIT (http://opensource.org/licenses/MIT)
|
|
@@ -448,6 +448,7 @@ return kdbush;
|
|
|
448
448
|
})));
|
|
449
449
|
|
|
450
450
|
},{}],"makerjs":[function(require,module,exports){
|
|
451
|
+
(function (global){(function (){
|
|
451
452
|
/**
|
|
452
453
|
* Root module for Maker.js.
|
|
453
454
|
*
|
|
@@ -476,29 +477,35 @@ var MakerJs;
|
|
|
476
477
|
* @private
|
|
477
478
|
*/
|
|
478
479
|
var EPSILON = Number.EPSILON || Math.pow(2, -52);
|
|
479
|
-
/**
|
|
480
|
-
* @private
|
|
481
|
-
*/
|
|
482
|
-
function tryEval(name) {
|
|
483
|
-
try {
|
|
484
|
-
var value = eval(name);
|
|
485
|
-
return value;
|
|
486
|
-
}
|
|
487
|
-
catch (e) { }
|
|
488
|
-
return;
|
|
489
|
-
}
|
|
490
480
|
/**
|
|
491
481
|
* @private
|
|
492
482
|
*/
|
|
493
483
|
function detectEnvironment() {
|
|
494
|
-
|
|
484
|
+
// Use a function to get the global object to avoid TypeScript checking specific globals
|
|
485
|
+
var getGlobal = function () {
|
|
486
|
+
// In browsers and workers, 'self' refers to the global scope
|
|
487
|
+
if (typeof self !== 'undefined') {
|
|
488
|
+
return self;
|
|
489
|
+
}
|
|
490
|
+
// In Node.js, 'global' refers to the global scope
|
|
491
|
+
if (typeof global !== 'undefined') {
|
|
492
|
+
return global;
|
|
493
|
+
}
|
|
494
|
+
// Fallback for older environments
|
|
495
|
+
return this || {};
|
|
496
|
+
};
|
|
497
|
+
var globalObj = getGlobal();
|
|
498
|
+
// Check for Web Worker environment
|
|
499
|
+
// Workers have 'self' and 'WorkerGlobalScope' but not 'window'
|
|
500
|
+
if (globalObj['self'] && globalObj['WorkerGlobalScope'] && !globalObj['window']) {
|
|
495
501
|
return MakerJs.environmentTypes.WebWorker;
|
|
496
502
|
}
|
|
497
|
-
|
|
503
|
+
// Check for Browser UI environment
|
|
504
|
+
if (globalObj['window'] && globalObj['document']) {
|
|
498
505
|
return MakerJs.environmentTypes.BrowserUI;
|
|
499
506
|
}
|
|
500
507
|
//put node last since packagers usually add shims for it
|
|
501
|
-
if (
|
|
508
|
+
if (globalObj['global'] && globalObj['process']) {
|
|
502
509
|
return MakerJs.environmentTypes.NodeJs;
|
|
503
510
|
}
|
|
504
511
|
return MakerJs.environmentTypes.Unknown;
|
|
@@ -663,7 +670,9 @@ var MakerJs;
|
|
|
663
670
|
function extendObject(target, other) {
|
|
664
671
|
if (target && other) {
|
|
665
672
|
for (var key in other) {
|
|
666
|
-
if (typeof other[key] !== 'undefined') {
|
|
673
|
+
if (other.hasOwnProperty(key) && typeof other[key] !== 'undefined') {
|
|
674
|
+
if (key === '__proto__' || key === 'constructor' || key === 'prototype')
|
|
675
|
+
continue;
|
|
667
676
|
target[key] = other[key];
|
|
668
677
|
}
|
|
669
678
|
}
|
|
@@ -7585,20 +7594,29 @@ var MakerJs;
|
|
|
7585
7594
|
/**
|
|
7586
7595
|
* Convert a chain to SVG path data.
|
|
7587
7596
|
*
|
|
7588
|
-
* @param
|
|
7597
|
+
* @param c Chain to convert.
|
|
7589
7598
|
* @param offset IPoint relative offset point.
|
|
7590
7599
|
* @param accuracy Optional accuracy of SVG path data.
|
|
7600
|
+
* @param clockwise Optional flag to specify desired winding direction for nonzero fill rule.
|
|
7591
7601
|
* @returns String of SVG path data.
|
|
7592
7602
|
*/
|
|
7593
|
-
function chainToSVGPathData(
|
|
7603
|
+
function chainToSVGPathData(c, offset, accuracy, clockwise) {
|
|
7594
7604
|
function offsetPoint(p) {
|
|
7595
7605
|
return MakerJs.point.add(p, offset);
|
|
7596
7606
|
}
|
|
7597
|
-
|
|
7607
|
+
// If clockwise direction is specified, check if chain needs to be reversed
|
|
7608
|
+
if (clockwise !== undefined) {
|
|
7609
|
+
var isClockwise = MakerJs.measure.isChainClockwise(c);
|
|
7610
|
+
if (isClockwise !== null && isClockwise !== clockwise) {
|
|
7611
|
+
c = MakerJs.cloneObject(c);
|
|
7612
|
+
MakerJs.chain.reverse(c);
|
|
7613
|
+
}
|
|
7614
|
+
}
|
|
7615
|
+
var first = c.links[0];
|
|
7598
7616
|
var firstPoint = offsetPoint(svgCoords(first.endPoints[first.reversed ? 1 : 0]));
|
|
7599
7617
|
var d = ['M', MakerJs.round(firstPoint[0], accuracy), MakerJs.round(firstPoint[1], accuracy)];
|
|
7600
|
-
for (var i = 0; i <
|
|
7601
|
-
var link =
|
|
7618
|
+
for (var i = 0; i < c.links.length; i++) {
|
|
7619
|
+
var link = c.links[i];
|
|
7602
7620
|
var pathContext = link.walkedPath.pathContext;
|
|
7603
7621
|
var fn = chainLinkToPathDataMap[pathContext.type];
|
|
7604
7622
|
if (fn) {
|
|
@@ -7610,7 +7628,7 @@ var MakerJs;
|
|
|
7610
7628
|
fn(fixedPath, offsetPoint(svgCoords(link.endPoints[link.reversed ? 0 : 1])), link.reversed, d, accuracy);
|
|
7611
7629
|
}
|
|
7612
7630
|
}
|
|
7613
|
-
if (
|
|
7631
|
+
if (c.endless) {
|
|
7614
7632
|
d.push('Z');
|
|
7615
7633
|
}
|
|
7616
7634
|
return d.join(' ');
|
|
@@ -7686,16 +7704,16 @@ var MakerJs;
|
|
|
7686
7704
|
}
|
|
7687
7705
|
pathDataByLayer[layer] = [];
|
|
7688
7706
|
function doChains(cs, clockwise) {
|
|
7689
|
-
cs.forEach(function (
|
|
7690
|
-
if (
|
|
7691
|
-
var pathData = chainToSVGPathData(
|
|
7707
|
+
cs.forEach(function (c) {
|
|
7708
|
+
if (c.links.length > 1) {
|
|
7709
|
+
var pathData = chainToSVGPathData(c, offset, accuracy, clockwise);
|
|
7692
7710
|
pathDataByLayer[layer].push(pathData);
|
|
7693
7711
|
}
|
|
7694
7712
|
else {
|
|
7695
|
-
single(
|
|
7713
|
+
single(c.links[0].walkedPath, clockwise);
|
|
7696
7714
|
}
|
|
7697
|
-
if (
|
|
7698
|
-
doChains(
|
|
7715
|
+
if (c.contains) {
|
|
7716
|
+
doChains(c.contains, !clockwise);
|
|
7699
7717
|
}
|
|
7700
7718
|
});
|
|
7701
7719
|
}
|
|
@@ -10225,6 +10243,7 @@ var MakerJs;
|
|
|
10225
10243
|
];
|
|
10226
10244
|
})(models = MakerJs.models || (MakerJs.models = {}));
|
|
10227
10245
|
})(MakerJs || (MakerJs = {}));
|
|
10246
|
+
/// <reference types="fontkit" />
|
|
10228
10247
|
var MakerJs;
|
|
10229
10248
|
(function (MakerJs) {
|
|
10230
10249
|
var models;
|
|
@@ -10232,13 +10251,13 @@ var MakerJs;
|
|
|
10232
10251
|
var Text = /** @class */ (function () {
|
|
10233
10252
|
/**
|
|
10234
10253
|
* Renders text in a given font to a model.
|
|
10235
|
-
* @param font OpenType.Font object.
|
|
10254
|
+
* @param font OpenType.Font object or fontkit font object.
|
|
10236
10255
|
* @param text String of text to render.
|
|
10237
10256
|
* @param fontSize Font size.
|
|
10238
10257
|
* @param combine Flag (default false) to perform a combineUnion upon each character with characters to the left and right.
|
|
10239
10258
|
* @param centerCharacterOrigin Flag (default false) to move the x origin of each character to the center. Useful for rotating text characters.
|
|
10240
10259
|
* @param bezierAccuracy Optional accuracy of Bezier curves.
|
|
10241
|
-
* @param opentypeOptions Optional opentype.RenderOptions object.
|
|
10260
|
+
* @param opentypeOptions Optional opentype.RenderOptions object or fontkit layout options.
|
|
10242
10261
|
* @returns Model of the text.
|
|
10243
10262
|
*/
|
|
10244
10263
|
function Text(font, text, fontSize, combine, centerCharacterOrigin, bezierAccuracy, opentypeOptions) {
|
|
@@ -10250,7 +10269,7 @@ var MakerJs;
|
|
|
10250
10269
|
var prevDeleted;
|
|
10251
10270
|
var prevChar;
|
|
10252
10271
|
var cb = function (glyph, x, y, _fontSize, options) {
|
|
10253
|
-
var charModel = Text.glyphToModel(glyph, _fontSize, bezierAccuracy);
|
|
10272
|
+
var charModel = Text.glyphToModel(glyph, _fontSize, bezierAccuracy, font);
|
|
10254
10273
|
charModel.origin = [x, 0];
|
|
10255
10274
|
if (centerCharacterOrigin && (charModel.paths || charModel.models)) {
|
|
10256
10275
|
var m = MakerJs.measure.modelExtents(charModel);
|
|
@@ -10282,62 +10301,227 @@ var MakerJs;
|
|
|
10282
10301
|
charIndex++;
|
|
10283
10302
|
prevChar = charModel;
|
|
10284
10303
|
};
|
|
10285
|
-
font
|
|
10304
|
+
// Detect if font is fontkit (has layout method) or opentype.js (has forEachGlyph)
|
|
10305
|
+
if (font.layout && typeof font.layout === 'function') {
|
|
10306
|
+
// fontkit font - use layout engine
|
|
10307
|
+
var fontkitFont = font;
|
|
10308
|
+
var layoutOpts = opentypeOptions;
|
|
10309
|
+
var run = fontkitFont.layout(text, layoutOpts === null || layoutOpts === void 0 ? void 0 : layoutOpts.features, layoutOpts === null || layoutOpts === void 0 ? void 0 : layoutOpts.script, layoutOpts === null || layoutOpts === void 0 ? void 0 : layoutOpts.language, layoutOpts === null || layoutOpts === void 0 ? void 0 : layoutOpts.direction);
|
|
10310
|
+
var scale = fontSize / fontkitFont.unitsPerEm;
|
|
10311
|
+
var currentX = 0;
|
|
10312
|
+
for (var i = 0; i < run.glyphs.length; i++) {
|
|
10313
|
+
var glyph = run.glyphs[i];
|
|
10314
|
+
var position = run.positions[i];
|
|
10315
|
+
var glyphX = currentX + (position.xOffset || 0) * scale;
|
|
10316
|
+
var glyphY = (position.yOffset || 0) * scale;
|
|
10317
|
+
cb(glyph, glyphX, glyphY, fontSize, opentypeOptions);
|
|
10318
|
+
currentX += (position.xAdvance || 0) * scale;
|
|
10319
|
+
}
|
|
10320
|
+
}
|
|
10321
|
+
else {
|
|
10322
|
+
// opentype.js font - use forEachGlyph
|
|
10323
|
+
var opentypeFont = font;
|
|
10324
|
+
opentypeFont.forEachGlyph(text, 0, 0, fontSize, opentypeOptions, cb);
|
|
10325
|
+
}
|
|
10286
10326
|
}
|
|
10287
10327
|
/**
|
|
10288
|
-
* Convert an opentype glyph to a model.
|
|
10289
|
-
* @param glyph Opentype.Glyph object.
|
|
10328
|
+
* Convert an opentype glyph or fontkit glyph to a model.
|
|
10329
|
+
* @param glyph Opentype.Glyph object or fontkit glyph.
|
|
10290
10330
|
* @param fontSize Font size.
|
|
10291
10331
|
* @param bezierAccuracy Optional accuracy of Bezier curves.
|
|
10332
|
+
* @param font Optional font object (needed for fontkit to get scale).
|
|
10292
10333
|
* @returns Model of the glyph.
|
|
10293
10334
|
*/
|
|
10294
|
-
Text.glyphToModel = function (glyph, fontSize, bezierAccuracy) {
|
|
10335
|
+
Text.glyphToModel = function (glyph, fontSize, bezierAccuracy, font) {
|
|
10295
10336
|
var charModel = {};
|
|
10296
10337
|
var firstPoint;
|
|
10297
10338
|
var currPoint;
|
|
10298
10339
|
var pathCount = 0;
|
|
10299
|
-
function addPath(p) {
|
|
10340
|
+
function addPath(p, layer) {
|
|
10300
10341
|
if (!charModel.paths) {
|
|
10301
10342
|
charModel.paths = {};
|
|
10302
10343
|
}
|
|
10344
|
+
if (layer) {
|
|
10345
|
+
if (!charModel.layer)
|
|
10346
|
+
charModel.layer = layer;
|
|
10347
|
+
}
|
|
10303
10348
|
charModel.paths['p_' + ++pathCount] = p;
|
|
10304
10349
|
}
|
|
10305
|
-
function addModel(m) {
|
|
10350
|
+
function addModel(m, layer) {
|
|
10306
10351
|
if (!charModel.models) {
|
|
10307
10352
|
charModel.models = {};
|
|
10308
10353
|
}
|
|
10354
|
+
if (layer) {
|
|
10355
|
+
if (!charModel.layer)
|
|
10356
|
+
charModel.layer = layer;
|
|
10357
|
+
}
|
|
10309
10358
|
charModel.models['p_' + ++pathCount] = m;
|
|
10310
10359
|
}
|
|
10311
|
-
|
|
10312
|
-
|
|
10313
|
-
|
|
10314
|
-
|
|
10315
|
-
|
|
10316
|
-
|
|
10317
|
-
|
|
10318
|
-
|
|
10319
|
-
|
|
10320
|
-
|
|
10321
|
-
|
|
10322
|
-
|
|
10323
|
-
|
|
10324
|
-
|
|
10325
|
-
|
|
10326
|
-
|
|
10327
|
-
|
|
10360
|
+
// Detect if this is a fontkit glyph (has path property) or opentype.js glyph (has getPath method)
|
|
10361
|
+
var isFontkitGlyph = glyph.path && !glyph.getPath;
|
|
10362
|
+
var p;
|
|
10363
|
+
if (isFontkitGlyph && font) {
|
|
10364
|
+
// fontkit glyph
|
|
10365
|
+
var scale_1 = fontSize / font.unitsPerEm;
|
|
10366
|
+
p = glyph.path;
|
|
10367
|
+
// Check for color layers (COLR table support)
|
|
10368
|
+
if (glyph.layers && glyph.layers.length > 0) {
|
|
10369
|
+
// Handle color glyph with layers
|
|
10370
|
+
glyph.layers.forEach(function (layer, layerIndex) {
|
|
10371
|
+
var layerGlyph = font.getGlyph(layer.glyph);
|
|
10372
|
+
var layerPath = layerGlyph.path;
|
|
10373
|
+
if (layerPath && layerPath.commands) {
|
|
10374
|
+
// Get color from palette if available
|
|
10375
|
+
var layerColor = void 0;
|
|
10376
|
+
if (font['COLR'] && font['CPAL'] && layer.color !== undefined) {
|
|
10377
|
+
// CPAL table structure varies, try to access color palettes
|
|
10378
|
+
var cpal = font['CPAL'];
|
|
10379
|
+
var colorPalettes = cpal.colorPalettes || cpal.colorRecords;
|
|
10380
|
+
if (colorPalettes && colorPalettes.length > 0) {
|
|
10381
|
+
// Get the first palette
|
|
10382
|
+
var palette = colorPalettes[0];
|
|
10383
|
+
if (palette && palette.length > layer.color) {
|
|
10384
|
+
var color = palette[layer.color];
|
|
10385
|
+
if (color) {
|
|
10386
|
+
// Convert RGBA to hex color for layer name
|
|
10387
|
+
var red = color.red !== undefined ? color.red : color.r || 0;
|
|
10388
|
+
var green = color.green !== undefined ? color.green : color.g || 0;
|
|
10389
|
+
var blue = color.blue !== undefined ? color.blue : color.b || 0;
|
|
10390
|
+
layerColor = "color_".concat(red.toString(16).padStart(2, '0')).concat(green.toString(16).padStart(2, '0')).concat(blue.toString(16).padStart(2, '0'));
|
|
10391
|
+
}
|
|
10392
|
+
}
|
|
10393
|
+
}
|
|
10394
|
+
}
|
|
10395
|
+
// Process layer path commands
|
|
10396
|
+
var layerFirstPoint = void 0;
|
|
10397
|
+
var layerCurrPoint = void 0;
|
|
10398
|
+
for (var _i = 0, _a = layerPath.commands; _i < _a.length; _i++) {
|
|
10399
|
+
var cmd = _a[_i];
|
|
10400
|
+
var points = Text.convertFontkitCommand(cmd, scale_1);
|
|
10401
|
+
switch (cmd.command) {
|
|
10402
|
+
case 'moveTo':
|
|
10403
|
+
layerFirstPoint = points[0];
|
|
10404
|
+
layerCurrPoint = points[0];
|
|
10405
|
+
break;
|
|
10406
|
+
case 'closePath':
|
|
10407
|
+
points[0] = layerFirstPoint;
|
|
10408
|
+
// fall through to line
|
|
10409
|
+
case 'lineTo':
|
|
10410
|
+
if (layerCurrPoint && !MakerJs.measure.isPointEqual(layerCurrPoint, points[0])) {
|
|
10411
|
+
addPath(new MakerJs.paths.Line(layerCurrPoint, points[0]), layerColor);
|
|
10412
|
+
}
|
|
10413
|
+
layerCurrPoint = points[0];
|
|
10414
|
+
break;
|
|
10415
|
+
case 'bezierCurveTo':
|
|
10416
|
+
if (layerCurrPoint) {
|
|
10417
|
+
addModel(new models.BezierCurve(layerCurrPoint, points[0], points[1], points[2], bezierAccuracy), layerColor);
|
|
10418
|
+
}
|
|
10419
|
+
layerCurrPoint = points[2];
|
|
10420
|
+
break;
|
|
10421
|
+
case 'quadraticCurveTo':
|
|
10422
|
+
if (layerCurrPoint) {
|
|
10423
|
+
addModel(new models.BezierCurve(layerCurrPoint, points[0], points[1], bezierAccuracy), layerColor);
|
|
10424
|
+
}
|
|
10425
|
+
layerCurrPoint = points[1];
|
|
10426
|
+
break;
|
|
10427
|
+
}
|
|
10428
|
+
}
|
|
10328
10429
|
}
|
|
10329
|
-
|
|
10330
|
-
|
|
10331
|
-
|
|
10332
|
-
|
|
10333
|
-
|
|
10334
|
-
|
|
10335
|
-
|
|
10430
|
+
});
|
|
10431
|
+
return charModel;
|
|
10432
|
+
}
|
|
10433
|
+
// Standard fontkit glyph (no color layers)
|
|
10434
|
+
if (!p || !p.commands) {
|
|
10435
|
+
return charModel; // Empty glyph (e.g., space)
|
|
10436
|
+
}
|
|
10437
|
+
for (var _i = 0, _a = p.commands; _i < _a.length; _i++) {
|
|
10438
|
+
var cmd = _a[_i];
|
|
10439
|
+
var points = Text.convertFontkitCommand(cmd, scale_1);
|
|
10440
|
+
switch (cmd.command) {
|
|
10441
|
+
case 'moveTo':
|
|
10442
|
+
firstPoint = points[0];
|
|
10443
|
+
currPoint = points[0];
|
|
10444
|
+
break;
|
|
10445
|
+
case 'closePath':
|
|
10446
|
+
points[0] = firstPoint;
|
|
10447
|
+
// fall through to line
|
|
10448
|
+
case 'lineTo':
|
|
10449
|
+
if (!MakerJs.measure.isPointEqual(currPoint, points[0])) {
|
|
10450
|
+
addPath(new MakerJs.paths.Line(currPoint, points[0]));
|
|
10451
|
+
}
|
|
10452
|
+
currPoint = points[0];
|
|
10453
|
+
break;
|
|
10454
|
+
case 'bezierCurveTo':
|
|
10455
|
+
addModel(new models.BezierCurve(currPoint, points[0], points[1], points[2], bezierAccuracy));
|
|
10456
|
+
currPoint = points[2];
|
|
10457
|
+
break;
|
|
10458
|
+
case 'quadraticCurveTo':
|
|
10459
|
+
addModel(new models.BezierCurve(currPoint, points[0], points[1], bezierAccuracy));
|
|
10460
|
+
currPoint = points[1];
|
|
10461
|
+
break;
|
|
10462
|
+
}
|
|
10336
10463
|
}
|
|
10337
|
-
|
|
10338
|
-
|
|
10464
|
+
}
|
|
10465
|
+
else {
|
|
10466
|
+
// opentype.js glyph
|
|
10467
|
+
p = glyph.getPath(0, 0, fontSize);
|
|
10468
|
+
p.commands.map(function (command, i) {
|
|
10469
|
+
var points = [[command.x, command.y], [command.x1, command.y1], [command.x2, command.y2]].map(function (p) {
|
|
10470
|
+
if (p[0] !== void 0) {
|
|
10471
|
+
return MakerJs.point.mirror(p, false, true);
|
|
10472
|
+
}
|
|
10473
|
+
});
|
|
10474
|
+
switch (command.type) {
|
|
10475
|
+
case 'M':
|
|
10476
|
+
firstPoint = points[0];
|
|
10477
|
+
break;
|
|
10478
|
+
case 'Z':
|
|
10479
|
+
points[0] = firstPoint;
|
|
10480
|
+
//fall through to line
|
|
10481
|
+
case 'L':
|
|
10482
|
+
if (!MakerJs.measure.isPointEqual(currPoint, points[0])) {
|
|
10483
|
+
addPath(new MakerJs.paths.Line(currPoint, points[0]));
|
|
10484
|
+
}
|
|
10485
|
+
break;
|
|
10486
|
+
case 'C':
|
|
10487
|
+
addModel(new models.BezierCurve(currPoint, points[1], points[2], points[0], bezierAccuracy));
|
|
10488
|
+
break;
|
|
10489
|
+
case 'Q':
|
|
10490
|
+
addModel(new models.BezierCurve(currPoint, points[1], points[0], bezierAccuracy));
|
|
10491
|
+
break;
|
|
10492
|
+
}
|
|
10493
|
+
currPoint = points[0];
|
|
10494
|
+
});
|
|
10495
|
+
}
|
|
10339
10496
|
return charModel;
|
|
10340
10497
|
};
|
|
10498
|
+
/**
|
|
10499
|
+
* Convert fontkit path command to points array
|
|
10500
|
+
* @param cmd Fontkit path command
|
|
10501
|
+
* @param scale Scale factor
|
|
10502
|
+
* @returns Array of points
|
|
10503
|
+
*/
|
|
10504
|
+
Text.convertFontkitCommand = function (cmd, scale) {
|
|
10505
|
+
var points = [];
|
|
10506
|
+
switch (cmd.command) {
|
|
10507
|
+
case 'moveTo':
|
|
10508
|
+
case 'lineTo':
|
|
10509
|
+
points.push([cmd.args[0] * scale, cmd.args[1] * scale]);
|
|
10510
|
+
break;
|
|
10511
|
+
case 'quadraticCurveTo':
|
|
10512
|
+
// Control point, end point
|
|
10513
|
+
points.push([cmd.args[0] * scale, cmd.args[1] * scale]);
|
|
10514
|
+
points.push([cmd.args[2] * scale, cmd.args[3] * scale]);
|
|
10515
|
+
break;
|
|
10516
|
+
case 'bezierCurveTo':
|
|
10517
|
+
// Control point 1, control point 2, end point
|
|
10518
|
+
points.push([cmd.args[0] * scale, cmd.args[1] * scale]);
|
|
10519
|
+
points.push([cmd.args[2] * scale, cmd.args[3] * scale]);
|
|
10520
|
+
points.push([cmd.args[4] * scale, cmd.args[5] * scale]);
|
|
10521
|
+
break;
|
|
10522
|
+
}
|
|
10523
|
+
return points;
|
|
10524
|
+
};
|
|
10341
10525
|
return Text;
|
|
10342
10526
|
}());
|
|
10343
10527
|
models.Text = Text;
|
|
@@ -10350,6 +10534,7 @@ var MakerJs;
|
|
|
10350
10534
|
];
|
|
10351
10535
|
})(models = MakerJs.models || (MakerJs.models = {}));
|
|
10352
10536
|
})(MakerJs || (MakerJs = {}));
|
|
10353
|
-
MakerJs.version = "0.
|
|
10537
|
+
MakerJs.version = "0.19.2";
|
|
10354
10538
|
|
|
10539
|
+
}).call(this)}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
|
10355
10540
|
},{"clone":2,"graham_scan":3,"kdbush":4}]},{},[]);
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Type definitions for Maker.js 0.
|
|
1
|
+
// Type definitions for Maker.js 0.19.2
|
|
2
2
|
// Project: https://github.com/Microsoft/maker.js
|
|
3
3
|
// Definitions by: Dan Marshall <https://github.com/danmarshall>
|
|
4
4
|
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
|
@@ -3244,12 +3244,13 @@ declare namespace MakerJs.exporter {
|
|
|
3244
3244
|
/**
|
|
3245
3245
|
* Convert a chain to SVG path data.
|
|
3246
3246
|
*
|
|
3247
|
-
* @param
|
|
3247
|
+
* @param c Chain to convert.
|
|
3248
3248
|
* @param offset IPoint relative offset point.
|
|
3249
3249
|
* @param accuracy Optional accuracy of SVG path data.
|
|
3250
|
+
* @param clockwise Optional flag to specify desired winding direction for nonzero fill rule.
|
|
3250
3251
|
* @returns String of SVG path data.
|
|
3251
3252
|
*/
|
|
3252
|
-
function chainToSVGPathData(
|
|
3253
|
+
function chainToSVGPathData(c: IChain, offset: IPoint, accuracy?: number, clockwise?: boolean): string;
|
|
3253
3254
|
/**
|
|
3254
3255
|
* Export a path to SVG path data.
|
|
3255
3256
|
*
|
|
@@ -3943,28 +3944,55 @@ declare namespace MakerJs.models {
|
|
|
3943
3944
|
static InnerRadiusRatio(numberOfPoints: number, skipPoints: number): number;
|
|
3944
3945
|
}
|
|
3945
3946
|
}
|
|
3947
|
+
declare namespace fontkit {
|
|
3948
|
+
type Font = import('fontkit').Font;
|
|
3949
|
+
}
|
|
3950
|
+
declare namespace MakerJs {
|
|
3951
|
+
/**
|
|
3952
|
+
* Layout options for fontkit font rendering.
|
|
3953
|
+
* These options are passed to the fontkit layout engine.
|
|
3954
|
+
*/
|
|
3955
|
+
interface IFontkitLayoutOptions {
|
|
3956
|
+
/** OpenType features to enable/disable (array of feature tags or object mapping feature tags to boolean) */
|
|
3957
|
+
features?: string[] | Record<string, boolean>;
|
|
3958
|
+
/** Script code (e.g., 'latn', 'arab') */
|
|
3959
|
+
script?: string;
|
|
3960
|
+
/** Language code (e.g., 'ENG', 'ARA') */
|
|
3961
|
+
language?: string;
|
|
3962
|
+
/** Text direction ('ltr' or 'rtl') */
|
|
3963
|
+
direction?: string;
|
|
3964
|
+
}
|
|
3965
|
+
}
|
|
3946
3966
|
declare namespace MakerJs.models {
|
|
3947
3967
|
class Text implements IModel {
|
|
3948
3968
|
models: IModelMap;
|
|
3949
3969
|
/**
|
|
3950
3970
|
* Renders text in a given font to a model.
|
|
3951
|
-
* @param font OpenType.Font object.
|
|
3971
|
+
* @param font OpenType.Font object or fontkit font object.
|
|
3952
3972
|
* @param text String of text to render.
|
|
3953
3973
|
* @param fontSize Font size.
|
|
3954
3974
|
* @param combine Flag (default false) to perform a combineUnion upon each character with characters to the left and right.
|
|
3955
3975
|
* @param centerCharacterOrigin Flag (default false) to move the x origin of each character to the center. Useful for rotating text characters.
|
|
3956
3976
|
* @param bezierAccuracy Optional accuracy of Bezier curves.
|
|
3957
|
-
* @param opentypeOptions Optional opentype.RenderOptions object.
|
|
3977
|
+
* @param opentypeOptions Optional opentype.RenderOptions object or fontkit layout options.
|
|
3958
3978
|
* @returns Model of the text.
|
|
3959
3979
|
*/
|
|
3960
|
-
constructor(font: opentype.Font, text: string, fontSize: number, combine?: boolean, centerCharacterOrigin?: boolean, bezierAccuracy?: number, opentypeOptions?: opentype.RenderOptions);
|
|
3980
|
+
constructor(font: opentype.Font | fontkit.Font, text: string, fontSize: number, combine?: boolean, centerCharacterOrigin?: boolean, bezierAccuracy?: number, opentypeOptions?: opentype.RenderOptions | IFontkitLayoutOptions);
|
|
3961
3981
|
/**
|
|
3962
|
-
* Convert an opentype glyph to a model.
|
|
3963
|
-
* @param glyph Opentype.Glyph object.
|
|
3982
|
+
* Convert an opentype glyph or fontkit glyph to a model.
|
|
3983
|
+
* @param glyph Opentype.Glyph object or fontkit glyph.
|
|
3964
3984
|
* @param fontSize Font size.
|
|
3965
3985
|
* @param bezierAccuracy Optional accuracy of Bezier curves.
|
|
3986
|
+
* @param font Optional font object (needed for fontkit to get scale).
|
|
3966
3987
|
* @returns Model of the glyph.
|
|
3967
3988
|
*/
|
|
3968
|
-
static glyphToModel(glyph:
|
|
3989
|
+
static glyphToModel(glyph: any, fontSize: number, bezierAccuracy?: number, font?: any): IModel;
|
|
3990
|
+
/**
|
|
3991
|
+
* Convert fontkit path command to points array
|
|
3992
|
+
* @param cmd Fontkit path command
|
|
3993
|
+
* @param scale Scale factor
|
|
3994
|
+
* @returns Array of points
|
|
3995
|
+
*/
|
|
3996
|
+
private static convertFontkitCommand;
|
|
3969
3997
|
}
|
|
3970
3998
|
}
|