0.1.26 • Published 9 months ago

@verygoodgraphics/vgg-wasm v0.1.26

Weekly downloads
-
License
MIT
Repository
github
Last release
9 months ago

VGG WASM

Environment

Create a .env file and set the VGG runtime URL if you want to use a specific version, otherwise it will use the latest version.

# Open your terminal and goto the root directory of your project
cp /packages/wasm/.env.example /packages/wasm/.env

Usage

Import through CDN

<script src="https://www.unpkg.com/@verygoodgraphics/vgg-wasm"></script>
<script>
  const vgg = new VGG({
    src: "https://raw.githubusercontent.com/verygoodgraphics/vgg_docs/main/static/example/docs__example__vgg_homepage_v1.daruma",
    canvas: document.querySelector("#canvas"),
  })

  ;(async () => {
    await vgg.load()

    if (vgg.state === "ready") {
      await vgg.render()

      vgg.$("#vgg_home").on("click", async () => {
        window.alert("Hello, VGG!")
      })
    }
  })()
</script>

Import through NPM

npm install @verygoodgraphics/vgg-wasm
import { VGG } from "@verygoodgraphics/vgg-wasm"

const vgg = await new VGG({
  src: "https://raw.githubusercontent.com/verygoodgraphics/vgg_docs/main/static/example/docs__example__vgg_homepage_v1.daruma",
  canvas: document.querySelector("#canvas") as HTMLCanvasElement,
}).load()

if (vgg.state === State.Ready) await vgg.render()

API

Props for creating a new instance

OptionTypeRequiredDefault
canvasHTMLCanvasElement | OffscreenCanvas-
srcstring | Int8Array-
runtimestring-https://s5.vgg.cool/runtime/latest
editModeboolean-false
verboseboolean-false
disableLoaderboolean-false
customFontsstring[]-[]
onLoadEventCallback--
onLoadErrorEventCallback--
onReadyEventCallback--
onRenderedEventCallback--
onStateChangeEventCallback--
onSelectEventCallback--
onLoadingStateUpdate(state: LoadingState) => void--

VGG instance methods and properties

MethodDescriptionReturnArguments
vggInstanceKeyThe unique key of current instancestring-
stateCurrent state of the rendering processState-
loadInitialize the renderPromise<void>-
loadFontFileLoad fontsvoid(font: Uint8Array, name: string): void
onSubscribe to VGG-generated eventsVGG(type: VGGEventType, callback: EventCallback): VGG<T>
renderRender the Daruma filePromise<void>(darumaSource: string &#124; Int8Array, opts?: {width: number, height: number, editMode?: boolean}): VGG<T>
$Element selectorObservable(selector: T): Observable
destroyDestroy VGG instanceVGG-
getTextContentExtract all the text contentstring[]-
snapshotExport current frame as imageUint8Array(opts: {type: "png" &#124; "jpg" &#124; "webp", quality: number}): Uint8Array
setContentModeRender Modevoid(mode: "fig" &#124; "fill" &#124; "original" &#124; "autoFill"): void
setFitToViewportEnabledTurn on/off the breakpoint modevoid(bool: boolean): void
getAllFramesGet all the frames's dataFrame[]-
setCurrentFrameUpdate render framevoid(id: string, preserveScrollHeight: boolean): void
nextFrameRender the next framevoid-
prevFrameRender the previous framevoid-
currentFrameIdGet current frame idstring-
getFontsInUseGet the fonts used in the fileFont[]-

.load()

After loading, the state will be State.Ready or State.Error.

.render()

When the state is State.Ready, we can call this method to render the canvas.

$(selector: string)

Get the element by selector.

FAQ

  1. How to get the element selector?\ set editMode and verbose to true, then you can see the selector in the console when select specific element in the canvas.
0.1.26

9 months ago

0.1.22

12 months ago

0.1.23

12 months ago

0.1.24

12 months ago

0.1.25

11 months ago

0.1.21

1 year ago

0.1.20

1 year ago

0.1.19

1 year ago

0.1.17

1 year ago

0.1.18

1 year ago

0.1.16

1 year ago

0.1.15

1 year ago

0.1.14

1 year ago

0.1.12

1 year ago

0.1.13

1 year ago

0.1.11

1 year ago

0.1.10

1 year ago

0.1.8

1 year ago

0.1.7

1 year ago

0.1.9

1 year ago

0.1.6

1 year ago

0.1.2

1 year ago

0.1.4

1 year ago

0.1.3

1 year ago

0.1.5

1 year ago

0.1.1

1 year ago

0.1.0

1 year ago

0.0.17

1 year ago

0.0.18

1 year ago

0.0.16

1 year ago

0.0.15

1 year ago

0.0.10

1 year ago

0.0.11

1 year ago

0.0.12

1 year ago

0.0.14

1 year ago

0.0.9

1 year ago

0.0.8

1 year ago

0.0.7

1 year ago

0.0.6

1 year ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago