wip(core): Migrated to named exports only
This commit is contained in:
parent
4b12a7330c
commit
c09ae4aa69
23 changed files with 592 additions and 557 deletions
|
@ -1,4 +1,4 @@
|
|||
function Attributes() {
|
||||
export function Attributes() {
|
||||
this.list = {}
|
||||
}
|
||||
|
||||
|
@ -103,4 +103,3 @@ Attributes.prototype.clone = function () {
|
|||
return clone
|
||||
}
|
||||
|
||||
export default Attributes
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import Pattern from './pattern.mjs'
|
||||
import { Pattern } from './pattern.mjs'
|
||||
import { addPartConfig } from './utils.mjs'
|
||||
|
||||
|
||||
|
@ -6,7 +6,7 @@ import { addPartConfig } from './utils.mjs'
|
|||
* The Design constructor. Returns a Pattern constructor
|
||||
* So it's sort of a super-constructor
|
||||
*/
|
||||
export default function Design(config) {
|
||||
export function Design(config) {
|
||||
|
||||
// Merge config with defaults
|
||||
config = {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
export default function Hooks() {
|
||||
export function Hooks() {
|
||||
return {
|
||||
preDraft: [],
|
||||
postDraft: [],
|
||||
|
|
|
@ -1,42 +1,78 @@
|
|||
import Design from './design.mjs'
|
||||
import Pattern from './pattern.mjs'
|
||||
import Point from './point.mjs'
|
||||
import Path from './path.mjs'
|
||||
import Snippet from './snippet.mjs'
|
||||
import * as utils from './utils.mjs'
|
||||
import pkg from '../package.json' assert { type: 'json' }
|
||||
|
||||
const { version } = pkg
|
||||
|
||||
/*
|
||||
* Named exports will become the default in FreeSewing v3
|
||||
*/
|
||||
export {
|
||||
version,
|
||||
Design,
|
||||
Pattern,
|
||||
Point,
|
||||
Path,
|
||||
Snippet,
|
||||
utils,
|
||||
}
|
||||
|
||||
// This is a helper for configuration files
|
||||
export const pctBasedOn = utils.pctBasedOn
|
||||
|
||||
// This is a helper for manual layouts
|
||||
export const generatePartTransform = utils.generatePartTransform
|
||||
|
||||
/*
|
||||
* Default exports will be removed in FreeSewing v3
|
||||
*/
|
||||
export default {
|
||||
version,
|
||||
Design,
|
||||
Pattern,
|
||||
Point,
|
||||
Path,
|
||||
Snippet,
|
||||
utils,
|
||||
import { Attributes } from './attributes.mjs'
|
||||
import { Design } from './design.mjs'
|
||||
import { Pattern } from './pattern.mjs'
|
||||
import { Point } from './point.mjs'
|
||||
import { Path } from './path.mjs'
|
||||
import { Snippet } from './snippet.mjs'
|
||||
import {
|
||||
isCoord,
|
||||
capitalize,
|
||||
beamsIntersect,
|
||||
linesIntersect,
|
||||
pointOnBeam,
|
||||
pointOnLine,
|
||||
pointOnCurve,
|
||||
splitCurve,
|
||||
beamIntersectsX,
|
||||
beamIntersectsY,
|
||||
units,
|
||||
lineIntersectsCurve,
|
||||
curveIntersectsX,
|
||||
curveIntersectsY,
|
||||
curvesIntersect,
|
||||
circlesIntersect,
|
||||
beamIntersectsCircle,
|
||||
lineIntersectsCircle,
|
||||
curveEdge,
|
||||
stretchToScale,
|
||||
round,
|
||||
sampleStyle,
|
||||
deg2rad,
|
||||
rad2deg,
|
||||
pctBasedOn,
|
||||
Bezier,
|
||||
generatePartTransform,
|
||||
macroName,
|
||||
} from "./utils.mjs"
|
||||
import { version } from '../package.json' assert { type: 'json' }
|
||||
|
||||
// Named exports
|
||||
export {
|
||||
Attributes,
|
||||
Design,
|
||||
Pattern,
|
||||
Point,
|
||||
Path,
|
||||
Snippet,
|
||||
|
||||
Bezier,
|
||||
version,
|
||||
capitalize,
|
||||
beamsIntersect,
|
||||
linesIntersect,
|
||||
pointOnBeam,
|
||||
pointOnLine,
|
||||
pointOnCurve,
|
||||
splitCurve,
|
||||
beamIntersectsX,
|
||||
beamIntersectsY,
|
||||
units,
|
||||
lineIntersectsCurve,
|
||||
curveIntersectsX,
|
||||
curveIntersectsY,
|
||||
curvesIntersect,
|
||||
circlesIntersect,
|
||||
beamIntersectsCircle,
|
||||
lineIntersectsCircle,
|
||||
curveEdge,
|
||||
stretchToScale,
|
||||
round,
|
||||
sampleStyle,
|
||||
deg2rad,
|
||||
rad2deg,
|
||||
pctBasedOn,
|
||||
generatePartTransform,
|
||||
macroName,
|
||||
isCoord
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
function Option(config) {
|
||||
export function Option(config) {
|
||||
this.id = config.id
|
||||
this.config = config
|
||||
this.val = config.val
|
||||
|
@ -6,4 +6,3 @@ function Option(config) {
|
|||
return this
|
||||
}
|
||||
|
||||
export default Option
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
import { Attributes } from './attributes.mjs'
|
||||
import * as utils from './utils.mjs'
|
||||
import Point from './point.mjs'
|
||||
import Path from './path.mjs'
|
||||
import Snippet from './snippet.mjs'
|
||||
import Attributes from './attributes.mjs'
|
||||
import Hooks from './hooks.mjs'
|
||||
import { Point } from './point.mjs'
|
||||
import { Path } from './path.mjs'
|
||||
import { Snippet } from './snippet.mjs'
|
||||
import { Hooks } from './hooks.mjs'
|
||||
|
||||
function Part() {
|
||||
export function Part() {
|
||||
this.attributes = new Attributes()
|
||||
this.points = {}
|
||||
this.paths = {}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import Attributes from './attributes.mjs'
|
||||
import Point from './point.mjs'
|
||||
import { Attributes } from './attributes.mjs'
|
||||
import { Point } from './point.mjs'
|
||||
import { Bezier } from 'bezier-js'
|
||||
import {
|
||||
linesIntersect,
|
||||
|
@ -11,7 +11,7 @@ import {
|
|||
round,
|
||||
} from './utils.mjs'
|
||||
|
||||
function Path(debug = false) {
|
||||
export function Path(debug = false) {
|
||||
this.render = true
|
||||
this.topLeft = false
|
||||
this.bottomRight = false
|
||||
|
@ -913,4 +913,3 @@ Path.prototype.translate = function (x, y) {
|
|||
return clone
|
||||
}
|
||||
|
||||
export default Path
|
||||
|
|
|
@ -1,23 +1,28 @@
|
|||
import { Attributes } from './attributes.mjs'
|
||||
import pack from 'bin-pack'
|
||||
import {
|
||||
macroName,
|
||||
sampleStyle,
|
||||
capitalize,
|
||||
decoratePartDependency,
|
||||
addPartConfig,
|
||||
mergeDependencies,
|
||||
} from './utils.mjs'
|
||||
import Part from './part.mjs'
|
||||
import Point from './point.mjs'
|
||||
import Path from './path.mjs'
|
||||
import Snippet from './snippet.mjs'
|
||||
import Svg from './svg.mjs'
|
||||
import Store from './store.mjs'
|
||||
import Hooks from './hooks.mjs'
|
||||
import Attributes from './attributes.mjs'
|
||||
import { Part } from './part.mjs'
|
||||
import { Point } from './point.mjs'
|
||||
import { Path } from './path.mjs'
|
||||
import { Snippet } from './snippet.mjs'
|
||||
import { Svg } from './svg.mjs'
|
||||
import { Store } from './store.mjs'
|
||||
import { Hooks } from './hooks.mjs'
|
||||
import { version } from '../package.json' assert { type: 'json' }
|
||||
|
||||
export default function Pattern(config = { options: {} }) {
|
||||
/*
|
||||
* Makes sure an object passed to be attached as a part it not merely a method
|
||||
*/
|
||||
const decoratePartDependency = (obj, name) => (typeof obj === 'function') ? { draft: obj, name } : obj
|
||||
|
||||
|
||||
export function Pattern(config = { options: {} }) {
|
||||
|
||||
// Apply default settings
|
||||
this.settings = {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import Attributes from './attributes.mjs'
|
||||
import { Attributes } from './attributes.mjs'
|
||||
|
||||
function Point(x, y, debug = false) {
|
||||
export function Point(x, y, debug = false) {
|
||||
this.x = x
|
||||
this.y = y
|
||||
this.attributes = new Attributes()
|
||||
|
@ -249,4 +249,3 @@ Point.prototype.setCircle = function (radius = false, className=false) {
|
|||
return this
|
||||
}
|
||||
|
||||
export default Point
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import Attributes from './attributes.mjs'
|
||||
import { Attributes } from './attributes.mjs'
|
||||
|
||||
function Snippet(def, anchor, debug = false) {
|
||||
export function Snippet(def, anchor, debug = false) {
|
||||
this.def = def
|
||||
this.anchor = anchor
|
||||
this.attributes = new Attributes()
|
||||
|
@ -31,4 +31,3 @@ Snippet.prototype.clone = function () {
|
|||
return clone
|
||||
}
|
||||
|
||||
export default Snippet
|
||||
|
|
|
@ -1,21 +0,0 @@
|
|||
import Path from './path'
|
||||
|
||||
/** Splits a curve on a point */
|
||||
export default function splitCurve(start, cp1, cp2, end, split) {
|
||||
let [c1, c2] = new Path().move(start).curve(cp1, cp2, end).split(split)
|
||||
|
||||
return [
|
||||
{
|
||||
start: c1.ops[0].to,
|
||||
cp1: c1.ops[1].cp1,
|
||||
cp2: c1.ops[1].cp2,
|
||||
end: c1.ops[1].to,
|
||||
},
|
||||
{
|
||||
start: c2.ops[0].to,
|
||||
cp1: c2.ops[1].cp1,
|
||||
cp2: c2.ops[1].cp2,
|
||||
end: c2.ops[1].to,
|
||||
},
|
||||
]
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
function Store(raise) {
|
||||
export function Store(raise) {
|
||||
this.data = new Map()
|
||||
this.raise = raise
|
||||
}
|
||||
|
@ -20,4 +20,3 @@ Store.prototype.get = function (key) {
|
|||
return this.data.get(key)
|
||||
}
|
||||
|
||||
export default Store
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
import Attributes from './attributes.mjs'
|
||||
import { Attributes } from './attributes.mjs'
|
||||
import { round } from './utils.mjs'
|
||||
import pkg from '../package.json'
|
||||
import { version } from '../package.json'
|
||||
|
||||
function Svg(pattern) {
|
||||
export function Svg(pattern) {
|
||||
this.openGroups = []
|
||||
this.layout = {}
|
||||
this.freeId = 0
|
||||
|
@ -23,7 +23,7 @@ function Svg(pattern) {
|
|||
this.attributes.add('xmlns:xlink', 'http://www.w3.org/1999/xlink')
|
||||
this.attributes.add('xml:lang', pattern.settings.locale)
|
||||
this.attributes.add('xmlns:freesewing', 'http://freesewing.org/namespaces/freesewing')
|
||||
this.attributes.add('freesewing', pkg.version)
|
||||
this.attributes.add('freesewing', version)
|
||||
}
|
||||
|
||||
Svg.prototype.runHooks = function (hookName, data = false) {
|
||||
|
@ -312,4 +312,3 @@ Svg.prototype.getId = function () {
|
|||
return '' + this.freeId
|
||||
}
|
||||
|
||||
export default Svg
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { Bezier } from 'bezier-js'
|
||||
import Path from './path.mjs'
|
||||
import Point from './point.mjs'
|
||||
import { Path } from './path.mjs'
|
||||
import { Point } from './point.mjs'
|
||||
|
||||
export function capitalize(string) {
|
||||
return string.charAt(0).toUpperCase() + string.slice(1)
|
||||
|
@ -410,11 +410,6 @@ export const generatePartTransform = (x, y, rotate, flipX, flipY, part) => {
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Makes sure an object passed to be attached as a part it not merely a method
|
||||
*/
|
||||
export const decoratePartDependency = (obj, name) => (typeof obj === 'function') ? { draft: obj, name } : obj
|
||||
|
||||
// Add part-level options
|
||||
const addPartOptions = (part, config) => {
|
||||
if (part.options) {
|
||||
|
@ -432,6 +427,7 @@ const addPartOptions = (part, config) => {
|
|||
return config
|
||||
}
|
||||
|
||||
/*
|
||||
// Helper method for detecting a array with only strings
|
||||
const isStringArray = val => (Array.isArray(val) && val.length > 0)
|
||||
? val.reduce((prev=true, cur) => (prev && typeof cur === 'string'))
|
||||
|
@ -473,7 +469,7 @@ const mergeOptionGroups = (cur, add) => {
|
|||
|
||||
return cur
|
||||
}
|
||||
|
||||
*/
|
||||
// Add part-level optionGroups
|
||||
const addPartOptionGroups = (part, config) => {
|
||||
if (typeof config.optionGroups === 'undefined') {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue