@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.
- package/CHANGELOG.md +17 -0
- package/bin/helpers.js +220 -0
- package/bin/index.js +141 -0
- package/boilerplate/common/eslint/husky/pre-commit +2 -0
- package/boilerplate/common/eslint/package.json +20 -0
- package/boilerplate/common/ide/.vscode/settings.json +10 -0
- package/boilerplate/js/default/.gitattributes +3 -0
- package/boilerplate/{package.json → js/default/package.json} +3 -3
- package/docs/getting_started.md +7 -7
- package/package.json +13 -6
- package/public/assets/fps_sprite.base64.js +1 -0
- package/public/assets/fps_sprite.png +0 -0
- package/scripts/postpublish.js +59 -0
- package/scripts/prepublishOnly.js +84 -0
- package/src/component.js +0 -6
- package/src/components/Circle.js +32 -3
- package/src/components/Circle.orig.js +31 -0
- package/src/components/FPScounter.js +1127 -0
- package/src/components/FPScounter.orig.js +122 -0
- package/src/components/Image.js +23 -2
- package/src/components/Image.orig.js +33 -0
- package/src/components/RouterView.js +24 -5
- package/src/components/RouterView.orig.js +51 -0
- package/src/components/Sprite.js +26 -3
- package/src/components/Sprite.orig.js +58 -0
- package/src/components/Text.js +56 -20
- package/src/components/Text.orig.js +79 -0
- package/src/launch.d.ts +10 -1
- package/src/launch.js +1 -0
- package/src/lib/codegenerator/generator.js +23 -13
- package/src/lib/precompiler/precompiler.js +64 -0
- package/src/lib/setup/base.js +2 -0
- package/src/lib/symbols.js +2 -0
- package/src/lib/templateparser/parser.js +8 -6
- package/vite/index.js +17 -0
- package/vite/preCompiler.js +19 -39
- package/bin/index.cjs +0 -25
- package/boilerplate/.vscode/settings.json +0 -10
- /package/boilerplate/{.editorconfig → common/eslint/.editorconfig} +0 -0
- /package/boilerplate/{.eslintignore → common/eslint/.eslintignore} +0 -0
- /package/boilerplate/{.eslintrc.cjs → common/eslint/.eslintrc.cjs} +0 -0
- /package/boilerplate/{.vscode → common/ide/.vscode}/extensions.json +0 -0
- /package/boilerplate/{.vscode → common/ide/.vscode}/launch.json +0 -0
- /package/boilerplate/{public → common/public}/assets/logo.png +0 -0
- /package/boilerplate/{public → common/public}/fonts/Lato-Regular.msdf.json +0 -0
- /package/boilerplate/{public → common/public}/fonts/Lato-Regular.msdf.png +0 -0
- /package/boilerplate/{public → common/public}/fonts/OpenSans-Medium.ttf +0 -0
- /package/boilerplate/{public → common/public}/fonts/Raleway-ExtraBold.msdf.json +0 -0
- /package/boilerplate/{public → common/public}/fonts/Raleway-ExtraBold.msdf.png +0 -0
- /package/boilerplate/{index.html → js/default/index.html} +0 -0
- /package/boilerplate/{src → js/default/src}/App.js +0 -0
- /package/boilerplate/{src → js/default/src}/components/Loader.js +0 -0
- /package/boilerplate/{src → js/default/src}/fontloader.js +0 -0
- /package/boilerplate/{src → js/default/src}/index.js +0 -0
- /package/boilerplate/{src → js/default/src}/pages/Home.js +0 -0
- /package/boilerplate/{src → js/default/src}/renderer.js +0 -0
- /package/boilerplate/{vite.config.js → js/default/vite.config.js} +0 -0
|
@@ -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
|
+
}
|
package/src/lib/setup/base.js
CHANGED
|
@@ -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/src/lib/symbols.js
CHANGED
|
@@ -77,7 +77,7 @@ export default (template = '', componentName, parentComponent, filePath = null)
|
|
|
77
77
|
const match = moveCursorOnMatch(emptyTagStartRegex)
|
|
78
78
|
if (match) {
|
|
79
79
|
tags.push({
|
|
80
|
-
|
|
80
|
+
[Symbol.for('componentType')]: null,
|
|
81
81
|
[symbols.type]: 'opening',
|
|
82
82
|
[symbols.level]: currentLevel,
|
|
83
83
|
[symbols.cursorTagStart]: prevCursor,
|
|
@@ -94,7 +94,7 @@ export default (template = '', componentName, parentComponent, filePath = null)
|
|
|
94
94
|
if (match) {
|
|
95
95
|
currentLevel--
|
|
96
96
|
tags.push({
|
|
97
|
-
|
|
97
|
+
[Symbol.for('componentType')]: null,
|
|
98
98
|
[symbols.type]: 'closing',
|
|
99
99
|
[symbols.level]: currentLevel,
|
|
100
100
|
})
|
|
@@ -108,7 +108,7 @@ export default (template = '', componentName, parentComponent, filePath = null)
|
|
|
108
108
|
const match = moveCursorOnMatch(tagStartRegex)
|
|
109
109
|
if (match) {
|
|
110
110
|
currentTag = {
|
|
111
|
-
|
|
111
|
+
[Symbol.for('componentType')]: match[1],
|
|
112
112
|
[symbols.level]: currentLevel,
|
|
113
113
|
[symbols.cursorTagStart]: prevCursor,
|
|
114
114
|
}
|
|
@@ -221,7 +221,7 @@ export default (template = '', componentName, parentComponent, filePath = null)
|
|
|
221
221
|
[symbols.level]: element[symbols.level],
|
|
222
222
|
[symbols.type]: element[symbols.type],
|
|
223
223
|
[symbols.cursorTagStart]: element[symbols.cursorTagStart],
|
|
224
|
-
|
|
224
|
+
[Symbol.for('componentType')]: element[Symbol.for('componentType')],
|
|
225
225
|
parent: currentParent, // helps getting the previous parent when closing tag is encountered
|
|
226
226
|
})
|
|
227
227
|
} else if (element[symbols.type] === 'closing') {
|
|
@@ -230,7 +230,9 @@ export default (template = '', componentName, parentComponent, filePath = null)
|
|
|
230
230
|
let isTagMismatch = false
|
|
231
231
|
if (!isStackEmpty) {
|
|
232
232
|
isLevelMismatch = stack[stack.length - 1][symbols.level] !== element[symbols.level]
|
|
233
|
-
isTagMismatch =
|
|
233
|
+
isTagMismatch =
|
|
234
|
+
stack[stack.length - 1][Symbol.for('componentType')] !==
|
|
235
|
+
element[Symbol.for('componentType')]
|
|
234
236
|
}
|
|
235
237
|
|
|
236
238
|
if (isStackEmpty || isLevelMismatch || isTagMismatch) {
|
|
@@ -329,7 +331,7 @@ export default (template = '', componentName, parentComponent, filePath = null)
|
|
|
329
331
|
let currentParent = parentComponent
|
|
330
332
|
|
|
331
333
|
while (currentParent) {
|
|
332
|
-
hierarchy = `${currentParent.
|
|
334
|
+
hierarchy = `${currentParent[Symbol.for('componentType')]}/${hierarchy}`
|
|
333
335
|
currentParent = currentParent.parent
|
|
334
336
|
}
|
|
335
337
|
return hierarchy
|
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
|
|
package/vite/preCompiler.js
CHANGED
|
@@ -1,6 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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 compiler from '../src/lib/precompiler/precompiler.js'
|
|
4
19
|
|
|
5
20
|
export default function () {
|
|
6
21
|
let config
|
|
@@ -11,42 +26,7 @@ export default function () {
|
|
|
11
26
|
},
|
|
12
27
|
transform(source, filePath) {
|
|
13
28
|
if (config.blits && config.blits.precompile === false) return source
|
|
14
|
-
|
|
15
|
-
// get the start of the template key in de component configuration object
|
|
16
|
-
const templateKeyRegex = /template:\s*([`"'])*/g
|
|
17
|
-
const templateStartResult = templateKeyRegex.exec(source)
|
|
18
|
-
const typeOfQuotesUsed = templateStartResult[1]
|
|
19
|
-
const templateStartIndex = templateStartResult.index
|
|
20
|
-
|
|
21
|
-
// get the template contents from the configuration object
|
|
22
|
-
const templateContentsRegex = new RegExp(
|
|
23
|
-
`${typeOfQuotesUsed}([\\s\\S]*?)${typeOfQuotesUsed}`
|
|
24
|
-
)
|
|
25
|
-
|
|
26
|
-
const templateContentResult = templateContentsRegex.exec(source.slice(templateStartIndex))
|
|
27
|
-
const templateEndIndex =
|
|
28
|
-
templateStartIndex + templateContentResult.index + templateContentResult[0].length
|
|
29
|
-
|
|
30
|
-
// Parse the template
|
|
31
|
-
let resourceName = 'Blits.Application'
|
|
32
|
-
if (source.indexOf('Blits.Component(') > -1) {
|
|
33
|
-
resourceName = source.match(/Blits\.Component\(['"](.*)['"]\s*,/)[1]
|
|
34
|
-
}
|
|
35
|
-
const componentPath = path.relative(process.cwd(), filePath)
|
|
36
|
-
const parsed = parser(templateContentResult[1], resourceName, null, componentPath)
|
|
37
|
-
|
|
38
|
-
// Generate the code
|
|
39
|
-
const code = generator.call({ components: {} }, parsed)
|
|
40
|
-
|
|
41
|
-
// Insert the code in the component using the 'code' key, replacing the template key
|
|
42
|
-
const replacement = `code: { render: ${code.render.toString()}, effects: [${code.effects.map(
|
|
43
|
-
(fn) => fn.toString() + ','
|
|
44
|
-
)}], context: {}}`
|
|
45
|
-
const newSource =
|
|
46
|
-
source.substring(0, templateStartIndex) + replacement + source.substring(templateEndIndex)
|
|
47
|
-
|
|
48
|
-
return newSource
|
|
49
|
-
}
|
|
29
|
+
return compiler(source, filePath)
|
|
50
30
|
},
|
|
51
31
|
}
|
|
52
32
|
}
|
package/bin/index.cjs
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
const path = require('path')
|
|
4
|
-
const fs = require('fs')
|
|
5
|
-
|
|
6
|
-
const folder = process.argv.slice(2).pop()
|
|
7
|
-
|
|
8
|
-
if (!folder) {
|
|
9
|
-
console.error('Please specify a folder for your new Lightning 3 App')
|
|
10
|
-
} else {
|
|
11
|
-
if (fs.existsSync(folder)) {
|
|
12
|
-
console.error(`The directory ${folder} already exists! Choose a different location.`)
|
|
13
|
-
} else {
|
|
14
|
-
fs.cpSync(path.join(__dirname, '..', 'boilerplate'), folder, { recursive: true })
|
|
15
|
-
console.log(
|
|
16
|
-
'================================== ⚡️⚡️⚡️⚡️ ================================== '
|
|
17
|
-
)
|
|
18
|
-
console.log('Your new boilerplate Lightning 3 App has been created!')
|
|
19
|
-
console.log('')
|
|
20
|
-
console.log(`Go to ${folder}, run npm install, followed by npm run dev to get started`)
|
|
21
|
-
console.log(
|
|
22
|
-
'================================== ⚡️⚡️⚡️⚡️ ================================== '
|
|
23
|
-
)
|
|
24
|
-
}
|
|
25
|
-
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|