Skip to content
/ canvy Public
generated from stagas/ts

efficient html canvas-based code text editor

License

Notifications You must be signed in to change notification settings

stagas/canvy

Repository files navigation

canvy

efficient html canvas-based code text editor

npm i canvy pnpm add canvy yarn add canvy

Examples

# basic
    # view source example/basic.ts

    import { add, sub } from 'canvy'
    
    console.log(add(1, 2)) // => 3
    console.log(sub(2, 5)) // => -3

# jsx
    # view source example/jsx.tsx

    const h = (canvy.args: unknown[]) => args
    
    console.log(<foo bar="baz" />)
    // => [ 'foo', { bar: 'baz' } ]

# web
    # view source example/web.tsx

    /** @jsxImportSource sigl */
    import $ from 'sigl'
    
    import { CanvyElement, EditorScene, File } from 'canvy'
    
    const scene = new EditorScene(document.body)
    
    const Canvy = $.element(CanvyElement)
    
    const canvy = {
      current: null as null | CanvyElement,
    }
    
    $.render(
      <Canvy
        ref={canvy}
        scene={scene}
        files={[
          new File({
            value: `\\ hello
    
    \\ world
    
    f()=sin(330);
    `,
          }),
        ]}
      />,
      document.body
    )
    
    queueMicrotask(() => {
      canvy.current!.$.effect(({ worker }) => {
        worker.postMessage({
          call: 'onmarkers',
          markers: [
            { index: 4, size: 4 },
            { index: 10, size: 3 },
          ],
        })
      })
    })

API

# CanvyElement src/editor.tsx#L130
# EditorScene src/editor-scene.ts#L6
# File src/editor.tsx#L33
# CanvyEvents src/editor.tsx#L123
# Lens src/editor.tsx#L4
# Marker src/editor.tsx#L9
# Editors  =  ... src/editor.tsx#L31

    Set<unknown>

# Canvy(props) src/editor.tsx#L757

    # props

    Canvy(props)  =>

      VKid

Credits

Contributing

Fork or edit and submit a PR.

All contributions are welcome!

License

MIT © 2023 stagas

About

efficient html canvas-based code text editor

Resources

License

Stars

Watchers

Forks

Packages

No packages published