@wrnrlr/prelude 0.1.8 → 0.2.0

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 (53) hide show
  1. package/.github/workflows/publish.yml +12 -11
  2. package/{deno.json → deno.jsonc} +13 -8
  3. package/example/index.html +43 -0
  4. package/package.json +6 -2
  5. package/src/constants.ts +110 -52
  6. package/src/controlflow.ts +140 -91
  7. package/src/hyperscript.ts +85 -109
  8. package/src/mod.ts +3 -5
  9. package/src/reactive.ts +29 -17
  10. package/src/runtime.ts +128 -66
  11. package/test/hyperscript.js +7 -6
  12. package/test/reactive.js +22 -2
  13. package/test/types.ts +44 -0
  14. package/src/components.js +0 -20
  15. package/src/ui/accordion.ts +0 -8
  16. package/src/ui/button.ts +0 -9
  17. package/src/ui/canvas.ts +0 -8
  18. package/src/ui/date.ts +0 -8
  19. package/src/ui/dialog.ts +0 -12
  20. package/src/ui/filter.ts +0 -8
  21. package/src/ui/form.ts +0 -7
  22. package/src/ui/h.ts +0 -48
  23. package/src/ui/image.ts +0 -5
  24. package/src/ui/input.ts +0 -49
  25. package/src/ui/mod.ts +0 -12
  26. package/src/ui/multiselect.ts +0 -42
  27. package/src/ui/option.ts +0 -1
  28. package/src/ui/select.ts +0 -28
  29. package/src/ui/tab.ts +0 -7
  30. package/src/ui/table.ts +0 -9
  31. package/src/ui/upload.ts +0 -7
  32. package/www/assets/css/presets.css +0 -504
  33. package/www/assets/css/style.css +0 -90
  34. package/www/demo.html +0 -28
  35. package/www/index.html +0 -211
  36. package/www/playground.html +0 -184
  37. package/www/public/banner.svg +0 -6
  38. package/www/public/example/admin.html +0 -88
  39. package/www/public/example/counter.html +0 -24
  40. package/www/public/example/greeting.html +0 -25
  41. package/www/public/example/select.html +0 -27
  42. package/www/public/example/show.html +0 -18
  43. package/www/public/example/todo.html +0 -70
  44. package/www/public/fonts/fab.ttf +0 -0
  45. package/www/public/fonts/fab.woff2 +0 -0
  46. package/www/public/fonts/far.ttf +0 -0
  47. package/www/public/fonts/far.woff2 +0 -0
  48. package/www/public/fonts/fas.ttf +0 -0
  49. package/www/public/fonts/fas.woff2 +0 -0
  50. package/www/public/logo.svg +0 -16
  51. package/www/typedoc.json +0 -13
  52. package/www/ui.html +0 -49
  53. package/www/vite.config.js +0 -106
