From 7551f09b8da8f07920a677a0d2446a0b6d2a604b Mon Sep 17 00:00:00 2001 From: Enoch Riese Date: Wed, 8 Mar 2023 12:12:13 -0600 Subject: [PATCH] use presets for common hide configurations --- designs/carlita/src/front.mjs | 6 +- designs/carlton/src/back.mjs | 6 +- designs/carlton/src/front.mjs | 6 +- designs/charlie/src/back.mjs | 6 +- designs/charlie/src/front.mjs | 7 +- designs/diana/src/front.mjs | 11 +- designs/diana/src/sleeve.mjs | 6 +- designs/huey/src/sleeve.mjs | 6 +- designs/hugo/src/back.mjs | 6 +- designs/hugo/src/front.mjs | 6 +- designs/hugo/src/sleeve.mjs | 6 +- designs/jaeger/src/backbase.mjs | 7 +- designs/jaeger/src/frontbase.mjs | 7 +- designs/jaeger/src/topsleeve.mjs | 6 +- designs/jaeger/src/undersleeve.mjs | 6 +- designs/noble/src/backpoints.mjs | 7 +- designs/noble/src/frontpoints.mjs | 7 +- designs/paco/src/back.mjs | 7 +- designs/paco/src/front.mjs | 6 +- designs/simon/src/back.mjs | 6 +- designs/simon/src/sleeve.mjs | 6 +- designs/sven/src/frontback.mjs | 11 +- designs/sven/src/sleeve.mjs | 6 +- designs/teagan/src/front.mjs | 6 +- designs/teagan/src/sleeve.mjs | 6 +- designs/wahid/src/back.mjs | 6 +- designs/wahid/src/front.mjs | 6 +- designs/yuri/src/back.mjs | 6 +- designs/yuri/src/front.mjs | 6 +- designs/yuri/src/sleeve.mjs | 6 +- packages/core/src/index.mjs | 3 + packages/core/src/pattern-config.mjs | 62 +++++--- .../core/tests/pattern-part-hiding.test.mjs | 137 ++++++++++++++++-- 33 files changed, 228 insertions(+), 170 deletions(-) diff --git a/designs/carlita/src/front.mjs b/designs/carlita/src/front.mjs index 87cc0ec6515..6b5fe78866f 100644 --- a/designs/carlita/src/front.mjs +++ b/designs/carlita/src/front.mjs @@ -1,5 +1,6 @@ import { pluginBust } from '@freesewing/plugin-bust' import { front as carltonFront } from '@freesewing/carlton' +import { hidePresets } from '@freesewing/core' function draftCarlitaFront({ paperless, @@ -501,10 +502,7 @@ function draftCarlitaFront({ export const front = { name: 'carlita.front', from: carltonFront, - hide: { - from: true, - inherited: true, - }, + hide: hidePresets.HIDE_TREE, measurements: ['highBust', 'bustSpan', 'hpsToBust'], plugins: [pluginBust], options: { diff --git a/designs/carlton/src/back.mjs b/designs/carlton/src/back.mjs index 21218fb341f..69605c62e53 100644 --- a/designs/carlton/src/back.mjs +++ b/designs/carlton/src/back.mjs @@ -1,5 +1,6 @@ import { back as bentBack } from '@freesewing/bent' import { calculateRatios } from './shared.mjs' +import { hidePresets } from '@freesewing/core' function draftCarltonBack({ paperless, @@ -230,10 +231,7 @@ function draftCarltonBack({ export const back = { name: 'carlton.back', from: bentBack, - hide: { - from: true, - inherited: true, - }, + hide: hidePresets.HIDE_TREE, measurements: ['chest', 'hpsToWaistBack'], options: { backPleat: 0.048, diff --git a/designs/carlton/src/front.mjs b/designs/carlton/src/front.mjs index 87c75b67fd3..9ca1b686cfa 100644 --- a/designs/carlton/src/front.mjs +++ b/designs/carlton/src/front.mjs @@ -1,5 +1,6 @@ import { front as bentFront } from '@freesewing/bent' import { calculateRatios } from './shared.mjs' +import { hidePresets } from '@freesewing/core' function draftCarltonFront({ paperless, @@ -477,10 +478,7 @@ function draftCarltonFront({ export const front = { name: 'carlton.front', from: bentFront, - hide: { - from: true, - inherited: true, - }, + hide: hidePresets.HIDE_TREE, measurements: ['waist', 'waistToFloor', 'waistToSeat'], options: { chestEase: { pct: 10, min: 5, max: 20, menu: 'fit' }, diff --git a/designs/charlie/src/back.mjs b/designs/charlie/src/back.mjs index 56ac0874779..5662c07f007 100644 --- a/designs/charlie/src/back.mjs +++ b/designs/charlie/src/back.mjs @@ -1,5 +1,6 @@ import { back as titanBack } from '@freesewing/titan' import { front } from './front.mjs' +import { hidePresets } from '@freesewing/core' function draftCharlieBack({ points, @@ -346,10 +347,7 @@ export const back = { name: 'charlie.back', from: titanBack, after: front, - hide: { - from: true, - inherited: true, - }, + hide: hidePresets.HIDE_TREE, options: { backPocketVerticalPlacement: { pct: 24, min: 18, max: 30, menu: 'pockets.backpockets' }, backPocketHorizontalPlacement: { pct: 55, min: 48, max: 62, menu: 'pockets.backpockets' }, diff --git a/designs/charlie/src/front.mjs b/designs/charlie/src/front.mjs index 0d8bc02a5ca..ed3e4c45b58 100644 --- a/designs/charlie/src/front.mjs +++ b/designs/charlie/src/front.mjs @@ -1,5 +1,5 @@ import { elastics } from '@freesewing/snapseries' -import { pctBasedOn } from '@freesewing/core' +import { pctBasedOn, hidePresets } from '@freesewing/core' import { front as titanFront } from '@freesewing/titan' function draftCharlieFront({ @@ -366,10 +366,7 @@ function draftCharlieFront({ export const front = { name: 'charlie.front', from: titanFront, - hide: { - from: true, - inherited: true, - }, + hide: hidePresets.HIDE_TREE, measurements: [ 'crossSeam', 'crossSeamFront', diff --git a/designs/diana/src/front.mjs b/designs/diana/src/front.mjs index 4c1371a7443..247755be565 100644 --- a/designs/diana/src/front.mjs +++ b/designs/diana/src/front.mjs @@ -1,5 +1,6 @@ import { front as frontBase } from '@freesewing/brian' import { back as backBase } from '@freesewing/brian' +import { hidePresets } from '@freesewing/core' export function draftDianaFrontOrBack({ measurements, @@ -165,10 +166,7 @@ export function draftDianaFrontOrBack({ export const front = { name: 'diana.front', from: frontBase, - hide: { - from: true, - inherited: true, - }, + hide: hidePresets.HIDE_TREE, measurements: [ 'biceps', 'chest', @@ -244,10 +242,7 @@ export const front = { export const back = { name: 'diana.back', from: backBase, - hide: { - from: true, - inherited: true, - }, + hide: hidePresets.HIDE_TREE, measurements: [ 'biceps', 'chest', diff --git a/designs/diana/src/sleeve.mjs b/designs/diana/src/sleeve.mjs index 8d1bb02a50a..905c2d4c2dc 100644 --- a/designs/diana/src/sleeve.mjs +++ b/designs/diana/src/sleeve.mjs @@ -1,6 +1,7 @@ import { sleeve as sleeveBase } from '@freesewing/brian' import { front } from './front.mjs' import { back } from './front.mjs' +import { hidePresets } from '@freesewing/core' function draftDianaSleeve({ sa, points, paths, Path, complete, paperless, macro, part }) { paths.seam = new Path() @@ -67,9 +68,6 @@ export const sleeve = { name: 'diana.sleeve', from: sleeveBase, after: [front, back], - hide: { - from: true, - inherited: true, - }, + hide: hidePresets.HIDE_TREE, draft: draftDianaSleeve, } diff --git a/designs/huey/src/sleeve.mjs b/designs/huey/src/sleeve.mjs index 3d47c6bf550..7f2e86a092b 100644 --- a/designs/huey/src/sleeve.mjs +++ b/designs/huey/src/sleeve.mjs @@ -1,5 +1,6 @@ import { sleeve as brianSleeve } from '@freesewing/brian' import { back } from './back.mjs' +import { hidePresets } from '@freesewing/core' function draftHueySleeve({ Point, @@ -94,8 +95,5 @@ export const sleeve = { from: brianSleeve, after: back, draft: draftHueySleeve, - hide: { - from: true, - inherited: true, - }, + hide: hidePresets.HIDE_TREE, } diff --git a/designs/hugo/src/back.mjs b/designs/hugo/src/back.mjs index 628fb384ab2..a520f865299 100644 --- a/designs/hugo/src/back.mjs +++ b/designs/hugo/src/back.mjs @@ -1,5 +1,6 @@ import { back as brianBack } from '@freesewing/brian' import { front } from './front.mjs' +import { hidePresets } from '@freesewing/core' function hugoBack({ store, @@ -116,10 +117,7 @@ function hugoBack({ export const back = { name: 'hugo.back', from: brianBack, - hide: { - from: true, - inherited: true, - }, + hide: hidePresets.HIDE_TREE, measurements: ['hips'], after: front, draft: hugoBack, diff --git a/designs/hugo/src/front.mjs b/designs/hugo/src/front.mjs index 8d203091e5b..9c3f99cb7d0 100644 --- a/designs/hugo/src/front.mjs +++ b/designs/hugo/src/front.mjs @@ -1,4 +1,5 @@ import { front as brianFront } from '@freesewing/brian' +import { hidePresets } from '@freesewing/core' import { collarEase, armholeDepthFactor, @@ -189,10 +190,7 @@ function hugoFront({ export const front = { name: 'hugo.front', from: brianFront, - hide: { - from: true, - inherited: true, - }, + hide: hidePresets.HIDE_TREE, measurements: ['hips', 'waistToHips'], options: { collarEase, diff --git a/designs/hugo/src/sleeve.mjs b/designs/hugo/src/sleeve.mjs index d840343d277..d0374451231 100644 --- a/designs/hugo/src/sleeve.mjs +++ b/designs/hugo/src/sleeve.mjs @@ -2,6 +2,7 @@ import { sleeve as brianSleeve } from '@freesewing/brian' import { front } from './front.mjs' import { back } from './back.mjs' import { cuffEase, sleeveLengthBonus, ribbingHeight } from './options.mjs' +import { hidePresets } from '@freesewing/core' function hugoSleeve({ utils, @@ -223,10 +224,7 @@ function hugoSleeve({ export const sleeve = { name: 'hugo.sleeve', from: brianSleeve, - hide: { - from: true, - inherited: true, - }, + hide: hidePresets.HIDE_TREE, after: [front, back], options: { cuffEase, sleeveLengthBonus, ribbingHeight }, draft: hugoSleeve, diff --git a/designs/jaeger/src/backbase.mjs b/designs/jaeger/src/backbase.mjs index fb5853d87c0..b3a5cec982a 100644 --- a/designs/jaeger/src/backbase.mjs +++ b/designs/jaeger/src/backbase.mjs @@ -1,5 +1,6 @@ import { calculateRatios, backSideBoundary } from './shared.mjs' import { back as bentBack } from '@freesewing/bent' +import { hidePresets } from '@freesewing/core' import { centerBackDart, hipsEase, @@ -91,11 +92,7 @@ export const backBase = { name: 'jaeger.backBase', measurements: ['hips', 'waist'], from: bentBack, - hide: { - self: true, - from: true, - inherited: true, - }, + hide: hidePresets.HIDE_ALL, options: { centerBackDart, hipsEase, diff --git a/designs/jaeger/src/frontbase.mjs b/designs/jaeger/src/frontbase.mjs index a8e21658283..b2f965cda1e 100644 --- a/designs/jaeger/src/frontbase.mjs +++ b/designs/jaeger/src/frontbase.mjs @@ -1,5 +1,6 @@ import { backSideBoundary } from './shared.mjs' import { front as bentFront } from '@freesewing/bent' +import { hidePresets } from '@freesewing/core' import { hipsEase, waistEase, @@ -192,11 +193,7 @@ export const frontBase = { name: 'jaeger.frontBase', measurements: ['hips', 'waist'], from: bentFront, - hide: { - self: true, - from: true, - inherited: true, - }, + hide: hidePresets.HIDE_ALL, options: { hipsEase, waistEase, diff --git a/designs/jaeger/src/topsleeve.mjs b/designs/jaeger/src/topsleeve.mjs index 2f24a6cac4e..25ddf93a1b3 100644 --- a/designs/jaeger/src/topsleeve.mjs +++ b/designs/jaeger/src/topsleeve.mjs @@ -1,5 +1,6 @@ import { topSleeve as bentTopSleeve } from '@freesewing/bent' import { sleeveVentLength, sleeveVentWidth } from './options.mjs' +import { hidePresets } from '@freesewing/core' function jaegerTopSleeve({ paperless, @@ -219,10 +220,7 @@ function jaegerTopSleeve({ export const topSleeve = { name: 'jaeger.topSleeve', from: bentTopSleeve, - hide: { - from: true, - inherited: true, - }, + hide: hidePresets.HIDE_TREE, options: { sleeveVentLength, sleeveVentWidth }, draft: jaegerTopSleeve, } diff --git a/designs/jaeger/src/undersleeve.mjs b/designs/jaeger/src/undersleeve.mjs index ce39e94f18a..9873a8c3726 100644 --- a/designs/jaeger/src/undersleeve.mjs +++ b/designs/jaeger/src/undersleeve.mjs @@ -1,5 +1,6 @@ import { underSleeve as bentUnderSleeve } from '@freesewing/bent' import { sleeveVentLength, sleeveVentWidth } from './options.mjs' +import { hidePresets } from '@freesewing/core' function jaegerUnderSleeve({ paperless, @@ -204,9 +205,6 @@ export const underSleeve = { name: 'jaeger.underSleeve', from: bentUnderSleeve, options: { sleeveVentLength, sleeveVentWidth }, - hide: { - from: true, - inherited: true, - }, + hide: hidePresets.HIDE_TREE, draft: jaegerUnderSleeve, } diff --git a/designs/noble/src/backpoints.mjs b/designs/noble/src/backpoints.mjs index 427efb68055..e5d04c647d2 100644 --- a/designs/noble/src/backpoints.mjs +++ b/designs/noble/src/backpoints.mjs @@ -1,4 +1,5 @@ import { back as bellaBack } from '@freesewing/bella' +import { hidePresets } from '@freesewing/core' import * as options from './options.mjs' function nobleBackPoints({ points, Path, paths, options, snippets, log, part }) { @@ -83,11 +84,7 @@ function nobleBackPoints({ points, Path, paths, options, snippets, log, part }) export const backPoints = { name: 'noble.backPoints', from: bellaBack, - hide: { - self: true, - from: true, - inherited: true, - }, + hide: hidePresets.HIDE_ALL, options, draft: nobleBackPoints, } diff --git a/designs/noble/src/frontpoints.mjs b/designs/noble/src/frontpoints.mjs index b00bae0d58e..16a2bcd182c 100644 --- a/designs/noble/src/frontpoints.mjs +++ b/designs/noble/src/frontpoints.mjs @@ -1,4 +1,5 @@ import { frontSideDart as bellaFront } from '@freesewing/bella' +import { hidePresets } from '@freesewing/core' import * as options from './options.mjs' function nobleFrontPoints({ log, points, Path, paths, snippets, options, macro, part }) { @@ -318,11 +319,7 @@ function nobleFrontPoints({ log, points, Path, paths, snippets, options, macro, export const frontPoints = { name: 'noble.frontPoints', from: bellaFront, - hide: { - self: true, - from: true, - inherited: true, - }, + hide: hidePresets.HIDE_ALL, options, draft: nobleFrontPoints, } diff --git a/designs/paco/src/back.mjs b/designs/paco/src/back.mjs index bcdcaa47517..c0568c95306 100644 --- a/designs/paco/src/back.mjs +++ b/designs/paco/src/back.mjs @@ -1,5 +1,5 @@ import { back as titanBack } from '@freesewing/titan' -import { pctBasedOn } from '@freesewing/core' +import { pctBasedOn, hidePresets } from '@freesewing/core' import { elastics, smallSteps } from '@freesewing/snapseries' function pacoBack({ @@ -312,10 +312,7 @@ function pacoBack({ export const back = { name: 'paco.back', from: titanBack, - hide: { - from: true, - inherited: true, - }, + hide: hidePresets.HIDE_TREE, measurements: ['heel'], options: { // Constants diff --git a/designs/paco/src/front.mjs b/designs/paco/src/front.mjs index 0b385edbe87..ee366197c7e 100644 --- a/designs/paco/src/front.mjs +++ b/designs/paco/src/front.mjs @@ -1,5 +1,6 @@ import { front as titanFront } from '@freesewing/titan' import { back } from './back.mjs' +import { hidePresets } from '@freesewing/core' function pacoFront({ utils, @@ -327,10 +328,7 @@ function pacoFront({ export const front = { name: 'paco.front', from: titanFront, - hide: { - from: true, - inherited: true, - }, + hide: hidePresets.HIDE_TREE, after: back, draft: pacoFront, } diff --git a/designs/simon/src/back.mjs b/designs/simon/src/back.mjs index 79e0e501a4d..b785045e26e 100644 --- a/designs/simon/src/back.mjs +++ b/designs/simon/src/back.mjs @@ -1,6 +1,7 @@ import { calculateReduction } from './shared.mjs' import { flipPlugin } from '@freesewing/plugin-flip' import { back as brianBack } from '@freesewing/brian' +import { hidePresets } from '@freesewing/core' import { collarFactor, backDarts, @@ -408,10 +409,7 @@ export const back = { plugins: [flipPlugin], measurements: ['waist', 'hips'], from: brianBack, - hide: { - from: true, - inherited: true, - }, + hide: hidePresets.HIDE_TREE, options: { collarFactor, backDarts, diff --git a/designs/simon/src/sleeve.mjs b/designs/simon/src/sleeve.mjs index aa4943de3f2..283a81ccb08 100644 --- a/designs/simon/src/sleeve.mjs +++ b/designs/simon/src/sleeve.mjs @@ -1,5 +1,6 @@ import { front } from './front.mjs' import { sleeve as brianSleeve } from '@freesewing/brian' +import { hidePresets } from '@freesewing/core' import { cuffOverlap, cuffDrape, @@ -284,10 +285,7 @@ export const sleeve = { name: 'simon.sleeve', from: brianSleeve, after: front, - hide: { - from: true, - inherited: true, - }, + hide: hidePresets.HIDE_TREE, options: { cuffOverlap, cuffDrape, diff --git a/designs/sven/src/frontback.mjs b/designs/sven/src/frontback.mjs index 9f915351bcb..2335b36de01 100644 --- a/designs/sven/src/frontback.mjs +++ b/designs/sven/src/frontback.mjs @@ -1,4 +1,5 @@ import { front as brianFront, back as brianBack } from '@freesewing/brian' +import { hidePresets } from '@freesewing/core' function svenFrontBack({ store, @@ -128,10 +129,7 @@ export const front = { name: 'sven.front', from: brianFront, options, - hide: { - from: true, - inherited: true, - }, + hide: hidePresets.HIDE_TREE, measurements, draft: svenFrontBack, } @@ -140,10 +138,7 @@ export const back = { name: 'sven.back', from: brianBack, options, - hide: { - from: true, - inherited: true, - }, + hide: hidePresets.HIDE_TREE, measurements, draft: svenFrontBack, } diff --git a/designs/sven/src/sleeve.mjs b/designs/sven/src/sleeve.mjs index c264a19c208..fbc7236b3a2 100644 --- a/designs/sven/src/sleeve.mjs +++ b/designs/sven/src/sleeve.mjs @@ -1,5 +1,6 @@ import { sleeve as brianSleeve } from '@freesewing/brian' import { ribbing, front, back } from './frontback.mjs' +import { hidePresets } from '@freesewing/core' function svenSleeve({ store, sa, points, paths, Path, complete, paperless, macro, options, part }) { if (options.ribbing) { @@ -72,10 +73,7 @@ function svenSleeve({ store, sa, points, paths, Path, complete, paperless, macro export const sleeve = { name: 'sven.sleeve', from: brianSleeve, - hide: { - from: true, - inherited: true, - }, + hide: hidePresets.HIDE_TREE, after: [front, back], options: { ribbing, diff --git a/designs/teagan/src/front.mjs b/designs/teagan/src/front.mjs index e3dc80eaebe..3fba97e2935 100644 --- a/designs/teagan/src/front.mjs +++ b/designs/teagan/src/front.mjs @@ -1,4 +1,5 @@ import { base } from '@freesewing/brian' +import { hidePresets } from '@freesewing/core' function teaganFront({ utils, @@ -166,10 +167,7 @@ export const front = { name: 'teagan.front', from: base, measurements: ['hips', 'waist'], - hide: { - from: true, - inherited: true, - }, + hide: hidePresets.HIDE_TREE, options: { bicepsEase: 0.05, shoulderEase: 0, diff --git a/designs/teagan/src/sleeve.mjs b/designs/teagan/src/sleeve.mjs index eeabf68faae..bcc085ac54b 100644 --- a/designs/teagan/src/sleeve.mjs +++ b/designs/teagan/src/sleeve.mjs @@ -1,4 +1,5 @@ import { sleevecap } from '@freesewing/brian' +import { hidePresets } from '@freesewing/core' function teaganSleeve({ sa, @@ -96,10 +97,7 @@ function teaganSleeve({ export const sleeve = { name: 'teagan.sleeve', from: sleevecap, - hide: { - from: true, - inherited: true, - }, + hide: hidePresets.HIDE_TREE, options: { sleeveEase: { pct: 15, min: 5, max: 35, menu: 'style' }, }, diff --git a/designs/wahid/src/back.mjs b/designs/wahid/src/back.mjs index 96d8f88ec52..e21fc229710 100644 --- a/designs/wahid/src/back.mjs +++ b/designs/wahid/src/back.mjs @@ -1,6 +1,7 @@ import { constructMainDart, shapeSideSeam, dartPath } from './shared.mjs' import { back as brianBack } from '@freesewing/brian' import { backInset, shoulderInset, neckInset, centerBackDart, backScyeDart } from './options.mjs' +import { hidePresets } from '@freesewing/core' function wahidBack({ points, @@ -227,10 +228,7 @@ function wahidBack({ export const back = { name: 'wahid.back', from: brianBack, - hide: { - from: true, - inherited: true, - }, + hide: hidePresets.HIDE_TREE, measurements: ['hips', 'waist'], options: { backInset, diff --git a/designs/wahid/src/front.mjs b/designs/wahid/src/front.mjs index 8f6264fe3dc..82421cf6b7a 100644 --- a/designs/wahid/src/front.mjs +++ b/designs/wahid/src/front.mjs @@ -1,5 +1,6 @@ import { constructMainDart, shapeSideSeam, dartPath } from './shared.mjs' import { front as brianFront } from '@freesewing/brian' +import { hidePresets } from '@freesewing/core' import { frontOverlap, necklineDrop, @@ -493,10 +494,7 @@ function wahidFront({ export const front = { name: 'wahid.front', from: brianFront, - hide: { - from: true, - inherited: true, - }, + hide: hidePresets.HIDE_TREE, measurements: ['hips', 'waist'], options: { frontOverlap, diff --git a/designs/yuri/src/back.mjs b/designs/yuri/src/back.mjs index 8705b69a01b..fcee879e339 100644 --- a/designs/yuri/src/back.mjs +++ b/designs/yuri/src/back.mjs @@ -1,5 +1,6 @@ import { back as brianBack } from '@freesewing/brian' import { sharedDimensions } from './shared.mjs' +import { hidePresets } from '@freesewing/core' function yuriBack({ store, @@ -109,10 +110,7 @@ export const back = { sleeveLengthBonus: { pct: 1, min: 0, max: 10 }, }, }, - hide: { - from: true, - inherited: true, - }, + hide: hidePresets.HIDE_TREE, options: { hipsEase: { pct: 0, min: 0, max: 10 }, }, diff --git a/designs/yuri/src/front.mjs b/designs/yuri/src/front.mjs index bbb3dff3059..5ae24f17ef0 100644 --- a/designs/yuri/src/front.mjs +++ b/designs/yuri/src/front.mjs @@ -1,5 +1,6 @@ import { front as brianFront } from '@freesewing/brian' import { sharedDimensions } from './shared.mjs' +import { hidePresets } from '@freesewing/core' function yuriFront({ store, @@ -118,10 +119,7 @@ export const front = { sleeveLengthBonus: { pct: 1, min: 0, max: 10 }, }, }, - hide: { - from: true, - inherited: true, - }, + hide: hidePresets.HIDE_TREE, options: { hipsEase: { pct: 0, min: 0, max: 10 }, }, diff --git a/designs/yuri/src/sleeve.mjs b/designs/yuri/src/sleeve.mjs index 75abf2043bd..e24f8723f88 100644 --- a/designs/yuri/src/sleeve.mjs +++ b/designs/yuri/src/sleeve.mjs @@ -1,4 +1,5 @@ import { sleeve as brianSleeve } from '@freesewing/brian' +import { hidePresets } from '@freesewing/core' function yuriSleeve({ Point, Path, points, paths, complete, sa, paperless, macro, part }) { // Clear paths from Brian, but keep sleevecap @@ -69,9 +70,6 @@ function yuriSleeve({ Point, Path, points, paths, complete, sa, paperless, macro export const sleeve = { name: 'yuri.sleeve', from: brianSleeve, - hide: { - from: true, - inherited: true, - }, + hide: hidePresets.HIDE_TREE, draft: yuriSleeve, } diff --git a/packages/core/src/index.mjs b/packages/core/src/index.mjs index 0d4316b4651..98224d8e5ea 100644 --- a/packages/core/src/index.mjs +++ b/packages/core/src/index.mjs @@ -7,6 +7,7 @@ import { Point } from './point.mjs' import { Path } from './path.mjs' import { Snippet } from './snippet.mjs' import { Store } from './store.mjs' +import { hidePresets } from './pattern-config.mjs' import { beamIntersectsCircle, beamIntersectsX, @@ -47,6 +48,8 @@ export { Store, version, Bezier, + //consts + hidePresets, // Utils beamIntersectsCircle, beamIntersectsX, diff --git a/packages/core/src/pattern-config.mjs b/packages/core/src/pattern-config.mjs index 2af181ce3aa..8b87c0450d8 100644 --- a/packages/core/src/pattern-config.mjs +++ b/packages/core/src/pattern-config.mjs @@ -1,5 +1,18 @@ import { __addNonEnumProp, capitalize } from './utils.mjs' +export const hidePresets = { + HIDE_ALL: { + self: true, + from: true, + after: true, + inherited: true, + }, + HIDE_TREE: { + from: true, + inherited: true, + }, +} + /** * Get the name of the given plugin config * @@ -328,34 +341,35 @@ PatternConfig.prototype.__addPartPlugins = function (part) { const depTypes = ['from', 'after'] const exceptionTypes = ['never', 'always'] PatternConfig.prototype.__resolvePartHiding = function (part) { - if (part.hide) { - // get the part's option priority - const partDistance = this.__mutated.partDistance?.[part.name] - const neverDistance = this.__hiding.never[part.name] || Infinity - const alwaysDistance = this.__hiding.always[part.name] || Infinity + let hide = part.hide + if (typeof hide === 'string') hide = hidePresets[hide] + if (!hide) return - if (part.hide.self && (neverDistance > partDistance || alwaysDistance <= neverDistance)) - this.partHide[part.name] = true + // get the part's option priority + const partDistance = this.__mutated.partDistance?.[part.name] + const neverDistance = this.__hiding.never[part.name] || Infinity + const alwaysDistance = this.__hiding.always[part.name] || Infinity - exceptionTypes.forEach((e, i) => { - if (part.hide[e]) { - part.hide[e].forEach((p) => { - const otherDistance = this.__hiding[exceptionTypes[Math.abs(i - 1)]][p] || Infinity + if (hide.self && (neverDistance > partDistance || alwaysDistance <= neverDistance)) + this.partHide[part.name] = true - if (otherDistance > partDistance) { - const thisDistance = this.__hiding[e][p] || Infinity - this.__hiding[e][p] = Math.min(thisDistance, partDistance) - this.partHide[p] = i == 1 - } - }) - } - }) + exceptionTypes.forEach((e, i) => { + if (hide[e]) { + hide[e].forEach((p) => { + const otherDistance = this.__hiding[exceptionTypes[Math.abs(i - 1)]][p] || Infinity - Object.keys(this.__hiding).forEach((k) => { - if (!exceptionTypes.includes(k) && this.__hiding[k][part.name] === undefined) - this.__hiding[k][part.name] = part.hide[k] - }) - } + if (otherDistance > partDistance) { + const thisDistance = this.__hiding[e][p] || Infinity + this.__hiding[e][p] = Math.min(thisDistance, partDistance) + this.partHide[p] = i == 1 + } + }) + } + }) + + depTypes.concat('inherited').forEach((k) => { + if (this.__hiding[k][part.name] === undefined) this.__hiding[k][part.name] = hide[k] + }) } /** * Recursively register part dependencies diff --git a/packages/core/tests/pattern-part-hiding.test.mjs b/packages/core/tests/pattern-part-hiding.test.mjs index ce5c5e9d277..9590f0d62b1 100644 --- a/packages/core/tests/pattern-part-hiding.test.mjs +++ b/packages/core/tests/pattern-part-hiding.test.mjs @@ -1,5 +1,5 @@ import chai from 'chai' -import { Design } from '../src/index.mjs' +import { Design, hidePresets } from '../src/index.mjs' const expect = chai.expect function hidePartMatcher(partName) { @@ -14,7 +14,25 @@ function hidePartMatcher(partName) { `expected part ${partName} to NOT be hidden, but it is hidden` ) } + +function hidePartsMatcher(...partNames) { + const hiddens = partNames.map((n) => { + if (!this._obj.config.parts[n]) { + throw new chai.AssertionError(`expected part \`${n}\` to exist in pattern`) + this.fail() + } + return this._obj.__isPartHidden(n) + }) + + this.assert( + hiddens.every((v) => v === true), + `expected parts [${partNames}] to be hidden, but hide check returns [${hiddens}]`, + `expected parts [${partNames}] to NOT be hidden, but hide check returns [${hiddens}]` + ) +} + chai.Assertion.addMethod('hidePart', hidePartMatcher) +chai.Assertion.addMethod('hideParts', hidePartsMatcher) const blankDraft = ({ part }) => part const blankPart = (name, config = {}) => ({ @@ -49,8 +67,7 @@ describe('Hiding parts', () => { }) it("Should NOT hide the part's dependencies", () => { - expect(pattern).not.to.hidePart('fromPart') - expect(pattern).not.to.hidePart('afterPart') + expect(pattern).not.to.hidePart('fromPart', 'afterPart') }) describe('Inherited Parts', () => { @@ -75,8 +92,7 @@ describe('Hiding parts', () => { pattern.__init() it('Should NOT hide inherited `from` dependencies', () => { - expect(pattern).not.to.hidePart('fromPart') - expect(pattern).not.to.hidePart('mainPart') + expect(pattern).not.to.hideParts('fromPart', 'mainPart') }) it('Should NOT hide inherited `after` dependencies', () => { @@ -247,13 +263,11 @@ describe('Hiding parts', () => { }) it('Should hide the `after` dependencies of `from` dependencies', () => { - expect(pattern).to.hidePart('afterPart') - expect(pattern).to.hidePart('parentAfter') + expect(pattern).to.hideParts('afterPart', 'parentAfter') }) it('Should hide the `from` dependencies of `from` dependencies', () => { - expect(pattern).to.hidePart('fromPart') - expect(pattern).to.hidePart('grandParent') + expect(pattern).to.hideParts('fromPart', 'grandParent') }) }) @@ -342,6 +356,107 @@ describe('Hiding parts', () => { }) }) + describe('HIDE_ALL', () => { + const grandParent = blankPart('grandParent') + const parent = blankPart('parent', { + from: grandParent, + }) + + it('Should behave like `{self: true, after: true, from: true, inherited: true}`', () => { + const main1 = blankPart('main1', { + from: parent, + after: afterPart, + hide: hidePresets.HIDE_ALL, + }) + + const Test = new Design({ + name: 'test', + parts: [main1], + }) + const pattern = new Test() + pattern.__init() + + expect(pattern).to.hideParts('grandParent', 'parent', 'main1', 'afterPart') + }) + it('Should work when passed as a string', () => { + const main1 = blankPart('main1', { + from: parent, + after: afterPart, + hide: 'HIDE_ALL', + }) + + const Test = new Design({ + name: 'test', + parts: [main1], + }) + const pattern = new Test() + pattern.__init() + + expect(pattern).to.hideParts('grandParent', 'parent', 'main1', 'afterPart') + }) + }) + + describe('HIDE_TREE', () => { + const grandParent = blankPart('grandParent', { from: fromPart, after: afterPart }) + const parentAfter = blankPart('parentAfter') + const parent = blankPart('parent', { from: grandParent, after: parentAfter }) + const mainAfterFrom = blankPart('mainAfterFrom') + const mainAfterAfter = blankPart('mainAfterAfter') + const mainAfter = blankPart('mainAfter', { after: mainAfterAfter, from: mainAfterFrom }) + + it('Should behave like `{from: true, inherited: true}`', () => { + const mainPart = { + name: 'mainPart', + from: parent, + after: mainAfter, + hide: hidePresets.HIDE_TREE, + draft: blankDraft, + } + const Test = new Design({ + name: 'test', + parts: [mainPart], + }) + + const pattern = new Test() + pattern.__init() + + expect(pattern).to.hideParts( + 'grandParent', + 'fromPart', + 'afterPart', + 'parentAfter', + `mainAfterFrom`, + `parent` + ) + expect(pattern).to.not.hideParts('mainPart', 'mainAfter', 'mainAfterAfter') + }) + it('Should work when passed as a string', () => { + const mainPart = { + name: 'mainPart', + from: parent, + after: mainAfter, + hide: 'HIDE_TREE', + draft: blankDraft, + } + const Test = new Design({ + name: 'test', + parts: [mainPart], + }) + + const pattern = new Test() + pattern.__init() + + expect(pattern).to.hideParts( + 'grandParent', + 'fromPart', + 'afterPart', + 'parentAfter', + `mainAfterFrom`, + `parent` + ) + expect(pattern).to.not.hideParts('mainPart', 'mainAfter', 'mainAfterAfter') + }) + }) describe('With complex inheritance', () => { it('Should use the strictest hiding configuration given by toplevel parts', () => { const greatGrandParent = blankPart('greatGrandParent') @@ -363,9 +478,7 @@ describe('Hiding parts', () => { const pattern = new Test() pattern.__init() - expect(pattern).to.hidePart('parent') - expect(pattern).to.hidePart('grandParent') - expect(pattern).to.hidePart('greatGrandParent') + expect(pattern).to.hideParts('parent', 'grandParent', 'greatGrandParent') }) it('Should use inherited configurations that are not overridden', () => { const greatGrandParent = blankPart('greatGrandParent')