@torpor/view 0.0.11 → 0.0.12

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 (173) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/{ServerSlotRender-AWF3bD5B.d.cts → ServerSlotRender-t1sOutne.d.cts} +1 -1
  3. package/dist/{ServerSlotRender-AWF3bD5B.d.ts → ServerSlotRender-t1sOutne.d.ts} +1 -1
  4. package/dist/{chunk-GO2L324Q.js → chunk-T6JGCJ5T.js} +5 -2
  5. package/dist/chunk-T6JGCJ5T.js.map +1 -0
  6. package/dist/compile.cjs +38 -31
  7. package/dist/compile.cjs.map +1 -1
  8. package/dist/compile.d.cts +1 -0
  9. package/dist/compile.d.ts +1 -0
  10. package/dist/compile.js +38 -31
  11. package/dist/compile.js.map +1 -1
  12. package/dist/index.cjs +4 -1
  13. package/dist/index.cjs.map +1 -1
  14. package/dist/index.d.cts +2 -2
  15. package/dist/index.d.ts +2 -2
  16. package/dist/index.js +1 -1
  17. package/dist/index.js.map +1 -1
  18. package/dist/metafile-cjs.json +1 -1
  19. package/dist/metafile-esm.json +1 -1
  20. package/dist/ssr.cjs +4 -1
  21. package/dist/ssr.cjs.map +1 -1
  22. package/dist/ssr.d.cts +2 -2
  23. package/dist/ssr.d.ts +2 -2
  24. package/dist/ssr.js +1 -1
  25. package/dist/ssr.js.map +1 -1
  26. package/package.json +6 -6
  27. package/scripts/buildTestOutput.ts +2 -121
  28. package/src/compile/build/client/buildAddFragment.ts +1 -1
  29. package/src/compile/build/client/buildAwaitNode.ts +1 -1
  30. package/src/compile/build/client/buildComponentNode.ts +1 -1
  31. package/src/compile/build/client/buildControlNode.ts +1 -1
  32. package/src/compile/build/client/buildElementNode.ts +7 -1
  33. package/src/compile/build/client/buildForNode.ts +1 -1
  34. package/src/compile/build/client/buildFragment.ts +1 -1
  35. package/src/compile/build/client/buildFragmentText.ts +7 -1
  36. package/src/compile/build/client/buildHeadNode.ts +1 -1
  37. package/src/compile/build/client/buildHtmlNode.ts +1 -1
  38. package/src/compile/build/client/buildIfNode.ts +1 -1
  39. package/src/compile/build/client/buildMount.ts +1 -1
  40. package/src/compile/build/client/buildNode.ts +1 -1
  41. package/src/compile/build/client/buildReplaceNode.ts +1 -1
  42. package/src/compile/build/client/buildRootNode.ts +1 -1
  43. package/src/compile/build/client/buildRun.ts +1 -1
  44. package/src/compile/build/client/buildScriptNode.ts +1 -1
  45. package/src/compile/build/client/buildSlotNode.ts +1 -1
  46. package/src/compile/build/client/buildSwitchNode.ts +1 -1
  47. package/src/compile/build/client/buildTextNode.ts +1 -1
  48. package/src/compile/build/client/replaceForVarNames.ts +1 -1
  49. package/src/compile/build/server/buildServerAwaitNode.ts +1 -1
  50. package/src/compile/build/server/buildServerComponentNode.ts +1 -1
  51. package/src/compile/build/server/buildServerControlNode.ts +1 -1
  52. package/src/compile/build/server/buildServerElementNode.ts +9 -1
  53. package/src/compile/build/server/buildServerForNode.ts +1 -1
  54. package/src/compile/build/server/buildServerHtmlNode.ts +1 -1
  55. package/src/compile/build/server/buildServerIfNode.ts +1 -1
  56. package/src/compile/build/server/buildServerNode.ts +5 -1
  57. package/src/compile/build/server/buildServerReplaceNode.ts +1 -1
  58. package/src/compile/build/server/buildServerRootNode.ts +5 -1
  59. package/src/compile/build/server/buildServerScriptNode.ts +1 -1
  60. package/src/compile/build/server/buildServerSlotNode.ts +1 -1
  61. package/src/compile/build/server/buildServerSpecialNode.ts +1 -1
  62. package/src/compile/build/server/buildServerSwitchNode.ts +1 -1
  63. package/src/compile/build/server/buildServerTextNode.ts +1 -1
  64. package/src/compile/build/utils/isFullyReactive.ts +1 -1
  65. package/src/compile/build/utils/isReactive.ts +1 -1
  66. package/src/compile/build/utils/isReactiveAttribute.ts +1 -1
  67. package/src/compile/parse/addSpaceElement.ts +4 -1
  68. package/src/compile/parse/parseControl.ts +4 -1
  69. package/src/compile/parse/parseImports.ts +1 -1
  70. package/src/compile/parse/parseMarkup.ts +1 -1
  71. package/src/compile/parse/parseStyles.ts +1 -1
  72. package/src/compile/parse/scopeStyles.ts +13 -21
  73. package/src/compile/parse/slottifyChildNodes.ts +1 -1
  74. package/src/compile/parse/utils/addError.ts +5 -1
  75. package/src/compile/parse/utils/consumeUntil.ts +1 -1
  76. package/src/compile/parse/utils/isAlphaNumeric.ts +1 -1
  77. package/src/compile/parse/utils/isAlphaNumericChar.ts +1 -1
  78. package/src/compile/parse/utils/isSpace.ts +1 -1
  79. package/src/compile/parse/utils/isSpaceChar.ts +1 -1
  80. package/src/compile/types/nodes/TemplateNode.ts +3 -0
  81. package/src/compile/utils/Builder.ts +3 -3
  82. package/src/compile/utils/trimEnd.ts +1 -1
  83. package/src/compile/utils/trimMatched.ts +1 -1
  84. package/src/compile/utils/trimQuotes.ts +1 -1
  85. package/src/compile/utils/trimStart.ts +1 -1
  86. package/src/compile/utils/trimStartAndEnd.ts +1 -1
  87. package/src/compile/utils/voidTags.ts +1 -1
  88. package/src/debug/printHtml.ts +1 -1
  89. package/src/motion/animate.ts +1 -1
  90. package/src/render/$mount.ts +1 -1
  91. package/src/render/$run.ts +1 -1
  92. package/src/render/$serverMount.ts +1 -1
  93. package/src/render/$serverRun.ts +1 -1
  94. package/src/render/$stream.ts +1 -1
  95. package/src/render/addAnimation.ts +1 -1
  96. package/src/render/addEvent.ts +1 -1
  97. package/src/render/addFragment.ts +1 -1
  98. package/src/render/applyProps.ts +1 -1
  99. package/src/render/clearRange.ts +1 -1
  100. package/src/render/createComment.ts +1 -1
  101. package/src/render/createElement.ts +1 -1
  102. package/src/render/createFragment.ts +1 -1
  103. package/src/render/createText.ts +1 -1
  104. package/src/render/flushMountEffects.ts +1 -1
  105. package/src/render/getClasses.ts +4 -1
  106. package/src/render/hydrate.ts +1 -1
  107. package/src/render/hydrateRoot.ts +1 -1
  108. package/src/render/mount.ts +1 -1
  109. package/src/render/moveRange.ts +1 -1
  110. package/src/render/popRange.ts +1 -1
  111. package/src/render/runControl.ts +1 -1
  112. package/src/render/runControlBranch.ts +1 -1
  113. package/src/render/runList.ts +1 -1
  114. package/src/render/runListItems.ts +1 -1
  115. package/src/render/setAttribute.ts +1 -1
  116. package/src/render/setDynamicElement.ts +1 -1
  117. package/src/watch/proxyGet.ts +1 -1
  118. package/src/watch/removeEffect.ts +1 -1
  119. package/src/watch/runEffect.ts +1 -1
  120. package/src/watch/symbols.ts +1 -1
  121. package/src/watch/trackEffect.ts +1 -1
  122. package/src/watch/transferEffects.ts +1 -1
  123. package/src/watch/triggerEffects.ts +1 -1
  124. package/test/bench/components/output/Bench-client.ts +0 -204
  125. package/test/bench/components/output/Bench-server.ts +0 -130
  126. package/test/bench/components/temp/Bench-client-5fee290225ae4771aa847360006123671e8f17f1.ts +208 -0
  127. package/test/bench/components/temp/Bench-server-00cefa588803c01ca4f2741c595e4f045cdd101e.ts +130 -0
  128. package/test/build-server/components/{output/IfNested-client.ts → temp/IfNested-client-979db97eea5b4595550b9b46f297f3fbc31796d2.ts} +11 -0
  129. package/test/buildHtml.ts +1 -1
  130. package/test/buildOutputFiles.ts +47 -12
  131. package/test/class/class.test.ts +29 -6
  132. package/test/class/components/Class.torp +15 -1
  133. package/test/class/components/output/Class-client.ts +10 -6
  134. package/test/class/components/output/Class-server.ts +1 -1
  135. package/test/class/components/temp/{Class-client-600bf865c14f1052d24e1c79242f837aaf5ae5e8.ts → Class-client-8c3f9e0257cc2b687e9bb7106cccbab94a4b5adf.ts} +10 -6
  136. package/test/class/components/temp/Class-server-2218c3284845fdab80d1a41ebace9a9e2ddd6fc1.ts +17 -0
  137. package/test/component/components/temp/Header-client-ac151eea86e3f6b058fab101661e13ae73864968.ts +34 -0
  138. package/test/component/components/temp/Header-server-4f10f2332f3ca7a097517cfb938ab1e6f31d68ac.ts +17 -0
  139. package/test/console/components/temp/{Console-client-254d7d4799471401334d698b1631ab1cb5b70558.ts → Console-client-2f206752ce59e59fba9bb91263b4102fd515951e.ts} +1 -1
  140. package/test/console/components/temp/Console-server-b4b15f7a0d1d2b50d87bad4870e1b8d368707c04.ts +17 -0
  141. package/test/globalSetup.ts +1 -1
  142. package/test/helpers.ts +6 -2
  143. package/test/hydrateComponent.ts +1 -1
  144. package/test/importComponent.ts +12 -40
  145. package/test/mountComponent.ts +5 -1
  146. package/test/party/components/temp/AnswerButton-client-243454cd7bf84c648f244b3587e60d01a0401039.ts +33 -0
  147. package/test/party/components/temp/AnswerButton-server-938e46c1d2510ea37454854ef527e4aa64eb8e52.ts +16 -0
  148. package/test/party/components/temp/FunnyButton-client-2e6bec8259065b5bc9ae16d1ca93dd1bd0c56b7c.ts +40 -0
  149. package/test/party/components/temp/FunnyButton-server-e8ab55e47c735f7e42c55d2b7504dfa4190a1b40.ts +32 -0
  150. package/test/party/components/temp/Time-client-7ba4ca9322af2cb88a873c812fc776760c337c64.ts +47 -0
  151. package/test/party/components/temp/Time-server-08f66c7f3f32b13de06d75fe679cf58b5727c473.ts +31 -0
  152. package/test/party/components/temp/UserProfile-client-938bcef20a2555de22aca939022a32742ac5e729.ts +51 -0
  153. package/test/party/components/temp/UserProfile-server-9df5c59b8797fa67c479bc76450104d45e6076f9.ts +22 -0
  154. package/test/party/components/temp/UserProfileContext-client-93211cdba795b8baf926f60f5b17da90701743b3.ts +44 -0
  155. package/test/party/components/temp/UserProfileContext-server-cf58767df1e2d1dde919f59de73cdd9764bbc006.ts +20 -0
  156. package/test/slots/components/temp/Article-client-741f94eab2e96655f4c9d69ccd7d9c7cc998f4ce.ts +41 -0
  157. package/test/slots/components/temp/Article-server-a6bd47a621cc213db4313eb775a52246541dd203.ts +28 -0
  158. package/test/slots/components/temp/Header-client-e2e1e7d60b48b0841cd0c20224f520330ca96458.ts +38 -0
  159. package/test/slots/components/temp/Header-server-1c195508a91c32822da22a08576c8a30c9070636.ts +22 -0
  160. package/test/slots/components/temp/List-client-0659d999cfb48b865fe5b8aaaf2a4ddac3a8a8b6.ts +76 -0
  161. package/test/slots/components/temp/List-server-4b76485a259d054187edad8aa691d80ac918ad86.ts +25 -0
  162. package/test/special-component/components/temp/BigTitle-client-881a9f84876fb3f6d994736edb253b96e71de926.ts +32 -0
  163. package/test/special-component/components/temp/BigTitle-server-9efc738f5eb131a4b859c4a99a8e255d93834e9a.ts +20 -0
  164. package/test/special-component/components/temp/SmallTitle-client-25b3097b7ae47848dd82967403faf7745fc43388.ts +32 -0
  165. package/test/special-component/components/temp/SmallTitle-server-fc105db9a91b83644d67e049ce583a3d1a61f50c.ts +20 -0
  166. package/tsconfig.json +1 -1
  167. package/tsup.config.ts +7 -2
  168. package/vitest.config.ts +2 -2
  169. package/dist/chunk-GO2L324Q.js.map +0 -1
  170. package/test/bench/components/temp/Bench-client-3efcd3b6c03c7a51368df3b8b1bdf2e7fa722432.ts +0 -126
  171. package/test/build-server/components/IfNested.d.ts +0 -18
  172. package/test/class/components/temp/Class-server-082505b03612c762384ffff329472db3f55b8097.ts +0 -17
  173. /package/test/build-server/components/{output/IfNested-server.ts → temp/IfNested-server-3c4e4b6f2162c0906cef685830219b9ea9ee985c.ts} +0 -0
