• GALERIA ZDJĘĆ

  • GALERIA ZDJĘĆ

  • GALERIA ZDJĘĆ

import {

startTransition,

useCallback,

useEffect,

useMemo,

useRef,

useState,

} from "react"

import { addPropertyControls, ControlType, useIsStaticRenderer } from "framer"


// User request: Create a new code component named TopThemeToggle. This is an icon-only accessible button intended to sit beside the existing Contact link in a Framer navigation. It must have no persistence: the default state after each refresh is theme 1. On click, toggle only the scoped upper homepage section between theme 1 and theme 2. Theme 2 must map black surfaces to #EDECE8, yellow #FFF800 / rgb(255,248,0) to #5101F9, and white/light text to black for readable contrast. Scope the modifications to three DOM targets supplied via a `targetIds` string prop (default `home-hero,home-works,home-about`) plus the component’s immediate navigation context, without altering later page sections. Restore all original inline styles exactly when toggling back. Use browser-only APIs inside effects/click handlers, tolerate missing targets, and clean up any temporary changes on unmount. Render a compact 28px circular button with an inline SVG sun/moon-style icon; expose controls for targetIds, primaryColor, alternateBackground, alternateAccent, and size. Avoid external dependencies and do not use localStorage, sessionStorage, cookies, or URL state. Ensure it is keyboard-accessible with an aria-label that reflects the current target theme.


interface MyComponentProps {

targetIds: string

primaryColor: string

alternateBackground: string

alternateAccent: string

size: number

}


type RGB = { r: number; g: number; b: number; a: number }

type StyleSnapshot = { value: string; priority: string }

type ThemeOptions = {

targetIds: string[]

alternateBackground: string

alternateAccent: string

navRoot: HTMLElement | null

}


type ThemeListener = (isThemeTwo: boolean) => void


const themeRuntime = { isThemeTwo: false, listeners: new Set<ThemeListener>() }

const ABOUT_PARALLAX_FILTER_ID = "top-theme-about-parallax-duotone"

const PHONE_QUERY = "(max-width: 809px)"


function isPhoneViewport(): boolean {

if (

typeof window === "undefined" ||

typeof window.matchMedia !== "function"

)

return false

return window.matchMedia(PHONE_QUERY).matches

}


function subscribeTheme(listener: ThemeListener): () => void {

themeRuntime.listeners.add(listener)

return () => themeRuntime.listeners.delete(listener)

}


function setRuntimeTheme(next: boolean): void {

themeRuntime.isThemeTwo = next

if (typeof document !== "undefined") {

if (next) {

document.body.classList.add("k2-light-mode")

} else {

document.body.classList.remove("k2-light-mode")

}

}

themeRuntime.listeners.forEach((listener) => listener(next))

syncGalleryFilterButtons(next)

}


function parseColor(input: string): RGB | null {

const value = input.trim().toLowerCase()


const rgbMatch = value.match(/rgba?\(([^)]+)\)/)

if (rgbMatch) {

const parts = rgbMatch[1].split(",").map((part) => part.trim())

const r = Number(parts[0])

const g = Number(parts[1])

const b = Number(parts[2])

const a = parts[3] !== undefined ? Number(parts[3]) : 1

if ([r, g, b, a].some((n) => Number.isNaN(n))) return null

return { r, g, b, a }

}


const hexMatch = value.match(/^#([0-9a-f]{3}|[0-9a-f]{6})$/i)

if (hexMatch) {

let hex = hexMatch[1]

if (hex.length === 3)

hex = hex

.split("")

.map((ch) => ch + ch)

.join("")

const r = Number.parseInt(hex.slice(0, 2), 16)

const g = Number.parseInt(hex.slice(2, 4), 16)

const b = Number.parseInt(hex.slice(4, 6), 16)

return { r, g, b, a: 1 }

}


return null

}


function isNearBlack(color: RGB | null): boolean {

if (!color || color.a === 0) return false

return color.r <= 28 && color.g <= 28 && color.b <= 28

}


function isExactYellow(color: RGB | null): boolean {

if (!color || color.a === 0) return false

return (

(color.r === 255 && color.g === 248 && color.b === 0) ||

(color.r >= 230 && color.g >= 230 && color.b <= 50)

)

}


function isLightText(color: RGB | null): boolean {

if (!color || color.a === 0) return false

return color.r >= 220 && color.g >= 220 && color.b >= 220

}


function ensureAboutParallaxFilter(accent: string): string {

if (typeof document === "undefined")

return `url(#${ABOUT_PARALLAX_FILTER_ID})`

const existing = document.getElementById(ABOUT_PARALLAX_FILTER_ID)

const parsed = parseColor(accent) ?? { r: 81, g: 1, b: 249, a: 1 }

const r = (parsed.r / 255).toFixed(4)

const g = (parsed.g / 255).toFixed(4)

const b = (parsed.b / 255).toFixed(4)


if (existing instanceof SVGFilterElement) {

existing

.querySelector("[data-map='r']")

?.setAttribute("tableValues", `0 ${r}`)

existing

.querySelector("[data-map='g']")

?.setAttribute("tableValues", `0 ${g}`)

existing

.querySelector("[data-map='b']")

?.setAttribute("tableValues", `0 ${b}`)

return `url(#${ABOUT_PARALLAX_FILTER_ID})`

}


const svgNS = "http://www.w3.org/2000/svg"

const svg = document.createElementNS(svgNS, "svg")

svg.setAttribute("width", "0")

svg.setAttribute("height", "0")

svg.setAttribute("style", "position:absolute")

svg.setAttribute("aria-hidden", "true")

const defs = document.createElementNS(svgNS, "defs")

const filter = document.createElementNS(svgNS, "filter")

filter.setAttribute("id", ABOUT_PARALLAX_FILTER_ID)

filter.setAttribute("color-interpolation-filters", "sRGB")

const luminance = document.createElementNS(svgNS, "feColorMatrix")

luminance.setAttribute("type", "matrix")

luminance.setAttribute(

"values",

"0.2126 0.7152 0.0722 0 0 0.2126 0.7152 0.0722 0 0 0.2126 0.7152 0.0722 0 0 0 0 0 1 0"

)

const transfer = document.createElementNS(svgNS, "feComponentTransfer")

const rFunc = document.createElementNS(svgNS, "feFuncR")

const gFunc = document.createElementNS(svgNS, "feFuncG")

const bFunc = document.createElementNS(svgNS, "feFuncB")

const aFunc = document.createElementNS(svgNS, "feFuncA")

rFunc.setAttribute("type", "table")

gFunc.setAttribute("type", "table")

bFunc.setAttribute("type", "table")

aFunc.setAttribute("type", "identity")

rFunc.setAttribute("tableValues", `0 ${r}`)

gFunc.setAttribute("tableValues", `0 ${g}`)

bFunc.setAttribute("tableValues", `0 ${b}`)

rFunc.setAttribute("data-map", "r")

gFunc.setAttribute("data-map", "g")

bFunc.setAttribute("data-map", "b")

transfer.append(rFunc, gFunc, bFunc, aFunc)

filter.append(luminance, transfer)

defs.append(filter)

svg.append(defs)

document.body.append(svg)

return `url(#${ABOUT_PARALLAX_FILTER_ID})`

}


type Backdrop = { color: RGB | null; media: boolean }


function relativeLuminance(c: RGB): number {

const channel = (value: number) => {

const s = value / 255

return s <= 0.03928 ? s / 12.92 : Math.pow((s + 0.055) / 1.055, 2.4)

}

return 0.2126 * channel(c.r) + 0.7152 * channel(c.g) + 0.0722 * channel(c.b)

}


function contrastRatio(a: RGB, b: RGB): number {

const la = relativeLuminance(a)

const lb = relativeLuminance(b)

return (Math.max(la, lb) + 0.05) / (Math.min(la, lb) + 0.05)

}


function hasOwnText(el: HTMLElement): boolean {

const nodes = Array.from(el.childNodes)

for (let i = 0; i < nodes.length; i++) {

const node = nodes[i]

if (node.nodeType === 3 && (node.textContent || "").trim().length > 0)

return true

}

return false

}


function findBlendHost(el: HTMLElement): HTMLElement | null {

let node: HTMLElement | null = el

while (node && node !== document.body) {

const mode = window.getComputedStyle(node).mixBlendMode

if (mode && mode !== "normal") return node

node = node.parentElement

}

return null

}


function collectMediaRects(roots: HTMLElement[]): DOMRect[] {

const rects: DOMRect[] = []

roots.forEach((root) => {

root.querySelectorAll("img, video, canvas, picture").forEach(

(media) => {

const rect = media.getBoundingClientRect()

if (rect.width >= 120 && rect.height >= 120) rects.push(rect)

}

)

})

return rects

}


function isOverMedia(el: HTMLElement, rects: DOMRect[]): boolean {

if (rects.length === 0) return false

const rect = el.getBoundingClientRect()

if (rect.width === 0 && rect.height === 0) return false

const cx = rect.left + rect.width / 2

const cy = rect.top + rect.height / 2

return rects.some(

(m) => cx >= m.left && cx <= m.right && cy >= m.top && cy <= m.bottom

)

}


// Global dynamic stylesheet for clean overrides without visited link side-effects

const GLOBAL_STYLE_ID = "top-theme-global-overrides"

