@lightningjs/blits 0.6.9 → 0.6.10

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.
Files changed (53) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/bin/helpers.js +220 -0
  3. package/bin/index.js +141 -0
  4. package/boilerplate/common/eslint/husky/pre-commit +2 -0
  5. package/boilerplate/common/eslint/package.json +20 -0
  6. package/boilerplate/common/ide/.vscode/settings.json +10 -0
  7. package/boilerplate/js/default/.gitattributes +3 -0
  8. package/boilerplate/{package.json → js/default/package.json} +3 -3
  9. package/docs/getting_started.md +7 -7
  10. package/package.json +13 -5
  11. package/public/assets/fps_sprite.base64.js +1 -0
  12. package/public/assets/fps_sprite.png +0 -0
  13. package/scripts/postpublish.js +59 -0
  14. package/scripts/prepublishOnly.js +84 -0
  15. package/src/components/Circle.js +32 -3
  16. package/src/components/Circle.orig.js +31 -0
  17. package/src/components/FPScounter.js +1127 -0
  18. package/src/components/FPScounter.orig.js +122 -0
  19. package/src/components/Image.js +23 -2
  20. package/src/components/Image.orig.js +33 -0
  21. package/src/components/RouterView.js +22 -3
  22. package/src/components/RouterView.orig.js +51 -0
  23. package/src/components/Sprite.js +26 -3
  24. package/src/components/Sprite.orig.js +58 -0
  25. package/src/components/Text.js +56 -20
  26. package/src/components/Text.orig.js +79 -0
  27. package/src/launch.d.ts +10 -1
  28. package/src/launch.js +1 -0
  29. package/src/lib/precompiler/precompiler.js +64 -0
  30. package/src/lib/setup/base.js +2 -0
  31. package/vite/index.js +17 -0
  32. package/vite/preCompiler.js +19 -39
  33. package/bin/index.cjs +0 -25
  34. package/boilerplate/.vscode/settings.json +0 -10
  35. /package/boilerplate/{.editorconfig → common/eslint/.editorconfig} +0 -0
  36. /package/boilerplate/{.eslintignore → common/eslint/.eslintignore} +0 -0
  37. /package/boilerplate/{.eslintrc.cjs → common/eslint/.eslintrc.cjs} +0 -0
  38. /package/boilerplate/{.vscode → common/ide/.vscode}/extensions.json +0 -0
  39. /package/boilerplate/{.vscode → common/ide/.vscode}/launch.json +0 -0
  40. /package/boilerplate/{public → common/public}/assets/logo.png +0 -0
  41. /package/boilerplate/{public → common/public}/fonts/Lato-Regular.msdf.json +0 -0
  42. /package/boilerplate/{public → common/public}/fonts/Lato-Regular.msdf.png +0 -0
  43. /package/boilerplate/{public → common/public}/fonts/OpenSans-Medium.ttf +0 -0
  44. /package/boilerplate/{public → common/public}/fonts/Raleway-ExtraBold.msdf.json +0 -0
  45. /package/boilerplate/{public → common/public}/fonts/Raleway-ExtraBold.msdf.png +0 -0
  46. /package/boilerplate/{index.html → js/default/index.html} +0 -0
  47. /package/boilerplate/{src → js/default/src}/App.js +0 -0
  48. /package/boilerplate/{src → js/default/src}/components/Loader.js +0 -0
  49. /package/boilerplate/{src → js/default/src}/fontloader.js +0 -0
  50. /package/boilerplate/{src → js/default/src}/index.js +0 -0
  51. /package/boilerplate/{src → js/default/src}/pages/Home.js +0 -0
  52. /package/boilerplate/{src → js/default/src}/renderer.js +0 -0
  53. /package/boilerplate/{vite.config.js → js/default/vite.config.js} +0 -0
