Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@verygoodgraphics/vgg-wasm

Package Overview
Dependencies
Maintainers
0
Versions
44
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@verygoodgraphics/vgg-wasm

## Usage

  • 0.1.25
  • Source
  • npm
  • Socket score

Version published
Maintainers
0
Created
Source

VGG WASM

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.

FAQs

Package last updated on 03 Jul 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc