custom-elements-ts 0.0.17 → 0.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.
Files changed (82) hide show
  1. package/.eslintrc.json +47 -0
  2. package/.github/workflows/ci.yml +49 -0
  3. package/.prettierrc +7 -0
  4. package/LICENSE +20 -0
  5. package/README.md +279 -37
  6. package/assets/readme-header.png +0 -0
  7. package/assets/social-preview.jpg +0 -0
  8. package/demos/counter/counter.element.html +1 -0
  9. package/demos/counter/counter.element.scss +234 -0
  10. package/demos/counter/counter.element.ts +68 -0
  11. package/demos/counter/index.html +205 -0
  12. package/demos/counter/index.ts +1 -0
  13. package/demos/site/code-example/code-example.element.scss +168 -0
  14. package/demos/site/code-example/code-example.element.ts +88 -0
  15. package/demos/site/event-log/event-log.element.scss +179 -0
  16. package/demos/site/event-log/event-log.element.ts +123 -0
  17. package/demos/site/favicon.svg +14 -0
  18. package/demos/site/index.html +368 -0
  19. package/demos/site/index.ts +19 -0
  20. package/demos/site/llms.txt +53 -0
  21. package/demos/site/message/message.element.scss +75 -0
  22. package/demos/site/message/message.element.ts +76 -0
  23. package/demos/site/og-image.png +0 -0
  24. package/demos/site/scroll-restoration.ts +28 -0
  25. package/demos/site/source-toggle/source-toggle.ts +88 -0
  26. package/demos/site/source-viewer/source-viewer.element.scss +292 -0
  27. package/demos/site/source-viewer/source-viewer.element.ts +138 -0
  28. package/demos/site/source-viewer/sources.generated.ts +11 -0
  29. package/demos/site/styles/site.css +1135 -0
  30. package/demos/site/styles/tokens.css +56 -0
  31. package/demos/site/toast/toast.element.scss +110 -0
  32. package/demos/site/toast/toast.element.ts +63 -0
  33. package/demos/todo-dashboard/index.html +141 -0
  34. package/demos/todo-dashboard/index.ts +4 -0
  35. package/demos/todo-dashboard/todo-dashboard.element.scss +1150 -0
  36. package/demos/todo-dashboard/todo-dashboard.element.ts +333 -0
  37. package/demos/todo-dashboard/todo-filters.element.ts +54 -0
  38. package/demos/todo-dashboard/todo-item.element.ts +127 -0
  39. package/demos/todo-dashboard/todo-stats.element.ts +189 -0
  40. package/package.json +73 -24
  41. package/src/custom-element.ts +206 -0
  42. package/src/index.ts +8 -0
  43. package/src/listen.ts +70 -0
  44. package/src/prop.ts +92 -0
  45. package/src/signal.ts +66 -0
  46. package/src/state.ts +141 -0
  47. package/src/template-runtime.ts +783 -0
  48. package/src/toggle.ts +66 -0
  49. package/src/tsconfig.json +24 -0
  50. package/src/util.ts +33 -0
  51. package/src/watch.ts +14 -0
  52. package/tests/basic.spec.ts +70 -0
  53. package/tests/custom-element.spec.ts +77 -0
  54. package/tests/dispatch.spec.ts +52 -0
  55. package/tests/init.spec.ts +94 -0
  56. package/tests/listen.spec.ts +118 -0
  57. package/tests/map-shallow-state.spec.ts +184 -0
  58. package/tests/prop.spec.ts +118 -0
  59. package/tests/signal.spec.ts +117 -0
  60. package/tests/templating-runtime.spec.ts +575 -0
  61. package/tests/toggle.spec.ts +92 -0
  62. package/tests/watch.spec.ts +183 -0
  63. package/tools/build.js +128 -0
  64. package/tools/bundle.js +167 -0
  65. package/tools/generate-sources.js +76 -0
  66. package/tools/rollup-config.js +70 -0
  67. package/tools/start.js +194 -0
  68. package/tsconfig.json +38 -0
  69. package/vite.config.mts +30 -0
  70. package/bundles/custom-elements-ts.umd.js +0 -359
  71. package/bundles/custom-elements-ts.umd.js.map +0 -1
  72. package/esm2015/custom-elements-ts.js +0 -283
  73. package/esm2015/custom-elements-ts.js.map +0 -1
  74. package/esm5/custom-element.d.ts +0 -12
  75. package/esm5/custom-elements-ts.js +0 -344
  76. package/esm5/custom-elements-ts.js.map +0 -1
  77. package/esm5/index.d.ts +0 -5
  78. package/esm5/listen.d.ts +0 -17
  79. package/esm5/prop.d.ts +0 -2
  80. package/esm5/toggle.d.ts +0 -1
  81. package/esm5/util.d.ts +0 -4
  82. package/esm5/watch.d.ts +0 -1
