@lightningtv/core
Advanced tools
Comparing version 0.0.12 to 0.0.13
@@ -1,12 +0,12 @@ | ||
import type { ElementNode, TextNode } from './elementNode.js'; | ||
import type { ElementNode, ElementText } from './elementNode.js'; | ||
/** | ||
* Children class | ||
*/ | ||
export default class Children extends Array<ElementNode | TextNode> { | ||
export default class Children extends Array<ElementNode | ElementText> { | ||
_parent: ElementNode; | ||
constructor(node: ElementNode); | ||
get selected(): ElementNode | undefined; | ||
get firstChild(): ElementNode | TextNode | undefined; | ||
insert(node: ElementNode | TextNode, beforeNode?: ElementNode | TextNode | null): void; | ||
remove(node: ElementNode | TextNode): void; | ||
get firstChild(): ElementNode | ElementText | undefined; | ||
insert(node: ElementNode | ElementText, beforeNode?: ElementNode | ElementText | null): void; | ||
remove(node: ElementNode | ElementText): void; | ||
} |
import { createShader } from './lightningInit.js'; | ||
import { type IntrinsicCommonProps, type IntrinsicNodeProps, type IntrinsicTextProps, type StyleEffects, type NodeStyles, type TextStyles, TextProps } from './intrinsicTypes.js'; | ||
import { type IntrinsicCommonProps, type IntrinsicNodeProps, type IntrinsicTextProps, type StyleEffects, type NodeStyles, type TextStyles } from './intrinsicTypes.js'; | ||
import Children from './children.js'; | ||
@@ -9,5 +9,10 @@ import States, { type NodeStates } from './states.js'; | ||
} & (NodeStyles | TextStyles); | ||
export interface TextNode extends TextProps { | ||
/** Node text, children of a ElementNode of type TextNode */ | ||
export interface ElementText { | ||
id?: string; | ||
type: 'text'; | ||
parent?: ElementNode; | ||
text: string; | ||
states?: States; | ||
_queueDelete?: boolean; | ||
} | ||
@@ -65,3 +70,3 @@ export interface ElementNode extends Partial<Omit<INodeWritableProps, 'parent' | 'shader'>>, IntrinsicCommonProps { | ||
get hasChildren(): boolean; | ||
getChildById(id: string): ElementNode | TextNode | undefined; | ||
getChildById(id: string): ElementNode | ElementText | undefined; | ||
searchChildrenById(id: string): ElementNode | undefined; | ||
@@ -68,0 +73,0 @@ set states(states: NodeStates); |
@@ -5,3 +5,3 @@ import { renderer, createShader } from './lightningInit.js'; | ||
import calculateFlex from './flex.js'; | ||
import { log, isArray, isNumber, isFunc, keyExists, flattenStyles, isINode, } from './utils.js'; | ||
import { log, isArray, isNumber, isFunc, keyExists, flattenStyles, isINode, isElementNode, } from './utils.js'; | ||
import { Config } from './config.js'; | ||
@@ -186,3 +186,3 @@ import { assertTruthy } from '@lightningjs/renderer/utils'; | ||
const child = this.children[focusedIndex]; | ||
child instanceof ElementNode && child.setFocus(); | ||
isElementNode(child) && child.setFocus(); | ||
return; | ||
@@ -255,3 +255,3 @@ } | ||
const child = this.children[i]; | ||
if (child instanceof ElementNode) { | ||
if (isElementNode(child)) { | ||
if (child.id === id) { | ||
@@ -311,3 +311,5 @@ return child; | ||
const states = this.states.slice(); | ||
this.children.forEach((c) => (c.states = states)); | ||
this.children.forEach((c) => { | ||
c.states = states; | ||
}); | ||
} | ||
@@ -468,3 +470,3 @@ const states = this.states; | ||
assertTruthy(c, 'Child is undefined'); | ||
if (c instanceof ElementNode) { | ||
if (isElementNode(c)) { | ||
c.render(); | ||
@@ -471,0 +473,0 @@ } |
@@ -93,3 +93,2 @@ 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; | ||
@@ -96,0 +95,0 @@ children?: string | number | (string | number | undefined)[]; |
import { INode } from '@lightningjs/renderer'; | ||
import type { ElementNode, TextNode, Styles } from './elementNode.js'; | ||
export declare function log(msg: string, node: ElementNode | TextNode, ...args: any[]): void; | ||
import { ElementNode, Styles, ElementText } from './elementNode.js'; | ||
export declare function log(msg: string, node: ElementNode | ElementText, ...args: any[]): void; | ||
export declare const isFunc: (obj: unknown) => obj is CallableFunction; | ||
@@ -11,3 +11,4 @@ export declare function isObject(item: unknown): item is Record<string | number | symbol, unknown>; | ||
export declare function isINode(node: object): node is INode; | ||
export declare function isElementNode(node: unknown): node is ElementNode; | ||
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; |
import { Config, isDev } from './config.js'; | ||
import { ElementNode } from './elementNode.js'; | ||
function hasDebug(node) { | ||
@@ -29,4 +30,7 @@ return isObject(node) && node.debug; | ||
export function isINode(node) { | ||
return Boolean('destroy' in node); | ||
return 'destroy' in node && typeof node.destroy === 'function'; | ||
} | ||
export function isElementNode(node) { | ||
return node instanceof ElementNode; | ||
} | ||
export function keyExists(obj, keys) { | ||
@@ -33,0 +37,0 @@ for (const key of keys) { |
{ | ||
"name": "@lightningtv/core", | ||
"version": "0.0.12", | ||
"version": "0.0.13", | ||
"description": "Lightning TV Core for Universal Renderers", | ||
@@ -5,0 +5,0 @@ "type": "module", |
@@ -1,2 +0,2 @@ | ||
import type { ElementNode, TextNode } from './elementNode.js'; | ||
import type { ElementNode, ElementText } from './elementNode.js'; | ||
@@ -6,3 +6,3 @@ /** | ||
*/ | ||
export default class Children extends Array<ElementNode | TextNode> { | ||
export default class Children extends Array<ElementNode | ElementText> { | ||
_parent: ElementNode; | ||
@@ -25,4 +25,4 @@ | ||
insert( | ||
node: ElementNode | TextNode, | ||
beforeNode?: ElementNode | TextNode | null, | ||
node: ElementNode | ElementText, | ||
beforeNode?: ElementNode | ElementText | null, | ||
) { | ||
@@ -39,3 +39,3 @@ if (beforeNode) { | ||
remove(node: ElementNode | TextNode) { | ||
remove(node: ElementNode | ElementText) { | ||
const nodeIndexToRemove = this.indexOf(node); | ||
@@ -42,0 +42,0 @@ if (nodeIndexToRemove >= 0) { |
@@ -12,3 +12,2 @@ import { renderer, createShader } from './lightningInit.js'; | ||
type ShaderEffectDesc, | ||
TextProps, | ||
} from './intrinsicTypes.js'; | ||
@@ -26,2 +25,3 @@ import Children from './children.js'; | ||
isINode, | ||
isElementNode, | ||
} from './utils.js'; | ||
@@ -140,5 +140,10 @@ import { Config } from './config.js'; | ||
export interface TextNode extends TextProps { | ||
/** Node text, children of a ElementNode of type TextNode */ | ||
export interface ElementText { | ||
id?: string; | ||
type: 'text'; | ||
parent?: ElementNode; | ||
text: string; | ||
states?: States; | ||
_queueDelete?: boolean; | ||
} | ||
@@ -300,3 +305,3 @@ | ||
const child = this.children[focusedIndex]; | ||
child instanceof ElementNode && child.setFocus(); | ||
isElementNode(child) && child.setFocus(); | ||
return; | ||
@@ -384,3 +389,3 @@ } | ||
const child = this.children[i] as ElementNode; | ||
if (child instanceof ElementNode) { | ||
if (isElementNode(child)) { | ||
if (child.id === id) { | ||
@@ -450,3 +455,5 @@ return child; | ||
const states = this.states.slice() as States; | ||
this.children.forEach((c) => (c.states = states)); | ||
this.children.forEach((c) => { | ||
c.states = states; | ||
}); | ||
} | ||
@@ -642,3 +649,3 @@ | ||
assertTruthy(c, 'Child is undefined'); | ||
if (c instanceof ElementNode) { | ||
if (isElementNode(c)) { | ||
c.render(); | ||
@@ -645,0 +652,0 @@ } else if (c.text && c.type === NodeType.Text) { |
@@ -151,3 +151,2 @@ import { | ||
extends AddUndefined<IntrinsicNodeCommonProps & IntrinsicTextNodeStyleProps> { | ||
states?: NodeStates; | ||
style?: | ||
@@ -154,0 +153,0 @@ | IntrinsicTextNodeStyleProps |
import { INode } from '@lightningjs/renderer'; | ||
import { Config, isDev } from './config.js'; | ||
import type { ElementNode, TextNode, Styles } from './elementNode.js'; | ||
import { ElementNode, Styles, ElementText } from './elementNode.js'; | ||
@@ -9,3 +9,7 @@ function hasDebug(node: any) { | ||
export function log(msg: string, node: ElementNode | TextNode, ...args: any[]) { | ||
export function log( | ||
msg: string, | ||
node: ElementNode | ElementText, | ||
...args: any[] | ||
) { | ||
if (isDev) { | ||
@@ -44,5 +48,9 @@ if (Config.debug || hasDebug(node) || hasDebug(args[0])) { | ||
export function isINode(node: object): node is INode { | ||
return Boolean('destroy' in node); | ||
return 'destroy' in node && typeof node.destroy === 'function'; | ||
} | ||
export function isElementNode(node: unknown): node is ElementNode { | ||
return node instanceof ElementNode; | ||
} | ||
export function keyExists( | ||
@@ -49,0 +57,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
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
153761
2255