tkeron 0.0.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.
Files changed (183) hide show
  1. package/.github/workflows/CICD.yml +43 -0
  2. package/LICENSE +21 -0
  3. package/README.md +76 -0
  4. package/assets/tkexample.gif +0 -0
  5. package/changelog.md +8 -0
  6. package/dist/base64.d.ts +2 -0
  7. package/dist/base64.js +7 -0
  8. package/dist/build.d.ts +10 -0
  9. package/dist/build.js +102 -0
  10. package/dist/buildFront.d.ts +10 -0
  11. package/dist/buildFront.js +27 -0
  12. package/dist/buildLoaders.d.ts +13 -0
  13. package/dist/buildLoaders.js +23 -0
  14. package/dist/bundleTs.d.ts +1 -0
  15. package/dist/bundleTs.js +35 -0
  16. package/dist/cicd.d.ts +1 -0
  17. package/dist/cicd.js +8 -0
  18. package/dist/cmdBuild.d.ts +1 -0
  19. package/dist/cmdBuild.js +11 -0
  20. package/dist/cmdDev.d.ts +7 -0
  21. package/dist/cmdDev.js +63 -0
  22. package/dist/cmdGenerate.d.ts +1 -0
  23. package/dist/cmdGenerate.js +41 -0
  24. package/dist/cmdInit.d.ts +1 -0
  25. package/dist/cmdInit.js +36 -0
  26. package/dist/copyDir.d.ts +1 -0
  27. package/dist/copyDir.js +18 -0
  28. package/dist/createModFile.d.ts +1 -0
  29. package/dist/createModFile.js +14 -0
  30. package/dist/createTsConfigFile.d.ts +1 -0
  31. package/dist/createTsConfigFile.js +39 -0
  32. package/dist/eventEmitter.d.ts +5 -0
  33. package/dist/eventEmitter.js +29 -0
  34. package/dist/fileExist.d.ts +1 -0
  35. package/dist/fileExist.js +6 -0
  36. package/dist/generateItems.d.ts +11 -0
  37. package/dist/generateItems.js +16 -0
  38. package/dist/getDocument.d.ts +11 -0
  39. package/dist/getDocument.js +37 -0
  40. package/dist/getFilesRecursive.d.ts +9 -0
  41. package/dist/getFilesRecursive.js +53 -0
  42. package/dist/getOptions.d.ts +8 -0
  43. package/dist/getOptions.js +28 -0
  44. package/dist/getType.d.ts +1 -0
  45. package/dist/getType.js +5 -0
  46. package/dist/getVersion.d.ts +2 -0
  47. package/dist/getVersion.js +16 -0
  48. package/dist/index.d.ts +2 -0
  49. package/dist/index.js +5 -0
  50. package/dist/injectCode.d.ts +1 -0
  51. package/dist/injectCode.js +7 -0
  52. package/dist/injectTsFile.d.ts +8 -0
  53. package/dist/injectTsFile.js +22 -0
  54. package/dist/jsDom/crypto.d.ts +3 -0
  55. package/dist/jsDom/crypto.js +22 -0
  56. package/dist/jsDom/errors.d.ts +3 -0
  57. package/dist/jsDom/errors.js +30 -0
  58. package/dist/jsDom/joinScripts.d.ts +1 -0
  59. package/dist/jsDom/joinScripts.js +25 -0
  60. package/dist/jsDom/logs.d.ts +1 -0
  61. package/dist/jsDom/logs.js +10 -0
  62. package/dist/jsDom/writeLogElement.d.ts +1 -0
  63. package/dist/jsDom/writeLogElement.js +49 -0
  64. package/dist/libFiles.ts.d.ts +1 -0
  65. package/dist/libFiles.ts.js +14 -0
  66. package/dist/main.d.ts +1 -0
  67. package/dist/main.js +58 -0
  68. package/dist/mod.d.ts +3 -0
  69. package/dist/mod.js +9 -0
  70. package/dist/pathToUrlResource.d.ts +4 -0
  71. package/dist/pathToUrlResource.js +11 -0
  72. package/dist/random.d.ts +3 -0
  73. package/dist/random.js +31 -0
  74. package/dist/range.d.ts +1 -0
  75. package/dist/range.js +5 -0
  76. package/dist/readJsonFile.d.ts +1 -0
  77. package/dist/readJsonFile.js +20 -0
  78. package/dist/rectReady.d.ts +1 -0
  79. package/dist/rectReady.js +33 -0
  80. package/dist/rnd.d.ts +2 -0
  81. package/dist/rnd.js +11 -0
  82. package/dist/rnda.d.ts +1 -0
  83. package/dist/rnda.js +8 -0
  84. package/dist/runOncePerTime.d.ts +1 -0
  85. package/dist/runOncePerTime.js +17 -0
  86. package/dist/serializeDocument.d.ts +1 -0
  87. package/dist/serializeDocument.js +5 -0
  88. package/dist/simpleHotRestart.d.ts +1 -0
  89. package/dist/simpleHotRestart.js +17 -0
  90. package/dist/test/buildLoaders.test.d.ts +1 -0
  91. package/dist/test/buildLoaders.test.js +27 -0
  92. package/dist/test/bundleTs.test.d.ts +1 -0
  93. package/dist/test/bundleTs.test.js +94 -0
  94. package/dist/test/errors.test.d.ts +1 -0
  95. package/dist/test/errors.test.js +29 -0
  96. package/dist/test/fileExist.test.d.ts +1 -0
  97. package/dist/test/fileExist.test.js +26 -0
  98. package/dist/test/getFilesRecursive.test.d.ts +1 -0
  99. package/dist/test/getFilesRecursive.test.js +66 -0
  100. package/dist/test/getRandomValues.test.d.ts +1 -0
  101. package/dist/test/getRandomValues.test.js +35 -0
  102. package/dist/test/logs.test.d.ts +1 -0
  103. package/dist/test/logs.test.js +20 -0
  104. package/dist/test/main.test.d.ts +1 -0
  105. package/dist/test/main.test.js +15 -0
  106. package/dist/test/pathToUrlResource.test.d.ts +1 -0
  107. package/dist/test/pathToUrlResource.test.js +14 -0
  108. package/dist/test/runOncePerTime.test.d.ts +1 -0
  109. package/dist/test/runOncePerTime.test.js +17 -0
  110. package/dist/tk.d.ts +2 -0
  111. package/dist/tk.js +5 -0
  112. package/dist/tkeron.d.ts +44 -0
  113. package/dist/tkeron.js +258 -0
  114. package/dist/wait.d.ts +1 -0
  115. package/dist/wait.js +5 -0
  116. package/distFiles/eventEmitter.ts +29 -0
  117. package/distFiles/getType.ts +2 -0
  118. package/distFiles/random.ts +26 -0
  119. package/distFiles/range.ts +2 -0
  120. package/distFiles/rectReady.ts +27 -0
  121. package/distFiles/rnda.ts +5 -0
  122. package/distFiles/runOncePerTime.ts +12 -0
  123. package/distFiles/simpleHotRestart.ts +18 -0
  124. package/distFiles/tkeron.ts +317 -0
  125. package/package.json +47 -0
  126. package/src/base64.ts +3 -0
  127. package/src/build.ts +112 -0
  128. package/src/buildFront.ts +40 -0
  129. package/src/buildLoaders.ts +23 -0
  130. package/src/bundleTs.ts +32 -0
  131. package/src/cicd.ts +8 -0
  132. package/src/cmdBuild.ts +9 -0
  133. package/src/cmdDev.ts +68 -0
  134. package/src/cmdGenerate.ts +41 -0
  135. package/src/cmdInit.ts +37 -0
  136. package/src/copyDir.ts +16 -0
  137. package/src/createModFile.ts +15 -0
  138. package/src/createTsConfigFile.ts +37 -0
  139. package/src/eventEmitter.ts +29 -0
  140. package/src/fileExist.ts +4 -0
  141. package/src/generateItems.ts +16 -0
  142. package/src/getDocument.ts +40 -0
  143. package/src/getFilesRecursive.ts +49 -0
  144. package/src/getOptions.ts +27 -0
  145. package/src/getType.ts +2 -0
  146. package/src/getVersion.ts +14 -0
  147. package/src/index.ts +5 -0
  148. package/src/injectCode.ts +9 -0
  149. package/src/injectTsFile.ts +28 -0
  150. package/src/jsDom/crypto.ts +22 -0
  151. package/src/jsDom/errors.ts +35 -0
  152. package/src/jsDom/joinScripts.ts +22 -0
  153. package/src/jsDom/logs.ts +7 -0
  154. package/src/jsDom/writeLogElement.ts +45 -0
  155. package/src/libFiles.ts.ts +16 -0
  156. package/src/main.ts +67 -0
  157. package/src/mod.ts +7 -0
  158. package/src/pathToUrlResource.ts +10 -0
  159. package/src/random.ts +26 -0
  160. package/src/range.ts +2 -0
  161. package/src/readJsonFile.ts +16 -0
  162. package/src/rectReady.ts +27 -0
  163. package/src/rnd.ts +5 -0
  164. package/src/rnda.ts +5 -0
  165. package/src/runOncePerTime.ts +12 -0
  166. package/src/serializeDocument.ts +7 -0
  167. package/src/simpleHotRestart.ts +18 -0
  168. package/src/test/buildLoaders.test.ts +31 -0
  169. package/src/test/bundleTs.test.ts +98 -0
  170. package/src/test/errors.test.ts +31 -0
  171. package/src/test/fileExist.test.ts +29 -0
  172. package/src/test/getFilesRecursive.test.ts +67 -0
  173. package/src/test/getRandomValues.test.ts +34 -0
  174. package/src/test/logs.test.ts +20 -0
  175. package/src/test/main.test.ts +16 -0
  176. package/src/test/pathToUrlResource.test.ts +18 -0
  177. package/src/test/runOncePerTime.test.ts +16 -0
  178. package/src/tk.ts +5 -0
  179. package/src/tkeron.ts +317 -0
  180. package/src/wait.ts +2 -0
  181. package/tkeron.json +4 -0
  182. package/tkeron.tsconfig.json +12 -0
  183. package/tsconfig.json +29 -0
