Browse Source

REFA: fefactored base classes/logic of SideUnitDependendAttributes

renamed: SideUnitDependendAttribute -> DirectionUnitDependentAttribute
moved logic from Siding into DirectionUnitDependentAttribute
removed Siding class
updated inheritance to DirectionUnitDependentAttribute
master
chris 6 months ago
parent
commit
060918fe51
  1. 6
      src/sizeSide/dimensions.js
  2. 2
      src/sizeSide/shapes.js
  3. 60
      src/sizeSide/siding.js

6
src/sizeSide/dimensions.js

@ -1,13 +1,13 @@
const SidingRefDimensions = Object.freeze({ const SidingRefDimensions = Object.freeze({
WIDTH: (sideUnitDependentAttribute) => sideUnitDependentAttribute._fFirst, WIDTH: (DirectionUnitDependentAttribute) => DirectionUnitDependentAttribute._fFirst,
HEIGHT: (sideUnitDependentAttribute) => sideUnitDependentAttribute._fSecond HEIGHT: (DirectionUnitDependentAttribute) => DirectionUnitDependentAttribute._fSecond
}) })
/** /**
* Simple Dimensions container for the height and width in pixels. * Simple Dimensions container for the height and width in pixels.
*/ */
class Dimensions extends SideUnitDependentAttribute { class Dimensions extends DirectionUnitDependentAttribute {
constructor(defaultValue = 0, defaultUnit = SizeUnits.PIXEL) { constructor(defaultValue = 0, defaultUnit = SizeUnits.PIXEL) {
super(); super();
this._unit = defaultUnit; this._unit = defaultUnit;

2
src/sizeSide/shapes.js

@ -5,7 +5,7 @@ const SidingRefCorners = Object.freeze({
BOTTOMRIGHT: (sideUnitDependentAttribute) => sideUnitDependentAttribute._fForth BOTTOMRIGHT: (sideUnitDependentAttribute) => sideUnitDependentAttribute._fForth
}) })
class Shape extends Siding { class Shape extends DirectionUnitDependentAttribute {
constructor(defaultValue = 0, defaultUnit = SizeUnits.PIXEL) { constructor(defaultValue = 0, defaultUnit = SizeUnits.PIXEL) {
super(defaultValue, defaultUnit); super(defaultValue, defaultUnit);
} }

60
src/sizeSide/siding.js

@ -4,17 +4,25 @@ const SizeUnits = Object.freeze({
}) })
class SideUnitDependentAttribute { class DirectionUnitDependentAttribute {
_unit; _unit;
_fFirst; _fFirst;
_fSecond; _fSecond;
_fThird; _fThird;
_fForth; _fForth;
constructor(defaultValue = 0, defaultUnit = SizeUnits.PIXEL) {
this._unit = defaultUnit;
this._fFirst = defaultValue;
this._fSecond = defaultValue;
this._fThird = defaultValue;
this._fForth = defaultValue;
}
/** /**
* *
* @param {Units} unit The unit of the amount or style * @param {Units} unit The unit of the amount or style
* @returns {SideUnitDependentAttribute} this - Object * @returns {DirectionUnitDependentAttribute} this - Object
*/ */
setUnit(unit) { setUnit(unit) {
this._unit = unit; this._unit = unit;
@ -32,7 +40,7 @@ class SideUnitDependentAttribute {
* *
* @param {SidingRef} sidingRef * @param {SidingRef} sidingRef
* @param {*} value * @param {*} value
* @returns {SideUnitDependentAttribute} this * @returns {DirectionUnitDependentAttribute} this
*/ */
setBySidingRef(sidingRef, value) { setBySidingRef(sidingRef, value) {
sidingRef(this) = value; sidingRef(this) = value;
@ -59,24 +67,18 @@ const SidingRefSides = Object.freeze({
/** /**
* The Class holds values from each side/direction of an element. * Placeholder for overrides
* Used for margin/padding. * @returns {Object}
* Extended Logic is used for Dimensions, Shape, Border as well.
*/ */
class Siding extends SideUnitDependentAttribute { toModifications() {
constructor(defaultValue = 0, defaultUnit = SizeUnits.PIXEL) { return this.getOrderedValues()
super();
this._unit = defaultUnit;
this._fFirst = defaultValue;
this._fSecond = defaultValue;
this._fThird = defaultValue;
this._fForth = defaultValue;
} }
/** /**
* sets the amount-value for all sides. * sets the amount-value for all directions.
* @param {number} amount siding from all sides * @param {number} amount value to set for all directions
* @returns {Siding} this Siding Object * @returns {DirectionUnitDependentAttribute} this
*/ */
all(amount) { all(amount) {
this._fFirst = amount; this._fFirst = amount;
@ -86,6 +88,20 @@ class Siding extends SideUnitDependentAttribute {
return this; return this;
} }
}
class Sides extends DirectionUnitDependentAttribute {
/**
*
* @param {number|string} defaultValue
* @param {SizeUnits} defaultUnit
*/
constructor(defaultValue = 0, defaultUnit = SizeUnits.PIXEL) {
super(defaultValue, defaultUnit);
}
/** /**
* sets the amount-value for the left side. * sets the amount-value for the left side.
* @param {number} amount siding for left * @param {number} amount siding for left
@ -137,15 +153,6 @@ class Siding extends SideUnitDependentAttribute {
} }
class Sides extends Siding {
/**
*
* @param {number|string} defaultValue
* @param {*} defaultUnit
*/
constructor(defaultValue = 0, defaultUnit = SizeUnits.PIXEL) {
super(defaultValue, defaultUnit);
}
/** /**
* sets the amount-value for the horizontal sides (left and right). * sets the amount-value for the horizontal sides (left and right).
* @param {number} amount siding for left and right. * @param {number} amount siding for left and right.
@ -169,6 +176,7 @@ class Sides extends Siding {
} }
} }
class PaddingChain extends Sides { class PaddingChain extends Sides {
_modifier; _modifier;
constructor(modifier) { constructor(modifier) {

Loading…
Cancel
Save