create-gardener 1.1.13 → 2.0.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 (45) hide show
  1. package/package.json +1 -1
  2. package/starter.js +5 -2
  3. package/template/.env +0 -0
  4. package/template/buildHelper.js +3 -0
  5. package/template/jsconfig.json +27 -0
  6. package/template/package.json +6 -5
  7. package/template/src/backend/controllers/gardener/addComponent.ts +27 -0
  8. package/template/src/backend/controllers/gardener/addPage.ts +60 -0
  9. package/template/src/backend/controllers/gardener/createStatic.ts +84 -0
  10. package/template/src/backend/controllers/gardener/imageOptimiser.ts +67 -0
  11. package/template/src/backend/controllers/gardener/index.ts +4 -0
  12. package/template/src/backend/libs/generateWebp.ts +1 -0
  13. package/template/src/backend/routes/gardener.route.ts +15 -5
  14. package/template/src/backend/server.ts +8 -10
  15. package/template/src/frontend/assets/favicon.png +0 -0
  16. package/template/src/frontend/frontendtemplate.ejs +5 -17
  17. package/template/src/frontend/static/cache/favicon_500x500.webp +0 -0
  18. package/template/src/frontend/static/cache/favicon_50x50.webp +0 -0
  19. package/template/src/frontend/static/cache/gardener_50x50.webp +0 -0
  20. package/template/src/frontend/static/components/copybtn.js +86 -0
  21. package/template/src/frontend/static/components/nonui/api.js +33 -16
  22. package/template/src/frontend/static/components/nonui/navigation.js +59 -0
  23. package/template/src/frontend/static/components/secondtest.js +6 -0
  24. package/template/src/frontend/static/components/{emailsvg.js → testdd.js} +7 -7
  25. package/template/src/frontend/static/gardener.js +0 -388
  26. package/template/src/frontend/static/gardenerConfig.js +1 -0
  27. package/template/src/frontend/static/gardenerDev.js +408 -0
  28. package/template/src/frontend/static/global.js +2 -56
  29. package/template/src/frontend/static/pages/_.js +13 -0
  30. package/template/src/frontend/static/pages/_get-started.js +5 -0
  31. package/template/src/frontend/static/style.css +1039 -1
  32. package/template/src/frontend/static/style2.css +1 -1
  33. package/template/src/frontend/static/zod.js +8 -0
  34. package/template/src/frontend/views/_.ejs +96 -216
  35. package/template/src/frontend/views/_get-started.ejs +25 -0
  36. package/template/src/frontend/views/partials/icons/clipboard.ejs +1 -0
  37. package/template/src/frontend/views/partials/icons/clipboardok.ejs +1 -0
  38. package/template/tsconfig.json +1 -1
  39. package/template/src/backend/controllers/gardener.controller.ts +0 -193
  40. package/template/src/frontend/gardenerST.js +0 -431
  41. package/template/src/frontend/static/components/eyeoff.js +0 -50
  42. package/template/src/frontend/static/components/eyeon.js +0 -43
  43. package/template/src/frontend/static/components/passwordBox.js +0 -105
  44. package/template/src/frontend/views/_login.ejs +0 -75
  45. package/template/src/frontend/views/partials/loader.ejs +0 -3
@@ -0,0 +1,6 @@
1
+
2
+ import { gardener, fetchElement, replaceElement } from '../gardener.js'
3
+
4
+ export function secondtest.js() {
5
+ return gardener("{\n \"t\": \"button\",\n \"cn\": [\n \"copybtn\"\n ],\n \"children\": [\n {\n \"t\": \"svg\",\n \"cn\": [\n \"icon\",\n \"icon-tabler\",\n \"icons-tabler-outline\",\n \"icon-tabler-clipboard\"\n ],\n \"attr\": {\n \"xmlns\": \"http://www.w3.org/2000/svg\",\n \"width\": \"24\",\n \"height\": \"24\",\n \"viewBox\": \"0 0 24 24\",\n \"fill\": \"none\",\n \"stroke\": \"currentColor\",\n \"stroke-width\": \"2\",\n \"stroke-linecap\": \"round\",\n \"stroke-linejoin\": \"round\"\n },\n \"children\": [\n {\n \"t\": \"path\",\n \"attr\": {\n \"stroke\": \"none\",\n \"d\": \"M0 0h24v24H0z\",\n \"fill\": \"none\"\n }\n },\n {\n \"t\": \"path\",\n \"attr\": {\n \"d\": \"M9 5h-2a2 2 0 0 0 -2 2v12a2 2 0 0 0 2 2h10a2 2 0 0 0 2 -2v-12a2 2 0 0 0 -2 -2h-2\"\n }\n },\n {\n \"t\": \"path\",\n \"attr\": {\n \"d\": \"M9 5a2 2 0 0 1 2 -2h2a2 2 0 0 1 2 2a2 2 0 0 1 -2 2h-2a2 2 0 0 1 -2 -2\"\n }\n }\n ]\n }\n ]\n}")
6
+ }
@@ -1,11 +1,11 @@
1
1
 
