@aiconomy/aico-components 0.1.0 → 0.2.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/dist/aico-components/aico-components.esm.js +1 -1
- package/dist/aico-components/aico-components.esm.js.map +1 -1
- package/dist/aico-components/{p-17b7115a.entry.js → p-cf9b69ea.entry.js} +3 -3
- package/dist/aico-components/p-cf9b69ea.entry.js.map +1 -0
- package/dist/cjs/aico-album-content_28.cjs.entry.js +131 -10
- package/dist/cjs/aico-album-content_28.cjs.entry.js.map +1 -1
- package/dist/cjs/aico-components.cjs.js +1 -1
- package/dist/cjs/loader.cjs.js +1 -1
- package/dist/collection/components/aico-article-detail/aico-article-detail.js +11 -7
- package/dist/collection/components/aico-article-detail/aico-article-detail.js.map +1 -1
- package/dist/collection/components/aico-neo-content/aico-neo-content.js +53 -2
- package/dist/collection/components/aico-neo-content/aico-neo-content.js.map +1 -1
- package/dist/collection/utils/neo/neo-lead-trim.js +106 -0
- package/dist/collection/utils/neo/neo-lead-trim.js.map +1 -0
- package/dist/components/aico-article-detail2.js +11 -7
- package/dist/components/aico-article-detail2.js.map +1 -1
- package/dist/components/aico-neo-content2.js +126 -5
- package/dist/components/aico-neo-content2.js.map +1 -1
- package/dist/esm/aico-album-content_28.entry.js +131 -10
- package/dist/esm/aico-album-content_28.entry.js.map +1 -1
- package/dist/esm/aico-components.js +1 -1
- package/dist/esm/loader.js +1 -1
- package/dist/ssr/index.js +134 -11
- package/dist/ssr/index.mjs +134 -11
- package/dist/types/components/aico-article-detail/aico-article-detail.d.ts +3 -1
- package/dist/types/components/aico-neo-content/aico-neo-content.d.ts +10 -0
- package/dist/types/components.d.ts +16 -0
- package/dist/types/utils/neo/neo-lead-trim.d.ts +33 -0
- package/package.json +1 -1
- package/dist/aico-components/p-17b7115a.entry.js.map +0 -1
|
@@ -162,6 +162,112 @@ function resolveLocale(document, locale, defaultLocale = null) {
|
|
|
162
162
|
return resolved;
|
|
163
163
|
}
|
|
164
164
|
|
|
165
|
+
const ENTITIES = {
|
|
166
|
+
'&': '&',
|
|
167
|
+
'<': '<',
|
|
168
|
+
'>': '>',
|
|
169
|
+
'"': '"',
|
|
170
|
+
''': "'",
|
|
171
|
+
' ': ' ',
|
|
172
|
+
};
|
|
173
|
+
/** Plain text of an HTML fragment, whitespace-collapsed and lowercased (mirrors NeoNewsContentRenderer::normalizeText). */
|
|
174
|
+
function normalizeText(html) {
|
|
175
|
+
const stripped = html.replace(/<[^>]*>/g, '');
|
|
176
|
+
const decoded = stripped.replace(/&|<|>|"|'| /g, entity => ENTITIES[entity]);
|
|
177
|
+
return decoded.replace(/\s+/g, ' ').trim().toLowerCase();
|
|
178
|
+
}
|
|
179
|
+
function headingText(element) {
|
|
180
|
+
var _a;
|
|
181
|
+
const text = (_a = element.content) === null || _a === void 0 ? void 0 : _a.text;
|
|
182
|
+
return typeof text === 'string' ? text : '';
|
|
183
|
+
}
|
|
184
|
+
/** Filters one elements array, recursing into `columns` children. Returns the input array by reference when nothing changed. */
|
|
185
|
+
function trimElements(elements, state) {
|
|
186
|
+
const result = [];
|
|
187
|
+
let changed = false;
|
|
188
|
+
for (const element of elements) {
|
|
189
|
+
if (element.type === 'columns') {
|
|
190
|
+
const children = Array.isArray(element.children) ? element.children : [];
|
|
191
|
+
const newChildren = trimElements(children, state);
|
|
192
|
+
if (newChildren.length === 0) {
|
|
193
|
+
changed = true;
|
|
194
|
+
continue;
|
|
195
|
+
}
|
|
196
|
+
if (newChildren !== children) {
|
|
197
|
+
changed = true;
|
|
198
|
+
result.push(Object.assign(Object.assign({}, element), { children: newChildren }));
|
|
199
|
+
}
|
|
200
|
+
else {
|
|
201
|
+
result.push(element);
|
|
202
|
+
}
|
|
203
|
+
continue;
|
|
204
|
+
}
|
|
205
|
+
if (element.type === 'image') {
|
|
206
|
+
// Images never end the lead: kept or dropped, either way the next
|
|
207
|
+
// element is still evaluated as leading.
|
|
208
|
+
if (state.atLeadingEdge && state.dropLeadingImage) {
|
|
209
|
+
changed = true;
|
|
210
|
+
continue;
|
|
211
|
+
}
|
|
212
|
+
result.push(element);
|
|
213
|
+
continue;
|
|
214
|
+
}
|
|
215
|
+
if (element.type === 'divider') {
|
|
216
|
+
// Dividers don't end the lead either.
|
|
217
|
+
result.push(element);
|
|
218
|
+
continue;
|
|
219
|
+
}
|
|
220
|
+
if (element.type === 'heading') {
|
|
221
|
+
if (state.atLeadingEdge && state.normalizedTitle !== null && normalizeText(headingText(element)) === state.normalizedTitle) {
|
|
222
|
+
changed = true;
|
|
223
|
+
continue;
|
|
224
|
+
}
|
|
225
|
+
result.push(element);
|
|
226
|
+
state.atLeadingEdge = false;
|
|
227
|
+
continue;
|
|
228
|
+
}
|
|
229
|
+
// Any other element type (text, html, button, video, gallery, slideshow, …) is kept and ends the lead.
|
|
230
|
+
result.push(element);
|
|
231
|
+
state.atLeadingEdge = false;
|
|
232
|
+
}
|
|
233
|
+
return changed ? result : elements;
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* Preprocesses a locale-resolved Neo document, dropping lead content that
|
|
237
|
+
* duplicates the host page's own header. Non-mutating: returns the input
|
|
238
|
+
* unchanged (same reference) when there is nothing to do, otherwise a new
|
|
239
|
+
* document with a new `sections` array (untouched sections/elements may be
|
|
240
|
+
* reused by reference).
|
|
241
|
+
*/
|
|
242
|
+
function trimNeoLead(document, options) {
|
|
243
|
+
const sections = Array.isArray(document.sections) ? document.sections : [];
|
|
244
|
+
if (sections.length === 0) {
|
|
245
|
+
return document;
|
|
246
|
+
}
|
|
247
|
+
const dedupeTitle = options.dedupeTitle;
|
|
248
|
+
const hasDedupeTitle = typeof dedupeTitle === 'string' && dedupeTitle.trim() !== '';
|
|
249
|
+
if (!options.trimLeadImage && !hasDedupeTitle) {
|
|
250
|
+
return document;
|
|
251
|
+
}
|
|
252
|
+
const state = {
|
|
253
|
+
atLeadingEdge: true,
|
|
254
|
+
dropLeadingImage: options.trimLeadImage,
|
|
255
|
+
normalizedTitle: hasDedupeTitle ? normalizeText(dedupeTitle) : null,
|
|
256
|
+
};
|
|
257
|
+
const newSections = [];
|
|
258
|
+
for (const section of sections) {
|
|
259
|
+
const elements = Array.isArray(section.elements) ? section.elements : [];
|
|
260
|
+
const newElements = trimElements(elements, state);
|
|
261
|
+
if (newElements.length === 0) {
|
|
262
|
+
// An empty section must not survive — this is what removes a
|
|
263
|
+
// background-only hero section once its sole image is trimmed.
|
|
264
|
+
continue;
|
|
265
|
+
}
|
|
266
|
+
newSections.push(newElements === elements ? section : Object.assign(Object.assign({}, section), { elements: newElements }));
|
|
267
|
+
}
|
|
268
|
+
return Object.assign(Object.assign({}, document), { sections: newSections });
|
|
269
|
+
}
|
|
270
|
+
|
|
165
271
|
/**
|
|
166
272
|
* news-neo-renderer.ts
|
|
167
273
|
*
|
|
@@ -1301,12 +1407,14 @@ const AicoNeoContent = /*@__PURE__*/ proxyCustomElement(class AicoNeoContent ext
|
|
|
1301
1407
|
this.neoDocument = undefined;
|
|
1302
1408
|
this.locale = 'de';
|
|
1303
1409
|
this.defaultLocale = undefined;
|
|
1410
|
+
this.trimLeadImage = false;
|
|
1411
|
+
this.dedupeTitle = undefined;
|
|
1304
1412
|
}
|
|
1305
1413
|
componentWillLoad() {
|
|
1306
1414
|
this.prepareHtml();
|
|
1307
1415
|
}
|
|
1308
1416
|
prepareHtml() {
|
|
1309
|
-
var _a;
|
|
1417
|
+
var _a, _b;
|
|
1310
1418
|
if (!neoDocumentHasContent(this.neoDocument)) {
|
|
1311
1419
|
this.renderedHtml = '';
|
|
1312
1420
|
return;
|
|
@@ -1315,6 +1423,13 @@ const AicoNeoContent = /*@__PURE__*/ proxyCustomElement(class AicoNeoContent ext
|
|
|
1315
1423
|
if (hasLocaleStructure(resolvedDocument)) {
|
|
1316
1424
|
resolvedDocument = resolveLocale(resolvedDocument, this.locale, (_a = this.defaultLocale) !== null && _a !== void 0 ? _a : null);
|
|
1317
1425
|
}
|
|
1426
|
+
if (this.trimLeadImage || this.dedupeTitle) {
|
|
1427
|
+
resolvedDocument = trimNeoLead(resolvedDocument, { trimLeadImage: this.trimLeadImage, dedupeTitle: (_b = this.dedupeTitle) !== null && _b !== void 0 ? _b : null });
|
|
1428
|
+
if (resolvedDocument.sections.length === 0) {
|
|
1429
|
+
this.renderedHtml = '';
|
|
1430
|
+
return;
|
|
1431
|
+
}
|
|
1432
|
+
}
|
|
1318
1433
|
setActiveLocale(this.locale);
|
|
1319
1434
|
this.renderedHtml = NewsNeo.render({ contentBuilderNeoJson: resolvedDocument });
|
|
1320
1435
|
}
|
|
@@ -1326,23 +1441,29 @@ const AicoNeoContent = /*@__PURE__*/ proxyCustomElement(class AicoNeoContent ext
|
|
|
1326
1441
|
}
|
|
1327
1442
|
}
|
|
1328
1443
|
render() {
|
|
1329
|
-
return (h(Host, { key: '
|
|
1444
|
+
return (h(Host, { key: '663be625008bd9444656dfedd24cfe9fa97e7d43' }, h("div", { key: 'f0827191bf2ccc6d8cb35644103aa558d338382f', class: "aico-neo-content-mount", innerHTML: this.renderedHtml })));
|
|
1330
1445
|
}
|
|
1331
1446
|
get host() { return this; }
|
|
1332
1447
|
static get watchers() { return {
|
|
1333
1448
|
"neoDocument": ["prepareHtml"],
|
|
1334
1449
|
"locale": ["prepareHtml"],
|
|
1335
|
-
"defaultLocale": ["prepareHtml"]
|
|
1450
|
+
"defaultLocale": ["prepareHtml"],
|
|
1451
|
+
"trimLeadImage": ["prepareHtml"],
|
|
1452
|
+
"dedupeTitle": ["prepareHtml"]
|
|
1336
1453
|
}; }
|
|
1337
1454
|
static get style() { return AicoNeoContentStyle0; }
|
|
1338
1455
|
}, [0, "aico-neo-content", {
|
|
1339
1456
|
"neoDocument": [16],
|
|
1340
1457
|
"locale": [1],
|
|
1341
|
-
"defaultLocale": [1, "default-locale"]
|
|
1458
|
+
"defaultLocale": [1, "default-locale"],
|
|
1459
|
+
"trimLeadImage": [4, "trim-lead-image"],
|
|
1460
|
+
"dedupeTitle": [1, "dedupe-title"]
|
|
1342
1461
|
}, undefined, {
|
|
1343
1462
|
"neoDocument": ["prepareHtml"],
|
|
1344
1463
|
"locale": ["prepareHtml"],
|
|
1345
|
-
"defaultLocale": ["prepareHtml"]
|
|
1464
|
+
"defaultLocale": ["prepareHtml"],
|
|
1465
|
+
"trimLeadImage": ["prepareHtml"],
|
|
1466
|
+
"dedupeTitle": ["prepareHtml"]
|
|
1346
1467
|
}]);
|
|
1347
1468
|
function defineCustomElement() {
|
|
1348
1469
|
if (typeof customElements === "undefined") {
|