makerjs 0.17.2 → 0.17.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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.17.2
42
+ * version: 0.17.4
43
43
  *
44
44
  * browserify:
45
45
  * license: MIT (http://opensource.org/licenses/MIT)
@@ -7742,7 +7742,8 @@ var MakerJs;
7742
7742
  "stroke": elOpts.stroke,
7743
7743
  "stroke-width": elOpts.strokeWidth,
7744
7744
  "fill": elOpts.fill,
7745
- "style": elOpts.cssStyle || cssStyle(elOpts)
7745
+ "style": elOpts.cssStyle || cssStyle(elOpts),
7746
+ "class": elOpts.className
7746
7747
  });
7747
7748
  }
7748
7749
  function colorLayerOptions(layer) {
@@ -8383,10 +8384,12 @@ var MakerJs;
8383
8384
  cpa.sort(function (a, b) { return a.xRatio - b.xRatio; });
8384
8385
  var first = cpa[0];
8385
8386
  var last = cpa[cpa.length - 1];
8386
- var min = first.xRatio;
8387
- var max = last.xRatio;
8388
- var span = max - min;
8389
- cpa.forEach(function (cp) { return cp.xRatio = (cp.xRatio - min) / span; });
8387
+ if (cpa.length > 1) {
8388
+ var min = first.xRatio;
8389
+ var max = last.xRatio;
8390
+ var span = max - min;
8391
+ cpa.forEach(function (cp) { return cp.xRatio = (cp.xRatio - min) / span; });
8392
+ }
8390
8393
  return {
8391
8394
  cpa: cpa,
8392
8395
  firstX: xMap[first.childId],
@@ -8439,7 +8442,7 @@ var MakerJs;
8439
8442
  var result = getChildPlacement(parentModel, baseline);
8440
8443
  var cpa = result.cpa;
8441
8444
  var chosenPath = onPath;
8442
- if (contain) {
8445
+ if (contain && cpa.length > 1) {
8443
8446
  //see if we need to clip
8444
8447
  var onPathLength = MakerJs.measure.pathLength(onPath);
8445
8448
  if (result.firstX + result.lastX < onPathLength) {
@@ -8501,35 +8504,52 @@ var MakerJs;
8501
8504
  var result = getChildPlacement(parentModel, baseline);
8502
8505
  var cpa = result.cpa;
8503
8506
  var chainLength = onChain.pathLength;
8504
- if (contain)
8505
- chainLength -= result.firstX + result.lastX;
8506
- var absolutes = cpa.map(function (cp) { return (reversed ? 1 - cp.xRatio : cp.xRatio) * chainLength; });
8507
- var relatives;
8508
- if (reversed)
8509
- absolutes.reverse();
8510
- relatives = absolutes.map(function (ab, i) { return Math.abs(ab - (i == 0 ? 0 : absolutes[i - 1])); });
8511
- if (contain) {
8512
- relatives[0] += reversed ? result.lastX : result.firstX;
8507
+ var points;
8508
+ if (cpa.length > 1) {
8509
+ if (contain)
8510
+ chainLength -= result.firstX + result.lastX;
8511
+ var absolutes = cpa.map(function (cp) { return (reversed ? 1 - cp.xRatio : cp.xRatio) * chainLength; });
8512
+ var relatives;
8513
+ if (reversed)
8514
+ absolutes.reverse();
8515
+ relatives = absolutes.map(function (ab, i) { return Math.abs(ab - (i == 0 ? 0 : absolutes[i - 1])); });
8516
+ if (contain) {
8517
+ relatives[0] += reversed ? result.lastX : result.firstX;
8518
+ }
8519
+ else {
8520
+ relatives.shift();
8521
+ }
8522
+ //chain.toPoints always follows the chain in its order, from beginning to end. This is why we needed to contort the points input
8523
+ points = MakerJs.chain.toPoints(onChain, relatives);
8524
+ if (points.length < cpa.length) {
8525
+ //add last point of chain, since our distances exceeded the chain
8526
+ var endLink = onChain.links[onChain.links.length - 1];
8527
+ points.push(endLink.endPoints[endLink.reversed ? 0 : 1]);
8528
+ }
8529
+ if (contain)
8530
+ points.shift(); //delete the first point which is the beginning of the chain
8513
8531
  }
8514
8532
  else {
8515
- relatives.shift();
8533
+ //get the first point and the middle point of the chain
8534
+ points = MakerJs.chain.toPoints(onChain, 0.5 * chainLength);
8535
+ points.length = 2;
8536
+ //add the last point of the chain
8537
+ points.push(onChain.links[onChain.links.length - 1].endPoints[onChain.links[onChain.links.length - 1].reversed ? 0 : 1]);
8516
8538
  }
8517
- //chain.toPoints always follows the chain in its order, from beginning to end. This is why we needed to contort the points input
8518
- var points = MakerJs.chain.toPoints(onChain, relatives);
8519
- if (points.length < cpa.length) {
8520
- //add last point of chain, since our distances exceeded the chain
8521
- var endLink = onChain.links[onChain.links.length - 1];
8522
- points.push(endLink.endPoints[endLink.reversed ? 0 : 1]);
8523
- }
8524
- if (contain)
8525
- points.shift(); //delete the first point which is the beginning of the chain
8526
8539
  if (reversed)
8527
8540
  points.reverse();
8528
8541
  var angles = miterAngles(points, -90);
8529
- cpa.forEach(function (cp, i) {
8530
- cp.angle = angles[i];
8531
- cp.origin = points[i];
8532
- });
8542
+ if (cpa.length > 1) {
8543
+ cpa.forEach(function (cp, i) {
8544
+ cp.angle = angles[i];
8545
+ cp.origin = points[i];
8546
+ });
8547
+ }
8548
+ else {
8549
+ //use the middle point
8550
+ cpa[0].angle = angles[1];
8551
+ cpa[0].origin = points[1];
8552
+ }
8533
8553
  moveAndRotate(parentModel, cpa, rotated);
8534
8554
  return parentModel;
8535
8555
  }
@@ -10285,6 +10305,6 @@ var MakerJs;
10285
10305
  ];
10286
10306
  })(models = MakerJs.models || (MakerJs.models = {}));
10287
10307
  })(MakerJs || (MakerJs = {}));
