minerender 2.1.0-alpha.8 → 2.1.0-alpha.9

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/dist/bundle.js CHANGED
@@ -38,14 +38,6 @@ var MineRender = (() => {
38
38
  mod
39
39
  ));
40
40
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
41
- var __decorateClass = (decorators, target, key, kind) => {
42
- var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
43
- for (var i4 = decorators.length - 1, decorator; i4 >= 0; i4--)
44
- if (decorator = decorators[i4])
45
- result = (kind ? decorator(target, key, result) : decorator(result)) || result;
46
- if (kind && result) __defProp(target, key, result);
47
- return result;
48
- };
49
41
 
50
42
  // ../../node_modules/esbuild-plugin-polyfill-node/polyfills/__dirname.js
51
43
  var init_dirname = __esm({
@@ -47262,11 +47254,14 @@ return ${compiler2.callType("value", tagType)}
47262
47254
  static open(name2) {
47263
47255
  return Env.provider.openCache(name2, _PersistentCache.VERSION);
47264
47256
  }
47257
+ /** Loads a missing entry and stores only non-nullish results. */
47265
47258
  async getOrLoad(key, loader) {
47266
47259
  let v5 = await this.get(key);
47267
47260
  if (typeof v5 === "undefined" || v5 === null) {
47268
47261
  v5 = await loader(key);
47269
- await this.put(key, v5);
47262
+ if (typeof v5 !== "undefined" && v5 !== null) {
47263
+ await this.put(key, v5);
47264
+ }
47270
47265
  }
47271
47266
  return v5;
47272
47267
  }
@@ -68077,7 +68072,10 @@ return ${compiler2.callType("value", tagType)}
68077
68072
  init_process2();
68078
68073
 
68079
68074
  // src/cache/Caching.ts
68080
- var Caching = class {
68075
+ var _Caching = class _Caching {
68076
+ static createAssetCache() {
68077
+ return Caches.builder().expireAfterWrite(Time.minutes(10)).expireAfterAccess(Time.minutes(5)).expirationInterval(Time.seconds(30)).buildAsync();
68078
+ }
68081
68079
  /** Every cache above, so clear()/end() can never fall out of sync with the field list again. */
68082
68080
  static get all() {
68083
68081
  return [
@@ -68094,7 +68092,10 @@ return ${compiler2.callType("value", tagType)}
68094
68092
  this.rawModelCache,
68095
68093
  this.mergedModelCache,
68096
68094
  this.modelTextureAtlasCache,
68097
- this.blockStateCache
68095
+ this.blockStateCache,
68096
+ this.listAssetCache,
68097
+ this.defaultBlockStatesCache,
68098
+ this.entityModelsCache
68098
68099
  ];
68099
68100
  }
68100
68101
  static clear() {
@@ -68120,20 +68121,24 @@ return ${compiler2.callType("value", tagType)}
68120
68121
  };
68121
68122
  }
68122
68123
  };
68123
- Caching.rawImageCache = Caches.builder().expireAfterWrite(Time.minutes(10)).expireAfterAccess(Time.minutes(5)).expirationInterval(Time.seconds(5)).buildAsync();
68124
- Caching.imageDataCache = Caches.builder().expireAfterWrite(Time.minutes(10)).expireAfterAccess(Time.minutes(5)).expirationInterval(Time.seconds(10)).buildAsync();
68125
- Caching.canvasImageDataCache = Caches.builder().expireAfterWrite(Time.minutes(10)).expireAfterAccess(Time.minutes(5)).expirationInterval(Time.seconds(10)).buildAsync();
68126
- Caching.wrappedImageCache = Caches.builder().expireAfterWrite(Time.minutes(10)).expireAfterAccess(Time.minutes(5)).expirationInterval(Time.seconds(10)).buildAsync();
68127
- Caching.boxGeometryCache = Caches.builder().expireAfterWrite(Time.minutes(10)).expireAfterAccess(Time.minutes(5)).expirationInterval(Time.seconds(20)).build();
68128
- Caching.textureCache = Caches.builder().expireAfterWrite(Time.minutes(10)).expireAfterAccess(Time.minutes(5)).expirationInterval(Time.seconds(30)).build();
68129
- Caching.materialCache = Caches.builder().expireAfterWrite(Time.minutes(10)).expireAfterAccess(Time.minutes(5)).expirationInterval(Time.seconds(30)).build();
68130
- Caching.boxMeshCache = Caches.builder().expireAfterWrite(Time.minutes(10)).expireAfterAccess(Time.minutes(5)).expirationInterval(Time.seconds(30)).build();
68131
- Caching.textureAssetCache = Caches.builder().expireAfterWrite(Time.minutes(10)).expireAfterAccess(Time.minutes(5)).expirationInterval(Time.seconds(30)).buildAsync();
68132
- Caching.textureMetaCache = Caches.builder().expireAfterWrite(Time.minutes(10)).expireAfterAccess(Time.minutes(5)).expirationInterval(Time.seconds(30)).buildAsync();
68133
- Caching.rawModelCache = Caches.builder().expireAfterWrite(Time.minutes(10)).expireAfterAccess(Time.minutes(5)).expirationInterval(Time.seconds(30)).buildAsync();
68134
- Caching.mergedModelCache = Caches.builder().expireAfterWrite(Time.minutes(10)).expireAfterAccess(Time.minutes(5)).expirationInterval(Time.seconds(30)).buildAsync();
68135
- Caching.modelTextureAtlasCache = Caches.builder().expireAfterWrite(Time.minutes(10)).expireAfterAccess(Time.minutes(5)).expirationInterval(Time.seconds(30)).buildAsync();
68136
- Caching.blockStateCache = Caches.builder().expireAfterWrite(Time.minutes(10)).expireAfterAccess(Time.minutes(5)).expirationInterval(Time.seconds(30)).buildAsync();
68124
+ _Caching.rawImageCache = Caches.builder().expireAfterWrite(Time.minutes(10)).expireAfterAccess(Time.minutes(5)).expirationInterval(Time.seconds(5)).buildAsync();
68125
+ _Caching.imageDataCache = Caches.builder().expireAfterWrite(Time.minutes(10)).expireAfterAccess(Time.minutes(5)).expirationInterval(Time.seconds(10)).buildAsync();
68126
+ _Caching.canvasImageDataCache = Caches.builder().expireAfterWrite(Time.minutes(10)).expireAfterAccess(Time.minutes(5)).expirationInterval(Time.seconds(10)).buildAsync();
68127
+ _Caching.wrappedImageCache = Caches.builder().expireAfterWrite(Time.minutes(10)).expireAfterAccess(Time.minutes(5)).expirationInterval(Time.seconds(10)).buildAsync();
68128
+ _Caching.boxGeometryCache = Caches.builder().expireAfterWrite(Time.minutes(10)).expireAfterAccess(Time.minutes(5)).expirationInterval(Time.seconds(20)).build();
68129
+ _Caching.textureCache = Caches.builder().expireAfterWrite(Time.minutes(10)).expireAfterAccess(Time.minutes(5)).expirationInterval(Time.seconds(30)).build();
68130
+ _Caching.materialCache = Caches.builder().expireAfterWrite(Time.minutes(10)).expireAfterAccess(Time.minutes(5)).expirationInterval(Time.seconds(30)).build();
68131
+ _Caching.boxMeshCache = Caches.builder().expireAfterWrite(Time.minutes(10)).expireAfterAccess(Time.minutes(5)).expirationInterval(Time.seconds(30)).build();
68132
+ _Caching.textureAssetCache = Caches.builder().expireAfterWrite(Time.minutes(10)).expireAfterAccess(Time.minutes(5)).expirationInterval(Time.seconds(30)).buildAsync();
68133
+ _Caching.textureMetaCache = Caches.builder().expireAfterWrite(Time.minutes(10)).expireAfterAccess(Time.minutes(5)).expirationInterval(Time.seconds(30)).buildAsync();
68134
+ _Caching.rawModelCache = Caches.builder().expireAfterWrite(Time.minutes(10)).expireAfterAccess(Time.minutes(5)).expirationInterval(Time.seconds(30)).buildAsync();
68135
+ _Caching.mergedModelCache = Caches.builder().expireAfterWrite(Time.minutes(10)).expireAfterAccess(Time.minutes(5)).expirationInterval(Time.seconds(30)).buildAsync();
68136
+ _Caching.modelTextureAtlasCache = Caches.builder().expireAfterWrite(Time.minutes(10)).expireAfterAccess(Time.minutes(5)).expirationInterval(Time.seconds(30)).buildAsync();
68137
+ _Caching.blockStateCache = Caches.builder().expireAfterWrite(Time.minutes(10)).expireAfterAccess(Time.minutes(5)).expirationInterval(Time.seconds(30)).buildAsync();
68138
+ _Caching.listAssetCache = _Caching.createAssetCache();
68139
+ _Caching.defaultBlockStatesCache = _Caching.createAssetCache();
68140
+ _Caching.entityModelsCache = _Caching.createAssetCache();
68141
+ var Caching = _Caching;
68137
68142
 
68138
68143
  // src/Geometries.ts
68139
68144
  var Geometries = class _Geometries {
@@ -68996,95 +69001,6 @@ return ${compiler2.callType("value", tagType)}
68996
69001
  }
68997
69002
  };
68998
69003
 
68999
- // ../../node_modules/typescript-memoize/dist/es2015/memoize-decorator.js
69000
- init_dirname();
69001
- init_buffer2();
69002
- init_process2();
69003
- function Memoize(args) {
69004
- let hashFunction;
69005
- let duration;
69006
- let tags;
69007
- if (typeof args === "object") {
69008
- hashFunction = args.hashFunction;
69009
- duration = args.expiring;
69010
- tags = args.tags;
69011
- } else {
69012
- hashFunction = args;
69013
- }
69014
- return (target, propertyKey, descriptor) => {
69015
- if (descriptor.value != null) {
69016
- descriptor.value = getNewFunction(descriptor.value, hashFunction, duration, tags);
69017
- } else if (descriptor.get != null) {
69018
- descriptor.get = getNewFunction(descriptor.get, hashFunction, duration, tags);
69019
- } else {
69020
- throw "Only put a Memoize() decorator on a method or get accessor.";
69021
- }
69022
- };
69023
- }
69024
- var clearCacheTagsMap = /* @__PURE__ */ new Map();
69025
- function getNewFunction(originalMethod, hashFunction, duration = 0, tags) {
69026
- const propMapName = Symbol(`__memoized_map__`);
69027
- return function(...args) {
69028
- let returnedValue;
69029
- if (!this.hasOwnProperty(propMapName)) {
69030
- Object.defineProperty(this, propMapName, {
69031
- configurable: false,
69032
- enumerable: false,
69033
- writable: false,
69034
- value: /* @__PURE__ */ new Map()
69035
- });
69036
- }
69037
- let myMap = this[propMapName];
69038
- if (Array.isArray(tags)) {
69039
- for (const tag of tags) {
69040
- if (clearCacheTagsMap.has(tag)) {
69041
- clearCacheTagsMap.get(tag).push(myMap);
69042
- } else {
69043
- clearCacheTagsMap.set(tag, [myMap]);
69044
- }
69045
- }
69046
- }
69047
- if (hashFunction || args.length > 0 || duration > 0) {
69048
- let hashKey;
69049
- if (hashFunction === true) {
69050
- hashKey = args.map((a4) => a4.toString()).join("!");
69051
- } else if (hashFunction) {
69052
- hashKey = hashFunction.apply(this, args);
69053
- } else {
69054
- hashKey = args[0];
69055
- }
69056
- const timestampKey = `${hashKey}__timestamp`;
69057
- let isExpired = false;
69058
- if (duration > 0) {
69059
- if (!myMap.has(timestampKey)) {
69060
- isExpired = true;
69061
- } else {
69062
- let timestamp = myMap.get(timestampKey);
69063
- isExpired = Date.now() - timestamp > duration;
69064
- }
69065
- }
69066
- if (myMap.has(hashKey) && !isExpired) {
69067
- returnedValue = myMap.get(hashKey);
69068
- } else {
69069
- returnedValue = originalMethod.apply(this, args);
69070
- myMap.set(hashKey, returnedValue);
69071
- if (duration > 0) {
69072
- myMap.set(timestampKey, Date.now());
69073
- }
69074
- }
69075
- } else {
69076
- const hashKey = this;
69077
- if (myMap.has(hashKey)) {
69078
- returnedValue = myMap.get(hashKey);
69079
- } else {
69080
- returnedValue = originalMethod.apply(this, args);
69081
- myMap.set(hashKey, returnedValue);
69082
- }
69083
- }
69084
- return returnedValue;
69085
- };
69086
- }
69087
-
69088
69004
  // src/assets/source/parser/AssetParsers.ts
69089
69005
  init_dirname();
69090
69006
  init_buffer2();
@@ -69101,14 +69017,14 @@ return ${compiler2.callType("value", tagType)}
69101
69017
  })(AssetParser || {});
