@dinoreic/fez 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/LICENSE +30 -0
- package/README.md +638 -0
- package/dist/fez.js +28 -0
- package/dist/fez.js.map +7 -0
- package/dist/rollup.js +3 -0
- package/dist/rollup.js.map +7 -0
- package/package.json +60 -0
- package/src/fez/compile.js +195 -0
- package/src/fez/connect.js +217 -0
- package/src/fez/instance.js +582 -0
- package/src/fez/lib/global-state.js +157 -0
- package/src/fez/lib/n.js +65 -0
- package/src/fez/lib/template.js +119 -0
- package/src/fez/root.js +465 -0
- package/src/fez/vendor/gobber.js +8 -0
- package/src/fez/vendor/idiomorph.js +860 -0
- package/src/fez.js +73 -0
- package/src/rollup.js +31 -0
package/src/fez.js
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
// base class for custom dom objects
|
|
2
|
+
import FezBase from './fez/instance.js'
|
|
3
|
+
if (typeof window !== 'undefined') window.FezBase = FezBase
|
|
4
|
+
|
|
5
|
+
// base class for custom dom objects
|
|
6
|
+
import Fez from './fez/root.js'
|
|
7
|
+
if (typeof window !== 'undefined') window.Fez = Fez
|
|
8
|
+
|
|
9
|
+
// clear all unattached nodes
|
|
10
|
+
setInterval(() => {
|
|
11
|
+
for (const [key, el] of Fez.instances) {
|
|
12
|
+
if (!el?.isConnected) {
|
|
13
|
+
// Fez.error(`Found junk instance that is not connected ${el.fezName}`)
|
|
14
|
+
el.fez?.fezRemoveSelf()
|
|
15
|
+
Fez.instances.delete(key)
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}, 5_000)
|
|
19
|
+
|
|
20
|
+
// define Fez observer
|
|
21
|
+
const observer = new MutationObserver((mutations) => {
|
|
22
|
+
for (const { addedNodes, removedNodes } of mutations) {
|
|
23
|
+
addedNodes.forEach((node) => {
|
|
24
|
+
if (node.nodeType !== 1) return; // only elements
|
|
25
|
+
// check the node itself
|
|
26
|
+
if (node.matches('template[fez], xmp[fez], script[fez]')) {
|
|
27
|
+
window.requestAnimationFrame(()=>{
|
|
28
|
+
Fez.compile(node);
|
|
29
|
+
node.remove();
|
|
30
|
+
})
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
removedNodes.forEach((node) => {
|
|
35
|
+
if (node.nodeType === 1 && node.querySelectorAll) {
|
|
36
|
+
// check both the node itself and its descendants
|
|
37
|
+
const fezElements = node.querySelectorAll('.fez, :scope.fez');
|
|
38
|
+
fezElements
|
|
39
|
+
.forEach(el => {
|
|
40
|
+
if (el.fez && el.root) {
|
|
41
|
+
Fez.instances.delete(el.fez.UID)
|
|
42
|
+
el.fez.fezRemoveSelf()
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
// start observing the whole document
|
|
51
|
+
observer.observe(document.documentElement, {
|
|
52
|
+
childList: true,
|
|
53
|
+
subtree: true
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
// fez custom tags
|
|
57
|
+
|
|
58
|
+
//<fez-component name="some-node" :props="fez.props"></fez-node>
|
|
59
|
+
Fez('fez-component', class {
|
|
60
|
+
init(props) {
|
|
61
|
+
const tag = document.createElement(props.name)
|
|
62
|
+
tag.props = props.props || props['data-props'] || props
|
|
63
|
+
|
|
64
|
+
while (this.root.firstChild) {
|
|
65
|
+
this.root.parentNode.insertBefore(this.root.lastChild, tag.nextSibling);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
this.root.innerHTML = ''
|
|
69
|
+
this.root.appendChild(tag)
|
|
70
|
+
}
|
|
71
|
+
})
|
|
72
|
+
|
|
73
|
+
export default Fez
|
package/src/rollup.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
function fezPlugin() {
|
|
2
|
+
return {
|
|
3
|
+
name: 'fez-plugin',
|
|
4
|
+
|
|
5
|
+
transform(code, filePath) {
|
|
6
|
+
const baseName = filePath.split('/').pop().split('.');
|
|
7
|
+
|
|
8
|
+
if (baseName[1] === 'fez') {
|
|
9
|
+
code = code.replace(/`/g, '\\`').replace(/\$/g, '\\$');
|
|
10
|
+
const transformedCode = `Fez.compile('${baseName[0]}', \`\n${code}\`)`;
|
|
11
|
+
|
|
12
|
+
// if (baseName[0] === 'admin-menu') {
|
|
13
|
+
// console.log('Transformed code:', baseName, transformedCode);
|
|
14
|
+
// }
|
|
15
|
+
|
|
16
|
+
return {
|
|
17
|
+
code: transformedCode,
|
|
18
|
+
map: null,
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// Export for ES modules
|
|
26
|
+
export default fezPlugin;
|
|
27
|
+
|
|
28
|
+
// Export for CommonJS
|
|
29
|
+
// if (typeof module !== 'undefined') {
|
|
30
|
+
// module.exports = fezPlugin;
|
|
31
|
+
// }
|