@lightningtv/core
Advanced tools
Comparing version 2.7.0-0 to 2.7.0-1
@@ -9,3 +9,2 @@ import type { RendererMainSettings } from '@lightningjs/renderer'; | ||
animationsEnabled: boolean; | ||
enableShaderCaching: boolean; | ||
fontSettings: Partial<TextProps>; | ||
@@ -12,0 +11,0 @@ rendererOptions?: Partial<RendererMainSettings>; |
@@ -17,3 +17,2 @@ function isDevEnv() { | ||
}, | ||
enableShaderCaching: false, | ||
setActiveElement: () => { }, | ||
@@ -20,0 +19,0 @@ focusStateKey: '$focus', |
@@ -1,2 +0,2 @@ | ||
import { createShader } from './lightningInit.js'; | ||
import { renderer } from './lightningInit.js'; | ||
import { type BorderRadius, type BorderStyle, type StyleEffects, type AnimationSettings, type ElementText, type Styles, type AnimationEvents, type AnimationEventHandler, AddColorString, TextNode, type OnEvent, NewOmit } from './intrinsicTypes.js'; | ||
@@ -128,3 +128,3 @@ import States, { type NodeStates } from './states.js'; | ||
get selectedNode(): ElementNode | undefined; | ||
set shader(shaderProps: Parameters<typeof createShader> | ReturnType<RendererMain['createShader']>); | ||
set shader(shaderProps: Parameters<typeof renderer.createShader> | ReturnType<RendererMain['createShader']>); | ||
_sendToLightningAnimatable(name: string, value: number): IAnimationController | undefined; | ||
@@ -131,0 +131,0 @@ animate(props: Partial<INodeAnimateProps>, animationSettings?: AnimationSettings): IAnimationController; |
@@ -1,2 +0,2 @@ | ||
import { renderer, createShader } from './lightningInit.js'; | ||
import { renderer } from './lightningInit.js'; | ||
import States from './states.js'; | ||
@@ -29,23 +29,16 @@ import calculateFlex from './flex.js'; | ||
} | ||
const shaderCache = new Map(); | ||
function convertEffectsToShader(node, styleEffects) { | ||
let cacheKey; | ||
if (Config.enableShaderCaching) { | ||
const roundedAlpha = Math.round((node.alpha || 0) * 10) / 10; // Round to the first decimal | ||
cacheKey = | ||
`${node.width},${node.height},${roundedAlpha}` + | ||
JSON.stringify(styleEffects); | ||
if (shaderCache.has(cacheKey)) { | ||
return shaderCache.get(cacheKey); | ||
} | ||
} | ||
const effects = []; | ||
for (const [type, props] of Object.entries(styleEffects)) { | ||
effects.push({ type, props }); | ||
for (const type in styleEffects) { | ||
// @ts-ignore getting the right type info is hard | ||
effects.push(renderer.createEffect(type, styleEffects[type], type)); | ||
} | ||
const shader = createShader('DynamicShader', { effects }); | ||
if (Config.enableShaderCaching && cacheKey) { | ||
shaderCache.set(cacheKey, shader); | ||
return renderer.createShader('DynamicShader', { effects }); | ||
} | ||
function updateShaderEffects(node, styleEffects) { | ||
const shader = node.lng.shader; | ||
for (const type in styleEffects) { | ||
// @ts-ignore getting the right type info is hard | ||
Object.assign(shader.props[type], styleEffects[type]); | ||
} | ||
return shader; | ||
} | ||
@@ -151,3 +144,7 @@ function borderAccessor(direction = '') { | ||
if (this.rendered) { | ||
this.shader = convertEffectsToShader(this, v); | ||
this.lng.shader = convertEffectsToShader(this, v); | ||
// if (this.lng.shader) { | ||
// updateShaderEffects(this, v); | ||
// } else { | ||
// } | ||
} | ||
@@ -207,3 +204,3 @@ } | ||
if (isArray(shaderProps)) { | ||
shProps = createShader(...shaderProps); | ||
shProps = renderer.createShader(...shaderProps); | ||
} | ||
@@ -210,0 +207,0 @@ this.lng.shader = shProps; |
@@ -107,21 +107,23 @@ import { Config } from './config.js'; | ||
const propagateKeyPress = (e, mappedEvent, isHold = false, isUp = false) => { | ||
let finalFocusElm = undefined; | ||
if (mappedEvent) { | ||
for (const elm of focusPath) { | ||
finalFocusElm = finalFocusElm || elm; | ||
const onKeyHandler = (isUp ? elm[`on${mappedEvent}Release`] : elm[`on${mappedEvent}`]); | ||
if (isFunction(onKeyHandler) && | ||
onKeyHandler.call(elm, e, elm, finalFocusElm) === true) { | ||
break; | ||
let finalFocusElm; | ||
for (const elm of focusPath) { | ||
if (!finalFocusElm) | ||
finalFocusElm = elm; | ||
if (mappedEvent) { | ||
const eventHandler = isUp | ||
? elm[`on${mappedEvent}Release`] | ||
: elm[`on${mappedEvent}`]; | ||
if (isFunction(eventHandler) && | ||
eventHandler.call(elm, e, elm, finalFocusElm) === true) { | ||
return true; | ||
} | ||
const fallbackFunction = isHold ? elm.onKeyHold : elm.onKeyPress; | ||
if (isFunction(fallbackFunction) && | ||
fallbackFunction.call(elm, e, mappedEvent, elm, finalFocusElm) === true) { | ||
break; | ||
} | ||
if (!isUp) { | ||
const fallbackHandler = isHold ? elm.onKeyHold : elm.onKeyPress; | ||
if (isFunction(fallbackHandler) && | ||
fallbackHandler.call(elm, e, mappedEvent, elm, finalFocusElm) === true) { | ||
return true; | ||
} | ||
} | ||
} | ||
else { | ||
console.log(`Unhandled ${e.type} for key event: ${e.key || e.keyCode}`); | ||
} | ||
return false; | ||
@@ -128,0 +130,0 @@ }; |
@@ -5,3 +5,2 @@ import type { RendererMainSettings, SdfTrFontFaceOptions, WebTrFontFaceOptions } from '@lightningjs/renderer'; | ||
export declare let renderer: RendererMain; | ||
export declare let createShader: RendererMain['createShader']; | ||
export declare const getRenderer: () => RendererMain; | ||
@@ -8,0 +7,0 @@ export declare function startLightningRenderer(options: RendererMainSettings, rootId?: string | HTMLElement): RendererMain; |
import { SdfTrFontFace, WebTrFontFace, RendererMain, } from '@lightningjs/renderer'; | ||
export let renderer; | ||
export let createShader; | ||
export const getRenderer = () => renderer; | ||
export function startLightningRenderer(options, rootId = 'app') { | ||
renderer = new RendererMain(options, rootId); | ||
createShader = renderer.createShader.bind(renderer); | ||
return renderer; | ||
@@ -9,0 +7,0 @@ } |
{ | ||
"name": "@lightningtv/core", | ||
"version": "2.7.0-0", | ||
"version": "2.7.0-1", | ||
"description": "Lightning TV Core for Universal Renderers", | ||
@@ -5,0 +5,0 @@ "type": "module", |
@@ -14,3 +14,2 @@ import type { RendererMainSettings } from '@lightningjs/renderer'; | ||
animationsEnabled: boolean; | ||
enableShaderCaching: boolean; | ||
fontSettings: Partial<TextProps>; | ||
@@ -39,5 +38,4 @@ rendererOptions?: Partial<RendererMainSettings>; | ||
}, | ||
enableShaderCaching: false, | ||
setActiveElement: () => {}, | ||
focusStateKey: '$focus', | ||
}; |
@@ -1,2 +0,2 @@ | ||
import { renderer, createShader } from './lightningInit.js'; | ||
import { renderer } from './lightningInit.js'; | ||
import { | ||
@@ -72,3 +72,2 @@ type BorderRadius, | ||
const shaderCache = new Map(); | ||
function convertEffectsToShader( | ||
@@ -78,26 +77,19 @@ node: ElementNode, | ||
): ShaderController<'DynamicShader'> { | ||
let cacheKey: string | undefined; | ||
if (Config.enableShaderCaching) { | ||
const roundedAlpha = Math.round((node.alpha || 0) * 10) / 10; // Round to the first decimal | ||
cacheKey = | ||
`${node.width},${node.height},${roundedAlpha}` + | ||
JSON.stringify(styleEffects); | ||
if (shaderCache.has(cacheKey)) { | ||
return shaderCache.get(cacheKey); | ||
} | ||
} | ||
const effects: EffectDescUnion[] = []; | ||
for (const [type, props] of Object.entries(styleEffects)) { | ||
effects.push({ type, props } as EffectDescUnion); | ||
for (const type in styleEffects) { | ||
// @ts-ignore getting the right type info is hard | ||
effects.push(renderer.createEffect(type, styleEffects[type], type)); | ||
} | ||
const shader = createShader('DynamicShader', { effects }); | ||
return renderer.createShader('DynamicShader', { effects }); | ||
} | ||
if (Config.enableShaderCaching && cacheKey) { | ||
shaderCache.set(cacheKey, shader); | ||
function updateShaderEffects( | ||
node: ElementNode, | ||
styleEffects: StyleEffects, | ||
): void { | ||
const shader = node.lng.shader; | ||
for (const type in styleEffects) { | ||
// @ts-ignore getting the right type info is hard | ||
Object.assign(shader.props[type], styleEffects[type]); | ||
} | ||
return shader; | ||
} | ||
@@ -337,3 +329,7 @@ | ||
if (this.rendered) { | ||
this.shader = convertEffectsToShader(this, v); | ||
this.lng.shader = convertEffectsToShader(this, v); | ||
// if (this.lng.shader) { | ||
// updateShaderEffects(this, v); | ||
// } else { | ||
// } | ||
} | ||
@@ -406,3 +402,3 @@ } | ||
shaderProps: | ||
| Parameters<typeof createShader> | ||
| Parameters<typeof renderer.createShader> | ||
| ReturnType<RendererMain['createShader']>, | ||
@@ -412,3 +408,3 @@ ) { | ||
if (isArray(shaderProps)) { | ||
shProps = createShader(...shaderProps); | ||
shProps = renderer.createShader(...shaderProps); | ||
} | ||
@@ -415,0 +411,0 @@ this.lng.shader = shProps; |
@@ -144,32 +144,33 @@ import { Config } from './config.js'; | ||
e: KeyboardEvent, | ||
mappedEvent: string | undefined, | ||
mappedEvent?: string, | ||
isHold: boolean = false, | ||
isUp: boolean = false, | ||
) => { | ||
let finalFocusElm: ElementNode | undefined = undefined; | ||
): boolean => { | ||
let finalFocusElm: ElementNode | undefined; | ||
if (mappedEvent) { | ||
for (const elm of focusPath) { | ||
finalFocusElm = finalFocusElm || elm; | ||
const onKeyHandler = ( | ||
isUp ? elm[`on${mappedEvent}Release`] : elm[`on${mappedEvent}`] | ||
) as unknown; | ||
for (const elm of focusPath) { | ||
if (!finalFocusElm) finalFocusElm = elm; | ||
if (mappedEvent) { | ||
const eventHandler = isUp | ||
? elm[`on${mappedEvent}Release`] | ||
: elm[`on${mappedEvent}`]; | ||
if ( | ||
isFunction(onKeyHandler) && | ||
onKeyHandler.call(elm, e, elm, finalFocusElm) === true | ||
isFunction(eventHandler) && | ||
eventHandler.call(elm, e, elm, finalFocusElm) === true | ||
) { | ||
break; | ||
return true; | ||
} | ||
} | ||
const fallbackFunction = isHold ? elm.onKeyHold : elm.onKeyPress; | ||
if (!isUp) { | ||
const fallbackHandler = isHold ? elm.onKeyHold : elm.onKeyPress; | ||
if ( | ||
isFunction(fallbackFunction) && | ||
fallbackFunction.call(elm, e, mappedEvent, elm, finalFocusElm) === true | ||
isFunction(fallbackHandler) && | ||
fallbackHandler.call(elm, e, mappedEvent, elm, finalFocusElm) === true | ||
) { | ||
break; | ||
return true; | ||
} | ||
} | ||
} else { | ||
console.log(`Unhandled ${e.type} for key event: ${e.key || e.keyCode}`); | ||
} | ||
@@ -176,0 +177,0 @@ |
@@ -14,3 +14,2 @@ import type { | ||
export let renderer: RendererMain; | ||
export let createShader: RendererMain['createShader']; | ||
@@ -24,3 +23,2 @@ export const getRenderer = () => renderer; | ||
renderer = new RendererMain(options, rootId); | ||
createShader = renderer.createShader.bind(renderer); | ||
return renderer; | ||
@@ -27,0 +25,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
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
233589
3643