@rulecms/widget-angular 0.6.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.
Files changed (54) hide show
  1. package/fesm2022/rulecms-widget-angular.mjs +1300 -167
  2. package/fesm2022/rulecms-widget-angular.mjs.map +1 -1
  3. package/lib/helpers/get-component-attributes-and-styles.d.ts.map +1 -1
  4. package/lib/project-css-classes/format-project-css-classes-stylesheet.d.ts +10 -1
  5. package/lib/project-css-classes/format-project-css-classes-stylesheet.d.ts.map +1 -1
  6. package/lib/project-css-classes/include-project-css-layers-on-published-widget.d.ts +6 -0
  7. package/lib/project-css-classes/include-project-css-layers-on-published-widget.d.ts.map +1 -0
  8. package/lib/project-css-classes/project-css-classes-stylesheet.component.d.ts +3 -2
  9. package/lib/project-css-classes/project-css-classes-stylesheet.component.d.ts.map +1 -1
  10. package/lib/project-css-fonts/format-project-css-fonts-stylesheet.d.ts +34 -0
  11. package/lib/project-css-fonts/format-project-css-fonts-stylesheet.d.ts.map +1 -0
  12. package/lib/project-css-fonts/include-project-css-fonts-on-published-widget.d.ts +6 -0
  13. package/lib/project-css-fonts/include-project-css-fonts-on-published-widget.d.ts.map +1 -0
  14. package/lib/project-css-fonts/project-css-fonts-stylesheet.component.d.ts +16 -0
  15. package/lib/project-css-fonts/project-css-fonts-stylesheet.component.d.ts.map +1 -0
  16. package/lib/project-css-keyframes/format-project-css-keyframes-stylesheet.d.ts +11 -0
  17. package/lib/project-css-keyframes/format-project-css-keyframes-stylesheet.d.ts.map +1 -0
  18. package/lib/project-css-keyframes/include-project-css-keyframes-on-published-widget.d.ts +6 -0
  19. package/lib/project-css-keyframes/include-project-css-keyframes-on-published-widget.d.ts.map +1 -0
  20. package/lib/project-css-keyframes/project-css-keyframes-stylesheet.component.d.ts +14 -0
  21. package/lib/project-css-keyframes/project-css-keyframes-stylesheet.component.d.ts.map +1 -0
  22. package/lib/project-css-position-try/format-project-css-position-try-stylesheet.d.ts +11 -0
  23. package/lib/project-css-position-try/format-project-css-position-try-stylesheet.d.ts.map +1 -0
  24. package/lib/project-css-position-try/include-project-css-position-try-on-published-widget.d.ts +6 -0
  25. package/lib/project-css-position-try/include-project-css-position-try-on-published-widget.d.ts.map +1 -0
  26. package/lib/project-css-position-try/project-css-position-try-stylesheet.component.d.ts +14 -0
  27. package/lib/project-css-position-try/project-css-position-try-stylesheet.component.d.ts.map +1 -0
  28. package/lib/project-css-properties/format-project-css-properties-stylesheet.d.ts +15 -0
  29. package/lib/project-css-properties/format-project-css-properties-stylesheet.d.ts.map +1 -0
  30. package/lib/project-css-properties/include-project-css-properties-on-published-widget.d.ts +6 -0
  31. package/lib/project-css-properties/include-project-css-properties-on-published-widget.d.ts.map +1 -0
  32. package/lib/project-css-properties/project-css-properties-stylesheet.component.d.ts +14 -0
  33. package/lib/project-css-properties/project-css-properties-stylesheet.component.d.ts.map +1 -0
  34. package/lib/project-css-themes/format-project-css-themes-stylesheet.d.ts +24 -0
  35. package/lib/project-css-themes/format-project-css-themes-stylesheet.d.ts.map +1 -0
  36. package/lib/project-css-themes/include-project-css-themes-on-published-widget.d.ts +6 -0
  37. package/lib/project-css-themes/include-project-css-themes-on-published-widget.d.ts.map +1 -0
  38. package/lib/project-css-themes/project-css-themes-stylesheet.component.d.ts +14 -0
  39. package/lib/project-css-themes/project-css-themes-stylesheet.component.d.ts.map +1 -0
  40. package/lib/project-css-variables/format-project-css-variables-stylesheet.d.ts +1 -1
  41. package/lib/project-css-variables/format-project-css-variables-stylesheet.d.ts.map +1 -1
  42. package/lib/project-css-variables/include-project-css-variables-on-published-widget.d.ts +4 -9
  43. package/lib/project-css-variables/include-project-css-variables-on-published-widget.d.ts.map +1 -1
  44. package/lib/project-css-widget-chrome/format-project-css-widget-chrome-stylesheet.d.ts +19 -0
  45. package/lib/project-css-widget-chrome/format-project-css-widget-chrome-stylesheet.d.ts.map +1 -0
  46. package/lib/project-css-widget-chrome/include-project-css-widget-chrome-on-published-widget.d.ts +6 -0
  47. package/lib/project-css-widget-chrome/include-project-css-widget-chrome-on-published-widget.d.ts.map +1 -0
  48. package/lib/project-css-widget-chrome/project-css-widget-chrome-stylesheet.component.d.ts +14 -0
  49. package/lib/project-css-widget-chrome/project-css-widget-chrome-stylesheet.component.d.ts.map +1 -0
  50. package/lib/widget/prepare-rule-cms-widget-data.d.ts.map +1 -1
  51. package/lib/widget/rule-cms-widget.component.d.ts.map +1 -1
  52. package/lib/widget/widget-data.types.d.ts +98 -16
  53. package/lib/widget/widget-data.types.d.ts.map +1 -1
  54. 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: deriveDisplayFlexIfNeeded(componentStyles),
