@lightningjs/blits 2.4.0 → 2.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,256 +0,0 @@
1
- /*
2
- * Copyright 2023 Comcast Cable Communications Management, LLC
3
- * Licensed under the Apache License, Version 2.0 (the "License");
4
- * you may not use this file except in compliance with the License.
5
- * You may obtain a copy of the License at
6
- *
7
- * http://www.apache.org/licenses/LICENSE-2.0
8
- *
9
- * Unless required by applicable law or agreed to in writing, software
10
- * distributed under the License is distributed on an "AS IS" BASIS,
11
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- * See the License for the specific language governing permissions and
13
- * limitations under the License.
14
- *
15
- * SPDX-License-Identifier: Apache-2.0
16
- */
17
-
18
- import Component from '../component.js'
19
-
20
- import symbols from '../lib/symbols.js'
21
-
22
- export default () =>
23
- Component('Sprite', {
24
- /* eslint-disable no-unused-vars */
25
- code: {
26
- render: function anonymous(parent, component, context, components, effect, getRaw, Log) {
27
- const elms = []
28
- const validAttributes = [
29
- 'parent',
30
- 'rotation',
31
- 'w',
32
- 'h',
33
- 'x',
34
- 'y',
35
- 'z',
36
- 'zIndex',
37
- 'color',
38
- 'src',
39
- 'texture',
40
- 'fit',
41
- 'rtt',
42
- 'mount',
43
- 'pivot',
44
- 'scale',
45
- 'show',
46
- 'alpha',
47
- 'rounded',
48
- 'border',
49
- 'shadow',
50
- 'shader',
51
- 'clipping',
52
- 'overflow',
53
- 'font',
54
- 'size',
55
- 'maxwidth',
56
- 'maxheight',
57
- 'maxlines',
58
- 'textoverflow',
59
- 'letterspacing',
60
- 'lineheight',
61
- 'contain',
62
- 'align',
63
- 'content',
64
- 'placement',
65
- 'inspector-data',
66
- 'holder',
67
- ]
68
- const elementConfigs = []
69
- const forloops = []
70
- const props = []
71
- const created = []
72
- const effects = {}
73
- const skips = []
74
- let componentType
75
- let rootComponent = component
76
- let propData
77
- let slotComponent
78
- let inSlot = false
79
- let slotChildCounter = 0
80
- let cmps = []
81
- elementConfigs[0] = {}
82
- elementConfigs[0]['___wrapper'] = true
83
-
84
- elms[0] = this.element(
85
- { parent: parent || 'root' },
86
- inSlot === true ? slotComponent : component
87
- )
88
-
89
- elementConfigs[0]['w'] = parent.node.w * (100 / 100)
90
- elementConfigs[0]['h'] = parent.node.h * (100 / 100)
91
- elementConfigs[0]['texture'] = component.texture
92
- elementConfigs[0]['color'] = component.color
93
- elementConfigs[0]['rounded'] = component.rounded
94
- elementConfigs[0]['border'] = component.border
95
- elementConfigs[0]['shadow'] = component.shadow
96
- elms[0].populate(elementConfigs[0])
97
-
98
- if (inSlot === true) {
99
- slotChildCounter -= 1
100
- }
101
-
102
- return {
103
- elms,
104
- cleanup: () => {
105
- rootComponent = null
106
- propData = null
107
- slotComponent = null
108
- parent = null
109
- component = null
110
- cmps.length = 0
111
- elms.length = 0
112
- components.length = 0
113
- elementConfigs.length = 0
114
- forloops.length = 0
115
- props.length = 0
116
- skips.length = 0
117
- },
118
- skips,
119
- }
120
- },
121
- effects: [
122
- function anonymous(component, elms, context, components, rootComponent, skips, effect) {
123
- elms[0].set('texture', component.texture)
124
- },
125
- function anonymous(component, elms, context, components, rootComponent, skips, effect) {
126
- elms[0].set('color', component.color)
127
- },
128
- function anonymous(component, elms, context, components, rootComponent, skips, effect) {
129
- elms[0].set('rounded', component.rounded)
130
- },
131
- function anonymous(component, elms, context, components, rootComponent, skips, effect) {
132
- elms[0].set('border', component.border)
133
- },
134
- function anonymous(component, elms, context, components, rootComponent, skips, effect) {
135
- elms[0].set('shadow', component.shadow)
136
- },
137
- ],
138
- context: {},
139
- },
140
- props: {
141
- image: undefined,
142
- map: undefined,
143
- frame: undefined,
144
- color: undefined,
145
- rounded: undefined,
146
- border: undefined,
147
- shadow: undefined,
148
- '@loaded': undefined,
149
- '@error': undefined,
150
- },
151
- state() {
152
- return {
153
- spriteTexture: null,
154
- currentSrc: null,
155
- }
156
- },
157
-
158
- hooks: {
159
- ready() {
160
- const loaded = this['@loaded']
161
- if (loaded && typeof loaded === 'function') {
162
- const cb = (payload) => loaded({ w: payload?.w, h: payload?.h }, this[symbols.wrapper])
163
- this._loadedCb = cb
164
- if (this.spriteTexture !== undefined && this.spriteTexture !== null) {
165
- this.spriteTexture.on('loaded', cb)
166
- }
167
- }
168
- const error = this['@error']
169
- if (error && typeof error === 'function') {
170
- const cb = (payload) => error(payload, this[symbols.wrapper])
171
- this._failedCb = cb
172
- if (this.spriteTexture !== undefined && this.spriteTexture !== null) {
173
- this.spriteTexture.on('failed', cb)
174
- }
175
- }
176
- },
177
- destroy() {
178
- if (this.spriteTexture !== undefined && this.spriteTexture !== null) {
179
- if (this._loadedCb) this.spriteTexture.off('loaded', this._loadedCb)
180
- if (this._failedCb) this.spriteTexture.off('failed', this._failedCb)
181
- }
182
- },
183
- },
184
-
185
- computed: {
186
- texture() {
187
- // If no image - nothing to render
188
- if (this.image === undefined || this.image === null) {
189
- return null
190
- }
191
-
192
- // Get renderer
193
- const renderer = this[symbols.renderer]()
194
- if (renderer === null || renderer === undefined || renderer.createTexture === undefined) {
195
- return null
196
- }
197
-
198
- // Recreate texture only when image src changes
199
- if (
200
- this.spriteTexture === undefined ||
201
- this.spriteTexture === null ||
202
- this.currentSrc !== this.image
203
- ) {
204
- const prevTexture = this.spriteTexture
205
- if (prevTexture !== undefined && prevTexture !== null) {
206
- if (this._loadedCb) prevTexture.off('loaded', this._loadedCb)
207
- if (this._failedCb) prevTexture.off('failed', this._failedCb)
208
- }
209
- this.spriteTexture = renderer.createTexture('ImageTexture', {
210
- src: this.image,
211
- })
212
- this.currentSrc = this.image
213
- if (this._loadedCb) this.spriteTexture.on('loaded', this._loadedCb)
214
- if (this._failedCb) this.spriteTexture.on('failed', this._failedCb)
215
- }
216
-
217
- // Resolve frame data from sprite map
218
- let options = null
219
- if (
220
- this.map !== null &&
221
- this.map !== undefined &&
222
- this.frame !== null &&
223
- this.frame !== undefined
224
- ) {
225
- if (
226
- this.map.frames !== null &&
227
- this.map.frames !== undefined &&
228
- this.frame in this.map.frames
229
- ) {
230
- options = Object.assign({}, this.map.defaults || {}, this.map.frames[this.frame])
231
- } else if (this.frame in this.map) {
232
- options = this.map[this.frame]
233
- }
234
- }
235
-
236
- // If no map but frame is object (manual subtexture)
237
- if ((options === null || options === undefined) && typeof this.frame === 'object') {
238
- options = this.frame
239
- }
240
-
241
- // Create SubTexture only if frame data exists
242
- if (options !== null && options !== undefined) {
243
- return renderer.createTexture('SubTexture', {
244
- texture: this.spriteTexture,
245
- x: options.x,
246
- y: options.y,
247
- w: options.w,
248
- h: options.h,
249
- })
250
- }
251
-
252
- // Default fallback (single image)
253
- return this.spriteTexture
254
- },
255
- },
256
- })