basklee-svelte 0.9.2 → 0.9.3
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "basklee-svelte",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.3",
|
|
4
4
|
"description": "SvelteKit 2 storefront for your Basklee marketplace: setup CLI, server API gateway, typed store and ready-made catalog, cart, checkout and account components in English, Russian and Spanish, plus an Android app build.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -6,6 +6,8 @@ The article page shows one journal article: its cover, its text, the products at
|
|
|
6
6
|
|
|
7
7
|
Article videos may come as the backend's own paths (`/ps3/...`). In an Android app build those paths (cover, videos, images and videos inside the text) load from the storefront address.
|
|
8
8
|
|
|
9
|
+
The text is sanitized with DOMPurify in `src/lib/utils/basklee/blogArticleHtml.ts`. A YouTube player the editor inserts (an `<iframe>` with a `youtube.com` or `youtube-nocookie.com` `/embed/<id>` address) is kept and played from `youtube-nocookie.com` at the article's width in 16:9, with fixed `allow`, `loading="lazy"` and referrer attributes and an optional start second. Other frames, scripts, forms and event attributes are removed.
|
|
10
|
+
|
|
9
11
|
The cover and the images of the text open larger: a click, Enter or Space on one opens `ProductReviewImageViewer` at that image, with the article's other images a step away and each image's caption (its `figcaption`, else its `title`, else its `alt`) under it. The images get `role="button"`, a keyboard stop and an «Open image» name; a zoom-in cursor marks them. Images inside a link, a button or a product placement keep their own action. The helper is `src/lib/utils/basklee/blogImageViewer.ts`.
|
|
10
12
|
|
|
11
13
|
Products the author places in the text appear at those positions: an empty block with `data-product-id="12"` shows one product card, `data-product-ids="12,15,9"` a row of up to 24 cards. The block keeps the editor's float or centred style, and `data-product-hidden-badges` (`new`, `popular`, `good-deal`) turns card badges off. Products missing from `related_products` are loaded with `products_search` and `filters.id_in`, up to 35 IDs per request, and stored with `store.setProduct()`; a block whose products are not found stays hidden. Article text styles do not reach the cards, and in a narrow article a floated card stands alone in the middle. The helper is `src/lib/utils/basklee/blogProductPlacements.ts`.
|
|
@@ -1048,6 +1048,18 @@
|
|
|
1048
1048
|
width: 100%;
|
|
1049
1049
|
}
|
|
1050
1050
|
|
|
1051
|
+
/* A YouTube player from the editor: the article's width, 16:9. */
|
|
1052
|
+
.op-feature-prose :global(iframe.blog-post-editor-youtube:where(:not([data-product-id] *, [data-product-ids] *))) {
|
|
1053
|
+
display: block;
|
|
1054
|
+
width: 100%;
|
|
1055
|
+
height: auto;
|
|
1056
|
+
margin: 1.5rem 0;
|
|
1057
|
+
clear: both;
|
|
1058
|
+
aspect-ratio: 16 / 9;
|
|
1059
|
+
border: 0;
|
|
1060
|
+
background: #000;
|
|
1061
|
+
}
|
|
1062
|
+
|
|
1051
1063
|
.op-feature-prose :global(figcaption:where(:not([data-product-id] *, [data-product-ids] *))) {
|
|
1052
1064
|
margin-top: 0.5rem;
|
|
1053
1065
|
font-size: 0.875rem;
|
|
@@ -14,8 +14,9 @@ type TStylePatterns = Record<string, RegExp>;
|
|
|
14
14
|
* the backend, so the storefront sanitizes it before display. The allowlist
|
|
15
15
|
* matches what that editor writes: text formatting, headings, lists and task
|
|
16
16
|
* lists, quotes, code blocks, tables, images and galleries, videos,
|
|
17
|
-
* collapsible sections, formulas and alignment, color and size styles
|
|
18
|
-
*
|
|
17
|
+
* collapsible sections, formulas and alignment, color and size styles,
|
|
18
|
+
* and YouTube players. A frame is kept only when its address is a YouTube
|
|
19
|
+
* embed (see blogYoutubeEmbedSource); every other frame is removed.
|
|
19
20
|
*/
|
|
20
21
|
|
|
21
22
|
export const blogArticleTags = [
|
|
@@ -78,6 +79,7 @@ export const blogArticleTags = [
|
|
|
78
79
|
'track',
|
|
79
80
|
'details',
|
|
80
81
|
'summary',
|
|
82
|
+
'iframe',
|
|
81
83
|
];
|
|
82
84
|
|
|
83
85
|
const attributes = [
|
|
@@ -135,6 +137,9 @@ const attributes = [
|
|
|
135
137
|
'data-product-id',
|
|
136
138
|
'data-product-ids',
|
|
137
139
|
'data-product-hidden-badges',
|
|
140
|
+
'allow',
|
|
141
|
+
'allowfullscreen',
|
|
142
|
+
'referrerpolicy',
|
|
138
143
|
];
|
|
139
144
|
|
|
140
145
|
const marginLength = '(-?\\d+(\\.\\d+)?(px|em|rem|%)?|auto)';
|
|
@@ -146,6 +151,7 @@ const editorClasses = new Set([
|
|
|
146
151
|
'blog-code-block',
|
|
147
152
|
'blog-post-editor-image',
|
|
148
153
|
'blog-post-editor-video',
|
|
154
|
+
'blog-post-editor-youtube',
|
|
149
155
|
]);
|
|
150
156
|
|
|
151
157
|
// The editor's named text and background colors.
|
|
@@ -193,6 +199,53 @@ const editorArticlePath =
|
|
|
193
199
|
|
|
194
200
|
const authorRelTokens = new Set(['nofollow', 'sponsored', 'ugc']);
|
|
195
201
|
|
|
202
|
+
// A YouTube player the editor inserts: youtube.com or youtube-nocookie.com,
|
|
203
|
+
// /embed/ and an 11-character video ID, optionally a start second.
|
|
204
|
+
const youtubeEmbed =
|
|
205
|
+
/^https:\/\/(?:www\.)?youtube(?:-nocookie)?\.com\/embed\/([\w-]{11})(?:\?([^#]*))?$/i;
|
|
206
|
+
|
|
207
|
+
export const blogYoutubeAllow =
|
|
208
|
+
'accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share';
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* The privacy-enhanced player address for a YouTube embed address, or an
|
|
212
|
+
* empty string for anything else (other sites, other YouTube pages).
|
|
213
|
+
*/
|
|
214
|
+
export function blogYoutubeEmbedSource(value: string) {
|
|
215
|
+
const match = youtubeEmbed.exec(value.trim());
|
|
216
|
+
|
|
217
|
+
if (!match) {
|
|
218
|
+
return '';
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
const start = /(?:^|&)start=(\d{1,6})(?:&|$)/.exec(match[2] ?? '')?.[1];
|
|
222
|
+
|
|
223
|
+
return `https://www.youtube-nocookie.com/embed/${match[1]}${start && Number(start) > 0 ? `?start=${Number(start)}` : ''}`;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
function prepareYoutubeFrame(node: Element) {
|
|
227
|
+
const source = blogYoutubeEmbedSource(node.getAttribute('src') ?? '');
|
|
228
|
+
|
|
229
|
+
if (!source) {
|
|
230
|
+
node.remove();
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
const title = node.getAttribute('title')?.trim() || 'YouTube video';
|
|
235
|
+
|
|
236
|
+
for (const attribute of [...node.getAttributeNames()]) {
|
|
237
|
+
node.removeAttribute(attribute);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
node.setAttribute('class', 'blog-post-editor-youtube');
|
|
241
|
+
node.setAttribute('src', source);
|
|
242
|
+
node.setAttribute('title', title);
|
|
243
|
+
node.setAttribute('allow', blogYoutubeAllow);
|
|
244
|
+
node.setAttribute('allowfullscreen', '');
|
|
245
|
+
node.setAttribute('loading', 'lazy');
|
|
246
|
+
node.setAttribute('referrerpolicy', 'strict-origin-when-cross-origin');
|
|
247
|
+
}
|
|
248
|
+
|
|
196
249
|
function normalizedHeadingText(value: string) {
|
|
197
250
|
return htmlTextParagraphs(value)
|
|
198
251
|
.join(' ')
|
|
@@ -314,6 +367,11 @@ function prepareLink(link: Element) {
|
|
|
314
367
|
function prepareElement(node: Element) {
|
|
315
368
|
const name = node.nodeName;
|
|
316
369
|
|
|
370
|
+
if (name === 'IFRAME') {
|
|
371
|
+
prepareYoutubeFrame(node);
|
|
372
|
+
return;
|
|
373
|
+
}
|
|
374
|
+
|
|
317
375
|
if (name === 'A') {
|
|
318
376
|
prepareLink(node);
|
|
319
377
|
}
|