create-gardener 1.1.6 → 1.1.8

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 (32) hide show
  1. package/Readme.md +2 -313
  2. package/package.json +1 -1
  3. package/template/package.json +11 -12
  4. package/template/pnpm-lock.yaml +1545 -0
  5. package/template/src/backend/controllers/gardener.controller.ts +7 -32
  6. package/template/src/backend/routes/gardener.route.ts +2 -1
  7. package/template/src/backend/server.ts +1 -1
  8. package/template/src/frontend/frontendtemplate.ejs +4 -4
  9. package/template/src/frontend/gardenerST.js +430 -0
  10. package/template/src/frontend/static/components/emailsvg.js +55 -0
  11. package/template/src/frontend/{components → static/components}/eyeoff.js +1 -1
  12. package/template/src/frontend/static/components/eyeon.js +43 -0
  13. package/template/src/frontend/{components → static/components}/notification.js +1 -1
  14. package/template/src/frontend/{components → static/components}/passwordBox.js +3 -3
  15. package/template/src/frontend/static/components/test.js +54 -0
  16. package/template/src/frontend/{gardener.js → static/gardener.js} +76 -4
  17. package/template/src/frontend/static/style.css +1048 -0
  18. package/template/src/frontend/style.css +148 -350
  19. package/template/src/frontend/views/_.ejs +17 -8
  20. package/template/src/frontend/views/_login.ejs +8 -8
  21. package/template/tsconfig.json +1 -1
  22. package/.direnv/bin/nix-direnv-reload +0 -19
  23. package/.direnv/flake-profile-a5d5b61aa8a61b7d9d765e1daf971a9a578f1cfa.rc +0 -2140
  24. package/.envrc +0 -1
  25. package/template/Readme.md +0 -349
  26. package/template/src/frontend/components/emailsvg.js +0 -55
  27. package/template/src/frontend/components/eyeon.js +0 -44
  28. package/template/src/frontend/components/test.js +0 -54
  29. /package/template/src/{backend → frontend/static}/cache/gardener_500x500.webp +0 -0
  30. /package/template/src/frontend/{components → static/components}/nonui/api.js +0 -0
  31. /package/template/src/frontend/{global.js → static/global.js} +0 -0
  32. /package/template/src/frontend/{style2.css → static/style2.css} +0 -0
@@ -0,0 +1,54 @@
1
+
2
+ import { gardener, fetchElement, replaceElement } from '/static/gardener.js'
3
+
4
+ export default function thisfun() {
5
+ return gardener({
6
+ "t": "div",
7
+ "attr": {
8
+ "id": "body"
9
+ },
10
+ "children": [
11
+ {
12
+ "t": "div",
13
+ "cn": [
14
+ "h-screen",
15
+ "w-screen",
16
+ "bg-white",
17
+ "loader",
18
+ "absolute"
19
+ ],
20
+ "attr": {
21
+ "style": "transition: 0.4s; opacity: 0;"
22
+ },
23
+ "txt": ""
24
+ },
25
+ {
26
+ "t": "div",
27
+ "cn": [
28
+ "hero",
29
+ "flex",
30
+ "justify-around",
31
+ "items-center",
32
+ "p-5",
33
+ "h-[90vh]"
34
+ ],
35
+ "children": [
36
+ {
37
+ "t": "p",
38
+ "cn": [
39
+ "p-5"
40
+ ],
41
+ "txt": "Gardener is a front-end library for creating and manipulating DOM elements using a declarative JavaScript object syntax. It includes a development server with features like timely reload and on-the-fly component creation from existing HTML. The server also provides dynamic image resizing and caching."
42
+ },
43
+ {
44
+ "t": "img",
45
+ "attr": {
46
+ "src": "/cache/gardener_500x500.webp",
47
+ "alt": "logo"
48
+ }
49
+ }
50
+ ]
51
+ }
52
+ ]
53
+ })
54
+ }
@@ -1,6 +1,6 @@
1
1
  const config = {
2
2
  mode: 'dev',
3
- componentdir: 'components',
3
+ componentdir: 'static/components',
4
4
  hotreload: false
5
5
  }
6
6
 
@@ -255,6 +255,9 @@ export function fetchElement(param) {
255
255
  }
256
256
 
257
257
  export function appendElement(parent, child) {
258
+ if (typeof parent === 'string') {
259
+ parent = fetchElement(parent);
260
+ }
258
261
  parent.appendChild(child);
259
262
  }
260
263
 
@@ -270,6 +273,9 @@ export function insertText(element, text) {
270
273
  }
271
274
 
272
275
  export function replaceElement(original, New) {
276
+ if (typeof original === 'string') {
277
+ original = fetchElement(original);
278
+ }
273
279
  original.replaceWith(New);
274
280
  }
275
281
 
@@ -331,11 +337,56 @@ export function gardener(Dom) {
331
337
  return element;
332
338
  }
333
339
 
340
+
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
+ return `
369
+ import { gardener, fetchElement, replaceElement } from '../gardener.js'
370
+
371
+ export default function thisfun({${extractedList}}) {
372
+ return gardener(${cleanedString})
373
+ }
374
+ `;
375
+ }
376
+
377
+
378
+ // Example:
379
+ // const result = cleanStringAndList('hi "{ritish}" how are you');
380
+ // console.log(result.cleanedString); // "hi ritish how are you"
381
+ // console.log(result.extractedList); // ["ritish"]
382
+
383
+
334
384
  export function parser(element, isParent = true) {
335
385
  if (typeof element === 'string') {
336
386
  element = fetchElement(element);
337
387
  }
338
388
 
389
+ console.log(element)
339
390
  const obj = {
340
391
  t: element.tagName.toLowerCase(),
341
392
  };
@@ -356,28 +407,49 @@ export function parser(element, isParent = true) {
356
407
  obj.txt = element.textContent.trim();
357
408
 
358
409
  if (isParent) {
359
- parserWindow(JSON.stringify(obj))
410
+
411
+ parserWindow(generateFile(obj))
360
412
  }
361
413
 
362
414
  return obj;
363
415
  }
364
416
 
417
+
365
418
  // add children recursively
366
419
  const children = [];
367
- for (const child of element.children) {
420
+ for (const child of element.childNodes) {
421
+ if (child.nodeType === Node.COMMENT_NODE) continue;
422
+
423
+ if (child.nodeType === Node.TEXT_NODE && child.textContent.trim() === '') continue;
424
+
425
+ if (child.nodeType === Node.TEXT_NODE) {
426
+ children.push({ t: 'span', txt: child.textContent.trim() });
427
+ continue;
428
+ }
368
429
  children.push(parser(child, false));
369
430
  }
370
431
  if (children.length) obj.children = children;
371
432
 
372
433
 
373
434
  if (isParent) {
374
- parserWindow(JSON.stringify(obj))
435
+
436
+
437
+ parserWindow(generateFile(obj))
375
438
  }
376
439
 
377
440
  return obj
441
+
442
+
378
443
  //Let Browser do the migration from html to json and then use copy paste
379
444
  }
380
445
 
446
+ export function addEL(parent, event, fun) {
447
+ if (typeof parent === 'string') {
448
+ parent = fetchElement(parent);
449
+ }
450
+ parent.addEventListener(event, fun)
451
+ }
452
+
381
453
  export function imagePreloader(images) {
382
454
  const body = fetchElement('body')
383
455
  images.forEach(entry => {