@mantou/gem 1.6.2 → 1.6.8
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/README.md +6 -38
- package/{umd.d.ts → all.d.ts} +1 -5
- package/all.d.ts.map +1 -0
- package/all.js +14 -0
- package/all.js.map +1 -0
- package/elements/dialog-base.d.ts +2 -2
- package/elements/dialog-base.d.ts.map +1 -1
- package/elements/dialog-base.js +6 -6
- package/elements/dialog-base.js.map +1 -1
- package/elements/gesture.d.ts +2 -1
- package/elements/gesture.d.ts.map +1 -1
- package/elements/gesture.js +6 -5
- package/elements/gesture.js.map +1 -1
- package/elements/link.d.ts +1 -1
- package/elements/link.d.ts.map +1 -1
- package/elements/link.js +11 -16
- package/elements/link.js.map +1 -1
- package/elements/modal-base.d.ts +4 -4
- package/elements/modal-base.d.ts.map +1 -1
- package/elements/modal-base.js +9 -4
- package/elements/modal-base.js.map +1 -1
- package/elements/reflect.d.ts +1 -1
- package/elements/reflect.d.ts.map +1 -1
- package/elements/reflect.js +2 -1
- package/elements/reflect.js.map +1 -1
- package/elements/route.d.ts +7 -3
- package/elements/route.d.ts.map +1 -1
- package/elements/route.js +12 -6
- package/elements/route.js.map +1 -1
- package/elements/title.d.ts +1 -1
- package/elements/title.d.ts.map +1 -1
- package/elements/title.js +4 -1
- package/elements/title.js.map +1 -1
- package/elements/unsafe.d.ts +1 -1
- package/elements/unsafe.d.ts.map +1 -1
- package/elements/unsafe.js +2 -1
- package/elements/unsafe.js.map +1 -1
- package/elements/use.d.ts +1 -1
- package/elements/use.d.ts.map +1 -1
- package/elements/use.js +2 -1
- package/elements/use.js.map +1 -1
- package/helper/i18n.js +47 -58
- package/helper/i18n.js.map +1 -1
- package/helper/request.js +11 -19
- package/helper/request.js.map +1 -1
- package/index.d.ts +5 -4
- package/index.d.ts.map +1 -1
- package/index.js +4 -2
- package/index.js.map +1 -1
- package/lib/element.d.ts.map +1 -1
- package/lib/element.js +2 -2
- package/lib/element.js.map +1 -1
- package/lib/history.js +17 -5
- package/lib/history.js.map +1 -1
- package/lib/utils.d.ts +3 -1
- package/lib/utils.d.ts.map +1 -1
- package/lib/utils.js +7 -4
- package/lib/utils.js.map +1 -1
- package/lib/version.d.ts +1 -1
- package/lib/version.js +1 -1
- package/package.json +23 -53
- package/src/{umd.ts → all.ts} +0 -4
- package/src/elements/dialog-base.ts +5 -4
- package/src/elements/gesture.ts +2 -1
- package/src/elements/link.ts +5 -15
- package/src/elements/modal-base.ts +3 -1
- package/src/elements/reflect.ts +2 -1
- package/src/elements/route.ts +8 -20
- package/src/elements/title.ts +4 -1
- package/src/elements/unsafe.ts +2 -1
- package/src/elements/use.ts +2 -1
- package/src/index.ts +4 -6
- package/src/lib/element.ts +3 -2
- package/src/lib/history.ts +1 -1
- package/src/lib/utils.ts +10 -4
- package/src/lib/version.ts +1 -1
- package/src/test/gem-element/advance.test.ts +1 -0
- package/src/test/gem-element/basic.test.ts +1 -0
- package/src/test/gem-element/decorators.test.ts +1 -0
- package/src/test/gem-element/multi.test.ts +1 -0
- package/src/test/history.test.ts +1 -0
- package/src/test/store.test.ts +1 -0
- package/src/test/utils.test.ts +1 -0
- package/src/examples/base-path/index.ts +0 -44
- package/src/examples/controlled/index.ts +0 -75
- package/src/examples/decorator/chidren.ts +0 -77
- package/src/examples/decorator/index.ts +0 -110
- package/src/examples/dialog/index.ts +0 -148
- package/src/examples/effect/index.ts +0 -45
- package/src/examples/elements/env.ts +0 -7
- package/src/examples/elements/layout.ts +0 -53
- package/src/examples/elements/nav.ts +0 -71
- package/src/examples/elements/source.ts +0 -68
- package/src/examples/gesture/canvas.ts +0 -69
- package/src/examples/gesture/index.ts +0 -97
- package/src/examples/gesture/manifest.json +0 -3
- package/src/examples/hash/index.ts +0 -55
- package/src/examples/i18n/index.ts +0 -63
- package/src/examples/index/index.ts +0 -33
- package/src/examples/index/manifest.json +0 -5
- package/src/examples/light-dom/index.ts +0 -31
- package/src/examples/multi-page/api.ts +0 -9
- package/src/examples/multi-page/index.ts +0 -78
- package/src/examples/multi-page/page-a.ts +0 -16
- package/src/examples/multi-page/page-b.ts +0 -12
- package/src/examples/multi-page/page-c.ts +0 -40
- package/src/examples/multi-page/store.ts +0 -10
- package/src/examples/perf-demo/index.ts +0 -136
- package/src/examples/ref-route/index.ts +0 -109
- package/src/examples/reflect/index.ts +0 -61
- package/src/examples/styled/index.ts +0 -39
- package/src/examples/svg-icon/index.ts +0 -31
- package/src/examples/theme/index.ts +0 -56
- package/src/examples/unsafe/index.ts +0 -29
- package/umd.d.ts.map +0 -1
- package/umd.js +0 -54
- package/umd.js.LICENSE.txt +0 -13
- package/umd.js.map +0 -1
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
import { render, GemElement, html, customElement, refobject, RefObject } from '../..';
|
|
2
|
-
|
|
3
|
-
import '../../elements/gesture';
|
|
4
|
-
import { PanEventDetail, PinchEventDetail, RotateEventDetail, SwipeEventDetail } from '../../elements/gesture';
|
|
5
|
-
import '../elements/layout';
|
|
6
|
-
import './canvas';
|
|
7
|
-
|
|
8
|
-
@customElement('app-root')
|
|
9
|
-
export class AppRoot extends GemElement {
|
|
10
|
-
@refobject gestureRef: RefObject<any>;
|
|
11
|
-
state = {
|
|
12
|
-
x: 0,
|
|
13
|
-
y: 0,
|
|
14
|
-
duration: 0,
|
|
15
|
-
scale: 1,
|
|
16
|
-
rotate: 0,
|
|
17
|
-
swipe: '',
|
|
18
|
-
moves: [],
|
|
19
|
-
};
|
|
20
|
-
onPan = (evt: CustomEvent<PanEventDetail>) => {
|
|
21
|
-
const { detail } = evt;
|
|
22
|
-
const { x, y } = this.state;
|
|
23
|
-
this.setState({ x: detail.x + x, y: detail.y + y, duration: 0 });
|
|
24
|
-
};
|
|
25
|
-
onPinch = (evt: CustomEvent<PinchEventDetail>) => {
|
|
26
|
-
this.setState({ scale: evt.detail.scale * this.state.scale });
|
|
27
|
-
};
|
|
28
|
-
onRotate = (evt: CustomEvent<RotateEventDetail>) => {
|
|
29
|
-
this.setState({ rotate: evt.detail.rotate + this.state.rotate });
|
|
30
|
-
};
|
|
31
|
-
onSwipe = (e: CustomEvent<SwipeEventDetail>) => {
|
|
32
|
-
this.setState({ swipe: `${e.detail.direction}, speed: ${e.detail.speed}` });
|
|
33
|
-
};
|
|
34
|
-
onEnd = () => {
|
|
35
|
-
this.setState({
|
|
36
|
-
x: 0,
|
|
37
|
-
y: 0,
|
|
38
|
-
duration: 0.5,
|
|
39
|
-
scale: 1,
|
|
40
|
-
rotate: 0,
|
|
41
|
-
swipe: '',
|
|
42
|
-
moves: [...this.gestureRef.element.movesMap.values().next().value],
|
|
43
|
-
});
|
|
44
|
-
};
|
|
45
|
-
render() {
|
|
46
|
-
const { x, y, scale, rotate, duration, swipe, moves } = this.state;
|
|
47
|
-
return html`
|
|
48
|
-
<style>
|
|
49
|
-
img {
|
|
50
|
-
translate: ${x}px ${y}px;
|
|
51
|
-
scale: ${scale};
|
|
52
|
-
rotate: ${rotate}deg;
|
|
53
|
-
transition: all ${duration}s;
|
|
54
|
-
}
|
|
55
|
-
</style>
|
|
56
|
-
<gem-gesture
|
|
57
|
-
ref=${this.gestureRef.ref}
|
|
58
|
-
@pan=${this.onPan}
|
|
59
|
-
@end=${this.onEnd}
|
|
60
|
-
@pinch=${this.onPinch}
|
|
61
|
-
@rotate=${this.onRotate}
|
|
62
|
-
@press=${console.log}
|
|
63
|
-
@swipe=${this.onSwipe}
|
|
64
|
-
touch-action="pan-y"
|
|
65
|
-
>
|
|
66
|
-
<gem-gesture
|
|
67
|
-
@pan=${console.log}
|
|
68
|
-
@end=${console.log}
|
|
69
|
-
@pinch=${console.log}
|
|
70
|
-
@rotate=${console.log}
|
|
71
|
-
@press=${console.log}
|
|
72
|
-
@swipe=${console.log}
|
|
73
|
-
touch-action="pan-y"
|
|
74
|
-
>
|
|
75
|
-
<img src="https://gem-book.js.org/logo.png" width="200" />
|
|
76
|
-
</gem-gesture>
|
|
77
|
-
<div>${moves[moves.length - 1] ? `${JSON.stringify(moves[moves.length - 1])}` : ''}</div>
|
|
78
|
-
<div>${swipe}</div>
|
|
79
|
-
<app-canvas .data=${moves}></app-canvas>
|
|
80
|
-
</gem-gesture>
|
|
81
|
-
`;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
render(
|
|
86
|
-
html`
|
|
87
|
-
<style>
|
|
88
|
-
body {
|
|
89
|
-
overscroll-behavior: contain;
|
|
90
|
-
}
|
|
91
|
-
</style>
|
|
92
|
-
<gem-examples-layout>
|
|
93
|
-
<app-root slot="main"></app-root>
|
|
94
|
-
</gem-examples-layout>
|
|
95
|
-
`,
|
|
96
|
-
document.body,
|
|
97
|
-
);
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { GemElement, render, html } from '../../';
|
|
2
|
-
import '../../elements/link';
|
|
3
|
-
|
|
4
|
-
import '../elements/layout';
|
|
5
|
-
|
|
6
|
-
class Article extends GemElement {
|
|
7
|
-
constructor() {
|
|
8
|
-
super();
|
|
9
|
-
window.addEventListener('hashchange', this.checkHash);
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
mounted = () => {
|
|
13
|
-
// 在当前页面刷新浏览器会保留滚动位置
|
|
14
|
-
// 开新窗口测试带 hash 链接
|
|
15
|
-
this.checkHash();
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
unmounted = () => {
|
|
19
|
-
window.removeEventListener('hashchange', this.checkHash);
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
checkHash = () => {
|
|
23
|
-
if (this.id === location.hash.substr(1)) {
|
|
24
|
-
this.scrollIntoView();
|
|
25
|
-
}
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
render() {
|
|
29
|
-
return html`<div style="height: 1000px"><slot></slot></div>`;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
customElements.define('app-article', Article);
|
|
33
|
-
|
|
34
|
-
class App extends GemElement {
|
|
35
|
-
render() {
|
|
36
|
-
return html`
|
|
37
|
-
<a href="#article-1">${'<a href="#article-1">'}</a>
|
|
38
|
-
<a href="#article-2">${'<a href="#article-2">'}</a>
|
|
39
|
-
<gem-link path="/" hash="#article-1"><button>go #article-1</button></gem-link>
|
|
40
|
-
<gem-link path="/" hash="#article-2"><button>go #article-2</button></gem-link>
|
|
41
|
-
<app-article id="article-1" style="display: block; margin-top: 100px;">article-1</app-article>
|
|
42
|
-
<app-article id="article-2" style="display: block; margin-top: 100px;">article-2</app-article>
|
|
43
|
-
`;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
customElements.define('app-root', App);
|
|
47
|
-
|
|
48
|
-
render(
|
|
49
|
-
html`
|
|
50
|
-
<gem-examples-layout>
|
|
51
|
-
<app-root slot="main"></app-root>
|
|
52
|
-
</gem-examples-layout>
|
|
53
|
-
`,
|
|
54
|
-
document.body,
|
|
55
|
-
);
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import { GemElement, html, connectStore, customElement, render } from '../../';
|
|
2
|
-
|
|
3
|
-
import '../elements/layout';
|
|
4
|
-
|
|
5
|
-
import { I18n } from '../../helper/i18n';
|
|
6
|
-
|
|
7
|
-
const en = {
|
|
8
|
-
title: 'This is I18n',
|
|
9
|
-
hello: 'Hello, $1! $2=> $1, Hello!',
|
|
10
|
-
detail: 'See $1<detail>, $1<detail2>',
|
|
11
|
-
};
|
|
12
|
-
const i18n = new I18n<typeof en>({
|
|
13
|
-
cache: true,
|
|
14
|
-
fallbackLanguage: 'en',
|
|
15
|
-
resources: {
|
|
16
|
-
en,
|
|
17
|
-
de: {
|
|
18
|
-
title: 'Das ist I18n',
|
|
19
|
-
},
|
|
20
|
-
zh: 'data:text/plain;base64,eyJ0aXRsZSI6Iui/meaYr0kxOG4ifQ==',
|
|
21
|
-
},
|
|
22
|
-
onChange: console.log,
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
const i18nModule = i18n.createSubModule<typeof en>('test', {
|
|
26
|
-
en,
|
|
27
|
-
de: {
|
|
28
|
-
title: 'Das ist I18n',
|
|
29
|
-
},
|
|
30
|
-
zh: 'data:text/plain;base64,eyJ0aXRsZSI6Iui/meaYr0kxOG4ifQ==',
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
@connectStore(i18n.store)
|
|
34
|
-
@connectStore(i18nModule.store)
|
|
35
|
-
@customElement('app-root')
|
|
36
|
-
export class App extends GemElement {
|
|
37
|
-
render() {
|
|
38
|
-
return html`
|
|
39
|
-
<button @click=${() => i18n.setLanguage('de')}>de</button>
|
|
40
|
-
<button @click=${() => i18n.setLanguage('zh')}>zh</button>
|
|
41
|
-
<button @click=${() => i18n.setLanguage('en')}>en</button>
|
|
42
|
-
<button @click=${() => i18n.resetLanguage()}>reset</button>
|
|
43
|
-
<p>Current language: ${i18n.currentLanguage}</p>
|
|
44
|
-
<p>${i18n.get('title')}</p>
|
|
45
|
-
<p>${i18n.get('hello', 'World', 'reverse')}</p>
|
|
46
|
-
<p>${i18n.get('detail', (s) => html`<a href="#">${s}</a>`)}</p>
|
|
47
|
-
|
|
48
|
-
<h2>sub module</h2>
|
|
49
|
-
<p>${i18nModule.get('title')}</p>
|
|
50
|
-
<p>${i18nModule.get('hello', 'World', 'reverse')}</p>
|
|
51
|
-
<p>${i18nModule.get('detail', (s) => html`<a href="#">${s}</a>`)}</p>
|
|
52
|
-
`;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
render(
|
|
57
|
-
html`
|
|
58
|
-
<gem-examples-layout>
|
|
59
|
-
<app-root slot="main"></app-root>
|
|
60
|
-
</gem-examples-layout>
|
|
61
|
-
`,
|
|
62
|
-
document.body,
|
|
63
|
-
);
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { render, GemElement, createStore, updateStore, html } from '../../';
|
|
2
|
-
import { connectStore, customElement } from '../../lib/decorators';
|
|
3
|
-
|
|
4
|
-
import '../elements/layout';
|
|
5
|
-
|
|
6
|
-
// 新建全局数据对象
|
|
7
|
-
const store = createStore({
|
|
8
|
-
a: 1,
|
|
9
|
-
});
|
|
10
|
-
|
|
11
|
-
// 定义自定义元素
|
|
12
|
-
@customElement('app-root')
|
|
13
|
-
@connectStore(store)
|
|
14
|
-
export class HelloWorld extends GemElement {
|
|
15
|
-
clickHandle = () => {
|
|
16
|
-
updateStore(store, { a: ++store.a });
|
|
17
|
-
};
|
|
18
|
-
render() {
|
|
19
|
-
return html`
|
|
20
|
-
<button @click="${this.clickHandle}">Hello, World</button>
|
|
21
|
-
<div>store.a: ${store.a}</div>
|
|
22
|
-
`;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
render(
|
|
27
|
-
html`
|
|
28
|
-
<gem-examples-layout>
|
|
29
|
-
<app-root slot="main"></app-root>
|
|
30
|
-
</gem-examples-layout>
|
|
31
|
-
`,
|
|
32
|
-
document.body,
|
|
33
|
-
);
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { GemElement, html, render } from '../../';
|
|
2
|
-
|
|
3
|
-
import '../elements/layout';
|
|
4
|
-
|
|
5
|
-
export class App extends GemElement {
|
|
6
|
-
state = { now: 0 };
|
|
7
|
-
constructor() {
|
|
8
|
-
super({ isLight: true });
|
|
9
|
-
setInterval(() => {
|
|
10
|
-
this.setState({ now: Date.now() });
|
|
11
|
-
}, 1000);
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
render() {
|
|
15
|
-
return html`
|
|
16
|
-
<div>hello world!</div>
|
|
17
|
-
<time>${this.state.now}</time>
|
|
18
|
-
`;
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
customElements.define('app-root', App);
|
|
23
|
-
|
|
24
|
-
render(
|
|
25
|
-
html`
|
|
26
|
-
<gem-examples-layout>
|
|
27
|
-
<app-root slot="main"></app-root>
|
|
28
|
-
</gem-examples-layout>
|
|
29
|
-
`,
|
|
30
|
-
document.body,
|
|
31
|
-
);
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import { GemElement, html, render } from '../../';
|
|
2
|
-
import { GemTitleElement } from '../../elements/title';
|
|
3
|
-
import '../../elements/route';
|
|
4
|
-
import '../../elements/link';
|
|
5
|
-
|
|
6
|
-
import '../elements/layout';
|
|
7
|
-
|
|
8
|
-
import './page-b';
|
|
9
|
-
import './page-c';
|
|
10
|
-
|
|
11
|
-
const routes = [
|
|
12
|
-
{
|
|
13
|
-
pattern: '/',
|
|
14
|
-
redirect: '/c/e',
|
|
15
|
-
},
|
|
16
|
-
{
|
|
17
|
-
title: 'Page A Title',
|
|
18
|
-
pattern: '/a',
|
|
19
|
-
get content() {
|
|
20
|
-
import('./page-a');
|
|
21
|
-
return html`<app-page-a>A: </app-page-a>`;
|
|
22
|
-
},
|
|
23
|
-
},
|
|
24
|
-
{
|
|
25
|
-
title: 'Page B Title',
|
|
26
|
-
pattern: '/B',
|
|
27
|
-
content: html` <app-page-b>B: </app-page-b> `,
|
|
28
|
-
},
|
|
29
|
-
{
|
|
30
|
-
title: 'Page C Title',
|
|
31
|
-
pattern: '/c/*',
|
|
32
|
-
content: html`<app-page-c>C: </app-page-c>`,
|
|
33
|
-
},
|
|
34
|
-
{
|
|
35
|
-
pattern: '/',
|
|
36
|
-
content: html`<div>hello</div>`,
|
|
37
|
-
},
|
|
38
|
-
];
|
|
39
|
-
|
|
40
|
-
class App extends GemElement {
|
|
41
|
-
render() {
|
|
42
|
-
return html`
|
|
43
|
-
<style>
|
|
44
|
-
:host {
|
|
45
|
-
text-align: center;
|
|
46
|
-
}
|
|
47
|
-
gem-link {
|
|
48
|
-
cursor: pointer;
|
|
49
|
-
}
|
|
50
|
-
gem-link + gem-link {
|
|
51
|
-
margin-left: 0.5em;
|
|
52
|
-
}
|
|
53
|
-
gem-link:hover {
|
|
54
|
-
text-decoration: underline;
|
|
55
|
-
}
|
|
56
|
-
</style>
|
|
57
|
-
<header><gem-title suffix=${GemTitleElement.defaultSuffix}>AppName</gem-title></header>
|
|
58
|
-
<nav>
|
|
59
|
-
<gem-link path="/">Home</gem-link>
|
|
60
|
-
<gem-link path="/A">PageA</gem-link>
|
|
61
|
-
<gem-link path="/b">PageB</gem-link>
|
|
62
|
-
<gem-link path="/c/e" pattern="/c/*">PageC</gem-link>
|
|
63
|
-
</nav>
|
|
64
|
-
<main><gem-light-route .routes=${routes}></gem-light-route></main>
|
|
65
|
-
`;
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
customElements.define('app-root', App);
|
|
70
|
-
|
|
71
|
-
render(
|
|
72
|
-
html`
|
|
73
|
-
<gem-examples-layout>
|
|
74
|
-
<app-root slot="main"></app-root>
|
|
75
|
-
</gem-examples-layout>
|
|
76
|
-
`,
|
|
77
|
-
document.body,
|
|
78
|
-
);
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { GemElement, html } from '../../';
|
|
2
|
-
import storeSet from './store';
|
|
3
|
-
import api from './api';
|
|
4
|
-
|
|
5
|
-
customElements.define(
|
|
6
|
-
'app-page-a',
|
|
7
|
-
class extends GemElement {
|
|
8
|
-
static observedStores = [storeSet.pageA];
|
|
9
|
-
mounted() {
|
|
10
|
-
api.getData();
|
|
11
|
-
}
|
|
12
|
-
render() {
|
|
13
|
-
return html`<slot></slot> ${storeSet.pageA.text}`;
|
|
14
|
-
}
|
|
15
|
-
},
|
|
16
|
-
);
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { GemElement, html } from '../../';
|
|
2
|
-
import storeSet from './store';
|
|
3
|
-
|
|
4
|
-
customElements.define(
|
|
5
|
-
'app-page-b',
|
|
6
|
-
class extends GemElement {
|
|
7
|
-
static observedStores = [storeSet.pageB];
|
|
8
|
-
render() {
|
|
9
|
-
return html`<slot></slot> ${storeSet.pageB.text}`;
|
|
10
|
-
}
|
|
11
|
-
},
|
|
12
|
-
);
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { GemElement, html } from '../../';
|
|
2
|
-
import '../../elements/route';
|
|
3
|
-
import '../../elements/link';
|
|
4
|
-
|
|
5
|
-
const routes = [
|
|
6
|
-
{
|
|
7
|
-
title: 'ccccccd',
|
|
8
|
-
pattern: '/c/d',
|
|
9
|
-
content: html`<div>C/D</div>`,
|
|
10
|
-
},
|
|
11
|
-
{
|
|
12
|
-
// `title` 未设置会使用父路由标题
|
|
13
|
-
pattern: '/c/e',
|
|
14
|
-
content: html`<div>C/E</div>`,
|
|
15
|
-
},
|
|
16
|
-
{
|
|
17
|
-
pattern: '/c/*',
|
|
18
|
-
content: html`<div>C/E</div>`,
|
|
19
|
-
},
|
|
20
|
-
];
|
|
21
|
-
|
|
22
|
-
customElements.define(
|
|
23
|
-
'app-page-c',
|
|
24
|
-
class extends GemElement {
|
|
25
|
-
render() {
|
|
26
|
-
return html`
|
|
27
|
-
<style>
|
|
28
|
-
gem-link + gem-link {
|
|
29
|
-
margin-left: 0.5em;
|
|
30
|
-
}
|
|
31
|
-
</style>
|
|
32
|
-
<gem-link path="./d">Page c/d</gem-link>
|
|
33
|
-
<gem-link path="./e">Page c/e</gem-link>
|
|
34
|
-
<gem-route .routes=${routes}></gem-route>
|
|
35
|
-
inert route:
|
|
36
|
-
<gem-route ?inert=${true} .routes=${routes}></gem-route>
|
|
37
|
-
`;
|
|
38
|
-
}
|
|
39
|
-
},
|
|
40
|
-
);
|
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
import { raw, GemElement, createStore, updateStore, html } from '../../';
|
|
2
|
-
|
|
3
|
-
const store = createStore({
|
|
4
|
-
number: 1,
|
|
5
|
-
});
|
|
6
|
-
|
|
7
|
-
setInterval(() => {
|
|
8
|
-
updateStore(store, { number: (store.number % 10) + 1 });
|
|
9
|
-
}, 1000);
|
|
10
|
-
|
|
11
|
-
customElements.define(
|
|
12
|
-
'fiber-dot',
|
|
13
|
-
class extends GemElement {
|
|
14
|
-
static observedStores = [store];
|
|
15
|
-
constructor() {
|
|
16
|
-
super({ isAsync: true });
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
onmouseenter = () => {
|
|
20
|
-
this.setState({ hover: true });
|
|
21
|
-
};
|
|
22
|
-
onmouseleave = () => {
|
|
23
|
-
this.setState({ hover: false });
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
size: number;
|
|
27
|
-
x: number;
|
|
28
|
-
y: number;
|
|
29
|
-
|
|
30
|
-
state = { hover: false };
|
|
31
|
-
|
|
32
|
-
render() {
|
|
33
|
-
const s = this.size * 1.3;
|
|
34
|
-
Object.assign(this.style, {
|
|
35
|
-
width: s + 'px',
|
|
36
|
-
height: s + 'px',
|
|
37
|
-
left: this.x + 'px',
|
|
38
|
-
top: this.y + 'px',
|
|
39
|
-
borderRadius: s / 2 + 'px',
|
|
40
|
-
lineHeight: s + 'px',
|
|
41
|
-
background: this.state.hover ? '#ff0' : '#61dafb',
|
|
42
|
-
});
|
|
43
|
-
return html`
|
|
44
|
-
<style>
|
|
45
|
-
:host {
|
|
46
|
-
position: absolute;
|
|
47
|
-
font: normal 15px sans-serif;
|
|
48
|
-
text-align: center;
|
|
49
|
-
cursor: pointer;
|
|
50
|
-
display: block;
|
|
51
|
-
}
|
|
52
|
-
</style>
|
|
53
|
-
${this.state.hover ? '**' + store.number + '**' : store.number}
|
|
54
|
-
`;
|
|
55
|
-
}
|
|
56
|
-
},
|
|
57
|
-
);
|
|
58
|
-
|
|
59
|
-
const targetSize = 25;
|
|
60
|
-
customElements.define(
|
|
61
|
-
'fiber-triangle',
|
|
62
|
-
class extends GemElement {
|
|
63
|
-
x: number;
|
|
64
|
-
y: number;
|
|
65
|
-
s: number;
|
|
66
|
-
seconds: number;
|
|
67
|
-
|
|
68
|
-
render() {
|
|
69
|
-
let s = this.s;
|
|
70
|
-
if (s <= targetSize) {
|
|
71
|
-
return html`
|
|
72
|
-
<fiber-dot .x=${this.x - targetSize / 2} .y=${this.y - targetSize / 2} .size=${targetSize}></fiber-dot>
|
|
73
|
-
`;
|
|
74
|
-
}
|
|
75
|
-
s = s / 2;
|
|
76
|
-
|
|
77
|
-
const slowDown = true;
|
|
78
|
-
if (slowDown) {
|
|
79
|
-
const e = performance.now() + 0.8;
|
|
80
|
-
while (performance.now() < e) {
|
|
81
|
-
// Artificially long execution time.
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
return html`
|
|
85
|
-
<fiber-triangle .x=${this.x} .y=${this.y - s / 2} .s=${s}></fiber-triangle>
|
|
86
|
-
<fiber-triangle .x=${this.x - s} .y=${this.y + s / 2} .s=${s}></fiber-triangle>
|
|
87
|
-
<fiber-triangle .x=${this.x + s} .y=${this.y + s / 2} .s=${s}></fiber-triangle>
|
|
88
|
-
`;
|
|
89
|
-
}
|
|
90
|
-
},
|
|
91
|
-
);
|
|
92
|
-
|
|
93
|
-
class App extends GemElement {
|
|
94
|
-
static observedPropertys = ['elapsed'];
|
|
95
|
-
elapsed = 0;
|
|
96
|
-
render() {
|
|
97
|
-
const elapsed = this.elapsed;
|
|
98
|
-
const t = (elapsed / 1000) % 10;
|
|
99
|
-
const scale = 1 + (t > 5 ? 10 - t : t) / 10;
|
|
100
|
-
this.style.transform = 'scaleX(' + scale / 2.1 + ') scaleY(0.7) translateZ(0.1px)';
|
|
101
|
-
return html`
|
|
102
|
-
<style>
|
|
103
|
-
:host {
|
|
104
|
-
position: absolute;
|
|
105
|
-
transform-origin: 0 0;
|
|
106
|
-
left: 50%;
|
|
107
|
-
top: 50%;
|
|
108
|
-
width: 10px;
|
|
109
|
-
height: 10px;
|
|
110
|
-
background: #eee;
|
|
111
|
-
}
|
|
112
|
-
</style>
|
|
113
|
-
<div>
|
|
114
|
-
<fiber-triangle .x=${0} .y=${0} .s=${1000}></fiber-triangle>
|
|
115
|
-
</div>
|
|
116
|
-
`;
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
customElements.define('app-root', App);
|
|
120
|
-
|
|
121
|
-
document.body.innerHTML = raw`
|
|
122
|
-
<ul>
|
|
123
|
-
<li><a href="https://stencil-fiber-demo.firebaseapp.com/perf.html">stencil-fiber-demo</a></li>
|
|
124
|
-
<li><a href="https://claudiopro.github.io/react-fiber-vs-stack-demo/fiber.html">react-fiber-demo</a></li>
|
|
125
|
-
</ul>
|
|
126
|
-
`;
|
|
127
|
-
|
|
128
|
-
const app = new App();
|
|
129
|
-
document.body.append(app);
|
|
130
|
-
|
|
131
|
-
const start = Date.now();
|
|
132
|
-
function update() {
|
|
133
|
-
app.elapsed = Date.now() - start;
|
|
134
|
-
requestAnimationFrame(update);
|
|
135
|
-
}
|
|
136
|
-
requestAnimationFrame(update);
|