@lightningjs/blits 0.3.2 → 0.3.3
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.
- package/boilerplate/public/fonts/Lato-Regular.msdf.json +5383 -0
- package/boilerplate/public/fonts/Lato-Regular.msdf.png +0 -0
- package/boilerplate/public/fonts/OpenSans-Medium.ttf +0 -0
- package/boilerplate/public/fonts/Raleway-ExtraBold.msdf.json +10838 -0
- package/boilerplate/public/fonts/Raleway-ExtraBold.msdf.png +0 -0
- package/boilerplate/src/index.js +6 -0
- package/package.json +1 -1
- package/src/components/Text.js +10 -2
- package/src/element.js +15 -2
- package/src/fontLoader.js +17 -0
- package/src/launch.js +5 -3
- package/src/lib/codegenerator/generator.js +5 -0
- package/src/lib/templateparser/parser.js +1 -1
- package/foo.js +0 -22
|
Binary file
|
package/boilerplate/src/index.js
CHANGED
|
@@ -6,6 +6,12 @@ const settings = {
|
|
|
6
6
|
w: 1920,
|
|
7
7
|
h: 1080,
|
|
8
8
|
multithreaded: false,
|
|
9
|
+
debugLevel: 1,
|
|
10
|
+
fonts: [
|
|
11
|
+
{family: 'lato', type: 'msdf', png: '/fonts/Lato-Regular.msdf.png', json: '/fonts/Lato-Regular.msdf.json'},
|
|
12
|
+
{family: 'raleway', type: 'msdf', png: '/fonts/Raleway-ExtraBold.msdf.png', json: '/fonts/Raleway-ExtraBold.msdf.json'},
|
|
13
|
+
{family: 'opensans', type: 'web', file: '/fonts/OpenSans-Medium.ttf'}
|
|
14
|
+
],
|
|
9
15
|
}
|
|
10
16
|
|
|
11
17
|
Blits.Launch(App, 'app', settings)
|
package/package.json
CHANGED
package/src/components/Text.js
CHANGED
|
@@ -30,14 +30,17 @@ export default () =>
|
|
|
30
30
|
:weight="$weight"
|
|
31
31
|
letterSpacing="$letterspacing"
|
|
32
32
|
stretch="$stretch"
|
|
33
|
+
contain="$_contain"
|
|
33
34
|
:w="$w"
|
|
34
35
|
:textAlign="$align"
|
|
36
|
+
@loaded="$@loaded"
|
|
37
|
+
@error="$@error"
|
|
35
38
|
/>`,
|
|
36
39
|
props: [
|
|
37
40
|
'content',
|
|
38
41
|
{
|
|
39
42
|
key: 'font',
|
|
40
|
-
default: '
|
|
43
|
+
default: 'lato',
|
|
41
44
|
},
|
|
42
45
|
{
|
|
43
46
|
key: 'size',
|
|
@@ -51,11 +54,16 @@ export default () =>
|
|
|
51
54
|
'stretch',
|
|
52
55
|
'align',
|
|
53
56
|
'w',
|
|
57
|
+
'contain',
|
|
58
|
+
'@loaded',
|
|
59
|
+
'@error',
|
|
54
60
|
],
|
|
55
61
|
computed: {
|
|
56
62
|
text() {
|
|
57
63
|
return this.slotcontent || this.content || ''
|
|
58
64
|
},
|
|
65
|
+
_contain() {
|
|
66
|
+
return this.contain || (this.align ? 'width' : null)
|
|
67
|
+
},
|
|
59
68
|
},
|
|
60
|
-
hooks: {},
|
|
61
69
|
})
|
package/src/element.js
CHANGED
|
@@ -149,7 +149,7 @@ const Element = {
|
|
|
149
149
|
rotation: 0,
|
|
150
150
|
},
|
|
151
151
|
populate(data) {
|
|
152
|
-
|
|
152
|
+
const props = {
|
|
153
153
|
...this.defaults,
|
|
154
154
|
...this.config,
|
|
155
155
|
...data,
|
|
@@ -162,13 +162,26 @@ const Element = {
|
|
|
162
162
|
props[prop] = transformations.unpackTransition(props[prop])
|
|
163
163
|
transformations[prop](props, this.setProperties)
|
|
164
164
|
}
|
|
165
|
-
|
|
166
165
|
this.setProperties.push(prop)
|
|
167
166
|
})
|
|
168
167
|
|
|
169
168
|
transformations.textureColor(props, this.setProperties)
|
|
170
169
|
|
|
171
170
|
this.node = props.__textnode ? renderer.createTextNode(props) : renderer.createNode(props)
|
|
171
|
+
|
|
172
|
+
if (props['@loaded']) {
|
|
173
|
+
const event = props.__textnode ? 'textLoaded' : 'txLoaded'
|
|
174
|
+
this.node.once(event, (el, { width: w, height: h }) => {
|
|
175
|
+
props['@loaded']({ w, h }, this)
|
|
176
|
+
})
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
if (props['@error']) {
|
|
180
|
+
const event = props.__textnode ? 'textFailed' : 'txFailed'
|
|
181
|
+
this.node.once(event, (el, error) => {
|
|
182
|
+
props['@error'](error, this)
|
|
183
|
+
})
|
|
184
|
+
}
|
|
172
185
|
},
|
|
173
186
|
set(prop, value) {
|
|
174
187
|
if (isTransition(value) && this.setProperties.indexOf(prop) > -1) {
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { CoreExtension, WebTrFontFace, SdfTrFontFace } from '@lightningjs/renderer/core'
|
|
2
|
+
|
|
3
|
+
import Settings from './settings'
|
|
4
|
+
|
|
5
|
+
export default class FontLoader extends CoreExtension {
|
|
6
|
+
async run(stage) {
|
|
7
|
+
Settings.get('fonts', []).forEach((font) => {
|
|
8
|
+
if (font.type === 'sdf' || font.type === 'msdf') {
|
|
9
|
+
stage.fontManager.addFontFace(
|
|
10
|
+
new SdfTrFontFace(font.family, {}, font.type, stage, font.png, font.json)
|
|
11
|
+
)
|
|
12
|
+
} else if (font.type === 'web') {
|
|
13
|
+
new WebTrFontFace(font.family, {}, font.file)
|
|
14
|
+
}
|
|
15
|
+
})
|
|
16
|
+
}
|
|
17
|
+
}
|
package/src/launch.js
CHANGED
|
@@ -20,6 +20,8 @@ import { MainRenderDriver, RendererMain, ThreadXRenderDriver } from '@lightningj
|
|
|
20
20
|
import Settings from './settings.js'
|
|
21
21
|
import { initLog } from './lib/log.js'
|
|
22
22
|
|
|
23
|
+
import coreExtensionModule from './fontLoader.js?importChunkUrl'
|
|
24
|
+
|
|
23
25
|
export let renderer
|
|
24
26
|
|
|
25
27
|
export default (App, target, settings) => {
|
|
@@ -36,9 +38,9 @@ export default (App, target, settings) => {
|
|
|
36
38
|
|
|
37
39
|
renderer = new RendererMain(
|
|
38
40
|
{
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
coreExtensionModule:
|
|
41
|
+
appWidth: settings.w || 1920,
|
|
42
|
+
appHeight: settings.h || 1080,
|
|
43
|
+
coreExtensionModule: coreExtensionModule,
|
|
42
44
|
},
|
|
43
45
|
target,
|
|
44
46
|
driver
|
|
@@ -297,6 +297,11 @@ const cast = (val = '', key = false, component = 'component.') => {
|
|
|
297
297
|
else if (val.toLowerCase() === 'false') {
|
|
298
298
|
castedValue = false
|
|
299
299
|
}
|
|
300
|
+
// @-listener
|
|
301
|
+
else if (key.startsWith('@') && val) {
|
|
302
|
+
const c = component.slice(0, -1)
|
|
303
|
+
castedValue = `${c}['${val.replace('$', '')}'] && ${c}['${val.replace('$', '')}'].bind(${c})`
|
|
304
|
+
}
|
|
300
305
|
// dynamic value
|
|
301
306
|
else if (val.startsWith('$')) {
|
|
302
307
|
castedValue = `${component}${val.replace('$', '')}`
|
|
@@ -80,7 +80,7 @@ export default (template = '') => {
|
|
|
80
80
|
type: (match = tag.match(/^([A-Za-z0-9]+)(?![A-Za-z0-9=])/)) && match[0], // || 'Element' maybe default to 'Element'
|
|
81
81
|
}
|
|
82
82
|
|
|
83
|
-
const attributes = tag.match(/[
|
|
83
|
+
const attributes = tag.match(/[:*@\w.-]+="[^"]*"/g) || []
|
|
84
84
|
if (attributes.length) {
|
|
85
85
|
result['attributes'] = attributes.reduce((obj, attr) => {
|
|
86
86
|
const match = /(.+)=["'](.+)["']/.exec(attr)
|
package/foo.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
const items1 = [{ foo: 'bar' }, { foo: 'baz' }]
|
|
2
|
-
|
|
3
|
-
const items2 = {
|
|
4
|
-
1: { foo: 'bar' },
|
|
5
|
-
2: { foo: 'baz' },
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
const loop = (items) => {
|
|
9
|
-
if (!Array.isArray(items)) {
|
|
10
|
-
items = Object.keys(items).map((k) => {
|
|
11
|
-
return items[k]
|
|
12
|
-
})
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
for (let i = 0; i < items.length; i++) {
|
|
16
|
-
console.log(items[i].foo)
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
loop(items1)
|
|
21
|
-
|
|
22
|
-
loop(items2)
|