@e280/sly 0.2.5 → 0.3.0-10

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 (350) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +356 -626
  3. package/package.json +22 -30
  4. package/s/_archive/README.md +1221 -0
  5. package/s/_archive/view/index.ts +7 -0
  6. package/s/_archive/view/types.ts +45 -0
  7. package/s/demo/demo.bundle.ts +5 -8
  8. package/s/demo/views/counter-light.ts +13 -0
  9. package/s/demo/views/counter-shadow.ts +16 -0
  10. package/s/demo/views/demo.ts +24 -20
  11. package/s/demo/views/loaders.ts +9 -9
  12. package/s/demo/views/time-light.ts +19 -0
  13. package/s/demo/views/time-shadow.ts +22 -0
  14. package/s/dom/attrs/attrs.ts +3 -3
  15. package/s/dom/attrs/parts/attr-spec.ts +17 -5
  16. package/s/dom/attrs/parts/on-attrs.ts +1 -1
  17. package/s/dom/dom.ts +1 -1
  18. package/s/index.html.ts +30 -33
  19. package/s/index.ts +2 -4
  20. package/s/{loaders → loader}/index.barrel.ts +0 -1
  21. package/s/{loaders → loader}/index.ts +0 -1
  22. package/s/{loaders → loader}/make.ts +1 -1
  23. package/s/{loaders → loader}/parts/ascii-anim.ts +6 -8
  24. package/s/loader/parts/error-display.ts +26 -0
  25. package/s/{loaders → loader}/types.ts +1 -1
  26. package/s/test.ts +5 -0
  27. package/s/view/common/css-reset.ts +19 -0
  28. package/s/view/common/sly-shadow.ts +14 -0
  29. package/s/view/elements/light.ts +14 -0
  30. package/s/view/elements/shadow.ts +52 -0
  31. package/s/view/hooks/plumbing/hooks.ts +28 -0
  32. package/s/view/hooks/plumbing/hookscope.ts +12 -0
  33. package/s/view/hooks/use-attrs.ts +28 -0
  34. package/s/view/hooks/use-css.ts +14 -0
  35. package/s/view/hooks/use-cx.ts +41 -0
  36. package/s/view/hooks/use-life.ts +17 -0
  37. package/s/view/hooks/use-mount.ts +30 -0
  38. package/s/view/hooks/use-name.ts +10 -0
  39. package/s/view/hooks/use-once.ts +9 -0
  40. package/s/view/hooks/use-op.ts +12 -0
  41. package/s/view/hooks/use-ref.ts +11 -0
  42. package/s/view/hooks/use-signal.ts +16 -0
  43. package/s/view/hooks/use-state.ts +20 -0
  44. package/s/view/hooks/use-wake.ts +8 -0
  45. package/s/view/index.ts +22 -4
  46. package/s/view/light.ts +50 -0
  47. package/s/view/parts/apply-attrs.ts +22 -0
  48. package/s/view/parts/apply-styles.ts +21 -0
  49. package/s/view/parts/cx.ts +26 -0
  50. package/s/view/parts/reactivity.ts +22 -0
  51. package/s/view/shadow.ts +93 -0
  52. package/s/view/types.ts +15 -34
  53. package/x/demo/demo.bundle.js +5 -8
  54. package/x/demo/demo.bundle.js.map +1 -1
  55. package/x/demo/demo.bundle.min.js +52 -63
  56. package/x/demo/demo.bundle.min.js.map +4 -4
  57. package/x/demo/views/counter-light.d.ts +1 -0
  58. package/x/demo/views/counter-light.js +10 -0
  59. package/x/demo/views/counter-light.js.map +1 -0
  60. package/x/demo/views/counter-shadow.d.ts +1 -0
  61. package/x/demo/views/counter-shadow.js +12 -0
  62. package/x/demo/views/counter-shadow.js.map +1 -0
  63. package/x/demo/views/demo.d.ts +1 -4
  64. package/x/demo/views/demo.js +24 -20
  65. package/x/demo/views/demo.js.map +1 -1
  66. package/x/demo/views/loaders.d.ts +1 -1
  67. package/x/demo/views/loaders.js +9 -9
  68. package/x/demo/views/loaders.js.map +1 -1
  69. package/x/demo/views/{counter.d.ts → time-light.d.ts} +3 -19
  70. package/x/demo/views/time-light.js +16 -0
  71. package/x/demo/views/time-light.js.map +1 -0
  72. package/x/demo/views/time-shadow.d.ts +365 -0
  73. package/x/demo/views/time-shadow.js +18 -0
  74. package/x/demo/views/time-shadow.js.map +1 -0
  75. package/x/dom/attrs/attrs.d.ts +3 -2
  76. package/x/dom/attrs/attrs.js +2 -2
  77. package/x/dom/attrs/attrs.js.map +1 -1
  78. package/x/dom/attrs/parts/attr-spec.d.ts +5 -1
  79. package/x/dom/attrs/parts/attr-spec.js +12 -6
  80. package/x/dom/attrs/parts/attr-spec.js.map +1 -1
  81. package/x/dom/attrs/parts/on-attrs.d.ts +1 -1
  82. package/x/dom/attrs/parts/on-attrs.js.map +1 -1
  83. package/x/dom/dom.d.ts +1 -1
  84. package/x/dom/dom.js.map +1 -1
  85. package/x/index.d.ts +2 -4
  86. package/x/index.html +30 -140
  87. package/x/index.html.js +31 -31
  88. package/x/index.html.js.map +1 -1
  89. package/x/index.js +2 -4
  90. package/x/index.js.map +1 -1
  91. package/x/{loaders → loader}/index.barrel.d.ts +0 -1
  92. package/x/loader/index.barrel.js.map +1 -0
  93. package/x/{loaders → loader}/index.d.ts +0 -1
  94. package/x/loader/index.js.map +1 -0
  95. package/x/{loaders → loader}/make.d.ts +1 -1
  96. package/x/loader/make.js.map +1 -0
  97. package/x/loader/mock.js.map +1 -0
  98. package/x/loader/parts/anims.js.map +1 -0
  99. package/x/{loaders → loader}/parts/ascii-anim.d.ts +1 -1
  100. package/x/{loaders → loader}/parts/ascii-anim.js +6 -7
  101. package/x/loader/parts/ascii-anim.js.map +1 -0
  102. package/x/loader/parts/error-display.d.ts +1 -0
  103. package/x/loader/parts/error-display.js +20 -0
  104. package/x/loader/parts/error-display.js.map +1 -0
  105. package/x/{loaders → loader}/types.d.ts +1 -1
  106. package/x/{loaders → loader}/types.js.map +1 -1
  107. package/x/loot/drag-and-drops.d.ts +2 -2
  108. package/x/loot/drops.d.ts +1 -1
  109. package/x/op/index.js.map +1 -0
  110. package/x/op/op.js.map +1 -0
  111. package/x/op/podium.js.map +1 -0
  112. package/x/{ops → op}/types.js.map +1 -1
  113. package/x/test.js +3 -0
  114. package/x/test.js.map +1 -0
  115. package/x/view/common/css-reset.js +17 -0
  116. package/x/view/common/css-reset.js.map +1 -0
  117. package/x/view/common/sly-shadow.d.ts +4 -0
  118. package/x/view/common/sly-shadow.js +11 -0
  119. package/x/view/common/sly-shadow.js.map +1 -0
  120. package/x/view/elements/light.d.ts +357 -0
  121. package/x/view/elements/light.js +10 -0
  122. package/x/view/elements/light.js.map +1 -0
  123. package/x/view/elements/shadow.d.ts +366 -0
  124. package/x/view/elements/shadow.js +42 -0
  125. package/x/view/elements/shadow.js.map +1 -0
  126. package/x/view/hooks/plumbing/hooks.d.ts +11 -0
  127. package/x/view/hooks/plumbing/hooks.js +26 -0
  128. package/x/view/hooks/plumbing/hooks.js.map +1 -0
  129. package/x/view/hooks/plumbing/hookscope.d.ts +10 -0
  130. package/x/view/hooks/plumbing/hookscope.js +12 -0
  131. package/x/view/hooks/plumbing/hookscope.js.map +1 -0
  132. package/x/view/hooks/use-attrs.d.ts +2 -0
  133. package/x/view/hooks/use-attrs.js +23 -0
  134. package/x/view/hooks/use-attrs.js.map +1 -0
  135. package/x/view/hooks/use-css.d.ts +4 -0
  136. package/x/view/hooks/use-css.js +10 -0
  137. package/x/view/hooks/use-css.js.map +1 -0
  138. package/x/view/hooks/use-cx.d.ts +10 -0
  139. package/x/view/hooks/use-cx.js +33 -0
  140. package/x/view/hooks/use-cx.js.map +1 -0
  141. package/x/view/hooks/use-life.d.ts +2 -0
  142. package/x/view/hooks/use-life.js +13 -0
  143. package/x/view/hooks/use-life.js.map +1 -0
  144. package/x/{base/utils/mounts.d.ts → view/hooks/use-mount.d.ts} +1 -0
  145. package/x/{base/utils/mounts.js → view/hooks/use-mount.js} +7 -1
  146. package/x/view/hooks/use-mount.js.map +1 -0
  147. package/x/view/hooks/use-name.d.ts +2 -0
  148. package/x/view/hooks/use-name.js +8 -0
  149. package/x/view/hooks/use-name.js.map +1 -0
  150. package/x/view/hooks/use-once.d.ts +2 -0
  151. package/x/view/hooks/use-once.js +7 -0
  152. package/x/view/hooks/use-once.js.map +1 -0
  153. package/x/view/hooks/use-op.d.ts +3 -0
  154. package/x/view/hooks/use-op.js +9 -0
  155. package/x/view/hooks/use-op.js.map +1 -0
  156. package/x/view/hooks/use-ref.d.ts +5 -0
  157. package/x/view/hooks/use-ref.js +11 -0
  158. package/x/view/hooks/use-ref.js.map +1 -0
  159. package/x/view/hooks/use-signal.d.ts +3 -0
  160. package/x/view/hooks/use-signal.js +12 -0
  161. package/x/view/hooks/use-signal.js.map +1 -0
  162. package/x/view/hooks/use-state.d.ts +1 -0
  163. package/x/view/hooks/use-state.js +17 -0
  164. package/x/view/hooks/use-state.js.map +1 -0
  165. package/x/view/hooks/use-wake.d.ts +2 -0
  166. package/x/view/hooks/use-wake.js +6 -0
  167. package/x/view/hooks/use-wake.js.map +1 -0
  168. package/x/view/index.d.ts +19 -4
  169. package/x/view/index.js +19 -4
  170. package/x/view/index.js.map +1 -1
  171. package/x/view/light.d.ts +2 -0
  172. package/x/view/light.js +41 -0
  173. package/x/view/light.js.map +1 -0
  174. package/x/view/parts/apply-attrs.d.ts +2 -0
  175. package/x/view/parts/apply-attrs.js +22 -0
  176. package/x/view/parts/apply-attrs.js.map +1 -0
  177. package/x/{base/utils → view/parts}/apply-styles.js.map +1 -1
  178. package/x/view/parts/cx.d.ts +12 -0
  179. package/x/view/parts/cx.js +24 -0
  180. package/x/view/parts/cx.js.map +1 -0
  181. package/x/view/parts/reactivity.d.ts +5 -0
  182. package/x/view/parts/reactivity.js +18 -0
  183. package/x/view/parts/reactivity.js.map +1 -0
  184. package/x/view/shadow.d.ts +6 -0
  185. package/x/view/shadow.js +71 -0
  186. package/x/view/shadow.js.map +1 -0
  187. package/x/view/types.d.ts +13 -21
  188. package/s/demo/views/counter.ts +0 -50
  189. package/s/demo/views/fastcount.ts +0 -29
  190. package/s/demo/views/mounting.ts +0 -36
  191. package/s/loaders/parts/error-display.ts +0 -26
  192. package/s/tests.test.ts +0 -8
  193. package/x/base/css-reset.js +0 -19
  194. package/x/base/css-reset.js.map +0 -1
  195. package/x/base/element.d.ts +0 -19
  196. package/x/base/element.js +0 -55
  197. package/x/base/element.js.map +0 -1
  198. package/x/base/index.d.ts +0 -5
  199. package/x/base/index.js +0 -6
  200. package/x/base/index.js.map +0 -1
  201. package/x/base/types.d.ts +0 -3
  202. package/x/base/types.js +0 -3
  203. package/x/base/types.js.map +0 -1
  204. package/x/base/use.d.ts +0 -59
  205. package/x/base/use.js +0 -129
  206. package/x/base/use.js.map +0 -1
  207. package/x/base/utils/attr-watcher.d.ts +0 -8
  208. package/x/base/utils/attr-watcher.js +0 -20
  209. package/x/base/utils/attr-watcher.js.map +0 -1
  210. package/x/base/utils/mounts.js.map +0 -1
  211. package/x/base/utils/reactor.d.ts +0 -5
  212. package/x/base/utils/reactor.js +0 -25
  213. package/x/base/utils/reactor.js.map +0 -1
  214. package/x/base/utils/states.d.ts +0 -13
  215. package/x/base/utils/states.js +0 -41
  216. package/x/base/utils/states.js.map +0 -1
  217. package/x/base/utils/use-attrs.d.ts +0 -11
  218. package/x/base/utils/use-attrs.js +0 -18
  219. package/x/base/utils/use-attrs.js.map +0 -1
  220. package/x/demo/views/counter.js +0 -42
  221. package/x/demo/views/counter.js.map +0 -1
  222. package/x/demo/views/fastcount.d.ts +0 -12
  223. package/x/demo/views/fastcount.js +0 -21
  224. package/x/demo/views/fastcount.js.map +0 -1
  225. package/x/demo/views/mounting.d.ts +0 -3
  226. package/x/demo/views/mounting.js +0 -28
  227. package/x/demo/views/mounting.js.map +0 -1
  228. package/x/loaders/index.barrel.js.map +0 -1
  229. package/x/loaders/index.js.map +0 -1
  230. package/x/loaders/make.js.map +0 -1
  231. package/x/loaders/mock.js.map +0 -1
  232. package/x/loaders/parts/anims.js.map +0 -1
  233. package/x/loaders/parts/ascii-anim.js.map +0 -1
  234. package/x/loaders/parts/error-display.d.ts +0 -1
  235. package/x/loaders/parts/error-display.js +0 -20
  236. package/x/loaders/parts/error-display.js.map +0 -1
  237. package/x/ops/index.js.map +0 -1
  238. package/x/ops/op.js.map +0 -1
  239. package/x/ops/podium.js.map +0 -1
  240. package/x/spa/index.barrel.d.ts +0 -4
  241. package/x/spa/index.barrel.js +0 -3
  242. package/x/spa/index.barrel.js.map +0 -1
  243. package/x/spa/index.d.ts +0 -2
  244. package/x/spa/index.js +0 -2
  245. package/x/spa/index.js.map +0 -1
  246. package/x/spa/plumbing/braces.d.ts +0 -12
  247. package/x/spa/plumbing/braces.js +0 -55
  248. package/x/spa/plumbing/braces.js.map +0 -1
  249. package/x/spa/plumbing/primitives.d.ts +0 -22
  250. package/x/spa/plumbing/primitives.js +0 -65
  251. package/x/spa/plumbing/primitives.js.map +0 -1
  252. package/x/spa/plumbing/router-core.d.ts +0 -13
  253. package/x/spa/plumbing/router-core.js +0 -38
  254. package/x/spa/plumbing/router-core.js.map +0 -1
  255. package/x/spa/plumbing/types.d.ts +0 -35
  256. package/x/spa/plumbing/types.js +0 -2
  257. package/x/spa/plumbing/types.js.map +0 -1
  258. package/x/spa/router.d.ts +0 -13
  259. package/x/spa/router.js +0 -39
  260. package/x/spa/router.js.map +0 -1
  261. package/x/spa/spa.test.d.ts +0 -15
  262. package/x/spa/spa.test.js +0 -78
  263. package/x/spa/spa.test.js.map +0 -1
  264. package/x/tests.test.js +0 -6
  265. package/x/tests.test.js.map +0 -1
  266. package/x/view/utils/contextualize.d.ts +0 -13
  267. package/x/view/utils/contextualize.js +0 -18
  268. package/x/view/utils/contextualize.js.map +0 -1
  269. package/x/view/utils/make-component.d.ts +0 -5
  270. package/x/view/utils/make-component.js +0 -17
  271. package/x/view/utils/make-component.js.map +0 -1
  272. package/x/view/utils/make-view.d.ts +0 -2
  273. package/x/view/utils/make-view.js +0 -32
  274. package/x/view/utils/make-view.js.map +0 -1
  275. package/x/view/utils/parts/capsule.d.ts +0 -12
  276. package/x/view/utils/parts/capsule.js +0 -56
  277. package/x/view/utils/parts/capsule.js.map +0 -1
  278. package/x/view/utils/parts/chain.d.ts +0 -13
  279. package/x/view/utils/parts/chain.js +0 -26
  280. package/x/view/utils/parts/chain.js.map +0 -1
  281. package/x/view/utils/parts/context.d.ts +0 -9
  282. package/x/view/utils/parts/context.js +0 -10
  283. package/x/view/utils/parts/context.js.map +0 -1
  284. package/x/view/utils/parts/directive.d.ts +0 -5
  285. package/x/view/utils/parts/directive.js +0 -20
  286. package/x/view/utils/parts/directive.js.map +0 -1
  287. package/x/view/utils/parts/naked.d.ts +0 -18
  288. package/x/view/utils/parts/naked.js +0 -57
  289. package/x/view/utils/parts/naked.js.map +0 -1
  290. package/x/view/utils/parts/sly-view.d.ts +0 -6
  291. package/x/view/utils/parts/sly-view.js +0 -16
  292. package/x/view/utils/parts/sly-view.js.map +0 -1
  293. package/x/view/view.d.ts +0 -11
  294. package/x/view/view.js +0 -15
  295. package/x/view/view.js.map +0 -1
  296. /package/s/{base → _archive/base}/css-reset.ts +0 -0
  297. /package/s/{base → _archive/base}/element.ts +0 -0
  298. /package/s/{base → _archive/base}/index.ts +0 -0
  299. /package/s/{base → _archive/base}/types.ts +0 -0
  300. /package/s/{base → _archive/base}/use.ts +0 -0
  301. /package/s/{base → _archive/base}/utils/apply-styles.ts +0 -0
  302. /package/s/{base → _archive/base}/utils/attr-watcher.ts +0 -0
  303. /package/s/{base → _archive/base}/utils/mounts.ts +0 -0
  304. /package/s/{base → _archive/base}/utils/reactor.ts +0 -0
  305. /package/s/{base → _archive/base}/utils/states.ts +0 -0
  306. /package/s/{base → _archive/base}/utils/use-attrs.ts +0 -0
  307. /package/s/{spa → _archive/spa}/index.barrel.ts +0 -0
  308. /package/s/{spa → _archive/spa}/index.ts +0 -0
  309. /package/s/{spa → _archive/spa}/plumbing/braces.ts +0 -0
  310. /package/s/{spa → _archive/spa}/plumbing/primitives.ts +0 -0
  311. /package/s/{spa → _archive/spa}/plumbing/router-core.ts +0 -0
  312. /package/s/{spa → _archive/spa}/plumbing/types.ts +0 -0
  313. /package/s/{spa → _archive/spa}/router.ts +0 -0
  314. /package/s/{spa → _archive/spa}/spa.test.ts +0 -0
  315. /package/s/{view → _archive/view}/utils/contextualize.ts +0 -0
  316. /package/s/{view → _archive/view}/utils/make-component.ts +0 -0
  317. /package/s/{view → _archive/view}/utils/make-view.ts +0 -0
  318. /package/s/{view → _archive/view}/utils/parts/capsule.ts +0 -0
  319. /package/s/{view → _archive/view}/utils/parts/chain.ts +0 -0
  320. /package/s/{view → _archive/view}/utils/parts/context.ts +0 -0
  321. /package/s/{view → _archive/view}/utils/parts/directive.ts +0 -0
  322. /package/s/{view → _archive/view}/utils/parts/naked.ts +0 -0
  323. /package/s/{view → _archive/view}/utils/parts/sly-view.ts +0 -0
  324. /package/s/{view → _archive/view}/view.ts +0 -0
  325. /package/s/{loaders → loader}/mock.ts +0 -0
  326. /package/s/{loaders → loader}/parts/anims.ts +0 -0
  327. /package/s/{ops → op}/index.ts +0 -0
  328. /package/s/{ops → op}/op.ts +0 -0
  329. /package/s/{ops → op}/podium.ts +0 -0
  330. /package/s/{ops → op}/types.ts +0 -0
  331. /package/x/{loaders → loader}/index.barrel.js +0 -0
  332. /package/x/{loaders → loader}/index.js +0 -0
  333. /package/x/{loaders → loader}/make.js +0 -0
  334. /package/x/{loaders → loader}/mock.d.ts +0 -0
  335. /package/x/{loaders → loader}/mock.js +0 -0
  336. /package/x/{loaders → loader}/parts/anims.d.ts +0 -0
  337. /package/x/{loaders → loader}/parts/anims.js +0 -0
  338. /package/x/{loaders → loader}/types.js +0 -0
  339. /package/x/{ops → op}/index.d.ts +0 -0
  340. /package/x/{ops → op}/index.js +0 -0
  341. /package/x/{ops → op}/op.d.ts +0 -0
  342. /package/x/{ops → op}/op.js +0 -0
  343. /package/x/{ops → op}/podium.d.ts +0 -0
  344. /package/x/{ops → op}/podium.js +0 -0
  345. /package/x/{ops → op}/types.d.ts +0 -0
  346. /package/x/{ops → op}/types.js +0 -0
  347. /package/x/{tests.test.d.ts → test.d.ts} +0 -0
  348. /package/x/{base → view/common}/css-reset.d.ts +0 -0
  349. /package/x/{base/utils → view/parts}/apply-styles.d.ts +0 -0
  350. /package/x/{base/utils → view/parts}/apply-styles.js +0 -0