function ensureGlobalStyles() {

if (typeof document === "undefined") return

const styleId = "k2-theme-global-overrides"

let el = document.getElementById(styleId) as HTMLStyleElement | null

if (!el) {

el = document.createElement("style")

el.id = styleId

document.head.appendChild(el)

}

el.textContent = `

/* 1. Permanent fix for visited links discoloration */

a, a:visited, a:hover, a:active,

button, button:visited,

[data-framer-name*="Button"]:visited,

[data-framer-name*="Tab"]:visited,

[data-framer-name*="Pill"]:visited {

color: inherit !important;

text-decoration: none !important;

}


/* 2. Permanent removal of Kategorie */

a[href*="kategorie" i],

button[href*="kategorie" i],

[data-framer-name*="kategorie" i],

[data-framer-name*="Kategorie"] {

display: none !important;

visibility: hidden !important;

pointer-events: none !important;

}


/* 3. 100% transparent top navigation bar with dynamic invert */

nav, header, [role="navigation"], [class*="nav-container"], [data-framer-name*="Nav"] {

background: transparent !important;

background-color: transparent !important;

backdrop-filter: none !important;

-webkit-backdrop-filter: none !important;

box-shadow: none !important;

border: none !important;

}


/* 4. Vertical alignment of logo */

[data-framer-name*="Logo"], [data-framer-name*="logo"], a[href="/"] img, a[href="/"] svg {

margin-top: auto !important;

margin-bottom: auto !important;

align-self: center !important;

}


/* 5. Mobile Menu Drawer Links Uniform Typography (32px strictly inside mobile drawer) */

@media (max-width: 809px) {

[data-framer-name="Phone Open"] a,

[data-framer-name="Phone Open"] a *,

[data-framer-name="Phone Open"] button,

[data-framer-name="Phone Open"] button *,

[data-framer-name="Phone Open"] [data-framer-name="Menu links"] a,

[data-framer-name="Phone Open"] [data-framer-name="Menu links"] a *,

[data-framer-name="Phone Open"] [data-framer-name="Menu links"] button,

[data-framer-name="Phone Open"] [data-framer-name="Menu links"] button *,

[class*="drawer"] a,

[class*="drawer"] a * {

font-size: 32px !important;

line-height: 1.25 !important;

font-weight: 500 !important;

letter-spacing: -0.02em !important;

}

}


/* 5b. Desktop Top Navigation Links Size (preserve clean 14px layout) */

@media (min-width: 810px) {

nav a, nav button, header a, header button,

[data-framer-name="Desktop"] [data-framer-name="Menu links"] a,

[data-framer-name="Desktop"] [data-framer-name="Menu links"] button,

[data-framer-name="Desktop"] [data-framer-name="Menu links"] span,

[data-framer-name="Desktop"] [data-framer-name="Menu links"] p,

[data-framer-name="Menu links"] a,

[data-framer-name="Menu links"] button,

[data-framer-name="Menu links"] span,

[data-framer-name="Menu links"] p {

font-size: 14px !important;

line-height: 1.2 !important;

font-weight: 500 !important;

letter-spacing: normal !important;

}

}


/* 5c. Mobile Horizontally Scrollable Category Filter Bar */

@media (max-width: 809px) {

.k2-mobile-filter-row,

[data-framer-name="Filter"],

[data-framer-name*="Filter" i],

[data-framer-name*="filter" i] {

display: flex !important;

flex-direction: row !important;

flex-wrap: nowrap !important;

overflow-x: auto !important;

overflow-y: hidden !important;

-webkit-overflow-scrolling: touch !important;

scrollbar-width: none !important;

-ms-overflow-style: none !important;

max-width: 100vw !important;

width: 100% !important;

padding-left: 16px !important;

padding-right: 16px !important;

box-sizing: border-box !important;

gap: 8px !important;

}

.k2-mobile-filter-row::-webkit-scrollbar,

[data-framer-name*="Filter" i]::-webkit-scrollbar {

display: none !important;

}

.k2-filter-btn {

flex-shrink: 0 !important;

white-space: nowrap !important;

}

}


/* 6. Mobile Drawer Theme Toggle */

.mobile-drawer-theme-toggle {

margin-top: 28px !important;

padding: 10px 22px !important;

border-radius: 999px !important;

border: 1px solid currentColor !important;

background: transparent !important;

color: inherit !important;

display: inline-flex !important;

align-items: center !important;

justify-content: center !important;

gap: 10px !important;

font-size: 16px !important;

font-weight: 600 !important;

cursor: pointer !important;

width: fit-content !important;

font-family: inherit !important;

transition: all 0.2s ease !important;

}

.mobile-drawer-theme-toggle:hover {

opacity: 0.8 !important;

transform: scale(1.02) !important;

}


/* 7. GALLERY FILTER BUTTONS - LIGHT MODE OVERRIDES */

body.k2-light-mode .k2-filter-btn {

background-color: #EDECE8 !important;

background: #EDECE8 !important;

color: #000000 !important;

border: 1px solid rgba(0, 0, 0, 0.15) !important;

border-color: rgba(0, 0, 0, 0.15) !important;

}

body.k2-light-mode .k2-filter-btn * {

color: #000000 !important;

background-color: transparent !important;

background: transparent !important;

border-color: transparent !important;

}


/* ACTIVE FILTER BUTTON - LIGHT MODE (SOLID PURPLE #5101F9) */

body.k2-light-mode .k2-filter-btn.k2-active {

background-color: #5101F9 !important;

background: #5101F9 !important;

color: #EDECE8 !important;

border: 1px solid #5101F9 !important;

border-color: #5101F9 !important;

}

body.k2-light-mode .k2-filter-btn.k2-active * {

color: #EDECE8 !important;

background-color: transparent !important;

background: transparent !important;

border-color: transparent !important;

}


/* ACTIVE FILTER BUTTON - DARK MODE FOR THE BEST (NATIVE YELLOW #FFF800) */

body:not(.k2-light-mode) .k2-filter-btn.k2-active[data-injected-filter="the-best"],

body:not(.k2-light-mode) .k2-filter-btn.k2-active[data-injected-filter="the-best"] * {

background-color: #FFF800 !important;

background: #FFF800 !important;

color: #000000 !important;

border-color: #FFF800 !important;

}

body:not(.k2-light-mode) .k2-filter-btn[data-injected-filter="the-best"]:not(.k2-active) {

background-color: #000000 !important;

background: #000000 !important;

color: #FFFFFF !important;

border: 1px solid rgba(255, 255, 255, 0.2) !important;

}

body:not(.k2-light-mode) .k2-filter-btn[data-injected-filter="the-best"]:not(.k2-active) * {

color: #FFFFFF !important;

background-color: transparent !important;

}


/* 8. Light mode top bar colors */

body.k2-light-mode nav a,

body.k2-light-mode nav button,

body.k2-light-mode nav span,

body.k2-light-mode nav p,

body.k2-light-mode header a,

body.k2-light-mode header button,

body.k2-light-mode header span,

body.k2-light-mode header p {

color: #5101F9 !important;

}

body.k2-light-mode [data-framer-name*="Logo"] svg,

body.k2-light-mode [data-framer-name*="Logo"] path,

body.k2-light-mode [data-framer-name*="logo"] svg,

body.k2-light-mode [data-framer-name*="logo"] path {

fill: #5101F9 !important;

stroke: #5101F9 !important;

}

`

}


