vaderjs 1.3.2 → 1.3.4
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/create-vader-app/example_proj/dist/vaderjs/index.js +5 -0
- package/create-vader-app/example_proj/dist/vaderjs/vader-min.js +1115 -0
- package/create-vader-app/example_proj/dist/vaderjs/vaderRouter-min.js +1 -0
- package/create-vader-app/example_proj/dist/vaderjs/worker.js +327 -0
- package/create-vader-app/example_proj/index.html +20 -0
- package/create-vader-app/example_proj/readme.md +2 -0
- package/create-vader-app/example_proj/src/pages/Index.js +13 -0
- package/create-vader-app/example_proj/src/views/app.html +16 -0
- package/create-vader-app/index.js +20 -0
- package/create-vader-app/node_modules/.package-lock.json +350 -0
- package/create-vader-app/node_modules/chalk/license +9 -0
- package/create-vader-app/node_modules/chalk/package.json +83 -0
- package/create-vader-app/node_modules/chalk/readme.md +325 -0
- package/create-vader-app/node_modules/chalk/source/index.d.ts +320 -0
- package/create-vader-app/node_modules/chalk/source/index.js +225 -0
- package/create-vader-app/node_modules/chalk/source/utilities.js +33 -0
- package/create-vader-app/node_modules/chalk/source/vendor/ansi-styles/index.d.ts +236 -0
- package/create-vader-app/node_modules/chalk/source/vendor/ansi-styles/index.js +223 -0
- package/create-vader-app/node_modules/chalk/source/vendor/supports-color/browser.d.ts +1 -0
- package/create-vader-app/node_modules/chalk/source/vendor/supports-color/browser.js +30 -0
- package/create-vader-app/node_modules/chalk/source/vendor/supports-color/index.d.ts +55 -0
- package/create-vader-app/node_modules/chalk/source/vendor/supports-color/index.js +182 -0
- package/create-vader-app/node_modules/commander/LICENSE +22 -0
- package/create-vader-app/node_modules/commander/Readme.md +1146 -0
- package/create-vader-app/node_modules/commander/esm.mjs +16 -0
- package/create-vader-app/node_modules/commander/index.js +27 -0
- package/create-vader-app/node_modules/commander/lib/argument.js +147 -0
- package/create-vader-app/node_modules/commander/lib/command.js +2196 -0
- package/create-vader-app/node_modules/commander/lib/error.js +45 -0
- package/create-vader-app/node_modules/commander/lib/help.js +464 -0
- package/create-vader-app/node_modules/commander/lib/option.js +331 -0
- package/create-vader-app/node_modules/commander/lib/suggestSimilar.js +100 -0
- package/create-vader-app/node_modules/commander/package-support.json +16 -0
- package/create-vader-app/node_modules/commander/package.json +90 -0
- package/create-vader-app/node_modules/commander/typings/esm.d.mts +3 -0
- package/create-vader-app/node_modules/commander/typings/index.d.ts +889 -0
- package/create-vader-app/node_modules/fs-extra/LICENSE +15 -0
- package/create-vader-app/node_modules/fs-extra/README.md +292 -0
- package/create-vader-app/node_modules/fs-extra/lib/copy/copy-sync.js +161 -0
- package/create-vader-app/node_modules/fs-extra/lib/copy/copy.js +238 -0
- package/create-vader-app/node_modules/fs-extra/lib/copy/index.js +7 -0
- package/create-vader-app/node_modules/fs-extra/lib/empty/index.js +39 -0
- package/create-vader-app/node_modules/fs-extra/lib/ensure/file.js +69 -0
- package/create-vader-app/node_modules/fs-extra/lib/ensure/index.js +23 -0
- package/create-vader-app/node_modules/fs-extra/lib/ensure/link.js +64 -0
- package/create-vader-app/node_modules/fs-extra/lib/ensure/symlink-paths.js +99 -0
- package/create-vader-app/node_modules/fs-extra/lib/ensure/symlink-type.js +31 -0
- package/create-vader-app/node_modules/fs-extra/lib/ensure/symlink.js +82 -0
- package/create-vader-app/node_modules/fs-extra/lib/esm.mjs +68 -0
- package/create-vader-app/node_modules/fs-extra/lib/fs/index.js +140 -0
- package/create-vader-app/node_modules/fs-extra/lib/index.js +16 -0
- package/create-vader-app/node_modules/fs-extra/lib/json/index.js +16 -0
- package/create-vader-app/node_modules/fs-extra/lib/json/jsonfile.js +11 -0
- package/create-vader-app/node_modules/fs-extra/lib/json/output-json-sync.js +12 -0
- package/create-vader-app/node_modules/fs-extra/lib/json/output-json.js +12 -0
- package/create-vader-app/node_modules/fs-extra/lib/mkdirs/index.js +14 -0
- package/create-vader-app/node_modules/fs-extra/lib/mkdirs/make-dir.js +27 -0
- package/create-vader-app/node_modules/fs-extra/lib/mkdirs/utils.js +21 -0
- package/create-vader-app/node_modules/fs-extra/lib/move/index.js +7 -0
- package/create-vader-app/node_modules/fs-extra/lib/move/move-sync.js +55 -0
- package/create-vader-app/node_modules/fs-extra/lib/move/move.js +76 -0
- package/create-vader-app/node_modules/fs-extra/lib/output-file/index.js +40 -0
- package/create-vader-app/node_modules/fs-extra/lib/path-exists/index.js +12 -0
- package/create-vader-app/node_modules/fs-extra/lib/remove/index.js +17 -0
- package/create-vader-app/node_modules/fs-extra/lib/util/stat.js +154 -0
- package/create-vader-app/node_modules/fs-extra/lib/util/utimes.js +26 -0
- package/create-vader-app/node_modules/fs-extra/package.json +71 -0
- package/create-vader-app/node_modules/graceful-fs/LICENSE +15 -0
- package/create-vader-app/node_modules/graceful-fs/README.md +143 -0
- package/create-vader-app/node_modules/graceful-fs/clone.js +23 -0
- package/create-vader-app/node_modules/graceful-fs/graceful-fs.js +448 -0
- package/create-vader-app/node_modules/graceful-fs/legacy-streams.js +118 -0
- package/create-vader-app/node_modules/graceful-fs/package.json +53 -0
- package/create-vader-app/node_modules/graceful-fs/polyfills.js +355 -0
- package/create-vader-app/node_modules/inherits/LICENSE +16 -0
- package/create-vader-app/node_modules/inherits/README.md +42 -0
- package/create-vader-app/node_modules/inherits/inherits.js +7 -0
- package/create-vader-app/node_modules/inherits/inherits_browser.js +23 -0
- package/create-vader-app/node_modules/inherits/package.json +29 -0
- package/create-vader-app/node_modules/jsonfile/CHANGELOG.md +171 -0
- package/create-vader-app/node_modules/jsonfile/LICENSE +15 -0
- package/create-vader-app/node_modules/jsonfile/README.md +230 -0
- package/create-vader-app/node_modules/jsonfile/index.js +88 -0
- package/create-vader-app/node_modules/jsonfile/package.json +40 -0
- package/create-vader-app/node_modules/jsonfile/utils.js +14 -0
- package/create-vader-app/node_modules/path/LICENSE +18 -0
- package/create-vader-app/node_modules/path/README.md +15 -0
- package/create-vader-app/node_modules/path/package.json +24 -0
- package/create-vader-app/node_modules/path/path.js +628 -0
- package/create-vader-app/node_modules/process/.eslintrc +21 -0
- package/create-vader-app/node_modules/process/LICENSE +22 -0
- package/create-vader-app/node_modules/process/README.md +26 -0
- package/create-vader-app/node_modules/process/browser.js +184 -0
- package/create-vader-app/node_modules/process/index.js +2 -0
- package/create-vader-app/node_modules/process/package.json +27 -0
- package/create-vader-app/node_modules/process/test.js +199 -0
- package/create-vader-app/node_modules/universalify/LICENSE +20 -0
- package/create-vader-app/node_modules/universalify/README.md +76 -0
- package/create-vader-app/node_modules/universalify/index.js +24 -0
- package/create-vader-app/node_modules/universalify/package.json +34 -0
- package/create-vader-app/node_modules/util/LICENSE +18 -0
- package/create-vader-app/node_modules/util/README.md +15 -0
- package/create-vader-app/node_modules/util/package.json +35 -0
- package/create-vader-app/node_modules/util/support/isBuffer.js +3 -0
- package/create-vader-app/node_modules/util/support/isBufferBrowser.js +6 -0
- package/create-vader-app/node_modules/util/util.js +586 -0
- package/create-vader-app/package-lock.json +384 -0
- package/create-vader-app/package.json +18 -0
- package/images/router.png +0 -0
- package/images/state.png +0 -0
- package/package.json +1 -1
- package/ts.config.json +1 -0
- package/vader-min.js +1 -1
- package/vader.js +106 -326
- package/worker-min.js +1 -1
- package/worker.js +268 -168
package/vader.js
CHANGED
|
@@ -1,96 +1,8 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
1
2
|
let dom = [];
|
|
2
3
|
let states = {};
|
|
3
|
-
let worker = new Worker(new URL("./worker.js", import.meta.url));
|
|
4
|
-
/**
|
|
5
|
-
* @function markdown
|
|
6
|
-
* @param {String} content
|
|
7
|
-
* @description Allows you to convert markdown to html
|
|
8
|
-
*/
|
|
9
|
-
function markdown(content) {
|
|
10
|
-
let headers = content.match(/(#+)(.*)/g);
|
|
11
|
-
if (headers) {
|
|
12
|
-
headers.forEach((header) => {
|
|
13
|
-
if (
|
|
14
|
-
header.includes("/") ||
|
|
15
|
-
header.includes("<") ||
|
|
16
|
-
header.includes(">")
|
|
17
|
-
) {
|
|
18
|
-
return;
|
|
19
|
-
}
|
|
20
|
-
let level = header.split("#").length;
|
|
21
|
-
content = content.replace(
|
|
22
|
-
header,
|
|
23
|
-
`<h${level} class="markdown_heading">${header.replace(
|
|
24
|
-
/#/g,
|
|
25
|
-
""
|
|
26
|
-
)}</h${level}>`
|
|
27
|
-
);
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
content = content.replace(/\*\*(.*?)\*\*/g, (match, text) => {
|
|
32
|
-
return `<b class="markdown_bold">${text}</b>`;
|
|
33
|
-
});
|
|
34
|
-
content = content.replace(/\*(.*?)\*/g, (match, text) => {
|
|
35
|
-
return `<i class="markdown_italic">${text}</i>`;
|
|
36
|
-
});
|
|
37
|
-
content = content.replace(/`(.*?)`/g, (match, text) => {
|
|
38
|
-
return `<code>${text}</code>`;
|
|
39
|
-
});
|
|
40
|
-
content = content.replace(/\[([^\]]+)\]\(([^)]+)\)/g, (match, text, url) => {
|
|
41
|
-
return `<a class="markdown_link" href="${url}">${text}</a>`;
|
|
42
|
-
});
|
|
43
|
-
content = content.replace(/!\[([^\]]+)\]\(([^)]+)\)/g, (match, alt, src) => {
|
|
44
|
-
return `<img class="markdown_image" src="${src}" alt="${alt}" />`;
|
|
45
|
-
});
|
|
46
|
-
content = content
|
|
47
|
-
.split("\n")
|
|
48
|
-
.map((line, index, arr) => {
|
|
49
|
-
if (line.match(/^\s*-\s+(.*?)$/gm)) {
|
|
50
|
-
if (index === 0 || !arr[index - 1].match(/^\s*-\s+(.*?)$/gm)) {
|
|
51
|
-
return `<ul class="markdown_unordered" style="list-style-type:disc;list-style:inside"><li>${line.replace(
|
|
52
|
-
/^\s*-\s+(.*?)$/gm,
|
|
53
|
-
"$1"
|
|
54
|
-
)}</li>`;
|
|
55
|
-
} else if (
|
|
56
|
-
index === arr.length - 1 ||
|
|
57
|
-
!arr[index + 1].match(/^\s*-\s+(.*?)$/gm)
|
|
58
|
-
) {
|
|
59
|
-
return `<li>${line.replace(/^\s*-\s+(.*?)$/gm, "$1")}</li></ul>`;
|
|
60
|
-
} else {
|
|
61
|
-
return `<li>${line.replace(/^\s*-\s+(.*?)$/gm, "$1")}</li>`;
|
|
62
|
-
}
|
|
63
|
-
} else {
|
|
64
|
-
return line;
|
|
65
|
-
}
|
|
66
|
-
})
|
|
67
|
-
.join("\n");
|
|
68
4
|
|
|
69
|
-
|
|
70
|
-
.split("\n")
|
|
71
|
-
.map((line, index, arr) => {
|
|
72
|
-
if (line.match(/^\s*\d+\.\s+(.*?)$/gm)) {
|
|
73
|
-
if (index === 0 || !arr[index - 1].match(/^\s*\d+\.\s+(.*?)$/gm)) {
|
|
74
|
-
return `<ol class="markdown_ordered" style="list-style-type:decimal;"><li>${line.replace(
|
|
75
|
-
/^\s*\d+\.\s+(.*?)$/gm,
|
|
76
|
-
"$1"
|
|
77
|
-
)}</li>`;
|
|
78
|
-
} else if (
|
|
79
|
-
index === arr.length - 1 ||
|
|
80
|
-
!arr[index + 1].match(/^\s*\d+\.\s+(.*?)$/gm)
|
|
81
|
-
) {
|
|
82
|
-
return `<li>${line.replace(/^\s*\d+\.\s+(.*?)$/gm, "$1")}</li></ol>`;
|
|
83
|
-
} else {
|
|
84
|
-
return `<li>${line.replace(/^\s*\d+\.\s+(.*?)$/gm, "$1")}</li>`;
|
|
85
|
-
}
|
|
86
|
-
} else {
|
|
87
|
-
return line;
|
|
88
|
-
}
|
|
89
|
-
})
|
|
90
|
-
.join("\n");
|
|
91
|
-
|
|
92
|
-
return content;
|
|
93
|
-
}
|
|
5
|
+
let worker = new Worker(new URL("./worker.js", import.meta.url));
|
|
94
6
|
|
|
95
7
|
/**
|
|
96
8
|
* @function useRef
|
|
@@ -187,7 +99,7 @@ export class Component {
|
|
|
187
99
|
* @property {Array} snapshots
|
|
188
100
|
* @private
|
|
189
101
|
*/
|
|
190
|
-
|
|
102
|
+
this.snapshots = [];
|
|
191
103
|
/**
|
|
192
104
|
* @property {Object} dom
|
|
193
105
|
* @description Allows you to get reference to DOM element
|
|
@@ -217,8 +129,6 @@ export class Component {
|
|
|
217
129
|
*/
|
|
218
130
|
adapter(options) {
|
|
219
131
|
// allow you to override the compoent logic
|
|
220
|
-
|
|
221
|
-
|
|
222
132
|
}
|
|
223
133
|
init() {
|
|
224
134
|
this.registerComponent();
|
|
@@ -386,7 +296,6 @@ export class Component {
|
|
|
386
296
|
* @param {*} detail
|
|
387
297
|
*/
|
|
388
298
|
this.$_signal_set = (detail) => {
|
|
389
|
-
|
|
390
299
|
setState(detail);
|
|
391
300
|
};
|
|
392
301
|
|
|
@@ -725,7 +634,9 @@ export class Component {
|
|
|
725
634
|
|
|
726
635
|
return {
|
|
727
636
|
cleanup: () => {
|
|
637
|
+
// @ts-ignore
|
|
728
638
|
this.effects[this.name] = this.effects[this.name].filter(
|
|
639
|
+
// @ts-ignore
|
|
729
640
|
(effect) => effect !== effectFn
|
|
730
641
|
);
|
|
731
642
|
}
|
|
@@ -838,143 +749,6 @@ export class Component {
|
|
|
838
749
|
return /^[a-zA-Z0-9-_]+$/.test(className);
|
|
839
750
|
}
|
|
840
751
|
|
|
841
|
-
parseHTML(result) {
|
|
842
|
-
const dom = new DOMParser().parseFromString(result, "text/html");
|
|
843
|
-
const elements = dom.documentElement.querySelectorAll("*");
|
|
844
|
-
|
|
845
|
-
elements.forEach((element) => {
|
|
846
|
-
switch (element.nodeName) {
|
|
847
|
-
case "IMG":
|
|
848
|
-
if (
|
|
849
|
-
!element.hasAttribute("alt") &&
|
|
850
|
-
!document.documentElement.outerHTML
|
|
851
|
-
.trim()
|
|
852
|
-
.includes("<!-- #vader-disable_accessibility -->")
|
|
853
|
-
) {
|
|
854
|
-
throw new SyntaxError(
|
|
855
|
-
`Image: ${element.outerHTML} missing alt attribute`
|
|
856
|
-
);
|
|
857
|
-
} else if (
|
|
858
|
-
element.hasAttribute("alt") &&
|
|
859
|
-
// @ts-ignore
|
|
860
|
-
element.getAttribute("alt").length < 1 &&
|
|
861
|
-
!document.documentElement.outerHTML
|
|
862
|
-
.trim()
|
|
863
|
-
.includes("<!-- #vader-disable_accessibility -->")
|
|
864
|
-
) {
|
|
865
|
-
throw new SyntaxError(
|
|
866
|
-
`Image: ${element.outerHTML} alt attribute cannot be empty`
|
|
867
|
-
);
|
|
868
|
-
} else if (
|
|
869
|
-
(element.hasAttribute("src") &&
|
|
870
|
-
!element.getAttribute("src")?.includes("http")) ||
|
|
871
|
-
(!element.getAttribute("src")?.includes("https") &&
|
|
872
|
-
!document.documentElement.outerHTML
|
|
873
|
-
.trim()
|
|
874
|
-
.includes("<!-- #vader-disable_accessibility -->"))
|
|
875
|
-
) {
|
|
876
|
-
let prevurl = element.getAttribute("src");
|
|
877
|
-
element.setAttribute("aria-hidden", "true");
|
|
878
|
-
element.setAttribute("hidden", "true");
|
|
879
|
-
// if window.lcoation.pathname includes a html file remove it and only use the path
|
|
880
|
-
let url =
|
|
881
|
-
window.location.origin +
|
|
882
|
-
window.location.pathname.replace(/\/[^\/]*$/, "") +
|
|
883
|
-
"/public/" +
|
|
884
|
-
element.getAttribute("src");
|
|
885
|
-
let image = new Image();
|
|
886
|
-
image.src = url;
|
|
887
|
-
image.onerror = () => {
|
|
888
|
-
// @ts-ignore
|
|
889
|
-
element.setAttribute("src", prevurl);
|
|
890
|
-
throw new Error(`Image: ${element.outerHTML} not found`);
|
|
891
|
-
};
|
|
892
|
-
element.setAttribute("src", url);
|
|
893
|
-
|
|
894
|
-
image.onload = () => {
|
|
895
|
-
document.querySelectorAll(`img[src="${url}"]`).forEach((img) => {
|
|
896
|
-
img.setAttribute("src", url);
|
|
897
|
-
img.removeAttribute("aria-hidden");
|
|
898
|
-
img.removeAttribute("hidden");
|
|
899
|
-
});
|
|
900
|
-
};
|
|
901
|
-
}
|
|
902
|
-
break;
|
|
903
|
-
|
|
904
|
-
default:
|
|
905
|
-
if (element.hasAttribute("ref")) {
|
|
906
|
-
// @ts-ignore
|
|
907
|
-
dom[element.getAttribute("ref")] = element;
|
|
908
|
-
}
|
|
909
|
-
if (element.nodeName === "MARKDOWN") {
|
|
910
|
-
element.innerHTML = markdown(
|
|
911
|
-
element.innerHTML.replace(/\\n/g, "\n").trim()
|
|
912
|
-
);
|
|
913
|
-
}
|
|
914
|
-
|
|
915
|
-
if (element.hasAttribute("class")) {
|
|
916
|
-
const allowClassComments = document.documentElement.outerHTML.includes(
|
|
917
|
-
"<!-- #vader-allow_class -->"
|
|
918
|
-
);
|
|
919
|
-
if (!allowClassComments) {
|
|
920
|
-
console.warn(
|
|
921
|
-
"you can disable class errors using, <!-- #vader-allow_class -->"
|
|
922
|
-
);
|
|
923
|
-
throw new Error(
|
|
924
|
-
"class attribute is not allowed, please use className instead"
|
|
925
|
-
);
|
|
926
|
-
}
|
|
927
|
-
} else if (element.hasAttribute("className")) {
|
|
928
|
-
// @ts-ignore
|
|
929
|
-
element.setAttribute("class", element.getAttribute("className"));
|
|
930
|
-
element.removeAttribute("className");
|
|
931
|
-
}
|
|
932
|
-
|
|
933
|
-
if (
|
|
934
|
-
element.hasAttribute("href") &&
|
|
935
|
-
// @ts-ignore
|
|
936
|
-
element.getAttribute("href").startsWith("/") &&
|
|
937
|
-
!document.documentElement.outerHTML
|
|
938
|
-
.trim()
|
|
939
|
-
.includes("<!-- #vader-disable_relative-paths -->")
|
|
940
|
-
) {
|
|
941
|
-
element.setAttribute(
|
|
942
|
-
"href",
|
|
943
|
-
// @ts-ignore
|
|
944
|
-
`#/${element.getAttribute("href").replace("/", "")}`
|
|
945
|
-
);
|
|
946
|
-
}
|
|
947
|
-
|
|
948
|
-
if (
|
|
949
|
-
element.hasAttribute("src") &&
|
|
950
|
-
// @ts-ignore
|
|
951
|
-
!element.getAttribute("src").includes("http") &&
|
|
952
|
-
// @ts-ignore
|
|
953
|
-
!element.getAttribute("src").includes("https") &&
|
|
954
|
-
!document.documentElement.outerHTML.includes(
|
|
955
|
-
`<!-- #vader-disable_relative-paths -->`
|
|
956
|
-
)
|
|
957
|
-
) {
|
|
958
|
-
element.setAttribute(
|
|
959
|
-
"src",
|
|
960
|
-
// @ts-ignore
|
|
961
|
-
`./public/${element.getAttribute("src")}`
|
|
962
|
-
);
|
|
963
|
-
}
|
|
964
|
-
break;
|
|
965
|
-
}
|
|
966
|
-
});
|
|
967
|
-
|
|
968
|
-
result = dom.body.innerHTML;
|
|
969
|
-
|
|
970
|
-
this.Componentcontent = result;
|
|
971
|
-
|
|
972
|
-
if (!result.includes("<div data-component")) {
|
|
973
|
-
result = `<div data-component="${this.name}">${result}</div>`;
|
|
974
|
-
}
|
|
975
|
-
return markdown(result.replace(/\\n/g, "\n").trim());
|
|
976
|
-
}
|
|
977
|
-
|
|
978
752
|
/**
|
|
979
753
|
* The `html` method generates and processes HTML content for a component, performing various validations and tasks.
|
|
980
754
|
*
|
|
@@ -1024,9 +798,9 @@ export class Component {
|
|
|
1024
798
|
|
|
1025
799
|
html(strings, ...args) {
|
|
1026
800
|
// @ts-ignore
|
|
1027
|
-
let
|
|
801
|
+
let timer = setInterval(() => {
|
|
1028
802
|
if (document.querySelector(`[data-component="${this.name}"]`)) {
|
|
1029
|
-
clearInterval(
|
|
803
|
+
clearInterval(timer);
|
|
1030
804
|
this.componentMounted = true;
|
|
1031
805
|
|
|
1032
806
|
document
|
|
@@ -1045,95 +819,92 @@ export class Component {
|
|
|
1045
819
|
script.setAttribute("type", "text/javascript");
|
|
1046
820
|
script.setAttribute(`data-component-script`, this.name);
|
|
1047
821
|
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
822
|
+
worker.postMessage({
|
|
823
|
+
strings,
|
|
824
|
+
args,
|
|
825
|
+
location:
|
|
826
|
+
window.location.origin +
|
|
827
|
+
window.location.pathname.replace(/\/[^\/]*$/, "") +
|
|
828
|
+
"/public/",
|
|
829
|
+
name: this.name
|
|
830
|
+
});
|
|
831
|
+
let promise = new Promise((resolve, reject) => {
|
|
832
|
+
worker.onmessage = (e) => {
|
|
833
|
+
if (e.data.error) {
|
|
834
|
+
throw new Error(e.data.error);
|
|
835
|
+
}
|
|
836
|
+
const dom = this.dom; // Assuming this.dom is an object
|
|
837
|
+
let js = e.data.js;
|
|
838
|
+
let template = e.data.template;
|
|
839
|
+
// Bind the component's context
|
|
840
|
+
|
|
841
|
+
const useState = this.useState.bind(this); // Bind the component's context
|
|
842
|
+
const useEffect = this.useEffect.bind(this); // Bind the component's context
|
|
843
|
+
const useReducer = this.useReducer.bind(this); // Bind the component's context
|
|
844
|
+
const useAuth = this.useAuth.bind(this); // Bind the component's context
|
|
845
|
+
const useSyncStore = this.useSyncStore.bind(this); // Bind the component's context
|
|
846
|
+
const signal = this.signal.bind(this); // Bind the component's context
|
|
847
|
+
const $Function = this.$Function.bind(this); // Bind the component's context
|
|
848
|
+
let states = this.states;
|
|
849
|
+
const useRef = this.useRef.bind(this); // Bind the component's context
|
|
850
|
+
new Function(
|
|
851
|
+
"useState",
|
|
852
|
+
"useEffect",
|
|
853
|
+
"useAuth",
|
|
854
|
+
"useReducer",
|
|
855
|
+
"useSyncStore",
|
|
856
|
+
"signal",
|
|
857
|
+
"$Function",
|
|
858
|
+
"dom",
|
|
859
|
+
"render",
|
|
860
|
+
"states",
|
|
861
|
+
"useRef",
|
|
862
|
+
js
|
|
863
|
+
)(
|
|
864
|
+
useState,
|
|
865
|
+
useEffect,
|
|
866
|
+
useAuth,
|
|
867
|
+
useReducer,
|
|
868
|
+
useSyncStore,
|
|
869
|
+
signal,
|
|
870
|
+
$Function,
|
|
871
|
+
this.dom,
|
|
872
|
+
this.render,
|
|
873
|
+
this.states,
|
|
874
|
+
useRef
|
|
875
|
+
);
|
|
1069
876
|
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
const signal = this.signal.bind(this); // Bind the component's context
|
|
1076
|
-
const rf = this.$Function.bind(this); // Bind the component's context
|
|
1077
|
-
let states = this.states;
|
|
1078
|
-
const useRef = this.useRef.bind(this); // Bind the component's context
|
|
1079
|
-
new Function(
|
|
877
|
+
resolve(
|
|
878
|
+
handletemplate( new Function(
|
|
879
|
+
"useRef",
|
|
880
|
+
"states",
|
|
881
|
+
"signal",
|
|
1080
882
|
"useState",
|
|
1081
|
-
"useEffect",
|
|
1082
|
-
"useAuth",
|
|
1083
883
|
"useReducer",
|
|
884
|
+
"useAuth",
|
|
1084
885
|
"useSyncStore",
|
|
1085
|
-
"signal",
|
|
1086
|
-
"rf",
|
|
1087
|
-
"dom",
|
|
1088
|
-
"render",
|
|
1089
|
-
"states",
|
|
1090
886
|
"useRef",
|
|
1091
|
-
|
|
887
|
+
"$Function",
|
|
888
|
+
"return" + "`" + template + "`"
|
|
1092
889
|
)(
|
|
890
|
+
useRef,
|
|
891
|
+
states,
|
|
892
|
+
signal,
|
|
1093
893
|
useState,
|
|
1094
|
-
useEffect,
|
|
1095
|
-
useAuth,
|
|
1096
894
|
useReducer,
|
|
895
|
+
useAuth,
|
|
1097
896
|
useSyncStore,
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
this.render,
|
|
1102
|
-
this.states,
|
|
1103
|
-
useRef
|
|
1104
|
-
);
|
|
1105
|
-
|
|
1106
|
-
resolve(
|
|
1107
|
-
new Function("useRef", "states", "return" + "`" + template + "`")(
|
|
1108
|
-
useRef,
|
|
1109
|
-
states
|
|
1110
|
-
)
|
|
1111
|
-
);
|
|
1112
|
-
};
|
|
1113
|
-
worker.onerror = (e) => {
|
|
1114
|
-
reject(e);
|
|
1115
|
-
};
|
|
1116
|
-
});
|
|
1117
|
-
// @ts-ignore
|
|
1118
|
-
return promise;
|
|
1119
|
-
} else {
|
|
1120
|
-
let result = "";
|
|
1121
|
-
for (let i = 0; i < strings.length; i++) {
|
|
1122
|
-
result += strings[i];
|
|
1123
|
-
if (i < args.length) {
|
|
1124
|
-
result += args[i];
|
|
1125
|
-
}
|
|
1126
|
-
}
|
|
1127
|
-
result = new Function("useRef", `return \`${result}\``)(useRef);
|
|
1128
|
-
|
|
1129
|
-
if (!result.trim().startsWith("<body>")) {
|
|
1130
|
-
console.warn(
|
|
1131
|
-
"You should wrap your html in a body tag, vader may not grab all html!"
|
|
897
|
+
useRef,
|
|
898
|
+
$Function
|
|
899
|
+
))
|
|
1132
900
|
);
|
|
1133
|
-
}
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
901
|
+
};
|
|
902
|
+
worker.onerror = (e) => {
|
|
903
|
+
reject(e);
|
|
904
|
+
};
|
|
905
|
+
});
|
|
906
|
+
// @ts-ignore
|
|
907
|
+
return promise;
|
|
1137
908
|
}
|
|
1138
909
|
// write types to ensure it returns a string
|
|
1139
910
|
/**
|
|
@@ -1200,7 +971,7 @@ const Vader = {
|
|
|
1200
971
|
* @returns {Component}
|
|
1201
972
|
*/
|
|
1202
973
|
export const component = () => {
|
|
1203
|
-
return new Component()
|
|
974
|
+
return new Component();
|
|
1204
975
|
};
|
|
1205
976
|
|
|
1206
977
|
/**
|
|
@@ -1242,7 +1013,6 @@ async function handletemplate(data) {
|
|
|
1242
1013
|
filedata = new Function(`return \`${filedata}\`;`)();
|
|
1243
1014
|
let newdom = new DOMParser().parseFromString(filedata, "text/html");
|
|
1244
1015
|
|
|
1245
|
-
|
|
1246
1016
|
newdom.querySelectorAll("include").forEach((el) => {
|
|
1247
1017
|
el.remove();
|
|
1248
1018
|
});
|
|
@@ -1254,22 +1024,29 @@ async function handletemplate(data) {
|
|
|
1254
1024
|
if (el.attributes.length > 0) {
|
|
1255
1025
|
for (var i = 0; i < el.attributes.length; i++) {
|
|
1256
1026
|
// @ts-ignore
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1027
|
+
let t = "{{" + el.attributes[i].name + "}}";
|
|
1028
|
+
if (newdom.body.innerHTML.includes(t)) {
|
|
1029
|
+
// @ts-ignore
|
|
1030
|
+
newdom.body.innerHTML = newdom.body.innerHTML.replaceAll(
|
|
1031
|
+
t,
|
|
1032
|
+
el.attributes[i].value
|
|
1033
|
+
);
|
|
1034
|
+
}
|
|
1261
1035
|
}
|
|
1262
1036
|
}
|
|
1263
1037
|
if (el.children.length > 0 && newdom.body.querySelector("slot")) {
|
|
1264
1038
|
for (var i = 0; i < el.children.length; i++) {
|
|
1265
1039
|
let slots = newdom.body.querySelectorAll("slot");
|
|
1266
1040
|
slots.forEach((slot) => {
|
|
1267
|
-
|
|
1268
1041
|
let id = slot.getAttribute("id");
|
|
1269
|
-
|
|
1270
|
-
if
|
|
1271
|
-
|
|
1272
|
-
|
|
1042
|
+
|
|
1043
|
+
if (
|
|
1044
|
+
(el.hasAttribute("key") && el.getAttribute("key") === id) ||
|
|
1045
|
+
(!el.hasAttribute("key") && el.nodeName === id)
|
|
1046
|
+
) {
|
|
1047
|
+
if (el.children[i].innerHTML.length > 0) {
|
|
1048
|
+
slot.outerHTML = el.children[i].innerHTML;
|
|
1049
|
+
}
|
|
1273
1050
|
}
|
|
1274
1051
|
});
|
|
1275
1052
|
}
|
|
@@ -1312,8 +1089,10 @@ export const include = async (path) => {
|
|
|
1312
1089
|
) {
|
|
1313
1090
|
path = "/src/" + path;
|
|
1314
1091
|
}
|
|
1092
|
+
// @ts-ignore
|
|
1315
1093
|
if (cache[path]) {
|
|
1316
|
-
|
|
1094
|
+
// @ts-ignore
|
|
1095
|
+
return cache[path];
|
|
1317
1096
|
} else {
|
|
1318
1097
|
return fetch(`./${path}`)
|
|
1319
1098
|
.then((res) => {
|
|
@@ -1323,13 +1102,14 @@ export const include = async (path) => {
|
|
|
1323
1102
|
return res.text();
|
|
1324
1103
|
})
|
|
1325
1104
|
.then(async (data) => {
|
|
1105
|
+
// @ts-ignore
|
|
1326
1106
|
cache[path] = data;
|
|
1327
1107
|
|
|
1328
|
-
|
|
1108
|
+
|
|
1329
1109
|
|
|
1330
1110
|
return data;
|
|
1331
1111
|
});
|
|
1332
1112
|
}
|
|
1333
1113
|
};
|
|
1334
1114
|
|
|
1335
|
-
export default Vader
|
|
1115
|
+
export default Vader
|
package/worker-min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
onmessage=e=>{let
|
|
1
|
+
onmessage=e=>{let l=Date.now(),a=e.data.strings,t=e.data.args,s="",r=e.data.location.split("/").slice(0,-1).join("/"),c="";for(let e=0;e<a.length;e++)c+=a[e],e<t.length&&(c+=t[e]);let i=c.match(/--([^>]*)--/gs);if(i)for(;i.length;){let e=i.pop();c=c.replace(e,"")}if(c=c.replace(/(#+)([^<>\n]*)(?![^<]*>)(?![^{]*})/g,((e,l,a)=>{let t=l.length;return`<h${t} class="markdown_heading">${a}</h${t}>`})),c=c.replace(/\*\*(.*?)\*\*/g,((e,l)=>`<b class="markdown_bold">${l}</b>`)),c=c.replace(/\*(.*?)\*/g,((e,l)=>`<i class="markdown_italic">${l}</i>`)),c=c.replace(/`(.*?)`/g,((e,l)=>`<code>${l}</code>`)),c=c.replace(/\[([^\]]+)\]\(([^)]+)\)/g,((e,l,a)=>`<a class="markdown_link" href="${a}">${l}</a>`)),c=c.replace(/!\[([^\]]+)\]\(([^)]+)\)/g,((e,l,a)=>`<img class="markdown_image" src="${a}" alt="${l}" />`)),c.split("\n").forEach(((e,l,a)=>{e.match(/^\s*-\s+(.*?)$/gm)&&(c=0!==l&&a[l-1].match(/^\s*-\s+(.*?)$/gm)?l!==a.length-1&&a[l+1].match(/^\s*-\s+(.*?)$/gm)?c.replace(e,`<li>${e.replace(/^\s*-\s+(.*?)$/gm,"$1")}</li>`):c.replace(e,`<li>${e.replace(/^\s*-\s+(.*?)$/gm,"$1")}</li></ul>`):c.replace(e,`<ul class="markdown_unordered" style="list-style-type:disc;list-style:inside"><li>${e.replace(/^\s*-\s+(.*?)$/gm,"$1")}</li>`))})),c.split("\n").forEach(((e,l,a)=>{e.match(/^\s*\d+\.\s+(.*?)$/gm)&&(c=0!==l&&a[l-1].match(/^\s*\d+\.\s+(.*?)$/gm)?l!==a.length-1&&a[l+1].match(/^\s*\d+\.\s+(.*?)$/gm)?c.replace(e,`<li>${e.replace(/^\s*\d+\.\s+(.*?)$/gm,"$1")}</li>`):c.replace(e,`<li>${e.replace(/^\s*\d+\.\s+(.*?)$/gm,"$1")}</li></ol>`):c.replace(e,`<ol class="markdown_ordered" style="list-style-type:decimal;"><li>${e.replace(/^\s*\d+\.\s+(.*?)$/gm,"$1")}</li>`))})),c=c.replace(/^\s*-\s+(.*?)$/gm,((e,l)=>`<li class="markdown_list_item">${l}</li>`)),c=c.replace(/^\s*---\s*$/gm,'<hr class="markdown_horizontal" />'),c=c.replace(/^\s*> (.*)$/gm,((e,l)=>`<blockquote class="markdown_blockquote">${l}</blockquote>`)),c=c.replace(/((?: *\|.*?)+)\n((?: *\|.*?)+)/gm,((e,l,a)=>{const t=l.split("|").slice(1,-1),s=a.split("|").slice(1,-1);let r='<table class="markdown_table">';return r+='<thead class="markdown_table_head"><tr class="markdown_table_row">',t.forEach((e=>{r+=`<th class="markdown_table_header_cell">${e}</th>`})),r+='</tr></thead><tbody class="markdown_table_body"><tr class="markdown_table_row">',s.forEach((e=>{r+=`<td class="markdown_table_body_cell">${e}</td>`})),r+="</tr></tbody></table>",r})),!c.includes("<body>"))throw new Error(`Vader Error: You must enclose your html in a body tag for all components. \n\n${c}`);c=c.replace(/classname/g,"class");let o=c.match(/<img([^>]*)>/g);if(o)for(let l=0;l<o.length;l++){let a=o[l],t=a.match(/src="([^"]*)"/);if(!a.match(/alt="([^"]*)"/)&&!c.includes("\x3c!-- #vader-disable_accessibility --\x3e"))throw new Error(`Vader Error: You must include an alt attribute in the image tag \n\n${a} of class ${e.data.name}. `);t&&t.forEach((l=>{if(l.includes("http")||c.includes("\x3c!-- #vader-disable_relative-paths --\x3e")){if(!l.includes("http")&&l.startsWith(".")&&!c.includes("\x3c!-- #vader-disable_relative-paths --\x3e"))throw new Error(`Vader Error: You cannot use absolute paths since relative paths are not disabled in ${e.data.file}. Use relative paths instead. \n\n${l}`)}else c=c.replace(`src="${l}"`,`src="${r}/${l}"`)}))}let n=c.match(/href="([^"]*)"/g);if(n)for(;n.length;){let l=n.pop();if(l=l.replace('href="',"").replace('"',""),l.includes("http")||c.includes("\x3c!-- #vader-disable_relative-paths --\x3e")){if(!l.includes("http")&&l.startsWith(".")&&!c.includes("\x3c!-- #vader-disable_relative-paths --\x3e"))throw new Error(`Vader Error: You cannot use absolute paths since relative paths are not disabled in ${e.data.file}. Use relative paths instead. \n\n${l}`)}else c=c.replace(`href="${l}"`,`href="#${l}"`)}let d=Date.now()-l,p=!1;(r.includes("localhost")||r.includes("127.0.0.1")&&!p)&&(p=!0,c+=`\${console.log('%c${e.data.name} component rendered in ${d}ms')}`);const h=c.split("<script>");h&&h.forEach(((e,l)=>{if(0===l)c=e;else{if(e.includes("// <![CDATA[ <-- For SVG support"))return;let l=e.split("<\/script>")[0];s+=l}}));let m=c.match(/(\$\(.*?\))/gs);if(m)for(;m.length;){let e=m.pop();c=c.replace(e,`\${${e.replace("$(","").replace(")","")}}`)}let $=c.match(/@title '([^>]*)';/);if($){let e=`{document.title = "${$[1]}", ""}`;c=c.replace($[0],"$"+e)}let g=c.match(/@style{([^>]*)};/gs);if(g)for(let e=0;e<g.length;e++){if(!g[e].includes("style"))continue;let l=g[e];console.log(l);let a=l.replace("@style{","").replace("};","");a=a.replaceAll(",",";"),a=a.replaceAll(/[A-Z]/g,(e=>`-${e.toLowerCase()}`)),a=a.replaceAll(/'/g," "),c=c.replace(l,`style="${a}"`)}let u=c.match(/@stylesheet{([^>]*)};/);if(u){let e=u[1].replaceAll(" ","");e=e.replaceAll(",",";"),e=e.replaceAll(/[A-Z]/g,(e=>`-${e.toLowerCase()}`)),e=e.replaceAll(/'/g," "),c=c.replace(u[0],`<style>${e}</style>`)}postMessage({template:`<div data-component=${e.data.name}>${c}</div>`,js:s||""})};
|