10288
- MakerJs.version = "0.17.2";
10308
+ MakerJs.version = "0.17.4";
10289
10309
 
10290
10310
  },{"clone":2,"graham_scan":3,"kdbush":4}]},{},[]);
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- // Type definitions for Maker.js 0.17.2
1
+ // Type definitions for Maker.js 0.17.4
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
@@ -3314,6 +3314,10 @@ declare namespace MakerJs.exporter {
3314
3314
  * CSS style to apply to elements.
3315
3315
  */
3316
3316
  cssStyle?: string;
3317
+ /**
3318
+ * SVG class name of the rendered paths.
3319
+ */
3320
+ className?: string;
3317
3321
  }
3318
3322
  /**
3319
3323
  * Annotate paths with directional flow marks.
package/dist/index.js CHANGED
@@ -7325,7 +7325,8 @@ var MakerJs;
7325
7325
  "stroke": elOpts.stroke,
7326
7326
  "stroke-width": elOpts.strokeWidth,
7327
7327
  "fill": elOpts.fill,
7328
- "style": elOpts.cssStyle || cssStyle(elOpts)
7328
+ "style": elOpts.cssStyle || cssStyle(elOpts),
7329
+ "class": elOpts.className
7329
7330
  });
7330
7331
  }
7331
7332
  function colorLayerOptions(layer) {
@@ -7966,10 +7967,12 @@ var MakerJs;
7966
7967
  cpa.sort(function (a, b) { return a.xRatio - b.xRatio; });
7967
7968
  var first = cpa[0];
7968
7969
  var last = cpa[cpa.length - 1];
7969
- var min = first.xRatio;
7970
- var max = last.xRatio;
7971
- var span = max - min;
7972
- cpa.forEach(function (cp) { return cp.xRatio = (cp.xRatio - min) / span; });
7970
+ if (cpa.length > 1) {
7971
+ var min = first.xRatio;
7972
+ var max = last.xRatio;
7973
+ var span = max - min;
7974
+ cpa.forEach(function (cp) { return cp.xRatio = (cp.xRatio - min) / span; });
7975
+ }
7973
7976
  return {
7974
7977
  cpa: cpa,
7975
7978
  firstX: xMap[first.childId],
@@ -8022,7 +8025,7 @@ var MakerJs;
8022
8025
  var result = getChildPlacement(parentModel, baseline);
8023
8026
  var cpa = result.cpa;
8024
8027
  var chosenPath = onPath;
8025
- if (contain) {
8028
+ if (contain && cpa.length > 1) {
8026
8029
  //see if we need to clip
8027
8030
  var onPathLength = MakerJs.measure.pathLength(onPath);
8028
8031
  if (result.firstX + result.lastX < onPathLength) {
@@ -8084,35 +8087,52 @@ var MakerJs;
8084
8087
  var result = getChildPlacement(parentModel, baseline);
8085
8088
  var cpa = result.cpa;
8086
8089
  var chainLength = onChain.pathLength;
8087
- if (contain)
8088
- chainLength -= result.firstX + result.lastX;
8089
- var absolutes = cpa.map(function (cp) { return (reversed ? 1 - cp.xRatio : cp.xRatio) * chainLength; });
8090
- var relatives;
8091
- if (reversed)
8092
- absolutes.reverse();
8093
- relatives = absolutes.map(function (ab, i) { return Math.abs(ab - (i == 0 ? 0 : absolutes[i - 1])); });
8094
- if (contain) {
8095
- relatives[0] += reversed ? result.lastX : result.firstX;
8090
+ var points;
8091
+ if (cpa.length > 1) {
8092
+ if (contain)
8093
+ chainLength -= result.firstX + result.lastX;
8094
+ var absolutes = cpa.map(function (cp) { return (reversed ? 1 - cp.xRatio : cp.xRatio) * chainLength; });
8095
+ var relatives;
8096
+ if (reversed)
8097
+ absolutes.reverse();
8098
+ relatives = absolutes.map(function (ab, i) { return Math.abs(ab - (i == 0 ? 0 : absolutes[i - 1])); });
8099
+ if (contain) {
8100
+ relatives[0] += reversed ? result.lastX : result.firstX;
8101
+ }
8102
+ else {
8103
+ relatives.shift();
8104
+ }
8105
+ //chain.toPoints always follows the chain in its order, from beginning to end. This is why we needed to contort the points input
8106
+ points = MakerJs.chain.toPoints(onChain, relatives);
8107
+ if (points.length < cpa.length) {
8108
+ //add last point of chain, since our distances exceeded the chain
8109
+ var endLink = onChain.links[onChain.links.length - 1];
8110
+ points.push(endLink.endPoints[endLink.reversed ? 0 : 1]);
8111
+ }
8112
+ if (contain)
8113
+ points.shift(); //delete the first point which is the beginning of the chain
8096
8114
  }
8097
8115
  else {
8098
- relatives.shift();
8116
+ //get the first point and the middle point of the chain
8117
+ points = MakerJs.chain.toPoints(onChain, 0.5 * chainLength);
8118
+ points.length = 2;
8119
+ //add the last point of the chain
8120
+ points.push(onChain.links[onChain.links.length - 1].endPoints[onChain.links[onChain.links.length - 1].reversed ? 0 : 1]);
8099
8121
  }
8100
- //chain.toPoints always follows the chain in its order, from beginning to end. This is why we needed to contort the points input
8101
- var points = MakerJs.chain.toPoints(onChain, relatives);
8102
- if (points.length < cpa.length) {
8103
- //add last point of chain, since our distances exceeded the chain
8104
- var endLink = onChain.links[onChain.links.length - 1];
8105
- points.push(endLink.endPoints[endLink.reversed ? 0 : 1]);
8106
- }
8107
- if (contain)
8108
- points.shift(); //delete the first point which is the beginning of the chain
8109
8122
  if (reversed)
8110
8123
  points.reverse();
8111
8124
  var angles = miterAngles(points, -90);
8112
- cpa.forEach(function (cp, i) {
8113
- cp.angle = angles[i];
8114
- cp.origin = points[i];
8115
- });
8125
+ if (cpa.length > 1) {
8126
+ cpa.forEach(function (cp, i) {
8127
+ cp.angle = angles[i];
8128
+ cp.origin = points[i];
8129
+ });
8130
+ }
8131
+ else {
8132
+ //use the middle point
8133
+ cpa[0].angle = angles[1];
8134
+ cpa[0].origin = points[1];
8135
+ }
8116
8136
  moveAndRotate(parentModel, cpa, rotated);
8117
8137
  return parentModel;
8118
8138
  }
@@ -9868,5 +9888,5 @@ var MakerJs;
9868
9888
  ];
9869
9889
  })(models = MakerJs.models || (MakerJs.models = {}));
9870
9890
  })(MakerJs || (MakerJs = {}));
9871
- MakerJs.version = "0.17.2";
9891
+ MakerJs.version = "0.17.4";
9872
9892
  var Bezier = require('bezier-js');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "makerjs",
3
- "version": "0.17.2",
3
+ "version": "0.17.4",
4
4
  "description": "Maker.js, a Microsoft Garage project, is a JavaScript library for creating and sharing modular line drawings for CNC and laser cutters.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",