npm.io
2.0.0 • Published 3 years ago

sigl

Licence
MIT
Version
2.0.0
Deps
14
Size
1.8 MB
Vulns
0
Weekly
0

sigl

Web framework

npm i sigl pnpm add sigl yarn add sigl

Examples

# web
    # view source example/web.tsx

    /** @jsxImportSource sigl */
    
    import $ from 'sigl'
    
    // simple reactive element
    
    interface ZooElement extends $.Element<ZooElement> { }
    
    @$.element()
    class ZooElement extends HTMLElement {
      @$.out() bananas = 0
      mounted($: this['
    

# worker
    # view source example/worker.ts

    import $ from 'sigl/worker'
    
    interface RxFoo extends $.Reactive<RxFoo> {}
    @$.reactive()
    class RxFoo {
      // properties
      result = 555
    
      min = 100
      max = 1000
    
      // example reducers
      scale = $(this).reduce(({ min, max }) => max - min)
      normal = $(this).reduce(({ scale, min, result }) => (result - min) / scale)
    }
    
    const rx = new RxFoo()
    console.log(rx.normal)

API

# default

    # AbortOptions

      sigl.AbortOptions

    # ChildOf

      sigl.ChildOf<T>

    # Class

      sigl.Class<T>

    # CleanClass

      sigl.CleanClass<T>

    # CleanInstance

      sigl.CleanInstance<T>

    # Component

      sigl.Component<T, I>

    # ComponentProps

      sigl.ComponentProps<T, I>

    # Context

      sigl.Context<T>

    # ContextClass

      sigl.ContextClass<T>

    # CustomElementConstructor

      sigl.CustomElementConstructor

    # Deps

      sigl.Deps<T>

    # Dispatch

      sigl.Dispatch<T>

    # DispatchOptions

      sigl.DispatchOptions

    # Element

      sigl.Element<T, E>

    # ElementClass

      sigl.ElementClass

    # EventHandler

      sigl.EventHandler<T, E>

    # EventKeys

      sigl.EventKeys<T>

    # EventOptions

      sigl.EventOptions

    # Events

      sigl.Events<T, P>

    # FxDeps

      sigl.FxDeps<T>

    # FxFn

      sigl.FxFn<T, R>

    # HTMLAttributes

      sigl.HTMLAttributes<T>

    # Intersect

      sigl.Intersect

    # JsxContext

      sigl.JsxContext<T>

    # Layout

      sigl.mixins.LayoutMixin

    # LifecycleEvents

      sigl.LifecycleEvents

    # Line

      sigl.Line

    # Matrix

      sigl.Matrix

    # Mixin

      sigl.Mixin

    # Morph

      sigl.Morph

    # Narrow

      sigl.Narrow<T, U>

    # NestedCSSCompiler

      sigl.NestedCSSCompiler

    # NestedCSSDeclaration

      sigl.NestedCSSDeclaration

    # Off

      sigl.Off

    # On

      sigl.On<T>

    # OnEvent

      sigl.OnEvent<T, K>

    # OnGetter

      sigl.OnGetter<T>

    # Placement

      sigl.Placement

    # Point

      sigl.Point

    # Polygon

      sigl.Polygon

    # Polyline

      sigl.Polyline

    # Positioned

      sigl.Positioned

    # PropertyKind

      sigl.PropertyKind<T>

    # PropsOf

      sigl.PropsOf<T>

    # QueueOptions

      sigl.QueueOptions

    # Reactive

      sigl.Reactive<T>

    # ReactiveClass

      sigl.ReactiveClass<T>

    # Rect

      sigl.Rect

    # Ref

      sigl.VRef<T>

    # RefItem

      sigl.RefItem<T>

    # RefMap

      sigl.RefMap<T>

    # RefSet

      sigl.RefSet<T>

    # Scalar

      sigl.Scalar

    # Shape

      sigl.Shape

    # ShapeLike

      sigl.ShapeLike

    # State

      sigl.State<T, U>

    # StateInstance

      sigl.StateInstance

    # Super

      sigl.Super<T, U>

    # Task

      sigl.Task

    # ValuesOf

      sigl.ValuesOf<T>

    # Vec3

      sigl.Vec3

# default(ctor)

    # ctor

    default<T extends  Class<T>>(ctor)  =>

      CleanClass<T>

    # ctx

    default<T>(ctx)  =>

      ElementWrapper<T>

    # ctx

    default<T extends  Reactive<any>>(ctx)  =>

      ReactiveWrapper<T>

Credits

Contributing

Fork or edit and submit a PR.

All contributions are welcome!

License

MIT 2022 stagas

]) { $.render(({ bananas }) => ( <div> {bananas} bananas <button onclick={() => $.bananas = bananas + 1}>+</button> <button onclick={() => $.bananas = bananas - 1}>-</button> </div> )) } } // example mixin const runnable = $.mixin(superclass => class extends superclass { speed = 10 } ) const swimmable = $.mixin(superclass => class extends superclass { depth = 10 } ) // a plain reactive class interface RxFoo extends $.Reactive<RxFoo> { } @$.reactive() class RxFoo { // properties result = 555 min = 100 max = 1000 // example reducers scale = $(this).reduce(({ min, max }) => max - min) normal = $(this).reduce(({ scale, min, result }) => (result - min) / scale) } const rx = new RxFoo() console.log(rx.normal) // an element with events interface FooEvents { jump: CustomEvent<{ height: number }> } interface FooElement extends $.Element<FooElement, FooEvents> { } @$.element() class FooElement extends $.mix(ZooElement, runnable, swimmable) { // dependencies Zoo = $.element(ZooElement) // makes a jsx component out of a web component element // attributes (reflected in html and reactive to them) @$.attr() color = 'blue' @$.attr() another = 123 @$.attr() withCapital = true @$.attr() notYet = $.Boolean // properties result = 42 min = 100 max = 1000 // example reducers scale = $(this).reduce(({ min, max }) => max - min) normal = $(this).reduce(({ scale, min, result }) => (result - min) / scale) inverted = $(this).fulfill(({ normal }) => fulfill => fulfill(-normal), 0) // example callback that mutates state toggle = $(this).callback(({ $, withCapital }) => (() => { $.withCapital = !withCapital })) // a ref we fill at render button?: HTMLButtonElement // a ref that we will be attaching effects on @$.out() zoo?: ZooElement hasBananas = false onPointerDown?: $.EventHandler<FooElement, PointerEvent> mounted($: this['

