From 208481a8672116dbddf2d4b6596df398f4814b0e Mon Sep 17 00:00:00 2001 From: chris Date: Tue, 22 Apr 2025 23:21:26 +0200 Subject: [PATCH] FIX,DOC: adjusted return types and fixed integer identification --- fileOrder.json | 2 +- src/context/generalHelpers.js | 4 +-- src/modifier.js | 46 +++++++++++++++++------------------ src/sizeSide/border.js | 14 +++++------ src/sizeSide/dimensions.js | 13 ++++++---- src/sizeSide/shapes.js | 20 +++++++-------- src/sizeSide/siding.js | 18 +++++++------- 7 files changed, 60 insertions(+), 57 deletions(-) diff --git a/fileOrder.json b/fileOrder.json index 92f7963..33891e6 100644 --- a/fileOrder.json +++ b/fileOrder.json @@ -5,7 +5,7 @@ "alignment.js", "arrangement.js" ], - "size_sidings": [ + "modifications": [ "modificationSubChainMixins.js", "siding.js", "padding.js", diff --git a/src/context/generalHelpers.js b/src/context/generalHelpers.js index 08b955e..754fa6b 100644 --- a/src/context/generalHelpers.js +++ b/src/context/generalHelpers.js @@ -66,8 +66,8 @@ class ObjectAccessObject { * @param {Function} fun * @returns {Object | Array} */ -function onSingleOrArray(singleOrArray, fun){ - if(singleOrArray instanceof Array){ +function onSingleOrArray(singleOrArray, fun) { + if (singleOrArray instanceof Array) { return singleOrArray.map(fun); } return fun(singleOrArray); diff --git a/src/modifier.js b/src/modifier.js index 38cdf47..f938536 100644 --- a/src/modifier.js +++ b/src/modifier.js @@ -34,7 +34,7 @@ class Modifier { /** * Sets the modifications for widht and height to 100%. - * @returns {Modifier} this modifier object + * @returns {Modifier | ChainableModifier} this modifier object */ fillMaxSize(widthFraction = 1, heightFraction = 1) { return this.fillMaxWidth(widthFraction) @@ -44,7 +44,7 @@ class Modifier { /** * Sets the modification for width to the given fraction of 1 (default 1 := 100%). * @param {number} fraction - * @returns {Modifier} this modifier object + * @returns {Modifier | ChainableModifier} this modifier object */ fillMaxWidth(fraction = 1) { this._modifications["width"] = (100 * fraction) + "%"; @@ -55,7 +55,7 @@ class Modifier { /** * Sets the modification for height to the given fraction of 1 (default 1 := 100%). * @param {number} fraction - * @returns {Modifier} this modifier object + * @returns {Modifier | ChainableModifier} this modifier object */ fillMaxHeight(fraction = 1) { this._modifications["height"] = (100 * fraction) + "%"; @@ -133,7 +133,7 @@ class Modifier { return this; } else { let modSub = new DimensionsChain(this); - if (modify instanceof Number && modify > 0) { + if (Number.isInteger(modify) && modify > 0) { return modSub.all(modify).ensureModifier(); } // case dimension is number but < 0 or dimensions == null or anything else @@ -146,7 +146,7 @@ class Modifier { * Currently the padding will always be set * to the most recent padding/padding. * @param {Padding | number | undefined} modify as in modifiers - * @returns {Modifier} this modifier object + * @returns {Modifier | PaddingChain} this modifier object */ padding(modify = null) { if (modify instanceof Sides && !(modify instanceof Padding)) { @@ -177,7 +177,7 @@ class Modifier { * it is recommended to use padding and to stick to that as often as possible. * Padding values take affect inside/within the element. * @param {Margin | number | undefined} modify - * @returns {Modifier} this modifier object + * @returns {Modifier | MarginChain} this modifier object */ margin(modify = null) { if (modify instanceof Sides && !(modify instanceof Margin)) { @@ -205,7 +205,7 @@ class Modifier { * If no color is given/specified the styling will be set to "inherit" * and use the color setting from (one of) the parent. * @param {Color} color - * @returns {Modifier} this modifier object + * @returns {Modifier | ChainableModifier} this modifier object */ background(color) { if (color) { @@ -225,7 +225,7 @@ class Modifier { * If no color is given/specified the styling will be set to "inherit" * and use the color setting from (one of) the parent. * @param {Color} color - * @returns {Modifier} this modifier object + * @returns {Modifier | ChainableModifier} this modifier object */ color(color) { this._modifications["color"] = ( @@ -246,7 +246,7 @@ class Modifier { * @todo finish second parameter "modifications" - logic * * @param modifier The "new" Modifier - * @returns {Modifier} The "old/current" Modifier, + * @returns {Modifier | ChainableModifier} The "old/current" Modifier, * extended with the modifications of the given Modifier. */ join(modifier, modifications = {}) { @@ -271,7 +271,7 @@ class Modifier { * * @param {string} key a css style rule * @param {string} value the corresponding value to the css style rule - * @returns {Modifier} this modifier object + * @returns {Modifier | ChainableModifier} this modifier object */ setStyleRule(key, value) { this._modifications[key] = value; @@ -281,7 +281,7 @@ class Modifier { /** * * @param {StylePropertyMap} rulemap - * @returns {Modifier} + * @returns {Modifier | ChainableModifier} */ addStyleRuleMap(rulemap) { for (const ruleKey of Object.keys(rulemap)) { @@ -293,7 +293,7 @@ class Modifier { /** * * @param {string} key - * @returns {Modifier} this modifier object + * @returns {Modifier | ChainableModifier} this modifier object */ removeStyleRule(key) { this._removeMods.push(key); @@ -341,7 +341,7 @@ class Modifier { return this; } else { let modSub = new BorderChain(this); - if (modify instanceof Number && modify > 0) { + if (Number.isInteger(modify) && modify > 0) { return modSub.width(modify).ensureModifier(); } return modSub; @@ -373,7 +373,7 @@ class Modifier { return this; } else { let modSub = new ShapeChain(this); - if (modify instanceof Number && modify > 0) { + if (Number.isInteger(modify) && modify > 0) { return modSub.all(modify).ensureModifier(); } return modSub; @@ -487,7 +487,7 @@ class ChainableModifier extends Modifier { * @returns {ChainableModifier | DimensionsChainedModifier} */ dimensions(modify = null) { - if (modify instanceof Dimensions || modify instanceof Number) { + if (modify instanceof Dimensions || Number.isInteger(modify)) { return super.dimensions(modify); } return new DimensionsChainedModifier(this); @@ -523,12 +523,12 @@ class ChainableModifier extends Modifier { * @inheritdoc * * @override - * @param {Shape | number | undefined} [Shape=null] shape + * @param {Shape | number | undefined} [modify=null] modify * @returns {ChainableModifier | ShapeChainedModifier} */ - clip(shape = null) { - if (shape instanceof Shape || shhaape instanceof Number) { - return super.clip(shape); + clip(modify = null) { + if (modify instanceof Shape || Number.isInteger(modify)) { + return super.clip(modify); } return new ShapeChainedModifier(this); } @@ -539,12 +539,12 @@ class ChainableModifier extends Modifier { * @inheritdoc * * @override - * @param {Border | number | undefined} [border=null] border + * @param {Border | number | undefined} [modify=null] modify * @returns {ChainableModifier | BorderChainedModifier} */ - border(border = null) { - if (border instanceof Border || border instanceof Number) { - return super.border(border); + border(modify = null) { + if (modify instanceof Border || Number.isInteger(modify)) { + return super.border(modify); } return new BorderChainedModifier(this); } diff --git a/src/sizeSide/border.js b/src/sizeSide/border.js index 195bc19..eabe9b7 100644 --- a/src/sizeSide/border.js +++ b/src/sizeSide/border.js @@ -79,7 +79,7 @@ class Border extends Sides { * * @param {string} key * @param {*} value - * @returns {this} + * @returns {typeof Border} */ setOnDirections(key, value) { let orderedAttributes = this.getOrderedAttributes() @@ -92,7 +92,7 @@ class Border extends Sides { /** * * @param {number} width - * @returns {this} + * @returns {typeof Border} */ width(width) { this._fFirst._width = width; @@ -105,7 +105,7 @@ class Border extends Sides { /** * * @param {*} color - * @returns {this} + * @returns {typeof Border} */ color(color) { this._fFirst._color = color; @@ -118,7 +118,7 @@ class Border extends Sides { /** * * @param {Shape} shape - * @returns {this} + * @returns {typeof Border} */ shape(shape) { this._shape = shape; @@ -128,7 +128,7 @@ class Border extends Sides { /** * Sets the border-style of all sides to the given. * @param {LineStyles} lineStyle style of the border - * @returns {this} + * @returns {typeof Border} */ setStyleAll(lineStyle) { this._fFirst._style = lineStyle; @@ -142,7 +142,7 @@ class Border extends Sides { * * @param {LineStyles} lineStyle * @param {*} sidingRefSide - * @returns {this} + * @returns {typeof Border} */ setLineStyle(lineStyle, sidingRefSide) { this._sidingStyles.setBySidingRef(sidingRefSide, lineStyle) @@ -152,7 +152,7 @@ class Border extends Sides { /** * * @param {Map