@dooboostore/simple-web-component 1.0.24 → 1.0.26
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 +162 -33
- package/dist/cjs/decorators/addEventListener.js +1 -1
- package/dist/cjs/decorators/addEventListener.js.map +2 -2
- package/dist/cjs/decorators/applyAttribute.js +148 -0
- package/dist/cjs/decorators/applyAttribute.js.map +7 -0
- package/dist/cjs/decorators/applyClass.js +164 -0
- package/dist/cjs/decorators/applyClass.js.map +7 -0
- package/dist/cjs/decorators/applyNode.js +87 -194
- package/dist/cjs/decorators/applyNode.js.map +2 -2
- package/dist/cjs/decorators/{style.js → applyStyle.js} +50 -60
- package/dist/cjs/decorators/applyStyle.js.map +7 -0
- package/dist/cjs/decorators/attribute.js +10 -16
- package/dist/cjs/decorators/attribute.js.map +2 -2
- package/dist/cjs/decorators/changedAttributeHost.js +1 -1
- package/dist/cjs/decorators/changedAttributeHost.js.map +2 -2
- package/dist/cjs/decorators/elementDefine.js +14 -23
- package/dist/cjs/decorators/elementDefine.js.map +2 -2
- package/dist/cjs/decorators/emitCustomEvent.js +5 -2
- package/dist/cjs/decorators/emitCustomEvent.js.map +2 -2
- package/dist/cjs/decorators/index.js +3 -3
- package/dist/cjs/decorators/index.js.map +2 -2
- package/dist/cjs/decorators/lifecycles.js +9 -9
- package/dist/cjs/decorators/lifecycles.js.map +2 -2
- package/dist/cjs/decorators/query.js +1 -1
- package/dist/cjs/decorators/query.js.map +2 -2
- package/dist/cjs/decorators/queryAll.js +1 -1
- package/dist/cjs/decorators/queryAll.js.map +2 -2
- package/dist/cjs/elements/SwcAppEngine.js +19 -4
- package/dist/cjs/elements/SwcAppEngine.js.map +2 -2
- package/dist/cjs/elements/SwcAppMixin.js +2 -0
- package/dist/cjs/elements/SwcAppMixin.js.map +2 -2
- package/dist/cjs/utils/Utils.js +1 -1
- package/dist/cjs/utils/Utils.js.map +2 -2
- package/dist/esm/decorators/addEventListener.js +1 -1
- package/dist/esm/decorators/addEventListener.js.map +2 -2
- package/dist/esm/decorators/applyAttribute.js +129 -0
- package/dist/esm/decorators/applyAttribute.js.map +7 -0
- package/dist/esm/decorators/applyClass.js +145 -0
- package/dist/esm/decorators/applyClass.js.map +7 -0
- package/dist/esm/decorators/applyNode.js +87 -194
- package/dist/esm/decorators/applyNode.js.map +2 -2
- package/dist/esm/decorators/{style.js → applyStyle.js} +47 -57
- package/dist/esm/decorators/applyStyle.js.map +7 -0
- package/dist/esm/decorators/attribute.js +10 -16
- package/dist/esm/decorators/attribute.js.map +2 -2
- package/dist/esm/decorators/changedAttributeHost.js +1 -1
- package/dist/esm/decorators/changedAttributeHost.js.map +2 -2
- package/dist/esm/decorators/elementDefine.js +14 -23
- package/dist/esm/decorators/elementDefine.js.map +2 -2
- package/dist/esm/decorators/emitCustomEvent.js +5 -2
- package/dist/esm/decorators/emitCustomEvent.js.map +2 -2
- package/dist/esm/decorators/index.js +3 -3
- package/dist/esm/decorators/index.js.map +1 -1
- package/dist/esm/decorators/lifecycles.js +9 -9
- package/dist/esm/decorators/lifecycles.js.map +2 -2
- package/dist/esm/decorators/query.js +1 -1
- package/dist/esm/decorators/query.js.map +2 -2
- package/dist/esm/decorators/queryAll.js +1 -1
- package/dist/esm/decorators/queryAll.js.map +2 -2
- package/dist/esm/elements/SwcAppEngine.js +19 -4
- package/dist/esm/elements/SwcAppEngine.js.map +2 -2
- package/dist/esm/elements/SwcAppMixin.js +2 -0
- package/dist/esm/elements/SwcAppMixin.js.map +2 -2
- package/dist/esm/utils/Utils.js +1 -1
- package/dist/esm/utils/Utils.js.map +2 -2
- package/dist/esm-bundle/dooboostore-simple-web-component.esm.js +2853 -574
- package/dist/esm-bundle/dooboostore-simple-web-component.esm.js.map +4 -4
- package/dist/types/decorators/addEventListener.d.ts.map +1 -1
- package/dist/types/decorators/applyAttribute.d.ts +22 -0
- package/dist/types/decorators/applyAttribute.d.ts.map +1 -0
- package/dist/types/decorators/applyClass.d.ts +65 -0
- package/dist/types/decorators/applyClass.d.ts.map +1 -0
- package/dist/types/decorators/applyNode.d.ts +15 -123
- package/dist/types/decorators/applyNode.d.ts.map +1 -1
- package/dist/types/decorators/applyStyle.d.ts +21 -0
- package/dist/types/decorators/applyStyle.d.ts.map +1 -0
- package/dist/types/decorators/attribute.d.ts +10 -19
- package/dist/types/decorators/attribute.d.ts.map +1 -1
- package/dist/types/decorators/changedAttributeHost.d.ts.map +1 -1
- package/dist/types/decorators/elementDefine.d.ts.map +1 -1
- package/dist/types/decorators/emitCustomEvent.d.ts +1 -1
- package/dist/types/decorators/emitCustomEvent.d.ts.map +1 -1
- package/dist/types/decorators/index.d.ts +3 -3
- package/dist/types/decorators/index.d.ts.map +1 -1
- package/dist/types/decorators/lifecycles.d.ts.map +1 -1
- package/dist/types/decorators/query.d.ts.map +1 -1
- package/dist/types/decorators/queryAll.d.ts.map +1 -1
- package/dist/types/elements/SwcAppEngine.d.ts +7 -0
- package/dist/types/elements/SwcAppEngine.d.ts.map +1 -1
- package/dist/types/elements/SwcAppMixin.d.ts +1 -1
- package/dist/types/elements/SwcAppMixin.d.ts.map +1 -1
- package/dist/types/utils/Utils.d.ts.map +1 -1
- package/dist/umd-bundle/dooboostore-simple-web-component.umd.js +2853 -574
- package/dist/umd-bundle/dooboostore-simple-web-component.umd.js.map +4 -4
- package/package.json +2 -2
- package/src/decorators/addEventListener.ts +1 -1
- package/src/decorators/applyAttribute.ts +147 -0
- package/src/decorators/applyClass.ts +158 -0
- package/src/decorators/applyNode.ts +112 -330
- package/src/decorators/applyStyle.ts +128 -0
- package/src/decorators/attribute.ts +21 -55
- package/src/decorators/changedAttributeHost.ts +1 -1
- package/src/decorators/elementDefine.ts +18 -39
- package/src/decorators/emitCustomEvent.ts +6 -3
- package/src/decorators/index.ts +3 -3
- package/src/decorators/lifecycles.ts +9 -11
- package/src/decorators/query.ts +1 -1
- package/src/decorators/queryAll.ts +1 -1
- package/src/elements/SwcAppEngine.ts +32 -4
- package/src/elements/SwcAppMixin.ts +2 -0
- package/src/utils/Utils.ts +2 -1
- package/dist/cjs/decorators/classList.js +0 -177
- package/dist/cjs/decorators/classList.js.map +0 -7
- package/dist/cjs/decorators/setAttribute.js +0 -111
- package/dist/cjs/decorators/setAttribute.js.map +0 -7
- package/dist/cjs/decorators/style.js.map +0 -7
- package/dist/esm/decorators/classList.js +0 -158
- package/dist/esm/decorators/classList.js.map +0 -7
- package/dist/esm/decorators/setAttribute.js +0 -92
- package/dist/esm/decorators/setAttribute.js.map +0 -7
- package/dist/esm/decorators/style.js.map +0 -7
- package/dist/types/decorators/classList.d.ts +0 -71
- package/dist/types/decorators/classList.d.ts.map +0 -1
- package/dist/types/decorators/setAttribute.d.ts +0 -23
- package/dist/types/decorators/setAttribute.d.ts.map +0 -1
- package/dist/types/decorators/style.d.ts +0 -58
- package/dist/types/decorators/style.d.ts.map +0 -1
- package/src/decorators/classList.ts +0 -234
- package/src/decorators/setAttribute.ts +0 -114
- package/src/decorators/style.ts +0 -185
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
import { ReflectUtils } from '@dooboostore/core';
|
|
2
|
-
import { ensureInit, getElementConfig } from './elementDefine';
|
|
3
|
-
import { SwcUtils } from '../utils/Utils';
|
|
4
|
-
import { SwcQueryOptions } from '../types';
|
|
5
|
-
|
|
6
|
-
export interface SetAttributeMetadata {
|
|
7
|
-
propertyKey: string | symbol;
|
|
8
|
-
selector: string;
|
|
9
|
-
name: string;
|
|
10
|
-
options: SwcQueryOptions;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export const SET_ATTRIBUTE_METADATA_KEY = Symbol('simple-web-component:set-attribute');
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* @setAttribute decorator to surgically update an attribute of a target element.
|
|
17
|
-
* Usage: @setAttribute(':host', 'count')
|
|
18
|
-
* Usage: @setAttribute('#child', 'disabled')
|
|
19
|
-
*/
|
|
20
|
-
export function setAttribute(selector: string, name: string): MethodDecorator;
|
|
21
|
-
export function setAttribute(selector: string, name: string, options?: SwcQueryOptions): MethodDecorator;
|
|
22
|
-
export function setAttribute(selector: string, name: string, options: SwcQueryOptions = {}): MethodDecorator {
|
|
23
|
-
return (target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor) => {
|
|
24
|
-
const constructor = target.constructor;
|
|
25
|
-
let metaList = ReflectUtils.getOwnMetadata(SET_ATTRIBUTE_METADATA_KEY, constructor) as Map<string | symbol, SetAttributeMetadata>;
|
|
26
|
-
if (!metaList) {
|
|
27
|
-
metaList = new Map<string | symbol, SetAttributeMetadata>();
|
|
28
|
-
ReflectUtils.defineMetadata(SET_ATTRIBUTE_METADATA_KEY, metaList, constructor);
|
|
29
|
-
}
|
|
30
|
-
metaList.set(propertyKey, { propertyKey, selector, name, options });
|
|
31
|
-
|
|
32
|
-
const original = descriptor.value;
|
|
33
|
-
descriptor.value = async function (...args: any[]) {
|
|
34
|
-
ensureInit(this);
|
|
35
|
-
const res = await original.apply(this, args);
|
|
36
|
-
if (res !== undefined) {
|
|
37
|
-
const hostSet = SwcUtils.getHostSet(this as any);
|
|
38
|
-
const conf = getElementConfig(this);
|
|
39
|
-
const currentWin = (this as any)._resolveWindow?.(conf) || ((typeof window !== 'undefined' ? window : undefined) as Window);
|
|
40
|
-
|
|
41
|
-
const targetEls: any[] = [];
|
|
42
|
-
const r = options.root || 'auto';
|
|
43
|
-
|
|
44
|
-
const applyRoot = (t: any) => {
|
|
45
|
-
if (!t) return;
|
|
46
|
-
if (r === 'auto') {
|
|
47
|
-
// Attributes belong to the ELEMENT, not the ShadowRoot.
|
|
48
|
-
targetEls.push(t);
|
|
49
|
-
} else {
|
|
50
|
-
if (r === 'light' || r === 'all') targetEls.push(t);
|
|
51
|
-
if ((r === 'shadow' || r === 'all') && (t as any).shadowRoot) targetEls.push((t as any).shadowRoot);
|
|
52
|
-
}
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
if (selector === ':window') targetEls.push(currentWin);
|
|
56
|
-
else if (selector === ':document') targetEls.push(currentWin.document as any);
|
|
57
|
-
else if (selector === ':parentHost') applyRoot(hostSet.$parentHost);
|
|
58
|
-
else if (selector === ':appHost') applyRoot(hostSet.$appHost);
|
|
59
|
-
else if (selector === ':firstHost') applyRoot(hostSet.$firstHost);
|
|
60
|
-
else if (selector === ':lastHost') applyRoot(hostSet.$lastHost);
|
|
61
|
-
else if (selector === ':firstAppHost') applyRoot(hostSet.$firstAppHost);
|
|
62
|
-
else if (selector === ':lastAppHost') applyRoot(hostSet.$lastAppHost);
|
|
63
|
-
else if (selector === ':hosts') hostSet.$hosts.forEach(applyRoot);
|
|
64
|
-
else if (selector === ':appHosts') hostSet.$appHosts.forEach(applyRoot);
|
|
65
|
-
else if (selector === ':host' || !selector) applyRoot(this);
|
|
66
|
-
else {
|
|
67
|
-
const roots: any[] = [];
|
|
68
|
-
if (r === 'shadow') {
|
|
69
|
-
if ((this as any).shadowRoot) roots.push((this as any).shadowRoot);
|
|
70
|
-
} else if (r === 'light') {
|
|
71
|
-
roots.push(this as any);
|
|
72
|
-
} else if (r === 'all') {
|
|
73
|
-
roots.push(this as any);
|
|
74
|
-
if ((this as any).shadowRoot) roots.push((this as any).shadowRoot);
|
|
75
|
-
} else {
|
|
76
|
-
roots.push((this as any).shadowRoot || (this as any));
|
|
77
|
-
}
|
|
78
|
-
roots.forEach(root => targetEls.push(...root.querySelectorAll(selector)));
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
targetEls.forEach(targetEl => {
|
|
82
|
-
if (!targetEl || typeof (targetEl as any).setAttribute !== 'function') return;
|
|
83
|
-
if (res === null) (targetEl as any).removeAttribute(name);
|
|
84
|
-
else (targetEl as any).setAttribute(name, String(res));
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
return res;
|
|
88
|
-
};
|
|
89
|
-
};
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
export const getSetAttributeMetadata = (target: any): Map<string | symbol, SetAttributeMetadata> | undefined => {
|
|
93
|
-
const constructor = target instanceof Function ? target : target.constructor;
|
|
94
|
-
return ReflectUtils.getMetadata(SET_ATTRIBUTE_METADATA_KEY, constructor);
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
export const findAllSetAttributeMetadata = (target: any): Map<string | symbol, SetAttributeMetadata> => {
|
|
98
|
-
const result = new Map<string | symbol, SetAttributeMetadata>();
|
|
99
|
-
const maps = ReflectUtils.findAllMetadata<Map<string | symbol, SetAttributeMetadata>>(SET_ATTRIBUTE_METADATA_KEY, target);
|
|
100
|
-
maps.forEach(map => {
|
|
101
|
-
if (map instanceof Map) {
|
|
102
|
-
map.forEach((v, k) => result.set(k, v));
|
|
103
|
-
}
|
|
104
|
-
});
|
|
105
|
-
return result;
|
|
106
|
-
};
|
|
107
|
-
|
|
108
|
-
/**
|
|
109
|
-
* @setAttributeHost decorator - simplified version of @setAttribute for :host selector
|
|
110
|
-
* Usage: @setAttributeHost('aria-disabled')
|
|
111
|
-
*/
|
|
112
|
-
export function setAttributeHost(name: string, options?: SwcQueryOptions): MethodDecorator {
|
|
113
|
-
return setAttribute(':host', name, options);
|
|
114
|
-
}
|
package/src/decorators/style.ts
DELETED
|
@@ -1,185 +0,0 @@
|
|
|
1
|
-
import { ReflectUtils } from '@dooboostore/core';
|
|
2
|
-
import { ensureInit } from './elementDefine';
|
|
3
|
-
import { SwcUtils } from '../utils/Utils';
|
|
4
|
-
import { SwcQueryOptions } from '../types';
|
|
5
|
-
|
|
6
|
-
export type StyleAction = 'set' | 'update' | 'remove';
|
|
7
|
-
|
|
8
|
-
export interface StyleOptions extends SwcQueryOptions {}
|
|
9
|
-
|
|
10
|
-
export interface StyleMetadata {
|
|
11
|
-
propertyKey: string | symbol;
|
|
12
|
-
selector: string;
|
|
13
|
-
action: StyleAction;
|
|
14
|
-
options: StyleOptions;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export const STYLE_METADATA_KEY = Symbol('simple-web-component:style');
|
|
18
|
-
|
|
19
|
-
function createStyleDecorator(action: StyleAction) {
|
|
20
|
-
return (selector: string, options: StyleOptions = {}): MethodDecorator => {
|
|
21
|
-
return (target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor) => {
|
|
22
|
-
const constructor = target.constructor;
|
|
23
|
-
let metaList = ReflectUtils.getOwnMetadata(STYLE_METADATA_KEY, constructor) as Map<string | symbol, StyleMetadata>;
|
|
24
|
-
if (!metaList) {
|
|
25
|
-
metaList = new Map<string | symbol, StyleMetadata>();
|
|
26
|
-
ReflectUtils.defineMetadata(STYLE_METADATA_KEY, metaList, constructor);
|
|
27
|
-
}
|
|
28
|
-
metaList.set(propertyKey, { propertyKey, selector, action, options });
|
|
29
|
-
|
|
30
|
-
const original = descriptor.value;
|
|
31
|
-
descriptor.value = async function (...args: any[]) {
|
|
32
|
-
ensureInit(this);
|
|
33
|
-
const res = await original.apply(this, args);
|
|
34
|
-
if (res !== undefined) {
|
|
35
|
-
const r = options.root || 'auto';
|
|
36
|
-
const hostSet = SwcUtils.getHostSet(this as any);
|
|
37
|
-
const targetEls: HTMLElement[] = [];
|
|
38
|
-
|
|
39
|
-
const applyRoot = (t: any) => {
|
|
40
|
-
if (!t || !(t instanceof HTMLElement)) return;
|
|
41
|
-
if (r === 'auto') {
|
|
42
|
-
// Styles belong to the ELEMENT, not the ShadowRoot.
|
|
43
|
-
targetEls.push(t);
|
|
44
|
-
} else {
|
|
45
|
-
if (r === 'light' || r === 'all') targetEls.push(t);
|
|
46
|
-
if ((r === 'shadow' || r === 'all') && t.shadowRoot) {
|
|
47
|
-
// ShadowRoot doesn't have a style property, so we skip it.
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
if (selector === ':parentHost') applyRoot(hostSet.$parentHost);
|
|
53
|
-
else if (selector === ':appHost') applyRoot(hostSet.$appHost);
|
|
54
|
-
else if (selector === ':firstHost') applyRoot(hostSet.$firstHost);
|
|
55
|
-
else if (selector === ':lastHost') applyRoot(hostSet.$lastHost);
|
|
56
|
-
else if (selector === ':firstAppHost') applyRoot(hostSet.$firstAppHost);
|
|
57
|
-
else if (selector === ':lastAppHost') applyRoot(hostSet.$lastAppHost);
|
|
58
|
-
else if (selector === ':hosts') hostSet.$hosts.forEach(applyRoot);
|
|
59
|
-
else if (selector === ':appHosts') hostSet.$appHosts.forEach(applyRoot);
|
|
60
|
-
else if (selector === ':host' || !selector) applyRoot(this);
|
|
61
|
-
else {
|
|
62
|
-
if (r === 'shadow') {
|
|
63
|
-
const found = this.shadowRoot?.querySelectorAll(selector);
|
|
64
|
-
if (found) targetEls.push(...(Array.from(found) as HTMLElement[]));
|
|
65
|
-
} else if (r === 'light') {
|
|
66
|
-
const found = (this as any).querySelectorAll(selector);
|
|
67
|
-
if (found) targetEls.push(...(Array.from(found) as HTMLElement[]));
|
|
68
|
-
} else if (r === 'all') {
|
|
69
|
-
const sFound = this.shadowRoot?.querySelectorAll(selector);
|
|
70
|
-
const lFound = (this as any).querySelectorAll(selector);
|
|
71
|
-
if (sFound) targetEls.push(...(Array.from(sFound) as HTMLElement[]));
|
|
72
|
-
if (lFound) targetEls.push(...(Array.from(lFound) as HTMLElement[]));
|
|
73
|
-
} else {
|
|
74
|
-
// auto
|
|
75
|
-
const found = (this.shadowRoot || (this as any)).querySelectorAll(selector);
|
|
76
|
-
if (found) targetEls.push(...(Array.from(found) as HTMLElement[]));
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
targetEls.forEach(targetEl => {
|
|
81
|
-
if (action === 'set') {
|
|
82
|
-
targetEl.style.cssText = '';
|
|
83
|
-
if (typeof res === 'object' && res !== null) {
|
|
84
|
-
Object.assign(targetEl.style, res);
|
|
85
|
-
} else if (typeof res === 'string') {
|
|
86
|
-
targetEl.style.cssText = res;
|
|
87
|
-
}
|
|
88
|
-
} else if (action === 'update') {
|
|
89
|
-
if (typeof res === 'object' && res !== null) {
|
|
90
|
-
Object.assign(targetEl.style, res);
|
|
91
|
-
}
|
|
92
|
-
} else if (action === 'remove') {
|
|
93
|
-
const props = Array.isArray(res) ? res : [res];
|
|
94
|
-
props.forEach(p => targetEl.style.removeProperty(String(p)));
|
|
95
|
-
}
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
return res;
|
|
99
|
-
};
|
|
100
|
-
};
|
|
101
|
-
};
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* @setStyle decorator to surgically set styles on a target element (replaces all existing styles).
|
|
106
|
-
* Usage: @setStyle('#box') getStyles() { return { color: 'red', display: 'block' }; }
|
|
107
|
-
* Usage: @setStyle('#box', { root: 'shadow' }) getStyles() { return { color: 'red' }; }
|
|
108
|
-
*/
|
|
109
|
-
export const setStyle = (selector: string, options: StyleOptions = {}) => createStyleDecorator('set')(selector, options);
|
|
110
|
-
|
|
111
|
-
/**
|
|
112
|
-
* @setStyleHost decorator - simplified version of @setStyle for :host selector.
|
|
113
|
-
* Usage: @setStyleHost setHostStyle() { return { color: 'red' }; }
|
|
114
|
-
* Usage: @setStyleHost() setHostStyle() { return { color: 'red' }; }
|
|
115
|
-
* Usage: @setStyleHost({ ... }) setHostStyle() { return { color: 'red' }; }
|
|
116
|
-
*/
|
|
117
|
-
export function setStyleHost(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): any;
|
|
118
|
-
export function setStyleHost(): MethodDecorator;
|
|
119
|
-
export function setStyleHost(options: StyleOptions): MethodDecorator;
|
|
120
|
-
export function setStyleHost(targetOrOptions?: any, propertyKey?: string | symbol, descriptor?: PropertyDescriptor): any {
|
|
121
|
-
if (propertyKey !== undefined) {
|
|
122
|
-
const decorator = createStyleDecorator('set')(':host', {});
|
|
123
|
-
return decorator(targetOrOptions, propertyKey, descriptor);
|
|
124
|
-
}
|
|
125
|
-
return createStyleDecorator('set')(':host', (targetOrOptions as StyleOptions) || {});
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
/**
|
|
129
|
-
* @updateStyle decorator to surgically update styles on a target element (merges with existing styles).
|
|
130
|
-
* Usage: @updateStyle('#box') updateStyles() { return { color: 'blue' }; }
|
|
131
|
-
* Usage: @updateStyle('#box', { root: 'shadow' }) updateStyles() { return { color: 'blue' }; }
|
|
132
|
-
*/
|
|
133
|
-
export const updateStyle = (selector: string, options: StyleOptions = {}) => createStyleDecorator('update')(selector, options);
|
|
134
|
-
|
|
135
|
-
/**
|
|
136
|
-
* @updateStyleHost decorator - simplified version of @updateStyle for :host selector.
|
|
137
|
-
* Usage: @updateStyleHost updateStyles() { return { color: 'blue' }; }
|
|
138
|
-
* Usage: @updateStyleHost() updateStyles() { return { color: 'blue' }; }
|
|
139
|
-
* Usage: @updateStyleHost({ ... }) updateStyles() { return { color: 'blue' }; }
|
|
140
|
-
*/
|
|
141
|
-
export function updateStyleHost(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): any;
|
|
142
|
-
export function updateStyleHost(): MethodDecorator;
|
|
143
|
-
export function updateStyleHost(options: StyleOptions): MethodDecorator;
|
|
144
|
-
export function updateStyleHost(targetOrOptions?: any, propertyKey?: string | symbol, descriptor?: PropertyDescriptor): any {
|
|
145
|
-
if (propertyKey !== undefined) {
|
|
146
|
-
const decorator = createStyleDecorator('update')(':host', {});
|
|
147
|
-
return decorator(targetOrOptions, propertyKey, descriptor);
|
|
148
|
-
}
|
|
149
|
-
return createStyleDecorator('update')(':host', (targetOrOptions as StyleOptions) || {});
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
/**
|
|
153
|
-
* @removeStyle decorator to surgically remove styles from a target element.
|
|
154
|
-
* Usage: @removeStyle('#box') clearStyles() { return ['color', 'display']; }
|
|
155
|
-
* Usage: @removeStyle('#box', { root: 'shadow' }) clearStyles() { return ['color']; }
|
|
156
|
-
*/
|
|
157
|
-
export const removeStyle = (selector: string, options: StyleOptions = {}) => createStyleDecorator('remove')(selector, options);
|
|
158
|
-
|
|
159
|
-
/**
|
|
160
|
-
* @removeStyleHost decorator - simplified version of @removeStyle for :host selector.
|
|
161
|
-
* Usage: @removeStyleHost clearStyles() { return ['color']; }
|
|
162
|
-
* Usage: @removeStyleHost() clearStyles() { return ['color']; }
|
|
163
|
-
* Usage: @removeStyleHost({ ... }) clearStyles() { return ['color']; }
|
|
164
|
-
*/
|
|
165
|
-
export function removeStyleHost(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): any;
|
|
166
|
-
export function removeStyleHost(): MethodDecorator;
|
|
167
|
-
export function removeStyleHost(options: StyleOptions): MethodDecorator;
|
|
168
|
-
export function removeStyleHost(targetOrOptions?: any, propertyKey?: string | symbol, descriptor?: PropertyDescriptor): any {
|
|
169
|
-
if (propertyKey !== undefined) {
|
|
170
|
-
const decorator = createStyleDecorator('remove')(':host', {});
|
|
171
|
-
return decorator(targetOrOptions, propertyKey, descriptor);
|
|
172
|
-
}
|
|
173
|
-
return createStyleDecorator('remove')(':host', (targetOrOptions as StyleOptions) || {});
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
export const findAllStyleMetadata = (target: any): Map<string | symbol, StyleMetadata> => {
|
|
177
|
-
const result = new Map<string | symbol, StyleMetadata>();
|
|
178
|
-
const maps = ReflectUtils.findAllMetadata<Map<string | symbol, StyleMetadata>>(STYLE_METADATA_KEY, target);
|
|
179
|
-
maps.forEach(map => {
|
|
180
|
-
if (map instanceof Map) {
|
|
181
|
-
map.forEach((v, k) => result.set(k, v));
|
|
182
|
-
}
|
|
183
|
-
});
|
|
184
|
-
return result;
|
|
185
|
-
};
|