elegance-js 1.2.3 → 1.4.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.
package/dist/build.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ export declare const processPageElements: (element: Child, objectAttributes: Array<any>, parent: Child) => Child;
1
2
  type CompilationOptions = {
2
3
  postCompile?: () => any;
3
4
  preCompile?: () => any;
package/dist/build.mjs CHANGED
@@ -248,6 +248,10 @@ var initializeState = () => globalThis.__SERVER_CURRENT_STATE__ = [];
248
248
  var getState = () => {
249
249
  return globalThis.__SERVER_CURRENT_STATE__;
250
250
  };
251
+ var initializeObjectAttributes = () => globalThis.__SERVER_CURRENT_OBJECT_ATTRIBUTES__ = [];
252
+ var getObjectAttributes = () => {
253
+ return globalThis.__SERVER_CURRENT_OBJECT_ATTRIBUTES__;
254
+ };
251
255
 
252
256
  // src/server/loadHook.ts
253
257
  var resetLoadHooks = () => globalThis.__SERVER_CURRENT_LOADHOOKS__ = [];
@@ -770,7 +774,7 @@ var generateClientPageData = async (pageLocation, state, objectAttributes, pageL
770
774
  clientPageJSText += "if(!globalThis.pd) { globalThis.pd = {}; globalThis.pd[url] = data}";
771
775
  const pageDataPath = path.join(pageLocation, `${pageName}_data.js`);
772
776
  let sendHardReloadInstruction = false;
773
- const transformedResult = await esbuild.transform(clientPageJSText, { minify: true }).catch((error) => {
777
+ const transformedResult = await esbuild.transform(clientPageJSText, { minify: options.environment === "production" }).catch((error) => {
774
778
  console.error("Failed to transform client page js!", error);
775
779
  });
776
780
  if (!transformedResult) return { sendHardReloadInstruction };
@@ -797,6 +801,7 @@ var buildPages = async (DIST_DIR) => {
797
801
  }
798
802
  fs2.rmSync(filePath, { force: true });
799
803
  initializeState();
804
+ initializeObjectAttributes();
800
805
  resetLoadHooks();
801
806
  let pageElements;
802
807
  let metadata;
@@ -809,7 +814,7 @@ var buildPages = async (DIST_DIR) => {
809
814
  metadata = pageMetadata;
810
815
  } catch (e) {
811
816
  fs2.rmSync(tempPath, { force: true });
812
- throw `Error in Page: ${directory === "" ? "/" : directory}${file.name} - ${e}`;
817
+ throw new Error(`Error in Page: ${directory === "" ? "/" : directory}${file.name} - ${e}`);
813
818
  }
814
819
  fs2.rmSync(tempPath, { force: true });
815
820
  if (!metadata || metadata && typeof metadata !== "function") {
@@ -823,7 +828,8 @@ var buildPages = async (DIST_DIR) => {
823
828
  }
824
829
  const state = getState();
825
830
  const pageLoadHooks = getLoadHooks();
826
- const objectAttributes = await generateSuitablePageElements(
831
+ const objectAttributes = getObjectAttributes();
832
+ const foundObjectAttributes = await generateSuitablePageElements(
827
833
  file.parentPath,
828
834
  pageElements || body(),
829
835
  metadata ?? (() => head()),
@@ -835,7 +841,7 @@ var buildPages = async (DIST_DIR) => {
835
841
  } = await generateClientPageData(
836
842
  file.parentPath,
837
843
  state || {},
838
- objectAttributes,
844
+ [...objectAttributes, ...foundObjectAttributes],
839
845
  pageLoadHooks || [],
840
846
  DIST_DIR,
841
847
  name
@@ -937,7 +943,12 @@ var build = async (DIST_DIR) => {
937
943
  keepNames: false,
938
944
  banner: {
939
945
  js: "//__ELEGANCE_JS_PAGE_MARKER__"
940
- }
946
+ },
947
+ define: {
948
+ "DEV": options.environment === "development" ? "true" : "false",
949
+ "PROD": options.environment === "development" ? "false" : "true"
950
+ },
951
+ external: ["fs"]
941
952
  });
942
953
  await esbuild.build({
943
954
  entryPoints: [
@@ -954,7 +965,11 @@ var build = async (DIST_DIR) => {
954
965
  },
955
966
  format: "esm",
956
967
  platform: "node",
957
- keepNames: false
968
+ keepNames: false,
969
+ define: {
970
+ "DEV": options.environment === "development" ? "true" : "false",
971
+ "PROD": options.environment === "development" ? "false" : "true"
972
+ }
958
973
  });
959
974
  }
960
975
  const pagesTranspiled = performance.now();
@@ -1067,5 +1082,6 @@ var compile = async (props) => {
1067
1082
  if (!success) return;
1068
1083
  };
1069
1084
  export {
1070
- compile
1085
+ compile,
1086
+ processPageElements
1071
1087
  };
@@ -1 +1 @@
1
- export {};
1
+ import "../shared/bindServerElements";
@@ -1,6 +1,183 @@
1
+ // src/shared/serverElements.ts
2
+ var createBuildableElement = (tag) => {
3
+ return (options, ...children) => ({
4
+ tag,
5
+ options: options || {},
6
+ children
7
+ });
8
+ };
9
+ var createChildrenlessBuildableElement = (tag) => {
10
+ return (options) => ({
11
+ tag,
12
+ options: options || {},
13
+ children: null
14
+ });
15
+ };
16
+ var childrenlessElementTags = [
17
+ "area",
18
+ "base",
19
+ "br",
20
+ "col",
21
+ "embed",
22
+ "hr",
23
+ "img",
24
+ "input",
25
+ "link",
26
+ "meta",
27
+ "source",
28
+ "track",
29
+ "path",
30
+ "rect"
31
+ ];
32
+ var elementTags = [
33
+ "a",
34
+ "address",
35
+ "article",
36
+ "aside",
37
+ "audio",
38
+ "blockquote",
39
+ "body",
40
+ "button",
41
+ "canvas",
42
+ "caption",
43
+ "colgroup",
44
+ "data",
45
+ "datalist",
46
+ "dd",
47
+ "del",
48
+ "details",
49
+ "dialog",
50
+ "div",
51
+ "dl",
52
+ "dt",
53
+ "fieldset",
54
+ "figcaption",
55
+ "figure",
56
+ "footer",
57
+ "form",
58
+ "h1",
59
+ "h2",
60
+ "h3",
61
+ "h4",
62
+ "h5",
63
+ "h6",
64
+ "head",
65
+ "header",
66
+ "hgroup",
67
+ "html",
68
+ "iframe",
69
+ "ins",
70
+ "label",
71
+ "legend",
72
+ "li",
73
+ "main",
74
+ "map",
75
+ "meter",
76
+ "nav",
77
+ "noscript",
78
+ "object",
79
+ "ol",
80
+ "optgroup",
81
+ "option",
82
+ "output",
83
+ "p",
84
+ "picture",
85
+ "pre",
86
+ "progress",
87
+ "q",
88
+ "section",
89
+ "select",
90
+ "summary",
91
+ "table",
92
+ "tbody",
93
+ "td",
94
+ "template",
95
+ "textarea",
96
+ "tfoot",
97
+ "th",
98
+ "thead",
99
+ "time",
100
+ "tr",
101
+ "ul",
102
+ "video",
103
+ "span",
104
+ "script",
105
+ "abbr",
106
+ "b",
107
+ "bdi",
108
+ "bdo",
109
+ "cite",
110
+ "code",
111
+ "dfn",
112
+ "em",
113
+ "i",
114
+ "kbd",
115
+ "mark",
116
+ "rp",
117
+ "rt",
118
+ "ruby",
119
+ "s",
120
+ "samp",
121
+ "small",
122
+ "strong",
123
+ "sub",
124
+ "sup",
125
+ "u",
126
+ "wbr",
127
+ "title",
128
+ "svg"
129
+ ];
130
+ var elements = {};
131
+ var childrenlessElements = {};
132
+ for (const element of elementTags) {
133
+ elements[element] = createBuildableElement(element);
134
+ }
135
+ for (const element of childrenlessElementTags) {
136
+ childrenlessElements[element] = createChildrenlessBuildableElement(element);
137
+ }
138
+ var allElements = {
139
+ ...elements,
140
+ ...childrenlessElements
141
+ };
142
+
143
+ // src/shared/bindServerElements.ts
144
+ Object.assign(globalThis, elements);
145
+ Object.assign(globalThis, childrenlessElements);
146
+
1
147
  // src/client/client.ts
2
148
  console.log("Elegance.JS is loading..");
3
149
  if (!globalThis.pd) globalThis.pd = {};
150
+ Object.assign(window, {
151
+ observe: (subjects, updateCallback) => {
152
+ return {
153
+ subjects,
154
+ updateCallback,
155
+ isAttribute: true
156
+ };
157
+ },
158
+ /*
159
+ observe: (subjects: ClientSubject[], updateCallback: () => any) => {
160
+ const pageData = pd[currentPage];
161
+
162
+ const keys = [];
163
+
164
+ for (const subject of subjects) {
165
+ const key = subject.id + Date.now();
166
+
167
+ keys.push({
168
+ key: key,
169
+ subject: subject.id,
170
+ });
171
+
172
+ pageData.stateManager.observe(subject, updateCallback, key);
173
+ }
174
+
175
+ return { keys }
176
+ },
177
+ */
178
+ eventListener: () => {
179
+ }
180
+ });
4
181
  var domParser = new DOMParser();
5
182
  var xmlSerializer = new XMLSerializer();
6
183
  var pageStringCache = /* @__PURE__ */ new Map();
@@ -32,6 +209,9 @@ var createStateManager = (subjects) => {
32
209
  };
33
210
  return s;
34
211
  }),
212
+ destroy: (s) => {
213
+ state.subjects.splice(state.subjects.indexOf(s), 1);
214
+ },
35
215
  get: (id, bind) => {
36
216
  if (bind) {
37
217
  return pd[bind].get(id);
@@ -47,6 +227,9 @@ var createStateManager = (subjects) => {
47
227
  observe: (subject, observer, key) => {
48
228
  subject.observers.delete(key);
49
229
  subject.observers.set(key, observer);
230
+ },
231
+ unobserve: (subject, key) => {
232
+ subject.observers.delete(key);
50
233
  }
51
234
  };
52
235
  return state;
@@ -55,6 +238,7 @@ var loadPage = (deprecatedKeys = [], newBreakpoints) => {
55
238
  const fixedUrl = new URL(loc.href);
56
239
  fixedUrl.pathname = sanitizePathname(fixedUrl.pathname);
57
240
  const pathname = fixedUrl.pathname;
241
+ currentPage = pathname;
58
242
  history.replaceState(null, "", fixedUrl.href);
59
243
  let pageData = pd[pathname];
60
244
  if (pd === void 0) {
@@ -91,7 +275,7 @@ var loadPage = (deprecatedKeys = [], newBreakpoints) => {
91
275
  subject.observers = /* @__PURE__ */ new Map();
92
276
  }
93
277
  for (const ooa of pageData.ooa || []) {
94
- const el = doc.querySelector(`[key="${ooa.key}"]`);
278
+ const els = doc.querySelectorAll(`[key="${ooa.key}"]`);
95
279
  let values = {};
96
280
  for (const { id, bind } of ooa.refs) {
97
281
  const subject = state.get(id, bind);
@@ -101,7 +285,9 @@ var loadPage = (deprecatedKeys = [], newBreakpoints) => {
101
285
  try {
102
286
  const newValue = ooa.update(...Object.values(values));
103
287
  let attribute = ooa.attribute === "class" ? "className" : ooa.attribute;
104
- el[attribute] = newValue;
288
+ for (const el of Array.from(els)) {
289
+ el[attribute] = newValue;
290
+ }
105
291
  } catch (e) {
106
292
  console.error(e);
107
293
  return;
@@ -0,0 +1 @@
1
+ export declare const processPageElements: (element: Child, objectAttributes: Array<any>, parent: Child) => Child;
@@ -0,0 +1,117 @@
1
+ // src/client/processPageElements.ts
2
+ var elementKey = 0;
3
+ var processOptionAsObjectAttribute = (element, optionName, optionValue, objectAttributes) => {
4
+ const lcOptionName = optionName.toLowerCase();
5
+ const options = element.options;
6
+ let key = options.key;
7
+ if (key == void 0) {
8
+ elementKey -= 1;
9
+ key = elementKey;
10
+ options.key = key;
11
+ }
12
+ if (!optionValue.type) {
13
+ throw `ObjectAttributeType is missing from object attribute. ${element.tag}: ${optionName}/${optionValue}`;
14
+ }
15
+ let optionFinal = lcOptionName;
16
+ switch (optionValue.type) {
17
+ case 1 /* STATE */:
18
+ const SOA = optionValue;
19
+ if (typeof SOA.value === "function") {
20
+ delete options[optionName];
21
+ break;
22
+ }
23
+ if (lcOptionName === "innertext" || lcOptionName === "innerhtml") {
24
+ element.children = [SOA.value];
25
+ delete options[optionName];
26
+ } else {
27
+ delete options[optionName];
28
+ options[lcOptionName] = SOA.value;
29
+ }
30
+ break;
31
+ case 2 /* OBSERVER */:
32
+ const OOA = optionValue;
33
+ const firstValue = OOA.update(...OOA.initialValues);
34
+ if (lcOptionName === "innertext" || lcOptionName === "innerhtml") {
35
+ element.children = [firstValue];
36
+ delete options[optionName];
37
+ } else {
38
+ delete options[optionName];
39
+ options[lcOptionName] = firstValue;
40
+ }
41
+ optionFinal = optionName;
42
+ break;
43
+ case 4 /* REFERENCE */:
44
+ options["ref"] = optionValue.value;
45
+ break;
46
+ }
47
+ objectAttributes.push({ ...optionValue, key, attribute: optionFinal });
48
+ };
49
+ var processPageElements = (element, objectAttributes, parent) => {
50
+ if (typeof element === "boolean" || typeof element === "number" || Array.isArray(element)) return element;
51
+ if (typeof element === "string") {
52
+ return element;
53
+ }
54
+ const processElementOptionsAsChildAndReturn = () => {
55
+ const children = element.children;
56
+ element.children = [
57
+ element.options,
58
+ ...children
59
+ ];
60
+ element.options = {};
61
+ for (let i = 0; i < children.length + 1; i++) {
62
+ const child = element.children[i];
63
+ const processedChild = processPageElements(child, objectAttributes, element);
64
+ element.children[i] = processedChild;
65
+ }
66
+ return {
67
+ ...element,
68
+ options: {}
69
+ };
70
+ };
71
+ if (typeof element.options !== "object") {
72
+ return processElementOptionsAsChildAndReturn();
73
+ }
74
+ const {
75
+ tag: elementTag,
76
+ options: elementOptions,
77
+ children: elementChildren
78
+ } = element.options;
79
+ if (elementTag && elementOptions && elementChildren) {
80
+ return processElementOptionsAsChildAndReturn();
81
+ }
82
+ const options = element.options;
83
+ for (const [optionName, optionValue] of Object.entries(options)) {
84
+ const lcOptionName = optionName.toLowerCase();
85
+ if (typeof optionValue !== "object") {
86
+ if (lcOptionName === "innertext") {
87
+ delete options[optionName];
88
+ if (element.children === null) {
89
+ throw `Cannot use innerText or innerHTML on childrenless elements.`;
90
+ }
91
+ element.children = [optionValue, ...element.children];
92
+ continue;
93
+ } else if (lcOptionName === "innerhtml") {
94
+ if (element.children === null) {
95
+ throw `Cannot use innerText or innerHTML on childrenless elements.`;
96
+ }
97
+ delete options[optionName];
98
+ element.children = [optionValue];
99
+ continue;
100
+ }
101
+ continue;
102
+ }
103
+ ;
104
+ processOptionAsObjectAttribute(element, optionName, optionValue, objectAttributes);
105
+ }
106
+ if (element.children) {
107
+ for (let i = 0; i < element.children.length; i++) {
108
+ const child = element.children[i];
109
+ const processedChild = processPageElements(child, objectAttributes, element);
110
+ element.children[i] = processedChild;
111
+ }
112
+ }
113
+ return element;
114
+ };
115
+ export {
116
+ processPageElements
117
+ };
@@ -0,0 +1 @@
1
+ export declare const renderRecursively: (element: Child) => HTMLElement | DocumentFragment | Text | null;
@@ -0,0 +1,41 @@
1
+ // src/client/render.ts
2
+ var renderRecursively = (element) => {
3
+ if (typeof element === "boolean") {
4
+ return null;
5
+ }
6
+ if (typeof element === "number" || typeof element === "string") {
7
+ return document.createTextNode(element.toString());
8
+ }
9
+ if (Array.isArray(element)) {
10
+ const fragment = document.createDocumentFragment();
11
+ element.forEach((item) => {
12
+ const childNode = renderRecursively(item);
13
+ if (childNode) fragment.appendChild(childNode);
14
+ });
15
+ return fragment;
16
+ }
17
+ const domElement = document.createElement(element.tag);
18
+ if (typeof element.options === "object" && element.options !== null) {
19
+ for (const [attrName, attrValue] of Object.entries(element.options)) {
20
+ if (typeof attrValue === "object") {
21
+ throw new Error(`Attr ${attrName} for element ${element.tag} has object type. Got: ${JSON.stringify(element)}`);
22
+ }
23
+ domElement.setAttribute(attrName.toLowerCase(), attrValue);
24
+ }
25
+ }
26
+ if (element.children !== null) {
27
+ if (Array.isArray(element.children)) {
28
+ element.children.forEach((child) => {
29
+ const childNode = renderRecursively(child);
30
+ if (childNode) domElement.appendChild(childNode);
31
+ });
32
+ } else {
33
+ const childNode = renderRecursively(element.children);
34
+ if (childNode) domElement.appendChild(childNode);
35
+ }
36
+ }
37
+ return domElement;
38
+ };
39
+ export {
40
+ renderRecursively
41
+ };
@@ -251,6 +251,10 @@ var initializeState = () => globalThis.__SERVER_CURRENT_STATE__ = [];
251
251
  var getState = () => {
252
252
  return globalThis.__SERVER_CURRENT_STATE__;
253
253
  };
254
+ var initializeObjectAttributes = () => globalThis.__SERVER_CURRENT_OBJECT_ATTRIBUTES__ = [];
255
+ var getObjectAttributes = () => {
256
+ return globalThis.__SERVER_CURRENT_OBJECT_ATTRIBUTES__;
257
+ };
254
258
 
255
259
  // src/server/loadHook.ts
256
260
  var resetLoadHooks = () => globalThis.__SERVER_CURRENT_LOADHOOKS__ = [];
@@ -773,7 +777,7 @@ var generateClientPageData = async (pageLocation, state, objectAttributes, pageL
773
777
  clientPageJSText += "if(!globalThis.pd) { globalThis.pd = {}; globalThis.pd[url] = data}";
774
778
  const pageDataPath = path.join(pageLocation, `${pageName}_data.js`);
775
779
  let sendHardReloadInstruction = false;
776
- const transformedResult = await esbuild.transform(clientPageJSText, { minify: true }).catch((error) => {
780
+ const transformedResult = await esbuild.transform(clientPageJSText, { minify: options.environment === "production" }).catch((error) => {
777
781
  console.error("Failed to transform client page js!", error);
778
782
  });
779
783
  if (!transformedResult) return { sendHardReloadInstruction };
@@ -800,6 +804,7 @@ var buildPages = async (DIST_DIR) => {
800
804
  }
801
805
  fs2.rmSync(filePath, { force: true });
802
806
  initializeState();
807
+ initializeObjectAttributes();
803
808
  resetLoadHooks();
804
809
  let pageElements;
805
810
  let metadata;
@@ -812,7 +817,7 @@ var buildPages = async (DIST_DIR) => {
812
817
  metadata = pageMetadata;
813
818
  } catch (e) {
814
819
  fs2.rmSync(tempPath, { force: true });
815
- throw `Error in Page: ${directory === "" ? "/" : directory}${file.name} - ${e}`;
820
+ throw new Error(`Error in Page: ${directory === "" ? "/" : directory}${file.name} - ${e}`);
816
821
  }
817
822
  fs2.rmSync(tempPath, { force: true });
818
823
  if (!metadata || metadata && typeof metadata !== "function") {
@@ -826,7 +831,8 @@ var buildPages = async (DIST_DIR) => {
826
831
  }
827
832
  const state = getState();
828
833
  const pageLoadHooks = getLoadHooks();
829
- const objectAttributes = await generateSuitablePageElements(
834
+ const objectAttributes = getObjectAttributes();
835
+ const foundObjectAttributes = await generateSuitablePageElements(
830
836
  file.parentPath,
831
837
  pageElements || body(),
832
838
  metadata ?? (() => head()),
@@ -838,7 +844,7 @@ var buildPages = async (DIST_DIR) => {
838
844
  } = await generateClientPageData(
839
845
  file.parentPath,
840
846
  state || {},
841
- objectAttributes,
847
+ [...objectAttributes, ...foundObjectAttributes],
842
848
  pageLoadHooks || [],
843
849
  DIST_DIR,
844
850
  name
@@ -940,7 +946,12 @@ var build = async (DIST_DIR) => {
940
946
  keepNames: false,
941
947
  banner: {
942
948
  js: "//__ELEGANCE_JS_PAGE_MARKER__"
943
- }
949
+ },
950
+ define: {
951
+ "DEV": options.environment === "development" ? "true" : "false",
952
+ "PROD": options.environment === "development" ? "false" : "true"
953
+ },
954
+ external: ["fs"]
944
955
  });
945
956
  await esbuild.build({
946
957
  entryPoints: [
@@ -957,7 +968,11 @@ var build = async (DIST_DIR) => {
957
968
  },
958
969
  format: "esm",
959
970
  platform: "node",
960
- keepNames: false
971
+ keepNames: false,
972
+ define: {
973
+ "DEV": options.environment === "development" ? "true" : "false",
974
+ "PROD": options.environment === "development" ? "false" : "true"
975
+ }
961
976
  });
962
977
  }
963
978
  const pagesTranspiled = performance.now();
@@ -1,3 +1,9 @@
1
+ // src/internal/deprecate.ts
2
+ var ShowDeprecationWarning = (msg) => {
3
+ console.warn("\x1B[31m", msg);
4
+ console.trace("Stack Trace:");
5
+ };
6
+
1
7
  // src/server/createState.ts
2
8
  if (!globalThis.__SERVER_CURRENT_STATE_ID__) {
3
9
  globalThis.__SERVER_CURRENT_STATE_ID__ = 0;
@@ -8,6 +14,7 @@ var createEventListener = ({
8
14
  dependencies = [],
9
15
  params
10
16
  }) => {
17
+ ShowDeprecationWarning("WARNING: The createEventListener() and function is deprecated. Please use eventListener() instead, from elegance-js/state.");
11
18
  const deps = dependencies.map((dep) => ({ id: dep.id, bind: dep.bind }));
12
19
  let dependencyString = "[";
13
20
  for (const dep of deps) {
@@ -31,6 +38,7 @@ var createEventListener = ({
31
38
 
32
39
  // src/server/loadHook.ts
33
40
  var createLoadHook = (options) => {
41
+ ShowDeprecationWarning("WARNING: createLoadHook() is a deprecated function. Use loadHook() from elegance-js/loadHook instead.");
34
42
  const stringFn = options.fn.toString();
35
43
  const deps = (options.deps || []).map((dep) => ({
36
44
  id: dep.id,
@@ -0,0 +1,18 @@
1
+ import { ObjectAttributeType } from "../helpers/ObjectAttributeType";
2
+ type ClientSubjectGeneric<T> = Omit<ClientSubject, "value"> & {
3
+ value: T;
4
+ };
5
+ type ServerSubject = {
6
+ type: ObjectAttributeType;
7
+ value: unknown;
8
+ id: number;
9
+ bind?: string;
10
+ };
11
+ type ListOptions<T extends ServerSubject[]> = {
12
+ template: (...subjects: {
13
+ [K in keyof T]: ClientSubjectGeneric<T[K]["value"]>;
14
+ }) => Child;
15
+ deps?: [...T];
16
+ };
17
+ declare const List: <T extends ServerSubject[]>(options: ListOptions<T>) => void;
18
+ export { List };
@@ -0,0 +1,75 @@
1
+ // src/server/loadHook.ts
2
+ var loadHook = (deps, fn, bind) => {
3
+ const stringFn = fn.toString();
4
+ const depsArray = (deps || []).map((dep) => ({
5
+ id: dep.id,
6
+ bind: dep.bind
7
+ }));
8
+ let dependencyString = "[";
9
+ for (const dep of depsArray) {
10
+ dependencyString += `{id:${dep.id}`;
11
+ if (dep.bind) dependencyString += `,bind:${dep.bind}`;
12
+ dependencyString += `},`;
13
+ }
14
+ dependencyString += "]";
15
+ const isAsync = fn.constructor.name === "AsyncFunction";
16
+ const wrapperFn = isAsync ? `async (state) => await (${stringFn})(state, ...state.getAll(${dependencyString}))` : `(state) => (${stringFn})(state, ...state.getAll(${dependencyString}))`;
17
+ globalThis.__SERVER_CURRENT_LOADHOOKS__.push({
18
+ fn: wrapperFn,
19
+ bind: bind || ""
20
+ });
21
+ };
22
+
23
+ // src/server/state.ts
24
+ if (!globalThis.__SERVER_CURRENT_STATE_ID__) {
25
+ globalThis.__SERVER_CURRENT_STATE_ID__ = 0;
26
+ }
27
+ var currentId = globalThis.__SERVER_CURRENT_STATE_ID__;
28
+ var state = (value2, options) => {
29
+ const serverStateEntry = {
30
+ id: currentId += 1,
31
+ value: value2,
32
+ type: 1 /* STATE */,
33
+ bind: options?.bind
34
+ };
35
+ globalThis.__SERVER_CURRENT_STATE__.push(serverStateEntry);
36
+ if (Array.isArray(value2)) {
37
+ serverStateEntry.reactiveMap = reactiveMap;
38
+ }
39
+ return serverStateEntry;
40
+ };
41
+ var reactiveMap = (template, deps) => {
42
+ const strVal = template.toString();
43
+ console.log(strVal);
44
+ const id = currentId += 1;
45
+ const subject = void 0;
46
+ loadHook(
47
+ [subject],
48
+ (state2, subject2) => {
49
+ const el = document.querySelector(`[map-id]=${id}`);
50
+ if (!el) return;
51
+ const trackedElement = el.previousSibling;
52
+ if (!trackedElement) return;
53
+ state2.observe(subject2, () => {
54
+ console.log(trackedElement);
55
+ });
56
+ }
57
+ );
58
+ return div({
59
+ "map-id": id
60
+ });
61
+ };
62
+
63
+ // src/components/List.ts
64
+ var value = state([2, 3, "hi"]);
65
+ var List = (options) => {
66
+ };
67
+ div(
68
+ value.reactiveMap((item) => div(
69
+ {},
70
+ item
71
+ ))
72
+ );
73
+ export {
74
+ List
75
+ };