@reuters-graphics/graphics-components 0.0.21 → 0.0.23

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.
@@ -0,0 +1,38 @@
1
+ import { SvelteComponentTyped } from "svelte";
2
+ declare const __propDef: {
3
+ props: {
4
+ /**
5
+ * Section ID, which is often the URL path to the section page on reuters.com.
6
+ *
7
+ * Note that not all section pages will be available in the recent stories by section API.
8
+ * @required
9
+ */ section?: string;
10
+ /**
11
+ * Number of referrals to show.
12
+ * @required
13
+ */ number?: number;
14
+ /**
15
+ * Link [target](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#attr-target), e.g., `_blank` or `_parent`.
16
+ */ linkTarget?: string;
17
+ /**
18
+ * Add a heading to the referral block.
19
+ */ heading?: string;
20
+ /**
21
+ * Width of the component within the text well.
22
+ * @required
23
+ */ width?: "normal" | "wide" | "wider" | "widest" | "fluid";
24
+ /** Add an ID to target with SCSS. */ id?: string;
25
+ /** Add a class to target with SCSS. */ cls?: string;
26
+ };
27
+ events: {
28
+ [evt: string]: CustomEvent<any>;
29
+ };
30
+ slots: {};
31
+ };
32
+ export declare type ReferralBlockProps = typeof __propDef.props;
33
+ export declare type ReferralBlockEvents = typeof __propDef.events;
34
+ export declare type ReferralBlockSlots = typeof __propDef.slots;
35
+ /** `ReferralBlock` [Read the docs.](https://reuters-graphics.github.io/graphics-components/?path=/docs/components-ReferralBlock--default) */
36
+ export default class ReferralBlock extends SvelteComponentTyped<ReferralBlockProps, ReferralBlockEvents, ReferralBlockSlots> {
37
+ }
38
+ export {};
@@ -0,0 +1 @@
1
+ export const referrals: import("svelte/store").Writable<any[]>;
@@ -14,6 +14,7 @@ export { default as PaddingReset } from "./components/PaddingReset/PaddingReset.
14
14
  export { default as PhotoPack } from "./components/PhotoPack/PhotoPack.svelte";
15
15
  export { default as PymChild } from "./components/PymChild/PymChild.svelte";
16
16
  export { pymChildStore } from "./components/PymChild/stores.js";
17
+ export { default as ReferralBlock } from "./components/ReferralBlock/ReferralBlock.svelte";
17
18
  export { default as ReutersLogo } from "./components/ReutersLogo/ReutersLogo.svelte";
18
19
  export { default as Scroller } from "./components/Scroller/Scroller.svelte";
19
20
  export { default as SEO } from "./components/SEO/SEO.svelte";