@@ -0,0 +1,122 @@
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
+ import { renderer } from '../launch.js'
20
+ import fps_sprite from '../../public/assets/fps_sprite.base64.js'
21
+
22
+ console.log(fps_sprite)
23
+
24
+ export default () =>
25
+ Component('FPScounter', {
26
+ template: `
27
+ <Element>
28
+ <Element y="15" x="20">
29
+ <Element>
30
+ <Sprite image="$image" w="43" h="25" map="$sprite" frame="fps" />
31
+ <Element x="58" y="2">
32
+ <Sprite image="$image" x="0" h="20" w="20" map="$sprite" :frame="$fps[0]" />
33
+ <Sprite image="$image" x="18" h="20" w="20" map="$sprite" :frame="$fps[1]" />
34
+ <Sprite image="$image" x="36" h="20" w="20" map="$sprite" :frame="$fps[2]" />
35
+ </Element>
36
+ </Element>
37
+
38
+ <Element x="150">
39
+ <Sprite image="$image" y="2" w="48" h="25" map="$sprite" frame="avg" />
40
+ <Element x="63" y="2">
41
+ <Sprite image="$image" x="0" h="20" w="20" map="$sprite" :frame="$avgFps[0]" />
42
+ <Sprite image="$image" x="18" h="20" w="20" map="$sprite" :frame="$avgFps[1]" />
43
+ <Sprite image="$image" x="36" h="20" w="20" map="$sprite" :frame="$avgFps[2]" />
44
+ </Element>
45
+ </Element>
46
+
47
+ <Element x="0" y="40" >
48
+ <Sprite image="$image" x="-2" w="47" h="25" map="$sprite" frame="min" />
49
+ <Element x="58" y="2">
50
+ <Sprite image="$image" x="0" h="20" w="20" map="$sprite" :frame="$minFps[0]" />
51
+ <Sprite image="$image" x="18" h="20" w="20" map="$sprite" :frame="$minFps[1]" />
52
+ <Sprite image="$image" x="36" h="20" w="20" map="$sprite" :frame="$minFps[2]" />
53
+ </Element>
54
+ </Element>
55
+
56
+ <Element x="150" y="40">
57
+ <Sprite image="$image" w="53" h="25" map="$sprite" frame="max" />
58
+ <Element x="63" y="2">
59
+ <Sprite image="$image" x="0" h="20" w="20" map="$sprite" :frame="$maxFps[0]" />
60
+ <Sprite image="$image" x="18" h="20" w="20" map="$sprite" :frame="$maxFps[1]" />
61
+ <Sprite image="$image" x="36" h="20" w="20" map="$sprite" :frame="$maxFps[2]" />
62
+ </Element>
63
+ </Element>
64
+ </Element>
65
+ </Element>
66
+ `,
67
+ state() {
68
+ return {
69
+ image: fps_sprite,
70
+ sprite: {
71
+ defaults: {
72
+ y: 1,
73
+ w: 20,
74
+ h: 20,
75
+ },
76
+ frames: {
77
+ '-': { x: -1000 },
78
+ 0: { x: 1 },
79
+ 1: { x: 23 },
80
+ 2: { x: 45 },
81
+ 3: { x: 67 },
82
+ 4: { x: 89 },
83
+ 5: { x: 111 },
84
+ 6: { x: 133 },
85
+ 7: { x: 155 },
86
+ 8: { x: 177 },
87
+ 9: { x: 199 },
88
+ avg: { x: 221, w: 48, h: 25 },
89
+ fps: { x: 271, w: 43, h: 25 },
90
+ max: { x: 316, w: 53, h: 25 },
91
+ min: { x: 371, w: 47, h: 25 },
92
+ },
93
+ },
94
+ fps: '---',
95
+ avgFps: '---',
96
+ minFps: '---',
97
+ maxFps: '---',
98
+ }
99
+ },
100
+ hooks: {
101
+ ready() {
102
+ let minFps = 10000
103
+ let maxFps = 0
104
+ let avgFps = 0
105
+ let totalFps = 0
106
+ let fpsUpdateCounter = 0
107
+
108
+ renderer.on('fpsUpdate', (rM, { fps }) => {
109
+ minFps = Math.min(fps, minFps)
110
+ maxFps = Math.max(fps, maxFps)
111
+ totalFps += fps
112
+ fpsUpdateCounter++
113
+ avgFps = Math.round(totalFps / fpsUpdateCounter)
114
+
115
+ this.fps = fps.toString().padStart(3, '0')
116
+ this.avgFps = avgFps.toString().padStart(3, '0')
117
+ this.minFps = minFps.toString().padStart(3, '0')
118
+ this.maxFps = maxFps.toString().padStart(3, '0')
119
+ })
120
+ },
121
+ },
122
+ })
@@ -19,8 +19,29 @@ 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: {
24
+ render: function anonymous(parent, component, context) {
25
+ const elms = []
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
+ }
35
+
36
+ return elms
37
+ },
38
+ effects: [
39
+ function anonymous(component, elms, context) {
40
+ elms[0].set('imageSource', component.imageSource)
41
+ },
42
+ ],
43
+ context: {},
44
+ },
24
45
  props: ['src'],
