<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="he">
	<id>https://chabadpedia.co.il/index.php?action=history&amp;feed=atom&amp;title=%D7%99%D7%97%D7%99%D7%93%D7%94%3AWCAG</id>
	<title>יחידה:WCAG - היסטוריית גרסאות</title>
	<link rel="self" type="application/atom+xml" href="https://chabadpedia.co.il/index.php?action=history&amp;feed=atom&amp;title=%D7%99%D7%97%D7%99%D7%93%D7%94%3AWCAG"/>
	<link rel="alternate" type="text/html" href="https://chabadpedia.co.il/index.php?title=%D7%99%D7%97%D7%99%D7%93%D7%94:WCAG&amp;action=history"/>
	<updated>2026-04-21T09:23:26Z</updated>
	<subtitle>היסטוריית הגרסאות של הדף הזה בוויקי</subtitle>
	<generator>MediaWiki 1.43.1</generator>
	<entry>
		<id>https://chabadpedia.co.il/index.php?title=%D7%99%D7%97%D7%99%D7%93%D7%94:WCAG&amp;diff=796897&amp;oldid=prev</id>
		<title>מ. רובין: יצירת דף עם התוכן &quot;local WCAG = {} -- Function to determine the optimal text color (black or white) based on background color -- according to WCAG (Web Content Accessibility Guidelines) standards -- Input: Background color in hex format (e.g., &quot;#FF5733&quot; or &quot;FF5733&quot;) or RGB values (0-255) -- Output: Suitable text color (&quot;#000000&quot; for black or &quot;#FFFFFF&quot; for white)  function WCAG._getContrastTextColor(backgroundColor) 	mw.logObject(&quot;backgroundColor: &quot;..backgroundColor)     local...&quot;</title>
		<link rel="alternate" type="text/html" href="https://chabadpedia.co.il/index.php?title=%D7%99%D7%97%D7%99%D7%93%D7%94:WCAG&amp;diff=796897&amp;oldid=prev"/>
		<updated>2025-08-20T14:14:34Z</updated>

		<summary type="html">&lt;p&gt;יצירת דף עם התוכן &amp;quot;local WCAG = {} -- Function to determine the optimal text color (black or white) based on background color -- according to WCAG (Web Content Accessibility Guidelines) standards -- Input: Background color in hex format (e.g., &amp;quot;#FF5733&amp;quot; or &amp;quot;FF5733&amp;quot;) or RGB values (0-255) -- Output: Suitable text color (&amp;quot;#000000&amp;quot; for black or &amp;quot;#FFFFFF&amp;quot; for white)  function WCAG._getContrastTextColor(backgroundColor) 	mw.logObject(&amp;quot;backgroundColor: &amp;quot;..backgroundColor)     local...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;דף חדש&lt;/b&gt;&lt;/p&gt;&lt;div&gt;local WCAG = {}&lt;br /&gt;
-- Function to determine the optimal text color (black or white) based on background color&lt;br /&gt;
-- according to WCAG (Web Content Accessibility Guidelines) standards&lt;br /&gt;
-- Input: Background color in hex format (e.g., &amp;quot;#FF5733&amp;quot; or &amp;quot;FF5733&amp;quot;) or RGB values (0-255)&lt;br /&gt;
-- Output: Suitable text color (&amp;quot;#000000&amp;quot; for black or &amp;quot;#FFFFFF&amp;quot; for white)&lt;br /&gt;
&lt;br /&gt;
function WCAG._getContrastTextColor(backgroundColor)&lt;br /&gt;
	mw.logObject(&amp;quot;backgroundColor: &amp;quot;..backgroundColor)&lt;br /&gt;
    local r, g, b&lt;br /&gt;
    &lt;br /&gt;
    -- Handle different input formats&lt;br /&gt;
    if type(backgroundColor) == &amp;quot;string&amp;quot; then&lt;br /&gt;
        -- Remove # if present&lt;br /&gt;
        backgroundColor = backgroundColor:gsub(&amp;quot;#&amp;quot;, &amp;quot;&amp;quot;)&lt;br /&gt;
        &lt;br /&gt;
        -- Convert hex to RGB&lt;br /&gt;
        r = tonumber(backgroundColor:sub(1, 2), 16) or 0&lt;br /&gt;
        g = tonumber(backgroundColor:sub(3, 4), 16) or 0&lt;br /&gt;
        b = tonumber(backgroundColor:sub(5, 6), 16) or 0&lt;br /&gt;
    elseif type(backgroundColor) == &amp;quot;table&amp;quot; then&lt;br /&gt;
        r = backgroundColor.r or backgroundColor[1] or 0&lt;br /&gt;
        g = backgroundColor.g or backgroundColor[2] or 0&lt;br /&gt;
        b = backgroundColor.b or backgroundColor[3] or 0&lt;br /&gt;
    else&lt;br /&gt;
        return &amp;quot;#000000&amp;quot; -- default to black on error&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    -- Normalize RGB values to range 0-1&lt;br /&gt;
    r = r / 255&lt;br /&gt;
    g = g / 255&lt;br /&gt;
    b = b / 255&lt;br /&gt;
    &lt;br /&gt;
    -- Calculate luminance according to WCAG formula&lt;br /&gt;
    -- Convert RGB to sRGB&lt;br /&gt;
    r = r &amp;lt;= 0.03928 and r/12.92 or ((r+0.055)/1.055)^2.4&lt;br /&gt;
    g = g &amp;lt;= 0.03928 and g/12.92 or ((g+0.055)/1.055)^2.4&lt;br /&gt;
    b = b &amp;lt;= 0.03928 and b/12.92 or ((b+0.055)/1.055)^2.4&lt;br /&gt;
    &lt;br /&gt;
    -- Calculate relative luminance&lt;br /&gt;
    local luminance = 0.2126 * r + 0.7152 * g + 0.0722 * b&lt;br /&gt;
    &lt;br /&gt;
    -- WCAG recommends black text on light backgrounds and white text on dark backgrounds&lt;br /&gt;
    -- The threshold is typically at luminance of 0.5 but WCAG suggests 0.179 for better compliance&lt;br /&gt;
    if luminance &amp;gt; 0.179 then&lt;br /&gt;
        return &amp;quot;#000000&amp;quot; -- black text for light backgrounds&lt;br /&gt;
    else&lt;br /&gt;
        return &amp;quot;#FFFFFF&amp;quot; -- white text for dark backgrounds&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- Calculate contrast ratio between two colors (for advanced usage)&lt;br /&gt;
function WCAG._getContrastRatio(color1, color2)&lt;br /&gt;
    -- Implementation would convert colors to luminance values&lt;br /&gt;
    -- and calculate (L1 + 0.05) / (L2 + 0.05) where L1 is the lighter color&lt;br /&gt;
    &lt;br /&gt;
    -- This is a stub - expand as needed&lt;br /&gt;
    local l1 = 0.9 -- luminance of color1&lt;br /&gt;
    local l2 = 0.1 -- luminance of color2&lt;br /&gt;
    &lt;br /&gt;
    -- Ensure l1 is the lighter color (higher luminance)&lt;br /&gt;
    if l2 &amp;gt; l1 then&lt;br /&gt;
        l1, l2 = l2, l1&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    -- Calculate contrast ratio&lt;br /&gt;
    return (l1 + 0.05) / (l2 + 0.05)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function WCAG.getContrastTextColor(frame)&lt;br /&gt;
	local backgroundColor = frame.args[1]&lt;br /&gt;
	return WCAG._getContrastTextColor(backgroundColor)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- Example usage:&lt;br /&gt;
-- local textColor = getContrastTextColor(&amp;quot;#3366FF&amp;quot;)&lt;br /&gt;
-- local textColor = getContrastTextColor({51, 102, 255})&lt;br /&gt;
-- local contrastRatio = getContrastRatio(&amp;quot;#FFFFFF&amp;quot;, &amp;quot;#000000&amp;quot;) -- Would return approximately 21:1&lt;br /&gt;
&lt;br /&gt;
return WCAG&lt;/div&gt;</summary>
		<author><name>מ. רובין</name></author>
	</entry>
</feed>