@torpor/view 0.4.13 → 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.
Files changed (94) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/dist/{Cleanup-BGQ5zaxE.d.cts → Cleanup-CYsytTEc.d.cts} +1 -1
  3. package/dist/Cleanup-CYsytTEc.d.cts.map +1 -0
  4. package/dist/{Cleanup-Ca8IspaG.d.ts → Cleanup-CgjyN0lW.d.mts} +1 -1
  5. package/dist/Cleanup-CgjyN0lW.d.mts.map +1 -0
  6. package/dist/{Component-BDUCwkBQ.d.cts → Component-DmWGMgak.d.mts} +1 -1
  7. package/dist/{Component-BDUCwkBQ.d.cts.map → Component-DmWGMgak.d.mts.map} +1 -1
  8. package/dist/{Component-JVwSemf-.d.ts → Component-kGLRFYg2.d.cts} +1 -1
  9. package/dist/Component-kGLRFYg2.d.cts.map +1 -0
  10. package/dist/{Region-BrsZLZUe.d.ts → Region-Bb6HAb-F.d.cts} +2 -2
  11. package/dist/{Region-Cf7OeBIQ.d.cts.map → Region-Bb6HAb-F.d.cts.map} +1 -1
  12. package/dist/{Region-Cf7OeBIQ.d.cts → Region-CTchywkr.d.mts} +2 -2
  13. package/dist/Region-CTchywkr.d.mts.map +1 -0
  14. package/dist/compile.cjs +238 -68
  15. package/dist/compile.d.cts +1 -1
  16. package/dist/{compile.d.ts → compile.d.mts} +2 -2
  17. package/dist/compile.d.mts.map +1 -0
  18. package/dist/{compile.js → compile.mjs} +238 -67
  19. package/dist/compile.mjs.map +1 -0
  20. package/dist/dev.cjs +1 -2
  21. package/dist/dev.d.cts +2 -2
  22. package/dist/{dev.d.ts → dev.d.mts} +3 -3
  23. package/dist/dev.d.mts.map +1 -0
  24. package/dist/{dev.js → dev.mjs} +2 -2
  25. package/dist/{dev.cjs.map → dev.mjs.map} +1 -1
  26. package/dist/devContext-B3yskfhA.cjs +1 -2
  27. package/dist/{devContext-CevrTlUO.js → devContext-CQ8RhBX-.mjs} +1 -1
  28. package/dist/{devContext-B3yskfhA.cjs.map → devContext-CQ8RhBX-.mjs.map} +1 -1
  29. package/dist/{formatText-Ck04q8_X.cjs → formatText--9zsK5Nq.cjs} +4 -4
  30. package/dist/{formatText-OyD8MNAM.js → formatText-B8u71S_K.mjs} +4 -3
  31. package/dist/formatText-B8u71S_K.mjs.map +1 -0
  32. package/dist/{formatText-BlLF3PPm.d.ts → formatText-BNP3P38F.d.cts} +3 -3
  33. package/dist/formatText-BNP3P38F.d.cts.map +1 -0
  34. package/dist/{formatText-Bcb1JvW5.d.cts → formatText-D6Ov8Ub0.d.mts} +3 -3
  35. package/dist/formatText-D6Ov8Ub0.d.mts.map +1 -0
  36. package/dist/index.cjs +2 -3
  37. package/dist/index.d.cts +4 -4
  38. package/dist/{index.d.ts → index.d.mts} +5 -5
  39. package/dist/index.d.mts.map +1 -0
  40. package/dist/{index.js → index.mjs} +3 -3
  41. package/dist/{index.cjs.map → index.mjs.map} +1 -1
  42. package/dist/ssr.cjs +2 -3
  43. package/dist/ssr.d.cts +2 -2
  44. package/dist/{ssr.d.ts → ssr.d.mts} +3 -3
  45. package/dist/ssr.d.mts.map +1 -0
  46. package/dist/{ssr.js → ssr.mjs} +2 -2
  47. package/dist/{ssr.cjs.map → ssr.mjs.map} +1 -1
  48. package/package.json +17 -17
  49. package/scripts/copyToRepl.ts +6 -6
  50. package/src/compile/build/client/addMappedTextWithOffsets.ts +31 -0
  51. package/src/compile/build/client/buildAddFragment.ts +11 -11
  52. package/src/compile/build/client/buildComponentNode.ts +126 -29
  53. package/src/compile/build/client/buildElementNode.ts +65 -8
  54. package/src/compile/build/client/buildIfNode.ts +1 -1
  55. package/src/compile/build/client/buildSwitchNode.ts +1 -1
  56. package/src/compile/build/client/buildTextNode.ts +13 -6
  57. package/src/compile/build/client/getAttributeOffsets.ts +90 -0
  58. package/src/compile/build/client/stashRunWithOffsets.ts +7 -1
  59. package/src/compile/build/server/buildServerElementNode.ts +1 -1
  60. package/src/compile/parse/parseTag.ts +1 -7
  61. package/src/compile/parse/parseText.ts +1 -1
  62. package/src/render/buildClasses.ts +1 -1
  63. package/src/render/buildStyles.ts +3 -1
  64. package/src/types/ClassValue.ts +6 -1
  65. package/src/types/StyleValue.ts +6 -1
  66. package/test/class/class.test.ts +31 -12
  67. package/test/class/components/output/Class-client.ts +62 -17
  68. package/test/class/components/output/Class-server.ts +40 -6
  69. package/test/class/components/temp/Class-client-c100fef7474dd892108c52b2cfed5825a3412e8b.ts +123 -0
  70. package/test/class/components/temp/Class-server-f42d0611a27002b493da55392baf7244d31e0d39.ts +78 -0
  71. package/test/source-maps/interpolated.test.ts +88 -0
  72. package/test/source-maps/parse.test.ts +1 -1
  73. package/tsdown.config.ts +2 -9
  74. package/vitest.config.ts +3 -3
  75. package/dist/Cleanup-BGQ5zaxE.d.cts.map +0 -1
  76. package/dist/Cleanup-Ca8IspaG.d.ts.map +0 -1
  77. package/dist/Component-JVwSemf-.d.ts.map +0 -1
  78. package/dist/Region-BrsZLZUe.d.ts.map +0 -1
  79. package/dist/compile.cjs.map +0 -1
  80. package/dist/compile.d.ts.map +0 -1
  81. package/dist/compile.js.map +0 -1
  82. package/dist/dev.d.ts.map +0 -1
  83. package/dist/dev.js.map +0 -1
  84. package/dist/devContext-CevrTlUO.js.map +0 -1
  85. package/dist/formatText-Bcb1JvW5.d.cts.map +0 -1
  86. package/dist/formatText-BlLF3PPm.d.ts.map +0 -1
  87. package/dist/formatText-Ck04q8_X.cjs.map +0 -1
  88. package/dist/formatText-OyD8MNAM.js.map +0 -1
  89. package/dist/index.d.ts.map +0 -1
  90. package/dist/index.js.map +0 -1
  91. package/dist/ssr.d.ts.map +0 -1
  92. package/dist/ssr.js.map +0 -1
  93. package/test/class/components/temp/Class-client-d17977d356d8c8f964eaa1ac5a381814b33c22ba.ts +0 -78
  94. package/test/class/components/temp/Class-server-e4adcf242d5620acfcfa31c57b9b35c323a15664.ts +0 -44