1723
+ componentStyles: stylesForDevice,
1713
1724
  };
1714
1725
  }
1715
1726
 
@@ -3382,19 +3393,39 @@ function shouldIncludeClassDefinitionsOnPublishedWidget(includeClassDefinitions)
3382
3393
  return includeClassDefinitions !== false;
3383
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$1 = (value) => value.replace(/\\/g, '\\\\').replace(/"/g, '\\"');
3420
+ const escapeCssAttributeValue$2 = (value) => value.replace(/\\/g, '\\\\').replace(/"/g, '\\"');
3390
3421
  /** Escape a class name for use after `.` (`/` → `\/`). */
3391
- const escapeCssClassName = (name) => name.replace(/[^A-Za-z0-9_-]/g, (char) => `\\${char}`);
3422
+ const escapeCssClassName = (name) => name.replace(/[^A-Za-z0-9_-]/g, char => `\\${char}`);
3392
3423
  const REJECTED_IN_BODY = ['</', '<script', '@import', 'javascript:', 'vbscript:', 'expression('];
3393
3424
  // eslint-disable-next-line no-control-regex -- control characters are what this matches
3394
- const REJECTED_CONTROL_CHARACTERS = /[\u0000-\u0008\u000b\u000c\u000e-\u001f\u007f]/;
3425
+ const REJECTED_CONTROL_CHARACTERS$2 = /[\u0000-\u0008\u000b\u000c\u000e-\u001f\u007f]/;
3395
3426
  const DISALLOWED_IN_NAME = /[\s{};"]/;
3396
- const ALLOWED_NAME = /^[A-Za-z0-9_:%./[\]%-]+$/;
3397
- const isBraceBalanced = (value) => {
3427
+ const ALLOWED_NAME$2 = /^[A-Za-z0-9_:%./[\]%-]+$/;
3428
+ const isBraceBalanced$1 = (value) => {
3398
3429
  let depth = 0;
3399
3430
  for (const char of value) {
3400
3431
  if (char === '{') {
@@ -3414,18 +3445,18 @@ const isCssClassName = (value) => {
3414
3445
  if (!name || name.length > 200 || name.startsWith('.') || DISALLOWED_IN_NAME.test(name)) {
3415
3446
  return false;
3416
3447
  }
3417
- return ALLOWED_NAME.test(name);
3448
+ return ALLOWED_NAME$2.test(name);
3418
3449
  };
3419
3450
  const isCssClassDeclarationBody = (value) => {
3420
3451
  const trimmed = value.trim();
3421
3452
  if (!trimmed || trimmed.length > 4000) {
3422
3453
  return false;
3423
3454
  }
3424
- if (REJECTED_CONTROL_CHARACTERS.test(trimmed) || !isBraceBalanced(trimmed)) {
3455
+ if (REJECTED_CONTROL_CHARACTERS$2.test(trimmed) || !isBraceBalanced$1(trimmed)) {
3425
3456
  return false;
3426
3457
  }
3427
3458
  const lowered = trimmed.toLowerCase();
3428
- return !REJECTED_IN_BODY.some((rejected) => lowered.includes(rejected));
3459
+ return !REJECTED_IN_BODY.some(rejected => lowered.includes(rejected));
3429
3460
  };
3430
3461
  const sanitizeForStylesheet$1 = (classes) => {
3431
3462
  if (!classes) {
@@ -3445,15 +3476,15 @@ const sanitizeForStylesheet$1 = (classes) => {
3445
3476
  }
3446
3477
  return sanitized;
3447
3478
  };
3448
- const indentDeclarationBody = (body) => body
3479
+ const indentDeclarationBody$1 = (body) => body
3449
3480
  .split('\n')
3450
- .map((line) => ` ${line}`)
3481
+ .map(line => ` ${line}`)
3451
3482
  .join('\n');
3452
3483
  /**
3453
3484
  * Descendant class rules under this widget’s published-key span.
3454
3485
  * Empty / flag-off / unsanitary catalogs return null so the caller omits `<style>`.
3455
3486
  */
3456
- const formatProjectCssClassesStylesheet = (publishedKey, classes, includeClassDefinitions) => {
3487
+ const formatProjectCssClassesStylesheet = (publishedKey, classes, includeClassDefinitions, classLayer) => {
3457
3488
  if (!shouldIncludeClassDefinitionsOnPublishedWidget(includeClassDefinitions)) {
3458
3489
  return null;
3459
3490
  }
@@ -3462,12 +3493,14 @@ const formatProjectCssClassesStylesheet = (publishedKey, classes, includeClassDe
3462
3493
  if (names.length === 0 || !publishedKey) {
3463
3494
  return null;
3464
3495
  }
3465
- const ancestor = `[data-rulecms-published-key="${escapeCssAttributeValue$1(publishedKey)}"]`;
3466
- return names
3496
+ const ancestor = `[data-rulecms-published-key="${escapeCssAttributeValue$2(publishedKey)}"]`;
3497
+ const css = names
3467
3498
  .sort((left, right) => left.localeCompare(right))
3468
- .map((name) => `${ancestor} .${escapeCssClassName(name)} {\n${indentDeclarationBody(sanitized[name])}\n}`)
3499
+ .map(name => `${ancestor} .${escapeCssClassName(name)} {\n${indentDeclarationBody$1(sanitized[name])}\n}`)
3469
3500
  .join('\n');
3501
+ return wrapProjectCssClassesStylesheetInLayer(css, classLayer);
3470
3502
  };
3503
+ const formatProjectCssClassesStylesheetInLayer = (publishedKey, classes, classLayer, includeClassDefinitions) => formatProjectCssClassesStylesheet(publishedKey, classes, includeClassDefinitions, classLayer);
3471
3504
 
3472
3505
  /**
3473
3506
  * Emits one scoped `<style data-rulecms-project-class-definitions>` from the
@@ -3475,10 +3508,10 @@ const formatProjectCssClassesStylesheet = (publishedKey, classes, includeClassDe
3475
3508
  */
3476
3509
  class ProjectCssClassesStylesheetComponent {
3477
3510
  get css() {
3478
- return formatProjectCssClassesStylesheet(this.publishedKey, this.classes);
3511
+ return formatProjectCssClassesStylesheet(this.publishedKey, this.classes, undefined, this.classLayer);
3479
3512
  }
3480
3513
  static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: ProjectCssClassesStylesheetComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
3481
- 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" }, ngImport: i0, template: `
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: `
3482
3515
  @if (css) {
3483
3516
  <style data-rulecms-project-class-definitions="" [innerText]="css"></style>
3484
3517
  }
@@ -3500,205 +3533,1249 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.25", ngImpo
3500
3533
  args: [{ required: true }]
3501
3534
  }], classes: [{
3502
3535
  type: Input
3536
+ }], classLayer: [{
3537
+ type: Input
3503
3538
  }] } });
3504
3539
 
3505
3540
  /**
3506
- * When true, a non-empty `cssVariables` object on the widget GET payload is
3507
- * emitted as one scoped `<style>` on the published widget.
3508
- *
3509
- * TODO: project setting — the customer turns this off if the host stylesheet
3510
- * already defines these tokens. Hardcoded on for this iteration.
3511
- *
3512
- * Class definitions (`classDefinitions` / `includeClassDefinitions` on the
3513
- * same GET) are a separate catalog; see `project-css-classes/`.
3541
+ * Missing/undefined on a widget GET payload means include. Only an explicit
3542
+ * `false` turns emission off, even if `fontFaces` is still present.
3514
3543
  */
3515
- const INCLUDE_PROJECT_CSS_VARIABLES_ON_PUBLISHED_WIDGET = true;
3544
+ function shouldIncludeFontFacesOnPublishedWidget(includeFontFaces) {
3545
+ return includeFontFaces !== false;
3546
+ }
3516
3547
 
3517
- /**
3518
- * Attribute-selector escape so a published key cannot break out of
3519
- * `[data-rulecms-published-key="…"]`. `CSS.escape` is not assumed (SSR / Node).
3520
- */
3521
- const escapeCssAttributeValue = (value) => value.replace(/\\/g, '\\\\').replace(/"/g, '\\"');
3522
- const REJECTED_IN_EMITTED_VALUE = /[{};]/;
3523
- const sanitizeForStylesheet = (variables) => {
3524
- if (!variables) {
3525
- return {};
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, '\\"')}"`;
3578
+ };
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;
3526
3594
  }
3527
- const sanitized = {};
3528
- for (const [rawName, rawValue] of Object.entries(variables)) {
3529
- if (!isCssVariableName(rawName) || typeof rawValue !== 'string') {
3595
+ return value;
3596
+ };
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) {
3530
3604
  continue;
3531
3605
  }
3532
- const value = rawValue.trim();
3533
- if (value === '' || REJECTED_IN_EMITTED_VALUE.test(value)) {
3606
+ const record = item;
3607
+ if (!isSafePaletteName(record.name)) {
3534
3608
  continue;
3535
3609
  }
3536
- sanitized[rawName.trim()] = value;
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;
3640
+ };
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
+ });
3537
3694
  }
3538
3695
  return sanitized;
3539
3696
  };
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`;
3708
+ };
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;
3725
+ };
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
+ }
3733
+ }
3734
+ return undefined;
3735
+ };
3540
3736
  /**
3541
- * One rule: custom properties on the first boxed children of this widget’s
3542
- * published-key span. Empty / flag-off / unsanitary catalogs return null so
3543
- * the caller omits the `<style>` tag.
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`.
3544
3741
  */
3545
- const formatProjectCssVariablesStylesheet = (publishedKey, variables) => {
3546
- if (!INCLUDE_PROJECT_CSS_VARIABLES_ON_PUBLISHED_WIDGET) {
3742
+ const formatProjectCssFontsStylesheet = (publishedKey, fonts, includeFontFaces) => {
3743
+ if (!shouldIncludeFontFacesOnPublishedWidget(includeFontFaces) || !publishedKey) {
3547
3744
  return null;
3548
3745
  }
3549
- const sanitized = sanitizeForStylesheet(variables);
3550
- const names = Object.keys(sanitized);
3551
- if (names.length === 0 || !publishedKey) {
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
+ }
3756
+ }
3757
+ const paletteName = appliedPaletteName(sanitized);
3758
+ if (paletteName) {
3759
+ declarations.push(` font-palette: ${paletteName};`);
3760
+ }
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) {
3552
3765
  return null;
3553
3766
  }
3554
- const selector = `[data-rulecms-published-key="${escapeCssAttributeValue(publishedKey)}"] > *`;
3555
- const declarations = names
3556
- .sort((left, right) => left.localeCompare(right))
3557
- .map((name) => ` ${name}: ${sanitized[name]};`)
3558
- .join('\n');
3559
- return `${selector} {\n${declarations}\n}`;
3767
+ if (!palettes) {
3768
+ return surface;
3769
+ }
3770
+ if (!surface) {
3771
+ return palettes;
3772
+ }
3773
+ return `${palettes}\n\n${surface}`;
3560
3774
  };
3561
3775
 
3562
3776
  /**
3563
- * Emits one scoped `<style data-rulecms-project-css-variables>` from the
3564
- * project catalog, or nothing when the catalog is empty / unsanitary.
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.
3565
3779
  */
3566
- class ProjectCssVariablesStylesheetComponent {
3780
+ class ProjectCssFontsStylesheetComponent {
3781
+ get href() {
3782
+ if (!shouldIncludeFontFacesOnPublishedWidget(this.includeFontFaces)) {
3783
+ return null;
3784
+ }
3785
+ return buildGoogleFontsCssHref(sanitizeProjectFontFaces(this.fonts));
3786
+ }
3567
3787
  get css() {
3568
- return formatProjectCssVariablesStylesheet(this.publishedKey, this.variables);
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="" />
3569
3794
  }
3570
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: ProjectCssVariablesStylesheetComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
3571
- 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: `
3572
3795
  @if (css) {
3573
- <style data-rulecms-project-css-variables="" [innerText]="css"></style>
3796
+ <style data-rulecms-project-fonts="" [innerText]="css"></style>
3574
3797
  }
3575
3798
  `, isInline: true }); }
3576
3799
  }
3577
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: ProjectCssVariablesStylesheetComponent, decorators: [{
3800
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: ProjectCssFontsStylesheetComponent, decorators: [{
3578
3801
  type: Component,
3579
3802
  args: [{
3580
- selector: 'rulecms-project-css-variables-stylesheet',
3803
+ selector: 'rulecms-project-css-fonts-stylesheet',
3581
3804
  standalone: true,
3582
3805
  template: `
3806
+ @if (href) {
3807
+ <link rel="stylesheet" [attr.href]="href" data-rulecms-project-fonts="" />
3808
+ }
3583
3809
  @if (css) {
3584
- <style data-rulecms-project-css-variables="" [innerText]="css"></style>
3810
+ <style data-rulecms-project-fonts="" [innerText]="css"></style>
3585
3811
  }
3586
3812
  `,
3587
3813
  }]
3588
3814
  }], propDecorators: { publishedKey: [{
3589
3815
  type: Input,
3590
3816
  args: [{ required: true }]
3591
- }], variables: [{
3817
+ }], fonts: [{
3818
+ type: Input
3819
+ }], includeFontFaces: [{
3592
3820
  type: Input
3593
3821
  }] } });
3594
3822
 
3595
- function transformChildCollections(childCollections) {
3596
- const transformed = {};
3597
- Object.entries(childCollections).forEach(([key, collection]) => {
3598
- const collectionToUse = { ...collection };
3599
- if (collectionToUse.itemList) {
3600
- try {
3601
- collectionToUse.collectionRows =
3602
- typeof collectionToUse.itemList === 'string'
3603
- ? JSON.parse(collectionToUse.itemList)
3604
- : collectionToUse.itemList;
3605
- }
3606
- catch (error) {
3607
- console.error(`Failed to parse itemList for collection ${key}:`, error);
3608
- collectionToUse.collectionRows = { rows: [] };
3609
- }
3610
- }
3611
- let collectionKey = `${collectionToUse.name}$${key}`;
3612
- if (collectionToUse.parentId) {
3613
- collectionKey = `${collectionKey}@${collectionToUse.parentId}`;
3614
- }
3615
- transformed[collectionKey] = collectionToUse;
3616
- });
3617
- return transformed;
3618
- }
3619
- function parseDisplayItemList(widget) {
3620
- return typeof widget.itemList === 'string'
3621
- ? JSON.parse(widget.itemList)
3622
- : widget.itemList;
3623
- }
3624
- /** Transform raw widget API data into render-ready displayItemList + collections. */
3625
- function prepareRuleCMSWidgetData(raw) {
3626
- return {
3627
- displayItemList: parseDisplayItemList(raw.widget),
3628
- widgetCollections: transformChildCollections(raw.childCollections),
3629
- ...(raw.libraries ? { libraries: raw.libraries } : {}),
3630
- ...(raw.cssVariables && Object.keys(raw.cssVariables).length > 0
3631
- ? { cssVariables: raw.cssVariables }
3632
- : {}),
3633
- ...(shouldIncludeClassDefinitionsOnPublishedWidget(raw.includeClassDefinitions) &&
3634
- raw.classDefinitions &&
3635
- Object.keys(raw.classDefinitions).length > 0
3636
- ? { classDefinitions: raw.classDefinitions }
3637
- : {}),
3638
- };
3639
- }
3640
-
3641
- function resolveSourceComponentsPluginSync(params) {
3642
- const registry = params.registry ?? createComponentLibraryRegistry();
3643
- const referenced = collectReferencedLibraryIds({
3644
- displayItemList: params.displayItemList,
3645
- widgetCollections: params.widgetCollections,
3646
- });
3647
- return registry.resolveSync({ registrations: params.libraries, referenced });
3648
- }
3649
- function resolveSourceComponentsPlugin(params) {
3650
- const registry = params.registry ?? createComponentLibraryRegistry();
3651
- const referenced = collectReferencedLibraryIds({
3652
- displayItemList: params.displayItemList,
3653
- widgetCollections: params.widgetCollections,
3654
- });
3655
- return registry.resolve({ registrations: params.libraries, referenced });
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;
3656
3829
  }
3657
3830
 
3658
- const loadingContainerStyle = {
3659
- display: 'flex',
3660
- justifyContent: 'center',
3661
- alignItems: 'center',
3662
- padding: '3rem',
3663
- color: '#e2e8f0',
3664
- };
3665
- const spinnerContainerStyle = {
3666
- display: 'flex',
3667
- alignItems: 'center',
3668
- gap: '1rem',
3669
- };
3670
- const spinnerStyle = {
3671
- width: '40px',
3672
- height: '40px',
3673
- border: '4px solid #4a5568',
3674
- borderTopColor: '#63b3ed',
3675
- borderRadius: '50%',
3676
- animation: 'spin 1s linear infinite',
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;
3677
3863
  };
3678
- const errorContainerStyle = {
3679
- padding: '1.5rem',
3680
- backgroundColor: '#742a2a',
3681
- border: '1px solid #9b2c2c',
3682
- borderRadius: '8px',
3683
- color: '#fed7d7',
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);
3684
3876
  };
3685
- const errorTitleStyle = {
3686
- fontSize: '16px',
3687
- fontWeight: '600',
3688
- marginBottom: '0.5rem',
3689
- color: '#feb2b2',
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;
3690
3892
  };
3691
- const errorMessageStyle = {
3692
- fontSize: '14px',
3693
- color: '#fed7d7',
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;
3694
3926
  };
3695
- const globalStyles = `
3696
- @keyframes spin {
3697
- from {
3698
- transform: rotate(0deg);
3927
+ const isCssKeyframeBody = (value) => {
3928
+ const trimmed = value.trim();
3929
+ if (!trimmed || trimmed.length > KEYFRAME_BODY_MAX_LENGTH) {
3930
+ return false;
3699
3931
  }
3700
- to {
3701
- transform: rotate(360deg);
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);
3702
4779
  }
3703
4780
  }
3704
4781
  `;
@@ -3875,6 +4952,30 @@ class RuleCMSWidgetComponent {
3875
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 }); }
3876
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: `
3877
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
+ />
3878
4979
  <rulecms-project-css-variables-stylesheet
3879
4980
  [publishedKey]="publishedKey"
3880
4981
  [variables]="preparedData?.cssVariables"
@@ -3882,6 +4983,7 @@ class RuleCMSWidgetComponent {
3882
4983
  <rulecms-project-css-classes-stylesheet
3883
4984
  [publishedKey]="publishedKey"
3884
4985
  [classes]="preparedData?.classDefinitions"
4986
+ [classLayer]="preparedData?.classLayer"
3885
4987
  />
3886
4988
  @if (mode !== 'pre-fetched' && loading) {
3887
4989
  <div [ngStyle]="loadingContainerStyle">
@@ -3923,7 +5025,7 @@ class RuleCMSWidgetComponent {
3923
5025
  }
3924
5026
  }
3925
5027
  </span>
3926
- `, 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"] }] }); }
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"] }] }); }
3927
5029
  }
