@lightningtv/core
Advanced tools
Comparing version 0.0.10 to 0.0.11
import { createShader } from './lightningInit.js'; | ||
import { type IntrinsicCommonProps, type IntrinsicNodeProps, type IntrinsicTextProps, type StyleEffects, type NodeStyles, type TextStyles } from './intrinsicTypes.js'; | ||
import { type IntrinsicCommonProps, type IntrinsicNodeProps, type IntrinsicTextProps, type StyleEffects, type NodeStyles, type TextStyles, TextProps } from './intrinsicTypes.js'; | ||
import Children from './children.js'; | ||
@@ -9,8 +9,4 @@ import States, { type NodeStates } from './states.js'; | ||
} & (NodeStyles | TextStyles); | ||
export interface TextNode { | ||
id?: string; | ||
text: string; | ||
export interface TextNode extends TextProps { | ||
type: 'text'; | ||
parent?: ElementNode; | ||
states?: NodeStates; | ||
} | ||
@@ -29,2 +25,3 @@ export interface ElementNode extends Partial<Omit<INodeWritableProps, 'parent' | 'shader'>>, IntrinsicCommonProps { | ||
flexOrder?: number; | ||
flexGrow?: number; | ||
text?: string; | ||
@@ -31,0 +28,0 @@ forwardFocus?: number | ((this: ElementNode, elm: ElementNode) => boolean | void); |
@@ -5,3 +5,3 @@ import { renderer, createShader } from './lightningInit.js'; | ||
import calculateFlex from './flex.js'; | ||
import { log, isArray, isNumber, isFunc, keyExists, flattenStyles, } from './utils.js'; | ||
import { log, isArray, isNumber, isFunc, keyExists, flattenStyles, isINode, } from './utils.js'; | ||
import { Config } from './config.js'; | ||
@@ -215,3 +215,3 @@ import { assertTruthy } from '@lightningjs/renderer/utils'; | ||
destroy() { | ||
if (this._queueDelete) { | ||
if (this._queueDelete && isINode(this.lng)) { | ||
this.lng.destroy(); | ||
@@ -466,3 +466,3 @@ } | ||
assertTruthy(c, 'Child is undefined'); | ||
if ('render' in c) { | ||
if (c instanceof ElementNode) { | ||
c.render(); | ||
@@ -469,0 +469,0 @@ } |
@@ -1,2 +0,1 @@ | ||
import { assertTruthy } from '@lightningjs/renderer/utils'; | ||
import { NodeType } from './nodeTypes.js'; | ||
@@ -6,2 +5,3 @@ export default function (node) { | ||
let hasOrder = false; | ||
let growSize = 0; | ||
for (let i = 0; i < node.children.length; i++) { | ||
@@ -24,2 +24,5 @@ const c = node.children[i]; | ||
} | ||
if (c.flexGrow !== undefined) { | ||
growSize += c.flexGrow; | ||
} | ||
children.push(c); | ||
@@ -44,2 +47,15 @@ } | ||
const align = node.alignItems; | ||
if (growSize) { | ||
const flexBasis = children.reduce((prev, c) => prev + | ||
(c.flexGrow ? 0 : c[dimension] || 0) + | ||
(c[marginOne] || 0) + | ||
(c[marginTwo] || 0), 0); | ||
const growFactor = (containerSize - flexBasis - gap * (numChildren - 1)) / growSize; | ||
for (let i = 0; i < children.length; i++) { | ||
const c = children[i]; | ||
if (c.flexGrow !== undefined && c.flexGrow > 0) { | ||
c[dimension] = c.flexGrow * growFactor; | ||
} | ||
} | ||
} | ||
let itemSize = 0; | ||
@@ -85,3 +101,2 @@ if (['center', 'spaceBetween', 'spaceEvenly'].includes(justify)) { | ||
const c = children[i]; | ||
assertTruthy(c); | ||
c[prop] = start - (c[dimension] || 0) - (c[marginTwo] || 0); | ||
@@ -88,0 +103,0 @@ start -= |
@@ -93,2 +93,3 @@ import { type AnimationSettings, type Dimensions, type FadeOutEffectProps, type GlitchEffectProps, type GrayscaleEffectProps, type INode, type INodeWritableProps, type ITextNodeWritableProps, type LinearGradientEffectProps, type NodeFailedPayload, type NodeLoadedPayload, type RadialGradientEffectProps, type RadialProgressEffectProps } from '@lightningjs/renderer'; | ||
export interface IntrinsicTextProps extends AddUndefined<IntrinsicNodeCommonProps & IntrinsicTextNodeStyleProps> { | ||
states?: NodeStates; | ||
style?: IntrinsicTextNodeStyleProps | (IntrinsicTextNodeStyleProps | undefined)[] | undefined; | ||
@@ -95,0 +96,0 @@ children?: string | number | (string | number | undefined)[]; |
@@ -0,1 +1,2 @@ | ||
import { INode } from '@lightningjs/renderer'; | ||
import type { ElementNode, TextNode, Styles } from './elementNode.js'; | ||
@@ -9,3 +10,4 @@ export declare function log(msg: string, node: ElementNode | TextNode, ...args: any[]): void; | ||
export declare function isInteger(item: unknown): item is number; | ||
export declare function isINode(node: object): node is INode; | ||
export declare function keyExists(obj: Record<string, unknown>, keys: (string | number | symbol)[]): boolean; | ||
export declare function flattenStyles(obj: Styles | undefined | (Styles | undefined)[], result?: Styles): Styles; |
@@ -28,2 +28,5 @@ import { Config, isDev } from './config.js'; | ||
} | ||
export function isINode(node) { | ||
return Boolean('destroy' in node); | ||
} | ||
export function keyExists(obj, keys) { | ||
@@ -30,0 +33,0 @@ for (const key of keys) { |
{ | ||
"name": "@lightningtv/core", | ||
"version": "0.0.10", | ||
"version": "0.0.11", | ||
"description": "Lightning TV Core for Universal Renderers", | ||
@@ -50,3 +50,3 @@ "type": "module", | ||
"peerDependencies": { | ||
"@lightningjs/renderer": "*" | ||
"@lightningjs/renderer": "^0.9.0" | ||
}, | ||
@@ -53,0 +53,0 @@ "lint-staged": { |
@@ -12,2 +12,3 @@ import { renderer, createShader } from './lightningInit.js'; | ||
type ShaderEffectDesc, | ||
TextProps, | ||
} from './intrinsicTypes.js'; | ||
@@ -24,2 +25,3 @@ import Children from './children.js'; | ||
flattenStyles, | ||
isINode, | ||
} from './utils.js'; | ||
@@ -39,3 +41,3 @@ import { Config } from './config.js'; | ||
import { assertTruthy } from '@lightningjs/renderer/utils'; | ||
import { NodeType, type NodeTypes } from './nodeTypes.js'; | ||
import { NodeType } from './nodeTypes.js'; | ||
@@ -139,9 +141,6 @@ const layoutQueue = new Set<ElementNode>(); | ||
export interface TextNode { | ||
id?: string; | ||
text: string; | ||
export interface TextNode extends TextProps { | ||
type: 'text'; | ||
parent?: ElementNode; | ||
states?: NodeStates; | ||
} | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging | ||
@@ -162,2 +161,3 @@ export interface ElementNode | ||
flexOrder?: number; | ||
flexGrow?: number; | ||
text?: string; | ||
@@ -336,4 +336,4 @@ forwardFocus?: | ||
destroy() { | ||
if (this._queueDelete) { | ||
(this.lng as INode).destroy(); | ||
if (this._queueDelete && isINode(this.lng)) { | ||
this.lng.destroy(); | ||
} | ||
@@ -641,3 +641,3 @@ } | ||
assertTruthy(c, 'Child is undefined'); | ||
if ('render' in c) { | ||
if (c instanceof ElementNode) { | ||
c.render(); | ||
@@ -669,6 +669,6 @@ } else if (c.text && c.type === NodeType.Text) { | ||
Object.defineProperty(ElementNode.prototype, key, { | ||
get() { | ||
get(): unknown { | ||
return this.lng[key]; | ||
}, | ||
set(v) { | ||
set(v: unknown) { | ||
this.lng[key] = v; | ||
@@ -675,0 +675,0 @@ }, |
@@ -1,2 +0,1 @@ | ||
import { assertTruthy } from '@lightningjs/renderer/utils'; | ||
import { type ElementNode } from './elementNode.js'; | ||
@@ -8,2 +7,3 @@ import { NodeType } from './nodeTypes.js'; | ||
let hasOrder = false; | ||
let growSize = 0; | ||
for (let i = 0; i < node.children.length; i++) { | ||
@@ -30,2 +30,6 @@ const c = node.children[i]!; | ||
if (c.flexGrow !== undefined) { | ||
growSize += c.flexGrow; | ||
} | ||
children.push(c); | ||
@@ -52,2 +56,22 @@ } | ||
const align = node.alignItems; | ||
if (growSize) { | ||
const flexBasis = children.reduce( | ||
(prev, c) => | ||
prev + | ||
(c.flexGrow ? 0 : c[dimension] || 0) + | ||
(c[marginOne] || 0) + | ||
(c[marginTwo] || 0), | ||
0, | ||
); | ||
const growFactor = | ||
(containerSize - flexBasis - gap * (numChildren - 1)) / growSize; | ||
for (let i = 0; i < children.length; i++) { | ||
const c = children[i]!; | ||
if (c.flexGrow !== undefined && c.flexGrow > 0) { | ||
c[dimension] = c.flexGrow * growFactor; | ||
} | ||
} | ||
} | ||
let itemSize = 0; | ||
@@ -96,4 +120,3 @@ if (['center', 'spaceBetween', 'spaceEvenly'].includes(justify)) { | ||
for (let i = numChildren - 1; i >= 0; i--) { | ||
const c = children[i]; | ||
assertTruthy(c); | ||
const c = children[i]!; | ||
c[prop] = start - (c[dimension] || 0) - (c[marginTwo] || 0); | ||
@@ -100,0 +123,0 @@ start -= |
@@ -151,2 +151,3 @@ import { | ||
extends AddUndefined<IntrinsicNodeCommonProps & IntrinsicTextNodeStyleProps> { | ||
states?: NodeStates; | ||
style?: | ||
@@ -153,0 +154,0 @@ | IntrinsicTextNodeStyleProps |
@@ -0,1 +1,2 @@ | ||
import { INode } from '@lightningjs/renderer'; | ||
import { Config, isDev } from './config.js'; | ||
@@ -41,2 +42,6 @@ import type { ElementNode, TextNode, Styles } from './elementNode.js'; | ||
export function isINode(node: object): node is INode { | ||
return Boolean('destroy' in node); | ||
} | ||
export function keyExists( | ||
@@ -43,0 +48,0 @@ obj: Record<string, unknown>, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
152911
2229