@loaders.gl/splats 5.0.0-beta.5 → 5.0.0-beta.7

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/dist.dev.js CHANGED
@@ -1218,7 +1218,7 @@ var __exports__ = (() => {
1218
1218
  if (options?.core) {
1219
1219
  loadOptions.core = { ...options.core };
1220
1220
  const parserCore = loadOptions.core;
1221
- for (const key of ["type", "attributions", "loaders", "onError", "loadOptions"]) {
1221
+ for (const key of ["type", "name", "attributions", "loaders", "onError", "loadOptions"]) {
1222
1222
  delete parserCore[key];
1223
1223
  }
1224
1224
  if (Object.keys(parserCore).length === 0) {
@@ -1253,6 +1253,43 @@ var __exports__ = (() => {
1253
1253
  );
1254
1254
  };
1255
1255
  }
1256
+ function getDataSourceName(data, options) {
1257
+ const explicitName = options.core?.name;
1258
+ if (explicitName !== void 0) {
1259
+ if (typeof explicitName !== "string" || !explicitName.trim())
1260
+ throw new Error("Data source name must be a non-empty string.");
1261
+ return explicitName;
1262
+ }
1263
+ if (data && typeof data === "object") {
1264
+ const named = data;
1265
+ if (typeof named.name === "string" && named.name.trim())
1266
+ return data instanceof Blob ? removeFileExtension(named.name) : named.name;
1267
+ const metadata = named.schema?.metadata;
1268
+ const embeddedName = metadata instanceof Map ? metadata.get("name") : metadata?.name;
1269
+ if (typeof embeddedName === "string" && embeddedName.trim()) return embeddedName;
1270
+ }
1271
+ if (typeof data === "string") {
1272
+ try {
1273
+ const url2 = new URL(data.replace(/\\/g, "/"), "https://source.invalid/");
1274
+ if (!["data:", "blob:"].includes(url2.protocol)) {
1275
+ let basename = url2.pathname.split("/").filter(Boolean).pop();
1276
+ if (basename) {
1277
+ try {
1278
+ basename = decodeURIComponent(basename);
1279
+ } catch {
1280
+ }
1281
+ return removeFileExtension(basename);
1282
+ }
1283
+ }
1284
+ } catch {
1285
+ }
1286
+ }
1287
+ return options.core?.type && options.core.type !== "auto" ? options.core.type : "source";
1288
+ }
1289
+ function removeFileExtension(name) {
1290
+ const extension = name.lastIndexOf(".");
1291
+ return extension > 0 ? name.slice(0, extension) : name;
1292
+ }
1256
1293
  var UNAVAILABLE_CORE_API, DataSource;
1257
1294
  var init_data_source = __esm({
1258
1295
  "../core/src/loader-utils/lib/sources/data-source.ts"() {
@@ -1284,6 +1321,8 @@ var __exports__ = (() => {
1284
1321
  options;
1285
1322
  data;
1286
1323
  url;
1324
+ /** Stable query-visible name, resolved without fetching source data. */
1325
+ name;
1287
1326
  /** Shared parser options derived from the source options, excluding source-only core controls. */
1288
1327
  loadOptions;
1289
1328
  /** A resolved fetch function extracted from the shared core options. */
@@ -1300,6 +1339,7 @@ var __exports__ = (() => {
1300
1339
  );
1301
1340
  this.data = data;
1302
1341
  this.url = typeof data === "string" ? resolvePath(data) : "";
1342
+ this.name = getDataSourceName(data, this.options);
1303
1343
  const loadOptions = resolveAuthenticationOptions(getSourceLoaderOptions(this.options));
1304
1344
  this.loadOptions = loadOptions;
1305
1345
  const fetch2 = getFetchFunction(loadOptions);
@@ -1308,6 +1348,8 @@ var __exports__ = (() => {
1308
1348
  this.fetch = fetch2;
1309
1349
  }
1310
1350
  setProps(options) {
1351
+ if (options.core?.name !== void 0 && options.core.name !== this.name)
1352
+ throw new Error("Data source names are fixed at creation.");
1311
1353
  const mergedOptions = mergeOptions(this.options, options);
1312
1354
  const loadOptions = resolveAuthenticationOptions(getSourceLoaderOptions(mergedOptions));
1313
1355
  this.options = mergedOptions;