@mantou/gem 2.1.0 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/gem.es.js +1845 -1904
- package/dist/gem.umd.js +34 -191
- package/elements/base/dialog.d.ts +0 -4
- package/elements/base/dialog.d.ts.map +1 -1
- package/elements/base/dialog.js +0 -4
- package/elements/base/dialog.js.map +1 -1
- package/elements/base/gesture.d.ts +4 -14
- package/elements/base/gesture.d.ts.map +1 -1
- package/elements/base/gesture.js +34 -37
- package/elements/base/gesture.js.map +1 -1
- package/elements/base/link.d.ts +2 -19
- package/elements/base/link.d.ts.map +1 -1
- package/elements/base/link.js +29 -42
- package/elements/base/link.js.map +1 -1
- package/elements/base/modal-factory.d.ts +32 -33
- package/elements/base/modal-factory.d.ts.map +1 -1
- package/elements/base/reflect.d.ts +0 -3
- package/elements/base/reflect.d.ts.map +1 -1
- package/elements/base/reflect.js +0 -3
- package/elements/base/reflect.js.map +1 -1
- package/elements/base/route.d.ts +0 -10
- package/elements/base/route.d.ts.map +1 -1
- package/elements/base/route.js +10 -22
- package/elements/base/route.js.map +1 -1
- package/elements/base/title.d.ts +0 -6
- package/elements/base/title.d.ts.map +1 -1
- package/elements/base/title.js +13 -8
- package/elements/base/title.js.map +1 -1
- package/elements/base/unsafe.d.ts +1 -6
- package/elements/base/unsafe.d.ts.map +1 -1
- package/elements/base/unsafe.js +12 -12
- package/elements/base/unsafe.js.map +1 -1
- package/elements/base/use.d.ts +0 -4
- package/elements/base/use.d.ts.map +1 -1
- package/elements/base/use.js +15 -13
- package/elements/base/use.js.map +1 -1
- package/helper/theme.d.ts +3 -3
- package/helper/theme.d.ts.map +1 -1
- package/helper/theme.js +3 -3
- package/helper/theme.js.map +1 -1
- package/index.d.ts +0 -1
- package/index.d.ts.map +1 -1
- package/index.js +0 -1
- package/index.js.map +1 -1
- package/lib/decorators.d.ts +7 -6
- package/lib/decorators.d.ts.map +1 -1
- package/lib/decorators.js +48 -33
- package/lib/decorators.js.map +1 -1
- package/lib/directive.d.ts +83 -0
- package/lib/directive.d.ts.map +1 -0
- package/lib/directive.js +59 -0
- package/lib/directive.js.map +1 -0
- package/lib/element.d.ts +9 -23
- package/lib/element.d.ts.map +1 -1
- package/lib/element.js +61 -56
- package/lib/element.js.map +1 -1
- package/lib/lit-html.d.ts +331 -0
- package/lib/lit-html.d.ts.map +1 -0
- package/lib/lit-html.js +941 -0
- package/lib/lit-html.js.map +1 -0
- package/lib/ref.d.ts +1 -0
- package/lib/ref.d.ts.map +1 -0
- package/lib/ref.js +2 -0
- package/lib/ref.js.map +1 -0
- package/lib/repeat.d.ts +126 -0
- package/lib/repeat.d.ts.map +1 -0
- package/lib/repeat.js +533 -0
- package/lib/repeat.js.map +1 -0
- package/lib/store.d.ts +1 -1
- package/lib/store.d.ts.map +1 -1
- package/lib/store.js +4 -4
- package/lib/store.js.map +1 -1
- package/lib/utils.d.ts +1 -4
- package/lib/utils.d.ts.map +1 -1
- package/lib/utils.js +6 -15
- package/lib/utils.js.map +1 -1
- package/package.json +7 -9
- package/src/elements/base/dialog.ts +0 -4
- package/src/elements/base/gesture.ts +32 -35
- package/src/elements/base/link.ts +21 -41
- package/src/elements/base/reflect.ts +0 -3
- package/src/elements/base/route.ts +11 -21
- package/src/elements/base/title.ts +3 -7
- package/src/elements/base/unsafe.ts +9 -11
- package/src/elements/base/use.ts +8 -14
- package/src/helper/theme.ts +4 -4
- package/src/index.ts +0 -1
- package/src/lib/decorators.ts +53 -40
- package/src/lib/directive.ts +139 -0
- package/src/lib/element.ts +70 -79
- package/src/lib/lit-html.ts +1217 -0
- package/src/lib/repeat.ts +580 -0
- package/src/lib/store.ts +4 -4
- package/src/lib/utils.ts +6 -16
- package/src/test/elements/link.test.ts +1 -2
- package/src/test/elements/reflect.test.ts +13 -3
- package/src/test/elements/title.test.ts +1 -2
- package/src/test/gem-element/advance.test.ts +15 -8
- package/src/test/gem-element/basic.test.ts +22 -10
- package/src/test/gem-element/decorators.test.ts +6 -9
- package/src/test/gem-element/multi.test.ts +20 -11
- package/src/test/history.test.ts +2 -2
- package/src/test/store.test.ts +3 -3
- package/src/test/utils.test.ts +9 -10
- package/src/test/utils.ts +22 -0
- package/LICENSE +0 -21
- package/src/lib/directives.ts +0 -6
|
@@ -1,16 +1,25 @@
|
|
|
1
|
-
import { fixture, expect, nextFrame } from '
|
|
2
|
-
|
|
3
|
-
import {
|
|
1
|
+
import { fixture, expect, nextFrame } from '../utils';
|
|
2
|
+
import { css, GemElement, html } from '../../lib/element';
|
|
3
|
+
import { adoptedStyle, customElement } from '../../lib/decorators';
|
|
4
4
|
import type { GemReflectElement } from '../../elements/reflect';
|
|
5
5
|
|
|
6
6
|
import '../../elements/reflect';
|
|
7
7
|
|
|
8
|
+
@adoptedStyle(css`
|
|
9
|
+
:scope {
|
|
10
|
+
color: rgb(255, 0, 0);
|
|
11
|
+
}
|
|
12
|
+
`)
|
|
13
|
+
@customElement('light-dom')
|
|
14
|
+
export class Children extends GemElement {}
|
|
15
|
+
|
|
8
16
|
describe('GemReflectElement', () => {
|
|
9
17
|
it('basic', async () => {
|
|
10
18
|
const reflect: GemReflectElement = await fixture(html`
|
|
11
19
|
<gem-reflect>
|
|
12
20
|
<div id="one"></div>
|
|
13
21
|
<div id="two"></div>
|
|
22
|
+
<light-dom></light-dom>
|
|
14
23
|
</gem-reflect>
|
|
15
24
|
`);
|
|
16
25
|
const div = document.head.querySelector('#one');
|
|
@@ -20,6 +29,7 @@ describe('GemReflectElement', () => {
|
|
|
20
29
|
reflect.target = document.body;
|
|
21
30
|
await nextFrame();
|
|
22
31
|
expect(document.body.querySelector('#one')).to.equal(div);
|
|
32
|
+
expect(getComputedStyle(document.body.querySelector('light-dom')!).color).to.equal('rgb(255, 0, 0)');
|
|
23
33
|
expect(div?.nextSibling).to.equal(comment);
|
|
24
34
|
reflect.remove();
|
|
25
35
|
expect(!!document.querySelector('#one')).to.equal(false);
|
|
@@ -6,10 +6,9 @@
|
|
|
6
6
|
* - 派生元素(类扩展)
|
|
7
7
|
* - 无渲染内容 Gem 元素
|
|
8
8
|
*/
|
|
9
|
-
import { fixture, expect, nextFrame } from '
|
|
10
|
-
|
|
9
|
+
import { fixture, expect, nextFrame } from '../utils';
|
|
11
10
|
import type { Metadata } from '../../lib/element';
|
|
12
|
-
import {
|
|
11
|
+
import { css, createState, GemElement, html, createRef } from '../../lib/element';
|
|
13
12
|
import { createStore } from '../../lib/store';
|
|
14
13
|
import {
|
|
15
14
|
attribute,
|
|
@@ -22,7 +21,6 @@ import {
|
|
|
22
21
|
shadow,
|
|
23
22
|
mounted,
|
|
24
23
|
} from '../../lib/decorators';
|
|
25
|
-
import { css } from '../../lib/utils';
|
|
26
24
|
|
|
27
25
|
const store = createStore({
|
|
28
26
|
a: 1,
|
|
@@ -54,11 +52,11 @@ describe('异步 gem element 测试', () => {
|
|
|
54
52
|
});
|
|
55
53
|
});
|
|
56
54
|
|
|
57
|
-
const lightStyle =
|
|
55
|
+
const lightStyle = css`
|
|
58
56
|
div {
|
|
59
57
|
font-size: 18.1px;
|
|
60
58
|
}
|
|
61
|
-
|
|
59
|
+
`;
|
|
62
60
|
|
|
63
61
|
@customElement('light-gem-demo')
|
|
64
62
|
@adoptedStyle(lightStyle)
|
|
@@ -100,7 +98,7 @@ class LifecycleGemElement extends GemElement {
|
|
|
100
98
|
this.appTitle2 = appTitle2 ?? this.appTitle2;
|
|
101
99
|
this.effect(
|
|
102
100
|
() => {
|
|
103
|
-
this.refInConstructor = this.divRef.
|
|
101
|
+
this.refInConstructor = this.divRef.value;
|
|
104
102
|
},
|
|
105
103
|
() => [],
|
|
106
104
|
);
|
|
@@ -118,7 +116,7 @@ class LifecycleGemElement extends GemElement {
|
|
|
118
116
|
|
|
119
117
|
render() {
|
|
120
118
|
this.renderCount++;
|
|
121
|
-
return html`<div
|
|
119
|
+
return html`<div ${this.divRef}></div>`;
|
|
122
120
|
}
|
|
123
121
|
}
|
|
124
122
|
describe('gem element 生命周期', () => {
|
|
@@ -304,12 +302,20 @@ class InheritGem extends I {
|
|
|
304
302
|
@attribute appTitle = '1';
|
|
305
303
|
@attribute appTitle2 = '2';
|
|
306
304
|
}
|
|
305
|
+
|
|
306
|
+
@customElement('inherit-gem1')
|
|
307
|
+
class InheritGem1 extends I {}
|
|
308
|
+
|
|
307
309
|
describe('gem element 继承', () => {
|
|
308
310
|
it('静态字段继承', async () => {
|
|
309
311
|
new I();
|
|
310
312
|
new InheritGem(); // 触发装饰器自定义初始化函数
|
|
311
313
|
const metadata: Metadata = Reflect.get(InheritGem, Symbol.metadata);
|
|
312
314
|
expect(metadata.observedAttributes).to.eql(['app-title', 'app-title2']);
|
|
315
|
+
|
|
316
|
+
new InheritGem1(); // 触发装饰器自定义初始化函数
|
|
317
|
+
const metadata1: Metadata = Reflect.get(InheritGem1, Symbol.metadata);
|
|
318
|
+
expect(metadata1.observedAttributes).to.eql(['app-title']);
|
|
313
319
|
});
|
|
314
320
|
it('attr/prop/emitter 继承', async () => {
|
|
315
321
|
const name = window.name;
|
|
@@ -333,6 +339,7 @@ describe('gem element 继承', () => {
|
|
|
333
339
|
window.name += '2';
|
|
334
340
|
});
|
|
335
341
|
el.sayHi();
|
|
342
|
+
await Promise.resolve();
|
|
336
343
|
expect(window.name).to.equal(name + '21');
|
|
337
344
|
});
|
|
338
345
|
});
|
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
import { fixture, expect, nextFrame } from '
|
|
2
|
-
|
|
3
|
-
import { createCSSSheet, createState, GemElement, html } from '../../lib/element';
|
|
1
|
+
import { fixture, expect, nextFrame } from '../utils';
|
|
2
|
+
import { css, createState, GemElement, html } from '../../lib/element';
|
|
4
3
|
import { createStore } from '../../lib/store';
|
|
5
|
-
import { css } from '../../lib/utils';
|
|
6
4
|
import {
|
|
7
5
|
adoptedStyle,
|
|
8
6
|
attribute,
|
|
9
7
|
boolattribute,
|
|
10
8
|
connectStore,
|
|
11
9
|
customElement,
|
|
10
|
+
fallback,
|
|
12
11
|
numattribute,
|
|
13
12
|
property,
|
|
14
13
|
shadow,
|
|
@@ -18,11 +17,11 @@ const store = createStore({
|
|
|
18
17
|
a: 1,
|
|
19
18
|
});
|
|
20
19
|
|
|
21
|
-
const styles =
|
|
20
|
+
const styles = css`
|
|
22
21
|
:host {
|
|
23
22
|
background: rgb(255, 0, 0);
|
|
24
23
|
}
|
|
25
|
-
|
|
24
|
+
`;
|
|
26
25
|
|
|
27
26
|
@connectStore(store)
|
|
28
27
|
@adoptedStyle(styles)
|
|
@@ -40,11 +39,15 @@ class GemDemo extends GemElement {
|
|
|
40
39
|
renderCount = 0;
|
|
41
40
|
|
|
42
41
|
render() {
|
|
42
|
+
if (this.attr === 'error') throw new Error();
|
|
43
43
|
const { attr, disabled, count, prop } = this;
|
|
44
44
|
const { value } = this.#state;
|
|
45
45
|
this.renderCount++;
|
|
46
46
|
return html`attr: ${attr}, disabled: ${disabled}, count: ${count}, prop: ${prop.value}, state: ${value}`;
|
|
47
47
|
}
|
|
48
|
+
|
|
49
|
+
@fallback()
|
|
50
|
+
#error = () => html`Error`;
|
|
48
51
|
}
|
|
49
52
|
|
|
50
53
|
describe('基本 gem element 测试', () => {
|
|
@@ -68,12 +71,14 @@ describe('基本 gem element 测试', () => {
|
|
|
68
71
|
});
|
|
69
72
|
it('渲染 gem element', async () => {
|
|
70
73
|
const el: GemDemo = await fixture(html`<gem-demo attr="attr" .prop=${{ value: 'prop' }}></gem-demo>`);
|
|
71
|
-
expect(el).
|
|
74
|
+
expect(el.shadowRoot?.textContent).to.equal('attr: attr, disabled: false, count: 0, prop: prop, state: ');
|
|
72
75
|
await Promise.resolve();
|
|
73
76
|
expect(el.renderCount).to.equal(1);
|
|
74
77
|
el.update();
|
|
75
78
|
await Promise.resolve();
|
|
76
79
|
expect(el.renderCount).to.equal(2);
|
|
80
|
+
const errEl: GemDemo = await fixture(html`<gem-demo attr="error"></gem-demo>`);
|
|
81
|
+
expect(errEl.shadowRoot?.textContent).to.equal('Error');
|
|
77
82
|
});
|
|
78
83
|
it('读取 attr', async () => {
|
|
79
84
|
const el: GemDemo = await fixture(html`
|
|
@@ -102,7 +107,7 @@ describe('基本 gem element 测试', () => {
|
|
|
102
107
|
expect(el.attr).to.equal('value');
|
|
103
108
|
expect(el.disabled).to.equal(true);
|
|
104
109
|
expect(el.count).to.equal(2);
|
|
105
|
-
expect(el).
|
|
110
|
+
expect(el.shadowRoot?.textContent).to.equal('attr: value, disabled: true, count: 2, prop: , state: ');
|
|
106
111
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
107
112
|
// @ts-ignore
|
|
108
113
|
el.attr = null;
|
|
@@ -124,7 +129,14 @@ describe('基本 gem element 测试', () => {
|
|
|
124
129
|
await Promise.resolve();
|
|
125
130
|
expect(el.renderCount).to.equal(2);
|
|
126
131
|
expect(el.prop).to.deep.equal({ value: 'value' });
|
|
127
|
-
expect(el).
|
|
132
|
+
expect(el.shadowRoot?.textContent).to.equal('attr: , disabled: false, count: 0, prop: value, state: ');
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
it('只能在 initEffect 前修改 state', async () => {
|
|
136
|
+
const syncUpdateEle = new GemDemo();
|
|
137
|
+
expect(() => syncUpdateEle.internals.stateList[0]()).to.not.throw();
|
|
138
|
+
document.body.append(syncUpdateEle);
|
|
139
|
+
expect(() => syncUpdateEle.internals.stateList[0]()).to.throw();
|
|
128
140
|
});
|
|
129
141
|
|
|
130
142
|
it('修改 state', async () => {
|
|
@@ -136,7 +148,7 @@ describe('基本 gem element 测试', () => {
|
|
|
136
148
|
await Promise.resolve();
|
|
137
149
|
expect(el.renderCount).to.equal(2);
|
|
138
150
|
expect({ ...el.internals.stateList[0] }).to.deep.equal({ value: 'state' });
|
|
139
|
-
expect(el).
|
|
151
|
+
expect(el.shadowRoot?.textContent).to.equal('attr: , disabled: false, count: 0, prop: , state: state');
|
|
140
152
|
});
|
|
141
153
|
|
|
142
154
|
it('更新 store', async () => {
|
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import { fixture, expect } from '
|
|
2
|
-
|
|
1
|
+
import { fixture, expect } from '../utils';
|
|
3
2
|
import type { Metadata } from '../../lib/element';
|
|
4
|
-
import {
|
|
3
|
+
import { css, GemElement, html } from '../../lib/element';
|
|
5
4
|
import { createStore } from '../../lib/store';
|
|
6
|
-
import { css } from '../../lib/utils';
|
|
7
5
|
import type { Emitter } from '../../lib/decorators';
|
|
8
6
|
import {
|
|
9
7
|
attribute,
|
|
@@ -24,11 +22,11 @@ const store = createStore({
|
|
|
24
22
|
a: 1,
|
|
25
23
|
});
|
|
26
24
|
|
|
27
|
-
const styles =
|
|
25
|
+
const styles = css`
|
|
28
26
|
:host {
|
|
29
27
|
background: rgb(255, 0, 0);
|
|
30
28
|
}
|
|
31
|
-
|
|
29
|
+
`;
|
|
32
30
|
|
|
33
31
|
@connectStore(store)
|
|
34
32
|
@adoptedStyle(styles)
|
|
@@ -47,7 +45,6 @@ class DecoratorGemElement extends GemElement {
|
|
|
47
45
|
@state openState: boolean;
|
|
48
46
|
@part headerPart: string;
|
|
49
47
|
@slot bodySlot: string;
|
|
50
|
-
inputRef = createRef<HTMLElement>();
|
|
51
48
|
renderCount = 0;
|
|
52
49
|
render() {
|
|
53
50
|
this.renderCount++;
|
|
@@ -99,13 +96,13 @@ describe('装饰器', () => {
|
|
|
99
96
|
expect(el.propData).to.eql({ value: 'prop' });
|
|
100
97
|
expect(el.openState).to.equal(false);
|
|
101
98
|
expect(el.headerPart).to.equal('header-part');
|
|
102
|
-
expect(el.inputRef.ref.startsWith('ref-')).to.equal(true);
|
|
103
99
|
expect(el.bodySlot).to.equal('body-slot');
|
|
104
|
-
expect(el).
|
|
100
|
+
expect(el.shadowRoot?.textContent).to.equal('attr: attr, disabled: true, count: 2, prop: prop');
|
|
105
101
|
store({ a: 3 });
|
|
106
102
|
await Promise.resolve();
|
|
107
103
|
expect(el.renderCount).to.equal(3);
|
|
108
104
|
el.sayHi(2);
|
|
105
|
+
await Promise.resolve();
|
|
109
106
|
expect(el.renderCount).to.equal(3);
|
|
110
107
|
expect(a).to.equal(2);
|
|
111
108
|
});
|
|
@@ -1,16 +1,20 @@
|
|
|
1
|
-
import { expect, fixture } from '
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
import { GemElement, html, createRef } from '../../lib/element';
|
|
1
|
+
import { expect, fixture } from '../utils';
|
|
2
|
+
import { attribute, customElement, emitter, mounted, property, type Emitter } from '../../lib/decorators';
|
|
3
|
+
import { GemElement, html, createRef, createState } from '../../lib/element';
|
|
5
4
|
|
|
6
5
|
@customElement('app-children')
|
|
7
6
|
export class Children extends GemElement {
|
|
8
7
|
@property value?: { value: number };
|
|
9
8
|
@attribute attr: string;
|
|
9
|
+
@emitter sayHi: Emitter<null>;
|
|
10
|
+
|
|
10
11
|
inputRef = createRef<HTMLInputElement>();
|
|
11
12
|
|
|
13
|
+
@mounted()
|
|
14
|
+
#init = () => this.sayHi();
|
|
15
|
+
|
|
12
16
|
render() {
|
|
13
|
-
return html`<input
|
|
17
|
+
return html`<input ${this.inputRef} />`;
|
|
14
18
|
}
|
|
15
19
|
}
|
|
16
20
|
|
|
@@ -18,20 +22,25 @@ export class Children extends GemElement {
|
|
|
18
22
|
export class App extends GemElement {
|
|
19
23
|
childrenRef1 = createRef<Children>();
|
|
20
24
|
childrenRef2 = createRef<Children>();
|
|
25
|
+
|
|
26
|
+
// 还未 mounted, 不应该发生错误
|
|
27
|
+
#state = createState({});
|
|
28
|
+
#onSayHi = () => this.#state();
|
|
29
|
+
|
|
21
30
|
render() {
|
|
22
31
|
return html`
|
|
23
|
-
<app-children
|
|
24
|
-
<app-children
|
|
32
|
+
<app-children ${this.childrenRef1} .value=${{ value: 1 }} attr="1" @say-hi=${this.#onSayHi}></app-children>
|
|
33
|
+
<app-children ${this.childrenRef2} .value=${{ value: 2 }} attr="2"></app-children>
|
|
25
34
|
`;
|
|
26
35
|
}
|
|
27
36
|
}
|
|
28
37
|
describe('多个 gem element 一起工作', () => {
|
|
29
38
|
it('ref & prop & attr', async () => {
|
|
30
39
|
const el: App = await fixture(html`<app-root></app-root>`);
|
|
31
|
-
const children1 = el.childrenRef1.
|
|
32
|
-
const children2 = el.childrenRef2.
|
|
33
|
-
const input1 = children1.inputRef.
|
|
34
|
-
const input2 = children2.inputRef.
|
|
40
|
+
const children1 = el.childrenRef1.value!;
|
|
41
|
+
const children2 = el.childrenRef2.value!;
|
|
42
|
+
const input1 = children1.inputRef.value!;
|
|
43
|
+
const input2 = children2.inputRef.value!;
|
|
35
44
|
expect(input1 !== input2).to.equal(true);
|
|
36
45
|
expect(children1.value).to.eql({ value: 1 });
|
|
37
46
|
expect(children2.value).to.eql({ value: 2 });
|
package/src/test/history.test.ts
CHANGED
package/src/test/store.test.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { _StoreListenerMap, createStore, connect } from '../lib/store';
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { expect, aTimeout } from './utils';
|
|
4
4
|
|
|
5
5
|
describe('store 测试', () => {
|
|
6
6
|
it('create store', () => {
|
|
7
7
|
const origin = { a: 1 };
|
|
8
8
|
const store = createStore(origin);
|
|
9
9
|
expect({ ...store }).to.deep.equal(origin);
|
|
10
|
-
expect(!!
|
|
10
|
+
expect(!!_StoreListenerMap.get(store)).to.equal(true);
|
|
11
11
|
});
|
|
12
12
|
it('update store', async () => {
|
|
13
13
|
const store = createStore({ a: 1 });
|
package/src/test/utils.test.ts
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
import { createCSSSheet, SheetToken } from '../lib/element';
|
|
1
|
+
import { css, SheetToken } from '../lib/element';
|
|
4
2
|
import {
|
|
5
3
|
LinkedList,
|
|
6
4
|
QueryString,
|
|
7
|
-
css,
|
|
8
5
|
raw,
|
|
9
6
|
styled,
|
|
10
7
|
styleMap,
|
|
@@ -13,6 +10,8 @@ import {
|
|
|
13
10
|
absoluteLocation,
|
|
14
11
|
} from '../lib/utils';
|
|
15
12
|
|
|
13
|
+
import { expect } from './utils';
|
|
14
|
+
|
|
16
15
|
declare global {
|
|
17
16
|
interface CSSRuleList {
|
|
18
17
|
// only test style rule
|
|
@@ -81,12 +80,12 @@ describe('utils 测试', () => {
|
|
|
81
80
|
expect(new QueryString({ a: 1 }).toString()).to.equal('?a=1');
|
|
82
81
|
expect(new QueryString(query).toString()).to.equal(query.toString());
|
|
83
82
|
});
|
|
84
|
-
it('
|
|
85
|
-
const cssSheet =
|
|
83
|
+
it('css', () => {
|
|
84
|
+
const cssSheet = css`
|
|
86
85
|
div {
|
|
87
86
|
background: red;
|
|
88
87
|
}
|
|
89
|
-
|
|
88
|
+
`;
|
|
90
89
|
const rules = cssSheet[SheetToken].getStyle().cssRules;
|
|
91
90
|
expect(rules.item(0).selectorText).to.equal('div');
|
|
92
91
|
expect(rules.item(0).style.background).to.equal('red');
|
|
@@ -101,9 +100,9 @@ describe('utils 测试', () => {
|
|
|
101
100
|
expect(raw`<div>${'str'}</div>`).to.equal('<div>str</div>');
|
|
102
101
|
});
|
|
103
102
|
it('styled', () => {
|
|
104
|
-
const cssSheet =
|
|
105
|
-
$: styled
|
|
106
|
-
scroll: styled
|
|
103
|
+
const cssSheet = css({
|
|
104
|
+
$: styled``,
|
|
105
|
+
scroll: styled`
|
|
107
106
|
background: red;
|
|
108
107
|
&:hover * {
|
|
109
108
|
background: blue;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { expect, should, assert } from 'chai';
|
|
2
|
+
|
|
3
|
+
import { render } from '../lib/element';
|
|
4
|
+
import type { TemplateResult } from '../lib/element';
|
|
5
|
+
|
|
6
|
+
export { expect, should, assert };
|
|
7
|
+
|
|
8
|
+
export function nextFrame() {
|
|
9
|
+
return new Promise((resolve) => requestAnimationFrame(() => resolve(null)));
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function aTimeout(ms = 0) {
|
|
13
|
+
return new Promise((resolve) => setTimeout(() => resolve(null), ms));
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export async function fixture(template: TemplateResult) {
|
|
17
|
+
const wrapper = document.createElement('div');
|
|
18
|
+
document.body.appendChild(wrapper);
|
|
19
|
+
render(template, wrapper);
|
|
20
|
+
await nextFrame();
|
|
21
|
+
return wrapper.firstElementChild as any;
|
|
22
|
+
}
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2021-present
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|