@@ -43,6 +43,7 @@ type NodeType = "root" | "control" | "component" | "element" | "text" | "special
43
43
 
44
44
  type TemplateNode = {
45
45
  type: NodeType;
46
+ scopeStyles?: boolean;
46
47
  varName?: string;
47
48
  handled?: boolean;
48
49
  };
package/dist/compile.d.ts CHANGED
@@ -43,6 +43,7 @@ type NodeType = "root" | "control" | "component" | "element" | "text" | "special
43
43
 
44
44
  type TemplateNode = {
45
45
  type: NodeType;
46
+ scopeStyles?: boolean;
46
47
  varName?: string;
47
48
  handled?: boolean;
48
49
  };
package/dist/compile.js CHANGED
@@ -65,6 +65,17 @@ var HYDRATION_START_COMMENT = "<![>";
65
65
  var HYDRATION_END_COMMENT = "<!]>";
66
66
  var HYDRATION_BRANCH_COMMENT = "<!^>";
67
67
 
68
+ // src/compile/utils/trimQuotes.ts
69
+ function trimQuotes(text) {
70
+ let start = 0;
71
+ let end = text.length;
72
+ while (text[start] === "'" && text[end - 1] === "'" || text[start] === '"' && text[end - 1] === '"' || text[start] === "`" && text[end - 1] === "`") {
73
+ start += 1;
74
+ end -= 1;
75
+ }
76
+ return text.substring(start, end);
77
+ }
78
+
68
79
  // src/compile/build/utils/isReactive.ts
