create-gardener 2.1.0 → 2.1.2
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/package.json +1 -1
- package/template/build/backend/controllers/gardener/addPage.d.ts.map +1 -1
- package/template/build/backend/controllers/gardener/addPage.js +31 -21
- package/template/build/backend/controllers/gardener/addPage.js.map +1 -1
- package/template/build/backend/controllers/gardener/createStatic.d.ts.map +1 -1
- package/template/build/backend/controllers/gardener/createStatic.js +3 -1
- package/template/build/backend/controllers/gardener/createStatic.js.map +1 -1
- package/template/build/backend/libs/generateWebp.d.ts.map +1 -1
- package/template/build/backend/libs/generateWebp.js +0 -2
- package/template/build/backend/libs/generateWebp.js.map +1 -1
- package/template/build/backend/routes/gardener.route.js +5 -0
- package/template/build/backend/routes/gardener.route.js.map +1 -1
- package/template/build/frontend/static/bundle/bundle._.js +1 -0
- package/template/build/frontend/static/bundle/bundle._about.js +1 -0
- package/template/build/frontend/static/bundle/bundle._kartik.js +1 -0
- package/template/build/frontend/static/bundle/bundle._new.js +1 -0
- package/template/build/frontend/static/bundle/bundle._ritish.js +1 -0
- package/template/build/frontend/static/cache/gardener_100x100.webp +0 -0
- package/template/build/frontend/static/components/copybtn.js +16 -3
- package/template/build/frontend/static/components/footer.js +33 -0
- package/template/build/frontend/static/components/gardener/errorBox.js +47 -0
- package/template/build/frontend/static/components/gardener/hotReloadbtn.js +82 -0
- package/template/build/frontend/static/components/gardener/pageOverlayBtn.js +138 -0
- package/template/build/frontend/static/components/gardener/parserWindow.js +159 -0
- package/template/build/frontend/static/components/nonui/api.js +15 -2
- package/template/build/frontend/static/components/nonui/navigation.js +2 -2
- package/template/build/frontend/static/components/notification.js +1 -1
- package/template/build/frontend/static/gardener.js +129 -58
- package/template/build/frontend/static/gardenerConfig.js +1 -1
- package/template/build/frontend/static/gardenerDev.js +67 -401
- package/template/build/frontend/static/global.js +2 -2
- package/template/build/frontend/static/pages/pages._.js +7 -2
- package/template/build/frontend/static/pages/pages._about.js +2 -0
- package/template/build/frontend/static/pages/pages._kartik.js +2 -0
- package/template/build/frontend/static/pages/pages._new.js +2 -0
- package/template/build/frontend/static/pages/pages._ritish.js +2 -0
- package/template/build/frontend/static/style.css +1 -1
- package/template/build/frontend/static/style2.css +2 -2
- package/template/build/frontend/views/_.ejs +6 -2
- package/template/build/frontend/views/_about.ejs +126 -0
- package/template/build/frontend/views/_kartik.ejs +126 -0
- package/template/build/frontend/views/_new.ejs +126 -0
- package/template/build/frontend/views/_ritish.ejs +126 -0
- package/template/buildHelper.js +33 -2
- package/template/package.json +2 -1
- package/template/pnpm-lock.yaml +271 -0
- package/template/src/backend/controllers/gardener/addPage.ts +7 -1
- package/template/src/backend/controllers/gardener/createStatic.ts +94 -59
- package/template/src/backend/controllers/gardener/index.ts +0 -1
- package/template/src/backend/routes/gardener.route.ts +1 -2
- package/template/src/frontend/bundle/bundle._.js +2 -0
- package/template/src/frontend/bundle/bundle._about.js +1 -0
- package/template/src/frontend/bundle/bundle._kartik.js +1 -0
- package/template/src/frontend/bundle/bundle._new.js +1 -0
- package/template/src/frontend/bundle/bundle._ritish.js +1 -0
- package/template/src/frontend/static/components/nonui/navigation.js +2 -2
- package/template/src/frontend/static/components/notification.js +1 -1
- package/template/src/frontend/static/gardenerDev.js +2 -2
- package/template/src/frontend/static/global.js +1 -1
- package/template/src/frontend/static/pages/pages._.js +2 -2
- package/template/src/frontend/static/style.css +61 -31
- package/template/src/frontend/template/template._.ejs +5 -1
- package/template/src/frontend/views/_.ejs +6 -2
- package/template/build/frontend/static/gardener.test.js +0 -364
- package/template/build/frontend/static/zod.js +0 -8
- package/template/buildHelper.test.js +0 -78
- package/template/jest.config.js +0 -13
- package/template/src/frontend/static/gardener.test.js +0 -364
- package/template/src/frontend/static/zod.js +0 -8
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { gardener, fetchElement, appendElement } from '../../gardener.js'
|
|
2
|
+
|
|
3
|
+
const body = fetchElement('body');
|
|
4
|
+
|
|
5
|
+
function opnPagedialog(btn = true) {
|
|
6
|
+
if (btn) {
|
|
7
|
+
const dialog = gardener({
|
|
8
|
+
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: {
|
|
9
|
+
submit: async (e) => {
|
|
10
|
+
try {
|
|
11
|
+
e.preventDefault()
|
|
12
|
+
const data = new FormData(e.target);
|
|
13
|
+
const input = Object.fromEntries(data.entries());
|
|
14
|
+
|
|
15
|
+
const response = await fetch('/addpage', {
|
|
16
|
+
method: 'POST',
|
|
17
|
+
headers: {
|
|
18
|
+
"Content-Type": 'application/json'
|
|
19
|
+
},
|
|
20
|
+
body: JSON.stringify(input)
|
|
21
|
+
}).then(res => res.json())
|
|
22
|
+
opnPagedialog(false)
|
|
23
|
+
window.location.href = `${input.page}`
|
|
24
|
+
}
|
|
25
|
+
catch (err) {
|
|
26
|
+
console.log(err)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
}
|
|
30
|
+
}, children: [{
|
|
31
|
+
t: 'label',
|
|
32
|
+
txt: 'ENTER PATH FOR NEW PAGE'
|
|
33
|
+
}, { t: 'input', attr: { name: 'page' }, cn: ['pathinput'] }]
|
|
34
|
+
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
appendElement(body, dialog);
|
|
38
|
+
fetchElement('.pathinput').focus();
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
fetchElement('.addpageform').remove();
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
const pagebtns = gardener({
|
|
48
|
+
t: 'div',
|
|
49
|
+
cn: [
|
|
50
|
+
'fixed',
|
|
51
|
+
'bottom-20',
|
|
52
|
+
'right-4',
|
|
53
|
+
'flex',
|
|
54
|
+
'flex-col',
|
|
55
|
+
'gap-2',
|
|
56
|
+
'bg-white',
|
|
57
|
+
'shadow-lg',
|
|
58
|
+
'rounded-xl',
|
|
59
|
+
'p-3',
|
|
60
|
+
'z-50'
|
|
61
|
+
],
|
|
62
|
+
children: [
|
|
63
|
+
{
|
|
64
|
+
t: 'button',
|
|
65
|
+
cn: [
|
|
66
|
+
'px-4',
|
|
67
|
+
'py-2',
|
|
68
|
+
'bg-blue-500',
|
|
69
|
+
'text-white',
|
|
70
|
+
'rounded-lg',
|
|
71
|
+
'hover:bg-blue-600',
|
|
72
|
+
'transition'
|
|
73
|
+
],
|
|
74
|
+
children: [{ t: 'span', txt: 'New Page' }],
|
|
75
|
+
events: {
|
|
76
|
+
click: opnPagedialog
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
t: 'button',
|
|
81
|
+
cn: [
|
|
82
|
+
'px-4',
|
|
83
|
+
'py-2',
|
|
84
|
+
'bg-gray-800',
|
|
85
|
+
'text-white',
|
|
86
|
+
'rounded-lg',
|
|
87
|
+
'hover:bg-gray-900',
|
|
88
|
+
'transition'
|
|
89
|
+
],
|
|
90
|
+
children: [{ t: 'span', txt: 'Save Template' }],
|
|
91
|
+
events: {
|
|
92
|
+
click: async () => {
|
|
93
|
+
const result = await fetch('/savetemplate', {
|
|
94
|
+
method: 'POST',
|
|
95
|
+
headers: { "Content-Type": 'application/json' },
|
|
96
|
+
body: JSON.stringify({ path: fetchElement('#fileName').innerText })
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
const data = await result.json(); // ✅ fix
|
|
100
|
+
alert(data.message);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
]
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
export const addPagebtn = gardener({
|
|
109
|
+
t: 'div',
|
|
110
|
+
cn: ['fixed', 'bottom-4', 'right-4', 'z-50'],
|
|
111
|
+
events: {
|
|
112
|
+
mouseenter: () => appendElement(addPagebtn, pagebtns),
|
|
113
|
+
mouseleave: () => pagebtns.remove()
|
|
114
|
+
},
|
|
115
|
+
children: [
|
|
116
|
+
{
|
|
117
|
+
t: 'span',
|
|
118
|
+
// cn: ['pb-1.5', 'flex', 'items-center', 'justify-center', 'h-15', 'w-15', 'bg-black', 'text-white', 'fixed', 'bottom-22', 'right-2'],
|
|
119
|
+
|
|
120
|
+
cn: [
|
|
121
|
+
'flex',
|
|
122
|
+
'items-center',
|
|
123
|
+
'justify-center',
|
|
124
|
+
'h-14',
|
|
125
|
+
'w-14',
|
|
126
|
+
'bg-black',
|
|
127
|
+
'text-white',
|
|
128
|
+
'fixed',
|
|
129
|
+
'bottom-22',
|
|
130
|
+
'right-2',
|
|
131
|
+
'rounded-full',
|
|
132
|
+
'shadow-lg',
|
|
133
|
+
'cursor-pointer',
|
|
134
|
+
],
|
|
135
|
+
txt: 'GR'
|
|
136
|
+
}
|
|
137
|
+
]
|
|
138
|
+
});
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import { gardener, fetchElement, appendElement } from '../../gardener.js'
|
|
2
|
+
import { gardenerError } from './errorBox.js';
|
|
3
|
+
|
|
4
|
+
const body = fetchElement('body');
|
|
5
|
+
|
|
6
|
+
const config = {
|
|
7
|
+
componentdir: 'static/components',
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
let result;
|
|
11
|
+
export function parserWindow(text) {
|
|
12
|
+
result = gardener({
|
|
13
|
+
t: 'div',
|
|
14
|
+
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'],
|
|
15
|
+
children: [
|
|
16
|
+
{
|
|
17
|
+
t: 'div',
|
|
18
|
+
cn: ['bg-gray-200', 'h-15', 'text-black', 'rounded-t-lg', 'flex', 'items-center', 'justify-around'],
|
|
19
|
+
children: [
|
|
20
|
+
{
|
|
21
|
+
t: 'h3',
|
|
22
|
+
cn: ['font-bold', 'p-5'],
|
|
23
|
+
txt: 'Parser Window'
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
t: 'div',
|
|
27
|
+
cn: ['flex', 'gap-3'],
|
|
28
|
+
children: [
|
|
29
|
+
{
|
|
30
|
+
t: 'button',
|
|
31
|
+
cn: ['p-2', 'bg-green-300', 'rounded-lg', 'cursor-pointer'],
|
|
32
|
+
txt: 'Copy Component',
|
|
33
|
+
attr: { id: 'copybtn' },
|
|
34
|
+
events: {
|
|
35
|
+
click: () => { navigator.clipboard.writeText(text); fetchElement('#copybtn').innerText = 'copied'; }
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
t: 'button',
|
|
40
|
+
cn: ['p-2', 'bg-red-300', 'rounded-lg', 'cursor-pointer'],
|
|
41
|
+
txt: 'Add Component',
|
|
42
|
+
events: {
|
|
43
|
+
click: () => addComponentForm(text)
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
]
|
|
47
|
+
}
|
|
48
|
+
]
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
t: 'p',
|
|
52
|
+
cn: ['p-5', 'overflow-scroll'],
|
|
53
|
+
txt: text
|
|
54
|
+
},
|
|
55
|
+
]
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
return result;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function addComponentForm(text) {
|
|
63
|
+
result.remove()
|
|
64
|
+
|
|
65
|
+
const compform = gardener({
|
|
66
|
+
t: 'form',
|
|
67
|
+
events: {
|
|
68
|
+
submit: (event) => {
|
|
69
|
+
event.preventDefault()
|
|
70
|
+
addComponent(text, `${fetchElement('.componentInp').value}`)
|
|
71
|
+
compform.remove();
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
cn: ['fixed', 'left-2/5', 'bg-gray-500', 'rounded-lg', 'block', 'top-2/5', 'p-2'],
|
|
75
|
+
children: [
|
|
76
|
+
{
|
|
77
|
+
t: 'input',
|
|
78
|
+
cn: ['bg-white', 'componentInp'],
|
|
79
|
+
attr: {
|
|
80
|
+
type: 'text',
|
|
81
|
+
placeholder: 'Component Name'
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
]
|
|
85
|
+
});
|
|
86
|
+
appendElement(body, compform);
|
|
87
|
+
|
|
88
|
+
fetchElement('.componentInp').focus();
|
|
89
|
+
//setTimeout(() => result.remove(), 500);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
async function addComponent(txt, path) {
|
|
93
|
+
try {
|
|
94
|
+
const res = await fetch('/addcomponent', {
|
|
95
|
+
method: 'POST',
|
|
96
|
+
headers: {
|
|
97
|
+
"Content-Type": 'application/json'
|
|
98
|
+
},
|
|
99
|
+
body: JSON.stringify({ component: generateFile(txt, path), path: `${config.componentdir}/${path}.js` })
|
|
100
|
+
})
|
|
101
|
+
|
|
102
|
+
if (!res.ok) {
|
|
103
|
+
throw new Error(`Failed to add component: ${res.status} ${res.statusText}`);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const data = await res.json()
|
|
107
|
+
|
|
108
|
+
}
|
|
109
|
+
catch (err) {
|
|
110
|
+
console.error('Add Component Error:', err);
|
|
111
|
+
gardenerError(err.message || 'Failed to add component');
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
function generateFile(obj, name) {
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
const { cleanedString, extractedList } = cleanStringAndList(obj);
|
|
121
|
+
|
|
122
|
+
if (extractedList.length === 0) return `
|
|
123
|
+
import { gardener, fetchElement, replaceElement } from '../gardener.js'
|
|
124
|
+
|
|
125
|
+
export function ${name}() {
|
|
126
|
+
return gardener(${cleanedString})
|
|
127
|
+
}
|
|
128
|
+
`;
|
|
129
|
+
|
|
130
|
+
return `
|
|
131
|
+
import { gardener, fetchElement, replaceElement } from '../gardener.js'
|
|
132
|
+
|
|
133
|
+
export function ${name}({${extractedList}}) {
|
|
134
|
+
return gardener(${cleanedString})
|
|
135
|
+
}
|
|
136
|
+
`;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
function cleanStringAndList(input) {
|
|
141
|
+
const pattern = /\?"?(\w+)"?\?/g;
|
|
142
|
+
const vars = new Set();
|
|
143
|
+
let match;
|
|
144
|
+
|
|
145
|
+
while ((match = pattern.exec(input)) !== null) {
|
|
146
|
+
vars.add(match[1]);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// Replace ?var? with "+var+" and clean up resulting empty strings or double quotes
|
|
150
|
+
const cleanedString = input
|
|
151
|
+
.replace(pattern, '"+$1+"')
|
|
152
|
+
.replace(/^""\+/, '')
|
|
153
|
+
.replace(/\+""$/, '');
|
|
154
|
+
|
|
155
|
+
return {
|
|
156
|
+
cleanedString,
|
|
157
|
+
extractedList: [...vars].join(', ')
|
|
158
|
+
};
|
|
159
|
+
}
|
|
@@ -29,11 +29,24 @@ export async function Fetch(
|
|
|
29
29
|
body: JSON.stringify(body),
|
|
30
30
|
});
|
|
31
31
|
|
|
32
|
-
|
|
32
|
+
if (!res.ok) {
|
|
33
|
+
throw new Error(`HTTP error! status: ${res.status}`);
|
|
34
|
+
}
|
|
33
35
|
|
|
34
36
|
return res
|
|
35
37
|
}
|
|
36
38
|
catch (err) {
|
|
37
|
-
console.
|
|
39
|
+
console.error('Fetch Error:', err);
|
|
40
|
+
|
|
41
|
+
// Import and display error using gardenerError
|
|
42
|
+
import('../gardener/errorBox.js')
|
|
43
|
+
.then(({ gardenerError }) => {
|
|
44
|
+
gardenerError(err.message || 'Network request failed');
|
|
45
|
+
})
|
|
46
|
+
.catch(() => {
|
|
47
|
+
console.error('Error component not available:', err.message);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
throw err;
|
|
38
51
|
}
|
|
39
52
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { gardener, fetchElement, appendElement } from "
|
|
2
|
-
import { mode } from "
|
|
1
|
+
import { gardener, fetchElement, appendElement } from "../../gardener.js";
|
|
2
|
+
import { mode } from "../../gardenerConfig.js";
|
|
3
3
|
|
|
4
4
|
const body = fetchElement('#main');
|
|
5
5
|
|
|
@@ -1,89 +1,160 @@
|
|
|
1
|
+
import { gardenerError } from "./components/gardener/errorBox.js";
|
|
2
|
+
|
|
1
3
|
|
|
2
4
|
export function fetchElement(param) {
|
|
3
|
-
|
|
5
|
+
const element = document.querySelector(param);
|
|
6
|
+
if (!element) {
|
|
7
|
+
console.warn(`Element not found: ${param}`);
|
|
8
|
+
}
|
|
9
|
+
return element;
|
|
4
10
|
}
|
|
5
11
|
|
|
6
12
|
export function appendElement(parent, child) {
|
|
7
|
-
|
|
8
|
-
parent
|
|
13
|
+
try {
|
|
14
|
+
if (typeof parent === 'string') {
|
|
15
|
+
parent = fetchElement(parent);
|
|
16
|
+
}
|
|
17
|
+
if (!parent) {
|
|
18
|
+
throw new Error('Parent element is null or undefined');
|
|
19
|
+
}
|
|
20
|
+
if (!child) {
|
|
21
|
+
throw new Error('Child element is null or undefined');
|
|
22
|
+
}
|
|
23
|
+
parent.appendChild(child);
|
|
24
|
+
} catch (error) {
|
|
25
|
+
gardenerError(error);
|
|
9
26
|
}
|
|
10
|
-
parent.appendChild(child);
|
|
11
27
|
}
|
|
12
28
|
|
|
13
29
|
export function createElement(type, classname) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
30
|
+
try {
|
|
31
|
+
if (!type) {
|
|
32
|
+
throw new Error('Element type is required');
|
|
33
|
+
}
|
|
34
|
+
let element = document.createElement(type);
|
|
35
|
+
if (classname)
|
|
36
|
+
element.classList.add(...classname);
|
|
37
|
+
return element;
|
|
38
|
+
} catch (error) {
|
|
39
|
+
gardenerError(error);
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
18
42
|
}
|
|
19
43
|
|
|
20
44
|
export function insertText(element, text) {
|
|
21
|
-
element
|
|
45
|
+
if (!element) {
|
|
46
|
+
console.warn('insertText: Element is null or undefined');
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
element.textContent = text;
|
|
22
50
|
}
|
|
23
51
|
|
|
24
52
|
export function replaceElement(original, New) {
|
|
25
|
-
|
|
26
|
-
original
|
|
53
|
+
try {
|
|
54
|
+
if (typeof original === 'string') {
|
|
55
|
+
original = fetchElement(original);
|
|
56
|
+
}
|
|
57
|
+
if (!original) {
|
|
58
|
+
throw new Error('Original element is null or undefined');
|
|
59
|
+
}
|
|
60
|
+
if (!New) {
|
|
61
|
+
throw new Error('New element is null or undefined');
|
|
62
|
+
}
|
|
63
|
+
original.replaceWith(New);
|
|
64
|
+
} catch (error) {
|
|
65
|
+
gardenerError(error);
|
|
27
66
|
}
|
|
28
|
-
original.replaceWith(New);
|
|
29
67
|
}
|
|
30
68
|
|
|
31
69
|
export function gardener(Dom) {
|
|
70
|
+
try {
|
|
71
|
+
if (!Dom) {
|
|
72
|
+
throw new Error('DOM configuration is null or undefined');
|
|
73
|
+
}
|
|
32
74
|
|
|
33
|
-
|
|
34
|
-
// detect if this is an SVG element
|
|
35
|
-
const isSVG = [
|
|
36
|
-
'svg', 'path', 'circle', 'rect', 'line', 'polygon', 'polyline', 'g', 'defs', 'clipPath', 'use'
|
|
37
|
-
].includes(Dom.t);
|
|
75
|
+
if (Dom.nodeType === 1) return Dom;
|
|
38
76
|
|
|
39
|
-
|
|
40
|
-
|
|
77
|
+
if (!Dom.t) {
|
|
78
|
+
throw new Error('Element type (t) is required in DOM configuration');
|
|
79
|
+
}
|
|
41
80
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
}
|
|
47
|
-
else {
|
|
48
|
-
element = createElement(Dom.t, Dom.cn);
|
|
49
|
-
}
|
|
81
|
+
// detect if this is an SVG element
|
|
82
|
+
const isSVG = [
|
|
83
|
+
'svg', 'path', 'circle', 'rect', 'line', 'polygon', 'polyline', 'g', 'defs', 'clipPath', 'use'
|
|
84
|
+
].includes(Dom.t);
|
|
50
85
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
86
|
+
// create element accordingly
|
|
87
|
+
let element;
|
|
88
|
+
|
|
89
|
+
if (isSVG) {
|
|
90
|
+
element = document.createElementNS('http://www.w3.org/2000/svg', Dom.t);
|
|
91
|
+
if (Dom.cn)
|
|
92
|
+
element.classList.add(...Dom.cn);
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
element = createElement(Dom.t, Dom.cn);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
if (!element) {
|
|
99
|
+
throw new Error(`Failed to create element: ${Dom.t}`);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// text content (skip for SVG like <path>)
|
|
103
|
+
if (Dom.txt) {
|
|
104
|
+
insertText(element, Dom.txt);
|
|
105
|
+
}
|
|
55
106
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
107
|
+
// apply attributes safely
|
|
108
|
+
const propertyNames = new Set([
|
|
109
|
+
'value', 'selected', 'muted', 'disabled',
|
|
110
|
+
'selectedIndex', 'volume', // etc.
|
|
111
|
+
]);
|
|
112
|
+
|
|
113
|
+
if (Dom.attr) {
|
|
114
|
+
for (const [key, value] of Object.entries(Dom.attr)) {
|
|
115
|
+
try {
|
|
116
|
+
if (isSVG || key.startsWith('data-') || key.startsWith('aria-')) {
|
|
117
|
+
element.setAttribute(key, value);
|
|
118
|
+
} else if (key in element && !propertyNames.has(key)) {
|
|
119
|
+
// Prefer property for known safe cases
|
|
120
|
+
try { element[key] = value === '' ? true : value; } catch (e) { element.setAttribute(key, value); }
|
|
121
|
+
} else {
|
|
122
|
+
element.setAttribute(key, value);
|
|
123
|
+
}
|
|
124
|
+
} catch (attrError) {
|
|
125
|
+
console.warn(`Failed to set attribute ${key}:`, attrError);
|
|
126
|
+
}
|
|
71
127
|
}
|
|
72
128
|
}
|
|
73
|
-
}
|
|
74
129
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
130
|
+
if (Dom.events) {
|
|
131
|
+
Object.entries(Dom.events).forEach(([eventName, handler]) => {
|
|
132
|
+
try {
|
|
133
|
+
if (typeof handler !== 'function') {
|
|
134
|
+
throw new Error(`Event handler for '${eventName}' must be a function`);
|
|
135
|
+
}
|
|
136
|
+
element.addEventListener(eventName, handler);
|
|
137
|
+
} catch (eventError) {
|
|
138
|
+
console.warn(`Failed to add event listener ${eventName}:`, eventError);
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
}
|
|
80
142
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
143
|
+
// recursively handle children
|
|
144
|
+
if (Dom.children) {
|
|
145
|
+
Dom.children.forEach(child => {
|
|
146
|
+
try {
|
|
147
|
+
appendElement(element, gardener(child));
|
|
148
|
+
} catch (childError) {
|
|
149
|
+
console.warn('Failed to append child:', childError);
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
}
|
|
85
153
|
|
|
86
|
-
|
|
154
|
+
return element;
|
|
155
|
+
} catch (error) {
|
|
156
|
+
gardenerError(error);
|
|
157
|
+
return null;
|
|
158
|
+
}
|
|
87
159
|
}
|
|
88
160
|
|
|
89
|
-
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export const mode = 'prod';
|
|
1
|
+
export const mode = 'prod';
|