@shgysk8zer0/importmap 1.8.20 → 1.9.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/CHANGELOG.md +16 -0
- package/cli.cjs +3 -4
- package/cli.js +3 -4
- package/consts.js +1 -2
- package/html.cjs +6 -7
- package/html.js +6 -7
- package/imap.js +195 -0
- package/importmap.cjs +2 -189
- package/importmap.js +2 -183
- package/importmap.json +1 -0
- package/index.cjs +54 -19
- package/index.js +51 -16
- package/package.json +3 -2
- package/unpkg.js +9 -1
package/imap.js
ADDED
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
import { SHA256, SHA384, SHA512, DEFAULT_ALGO, BASE64 } from './hash.js';
|
|
2
|
+
|
|
3
|
+
export class Importmap {
|
|
4
|
+
#imports = {};
|
|
5
|
+
#scopes = {};
|
|
6
|
+
#base = globalThis?.document?.baseURI ?? null;
|
|
7
|
+
|
|
8
|
+
constructor({ imports: i = {}, scopes: s = {} } = {}) {
|
|
9
|
+
this.#imports = i;
|
|
10
|
+
this.#scopes = s;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
get imports() {
|
|
14
|
+
return structuredClone(this.#imports);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
get scopes() {
|
|
18
|
+
return structuredClone(this.#scopes);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
delete(key) {
|
|
22
|
+
return Reflect.deleteProperty(this.#imports, key);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
get(key) {
|
|
26
|
+
return Reflect.get(this.#imports, key);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
has(key) {
|
|
30
|
+
return Reflect.has(this.#imports, key);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
set(key, newValue) {
|
|
34
|
+
return Reflect.set(this.#imports, key, newValue);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
toJSON() {
|
|
38
|
+
return { imports: this.#imports, scopes: this.#scopes };
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
toString() {
|
|
42
|
+
return JSON.stringify(this);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
get baseUrl() {
|
|
46
|
+
return this.#base;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
set baseUrl(val) {
|
|
50
|
+
if (typeof val === 'string' && URL.canParse(val)) {
|
|
51
|
+
this.#base = val;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
resolve(specifier, base = this.baseUrl) {
|
|
56
|
+
console.log({ specifier, base });
|
|
57
|
+
if (specifier instanceof URL) {
|
|
58
|
+
return specifier.href;
|
|
59
|
+
} else if (typeof specifier !== 'string') {
|
|
60
|
+
return null;
|
|
61
|
+
} else if (this.has(specifier)) {
|
|
62
|
+
return URL.parse(this.get(specifier), base)?.href ?? null;
|
|
63
|
+
} else if (URL.canParse(specifier)) {
|
|
64
|
+
return specifier;
|
|
65
|
+
} else if (! specifier.startsWith('.')) {
|
|
66
|
+
// Find the longest match
|
|
67
|
+
const matches = Object.keys(this.imports)
|
|
68
|
+
.filter(key => key.endsWith('/') && specifier.startsWith(key))
|
|
69
|
+
.sort((a, b) => b.length - a.length);
|
|
70
|
+
|
|
71
|
+
if (matches.length === 0) {
|
|
72
|
+
return null;
|
|
73
|
+
} else {
|
|
74
|
+
const imports = this.#imports;
|
|
75
|
+
const match = matches[0];
|
|
76
|
+
const target = imports[match];
|
|
77
|
+
const subpath = specifier.slice(match.length);
|
|
78
|
+
// Resolve the mapping target against the map's base, then the subpath against that
|
|
79
|
+
const resolvedTarget = new URL(target, base);
|
|
80
|
+
return new URL(subpath, resolvedTarget).href;
|
|
81
|
+
}
|
|
82
|
+
} else if (typeof base === 'string') {
|
|
83
|
+
return URL.parse(specifier, base)?.href ?? null;
|
|
84
|
+
} else {
|
|
85
|
+
return null;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
async importLocalPackage(name = 'package.json', { signal } = {}) {
|
|
90
|
+
const [{ join }, { readFile }] = await Promise.all([
|
|
91
|
+
import('node:path'),
|
|
92
|
+
import('node:fs/promises'),
|
|
93
|
+
]);
|
|
94
|
+
|
|
95
|
+
const path = join(process.cwd(), name);
|
|
96
|
+
const pkg = await readFile(path, { encoding: 'utf8', signal });
|
|
97
|
+
|
|
98
|
+
return this.setLocalPackage(JSON.parse(pkg));
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
setLocalPackage({ name, module, exports = {} }) {
|
|
102
|
+
if (typeof name !== 'string') {
|
|
103
|
+
return false;
|
|
104
|
+
} else if (typeof exports === 'string' ) {
|
|
105
|
+
this.set(name, exports);
|
|
106
|
+
return true;
|
|
107
|
+
} else if (typeof exports === 'object') {
|
|
108
|
+
Object.entries(exports).forEach(([key, value]) => {
|
|
109
|
+
if (key.startsWith('.')) {
|
|
110
|
+
const importKey = key === '.' ? name : `${name}${key.substring(1)}`;
|
|
111
|
+
const resolved = typeof value === 'string' ? value : value.import ?? value.default;
|
|
112
|
+
|
|
113
|
+
if (typeof resolved === 'string' && resolved.startsWith('./')) {
|
|
114
|
+
if (importKey.includes('*') && resolved.includes('*')) {
|
|
115
|
+
const [prefix, suffix] = importKey.split('*');
|
|
116
|
+
|
|
117
|
+
if (resolved.endsWith('*' + suffix)) {
|
|
118
|
+
this.set(prefix, resolved.substring(1).replace('*' + suffix, ''));
|
|
119
|
+
}
|
|
120
|
+
} else {
|
|
121
|
+
this.set(importKey, resolved.substring(1));
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
return true;
|
|
128
|
+
} else if (typeof module === 'string') {
|
|
129
|
+
this.set(name, module);
|
|
130
|
+
return true;
|
|
131
|
+
} else {
|
|
132
|
+
this.set(name, '/');
|
|
133
|
+
return true;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
async getScript({ algo = DEFAULT_ALGO, alphabet = BASE64, name, signal } = {}) {
|
|
138
|
+
const integrity = await this.getIntegrity({ algo, alphabet, signal });
|
|
139
|
+
|
|
140
|
+
return typeof name === 'string'
|
|
141
|
+
? `<script type="importmap" name="${name}" integrity="${integrity}">${JSON.stringify(this)}</script>`
|
|
142
|
+
: `<script type="importmap" integrity="${integrity}">${JSON.stringify(this)}</script>`;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
async getIntegrity({ algo = DEFAULT_ALGO, alphabet = BASE64, signal } = {}) {
|
|
146
|
+
if (signal instanceof AbortSignal && signal.aborted) {
|
|
147
|
+
throw signal.reason;
|
|
148
|
+
} else {
|
|
149
|
+
const prefix = algo.toLowerCase().replace('-', '') + '-';
|
|
150
|
+
const encoded = new TextEncoder().encode(this);
|
|
151
|
+
const hash = await crypto.subtle.digest(algo, encoded);
|
|
152
|
+
|
|
153
|
+
return prefix + new Uint8Array(hash).toBase64({ alphabet });
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
static get SHA256() {
|
|
158
|
+
return SHA256;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
static get SHA384() {
|
|
162
|
+
return SHA384;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
static get SHA512() {
|
|
166
|
+
return SHA512;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
static importFromScript(script) {
|
|
170
|
+
if (! ('HTMLScriptElement' in globalThis)) {
|
|
171
|
+
throw new Error('Attempting to import from the wrong environment.');
|
|
172
|
+
} else if (typeof script === 'string') {
|
|
173
|
+
return this.importFromScript(globalThis.document.scripts.namedItem(script));
|
|
174
|
+
} else if (typeof script === 'number') {
|
|
175
|
+
return this.importFromScript(globalThis.document.scripts.item(script));
|
|
176
|
+
} else if (! (script instanceof globalThis.HTMLScriptElement)) {
|
|
177
|
+
throw new TypeError('Can only import from a <script>.');
|
|
178
|
+
} else if (script.type !== 'importmap') {
|
|
179
|
+
throw new TypeError(`Cannot import importmap from a <script type="${script.type ?? 'application/jacascript'}">.`);
|
|
180
|
+
} else {
|
|
181
|
+
return new this(JSON.parse(script.textContent));
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
static async importFromFile(path = 'importmap.json', { signal } = {}) {
|
|
186
|
+
const [{ join }, { readFile }] = await Promise.all([
|
|
187
|
+
import('node:path'),
|
|
188
|
+
import('node:fs/promises'),
|
|
189
|
+
]);
|
|
190
|
+
const fullPath = join(process.cwd(), path);
|
|
191
|
+
const importmap = await readFile(fullPath, { encoding: 'utf8', signal });
|
|
192
|
+
|
|
193
|
+
return new Importmap(JSON.parse(importmap));
|
|
194
|
+
}
|
|
195
|
+
}
|
package/importmap.cjs
CHANGED
|
@@ -1,192 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
3
|
+
var importmap = JSON.parse('{\n "imports": {\n "@node/": "/node_modules/",\n "@shgysk8zer0/kazoo/": "https://unpkg.com/@shgysk8zer0/kazoo@1.0.11/",\n "@shgysk8zer0/konami": "https://unpkg.com/@shgysk8zer0/konami@1.1.2/konami.js",\n "@shgysk8zer0/polyfills": "https://unpkg.com/@shgysk8zer0/polyfills@0.6.3/browser.min.js",\n "@shgysk8zer0/polyfills/": "https://unpkg.com/@shgysk8zer0/polyfills@0.6.3/",\n "@shgysk8zer0/jwk-utils": "https://unpkg.com/@shgysk8zer0/jwk-utils@1.1.5/jwk-utils.min.js",\n "@shgysk8zer0/jwk-utils/": "https://unpkg.com/@shgysk8zer0/jwk-utils@1.1.5/",\n "@shgysk8zer0/jswaggersheets": "https://unpkg.com/@shgysk8zer0/jswaggersheets@1.1.0/swagger.js",\n "@shgysk8zer0/jswaggersheets/": "https://unpkg.com/@shgysk8zer0/jswaggersheets@1.1.0/",\n "@shgysk8zer0/jss/": "https://unpkg.com/@shgysk8zer0/jss@1.0.1/",\n "@shgysk8zer0/consts/": "https://unpkg.com/@shgysk8zer0/consts@1.0.8/",\n "@shgysk8zer0/http/": "https://unpkg.com/@shgysk8zer0/http@1.0.5/",\n "@shgysk8zer0/http-status": "https://unpkg.com/@shgysk8zer0/http-status@1.1.4/http-status.js",\n "@shgysk8zer0/aes-gcm": "https://unpkg.com/@shgysk8zer0/aes-gcm@1.0.9/aes-gcm.min.js",\n "@shgysk8zer0/aes-gcm/": "https://unpkg.com/@shgysk8zer0/aes-gcm@1.0.9/",\n "@shgysk8zer0/squish": "https://unpkg.com/@shgysk8zer0/squish@1.0.2/squish.min.js",\n "@shgysk8zer0/squish/": "https://unpkg.com/@shgysk8zer0/squish@1.0.2/",\n "@shgysk8zer0/suid": "https://unpkg.com/@shgysk8zer0/suid@1.0.0/suid.min.js",\n "@shgysk8zer0/suid/": "https://unpkg.com/@shgysk8zer0/suid@1.0.0/",\n "@shgysk8zer0/geoutils": "https://unpkg.com/@shgysk8zer0/geoutils@1.0.6/geoutils.min.js",\n "@shgysk8zer0/geoutils/": "https://unpkg.com/@shgysk8zer0/geoutils@1.0.6/",\n "@shgysk8zer0/core-css/": "https://unpkg.com/@shgysk8zer0/core-css@3.0.0/",\n "@shgysk8zer0/signals": "https://unpkg.com/@shgysk8zer0/signals@0.0.3/signals.min.js",\n "@shgysk8zer0/signals/": "https://unpkg.com/@shgysk8zer0/signals@0.0.3/",\n "@shgysk8zer0/importmap/": "https://unpkg.com/@shgysk8zer0/importmap@1.9.1/",\n "@aegisjsproject/trusted-types": "https://unpkg.com/@aegisjsproject/trusted-types@1.0.2/bundle.min.js",\n "@aegisjsproject/trusted-types/": "https://unpkg.com/@aegisjsproject/trusted-types@1.0.2/",\n "@aegisjsproject/parsers": "https://unpkg.com/@aegisjsproject/parsers@0.1.6/bundle.min.js",\n "@aegisjsproject/parsers/": "https://unpkg.com/@aegisjsproject/parsers@0.1.6/",\n "@aegisjsproject/sanitizer": "https://unpkg.com/@aegisjsproject/sanitizer@0.2.4/sanitizer.js",\n "@aegisjsproject/sanitizer/": "https://unpkg.com/@aegisjsproject/sanitizer@0.2.4/",\n "@aegisjsproject/core": "https://unpkg.com/@aegisjsproject/core@0.2.34/core.js",\n "@aegisjsproject/core/": "https://unpkg.com/@aegisjsproject/core@0.2.34/",\n "@aegisjsproject/styles": "https://unpkg.com/@aegisjsproject/styles@0.3.2/styles.js",\n "@aegisjsproject/styles/": "https://unpkg.com/@aegisjsproject/styles@0.3.2/",\n "@aegisjsproject/component": "https://unpkg.com/@aegisjsproject/component@0.1.8/component.js",\n "@aegisjsproject/component/": "https://unpkg.com/@aegisjsproject/component@0.1.8/",\n "@aegisjsproject/markdown": "https://unpkg.com/@aegisjsproject/markdown@0.1.7/markdown.min.js",\n "@aegisjsproject/markdown/": "https://unpkg.com/@aegisjsproject/markdown@0.1.7/",\n "@aegisjsproject/aegis-md": "https://unpkg.com/@aegisjsproject/aegis-md@0.0.4/aegis-md.js",\n "@aegisjsproject/aegis-md/": "https://unpkg.com/@aegisjsproject/aegis-md@0.0.4/",\n "@aegisjsproject/url": "https://unpkg.com/@aegisjsproject/url@1.0.3/url.min.js",\n "@aegisjsproject/url/": "https://unpkg.com/@aegisjsproject/url@1.0.3/",\n "@aegisjsproject/idb/": "https://unpkg.com/@aegisjsproject/idb@1.0.6/",\n "@aegisjsproject/idb": "https://unpkg.com/@aegisjsproject/idb@1.0.6/idb.min.js",\n "@aegisjsproject/otp/": "https://unpkg.com/@aegisjsproject/otp@1.0.2/",\n "@aegisjsproject/otp": "https://unpkg.com/@aegisjsproject/otp@1.0.2/otp.min.js",\n "@aegisjsproject/md-editor": "https://unpkg.com/@aegisjsproject/md-editor@1.0.0/md-editor.js",\n "@aegisjsproject/md-editor/": "https://unpkg.com/@aegisjsproject/md-editor@1.0.0/",\n "@aegisjsproject/barcodescanner": "https://unpkg.com/@aegisjsproject/barcodescanner@1.2.3/scanner.min.js",\n "@aegisjsproject/barcodescanner/": "https://unpkg.com/@aegisjsproject/barcodescanner@1.2.3/",\n "@shgysk8zer0/components/": "https://unpkg.com/@shgysk8zer0/components@0.3.23/",\n "@aegisjsproject/state": "https://unpkg.com/@aegisjsproject/state@1.0.7/state.mjs",\n "@aegisjsproject/state/": "https://unpkg.com/@aegisjsproject/state@1.0.7/",\n "@aegisjsproject/router": "https://unpkg.com/@aegisjsproject/router@1.1.15/router.mjs",\n "@aegisjsproject/router/": "https://unpkg.com/@aegisjsproject/router@1.1.15/",\n "@aegisjsproject/callback-registry": "https://unpkg.com/@aegisjsproject/callback-registry@2.0.4/callbackRegistry.js",\n "@aegisjsproject/callback-registry/": "https://unpkg.com/@aegisjsproject/callback-registry@2.0.4/",\n "@aegisjsproject/attempt": "https://unpkg.com/@aegisjsproject/attempt@1.0.7/attempt.js",\n "@aegisjsproject/attempt/": "https://unpkg.com/@aegisjsproject/attempt@1.0.7/",\n "@aegisjsproject/secret-store": "https://unpkg.com/@aegisjsproject/secret-store@1.1.1/commands.min.js",\n "@aegisjsproject/commands/": "https://unpkg.com/@aegisjsproject/commands@1.0.2/",\n "@aegisjsproject/commands": "https://unpkg.com/@aegisjsproject/commands@1.0.2/commands.min.js",\n "@aegisjsproject/firebase-account-routes": "https://unpkg.com/@aegisjsproject/firebase-account-routes@0.0.6/main.js",\n "@aegisjsproject/firebase-account-routes/": "https://unpkg.com/@aegisjsproject/firebase-account-routes@0.0.6/",\n "@aegisjsproject/secret-store/": "https://unpkg.com/@aegisjsproject/secret-store@1.1.1/",\n "@aegisjsproject/qr-encoder": "https://unpkg.com/@aegisjsproject/qr-encoder@1.0.1/index.min.js",\n "@aegisjsproject/qr-encoder/": "https://unpkg.com/@aegisjsproject/qr-encoder@1.0.1/",\n "@aegisjsproject/escape": "https://unpkg.com/@aegisjsproject/escape@1.0.4/index.min.js",\n "@aegisjsproject/escape/": "https://unpkg.com/@aegisjsproject/escape@1.0.4/",\n "@aegisjsproject/disposable": "https://unpkg.com/@aegisjsproject/disposable@1.0.3/disposable.min.js",\n "@aegisjsproject/disposable/": "https://unpkg.com/@aegisjsproject/disposable@1.0.3/",\n "@aegisjsproject/iota": "https://unpkg.com/@aegisjsproject/iota@1.0.12/iota.min.js",\n "@aegisjsproject/iota/": "https://unpkg.com/@aegisjsproject/iota@1.0.12/",\n "@aegisjsproject/disposable-registry": "https://unpkg.com/@aegisjsproject/disposable-registry@1.0.2/registry.js",\n "@aegisjsproject/disposable-registry/": "https://unpkg.com/@aegisjsproject/disposable-registry@1.0.2/",\n "@aegisjsproject/hermes": "https://unpkg.com/@aegisjsproject/hermes@1.0.2/hermes.js",\n "@aegisjsproject/hermes/": "https://unpkg.com/@aegisjsproject/hermes@1.0.2/",\n "@kernvalley/components/": "https://unpkg.com/@kernvalley/components@2.0.10/",\n "@webcomponents/custom-elements": "https://unpkg.com/@webcomponents/custom-elements@1.6.0/custom-elements.min.js",\n "leaflet": "https://unpkg.com/leaflet@1.9.4/dist/leaflet-src.esm.js",\n "leaflet/": "https://unpkg.com/leaflet@1.9.4/dist/",\n "urlpattern-polyfill": "https://unpkg.com/urlpattern-polyfill@10.1.0/index.js",\n "highlight.js": "https://unpkg.com/@highlightjs/cdn-assets@11.11.1/es/core.min.js",\n "highlight.js/": "https://unpkg.com/@highlightjs/cdn-assets@11.11.1/es/",\n "highlight.js/styles/": "https://unpkg.com/@highlightjs/cdn-assets@11.11.1/styles/",\n "@highlightjs/cdn-assets": "https://unpkg.com/@highlightjs/cdn-assets@11.11.1/es/core.min.js",\n "@highlightjs/cdn-assets/": "https://unpkg.com/@highlightjs/cdn-assets@11.11.1/es/",\n "@highlightjs/cdn-assets/styles/": "https://unpkg.com/@highlightjs/cdn-assets@11.11.1/styles/",\n "marked": "https://unpkg.com/marked@18.0.0/lib/marked.esm.js",\n "marked-highlight": "https://unpkg.com/marked-highlight@2.2.4/src/index.js",\n "yaml": "https://unpkg.com/yaml@2.8.3/browser/dist/index.js",\n "yaml/": "https://unpkg.com/yaml@2.8.3/browser/dist/",\n "firebase/": "https://www.gstatic.com/firebasejs/10.12.1/",\n "firebase/app": "https://www.gstatic.com/firebasejs/10.12.1/firebase-app.js",\n "firebase/app-check": "https://www.gstatic.com/firebasejs/10.12.1/firebase-app-check.js",\n "firebase/auth": "https://www.gstatic.com/firebasejs/10.12.1/firebase-auth.js",\n "firebase/database": "https://www.gstatic.com/firebasejs/10.12.1/firebase-database.js",\n "firebase/firestore": "https://www.gstatic.com/firebasejs/10.12.1/firebase-firestore.js",\n "firebase/functions": "https://www.gstatic.com/firebasejs/10.12.1/firebase-functions.js",\n "firebase/messaging": "https://www.gstatic.com/firebasejs/10.12.1/firebase-messaging.js",\n "firebase/performance": "https://www.gstatic.com/firebasejs/10.12.1/firebase-performance.js",\n "firebase/remote-config": "https://www.gstatic.com/firebasejs/10.12.1/firebase-remote-config.js",\n "firebase/storage": "https://www.gstatic.com/firebasejs/10.12.1/firebase-storage.js",\n "firebase/analytics": "https://www.gstatic.com/firebasejs/10.12.1/firebase-analytics.js",\n "qr": "https://unpkg.com/qr@0.5.5/index.js",\n "qr/": "https://unpkg.com/qr@0.5.5/",\n "lit": "https://unpkg.com/lit@3.3.2/index.js",\n "lit/": "https://unpkg.com/lit@3.3.2/",\n "lit-html": "https://unpkg.com/lit-html@3.3.2/lit-html.js",\n "lit-html/": "https://unpkg.com/lit-html@3.3.2/",\n "lit-element": "https://unpkg.com/lit-element@4.2.2/lit-element.js",\n "lit-element/": "https://unpkg.com/lit-element@4.2.2/",\n "@lit/reactive-element": "https://unpkg.com/@lit/reactive-element@2.1.2/reactive-element.js",\n "@lit/reactive-element/": "https://unpkg.com/@lit/reactive-element@2.1.2/",\n "@awesome.me/webawesome/": "https://unpkg.com/@awesome.me/webawesome@3.5.0/",\n "normalize.css": "https://unpkg.com/normalize.css@8.0.1/normalize.css"\n },\n "scopes": {}\n}');
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
var promises = require('node:fs/promises');
|
|
7
|
-
require('@shgysk8zer0/polyfills');
|
|
8
|
-
|
|
9
|
-
var json = JSON.parse('{\n "imports": {\n "@node/": "/node_modules/",\n "@shgysk8zer0/kazoo/": "https://unpkg.com/@shgysk8zer0/kazoo@1.0.11/",\n "@shgysk8zer0/konami": "https://unpkg.com/@shgysk8zer0/konami@1.1.2/konami.js",\n "@shgysk8zer0/polyfills": "https://unpkg.com/@shgysk8zer0/polyfills@0.6.3/browser.min.js",\n "@shgysk8zer0/polyfills/": "https://unpkg.com/@shgysk8zer0/polyfills@0.6.3/",\n "@shgysk8zer0/jwk-utils": "https://unpkg.com/@shgysk8zer0/jwk-utils@1.1.5/jwk-utils.min.js",\n "@shgysk8zer0/jwk-utils/": "https://unpkg.com/@shgysk8zer0/jwk-utils@1.1.5/",\n "@shgysk8zer0/jswaggersheets": "https://unpkg.com/@shgysk8zer0/jswaggersheets@1.1.0/swagger.js",\n "@shgysk8zer0/jswaggersheets/": "https://unpkg.com/@shgysk8zer0/jswaggersheets@1.1.0/",\n "@shgysk8zer0/jss/": "https://unpkg.com/@shgysk8zer0/jss@1.0.1/",\n "@shgysk8zer0/consts/": "https://unpkg.com/@shgysk8zer0/consts@1.0.8/",\n "@shgysk8zer0/http/": "https://unpkg.com/@shgysk8zer0/http@1.0.5/",\n "@shgysk8zer0/http-status": "https://unpkg.com/@shgysk8zer0/http-status@1.1.4/http-status.js",\n "@shgysk8zer0/aes-gcm": "https://unpkg.com/@shgysk8zer0/aes-gcm@1.0.9/aes-gcm.min.js",\n "@shgysk8zer0/aes-gcm/": "https://unpkg.com/@shgysk8zer0/aes-gcm@1.0.9/",\n "@shgysk8zer0/squish": "https://unpkg.com/@shgysk8zer0/squish@1.0.2/squish.min.js",\n "@shgysk8zer0/squish/": "https://unpkg.com/@shgysk8zer0/squish@1.0.2/",\n "@shgysk8zer0/suid": "https://unpkg.com/@shgysk8zer0/suid@1.0.0/suid.min.js",\n "@shgysk8zer0/suid/": "https://unpkg.com/@shgysk8zer0/suid@1.0.0/",\n "@shgysk8zer0/geoutils": "https://unpkg.com/@shgysk8zer0/geoutils@1.0.6/geoutils.min.js",\n "@shgysk8zer0/geoutils/": "https://unpkg.com/@shgysk8zer0/geoutils@1.0.6/",\n "@shgysk8zer0/core-css/": "https://unpkg.com/@shgysk8zer0/core-css@3.0.0/",\n "@shgysk8zer0/signals": "https://unpkg.com/@shgysk8zer0/signals@0.0.3/signals.min.js",\n "@shgysk8zer0/signals/": "https://unpkg.com/@shgysk8zer0/signals@0.0.3/",\n "@aegisjsproject/trusted-types": "https://unpkg.com/@aegisjsproject/trusted-types@1.0.2/bundle.min.js",\n "@aegisjsproject/trusted-types/": "https://unpkg.com/@aegisjsproject/trusted-types@1.0.2/",\n "@aegisjsproject/parsers": "https://unpkg.com/@aegisjsproject/parsers@0.1.6/bundle.min.js",\n "@aegisjsproject/parsers/": "https://unpkg.com/@aegisjsproject/parsers@0.1.6/",\n "@aegisjsproject/sanitizer": "https://unpkg.com/@aegisjsproject/sanitizer@0.2.4/sanitizer.js",\n "@aegisjsproject/sanitizer/": "https://unpkg.com/@aegisjsproject/sanitizer@0.2.4/",\n "@aegisjsproject/core": "https://unpkg.com/@aegisjsproject/core@0.2.34/core.js",\n "@aegisjsproject/core/": "https://unpkg.com/@aegisjsproject/core@0.2.34/",\n "@aegisjsproject/styles": "https://unpkg.com/@aegisjsproject/styles@0.3.2/styles.js",\n "@aegisjsproject/styles/": "https://unpkg.com/@aegisjsproject/styles@0.3.2/",\n "@aegisjsproject/component": "https://unpkg.com/@aegisjsproject/component@0.1.8/component.js",\n "@aegisjsproject/component/": "https://unpkg.com/@aegisjsproject/component@0.1.8/",\n "@aegisjsproject/markdown": "https://unpkg.com/@aegisjsproject/markdown@0.1.7/markdown.min.js",\n "@aegisjsproject/markdown/": "https://unpkg.com/@aegisjsproject/markdown@0.1.7/",\n "@aegisjsproject/aegis-md": "https://unpkg.com/@aegisjsproject/aegis-md@0.0.4/aegis-md.js",\n "@aegisjsproject/aegis-md/": "https://unpkg.com/@aegisjsproject/aegis-md@0.0.4/",\n "@aegisjsproject/url": "https://unpkg.com/@aegisjsproject/url@1.0.3/url.min.js",\n "@aegisjsproject/url/": "https://unpkg.com/@aegisjsproject/url@1.0.3/",\n "@aegisjsproject/idb/": "https://unpkg.com/@aegisjsproject/idb@1.0.6/",\n "@aegisjsproject/idb": "https://unpkg.com/@aegisjsproject/idb@1.0.6/idb.min.js",\n "@aegisjsproject/otp/": "https://unpkg.com/@aegisjsproject/otp@1.0.2/",\n "@aegisjsproject/otp": "https://unpkg.com/@aegisjsproject/otp@1.0.2/otp.min.js",\n "@aegisjsproject/md-editor": "https://unpkg.com/@aegisjsproject/md-editor@1.0.0/md-editor.js",\n "@aegisjsproject/md-editor/": "https://unpkg.com/@aegisjsproject/md-editor@1.0.0/",\n "@aegisjsproject/barcodescanner": "https://unpkg.com/@aegisjsproject/barcodescanner@1.2.3/scanner.min.js",\n "@aegisjsproject/barcodescanner/": "https://unpkg.com/@aegisjsproject/barcodescanner@1.2.3/",\n "@shgysk8zer0/components/": "https://unpkg.com/@shgysk8zer0/components@0.3.23/",\n "@aegisjsproject/state": "https://unpkg.com/@aegisjsproject/state@1.0.7/state.mjs",\n "@aegisjsproject/state/": "https://unpkg.com/@aegisjsproject/state@1.0.7/",\n "@aegisjsproject/router": "https://unpkg.com/@aegisjsproject/router@1.1.15/router.mjs",\n "@aegisjsproject/router/": "https://unpkg.com/@aegisjsproject/router@1.1.15/",\n "@aegisjsproject/callback-registry": "https://unpkg.com/@aegisjsproject/callback-registry@2.0.4/callbackRegistry.js",\n "@aegisjsproject/callback-registry/": "https://unpkg.com/@aegisjsproject/callback-registry@2.0.4/",\n "@aegisjsproject/attempt": "https://unpkg.com/@aegisjsproject/attempt@1.0.7/attempt.js",\n "@aegisjsproject/attempt/": "https://unpkg.com/@aegisjsproject/attempt@1.0.7/",\n "@aegisjsproject/secret-store": "https://unpkg.com/@aegisjsproject/secret-store@1.1.1/commands.min.js",\n "@aegisjsproject/commands/": "https://unpkg.com/@aegisjsproject/commands@1.0.2/",\n "@aegisjsproject/commands": "https://unpkg.com/@aegisjsproject/commands@1.0.2/commands.min.js",\n "@aegisjsproject/firebase-account-routes": "https://unpkg.com/@aegisjsproject/firebase-account-routes@0.0.6/main.js",\n "@aegisjsproject/firebase-account-routes/": "https://unpkg.com/@aegisjsproject/firebase-account-routes@0.0.6/",\n "@aegisjsproject/secret-store/": "https://unpkg.com/@aegisjsproject/secret-store@1.1.1/",\n "@aegisjsproject/qr-encoder": "https://unpkg.com/@aegisjsproject/qr-encoder@1.0.1/index.min.js",\n "@aegisjsproject/qr-encoder/": "https://unpkg.com/@aegisjsproject/qr-encoder@1.0.1/",\n "@aegisjsproject/escape": "https://unpkg.com/@aegisjsproject/escape@1.0.4/index.min.js",\n "@aegisjsproject/escape/": "https://unpkg.com/@aegisjsproject/escape@1.0.4/",\n "@aegisjsproject/disposable": "https://unpkg.com/@aegisjsproject/disposable@1.0.3/disposable.min.js",\n "@aegisjsproject/disposable/": "https://unpkg.com/@aegisjsproject/disposable@1.0.3/",\n "@aegisjsproject/iota": "https://unpkg.com/@aegisjsproject/iota@1.0.12/iota.min.js",\n "@aegisjsproject/iota/": "https://unpkg.com/@aegisjsproject/iota@1.0.12/",\n "@aegisjsproject/disposable-registry": "https://unpkg.com/@aegisjsproject/disposable-registry@1.0.2/registry.js",\n "@aegisjsproject/disposable-registry/": "https://unpkg.com/@aegisjsproject/disposable-registry@1.0.2/",\n "@aegisjsproject/hermes": "https://unpkg.com/@aegisjsproject/hermes@1.0.2/hermes.js",\n "@aegisjsproject/hermes/": "https://unpkg.com/@aegisjsproject/hermes@1.0.2/",\n "@kernvalley/components/": "https://unpkg.com/@kernvalley/components@2.0.10/",\n "@webcomponents/custom-elements": "https://unpkg.com/@webcomponents/custom-elements@1.6.0/custom-elements.min.js",\n "leaflet": "https://unpkg.com/leaflet@1.9.4/dist/leaflet-src.esm.js",\n "leaflet/": "https://unpkg.com/leaflet@1.9.4/dist/",\n "urlpattern-polyfill": "https://unpkg.com/urlpattern-polyfill@10.1.0/index.js",\n "highlight.js": "https://unpkg.com/@highlightjs/cdn-assets@11.11.1/es/core.min.js",\n "highlight.js/": "https://unpkg.com/@highlightjs/cdn-assets@11.11.1/es/",\n "highlight.js/styles/": "https://unpkg.com/@highlightjs/cdn-assets@11.11.1/styles/",\n "@highlightjs/cdn-assets": "https://unpkg.com/@highlightjs/cdn-assets@11.11.1/es/core.min.js",\n "@highlightjs/cdn-assets/": "https://unpkg.com/@highlightjs/cdn-assets@11.11.1/es/",\n "@highlightjs/cdn-assets/styles/": "https://unpkg.com/@highlightjs/cdn-assets@11.11.1/styles/",\n "marked": "https://unpkg.com/marked@18.0.0/lib/marked.esm.js",\n "marked-highlight": "https://unpkg.com/marked-highlight@2.2.4/src/index.js",\n "yaml": "https://unpkg.com/yaml@2.8.3/browser/dist/index.js",\n "yaml/": "https://unpkg.com/yaml@2.8.3/browser/dist/",\n "firebase/": "https://www.gstatic.com/firebasejs/10.12.1/",\n "firebase/app": "https://www.gstatic.com/firebasejs/10.12.1/firebase-app.js",\n "firebase/app-check": "https://www.gstatic.com/firebasejs/10.12.1/firebase-app-check.js",\n "firebase/auth": "https://www.gstatic.com/firebasejs/10.12.1/firebase-auth.js",\n "firebase/database": "https://www.gstatic.com/firebasejs/10.12.1/firebase-database.js",\n "firebase/firestore": "https://www.gstatic.com/firebasejs/10.12.1/firebase-firestore.js",\n "firebase/functions": "https://www.gstatic.com/firebasejs/10.12.1/firebase-functions.js",\n "firebase/messaging": "https://www.gstatic.com/firebasejs/10.12.1/firebase-messaging.js",\n "firebase/performance": "https://www.gstatic.com/firebasejs/10.12.1/firebase-performance.js",\n "firebase/remote-config": "https://www.gstatic.com/firebasejs/10.12.1/firebase-remote-config.js",\n "firebase/storage": "https://www.gstatic.com/firebasejs/10.12.1/firebase-storage.js",\n "firebase/analytics": "https://www.gstatic.com/firebasejs/10.12.1/firebase-analytics.js",\n "qr": "https://unpkg.com/qr@0.5.5/index.js",\n "qr/": "https://unpkg.com/qr@0.5.5/",\n "lit": "https://unpkg.com/lit@3.3.2/index.js",\n "lit/": "https://unpkg.com/lit@3.3.2/",\n "lit-html": "https://unpkg.com/lit-html@3.3.2/lit-html.js",\n "lit-html/": "https://unpkg.com/lit-html@3.3.2/",\n "lit-element": "https://unpkg.com/lit-element@4.2.2/lit-element.js",\n "lit-element/": "https://unpkg.com/lit-element@4.2.2/",\n "@lit/reactive-element": "https://unpkg.com/@lit/reactive-element@2.1.2/reactive-element.js",\n "@lit/reactive-element/": "https://unpkg.com/@lit/reactive-element@2.1.2/",\n "@awesome.me/webawesome/": "https://unpkg.com/@awesome.me/webawesome@3.5.0/",\n "normalize.css": "https://unpkg.com/normalize.css@8.0.1/normalize.css"\n },\n "scopes": {}\n}');
|
|
10
|
-
|
|
11
|
-
const SHA256 = 'SHA-256';
|
|
12
|
-
const SHA384 = 'SHA-384';
|
|
13
|
-
const SHA512 = 'SHA-512';
|
|
14
|
-
const DEFAULT_ALGO = SHA384;
|
|
15
|
-
|
|
16
|
-
const BASE64 = 'base64';
|
|
17
|
-
|
|
18
|
-
const { imports, scopes } = json;
|
|
19
|
-
|
|
20
|
-
class Importmap {
|
|
21
|
-
#imports = {};
|
|
22
|
-
#scopes = {};
|
|
23
|
-
#base;
|
|
24
|
-
|
|
25
|
-
constructor({ imports: i = imports, scopes: s = scopes } = {}) {
|
|
26
|
-
this.#imports = i;
|
|
27
|
-
this.#scopes = s;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
get imports() {
|
|
31
|
-
return structuredClone(this.#imports);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
get scopes() {
|
|
35
|
-
return structuredClone(this.#scopes);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
delete(key) {
|
|
39
|
-
return Reflect.deleteProperty(this.#imports, key);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
get(key) {
|
|
43
|
-
return Reflect.get(this.#imports, key);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
has(key) {
|
|
47
|
-
return Reflect.has(this.#imports, key);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
set(key, newValue) {
|
|
51
|
-
return Reflect.set(this.#imports, key, newValue);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
toJSON() {
|
|
55
|
-
return { imports: this.#imports, scopes: this.#scopes };
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
toString() {
|
|
59
|
-
return JSON.stringify(this);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
get baseUrl() {
|
|
63
|
-
return this.#base;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
set baseUrl(val) {
|
|
67
|
-
if (typeof val === 'string' && URL.canParse(val)) {
|
|
68
|
-
this.#base = val;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
resolve(specifier, base = this.baseUrl) {
|
|
73
|
-
if (specifier instanceof URL) {
|
|
74
|
-
return specifier.href;
|
|
75
|
-
} else if (typeof specifier !== 'string') {
|
|
76
|
-
return null;
|
|
77
|
-
} else if (this.has(specifier)) {
|
|
78
|
-
return URL.parse(this.get(specifier), this.baseUrl)?.href ?? null;
|
|
79
|
-
} else if (URL.canParse(specifier)) {
|
|
80
|
-
return specifier;
|
|
81
|
-
} else if (! specifier.startsWith('.')) {
|
|
82
|
-
// Find the longest match
|
|
83
|
-
const matches = Object.keys(this.imports)
|
|
84
|
-
.filter(key => key.endsWith('/') && specifier.startsWith(key))
|
|
85
|
-
.sort((a, b) => b.length - a.length);
|
|
86
|
-
|
|
87
|
-
if (matches.length === 0) {
|
|
88
|
-
return null;
|
|
89
|
-
} else {
|
|
90
|
-
const match = matches[0];
|
|
91
|
-
const target = imports[match];
|
|
92
|
-
const subpath = specifier.slice(match.length);
|
|
93
|
-
// Resolve the mapping target against the map's base, then the subpath against that
|
|
94
|
-
const resolvedTarget = new URL(target, this.baseUrl);
|
|
95
|
-
return new URL(subpath, resolvedTarget).href;
|
|
96
|
-
}
|
|
97
|
-
} else if (typeof base === 'string') {
|
|
98
|
-
return URL.parse(specifier, base)?.href ?? null;
|
|
99
|
-
} else {
|
|
100
|
-
return null;
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
async importLocalPackage(name = 'package.json', { signal } = {}) {
|
|
105
|
-
const path = node_path.join(process.cwd(), name);
|
|
106
|
-
const pkg = await promises.readFile(path, { encoding: 'utf8', signal });
|
|
107
|
-
|
|
108
|
-
return this.setLocalPackage(JSON.parse(pkg));
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
setLocalPackage({ name, module, exports = {} }) {
|
|
112
|
-
if (typeof name !== 'string') {
|
|
113
|
-
return false;
|
|
114
|
-
} else if (typeof exports === 'string' ) {
|
|
115
|
-
this.set(name, exports);
|
|
116
|
-
return true;
|
|
117
|
-
} else if (typeof exports === 'object') {
|
|
118
|
-
Object.entries(exports).forEach(([key, value]) => {
|
|
119
|
-
if (key.startsWith('.')) {
|
|
120
|
-
const importKey = key === '.' ? name : `${name}${key.substring(1)}`;
|
|
121
|
-
const resolved = typeof value === 'string' ? value : value.import ?? value.default;
|
|
122
|
-
|
|
123
|
-
if (typeof resolved === 'string' && resolved.startsWith('./')) {
|
|
124
|
-
if (importKey.includes('*') && resolved.includes('*')) {
|
|
125
|
-
const [prefix, suffix] = importKey.split('*');
|
|
126
|
-
|
|
127
|
-
if (resolved.endsWith('*' + suffix)) {
|
|
128
|
-
this.set(prefix, resolved.substring(1).replace('*' + suffix, ''));
|
|
129
|
-
}
|
|
130
|
-
} else {
|
|
131
|
-
this.set(importKey, resolved.substring(1));
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
return true;
|
|
138
|
-
} else if (typeof module === 'string') {
|
|
139
|
-
this.set(name, module);
|
|
140
|
-
return true;
|
|
141
|
-
} else {
|
|
142
|
-
this.set(name, '/');
|
|
143
|
-
return true;
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
async getScript({ algo = DEFAULT_ALGO, alphabet = BASE64, signal } = {}) {
|
|
148
|
-
const integrity = await this.getIntegrity({ algo, alphabet, signal });
|
|
149
|
-
|
|
150
|
-
return `<script type="importmap" integrity="${integrity}">${JSON.stringify(this)}</script>`;
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
async getIntegrity({ algo = DEFAULT_ALGO, alphabet = BASE64, signal } = {}) {
|
|
154
|
-
if (signal instanceof AbortSignal && signal.aborted) {
|
|
155
|
-
throw signal.reason;
|
|
156
|
-
} else {
|
|
157
|
-
const prefix = algo.toLowerCase().replace('-', '') + '-';
|
|
158
|
-
const encoded = new TextEncoder().encode(this);
|
|
159
|
-
const hash = await crypto.subtle.digest(algo, encoded);
|
|
160
|
-
|
|
161
|
-
return prefix + new Uint8Array(hash).toBase64({ alphabet });
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
static get SHA256() {
|
|
166
|
-
return SHA256;
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
static get SHA384() {
|
|
170
|
-
return SHA384;
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
static get SHA512() {
|
|
174
|
-
return SHA512;
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
static async importFromFile(path = 'importmap.json', { signal } = {}) {
|
|
178
|
-
const fullPath = node_path.join(process.cwd(), path);
|
|
179
|
-
const importmap = await promises.readFile(fullPath, { encoding: 'utf8', signal });
|
|
180
|
-
|
|
181
|
-
return new Importmap(JSON.parse(importmap));
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
const importmap = new Importmap({ imports, scopes });
|
|
186
|
-
var importmap$1 = { imports, scopes };
|
|
187
|
-
|
|
188
|
-
exports.Importmap = Importmap;
|
|
189
|
-
exports.default = importmap$1;
|
|
190
|
-
exports.importmap = importmap;
|
|
191
|
-
exports.imports = imports;
|
|
192
|
-
exports.scopes = scopes;
|
|
5
|
+
module.exports = importmap;
|