tempest-react-sdk 0.8.0 → 0.9.0
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/README.md +4 -4
- package/bin/lib/openapi/generate.mjs +259 -0
- package/bin/lib/openapi/generate.test.mjs +129 -0
- package/bin/lib/openapi/load.mjs +24 -0
- package/bin/lib/openapi/schema-to-zod.mjs +123 -0
- package/bin/lib/openapi/schema-to-zod.test.mjs +81 -0
- package/bin/tempest.mjs +84 -2
- package/dist/sw.cjs +1 -1
- package/dist/sw.cjs.map +1 -1
- package/dist/sw.d.ts +130 -0
- package/dist/sw.js +327 -61
- package/dist/sw.js.map +1 -1
- package/dist/tempest-react-sdk.cjs +3 -3
- package/dist/tempest-react-sdk.d.ts +130 -0
- package/dist/tempest-react-sdk.js +36 -32
- package/dist/vite.cjs +3 -1
- package/dist/vite.cjs.map +1 -1
- package/dist/vite.d.ts +136 -0
- package/dist/vite.js +253 -34
- package/dist/vite.js.map +1 -1
- package/package.json +1 -1
- package/template-pwa/index.html +1 -1
- package/template-pwa/package.json +3 -0
- package/template-pwa/public/manifest.webmanifest +6 -6
- package/template-pwa/src/main.tsx +17 -24
- package/template-pwa/src/sw.ts +44 -9
- package/template-pwa/vite.config.ts +21 -0
- package/template-pwa/public/icon-maskable.svg +0 -4
|
@@ -1259,6 +1259,17 @@ export declare interface CreateLoggerOptions {
|
|
|
1259
1259
|
*/
|
|
1260
1260
|
export declare function createOfflineStore<TItem, TKey extends string | number = string>(config: OfflineStoreConfig<TItem>): OfflineStore<TItem, TKey>;
|
|
1261
1261
|
|
|
1262
|
+
/**
|
|
1263
|
+
* Build a `206 Partial Content` response from a full one for an HTTP `Range`
|
|
1264
|
+
* request. Supports `bytes=start-end`, open-ended `bytes=start-` and suffix
|
|
1265
|
+
* `bytes=-suffixLength`. Returns the original response when there is no usable
|
|
1266
|
+
* `Range` header, or a `416` when the range is unsatisfiable.
|
|
1267
|
+
*
|
|
1268
|
+
* @param request The incoming request (its `Range` header drives the slice).
|
|
1269
|
+
* @param response The full (200) response to slice.
|
|
1270
|
+
*/
|
|
1271
|
+
export declare function createPartialResponse(request: Request, response: Response): Promise<Response>;
|
|
1272
|
+
|
|
1262
1273
|
/**
|
|
1263
1274
|
* Build a [[TelemetryAdapter]] backed by [`posthog-js`](https://posthog.com/docs/libraries/js).
|
|
1264
1275
|
* The PostHog client is supplied by the caller (not bundled).
|
|
@@ -2455,6 +2466,42 @@ export declare interface InputProps extends Omit<InputHTMLAttributes<HTMLInputEl
|
|
|
2455
2466
|
|
|
2456
2467
|
export declare type InputSize = "sm" | "md" | "lg";
|
|
2457
2468
|
|
|
2469
|
+
/**
|
|
2470
|
+
* Install the background-sync queue: on a failed mutating request, the request
|
|
2471
|
+
* is serialized to IndexedDB and a sync is registered; the original fetch still
|
|
2472
|
+
* rejects (so your app can show an offline state), and the request is replayed
|
|
2473
|
+
* later when the network returns.
|
|
2474
|
+
*/
|
|
2475
|
+
export declare function installBackgroundSync(options?: InstallBackgroundSyncOptions): void;
|
|
2476
|
+
|
|
2477
|
+
/**
|
|
2478
|
+
* Background-sync helper: queue failed mutating requests (POST/PUT/PATCH/DELETE)
|
|
2479
|
+
* while offline and replay them when connectivity returns. A dependency-free
|
|
2480
|
+
* take on Workbox's `BackgroundSyncPlugin`, backed by a tiny IndexedDB queue.
|
|
2481
|
+
*
|
|
2482
|
+
* Import inside your `sw.ts`. Uses the Background Sync API (`registration.sync`)
|
|
2483
|
+
* when available, and also replays opportunistically on the next request as a
|
|
2484
|
+
* fallback for browsers without it (e.g. Safari).
|
|
2485
|
+
*
|
|
2486
|
+
* @example
|
|
2487
|
+
* import { installBackgroundSync } from "tempest-react-sdk/sw";
|
|
2488
|
+
*
|
|
2489
|
+
* installBackgroundSync({ match: (url) => url.pathname.startsWith("/api/") });
|
|
2490
|
+
*/
|
|
2491
|
+
/** Options for {@link installBackgroundSync}. */
|
|
2492
|
+
export declare interface InstallBackgroundSyncOptions {
|
|
2493
|
+
/**
|
|
2494
|
+
* Which requests to queue on failure. A `RegExp` against the URL or a
|
|
2495
|
+
* predicate. Only non-`GET` requests are ever considered. Default: all
|
|
2496
|
+
* non-`GET` requests.
|
|
2497
|
+
*/
|
|
2498
|
+
match?: RegExp | ((url: URL, request: Request) => boolean);
|
|
2499
|
+
/** IndexedDB database name, also used as the sync tag. Default `tempest-bg-sync`. */
|
|
2500
|
+
queueName?: string;
|
|
2501
|
+
/** Drop queued requests older than this (minutes) on replay. Default `1440` (24h). */
|
|
2502
|
+
maxRetentionMinutes?: number;
|
|
2503
|
+
}
|
|
2504
|
+
|
|
2458
2505
|
/**
|
|
2459
2506
|
* Install a `notificationclick` handler that focuses an existing client when
|
|
2460
2507
|
* possible and falls back to opening a new window.
|
|
@@ -2466,6 +2513,32 @@ export declare interface InstallNotificationClickHandlerOptions {
|
|
|
2466
2513
|
resolveUrl?: (data: unknown) => string;
|
|
2467
2514
|
}
|
|
2468
2515
|
|
|
2516
|
+
/**
|
|
2517
|
+
* Precache the app shell at `install` and serve it offline:
|
|
2518
|
+
* - reads `precache-manifest.json` (emitted by `tempestPwaManifest()`),
|
|
2519
|
+
* - caches every listed URL under a versioned cache,
|
|
2520
|
+
* - on `activate`, deletes stale precache versions and claims open clients,
|
|
2521
|
+
* - on `fetch`, serves precached assets cache-first and falls back to the
|
|
2522
|
+
* `navigateFallback` document for offline navigations (SPA routing).
|
|
2523
|
+
*
|
|
2524
|
+
* Same-origin only. Register this LAST, after any {@link installRuntimeCache}.
|
|
2525
|
+
*/
|
|
2526
|
+
export declare function installPrecache(options?: InstallPrecacheOptions): void;
|
|
2527
|
+
|
|
2528
|
+
/** Options for {@link installPrecache}. */
|
|
2529
|
+
export declare interface InstallPrecacheOptions {
|
|
2530
|
+
/** URL of the manifest emitted by `tempestPwaManifest()`. Default `/precache-manifest.json`. */
|
|
2531
|
+
manifestUrl?: string;
|
|
2532
|
+
/** Cache name prefix; the manifest `version` is appended. Default `tempest-precache`. */
|
|
2533
|
+
cacheName?: string;
|
|
2534
|
+
/** App-shell document served for navigation requests offline. Default `/index.html`. */
|
|
2535
|
+
navigateFallback?: string;
|
|
2536
|
+
/** Navigation paths that should NOT use the fallback (e.g. `[/^\/api\//]`). */
|
|
2537
|
+
navigateFallbackDenylist?: RegExp[];
|
|
2538
|
+
/** Activate the new worker immediately after precaching. Default `true`. */
|
|
2539
|
+
skipWaiting?: boolean;
|
|
2540
|
+
}
|
|
2541
|
+
|
|
2469
2542
|
/**
|
|
2470
2543
|
* Install a `push` event listener that parses the payload as JSON (with a
|
|
2471
2544
|
* plain-text fallback) and shows a notification.
|
|
@@ -2486,6 +2559,18 @@ export declare interface InstallPushHandlerOptions {
|
|
|
2486
2559
|
transform?: (payload: PushPayload) => PushPayload | null;
|
|
2487
2560
|
}
|
|
2488
2561
|
|
|
2562
|
+
/**
|
|
2563
|
+
* Install a `fetch` handler that resolves matching `GET` requests with the
|
|
2564
|
+
* given runtime strategies. Non-matching requests are left untouched (no
|
|
2565
|
+
* `respondWith`), so a later {@link installPrecache} can handle them.
|
|
2566
|
+
*
|
|
2567
|
+
* Register this BEFORE `installPrecache` so specific routes win over the
|
|
2568
|
+
* precache catch-all.
|
|
2569
|
+
*
|
|
2570
|
+
* @param routes Ordered rules; the first whose `match` passes handles the request.
|
|
2571
|
+
*/
|
|
2572
|
+
export declare function installRuntimeCache(routes: RuntimeRoute[]): void;
|
|
2573
|
+
|
|
2489
2574
|
/**
|
|
2490
2575
|
* Install a `message` listener that activates a waiting worker when the host
|
|
2491
2576
|
* app sends `{ type: "SKIP_WAITING" }`.
|
|
@@ -3635,6 +3720,51 @@ export declare type RouterKind = "browser" | "hash" | "memory";
|
|
|
3635
3720
|
|
|
3636
3721
|
export { Routes }
|
|
3637
3722
|
|
|
3723
|
+
/** A single runtime-caching rule, matched against each `GET` request. */
|
|
3724
|
+
export declare interface RuntimeRoute {
|
|
3725
|
+
/** A `RegExp` tested against the full URL, or a predicate over the parsed URL. */
|
|
3726
|
+
match: RegExp | ((url: URL, request: Request) => boolean);
|
|
3727
|
+
/** How to resolve a match. */
|
|
3728
|
+
strategy: RuntimeStrategy;
|
|
3729
|
+
/** Cache bucket name for this route. */
|
|
3730
|
+
cacheName: string;
|
|
3731
|
+
/** Trim the cache to at most this many entries (FIFO) after each write. */
|
|
3732
|
+
maxEntries?: number;
|
|
3733
|
+
/** Treat a cached response older than this (seconds) as a miss. */
|
|
3734
|
+
maxAgeSeconds?: number;
|
|
3735
|
+
/** For `network-first`: fall back to cache after this timeout (seconds). */
|
|
3736
|
+
networkTimeoutSeconds?: number;
|
|
3737
|
+
/**
|
|
3738
|
+
* Serve HTTP `Range` requests (206 Partial Content) by slicing the cached
|
|
3739
|
+
* full response. Enable for audio/video so seeking works offline. The full
|
|
3740
|
+
* resource is cached once (the `Range` header is stripped before caching).
|
|
3741
|
+
*/
|
|
3742
|
+
rangeRequests?: boolean;
|
|
3743
|
+
}
|
|
3744
|
+
|
|
3745
|
+
/**
|
|
3746
|
+
* Service-worker caching helpers — a small, dependency-free subset of what
|
|
3747
|
+
* Workbox provides: precaching of the build's app shell (so the app launches
|
|
3748
|
+
* offline) plus runtime caching strategies for fonts, APIs and images.
|
|
3749
|
+
*
|
|
3750
|
+
* Import these inside your own `sw.ts`. They run in the service-worker global
|
|
3751
|
+
* scope, not the main thread. Pair `installPrecache` with the
|
|
3752
|
+
* `tempestPwaManifest()` Vite plugin (from `tempest-react-sdk/vite`), which
|
|
3753
|
+
* emits the `precache-manifest.json` this reads at install time.
|
|
3754
|
+
*
|
|
3755
|
+
* @example
|
|
3756
|
+
* /// <reference lib="webworker" />
|
|
3757
|
+
* import { installRuntimeCache, installPrecache } from "tempest-react-sdk/sw";
|
|
3758
|
+
*
|
|
3759
|
+
* // Register specific routes FIRST so they win over the precache catch-all.
|
|
3760
|
+
* installRuntimeCache([
|
|
3761
|
+
* { match: /\/api\//, strategy: "network-first", cacheName: "api", maxAgeSeconds: 300 },
|
|
3762
|
+
* ]);
|
|
3763
|
+
* installPrecache();
|
|
3764
|
+
*/
|
|
3765
|
+
/** Caching strategy for a runtime route. Mirrors the common Workbox trio. */
|
|
3766
|
+
export declare type RuntimeStrategy = "cache-first" | "network-first" | "stale-while-revalidate";
|
|
3767
|
+
|
|
3638
3768
|
/**
|
|
3639
3769
|
* Apply `env(safe-area-inset-*)` padding so content avoids iOS notch /
|
|
3640
3770
|
* Android navbar / device chrome. Wrap the outermost container of pages
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createPartialResponse as Dw, installBackgroundSync as Mw, installNotificationClickHandler as Iw, installPrecache as Aw, installPushHandler as Rw, installRuntimeCache as Pw, installSkipWaitingListener as Bw, registerServiceWorker as Ow, skipWaiting as Fw, unregisterAllServiceWorkers as zw } from "./sw.js";
|
|
2
2
|
import { jsx as a, jsxs as v, Fragment as ce } from "react/jsx-runtime";
|
|
3
3
|
import { useId as U, useState as N, useCallback as E, useEffect as S, useMemo as A, Fragment as lt, forwardRef as F, useRef as L, useContext as Ae, createContext as Re, cloneElement as tn, createElement as kn, lazy as Tn, Suspense as Sn, Component as En, isValidElement as Cn, useSyncExternalStore as nn } from "react";
|
|
4
4
|
import { QueryClient as xn, QueryClientProvider as Ln } from "@tanstack/react-query";
|
|
5
5
|
import { Navigate as Dn, MemoryRouter as Mn, HashRouter as In, BrowserRouter as An, Routes as Rn, Route as xt } from "react-router-dom";
|
|
6
|
-
import { BrowserRouter as
|
|
6
|
+
import { BrowserRouter as jw, HashRouter as Uw, Link as Hw, MemoryRouter as Kw, NavLink as qw, Navigate as Gw, Outlet as Jw, Route as Qw, Routes as Yw, redirect as Vw, useLocation as Zw, useMatch as Xw, useNavigate as ev, useParams as tv, useRouteError as nv, useSearchParams as rv } from "react-router-dom";
|
|
7
7
|
import { createPortal as Ue } from "react-dom";
|
|
8
8
|
import { useFormContext as Pn, Controller as Bn, useForm as On } from "react-hook-form";
|
|
9
|
-
import { Controller as
|
|
9
|
+
import { Controller as ov, FormProvider as iv, useFieldArray as av, useForm as cv, useFormContext as lv, useFormState as uv, useWatch as dv } from "react-hook-form";
|
|
10
10
|
import { create as wt } from "zustand";
|
|
11
11
|
import { persist as rn, createJSONStorage as sn } from "zustand/middleware";
|
|
12
12
|
import Fn from "dexie";
|
|
@@ -6941,7 +6941,7 @@ export {
|
|
|
6941
6941
|
Q_ as BottomNavigation,
|
|
6942
6942
|
Y_ as BottomSheet,
|
|
6943
6943
|
V_ as Breadcrumbs,
|
|
6944
|
-
|
|
6944
|
+
jw as BrowserRouter,
|
|
6945
6945
|
$t as Button,
|
|
6946
6946
|
Xh as CACHE_TIME,
|
|
6947
6947
|
Oy as CEPInput,
|
|
@@ -6961,7 +6961,7 @@ export {
|
|
|
6961
6961
|
rg as ConfirmDialog,
|
|
6962
6962
|
hg as Container,
|
|
6963
6963
|
hb as ContextMenu,
|
|
6964
|
-
|
|
6964
|
+
ov as Controller,
|
|
6965
6965
|
Zg as CopyButton,
|
|
6966
6966
|
cb as DataList,
|
|
6967
6967
|
Yb as DataTable,
|
|
@@ -6980,12 +6980,12 @@ export {
|
|
|
6980
6980
|
dg as Form,
|
|
6981
6981
|
fg as FormActions,
|
|
6982
6982
|
Ty as FormField,
|
|
6983
|
-
|
|
6983
|
+
iv as FormProvider,
|
|
6984
6984
|
mg as FormRow,
|
|
6985
6985
|
pg as FormSection,
|
|
6986
6986
|
ay as GoogleSignIn,
|
|
6987
6987
|
gg as Grid,
|
|
6988
|
-
|
|
6988
|
+
Uw as HashRouter,
|
|
6989
6989
|
Lg as Hide,
|
|
6990
6990
|
_b as HoverCard,
|
|
6991
6991
|
c_ as I18nProvider,
|
|
@@ -6993,17 +6993,17 @@ export {
|
|
|
6993
6993
|
Ct as Input,
|
|
6994
6994
|
bg as Kbd,
|
|
6995
6995
|
mb as Label,
|
|
6996
|
-
|
|
6997
|
-
|
|
6996
|
+
Hw as Link,
|
|
6997
|
+
Kw as MemoryRouter,
|
|
6998
6998
|
$b as Menubar,
|
|
6999
6999
|
ti as Modal,
|
|
7000
7000
|
eb as Money,
|
|
7001
7001
|
Fy as MoneyInput,
|
|
7002
|
-
|
|
7002
|
+
qw as NavLink,
|
|
7003
7003
|
yg as Navbar,
|
|
7004
|
-
|
|
7004
|
+
Gw as Navigate,
|
|
7005
7005
|
vb as NavigationMenu,
|
|
7006
|
-
|
|
7006
|
+
Jw as Outlet,
|
|
7007
7007
|
wg as Page,
|
|
7008
7008
|
Kc as Pagination,
|
|
7009
7009
|
vg as PasswordInput,
|
|
@@ -7020,9 +7020,9 @@ export {
|
|
|
7020
7020
|
Cg as RatingStars,
|
|
7021
7021
|
Xg as RelativeTime,
|
|
7022
7022
|
yb as Resizable,
|
|
7023
|
-
|
|
7023
|
+
Qw as Route,
|
|
7024
7024
|
t_ as RouteGuard,
|
|
7025
|
-
|
|
7025
|
+
Yw as Routes,
|
|
7026
7026
|
Zh as STALE_TIME,
|
|
7027
7027
|
Dg as SafeArea,
|
|
7028
7028
|
bb as ScrollArea,
|
|
@@ -7075,6 +7075,7 @@ export {
|
|
|
7075
7075
|
ew as createLaunchDarklyFeatureFlagsAdapter,
|
|
7076
7076
|
x_ as createLogger,
|
|
7077
7077
|
Ny as createOfflineStore,
|
|
7078
|
+
Dw as createPartialResponse,
|
|
7078
7079
|
Jy as createPostHogTelemetryAdapter,
|
|
7079
7080
|
uy as createQueryKeys,
|
|
7080
7081
|
iy as createRefreshQueue,
|
|
@@ -7100,9 +7101,12 @@ export {
|
|
|
7100
7101
|
ty as generateIdempotencyKey,
|
|
7101
7102
|
jy as getInitialTheme,
|
|
7102
7103
|
uw as groupBy,
|
|
7103
|
-
|
|
7104
|
-
|
|
7105
|
-
|
|
7104
|
+
Mw as installBackgroundSync,
|
|
7105
|
+
Iw as installNotificationClickHandler,
|
|
7106
|
+
Aw as installPrecache,
|
|
7107
|
+
Rw as installPushHandler,
|
|
7108
|
+
Pw as installRuntimeCache,
|
|
7109
|
+
Bw as installSkipWaitingListener,
|
|
7106
7110
|
gw as isDefined,
|
|
7107
7111
|
_w as isEmpty,
|
|
7108
7112
|
oy as isJWTExpired,
|
|
@@ -7122,12 +7126,12 @@ export {
|
|
|
7122
7126
|
lw as pluralize,
|
|
7123
7127
|
Cw as randomId,
|
|
7124
7128
|
mw as range,
|
|
7125
|
-
|
|
7126
|
-
|
|
7129
|
+
Vw as redirect,
|
|
7130
|
+
Ow as registerServiceWorker,
|
|
7127
7131
|
Mm as relativeTime,
|
|
7128
7132
|
ey as retry,
|
|
7129
7133
|
tw as share,
|
|
7130
|
-
|
|
7134
|
+
Fw as skipWaiting,
|
|
7131
7135
|
Sw as sleep,
|
|
7132
7136
|
sw as slugify,
|
|
7133
7137
|
vy as stopAudio,
|
|
@@ -7137,7 +7141,7 @@ export {
|
|
|
7137
7141
|
ow as truncate,
|
|
7138
7142
|
dw as uniqueBy,
|
|
7139
7143
|
Ly as unmask,
|
|
7140
|
-
|
|
7144
|
+
zw as unregisterAllServiceWorkers,
|
|
7141
7145
|
Xb as uploadWithProgress,
|
|
7142
7146
|
f_ as urlBase64ToUint8Array,
|
|
7143
7147
|
Lb as useAsync,
|
|
@@ -7153,12 +7157,12 @@ export {
|
|
|
7153
7157
|
Eb as useEventListener,
|
|
7154
7158
|
by as useEventStream,
|
|
7155
7159
|
Yy as useFeatureFlag,
|
|
7156
|
-
|
|
7160
|
+
av as useFieldArray,
|
|
7157
7161
|
Vy as useFlagValue,
|
|
7158
7162
|
kf as useFocusTrap,
|
|
7159
|
-
|
|
7160
|
-
|
|
7161
|
-
|
|
7163
|
+
cv as useForm,
|
|
7164
|
+
lv as useFormContext,
|
|
7165
|
+
uv as useFormState,
|
|
7162
7166
|
Fb as useGeolocation,
|
|
7163
7167
|
Jb as useHover,
|
|
7164
7168
|
l_ as useI18n,
|
|
@@ -7167,22 +7171,22 @@ export {
|
|
|
7167
7171
|
Hb as useInterval,
|
|
7168
7172
|
Pb as useKeyboardShortcut,
|
|
7169
7173
|
Cb as useLocalStorage,
|
|
7170
|
-
|
|
7174
|
+
Zw as useLocation,
|
|
7171
7175
|
Qb as useLongPress,
|
|
7172
|
-
|
|
7176
|
+
Xw as useMatch,
|
|
7173
7177
|
Sb as useMediaQuery,
|
|
7174
|
-
|
|
7178
|
+
ev as useNavigate,
|
|
7175
7179
|
cy as useOAuthCallback,
|
|
7176
7180
|
Db as useOnline,
|
|
7177
7181
|
Ph as usePagination,
|
|
7178
|
-
|
|
7182
|
+
tv as useParams,
|
|
7179
7183
|
ny as usePoll,
|
|
7180
7184
|
Ub as usePrevious,
|
|
7181
7185
|
yy as usePushSubscription,
|
|
7182
7186
|
Ab as useResizeObserver,
|
|
7183
|
-
|
|
7187
|
+
nv as useRouteError,
|
|
7184
7188
|
zb as useScrollLock,
|
|
7185
|
-
|
|
7189
|
+
rv as useSearchParams,
|
|
7186
7190
|
Wb as useStableCallback,
|
|
7187
7191
|
Ky as useTelemetry,
|
|
7188
7192
|
hy as useTheme,
|
|
@@ -7192,7 +7196,7 @@ export {
|
|
|
7192
7196
|
xb as useToggle,
|
|
7193
7197
|
_y as useTranslate,
|
|
7194
7198
|
zy as useViaCEP,
|
|
7195
|
-
|
|
7199
|
+
dv as useWatch,
|
|
7196
7200
|
Wy as useWebSocket,
|
|
7197
7201
|
Gb as useWindowSize,
|
|
7198
7202
|
Ey as useZodForm,
|
package/dist/vite.cjs
CHANGED
|
@@ -1,2 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";var z=Object.create;var $=Object.defineProperty;var B=Object.getOwnPropertyDescriptor;var I=Object.getOwnPropertyNames;var H=Object.getPrototypeOf,D=Object.prototype.hasOwnProperty;var O=(e,t,n,a)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of I(t))!D.call(e,s)&&s!==n&&$(e,s,{get:()=>t[s],enumerable:!(a=B(t,s))||a.enumerable});return e};var T=(e,t,n)=>(n=e!=null?z(H(e)):{},O(t||!e||!e.__esModule?$(n,"default",{value:e,enumerable:!0}):n,e));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const S=require("node:path"),A=require("vite"),F=require("@vitejs/plugin-react"),R=require("node:fs/promises");function W(e){const t={};for(const[n,a]of Object.entries(e))t[n]=typeof a=="string"?{target:a,changeOrigin:!0}:a;return t}function q(e={}){const{srcDir:t="src",port:n=5173,host:a="127.0.0.1",open:s=!1,proxy:c,alias:d={},plugins:g=[],overrides:u={}}=e,r=u,l={plugins:[F(),...g],resolve:{alias:{"@":S.resolve(process.cwd(),t),...d}},server:{port:n,host:a,open:s,...c?{proxy:W(c)}:{}}},p={...l,...r,plugins:[...l.plugins??[],...r.plugins??[]],resolve:{...l.resolve,...r.resolve},server:{...l.server,...r.server}};return A.defineConfig(p)}function N(e,t){return`${e.endsWith("/")?e:`${e}/`}${t}`.replace(/([^:]\/)\/+/g,"$1")}function U(e){let t=5381;for(let n=0;n<e.length;n++)t=(t<<5)+t+e.charCodeAt(n)>>>0;return t.toString(16)}function L(e={}){const{fileName:t="precache-manifest.json",additionalUrls:n=[],exclude:a=/\.map$/,includeHtml:s=!0,appShell:c="/index.html"}=e;let d="/";return{name:"tempest-pwa-manifest",apply:"build",configResolved(u){d=u.base??"/"},generateBundle(u,r){const l=new Set(n);c&&l.add(c);for(const w of Object.keys(r))w!==t&&(a.test(w)||!s&&w.endsWith(".html")||l.add(N(d,w)));const p=[...l].sort(),f=U(p.join(`
|
|
2
|
+
`));this.emitFile({type:"asset",fileName:t,source:JSON.stringify({version:f,urls:p})})}}}const _=[{width:375,height:667,ratio:2},{width:375,height:812,ratio:3},{width:390,height:844,ratio:3},{width:393,height:852,ratio:3},{width:414,height:896,ratio:2},{width:414,height:896,ratio:3},{width:428,height:926,ratio:3},{width:430,height:932,ratio:3},{width:768,height:1024,ratio:2},{width:834,height:1194,ratio:2},{width:1024,height:1366,ratio:2}];function M(e){return`splash/apple-splash-${e.width*e.ratio}x${e.height*e.ratio}.png`}function J(e){return`(device-width: ${e.width}px) and (device-height: ${e.height}px) and (-webkit-device-pixel-ratio: ${e.ratio}) and (orientation: portrait)`}function P(e){const t=e.replace("#",""),n=t.length===3?t.split("").map(a=>a+a).join(""):t;return{r:parseInt(n.slice(0,2),16),g:parseInt(n.slice(2,4),16),b:parseInt(n.slice(4,6),16)}}function V(e={}){const{source:t="public/icon.svg",sizes:n=[192,512],maskableSizes:a=[512],appleTouchIcon:s=180,outDir:c="icons",background:d="#ffffff",maskablePadding:g=.1,appleSplash:u=!1,splashBackground:r,splashIconScale:l=.3}=e,p=u?Array.isArray(u)?u:_:[];let f=process.cwd();return{name:"tempest-pwa-icons",apply:"build",configResolved(h){f=h.root??process.cwd()},transformIndexHtml(){if(p.length)return p.map(h=>({tag:"link",attrs:{rel:"apple-touch-startup-image",media:J(h),href:`/${M(h)}`},injectTo:"head"}))},async generateBundle(){let h;try{const o=await import("sharp");h=o.default??o}catch{this.warn("tempestPwaIcons: `sharp` is not installed — skipping icon generation. Run `npm i -D sharp` to enable it.");return}const m=await R.readFile(S.resolve(f,t)),y=P(d),v=(i,o)=>{this.emitFile({type:"asset",fileName:i,source:o})};for(const i of n){const o=await h(m,{density:Math.max(i,512)}).resize(i,i,{fit:"contain",background:{r:0,g:0,b:0,alpha:0}}).png().toBuffer();v(`${c}/icon-${i}.png`,o)}for(const i of a){const o=Math.round(i*(1-g*2)),b=await h(m,{density:Math.max(i,512)}).resize(o,o,{fit:"contain",background:{r:0,g:0,b:0,alpha:0}}).extend({top:Math.round((i-o)/2),bottom:Math.round((i-o)/2),left:Math.round((i-o)/2),right:Math.round((i-o)/2),background:{...y,alpha:1}}).resize(i,i).png().toBuffer();v(`${c}/maskable-${i}.png`,b)}if(s){const i=await h(m,{density:Math.max(s,512)}).resize(s,s,{fit:"contain",background:{...y,alpha:1}}).flatten({background:y}).png().toBuffer();v("apple-touch-icon.png",i)}if(p.length){const i=P(r??d);for(const o of p){const b=o.width*o.ratio,k=o.height*o.ratio,x=Math.round(Math.min(b,k)*l),j=await h(m,{density:Math.max(x,512)}).resize(x,x,{fit:"contain",background:{r:0,g:0,b:0,alpha:0}}).png().toBuffer(),C=await h({create:{width:b,height:k,channels:4,background:{...i,alpha:1}}}).composite([{input:j,gravity:"center"}]).png().toBuffer();v(M(o),C)}}}}}function E(e={}){const{swSrc:t="src/sw.ts",swUrl:n="/sw.js",manifestUrl:a="/precache-manifest.json",enabled:s=!0}=e;let c=process.cwd();return{name:"tempest-pwa-dev-sw",apply:"serve",configResolved(g){c=g.root??process.cwd()},configureServer(g){s&&g.middlewares.use(async(u,r,l)=>{const p=(u.url??"").split("?")[0];if(p===n){try{const w=await(await import("esbuild")).build({entryPoints:[S.resolve(c,t)],bundle:!0,format:"iife",platform:"browser",target:"es2020",write:!1,absWorkingDir:c,logLevel:"silent"});r.setHeader("Content-Type","application/javascript"),r.setHeader("Service-Worker-Allowed","/"),r.setHeader("Cache-Control","no-cache"),r.end(w.outputFiles[0].text)}catch(f){r.statusCode=500,r.end(`// SW dev build failed:
|
|
3
|
+
// ${String(f)}`)}return}if(p===a){r.setHeader("Content-Type","application/json"),r.setHeader("Cache-Control","no-cache"),r.end(JSON.stringify({version:"dev",urls:[]}));return}l()})}}}exports.createViteConfig=q;exports.tempestPwaDevSw=E;exports.tempestPwaIcons=V;exports.tempestPwaManifest=L;
|
|
2
4
|
//# sourceMappingURL=vite.cjs.map
|
package/dist/vite.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vite.cjs","sources":["../src/vite/create-vite-config.ts"],"sourcesContent":["import { resolve } from \"node:path\";\nimport { defineConfig } from \"vite\";\nimport type { ProxyOptions, UserConfig } from \"vite\";\nimport react from \"@vitejs/plugin-react\";\n\n/**\n * A Vite proxy entry: either a target URL string (expanded to\n * `{ target, changeOrigin: true }`) or a raw Vite `ProxyOptions` object.\n */\nexport type ProxyEntry = string | Record<string, unknown>;\n\nexport interface CreateViteConfigOptions {\n /**\n * Source directory aliased to `@`, relative to the project root.\n * Default: `\"src\"` (so `@/components/Button` → `<root>/src/components/Button`).\n */\n srcDir?: string;\n /** Dev server port. Default: `5173`. */\n port?: number;\n /** Dev server host. Default: `\"127.0.0.1\"`. */\n host?: string | boolean;\n /** Open the browser on `dev` start. Default: `false`. */\n open?: boolean;\n /**\n * Dev proxy table. String values are expanded to\n * `{ target, changeOrigin: true }`; objects are passed through untouched.\n *\n * @example { \"/api\": \"http://127.0.0.1:8000\" }\n */\n proxy?: Record<string, ProxyEntry>;\n /** Extra path aliases merged on top of the default `@` → src alias. */\n alias?: Record<string, string>;\n /** Vite plugins appended after `@vitejs/plugin-react`. */\n plugins?: unknown[];\n /**\n * Arbitrary Vite config (a `UserConfig` object) deep-merged last, for\n * escape-hatch overrides (build target, define, extra `server` keys, …).\n */\n overrides?: Record<string, unknown>;\n}\n\n/**\n * The resulting Vite config object. Typed loosely so the SDK's published\n * declarations stay free of `vite`'s internal types; assign it straight to a\n * `vite.config.ts` default export.\n */\nexport type TempestViteConfig = Record<string, unknown>;\n\nfunction normalizeProxy(proxy: Record<string, ProxyEntry>): Record<string, ProxyOptions> {\n const out: Record<string, ProxyOptions> = {};\n for (const [path, value] of Object.entries(proxy)) {\n out[path] =\n typeof value === \"string\"\n ? { target: value, changeOrigin: true }\n : (value as ProxyOptions);\n }\n return out;\n}\n\n/**\n * Build a Tempest-flavored Vite config for a React app: the `@vitejs/plugin-react`\n * plugin, the `@` → `src` import alias, and sane dev-server defaults — so a\n * consuming app's `vite.config.ts` is a single call instead of repeated\n * boilerplate. Everything is overridable.\n *\n * Import it from the dedicated Node entry point:\n *\n * @example\n * // vite.config.ts\n * import { createViteConfig } from \"tempest-react-sdk/vite\";\n *\n * export default createViteConfig({\n * proxy: { \"/api\": \"http://127.0.0.1:8000\" },\n * });\n */\nexport function createViteConfig(options: CreateViteConfigOptions = {}): TempestViteConfig {\n const {\n srcDir = \"src\",\n port = 5173,\n host = \"127.0.0.1\",\n open = false,\n proxy,\n alias = {},\n plugins = [],\n overrides = {},\n } = options;\n\n const overridesConfig = overrides as UserConfig;\n\n const base: UserConfig = {\n plugins: [react(), ...plugins] as UserConfig[\"plugins\"],\n resolve: {\n alias: {\n \"@\": resolve(process.cwd(), srcDir),\n ...alias,\n },\n },\n server: {\n port,\n host,\n open,\n ...(proxy ? { proxy: normalizeProxy(proxy) } : {}),\n },\n };\n\n const merged: UserConfig = {\n ...base,\n ...overridesConfig,\n plugins: [...(base.plugins ?? []), ...(overridesConfig.plugins ?? [])],\n resolve: { ...base.resolve, ...overridesConfig.resolve },\n server: { ...base.server, ...overridesConfig.server },\n };\n\n return defineConfig(merged) as TempestViteConfig;\n}\n"],"names":["normalizeProxy","proxy","out","path","value","createViteConfig","options","srcDir","port","host","open","alias","plugins","overrides","overridesConfig","base","react","resolve","merged","defineConfig"],"mappings":"iKAgDA,SAASA,EAAeC,EAAiE,CACrF,MAAMC,EAAoC,CAAA,EAC1C,SAAW,CAACC,EAAMC,CAAK,IAAK,OAAO,QAAQH,CAAK,EAC5CC,EAAIC,CAAI,EACJ,OAAOC,GAAU,SACX,CAAE,OAAQA,EAAO,aAAc,EAAA,EAC9BA,EAEf,OAAOF,CACX,CAkBO,SAASG,EAAiBC,EAAmC,GAAuB,CACvF,KAAM,CACF,OAAAC,EAAS,MACT,KAAAC,EAAO,KACP,KAAAC,EAAO,YACP,KAAAC,EAAO,GACP,MAAAT,EACA,MAAAU,EAAQ,CAAA,EACR,QAAAC,EAAU,CAAA,EACV,UAAAC,EAAY,CAAA,CAAC,EACbP,EAEEQ,EAAkBD,EAElBE,EAAmB,CACrB,QAAS,CAACC,IAAS,GAAGJ,CAAO,EAC7B,QAAS,CACL,MAAO,CACH,IAAKK,EAAAA,QAAQ,QAAQ,IAAA,EAAOV,CAAM,EAClC,GAAGI,CAAA,CACP,EAEJ,OAAQ,CACJ,KAAAH,EACA,KAAAC,EACA,KAAAC,EACA,GAAIT,EAAQ,CAAE,MAAOD,EAAeC,CAAK,CAAA,EAAM,CAAA,CAAC,CACpD,EAGEiB,EAAqB,CACvB,GAAGH,EACH,GAAGD,EACH,QAAS,CAAC,GAAIC,EAAK,SAAW,CAAA,EAAK,GAAID,EAAgB,SAAW,EAAG,EACrE,QAAS,CAAE,GAAGC,EAAK,QAAS,GAAGD,EAAgB,OAAA,EAC/C,OAAQ,CAAE,GAAGC,EAAK,OAAQ,GAAGD,EAAgB,MAAA,CAAO,EAGxD,OAAOK,EAAAA,aAAaD,CAAM,CAC9B"}
|
|
1
|
+
{"version":3,"file":"vite.cjs","sources":["../src/vite/create-vite-config.ts","../src/vite/tempest-pwa-manifest.ts","../src/vite/tempest-pwa-icons.ts","../src/vite/tempest-pwa-dev-sw.ts"],"sourcesContent":["import { resolve } from \"node:path\";\nimport { defineConfig } from \"vite\";\nimport type { ProxyOptions, UserConfig } from \"vite\";\nimport react from \"@vitejs/plugin-react\";\n\n/**\n * A Vite proxy entry: either a target URL string (expanded to\n * `{ target, changeOrigin: true }`) or a raw Vite `ProxyOptions` object.\n */\nexport type ProxyEntry = string | Record<string, unknown>;\n\nexport interface CreateViteConfigOptions {\n /**\n * Source directory aliased to `@`, relative to the project root.\n * Default: `\"src\"` (so `@/components/Button` → `<root>/src/components/Button`).\n */\n srcDir?: string;\n /** Dev server port. Default: `5173`. */\n port?: number;\n /** Dev server host. Default: `\"127.0.0.1\"`. */\n host?: string | boolean;\n /** Open the browser on `dev` start. Default: `false`. */\n open?: boolean;\n /**\n * Dev proxy table. String values are expanded to\n * `{ target, changeOrigin: true }`; objects are passed through untouched.\n *\n * @example { \"/api\": \"http://127.0.0.1:8000\" }\n */\n proxy?: Record<string, ProxyEntry>;\n /** Extra path aliases merged on top of the default `@` → src alias. */\n alias?: Record<string, string>;\n /** Vite plugins appended after `@vitejs/plugin-react`. */\n plugins?: unknown[];\n /**\n * Arbitrary Vite config (a `UserConfig` object) deep-merged last, for\n * escape-hatch overrides (build target, define, extra `server` keys, …).\n */\n overrides?: Record<string, unknown>;\n}\n\n/**\n * The resulting Vite config object. Typed loosely so the SDK's published\n * declarations stay free of `vite`'s internal types; assign it straight to a\n * `vite.config.ts` default export.\n */\nexport type TempestViteConfig = Record<string, unknown>;\n\nfunction normalizeProxy(proxy: Record<string, ProxyEntry>): Record<string, ProxyOptions> {\n const out: Record<string, ProxyOptions> = {};\n for (const [path, value] of Object.entries(proxy)) {\n out[path] =\n typeof value === \"string\"\n ? { target: value, changeOrigin: true }\n : (value as ProxyOptions);\n }\n return out;\n}\n\n/**\n * Build a Tempest-flavored Vite config for a React app: the `@vitejs/plugin-react`\n * plugin, the `@` → `src` import alias, and sane dev-server defaults — so a\n * consuming app's `vite.config.ts` is a single call instead of repeated\n * boilerplate. Everything is overridable.\n *\n * Import it from the dedicated Node entry point:\n *\n * @example\n * // vite.config.ts\n * import { createViteConfig } from \"tempest-react-sdk/vite\";\n *\n * export default createViteConfig({\n * proxy: { \"/api\": \"http://127.0.0.1:8000\" },\n * });\n */\nexport function createViteConfig(options: CreateViteConfigOptions = {}): TempestViteConfig {\n const {\n srcDir = \"src\",\n port = 5173,\n host = \"127.0.0.1\",\n open = false,\n proxy,\n alias = {},\n plugins = [],\n overrides = {},\n } = options;\n\n const overridesConfig = overrides as UserConfig;\n\n const base: UserConfig = {\n plugins: [react(), ...plugins] as UserConfig[\"plugins\"],\n resolve: {\n alias: {\n \"@\": resolve(process.cwd(), srcDir),\n ...alias,\n },\n },\n server: {\n port,\n host,\n open,\n ...(proxy ? { proxy: normalizeProxy(proxy) } : {}),\n },\n };\n\n const merged: UserConfig = {\n ...base,\n ...overridesConfig,\n plugins: [...(base.plugins ?? []), ...(overridesConfig.plugins ?? [])],\n resolve: { ...base.resolve, ...overridesConfig.resolve },\n server: { ...base.server, ...overridesConfig.server },\n };\n\n return defineConfig(merged) as TempestViteConfig;\n}\n","import type { Plugin } from \"vite\";\n\n/**\n * A Vite plugin object. Typed loosely so the SDK's published declarations stay\n * free of `vite`'s internal types (which the `.d.ts` rollup can't analyze);\n * assign the result straight into a `plugins: [...]` array.\n */\nexport type TempestVitePlugin = { name: string } & Record<string, unknown>;\n\n/** Options for {@link tempestPwaManifest}. */\nexport interface TempestPwaManifestOptions {\n /** Output file name (under the build root). Default `precache-manifest.json`. */\n fileName?: string;\n /**\n * Extra URLs to precache that Vite doesn't emit into the bundle — typically\n * `public/` assets like the web manifest and icons. Default `[]`.\n */\n additionalUrls?: string[];\n /** Emitted files matching this are skipped. Default `/\\.map$/` (source maps). */\n exclude?: RegExp;\n /** Include emitted `.html` documents (the app shell). Default `true`. */\n includeHtml?: boolean;\n /**\n * App-shell document always added to the manifest, even if Vite emits it\n * after this plugin runs. Must match `installPrecache`'s `navigateFallback`\n * so offline navigations resolve. Pass `false` to disable. Default `/index.html`.\n */\n appShell?: string | false;\n}\n\nfunction joinBase(base: string, file: string): string {\n const prefix = base.endsWith(\"/\") ? base : `${base}/`;\n return `${prefix}${file}`.replace(/([^:]\\/)\\/+/g, \"$1\");\n}\n\n/** Deterministic djb2 hash → hex. Stable across rebuilds with the same assets. */\nfunction hash(input: string): string {\n let h = 5381;\n for (let i = 0; i < input.length; i++) {\n h = ((h << 5) + h + input.charCodeAt(i)) >>> 0;\n }\n return h.toString(16);\n}\n\n/**\n * Vite build plugin that emits a `precache-manifest.json` listing every built\n * asset (plus any `additionalUrls`) as root-absolute URLs, with a content-based\n * `version`. It is the dependency-free counterpart to Workbox's `__WB_MANIFEST`:\n * `installPrecache` (from `tempest-react-sdk/sw`) reads this file at the service\n * worker's `install` event to cache the app shell for offline use.\n *\n * @example\n * // vite.config.ts\n * import { createViteConfig, tempestPwaManifest } from \"tempest-react-sdk/vite\";\n *\n * export default createViteConfig({\n * plugins: [tempestPwaManifest({ additionalUrls: [\"/manifest.webmanifest\", \"/icon.svg\"] })],\n * });\n */\nexport function tempestPwaManifest(options: TempestPwaManifestOptions = {}): TempestVitePlugin {\n const {\n fileName = \"precache-manifest.json\",\n additionalUrls = [],\n exclude = /\\.map$/,\n includeHtml = true,\n appShell = \"/index.html\",\n } = options;\n\n let base = \"/\";\n\n const plugin: Plugin = {\n name: \"tempest-pwa-manifest\",\n apply: \"build\",\n configResolved(config) {\n base = config.base ?? \"/\";\n },\n generateBundle(_outputOptions, bundle) {\n const urls = new Set<string>(additionalUrls);\n // Vite may emit index.html after this hook, so guarantee the shell.\n if (appShell) urls.add(appShell);\n for (const file of Object.keys(bundle)) {\n if (file === fileName) continue;\n if (exclude.test(file)) continue;\n if (!includeHtml && file.endsWith(\".html\")) continue;\n urls.add(joinBase(base, file));\n }\n\n const list = [...urls].sort();\n const version = hash(list.join(\"\\n\"));\n this.emitFile({\n type: \"asset\",\n fileName,\n source: JSON.stringify({ version, urls: list }),\n });\n },\n };\n\n return plugin as TempestVitePlugin;\n}\n","import { readFile } from \"node:fs/promises\";\nimport { resolve } from \"node:path\";\nimport type { Plugin } from \"vite\";\nimport type { TempestVitePlugin } from \"./tempest-pwa-manifest\";\n\n/** Options for {@link tempestPwaIcons}. */\nexport interface TempestPwaIconsOptions {\n /** Source image (SVG or large PNG), relative to the project root. Default `public/icon.svg`. */\n source?: string;\n /** Square \"any\"-purpose icon sizes to emit. Default `[192, 512]`. */\n sizes?: number[];\n /** Square \"maskable\" icon sizes to emit (with safe-zone padding). Default `[512]`. */\n maskableSizes?: number[];\n /** Apple touch icon size, or `false` to skip. Default `180`. */\n appleTouchIcon?: number | false;\n /** Output directory for the icon set, under the build root. Default `icons`. */\n outDir?: string;\n /** Opaque background for maskable + apple icons (no transparency allowed). Default `#ffffff`. */\n background?: string;\n /** Maskable safe-zone padding as a fraction of the icon. Default `0.1` (10% each side). */\n maskablePadding?: number;\n /**\n * Generate Apple splash screens (launch images) and inject the matching\n * `<link rel=\"apple-touch-startup-image\">` tags. `true` uses a built-in set\n * of common iPhone/iPad portrait sizes; pass an array to override. Default `false`.\n */\n appleSplash?: boolean | AppleSplashSpec[];\n /** Background color for splash screens. Default: `background`. */\n splashBackground?: string;\n /** Icon size on the splash as a fraction of the shorter side. Default `0.3`. */\n splashIconScale?: number;\n}\n\n/** A single Apple splash target (CSS px + device pixel ratio). */\nexport interface AppleSplashSpec {\n /** CSS width (device-width in the media query). */\n width: number;\n /** CSS height (device-height in the media query). */\n height: number;\n /** Device pixel ratio. */\n ratio: number;\n}\n\n/** Common iPhone/iPad portrait splash sizes (CSS px @ ratio). */\nconst DEFAULT_SPLASH: AppleSplashSpec[] = [\n { width: 375, height: 667, ratio: 2 }, // iPhone SE / 8\n { width: 375, height: 812, ratio: 3 }, // iPhone X / 11 Pro\n { width: 390, height: 844, ratio: 3 }, // iPhone 12 / 13 / 14\n { width: 393, height: 852, ratio: 3 }, // iPhone 14 Pro / 15\n { width: 414, height: 896, ratio: 2 }, // iPhone XR / 11\n { width: 414, height: 896, ratio: 3 }, // iPhone XS Max / 11 Pro Max\n { width: 428, height: 926, ratio: 3 }, // iPhone 13/14 Pro Max\n { width: 430, height: 932, ratio: 3 }, // iPhone 15 Pro Max\n { width: 768, height: 1024, ratio: 2 }, // iPad\n { width: 834, height: 1194, ratio: 2 }, // iPad Pro 11\"\n { width: 1024, height: 1366, ratio: 2 }, // iPad Pro 12.9\"\n];\n\nfunction splashFileName(spec: AppleSplashSpec): string {\n return `splash/apple-splash-${spec.width * spec.ratio}x${spec.height * spec.ratio}.png`;\n}\n\nfunction splashMedia(spec: AppleSplashSpec): string {\n return (\n `(device-width: ${spec.width}px) and (device-height: ${spec.height}px) ` +\n `and (-webkit-device-pixel-ratio: ${spec.ratio}) and (orientation: portrait)`\n );\n}\n\ninterface Rgb {\n r: number;\n g: number;\n b: number;\n}\n\nfunction hexToRgb(hex: string): Rgb {\n const value = hex.replace(\"#\", \"\");\n const full =\n value.length === 3\n ? value\n .split(\"\")\n .map((c) => c + c)\n .join(\"\")\n : value;\n return {\n r: parseInt(full.slice(0, 2), 16),\n g: parseInt(full.slice(2, 4), 16),\n b: parseInt(full.slice(4, 6), 16),\n };\n}\n\n/**\n * Build plugin that rasterizes a single source image into a full PWA icon set\n * (regular + maskable + apple-touch-icon), the dependency-free counterpart to\n * `@vite-pwa/assets-generator`. Rendering uses **`sharp`**, imported lazily and\n * treated as optional: if it isn't installed the plugin logs a warning and skips\n * generation (your build still succeeds; the icons just aren't produced).\n *\n * Point your `manifest.webmanifest` icon entries at the emitted files\n * (`/icons/icon-192.png`, `/icons/icon-512.png`, `/icons/maskable-512.png`) and\n * the apple touch icon at `/apple-touch-icon.png`.\n *\n * @example\n * // vite.config.ts\n * import { createViteConfig, tempestPwaIcons } from \"tempest-react-sdk/vite\";\n *\n * export default createViteConfig({\n * plugins: [tempestPwaIcons({ source: \"public/icon.svg\" })],\n * });\n */\nexport function tempestPwaIcons(options: TempestPwaIconsOptions = {}): TempestVitePlugin {\n const {\n source = \"public/icon.svg\",\n sizes = [192, 512],\n maskableSizes = [512],\n appleTouchIcon = 180,\n outDir = \"icons\",\n background = \"#ffffff\",\n maskablePadding = 0.1,\n appleSplash = false,\n splashBackground,\n splashIconScale = 0.3,\n } = options;\n\n const splashSpecs: AppleSplashSpec[] = appleSplash\n ? Array.isArray(appleSplash)\n ? appleSplash\n : DEFAULT_SPLASH\n : [];\n\n let root = process.cwd();\n\n const plugin: Plugin = {\n name: \"tempest-pwa-icons\",\n apply: \"build\",\n configResolved(config) {\n root = config.root ?? process.cwd();\n },\n transformIndexHtml() {\n if (!splashSpecs.length) return;\n return splashSpecs.map((spec) => ({\n tag: \"link\",\n attrs: {\n rel: \"apple-touch-startup-image\",\n media: splashMedia(spec),\n href: `/${splashFileName(spec)}`,\n },\n injectTo: \"head\" as const,\n }));\n },\n async generateBundle() {\n let sharp: SharpFactory;\n try {\n // Non-literal specifier so TS doesn't require `sharp`'s types\n // (it is an optional, lazily-loaded dependency).\n const specifier = \"sharp\";\n const mod = (await import(specifier)) as { default?: SharpFactory } & SharpFactory;\n sharp = (mod.default ?? mod) as SharpFactory;\n } catch {\n this.warn(\n \"tempestPwaIcons: `sharp` is not installed — skipping icon generation. \" +\n \"Run `npm i -D sharp` to enable it.\",\n );\n return;\n }\n\n const input = await readFile(resolve(root, source));\n const bg = hexToRgb(background);\n const emit = (fileName: string, data: Buffer): void => {\n this.emitFile({ type: \"asset\", fileName, source: data });\n };\n\n // Regular \"any\" icons — transparent background, full bleed.\n for (const size of sizes) {\n const png = await sharp(input, { density: Math.max(size, 512) })\n .resize(size, size, {\n fit: \"contain\",\n background: { r: 0, g: 0, b: 0, alpha: 0 },\n })\n .png()\n .toBuffer();\n emit(`${outDir}/icon-${size}.png`, png);\n }\n\n // Maskable icons — content shrunk into the safe zone over a solid bg.\n for (const size of maskableSizes) {\n const content = Math.round(size * (1 - maskablePadding * 2));\n const png = await sharp(input, { density: Math.max(size, 512) })\n .resize(content, content, {\n fit: \"contain\",\n background: { r: 0, g: 0, b: 0, alpha: 0 },\n })\n .extend({\n top: Math.round((size - content) / 2),\n bottom: Math.round((size - content) / 2),\n left: Math.round((size - content) / 2),\n right: Math.round((size - content) / 2),\n background: { ...bg, alpha: 1 },\n })\n .resize(size, size)\n .png()\n .toBuffer();\n emit(`${outDir}/maskable-${size}.png`, png);\n }\n\n // Apple touch icon — opaque, no alpha.\n if (appleTouchIcon) {\n const png = await sharp(input, { density: Math.max(appleTouchIcon, 512) })\n .resize(appleTouchIcon, appleTouchIcon, {\n fit: \"contain\",\n background: { ...bg, alpha: 1 },\n })\n .flatten({ background: bg })\n .png()\n .toBuffer();\n emit(\"apple-touch-icon.png\", png);\n }\n\n // Apple splash screens — icon centered on a solid background.\n if (splashSpecs.length) {\n const splashBg = hexToRgb(splashBackground ?? background);\n for (const spec of splashSpecs) {\n const w = spec.width * spec.ratio;\n const h = spec.height * spec.ratio;\n const iconPx = Math.round(Math.min(w, h) * splashIconScale);\n const icon = await sharp(input, { density: Math.max(iconPx, 512) })\n .resize(iconPx, iconPx, {\n fit: \"contain\",\n background: { r: 0, g: 0, b: 0, alpha: 0 },\n })\n .png()\n .toBuffer();\n const png = await sharp({\n create: {\n width: w,\n height: h,\n channels: 4,\n background: { ...splashBg, alpha: 1 },\n },\n })\n .composite([{ input: icon, gravity: \"center\" }])\n .png()\n .toBuffer();\n emit(splashFileName(spec), png);\n }\n }\n },\n };\n\n return plugin as TempestVitePlugin;\n}\n\n/** Options for the sharp `create` (blank canvas) form. */\ninterface SharpCreate {\n create: {\n width: number;\n height: number;\n channels: number;\n background: { r: number; g: number; b: number; alpha: number };\n };\n}\n\n/** The sharp factory function (minimal typing — sharp is an optional dep). */\ntype SharpFactory = (input: Buffer | SharpCreate, opts?: { density?: number }) => SharpInstance;\n\n/** Minimal subset of the sharp chainable API this plugin uses. */\ninterface SharpInstance {\n resize(\n width: number,\n height: number,\n opts?: { fit?: string; background?: { r: number; g: number; b: number; alpha: number } },\n ): SharpInstance;\n extend(opts: {\n top: number;\n bottom: number;\n left: number;\n right: number;\n background: { r: number; g: number; b: number; alpha: number };\n }): SharpInstance;\n flatten(opts: { background: Rgb }): SharpInstance;\n composite(items: { input: Buffer; gravity?: string }[]): SharpInstance;\n png(): SharpInstance;\n toBuffer(): Promise<Buffer>;\n}\n","import { resolve } from \"node:path\";\nimport type { Plugin } from \"vite\";\nimport type { TempestVitePlugin } from \"./tempest-pwa-manifest\";\n\n/** Options for {@link tempestPwaDevSw}. */\nexport interface TempestPwaDevSwOptions {\n /** Service-worker entry, relative to the project root. Default `src/sw.ts`. */\n swSrc?: string;\n /** URL the worker is served at (must match `registerServiceWorker`). Default `/sw.js`. */\n swUrl?: string;\n /** Dev URL of the precache manifest. Default `/precache-manifest.json`. */\n manifestUrl?: string;\n /** Serve the worker in dev. Default `true`; set `false` to opt out. */\n enabled?: boolean;\n}\n\n/**\n * Dev-server plugin that makes the service worker available under `npm run dev`.\n *\n * The production worker is bundled at build time (`vite.sw.config.ts`), so in\n * dev there is no `/sw.js` to register. This plugin compiles `swSrc` on the fly\n * with esbuild and serves it as a classic worker, plus an empty\n * `precache-manifest.json` (there are no hashed build assets to precache in\n * dev — push and runtime caching still work). It closes the \"SW in dev\" gap\n * that otherwise only `vite-plugin-pwa`'s `devOptions` covered.\n *\n * @example\n * // vite.config.ts\n * import { createViteConfig, tempestPwaDevSw } from \"tempest-react-sdk/vite\";\n *\n * export default createViteConfig({ plugins: [tempestPwaDevSw()] });\n */\nexport function tempestPwaDevSw(options: TempestPwaDevSwOptions = {}): TempestVitePlugin {\n const {\n swSrc = \"src/sw.ts\",\n swUrl = \"/sw.js\",\n manifestUrl = \"/precache-manifest.json\",\n enabled = true,\n } = options;\n\n let root = process.cwd();\n\n const plugin: Plugin = {\n name: \"tempest-pwa-dev-sw\",\n apply: \"serve\",\n configResolved(config) {\n root = config.root ?? process.cwd();\n },\n configureServer(server) {\n if (!enabled) return;\n server.middlewares.use(async (req, res, next) => {\n const url = (req.url ?? \"\").split(\"?\")[0];\n\n if (url === swUrl) {\n try {\n const esbuild = await import(\"esbuild\");\n const result = await esbuild.build({\n entryPoints: [resolve(root, swSrc)],\n bundle: true,\n format: \"iife\",\n platform: \"browser\",\n target: \"es2020\",\n write: false,\n absWorkingDir: root,\n logLevel: \"silent\",\n });\n res.setHeader(\"Content-Type\", \"application/javascript\");\n res.setHeader(\"Service-Worker-Allowed\", \"/\");\n res.setHeader(\"Cache-Control\", \"no-cache\");\n res.end(result.outputFiles[0].text);\n } catch (error) {\n res.statusCode = 500;\n res.end(`// SW dev build failed:\\n// ${String(error)}`);\n }\n return;\n }\n\n if (url === manifestUrl) {\n res.setHeader(\"Content-Type\", \"application/json\");\n res.setHeader(\"Cache-Control\", \"no-cache\");\n res.end(JSON.stringify({ version: \"dev\", urls: [] }));\n return;\n }\n\n next();\n });\n },\n };\n\n return plugin as TempestVitePlugin;\n}\n"],"names":["normalizeProxy","proxy","out","path","value","createViteConfig","options","srcDir","port","host","open","alias","plugins","overrides","overridesConfig","base","react","resolve","merged","defineConfig","joinBase","file","hash","input","h","i","tempestPwaManifest","fileName","additionalUrls","exclude","includeHtml","appShell","config","_outputOptions","bundle","urls","list","version","DEFAULT_SPLASH","splashFileName","spec","splashMedia","hexToRgb","hex","full","c","tempestPwaIcons","source","sizes","maskableSizes","appleTouchIcon","outDir","background","maskablePadding","appleSplash","splashBackground","splashIconScale","splashSpecs","root","sharp","mod","readFile","bg","emit","data","size","png","content","splashBg","w","iconPx","icon","tempestPwaDevSw","swSrc","swUrl","manifestUrl","enabled","server","req","res","next","url","result","error"],"mappings":"0oBAgDA,SAASA,EAAeC,EAAiE,CACrF,MAAMC,EAAoC,CAAA,EAC1C,SAAW,CAACC,EAAMC,CAAK,IAAK,OAAO,QAAQH,CAAK,EAC5CC,EAAIC,CAAI,EACJ,OAAOC,GAAU,SACX,CAAE,OAAQA,EAAO,aAAc,EAAA,EAC9BA,EAEf,OAAOF,CACX,CAkBO,SAASG,EAAiBC,EAAmC,GAAuB,CACvF,KAAM,CACF,OAAAC,EAAS,MACT,KAAAC,EAAO,KACP,KAAAC,EAAO,YACP,KAAAC,EAAO,GACP,MAAAT,EACA,MAAAU,EAAQ,CAAA,EACR,QAAAC,EAAU,CAAA,EACV,UAAAC,EAAY,CAAA,CAAC,EACbP,EAEEQ,EAAkBD,EAElBE,EAAmB,CACrB,QAAS,CAACC,IAAS,GAAGJ,CAAO,EAC7B,QAAS,CACL,MAAO,CACH,IAAKK,EAAAA,QAAQ,QAAQ,IAAA,EAAOV,CAAM,EAClC,GAAGI,CAAA,CACP,EAEJ,OAAQ,CACJ,KAAAH,EACA,KAAAC,EACA,KAAAC,EACA,GAAIT,EAAQ,CAAE,MAAOD,EAAeC,CAAK,CAAA,EAAM,CAAA,CAAC,CACpD,EAGEiB,EAAqB,CACvB,GAAGH,EACH,GAAGD,EACH,QAAS,CAAC,GAAIC,EAAK,SAAW,CAAA,EAAK,GAAID,EAAgB,SAAW,EAAG,EACrE,QAAS,CAAE,GAAGC,EAAK,QAAS,GAAGD,EAAgB,OAAA,EAC/C,OAAQ,CAAE,GAAGC,EAAK,OAAQ,GAAGD,EAAgB,MAAA,CAAO,EAGxD,OAAOK,EAAAA,aAAaD,CAAM,CAC9B,CCpFA,SAASE,EAASL,EAAcM,EAAsB,CAElD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,OAASC,EAAO,CACZJ,EAAI,WAAa,IACjBA,EAAI,IAAI;AAAA,KAA+B,OAAOI,CAAK,CAAC,EAAE,CAC1D,CACA,MACJ,CAEA,GAAIF,IAAQN,EAAa,CACrBI,EAAI,UAAU,eAAgB,kBAAkB,EAChDA,EAAI,UAAU,gBAAiB,UAAU,EACzCA,EAAI,IAAI,KAAK,UAAU,CAAE,QAAS,MAAO,KAAM,CAAA,CAAC,CAAG,CAAC,EACpD,MACJ,CAEAC,EAAA,CACJ,CAAC,CACL,CAAA,CAIR"}
|
package/dist/vite.d.ts
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
/** A single Apple splash target (CSS px + device pixel ratio). */
|
|
2
|
+
export declare interface AppleSplashSpec {
|
|
3
|
+
/** CSS width (device-width in the media query). */
|
|
4
|
+
width: number;
|
|
5
|
+
/** CSS height (device-height in the media query). */
|
|
6
|
+
height: number;
|
|
7
|
+
/** Device pixel ratio. */
|
|
8
|
+
ratio: number;
|
|
9
|
+
}
|
|
10
|
+
|
|
1
11
|
/**
|
|
2
12
|
* Build a Tempest-flavored Vite config for a React app: the `@vitejs/plugin-react`
|
|
3
13
|
* plugin, the `@` → `src` import alias, and sane dev-server defaults — so a
|
|
@@ -52,6 +62,123 @@ export declare interface CreateViteConfigOptions {
|
|
|
52
62
|
*/
|
|
53
63
|
export declare type ProxyEntry = string | Record<string, unknown>;
|
|
54
64
|
|
|
65
|
+
/**
|
|
66
|
+
* Dev-server plugin that makes the service worker available under `npm run dev`.
|
|
67
|
+
*
|
|
68
|
+
* The production worker is bundled at build time (`vite.sw.config.ts`), so in
|
|
69
|
+
* dev there is no `/sw.js` to register. This plugin compiles `swSrc` on the fly
|
|
70
|
+
* with esbuild and serves it as a classic worker, plus an empty
|
|
71
|
+
* `precache-manifest.json` (there are no hashed build assets to precache in
|
|
72
|
+
* dev — push and runtime caching still work). It closes the "SW in dev" gap
|
|
73
|
+
* that otherwise only `vite-plugin-pwa`'s `devOptions` covered.
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* // vite.config.ts
|
|
77
|
+
* import { createViteConfig, tempestPwaDevSw } from "tempest-react-sdk/vite";
|
|
78
|
+
*
|
|
79
|
+
* export default createViteConfig({ plugins: [tempestPwaDevSw()] });
|
|
80
|
+
*/
|
|
81
|
+
export declare function tempestPwaDevSw(options?: TempestPwaDevSwOptions): TempestVitePlugin;
|
|
82
|
+
|
|
83
|
+
/** Options for {@link tempestPwaDevSw}. */
|
|
84
|
+
export declare interface TempestPwaDevSwOptions {
|
|
85
|
+
/** Service-worker entry, relative to the project root. Default `src/sw.ts`. */
|
|
86
|
+
swSrc?: string;
|
|
87
|
+
/** URL the worker is served at (must match `registerServiceWorker`). Default `/sw.js`. */
|
|
88
|
+
swUrl?: string;
|
|
89
|
+
/** Dev URL of the precache manifest. Default `/precache-manifest.json`. */
|
|
90
|
+
manifestUrl?: string;
|
|
91
|
+
/** Serve the worker in dev. Default `true`; set `false` to opt out. */
|
|
92
|
+
enabled?: boolean;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Build plugin that rasterizes a single source image into a full PWA icon set
|
|
97
|
+
* (regular + maskable + apple-touch-icon), the dependency-free counterpart to
|
|
98
|
+
* `@vite-pwa/assets-generator`. Rendering uses **`sharp`**, imported lazily and
|
|
99
|
+
* treated as optional: if it isn't installed the plugin logs a warning and skips
|
|
100
|
+
* generation (your build still succeeds; the icons just aren't produced).
|
|
101
|
+
*
|
|
102
|
+
* Point your `manifest.webmanifest` icon entries at the emitted files
|
|
103
|
+
* (`/icons/icon-192.png`, `/icons/icon-512.png`, `/icons/maskable-512.png`) and
|
|
104
|
+
* the apple touch icon at `/apple-touch-icon.png`.
|
|
105
|
+
*
|
|
106
|
+
* @example
|
|
107
|
+
* // vite.config.ts
|
|
108
|
+
* import { createViteConfig, tempestPwaIcons } from "tempest-react-sdk/vite";
|
|
109
|
+
*
|
|
110
|
+
* export default createViteConfig({
|
|
111
|
+
* plugins: [tempestPwaIcons({ source: "public/icon.svg" })],
|
|
112
|
+
* });
|
|
113
|
+
*/
|
|
114
|
+
export declare function tempestPwaIcons(options?: TempestPwaIconsOptions): TempestVitePlugin;
|
|
115
|
+
|
|
116
|
+
/** Options for {@link tempestPwaIcons}. */
|
|
117
|
+
export declare interface TempestPwaIconsOptions {
|
|
118
|
+
/** Source image (SVG or large PNG), relative to the project root. Default `public/icon.svg`. */
|
|
119
|
+
source?: string;
|
|
120
|
+
/** Square "any"-purpose icon sizes to emit. Default `[192, 512]`. */
|
|
121
|
+
sizes?: number[];
|
|
122
|
+
/** Square "maskable" icon sizes to emit (with safe-zone padding). Default `[512]`. */
|
|
123
|
+
maskableSizes?: number[];
|
|
124
|
+
/** Apple touch icon size, or `false` to skip. Default `180`. */
|
|
125
|
+
appleTouchIcon?: number | false;
|
|
126
|
+
/** Output directory for the icon set, under the build root. Default `icons`. */
|
|
127
|
+
outDir?: string;
|
|
128
|
+
/** Opaque background for maskable + apple icons (no transparency allowed). Default `#ffffff`. */
|
|
129
|
+
background?: string;
|
|
130
|
+
/** Maskable safe-zone padding as a fraction of the icon. Default `0.1` (10% each side). */
|
|
131
|
+
maskablePadding?: number;
|
|
132
|
+
/**
|
|
133
|
+
* Generate Apple splash screens (launch images) and inject the matching
|
|
134
|
+
* `<link rel="apple-touch-startup-image">` tags. `true` uses a built-in set
|
|
135
|
+
* of common iPhone/iPad portrait sizes; pass an array to override. Default `false`.
|
|
136
|
+
*/
|
|
137
|
+
appleSplash?: boolean | AppleSplashSpec[];
|
|
138
|
+
/** Background color for splash screens. Default: `background`. */
|
|
139
|
+
splashBackground?: string;
|
|
140
|
+
/** Icon size on the splash as a fraction of the shorter side. Default `0.3`. */
|
|
141
|
+
splashIconScale?: number;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Vite build plugin that emits a `precache-manifest.json` listing every built
|
|
146
|
+
* asset (plus any `additionalUrls`) as root-absolute URLs, with a content-based
|
|
147
|
+
* `version`. It is the dependency-free counterpart to Workbox's `__WB_MANIFEST`:
|
|
148
|
+
* `installPrecache` (from `tempest-react-sdk/sw`) reads this file at the service
|
|
149
|
+
* worker's `install` event to cache the app shell for offline use.
|
|
150
|
+
*
|
|
151
|
+
* @example
|
|
152
|
+
* // vite.config.ts
|
|
153
|
+
* import { createViteConfig, tempestPwaManifest } from "tempest-react-sdk/vite";
|
|
154
|
+
*
|
|
155
|
+
* export default createViteConfig({
|
|
156
|
+
* plugins: [tempestPwaManifest({ additionalUrls: ["/manifest.webmanifest", "/icon.svg"] })],
|
|
157
|
+
* });
|
|
158
|
+
*/
|
|
159
|
+
export declare function tempestPwaManifest(options?: TempestPwaManifestOptions): TempestVitePlugin;
|
|
160
|
+
|
|
161
|
+
/** Options for {@link tempestPwaManifest}. */
|
|
162
|
+
export declare interface TempestPwaManifestOptions {
|
|
163
|
+
/** Output file name (under the build root). Default `precache-manifest.json`. */
|
|
164
|
+
fileName?: string;
|
|
165
|
+
/**
|
|
166
|
+
* Extra URLs to precache that Vite doesn't emit into the bundle — typically
|
|
167
|
+
* `public/` assets like the web manifest and icons. Default `[]`.
|
|
168
|
+
*/
|
|
169
|
+
additionalUrls?: string[];
|
|
170
|
+
/** Emitted files matching this are skipped. Default `/\.map$/` (source maps). */
|
|
171
|
+
exclude?: RegExp;
|
|
172
|
+
/** Include emitted `.html` documents (the app shell). Default `true`. */
|
|
173
|
+
includeHtml?: boolean;
|
|
174
|
+
/**
|
|
175
|
+
* App-shell document always added to the manifest, even if Vite emits it
|
|
176
|
+
* after this plugin runs. Must match `installPrecache`'s `navigateFallback`
|
|
177
|
+
* so offline navigations resolve. Pass `false` to disable. Default `/index.html`.
|
|
178
|
+
*/
|
|
179
|
+
appShell?: string | false;
|
|
180
|
+
}
|
|
181
|
+
|
|
55
182
|
/**
|
|
56
183
|
* The resulting Vite config object. Typed loosely so the SDK's published
|
|
57
184
|
* declarations stay free of `vite`'s internal types; assign it straight to a
|
|
@@ -59,4 +186,13 @@ export declare type ProxyEntry = string | Record<string, unknown>;
|
|
|
59
186
|
*/
|
|
60
187
|
export declare type TempestViteConfig = Record<string, unknown>;
|
|
61
188
|
|
|
189
|
+
/**
|
|
190
|
+
* A Vite plugin object. Typed loosely so the SDK's published declarations stay
|
|
191
|
+
* free of `vite`'s internal types (which the `.d.ts` rollup can't analyze);
|
|
192
|
+
* assign the result straight into a `plugins: [...]` array.
|
|
193
|
+
*/
|
|
194
|
+
export declare type TempestVitePlugin = {
|
|
195
|
+
name: string;
|
|
196
|
+
} & Record<string, unknown>;
|
|
197
|
+
|
|
62
198
|
export { }
|