package/tools/start.js ADDED
@@ -0,0 +1,194 @@
1
+ const path = require('path');
2
+ const { join } = path;
3
+ const express = require('express');
4
+ const { existsSync, mkdirSync, copyFileSync, readFileSync, writeFileSync, watch } = require('fs');
5
+ const rollup = require('rollup');
6
+ const rimraf = require('rimraf');
7
+ const glob = require('glob');
8
+ const { config, ELEMENT_NAME } = require('./rollup-config');
9
+ const { generateSources } = require('./generate-sources');
10
+
11
+ const STATIC_ASSET_EXTS = new Set([
12
+ '.css', '.svg', '.png', '.jpg', '.jpeg', '.gif',
13
+ '.ico', '.webp', '.woff', '.woff2', '.ttf', '.otf',
14
+ '.txt'
15
+ ]);
16
+
17
+ const INLINE_SOURCE_EXTS = new Set(['.ts', '.scss']);
18
+
19
+ const DEST_PATH = 'dist';
20
+ // Inline demo sources so sibling demo imports resolve.
21
+ const SRC_PATH = `demos/**/*.ts`;
22
+ const SRC_TMP_PATH = `.tmp`;
23
+
24
+ // Simple dev server
25
+ class DevServer {
26
+ static start() {
27
+ const app = express();
28
+ const port = 3000;
29
+
30
+ app.use(express.static(DEST_PATH));
31
+
32
+ app.listen(port, () => {
33
+ console.log(`Server running at http://localhost:${port}`);
34
+ });
35
+ }
36
+ }
37
+
38
+ async function clean(dir) {
39
+ return new Promise((resolve, reject) => {
40
+ rimraf(dir, (err) => {
41
+ if (err) reject(err);
42
+ else resolve();
43
+ });
44
+ });
45
+ }
46
+
47
+ async function inlineSources(srcPattern, destPath) {
48
+ const files = glob.sync(srcPattern);
49
+
50
+ if (!existsSync(destPath)) {
51
+ mkdirSync(destPath, { recursive: true });
52
+ }
53
+
54
+ for (const file of files) {
55
+ let content = readFileSync(file, 'utf-8');
56
+ const relativePath = file.replace('demos/', '');
57
+ const destFile = join(destPath, relativePath);
58
+ const destDir = join(destPath, relativePath.split('/').slice(0, -1).join('/'));
59
+
60
+ if (!existsSync(destDir)) {
61
+ mkdirSync(destDir, { recursive: true });
62
+ }
63
+
64
+ // Inline templateUrl and styleUrl references
65
+ content = inlineTemplates(content, file.split('/').slice(0, -1).join('/'));
66
+
67
+ writeFileSync(destFile, content);
68
+ }
69
+ }
70
+
71
+ function inlineTemplates(content, basePath) {
72
+ // Match templateUrl: './file.html'
73
+ const templateUrlRegex = /templateUrl:\s*['"`]([^'"`]+)['"`]/g;
74
+ content = content.replace(templateUrlRegex, (match, filePath) => {
75
+ const fullPath = join(basePath, filePath);
76
+ if (existsSync(fullPath)) {
77
+ const template = readFileSync(fullPath, 'utf-8')
78
+ .replace(/`/g, '\\`')
79
+ .replace(/\$/g, '\\$');
80
+ return `template: \`${template}\``;
81
+ }
82
+ return match;
83
+ });
84
+
85
+ // Match styleUrl: './file.scss' or './file.css'
86
+ const styleUrlRegex = /styleUrl:\s*['"`]([^'"`]+)['"`]/g;
87
+ content = content.replace(styleUrlRegex, (match, filePath) => {
88
+ const fullPath = join(basePath, filePath);
89
+ if (existsSync(fullPath)) {
90
+ let style = readFileSync(fullPath, 'utf-8');
91
+ // For SCSS files, we'd normally compile them, but for now just use as CSS
92
+ style = style.replace(/`/g, '\\`').replace(/\$/g, '\\$');
93
+ return `style: \`${style}\``;
94
+ }
95
+ return match;
96
+ });
97
+
98
+ return content;
99
+ }
100
+
101
+ async function rollupGenerate(config) {
102
+ const bundle = await rollup.rollup(config.inputOptions);
103
+ await bundle.write(config.outputOptions);
104
+ }
105
+
106
+ function copyStaticAssets(srcDir, destDir) {
107
+ const files = glob.sync(`${srcDir}/**/*`, { nodir: true });
108
+ for (const file of files) {
109
+ const ext = path.extname(file).toLowerCase();
110
+ if (!STATIC_ASSET_EXTS.has(ext)) continue;
111
+ const rel = path.relative(srcDir, file);
112
+ const dest = path.join(destDir, rel);
113
+ const destSubDir = path.dirname(dest);
114
+ if (!existsSync(destSubDir)) mkdirSync(destSubDir, { recursive: true });
115
+ copyFileSync(file, dest);
116
+ }
117
+ }
118
+
119
+ const copy = () => {
120
+ if (!existsSync(DEST_PATH)) {
121
+ mkdirSync(DEST_PATH, { recursive: true });
122
+ }
123
+
124
+ // Copy polyfills to dist
125
+ const polyfillsDir = join(DEST_PATH, 'node_modules', '@webcomponents', 'custom-elements');
126
+ if (!existsSync(polyfillsDir)) {
127
+ mkdirSync(polyfillsDir, { recursive: true });
128
+ }
129
+
130
+ const srcDir = join(polyfillsDir, 'src');
131
+ if (!existsSync(srcDir)) {
132
+ mkdirSync(srcDir, { recursive: true });
133
+ }
134
+
135
+ // Copy native-shim.js
136
+ const nativeShimSrc = join('node_modules', '@webcomponents', 'custom-elements', 'src', 'native-shim.js');
137
+ const nativeShimDest = join(polyfillsDir, 'src', 'native-shim.js');
138
+ if (existsSync(nativeShimSrc)) {
139
+ copyFileSync(nativeShimSrc, nativeShimDest);
140
+ }
141
+
142
+ // Copy custom-elements.min.js
143
+ const customElementsSrc = join('node_modules', '@webcomponents', 'custom-elements', 'custom-elements.min.js');
144
+ const customElementsDest = join(polyfillsDir, 'custom-elements.min.js');
145
+ if (existsSync(customElementsSrc)) {
146
+ copyFileSync(customElementsSrc, customElementsDest);
147
+ }
148
+
149
+ copyStaticAssets(`demos/${ELEMENT_NAME}`, DEST_PATH);
150
+
151
+ return copyFileSync(`demos/${ELEMENT_NAME}/index.html`, join(DEST_PATH, 'index.html'));
152
+ };
153
+
154
+ const fileWatcher = () => {
155
+ // Watch src and demos directories
156
+ watch('src', { recursive: true }, async (eventType, filename) => {
157
+ if (filename && INLINE_SOURCE_EXTS.has(path.extname(filename).toLowerCase())) {
158
+ console.log(`File changed: ${filename}`);
159
+ await inlineSources(SRC_PATH, SRC_TMP_PATH);
160
+ await generateSources(SRC_TMP_PATH);
161
+ await rollupGenerate(config);
162
+ }
163
+ });
164
+
165
+ watch('demos', { recursive: true }, async (eventType, filename) => {
166
+ if (!filename) return;
167
+ const ext = path.extname(filename).toLowerCase();
168
+ if (INLINE_SOURCE_EXTS.has(ext)) {
169
+ console.log(`File changed: ${filename}`);
170
+ await inlineSources(SRC_PATH, SRC_TMP_PATH);
171
+ await generateSources(SRC_TMP_PATH);
172
+ await rollupGenerate(config);
173
+ } else if (ext === '.html') {
174
+ console.log(`HTML changed: ${filename}`);
175
+ copy();
176
+ } else if (STATIC_ASSET_EXTS.has(ext)) {
177
+ console.log(`Asset changed: ${filename}`);
178
+ copyStaticAssets(`demos/${ELEMENT_NAME}`, DEST_PATH);
179
+ }
180
+ });
181
+ }
182
+
183
+ Promise.all([clean(DEST_PATH), clean(SRC_TMP_PATH)])
184
+ .then(() => Promise.all([inlineSources(SRC_PATH, SRC_TMP_PATH), copy()]))
185
+ .then(() => generateSources(SRC_TMP_PATH))
186
+ .then(() => {
187
+ rollupGenerate(config);
188
+ DevServer.start();
189
+ fileWatcher();
190
+ })
191
+ .catch(err => {
192
+ console.error('Start failed:', err);
193
+ process.exit(1);
194
+ });
package/tsconfig.json ADDED
@@ -0,0 +1,38 @@
1
+ {
2
+ "compilerOptions": {
3
+ "allowSyntheticDefaultImports": true,
4
+ "allowUnreachableCode": false,
5
+ "baseUrl": ".",
6
+ "emitDecoratorMetadata": true,
7
+ "experimentalDecorators": true,
8
+ "importHelpers": true,
9
+ "lib": ["es5", "es6", "dom"],
10
+ "module": "es2015",
11
+ "moduleResolution": "node",
12
+ "noUnusedLocals": false,
13
+ "strict": true,
14
+ "noImplicitAny": true,
15
+ "strictNullChecks": true,
16
+ "noFallthroughCasesInSwitch": true,
17
+ "forceConsistentCasingInFileNames": true,
18
+ "noUnusedParameters": true,
19
+ "outDir": "dist",
20
+ "paths": {
21
+ "custom-elements-ts": ["src/index"]
22
+ },
23
+ "removeComments": true,
24
+ "rootDir": ".",
25
+ "sourceMap": true,
26
+ "target": "es6"
27
+ },
28
+ "include": [
29
+ ".tmp/**/*",
30
+ "demos/**/*.ts",
31
+ "src/**/*.ts",
32
+ "tests/**/*.ts"
33
+ ],
34
+ "exclude": [
35
+ "dist",
36
+ "node_modules"
37
+ ]
38
+ }
@@ -0,0 +1,30 @@
1
+ import { defineConfig } from 'vitest/config';
2
+
3
+ export default defineConfig({
4
+ esbuild: {
5
+ tsconfigRaw: {
6
+ compilerOptions: {
7
+ experimentalDecorators: true,
8
+ useDefineForClassFields: false,
9
+ target: 'es2017',
10
+ },
11
+ },
12
+ },
13
+ resolve: {
14
+ alias: {
15
+ 'custom-elements-ts': '/src/index.ts',
16
+ },
17
+ },
18
+ test: {
19
+ environment: 'happy-dom',
20
+ globals: true,
21
+ reporters: ['verbose'],
22
+ coverage: {
23
+ provider: 'v8',
24
+ reporter: ['text', 'lcov', 'html'],
25
+ include: ['src/**/*.{ts,tsx,js}'],
26
+ exclude: ['demos/**', 'tools/**', 'tests/**', 'dist/**', 'node_modules/**']
27
+ },
28
+ },
29
+ });
30
+
@@ -1,359 +0,0 @@
1
- (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
3
- typeof define === 'function' && define.amd ? define(['exports'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["custom-elements-ts"] = {}));
5
- })(this, (function (exports) { 'use strict';
6
-
7
- /******************************************************************************
8
- Copyright (c) Microsoft Corporation.
9
-
10
- Permission to use, copy, modify, and/or distribute this software for any
11
- purpose with or without fee is hereby granted.
12
-
13
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
14
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
15
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
16
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
17
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
18
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
19
- PERFORMANCE OF THIS SOFTWARE.
20
- ***************************************************************************** */
21
- /* global Reflect, Promise, SuppressedError, Symbol, Iterator */
22
-
23
- var extendStatics = function(d, b) {
24
- extendStatics = Object.setPrototypeOf ||
25
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
26
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
27
- return extendStatics(d, b);
28
- };
29
-
30
- function __extends(d, b) {
31
- if (typeof b !== "function" && b !== null)
32
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
33
- extendStatics(d, b);
34
- function __() { this.constructor = d; }
35
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
36
- }
37
-
38
- var __assign = function() {
39
- __assign = Object.assign || function __assign(t) {
40
- for (var s, i = 1, n = arguments.length; i < n; i++) {
41
- s = arguments[i];
42
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
43
- }
44
- return t;
45
- };
46
- return __assign.apply(this, arguments);
47
- };
48
-
49
- typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
50
- var e = new Error(message);
51
- return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
52
- };
53
-
54
- var toKebabCase = function (str) {
55
- return str
56
- .replace(/([a-z])([A-Z])/g, '$1-$2')
57
- .replace(/[\s_]+/g, '-')
58
- .toLowerCase();
59
- };
60
- var toCamelCase = function (str) {
61
- return str.toLowerCase().replace(/(-\w)/g, function (m) { return m[1].toUpperCase(); });
62
- };
63
- var toDotCase = function (str) {
64
- return str
65
- .replace(/(?!^)([A-Z])/g, ' $1')
66
- .replace(/[_\s]+(?=[a-zA-Z])/g, '.')
67
- .toLowerCase();
68
- };
69
- var tryParseInt = function (value) {
70
- if (typeof value === 'number' && Number.isInteger(value)) {
71
- return value;
72
- }
73
- if (typeof value === 'string') {
74
- var trimmed = value.trim();
75
- if (trimmed !== '') {
76
- var parsed = Number(trimmed);
77
- if (Number.isInteger(parsed) && String(parsed) === trimmed) {
78
- return parsed;
79
- }
80
- }
81
- }
82
- return value;
83
- };
84
-
85
- var Listen = function (eventName, selector) {
86
- return function (target, methodName) {
87
- if (!target.constructor.listeners) {
88
- target.constructor.listeners = [];
89
- }
90
- target.constructor.listeners.push({
91
- selector: selector,
92
- eventName: eventName,
93
- handler: target[methodName],
94
- });
95
- };
96
- };
97
- var addEventListeners = function (target) {
98
- if (target.constructor.listeners) {
99
- var targetRoot = target.shadowRoot || target;
100
- var _loop_1 = function (listener) {
101
- var eventTarget = target;
102
- if (listener.selector) {
103
- eventTarget = targetRoot.querySelector(listener.selector);
104
- }
105
- if (eventTarget) {
106
- eventTarget.addEventListener(listener.eventName, function (e) {
107
- listener.handler.call(target, e);
108
- });
109
- }
110
- };
111
- for (var _i = 0, _a = target.constructor.listeners; _i < _a.length; _i++) {
112
- var listener = _a[_i];
113
- _loop_1(listener);
114
- }
115
- }
116
- };
117
- var Dispatch = function (eventName) {
118
- return function (target, propertyName) {
119
- function get() {
120
- var self = this;
121
- return {
122
- emit: function (options) {
123
- var evtName = eventName ? eventName : toDotCase(propertyName);
124
- self.dispatchEvent(new CustomEvent(evtName, options));
125
- },
126
- };
127
- }
128
- Object.defineProperty(target, propertyName, { get: get });
129
- };
130
- };
131
-
132
- var Prop = function () {
133
- return function (target, propName) {
134
- var attrName = toKebabCase(propName);
135
- function get() {
136
- var hasOwn = Object.prototype.hasOwnProperty.call(this.props, propName);
137
- if (hasOwn) {
138
- return this.props[propName];
139
- }
140
- return this.getAttribute(attrName);
141
- }
142
- function set(value) {
143
- if (this.__connected) {
144
- var oldValue = this.props[propName];
145
- this.props[propName] = tryParseInt(value);
146
- var valueType = typeof value;
147
- var shouldReflect = valueType === 'string' || valueType === 'number' || valueType === 'boolean';
148
- if (shouldReflect) {
149
- this.setAttribute(attrName, value);
150
- }
151
- else {
152
- this.onAttributeChange(attrName, oldValue, value, false);
153
- }
154
- }
155
- else {
156
- if (!this.hasAttribute(toKebabCase(propName))) {
157
- this.constructor.propsInit[propName] = value;
158
- }
159
- }
160
- }
161
- if (!target.constructor.propsInit) {
162
- target.constructor.propsInit = {};
163
- }
164
- target.constructor.propsInit[propName] = null;
165
- Object.defineProperty(target, propName, { get: get, set: set });
166
- };
167
- };
168
- var getProps = function (target) {
169
- var watchAttributes = target.constructor.watchAttributes;
170
- var plainAttributes = __assign({}, watchAttributes);
171
- Object.keys(plainAttributes).forEach(function (v) { return (plainAttributes[v] = ''); });
172
- var cycleProps = __assign(__assign({}, plainAttributes), target.constructor.propsInit);
173
- return Object.keys(cycleProps);
174
- };
175
- var initializeProps = function (target) {
176
- var watchAttributes = target.constructor.watchAttributes;
177
- for (var _i = 0, _a = getProps(target); _i < _a.length; _i++) {
178
- var prop = _a[_i];
179
- if (watchAttributes) {
180
- if (watchAttributes[toKebabCase(prop)] === null ||
181
- watchAttributes[toKebabCase(prop)] === undefined) {
182
- watchAttributes[toKebabCase(prop)] = '';
183
- }
184
- else {
185
- var hasOwn = Object.prototype.hasOwnProperty.call(target.props, prop);
186
- var attribValue = hasOwn ? target.props[prop] : target.getAttribute(toKebabCase(prop));
187
- if (typeof target[watchAttributes[prop]] === 'function') {
188
- target[watchAttributes[prop]]({ new: attribValue });
189
- }
190
- }
191
- }
192
- if (target.constructor.propsInit[prop]) {
193
- if (!target.hasAttribute(toKebabCase(prop))) {
194
- target[prop] = target.constructor.propsInit[prop];
195
- }
196
- }
197
- }
198
- };
199
-
200
- var CustomElement = function (args) {
201
- return function (target) {
202
- var tag = args.tag || toKebabCase(target.prototype.constructor.name);
203
- var customElement = (function (_super) {
204
- __extends(class_1, _super);
205
- function class_1() {
206
- var _this = _super.call(this) || this;
207
- _this.__connected = false;
208
- _this.props = {};
209
- _this.showShadowRoot =
210
- args.shadow === undefined || args.shadow === null ? true : args.shadow;
211
- if (!_this.shadowRoot && _this.showShadowRoot) {
212
- _this.attachShadow({ mode: 'open' });
213
- }
214
- return _this;
215
- }
216
- Object.defineProperty(class_1, "observedAttributes", {
217
- get: function () {
218
- return Object.keys(this.propsInit || {}).map(function (x) { return toKebabCase(x); });
219
- },
220
- enumerable: false,
221
- configurable: true
222
- });
223
- class_1.prototype.attributeChangedCallback = function (name, oldValue, newValue) {
224
- this.onAttributeChange(name, oldValue, newValue);
225
- };
226
- class_1.prototype.onAttributeChange = function (name, oldValue, newValue, set) {
227
- if (set === void 0) { set = true; }
228
- if (oldValue !== newValue) {
229
- if (set) {
230
- var propName = toCamelCase(name);
231
- this[propName] = newValue;
232
- }
233
- var watchAttributes = this.constructor.watchAttributes;
234
- if (watchAttributes && watchAttributes[name]) {
235
- var methodToCall = watchAttributes[name];
236
- if (this.__connected) {
237
- if (typeof this[methodToCall] === 'function') {
238
- this[methodToCall]({ old: oldValue, new: newValue });
239
- }
240
- }
241
- }
242
- }
243
- };
244
- class_1.prototype.connectedCallback = function () {
245
- this.__render();
246
- var parentProto = Object.getPrototypeOf(Object.getPrototypeOf(this)) || null;
247
- if (parentProto && typeof parentProto.connectedCallback === 'function') {
248
- parentProto.connectedCallback.call(this);
249
- }
250
- this.__connected = true;
251
- addEventListeners(this);
252
- initializeProps(this);
253
- };
254
- class_1.prototype.__render = function () {
255
- if (this.__connected)
256
- return;
257
- var template = document.createElement('template');
258
- var style = "".concat(args.style ? "<style>".concat(args.style, "</style>") : '');
259
- template.innerHTML = "".concat(style).concat(args.template ? args.template : '');
260
- (this.showShadowRoot ? this.shadowRoot : this).appendChild(document.importNode(template.content, true));
261
- };
262
- return class_1;
263
- }(target));
264
- if (!customElements.get(tag)) {
265
- customElements.define(tag, customElement);
266
- }
267
- return customElement;
268
- };
269
- };
270
-
271
- var Watch = function (attrName) {
272
- return function (target, propertyName) {
273
- if (!target.constructor.watchAttributes) {
274
- target.constructor.watchAttributes = {};
275
- }
276
- target.constructor.watchAttributes[toKebabCase(attrName)] = propertyName;
277
- if (!target.constructor.propsInit) {
278
- target.constructor.propsInit = {};
279
- }
280
- target.constructor.propsInit[attrName] = null;
281
- };
282
- };
283
-
284
- var Toggle = function () {
285
- return function (target, propName) {
286
- function get() {
287
- var _this = this;
288
- var getAttribute = function (attrName) {
289
- if (_this.hasAttribute(attrName)) {
290
- var attrValue = _this.getAttribute(attrName);
291
- if (/^(true|false|^$)$/.test(attrValue)) {
292
- return attrValue === 'true' || attrValue === '';
293
- }
294
- else {
295
- return false;
296
- }
297
- }
298
- return false;
299
- };
300
- return getAttribute(propName);
301
- }
302
- function set(value) {
303
- var oldValue = value;
304
- if (value !== null && value !== undefined) {
305
- switch (typeof value) {
306
- case 'boolean':
307
- break;
308
- case 'string':
309
- if (/^(true|false|^$)$/.test(value)) {
310
- value = oldValue === 'true' || oldValue === '';
311
- }
312
- else {
313
- console.warn("TypeError: Cannot set boolean toggle property '".concat(propName, "' to '").concat(value, "'"));
314
- value = false;
315
- }
316
- break;
317
- default:
318
- throw new TypeError("Cannot set boolean toggle property '".concat(propName, "' to '").concat(value, "'"));
319
- }
320
- }
321
- if (this.__connected) {
322
- this.props[propName] = value || false;
323
- if (oldValue !== '' && oldValue !== null) {
324
- this.setAttribute(propName, value);
325
- }
326
- else {
327
- if (value) {
328
- this.setAttribute(propName, '');
329
- }
330
- else {
331
- this.removeAttribute(propName);
332
- }
333
- }
334
- }
335
- else {
336
- if (!this.hasAttribute(toKebabCase(propName))) {
337
- this.constructor.propsInit[propName] = value;
338
- }
339
- }
340
- }
341
- if (!target.constructor.propsInit) {
342
- target.constructor.propsInit = {};
343
- }
344
- target.constructor.propsInit[propName] = null;
345
- Object.defineProperty(target, propName, { get: get, set: set });
346
- };
347
- };
348
-
349
- exports.CustomElement = CustomElement;
350
- exports.Dispatch = Dispatch;
351
- exports.Listen = Listen;
352
- exports.Prop = Prop;
353
- exports.Toggle = Toggle;
354
- exports.Watch = Watch;
355
- exports.addEventListeners = addEventListeners;
356
- exports.initializeProps = initializeProps;
357
-
358
- }));
359
- //# sourceMappingURL=custom-elements-ts.umd.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"custom-elements-ts.umd.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}