@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,77 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
GemElement,
|
|
3
|
-
html,
|
|
4
|
-
property,
|
|
5
|
-
attribute,
|
|
6
|
-
slot,
|
|
7
|
-
part,
|
|
8
|
-
state,
|
|
9
|
-
emitter,
|
|
10
|
-
Emitter,
|
|
11
|
-
customElement,
|
|
12
|
-
numattribute,
|
|
13
|
-
boolattribute,
|
|
14
|
-
rootElement,
|
|
15
|
-
} from '../../';
|
|
16
|
-
|
|
17
|
-
export type Message = number[];
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* @attr first-name
|
|
21
|
-
* @attr last-name
|
|
22
|
-
* @attr count
|
|
23
|
-
* @attr disabled
|
|
24
|
-
* @fires say-hi
|
|
25
|
-
* @fires load
|
|
26
|
-
* @state odd
|
|
27
|
-
* @slot light
|
|
28
|
-
* @part paragraph
|
|
29
|
-
*/
|
|
30
|
-
@customElement('app-children')
|
|
31
|
-
@rootElement('app-root')
|
|
32
|
-
export class Children extends GemElement {
|
|
33
|
-
@slot static light: string;
|
|
34
|
-
@part static paragraph: string;
|
|
35
|
-
|
|
36
|
-
@attribute firstName: string;
|
|
37
|
-
@attribute lastName: string;
|
|
38
|
-
@numattribute count: number;
|
|
39
|
-
@boolattribute disabled: boolean;
|
|
40
|
-
@property message: Message | undefined;
|
|
41
|
-
@emitter sayHi: Emitter;
|
|
42
|
-
@emitter load: Emitter;
|
|
43
|
-
@state odd: boolean;
|
|
44
|
-
|
|
45
|
-
constructor() {
|
|
46
|
-
super();
|
|
47
|
-
console.log('child cons');
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
mounted = () => {
|
|
51
|
-
console.log('child mounted');
|
|
52
|
-
setTimeout(() => this.load(new Date()), 1000);
|
|
53
|
-
this.addEventListener('click', () => {
|
|
54
|
-
this.odd = !this.odd;
|
|
55
|
-
});
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
updated = () => {
|
|
59
|
-
console.log('child updated');
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
render() {
|
|
63
|
-
console.log('child render');
|
|
64
|
-
return html`
|
|
65
|
-
<p>
|
|
66
|
-
attributes:
|
|
67
|
-
<span>${this.firstName},</span>
|
|
68
|
-
<span>${this.lastName},</span>
|
|
69
|
-
<span>${this.disabled},</span>
|
|
70
|
-
<span>${this.count}.</span>
|
|
71
|
-
</p>
|
|
72
|
-
<p part=${Children.paragraph}>properties: ${JSON.stringify(this.message)}</p>
|
|
73
|
-
<slot name=${Children.light}></slot>
|
|
74
|
-
<button @click=${() => this.sayHi({}, { bubbles: true, composed: true })}>say hi</button>
|
|
75
|
-
`;
|
|
76
|
-
}
|
|
77
|
-
}
|
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
createStore,
|
|
3
|
-
updateStore,
|
|
4
|
-
createCSSSheet,
|
|
5
|
-
GemElement,
|
|
6
|
-
html,
|
|
7
|
-
refobject,
|
|
8
|
-
RefObject,
|
|
9
|
-
attribute,
|
|
10
|
-
connectStore,
|
|
11
|
-
customElement,
|
|
12
|
-
adoptedStyle,
|
|
13
|
-
css,
|
|
14
|
-
render,
|
|
15
|
-
} from '../../';
|
|
16
|
-
|
|
17
|
-
import '../elements/layout';
|
|
18
|
-
|
|
19
|
-
import { Message, Children } from './chidren';
|
|
20
|
-
import './chidren';
|
|
21
|
-
|
|
22
|
-
interface GlobalState {
|
|
23
|
-
msg: Message;
|
|
24
|
-
now: Date;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
const store = createStore<GlobalState>({
|
|
28
|
-
msg: [1, 2],
|
|
29
|
-
now: new Date(),
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
const styles = createCSSSheet(css`
|
|
33
|
-
h1 {
|
|
34
|
-
text-decoration: underline;
|
|
35
|
-
}
|
|
36
|
-
`);
|
|
37
|
-
|
|
38
|
-
@connectStore(store)
|
|
39
|
-
@adoptedStyle(styles)
|
|
40
|
-
@customElement('app-root')
|
|
41
|
-
export class App extends GemElement {
|
|
42
|
-
@refobject childRef: RefObject<Children>;
|
|
43
|
-
@attribute appTitle: string;
|
|
44
|
-
|
|
45
|
-
constructor(title: string) {
|
|
46
|
-
super();
|
|
47
|
-
this.appTitle = title;
|
|
48
|
-
console.log('parent cons');
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
mounted = () => {
|
|
52
|
-
console.log('parent mounted');
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
updated = () => {
|
|
56
|
-
console.log('parent updated');
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
onSayHi = () => {
|
|
60
|
-
const [foo, bar] = store.msg;
|
|
61
|
-
updateStore(store, {
|
|
62
|
-
msg: [bar, foo],
|
|
63
|
-
now: new Date(),
|
|
64
|
-
});
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
loadHandle = () => {
|
|
68
|
-
const { element } = this.childRef;
|
|
69
|
-
if (!element) return;
|
|
70
|
-
const { firstName, lastName, disabled, count } = element;
|
|
71
|
-
console.log({ firstName, lastName, disabled, count });
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
render() {
|
|
75
|
-
console.log('parent render');
|
|
76
|
-
return html`
|
|
77
|
-
<style>
|
|
78
|
-
app-children:where(:--odd, [data-odd])::part(${Children.paragraph}) {
|
|
79
|
-
color: red;
|
|
80
|
-
}
|
|
81
|
-
</style>
|
|
82
|
-
<h1>${this.appTitle}</h1>
|
|
83
|
-
<app-children
|
|
84
|
-
ref=${this.childRef.ref}
|
|
85
|
-
@load=${this.loadHandle}
|
|
86
|
-
@say-hi=${this.onSayHi}
|
|
87
|
-
.message=${store.msg}
|
|
88
|
-
first-name="hello"
|
|
89
|
-
last-name="world"
|
|
90
|
-
count=${1}
|
|
91
|
-
disabled
|
|
92
|
-
>
|
|
93
|
-
<p slot=${Children.light}>now: ${store.now}</p>
|
|
94
|
-
</app-children>
|
|
95
|
-
`;
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
document.addEventListener('say-hi', (e: CustomEvent) => {
|
|
100
|
-
console.log('`sayhi` target', e.composedPath()[0]);
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
render(
|
|
104
|
-
html`
|
|
105
|
-
<gem-examples-layout>
|
|
106
|
-
<app-root app-title="I'm Title" slot="main"></app-root>
|
|
107
|
-
</gem-examples-layout>
|
|
108
|
-
`,
|
|
109
|
-
document.body,
|
|
110
|
-
);
|
|
@@ -1,148 +0,0 @@
|
|
|
1
|
-
import { GemElement, html, customElement, refobject, RefObject, render } from '../../';
|
|
2
|
-
import { createModalClass } from '../../elements/modal-base';
|
|
3
|
-
import { DialogBaseElement } from '../../elements/dialog-base';
|
|
4
|
-
import '../../elements/link';
|
|
5
|
-
|
|
6
|
-
import '../elements/layout';
|
|
7
|
-
|
|
8
|
-
@customElement('app-confirm')
|
|
9
|
-
class Confirm extends createModalClass({
|
|
10
|
-
content: html``,
|
|
11
|
-
confirmHandle: () => {
|
|
12
|
-
/** */
|
|
13
|
-
},
|
|
14
|
-
}) {
|
|
15
|
-
label = 'confirm title';
|
|
16
|
-
|
|
17
|
-
confirm = () => {
|
|
18
|
-
Confirm.close();
|
|
19
|
-
Confirm.store.confirmHandle();
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
render() {
|
|
23
|
-
return html`
|
|
24
|
-
<style>
|
|
25
|
-
.root {
|
|
26
|
-
position: fixed;
|
|
27
|
-
z-index: 3;
|
|
28
|
-
top: 0;
|
|
29
|
-
left: 0;
|
|
30
|
-
width: 100%;
|
|
31
|
-
height: 100%;
|
|
32
|
-
background: rgba(0, 0, 0, 0.5);
|
|
33
|
-
}
|
|
34
|
-
.body {
|
|
35
|
-
position: absolute;
|
|
36
|
-
top: 50%;
|
|
37
|
-
left: 50%;
|
|
38
|
-
transform: translate(-50%, -50%);
|
|
39
|
-
width: 200px;
|
|
40
|
-
height: 100px;
|
|
41
|
-
background: white;
|
|
42
|
-
}
|
|
43
|
-
</style>
|
|
44
|
-
<div class="root" ?hidden=${!Confirm.isOpen}>
|
|
45
|
-
<div class="body">
|
|
46
|
-
<h2>${Confirm.store.content}</h2>
|
|
47
|
-
<button @click=${this.confirm}>close dialog</button>
|
|
48
|
-
</div>
|
|
49
|
-
</div>
|
|
50
|
-
`;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
@customElement('app-dialog')
|
|
55
|
-
class Dialog extends DialogBaseElement {
|
|
56
|
-
shouldClose = () => {
|
|
57
|
-
if (this.opened) {
|
|
58
|
-
Confirm.open({
|
|
59
|
-
content: html`Confirm?`,
|
|
60
|
-
confirmHandle: this.forceClose, // 不能使用 `close` 方法
|
|
61
|
-
});
|
|
62
|
-
return false;
|
|
63
|
-
} else {
|
|
64
|
-
return true;
|
|
65
|
-
}
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
render() {
|
|
69
|
-
return html`
|
|
70
|
-
<style>
|
|
71
|
-
:host {
|
|
72
|
-
display: none;
|
|
73
|
-
}
|
|
74
|
-
:host(:where(:--opened, [data-opened])) {
|
|
75
|
-
display: block;
|
|
76
|
-
}
|
|
77
|
-
.root {
|
|
78
|
-
position: fixed;
|
|
79
|
-
z-index: 2;
|
|
80
|
-
top: 0;
|
|
81
|
-
left: 0;
|
|
82
|
-
width: 100%;
|
|
83
|
-
height: 100%;
|
|
84
|
-
background: rgba(0, 0, 0, 0.5);
|
|
85
|
-
backdrop-filter: blur(5px);
|
|
86
|
-
}
|
|
87
|
-
.body {
|
|
88
|
-
position: absolute;
|
|
89
|
-
top: 50%;
|
|
90
|
-
left: 50%;
|
|
91
|
-
transform: translate(-50%, -50%);
|
|
92
|
-
width: 300px;
|
|
93
|
-
height: 200px;
|
|
94
|
-
background: white;
|
|
95
|
-
}
|
|
96
|
-
</style>
|
|
97
|
-
<div class="root">
|
|
98
|
-
<div class="body">
|
|
99
|
-
<h2>Dialog Title</h2>
|
|
100
|
-
<slot></slot>
|
|
101
|
-
<button @click=${this.close}>x</button>
|
|
102
|
-
</div>
|
|
103
|
-
</div>
|
|
104
|
-
`;
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
@customElement('app-root')
|
|
109
|
-
export class Root extends GemElement {
|
|
110
|
-
@refobject dialog: RefObject<Dialog>;
|
|
111
|
-
|
|
112
|
-
state = {
|
|
113
|
-
modal: false,
|
|
114
|
-
};
|
|
115
|
-
|
|
116
|
-
clickHandle = () => {
|
|
117
|
-
this.dialog.element?.open();
|
|
118
|
-
};
|
|
119
|
-
|
|
120
|
-
render() {
|
|
121
|
-
return html`
|
|
122
|
-
<style>
|
|
123
|
-
:host {
|
|
124
|
-
font-size: x-large;
|
|
125
|
-
}
|
|
126
|
-
</style>
|
|
127
|
-
<button ?inert=${this.state.modal} @click="${this.clickHandle}">open dialog</button>
|
|
128
|
-
<app-dialog
|
|
129
|
-
label="dialog title"
|
|
130
|
-
ref=${this.dialog.ref}
|
|
131
|
-
@open=${() => this.setState({ modal: true })}
|
|
132
|
-
@close=${() => this.setState({ modal: false })}
|
|
133
|
-
>
|
|
134
|
-
<div>dialog body</div>
|
|
135
|
-
<gem-link path="/hi" style="cursor: pointer; color: blue">replace route</gem-link>
|
|
136
|
-
</app-dialog>
|
|
137
|
-
`;
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
render(
|
|
142
|
-
html`
|
|
143
|
-
<gem-examples-layout>
|
|
144
|
-
<app-root slot="main"></app-root>
|
|
145
|
-
</gem-examples-layout>
|
|
146
|
-
`,
|
|
147
|
-
document.body,
|
|
148
|
-
);
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { GemElement, html, customElement, RefObject, refobject, render } from '../../';
|
|
2
|
-
|
|
3
|
-
import '../elements/layout';
|
|
4
|
-
|
|
5
|
-
function effect([textareaElement, callback]: [HTMLTextAreaElement | undefined, (height: number) => void]) {
|
|
6
|
-
if (!textareaElement) return callback(0);
|
|
7
|
-
const ro = new ResizeObserver(([entry]: [any]) => {
|
|
8
|
-
callback(entry.contentRect.height);
|
|
9
|
-
});
|
|
10
|
-
ro.observe(textareaElement, {});
|
|
11
|
-
return () => ro.disconnect();
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
@customElement('app-root')
|
|
15
|
-
export class App extends GemElement {
|
|
16
|
-
@refobject textAreaRef: RefObject<HTMLTextAreaElement>;
|
|
17
|
-
state = {
|
|
18
|
-
height: 0,
|
|
19
|
-
hidden: false,
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
#updateHeight = (height: number) => {
|
|
23
|
-
this.setState({ height });
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
render() {
|
|
27
|
-
return html`
|
|
28
|
-
<div><button @click=${() => this.setState({ hidden: !this.state.hidden })}>switch</button></div>
|
|
29
|
-
${this.state.hidden ? null : html`<textarea ref=${this.textAreaRef.ref}></textarea>`}
|
|
30
|
-
<div>${this.state.height}</div>
|
|
31
|
-
`;
|
|
32
|
-
}
|
|
33
|
-
mounted() {
|
|
34
|
-
this.effect(effect, () => [this.textAreaRef.element, this.#updateHeight]);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
render(
|
|
39
|
-
html`
|
|
40
|
-
<gem-examples-layout>
|
|
41
|
-
<app-root slot="main"></app-root>
|
|
42
|
-
</gem-examples-layout>
|
|
43
|
-
`,
|
|
44
|
-
document.body,
|
|
45
|
-
);
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
type Manifest = typeof import('../index/manifest.json');
|
|
2
|
-
|
|
3
|
-
export const MATADATA = process.env.METADATA as unknown as Record<string, Partial<Manifest>>;
|
|
4
|
-
export const EXAMPLES = process.env.EXAMPLES as unknown as string[];
|
|
5
|
-
export const EXAMPLE = process.env.EXAMPLE as string;
|
|
6
|
-
export const FILES = process.env.FILES as unknown as string[];
|
|
7
|
-
export const PATH = process.env.TAEGET === 'pages' && EXAMPLE !== 'index' ? EXAMPLE : '';
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import { GemElement, html } from '../../lib/element';
|
|
2
|
-
import { customElement, slot } from '../../lib/decorators';
|
|
3
|
-
import '../../elements/reflect';
|
|
4
|
-
import '../../elements/title';
|
|
5
|
-
|
|
6
|
-
import { MATADATA, EXAMPLE } from './env';
|
|
7
|
-
import './nav';
|
|
8
|
-
import './source';
|
|
9
|
-
|
|
10
|
-
@customElement('gem-examples-layout')
|
|
11
|
-
export class Layout extends GemElement {
|
|
12
|
-
@slot main: string;
|
|
13
|
-
|
|
14
|
-
render() {
|
|
15
|
-
return html`
|
|
16
|
-
<gem-title suffix=" - Gem Examples" hidden>${MATADATA[EXAMPLE].name || EXAMPLE}</gem-title>
|
|
17
|
-
<gem-reflect>
|
|
18
|
-
<style>
|
|
19
|
-
body {
|
|
20
|
-
margin: 0;
|
|
21
|
-
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, 'Noto Sans',
|
|
22
|
-
sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol', 'Noto Color Emoji';
|
|
23
|
-
}
|
|
24
|
-
</style>
|
|
25
|
-
</gem-reflect>
|
|
26
|
-
<style>
|
|
27
|
-
:host {
|
|
28
|
-
display: grid;
|
|
29
|
-
grid-template-areas: 'nav main' 'nav source';
|
|
30
|
-
grid-template-columns: 260px 1fr;
|
|
31
|
-
grid-template-rows: 1fr 400px;
|
|
32
|
-
height: 100vh;
|
|
33
|
-
}
|
|
34
|
-
::slotted(*) {
|
|
35
|
-
overflow: auto;
|
|
36
|
-
padding: 2em;
|
|
37
|
-
}
|
|
38
|
-
@media (max-width: 480px) {
|
|
39
|
-
:host {
|
|
40
|
-
display: block;
|
|
41
|
-
}
|
|
42
|
-
gem-examples-nav,
|
|
43
|
-
gem-examples-source {
|
|
44
|
-
display: none;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
</style>
|
|
48
|
-
<gem-examples-nav></gem-examples-nav>
|
|
49
|
-
<slot name=${this.main}></slot>
|
|
50
|
-
<gem-examples-source></gem-examples-source>
|
|
51
|
-
`;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import { GemElement, html, customElement, version } from '../..';
|
|
2
|
-
import { MATADATA, EXAMPLES, EXAMPLE } from './env';
|
|
3
|
-
|
|
4
|
-
const getGitPageUrl = (name: string) => `../${name}/`;
|
|
5
|
-
|
|
6
|
-
const getName = (name: string) => (MATADATA[name].name || name).replace('-', ' ');
|
|
7
|
-
|
|
8
|
-
@customElement('gem-examples-nav')
|
|
9
|
-
export class Nav extends GemElement {
|
|
10
|
-
render() {
|
|
11
|
-
return html`
|
|
12
|
-
<style>
|
|
13
|
-
:host {
|
|
14
|
-
grid-area: nav;
|
|
15
|
-
padding: 2em 0;
|
|
16
|
-
overflow: auto;
|
|
17
|
-
background: #666;
|
|
18
|
-
color: white;
|
|
19
|
-
}
|
|
20
|
-
.header {
|
|
21
|
-
margin-bottom: 1em;
|
|
22
|
-
padding: 0 2em;
|
|
23
|
-
}
|
|
24
|
-
.name {
|
|
25
|
-
font-size: 1.2em;
|
|
26
|
-
}
|
|
27
|
-
.version {
|
|
28
|
-
font-family: monospace;
|
|
29
|
-
}
|
|
30
|
-
ol {
|
|
31
|
-
margin: 0;
|
|
32
|
-
padding: 0;
|
|
33
|
-
}
|
|
34
|
-
li {
|
|
35
|
-
display: contents;
|
|
36
|
-
}
|
|
37
|
-
a {
|
|
38
|
-
padding: 0.5em 2em;
|
|
39
|
-
display: block;
|
|
40
|
-
color: inherit;
|
|
41
|
-
opacity: 0.8;
|
|
42
|
-
line-height: 1.5;
|
|
43
|
-
text-decoration: none;
|
|
44
|
-
text-transform: capitalize;
|
|
45
|
-
}
|
|
46
|
-
a:hover {
|
|
47
|
-
opacity: 1;
|
|
48
|
-
}
|
|
49
|
-
a.active {
|
|
50
|
-
opacity: 1;
|
|
51
|
-
background: #444;
|
|
52
|
-
}
|
|
53
|
-
</style>
|
|
54
|
-
<a class="header" href="https://github.com/mantou132/gem" target="_blank">
|
|
55
|
-
<div class="name">Gem Examples</div>
|
|
56
|
-
<div class="version">version: ${version}</div>
|
|
57
|
-
</a>
|
|
58
|
-
<ol>
|
|
59
|
-
${EXAMPLES.sort((a, b) => ((MATADATA[a].order || 0) > (MATADATA[b].order || 0) ? 1 : -1)).map(
|
|
60
|
-
(name) =>
|
|
61
|
-
html`<li>
|
|
62
|
-
<a class=${EXAMPLE === name ? 'active' : ''} href=${getGitPageUrl(name)}>
|
|
63
|
-
<div>${getName(name)}</div>
|
|
64
|
-
<div>${MATADATA[name].desc}</div>
|
|
65
|
-
</a>
|
|
66
|
-
</li>`,
|
|
67
|
-
)}
|
|
68
|
-
</ol>
|
|
69
|
-
`;
|
|
70
|
-
}
|
|
71
|
-
}
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import { GemElement, html, customElement } from '../..';
|
|
2
|
-
import { EXAMPLE, FILES } from './env';
|
|
3
|
-
|
|
4
|
-
@customElement('gem-examples-source')
|
|
5
|
-
export class Source extends GemElement {
|
|
6
|
-
state = {
|
|
7
|
-
files: FILES.map((file) => ({ file: file, content: '' })),
|
|
8
|
-
current: FILES[0],
|
|
9
|
-
};
|
|
10
|
-
render() {
|
|
11
|
-
const { files, current } = this.state;
|
|
12
|
-
return html`
|
|
13
|
-
<style>
|
|
14
|
-
:host {
|
|
15
|
-
border-top: 1px solid #666;
|
|
16
|
-
overflow: auto;
|
|
17
|
-
grid-area: source;
|
|
18
|
-
background: #eee5;
|
|
19
|
-
}
|
|
20
|
-
ul {
|
|
21
|
-
margin: 0;
|
|
22
|
-
padding: 0 1em;
|
|
23
|
-
display: flex;
|
|
24
|
-
gap: 1em 2em;
|
|
25
|
-
border-bottom: 1px solid #eee;
|
|
26
|
-
position: sticky;
|
|
27
|
-
top: 0;
|
|
28
|
-
background: white;
|
|
29
|
-
}
|
|
30
|
-
li {
|
|
31
|
-
cursor: pointer;
|
|
32
|
-
line-height: 2;
|
|
33
|
-
list-style: none;
|
|
34
|
-
border-bottom: 2px solid transparent;
|
|
35
|
-
}
|
|
36
|
-
li.current {
|
|
37
|
-
border-color: #1ecfe3;
|
|
38
|
-
}
|
|
39
|
-
pre {
|
|
40
|
-
margin: 0;
|
|
41
|
-
padding: 1em;
|
|
42
|
-
}
|
|
43
|
-
</style>
|
|
44
|
-
<ul>
|
|
45
|
-
${FILES.map(
|
|
46
|
-
(file) =>
|
|
47
|
-
html`
|
|
48
|
-
<li class=${current === file ? 'current' : ''} @click=${() => this.setState({ current: file })}>
|
|
49
|
-
${file}
|
|
50
|
-
</li>
|
|
51
|
-
`,
|
|
52
|
-
)}
|
|
53
|
-
</ul>
|
|
54
|
-
<pre>${files.find((e) => e.file === current)?.content}</pre>
|
|
55
|
-
`;
|
|
56
|
-
}
|
|
57
|
-
mounted() {
|
|
58
|
-
FILES.forEach(async (file) => {
|
|
59
|
-
const { files } = this.state;
|
|
60
|
-
const item = files.find((e) => e.file === file);
|
|
61
|
-
if (!item) return;
|
|
62
|
-
item.content = await (
|
|
63
|
-
await fetch(`https://raw.githubusercontent.com/mantou132/gem/master/src/examples/${EXAMPLE}/${file}`)
|
|
64
|
-
).text();
|
|
65
|
-
this.update();
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
}
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import { GemElement, html, customElement, property, refobject, RefObject } from '../..';
|
|
2
|
-
import { PanEventDetail } from '../../elements/gesture';
|
|
3
|
-
|
|
4
|
-
@customElement('app-canvas')
|
|
5
|
-
export class AppCanvas extends GemElement {
|
|
6
|
-
@property data: PanEventDetail[];
|
|
7
|
-
|
|
8
|
-
@refobject canvasRef: RefObject<HTMLCanvasElement>;
|
|
9
|
-
@refobject canvasRef1: RefObject<HTMLCanvasElement>;
|
|
10
|
-
render() {
|
|
11
|
-
return html`
|
|
12
|
-
<br />
|
|
13
|
-
<canvas ref=${this.canvasRef.ref} style="border: 1px solid"></canvas>
|
|
14
|
-
<canvas ref=${this.canvasRef1.ref} style="border: 1px solid"></canvas>
|
|
15
|
-
`;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
mounted() {
|
|
19
|
-
const canvas = this.canvasRef.element!;
|
|
20
|
-
const canvas1 = this.canvasRef1.element!;
|
|
21
|
-
const ctx = canvas.getContext('2d')!;
|
|
22
|
-
const ctx1 = canvas1.getContext('2d')!;
|
|
23
|
-
canvas.height = 150;
|
|
24
|
-
canvas1.height = 150;
|
|
25
|
-
this.effect(() => {
|
|
26
|
-
canvas.width = 0;
|
|
27
|
-
canvas.width = 300;
|
|
28
|
-
canvas1.width = 0;
|
|
29
|
-
canvas1.width = 300;
|
|
30
|
-
const maxX = [...this.data].sort(({ x }, { x: x1 }) => {
|
|
31
|
-
if (x > x1) return -1;
|
|
32
|
-
return 1;
|
|
33
|
-
})[0]?.x;
|
|
34
|
-
ctx.fillText(String(maxX), 0, 8);
|
|
35
|
-
const maxY = [...this.data].sort(({ y }, { y: y1 }) => {
|
|
36
|
-
if (y > y1) return -1;
|
|
37
|
-
return 1;
|
|
38
|
-
})[0]?.y;
|
|
39
|
-
ctx1.fillText(String(maxY), 0, 8);
|
|
40
|
-
console.log('x:', this.data.map(({ x }) => x).join());
|
|
41
|
-
console.log('y:', this.data.map(({ y }) => y).join());
|
|
42
|
-
console.log(
|
|
43
|
-
'timeStamp interval:',
|
|
44
|
-
this.data.reduce(
|
|
45
|
-
(p, c, index) => (index ? `${p}, ${(c.timeStamp - this.data[index - 1].timeStamp).toFixed()}` : ''),
|
|
46
|
-
'',
|
|
47
|
-
),
|
|
48
|
-
);
|
|
49
|
-
this.data.forEach((data, index) => {
|
|
50
|
-
const y = 150 - data.x * (150 / maxX);
|
|
51
|
-
const y1 = 150 - data.y * (150 / maxY);
|
|
52
|
-
const x = index * (300 / this.data.length);
|
|
53
|
-
if (index === 0) {
|
|
54
|
-
ctx.beginPath();
|
|
55
|
-
ctx.moveTo(x, y);
|
|
56
|
-
ctx1.beginPath();
|
|
57
|
-
ctx1.moveTo(x, y1);
|
|
58
|
-
} else {
|
|
59
|
-
ctx.lineTo(x, y);
|
|
60
|
-
ctx1.lineTo(x, y1);
|
|
61
|
-
}
|
|
62
|
-
if (index === this.data.length - 1) {
|
|
63
|
-
ctx.stroke();
|
|
64
|
-
ctx1.stroke();
|
|
65
|
-
}
|
|
66
|
-
});
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
}
|