@startup-api/cloudflare 0.4.4 → 0.4.5

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@startup-api/cloudflare",
3
- "version": "0.4.4",
3
+ "version": "0.4.5",
4
4
  "license": "Apache-2.0",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -15,7 +15,7 @@
15
15
  <power-strip providers="{{ssr:providers}}" style="position: absolute; top: 0; right: 0; z-index: 9999; border-radius: 0 0 0 0.3rem">
16
16
  <svg viewBox="0 0 24 24" style="width: 1rem; height: 1rem"><path d="M7 2v11h3v9l7-12h-4l4-8z" fill="#ffcc00" /></svg>
17
17
  </power-strip>
18
- <script src="/users/power-strip.js" async></script>
18
+ <script type="module" src="/users/power-strip.js" async></script>
19
19
 
20
20
  <div class="header-area">
21
21
  <a href="/" class="back-link">← Back to Home</a>
@@ -181,7 +181,7 @@
181
181
  <power-strip providers="{{ssr:providers}}" style="position: absolute; top: 0; right: 0; z-index: 9999; border-radius: 0 0 0 0.3rem">
182
182
  <svg viewBox="0 0 24 24" style="width: 1rem; height: 1rem"><path d="M7 2v11h3v9l7-12h-4l4-8z" fill="#ffcc00" /></svg>
183
183
  </power-strip>
184
- <script src="/users/power-strip.js" async></script>
184
+ <script type="module" src="/users/power-strip.js" async></script>
185
185
 
186
186
  <h1>StartupAPI Admin</h1>
187
187
 
@@ -17,22 +17,15 @@ class PowerStrip extends HTMLElement {
17
17
  }
18
18
 
19
19
  detectBasePath() {
20
- const script =
21
- document.currentScript ||
22
- (function () {
23
- const scripts = document.getElementsByTagName('script');
24
- return scripts[scripts.length - 1];
25
- })();
26
-
27
- if (script && script.src) {
28
- try {
29
- const url = new URL(script.src);
30
- return url.pathname.substring(0, url.pathname.lastIndexOf('/'));
31
- } catch (e) {
32
- console.error('Failed to parse script URL', e);
33
- }
20
+ // This file is loaded as an ES module (`<script type="module">`), so `document.currentScript`
21
+ // is null. `import.meta.url` is the module's own URL and is the reliable way to locate ourselves.
22
+ try {
23
+ const url = new URL(import.meta.url);
24
+ return url.pathname.substring(0, url.pathname.lastIndexOf('/'));
25
+ } catch (e) {
26
+ console.error('Failed to derive base path from import.meta.url', e);
27
+ return '';
34
28
  }
35
- return '';
36
29
  }
37
30
 
38
31
  async connectedCallback() {
@@ -10,7 +10,7 @@
10
10
  <power-strip providers="{{ssr:providers}}" style="position: absolute; top: 0; right: 0; z-index: 9999; border-radius: 0 0 0 0.3rem">
11
11
  <svg viewBox="0 0 24 24" style="width: 1rem; height: 1rem"><path d="M7 2v11h3v9l7-12h-4l4-8z" fill="#ffcc00" /></svg>
12
12
  </power-strip>
13
- <script src="/users/power-strip.js" async></script>
13
+ <script type="module" src="/users/power-strip.js" async></script>
14
14
 
15
15
  <div class="header-area">
16
16
  <a href="/" class="back-link">← Back to Home</a>
package/src/PowerStrip.ts CHANGED
@@ -24,7 +24,7 @@ export async function injectPowerStrip(response: Response, usersPath: string, pr
24
24
  element(element) {
25
25
  // The script is always needed to define the <power-strip> custom element.
26
26
  // It is loaded from the USERS_PATH, which is intercepted by this worker.
27
- element.prepend(`<script src="${usersPath}power-strip.js" async></script>`, { html: true });
27
+ element.prepend(`<script type="module" src="${usersPath}power-strip.js" async></script>`, { html: true });
28
28
 
29
29
  // Defer the component decision until the end of <body>, by which point
30
30
  // the streaming parser has seen any author-supplied <power-strip>.