@@ -0,0 +1,7 @@
1
+
2
+ export * from "./utils/parts/chain.js"
3
+ export * from "./utils/parts/sly-view.js"
4
+ export * from "./utils/contextualize.js"
5
+ export * from "./types.js"
6
+ export * from "./view.js"
7
+
@@ -0,0 +1,45 @@
1
+
2
+ import {TemplateResult} from "lit"
3
+ import {Constructor} from "@e280/stz"
4
+ import {DirectiveResult} from "lit/directive.js"
5
+
6
+ import {Use} from "../base/use.js"
7
+ import {BaseElement} from "../base/element.js"
8
+ import {ViewChain} from "./utils/parts/chain.js"
9
+
10
+ export type Content = TemplateResult | DirectiveResult | HTMLElement | string | null | undefined | void | Content[]
11
+
12
+ export type ViewFn<Props extends any[]> = (
13
+ (use: Use) =>
14
+ (...props: Props) =>
15
+ Content
16
+ )
17
+
18
+ export type View<Props extends any[]> = {
19
+ (...props: Props): DirectiveResult
20
+ props: (...props: Props) => ViewChain<Props>
21
+ transmute: <PropsB extends any[]>(convert: (...propsB: PropsB) => Props) => View<PropsB>
22
+ component: <B extends Constructor<BaseElement>>(Base?: B) => {
23
+ props: (propFn: (component: InstanceType<B>) => Props) => (
24
+ ComponentClass<B, Props>
25
+ )
26
+ }
27
+ naked: (host: HTMLElement) => NakedView<Props>
28
+ }
29
+
30
+ export type ViewProps<V extends View<any>> = (
31
+ V extends View<infer Props>
32
+ ? Props
33
+ : never
34
+ )
35
+
36
+ export type ComponentClass<B extends Constructor<BaseElement>, Props extends any[]> = {
37
+ view: View<Props>
38
+ new(): InstanceType<B>
39
+ } & B
40
+
41
+ export type NakedView<Props extends any[]> = {
42
+ host: HTMLElement
43
+ render: (...props: Props) => void
44
+ }
45
+
@@ -1,14 +1,11 @@
1
1
 
