@lightningjs/solid
Advanced tools
Comparing version 0.7.4 to 0.7.5
@@ -398,6 +398,9 @@ import { createSignal, createEffect, mergeProps as mergeProps$1, createRoot, createRenderEffect, createMemo, createComponent as createComponent$1, untrack } from 'solid-js'; | ||
const dimension = direction === 'row' ? 'width' : 'height'; | ||
const crossDimension = direction === 'row' ? 'height' : 'width'; | ||
const marginOne = direction === 'row' ? 'marginLeft' : 'marginTop'; | ||
const marginTwo = direction === 'row' ? 'marginRight' : 'marginBottom'; | ||
const prop = direction === 'row' ? 'x' : 'y'; | ||
const crossProp = direction === 'row' ? 'y' : 'x'; | ||
const containerSize = node[dimension] || 0; | ||
const containerCrossSize = node[crossDimension] || 0; | ||
const itemSize = children.reduce((prev, c) => prev + (c[dimension] || 0), 0); | ||
@@ -407,2 +410,14 @@ const gap = node.gap || 0; | ||
const justify = node.justifyContent || 'flexStart'; | ||
const align = node.alignItems; | ||
// Only align children if container has a cross size | ||
const crossAlignChild = containerCrossSize && align ? c => { | ||
if (align === 'flexStart') { | ||
c[crossProp] = 0; | ||
} else if (align === 'center') { | ||
c[crossProp] = (containerCrossSize - (c[crossDimension] || 0)) / 2; | ||
} else if (align === 'flexEnd') { | ||
c[crossProp] = containerCrossSize - (c[crossDimension] || 0); | ||
} | ||
} : c => c; | ||
if (justify === 'flexStart') { | ||
@@ -413,2 +428,3 @@ let start = 0; | ||
start += (c[dimension] || 0) + gap + (c[marginOne] || 0) + (c[marginTwo] || 0); | ||
crossAlignChild(c); | ||
}); | ||
@@ -423,2 +439,3 @@ } | ||
start -= (c[dimension] || 0) + gap + (c[marginOne] || 0) + (c[marginTwo] || 0); | ||
crossAlignChild(c); | ||
} | ||
@@ -431,2 +448,3 @@ } | ||
start += (c[dimension] || 0) + gap; | ||
crossAlignChild(c); | ||
}); | ||
@@ -440,2 +458,3 @@ } | ||
start += (c[dimension] || 0) + toPad; | ||
crossAlignChild(c); | ||
}); | ||
@@ -449,2 +468,3 @@ } | ||
start += (c[dimension] || 0) + toPad; | ||
crossAlignChild(c); | ||
}); | ||
@@ -451,0 +471,0 @@ } |
@@ -23,6 +23,9 @@ /* | ||
const dimension = direction === 'row' ? 'width' : 'height'; | ||
const crossDimension = direction === 'row' ? 'height' : 'width'; | ||
const marginOne = direction === 'row' ? 'marginLeft' : 'marginTop'; | ||
const marginTwo = direction === 'row' ? 'marginRight' : 'marginBottom'; | ||
const prop = direction === 'row' ? 'x' : 'y'; | ||
const crossProp = direction === 'row' ? 'y' : 'x'; | ||
const containerSize = node[dimension] || 0; | ||
const containerCrossSize = node[crossDimension] || 0; | ||
const itemSize = children.reduce((prev, c) => prev + (c[dimension] || 0), 0); | ||
@@ -32,2 +35,17 @@ const gap = node.gap || 0; | ||
const justify = node.justifyContent || 'flexStart'; | ||
const align = node.alignItems; | ||
// Only align children if container has a cross size | ||
const crossAlignChild = containerCrossSize && align | ||
? (c) => { | ||
if (align === 'flexStart') { | ||
c[crossProp] = 0; | ||
} | ||
else if (align === 'center') { | ||
c[crossProp] = (containerCrossSize - (c[crossDimension] || 0)) / 2; | ||
} | ||
else if (align === 'flexEnd') { | ||
c[crossProp] = containerCrossSize - (c[crossDimension] || 0); | ||
} | ||
} | ||
: (c) => c; | ||
if (justify === 'flexStart') { | ||
@@ -39,2 +57,3 @@ let start = 0; | ||
(c[dimension] || 0) + gap + (c[marginOne] || 0) + (c[marginTwo] || 0); | ||
crossAlignChild(c); | ||
}); | ||
@@ -50,2 +69,3 @@ } | ||
(c[dimension] || 0) + gap + (c[marginOne] || 0) + (c[marginTwo] || 0); | ||
crossAlignChild(c); | ||
} | ||
@@ -58,2 +78,3 @@ } | ||
start += (c[dimension] || 0) + gap; | ||
crossAlignChild(c); | ||
}); | ||
@@ -67,2 +88,3 @@ } | ||
start += (c[dimension] || 0) + toPad; | ||
crossAlignChild(c); | ||
}); | ||
@@ -76,4 +98,5 @@ } | ||
start += (c[dimension] || 0) + toPad; | ||
crossAlignChild(c); | ||
}); | ||
} | ||
} |
@@ -14,2 +14,3 @@ import { type Dimensions, type INode, type INodeWritableProps, type ITextNodeWritableProps } from '@lightningjs/renderer'; | ||
justifyContent?: 'flexStart' | 'flexEnd' | 'center' | 'spaceBetween' | 'spaceEvenly'; | ||
alignItems?: 'flexStart' | 'flexEnd' | 'center'; | ||
marginLeft?: number; | ||
@@ -16,0 +17,0 @@ marginRight?: number; |
{ | ||
"name": "@lightningjs/solid", | ||
"version": "0.7.4", | ||
"version": "0.7.5", | ||
"description": "Lightning renderer for solid universal", | ||
@@ -5,0 +5,0 @@ "type": "module", |
@@ -18,3 +18,3 @@ /* | ||
import { assertTruthy } from '@lightningjs/renderer/utils'; | ||
import type { ElementNode } from './node/index.js'; | ||
import type { ElementNode, SolidNode } from './node/index.js'; | ||
@@ -26,6 +26,9 @@ export default function (node: ElementNode) { | ||
const dimension = direction === 'row' ? 'width' : 'height'; | ||
const crossDimension = direction === 'row' ? 'height' : 'width'; | ||
const marginOne = direction === 'row' ? 'marginLeft' : 'marginTop'; | ||
const marginTwo = direction === 'row' ? 'marginRight' : 'marginBottom'; | ||
const prop = direction === 'row' ? 'x' : 'y'; | ||
const crossProp = direction === 'row' ? 'y' : 'x'; | ||
const containerSize = node[dimension] || 0; | ||
const containerCrossSize = node[crossDimension] || 0; | ||
const itemSize = children.reduce((prev, c) => prev + (c[dimension] || 0), 0); | ||
@@ -35,3 +38,18 @@ const gap = node.gap || 0; | ||
const justify = node.justifyContent || 'flexStart'; | ||
const align = node.alignItems; | ||
// Only align children if container has a cross size | ||
const crossAlignChild = | ||
containerCrossSize && align | ||
? (c: SolidNode) => { | ||
if (align === 'flexStart') { | ||
c[crossProp] = 0; | ||
} else if (align === 'center') { | ||
c[crossProp] = (containerCrossSize - (c[crossDimension] || 0)) / 2; | ||
} else if (align === 'flexEnd') { | ||
c[crossProp] = containerCrossSize - (c[crossDimension] || 0); | ||
} | ||
} | ||
: (c: SolidNode) => c; | ||
if (justify === 'flexStart') { | ||
@@ -43,2 +61,3 @@ let start = 0; | ||
(c[dimension] || 0) + gap + (c[marginOne] || 0) + (c[marginTwo] || 0); | ||
crossAlignChild(c); | ||
}); | ||
@@ -54,2 +73,3 @@ } | ||
(c[dimension] || 0) + gap + (c[marginOne] || 0) + (c[marginTwo] || 0); | ||
crossAlignChild(c); | ||
} | ||
@@ -62,2 +82,3 @@ } | ||
start += (c[dimension] || 0) + gap; | ||
crossAlignChild(c); | ||
}); | ||
@@ -71,2 +92,3 @@ } | ||
start += (c[dimension] || 0) + toPad; | ||
crossAlignChild(c); | ||
}); | ||
@@ -80,4 +102,5 @@ } | ||
start += (c[dimension] || 0) + toPad; | ||
crossAlignChild(c); | ||
}); | ||
} | ||
} |
@@ -45,2 +45,3 @@ /* | ||
| 'spaceEvenly'; | ||
alignItems?: 'flexStart' | 'flexEnd' | 'center'; | ||
marginLeft?: number; | ||
@@ -47,0 +48,0 @@ marginRight?: number; |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
282511
4454