@@ -2,7 +2,6 @@ import type Attribute from "../types/nodes/Attribute";
2
2
  import type ElementNode from "../types/nodes/ElementNode";
3
3
  import isFullyReactive from "../utils/isFullyReactive";
4
4
  import isReactive from "../utils/isReactive";
5
- import trimQuotes from "../utils/trimQuotes";
6
5
  import type ParseStatus from "./ParseStatus";
7
6
  import parseInlineScript from "./parseInlineScript";
8
7
  import accept from "./utils/accept";
@@ -17,7 +16,7 @@ export default function parseTag(status: ParseStatus): ElementNode {
17
16
 
18
17
  consumeSpace(status);
19
18
 
20
- let tagStart = status.i;
19
+ let tagStart = status.i + 1;
21
20
  let snailed = accept("@", status);
22
21
  let tagName = consumeAlphaNumeric(status);
23
22
  let tagEnd = status.i;
@@ -109,11 +108,6 @@ function parseAttribute(status: ParseStatus): Attribute {
109
108
  value = value.substring(1, value.length - 1);
110
109
  valueStart++;
111
110
  valueEnd--;
112
- } else if (reactive) {
113
- // TODO: Ranges etc, like text nodes -- I think we would need to
114
- // leave things reactive (or fully reactive) and check it when
115
- // building instead
116
- value = `\`${trimQuotes(value).replaceAll("{", "${")}\``;
117
111
  }
118
112
  } else if (name.startsWith("{") && name.endsWith("}")) {
119
113
  // It's a shortcut attribute. It could be e.g. {width} or it could be
@@ -84,7 +84,7 @@ export default function parseText(status: ParseStatus, element: ElementNode): vo
84
84
  const text: TextNode = {
85
85
  type: "text",
86
86
  content: content + spaceContent,
87
- spans: spans,
87
+ spans,
88
88
  };
89
89
  element.children.push(text);
90
90
  }
@@ -16,7 +16,7 @@ export default function buildClasses(value: ClassValue, styleHash?: string): str
16
16
  }
17
17
  }
18
18
 
19
- function gatherNames(name: string, value: ClassValue, classes: string[]) {
19
+ function gatherNames(name: string, value: unknown, classes: string[]) {
20
20
  if (value) {
21
21
  if (Array.isArray(value)) {
22
22
  for (let v of value) {
@@ -8,7 +8,9 @@ export default function buildStyles(value: StyleValue): string {
8
8
  if (value) {
9
9
  if (Array.isArray(value)) {
10
10
  for (let v of value) {
11
- styles.push(v);
11
+ if (v) {
12
+ styles.push(v);
13
+ }
12
14
  }
13
15
  } else if (typeof value === "object") {
14
16
  for (let [n, v] of Object.entries(value)) {
@@ -1,3 +1,8 @@
1
- type ClassValue = string | Record<string, string> | undefined | Array<ClassValue>;
1
+ type ClassValue =
2
+ | string
3
+ | Record<string, boolean | null | undefined>
4
+ | Array<ClassValue>
5
+ | null
6
+ | undefined;
2
7
 
3
8
  export default ClassValue;
@@ -1,3 +1,8 @@
1
- type StyleValue = string | Record<string, string> | Array<string> | undefined;
1
+ type StyleValue =
2
+ | string
3
+ | Record<string, string | null | undefined>
4
+ | Array<string | null | undefined>
5
+ | null
6
+ | undefined;
2
7
 
3
8
  export default StyleValue;
@@ -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
+ }