acrylblends 0.6.1 → 0.6.3

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 (217) hide show
  1. package/README.md +11 -6
  2. package/docs/framework/README.md +3 -2
  3. package/docs/framework/UPSTREAM.md +1 -1
  4. package/docs/framework/api/presets.md +0 -3
  5. package/docs/framework/cordis/acryl-in-a-cordis-app.md +9 -0
  6. package/docs/framework/getting-started/basic.md +5 -4
  7. package/docs/framework/getting-started/desktop.md +41 -0
  8. package/docs/framework/guides/jsx-dom.md +0 -3
  9. package/docs/framework/guides/jsx.md +1 -4
  10. package/docs/framework/guides/middleware.md +1 -1
  11. package/docs/framework/helpers/cookie.md +1 -1
  12. package/docs/framework/helpers/css.md +0 -3
  13. package/docs/framework/helpers/dev.md +0 -3
  14. package/docs/framework/helpers/jwt.md +1 -1
  15. package/docs/framework/helpers/proxy.md +0 -3
  16. package/docs/framework/middleware/builtin/basic-auth.md +6 -6
  17. package/docs/framework/middleware/builtin/cache.md +0 -3
  18. package/docs/framework/middleware/builtin/combine.md +1 -1
  19. package/docs/framework/middleware/builtin/ip-restriction.md +1 -1
  20. package/docs/framework/middleware/builtin/logger.md +1 -1
  21. package/docs/framework/middleware/builtin/mount.md +0 -3
  22. package/docs/framework/upstream.json +3 -3
  23. package/lib/accepts.d.ts +1 -1
  24. package/lib/acryl-base.d.ts +1 -1
  25. package/lib/adapter.d.ts +1 -1
  26. package/lib/{app-CmAYW1Al.d.ts → app-wFwpg-bt.d.ts} +1 -1
  27. package/lib/base-BpQy2Rk7.d.ts +783 -0
  28. package/lib/base-ddiVmiE7.js +721 -0
  29. package/lib/basic-auth.d.ts +1 -1
  30. package/lib/bearer-auth.d.ts +1 -1
  31. package/lib/body-limit.d.ts +1 -1
  32. package/lib/cache.d.ts +43 -0
  33. package/lib/cache.js +169 -0
  34. package/lib/client.d.ts +2 -2
  35. package/lib/combine.d.ts +1 -1
  36. package/lib/common-D8Z4JRCw.d.ts +46 -0
  37. package/lib/components-Ce5FRyHU.js +268 -0
  38. package/lib/components-DYZdxJIJ.js +24 -0
  39. package/lib/compress.d.ts +1 -1
  40. package/lib/conninfo.d.ts +2 -2
  41. package/lib/constants-BR9jM9BC.js +9 -0
  42. package/lib/{context-Bm7rI-oK.d.ts → context-DVQBjuns.d.ts} +1 -1
  43. package/lib/context-DxFdY_un.d.ts +250 -0
  44. package/lib/context-storage.d.ts +1 -1
  45. package/lib/{cookie-ClMaKDQf.d.ts → cookie-CCelEqky.d.ts} +1 -1
  46. package/lib/cookie.d.ts +3 -3
  47. package/lib/cors.d.ts +1 -1
  48. package/lib/csrf.d.ts +1 -1
  49. package/lib/css-D2jb7X8b.js +320 -0
  50. package/lib/css.d.ts +82 -0
  51. package/lib/css.js +134 -0
  52. package/lib/dev.d.ts +19 -0
  53. package/lib/dev.js +50 -0
  54. package/lib/etag.d.ts +1 -1
  55. package/lib/factory.d.ts +2 -2
  56. package/lib/hooks-Bq5q9IMl.js +762 -0
  57. package/lib/html-SllAe0YT.d.ts +46 -0
  58. package/lib/html.d.ts +1 -1
  59. package/lib/index-C850MeBA.d.ts +94 -0
  60. package/lib/{index-oOClm_Xk.d.ts → index-CUTfU69R.d.ts} +3 -3
  61. package/lib/{index-B-3F4wt2.d.ts → index-Cqcdluyn.d.ts} +2 -2
  62. package/lib/{index-UTBmM3GX.d.ts → index-CsvB-F9j.d.ts} +2 -2
  63. package/lib/index.d.ts +4 -4
  64. package/lib/ip-restriction.d.ts +2 -2
  65. package/lib/jsx/dom/client.d.ts +30 -0
  66. package/lib/jsx/dom/client.js +49 -0
  67. package/lib/jsx/dom/css.d.ts +84 -0
  68. package/lib/jsx/dom/css.js +2 -0
  69. package/lib/jsx/dom/jsx-dev-runtime.d.ts +3 -0
  70. package/lib/jsx/dom/jsx-dev-runtime.js +2 -0
  71. package/lib/jsx/dom/jsx-runtime.d.ts +3 -0
  72. package/lib/jsx/dom/jsx-runtime.js +2 -0
  73. package/lib/jsx/dom/server.d.ts +105 -0
  74. package/lib/jsx/dom/server.js +37 -0
  75. package/lib/jsx/dom.d.ts +5 -0
  76. package/lib/jsx/dom.js +74 -0
  77. package/lib/jsx/jsx-dev-runtime.d.ts +6 -0
  78. package/lib/jsx/jsx-dev-runtime.js +14 -0
  79. package/lib/jsx/jsx-runtime.d.ts +10 -0
  80. package/lib/jsx/jsx-runtime.js +30 -0
  81. package/lib/jsx/streaming.d.ts +2 -0
  82. package/lib/jsx/streaming.js +2 -0
  83. package/lib/jsx-dev-runtime-B22O-Npk.d.ts +7 -0
  84. package/lib/jsx-dev-runtime-kAhR_4C7.js +354 -0
  85. package/lib/jsx-runtime-BVVgDSdq.d.ts +1 -0
  86. package/lib/jsx.d.ts +3 -0
  87. package/lib/jsx.js +47 -0
  88. package/lib/jwk.d.ts +4 -4
  89. package/lib/{jwt-Dg493Tai.d.ts → jwt-BARhotDz.d.ts} +1 -1
  90. package/lib/jwt.d.ts +4 -4
  91. package/lib/language.d.ts +1 -1
  92. package/lib/linear-router-C3FPib6h.js +96 -0
  93. package/lib/logger.d.ts +1 -1
  94. package/lib/loopback-only.d.ts +1 -1
  95. package/lib/method-not-allowed.d.ts +2 -2
  96. package/lib/method-override.d.ts +2 -2
  97. package/lib/mount.d.ts +44 -0
  98. package/lib/mount.js +67 -0
  99. package/lib/node-server/conninfo.d.ts +1 -1
  100. package/lib/node-server/serve-static.d.ts +1 -1
  101. package/lib/node-server/serve-static.js +1 -1
  102. package/lib/node-server.d.ts +1 -1
  103. package/lib/node-server.js +1 -1
  104. package/lib/pattern-router-HZxjDGEQ.js +41 -0
  105. package/lib/powered-by.d.ts +1 -1
  106. package/lib/pretty-json.d.ts +1 -1
  107. package/lib/proxy.d.ts +72 -0
  108. package/lib/proxy.js +121 -0
  109. package/lib/quick.d.ts +8 -0
  110. package/lib/quick.js +17 -0
  111. package/lib/request-id.d.ts +1 -1
  112. package/lib/request.d.ts +1 -1
  113. package/lib/route.d.ts +1 -1
  114. package/lib/router/linear-router.js +1 -95
  115. package/lib/router/pattern-router.js +1 -40
  116. package/lib/schema-validator.d.ts +1 -1
  117. package/lib/secure-headers.d.ts +1 -1
  118. package/lib/{serve-static-Dw_m6KxR.js → serve-static-Cw23shXv.js} +1 -0
  119. package/lib/serve-static.d.ts +1 -1
  120. package/lib/streaming.d.ts +1 -1
  121. package/lib/testing.d.ts +4 -4
  122. package/lib/timeout.d.ts +1 -1
  123. package/lib/timing.d.ts +1 -1
  124. package/lib/tiny.d.ts +8 -0
  125. package/lib/tiny.js +15 -0
  126. package/lib/trailing-slash.d.ts +1 -1
  127. package/lib/{types-CHesD1KG.d.ts → types-CQiGmsWW.d.ts} +3 -3
  128. package/lib/{types-CwrQjlaM.d.ts → types-Lqx5BxQF.d.ts} +10 -1
  129. package/lib/{types-CDO6I3B0.d.ts → types-nEL8VPDC.d.ts} +1 -1
  130. package/lib/types.d.ts +1 -1
  131. package/lib/utils/body.d.ts +1 -1
  132. package/lib/utils/cookie.d.ts +1 -1
  133. package/lib/utils/crypto.d.ts +1 -1
  134. package/lib/utils/html.d.ts +1 -45
  135. package/lib/utils/ipaddr.d.ts +1 -1
  136. package/lib/utils/jwt.d.ts +1 -1
  137. package/lib/utils/types.d.ts +2 -2
  138. package/lib/validator.d.ts +2 -2
  139. package/lib/ws.d.ts +1 -1
  140. package/package.json +69 -1
  141. package/plugins/acryl-inspect/upstream.json +1 -1
  142. package/plugins/acryl-node-server/upstream.json +1 -1
  143. package/plugins/acryl-router/src/core/helper/css/common.case.test.tsx +506 -0
  144. package/plugins/acryl-router/src/core/helper/css/common.ts +337 -0
  145. package/plugins/acryl-router/src/core/helper/css/index.test.tsx +678 -0
  146. package/plugins/acryl-router/src/core/helper/css/index.ts +262 -0
  147. package/plugins/acryl-router/src/core/helper/dev/index.test.ts +181 -0
  148. package/plugins/acryl-router/src/core/helper/dev/index.ts +79 -0
  149. package/plugins/acryl-router/src/core/helper/proxy/index.test.ts +356 -0
  150. package/plugins/acryl-router/src/core/helper/proxy/index.ts +203 -0
  151. package/plugins/acryl-router/src/core/helper/streaming/sse.test.tsx +557 -0
  152. package/plugins/acryl-router/src/core/jsx/base.test.tsx +97 -0
  153. package/plugins/acryl-router/src/core/jsx/base.ts +490 -0
  154. package/plugins/acryl-router/src/core/jsx/children.test.ts +52 -0
  155. package/plugins/acryl-router/src/core/jsx/children.ts +20 -0
  156. package/plugins/acryl-router/src/core/jsx/components.test.tsx +936 -0
  157. package/plugins/acryl-router/src/core/jsx/components.ts +257 -0
  158. package/plugins/acryl-router/src/core/jsx/constants.ts +6 -0
  159. package/plugins/acryl-router/src/core/jsx/context-isolation.test.ts +655 -0
  160. package/plugins/acryl-router/src/core/jsx/context.ts +266 -0
  161. package/plugins/acryl-router/src/core/jsx/dom/client.test.tsx +128 -0
  162. package/plugins/acryl-router/src/core/jsx/dom/client.ts +89 -0
  163. package/plugins/acryl-router/src/core/jsx/dom/components.test.tsx +330 -0
  164. package/plugins/acryl-router/src/core/jsx/dom/components.ts +39 -0
  165. package/plugins/acryl-router/src/core/jsx/dom/context.test.tsx +184 -0
  166. package/plugins/acryl-router/src/core/jsx/dom/context.ts +52 -0
  167. package/plugins/acryl-router/src/core/jsx/dom/css.test.tsx +149 -0
  168. package/plugins/acryl-router/src/core/jsx/dom/css.ts +263 -0
  169. package/plugins/acryl-router/src/core/jsx/dom/hooks/index.test.tsx +172 -0
  170. package/plugins/acryl-router/src/core/jsx/dom/hooks/index.ts +91 -0
  171. package/plugins/acryl-router/src/core/jsx/dom/index.test.tsx +3681 -0
  172. package/plugins/acryl-router/src/core/jsx/dom/index.ts +170 -0
  173. package/plugins/acryl-router/src/core/jsx/dom/intrinsic-element/components.test.tsx +1344 -0
  174. package/plugins/acryl-router/src/core/jsx/dom/intrinsic-element/components.ts +438 -0
  175. package/plugins/acryl-router/src/core/jsx/dom/jsx-dev-runtime.ts +23 -0
  176. package/plugins/acryl-router/src/core/jsx/dom/jsx-runtime.ts +8 -0
  177. package/plugins/acryl-router/src/core/jsx/dom/render.ts +879 -0
  178. package/plugins/acryl-router/src/core/jsx/dom/server.test.tsx +199 -0
  179. package/plugins/acryl-router/src/core/jsx/dom/server.ts +76 -0
  180. package/plugins/acryl-router/src/core/jsx/dom/utils.ts +7 -0
  181. package/plugins/acryl-router/src/core/jsx/hooks/dom.test.tsx +859 -0
  182. package/plugins/acryl-router/src/core/jsx/hooks/index.ts +437 -0
  183. package/plugins/acryl-router/src/core/jsx/hooks/string.test.tsx +40 -0
  184. package/plugins/acryl-router/src/core/jsx/index.test.tsx +1744 -0
  185. package/plugins/acryl-router/src/core/jsx/index.ts +115 -0
  186. package/plugins/acryl-router/src/core/jsx/intrinsic-element/common.ts +23 -0
  187. package/plugins/acryl-router/src/core/jsx/intrinsic-element/components.test.tsx +666 -0
  188. package/plugins/acryl-router/src/core/jsx/intrinsic-element/components.ts +210 -0
  189. package/plugins/acryl-router/src/core/jsx/intrinsic-elements.ts +938 -0
  190. package/plugins/acryl-router/src/core/jsx/jsx-dev-runtime.ts +26 -0
  191. package/plugins/acryl-router/src/core/jsx/jsx-runtime.test.tsx +85 -0
  192. package/plugins/acryl-router/src/core/jsx/jsx-runtime.ts +51 -0
  193. package/plugins/acryl-router/src/core/jsx/streaming.test.tsx +1281 -0
  194. package/plugins/acryl-router/src/core/jsx/streaming.ts +231 -0
  195. package/plugins/acryl-router/src/core/jsx/types.ts +41 -0
  196. package/plugins/acryl-router/src/core/jsx/utils.test.ts +366 -0
  197. package/plugins/acryl-router/src/core/jsx/utils.ts +202 -0
  198. package/plugins/acryl-router/src/core/middleware/cache/index.test.ts +1211 -0
  199. package/plugins/acryl-router/src/core/middleware/cache/index.ts +323 -0
  200. package/plugins/acryl-router/src/core/middleware/mount/index.test.ts +334 -0
  201. package/plugins/acryl-router/src/core/middleware/mount/index.ts +108 -0
  202. package/plugins/acryl-router/src/core/preset/quick.test.ts +42 -0
  203. package/plugins/acryl-router/src/core/preset/quick.ts +24 -0
  204. package/plugins/acryl-router/src/core/preset/tiny.test.ts +42 -0
  205. package/plugins/acryl-router/src/core/preset/tiny.ts +20 -0
  206. package/plugins/acryl-router/src/core/utils/types.ts +9 -0
  207. package/plugins/acryl-router/src/helpers/index.ts +3 -0
  208. package/plugins/acryl-router/src/middleware/index.ts +2 -0
  209. package/plugins/acryl-router/src/service.ts +22 -5
  210. package/plugins/acryl-router/tests/jsx.spec.tsx +63 -0
  211. package/plugins/acryl-router/upstream.json +3 -3
  212. package/plugins/acryl-router-http/upstream.json +1 -1
  213. package/plugins/acryl-state/upstream.json +1 -1
  214. package/plugins/desktop/upstream.json +1 -1
  215. package/plugins/desktop-web/upstream.json +1 -1
  216. package/plugins/save/plugin.json +1 -1
  217. package/templates/todo/upstream.json +1 -1