69
80
  function isReactive(text) {
70
81
  return text.includes("{") && text.includes("}");
@@ -172,6 +183,9 @@ function buildElementFragmentText(node, status, fragments, currentFragment) {
172
183
  if (a.name.startsWith("data-")) {
173
184
  return `${a.name}=""`;
174
185
  }
186
+ } else if (a.name === "class" && node.scopeStyles) {
187
+ let value = a.value ? `"${trimQuotes(a.value)} torp-${status.styleHash}"` : `"torp-${status.styleHash}"`;
188
+ return `${a.name}=${value}`;
175
189
  } else {
176
190
  return `${a.name}${a.value != null ? `=${a.value}` : ""}`;
177
191
  }
@@ -241,17 +255,6 @@ function trimMatched(text, startChar, endChar) {
241
255
  return text.substring(start, end);
242
256
  }
243
257
 
244
- // src/compile/utils/trimQuotes.ts
245
- function trimQuotes(text) {
246
- let start = 0;
247
- let end = text.length;
248
- while (text[start] === "'" && text[end - 1] === "'" || text[start] === '"' && text[end - 1] === '"' || text[start] === "`" && text[end - 1] === "`") {
249
- start += 1;
250
- end -= 1;
251
- }
252
- return text.substring(start, end);
253
- }
254
-
255
258
  // src/compile/build/utils/isFullyReactive.ts
256
259
  function isFullyReactive(text) {
257
260
  return text.trim().startsWith("{") && text.trim().endsWith("}");
@@ -1508,9 +1511,15 @@ function buildElementAttributes(node, varName, status, b) {
1508
1511
  } else if (name.startsWith(":transition")) {
1509
1512
  buildTransitionAttribute(node, varName, name, value, status, b);
1510
1513
  } else if (name === "class") {
1514
+ if (node.scopeStyles) {
1515
+ value += `+ "torp-${status.styleHash}"`;
1516
+ }
1511
1517
  buildRun("setClassName", `${varName}.className = ${value};`, status, b);
1512
1518
  } else if (name === ":class") {
1513
1519
  status.imports.add("t_class");
1520
+ if (node.scopeStyles) {
1521
+ value += `, "torp-${status.styleHash}"`;
1522
+ }
1514
1523
  buildRun("setClasses", `${varName}.className = t_class(${value});`, status, b);
1515
1524
  } else if (name === ":style") {
1516
1525
  status.imports.add("t_style");
@@ -2423,6 +2432,9 @@ function buildElementAttributes2(node, status) {
2423
2432
  attributes.push(`${propName}="\${${valueOrDefault}}"`);
2424
2433
  } else if (name === ":class") {
2425
2434
  status.imports.add("t_class");
2435
+ if (node.scopeStyles) {
2436
+ value += `, "torp-${status.styleHash}"`;
2437
+ }
2426
2438
  attributes.push(`class="\${t_class(${value})}"`);
2427
2439
  } else if (name === ":style") {
2428
2440
  status.imports.add("t_style");
@@ -2436,6 +2448,9 @@ function buildElementAttributes2(node, status) {
2436
2448
  attributes.push(
2437
2449
  `${name}="${trimQuotes(value).replaceAll("{", "${t_attr(").replaceAll("}", ")}")}"`
2438
2450
  );
2451
+ } else if (name === "class" && node.scopeStyles) {
2452
+ value = value ? `"${trimQuotes(value)} torp-${status.styleHash}"` : `"torp-${status.styleHash}"`;
2453
+ attributes.push(`${name}="${trimQuotes(value).replaceAll('"', "&quot;")}"`);
2439
2454
  } else if (value != null) {
2440
2455
  attributes.push(`${name}="${trimQuotes(value).replaceAll('"', "&quot;")}"`);
2441
2456
  } else {
@@ -3563,40 +3578,32 @@ function scopeStyles(status) {
3563
3578
  for (let block of component.style.blocks) {
3564
3579
  collectStyleSelectors(block, selectors);
3565
3580
  }
3566
- scopeStylesOnNode(component.markup, selectors, component.style.hash);
3581
+ scopeStylesOnNode(component.markup, selectors);
3567
3582
  }
3568
3583
  }
3569
3584
  }
3570
- function scopeStylesOnNode(node, selectors, styleHash) {
3585
+ function scopeStylesOnNode(node, selectors) {
3571
3586
  if (isElementNode(node)) {
3572
- let addClass = selectors.includes(node.tagName);
3573
- if (!addClass) {
3587
+ let scopeStyles2 = selectors.includes(node.tagName);
3588
+ if (!scopeStyles2) {
3574
3589
  for (let a of node.attributes) {
3575
3590
  if (a.name === "class" || a.name === ":class") {
3576
- addClass = true;
3591
+ scopeStyles2 = true;
3577
3592
  } else if (a.name === "id" && a.value) {
3578
- addClass = selectors.includes(`#${trimQuotes(a.value)}`);
3593
+ scopeStyles2 = selectors.includes(`#${trimQuotes(a.value)}`);
3579
3594
  } else if (a.name === "class" && a.value) {
3580
- addClass = selectors.includes(`.${trimQuotes(a.value)}`);
3595
+ scopeStyles2 = selectors.includes(`.${trimQuotes(a.value)}`);
3596
+ }
3597
+ if (scopeStyles2) {
3598
+ break;
3581
3599
  }
3582
- if (addClass) break;
3583
- }
3584
- }
3585
- if (addClass) {
3586
- let classAttribute = node.attributes.find((a) => a.name === "class");
3587
- if (classAttribute && classAttribute.value) {
3588
- classAttribute.value = `"${trimQuotes(classAttribute.value)} torp-${styleHash}"`;
3589
- } else {
3590
- node.attributes.push({
3591
- name: "class",
3592
- value: `"torp-${styleHash}"`
3593
- });
3594
3600
  }
3595
3601
  }
3602
+ node.scopeStyles = scopeStyles2;
3596
3603
  }
3597
3604
  if (isParentNode(node)) {
3598
3605
  for (let child of node.children) {
3599
- scopeStylesOnNode(child, selectors, styleHash);
3606
+ scopeStylesOnNode(child, selectors);
3600
3607
  }
3601
3608
  }
3602
3609
  }