package/src/ui/h.ts DELETED
@@ -1,48 +0,0 @@
1
- import {runtime,type Runtime} from '../runtime.ts'
2
- import {hyperscript,type HyperScript} from '../hyperscript.ts'
3
-
4
- let _fontMetricsCtx:undefined|CanvasRenderingContext2D
5
-
6
- export function fontMetrics(font:string, text:string) {
7
- if (!_fontMetricsCtx) _fontMetricsCtx = document.createElement('canvas').getContext('2d')
8
- _fontMetricsCtx!.font = font;
9
- return _fontMetricsCtx!.measureText(text)
10
- }
11
-
12
- export function renderEffect(fn:any):any {
13
- return requestAnimationFrame(()=>effect(fn))
14
- }
15
-
16
- const r:Runtime|undefined = /*#__PURE__*/ (typeof window === 'object') ? runtime(window as any) : undefined
17
-
18
- /** h
19
- @example Element with a single child
20
- ```js
21
- h('h1','Hello World!')
22
- ```
23
- @example Element with multiple children
24
- ```js
25
- h('p',['Hello ',h('em','World!')])
26
- ```
27
- @example Component with event handler
28
- ```js
29
- h(Input,{onInput:e => {}})
30
- ```
31
- @group Hyperscript
32
- */
33
- const h:HyperScript|undefined = /*#__PURE__*/ r ? hyperscript(r) : undefined
34
-
35
- const render = /*#__PURE__*/ r?.render
36
-
37
- // import {signal,wrap} from './reactive.ts'
38
-
39
- // /**
40
- // @group Utils
41
- // */
42
- // export function $(a:any,b:any):any {
43
- // const t = typeof a
44
- // if (t==='function') return wrap(a,b)
45
- // else return signal(a,b)
46
- // }
47
-
48
- export {h,render}
package/src/ui/image.ts DELETED
@@ -1,5 +0,0 @@
1
- import {h} from './h.ts'
2
-
3
- export function Img(props:ImgProps) {
4
- return h('img', props)
5
- }
package/src/ui/input.ts DELETED
@@ -1,49 +0,0 @@
1
- import {h,fontMetrics,renderEffect} from './h.ts'
2
- import {type Getter, type Setter} from '../reactive.ts'
3
-
4
- export type InputProps = {
5
- ref?: (r:HTMLElement)=>void,
6
- id?: string,
7
- autocomplete?: 'on'|'off',
8
- autosize?: (r:HTMLElement, props:any)=>(r:HTMLElement)=>void,
9
- class?: string,
10
- disabled?: boolean,
11
- name?: string,
12
- placeholder?: string,
13
- onInput?: (e:Event) => void,
14
- value: (Getter<string>&Setter<string>)|(Getter<number>&Setter<number>),
15
- style?: string,
16
- type?: string,
17
- }
18
-
19
- export function Input(props: InputProps): any {
20
- props.onInput = props.onInput || ((e:Event) => props.value(e?.target?.value))
21
- props.autocomplete = props.autocomplete || 'off'
22
- if (props.autosize) props.ref = (r)=>props.autosize(r,props)
23
- return h('input', props)
24
- }
25
-
26
- const autosize = (r:HTMLElement, props:any) => {
27
- const style = window.getComputedStyle(r)
28
- renderEffect(() => {
29
- const font = style.getPropertyValue('font')
30
- const metrics = fontMetrics(font, props.value().toString())
31
- r.style.width = metrics.width + 'px'
32
- })
33
- }
34
-
35
- Input.prototype.autosize = autosize
36
-
37
- // return h('input', {
38
- // ref,
39
- // id: props.id,
40
- // autocomplete: props.autocomplete || 'off',
41
- // class: props.class,
42
- // disabled: props.disabled,
43
- // onInput: (e:Event) => props.value(e?.target?.value),
44
- // name: props.name,
45
- // placeholder: props.placeholder,
46
- // type: props.type,
47
- // style: props.style,
48
- // value: props.value,
49
- // })
package/src/ui/mod.ts DELETED
@@ -1,12 +0,0 @@
1
- export {Accordion, type AccordionProps} from './accordion.ts'
2
- export {Button, type ButtonProps} from './button.ts'
3
- export {Canvas} from './canvas.ts'
4
- export {DateInput} from './date.ts'
5
- export {Input, type InputProps} from './input.ts'
6
- export {Form} from './form.ts'
7
- export {Tab} from './tab.ts'
8
- export {Filter, type FilterProps} from './filter.ts'
9
- export {Multiselect, type MultiselectProps} from './multiselect.ts'
10
- export {Select, type SelectProps} from './select.ts'
11
- export {Table, type TableProps} from './table.ts'
12
- export {Upload} from './upload.ts'
@@ -1,42 +0,0 @@
1
- import {h} from './h.ts'
2
- import {signal} from "../reactive.ts"
3
- import {Dialog} from './dialog.ts'
4
- import {Button} from './button.ts'
5
-
6
- export type MultiselectProps = {
7
- key: string | ((item:unknown)=>string),
8
- label: string | ((item:unknown)=>string),
9
- options: string[] | (()=>string[]),
10
- disabled: boolean | (()=>boolean),
11
- value: string[] | ((value:string[])=>void),
12
- }
13
-
14
- export function Multiselect(props:MultiselectProps) {
15
- const showDialog = signal(true)
16
- const key = props.key || (f => f)
17
- const label = props.label || (f => f)
18
- const add = item => props.value([...props.value(), key(item)])
19
- const remove = i => _ => props.value(items=>items.toSpliced(i,1))
20
- const options = () => (props.options.call ? props.options() : props.options).filter(e=>!props.value().includes(e))
21
- const value = (...args:any[]) => (!args.length) ? props.value() : (show(false), add(key(args[0])))
22
- const disabled = () => ((props?.disabled?.call ? props.disabled() : props.disabled))
23
-
24
- return h('span.multiselect', [
25
- h(List, {each:()=>value}, (e,i) => h('span', [
26
- h(Button, {disabled}, ()=>label(e())),
27
- h(Button, {disabled, onClick:remove(i())})
28
- ])),
29
- h('span', {style:'position:relative'}, [
30
- h(Button, {
31
- onClick: _ => showDialog(b=>!b),
32
- class: () => showDialog() ? 'minus' : 'add',
33
- disabled: () => disabled() || !options().length,
34
- }, '+'),
35
- h(Dialog, {show:()=>showDialog}, h(Options, {
36
- options: () => options,
37
- value: () => value,
38
- label
39
- }))
40
- ])
41
- ])
42
- }
package/src/ui/option.ts DELETED
@@ -1 +0,0 @@
1
- import {h} from './h.ts'
package/src/ui/select.ts DELETED
@@ -1,28 +0,0 @@
1
- import {signal} from '../reactive.ts'
2
- import { h } from './h.ts'
3
- import {Dialog} from './dialog.ts'
4
- import {Button} from './button.ts'
5
-
6
- export type SelectProps = {
7
- label?: (value:any)=>string,
8
- key?: (value:any)=>string,
9
- options: any[] | (()=>any[]),
10
- }
11
-
12
- export function Select(props:SelectProps) {
13
- const show = signal(false)
14
- const label = props.label || (f => f)
15
- const key = props.key || (f => f)
16
- const placeholder = h('span.placeholder', props.placeholder)
17
- const display = () => props?.value?.() ? label(props.value()) : placeholder
18
- const value = (...args) => (!args.length) ? props.value() : (show(false), props.value(key(args[0])))
19
-
20
- return h('span.select', {id: props.id, class:props.class, style:'position:relative'}, [
21
- h(Button, {onClick:_ => show(b=>!b)}, display),
22
- h(Dialog, {show:()=>show}, h(Options, {
23
- options: props.options,
24
- value: ()=>value,
25
- label
26
- }))
27
- ])
28
- }
package/src/ui/tab.ts DELETED
@@ -1,7 +0,0 @@
1
- export type TabProps = {
2
-
3
- }
4
-
5
- export function Tab(props: TabProps) {
6
-
7
- }
package/src/ui/table.ts DELETED
@@ -1,9 +0,0 @@
1
- export type TableProps = {
2
- }
3
-
4
- export function Table(props:TableProps) {
5
- return h('table',[
6
- h('thead',[]),
7
- h('tbody',[])
8
- ])
9
- }
package/src/ui/upload.ts DELETED
@@ -1,7 +0,0 @@
1
- import {h} from './h.ts'
2
-
3
- export type UploadProps = {}
4
-
5
- export function Upload(props:UploadProps) {
6
- return h('input', props)
7
- }