@lightningjs/blits 1.1.0 → 1.3.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 +19 -0
- package/NOTICE +9 -0
- package/docs/_sidebar.md +1 -0
- package/docs/built-in/directives.md +4 -6
- package/docs/built-in/for-loop.md +6 -8
- package/docs/components/component_state.md +3 -5
- package/docs/components/computed_properties.md +3 -5
- package/docs/components/lifecycle_events.md +2 -4
- package/docs/components/methods.md +1 -3
- package/docs/components/props.md +3 -5
- package/docs/components/user_input.md +6 -8
- package/docs/components/utilities.md +1 -2
- package/docs/components/watchers.md +2 -4
- package/docs/essentials/application_root.md +1 -3
- package/docs/essentials/components.md +2 -4
- package/docs/essentials/displaying_images.md +4 -6
- package/docs/essentials/displaying_text.md +4 -6
- package/docs/essentials/element_attributes.md +10 -12
- package/docs/essentials/template_syntax.md +5 -7
- package/docs/getting_started/file_structure.md +9 -11
- package/docs/getting_started/getting_started.md +5 -7
- package/docs/plugins/language.md +172 -0
- package/docs/plugins/text-to-speech-announcer.md +2 -4
- package/docs/sidebar.json +4 -0
- package/docs/transitions_animations/transitions.md +5 -7
- package/index.d.ts +2 -0
- package/index.js +2 -0
- package/package.json +3 -2
- package/src/component/base/index.js +4 -1
- package/src/component/base/log.js +1 -1
- package/src/component/base/methods.js +1 -2
- package/src/component/setup/state.js +9 -13
- package/src/component.d.ts +6 -0
- package/src/component.js +30 -10
- package/src/components/FPScounter.js +56 -12
- package/src/components/index.js +0 -2
- package/src/components/index.orig.js +0 -2
- package/src/engines/L3/element.js +56 -66
- package/src/helpers/fetchJson.js +34 -0
- package/src/lib/codegenerator/generator.js +104 -28
- package/src/lib/codegenerator/generator.test.js +184 -0
- package/src/lib/colors/colors.js +6 -7
- package/src/lib/reactivity/reactive.js +3 -5
- package/src/lib/symbols.js +1 -0
- package/src/lib/templateparser/parser.js +1 -1
- package/src/plugin.d.ts +71 -0
- package/src/plugin.js +23 -0
- package/src/{components/Image.orig.js → plugins/index.js} +2 -17
- package/src/plugins/language.js +122 -0
- package/src/components/Image.js +0 -52
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2024 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 fetchJson from '../helpers/fetchJson'
|
|
19
|
+
import { Log } from '../lib/log'
|
|
20
|
+
import { reactive } from '../lib/reactivity/reactive'
|
|
21
|
+
|
|
22
|
+
export default {
|
|
23
|
+
name: 'language',
|
|
24
|
+
plugin(options = {}) {
|
|
25
|
+
let translations = {}
|
|
26
|
+
let dictionary = {}
|
|
27
|
+
|
|
28
|
+
const state = reactive({
|
|
29
|
+
language: '',
|
|
30
|
+
loaded: 0,
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
const setLanguage = (language) => {
|
|
34
|
+
// define the dictionary
|
|
35
|
+
dictionary = translations[language] || {}
|
|
36
|
+
// set the current language in the reactive state
|
|
37
|
+
state.language = language
|
|
38
|
+
|
|
39
|
+
// warnings
|
|
40
|
+
if (Object.keys(translations).length === 0) {
|
|
41
|
+
Log.warn(
|
|
42
|
+
'No translations loaded. Please load a file with translations or specify a translations object manually'
|
|
43
|
+
)
|
|
44
|
+
}
|
|
45
|
+
if (language in translations === false) {
|
|
46
|
+
Log.warn(`Language ${language} not available in the loaded translations`)
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const loadLanguageFile = (filePath) => {
|
|
51
|
+
return fetchJson(filePath)
|
|
52
|
+
.then((result) => {
|
|
53
|
+
setTranslations(result)
|
|
54
|
+
})
|
|
55
|
+
.catch((e) => {
|
|
56
|
+
Log.error(e)
|
|
57
|
+
})
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const setTranslations = (translationsObject) => {
|
|
61
|
+
translations = translationsObject
|
|
62
|
+
dictionary = translations[state.language] || {}
|
|
63
|
+
state.loaded++
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if ('file' in options) {
|
|
67
|
+
loadLanguageFile(options.file).then(() => {
|
|
68
|
+
if ('language' in options) {
|
|
69
|
+
setLanguage(options.language)
|
|
70
|
+
}
|
|
71
|
+
})
|
|
72
|
+
} else if ('language' in options) {
|
|
73
|
+
setLanguage(options.language)
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// Public API language plugin
|
|
77
|
+
return {
|
|
78
|
+
translate(key) {
|
|
79
|
+
// reference state.language, to trigger reactive effects for
|
|
80
|
+
// translate functions when language is modified
|
|
81
|
+
state.language
|
|
82
|
+
|
|
83
|
+
// reference state.loaded, to trigger reactive effects for
|
|
84
|
+
// translate functions when language is modified
|
|
85
|
+
state.loaded
|
|
86
|
+
|
|
87
|
+
let replacements = [...arguments].slice(1)
|
|
88
|
+
|
|
89
|
+
// no replacements so just translated string
|
|
90
|
+
if (replacements.length === 0) {
|
|
91
|
+
return (dictionary && dictionary[key]) || key
|
|
92
|
+
} else {
|
|
93
|
+
if (replacements.length === 1 && typeof replacements[0] === 'object') {
|
|
94
|
+
replacements = replacements.pop()
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
return Object.keys(
|
|
98
|
+
// maps array input to an object {0: 'item1', 1: 'item2'}
|
|
99
|
+
Array.isArray(replacements) ? Object.assign({}, replacements) : replacements
|
|
100
|
+
).reduce((text, replacementKey) => {
|
|
101
|
+
return text.replace(
|
|
102
|
+
new RegExp('{\\s?' + replacementKey + '\\s?}', 'g'),
|
|
103
|
+
replacements[replacementKey]
|
|
104
|
+
)
|
|
105
|
+
}, (dictionary && dictionary[key]) || key)
|
|
106
|
+
}
|
|
107
|
+
},
|
|
108
|
+
get language() {
|
|
109
|
+
return state.language
|
|
110
|
+
},
|
|
111
|
+
set(language) {
|
|
112
|
+
setLanguage(language)
|
|
113
|
+
},
|
|
114
|
+
translations(translationsObject) {
|
|
115
|
+
setTranslations(translationsObject)
|
|
116
|
+
},
|
|
117
|
+
load(file) {
|
|
118
|
+
return loadLanguageFile(file)
|
|
119
|
+
},
|
|
120
|
+
}
|
|
121
|
+
},
|
|
122
|
+
}
|
package/src/components/Image.js
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
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
|
-
/* eslint-disable no-unused-vars */
|
|
23
|
-
code: {
|
|
24
|
-
render: function anonymous(parent, component, context, components, effect, getRaw) {
|
|
25
|
-
const elms = []
|
|
26
|
-
let componentType
|
|
27
|
-
const rootComponent = component
|
|
28
|
-
const elementConfig0 = {}
|
|
29
|
-
|
|
30
|
-
elms[0] = this.element({ parent: parent || 'root' }, component)
|
|
31
|
-
|
|
32
|
-
elementConfig0['imageSource'] = component.imageSource
|
|
33
|
-
elms[0].populate(elementConfig0)
|
|
34
|
-
return elms
|
|
35
|
-
},
|
|
36
|
-
effects: [
|
|
37
|
-
function anonymous(component, elms, context, components, rootComponent, effect) {
|
|
38
|
-
elms[0].set('imageSource', component.imageSource)
|
|
39
|
-
},
|
|
40
|
-
],
|
|
41
|
-
context: {},
|
|
42
|
-
},
|
|
43
|
-
props: ['src'],
|
|
44
|
-
computed: {
|
|
45
|
-
imageSource() {
|
|
46
|
-
if (/^(?:https?:)?\/\//i.test(this.src)) {
|
|
47
|
-
return this.src
|
|
48
|
-
}
|
|
49
|
-
return `${window.location.protocol}//${window.location.host}/${this.src}`
|
|
50
|
-
},
|
|
51
|
-
},
|
|
52
|
-
})
|