@flairstudio/kit 0.2.0-beta.0 → 0.2.0-beta.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 +11 -0
- package/README.md +27 -21
- package/TOKENS.md +1 -1
- package/dist/fonts.css +1 -1
- package/dist/preview-host.d.ts +2 -2
- package/dist/preview-host.js +3 -3
- package/dist/preview.d.ts +5 -5
- package/dist/preview.js +20 -11
- package/dist/tokens.css +1 -1
- package/dist/tokens.json +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,17 @@
|
|
|
2
2
|
|
|
3
3
|
Renaming or removing a token is a breaking change. Adding a token, or changing a value, is a minor release. Before 1.0, a breaking change bumps the minor version.
|
|
4
4
|
|
|
5
|
+
## 0.2.0-beta.1
|
|
6
|
+
|
|
7
|
+
A beta, published under npm's `next` tag. `latest` stays at 0.1.0 until 0.2.0.
|
|
8
|
+
|
|
9
|
+
- **Added:** FlairDesigner's local addresses, `http://localhost:3300` (its dev server) and `http://localhost:4330` (its tests), to `DEFAULT_ALLOW`. A page that FlairDesigner frames now needs no `allow` list of its own. Flair Design's two addresses stay.
|
|
10
|
+
- **Changed:** a message from the host that isn't flair-kit's, one whose `type` doesn't start with `flair-kit:`, such as a browser extension's, is now ignored without a word. In beta.0 it got a console warning and a `refused` answer with the reason `type`, so the host showed a refusal while the theme was on. An unknown `flair-kit:` type is still refused.
|
|
11
|
+
- **Changed:** in Chrome and Safari, which name the parent's origin, the listener now sends `ready` only to that origin, or to none if it isn't allowed. A framed page no longer logs a console warning for each other allowed address. Where the browser doesn't name the parent, as in Firefox, or names it `"null"`, `ready` still goes to each allowed address.
|
|
12
|
+
- **Docs:** "Showing a site in Flair" in the README names FlairDesigner as the app that frames the page, and calls it the host.
|
|
13
|
+
- Two of its subheadings are renamed: "Which Flair may theme the page" is now "Which hosts may theme the page", and "Flair's side: `preview-host.js`" is now "The host's side: `preview-host.js`".
|
|
14
|
+
- The Playwright recipe's host address is now `HOST`, on `http://localhost:4330`, instead of `FLAIR`, on `http://localhost:4317`. Both are allowed, so a test copied from beta.0's recipe still runs.
|
|
15
|
+
|
|
5
16
|
## 0.2.0-beta.0
|
|
6
17
|
|
|
7
18
|
A beta, published under npm's `next` tag. `latest` stays at 0.1.0 until 0.2.0.
|
package/README.md
CHANGED
|
@@ -9,7 +9,7 @@ Every token is listed in `TOKENS.md`, which ships in the package.
|
|
|
9
9
|
## Use it in a site with a build
|
|
10
10
|
|
|
11
11
|
```sh
|
|
12
|
-
npm install @flairstudio/kit@0.2.0-beta.
|
|
12
|
+
npm install @flairstudio/kit@0.2.0-beta.1 --save-exact
|
|
13
13
|
```
|
|
14
14
|
|
|
15
15
|
Import in this order:
|
|
@@ -41,7 +41,7 @@ Line 1 of each generated file names its version, `/* flair-kit <version> · …
|
|
|
41
41
|
|
|
42
42
|
The package's colours are a default. A site's palette file replaces them, and it must:
|
|
43
43
|
|
|
44
|
-
- **open with the layer order line, then put everything inside `@layer flair-kit.palette { … }`.** The line fixes the order of the layers whichever CSS file the browser reads first, so the palette beats the package's defaults even if it loads before `tokens.css`. The layer lets
|
|
44
|
+
- **open with the layer order line, then put everything inside `@layer flair-kit.palette { … }`.** The line fixes the order of the layers whichever CSS file the browser reads first, so the palette beats the package's defaults even if it loads before `tokens.css`. The layer lets the preview beat the palette while a host shows the page (see "Showing a site in Flair").
|
|
45
45
|
- **use the same three selectors as `tokens.css`, in this order.** The dark block must come after the light one, or `data-theme="dark"` on `<html>` stops working:
|
|
46
46
|
|
|
47
47
|
```css
|
|
@@ -60,9 +60,9 @@ The package's colours are a default. A site's palette file replaces them, and it
|
|
|
60
60
|
```
|
|
61
61
|
|
|
62
62
|
- **set every colour in both modes.** A colour the file leaves out falls back to the package's default. `tokens.json` lists them all under `colors.names`, so a site test can check its palette covers them.
|
|
63
|
-
- **set colours only on `:root` and on elements with `data-theme`.** A palette may use stronger selectors, such as `#page[data-palette][data-theme]`, as long as the element carries `data-theme`. A colour set on any other element, such as `body` or `.page`, isn't reached by
|
|
63
|
+
- **set colours only on `:root` and on elements with `data-theme`.** A palette may use stronger selectors, such as `#page[data-palette][data-theme]`, as long as the element carries `data-theme`. A colour set on any other element, such as `body` or `.page`, isn't reached by the preview: the element keeps the palette's value instead of inheriting the preview's.
|
|
64
64
|
|
|
65
|
-
A palette left outside the layer still works on the site, but in
|
|
65
|
+
A palette left outside the layer still works on the site, but in the host's frame it beats the preview, so the page doesn't change as the theme is edited.
|
|
66
66
|
|
|
67
67
|
Override a colour with those same three selectors. A colour set only on `:root` behaves differently:
|
|
68
68
|
- it applies to the page in every mode, so a value chosen for light mode also shows in dark mode;
|
|
@@ -71,7 +71,7 @@ Override a colour with those same three selectors. A colour set only on `:root`
|
|
|
71
71
|
|
|
72
72
|
Check colour values carefully. The colours are registered as `<color>`, so a misspelt value (`#1f2a3`, `banana`) doesn't fail loudly. The element quietly takes its parent's colour instead, which inside a `data-theme` region can mean a light colour in a dark region.
|
|
73
73
|
|
|
74
|
-
Every token declaration in the package sits in the `flair-kit.tokens` cascade layer. The `@property` registrations in `tokens.css` and the `@font-face` rules in `fonts.css` sit outside it by design, because neither needs overriding. A site's own CSS outside a layer always wins, whatever its selectors, so no override needs `!important`, and overrides stay outside a layer. From lowest to highest, the order is the package's defaults, the site's palette, components,
|
|
74
|
+
Every token declaration in the package sits in the `flair-kit.tokens` cascade layer. The `@property` registrations in `tokens.css` and the `@font-face` rules in `fonts.css` sit outside it by design, because neither needs overriding. A site's own CSS outside a layer always wins, whatever its selectors, so no override needs `!important`, and overrides stay outside a layer. From lowest to highest, the order is the package's defaults, the site's palette, components, the preview, then the site's unlayered CSS:
|
|
75
75
|
|
|
76
76
|
```css
|
|
77
77
|
@layer flair-kit.tokens, flair-kit.palette, flair-kit.components, flair-kit.preview;
|
|
@@ -89,7 +89,7 @@ The package adds no transitions. `--dur-theme` is there for a site that fades be
|
|
|
89
89
|
|
|
90
90
|
## Showing a site in Flair
|
|
91
91
|
|
|
92
|
-
|
|
92
|
+
FlairDesigner can show a site's real page in a frame, wearing the theme being edited, and follow every change live. This section calls it the host: any app that frames the page and sends it themes with `preview-host.js`. The page needs the listener, `preview.js`, from this package. It loads only inside a frame, so visitors never download it.
|
|
93
93
|
|
|
94
94
|
### Load the listener
|
|
95
95
|
|
|
@@ -111,30 +111,36 @@ A site without a build, with `dist/` copied to `assets/flair-kit/`, after its st
|
|
|
111
111
|
|
|
112
112
|
Outside a frame, `listen()` does nothing. Calling it again while it runs changes nothing, and it returns a function that stops it.
|
|
113
113
|
|
|
114
|
-
### Which
|
|
114
|
+
### Which hosts may theme the page
|
|
115
115
|
|
|
116
|
-
`listen()` takes themes only from
|
|
116
|
+
`listen()` takes themes only from the hosts' own local addresses, which it exports as `DEFAULT_ALLOW`:
|
|
117
|
+
- `http://localhost:3000` and `http://localhost:4317`: Flair Design's dev server and its tests;
|
|
118
|
+
- `http://localhost:3300` and `http://localhost:4330`: the same for FlairDesigner.
|
|
119
|
+
|
|
120
|
+
Pass `allow` to replace the list, or spread the default to add to it:
|
|
117
121
|
|
|
118
122
|
```js
|
|
119
123
|
import('@flairstudio/kit/preview.js').then(({ listen, DEFAULT_ALLOW }) =>
|
|
120
124
|
listen({ allow: [...DEFAULT_ALLOW, 'https://flair.example'] }));
|
|
121
125
|
```
|
|
122
126
|
|
|
123
|
-
Addresses must match exactly: `http://127.0.0.1:
|
|
127
|
+
Addresses must match exactly: `http://127.0.0.1:3300` isn't `http://localhost:3300`. A message from any other address, or from a window that isn't the page's parent, is ignored without a word. So is a message from the host that isn't flair-kit's, one whose `type` doesn't start with `flair-kit:`, such as a browser extension's. Only colour names the package knows and `#rrggbb` values get through, so a message can't add any other CSS.
|
|
128
|
+
|
|
129
|
+
When it starts, the listener tells the page's parent it's ready. Chrome and Safari name the parent's origin (`location.ancestorOrigins`), so there it sends to that origin alone, or to none if the origin isn't allowed. Where the browser doesn't name the parent, as in Firefox, or names it `"null"`, the listener sends to each allowed address, and the browser drops the ones that don't match. A browser may log a console warning for each one it drops.
|
|
124
130
|
|
|
125
131
|
### What the listener changes
|
|
126
132
|
|
|
127
|
-
Only these, and only once
|
|
133
|
+
Only these, and only once the host has sent a theme:
|
|
128
134
|
- its own `<style>`, in the `flair-kit.preview` layer, which beats the site's palette but not its unlayered overrides;
|
|
129
|
-
- `data-theme` on `<html>`, set to the mode chosen in
|
|
135
|
+
- `data-theme` on `<html>`, set to the mode chosen in the host;
|
|
130
136
|
- `data-flair-preview` on `<html>`, set with the first theme;
|
|
131
137
|
- an inline `--dur-theme` on `<html>`: `0.01ms` for the first theme and while a colour is being dragged, so nothing fades.
|
|
132
138
|
|
|
133
|
-
The preview beats the palette only when the palette sits in its layer (see "A site's palette and overrides"). If a router or hydration rebuilds `<head>`, the listener puts its `<style>` back with the next theme. A Content Security Policy whose `style-src` doesn't allow inline styles blocks that `<style>`, so the page keeps its own colours in
|
|
139
|
+
The preview beats the palette only when the palette sits in its layer (see "A site's palette and overrides"). If a router or hydration rebuilds `<head>`, the listener puts its `<style>` back with the next theme. A Content Security Policy whose `style-src` doesn't allow inline styles blocks that `<style>`, so the page keeps its own colours in the host's frame. Allow inline styles on the pages a host frames.
|
|
134
140
|
|
|
135
141
|
### Review tools step aside
|
|
136
142
|
|
|
137
|
-
A site's own review tools, such as a theme switcher, notes or a palette menu, would fight
|
|
143
|
+
A site's own review tools, such as a theme switcher, notes or a palette menu, would fight the host's. Hide them under the attribute:
|
|
138
144
|
|
|
139
145
|
```css
|
|
140
146
|
[data-flair-preview] .review-tools { display: none; }
|
|
@@ -148,16 +154,16 @@ document.addEventListener('flair-kit:preview', (event) => {
|
|
|
148
154
|
});
|
|
149
155
|
```
|
|
150
156
|
|
|
151
|
-
|
|
157
|
+
The host shows the page once the listeners have run and two frames have been drawn, so a change made in the handler is in place by then.
|
|
152
158
|
|
|
153
159
|
### Two rules
|
|
154
160
|
|
|
155
|
-
- **
|
|
161
|
+
- **The host sets the mode on `<html>`, and an element with its own `data-theme` keeps it.** So a page root that sets its own `data-theme`, such as `#page`, copies `event.detail.mode` into it on every event. Regions that always stay one mode keep theirs.
|
|
156
162
|
- **Set `--dur-theme` on `:root` only.** The listener's inline value on `<html>` beats it there. A value set on another element would bring the fade back during a drag.
|
|
157
163
|
|
|
158
|
-
###
|
|
164
|
+
### The host's side: `preview-host.js`
|
|
159
165
|
|
|
160
|
-
|
|
166
|
+
The host sends themes with `preview-host.js`, and a site's tests can too:
|
|
161
167
|
|
|
162
168
|
```js
|
|
163
169
|
import { connect } from '@flairstudio/kit/preview-host.js';
|
|
@@ -176,14 +182,14 @@ send({ light, dark, mode: 'light', angle: 110, instant: false });
|
|
|
176
182
|
|
|
177
183
|
### Testing a site's pages with a Flair theme
|
|
178
184
|
|
|
179
|
-
A site's Playwright tests can put a theme on its pages without
|
|
185
|
+
A site's Playwright tests can put a theme on its pages without the host running. The test answers an allowed address itself with `page.route`, serving a small host page and the two scripts. The site's own server serves the page under test.
|
|
180
186
|
|
|
181
187
|
```js
|
|
182
188
|
import { test, expect } from '@playwright/test';
|
|
183
189
|
import { createRequire } from 'node:module';
|
|
184
190
|
import { dirname, join } from 'node:path';
|
|
185
191
|
|
|
186
|
-
const
|
|
192
|
+
const HOST = 'http://localhost:4330'; // an allowed address; nothing needs to run there
|
|
187
193
|
const SITE = 'http://localhost:5173/'; // the page under test
|
|
188
194
|
const require = createRequire(import.meta.url);
|
|
189
195
|
const dist = dirname(require.resolve('@flairstudio/kit/preview-host.js'));
|
|
@@ -204,12 +210,12 @@ const HOST_PAGE = `<!doctype html>
|
|
|
204
210
|
</script>`;
|
|
205
211
|
|
|
206
212
|
test('the home page wears a Flair theme', async ({ page }) => {
|
|
207
|
-
await page.route(`${
|
|
213
|
+
await page.route(`${HOST}/**`, (route) => {
|
|
208
214
|
const { pathname } = new URL(route.request().url());
|
|
209
215
|
if (pathname === '/') return route.fulfill({ contentType: 'text/html', body: HOST_PAGE });
|
|
210
216
|
return route.fulfill({ path: join(dist, pathname.slice(1)) }); // preview-host.js, and the preview.js it imports
|
|
211
217
|
});
|
|
212
|
-
await page.goto(`${
|
|
218
|
+
await page.goto(`${HOST}/`);
|
|
213
219
|
await page.evaluate((theme) => window.flairKit.host.send(theme), { light, dark, mode: 'dark', angle: 110 });
|
|
214
220
|
await expect.poll(() => page.evaluate(() => window.flairKit.applied)).toBeGreaterThan(0);
|
|
215
221
|
const site = page.frameLocator('iframe');
|
package/TOKENS.md
CHANGED
package/dist/fonts.css
CHANGED
package/dist/preview-host.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
/* flair-kit 0.2.0-beta.
|
|
1
|
+
/* flair-kit 0.2.0-beta.1 · generated from src/tokens.ts · do not edit */
|
|
2
2
|
|
|
3
3
|
import type { Colors, Mode } from './preview.js';
|
|
4
4
|
|
|
5
5
|
export { COLOR_NAMES, FORMAT_VERSION, KIT_VERSION } from './preview.js';
|
|
6
6
|
export type { ColorName, Colors, Mode, Reason } from './preview.js';
|
|
7
7
|
|
|
8
|
-
/** A theme as
|
|
8
|
+
/** A theme as the host sends it: both modes' colours, the canvas mode, the gradient angle, and whether a drag is under way */
|
|
9
9
|
export interface Theme {
|
|
10
10
|
readonly light: Colors;
|
|
11
11
|
readonly dark: Colors;
|
package/dist/preview-host.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
/* flair-kit 0.2.0-beta.
|
|
1
|
+
/* flair-kit 0.2.0-beta.1 · generated from src/preview-host.js · do not edit */
|
|
2
2
|
|
|
3
|
-
//
|
|
4
|
-
// it too, to put a Flair theme on their pages without
|
|
3
|
+
// The host's side of the preview: frames a site's page and sends it the theme being edited. A site's own tests use
|
|
4
|
+
// it too, to put a Flair theme on their pages without the host running. The names and the checks come from
|
|
5
5
|
// ./preview.js, so both sides of the format are written once.
|
|
6
6
|
import { COLOR_NAMES, FORMAT_VERSION, KIT_VERSION, MESSAGE_TYPES, checkTheme } from './preview.js';
|
|
7
7
|
|
package/dist/preview.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* flair-kit 0.2.0-beta.
|
|
1
|
+
/* flair-kit 0.2.0-beta.1 · generated from src/tokens.ts · do not edit */
|
|
2
2
|
|
|
3
3
|
/** The package version this listener came from */
|
|
4
4
|
export declare const KIT_VERSION: string;
|
|
@@ -10,8 +10,8 @@ export declare const COLOR_NAMES: readonly ["background","card","muted","seconda
|
|
|
10
10
|
export type ColorName = (typeof COLOR_NAMES)[number];
|
|
11
11
|
/** A colour mode */
|
|
12
12
|
export type Mode = 'light' | 'dark';
|
|
13
|
-
/** The
|
|
14
|
-
export declare const DEFAULT_ALLOW: readonly ["http://localhost:3000","http://localhost:4317"];
|
|
13
|
+
/** The host addresses listen() allows when it's given no list: Flair Design's dev server and tests, then FlairDesigner's */
|
|
14
|
+
export declare const DEFAULT_ALLOW: readonly ["http://localhost:3000","http://localhost:4317","http://localhost:3300","http://localhost:4330"];
|
|
15
15
|
/** The type of each message in the format */
|
|
16
16
|
export declare const MESSAGE_TYPES: { readonly ready: "flair-kit:ready"; readonly hello: "flair-kit:hello"; readonly theme: "flair-kit:theme"; readonly applied: "flair-kit:applied"; readonly refused: "flair-kit:refused"; };
|
|
17
17
|
/** Why a theme was refused. A refusal never echoes the values it was sent */
|
|
@@ -22,10 +22,10 @@ export type Colors = { readonly [N in ColorName]?: string };
|
|
|
22
22
|
export interface PreviewEventDetail { readonly mode: Mode; readonly first: boolean }
|
|
23
23
|
/** Options for listen() */
|
|
24
24
|
export interface ListenOptions {
|
|
25
|
-
/** The
|
|
25
|
+
/** The host addresses that may theme the page, as origins or page addresses. It replaces DEFAULT_ALLOW */
|
|
26
26
|
readonly allow?: readonly string[];
|
|
27
27
|
}
|
|
28
|
-
/** Starts listening for
|
|
28
|
+
/** Starts listening for the host if the page is in a frame, and returns a function that stops it. A second call while it runs returns the same function */
|
|
29
29
|
export declare function listen(options?: ListenOptions): () => void;
|
|
30
30
|
/** Checks a theme's mode, angle and colours against `names`: the first reason it fails, or null. Never throws */
|
|
31
31
|
export declare function checkTheme(theme: unknown, names: readonly string[]): Reason | null;
|
package/dist/preview.js
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
|
-
/* flair-kit 0.2.0-beta.
|
|
1
|
+
/* flair-kit 0.2.0-beta.1 · generated from src/preview.js and src/tokens.ts · do not edit */
|
|
2
2
|
|
|
3
3
|
// Written by the build from src/tokens.ts and src/preview-format.ts
|
|
4
|
-
export const KIT_VERSION = "0.2.0-beta.
|
|
4
|
+
export const KIT_VERSION = "0.2.0-beta.1";
|
|
5
5
|
export const FORMAT_VERSION = 1;
|
|
6
6
|
export const COLOR_NAMES = Object.freeze(["background","card","muted","secondary","foreground","card-foreground","muted-foreground","on-secondary","border","outline","primary","on-primary","primary-hover","primary-pressed","primary-text","ring","tertiary","on-tertiary","accent-2","glow","destructive","on-destructive","chart-1","chart-2","chart-3","chart-4","brand","gradient-1","gradient-2","gradient-3"]);
|
|
7
|
-
export const DEFAULT_ALLOW = Object.freeze(["http://localhost:3000","http://localhost:4317"]);
|
|
7
|
+
export const DEFAULT_ALLOW = Object.freeze(["http://localhost:3000","http://localhost:4317","http://localhost:3300","http://localhost:4330"]);
|
|
8
8
|
export const MESSAGE_TYPES = Object.freeze({"ready":"flair-kit:ready","hello":"flair-kit:hello","theme":"flair-kit:theme","applied":"flair-kit:applied","refused":"flair-kit:refused"});
|
|
9
|
+
const MESSAGE_PREFIX = "flair-kit:";
|
|
9
10
|
const LAYER_ORDER = "@layer flair-kit.tokens, flair-kit.palette, flair-kit.components, flair-kit.preview;";
|
|
10
11
|
const PREVIEW_LAYER = "flair-kit.preview";
|
|
11
12
|
|
|
12
|
-
// The listener that lets
|
|
13
|
-
// KIT_VERSION, FORMAT_VERSION, COLOR_NAMES, DEFAULT_ALLOW, MESSAGE_TYPES, LAYER_ORDER and PREVIEW_LAYER are
|
|
13
|
+
// The listener that lets a host, such as FlairDesigner, show this page in its frame, wearing the theme being edited.
|
|
14
|
+
// KIT_VERSION, FORMAT_VERSION, COLOR_NAMES, DEFAULT_ALLOW, MESSAGE_TYPES, MESSAGE_PREFIX, LAYER_ORDER and PREVIEW_LAYER are
|
|
14
15
|
// written above this file by the build (scripts/lib/preview.ts). Nothing here runs until listen() is called.
|
|
15
16
|
|
|
16
17
|
const HEX = /^#[0-9a-f]{6}$/i;
|
|
@@ -89,9 +90,11 @@ export function checkTheme(theme, names) {
|
|
|
89
90
|
return null;
|
|
90
91
|
}
|
|
91
92
|
|
|
92
|
-
/**
|
|
93
|
+
/** True for an object whose type starts flair-kit:. Anything else, such as an extension's chatter, isn't ours to answer */
|
|
94
|
+
const isOurs = (data) => data !== null && typeof data === 'object' && typeof data.type === 'string' && data.type.startsWith(MESSAGE_PREFIX);
|
|
95
|
+
|
|
96
|
+
/** Why a flair-kit message from the allowed parent can't be used, or null */
|
|
93
97
|
function messageReason(data) {
|
|
94
|
-
if (data === null || typeof data !== 'object') return 'type';
|
|
95
98
|
if (data.type !== MESSAGE_TYPES.theme && data.type !== MESSAGE_TYPES.hello) return 'type';
|
|
96
99
|
if (data.v !== FORMAT_VERSION) return 'version';
|
|
97
100
|
return data.type === MESSAGE_TYPES.theme ? checkTheme(data, COLOR_NAMES) : null;
|
|
@@ -100,8 +103,8 @@ function messageReason(data) {
|
|
|
100
103
|
const readyMessage = () => ({ type: MESSAGE_TYPES.ready, v: FORMAT_VERSION, kit: KIT_VERSION, names: [...COLOR_NAMES] });
|
|
101
104
|
|
|
102
105
|
/**
|
|
103
|
-
* Starts listening for
|
|
104
|
-
* `allow` lists the
|
|
106
|
+
* Starts listening for the host, if this page is inside a frame. Returns a function that stops it.
|
|
107
|
+
* `allow` lists the host addresses that may theme the page; without it, DEFAULT_ALLOW, the hosts' own local addresses.
|
|
105
108
|
* Calling it again while it runs returns the same stop function and changes nothing.
|
|
106
109
|
*/
|
|
107
110
|
export function listen(options = {}) {
|
|
@@ -112,6 +115,11 @@ export function listen(options = {}) {
|
|
|
112
115
|
|
|
113
116
|
const allow = [...(options.allow ?? DEFAULT_ALLOW)].map(toOrigin);
|
|
114
117
|
const post = (message, origin) => win.parent.postMessage(message, origin);
|
|
118
|
+
// Chrome and Safari name the parent's origin, so ready goes there alone, or nowhere if it isn't allowed, and no
|
|
119
|
+
// post fails with a console warning. Elsewhere, or when it's hidden as "null", ready goes to each allowed origin.
|
|
120
|
+
const parentOrigin = win.location?.ancestorOrigins?.[0];
|
|
121
|
+
const named = typeof parentOrigin === 'string' && parentOrigin !== 'null';
|
|
122
|
+
const readyTo = named ? allow.filter((origin) => origin === parentOrigin).slice(0, 1) : allow;
|
|
115
123
|
|
|
116
124
|
let first = true;
|
|
117
125
|
/** True once the first theme has been drawn and its applied has gone. Until then every theme keeps the hold */
|
|
@@ -181,9 +189,10 @@ export function listen(options = {}) {
|
|
|
181
189
|
if (!allow.includes(event.origin)) return;
|
|
182
190
|
if (event.source !== win.parent) return;
|
|
183
191
|
const { data } = event;
|
|
192
|
+
if (!isOurs(data)) return;
|
|
184
193
|
const reason = messageReason(data);
|
|
185
194
|
if (reason) {
|
|
186
|
-
console.warn(`flair-kit: a preview message from
|
|
195
|
+
console.warn(`flair-kit: a preview message from the host was refused (${reason})`);
|
|
187
196
|
post({ type: MESSAGE_TYPES.refused, v: FORMAT_VERSION, reason }, event.origin);
|
|
188
197
|
return;
|
|
189
198
|
}
|
|
@@ -206,6 +215,6 @@ export function listen(options = {}) {
|
|
|
206
215
|
|
|
207
216
|
running.set(win, { stop });
|
|
208
217
|
win.addEventListener('message', onMessage);
|
|
209
|
-
for (const origin of
|
|
218
|
+
for (const origin of readyTo) post(readyMessage(), origin);
|
|
210
219
|
return stop;
|
|
211
220
|
}
|
package/dist/tokens.css
CHANGED
package/dist/tokens.json
CHANGED
package/package.json
CHANGED