@mantou/gem 2.2.10 → 2.2.11
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.js +4 -4
- package/dist/gem.mjs +4 -4
- package/elements/base/gesture.d.ts +8 -0
- package/elements/base/gesture.d.ts.map +1 -1
- package/elements/base/gesture.js +89 -38
- package/elements/base/gesture.js.map +1 -1
- package/helper/theme.d.ts.map +1 -1
- package/helper/theme.js +12 -2
- package/helper/theme.js.map +1 -1
- package/lib/version.d.ts +1 -1
- package/lib/version.js +1 -1
- package/package.json +1 -1
- package/src/elements/base/gesture.ts +105 -38
- package/src/helper/theme.ts +15 -2
- package/src/lib/version.ts +1 -1
- package/src/test/elements/gesture.test.ts +311 -0
- package/src/test/gem-element/decorators.test.ts +67 -0
- package/src/test/utils.ts +1 -1
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { createDecoratorTheme } from '../../helper/theme';
|
|
1
2
|
import type { Emitter } from '../../lib/decorators';
|
|
2
3
|
import {
|
|
3
4
|
adoptedStyle,
|
|
@@ -18,6 +19,51 @@ import { css, GemElement, html } from '../../lib/element';
|
|
|
18
19
|
import { createStore } from '../../lib/store';
|
|
19
20
|
import { expect, fixture } from '../utils';
|
|
20
21
|
|
|
22
|
+
const elemTheme = createDecoratorTheme({ color: 'rgb(255, 0, 0)' });
|
|
23
|
+
|
|
24
|
+
const themeDemoStyle = css`
|
|
25
|
+
:host {
|
|
26
|
+
color: ${elemTheme.color};
|
|
27
|
+
}
|
|
28
|
+
`;
|
|
29
|
+
|
|
30
|
+
@customElement('decorator-theme-demo')
|
|
31
|
+
@adoptedStyle(themeDemoStyle)
|
|
32
|
+
@shadow()
|
|
33
|
+
class DecoratorThemeDemo extends GemElement {
|
|
34
|
+
@boolattribute active: boolean;
|
|
35
|
+
|
|
36
|
+
@elemTheme((i) => [i.active])
|
|
37
|
+
#theme = () => ({
|
|
38
|
+
color: this.active ? 'rgb(0, 0, 255)' : 'rgb(255, 0, 0)',
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
render() {
|
|
42
|
+
return html`Theme Demo`;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const lightThemeDemoStyle = css`
|
|
47
|
+
:scope {
|
|
48
|
+
color: ${elemTheme.color};
|
|
49
|
+
}
|
|
50
|
+
`;
|
|
51
|
+
|
|
52
|
+
@customElement('decorator-theme-light-demo')
|
|
53
|
+
@adoptedStyle(lightThemeDemoStyle)
|
|
54
|
+
class DecoratorThemeLightDemo extends GemElement {
|
|
55
|
+
@boolattribute active: boolean;
|
|
56
|
+
|
|
57
|
+
@elemTheme((i) => [i.active])
|
|
58
|
+
#theme = () => ({
|
|
59
|
+
color: this.active ? 'rgb(0, 0, 255)' : 'rgb(255, 0, 0)',
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
render() {
|
|
63
|
+
return html`<span>Light Theme Demo</span>`;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
21
67
|
const store = createStore({
|
|
22
68
|
a: 1,
|
|
23
69
|
});
|
|
@@ -106,4 +152,25 @@ describe('装饰器', () => {
|
|
|
106
152
|
expect(el.renderCount).to.equal(3);
|
|
107
153
|
expect(a).to.equal(2);
|
|
108
154
|
});
|
|
155
|
+
|
|
156
|
+
it('createDecoratorTheme 响应式更新及多实例隔离', async () => {
|
|
157
|
+
const el1: DecoratorThemeDemo = await fixture(html`<decorator-theme-demo></decorator-theme-demo>`);
|
|
158
|
+
const el2: DecoratorThemeDemo = await fixture(html`<decorator-theme-demo active></decorator-theme-demo>`);
|
|
159
|
+
|
|
160
|
+
expect(getComputedStyle(el1).color).to.equal('rgb(255, 0, 0)');
|
|
161
|
+
expect(getComputedStyle(el2).color).to.equal('rgb(0, 0, 255)');
|
|
162
|
+
|
|
163
|
+
el1.active = true;
|
|
164
|
+
await Promise.resolve();
|
|
165
|
+
expect(getComputedStyle(el1).color).to.equal('rgb(0, 0, 255)');
|
|
166
|
+
expect(getComputedStyle(el2).color).to.equal('rgb(0, 0, 255)');
|
|
167
|
+
|
|
168
|
+
const elLight: DecoratorThemeLightDemo = await fixture(
|
|
169
|
+
html`<decorator-theme-light-demo></decorator-theme-light-demo>`,
|
|
170
|
+
);
|
|
171
|
+
expect(getComputedStyle(elLight).color).to.equal('rgb(255, 0, 0)');
|
|
172
|
+
elLight.active = true;
|
|
173
|
+
await Promise.resolve();
|
|
174
|
+
expect(getComputedStyle(elLight).color).to.equal('rgb(0, 0, 255)');
|
|
175
|
+
});
|
|
109
176
|
});
|
package/src/test/utils.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { assert, expect, should } from 'chai';
|
|
|
3
3
|
import type { TemplateResult } from '../lib/element';
|
|
4
4
|
import { render } from '../lib/element';
|
|
5
5
|
|
|
6
|
-
export { expect, should
|
|
6
|
+
export { assert, expect, should };
|
|
7
7
|
|
|
8
8
|
export function nextFrame() {
|
|
9
9
|
return new Promise((resolve) => requestAnimationFrame(() => resolve(null)));
|