Skip to content

Commit

Permalink
Merge pull request #732 from jonobr1/731-nostroke
Browse files Browse the repository at this point in the history
Made noStroke methods consistent
  • Loading branch information
jonobr1 authored Jul 9, 2024
2 parents 1e2b63f + c9da5de commit 3e63c35
Show file tree
Hide file tree
Showing 7 changed files with 716 additions and 655 deletions.
197 changes: 108 additions & 89 deletions build/two.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
MIT License
Copyright (c) 2012 - 2021 @jonobr1 / http://jono.fyi
Copyright (c) 2012 - 2024 @jonobr1 / http://jono.fyi
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -737,8 +737,8 @@ var Two = (() => {
svg: "SVGRenderer",
canvas: "CanvasRenderer"
},
Version: "v0.8.14",
PublishDate: "2024-06-11T02:06:29.216Z",
Version: "v0.8.15",
PublishDate: "2024-07-09T17:21:48.285Z",
Identifier: "two-",
Resolution: 12,
AutoCalculateImportedMatrices: true,
Expand Down Expand Up @@ -4190,15 +4190,19 @@ var Two = (() => {
return v.toObject();
})
};
_.each(_Path.Properties, function(k) {
if (typeof this[k] !== "undefined") {
if (this[k].toObject) {
result[k] = this[k].toObject();
} else {
result[k] = this[k];
_.each(
_Path.Properties,
function(k) {
if (typeof this[k] !== "undefined") {
if (this[k].toObject) {
result[k] = this[k].toObject();
} else {
result[k] = this[k];
}
}
}
}, this);
},
this
);
result.className = this.className;
result.translation = this.translation.toObject();
result.rotation = this.rotation;
Expand All @@ -4216,6 +4220,7 @@ var Two = (() => {
}
noStroke() {
this.stroke = "none";
this.linewidth = 0;
return this;
}
corner() {
Expand Down Expand Up @@ -4304,16 +4309,7 @@ var Two = (() => {
ly += v1.y;
}
let [c1x, c1y] = matrix.multiply(lx, ly);
const bb = getCurveBoundingBox(
v0x,
v0y,
c0x,
c0y,
c1x,
c1y,
v1x,
v1y
);
const bb = getCurveBoundingBox(v0x, v0y, c0x, c0y, c1x, c1y, v1x, v1y);
top = min3(bb.min.y - border, top);
left = min3(bb.min.x - border, left);
right = max3(bb.max.x + border, right);
Expand Down Expand Up @@ -4457,47 +4453,51 @@ var Two = (() => {
const closed2 = this._closed || this.vertices[last]._command === Commands.close;
let b = this.vertices[last];
let points = [], verts;
_.each(this.vertices, function(a, i) {
if (i <= 0 && !closed2) {
b = a;
return;
}
if (a.command === Commands.move) {
points.push(new Anchor(b.x, b.y));
if (i > 0) {
points[points.length - 1].command = Commands.line;
}
b = a;
return;
}
verts = getSubdivisions(a, b, limit);
points = points.concat(verts);
_.each(verts, function(v, i2) {
if (i2 <= 0 && b.command === Commands.move) {
v.command = Commands.move;
} else {
v.command = Commands.line;
_.each(
this.vertices,
function(a, i) {
if (i <= 0 && !closed2) {
b = a;
return;
}
});
if (i >= last) {
if (this._closed && this._automatic) {
if (a.command === Commands.move) {
points.push(new Anchor(b.x, b.y));
if (i > 0) {
points[points.length - 1].command = Commands.line;
}
b = a;
verts = getSubdivisions(a, b, limit);
points = points.concat(verts);
_.each(verts, function(v, i2) {
if (i2 <= 0 && b.command === Commands.move) {
v.command = Commands.move;
} else {
v.command = Commands.line;
}
});
} else if (closed2) {
points.push(new Anchor(a.x, a.y));
return;
}
points[points.length - 1].command = closed2 ? Commands.close : Commands.line;
}
b = a;
}, this);
verts = getSubdivisions(a, b, limit);
points = points.concat(verts);
_.each(verts, function(v, i2) {
if (i2 <= 0 && b.command === Commands.move) {
v.command = Commands.move;
} else {
v.command = Commands.line;
}
});
if (i >= last) {
if (this._closed && this._automatic) {
b = a;
verts = getSubdivisions(a, b, limit);
points = points.concat(verts);
_.each(verts, function(v, i2) {
if (i2 <= 0 && b.command === Commands.move) {
v.command = Commands.move;
} else {
v.command = Commands.line;
}
});
} else if (closed2) {
points.push(new Anchor(a.x, a.y));
}
points[points.length - 1].command = closed2 ? Commands.close : Commands.line;
}
b = a;
},
this
);
this._automatic = false;
this._curved = false;
this.vertices = points;
Expand All @@ -4515,21 +4515,25 @@ var Two = (() => {
if (typeof this._lengths === "undefined") {
this._lengths = [];
}
_.each(this.vertices, function(a, i) {
if (i <= 0 && !closed2 || a.command === Commands.move) {
_.each(
this.vertices,
function(a, i) {
if (i <= 0 && !closed2 || a.command === Commands.move) {
b = a;
this._lengths[i] = 0;
return;
}
this._lengths[i] = getCurveLength2(a, b, limit);
sum += this._lengths[i];
if (i >= last && closed2) {
b = this.vertices[(i + 1) % length];
this._lengths[i + 1] = getCurveLength2(a, b, limit);
sum += this._lengths[i + 1];
}
b = a;
this._lengths[i] = 0;
return;
}
this._lengths[i] = getCurveLength2(a, b, limit);
sum += this._lengths[i];
if (i >= last && closed2) {
b = this.vertices[(i + 1) % length];
this._lengths[i + 1] = getCurveLength2(a, b, limit);
sum += this._lengths[i + 1];
}
b = a;
}, this);
},
this
);
this._length = sum;
this._flagLength = false;
return this;
Expand Down Expand Up @@ -6140,7 +6144,13 @@ var Two = (() => {
middle: "center",
end: "right"
};
var reservedAttributesToRemove = ["id", "class", "transform", "xmlns", "viewBox"];
var reservedAttributesToRemove = [
"id",
"class",
"transform",
"xmlns",
"viewBox"
];
var overwriteAttrs = ["x", "y", "width", "height", "href", "xlink:href"];
function getAlignment(anchor2) {
return alignments[anchor2];
Expand All @@ -6151,7 +6161,7 @@ var Two = (() => {
return a || b;
}
function getTagName(tag) {
return tag.replace(/svg:/ig, "").toLowerCase();
return tag.replace(/svg:/gi, "").toLowerCase();
}
function applyTransformsToVector(transforms, vector3) {
vector3.x += transforms.translateX;
Expand Down Expand Up @@ -6594,10 +6604,14 @@ var Two = (() => {
points = node.getAttribute("points");
}
const verts = [];
points.replace(/(-?[\d.eE-]+)[,|\s](-?[\d.eE-]+)/g, function(match, p1, p2) {
verts.push(new Anchor(parseFloat(p1), parseFloat(p2)));
});
const poly = new Path(verts, true).noStroke();
points.replace(
/(-?[\d.eE-]+)[,|\s](-?[\d.eE-]+)/g,
function(match, p1, p2) {
verts.push(new Anchor(parseFloat(p1), parseFloat(p2)));
}
);
const poly = new Path(verts, true);
poly.stroke = "none";
poly.fill = "black";
applySvgAttributes.call(this, node, poly, parentStyles);
return poly;
Expand All @@ -6620,7 +6634,7 @@ var Two = (() => {
if (path) {
let coord = new Anchor();
let control, coords;
let commands = path.match(/[a-df-z][^a-df-z]*/ig);
let commands = path.match(/[a-df-z][^a-df-z]*/gi);
const last = commands.length - 1;
_.each(commands.slice(0), function(command, i) {
const items = command.slice(1).trim().match(regex2.path);
Expand Down Expand Up @@ -6882,7 +6896,8 @@ var Two = (() => {
}
});
}
path = new Path(points, closed2, void 0, true).noStroke();
path = new Path(points, closed2, void 0, true);
path.stroke = "none";
path.fill = "black";
const rect = path.getBoundingClientRect(true);
rect.centroid = {
Expand All @@ -6900,7 +6915,8 @@ var Two = (() => {
const x = parseFloat(node.getAttribute("cx"));
const y = parseFloat(node.getAttribute("cy"));
const r = parseFloat(node.getAttribute("r"));
const circle = new Circle(0, 0, r).noStroke();
const circle = new Circle(0, 0, r);
circle.stroke = "none";
circle.fill = "black";
applySvgAttributes.call(this, node, circle, parentStyles);
circle.translation.x = x;
Expand All @@ -6912,7 +6928,8 @@ var Two = (() => {
const y = parseFloat(node.getAttribute("cy"));
const width = parseFloat(node.getAttribute("rx"));
const height = parseFloat(node.getAttribute("ry"));
const ellipse = new Ellipse(0, 0, width, height).noStroke();
const ellipse = new Ellipse(0, 0, width, height);
ellipse.stroke = "none";
ellipse.fill = "black";
applySvgAttributes.call(this, node, ellipse, parentStyles);
ellipse.translation.x = x;
Expand All @@ -6929,7 +6946,8 @@ var Two = (() => {
const height = parseFloat(node.getAttribute("height"));
const w2 = width / 2;
const h2 = height / 2;
const rect = new Rectangle(0, 0, width, height).noStroke();
const rect = new Rectangle(0, 0, width, height);
rect.stroke = "none";
rect.fill = "black";
applySvgAttributes.call(this, node, rect, parentStyles);
rect.translation.x += w2;
Expand All @@ -6944,7 +6962,8 @@ var Two = (() => {
const w2 = width / 2;
const h2 = height / 2;
const radius = new Vector(rx, ry);
const rect = new RoundedRectangle(0, 0, width, height, radius).noStroke();
const rect = new RoundedRectangle(0, 0, width, height, radius);
rect.stroke = "none";
rect.fill = "black";
applySvgAttributes.call(this, node, rect, parentStyles);
rect.translation.x += w2;
Expand Down Expand Up @@ -6985,8 +7004,8 @@ var Two = (() => {
for (let i = 0; i < node.children.length; i++) {
const child = node.children[i];
let offset = child.getAttribute("offset");
if (/%/ig.test(offset)) {
offset = parseFloat(offset.replace(/%/ig, "")) / 100;
if (/%/gi.test(offset)) {
offset = parseFloat(offset.replace(/%/gi, "")) / 100;
}
offset = parseFloat(offset);
let color = child.getAttribute("stop-color");
Expand Down Expand Up @@ -7043,8 +7062,8 @@ var Two = (() => {
for (let i = 0; i < node.children.length; i++) {
const child = node.children[i];
let offset = child.getAttribute("offset");
if (/%/ig.test(offset)) {
offset = parseFloat(offset.replace(/%/ig, "")) / 100;
if (/%/gi.test(offset)) {
offset = parseFloat(offset.replace(/%/gi, "")) / 100;
}
offset = parseFloat(offset);
let color = child.getAttribute("stop-color");
Expand Down
4 changes: 2 additions & 2 deletions build/two.min.js

Large diffs are not rendered by default.

Loading

0 comments on commit 3e63c35

Please sign in to comment.