custom-elements-ts 0.0.16 → 0.1.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/.eslintrc.json +46 -0
- package/.github/workflows/ci.yml +49 -0
- package/.prettierrc +7 -0
- package/LICENSE +20 -0
- package/README.md +426 -168
- package/demos/counter/counter.element.html +1 -0
- package/demos/counter/counter.element.scss +234 -0
- package/demos/counter/counter.element.ts +68 -0
- package/demos/counter/index.html +205 -0
- package/demos/counter/index.ts +1 -0
- package/demos/site/code-example/code-example.element.scss +168 -0
- package/demos/site/code-example/code-example.element.ts +88 -0
- package/demos/site/event-log/event-log.element.scss +179 -0
- package/demos/site/event-log/event-log.element.ts +134 -0
- package/demos/site/favicon.svg +14 -0
- package/demos/site/index.html +346 -0
- package/demos/site/index.ts +13 -0
- package/demos/site/message/message.element.scss +75 -0
- package/demos/site/message/message.element.ts +76 -0
- package/demos/site/og-image.png +0 -0
- package/demos/site/styles/site.css +1023 -0
- package/demos/site/styles/tokens.css +56 -0
- package/demos/site/toast/toast.element.scss +110 -0
- package/demos/site/toast/toast.element.ts +63 -0
- package/demos/todo-dashboard/index.html +141 -0
- package/demos/todo-dashboard/index.ts +4 -0
- package/demos/todo-dashboard/todo-dashboard.element.scss +1145 -0
- package/demos/todo-dashboard/todo-dashboard.element.ts +332 -0
- package/demos/todo-dashboard/todo-filters.element.ts +54 -0
- package/demos/todo-dashboard/todo-item.element.ts +126 -0
- package/demos/todo-dashboard/todo-stats.element.ts +189 -0
- package/package.json +73 -29
- package/src/custom-element.ts +206 -0
- package/{index.d.ts → src/index.ts} +2 -0
- package/src/listen.ts +70 -0
- package/src/prop.ts +92 -0
- package/src/state.ts +129 -0
- package/src/template-runtime.ts +435 -0
- package/src/toggle.ts +66 -0
- package/src/tsconfig.json +24 -0
- package/src/util.ts +33 -0
- package/src/watch.ts +14 -0
- package/tests/basic.spec.ts +70 -0
- package/tests/custom-element.spec.ts +77 -0
- package/tests/dispatch.spec.ts +52 -0
- package/tests/init.spec.ts +94 -0
- package/tests/listen.spec.ts +118 -0
- package/tests/prop.spec.ts +118 -0
- package/tests/templating-runtime.spec.ts +575 -0
- package/tests/toggle.spec.ts +92 -0
- package/tests/watch.spec.ts +183 -0
- package/tools/build.js +119 -0
- package/tools/bundle.js +167 -0
- package/tools/rollup-config.js +70 -0
- package/tools/start.js +188 -0
- package/tsconfig.json +38 -0
- package/vite.config.mts +30 -0
- package/bundles/custom-elements-ts.umd.js +0 -315
- package/bundles/custom-elements-ts.umd.js.map +0 -1
- package/custom-element.d.ts +0 -12
- package/esm2015/custom-elements-ts.js +0 -260
- package/esm2015/custom-elements-ts.js.map +0 -1
- package/esm5/custom-elements-ts.js +0 -298
- package/esm5/custom-elements-ts.js.map +0 -1
- package/listen.d.ts +0 -17
- package/prop.d.ts +0 -2
- package/toggle.d.ts +0 -1
- package/util.d.ts +0 -4
- package/watch.d.ts +0 -1
package/tools/start.js
ADDED
|
@@ -0,0 +1,188 @@
|
|
|
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
|
+
|
|
10
|
+
const STATIC_ASSET_EXTS = new Set([
|
|
11
|
+
'.css', '.svg', '.png', '.jpg', '.jpeg', '.gif',
|
|
12
|
+
'.ico', '.webp', '.woff', '.woff2', '.ttf', '.otf'
|
|
13
|
+
]);
|
|
14
|
+
|
|
15
|
+
const DEST_PATH = 'dist';
|
|
16
|
+
// Inline every demo source so a demo (like `site`) can freely import sibling
|
|
17
|
+
// demos and have their templateUrl/styleUrl references resolved.
|
|
18
|
+
const SRC_PATH = `demos/**/*.ts`;
|
|
19
|
+
const SRC_TMP_PATH = `.tmp`;
|
|
20
|
+
|
|
21
|
+
// Simple dev server
|
|
22
|
+
class DevServer {
|
|
23
|
+
static start() {
|
|
24
|
+
const app = express();
|
|
25
|
+
const port = 3000;
|
|
26
|
+
|
|
27
|
+
app.use(express.static(DEST_PATH));
|
|
28
|
+
|
|
29
|
+
app.listen(port, () => {
|
|
30
|
+
console.log(`Server running at http://localhost:${port}`);
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
async function clean(dir) {
|
|
36
|
+
return new Promise((resolve, reject) => {
|
|
37
|
+
rimraf(dir, (err) => {
|
|
38
|
+
if (err) reject(err);
|
|
39
|
+
else resolve();
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
async function inlineSources(srcPattern, destPath) {
|
|
45
|
+
const files = glob.sync(srcPattern);
|
|
46
|
+
|
|
47
|
+
if (!existsSync(destPath)) {
|
|
48
|
+
mkdirSync(destPath, { recursive: true });
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
for (const file of files) {
|
|
52
|
+
let content = readFileSync(file, 'utf-8');
|
|
53
|
+
const relativePath = file.replace('demos/', '');
|
|
54
|
+
const destFile = join(destPath, relativePath);
|
|
55
|
+
const destDir = join(destPath, relativePath.split('/').slice(0, -1).join('/'));
|
|
56
|
+
|
|
57
|
+
if (!existsSync(destDir)) {
|
|
58
|
+
mkdirSync(destDir, { recursive: true });
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// Inline templateUrl and styleUrl references
|
|
62
|
+
content = inlineTemplates(content, file.split('/').slice(0, -1).join('/'));
|
|
63
|
+
|
|
64
|
+
writeFileSync(destFile, content);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function inlineTemplates(content, basePath) {
|
|
69
|
+
// Match templateUrl: './file.html'
|
|
70
|
+
const templateUrlRegex = /templateUrl:\s*['"`]([^'"`]+)['"`]/g;
|
|
71
|
+
content = content.replace(templateUrlRegex, (match, filePath) => {
|
|
72
|
+
const fullPath = join(basePath, filePath);
|
|
73
|
+
if (existsSync(fullPath)) {
|
|
74
|
+
const template = readFileSync(fullPath, 'utf-8')
|
|
75
|
+
.replace(/`/g, '\\`')
|
|
76
|
+
.replace(/\$/g, '\\$');
|
|
77
|
+
return `template: \`${template}\``;
|
|
78
|
+
}
|
|
79
|
+
return match;
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
// Match styleUrl: './file.scss' or './file.css'
|
|
83
|
+
const styleUrlRegex = /styleUrl:\s*['"`]([^'"`]+)['"`]/g;
|
|
84
|
+
content = content.replace(styleUrlRegex, (match, filePath) => {
|
|
85
|
+
const fullPath = join(basePath, filePath);
|
|
86
|
+
if (existsSync(fullPath)) {
|
|
87
|
+
let style = readFileSync(fullPath, 'utf-8');
|
|
88
|
+
// For SCSS files, we'd normally compile them, but for now just use as CSS
|
|
89
|
+
style = style.replace(/`/g, '\\`').replace(/\$/g, '\\$');
|
|
90
|
+
return `style: \`${style}\``;
|
|
91
|
+
}
|
|
92
|
+
return match;
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
return content;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
async function rollupGenerate(config) {
|
|
99
|
+
const bundle = await rollup.rollup(config.inputOptions);
|
|
100
|
+
await bundle.write(config.outputOptions);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function copyStaticAssets(srcDir, destDir) {
|
|
104
|
+
const files = glob.sync(`${srcDir}/**/*`, { nodir: true });
|
|
105
|
+
for (const file of files) {
|
|
106
|
+
const ext = path.extname(file).toLowerCase();
|
|
107
|
+
if (!STATIC_ASSET_EXTS.has(ext)) continue;
|
|
108
|
+
const rel = path.relative(srcDir, file);
|
|
109
|
+
const dest = path.join(destDir, rel);
|
|
110
|
+
const destSubDir = path.dirname(dest);
|
|
111
|
+
if (!existsSync(destSubDir)) mkdirSync(destSubDir, { recursive: true });
|
|
112
|
+
copyFileSync(file, dest);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const copy = () => {
|
|
117
|
+
if (!existsSync(DEST_PATH)) {
|
|
118
|
+
mkdirSync(DEST_PATH, { recursive: true });
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// Copy polyfills to dist
|
|
122
|
+
const polyfillsDir = join(DEST_PATH, 'node_modules', '@webcomponents', 'custom-elements');
|
|
123
|
+
if (!existsSync(polyfillsDir)) {
|
|
124
|
+
mkdirSync(polyfillsDir, { recursive: true });
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
const srcDir = join(polyfillsDir, 'src');
|
|
128
|
+
if (!existsSync(srcDir)) {
|
|
129
|
+
mkdirSync(srcDir, { recursive: true });
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// Copy native-shim.js
|
|
133
|
+
const nativeShimSrc = join('node_modules', '@webcomponents', 'custom-elements', 'src', 'native-shim.js');
|
|
134
|
+
const nativeShimDest = join(polyfillsDir, 'src', 'native-shim.js');
|
|
135
|
+
if (existsSync(nativeShimSrc)) {
|
|
136
|
+
copyFileSync(nativeShimSrc, nativeShimDest);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// Copy custom-elements.min.js
|
|
140
|
+
const customElementsSrc = join('node_modules', '@webcomponents', 'custom-elements', 'custom-elements.min.js');
|
|
141
|
+
const customElementsDest = join(polyfillsDir, 'custom-elements.min.js');
|
|
142
|
+
if (existsSync(customElementsSrc)) {
|
|
143
|
+
copyFileSync(customElementsSrc, customElementsDest);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
copyStaticAssets(`demos/${ELEMENT_NAME}`, DEST_PATH);
|
|
147
|
+
|
|
148
|
+
return copyFileSync(`demos/${ELEMENT_NAME}/index.html`, join(DEST_PATH, 'index.html'));
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
const fileWatcher = () => {
|
|
152
|
+
// Watch src and demos directories
|
|
153
|
+
watch('src', { recursive: true }, async (eventType, filename) => {
|
|
154
|
+
if (filename && filename.endsWith('.ts')) {
|
|
155
|
+
console.log(`File changed: ${filename}`);
|
|
156
|
+
await inlineSources(SRC_PATH, SRC_TMP_PATH);
|
|
157
|
+
await rollupGenerate(config);
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
watch('demos', { recursive: true }, async (eventType, filename) => {
|
|
162
|
+
if (!filename) return;
|
|
163
|
+
const ext = path.extname(filename).toLowerCase();
|
|
164
|
+
if (ext === '.ts') {
|
|
165
|
+
console.log(`File changed: ${filename}`);
|
|
166
|
+
await inlineSources(SRC_PATH, SRC_TMP_PATH);
|
|
167
|
+
await rollupGenerate(config);
|
|
168
|
+
} else if (ext === '.html') {
|
|
169
|
+
console.log(`HTML changed: ${filename}`);
|
|
170
|
+
copy();
|
|
171
|
+
} else if (STATIC_ASSET_EXTS.has(ext)) {
|
|
172
|
+
console.log(`Asset changed: ${filename}`);
|
|
173
|
+
copyStaticAssets(`demos/${ELEMENT_NAME}`, DEST_PATH);
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
Promise.all([clean(DEST_PATH), clean(SRC_TMP_PATH)])
|
|
179
|
+
.then(() => Promise.all([inlineSources(SRC_PATH, SRC_TMP_PATH), copy()]))
|
|
180
|
+
.then(() => {
|
|
181
|
+
rollupGenerate(config);
|
|
182
|
+
DevServer.start();
|
|
183
|
+
fileWatcher();
|
|
184
|
+
})
|
|
185
|
+
.catch(err => {
|
|
186
|
+
console.error('Start failed:', err);
|
|
187
|
+
process.exit(1);
|
|
188
|
+
});
|
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
|
+
}
|
package/vite.config.mts
ADDED
|
@@ -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,315 +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
|
-
(factory((global['custom-elements-ts'] = {})));
|
|
5
|
-
}(this, (function (exports) { 'use strict';
|
|
6
|
-
|
|
7
|
-
var extendStatics = function(d, b) {
|
|
8
|
-
extendStatics = Object.setPrototypeOf ||
|
|
9
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
10
|
-
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
|
11
|
-
return extendStatics(d, b);
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
function __extends(d, b) {
|
|
15
|
-
extendStatics(d, b);
|
|
16
|
-
function __() { this.constructor = d; }
|
|
17
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
var __assign = function() {
|
|
21
|
-
__assign = Object.assign || function __assign(t) {
|
|
22
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
23
|
-
s = arguments[i];
|
|
24
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
25
|
-
}
|
|
26
|
-
return t;
|
|
27
|
-
};
|
|
28
|
-
return __assign.apply(this, arguments);
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
var toKebabCase = function (str) {
|
|
32
|
-
return str
|
|
33
|
-
.replace(/([a-z])([A-Z])/g, '$1-$2')
|
|
34
|
-
.replace(/[\s_]+/g, '-')
|
|
35
|
-
.toLowerCase();
|
|
36
|
-
};
|
|
37
|
-
var toCamelCase = function (str) {
|
|
38
|
-
return str
|
|
39
|
-
.toLowerCase()
|
|
40
|
-
.replace(/(\-\w)/g, function (m) { return m[1].toUpperCase(); });
|
|
41
|
-
};
|
|
42
|
-
var toDotCase = function (str) {
|
|
43
|
-
return str.replace(/(?!^)([A-Z])/g, ' $1')
|
|
44
|
-
.replace(/[_\s]+(?=[a-zA-Z])/g, '.')
|
|
45
|
-
.toLowerCase();
|
|
46
|
-
};
|
|
47
|
-
var tryParseInt = function (value) {
|
|
48
|
-
return (parseInt(value) == value && parseFloat(value) !== NaN) ? parseInt(value) : value;
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
var Listen = function (eventName, selector) {
|
|
52
|
-
return function (target, methodName) {
|
|
53
|
-
if (!target.constructor.listeners) {
|
|
54
|
-
target.constructor.listeners = [];
|
|
55
|
-
}
|
|
56
|
-
target.constructor.listeners.push({ selector: selector, eventName: eventName, handler: target[methodName] });
|
|
57
|
-
};
|
|
58
|
-
};
|
|
59
|
-
var addEventListeners = function (target) {
|
|
60
|
-
if (target.constructor.listeners) {
|
|
61
|
-
var targetRoot = target.shadowRoot || target;
|
|
62
|
-
var _loop_1 = function (listener) {
|
|
63
|
-
var eventTarget = (listener.selector)
|
|
64
|
-
? targetRoot.querySelector(listener.selector)
|
|
65
|
-
? targetRoot.querySelector(listener.selector) : null
|
|
66
|
-
: target;
|
|
67
|
-
if (eventTarget) {
|
|
68
|
-
eventTarget.addEventListener(listener.eventName, function (e) {
|
|
69
|
-
listener.handler.call(target, e);
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
};
|
|
73
|
-
for (var _i = 0, _a = target.constructor.listeners; _i < _a.length; _i++) {
|
|
74
|
-
var listener = _a[_i];
|
|
75
|
-
_loop_1(listener);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
};
|
|
79
|
-
var Dispatch = function (eventName) {
|
|
80
|
-
return function (target, propertyName) {
|
|
81
|
-
function get() {
|
|
82
|
-
var self = this;
|
|
83
|
-
return {
|
|
84
|
-
emit: function (options) {
|
|
85
|
-
var evtName = (eventName) ? eventName : toDotCase(propertyName);
|
|
86
|
-
self.dispatchEvent(new CustomEvent(evtName, options));
|
|
87
|
-
}
|
|
88
|
-
};
|
|
89
|
-
}
|
|
90
|
-
Object.defineProperty(target, propertyName, { get: get });
|
|
91
|
-
};
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
var Prop = function () {
|
|
95
|
-
return function (target, propName) {
|
|
96
|
-
var attrName = toKebabCase(propName);
|
|
97
|
-
function get() {
|
|
98
|
-
if (this.props[propName]) {
|
|
99
|
-
return this.props[propName];
|
|
100
|
-
}
|
|
101
|
-
return this.getAttribute(attrName);
|
|
102
|
-
}
|
|
103
|
-
function set(value) {
|
|
104
|
-
if (this.__connected) {
|
|
105
|
-
var oldValue = this.props[propName];
|
|
106
|
-
this.props[propName] = tryParseInt(value);
|
|
107
|
-
if (typeof value != 'object') {
|
|
108
|
-
this.setAttribute(attrName, value);
|
|
109
|
-
}
|
|
110
|
-
else {
|
|
111
|
-
this.onAttributeChange(attrName, oldValue, value, false);
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
else {
|
|
115
|
-
if (!this.hasAttribute(toKebabCase(propName))) {
|
|
116
|
-
this.constructor.propsInit[propName] = value;
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
if (!target.constructor.propsInit) {
|
|
121
|
-
target.constructor.propsInit = {};
|
|
122
|
-
}
|
|
123
|
-
target.constructor.propsInit[propName] = null;
|
|
124
|
-
Object.defineProperty(target, propName, { get: get, set: set });
|
|
125
|
-
};
|
|
126
|
-
};
|
|
127
|
-
var getProps = function (target) {
|
|
128
|
-
var watchAttributes = target.constructor.watchAttributes;
|
|
129
|
-
var plainAttributes = __assign({}, watchAttributes);
|
|
130
|
-
Object.keys(plainAttributes).forEach(function (v) { return plainAttributes[v] = ''; });
|
|
131
|
-
var cycleProps = __assign({}, plainAttributes, target.constructor.propsInit);
|
|
132
|
-
return Object.keys(cycleProps);
|
|
133
|
-
};
|
|
134
|
-
var initializeProps = function (target) {
|
|
135
|
-
var watchAttributes = target.constructor.watchAttributes;
|
|
136
|
-
for (var _i = 0, _a = getProps(target); _i < _a.length; _i++) {
|
|
137
|
-
var prop = _a[_i];
|
|
138
|
-
if (watchAttributes) {
|
|
139
|
-
if (watchAttributes[toKebabCase(prop)] == null) {
|
|
140
|
-
watchAttributes[toKebabCase(prop)] = '';
|
|
141
|
-
}
|
|
142
|
-
else {
|
|
143
|
-
var attribValue = target.props[prop] || target.getAttribute(toKebabCase(prop));
|
|
144
|
-
if (typeof target[watchAttributes[prop]] == 'function') {
|
|
145
|
-
target[watchAttributes[prop]]({ new: attribValue });
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
if (target.constructor.propsInit[prop]) {
|
|
150
|
-
if (!target.hasAttribute(toKebabCase(prop))) {
|
|
151
|
-
target[prop] = target.constructor.propsInit[prop];
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
};
|
|
156
|
-
|
|
157
|
-
var CustomElement = function (args) {
|
|
158
|
-
return function (target) {
|
|
159
|
-
var _a;
|
|
160
|
-
var tag = args.tag || toKebabCase(target.prototype.constructor.name);
|
|
161
|
-
var customElement = (_a = (function (_super) {
|
|
162
|
-
__extends(class_1, _super);
|
|
163
|
-
function class_1() {
|
|
164
|
-
var _this = _super.call(this) || this;
|
|
165
|
-
_this.props = {};
|
|
166
|
-
_this.showShadowRoot = args.shadow == null ? true : args.shadow;
|
|
167
|
-
if (!_this.shadowRoot && _this.showShadowRoot) {
|
|
168
|
-
_this.attachShadow({ mode: 'open' });
|
|
169
|
-
}
|
|
170
|
-
return _this;
|
|
171
|
-
}
|
|
172
|
-
Object.defineProperty(class_1, "observedAttributes", {
|
|
173
|
-
get: function () {
|
|
174
|
-
return Object.keys(this.propsInit || {}).map(function (x) { return toKebabCase(x); });
|
|
175
|
-
},
|
|
176
|
-
enumerable: true,
|
|
177
|
-
configurable: true
|
|
178
|
-
});
|
|
179
|
-
class_1.prototype.attributeChangedCallback = function (name, oldValue, newValue) {
|
|
180
|
-
this.onAttributeChange(name, oldValue, newValue);
|
|
181
|
-
};
|
|
182
|
-
class_1.prototype.onAttributeChange = function (name, oldValue, newValue, set) {
|
|
183
|
-
if (set === void 0) { set = true; }
|
|
184
|
-
if (oldValue != newValue) {
|
|
185
|
-
if (set) {
|
|
186
|
-
this[toCamelCase(name)] = newValue;
|
|
187
|
-
}
|
|
188
|
-
var watchAttributes = this.constructor.watchAttributes;
|
|
189
|
-
if (watchAttributes && watchAttributes[name]) {
|
|
190
|
-
var methodToCall = watchAttributes[name];
|
|
191
|
-
if (this.__connected) {
|
|
192
|
-
if (typeof this[methodToCall] == 'function') {
|
|
193
|
-
this[methodToCall]({ old: oldValue, new: newValue });
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
};
|
|
199
|
-
class_1.prototype.connectedCallback = function () {
|
|
200
|
-
this.__render();
|
|
201
|
-
_super.prototype.connectedCallback && _super.prototype.connectedCallback.call(this);
|
|
202
|
-
this.__connected = true;
|
|
203
|
-
addEventListeners(this);
|
|
204
|
-
initializeProps(this);
|
|
205
|
-
};
|
|
206
|
-
class_1.prototype.__render = function () {
|
|
207
|
-
if (this.__connected)
|
|
208
|
-
return;
|
|
209
|
-
var template = document.createElement('template');
|
|
210
|
-
var style = "" + (args.style ? "<style>" + args.style + "</style>" : '');
|
|
211
|
-
template.innerHTML = "" + style + (args.template ? args.template : '');
|
|
212
|
-
(this.showShadowRoot ? this.shadowRoot : this).appendChild(document.importNode(template.content, true));
|
|
213
|
-
};
|
|
214
|
-
return class_1;
|
|
215
|
-
}(target)),
|
|
216
|
-
_a.__connected = false,
|
|
217
|
-
_a);
|
|
218
|
-
if (!customElements.get(tag)) {
|
|
219
|
-
customElements.define(tag, customElement);
|
|
220
|
-
}
|
|
221
|
-
return customElement;
|
|
222
|
-
};
|
|
223
|
-
};
|
|
224
|
-
|
|
225
|
-
var Watch = function (attrName) {
|
|
226
|
-
return function (target, propertyName) {
|
|
227
|
-
if (!target.constructor.watchAttributes) {
|
|
228
|
-
target.constructor.watchAttributes = {};
|
|
229
|
-
}
|
|
230
|
-
target.constructor.watchAttributes[toKebabCase(attrName)] = propertyName;
|
|
231
|
-
if (!target.constructor.propsInit) {
|
|
232
|
-
target.constructor.propsInit = {};
|
|
233
|
-
}
|
|
234
|
-
target.constructor.propsInit[attrName] = null;
|
|
235
|
-
};
|
|
236
|
-
};
|
|
237
|
-
|
|
238
|
-
var Toggle = function () {
|
|
239
|
-
return function (target, propName) {
|
|
240
|
-
function get() {
|
|
241
|
-
var _this = this;
|
|
242
|
-
var getAttribute = function (propName) {
|
|
243
|
-
if (_this.hasAttribute(propName)) {
|
|
244
|
-
var attrValue = _this.getAttribute(propName);
|
|
245
|
-
if (/^(true|false|^$)$/.test(attrValue)) {
|
|
246
|
-
return attrValue == 'true' || attrValue == '';
|
|
247
|
-
}
|
|
248
|
-
else {
|
|
249
|
-
return false;
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
return false;
|
|
253
|
-
};
|
|
254
|
-
return getAttribute(propName);
|
|
255
|
-
}
|
|
256
|
-
function set(value) {
|
|
257
|
-
var oldValue = value;
|
|
258
|
-
if (value != undefined) {
|
|
259
|
-
switch (typeof value) {
|
|
260
|
-
case 'boolean':
|
|
261
|
-
break;
|
|
262
|
-
case 'string':
|
|
263
|
-
if (/^(true|false|^$)$/.test(value)) {
|
|
264
|
-
value = oldValue == 'true' || oldValue == '';
|
|
265
|
-
}
|
|
266
|
-
else {
|
|
267
|
-
console.warn("TypeError: Cannot set boolean toggle property '" + propName + "' to '" + value + "'");
|
|
268
|
-
value = false;
|
|
269
|
-
}
|
|
270
|
-
break;
|
|
271
|
-
default:
|
|
272
|
-
throw ("TypeError: Cannot set boolean toggle property '" + propName + "' to '" + value + "'");
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
if (this.__connected) {
|
|
276
|
-
this.props[propName] = value || false;
|
|
277
|
-
if (oldValue !== '' && oldValue !== null) {
|
|
278
|
-
this.setAttribute(propName, value);
|
|
279
|
-
}
|
|
280
|
-
else {
|
|
281
|
-
if (value) {
|
|
282
|
-
this.setAttribute(propName, '');
|
|
283
|
-
}
|
|
284
|
-
else {
|
|
285
|
-
this.removeAttribute(propName);
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
else {
|
|
290
|
-
if (!this.hasAttribute(toKebabCase(propName))) {
|
|
291
|
-
this.constructor.propsInit[propName] = value;
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
if (!target.constructor.propsInit) {
|
|
296
|
-
target.constructor.propsInit = {};
|
|
297
|
-
}
|
|
298
|
-
target.constructor.propsInit[propName] = null;
|
|
299
|
-
Object.defineProperty(target, propName, { get: get, set: set });
|
|
300
|
-
};
|
|
301
|
-
};
|
|
302
|
-
|
|
303
|
-
exports.CustomElement = CustomElement;
|
|
304
|
-
exports.Watch = Watch;
|
|
305
|
-
exports.Prop = Prop;
|
|
306
|
-
exports.initializeProps = initializeProps;
|
|
307
|
-
exports.Toggle = Toggle;
|
|
308
|
-
exports.Listen = Listen;
|
|
309
|
-
exports.addEventListeners = addEventListeners;
|
|
310
|
-
exports.Dispatch = Dispatch;
|
|
311
|
-
|
|
312
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
313
|
-
|
|
314
|
-
})));
|
|
315
|
-
//# sourceMappingURL=custom-elements-ts.umd.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"custom-elements-ts.umd.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/custom-element.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
export interface CustomElementMetadata {
|
|
2
|
-
tag?: string;
|
|
3
|
-
template?: string;
|
|
4
|
-
templateUrl?: string;
|
|
5
|
-
styleUrl?: string;
|
|
6
|
-
style?: string;
|
|
7
|
-
shadow?: boolean;
|
|
8
|
-
}
|
|
9
|
-
export interface KeyValue {
|
|
10
|
-
[key: string]: any;
|
|
11
|
-
}
|
|
12
|
-
export declare const CustomElement: (args: CustomElementMetadata) => (target: any) => any;
|