@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
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# Blits - Lightning 3 App Development Framework
|
|
2
|
+
|
|
3
|
+
## Building Your First Component
|
|
4
|
+
|
|
5
|
+
Components in Blits follow a clearly defined structure, which helps keep your code clean and guides you to quickly build your components.
|
|
6
|
+
|
|
7
|
+
This universal structure is also valuable for the interoperability of components.
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
### Creating a new Component
|
|
11
|
+
|
|
12
|
+
Let's see how to create a new component and explore the basic anatomy of a component.
|
|
13
|
+
|
|
14
|
+
A new component is created using the `Blits.Component()` function. This function accepts two arguments:
|
|
15
|
+
|
|
16
|
+
1. The first argument is the name of the component, which is mainly used for debugging purposes. It's essential to choose a unique and descriptive name for your component, such as `Homepage`, `Loader` or `SidebarMenuItem`.
|
|
17
|
+
|
|
18
|
+
2. The second argument is a configuration object, represented as an `object literal`. This configuration object can contain a predefined set of key-value pairs, including for example:
|
|
19
|
+
|
|
20
|
+
- `template`: to define the template for the component.
|
|
21
|
+
- `state`: to specify the component instance's internal state.
|
|
22
|
+
- `prop`: to define the props that can be passed into the component.
|
|
23
|
+
- `hooks`: allowing you to hook into different lifecycle events of the component.
|
|
24
|
+
- `input`: used to tap into user input.
|
|
25
|
+
|
|
26
|
+
In the next sections, we will go into the details of each of the component configuration options.
|
|
27
|
+
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# Blits - Lightning 3 App Development Framework
|
|
2
|
+
|
|
3
|
+
## Computed properties
|
|
4
|
+
|
|
5
|
+
So far we've learned how to utilize internal state variables and props passed by a parent in (the template of) our component.
|
|
6
|
+
We can even perform simple operations like `Math.max()` or `str.toUpperCase()` directly within an argument of the template.
|
|
7
|
+
|
|
8
|
+
However, sometimes it's more clear and more maintainable to abstract these operations into what we call _computed properties_.
|
|
9
|
+
|
|
10
|
+
Within the computed key of the Component configuration object, you can specify a set of functions. Each function name you define (`offset()` for example) becomes accessible as a computed property.
|
|
11
|
+
|
|
12
|
+
In your template, you can reference these computed properties by prefixing them with a dollar sign (e.g., `$offset`). In the rest of your app's code, you can access these computed properties (but not modify them) using `this.offset`.
|
|
13
|
+
|
|
14
|
+
Within a computed property, you can reference one or more state variables or props and return a value based on calculations or logical operations.
|
|
15
|
+
|
|
16
|
+
Whenever the value of any referenced variable changes, the computed property will automatically recalculate. If a computed property is referenced reactively in the template (i.e., prefixed with colons `:`), it will also trigger an automatic rerender of that portion of the template.
|
|
17
|
+
|
|
18
|
+
Computed properties are a powerful tool for enhancing the readability of your component code. By abstracting complex or frequently used calculations into computed properties, you can make your code (and especially your template) more concise and easier to understand.
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# Blits - Lightning 3 App Development Framework
|
|
2
|
+
|
|
3
|
+
## Getting Started
|
|
4
|
+
|
|
5
|
+
To begin with Blits, follow these simple steps to set up your development environment and create your first Lightning 3 App.
|
|
6
|
+
|
|
7
|
+
### Installation
|
|
8
|
+
|
|
9
|
+
1. Open your terminal or command prompt.
|
|
10
|
+
|
|
11
|
+
2. Run the following command to create a new Lightning 3 App project:
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npx @lightningjs/blits@latest my_lightning3_app
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
This will generate the necessary boilerplate code in the folder `my_lightning3_app` for you to start building your own Lightning 3 App.
|
|
18
|
+
|
|
19
|
+
3. Navigate to the newly created project directory and install the project dependencies:
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
cd my_lightning3_app
|
|
23
|
+
npm install
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
### Running Your App
|
|
27
|
+
|
|
28
|
+
1. After installing the dependencies, you can start your development server by running:
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
npm run dev
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
This command will create an application bundle and launch a development server using Vite.
|
|
35
|
+
|
|
36
|
+
2. Once the server is up and running, open your web browser and navigate to the URL displayed in the console. Congratulations! You now have your brand new Lightning 3 App up and running.
|
|
37
|
+
|
|
38
|
+
### Next steps
|
|
39
|
+
|
|
40
|
+
You are now ready to dive into the world of TV app development using Blits. In the following sections, we will explore the core concepts and guide you through building your TV applications step by step.
|
package/docs/index.html
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8">
|
|
5
|
+
<title>Blits Lightning App Development Framework</title>
|
|
6
|
+
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
|
|
7
|
+
<meta name="description" content="Description">
|
|
8
|
+
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
|
|
9
|
+
<!--link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/docsify-themeable@0/dist/css/theme-simple.css"-->
|
|
10
|
+
<link
|
|
11
|
+
rel="stylesheet"
|
|
12
|
+
href="//cdn.jsdelivr.net/npm/docsify-darklight-theme@latest/dist/style.min.css"
|
|
13
|
+
title="docsify-darklight-theme"
|
|
14
|
+
type="text/css"
|
|
15
|
+
/>
|
|
16
|
+
</head>
|
|
17
|
+
<body>
|
|
18
|
+
<div id="app"></div>
|
|
19
|
+
<script>
|
|
20
|
+
window.$docsify = {
|
|
21
|
+
name: 'Blits <br />L3 App Development Framework',
|
|
22
|
+
repo: 'https://github.com/lightning-js/blits/',
|
|
23
|
+
loadSidebar: true,
|
|
24
|
+
relativePath: true,
|
|
25
|
+
auto2top: true,
|
|
26
|
+
search: {
|
|
27
|
+
maxAge: 24*60*60*1000, // one day
|
|
28
|
+
paths: 'auto',
|
|
29
|
+
placeholder: 'Type to search',
|
|
30
|
+
noData: 'No Results!',
|
|
31
|
+
depth: 6,
|
|
32
|
+
},
|
|
33
|
+
darklightTheme: {
|
|
34
|
+
defaultTheme : 'dark',
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
</script>
|
|
39
|
+
<script src="//unpkg.com/docsify/lib/docsify.min.js"></script>
|
|
40
|
+
<script src="https://cdn.jsdelivr.net/npm/docsify-themeable@0"></script>
|
|
41
|
+
<script
|
|
42
|
+
src="//cdn.jsdelivr.net/npm/docsify-darklight-theme@latest/dist/index.min.js"
|
|
43
|
+
type="text/javascript">
|
|
44
|
+
</script>
|
|
45
|
+
<script src="//unpkg.com/docsify/lib/plugins/search.js"></script>
|
|
46
|
+
</body>
|
|
47
|
+
</html>
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# Blits - Lightning 3 App Development Framework
|
|
2
|
+
|
|
3
|
+
## Hooking into Lifecycle Events
|
|
4
|
+
|
|
5
|
+
In Blits, components follow a defined flow of lifecycle events. Developers can integrate their logic into these events by specifying them in the `hooks` key of the Component configuration object.
|
|
6
|
+
|
|
7
|
+
For each available lifecycle event, you can define a function with the same name as the event itself. This function will execute each time the event is triggered for your component's instance. It's essential to use a regular function instead of an arrow function if you intend to access the `this` scope of your component instance.
|
|
8
|
+
|
|
9
|
+
### Lifecycle Events
|
|
10
|
+
|
|
11
|
+
- **init()**: This event fires when the component is instantiated, just before it sends its render instructions to the Lightning renderer. At this point, the elements of your template won't be available yet.
|
|
12
|
+
|
|
13
|
+
- **ready()**: The `ready` event fires when the component instance is fully initialized and rendered, indicating that it's ready for interaction.
|
|
14
|
+
|
|
15
|
+
- **focus()**: This event triggers whenever the component instance receives focus. It's important to note that this event can fire multiple times during the component's lifecycle, depending on user interactions.
|
|
16
|
+
|
|
17
|
+
- **unfocus()**: The `unfocus` event fires whenever the component instance loses focus. Similar to the `focus` event, it can occur multiple times during the component's lifecycle.
|
|
18
|
+
|
|
19
|
+
- **destroy()**: The `destroy` event fires when the component is being destroyed and removed. This event provides an opportunity to perform any custom cleanup operations before the component is removed.
|
|
20
|
+
|
|
21
|
+
### Example
|
|
22
|
+
|
|
23
|
+
```javascript
|
|
24
|
+
{
|
|
25
|
+
// Other component configurations...
|
|
26
|
+
hooks: {
|
|
27
|
+
init() {
|
|
28
|
+
// Logic to execute on init event
|
|
29
|
+
},
|
|
30
|
+
ready() {
|
|
31
|
+
// Logic to execute on ready event
|
|
32
|
+
},
|
|
33
|
+
focus() {
|
|
34
|
+
// Logic to execute on focus event
|
|
35
|
+
},
|
|
36
|
+
unfocus() {
|
|
37
|
+
// Logic to execute on unfocus event
|
|
38
|
+
},
|
|
39
|
+
destroy() {
|
|
40
|
+
// Logic to execute on destroy event
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
In the provided example, each function within the `hooks` object corresponds to a specific lifecycle event, allowing developers to inject custom logic at different stages of the component's lifecycle.
|
package/docs/props.md
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# Blits - Lightning 3 App Development Framework
|
|
2
|
+
|
|
3
|
+
## Props
|
|
4
|
+
|
|
5
|
+
Components in Blits have their own internal state and logic. However, as each component is part of the larger app's scope, they may need to display different behaviors or appearances based on the rest of the app. To achieve this, components can receive `props` from their parent component.
|
|
6
|
+
|
|
7
|
+
In the Component configuration object, you can specify exactly which props a component can accept. These props are passed to the child component via attributes in the parent component's template. Any attributes not explicitly defined as a prop will be ignored.
|
|
8
|
+
|
|
9
|
+
The `props` key in the Component configuration object should be an `Array`, where each item corresponds to a prop that the component can accept. The simplest way to define props is to list their names within the `props` array.
|
|
10
|
+
|
|
11
|
+
```javascript
|
|
12
|
+
{
|
|
13
|
+
props: ['x', 'color', 'index', 'alpha']
|
|
14
|
+
}
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Once specified, you can refer to these props inside the template of your component using the `$` sign, similar to how you would reference variables defined within your component's state (i.e. `<Element color="$color" />`). Likewise, you can access a prop inside a component's code (e.g., inside the `ready()` lifecycle hook) using `this.color` (note: without a dollar sign!).
|
|
18
|
+
|
|
19
|
+
Since props are used to pass information from a parent to a child, it's important not to attempt to modify props inside your child component. If changes based on the prop from the parent are needed, you can either reference the prop inside the component state (using `this.myprop`) or use the prop in a `computed` property.
|
|
20
|
+
|
|
21
|
+
For more advanced usage, you can define props using an array of objects for each prop. Within each prop object, you can:
|
|
22
|
+
|
|
23
|
+
- Specify a _default value_ for the prop if it's omitted.
|
|
24
|
+
- _Validate_ the value of the prop based on certain criteria.
|
|
25
|
+
- Mark the prop as _required_.
|
|
26
|
+
- Apply a `cast` function to modify the value passed as a prop.
|
|
27
|
+
|
|
28
|
+
```javascript
|
|
29
|
+
{
|
|
30
|
+
props: [
|
|
31
|
+
{
|
|
32
|
+
key: 'alpha',
|
|
33
|
+
default: 0.5,
|
|
34
|
+
required: true,
|
|
35
|
+
validate(v) {
|
|
36
|
+
return v <= 1 && v >= 0;
|
|
37
|
+
},
|
|
38
|
+
cast: Number
|
|
39
|
+
}
|
|
40
|
+
]
|
|
41
|
+
}
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
You can mix and match the simple string notation with the more advanced object notation within the same `props` array.
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# Blits - Lightning 3 App Development Framework
|
|
2
|
+
|
|
3
|
+
## Template structure
|
|
4
|
+
|
|
5
|
+
Blits uses an easy-to-read XML-style template syntax. The syntax is inspired by frameworks like VueJS, so developers familiar with Vue will recognize certain concepts.
|
|
6
|
+
|
|
7
|
+
The template key in the configuration object holds a string with an XML-like structure. Templates often span multiple lines, so it's advisable to use a JS template literal.
|
|
8
|
+
|
|
9
|
+
You can use different tags in your templates. And similar to HTML you can use arguments and nested tags. Self-closing tags and HTML-style comments are also supported.
|
|
10
|
+
|
|
11
|
+
The default tag within a template is the `<Element>` tag, which corresponds to a node in the Lightning 3 renderer. For each element, you can define a set of predefined render properties, such as `x`, `y`, `w`, `color`, and more. Detailed information regarding the properties supported by the <Element> tag can be found here.
|
|
12
|
+
|
|
13
|
+
As your component grows in complexity, you may want to organize your template with custom components, abstracting both templates and logic. Inside a component template, you can utilize sub-components (i.e. a `Menu` component) and reference them with tags like `<Menu></Menu>`.
|
|
14
|
+
|
|
15
|
+
Consider the following template example:
|
|
16
|
+
|
|
17
|
+
```xml
|
|
18
|
+
<Element x="20" y="20">
|
|
19
|
+
<Element w="100" h="100" x="360" color="#0891b2" />
|
|
20
|
+
<Element w="$width" h="$height" color="$color" />
|
|
21
|
+
<Element :w="$changingWidth" :h="Math.floor($height / 5)" :color="$highlight" />
|
|
22
|
+
</Element>
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
In this template, you'll observe certain arguments with hardcoded values. You use these to configure the parts of your component that never change.
|
|
26
|
+
|
|
27
|
+
Additionally, some arguments contain a value prefixed with a dollar sign (`$`), representing _dynamic_ arguments. When the component renders, it automatically populates these dynamic values based on the component's state (or props or computed properties).
|
|
28
|
+
|
|
29
|
+
Furthermore, certain arguments are prefixed with a colon sign (`:`), indicating _reactive_ arguments. These are not only dynamically set when your component renders, but also _rerender_ the corresponding part of the template whenever the referenced value in your component's internal state changes. This reactive data binding eliminates the need for manual template patching, as seen in Lightning 2.
|
|
30
|
+
|
|
31
|
+
Reactive arguments support _interpolation_, enabling the use of simple JavaScript instructions, such as ternary conditions or basic string and Math manipulations. For more complex logic, it's recommended to abstract this into a Component method or a Computed property.
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
# Blits - Lightning 3 App Development Framework
|
|
2
|
+
|
|
3
|
+
## Handling User Input
|
|
4
|
+
|
|
5
|
+
You don't want your Lightning 3 App to be completely static, instead users should be able to navigate and interact with the app, often using devices like a remote control.
|
|
6
|
+
|
|
7
|
+
Blits offers a straightforward interface to handle user input for each component.
|
|
8
|
+
|
|
9
|
+
### Configuring Input Handling
|
|
10
|
+
|
|
11
|
+
Within the Component configuration object, the `input` key is utilized to define how the component should react to specific key presses when it has focus. It should contain an object of functions that specify the actions to take based on key presses.
|
|
12
|
+
|
|
13
|
+
Each function should correspond to a key name, such as `up`, `down`, `enter`, `space`, `back`, `1`, `2`, `a` etc. Each function defined in the `input` object receives the full `InputEvent` object as its first argument.
|
|
14
|
+
|
|
15
|
+
```javascript
|
|
16
|
+
{
|
|
17
|
+
input: {
|
|
18
|
+
up() {
|
|
19
|
+
// Logic to execute when users press up
|
|
20
|
+
},
|
|
21
|
+
down() {
|
|
22
|
+
// Logic to execute when users press down
|
|
23
|
+
},
|
|
24
|
+
enter() {
|
|
25
|
+
// Logic to execute when users press enter
|
|
26
|
+
},
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
### Event Handling Chain
|
|
32
|
+
|
|
33
|
+
If the currently focused component does not handle a key press, the framework will traverse up the component hierarchy, checking if any parent components have defined functions for that key press in their `input`-object. This event handling chain continues until it reaches the root Application.
|
|
34
|
+
|
|
35
|
+
When a component handles a key press by having a corresponding function specified, the event handling chain stops by default. However, if you want the input event to propagate up the hierarchy, you can set focus to the parent element and pass the `InputEvent` object on in the function call.
|
|
36
|
+
|
|
37
|
+
```javascript
|
|
38
|
+
{
|
|
39
|
+
input: {
|
|
40
|
+
enter() {
|
|
41
|
+
// Give focus to the parent
|
|
42
|
+
this.parent.focus();
|
|
43
|
+
},
|
|
44
|
+
back(e) {
|
|
45
|
+
// Give focus to the parent and let the user input event bubble
|
|
46
|
+
this.parent.focus(e);
|
|
47
|
+
},
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
### Catch-All Handling
|
|
53
|
+
|
|
54
|
+
To allow a focused component to respond to any key and act as a catch-all, you can add an `any()` function to the input object.
|
|
55
|
+
|
|
56
|
+
```javascript
|
|
57
|
+
{
|
|
58
|
+
input: {
|
|
59
|
+
any() {
|
|
60
|
+
// Logic to execute for any key press
|
|
61
|
+
},
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
```
|
package/docs/watchers.md
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# Blits - Lightning 3 App Development Framework
|
|
2
|
+
|
|
3
|
+
## Watching for Changes
|
|
4
|
+
|
|
5
|
+
In some cases, you may want to execute specific actions whenever the value of a state variable, a prop, or a computed property changes. These actions could involve dispatching an event or updating another state variable.
|
|
6
|
+
|
|
7
|
+
You might be tempted to handle this functionality inside a computed property, but this is not recommended. Computed properties should not have side effects, as side effects could potentially lead your app into an endless loop if not handled carefully.
|
|
8
|
+
|
|
9
|
+
Instead, Blits allows you to specify **watchers**.
|
|
10
|
+
|
|
11
|
+
### Using Watchers
|
|
12
|
+
|
|
13
|
+
Within the `watch` key of the Component configuration object, you can define an object of _watcher functions_.
|
|
14
|
+
|
|
15
|
+
The name of each function should correspond to the name of the internal state variable, prop, or computed property that you want to watch. Whenever the target value changes, the respective watcher function will be invoked.
|
|
16
|
+
|
|
17
|
+
The watcher function receives two arguments: the new value and the old value of the observed property. This allows you to perform specific actions based on the changes.
|
|
18
|
+
|
|
19
|
+
### Example:
|
|
20
|
+
|
|
21
|
+
```javascript
|
|
22
|
+
{
|
|
23
|
+
state() {
|
|
24
|
+
return {
|
|
25
|
+
alpha: 0.2
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
watchers: {
|
|
29
|
+
alpha(value, oldValue) {
|
|
30
|
+
if(value > oldValue) {
|
|
31
|
+
// Execute some logic when the 'alpha' value increases
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
In this example, whenever the 'alpha' value changes, the watcher function associated with 'alpha' will be invoked. The function checks if the new value is greater than the old value and executes custom logic accordingly.
|
package/index.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
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 './src/component.js'
|
|
19
|
+
import Application from './src/application.js'
|
|
20
|
+
import Launch from './src/launch.js'
|
|
21
|
+
|
|
22
|
+
export default {
|
|
23
|
+
Component,
|
|
24
|
+
Application,
|
|
25
|
+
Launch,
|
|
26
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@lightningjs/blits",
|
|
3
|
+
"version": "0.3.0",
|
|
4
|
+
"description": "Blits: The Lightning 3 App Development Framework",
|
|
5
|
+
"bin": "bin/index.cjs",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": "./index.js",
|
|
8
|
+
"./vite": "./vite/index.js"
|
|
9
|
+
},
|
|
10
|
+
"scripts": {
|
|
11
|
+
"test": "tape '{,!(node_modules)/**/}*.test.js' | tap-diff",
|
|
12
|
+
"lint": "eslint '**/*.js'",
|
|
13
|
+
"lint:fix": "eslint '**/*.js' --fix"
|
|
14
|
+
},
|
|
15
|
+
"lint-staged": {
|
|
16
|
+
"*.js": [
|
|
17
|
+
"eslint --fix"
|
|
18
|
+
]
|
|
19
|
+
},
|
|
20
|
+
"husky": {
|
|
21
|
+
"hooks": {
|
|
22
|
+
"pre-commit": "lint-staged"
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
"type": "module",
|
|
26
|
+
"author": "Michiel van der Geest <hello@michielvandergeest.com>",
|
|
27
|
+
"license": "Apache-2.0",
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"babel-eslint": "^10.1.0",
|
|
30
|
+
"eslint": "^8.8.0",
|
|
31
|
+
"eslint-config-prettier": "^8.3.0",
|
|
32
|
+
"eslint-plugin-prettier": "^4.0.0",
|
|
33
|
+
"esm": "^3.2.25",
|
|
34
|
+
"husky": "^7.0.4",
|
|
35
|
+
"lint-staged": "^12.3.3",
|
|
36
|
+
"prettier": "^2.5.1",
|
|
37
|
+
"tap-diff": "^0.1.1",
|
|
38
|
+
"tape": "^5.5.0"
|
|
39
|
+
},
|
|
40
|
+
"dependencies": {
|
|
41
|
+
"@lightningjs/renderer": "^0.3.0",
|
|
42
|
+
"@lightningjs/vite-plugin-import-chunk-url": "^0.3.0"
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
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
|
+
import Focus from './focus.js'
|
|
21
|
+
|
|
22
|
+
const Application = (config) => {
|
|
23
|
+
// make configurable?
|
|
24
|
+
const mapping = {
|
|
25
|
+
ArrowLeft: 'left',
|
|
26
|
+
ArrowRight: 'right',
|
|
27
|
+
ArrowUp: 'up',
|
|
28
|
+
ArrowDown: 'down',
|
|
29
|
+
Enter: 'enter',
|
|
30
|
+
' ': 'space',
|
|
31
|
+
Backspace: 'back',
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const handler = (e) => {
|
|
35
|
+
const key = mapping[e.key] || e.key
|
|
36
|
+
Focus.input(key, e)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
document.addEventListener('keydown', handler)
|
|
40
|
+
|
|
41
|
+
config.hooks = config.hooks || {}
|
|
42
|
+
config.hooks.___init = function () {
|
|
43
|
+
Focus.set(this)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
config.hooks.___destroy = function () {
|
|
47
|
+
document.removeEventListener('keydown', handler)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const App = Component('App', config)
|
|
51
|
+
|
|
52
|
+
return App
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export default Application
|