@lightningtv/core
Advanced tools
Comparing version 0.0.6 to 0.0.7
@@ -1,12 +0,12 @@ | ||
import type { ElementNode, SolidNode } from './elementNode.js'; | ||
import type { ElementNode, TextNode } from './elementNode.js'; | ||
/** | ||
* Children class | ||
*/ | ||
export default class Children extends Array<SolidNode> { | ||
export default class Children extends Array<ElementNode | TextNode> { | ||
_parent: ElementNode; | ||
constructor(node: ElementNode); | ||
get selected(): ElementNode | undefined; | ||
get firstChild(): SolidNode | undefined; | ||
insert(node: SolidNode, beforeNode?: SolidNode | null): void; | ||
remove(node: SolidNode): void; | ||
get firstChild(): ElementNode | TextNode | undefined; | ||
insert(node: ElementNode | TextNode, beforeNode?: ElementNode | TextNode | null): void; | ||
remove(node: ElementNode | TextNode): void; | ||
} |
@@ -6,26 +6,12 @@ import { createShader } from './lightningInit.js'; | ||
import type { RendererMain, INode, INodeAnimatableProps, INodeWritableProps, ShaderRef, Dimensions, AnimationSettings } from '@lightningjs/renderer'; | ||
import { type NodeTypes } from './nodeTypes.js'; | ||
export interface TextNode { | ||
export type Styles = { | ||
[key: string]: NodeStyles | TextStyles | undefined; | ||
} & (NodeStyles | TextStyles); | ||
export type TextNode = { | ||
id?: string; | ||
type: NodeTypes; | ||
text: string; | ||
parent: ElementNode | undefined; | ||
zIndex?: number; | ||
states?: States; | ||
x?: number; | ||
y?: number; | ||
width?: number; | ||
height?: number; | ||
marginLeft?: number; | ||
marginRight?: number; | ||
marginTop?: number; | ||
marginBottom?: number; | ||
flexItem?: boolean; | ||
flexOrder?: number; | ||
_queueDelete?: boolean; | ||
} | ||
export type SolidNode = ElementNode | TextNode; | ||
export type SolidStyles = { | ||
[key: string]: NodeStyles | TextStyles | undefined; | ||
} & (NodeStyles | TextStyles); | ||
type: 'text'; | ||
parent?: ElementNode; | ||
states?: NodeStates; | ||
}; | ||
export interface ElementNode extends Partial<Omit<INodeWritableProps, 'parent' | 'shader'>>, IntrinsicCommonProps { | ||
@@ -35,3 +21,3 @@ [key: string]: unknown; | ||
debug?: boolean; | ||
type: NodeTypes; | ||
type: 'element' | 'textNode'; | ||
lng: INode | IntrinsicNodeProps | IntrinsicTextProps; | ||
@@ -44,4 +30,3 @@ rendered: boolean; | ||
flexOrder?: number; | ||
flexBoundary?: 'contain' | 'fixed'; | ||
_queueDelete?: boolean; | ||
text?: string; | ||
forwardFocus?: number | ((this: ElementNode, elm: ElementNode) => boolean | void); | ||
@@ -51,3 +36,3 @@ _undoStyles?: string[]; | ||
_parent: ElementNode | undefined; | ||
_style?: SolidStyles; | ||
_style?: Styles; | ||
_states?: States; | ||
@@ -82,7 +67,7 @@ _events?: Array<[string, (target: ElementNode, event?: Event) => void]>; | ||
get onEvents(): Array<[string, (target: ElementNode, event?: any) => void]> | undefined; | ||
set style(values: SolidStyles | (SolidStyles | undefined)[]); | ||
get style(): SolidStyles; | ||
set style(values: Styles | (Styles | undefined)[]); | ||
get style(): Styles; | ||
get hasChildren(): boolean; | ||
getChildById(id: string): SolidNode | undefined; | ||
searchChildrenById(id: string): SolidNode | undefined; | ||
getChildById(id: string): ElementNode | TextNode | undefined; | ||
searchChildrenById(id: string): ElementNode | undefined; | ||
set states(states: NodeStates); | ||
@@ -89,0 +74,0 @@ get states(): States; |
@@ -1,3 +0,3 @@ | ||
import type { SolidNode, SolidStyles } from './elementNode.js'; | ||
export declare function log(msg: string, node: SolidNode, ...args: any[]): void; | ||
import type { ElementNode, Styles } from './elementNode.js'; | ||
export declare function log(msg: string, node: ElementNode, ...args: any[]): void; | ||
export declare const isFunc: (obj: unknown) => obj is CallableFunction; | ||
@@ -10,2 +10,2 @@ export declare function isObject(item: unknown): item is Record<string | number | symbol, unknown>; | ||
export declare function keyExists(obj: Record<string, unknown>, keys: (string | number | symbol)[]): boolean; | ||
export declare function flattenStyles(obj: SolidStyles | undefined | (SolidStyles | undefined)[], result?: SolidStyles): SolidStyles; | ||
export declare function flattenStyles(obj: Styles | undefined | (Styles | undefined)[], result?: Styles): Styles; |
{ | ||
"name": "@lightningtv/core", | ||
"version": "0.0.6", | ||
"version": "0.0.7", | ||
"description": "Lightning TV Core for Universal Renderers", | ||
@@ -39,3 +39,2 @@ "type": "module", | ||
"devDependencies": { | ||
"@lightningjs/renderer": "^0.9.1", | ||
"@typescript-eslint/eslint-plugin": "^6.21.0", | ||
@@ -51,2 +50,5 @@ "@typescript-eslint/parser": "^6.21.0", | ||
}, | ||
"peerDependencies": { | ||
"@lightningjs/renderer": "*" | ||
}, | ||
"lint-staged": { | ||
@@ -53,0 +55,0 @@ "*.ts": [ |
@@ -1,2 +0,2 @@ | ||
import type { ElementNode, SolidNode } from './elementNode.js'; | ||
import type { ElementNode, TextNode } from './elementNode.js'; | ||
@@ -6,3 +6,3 @@ /** | ||
*/ | ||
export default class Children extends Array<SolidNode> { | ||
export default class Children extends Array<ElementNode | TextNode> { | ||
_parent: ElementNode; | ||
@@ -24,3 +24,6 @@ | ||
insert(node: SolidNode, beforeNode?: SolidNode | null) { | ||
insert( | ||
node: ElementNode | TextNode, | ||
beforeNode?: ElementNode | TextNode | null, | ||
) { | ||
if (beforeNode) { | ||
@@ -36,3 +39,3 @@ const index = this.indexOf(beforeNode); | ||
remove(node: SolidNode) { | ||
remove(node: ElementNode | TextNode) { | ||
const nodeIndexToRemove = this.indexOf(node); | ||
@@ -39,0 +42,0 @@ if (nodeIndexToRemove >= 0) { |
@@ -132,27 +132,13 @@ import { renderer, createShader } from './lightningInit.js'; | ||
export interface TextNode { | ||
id?: string; | ||
type: NodeTypes; | ||
text: string; | ||
parent: ElementNode | undefined; | ||
zIndex?: number; | ||
states?: States; | ||
x?: number; | ||
y?: number; | ||
width?: number; | ||
height?: number; | ||
marginLeft?: number; | ||
marginRight?: number; | ||
marginTop?: number; | ||
marginBottom?: number; | ||
flexItem?: boolean; | ||
flexOrder?: number; | ||
_queueDelete?: boolean; | ||
} | ||
export type SolidNode = ElementNode | TextNode; | ||
export type SolidStyles = { | ||
export type Styles = { | ||
[key: string]: NodeStyles | TextStyles | undefined; | ||
} & (NodeStyles | TextStyles); | ||
export type TextNode = { | ||
id?: string; | ||
text: string; | ||
type: 'text'; | ||
parent?: ElementNode; | ||
states?: NodeStates; | ||
}; | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging | ||
@@ -165,3 +151,3 @@ export interface ElementNode | ||
debug?: boolean; | ||
type: NodeTypes; | ||
type: 'element' | 'textNode'; | ||
lng: INode | IntrinsicNodeProps | IntrinsicTextProps; | ||
@@ -174,4 +160,3 @@ rendered: boolean; | ||
flexOrder?: number; | ||
flexBoundary?: 'contain' | 'fixed'; // default is undefined - contained for flex calculated size | ||
_queueDelete?: boolean; | ||
text?: string; | ||
forwardFocus?: | ||
@@ -184,3 +169,3 @@ | number | ||
_parent: ElementNode | undefined; | ||
_style?: SolidStyles; | ||
_style?: Styles; | ||
_states?: States; | ||
@@ -367,3 +352,3 @@ _events?: Array<[string, (target: ElementNode, event?: Event) => void]>; | ||
set style(values: SolidStyles | (SolidStyles | undefined)[]) { | ||
set style(values: Styles | (Styles | undefined)[]) { | ||
if (isArray(values)) { | ||
@@ -377,4 +362,4 @@ this._style = flattenStyles(values); | ||
// be careful of 0 values | ||
if (this[key as keyof SolidStyles] === undefined) { | ||
this[key as keyof SolidStyles] = this._style[key as keyof SolidStyles]; | ||
if (this[key as keyof Styles] === undefined) { | ||
this[key as keyof Styles] = this._style[key as keyof Styles]; | ||
} | ||
@@ -384,3 +369,3 @@ } | ||
get style(): SolidStyles { | ||
get style(): Styles { | ||
return this._style!; | ||
@@ -397,6 +382,6 @@ } | ||
searchChildrenById(id: string): SolidNode | undefined { | ||
searchChildrenById(id: string): ElementNode | undefined { | ||
// traverse all the childrens children | ||
for (let i = 0; i < this.children.length; i++) { | ||
const child = this.children[i]; | ||
const child = this.children[i] as ElementNode; | ||
if (child instanceof ElementNode) { | ||
@@ -403,0 +388,0 @@ if (child.id === id) { |
import { assertTruthy } from '@lightningjs/renderer/utils'; | ||
import { type ElementNode, type SolidNode } from './elementNode.js'; | ||
import { type ElementNode } from './elementNode.js'; | ||
import { NodeType } from './nodeTypes.js'; | ||
@@ -58,3 +58,3 @@ | ||
containerCrossSize && align | ||
? (c: SolidNode) => { | ||
? (c: ElementNode) => { | ||
if (align === 'flexStart') { | ||
@@ -68,3 +68,3 @@ c[crossProp] = 0; | ||
} | ||
: (c: SolidNode) => c; | ||
: (c: ElementNode) => c; | ||
@@ -71,0 +71,0 @@ if (justify === 'flexStart') { |
import { Config, isDev } from './config.js'; | ||
import type { SolidNode, SolidStyles } from './elementNode.js'; | ||
import type { ElementNode, Styles } from './elementNode.js'; | ||
@@ -8,3 +8,3 @@ function hasDebug(node: any) { | ||
export function log(msg: string, node: SolidNode, ...args: any[]) { | ||
export function log(msg: string, node: ElementNode, ...args: any[]) { | ||
if (isDev) { | ||
@@ -55,5 +55,5 @@ if (Config.debug || hasDebug(node) || hasDebug(args[0])) { | ||
export function flattenStyles( | ||
obj: SolidStyles | undefined | (SolidStyles | undefined)[], | ||
result: SolidStyles = {}, | ||
): SolidStyles { | ||
obj: Styles | undefined | (Styles | undefined)[], | ||
result: Styles = {}, | ||
): Styles { | ||
if (isArray(obj)) { | ||
@@ -68,3 +68,3 @@ obj.forEach((item) => { | ||
if (result[key] === undefined) { | ||
result[key as keyof SolidStyles] = obj[key as keyof SolidStyles]; | ||
result[key as keyof Styles] = obj[key as keyof Styles]; | ||
} | ||
@@ -71,0 +71,0 @@ } |
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
Sorry, the diff of this file is not supported yet
9
148259
1
2159