@lightningjs/blits 0.9.4 → 0.9.6

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.
@@ -19,29 +19,26 @@ import Component from '../component.js'
19
19
 
20
20
  export default () =>
21
21
  Component('Image', {
22
- /* eslint-disable no-unused-vars */
23
- code: {
24
- render: function anonymous(parent, component, context) {
25
- const elms = []
22
+ /* eslint-disable no-unused-vars */
23
+ code: { render: function anonymous(parent,component,context
24
+ ) {
25
+ const elms = []
26
26
 
27
- if (!elms[0]) {
28
- elms[0] = this.element({ parent: parent || 'root' }, component)
29
- }
30
- const elementConfig0 = {}
31
-
32
- if (!elms[0].nodeId) {
33
- elms[0].populate(elementConfig0)
34
- }
27
+ if(!elms[0]) {
28
+ elms[0] = this.element({parent: parent || 'root'}, component)
29
+ }
30
+ const elementConfig0 = {}
31
+
35
32
 
36
- return elms
37
- },
38
- effects: [
39
- function anonymous(component, elms, context) {
40
- elms[0].set('imageSource', component.imageSource)
41
- },
42
- ],
43
- context: {},
44
- },
33
+ if(!elms[0].nodeId) {
34
+ elms[0].populate(elementConfig0)
35
+ }
36
+
37
+ return elms
38
+ }, effects: [function anonymous(component,elms,context
39
+ ) {
40
+ elms[0].set('imageSource', component.imageSource)
41
+ }], context: {}},
45
42
  props: ['src'],
46
43
  computed: {
47
44
  imageSource() {
@@ -19,8 +19,26 @@ import Component from '../component.js'
19
19
 
20
20
  export default () =>
21
21
  Component('Image', {
22
- template: `
23
- <Element :imageSource="$imageSource" />`,
22
+ /* eslint-disable no-unused-vars */
23
+ code: { render: function anonymous(parent,component,context
24
+ ) {
25
+ const elms = []
26
+
27
+ if(!elms[0]) {
28
+ elms[0] = this.element({parent: parent || 'root'}, component)
29
+ }
30
+ const elementConfig0 = {}
31
+
32
+
33
+ if(!elms[0].nodeId) {
34
+ elms[0].populate(elementConfig0)
35
+ }
36
+
37
+ return elms
38
+ }, effects: [function anonymous(component,elms,context
39
+ ) {
40
+ elms[0].set('imageSource', component.imageSource)
41
+ }], context: {}},
24
42
  props: ['src'],
25
43
  computed: {
26
44
  imageSource() {
@@ -22,28 +22,25 @@ let handler
22
22
 
23
23
  export default () =>
24
24
  Component('RouterView', {
25
- /* eslint-disable no-unused-vars */
26
- code: {
27
- render: function anonymous(parent, component, context) {
28
- const elms = []
25
+ /* eslint-disable no-unused-vars */
26
+ code: { render: function anonymous(parent,component,context
27
+ ) {
28
+ const elms = []
29
29
 
30
- if (!elms[0]) {
31
- elms[0] = this.element({ parent: parent || 'root' }, component)
32
- }
33
- const elementConfig0 = {}
30
+ if(!elms[0]) {
31
+ elms[0] = this.element({parent: parent || 'root'}, component)
32
+ }
33
+ const elementConfig0 = {}
34
+
35
+ elementConfig0['w'] = parent.node.width * (100 / 100)
36
+ elementConfig0['height'] = parent.node.height * (100 / 100)
34
37
 
35
- elementConfig0['w'] = parent.node.width * (100 / 100)
36
- elementConfig0['height'] = parent.node.height * (100 / 100)
37
-
38
- if (!elms[0].nodeId) {
39
- elms[0].populate(elementConfig0)
40
- }
41
-
42
- return elms
43
- },
44
- effects: [],
45
- context: {},
46
- },
38
+ if(!elms[0].nodeId) {
39
+ elms[0].populate(elementConfig0)
40
+ }
41
+
42
+ return elms
43
+ }, effects: [], context: {}},
47
44
  state() {
48
45
  return {
49
46
  activeView: null,
@@ -22,9 +22,25 @@ let handler
22
22
 
23
23
  export default () =>
24
24
  Component('RouterView', {
25
- template: `
26
- <Element w="100%" height="100%"></Element>
27
- `,
25
+ /* eslint-disable no-unused-vars */
26
+ code: { render: function anonymous(parent,component,context
27
+ ) {
28
+ const elms = []
29
+
30
+ if(!elms[0]) {
31
+ elms[0] = this.element({parent: parent || 'root'}, component)
32
+ }
33
+ const elementConfig0 = {}
34
+
35
+ elementConfig0['w'] = parent.node.width * (100 / 100)
36
+ elementConfig0['height'] = parent.node.height * (100 / 100)
37
+
38
+ if(!elms[0].nodeId) {
39
+ elms[0].populate(elementConfig0)
40
+ }
41
+
42
+ return elms
43
+ }, effects: [], context: {}},
28
44
  state() {
29
45
  return {
30
46
  activeView: null,
@@ -21,35 +21,31 @@ import symbols from '../lib/symbols.js'
21
21
 
22
22
  export default () =>
23
23
  Component('Sprite', {
24
- /* eslint-disable no-unused-vars */
25
- code: {
26
- render: function anonymous(parent, component, context) {
27
- const elms = []
24
+ /* eslint-disable no-unused-vars */
25
+ code: { render: function anonymous(parent,component,context
26
+ ) {
27
+ const elms = []
28
28
 
29
- if (!elms[0]) {
30
- elms[0] = this.element({ parent: parent || 'root' }, component)
31
- }
32
- const elementConfig0 = {}
33
-
34
- elementConfig0['w'] = parent.node.width * (100 / 100)
35
- elementConfig0['h'] = parent.node.height * (100 / 100)
36
-
37
- if (!elms[0].nodeId) {
38
- elms[0].populate(elementConfig0)
39
- }
29
+ if(!elms[0]) {
30
+ elms[0] = this.element({parent: parent || 'root'}, component)
31
+ }
32
+ const elementConfig0 = {}
33
+
34
+ elementConfig0['w'] = parent.node.width * (100 / 100)
35
+ elementConfig0['h'] = parent.node.height * (100 / 100)
40
36
 
41
- return elms
42
- },
43
- effects: [
44
- function anonymous(component, elms, context) {
45
- elms[0].set('texture', component.texture)
46
- },
47
- function anonymous(component, elms, context) {
48
- elms[0].set('color', component.color)
49
- },
50
- ],
51
- context: {},
52
- },
37
+ if(!elms[0].nodeId) {
38
+ elms[0].populate(elementConfig0)
39
+ }
40
+
41
+ return elms
42
+ }, effects: [function anonymous(component,elms,context
43
+ ) {
44
+ elms[0].set('texture', component.texture)
45
+ },function anonymous(component,elms,context
46
+ ) {
47
+ elms[0].set('color', component.color)
48
+ }], context: {}},
53
49
  props: ['image', 'map', 'frame', 'color'],
54
50
  state() {
55
51
  return {
@@ -21,9 +21,31 @@ import symbols from '../lib/symbols.js'
21
21
 
22
22
  export default () =>
23
23
  Component('Sprite', {
24
- template: `
25
- <Element w="100%" h="100%" :texture="$texture" :color="$color" />
26
- `,
24
+ /* eslint-disable no-unused-vars */
25
+ code: { render: function anonymous(parent,component,context
26
+ ) {
27
+ const elms = []
28
+
29
+ if(!elms[0]) {
30
+ elms[0] = this.element({parent: parent || 'root'}, component)
31
+ }
32
+ const elementConfig0 = {}
33
+
34
+ elementConfig0['w'] = parent.node.width * (100 / 100)
35
+ elementConfig0['h'] = parent.node.height * (100 / 100)
36
+
37
+ if(!elms[0].nodeId) {
38
+ elms[0].populate(elementConfig0)
39
+ }
40
+
41
+ return elms
42
+ }, effects: [function anonymous(component,elms,context
43
+ ) {
44
+ elms[0].set('texture', component.texture)
45
+ },function anonymous(component,elms,context
46
+ ) {
47
+ elms[0].set('color', component.color)
48
+ }], context: {}},
27
49
  props: ['image', 'map', 'frame', 'color'],
28
50
  state() {
29
51
  return {
@@ -20,65 +20,61 @@ import Settings from '../settings.js'
20
20
 
21
21
  export default () =>
22
22
  Component('Text', {
23
- /* eslint-disable no-unused-vars */
24
- code: {
25
- render: function anonymous(parent, component, context) {
26
- const elms = []
23
+ /* eslint-disable no-unused-vars */
24
+ code: { render: function anonymous(parent,component,context
25
+ ) {
26
+ const elms = []
27
27
 
28
- if (!elms[0]) {
29
- elms[0] = this.element({ parent: parent || 'root' }, component)
30
- }
31
- const elementConfig0 = {}
28
+ if(!elms[0]) {
29
+ elms[0] = this.element({parent: parent || 'root'}, component)
30
+ }
31
+ const elementConfig0 = {}
32
+
33
+ elementConfig0['__textnode'] = true
34
+ elementConfig0['fontFamily'] = component.font
35
+ elementConfig0['letterSpacing'] = component.letterspacing
36
+ elementConfig0['lineHeight'] = component._lineheight
37
+ elementConfig0['stretch'] = component.stretch
38
+ elementConfig0['contain'] = component._contain
39
+ elementConfig0['@loaded'] = component['@loaded'] && component['@loaded'].bind(component)
40
+ elementConfig0['@error'] = component['@error'] && component['@error'].bind(component)
32
41
 
33
- elementConfig0['__textnode'] = true
34
- elementConfig0['fontFamily'] = component.font
35
- elementConfig0['letterSpacing'] = component.letterspacing
36
- elementConfig0['lineHeight'] = component._lineheight
37
- elementConfig0['stretch'] = component.stretch
38
- elementConfig0['contain'] = component._contain
39
- elementConfig0['@loaded'] = component['@loaded'] && component['@loaded'].bind(component)
40
- elementConfig0['@error'] = component['@error'] && component['@error'].bind(component)
41
-
42
- if (!elms[0].nodeId) {
43
- elms[0].populate(elementConfig0)
44
- }
45
-
46
- return elms
47
- },
48
- effects: [
49
- function anonymous(component, elms, context) {
50
- elms[0].set('text', component.content)
51
- },
52
- function anonymous(component, elms, context) {
53
- elms[0].set('fontSize', component.size)
54
- },
55
- function anonymous(component, elms, context) {
56
- elms[0].set('color', component.color)
57
- },
58
- function anonymous(component, elms, context) {
59
- elms[0].set('style', component.style)
60
- },
61
- function anonymous(component, elms, context) {
62
- elms[0].set('weight', component.weight)
63
- },
64
- function anonymous(component, elms, context) {
65
- elms[0].set('wordWrap', component.wordwrap)
66
- },
67
- function anonymous(component, elms, context) {
68
- elms[0].set('maxLines', component.maxlines)
69
- },
70
- function anonymous(component, elms, context) {
71
- elms[0].set('h', component.maxheight)
72
- },
73
- function anonymous(component, elms, context) {
74
- elms[0].set('textAlign', component.align)
75
- },
76
- function anonymous(component, elms, context) {
77
- elms[0].set('overflowSuffix', component.textoverflow)
78
- },
79
- ],
80
- context: {},
81
- },
42
+ if(!elms[0].nodeId) {
43
+ elms[0].populate(elementConfig0)
44
+ }
45
+
46
+ return elms
47
+ }, effects: [function anonymous(component,elms,context
48
+ ) {
49
+ elms[0].set('text', component.content)
50
+ },function anonymous(component,elms,context
51
+ ) {
52
+ elms[0].set('fontSize', component.size)
53
+ },function anonymous(component,elms,context
54
+ ) {
55
+ elms[0].set('color', component.color)
56
+ },function anonymous(component,elms,context
57
+ ) {
58
+ elms[0].set('style', component.style)
59
+ },function anonymous(component,elms,context
60
+ ) {
61
+ elms[0].set('weight', component.weight)
62
+ },function anonymous(component,elms,context
63
+ ) {
64
+ elms[0].set('wordWrap', component.wordwrap)
65
+ },function anonymous(component,elms,context
66
+ ) {
67
+ elms[0].set('maxLines', component.maxlines)
68
+ },function anonymous(component,elms,context
69
+ ) {
70
+ elms[0].set('h', component.maxheight)
71
+ },function anonymous(component,elms,context
72
+ ) {
73
+ elms[0].set('textAlign', component.align)
74
+ },function anonymous(component,elms,context
75
+ ) {
76
+ elms[0].set('overflowSuffix', component.textoverflow)
77
+ }], context: {}},
82
78
  props: [
83
79
  'content',
84
80
  {
@@ -20,27 +20,61 @@ import Settings from '../settings.js'
20
20
 
21
21
  export default () =>
22
22
  Component('Text', {
23
- template: `
24
- <Element
25
- __textnode="true"
26
- :text="$content"
27
- fontFamily="$font"
28
- :fontSize="$size"
29
- :color="$color"
30
- :style="$style"
31
- :weight="$weight"
32
- letterSpacing="$letterspacing"
33
- lineHeight="$_lineheight"
34
- stretch="$stretch"
35
- contain="$_contain"
36
- :wordWrap="$wordwrap"
37
- :maxLines="$maxlines"
38
- :h="$maxheight"
39
- :textAlign="$align"
40
- :overflowSuffix="$textoverflow"
41
- @loaded="$@loaded"
42
- @error="$@error"
43
- />`,
23
+ /* eslint-disable no-unused-vars */
24
+ code: { render: function anonymous(parent,component,context
25
+ ) {
26
+ const elms = []
27
+
28
+ if(!elms[0]) {
29
+ elms[0] = this.element({parent: parent || 'root'}, component)
30
+ }
31
+ const elementConfig0 = {}
32
+
33
+ elementConfig0['__textnode'] = true
34
+ elementConfig0['fontFamily'] = component.font
35
+ elementConfig0['letterSpacing'] = component.letterspacing
36
+ elementConfig0['lineHeight'] = component._lineheight
37
+ elementConfig0['stretch'] = component.stretch
38
+ elementConfig0['contain'] = component._contain
39
+ elementConfig0['@loaded'] = component['@loaded'] && component['@loaded'].bind(component)
40
+ elementConfig0['@error'] = component['@error'] && component['@error'].bind(component)
41
+
42
+ if(!elms[0].nodeId) {
43
+ elms[0].populate(elementConfig0)
44
+ }
45
+
46
+ return elms
47
+ }, effects: [function anonymous(component,elms,context
48
+ ) {
49
+ elms[0].set('text', component.content)
50
+ },function anonymous(component,elms,context
51
+ ) {
52
+ elms[0].set('fontSize', component.size)
53
+ },function anonymous(component,elms,context
54
+ ) {
55
+ elms[0].set('color', component.color)
56
+ },function anonymous(component,elms,context
57
+ ) {
58
+ elms[0].set('style', component.style)
59
+ },function anonymous(component,elms,context
60
+ ) {
61
+ elms[0].set('weight', component.weight)
62
+ },function anonymous(component,elms,context
63
+ ) {
64
+ elms[0].set('wordWrap', component.wordwrap)
65
+ },function anonymous(component,elms,context
66
+ ) {
67
+ elms[0].set('maxLines', component.maxlines)
68
+ },function anonymous(component,elms,context
69
+ ) {
70
+ elms[0].set('h', component.maxheight)
71
+ },function anonymous(component,elms,context
72
+ ) {
73
+ elms[0].set('textAlign', component.align)
74
+ },function anonymous(component,elms,context
75
+ ) {
76
+ elms[0].set('overflowSuffix', component.textoverflow)
77
+ }], context: {}},
44
78
  props: [
45
79
  'content',
46
80
  {
@@ -311,11 +311,10 @@ const Element = {
311
311
  },
312
312
  animate(prop, value, transition) {
313
313
  if (this.node[prop] === value) return Promise.resolve()
314
- // check if a transition is already schedule or running on the same prop
314
+ // check if a transition is already scheduled or running on the same prop
315
315
  if (this.scheduledTransitions[prop]) {
316
- // clearTimeout(this.scheduledTransitions[prop].timeout)
317
316
  if (this.scheduledTransitions[prop].f.state === 'running') {
318
- this.scheduledTransitions[prop].f.pause()
317
+ this.scheduledTransitions[prop].f.stop()
319
318
  // fastforward to final value
320
319
  this.node[prop] = this.scheduledTransitions[prop].v
321
320
  }
@@ -348,33 +347,33 @@ const Element = {
348
347
  const startValue = this.node[prop]
349
348
  this.scheduledTransitions[prop] = {
350
349
  v: props[prop],
351
- f: () => {
352
- try {
353
- f.start()
354
- .waitUntilStarted()
355
- .then((animation) => {
356
- // fire transition start callback if specified
357
- transition.start &&
358
- typeof transition.start === 'function' &&
359
- transition.start.call(this.component, this, prop, startValue)
360
- // continue the chain
361
- animation
362
- .waitUntilStopped()
363
- .then(() => delete this.scheduledTransitions[prop])
364
- .then(() => {
365
- // fire transition end callback if specified
366
- transition.end &&
367
- typeof transition.end === 'function' &&
368
- transition.end.call(this.component, this, prop, this.node[prop])
369
- })
370
- .then(resolve)
350
+ cancel: false,
351
+ f,
352
+ }
353
+
354
+ try {
355
+ f.start()
356
+ .waitUntilStarted()
357
+ .then((animation) => {
358
+ // fire transition start callback if specified
359
+ transition.start &&
360
+ typeof transition.start === 'function' &&
361
+ transition.start.call(this.component, this, prop, startValue)
362
+ // continue the chain
363
+ animation
364
+ .waitUntilStopped()
365
+ .then(() => delete this.scheduledTransitions[prop])
366
+ .then(() => {
367
+ // fire transition end callback if specified
368
+ transition.end &&
369
+ typeof transition.end === 'function' &&
370
+ transition.end.call(this.component, this, prop, this.node[prop])
371
371
  })
372
- } catch (e) {
373
- Log.error(e)
374
- }
375
- },
372
+ .then(resolve)
373
+ })
374
+ } catch (e) {
375
+ Log.error(e)
376
376
  }
377
- this.scheduledTransitions[prop].f()
378
377
  })
379
378
  },
380
379
  destroy() {
@@ -218,7 +218,7 @@ const generateForLoopCode = function (templateObject, parent) {
218
218
  ctx.renderCode.push(`parent = ${parent}`)
219
219
  }
220
220
 
221
- const forCounter = counter
221
+ const forStartCounter = counter
222
222
 
223
223
  // reference all reactive attributes (except those referencing the iterator item),
224
224
  // to ensure that reactivity is registered, even when the initial array is empty
@@ -282,12 +282,15 @@ const generateForLoopCode = function (templateObject, parent) {
282
282
  ctx.renderCode = ctx.renderCode.concat(ctx.effectsCode)
283
283
  ctx.renderCode.push('}')
284
284
 
285
+ const forEndCounter = counter
285
286
  ctx.renderCode.push(`
286
- if(elms[${forCounter}]) {
287
- Object.keys(elms[${forCounter}]).forEach(key => {
287
+ if(elms[${forStartCounter}]) {
288
+ Object.keys(elms[${forStartCounter}]).forEach(key => {
288
289
  if(keys.indexOf(key) === -1) {
289
- elms[${forCounter}][key].destroy && elms[${forCounter}][key].destroy()
290
- delete elms[1][key]
290
+ for(let i=${forStartCounter}; i <= ${forEndCounter}; i++){
291
+ elms[i][key].destroy && elms[i][key].destroy()
292
+ delete elms[i][key]
293
+ }
291
294
  }
292
295
  })
293
296
  }
@@ -19,7 +19,17 @@ import { Log } from './log.js'
19
19
  import { emit, privateEmit } from './hooks.js'
20
20
  import symbols from './symbols.js'
21
21
 
22
- const states = ['init', 'ready', 'focus', 'unfocus', 'destroy']
22
+ const states = [
23
+ 'init', // fired upon component instantiation
24
+ 'ready', // fired when component instantiated, reactivity setup done and template spawned
25
+ 'focus', // fired when receiving focus (can occur multiple times)
26
+ 'unfocus', // fired when losing focus (can occur multiple times)
27
+ 'destroy', // fired when component is destroyed and removed
28
+ 'attach', // fired when entering the viewport margin and attached to the render tree
29
+ 'detach', // fired when leaving the viewport margin and detached from the render tree
30
+ 'enter', // fired when entering the visible viewport
31
+ 'exit', // fired when leaving the visible viewport
32
+ ]
23
33
 
24
34
  export default {
25
35
  previous: null,
@@ -3,6 +3,7 @@ export default {
3
3
  cursorTagStart: Symbol('cursorTagStart'),
4
4
  computedKeys: Symbol('computedKeys'),
5
5
  destroy: Symbol('destroy'),
6
+ holder: Symbol('holder'),
6
7
  id: Symbol('id'),
7
8
  identifier: Symbol('identifier'),
8
9
  index: Symbol('index'),