canvy
TypeScript icon, indicating that this package has built-in type declarations

1.3.1 • Public • Published

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

# ctx

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

    ReactiveWrapper<T>
} & __module & {

# Boolean

    undefined | boolean

# Number

    undefined | number

# String

    undefined | string

}>
# _onblur  =  ... src/editor.tsx#L183

    # ()

      ()  =>

        void

# _onchange  =  ... src/editor.tsx#L236
# _onedit  =  ... src/editor.tsx#L226
# _onentermarker  =  ... src/editor.tsx#L268
# _onfocus  =  ... src/editor.tsx#L191
# _onfontsize  =  ... src/editor.tsx#L246
# _onleavemarker  =  ... src/editor.tsx#L277
# _onresize  =  ... src/editor.tsx#L205

    # (any)

      any

      (any)  =>

        void

# _onselection  =  ... src/editor.tsx#L210
# _onsnapshot  =  ... src/editor.tsx#L254

    # (snapshot)

      # snapshot

        any

      (snapshot)  =>

        void

# canvas src/editor.tsx#L137

    HTMLCanvasElement

# caret src/editor.tsx#L145

    any

# computedRect

    Rect

# context

    ContextClass<CanvyElement & JsxContext<CanvyElement> & {

    # ctor

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

      CleanClass<T>
    # ctx

    <T>(ctx)  =>

      ElementWrapper<T>
    # ctx

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

      ReactiveWrapper<T>
    } & __module & {

    # Boolean

      undefined | boolean

    # Number

      undefined | number

    # String

      undefined | string

    }>
# debug

    boolean

# dispatch

    Dispatch<

    # (name, detail, init)

      # name

        Event | Narrow<K, string>

      # detail
      # init

        CustomEventInit<any>

      <K, E>(name, detail, init)  =>

        any

>
# editor src/editor.tsx#L149

    Editor

# files  =  [] src/editor.tsx#L169
# fixed

    boolean

# focused  =  false src/editor.tsx#L135

    boolean

# focusedFile  =  ... src/editor.tsx#L170
# font src/editor.tsx#L138

    string

# fontName src/editor.tsx#L139

    string

# fontSize  =  11 src/editor.tsx#L134

    number

# host
# hoveringMarker src/editor.tsx#L266
# hoveringMarkerIndex src/editor.tsx#L265

    null | number

# initialValue src/editor.tsx#L141

    string

# isVisible  =  true src/editor.tsx#L152

    boolean

# layout

    LayoutMixin

# layoutRect

    Rect

# matrix

    Matrix

# onedit
# onentermarker
# onevent
# onleavemarker
# onmounted
# onunmounted
# padding  =  3 src/editor.tsx#L147

    number

# pixelRatio  =  window.devicePixelRatio src/editor.tsx#L151

    number

# pos

    Point

# preventUnmount

    boolean

# ready  =  false src/editor.tsx#L172

    boolean

# rect

    Rect

# replaceChunk  =  ... src/editor.tsx#L285
# scale

    number

# scene src/editor.tsx#L146
# setFromSnapshot  =  ... src/editor.tsx#L261

    # (snapshot, noScroll)

      # snapshot

        any

      # noScroll

        boolean

      (snapshot, noScroll)  =>

        void

# setLenses  =  ... src/editor.tsx#L293

    # (lenses)

      # lenses

      (lenses)  =>

        void

# setMarkers  =  ... src/editor.tsx#L289

    # (markers)

      # markers

      (markers)  =>

        void

# setReadableOnly  =  ... src/editor.tsx#L305

    # (readableOnly)

      # readableOnly

        boolean

      (readableOnly)  =>

        void

# setValue  =  ... src/editor.tsx#L297

    # (value, clearHistory, scrollToTop)

      # value

        string

      # clearHistory

        boolean

      # scrollToTop

        boolean

      (value, clearHistory, scrollToTop)  =>

        void

# singleComment  =  '//' src/editor.tsx#L143

    string

# size

    Point

# snapshot src/editor.tsx#L252

    any