# __INLINE_CODE_5__

API

# __INLINE_CODE_7__

    # __INLINE_CODE_8__

      sigl.AbortOptions

    # __INLINE_CODE_9__

      sigl.ChildOf<T>

    # __INLINE_CODE_10__

      sigl.Class<T>

    # __INLINE_CODE_11__

      sigl.CleanClass<T>

    # __INLINE_CODE_12__

      sigl.CleanInstance<T>

    # __INLINE_CODE_13__

      sigl.Component<T, I>

    # __INLINE_CODE_14__

      sigl.ComponentProps<T, I>

    # __INLINE_CODE_15__

      sigl.Context<T>

    # __INLINE_CODE_16__

      sigl.ContextClass<T>

    # __INLINE_CODE_17__

      sigl.CustomElementConstructor

    # __INLINE_CODE_18__

      sigl.Deps<T>

    # __INLINE_CODE_19__

      sigl.Dispatch<T>

    # __INLINE_CODE_20__

      sigl.DispatchOptions

    # __INLINE_CODE_21__

      sigl.Element<T, E>

    # __INLINE_CODE_22__

      sigl.ElementClass

    # __INLINE_CODE_23__

      sigl.EventHandler<T, E>

    # __INLINE_CODE_24__

      sigl.EventKeys<T>

    # __INLINE_CODE_25__

      sigl.EventOptions

    # __INLINE_CODE_26__

      sigl.Events<T, P>

    # __INLINE_CODE_27__

      sigl.FxDeps<T>

    # __INLINE_CODE_28__

      sigl.FxFn<T, R>

    # __INLINE_CODE_29__

      sigl.HTMLAttributes<T>

    # __INLINE_CODE_30__

      sigl.Intersect

    # __INLINE_CODE_31__

      sigl.JsxContext<T>

    # __INLINE_CODE_32__

      sigl.mixins.LayoutMixin

    # __INLINE_CODE_33__

      sigl.LifecycleEvents

    # __INLINE_CODE_34__

      sigl.Line

    # __INLINE_CODE_35__

      sigl.Matrix

    # __INLINE_CODE_36__

      sigl.Mixin

    # __INLINE_CODE_37__

      sigl.Morph

    # __INLINE_CODE_38__

      sigl.Narrow<T, U>

    # __INLINE_CODE_39__

      sigl.NestedCSSCompiler

    # __INLINE_CODE_40__

      sigl.NestedCSSDeclaration

    # __INLINE_CODE_41__

      sigl.Off

    # __INLINE_CODE_42__

      sigl.On<T>

    # __INLINE_CODE_43__

      sigl.OnEvent<T, K>

    # __INLINE_CODE_44__

      sigl.OnGetter<T>

    # __INLINE_CODE_45__

      sigl.Placement

    # __INLINE_CODE_46__

      sigl.Point

    # __INLINE_CODE_47__

      sigl.Polygon

    # __INLINE_CODE_48__

      sigl.Polyline

    # __INLINE_CODE_49__

      sigl.Positioned

    # __INLINE_CODE_50__

      sigl.PropertyKind<T>

    # __INLINE_CODE_51__

      sigl.PropsOf<T>

    # __INLINE_CODE_52__

      sigl.QueueOptions

    # __INLINE_CODE_53__

      sigl.Reactive<T>

    # __INLINE_CODE_54__

      sigl.ReactiveClass<T>

    # __INLINE_CODE_55__

      sigl.Rect

    # __INLINE_CODE_56__

      sigl.VRef<T>

    # __INLINE_CODE_57__

      sigl.RefItem<T>

    # __INLINE_CODE_58__

      sigl.RefMap<T>

    # __INLINE_CODE_59__

      sigl.RefSet<T>

    # __INLINE_CODE_60__

      sigl.Scalar

    # __INLINE_CODE_61__

      sigl.Shape

    # __INLINE_CODE_62__

      sigl.ShapeLike

    # __INLINE_CODE_63__

      sigl.State<T, U>

    # __INLINE_CODE_64__

      sigl.StateInstance

    # __INLINE_CODE_65__

      sigl.Super<T, U>

    # __INLINE_CODE_66__

      sigl.Task

    # __INLINE_CODE_67__

      sigl.ValuesOf<T>

    # __INLINE_CODE_68__

      sigl.Vec3

# __INLINE_CODE_69__(ctor)

    # __INLINE_CODE_70__

    default<T extends  Class<T>>(ctor)  =>

      CleanClass<T>

    # __INLINE_CODE_71__

    default<T>(ctx)  =>

      ElementWrapper<T>

    # __INLINE_CODE_72__

    default<T extends  Reactive<any>>(ctx)  =>

      ReactiveWrapper<T>

Credits

Contributing

Fork or edit and submit a PR.

All contributions are welcome!

License

MIT 2022 stagas

]
) { // example reducer with circular dependency $.result = $.reduce(({ min, max, result }) => Math.max(min, Math.min(max, result))) $.onPointerDown = $.reduce(() => $.queue.throttle(100)(_e => { // }), _ => { }) // mixins test $.effect(({ speed, depth, }) => { const s = speed const d = depth console.log('got speed and depth from mixins', s, d) }) $.effect(({ host }) => { // html property listeners work like with regular elements host.onjump = ({ detail: { height } }) => { console.log(height) } // $.on has type access to all possible events (click etc) $.on(host).jump(({ detail: { height } }) => { console.log(height) }) // host.on has type access only to our own host events host.on('jump').once.passive($.atomic(({ detail: { height } }) => { console.log('height', height) })) // $.dispatch has type access to all possible events (click etc) $.dispatch.bubbles.composed(host, 'jump', { height: 456 }) // host.dispatch has type access only to our own host events host.dispatch.bubbles('jump', { height: 123 }) }) // example of the ref of the 'button' element firing when filled // and assigning a click handler with preventDefault + stopPropagation mods $.effect(({ button }) => $.on(button).click.prevent.stop(console.log)) // example of being reactive to state from foreign elements $.effect(({ zoo }) => // apply effect on raf (requestAnimationFrame) zoo.$.effect.raf(({ bananas }) => { $.hasBananas = !!bananas }) ) $.effect(() => { return () => { console.log('disconnected') } }) // this part can be inserted in the render below but will only appear // when its dependencies are met. both .part and .render also accept a // second argument, which is the default output when it's not yet fulfilled const Bar = $.part(({ withCapital }) => <div>{withCapital ? 'On' : 'Off'}</div>) // main render in animation frame $.render(({ Zoo, hasBananas, color, result, normal, toggle, withCapital }) => ( <> <style> {$.css /*css*/` /* top level is :host */ display: block; background: #444; button { /* an example of conditional css using regular string templating */ background: ${withCapital ? 'pink' : 'purple'}; /* sass style nesting */ &:hover { background: orange; } } `(/* here we can set a different top level selector, default is :host */)} </style> <div> <button ref={$.ref.button} onclick={$.event.stop(() => { $.color = color === 'red' ? 'blue' : 'red' })} > Toggle inline </button> color: {color} <hr /> <Zoo ref={$.ref.zoo} /> {hasBananas ? ($.zoo!.bananas) < 0 ? 'bananas?' : 'bananas!!' : 'no bananas :('} <hr /> result: {result} <button onclick={() => $.result = result + 1}>+</button> <button onclick={() => $.result = result - 1}>-</button> <hr /> normal: {normal.toFixed(3)} <hr /> <Bar /> <button onclick={$.event.prevent.throttle(500)(() => { $.withCapital = !withCapital })} > Toggle throttled inline </button> <button onclick={$.queue.throttle(300)(toggle)}> Toggle method </button> </div> </> )) } } customElements.define('x-foo', FooElement) const foo = new FooElement() document.body.appendChild(foo) foo.setAttribute('color', 'red') interface BarElement extends $.Element<BarElement> { } @$.element() class BarElement extends $.inherit(FooElement) { } customElements.define('x-bar', BarElement) new BarElement() interface XElement extends $.Element<XElement> { } @$.element() class XElement extends $.mix(HTMLElement, $.mixins.observed()) { @$.out() foo = 123 } customElements.define('x-x', XElement) // new BarElement()

# __INLINE_CODE_5__

API

# __INLINE_CODE_7__

    # __INLINE_CODE_8__

      sigl.AbortOptions

    # __INLINE_CODE_9__

      sigl.ChildOf<T>

    # __INLINE_CODE_10__

      sigl.Class<T>

    # __INLINE_CODE_11__

      sigl.CleanClass<T>

    # __INLINE_CODE_12__

      sigl.CleanInstance<T>

    # __INLINE_CODE_13__

      sigl.Component<T, I>

    # __INLINE_CODE_14__

      sigl.ComponentProps<T, I>

    # __INLINE_CODE_15__

      sigl.Context<T>

    # __INLINE_CODE_16__

      sigl.ContextClass<T>

    # __INLINE_CODE_17__

      sigl.CustomElementConstructor

    # __INLINE_CODE_18__

      sigl.Deps<T>

    # __INLINE_CODE_19__

      sigl.Dispatch<T>

    # __INLINE_CODE_20__

      sigl.DispatchOptions

    # __INLINE_CODE_21__

      sigl.Element<T, E>

    # __INLINE_CODE_22__

      sigl.ElementClass

    # __INLINE_CODE_23__

      sigl.EventHandler<T, E>

    # __INLINE_CODE_24__

      sigl.EventKeys<T>

    # __INLINE_CODE_25__

      sigl.EventOptions

    # __INLINE_CODE_26__

      sigl.Events<T, P>

    # __INLINE_CODE_27__

      sigl.FxDeps<T>

    # __INLINE_CODE_28__

      sigl.FxFn<T, R>

    # __INLINE_CODE_29__

      sigl.HTMLAttributes<T>

    # __INLINE_CODE_30__

      sigl.Intersect

    # __INLINE_CODE_31__

      sigl.JsxContext<T>

    # __INLINE_CODE_32__

      sigl.mixins.LayoutMixin

    # __INLINE_CODE_33__

      sigl.LifecycleEvents

    # __INLINE_CODE_34__

      sigl.Line

    # __INLINE_CODE_35__

      sigl.Matrix

    # __INLINE_CODE_36__

      sigl.Mixin

    # __INLINE_CODE_37__

      sigl.Morph

    # __INLINE_CODE_38__

      sigl.Narrow<T, U>

    # __INLINE_CODE_39__

      sigl.NestedCSSCompiler

    # __INLINE_CODE_40__

      sigl.NestedCSSDeclaration

    # __INLINE_CODE_41__

      sigl.Off

    # __INLINE_CODE_42__

      sigl.On<T>

    # __INLINE_CODE_43__

      sigl.OnEvent<T, K>

    # __INLINE_CODE_44__

      sigl.OnGetter<T>

    # __INLINE_CODE_45__

      sigl.Placement

    # __INLINE_CODE_46__

      sigl.Point

    # __INLINE_CODE_47__

      sigl.Polygon

    # __INLINE_CODE_48__

      sigl.Polyline

    # __INLINE_CODE_49__

      sigl.Positioned

    # __INLINE_CODE_50__

      sigl.PropertyKind<T>

    # __INLINE_CODE_51__

      sigl.PropsOf<T>

    # __INLINE_CODE_52__

      sigl.QueueOptions

    # __INLINE_CODE_53__

      sigl.Reactive<T>

    # __INLINE_CODE_54__

      sigl.ReactiveClass<T>

    # __INLINE_CODE_55__

      sigl.Rect

    # __INLINE_CODE_56__

      sigl.VRef<T>

    # __INLINE_CODE_57__

      sigl.RefItem<T>

    # __INLINE_CODE_58__

      sigl.RefMap<T>

    # __INLINE_CODE_59__

      sigl.RefSet<T>

    # __INLINE_CODE_60__

      sigl.Scalar

    # __INLINE_CODE_61__

      sigl.Shape

    # __INLINE_CODE_62__

      sigl.ShapeLike

    # __INLINE_CODE_63__

      sigl.State<T, U>

    # __INLINE_CODE_64__

      sigl.StateInstance

    # __INLINE_CODE_65__

      sigl.Super<T, U>

    # __INLINE_CODE_66__

      sigl.Task

    # __INLINE_CODE_67__

      sigl.ValuesOf<T>

    # __INLINE_CODE_68__

      sigl.Vec3

# __INLINE_CODE_69__(ctor)

    # __INLINE_CODE_70__

    default<T extends  Class<T>>(ctor)  =>

      CleanClass<T>

    # __INLINE_CODE_71__

    default<T>(ctx)  =>

      ElementWrapper<T>

    # __INLINE_CODE_72__

    default<T extends  Reactive<any>>(ctx)  =>

      ReactiveWrapper<T>

Credits

Contributing

Fork or edit and submit a PR.

All contributions are welcome!

License

MIT 2022 stagas