@@ -0,0 +1,506 @@
1
+ /** @jsxImportSource ../../jsx */
2
+ import type {
3
+ Style as StyleComponent,
4
+ css as cssHelper,
5
+ keyframes as keyframesHelper,
6
+ rawCssString as rawCssStringHelper,
7
+ viewTransition as viewTransitionHelper,
8
+ } from './index.ts'
9
+
10
+ interface Support {
11
+ nest: boolean
12
+ }
13
+ export const renderTest = (
14
+ getEnv: () => {
15
+ css: typeof cssHelper
16
+ keyframes: typeof keyframesHelper
17
+ viewTransition: typeof viewTransitionHelper
18
+ rawCssString: typeof rawCssStringHelper
19
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
20
+ toString: (template: any) => Promise<string>
21
+ Style: typeof StyleComponent
22
+ support: Support
23
+ }
24
+ ) => {
25
+ const { support } = getEnv()
26
+
27
+ let css: typeof cssHelper
28
+ let keyframes: typeof keyframesHelper
29
+ let viewTransition: typeof viewTransitionHelper
30
+ let rawCssString: typeof rawCssStringHelper
31
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
32
+ let toString: (template: any) => Promise<string>
33
+ let Style: typeof StyleComponent
34
+ beforeEach(() => {
35
+ ;({ css, keyframes, viewTransition, rawCssString, toString, Style } = getEnv())
36
+ })
37
+
38
+ describe('render css', () => {
39
+ it('Should render CSS styles with JSX', async () => {
40
+ const headerClass = css`
41
+ background-color: blue;
42
+ `
43
+ const template = (
44
+ <>
45
+ <Style />
46
+ <h1 class={headerClass}>Hello!</h1>
47
+ </>
48
+ )
49
+ expect(await toString(template)).toBe(
50
+ '<style id="acryl-css">.css-2458908649{background-color:blue}</style><h1 class="css-2458908649">Hello!</h1>'
51
+ )
52
+ })
53
+
54
+ it('Should render CSS with keyframes', async () => {
55
+ const animation = keyframes`
56
+ from {
57
+ opacity: 0;
58
+ }
59
+ to {
60
+ opacity: 1;
61
+ }
62
+ `
63
+ const headerClass = css`
64
+ background-color: blue;
65
+ animation: ${animation} 1s ease-in-out;
66
+ `
67
+ const template = (
68
+ <>
69
+ <Style />
70
+ <h1 class={headerClass}>Hello!</h1>
71
+ </>
72
+ )
73
+ expect(await toString(template)).toBe(
74
+ '<style id="acryl-css">.css-1580801783{background-color:blue;animation:css-9294673 1s ease-in-out}@keyframes css-9294673{from{opacity:0}to{opacity:1}}</style><h1 class="css-1580801783">Hello!</h1>'
75
+ )
76
+ })
77
+
78
+ it('Should not output the same class name multiple times.', async () => {
79
+ const headerClass = css`
80
+ background-color: blue;
81
+ `
82
+ const headerClass2 = css`
83
+ background-color: blue;
84
+ `
85
+ const template = (
86
+ <>
87
+ <Style />
88
+ <h1 class={headerClass}>Hello!</h1>
89
+ <h1 class={headerClass2}>Hello2!</h1>
90
+ </>
91
+ )
92
+ expect(await toString(template)).toBe(
93
+ '<style id="acryl-css">.css-2458908649{background-color:blue}</style><h1 class="css-2458908649">Hello!</h1><h1 class="css-2458908649">Hello2!</h1>'
94
+ )
95
+ })
96
+
97
+ it('Should render CSS with variable', async () => {
98
+ const headerClass = css`
99
+ background-color: blue;
100
+ content: '${"I'm a variable!"}';
101
+ `
102
+ const template = (
103
+ <>
104
+ <Style />
105
+ <h1 class={headerClass}>Hello!</h1>
106
+ </>
107
+ )
108
+ expect(await toString(template)).toBe(
109
+ '<style id="acryl-css">.css-4027435072{background-color:blue;content:\'I\\\'m a variable!\'}</style><h1 class="css-4027435072">Hello!</h1>'
110
+ )
111
+ })
112
+
113
+ it('Should escape </style>', async () => {
114
+ const headerClass = css`
115
+ background-color: blue;
116
+ content: '${'</style>'}';
117
+ `
118
+ const template = (
119
+ <>
120
+ <Style />
121
+ <h1 class={headerClass}>Hello!</h1>
122
+ </>
123
+ )
124
+ expect(await toString(template)).toBe(
125
+ '<style id="acryl-css">.css-372954897{background-color:blue;content:\'<\\/style>\'}</style><h1 class="css-372954897">Hello!</h1>'
126
+ )
127
+ })
128
+
129
+ it('Should not escape URL', async () => {
130
+ const headerClass = css`
131
+ background-color: blue;
132
+ background: url('${'http://www.example.com/path/to/file.jpg'}');
133
+ `
134
+ const template = (
135
+ <>
136
+ <Style />
137
+ <h1 class={headerClass}>Hello!</h1>
138
+ </>
139
+ )
140
+ expect(await toString(template)).toBe(
141
+ '<style id="acryl-css">.css-1321888780{background-color:blue;background:url(\'http://www.example.com/path/to/file.jpg\')}</style><h1 class="css-1321888780">Hello!</h1>'
142
+ )
143
+ })
144
+
145
+ it('Should render CSS with escaped variable', async () => {
146
+ const headerClass = css`
147
+ background-color: blue;
148
+ content: '${rawCssString('say "Hello!"')}';
149
+ `
150
+ const template = (
151
+ <>
152
+ <Style />
153
+ <h1 class={headerClass}>Hello!</h1>
154
+ </>
155
+ )
156
+ expect(await toString(template)).toBe(
157
+ '<style id="acryl-css">.css-2238574885{background-color:blue;content:\'say "Hello!"\'}</style><h1 class="css-2238574885">Hello!</h1>'
158
+ )
159
+ })
160
+
161
+ it('Should render CSS with number', async () => {
162
+ const headerClass = css`
163
+ background-color: blue;
164
+ font-size: ${1}rem;
165
+ `
166
+ const template = (
167
+ <>
168
+ <Style />
169
+ <h1 class={headerClass}>Hello!</h1>
170
+ </>
171
+ )
172
+ expect(await toString(template)).toBe(
173
+ '<style id="acryl-css">.css-1847536026{background-color:blue;font-size:1rem}</style><h1 class="css-1847536026">Hello!</h1>'
174
+ )
175
+ })
176
+
177
+ it('Should render CSS with array', async () => {
178
+ const animation = keyframes`
179
+ from {
180
+ opacity: 0;
181
+ }
182
+ to {
183
+ opacity: 1;
184
+ }
185
+ `
186
+ const headerClass = css`
187
+ background-color: blue;
188
+ animation: ${animation} 1s ease-in-out;
189
+ `
190
+ const extendedHeaderClass = css`
191
+ ${headerClass}
192
+ color: red;
193
+ `
194
+ const template = (
195
+ <>
196
+ <Style />
197
+ <h1 class={extendedHeaderClass}>Hello!</h1>
198
+ </>
199
+ )
200
+ expect(await toString(template)).toBe(
201
+ '<style id="acryl-css">.css-2558359670{background-color:blue;animation:css-9294673 1s ease-in-out;color:red}@keyframes css-9294673{from{opacity:0}to{opacity:1}}</style><h1 class="css-2558359670">Hello!</h1>'
202
+ )
203
+ })
204
+
205
+ it.runIf(support.nest)(
206
+ 'Should be used as a class name for syntax `${className} {`',
207
+ async () => {
208
+ const headerClass = css`
209
+ font-weight: bold;
210
+ `
211
+ const containerClass = css`
212
+ ${headerClass} {
213
+ h1 {
214
+ color: red;
215
+ }
216
+ }
217
+ `
218
+ const template = (
219
+ <>
220
+ <Style />
221
+ <div class={containerClass}>
222
+ <h1 class={headerClass}>Hello!</h1>
223
+ </div>
224
+ </>
225
+ )
226
+ expect(await toString(template)).toBe(
227
+ '<style id="acryl-css">.css-4220297002{.css-1032195302{h1{color:red}}}.css-1032195302{font-weight:bold}</style><div class="css-4220297002"><h1 class="css-1032195302">Hello!</h1></div>'
228
+ )
229
+ }
230
+ )
231
+
232
+ it('Should be inserted to global if style string starts with :-acryl-root', async () => {
233
+ const globalClass = css`
234
+ :-acryl-global {
235
+ html {
236
+ color: red;
237
+ }
238
+ body {
239
+ display: flex;
240
+ }
241
+ }
242
+ `
243
+ const template = (
244
+ <>
245
+ <Style />
246
+ <div class={globalClass}>
247
+ <h1>Hello!</h1>
248
+ </div>
249
+ </>
250
+ )
251
+ expect(await toString(template)).toBe(
252
+ '<style id="acryl-css">html{color:red}body{display:flex}</style><div class=""><h1>Hello!</h1></div>'
253
+ )
254
+ })
255
+
256
+ it.runIf(support.nest)(
257
+ 'Should be inserted to global if style string starts with :-acryl-root and extends class name',
258
+ async () => {
259
+ const headerClass = css`
260
+ display: flex;
261
+ `
262
+ const specialHeaderClass = css`
263
+ :-acryl-global {
264
+ ${headerClass} {
265
+ h1 {
266
+ color: red;
267
+ }
268
+ }
269
+ }
270
+ `
271
+ const template = (
272
+ <>
273
+ <Style />
274
+ <div class={specialHeaderClass}>
275
+ <h1>Hello!</h1>
276
+ </div>
277
+ </>
278
+ )
279
+ expect(await toString(template)).toBe(
280
+ '<style id="acryl-css">.css-3980466870{h1{color:red}}.css-3980466870{display:flex}</style><div class="css-3980466870"><h1>Hello!</h1></div>'
281
+ )
282
+ }
283
+ )
284
+
285
+ it('Should be inserted as global css if passed css`` to Style component', async () => {
286
+ const headerClass = css`
287
+ font-size: 1rem;
288
+ `
289
+ const template = (
290
+ <>
291
+ <Style>{css`
292
+ html {
293
+ color: red;
294
+ }
295
+ body {
296
+ display: flex;
297
+ }
298
+ `}</Style>
299
+ <div>
300
+ <h1 class={headerClass}>Hello!</h1>
301
+ </div>
302
+ </>
303
+ )
304
+ expect(await toString(template)).toBe(
305
+ '<style id="acryl-css">html{color:red}body{display:flex}.css-1740067317{font-size:1rem}</style><div><h1 class="css-1740067317">Hello!</h1></div>'
306
+ )
307
+ })
308
+
309
+ it('Should be ignored :-acryl-root inside Style component', async () => {
310
+ const headerClass = css`
311
+ font-size: 1rem;
312
+ `
313
+ const template = (
314
+ <>
315
+ <Style>{css`
316
+ :-acryl-global {
317
+ html {
318
+ color: red;
319
+ }
320
+ body {
321
+ display: flex;
322
+ }
323
+ }
324
+ `}</Style>
325
+ <div>
326
+ <h1 class={headerClass}>Hello!</h1>
327
+ </div>
328
+ </>
329
+ )
330
+ expect(await toString(template)).toBe(
331
+ '<style id="acryl-css">html{color:red}body{display:flex}.css-1740067317{font-size:1rem}</style><div><h1 class="css-1740067317">Hello!</h1></div>'
332
+ )
333
+ })
334
+
335
+ describe('viewTransition', () => {
336
+ it('Should render CSS with unique view-transition-name', async () => {
337
+ const transition = viewTransition()
338
+ const template = (
339
+ <>
340
+ <Style />
341
+ <h1 class={transition}>Hello!</h1>
342
+ </>
343
+ )
344
+ expect(await toString(template)).toBe(
345
+ '<style id="acryl-css">.css-1644952339{view-transition-name:css-1644952339}</style><h1 class="css-1644952339">Hello!</h1>'
346
+ )
347
+ })
348
+
349
+ it('Should render CSS with css and keyframes', async () => {
350
+ const kf = keyframes`
351
+ from {
352
+ opacity: 0;
353
+ }
354
+ to {
355
+ opacity: 1;
356
+ }
357
+ `
358
+ const transition = viewTransition(css`
359
+ ::view-transition-old() {
360
+ animation-name: ${kf};
361
+ }
362
+ ::view-transition-new() {
363
+ animation-name: ${kf};
364
+ }
365
+ `)
366
+ const headerClass = css`
367
+ ${transition}
368
+ background-color: blue;
369
+ `
370
+ const template = (
371
+ <>
372
+ <Style />
373
+ <h1 class={headerClass}>Hello!</h1>
374
+ </>
375
+ )
376
+ expect(await toString(template)).toBe(
377
+ '<style id="acryl-css">.css-1245070278{view-transition-name:css-399742870;background-color:blue}@keyframes css-9294673{from{opacity:0}to{opacity:1}}::view-transition-old(css-399742870){animation-name:css-9294673}::view-transition-new(css-399742870){animation-name:css-9294673}</style><h1 class="css-1245070278">Hello!</h1>'
378
+ )
379
+ })
380
+
381
+ it('Should works as a template tag function', async () => {
382
+ const kf = keyframes`
383
+ from {
384
+ opacity: 0;
385
+ }
386
+ to {
387
+ opacity: 1;
388
+ }
389
+ `
390
+ const transition = viewTransition`
391
+ ::view-transition-old() {
392
+ animation-name: ${kf};
393
+ }
394
+ ::view-transition-new() {
395
+ animation-name: ${kf};
396
+ }
397
+ `
398
+ const headerClass = css`
399
+ ${transition}
400
+ background-color: blue;
401
+ `
402
+ const template = (
403
+ <>
404
+ <Style />
405
+ <h1 class={headerClass}>Hello!</h1>
406
+ </>
407
+ )
408
+ expect(await toString(template)).toBe(
409
+ '<style id="acryl-css">.css-1245070278{view-transition-name:css-399742870;background-color:blue}@keyframes css-9294673{from{opacity:0}to{opacity:1}}::view-transition-old(css-399742870){animation-name:css-9294673}::view-transition-new(css-399742870){animation-name:css-9294673}</style><h1 class="css-1245070278">Hello!</h1>'
410
+ )
411
+ })
412
+ })
413
+
414
+ it.runIf(support.nest)('Should render sub CSS with keyframe', async () => {
415
+ const headerClass = css`
416
+ background-color: blue;
417
+ ${[1, 2].map(
418
+ (i) => css`
419
+ :nth-child(${i}) {
420
+ color: red;
421
+ }
422
+ `
423
+ )}
424
+ `
425
+ const template = (
426
+ <>
427
+ <Style />
428
+ <h1 class={headerClass}>Hello!</h1>
429
+ </>
430
+ )
431
+ expect(await toString(template)).toBe(
432
+ '<style id="acryl-css">.css-1539881271{background-color:blue;:nth-child(1){color:red}:nth-child(2){color:red}}</style><h1 class="css-1539881271">Hello!</h1>'
433
+ )
434
+ })
435
+
436
+ it('Should be generated deferent class name for deferent first line comment even if the content is the same', async () => {
437
+ const headerClassA = css`
438
+ /* class A */
439
+ display: flex;
440
+ `
441
+ const headerClassB = css`
442
+ /* class B */
443
+ display: flex;
444
+ `
445
+ const template = (
446
+ <>
447
+ <Style />
448
+ <h1 class={headerClassA}>Hello!</h1>
449
+ <h1 class={headerClassB}>Hello!</h1>
450
+ </>
451
+ )
452
+ expect(await toString(template)).toBe(
453
+ '<style id="acryl-css">.css-3170754153{display:flex}.css-896513246{display:flex}</style><h1 class="css-3170754153">Hello!</h1><h1 class="css-896513246">Hello!</h1>'
454
+ )
455
+ })
456
+
457
+ describe('Booleans, Null, and Undefined Are Ignored', () => {
458
+ it.each([true, false, undefined, null])('%s', async (value) => {
459
+ const headerClass = css`
460
+ ${value}
461
+ background-color: blue;
462
+ `
463
+ const template = (
464
+ <>
465
+ <Style />
466
+ <h1 class={headerClass}>Hello!</h1>
467
+ </>
468
+ )
469
+ expect(await toString(template)).toBe(
470
+ '<style id="acryl-css">.css-2458908649{background-color:blue}</style><h1 class="css-2458908649">Hello!</h1>'
471
+ )
472
+ })
473
+
474
+ it('falsy value', async () => {
475
+ const value = 0
476
+ const headerClass = css`
477
+ padding: ${value};
478
+ `
479
+ const template = (
480
+ <>
481
+ <Style />
482
+ <h1 class={headerClass}>Hello!</h1>
483
+ </>
484
+ )
485
+ expect(await toString(template)).toBe(
486
+ '<style id="acryl-css">.css-478287868{padding:0}</style><h1 class="css-478287868">Hello!</h1>'
487
+ )
488
+ })
489
+
490
+ it('Should render CSS styles with CSP nonce', async () => {
491
+ const headerClass = css`
492
+ background-color: blue;
493
+ `
494
+ const template = (
495
+ <>
496
+ <Style nonce='1234' />
497
+ <h1 class={headerClass}>Hello!</h1>
498
+ </>
499
+ )
500
+ expect(await toString(template)).toBe(
501
+ '<style id="acryl-css" nonce="1234">.css-2458908649{background-color:blue}</style><h1 class="css-2458908649">Hello!</h1>'
502
+ )
503
+ })
504
+ })
505
+ })
506
+ }