diff --git a/package-lock.json b/package-lock.json index 145b8ccc..cee5ff36 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6,7 +6,7 @@ "packages": { "": { "name": "@lightningjs/blits", - "version": "1.19.0", + "version": "1.19.1", "license": "Apache-2.0", "dependencies": { "@lightningjs/msdf-generator": "^1.1.1", diff --git a/src/engines/L3/element.js b/src/engines/L3/element.js index b2d6fcfc..a140c7d3 100644 --- a/src/engines/L3/element.js +++ b/src/engines/L3/element.js @@ -171,6 +171,47 @@ const colorMap = { let textDefaults = null +const AvailableProps = [ + 'parent', + 'rotation', + 'w', + 'width', + 'h', + 'height', + 'x', + 'y', + 'z', + 'zIndex', + 'color', + 'style', + 'src', + 'texture', + 'fit', + 'rtt', + 'mount', + 'pivot', + 'scale', + 'show', + 'alpha', + 'shader', + 'effects', + 'clipping', + 'overflow', + 'font', + 'size', + 'wordwrap', + 'maxwidth', + 'maxheight', + 'contain', + 'maxlines', + 'textoverflow', + 'letterspacing', + 'lineheight', + 'align', + 'content', + 'placement', +] + const propsTransformer = { set parent(v) { this.props['parent'] = v === 'root' ? renderer.root : v.node @@ -426,6 +467,25 @@ const propsTransformer = { this.props['data'] = v } }, + set style(v) { + if (typeof v !== 'object') { + if (isObjectString(v) === true) { + v = parseToObject(v) + } else { + console.warn('Invalid style format: Expected an object or a valid object-like string.') + return + } + } + + // Apply valid style properties + Object.entries(v).forEach(([key, value]) => { + if (AvailableProps.includes(key)) { + this[key] = value + } else { + console.warn(`"${key}" is not a valid style property.`) + } + }) + }, } const Element = {