@dooboostore/simple-web-component 1.0.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/README.md +102 -0
- package/dist/cjs/bundle-entry.js +18 -0
- package/dist/cjs/bundle-entry.js.map +7 -0
- package/dist/cjs/decorators/attributeChanged.js +42 -0
- package/dist/cjs/decorators/attributeChanged.js.map +7 -0
- package/dist/cjs/decorators/element.js +183 -0
- package/dist/cjs/decorators/element.js.map +7 -0
- package/dist/cjs/decorators/style.js +34 -0
- package/dist/cjs/decorators/style.js.map +7 -0
- package/dist/cjs/decorators/template.js +34 -0
- package/dist/cjs/decorators/template.js.map +7 -0
- package/dist/cjs/index.js +21 -0
- package/dist/cjs/index.js.map +7 -0
- package/dist/cjs/package.json +5 -0
- package/dist/esm/bundle-entry.js +2 -0
- package/dist/esm/bundle-entry.js.map +7 -0
- package/dist/esm/decorators/attributeChanged.js +23 -0
- package/dist/esm/decorators/attributeChanged.js.map +7 -0
- package/dist/esm/decorators/element.js +164 -0
- package/dist/esm/decorators/element.js.map +7 -0
- package/dist/esm/decorators/style.js +15 -0
- package/dist/esm/decorators/style.js.map +7 -0
- package/dist/esm/decorators/template.js +15 -0
- package/dist/esm/decorators/template.js.map +7 -0
- package/dist/esm/index.js +5 -0
- package/dist/esm/index.js.map +7 -0
- package/dist/esm-bundle/dooboostore-simple-web-component.esm.js +260 -0
- package/dist/esm-bundle/dooboostore-simple-web-component.esm.js.map +7 -0
- package/dist/types/bundle-entry.d.ts +2 -0
- package/dist/types/bundle-entry.d.ts.map +1 -0
- package/dist/types/decorators/attributeChanged.d.ts +4 -0
- package/dist/types/decorators/attributeChanged.d.ts.map +1 -0
- package/dist/types/decorators/element.d.ts +11 -0
- package/dist/types/decorators/element.d.ts.map +1 -0
- package/dist/types/decorators/style.d.ts +4 -0
- package/dist/types/decorators/style.d.ts.map +1 -0
- package/dist/types/decorators/template.d.ts +4 -0
- package/dist/types/decorators/template.d.ts.map +1 -0
- package/dist/types/index.d.ts +5 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/umd-bundle/dooboostore-simple-web-component.umd.js +284 -0
- package/dist/umd-bundle/dooboostore-simple-web-component.umd.js.map +7 -0
- package/package.json +93 -0
- package/src/bundle-entry.ts +1 -0
- package/src/decorators/attributeChanged.ts +20 -0
- package/src/decorators/element.ts +201 -0
- package/src/decorators/style.ts +12 -0
- package/src/decorators/template.ts +14 -0
- package/src/index.ts +4 -0
- package/tsconfig.json +23 -0
package/README.md
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
# @dooboostore/simple-web-component
|
|
2
|
+
|
|
3
|
+
`@dooboostore/simple-web-component` is a lightweight, decorator-driven library for building Web Components. It allows you to define standard Custom Elements using classes and decorators without complex configurations, providing powerful features like Shadow DOM management, attribute observation, and seamless template/style injection.
|
|
4
|
+
|
|
5
|
+
## Key Features
|
|
6
|
+
|
|
7
|
+
- **Decorator-based**: Declarative development using `@element`, `@template`, `@style`, and `@attributeChanged`.
|
|
8
|
+
- **Standards Compliant**: Built on top of native browser Web Components (Custom Elements) technology.
|
|
9
|
+
- **Automatic Registration**: The `@element` decorator automatically registers your component with the browser using the provided `tagName`.
|
|
10
|
+
- **Built-in Element Extension**: Easily inherit and extend standard HTML tags like `ul`, `button`, or `a` using the `extends` option.
|
|
11
|
+
- **Automatic Attribute Observation**: Use the `@attributeChanged` decorator to automatically register attributes for observation and handle changes via callbacks.
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
pnpm add @dooboostore/simple-web-component
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Usage
|
|
20
|
+
|
|
21
|
+
### 1. Basic Autonomous Custom Element
|
|
22
|
+
|
|
23
|
+
This is the most common way to create an encapsulated component using Shadow DOM.
|
|
24
|
+
|
|
25
|
+
```typescript
|
|
26
|
+
import { element, template, style, attributeChanged } from '@dooboostore/simple-web-component';
|
|
27
|
+
|
|
28
|
+
@element({
|
|
29
|
+
tagName: 'my-profile',
|
|
30
|
+
useShadow: true, // Defaults to false (Light DOM)
|
|
31
|
+
observedAttributes: ['status'] // Manual registration is also possible
|
|
32
|
+
})
|
|
33
|
+
class MyProfile extends HTMLElement {
|
|
34
|
+
|
|
35
|
+
@style
|
|
36
|
+
styles() {
|
|
37
|
+
return `
|
|
38
|
+
.card { border: 1px solid #ccc; padding: 10px; }
|
|
39
|
+
.name { font-weight: bold; color: blue; }
|
|
40
|
+
`;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
@template
|
|
44
|
+
render() {
|
|
45
|
+
return `
|
|
46
|
+
<div class="card">
|
|
47
|
+
<div class="name">Hello, Visitor!</div>
|
|
48
|
+
<div id="status">Status: Pending</div>
|
|
49
|
+
</div>
|
|
50
|
+
`;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// Called automatically when the 'status' attribute changes
|
|
54
|
+
@attributeChanged('status')
|
|
55
|
+
onStatusChange(newVal: string, oldVal: string) {
|
|
56
|
+
console.log(`Status changed: ${oldVal} -> ${newVal}`);
|
|
57
|
+
this.shadowRoot.getElementById('status').innerText = `Status: ${newVal}`;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
### 2. Extending Built-in Elements (Customized Built-in Element)
|
|
63
|
+
|
|
64
|
+
Inherit properties and behaviors from existing HTML tags while adding your custom logic.
|
|
65
|
+
|
|
66
|
+
```typescript
|
|
67
|
+
import { element, template } from '@dooboostore/simple-web-component';
|
|
68
|
+
|
|
69
|
+
@element({
|
|
70
|
+
tagName: 'special-list',
|
|
71
|
+
extends: 'ul' // Specifies that this component extends the <ul> tag
|
|
72
|
+
})
|
|
73
|
+
class SpecialList extends HTMLUListElement {
|
|
74
|
+
@template
|
|
75
|
+
render() {
|
|
76
|
+
return `<li>Initial item of the extended list</li>`;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## API Reference
|
|
82
|
+
|
|
83
|
+
### Decorators
|
|
84
|
+
|
|
85
|
+
| Decorator | Target | Description |
|
|
86
|
+
| :--- | :--- | :--- |
|
|
87
|
+
| `@element(config)` | Class | Configures the tag name, inheritance, Shadow DOM usage, and registers it to the browser. |
|
|
88
|
+
| `@template` | Method | Identifies the method that returns the component's HTML structure. |
|
|
89
|
+
| `@style` | Method | Identifies the method that returns the component's CSS styles. |
|
|
90
|
+
| `@attributeChanged(name)`| Method | Defines an attribute to monitor and the handler to execute when it changes. |
|
|
91
|
+
|
|
92
|
+
### ElementConfig Options
|
|
93
|
+
|
|
94
|
+
- `tagName`: (Required) The name for the custom element (e.g., `my-button`).
|
|
95
|
+
- `useShadow`: (Optional) Whether to use Shadow DOM (default: `false`).
|
|
96
|
+
- `extends`: (Optional) The name of the built-in tag to extend (e.g., `ul`, `button`, `a`).
|
|
97
|
+
- `observedAttributes`: (Optional) An array of attributes to monitor manually. (Automatically populated if `@attributeChanged` is used).
|
|
98
|
+
- `customElementRegistry`: (Optional) A specific registry to use for registration (defaults to global `customElements`).
|
|
99
|
+
|
|
100
|
+
## License
|
|
101
|
+
|
|
102
|
+
MIT
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __copyProps = (to, from, except, desc) => {
|
|
6
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
7
|
+
for (let key of __getOwnPropNames(from))
|
|
8
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
9
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
10
|
+
}
|
|
11
|
+
return to;
|
|
12
|
+
};
|
|
13
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
var bundle_entry_exports = {};
|
|
16
|
+
module.exports = __toCommonJS(bundle_entry_exports);
|
|
17
|
+
__reExport(bundle_entry_exports, require("./index"), module.exports);
|
|
18
|
+
//# sourceMappingURL=bundle-entry.js.map
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var attributeChanged_exports = {};
|
|
19
|
+
__export(attributeChanged_exports, {
|
|
20
|
+
ATTRIBUTE_CHANGED_METADATA_KEY: () => ATTRIBUTE_CHANGED_METADATA_KEY,
|
|
21
|
+
attributeChanged: () => attributeChanged,
|
|
22
|
+
getAttributeChangedMap: () => getAttributeChangedMap
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(attributeChanged_exports);
|
|
25
|
+
var import_ReflectUtils = require("@dooboostore/core/reflect/ReflectUtils");
|
|
26
|
+
const ATTRIBUTE_CHANGED_METADATA_KEY = Symbol("simple-web-component:attribute-changed");
|
|
27
|
+
const attributeChanged = (attributeName) => {
|
|
28
|
+
return (target, propertyKey, descriptor) => {
|
|
29
|
+
const constructor = target.constructor;
|
|
30
|
+
let meta = import_ReflectUtils.ReflectUtils.getMetadata(ATTRIBUTE_CHANGED_METADATA_KEY, constructor);
|
|
31
|
+
if (!meta) {
|
|
32
|
+
meta = /* @__PURE__ */ new Map();
|
|
33
|
+
import_ReflectUtils.ReflectUtils.defineMetadata(ATTRIBUTE_CHANGED_METADATA_KEY, meta, constructor);
|
|
34
|
+
}
|
|
35
|
+
meta.set(attributeName, propertyKey);
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
const getAttributeChangedMap = (target) => {
|
|
39
|
+
const constructor = target instanceof Function ? target : target.constructor;
|
|
40
|
+
return import_ReflectUtils.ReflectUtils.getMetadata(ATTRIBUTE_CHANGED_METADATA_KEY, constructor);
|
|
41
|
+
};
|
|
42
|
+
//# sourceMappingURL=attributeChanged.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/decorators/attributeChanged.ts"],
|
|
4
|
+
"sourcesContent": ["import { ReflectUtils } from '@dooboostore/core/reflect/ReflectUtils';\n\nexport const ATTRIBUTE_CHANGED_METADATA_KEY = Symbol('simple-web-component:attribute-changed');\n\nexport const attributeChanged = (attributeName: string): MethodDecorator => {\n return (target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor) => {\n const constructor = target.constructor;\n let meta = ReflectUtils.getMetadata<Map<string, string | symbol>>(ATTRIBUTE_CHANGED_METADATA_KEY, constructor);\n if (!meta) {\n meta = new Map<string, string | symbol>();\n ReflectUtils.defineMetadata(ATTRIBUTE_CHANGED_METADATA_KEY, meta, constructor);\n }\n meta.set(attributeName, propertyKey);\n };\n};\n\nexport const getAttributeChangedMap = (target: any): Map<string, string | symbol> | undefined => {\n const constructor = target instanceof Function ? target : target.constructor;\n return ReflectUtils.getMetadata(ATTRIBUTE_CHANGED_METADATA_KEY, constructor);\n};\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,0BAA6B;AAEtB,MAAM,iCAAiC,OAAO,wCAAwC;AAEtF,MAAM,mBAAmB,CAAC,kBAA2C;AAC1E,SAAO,CAAC,QAAgB,aAA8B,eAAmC;AACvF,UAAM,cAAc,OAAO;AAC3B,QAAI,OAAO,iCAAa,YAA0C,gCAAgC,WAAW;AAC7G,QAAI,CAAC,MAAM;AACT,aAAO,oBAAI,IAA6B;AACxC,uCAAa,eAAe,gCAAgC,MAAM,WAAW;AAAA,IAC/E;AACA,SAAK,IAAI,eAAe,WAAW;AAAA,EACrC;AACF;AAEO,MAAM,yBAAyB,CAAC,WAA0D;AAC/F,QAAM,cAAc,kBAAkB,WAAW,SAAS,OAAO;AACjE,SAAO,iCAAa,YAAY,gCAAgC,WAAW;AAC7E;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var element_exports = {};
|
|
19
|
+
__export(element_exports, {
|
|
20
|
+
ELEMENT_CONFIG_KEY: () => ELEMENT_CONFIG_KEY,
|
|
21
|
+
element: () => element,
|
|
22
|
+
getElementConfig: () => getElementConfig
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(element_exports);
|
|
25
|
+
var import_ReflectUtils = require("@dooboostore/core/reflect/ReflectUtils");
|
|
26
|
+
var import_attributeChanged = require("./attributeChanged");
|
|
27
|
+
var import_template = require("./template");
|
|
28
|
+
var import_style = require("./style");
|
|
29
|
+
const ELEMENT_CONFIG_KEY = Symbol("simple-web-component:element-config");
|
|
30
|
+
const BUILT_IN_TAG_MAP = /* @__PURE__ */ new Map();
|
|
31
|
+
const registerTag = (className, tagName) => {
|
|
32
|
+
if (typeof globalThis !== "undefined" && globalThis[className]) {
|
|
33
|
+
BUILT_IN_TAG_MAP.set(globalThis[className], tagName);
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
[
|
|
37
|
+
["HTMLAnchorElement", "a"],
|
|
38
|
+
["HTMLAreaElement", "area"],
|
|
39
|
+
["HTMLAudioElement", "audio"],
|
|
40
|
+
["HTMLBaseElement", "base"],
|
|
41
|
+
["HTMLButtonElement", "button"],
|
|
42
|
+
["HTMLCanvasElement", "canvas"],
|
|
43
|
+
["HTMLDataElement", "data"],
|
|
44
|
+
["HTMLDataListElement", "datalist"],
|
|
45
|
+
["HTMLDetailsElement", "details"],
|
|
46
|
+
["HTMLDialogElement", "dialog"],
|
|
47
|
+
["HTMLDivElement", "div"],
|
|
48
|
+
["HTMLDListElement", "dl"],
|
|
49
|
+
["HTMLEmbedElement", "embed"],
|
|
50
|
+
["HTMLFieldSetElement", "fieldset"],
|
|
51
|
+
["HTMLFormElement", "form"],
|
|
52
|
+
["HTMLHRElement", "hr"],
|
|
53
|
+
["HTMLIFrameElement", "iframe"],
|
|
54
|
+
["HTMLImageElement", "img"],
|
|
55
|
+
["HTMLInputElement", "input"],
|
|
56
|
+
["HTMLLabelElement", "label"],
|
|
57
|
+
["HTMLLegendElement", "legend"],
|
|
58
|
+
["HTMLLIElement", "li"],
|
|
59
|
+
["HTMLLinkElement", "link"],
|
|
60
|
+
["HTMLMapElement", "map"],
|
|
61
|
+
["HTMLMetaElement", "meta"],
|
|
62
|
+
["HTMLMeterElement", "meter"],
|
|
63
|
+
["HTMLModElement", "del"],
|
|
64
|
+
["HTMLObjectElement", "object"],
|
|
65
|
+
["HTMLOListElement", "ol"],
|
|
66
|
+
["HTMLOptGroupElement", "optgroup"],
|
|
67
|
+
["HTMLOptionElement", "option"],
|
|
68
|
+
["HTMLOutputElement", "output"],
|
|
69
|
+
["HTMLParagraphElement", "p"],
|
|
70
|
+
["HTMLParamElement", "param"],
|
|
71
|
+
["HTMLPictureElement", "picture"],
|
|
72
|
+
["HTMLPreElement", "pre"],
|
|
73
|
+
["HTMLProgressElement", "progress"],
|
|
74
|
+
["HTMLQuoteElement", "blockquote"],
|
|
75
|
+
["HTMLScriptElement", "script"],
|
|
76
|
+
["HTMLSelectElement", "select"],
|
|
77
|
+
["HTMLSlotElement", "slot"],
|
|
78
|
+
["HTMLSourceElement", "source"],
|
|
79
|
+
["HTMLSpanElement", "span"],
|
|
80
|
+
["HTMLStyleElement", "style"],
|
|
81
|
+
["HTMLTableElement", "table"],
|
|
82
|
+
["HTMLTableSectionElement", "tbody"],
|
|
83
|
+
["HTMLTableCellElement", "td"],
|
|
84
|
+
["HTMLTemplateElement", "template"],
|
|
85
|
+
["HTMLTextAreaElement", "textarea"],
|
|
86
|
+
["HTMLTimeElement", "time"],
|
|
87
|
+
["HTMLTitleElement", "title"],
|
|
88
|
+
["HTMLTableRowElement", "tr"],
|
|
89
|
+
["HTMLTrackElement", "track"],
|
|
90
|
+
["HTMLUListElement", "ul"],
|
|
91
|
+
["HTMLVideoElement", "video"],
|
|
92
|
+
["HTMLHeadingElement", "h1"]
|
|
93
|
+
].forEach(([cls, tag]) => registerTag(cls, tag));
|
|
94
|
+
const element = (inConfig) => (constructor) => {
|
|
95
|
+
const config = typeof inConfig === "string" ? { tagName: inConfig } : inConfig;
|
|
96
|
+
let extendsTagName = config.extends;
|
|
97
|
+
if (!extendsTagName) {
|
|
98
|
+
let proto = Object.getPrototypeOf(constructor);
|
|
99
|
+
while (proto && proto !== HTMLElement && proto !== Function.prototype) {
|
|
100
|
+
extendsTagName = BUILT_IN_TAG_MAP.get(proto);
|
|
101
|
+
if (extendsTagName)
|
|
102
|
+
break;
|
|
103
|
+
proto = Object.getPrototypeOf(proto);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
const attributeChangedMap = (0, import_attributeChanged.getAttributeChangedMap)(constructor);
|
|
107
|
+
const observedFromDecorators = attributeChangedMap ? Array.from(attributeChangedMap.keys()) : [];
|
|
108
|
+
const mergedObservedAttributes = [.../* @__PURE__ */ new Set([...config.observedAttributes ?? [], ...observedFromDecorators])];
|
|
109
|
+
const NewClass = class extends constructor {
|
|
110
|
+
static get observedAttributes() {
|
|
111
|
+
return mergedObservedAttributes;
|
|
112
|
+
}
|
|
113
|
+
constructor(...args) {
|
|
114
|
+
super(...args);
|
|
115
|
+
if (config.useShadow === true && !this.shadowRoot) {
|
|
116
|
+
this.attachShadow({ mode: "open" });
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
disconnectedCallback() {
|
|
120
|
+
if (super.disconnectedCallback) {
|
|
121
|
+
super.disconnectedCallback();
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
connectedMoveCallback() {
|
|
125
|
+
if (super.connectedMoveCallback) {
|
|
126
|
+
super.connectedMoveCallback();
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
adoptedCallback() {
|
|
130
|
+
if (super.adoptedCallback) {
|
|
131
|
+
super.adoptedCallback();
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
async connectedCallback() {
|
|
135
|
+
if (super.connectedCallback) {
|
|
136
|
+
await super.connectedCallback();
|
|
137
|
+
}
|
|
138
|
+
const templateMethod = (0, import_template.getTemplateMethod)(this);
|
|
139
|
+
const styleMethod = (0, import_style.getStyleMethod)(this);
|
|
140
|
+
const template = templateMethod ? await this[templateMethod]() : void 0;
|
|
141
|
+
const style = styleMethod ? await this[styleMethod]() : void 0;
|
|
142
|
+
if (!this.shadowRoot && template === void 0 && style === void 0) {
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
let content = "";
|
|
146
|
+
if (style !== void 0 && style.trim().length > 0) {
|
|
147
|
+
content += `<style>${style}</style>`;
|
|
148
|
+
}
|
|
149
|
+
if (template !== void 0) {
|
|
150
|
+
content += template;
|
|
151
|
+
} else if (!this.shadowRoot) {
|
|
152
|
+
content += this.innerHTML;
|
|
153
|
+
}
|
|
154
|
+
if (this.shadowRoot) {
|
|
155
|
+
this.shadowRoot.innerHTML = content;
|
|
156
|
+
} else {
|
|
157
|
+
this.innerHTML = content;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
// 4. Handle attribute changes and route to decorated methods
|
|
161
|
+
attributeChangedCallback(name, oldValue, newValue) {
|
|
162
|
+
if (super.attributeChangedCallback) {
|
|
163
|
+
super.attributeChangedCallback(name, oldValue, newValue);
|
|
164
|
+
}
|
|
165
|
+
const methodKey = attributeChangedMap?.get(name);
|
|
166
|
+
if (methodKey && typeof this[methodKey] === "function") {
|
|
167
|
+
this[methodKey](newValue, oldValue);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
const registry = config.customElementRegistry || (typeof customElements !== "undefined" ? customElements : void 0);
|
|
172
|
+
if (registry && !registry.get(config.tagName)) {
|
|
173
|
+
const options = extendsTagName ? { extends: extendsTagName } : void 0;
|
|
174
|
+
registry.define(config.tagName, NewClass, options);
|
|
175
|
+
}
|
|
176
|
+
import_ReflectUtils.ReflectUtils.defineMetadata(ELEMENT_CONFIG_KEY, config, NewClass);
|
|
177
|
+
return NewClass;
|
|
178
|
+
};
|
|
179
|
+
const getElementConfig = (target) => {
|
|
180
|
+
const constructor = target instanceof Function ? target : target.constructor;
|
|
181
|
+
return import_ReflectUtils.ReflectUtils.getMetadata(ELEMENT_CONFIG_KEY, constructor);
|
|
182
|
+
};
|
|
183
|
+
//# sourceMappingURL=element.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/decorators/element.ts"],
|
|
4
|
+
"sourcesContent": ["import { ReflectUtils } from '@dooboostore/core/reflect/ReflectUtils';\nimport { getAttributeChangedMap } from './attributeChanged';\nimport { getTemplateMethod } from './template';\nimport { getStyleMethod } from './style';\n\nexport interface ElementConfig {\n tagName: string;\n useShadow?: boolean;\n extends?: string;\n observedAttributes?: string[];\n customElementRegistry?: CustomElementRegistry;\n}\n\nexport const ELEMENT_CONFIG_KEY = Symbol('simple-web-component:element-config');\n\nconst BUILT_IN_TAG_MAP = new Map<any, string>();\n\nconst registerTag = (className: string, tagName: string) => {\n if (typeof globalThis !== 'undefined' && (globalThis as any)[className]) {\n BUILT_IN_TAG_MAP.set((globalThis as any)[className], tagName);\n }\n};\n\n// Register comprehensive list of supported tags for automatic extends inference\n[\n ['HTMLAnchorElement', 'a'],\n ['HTMLAreaElement', 'area'],\n ['HTMLAudioElement', 'audio'],\n ['HTMLBaseElement', 'base'],\n ['HTMLButtonElement', 'button'],\n ['HTMLCanvasElement', 'canvas'],\n ['HTMLDataElement', 'data'],\n ['HTMLDataListElement', 'datalist'],\n ['HTMLDetailsElement', 'details'],\n ['HTMLDialogElement', 'dialog'],\n ['HTMLDivElement', 'div'],\n ['HTMLDListElement', 'dl'],\n ['HTMLEmbedElement', 'embed'],\n ['HTMLFieldSetElement', 'fieldset'],\n ['HTMLFormElement', 'form'],\n ['HTMLHRElement', 'hr'],\n ['HTMLIFrameElement', 'iframe'],\n ['HTMLImageElement', 'img'],\n ['HTMLInputElement', 'input'],\n ['HTMLLabelElement', 'label'],\n ['HTMLLegendElement', 'legend'],\n ['HTMLLIElement', 'li'],\n ['HTMLLinkElement', 'link'],\n ['HTMLMapElement', 'map'],\n ['HTMLMetaElement', 'meta'],\n ['HTMLMeterElement', 'meter'],\n ['HTMLModElement', 'del'],\n ['HTMLObjectElement', 'object'],\n ['HTMLOListElement', 'ol'],\n ['HTMLOptGroupElement', 'optgroup'],\n ['HTMLOptionElement', 'option'],\n ['HTMLOutputElement', 'output'],\n ['HTMLParagraphElement', 'p'],\n ['HTMLParamElement', 'param'],\n ['HTMLPictureElement', 'picture'],\n ['HTMLPreElement', 'pre'],\n ['HTMLProgressElement', 'progress'],\n ['HTMLQuoteElement', 'blockquote'],\n ['HTMLScriptElement', 'script'],\n ['HTMLSelectElement', 'select'],\n ['HTMLSlotElement', 'slot'],\n ['HTMLSourceElement', 'source'],\n ['HTMLSpanElement', 'span'],\n ['HTMLStyleElement', 'style'],\n ['HTMLTableElement', 'table'],\n ['HTMLTableSectionElement', 'tbody'],\n ['HTMLTableCellElement', 'td'],\n ['HTMLTemplateElement', 'template'],\n ['HTMLTextAreaElement', 'textarea'],\n ['HTMLTimeElement', 'time'],\n ['HTMLTitleElement', 'title'],\n ['HTMLTableRowElement', 'tr'],\n ['HTMLTrackElement', 'track'],\n ['HTMLUListElement', 'ul'],\n ['HTMLVideoElement', 'video'],\n ['HTMLHeadingElement', 'h1']\n].forEach(([cls, tag]) => registerTag(cls, tag));\n\nexport const element =\n (inConfig: ElementConfig | string): ClassDecorator =>\n (constructor: any) => {\n const config: ElementConfig = typeof inConfig === 'string' ? { tagName: inConfig } : inConfig;\n\n // 1. Automatically derive extendsTagName from prototype chain if not provided\n let extendsTagName = config.extends;\n if (!extendsTagName) {\n let proto = Object.getPrototypeOf(constructor);\n while (proto && proto !== HTMLElement && proto !== Function.prototype) {\n extendsTagName = BUILT_IN_TAG_MAP.get(proto);\n if (extendsTagName) break;\n proto = Object.getPrototypeOf(proto);\n }\n }\n\n // 2. Automatically collect observed attributes from @attributeChanged decorators\n const attributeChangedMap = getAttributeChangedMap(constructor);\n const observedFromDecorators = attributeChangedMap ? Array.from(attributeChangedMap.keys()) : [];\n const mergedObservedAttributes = [...new Set([...(config.observedAttributes ?? []), ...observedFromDecorators])];\n\n // 3. Create a new anonymous class that extends the original constructor\n const NewClass = class extends (constructor as any) {\n static get observedAttributes() {\n return mergedObservedAttributes;\n }\n\n constructor(...args: any[]) {\n super(...args);\n if (config.useShadow === true && !this.shadowRoot) {\n this.attachShadow({ mode: 'open' });\n }\n }\n\n disconnectedCallback() {\n if (super.disconnectedCallback) {\n super.disconnectedCallback();\n }\n }\n\n connectedMoveCallback() {\n if (super.connectedMoveCallback) {\n super.connectedMoveCallback();\n }\n }\n\n adoptedCallback() {\n if (super.adoptedCallback) {\n super.adoptedCallback();\n }\n }\n\n async connectedCallback() {\n if (super.connectedCallback) {\n await super.connectedCallback();\n }\n\n const templateMethod = getTemplateMethod(this);\n const styleMethod = getStyleMethod(this);\n\n const template = templateMethod ? await (this as any)[templateMethod]() : undefined;\n const style = styleMethod ? await (this as any)[styleMethod]() : undefined;\n\n // If not using shadow DOM and no decorators are present, do nothing\n if (!this.shadowRoot && template === undefined && style === undefined) {\n return;\n }\n\n let content = '';\n if (style !== undefined && style.trim().length > 0) {\n content += `<style>${style}</style>`;\n }\n\n if (template !== undefined) {\n content += template;\n } else if (!this.shadowRoot) {\n content += this.innerHTML;\n }\n\n if (this.shadowRoot) {\n this.shadowRoot.innerHTML = content;\n } else {\n this.innerHTML = content;\n }\n }\n\n // 4. Handle attribute changes and route to decorated methods\n attributeChangedCallback(name: string, oldValue: string | null, newValue: string | null) {\n // Call the original callback if it exists\n if (super.attributeChangedCallback) {\n super.attributeChangedCallback(name, oldValue, newValue);\n }\n\n // Call the method associated with @attributeChanged\n const methodKey = attributeChangedMap?.get(name);\n if (methodKey && typeof (this as any)[methodKey] === 'function') {\n (this as any)[methodKey](newValue, oldValue);\n }\n }\n };\n\n // 5. Register Custom Element using specified or default registry\n const registry = config.customElementRegistry || (typeof customElements !== 'undefined' ? customElements : undefined);\n if (registry && !registry.get(config.tagName)) {\n const options = extendsTagName ? { extends: extendsTagName } : undefined;\n registry.define(config.tagName, NewClass as any, options);\n }\n\n // 6. Save metadata\n ReflectUtils.defineMetadata(ELEMENT_CONFIG_KEY, config, NewClass);\n\n return NewClass as any;\n };\n\nexport const getElementConfig = (target: any): ElementConfig | undefined => {\n const constructor = target instanceof Function ? target : target.constructor;\n return ReflectUtils.getMetadata(ELEMENT_CONFIG_KEY, constructor);\n};\n"],
|
|
5
|
+
"mappings": "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",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var style_exports = {};
|
|
19
|
+
__export(style_exports, {
|
|
20
|
+
STYLE_METHOD_KEY: () => STYLE_METHOD_KEY,
|
|
21
|
+
getStyleMethod: () => getStyleMethod,
|
|
22
|
+
style: () => style
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(style_exports);
|
|
25
|
+
var import_ReflectUtils = require("@dooboostore/core/reflect/ReflectUtils");
|
|
26
|
+
const STYLE_METHOD_KEY = Symbol("simple-web-component:style-method");
|
|
27
|
+
const style = (target, propertyKey, descriptor) => {
|
|
28
|
+
import_ReflectUtils.ReflectUtils.defineMetadata(STYLE_METHOD_KEY, propertyKey, target.constructor);
|
|
29
|
+
};
|
|
30
|
+
const getStyleMethod = (target) => {
|
|
31
|
+
const constructor = target instanceof Function ? target : target.constructor;
|
|
32
|
+
return import_ReflectUtils.ReflectUtils.getMetadata(STYLE_METHOD_KEY, constructor);
|
|
33
|
+
};
|
|
34
|
+
//# sourceMappingURL=style.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/decorators/style.ts"],
|
|
4
|
+
"sourcesContent": ["import { ReflectUtils } from '@dooboostore/core/reflect/ReflectUtils';\n\nexport const STYLE_METHOD_KEY = Symbol('simple-web-component:style-method');\n\nexport const style: MethodDecorator = (target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor) => {\n ReflectUtils.defineMetadata(STYLE_METHOD_KEY, propertyKey, target.constructor);\n};\n\nexport const getStyleMethod = (target: any): string | symbol | undefined => {\n const constructor = target instanceof Function ? target : target.constructor;\n return ReflectUtils.getMetadata(STYLE_METHOD_KEY, constructor);\n};\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,0BAA6B;AAEtB,MAAM,mBAAmB,OAAO,mCAAmC;AAEnE,MAAM,QAAyB,CAAC,QAAgB,aAA8B,eAAmC;AACtH,mCAAa,eAAe,kBAAkB,aAAa,OAAO,WAAW;AAC/E;AAEO,MAAM,iBAAiB,CAAC,WAA6C;AAC1E,QAAM,cAAc,kBAAkB,WAAW,SAAS,OAAO;AACjE,SAAO,iCAAa,YAAY,kBAAkB,WAAW;AAC/D;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var template_exports = {};
|
|
19
|
+
__export(template_exports, {
|
|
20
|
+
TEMPLATE_METHOD_KEY: () => TEMPLATE_METHOD_KEY,
|
|
21
|
+
getTemplateMethod: () => getTemplateMethod,
|
|
22
|
+
template: () => template
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(template_exports);
|
|
25
|
+
var import_ReflectUtils = require("@dooboostore/core/reflect/ReflectUtils");
|
|
26
|
+
const TEMPLATE_METHOD_KEY = Symbol("simple-web-component:template-method");
|
|
27
|
+
const template = (target, propertyKey, descriptor) => {
|
|
28
|
+
import_ReflectUtils.ReflectUtils.defineMetadata(TEMPLATE_METHOD_KEY, propertyKey, target.constructor);
|
|
29
|
+
};
|
|
30
|
+
const getTemplateMethod = (target) => {
|
|
31
|
+
const constructor = target instanceof Function ? target : target.constructor;
|
|
32
|
+
return import_ReflectUtils.ReflectUtils.getMetadata(TEMPLATE_METHOD_KEY, constructor);
|
|
33
|
+
};
|
|
34
|
+
//# sourceMappingURL=template.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/decorators/template.ts"],
|
|
4
|
+
"sourcesContent": ["import { ReflectUtils } from '@dooboostore/core/reflect/ReflectUtils';\n\nexport const TEMPLATE_METHOD_KEY = Symbol('simple-web-component:template-method');\n\nexport const template: MethodDecorator = (target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor) => {\n // console.log('setTemplateMethod target.constructor', target.constructor)\n ReflectUtils.defineMetadata(TEMPLATE_METHOD_KEY, propertyKey, target.constructor);\n};\n\nexport const getTemplateMethod = (target: any): string | symbol | undefined => {\n const constructor = target instanceof Function ? target : target.constructor;\n // console.log('getTemplateMethod constructor', constructor)\n return ReflectUtils.getMetadata(TEMPLATE_METHOD_KEY, constructor);\n};\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,0BAA6B;AAEtB,MAAM,sBAAsB,OAAO,sCAAsC;AAEzE,MAAM,WAA4B,CAAC,QAAgB,aAA8B,eAAmC;AAEzH,mCAAa,eAAe,qBAAqB,aAAa,OAAO,WAAW;AAClF;AAEO,MAAM,oBAAoB,CAAC,WAA6C;AAC7E,QAAM,cAAc,kBAAkB,WAAW,SAAS,OAAO;AAEjE,SAAO,iCAAa,YAAY,qBAAqB,WAAW;AAClE;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __copyProps = (to, from, except, desc) => {
|
|
6
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
7
|
+
for (let key of __getOwnPropNames(from))
|
|
8
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
9
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
10
|
+
}
|
|
11
|
+
return to;
|
|
12
|
+
};
|
|
13
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
var src_exports = {};
|
|
16
|
+
module.exports = __toCommonJS(src_exports);
|
|
17
|
+
__reExport(src_exports, require("./decorators/element"), module.exports);
|
|
18
|
+
__reExport(src_exports, require("./decorators/template"), module.exports);
|
|
19
|
+
__reExport(src_exports, require("./decorators/style"), module.exports);
|
|
20
|
+
__reExport(src_exports, require("./decorators/attributeChanged"), module.exports);
|
|
21
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/index.ts"],
|
|
4
|
+
"sourcesContent": ["export * from './decorators/element';\nexport * from './decorators/template';\nexport * from './decorators/style';\nexport * from './decorators/attributeChanged';"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;AAAA;AAAA;AAAA,wBAAc,iCAAd;AACA,wBAAc,kCADd;AAEA,wBAAc,+BAFd;AAGA,wBAAc,0CAHd;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { ReflectUtils } from "@dooboostore/core/reflect/ReflectUtils";
|
|
2
|
+
const ATTRIBUTE_CHANGED_METADATA_KEY = Symbol("simple-web-component:attribute-changed");
|
|
3
|
+
const attributeChanged = (attributeName) => {
|
|
4
|
+
return (target, propertyKey, descriptor) => {
|
|
5
|
+
const constructor = target.constructor;
|
|
6
|
+
let meta = ReflectUtils.getMetadata(ATTRIBUTE_CHANGED_METADATA_KEY, constructor);
|
|
7
|
+
if (!meta) {
|
|
8
|
+
meta = /* @__PURE__ */ new Map();
|
|
9
|
+
ReflectUtils.defineMetadata(ATTRIBUTE_CHANGED_METADATA_KEY, meta, constructor);
|
|
10
|
+
}
|
|
11
|
+
meta.set(attributeName, propertyKey);
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
const getAttributeChangedMap = (target) => {
|
|
15
|
+
const constructor = target instanceof Function ? target : target.constructor;
|
|
16
|
+
return ReflectUtils.getMetadata(ATTRIBUTE_CHANGED_METADATA_KEY, constructor);
|
|
17
|
+
};
|
|
18
|
+
export {
|
|
19
|
+
ATTRIBUTE_CHANGED_METADATA_KEY,
|
|
20
|
+
attributeChanged,
|
|
21
|
+
getAttributeChangedMap
|
|
22
|
+
};
|
|
23
|
+
//# sourceMappingURL=attributeChanged.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/decorators/attributeChanged.ts"],
|
|
4
|
+
"sourcesContent": ["import { ReflectUtils } from '@dooboostore/core/reflect/ReflectUtils';\n\nexport const ATTRIBUTE_CHANGED_METADATA_KEY = Symbol('simple-web-component:attribute-changed');\n\nexport const attributeChanged = (attributeName: string): MethodDecorator => {\n return (target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor) => {\n const constructor = target.constructor;\n let meta = ReflectUtils.getMetadata<Map<string, string | symbol>>(ATTRIBUTE_CHANGED_METADATA_KEY, constructor);\n if (!meta) {\n meta = new Map<string, string | symbol>();\n ReflectUtils.defineMetadata(ATTRIBUTE_CHANGED_METADATA_KEY, meta, constructor);\n }\n meta.set(attributeName, propertyKey);\n };\n};\n\nexport const getAttributeChangedMap = (target: any): Map<string, string | symbol> | undefined => {\n const constructor = target instanceof Function ? target : target.constructor;\n return ReflectUtils.getMetadata(ATTRIBUTE_CHANGED_METADATA_KEY, constructor);\n};\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,oBAAoB;AAEtB,MAAM,iCAAiC,OAAO,wCAAwC;AAEtF,MAAM,mBAAmB,CAAC,kBAA2C;AAC1E,SAAO,CAAC,QAAgB,aAA8B,eAAmC;AACvF,UAAM,cAAc,OAAO;AAC3B,QAAI,OAAO,aAAa,YAA0C,gCAAgC,WAAW;AAC7G,QAAI,CAAC,MAAM;AACT,aAAO,oBAAI,IAA6B;AACxC,mBAAa,eAAe,gCAAgC,MAAM,WAAW;AAAA,IAC/E;AACA,SAAK,IAAI,eAAe,WAAW;AAAA,EACrC;AACF;AAEO,MAAM,yBAAyB,CAAC,WAA0D;AAC/F,QAAM,cAAc,kBAAkB,WAAW,SAAS,OAAO;AACjE,SAAO,aAAa,YAAY,gCAAgC,WAAW;AAC7E;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|