makerjs 0.18.1 → 0.19.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.
@@ -39,12 +39,12 @@ 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.18.1
42
+ * version: 0.19.1
43
43
  *
44
44
  * browserify:
45
45
  * license: MIT (http://opensource.org/licenses/MIT)
46
46
  * author: James Halliday <mail@substack.net>
47
- * version: 17.0.0
47
+ * version: 17.0.1
48
48
  *
49
49
  * clone:
50
50
  * license: MIT (http://opensource.org/licenses/MIT)
@@ -54,9 +54,9 @@ and limitations under the License.
54
54
  *
55
55
  * graham_scan:
56
56
  * license: MIT (http://opensource.org/licenses/MIT)
57
- * author: Brian Barnett <brian@3kb.co.uk>
57
+ * author: Brian Barnett <me@brianbar.net>
58
58
  * homepage: http://brian3kb.github.io/graham_scan_js
59
- * version: 1.0.4
59
+ * version: 1.0.5
60
60
  *
61
61
  * kdbush:
62
62
  * license: ISC (http://opensource.org/licenses/ISC)
@@ -242,9 +242,10 @@ if (typeof module === 'object' && module.exports) {
242
242
  * Graham's Scan Convex Hull Algorithm
243
243
  * @desc An implementation of the Graham's Scan Convex Hull algorithm in JavaScript.
244
244
  * @author Brian Barnett, brian@3kb.co.uk, http://brianbar.net/ || http://3kb.co.uk/
245
- * @version 1.0.4
245
+ * @version 1.0.5
246
246
  */
247
- function ConvexHullGrahamScan(){this.anchorPoint=void 0,this.reverse=!1,this.points=[]}ConvexHullGrahamScan.prototype={constructor:ConvexHullGrahamScan,Point:function(n,t){this.x=n,this.y=t},_findPolarAngle:function(n,t){var i,o,h=57.295779513082;if(!n||!t)return 0;if(i=t.x-n.x,o=t.y-n.y,0==i&&0==o)return 0;var r=Math.atan2(o,i)*h;return this.reverse?0>=r&&(r+=360):r>=0&&(r+=360),r},addPoint:function(n,t){return void 0===this.anchorPoint?void(this.anchorPoint=new this.Point(n,t)):this.anchorPoint.y>t&&this.anchorPoint.x>n||this.anchorPoint.y===t&&this.anchorPoint.x>n||this.anchorPoint.y>t&&this.anchorPoint.x===n?(this.points.push(new this.Point(this.anchorPoint.x,this.anchorPoint.y)),void(this.anchorPoint=new this.Point(n,t))):void this.points.push(new this.Point(n,t))},_sortPoints:function(){var n=this;return this.points.sort(function(t,i){var o=n._findPolarAngle(n.anchorPoint,t),h=n._findPolarAngle(n.anchorPoint,i);return h>o?-1:o>h?1:0})},_checkPoints:function(n,t,i){var o,h=this._findPolarAngle(n,t),r=this._findPolarAngle(n,i);return h>r?(o=h-r,!(o>180)):r>h?(o=r-h,o>180):!0},getHull:function(){var n,t,i=[];if(this.reverse=this.points.every(function(n){return n.x<0&&n.y<0}),n=this._sortPoints(),t=n.length,3>t)return n.unshift(this.anchorPoint),n;for(i.push(n.shift(),n.shift());;){var o,h,r;if(i.push(n.shift()),o=i[i.length-3],h=i[i.length-2],r=i[i.length-1],this._checkPoints(o,h,r)&&i.splice(i.length-2,1),0==n.length){if(t==i.length){var e=this.anchorPoint;return i=i.filter(function(n){return!!n}),i.some(function(n){return n.x==e.x&&n.y==e.y})||i.unshift(this.anchorPoint),i}n=i,t=n.length,i=[],i.push(n.shift(),n.shift())}}}},"function"==typeof define&&define.amd&&define(function(){return ConvexHullGrahamScan}),"undefined"!=typeof module&&(module.exports=ConvexHullGrahamScan);
247
+ function ConvexHullGrahamScan(){this.anchorPoint=void 0,this.reverse=!1,this.points=[]}ConvexHullGrahamScan.prototype={constructor:ConvexHullGrahamScan,Point:function(a,b){this.x=a,this.y=b},_findPolarAngle:function(a,b){var c,d,e=57.295779513082;if(!a||!b)return 0;if(c=b.x-a.x,d=b.y-a.y,0==c&&0==d)return 0;var f=Math.atan2(d,c)*e;return this.reverse?0>=f&&(f+=360):f>=0&&(f+=360),f},addPoint:function(a,b){var c=void 0===this.anchorPoint||this.anchorPoint.y>b||this.anchorPoint.y===b&&this.anchorPoint.x>a;c?(void 0!==this.anchorPoint&&this.points.push(new this.Point(this.anchorPoint.x,this.anchorPoint.y)),this.anchorPoint=new this.Point(a,b)):this.points.push(new this.Point(a,b))},_sortPoints:function(){var a=this;return this.points.sort(function(b,c){var d=a._findPolarAngle(a.anchorPoint,b),e=a._findPolarAngle(a.anchorPoint,c);return e>d?-1:d>e?1:0})},_checkPoints:function(a,b,c){var d,e=this._findPolarAngle(a,b),f=this._findPolarAngle(a,c);return e>f?(d=e-f,!(d>180)):f>e?(d=f-e,d>180):!0},getHull:function(){var a,b,c=[];if(this.reverse=this.points.every(function(a){return a.x<0&&a.y<0}),a=this._sortPoints(),b=a.length,3>b)return a.unshift(this.anchorPoint),a;for(c.push(a.shift(),a.shift());;){var d,e,f;if(c.push(a.shift()),d=c[c.length-3],e=c[c.length-2],f=c[c.length-1],this._checkPoints(d,e,f)&&c.splice(c.length-2,1),0==a.length){if(b==c.length){var g=this.anchorPoint;return c=c.filter(function(a){return!!a}),c.some(function(a){return a.x==g.x&&a.y==g.y})||c.unshift(this.anchorPoint),c}a=c,b=a.length,c=[],c.push(a.shift(),a.shift())}}}},"function"==typeof define&&define.amd&&define(function(){return ConvexHullGrahamScan}),"undefined"!=typeof module&&(module.exports=ConvexHullGrahamScan);
248
+
248
249
  },{}],4:[function(require,module,exports){
249
250
  (function (global, factory) {
250
251
  typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
@@ -447,6 +448,7 @@ return kdbush;
447
448
  })));
448
449
 
449
450
  },{}],"makerjs":[function(require,module,exports){
451
+ (function (global){(function (){
450
452
  /**
451
453
  * Root module for Maker.js.
452
454
  *
@@ -475,29 +477,35 @@ var MakerJs;
475
477
  * @private
476
478
  */
477
479
  var EPSILON = Number.EPSILON || Math.pow(2, -52);
478
- /**
479
- * @private
480
- */
481
- function tryEval(name) {
482
- try {
483
- var value = eval(name);
484
- return value;
485
- }
486
- catch (e) { }
487
- return;
488
- }
489
480
  /**
490
481
  * @private
491
482
  */
492
483
  function detectEnvironment() {
493
- if (tryEval('WorkerGlobalScope') && tryEval('self')) {
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']) {
494
501
  return MakerJs.environmentTypes.WebWorker;
495
502
  }
496
- if (tryEval('window') && tryEval('document')) {
503
+ // Check for Browser UI environment
504
+ if (globalObj['window'] && globalObj['document']) {
497
505
  return MakerJs.environmentTypes.BrowserUI;
498
506
  }
499
507
  //put node last since packagers usually add shims for it
500
- if (tryEval('global') && tryEval('process')) {
508
+ if (globalObj['global'] && globalObj['process']) {
501
509
  return MakerJs.environmentTypes.NodeJs;
502
510
  }
503
511
  return MakerJs.environmentTypes.Unknown;
@@ -2674,7 +2682,7 @@ var MakerJs;
2674
2682
  }
2675
2683
  if (modelToDistort.type === MakerJs.models.BezierCurve.typeName) {
2676
2684
  var b = modelToDistort;
2677
- var bezierPartsByLayer = MakerJs.models.BezierCurve.getBezierSeeds(b, { byLayers: true });
2685
+ var bezierPartsByLayer = MakerJs.models.BezierCurve.getBezierSeeds(b, { byLayers: true, pointMatchingDistance: bezierAccuracy });
2678
2686
  var _loop_1 = function (layer_1) {
2679
2687
  var pathArray = bezierPartsByLayer[layer_1];
2680
2688
  pathArray.forEach(function (p, i) {
@@ -4594,7 +4602,7 @@ var MakerJs;
4594
4602
  if (m) {
4595
4603
  return augment(m);
4596
4604
  }
4597
- return m;
4605
+ return null;
4598
4606
  }
4599
4607
  measure.modelExtents = modelExtents;
4600
4608
  /**
@@ -5029,6 +5037,12 @@ var MakerJs;
5029
5037
  };
5030
5038
  }
5031
5039
  }
5040
+ function lineTypeLayerOptions(layer) {
5041
+ if (opts.layerOptions && opts.layerOptions[layer] && opts.layerOptions[layer].lineType) {
5042
+ return opts.layerOptions[layer].lineType;
5043
+ }
5044
+ return "CONTINUOUS";
5045
+ }
5032
5046
  function defaultLayer(pathContext, parentLayer) {
5033
5047
  var layerId = (pathContext && pathContext.layer) || parentLayer || '0';
5034
5048
  if (layerIds.indexOf(layerId) < 0) {
@@ -5038,9 +5052,10 @@ var MakerJs;
5038
5052
  }
5039
5053
  var map = {};
5040
5054
  map[MakerJs.pathType.Line] = function (line, offset, layer) {
5055
+ var layerId = defaultLayer(line, layer);
5041
5056
  var lineEntity = {
5042
5057
  type: "LINE",
5043
- layer: defaultLayer(line, layer),
5058
+ layer: layerId,
5044
5059
  vertices: [
5045
5060
  {
5046
5061
  x: MakerJs.round(line.origin[0] + offset[0], opts.accuracy),
@@ -5052,24 +5067,28 @@ var MakerJs;
5052
5067
  }
5053
5068
  ]
5054
5069
  };
5070
+ lineEntity.lineType = lineTypeLayerOptions(layerId);
5055
5071
  return lineEntity;
5056
5072
  };
5057
5073
  map[MakerJs.pathType.Circle] = function (circle, offset, layer) {
5074
+ var layerId = defaultLayer(circle, layer);
5058
5075
  var circleEntity = {
5059
5076
  type: "CIRCLE",
5060
- layer: defaultLayer(circle, layer),
5077
+ layer: layerId,
5061
5078
  center: {
5062
5079
  x: MakerJs.round(circle.origin[0] + offset[0], opts.accuracy),
5063
5080
  y: MakerJs.round(circle.origin[1] + offset[1], opts.accuracy)
5064
5081
  },
5065
5082
  radius: MakerJs.round(circle.radius, opts.accuracy)
5066
5083
  };
5084
+ circleEntity.lineType = lineTypeLayerOptions(layerId);
5067
5085
  return circleEntity;
5068
5086
  };
5069
5087
  map[MakerJs.pathType.Arc] = function (arc, offset, layer) {
5088
+ var layerId = defaultLayer(arc, layer);
5070
5089
  var arcEntity = {
5071
5090
  type: "ARC",
5072
- layer: defaultLayer(arc, layer),
5091
+ layer: layerId,
5073
5092
  center: {
5074
5093
  x: MakerJs.round(arc.origin[0] + offset[0], opts.accuracy),
5075
5094
  y: MakerJs.round(arc.origin[1] + offset[1], opts.accuracy)
@@ -5078,6 +5097,7 @@ var MakerJs;
5078
5097
  startAngle: MakerJs.round(arc.startAngle, opts.accuracy),
5079
5098
  endAngle: MakerJs.round(arc.endAngle, opts.accuracy)
5080
5099
  };
5100
+ arcEntity.lineType = lineTypeLayerOptions(layerId);
5081
5101
  return arcEntity;
5082
5102
  };
5083
5103
  //TODO - handle scenario if any bezier seeds get passed
@@ -5099,6 +5119,7 @@ var MakerJs;
5099
5119
  shape: c.chain.endless,
5100
5120
  vertices: []
5101
5121
  };
5122
+ polylineEntity.lineType = lineTypeLayerOptions(polylineEntity.layer);
5102
5123
  c.chain.links.forEach(function (link, i) {
5103
5124
  var bulge;
5104
5125
  if (link.walkedPath.pathContext.type === MakerJs.pathType.Arc) {
@@ -5140,15 +5161,31 @@ var MakerJs;
5140
5161
  name: layerId,
5141
5162
  color: layerColor
5142
5163
  };
5164
+ layerEntity.lineType = lineTypeLayerOptions(layerId);
5143
5165
  return layerEntity;
5144
5166
  }
5145
5167
  function lineTypesOut() {
5168
+ // Dash pattern convention: positive = drawn segment, negative = gap, 0 can be dot.
5169
+ // patternLength is sum of absolute values.
5146
5170
  var lineStyleTable = {
5147
5171
  lineTypes: {
5148
5172
  "CONTINUOUS": {
5149
5173
  name: "CONTINUOUS",
5150
5174
  description: "______",
5151
- patternLength: 0
5175
+ patternLength: 0,
5176
+ elements: []
5177
+ },
5178
+ "DASHED": {
5179
+ name: "DASHED",
5180
+ description: "_ _ _ ",
5181
+ elements: [5, -2.5],
5182
+ patternLength: 7.5
5183
+ },
5184
+ "DOTTED": {
5185
+ name: "DOTTED",
5186
+ description: ". . . ",
5187
+ elements: [0.5, -1.0],
5188
+ patternLength: 1.5
5152
5189
  }
5153
5190
  }
5154
5191
  };
@@ -5240,15 +5277,27 @@ var MakerJs;
5240
5277
  }
5241
5278
  dxf.push.apply(dxf, values);
5242
5279
  }
5280
+ function appendLineType(entity) {
5281
+ var lt = entity.lineType;
5282
+ if (lt) {
5283
+ append("6", lt);
5284
+ }
5285
+ }
5243
5286
  var map = {};
5244
5287
  map["LINE"] = function (line) {
5245
- append("0", "LINE", "8", line.layer, "10", line.vertices[0].x, "20", line.vertices[0].y, "11", line.vertices[1].x, "21", line.vertices[1].y);
5288
+ append("0", "LINE", "8", line.layer);
5289
+ appendLineType(line);
5290
+ append("10", line.vertices[0].x, "20", line.vertices[0].y, "11", line.vertices[1].x, "21", line.vertices[1].y);
5246
5291
  };
5247
5292
  map["CIRCLE"] = function (circle) {
5248
- append("0", "CIRCLE", "8", circle.layer, "10", circle.center.x, "20", circle.center.y, "40", circle.radius);
5293
+ append("0", "CIRCLE", "8", circle.layer);
5294
+ appendLineType(circle);
5295
+ append("10", circle.center.x, "20", circle.center.y, "40", circle.radius);
5249
5296
  };
5250
5297
  map["ARC"] = function (arc) {
5251
- append("0", "ARC", "8", arc.layer, "10", arc.center.x, "20", arc.center.y, "40", arc.radius, "50", arc.startAngle, "51", arc.endAngle);
5298
+ append("0", "ARC", "8", arc.layer);
5299
+ appendLineType(arc);
5300
+ append("10", arc.center.x, "20", arc.center.y, "40", arc.radius, "50", arc.startAngle, "51", arc.endAngle);
5252
5301
  };
5253
5302
  //TODO - handle scenario if any bezier seeds get passed
5254
5303
  //map[pathType.BezierSeed]
@@ -5259,7 +5308,9 @@ var MakerJs;
5259
5308
  }
5260
5309
  };
5261
5310
  map["POLYLINE"] = function (polyline) {
5262
- append("0", "POLYLINE", "8", polyline.layer, "66", 1, "70", polyline.shape ? 1 : 0);
5311
+ append("0", "POLYLINE", "8", polyline.layer);
5312
+ appendLineType(polyline);
5313
+ append("66", 1, "70", polyline.shape ? 1 : 0);
5263
5314
  polyline.vertices.forEach(function (vertex) { return map["VERTEX"](vertex); });
5264
5315
  append("0", "SEQEND");
5265
5316
  };
@@ -5282,11 +5333,14 @@ var MakerJs;
5282
5333
  table(layersOut);
5283
5334
  }
5284
5335
  function layerOut(layer) {
5285
- append("0", "LAYER", "2", layer.name, "70", "0", "62", layer.color, "6", "CONTINUOUS");
5336
+ var lt = (layer.lineType || "CONTINUOUS");
5337
+ append("0", "LAYER", "2", layer.name, "70", "0", "62", layer.color, "6", lt);
5286
5338
  }
5287
5339
  function lineTypeOut(lineType) {
5340
+ var elements = ((lineType.elements) || []);
5288
5341
  append("0", "LTYPE", "72", //72 Alignment code; value is always 65, the ASCII code for A
5289
- "65", "70", "64", "2", lineType.name, "3", lineType.description, "73", "0", "40", lineType.patternLength);
5342
+ "65", "70", "0", "2", lineType.name, "3", lineType.description, "73", elements.length, "40", lineType.patternLength);
5343
+ elements.forEach(function (e) { return append("49", e); });
5290
5344
  }
5291
5345
  function lineTypesOut() {
5292
5346
  var lineTypeTableName = 'lineType';
@@ -6437,7 +6491,7 @@ var MakerJs;
6437
6491
  var beziers;
6438
6492
  if (opts.unifyBeziers) {
6439
6493
  beziers = getBezierModels(modelContext);
6440
- swapBezierPathsWithSeeds(beziers, true);
6494
+ swapBezierPathsWithSeeds(beziers, true, opts.pointMatchingDistance);
6441
6495
  }
6442
6496
  model.walk(modelContext, walkOptions);
6443
6497
  var _loop_3 = function (layer_2) {
@@ -6474,7 +6528,7 @@ var MakerJs;
6474
6528
  _loop_3(layer_2);
6475
6529
  }
6476
6530
  if (beziers) {
6477
- swapBezierPathsWithSeeds(beziers, false);
6531
+ swapBezierPathsWithSeeds(beziers, false, opts.pointMatchingDistance);
6478
6532
  }
6479
6533
  if (opts.byLayers) {
6480
6534
  return chainsByLayer;
@@ -6571,7 +6625,7 @@ var MakerJs;
6571
6625
  /**
6572
6626
  * @private
6573
6627
  */
6574
- function swapBezierPathsWithSeeds(beziers, swap) {
6628
+ function swapBezierPathsWithSeeds(beziers, swap, pointMatchingDistance) {
6575
6629
  var tempKey = 'tempPaths';
6576
6630
  var tempLayerKey = 'tempLayer';
6577
6631
  beziers.forEach(function (wm) {
@@ -6583,7 +6637,7 @@ var MakerJs;
6583
6637
  b.layer = wm.layer;
6584
6638
  }
6585
6639
  //use seeds as path, hide the arc paths from findChains()
6586
- var bezierPartsByLayer = MakerJs.models.BezierCurve.getBezierSeeds(b, { byLayers: true });
6640
+ var bezierPartsByLayer = MakerJs.models.BezierCurve.getBezierSeeds(b, { byLayers: true, pointMatchingDistance: pointMatchingDistance });
6587
6641
  for (var layer in bezierPartsByLayer) {
6588
6642
  var bezierSeeds = bezierPartsByLayer[layer];
6589
6643
  if (bezierSeeds.length > 0) {
@@ -7538,20 +7592,29 @@ var MakerJs;
7538
7592
  /**
7539
7593
  * Convert a chain to SVG path data.
7540
7594
  *
7541
- * @param chain Chain to convert.
7595
+ * @param c Chain to convert.
7542
7596
  * @param offset IPoint relative offset point.
7543
7597
  * @param accuracy Optional accuracy of SVG path data.
7598
+ * @param clockwise Optional flag to specify desired winding direction for nonzero fill rule.
7544
7599
  * @returns String of SVG path data.
7545
7600
  */
7546
- function chainToSVGPathData(chain, offset, accuracy) {
7601
+ function chainToSVGPathData(c, offset, accuracy, clockwise) {
7547
7602
  function offsetPoint(p) {
7548
7603
  return MakerJs.point.add(p, offset);
7549
7604
  }
7550
- var first = chain.links[0];
7605
+ // If clockwise direction is specified, check if chain needs to be reversed
7606
+ if (clockwise !== undefined) {
7607
+ var isClockwise = MakerJs.measure.isChainClockwise(c);
7608
+ if (isClockwise !== null && isClockwise !== clockwise) {
7609
+ c = MakerJs.cloneObject(c);
7610
+ MakerJs.chain.reverse(c);
7611
+ }
7612
+ }
7613
+ var first = c.links[0];
7551
7614
  var firstPoint = offsetPoint(svgCoords(first.endPoints[first.reversed ? 1 : 0]));
7552
7615
  var d = ['M', MakerJs.round(firstPoint[0], accuracy), MakerJs.round(firstPoint[1], accuracy)];
7553
- for (var i = 0; i < chain.links.length; i++) {
7554
- var link = chain.links[i];
7616
+ for (var i = 0; i < c.links.length; i++) {
7617
+ var link = c.links[i];
7555
7618
  var pathContext = link.walkedPath.pathContext;
7556
7619
  var fn = chainLinkToPathDataMap[pathContext.type];
7557
7620
  if (fn) {
@@ -7563,7 +7626,7 @@ var MakerJs;
7563
7626
  fn(fixedPath, offsetPoint(svgCoords(link.endPoints[link.reversed ? 0 : 1])), link.reversed, d, accuracy);
7564
7627
  }
7565
7628
  }
7566
- if (chain.endless) {
7629
+ if (c.endless) {
7567
7630
  d.push('Z');
7568
7631
  }
7569
7632
  return d.join(' ');
@@ -7639,16 +7702,16 @@ var MakerJs;
7639
7702
  }
7640
7703
  pathDataByLayer[layer] = [];
7641
7704
  function doChains(cs, clockwise) {
7642
- cs.forEach(function (chain) {
7643
- if (chain.links.length > 1) {
7644
- var pathData = chainToSVGPathData(chain, offset, accuracy);
7705
+ cs.forEach(function (c) {
7706
+ if (c.links.length > 1) {
7707
+ var pathData = chainToSVGPathData(c, offset, accuracy, clockwise);
7645
7708
  pathDataByLayer[layer].push(pathData);
7646
7709
  }
7647
7710
  else {
7648
- single(chain.links[0].walkedPath, clockwise);
7711
+ single(c.links[0].walkedPath, clockwise);
7649
7712
  }
7650
- if (chain.contains) {
7651
- doChains(chain.contains, !clockwise);
7713
+ if (c.contains) {
7714
+ doChains(c.contains, !clockwise);
7652
7715
  }
7653
7716
  });
7654
7717
  }
@@ -9002,7 +9065,7 @@ var MakerJs;
9002
9065
  /**
9003
9066
  * @private
9004
9067
  */
9005
- function getActualBezierRange(curve, arc, endpoints, offset) {
9068
+ function getActualBezierRange(curve, arc, endpoints, offset, pointMatchingDistance) {
9006
9069
  var b = getScratch(curve.seed);
9007
9070
  var tPoints = [arc.bezierData.startT, arc.bezierData.endT].map(function (t) { return new TPoint(b, t, offset); });
9008
9071
  var ends = endpoints.slice();
@@ -9011,7 +9074,7 @@ var MakerJs;
9011
9074
  if (endpointDistancetoStart[0] > endpointDistancetoStart[1])
9012
9075
  ends.reverse();
9013
9076
  for (var i = 2; i--;) {
9014
- if (!MakerJs.measure.isPointEqual(ends[i], tPoints[i].point)) {
9077
+ if (!MakerJs.measure.isPointEqual(ends[i], tPoints[i].point, pointMatchingDistance)) {
9015
9078
  return null;
9016
9079
  }
9017
9080
  }
@@ -9020,13 +9083,13 @@ var MakerJs;
9020
9083
  /**
9021
9084
  * @private
9022
9085
  */
9023
- function getChainBezierRange(curve, c, layer, addToLayer) {
9086
+ function getChainBezierRange(curve, c, layer, addToLayer, pointMatchingDistance) {
9024
9087
  var endLinks = [c.links[0], c.links[c.links.length - 1]];
9025
9088
  if (endLinks[0].walkedPath.pathContext.bezierData.startT > endLinks[1].walkedPath.pathContext.bezierData.startT) {
9026
9089
  MakerJs.chain.reverse(c);
9027
9090
  endLinks.reverse();
9028
9091
  }
9029
- var actualBezierRanges = endLinks.map(function (endLink) { return getActualBezierRange(curve, endLink.walkedPath.pathContext, endLink.endPoints, endLink.walkedPath.offset); });
9092
+ var actualBezierRanges = endLinks.map(function (endLink) { return getActualBezierRange(curve, endLink.walkedPath.pathContext, endLink.endPoints, endLink.walkedPath.offset, pointMatchingDistance); });
9030
9093
  var result = {
9031
9094
  startT: actualBezierRanges[0] ? actualBezierRanges[0].startT : null,
9032
9095
  endT: actualBezierRanges[1] ? actualBezierRanges[1].endT : null
@@ -9188,7 +9251,7 @@ var MakerJs;
9188
9251
  };
9189
9252
  MakerJs.model.findChains(curve, function (chains, loose, layer) {
9190
9253
  chains.forEach(function (c) {
9191
- var range = getChainBezierRange(curve, c, layer, addToLayer);
9254
+ var range = getChainBezierRange(curve, c, layer, addToLayer, options.pointMatchingDistance);
9192
9255
  if (range) {
9193
9256
  var b = getScratch(curve.seed);
9194
9257
  var piece = b.split(range.startT, range.endT);
@@ -9203,7 +9266,7 @@ var MakerJs;
9203
9266
  //bezier is linear
9204
9267
  return addToLayer(wp.pathContext, layer, true);
9205
9268
  }
9206
- var range = getActualBezierRange(curve, wp.pathContext, MakerJs.point.fromPathEnds(wp.pathContext), wp.offset);
9269
+ var range = getActualBezierRange(curve, wp.pathContext, MakerJs.point.fromPathEnds(wp.pathContext), wp.offset, options.pointMatchingDistance);
9207
9270
  if (range) {
9208
9271
  var b = getScratch(curve.seed);
9209
9272
  var piece = b.split(range.startT, range.endT);
@@ -10178,6 +10241,7 @@ var MakerJs;
10178
10241
  ];
10179
10242
  })(models = MakerJs.models || (MakerJs.models = {}));
10180
10243
  })(MakerJs || (MakerJs = {}));
10244
+ /// <reference types="fontkit" />
10181
10245
  var MakerJs;
10182
10246
  (function (MakerJs) {
10183
10247
  var models;
@@ -10185,13 +10249,13 @@ var MakerJs;
10185
10249
  var Text = /** @class */ (function () {
10186
10250
  /**
10187
10251
  * Renders text in a given font to a model.
10188
- * @param font OpenType.Font object.
10252
+ * @param font OpenType.Font object or fontkit font object.
10189
10253
  * @param text String of text to render.
10190
10254
  * @param fontSize Font size.
10191
10255
  * @param combine Flag (default false) to perform a combineUnion upon each character with characters to the left and right.
10192
10256
  * @param centerCharacterOrigin Flag (default false) to move the x origin of each character to the center. Useful for rotating text characters.
10193
10257
  * @param bezierAccuracy Optional accuracy of Bezier curves.
10194
- * @param opentypeOptions Optional opentype.RenderOptions object.
10258
+ * @param opentypeOptions Optional opentype.RenderOptions object or fontkit layout options.
10195
10259
  * @returns Model of the text.
10196
10260
  */
10197
10261
  function Text(font, text, fontSize, combine, centerCharacterOrigin, bezierAccuracy, opentypeOptions) {
@@ -10203,7 +10267,7 @@ var MakerJs;
10203
10267
  var prevDeleted;
10204
10268
  var prevChar;
10205
10269
  var cb = function (glyph, x, y, _fontSize, options) {
10206
- var charModel = Text.glyphToModel(glyph, _fontSize, bezierAccuracy);
10270
+ var charModel = Text.glyphToModel(glyph, _fontSize, bezierAccuracy, font);
10207
10271
  charModel.origin = [x, 0];
10208
10272
  if (centerCharacterOrigin && (charModel.paths || charModel.models)) {
10209
10273
  var m = MakerJs.measure.modelExtents(charModel);
@@ -10235,62 +10299,227 @@ var MakerJs;
10235
10299
  charIndex++;
10236
10300
  prevChar = charModel;
10237
10301
  };
10238
- font.forEachGlyph(text, 0, 0, fontSize, opentypeOptions, cb);
10302
+ // Detect if font is fontkit (has layout method) or opentype.js (has forEachGlyph)
10303
+ if (font.layout && typeof font.layout === 'function') {
10304
+ // fontkit font - use layout engine
10305
+ var fontkitFont = font;
10306
+ var layoutOpts = opentypeOptions;
10307
+ 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);
10308
+ var scale = fontSize / fontkitFont.unitsPerEm;
10309
+ var currentX = 0;
10310
+ for (var i = 0; i < run.glyphs.length; i++) {
10311
+ var glyph = run.glyphs[i];
10312
+ var position = run.positions[i];
10313
+ var glyphX = currentX + (position.xOffset || 0) * scale;
10314
+ var glyphY = (position.yOffset || 0) * scale;
10315
+ cb(glyph, glyphX, glyphY, fontSize, opentypeOptions);
10316
+ currentX += (position.xAdvance || 0) * scale;
10317
+ }
10318
+ }
10319
+ else {
10320
+ // opentype.js font - use forEachGlyph
10321
+ var opentypeFont = font;
10322
+ opentypeFont.forEachGlyph(text, 0, 0, fontSize, opentypeOptions, cb);
10323
+ }
10239
10324
  }
10240
10325
  /**
10241
- * Convert an opentype glyph to a model.
10242
- * @param glyph Opentype.Glyph object.
10326
+ * Convert an opentype glyph or fontkit glyph to a model.
10327
+ * @param glyph Opentype.Glyph object or fontkit glyph.
10243
10328
  * @param fontSize Font size.
10244
10329
  * @param bezierAccuracy Optional accuracy of Bezier curves.
10330
+ * @param font Optional font object (needed for fontkit to get scale).
10245
10331
  * @returns Model of the glyph.
10246
10332
  */
10247
- Text.glyphToModel = function (glyph, fontSize, bezierAccuracy) {
10333
+ Text.glyphToModel = function (glyph, fontSize, bezierAccuracy, font) {
10248
10334
  var charModel = {};
10249
10335
  var firstPoint;
10250
10336
  var currPoint;
10251
10337
  var pathCount = 0;
10252
- function addPath(p) {
10338
+ function addPath(p, layer) {
10253
10339
  if (!charModel.paths) {
10254
10340
  charModel.paths = {};
10255
10341
  }
10342
+ if (layer) {
10343
+ if (!charModel.layer)
10344
+ charModel.layer = layer;
10345
+ }
10256
10346
  charModel.paths['p_' + ++pathCount] = p;
10257
10347
  }
10258
- function addModel(m) {
10348
+ function addModel(m, layer) {
10259
10349
  if (!charModel.models) {
10260
10350
  charModel.models = {};
10261
10351
  }
10352
+ if (layer) {
10353
+ if (!charModel.layer)
10354
+ charModel.layer = layer;
10355
+ }
10262
10356
  charModel.models['p_' + ++pathCount] = m;
10263
10357
  }
10264
- var p = glyph.getPath(0, 0, fontSize);
10265
- p.commands.map(function (command, i) {
10266
- var points = [[command.x, command.y], [command.x1, command.y1], [command.x2, command.y2]].map(function (p) {
10267
- if (p[0] !== void 0) {
10268
- return MakerJs.point.mirror(p, false, true);
10269
- }
10270
- });
10271
- switch (command.type) {
10272
- case 'M':
10273
- firstPoint = points[0];
10274
- break;
10275
- case 'Z':
10276
- points[0] = firstPoint;
10277
- //fall through to line
10278
- case 'L':
10279
- if (!MakerJs.measure.isPointEqual(currPoint, points[0])) {
10280
- addPath(new MakerJs.paths.Line(currPoint, points[0]));
10358
+ // Detect if this is a fontkit glyph (has path property) or opentype.js glyph (has getPath method)
10359
+ var isFontkitGlyph = glyph.path && !glyph.getPath;
10360
+ var p;
10361
+ if (isFontkitGlyph && font) {
10362
+ // fontkit glyph
10363
+ var scale_1 = fontSize / font.unitsPerEm;
10364
+ p = glyph.path;
10365
+ // Check for color layers (COLR table support)
10366
+ if (glyph.layers && glyph.layers.length > 0) {
10367
+ // Handle color glyph with layers
10368
+ glyph.layers.forEach(function (layer, layerIndex) {
10369
+ var layerGlyph = font.getGlyph(layer.glyph);
10370
+ var layerPath = layerGlyph.path;
10371
+ if (layerPath && layerPath.commands) {
10372
+ // Get color from palette if available
10373
+ var layerColor = void 0;
10374
+ if (font['COLR'] && font['CPAL'] && layer.color !== undefined) {
10375
+ // CPAL table structure varies, try to access color palettes
10376
+ var cpal = font['CPAL'];
10377
+ var colorPalettes = cpal.colorPalettes || cpal.colorRecords;
10378
+ if (colorPalettes && colorPalettes.length > 0) {
10379
+ // Get the first palette
10380
+ var palette = colorPalettes[0];
10381
+ if (palette && palette.length > layer.color) {
10382
+ var color = palette[layer.color];
10383
+ if (color) {
10384
+ // Convert RGBA to hex color for layer name
10385
+ var red = color.red !== undefined ? color.red : color.r || 0;
10386
+ var green = color.green !== undefined ? color.green : color.g || 0;
10387
+ var blue = color.blue !== undefined ? color.blue : color.b || 0;
10388
+ layerColor = "color_".concat(red.toString(16).padStart(2, '0')).concat(green.toString(16).padStart(2, '0')).concat(blue.toString(16).padStart(2, '0'));
10389
+ }
10390
+ }
10391
+ }
10392
+ }
10393
+ // Process layer path commands
10394
+ var layerFirstPoint = void 0;
10395
+ var layerCurrPoint = void 0;
10396
+ for (var _i = 0, _a = layerPath.commands; _i < _a.length; _i++) {
10397
+ var cmd = _a[_i];
10398
+ var points = Text.convertFontkitCommand(cmd, scale_1);
10399
+ switch (cmd.command) {
10400
+ case 'moveTo':
10401
+ layerFirstPoint = points[0];
10402
+ layerCurrPoint = points[0];
10403
+ break;
10404
+ case 'closePath':
10405
+ points[0] = layerFirstPoint;
10406
+ // fall through to line
10407
+ case 'lineTo':
10408
+ if (layerCurrPoint && !MakerJs.measure.isPointEqual(layerCurrPoint, points[0])) {
10409
+ addPath(new MakerJs.paths.Line(layerCurrPoint, points[0]), layerColor);
10410
+ }
10411
+ layerCurrPoint = points[0];
10412
+ break;
10413
+ case 'bezierCurveTo':
10414
+ if (layerCurrPoint) {
10415
+ addModel(new models.BezierCurve(layerCurrPoint, points[0], points[1], points[2], bezierAccuracy), layerColor);
10416
+ }
10417
+ layerCurrPoint = points[2];
10418
+ break;
10419
+ case 'quadraticCurveTo':
10420
+ if (layerCurrPoint) {
10421
+ addModel(new models.BezierCurve(layerCurrPoint, points[0], points[1], bezierAccuracy), layerColor);
10422
+ }
10423
+ layerCurrPoint = points[1];
10424
+ break;
10425
+ }
10426
+ }
10281
10427
  }
10282
- break;
10283
- case 'C':
10284
- addModel(new models.BezierCurve(currPoint, points[1], points[2], points[0], bezierAccuracy));
10285
- break;
10286
- case 'Q':
10287
- addModel(new models.BezierCurve(currPoint, points[1], points[0], bezierAccuracy));
10288
- break;
10428
+ });
10429
+ return charModel;
10430
+ }
10431
+ // Standard fontkit glyph (no color layers)
10432
+ if (!p || !p.commands) {
10433
+ return charModel; // Empty glyph (e.g., space)
10434
+ }
10435
+ for (var _i = 0, _a = p.commands; _i < _a.length; _i++) {
10436
+ var cmd = _a[_i];
10437
+ var points = Text.convertFontkitCommand(cmd, scale_1);
10438
+ switch (cmd.command) {
10439
+ case 'moveTo':
10440
+ firstPoint = points[0];
10441
+ currPoint = points[0];
10442
+ break;
10443
+ case 'closePath':
10444
+ points[0] = firstPoint;
10445
+ // fall through to line
10446
+ case 'lineTo':
10447
+ if (!MakerJs.measure.isPointEqual(currPoint, points[0])) {
10448
+ addPath(new MakerJs.paths.Line(currPoint, points[0]));
10449
+ }
10450
+ currPoint = points[0];
10451
+ break;
10452
+ case 'bezierCurveTo':
10453
+ addModel(new models.BezierCurve(currPoint, points[0], points[1], points[2], bezierAccuracy));
10454
+ currPoint = points[2];
10455
+ break;
10456
+ case 'quadraticCurveTo':
10457
+ addModel(new models.BezierCurve(currPoint, points[0], points[1], bezierAccuracy));
10458
+ currPoint = points[1];
10459
+ break;
10460
+ }
10289
10461
  }
10290
- currPoint = points[0];
10291
- });
10462
+ }
10463
+ else {
10464
+ // opentype.js glyph
10465
+ p = glyph.getPath(0, 0, fontSize);
10466
+ p.commands.map(function (command, i) {
10467
+ var points = [[command.x, command.y], [command.x1, command.y1], [command.x2, command.y2]].map(function (p) {
10468
+ if (p[0] !== void 0) {
10469
+ return MakerJs.point.mirror(p, false, true);
10470
+ }
10471
+ });
10472
+ switch (command.type) {
10473
+ case 'M':
10474
+ firstPoint = points[0];
10475
+ break;
10476
+ case 'Z':
10477
+ points[0] = firstPoint;
10478
+ //fall through to line
10479
+ case 'L':
10480
+ if (!MakerJs.measure.isPointEqual(currPoint, points[0])) {
10481
+ addPath(new MakerJs.paths.Line(currPoint, points[0]));
10482
+ }
10483
+ break;
10484
+ case 'C':
10485
+ addModel(new models.BezierCurve(currPoint, points[1], points[2], points[0], bezierAccuracy));
10486
+ break;
10487
+ case 'Q':
10488
+ addModel(new models.BezierCurve(currPoint, points[1], points[0], bezierAccuracy));
10489
+ break;
10490
+ }
10491
+ currPoint = points[0];
10492
+ });
10493
+ }
10292
10494
  return charModel;
10293
10495
  };
10496
+ /**
10497
+ * Convert fontkit path command to points array
10498
+ * @param cmd Fontkit path command
10499
+ * @param scale Scale factor
10500
+ * @returns Array of points
10501
+ */
10502
+ Text.convertFontkitCommand = function (cmd, scale) {
10503
+ var points = [];
10504
+ switch (cmd.command) {
10505
+ case 'moveTo':
10506
+ case 'lineTo':
10507
+ points.push([cmd.args[0] * scale, cmd.args[1] * scale]);
10508
+ break;
10509
+ case 'quadraticCurveTo':
10510
+ // Control point, end point
10511
+ points.push([cmd.args[0] * scale, cmd.args[1] * scale]);
10512
+ points.push([cmd.args[2] * scale, cmd.args[3] * scale]);
10513
+ break;
10514
+ case 'bezierCurveTo':
10515
+ // Control point 1, control point 2, end point
10516
+ points.push([cmd.args[0] * scale, cmd.args[1] * scale]);
10517
+ points.push([cmd.args[2] * scale, cmd.args[3] * scale]);
10518
+ points.push([cmd.args[4] * scale, cmd.args[5] * scale]);
10519
+ break;
10520
+ }
10521
+ return points;
10522
+ };
10294
10523
  return Text;
10295
10524
  }());
10296
10525
  models.Text = Text;
@@ -10303,6 +10532,7 @@ var MakerJs;
10303
10532
  ];
10304
10533
  })(models = MakerJs.models || (MakerJs.models = {}));
10305
10534
  })(MakerJs || (MakerJs = {}));
10306
- MakerJs.version = "0.18.1";
10535
+ MakerJs.version = "0.19.1";
10307
10536
 
10537
+ }).call(this)}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
10308
10538
  },{"clone":2,"graham_scan":3,"kdbush":4}]},{},[]);