@lightningjs/blits 0.5.10 → 0.6.0

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 CHANGED
@@ -1,5 +1,12 @@
1
1
  # Changelog
2
2
 
3
+ # v0.6.0
4
+
5
+ _4 jan 2024_
6
+
7
+ - Added pre-compilation functionality to improve performance. Requires an update to the `vite.config.js` to enable. Read more details in this [blog post](https://lightningjs.io/blogs/blitsPreCompilation.html)
8
+ - Added `defaultFont` to the Launch settings
9
+
3
10
  # v0.5.10
4
11
 
5
12
  _3 jan 2024_
@@ -31,6 +31,6 @@
31
31
  "vite": "^4.0.4"
32
32
  },
33
33
  "dependencies": {
34
- "@lightningjs/blits": "^0.5.10"
34
+ "@lightningjs/blits": "^0.6.0"
35
35
  }
36
36
  }
@@ -1,9 +1,9 @@
1
1
  import { defineConfig } from 'vite'
2
- import { importChunkUrl } from '@lightningjs/blits/vite'
2
+ import blitsVitePlugins from '@lightningjs/blits/vite'
3
3
 
4
4
  export default defineConfig(({ command, mode, ssrBuild }) => {
5
5
  return {
6
- plugins: [importChunkUrl()],
6
+ plugins: [...blitsVitePlugins],
7
7
  resolve: {
8
8
  mainFields: ['browser', 'module', 'jsnext:main', 'jsnext'],
9
9
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lightningjs/blits",
3
- "version": "0.5.10",
3
+ "version": "0.6.0",
4
4
  "description": "Blits: The Lightning 3 App Development Framework",
5
5
  "bin": "bin/index.cjs",
6
6
  "exports": {
package/src/component.js CHANGED
@@ -47,13 +47,11 @@ const required = (name) => {
47
47
  }
48
48
 
49
49
  const Component = (name = required('name'), config = required('config')) => {
50
- let code = null
51
-
52
50
  const setupComponent = (lifecycle) => {
53
51
  // code generation
54
- if (!code) {
52
+ if (!config.code) {
55
53
  Log.debug(`Generating code for ${name} component`)
56
- code = codegenerator.call(config, parser(config.template))
54
+ config.code = codegenerator.call(config, parser(config.template))
57
55
  }
58
56
 
59
57
  setupBase(component)
@@ -167,7 +165,7 @@ const Component = (name = required('name'), config = required('config')) => {
167
165
  this.lifecycle.state = 'init'
168
166
 
169
167
  Object.defineProperty(this, symbols.children, {
170
- value: code.render.apply(stage, [parentEl, this, code.context]),
168
+ value: config.code.render.apply(stage, [parentEl, this, config]),
171
169
  writable: false,
172
170
  enumerable: false,
173
171
  configurable: false,
@@ -180,9 +178,9 @@ const Component = (name = required('name'), config = required('config')) => {
180
178
  configurable: false,
181
179
  })
182
180
 
183
- code.effects.forEach((eff) => {
181
+ config.code.effects.forEach((eff) => {
184
182
  effect(() => {
185
- eff.apply(stage, [this, this[symbols.children], code.context])
183
+ eff.apply(stage, [this, this[symbols.children], config])
186
184
  })
187
185
  })
188
186
 
@@ -16,6 +16,7 @@
16
16
  */
17
17
 
18
18
  import Component from '../component.js'
19
+ import Settings from '../settings.js'
19
20
 
20
21
  export default () =>
21
22
  Component('Text', {
@@ -41,7 +42,7 @@ export default () =>
41
42
  'content',
42
43
  {
43
44
  key: 'font',
44
- default: 'lato',
45
+ default: Settings.get('defaultFont', 'lato'),
45
46
  },
46
47
  {
47
48
  key: 'size',
package/src/launch.d.ts CHANGED
@@ -90,6 +90,15 @@ export interface Settings {
90
90
  * Fonts to be used in the Application
91
91
  */
92
92
  fonts?: Font[],
93
+ /**
94
+ * Default font family to use in the Application when no font attribute is specified
95
+ * on a Text-component
96
+ *
97
+ * The default font must be registered in the `fonts` array in the settings.
98
+ *
99
+ * Defaults to `lato` font family
100
+ */
101
+ defaultFont?: string,
93
102
  /**
94
103
  * Custom keymapping
95
104
  */
@@ -92,8 +92,8 @@ const generateElementCode = function (
92
92
  if (options.holder === true) {
93
93
  renderCode.push(`
94
94
  if(typeof cmp${counter} !== 'undefined') {
95
- for(key in cmp${counter}.config.props) {
96
- delete elementConfig${counter}[cmp${counter}.config.props[key]]
95
+ for(let key in cmp${counter}.config.props) {
96
+ delete elementConfig${counter}[cmp${counter}.config.props[key]]
97
97
  }
98
98
  }
99
99
  `)
@@ -171,7 +171,7 @@ const generateComponentCode = function (
171
171
 
172
172
  renderCode.push(`
173
173
  if(!${elm}) {
174
- ${elm} = (context.components && context.components['${templateObject.type}'] || component[Symbol.for('components')]['${templateObject.type}'] || (() => { console.log('component ${templateObject.type} not found')})).call(null, {props: props${counter}}, ${parent}, component)
174
+ ${elm} = (context.components && context.components['${templateObject.type}'] || component[Symbol.for('components')]['${templateObject.type}'] || (() => { console.error('component ${templateObject.type} not found')})).call(null, {props: props${counter}}, ${parent}, component)
175
175
  if (${elm}[Symbol.for('slots')][0]) {
176
176
  parent = ${elm}[Symbol.for('slots')][0]
177
177
  component = ${elm}
package/vite/index.js CHANGED
@@ -1 +1,7 @@
1
+ import preCompiler from './preCompiler.js'
2
+ import { importChunkUrl } from '@lightningjs/vite-plugin-import-chunk-url'
3
+
1
4
  export { importChunkUrl as importChunkUrl } from '@lightningjs/vite-plugin-import-chunk-url'
5
+ export { default as preCompiler } from './preCompiler.js'
6
+
7
+ export default [importChunkUrl(), preCompiler()]
@@ -0,0 +1,46 @@
1
+ import parser from '../src/lib/templateparser/parser.js'
2
+ import generator from '../src/lib/codegenerator/generator.js'
3
+
4
+ export default function () {
5
+ let config
6
+ return {
7
+ name: 'preCompiler',
8
+ configResolved(resolvedConfig) {
9
+ config = resolvedConfig
10
+ },
11
+ transform(source) {
12
+ if (config.blits && config.blits.precompile === false) return source
13
+ if (source.indexOf('Blits.Component(') > -1 || source.indexOf('Blits.Application(') > -1) {
14
+ // get the start of the template key in de component configuration object
15
+ const templateKeyRegex = /template:\s*([`"'])*/g
16
+ const templateStartResult = templateKeyRegex.exec(source)
17
+ const typeOfQuotesUsed = templateStartResult[1]
18
+ const templateStartIndex = templateStartResult.index
19
+
20
+ // get the template contents from the configuration object
21
+ const templateContentsRegex = new RegExp(
22
+ `${typeOfQuotesUsed}([\\s\\S]*?)${typeOfQuotesUsed}`
23
+ )
24
+
25
+ const templateContentResult = templateContentsRegex.exec(source.slice(templateStartIndex))
26
+ const templateEndIndex =
27
+ templateStartIndex + templateContentResult.index + templateContentResult[0].length
28
+
29
+ // Parse the template
30
+ const parsed = parser(templateContentResult[1])
31
+
32
+ // Generate the code
33
+ const code = generator.call({ components: {} }, parsed)
34
+
35
+ // Insert the code in the component using the 'code' key, replacing the template key
36
+ const replacement = `code: { render: ${code.render.toString()}, effects: [${code.effects.map(
37
+ (fn) => fn.toString() + ','
38
+ )}], context: {}}`
39
+ const newSource =
40
+ source.substring(0, templateStartIndex) + replacement + source.substring(templateEndIndex)
41
+
42
+ return newSource
43
+ }
44
+ },
45
+ }
46
+ }