@lightningjs/blits 0.6.9 → 0.6.11

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 (57) hide show
  1. package/CHANGELOG.md +17 -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 -6
  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/component.js +0 -6
  16. package/src/components/Circle.js +32 -3
  17. package/src/components/Circle.orig.js +31 -0
  18. package/src/components/FPScounter.js +1127 -0
  19. package/src/components/FPScounter.orig.js +122 -0
  20. package/src/components/Image.js +23 -2
  21. package/src/components/Image.orig.js +33 -0
  22. package/src/components/RouterView.js +24 -5
  23. package/src/components/RouterView.orig.js +51 -0
  24. package/src/components/Sprite.js +26 -3
  25. package/src/components/Sprite.orig.js +58 -0
  26. package/src/components/Text.js +56 -20
  27. package/src/components/Text.orig.js +79 -0
  28. package/src/launch.d.ts +10 -1
  29. package/src/launch.js +1 -0
  30. package/src/lib/codegenerator/generator.js +23 -13
  31. package/src/lib/precompiler/precompiler.js +64 -0
  32. package/src/lib/setup/base.js +2 -0
  33. package/src/lib/symbols.js +2 -0
  34. package/src/lib/templateparser/parser.js +8 -6
  35. package/vite/index.js +17 -0
  36. package/vite/preCompiler.js +19 -39
  37. package/bin/index.cjs +0 -25
  38. package/boilerplate/.vscode/settings.json +0 -10
  39. /package/boilerplate/{.editorconfig → common/eslint/.editorconfig} +0 -0
  40. /package/boilerplate/{.eslintignore → common/eslint/.eslintignore} +0 -0
  41. /package/boilerplate/{.eslintrc.cjs → common/eslint/.eslintrc.cjs} +0 -0
  42. /package/boilerplate/{.vscode → common/ide/.vscode}/extensions.json +0 -0
  43. /package/boilerplate/{.vscode → common/ide/.vscode}/launch.json +0 -0
  44. /package/boilerplate/{public → common/public}/assets/logo.png +0 -0
  45. /package/boilerplate/{public → common/public}/fonts/Lato-Regular.msdf.json +0 -0
  46. /package/boilerplate/{public → common/public}/fonts/Lato-Regular.msdf.png +0 -0
  47. /package/boilerplate/{public → common/public}/fonts/OpenSans-Medium.ttf +0 -0
  48. /package/boilerplate/{public → common/public}/fonts/Raleway-ExtraBold.msdf.json +0 -0
  49. /package/boilerplate/{public → common/public}/fonts/Raleway-ExtraBold.msdf.png +0 -0
  50. /package/boilerplate/{index.html → js/default/index.html} +0 -0
  51. /package/boilerplate/{src → js/default/src}/App.js +0 -0
  52. /package/boilerplate/{src → js/default/src}/components/Loader.js +0 -0
  53. /package/boilerplate/{src → js/default/src}/fontloader.js +0 -0
  54. /package/boilerplate/{src → js/default/src}/index.js +0 -0
  55. /package/boilerplate/{src → js/default/src}/pages/Home.js +0 -0
  56. /package/boilerplate/{src → js/default/src}/renderer.js +0 -0
  57. /package/boilerplate/{vite.config.js → js/default/vite.config.js} +0 -0
@@ -0,0 +1,84 @@
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 fs from 'fs'
19
+ import path from 'path'
20
+ import compiler from '../src/lib/precompiler/precompiler.js'
21
+ import { exec } from 'child_process'
22
+
23
+ const currentDir = process.cwd()
24
+ const componentDirs = ['src/components']
25
+
26
+ function precompileComponents() {
27
+ for (const dir of componentDirs) {
28
+ const fullDir = path.resolve(currentDir, dir)
29
+ console.log(`Checking files in ${fullDir} for components to precompile`)
30
+ processDirectory(fullDir)
31
+ }
32
+ console.log('Finished processing files suitable for precompilation')
33
+ }
34
+
35
+ function processDirectory(directory) {
36
+ const files = fs.readdirSync(directory)
37
+
38
+ for (const file of files) {
39
+ const filePath = path.join(directory, file)
40
+ const stat = fs.statSync(filePath)
41
+
42
+ if (stat.isDirectory()) {
43
+ processDirectory(filePath)
44
+ } else if (/^(?!.*\.orig\.(js|ts)$).*\.(js|ts)$/.test(file)) {
45
+ // only process files that don't end in .orig.js or .orig.ts
46
+ processFile(filePath)
47
+ }
48
+ }
49
+ }
50
+
51
+ function processFile(filePath) {
52
+ console.log(`Precompiling ${filePath}`)
53
+ // backup the file
54
+ const backupFilePath = filePath.replace(/\.(j|t)s$/, '.orig.$1s')
55
+ fs.copyFileSync(filePath, backupFilePath)
56
+
57
+ const source = fs.readFileSync(filePath, 'utf-8')
58
+ const newSource = compiler(source, filePath)
59
+ fs.writeFileSync(filePath, newSource)
60
+
61
+ // only format the file if it was changed
62
+ if (source !== newSource) {
63
+ formatFileWithESLint(filePath)
64
+ }
65
+ }
66
+
67
+ function formatFileWithESLint(filePath) {
68
+ const command = `eslint "${filePath}" --fix`
69
+
70
+ exec(command, (error, stdout, stderr) => {
71
+ if (error) {
72
+ console.error(`Execution Error: ${error.message}`)
73
+ console.error(`Exit Code: ${error.code}`)
74
+ }
75
+ if (stderr) {
76
+ console.error(`ESLint Error: ${stderr}`)
77
+ }
78
+ if (stdout) {
79
+ console.log(`ESLint Output: ${stdout}`)
80
+ }
81
+ })
82
+ }
83
+
84
+ precompileComponents()
package/src/component.js CHANGED
@@ -122,12 +122,6 @@ const Component = (name = required('name'), config = required('config')) => {
122
122
  this[symbols.wrapper] = parentEl
123
123
 
124
124
  Object.defineProperties(this, {
125
- type: {
126
- value: name,
127
- writable: false,
128
- enumerable: true,
129
- configurable: false,
130
- },
131
125
  componentId: {
132
126
  value: createHumanReadableId(name),
133
127
  writable: false,
@@ -19,9 +19,38 @@ import Component from '../component.js'
19
19
 
20
20
  export default () =>
21
21
  Component('Circle', {
22
- template: `
23
- <Element :color="$color" :w="$size" :h="$size" :effects="[$shader('radius', {radius: $radius})]"></Element>
24
- `,
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('color', component.color)
41
+ },
42
+ function anonymous(component, elms, context) {
43
+ elms[0].set('w', component.size)
44
+ },
45
+ function anonymous(component, elms, context) {
46
+ elms[0].set('h', component.size)
47
+ },
48
+ function anonymous(component, elms, context) {
49
+ elms[0].set('effects', [component.shader('radius', { radius: component.radius })])
50
+ },
51
+ ],
52
+ context: {},
53
+ },
25
54
  props: [{ key: 'size', default: 40 }, 'color'],
26
55
  computed: {
27
56
  radius() {
@@ -0,0 +1,31 @@
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('Circle', {
22
+ template: `
23
+ <Element :color="$color" :w="$size" :h="$size" :effects="[$shader('radius', {radius: $radius})]"></Element>
24
+ `,
25
+ props: [{ key: 'size', default: 40 }, 'color'],
26
+ computed: {
27
+ radius() {
28
+ return this.size / 2
29
+ },
30
+ },
31
+ })