@shgysk8zer0/importmap 1.7.4 → 1.7.6

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/CHANGELOG.md CHANGED
@@ -7,6 +7,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [v1.7.6] - 2026-01-09
11
+
12
+ ### Added
13
+ - Add `Importmap.resolve()`
14
+
15
+ ### Changed
16
+ - Update `@aegisjsproject/parsers` & `@aegisjsproject/core`
17
+
18
+ ## [v1.7.5] - 2026-01-08
19
+
20
+ ### Added
21
+ - Add `@awesome.me/webawesome`
22
+
10
23
  ## [v1.7.4] - 2026-01-06
11
24
 
12
25
  ### Changed
package/cli.cjs CHANGED
@@ -33,12 +33,12 @@ const imports$1 = {
33
33
  "@shgysk8zer0/geoutils/": "https://unpkg.com/@shgysk8zer0/geoutils@1.0.6/",
34
34
  "@aegisjsproject/trusted-types": "https://unpkg.com/@aegisjsproject/trusted-types@1.0.2/bundle.min.js",
35
35
  "@aegisjsproject/trusted-types/": "https://unpkg.com/@aegisjsproject/trusted-types@1.0.2/",
36
- "@aegisjsproject/parsers": "https://unpkg.com/@aegisjsproject/parsers@0.1.4/bundle.min.js",
37
- "@aegisjsproject/parsers/": "https://unpkg.com/@aegisjsproject/parsers@0.1.4/",
36
+ "@aegisjsproject/parsers": "https://unpkg.com/@aegisjsproject/parsers@0.1.5/bundle.min.js",
37
+ "@aegisjsproject/parsers/": "https://unpkg.com/@aegisjsproject/parsers@0.1.5/",
38
38
  "@aegisjsproject/sanitizer": "https://unpkg.com/@aegisjsproject/sanitizer@0.2.4/sanitizer.js",
39
39
  "@aegisjsproject/sanitizer/": "https://unpkg.com/@aegisjsproject/sanitizer@0.2.4/",
40
- "@aegisjsproject/core": "https://unpkg.com/@aegisjsproject/core@0.2.30/core.js",
41
- "@aegisjsproject/core/": "https://unpkg.com/@aegisjsproject/core@0.2.30/",
40
+ "@aegisjsproject/core": "https://unpkg.com/@aegisjsproject/core@0.2.32/core.js",
41
+ "@aegisjsproject/core/": "https://unpkg.com/@aegisjsproject/core@0.2.32/",
42
42
  "@aegisjsproject/styles": "https://unpkg.com/@aegisjsproject/styles@0.2.7/styles.js",
43
43
  "@aegisjsproject/styles/": "https://unpkg.com/@aegisjsproject/styles@0.2.7/",
44
44
  "@aegisjsproject/component": "https://unpkg.com/@aegisjsproject/component@0.1.7/component.js",
@@ -76,9 +76,6 @@ const imports$1 = {
76
76
  "@aegisjsproject/qr-encoder/": "https://unpkg.com/@aegisjsproject/qr-encoder@1.0.1/",
77
77
  "@aegisjsproject/escape": "https://unpkg.com/@aegisjsproject/escape@1.0.4/index.min.js",
78
78
  "@aegisjsproject/escape/": "https://unpkg.com/@aegisjsproject/escape@1.0.4/",
79
- "@aegisjsproject/escape/html": "https://unpkg.com/@aegisjsproject/escape@1.0.4/html.min.js",
80
- "@aegisjsproject/escape/trusted-html": "https://unpkg.com/@aegisjsproject/escape@1.0.4/trusted-html.min.js",
81
- "@aegisjsproject/escape/css": "https://unpkg.com/@aegisjsproject/escape@1.0.4/css.min.js",
82
79
  "@kernvalley/components/": "https://unpkg.com/@kernvalley/components@2.0.9/",
83
80
  "@webcomponents/custom-elements": "https://unpkg.com/@webcomponents/custom-elements@1.6.0/custom-elements.min.js",
84
81
  leaflet: "https://unpkg.com/leaflet@1.9.4/dist/leaflet-src.esm.js",
@@ -113,7 +110,8 @@ const imports$1 = {
113
110
  "lit-element": "https://unpkg.com/lit-element@4.2.2/lit-element.js",
114
111
  "lit-element/": "https://unpkg.com/lit-element@4.2.2/",
115
112
  "@lit/reactive-element": "https://unpkg.com/@lit/reactive-element@2.1.2/reactive-element.js",
116
- "@lit/reactive-element/": "https://unpkg.com/@lit/reactive-element@2.1.2/"
113
+ "@lit/reactive-element/": "https://unpkg.com/@lit/reactive-element@2.1.2/",
114
+ "@awesome.me/webawesome/": "https://unpkg.com/@awesome.me/webawesome@3.1.0/"
117
115
  };
118
116
  const scopes$1 = {
119
117
  };
@@ -134,6 +132,7 @@ const { imports, scopes } = json;
134
132
  class Importmap {
135
133
  #imports = {};
136
134
  #scopes = {};
135
+ #base;
137
136
 
138
137
  constructor({ imports: i = imports, scopes: s = scopes } = {}) {
139
138
  this.#imports = i;
@@ -172,6 +171,48 @@ class Importmap {
172
171
  return JSON.stringify(this);
173
172
  }
174
173
 
174
+ get baseUrl() {
175
+ return this.#base;
176
+ }
177
+
178
+ set baseUrl(val) {
179
+ if (typeof val === 'string' && URL.canParse(val)) {
180
+ this.#base = val;
181
+ }
182
+ }
183
+
184
+ resolve(specifier, base = this.baseUrl) {
185
+ if (specifier instanceof URL) {
186
+ return specifier.href;
187
+ } else if (typeof specifier !== 'string') {
188
+ return null;
189
+ } else if (this.has(specifier)) {
190
+ return URL.parse(this.get(specifier), this.baseUrl)?.href ?? null;
191
+ } else if (URL.canParse(specifier)) {
192
+ return specifier;
193
+ } else if (! specifier.startsWith('.')) {
194
+ // Find the longest match
195
+ const matches = Object.keys(this.imports)
196
+ .filter(key => key.endsWith('/') && specifier.startsWith(key))
197
+ .sort((a, b) => b.length - a.length);
198
+
199
+ if (matches.length === 0) {
200
+ return null;
201
+ } else {
202
+ const match = matches[0];
203
+ const target = imports[match];
204
+ const subpath = specifier.slice(match.length);
205
+ // Resolve the mapping target against the map's base, then the subpath against that
206
+ const resolvedTarget = new URL(target, this.baseUrl);
207
+ return new URL(subpath, resolvedTarget).href;
208
+ }
209
+ } else if (typeof base === 'string') {
210
+ return URL.parse(specifier, base)?.href ?? null;
211
+ } else {
212
+ return null;
213
+ }
214
+ }
215
+
175
216
  async importLocalPackage(name = 'package.json', { signal } = {}) {
176
217
  const path = node_path.join(process.cwd(), name);
177
218
  const pkg = await promises.readFile(path, { encoding: 'utf8', signal });
package/cli.js CHANGED
@@ -30,12 +30,12 @@ const imports$1 = {
30
30
  "@shgysk8zer0/geoutils/": "https://unpkg.com/@shgysk8zer0/geoutils@1.0.6/",
31
31
  "@aegisjsproject/trusted-types": "https://unpkg.com/@aegisjsproject/trusted-types@1.0.2/bundle.min.js",
32
32
  "@aegisjsproject/trusted-types/": "https://unpkg.com/@aegisjsproject/trusted-types@1.0.2/",
33
- "@aegisjsproject/parsers": "https://unpkg.com/@aegisjsproject/parsers@0.1.4/bundle.min.js",
34
- "@aegisjsproject/parsers/": "https://unpkg.com/@aegisjsproject/parsers@0.1.4/",
33
+ "@aegisjsproject/parsers": "https://unpkg.com/@aegisjsproject/parsers@0.1.5/bundle.min.js",
34
+ "@aegisjsproject/parsers/": "https://unpkg.com/@aegisjsproject/parsers@0.1.5/",
35
35
  "@aegisjsproject/sanitizer": "https://unpkg.com/@aegisjsproject/sanitizer@0.2.4/sanitizer.js",
36
36
  "@aegisjsproject/sanitizer/": "https://unpkg.com/@aegisjsproject/sanitizer@0.2.4/",
37
- "@aegisjsproject/core": "https://unpkg.com/@aegisjsproject/core@0.2.30/core.js",
38
- "@aegisjsproject/core/": "https://unpkg.com/@aegisjsproject/core@0.2.30/",
37
+ "@aegisjsproject/core": "https://unpkg.com/@aegisjsproject/core@0.2.32/core.js",
38
+ "@aegisjsproject/core/": "https://unpkg.com/@aegisjsproject/core@0.2.32/",
39
39
  "@aegisjsproject/styles": "https://unpkg.com/@aegisjsproject/styles@0.2.7/styles.js",
40
40
  "@aegisjsproject/styles/": "https://unpkg.com/@aegisjsproject/styles@0.2.7/",
41
41
  "@aegisjsproject/component": "https://unpkg.com/@aegisjsproject/component@0.1.7/component.js",
@@ -73,9 +73,6 @@ const imports$1 = {
73
73
  "@aegisjsproject/qr-encoder/": "https://unpkg.com/@aegisjsproject/qr-encoder@1.0.1/",
74
74
  "@aegisjsproject/escape": "https://unpkg.com/@aegisjsproject/escape@1.0.4/index.min.js",
75
75
  "@aegisjsproject/escape/": "https://unpkg.com/@aegisjsproject/escape@1.0.4/",
76
- "@aegisjsproject/escape/html": "https://unpkg.com/@aegisjsproject/escape@1.0.4/html.min.js",
77
- "@aegisjsproject/escape/trusted-html": "https://unpkg.com/@aegisjsproject/escape@1.0.4/trusted-html.min.js",
78
- "@aegisjsproject/escape/css": "https://unpkg.com/@aegisjsproject/escape@1.0.4/css.min.js",
79
76
  "@kernvalley/components/": "https://unpkg.com/@kernvalley/components@2.0.9/",
80
77
  "@webcomponents/custom-elements": "https://unpkg.com/@webcomponents/custom-elements@1.6.0/custom-elements.min.js",
81
78
  leaflet: "https://unpkg.com/leaflet@1.9.4/dist/leaflet-src.esm.js",
@@ -110,7 +107,8 @@ const imports$1 = {
110
107
  "lit-element": "https://unpkg.com/lit-element@4.2.2/lit-element.js",
111
108
  "lit-element/": "https://unpkg.com/lit-element@4.2.2/",
112
109
  "@lit/reactive-element": "https://unpkg.com/@lit/reactive-element@2.1.2/reactive-element.js",
113
- "@lit/reactive-element/": "https://unpkg.com/@lit/reactive-element@2.1.2/"
110
+ "@lit/reactive-element/": "https://unpkg.com/@lit/reactive-element@2.1.2/",
111
+ "@awesome.me/webawesome/": "https://unpkg.com/@awesome.me/webawesome@3.1.0/"
114
112
  };
115
113
  const scopes$1 = {
116
114
  };
@@ -131,6 +129,7 @@ const { imports, scopes } = json;
131
129
  class Importmap {
132
130
  #imports = {};
133
131
  #scopes = {};
132
+ #base;
134
133
 
135
134
  constructor({ imports: i = imports, scopes: s = scopes } = {}) {
136
135
  this.#imports = i;
@@ -169,6 +168,48 @@ class Importmap {
169
168
  return JSON.stringify(this);
170
169
  }
171
170
 
171
+ get baseUrl() {
172
+ return this.#base;
173
+ }
174
+
175
+ set baseUrl(val) {
176
+ if (typeof val === 'string' && URL.canParse(val)) {
177
+ this.#base = val;
178
+ }
179
+ }
180
+
181
+ resolve(specifier, base = this.baseUrl) {
182
+ if (specifier instanceof URL) {
183
+ return specifier.href;
184
+ } else if (typeof specifier !== 'string') {
185
+ return null;
186
+ } else if (this.has(specifier)) {
187
+ return URL.parse(this.get(specifier), this.baseUrl)?.href ?? null;
188
+ } else if (URL.canParse(specifier)) {
189
+ return specifier;
190
+ } else if (! specifier.startsWith('.')) {
191
+ // Find the longest match
192
+ const matches = Object.keys(this.imports)
193
+ .filter(key => key.endsWith('/') && specifier.startsWith(key))
194
+ .sort((a, b) => b.length - a.length);
195
+
196
+ if (matches.length === 0) {
197
+ return null;
198
+ } else {
199
+ const match = matches[0];
200
+ const target = imports[match];
201
+ const subpath = specifier.slice(match.length);
202
+ // Resolve the mapping target against the map's base, then the subpath against that
203
+ const resolvedTarget = new URL(target, this.baseUrl);
204
+ return new URL(subpath, resolvedTarget).href;
205
+ }
206
+ } else if (typeof base === 'string') {
207
+ return URL.parse(specifier, base)?.href ?? null;
208
+ } else {
209
+ return null;
210
+ }
211
+ }
212
+
172
213
  async importLocalPackage(name = 'package.json', { signal } = {}) {
173
214
  const path = join(process.cwd(), name);
174
215
  const pkg = await readFile(path, { encoding: 'utf8', signal });
package/importmap.cjs CHANGED
@@ -30,12 +30,12 @@ const imports$1 = {
30
30
  "@shgysk8zer0/geoutils/": "https://unpkg.com/@shgysk8zer0/geoutils@1.0.6/",
31
31
  "@aegisjsproject/trusted-types": "https://unpkg.com/@aegisjsproject/trusted-types@1.0.2/bundle.min.js",
32
32
  "@aegisjsproject/trusted-types/": "https://unpkg.com/@aegisjsproject/trusted-types@1.0.2/",
33
- "@aegisjsproject/parsers": "https://unpkg.com/@aegisjsproject/parsers@0.1.4/bundle.min.js",
34
- "@aegisjsproject/parsers/": "https://unpkg.com/@aegisjsproject/parsers@0.1.4/",
33
+ "@aegisjsproject/parsers": "https://unpkg.com/@aegisjsproject/parsers@0.1.5/bundle.min.js",
34
+ "@aegisjsproject/parsers/": "https://unpkg.com/@aegisjsproject/parsers@0.1.5/",
35
35
  "@aegisjsproject/sanitizer": "https://unpkg.com/@aegisjsproject/sanitizer@0.2.4/sanitizer.js",
36
36
  "@aegisjsproject/sanitizer/": "https://unpkg.com/@aegisjsproject/sanitizer@0.2.4/",
37
- "@aegisjsproject/core": "https://unpkg.com/@aegisjsproject/core@0.2.30/core.js",
38
- "@aegisjsproject/core/": "https://unpkg.com/@aegisjsproject/core@0.2.30/",
37
+ "@aegisjsproject/core": "https://unpkg.com/@aegisjsproject/core@0.2.32/core.js",
38
+ "@aegisjsproject/core/": "https://unpkg.com/@aegisjsproject/core@0.2.32/",
39
39
  "@aegisjsproject/styles": "https://unpkg.com/@aegisjsproject/styles@0.2.7/styles.js",
40
40
  "@aegisjsproject/styles/": "https://unpkg.com/@aegisjsproject/styles@0.2.7/",
41
41
  "@aegisjsproject/component": "https://unpkg.com/@aegisjsproject/component@0.1.7/component.js",
@@ -73,9 +73,6 @@ const imports$1 = {
73
73
  "@aegisjsproject/qr-encoder/": "https://unpkg.com/@aegisjsproject/qr-encoder@1.0.1/",
74
74
  "@aegisjsproject/escape": "https://unpkg.com/@aegisjsproject/escape@1.0.4/index.min.js",
75
75
  "@aegisjsproject/escape/": "https://unpkg.com/@aegisjsproject/escape@1.0.4/",
76
- "@aegisjsproject/escape/html": "https://unpkg.com/@aegisjsproject/escape@1.0.4/html.min.js",
77
- "@aegisjsproject/escape/trusted-html": "https://unpkg.com/@aegisjsproject/escape@1.0.4/trusted-html.min.js",
78
- "@aegisjsproject/escape/css": "https://unpkg.com/@aegisjsproject/escape@1.0.4/css.min.js",
79
76
  "@kernvalley/components/": "https://unpkg.com/@kernvalley/components@2.0.9/",
80
77
  "@webcomponents/custom-elements": "https://unpkg.com/@webcomponents/custom-elements@1.6.0/custom-elements.min.js",
81
78
  leaflet: "https://unpkg.com/leaflet@1.9.4/dist/leaflet-src.esm.js",
@@ -110,7 +107,8 @@ const imports$1 = {
110
107
  "lit-element": "https://unpkg.com/lit-element@4.2.2/lit-element.js",
111
108
  "lit-element/": "https://unpkg.com/lit-element@4.2.2/",
112
109
  "@lit/reactive-element": "https://unpkg.com/@lit/reactive-element@2.1.2/reactive-element.js",
113
- "@lit/reactive-element/": "https://unpkg.com/@lit/reactive-element@2.1.2/"
110
+ "@lit/reactive-element/": "https://unpkg.com/@lit/reactive-element@2.1.2/",
111
+ "@awesome.me/webawesome/": "https://unpkg.com/@awesome.me/webawesome@3.1.0/"
114
112
  };
115
113
  const scopes$1 = {
116
114
  };
@@ -131,6 +129,7 @@ const { imports, scopes } = json;
131
129
  class Importmap {
132
130
  #imports = {};
133
131
  #scopes = {};
132
+ #base;
134
133
 
135
134
  constructor({ imports: i = imports, scopes: s = scopes } = {}) {
136
135
  this.#imports = i;
@@ -169,6 +168,48 @@ class Importmap {
169
168
  return JSON.stringify(this);
170
169
  }
171
170
 
171
+ get baseUrl() {
172
+ return this.#base;
173
+ }
174
+
175
+ set baseUrl(val) {
176
+ if (typeof val === 'string' && URL.canParse(val)) {
177
+ this.#base = val;
178
+ }
179
+ }
180
+
181
+ resolve(specifier, base = this.baseUrl) {
182
+ if (specifier instanceof URL) {
183
+ return specifier.href;
184
+ } else if (typeof specifier !== 'string') {
185
+ return null;
186
+ } else if (this.has(specifier)) {
187
+ return URL.parse(this.get(specifier), this.baseUrl)?.href ?? null;
188
+ } else if (URL.canParse(specifier)) {
189
+ return specifier;
190
+ } else if (! specifier.startsWith('.')) {
191
+ // Find the longest match
192
+ const matches = Object.keys(this.imports)
193
+ .filter(key => key.endsWith('/') && specifier.startsWith(key))
194
+ .sort((a, b) => b.length - a.length);
195
+
196
+ if (matches.length === 0) {
197
+ return null;
198
+ } else {
199
+ const match = matches[0];
200
+ const target = imports[match];
201
+ const subpath = specifier.slice(match.length);
202
+ // Resolve the mapping target against the map's base, then the subpath against that
203
+ const resolvedTarget = new URL(target, this.baseUrl);
204
+ return new URL(subpath, resolvedTarget).href;
205
+ }
206
+ } else if (typeof base === 'string') {
207
+ return URL.parse(specifier, base)?.href ?? null;
208
+ } else {
209
+ return null;
210
+ }
211
+ }
212
+
172
213
  async importLocalPackage(name = 'package.json', { signal } = {}) {
173
214
  const path = node_path.join(process.cwd(), name);
174
215
  const pkg = await promises.readFile(path, { encoding: 'utf8', signal });
package/importmap.js CHANGED
@@ -26,12 +26,12 @@ const imports$1 = {
26
26
  "@shgysk8zer0/geoutils/": "https://unpkg.com/@shgysk8zer0/geoutils@1.0.6/",
27
27
  "@aegisjsproject/trusted-types": "https://unpkg.com/@aegisjsproject/trusted-types@1.0.2/bundle.min.js",
28
28
  "@aegisjsproject/trusted-types/": "https://unpkg.com/@aegisjsproject/trusted-types@1.0.2/",
29
- "@aegisjsproject/parsers": "https://unpkg.com/@aegisjsproject/parsers@0.1.4/bundle.min.js",
30
- "@aegisjsproject/parsers/": "https://unpkg.com/@aegisjsproject/parsers@0.1.4/",
29
+ "@aegisjsproject/parsers": "https://unpkg.com/@aegisjsproject/parsers@0.1.5/bundle.min.js",
30
+ "@aegisjsproject/parsers/": "https://unpkg.com/@aegisjsproject/parsers@0.1.5/",
31
31
  "@aegisjsproject/sanitizer": "https://unpkg.com/@aegisjsproject/sanitizer@0.2.4/sanitizer.js",
32
32
  "@aegisjsproject/sanitizer/": "https://unpkg.com/@aegisjsproject/sanitizer@0.2.4/",
33
- "@aegisjsproject/core": "https://unpkg.com/@aegisjsproject/core@0.2.30/core.js",
34
- "@aegisjsproject/core/": "https://unpkg.com/@aegisjsproject/core@0.2.30/",
33
+ "@aegisjsproject/core": "https://unpkg.com/@aegisjsproject/core@0.2.32/core.js",
34
+ "@aegisjsproject/core/": "https://unpkg.com/@aegisjsproject/core@0.2.32/",
35
35
  "@aegisjsproject/styles": "https://unpkg.com/@aegisjsproject/styles@0.2.7/styles.js",
36
36
  "@aegisjsproject/styles/": "https://unpkg.com/@aegisjsproject/styles@0.2.7/",
37
37
  "@aegisjsproject/component": "https://unpkg.com/@aegisjsproject/component@0.1.7/component.js",
@@ -69,9 +69,6 @@ const imports$1 = {
69
69
  "@aegisjsproject/qr-encoder/": "https://unpkg.com/@aegisjsproject/qr-encoder@1.0.1/",
70
70
  "@aegisjsproject/escape": "https://unpkg.com/@aegisjsproject/escape@1.0.4/index.min.js",
71
71
  "@aegisjsproject/escape/": "https://unpkg.com/@aegisjsproject/escape@1.0.4/",
72
- "@aegisjsproject/escape/html": "https://unpkg.com/@aegisjsproject/escape@1.0.4/html.min.js",
73
- "@aegisjsproject/escape/trusted-html": "https://unpkg.com/@aegisjsproject/escape@1.0.4/trusted-html.min.js",
74
- "@aegisjsproject/escape/css": "https://unpkg.com/@aegisjsproject/escape@1.0.4/css.min.js",
75
72
  "@kernvalley/components/": "https://unpkg.com/@kernvalley/components@2.0.9/",
76
73
  "@webcomponents/custom-elements": "https://unpkg.com/@webcomponents/custom-elements@1.6.0/custom-elements.min.js",
77
74
  leaflet: "https://unpkg.com/leaflet@1.9.4/dist/leaflet-src.esm.js",
@@ -106,7 +103,8 @@ const imports$1 = {
106
103
  "lit-element": "https://unpkg.com/lit-element@4.2.2/lit-element.js",
107
104
  "lit-element/": "https://unpkg.com/lit-element@4.2.2/",
108
105
  "@lit/reactive-element": "https://unpkg.com/@lit/reactive-element@2.1.2/reactive-element.js",
109
- "@lit/reactive-element/": "https://unpkg.com/@lit/reactive-element@2.1.2/"
106
+ "@lit/reactive-element/": "https://unpkg.com/@lit/reactive-element@2.1.2/",
107
+ "@awesome.me/webawesome/": "https://unpkg.com/@awesome.me/webawesome@3.1.0/"
110
108
  };
111
109
  const scopes$1 = {
112
110
  };
@@ -127,6 +125,7 @@ const { imports, scopes } = json;
127
125
  class Importmap {
128
126
  #imports = {};
129
127
  #scopes = {};
128
+ #base;
130
129
 
131
130
  constructor({ imports: i = imports, scopes: s = scopes } = {}) {
132
131
  this.#imports = i;
@@ -165,6 +164,48 @@ class Importmap {
165
164
  return JSON.stringify(this);
166
165
  }
167
166
 
167
+ get baseUrl() {
168
+ return this.#base;
169
+ }
170
+
171
+ set baseUrl(val) {
172
+ if (typeof val === 'string' && URL.canParse(val)) {
173
+ this.#base = val;
174
+ }
175
+ }
176
+
177
+ resolve(specifier, base = this.baseUrl) {
178
+ if (specifier instanceof URL) {
179
+ return specifier.href;
180
+ } else if (typeof specifier !== 'string') {
181
+ return null;
182
+ } else if (this.has(specifier)) {
183
+ return URL.parse(this.get(specifier), this.baseUrl)?.href ?? null;
184
+ } else if (URL.canParse(specifier)) {
185
+ return specifier;
186
+ } else if (! specifier.startsWith('.')) {
187
+ // Find the longest match
188
+ const matches = Object.keys(this.imports)
189
+ .filter(key => key.endsWith('/') && specifier.startsWith(key))
190
+ .sort((a, b) => b.length - a.length);
191
+
192
+ if (matches.length === 0) {
193
+ return null;
194
+ } else {
195
+ const match = matches[0];
196
+ const target = imports[match];
197
+ const subpath = specifier.slice(match.length);
198
+ // Resolve the mapping target against the map's base, then the subpath against that
199
+ const resolvedTarget = new URL(target, this.baseUrl);
200
+ return new URL(subpath, resolvedTarget).href;
201
+ }
202
+ } else if (typeof base === 'string') {
203
+ return URL.parse(specifier, base)?.href ?? null;
204
+ } else {
205
+ return null;
206
+ }
207
+ }
208
+
168
209
  async importLocalPackage(name = 'package.json', { signal } = {}) {
169
210
  const path = join(process.cwd(), name);
170
211
  const pkg = await readFile(path, { encoding: 'utf8', signal });
package/importmap.json CHANGED
@@ -23,12 +23,12 @@
23
23
  "@shgysk8zer0/geoutils/": "https://unpkg.com/@shgysk8zer0/geoutils@1.0.6/",
24
24
  "@aegisjsproject/trusted-types": "https://unpkg.com/@aegisjsproject/trusted-types@1.0.2/bundle.min.js",
25
25
  "@aegisjsproject/trusted-types/": "https://unpkg.com/@aegisjsproject/trusted-types@1.0.2/",
26
- "@aegisjsproject/parsers": "https://unpkg.com/@aegisjsproject/parsers@0.1.4/bundle.min.js",
27
- "@aegisjsproject/parsers/": "https://unpkg.com/@aegisjsproject/parsers@0.1.4/",
26
+ "@aegisjsproject/parsers": "https://unpkg.com/@aegisjsproject/parsers@0.1.5/bundle.min.js",
27
+ "@aegisjsproject/parsers/": "https://unpkg.com/@aegisjsproject/parsers@0.1.5/",
28
28
  "@aegisjsproject/sanitizer": "https://unpkg.com/@aegisjsproject/sanitizer@0.2.4/sanitizer.js",
29
29
  "@aegisjsproject/sanitizer/": "https://unpkg.com/@aegisjsproject/sanitizer@0.2.4/",
30
- "@aegisjsproject/core": "https://unpkg.com/@aegisjsproject/core@0.2.30/core.js",
31
- "@aegisjsproject/core/": "https://unpkg.com/@aegisjsproject/core@0.2.30/",
30
+ "@aegisjsproject/core": "https://unpkg.com/@aegisjsproject/core@0.2.32/core.js",
31
+ "@aegisjsproject/core/": "https://unpkg.com/@aegisjsproject/core@0.2.32/",
32
32
  "@aegisjsproject/styles": "https://unpkg.com/@aegisjsproject/styles@0.2.7/styles.js",
33
33
  "@aegisjsproject/styles/": "https://unpkg.com/@aegisjsproject/styles@0.2.7/",
34
34
  "@aegisjsproject/component": "https://unpkg.com/@aegisjsproject/component@0.1.7/component.js",
@@ -66,9 +66,6 @@
66
66
  "@aegisjsproject/qr-encoder/": "https://unpkg.com/@aegisjsproject/qr-encoder@1.0.1/",
67
67
  "@aegisjsproject/escape": "https://unpkg.com/@aegisjsproject/escape@1.0.4/index.min.js",
68
68
  "@aegisjsproject/escape/": "https://unpkg.com/@aegisjsproject/escape@1.0.4/",
69
- "@aegisjsproject/escape/html": "https://unpkg.com/@aegisjsproject/escape@1.0.4/html.min.js",
70
- "@aegisjsproject/escape/trusted-html": "https://unpkg.com/@aegisjsproject/escape@1.0.4/trusted-html.min.js",
71
- "@aegisjsproject/escape/css": "https://unpkg.com/@aegisjsproject/escape@1.0.4/css.min.js",
72
69
  "@kernvalley/components/": "https://unpkg.com/@kernvalley/components@2.0.9/",
73
70
  "@webcomponents/custom-elements": "https://unpkg.com/@webcomponents/custom-elements@1.6.0/custom-elements.min.js",
74
71
  "leaflet": "https://unpkg.com/leaflet@1.9.4/dist/leaflet-src.esm.js",
@@ -103,7 +100,8 @@
103
100
  "lit-element": "https://unpkg.com/lit-element@4.2.2/lit-element.js",
104
101
  "lit-element/": "https://unpkg.com/lit-element@4.2.2/",
105
102
  "@lit/reactive-element": "https://unpkg.com/@lit/reactive-element@2.1.2/reactive-element.js",
106
- "@lit/reactive-element/": "https://unpkg.com/@lit/reactive-element@2.1.2/"
103
+ "@lit/reactive-element/": "https://unpkg.com/@lit/reactive-element@2.1.2/",
104
+ "@awesome.me/webawesome/": "https://unpkg.com/@awesome.me/webawesome@3.1.0/"
107
105
  },
108
106
  "scopes": {}
109
- }
107
+ }
package/index.cjs CHANGED
@@ -31,12 +31,12 @@ const imports$1 = {
31
31
  "@shgysk8zer0/geoutils/": "https://unpkg.com/@shgysk8zer0/geoutils@1.0.6/",
32
32
  "@aegisjsproject/trusted-types": "https://unpkg.com/@aegisjsproject/trusted-types@1.0.2/bundle.min.js",
33
33
  "@aegisjsproject/trusted-types/": "https://unpkg.com/@aegisjsproject/trusted-types@1.0.2/",
34
- "@aegisjsproject/parsers": "https://unpkg.com/@aegisjsproject/parsers@0.1.4/bundle.min.js",
35
- "@aegisjsproject/parsers/": "https://unpkg.com/@aegisjsproject/parsers@0.1.4/",
34
+ "@aegisjsproject/parsers": "https://unpkg.com/@aegisjsproject/parsers@0.1.5/bundle.min.js",
35
+ "@aegisjsproject/parsers/": "https://unpkg.com/@aegisjsproject/parsers@0.1.5/",
36
36
  "@aegisjsproject/sanitizer": "https://unpkg.com/@aegisjsproject/sanitizer@0.2.4/sanitizer.js",
37
37
  "@aegisjsproject/sanitizer/": "https://unpkg.com/@aegisjsproject/sanitizer@0.2.4/",
38
- "@aegisjsproject/core": "https://unpkg.com/@aegisjsproject/core@0.2.30/core.js",
39
- "@aegisjsproject/core/": "https://unpkg.com/@aegisjsproject/core@0.2.30/",
38
+ "@aegisjsproject/core": "https://unpkg.com/@aegisjsproject/core@0.2.32/core.js",
39
+ "@aegisjsproject/core/": "https://unpkg.com/@aegisjsproject/core@0.2.32/",
40
40
  "@aegisjsproject/styles": "https://unpkg.com/@aegisjsproject/styles@0.2.7/styles.js",
41
41
  "@aegisjsproject/styles/": "https://unpkg.com/@aegisjsproject/styles@0.2.7/",
42
42
  "@aegisjsproject/component": "https://unpkg.com/@aegisjsproject/component@0.1.7/component.js",
@@ -74,9 +74,6 @@ const imports$1 = {
74
74
  "@aegisjsproject/qr-encoder/": "https://unpkg.com/@aegisjsproject/qr-encoder@1.0.1/",
75
75
  "@aegisjsproject/escape": "https://unpkg.com/@aegisjsproject/escape@1.0.4/index.min.js",
76
76
  "@aegisjsproject/escape/": "https://unpkg.com/@aegisjsproject/escape@1.0.4/",
77
- "@aegisjsproject/escape/html": "https://unpkg.com/@aegisjsproject/escape@1.0.4/html.min.js",
78
- "@aegisjsproject/escape/trusted-html": "https://unpkg.com/@aegisjsproject/escape@1.0.4/trusted-html.min.js",
79
- "@aegisjsproject/escape/css": "https://unpkg.com/@aegisjsproject/escape@1.0.4/css.min.js",
80
77
  "@kernvalley/components/": "https://unpkg.com/@kernvalley/components@2.0.9/",
81
78
  "@webcomponents/custom-elements": "https://unpkg.com/@webcomponents/custom-elements@1.6.0/custom-elements.min.js",
82
79
  leaflet: "https://unpkg.com/leaflet@1.9.4/dist/leaflet-src.esm.js",
@@ -111,7 +108,8 @@ const imports$1 = {
111
108
  "lit-element": "https://unpkg.com/lit-element@4.2.2/lit-element.js",
112
109
  "lit-element/": "https://unpkg.com/lit-element@4.2.2/",
113
110
  "@lit/reactive-element": "https://unpkg.com/@lit/reactive-element@2.1.2/reactive-element.js",
114
- "@lit/reactive-element/": "https://unpkg.com/@lit/reactive-element@2.1.2/"
111
+ "@lit/reactive-element/": "https://unpkg.com/@lit/reactive-element@2.1.2/",
112
+ "@awesome.me/webawesome/": "https://unpkg.com/@awesome.me/webawesome@3.1.0/"
115
113
  };
116
114
  const scopes$1 = {
117
115
  };
@@ -164,6 +162,7 @@ const { imports, scopes } = json;
164
162
  class Importmap {
165
163
  #imports = {};
166
164
  #scopes = {};
165
+ #base;
167
166
 
168
167
  constructor({ imports: i = imports, scopes: s = scopes } = {}) {
169
168
  this.#imports = i;
@@ -202,6 +201,48 @@ class Importmap {
202
201
  return JSON.stringify(this);
203
202
  }
204
203
 
204
+ get baseUrl() {
205
+ return this.#base;
206
+ }
207
+
208
+ set baseUrl(val) {
209
+ if (typeof val === 'string' && URL.canParse(val)) {
210
+ this.#base = val;
211
+ }
212
+ }
213
+
214
+ resolve(specifier, base = this.baseUrl) {
215
+ if (specifier instanceof URL) {
216
+ return specifier.href;
217
+ } else if (typeof specifier !== 'string') {
218
+ return null;
219
+ } else if (this.has(specifier)) {
220
+ return URL.parse(this.get(specifier), this.baseUrl)?.href ?? null;
221
+ } else if (URL.canParse(specifier)) {
222
+ return specifier;
223
+ } else if (! specifier.startsWith('.')) {
224
+ // Find the longest match
225
+ const matches = Object.keys(this.imports)
226
+ .filter(key => key.endsWith('/') && specifier.startsWith(key))
227
+ .sort((a, b) => b.length - a.length);
228
+
229
+ if (matches.length === 0) {
230
+ return null;
231
+ } else {
232
+ const match = matches[0];
233
+ const target = imports[match];
234
+ const subpath = specifier.slice(match.length);
235
+ // Resolve the mapping target against the map's base, then the subpath against that
236
+ const resolvedTarget = new URL(target, this.baseUrl);
237
+ return new URL(subpath, resolvedTarget).href;
238
+ }
239
+ } else if (typeof base === 'string') {
240
+ return URL.parse(specifier, base)?.href ?? null;
241
+ } else {
242
+ return null;
243
+ }
244
+ }
245
+
205
246
  async importLocalPackage(name = 'package.json', { signal } = {}) {
206
247
  const path = node_path.join(process.cwd(), name);
207
248
  const pkg = await promises.readFile(path, { encoding: 'utf8', signal });
package/index.js CHANGED
@@ -29,12 +29,12 @@ const imports$1 = {
29
29
  "@shgysk8zer0/geoutils/": "https://unpkg.com/@shgysk8zer0/geoutils@1.0.6/",
30
30
  "@aegisjsproject/trusted-types": "https://unpkg.com/@aegisjsproject/trusted-types@1.0.2/bundle.min.js",
31
31
  "@aegisjsproject/trusted-types/": "https://unpkg.com/@aegisjsproject/trusted-types@1.0.2/",
32
- "@aegisjsproject/parsers": "https://unpkg.com/@aegisjsproject/parsers@0.1.4/bundle.min.js",
33
- "@aegisjsproject/parsers/": "https://unpkg.com/@aegisjsproject/parsers@0.1.4/",
32
+ "@aegisjsproject/parsers": "https://unpkg.com/@aegisjsproject/parsers@0.1.5/bundle.min.js",
33
+ "@aegisjsproject/parsers/": "https://unpkg.com/@aegisjsproject/parsers@0.1.5/",
34
34
  "@aegisjsproject/sanitizer": "https://unpkg.com/@aegisjsproject/sanitizer@0.2.4/sanitizer.js",
35
35
  "@aegisjsproject/sanitizer/": "https://unpkg.com/@aegisjsproject/sanitizer@0.2.4/",
36
- "@aegisjsproject/core": "https://unpkg.com/@aegisjsproject/core@0.2.30/core.js",
37
- "@aegisjsproject/core/": "https://unpkg.com/@aegisjsproject/core@0.2.30/",
36
+ "@aegisjsproject/core": "https://unpkg.com/@aegisjsproject/core@0.2.32/core.js",
37
+ "@aegisjsproject/core/": "https://unpkg.com/@aegisjsproject/core@0.2.32/",
38
38
  "@aegisjsproject/styles": "https://unpkg.com/@aegisjsproject/styles@0.2.7/styles.js",
39
39
  "@aegisjsproject/styles/": "https://unpkg.com/@aegisjsproject/styles@0.2.7/",
40
40
  "@aegisjsproject/component": "https://unpkg.com/@aegisjsproject/component@0.1.7/component.js",
@@ -72,9 +72,6 @@ const imports$1 = {
72
72
  "@aegisjsproject/qr-encoder/": "https://unpkg.com/@aegisjsproject/qr-encoder@1.0.1/",
73
73
  "@aegisjsproject/escape": "https://unpkg.com/@aegisjsproject/escape@1.0.4/index.min.js",
74
74
  "@aegisjsproject/escape/": "https://unpkg.com/@aegisjsproject/escape@1.0.4/",
75
- "@aegisjsproject/escape/html": "https://unpkg.com/@aegisjsproject/escape@1.0.4/html.min.js",
76
- "@aegisjsproject/escape/trusted-html": "https://unpkg.com/@aegisjsproject/escape@1.0.4/trusted-html.min.js",
77
- "@aegisjsproject/escape/css": "https://unpkg.com/@aegisjsproject/escape@1.0.4/css.min.js",
78
75
  "@kernvalley/components/": "https://unpkg.com/@kernvalley/components@2.0.9/",
79
76
  "@webcomponents/custom-elements": "https://unpkg.com/@webcomponents/custom-elements@1.6.0/custom-elements.min.js",
80
77
  leaflet: "https://unpkg.com/leaflet@1.9.4/dist/leaflet-src.esm.js",
@@ -109,7 +106,8 @@ const imports$1 = {
109
106
  "lit-element": "https://unpkg.com/lit-element@4.2.2/lit-element.js",
110
107
  "lit-element/": "https://unpkg.com/lit-element@4.2.2/",
111
108
  "@lit/reactive-element": "https://unpkg.com/@lit/reactive-element@2.1.2/reactive-element.js",
112
- "@lit/reactive-element/": "https://unpkg.com/@lit/reactive-element@2.1.2/"
109
+ "@lit/reactive-element/": "https://unpkg.com/@lit/reactive-element@2.1.2/",
110
+ "@awesome.me/webawesome/": "https://unpkg.com/@awesome.me/webawesome@3.1.0/"
113
111
  };
114
112
  const scopes$1 = {
115
113
  };
@@ -162,6 +160,7 @@ const { imports, scopes } = json;
162
160
  class Importmap {
163
161
  #imports = {};
164
162
  #scopes = {};
163
+ #base;
165
164
 
166
165
  constructor({ imports: i = imports, scopes: s = scopes } = {}) {
167
166
  this.#imports = i;
@@ -200,6 +199,48 @@ class Importmap {
200
199
  return JSON.stringify(this);
201
200
  }
202
201
 
202
+ get baseUrl() {
203
+ return this.#base;
204
+ }
205
+
206
+ set baseUrl(val) {
207
+ if (typeof val === 'string' && URL.canParse(val)) {
208
+ this.#base = val;
209
+ }
210
+ }
211
+
212
+ resolve(specifier, base = this.baseUrl) {
213
+ if (specifier instanceof URL) {
214
+ return specifier.href;
215
+ } else if (typeof specifier !== 'string') {
216
+ return null;
217
+ } else if (this.has(specifier)) {
218
+ return URL.parse(this.get(specifier), this.baseUrl)?.href ?? null;
219
+ } else if (URL.canParse(specifier)) {
220
+ return specifier;
221
+ } else if (! specifier.startsWith('.')) {
222
+ // Find the longest match
223
+ const matches = Object.keys(this.imports)
224
+ .filter(key => key.endsWith('/') && specifier.startsWith(key))
225
+ .sort((a, b) => b.length - a.length);
226
+
227
+ if (matches.length === 0) {
228
+ return null;
229
+ } else {
230
+ const match = matches[0];
231
+ const target = imports[match];
232
+ const subpath = specifier.slice(match.length);
233
+ // Resolve the mapping target against the map's base, then the subpath against that
234
+ const resolvedTarget = new URL(target, this.baseUrl);
235
+ return new URL(subpath, resolvedTarget).href;
236
+ }
237
+ } else if (typeof base === 'string') {
238
+ return URL.parse(specifier, base)?.href ?? null;
239
+ } else {
240
+ return null;
241
+ }
242
+ }
243
+
203
244
  async importLocalPackage(name = 'package.json', { signal } = {}) {
204
245
  const path = join(process.cwd(), name);
205
246
  const pkg = await readFile(path, { encoding: 'utf8', signal });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shgysk8zer0/importmap",
3
- "version": "1.7.4",
3
+ "version": "1.7.6",
4
4
  "engines": {
5
5
  "node": ">=20.10.0"
6
6
  },
@@ -71,7 +71,7 @@
71
71
  },
72
72
  "dependencies": {
73
73
  "@shgysk8zer0/npm-utils": "^1.1.3",
74
- "@shgysk8zer0/polyfills": "^0.5.6",
74
+ "@shgysk8zer0/polyfills": "^0.6.0",
75
75
  "commander": "^14.0.2"
76
76
  }
77
77
  }