bsign-customization-full 0.0.2 → 0.0.3

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": "bsign-customization-full",
3
- "version": "0.0.2",
3
+ "version": "0.0.3",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "dev": "vite",
Binary file
Binary file
package/src/index.css CHANGED
@@ -4,7 +4,7 @@
4
4
  @font-face {
5
5
  font-family: 'Bebasneue';
6
6
  src:
7
- url('https://cdn.jsdelivr.net/npm/bsign-customization@latest/src/fonts/BEBASNEUE-REGULAR.TTF') format('truetype');
7
+ url('/fonts/BEBASNEUE-REGULAR.TTF') format('truetype');
8
8
  font-weight: 400;
9
9
  font-style: normal;
10
10
  font-display: swap;
@@ -13,7 +13,7 @@
13
13
  @font-face {
14
14
  font-family: 'GOTHICB';
15
15
  src:
16
- url('./fonts/GOTHICB.TTF') format('truetype');
16
+ url('/fonts/GOTHICB.TTF') format('truetype');
17
17
  font-weight: 400;
18
18
  font-style: normal;
19
19
  font-display: swap;
@@ -22,11 +22,11 @@
22
22
  @font-face {
23
23
  font-family: 'Braille';
24
24
  src:
25
- url('https://cdn.jsdelivr.net/npm/bsign-customization@latest/src/fonts/Braille-Regular.ttf') format('truetype');
26
- font-weight: 400;
27
- font-style: normal;
28
- font-display: swap;
29
- }
25
+ url('/fonts/Braille-Regular.ttf') format('truetype');
26
+ font-weight: 400;
27
+ font-style: normal;
28
+ font-display: swap;
29
+ }
30
30
 
31
31
  @custom-variant dark (&:is(.dark *));
32
32
 
package/src/index.tsx CHANGED
@@ -3,6 +3,7 @@ import SignCustomizer, { type SignCustomizerProps } from "./AppDemo2"
3
3
  import resizableStyles from "react-resizable/css/styles.css?inline"
4
4
  import widgetStyles from "./index.css?inline"
5
5
  import { WidgetPortalContainerContext } from "./lib/widget-context"
6
+ import { resolveAssetUrl } from "./lib/asset-url"
6
7
 
7
8
  export type WidgetTarget = string | HTMLElement
8
9
 
@@ -10,7 +11,24 @@ export interface MountConstructorWidgetProps extends SignCustomizerProps {
10
11
  widgetCss?: string | string[]
11
12
  }
12
13
 
13
- const BASE_WIDGET_CSS = `${resizableStyles}\n${widgetStyles}`
14
+ const FONT_ASSET_PATHS = [
15
+ "/fonts/BEBASNEUE-REGULAR.TTF",
16
+ "/fonts/GOTHICB.TTF",
17
+ "/fonts/Braille-Regular.ttf",
18
+ ] as const
19
+
20
+ function resolveFontUrlsInCss(styles: string): string {
21
+ return FONT_ASSET_PATHS.reduce((nextStyles, fontPath) => {
22
+ const resolvedFontPath = resolveAssetUrl(fontPath)
23
+
24
+ return nextStyles
25
+ .replaceAll(`url('${fontPath}')`, `url('${resolvedFontPath}')`)
26
+ .replaceAll(`url("${fontPath}")`, `url("${resolvedFontPath}")`)
27
+ .replaceAll(`url(${fontPath})`, `url(${resolvedFontPath})`)
28
+ }, styles)
29
+ }
30
+
31
+ const BASE_WIDGET_CSS = `${resizableStyles}\n${resolveFontUrlsInCss(widgetStyles)}`
14
32
  const rootsByHost = new WeakMap<HTMLElement, Root>()
15
33
 
16
34
  function resolveTarget(target: WidgetTarget): HTMLElement {
@@ -1,6 +1,24 @@
1
1
  const ABSOLUTE_URL_PATTERN = /^(?:[a-z][a-z\d+\-.]*:)?\/\//i
2
2
  const SPECIAL_PROTOCOL_PATTERN = /^(?:data|blob):/i
3
3
 
4
+ function isLocalhostHost(hostname: string): boolean {
5
+ const normalizedHost = hostname.toLowerCase()
6
+ return (
7
+ normalizedHost === "localhost" ||
8
+ normalizedHost === "127.0.0.1" ||
9
+ normalizedHost === "[::1]" ||
10
+ normalizedHost.endsWith(".localhost")
11
+ )
12
+ }
13
+
14
+ function shouldUseRelativeUrls(): boolean {
15
+ if (typeof window === "undefined") {
16
+ return false
17
+ }
18
+
19
+ return isLocalhostHost(window.location.hostname)
20
+ }
21
+
4
22
  function toBaseUrl(url: string): string | undefined {
5
23
  try {
6
24
  return new URL(".", url).toString()
@@ -65,6 +83,14 @@ export function resolveAssetUrl(path: string): string {
65
83
  return path
66
84
  }
67
85
 
86
+ if (shouldUseRelativeUrls()) {
87
+ if (path.startsWith("/") || path.startsWith("./") || path.startsWith("../")) {
88
+ return path
89
+ }
90
+
91
+ return `./${path}`
92
+ }
93
+
68
94
  const normalizedPath = path.startsWith("/") ? path.slice(1) : path
69
95
  return new URL(normalizedPath, getAssetBaseUrl()).toString()
70
96
  }