@panomc/widget-host 0.0.0-stage → 1.0.0-dev.61

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.
Files changed (108) hide show
  1. package/dist/runtime/chunks/chunk-9EZydhXt.js +1 -0
  2. package/dist/runtime/chunks/chunk-BQPllGmY.js +1 -0
  3. package/dist/runtime/chunks/chunk-CTgT5UYL.js +1 -0
  4. package/dist/runtime/chunks/chunk-ChRkfjHR.js +1 -0
  5. package/dist/runtime/chunks/chunk-Cmbb89rp.js +1 -0
  6. package/dist/runtime/chunks/chunk-CqpY4RsZ.js +1 -0
  7. package/dist/runtime/chunks/chunk-D7Jd5Dpn.js +1 -0
  8. package/dist/runtime/chunks/chunk-DNUkGPCL.js +1 -0
  9. package/dist/runtime/chunks/chunk-DebScgYV.js +1 -0
  10. package/dist/runtime/chunks/chunk-DgPYxg7o.js +1 -0
  11. package/dist/runtime/chunks/chunk-DhgH0pN2.js +1 -0
  12. package/dist/runtime/chunks/chunk-FEL6LDrJ.js +1 -0
  13. package/dist/runtime/chunks/chunk-RPo0Hd8r.js +1 -0
  14. package/dist/runtime/chunks/chunk-Xd_2KAhC.js +1 -0
  15. package/dist/runtime/chunks/chunk-akOtSLvV.js +1 -0
  16. package/dist/runtime/chunks/chunk-cUxFvg6m.js +1 -0
  17. package/dist/runtime/css/pano-fallback-icons.css +9 -0
  18. package/dist/runtime/css/pano-tokens.css +225 -0
  19. package/dist/runtime/host/components-panel.js +1 -0
  20. package/dist/runtime/host/components-theme.js +1 -0
  21. package/dist/runtime/host/controllers.js +1 -0
  22. package/dist/runtime/host/index.js +1 -0
  23. package/dist/runtime/host/internal.js +1 -0
  24. package/dist/runtime/host/svelte.js +1 -0
  25. package/dist/runtime/host/toasts.js +1 -0
  26. package/dist/runtime/host/utils-api.js +1 -0
  27. package/dist/runtime/host/utils-auth.js +1 -0
  28. package/dist/runtime/host/utils-component.js +1 -0
  29. package/dist/runtime/host/utils-language.js +1 -0
  30. package/dist/runtime/host/utils-route.js +1 -0
  31. package/dist/runtime/host/utils-text.js +1 -0
  32. package/dist/runtime/host/utils-tooltip.js +1 -0
  33. package/dist/runtime/host/variables.js +1 -0
  34. package/dist/runtime/host/views.js +1 -0
  35. package/dist/runtime/loader.js +1 -0
  36. package/dist/runtime/runtime.json +104 -0
  37. package/dist/runtime/svelte/animate.js +1 -0
  38. package/dist/runtime/svelte/attachments.js +1 -0
  39. package/dist/runtime/svelte/easing.js +1 -0
  40. package/dist/runtime/svelte/events.js +1 -0
  41. package/dist/runtime/svelte/index.js +1 -0
  42. package/dist/runtime/svelte/internal-client.js +1 -0
  43. package/dist/runtime/svelte/internal-disclose-version.js +1 -0
  44. package/dist/runtime/svelte/internal-flags-async.js +1 -0
  45. package/dist/runtime/svelte/internal-flags-legacy.js +1 -0
  46. package/dist/runtime/svelte/internal-flags-tracing.js +1 -0
  47. package/dist/runtime/svelte/internal.js +1 -0
  48. package/dist/runtime/svelte/legacy.js +1 -0
  49. package/dist/runtime/svelte/motion.js +1 -0
  50. package/dist/runtime/svelte/reactivity-window.js +1 -0
  51. package/dist/runtime/svelte/reactivity.js +1 -0
  52. package/dist/runtime/svelte/store.js +1 -0
  53. package/dist/runtime/svelte/transition.js +1 -0
  54. package/dist/runtime/svelte-i18n.js +1 -0
  55. package/dist/runtime/webfonts/fa-brands-400.ttf +0 -0
  56. package/dist/runtime/webfonts/fa-brands-400.woff2 +0 -0
  57. package/dist/runtime/webfonts/fa-regular-400.ttf +0 -0
  58. package/dist/runtime/webfonts/fa-regular-400.woff2 +0 -0
  59. package/dist/runtime/webfonts/fa-solid-900.ttf +0 -0
  60. package/dist/runtime/webfonts/fa-solid-900.woff2 +0 -0
  61. package/dist/runtime/webfonts/fa-v4compatibility.ttf +0 -0
  62. package/dist/runtime/webfonts/fa-v4compatibility.woff2 +0 -0
  63. package/dist/widget-runtime.zip +0 -0
  64. package/package.json +59 -4
  65. package/scripts/build-zip.js +35 -0
  66. package/scripts/install-local.js +57 -0
  67. package/scripts/loader.js +169 -0
  68. package/scripts/runtime-map.js +52 -0
  69. package/scripts/zip.js +128 -0
  70. package/src/__tests__/components.test.js +77 -0
  71. package/src/__tests__/controllers.test.js +188 -0
  72. package/src/__tests__/define.test.js +276 -0
  73. package/src/__tests__/env.js +111 -0
  74. package/src/__tests__/fixtures/Goal.svelte +5 -0
  75. package/src/__tests__/modules.test.js +251 -0
  76. package/src/__tests__/parity.test.js +123 -0
  77. package/src/api.js +144 -0
  78. package/src/auth.js +2 -0
  79. package/src/component.js +4 -0
  80. package/src/components/Date.svelte +38 -0
  81. package/src/components/NoContent.svelte +13 -0
  82. package/src/components/PageActions.svelte +22 -0
  83. package/src/components/PageTitle.svelte +32 -0
  84. package/src/components/Pagination.svelte +49 -0
  85. package/src/components/PlayerHead.svelte +39 -0
  86. package/src/components/Toast.svelte +16 -0
  87. package/src/components/empty.js +3 -0
  88. package/src/components/index.js +14 -0
  89. package/src/components/panel.js +19 -0
  90. package/src/config.js +100 -0
  91. package/src/context.js +47 -0
  92. package/src/controllers.js +313 -0
  93. package/src/define.js +352 -0
  94. package/src/index.js +38 -0
  95. package/src/internal.js +2 -0
  96. package/src/language.js +181 -0
  97. package/src/plugin.js +20 -0
  98. package/src/route.js +4 -0
  99. package/src/runtime.js +49 -0
  100. package/src/session.js +72 -0
  101. package/src/svelte-runtime.js +3 -0
  102. package/src/svelte.js +72 -0
  103. package/src/text.js +2 -0
  104. package/src/toasts.js +75 -0
  105. package/src/tooltip.js +4 -0
  106. package/src/variables.js +29 -0
  107. package/src/views.js +17 -0
  108. package/README.md +0 -3