2
2
  import {dom} from "../dom/dom.js"
3
- import {CounterComponent} from "./views/counter.js"
4
- import {DemoComponent} from "./views/demo.js"
5
- import {FastcountElement} from "./views/fastcount.js"
3
+ import {Demo} from "./views/demo.js"
4
+ import {TimeLight} from "./views/time-light.js"
5
+ import {TimeShadow} from "./views/time-shadow.js"
6
6
 
7
- dom.register({
8
- DemoComponent,
9
- CounterComponent,
10
- FastcountElement,
11
- })
7
+ dom.register({TimeShadow, TimeLight})
12
8
 
9
+ dom.render(dom(".demo"), Demo())
13
10
  console.log("🦝 sly")
14
11
 
@@ -0,0 +1,13 @@
1
+
2
+ import {html} from "lit"
3
+ import {light, useSignal} from "../../view/index.js"
4
+
5
+ export const CounterLight = light((start: number) => {
6
+ const $count = useSignal(start)
7
+ const increment = () => $count.value++
8
+
9
+ return html`
10
+ <button @click="${increment}">${$count()}</button>
11
+ `
12
+ })
13
+
@@ -0,0 +1,16 @@
1
+
2
+ import {css, html} from "lit"
3
+ import {shadow, useName, useCss, useSignal} from "../../view/index.js"
4
+
5
+ export const CounterShadow = shadow((start: number) => {
6
+ useName("counter-shadow")
7
+ useCss(css`:host{display:inline-block} button{color:cyan}`)
8
+
9
+ const $count = useSignal(start)
10
+ const increment = () => $count.value++
11
+
12
+ return html`
13
+ <button @click="${increment}">${$count()}</button>
14
+ `
15
+ })
16
+
@@ -1,34 +1,38 @@
1
1
 
2
2
  import {css, html} from "lit"
3
-
4
- import {view} from "../../view/view.js"
5
- import {CounterView} from "./counter.js"
6
3
  import {LoadersView} from "./loaders.js"
7
- import {MountingTest} from "./mounting.js"
8
- import {cssReset} from "../../base/css-reset.js"
4
+ import {CounterLight} from "./counter-light.js"
5
+ import {CounterShadow} from "./counter-shadow.js"
6
+ import {cssReset, shadow, useName, useStyles} from "../../view/index.js"
9
7
 
10
- export class DemoComponent extends (view.component(use => {
11
- use.name("demo")
12
- use.styles(cssReset, styles)
8
+ export const Demo = shadow(() => {
9
+ useName("demo")
10
+ useStyles(cssReset, styles)
13
11
 
14
12
  return html`
15
- ${MountingTest()}
13
+ <p>light ${CounterLight(123)}</p>
14
+
15
+ <p>
16
+ shadow ${CounterShadow.with({
17
+ props: [234],
18
+ attrs: {"data-lol": 555},
19
+ children: html`<p>hello</p>`,
20
+ })}
21
+ </p>
16
22
 
17
- ${CounterView
18
- .props(768, 3)
19
- .children("view")
20
- .render()}
23
+ <time-shadow></time-shadow>
24
+ <time-light></time-light>
21
25
 
22
26
  ${LoadersView()}
23
27
  `
24
- })) {}
28
+ })
25
29
 
26
30
  const styles = css`
27
- :host {
28
- display: flex;
29
- flex-direction: column;
30
- align-items: center;
31
- gap: 1em;
32
- }
31
+ :host {
32
+ display: flex;
33
+ flex-direction: column;
34
+ align-items: center;
35
+ gap: 1em;
36
+ }
33
37
  `
34
38
 
@@ -1,17 +1,17 @@
1
1
 
2
2
  import {css, html} from "lit"
3
- import {Op} from "../../ops/op.js"
4
- import {view} from "../../view/view.js"
5
- import {loaders} from "../../loaders/index.js"
6
- import {cssReset} from "../../base/css-reset.js"
3
+ import {Op} from "../../op/op.js"
4
+ import {shadow} from "../../view/shadow.js"
5
+ import {loaders} from "../../loader/index.js"
6
+ import {cssReset, useName, useOnce, useStyles} from "../../view/index.js"
7
7
 
8
- export const LoadersView = view(use => () => {
9
- use.name("loaders")
10
- use.styles(cssReset, styles)
8
+ export const LoadersView = shadow(() => {
9
+ useName("loaders")
10
+ useStyles(cssReset, styles)
11
11
 
12
- const op = use.once(() => Op.loading())
12
+ const op = useOnce(() => Op.loading())
13
13
 
14
- const library = use.once(() =>
14
+ const library = useOnce(() =>
15
15
  Object.entries(loaders.anims).map(([key, anim]) => ({
16
16
  key,
17
17
  loader: loaders.make(anim)
@@ -0,0 +1,19 @@
1
+
2
+ import {html} from "lit"
3
+ import {cycle, nap} from "@e280/stz"
4
+ import {useMount, useSignal} from "../../view/index.js"
5
+ import {lightElement} from "../../view/elements/light.js"
6
+
7
+ export class TimeLight extends lightElement(() => {
8
+ const $time = useSignal(Date.now())
9
+
10
+ useMount(() => cycle(async() => {
11
+ await nap(100)
12
+ $time(Date.now())
13
+ }))
14
+
15
+ return html`
16
+ <p>${$time()}</p>
17
+ `
18
+ }) {}
19
+
@@ -0,0 +1,22 @@
1
+
2
+ import {css, html} from "lit"
3
+ import {cycle, nap} from "@e280/stz"
4
+ import {shadowElement} from "../../view/elements/shadow.js"
5
+ import {useCss, useMount, useName, useSignal} from "../../view/index.js"
6
+
7
+ export class TimeShadow extends shadowElement(() => {
8
+ useName("time-shadow")
9
+ useCss(css`:host{display:inline-block} button{color:cyan}`)
10
+
11
+ const $time = useSignal(Date.now())
12
+
13
+ useMount(() => cycle(async() => {
14
+ await nap(100)
15
+ $time(Date.now())
16
+ }))
17
+
18
+ return html`
19
+ <p>${$time()}</p>
20
+ `
21
+ }) {}
22
+
@@ -1,9 +1,9 @@
1
1
 
2
2
  import {AttrSpec} from "../types.js"
3
3
  import {onAttrs} from "./parts/on-attrs.js"
4
- import {attrSpec} from "./parts/attr-spec.js"
5
4
  import {AttrProxies} from "./parts/attr-proxies.js"
6
5
  import {attrGet, attrSet} from "./parts/attr-fns.js"
6
+ import {attrSpec, AttrSpecOptions} from "./parts/attr-spec.js"
7
7
 
8
8
  export function attrs(element: HTMLElement) {
9
9
  const proxies = new AttrProxies(element)
@@ -11,8 +11,8 @@ export function attrs(element: HTMLElement) {
11
11
  strings: proxies.strings,
12
12
  numbers: proxies.numbers,
13
13
  booleans: proxies.booleans,
14
- on: (fn: () => void) => onAttrs(element, fn),
15
- spec: <A extends AttrSpec>(spec: A) => attrSpec(element, spec),
14
+ on: (fn: MutationCallback) => onAttrs(element, fn),
15
+ spec: <A extends AttrSpec>(spec: A, options: AttrSpecOptions = {}) => attrSpec(element, spec, options),
16
16
  }
17
17
  }
18
18
 
@@ -2,10 +2,16 @@
2
2
  import {attrGet, attrSet} from "./attr-fns.js"
3
3
  import {AttrSpec, AttrTypes} from "../../types.js"
4
4
 
5
+ export type AttrSpecOptions = {
6
+ beforeSet?: (attrKey: string) => void
7
+ afterSet?: (attrKey: string) => void
8
+ }
9
+
5
10
  /** specify available html attributes and their types and create a proxy accessor */
6
11
  export const attrSpec = <A extends AttrSpec>(
7
12
  e: HTMLElement,
8
13
  spec: A,
14
+ options: AttrSpecOptions = {},
9
15
  ) => new Proxy(spec, {
10
16
 
11
17
  get: (_target, key: string) => {
@@ -18,11 +24,17 @@ export const attrSpec = <A extends AttrSpec>(
18
24
  },
19
25
 
20
26
  set: (_target, key: string, value: any) => {
21
- switch (spec[key]) {
22
- case String: return attrSet.string(e, key, value)
23
- case Number: return attrSet.number(e, key, value)
24
- case Boolean: return attrSet.boolean(e, key, value)
25
- default: throw new Error(`invalid attribute type for "${key}"`)
27
+ try {
28
+ options.beforeSet?.(key)
29
+ switch (spec[key]) {
30
+ case String: return attrSet.string(e, key, value)
31
+ case Number: return attrSet.number(e, key, value)
32
+ case Boolean: return attrSet.boolean(e, key, value)
33
+ default: throw new Error(`invalid attribute type for "${key}"`)
34
+ }
35
+ }
36
+ finally {
37
+ options.afterSet?.(key)
26
38
  }
27
39
  },
28
40
  }) as any as AttrTypes<A>
@@ -1,6 +1,6 @@
1
1
 
2
2
  /** respond when any attribute changes on the html element */
3
- export function onAttrs(element: HTMLElement, fn: () => void) {
3
+ export function onAttrs(element: HTMLElement, fn: MutationCallback) {
4
4
  const observer = new MutationObserver(fn)
5
5
  observer.observe(element, {attributes: true})
6
6
  return () => observer.disconnect()
package/s/dom/dom.ts CHANGED
@@ -11,7 +11,7 @@ import {register} from "./parts/register.js"
11
11
  import {Queryable, Renderable} from "./types.js"
12
12
  import {queryAll, queryMaybe, queryRequire} from "./parts/queries.js"
13
13
 
14
- export function dom<E extends Element>(selector: string, container: Queryable = document): E {
14
+ export function dom<E extends HTMLElement>(selector: string, container: Queryable = document) {
15
15
  return queryRequire<E>(selector, container)
16
16
  }
17
17
 
package/s/index.html.ts CHANGED
@@ -1,38 +1,35 @@
1
1
 
2
- import {ssg, html} from "@e280/scute"
2
+ import {template, html, socialCard} from "@e280/scute"
3
3
 
4
- const title = "sly"
5
- const description = "mischievous shadow views"
6
- const domain = "sly.e280.org"
7
- const favicon = "/assets/favicon.png"
4
+ export default template(import.meta.url, async orb => html`
5
+ <!doctype html>
6
+ <html>
7
+ <head>
8
+ <meta charset="utf-8"/>
9
+ <meta name="viewport" content="width=device-width,initial-scale=1"/>
10
+ <meta name="darkreader-lock"/>
11
+ <style>@layer base{html{background:#000}}</style>
8
12
 
9
- export default ssg.page(import.meta.url, async orb => ({
10
- title,
11
- js: "demo/demo.bundle.min.js",
12
- css: "demo/demo.css",
13
- favicon,
14
- dark: true,
15
- socialCard: {
16
- themeColor: "#95ff7b",
17
- title,
18
- description,
19
- siteName: "@e280/sly",
20
- image: "https://" + domain + favicon,
21
- },
13
+ <title>sly</title>
14
+ <link rel="icon" href="/assets/favicon.png"/>
15
+ <link rel="stylesheet" href="${orb.hashurl("demo/demo.css")}"/>
16
+ <script type="module" src="${orb.hashurl("demo/demo.bundle.min.js")}"></script>
22
17
 
23
- head: html`
24
- <meta name="example" value="whatever"/>
25
- `,
26
-
27
- body: html`
28
- <img class=icon alt="" src="/assets/favicon.png"/>
29
- <h1>sly testing page</h1>
30
- <p><a href="https://github.com/e280/sly">github.com/e280/sly</a></p>
31
- <p class=lil>v${orb.packageVersion()}</p>
32
-
33
- <fastcount-element></fastcount-element>
34
- <counter-component start=280 step=2>component</counter-component>
35
- <demo-component></demo-component>
36
- `,
37
- }))
18
+ ${socialCard({
19
+ themeColor: "#95ff7b",
20
+ title: "sly",
21
+ description: "mischievous shadow views",
22
+ siteName: "@e280/sly",
23
+ image: "https://sly.e280.org/assets/favicon.png",
24
+ })}
25
+ </head>
26
+ <body>
27
+ <img class=icon alt="" src="/assets/favicon.png"/>
28
+ <h1>sly testing page</h1>
29
+ <p><a href="https://github.com/e280/sly">github.com/e280/sly</a></p>
30
+ <p class=lil>v${orb.packageVersion()}</p>
31
+ <div class="demo"></div>
32
+ </body>
33
+ </html>
34
+ `)
38
35
 
package/s/index.ts CHANGED
@@ -1,9 +1,7 @@
1
1
 
2
- export * from "./base/index.js"
3
2
  export * from "./dom/index.js"
4
- export * from "./loaders/index.js"
3
+ export * from "./loader/index.js"
5
4
  export * from "./loot/index.js"
6
- export * from "./ops/index.js"
7
- export * from "./spa/index.js"
5
+ export * from "./op/index.js"
8
6
  export * from "./view/index.js"
9
7
 
@@ -1,6 +1,5 @@
1
1
 
2
2
  export * as anims from "./parts/anims.js"
3
- export type * from "./parts/anims.js"
4
3
  export * from "./parts/ascii-anim.js"
5
4
  export * from "./parts/error-display.js"
6
5
  export * from "./make.js"
@@ -1,4 +1,3 @@
1
1
 
2
2
  export * as loaders from "./index.barrel.js"
3
- export type * from "./index.barrel.js"
4
3
 
@@ -1,7 +1,7 @@
1
1
 
2
2
  import {Loader} from "./types.js"
3
3
  import {earth} from "./parts/anims.js"
4
- import type {Content} from "../view/types.js"
4
+ import {Content} from "../view/types.js"
5
5
  import {ErrorDisplay} from "./parts/error-display.js"
6
6
 
7
7
  export function make(
@@ -1,26 +1,24 @@
1
1
 
2
2
  import {css} from "lit"
3
3
  import {nap, cycle} from "@e280/stz"
4
-
5
- import {view} from "../../view/view.js"
6
4
  import {Content} from "../../view/types.js"
7
- import {cssReset} from "../../base/css-reset.js"
5
+ import {cssReset, shadow, useMount, useName, useSignal, useStyles} from "../../view/index.js"
8
6
 
9
7
  export function makeAsciiAnim(hz: number, frames: string[]): () => Content {
10
8
  return () => AsciiAnim({hz, frames})
11
9
  }
12
10
 
13
- export const AsciiAnim = view(use => ({hz, frames}: {
11
+ export const AsciiAnim = shadow(({hz, frames}: {
14
12
  hz: number,
15
13
  frames: string[],
16
14
  }) => {
17
15
 
18
- use.name("loading")
19
- use.styles(cssReset, style)
16
+ useName("loading")
17
+ useStyles(cssReset, style)
20
18
 
21
- const frame = use.signal(0)
19
+ const frame = useSignal(0)
22
20
 
23
- use.mount(() => cycle(async() => {
21
+ useMount(() => cycle(async() => {
24
22
  await nap(1000 / hz)
25
23
  const next = frame.get() + 1
26
24
  frame.set(next >= frames.length ? 0 : next)
@@ -0,0 +1,26 @@
1
+
2
+ import {css, html} from "lit"
3
+ import {shadow} from "../../view/shadow.js"
4
+ import {cssReset, useName, useStyles} from "../../view/index.js"
5
+
6
+ export const ErrorDisplay = shadow((error: any) => {
7
+ useName("error")
8
+ useStyles(cssReset, style)
9
+
10
+ if (typeof error === "string")
11
+ return error
12
+
13
+ else if (error instanceof Error)
14
+ return html`<strong>${error.name}:</strong> <span>${error.message}</span>`
15
+
16
+ else
17
+ return `error`
18
+ })
19
+
20
+ const style = css`
21
+ :host {
22
+ font-family: monospace;
23
+ color: red;
24
+ }
25
+ `
26
+
@@ -1,5 +1,5 @@
1
1
 
2
- import type {Op} from "../ops/op.js"
2
+ import type {Op} from "../op/op.js"
3
3
  import type {Content} from "../view/types.js"
4
4
 
5
5
  export type Loader = <V>(op: Op<V>, ready: (value: V) => Content) => Content
package/s/test.ts ADDED
@@ -0,0 +1,5 @@
1
+
2
+ import {Science} from "@e280/science"
3
+
4
+ await Science.run({})
5
+
@@ -0,0 +1,19 @@
1
+
2
+ import {css, CSSResultGroup} from "lit"
3
+
4
+ export const cssReset: CSSResultGroup = css`
5
+ * {
6
+ margin: 0;
7
+ padding: 0;
8
+ box-sizing: border-box;
9
+
10
+ scrollbar-width: thin;
11
+ scrollbar-color: #888 transparent;
12
+ }
13
+
14
+ ::-webkit-scrollbar { width: 8px; }
15
+ ::-webkit-scrollbar-track { background: transparent; }
16
+ ::-webkit-scrollbar-thumb { background: #888; border-radius: 1em; }
17
+ ::-webkit-scrollbar-thumb:hover { background: #999; }
18
+ `
19
+
@@ -0,0 +1,14 @@
1
+
2
+ import {dom} from "../../dom/dom.js"
3
+
4
+ export class SlyShadow extends HTMLElement {
5
+ static register() {
6
+ dom.register({SlyShadow}, {soft: true})
7
+ }
8
+
9
+ connectedCallback() {
10
+ if (!this.hasAttribute("view"))
11
+ this.setAttribute("view", "")
12
+ }
13
+ }
14
+
@@ -0,0 +1,14 @@
1
+
2
+ import {render} from "lit"
3
+ import {light} from "../light.js"
4
+ import {Content} from "../types.js"
5
+
6
+ export function lightElement(view: () => Content) {
7
+ const fn = light(view)
8
+
9
+ return class extends HTMLElement {
10
+ connectedCallback() { render(fn(), this) }
11
+ disconnectedCallback() { render(null, this) }
12
+ }
13
+ }
14
+
@@ -0,0 +1,52 @@
1
+
2
+ import {microbounce} from "@e280/stz"
3
+ import {render as litRender} from "lit"
4
+ import {Content} from "../types.js"
5
+ import {ShadowCx} from "../parts/cx.js"
6
+ import {hooks} from "../hooks/plumbing/hooks.js"
7
+ import {Reactivity} from "../parts/reactivity.js"
8
+ import {Hookscope} from "../hooks/plumbing/hookscope.js"
9
+
10
+ export function shadowElement(view: () => Content) {
11
+ return class extends HTMLElement {
12
+ #cx
13
+ #hookscope
14
+ #reactivity = new Reactivity()
15
+ #shadow = this.attachShadow({mode: "open"})
16
+
17
+ constructor() {
18
+ super()
19
+ const rerender = microbounce(() => {
20
+ if (!this.isConnected) return
21
+ const content = this.#renderContent()
22
+ litRender(content, this.#cx.shadow)
23
+ this.#cx.doneRender()
24
+ })
25
+ this.#cx = new ShadowCx(rerender, this, this.#shadow)
26
+ this.#hookscope = new Hookscope(this.#cx)
27
+ }
28
+
29
+ #renderContent() {
30
+ return this.#reactivity.observe(
31
+ () => hooks.wrap(this.#hookscope, () => view()),
32
+ this.#cx.render,
33
+ )
34
+ }
35
+
36
+ render() {
37
+ litRender(this.#renderContent(), this.#cx.shadow)
38
+ this.#cx.doneRender()
39
+ }
40
+
41
+ connectedCallback() {
42
+ this.#hookscope.mounts.remountAll()
43
+ this.#cx.render()
44
+ }
45
+
46
+ disconnectedCallback() {
47
+ this.#hookscope.mounts.unmountAll()
48
+ this.#reactivity.clear()
49
+ }
50
+ }
51
+ }
52
+
@@ -0,0 +1,28 @@
1
+
2
+ import {Hookscope} from "./hookscope.js"
3
+
4
+ export class Hooks {
5
+ #scopes: Hookscope[] = []
6
+
7
+ get scope() {
8
+ const scope = this.#scopes.at(-1)
9
+ if (!scope) throw new Error("hooks must be called within a render fn")
10
+ return scope
11
+ }
12
+
13
+ increment() {
14
+ const scope = this.scope
15
+ const position = scope.position++
16
+ return {scope, position}
17
+ }
18
+
19
+ wrap<Ret>(scope: Hookscope, fn: () => Ret) {
20
+ scope.position = 0
21
+ this.#scopes.push(scope)
22
+ try { return fn() }
23
+ finally { this.#scopes.pop() }
24
+ }
25
+ }
26
+
27
+ export const hooks: Hooks = (globalThis as any)[Symbol.for("e280.hooks")] ??= new Hooks()
28
+
@@ -0,0 +1,12 @@
1
+
2
+ import {GMap} from "@e280/stz"
3
+ import {Mounts} from "../use-mount.js"
4
+ import {LightCx, ShadowCx} from "../../parts/cx.js"
5
+
6
+ export class Hookscope {
7
+ position = 0
8
+ values = new GMap<number, any>()
9
+ mounts = new Mounts()
10
+ constructor(public cx: LightCx | ShadowCx) {}
11
+ }
12
+