UNPKG

makerjs-card

Version:
666 lines 299 kB
��(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){ var makerjs = require('makerjs'); var makerjs_logo = require('makerjs-logo'); var makerjs_monotext = require('makerjs-monotext'); function card(w, h, outerRadius, rim, boltRadius, conn, logoOutline, logoScale, logoY, logoAngle, textScale, textY, tabMargin, tabHeight, tabR ) { if (arguments.length == 0) { var defaultValues = makerjs.kit.getParameterValues(card); function v() { return defaultValues.shift(); } w = v(); h = v(); outerRadius = v(); rim = v(); boltRadius = v(); conn = v(); logoOutline = v(); logoScale = v(); logoY = v(); logoAngle = v(); textScale = v(); textY = v(); tabMargin = v(); tabHeight = v(); tabR = v(); } function hCenter(model, y) { var measure = makerjs.measure.modelExtents(model); var mw = measure.high[0]; model.origin = [(w - mw) / 2, y]; return mw; } function flipArcs(roundRect) { function findAndFlip(arcId, origin) { var arc = roundRect.paths[arcId]; arc.startAngle = makerjs.angle.mirror(arc.startAngle, true, true); arc.endAngle = makerjs.angle.mirror(arc.endAngle, true, true); arc.origin = origin; } findAndFlip('BottomLeft', [0, 0]); findAndFlip('BottomRight', [innerW, 0]); findAndFlip('TopLeft', [0, innerH]); findAndFlip('TopRight', [innerW, innerH]); } var outer = new makerjs.models.RoundRectangle(w, h, outerRadius); var bolts = new makerjs.models.BoltRectangle(w - 2 * rim, h - 2 * rim, boltRadius); bolts.origin = [rim, rim]; var logo = makerjs.model.scale(new makerjs_logo(1.06, .3, .35, logoOutline, 8.3, .65, logoAngle, 1, 2.7, 1.32, 2.31), logoScale); hCenter(logo, logoY); var text = makerjs.model.scale(new makerjs_monotext('MAKERJS.ORG'), textScale); var textW = hCenter(text, textY); var tabW = textW + tabMargin; var tab = new makerjs.models.RoundRectangle(tabW, tabHeight, tabR); hCenter(tab, rim - tabR); var innerW = w - 2 * rim; var innerH = h - 2 * rim; var inner = new makerjs.models.RoundRectangle(innerW, innerH, rim); inner.origin = [rim, rim]; flipArcs(inner); this.units = makerjs.unitType.Millimeter; this.paths = {}; var plus = { origin: [(w - conn) / 2, (h - conn) / 2], paths: { n1: new makerjs.paths.Line([0, 0], [0, h]), n2: new makerjs.paths.Line([conn, 0], [conn, h]), s1: new makerjs.paths.Line([0, -h], [0, 0]), s2: new makerjs.paths.Line([conn, -h], [conn, 0]), w1: new makerjs.paths.Line([-w, 0], [0, 0]), w2: new makerjs.paths.Line([-w, conn], [0, conn]), e1: new makerjs.paths.Line([0, 0], [w, 0]), e2: new makerjs.paths.Line([0, conn], [w, conn]) } } makerjs.model.rotate(plus, -logoAngle, plus.origin); this.models = { logo: logo, text: text, outer: outer, bolts: bolts, inner: inner, tab: tab, plus: plus }; makerjs.model.originate(this); makerjs.model.combine(tab, inner, true, false, false, true); makerjs.model.combine(plus, { models: { inner: inner, tab: tab} }, true, false, false, true); makerjs.model.combine(plus, logo.models.outline, false, true, false, true); } card.metaParameters = [ { title: "width", type: "range", min: 30, max: 200, value: 75 }, { title: "height", type: "range", min: 30, max: 200, value: 60 }, { title: "outer radius", type: "range", min: 0, max: 10, step: .5, value: 4 }, { title: "rim", type: "range", min: 1, max: 10, step: .5, value: 4 }, { title: "bolt radius", type: "range", min: 0, max: 5, step: .1, value: 1.5 }, { title: "connector width", type: "range", min: .5, max: 5, step: .1, value: 2.75 }, { title: "logo outline", type: "range", min: .3, max: 3, step: .1, value: 1.3 }, { title: "logo scale", type: "range", min: 1, max: 6, step: .1, value: 3.33 }, { title: "logo y-offset", type: "range", min: 0, max: 30, step: 1, value: 17 }, { title: "logo angle", type: "range", min: 0, max: 45, step: 1, value: 19 }, { title: "text scale", type: "range", min: .005, max: .05, step: .001, value: .03 }, { title: "text y-offset", type: "range", min: 0, max: 10, step: .1, value: 3.5 }, { title: "text margin", type: "range", min: 1, max: 10, step: .1, value: 7 }, { title: "tab height", type: "range", min: 2, max: 15, step: .5, value: 9.5 }, { title: "tab radius", type: "range", min: 0, max: 2, step: .1, value: 1.5 }, ]; module.exports = card; },{"makerjs":6,"makerjs-logo":2,"makerjs-monotext":4}],2:[function(require,module,exports){ var makerjs = require('makerjs'); var point = makerjs.point; var path = makerjs.path; var paths = makerjs.paths; var Line = paths.Line; var Parallel = paths.Parallel; var model = makerjs.model; function logo(or, ir, ear, outline, mHeight, serifHeight, speed, drop, columnWidth, spacing, step) { if (arguments.length == 0) { var v = makerjs.kit.getParameterValues(logo); or = v.shift(); ir = v.shift(); ear = v.shift(); outline = v.shift(); mHeight = v.shift(); serifHeight = v.shift(); speed = v.shift(); drop = v.shift(); columnWidth = v.shift(); spacing = v.shift(); step = v.shift(); } function M() { this.models = { base: { paths: {} }, legs: { models: {} } }; } var m_letter = new M(); var m_outline = new M(); var legModels = m_letter.models.legs.models; var outlineModels = m_outline.models.legs.models; var far = 100; function addLeg(id, leftRef, leftSpace, topRef, topSpace, topPoint, trimToLeftRef, earDistance) { var leg = { paths: {} }; leg.paths.top = new Parallel(topRef, topSpace, topPoint); leg.paths.left = new Parallel(leftRef, leftSpace, [far, 0]); leg.paths.serif = new Parallel(leg.paths.top, serifHeight, [0, 0]); leg.paths.right = new Parallel(leg.paths.left, columnWidth, [far, 0]); leg.paths.ear = new Parallel(leg.paths.left, earDistance, [0, 0]); legModels[id] = leg; var outleg = { paths: {} }; outleg.paths.top = new Parallel(leg.paths.top, outline, [0, far]); outleg.paths.left = new Parallel(leg.paths.left, outline, [-far, 0]); outleg.paths.serif = new Parallel(leg.paths.serif, outline, [0, 0]); outleg.paths.right = new Parallel(leg.paths.right, outline, [far, 0]); outleg.paths.ear = new Parallel(leg.paths.ear, outline, [-far, 0]); outlineModels[id] = outleg; } function trimLeg(id) { function trimLegPart(leg, innerRadius, outerRadius) { trimLines(leg.paths.top, leg.paths.right); trimLines(leg.paths.serif, leg.paths.left); leg.paths.innerFillet = path.fillet(leg.paths.left, leg.paths.serif, innerRadius); leg.paths.outerFillet = path.fillet(leg.paths.top, leg.paths.right, outerRadius); trimLines(leg.paths.top, leg.paths.ear, true); trimLines(leg.paths.serif, leg.paths.ear, true, true); } trimLegPart(legModels[id], ir, or); trimLegPart(outlineModels[id], ir - outline, or + outline); } function combineM(m) { var legs = m.models.legs; model.combine(legs.models['1'], legs.models['2'], false, true, false, true); model.combine(legs.models['2'], legs.models['3'], false, true, false, true); model.combine(m.models.base, legs, true, false, false, true); } m_outline.models.base.paths.bottom = new Line([0, 0], [far, 0]); m_letter.models.base.paths.bottom = new Parallel(m_outline.models.base.paths.bottom, outline, [0, far]); var rotatedLeft = path.rotate(new Line([0, 0], [0, far]), -speed, [0, 0]); var rotatedBottom = path.rotate(new Line([-far, outline], [far, outline]), drop, [0, outline]); addLeg('1', rotatedLeft, outline, rotatedBottom, mHeight, [0, far], false, ear + ir); addLeg('2', legModels['1'].paths.right, spacing, legModels['1'].paths.top, step, [0, 0], true, spacing + columnWidth / 2); addLeg('3', legModels['2'].paths.right, spacing, legModels['2'].paths.top, step, [0, 0], true, spacing + columnWidth / 2); trimLeg('1', false); trimLeg('2', true); trimLeg('3', true); combineM(m_letter); combineM(m_outline); this.models = { letter: m_letter, outline: m_outline }; } function trimLines(line1, line2, useLine1Origin, useLine2Origin) { var int = path.slopeIntersectionPoint(line1, line2); if (int) { line1[useLine1Origin ? 'origin' : 'end'] = int; line2[useLine2Origin ? 'origin' : 'end'] = int; } } logo.metaParameters = [ { title: "outer radius", type: "range", min: 0, max: 1.7, step: .1, value: 1.06 }, { title: "inner radius", type: "range", min: 0, max: .9, step: .1, value: .3 }, { title: "ear", type: "range", min: 0, max: 2, step: .1, value: 1.1 }, { title: "outline", type: "range", min: 0.2, max: 2, step: .1, value: 1.06 }, { title: "m height", type: "range", min: 7, max: 20, step: .1, value: 8.3 }, { title: "serif height", type: "range", min: .1, max: 1.9, step: .1, value: .65 }, { title: "speed", type: "range", min: 0, max: 45, step: 1, value: 19.01 }, { title: "drop", type: "range", min: 0, max: 30, step: 1, value: 1 }, { title: "column width", type: "range", min: .4, max: 5, step: .1, value: 2.59 }, { title: "spacing", type: "range", min: 1.3, max: 5, step: .1, value: 1.25 }, { title: "step", type: "range", min: 0, max: 4, step: .1, value: 2.385 }, ]; module.exports = logo; },{"makerjs":3}],3:[function(require,module,exports){ /*! ***************************************************************************** Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT. See the Apache Version 2.0 License for specific language governing permissions and limitations under the License. ***************************************************************************** */ //https://github.com/Microsoft/maker.js /** * Root module for Maker.js. * * Example: get a reference to Maker.js * ``` * var makerjs = require('makerjs'); * ``` * */ var MakerJs; (function (MakerJs) { //units /** * String-based enumeration of unit types: imperial, metric or otherwise. * A model may specify the unit system it is using, if any. When importing a model, it may have different units. * Unit conversion function is makerjs.units.conversionScale(). * Important: If you add to this, you must also add a corresponding conversion ratio in the unit.ts file! */ MakerJs.unitType = { Centimeter: 'cm', Foot: 'foot', Inch: 'inch', Meter: 'm', Millimeter: 'mm' }; /** * Numeric rounding * * Example: round to 3 decimal places * ``` * makerjs.round(3.14159, .001); //returns 3.142 * ``` * * @param n The number to round off. * @param accuracy Optional exemplar of number of decimal places. */ function round(n, accuracy) { if (accuracy === void 0) { accuracy = .0000001; } var places = 1 / accuracy; return Math.round(n * places) / places; } MakerJs.round = round; /** * Clone an object. * * @param objectToClone The object to clone. * @returns A new clone of the original object. */ function cloneObject(objectToClone) { var serialized = JSON.stringify(objectToClone); return JSON.parse(serialized); } MakerJs.cloneObject = cloneObject; /** * Copy the properties from one object to another object. * * Example: * ``` * makerjs.extendObject({ abc: 123 }, { xyz: 789 }); //returns { abc: 123, xyz: 789 } * ``` * * @param target The object to extend. It will receive the new properties. * @param other An object containing properties to merge in. * @returns The original object after merging. */ function extendObject(target, other) { if (target && other) { for (var key in other) { if (typeof other[key] !== 'undefined') { target[key] = other[key]; } } } return target; } MakerJs.extendObject = extendObject; /** * Test to see if an object implements the required properties of a point. * * @param item The item to test. */ function isPoint(item) { return (Array.isArray(item) && item.length > 1); } MakerJs.isPoint = isPoint; /** * Test to see if an object implements the required properties of a path. * * @param item The item to test. */ function isPath(item) { return item && item.type && item.origin; } MakerJs.isPath = isPath; /** * Test to see if an object implements the required properties of a line. * * @param item The item to test. */ function isPathLine(item) { return isPath(item) && item.type == MakerJs.pathType.Line && item.end; } MakerJs.isPathLine = isPathLine; /** * Test to see if an object implements the required properties of a circle. * * @param item The item to test. */ function isPathCircle(item) { return isPath(item) && item.type == MakerJs.pathType.Circle && item.radius; } MakerJs.isPathCircle = isPathCircle; /** * Test to see if an object implements the required properties of an arc. * * @param item The item to test. */ function isPathArc(item) { return isPath(item) && item.type == MakerJs.pathType.Arc && item.radius && item.startAngle && item.endAngle; } MakerJs.isPathArc = isPathArc; /** * String-based enumeration of all paths types. * * Examples: use pathType instead of string literal when creating a circle. * ``` * var circle: IPathCircle = { type: pathType.Circle, origin: [0, 0], radius: 7 }; //typescript * var circle = { type: pathType.Circle, origin: [0, 0], radius: 7 }; //javascript * ``` */ MakerJs.pathType = { Line: "line", Circle: "circle", Arc: "arc" }; /** * Test to see if an object implements the required properties of a model. */ function isModel(item) { return item && (item.paths || item.models); } MakerJs.isModel = isModel; })(MakerJs || (MakerJs = {})); //CommonJs module.exports = MakerJs; var MakerJs; (function (MakerJs) { var angle; (function (angle) { /** * Find out if two angles are equal. * * @param a First angle. * @param b Second angle. * @returns true if angles are the same, false if they are not */ function areEqual(angle1, angle2) { var a1 = noRevolutions(MakerJs.round(angle1)); var a2 = noRevolutions(MakerJs.round(angle2)); return a1 == a2 || a1 + 360 == a2 || a1 - 360 == a2; } angle.areEqual = areEqual; /** * Ensures an angle is not greater than 360 * * @param angleInDegrees Angle in degrees. * @retiurns Same polar angle but not greater than 360 degrees. */ function noRevolutions(angleInDegrees) { var revolutions = Math.floor(angleInDegrees / 360); return angleInDegrees - (360 * revolutions); } angle.noRevolutions = noRevolutions; /** * Convert an angle from degrees to radians. * * @param angleInDegrees Angle in degrees. * @returns Angle in radians. */ function toRadians(angleInDegrees) { return noRevolutions(angleInDegrees) * Math.PI / 180.0; } angle.toRadians = toRadians; /** * Convert an angle from radians to degrees. * * @param angleInRadians Angle in radians. * @returns Angle in degrees. */ function toDegrees(angleInRadians) { return angleInRadians * 180.0 / Math.PI; } angle.toDegrees = toDegrees; /** * Get an arc's end angle, ensured to be greater than its start angle. * * @param arc An arc path object. * @returns End angle of arc. */ function ofArcEnd(arc) { //compensate for values past zero. This allows easy compute of total angle size. //for example 0 = 360 if (arc.endAngle < arc.startAngle) { return 360 + arc.endAngle; } return arc.endAngle; } angle.ofArcEnd = ofArcEnd; /** * Get the angle in the middle of an arc's start and end angles. * * @param arc An arc path object. * @param ratio Optional number between 0 and 1 specifying percentage between start and end angles. Default is .5 * @returns Middle angle of arc. */ function ofArcMiddle(arc, ratio) { if (ratio === void 0) { ratio = .5; } return arc.startAngle + MakerJs.measure.arcAngle(arc) * ratio; } angle.ofArcMiddle = ofArcMiddle; /** * Angle of a line path. * * @param line The line path to find the angle of. * @returns Angle of the line path, in degrees. */ function ofLineInDegrees(line) { return noRevolutions(toDegrees(ofPointInRadians(line.origin, line.end))); } angle.ofLineInDegrees = ofLineInDegrees; /** * Angle of a line through a point, in degrees. * * @param pointToFindAngle The point to find the angle. * @param origin Point of origin of the angle. * @returns Angle of the line throught the point, in degrees. */ function ofPointInDegrees(origin, pointToFindAngle) { return toDegrees(ofPointInRadians(origin, pointToFindAngle)); } angle.ofPointInDegrees = ofPointInDegrees; /** * Angle of a line through a point, in radians. * * @param pointToFindAngle The point to find the angle. * @param origin Point of origin of the angle. * @returns Angle of the line throught the point, in radians. */ function ofPointInRadians(origin, pointToFindAngle) { var d = MakerJs.point.subtract(pointToFindAngle, origin); var x = d[0]; var y = d[1]; return Math.atan2(-y, -x) + Math.PI; } angle.ofPointInRadians = ofPointInRadians; /** * Mirror an angle on either or both x and y axes. * * @param angleInDegrees The angle to mirror. * @param mirrorX Boolean to mirror on the x axis. * @param mirrorY Boolean to mirror on the y axis. * @returns Mirrored angle. */ function mirror(angleInDegrees, mirrorX, mirrorY) { if (mirrorY) { angleInDegrees = 360 - angleInDegrees; } if (mirrorX) { angleInDegrees = (angleInDegrees < 180 ? 180 : 540) - angleInDegrees; } return angleInDegrees; } angle.mirror = mirror; })(angle = MakerJs.angle || (MakerJs.angle = {})); })(MakerJs || (MakerJs = {})); var MakerJs; (function (MakerJs) { var point; (function (point) { /** * Add two points together and return the result as a new point object. * * @param a First point. * @param b Second point. * @param subtract Optional boolean to subtract instead of add. * @returns A new point object. */ function add(a, b, subtract) { var newPoint = clone(a); if (!b) return newPoint; for (var i = 2; i--;) { if (subtract) { newPoint[i] -= b[i]; } else { newPoint[i] += b[i]; } } return newPoint; } point.add = add; /** * Find out if two points are equal. * * @param a First point. * @param b Second point. * @returns true if points are the same, false if they are not */ function areEqual(a, b) { return a[0] == b[0] && a[1] == b[1]; } point.areEqual = areEqual; /** * Find out if two points are equal after rounding. * * @param a First point. * @param b Second point. * @returns true if points are the same, false if they are not */ function areEqualRounded(a, b, accuracy) { if (accuracy === void 0) { accuracy = .0000001; } return MakerJs.round(a[0], accuracy) == MakerJs.round(b[0], accuracy) && MakerJs.round(a[1], accuracy) == MakerJs.round(b[1], accuracy); } point.areEqualRounded = areEqualRounded; /** * Clone a point into a new point. * * @param pointToClone The point to clone. * @returns A new point with same values as the original. */ function clone(pointToClone) { if (!pointToClone) return point.zero(); return [pointToClone[0], pointToClone[1]]; } point.clone = clone; /** * From an array of points, find the closest point to a given reference point. * * @param referencePoint The reference point. * @param pointOptions Array of points to choose from. * @returns The first closest point from the pointOptions. */ function closest(referencePoint, pointOptions) { var smallest = { index: 0, distance: -1 }; for (var i = 0; i < pointOptions.length; i++) { var distance = MakerJs.measure.pointDistance(referencePoint, pointOptions[i]); if (smallest.distance == -1 || distance < smallest.distance) { smallest.distance = distance; smallest.index = i; } } return pointOptions[smallest.index]; } point.closest = closest; /** * Get a point from its polar coordinates. * * @param angleInRadians The angle of the polar coordinate, in radians. * @param radius The radius of the polar coordinate. * @returns A new point object. */ function fromPolar(angleInRadians, radius) { return [ radius * Math.cos(angleInRadians), radius * Math.sin(angleInRadians) ]; } point.fromPolar = fromPolar; /** * Get a point on a circle or arc path, at a given angle. * @param angleInDegrees The angle at which you want to find the point, in degrees. * @param circle A circle or arc. * @returns A new point object. */ function fromAngleOnCircle(angleInDegrees, circle) { return add(circle.origin, fromPolar(MakerJs.angle.toRadians(angleInDegrees), circle.radius)); } point.fromAngleOnCi