2
- import { gardener, fetchElement, replaceElement } from '/static/gardener.js'
2
+ import { gardener, fetchElement, replaceElement } from '../gardener.js'
3
3
 
4
- export default function thisfun() {
4
+ export function testdd() {
5
5
  return gardener({
6
- "t": "span",
6
+ "t": "button",
7
7
  "cn": [
8
- "emailsvg"
8
+ "copybtn"
9
9
  ],
10
10
  "children": [
11
11
  {
@@ -14,7 +14,7 @@ export default function thisfun() {
14
14
  "icon",
15
15
  "icon-tabler",
16
16
  "icons-tabler-outline",
17
- "icon-tabler-mail"
17
+ "icon-tabler-clipboard"
18
18
  ],
19
19
  "attr": {
20
20
  "xmlns": "http://www.w3.org/2000/svg",
@@ -39,13 +39,13 @@ export default function thisfun() {
39
39
  {
40
40
  "t": "path",
41
41
  "attr": {
42
- "d": "M3 7a2 2 0 0 1 2 -2h14a2 2 0 0 1 2 2v10a2 2 0 0 1 -2 2h-14a2 2 0 0 1 -2 -2v-10"
42
+ "d": "M9 5h-2a2 2 0 0 0 -2 2v12a2 2 0 0 0 2 2h10a2 2 0 0 0 2 -2v-12a2 2 0 0 0 -2 -2h-2"
43
43
  }
44
44
  },
45
45
  {
46
46
  "t": "path",
47
47
  "attr": {
48
- "d": "M3 7l9 6l9 -6"
48
+ "d": "M9 5a2 2 0 0 1 2 -2h2a2 2 0 0 1 2 2a2 2 0 0 1 -2 2h-2a2 2 0 0 1 -2 -2"
49
49
  }
50
50
  }
51
51
  ]
@@ -1,254 +1,3 @@
1
- const config = {
2
- mode: 'dev',
3
- componentdir: 'static/components',
4
- hotreload: false
5
- }
6
-
7
- let hotReloadtimeout;
8
- const body = fetchElement('body');
9
- let hotReload = localStorage.getItem('hotreload');
10
-
11
- if (hotReload === null) hotReload = config.hotreload;
12
- else if (hotReload === 'true') hotReload = true
13
- else if (hotReload === 'false') hotReload = false
14
-
15
- function opnPagedialog(btn = true) {
16
- if (btn) {
17
- const dialog = gardener({
18
- t: 'form', cn: ['addpageform', 'fixed', 'left-2/5', 'bg-gray-200', 'rounded-lg', 'block', 'top-2/5', 'p-2', 'flex', 'flex-col', 'p-5', 'gap-2'], events: {
19
- submit: async (e) => {
20
- try {
21
- e.preventDefault()
22
- const data = new FormData(e.target);
23
- const input = Object.fromEntries(data.entries());
24
- console.log(input)
25
-
26
- const response = await fetch('/addpage', {
27
- method: 'POST',
28
- headers: {
29
- "Content-Type": 'application/json'
30
- },
31
- body: JSON.stringify(input)
32
- }).then(res => res.json())
33
- console.log(response)
34
- opnPagedialog(false)
35
- window.location.href = input.page
36
- }
37
- catch (err) {
38
- console.log(err)
39
- }
40
-
41
- }
42
- }, children: [{
43
- t: 'label',
44
- txt: 'ENTER PATH FOR NEW PAGE'
45
- }, { t: 'input', attr: { name: 'page' }, cn: ['pathinput'] }]
46
-
47
- })
48
-
49
- console.log('test')
50
- appendElement(body, dialog);
51
- fetchElement('.pathinput').focus();
52
- }
53
- else {
54
- console.log('removed')
55
- fetchElement('.addpageform').remove();
56
- }
57
- }
58
-
59
- if (config.mode === 'dev') {
60
- const addPagebtn = gardener({
61
- t: 'button',
62
- cn: ['pb-1.5', 'flex', 'items-center', 'justify-center', 'h-15', 'w-15', 'bg-green-300', 'fixed', 'bottom-22', 'right-2', 'rounded-full', 'text-5xl'],
63
- children: [{ t: 'span', txt: '+' }],
64
- events: {
65
- click: opnPagedialog
66
- }
67
- });
68
-
69
- appendElement(body, addPagebtn);
70
-
71
-
72
- appendElement(body, gardener({
73
- t: 'p',
74
- cn: ['bg-gray-200', 'fixed', 'bottom-0', 'z-100', 'right-0', 'border-b-1', 'p-2', 'rounded-md'],
75
- children: [
76
- {
77
- t: 'span',
78
- txt: 'Press '
79
- },
80
- {
81
- t: 'span',
82
- cn: ['text-green-500', 'font-bold'],
83
- txt: 'Alt+h'
84
- },
85
- {
86
- t: 'span',
87
- txt: ' to toggle Hot Reload'
88
- },
89
- {
90
- t: 'form',
91
- attr: {
92
- id: 'hrcheckbox',
93
- },
94
- events: {
95
- click: () => togglehotreload()
96
- },
97
- cn: ['p-2', 'bg-red-300'],
98
- children: [{
99
- t: 'label',
100
- txt: 'Hot Reload ',
101
- }
102
- , {
103
- t: 'input',
104
- cn: ['hrcheckbox'],
105
- attr: {
106
- type: 'checkbox'
107
- }
108
- }]
109
- }
110
- ]
111
- }))
112
-
113
- //appendElement(body, gardener())
114
-
115
-
116
- togglehotreload();
117
- document.addEventListener('keydown', function(e) {
118
- // Detect Ctrl + H
119
- if (e.altKey && e.key.toLowerCase() === 'h') {
120
- e.preventDefault(); // Stop browser from opening history
121
- // Your logic here...
122
- togglehotreload();
123
- }
124
- });
125
- }
126
-
127
- //if (config.mode === 'dev') {
128
-
129
-
130
- function togglehotreload() {
131
- const hr = hotReload;
132
- const hrcheck = fetchElement('#hrcheckbox');
133
-
134
- localStorage.setItem('hotreload', hr);
135
-
136
- hotReload = !hotReload;
137
-
138
- if (hr) {
139
- hrcheck.style.background = '#66e666';
140
- fetchElement('.hrcheckbox').checked = true;
141
- localStorage.setItem('hotreload', 'true');
142
- hotReloadtimeout = setTimeout(() => window.location.reload(), 1000);
143
- }
144
- else {
145
- hrcheck.style.background = 'red';
146
- fetchElement('.hrcheckbox').checked = false;
147
- localStorage.setItem('hotreload', 'false');
148
- clearTimeout(hotReloadtimeout);
149
- }
150
-
151
- //localStorage.setItem('hotreload', hotReload);
152
- }
153
-
154
- export function parserWindow(text) {
155
- if (config.mode !== 'dev') return;
156
-
157
-
158
- const result = gardener({
159
- t: 'div',
160
- cn: ['fixed', 'border-2', 'border-black', 'bg-gray-500', 'text-white', 'rounded-lg', 'z-90', 'w-2/4', 'h-2/4', 'left-1/4', 'flex', 'flex-col', 'justify-between', 'top-1/4'],
161
- children: [
162
- {
163
- t: 'div',
164
- cn: ['bg-gray-200', 'h-15', 'text-black', 'rounded-t-lg', 'flex', 'items-center', 'justify-around'],
165
- children: [
166
- {
167
- t: 'h3',
168
- cn: ['font-bold'],
169
- txt: 'Parser Window'
170
- },
171
- {
172
- t: 'button',
173
- cn: ['p-2', 'bg-red-300', 'rounded-lg', 'cursor-pointer'],
174
- txt: 'Add Component',
175
- attr: {
176
- id: 'copybtn'
177
- },
178
- events: {
179
- click: copytxt
180
- }
181
- }
182
- ]
183
- },
184
- {
185
- t: 'p',
186
- cn: ['p-5', 'overflow-scroll'],
187
- txt: text
188
- },
189
- ]
190
- })
191
-
192
- function copytxt() {
193
- result.remove()
194
-
195
- const compform = gardener({
196
- t: 'form',
197
- events: {
198
- submit: (event) => {
199
- event.preventDefault()
200
- copyText(text, `${fetchElement('.componentInp').value}.js`)
201
- compform.remove();
202
- }
203
- },
204
- cn: ['fixed', 'left-2/5', 'bg-gray-500', 'rounded-lg', 'block', 'top-2/5', 'p-2'],
205
- children: [
206
- {
207
- t: 'input',
208
- cn: ['bg-white', 'componentInp'],
209
- attr: {
210
- type: 'text',
211
- placeholder: 'Component Name'
212
- }
213
- }
214
- ]
215
- });
216
- appendElement(body, compform);
217
-
218
- fetchElement('.componentInp').focus();
219
- //setTimeout(() => result.remove(), 500);
220
- }
221
-
222
- appendElement(body, result);
223
- }
224
-
225
-
226
-
227
- async function copyText(txt, path) {
228
- // await navigator.clipboard.writeText(txt);
229
- try {
230
- const res = await fetch('/addcomponent', {
231
- method: 'POST',
232
- headers: {
233
- "Content-Type": 'application/json'
234
- },
235
- body: JSON.stringify({ component: txt, path: `${config.componentdir}/${path}` })
236
- })
237
-
238
- if (!res.ok) console.error('wrong');
239
-
240
- const data = await res.json()
241
- console.log(data);
242
-
243
- }
244
- catch (err) {
245
- console.error(err);
246
- }
247
-
248
- }
249
-
250
-
251
-
252
1
 
253
2
  export function fetchElement(param) {
254
3
  return document.querySelector(param);
@@ -338,140 +87,3 @@ export function gardener(Dom) {
338
87
  }
339
88
 
340
89
 
341
- function cleanStringAndList(input) {
342
- const pattern = /\?"?(\w+)"?\?/g;
343
- const vars = new Set();
344
- let match;
345
-
346
- while ((match = pattern.exec(input)) !== null) {
347
- vars.add(match[1]);
348
- }
349
-
350
- // Replace ?var? with "+var+" and clean up resulting empty strings or double quotes
351
- const cleanedString = input
352
- .replace(pattern, '"+$1+"')
353
- .replace(/^""\+/, '')
354
- .replace(/\+""$/, '');
355
-
356
- return {
357
- cleanedString,
358
- extractedList: [...vars].join(', ')
359
- };
360
- }
361
-
362
- function generateFile(obj) {
363
-
364
-
365
- const formatted = JSON.stringify(obj, null, 2);
366
- const { cleanedString, extractedList } = cleanStringAndList(formatted);
367
-
368
- if (extractedList.length === 0) return `
369
- import { gardener, fetchElement, replaceElement } from '../gardener.js'
370
-
371
- export default function thisfun() {
372
- return gardener(${cleanedString})
373
- }
374
- `;
375
-
376
- return `
377
- import { gardener, fetchElement, replaceElement } from '../gardener.js'
378
-
379
- export default function thisfun({${extractedList}}) {
380
- return gardener(${cleanedString})
381
- }
382
- `;
383
- }
384
-
385
-
386
- // console.log(result.extractedList); // ["ritish"]
387
-
388
-
389
- export function parser(element, isParent = true) {
390
- if (typeof element === 'string') {
391
- element = fetchElement(element);
392
- }
393
-
394
- console.log(element)
395
- const obj = {
396
- t: element.tagName.toLowerCase(),
397
- };
398
-
399
- // add classes if present
400
- if (element.classList.length) {
401
- obj.cn = Array.from(element.classList);
402
- }
403
-
404
- // add attributes if present
405
- const attrs = {};
406
- for (const attr of element.attributes) {
407
- if (attr.name !== 'class') attrs[attr.name] = attr.value;
408
- }
409
- if (Object.keys(attrs).length) obj.attr = attrs;
410
- // add text content (only if no children)
411
- if (element.childNodes.length === 1 && element.firstChild.nodeType === Node.TEXT_NODE) {
412
- obj.txt = element.textContent.trim();
413
-
414
- if (isParent) {
415
-
416
- parserWindow(generateFile(obj))
417
- }
418
-
419
- return obj;
420
- }
421
-
422
-
423
- // add children recursively
424
- const children = [];
425
- for (const child of element.childNodes) {
426
- if (child.nodeType === Node.COMMENT_NODE) continue;
427
-
428
- if (child.nodeType === Node.TEXT_NODE && child.textContent.trim() === '') continue;
429
-
430
- if (child.nodeType === Node.TEXT_NODE) {
431
- children.push({ t: 'span', txt: child.textContent.trim() });
432
- continue;
433
- }
434
- children.push(parser(child, false));
435
- }
436
- if (children.length) obj.children = children;
437
-
438
-
439
- if (isParent) {
440
-
441
-
442
- parserWindow(generateFile(obj))
443
- }
444
-
445
- return obj
446
-
447
-
448
- //Let Browser do the migration from html to json and then use copy paste
449
- }
450
-
451
- export function addEL(parent, event, fun) {
452
- if (typeof parent === 'string') {
453
- parent = fetchElement(parent);
454
- }
455
- parent.addEventListener(event, fun)
456
- }
457
-
458
- export class State {
459
- constructor(value) {
460
- this.value = value;
461
- this.cb = [];
462
- }
463
- registerCb(cb) {
464
- cb(this.value);
465
- this.cb.push(cb);
466
- }
467
- setTo(val) {
468
- this.value = val;
469
- this.cb.forEach(cb => { cb(val) });
470
- }
471
- }
472
-
473
-
474
- export function log(target) {
475
- console.log(target)
476
- }
477
-
@@ -0,0 +1 @@
1
+ export const mode = 'dev';