Skip to content

Commit 2a91740

Browse files
committed
[css-color] Add intro to the API section.
1 parent d5a3988 commit 2a91740

2 files changed

Lines changed: 86 additions & 5 deletions

File tree

css-color/Overview.bs

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2466,7 +2466,49 @@ Default Style Rules</h2>
24662466
<h2 id='apis'>
24672467
APIs for Parsing and Manipulating Colors</h2>
24682468

2469-
Issue: This section is in the process of being written and cleaned up.
2469+
In many applications, authors have to use and manipulate colors.
2470+
CSS allows many different useful syntaxes for colors,
2471+
but these are only usable in stylesheets,
2472+
not in script.
2473+
2474+
This section defines a number of APIs for creating and manipulating colors in script:
2475+
2476+
<ul>
2477+
<li>
2478+
It allows CSS colors to be parsed into JS objects--
2479+
use the <code>CSSColor.parse("rebeccapurple")</code> method to get a corresponding color object,
2480+
or one of the specific color constructors,
2481+
like <code>new HSLColor("rebeccapurple")</code>,
2482+
to get back a specific type of color class.
2483+
2484+
<li>
2485+
It allows colors to be manipulated in any of the syntaxes that CSS exposes:
2486+
<a idl>RGBColor</a> for RGBA colors, with components ranging from 0-1;
2487+
<a idl>HexColor</a> for RGBA colors, with components ranging from 0-255;
2488+
<a idl>HSLColor</a> for HSLA colors, corresponding to the ''hsla()'' syntax;
2489+
and <a idl>CMYKColor</a> for CMYK colors, corresponding to the ''device-cmyk()'' syntax.
2490+
2491+
All of these expose their components as attributes you can manipulate directly,
2492+
and colors can be easily converted between any of the classes with methods like <code>toRGB()</code> and <code>toHSL()</code>.
2493+
2494+
<li>
2495+
It allows colors to be automatically stringified back into a form that CSS understands,
2496+
so you can write code like:
2497+
2498+
<pre>
2499+
var c = new HSLColor("red");
2500+
c.l += .1;
2501+
el.style.backgroundColor = c;
2502+
// c is automatically turned into the string "rgba(100%, 20%, 20%, 100%)"
2503+
</pre>
2504+
2505+
If you wish, you can control what type of syntax it stringifies as,
2506+
like <code>c.toString("hsl")</code>.
2507+
2508+
<li>
2509+
It's explicitly designed to be easy to extend with new methods and new color types,
2510+
and gives guidance to help you do it correctly (see <a section href="#api-extending"></a>).
2511+
</ul>
24702512

24712513
<h3 id='api-RGBColor'>
24722514
The RGBColor Object</h3>

css-color/Overview.html

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2589,7 +2589,48 @@ <h2 class="heading settled heading" data-level=14 id=sample><span class=secno>14
25892589
<h2 class="heading settled heading" data-level=15 id=apis><span class=secno>15 </span><span class=content>
25902590
APIs for Parsing and Manipulating Colors</span><a class=self-link href=#apis></a></h2>
25912591

2592-
<p class=issue id=issue-dc028349><a class=self-link href=#issue-dc028349></a>This section is in the process of being written and cleaned up.</p>
2592+
<p>In many applications, authors have to use and manipulate colors.
2593+
CSS allows many different useful syntaxes for colors,
2594+
but these are only usable in stylesheets,
2595+
not in script.</p>
2596+
2597+
<p>This section defines a number of APIs for creating and manipulating colors in script:</p>
2598+
2599+
<ul>
2600+
<li>
2601+
It allows CSS colors to be parsed into JS objects—<wbr>use the <code>CSSColor.parse("rebeccapurple")</code> method to get a corresponding color object,
2602+
or one of the specific color constructors,
2603+
like <code>new HSLColor("rebeccapurple")</code>,
2604+
to get back a specific type of color class.
2605+
2606+
<li>
2607+
It allows colors to be manipulated in any of the syntaxes that CSS exposes:
2608+
<a data-link-type=idl href=#dom-rgbcolor title=rgbcolor>RGBColor</a> for RGBA colors, with components ranging from 0-1;
2609+
<a data-link-type=idl href=#dom-hexcolor title=hexcolor>HexColor</a> for RGBA colors, with components ranging from 0-255;
2610+
<a data-link-type=idl href=#dom-hslcolor title=hslcolor>HSLColor</a> for HSLA colors, corresponding to the <a class=css data-link-type=maybe href=#funcdef-hsla title=hsla()>hsla()</a> syntax;
2611+
and <a data-link-type=idl href=#dom-cmykcolor title=cmykcolor>CMYKColor</a> for CMYK colors, corresponding to the <a class=css data-link-type=maybe href=#funcdef-device-cmyk title=device-cmyk()>device-cmyk()</a> syntax.
2612+
2613+
<p>All of these expose their components as attributes you can manipulate directly,
2614+
and colors can be easily converted between any of the classes with methods like <code>toRGB()</code> and <code>toHSL()</code>.</p>
2615+
2616+
<li>
2617+
It allows colors to be automatically stringified back into a form that CSS understands,
2618+
so you can write code like:
2619+
2620+
<pre>var c = new HSLColor("red");
2621+
c.l += .1;
2622+
el.style.backgroundColor = c;
2623+
// c is automatically turned into the string "rgba(100%, 20%, 20%, 100%)"
2624+
</pre>
2625+
2626+
<p>If you wish, you can control what type of syntax it stringifies as,
2627+
like <code>c.toString("hsl")</code>.</p>
2628+
2629+
<li>
2630+
It’s explicitly designed to be easy to extend with new methods and new color types,
2631+
and gives guidance to help you do it correctly (see <a data-section="" href=#api-extending>§15.5
2632+
Extending the Color Classes</a>).
2633+
</ul>
25932634

25942635
<h3 class="heading settled heading" data-level=15.1 id=api-RGBColor><span class=secno>15.1 </span><span class=content>
25952636
The RGBColor Object</span><a class=self-link href=#api-RGBColor></a></h3>
@@ -4428,6 +4469,4 @@ <h2 class="no-num heading settled" id=issues-index><span class=content>Issues In
44284469
Really? Shouldn’t video be consistent with images?
44294470
Or do implementations really do this differently?
44304471

4431-
<a href=#issue-9c7b92e0></a></div><div class=issue>This section is in the process of being written and cleaned up.<a href=#issue-dc028349></a></div>
4432-
4433-
</div>
4472+
<a href=#issue-9c7b92e0></a></div></div>

0 commit comments

Comments
 (0)