3928
5030
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: RuleCMSWidgetComponent, decorators: [{
3929
5031
  type: Component,
@@ -3936,9 +5038,39 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.25", ngImpo
3936
5038
  RenderComponentsComponent,
3937
5039
  ProjectCssVariablesStylesheetComponent,
3938
5040
  ProjectCssClassesStylesheetComponent,
5041
+ ProjectCssFontsStylesheetComponent,
5042
+ ProjectCssKeyframesStylesheetComponent,
5043
+ ProjectCssThemesStylesheetComponent,
5044
+ ProjectCssPropertiesStylesheetComponent,
5045
+ ProjectCssWidgetChromeStylesheetComponent,
5046
+ ProjectCssPositionTryStylesheetComponent,
3939
5047
  ],
3940
5048
  template: `
3941
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
+ />
3942
5074
  <rulecms-project-css-variables-stylesheet
3943
5075
  [publishedKey]="publishedKey"
3944
5076
  [variables]="preparedData?.cssVariables"
@@ -3946,6 +5078,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.25", ngImpo
3946
5078
  <rulecms-project-css-classes-stylesheet
3947
5079
  [publishedKey]="publishedKey"
3948
5080
  [classes]="preparedData?.classDefinitions"
5081
+ [classLayer]="preparedData?.classLayer"
3949
5082
  />
3950
5083
  @if (mode !== 'pre-fetched' && loading) {
3951
5084
  <div [ngStyle]="loadingContainerStyle">