package/src/tkeron.ts ADDED
@@ -0,0 +1,317 @@
1
+
2
+ export interface tkeronOptions {
3
+ type?: string;
4
+ value?: string;
5
+ }
6
+
7
+ export interface Component {
8
+ readonly id: string;
9
+
10
+ value: string;
11
+ setValue(v: string): Component;
12
+
13
+ readonly parent: Component | null;
14
+ _setParent(c: Component | null): Component;
15
+ childs: Component[];
16
+ add(...c: Component[]): Component;
17
+ remove(c: Component): Component;
18
+
19
+ renderIn(query: string | HTMLElement): Component;
20
+ appendIn(query: string | HTMLElement): Component;
21
+
22
+ getHTMLElement(f: (el: HTMLElement) => void): Component;
23
+ getHTML(): string;
24
+
25
+ readonly classList: string[];
26
+ addClass(cls: string): Component;
27
+ removeClass(cls: string): Component;
28
+
29
+ readonly attributes: any;
30
+ addAttribute(attr: string, value: string): Component;
31
+ removeAttribute(attr: string): Component;
32
+
33
+ getElement(): HTMLElement;
34
+ setElement(el: HTMLElement): Component;
35
+
36
+ css(css: string): Component;
37
+ getCss(): string;
38
+
39
+ on(f: (_com: Component, _el: HTMLElement) => void): Component;
40
+
41
+ onRender(fn: () => void): Component;
42
+ onAppend(fn: () => void): Component;
43
+
44
+ send(...msg: any[]): Component;
45
+ onMessage(fn: (...msg: any[]) => void): Component;
46
+ }
47
+
48
+ const enum event {
49
+ render,
50
+ append,
51
+ msg
52
+ }
53
+ const handlers: any = {};
54
+ const addHandler = (id: string, event: event, fn: (...args: any[]) => void) => {
55
+ if (typeof handlers[event] === "undefined") handlers[event] = {} as any;
56
+ if (typeof handlers[event][id] === "undefined") handlers[event][id] = [] as any[];
57
+ handlers[event][id].push(fn);
58
+ };
59
+ const runHandlers = (id: string, event: event, ...args: any[]) => {
60
+ if (typeof handlers[event] === "undefined") return;
61
+ if (typeof handlers[event][id] === "undefined") return;
62
+ handlers[event][id].forEach((fn: (...args: any[]) => void) => fn(...args));
63
+ };
64
+
65
+ const toHexString = (bytes: Uint8Array): string => bytes.reduce((str, byte) => str + byte.toString(16).padStart(2, "0"), "");
66
+ const rnds = (n: number): string => toHexString(crypto.getRandomValues(new Uint8Array(n))).slice(0, n);
67
+
68
+ const IDs: string[] = [];
69
+ const getID = (): string => {
70
+ const id = "tk_" + rnds(20);
71
+ //@ts-ignore
72
+ if (IDs.includes(id)) {
73
+ return getID();
74
+ }
75
+ return id;
76
+ };
77
+
78
+ export const tkeron = (opt?: tkeronOptions | string, ...classes: string[]): Component => {
79
+ if (typeof opt === "string") {
80
+ classes.push(opt);
81
+ opt = { type: "div" };
82
+ }
83
+ if (!opt) opt = { type: "div" };
84
+ const valueProp: boolean = [
85
+ "input",
86
+ "textarea"
87
+ ].some(n => {
88
+ if ("type" in (opt as any)) return (opt as any).type === n;
89
+ });
90
+ let el = document.createElement(opt.type || "div");
91
+ const priv = {
92
+ parent: {} as Component | null,
93
+ childs: [] as Component[],
94
+ css: ""
95
+ };
96
+ priv.parent = null;
97
+ const com: Component = {
98
+ id: getID(),
99
+ parent: priv.parent,
100
+ _setParent: (c: Component | null) => {
101
+ priv.parent = c;
102
+ return com;
103
+ },
104
+ value: "",
105
+ setValue: (v: string) => {
106
+ com.value = v;
107
+ return com;
108
+ },
109
+ childs: priv.childs,
110
+ add: (...c: Component[]) => {
111
+ c.forEach(_ => {
112
+ _._setParent(com);
113
+ priv.childs.push(_);
114
+ _.getHTMLElement((ele) => {
115
+ el.appendChild(ele);
116
+ });
117
+ });
118
+ return com;
119
+ },
120
+ remove: (c: Component) => {
121
+ c._setParent(null);
122
+ priv.childs = priv.childs.filter(_c => {
123
+ if (_c.id === c.id) return false;
124
+ return true;
125
+ });
126
+ c.getHTMLElement(_el => {
127
+ el.removeChild(_el);
128
+ });
129
+ return com;
130
+ },
131
+ renderIn: (query: string | HTMLElement) => {
132
+ if (typeof query === "string") {
133
+ const domel = document.querySelector(query);
134
+ if (!domel) {
135
+ document.addEventListener("DOMContentLoaded", () => {
136
+ com.renderIn(query);
137
+ });
138
+ return com;
139
+ }
140
+ domel.innerHTML = "";
141
+ domel.appendChild(el);
142
+ runHandlers(com.id, event.render);
143
+ return com;
144
+ }
145
+ (query as HTMLElement).innerHTML = "";
146
+ (query as HTMLElement).appendChild(el);
147
+ runHandlers(com.id, event.render);
148
+ return com;
149
+ },
150
+ appendIn: (query: string | HTMLElement) => {
151
+ if (typeof query === "string") {
152
+ const domel = document.querySelector(query);
153
+ if (!domel) {
154
+ document.addEventListener("DOMContentLoaded", () => {
155
+ com.appendIn(query);
156
+ });
157
+ return com;
158
+ }
159
+ domel.appendChild(el);
160
+ runHandlers(com.id, event.append);
161
+ return com;
162
+ }
163
+ (query as HTMLElement).appendChild(el);
164
+ runHandlers(com.id, event.append);
165
+ return com;
166
+ },
167
+ getHTMLElement: (f) => {
168
+ f(el);
169
+ return com;
170
+ },
171
+ getHTML: () => {
172
+ return el.outerHTML;
173
+ },
174
+ classList: [],
175
+ addClass: (cls: string) => {
176
+ el.classList.add(cls);
177
+ return com;
178
+ },
179
+ removeClass: (cls: string) => {
180
+ el.classList.remove(cls);
181
+ return com;
182
+ },
183
+ attributes: {},
184
+ addAttribute: (attr: string, value: string) => {
185
+ el.setAttribute(attr, value);
186
+ return com;
187
+ },
188
+ removeAttribute: (attr: string) => {
189
+ el.removeAttribute(attr);
190
+ return com;
191
+ },
192
+ getElement: () => {
193
+ return el;
194
+ },
195
+ setElement: (ele: HTMLElement) => {
196
+ if (!ele) throw Error("Component.setElement: Element must not be null.");
197
+ el = ele;
198
+ return com;
199
+ },
200
+ css: (css: string) => {
201
+ priv.css = css;
202
+ tkeron.css(com.id, `#${com.id} {${css}}`);
203
+ com.addAttribute("id", com.id);
204
+ return com;
205
+ },
206
+ getCss: () => priv.css,
207
+ on: (f) => {
208
+ f(com, el);
209
+ return com;
210
+ },
211
+ onRender: (fn) => {
212
+ addHandler(com.id, event.render, fn);
213
+ return com;
214
+ },
215
+ onAppend: (fn) => {
216
+ addHandler(com.id, event.append, fn);
217
+ return com;
218
+ },
219
+ send: (...msg: any[]) => {
220
+ runHandlers(com.id, event.msg, ...msg);
221
+ return com;
222
+ },
223
+ onMessage: (fn) => {
224
+ addHandler(com.id, event.msg, fn);
225
+ return com;
226
+ },
227
+ };
228
+
229
+ Object.defineProperty(com, "attributes", {
230
+ get() {
231
+ return el.attributes;
232
+ }
233
+ });
234
+ Object.defineProperty(com, "value", {
235
+ get() {
236
+ if (valueProp) {
237
+ //@ts-ignore
238
+ return el.value;
239
+ }
240
+ return el.innerHTML;
241
+ },
242
+ set(v: string) {
243
+ if (valueProp) {
244
+ //@ts-ignore
245
+ el.value = v;
246
+ return true;
247
+ }
248
+ priv.childs.forEach(c => c._setParent(null));
249
+ priv.childs.length = 0;
250
+ el.innerHTML = v;
251
+ return true;
252
+ }
253
+ });
254
+ Object.defineProperty(com, "classList", {
255
+ get() {
256
+ //@ts-ignore
257
+ return Array.from(el.classList);
258
+ }
259
+ });
260
+
261
+ if (typeof opt.value !== "undefined") com.setValue(opt.value);
262
+
263
+ if (classes.length) {
264
+ classes.forEach(c => {
265
+ com.addClass(c);
266
+ });
267
+ }
268
+
269
+ return com;
270
+ };
271
+
272
+ tkeron.css = (name: string, cssText: string) => {
273
+ const selctr = `style[name=${name}]`;
274
+ const cstyle = document.head.querySelector(selctr);
275
+ if (cstyle) {
276
+ cstyle.innerHTML = cssText;
277
+ return;
278
+ }
279
+ const style = document.createElement("style");
280
+ style.setAttribute("name", name);
281
+ style.innerHTML = cssText;
282
+ //@ts-ignore
283
+ style.selctr = selctr;
284
+
285
+ document.head.appendChild(style);
286
+ };
287
+
288
+ export interface scriptOptions {
289
+ appendIn?: string;
290
+ runOnDOMContentLoaded?: boolean;
291
+ globalFunctions?: CallableFunction[];
292
+ }
293
+ tkeron.script = (anonFunc: CallableFunction, options?: scriptOptions) => {
294
+ const { appendIn, runOnDOMContentLoaded, globalFunctions } = options || {} as scriptOptions;
295
+ let value = `(${anonFunc.toString()})();`;
296
+ if (runOnDOMContentLoaded) value = `document.addEventListener("DOMContentLoaded",(${anonFunc.toString()}));`;
297
+
298
+ if (globalFunctions) {
299
+ let functions = "";
300
+ for (const func of globalFunctions) {
301
+ const name = func.name;
302
+ functions += `
303
+ const ${name} = ${func.toString()};
304
+ window.${name} = ${name};
305
+ `;
306
+ }
307
+ value = `${functions} ${value}`;
308
+ }
309
+
310
+ value = `/*tkeron-front-script ${value} tkeron-front-script*/`;
311
+
312
+ tkeron({ type: "script", value }).appendIn(appendIn || "body");
313
+ };
314
+
315
+
316
+ export const version = "1.9.0";
317
+
package/src/wait.ts ADDED
@@ -0,0 +1,2 @@
1
+
2
+ export const wait = async (time = 500) => new Promise((done) => setTimeout(done, time));
package/tkeron.json ADDED
@@ -0,0 +1,4 @@
1
+ {
2
+ "sourceDir": "front",
3
+ "outputDir": "web"
4
+ }
@@ -0,0 +1,12 @@
1
+ {
2
+ "compilerOptions": {
3
+ "module": "NodeNext",
4
+ "outDir": "dist",
5
+ "target": "ESNext",
6
+ "esModuleInterop": true,
7
+ "moduleResolution": "node",
8
+ "declaration": true
9
+ },
10
+ "exclude": ["node_modules"],
11
+ "include": ["src"]
12
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,29 @@
1
+ {
2
+ "compilerOptions": {
3
+ "experimentalDecorators": true,
4
+ "module": "ESNext",
5
+ "target": "ESNext",
6
+ "esModuleInterop": true,
7
+ "moduleResolution": "Node",
8
+ "declaration": false,
9
+ "skipLibCheck": true,
10
+ "baseUrl": "front",
11
+ "paths": {
12
+ "@tkeron": [
13
+ "tklibs/mod"
14
+ ],
15
+ "@comps/*": [
16
+ "comps/*"
17
+ ],
18
+ "@rxjs": [
19
+ "tklibs/rxjs/index"
20
+ ],
21
+ }
22
+ },
23
+ "compileOnSave": true,
24
+ "lib": [
25
+ "dom",
26
+ "es2015",
27
+ "esnext.asynciterable"
28
+ ]
29
+ }