25
46
  computed: {
26
47
  imageSource() {
@@ -0,0 +1,33 @@
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
+ export default () =>
21
+ Component('Image', {
22
+ template: `
23
+ <Element :imageSource="$imageSource" />`,
24
+ props: ['src'],
25
+ computed: {
26
+ imageSource() {
27
+ if (/^(?:https?:)?\/\//i.test(this.src)) {
28
+ return this.src
29
+ }
30
+ return `${window.location.protocol}//${window.location.host}/${this.src}`
31
+ },
32
+ },
33
+ })
@@ -22,9 +22,28 @@ 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: {
27
+ render: function anonymous(parent, component, context) {
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
+ },
44
+ effects: [],
45
+ context: {},
46
+ },
28
47
  state() {
29
48
  return {
30
49
  activeView: null,
@@ -0,0 +1,51 @@
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
+ import Router from '../router/router.js'
20
+
21
+ let handler
22
+
23
+ export default () =>
24
+ Component('RouterView', {
25
+ template: `
26
+ <Element w="100%" height="100%"></Element>
27
+ `,
28
+ state() {
29
+ return {
30
+ activeView: null,
31
+ }
32
+ },
33
+ hooks: {
34
+ ready() {
35
+ handler = () => Router.navigate.apply(this)
36
+ Router.navigate.apply(this)
37
+ window.addEventListener('hashchange', handler)
38
+ },
39
+ destroy() {
40
+ window.removeEventListener('hashchange', handler, false)
41
+ },
42
+ focus() {
43
+ this.activeView && this.activeView.focus()
44
+ },
45
+ },
46
+ input: {
47
+ back(e) {
48
+ if (!Router.back()) this.parent.focus(e)
49
+ },
50
+ },
51
+ })
@@ -21,9 +21,32 @@ import symbols from '../lib/symbols.js'
21
21
 
22
22
  export default () =>
23
23
  Component('Sprite', {
24
- template: `
25
- <Element w="$w" h="$h" :texture="$texture" />
26
- `,
24
+ /* eslint-disable no-unused-vars */
25
+ code: {
26
+ render: function anonymous(parent, component, context) {
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'] = component.w
35
+ elementConfig0['h'] = component.h
36
+
37
+ if (!elms[0].nodeId) {
38
+ elms[0].populate(elementConfig0)
39
+ }
40
+
41
+ return elms
42
+ },
43
+ effects: [
44
+ function anonymous(component, elms, context) {
45
+ elms[0].set('texture', component.texture)
46
+ },
47
+ ],
48
+ context: {},
49
+ },
27
50
  props: ['image', 'map', 'frame', 'w', 'h'],
28
51
  state() {
29
52
  return {
@@ -0,0 +1,58 @@
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
+ template: `
25
+ <Element w="$w" h="$h" :texture="$texture" />
26
+ `,
27
+ props: ['image', 'map', 'frame', 'w', 'h'],
28
+ state() {
29
+ return {
30
+ spriteTexture: false,
31
+ }
32
+ },
33
+ computed: {
34
+ texture() {
35
+ const options =
36
+ 'frames' in this.map
37
+ ? Object.assign({}, this.map.defaults || {}, this.map.frames[this.frame])
38
+ : this.map[this.frame]
39
+
40
+ if (this.spriteTexture && options) {
41
+ return this[symbols.renderer].createTexture('SubTexture', {
42
+ texture: this.spriteTexture,
43
+ x: options.x,
44
+ y: options.y,
45
+ width: options.w,
46
+ height: options.h,
47
+ })
48
+ }
49
+ },
50
+ },
51
+ hooks: {
52
+ ready() {
53
+ this.spriteTexture = this[symbols.renderer].createTexture('ImageTexture', {
54
+ src: this.image,
55
+ })
56
+ },
57
+ },
58
+ })
@@ -20,26 +20,62 @@ 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
- :textAlign="$align"
39
- :overflowSuffix="$textoverflow"
40
- @loaded="$@loaded"
41
- @error="$@error"
42
- />`,
23
+ /* eslint-disable no-unused-vars */
24
+ code: {
25
+ render: function anonymous(parent, component, context) {
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
+ },
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('textAlign', component.align)
72
+ },
73
+ function anonymous(component, elms, context) {
74
+ elms[0].set('overflowSuffix', component.textoverflow)
75
+ },
76
+ ],
77
+ context: {},
78
+ },
43
79
  props: [
44
80
  'content',
45
81
  {
@@ -0,0 +1,79 @@
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
+ import Settings from '../settings.js'
20
+
21
+ export default () =>
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
+ :textAlign="$align"
39
+ :overflowSuffix="$textoverflow"
40
+ @loaded="$@loaded"
41
+ @error="$@error"
42
+ />`,
43
+ props: [
44
+ 'content',
45
+ {
46
+ key: 'font',
47
+ default: Settings.get('defaultFont', 'lato'),
48
+ },
49
+ {
50
+ key: 'size',
51
+ cast: Number,
52
+ default: 32,
53
+ },
54
+ 'style',
55
+ 'color',
56
+ 'weight',
57
+ 'letterspacing',
58
+ 'stretch',
59
+ 'align',
60
+ 'wordwrap',
61
+ 'maxlines',
62
+ 'lineheight',
63
+ 'contain',
64
+ '@loaded',
65
+ '@error',
66
+ 'textoverflow',
67
+ ],
68
+ computed: {
69
+ _contain() {
70
+ return (
71
+ this.contain ||
72
+ (this.wordwrap && this.maxlines ? 'both' : this.wordwrap ? 'width' : 'none')
73
+ )
74
+ },
75
+ _lineheight() {
76
+ return this.lineheight !== undefined ? this.lineheight : this.size
77
+ },
78
+ },
79
+ })
package/src/launch.d.ts CHANGED
@@ -144,7 +144,16 @@ export interface Settings {
144
144
  *
145
145
  * Defaults to 1 if not specified
146
146
  */
147
- pixelRatio?: number,
147
+ pixelRatio?: number
148
+ /**
149
+ * Interval in milliseconds to receive FPS updates
150
+ *
151
+ * @remarks
152
+ * If set to `0`, FPS updates will be disabled.
153
+ *
154
+ * @defaultValue `1000` (disabled)
155
+ */
156
+ fpsInterval?: number
148
157
  /**
149
158
  * Maximum number of web workers to spin up simultaneously for offloading functionality such
150
159
  * as image loading to separate threads (when supported by the browser)
package/src/launch.js CHANGED
@@ -41,6 +41,7 @@ export default (App, target, settings) => {
41
41
  appWidth: settings.w || 1920,
42
42
  appHeight: settings.h || 1080,
43
43
  coreExtensionModule: settings.fontLoader,
44
+ fpsUpdateInterval: settings.fpsInterval || 1000,
44
45
  deviceLogicalPixelRatio:
45
46
  settings.pixelRatio ||
46
47
  screenResolutions[settings.screenResolution] ||
@@ -0,0 +1,64 @@
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 parser from '../templateparser/parser.js'
19
+ import generator from '../codegenerator/generator.js'
20
+ import path from 'path'
21
+
22
+ export default (source, filePath) => {
23
+ if (
24
+ source.indexOf('Blits.Component(') > -1 ||
25
+ source.indexOf('Blits.Application(') > -1 ||
26
+ /=>\s*Component\(['"][A-Za-z]+['"],/s.test(source) // blits component
27
+ ) {
28
+ // get the start of the template key in de component configuration object
29
+ const templateKeyRegex = /template:\s*([`"'])*/g
30
+ const templateStartResult = templateKeyRegex.exec(source)
31
+
32
+ if (templateStartResult) {
33
+ const typeOfQuotesUsed = templateStartResult[1]
34
+ const templateStartIndex = templateStartResult.index
35
+
36
+ // get the template contents from the configuration object
37
+ const templateContentsRegex = new RegExp(`${typeOfQuotesUsed}([\\s\\S]*?)${typeOfQuotesUsed}`)
38
+ const templateContentResult = templateContentsRegex.exec(source.slice(templateStartIndex))
39
+ const templateEndIndex =
40
+ templateStartIndex + templateContentResult.index + templateContentResult[0].length
41
+
42
+ // Parse the template
43
+ let resourceName = 'Blits.Application'
44
+ if (source.indexOf('Blits.Component(') > -1) {
45
+ resourceName = source.match(/Blits\.Component\(['"](.*)['"]\s*,/)[1]
46
+ }
47
+ const componentPath = path.relative(process.cwd(), filePath)
48
+ const parsed = parser(templateContentResult[1], resourceName, null, componentPath)
49
+
50
+ // Generate the code
51
+ const code = generator.call({ components: {} }, parsed)
52
+
53
+ // Insert the code in the component using the 'code' key, replacing the template key
54
+ const replacement = `/* eslint-disable no-unused-vars */ \ncode: { render: ${code.render.toString()}, effects: [${code.effects.map(
55
+ (fn) => fn.toString()
56
+ )}], context: {}}`
57
+ const newSource =
58
+ source.substring(0, templateStartIndex) + replacement + source.substring(templateEndIndex)
59
+
60
+ return newSource
61
+ }
62
+ }
63
+ return source
64
+ }
@@ -23,6 +23,7 @@ import Circle from '../../components/Circle.js'
23
23
  import RouterView from '../../components/RouterView.js'
24
24
  import Sprite from '../../components/Sprite.js'
25
25
  import Text from '../../components/Text.js'
26
+ import FPScounter from '../../components/FPScounter.js'
26
27
  import eventListeners from '../eventListeners.js'
27
28
  import { default as log, Log } from '../log.js'
28
29
  import symbols from '../symbols.js'
@@ -135,6 +136,7 @@ export default (component) => {
135
136
  RouterView: RouterView(),
136
137
  Sprite: Sprite(),
137
138
  Text: Text(),
139
+ FPScounter: FPScounter(),
138
140
  },
139
141
  writable: false,
140
142
  enumerable: false,
package/vite/index.js CHANGED
@@ -1,3 +1,20 @@
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
+
1
18
  import preCompiler from './preCompiler.js'
2
19
  import { importChunkUrl } from '@lightningjs/vite-plugin-import-chunk-url'
3
20