@reuters-graphics/graphics-components 3.0.6 → 3.0.9
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/dist/components/Analytics/Analytics.svelte +1 -4
- package/dist/components/Analytics/providers/index.d.ts +0 -1
- package/dist/components/Analytics/providers/index.js +0 -1
- package/dist/components/Theme/@types/component.d.ts +2 -2
- package/dist/components/Theme/Theme.svelte +2 -2
- package/dist/components/Theme/Theme.svelte.d.ts +4 -4
- package/dist/components/Theme/themes/common.js +1 -1
- package/dist/components/Theme/themes/dark.js +1 -1
- package/dist/components/Theme/themes/light.js +1 -1
- package/dist/components/Theme/utils/merge.d.ts +2 -2
- package/dist/components/Visible/Visible.mdx +2 -1
- package/dist/components/Visible/Visible.stories.svelte +3 -10
- package/dist/components/Visible/Visible.svelte +20 -30
- package/dist/components/Visible/Visible.svelte.d.ts +8 -8
- package/dist/components/Visible/demo/VisibleDemo.svelte +46 -0
- package/dist/components/Visible/demo/VisibleDemo.svelte.d.ts +3 -0
- package/dist/globals.d.ts +0 -8
- package/package.json +1 -1
- package/dist/components/Analytics/providers/parsely.d.ts +0 -3
- package/dist/components/Analytics/providers/parsely.js +0 -29
|
@@ -3,13 +3,11 @@
|
|
|
3
3
|
<script module>
|
|
4
4
|
import { registerPageview as registerChartbeatPageview } from './providers/chartbeat';
|
|
5
5
|
import { registerPageview as registerGAPageview } from './providers/ga';
|
|
6
|
-
import { registerPageview as registerParselyPageview } from './providers/parsely';
|
|
7
6
|
|
|
8
7
|
/** Register virtual pageviews when using client-side routing in multipage applications. */
|
|
9
8
|
function registerPageview() {
|
|
10
9
|
registerChartbeatPageview();
|
|
11
10
|
registerGAPageview();
|
|
12
|
-
registerParselyPageview();
|
|
13
11
|
}
|
|
14
12
|
|
|
15
13
|
export { registerPageview };
|
|
@@ -21,7 +19,7 @@
|
|
|
21
19
|
}
|
|
22
20
|
|
|
23
21
|
import { onMount } from 'svelte';
|
|
24
|
-
import { ga, chartbeat
|
|
22
|
+
import { ga, chartbeat } from './providers';
|
|
25
23
|
interface Props {
|
|
26
24
|
/**
|
|
27
25
|
* Used to associate a page with its author(s) in Chartbeat.
|
|
@@ -34,6 +32,5 @@
|
|
|
34
32
|
onMount(() => {
|
|
35
33
|
ga();
|
|
36
34
|
chartbeat(authors);
|
|
37
|
-
parsely();
|
|
38
35
|
});
|
|
39
36
|
</script>
|
|
@@ -37,11 +37,11 @@ export interface CustomFont {
|
|
|
37
37
|
family?: Partial<FontFamily>;
|
|
38
38
|
size?: Partial<FontSize>;
|
|
39
39
|
}
|
|
40
|
-
export interface
|
|
40
|
+
export interface ThemeConfig {
|
|
41
41
|
colour: Colour;
|
|
42
42
|
font: Font;
|
|
43
43
|
}
|
|
44
|
-
export interface
|
|
44
|
+
export interface CustomThemeConfig {
|
|
45
45
|
colour?: Partial<Colour>;
|
|
46
46
|
font?: Partial<CustomFont>;
|
|
47
47
|
[customProperty: string]: unknown;
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
import mergeThemes from './utils/merge.js';
|
|
15
15
|
|
|
16
16
|
// Types
|
|
17
|
-
import type {
|
|
17
|
+
import type { CustomThemeConfig, ThemeConfig } from './@types/component';
|
|
18
18
|
import type { Snippet } from 'svelte';
|
|
19
19
|
type Base = 'light' | 'dark';
|
|
20
20
|
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
/** Custom theme object. Can be a partial theme with just
|
|
23
23
|
* what you want to change.
|
|
24
24
|
*/
|
|
25
|
-
theme?:
|
|
25
|
+
theme?: CustomThemeConfig | ThemeConfig;
|
|
26
26
|
/**
|
|
27
27
|
* Base theme is one of `light` or `dark` and will be merged
|
|
28
28
|
* with your custom theme to fill in any values you don't
|
|
@@ -2,17 +2,17 @@
|
|
|
2
2
|
* Pre-made themes you can import.
|
|
3
3
|
*/
|
|
4
4
|
export declare const themes: {
|
|
5
|
-
light:
|
|
6
|
-
dark:
|
|
5
|
+
light: ThemeConfig;
|
|
6
|
+
dark: ThemeConfig;
|
|
7
7
|
};
|
|
8
|
-
import type {
|
|
8
|
+
import type { CustomThemeConfig, ThemeConfig } from './@types/component';
|
|
9
9
|
import type { Snippet } from 'svelte';
|
|
10
10
|
type Base = 'light' | 'dark';
|
|
11
11
|
interface Props {
|
|
12
12
|
/** Custom theme object. Can be a partial theme with just
|
|
13
13
|
* what you want to change.
|
|
14
14
|
*/
|
|
15
|
-
theme?:
|
|
15
|
+
theme?: CustomThemeConfig | ThemeConfig;
|
|
16
16
|
/**
|
|
17
17
|
* Base theme is one of `light` or `dark` and will be merged
|
|
18
18
|
* with your custom theme to fill in any values you don't
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** @type {Omit<import('../@types/component').
|
|
1
|
+
/** @type {Omit<import('../@types/component').ThemeConfig, "colour">} */
|
|
2
2
|
/* Generated from
|
|
3
3
|
https://www.fluid-type-scale.com/calculate?minFontSize=18&minWidth=320&minRatio=1.125&maxFontSize=21&maxWidth=1280&maxRatio=1.25&steps=xxs%2Cxs%2Csm%2Cbase%2Clg%2Cxl%2C2xl%2C3xl%2C4xl%2C5xl%2C6xl&baseStep=base&prefix=&decimals=2&useRems=on&remValue=16&previewFont=Noto+Sans&previewText=Almost+before+we+knew+it%2C+we+had+left+the+ground&previewWidth=0
|
|
4
4
|
*/
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ThemeConfig, CustomThemeConfig } from '../@types/component';
|
|
2
2
|
/**
|
|
3
3
|
* Deep merges theme objects.
|
|
4
4
|
*/
|
|
5
|
-
export default function merge<T extends Record<string, unknown>>(target: T, ...sources: (
|
|
5
|
+
export default function merge<T extends Record<string, unknown>>(target: T, ...sources: (ThemeConfig | CustomThemeConfig)[]): T;
|
|
@@ -19,7 +19,8 @@ By default, `visible` will switch between `false` and `true` whenever the elemen
|
|
|
19
19
|
import { Visible } from '@reuters-graphics/graphics-components';
|
|
20
20
|
</script>
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
<!-- Optionally set your own `top`, `bottom`, `right` and `left` values with `px` or `%` units -->
|
|
23
|
+
<Visible top="10px">
|
|
23
24
|
{#snippet children(visible)}
|
|
24
25
|
{#if visible}
|
|
25
26
|
<p>Visible!</p>
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { defineMeta } from '@storybook/addon-svelte-csf';
|
|
3
3
|
|
|
4
4
|
import Visible from './Visible.svelte';
|
|
5
|
+
import VisibleDemo from './demo/VisibleDemo.svelte';
|
|
5
6
|
|
|
6
7
|
const { Story } = defineMeta({
|
|
7
8
|
title: 'Components/Utilities/Visible',
|
|
@@ -9,14 +10,6 @@
|
|
|
9
10
|
});
|
|
10
11
|
</script>
|
|
11
12
|
|
|
12
|
-
<Story name="Demo"
|
|
13
|
-
<
|
|
14
|
-
{#snippet children(visible)}
|
|
15
|
-
{#if visible}
|
|
16
|
-
<p>Visible!</p>
|
|
17
|
-
{:else}
|
|
18
|
-
<p>Not yet visible.</p>
|
|
19
|
-
{/if}
|
|
20
|
-
{/snippet}
|
|
21
|
-
</Visible>
|
|
13
|
+
<Story name="Demo">
|
|
14
|
+
<VisibleDemo />
|
|
22
15
|
</Story>
|
|
@@ -9,14 +9,14 @@
|
|
|
9
9
|
* Useful for loading expensive images or other media and then keeping them around once they're first loaded.
|
|
10
10
|
*/
|
|
11
11
|
once?: boolean;
|
|
12
|
-
/** Set Intersection Observer [rootMargin](https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API#rootmargin) `top
|
|
13
|
-
top?:
|
|
14
|
-
/** Set Intersection Observer [rootMargin](https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API#rootmargin) `bottom
|
|
15
|
-
bottom?:
|
|
16
|
-
/** Set Intersection Observer [rootMargin](https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API#rootmargin) `left
|
|
17
|
-
left?:
|
|
18
|
-
/** Set Intersection Observer [rootMargin](https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API#rootmargin) `right
|
|
19
|
-
right?:
|
|
12
|
+
/** Set Intersection Observer [rootMargin](https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API#rootmargin) `top` with units. Units must be `px` or other [absolute lengths units](https://arc.net/l/quote/jkukcxqq), or `%`. */
|
|
13
|
+
top?: string;
|
|
14
|
+
/** Set Intersection Observer [rootMargin](https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API#rootmargin) `bottom` with units. Units must be `px` or other [absolute lengths units](https://arc.net/l/quote/jkukcxqq), or `%`. */
|
|
15
|
+
bottom?: string;
|
|
16
|
+
/** Set Intersection Observer [rootMargin](https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API#rootmargin) `left` with units. Units must be `px` or other [absolute lengths units](https://arc.net/l/quote/jkukcxqq), or `%`. */
|
|
17
|
+
left?: string;
|
|
18
|
+
/** Set Intersection Observer [rootMargin](https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API#rootmargin) `right` with units. Units must be `px` or other [absolute lengths units](https://arc.net/l/quote/jkukcxqq), or `%`. */
|
|
19
|
+
right?: string;
|
|
20
20
|
/** Set the Intersection Observer [threshold](https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API#threshold). */
|
|
21
21
|
threshold?: number;
|
|
22
22
|
children?: Snippet<[boolean]>;
|
|
@@ -24,10 +24,10 @@
|
|
|
24
24
|
|
|
25
25
|
let {
|
|
26
26
|
once = false,
|
|
27
|
-
top =
|
|
28
|
-
bottom =
|
|
29
|
-
left =
|
|
30
|
-
right =
|
|
27
|
+
top = '0px',
|
|
28
|
+
bottom = '0px',
|
|
29
|
+
left = '0px',
|
|
30
|
+
right = '0px',
|
|
31
31
|
threshold = 0,
|
|
32
32
|
children,
|
|
33
33
|
}: Props = $props();
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
|
|
38
38
|
onMount(() => {
|
|
39
39
|
if (typeof IntersectionObserver !== 'undefined') {
|
|
40
|
-
const rootMargin = `${bottom}
|
|
40
|
+
const rootMargin = `${bottom} ${left} ${top} ${right}`;
|
|
41
41
|
|
|
42
42
|
const observer = new IntersectionObserver(
|
|
43
43
|
(entries) => {
|
|
@@ -53,28 +53,18 @@
|
|
|
53
53
|
);
|
|
54
54
|
if (container) observer.observe(container);
|
|
55
55
|
return () => {
|
|
56
|
-
if (container) observer.
|
|
56
|
+
if (container) observer.unobserve(container);
|
|
57
57
|
};
|
|
58
58
|
}
|
|
59
|
-
function handler() {
|
|
60
|
-
if (container) {
|
|
61
|
-
const bcr = container.getBoundingClientRect();
|
|
62
|
-
visible =
|
|
63
|
-
bcr.bottom + bottom > 0 &&
|
|
64
|
-
bcr.right + right > 0 &&
|
|
65
|
-
bcr.top - top < window.innerHeight &&
|
|
66
|
-
bcr.left - left < window.innerWidth;
|
|
67
|
-
}
|
|
68
|
-
if (visible && once) {
|
|
69
|
-
window.removeEventListener('scroll', handler);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
window.addEventListener('scroll', handler);
|
|
73
|
-
return () => window.removeEventListener('scroll', handler);
|
|
74
59
|
});
|
|
75
60
|
</script>
|
|
76
61
|
|
|
77
|
-
<div
|
|
62
|
+
<div
|
|
63
|
+
bind:this={container}
|
|
64
|
+
class="visibility-tracker"
|
|
65
|
+
class:visible
|
|
66
|
+
class:not-visible={!visible}
|
|
67
|
+
>
|
|
78
68
|
{#if children}
|
|
79
69
|
{@render children(visible)}
|
|
80
70
|
{/if}
|
|
@@ -6,14 +6,14 @@ interface Props {
|
|
|
6
6
|
* Useful for loading expensive images or other media and then keeping them around once they're first loaded.
|
|
7
7
|
*/
|
|
8
8
|
once?: boolean;
|
|
9
|
-
/** Set Intersection Observer [rootMargin](https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API#rootmargin) `top
|
|
10
|
-
top?:
|
|
11
|
-
/** Set Intersection Observer [rootMargin](https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API#rootmargin) `bottom
|
|
12
|
-
bottom?:
|
|
13
|
-
/** Set Intersection Observer [rootMargin](https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API#rootmargin) `left
|
|
14
|
-
left?:
|
|
15
|
-
/** Set Intersection Observer [rootMargin](https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API#rootmargin) `right
|
|
16
|
-
right?:
|
|
9
|
+
/** Set Intersection Observer [rootMargin](https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API#rootmargin) `top` with units. Units must be `px` or other [absolute lengths units](https://arc.net/l/quote/jkukcxqq), or `%`. */
|
|
10
|
+
top?: string;
|
|
11
|
+
/** Set Intersection Observer [rootMargin](https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API#rootmargin) `bottom` with units. Units must be `px` or other [absolute lengths units](https://arc.net/l/quote/jkukcxqq), or `%`. */
|
|
12
|
+
bottom?: string;
|
|
13
|
+
/** Set Intersection Observer [rootMargin](https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API#rootmargin) `left` with units. Units must be `px` or other [absolute lengths units](https://arc.net/l/quote/jkukcxqq), or `%`. */
|
|
14
|
+
left?: string;
|
|
15
|
+
/** Set Intersection Observer [rootMargin](https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API#rootmargin) `right` with units. Units must be `px` or other [absolute lengths units](https://arc.net/l/quote/jkukcxqq), or `%`. */
|
|
16
|
+
right?: string;
|
|
17
17
|
/** Set the Intersection Observer [threshold](https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API#threshold). */
|
|
18
18
|
threshold?: number;
|
|
19
19
|
children?: Snippet<[boolean]>;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import Visible from '../Visible.svelte';
|
|
3
|
+
import BodyText from '../../BodyText/BodyText.svelte';
|
|
4
|
+
import Block from '../../Block/Block.svelte';
|
|
5
|
+
import FeaturePhoto from '../../FeaturePhoto/FeaturePhoto.svelte';
|
|
6
|
+
import sharkSrc from '../../FeaturePhoto/images/shark.jpg';
|
|
7
|
+
|
|
8
|
+
let top = '150px';
|
|
9
|
+
|
|
10
|
+
const demoText =
|
|
11
|
+
'Take a look at the *Elements* tab in Inspector to see how the photo in the middle of the page appears in the DOM only when its container comes into view.';
|
|
12
|
+
|
|
13
|
+
let demoText2 = $derived(
|
|
14
|
+
`The top value for \`rootMargin\` is set to \`${top}px\` in this demo. Read about how \`rootMargin\` affects the <a href='https://codepen.io/michellebarker/full/xxwLpRG'>Intersection Observer's behaviour here</a>.`
|
|
15
|
+
);
|
|
16
|
+
|
|
17
|
+
const text =
|
|
18
|
+
'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.';
|
|
19
|
+
</script>
|
|
20
|
+
|
|
21
|
+
<BodyText text={`**${demoText}**`} />
|
|
22
|
+
|
|
23
|
+
<BodyText text={`**${demoText2}**`} />
|
|
24
|
+
<BodyText {text} />
|
|
25
|
+
<BodyText {text} />
|
|
26
|
+
<BodyText {text} />
|
|
27
|
+
<BodyText {text} />
|
|
28
|
+
|
|
29
|
+
<Visible {top} once={false}>
|
|
30
|
+
{#snippet children(visible)}
|
|
31
|
+
{#if visible}
|
|
32
|
+
<FeaturePhoto
|
|
33
|
+
src={sharkSrc}
|
|
34
|
+
altText="A shark!"
|
|
35
|
+
caption="Carcharodon carcharias - REUTERS"
|
|
36
|
+
/>
|
|
37
|
+
{:else}
|
|
38
|
+
<Block><h2>Not yet visible.</h2></Block>
|
|
39
|
+
{/if}
|
|
40
|
+
{/snippet}
|
|
41
|
+
</Visible>
|
|
42
|
+
<BodyText {text} />
|
|
43
|
+
<BodyText {text} />
|
|
44
|
+
<BodyText {text} />
|
|
45
|
+
<BodyText {text} />
|
|
46
|
+
<BodyText {text} />
|
package/dist/globals.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
const SITE_ID = 'reuters.com';
|
|
2
|
-
const attachScript = () => {
|
|
3
|
-
const b = document.body;
|
|
4
|
-
const e = document.createElement('script');
|
|
5
|
-
e.id = 'parsely-cfg';
|
|
6
|
-
e.src = `//cdn.parsely.com/keys/${SITE_ID}/p.js`;
|
|
7
|
-
e.setAttribute('async', '');
|
|
8
|
-
e.setAttribute('defer', '');
|
|
9
|
-
b.appendChild(e);
|
|
10
|
-
};
|
|
11
|
-
export default () => {
|
|
12
|
-
window.PARSELY = window.PARSELY || {
|
|
13
|
-
autotrack: false,
|
|
14
|
-
onReady() {
|
|
15
|
-
window.PARSELY.updateDefaults({
|
|
16
|
-
data: {
|
|
17
|
-
is_logged_in: false,
|
|
18
|
-
},
|
|
19
|
-
});
|
|
20
|
-
window.PARSELY.beacon.trackPageView();
|
|
21
|
-
},
|
|
22
|
-
};
|
|
23
|
-
attachScript();
|
|
24
|
-
};
|
|
25
|
-
export const registerPageview = () => {
|
|
26
|
-
if (typeof window === 'undefined' || !window.PARSELY)
|
|
27
|
-
return;
|
|
28
|
-
window.PARSELY.beacon.trackPageView();
|
|
29
|
-
};
|