New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

pop.svg

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pop.svg - npm Package Compare versions

Comparing version 0.1.5 to 0.1.6

24

dist/index.d.ts

@@ -0,2 +1,26 @@

import { Point } from "./paths/Point";
export declare namespace POP {
class PathGuide {
path: string;
constructor(count?: number);
createLinesPath(count: number): any;
}
class ReferencePath {
commands: any[];
constructor(element: any, breakup?: number, min?: Point, max?: Point);
normalize(min?: Point, max?: Point): void;
}
class TranslationPath {
path: SVGPathElement;
width: number;
endWidth: number;
length: number;
constructor(element: any, width: number, endWidth?: number);
updatePath(): void;
getPath(path: ReferencePath, width?: number, endWidth?: number): string;
getWidth(yPercent: number, width: number, endWidth: number): number;
percentToPath(x: number, y: number, width: number, endWidth: number): Point;
getRotation(p1: Point, p2: Point): number;
getRotatedPoint(origin: Point, point: Point, angle: number): Point;
}
}

178

dist/index.js
"use strict";
// import { PathGuide } from "./paths/pathGuide";
// import { ReferencePath } from "./paths/referencePath";
// import { TranslationPath } from "./paths/translationPath";
Object.defineProperty(exports, "__esModule", { value: true });
var pathGuide_1 = require("./paths/pathGuide");
var referencePath_1 = require("./paths/referencePath");
var translationPath_1 = require("./paths/translationPath");
var svg_path_parser_1 = require("svg-path-parser");
var commands_1 = require("./paths/commands");
var POP;
(function (POP) {
pathGuide_1.PathGuide;
referencePath_1.ReferencePath;
translationPath_1.TranslationPath;
var PathGuide = /** @class */ (function () {
function PathGuide(count) {
if (count === void 0) { count = 3; }
this.path = '';
this.path = this.createLinesPath(count);
}
PathGuide.prototype.createLinesPath = function (count) {
var path = document.getElementById('lines');
var linesPath = '';
for (var i = 0; i < count; i++) {
linesPath += "M 0 " + i * 2 + " H 10";
}
if (path)
path.setAttribute('d', linesPath);
return path;
};
return PathGuide;
}());
POP.PathGuide = PathGuide;
var ReferencePath = /** @class */ (function () {
function ReferencePath(element, breakup, min, max) {
var isString = typeof element == 'string';
var pathString = '';
if (isString) {
pathString = element;
this.commands = svg_path_parser_1.makeAbsolute(svg_path_parser_1.parseSVG(pathString || ''));
}
else {
var path = element;
pathString = path.getAttribute('d') || '';
this.commands = svg_path_parser_1.makeAbsolute(svg_path_parser_1.parseSVG(pathString || ''));
if (breakup && breakup > 3) {
if (this.commands[0].code == 'M') {
pathString = "M " + this.commands[0].x + " " + this.commands[0].y;
}
else {
pathString = 'M 0 0';
}
var length_1 = path.getTotalLength();
for (var i = 1; i <= breakup; i++) {
var percent = i / breakup;
var pt = path.getPointAtLength(length_1 * percent);
pathString += "L " + pt.x + " " + pt.y;
}
this.commands = svg_path_parser_1.makeAbsolute(svg_path_parser_1.parseSVG(pathString || ''));
}
}
this.normalize(min, max);
}
ReferencePath.prototype.normalize = function (min, max) {
if (min === void 0) { min = { x: this.commands[0].x, y: this.commands[0].y }; }
if (max === void 0) { max = { x: this.commands[0].x, y: this.commands[0].y }; }
if (this.commands.length > 0) {
var ignore_1 = commands_1.CommandPath.ignoreWhenSizing;
this.commands.map(function (d) {
var keys = commands_1.CommandPath.keys[d.code];
keys.map(function (key) {
var ignoreIndex = ignore_1.indexOf(key);
if (ignoreIndex == -1) {
var direction = key.charAt(0);
if (direction == 'x' || direction == 'y') {
if (min[direction] == null || d[key] < min[direction])
min[direction] = d[key];
if (max[direction] == null || d[key] > max[direction])
max[direction] = d[key];
}
}
});
});
max.x -= min.x;
max.y -= min.y;
this.commands.map(function (d) {
var keys = commands_1.CommandPath.keys[d.code];
keys.map(function (key) {
var ignoreIndex = ignore_1.indexOf(key);
if (ignoreIndex == -1) {
var direction = key.charAt(0);
if (direction == 'x' || direction == 'y') {
d[key] -= min[direction];
d['p' + key] = (d[key] / max[direction]) * 1;
}
}
});
});
}
};
return ReferencePath;
}());
POP.ReferencePath = ReferencePath;
var TranslationPath = /** @class */ (function () {
function TranslationPath(element, width, endWidth) {
this.length = 0;
this.path = element;
this.width = width;
this.endWidth = endWidth !== undefined ? endWidth : width;
this.updatePath();
}
TranslationPath.prototype.updatePath = function () {
this.length = this.path.getTotalLength();
};
TranslationPath.prototype.getPath = function (path, width, endWidth) {
var _this = this;
var newPath = '';
var lastPoint = { x: 0, y: 0 };
path.commands.map(function (command) {
var ignoreCodes = ['A'];
if (ignoreCodes.indexOf(command.code) == -1) {
var code = command.code;
if (code == 'V' || code == 'H')
code = 'L';
newPath += code;
var keys = commands_1.CommandPath.keys[command.code];
for (var i = 0; i < keys.length; i += 2) {
var direction = keys[i].charAt(0);
var x = direction == 'x' ? keys[i] : null;
var y = direction == 'y' ? keys[i] : keys[i + 1] != null ? keys[i + 1] : null;
var xValue = x ? command['p' + x] : lastPoint.x;
var yValue = y ? command['p' + y] : lastPoint.y;
lastPoint.x = xValue;
lastPoint.y = yValue;
var newPoint = _this.percentToPath(xValue, yValue, width || _this.width, endWidth || _this.endWidth);
newPath += ' ' + newPoint.x;
newPath += ' ' + newPoint.y;
}
}
});
return newPath;
};
TranslationPath.prototype.getWidth = function (yPercent, width, endWidth) {
var w = endWidth - width;
var newWidth = width + (w * yPercent);
return newWidth;
};
TranslationPath.prototype.percentToPath = function (x, y, width, endWidth) {
var angleDistance = 0.01;
var pt = this.path.getPointAtLength(this.length * y);
var anglePt = y < angleDistance ? this.path.getPointAtLength(this.length * (y + angleDistance)) : this.path.getPointAtLength(this.length * (y - angleDistance));
var rotation = this.getRotation(y < angleDistance ? anglePt : pt, y < angleDistance ? pt : anglePt);
var w = this.getWidth(y, width, endWidth);
var origin = { x: pt.x, y: pt.y };
var target = { x: pt.x - (w / 2) + (w * x), y: pt.y };
var toReturn = this.getRotatedPoint(origin, target, rotation);
return toReturn;
};
TranslationPath.prototype.getRotation = function (p1, p2) {
var angleRadians = Math.atan2(p2.y - p1.y, p2.x - p1.x);
return angleRadians;
};
TranslationPath.prototype.getRotatedPoint = function (origin, point, angle) {
var newPoint = {
x: point.x - origin.x,
y: point.y - origin.y
};
var x = newPoint.x;
var y = newPoint.y;
var cos = Math.cos(angle);
var sin = Math.sin(angle);
newPoint.y = (cos * x) + (sin * y);
newPoint.x = (cos * y) - (sin * x);
newPoint.x += origin.x;
newPoint.y += origin.y;
return newPoint;
};
return TranslationPath;
}());
POP.TranslationPath = TranslationPath;
;
})(POP = exports.POP || (exports.POP = {}));

2

package.json
{
"name": "pop.svg",
"version": "0.1.5",
"version": "0.1.6",
"description": "",

@@ -5,0 +5,0 @@ "main": "./dist/index.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc