@e280/sly 0.0.0-5 → 0.0.0-7

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 (41) hide show
  1. package/README.md +74 -2
  2. package/package.json +1 -1
  3. package/s/demo/demo.bundle.ts +5 -0
  4. package/s/demo/demo.css +4 -1
  5. package/s/demo/views/counter.ts +8 -4
  6. package/s/demo/views/demo.ts +1 -1
  7. package/s/demo/views/loaders.ts +16 -3
  8. package/s/features/dom/dollar.ts +2 -0
  9. package/s/features/op/loaders/parts/anims.ts +170 -34
  10. package/s/features/views/types.ts +7 -0
  11. package/s/features/views/use.ts +3 -2
  12. package/s/features/views/view.ts +33 -8
  13. package/s/index.html.ts +1 -0
  14. package/x/demo/demo.bundle.js +4 -0
  15. package/x/demo/demo.bundle.js.map +1 -1
  16. package/x/demo/demo.bundle.min.js +39 -22
  17. package/x/demo/demo.bundle.min.js.map +3 -3
  18. package/x/demo/demo.css +4 -1
  19. package/x/demo/views/counter.d.ts +1 -1
  20. package/x/demo/views/counter.js +8 -4
  21. package/x/demo/views/counter.js.map +1 -1
  22. package/x/demo/views/demo.js +1 -1
  23. package/x/demo/views/demo.js.map +1 -1
  24. package/x/demo/views/loaders.js +16 -3
  25. package/x/demo/views/loaders.js.map +1 -1
  26. package/x/features/dom/dollar.d.ts +1 -0
  27. package/x/features/dom/dollar.js +2 -0
  28. package/x/features/dom/dollar.js.map +1 -1
  29. package/x/features/op/loaders/parts/anims.d.ts +13 -3
  30. package/x/features/op/loaders/parts/anims.js +159 -33
  31. package/x/features/op/loaders/parts/anims.js.map +1 -1
  32. package/x/features/views/types.d.ts +6 -0
  33. package/x/features/views/use.d.ts +1 -1
  34. package/x/features/views/use.js +2 -1
  35. package/x/features/views/use.js.map +1 -1
  36. package/x/features/views/view.d.ts +3 -1
  37. package/x/features/views/view.js +27 -8
  38. package/x/features/views/view.js.map +1 -1
  39. package/x/index.html +7 -3
  40. package/x/index.html.js +1 -0
  41. package/x/index.html.js.map +1 -1
package/README.md CHANGED
@@ -28,7 +28,14 @@ views are leaner than web components.. no dom registration, no string tag names.
28
28
 
29
29
  sly views are wired to automatically rerender whenever they're using any state stuff from [@e280/strata](https://github.com/e280/strata).
30
30
 
31
- ### 🍋 basic view example
31
+ - a minimal view looks like this:
32
+ ```ts
33
+ import {view} from "@e280/sly"
34
+
35
+ view(use => () => "hello world")
36
+ ```
37
+
38
+ ### 🍋 view example
32
39
  - views are hooks-based functional components with a [shadow root](https://developer.mozilla.org/en-US/docs/Web/API/Web_components/Using_shadow_DOM)
33
40
  - **declaring a view**
34
41
  ```ts
@@ -42,7 +49,7 @@ sly views are wired to automatically rerender whenever they're using any state s
42
49
 
43
50
  return html`
44
51
  <p>count ${count()}</p>
45
- <button @click="${() => { count.value++ }}"></button>
52
+ <button @click="${() => { count.value++ }}">+</button>
46
53
  `
47
54
  })
48
55
  ```
@@ -167,6 +174,29 @@ sly views are wired to automatically rerender whenever they're using any state s
167
174
  const op = use.op.promise(doAsyncWork())
168
175
  ```
169
176
 
177
+ ### 🍋 web components
178
+ - convert any view into a proper web component
179
+ ```ts
180
+ CounterView.component(1)
181
+ ```
182
+ - or build a component directly
183
+ ```ts
184
+ const MyComponent = view(use => html`hello world`)
185
+ ```
186
+ - register web components to the dom like this
187
+ ```ts
188
+ import {$} from "@e280/sly"
189
+
190
+ $.register({
191
+ MyCounter: CounterView.component(1),
192
+ MyComponent,
193
+ })
194
+
195
+ // <my-counter></my-counter>
196
+ // <my-component></my-component>
197
+ ```
198
+ - `$.register` automatically dashes the tag names (`MyComponent` becomes `<my-component>`)
199
+
170
200
  ### 🍋 neat tricks to impress the ladies
171
201
  - make a ticker — mount, repeat, and nap
172
202
  ```ts
@@ -189,6 +219,48 @@ sly views are wired to automatically rerender whenever they're using any state s
189
219
 
190
220
  <br/>
191
221
 
222
+ ## 🦝 SLY'S `$` DOLLAR DOM MULTITOOL
223
+ - import the `$` and it has a bunch of goodies
224
+ ```ts
225
+ import {$} from "@e280/sly"
226
+ ```
227
+ - query an element (throws an error if not found)
228
+ ```ts
229
+ $(".demo")
230
+ // HTMLElement
231
+ ```
232
+
233
+ ### queries
234
+ - query an element (undefined if not found)
235
+ ```ts
236
+ $.maybe(".demo")
237
+ // HTMLElement | undefined
238
+ ```
239
+ - query all elements (returns an array)
240
+ ```ts
241
+ $.maybe("ul li")
242
+ // HTMLElement[]
243
+ ```
244
+ - query all elements (returns an array)
245
+ ```ts
246
+ $.maybe("ul li")
247
+ // HTMLElement[]
248
+ ```
249
+
250
+ ### dom stuff
251
+ - register web components
252
+ ```ts
253
+ $.register({MyComponent, AnotherCoolComponent})
254
+ // <my-component>
255
+ // <another-cool-component>
256
+ ```
257
+ - render content into an element
258
+ ```ts
259
+ $.render(element, html`hello world`)
260
+ ```
261
+
262
+ <br/>
263
+
192
264
  ## 🦝 SLY OPS, PODS, AND LOADERS
193
265
  > ***TODO*** *we need to write real docs for this, lol*
194
266
  - `Pod` is a type for loading/ready/error states
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@e280/sly",
3
- "version": "0.0.0-5",
3
+ "version": "0.0.0-7",
4
4
  "description": "web shadow views",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -1,8 +1,13 @@
1
1
 
2
2
  import {DemoView} from "./views/demo.js"
3
3
  import {$} from "../features/dom/dollar.js"
4
+ import {CounterView} from "./views/counter.js"
4
5
 
5
6
  $.render($(".demo"), DemoView())
6
7
 
8
+ $.register({
9
+ DemoCounter: CounterView.component(1),
10
+ })
11
+
7
12
  console.log("🦝 sly")
8
13
 
package/s/demo/demo.css CHANGED
@@ -5,7 +5,7 @@
5
5
  :root {
6
6
  --prime: #1eff00;
7
7
  --accent: #387d42;
8
- --pill: #12763959;
8
+ --pill: #1276391a;
9
9
  --bg: #0e2316;
10
10
  --link: cyan;
11
11
  }
@@ -52,6 +52,7 @@
52
52
 
53
53
  @layer page {
54
54
  :root {
55
+ height: 100%;
55
56
  font-size: 21px;
56
57
  font-family: sans-serif;
57
58
 
@@ -68,9 +69,11 @@
68
69
 
69
70
  body {
70
71
  width: 100%;
72
+ min-height: 100%;
71
73
  max-width: 32em;
72
74
  margin: auto;
73
75
  padding: 1em;
76
+ padding-bottom: 6em;
74
77
 
75
78
  display: flex;
76
79
  flex-direction: column;
@@ -5,7 +5,7 @@ import {repeat} from "@e280/stz"
5
5
  import {view} from "../../features/views/view.js"
6
6
  import {cssReset} from "../../features/views/css-reset.js"
7
7
 
8
- export const CounterView = view(use => () => {
8
+ export const CounterView = view(use => (initial: number) => {
9
9
  use.name("counter")
10
10
  use.styles(cssReset, styles)
11
11
 
@@ -17,10 +17,11 @@ export const CounterView = view(use => () => {
17
17
  seconds(Math.floor(since / 1000))
18
18
  }))
19
19
 
20
- const count = use.signal(0)
20
+ const count = use.signal(initial)
21
21
  const increment = () => count(count() + 1)
22
22
 
23
23
  return html`
24
+ <slot></slot>
24
25
  <div>
25
26
  <span>${seconds()}</span>
26
27
  </div>
@@ -34,9 +35,12 @@ export const CounterView = view(use => () => {
34
35
  const styles = css`
35
36
  :host {
36
37
  display: flex;
37
- flex-direction: column;
38
38
  justify-content: center;
39
- text-align: center;
39
+ gap: 1em;
40
+ }
41
+
42
+ button {
43
+ padding: 0.2em 0.5em;
40
44
  }
41
45
  `
42
46
 
@@ -10,7 +10,7 @@ export const DemoView = view(use => () => {
10
10
  use.styles(cssReset, styles)
11
11
 
12
12
  return html`
13
- ${CounterView()}
13
+ ${CounterView.children("view")(2)}
14
14
  ${LoadersView()}
15
15
  `
16
16
  })
@@ -44,15 +44,28 @@ div {
44
44
 
45
45
  display: flex;
46
46
  flex-direction: column;
47
+ justify-content: center;
47
48
  align-items: center;
48
- gap: 0.4em;
49
+ text-align: center;
49
50
 
51
+ gap: 0.4em;
50
52
  padding: 0.2em 0.5em;
51
53
  background: var(--pill);
52
54
  border-radius: 0.5em;
53
55
 
54
- span:nth-child(1) { font-size: 0.6em; }
55
- span:nth-child(2) { font-size: 1.2em; }
56
+ span:nth-child(1) {
57
+ font-size: 0.6em;
58
+ }
59
+
60
+ span:nth-child(2) {
61
+ display: flex;
62
+ justify-content: center;
63
+ align-items: center;
64
+
65
+ font-size: 1.2em;
66
+ min-width: 7em;
67
+ min-height: 2.5em;
68
+ }
56
69
  }
57
70
  `
58
71
 
@@ -1,5 +1,6 @@
1
1
 
2
2
  import {render} from "lit"
3
+ import {register} from "./register.js"
3
4
  import {Content} from "../views/types.js"
4
5
 
5
6
  export type Container = HTMLElement | ShadowRoot | DocumentFragment
@@ -22,4 +23,5 @@ $.maybe = <E extends HTMLElement = HTMLElement>(selector: string, context: Query
22
23
  $.all = all
23
24
 
24
25
  $.render = (container: Container, ...content: Content[]) => render(content, container)
26
+ $.register = register
25
27
 
@@ -2,16 +2,18 @@
2
2
  import {makeAsciiAnim} from "./ascii-anim.js"
3
3
  import {Content} from "../../../views/types.js"
4
4
 
5
- const hz = 20
5
+ const fast = 20
6
+ const mid = 10
7
+ const slow = 4
6
8
 
7
- export const spinner = makeAsciiAnim(hz, [
9
+ export const spinner = makeAsciiAnim(fast, [
8
10
  "|",
9
11
  "/",
10
12
  "-",
11
13
  "\\",
12
14
  ])
13
15
 
14
- export const braille = makeAsciiAnim(hz, [
16
+ export const braille = makeAsciiAnim(fast, [
15
17
  "⠈",
16
18
  "⠐",
17
19
  "⠠",
@@ -22,18 +24,7 @@ export const braille = makeAsciiAnim(hz, [
22
24
  "⠁",
23
25
  ])
24
26
 
25
- export const arrow = makeAsciiAnim(hz, [
26
- "←",
27
- "↖",
28
- "↑",
29
- "↗",
30
- "→",
31
- "↘",
32
- "↓",
33
- "↙",
34
- ])
35
-
36
- export const arrow2 = makeAsciiAnim(hz, [
27
+ export const arrow = makeAsciiAnim(fast, [
37
28
  "⬆️",
38
29
  "↗️",
39
30
  "➡️",
@@ -44,7 +35,7 @@ export const arrow2 = makeAsciiAnim(hz, [
44
35
  "↖️",
45
36
  ])
46
37
 
47
- export const bar = makeAsciiAnim(hz, [
38
+ export const bar = makeAsciiAnim(fast, [
48
39
  "▰▱▱▱▱",
49
40
  "▰▱▱▱▱",
50
41
  "▱▰▱▱▱",
@@ -57,7 +48,7 @@ export const bar = makeAsciiAnim(hz, [
57
48
  "▱▰▱▱▱",
58
49
  ])
59
50
 
60
- export const bar2 = makeAsciiAnim(hz, [
51
+ export const bar2 = makeAsciiAnim(fast, [
61
52
  "▱▱▰▱▱",
62
53
  "▱▱▱▰▱",
63
54
  "▱▱▱▰▰",
@@ -80,7 +71,7 @@ export const bar2 = makeAsciiAnim(hz, [
80
71
  "▱▰▱▱▱",
81
72
  ])
82
73
 
83
- export const bar3 = makeAsciiAnim(hz, [
74
+ export const bar3 = makeAsciiAnim(fast, [
84
75
  "▰▱▱▱▱",
85
76
  "▰▱▱▱▱",
86
77
  "▰▰▱▱▱",
@@ -97,7 +88,8 @@ export const bar3 = makeAsciiAnim(hz, [
97
88
  "▰▰▱▱▱",
98
89
  ])
99
90
 
100
- export const bar4 = makeAsciiAnim(hz, [
91
+ export const bar4 = makeAsciiAnim(fast, [
92
+ "▱▱▱▱▱",
101
93
  "▱▱▱▱▱",
102
94
  "▰▱▱▱▱",
103
95
  "▰▰▱▱▱",
@@ -111,14 +103,57 @@ export const bar4 = makeAsciiAnim(hz, [
111
103
  "▱▱▱▱▰",
112
104
  ])
113
105
 
114
- export const pie = makeAsciiAnim(hz, [
106
+ export const block = makeAsciiAnim(fast, [
107
+ "▁▁▁▁▁",
108
+ "▁▁▁▁▁",
109
+ "█▁▁▁▁",
110
+ "██▁▁▁",
111
+ "███▁▁",
112
+ "████▁",
113
+ "█████",
114
+ "█████",
115
+ "▁████",
116
+ "▁▁███",
117
+ "▁▁▁██",
118
+ "▁▁▁▁█",
119
+ ])
120
+
121
+ export const block2 = makeAsciiAnim(fast, [
122
+ "█▁▁▁▁",
123
+ "█▁▁▁▁",
124
+ "██▁▁▁",
125
+ "███▁▁",
126
+ "████▁",
127
+ "█████",
128
+ "█████",
129
+ "▁████",
130
+ "▁▁███",
131
+ "▁▁▁██",
132
+ "▁▁▁▁█",
133
+ "▁▁▁▁█",
134
+ "▁▁▁██",
135
+ "▁▁███",
136
+ "▁████",
137
+ "█████",
138
+ "█████",
139
+ "████▁",
140
+ "███▁▁",
141
+ "██▁▁▁",
142
+ ])
143
+
144
+ export const runner = makeAsciiAnim(slow, [
145
+ "🚶",
146
+ "🏃",
147
+ ])
148
+
149
+ export const pie = makeAsciiAnim(mid, [
115
150
  "◷",
116
151
  "◶",
117
152
  "◵",
118
153
  "◴",
119
154
  ])
120
155
 
121
- export const cylon = makeAsciiAnim(hz, [
156
+ export const cylon = makeAsciiAnim(fast, [
122
157
  "=----",
123
158
  "-=---",
124
159
  "--=--",
@@ -131,7 +166,7 @@ export const cylon = makeAsciiAnim(hz, [
131
166
  "=----",
132
167
  ])
133
168
 
134
- export const slider = makeAsciiAnim(hz, [
169
+ export const slider = makeAsciiAnim(fast, [
135
170
  "o----",
136
171
  "-o---",
137
172
  "--o--",
@@ -144,7 +179,72 @@ export const slider = makeAsciiAnim(hz, [
144
179
  "o----",
145
180
  ])
146
181
 
147
- export const scrubber = makeAsciiAnim(hz, [
182
+ export const brackets = makeAsciiAnim(mid, [
183
+ "[ ]",
184
+ "[ ]",
185
+ "[= ]",
186
+ "[== ]",
187
+ "[===]",
188
+ "[ ==]",
189
+ "[ =]",
190
+ ])
191
+
192
+ export const brackets2 = makeAsciiAnim(mid, [
193
+ "[ ]",
194
+ "[ ]",
195
+ "[= ]",
196
+ "[== ]",
197
+ "[===]",
198
+ "[ ==]",
199
+ "[ =]",
200
+ "[ ]",
201
+ "[ ]",
202
+ "[ =]",
203
+ "[ ==]",
204
+ "[===]",
205
+ "[== ]",
206
+ "[= ]",
207
+ ])
208
+
209
+ export const dots = makeAsciiAnim(mid, [
210
+ " ",
211
+ " ",
212
+ ". ",
213
+ ".. ",
214
+ "...",
215
+ " ..",
216
+ " .",
217
+ ])
218
+
219
+ export const dots2 = makeAsciiAnim(fast, [
220
+ ". ",
221
+ ". ",
222
+ ".. ",
223
+ "...",
224
+ " ..",
225
+ " .",
226
+ " .",
227
+ " ..",
228
+ "...",
229
+ ".. ",
230
+ ])
231
+
232
+ export const wave = makeAsciiAnim(fast, [
233
+ ".....",
234
+ ".....",
235
+ ":....",
236
+ "::...",
237
+ ":::..",
238
+ "::::.",
239
+ ":::::",
240
+ ":::::",
241
+ ".::::",
242
+ "..:::",
243
+ "...::",
244
+ "....:",
245
+ ])
246
+
247
+ export const wavescrub = makeAsciiAnim(fast, [
148
248
  ":....",
149
249
  ":....",
150
250
  "::...",
@@ -159,7 +259,7 @@ export const scrubber = makeAsciiAnim(hz, [
159
259
  "::...",
160
260
  ])
161
261
 
162
- export const pulse = makeAsciiAnim(hz, [
262
+ export const wavepulse = makeAsciiAnim(fast, [
163
263
  ".....",
164
264
  ".....",
165
265
  "..:..",
@@ -171,7 +271,28 @@ export const pulse = makeAsciiAnim(hz, [
171
271
  ":...:",
172
272
  ])
173
273
 
174
- export const bin = makeAsciiAnim(hz, [
274
+ export const wavepulse2 = makeAsciiAnim(fast, [
275
+ ".....",
276
+ ".....",
277
+ "..:..",
278
+ ".:::.",
279
+ ".:::.",
280
+ ":::::",
281
+ ":::::",
282
+ "::.::",
283
+ ":...:",
284
+ ".....",
285
+ ".....",
286
+ ":...:",
287
+ "::.::",
288
+ ":::::",
289
+ ":::::",
290
+ ".:::.",
291
+ ".:::.",
292
+ "..:..",
293
+ ])
294
+
295
+ export const bin = makeAsciiAnim(fast, [
175
296
  "000",
176
297
  "100",
177
298
  "110",
@@ -180,7 +301,7 @@ export const bin = makeAsciiAnim(hz, [
180
301
  "001",
181
302
  ])
182
303
 
183
- export const binary = makeAsciiAnim(hz, [
304
+ export const binary = makeAsciiAnim(fast, [
184
305
  "11111",
185
306
  "01111",
186
307
  "00111",
@@ -194,7 +315,7 @@ export const binary = makeAsciiAnim(hz, [
194
315
  "11110",
195
316
  ])
196
317
 
197
- export const binary2 = makeAsciiAnim(hz, [
318
+ export const binary2 = makeAsciiAnim(fast, [
198
319
  "11111",
199
320
  "01111",
200
321
  "10111",
@@ -209,7 +330,22 @@ export const binary2 = makeAsciiAnim(hz, [
209
330
  "01111",
210
331
  ])
211
332
 
212
- export const clock = makeAsciiAnim(hz, [
333
+ export const pulseblue = makeAsciiAnim(slow, [
334
+ "🔹",
335
+ "🔵",
336
+ ])
337
+
338
+ export const kiss = makeAsciiAnim(mid, [
339
+ "🙂",
340
+ "🙂",
341
+ "😗",
342
+ "😙",
343
+ "😘",
344
+ "😘",
345
+ "😙",
346
+ ])
347
+
348
+ export const clock = makeAsciiAnim(fast, [
213
349
  "🕐",
214
350
  "🕑",
215
351
  "🕒",
@@ -224,7 +360,7 @@ export const clock = makeAsciiAnim(hz, [
224
360
  "🕛",
225
361
  ])
226
362
 
227
- export const fistbump = makeAsciiAnim(hz, [
363
+ export const fistbump = makeAsciiAnim(fast, [
228
364
  "🤜 🤛",
229
365
  "🤜 🤛",
230
366
  "🤜 🤛",
@@ -237,23 +373,23 @@ export const fistbump = makeAsciiAnim(hz, [
237
373
  "🤜 ✨ 🤛",
238
374
  ])
239
375
 
240
- export const earth = makeAsciiAnim(4, [
376
+ export const earth = makeAsciiAnim(slow, [
241
377
  "🌎",
242
378
  "🌏",
243
379
  "🌍",
244
380
  ])
245
381
 
246
- export const lock = makeAsciiAnim(4, [
382
+ export const lock = makeAsciiAnim(slow, [
247
383
  "🔓",
248
384
  "🔒",
249
385
  ])
250
386
 
251
- export const bright = makeAsciiAnim(4, [
387
+ export const bright = makeAsciiAnim(slow, [
252
388
  "🔅",
253
389
  "🔆",
254
390
  ])
255
391
 
256
- export const speaker = makeAsciiAnim(4, [
392
+ export const speaker = makeAsciiAnim(slow, [
257
393
  "🔈",
258
394
  "🔈",
259
395
  "🔉",
@@ -262,7 +398,7 @@ export const speaker = makeAsciiAnim(4, [
262
398
  "🔉",
263
399
  ])
264
400
 
265
- export const moon = makeAsciiAnim(10, [
401
+ export const moon = makeAsciiAnim(mid, [
266
402
  "🌑",
267
403
  "🌑",
268
404
  "🌑",
@@ -1,4 +1,5 @@
1
1
 
2
+ import {Constructor} from "@e280/stz"
2
3
  import {DirectiveResult} from "lit/directive.js"
3
4
  import {CSSResultGroup, TemplateResult} from "lit"
4
5
 
@@ -7,6 +8,11 @@ import {Use} from "./use.js"
7
8
  export type Content = TemplateResult | DirectiveResult | HTMLElement | string | null | undefined | void | Content[]
8
9
  export type AttrValue = string | boolean | number | undefined | null | void
9
10
 
11
+ export type Component<Props extends any[] = []> = {
12
+ render(...props: Props): void
13
+ } & HTMLElement
14
+
15
+ export type ComponentFn = (use: Use) => Content
10
16
  export type ViewFn<Props extends any[]> = (use: Use) => (...props: Props) => Content
11
17
  export type BasicView<Props extends any[]> = (...props: Props) => DirectiveResult<any>
12
18
  export type View<Props extends any[]> = BasicView<Props> & {
@@ -15,6 +21,7 @@ export type View<Props extends any[]> = BasicView<Props> & {
15
21
  children: (...children: Content[]) => View<Props>
16
22
  attrs: (attrs: Record<string, AttrValue>) => View<Props>
17
23
  attr: (name: string, value: AttrValue) => View<Props>
24
+ component: (...props: Props) => Constructor<Component>
18
25
  }
19
26
 
20
27
  export type ViewSettings = ShadowRootInit & {
@@ -18,12 +18,13 @@ export class Use {
18
18
  #rendered = defer()
19
19
  #mounts = new Mounts()
20
20
 
21
- ;[_wrap](fn: () => void) {
21
+ ;[_wrap]<R>(fn: () => R) {
22
22
  this.#runs++
23
23
  this.#position = 0
24
24
  this.#rendered = defer()
25
- fn()
25
+ const result = fn()
26
26
  this.#rendered.resolve()
27
+ return result
27
28
  }
28
29
 
29
30
  ;[_disconnect]() {