2.0.5 • Published 15 days ago

@xumumi/nine-patch v2.0.5

Weekly downloads
-
License
MIT
Repository
github
Last release
15 days ago

nine-patch

A simple nine-patch image reader for javascript.

Usage

Before using the nine-patch, you need to import the NinePatch class from the package. Then you must create a new instance of the NinePatch class and call the init method to load the image. After the image is loaded, you can call the draw method to draw the image on the element. Init method will return a promise, you can use the then method to do something after the image is loaded.

import NinePatch from '@xumumi/nine-patch'

const ninePatch = new NinePatch(url);
ninePatch.init().then(() => this.ninePatch.draw(element))

element: The element to draw the image on. url: The url of the nine-patch image.

if you want to get the image base64 data, you can use the following code:

import NinePatch from '@xumumi/nine-patch'

const ninePatch = new NinePatch(url);
ninePatch.init().then(() => {
  const base64 = ninePatch.getBase64(width, height);
  // do something with the base64 data
})

width: The width of the image. height: The height of the image.

You do not need to repeatedly call the init method to draw the image on multiple elements.

import NinePatch  from '@xumumi/nine-patch'
const ninePatch = new NinePatch(url);
await ninePatch.init();
ninePatch.draw(element1);
ninePatch.draw(element2);

If element size is changed, you can call the draw method to redraw the image.

function onResize() {
  ninePatch.draw(element);
}

Install

npm i @xumumi/nine-patch

CDN

<script src="https://unpkg.com/@xumumi/nine-patch/lib/nine-patch.min.js"></script>

Example

Clone the repository and run the following commands:

npm install
npm run dev

Then open the browser and visit http://localhost:5173.

Or you can visit the demo.

Reference

License

MIT

2.0.3

15 days ago

2.0.5

15 days ago

2.0.4

15 days ago

2.0.2

1 month ago

2.0.1

1 month ago

2.0.0

1 month ago

1.1.1

1 month ago

1.0.1

1 month ago

1.0.0

1 month ago