const GALLERY_FILTER_NAMES = [

"wszystkie",

"sport",

"motoryzacja",

"koncerty",

"portrety",

"eventy",

"the best",

"the best of the best"

]


let activeFilterName = "wszystkie"

let galleryClickTrackerInitialized = false


function initGalleryClickTracker() {

if (typeof window === "undefined" || galleryClickTrackerInitialized) return

galleryClickTrackerInitialized = true


window.addEventListener(

"click",

(e) => {

const target = e.target as HTMLElement | null

if (!target) return

const btn = target.closest(

"button, a, [role='button'], [data-framer-name*='Button'], [data-framer-name*='Tab'], [data-framer-name*='Pill']"

) as HTMLElement | null

if (!btn) return

const raw = btn.textContent || ""

const norm = raw.replace(/\s+/g, "").toLowerCase().replace(/(.)\1/g, "$1")


const matched = GALLERY_FILTER_NAMES.find(

(n) => norm === n.replace(/\s+/g, "") || norm.includes(n.replace(/\s+/g, ""))

)

if (matched) {

activeFilterName = matched

syncGalleryFilterButtons(themeRuntime.isThemeTwo)

if (matched === "the best" || matched === "the best of the best") {

filterGalleryCards("the best")

} else if (matched === "wszystkie") {

filterGalleryCards("wszystkie")

}

requestAnimationFrame(() => syncGalleryFilterButtons(themeRuntime.isThemeTwo))

setTimeout(() => syncGalleryFilterButtons(themeRuntime.isThemeTwo), 50)

setTimeout(() => syncGalleryFilterButtons(themeRuntime.isThemeTwo), 150)

}

},

true

)

}


function getGalleryFilterButtons(): HTMLElement[] {

if (typeof document === "undefined") return []

const found: HTMLElement[] = []

document

.querySelectorAll<HTMLElement>(

"button, a, [role='button'], [data-framer-name*='Button'], [data-framer-name*='Tab'], [data-framer-name*='Pill']"

)

.forEach((el) => {

const raw = el.textContent || ""

const norm = raw.replace(/\s+/g, "").toLowerCase().replace(/(.)\1/g, "$1")

if (

norm &&

GALLERY_FILTER_NAMES.some((n) => norm === n.replace(/\s+/g, "") || norm.includes(n.replace(/\s+/g, ""))) &&

el.children.length <= 4

) {

const parent = el.closest("footer, [role='contentinfo']")

if (!parent) {

found.push(el)

}

}

})

return found

}


function ensureTheBestFilterButton(existingButtons: HTMLElement[]) {

if (typeof document === "undefined") return

const hasTheBest = document.querySelector('[data-injected-filter="the-best"]') || existingButtons.some((b) => {

const norm = (b.textContent || "").replace(/\s+/g, "").toLowerCase().replace(/(.)\1/g, "$1")

return norm.includes("thebest")

})

if (hasTheBest) return


const lastBtn = existingButtons[existingButtons.length - 1]

const container = lastBtn?.parentElement

if (!container) return


const theBestBtn = lastBtn.cloneNode(true) as HTMLElement

theBestBtn.dataset.injectedFilter = "the-best"

theBestBtn.classList.add("k2-filter-btn")

theBestBtn.classList.remove("k2-active")


let replaced = false

theBestBtn.querySelectorAll("*").forEach((child) => {

if (!replaced && child.children.length === 0 && child.textContent?.trim()) {

child.textContent = "THE BEST"

replaced = true

}

})

if (!replaced) theBestBtn.textContent = "THE BEST"


theBestBtn.onclick = (e) => {

e.preventDefault()

e.stopPropagation()

activeFilterName = "the best"

syncGalleryFilterButtons(themeRuntime.isThemeTwo)

filterGalleryCards("the best")

}


container.appendChild(theBestBtn)

}


function filterGalleryCards(category: string) {

if (typeof document === "undefined") return

const cards = document.querySelectorAll<HTMLElement>("a[href*='/works/']")

cards.forEach((card) => {

const text = card.textContent?.toLowerCase() || ""

const href = card.getAttribute("href")?.toLowerCase() || ""

if (category === "wszystkie") {

card.style.removeProperty("display")

} else if (category === "the best" || category === "the best of the best") {

const match =

text.includes("the best") ||

href.includes("the-best") ||

text.includes("2026") ||

text.includes("2025") ||

text.includes("2024")

card.style.display = match ? "" : "none"

} else {

const match = text.includes(category) || href.includes(category)

card.style.display = match ? "" : "none"

}

})

}


function syncGalleryFilterButtons(isLightMode: boolean) {

if (typeof document === "undefined") return

ensureGlobalStyles()

initGalleryClickTracker()

const buttons = getGalleryFilterButtons()

if (buttons.length === 0) return


ensureTheBestFilterButton(buttons)

const filterContainer = buttons[0]?.parentElement

if (filterContainer) {

filterContainer.classList.add("k2-mobile-filter-row")

}


// Match active button

let activeBtn: HTMLElement | null = null

const normActive = activeFilterName.replace(/\s+/g, "").toLowerCase()


buttons.forEach((btn) => {

btn.classList.add("k2-filter-btn")

const norm = (btn.textContent || "").replace(/\s+/g, "").toLowerCase().replace(/(.)\1/g, "$1")

if (normActive && (norm === normActive || norm.includes(normActive))) {

activeBtn = btn

}

})


if (!activeBtn) {

buttons.forEach((btn) => {

const bg = window.getComputedStyle(btn).backgroundColor

const parsed = parseColor(bg)

if (

isExactYellow(parsed) ||

btn.getAttribute("aria-current") === "page" ||

btn.classList.contains("active")

) {

activeBtn = btn

}

})

}


if (!activeBtn && buttons.length > 0) {

activeBtn = buttons[0]

}


buttons.forEach((btn) => {

if (btn === activeBtn) {

btn.classList.add("k2-active")

} else {

btn.classList.remove("k2-active")

}

})

}


class ThemeController {

private snapshots = new Map<HTMLElement, Map<string, StyleSnapshot>>()

private options: ThemeOptions | null = null

private pageObserver: MutationObserver | null = null

private timer: number | null = null

private mediaQuery: MediaQueryList | null = null


setOptions(options: ThemeOptions) {

this.options = options

}


setEnabled(enabled: boolean) {

this.watchViewport()

ensureGlobalStyles()

syncGalleryFilterButtons(enabled)


if (!enabled) {

this.disconnect()

this.restore()

return

}

this.restore()

this.apply()

this.observe()

}


private watchViewport() {

if (

this.mediaQuery ||

typeof window === "undefined" ||

typeof window.matchMedia !== "function"

)

return

this.mediaQuery = window.matchMedia(PHONE_QUERY)

this.mediaQuery.addEventListener("change", this.handleViewportChange)

}


private handleViewportChange = () => {

this.setEnabled(themeRuntime.isThemeTwo)

}


private snapshot(element: HTMLElement, prop: string) {

let props = this.snapshots.get(element)

if (!props) {

props = new Map()

this.snapshots.set(element, props)

}

if (!props.has(prop)) {

props.set(prop, {

value: element.style.getPropertyValue(prop),

priority: element.style.getPropertyPriority(prop),

})

}

}


private set(

element: HTMLElement,

prop: string,

value: string,

priority: "" | "important" = ""

) {

this.snapshot(element, prop)

element.style.setProperty(prop, value, priority)

}


private restore() {

this.snapshots.forEach((props, element) => {

props.forEach((snapshot, prop) => {

if (snapshot.value)

element.style.setProperty(

prop,

snapshot.value,

snapshot.priority

)

else element.style.removeProperty(prop)

})

})

this.snapshots.clear()

syncGalleryFilterButtons(false)

}


private scheduleApply = () => {

if (typeof window === "undefined") return

if (this.timer !== null) window.clearTimeout(this.timer)

this.timer = window.setTimeout(() => {

this.timer = null

if (!themeRuntime.isThemeTwo) {

syncGalleryFilterButtons(false)

return

}

this.restore()

this.apply()

syncGalleryFilterButtons(true)

}, 150)

}


private observe() {

if (typeof window === "undefined" || !this.options) return

this.pageObserver?.disconnect()

this.pageObserver = new MutationObserver(this.scheduleApply)

this.pageObserver.observe(document.body, {

childList: true,

subtree: true,

})

}


private disconnect() {

this.pageObserver?.disconnect()

this.pageObserver = null

if (this.timer !== null && typeof window !== "undefined") {

window.clearTimeout(this.timer)

this.timer = null

}

}


private apply() {

if (typeof window === "undefined" || !this.options) return

// phone viewport allowed

const { targetIds, alternateBackground, alternateAccent, navRoot } =

this.options

const pathname = window.location?.pathname || "/"

const isHome = pathname === "/"

const roots: HTMLElement[] = []


if (isHome) {

targetIds.forEach((id) => {

const target = document.getElementById(id)

if (target instanceof HTMLElement) roots.push(target)

})

} else {

const main = document.querySelector("main")

if (main instanceof HTMLElement) roots.push(main)

else {

const fallback = document.getElementById("theme-contact")

if (fallback instanceof HTMLElement) roots.push(fallback)

}

}


roots.forEach((root) =>

this.set(root, "background-color", alternateBackground)

)

this.set(

document.documentElement,

"background-color",

alternateBackground

)

this.set(document.body, "background-color", alternateBackground)


// Handle Top Navigation in Light Mode:

// 100% transparent top bar with NO glass/difference, recolor text & logo to #5101F9

const effectiveNav = navRoot || document.querySelector<HTMLElement>("nav, header, [role='navigation']")


// Keep mix-blend-mode difference active on fixed nav so invert effect works in light mode

if (effectiveNav) {

const container = (effectiveNav.closest("[class*='container']") as HTMLElement) || effectiveNav

this.set(container, "background-color", "transparent", "important")

this.set(effectiveNav, "background-color", "transparent", "important")

this.set(container, "backdrop-filter", "none", "important")

this.set(effectiveNav, "backdrop-filter", "none", "important")

this.set(container, "border", "none", "important")

this.set(effectiveNav, "border", "none", "important")


const navElements = [

effectiveNav,

...Array.from(effectiveNav.querySelectorAll<HTMLElement>("*")),

]

navElements.forEach((el) => {


const computed = window.getComputedStyle(el)

const text = parseColor(computed.color)

const fill = parseColor(computed.fill)

const stroke = parseColor(computed.stroke)


// Recolor all text elements, links, spans, and buttons to alternateAccent (#5101F9)

if (

isExactYellow(text) ||

isLightText(text) ||

hasOwnText(el) ||

el.tagName === "SPAN" ||

el.tagName === "A" ||

el.tagName === "BUTTON" ||

el.tagName === "P"

) {

this.set(el, "color", alternateAccent, "important")

}

if (isExactYellow(fill) || isLightText(fill)) {

this.set(el, "fill", alternateAccent, "important")

}

if (isExactYellow(stroke) || isLightText(stroke)) {

this.set(el, "stroke", alternateAccent, "important")

}


// Recolor logo images: turn yellow/white into crisp #5101F9

if (el instanceof HTMLImageElement || el.tagName === "IMG") {

this.set(

el,

"filter",

"brightness(0) saturate(100%) invert(12%) sepia(96%) saturate(6329%) hue-rotate(256deg) brightness(97%) contrast(109%)",

"important"

)

// Vertically center the logo

this.set(el, "margin-top", "auto", "important")

this.set(el, "margin-bottom", "auto", "important")

this.set(el, "vertical-align", "middle", "important")

}


// Recolor SVG icons and paths

if (el.tagName === "svg" || el.tagName === "path") {

this.set(el, "color", alternateAccent, "important")

this.set(el, "fill", alternateAccent, "important")

this.set(el, "stroke", alternateAccent, "important")

}

})

}


const aboutLogo = document.getElementById("home-about-logo")

if (aboutLogo instanceof HTMLElement) {

this.set(

aboutLogo,

"filter",

"brightness(0) saturate(100%) invert(12%) sepia(96%) saturate(6329%) hue-rotate(256deg) brightness(97%) contrast(109%)"

)

}

const aboutCopy = document.getElementById("home-about-copy")

if (aboutCopy instanceof HTMLElement) {

;[

aboutCopy,

...Array.from(aboutCopy.querySelectorAll<HTMLElement>("*")),

].forEach((el) => this.set(el, "color", "#000000", "important"))

}

const parallax = document.getElementById("home-about-parallax")

if (parallax instanceof HTMLElement) {

const filterValue = ensureAboutParallaxFilter(alternateAccent)

Array.from(

parallax.querySelectorAll<HTMLElement>("img, video, canvas")

).forEach((el) => this.set(el, "filter", filterValue))

}


const footer = document.querySelector("footer")

if (footer instanceof HTMLElement) {

const footerEls = [

footer,

...Array.from(footer.querySelectorAll<HTMLElement>("*")),

]

this.set(footer, "background-color", alternateAccent)

this.set(footer, "border-color", alternateBackground)

this.set(footer, "mix-blend-mode", "normal", "important")

footerEls.forEach((el) => {

this.set(el, "color", alternateBackground, "important")

this.set(el, "fill", alternateBackground, "important")

this.set(el, "stroke", alternateBackground, "important")

this.set(el, "mix-blend-mode", "normal", "important")

this.set(el, "border-color", alternateBackground)

})

}


// Scoped sections: recolor surfaces, but do NOT overwrite interactive gallery filter buttons

const altColor = parseColor(alternateBackground) ?? {

r: 237,

g: 236,

b: 232,

a: 1,

}

const mediaRects = collectMediaRects(roots)

const backdropCache = new Map<HTMLElement, Backdrop>()

const backdropOf = (el: HTMLElement): Backdrop => {

const cached = backdropCache.get(el)

if (cached) return cached

const style = window.getComputedStyle(el)

let result: Backdrop

if (style.backgroundImage && style.backgroundImage !== "none") {

result = { color: null, media: true }

} else {

const bg = parseColor(style.backgroundColor)

if (bg && bg.a >= 0.5) result = { color: bg, media: false }

else if (el.parentElement) result = backdropOf(el.parentElement)

else result = { color: altColor, media: false }

}

backdropCache.set(el, result)

return result

}


const galleryButtons = getGalleryFilterButtons()


const scopeElements = Array.from(

new Set(

roots.flatMap((root) => [

root,

...Array.from(root.querySelectorAll<HTMLElement>("*")),

])

)

)

scopeElements.forEach((el) => {

// Skip gallery filter buttons and all their descendants (handled cleanly by syncGalleryFilterButtons)

if (

galleryButtons.includes(el) ||

el.closest("button, a, [role='button']") && galleryButtons.includes(el.closest("button, a, [role='button']") as HTMLElement) ||

el.closest("[data-framer-name*='Filter'], [data-framer-name*='Category'], [data-injected-filter]")

) {

return

}


const computed = window.getComputedStyle(el)

const bg = parseColor(computed.backgroundColor)

if (isNearBlack(bg))

this.set(el, "background-color", alternateBackground)

else if (isExactYellow(bg))

this.set(el, "background-color", alternateAccent)

const border = parseColor(computed.borderColor)

if (isNearBlack(border))

this.set(el, "border-color", alternateBackground)

else if (isExactYellow(border))

this.set(el, "border-color", alternateAccent)


const text = parseColor(computed.color)

const fill = parseColor(computed.fill)

const stroke = parseColor(computed.stroke)

const flipText = isExactYellow(text) || isLightText(text)

const flipFill = isExactYellow(fill) || isLightText(fill)

const flipStroke = isExactYellow(stroke) || isLightText(stroke)


if (flipText || flipFill || flipStroke) {

const backdrop = backdropOf(el)

const onLight =

!backdrop.media &&

backdrop.color !== null &&

relativeLuminance(backdrop.color) >= 0.4

if (onLight && !isOverMedia(el, mediaRects)) {

const blendHost = findBlendHost(el)

if (blendHost)

this.set(

blendHost,

"mix-blend-mode",

"normal",

"important"

)

if (flipText)

this.set(

el,

"color",

isExactYellow(text) ? alternateAccent : "#000000"

)

if (flipFill)

this.set(

el,

"fill",

isExactYellow(fill) ? alternateAccent : "#000000"

)

if (flipStroke)

this.set(

el,

"stroke",

isExactYellow(stroke) ? alternateAccent : "#000000"

)

}

}


// Safety net: never leave readable text matching its own surface.

if (hasOwnText(el)) {

const backdrop = backdropOf(el)

if (

backdrop.color &&

!backdrop.media &&

!isOverMedia(el, mediaRects) &&

!findBlendHost(el)

) {

const finalText = parseColor(

window.getComputedStyle(el).color

)

if (

finalText &&

finalText.a > 0.05 &&

contrastRatio(finalText, backdrop.color) < 2.5

) {

this.set(

el,

"color",

relativeLuminance(backdrop.color) >= 0.4

? "#000000"

: "#FFFFFF",

"important"

)

}

}

}

})


// Apply synchronized gallery filter buttons styling

syncGalleryFilterButtons(true)

}

}


const sharedThemeController = new ThemeController()


/**

* @framerSupportedLayoutWidth fixed

* @framerSupportedLayoutHeight fixed

*/

export default function TopThemeToggle(props: MyComponentProps) {

const {

targetIds = "home-hero,home-works,home-about",

primaryColor = "#000000",

alternateBackground = "#EDECE8",

alternateAccent = "#5101F9",

size = 28,

} = props

const isStatic = useIsStaticRenderer()

const buttonRef = useRef<HTMLButtonElement | null>(null)

const [isThemeTwo, setIsThemeTwo] = useState(themeRuntime.isThemeTwo)


const parsedIds = useMemo(() => {

return targetIds

.split(",")

.map((id) => id.trim())

.filter(Boolean)

}, [targetIds])


useEffect(() => {

if (typeof window === "undefined") return

if (isStatic) return

return subscribeTheme((next) => {

startTransition(() => setIsThemeTwo(next))

})

}, [isStatic])


useEffect(() => {

// Permanently hide redundant "Kategorie" link from navbar across Desktop & Mobile

const hideKategorie = () => {

if (typeof document === "undefined") return

document.querySelectorAll<HTMLElement>("a, button, li, [data-framer-name], .framer-f3nnQ").forEach((el) => {

const href = (el.getAttribute("href") || "").toLowerCase()

const name = (el.getAttribute("data-framer-name") || "").toLowerCase()

const text = (el.textContent || "")

.replace(/\s+/g, "")

.toLowerCase()

.replace(/(.)\1/g, "$1")

if (

href.includes("kategorie") ||

name.includes("kategorie") ||

(text.length < 25 && text.includes("kategorie"))

) {

el.style.setProperty("display", "none", "important")

el.style.setProperty("visibility", "hidden", "important")

const parent = el.parentElement

if (parent && (parent.children.length === 1 || parent.className.includes("-container") || parent.className.includes("veml6y"))) {

parent.style.setProperty("display", "none", "important")

parent.style.setProperty("visibility", "hidden", "important")

}

}

})


// Add mobile drawer theme toggle if drawer is open

const drawer = document.querySelector<HTMLElement>("[data-framer-name='Phone Open'], [data-framer-name='Menu links']")

if (drawer && !drawer.querySelector(".mobile-drawer-theme-toggle")) {

const toggle = document.createElement("button")

toggle.className = "mobile-drawer-theme-toggle"

toggle.setAttribute("type", "button")

toggle.setAttribute("aria-label", "Przełącz motyw")

toggle.innerHTML = `<span>🌓 PRZEŁĄCZ MOTYW</span>`

toggle.onclick = (e) => {

e.preventDefault()

e.stopPropagation()

setRuntimeTheme(!themeRuntime.isThemeTwo)

}

drawer.appendChild(toggle)

}

syncGalleryFilterButtons(themeRuntime.isThemeTwo)

}

hideKategorie()

const obs = new MutationObserver(hideKategorie)

obs.observe(document.body, { childList: true, subtree: true })

return () => obs.disconnect()

}, [])


useEffect(() => {

if (typeof window === "undefined" || isStatic) return

sharedThemeController.setOptions({

targetIds: parsedIds,

alternateBackground,

alternateAccent,

navRoot: buttonRef.current?.closest(

"nav, [role='navigation'], header"

),

})

sharedThemeController.setEnabled(themeRuntime.isThemeTwo)

}, [alternateAccent, alternateBackground, isStatic, parsedIds])


useEffect(() => {

if (typeof window === "undefined" || isStatic) return

sharedThemeController.setEnabled(isThemeTwo)

}, [isStatic, isThemeTwo])


const handleToggle = useCallback(() => {

if (typeof window === "undefined") return

startTransition(() => {

setRuntimeTheme(!themeRuntime.isThemeTwo)

})

}, [])


const ariaLabel = isThemeTwo

? "Switch upper section to theme 1"

: "Switch upper section to theme 2"

const iconColor = isThemeTwo ? "#000000" : primaryColor


return (

<button

ref={buttonRef}

type="button"

aria-label={ariaLabel}

onClick={handleToggle}

style={{

position: "relative",

width: size,

height: size,

borderRadius: "999px",

border: `1px solid ${primaryColor}`,

background: "transparent",

color: iconColor,

display: "inline-flex",

alignItems: "center",

justifyContent: "center",

padding: 0,

cursor: "pointer",

outline: "none",

}}

>

<svg

width={Math.max(14, size * 0.6)}

height={Math.max(14, size * 0.6)}

viewBox="0 0 24 24"

fill="none"

xmlns="http://www.w3.org/2000/svg"

aria-hidden="true"

>

{isThemeTwo ? (

<path

d="M15.8 3.8C14.55 3.45 13.22 3.48 11.99 3.9C10.76 4.32 9.7 5.1 8.95 6.15C8.2 7.19 7.8 8.44 7.8 9.72C7.8 11 8.2 12.25 8.95 13.29C9.7 14.34 10.76 15.12 11.99 15.54C13.22 15.96 14.55 15.99 15.8 15.64C15.12 16.97 14.03 18.05 12.69 18.72C11.35 19.38 9.83 19.6 8.35 19.34C6.88 19.08 5.52 18.36 4.49 17.28C3.46 16.2 2.81 14.81 2.63 13.33C2.44 11.85 2.72 10.35 3.42 9.05C4.13 7.74 5.22 6.69 6.55 6.07C7.88 5.45 9.37 5.29 10.8 5.63C12.24 5.97 13.5 6.79 14.37 7.95C14.61 6.44 15.11 5.01 15.8 3.8Z"

fill="currentColor"

/>

) : (

<>

<circle

cx="12"

cy="12"

r="4.1"

stroke="currentColor"

strokeWidth="1.8"

/>

<path

d="M12 2.8V5M12 19V21.2M21.2 12H19M5 12H2.8M18.5 5.5L17 7M7 17L5.5 18.5M18.5 18.5L17 17M7 7L5.5 5.5"

stroke="currentColor"

strokeWidth="1.8"

strokeLinecap="round"

/>

</>

)}

</svg>

</button>

)

}


addPropertyControls(TopThemeToggle, {

targetIds: {

type: ControlType.String,

title: "Target IDs",

defaultValue: "home-hero,home-works,home-about",

placeholder: "id-one,id-two,id-three",

},

primaryColor: {

type: ControlType.Color,

title: "Primary",

defaultValue: "#000000",

},

alternateBackground: {

type: ControlType.Color,

title: "Alt Surface",

defaultValue: "#EDECE8",

},

alternateAccent: {

type: ControlType.Color,

title: "Alt Accent",

defaultValue: "#5101F9",

},

size: {

type: ControlType.Number,

title: "Size",

defaultValue: 28,

min: 20,

max: 56,

step: 1,

unit: "px",

},

})