Skip to content

Commit e2365f6

Browse files
committed
review
1 parent c35de7b commit e2365f6

File tree

4 files changed

+31
-27
lines changed

4 files changed

+31
-27
lines changed

Diff for: index.html

+22-18
Original file line numberDiff line numberDiff line change
@@ -1329,7 +1329,6 @@ <h2>
13291329
top: anchor(center);
13301330
}</code></pre>
13311331
</section>
1332-
13331332
<section id="imports" class="demo-item">
13341333
<h2>
13351334
<a href="#imports" aria-hidden="true">🔗</a>
@@ -1340,17 +1339,20 @@ <h2>
13401339
<div class="target" id="target-1">Target One</div>
13411340
<div class="target" id="target-2">Target Two</div>
13421341
</div>
1343-
<p class="note">
1344-
With polyfill applied: Target and Anchor text is orange (from styles
1345-
defined in an imported stylesheet). Target One is positioned at the
1346-
bottom right corner of the Anchor. The Anchor has an envelope icon on
1347-
both sides of the text.<br />
1348-
1349-
<strong>Note:</strong> Target Two has <code>position-area</code> defined
1350-
in an imported stylesheet, which is not parsed by the polyfill, so it is
1351-
not positioned correctly. It should be positioned at the bottom left
1352-
corner.
1353-
</p>
1342+
<div class="note">
1343+
<p>
1344+
With polyfill applied: Target and Anchor text is orange (from styles
1345+
defined in an imported stylesheet). Target One is positioned at the
1346+
bottom right corner of the Anchor. The Anchor has an envelope icon on
1347+
both sides of the text.
1348+
</p>
1349+
<p>
1350+
<strong>Note:</strong> Target Two has
1351+
<code>position-area</code> defined in an imported stylesheet, which is
1352+
not parsed by the polyfill, so it is not positioned correctly. It
1353+
should be positioned at the bottom left corner.
1354+
</p>
1355+
</div>
13541356
<pre><code class="language-css">@import url('./import-is-imported-url.css') supports(display: grid) screen and (min-width: 400px);
13551357
@import './import-is-imported-string.css';
13561358

@@ -1359,22 +1361,24 @@ <h2>
13591361
}
13601362

13611363
/* ./import-is-imported-url.css */
1362-
#imports #target-1{
1364+
#imports #target-1 {
13631365
color: var(--brand-orange);
13641366
}
13651367

1366-
#imports #target-2{
1368+
#imports #target-2 {
13671369
position-area: block-end inline-start;
13681370
color: var(--brand-orange);
13691371
}
13701372

1373+
#imports .anchor::before {
1374+
content: url('./mail.svg');
1375+
}
1376+
13711377
/* ./import-is-imported-string.css */
1372-
#imports .anchor{
1378+
#imports .anchor {
13731379
color: var(--brand-orange);
1374-
}
1375-
</code></pre>
1380+
}</code></pre>
13761381
</section>
1377-
13781382
<section id="sponsor">
13791383
<h2>Sponsor OddBird’s OSS Work</h2>
13801384
<p>

Diff for: src/polyfill.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -593,14 +593,14 @@ export async function polyfill(
593593
// pre parse CSS styles that we need to cascade
594594
const cascadeCausedChanges = cascadeCSS(styleData);
595595
if (cascadeCausedChanges) {
596-
styleData = await transformCSS(styleData);
596+
styleData = transformCSS(styleData);
597597
}
598598
// parse CSS
599599
const { rules, inlineStyles } = await parseCSS(styleData);
600600

601601
if (Object.values(rules).length) {
602602
// update source code
603-
await transformCSS(styleData, inlineStyles, true);
603+
transformCSS(styleData, inlineStyles, true);
604604

605605
// calculate position values
606606
await position(rules, options.useAnimationFrame);

Diff for: src/transform.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const excludeAttributes = [
2121
'type',
2222
];
2323

24-
export async function transformCSS(
24+
export function transformCSS(
2525
styleData: StyleData[],
2626
inlineStyles?: Map<HTMLElement, Record<string, string>>,
2727
cleanup = false,

Diff for: tests/unit/transform.test.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { transformCSS } from '../../src/transform.js';
22

33
describe('transformCSS', () => {
4-
it('parses and removes new anchor positioning CSS after transformation to JS', async () => {
4+
it('parses and removes new anchor positioning CSS after transformation to JS', () => {
55
document.head.innerHTML = `
66
<link type="text/css" href="/sample.css" data-link="true" crossorigin="anonymous" />
77
<style>
@@ -32,7 +32,7 @@ describe('transformCSS', () => {
3232
];
3333
const inlineStyles = new Map();
3434
inlineStyles.set(div, { '--foo': '--bar' });
35-
await transformCSS(styleData, inlineStyles, true);
35+
transformCSS(styleData, inlineStyles, true);
3636

3737
expect(link.isConnected).toBe(false);
3838
const newLink = document.querySelector(
@@ -49,7 +49,7 @@ describe('transformCSS', () => {
4949
expect(div2.hasAttribute('data-has-inline-styles')).toBeFalsy();
5050
});
5151

52-
it('preserves id, media, and title attributes when replacing link elements', async () => {
52+
it('preserves id, media, and title attributes when replacing link elements', () => {
5353
document.head.innerHTML = `
5454
<link id="the-link" media="screen" title="stylish" rel="stylesheet" href="/sample.css"/>
5555
`;
@@ -58,7 +58,7 @@ describe('transformCSS', () => {
5858
const inlineStyles = new Map();
5959
const initialStyleElement = document.querySelector('style');
6060
expect(initialStyleElement).toBe(null);
61-
await transformCSS(styleData, inlineStyles, true);
61+
transformCSS(styleData, inlineStyles, true);
6262
const transformedStyleElement = document.querySelector(
6363
'style',
6464
) as HTMLStyleElement;
@@ -70,7 +70,7 @@ describe('transformCSS', () => {
7070
expect(transformedLink).toBe(null);
7171
});
7272

73-
it('creates new style elements for created styles', async () => {
73+
it('creates new style elements for created styles', () => {
7474
document.head.innerHTML = ``;
7575
const styleData = [
7676
{
@@ -80,7 +80,7 @@ describe('transformCSS', () => {
8080
created: true,
8181
},
8282
];
83-
await transformCSS(styleData, undefined, true);
83+
transformCSS(styleData, undefined, true);
8484

8585
const createdStyleElement = document.querySelector(
8686
'style',

0 commit comments

Comments
 (0)