@@ -0,0 +1,38 @@
1
+ <script>
2
+ import { currentLanguage } from '../language.js';
3
+ import { getConfig } from '../config.js';
4
+
5
+ let { time, relativeFormat = false, children } = $props();
6
+
7
+ const code = $derived($currentLanguage?.code ?? getConfig().locale ?? undefined);
8
+ const date = $derived(new Date(parseInt(time)));
9
+ const exact = $derived(
10
+ new Intl.DateTimeFormat(code, { dateStyle: 'short', timeStyle: 'short' }).format(date),
11
+ );
12
+ const text = $derived.by(() => {
13
+ if (!relativeFormat) {
14
+ return new Intl.DateTimeFormat(code, { day: '2-digit', month: 'long', year: 'numeric' }).format(date);
15
+ }
16
+ const seconds = Math.round((date.getTime() - Date.now()) / 1000);
17
+ const units = [
18
+ ['year', 31536000],
19
+ ['month', 2592000],
20
+ ['day', 86400],
21
+ ['hour', 3600],
22
+ ['minute', 60],
23
+ ];
24
+ const formatter = new Intl.RelativeTimeFormat(code, { numeric: 'auto' });
25
+ for (const [unit, size] of units) {
26
+ if (Math.abs(seconds) >= size) return formatter.format(Math.round(seconds / size), unit);
27
+ }
28
+ return formatter.format(seconds, 'second');
29
+ });
30
+ </script>
31
+
32
+ <span title={exact}>
33
+ {#if children}
34
+ {@render children()}
35
+ {:else}
36
+ {text}
37
+ {/if}
38
+ </span>
@@ -0,0 +1,13 @@
1
+ <script>
2
+ import { translate } from '../language.js';
3
+
4
+ let { icon = 'fa-solid fa-square fa-3x', text = translate('components.no-content.text', 'No content'), children } = $props();
5
+ </script>
6
+
7
+ <div class="card opacity-50 bg-transparent border-none">
8
+ <div class="card-body vstack gap-3 text-center">
9
+ <span class={icon}></span>
10
+ <p class="mb-0">{text}</p>
11
+ {@render children?.()}
12
+ </div>
13
+ </div>
@@ -0,0 +1,22 @@
1
+ <script>
2
+ // `left` / `middle` / `right` are snippets (the named slots of the theme component).
3
+ let { leftClasses = undefined, middleClasses = undefined, rightClasses = undefined, left, middle, right } = $props();
4
+ </script>
5
+
6
+ <div class="row d-flex align-items-center gy-3 justify-content-lg-between justify-content-center">
7
+ {#if leftClasses !== null && (left || leftClasses !== undefined)}
8
+ <div class="col-lg-auto col-12 d-flex justify-content-lg-start overflow-x-auto {leftClasses || ''}">
9
+ {@render left?.()}
10
+ </div>
11
+ {/if}
12
+ {#if middleClasses !== null && (middle || middleClasses !== undefined)}
13
+ <div class="col-lg-auto col-12 order-lg-2 order-last d-flex justify-content-center overflow-x-auto {middleClasses || ''}">
14
+ {@render middle?.()}
15
+ </div>
16
+ {/if}
17
+ {#if rightClasses !== null && (right || rightClasses !== undefined)}
18
+ <div class="col-lg-auto col-12 order-3 d-flex justify-content-lg-end overflow-x-auto {rightClasses || ''}">
19
+ {@render right?.()}
20
+ </div>
21
+ {/if}
22
+ </div>
@@ -0,0 +1,32 @@
1
+ <script>
2
+ // `title` is a string, or a snippet when the caller used the named slot `title` (legacy slot syntax compiles to a prop).
3
+ let { title = '', subtitle = '', html, subtitleHtml = false, children } = $props();
4
+
5
+ const custom = $derived(typeof title === 'function');
6
+ </script>
7
+
8
+ {#if title || subtitle}
9
+ <div class="text-center">
10
+ <h1 class="fs-3 mb-0 text-break word-break">
11
+ {#if custom}
12
+ {@render title()}
13
+ {:else if title}
14
+ {#if html}
15
+ {@html title}
16
+ {:else}
17
+ {title}
18
+ {/if}
19
+ {/if}
20
+ </h1>
21
+ {#if subtitle}
22
+ <p class="mb-0 mt-2 opacity-75">
23
+ {#if subtitleHtml}
24
+ {@html subtitle}
25
+ {:else}
26
+ {subtitle}
27
+ {/if}
28
+ </p>
29
+ {/if}
30
+ {@render children?.()}
31
+ </div>
32
+ {/if}
@@ -0,0 +1,49 @@
1
+ <script>
2
+ import { createEventDispatcher } from 'svelte';
3
+ import { translate } from '../language.js';
4
+
5
+ const dispatch = createEventDispatcher();
6
+
7
+ let { page = 1, totalPage = 1 } = $props();
8
+
9
+ const pages = $derived(Array.from({ length: totalPage }, (_, i) => i + 1));
10
+ const current = $derived(parseInt(page));
11
+ </script>
12
+
13
+ <nav>
14
+ <ul class="pagination pagination-sm mb-0 justify-content-start flex-wrap">
15
+ <li class="page-item" class:disabled={current === 1}>
16
+ <button
17
+ type="button"
18
+ class="page-link"
19
+ title={translate('components.pagination.previous-page', 'Previous page')}
20
+ onclick={() => dispatch('firstPageClick', {})}
21
+ aria-hidden={current === 1}>
22
+ <i class="fa-solid fa-caret-left"></i>
23
+ </button>
24
+ </li>
25
+
26
+ {#each pages as index (index)}
27
+ <li class="page-item" class:active={current === index} aria-current={current === index ? 'page' : undefined}>
28
+ <button
29
+ type="button"
30
+ class="page-link"
31
+ onclick={() => dispatch('pageLinkClick', { page: index })}
32
+ aria-hidden={current === index}>
33
+ {index}
34
+ </button>
35
+ </li>
36
+ {/each}
37
+
38
+ <li class="page-item" class:disabled={current === totalPage}>
39
+ <button
40
+ type="button"
41
+ class="page-link"
42
+ title={translate('components.pagination.next-page', 'Next page')}
43
+ onclick={() => dispatch('lastPageClick', {})}
44
+ aria-hidden={current === totalPage}>
45
+ <i class="fa-solid fa-caret-right"></i>
46
+ </button>
47
+ </li>
48
+ </ul>
49
+ </nav>
@@ -0,0 +1,39 @@
1
+ <script>
2
+ import { getConfig } from '../config.js';
3
+ import { currentLanguage, translate } from '../language.js';
4
+
5
+ let { username, width = 64, height = 64, checkTime, inGame = false, lastActivityTime, banned } = $props();
6
+
7
+ const isOnline = $derived(lastActivityTime > Date.now() - 5 * 60 * 1000 || inGame);
8
+ const src = $derived(`${getConfig().apiBase}/api/profile/picture/${encodeURIComponent(username)}`);
9
+ const hint = $derived.by(() => {
10
+ if (banned) return undefined;
11
+ if (isOnline) return translate(`components.player-head.${inGame ? 'in-game' : 'in-website'}`, inGame ? 'In game' : 'On the website');
12
+ const code = $currentLanguage?.code ?? getConfig().locale ?? undefined;
13
+ return new Intl.DateTimeFormat(code, { dateStyle: 'medium', timeStyle: 'short' }).format(new Date(parseInt(lastActivityTime)));
14
+ });
15
+ </script>
16
+
17
+ {#if lastActivityTime}
18
+ <img
19
+ {src}
20
+ class="img-thumbnail rounded d-block m-auto"
21
+ {width}
22
+ {height}
23
+ alt={username}
24
+ title={hint}
25
+ class:border={banned || isOnline}
26
+ class:border-3={banned || isOnline}
27
+ class:border-success={!banned && isOnline}
28
+ class:border-danger={banned} />
29
+ {:else}
30
+ <img
31
+ {src}
32
+ class="rounded d-block m-auto"
33
+ {width}
34
+ {height}
35
+ alt={username}
36
+ class:border={banned}
37
+ class:border-3={banned}
38
+ class:border-danger={banned} />
39
+ {/if}
@@ -0,0 +1,16 @@
1
+ <script>
2
+ // 'success' | 'danger' | null, mapped so a caller cannot inject an arbitrary utility class.
3
+ let { id, variant = null, children } = $props();
4
+
5
+ const VARIANT_CLASSES = { success: 'text-success', danger: 'text-danger' };
6
+ const variantClass = $derived(VARIANT_CLASSES[variant] ?? '');
7
+ </script>
8
+
9
+ <div
10
+ id="appToast{id}"
11
+ class="toast show align-items-center shadow-lg text-bg-tertiary opacity-100 {variantClass}"
12
+ role="alert"
13
+ aria-live="assertive"
14
+ aria-atomic="true">
15
+ <div class="toast-body">{@render children?.()}</div>
16
+ </div>
@@ -0,0 +1,3 @@
1
+ // A Svelte 5 component that renders nothing: `PluginBlock` / `PluginSlot` in a widget (doc 06 section 3.2),
2
+ // and every panel-only component, which a widget view never uses.
3
+ export default function Empty() {}
@@ -0,0 +1,14 @@
1
+ // `@panomc/sdk/components/theme` outside a theme (doc 06 section 3.2): plain Svelte copies of the theme components.
2
+ import Empty from './empty.js';
3
+
4
+ export { default as PlayerHead } from './PlayerHead.svelte';
5
+ export { default as NoContent } from './NoContent.svelte';
6
+ export { default as Date } from './Date.svelte';
7
+ export { default as Toast } from './Toast.svelte';
8
+ export { default as PageTitle } from './PageTitle.svelte';
9
+ export { default as PageActions } from './PageActions.svelte';
10
+ export { default as Pagination } from './Pagination.svelte';
11
+
12
+ /** Outside a theme there is no registry: blocks and slots are empty. */
13
+ export const PluginBlock = Empty;
14
+ export const PluginSlot = Empty;
@@ -0,0 +1,19 @@
1
+ // `@panomc/sdk/components/panel` in a widget: the panel is not part of a widget page. Shared names are the real components, the rest render nothing.
2
+ import Empty from './empty.js';
3
+
4
+ export { default as NoContent } from './NoContent.svelte';
5
+ export { default as Date } from './Date.svelte';
6
+ export { default as Toast } from './Toast.svelte';
7
+ export { default as PageActions } from './PageActions.svelte';
8
+ export { default as Pagination } from './Pagination.svelte';
9
+
10
+ export const Editor = Empty;
11
+ export const DragAndDropZone = Empty;
12
+ export const PageLoading = Empty;
13
+ export const PageLoader = Empty;
14
+ export const PageNavItem = Empty;
15
+ export const PageNav = Empty;
16
+ export const CardFilters = Empty;
17
+ export const CardFiltersItem = Empty;
18
+ export const CardHeader = Empty;
19
+ export const SearchInput = Empty;
package/src/config.js ADDED
@@ -0,0 +1,100 @@
1
+ // Page-wide configuration of the widget host (doc 06 section 3.4 / 3.5). `window.PanoWidgets.configure(...)` of the loader
2
+ // ends up here. Every other module reads it lazily, so a `configure` call after import still takes effect.
3
+ import { createClient } from '@panomc/client';
4
+
5
+ /**
6
+ * @typedef {Object} WidgetConfig
7
+ * @property {string} apiBase what precedes `/api/v1`: Pano's origin, a proxy prefix such as `/pano`, or '' (same origin)
8
+ * @property {string} [locale]
9
+ * @property {Record<string,string>} urls doc 05 URL map: `{ 'market.store': '/shop', 'market.order': '/shop/o/{id}' }`
10
+ * @property {string} siteUrl the site URL the widgets belong to (index.json `site.url`)
11
+ * @property {typeof fetch} [fetch]
12
+ * @property {(url:string, o?:{replace?:boolean}) => (boolean|void)} [navigate] called after `pano:navigate` was not cancelled
13
+ * @property {'auto'|'off'} [csrf]
14
+ */
15
+
16
+ /** @type {WidgetConfig} */
17
+ const state = { apiBase: '', locale: undefined, urls: {}, siteUrl: '', fetch: undefined, navigate: undefined, csrf: undefined };
18
+
19
+ /** @type {any} */
20
+ let client = null;
21
+ /** @type {Set<(config: WidgetConfig) => void>} */
22
+ const listeners = new Set();
23
+
24
+ /** A prefix such as `/pano` is relative; '' (same origin) and absolute URLs are not. */
25
+ export function isRelativeBase(apiBase) {
26
+ if (!apiBase) return false;
27
+ return !/^[a-z][a-z0-9+.-]*:\/\//i.test(apiBase);
28
+ }
29
+
30
+ /** @param {Partial<WidgetConfig>} [partial] */
31
+ export function configure(partial = {}) {
32
+ if (partial.apiBase !== undefined) state.apiBase = String(partial.apiBase || '').replace(/\/+$/, '');
33
+ if (partial.locale !== undefined) state.locale = partial.locale || undefined;
34
+ if (partial.urls !== undefined) state.urls = { ...partial.urls };
35
+ if (partial.siteUrl !== undefined) state.siteUrl = String(partial.siteUrl || '').replace(/\/+$/, '');
36
+ if (partial.fetch !== undefined) state.fetch = partial.fetch;
37
+ if (partial.navigate !== undefined) state.navigate = partial.navigate;
38
+ if (partial.csrf !== undefined) state.csrf = partial.csrf;
39
+
40
+ client = null;
41
+ for (const fn of [...listeners]) fn(state);
42
+ return getConfig();
43
+ }
44
+
45
+ /** @returns {Readonly<WidgetConfig & { csrf: 'auto'|'off' }>} */
46
+ export function getConfig() {
47
+ return { ...state, csrf: state.csrf ?? (isRelativeBase(state.apiBase) ? 'off' : 'auto') };
48
+ }
49
+
50
+ /** Back to the defaults (tests). */
51
+ export function resetConfig() {
52
+ Object.assign(state, { apiBase: '', locale: undefined, urls: {}, siteUrl: '', fetch: undefined, navigate: undefined, csrf: undefined });
53
+ client = null;
54
+ for (const fn of [...listeners]) fn(state);
55
+ }
56
+
57
+ /** @param {(config: WidgetConfig) => void} fn @returns {() => void} */
58
+ export function onConfigure(fn) {
59
+ listeners.add(fn);
60
+ return () => listeners.delete(fn);
61
+ }
62
+
63
+ /** The page's `fetch`: the configured one, else the global one at call time. */
64
+ export function pageFetch(...args) {
65
+ const impl = state.fetch ?? globalThis.fetch;
66
+ return impl(...args);
67
+ }
68
+
69
+ /** The page's single `@panomc/client`. */
70
+ export function getClient() {
71
+ if (!client) {
72
+ const config = getConfig();
73
+ client = createClient({
74
+ baseUrl: config.apiBase,
75
+ fetch: (...args) => pageFetch(...args),
76
+ locale: config.locale,
77
+ credentials: 'include',
78
+ csrf: config.csrf,
79
+ });
80
+ }
81
+ return client;
82
+ }
83
+
84
+ /**
85
+ * Resolves a key of the URL map (`market.order` + `{ id: 7 }`) or a site path (`/shop`) against the site URL.
86
+ * Absolute URLs and unknown keys come back unchanged.
87
+ * @param {string} keyOrPath
88
+ * @param {Record<string, any>} [params]
89
+ */
90
+ export function resolveUrl(keyOrPath, params) {
91
+ let target = state.urls[keyOrPath] ?? keyOrPath;
92
+ if (params) {
93
+ target = target.replace(/\{([^}]+)\}/g, (whole, name) =>
94
+ params[name] === undefined || params[name] === null ? whole : encodeURIComponent(String(params[name])),
95
+ );
96
+ }
97
+ if (/^[a-z][a-z0-9+.-]*:/i.test(target) || target.startsWith('//')) return target;
98
+ if (target.startsWith('/') && state.siteUrl) return `${state.siteUrl}${target}`;
99
+ return target;
100
+ }
package/src/context.js ADDED
@@ -0,0 +1,47 @@
1
+ // `getPanoContext` of a widget page (`@panomc/sdk` and `@panomc/sdk/internal`): a small context of the host modules.
2
+ // It is not the theme's `globalThis.__PANO_CONTEXT__`: a widget page has no theme and no engine.
3
+ import { getConfig, onConfigure } from './config.js';
4
+
5
+ const store = { context: /** @type {Record<string, any>} */ ({ isPanel: false, browser: true }), listeners: /** @type {Array<(c:any)=>void>} */ ([]) };
6
+
7
+ function notify() {
8
+ for (const fn of [...store.listeners]) {
9
+ try {
10
+ fn(store.context);
11
+ } catch (e) {
12
+ console.error('[pano-widgets] context listener failed', e);
13
+ }
14
+ }
15
+ }
16
+
17
+ /** @param {Record<string, any>} partial */
18
+ export function setPanoContext(partial) {
19
+ if (typeof partial !== 'object' || partial === null) {
20
+ console.warn('[PanoSDK] setPanoContext expects an object');
21
+ return;
22
+ }
23
+ Object.assign(store.context, partial);
24
+ notify();
25
+ }
26
+
27
+ /** @returns {{ context: Record<string, any>, subscribe: (fn: (c:any)=>void) => () => void }} */
28
+ export function getPanoContext() {
29
+ return {
30
+ context: store.context,
31
+ subscribe(fn) {
32
+ store.listeners.push(fn);
33
+ return () => {
34
+ store.listeners = store.listeners.filter((l) => l !== fn);
35
+ };
36
+ },
37
+ };
38
+ }
39
+
40
+ // the parts every module can read without importing the others
41
+ onConfigure((config) => {
42
+ store.context.base = config.siteUrl;
43
+ store.context.urls = { ...config.urls };
44
+ notify();
45
+ });
46
+ store.context.base = getConfig().siteUrl;
47
+ store.context.urls = getConfig().urls;