# value src/editor.tsx#L154
# _ondraw() src/editor.tsx#L180

    _ondraw()  =>

      void
# _onready() src/editor.tsx#L177

    _onready()  =>

      void
# created(ctx)

    # ctx

    # ctx

    <T>(ctx)  =>

      ElementWrapper<T>
    # ctx

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

      ReactiveWrapper<T>
    } & __module & {

    # Boolean

      undefined | boolean

    # Number

      undefined | number

    # String

      undefined | string

    }>

created(ctx)  =>

    void
# handleEvent(eventName, data) src/editor.tsx#L738

    # eventName

      string

    # data

      object

    handleEvent(eventName, data)  =>

      any
# mounted($) src/editor.tsx#L309

    # $

    # ctx

    <T>(ctx)  =>

      ElementWrapper<T>
    # ctx

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

      ReactiveWrapper<T>
    } & __module & {

    # Boolean

      undefined | boolean

    # Number

      undefined | number

    # String

      undefined | string

    }>

mounted($)  =>

    void
# on(name)
# setCaret(any) src/editor.tsx#L174

    any

    setCaret(any)  =>

      void
# toJSON()
# EditorScene src/editor-scene.ts#L6

    # constructor(data) src/editor-scene.ts#L28
    # $

      Context<EditorScene & {

      # ctor

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

        CleanClass<T>

    # ctx

    <T>(ctx)  =>

      ElementWrapper<T>
    # ctx

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

      ReactiveWrapper<T>
    } & __module & {

    # Boolean

      undefined | boolean

    # Number

      undefined | number

    # String

      undefined | string

    }>
# activeEditor src/editor-scene.ts#L18
# caret src/editor-scene.ts#L12

    null

# context

    ContextClass<EditorScene & {

    # ctor

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

      CleanClass<T>
    # ctx

    <T>(ctx)  =>

      ElementWrapper<T>
    # ctx

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

      ReactiveWrapper<T>
    } & __module & {

    # Boolean

      undefined | boolean

    # Number

      undefined | number

    # String

      undefined | string

    }>
# editors  =  ... src/editor-scene.ts#L11
# fullEditor src/editor-scene.ts#L19
# ignoredElements  =  [] src/editor-scene.ts#L16

    any []

# isValidTarget src/editor-scene.ts#L14

    # (el)

      # el

        HTMLElement

      (el)  =>

        boolean

# layout src/editor-scene.ts#L21
# selectionText  =  '' src/editor-scene.ts#L10

    string

# self
# created($) src/editor-scene.ts#L32

    # $

      Context<EditorScene & {

      # ctor

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

        CleanClass<T>

    # ctx

    <T>(ctx)  =>

      ElementWrapper<T>
    # ctx

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

      ReactiveWrapper<T>
    } & __module & {

    # Boolean

      undefined | boolean

    # Number

      undefined | number

    # String

      undefined | string

    }>

created($)  =>

    void
# destroy()

    destroy()  =>

      void
# register(editor) src/editor-scene.ts#L346
# toJSON()
# File src/editor.tsx#L33
# focus() src/editor.tsx#L62

    focus()  =>

      void
# moveDown() src/editor.tsx#L109

    moveDown()  =>

# moveUp() src/editor.tsx#L96

    moveUp()  =>

# rename(newTitle) src/editor.tsx#L78

    # newTitle

      string

    rename(newTitle)  =>

      void
# setColor(color) src/editor.tsx#L66

    # color

      string

    setColor(color)  =>

      void
# setData({ id, title }) src/editor.tsx#L70

setData({ id, title })  =>

    void
# toJSON() src/editor.tsx#L47
# updateMeta() src/editor.tsx#L55

    updateMeta()  =>

      void
# CanvyEvents src/editor.tsx#L123
# event src/editor.tsx#L126
# leavemarker src/editor.tsx#L125
# 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

Package Sidebar

Install

npm i canvy

Weekly Downloads

30

Version

1.3.1

License

MIT

Unpacked Size

3.24 MB

Total Files

38

Last publish

Collaborators

  • stagas