@lightningjs/blits 0.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/.editorconfig +7 -0
- package/.eslintignore +1 -0
- package/.eslintrc.cjs +60 -0
- package/.vscode/extensions.json +6 -0
- package/.vscode/settings.json +9 -0
- package/LICENSE +202 -0
- package/NOTICE +3 -0
- package/README.md +11 -0
- package/bin/index.cjs +25 -0
- package/boilerplate/.editorconfig +7 -0
- package/boilerplate/.eslintignore +3 -0
- package/boilerplate/.eslintrc.js +38 -0
- package/boilerplate/.vscode/extensions.json +7 -0
- package/boilerplate/.vscode/launch.json +12 -0
- package/boilerplate/.vscode/settings.json +9 -0
- package/boilerplate/index.html +11 -0
- package/boilerplate/package.json +36 -0
- package/boilerplate/public/assets/logo.png +0 -0
- package/boilerplate/src/App.js +12 -0
- package/boilerplate/src/components/Loader.js +23 -0
- package/boilerplate/src/index.js +11 -0
- package/boilerplate/src/pages/Home.js +15 -0
- package/boilerplate/src/renderer.js +3 -0
- package/boilerplate/vite.config.js +23 -0
- package/docs/.nojekyll +0 -0
- package/docs/README.md +30 -0
- package/docs/_sidebar.md +9 -0
- package/docs/component_state.md +21 -0
- package/docs/components.md +27 -0
- package/docs/computed_properties.md +18 -0
- package/docs/getting_started.md +40 -0
- package/docs/index.html +47 -0
- package/docs/lifecycle_events.md +46 -0
- package/docs/props.md +44 -0
- package/docs/template_syntax.md +31 -0
- package/docs/user_input.md +64 -0
- package/docs/watchers.md +38 -0
- package/index.js +26 -0
- package/package.json +44 -0
- package/src/application.js +55 -0
- package/src/component.js +192 -0
- package/src/component.test.js +51 -0
- package/src/components/Circle.js +31 -0
- package/src/components/Image.js +33 -0
- package/src/components/RouterView.js +38 -0
- package/src/components/Sprite.js +56 -0
- package/src/components/Text.js +61 -0
- package/src/element.js +236 -0
- package/src/focus.js +65 -0
- package/src/helpers/sequence.js +26 -0
- package/src/launch.js +61 -0
- package/src/lib/codegenerator/generator.js +276 -0
- package/src/lib/codegenerator/generator.test.js +970 -0
- package/src/lib/colors/colors.js +70 -0
- package/src/lib/colors/colors.test.js +190 -0
- package/src/lib/colors/htmlColors.js +168 -0
- package/src/lib/componentId.js +27 -0
- package/src/lib/componentId.test.js +83 -0
- package/src/lib/eventListeners.js +55 -0
- package/src/lib/hooks.js +29 -0
- package/src/lib/log.js +106 -0
- package/src/lib/reactivity/effect.js +54 -0
- package/src/lib/reactivity/effect.test.js +35 -0
- package/src/lib/reactivity/reactive.js +113 -0
- package/src/lib/reactivity/reactive.test.js +27 -0
- package/src/lib/setup/base.js +218 -0
- package/src/lib/setup/computed.js +43 -0
- package/src/lib/setup/input.js +28 -0
- package/src/lib/setup/methods.js +35 -0
- package/src/lib/setup/props.js +53 -0
- package/src/lib/setup/props.test.js +205 -0
- package/src/lib/setup/routes.js +24 -0
- package/src/lib/setup/state.js +45 -0
- package/src/lib/setup/watch.js +33 -0
- package/src/lib/templateparser/parser.js +103 -0
- package/src/lib/templateparser/parser.test.js +769 -0
- package/src/router.js +67 -0
- package/src/settings.js +34 -0
- package/vite/index.js +1 -0
package/src/lib/log.js
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
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 Settings from '../settings.js'
|
|
19
|
+
|
|
20
|
+
const n = () => {}
|
|
21
|
+
|
|
22
|
+
const time = () =>
|
|
23
|
+
new Date().toLocaleTimeString([], {
|
|
24
|
+
hour: '2-digit',
|
|
25
|
+
minute: '2-digit',
|
|
26
|
+
second: '2-digit',
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
const logger = (context) => {
|
|
30
|
+
const level = Settings.get('debugLevel')
|
|
31
|
+
const log = {}
|
|
32
|
+
|
|
33
|
+
Object.defineProperty(log, 'info', {
|
|
34
|
+
get() {
|
|
35
|
+
return (
|
|
36
|
+
((level >= 1 || (Array.isArray(level) && level.indexOf('info') > -1)) &&
|
|
37
|
+
console.info.bind(
|
|
38
|
+
window.console,
|
|
39
|
+
`%c ⚡️ ${context} %c ${time()}`,
|
|
40
|
+
'background-color: #0284c7; color: white; padding: 3px 6px 3px 1px; border-radius: 3px',
|
|
41
|
+
'color: ##94a3b8;'
|
|
42
|
+
)) ||
|
|
43
|
+
n
|
|
44
|
+
)
|
|
45
|
+
},
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
Object.defineProperty(log, 'warn', {
|
|
49
|
+
get() {
|
|
50
|
+
return (
|
|
51
|
+
((level >= 1 || (Array.isArray(level) && level.indexOf('warn') > -1)) &&
|
|
52
|
+
console.warn.bind(
|
|
53
|
+
window.console,
|
|
54
|
+
`%c ⚡️ ${context} %c ${time()}`,
|
|
55
|
+
'background-color: #fbbf24; color: white; padding: 3px 6px 3px 1px; border-radius: 3px',
|
|
56
|
+
'color: ##94a3b8;'
|
|
57
|
+
)) ||
|
|
58
|
+
n
|
|
59
|
+
)
|
|
60
|
+
},
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
Object.defineProperty(log, 'error', {
|
|
64
|
+
get() {
|
|
65
|
+
return (
|
|
66
|
+
((level >= 1 || (Array.isArray(level) && level.indexOf('error') > -1)) &&
|
|
67
|
+
console.error.bind(
|
|
68
|
+
window.console,
|
|
69
|
+
`%c ⚡️ ${context} %c ${time()}`,
|
|
70
|
+
'background-color: #dc2626; color: white; padding: 3px 6px 3px 1px; border-radius: 3px',
|
|
71
|
+
'color: ##94a3b8;'
|
|
72
|
+
)) ||
|
|
73
|
+
n
|
|
74
|
+
)
|
|
75
|
+
},
|
|
76
|
+
})
|
|
77
|
+
|
|
78
|
+
Object.defineProperty(log, 'debug', {
|
|
79
|
+
get() {
|
|
80
|
+
return (
|
|
81
|
+
((level >= 2 || (Array.isArray(level) && level.indexOf('debug') > -1)) &&
|
|
82
|
+
console.debug.bind(
|
|
83
|
+
window.console,
|
|
84
|
+
`%c ⚡️ ${context} %c (${new Date().toLocaleTimeString([], {
|
|
85
|
+
hour: '2-digit',
|
|
86
|
+
minute: '2-digit',
|
|
87
|
+
second: '2-digit',
|
|
88
|
+
})})`,
|
|
89
|
+
'background-color: #e2e8f0; color: #334155; padding: 3px 6px 3px 1px; border-radius: 3px',
|
|
90
|
+
'color: ##94a3b8;'
|
|
91
|
+
)) ||
|
|
92
|
+
n
|
|
93
|
+
)
|
|
94
|
+
},
|
|
95
|
+
})
|
|
96
|
+
|
|
97
|
+
return log
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export default logger
|
|
101
|
+
|
|
102
|
+
export let Log
|
|
103
|
+
// review this pattern
|
|
104
|
+
export const initLog = () => {
|
|
105
|
+
Log = logger('Blits')
|
|
106
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
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
|
+
let currentEffect = null
|
|
19
|
+
const objectMap = new WeakMap()
|
|
20
|
+
|
|
21
|
+
export const track = (target, key) => {
|
|
22
|
+
if (currentEffect) {
|
|
23
|
+
let effectsMap = objectMap.get(target)
|
|
24
|
+
if (!effectsMap) {
|
|
25
|
+
effectsMap = new Map()
|
|
26
|
+
objectMap.set(target, effectsMap)
|
|
27
|
+
}
|
|
28
|
+
let effects = effectsMap.get(key)
|
|
29
|
+
if (!effects) {
|
|
30
|
+
effects = new Set()
|
|
31
|
+
effectsMap.set(key, effects)
|
|
32
|
+
}
|
|
33
|
+
effects.add(currentEffect)
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export const trigger = (target, key) => {
|
|
38
|
+
const effectsMap = objectMap.get(target)
|
|
39
|
+
if (!effectsMap) {
|
|
40
|
+
return
|
|
41
|
+
}
|
|
42
|
+
const effects = effectsMap.get(key)
|
|
43
|
+
if (effects) {
|
|
44
|
+
effects.forEach((effect) => {
|
|
45
|
+
effect()
|
|
46
|
+
})
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export const effect = (effect) => {
|
|
51
|
+
currentEffect = effect
|
|
52
|
+
currentEffect()
|
|
53
|
+
currentEffect = null
|
|
54
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
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 test from 'tape'
|
|
19
|
+
import { trigger, track } from './effect.js'
|
|
20
|
+
|
|
21
|
+
test('Trigger - type', (assert) => {
|
|
22
|
+
const expected = 'function'
|
|
23
|
+
const actual = typeof trigger
|
|
24
|
+
|
|
25
|
+
assert.equal(actual, expected, 'Trigger should be a function')
|
|
26
|
+
assert.end()
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
test('Track type', (assert) => {
|
|
30
|
+
const expected = 'function'
|
|
31
|
+
const actual = typeof track
|
|
32
|
+
|
|
33
|
+
assert.equal(actual, expected, 'Track should be a function')
|
|
34
|
+
assert.end()
|
|
35
|
+
})
|
|
@@ -0,0 +1,113 @@
|
|
|
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 { track, trigger } from './effect.js'
|
|
19
|
+
|
|
20
|
+
const arrayMethods = [
|
|
21
|
+
'constructor',
|
|
22
|
+
'includes',
|
|
23
|
+
'indexOf',
|
|
24
|
+
'lastIndexOf',
|
|
25
|
+
'push',
|
|
26
|
+
'pop',
|
|
27
|
+
'shift',
|
|
28
|
+
'splice',
|
|
29
|
+
'unshift',
|
|
30
|
+
]
|
|
31
|
+
const reactiveProxy = (target) => {
|
|
32
|
+
const handler = {
|
|
33
|
+
get(target, key, receiver) {
|
|
34
|
+
if (Array.isArray(target) && arrayMethods.includes(key)) {
|
|
35
|
+
return Reflect.get(target, key, receiver)
|
|
36
|
+
}
|
|
37
|
+
track(target, key)
|
|
38
|
+
|
|
39
|
+
if (typeof target[key] === 'object') {
|
|
40
|
+
return reactiveProxy(target[key])
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return Reflect.get(target, key, receiver)
|
|
44
|
+
},
|
|
45
|
+
set(target, key, value, receiver) {
|
|
46
|
+
const oldValue = target[key]
|
|
47
|
+
|
|
48
|
+
const result = Reflect.set(target, key, value, receiver)
|
|
49
|
+
|
|
50
|
+
if (typeof result === 'object') {
|
|
51
|
+
reactiveProxy(target[key])
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (key === 'length') {
|
|
55
|
+
trigger(target, key)
|
|
56
|
+
} else {
|
|
57
|
+
if (result && oldValue !== value) {
|
|
58
|
+
trigger(target, key)
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return result
|
|
62
|
+
},
|
|
63
|
+
}
|
|
64
|
+
return new Proxy(target, handler)
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const reactiveDefineProperty = (target) => {
|
|
68
|
+
Object.keys(target).forEach((key) => {
|
|
69
|
+
let internalValue = target[key]
|
|
70
|
+
|
|
71
|
+
// can be improved
|
|
72
|
+
if (typeof target[key] === 'object') {
|
|
73
|
+
return reactiveDefineProperty(target[key])
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
Object.defineProperty(target, key, {
|
|
77
|
+
enumerable: true, // ?
|
|
78
|
+
configurable: true, // ?
|
|
79
|
+
get() {
|
|
80
|
+
track(target, key)
|
|
81
|
+
return internalValue
|
|
82
|
+
},
|
|
83
|
+
set(newValue) {
|
|
84
|
+
let oldValue = internalValue
|
|
85
|
+
if (oldValue !== newValue) {
|
|
86
|
+
internalValue = newValue
|
|
87
|
+
trigger(target, key)
|
|
88
|
+
}
|
|
89
|
+
},
|
|
90
|
+
})
|
|
91
|
+
})
|
|
92
|
+
|
|
93
|
+
return target
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// maybe an options object?
|
|
97
|
+
export const reactive = (target, type = 'proxy') => {
|
|
98
|
+
return type === 'proxy' ? reactiveProxy(target) : reactiveDefineProperty(target)
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export const memo = (raw) => {
|
|
102
|
+
const r = {
|
|
103
|
+
get value() {
|
|
104
|
+
track(r, 'value')
|
|
105
|
+
return raw
|
|
106
|
+
},
|
|
107
|
+
set value(v) {
|
|
108
|
+
raw = v
|
|
109
|
+
trigger(r, 'value')
|
|
110
|
+
},
|
|
111
|
+
}
|
|
112
|
+
return r
|
|
113
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
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 test from 'tape'
|
|
19
|
+
import { reactive } from './reactive.js'
|
|
20
|
+
|
|
21
|
+
test('Type', (assert) => {
|
|
22
|
+
const expected = 'function'
|
|
23
|
+
const actual = typeof reactive
|
|
24
|
+
|
|
25
|
+
assert.equal(actual, expected, 'Reactive should be a function')
|
|
26
|
+
assert.end()
|
|
27
|
+
})
|
|
@@ -0,0 +1,218 @@
|
|
|
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 { renderer } from '../../launch.js'
|
|
19
|
+
import Focus from '../../focus.js'
|
|
20
|
+
import { to } from '../../router.js'
|
|
21
|
+
import Image from '../../components/Image.js'
|
|
22
|
+
import Circle from '../../components/Circle.js'
|
|
23
|
+
import RouterView from '../../components/RouterView.js'
|
|
24
|
+
import Sprite from '../../components/Sprite.js'
|
|
25
|
+
import Text from '../../components/Text.js'
|
|
26
|
+
import eventListeners from '../eventListeners.js'
|
|
27
|
+
import { default as log, Log } from '../log.js'
|
|
28
|
+
|
|
29
|
+
const shaders = {
|
|
30
|
+
radius: 'radius',
|
|
31
|
+
rounded: 'radius',
|
|
32
|
+
border: 'border',
|
|
33
|
+
borderTop: 'borderTop',
|
|
34
|
+
glitch: 'glitch',
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export default (component) => {
|
|
38
|
+
Object.defineProperties(component.prototype, {
|
|
39
|
+
focus: {
|
|
40
|
+
value: function (e) {
|
|
41
|
+
Focus.set(this, e)
|
|
42
|
+
},
|
|
43
|
+
writable: false,
|
|
44
|
+
enumerable: true,
|
|
45
|
+
configurable: false,
|
|
46
|
+
},
|
|
47
|
+
unfocus: {
|
|
48
|
+
value: function () {
|
|
49
|
+
this.lifecycle.state = 'unfocus'
|
|
50
|
+
},
|
|
51
|
+
writable: false,
|
|
52
|
+
enumerable: true,
|
|
53
|
+
configurable: false,
|
|
54
|
+
},
|
|
55
|
+
destroy: {
|
|
56
|
+
value: function () {
|
|
57
|
+
this.lifecycle.state = 'destroy'
|
|
58
|
+
for (let i = 0; i < this.___timeouts.length; i++) {
|
|
59
|
+
clearTimeout(this.___timeouts[i])
|
|
60
|
+
}
|
|
61
|
+
for (let i = 0; i < this.___intervals.length; i++) {
|
|
62
|
+
clearInterval(this.___intervals[i])
|
|
63
|
+
}
|
|
64
|
+
eventListeners.removeListeners(this)
|
|
65
|
+
deleteChildren(this.___children)
|
|
66
|
+
Log.debug(`Destroyed component ${this.componentId}`)
|
|
67
|
+
},
|
|
68
|
+
writable: false,
|
|
69
|
+
enumerable: true,
|
|
70
|
+
configurable: false,
|
|
71
|
+
},
|
|
72
|
+
select: {
|
|
73
|
+
value: function (id) {
|
|
74
|
+
let selected = null
|
|
75
|
+
this.___children.forEach((child) => {
|
|
76
|
+
if (Array.isArray(child)) {
|
|
77
|
+
child.forEach((c) => {
|
|
78
|
+
if (c['id'] === id) selected = c
|
|
79
|
+
})
|
|
80
|
+
} else {
|
|
81
|
+
if (child['id'] === id) selected = child
|
|
82
|
+
}
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
return selected
|
|
86
|
+
},
|
|
87
|
+
writable: false,
|
|
88
|
+
enumerable: true,
|
|
89
|
+
configurable: false,
|
|
90
|
+
},
|
|
91
|
+
shader: {
|
|
92
|
+
value: function (type, args) {
|
|
93
|
+
if (type in shaders) {
|
|
94
|
+
return {
|
|
95
|
+
type: shaders[type],
|
|
96
|
+
props: args,
|
|
97
|
+
}
|
|
98
|
+
} else {
|
|
99
|
+
Log.error(`Shader ${type} not found`)
|
|
100
|
+
}
|
|
101
|
+
},
|
|
102
|
+
writable: false,
|
|
103
|
+
enumerable: false,
|
|
104
|
+
configurable: false,
|
|
105
|
+
},
|
|
106
|
+
$router: {
|
|
107
|
+
value: {
|
|
108
|
+
to,
|
|
109
|
+
},
|
|
110
|
+
writable: false,
|
|
111
|
+
enumerable: true,
|
|
112
|
+
configurable: false,
|
|
113
|
+
},
|
|
114
|
+
___components: {
|
|
115
|
+
value: {
|
|
116
|
+
Image: Image(),
|
|
117
|
+
Circle: Circle(),
|
|
118
|
+
RouterView: RouterView(),
|
|
119
|
+
Sprite: Sprite(),
|
|
120
|
+
Text: Text(),
|
|
121
|
+
},
|
|
122
|
+
writable: false,
|
|
123
|
+
enumerable: false,
|
|
124
|
+
configurable: false,
|
|
125
|
+
},
|
|
126
|
+
___timeouts: {
|
|
127
|
+
value: [],
|
|
128
|
+
writable: false,
|
|
129
|
+
enumerable: false,
|
|
130
|
+
configurable: false,
|
|
131
|
+
},
|
|
132
|
+
$setTimeout: {
|
|
133
|
+
value: function (fn, ms, ...params) {
|
|
134
|
+
const timeoutId = setTimeout(
|
|
135
|
+
() => {
|
|
136
|
+
this.____timeouts = this.___timeouts.filter((id) => id !== timeoutId)
|
|
137
|
+
fn.apply(null, params)
|
|
138
|
+
},
|
|
139
|
+
ms,
|
|
140
|
+
params
|
|
141
|
+
)
|
|
142
|
+
this.___timeouts.push(timeoutId)
|
|
143
|
+
return timeoutId
|
|
144
|
+
},
|
|
145
|
+
writable: false,
|
|
146
|
+
enumerable: true,
|
|
147
|
+
configurable: false,
|
|
148
|
+
},
|
|
149
|
+
___intervals: {
|
|
150
|
+
value: [],
|
|
151
|
+
writable: false,
|
|
152
|
+
enumerable: false,
|
|
153
|
+
configurable: false,
|
|
154
|
+
},
|
|
155
|
+
$setInterval: {
|
|
156
|
+
value: function (fn, ms, ...params) {
|
|
157
|
+
const intervalId = setInterval(
|
|
158
|
+
() => {
|
|
159
|
+
this.____intervals = this.___intervals.filter((id) => id !== intervalId)
|
|
160
|
+
fn.apply(null, params)
|
|
161
|
+
},
|
|
162
|
+
ms,
|
|
163
|
+
params
|
|
164
|
+
)
|
|
165
|
+
this.___intervals.push(intervalId)
|
|
166
|
+
return intervalId
|
|
167
|
+
},
|
|
168
|
+
writable: false,
|
|
169
|
+
enumerable: true,
|
|
170
|
+
configurable: false,
|
|
171
|
+
},
|
|
172
|
+
$emit: {
|
|
173
|
+
value: function (event, params) {
|
|
174
|
+
eventListeners.executeListeners(event, params)
|
|
175
|
+
},
|
|
176
|
+
writable: false,
|
|
177
|
+
enumerable: true,
|
|
178
|
+
configurable: false,
|
|
179
|
+
},
|
|
180
|
+
$listen: {
|
|
181
|
+
value: function (event, callback) {
|
|
182
|
+
eventListeners.registerListener(this, event, callback)
|
|
183
|
+
},
|
|
184
|
+
writable: false,
|
|
185
|
+
enumerable: true,
|
|
186
|
+
configurable: false,
|
|
187
|
+
},
|
|
188
|
+
___renderer: {
|
|
189
|
+
value: renderer,
|
|
190
|
+
writable: false,
|
|
191
|
+
enumerable: false,
|
|
192
|
+
configurable: false,
|
|
193
|
+
},
|
|
194
|
+
$log: {
|
|
195
|
+
value: log('App'),
|
|
196
|
+
writable: false,
|
|
197
|
+
enumerable: false,
|
|
198
|
+
configurable: false,
|
|
199
|
+
},
|
|
200
|
+
})
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
const deleteChildren = function (children) {
|
|
204
|
+
for (let i = 0; i < children.length; i++) {
|
|
205
|
+
if (!children[i]) return
|
|
206
|
+
if (Array.isArray(children[i])) {
|
|
207
|
+
deleteChildren(children[i])
|
|
208
|
+
} else if (children[i].delete) {
|
|
209
|
+
children[i].delete()
|
|
210
|
+
} else if (children[i].destroy) {
|
|
211
|
+
children[i].destroy()
|
|
212
|
+
children[i] = null
|
|
213
|
+
}
|
|
214
|
+
children[i] = null
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
children = []
|
|
218
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
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 { Log } from '../log.js'
|
|
19
|
+
|
|
20
|
+
export default (component, computeds) => {
|
|
21
|
+
component.___computedKeys = []
|
|
22
|
+
|
|
23
|
+
for (let computed in computeds) {
|
|
24
|
+
// test for reserved keys?
|
|
25
|
+
if (component.___stateKeys && component.___stateKeys.indexOf(computed) > -1) {
|
|
26
|
+
Log.error(`${computed} already exists as a prop`)
|
|
27
|
+
} else if (component.___propKeys && component.___propKeys.indexOf(computed) > -1) {
|
|
28
|
+
Log.error(`${computed} already exists as a prop`)
|
|
29
|
+
} else if (component.___methodKeys && component.___methodKeys.indexOf(computed) > -1) {
|
|
30
|
+
Log.error(`${computed} already exists as a method`)
|
|
31
|
+
} else {
|
|
32
|
+
if (typeof computeds[computed] !== 'function') {
|
|
33
|
+
Log.warn(`${computed} is not a function`)
|
|
34
|
+
}
|
|
35
|
+
component.___computedKeys.push(computed)
|
|
36
|
+
Object.defineProperty(component.prototype, computed, {
|
|
37
|
+
get() {
|
|
38
|
+
return computeds[computed].apply(this)
|
|
39
|
+
},
|
|
40
|
+
})
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
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 { Log } from '../log.js'
|
|
19
|
+
|
|
20
|
+
export default (component, input) => {
|
|
21
|
+
component.prototype.___inputEvents = []
|
|
22
|
+
Object.keys(input).forEach((key) => {
|
|
23
|
+
if (typeof input[key] !== 'function') {
|
|
24
|
+
Log.warn(`${input[key]} is not a function`)
|
|
25
|
+
}
|
|
26
|
+
component.prototype.___inputEvents[key] = input[key]
|
|
27
|
+
})
|
|
28
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
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 { Log } from '../log.js'
|
|
19
|
+
|
|
20
|
+
export default (component, methods) => {
|
|
21
|
+
component.___methodsKeys = []
|
|
22
|
+
|
|
23
|
+
for (let method in methods) {
|
|
24
|
+
// test for reserved keys?
|
|
25
|
+
if (component.___propKeys && component.___propKeys.indexOf(method) > -1) {
|
|
26
|
+
Log.error(`${method} already exists as a prop`)
|
|
27
|
+
} else {
|
|
28
|
+
if (typeof methods[method] !== 'function') {
|
|
29
|
+
Log.warn(`${method} is not a function`)
|
|
30
|
+
}
|
|
31
|
+
component.___methodsKeys.push(method)
|
|
32
|
+
component.prototype[method] = methods[method]
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|