@rhtml/custom-attributes 0.0.112 → 0.0.113
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 +31 -0
- package/dist/attribute.d.ts +15 -0
- package/dist/attribute.js +30 -0
- package/dist/attribute.js.map +1 -0
- package/dist/custom-registry.d.ts +18 -0
- package/dist/custom-registry.js +155 -0
- package/dist/custom-registry.js.map +1 -0
- package/dist/decorators/index.d.ts +21 -0
- package/dist/decorators/index.js +54 -0
- package/dist/decorators/index.js.map +1 -0
- package/dist/helpers/index.d.ts +2 -0
- package/dist/helpers/index.js +34 -0
- package/dist/helpers/index.js.map +1 -0
- package/dist/index.d.ts +6 -89
- package/dist/index.js +16 -310
- package/dist/index.js.map +1 -1
- package/dist/media-attribute.d.ts +27 -0
- package/dist/media-attribute.js +69 -0
- package/dist/media-attribute.js.map +1 -0
- package/dist/types.d.ts +30 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/package.json +1 -1
- package/src/attribute.ts +35 -0
- package/src/custom-registry.ts +171 -0
- package/src/decorators/index.ts +58 -0
- package/src/helpers/index.ts +35 -0
- package/src/index.ts +6 -388
- package/src/media-attribute.ts +92 -0
- package/src/types.ts +34 -0
package/dist/index.js
CHANGED
|
@@ -1,313 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const OnUpdateAttribute = prototype.OnUpdateAttribute || noop;
|
|
12
|
-
let observer;
|
|
13
|
-
prototype.OnInit = function () {
|
|
14
|
-
var _a;
|
|
15
|
-
const element = (_a = this.element) !== null && _a !== void 0 ? _a : this;
|
|
16
|
-
if (observer) {
|
|
17
|
-
observer.disconnect();
|
|
18
|
-
}
|
|
19
|
-
observer = new MutationObserver(() => {
|
|
20
|
-
OnUpdateAttribute.call(this, memberName, element.getAttribute(memberName));
|
|
21
|
-
target[memberName] = element.getAttribute(memberName);
|
|
22
|
-
});
|
|
23
|
-
observer.observe(element, {
|
|
24
|
-
attributeFilter: [memberName],
|
|
25
|
-
attributes: true
|
|
26
|
-
});
|
|
27
|
-
return OnInit.call(this);
|
|
28
|
-
};
|
|
29
|
-
prototype.OnDestroy = function () {
|
|
30
|
-
observer.disconnect();
|
|
31
|
-
return OnDestroy.call(this);
|
|
32
|
-
};
|
|
33
|
-
};
|
|
34
|
-
/**
|
|
35
|
-
* Decorator @Input
|
|
36
|
-
* Used to get attribute from element
|
|
37
|
-
*/
|
|
38
|
-
exports.Input = (options) => (target, memberName) => {
|
|
39
|
-
const OnInit = target.OnInit || noop;
|
|
40
|
-
Object.defineProperty(target, 'OnInit', {
|
|
41
|
-
value() {
|
|
42
|
-
var _a;
|
|
43
|
-
let originalValue = this[memberName];
|
|
44
|
-
const element = (_a = this.element) !== null && _a !== void 0 ? _a : this;
|
|
45
|
-
Object.defineProperty(this, memberName, {
|
|
46
|
-
get: function () {
|
|
47
|
-
originalValue = element.getAttribute(memberName.toLowerCase());
|
|
48
|
-
return originalValue;
|
|
49
|
-
},
|
|
50
|
-
set(value) {
|
|
51
|
-
element.setAttribute(memberName.toLowerCase(), value);
|
|
52
|
-
originalValue = value;
|
|
53
|
-
},
|
|
54
|
-
configurable: true
|
|
55
|
-
});
|
|
56
|
-
return OnInit.call(this);
|
|
57
|
-
},
|
|
58
|
-
configurable: true
|
|
59
|
-
});
|
|
60
|
-
if (options === null || options === void 0 ? void 0 : options.observe) {
|
|
61
|
-
observe(target, memberName);
|
|
62
|
-
}
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
+
for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p);
|
|
63
11
|
};
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
};
|
|
72
|
-
};
|
|
73
|
-
/**
|
|
74
|
-
* Decorator @CustomAttribute
|
|
75
|
-
* Accepts parameter options with selector and registry
|
|
76
|
-
*/
|
|
77
|
-
exports.CustomAttribute = exports.Modifier;
|
|
78
|
-
/**
|
|
79
|
-
* Decorator @Directive
|
|
80
|
-
* Accepts parameter options with selector and registry
|
|
81
|
-
*/
|
|
82
|
-
exports.Directive = exports.Modifier;
|
|
83
|
-
/* */
|
|
84
|
-
class Attribute {
|
|
85
|
-
setStyles(keys) {
|
|
86
|
-
return (div) => {
|
|
87
|
-
for (const [key, value] of Object.entries(keys)) {
|
|
88
|
-
div['style'][key] = value;
|
|
89
|
-
}
|
|
90
|
-
};
|
|
91
|
-
}
|
|
92
|
-
OnInit() {
|
|
93
|
-
/* */
|
|
94
|
-
}
|
|
95
|
-
OnDestroy() {
|
|
96
|
-
/* */
|
|
97
|
-
}
|
|
98
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
99
|
-
OnUpdate(_oldValue, _newValue) {
|
|
100
|
-
/* */
|
|
101
|
-
}
|
|
102
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
103
|
-
OnUpdateAttribute(_name, _value) {
|
|
104
|
-
/* */
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
exports.Attribute = Attribute;
|
|
108
|
-
/**
|
|
109
|
-
* Media query Attribute
|
|
110
|
-
* for performance reasons it is key value pair
|
|
111
|
-
*/
|
|
112
|
-
exports.MediaMatchers = new Map([
|
|
113
|
-
['screen and (max-width: 599px)', 'xs'],
|
|
114
|
-
['screen and (min-width: 600px) and (max-width: 959px)', 'sm'],
|
|
115
|
-
['screen and (min-width: 960px) and (max-width: 1279px)', 'md'],
|
|
116
|
-
['screen and (min-width: 1280px) and (max-width: 1919px)', 'lg'],
|
|
117
|
-
['screen and (min-width: 1920px) and (max-width: 5000px)', 'xl'],
|
|
118
|
-
['screen and (max-width: 959px)', 'lt-md'],
|
|
119
|
-
['screen and (max-width: 1279px)', 'lt-lg'],
|
|
120
|
-
['screen and (max-width: 1919px)', 'lt-xl'],
|
|
121
|
-
['screen and (min-width: 600px)', 'gt-xs'],
|
|
122
|
-
['screen and (min-width: 960px)', 'gt-sm'],
|
|
123
|
-
['screen and (min-width: 1280px)', 'gt-md'],
|
|
124
|
-
['screen and (min-width: 1920px)', 'gt-lg']
|
|
125
|
-
]);
|
|
126
|
-
exports.Breakpoints = [...exports.MediaMatchers.values()];
|
|
127
|
-
exports.createFiltersFromSelector = (selector) => [
|
|
128
|
-
...exports.Breakpoints.map(breakpoint => `${selector}.${breakpoint}`),
|
|
129
|
-
selector
|
|
130
|
-
];
|
|
131
|
-
class MediaQueryAttribute extends Attribute {
|
|
132
|
-
constructor() {
|
|
133
|
-
super(...arguments);
|
|
134
|
-
this.matchers = new Map();
|
|
135
|
-
this.cachedAttributes = new Map();
|
|
136
|
-
this.listener = (event) => {
|
|
137
|
-
const key = `${this.selector.toLowerCase()}.${exports.MediaMatchers.get(event.media)}`;
|
|
138
|
-
const attribute = this.cachedAttributes.get(key);
|
|
139
|
-
if (event.matches && attribute) {
|
|
140
|
-
return this.OnEnterMediaQuery([event, attribute]);
|
|
141
|
-
}
|
|
142
|
-
return this.OnExitMediaQuery([event, key]);
|
|
143
|
-
};
|
|
144
|
-
}
|
|
145
|
-
OnInit() {
|
|
146
|
-
if (this.OnEnterMediaQuery || this.OnExitMediaQuery) {
|
|
147
|
-
this.originalValue = this.value;
|
|
148
|
-
for (const query of exports.MediaMatchers.keys()) {
|
|
149
|
-
const matcher = window.matchMedia(query);
|
|
150
|
-
const attr = Object.values(this.element.attributes).find(v => v.name ===
|
|
151
|
-
`${this.selector.toLowerCase()}.${exports.MediaMatchers.get(query)}`);
|
|
152
|
-
if (attr) {
|
|
153
|
-
this.cachedAttributes.set(attr.name, attr);
|
|
154
|
-
matcher.addEventListener('change', this.listener);
|
|
155
|
-
}
|
|
156
|
-
if (attr && matcher.matches) {
|
|
157
|
-
this.listener(matcher);
|
|
158
|
-
}
|
|
159
|
-
this.matchers.set(matcher, matcher);
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
OnDestroy() {
|
|
164
|
-
for (const matcher of this.matchers.values()) {
|
|
165
|
-
matcher.removeEventListener('change', this.listener);
|
|
166
|
-
}
|
|
167
|
-
this.cachedAttributes.clear();
|
|
168
|
-
this.matchers.clear();
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
exports.MediaQueryAttribute = MediaQueryAttribute;
|
|
172
|
-
/* Media query Attribute END */
|
|
173
|
-
class CustomAttributeRegistry {
|
|
174
|
-
constructor(parent) {
|
|
175
|
-
this.parent = parent;
|
|
176
|
-
this._attrMap = new Map();
|
|
177
|
-
this._elementMap = new Map();
|
|
178
|
-
if (!parent) {
|
|
179
|
-
throw new Error('Must be given a parent element');
|
|
180
|
-
}
|
|
181
|
-
this.observe();
|
|
182
|
-
}
|
|
183
|
-
define(attrName, Constructor) {
|
|
184
|
-
this._attrMap.set(attrName.toLowerCase(), Constructor);
|
|
185
|
-
this.upgradeAttribute(attrName);
|
|
186
|
-
}
|
|
187
|
-
get(element, attrName) {
|
|
188
|
-
const map = this._elementMap.get(element);
|
|
189
|
-
if (!map)
|
|
190
|
-
return;
|
|
191
|
-
return map.get(attrName.toLowerCase());
|
|
192
|
-
}
|
|
193
|
-
getConstructor(attrName) {
|
|
194
|
-
return this._attrMap.get(attrName.toLowerCase());
|
|
195
|
-
}
|
|
196
|
-
observe() {
|
|
197
|
-
var _a, _b;
|
|
198
|
-
this.observer = new MutationObserver(mutations => {
|
|
199
|
-
for (const mutation of mutations) {
|
|
200
|
-
if (mutation.type === 'attributes') {
|
|
201
|
-
const attr = this.getConstructor(mutation.attributeName);
|
|
202
|
-
if (attr) {
|
|
203
|
-
this.found(mutation.attributeName, mutation.target, mutation.oldValue);
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
else {
|
|
207
|
-
for (const node of mutation.removedNodes) {
|
|
208
|
-
this.downgrade(node);
|
|
209
|
-
}
|
|
210
|
-
for (const node of mutation.addedNodes) {
|
|
211
|
-
this.upgradeElement(node);
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
});
|
|
216
|
-
this.observer.observe((_b = (_a = this.parent) === null || _a === void 0 ? void 0 : _a['shadowRoot']) !== null && _b !== void 0 ? _b : this.parent, {
|
|
217
|
-
childList: true,
|
|
218
|
-
subtree: true,
|
|
219
|
-
attributes: true,
|
|
220
|
-
attributeOldValue: true
|
|
221
|
-
});
|
|
222
|
-
}
|
|
223
|
-
unsubscribe() {
|
|
224
|
-
var _a;
|
|
225
|
-
(_a = this.observer) === null || _a === void 0 ? void 0 : _a.disconnect();
|
|
226
|
-
const values = [...this._elementMap.values()];
|
|
227
|
-
for (const elModifiers of values) {
|
|
228
|
-
const modifiers = [...elModifiers.values()];
|
|
229
|
-
for (const modifier of modifiers) {
|
|
230
|
-
modifier.OnDestroy();
|
|
231
|
-
}
|
|
232
|
-
elModifiers.clear();
|
|
233
|
-
}
|
|
234
|
-
this._elementMap.clear();
|
|
235
|
-
}
|
|
236
|
-
upgradeAttribute(attrName, doc) {
|
|
237
|
-
const parent = doc || this.parent;
|
|
238
|
-
const matches = parent.querySelectorAll('[' + attrName + ']');
|
|
239
|
-
for (const match of [...matches]) {
|
|
240
|
-
this.found(attrName, match);
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
upgradeElement(element) {
|
|
244
|
-
if (element.nodeType !== 1) {
|
|
245
|
-
return;
|
|
246
|
-
}
|
|
247
|
-
for (const attr of element.attributes) {
|
|
248
|
-
if (this.getConstructor(attr.name)) {
|
|
249
|
-
this.found(attr.name, element);
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
for (const [attr] of this._attrMap) {
|
|
253
|
-
this.upgradeAttribute(attr, element);
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
downgrade(element) {
|
|
257
|
-
const map = this._elementMap.get(element);
|
|
258
|
-
if (!map) {
|
|
259
|
-
return;
|
|
260
|
-
}
|
|
261
|
-
for (const [, instance] of map) {
|
|
262
|
-
if (instance.OnDestroy) {
|
|
263
|
-
instance.OnDestroy();
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
this._elementMap.delete(element);
|
|
267
|
-
}
|
|
268
|
-
found(attributeName, el, oldVal) {
|
|
269
|
-
var _a, _b;
|
|
270
|
-
let map = this._elementMap.get(el);
|
|
271
|
-
if (!map) {
|
|
272
|
-
map = new Map();
|
|
273
|
-
this._elementMap.set(el, map);
|
|
274
|
-
}
|
|
275
|
-
const modifier = map.get(attributeName);
|
|
276
|
-
const attribute = el.getAttribute(attributeName);
|
|
277
|
-
if (!modifier) {
|
|
278
|
-
const Modifier = this.getConstructor(attributeName);
|
|
279
|
-
const modifier = new Modifier();
|
|
280
|
-
if ((_b = (_a = Modifier.options) === null || _a === void 0 ? void 0 : _a.observedAttributes) === null || _b === void 0 ? void 0 : _b.length) {
|
|
281
|
-
for (const observedAttribute of Modifier.options.observedAttributes) {
|
|
282
|
-
observe(modifier, observedAttribute);
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
map.set(attributeName, modifier);
|
|
286
|
-
modifier.element = el;
|
|
287
|
-
modifier.selector = attributeName;
|
|
288
|
-
modifier.value = attribute || modifier.value;
|
|
289
|
-
modifier.parent = this.parent;
|
|
290
|
-
if (modifier.OnInit) {
|
|
291
|
-
modifier.OnInit();
|
|
292
|
-
}
|
|
293
|
-
return;
|
|
294
|
-
}
|
|
295
|
-
if (attribute == null && !!modifier.value) {
|
|
296
|
-
modifier.value = attribute;
|
|
297
|
-
if (modifier.OnDestroy) {
|
|
298
|
-
modifier.OnDestroy();
|
|
299
|
-
}
|
|
300
|
-
map.delete(attributeName);
|
|
301
|
-
return;
|
|
302
|
-
}
|
|
303
|
-
if (attribute !== modifier.value) {
|
|
304
|
-
modifier.value = attribute;
|
|
305
|
-
if (modifier.OnUpdate) {
|
|
306
|
-
modifier.OnUpdate(oldVal, attribute);
|
|
307
|
-
}
|
|
308
|
-
return;
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
exports.CustomAttributeRegistry = CustomAttributeRegistry;
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
__exportStar(require("./attribute"), exports);
|
|
14
|
+
__exportStar(require("./custom-registry"), exports);
|
|
15
|
+
__exportStar(require("./decorators"), exports);
|
|
16
|
+
__exportStar(require("./helpers"), exports);
|
|
17
|
+
__exportStar(require("./media-attribute"), exports);
|
|
18
|
+
__exportStar(require("./types"), exports);
|
|
313
19
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,8CAA4B;AAC5B,oDAAkC;AAClC,+CAA6B;AAC7B,4CAA0B;AAC1B,oDAAkC;AAClC,0CAAwB"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Attribute } from './attribute';
|
|
2
|
+
/**
|
|
3
|
+
* Media query Attribute
|
|
4
|
+
* for performance reasons it is key value pair
|
|
5
|
+
*/
|
|
6
|
+
export declare const MediaMatchers: Map<string, string>;
|
|
7
|
+
declare type MediaEvent = MediaQueryList | MediaQueryListEvent;
|
|
8
|
+
export declare type EnterMediaQueryAttributes = [MediaEvent, Attr];
|
|
9
|
+
export declare type ExitMediaQueryAttributes = [MediaEvent, string];
|
|
10
|
+
export interface OnUpdateMediaQuery {
|
|
11
|
+
OnEnterMediaQuery(tuple: [MediaEvent, Attr]): void;
|
|
12
|
+
OnExitMediaQuery(tuple: [MediaEvent, string]): void;
|
|
13
|
+
}
|
|
14
|
+
export declare const Breakpoints: string[];
|
|
15
|
+
export declare const createFiltersFromSelector: (selector: string) => string[];
|
|
16
|
+
export declare abstract class MediaQueryAttribute<T> extends Attribute<T> implements OnUpdateMediaQuery {
|
|
17
|
+
prevValue: string;
|
|
18
|
+
originalValue: string;
|
|
19
|
+
private matchers;
|
|
20
|
+
private cachedAttributes;
|
|
21
|
+
listener: (event: MediaQueryList | MediaQueryListEvent) => void;
|
|
22
|
+
OnInit(): void;
|
|
23
|
+
OnDestroy(): void;
|
|
24
|
+
abstract OnEnterMediaQuery(tuple: [MediaEvent, Attr]): void;
|
|
25
|
+
abstract OnExitMediaQuery(tuple: [MediaEvent, string]): void;
|
|
26
|
+
}
|
|
27
|
+
export {};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MediaQueryAttribute = exports.createFiltersFromSelector = exports.Breakpoints = exports.MediaMatchers = void 0;
|
|
4
|
+
const attribute_1 = require("./attribute");
|
|
5
|
+
/**
|
|
6
|
+
* Media query Attribute
|
|
7
|
+
* for performance reasons it is key value pair
|
|
8
|
+
*/
|
|
9
|
+
exports.MediaMatchers = new Map([
|
|
10
|
+
['screen and (max-width: 599px)', 'xs'],
|
|
11
|
+
['screen and (min-width: 600px) and (max-width: 959px)', 'sm'],
|
|
12
|
+
['screen and (min-width: 960px) and (max-width: 1279px)', 'md'],
|
|
13
|
+
['screen and (min-width: 1280px) and (max-width: 1919px)', 'lg'],
|
|
14
|
+
['screen and (min-width: 1920px) and (max-width: 5000px)', 'xl'],
|
|
15
|
+
['screen and (max-width: 959px)', 'lt-md'],
|
|
16
|
+
['screen and (max-width: 1279px)', 'lt-lg'],
|
|
17
|
+
['screen and (max-width: 1919px)', 'lt-xl'],
|
|
18
|
+
['screen and (min-width: 600px)', 'gt-xs'],
|
|
19
|
+
['screen and (min-width: 960px)', 'gt-sm'],
|
|
20
|
+
['screen and (min-width: 1280px)', 'gt-md'],
|
|
21
|
+
['screen and (min-width: 1920px)', 'gt-lg']
|
|
22
|
+
]);
|
|
23
|
+
exports.Breakpoints = [...exports.MediaMatchers.values()];
|
|
24
|
+
exports.createFiltersFromSelector = (selector) => [
|
|
25
|
+
...exports.Breakpoints.map(breakpoint => `${selector}.${breakpoint}`),
|
|
26
|
+
selector
|
|
27
|
+
];
|
|
28
|
+
class MediaQueryAttribute extends attribute_1.Attribute {
|
|
29
|
+
constructor() {
|
|
30
|
+
super(...arguments);
|
|
31
|
+
this.matchers = new Map();
|
|
32
|
+
this.cachedAttributes = new Map();
|
|
33
|
+
this.listener = (event) => {
|
|
34
|
+
const key = `${this.selector.toLowerCase()}.${exports.MediaMatchers.get(event.media)}`;
|
|
35
|
+
const attribute = this.cachedAttributes.get(key);
|
|
36
|
+
if (event.matches && attribute) {
|
|
37
|
+
return this.OnEnterMediaQuery([event, attribute]);
|
|
38
|
+
}
|
|
39
|
+
return this.OnExitMediaQuery([event, key]);
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
OnInit() {
|
|
43
|
+
if (this.OnEnterMediaQuery || this.OnExitMediaQuery) {
|
|
44
|
+
this.originalValue = this.value;
|
|
45
|
+
for (const query of exports.MediaMatchers.keys()) {
|
|
46
|
+
const matcher = window.matchMedia(query);
|
|
47
|
+
const attr = Object.values(this.element.attributes).find(v => v.name ===
|
|
48
|
+
`${this.selector.toLowerCase()}.${exports.MediaMatchers.get(query)}`);
|
|
49
|
+
if (attr) {
|
|
50
|
+
this.cachedAttributes.set(attr.name, attr);
|
|
51
|
+
matcher.addEventListener('change', this.listener);
|
|
52
|
+
}
|
|
53
|
+
if (attr && matcher.matches) {
|
|
54
|
+
this.listener(matcher);
|
|
55
|
+
}
|
|
56
|
+
this.matchers.set(matcher, matcher);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
OnDestroy() {
|
|
61
|
+
for (const matcher of this.matchers.values()) {
|
|
62
|
+
matcher.removeEventListener('change', this.listener);
|
|
63
|
+
}
|
|
64
|
+
this.cachedAttributes.clear();
|
|
65
|
+
this.matchers.clear();
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
exports.MediaQueryAttribute = MediaQueryAttribute;
|
|
69
|
+
//# sourceMappingURL=media-attribute.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"media-attribute.js","sourceRoot":"","sources":["../src/media-attribute.ts"],"names":[],"mappings":"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"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { CustomAttributeRegistry } from './custom-registry';
|
|
2
|
+
export declare type C<T> = new (...args: never[]) => T;
|
|
3
|
+
export interface Constructor<T> extends C<T> {
|
|
4
|
+
options: ModifierOptions;
|
|
5
|
+
}
|
|
6
|
+
export interface ModifierOptions {
|
|
7
|
+
/**
|
|
8
|
+
* Main selector of the attribute
|
|
9
|
+
*/
|
|
10
|
+
selector: string;
|
|
11
|
+
/**
|
|
12
|
+
* Define custom attribute registry
|
|
13
|
+
*/
|
|
14
|
+
registry?(this: HTMLElement): CustomAttributeRegistry;
|
|
15
|
+
/**
|
|
16
|
+
* Specify attributes to be listened
|
|
17
|
+
*/
|
|
18
|
+
observedAttributes?: string[];
|
|
19
|
+
/**
|
|
20
|
+
* Define MutationObserver to listen for parent element changes
|
|
21
|
+
* Defining property will attach observer to this.element
|
|
22
|
+
* */
|
|
23
|
+
observe?: MutationObserverInit;
|
|
24
|
+
}
|
|
25
|
+
export interface InputOptions {
|
|
26
|
+
/**
|
|
27
|
+
* If enabled will trigger OnUpdate method on the Attribute
|
|
28
|
+
* */
|
|
29
|
+
observe: true;
|
|
30
|
+
}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
package/package.json
CHANGED
package/src/attribute.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
2
|
+
import { ModifierOptions } from './types';
|
|
3
|
+
|
|
4
|
+
/* */
|
|
5
|
+
export abstract class Attribute<T = {}> {
|
|
6
|
+
public static options: ModifierOptions;
|
|
7
|
+
public element?: HTMLElement;
|
|
8
|
+
public value?: string;
|
|
9
|
+
public selector?: string;
|
|
10
|
+
public parent?: HTMLElement;
|
|
11
|
+
public observer?: MutationObserver;
|
|
12
|
+
setStyles(keys: T) {
|
|
13
|
+
return (div: HTMLElement | Element | HTMLDivElement) => {
|
|
14
|
+
for (const [key, value] of Object.entries(keys)) {
|
|
15
|
+
div['style'][key] = value;
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
OnInit(): void {
|
|
20
|
+
/* */
|
|
21
|
+
}
|
|
22
|
+
OnDestroy(): void {
|
|
23
|
+
/* */
|
|
24
|
+
}
|
|
25
|
+
OnUpdate(_oldValue: string, _newValue: string) {
|
|
26
|
+
/* */
|
|
27
|
+
}
|
|
28
|
+
OnUpdateAttribute(_name: string, _value: string) {
|
|
29
|
+
/* */
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
OnChange(_records: MutationRecord[]): void {
|
|
33
|
+
/* */
|
|
34
|
+
}
|
|
35
|
+
}
|