@rulecms/widget-angular 0.5.0 → 0.7.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/fesm2022/rulecms-widget-angular.mjs +1465 -186
- package/fesm2022/rulecms-widget-angular.mjs.map +1 -1
- package/lib/helpers/get-component-attributes-and-styles.d.ts.map +1 -1
- package/lib/project-css-classes/format-project-css-classes-stylesheet.d.ts +23 -0
- package/lib/project-css-classes/format-project-css-classes-stylesheet.d.ts.map +1 -0
- package/lib/project-css-classes/include-project-css-classes-on-published-widget.d.ts +7 -0
- package/lib/project-css-classes/include-project-css-classes-on-published-widget.d.ts.map +1 -0
- package/lib/project-css-classes/include-project-css-layers-on-published-widget.d.ts +6 -0
- package/lib/project-css-classes/include-project-css-layers-on-published-widget.d.ts.map +1 -0
- package/lib/project-css-classes/project-css-classes-stylesheet.component.d.ts +15 -0
- package/lib/project-css-classes/project-css-classes-stylesheet.component.d.ts.map +1 -0
- package/lib/project-css-fonts/format-project-css-fonts-stylesheet.d.ts +34 -0
- package/lib/project-css-fonts/format-project-css-fonts-stylesheet.d.ts.map +1 -0
- package/lib/project-css-fonts/include-project-css-fonts-on-published-widget.d.ts +6 -0
- package/lib/project-css-fonts/include-project-css-fonts-on-published-widget.d.ts.map +1 -0
- package/lib/project-css-fonts/project-css-fonts-stylesheet.component.d.ts +16 -0
- package/lib/project-css-fonts/project-css-fonts-stylesheet.component.d.ts.map +1 -0
- package/lib/project-css-keyframes/format-project-css-keyframes-stylesheet.d.ts +11 -0
- package/lib/project-css-keyframes/format-project-css-keyframes-stylesheet.d.ts.map +1 -0
- package/lib/project-css-keyframes/include-project-css-keyframes-on-published-widget.d.ts +6 -0
- package/lib/project-css-keyframes/include-project-css-keyframes-on-published-widget.d.ts.map +1 -0
- package/lib/project-css-keyframes/project-css-keyframes-stylesheet.component.d.ts +14 -0
- package/lib/project-css-keyframes/project-css-keyframes-stylesheet.component.d.ts.map +1 -0
- package/lib/project-css-position-try/format-project-css-position-try-stylesheet.d.ts +11 -0
- package/lib/project-css-position-try/format-project-css-position-try-stylesheet.d.ts.map +1 -0
- package/lib/project-css-position-try/include-project-css-position-try-on-published-widget.d.ts +6 -0
- package/lib/project-css-position-try/include-project-css-position-try-on-published-widget.d.ts.map +1 -0
- package/lib/project-css-position-try/project-css-position-try-stylesheet.component.d.ts +14 -0
- package/lib/project-css-position-try/project-css-position-try-stylesheet.component.d.ts.map +1 -0
- package/lib/project-css-properties/format-project-css-properties-stylesheet.d.ts +15 -0
- package/lib/project-css-properties/format-project-css-properties-stylesheet.d.ts.map +1 -0
- package/lib/project-css-properties/include-project-css-properties-on-published-widget.d.ts +6 -0
- package/lib/project-css-properties/include-project-css-properties-on-published-widget.d.ts.map +1 -0
- package/lib/project-css-properties/project-css-properties-stylesheet.component.d.ts +14 -0
- package/lib/project-css-properties/project-css-properties-stylesheet.component.d.ts.map +1 -0
- package/lib/project-css-themes/format-project-css-themes-stylesheet.d.ts +24 -0
- package/lib/project-css-themes/format-project-css-themes-stylesheet.d.ts.map +1 -0
- package/lib/project-css-themes/include-project-css-themes-on-published-widget.d.ts +6 -0
- package/lib/project-css-themes/include-project-css-themes-on-published-widget.d.ts.map +1 -0
- package/lib/project-css-themes/project-css-themes-stylesheet.component.d.ts +14 -0
- package/lib/project-css-themes/project-css-themes-stylesheet.component.d.ts.map +1 -0
- package/lib/project-css-variables/format-project-css-variables-stylesheet.d.ts +1 -1
- package/lib/project-css-variables/format-project-css-variables-stylesheet.d.ts.map +1 -1
- package/lib/project-css-variables/include-project-css-variables-on-published-widget.d.ts +4 -6
- package/lib/project-css-variables/include-project-css-variables-on-published-widget.d.ts.map +1 -1
- package/lib/project-css-widget-chrome/format-project-css-widget-chrome-stylesheet.d.ts +19 -0
- package/lib/project-css-widget-chrome/format-project-css-widget-chrome-stylesheet.d.ts.map +1 -0
- package/lib/project-css-widget-chrome/include-project-css-widget-chrome-on-published-widget.d.ts +6 -0
- package/lib/project-css-widget-chrome/include-project-css-widget-chrome-on-published-widget.d.ts.map +1 -0
- package/lib/project-css-widget-chrome/project-css-widget-chrome-stylesheet.component.d.ts +14 -0
- package/lib/project-css-widget-chrome/project-css-widget-chrome-stylesheet.component.d.ts.map +1 -0
- package/lib/widget/prepare-rule-cms-widget-data.d.ts.map +1 -1
- package/lib/widget/rule-cms-widget.component.d.ts.map +1 -1
- package/lib/widget/widget-data.types.d.ts +110 -13
- package/lib/widget/widget-data.types.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -1707,9 +1707,20 @@ function getComponentAttributesAndStyles({ col, deviceDisplayType, isComposeMode
|
|
|
1707
1707
|
break;
|
|
1708
1708
|
}
|
|
1709
1709
|
}
|
|
1710
|
+
const stylesForDevice = deriveDisplayFlexIfNeeded(componentStyles);
|
|
1711
|
+
// `pointer-events: none` would leave the author unable to click the column
|
|
1712
|
+
// to select it. Preview and published renders apply the authored value.
|
|
1713
|
+
if (isComposeMode && stylesForDevice.pointerEvents !== undefined) {
|
|
1714
|
+
const rest = { ...stylesForDevice };
|
|
1715
|
+
delete rest.pointerEvents;
|
|
1716
|
+
return {
|
|
1717
|
+
componentAttributesBasedOnDevice,
|
|
1718
|
+
componentStyles: rest,
|
|
1719
|
+
};
|
|
1720
|
+
}
|
|
1710
1721
|
return {
|
|
1711
1722
|
componentAttributesBasedOnDevice,
|
|
1712
|
-
componentStyles:
|
|
1723
|
+
componentStyles: stylesForDevice,
|
|
1713
1724
|
};
|
|
1714
1725
|
}
|
|
1715
1726
|
|
|
@@ -3374,259 +3385,1462 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.25", ngImpo
|
|
|
3374
3385
|
}] } });
|
|
3375
3386
|
|
|
3376
3387
|
/**
|
|
3377
|
-
*
|
|
3378
|
-
*
|
|
3379
|
-
*
|
|
3380
|
-
* TODO: project setting — the customer turns this off if the host stylesheet
|
|
3381
|
-
* already defines these tokens. Hardcoded on for this iteration.
|
|
3388
|
+
* Missing/undefined on a widget GET payload means include — the default, and
|
|
3389
|
+
* the shape older clients already understand. Only an explicit `false` turns
|
|
3390
|
+
* emission off, even if `classDefinitions` is still present on the payload.
|
|
3382
3391
|
*/
|
|
3383
|
-
|
|
3392
|
+
function shouldIncludeClassDefinitionsOnPublishedWidget(includeClassDefinitions) {
|
|
3393
|
+
return includeClassDefinitions !== false;
|
|
3394
|
+
}
|
|
3384
3395
|
|
|
3396
|
+
const PROJECT_CSS_CLASS_LAYERS = ['utilities', 'components'];
|
|
3397
|
+
const CLASS_LAYER_SET = new Set(PROJECT_CSS_CLASS_LAYERS);
|
|
3398
|
+
const isProjectCssClassLayer = (value) => typeof value === 'string' && CLASS_LAYER_SET.has(value);
|
|
3399
|
+
const indentCssBlock = (css) => css
|
|
3400
|
+
.split('\n')
|
|
3401
|
+
.map(line => (line.length > 0 ? ` ${line}` : line))
|
|
3402
|
+
.join('\n');
|
|
3403
|
+
/**
|
|
3404
|
+
* Wrap an already-formatted class stylesheet. Null in stays null. Unknown or
|
|
3405
|
+
* omitted layer names leave the stylesheet unlayered.
|
|
3406
|
+
*/
|
|
3407
|
+
const wrapProjectCssClassesStylesheetInLayer = (css, classLayer) => {
|
|
3408
|
+
if (!css) {
|
|
3409
|
+
return null;
|
|
3410
|
+
}
|
|
3411
|
+
if (!isProjectCssClassLayer(classLayer)) {
|
|
3412
|
+
return css;
|
|
3413
|
+
}
|
|
3414
|
+
return `@layer ${classLayer} {\n${indentCssBlock(css)}\n}`;
|
|
3415
|
+
};
|
|
3385
3416
|
/**
|
|
3386
3417
|
* Attribute-selector escape so a published key cannot break out of
|
|
3387
3418
|
* `[data-rulecms-published-key="…"]`. `CSS.escape` is not assumed (SSR / Node).
|
|
3388
3419
|
*/
|
|
3389
|
-
const escapeCssAttributeValue = (value) => value.replace(/\\/g, '\\\\').replace(/"/g, '\\"');
|
|
3390
|
-
|
|
3391
|
-
const
|
|
3392
|
-
|
|
3420
|
+
const escapeCssAttributeValue$2 = (value) => value.replace(/\\/g, '\\\\').replace(/"/g, '\\"');
|
|
3421
|
+
/** Escape a class name for use after `.` (`/` → `\/`). */
|
|
3422
|
+
const escapeCssClassName = (name) => name.replace(/[^A-Za-z0-9_-]/g, char => `\\${char}`);
|
|
3423
|
+
const REJECTED_IN_BODY = ['</', '<script', '@import', 'javascript:', 'vbscript:', 'expression('];
|
|
3424
|
+
// eslint-disable-next-line no-control-regex -- control characters are what this matches
|
|
3425
|
+
const REJECTED_CONTROL_CHARACTERS$2 = /[\u0000-\u0008\u000b\u000c\u000e-\u001f\u007f]/;
|
|
3426
|
+
const DISALLOWED_IN_NAME = /[\s{};"]/;
|
|
3427
|
+
const ALLOWED_NAME$2 = /^[A-Za-z0-9_:%./[\]%-]+$/;
|
|
3428
|
+
const isBraceBalanced$1 = (value) => {
|
|
3429
|
+
let depth = 0;
|
|
3430
|
+
for (const char of value) {
|
|
3431
|
+
if (char === '{') {
|
|
3432
|
+
depth += 1;
|
|
3433
|
+
}
|
|
3434
|
+
else if (char === '}') {
|
|
3435
|
+
depth -= 1;
|
|
3436
|
+
if (depth < 0) {
|
|
3437
|
+
return false;
|
|
3438
|
+
}
|
|
3439
|
+
}
|
|
3440
|
+
}
|
|
3441
|
+
return depth === 0;
|
|
3442
|
+
};
|
|
3443
|
+
const isCssClassName = (value) => {
|
|
3444
|
+
const name = value.startsWith('.') ? value.slice(1) : value;
|
|
3445
|
+
if (!name || name.length > 200 || name.startsWith('.') || DISALLOWED_IN_NAME.test(name)) {
|
|
3446
|
+
return false;
|
|
3447
|
+
}
|
|
3448
|
+
return ALLOWED_NAME$2.test(name);
|
|
3449
|
+
};
|
|
3450
|
+
const isCssClassDeclarationBody = (value) => {
|
|
3451
|
+
const trimmed = value.trim();
|
|
3452
|
+
if (!trimmed || trimmed.length > 4000) {
|
|
3453
|
+
return false;
|
|
3454
|
+
}
|
|
3455
|
+
if (REJECTED_CONTROL_CHARACTERS$2.test(trimmed) || !isBraceBalanced$1(trimmed)) {
|
|
3456
|
+
return false;
|
|
3457
|
+
}
|
|
3458
|
+
const lowered = trimmed.toLowerCase();
|
|
3459
|
+
return !REJECTED_IN_BODY.some(rejected => lowered.includes(rejected));
|
|
3460
|
+
};
|
|
3461
|
+
const sanitizeForStylesheet$1 = (classes) => {
|
|
3462
|
+
if (!classes) {
|
|
3393
3463
|
return {};
|
|
3394
3464
|
}
|
|
3395
3465
|
const sanitized = {};
|
|
3396
|
-
for (const [rawName, rawValue] of Object.entries(
|
|
3397
|
-
|
|
3466
|
+
for (const [rawName, rawValue] of Object.entries(classes)) {
|
|
3467
|
+
const name = rawName.startsWith('.') ? rawName.slice(1) : rawName.trim();
|
|
3468
|
+
if (!isCssClassName(name) || typeof rawValue !== 'string') {
|
|
3398
3469
|
continue;
|
|
3399
3470
|
}
|
|
3400
3471
|
const value = rawValue.trim();
|
|
3401
|
-
if (
|
|
3472
|
+
if (!isCssClassDeclarationBody(value)) {
|
|
3402
3473
|
continue;
|
|
3403
3474
|
}
|
|
3404
|
-
sanitized[
|
|
3475
|
+
sanitized[name] = value;
|
|
3405
3476
|
}
|
|
3406
3477
|
return sanitized;
|
|
3407
3478
|
};
|
|
3479
|
+
const indentDeclarationBody$1 = (body) => body
|
|
3480
|
+
.split('\n')
|
|
3481
|
+
.map(line => ` ${line}`)
|
|
3482
|
+
.join('\n');
|
|
3408
3483
|
/**
|
|
3409
|
-
*
|
|
3410
|
-
*
|
|
3411
|
-
* the caller omits the `<style>` tag.
|
|
3484
|
+
* Descendant class rules under this widget’s published-key span.
|
|
3485
|
+
* Empty / flag-off / unsanitary catalogs return null so the caller omits `<style>`.
|
|
3412
3486
|
*/
|
|
3413
|
-
const
|
|
3414
|
-
if (!
|
|
3487
|
+
const formatProjectCssClassesStylesheet = (publishedKey, classes, includeClassDefinitions, classLayer) => {
|
|
3488
|
+
if (!shouldIncludeClassDefinitionsOnPublishedWidget(includeClassDefinitions)) {
|
|
3415
3489
|
return null;
|
|
3416
3490
|
}
|
|
3417
|
-
const sanitized = sanitizeForStylesheet(
|
|
3491
|
+
const sanitized = sanitizeForStylesheet$1(classes);
|
|
3418
3492
|
const names = Object.keys(sanitized);
|
|
3419
3493
|
if (names.length === 0 || !publishedKey) {
|
|
3420
3494
|
return null;
|
|
3421
3495
|
}
|
|
3422
|
-
const
|
|
3423
|
-
const
|
|
3496
|
+
const ancestor = `[data-rulecms-published-key="${escapeCssAttributeValue$2(publishedKey)}"]`;
|
|
3497
|
+
const css = names
|
|
3424
3498
|
.sort((left, right) => left.localeCompare(right))
|
|
3425
|
-
.map(
|
|
3499
|
+
.map(name => `${ancestor} .${escapeCssClassName(name)} {\n${indentDeclarationBody$1(sanitized[name])}\n}`)
|
|
3426
3500
|
.join('\n');
|
|
3427
|
-
return
|
|
3501
|
+
return wrapProjectCssClassesStylesheetInLayer(css, classLayer);
|
|
3428
3502
|
};
|
|
3503
|
+
const formatProjectCssClassesStylesheetInLayer = (publishedKey, classes, classLayer, includeClassDefinitions) => formatProjectCssClassesStylesheet(publishedKey, classes, includeClassDefinitions, classLayer);
|
|
3429
3504
|
|
|
3430
3505
|
/**
|
|
3431
|
-
* Emits one scoped `<style data-rulecms-project-
|
|
3506
|
+
* Emits one scoped `<style data-rulecms-project-class-definitions>` from the
|
|
3432
3507
|
* project catalog, or nothing when the catalog is empty / unsanitary.
|
|
3433
3508
|
*/
|
|
3434
|
-
class
|
|
3509
|
+
class ProjectCssClassesStylesheetComponent {
|
|
3435
3510
|
get css() {
|
|
3436
|
-
return
|
|
3511
|
+
return formatProjectCssClassesStylesheet(this.publishedKey, this.classes, undefined, this.classLayer);
|
|
3437
3512
|
}
|
|
3438
|
-
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type:
|
|
3439
|
-
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "19.2.25", type:
|
|
3513
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: ProjectCssClassesStylesheetComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
|
|
3514
|
+
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "19.2.25", type: ProjectCssClassesStylesheetComponent, isStandalone: true, selector: "rulecms-project-css-classes-stylesheet", inputs: { publishedKey: "publishedKey", classes: "classes", classLayer: "classLayer" }, ngImport: i0, template: `
|
|
3440
3515
|
@if (css) {
|
|
3441
|
-
<style data-rulecms-project-
|
|
3516
|
+
<style data-rulecms-project-class-definitions="" [innerText]="css"></style>
|
|
3442
3517
|
}
|
|
3443
3518
|
`, isInline: true }); }
|
|
3444
3519
|
}
|
|
3445
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type:
|
|
3520
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: ProjectCssClassesStylesheetComponent, decorators: [{
|
|
3446
3521
|
type: Component,
|
|
3447
3522
|
args: [{
|
|
3448
|
-
selector: 'rulecms-project-css-
|
|
3523
|
+
selector: 'rulecms-project-css-classes-stylesheet',
|
|
3449
3524
|
standalone: true,
|
|
3450
3525
|
template: `
|
|
3451
3526
|
@if (css) {
|
|
3452
|
-
<style data-rulecms-project-
|
|
3527
|
+
<style data-rulecms-project-class-definitions="" [innerText]="css"></style>
|
|
3453
3528
|
}
|
|
3454
3529
|
`,
|
|
3455
3530
|
}]
|
|
3456
3531
|
}], propDecorators: { publishedKey: [{
|
|
3457
3532
|
type: Input,
|
|
3458
3533
|
args: [{ required: true }]
|
|
3459
|
-
}],
|
|
3534
|
+
}], classes: [{
|
|
3535
|
+
type: Input
|
|
3536
|
+
}], classLayer: [{
|
|
3460
3537
|
type: Input
|
|
3461
3538
|
}] } });
|
|
3462
3539
|
|
|
3463
|
-
|
|
3464
|
-
|
|
3465
|
-
|
|
3466
|
-
|
|
3467
|
-
|
|
3468
|
-
|
|
3469
|
-
collectionToUse.collectionRows =
|
|
3470
|
-
typeof collectionToUse.itemList === 'string'
|
|
3471
|
-
? JSON.parse(collectionToUse.itemList)
|
|
3472
|
-
: collectionToUse.itemList;
|
|
3473
|
-
}
|
|
3474
|
-
catch (error) {
|
|
3475
|
-
console.error(`Failed to parse itemList for collection ${key}:`, error);
|
|
3476
|
-
collectionToUse.collectionRows = { rows: [] };
|
|
3477
|
-
}
|
|
3478
|
-
}
|
|
3479
|
-
let collectionKey = `${collectionToUse.name}$${key}`;
|
|
3480
|
-
if (collectionToUse.parentId) {
|
|
3481
|
-
collectionKey = `${collectionKey}@${collectionToUse.parentId}`;
|
|
3482
|
-
}
|
|
3483
|
-
transformed[collectionKey] = collectionToUse;
|
|
3484
|
-
});
|
|
3485
|
-
return transformed;
|
|
3486
|
-
}
|
|
3487
|
-
function parseDisplayItemList(widget) {
|
|
3488
|
-
return typeof widget.itemList === 'string'
|
|
3489
|
-
? JSON.parse(widget.itemList)
|
|
3490
|
-
: widget.itemList;
|
|
3491
|
-
}
|
|
3492
|
-
/** Transform raw widget API data into render-ready displayItemList + collections. */
|
|
3493
|
-
function prepareRuleCMSWidgetData(raw) {
|
|
3494
|
-
return {
|
|
3495
|
-
displayItemList: parseDisplayItemList(raw.widget),
|
|
3496
|
-
widgetCollections: transformChildCollections(raw.childCollections),
|
|
3497
|
-
...(raw.libraries ? { libraries: raw.libraries } : {}),
|
|
3498
|
-
...(raw.cssVariables && Object.keys(raw.cssVariables).length > 0
|
|
3499
|
-
? { cssVariables: raw.cssVariables }
|
|
3500
|
-
: {}),
|
|
3501
|
-
};
|
|
3502
|
-
}
|
|
3503
|
-
|
|
3504
|
-
function resolveSourceComponentsPluginSync(params) {
|
|
3505
|
-
const registry = params.registry ?? createComponentLibraryRegistry();
|
|
3506
|
-
const referenced = collectReferencedLibraryIds({
|
|
3507
|
-
displayItemList: params.displayItemList,
|
|
3508
|
-
widgetCollections: params.widgetCollections,
|
|
3509
|
-
});
|
|
3510
|
-
return registry.resolveSync({ registrations: params.libraries, referenced });
|
|
3511
|
-
}
|
|
3512
|
-
function resolveSourceComponentsPlugin(params) {
|
|
3513
|
-
const registry = params.registry ?? createComponentLibraryRegistry();
|
|
3514
|
-
const referenced = collectReferencedLibraryIds({
|
|
3515
|
-
displayItemList: params.displayItemList,
|
|
3516
|
-
widgetCollections: params.widgetCollections,
|
|
3517
|
-
});
|
|
3518
|
-
return registry.resolve({ registrations: params.libraries, referenced });
|
|
3540
|
+
/**
|
|
3541
|
+
* Missing/undefined on a widget GET payload means include. Only an explicit
|
|
3542
|
+
* `false` turns emission off, even if `fontFaces` is still present.
|
|
3543
|
+
*/
|
|
3544
|
+
function shouldIncludeFontFacesOnPublishedWidget(includeFontFaces) {
|
|
3545
|
+
return includeFontFaces !== false;
|
|
3519
3546
|
}
|
|
3520
3547
|
|
|
3521
|
-
const
|
|
3522
|
-
|
|
3523
|
-
|
|
3524
|
-
|
|
3525
|
-
|
|
3526
|
-
|
|
3548
|
+
const escapeCssAttributeValue$1 = (value) => value.replace(/\\/g, '\\\\').replace(/"/g, '\\"');
|
|
3549
|
+
const GENERIC_FAMILIES = new Set([
|
|
3550
|
+
'serif',
|
|
3551
|
+
'sans-serif',
|
|
3552
|
+
'monospace',
|
|
3553
|
+
'cursive',
|
|
3554
|
+
'fantasy',
|
|
3555
|
+
'system-ui',
|
|
3556
|
+
'ui-sans-serif',
|
|
3557
|
+
'ui-serif',
|
|
3558
|
+
'ui-monospace',
|
|
3559
|
+
'ui-rounded',
|
|
3560
|
+
'emoji',
|
|
3561
|
+
'math',
|
|
3562
|
+
'fangsong',
|
|
3563
|
+
]);
|
|
3564
|
+
const IDENT = /^[a-zA-Z_\u00A0-\uFFFF-][a-zA-Z0-9_\u00A0-\uFFFF-]*$/;
|
|
3565
|
+
const REJECTED = /url\(|@|[{};\\<>]|javascript:/i;
|
|
3566
|
+
const REJECTED_COLOR = /url\(|@|[{};\\<>]|javascript:|expression\(/i;
|
|
3567
|
+
const PALETTE_NAME = /^--[A-Za-z_][\w-]*$/;
|
|
3568
|
+
const GOOGLE_FAMILY = /^[A-Za-z0-9 ]+$/;
|
|
3569
|
+
const GOOGLE_WEIGHTS = new Set([100, 200, 300, 400, 500, 600, 700, 800, 900]);
|
|
3570
|
+
const MAX_PALETTES_PER_FACE = 4;
|
|
3571
|
+
const MAX_PALETTE_OVERRIDE_COLORS = 8;
|
|
3572
|
+
const MAX_PALETTE_COLOR_INDEX = 255;
|
|
3573
|
+
const quoteCssFontFamily = (name) => {
|
|
3574
|
+
if (GENERIC_FAMILIES.has(name.toLowerCase()) || IDENT.test(name)) {
|
|
3575
|
+
return name;
|
|
3576
|
+
}
|
|
3577
|
+
return `"${name.replace(/\\/g, '\\\\').replace(/"/g, '\\"')}"`;
|
|
3527
3578
|
};
|
|
3528
|
-
const
|
|
3529
|
-
|
|
3530
|
-
|
|
3531
|
-
|
|
3579
|
+
const isSafeFamily = (value) => typeof value === 'string' &&
|
|
3580
|
+
value.trim() !== '' &&
|
|
3581
|
+
value.trim().length <= 80 &&
|
|
3582
|
+
!value.includes(',') &&
|
|
3583
|
+
!REJECTED.test(value);
|
|
3584
|
+
const isSafePaletteName = (value) => typeof value === 'string' &&
|
|
3585
|
+
PALETTE_NAME.test(value.trim()) &&
|
|
3586
|
+
value.trim().length <= 80;
|
|
3587
|
+
const isSafePaletteColor = (value) => typeof value === 'string' &&
|
|
3588
|
+
value.trim() !== '' &&
|
|
3589
|
+
value.trim().length <= 400 &&
|
|
3590
|
+
!REJECTED_COLOR.test(value);
|
|
3591
|
+
const parsePaletteColorIndex = (value) => {
|
|
3592
|
+
if (typeof value !== 'number' || !Number.isInteger(value) || value < 0 || value > MAX_PALETTE_COLOR_INDEX) {
|
|
3593
|
+
return null;
|
|
3594
|
+
}
|
|
3595
|
+
return value;
|
|
3532
3596
|
};
|
|
3533
|
-
const
|
|
3534
|
-
|
|
3535
|
-
|
|
3536
|
-
|
|
3537
|
-
|
|
3538
|
-
|
|
3539
|
-
|
|
3597
|
+
const sanitizePalettes = (raw, seenNames, hasDefaultPalette) => {
|
|
3598
|
+
if (!Array.isArray(raw)) {
|
|
3599
|
+
return [];
|
|
3600
|
+
}
|
|
3601
|
+
const palettes = [];
|
|
3602
|
+
for (const item of raw) {
|
|
3603
|
+
if (!item || typeof item !== 'object' || palettes.length >= MAX_PALETTES_PER_FACE) {
|
|
3604
|
+
continue;
|
|
3605
|
+
}
|
|
3606
|
+
const record = item;
|
|
3607
|
+
if (!isSafePaletteName(record.name)) {
|
|
3608
|
+
continue;
|
|
3609
|
+
}
|
|
3610
|
+
const name = record.name.trim();
|
|
3611
|
+
if (seenNames.has(name)) {
|
|
3612
|
+
continue;
|
|
3613
|
+
}
|
|
3614
|
+
const overrideColors = [];
|
|
3615
|
+
const seenIndexes = new Set();
|
|
3616
|
+
for (const color of record.overrideColors ?? []) {
|
|
3617
|
+
if (overrideColors.length >= MAX_PALETTE_OVERRIDE_COLORS) {
|
|
3618
|
+
break;
|
|
3619
|
+
}
|
|
3620
|
+
const index = parsePaletteColorIndex(color?.index);
|
|
3621
|
+
if (index === null || seenIndexes.has(index) || !isSafePaletteColor(color?.color)) {
|
|
3622
|
+
continue;
|
|
3623
|
+
}
|
|
3624
|
+
seenIndexes.add(index);
|
|
3625
|
+
overrideColors.push({ index, color: color.color.trim() });
|
|
3626
|
+
}
|
|
3627
|
+
overrideColors.sort((left, right) => left.index - right.index);
|
|
3628
|
+
const applyToWidget = record.applyToWidget === true && !hasDefaultPalette.current;
|
|
3629
|
+
if (applyToWidget) {
|
|
3630
|
+
hasDefaultPalette.current = true;
|
|
3631
|
+
}
|
|
3632
|
+
seenNames.add(name);
|
|
3633
|
+
palettes.push({
|
|
3634
|
+
name,
|
|
3635
|
+
...(overrideColors.length > 0 ? { overrideColors } : {}),
|
|
3636
|
+
...(applyToWidget ? { applyToWidget: true } : {}),
|
|
3637
|
+
});
|
|
3638
|
+
}
|
|
3639
|
+
return palettes;
|
|
3540
3640
|
};
|
|
3541
|
-
const
|
|
3542
|
-
|
|
3543
|
-
|
|
3544
|
-
|
|
3545
|
-
|
|
3546
|
-
|
|
3641
|
+
const sanitizeProjectFontFaces = (fonts) => {
|
|
3642
|
+
if (!Array.isArray(fonts)) {
|
|
3643
|
+
return [];
|
|
3644
|
+
}
|
|
3645
|
+
const sanitized = [];
|
|
3646
|
+
const seen = new Set();
|
|
3647
|
+
const seenPaletteNames = new Set();
|
|
3648
|
+
const hasDefaultPalette = { current: false };
|
|
3649
|
+
let hasDefault = false;
|
|
3650
|
+
for (const raw of fonts) {
|
|
3651
|
+
if (!raw || !isSafeFamily(raw.family)) {
|
|
3652
|
+
continue;
|
|
3653
|
+
}
|
|
3654
|
+
const family = raw.family.trim();
|
|
3655
|
+
const key = family.toLowerCase();
|
|
3656
|
+
if (seen.has(key) || sanitized.length >= 12) {
|
|
3657
|
+
continue;
|
|
3658
|
+
}
|
|
3659
|
+
const fallbacks = (raw.fallbacks ?? []).filter(isSafeFamily).slice(0, 8);
|
|
3660
|
+
const cssVariable = typeof raw.cssVariable === 'string' && isCssVariableName(raw.cssVariable.trim())
|
|
3661
|
+
? raw.cssVariable.trim()
|
|
3662
|
+
: undefined;
|
|
3663
|
+
let source = { kind: 'stack-only' };
|
|
3664
|
+
if (raw.source?.kind === 'google') {
|
|
3665
|
+
if (!GOOGLE_FAMILY.test(family)) {
|
|
3666
|
+
continue;
|
|
3667
|
+
}
|
|
3668
|
+
const rawWeights = Array.isArray(raw.source.weights)
|
|
3669
|
+
? raw.source.weights
|
|
3670
|
+
: [];
|
|
3671
|
+
const weights = rawWeights
|
|
3672
|
+
.filter((weight) => typeof weight === 'number' && GOOGLE_WEIGHTS.has(weight))
|
|
3673
|
+
.filter((weight, index, list) => list.indexOf(weight) === index)
|
|
3674
|
+
.sort((left, right) => left - right);
|
|
3675
|
+
if (weights.length === 0) {
|
|
3676
|
+
continue;
|
|
3677
|
+
}
|
|
3678
|
+
source = { kind: 'google', weights };
|
|
3679
|
+
}
|
|
3680
|
+
seen.add(key);
|
|
3681
|
+
const applyToWidget = raw.applyToWidget === true && !hasDefault;
|
|
3682
|
+
if (applyToWidget) {
|
|
3683
|
+
hasDefault = true;
|
|
3684
|
+
}
|
|
3685
|
+
const palettes = sanitizePalettes(raw.palettes, seenPaletteNames, hasDefaultPalette);
|
|
3686
|
+
sanitized.push({
|
|
3687
|
+
family,
|
|
3688
|
+
...(cssVariable ? { cssVariable } : {}),
|
|
3689
|
+
fallbacks,
|
|
3690
|
+
applyToWidget,
|
|
3691
|
+
source,
|
|
3692
|
+
...(palettes.length > 0 ? { palettes } : {}),
|
|
3693
|
+
});
|
|
3694
|
+
}
|
|
3695
|
+
return sanitized;
|
|
3547
3696
|
};
|
|
3548
|
-
const
|
|
3549
|
-
|
|
3550
|
-
|
|
3551
|
-
|
|
3552
|
-
|
|
3697
|
+
const buildGoogleFontsCssHref = (fonts) => {
|
|
3698
|
+
const families = sanitizeProjectFontFaces(fonts)
|
|
3699
|
+
.filter(font => font.source.kind === 'google')
|
|
3700
|
+
.map(font => {
|
|
3701
|
+
const weights = font.source.kind === 'google' ? font.source.weights.join(';') : '400';
|
|
3702
|
+
return `family=${font.family.replace(/ /g, '+')}:wght@${weights}`;
|
|
3703
|
+
});
|
|
3704
|
+
if (families.length === 0) {
|
|
3705
|
+
return null;
|
|
3706
|
+
}
|
|
3707
|
+
return `https://fonts.googleapis.com/css2?${families.join('&')}&display=swap`;
|
|
3553
3708
|
};
|
|
3554
|
-
const
|
|
3555
|
-
|
|
3556
|
-
|
|
3709
|
+
const buildStack = (font) => [quoteCssFontFamily(font.family), ...(font.fallbacks ?? []).map(quoteCssFontFamily)].join(', ');
|
|
3710
|
+
const formatPaletteValuesRules = (fonts) => {
|
|
3711
|
+
const blocks = [];
|
|
3712
|
+
for (const font of fonts) {
|
|
3713
|
+
for (const palette of font.palettes ?? []) {
|
|
3714
|
+
const lines = [` font-family: ${quoteCssFontFamily(font.family)};`];
|
|
3715
|
+
if (palette.overrideColors && palette.overrideColors.length > 0) {
|
|
3716
|
+
const overrides = palette.overrideColors
|
|
3717
|
+
.map(item => `${item.index} ${item.color}`)
|
|
3718
|
+
.join(', ');
|
|
3719
|
+
lines.push(` override-colors: ${overrides};`);
|
|
3720
|
+
}
|
|
3721
|
+
blocks.push(`@font-palette-values ${palette.name} {\n${lines.join('\n')}\n}`);
|
|
3722
|
+
}
|
|
3723
|
+
}
|
|
3724
|
+
return blocks.length > 0 ? blocks.join('\n\n') : null;
|
|
3557
3725
|
};
|
|
3558
|
-
const
|
|
3559
|
-
|
|
3560
|
-
|
|
3561
|
-
|
|
3726
|
+
const appliedPaletteName = (fonts) => {
|
|
3727
|
+
for (const font of fonts) {
|
|
3728
|
+
for (const palette of font.palettes ?? []) {
|
|
3729
|
+
if (palette.applyToWidget) {
|
|
3730
|
+
return palette.name;
|
|
3731
|
+
}
|
|
3732
|
+
}
|
|
3562
3733
|
}
|
|
3563
|
-
|
|
3564
|
-
|
|
3734
|
+
return undefined;
|
|
3735
|
+
};
|
|
3736
|
+
/**
|
|
3737
|
+
* Palette at-rules plus the token / optional `font-family` / optional
|
|
3738
|
+
* `font-palette` on the widget’s first boxed children. Google faces are a
|
|
3739
|
+
* separate `<link>`. Returns null when there is nothing to declare or
|
|
3740
|
+
* inclusion is off — palettes ride with `includeFontFaces`.
|
|
3741
|
+
*/
|
|
3742
|
+
const formatProjectCssFontsStylesheet = (publishedKey, fonts, includeFontFaces) => {
|
|
3743
|
+
if (!shouldIncludeFontFacesOnPublishedWidget(includeFontFaces) || !publishedKey) {
|
|
3744
|
+
return null;
|
|
3565
3745
|
}
|
|
3566
|
-
|
|
3567
|
-
|
|
3568
|
-
const
|
|
3569
|
-
|
|
3570
|
-
|
|
3571
|
-
|
|
3572
|
-
|
|
3573
|
-
|
|
3574
|
-
|
|
3575
|
-
|
|
3576
|
-
* `'pre-fetched'` renders `initialData` with CSS breakpoint variants.
|
|
3577
|
-
*/
|
|
3578
|
-
this.mode = 'client-fetch';
|
|
3579
|
-
this.publishedKeyAttribute = RULECMS_PUBLISHED_KEY_ATTRIBUTE;
|
|
3580
|
-
this.loadingContainerStyle = loadingContainerStyle;
|
|
3581
|
-
this.spinnerContainerStyle = spinnerContainerStyle;
|
|
3582
|
-
this.spinnerStyle = spinnerStyle;
|
|
3583
|
-
this.errorContainerStyle = errorContainerStyle;
|
|
3584
|
-
this.errorTitleStyle = errorTitleStyle;
|
|
3585
|
-
this.errorMessageStyle = errorMessageStyle;
|
|
3586
|
-
this.loading = false;
|
|
3587
|
-
this.error = null;
|
|
3588
|
-
this.preparedData = null;
|
|
3589
|
-
this.sourceComponentsPlugin = null;
|
|
3590
|
-
this.useBreakpointVariants = false;
|
|
3591
|
-
this.abortController = null;
|
|
3592
|
-
this.lastFetchKey = null;
|
|
3593
|
-
this.stylesInjected = false;
|
|
3746
|
+
const sanitized = sanitizeProjectFontFaces(fonts);
|
|
3747
|
+
const declarations = [];
|
|
3748
|
+
for (const font of sanitized) {
|
|
3749
|
+
const stack = buildStack(font);
|
|
3750
|
+
if (font.cssVariable) {
|
|
3751
|
+
declarations.push(` ${font.cssVariable}: ${stack};`);
|
|
3752
|
+
}
|
|
3753
|
+
if (font.applyToWidget) {
|
|
3754
|
+
declarations.push(` font-family: ${font.cssVariable ? `var(${font.cssVariable})` : stack};`);
|
|
3755
|
+
}
|
|
3594
3756
|
}
|
|
3595
|
-
|
|
3596
|
-
|
|
3757
|
+
const paletteName = appliedPaletteName(sanitized);
|
|
3758
|
+
if (paletteName) {
|
|
3759
|
+
declarations.push(` font-palette: ${paletteName};`);
|
|
3597
3760
|
}
|
|
3598
|
-
|
|
3599
|
-
|
|
3761
|
+
const palettes = formatPaletteValuesRules(sanitized);
|
|
3762
|
+
const selector = `[data-rulecms-published-key="${escapeCssAttributeValue$1(publishedKey)}"] > *`;
|
|
3763
|
+
const surface = declarations.length > 0 ? `${selector} {\n${declarations.join('\n')}\n}` : null;
|
|
3764
|
+
if (!palettes && !surface) {
|
|
3765
|
+
return null;
|
|
3600
3766
|
}
|
|
3601
|
-
|
|
3602
|
-
|
|
3767
|
+
if (!palettes) {
|
|
3768
|
+
return surface;
|
|
3603
3769
|
}
|
|
3604
|
-
|
|
3605
|
-
|
|
3770
|
+
if (!surface) {
|
|
3771
|
+
return palettes;
|
|
3606
3772
|
}
|
|
3607
|
-
|
|
3608
|
-
|
|
3609
|
-
|
|
3610
|
-
|
|
3611
|
-
|
|
3612
|
-
|
|
3613
|
-
|
|
3614
|
-
|
|
3615
|
-
|
|
3773
|
+
return `${palettes}\n\n${surface}`;
|
|
3774
|
+
};
|
|
3775
|
+
|
|
3776
|
+
/**
|
|
3777
|
+
* Emits a Google Fonts `<link>` and/or one `<style data-rulecms-project-fonts>`
|
|
3778
|
+
* from the project catalog, or nothing when inclusion is off / unsanitary.
|
|
3779
|
+
*/
|
|
3780
|
+
class ProjectCssFontsStylesheetComponent {
|
|
3781
|
+
get href() {
|
|
3782
|
+
if (!shouldIncludeFontFacesOnPublishedWidget(this.includeFontFaces)) {
|
|
3783
|
+
return null;
|
|
3616
3784
|
}
|
|
3617
|
-
this.
|
|
3618
|
-
this.fetchClient();
|
|
3785
|
+
return buildGoogleFontsCssHref(sanitizeProjectFontFaces(this.fonts));
|
|
3619
3786
|
}
|
|
3620
|
-
|
|
3621
|
-
|
|
3622
|
-
|
|
3623
|
-
|
|
3624
|
-
|
|
3625
|
-
|
|
3626
|
-
|
|
3627
|
-
|
|
3628
|
-
|
|
3629
|
-
|
|
3787
|
+
get css() {
|
|
3788
|
+
return formatProjectCssFontsStylesheet(this.publishedKey, sanitizeProjectFontFaces(this.fonts), this.includeFontFaces);
|
|
3789
|
+
}
|
|
3790
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: ProjectCssFontsStylesheetComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
|
|
3791
|
+
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "19.2.25", type: ProjectCssFontsStylesheetComponent, isStandalone: true, selector: "rulecms-project-css-fonts-stylesheet", inputs: { publishedKey: "publishedKey", fonts: "fonts", includeFontFaces: "includeFontFaces" }, ngImport: i0, template: `
|
|
3792
|
+
@if (href) {
|
|
3793
|
+
<link rel="stylesheet" [attr.href]="href" data-rulecms-project-fonts="" />
|
|
3794
|
+
}
|
|
3795
|
+
@if (css) {
|
|
3796
|
+
<style data-rulecms-project-fonts="" [innerText]="css"></style>
|
|
3797
|
+
}
|
|
3798
|
+
`, isInline: true }); }
|
|
3799
|
+
}
|
|
3800
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: ProjectCssFontsStylesheetComponent, decorators: [{
|
|
3801
|
+
type: Component,
|
|
3802
|
+
args: [{
|
|
3803
|
+
selector: 'rulecms-project-css-fonts-stylesheet',
|
|
3804
|
+
standalone: true,
|
|
3805
|
+
template: `
|
|
3806
|
+
@if (href) {
|
|
3807
|
+
<link rel="stylesheet" [attr.href]="href" data-rulecms-project-fonts="" />
|
|
3808
|
+
}
|
|
3809
|
+
@if (css) {
|
|
3810
|
+
<style data-rulecms-project-fonts="" [innerText]="css"></style>
|
|
3811
|
+
}
|
|
3812
|
+
`,
|
|
3813
|
+
}]
|
|
3814
|
+
}], propDecorators: { publishedKey: [{
|
|
3815
|
+
type: Input,
|
|
3816
|
+
args: [{ required: true }]
|
|
3817
|
+
}], fonts: [{
|
|
3818
|
+
type: Input
|
|
3819
|
+
}], includeFontFaces: [{
|
|
3820
|
+
type: Input
|
|
3821
|
+
}] } });
|
|
3822
|
+
|
|
3823
|
+
/**
|
|
3824
|
+
* Missing/undefined on a widget GET payload means include. Only an explicit
|
|
3825
|
+
* `false` turns emission off, even if `keyframes` is still present.
|
|
3826
|
+
*/
|
|
3827
|
+
function shouldIncludeKeyframesOnPublishedWidget(includeKeyframes) {
|
|
3828
|
+
return includeKeyframes !== false;
|
|
3829
|
+
}
|
|
3830
|
+
|
|
3831
|
+
const KEYFRAME_NAME_MAX_LENGTH = 80;
|
|
3832
|
+
const KEYFRAME_BODY_MAX_LENGTH = 4000;
|
|
3833
|
+
const MAX_PROJECT_KEYFRAMES = 32;
|
|
3834
|
+
const REJECTED_IN_NAME_OR_BODY$1 = [
|
|
3835
|
+
'url(',
|
|
3836
|
+
'@import',
|
|
3837
|
+
'@font-face',
|
|
3838
|
+
'@media',
|
|
3839
|
+
'@keyframes',
|
|
3840
|
+
'</',
|
|
3841
|
+
'<script',
|
|
3842
|
+
'javascript:',
|
|
3843
|
+
'expression(',
|
|
3844
|
+
'behavior:',
|
|
3845
|
+
];
|
|
3846
|
+
// eslint-disable-next-line no-control-regex -- control characters are what this matches
|
|
3847
|
+
const REJECTED_CONTROL_CHARACTERS$1 = /[\u0000-\u0008\u000b\u000c\u000e-\u001f\u007f]/;
|
|
3848
|
+
const ALLOWED_NAME$1 = /^[A-Za-z_][\w-]*$/;
|
|
3849
|
+
const isBraceBalanced = (value) => {
|
|
3850
|
+
let depth = 0;
|
|
3851
|
+
for (const char of value) {
|
|
3852
|
+
if (char === '{') {
|
|
3853
|
+
depth += 1;
|
|
3854
|
+
}
|
|
3855
|
+
else if (char === '}') {
|
|
3856
|
+
depth -= 1;
|
|
3857
|
+
if (depth < 0) {
|
|
3858
|
+
return false;
|
|
3859
|
+
}
|
|
3860
|
+
}
|
|
3861
|
+
}
|
|
3862
|
+
return depth === 0;
|
|
3863
|
+
};
|
|
3864
|
+
const isKeyframeName = (value) => {
|
|
3865
|
+
if (!value || value.length > KEYFRAME_NAME_MAX_LENGTH) {
|
|
3866
|
+
return false;
|
|
3867
|
+
}
|
|
3868
|
+
if (value.includes('@') || value.includes('.') || /\s/.test(value)) {
|
|
3869
|
+
return false;
|
|
3870
|
+
}
|
|
3871
|
+
const lowered = value.toLowerCase();
|
|
3872
|
+
if (REJECTED_IN_NAME_OR_BODY$1.some(rejected => lowered.includes(rejected))) {
|
|
3873
|
+
return false;
|
|
3874
|
+
}
|
|
3875
|
+
return ALLOWED_NAME$1.test(value);
|
|
3876
|
+
};
|
|
3877
|
+
const isKeyframeSelector = (value) => {
|
|
3878
|
+
const selector = value.trim();
|
|
3879
|
+
if (selector === '') {
|
|
3880
|
+
return false;
|
|
3881
|
+
}
|
|
3882
|
+
const lowered = selector.toLowerCase();
|
|
3883
|
+
if (lowered === 'from' || lowered === 'to') {
|
|
3884
|
+
return true;
|
|
3885
|
+
}
|
|
3886
|
+
const match = selector.match(/^(\d{1,3}(?:\.\d+)?)%$/);
|
|
3887
|
+
if (!match) {
|
|
3888
|
+
return false;
|
|
3889
|
+
}
|
|
3890
|
+
const percent = Number(match[1]);
|
|
3891
|
+
return percent >= 0 && percent <= 100;
|
|
3892
|
+
};
|
|
3893
|
+
const parseKeyframeBlocks = (input) => {
|
|
3894
|
+
let index = 0;
|
|
3895
|
+
const length = input.length;
|
|
3896
|
+
let found = 0;
|
|
3897
|
+
const skipWhitespace = () => {
|
|
3898
|
+
while (index < length && /\s/.test(input[index])) {
|
|
3899
|
+
index += 1;
|
|
3900
|
+
}
|
|
3901
|
+
};
|
|
3902
|
+
skipWhitespace();
|
|
3903
|
+
while (index < length) {
|
|
3904
|
+
const open = input.indexOf('{', index);
|
|
3905
|
+
if (open === -1) {
|
|
3906
|
+
return false;
|
|
3907
|
+
}
|
|
3908
|
+
const selectorPart = input.slice(index, open).trim();
|
|
3909
|
+
if (!selectorPart.split(',').every(part => isKeyframeSelector(part))) {
|
|
3910
|
+
return false;
|
|
3911
|
+
}
|
|
3912
|
+
index = open + 1;
|
|
3913
|
+
const close = input.indexOf('}', index);
|
|
3914
|
+
if (close === -1) {
|
|
3915
|
+
return false;
|
|
3916
|
+
}
|
|
3917
|
+
const declarations = input.slice(index, close);
|
|
3918
|
+
if (declarations.includes('{') || declarations.includes('}') || declarations.includes('@')) {
|
|
3919
|
+
return false;
|
|
3920
|
+
}
|
|
3921
|
+
index = close + 1;
|
|
3922
|
+
found += 1;
|
|
3923
|
+
skipWhitespace();
|
|
3924
|
+
}
|
|
3925
|
+
return found > 0;
|
|
3926
|
+
};
|
|
3927
|
+
const isCssKeyframeBody = (value) => {
|
|
3928
|
+
const trimmed = value.trim();
|
|
3929
|
+
if (!trimmed || trimmed.length > KEYFRAME_BODY_MAX_LENGTH) {
|
|
3930
|
+
return false;
|
|
3931
|
+
}
|
|
3932
|
+
if (REJECTED_CONTROL_CHARACTERS$1.test(trimmed) || !isBraceBalanced(trimmed)) {
|
|
3933
|
+
return false;
|
|
3934
|
+
}
|
|
3935
|
+
const lowered = trimmed.toLowerCase();
|
|
3936
|
+
if (REJECTED_IN_NAME_OR_BODY$1.some(rejected => lowered.includes(rejected))) {
|
|
3937
|
+
return false;
|
|
3938
|
+
}
|
|
3939
|
+
if (trimmed.includes('@')) {
|
|
3940
|
+
return false;
|
|
3941
|
+
}
|
|
3942
|
+
return parseKeyframeBlocks(trimmed);
|
|
3943
|
+
};
|
|
3944
|
+
const sanitizeProjectCssKeyframes = (keyframes) => {
|
|
3945
|
+
if (!keyframes) {
|
|
3946
|
+
return {};
|
|
3947
|
+
}
|
|
3948
|
+
const sanitized = {};
|
|
3949
|
+
for (const [rawName, rawValue] of Object.entries(keyframes)) {
|
|
3950
|
+
const name = rawName.trim();
|
|
3951
|
+
if (!isKeyframeName(name) || sanitized[name] !== undefined || typeof rawValue !== 'string') {
|
|
3952
|
+
continue;
|
|
3953
|
+
}
|
|
3954
|
+
const value = rawValue.trim();
|
|
3955
|
+
if (!isCssKeyframeBody(value)) {
|
|
3956
|
+
continue;
|
|
3957
|
+
}
|
|
3958
|
+
sanitized[name] = value;
|
|
3959
|
+
if (Object.keys(sanitized).length === MAX_PROJECT_KEYFRAMES) {
|
|
3960
|
+
break;
|
|
3961
|
+
}
|
|
3962
|
+
}
|
|
3963
|
+
return Object.fromEntries(Object.entries(sanitized).sort(([left], [right]) => left.localeCompare(right)));
|
|
3964
|
+
};
|
|
3965
|
+
const indentFrameBody = (body) => body
|
|
3966
|
+
.split('\n')
|
|
3967
|
+
.map(line => ` ${line}`)
|
|
3968
|
+
.join('\n');
|
|
3969
|
+
/**
|
|
3970
|
+
* Unscoped `@keyframes` blocks. `publishedKey` is unused (document-global
|
|
3971
|
+
* at-rule) and kept so the signature matches fonts/classes.
|
|
3972
|
+
*/
|
|
3973
|
+
const formatProjectCssKeyframesStylesheet = (publishedKey, keyframes, includeKeyframes) => {
|
|
3974
|
+
if (!shouldIncludeKeyframesOnPublishedWidget(includeKeyframes)) {
|
|
3975
|
+
return null;
|
|
3976
|
+
}
|
|
3977
|
+
const sanitized = sanitizeProjectCssKeyframes(keyframes);
|
|
3978
|
+
const names = Object.keys(sanitized);
|
|
3979
|
+
if (names.length === 0) {
|
|
3980
|
+
return null;
|
|
3981
|
+
}
|
|
3982
|
+
void publishedKey;
|
|
3983
|
+
return names
|
|
3984
|
+
.map(name => `@keyframes ${name} {\n${indentFrameBody(sanitized[name])}\n}`)
|
|
3985
|
+
.join('\n\n');
|
|
3986
|
+
};
|
|
3987
|
+
|
|
3988
|
+
/**
|
|
3989
|
+
* Emits one unscoped `<style data-rulecms-project-keyframes>` from the
|
|
3990
|
+
* project catalog, or nothing when the catalog is empty / unsanitary.
|
|
3991
|
+
*/
|
|
3992
|
+
class ProjectCssKeyframesStylesheetComponent {
|
|
3993
|
+
get css() {
|
|
3994
|
+
return formatProjectCssKeyframesStylesheet(this.publishedKey, this.keyframes);
|
|
3995
|
+
}
|
|
3996
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: ProjectCssKeyframesStylesheetComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
|
|
3997
|
+
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "19.2.25", type: ProjectCssKeyframesStylesheetComponent, isStandalone: true, selector: "rulecms-project-css-keyframes-stylesheet", inputs: { publishedKey: "publishedKey", keyframes: "keyframes" }, ngImport: i0, template: `
|
|
3998
|
+
@if (css) {
|
|
3999
|
+
<style data-rulecms-project-keyframes="" [innerText]="css"></style>
|
|
4000
|
+
}
|
|
4001
|
+
`, isInline: true }); }
|
|
4002
|
+
}
|
|
4003
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: ProjectCssKeyframesStylesheetComponent, decorators: [{
|
|
4004
|
+
type: Component,
|
|
4005
|
+
args: [{
|
|
4006
|
+
selector: 'rulecms-project-css-keyframes-stylesheet',
|
|
4007
|
+
standalone: true,
|
|
4008
|
+
template: `
|
|
4009
|
+
@if (css) {
|
|
4010
|
+
<style data-rulecms-project-keyframes="" [innerText]="css"></style>
|
|
4011
|
+
}
|
|
4012
|
+
`,
|
|
4013
|
+
}]
|
|
4014
|
+
}], propDecorators: { publishedKey: [{
|
|
4015
|
+
type: Input,
|
|
4016
|
+
args: [{ required: true }]
|
|
4017
|
+
}], keyframes: [{
|
|
4018
|
+
type: Input
|
|
4019
|
+
}] } });
|
|
4020
|
+
|
|
4021
|
+
/**
|
|
4022
|
+
* Missing / undefined means include (legacy payloads).
|
|
4023
|
+
* `false` turns emission off, even if `positionTry` is still present.
|
|
4024
|
+
*/
|
|
4025
|
+
const shouldIncludePositionTryOnPublishedWidget = (includePositionTry) => {
|
|
4026
|
+
return includePositionTry !== false;
|
|
4027
|
+
};
|
|
4028
|
+
|
|
4029
|
+
const POSITION_TRY_NAME_MAX_LENGTH = 80;
|
|
4030
|
+
const POSITION_TRY_BODY_MAX_LENGTH = 2000;
|
|
4031
|
+
const MAX_PROJECT_POSITION_TRY = 16;
|
|
4032
|
+
const REJECTED_IN_NAME_OR_BODY = ['url(', '@', '</', '<script', 'javascript:', 'expression('];
|
|
4033
|
+
// eslint-disable-next-line no-control-regex -- control characters are what this matches
|
|
4034
|
+
const REJECTED_CONTROL_CHARACTERS = /[\u0000-\u0008\u000b\u000c\u000e-\u001f\u007f]/;
|
|
4035
|
+
const ALLOWED_NAME = /^--[A-Za-z_][\w-]*$/;
|
|
4036
|
+
const isBraceBalancedAtZero = (value) => {
|
|
4037
|
+
for (const char of value) {
|
|
4038
|
+
if (char === '{' || char === '}') {
|
|
4039
|
+
return false;
|
|
4040
|
+
}
|
|
4041
|
+
}
|
|
4042
|
+
return true;
|
|
4043
|
+
};
|
|
4044
|
+
const isPositionTryName = (value) => {
|
|
4045
|
+
if (!value || value.length > POSITION_TRY_NAME_MAX_LENGTH) {
|
|
4046
|
+
return false;
|
|
4047
|
+
}
|
|
4048
|
+
if (value.includes('@') || value.includes('.') || /\s/.test(value)) {
|
|
4049
|
+
return false;
|
|
4050
|
+
}
|
|
4051
|
+
const lowered = value.toLowerCase();
|
|
4052
|
+
if (REJECTED_IN_NAME_OR_BODY.some(rejected => lowered.includes(rejected))) {
|
|
4053
|
+
return false;
|
|
4054
|
+
}
|
|
4055
|
+
return ALLOWED_NAME.test(value);
|
|
4056
|
+
};
|
|
4057
|
+
const isCssPositionTryBody = (value) => {
|
|
4058
|
+
const trimmed = value.trim();
|
|
4059
|
+
if (!trimmed || trimmed.length > POSITION_TRY_BODY_MAX_LENGTH) {
|
|
4060
|
+
return false;
|
|
4061
|
+
}
|
|
4062
|
+
if (REJECTED_CONTROL_CHARACTERS.test(trimmed) || !isBraceBalancedAtZero(trimmed)) {
|
|
4063
|
+
return false;
|
|
4064
|
+
}
|
|
4065
|
+
const lowered = trimmed.toLowerCase();
|
|
4066
|
+
return !REJECTED_IN_NAME_OR_BODY.some(rejected => lowered.includes(rejected));
|
|
4067
|
+
};
|
|
4068
|
+
const sanitizeProjectCssPositionTry = (positionTry) => {
|
|
4069
|
+
if (!positionTry) {
|
|
4070
|
+
return {};
|
|
4071
|
+
}
|
|
4072
|
+
const sanitized = {};
|
|
4073
|
+
for (const [rawName, rawValue] of Object.entries(positionTry)) {
|
|
4074
|
+
const name = rawName.trim();
|
|
4075
|
+
if (!isPositionTryName(name) || sanitized[name] !== undefined || typeof rawValue !== 'string') {
|
|
4076
|
+
continue;
|
|
4077
|
+
}
|
|
4078
|
+
const value = rawValue.trim();
|
|
4079
|
+
if (!isCssPositionTryBody(value)) {
|
|
4080
|
+
continue;
|
|
4081
|
+
}
|
|
4082
|
+
sanitized[name] = value;
|
|
4083
|
+
if (Object.keys(sanitized).length === MAX_PROJECT_POSITION_TRY) {
|
|
4084
|
+
break;
|
|
4085
|
+
}
|
|
4086
|
+
}
|
|
4087
|
+
return Object.fromEntries(Object.entries(sanitized).sort(([left], [right]) => left.localeCompare(right)));
|
|
4088
|
+
};
|
|
4089
|
+
const indentDeclarationBody = (body) => body
|
|
4090
|
+
.split('\n')
|
|
4091
|
+
.map(line => ` ${line}`)
|
|
4092
|
+
.join('\n');
|
|
4093
|
+
/**
|
|
4094
|
+
* Unscoped `@position-try` blocks. `publishedKey` is unused (document-global
|
|
4095
|
+
* at-rule) and kept so the signature matches fonts/keyframes.
|
|
4096
|
+
*/
|
|
4097
|
+
const formatProjectCssPositionTryStylesheet = (publishedKey, positionTry, includePositionTry) => {
|
|
4098
|
+
if (!shouldIncludePositionTryOnPublishedWidget(includePositionTry)) {
|
|
4099
|
+
return null;
|
|
4100
|
+
}
|
|
4101
|
+
const sanitized = sanitizeProjectCssPositionTry(positionTry);
|
|
4102
|
+
const names = Object.keys(sanitized);
|
|
4103
|
+
if (names.length === 0) {
|
|
4104
|
+
return null;
|
|
4105
|
+
}
|
|
4106
|
+
void publishedKey;
|
|
4107
|
+
return names
|
|
4108
|
+
.map(name => `@position-try ${name} {\n${indentDeclarationBody(sanitized[name])}\n}`)
|
|
4109
|
+
.join('\n\n');
|
|
4110
|
+
};
|
|
4111
|
+
|
|
4112
|
+
/**
|
|
4113
|
+
* Emits one unscoped `<style data-rulecms-project-position-try>` from the
|
|
4114
|
+
* project catalog, or nothing when the catalog is empty / unsanitary.
|
|
4115
|
+
*/
|
|
4116
|
+
class ProjectCssPositionTryStylesheetComponent {
|
|
4117
|
+
get css() {
|
|
4118
|
+
return formatProjectCssPositionTryStylesheet(this.publishedKey, this.positionTry);
|
|
4119
|
+
}
|
|
4120
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: ProjectCssPositionTryStylesheetComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
|
|
4121
|
+
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "19.2.25", type: ProjectCssPositionTryStylesheetComponent, isStandalone: true, selector: "rulecms-project-css-position-try-stylesheet", inputs: { publishedKey: "publishedKey", positionTry: "positionTry" }, ngImport: i0, template: `
|
|
4122
|
+
@if (css) {
|
|
4123
|
+
<style data-rulecms-project-position-try="" [innerText]="css"></style>
|
|
4124
|
+
}
|
|
4125
|
+
`, isInline: true }); }
|
|
4126
|
+
}
|
|
4127
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: ProjectCssPositionTryStylesheetComponent, decorators: [{
|
|
4128
|
+
type: Component,
|
|
4129
|
+
args: [{
|
|
4130
|
+
selector: 'rulecms-project-css-position-try-stylesheet',
|
|
4131
|
+
standalone: true,
|
|
4132
|
+
template: `
|
|
4133
|
+
@if (css) {
|
|
4134
|
+
<style data-rulecms-project-position-try="" [innerText]="css"></style>
|
|
4135
|
+
}
|
|
4136
|
+
`,
|
|
4137
|
+
}]
|
|
4138
|
+
}], propDecorators: { publishedKey: [{
|
|
4139
|
+
type: Input,
|
|
4140
|
+
args: [{ required: true }]
|
|
4141
|
+
}], positionTry: [{
|
|
4142
|
+
type: Input
|
|
4143
|
+
}] } });
|
|
4144
|
+
|
|
4145
|
+
/**
|
|
4146
|
+
* Missing/undefined on a widget GET payload means include. Only an explicit
|
|
4147
|
+
* `false` turns emission off, even if `cssProperties` is still present.
|
|
4148
|
+
*/
|
|
4149
|
+
function shouldIncludeCssPropertiesOnPublishedWidget(includeCssProperties) {
|
|
4150
|
+
return includeCssProperties !== false;
|
|
4151
|
+
}
|
|
4152
|
+
|
|
4153
|
+
const PROJECT_CSS_PROPERTY_SYNTAX_VALUES = [
|
|
4154
|
+
'*',
|
|
4155
|
+
'<number>',
|
|
4156
|
+
'<integer>',
|
|
4157
|
+
'<length>',
|
|
4158
|
+
'<percentage>',
|
|
4159
|
+
'<length-percentage>',
|
|
4160
|
+
'<color>',
|
|
4161
|
+
'<angle>',
|
|
4162
|
+
'<time>',
|
|
4163
|
+
'<transform-function>',
|
|
4164
|
+
'<transform-list>',
|
|
4165
|
+
];
|
|
4166
|
+
const PROPERTY_SYNTAX_SET = new Set(PROJECT_CSS_PROPERTY_SYNTAX_VALUES);
|
|
4167
|
+
const REJECTED_IN_EMITTED_VALUE$2 = /[{};]/;
|
|
4168
|
+
const MAX_PROJECT_CSS_PROPERTIES = 40;
|
|
4169
|
+
const PROPERTY_INITIAL_VALUE_MAX_LENGTH = 200;
|
|
4170
|
+
const isAllowlistedSyntax = (value) => typeof value === 'string' && PROPERTY_SYNTAX_SET.has(value);
|
|
4171
|
+
const isSafeInitialValue = (value, syntax) => {
|
|
4172
|
+
if (syntax !== '*' && value === '') {
|
|
4173
|
+
return false;
|
|
4174
|
+
}
|
|
4175
|
+
if (syntax === '*' && value === '') {
|
|
4176
|
+
return true;
|
|
4177
|
+
}
|
|
4178
|
+
if (value.length > PROPERTY_INITIAL_VALUE_MAX_LENGTH) {
|
|
4179
|
+
return false;
|
|
4180
|
+
}
|
|
4181
|
+
if (REJECTED_IN_EMITTED_VALUE$2.test(value) || value.includes('url(') || value.includes('@')) {
|
|
4182
|
+
return false;
|
|
4183
|
+
}
|
|
4184
|
+
return true;
|
|
4185
|
+
};
|
|
4186
|
+
const sanitizeProjectCssProperties = (cssProperties) => {
|
|
4187
|
+
if (!Array.isArray(cssProperties)) {
|
|
4188
|
+
return [];
|
|
4189
|
+
}
|
|
4190
|
+
const sanitized = [];
|
|
4191
|
+
const seen = new Set();
|
|
4192
|
+
for (const raw of cssProperties) {
|
|
4193
|
+
if (!raw || typeof raw.name !== 'string' || !isCssVariableName(raw.name.trim())) {
|
|
4194
|
+
continue;
|
|
4195
|
+
}
|
|
4196
|
+
const name = raw.name.trim();
|
|
4197
|
+
if (seen.has(name) || sanitized.length >= MAX_PROJECT_CSS_PROPERTIES) {
|
|
4198
|
+
continue;
|
|
4199
|
+
}
|
|
4200
|
+
if (!isAllowlistedSyntax(raw.syntax)) {
|
|
4201
|
+
continue;
|
|
4202
|
+
}
|
|
4203
|
+
if (typeof raw.inherits !== 'boolean') {
|
|
4204
|
+
continue;
|
|
4205
|
+
}
|
|
4206
|
+
const initialValue = typeof raw.initialValue === 'string' ? raw.initialValue.trim() : '';
|
|
4207
|
+
if (!isSafeInitialValue(initialValue, raw.syntax)) {
|
|
4208
|
+
continue;
|
|
4209
|
+
}
|
|
4210
|
+
seen.add(name);
|
|
4211
|
+
sanitized.push({
|
|
4212
|
+
name,
|
|
4213
|
+
syntax: raw.syntax,
|
|
4214
|
+
inherits: raw.inherits,
|
|
4215
|
+
initialValue,
|
|
4216
|
+
});
|
|
4217
|
+
}
|
|
4218
|
+
return sanitized;
|
|
4219
|
+
};
|
|
4220
|
+
const formatOneProperty = (property) => {
|
|
4221
|
+
const lines = [
|
|
4222
|
+
`@property ${property.name} {`,
|
|
4223
|
+
` syntax: "${property.syntax}";`,
|
|
4224
|
+
` inherits: ${property.inherits ? 'true' : 'false'};`,
|
|
4225
|
+
];
|
|
4226
|
+
if (property.initialValue !== '') {
|
|
4227
|
+
lines.push(` initial-value: ${property.initialValue};`);
|
|
4228
|
+
}
|
|
4229
|
+
lines.push('}');
|
|
4230
|
+
return lines.join('\n');
|
|
4231
|
+
};
|
|
4232
|
+
/**
|
|
4233
|
+
* Unscoped `@property` blocks. `publishedKey` is unused (document-global
|
|
4234
|
+
* at-rule) and kept so the signature matches fonts/keyframes.
|
|
4235
|
+
*/
|
|
4236
|
+
const formatProjectCssPropertiesStylesheet = (publishedKey, cssProperties, includeCssProperties) => {
|
|
4237
|
+
if (!shouldIncludeCssPropertiesOnPublishedWidget(includeCssProperties)) {
|
|
4238
|
+
return null;
|
|
4239
|
+
}
|
|
4240
|
+
const sanitized = sanitizeProjectCssProperties(cssProperties);
|
|
4241
|
+
if (sanitized.length === 0) {
|
|
4242
|
+
return null;
|
|
4243
|
+
}
|
|
4244
|
+
void publishedKey;
|
|
4245
|
+
return sanitized.map(formatOneProperty).join('\n\n');
|
|
4246
|
+
};
|
|
4247
|
+
|
|
4248
|
+
/**
|
|
4249
|
+
* Emits one unscoped `<style data-rulecms-project-css-properties>` from the
|
|
4250
|
+
* project catalog, or nothing when the catalog is empty / unsanitary.
|
|
4251
|
+
*/
|
|
4252
|
+
class ProjectCssPropertiesStylesheetComponent {
|
|
4253
|
+
get css() {
|
|
4254
|
+
return formatProjectCssPropertiesStylesheet(this.publishedKey, this.cssProperties);
|
|
4255
|
+
}
|
|
4256
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: ProjectCssPropertiesStylesheetComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
|
|
4257
|
+
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "19.2.25", type: ProjectCssPropertiesStylesheetComponent, isStandalone: true, selector: "rulecms-project-css-properties-stylesheet", inputs: { publishedKey: "publishedKey", cssProperties: "cssProperties" }, ngImport: i0, template: `
|
|
4258
|
+
@if (css) {
|
|
4259
|
+
<style data-rulecms-project-css-properties="" [innerText]="css"></style>
|
|
4260
|
+
}
|
|
4261
|
+
`, isInline: true }); }
|
|
4262
|
+
}
|
|
4263
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: ProjectCssPropertiesStylesheetComponent, decorators: [{
|
|
4264
|
+
type: Component,
|
|
4265
|
+
args: [{
|
|
4266
|
+
selector: 'rulecms-project-css-properties-stylesheet',
|
|
4267
|
+
standalone: true,
|
|
4268
|
+
template: `
|
|
4269
|
+
@if (css) {
|
|
4270
|
+
<style data-rulecms-project-css-properties="" [innerText]="css"></style>
|
|
4271
|
+
}
|
|
4272
|
+
`,
|
|
4273
|
+
}]
|
|
4274
|
+
}], propDecorators: { publishedKey: [{
|
|
4275
|
+
type: Input,
|
|
4276
|
+
args: [{ required: true }]
|
|
4277
|
+
}], cssProperties: [{
|
|
4278
|
+
type: Input
|
|
4279
|
+
}] } });
|
|
4280
|
+
|
|
4281
|
+
/**
|
|
4282
|
+
* Missing/undefined on a widget GET payload means include — the default, and
|
|
4283
|
+
* the shape older clients already understand. Only an explicit `false` turns
|
|
4284
|
+
* emission off, even if `cssVariables` is still present on the payload.
|
|
4285
|
+
*/
|
|
4286
|
+
function shouldIncludeCssVariablesOnPublishedWidget(includeCssVariables) {
|
|
4287
|
+
return includeCssVariables !== false;
|
|
4288
|
+
}
|
|
4289
|
+
|
|
4290
|
+
/**
|
|
4291
|
+
* Attribute-selector escape so a published key cannot break out of
|
|
4292
|
+
* `[data-rulecms-published-key="…"]`. `CSS.escape` is not assumed (SSR / Node).
|
|
4293
|
+
*/
|
|
4294
|
+
const escapeCssAttributeValue = (value) => value.replace(/\\/g, '\\\\').replace(/"/g, '\\"');
|
|
4295
|
+
const REJECTED_IN_EMITTED_VALUE$1 = /[{};]/;
|
|
4296
|
+
const sanitizeForStylesheet = (variables) => {
|
|
4297
|
+
if (!variables) {
|
|
4298
|
+
return {};
|
|
4299
|
+
}
|
|
4300
|
+
const sanitized = {};
|
|
4301
|
+
for (const [rawName, rawValue] of Object.entries(variables)) {
|
|
4302
|
+
if (!isCssVariableName(rawName) || typeof rawValue !== 'string') {
|
|
4303
|
+
continue;
|
|
4304
|
+
}
|
|
4305
|
+
const value = rawValue.trim();
|
|
4306
|
+
if (value === '' || REJECTED_IN_EMITTED_VALUE$1.test(value)) {
|
|
4307
|
+
continue;
|
|
4308
|
+
}
|
|
4309
|
+
sanitized[rawName.trim()] = value;
|
|
4310
|
+
}
|
|
4311
|
+
return sanitized;
|
|
4312
|
+
};
|
|
4313
|
+
/**
|
|
4314
|
+
* One rule: custom properties on the first boxed children of this widget’s
|
|
4315
|
+
* published-key span. Empty / flag-off / unsanitary catalogs return null so
|
|
4316
|
+
* the caller omits the `<style>` tag.
|
|
4317
|
+
*/
|
|
4318
|
+
const formatProjectCssVariablesStylesheet = (publishedKey, variables, includeCssVariables) => {
|
|
4319
|
+
if (!shouldIncludeCssVariablesOnPublishedWidget(includeCssVariables)) {
|
|
4320
|
+
return null;
|
|
4321
|
+
}
|
|
4322
|
+
const sanitized = sanitizeForStylesheet(variables);
|
|
4323
|
+
const names = Object.keys(sanitized);
|
|
4324
|
+
if (names.length === 0 || !publishedKey) {
|
|
4325
|
+
return null;
|
|
4326
|
+
}
|
|
4327
|
+
const selector = `[data-rulecms-published-key="${escapeCssAttributeValue(publishedKey)}"] > *`;
|
|
4328
|
+
const declarations = names
|
|
4329
|
+
.sort((left, right) => left.localeCompare(right))
|
|
4330
|
+
.map((name) => ` ${name}: ${sanitized[name]};`)
|
|
4331
|
+
.join('\n');
|
|
4332
|
+
return `${selector} {\n${declarations}\n}`;
|
|
4333
|
+
};
|
|
4334
|
+
|
|
4335
|
+
/**
|
|
4336
|
+
* Missing/undefined on a widget GET payload means include. Only an explicit
|
|
4337
|
+
* `false` turns emission off, even if `themes` is still present.
|
|
4338
|
+
*/
|
|
4339
|
+
function shouldIncludeThemesOnPublishedWidget(includeThemes) {
|
|
4340
|
+
return includeThemes !== false;
|
|
4341
|
+
}
|
|
4342
|
+
|
|
4343
|
+
const MAX_PROJECT_THEMES = 5;
|
|
4344
|
+
const MAX_THEME_VARIABLES = 200;
|
|
4345
|
+
const ALLOWED_CONDITIONS = [
|
|
4346
|
+
{ kind: 'prefers-color-scheme', value: 'dark' },
|
|
4347
|
+
{ kind: 'prefers-color-scheme', value: 'light' },
|
|
4348
|
+
{ kind: 'html-class', value: 'dark' },
|
|
4349
|
+
{ kind: 'data-theme', value: 'dark' },
|
|
4350
|
+
{ kind: 'data-theme', value: 'light' },
|
|
4351
|
+
];
|
|
4352
|
+
const REJECTED_IN_EMITTED_VALUE = /[{};]/;
|
|
4353
|
+
const isAllowedCondition = (value) => {
|
|
4354
|
+
if (typeof value !== 'object' || value === null || Array.isArray(value)) {
|
|
4355
|
+
return false;
|
|
4356
|
+
}
|
|
4357
|
+
const raw = value;
|
|
4358
|
+
return ALLOWED_CONDITIONS.some(option => option.kind === raw.kind && option.value === raw.value);
|
|
4359
|
+
};
|
|
4360
|
+
const sanitizeVariables = (variables) => {
|
|
4361
|
+
if (!variables || typeof variables !== 'object' || Array.isArray(variables)) {
|
|
4362
|
+
return {};
|
|
4363
|
+
}
|
|
4364
|
+
const sanitized = {};
|
|
4365
|
+
for (const [rawName, rawValue] of Object.entries(variables)) {
|
|
4366
|
+
if (!isCssVariableName(rawName) || typeof rawValue !== 'string') {
|
|
4367
|
+
continue;
|
|
4368
|
+
}
|
|
4369
|
+
const value = rawValue.trim();
|
|
4370
|
+
if (value === '' || REJECTED_IN_EMITTED_VALUE.test(value) || value.includes('url(') || value.includes('@')) {
|
|
4371
|
+
continue;
|
|
4372
|
+
}
|
|
4373
|
+
sanitized[rawName.trim()] = value;
|
|
4374
|
+
}
|
|
4375
|
+
return Object.fromEntries(Object.entries(sanitized).sort(([left], [right]) => left.localeCompare(right)));
|
|
4376
|
+
};
|
|
4377
|
+
const sanitizeProjectCssThemes = (themes) => {
|
|
4378
|
+
if (!Array.isArray(themes)) {
|
|
4379
|
+
return [];
|
|
4380
|
+
}
|
|
4381
|
+
const sanitized = [];
|
|
4382
|
+
const seen = new Set();
|
|
4383
|
+
let variableCount = 0;
|
|
4384
|
+
for (const raw of themes) {
|
|
4385
|
+
if (!raw || !isAllowedCondition(raw.condition)) {
|
|
4386
|
+
continue;
|
|
4387
|
+
}
|
|
4388
|
+
const id = `${raw.condition.kind}:${raw.condition.value}`;
|
|
4389
|
+
if (seen.has(id)) {
|
|
4390
|
+
continue;
|
|
4391
|
+
}
|
|
4392
|
+
const variables = sanitizeVariables(raw.variables);
|
|
4393
|
+
const nextCount = variableCount + Object.keys(variables).length;
|
|
4394
|
+
if (Object.keys(variables).length === 0 || nextCount > MAX_THEME_VARIABLES) {
|
|
4395
|
+
continue;
|
|
4396
|
+
}
|
|
4397
|
+
seen.add(id);
|
|
4398
|
+
variableCount = nextCount;
|
|
4399
|
+
sanitized.push({ condition: raw.condition, variables });
|
|
4400
|
+
if (sanitized.length === MAX_PROJECT_THEMES) {
|
|
4401
|
+
break;
|
|
4402
|
+
}
|
|
4403
|
+
}
|
|
4404
|
+
return sanitized;
|
|
4405
|
+
};
|
|
4406
|
+
const formatVariableBlock = (variables, tokenSelector) => {
|
|
4407
|
+
const lines = Object.entries(variables).map(([name, value]) => ` ${name}: ${value};`);
|
|
4408
|
+
return `${tokenSelector} {\n${lines.join('\n')}\n}`;
|
|
4409
|
+
};
|
|
4410
|
+
const indentBlock = (css) => css
|
|
4411
|
+
.split('\n')
|
|
4412
|
+
.map(line => ` ${line}`)
|
|
4413
|
+
.join('\n');
|
|
4414
|
+
const formatThemeRule = (theme, tokenSelector) => {
|
|
4415
|
+
const block = formatVariableBlock(theme.variables, tokenSelector);
|
|
4416
|
+
const { kind, value } = theme.condition;
|
|
4417
|
+
if (kind === 'prefers-color-scheme') {
|
|
4418
|
+
return `@media (prefers-color-scheme: ${value}) {\n${indentBlock(block)}\n}`;
|
|
4419
|
+
}
|
|
4420
|
+
if (kind === 'html-class') {
|
|
4421
|
+
return `html.${value} ${block}`;
|
|
4422
|
+
}
|
|
4423
|
+
return `[data-theme="${value}"] ${block}`;
|
|
4424
|
+
};
|
|
4425
|
+
/**
|
|
4426
|
+
* Host-condition token overrides on boxed children of this widget’s published-key
|
|
4427
|
+
* span. Never styles `html` / `:root` / `body`. Empty / flag-off / unsanitary
|
|
4428
|
+
* catalogs return null so the caller omits the `<style>` tag.
|
|
4429
|
+
*/
|
|
4430
|
+
const formatProjectCssThemesStylesheet = (publishedKey, themes, includeThemes) => {
|
|
4431
|
+
if (!shouldIncludeThemesOnPublishedWidget(includeThemes) || !publishedKey) {
|
|
4432
|
+
return null;
|
|
4433
|
+
}
|
|
4434
|
+
const sanitized = sanitizeProjectCssThemes(themes);
|
|
4435
|
+
if (sanitized.length === 0) {
|
|
4436
|
+
return null;
|
|
4437
|
+
}
|
|
4438
|
+
const tokenSelector = `[data-rulecms-published-key="${escapeCssAttributeValue(publishedKey)}"] > *`;
|
|
4439
|
+
return sanitized.map(theme => formatThemeRule(theme, tokenSelector)).join('\n\n');
|
|
4440
|
+
};
|
|
4441
|
+
|
|
4442
|
+
/**
|
|
4443
|
+
* Emits one `<style data-rulecms-project-themes>` from the project catalog,
|
|
4444
|
+
* or nothing when the catalog is empty / unsanitary.
|
|
4445
|
+
*/
|
|
4446
|
+
class ProjectCssThemesStylesheetComponent {
|
|
4447
|
+
get css() {
|
|
4448
|
+
return formatProjectCssThemesStylesheet(this.publishedKey, this.themes);
|
|
4449
|
+
}
|
|
4450
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: ProjectCssThemesStylesheetComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
|
|
4451
|
+
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "19.2.25", type: ProjectCssThemesStylesheetComponent, isStandalone: true, selector: "rulecms-project-css-themes-stylesheet", inputs: { publishedKey: "publishedKey", themes: "themes" }, ngImport: i0, template: `
|
|
4452
|
+
@if (css) {
|
|
4453
|
+
<style data-rulecms-project-themes="" [innerText]="css"></style>
|
|
4454
|
+
}
|
|
4455
|
+
`, isInline: true }); }
|
|
4456
|
+
}
|
|
4457
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: ProjectCssThemesStylesheetComponent, decorators: [{
|
|
4458
|
+
type: Component,
|
|
4459
|
+
args: [{
|
|
4460
|
+
selector: 'rulecms-project-css-themes-stylesheet',
|
|
4461
|
+
standalone: true,
|
|
4462
|
+
template: `
|
|
4463
|
+
@if (css) {
|
|
4464
|
+
<style data-rulecms-project-themes="" [innerText]="css"></style>
|
|
4465
|
+
}
|
|
4466
|
+
`,
|
|
4467
|
+
}]
|
|
4468
|
+
}], propDecorators: { publishedKey: [{
|
|
4469
|
+
type: Input,
|
|
4470
|
+
args: [{ required: true }]
|
|
4471
|
+
}], themes: [{
|
|
4472
|
+
type: Input
|
|
4473
|
+
}] } });
|
|
4474
|
+
|
|
4475
|
+
/**
|
|
4476
|
+
* Emits one scoped `<style data-rulecms-project-css-variables>` from the
|
|
4477
|
+
* project catalog, or nothing when the catalog is empty / unsanitary.
|
|
4478
|
+
*/
|
|
4479
|
+
class ProjectCssVariablesStylesheetComponent {
|
|
4480
|
+
get css() {
|
|
4481
|
+
return formatProjectCssVariablesStylesheet(this.publishedKey, this.variables);
|
|
4482
|
+
}
|
|
4483
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: ProjectCssVariablesStylesheetComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
|
|
4484
|
+
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "19.2.25", type: ProjectCssVariablesStylesheetComponent, isStandalone: true, selector: "rulecms-project-css-variables-stylesheet", inputs: { publishedKey: "publishedKey", variables: "variables" }, ngImport: i0, template: `
|
|
4485
|
+
@if (css) {
|
|
4486
|
+
<style data-rulecms-project-css-variables="" [innerText]="css"></style>
|
|
4487
|
+
}
|
|
4488
|
+
`, isInline: true }); }
|
|
4489
|
+
}
|
|
4490
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: ProjectCssVariablesStylesheetComponent, decorators: [{
|
|
4491
|
+
type: Component,
|
|
4492
|
+
args: [{
|
|
4493
|
+
selector: 'rulecms-project-css-variables-stylesheet',
|
|
4494
|
+
standalone: true,
|
|
4495
|
+
template: `
|
|
4496
|
+
@if (css) {
|
|
4497
|
+
<style data-rulecms-project-css-variables="" [innerText]="css"></style>
|
|
4498
|
+
}
|
|
4499
|
+
`,
|
|
4500
|
+
}]
|
|
4501
|
+
}], propDecorators: { publishedKey: [{
|
|
4502
|
+
type: Input,
|
|
4503
|
+
args: [{ required: true }]
|
|
4504
|
+
}], variables: [{
|
|
4505
|
+
type: Input
|
|
4506
|
+
}] } });
|
|
4507
|
+
|
|
4508
|
+
/**
|
|
4509
|
+
* Missing/undefined on a widget GET payload means include. Only an explicit
|
|
4510
|
+
* `false` turns emission off, even if `widgetChrome` is still present.
|
|
4511
|
+
*/
|
|
4512
|
+
function shouldIncludeWidgetChromeOnPublishedWidget(includeWidgetChrome) {
|
|
4513
|
+
return includeWidgetChrome !== false;
|
|
4514
|
+
}
|
|
4515
|
+
|
|
4516
|
+
const PROJECT_WIDGET_CHROME_COLOR_SCHEME_VALUES = [
|
|
4517
|
+
'light',
|
|
4518
|
+
'dark',
|
|
4519
|
+
'light dark',
|
|
4520
|
+
];
|
|
4521
|
+
const PROJECT_WIDGET_CHROME_SCROLLBAR_WIDTH_VALUES = ['auto', 'thin', 'none'];
|
|
4522
|
+
const COLOR_SCHEME_SET = new Set(PROJECT_WIDGET_CHROME_COLOR_SCHEME_VALUES);
|
|
4523
|
+
const SCROLLBAR_WIDTH_SET = new Set(PROJECT_WIDGET_CHROME_SCROLLBAR_WIDTH_VALUES);
|
|
4524
|
+
const REJECTED_IN_VALUE = /[{};]|url\(|@/i;
|
|
4525
|
+
const isSafeColorValue = (value) => typeof value === 'string' &&
|
|
4526
|
+
value.trim() !== '' &&
|
|
4527
|
+
value.trim().length <= 400 &&
|
|
4528
|
+
!REJECTED_IN_VALUE.test(value);
|
|
4529
|
+
const optionalColor = (value) => isSafeColorValue(value) ? value.trim() : undefined;
|
|
4530
|
+
const sanitizeProjectWidgetChrome = (widgetChrome) => {
|
|
4531
|
+
if (!widgetChrome || typeof widgetChrome !== 'object' || Array.isArray(widgetChrome)) {
|
|
4532
|
+
return null;
|
|
4533
|
+
}
|
|
4534
|
+
const selectionBackground = optionalColor(widgetChrome.selectionBackground);
|
|
4535
|
+
const selectionColor = optionalColor(widgetChrome.selectionColor);
|
|
4536
|
+
const caretColor = optionalColor(widgetChrome.caretColor);
|
|
4537
|
+
const scrollbarColor = optionalColor(widgetChrome.scrollbarColor);
|
|
4538
|
+
const sanitized = {
|
|
4539
|
+
...(typeof widgetChrome.colorScheme === 'string' &&
|
|
4540
|
+
COLOR_SCHEME_SET.has(widgetChrome.colorScheme)
|
|
4541
|
+
? { colorScheme: widgetChrome.colorScheme }
|
|
4542
|
+
: {}),
|
|
4543
|
+
...(selectionBackground ? { selectionBackground } : {}),
|
|
4544
|
+
...(selectionColor ? { selectionColor } : {}),
|
|
4545
|
+
...(caretColor ? { caretColor } : {}),
|
|
4546
|
+
...(scrollbarColor ? { scrollbarColor } : {}),
|
|
4547
|
+
...(typeof widgetChrome.scrollbarWidth === 'string' &&
|
|
4548
|
+
SCROLLBAR_WIDTH_SET.has(widgetChrome.scrollbarWidth)
|
|
4549
|
+
? { scrollbarWidth: widgetChrome.scrollbarWidth }
|
|
4550
|
+
: {}),
|
|
4551
|
+
};
|
|
4552
|
+
return Object.keys(sanitized).length > 0 ? sanitized : null;
|
|
4553
|
+
};
|
|
4554
|
+
/**
|
|
4555
|
+
* Color-scheme, caret, and scrollbars on boxed children of the published-key
|
|
4556
|
+
* wrapper; selection on that subtree. Never `:root` / `html` / `body`.
|
|
4557
|
+
*/
|
|
4558
|
+
const formatProjectCssWidgetChromeStylesheet = (publishedKey, widgetChrome, includeWidgetChrome) => {
|
|
4559
|
+
if (!shouldIncludeWidgetChromeOnPublishedWidget(includeWidgetChrome) || !publishedKey) {
|
|
4560
|
+
return null;
|
|
4561
|
+
}
|
|
4562
|
+
const sanitized = sanitizeProjectWidgetChrome(widgetChrome);
|
|
4563
|
+
if (!sanitized) {
|
|
4564
|
+
return null;
|
|
4565
|
+
}
|
|
4566
|
+
const ancestor = `[data-rulecms-published-key="${escapeCssAttributeValue$1(publishedKey)}"]`;
|
|
4567
|
+
const surfaceDeclarations = [];
|
|
4568
|
+
if (sanitized.colorScheme) {
|
|
4569
|
+
surfaceDeclarations.push(` color-scheme: ${sanitized.colorScheme};`);
|
|
4570
|
+
}
|
|
4571
|
+
if (sanitized.caretColor) {
|
|
4572
|
+
surfaceDeclarations.push(` caret-color: ${sanitized.caretColor};`);
|
|
4573
|
+
}
|
|
4574
|
+
if (sanitized.scrollbarWidth) {
|
|
4575
|
+
surfaceDeclarations.push(` scrollbar-width: ${sanitized.scrollbarWidth};`);
|
|
4576
|
+
}
|
|
4577
|
+
if (sanitized.scrollbarColor) {
|
|
4578
|
+
surfaceDeclarations.push(` scrollbar-color: ${sanitized.scrollbarColor};`);
|
|
4579
|
+
}
|
|
4580
|
+
const selectionDeclarations = [];
|
|
4581
|
+
if (sanitized.selectionBackground) {
|
|
4582
|
+
selectionDeclarations.push(` background: ${sanitized.selectionBackground};`);
|
|
4583
|
+
}
|
|
4584
|
+
if (sanitized.selectionColor) {
|
|
4585
|
+
selectionDeclarations.push(` color: ${sanitized.selectionColor};`);
|
|
4586
|
+
}
|
|
4587
|
+
const blocks = [];
|
|
4588
|
+
if (surfaceDeclarations.length > 0) {
|
|
4589
|
+
blocks.push(`${ancestor} > * {\n${surfaceDeclarations.join('\n')}\n}`);
|
|
4590
|
+
}
|
|
4591
|
+
if (selectionDeclarations.length > 0) {
|
|
4592
|
+
blocks.push(`${ancestor} > * ::selection {\n${selectionDeclarations.join('\n')}\n}`);
|
|
4593
|
+
}
|
|
4594
|
+
return blocks.length > 0 ? blocks.join('\n') : null;
|
|
4595
|
+
};
|
|
4596
|
+
|
|
4597
|
+
/**
|
|
4598
|
+
* Emits one `<style data-rulecms-project-widget-chrome>` from the project
|
|
4599
|
+
* catalog, or nothing when the catalog is empty / unsanitary.
|
|
4600
|
+
*/
|
|
4601
|
+
class ProjectCssWidgetChromeStylesheetComponent {
|
|
4602
|
+
get css() {
|
|
4603
|
+
return formatProjectCssWidgetChromeStylesheet(this.publishedKey, this.widgetChrome);
|
|
4604
|
+
}
|
|
4605
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: ProjectCssWidgetChromeStylesheetComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
|
|
4606
|
+
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "19.2.25", type: ProjectCssWidgetChromeStylesheetComponent, isStandalone: true, selector: "rulecms-project-css-widget-chrome-stylesheet", inputs: { publishedKey: "publishedKey", widgetChrome: "widgetChrome" }, ngImport: i0, template: `
|
|
4607
|
+
@if (css) {
|
|
4608
|
+
<style data-rulecms-project-widget-chrome="" [innerText]="css"></style>
|
|
4609
|
+
}
|
|
4610
|
+
`, isInline: true }); }
|
|
4611
|
+
}
|
|
4612
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: ProjectCssWidgetChromeStylesheetComponent, decorators: [{
|
|
4613
|
+
type: Component,
|
|
4614
|
+
args: [{
|
|
4615
|
+
selector: 'rulecms-project-css-widget-chrome-stylesheet',
|
|
4616
|
+
standalone: true,
|
|
4617
|
+
template: `
|
|
4618
|
+
@if (css) {
|
|
4619
|
+
<style data-rulecms-project-widget-chrome="" [innerText]="css"></style>
|
|
4620
|
+
}
|
|
4621
|
+
`,
|
|
4622
|
+
}]
|
|
4623
|
+
}], propDecorators: { publishedKey: [{
|
|
4624
|
+
type: Input,
|
|
4625
|
+
args: [{ required: true }]
|
|
4626
|
+
}], widgetChrome: [{
|
|
4627
|
+
type: Input
|
|
4628
|
+
}] } });
|
|
4629
|
+
|
|
4630
|
+
/**
|
|
4631
|
+
* Missing/undefined on a widget GET payload means wrap when `classLayer` is
|
|
4632
|
+
* set. Only an explicit `false` keeps class emit unlayered.
|
|
4633
|
+
*/
|
|
4634
|
+
function shouldIncludeClassLayerOnPublishedWidget(includeClassLayer) {
|
|
4635
|
+
return includeClassLayer !== false;
|
|
4636
|
+
}
|
|
4637
|
+
|
|
4638
|
+
function transformChildCollections(childCollections) {
|
|
4639
|
+
const transformed = {};
|
|
4640
|
+
Object.entries(childCollections).forEach(([key, collection]) => {
|
|
4641
|
+
const collectionToUse = { ...collection };
|
|
4642
|
+
if (collectionToUse.itemList) {
|
|
4643
|
+
try {
|
|
4644
|
+
collectionToUse.collectionRows =
|
|
4645
|
+
typeof collectionToUse.itemList === 'string'
|
|
4646
|
+
? JSON.parse(collectionToUse.itemList)
|
|
4647
|
+
: collectionToUse.itemList;
|
|
4648
|
+
}
|
|
4649
|
+
catch (error) {
|
|
4650
|
+
console.error(`Failed to parse itemList for collection ${key}:`, error);
|
|
4651
|
+
collectionToUse.collectionRows = { rows: [] };
|
|
4652
|
+
}
|
|
4653
|
+
}
|
|
4654
|
+
let collectionKey = `${collectionToUse.name}$${key}`;
|
|
4655
|
+
if (collectionToUse.parentId) {
|
|
4656
|
+
collectionKey = `${collectionKey}@${collectionToUse.parentId}`;
|
|
4657
|
+
}
|
|
4658
|
+
transformed[collectionKey] = collectionToUse;
|
|
4659
|
+
});
|
|
4660
|
+
return transformed;
|
|
4661
|
+
}
|
|
4662
|
+
function parseDisplayItemList(widget) {
|
|
4663
|
+
return typeof widget.itemList === 'string'
|
|
4664
|
+
? JSON.parse(widget.itemList)
|
|
4665
|
+
: widget.itemList;
|
|
4666
|
+
}
|
|
4667
|
+
/** Transform raw widget API data into render-ready displayItemList + collections. */
|
|
4668
|
+
function prepareRuleCMSWidgetData(raw) {
|
|
4669
|
+
const fontFaces = sanitizeProjectFontFaces(raw.fontFaces);
|
|
4670
|
+
const keyframes = sanitizeProjectCssKeyframes(raw.keyframes);
|
|
4671
|
+
const themes = sanitizeProjectCssThemes(raw.themes);
|
|
4672
|
+
const cssProperties = sanitizeProjectCssProperties(raw.cssProperties);
|
|
4673
|
+
const widgetChrome = sanitizeProjectWidgetChrome(raw.widgetChrome);
|
|
4674
|
+
const positionTry = sanitizeProjectCssPositionTry(raw.positionTry);
|
|
4675
|
+
const classLayer = shouldIncludeClassLayerOnPublishedWidget(raw.includeClassLayer) &&
|
|
4676
|
+
isProjectCssClassLayer(raw.classLayer)
|
|
4677
|
+
? raw.classLayer
|
|
4678
|
+
: undefined;
|
|
4679
|
+
return {
|
|
4680
|
+
displayItemList: parseDisplayItemList(raw.widget),
|
|
4681
|
+
widgetCollections: transformChildCollections(raw.childCollections),
|
|
4682
|
+
...(raw.libraries ? { libraries: raw.libraries } : {}),
|
|
4683
|
+
...(shouldIncludeCssVariablesOnPublishedWidget(raw.includeCssVariables) &&
|
|
4684
|
+
raw.cssVariables &&
|
|
4685
|
+
Object.keys(raw.cssVariables).length > 0
|
|
4686
|
+
? { cssVariables: raw.cssVariables }
|
|
4687
|
+
: {}),
|
|
4688
|
+
...(shouldIncludeClassDefinitionsOnPublishedWidget(raw.includeClassDefinitions) &&
|
|
4689
|
+
raw.classDefinitions &&
|
|
4690
|
+
Object.keys(raw.classDefinitions).length > 0
|
|
4691
|
+
? { classDefinitions: raw.classDefinitions }
|
|
4692
|
+
: {}),
|
|
4693
|
+
...(shouldIncludeFontFacesOnPublishedWidget(raw.includeFontFaces) && fontFaces.length > 0
|
|
4694
|
+
? { fontFaces }
|
|
4695
|
+
: {}),
|
|
4696
|
+
...(shouldIncludeKeyframesOnPublishedWidget(raw.includeKeyframes) &&
|
|
4697
|
+
Object.keys(keyframes).length > 0
|
|
4698
|
+
? { keyframes }
|
|
4699
|
+
: {}),
|
|
4700
|
+
...(shouldIncludeThemesOnPublishedWidget(raw.includeThemes) && themes.length > 0
|
|
4701
|
+
? { themes }
|
|
4702
|
+
: {}),
|
|
4703
|
+
...(shouldIncludeCssPropertiesOnPublishedWidget(raw.includeCssProperties) &&
|
|
4704
|
+
cssProperties.length > 0
|
|
4705
|
+
? { cssProperties }
|
|
4706
|
+
: {}),
|
|
4707
|
+
...(shouldIncludeWidgetChromeOnPublishedWidget(raw.includeWidgetChrome) && widgetChrome
|
|
4708
|
+
? { widgetChrome }
|
|
4709
|
+
: {}),
|
|
4710
|
+
...(classLayer ? { classLayer } : {}),
|
|
4711
|
+
...(shouldIncludePositionTryOnPublishedWidget(raw.includePositionTry) &&
|
|
4712
|
+
Object.keys(positionTry).length > 0
|
|
4713
|
+
? { positionTry }
|
|
4714
|
+
: {}),
|
|
4715
|
+
};
|
|
4716
|
+
}
|
|
4717
|
+
|
|
4718
|
+
function resolveSourceComponentsPluginSync(params) {
|
|
4719
|
+
const registry = params.registry ?? createComponentLibraryRegistry();
|
|
4720
|
+
const referenced = collectReferencedLibraryIds({
|
|
4721
|
+
displayItemList: params.displayItemList,
|
|
4722
|
+
widgetCollections: params.widgetCollections,
|
|
4723
|
+
});
|
|
4724
|
+
return registry.resolveSync({ registrations: params.libraries, referenced });
|
|
4725
|
+
}
|
|
4726
|
+
function resolveSourceComponentsPlugin(params) {
|
|
4727
|
+
const registry = params.registry ?? createComponentLibraryRegistry();
|
|
4728
|
+
const referenced = collectReferencedLibraryIds({
|
|
4729
|
+
displayItemList: params.displayItemList,
|
|
4730
|
+
widgetCollections: params.widgetCollections,
|
|
4731
|
+
});
|
|
4732
|
+
return registry.resolve({ registrations: params.libraries, referenced });
|
|
4733
|
+
}
|
|
4734
|
+
|
|
4735
|
+
const loadingContainerStyle = {
|
|
4736
|
+
display: 'flex',
|
|
4737
|
+
justifyContent: 'center',
|
|
4738
|
+
alignItems: 'center',
|
|
4739
|
+
padding: '3rem',
|
|
4740
|
+
color: '#e2e8f0',
|
|
4741
|
+
};
|
|
4742
|
+
const spinnerContainerStyle = {
|
|
4743
|
+
display: 'flex',
|
|
4744
|
+
alignItems: 'center',
|
|
4745
|
+
gap: '1rem',
|
|
4746
|
+
};
|
|
4747
|
+
const spinnerStyle = {
|
|
4748
|
+
width: '40px',
|
|
4749
|
+
height: '40px',
|
|
4750
|
+
border: '4px solid #4a5568',
|
|
4751
|
+
borderTopColor: '#63b3ed',
|
|
4752
|
+
borderRadius: '50%',
|
|
4753
|
+
animation: 'spin 1s linear infinite',
|
|
4754
|
+
};
|
|
4755
|
+
const errorContainerStyle = {
|
|
4756
|
+
padding: '1.5rem',
|
|
4757
|
+
backgroundColor: '#742a2a',
|
|
4758
|
+
border: '1px solid #9b2c2c',
|
|
4759
|
+
borderRadius: '8px',
|
|
4760
|
+
color: '#fed7d7',
|
|
4761
|
+
};
|
|
4762
|
+
const errorTitleStyle = {
|
|
4763
|
+
fontSize: '16px',
|
|
4764
|
+
fontWeight: '600',
|
|
4765
|
+
marginBottom: '0.5rem',
|
|
4766
|
+
color: '#feb2b2',
|
|
4767
|
+
};
|
|
4768
|
+
const errorMessageStyle = {
|
|
4769
|
+
fontSize: '14px',
|
|
4770
|
+
color: '#fed7d7',
|
|
4771
|
+
};
|
|
4772
|
+
const globalStyles = `
|
|
4773
|
+
@keyframes spin {
|
|
4774
|
+
from {
|
|
4775
|
+
transform: rotate(0deg);
|
|
4776
|
+
}
|
|
4777
|
+
to {
|
|
4778
|
+
transform: rotate(360deg);
|
|
4779
|
+
}
|
|
4780
|
+
}
|
|
4781
|
+
`;
|
|
4782
|
+
const RULECMS_PUBLISHED_KEY_ATTRIBUTE = 'data-rulecms-published-key';
|
|
4783
|
+
|
|
4784
|
+
class RuleCMSWidgetComponent {
|
|
4785
|
+
constructor(context, errorHandler) {
|
|
4786
|
+
this.context = context;
|
|
4787
|
+
this.errorHandler = errorHandler;
|
|
4788
|
+
/**
|
|
4789
|
+
* `'client-fetch'` (default) fetches in the browser.
|
|
4790
|
+
* `'pre-fetched'` renders `initialData` with CSS breakpoint variants.
|
|
4791
|
+
*/
|
|
4792
|
+
this.mode = 'client-fetch';
|
|
4793
|
+
this.publishedKeyAttribute = RULECMS_PUBLISHED_KEY_ATTRIBUTE;
|
|
4794
|
+
this.loadingContainerStyle = loadingContainerStyle;
|
|
4795
|
+
this.spinnerContainerStyle = spinnerContainerStyle;
|
|
4796
|
+
this.spinnerStyle = spinnerStyle;
|
|
4797
|
+
this.errorContainerStyle = errorContainerStyle;
|
|
4798
|
+
this.errorTitleStyle = errorTitleStyle;
|
|
4799
|
+
this.errorMessageStyle = errorMessageStyle;
|
|
4800
|
+
this.loading = false;
|
|
4801
|
+
this.error = null;
|
|
4802
|
+
this.preparedData = null;
|
|
4803
|
+
this.sourceComponentsPlugin = null;
|
|
4804
|
+
this.useBreakpointVariants = false;
|
|
4805
|
+
this.abortController = null;
|
|
4806
|
+
this.lastFetchKey = null;
|
|
4807
|
+
this.stylesInjected = false;
|
|
4808
|
+
}
|
|
4809
|
+
get plugins() {
|
|
4810
|
+
return { sourceComponents: this.sourceComponentsPlugin ?? undefined };
|
|
4811
|
+
}
|
|
4812
|
+
ngOnInit() {
|
|
4813
|
+
this.syncFromInputs();
|
|
4814
|
+
}
|
|
4815
|
+
ngOnChanges(_changes) {
|
|
4816
|
+
this.syncFromInputs();
|
|
4817
|
+
}
|
|
4818
|
+
ngOnDestroy() {
|
|
4819
|
+
this.abortController?.abort();
|
|
4820
|
+
}
|
|
4821
|
+
syncFromInputs() {
|
|
4822
|
+
this.useBreakpointVariants = this.mode === 'pre-fetched';
|
|
4823
|
+
if (this.mode === 'pre-fetched') {
|
|
4824
|
+
this.preparedData = this.initialData ?? null;
|
|
4825
|
+
this.loading = false;
|
|
4826
|
+
this.error = null;
|
|
4827
|
+
this.resolveLibraries();
|
|
4828
|
+
this.warnUnmatched();
|
|
4829
|
+
return;
|
|
4830
|
+
}
|
|
4831
|
+
this.ensureSpinnerStyles();
|
|
4832
|
+
this.fetchClient();
|
|
4833
|
+
}
|
|
4834
|
+
resolveLibraries() {
|
|
4835
|
+
if (!this.preparedData) {
|
|
4836
|
+
this.sourceComponentsPlugin = null;
|
|
4837
|
+
return;
|
|
4838
|
+
}
|
|
4839
|
+
const libraries = this.libraries ?? this.context?.libraries;
|
|
4840
|
+
const registry = this.context?.libraryRegistry;
|
|
4841
|
+
try {
|
|
4842
|
+
const sync = resolveSourceComponentsPluginSync({
|
|
4843
|
+
displayItemList: this.preparedData.displayItemList,
|
|
3630
4844
|
widgetCollections: this.preparedData.widgetCollections,
|
|
3631
4845
|
libraries,
|
|
3632
4846
|
registry,
|
|
@@ -3738,10 +4952,39 @@ class RuleCMSWidgetComponent {
|
|
|
3738
4952
|
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: RuleCMSWidgetComponent, deps: [{ token: RuleCMSWidgetContextService, optional: true }, { token: ErrorHandler, optional: true }], target: i0.ɵɵFactoryTarget.Component }); }
|
|
3739
4953
|
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "19.2.25", type: RuleCMSWidgetComponent, isStandalone: true, selector: "rulecms-widget", inputs: { publishedKey: "publishedKey", token: "token", endpoint: "endpoint", mode: "mode", initialData: "initialData", libraries: "libraries", componentProps: "componentProps", mounts: "mounts" }, host: { styleAttribute: "display: contents" }, usesOnChanges: true, ngImport: i0, template: `
|
|
3740
4954
|
<span [attr.data-rulecms-published-key]="publishedKey" style="display: contents">
|
|
4955
|
+
<rulecms-project-css-fonts-stylesheet
|
|
4956
|
+
[publishedKey]="publishedKey"
|
|
4957
|
+
[fonts]="preparedData?.fontFaces"
|
|
4958
|
+
/>
|
|
4959
|
+
<rulecms-project-css-keyframes-stylesheet
|
|
4960
|
+
[publishedKey]="publishedKey"
|
|
4961
|
+
[keyframes]="preparedData?.keyframes"
|
|
4962
|
+
/>
|
|
4963
|
+
<rulecms-project-css-themes-stylesheet
|
|
4964
|
+
[publishedKey]="publishedKey"
|
|
4965
|
+
[themes]="preparedData?.themes"
|
|
4966
|
+
/>
|
|
4967
|
+
<rulecms-project-css-properties-stylesheet
|
|
4968
|
+
[publishedKey]="publishedKey"
|
|
4969
|
+
[cssProperties]="preparedData?.cssProperties"
|
|
4970
|
+
/>
|
|
4971
|
+
<rulecms-project-css-widget-chrome-stylesheet
|
|
4972
|
+
[publishedKey]="publishedKey"
|
|
4973
|
+
[widgetChrome]="preparedData?.widgetChrome"
|
|
4974
|
+
/>
|
|
4975
|
+
<rulecms-project-css-position-try-stylesheet
|
|
4976
|
+
[publishedKey]="publishedKey"
|
|
4977
|
+
[positionTry]="preparedData?.positionTry"
|
|
4978
|
+
/>
|
|
3741
4979
|
<rulecms-project-css-variables-stylesheet
|
|
3742
4980
|
[publishedKey]="publishedKey"
|
|
3743
4981
|
[variables]="preparedData?.cssVariables"
|
|
3744
4982
|
/>
|
|
4983
|
+
<rulecms-project-css-classes-stylesheet
|
|
4984
|
+
[publishedKey]="publishedKey"
|
|
4985
|
+
[classes]="preparedData?.classDefinitions"
|
|
4986
|
+
[classLayer]="preparedData?.classLayer"
|
|
4987
|
+
/>
|
|
3745
4988
|
@if (mode !== 'pre-fetched' && loading) {
|
|
3746
4989
|
<div [ngStyle]="loadingContainerStyle">
|
|
3747
4990
|
<div [ngStyle]="spinnerContainerStyle">
|
|
@@ -3782,7 +5025,7 @@ class RuleCMSWidgetComponent {
|
|
|
3782
5025
|
}
|
|
3783
5026
|
}
|
|
3784
5027
|
</span>
|
|
3785
|
-
`, isInline: true, dependencies: [{ kind: "directive", type: NgStyle, selector: "[ngStyle]", inputs: ["ngStyle"] }, { kind: "component", type: BreakpointVariantRenderComponent, selector: "rulecms-breakpoint-variants", inputs: ["displayItemList", "widgetCollections", "plugins", "componentProps", "mounts", "scopeIdInput"] }, { kind: "component", type: RenderComponentsComponent, selector: "rulecms-render-components", inputs: ["displayItemList", "isComposeMode", "isWithinCollection", "widgetCollections", "showDropContainers", "reduxDeviceDisplayType", "plugins", "componentProps", "mounts"] }, { kind: "component", type: ProjectCssVariablesStylesheetComponent, selector: "rulecms-project-css-variables-stylesheet", inputs: ["publishedKey", "variables"] }] }); }
|
|
5028
|
+
`, isInline: true, dependencies: [{ kind: "directive", type: NgStyle, selector: "[ngStyle]", inputs: ["ngStyle"] }, { kind: "component", type: BreakpointVariantRenderComponent, selector: "rulecms-breakpoint-variants", inputs: ["displayItemList", "widgetCollections", "plugins", "componentProps", "mounts", "scopeIdInput"] }, { kind: "component", type: RenderComponentsComponent, selector: "rulecms-render-components", inputs: ["displayItemList", "isComposeMode", "isWithinCollection", "widgetCollections", "showDropContainers", "reduxDeviceDisplayType", "plugins", "componentProps", "mounts"] }, { kind: "component", type: ProjectCssVariablesStylesheetComponent, selector: "rulecms-project-css-variables-stylesheet", inputs: ["publishedKey", "variables"] }, { kind: "component", type: ProjectCssClassesStylesheetComponent, selector: "rulecms-project-css-classes-stylesheet", inputs: ["publishedKey", "classes", "classLayer"] }, { kind: "component", type: ProjectCssFontsStylesheetComponent, selector: "rulecms-project-css-fonts-stylesheet", inputs: ["publishedKey", "fonts", "includeFontFaces"] }, { kind: "component", type: ProjectCssKeyframesStylesheetComponent, selector: "rulecms-project-css-keyframes-stylesheet", inputs: ["publishedKey", "keyframes"] }, { kind: "component", type: ProjectCssThemesStylesheetComponent, selector: "rulecms-project-css-themes-stylesheet", inputs: ["publishedKey", "themes"] }, { kind: "component", type: ProjectCssPropertiesStylesheetComponent, selector: "rulecms-project-css-properties-stylesheet", inputs: ["publishedKey", "cssProperties"] }, { kind: "component", type: ProjectCssWidgetChromeStylesheetComponent, selector: "rulecms-project-css-widget-chrome-stylesheet", inputs: ["publishedKey", "widgetChrome"] }, { kind: "component", type: ProjectCssPositionTryStylesheetComponent, selector: "rulecms-project-css-position-try-stylesheet", inputs: ["publishedKey", "positionTry"] }] }); }
|
|
3786
5029
|
}
|
|
3787
5030
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: RuleCMSWidgetComponent, decorators: [{
|
|
3788
5031
|
type: Component,
|
|
@@ -3794,13 +5037,49 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.25", ngImpo
|
|
|
3794
5037
|
BreakpointVariantRenderComponent,
|
|
3795
5038
|
RenderComponentsComponent,
|
|
3796
5039
|
ProjectCssVariablesStylesheetComponent,
|
|
5040
|
+
ProjectCssClassesStylesheetComponent,
|
|
5041
|
+
ProjectCssFontsStylesheetComponent,
|
|
5042
|
+
ProjectCssKeyframesStylesheetComponent,
|
|
5043
|
+
ProjectCssThemesStylesheetComponent,
|
|
5044
|
+
ProjectCssPropertiesStylesheetComponent,
|
|
5045
|
+
ProjectCssWidgetChromeStylesheetComponent,
|
|
5046
|
+
ProjectCssPositionTryStylesheetComponent,
|
|
3797
5047
|
],
|
|
3798
5048
|
template: `
|
|
3799
5049
|
<span [attr.data-rulecms-published-key]="publishedKey" style="display: contents">
|
|
5050
|
+
<rulecms-project-css-fonts-stylesheet
|
|
5051
|
+
[publishedKey]="publishedKey"
|
|
5052
|
+
[fonts]="preparedData?.fontFaces"
|
|
5053
|
+
/>
|
|
5054
|
+
<rulecms-project-css-keyframes-stylesheet
|
|
5055
|
+
[publishedKey]="publishedKey"
|
|
5056
|
+
[keyframes]="preparedData?.keyframes"
|
|
5057
|
+
/>
|
|
5058
|
+
<rulecms-project-css-themes-stylesheet
|
|
5059
|
+
[publishedKey]="publishedKey"
|
|
5060
|
+
[themes]="preparedData?.themes"
|
|
5061
|
+
/>
|
|
5062
|
+
<rulecms-project-css-properties-stylesheet
|
|
5063
|
+
[publishedKey]="publishedKey"
|
|
5064
|
+
[cssProperties]="preparedData?.cssProperties"
|
|
5065
|
+
/>
|
|
5066
|
+
<rulecms-project-css-widget-chrome-stylesheet
|
|
5067
|
+
[publishedKey]="publishedKey"
|
|
5068
|
+
[widgetChrome]="preparedData?.widgetChrome"
|
|
5069
|
+
/>
|
|
5070
|
+
<rulecms-project-css-position-try-stylesheet
|
|
5071
|
+
[publishedKey]="publishedKey"
|
|
5072
|
+
[positionTry]="preparedData?.positionTry"
|
|
5073
|
+
/>
|
|
3800
5074
|
<rulecms-project-css-variables-stylesheet
|
|
3801
5075
|
[publishedKey]="publishedKey"
|
|
3802
5076
|
[variables]="preparedData?.cssVariables"
|
|
3803
5077
|
/>
|
|
5078
|
+
<rulecms-project-css-classes-stylesheet
|
|
5079
|
+
[publishedKey]="publishedKey"
|
|
5080
|
+
[classes]="preparedData?.classDefinitions"
|
|
5081
|
+
[classLayer]="preparedData?.classLayer"
|
|
5082
|
+
/>
|
|
3804
5083
|
@if (mode !== 'pre-fetched' && loading) {
|
|
3805
5084
|
<div [ngStyle]="loadingContainerStyle">
|
|
3806
5085
|
<div [ngStyle]="spinnerContainerStyle">
|