apprun 3.28.8 → 3.28.9
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 +4 -2
- package/README.md +8 -40
- package/WHATSNEW.md +6 -6
- package/apprun-cli.js +3 -221
- package/dist/apprun-html.esm.js +3 -3
- package/dist/apprun-html.esm.js.map +1 -1
- package/dist/apprun-html.js +1 -1
- package/dist/apprun-html.js.map +1 -1
- package/esm/vdom-lit-html.js +2 -0
- package/esm/vdom-lit-html.js.map +1 -1
- package/package.json +6 -9
- package/src/vdom-lit-html.ts +1 -0
- package/cli-templates/Layout.ts_ +0 -35
- package/cli-templates/_build.js +0 -27
- package/cli-templates/_eslintrc.js +0 -40
- package/cli-templates/_gitignore +0 -6
- package/cli-templates/component.ts_ +0 -14
- package/cli-templates/index.html +0 -10
- package/cli-templates/jest.config.js +0 -19
- package/cli-templates/karma.conf.js +0 -24
- package/cli-templates/main.ts_ +0 -13
- package/cli-templates/readme.md +0 -7
- package/cli-templates/spa_index.html +0 -14
- package/cli-templates/spa_main.ts_ +0 -12
- package/cli-templates/spec.ts_ +0 -12
- package/cli-templates/stories.js_ +0 -47
- package/cli-templates/tsconfig.es5.json +0 -15
- package/cli-templates/tsconfig.es6.json +0 -15
- package/cli-templates/webpack.config.js +0 -24
- package/index-apprun-play.html +0 -46
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -22,12 +22,13 @@ You can also load AppRun directly from the unpkg.com CDN:
|
|
|
22
22
|
```javascript
|
|
23
23
|
<script src="https://unpkg.com/apprun/dist/apprun-html.js"></script>
|
|
24
24
|
```
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
25
|
+
|
|
26
|
+
Or, you can create an AppRun app by using the `npm init apprun-app` command.
|
|
27
|
+
|
|
28
|
+
```sh
|
|
29
|
+
npm init apprun-app [my-app]
|
|
30
30
|
```
|
|
31
|
+
|
|
31
32
|
## Architecture Concept
|
|
32
33
|
|
|
33
34
|
* AppRun [architecure](docs/architecture) has _state_, _view_, and _update_.
|
|
@@ -39,41 +40,10 @@ You can get started with [AppRun Docs](https://apprun.js.org/docs) and [the AppR
|
|
|
39
40
|
|
|
40
41
|
## AppRun Book from Apress
|
|
41
42
|
|
|
42
|
-
[](https://www.amazon.com/Practical-Application-Development-AppRun-High-Performance/dp/1484240685/)
|
|
43
44
|
|
|
44
45
|
* [Order from Amazon](https://www.amazon.com/Practical-Application-Development-AppRun-High-Performance/dp/1484240685/)
|
|
45
46
|
|
|
46
|
-
## Create AppRun Apps
|
|
47
|
-
|
|
48
|
-
Use the AppRun CLI to initialize an esbuild configured project:
|
|
49
|
-
|
|
50
|
-
```sh
|
|
51
|
-
npx apprun --init --spa --esbuild
|
|
52
|
-
```
|
|
53
|
-
|
|
54
|
-
Use the AppRun CLI to initialize a TypeScript and webpack configured project:
|
|
55
|
-
|
|
56
|
-
```sh
|
|
57
|
-
npx apprun --init --spa
|
|
58
|
-
```
|
|
59
|
-
|
|
60
|
-
To initialize a project that targets ES5, use the AppRun CLI with the --es5 flag:
|
|
61
|
-
|
|
62
|
-
```sh
|
|
63
|
-
npx apprun --init --spa --es5
|
|
64
|
-
```
|
|
65
|
-
|
|
66
|
-
## AppRun Dev Server
|
|
67
|
-
|
|
68
|
-
AppRun now has a dev server. It is base on the _live-server_ and supports ES Modules. _apprun-dev-server_ is install by AppRun CLI when using _esbuild_. Or you can use it directly.
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
```sh
|
|
72
|
-
npx apprun-dev-server
|
|
73
|
-
```
|
|
74
|
-
|
|
75
|
-
See the announcement: [A Dev Server Supports ESM](https://dev.to/yysun/a-dev-server-supports-esm-3cea)
|
|
76
|
-
|
|
77
47
|
|
|
78
48
|
## AppRun Dev Tools
|
|
79
49
|
To use the AppRun dev-tools, include the dev-tools script.
|
|
@@ -125,13 +95,11 @@ AppRun is an MIT-licensed open source project. Please consider [supporting the p
|
|
|
125
95
|
* Kevin Shi
|
|
126
96
|
* Chancy Kennedy
|
|
127
97
|
|
|
128
|
-
|
|
129
|
-
|
|
130
98
|
## License
|
|
131
99
|
|
|
132
100
|
MIT
|
|
133
101
|
|
|
134
|
-
Copyright (c) 2015-
|
|
102
|
+
Copyright (c) 2015-2022 Yiyi Sun
|
|
135
103
|
|
|
136
104
|
|
|
137
105
|
[travis-image]: https://travis-ci.org/yysun/apprun.svg?branch=master
|
package/WHATSNEW.md
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
### What's New
|
|
2
2
|
|
|
3
|
-
##
|
|
3
|
+
## Create-AppRun-App CLI
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
You can create an AppRun app by running command `npm init apprun-app`.
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
```sh
|
|
8
|
+
npm init apprun-app [my-app]
|
|
9
|
+
```
|
|
8
10
|
|
|
9
|
-
|
|
11
|
+
> Note: AppRun CLI `npx apprun init` is deprecated. Please use `apprun create-app` instead.
|
|
10
12
|
|
|
11
|
-
* apprun@es5: 1.x, stable, es5
|
|
12
|
-
* apprun@latest: 3.x, stable, es2015, web components, lit-html
|
|
13
13
|
|
|
14
14
|
## Recent Posts and Publications
|
|
15
15
|
|
package/apprun-cli.js
CHANGED
|
@@ -2,225 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
'use strict';
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
const path = require('path');
|
|
7
|
-
const package_json = path.resolve('./package.json');
|
|
8
|
-
const tsconfig_json = path.resolve('./tsconfig.json');
|
|
9
|
-
const webpack_config_js = path.resolve('./webpack.config.js');
|
|
10
|
-
const git_ignore_file = path.resolve('./.gitignore');
|
|
11
|
-
const eslint_file = path.resolve('./.eslintrc.js');
|
|
12
|
-
const index_html = path.resolve('./index.html');
|
|
13
|
-
const main_tsx = path.resolve('./src/main.tsx');
|
|
14
|
-
const spa_index = path.resolve('./index.html');
|
|
15
|
-
const spa_main_tsx = path.resolve('./src/main.tsx');
|
|
16
|
-
const spa_layout_tsx = path.resolve('./src/Layout.tsx');
|
|
17
|
-
const readme_md = path.resolve('./README.md');
|
|
18
|
-
const build_js = path.resolve('./_build.js');
|
|
19
|
-
const execSync = require('child_process').execSync;
|
|
20
|
-
const program = require('commander');
|
|
5
|
+
console.log(`apprun CLI is deprecated. Please use create-apprun-app instead.
|
|
21
6
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
const dir_stories = './src/stories'
|
|
25
|
-
|
|
26
|
-
let show_start = false;
|
|
27
|
-
let show_test = false;
|
|
28
|
-
let es5 = false;
|
|
29
|
-
let esbuild = false;
|
|
30
|
-
|
|
31
|
-
function read(name) {
|
|
32
|
-
return fs.readFileSync(path.resolve(__dirname + '/cli-templates', name), 'utf8');
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
function write(file_name, text, title = ' * Creating', overwrite = false) {
|
|
36
|
-
const file = path.resolve(file_name);
|
|
37
|
-
if (!fs.existsSync(file) || overwrite) {
|
|
38
|
-
process.stdout.write(`${title}: ${file} ... `);
|
|
39
|
-
fs.writeFileSync(
|
|
40
|
-
file,
|
|
41
|
-
text
|
|
42
|
-
);
|
|
43
|
-
process.stdout.write('Done\n');
|
|
44
|
-
} else {
|
|
45
|
-
process.stdout.write(` * No change made. File exists: ${file}\n`);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
function init() {
|
|
50
|
-
RegExp.prototype.toJSON = RegExp.prototype.toString;
|
|
51
|
-
|
|
52
|
-
if (!fs.existsSync(package_json)) {
|
|
53
|
-
console.log(' * Initializing package.json');
|
|
54
|
-
execSync('npm init -y');
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
if (!fs.existsSync(dir_src)) fs.mkdirSync(dir_src);
|
|
58
|
-
|
|
59
|
-
const packages_es5 = 'npm install -D apprun@es5 typescript webpack webpack-cli webpack-dev-server ts-loader source-map-loader';
|
|
60
|
-
const packages_es6 = 'npm install -D apprun typescript webpack webpack-cli webpack-dev-server ts-loader source-map-loader';
|
|
61
|
-
console.log(' * Installing packages. This might take a few minutes.');
|
|
62
|
-
if (!esbuild) {
|
|
63
|
-
es5
|
|
64
|
-
? execSync(packages_es5)
|
|
65
|
-
: execSync(packages_es6);
|
|
66
|
-
} else {
|
|
67
|
-
es5
|
|
68
|
-
? execSync('npm install -D apprun@es5 apprun-dev-server esbuild')
|
|
69
|
-
: execSync('npm install -D apprun apprun-dev-server esbuild');
|
|
70
|
-
}
|
|
71
|
-
es5
|
|
72
|
-
? write(tsconfig_json, read('tsconfig.es5.json'), ' * Configuring typescript - es5', true)
|
|
73
|
-
: write(tsconfig_json, read('tsconfig.es6.json'), ' * Configuring typescript - es2015', true);
|
|
74
|
-
|
|
75
|
-
write(index_html, read('index.html'));
|
|
76
|
-
write(main_tsx, read('main.ts_'));
|
|
77
|
-
write(readme_md, read('readme.md'));
|
|
78
|
-
|
|
79
|
-
console.log(' * Adding npm scripts');
|
|
80
|
-
const package_info = require(package_json);
|
|
81
|
-
if (!package_info.scripts) package_info["scripts"] = {}
|
|
82
|
-
if (!esbuild) {
|
|
83
|
-
if (!package_info.scripts['start']) {
|
|
84
|
-
package_info["scripts"]["start"] = 'webpack serve --mode development';
|
|
85
|
-
}
|
|
86
|
-
if (!package_info.scripts['build']) {
|
|
87
|
-
package_info["scripts"]["build"] = 'webpack --mode production';
|
|
88
|
-
}
|
|
89
|
-
write(webpack_config_js, read('webpack.config.js'))
|
|
90
|
-
} else {
|
|
91
|
-
write(build_js, read('_build.js'));
|
|
92
|
-
if (!package_info.scripts['start']) {
|
|
93
|
-
package_info["scripts"]["start"] = 'node _build start';
|
|
94
|
-
}
|
|
95
|
-
if (!package_info.scripts['build']) {
|
|
96
|
-
package_info["scripts"]["build"] = 'node _build';
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
if (!package_info.scripts['tsc:watch']) {
|
|
100
|
-
package_info['scripts']['tsc:watch'] = 'tsc -w';
|
|
101
|
-
}
|
|
102
|
-
save_package_json(package_info);
|
|
103
|
-
git_init();
|
|
104
|
-
// jest_init();
|
|
105
|
-
show_start = true;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
function save_package_json(package_info) {
|
|
109
|
-
fs.writeFileSync(
|
|
110
|
-
package_json,
|
|
111
|
-
JSON.stringify(package_info, null, 2)
|
|
112
|
-
);
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
function git_init() {
|
|
116
|
-
if (!fs.existsSync('.git')) {
|
|
117
|
-
console.log(' * Initializing git');
|
|
118
|
-
execSync('git init');
|
|
119
|
-
} else {
|
|
120
|
-
console.log(' * Skip git init. .git exsits');
|
|
121
|
-
}
|
|
122
|
-
write(git_ignore_file, read('_gitignore'));
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
function component(name) {
|
|
126
|
-
if (!fs.existsSync(dir_src)) fs.mkdirSync(dir_src);
|
|
127
|
-
const fn = path.resolve(dir_src + '/' + name + '.tsx');
|
|
128
|
-
const component_template = read('component.ts_');
|
|
129
|
-
write(fn, component_template.replace(/\#name/g, name),
|
|
130
|
-
`Creating component ${name}`);
|
|
131
|
-
show_start = true;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
function jest_init() {
|
|
135
|
-
console.log(' * Installing jest');
|
|
136
|
-
execSync('npm i @types/jest jest ts-jest --save-dev');
|
|
137
|
-
const jest_config = {
|
|
138
|
-
"preset": "ts-jest",
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
const package_info = require(package_json) || {};
|
|
142
|
-
package_info["jest"] = jest_config
|
|
143
|
-
|
|
144
|
-
package_info["scripts"]["test"] = 'jest --watch';
|
|
145
|
-
save_package_json(package_info);
|
|
146
|
-
show_test = true;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
function lint_init() {
|
|
150
|
-
console.log(' * Installing ESLint');
|
|
151
|
-
execSync('npm install --save-dev eslint @typescript-eslint/parser @typescript-eslint/eslint-plugin');
|
|
152
|
-
|
|
153
|
-
const package_info = require(package_json) || {};
|
|
154
|
-
package_info["scripts"]["lint"] = 'eslint src';
|
|
155
|
-
package_info["scripts"]["lint:fix"] = 'eslint src --fix';
|
|
156
|
-
save_package_json(package_info);
|
|
157
|
-
|
|
158
|
-
write(eslint_file, read('_eslintrc.js'));
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
function component_spec(name) {
|
|
162
|
-
if (!fs.existsSync(dir_tests)) fs.mkdirSync(dir_tests);
|
|
163
|
-
const fn = path.resolve(dir_tests + '/' + name + '.spec.ts');
|
|
164
|
-
const test_template = read('spec.ts_');
|
|
165
|
-
write(fn, test_template.replace(/\#name/g, name),
|
|
166
|
-
`Creating component spec ${name}`);
|
|
167
|
-
show_test = true;
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
function component_story(name) {
|
|
171
|
-
if (!fs.existsSync(dir_stories)) fs.mkdirSync(dir_stories);
|
|
172
|
-
const fn = path.resolve(dir_stories + '/' + name + '.stories.tsx');
|
|
173
|
-
const story_template = read('stories.js_');
|
|
174
|
-
write(fn, story_template.replace(/\#name/g, name),
|
|
175
|
-
`Creating component stories ${name}`);
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
function spa() {
|
|
179
|
-
if (!fs.existsSync(dir_src)) fs.mkdirSync(dir_src);
|
|
180
|
-
write(spa_index, read('spa_index.html'), 'Creating', true);
|
|
181
|
-
write(spa_main_tsx, read('spa_main.ts_'), 'Creating', true);
|
|
182
|
-
write(spa_layout_tsx, read('Layout.ts_'), 'Creating', true);
|
|
183
|
-
component('Home');
|
|
184
|
-
component('About');
|
|
185
|
-
component('Contact');
|
|
186
|
-
show_start = true;
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
program
|
|
190
|
-
.name('apprun')
|
|
191
|
-
.version('2.27')
|
|
192
|
-
.option('-i, --init', 'Initialize AppRun Project')
|
|
193
|
-
.option('-c, --component <file>', 'Generate AppRun component')
|
|
194
|
-
.option('-g, --git', 'Initialize git repository')
|
|
195
|
-
.option('-j, --jest', 'Install jest')
|
|
196
|
-
.option('-l, --lint', 'Install ESLint')
|
|
197
|
-
.option('-t, --test <file>', 'Generate component spec')
|
|
198
|
-
.option('-o, --story <file>', 'Generate component stories')
|
|
199
|
-
.option('-s, --spa', 'Generate SPA app')
|
|
200
|
-
.option('-5, --es5', 'Use apprun@es5')
|
|
201
|
-
.option('-e, --esbuild', 'Use esbuild')
|
|
202
|
-
.parse(process.argv);
|
|
203
|
-
|
|
204
|
-
program._name = 'apprun';
|
|
205
|
-
const options = program.opts();
|
|
206
|
-
|
|
207
|
-
if (!options.init && !options.component && !options.git && !options.jest &&
|
|
208
|
-
!options.test && !options.spa && !options.lint && !options.story) {
|
|
209
|
-
program.outputHelp();
|
|
210
|
-
process.exit()
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
if (options.es5) es5 = true;
|
|
214
|
-
if (options.esbuild) esbuild = true;
|
|
215
|
-
if (options.init) init();
|
|
216
|
-
if (options.component) component(program.component);
|
|
217
|
-
if (options.git) git_init();
|
|
218
|
-
if (options.jest) jest_init();
|
|
219
|
-
if (options.lint) lint_init();
|
|
220
|
-
if (options.test) component_spec(program.test);
|
|
221
|
-
if (options.story) component_story(program.story);
|
|
222
|
-
if (options.spa) spa();
|
|
223
|
-
|
|
224
|
-
console.log('\r');
|
|
225
|
-
if (show_start) console.log('All done. You can run `npm start` and then navigate to http://localhost:8080 in a browser.');
|
|
226
|
-
//if (show_test) console.log('All done. You can run `npm test`.');
|
|
7
|
+
npm init apprun-app [my-app]
|
|
8
|
+
`);
|
package/dist/apprun-html.esm.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
class t{constructor(){this._events={}}on(t,i,s={}){this._events[t]=this._events[t]||[],this._events[t].push({fn:i,options:s})}off(t,i){const s=this._events[t]||[];this._events[t]=s.filter((t=>t.fn!==i))}find(t){return this._events[t]}run(t,...i){const s=this.getSubscribers(t,this._events);return console.assert(s&&s.length>0,"No subscriber for event: "+t),s.forEach((s=>{const{fn:n,options:e}=s;return e.delay?this.delay(t,n,i,e):Object.keys(e).length>0?n.apply(this,[...i,e]):n.apply(this,i),!s.options.once})),s.length}once(t,i,s={}){this.on(t,i,Object.assign(Object.assign({},s),{once:!0}))}delay(t,i,s,n){n._t&&clearTimeout(n._t),n._t=setTimeout((()=>{clearTimeout(n._t),Object.keys(n).length>0?i.apply(this,[...s,n]):i.apply(this,s)}),n.delay)}query(t,...i){const s=this.getSubscribers(t,this._events);console.assert(s&&s.length>0,"No subscriber for event: "+t);const n=s.map((t=>{const{fn:s,options:n}=t;return Object.keys(n).length>0?s.apply(this,[...i,n]):s.apply(this,i)}));return Promise.all(n)}getSubscribers(t,i){const s=i[t]||[];return i[t]=s.filter((t=>!t.options.once)),Object.keys(i).filter((i=>i.endsWith("*")&&t.startsWith(i.replace("*","")))).sort(((t,i)=>i.length-t.length)).forEach((n=>s.push(...i[n].map((i=>Object.assign(Object.assign({},i),{options:Object.assign(Object.assign({},i.options),{event:t})})))))),s}}let i;const s="object"==typeof self&&self.self===self&&self||"object"==typeof global&&global.global===global&&global;s.app&&s._AppRunVersions?i=s.app:(i=new t,s.app=i,s._AppRunVersions="AppRun-3");var n=i;function e(t,...i){return o(i)}function o(t){const i=[],s=t=>{null!=t&&""!==t&&!1!==t&&i.push("function"==typeof t||"object"==typeof t?t:`${t}`)};return t&&t.forEach((t=>{Array.isArray(t)?t.forEach((t=>s(t))):s(t)})),i}function r(t,i,...s){const n=o(s);if("string"==typeof t)return{tag:t,props:i,children:n};if(Array.isArray(t))return t;if(void 0===t&&s)return n;if(Object.getPrototypeOf(t).t)return{tag:t,props:i,children:n};if("function"==typeof t)return t(i,n);throw new Error(`Unknown tag in vdom ${t}`)}const h=new WeakMap,c=function(t,i,s={}){if(null==i||!1===i)return;i=v(i,s);const n="SVG"===(null==t?void 0:t.nodeName);if(!t)return;Array.isArray(i)?u(t,i,n):u(t,[i],n)};function l(t,i,s){3!==i._op&&(s=s||"svg"===i.tag,!function(t,i){const s=t.nodeName,n=`${i.tag||""}`;return s.toUpperCase()===n.toUpperCase()}(t,i)?t.parentNode.replaceChild(a(i,s),t):(!(2&i._op)&&u(t,i.children,s),!(1&i._op)&&f(t,i.props,s)))}function u(t,i,s){var n;const e=(null===(n=t.childNodes)||void 0===n?void 0:n.length)||0,o=(null==i?void 0:i.length)||0,r=Math.min(e,o);for(let n=0;n<r;n++){const e=i[n];if(3===e._op)continue;const o=t.childNodes[n];if("string"==typeof e)o.textContent!==e&&(3===o.nodeType?o.nodeValue=e:t.replaceChild(d(e),o));else if(e instanceof HTMLElement||e instanceof SVGElement)t.insertBefore(e,o);else{const i=e.props&&e.props.key;if(i)if(o.key===i)l(t.childNodes[n],e,s);else{const r=h[i];if(r){const i=r.nextSibling;t.insertBefore(r,o),i?t.insertBefore(o,i):t.appendChild(o),l(t.childNodes[n],e,s)}else t.replaceChild(a(e,s),o)}else l(t.childNodes[n],e,s)}}let c=t.childNodes.length;for(;c>r;)t.removeChild(t.lastChild),c--;if(o>r){const n=document.createDocumentFragment();for(let t=r;t<i.length;t++)n.appendChild(a(i[t],s));t.appendChild(n)}}function d(t){if(0===(null==t?void 0:t.indexOf("_html:"))){const i=document.createElement("div");return i.insertAdjacentHTML("afterbegin",t.substring(6)),i}return document.createTextNode(null!=t?t:"")}function a(t,i){if(t instanceof HTMLElement||t instanceof SVGElement)return t;if("string"==typeof t)return d(t);if(!t.tag||"function"==typeof t.tag)return d(JSON.stringify(t));const s=(i=i||"svg"===t.tag)?document.createElementNS("http://www.w3.org/2000/svg",t.tag):document.createElement(t.tag);return f(s,t.props,i),t.children&&t.children.forEach((t=>s.appendChild(a(t,i)))),s}function f(t,i,s){const n=t._props||{};i=function(t,i){i.class=i.class||i.className,delete i.className;const s={};return t&&Object.keys(t).forEach((t=>s[t]=null)),i&&Object.keys(i).forEach((t=>s[t]=i[t])),s}(n,i||{}),t._props=i;for(const n in i){const e=i[n];if(n.startsWith("data-")){const i=n.substring(5).replace(/-(\w)/g,(t=>t[1].toUpperCase()));t.dataset[i]!==e&&(e||""===e?t.dataset[i]=e:delete t.dataset[i])}else if("style"===n)if(t.style.cssText&&(t.style.cssText=""),"string"==typeof e)t.style.cssText=e;else for(const i in e)t.style[i]!==e[i]&&(t.style[i]=e[i]);else if(n.startsWith("xlink")){const i=n.replace("xlink","").toLowerCase();null==e||!1===e?t.removeAttributeNS("http://www.w3.org/1999/xlink",i):t.setAttributeNS("http://www.w3.org/1999/xlink",i,e)}else n.startsWith("on")?e&&"function"!=typeof e?"string"==typeof e&&(e?t.setAttribute(n,e):t.removeAttribute(n)):t[n]=e:/^id$|^class$|^list$|^readonly$|^contenteditable$|^role|-/g.test(n)||s?t.getAttribute(n)!==e&&(e?t.setAttribute(n,e):t.removeAttribute(n)):t[n]!==e&&(t[n]=e);"key"===n&&e&&(h[e]=t)}i&&"function"==typeof i.ref&&window.requestAnimationFrame((()=>i.ref(t)))}function v(t,i,s=0){var n;if("string"==typeof t)return t;if(Array.isArray(t))return t.map((t=>v(t,i,s++)));let e=t;if(t&&"function"==typeof t.tag&&Object.getPrototypeOf(t.tag).t&&(e=function(t,i,s){const{tag:n,props:e,children:o}=t;let r=`_${s}`,h=e&&e.id;h?r=h:h=`_${s}${Date.now()}`;let c="section";e&&e.as&&(c=e.as,delete e.as),i.i||(i.i={});let l=i.i[r];if(!(l&&l instanceof n&&l.element)){const t=document.createElement(c);l=i.i[r]=new n(Object.assign(Object.assign({},e),{children:o})).start(t)}if(l.mounted){const t=l.mounted(e,o,l.state);void 0!==t&&l.setState(t)}return f(l.element,e,!1),l.element}(t,i,s)),e&&Array.isArray(e.children)){const t=null===(n=e.props)||void 0===n?void 0:n._component;if(t){let i=0;e.children=e.children.map((s=>v(s,t,i++)))}else e.children=e.children.map((t=>v(t,i,s++)))}return e}const p=(t,i={})=>class extends HTMLElement{constructor(){super()}get component(){return this._component}get state(){return this._component.state}static get observedAttributes(){return(i.observedAttributes||[]).map((t=>t.toLowerCase()))}connectedCallback(){if(this.isConnected&&!this._component){const s=i||{};this._shadowRoot=s.shadow?this.attachShadow({mode:"open"}):this;const n=s.observedAttributes||[],e=n.reduce(((t,i)=>{const s=i.toLowerCase();return s!==i&&(t[s]=i),t}),{});this._attrMap=t=>e[t]||t;const o={};Array.from(this.attributes).forEach((t=>o[this._attrMap(t.name)]=t.value)),n.forEach((t=>{void 0!==this[t]&&(o[t]=this[t]),Object.defineProperty(this,t,{get:()=>o[t],set(i){this.attributeChangedCallback(t,o[t],i)},configurable:!0,enumerable:!0})}));const r=this.children?Array.from(this.children):[];if(r.forEach((t=>t.parentElement.removeChild(t))),this._component=new t(Object.assign(Object.assign({},o),{children:r})).mount(this._shadowRoot,s),this._component._props=o,this._component.dispatchEvent=this.dispatchEvent.bind(this),this._component.mounted){const t=this._component.mounted(o,r,this._component.state);void 0!==t&&(this._component.state=t)}this.on=this._component.on.bind(this._component),this.run=this._component.run.bind(this._component),!1!==s.render&&this._component.run(".")}}disconnectedCallback(){var t,i,s,n;null===(i=null===(t=this._component)||void 0===t?void 0:t.unload)||void 0===i||i.call(t),null===(n=null===(s=this._component)||void 0===s?void 0:s.unmount)||void 0===n||n.call(s),this._component=null}attributeChangedCallback(t,s,n){if(this._component){const e=this._attrMap(t);this._component._props[e]=n,this._component.run("attributeChanged",e,s,n),n!==s&&!1!==i.render&&window.requestAnimationFrame((()=>{this._component.run(".")}))}}};var y=(t,i,s)=>{"undefined"!=typeof customElements&&customElements.define(t,p(i,s))};const b={meta:new WeakMap,defineMetadata(t,i,s){this.meta.has(s)||this.meta.set(s,{}),this.meta.get(s)[t]=i},getMetadataKeys(t){return t=Object.getPrototypeOf(t),this.meta.get(t)?Object.keys(this.meta.get(t)):[]},getMetadata(t,i){return i=Object.getPrototypeOf(i),this.meta.get(i)?this.meta.get(i)[t]:null}};function g(t,i={}){return(s,n,e)=>{const o=t?t.toString():n;return b.defineMetadata(`apprun-update:${o}`,{name:o,key:n,options:i},s),e}}function w(t,i={}){return function(s,n){const e=t?t.toString():n;b.defineMetadata(`apprun-update:${e}`,{name:e,key:n,options:i},s)}}function m(t,i){return function(s){return y(t,s,i),s}}const $=(t,i)=>(i?t.state[i]:t.state)||"",j=(t,i,s)=>{if(i){const n=t.state||{};n[i]=s,t.setState(n)}else t.setState(s)},O=(t,i)=>{if(Array.isArray(t))return t.map((t=>O(t,i)));{let{tag:s,props:e,children:o}=t;return s?(e&&Object.keys(e).forEach((t=>{t.startsWith("$")&&(((t,i,s,e)=>{if(t.startsWith("$on")){const s=i[t];if(t=t.substring(1),"boolean"==typeof s)i[t]=i=>e.run(t,i);else if("string"==typeof s)i[t]=t=>e.run(s,t);else if("function"==typeof s)i[t]=t=>e.setState(s(e.state,t));else if(Array.isArray(s)){const[n,...o]=s;"string"==typeof n?i[t]=t=>e.run(n,...o,t):"function"==typeof n&&(i[t]=t=>e.setState(n(e.state,...o,t)))}}else if("$bind"===t){const n=i.type||"text",o="string"==typeof i[t]?i[t]:i.name;if("input"===s)switch(n){case"checkbox":i.checked=$(e,o),i.onclick=t=>j(e,o||t.target.name,t.target.checked);break;case"radio":i.checked=$(e,o)===i.value,i.onclick=t=>j(e,o||t.target.name,t.target.value);break;case"number":case"range":i.value=$(e,o),i.oninput=t=>j(e,o||t.target.name,Number(t.target.value));break;default:i.value=$(e,o),i.oninput=t=>j(e,o||t.target.name,t.target.value)}else"select"===s?(i.value=$(e,o),i.onchange=t=>{t.target.multiple||j(e,o||t.target.name,t.target.value)}):"option"===s?(i.selected=$(e,o),i.onclick=t=>j(e,o||t.target.name,t.target.selected)):"textarea"===s&&(i.innerHTML=$(e,o),i.oninput=t=>j(e,o||t.target.name,t.target.value))}else n.run("$",{key:t,tag:s,props:i,component:e})})(t,e,s,i),delete e[t])})),o&&(o=O(o,i)),{tag:s,props:e,children:o}):t}},A=new Map;n.on("get-components",(t=>t.components=A));const _=t=>t;class k{constructor(i,s,n,e){this.state=i,this.view=s,this.update=n,this.options=e,this._app=new t,this._actions=[],this._global_events=[],this._history=[],this._history_idx=-1,this._history_prev=()=>{this._history_idx--,this._history_idx>=0?this.setState(this._history[this._history_idx],{render:!0,history:!1}):this._history_idx=0},this._history_next=()=>{this._history_idx++,this._history_idx<this._history.length?this.setState(this._history[this._history_idx],{render:!0,history:!1}):this._history_idx=this._history.length-1},this.start=(t=null,i)=>this.mount(t,Object.assign({render:!0},i))}renderState(t,i=null){if(!this.view)return;let s=i||this.view(t);if(n.debug&&n.run("debug",{component:this,_:s?".":"-",state:t,vdom:s,el:this.element}),"object"!=typeof document)return;const e="string"==typeof this.element?document.getElementById(this.element):this.element;if(e){const t="_c";this.unload?e._component===this&&e.getAttribute(t)===this.tracking_id||(this.tracking_id=(new Date).valueOf().toString(),e.setAttribute(t,this.tracking_id),"undefined"!=typeof MutationObserver&&(this.observer||(this.observer=new MutationObserver((t=>{t[0].oldValue!==this.tracking_id&&document.body.contains(e)||(this.unload(this.state),this.observer.disconnect(),this.observer=null)}))),this.observer.observe(document.body,{childList:!0,subtree:!0,attributes:!0,attributeOldValue:!0,attributeFilter:[t]}))):e.removeAttribute&&e.removeAttribute(t),e._component=this}!i&&s&&(s=O(s,this),n.render(e,s,this)),this.rendered&&this.rendered(this.state)}setState(t,i={render:!0,history:!1}){if(t instanceof Promise)Promise.all([t,this._state]).then((t=>{t[0]&&this.setState(t[0])})).catch((t=>{throw console.error(t),t})),this._state=t;else{if(this._state=t,null==t)return;this.state=t,!1!==i.render&&this.renderState(t),!1!==i.history&&this.enable_history&&(this._history=[...this._history,t],this._history_idx=this._history.length-1),"function"==typeof i.callback&&i.callback(this.state)}}mount(t=null,i){var s,e;return console.assert(!this.element,"Component already mounted."),this.options=i=Object.assign(Object.assign({},this.options),i),this.element=t,this.global_event=i.global_event,this.enable_history=!!i.history,this.enable_history&&(this.on(i.history.prev||"history-prev",this._history_prev),this.on(i.history.next||"history-next",this._history_next)),i.route&&(this.update=this.update||{},this.update[i.route]=_),this.add_actions(),this.state=null!==(e=null!==(s=this.state)&&void 0!==s?s:this.model)&&void 0!==e?e:{},"function"==typeof this.state&&(this.state=this.state()),i.render?this.setState(this.state,{render:!0,history:!0}):this.setState(this.state,{render:!1,history:!0}),n.debug&&(A.get(t)?A.get(t).push(this):A.set(t,[this])),this}is_global_event(t){return t&&(this.global_event||this._global_events.indexOf(t)>=0||t.startsWith("#")||t.startsWith("/")||t.startsWith("@"))}add_action(t,i,s={}){i&&"function"==typeof i&&(s.global&&this._global_events.push(t),this.on(t,((...e)=>{n.debug&&n.run("debug",{component:this,_:">",event:t,p:e,current_state:this.state,options:s});const o=i(this.state,...e);n.debug&&n.run("debug",{component:this,_:"<",event:t,p:e,newState:o,state:this.state,options:s}),this.setState(o,s)}),s))}add_actions(){const t=this.update||{};b.getMetadataKeys(this).forEach((i=>{if(i.startsWith("apprun-update:")){const s=b.getMetadata(i,this);t[s.name]=[this[s.key].bind(this),s.options]}}));const i={};Array.isArray(t)?t.forEach((t=>{const[s,n,e]=t;s.toString().split(",").forEach((t=>i[t.trim()]=[n,e]))})):Object.keys(t).forEach((s=>{const n=t[s];("function"==typeof n||Array.isArray(n))&&s.split(",").forEach((t=>i[t.trim()]=n))})),i["."]||(i["."]=_),Object.keys(i).forEach((t=>{const s=i[t];"function"==typeof s?this.add_action(t,s):Array.isArray(s)&&this.add_action(t,s[0],s[1])}))}run(t,...i){const s=t.toString();return this.is_global_event(s)?n.run(s,...i):this._app.run(s,...i)}on(t,i,s){const e=t.toString();return this._actions.push({name:e,fn:i}),this.is_global_event(e)?n.on(e,i,s):this._app.on(e,i,s)}unmount(){var t;null===(t=this.observer)||void 0===t||t.disconnect(),this._actions.forEach((t=>{const{name:i,fn:s}=t;this.is_global_event(i)?n.off(i,s):this._app.off(i,s)}))}}k.t=!0;const x="//",M="///",T=t=>{if(t||(t="#"),t.startsWith("#")){const[i,...s]=t.split("/");n.run(i,...s)||n.run("///",i,...s),n.run("//",i,...s)}else if(t.startsWith("/")){const[i,s,...e]=t.split("/");n.run("/"+s,...e)||n.run("///","/"+s,...e),n.run("//","/"+s,...e)}else n.run(t)||n.run("///",t),n.run("//",t)};n.h=n.createElement=r,n.render=function(t,i,s){c(t,i,s)},n.Fragment=e,n.webComponent=y,n.start=(t,i,s,n,e)=>{const o=Object.assign({render:!0,global_event:!0},e),r=new k(i,s,n);return e&&e.rendered&&(r.rendered=e.rendered),r.mount(t,o),r};const E=t=>{};
|
|
1
|
+
class t{constructor(){this._events={}}on(t,i,s={}){this._events[t]=this._events[t]||[],this._events[t].push({fn:i,options:s})}off(t,i){const s=this._events[t]||[];this._events[t]=s.filter((t=>t.fn!==i))}find(t){return this._events[t]}run(t,...i){const s=this.getSubscribers(t,this._events);return console.assert(s&&s.length>0,"No subscriber for event: "+t),s.forEach((s=>{const{fn:n,options:e}=s;return e.delay?this.delay(t,n,i,e):Object.keys(e).length>0?n.apply(this,[...i,e]):n.apply(this,i),!s.options.once})),s.length}once(t,i,s={}){this.on(t,i,Object.assign(Object.assign({},s),{once:!0}))}delay(t,i,s,n){n._t&&clearTimeout(n._t),n._t=setTimeout((()=>{clearTimeout(n._t),Object.keys(n).length>0?i.apply(this,[...s,n]):i.apply(this,s)}),n.delay)}query(t,...i){const s=this.getSubscribers(t,this._events);console.assert(s&&s.length>0,"No subscriber for event: "+t);const n=s.map((t=>{const{fn:s,options:n}=t;return Object.keys(n).length>0?s.apply(this,[...i,n]):s.apply(this,i)}));return Promise.all(n)}getSubscribers(t,i){const s=i[t]||[];return i[t]=s.filter((t=>!t.options.once)),Object.keys(i).filter((i=>i.endsWith("*")&&t.startsWith(i.replace("*","")))).sort(((t,i)=>i.length-t.length)).forEach((n=>s.push(...i[n].map((i=>Object.assign(Object.assign({},i),{options:Object.assign(Object.assign({},i.options),{event:t})})))))),s}}let i;const s="object"==typeof self&&self.self===self&&self||"object"==typeof global&&global.global===global&&global;s.app&&s._AppRunVersions?i=s.app:(i=new t,s.app=i,s._AppRunVersions="AppRun-3");var n=i;function e(t,...i){return o(i)}function o(t){const i=[],s=t=>{null!=t&&""!==t&&!1!==t&&i.push("function"==typeof t||"object"==typeof t?t:`${t}`)};return t&&t.forEach((t=>{Array.isArray(t)?t.forEach((t=>s(t))):s(t)})),i}function r(t,i,...s){const n=o(s);if("string"==typeof t)return{tag:t,props:i,children:n};if(Array.isArray(t))return t;if(void 0===t&&s)return n;if(Object.getPrototypeOf(t).t)return{tag:t,props:i,children:n};if("function"==typeof t)return t(i,n);throw new Error(`Unknown tag in vdom ${t}`)}const h=new WeakMap,c=function(t,i,s={}){if(null==i||!1===i)return;i=v(i,s);const n="SVG"===(null==t?void 0:t.nodeName);if(!t)return;Array.isArray(i)?u(t,i,n):u(t,[i],n)};function l(t,i,s){3!==i._op&&(s=s||"svg"===i.tag,!function(t,i){const s=t.nodeName,n=`${i.tag||""}`;return s.toUpperCase()===n.toUpperCase()}(t,i)?t.parentNode.replaceChild(a(i,s),t):(!(2&i._op)&&u(t,i.children,s),!(1&i._op)&&f(t,i.props,s)))}function u(t,i,s){var n;const e=(null===(n=t.childNodes)||void 0===n?void 0:n.length)||0,o=(null==i?void 0:i.length)||0,r=Math.min(e,o);for(let n=0;n<r;n++){const e=i[n];if(3===e._op)continue;const o=t.childNodes[n];if("string"==typeof e)o.textContent!==e&&(3===o.nodeType?o.nodeValue=e:t.replaceChild(d(e),o));else if(e instanceof HTMLElement||e instanceof SVGElement)t.insertBefore(e,o);else{const i=e.props&&e.props.key;if(i)if(o.key===i)l(t.childNodes[n],e,s);else{const r=h[i];if(r){const i=r.nextSibling;t.insertBefore(r,o),i?t.insertBefore(o,i):t.appendChild(o),l(t.childNodes[n],e,s)}else t.replaceChild(a(e,s),o)}else l(t.childNodes[n],e,s)}}let c=t.childNodes.length;for(;c>r;)t.removeChild(t.lastChild),c--;if(o>r){const n=document.createDocumentFragment();for(let t=r;t<i.length;t++)n.appendChild(a(i[t],s));t.appendChild(n)}}function d(t){if(0===(null==t?void 0:t.indexOf("_html:"))){const i=document.createElement("div");return i.insertAdjacentHTML("afterbegin",t.substring(6)),i}return document.createTextNode(null!=t?t:"")}function a(t,i){if(t instanceof HTMLElement||t instanceof SVGElement)return t;if("string"==typeof t)return d(t);if(!t.tag||"function"==typeof t.tag)return d(JSON.stringify(t));const s=(i=i||"svg"===t.tag)?document.createElementNS("http://www.w3.org/2000/svg",t.tag):document.createElement(t.tag);return f(s,t.props,i),t.children&&t.children.forEach((t=>s.appendChild(a(t,i)))),s}function f(t,i,s){const n=t._props||{};i=function(t,i){i.class=i.class||i.className,delete i.className;const s={};return t&&Object.keys(t).forEach((t=>s[t]=null)),i&&Object.keys(i).forEach((t=>s[t]=i[t])),s}(n,i||{}),t._props=i;for(const n in i){const e=i[n];if(n.startsWith("data-")){const i=n.substring(5).replace(/-(\w)/g,(t=>t[1].toUpperCase()));t.dataset[i]!==e&&(e||""===e?t.dataset[i]=e:delete t.dataset[i])}else if("style"===n)if(t.style.cssText&&(t.style.cssText=""),"string"==typeof e)t.style.cssText=e;else for(const i in e)t.style[i]!==e[i]&&(t.style[i]=e[i]);else if(n.startsWith("xlink")){const i=n.replace("xlink","").toLowerCase();null==e||!1===e?t.removeAttributeNS("http://www.w3.org/1999/xlink",i):t.setAttributeNS("http://www.w3.org/1999/xlink",i,e)}else n.startsWith("on")?e&&"function"!=typeof e?"string"==typeof e&&(e?t.setAttribute(n,e):t.removeAttribute(n)):t[n]=e:/^id$|^class$|^list$|^readonly$|^contenteditable$|^role|-/g.test(n)||s?t.getAttribute(n)!==e&&(e?t.setAttribute(n,e):t.removeAttribute(n)):t[n]!==e&&(t[n]=e);"key"===n&&e&&(h[e]=t)}i&&"function"==typeof i.ref&&window.requestAnimationFrame((()=>i.ref(t)))}function v(t,i,s=0){var n;if("string"==typeof t)return t;if(Array.isArray(t))return t.map((t=>v(t,i,s++)));let e=t;if(t&&"function"==typeof t.tag&&Object.getPrototypeOf(t.tag).t&&(e=function(t,i,s){const{tag:n,props:e,children:o}=t;let r=`_${s}`,h=e&&e.id;h?r=h:h=`_${s}${Date.now()}`;let c="section";e&&e.as&&(c=e.as,delete e.as),i.i||(i.i={});let l=i.i[r];if(!(l&&l instanceof n&&l.element)){const t=document.createElement(c);l=i.i[r]=new n(Object.assign(Object.assign({},e),{children:o})).start(t)}if(l.mounted){const t=l.mounted(e,o,l.state);void 0!==t&&l.setState(t)}return f(l.element,e,!1),l.element}(t,i,s)),e&&Array.isArray(e.children)){const t=null===(n=e.props)||void 0===n?void 0:n._component;if(t){let i=0;e.children=e.children.map((s=>v(s,t,i++)))}else e.children=e.children.map((t=>v(t,i,s++)))}return e}const p=(t,i={})=>class extends HTMLElement{constructor(){super()}get component(){return this._component}get state(){return this._component.state}static get observedAttributes(){return(i.observedAttributes||[]).map((t=>t.toLowerCase()))}connectedCallback(){if(this.isConnected&&!this._component){const s=i||{};this._shadowRoot=s.shadow?this.attachShadow({mode:"open"}):this;const n=s.observedAttributes||[],e=n.reduce(((t,i)=>{const s=i.toLowerCase();return s!==i&&(t[s]=i),t}),{});this._attrMap=t=>e[t]||t;const o={};Array.from(this.attributes).forEach((t=>o[this._attrMap(t.name)]=t.value)),n.forEach((t=>{void 0!==this[t]&&(o[t]=this[t]),Object.defineProperty(this,t,{get:()=>o[t],set(i){this.attributeChangedCallback(t,o[t],i)},configurable:!0,enumerable:!0})}));const r=this.children?Array.from(this.children):[];if(r.forEach((t=>t.parentElement.removeChild(t))),this._component=new t(Object.assign(Object.assign({},o),{children:r})).mount(this._shadowRoot,s),this._component._props=o,this._component.dispatchEvent=this.dispatchEvent.bind(this),this._component.mounted){const t=this._component.mounted(o,r,this._component.state);void 0!==t&&(this._component.state=t)}this.on=this._component.on.bind(this._component),this.run=this._component.run.bind(this._component),!1!==s.render&&this._component.run(".")}}disconnectedCallback(){var t,i,s,n;null===(i=null===(t=this._component)||void 0===t?void 0:t.unload)||void 0===i||i.call(t),null===(n=null===(s=this._component)||void 0===s?void 0:s.unmount)||void 0===n||n.call(s),this._component=null}attributeChangedCallback(t,s,n){if(this._component){const e=this._attrMap(t);this._component._props[e]=n,this._component.run("attributeChanged",e,s,n),n!==s&&!1!==i.render&&window.requestAnimationFrame((()=>{this._component.run(".")}))}}};var y=(t,i,s)=>{"undefined"!=typeof customElements&&customElements.define(t,p(i,s))};const b={meta:new WeakMap,defineMetadata(t,i,s){this.meta.has(s)||this.meta.set(s,{}),this.meta.get(s)[t]=i},getMetadataKeys(t){return t=Object.getPrototypeOf(t),this.meta.get(t)?Object.keys(this.meta.get(t)):[]},getMetadata(t,i){return i=Object.getPrototypeOf(i),this.meta.get(i)?this.meta.get(i)[t]:null}};function g(t,i={}){return(s,n,e)=>{const o=t?t.toString():n;return b.defineMetadata(`apprun-update:${o}`,{name:o,key:n,options:i},s),e}}function w(t,i={}){return function(s,n){const e=t?t.toString():n;b.defineMetadata(`apprun-update:${e}`,{name:e,key:n,options:i},s)}}function m(t,i){return function(s){return y(t,s,i),s}}const $=(t,i)=>(i?t.state[i]:t.state)||"",j=(t,i,s)=>{if(i){const n=t.state||{};n[i]=s,t.setState(n)}else t.setState(s)},O=(t,i)=>{if(Array.isArray(t))return t.map((t=>O(t,i)));{let{tag:s,props:e,children:o}=t;return s?(e&&Object.keys(e).forEach((t=>{t.startsWith("$")&&(((t,i,s,e)=>{if(t.startsWith("$on")){const s=i[t];if(t=t.substring(1),"boolean"==typeof s)i[t]=i=>e.run(t,i);else if("string"==typeof s)i[t]=t=>e.run(s,t);else if("function"==typeof s)i[t]=t=>e.setState(s(e.state,t));else if(Array.isArray(s)){const[n,...o]=s;"string"==typeof n?i[t]=t=>e.run(n,...o,t):"function"==typeof n&&(i[t]=t=>e.setState(n(e.state,...o,t)))}}else if("$bind"===t){const n=i.type||"text",o="string"==typeof i[t]?i[t]:i.name;if("input"===s)switch(n){case"checkbox":i.checked=$(e,o),i.onclick=t=>j(e,o||t.target.name,t.target.checked);break;case"radio":i.checked=$(e,o)===i.value,i.onclick=t=>j(e,o||t.target.name,t.target.value);break;case"number":case"range":i.value=$(e,o),i.oninput=t=>j(e,o||t.target.name,Number(t.target.value));break;default:i.value=$(e,o),i.oninput=t=>j(e,o||t.target.name,t.target.value)}else"select"===s?(i.value=$(e,o),i.onchange=t=>{t.target.multiple||j(e,o||t.target.name,t.target.value)}):"option"===s?(i.selected=$(e,o),i.onclick=t=>j(e,o||t.target.name,t.target.selected)):"textarea"===s&&(i.innerHTML=$(e,o),i.oninput=t=>j(e,o||t.target.name,t.target.value))}else n.run("$",{key:t,tag:s,props:i,component:e})})(t,e,s,i),delete e[t])})),o&&(o=O(o,i)),{tag:s,props:e,children:o}):t}},A=new Map;n.on("get-components",(t=>t.components=A));const _=t=>t;class x{constructor(i,s,n,e){this.state=i,this.view=s,this.update=n,this.options=e,this._app=new t,this._actions=[],this._global_events=[],this._history=[],this._history_idx=-1,this._history_prev=()=>{this._history_idx--,this._history_idx>=0?this.setState(this._history[this._history_idx],{render:!0,history:!1}):this._history_idx=0},this._history_next=()=>{this._history_idx++,this._history_idx<this._history.length?this.setState(this._history[this._history_idx],{render:!0,history:!1}):this._history_idx=this._history.length-1},this.start=(t=null,i)=>this.mount(t,Object.assign({render:!0},i))}renderState(t,i=null){if(!this.view)return;let s=i||this.view(t);if(n.debug&&n.run("debug",{component:this,_:s?".":"-",state:t,vdom:s,el:this.element}),"object"!=typeof document)return;const e="string"==typeof this.element?document.getElementById(this.element):this.element;if(e){const t="_c";this.unload?e._component===this&&e.getAttribute(t)===this.tracking_id||(this.tracking_id=(new Date).valueOf().toString(),e.setAttribute(t,this.tracking_id),"undefined"!=typeof MutationObserver&&(this.observer||(this.observer=new MutationObserver((t=>{t[0].oldValue!==this.tracking_id&&document.body.contains(e)||(this.unload(this.state),this.observer.disconnect(),this.observer=null)}))),this.observer.observe(document.body,{childList:!0,subtree:!0,attributes:!0,attributeOldValue:!0,attributeFilter:[t]}))):e.removeAttribute&&e.removeAttribute(t),e._component=this}!i&&s&&(s=O(s,this),n.render(e,s,this)),this.rendered&&this.rendered(this.state)}setState(t,i={render:!0,history:!1}){if(t instanceof Promise)Promise.all([t,this._state]).then((t=>{t[0]&&this.setState(t[0])})).catch((t=>{throw console.error(t),t})),this._state=t;else{if(this._state=t,null==t)return;this.state=t,!1!==i.render&&this.renderState(t),!1!==i.history&&this.enable_history&&(this._history=[...this._history,t],this._history_idx=this._history.length-1),"function"==typeof i.callback&&i.callback(this.state)}}mount(t=null,i){var s,e;return console.assert(!this.element,"Component already mounted."),this.options=i=Object.assign(Object.assign({},this.options),i),this.element=t,this.global_event=i.global_event,this.enable_history=!!i.history,this.enable_history&&(this.on(i.history.prev||"history-prev",this._history_prev),this.on(i.history.next||"history-next",this._history_next)),i.route&&(this.update=this.update||{},this.update[i.route]=_),this.add_actions(),this.state=null!==(e=null!==(s=this.state)&&void 0!==s?s:this.model)&&void 0!==e?e:{},"function"==typeof this.state&&(this.state=this.state()),i.render?this.setState(this.state,{render:!0,history:!0}):this.setState(this.state,{render:!1,history:!0}),n.debug&&(A.get(t)?A.get(t).push(this):A.set(t,[this])),this}is_global_event(t){return t&&(this.global_event||this._global_events.indexOf(t)>=0||t.startsWith("#")||t.startsWith("/")||t.startsWith("@"))}add_action(t,i,s={}){i&&"function"==typeof i&&(s.global&&this._global_events.push(t),this.on(t,((...e)=>{n.debug&&n.run("debug",{component:this,_:">",event:t,p:e,current_state:this.state,options:s});const o=i(this.state,...e);n.debug&&n.run("debug",{component:this,_:"<",event:t,p:e,newState:o,state:this.state,options:s}),this.setState(o,s)}),s))}add_actions(){const t=this.update||{};b.getMetadataKeys(this).forEach((i=>{if(i.startsWith("apprun-update:")){const s=b.getMetadata(i,this);t[s.name]=[this[s.key].bind(this),s.options]}}));const i={};Array.isArray(t)?t.forEach((t=>{const[s,n,e]=t;s.toString().split(",").forEach((t=>i[t.trim()]=[n,e]))})):Object.keys(t).forEach((s=>{const n=t[s];("function"==typeof n||Array.isArray(n))&&s.split(",").forEach((t=>i[t.trim()]=n))})),i["."]||(i["."]=_),Object.keys(i).forEach((t=>{const s=i[t];"function"==typeof s?this.add_action(t,s):Array.isArray(s)&&this.add_action(t,s[0],s[1])}))}run(t,...i){const s=t.toString();return this.is_global_event(s)?n.run(s,...i):this._app.run(s,...i)}on(t,i,s){const e=t.toString();return this._actions.push({name:e,fn:i}),this.is_global_event(e)?n.on(e,i,s):this._app.on(e,i,s)}unmount(){var t;null===(t=this.observer)||void 0===t||t.disconnect(),this._actions.forEach((t=>{const{name:i,fn:s}=t;this.is_global_event(i)?n.off(i,s):this._app.off(i,s)}))}}x.t=!0;const k="//",T="///",M=t=>{if(t||(t="#"),t.startsWith("#")){const[i,...s]=t.split("/");n.run(i,...s)||n.run("///",i,...s),n.run("//",i,...s)}else if(t.startsWith("/")){const[i,s,...e]=t.split("/");n.run("/"+s,...e)||n.run("///","/"+s,...e),n.run("//","/"+s,...e)}else n.run(t)||n.run("///",t),n.run("//",t)};n.h=n.createElement=r,n.render=function(t,i,s){c(t,i,s)},n.Fragment=e,n.webComponent=y,n.start=(t,i,s,n,e)=>{const o=Object.assign({render:!0,global_event:!0},e),r=new x(i,s,n);return e&&e.rendered&&(r.rendered=e.rendered),r.mount(t,o),r};const E=t=>{};
|
|
2
2
|
/**
|
|
3
3
|
* @license
|
|
4
4
|
* Copyright 2017 Google LLC
|
|
5
5
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
6
6
|
*/
|
|
7
|
-
var
|
|
7
|
+
var C;n.on("$",E),n.on("debug",(t=>E)),n.on("//",E),n.on("#",E),n.route=M,n.on("route",(t=>n.route&&n.route(t))),"object"==typeof document&&document.addEventListener("DOMContentLoaded",(()=>{n.route===M&&(window.onpopstate=()=>M(location.hash),document.body.hasAttribute("apprun-no-init")||M(location.hash))})),"object"==typeof window&&(window.Component=x,window.React=n,window.on=w,window.customElement=m);const S=globalThis.trustedTypes,N=S?S.createPolicy("lit-html",{createHTML:t=>t}):void 0,L=`lit$${(Math.random()+"").slice(9)}$`,U="?"+L,H=`<${U}>`,D=document,I=(t="")=>D.createComment(t),V=t=>null===t||"object"!=typeof t&&"function"!=typeof t,G=Array.isArray,P=/<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g,R=/-->/g,W=/>/g,z=/>|[ \n\r](?:([^\s"'>=/]+)([ \n\r]*=[ \n\r]*(?:[^ \n\r"'`<>=]|("|')|))|$)/g,Z=/'/g,q=/"/g,F=/^(?:script|style|textarea|title)$/i,J=t=>(i,...s)=>({_$litType$:t,strings:i,values:s}),K=J(1),B=J(2),Q=Symbol.for("lit-noChange"),X=Symbol.for("lit-nothing"),Y=new WeakMap,tt=(t,i,s)=>{var n,e;const o=null!==(n=null==s?void 0:s.renderBefore)&&void 0!==n?n:i;let r=o._$litPart$;if(void 0===r){const t=null!==(e=null==s?void 0:s.renderBefore)&&void 0!==e?e:null;o._$litPart$=r=new rt(i.insertBefore(I(),t),t,void 0,null!=s?s:{})}return r._$AI(t),r},it=D.createTreeWalker(D,129,null,!1),st=(t,i)=>{const s=t.length-1,n=[];let e,o=2===i?"<svg>":"",r=P;for(let i=0;i<s;i++){const s=t[i];let h,c,l=-1,u=0;for(;u<s.length&&(r.lastIndex=u,c=r.exec(s),null!==c);)u=r.lastIndex,r===P?"!--"===c[1]?r=R:void 0!==c[1]?r=W:void 0!==c[2]?(F.test(c[2])&&(e=RegExp("</"+c[2],"g")),r=z):void 0!==c[3]&&(r=z):r===z?">"===c[0]?(r=null!=e?e:P,l=-1):void 0===c[1]?l=-2:(l=r.lastIndex-c[2].length,h=c[1],r=void 0===c[3]?z:'"'===c[3]?q:Z):r===q||r===Z?r=z:r===R||r===W?r=P:(r=z,e=void 0);const d=r===z&&t[i+1].startsWith("/>")?" ":"";o+=r===P?s+H:l>=0?(n.push(h),s.slice(0,l)+"$lit$"+s.slice(l)+L+d):s+L+(-2===l?(n.push(void 0),i):d)}const h=o+(t[s]||"<?>")+(2===i?"</svg>":"");if(!Array.isArray(t)||!t.hasOwnProperty("raw"))throw Error("invalid template strings array");return[void 0!==N?N.createHTML(h):h,n]};class nt{constructor({strings:t,_$litType$:i},s){let n;this.parts=[];let e=0,o=0;const r=t.length-1,h=this.parts,[c,l]=st(t,i);if(this.el=nt.createElement(c,s),it.currentNode=this.el.content,2===i){const t=this.el.content,i=t.firstChild;i.remove(),t.append(...i.childNodes)}for(;null!==(n=it.nextNode())&&h.length<r;){if(1===n.nodeType){if(n.hasAttributes()){const t=[];for(const i of n.getAttributeNames())if(i.endsWith("$lit$")||i.startsWith(L)){const s=l[o++];if(t.push(i),void 0!==s){const t=n.getAttribute(s.toLowerCase()+"$lit$").split(L),i=/([.?@])?(.*)/.exec(s);h.push({type:1,index:e,name:i[2],strings:t,ctor:"."===i[1]?ct:"?"===i[1]?ut:"@"===i[1]?dt:ht})}else h.push({type:6,index:e})}for(const i of t)n.removeAttribute(i)}if(F.test(n.tagName)){const t=n.textContent.split(L),i=t.length-1;if(i>0){n.textContent=S?S.emptyScript:"";for(let s=0;s<i;s++)n.append(t[s],I()),it.nextNode(),h.push({type:2,index:++e});n.append(t[i],I())}}}else if(8===n.nodeType)if(n.data===U)h.push({type:2,index:e});else{let t=-1;for(;-1!==(t=n.data.indexOf(L,t+1));)h.push({type:7,index:e}),t+=L.length-1}e++}}static createElement(t,i){const s=D.createElement("template");return s.innerHTML=t,s}}function et(t,i,s=t,n){var e,o,r,h;if(i===Q)return i;let c=void 0!==n?null===(e=s._$Cl)||void 0===e?void 0:e[n]:s._$Cu;const l=V(i)?void 0:i._$litDirective$;return(null==c?void 0:c.constructor)!==l&&(null===(o=null==c?void 0:c._$AO)||void 0===o||o.call(c,!1),void 0===l?c=void 0:(c=new l(t),c._$AT(t,s,n)),void 0!==n?(null!==(r=(h=s)._$Cl)&&void 0!==r?r:h._$Cl=[])[n]=c:s._$Cu=c),void 0!==c&&(i=et(t,c._$AS(t,i.values),c,n)),i}class ot{constructor(t,i){this.v=[],this._$AN=void 0,this._$AD=t,this._$AM=i}get parentNode(){return this._$AM.parentNode}get _$AU(){return this._$AM._$AU}p(t){var i;const{el:{content:s},parts:n}=this._$AD,e=(null!==(i=null==t?void 0:t.creationScope)&&void 0!==i?i:D).importNode(s,!0);it.currentNode=e;let o=it.nextNode(),r=0,h=0,c=n[0];for(;void 0!==c;){if(r===c.index){let i;2===c.type?i=new rt(o,o.nextSibling,this,t):1===c.type?i=new c.ctor(o,c.name,c.strings,this,t):6===c.type&&(i=new at(o,this,t)),this.v.push(i),c=n[++h]}r!==(null==c?void 0:c.index)&&(o=it.nextNode(),r++)}return e}m(t){let i=0;for(const s of this.v)void 0!==s&&(void 0!==s.strings?(s._$AI(t,s,i),i+=s.strings.length-2):s._$AI(t[i])),i++}}class rt{constructor(t,i,s,n){var e;this.type=2,this._$AH=X,this._$AN=void 0,this._$AA=t,this._$AB=i,this._$AM=s,this.options=n,this._$Cg=null===(e=null==n?void 0:n.isConnected)||void 0===e||e}get _$AU(){var t,i;return null!==(i=null===(t=this._$AM)||void 0===t?void 0:t._$AU)&&void 0!==i?i:this._$Cg}get parentNode(){let t=this._$AA.parentNode;const i=this._$AM;return void 0!==i&&11===t.nodeType&&(t=i.parentNode),t}get startNode(){return this._$AA}get endNode(){return this._$AB}_$AI(t,i=this){t=et(this,t,i),V(t)?t===X||null==t||""===t?(this._$AH!==X&&this._$AR(),this._$AH=X):t!==this._$AH&&t!==Q&&this.$(t):void 0!==t._$litType$?this.T(t):void 0!==t.nodeType?this.k(t):(t=>{var i;return G(t)||"function"==typeof(null===(i=t)||void 0===i?void 0:i[Symbol.iterator])})(t)?this.S(t):this.$(t)}A(t,i=this._$AB){return this._$AA.parentNode.insertBefore(t,i)}k(t){this._$AH!==t&&(this._$AR(),this._$AH=this.A(t))}$(t){this._$AH!==X&&V(this._$AH)?this._$AA.nextSibling.data=t:this.k(D.createTextNode(t)),this._$AH=t}T(t){var i;const{values:s,_$litType$:n}=t,e="number"==typeof n?this._$AC(t):(void 0===n.el&&(n.el=nt.createElement(n.h,this.options)),n);if((null===(i=this._$AH)||void 0===i?void 0:i._$AD)===e)this._$AH.m(s);else{const t=new ot(e,this),i=t.p(this.options);t.m(s),this.k(i),this._$AH=t}}_$AC(t){let i=Y.get(t.strings);return void 0===i&&Y.set(t.strings,i=new nt(t)),i}S(t){G(this._$AH)||(this._$AH=[],this._$AR());const i=this._$AH;let s,n=0;for(const e of t)n===i.length?i.push(s=new rt(this.A(I()),this.A(I()),this,this.options)):s=i[n],s._$AI(e),n++;n<i.length&&(this._$AR(s&&s._$AB.nextSibling,n),i.length=n)}_$AR(t=this._$AA.nextSibling,i){var s;for(null===(s=this._$AP)||void 0===s||s.call(this,!1,!0,i);t&&t!==this._$AB;){const i=t.nextSibling;t.remove(),t=i}}setConnected(t){var i;void 0===this._$AM&&(this._$Cg=t,null===(i=this._$AP)||void 0===i||i.call(this,t))}}class ht{constructor(t,i,s,n,e){this.type=1,this._$AH=X,this._$AN=void 0,this.element=t,this.name=i,this._$AM=n,this.options=e,s.length>2||""!==s[0]||""!==s[1]?(this._$AH=Array(s.length-1).fill(new String),this.strings=s):this._$AH=X}get tagName(){return this.element.tagName}get _$AU(){return this._$AM._$AU}_$AI(t,i=this,s,n){const e=this.strings;let o=!1;if(void 0===e)t=et(this,t,i,0),o=!V(t)||t!==this._$AH&&t!==Q,o&&(this._$AH=t);else{const n=t;let r,h;for(t=e[0],r=0;r<e.length-1;r++)h=et(this,n[s+r],i,r),h===Q&&(h=this._$AH[r]),o||(o=!V(h)||h!==this._$AH[r]),h===X?t=X:t!==X&&(t+=(null!=h?h:"")+e[r+1]),this._$AH[r]=h}o&&!n&&this.C(t)}C(t){t===X?this.element.removeAttribute(this.name):this.element.setAttribute(this.name,null!=t?t:"")}}class ct extends ht{constructor(){super(...arguments),this.type=3}C(t){this.element[this.name]=t===X?void 0:t}}const lt=S?S.emptyScript:"";class ut extends ht{constructor(){super(...arguments),this.type=4}C(t){t&&t!==X?this.element.setAttribute(this.name,lt):this.element.removeAttribute(this.name)}}class dt extends ht{constructor(t,i,s,n,e){super(t,i,s,n,e),this.type=5}_$AI(t,i=this){var s;if((t=null!==(s=et(this,t,i,0))&&void 0!==s?s:X)===Q)return;const n=this._$AH,e=t===X&&n!==X||t.capture!==n.capture||t.once!==n.once||t.passive!==n.passive,o=t!==X&&(n===X||e);e&&this.element.removeEventListener(this.name,this,n),o&&this.element.addEventListener(this.name,this,t),this._$AH=t}handleEvent(t){var i,s;"function"==typeof this._$AH?this._$AH.call(null!==(s=null===(i=this.options)||void 0===i?void 0:i.host)&&void 0!==s?s:this.element,t):this._$AH.handleEvent(t)}}class at{constructor(t,i,s){this.element=t,this.type=6,this._$AN=void 0,this._$AM=i,this.options=s}get _$AU(){return this._$AM._$AU}_$AI(t){et(this,t)}}const ft=window.litHtmlPolyfillSupport;null==ft||ft(nt,rt),(null!==(C=globalThis.litHtmlVersions)&&void 0!==C?C:globalThis.litHtmlVersions=[]).push("2.2.0");
|
|
8
8
|
/**
|
|
9
9
|
* @license
|
|
10
10
|
* Copyright 2017 Google LLC
|
|
@@ -15,5 +15,5 @@ const vt=2,pt=5,yt=t=>(...i)=>({_$litDirective$:t,values:i});class bt{constructo
|
|
|
15
15
|
* @license
|
|
16
16
|
* Copyright 2017 Google LLC
|
|
17
17
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
18
|
-
*/class gt extends bt{constructor(t){if(super(t),this.it=X,t.type!==vt)throw Error(this.constructor.directiveName+"() can only be used in child bindings")}render(t){if(t===X||null==t)return this.
|
|
18
|
+
*/class gt extends bt{constructor(t){if(super(t),this.it=X,t.type!==vt)throw Error(this.constructor.directiveName+"() can only be used in child bindings")}render(t){if(t===X||null==t)return this.ft=void 0,this.it=t;if(t===Q)return t;if("string"!=typeof t)throw Error(this.constructor.directiveName+"() called with a non-string value");if(t===this.it)return this.ft;this.it=t;const i=[t];return i.raw=i,this.ft={_$litType$:this.constructor.resultType,strings:i,values:[]}}}gt.directiveName="unsafeHTML",gt.resultType=1;const wt=yt(gt);function mt(t,i,s){i&&("string"==typeof i?(t._$litPart$||t.replaceChildren(),tt(K`${wt(i)}`,t)):"_$litType$"in i?(t._$litPart$||t.replaceChildren(),tt(i,t)):(c(t,i,s),t._$litPart$=void 0))}const $t=yt(class extends bt{constructor(t){if(super(t),t.type!==pt)throw new Error("${run} can only be used in event handlers")}update(t,i){let{element:s,name:n}=t;const e=()=>{let t=s._component;for(;!t&&s;)s=s.parentElement,t=s&&s._component;return console.assert(!!t,"Component not found."),t},[o,...r]=i;return"string"==typeof o?s[`on${n}`]=t=>e().run(o,...r,t):"function"==typeof o&&(s[`on${n}`]=t=>e().setState(o(e().state,...r,t))),this.render()}render(){return Q}});n.createElement=r,n.render=mt,n.Fragment=e,"object"==typeof window&&(window.html=K,window.svg=B,window.run=$t);export{x as Component,T as ROUTER_404_EVENT,k as ROUTER_EVENT,n as app,m as customElement,n as default,g as event,K as html,w as on,mt as render,$t as run,B as svg,g as update};
|
|
19
19
|
//# sourceMappingURL=apprun-html.esm.js.map
|