@nswds/app 1.87.14 → 1.89.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -17557,7 +17557,7 @@ function FormatToggle({ format, setFormat }) {
17557
17557
 
17558
17558
  // package.json
17559
17559
  var package_default = {
17560
- version: "1.87.0"};
17560
+ version: "1.88.0"};
17561
17561
  var SluggerContext = React5__namespace.default.createContext(null);
17562
17562
  function flattenText(nodes) {
17563
17563
  if (nodes == null || typeof nodes === "boolean") return "";
@@ -30428,40 +30428,56 @@ function ThemeColorPaletteLoading() {
30428
30428
  ] }, i)) })
30429
30429
  ] });
30430
30430
  }
30431
- function getInitialThemeState(searchParams) {
30431
+ function getInitialThemeState(searchParams, defaults) {
30432
30432
  const themeParam = searchParams.get("theme");
30433
30433
  const primaryParam = searchParams.get("primary");
30434
30434
  const accentParam = searchParams.get("accent");
30435
- const themeCategory = themeParam === "aboriginal" ? "aboriginal" : "brand";
30436
- let primaryColor = "blue";
30437
- let accentColor = "red";
30438
- const availableColors = Object.keys(colorThemes[themeCategory]);
30439
- if (primaryParam && availableColors.includes(primaryParam)) {
30435
+ const themeCategory = themeParam === "aboriginal" || themeParam === "brand" ? themeParam : defaults?.themeCategory ?? "brand";
30436
+ function pickFirst(arr) {
30437
+ return arr.length > 0 ? arr[0] : null;
30438
+ }
30439
+ function pickFirstNot(arr, not) {
30440
+ return arr.find((x) => x !== not) ?? null;
30441
+ }
30442
+ const availableColors = Object.keys(colorThemes[themeCategory] ?? {});
30443
+ const availableNonGreyColors = availableColors.filter((c) => !c.toLowerCase().includes("grey"));
30444
+ let primaryColor = defaults?.primaryColor ?? "blue";
30445
+ let accentColor = defaults?.accentColor ?? "red";
30446
+ if (primaryParam && availableNonGreyColors.includes(primaryParam)) {
30440
30447
  primaryColor = primaryParam;
30441
- } else if (!availableColors.includes(primaryColor)) {
30442
- primaryColor = availableColors[0];
30448
+ } else if (!availableNonGreyColors.includes(primaryColor)) {
30449
+ const fallback = pickFirst(availableNonGreyColors);
30450
+ if (fallback) primaryColor = fallback;
30443
30451
  }
30444
- if (accentParam && availableColors.includes(accentParam) && accentParam !== primaryColor) {
30452
+ if (accentParam && availableNonGreyColors.includes(accentParam) && accentParam !== primaryColor) {
30445
30453
  accentColor = accentParam;
30446
30454
  } else {
30447
- const newAccent = availableColors.find((c) => c !== primaryColor);
30448
- if (newAccent) accentColor = newAccent;
30455
+ const defaultAccentOk = availableNonGreyColors.includes(accentColor) && accentColor !== primaryColor;
30456
+ if (!defaultAccentOk) {
30457
+ const fallback = pickFirstNot(availableNonGreyColors, primaryColor);
30458
+ if (fallback) accentColor = fallback;
30459
+ }
30449
30460
  }
30450
- const neutralKey = Object.keys(colorThemes[themeCategory]).find((k) => k.toLowerCase().includes("grey")) ?? "grey";
30461
+ const neutralKey = Object.keys(colorThemes[themeCategory]).find((k) => k.toLowerCase().includes("grey")) ?? defaults?.greyColor ?? "grey";
30451
30462
  return { themeCategory, primaryColor, accentColor, greyColor: neutralKey };
30452
30463
  }
30453
- function ThemeColorPaletteContent() {
30464
+ function ThemeColorPaletteContent(props) {
30454
30465
  const searchParams = navigation.useSearchParams();
30455
- const baseColors = {
30456
- brand,
30457
- aboriginal
30458
- };
30459
30466
  const {
30460
30467
  themeCategory: initialThemeCategory,
30461
30468
  primaryColor: initialPrimaryColor,
30462
30469
  accentColor: initialAccentColor,
30463
30470
  greyColor: initialGreyColor
30464
- } = getInitialThemeState(searchParams);
30471
+ } = getInitialThemeState(searchParams, {
30472
+ themeCategory: props.defaultThemeCategory,
30473
+ primaryColor: props.defaultPrimaryColor,
30474
+ accentColor: props.defaultAccentColor,
30475
+ greyColor: props.defaultGreyColor
30476
+ });
30477
+ const baseColors = {
30478
+ brand,
30479
+ aboriginal
30480
+ };
30465
30481
  const [format, setFormat] = React5.useState("hex");
30466
30482
  const [viewMode, setViewMode] = React5.useState("grid");
30467
30483
  const [themeCategory, setThemeCategory] = React5.useState(initialThemeCategory);
@@ -30602,8 +30618,9 @@ function ThemeColorPaletteContent() {
30602
30618
  ] }),
30603
30619
  /* @__PURE__ */ jsxRuntime.jsx("div", { className: "space-y-12", children: currentColorPalette.map((theme2) => {
30604
30620
  const baseKey = theme2.name === "Primary" ? primaryColor : theme2.name === "Accent" ? accentColor : "grey";
30621
+ const headingId = theme2.name.toLowerCase().trim().replace(/\s+/g, "-");
30605
30622
  return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-4", children: [
30606
- /* @__PURE__ */ jsxRuntime.jsx("h2", { className: "text-2xl font-semibold", children: theme2.name }),
30623
+ /* @__PURE__ */ jsxRuntime.jsx("h2", { id: headingId, className: "text-2xl font-semibold", children: theme2.name }),
30607
30624
  /* @__PURE__ */ jsxRuntime.jsx(BaseColorSwatches, { baseColors: baseColors[themeCategory][baseKey], format }),
30608
30625
  /* @__PURE__ */ jsxRuntime.jsx(ColourScale, { colorsToUse: theme2.colors }),
30609
30626
  /* @__PURE__ */ jsxRuntime.jsx(ColorSwatches, { theme: theme2.colors, format, viewMode })
@@ -30611,8 +30628,8 @@ function ThemeColorPaletteContent() {
30611
30628
  }) })
30612
30629
  ] });
30613
30630
  }
30614
- function ThemeColorPalette() {
30615
- return /* @__PURE__ */ jsxRuntime.jsx(React5.Suspense, { fallback: /* @__PURE__ */ jsxRuntime.jsx(ThemeColorPaletteLoading, {}), children: /* @__PURE__ */ jsxRuntime.jsx(ThemeColorPaletteContent, {}) });
30631
+ function ThemeColorPalette(props) {
30632
+ return /* @__PURE__ */ jsxRuntime.jsx(React5.Suspense, { fallback: /* @__PURE__ */ jsxRuntime.jsx(ThemeColorPaletteLoading, {}), children: /* @__PURE__ */ jsxRuntime.jsx(ThemeColorPaletteContent, { ...props }) });
30616
30633
  }
30617
30634
  function ThemeProvider({ children, ...props }) {
30618
30635
  return /* @__PURE__ */ jsxRuntime.jsx(nextThemes.ThemeProvider, { ...props, children });