Comparing version 0.1.3 to 0.1.4
@@ -1,2 +0,48 @@ | ||
export declare namespace POP { | ||
declare module "paths/pathGuide" { | ||
export class PathGuide { | ||
path: string; | ||
constructor(count?: number); | ||
createLinesPath(count: number): any; | ||
} | ||
} | ||
declare module "paths/Point" { | ||
export interface Point { | ||
x: number; | ||
y: number; | ||
} | ||
} | ||
declare module "paths/commands" { | ||
export class CommandPath { | ||
static keys: any; | ||
static ignoreWhenSizing: string[]; | ||
} | ||
} | ||
declare module "paths/referencePath" { | ||
import { Point } from "paths/Point"; | ||
export class ReferencePath { | ||
commands: any[]; | ||
constructor(element: any, breakup?: number, min?: Point, max?: Point); | ||
normalize(min?: Point, max?: Point): void; | ||
} | ||
} | ||
declare module "paths/translationPath" { | ||
import { ReferencePath } from "paths/referencePath"; | ||
import { Point } from "paths/Point"; | ||
export 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; | ||
} | ||
} | ||
declare module "index" { | ||
export namespace POP { | ||
} | ||
} |
@@ -1,12 +0,216 @@ | ||
"use strict"; | ||
exports.__esModule = true; | ||
var pathGuide_1 = require("./paths/pathGuide"); | ||
var referencePath_1 = require("./paths/referencePath"); | ||
var translationPath_1 = require("./paths/translationPath"); | ||
var POP; | ||
(function (POP) { | ||
pathGuide_1.PathGuide; | ||
referencePath_1.ReferencePath; | ||
translationPath_1.TranslationPath; | ||
})(POP = exports.POP || (exports.POP = {})); | ||
define("paths/pathGuide", ["require", "exports"], function (require, exports) { | ||
"use strict"; | ||
exports.__esModule = true; | ||
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; | ||
}()); | ||
exports.PathGuide = PathGuide; | ||
}); | ||
define("paths/Point", ["require", "exports"], function (require, exports) { | ||
"use strict"; | ||
exports.__esModule = true; | ||
}); | ||
define("paths/commands", ["require", "exports"], function (require, exports) { | ||
"use strict"; | ||
exports.__esModule = true; | ||
var CommandPath = /** @class */ (function () { | ||
function CommandPath() { | ||
} | ||
CommandPath.keys = { | ||
M: ['x', 'y'], | ||
L: ['x', 'y'], | ||
V: ['y'], | ||
H: ['x'], | ||
C: ['x1', 'y1', 'x2', 'y2', 'x', 'y'], | ||
S: ['x2', 'y2', 'x', 'y'], | ||
Q: ['x1', 'y1', 'x', 'y'], | ||
T: ['x', 'y'], | ||
A: ['rx', 'ry', 'xAxisRotation', 'largeArc', 'sweep', 'x', 'y'], | ||
Z: [] | ||
}; | ||
CommandPath.ignoreWhenSizing = ['rx', 'ry', 'xAxisRotation', 'largeArc', 'sweep']; | ||
return CommandPath; | ||
}()); | ||
exports.CommandPath = CommandPath; | ||
}); | ||
define("paths/referencePath", ["require", "exports", "svg-path-parser", "paths/commands"], function (require, exports, svg_path_parser_1, commands_1) { | ||
"use strict"; | ||
exports.__esModule = true; | ||
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; | ||
}()); | ||
exports.ReferencePath = ReferencePath; | ||
}); | ||
define("paths/translationPath", ["require", "exports", "paths/commands"], function (require, exports, commands_2) { | ||
"use strict"; | ||
exports.__esModule = true; | ||
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_2.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; | ||
}()); | ||
exports.TranslationPath = TranslationPath; | ||
}); | ||
define("index", ["require", "exports", "paths/pathGuide", "paths/referencePath", "paths/translationPath"], function (require, exports, pathGuide_1, referencePath_1, translationPath_1) { | ||
"use strict"; | ||
exports.__esModule = true; | ||
var POP; | ||
(function (POP) { | ||
pathGuide_1.PathGuide; | ||
referencePath_1.ReferencePath; | ||
translationPath_1.TranslationPath; | ||
})(POP = exports.POP || (exports.POP = {})); | ||
}); | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "pop.svg", | ||
"version": "0.1.3", | ||
"version": "0.1.4", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "./dist/index.js", |
@@ -5,3 +5,3 @@ { | ||
//"target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */ | ||
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */ | ||
"module": "amd", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */ | ||
// "lib": [], /* Specify library files to be included in the compilation. */ | ||
@@ -14,4 +14,4 @@ // "allowJs": true, /* Allow javascript files to be compiled. */ | ||
"sourceMap": true, /* Generates corresponding '.map' file. */ | ||
// "outFile": "./", /* Concatenate and emit output to single file. */ | ||
"outDir": "./dist/", /* Redirect output structure to the directory. */ | ||
"outFile": "./dist/index.js", /* Concatenate and emit output to single file. */ | ||
//"outDir": "./dist/", /* Redirect output structure to the directory. */ | ||
//"rootDir": "./src", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */ | ||
@@ -18,0 +18,0 @@ // "composite": true, /* Enable project compilation */ |
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
26870
326
8
1