@mapka/shelf-pack 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,17 @@
1
+ Internet Systems Consortium license
2
+ ===================================
3
+
4
+ Copyright (c) 2017, Mapbox
5
+ Copyright (c) 2025, Mapka
6
+
7
+ Permission to use, copy, modify, and/or distribute this software for any purpose
8
+ with or without fee is hereby granted, provided that the above copyright notice
9
+ and this permission notice appear in all copies.
10
+
11
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
12
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
13
+ FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
14
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
15
+ OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
16
+ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
17
+ THIS SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,16 @@
1
+ # @mapka/shelf-pack
2
+
3
+ This is fork of [Shelf pack](https://github.com/mapbox/shelf-pack) library.
4
+
5
+ ## Usage
6
+
7
+ ```ts
8
+ import ShelfPack from '@mapka/shelf-pack';
9
+
10
+ const sprite = new ShelfPack(64, 64, { autoResize: false });
11
+ sprite.pack([
12
+ { id: 1, w: 12, h: 12 },
13
+ { id: 2, w: 12, h: 16 },
14
+ { id: 3, w: 12, h: 24 }
15
+ ]);
16
+ ```
@@ -0,0 +1 @@
1
+ {"fileNames":["../../../node_modules/typescript/lib/lib.es5.d.ts","../../../node_modules/typescript/lib/lib.es2015.d.ts","../../../node_modules/typescript/lib/lib.es2016.d.ts","../../../node_modules/typescript/lib/lib.es2017.d.ts","../../../node_modules/typescript/lib/lib.es2018.d.ts","../../../node_modules/typescript/lib/lib.es2019.d.ts","../../../node_modules/typescript/lib/lib.es2020.d.ts","../../../node_modules/typescript/lib/lib.es2021.d.ts","../../../node_modules/typescript/lib/lib.es2022.d.ts","../../../node_modules/typescript/lib/lib.es2023.d.ts","../../../node_modules/typescript/lib/lib.es2024.d.ts","../../../node_modules/typescript/lib/lib.dom.d.ts","../../../node_modules/typescript/lib/lib.dom.iterable.d.ts","../../../node_modules/typescript/lib/lib.dom.asynciterable.d.ts","../../../node_modules/typescript/lib/lib.webworker.importscripts.d.ts","../../../node_modules/typescript/lib/lib.scripthost.d.ts","../../../node_modules/typescript/lib/lib.es2015.core.d.ts","../../../node_modules/typescript/lib/lib.es2015.collection.d.ts","../../../node_modules/typescript/lib/lib.es2015.generator.d.ts","../../../node_modules/typescript/lib/lib.es2015.iterable.d.ts","../../../node_modules/typescript/lib/lib.es2015.promise.d.ts","../../../node_modules/typescript/lib/lib.es2015.proxy.d.ts","../../../node_modules/typescript/lib/lib.es2015.reflect.d.ts","../../../node_modules/typescript/lib/lib.es2015.symbol.d.ts","../../../node_modules/typescript/lib/lib.es2015.symbol.wellknown.d.ts","../../../node_modules/typescript/lib/lib.es2016.array.include.d.ts","../../../node_modules/typescript/lib/lib.es2016.intl.d.ts","../../../node_modules/typescript/lib/lib.es2017.arraybuffer.d.ts","../../../node_modules/typescript/lib/lib.es2017.date.d.ts","../../../node_modules/typescript/lib/lib.es2017.object.d.ts","../../../node_modules/typescript/lib/lib.es2017.sharedmemory.d.ts","../../../node_modules/typescript/lib/lib.es2017.string.d.ts","../../../node_modules/typescript/lib/lib.es2017.intl.d.ts","../../../node_modules/typescript/lib/lib.es2017.typedarrays.d.ts","../../../node_modules/typescript/lib/lib.es2018.asyncgenerator.d.ts","../../../node_modules/typescript/lib/lib.es2018.asynciterable.d.ts","../../../node_modules/typescript/lib/lib.es2018.intl.d.ts","../../../node_modules/typescript/lib/lib.es2018.promise.d.ts","../../../node_modules/typescript/lib/lib.es2018.regexp.d.ts","../../../node_modules/typescript/lib/lib.es2019.array.d.ts","../../../node_modules/typescript/lib/lib.es2019.object.d.ts","../../../node_modules/typescript/lib/lib.es2019.string.d.ts","../../../node_modules/typescript/lib/lib.es2019.symbol.d.ts","../../../node_modules/typescript/lib/lib.es2019.intl.d.ts","../../../node_modules/typescript/lib/lib.es2020.bigint.d.ts","../../../node_modules/typescript/lib/lib.es2020.date.d.ts","../../../node_modules/typescript/lib/lib.es2020.promise.d.ts","../../../node_modules/typescript/lib/lib.es2020.sharedmemory.d.ts","../../../node_modules/typescript/lib/lib.es2020.string.d.ts","../../../node_modules/typescript/lib/lib.es2020.symbol.wellknown.d.ts","../../../node_modules/typescript/lib/lib.es2020.intl.d.ts","../../../node_modules/typescript/lib/lib.es2020.number.d.ts","../../../node_modules/typescript/lib/lib.es2021.promise.d.ts","../../../node_modules/typescript/lib/lib.es2021.string.d.ts","../../../node_modules/typescript/lib/lib.es2021.weakref.d.ts","../../../node_modules/typescript/lib/lib.es2021.intl.d.ts","../../../node_modules/typescript/lib/lib.es2022.array.d.ts","../../../node_modules/typescript/lib/lib.es2022.error.d.ts","../../../node_modules/typescript/lib/lib.es2022.intl.d.ts","../../../node_modules/typescript/lib/lib.es2022.object.d.ts","../../../node_modules/typescript/lib/lib.es2022.string.d.ts","../../../node_modules/typescript/lib/lib.es2022.regexp.d.ts","../../../node_modules/typescript/lib/lib.es2023.array.d.ts","../../../node_modules/typescript/lib/lib.es2023.collection.d.ts","../../../node_modules/typescript/lib/lib.es2023.intl.d.ts","../../../node_modules/typescript/lib/lib.es2024.arraybuffer.d.ts","../../../node_modules/typescript/lib/lib.es2024.collection.d.ts","../../../node_modules/typescript/lib/lib.es2024.object.d.ts","../../../node_modules/typescript/lib/lib.es2024.promise.d.ts","../../../node_modules/typescript/lib/lib.es2024.regexp.d.ts","../../../node_modules/typescript/lib/lib.es2024.sharedmemory.d.ts","../../../node_modules/typescript/lib/lib.es2024.string.d.ts","../../../node_modules/typescript/lib/lib.esnext.disposable.d.ts","../../../node_modules/typescript/lib/lib.esnext.float16.d.ts","../../../node_modules/typescript/lib/lib.decorators.d.ts","../../../node_modules/typescript/lib/lib.decorators.legacy.d.ts","../../../node_modules/typescript/lib/lib.es2024.full.d.ts","../src/index.js","../../../node_modules/@vitest/pretty-format/dist/index.d.ts","../../../node_modules/@vitest/utils/dist/types.d.ts","../../../node_modules/@vitest/utils/dist/helpers.d.ts","../../../node_modules/tinyrainbow/dist/index-8b61d5bc.d.ts","../../../node_modules/tinyrainbow/dist/node.d.ts","../../../node_modules/@vitest/utils/dist/index.d.ts","../../../node_modules/@vitest/runner/dist/tasks.d-CkscK4of.d.ts","../../../node_modules/@vitest/utils/dist/types.d-BCElaP-c.d.ts","../../../node_modules/@vitest/utils/dist/diff.d.ts","../../../node_modules/@vitest/runner/dist/types.d.ts","../../../node_modules/@vitest/utils/dist/error.d.ts","../../../node_modules/@vitest/runner/dist/index.d.ts","../../../node_modules/vitest/optional-types.d.ts","../../../node_modules/vitest/dist/chunks/environment.d.cL3nLXbE.d.ts","../../../node_modules/@types/node/compatibility/iterators.d.ts","../../../node_modules/@types/node/globals.typedarray.d.ts","../../../node_modules/@types/node/buffer.buffer.d.ts","../../../node_modules/buffer/index.d.ts","../../../node_modules/undici-types/utility.d.ts","../../../node_modules/undici-types/header.d.ts","../../../node_modules/undici-types/readable.d.ts","../../../node_modules/undici-types/fetch.d.ts","../../../node_modules/undici-types/formdata.d.ts","../../../node_modules/undici-types/connector.d.ts","../../../node_modules/undici-types/client-stats.d.ts","../../../node_modules/undici-types/client.d.ts","../../../node_modules/undici-types/errors.d.ts","../../../node_modules/undici-types/dispatcher.d.ts","../../../node_modules/undici-types/global-dispatcher.d.ts","../../../node_modules/undici-types/global-origin.d.ts","../../../node_modules/undici-types/pool-stats.d.ts","../../../node_modules/undici-types/pool.d.ts","../../../node_modules/undici-types/handlers.d.ts","../../../node_modules/undici-types/balanced-pool.d.ts","../../../node_modules/undici-types/h2c-client.d.ts","../../../node_modules/undici-types/agent.d.ts","../../../node_modules/undici-types/mock-interceptor.d.ts","../../../node_modules/undici-types/mock-call-history.d.ts","../../../node_modules/undici-types/mock-agent.d.ts","../../../node_modules/undici-types/mock-client.d.ts","../../../node_modules/undici-types/mock-pool.d.ts","../../../node_modules/undici-types/mock-errors.d.ts","../../../node_modules/undici-types/proxy-agent.d.ts","../../../node_modules/undici-types/env-http-proxy-agent.d.ts","../../../node_modules/undici-types/retry-handler.d.ts","../../../node_modules/undici-types/retry-agent.d.ts","../../../node_modules/undici-types/api.d.ts","../../../node_modules/undici-types/cache-interceptor.d.ts","../../../node_modules/undici-types/interceptors.d.ts","../../../node_modules/undici-types/util.d.ts","../../../node_modules/undici-types/cookies.d.ts","../../../node_modules/undici-types/patch.d.ts","../../../node_modules/undici-types/websocket.d.ts","../../../node_modules/undici-types/eventsource.d.ts","../../../node_modules/undici-types/diagnostics-channel.d.ts","../../../node_modules/undici-types/content-type.d.ts","../../../node_modules/undici-types/cache.d.ts","../../../node_modules/undici-types/index.d.ts","../../../node_modules/@types/node/globals.d.ts","../../../node_modules/@types/node/assert.d.ts","../../../node_modules/@types/node/assert/strict.d.ts","../../../node_modules/@types/node/async_hooks.d.ts","../../../node_modules/@types/node/buffer.d.ts","../../../node_modules/@types/node/child_process.d.ts","../../../node_modules/@types/node/cluster.d.ts","../../../node_modules/@types/node/console.d.ts","../../../node_modules/@types/node/constants.d.ts","../../../node_modules/@types/node/crypto.d.ts","../../../node_modules/@types/node/dgram.d.ts","../../../node_modules/@types/node/diagnostics_channel.d.ts","../../../node_modules/@types/node/dns.d.ts","../../../node_modules/@types/node/dns/promises.d.ts","../../../node_modules/@types/node/domain.d.ts","../../../node_modules/@types/node/dom-events.d.ts","../../../node_modules/@types/node/events.d.ts","../../../node_modules/@types/node/fs.d.ts","../../../node_modules/@types/node/fs/promises.d.ts","../../../node_modules/@types/node/http.d.ts","../../../node_modules/@types/node/http2.d.ts","../../../node_modules/@types/node/https.d.ts","../../../node_modules/@types/node/inspector.d.ts","../../../node_modules/@types/node/module.d.ts","../../../node_modules/@types/node/net.d.ts","../../../node_modules/@types/node/os.d.ts","../../../node_modules/@types/node/path.d.ts","../../../node_modules/@types/node/perf_hooks.d.ts","../../../node_modules/@types/node/process.d.ts","../../../node_modules/@types/node/punycode.d.ts","../../../node_modules/@types/node/querystring.d.ts","../../../node_modules/@types/node/readline.d.ts","../../../node_modules/@types/node/readline/promises.d.ts","../../../node_modules/@types/node/repl.d.ts","../../../node_modules/@types/node/sea.d.ts","../../../node_modules/@types/node/sqlite.d.ts","../../../node_modules/@types/node/stream.d.ts","../../../node_modules/@types/node/stream/promises.d.ts","../../../node_modules/@types/node/stream/consumers.d.ts","../../../node_modules/@types/node/stream/web.d.ts","../../../node_modules/@types/node/string_decoder.d.ts","../../../node_modules/@types/node/test.d.ts","../../../node_modules/@types/node/timers.d.ts","../../../node_modules/@types/node/timers/promises.d.ts","../../../node_modules/@types/node/tls.d.ts","../../../node_modules/@types/node/trace_events.d.ts","../../../node_modules/@types/node/tty.d.ts","../../../node_modules/@types/node/url.d.ts","../../../node_modules/@types/node/util.d.ts","../../../node_modules/@types/node/v8.d.ts","../../../node_modules/@types/node/vm.d.ts","../../../node_modules/@types/node/wasi.d.ts","../../../node_modules/@types/node/worker_threads.d.ts","../../../node_modules/@types/node/zlib.d.ts","../../../node_modules/@types/node/index.d.ts","../../../node_modules/vite/types/hmrPayload.d.ts","../../../node_modules/vite/dist/node/moduleRunnerTransport-BWUZBVLX.d.ts","../../../node_modules/vite/types/customEvent.d.ts","../../../node_modules/@types/estree/index.d.ts","../../../node_modules/rollup/dist/rollup.d.ts","../../../node_modules/rollup/dist/parseAst.d.ts","../../../node_modules/vite/types/hot.d.ts","../../../node_modules/vite/dist/node/module-runner.d.ts","../../../node_modules/esbuild/lib/main.d.ts","../../../node_modules/vite/types/internal/terserOptions.d.ts","../../../node_modules/source-map-js/source-map.d.ts","../../../node_modules/postcss/lib/previous-map.d.ts","../../../node_modules/postcss/lib/input.d.ts","../../../node_modules/postcss/lib/css-syntax-error.d.ts","../../../node_modules/postcss/lib/declaration.d.ts","../../../node_modules/postcss/lib/root.d.ts","../../../node_modules/postcss/lib/warning.d.ts","../../../node_modules/postcss/lib/lazy-result.d.ts","../../../node_modules/postcss/lib/no-work-result.d.ts","../../../node_modules/postcss/lib/processor.d.ts","../../../node_modules/postcss/lib/result.d.ts","../../../node_modules/postcss/lib/document.d.ts","../../../node_modules/postcss/lib/rule.d.ts","../../../node_modules/postcss/lib/node.d.ts","../../../node_modules/postcss/lib/comment.d.ts","../../../node_modules/postcss/lib/container.d.ts","../../../node_modules/postcss/lib/at-rule.d.ts","../../../node_modules/postcss/lib/list.d.ts","../../../node_modules/postcss/lib/postcss.d.ts","../../../node_modules/postcss/lib/postcss.d.mts","../../../node_modules/vite/types/internal/lightningcssOptions.d.ts","../../../node_modules/vite/types/internal/cssPreprocessorOptions.d.ts","../../../node_modules/vite/types/importGlob.d.ts","../../../node_modules/vite/types/metadata.d.ts","../../../node_modules/vite/dist/node/index.d.ts","../../../node_modules/@vitest/mocker/dist/registry.d-D765pazg.d.ts","../../../node_modules/@vitest/mocker/dist/types.d-D_aRZRdy.d.ts","../../../node_modules/@vitest/mocker/dist/index.d.ts","../../../node_modules/@vitest/utils/dist/source-map.d.ts","../../../node_modules/vite-node/dist/trace-mapping.d-DLVdEqOp.d.ts","../../../node_modules/vite-node/dist/index.d-DGmxD2U7.d.ts","../../../node_modules/vite-node/dist/index.d.ts","../../../node_modules/@vitest/snapshot/dist/environment.d-DHdQ1Csl.d.ts","../../../node_modules/@vitest/snapshot/dist/rawSnapshot.d-lFsMJFUd.d.ts","../../../node_modules/@vitest/snapshot/dist/index.d.ts","../../../node_modules/@vitest/snapshot/dist/environment.d.ts","../../../node_modules/vitest/dist/chunks/config.d.D2ROskhv.d.ts","../../../node_modules/vitest/dist/chunks/worker.d.1GmBbd7G.d.ts","../../../node_modules/@types/deep-eql/index.d.ts","../../../node_modules/@types/chai/index.d.ts","../../../node_modules/@vitest/runner/dist/utils.d.ts","../../../node_modules/tinybench/dist/index.d.ts","../../../node_modules/vitest/dist/chunks/benchmark.d.BwvBVTda.d.ts","../../../node_modules/vite-node/dist/client.d.ts","../../../node_modules/vitest/dist/chunks/coverage.d.S9RMNXIe.d.ts","../../../node_modules/@vitest/snapshot/dist/manager.d.ts","../../../node_modules/vitest/dist/chunks/reporters.d.BFLkQcL6.d.ts","../../../node_modules/vitest/dist/chunks/worker.d.CKwWzBSj.d.ts","../../../node_modules/@vitest/spy/dist/index.d.ts","../../../node_modules/@vitest/expect/dist/index.d.ts","../../../node_modules/vitest/dist/chunks/global.d.MAmajcmJ.d.ts","../../../node_modules/vitest/dist/chunks/vite.d.CMLlLIFP.d.ts","../../../node_modules/vitest/dist/chunks/mocker.d.BE_2ls6u.d.ts","../../../node_modules/vitest/dist/chunks/suite.d.FvehnV49.d.ts","../../../node_modules/expect-type/dist/utils.d.ts","../../../node_modules/expect-type/dist/overloads.d.ts","../../../node_modules/expect-type/dist/branding.d.ts","../../../node_modules/expect-type/dist/messages.d.ts","../../../node_modules/expect-type/dist/index.d.ts","../../../node_modules/vitest/dist/index.d.ts","../src/__tests__/index.test.ts","../../../node_modules/@types/conventional-commits-parser/index.d.ts","../../../node_modules/minimatch/dist/commonjs/ast.d.ts","../../../node_modules/minimatch/dist/commonjs/escape.d.ts","../../../node_modules/minimatch/dist/commonjs/unescape.d.ts","../../../node_modules/minimatch/dist/commonjs/index.d.ts","../../../node_modules/@types/glob/index.d.ts","../../../node_modules/@types/mapbox__spritezero/index.d.ts","../../../node_modules/@types/minimatch/index.d.ts","../../../node_modules/@types/normalize-package-data/index.d.ts","../../../node_modules/@types/parse-path/index.d.ts"],"fileIdsList":[[95,141,240],[95,141,173,191],[95,141],[95,141,153,154,191,267],[95,138,141],[95,140,141],[141],[95,141,146,176],[95,141,142,147,153,154,161,173,184],[95,141,142,143,153,161],[95,141,144,185],[95,141,145,146,154,162],[95,141,146,173,181],[95,141,147,149,153,161],[95,140,141,148],[95,141,149,150],[95,141,151,153],[95,140,141,153],[95,141,153,154,155,173,184],[95,141,153,154,155,168,173,176],[95,136,141],[95,136,141,149,153,156,161,173,184],[95,141,153,154,156,157,161,173,181,184],[95,141,156,158,173,181,184],[93,94,95,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,183,184,185,186,187,188,189,190],[95,141,153,159],[95,141,160,184],[95,141,149,153,161,173],[95,141,162],[95,141,163],[95,140,141,164],[95,138,139,140,141,142,143,144,145,146,147,148,149,150,151,153,154,155,156,157,158,159,160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,183,184,185,186,187,188,189,190],[95,141,166],[95,141,167],[95,141,153,168,169],[95,141,168,170,185,187],[95,141,153,173,174,176],[95,141,175,176],[95,141,173,174],[95,141,176],[95,141,177],[95,138,141,173,178],[95,141,153,179,180],[95,141,179,180],[95,141,146,161,173,181],[95,141,182],[95,141,161,183],[95,141,156,167,184],[95,141,146,185],[95,141,173,186],[95,141,160,187],[95,141,188],[95,141,153,155,164,173,176,184,186,187,189],[95,141,173,190],[83,84,87,95,141,250],[95,141,227,228],[84,85,87,88,89,95,141],[84,95,141],[84,85,87,95,141],[84,85,95,141],[95,141,234],[79,95,141,234,235],[79,95,141,234],[79,86,95,141],[80,95,141],[79,80,81,83,95,141],[79,95,141],[95,141,256,257],[95,141,256,257,258,259],[95,141,256,258],[95,141,256],[95,141,267],[95,141,264,265,266],[95,141,217],[95,141,215,217],[95,141,206,214,215,216,218,220],[95,141,204],[95,141,207,212,217,220],[95,141,203,220],[95,141,207,208,211,212,213,220],[95,141,207,208,209,211,212,220],[95,141,204,205,206,207,208,212,213,214,216,217,218,220],[95,141,220],[95,141,202,204,205,206,207,208,209,211,212,213,214,215,216,217,218,219],[95,141,202,220],[95,141,207,209,210,212,213,220],[95,141,211,220],[95,141,212,213,217,220],[95,141,205,215],[95,141,196,225,226],[95,141,195,196],[82,95,141],[95,103,106,109,110,141,184],[95,106,141,173,184],[95,106,110,141,184],[95,141,173],[95,100,141],[95,104,141],[95,102,103,106,141,184],[95,141,161,181],[95,141,191],[95,100,141,191],[95,102,106,141,161,184],[95,97,98,99,101,105,141,153,173,184],[95,106,114,141],[95,98,104,141],[95,106,130,131,141],[95,98,101,106,141,176,184,191],[95,106,141],[95,102,106,141,184],[95,97,141],[95,100,101,102,104,105,106,107,108,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,131,132,133,134,135,141],[95,106,123,126,141,149],[95,106,114,115,116,141],[95,104,106,115,117,141],[95,105,141],[95,98,100,106,141],[95,106,110,115,117,141],[95,110,141],[95,104,106,109,141,184],[95,98,102,106,114,141],[95,106,123,141],[95,100,106,130,141,176,189,191],[95,141,231,232],[95,141,231],[95,141,153,154,156,157,158,161,173,181,184,190,191,192,193,194,196,197,199,200,201,221,222,223,224,225,226],[95,141,192,193,194,198],[95,141,192],[95,141,194],[95,141,196,226],[90,95,141,242,243,252],[79,87,90,95,141,236,237,252],[95,141,245],[91,95,141],[79,90,92,95,141,236,244,251,252],[95,141,229],[79,84,87,90,92,95,141,144,154,173,226,229,230,233,236,238,239,241,244,246,247,252,253],[90,95,141,242,243,244,252],[95,141,226,248,253],[90,92,95,141,233,236,238,252],[95,141,189,239],[79,84,87,90,91,92,95,141,144,154,173,189,226,229,230,233,236,237,238,239,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255,260],[78,95,141,261]],"fileInfos":[{"version":"c430d44666289dae81f30fa7b2edebf186ecc91a2d4c71266ea6ae76388792e1","affectsGlobalScope":true,"impliedFormat":1},{"version":"45b7ab580deca34ae9729e97c13cfd999df04416a79116c3bfb483804f85ded4","impliedFormat":1},{"version":"3facaf05f0c5fc569c5649dd359892c98a85557e3e0c847964caeb67076f4d75","impliedFormat":1},{"version":"e44bb8bbac7f10ecc786703fe0a6a4b952189f908707980ba8f3c8975a760962","impliedFormat":1},{"version":"5e1c4c362065a6b95ff952c0eab010f04dcd2c3494e813b493ecfd4fcb9fc0d8","impliedFormat":1},{"version":"68d73b4a11549f9c0b7d352d10e91e5dca8faa3322bfb77b661839c42b1ddec7","impliedFormat":1},{"version":"5efce4fc3c29ea84e8928f97adec086e3dc876365e0982cc8479a07954a3efd4","impliedFormat":1},{"version":"feecb1be483ed332fad555aff858affd90a48ab19ba7272ee084704eb7167569","impliedFormat":1},{"version":"ee7bad0c15b58988daa84371e0b89d313b762ab83cb5b31b8a2d1162e8eb41c2","impliedFormat":1},{"version":"27bdc30a0e32783366a5abeda841bc22757c1797de8681bbe81fbc735eeb1c10","impliedFormat":1},{"version":"8fd575e12870e9944c7e1d62e1f5a73fcf23dd8d3a321f2a2c74c20d022283fe","impliedFormat":1},{"version":"080941d9f9ff9307f7e27a83bcd888b7c8270716c39af943532438932ec1d0b9","affectsGlobalScope":true,"impliedFormat":1},{"version":"2e80ee7a49e8ac312cc11b77f1475804bee36b3b2bc896bead8b6e1266befb43","affectsGlobalScope":true,"impliedFormat":1},{"version":"d7a3c8b952931daebdfc7a2897c53c0a1c73624593fa070e46bd537e64dcd20a","affectsGlobalScope":true,"impliedFormat":1},{"version":"80e18897e5884b6723488d4f5652167e7bb5024f946743134ecc4aa4ee731f89","affectsGlobalScope":true,"impliedFormat":1},{"version":"cd034f499c6cdca722b60c04b5b1b78e058487a7085a8e0d6fb50809947ee573","affectsGlobalScope":true,"impliedFormat":1},{"version":"c57796738e7f83dbc4b8e65132f11a377649c00dd3eee333f672b8f0a6bea671","affectsGlobalScope":true,"impliedFormat":1},{"version":"dc2df20b1bcdc8c2d34af4926e2c3ab15ffe1160a63e58b7e09833f616efff44","affectsGlobalScope":true,"impliedFormat":1},{"version":"515d0b7b9bea2e31ea4ec968e9edd2c39d3eebf4a2d5cbd04e88639819ae3b71","affectsGlobalScope":true,"impliedFormat":1},{"version":"0559b1f683ac7505ae451f9a96ce4c3c92bdc71411651ca6ddb0e88baaaad6a3","affectsGlobalScope":true,"impliedFormat":1},{"version":"0dc1e7ceda9b8b9b455c3a2d67b0412feab00bd2f66656cd8850e8831b08b537","affectsGlobalScope":true,"impliedFormat":1},{"version":"ce691fb9e5c64efb9547083e4a34091bcbe5bdb41027e310ebba8f7d96a98671","affectsGlobalScope":true,"impliedFormat":1},{"version":"8d697a2a929a5fcb38b7a65594020fcef05ec1630804a33748829c5ff53640d0","affectsGlobalScope":true,"impliedFormat":1},{"version":"4ff2a353abf8a80ee399af572debb8faab2d33ad38c4b4474cff7f26e7653b8d","affectsGlobalScope":true,"impliedFormat":1},{"version":"fb0f136d372979348d59b3f5020b4cdb81b5504192b1cacff5d1fbba29378aa1","affectsGlobalScope":true,"impliedFormat":1},{"version":"d15bea3d62cbbdb9797079416b8ac375ae99162a7fba5de2c6c505446486ac0a","affectsGlobalScope":true,"impliedFormat":1},{"version":"68d18b664c9d32a7336a70235958b8997ebc1c3b8505f4f1ae2b7e7753b87618","affectsGlobalScope":true,"impliedFormat":1},{"version":"eb3d66c8327153d8fa7dd03f9c58d351107fe824c79e9b56b462935176cdf12a","affectsGlobalScope":true,"impliedFormat":1},{"version":"38f0219c9e23c915ef9790ab1d680440d95419ad264816fa15009a8851e79119","affectsGlobalScope":true,"impliedFormat":1},{"version":"69ab18c3b76cd9b1be3d188eaf8bba06112ebbe2f47f6c322b5105a6fbc45a2e","affectsGlobalScope":true,"impliedFormat":1},{"version":"a680117f487a4d2f30ea46f1b4b7f58bef1480456e18ba53ee85c2746eeca012","affectsGlobalScope":true,"impliedFormat":1},{"version":"2f11ff796926e0832f9ae148008138ad583bd181899ab7dd768a2666700b1893","affectsGlobalScope":true,"impliedFormat":1},{"version":"4de680d5bb41c17f7f68e0419412ca23c98d5749dcaaea1896172f06435891fc","affectsGlobalScope":true,"impliedFormat":1},{"version":"954296b30da6d508a104a3a0b5d96b76495c709785c1d11610908e63481ee667","affectsGlobalScope":true,"impliedFormat":1},{"version":"ac9538681b19688c8eae65811b329d3744af679e0bdfa5d842d0e32524c73e1c","affectsGlobalScope":true,"impliedFormat":1},{"version":"0a969edff4bd52585473d24995c5ef223f6652d6ef46193309b3921d65dd4376","affectsGlobalScope":true,"impliedFormat":1},{"version":"9e9fbd7030c440b33d021da145d3232984c8bb7916f277e8ffd3dc2e3eae2bdb","affectsGlobalScope":true,"impliedFormat":1},{"version":"811ec78f7fefcabbda4bfa93b3eb67d9ae166ef95f9bff989d964061cbf81a0c","affectsGlobalScope":true,"impliedFormat":1},{"version":"717937616a17072082152a2ef351cb51f98802fb4b2fdabd32399843875974ca","affectsGlobalScope":true,"impliedFormat":1},{"version":"d7e7d9b7b50e5f22c915b525acc5a49a7a6584cf8f62d0569e557c5cfc4b2ac2","affectsGlobalScope":true,"impliedFormat":1},{"version":"71c37f4c9543f31dfced6c7840e068c5a5aacb7b89111a4364b1d5276b852557","affectsGlobalScope":true,"impliedFormat":1},{"version":"576711e016cf4f1804676043e6a0a5414252560eb57de9faceee34d79798c850","affectsGlobalScope":true,"impliedFormat":1},{"version":"89c1b1281ba7b8a96efc676b11b264de7a8374c5ea1e6617f11880a13fc56dc6","affectsGlobalScope":true,"impliedFormat":1},{"version":"74f7fa2d027d5b33eb0471c8e82a6c87216223181ec31247c357a3e8e2fddc5b","affectsGlobalScope":true,"impliedFormat":1},{"version":"d6d7ae4d1f1f3772e2a3cde568ed08991a8ae34a080ff1151af28b7f798e22ca","affectsGlobalScope":true,"impliedFormat":1},{"version":"063600664504610fe3e99b717a1223f8b1900087fab0b4cad1496a114744f8df","affectsGlobalScope":true,"impliedFormat":1},{"version":"934019d7e3c81950f9a8426d093458b65d5aff2c7c1511233c0fd5b941e608ab","affectsGlobalScope":true,"impliedFormat":1},{"version":"52ada8e0b6e0482b728070b7639ee42e83a9b1c22d205992756fe020fd9f4a47","affectsGlobalScope":true,"impliedFormat":1},{"version":"3bdefe1bfd4d6dee0e26f928f93ccc128f1b64d5d501ff4a8cf3c6371200e5e6","affectsGlobalScope":true,"impliedFormat":1},{"version":"59fb2c069260b4ba00b5643b907ef5d5341b167e7d1dbf58dfd895658bda2867","affectsGlobalScope":true,"impliedFormat":1},{"version":"639e512c0dfc3fad96a84caad71b8834d66329a1f28dc95e3946c9b58176c73a","affectsGlobalScope":true,"impliedFormat":1},{"version":"368af93f74c9c932edd84c58883e736c9e3d53cec1fe24c0b0ff451f529ceab1","affectsGlobalScope":true,"impliedFormat":1},{"version":"af3dd424cf267428f30ccfc376f47a2c0114546b55c44d8c0f1d57d841e28d74","affectsGlobalScope":true,"impliedFormat":1},{"version":"995c005ab91a498455ea8dfb63aa9f83fa2ea793c3d8aa344be4a1678d06d399","affectsGlobalScope":true,"impliedFormat":1},{"version":"959d36cddf5e7d572a65045b876f2956c973a586da58e5d26cde519184fd9b8a","affectsGlobalScope":true,"impliedFormat":1},{"version":"965f36eae237dd74e6cca203a43e9ca801ce38824ead814728a2807b1910117d","affectsGlobalScope":true,"impliedFormat":1},{"version":"3925a6c820dcb1a06506c90b1577db1fdbf7705d65b62b99dce4be75c637e26b","affectsGlobalScope":true,"impliedFormat":1},{"version":"0a3d63ef2b853447ec4f749d3f368ce642264246e02911fcb1590d8c161b8005","affectsGlobalScope":true,"impliedFormat":1},{"version":"8cdf8847677ac7d20486e54dd3fcf09eda95812ac8ace44b4418da1bbbab6eb8","affectsGlobalScope":true,"impliedFormat":1},{"version":"8444af78980e3b20b49324f4a16ba35024fef3ee069a0eb67616ea6ca821c47a","affectsGlobalScope":true,"impliedFormat":1},{"version":"3287d9d085fbd618c3971944b65b4be57859f5415f495b33a6adc994edd2f004","affectsGlobalScope":true,"impliedFormat":1},{"version":"b4b67b1a91182421f5df999988c690f14d813b9850b40acd06ed44691f6727ad","affectsGlobalScope":true,"impliedFormat":1},{"version":"df83c2a6c73228b625b0beb6669c7ee2a09c914637e2d35170723ad49c0f5cd4","affectsGlobalScope":true,"impliedFormat":1},{"version":"436aaf437562f276ec2ddbee2f2cdedac7664c1e4c1d2c36839ddd582eeb3d0a","affectsGlobalScope":true,"impliedFormat":1},{"version":"8e3c06ea092138bf9fa5e874a1fdbc9d54805d074bee1de31b99a11e2fec239d","affectsGlobalScope":true,"impliedFormat":1},{"version":"87dc0f382502f5bbce5129bdc0aea21e19a3abbc19259e0b43ae038a9fc4e326","affectsGlobalScope":true,"impliedFormat":1},{"version":"b1cb28af0c891c8c96b2d6b7be76bd394fddcfdb4709a20ba05a7c1605eea0f9","affectsGlobalScope":true,"impliedFormat":1},{"version":"2fef54945a13095fdb9b84f705f2b5994597640c46afeb2ce78352fab4cb3279","affectsGlobalScope":true,"impliedFormat":1},{"version":"ac77cb3e8c6d3565793eb90a8373ee8033146315a3dbead3bde8db5eaf5e5ec6","affectsGlobalScope":true,"impliedFormat":1},{"version":"56e4ed5aab5f5920980066a9409bfaf53e6d21d3f8d020c17e4de584d29600ad","affectsGlobalScope":true,"impliedFormat":1},{"version":"4ece9f17b3866cc077099c73f4983bddbcb1dc7ddb943227f1ec070f529dedd1","affectsGlobalScope":true,"impliedFormat":1},{"version":"0a6282c8827e4b9a95f4bf4f5c205673ada31b982f50572d27103df8ceb8013c","affectsGlobalScope":true,"impliedFormat":1},{"version":"51ad4c928303041605b4d7ae32e0c1ee387d43a24cd6f1ebf4a2699e1076d4fa","affectsGlobalScope":true,"impliedFormat":1},{"version":"4245fee526a7d1754529d19227ecbf3be066ff79ebb6a380d78e41648f2f224d","affectsGlobalScope":true,"impliedFormat":1},{"version":"8e7f8264d0fb4c5339605a15daadb037bf238c10b654bb3eee14208f860a32ea","affectsGlobalScope":true,"impliedFormat":1},{"version":"782dec38049b92d4e85c1585fbea5474a219c6984a35b004963b00beb1aab538","affectsGlobalScope":true,"impliedFormat":1},{"version":"b3e9cef4eed59f8a2249ed834ba4aabe9d0d4e9037d4679487fa17dad99004a3","impliedFormat":1},{"version":"fb7a32a1568d16a7fbf384c56e36b1b351bc78fbaf18295c12a37593e565f939","signature":"9404729fdcff80506c5de70ac1eb5ea4bdf6b9b46867481b419773246601d1bd","impliedFormat":99},{"version":"5c54a34e3d91727f7ae840bfe4d5d1c9a2f93c54cb7b6063d06ee4a6c3322656","impliedFormat":99},{"version":"db4da53b03596668cf6cc9484834e5de3833b9e7e64620cf08399fe069cd398d","impliedFormat":99},{"version":"ac7c28f153820c10850457994db1462d8c8e462f253b828ad942a979f726f2f9","impliedFormat":99},{"version":"f9b028d3c3891dd817e24d53102132b8f696269309605e6ed4f0db2c113bbd82","impliedFormat":99},{"version":"fb7c8d90e52e2884509166f96f3d591020c7b7977ab473b746954b0c8d100960","impliedFormat":99},{"version":"0bff51d6ed0c9093f6955b9d8258ce152ddb273359d50a897d8baabcb34de2c4","impliedFormat":99},{"version":"45cec9a1ba6549060552eead8959d47226048e0b71c7d0702ae58b7e16a28912","impliedFormat":99},{"version":"ef13c73d6157a32933c612d476c1524dd674cf5b9a88571d7d6a0d147544d529","impliedFormat":99},{"version":"13918e2b81c4288695f9b1f3dcc2468caf0f848d5c1f3dc00071c619d34ff63a","impliedFormat":99},{"version":"6907b09850f86610e7a528348c15484c1e1c09a18a9c1e98861399dfe4b18b46","impliedFormat":99},{"version":"12deea8eaa7a4fc1a2908e67da99831e5c5a6b46ad4f4f948fd4759314ea2b80","impliedFormat":99},{"version":"f0a8b376568a18f9a4976ecb0855187672b16b96c4df1c183a7e52dc1b5d98e8","impliedFormat":99},{"version":"8124828a11be7db984fcdab052fd4ff756b18edcfa8d71118b55388176210923","impliedFormat":99},{"version":"092944a8c05f9b96579161e88c6f211d5304a76bd2c47f8d4c30053269146bc8","impliedFormat":99},{"version":"d153a11543fd884b596587ccd97aebbeed950b26933ee000f94009f1ab142848","affectsGlobalScope":true,"impliedFormat":1},{"version":"c0671b50bb99cc7ad46e9c68fa0e7f15ba4bc898b59c31a17ea4611fab5095da","affectsGlobalScope":true,"impliedFormat":1},{"version":"d802f0e6b5188646d307f070d83512e8eb94651858de8a82d1e47f60fb6da4e2","affectsGlobalScope":true,"impliedFormat":1},{"version":"8e9c23ba78aabc2e0a27033f18737a6df754067731e69dc5f52823957d60a4b6","impliedFormat":1},{"version":"cdcf9ea426ad970f96ac930cd176d5c69c6c24eebd9fc580e1572d6c6a88f62c","impliedFormat":1},{"version":"23cd712e2ce083d68afe69224587438e5914b457b8acf87073c22494d706a3d0","impliedFormat":1},{"version":"487b694c3de27ddf4ad107d4007ad304d29effccf9800c8ae23c2093638d906a","impliedFormat":1},{"version":"e525f9e67f5ddba7b5548430211cae2479070b70ef1fd93550c96c10529457bd","impliedFormat":1},{"version":"ccf4552357ce3c159ef75f0f0114e80401702228f1898bdc9402214c9499e8c0","impliedFormat":1},{"version":"c6fd2c5a395f2432786c9cb8deb870b9b0e8ff7e22c029954fabdd692bff6195","impliedFormat":1},{"version":"68834d631c8838c715f225509cfc3927913b9cc7a4870460b5b60c8dbdb99baf","impliedFormat":1},{"version":"4bc0794175abedf989547e628949888c1085b1efcd93fc482bccd77ee27f8b7c","impliedFormat":1},{"version":"3c8e93af4d6ce21eb4c8d005ad6dc02e7b5e6781f429d52a35290210f495a674","impliedFormat":1},{"version":"2c9875466123715464539bfd69bcaccb8ff6f3e217809428e0d7bd6323416d01","impliedFormat":1},{"version":"ea6bc8de8b59f90a7a3960005fd01988f98fd0784e14bc6922dde2e93305ec7d","impliedFormat":1},{"version":"36107995674b29284a115e21a0618c4c2751b32a8766dd4cb3ba740308b16d59","impliedFormat":1},{"version":"914a0ae30d96d71915fc519ccb4efbf2b62c0ddfb3a3fc6129151076bc01dc60","impliedFormat":1},{"version":"33e981bf6376e939f99bd7f89abec757c64897d33c005036b9a10d9587d80187","impliedFormat":1},{"version":"6c8e442ba33b07892169a14f7757321e49ab0f1032d676d321a1fdab8a67d40c","impliedFormat":1},{"version":"b41767d372275c154c7ea6c9d5449d9a741b8ce080f640155cc88ba1763e35b3","impliedFormat":1},{"version":"1cd673d367293fc5cb31cd7bf03d598eb368e4f31f39cf2b908abbaf120ab85a","impliedFormat":1},{"version":"af13e99445f37022c730bfcafcdc1761e9382ce1ea02afb678e3130b01ce5676","impliedFormat":1},{"version":"3825bf209f1662dfd039010a27747b73d0ef379f79970b1d05601ec8e8a4249f","impliedFormat":1},{"version":"0b6e25234b4eec6ed96ab138d96eb70b135690d7dd01f3dd8a8ab291c35a683a","impliedFormat":1},{"version":"9666f2f84b985b62400d2e5ab0adae9ff44de9b2a34803c2c5bd3c8325b17dc0","impliedFormat":1},{"version":"da52342062e70c77213e45107921100ba9f9b3a30dd019444cf349e5fb3470c4","impliedFormat":1},{"version":"e9ace91946385d29192766bf783b8460c7dbcbfc63284aa3c9cae6de5155c8bc","impliedFormat":1},{"version":"40b463c6766ca1b689bfcc46d26b5e295954f32ad43e37ee6953c0a677e4ae2b","impliedFormat":1},{"version":"249b9cab7f5d628b71308c7d9bb0a808b50b091e640ba3ed6e2d0516f4a8d91d","impliedFormat":1},{"version":"1e30c045732e7db8f7a82cf90b516ebe693d2f499ce2250a977ec0d12e44a529","impliedFormat":1},{"version":"84b736594d8760f43400202859cda55607663090a43445a078963031d47e25e7","impliedFormat":1},{"version":"499e5b055a5aba1e1998f7311a6c441a369831c70905cc565ceac93c28083d53","impliedFormat":1},{"version":"54c3e2371e3d016469ad959697fd257e5621e16296fa67082c2575d0bf8eced0","impliedFormat":1},{"version":"beb8233b2c220cfa0feea31fbe9218d89fa02faa81ef744be8dce5acb89bb1fd","impliedFormat":1},{"version":"78b29846349d4dfdd88bd6650cc5d2baaa67f2e89dc8a80c8e26ef7995386583","impliedFormat":1},{"version":"5d0375ca7310efb77e3ef18d068d53784faf62705e0ad04569597ae0e755c401","impliedFormat":1},{"version":"59af37caec41ecf7b2e76059c9672a49e682c1a2aa6f9d7dc78878f53aa284d6","impliedFormat":1},{"version":"addf417b9eb3f938fddf8d81e96393a165e4be0d4a8b6402292f9c634b1cb00d","impliedFormat":1},{"version":"e38d4fdf79e1eadd92ed7844c331dbaa40f29f21541cfee4e1acff4db09cda33","impliedFormat":1},{"version":"8bd86b8e8f6a6aa6c49b71e14c4ffe1211a0e97c80f08d2c8cc98838006e4b88","impliedFormat":1},{"version":"7c10a32ae6f3962672e6869ee2c794e8055d8225ef35c91c0228e354b4e5d2d3","impliedFormat":1},{"version":"2e85db9e6fd73cfa3d7f28e0ab6b55417ea18931423bd47b409a96e4a169e8e6","impliedFormat":1},{"version":"c46e079fe54c76f95c67fb89081b3e399da2c7d109e7dca8e4b58d83e332e605","impliedFormat":1},{"version":"99f569b42ea7e7c5fe404b2848c0893f3e1a56e0547c1cd0f74d5dbb9a9de27e","impliedFormat":1},{"version":"f4b4faedc57701ae727d78ba4a83e466a6e3bdcbe40efbf913b17e860642897c","affectsGlobalScope":true,"impliedFormat":1},{"version":"bbcfd9cd76d92c3ee70475270156755346c9086391e1b9cb643d072e0cf576b8","impliedFormat":1},{"version":"7394959e5a741b185456e1ef5d64599c36c60a323207450991e7a42e08911419","impliedFormat":1},{"version":"72c1f5e0a28e473026074817561d1bc9647909cf253c8d56c41d1df8d95b85f7","impliedFormat":1},{"version":"003ec918ec442c3a4db2c36dc0c9c766977ea1c8bcc1ca7c2085868727c3d3f6","affectsGlobalScope":true,"impliedFormat":1},{"version":"938f94db8400d0b479626b9006245a833d50ce8337f391085fad4af540279567","impliedFormat":1},{"version":"c4e8e8031808b158cfb5ac5c4b38d4a26659aec4b57b6a7e2ba0a141439c208c","impliedFormat":1},{"version":"2c91d8366ff2506296191c26fd97cc1990bab3ee22576275d28b654a21261a44","affectsGlobalScope":true,"impliedFormat":1},{"version":"5524481e56c48ff486f42926778c0a3cce1cc85dc46683b92b1271865bcf015a","impliedFormat":1},{"version":"db39d9a16e4ddcd8a8f2b7b3292b362cc5392f92ad7ccd76f00bccf6838ac7de","affectsGlobalScope":true,"impliedFormat":1},{"version":"289e9894a4668c61b5ffed09e196c1f0c2f87ca81efcaebdf6357cfb198dac14","impliedFormat":1},{"version":"25a1105595236f09f5bce42398be9f9ededc8d538c258579ab662d509aa3b98e","impliedFormat":1},{"version":"5078cd62dbdf91ae8b1dc90b1384dec71a9c0932d62bdafb1a811d2a8e26bef2","impliedFormat":1},{"version":"a2e2bbde231b65c53c764c12313897ffdfb6c49183dd31823ee2405f2f7b5378","impliedFormat":1},{"version":"ad1cc0ed328f3f708771272021be61ab146b32ecf2b78f3224959ff1e2cd2a5c","impliedFormat":1},{"version":"71450bbc2d82821d24ca05699a533e72758964e9852062c53b30f31c36978ab8","affectsGlobalScope":true,"impliedFormat":1},{"version":"62f572306e0b173cc5dfc4c583471151f16ef3779cf27ab96922c92ec82a3bc8","affectsGlobalScope":true,"impliedFormat":1},{"version":"067bdd82d9768baddbdc8df51d85f7b96387c47176bf7f895d2e21e2b6b2f1f4","impliedFormat":1},{"version":"42d30e7d04915facc3ded22b4127c9f517973b4c2b1326e56c10ff70daf6800a","impliedFormat":1},{"version":"bd8b644c5861b94926687618ec2c9e60ad054d334d6b7eb4517f23f53cb11f91","impliedFormat":1},{"version":"bcbabfaca3f6b8a76cb2739e57710daf70ab5c9479ab70f5351c9b4932abf6bd","impliedFormat":1},{"version":"77fced47f495f4ff29bb49c52c605c5e73cd9b47d50080133783032769a9d8a6","impliedFormat":1},{"version":"55f370475031b3d36af8dd47fb3934dff02e0f1330d13f1977c9e676af5c2e70","impliedFormat":1},{"version":"c54f0b30a787b3df16280f4675bd3d9d17bf983ae3cd40087409476bc50b922d","affectsGlobalScope":true,"impliedFormat":1},{"version":"0f5cda0282e1d18198e2887387eb2f026372ebc4e11c4e4516fef8a19ee4d514","impliedFormat":1},{"version":"e99b0e71f07128fc32583e88ccd509a1aaa9524c290efb2f48c22f9bf8ba83b1","impliedFormat":1},{"version":"76957a6d92b94b9e2852cf527fea32ad2dc0ef50f67fe2b14bd027c9ceef2d86","impliedFormat":1},{"version":"5e9f8c1e042b0f598a9be018fc8c3cb670fe579e9f2e18e3388b63327544fe16","affectsGlobalScope":true,"impliedFormat":1},{"version":"a8a99a5e6ed33c4a951b67cc1fd5b64fd6ad719f5747845c165ca12f6c21ba16","affectsGlobalScope":true,"impliedFormat":1},{"version":"a58a15da4c5ba3df60c910a043281256fa52d36a0fcdef9b9100c646282e88dd","impliedFormat":1},{"version":"b36beffbf8acdc3ebc58c8bb4b75574b31a2169869c70fc03f82895b93950a12","impliedFormat":1},{"version":"de263f0089aefbfd73c89562fb7254a7468b1f33b61839aafc3f035d60766cb4","impliedFormat":1},{"version":"70b57b5529051497e9f6482b76d91c0dcbb103d9ead8a0549f5bab8f65e5d031","impliedFormat":1},{"version":"8c81fd4a110490c43d7c578e8c6f69b3af01717189196899a6a44f93daa57a3a","impliedFormat":1},{"version":"1013eb2e2547ad8c100aca52ef9df8c3f209edee32bb387121bb3227f7c00088","impliedFormat":1},{"version":"e07c573ac1971ea89e2c56ff5fd096f6f7bba2e6dbcd5681d39257c8d954d4a8","impliedFormat":1},{"version":"363eedb495912790e867da6ff96e81bf792c8cfe386321e8163b71823a35719a","impliedFormat":1},{"version":"37ba7b45141a45ce6e80e66f2a96c8a5ab1bcef0fc2d0f56bb58df96ec67e972","impliedFormat":1},{"version":"125d792ec6c0c0f657d758055c494301cc5fdb327d9d9d5960b3f129aff76093","impliedFormat":1},{"version":"dba28a419aec76ed864ef43e5f577a5c99a010c32e5949fe4e17a4d57c58dd11","affectsGlobalScope":true,"impliedFormat":1},{"version":"ea713aa14a670b1ea0fbaaca4fd204e645f71ca7653a834a8ec07ee889c45de6","impliedFormat":1},{"version":"1e080418e53f9b7a05db81ab517c4e1d71b7194ee26ddd54016bcef3ac474bd4","impliedFormat":1},{"version":"9705cd157ffbb91c5cab48bdd2de5a437a372e63f870f8a8472e72ff634d47c1","affectsGlobalScope":true,"impliedFormat":1},{"version":"ae86f30d5d10e4f75ce8dcb6e1bd3a12ecec3d071a21e8f462c5c85c678efb41","impliedFormat":1},{"version":"982efeb2573605d4e6d5df4dc7e40846bda8b9e678e058fc99522ab6165c479e","impliedFormat":1},{"version":"e03460fe72b259f6d25ad029f085e4bedc3f90477da4401d8fbc1efa9793230e","impliedFormat":1},{"version":"4286a3a6619514fca656089aee160bb6f2e77f4dd53dc5a96b26a0b4fc778055","impliedFormat":1},{"version":"3b63610eaabadf26aadf51a563e4b2a8bf56eeaab1094f2a2b21509008eaef0c","affectsGlobalScope":true,"impliedFormat":1},{"version":"2d5d50cd0667d9710d4d2f6e077cc4e0f9dc75e106cccaea59999b36873c5a0d","affectsGlobalScope":true,"impliedFormat":1},{"version":"784490137935e1e38c49b9289110e74a1622baf8a8907888dcbe9e476d7c5e44","impliedFormat":1},{"version":"42180b657831d1b8fead051698618b31da623fb71ff37f002cb9d932cfa775f1","impliedFormat":1},{"version":"4f98d6fb4fe7cbeaa04635c6eaa119d966285d4d39f0eb55b2654187b0b27446","impliedFormat":1},{"version":"f8529fe0645fd9af7441191a4961497cc7638f75a777a56248eac6a079bb275d","affectsGlobalScope":true,"impliedFormat":1},{"version":"4445f6ce6289c5b2220398138da23752fd84152c5c95bb8b58dedefc1758c036","impliedFormat":1},{"version":"a51f786b9f3c297668f8f322a6c58f85d84948ef69ade32069d5d63ec917221c","impliedFormat":1},{"version":"a7ca8df4f2931bef2aa4118078584d84a0b16539598eaadf7dce9104dfaa381c","impliedFormat":1},{"version":"5c31dea483b64cbb341ea8a7073c457720d1574f87837e71cccb70ce91196211","impliedFormat":99},{"version":"11443a1dcfaaa404c68d53368b5b818712b95dd19f188cab1669c39bee8b84b3","impliedFormat":1},{"version":"151ff381ef9ff8da2da9b9663ebf657eac35c4c9a19183420c05728f31a6761d","impliedFormat":1},{"version":"ffb518fc55181aefd066c690dbc0f8fa6a1533c8ddac595469c8c5f7fda2d756","affectsGlobalScope":true,"impliedFormat":1},{"version":"a660aa95476042d3fdcc1343cf6bb8fdf24772d31712b1db321c5a4dcc325434","impliedFormat":1},{"version":"36977c14a7f7bfc8c0426ae4343875689949fb699f3f84ecbe5b300ebf9a2c55","impliedFormat":1},{"version":"217d7b67dacf8438f0be82b846f933981a1e6527e63c082c56adaf4782d62ab4","impliedFormat":99},{"version":"b8caba62c0d2ef625f31cbb4fde09d851251af2551086ccf068611b0a69efd81","affectsGlobalScope":true,"impliedFormat":1},{"version":"f582b0fcbf1eea9b318ab92fb89ea9ab2ebb84f9b60af89328a91155e1afce72","impliedFormat":1},{"version":"402e5c534fb2b85fa771170595db3ac0dd532112c8fa44fc23f233bc6967488b","impliedFormat":1},{"version":"8885cf05f3e2abf117590bbb951dcf6359e3e5ac462af1c901cfd24c6a6472e2","impliedFormat":1},{"version":"333caa2bfff7f06017f114de738050dd99a765c7eb16571c6d25a38c0d5365dc","impliedFormat":1},{"version":"e61df3640a38d535fd4bc9f4a53aef17c296b58dc4b6394fd576b808dd2fe5e6","impliedFormat":1},{"version":"459920181700cec8cbdf2a5faca127f3f17fd8dd9d9e577ed3f5f3af5d12a2e4","impliedFormat":1},{"version":"4719c209b9c00b579553859407a7e5dcfaa1c472994bd62aa5dd3cc0757eb077","impliedFormat":1},{"version":"7ec359bbc29b69d4063fe7dad0baaf35f1856f914db16b3f4f6e3e1bca4099fa","impliedFormat":1},{"version":"70790a7f0040993ca66ab8a07a059a0f8256e7bb57d968ae945f696cbff4ac7a","impliedFormat":1},{"version":"d1b9a81e99a0050ca7f2d98d7eedc6cda768f0eb9fa90b602e7107433e64c04c","impliedFormat":1},{"version":"a022503e75d6953d0e82c2c564508a5c7f8556fad5d7f971372d2d40479e4034","impliedFormat":1},{"version":"b215c4f0096f108020f666ffcc1f072c81e9f2f95464e894a5d5f34c5ea2a8b1","impliedFormat":1},{"version":"644491cde678bd462bb922c1d0cfab8f17d626b195ccb7f008612dc31f445d2d","impliedFormat":1},{"version":"dfe54dab1fa4961a6bcfba68c4ca955f8b5bbeb5f2ab3c915aa7adaa2eabc03a","impliedFormat":1},{"version":"1251d53755b03cde02466064260bb88fd83c30006a46395b7d9167340bc59b73","impliedFormat":1},{"version":"47865c5e695a382a916b1eedda1b6523145426e48a2eae4647e96b3b5e52024f","impliedFormat":1},{"version":"4cdf27e29feae6c7826cdd5c91751cc35559125e8304f9e7aed8faef97dcf572","impliedFormat":1},{"version":"331b8f71bfae1df25d564f5ea9ee65a0d847c4a94baa45925b6f38c55c7039bf","impliedFormat":1},{"version":"2a771d907aebf9391ac1f50e4ad37952943515eeea0dcc7e78aa08f508294668","impliedFormat":1},{"version":"0146fd6262c3fd3da51cb0254bb6b9a4e42931eb2f56329edd4c199cb9aaf804","impliedFormat":1},{"version":"183f480885db5caa5a8acb833c2be04f98056bdcc5fb29e969ff86e07efe57ab","impliedFormat":99},{"version":"4ec16d7a4e366c06a4573d299e15fe6207fc080f41beac5da06f4af33ea9761e","impliedFormat":1},{"version":"960bd764c62ac43edc24eaa2af958a4b4f1fa5d27df5237e176d0143b36a39c6","affectsGlobalScope":true,"impliedFormat":1},{"version":"59f8dc89b9e724a6a667f52cdf4b90b6816ae6c9842ce176d38fcc973669009e","affectsGlobalScope":true,"impliedFormat":1},{"version":"e4af494f7a14b226bbe732e9c130d8811f8c7025911d7c58dd97121a85519715","impliedFormat":1},{"version":"a5d643092d2f16cb861872357b12ab844f33fc1181f7c5aed447b3424b4f5668","impliedFormat":99},{"version":"b34b5f6b506abb206b1ea73c6a332b9ee9c8c98be0f6d17cdbda9430ecc1efab","impliedFormat":99},{"version":"75d4c746c3d16af0df61e7b0afe9606475a23335d9f34fcc525d388c21e9058b","impliedFormat":99},{"version":"fa959bf357232201c32566f45d97e70538c75a093c940af594865d12f31d4912","impliedFormat":99},{"version":"d2c52abd76259fc39a30dfae70a2e5ce77fd23144457a7ff1b64b03de6e3aec7","impliedFormat":99},{"version":"e6233e1c976265e85aa8ad76c3881febe6264cb06ae3136f0257e1eab4a6cc5a","impliedFormat":99},{"version":"f73e2335e568014e279927321770da6fe26facd4ac96cdc22a56687f1ecbb58e","impliedFormat":99},{"version":"317878f156f976d487e21fd1d58ad0461ee0a09185d5b0a43eedf2a56eb7e4ea","impliedFormat":99},{"version":"324ac98294dab54fbd580c7d0e707d94506d7b2c3d5efe981a8495f02cf9ad96","impliedFormat":99},{"version":"9ec72eb493ff209b470467e24264116b6a8616484bca438091433a545dfba17e","impliedFormat":99},{"version":"d6ee22aba183d5fc0c7b8617f77ee82ecadc2c14359cc51271c135e23f6ed51f","impliedFormat":99},{"version":"49747416f08b3ba50500a215e7a55d75268b84e31e896a40313c8053e8dec908","impliedFormat":99},{"version":"81e634f1c5e1ca309e7e3dc69e2732eea932ef07b8b34517d452e5a3e9a36fa3","impliedFormat":99},{"version":"34f39f75f2b5aa9c84a9f8157abbf8322e6831430e402badeaf58dd284f9b9a6","impliedFormat":99},{"version":"427fe2004642504828c1476d0af4270e6ad4db6de78c0b5da3e4c5ca95052a99","impliedFormat":1},{"version":"c8905dbea83f3220676a669366cd8c1acef56af4d9d72a8b2241b1d044bb4302","affectsGlobalScope":true,"impliedFormat":99},{"version":"891694d3694abd66f0b8872997b85fd8e52bc51632ce0f8128c96962b443189f","impliedFormat":99},{"version":"69bf2422313487956e4dacf049f30cb91b34968912058d244cb19e4baa24da97","impliedFormat":99},{"version":"971a2c327ff166c770c5fb35699575ba2d13bba1f6d2757309c9be4b30036c8e","impliedFormat":99},{"version":"4f45e8effab83434a78d17123b01124259fbd1e335732135c213955d85222234","impliedFormat":99},{"version":"7bd51996fb7717941cbe094b05adc0d80b9503b350a77b789bbb0fc786f28053","impliedFormat":99},{"version":"b62006bbc815fe8190c7aee262aad6bff993e3f9ade70d7057dfceab6de79d2f","impliedFormat":99},{"version":"13497c0d73306e27f70634c424cd2f3b472187164f36140b504b3756b0ff476d","impliedFormat":99},{"version":"bf7a2d0f6d9e72d59044079d61000c38da50328ccdff28c47528a1a139c610ec","impliedFormat":99},{"version":"04471dc55f802c29791cc75edda8c4dd2a121f71c2401059da61eff83099e8ab","impliedFormat":99},{"version":"120a80aa556732f684db3ed61aeff1d6671e1655bd6cba0aa88b22b88ac9a6b1","affectsGlobalScope":true,"impliedFormat":99},{"version":"e58c0b5226aff07b63be6ac6e1bec9d55bc3d2bda3b11b9b68cccea8c24ae839","affectsGlobalScope":true,"impliedFormat":99},{"version":"a23a08b626aa4d4a1924957bd8c4d38a7ffc032e21407bbd2c97413e1d8c3dbd","impliedFormat":99},{"version":"5a88655bf852c8cc007d6bc874ab61d1d63fba97063020458177173c454e9b4a","impliedFormat":99},{"version":"7e4dfae2da12ec71ffd9f55f4641a6e05610ce0d6784838659490e259e4eb13c","impliedFormat":99},{"version":"c30a41267fc04c6518b17e55dcb2b810f267af4314b0b6d7df1c33a76ce1b330","impliedFormat":1},{"version":"72422d0bac4076912385d0c10911b82e4694fc106e2d70added091f88f0824ba","impliedFormat":1},{"version":"da251b82c25bee1d93f9fd80c5a61d945da4f708ca21285541d7aff83ecb8200","impliedFormat":1},{"version":"4c8ca51077f382498f47074cf304d654aba5d362416d4f809dfdd5d4f6b3aaca","impliedFormat":1},{"version":"c6bddf16578495abc8b5546850b047f30c4b5a2a2b7fecefc0e11a44a6e91399","impliedFormat":1},{"version":"13573a613314e40482386fe9c7934f9d86f3e06f19b840466c75391fb833b99b","impliedFormat":99},{"version":"43e9d63ab563bc1e2fa5fceb3d72c72a8a86de1f7143788a70357838e58d1310","signature":"8e609bb71c20b858c77f0e9f90bb1319db8477b13f9f965f1a1e18524bf50881","impliedFormat":99},{"version":"f96f3c445afc7d65d4790386e37c5b57f095f285cc89b8315b209fe0c81837c1","impliedFormat":1},{"version":"7212c2d58855b8df35275180e97903a4b6093d4fbaefea863d8d028da63938c6","impliedFormat":1},{"version":"de0199a112f75809a7f80ec071495159dcf3e434bc021347e0175627398264c3","impliedFormat":1},{"version":"1a2bed55cfa62b4649485df27c0e560b04d4da4911e3a9f0475468721495563f","impliedFormat":1},{"version":"854045924626ba585f454b53531c42aed4365f02301aa8eca596423f4675b71f","impliedFormat":1},{"version":"fd326577c62145816fe1acc306c734c2396487f76719d3785d4e825b34540b33","impliedFormat":1},{"version":"6942f031a55d96365479986d08bb04aff56b7e2adae1159cdb4012bef6ff6d8c","impliedFormat":1},{"version":"963d59066dd6742da1918a6213a209bcc205b8ee53b1876ee2b4e6d80f97c85e","impliedFormat":1},{"version":"22293bd6fa12747929f8dfca3ec1684a3fe08638aa18023dd286ab337e88a592","impliedFormat":1},{"version":"e72bcd16c134dae5a840b1d5d0e8b87e1d07fbbff01d66e9a7b913da3cd39b8e","impliedFormat":1}],"root":[78,262],"options":{"allowJs":true,"allowUnreachableCode":false,"alwaysStrict":true,"composite":true,"declaration":true,"declarationMap":true,"erasableSyntaxOnly":true,"esModuleInterop":true,"experimentalDecorators":true,"module":101,"newLine":1,"noFallthroughCasesInSwitch":true,"noImplicitReturns":true,"noUnusedLocals":false,"noUnusedParameters":true,"outDir":"./","preserveConstEnums":true,"removeComments":false,"rootDir":"../src","skipLibCheck":true,"sourceMap":true,"strict":true,"target":11,"tsBuildInfoFile":"./.buildInfo.json"},"referencedMap":[[241,1],[263,2],[240,3],[195,3],[268,4],[269,3],[270,3],[138,5],[139,5],[140,6],[95,7],[141,8],[142,9],[143,10],[93,3],[144,11],[145,12],[146,13],[147,14],[148,15],[149,16],[150,16],[152,3],[151,17],[153,18],[154,19],[155,20],[137,21],[94,3],[156,22],[157,23],[158,24],[191,25],[159,26],[160,27],[161,28],[162,29],[163,30],[164,31],[165,32],[166,33],[167,34],[168,35],[169,35],[170,36],[171,3],[172,3],[173,37],[175,38],[174,39],[176,40],[177,41],[178,42],[179,43],[180,44],[181,45],[182,46],[183,47],[184,48],[185,49],[186,50],[187,51],[188,52],[189,53],[190,54],[271,3],[272,3],[251,55],[229,56],[227,3],[228,3],[79,3],[90,57],[85,58],[88,59],[242,60],[234,3],[237,61],[236,62],[247,62],[235,63],[250,3],[87,64],[89,64],[81,65],[84,66],[230,65],[86,67],[80,3],[96,3],[200,3],[258,68],[260,69],[259,70],[257,71],[256,3],[264,72],[265,72],[267,73],[266,72],[218,74],[216,75],[217,76],[205,77],[206,75],[213,78],[204,79],[209,80],[219,3],[210,81],[215,82],[221,83],[220,84],[203,85],[211,86],[212,87],[207,88],[214,74],[208,89],[197,90],[196,91],[202,3],[243,3],[82,3],[83,92],[75,3],[76,3],[14,3],[12,3],[13,3],[18,3],[17,3],[2,3],[19,3],[20,3],[21,3],[22,3],[23,3],[24,3],[25,3],[26,3],[3,3],[27,3],[28,3],[4,3],[29,3],[33,3],[30,3],[31,3],[32,3],[34,3],[35,3],[36,3],[5,3],[37,3],[38,3],[39,3],[40,3],[6,3],[44,3],[41,3],[42,3],[43,3],[45,3],[7,3],[46,3],[51,3],[52,3],[47,3],[48,3],[49,3],[50,3],[8,3],[56,3],[53,3],[54,3],[55,3],[57,3],[9,3],[58,3],[59,3],[60,3],[62,3],[61,3],[63,3],[64,3],[10,3],[65,3],[66,3],[67,3],[11,3],[77,3],[68,3],[69,3],[70,3],[71,3],[72,3],[1,3],[73,3],[74,3],[16,3],[15,3],[114,93],[125,94],[112,95],[126,96],[135,97],[103,98],[104,99],[102,100],[134,101],[129,102],[133,103],[106,104],[122,105],[105,106],[132,107],[100,108],[101,102],[107,109],[108,3],[113,110],[111,109],[98,111],[136,112],[127,113],[117,114],[116,109],[118,115],[120,116],[115,117],[119,118],[130,101],[109,119],[110,120],[121,121],[99,96],[124,122],[123,109],[128,3],[97,3],[131,123],[245,124],[232,125],[233,124],[231,3],[226,126],[199,127],[193,128],[194,128],[192,3],[198,129],[224,3],[223,3],[222,3],[201,3],[225,130],[244,131],[238,132],[246,133],[92,134],[252,135],[254,136],[248,137],[255,138],[253,139],[239,140],[249,141],[261,142],[91,3],[262,143],[78,3]],"latestChangedDtsFile":"./__tests__/index.test.d.ts","version":"5.9.2"}
package/lib/index.d.ts ADDED
@@ -0,0 +1,229 @@
1
+ export default ShelfPack;
2
+ /**
3
+ * Bin object with `id`, `width`, `height` properties
4
+ */
5
+ export type BinShorthand = {
6
+ /**
7
+ * Unique identifier for this bin
8
+ */
9
+ id: string;
10
+ /**
11
+ * Width of the bin
12
+ */
13
+ w: number;
14
+ /**
15
+ * Height of the bin
16
+ */
17
+ h: number;
18
+ };
19
+ /**
20
+ * Bin object with `id`, `w`, `h` properties
21
+ */
22
+ export type Bin = {
23
+ /**
24
+ * Unique identifier for this bin
25
+ */
26
+ id: string;
27
+ /**
28
+ * Width of the bin
29
+ */
30
+ width: number;
31
+ /**
32
+ * Height of the bin
33
+ */
34
+ height: number;
35
+ };
36
+ /**
37
+ * Create a new ShelfPack bin allocator.
38
+ *
39
+ * Uses the Shelf Best Height Fit algorithm from
40
+ * http://clb.demon.fi/files/RectangleBinPack.pdf
41
+ *
42
+ * @class ShelfPack
43
+ * @param {number} [w=64] Initial width of the sprite
44
+ * @param {number} [h=64] Initial width of the sprite
45
+ * @param {Object} [options]
46
+ * @param {boolean} [options.autoResize=false] If `true`, the sprite will automatically grow
47
+ * @example
48
+ * var sprite = new ShelfPack(64, 64, { autoResize: false });
49
+ */
50
+ declare function ShelfPack(w?: number, h?: number, options?: {
51
+ autoResize?: boolean | undefined;
52
+ }): void;
53
+ declare class ShelfPack {
54
+ /**
55
+ * Create a new ShelfPack bin allocator.
56
+ *
57
+ * Uses the Shelf Best Height Fit algorithm from
58
+ * http://clb.demon.fi/files/RectangleBinPack.pdf
59
+ *
60
+ * @class ShelfPack
61
+ * @param {number} [w=64] Initial width of the sprite
62
+ * @param {number} [h=64] Initial width of the sprite
63
+ * @param {Object} [options]
64
+ * @param {boolean} [options.autoResize=false] If `true`, the sprite will automatically grow
65
+ * @example
66
+ * var sprite = new ShelfPack(64, 64, { autoResize: false });
67
+ */
68
+ constructor(w?: number, h?: number, options?: {
69
+ autoResize?: boolean | undefined;
70
+ });
71
+ w: number;
72
+ h: number;
73
+ autoResize: boolean;
74
+ shelves: any[];
75
+ freebins: any[];
76
+ stats: {};
77
+ bins: {};
78
+ maxId: number;
79
+ /**
80
+ * Bin object with `id`, `width`, `height` properties
81
+ * @typedef {Object} BinShorthand
82
+ * @property {string} id Unique identifier for this bin
83
+ * @property {number} w Width of the bin
84
+ * @property {number} h Height of the bin
85
+ */
86
+ /**
87
+ * Bin object with `id`, `w`, `h` properties
88
+ * @typedef {Object} Bin
89
+ * @property {string} id Unique identifier for this bin
90
+ * @property {number} width Width of the bin
91
+ * @property {number} height Height of the bin
92
+ */
93
+ /**
94
+ * Batch pack multiple bins into the sprite.
95
+ *
96
+ * @param {Object[]} bins Array of requested bins - each object should have `width`, `height` (or `w`, `h`) properties
97
+ * @param {Object} [options]
98
+ * @param {boolean} [options.inPlace=false] If `true`, the supplied bin objects will be updated inplace with `x` and `y` properties
99
+ * @returns {Bin[]} Array of allocated Bins - each Bin is an object with `id`, `x`, `y`, `w`, `h` properties
100
+ * @noto Mutate input bins
101
+ * @example
102
+ * var bins = [
103
+ * { id: 1, w: 12, h: 12 },
104
+ * { id: 2, w: 12, h: 16 },
105
+ * { id: 3, w: 12, h: 24 }
106
+ * ];
107
+ * var results = sprite.pack(bins, { inPlace: false });
108
+ */
109
+ pack(bins: Object[], options?: {
110
+ inPlace?: boolean | undefined;
111
+ }): Bin[];
112
+ /**
113
+ * Pack a single bin into the sprite.
114
+ *
115
+ * Each bin will have a unique identitifer.
116
+ * If no identifier is supplied in the `id` parameter, one will be created.
117
+ * Note: The supplied `id` is used as an object index, so numeric values are fastest!
118
+ *
119
+ * Bins are automatically refcounted (i.e. a newly packed Bin will have a refcount of 1).
120
+ * When a bin is no longer needed, use the `ShelfPack.unref` function to mark it
121
+ * as unused. When a Bin's refcount decrements to 0, the Bin will be marked
122
+ * as free and its space may be reused by the packing code.
123
+ *
124
+ * @param {number} w Width of the bin to allocate
125
+ * @param {number} h Height of the bin to allocate
126
+ * @param {number|string} [id] Unique identifier for this bin, (if unsupplied, assume it's a new bin and create an id)
127
+ * @returns {Bin} Bin object with `id`, `x`, `y`, `w`, `h` properties, or `null` if allocation failed
128
+ * @example
129
+ * var results = sprite.packOne(12, 16, 'a');
130
+ */
131
+ packOne(w: number, h: number, id?: number | string): Bin;
132
+ private allocFreebin;
133
+ private allocShelf;
134
+ /**
135
+ * Shrink the width/height of the sprite to the bare minimum.
136
+ * Since shelf-pack doubles first width, then height when running out of shelf space
137
+ * this can result in fairly large unused space both in width and height if that happens
138
+ * towards the end of bin packing.
139
+ */
140
+ shrink(): void;
141
+ /**
142
+ * Return a packed bin given its id, or undefined if the id is not found
143
+ *
144
+ * @param {number|string} id Unique identifier for this bin,
145
+ * @returns {Bin} The requested bin, or undefined if not yet packed
146
+ * @example
147
+ * var b = sprite.getBin('a');
148
+ */
149
+ getBin(id: number | string): Bin;
150
+ /**
151
+ * Increment the ref count of a bin and update statistics.
152
+ *
153
+ * @param {Bin} bin Bin instance
154
+ * @returns {number} New refcount of the bin
155
+ * @example
156
+ * var bin = sprite.getBin('a');
157
+ * sprite.ref(bin);
158
+ */
159
+ ref(bin: Bin): number;
160
+ /**
161
+ * Decrement the ref count of a bin and update statistics.
162
+ * The bin will be automatically marked as free space once the refcount reaches 0.
163
+ *
164
+ * @param {Bin} bin Bin instance
165
+ * @returns {number} New refcount of the bin
166
+ * @example
167
+ * var bin = sprite.getBin('a');
168
+ * sprite.unref(bin);
169
+ */
170
+ unref(bin: Bin): number;
171
+ /**
172
+ * Clear the sprite. Resets everything and resets statistics.
173
+ *
174
+ * @example
175
+ * sprite.clear();
176
+ */
177
+ clear(): void;
178
+ /**
179
+ * Resize the sprite.
180
+ *
181
+ * @param {number} w Requested new sprite width
182
+ * @param {number} h Requested new sprite height
183
+ * @returns {boolean} `true` if resize succeeded, `false` if failed
184
+ * @example
185
+ * sprite.resize(256, 256);
186
+ */
187
+ resize(w: number, h: number): boolean;
188
+ }
189
+ /**
190
+ * Create a new Bin object.
191
+ *
192
+ * @class Bin
193
+ * @param {number|string} id Unique id of the bin
194
+ * @param {number} x Left coordinate of the bin
195
+ * @param {number} y Top coordinate of the bin
196
+ * @param {number} w Width of the bin
197
+ * @param {number} h Height of the bin
198
+ * @param {number} [maxw] Max width of the bin (defaults to `w` if not provided)
199
+ * @param {number} [maxh] Max height of the bin (defaults to `h` if not provided)
200
+ * @example
201
+ * var bin = new Bin('a', 0, 0, 12, 16);
202
+ */
203
+ declare function Bin(id: number | string, x: number, y: number, w: number, h: number, maxw?: number, maxh?: number): void;
204
+ declare class Bin {
205
+ /**
206
+ * Create a new Bin object.
207
+ *
208
+ * @class Bin
209
+ * @param {number|string} id Unique id of the bin
210
+ * @param {number} x Left coordinate of the bin
211
+ * @param {number} y Top coordinate of the bin
212
+ * @param {number} w Width of the bin
213
+ * @param {number} h Height of the bin
214
+ * @param {number} [maxw] Max width of the bin (defaults to `w` if not provided)
215
+ * @param {number} [maxh] Max height of the bin (defaults to `h` if not provided)
216
+ * @example
217
+ * var bin = new Bin('a', 0, 0, 12, 16);
218
+ */
219
+ constructor(id: number | string, x: number, y: number, w: number, h: number, maxw?: number, maxh?: number);
220
+ id: string | number;
221
+ x: number;
222
+ y: number;
223
+ w: number;
224
+ h: number;
225
+ maxw: number;
226
+ maxh: number;
227
+ refcount: number;
228
+ }
229
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.js"],"names":[],"mappings":";;;;;;;;QAgCc,MAAM;;;;OACN,MAAM;;;;OACN,MAAM;;;;;;;;;QAON,MAAM;;;;WACN,MAAM;;;;YACN,MAAM;;AAxCpB;;;;;;;;;;;;;GAaG;AACH,+BAPY,MAAM,MACN,MAAM,YAEf;IAA2B,UAAU;CACrC,QAaF;;IAxBD;;;;;;;;;;;;;OAaG;IACH,gBAPY,MAAM,MACN,MAAM,YAEf;QAA2B,UAAU;KACrC,EAaF;IARG,UAAgB;IAChB,UAAgB;IAChB,oBAAsC;IACtC,eAAiB;IACjB,gBAAkB;IAClB,UAAe;IACf,SAAc;IACd,cAAc;IAGlB;;;;;;OAMG;IAGH;;;;;;OAMG;IAGH;;;;;;;;;;;;;;;OAeG;IACH,WAba,MAAM,EAAE,YAElB;QAA6B,OAAO;KACpC,GAAU,GAAG,EAAE,CAuCjB;IAGD;;;;;;;;;;;;;;;;;;OAkBG;IACH,WAPc,MAAM,KACN,MAAM,OACN,MAAM,GAAC,MAAM,GACb,GAAG,CA8GhB;IAekC,qBASlC;IAegC,mBAMhC;IAGD;;;;;OAKG;IACH,eAaC;IAGD;;;;;;;OAOG;IACH,WALc,MAAM,GAAC,MAAM,GACb,GAAG,CAMhB;IAGD;;;;;;;;OAQG;IACH,SANc,GAAG,GACH,MAAM,CAYnB;IAGD;;;;;;;;;OASG;IACH,WANc,GAAG,GACH,MAAM,CAiBnB;IAGD;;;;;OAKG;IACH,cAMC;IAGD;;;;;;;;OAQG;IACH,UANa,MAAM,KACN,MAAM,GACN,OAAO,CAWnB;;AA4DD;;;;;;;;;;;;;GAaG;AACH,yBAVY,MAAM,GAAC,MAAM,KACb,MAAM,KACN,MAAM,KACN,MAAM,KACN,MAAM,SACN,MAAM,SACN,MAAM,QAajB;;IAvBD;;;;;;;;;;;;;OAaG;IACH,gBAVY,MAAM,GAAC,MAAM,KACb,MAAM,KACN,MAAM,KACN,MAAM,KACN,MAAM,SACN,MAAM,SACN,MAAM,EAajB;IARG,oBAAY;IACZ,UAAW;IACX,UAAW;IACX,UAAW;IACX,UAAW;IACX,aAAqB;IACrB,aAAqB;IACrB,iBAAiB"}
package/lib/index.js ADDED
@@ -0,0 +1,405 @@
1
+ export default ShelfPack;
2
+ /**
3
+ * Create a new ShelfPack bin allocator.
4
+ *
5
+ * Uses the Shelf Best Height Fit algorithm from
6
+ * http://clb.demon.fi/files/RectangleBinPack.pdf
7
+ *
8
+ * @class ShelfPack
9
+ * @param {number} [w=64] Initial width of the sprite
10
+ * @param {number} [h=64] Initial width of the sprite
11
+ * @param {Object} [options]
12
+ * @param {boolean} [options.autoResize=false] If `true`, the sprite will automatically grow
13
+ * @example
14
+ * var sprite = new ShelfPack(64, 64, { autoResize: false });
15
+ */
16
+ function ShelfPack(w, h, options) {
17
+ options = options || {};
18
+ this.w = w || 64;
19
+ this.h = h || 64;
20
+ this.autoResize = !!options.autoResize;
21
+ this.shelves = [];
22
+ this.freebins = [];
23
+ this.stats = {};
24
+ this.bins = {};
25
+ this.maxId = 0;
26
+ }
27
+ /**
28
+ * Bin object with `id`, `width`, `height` properties
29
+ * @typedef {Object} BinShorthand
30
+ * @property {string} id Unique identifier for this bin
31
+ * @property {number} w Width of the bin
32
+ * @property {number} h Height of the bin
33
+ */
34
+ /**
35
+ * Bin object with `id`, `w`, `h` properties
36
+ * @typedef {Object} Bin
37
+ * @property {string} id Unique identifier for this bin
38
+ * @property {number} width Width of the bin
39
+ * @property {number} height Height of the bin
40
+ */
41
+ /**
42
+ * Batch pack multiple bins into the sprite.
43
+ *
44
+ * @param {Object[]} bins Array of requested bins - each object should have `width`, `height` (or `w`, `h`) properties
45
+ * @param {Object} [options]
46
+ * @param {boolean} [options.inPlace=false] If `true`, the supplied bin objects will be updated inplace with `x` and `y` properties
47
+ * @returns {Bin[]} Array of allocated Bins - each Bin is an object with `id`, `x`, `y`, `w`, `h` properties
48
+ * @noto Mutate input bins
49
+ * @example
50
+ * var bins = [
51
+ * { id: 1, w: 12, h: 12 },
52
+ * { id: 2, w: 12, h: 16 },
53
+ * { id: 3, w: 12, h: 24 }
54
+ * ];
55
+ * var results = sprite.pack(bins, { inPlace: false });
56
+ */
57
+ ShelfPack.prototype.pack = function (bins, options) {
58
+ bins = [].concat(bins);
59
+ options = options || {};
60
+ var results = [], w, h, id, allocation;
61
+ for (var i = 0; i < bins.length; i++) {
62
+ w = bins[i].w || bins[i].width;
63
+ h = bins[i].h || bins[i].height;
64
+ id = bins[i].id;
65
+ if (w && h) {
66
+ allocation = this.packOne(w, h, id);
67
+ if (!allocation) {
68
+ continue;
69
+ }
70
+ if (options.inPlace) {
71
+ bins[i].x = allocation.x;
72
+ bins[i].y = allocation.y;
73
+ bins[i].id = allocation.id;
74
+ }
75
+ results.push(allocation);
76
+ }
77
+ }
78
+ this.shrink();
79
+ return results;
80
+ };
81
+ /**
82
+ * Pack a single bin into the sprite.
83
+ *
84
+ * Each bin will have a unique identitifer.
85
+ * If no identifier is supplied in the `id` parameter, one will be created.
86
+ * Note: The supplied `id` is used as an object index, so numeric values are fastest!
87
+ *
88
+ * Bins are automatically refcounted (i.e. a newly packed Bin will have a refcount of 1).
89
+ * When a bin is no longer needed, use the `ShelfPack.unref` function to mark it
90
+ * as unused. When a Bin's refcount decrements to 0, the Bin will be marked
91
+ * as free and its space may be reused by the packing code.
92
+ *
93
+ * @param {number} w Width of the bin to allocate
94
+ * @param {number} h Height of the bin to allocate
95
+ * @param {number|string} [id] Unique identifier for this bin, (if unsupplied, assume it's a new bin and create an id)
96
+ * @returns {Bin} Bin object with `id`, `x`, `y`, `w`, `h` properties, or `null` if allocation failed
97
+ * @example
98
+ * var results = sprite.packOne(12, 16, 'a');
99
+ */
100
+ ShelfPack.prototype.packOne = function (w, h, id) {
101
+ var best = { freebin: -1, shelf: -1, waste: Infinity }, y = 0, bin, shelf, waste, i;
102
+ // if id was supplied, attempt a lookup..
103
+ if (typeof id === 'string' || typeof id === 'number') {
104
+ bin = this.getBin(id);
105
+ if (bin) { // we packed this bin already
106
+ this.ref(bin);
107
+ return bin;
108
+ }
109
+ if (typeof id === 'number') {
110
+ this.maxId = Math.max(id, this.maxId);
111
+ }
112
+ }
113
+ else {
114
+ id = ++this.maxId;
115
+ }
116
+ // First try to reuse a free bin..
117
+ for (i = 0; i < this.freebins.length; i++) {
118
+ bin = this.freebins[i];
119
+ // exactly the right height and width, use it..
120
+ if (h === bin.maxh && w === bin.maxw) {
121
+ return this.allocFreebin(i, w, h, id);
122
+ }
123
+ // not enough height or width, skip it..
124
+ if (h > bin.maxh || w > bin.maxw) {
125
+ continue;
126
+ }
127
+ // extra height or width, minimize wasted area..
128
+ if (h <= bin.maxh && w <= bin.maxw) {
129
+ waste = (bin.maxw * bin.maxh) - (w * h);
130
+ if (waste < best.waste) {
131
+ best.waste = waste;
132
+ best.freebin = i;
133
+ }
134
+ }
135
+ }
136
+ // Next find the best shelf..
137
+ for (i = 0; i < this.shelves.length; i++) {
138
+ shelf = this.shelves[i];
139
+ y += shelf.h;
140
+ // not enough width on this shelf, skip it..
141
+ if (w > shelf.free) {
142
+ continue;
143
+ }
144
+ // exactly the right height, pack it..
145
+ if (h === shelf.h) {
146
+ return this.allocShelf(i, w, h, id);
147
+ }
148
+ // not enough height, skip it..
149
+ if (h > shelf.h) {
150
+ continue;
151
+ }
152
+ // extra height, minimize wasted area..
153
+ if (h < shelf.h) {
154
+ waste = (shelf.h - h) * w;
155
+ if (waste < best.waste) {
156
+ best.freebin = -1;
157
+ best.waste = waste;
158
+ best.shelf = i;
159
+ }
160
+ }
161
+ }
162
+ if (best.freebin !== -1) {
163
+ return this.allocFreebin(best.freebin, w, h, id);
164
+ }
165
+ if (best.shelf !== -1) {
166
+ return this.allocShelf(best.shelf, w, h, id);
167
+ }
168
+ // No free bins or shelves.. add shelf..
169
+ if (h <= (this.h - y) && w <= this.w) {
170
+ shelf = new Shelf(y, this.w, h);
171
+ return this.allocShelf(this.shelves.push(shelf) - 1, w, h, id);
172
+ }
173
+ // No room for more shelves..
174
+ // If `autoResize` option is set, grow the sprite as follows:
175
+ // * double whichever sprite dimension is smaller (`w1` or `h1`)
176
+ // * if sprite dimensions are equal, grow width before height
177
+ // * accomodate very large bin requests (big `w` or `h`)
178
+ if (this.autoResize) {
179
+ var h1, h2, w1, w2;
180
+ h1 = h2 = this.h;
181
+ w1 = w2 = this.w;
182
+ if (w1 <= h1 || w > w1) { // grow width..
183
+ w2 = Math.max(w, w1) * 2;
184
+ }
185
+ if (h1 < w1 || h > h1) { // grow height..
186
+ h2 = Math.max(h, h1) * 2;
187
+ }
188
+ this.resize(w2, h2);
189
+ return this.packOne(w, h, id); // retry
190
+ }
191
+ return null;
192
+ };
193
+ /**
194
+ * Called by packOne() to allocate a bin by reusing an existing freebin
195
+ *
196
+ * @private
197
+ * @param {number} index Index into the `this.freebins` array
198
+ * @param {number} w Width of the bin to allocate
199
+ * @param {number} h Height of the bin to allocate
200
+ * @param {number|string} id Unique identifier for this bin
201
+ * @returns {Bin} Bin object with `id`, `x`, `y`, `w`, `h` properties
202
+ * @example
203
+ * var bin = sprite.allocFreebin(0, 12, 16, 'a');
204
+ */
205
+ ShelfPack.prototype.allocFreebin = function (index, w, h, id) {
206
+ var bin = this.freebins.splice(index, 1)[0];
207
+ bin.id = id;
208
+ bin.w = w;
209
+ bin.h = h;
210
+ bin.refcount = 0;
211
+ this.bins[id] = bin;
212
+ this.ref(bin);
213
+ return bin;
214
+ };
215
+ /**
216
+ * Called by `packOne() to allocate bin on an existing shelf
217
+ *
218
+ * @private
219
+ * @param {number} index Index into the `this.shelves` array
220
+ * @param {number} w Width of the bin to allocate
221
+ * @param {number} h Height of the bin to allocate
222
+ * @param {number|string} id Unique identifier for this bin
223
+ * @returns {Bin} Bin object with `id`, `x`, `y`, `w`, `h` properties
224
+ * @example
225
+ * var results = sprite.allocShelf(0, 12, 16, 'a');
226
+ */
227
+ ShelfPack.prototype.allocShelf = function (index, w, h, id) {
228
+ var shelf = this.shelves[index];
229
+ var bin = shelf.alloc(w, h, id);
230
+ this.bins[id] = bin;
231
+ this.ref(bin);
232
+ return bin;
233
+ };
234
+ /**
235
+ * Shrink the width/height of the sprite to the bare minimum.
236
+ * Since shelf-pack doubles first width, then height when running out of shelf space
237
+ * this can result in fairly large unused space both in width and height if that happens
238
+ * towards the end of bin packing.
239
+ */
240
+ ShelfPack.prototype.shrink = function () {
241
+ if (this.shelves.length > 0) {
242
+ var w2 = 0;
243
+ var h2 = 0;
244
+ for (var j = 0; j < this.shelves.length; j++) {
245
+ var shelf = this.shelves[j];
246
+ h2 += shelf.h;
247
+ w2 = Math.max(shelf.w - shelf.free, w2);
248
+ }
249
+ this.resize(w2, h2);
250
+ }
251
+ };
252
+ /**
253
+ * Return a packed bin given its id, or undefined if the id is not found
254
+ *
255
+ * @param {number|string} id Unique identifier for this bin,
256
+ * @returns {Bin} The requested bin, or undefined if not yet packed
257
+ * @example
258
+ * var b = sprite.getBin('a');
259
+ */
260
+ ShelfPack.prototype.getBin = function (id) {
261
+ return this.bins[id];
262
+ };
263
+ /**
264
+ * Increment the ref count of a bin and update statistics.
265
+ *
266
+ * @param {Bin} bin Bin instance
267
+ * @returns {number} New refcount of the bin
268
+ * @example
269
+ * var bin = sprite.getBin('a');
270
+ * sprite.ref(bin);
271
+ */
272
+ ShelfPack.prototype.ref = function (bin) {
273
+ if (++bin.refcount === 1) { // a new Bin.. record height in stats historgram..
274
+ var h = bin.h;
275
+ this.stats[h] = (this.stats[h] | 0) + 1;
276
+ }
277
+ return bin.refcount;
278
+ };
279
+ /**
280
+ * Decrement the ref count of a bin and update statistics.
281
+ * The bin will be automatically marked as free space once the refcount reaches 0.
282
+ *
283
+ * @param {Bin} bin Bin instance
284
+ * @returns {number} New refcount of the bin
285
+ * @example
286
+ * var bin = sprite.getBin('a');
287
+ * sprite.unref(bin);
288
+ */
289
+ ShelfPack.prototype.unref = function (bin) {
290
+ if (bin.refcount === 0) {
291
+ return 0;
292
+ }
293
+ if (--bin.refcount === 0) {
294
+ this.stats[bin.h]--;
295
+ delete this.bins[bin.id];
296
+ this.freebins.push(bin);
297
+ }
298
+ return bin.refcount;
299
+ };
300
+ /**
301
+ * Clear the sprite. Resets everything and resets statistics.
302
+ *
303
+ * @example
304
+ * sprite.clear();
305
+ */
306
+ ShelfPack.prototype.clear = function () {
307
+ this.shelves = [];
308
+ this.freebins = [];
309
+ this.stats = {};
310
+ this.bins = {};
311
+ this.maxId = 0;
312
+ };
313
+ /**
314
+ * Resize the sprite.
315
+ *
316
+ * @param {number} w Requested new sprite width
317
+ * @param {number} h Requested new sprite height
318
+ * @returns {boolean} `true` if resize succeeded, `false` if failed
319
+ * @example
320
+ * sprite.resize(256, 256);
321
+ */
322
+ ShelfPack.prototype.resize = function (w, h) {
323
+ this.w = w;
324
+ this.h = h;
325
+ for (var i = 0; i < this.shelves.length; i++) {
326
+ this.shelves[i].resize(w);
327
+ }
328
+ return true;
329
+ };
330
+ /**
331
+ * Create a new Shelf.
332
+ *
333
+ * @private
334
+ * @class Shelf
335
+ * @param {number} y Top coordinate of the new shelf
336
+ * @param {number} w Width of the new shelf
337
+ * @param {number} h Height of the new shelf
338
+ * @example
339
+ * var shelf = new Shelf(64, 512, 24);
340
+ */
341
+ function Shelf(y, w, h) {
342
+ this.x = 0;
343
+ this.y = y;
344
+ this.w = this.free = w;
345
+ this.h = h;
346
+ }
347
+ /**
348
+ * Allocate a single bin into the shelf.
349
+ *
350
+ * @private
351
+ * @param {number} w Width of the bin to allocate
352
+ * @param {number} h Height of the bin to allocate
353
+ * @param {number|string} id Unique id of the bin to allocate
354
+ * @returns {Bin} Bin object with `id`, `x`, `y`, `w`, `h` properties, or `null` if allocation failed
355
+ * @example
356
+ * shelf.alloc(12, 16, 'a');
357
+ */
358
+ Shelf.prototype.alloc = function (w, h, id) {
359
+ if (w > this.free || h > this.h) {
360
+ return null;
361
+ }
362
+ var x = this.x;
363
+ this.x += w;
364
+ this.free -= w;
365
+ return new Bin(id, x, this.y, w, h, w, this.h);
366
+ };
367
+ /**
368
+ * Resize the shelf.
369
+ *
370
+ * @private
371
+ * @param {number} w Requested new width of the shelf
372
+ * @returns {boolean} true
373
+ * @example
374
+ * shelf.resize(512);
375
+ */
376
+ Shelf.prototype.resize = function (w) {
377
+ this.free += (w - this.w);
378
+ this.w = w;
379
+ return true;
380
+ };
381
+ /**
382
+ * Create a new Bin object.
383
+ *
384
+ * @class Bin
385
+ * @param {number|string} id Unique id of the bin
386
+ * @param {number} x Left coordinate of the bin
387
+ * @param {number} y Top coordinate of the bin
388
+ * @param {number} w Width of the bin
389
+ * @param {number} h Height of the bin
390
+ * @param {number} [maxw] Max width of the bin (defaults to `w` if not provided)
391
+ * @param {number} [maxh] Max height of the bin (defaults to `h` if not provided)
392
+ * @example
393
+ * var bin = new Bin('a', 0, 0, 12, 16);
394
+ */
395
+ function Bin(id, x, y, w, h, maxw, maxh) {
396
+ this.id = id;
397
+ this.x = x;
398
+ this.y = y;
399
+ this.w = w;
400
+ this.h = h;
401
+ this.maxw = maxw || w;
402
+ this.maxh = maxh || h;
403
+ this.refcount = 0;
404
+ }
405
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.js"],"names":[],"mappings":"AAAA,eAAe,SAAS,CAAC;AAGzB;;;;;;;;;;;;;GAaG;AACH,SAAS,SAAS,CAAC,CAAC,EAAE,CAAC,EAAE,OAAO;IAC5B,OAAO,GAAG,OAAO,IAAI,EAAE,CAAC;IACxB,IAAI,CAAC,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC;IACjB,IAAI,CAAC,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC;IACjB,IAAI,CAAC,UAAU,GAAG,CAAC,CAAC,OAAO,CAAC,UAAU,CAAC;IACvC,IAAI,CAAC,OAAO,GAAG,EAAE,CAAC;IAClB,IAAI,CAAC,QAAQ,GAAG,EAAE,CAAC;IACnB,IAAI,CAAC,KAAK,GAAG,EAAE,CAAC;IAChB,IAAI,CAAC,IAAI,GAAG,EAAE,CAAC;IACf,IAAI,CAAC,KAAK,GAAG,CAAC,CAAC;AACnB,CAAC;AAED;;;;;;GAMG;AAGH;;;;;;GAMG;AAGH;;;;;;;;;;;;;;;GAeG;AACH,SAAS,CAAC,SAAS,CAAC,IAAI,GAAG,UAAS,IAAI,EAAE,OAAO;IAC7C,IAAI,GAAG,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IACvB,OAAO,GAAG,OAAO,IAAI,EAAE,CAAC;IAExB,IAAI,OAAO,GAAG,EAAE,EACZ,CAAC,EAAE,CAAC,EAAE,EAAE,EAAE,UAAU,CAAC;IAEzB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACnC,CAAC,GAAI,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;QAChC,CAAC,GAAI,IAAI,CAA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 -0,0 +1,24 @@
1
+ {
2
+ "name": "@mapka/shelf-pack",
3
+ "version": "0.4.1",
4
+ "description": "A 2D rectangular bin packing data structure that uses the Shelf Best Height Fit heuristic.",
5
+ "main": "./lib/index.js",
6
+ "license": "ISC",
7
+ "type": "module",
8
+ "sideEffects": false,
9
+ "publishConfig": {
10
+ "access": "public"
11
+ },
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "https://github.com/mapka-dev/sprites.git"
15
+ },
16
+ "files": [
17
+ "src/",
18
+ "lib/",
19
+ "LICENSE",
20
+ "!**/__tests__/",
21
+ "!lib/buildInfo.json"
22
+ ],
23
+ "gitHead": "5ff8c7554e4a4eb2349337c662bb853b588f7e45"
24
+ }
package/src/index.js ADDED
@@ -0,0 +1,463 @@
1
+ export default ShelfPack;
2
+
3
+
4
+ /**
5
+ * Create a new ShelfPack bin allocator.
6
+ *
7
+ * Uses the Shelf Best Height Fit algorithm from
8
+ * http://clb.demon.fi/files/RectangleBinPack.pdf
9
+ *
10
+ * @class ShelfPack
11
+ * @param {number} [w=64] Initial width of the sprite
12
+ * @param {number} [h=64] Initial width of the sprite
13
+ * @param {Object} [options]
14
+ * @param {boolean} [options.autoResize=false] If `true`, the sprite will automatically grow
15
+ * @example
16
+ * var sprite = new ShelfPack(64, 64, { autoResize: false });
17
+ */
18
+ function ShelfPack(w, h, options) {
19
+ options = options || {};
20
+ this.w = w || 64;
21
+ this.h = h || 64;
22
+ this.autoResize = !!options.autoResize;
23
+ this.shelves = [];
24
+ this.freebins = [];
25
+ this.stats = {};
26
+ this.bins = {};
27
+ this.maxId = 0;
28
+ }
29
+
30
+ /**
31
+ * Bin object with `id`, `width`, `height` properties
32
+ * @typedef {Object} BinShorthand
33
+ * @property {string} id Unique identifier for this bin
34
+ * @property {number} w Width of the bin
35
+ * @property {number} h Height of the bin
36
+ */
37
+
38
+
39
+ /**
40
+ * Bin object with `id`, `w`, `h` properties
41
+ * @typedef {Object} Bin
42
+ * @property {string} id Unique identifier for this bin
43
+ * @property {number} width Width of the bin
44
+ * @property {number} height Height of the bin
45
+ */
46
+
47
+
48
+ /**
49
+ * Batch pack multiple bins into the sprite.
50
+ *
51
+ * @param {Object[]} bins Array of requested bins - each object should have `width`, `height` (or `w`, `h`) properties
52
+ * @param {Object} [options]
53
+ * @param {boolean} [options.inPlace=false] If `true`, the supplied bin objects will be updated inplace with `x` and `y` properties
54
+ * @returns {Bin[]} Array of allocated Bins - each Bin is an object with `id`, `x`, `y`, `w`, `h` properties
55
+ * @noto Mutate input bins
56
+ * @example
57
+ * var bins = [
58
+ * { id: 1, w: 12, h: 12 },
59
+ * { id: 2, w: 12, h: 16 },
60
+ * { id: 3, w: 12, h: 24 }
61
+ * ];
62
+ * var results = sprite.pack(bins, { inPlace: false });
63
+ */
64
+ ShelfPack.prototype.pack = function(bins, options) {
65
+ bins = [].concat(bins);
66
+ options = options || {};
67
+
68
+ var results = [],
69
+ w, h, id, allocation;
70
+
71
+ for (var i = 0; i < bins.length; i++) {
72
+ w = bins[i].w || bins[i].width;
73
+ h = bins[i].h || bins[i].height;
74
+ id = bins[i].id;
75
+
76
+ if (w && h) {
77
+ allocation = this.packOne(w, h, id);
78
+ if (!allocation) {
79
+ continue;
80
+ }
81
+ if (options.inPlace) {
82
+ bins[i].x = allocation.x;
83
+ bins[i].y = allocation.y;
84
+ bins[i].id = allocation.id;
85
+ }
86
+ results.push(allocation);
87
+ }
88
+ }
89
+
90
+ this.shrink();
91
+
92
+ return results;
93
+ };
94
+
95
+
96
+ /**
97
+ * Pack a single bin into the sprite.
98
+ *
99
+ * Each bin will have a unique identitifer.
100
+ * If no identifier is supplied in the `id` parameter, one will be created.
101
+ * Note: The supplied `id` is used as an object index, so numeric values are fastest!
102
+ *
103
+ * Bins are automatically refcounted (i.e. a newly packed Bin will have a refcount of 1).
104
+ * When a bin is no longer needed, use the `ShelfPack.unref` function to mark it
105
+ * as unused. When a Bin's refcount decrements to 0, the Bin will be marked
106
+ * as free and its space may be reused by the packing code.
107
+ *
108
+ * @param {number} w Width of the bin to allocate
109
+ * @param {number} h Height of the bin to allocate
110
+ * @param {number|string} [id] Unique identifier for this bin, (if unsupplied, assume it's a new bin and create an id)
111
+ * @returns {Bin} Bin object with `id`, `x`, `y`, `w`, `h` properties, or `null` if allocation failed
112
+ * @example
113
+ * var results = sprite.packOne(12, 16, 'a');
114
+ */
115
+ ShelfPack.prototype.packOne = function(w, h, id) {
116
+ var best = { freebin: -1, shelf: -1, waste: Infinity },
117
+ y = 0,
118
+ bin, shelf, waste, i;
119
+
120
+ // if id was supplied, attempt a lookup..
121
+ if (typeof id === 'string' || typeof id === 'number') {
122
+ bin = this.getBin(id);
123
+ if (bin) { // we packed this bin already
124
+ this.ref(bin);
125
+ return bin;
126
+ }
127
+ if (typeof id === 'number') {
128
+ this.maxId = Math.max(id, this.maxId);
129
+ }
130
+ } else {
131
+ id = ++this.maxId;
132
+ }
133
+
134
+ // First try to reuse a free bin..
135
+ for (i = 0; i < this.freebins.length; i++) {
136
+ bin = this.freebins[i];
137
+
138
+ // exactly the right height and width, use it..
139
+ if (h === bin.maxh && w === bin.maxw) {
140
+ return this.allocFreebin(i, w, h, id);
141
+ }
142
+ // not enough height or width, skip it..
143
+ if (h > bin.maxh || w > bin.maxw) {
144
+ continue;
145
+ }
146
+ // extra height or width, minimize wasted area..
147
+ if (h <= bin.maxh && w <= bin.maxw) {
148
+ waste = (bin.maxw * bin.maxh) - (w * h);
149
+ if (waste < best.waste) {
150
+ best.waste = waste;
151
+ best.freebin = i;
152
+ }
153
+ }
154
+ }
155
+
156
+ // Next find the best shelf..
157
+ for (i = 0; i < this.shelves.length; i++) {
158
+ shelf = this.shelves[i];
159
+ y += shelf.h;
160
+
161
+ // not enough width on this shelf, skip it..
162
+ if (w > shelf.free) {
163
+ continue;
164
+ }
165
+ // exactly the right height, pack it..
166
+ if (h === shelf.h) {
167
+ return this.allocShelf(i, w, h, id);
168
+ }
169
+ // not enough height, skip it..
170
+ if (h > shelf.h) {
171
+ continue;
172
+ }
173
+ // extra height, minimize wasted area..
174
+ if (h < shelf.h) {
175
+ waste = (shelf.h - h) * w;
176
+ if (waste < best.waste) {
177
+ best.freebin = -1;
178
+ best.waste = waste;
179
+ best.shelf = i;
180
+ }
181
+ }
182
+ }
183
+
184
+ if (best.freebin !== -1) {
185
+ return this.allocFreebin(best.freebin, w, h, id);
186
+ }
187
+
188
+ if (best.shelf !== -1) {
189
+ return this.allocShelf(best.shelf, w, h, id);
190
+ }
191
+
192
+ // No free bins or shelves.. add shelf..
193
+ if (h <= (this.h - y) && w <= this.w) {
194
+ shelf = new Shelf(y, this.w, h);
195
+ return this.allocShelf(this.shelves.push(shelf) - 1, w, h, id);
196
+ }
197
+
198
+ // No room for more shelves..
199
+ // If `autoResize` option is set, grow the sprite as follows:
200
+ // * double whichever sprite dimension is smaller (`w1` or `h1`)
201
+ // * if sprite dimensions are equal, grow width before height
202
+ // * accomodate very large bin requests (big `w` or `h`)
203
+ if (this.autoResize) {
204
+ var h1, h2, w1, w2;
205
+
206
+ h1 = h2 = this.h;
207
+ w1 = w2 = this.w;
208
+
209
+ if (w1 <= h1 || w > w1) { // grow width..
210
+ w2 = Math.max(w, w1) * 2;
211
+ }
212
+ if (h1 < w1 || h > h1) { // grow height..
213
+ h2 = Math.max(h, h1) * 2;
214
+ }
215
+
216
+ this.resize(w2, h2);
217
+ return this.packOne(w, h, id); // retry
218
+ }
219
+
220
+ return null;
221
+ };
222
+
223
+
224
+ /**
225
+ * Called by packOne() to allocate a bin by reusing an existing freebin
226
+ *
227
+ * @private
228
+ * @param {number} index Index into the `this.freebins` array
229
+ * @param {number} w Width of the bin to allocate
230
+ * @param {number} h Height of the bin to allocate
231
+ * @param {number|string} id Unique identifier for this bin
232
+ * @returns {Bin} Bin object with `id`, `x`, `y`, `w`, `h` properties
233
+ * @example
234
+ * var bin = sprite.allocFreebin(0, 12, 16, 'a');
235
+ */
236
+ ShelfPack.prototype.allocFreebin = function (index, w, h, id) {
237
+ var bin = this.freebins.splice(index, 1)[0];
238
+ bin.id = id;
239
+ bin.w = w;
240
+ bin.h = h;
241
+ bin.refcount = 0;
242
+ this.bins[id] = bin;
243
+ this.ref(bin);
244
+ return bin;
245
+ };
246
+
247
+
248
+ /**
249
+ * Called by `packOne() to allocate bin on an existing shelf
250
+ *
251
+ * @private
252
+ * @param {number} index Index into the `this.shelves` array
253
+ * @param {number} w Width of the bin to allocate
254
+ * @param {number} h Height of the bin to allocate
255
+ * @param {number|string} id Unique identifier for this bin
256
+ * @returns {Bin} Bin object with `id`, `x`, `y`, `w`, `h` properties
257
+ * @example
258
+ * var results = sprite.allocShelf(0, 12, 16, 'a');
259
+ */
260
+ ShelfPack.prototype.allocShelf = function(index, w, h, id) {
261
+ var shelf = this.shelves[index];
262
+ var bin = shelf.alloc(w, h, id);
263
+ this.bins[id] = bin;
264
+ this.ref(bin);
265
+ return bin;
266
+ };
267
+
268
+
269
+ /**
270
+ * Shrink the width/height of the sprite to the bare minimum.
271
+ * Since shelf-pack doubles first width, then height when running out of shelf space
272
+ * this can result in fairly large unused space both in width and height if that happens
273
+ * towards the end of bin packing.
274
+ */
275
+ ShelfPack.prototype.shrink = function() {
276
+ if (this.shelves.length > 0) {
277
+ var w2 = 0;
278
+ var h2 = 0;
279
+
280
+ for (var j = 0; j < this.shelves.length; j++) {
281
+ var shelf = this.shelves[j];
282
+ h2 += shelf.h;
283
+ w2 = Math.max(shelf.w - shelf.free, w2);
284
+ }
285
+
286
+ this.resize(w2, h2);
287
+ }
288
+ };
289
+
290
+
291
+ /**
292
+ * Return a packed bin given its id, or undefined if the id is not found
293
+ *
294
+ * @param {number|string} id Unique identifier for this bin,
295
+ * @returns {Bin} The requested bin, or undefined if not yet packed
296
+ * @example
297
+ * var b = sprite.getBin('a');
298
+ */
299
+ ShelfPack.prototype.getBin = function(id) {
300
+ return this.bins[id];
301
+ };
302
+
303
+
304
+ /**
305
+ * Increment the ref count of a bin and update statistics.
306
+ *
307
+ * @param {Bin} bin Bin instance
308
+ * @returns {number} New refcount of the bin
309
+ * @example
310
+ * var bin = sprite.getBin('a');
311
+ * sprite.ref(bin);
312
+ */
313
+ ShelfPack.prototype.ref = function(bin) {
314
+ if (++bin.refcount === 1) { // a new Bin.. record height in stats historgram..
315
+ var h = bin.h;
316
+ this.stats[h] = (this.stats[h] | 0) + 1;
317
+ }
318
+
319
+ return bin.refcount;
320
+ };
321
+
322
+
323
+ /**
324
+ * Decrement the ref count of a bin and update statistics.
325
+ * The bin will be automatically marked as free space once the refcount reaches 0.
326
+ *
327
+ * @param {Bin} bin Bin instance
328
+ * @returns {number} New refcount of the bin
329
+ * @example
330
+ * var bin = sprite.getBin('a');
331
+ * sprite.unref(bin);
332
+ */
333
+ ShelfPack.prototype.unref = function(bin) {
334
+ if (bin.refcount === 0) {
335
+ return 0;
336
+ }
337
+
338
+ if (--bin.refcount === 0) {
339
+ this.stats[bin.h]--;
340
+ delete this.bins[bin.id];
341
+ this.freebins.push(bin);
342
+ }
343
+
344
+ return bin.refcount;
345
+ };
346
+
347
+
348
+ /**
349
+ * Clear the sprite. Resets everything and resets statistics.
350
+ *
351
+ * @example
352
+ * sprite.clear();
353
+ */
354
+ ShelfPack.prototype.clear = function() {
355
+ this.shelves = [];
356
+ this.freebins = [];
357
+ this.stats = {};
358
+ this.bins = {};
359
+ this.maxId = 0;
360
+ };
361
+
362
+
363
+ /**
364
+ * Resize the sprite.
365
+ *
366
+ * @param {number} w Requested new sprite width
367
+ * @param {number} h Requested new sprite height
368
+ * @returns {boolean} `true` if resize succeeded, `false` if failed
369
+ * @example
370
+ * sprite.resize(256, 256);
371
+ */
372
+ ShelfPack.prototype.resize = function(w, h) {
373
+ this.w = w;
374
+ this.h = h;
375
+ for (var i = 0; i < this.shelves.length; i++) {
376
+ this.shelves[i].resize(w);
377
+ }
378
+ return true;
379
+ };
380
+
381
+
382
+ /**
383
+ * Create a new Shelf.
384
+ *
385
+ * @private
386
+ * @class Shelf
387
+ * @param {number} y Top coordinate of the new shelf
388
+ * @param {number} w Width of the new shelf
389
+ * @param {number} h Height of the new shelf
390
+ * @example
391
+ * var shelf = new Shelf(64, 512, 24);
392
+ */
393
+ function Shelf(y, w, h) {
394
+ this.x = 0;
395
+ this.y = y;
396
+ this.w = this.free = w;
397
+ this.h = h;
398
+ }
399
+
400
+
401
+ /**
402
+ * Allocate a single bin into the shelf.
403
+ *
404
+ * @private
405
+ * @param {number} w Width of the bin to allocate
406
+ * @param {number} h Height of the bin to allocate
407
+ * @param {number|string} id Unique id of the bin to allocate
408
+ * @returns {Bin} Bin object with `id`, `x`, `y`, `w`, `h` properties, or `null` if allocation failed
409
+ * @example
410
+ * shelf.alloc(12, 16, 'a');
411
+ */
412
+ Shelf.prototype.alloc = function(w, h, id) {
413
+ if (w > this.free || h > this.h) {
414
+ return null;
415
+ }
416
+ var x = this.x;
417
+ this.x += w;
418
+ this.free -= w;
419
+ return new Bin(id, x, this.y, w, h, w, this.h);
420
+ };
421
+
422
+
423
+ /**
424
+ * Resize the shelf.
425
+ *
426
+ * @private
427
+ * @param {number} w Requested new width of the shelf
428
+ * @returns {boolean} true
429
+ * @example
430
+ * shelf.resize(512);
431
+ */
432
+ Shelf.prototype.resize = function(w) {
433
+ this.free += (w - this.w);
434
+ this.w = w;
435
+ return true;
436
+ };
437
+
438
+
439
+ /**
440
+ * Create a new Bin object.
441
+ *
442
+ * @class Bin
443
+ * @param {number|string} id Unique id of the bin
444
+ * @param {number} x Left coordinate of the bin
445
+ * @param {number} y Top coordinate of the bin
446
+ * @param {number} w Width of the bin
447
+ * @param {number} h Height of the bin
448
+ * @param {number} [maxw] Max width of the bin (defaults to `w` if not provided)
449
+ * @param {number} [maxh] Max height of the bin (defaults to `h` if not provided)
450
+ * @example
451
+ * var bin = new Bin('a', 0, 0, 12, 16);
452
+ */
453
+ function Bin(id, x, y, w, h, maxw, maxh) {
454
+ this.id = id;
455
+ this.x = x;
456
+ this.y = y;
457
+ this.w = w;
458
+ this.h = h;
459
+ this.maxw = maxw || w;
460
+ this.maxh = maxh || h;
461
+ this.refcount = 0;
462
+ }
463
+