@@ -0,0 +1,212 @@
1
+ <!-- @component `ReferralBlock` [Read the docs.](https://reuters-graphics.github.io/graphics-components/?path=/docs/components-ReferralBlock--default) -->
2
+ <script>/** ✏️ DOCUMENT your chart's props using TypeScript and JSDoc comments like below! */
3
+ /**
4
+ * Section ID, which is often the URL path to the section page on reuters.com.
5
+ *
6
+ * Note that not all section pages will be available in the recent stories by section API.
7
+ * @required
8
+ */
9
+ export let section = '/world/';
10
+ /**
11
+ * Number of referrals to show.
12
+ * @required
13
+ */
14
+ export let number = 4;
15
+ /**
16
+ * Link [target](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#attr-target), e.g., `_blank` or `_parent`.
17
+ */
18
+ export let linkTarget = '_self';
19
+ /**
20
+ * Add a heading to the referral block.
21
+ */
22
+ export let heading = '';
23
+ /**
24
+ * Width of the component within the text well.
25
+ * @required
26
+ */
27
+ export let width = 'wide';
28
+ /** Add an ID to target with SCSS. */
29
+ export let id = '';
30
+ /** Add a class to target with SCSS. */
31
+ export let cls = '';
32
+ import Block from '../Block/Block.svelte';
33
+ import { referrals } from './stores.js';
34
+ import { onMount } from 'svelte';
35
+ import { getTime } from '../SiteHeader/NavBar/NavDropdown/StoryCard/time';
36
+ let clientWidth;
37
+ onMount(async () => {
38
+ try {
39
+ const response = await fetch('https://www.reuters.com/pf/api/v3/content/fetch/recent-stories-by-sections-v1?' +
40
+ new URLSearchParams({
41
+ query: JSON.stringify({
42
+ section_ids: section,
43
+ size: 20,
44
+ website: 'reuters',
45
+ }),
46
+ }));
47
+ const articles = (await response.json()).result.articles
48
+ .filter((a) => { var _a; return (_a = a === null || a === void 0 ? void 0 : a.kicker) === null || _a === void 0 ? void 0 : _a.name; })
49
+ .filter((a) => { var _a, _b, _c; return (_c = (_b = (_a = a === null || a === void 0 ? void 0 : a.thumbnail) === null || _a === void 0 ? void 0 : _a.renditions) === null || _b === void 0 ? void 0 : _b.landscape) === null || _c === void 0 ? void 0 : _c['240w']; })
50
+ .filter((a) => { var _a; return !((_a = a === null || a === void 0 ? void 0 : a.content) === null || _a === void 0 ? void 0 : _a.third_party); })
51
+ .slice(0, number);
52
+ referrals.set(articles);
53
+ }
54
+ catch (e) {
55
+ console.warn('Unable to fetch referral links.');
56
+ }
57
+ });
58
+ getTime();
59
+ </script>
60
+
61
+ {#if $referrals.length === number}
62
+ <Block width="{width}" id="{id}" cls="referrals-block {cls}">
63
+ {#if heading}
64
+ <h4 class:stacked="{clientWidth && clientWidth < 750}">{heading}</h4>
65
+ {/if}
66
+ <div
67
+ class="referral-container"
68
+ class:stacked="{clientWidth && clientWidth < 750}"
69
+ class:xs="{clientWidth && clientWidth < 450}"
70
+ bind:clientWidth
71
+ >
72
+ {#each $referrals as referral}
73
+ <div class="referral">
74
+ <a
75
+ href="https://www.reuters.com{referral.canonical_url}"
76
+ target="{linkTarget}"
77
+ rel="{linkTarget === '_blank' ? 'noreferrer' : null}"
78
+ >
79
+ <div class="referral-pack">
80
+ <div
81
+ class="headline"
82
+ class:xs="{clientWidth && clientWidth < 450}"
83
+ >
84
+ <div class="kicker">{referral.kicker.name}</div>
85
+ <div class="title">{referral.title}</div>
86
+ <div class="publish-time">
87
+ {getTime(new Date(referral.display_time))}
88
+ </div>
89
+ </div>
90
+ <div
91
+ class="image-container"
92
+ class:xs="{clientWidth && clientWidth < 450}"
93
+ >
94
+ <img
95
+ src="{referral.thumbnail.renditions.landscape['240w']}"
96
+ alt="{referral.thumbnail.caption ||
97
+ referral.thumbnail.alt_text}"
98
+ />
99
+ </div>
100
+ </div>
101
+ </a>
102
+ </div>
103
+ {/each}
104
+ </div>
105
+ </Block>
106
+ {/if}
107
+
108
+ <style>h4 {
109
+ font-family: var(--theme-font-family-subhed);
110
+ color: var(--theme-colour-text-primary, #404040);
111
+ font-size: 1.1rem;
112
+ margin: 0 0 5px;
113
+ font-weight: bold;
114
+ }
115
+ h4.stacked {
116
+ max-width: 450px;
117
+ margin: 0 auto 5px;
118
+ }
119
+
120
+ .referral-container {
121
+ width: 100%;
122
+ display: inline-flex;
123
+ flex-wrap: wrap;
124
+ justify-content: center;
125
+ gap: 10px 40px;
126
+ }
127
+ .referral-container a {
128
+ text-decoration: none;
129
+ }
130
+ .referral-container.stacked .referral {
131
+ width: 100%;
132
+ }
133
+ .referral-container.stacked .referral .headline {
134
+ padding: 0 10px 0 0;
135
+ }
136
+ .referral-container .referral {
137
+ display: block;
138
+ width: calc(50% - 20px);
139
+ max-width: 450px;
140
+ }
141
+ .referral-container .referral:hover .title {
142
+ text-decoration: underline;
143
+ }
144
+ .referral-container .referral:hover img {
145
+ filter: brightness(85%);
146
+ }
147
+ .referral-container .referral div.referral-pack {
148
+ display: flex;
149
+ justify-content: space-around;
150
+ max-width: 450px;
151
+ margin: 0 auto;
152
+ }
153
+ .referral-container .referral .headline {
154
+ display: inline-block;
155
+ width: calc(100% - 140px);
156
+ padding: 0 10px 0 0;
157
+ }
158
+ .referral-container .referral .headline.xs {
159
+ width: calc(100% - 80px);
160
+ }
161
+ .referral-container .referral .headline.xs .kicker {
162
+ font-size: 0.85rem;
163
+ }
164
+ .referral-container .referral .headline.xs .title {
165
+ font-size: 0.9rem;
166
+ line-height: 1.1rem;
167
+ }
168
+ .referral-container .referral .headline .kicker {
169
+ font-family: var(--theme-font-family-subhed);
170
+ color: var(--theme-colour-text-secondary, #666666);
171
+ font-size: 0.9rem;
172
+ margin: 0;
173
+ font-weight: 400;
174
+ }
175
+ .referral-container .referral .headline .title {
176
+ font-family: var(--theme-font-family-subhed);
177
+ color: var(--theme-colour-text-primary, #404040);
178
+ font-size: 0.95rem;
179
+ line-height: 1.15rem;
180
+ font-weight: bold;
181
+ margin: 0;
182
+ }
183
+ .referral-container .referral .headline .publish-time {
184
+ font-family: var(--theme-font-family-subhed);
185
+ color: var(--theme-colour-text-secondary, #666666);
186
+ font-size: 0.75rem;
187
+ margin: 2px 0 0;
188
+ font-weight: 400;
189
+ }
190
+ .referral-container .referral .image-container {
191
+ margin: 0;
192
+ overflow: hidden;
193
+ border-radius: 10px;
194
+ border: 1px solid var(--theme-colour-brand-rules, #d0d0d0);
195
+ display: block;
196
+ position: relative;
197
+ width: 140px;
198
+ height: 90px;
199
+ }
200
+ .referral-container .referral .image-container.xs {
201
+ width: 80px;
202
+ height: 60px;
203
+ }
204
+ .referral-container .referral .image-container img {
205
+ transition: filter 0.1s;
206
+ display: block;
207
+ width: 100%;
208
+ height: inherit;
209
+ -o-object-fit: cover;
210
+ object-fit: cover;
211
+ margin: 0;
212
+ }</style>
@@ -0,0 +1,3 @@
1
+ import { writable } from 'svelte/store';
2
+
3
+ export const referrals = writable([]);
@@ -16,30 +16,32 @@ const attachScript = function (i, s, o, g, r, a, m) {
16
16
  /* eslint-enable */
17
17
 
18
18
  export default (page, title) => {
19
- if (!window.ga) {
20
- attachScript(
21
- window,
22
- document,
23
- 'script',
24
- 'https://www.google-analytics.com/analytics.js',
25
- 'ga'
26
- );
27
-
28
- window.ga('create', 'UA-41619329-3', { cookieDomain: 'auto' });
29
- window.ga('require', 'linkid', 'linkid.js');
30
- }
31
-
32
- window.ga('send', 'pageview', {
33
- page,
34
- title,
35
- });
19
+ try {
20
+ if (!window.ga) {
21
+ attachScript(
22
+ window,
23
+ document,
24
+ 'script',
25
+ 'https://www.google-analytics.com/analytics.js',
26
+ 'ga'
27
+ );
28
+
29
+ window.ga('create', 'UA-41619329-3', { cookieDomain: 'auto' });
30
+ window.ga('require', 'linkid', 'linkid.js');
31
+ }
36
32
 
37
- if (!inIframe()) {
38
- // start time on page tracking if not in an iframe
39
- riveted.init({
40
- reportInterval: 30,
33
+ window.ga('send', 'pageview', {
34
+ page,
35
+ title,
41
36
  });
42
- }
37
+
38
+ if (!inIframe()) {
39
+ // start time on page tracking if not in an iframe
40
+ riveted.init({
41
+ reportInterval: 30,
42
+ });
43
+ }
44
+ } catch (e) {}
43
45
  };
44
46
 
45
47
  // checks if page is in an iframe
@@ -1,32 +1,34 @@
1
1
  export default () => {
2
- const { protocol } = document.location;
3
- const gptScript = document.querySelector(
4
- `script[src="${protocol}//www.googletagservices.com/tag/js/gpt.js"]`
5
- );
6
- // Only do this once.
7
- if (gptScript) return;
8
- const googletag = window.googletag || {};
9
- googletag.cmd = googletag.cmd || [];
10
- (function () {
11
- const gads = document.createElement('script');
12
- gads.async = true;
13
- gads.type = 'text/javascript';
14
- const useSSL = document.location.protocol === 'https:';
15
- gads.src =
16
- (useSSL ? 'https:' : 'http:') +
17
- '//www.googletagservices.com/tag/js/gpt.js';
18
- const node = document.getElementsByTagName('script')[0];
19
- node.parentNode.insertBefore(gads, node);
20
- })();
21
- googletag.cmd.push(function () {
22
- googletag
23
- .defineSlot(
24
- '/4735792/reuters_investigates',
25
- [[300, 250]],
26
- 'div-gpt-ad-1441822201033-0'
27
- )
28
- .addService(googletag.pubads());
29
- googletag.pubads().enableSingleRequest();
30
- googletag.enableServices();
31
- });
2
+ try {
3
+ const { protocol } = document.location;
4
+ const gptScript = document.querySelector(
5
+ `script[src="${protocol}//www.googletagservices.com/tag/js/gpt.js"]`
6
+ );
7
+ // Only do this once.
8
+ if (gptScript) return;
9
+ const googletag = window.googletag || {};
10
+ googletag.cmd = googletag.cmd || [];
11
+ (function () {
12
+ const gads = document.createElement('script');
13
+ gads.async = true;
14
+ gads.type = 'text/javascript';
15
+ const useSSL = document.location.protocol === 'https:';
16
+ gads.src =
17
+ (useSSL ? 'https:' : 'http:') +
18
+ '//www.googletagservices.com/tag/js/gpt.js';
19
+ const node = document.getElementsByTagName('script')[0];
20
+ node.parentNode.insertBefore(gads, node);
21
+ })();
22
+ googletag.cmd.push(function () {
23
+ googletag
24
+ .defineSlot(
25
+ '/4735792/reuters_investigates',
26
+ [[300, 250]],
27
+ 'div-gpt-ad-1441822201033-0'
28
+ )
29
+ .addService(googletag.pubads());
30
+ googletag.pubads().enableSingleRequest();
31
+ googletag.enableServices();
32
+ });
33
+ } catch (e) {}
32
34
  };
@@ -190,6 +190,7 @@ To handle overlapping borders within components (e.g., buttons and inputs in inp
190
190
  .section .section-link,
191
191
  .section .subsection-link {
192
192
  font-family: "Knowledge", "Source Sans Pro", Arial, sans-serif;
193
+ text-decoration: none;
193
194
  line-height: 1.2;
194
195
  color: var(--nav-primary);
195
196
  }
package/dist/index.js CHANGED
@@ -15,6 +15,7 @@ export { default as PaddingReset } from './components/PaddingReset/PaddingReset.
15
15
  export { default as PhotoPack } from './components/PhotoPack/PhotoPack.svelte';
16
16
  export { default as PymChild } from './components/PymChild/PymChild.svelte';
17
17
  export { pymChildStore } from './components/PymChild/stores.js';
18
+ export { default as ReferralBlock } from './components/ReferralBlock/ReferralBlock.svelte';
18
19
  export { default as ReutersLogo } from './components/ReutersLogo/ReutersLogo.svelte';
19
20
  export { default as Scroller } from './components/Scroller/Scroller.svelte';
20
21
  export { default as SEO } from './components/SEO/SEO.svelte';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reuters-graphics/graphics-components",
3
- "version": "0.0.21",
3
+ "version": "0.0.23",
4
4
  "type": "module",
5
5
  "private": false,
6
6
  "homepage": "https://reuters-graphics.github.io/graphics-components",
@@ -123,6 +123,8 @@
123
123
  "./components/PhotoPack/docProps.ts": "./dist/components/PhotoPack/docProps.ts",
124
124
  "./components/PymChild/PymChild.svelte": "./dist/components/PymChild/PymChild.svelte",
125
125
  "./components/PymChild/stores": "./dist/components/PymChild/stores.js",
126
+ "./components/ReferralBlock/ReferralBlock.svelte": "./dist/components/ReferralBlock/ReferralBlock.svelte",
127
+ "./components/ReferralBlock/stores": "./dist/components/ReferralBlock/stores.js",
126
128
  "./components/ReutersLogo/ReutersLogo.svelte": "./dist/components/ReutersLogo/ReutersLogo.svelte",
127
129
  "./components/SEO/SEO.svelte": "./dist/components/SEO/SEO.svelte",
128
130
  "./components/SEO/analytics": "./dist/components/SEO/analytics.js",