69102
69018
 
69103
69019
  // src/assets/Models.ts
69104
- var _Models = class _Models {
69020
+ var Models = class _Models {
69105
69021
  // opened lazily: touching the store at import time would hit IndexedDB/disk just for loading
69106
69022
  // the library, and would require an EnvProvider before any entry has had a chance to register
69107
69023
  static get PERSISTENT_CACHE() {
69108
69024
  return this._persistentCache ?? (this._persistentCache = PersistentCache.open("minerender-models"));
69109
69025
  }
69110
69026
  static async getItemList() {
69111
- return AssetLoader.get(new AssetKey(
69027
+ const key = new AssetKey(
69112
69028
  DEFAULT_NAMESPACE,
69113
69029
  "_list",
69114
69030
  "models",
@@ -69116,7 +69032,10 @@ return ${compiler2.callType("value", tagType)}
69116
69032
  "assets",
69117
69033
  ".json",
69118
69034
  DEFAULT_ROOT
69119
- ), "list" /* LIST */).then((r5) => r5?.files ?? []);
69035
+ );
69036
+ return Caching.listAssetCache.get(key.serialize(), () => {
69037
+ return AssetLoader.get(key, "list" /* LIST */);
69038
+ }).then((r5) => r5?.files ?? []);
69120
69039
  }
69121
69040
  static async loadAndMerge(key) {
69122
69041
  const model = await this.getRaw(key);
@@ -69163,10 +69082,6 @@ return ${compiler2.callType("value", tagType)}
69163
69082
  return this.PERSISTENT_CACHE.clear();
69164
69083
  }
69165
69084
  };
69166
- __decorateClass([
69167
- Memoize()
69168
- ], _Models, "getItemList", 1);
69169
- var Models = _Models;
69170
69085
 
69171
69086
  // src/assets/BlockStates.ts
69172
69087
  init_dirname();
@@ -69176,8 +69091,9 @@ return ${compiler2.callType("value", tagType)}
69176
69091
  static get PERSISTENT_CACHE() {
69177
69092
  return this._persistentCache ?? (this._persistentCache = PersistentCache.open("minerender-blockstates"));
69178
69093
  }
69094
+ // BlockState names are hardcoded
69179
69095
  static async getList() {
69180
- return AssetLoader.get(new AssetKey(
69096
+ const key = new AssetKey(
69181
69097
  DEFAULT_NAMESPACE,
69182
69098
  "_list",
69183
69099
  "blockstates",
@@ -69185,11 +69101,16 @@ return ${compiler2.callType("value", tagType)}
69185
69101
  "assets",
69186
69102
  ".json",
69187
69103
  DEFAULT_ROOT
69188
- ), "list" /* LIST */).then((r5) => r5?.files ?? []);
69104
+ );
69105
+ return Caching.listAssetCache.get(key.serialize(), () => {
69106
+ return AssetLoader.get(key, "list" /* LIST */);
69107
+ }).then((r5) => r5?.files ?? []);
69189
69108
  }
69190
69109
  static async getDefaultStates() {
69191
69110
  const key = AssetKey.parse("blockstates", "minerender:defaultBlockStates");
69192
- return AssetLoader.get(key, "json" /* JSON */);
69111
+ return Caching.defaultBlockStatesCache.get(key.serialize(), () => {
69112
+ return AssetLoader.get(key, "json" /* JSON */);
69113
+ });
69193
69114
  }
69194
69115
  static async getDefaultState(key) {
69195
69116
  const defaultStates = await this.getDefaultStates();
@@ -69228,12 +69149,6 @@ return ${compiler2.callType("value", tagType)}
69228
69149
  await this.PERSISTENT_CACHE.clear();
69229
69150
  }
69230
69151
  };
