@torpor/view 0.4.14 → 0.4.15

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@torpor/view",
3
- "version": "0.4.14",
3
+ "version": "0.4.15",
4
4
  "description": "Torpor's view library, for writing and mounting components",
5
5
  "type": "module",
6
6
  "exports": {
@@ -134,6 +134,9 @@ export default function buildComponentNode(
134
134
  runs.push(`${propsName}["${name}"] = ${value};`);
135
135
  }
136
136
  } else if (value != null) {
137
+ if (name === "class" && node.scopeStyles) {
138
+ value = `"${trimQuotes(value)} torp-${status.styleHash}"`;
139
+ }
137
140
  props.push({
138
141
  name,
139
142
  preText: "",
@@ -43,20 +43,32 @@ export default function Class() {
43
43
  Class nested
44
44
  </div>
45
45
 
46
- <Child class={{ "child-class": true }} />
46
+ <Child class={{ "child-class": true }}>
47
+ Child class 1
48
+ </Child>
49
+
50
+ <Child class="pink">
51
+ Child class 2
52
+ </Child>
47
53
  }
48
54
 
49
55
  @style {
50
56
  div {
51
57
  color: blue;
52
58
  }
59
+
60
+ .pink {
61
+ color: pink;
62
+ }
53
63
  }
54
64
  }
55
65
 
56
66
  function Child() {
57
67
  @render {
58
68
  <div class={$props.class}>
59
- Child class
69
+ <slot>
70
+ Child class
71
+ </slot>
60
72
  </div>
61
73
  }
62
74
  }
@@ -93,40 +105,40 @@ test("class -- hydrated", async () => {
93
105
 
94
106
  function check(container: HTMLElement, state: Props) {
95
107
  expect(queryByText(container, "From id")).not.toBeNull();
96
- expect(queryByText(container, "From id")).toHaveClass("torp-1ljxz83", {
108
+ expect(queryByText(container, "From id")).toHaveClass("torp-1ouzs8a", {
97
109
  exact: true,
98
110
  });
99
111
 
100
112
  expect(queryByText(container, "From string")).not.toBeNull();
101
- expect(queryByText(container, "From string")).toHaveClass("divclass torp-1ljxz83", {
113
+ expect(queryByText(container, "From string")).toHaveClass("divclass torp-1ouzs8a", {
102
114
  exact: true,
103
115
  });
104
116
 
105
117
  expect(queryByText(container, "From state")).not.toBeNull();
106
- expect(queryByText(container, "From state")).toHaveClass("hello red blue torp-1ljxz83", {
118
+ expect(queryByText(container, "From state")).toHaveClass("hello red blue torp-1ouzs8a", {
107
119
  exact: true,
108
120
  });
109
121
 
110
122
  expect(queryByText(container, "From state with scope")).not.toBeNull();
111
123
  expect(queryByText(container, "From state with scope")).toHaveClass(
112
- "hello red blue torp-1ljxz83",
124
+ "hello red blue torp-1ouzs8a",
113
125
  {
114
126
  exact: true,
115
127
  },
116
128
  );
117
129
 
118
130
  expect(queryByText(container, "Class object")).not.toBeNull();
119
- expect(queryByText(container, "Class object")).toHaveClass("foo baz torp-1ljxz83", {
131
+ expect(queryByText(container, "Class object")).toHaveClass("foo baz torp-1ouzs8a", {
120
132
  exact: true,
121
133
  });
122
134
 
123
135
  expect(queryByText(container, "Class array")).not.toBeNull();
124
- expect(queryByText(container, "Class array")).toHaveClass("foo baz torp-1ljxz83", {
136
+ expect(queryByText(container, "Class array")).toHaveClass("foo baz torp-1ouzs8a", {
125
137
  exact: true,
126
138
  });
127
139
 
128
140
  expect(queryByText(container, "Class nested")).not.toBeNull();
129
- expect(queryByText(container, "Class nested")).toHaveClass("foo bar baz qux torp-1ljxz83", {
141
+ expect(queryByText(container, "Class nested")).toHaveClass("foo bar baz qux torp-1ouzs8a", {
130
142
  exact: true,
131
143
  });
132
144
 
@@ -134,13 +146,20 @@ function check(container: HTMLElement, state: Props) {
134
146
  state.green = true;
135
147
  state.blue = false;
136
148
 
137
- expect(queryByText(container, "From state")).toHaveClass("hello red green torp-1ljxz83", {
149
+ expect(queryByText(container, "From state")).toHaveClass("hello red green torp-1ouzs8a", {
138
150
  exact: true,
139
151
  });
140
152
 
141
153
  // Components
142
- expect(queryByText(container, "Child class")).not.toBeNull();
143
- expect(queryByText(container, "Child class")).toHaveClass("child-class torp-1ljxz83", {
154
+ expect(queryByText(container, "Child class 1")).not.toBeNull();
155
+ expect(queryByText(container, "Child class 1")).toHaveClass("child-class torp-1ouzs8a", {
156
+ exact: true,
157
+ });
158
+
159
+ // Should get a bit fancier than this i.e. if a class is set on a component,
160
+ // ONLY that class gets the style hash added
161
+ expect(queryByText(container, "Child class 2")).not.toBeNull();
162
+ expect(queryByText(container, "Child class 2")).toHaveClass("pink torp-1ouzs8a", {
144
163
  exact: true,
145
164
  });
146
165
  }
@@ -3,6 +3,7 @@ import $watch from "../../../../src/watch/$watch";
3
3
  import type SlotRender from "../../../../src/types/SlotRender";
4
4
  import t_add_fragment from "../../../../src/render/addFragment";
5
5
  import t_anchor from "../../../../src/render/nodeAnchor";
6
+ import t_child from "../../../../src/render/nodeChild";
6
7
  import t_class from "../../../../src/render/buildClasses";
7
8
  import t_fragment from "../../../../src/render/getFragment";
8
9
  import t_next from "../../../../src/render/nodeNext";
@@ -21,7 +22,7 @@ export default function Class(
21
22
  /* User interface */
22
23
  const t_fragments: DocumentFragment[] = [];
23
24
 
24
- const t_fragment_0 = t_fragment($parent.ownerDocument!, t_fragments, 0, ` <div id="divid" class="torp-1ljxz83"> From id </div> <div class="divclass torp-1ljxz83"> From string </div> <a class="torp-1ljxz83"> From state </a> <div class="torp-1ljxz83"> From state with scope </div> <div class="torp-1ljxz83"> Class object </div> <div class="torp-1ljxz83"> Class array </div> <div class="torp-1ljxz83"> Class nested </div> <!> `);
25
+ const t_fragment_0 = t_fragment($parent.ownerDocument!, t_fragments, 0, ` <div id="divid" class="torp-1ouzs8a"> From id </div> <div class="divclass torp-1ouzs8a"> From string </div> <a class="torp-1ouzs8a"> From state </a> <div class="torp-1ouzs8a"> From state with scope </div> <div class="torp-1ouzs8a"> Class object </div> <div class="torp-1ouzs8a"> Class array </div> <div class="torp-1ouzs8a"> Class nested </div> <!> <!> `);
25
26
  const t_root_0 = t_root(t_fragment_0, true);
26
27
  const t_a_1 = t_next(t_next(t_next(t_next(t_next(t_root_0), true)), true)) as HTMLAnchorElement;
27
28
  const t_div_1 = t_next(t_next(t_a_1, true)) as HTMLDivElement;
@@ -32,23 +33,59 @@ export default function Class(
32
33
 
33
34
  /* @component */
34
35
  const t_props_1 = $watch({
35
- class: t_class({ "child-class": true }, "torp-1ljxz83"),
36
+ class: t_class({ "child-class": true }, "torp-1ouzs8a"),
36
37
  });
37
38
  $run(() => {
38
- t_props_1["class"] = t_class({ "child-class": true }, "torp-1ljxz83");
39
+ t_props_1["class"] = t_class({ "child-class": true }, "torp-1ouzs8a");
39
40
  });
40
- Child(t_fragment_0, t_comp_anchor_1, t_props_1, $context);
41
+ const t_slots_1: Record<string, SlotRender> = {};
42
+ t_slots_1["_"] = (
43
+ $sparent: ParentNode,
44
+ $sanchor: Node | null,
45
+ // @ts-ignore
46
+ $sprops?: Record<PropertyKey, any>,
47
+ // @ts-ignore
48
+ $context?: Record<PropertyKey, any>
49
+ ) => {
50
+ const t_fragment_2 = t_fragment($parent.ownerDocument!, t_fragments, 2, ` Child class 1 `);
51
+ const t_text_1 = t_root(t_fragment_2);
52
+ t_add_fragment(t_fragment_2, $sparent, $sanchor, t_text_1);
53
+ t_next(t_text_1);
54
+ }
55
+ Child(t_fragment_0, t_comp_anchor_1, t_props_1, $context, t_slots_1);
41
56
 
42
- const t_text_1 = t_next(t_comp_anchor_1, true);
57
+ let t_comp_anchor_2 = t_anchor(t_next(t_next(t_comp_anchor_1, true))) as HTMLElement;
58
+
59
+ /* @component */
60
+ const t_props_2 = $watch({
61
+ class: "pink torp-1ouzs8a",
62
+ });
63
+ const t_slots_2: Record<string, SlotRender> = {};
64
+ t_slots_2["_"] = (
65
+ $sparent: ParentNode,
66
+ $sanchor: Node | null,
67
+ // @ts-ignore
68
+ $sprops?: Record<PropertyKey, any>,
69
+ // @ts-ignore
70
+ $context?: Record<PropertyKey, any>
71
+ ) => {
72
+ const t_fragment_4 = t_fragment($parent.ownerDocument!, t_fragments, 4, ` Child class 2 `);
73
+ const t_text_2 = t_root(t_fragment_4);
74
+ t_add_fragment(t_fragment_4, $sparent, $sanchor, t_text_2);
75
+ t_next(t_text_2);
76
+ }
77
+ Child(t_fragment_0, t_comp_anchor_2, t_props_2, $context, t_slots_2);
78
+
79
+ const t_text_3 = t_next(t_comp_anchor_2, true);
43
80
  $run(() => {
44
- t_a_1.className = t_class({ hello: true, red: $props.red, green: $props.green, blue: $props.blue }, "torp-1ljxz83");
45
- t_div_1.className = t_class({ hello: true, red: $props.red, green: $props.green, blue: $props.blue }, "torp-1ljxz83");
46
- t_div_2.className = t_class({ foo: true, bar: false, baz: 5, qux: null }, "torp-1ljxz83");
47
- t_div_3.className = t_class([ "foo", false, true && "baz", undefined ], "torp-1ljxz83");
48
- t_div_4.className = t_class([ "foo", 0, { bar: true }, "", [1 && "baz", ["qux"]] ], "torp-1ljxz83");
81
+ t_a_1.className = t_class({ hello: true, red: $props.red, green: $props.green, blue: $props.blue }, "torp-1ouzs8a");
82
+ t_div_1.className = t_class({ hello: true, red: $props.red, green: $props.green, blue: $props.blue }, "torp-1ouzs8a");
83
+ t_div_2.className = t_class({ foo: true, bar: false, baz: 5, qux: null }, "torp-1ouzs8a");
84
+ t_div_3.className = t_class([ "foo", false, true && "baz", undefined ], "torp-1ouzs8a");
85
+ t_div_4.className = t_class([ "foo", 0, { bar: true }, "", [1 && "baz", ["qux"]] ], "torp-1ouzs8a");
49
86
  });
50
- t_add_fragment(t_fragment_0, $parent, $anchor, t_text_1);
51
- t_next(t_text_1);
87
+ t_add_fragment(t_fragment_0, $parent, $anchor, t_text_3);
88
+ t_next(t_text_3);
52
89
 
53
90
  }
54
91
 
@@ -58,21 +95,29 @@ function Child(
58
95
  $props: Record<PropertyKey, any>,
59
96
  // @ts-ignore
60
97
  $context?: Record<PropertyKey, any>,
61
- // @ts-ignore
62
98
  $slots?: Record<string, SlotRender>
63
99
  ): void {
64
100
 
65
101
  /* User interface */
66
102
  const t_fragments: DocumentFragment[] = [];
67
103
 
68
- const t_fragment_0 = t_fragment($parent.ownerDocument!, t_fragments, 0, ` <div> Child class </div> `);
104
+ const t_fragment_0 = t_fragment($parent.ownerDocument!, t_fragments, 0, ` <div> <!> </div> `);
69
105
  const t_root_0 = t_root(t_fragment_0, true);
70
106
  const t_div_1 = t_next(t_root_0) as HTMLDivElement;
71
- const t_text_1 = t_next(t_div_1, true);
107
+ let t_slot_anchor_1 = t_anchor(t_next(t_child(t_div_1))) as HTMLElement;
108
+ if ($slots && $slots["_"]) {
109
+ $slots["_"](t_div_1, t_slot_anchor_1, undefined, $context)
110
+ } else {
111
+ const t_fragment_1 = t_fragment($parent.ownerDocument!, t_fragments, 1, ` Child class `);
112
+ const t_text_1 = t_root(t_fragment_1);
113
+ t_add_fragment(t_fragment_1, t_div_1, t_slot_anchor_1, t_text_1);
114
+ t_next(t_text_1);
115
+ }
116
+ const t_text_2 = t_next(t_div_1, true);
72
117
  $run(() => {
73
118
  t_div_1.className = t_class($props.class);
74
119
  });
75
- t_add_fragment(t_fragment_0, $parent, $anchor, t_text_1);
76
- t_next(t_text_1);
120
+ t_add_fragment(t_fragment_0, $parent, $anchor, t_text_2);
121
+ t_next(t_text_2);
77
122
 
78
123
  }
@@ -12,17 +12,46 @@ export default function Class(
12
12
  let t_head = "";
13
13
 
14
14
  /* User interface */
15
- t_body += ` <div id="divid" class="torp-1ljxz83"> From id </div> <div class="divclass torp-1ljxz83"> From string </div> <a class="${t_class({ hello: true, red: $props.red, green: $props.green, blue: $props.blue }, "torp-1ljxz83")}"> From state </a> <div class="${t_class({ hello: true, red: $props.red, green: $props.green, blue: $props.blue }, "torp-1ljxz83")}"> From state with scope </div> <div class="${t_class({ foo: true, bar: false, baz: 5, qux: null }, "torp-1ljxz83")}"> Class object </div> <div class="${t_class([ "foo", false, true && "baz", undefined ], "torp-1ljxz83")}"> Class array </div> <div class="${t_class([ "foo", 0, { bar: true }, "", [1 && "baz", ["qux"]] ], "torp-1ljxz83")}"> Class nested </div> <![>`;
15
+ t_body += ` <div id="divid" class="torp-1ouzs8a"> From id </div> <div class="divclass torp-1ouzs8a"> From string </div> <a class="${t_class({ hello: true, red: $props.red, green: $props.green, blue: $props.blue }, "torp-1ouzs8a")}"> From state </a> <div class="${t_class({ hello: true, red: $props.red, green: $props.green, blue: $props.blue }, "torp-1ouzs8a")}"> From state with scope </div> <div class="${t_class({ foo: true, bar: false, baz: 5, qux: null }, "torp-1ouzs8a")}"> Class object </div> <div class="${t_class([ "foo", false, true && "baz", undefined ], "torp-1ouzs8a")}"> Class array </div> <div class="${t_class([ "foo", 0, { bar: true }, "", [1 && "baz", ["qux"]] ], "torp-1ouzs8a")}"> Class nested </div> <![>`;
16
16
  const t_props_1 = {
17
- class: t_class({ "child-class": true }, "torp-1ljxz83"),
17
+ class: t_class({ "child-class": true }, "torp-1ouzs8a"),
18
18
  };
19
- const t_comp_1 = Child(t_props_1, $context);
19
+ const t_slots_1: Record<string, ServerSlotRender> = {};
20
+ t_slots_1["_"] = (
21
+ // @ts-ignore
22
+ $sprops?: Record<PropertyKey, any>,
23
+ // @ts-ignore
24
+ $context?: Record<PropertyKey, any>
25
+ ) => {
26
+ let t_body = "";
27
+ t_body += ` Child class 1 `;
28
+ return t_body;
29
+ }
30
+ const t_comp_1 = Child(t_props_1, $context, t_slots_1);
20
31
  t_body += t_comp_1.body;
21
32
  t_head += t_comp_1.head;
33
+ t_body += `<!]><!> <![>`;
34
+ const t_props_2 = {
35
+ class: t_class("pink", "torp-1ouzs8a"),
36
+ };
37
+ const t_slots_2: Record<string, ServerSlotRender> = {};
38
+ t_slots_2["_"] = (
39
+ // @ts-ignore
40
+ $sprops?: Record<PropertyKey, any>,
41
+ // @ts-ignore
42
+ $context?: Record<PropertyKey, any>
43
+ ) => {
44
+ let t_body = "";
45
+ t_body += ` Child class 2 `;
46
+ return t_body;
47
+ }
48
+ const t_comp_2 = Child(t_props_2, $context, t_slots_2);
49
+ t_body += t_comp_2.body;
50
+ t_head += t_comp_2.head;
22
51
  t_body += `<!]><!> `;
23
52
 
24
53
  /* Style */
25
- t_head += "<style id='1ljxz83'>div.torp-1ljxz83 { color: blue; } </style>";
54
+ t_head += "<style id='1ouzs8a'>div.torp-1ouzs8a { color: blue; } .pink.torp-1ouzs8a { color: pink; } </style>";
26
55
 
27
56
  return { body: t_body, head: t_head };
28
57
  }
@@ -31,14 +60,19 @@ function Child(
31
60
  $props: Record<PropertyKey, any>,
32
61
  // @ts-ignore
33
62
  $context?: Record<PropertyKey, any>,
34
- // @ts-ignore
35
63
  $slots?: Record<string, ServerSlotRender>
36
64
  ): { body: string, head: string } {
37
65
  let t_body = "";
38
66
  let t_head = "";
39
67
 
40
68
  /* User interface */
41
- t_body += ` <div class="${t_class($props.class)}"> Child class </div> `;
69
+ t_body += ` <div class="${t_class($props.class)}"> <![>`;
70
+ if ($slots && $slots["_"]) {
71
+ t_body += $slots["_"](undefined, $context);
72
+ } else {
73
+ t_body += ` Child class `;
74
+ }
75
+ t_body += `<!]><!> </div> `;
42
76
 
43
77
  return { body: t_body, head: t_head };
44
78
  }
@@ -0,0 +1,123 @@
1
+ import $run from "../../../../src/watch/$run";
2
+ import $watch from "../../../../src/watch/$watch";
3
+ import type SlotRender from "../../../../src/types/SlotRender";
4
+ import t_add_fragment from "../../../../src/render/addFragment";
5
+ import t_anchor from "../../../../src/render/nodeAnchor";
6
+ import t_child from "../../../../src/render/nodeChild";
7
+ import t_class from "../../../../src/render/buildClasses";
8
+ import t_fragment from "../../../../src/render/getFragment";
9
+ import t_next from "../../../../src/render/nodeNext";
10
+ import t_root from "../../../../src/render/nodeRoot";
11
+
12
+ export default function Class(
13
+ $parent: ParentNode,
14
+ $anchor: Node | null,
15
+ $props: Record<PropertyKey, any>,
16
+ // @ts-ignore
17
+ $context?: Record<PropertyKey, any>,
18
+ // @ts-ignore
19
+ $slots?: Record<string, SlotRender>
20
+ ): void {
21
+
22
+ /* User interface */
23
+ const t_fragments: DocumentFragment[] = [];
24
+
25
+ const t_fragment_0 = t_fragment($parent.ownerDocument!, t_fragments, 0, ` <div id="divid" class="torp-1ouzs8a"> From id </div> <div class="divclass torp-1ouzs8a"> From string </div> <a class="torp-1ouzs8a"> From state </a> <div class="torp-1ouzs8a"> From state with scope </div> <div class="torp-1ouzs8a"> Class object </div> <div class="torp-1ouzs8a"> Class array </div> <div class="torp-1ouzs8a"> Class nested </div> <!> <!> `);
26
+ const t_root_0 = t_root(t_fragment_0, true);
27
+ const t_a_1 = t_next(t_next(t_next(t_next(t_next(t_root_0), true)), true)) as HTMLAnchorElement;
28
+ const t_div_1 = t_next(t_next(t_a_1, true)) as HTMLDivElement;
29
+ const t_div_2 = t_next(t_next(t_div_1, true)) as HTMLDivElement;
30
+ const t_div_3 = t_next(t_next(t_div_2, true)) as HTMLDivElement;
31
+ const t_div_4 = t_next(t_next(t_div_3, true)) as HTMLDivElement;
32
+ let t_comp_anchor_1 = t_anchor(t_next(t_next(t_div_4, true))) as HTMLElement;
33
+
34
+ /* @component */
35
+ const t_props_1 = $watch({
36
+ class: t_class({ "child-class": true }, "torp-1ouzs8a"),
37
+ });
38
+ $run(() => {
39
+ t_props_1["class"] = t_class({ "child-class": true }, "torp-1ouzs8a");
40
+ });
41
+ const t_slots_1: Record<string, SlotRender> = {};
42
+ t_slots_1["_"] = (
43
+ $sparent: ParentNode,
44
+ $sanchor: Node | null,
45
+ // @ts-ignore
46
+ $sprops?: Record<PropertyKey, any>,
47
+ // @ts-ignore
48
+ $context?: Record<PropertyKey, any>
49
+ ) => {
50
+ const t_fragment_2 = t_fragment($parent.ownerDocument!, t_fragments, 2, ` Child class 1 `);
51
+ const t_text_1 = t_root(t_fragment_2);
52
+ t_add_fragment(t_fragment_2, $sparent, $sanchor, t_text_1);
53
+ t_next(t_text_1);
54
+ }
55
+ Child(t_fragment_0, t_comp_anchor_1, t_props_1, $context, t_slots_1);
56
+
57
+ let t_comp_anchor_2 = t_anchor(t_next(t_next(t_comp_anchor_1, true))) as HTMLElement;
58
+
59
+ /* @component */
60
+ const t_props_2 = $watch({
61
+ class: "pink torp-1ouzs8a",
62
+ });
63
+ const t_slots_2: Record<string, SlotRender> = {};
64
+ t_slots_2["_"] = (
65
+ $sparent: ParentNode,
66
+ $sanchor: Node | null,
67
+ // @ts-ignore
68
+ $sprops?: Record<PropertyKey, any>,
69
+ // @ts-ignore
70
+ $context?: Record<PropertyKey, any>
71
+ ) => {
72
+ const t_fragment_4 = t_fragment($parent.ownerDocument!, t_fragments, 4, ` Child class 2 `);
73
+ const t_text_2 = t_root(t_fragment_4);
74
+ t_add_fragment(t_fragment_4, $sparent, $sanchor, t_text_2);
75
+ t_next(t_text_2);
76
+ }
77
+ Child(t_fragment_0, t_comp_anchor_2, t_props_2, $context, t_slots_2);
78
+
79
+ const t_text_3 = t_next(t_comp_anchor_2, true);
80
+ $run(() => {
81
+ t_a_1.className = t_class({ hello: true, red: $props.red, green: $props.green, blue: $props.blue }, "torp-1ouzs8a");
82
+ t_div_1.className = t_class({ hello: true, red: $props.red, green: $props.green, blue: $props.blue }, "torp-1ouzs8a");
83
+ t_div_2.className = t_class({ foo: true, bar: false, baz: 5, qux: null }, "torp-1ouzs8a");
84
+ t_div_3.className = t_class([ "foo", false, true && "baz", undefined ], "torp-1ouzs8a");
85
+ t_div_4.className = t_class([ "foo", 0, { bar: true }, "", [1 && "baz", ["qux"]] ], "torp-1ouzs8a");
86
+ });
87
+ t_add_fragment(t_fragment_0, $parent, $anchor, t_text_3);
88
+ t_next(t_text_3);
89
+
90
+ }
91
+
92
+ function Child(
93
+ $parent: ParentNode,
94
+ $anchor: Node | null,
95
+ $props: Record<PropertyKey, any>,
96
+ // @ts-ignore
97
+ $context?: Record<PropertyKey, any>,
98
+ $slots?: Record<string, SlotRender>
99
+ ): void {
100
+
101
+ /* User interface */
102
+ const t_fragments: DocumentFragment[] = [];
103
+
104
+ const t_fragment_0 = t_fragment($parent.ownerDocument!, t_fragments, 0, ` <div> <!> </div> `);
105
+ const t_root_0 = t_root(t_fragment_0, true);
106
+ const t_div_1 = t_next(t_root_0) as HTMLDivElement;
107
+ let t_slot_anchor_1 = t_anchor(t_next(t_child(t_div_1))) as HTMLElement;
108
+ if ($slots && $slots["_"]) {
109
+ $slots["_"](t_div_1, t_slot_anchor_1, undefined, $context)
110
+ } else {
111
+ const t_fragment_1 = t_fragment($parent.ownerDocument!, t_fragments, 1, ` Child class `);
112
+ const t_text_1 = t_root(t_fragment_1);
113
+ t_add_fragment(t_fragment_1, t_div_1, t_slot_anchor_1, t_text_1);
114
+ t_next(t_text_1);
115
+ }
116
+ const t_text_2 = t_next(t_div_1, true);
117
+ $run(() => {
118
+ t_div_1.className = t_class($props.class);
119
+ });
120
+ t_add_fragment(t_fragment_0, $parent, $anchor, t_text_2);
121
+ t_next(t_text_2);
122
+
123
+ }
@@ -0,0 +1,78 @@
1
+ import type ServerSlotRender from "../../../../src/types/ServerSlotRender";
2
+ import t_class from "../../../../src/render/buildClasses";
3
+
4
+ export default function Class(
5
+ $props: Record<PropertyKey, any>,
6
+ // @ts-ignore
7
+ $context?: Record<PropertyKey, any>,
8
+ // @ts-ignore
9
+ $slots?: Record<string, ServerSlotRender>
10
+ ): { body: string, head: string } {
11
+ let t_body = "";
12
+ let t_head = "";
13
+
14
+ /* User interface */
15
+ t_body += ` <div id="divid" class="torp-1ouzs8a"> From id </div> <div class="divclass torp-1ouzs8a"> From string </div> <a class="${t_class({ hello: true, red: $props.red, green: $props.green, blue: $props.blue }, "torp-1ouzs8a")}"> From state </a> <div class="${t_class({ hello: true, red: $props.red, green: $props.green, blue: $props.blue }, "torp-1ouzs8a")}"> From state with scope </div> <div class="${t_class({ foo: true, bar: false, baz: 5, qux: null }, "torp-1ouzs8a")}"> Class object </div> <div class="${t_class([ "foo", false, true && "baz", undefined ], "torp-1ouzs8a")}"> Class array </div> <div class="${t_class([ "foo", 0, { bar: true }, "", [1 && "baz", ["qux"]] ], "torp-1ouzs8a")}"> Class nested </div> <![>`;
16
+ const t_props_1 = {
17
+ class: t_class({ "child-class": true }, "torp-1ouzs8a"),
18
+ };
19
+ const t_slots_1: Record<string, ServerSlotRender> = {};
20
+ t_slots_1["_"] = (
21
+ // @ts-ignore
22
+ $sprops?: Record<PropertyKey, any>,
23
+ // @ts-ignore
24
+ $context?: Record<PropertyKey, any>
25
+ ) => {
26
+ let t_body = "";
27
+ t_body += ` Child class 1 `;
28
+ return t_body;
29
+ }
30
+ const t_comp_1 = Child(t_props_1, $context, t_slots_1);
31
+ t_body += t_comp_1.body;
32
+ t_head += t_comp_1.head;
33
+ t_body += `<!]><!> <![>`;
34
+ const t_props_2 = {
35
+ class: t_class("pink", "torp-1ouzs8a"),
36
+ };
37
+ const t_slots_2: Record<string, ServerSlotRender> = {};
38
+ t_slots_2["_"] = (
39
+ // @ts-ignore
40
+ $sprops?: Record<PropertyKey, any>,
41
+ // @ts-ignore
42
+ $context?: Record<PropertyKey, any>
43
+ ) => {
44
+ let t_body = "";
45
+ t_body += ` Child class 2 `;
46
+ return t_body;
47
+ }
48
+ const t_comp_2 = Child(t_props_2, $context, t_slots_2);
49
+ t_body += t_comp_2.body;
50
+ t_head += t_comp_2.head;
51
+ t_body += `<!]><!> `;
52
+
53
+ /* Style */
54
+ t_head += "<style id='1ouzs8a'>div.torp-1ouzs8a { color: blue; } .pink.torp-1ouzs8a { color: pink; } </style>";
55
+
56
+ return { body: t_body, head: t_head };
57
+ }
58
+
59
+ function Child(
60
+ $props: Record<PropertyKey, any>,
61
+ // @ts-ignore
62
+ $context?: Record<PropertyKey, any>,
63
+ $slots?: Record<string, ServerSlotRender>
64
+ ): { body: string, head: string } {
65
+ let t_body = "";
66
+ let t_head = "";
67
+
68
+ /* User interface */
69
+ t_body += ` <div class="${t_class($props.class)}"> <![>`;
70
+ if ($slots && $slots["_"]) {
71
+ t_body += $slots["_"](undefined, $context);
72
+ } else {
73
+ t_body += ` Child class `;
74
+ }
75
+ t_body += `<!]><!> </div> `;
76
+
77
+ return { body: t_body, head: t_head };
78
+ }
@@ -1,78 +0,0 @@
1
- import $run from "../../../../src/watch/$run";
2
- import $watch from "../../../../src/watch/$watch";
3
- import type SlotRender from "../../../../src/types/SlotRender";
4
- import t_add_fragment from "../../../../src/render/addFragment";
5
- import t_anchor from "../../../../src/render/nodeAnchor";
6
- import t_class from "../../../../src/render/buildClasses";
7
- import t_fragment from "../../../../src/render/getFragment";
8
- import t_next from "../../../../src/render/nodeNext";
9
- import t_root from "../../../../src/render/nodeRoot";
10
-
11
- export default function Class(
12
- $parent: ParentNode,
13
- $anchor: Node | null,
14
- $props: Record<PropertyKey, any>,
15
- // @ts-ignore
16
- $context?: Record<PropertyKey, any>,
17
- // @ts-ignore
18
- $slots?: Record<string, SlotRender>
19
- ): void {
20
-
21
- /* User interface */
22
- const t_fragments: DocumentFragment[] = [];
23
-
24
- const t_fragment_0 = t_fragment($parent.ownerDocument!, t_fragments, 0, ` <div id="divid" class="torp-1ljxz83"> From id </div> <div class="divclass torp-1ljxz83"> From string </div> <a class="torp-1ljxz83"> From state </a> <div class="torp-1ljxz83"> From state with scope </div> <div class="torp-1ljxz83"> Class object </div> <div class="torp-1ljxz83"> Class array </div> <div class="torp-1ljxz83"> Class nested </div> <!> `);
25
- const t_root_0 = t_root(t_fragment_0, true);
26
- const t_a_1 = t_next(t_next(t_next(t_next(t_next(t_root_0), true)), true)) as HTMLAnchorElement;
27
- const t_div_1 = t_next(t_next(t_a_1, true)) as HTMLDivElement;
28
- const t_div_2 = t_next(t_next(t_div_1, true)) as HTMLDivElement;
29
- const t_div_3 = t_next(t_next(t_div_2, true)) as HTMLDivElement;
30
- const t_div_4 = t_next(t_next(t_div_3, true)) as HTMLDivElement;
31
- let t_comp_anchor_1 = t_anchor(t_next(t_next(t_div_4, true))) as HTMLElement;
32
-
33
- /* @component */
34
- const t_props_1 = $watch({
35
- class: t_class({ "child-class": true }, "torp-1ljxz83"),
36
- });
37
- $run(() => {
38
- t_props_1["class"] = t_class({ "child-class": true }, "torp-1ljxz83");
39
- });
40
- Child(t_fragment_0, t_comp_anchor_1, t_props_1, $context);
41
-
42
- const t_text_1 = t_next(t_comp_anchor_1, true);
43
- $run(() => {
44
- t_a_1.className = t_class({ hello: true, red: $props.red, green: $props.green, blue: $props.blue }, "torp-1ljxz83");
45
- t_div_1.className = t_class({ hello: true, red: $props.red, green: $props.green, blue: $props.blue }, "torp-1ljxz83");
46
- t_div_2.className = t_class({ foo: true, bar: false, baz: 5, qux: null }, "torp-1ljxz83");
47
- t_div_3.className = t_class([ "foo", false, true && "baz", undefined ], "torp-1ljxz83");
48
- t_div_4.className = t_class([ "foo", 0, { bar: true }, "", [1 && "baz", ["qux"]] ], "torp-1ljxz83");
49
- });
50
- t_add_fragment(t_fragment_0, $parent, $anchor, t_text_1);
51
- t_next(t_text_1);
52
-
53
- }
54
-
55
- function Child(
56
- $parent: ParentNode,
57
- $anchor: Node | null,
58
- $props: Record<PropertyKey, any>,
59
- // @ts-ignore
60
- $context?: Record<PropertyKey, any>,
61
- // @ts-ignore
62
- $slots?: Record<string, SlotRender>
63
- ): void {
64
-
65
- /* User interface */
66
- const t_fragments: DocumentFragment[] = [];
67
-
68
- const t_fragment_0 = t_fragment($parent.ownerDocument!, t_fragments, 0, ` <div> Child class </div> `);
69
- const t_root_0 = t_root(t_fragment_0, true);
70
- const t_div_1 = t_next(t_root_0) as HTMLDivElement;
71
- const t_text_1 = t_next(t_div_1, true);
72
- $run(() => {
73
- t_div_1.className = t_class($props.class);
74
- });
75
- t_add_fragment(t_fragment_0, $parent, $anchor, t_text_1);
76
- t_next(t_text_1);
77
-
78
- }
@@ -1,44 +0,0 @@
1
- import type ServerSlotRender from "../../../../src/types/ServerSlotRender";
2
- import t_class from "../../../../src/render/buildClasses";
3
-
4
- export default function Class(
5
- $props: Record<PropertyKey, any>,
6
- // @ts-ignore
7
- $context?: Record<PropertyKey, any>,
8
- // @ts-ignore
9
- $slots?: Record<string, ServerSlotRender>
10
- ): { body: string, head: string } {
11
- let t_body = "";
12
- let t_head = "";
13
-
14
- /* User interface */
15
- t_body += ` <div id="divid" class="torp-1ljxz83"> From id </div> <div class="divclass torp-1ljxz83"> From string </div> <a class="${t_class({ hello: true, red: $props.red, green: $props.green, blue: $props.blue }, "torp-1ljxz83")}"> From state </a> <div class="${t_class({ hello: true, red: $props.red, green: $props.green, blue: $props.blue }, "torp-1ljxz83")}"> From state with scope </div> <div class="${t_class({ foo: true, bar: false, baz: 5, qux: null }, "torp-1ljxz83")}"> Class object </div> <div class="${t_class([ "foo", false, true && "baz", undefined ], "torp-1ljxz83")}"> Class array </div> <div class="${t_class([ "foo", 0, { bar: true }, "", [1 && "baz", ["qux"]] ], "torp-1ljxz83")}"> Class nested </div> <![>`;
16
- const t_props_1 = {
17
- class: t_class({ "child-class": true }, "torp-1ljxz83"),
18
- };
19
- const t_comp_1 = Child(t_props_1, $context);
20
- t_body += t_comp_1.body;
21
- t_head += t_comp_1.head;
22
- t_body += `<!]><!> `;
23
-
24
- /* Style */
25
- t_head += "<style id='1ljxz83'>div.torp-1ljxz83 { color: blue; } </style>";
26
-
27
- return { body: t_body, head: t_head };
28
- }
29
-
30
- function Child(
31
- $props: Record<PropertyKey, any>,
32
- // @ts-ignore
33
- $context?: Record<PropertyKey, any>,
34
- // @ts-ignore
35
- $slots?: Record<string, ServerSlotRender>
36
- ): { body: string, head: string } {
37
- let t_body = "";
38
- let t_head = "";
39
-
40
- /* User interface */
41
- t_body += ` <div class="${t_class($props.class)}"> Child class </div> `;
42
-
43
- return { body: t_body, head: t_head };
44
- }