69231
- __decorateClass([
69232
- Memoize()
69233
- ], BlockStates, "getList", 1);
69234
- __decorateClass([
69235
- Memoize()
69236
- ], BlockStates, "getDefaultStates", 1);
69237
69152
  var DefaultBlockStates = class {
69238
69153
  };
69239
69154
 
@@ -79830,12 +79745,16 @@ return ${compiler2.callType("value", tagType)}
79830
79745
  static async getBlockEntityModels() {
79831
79746
  const key = AssetKey.parse("models", "minerender:blockEntityModels");
79832
79747
  console.log(key);
79833
- return AssetLoader.get(key, "json" /* JSON */);
79748
+ return Caching.entityModelsCache.get(key.serialize(), () => {
79749
+ return AssetLoader.get(key, "json" /* JSON */);
79750
+ });
79834
79751
  }
79835
79752
  static async getEntityModels() {
79836
79753
  const key = AssetKey.parse("models", "minerender:entityModels");
79837
79754
  console.log(key);
79838
- return AssetLoader.get(key, "json" /* JSON */);
79755
+ return Caching.entityModelsCache.get(key.serialize(), () => {
79756
+ return AssetLoader.get(key, "json" /* JSON */);
79757
+ });
79839
79758
  }
79840
79759
  // BlockEntity names are hardcoded
79841
79760
  static async getBlockList() {
@@ -79881,12 +79800,6 @@ return ${compiler2.callType("value", tagType)}
79881
79800
  };
79882
79801
  }
79883
79802
  };
79884
- __decorateClass([
79885
- Memoize()
79886
- ], Entities, "getBlockEntityModels", 1);
79887
- __decorateClass([
79888
- Memoize()
79889
- ], Entities, "getEntityModels", 1);
79890
79803
  var EntityModels = class {
79891
79804
  };
79892
79805
  var BlockEntityModels = class {