Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add css variables and support link element #961

Merged
merged 13 commits into from
Dec 16, 2021
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
167 changes: 167 additions & 0 deletions integration_tests/specs/css/css-variables/css-variables.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
describe('CSS Variables', () => {
// https://github.com/web-platform-tests/wpt/blob/master/css/css-variables/css-variable-change-style-001.html
it('change-style-001', async () => {

document.body.appendChild(createStyle(`
.outer {
--x: red;
--y: green;
--z: 28px;
}
`));
document.head.appendChild(createStyle(`
.inner {
font-size: var(--z);
}
`));

document.body.appendChild(
<div class="outer">
<div class="inbetween">
<div class="inner">FontSize should be 28px.</div>
</div>
</div>
);

await snapshot();
});

it('change-style-002', async () => {
document.head.appendChild(createStyle(`
.inner {

--x: red;
--y: green;
--z: 28px;
font-size: var(--z);
}
`));

document.body.appendChild(
<div class="outer">
<div class="inbetween">
<div class="inner">FontSize should be 28px.</div>
</div>
</div>
);

await snapshot();
});


it('variable resolve color', async () => {
document.head.appendChild(createStyle(`
.inner {
--x: red;
--y: green;
--z: 28px;
background-color: var(--x);
}
`));

document.body.appendChild(
<div class="outer">
<div class="inbetween">
<div class="inner">Background should be red.</div>
</div>
</div>
);

await snapshot();
});

describe('Shorthand CSS properties', () => {
it('background', async () => {
document.head.appendChild(createStyle(`
.inner {
--x: red;
--y: green;
--z: 28px;
background: var(--y);
}
`));

document.body.appendChild(
<div class="outer">
<div class="inbetween">
<div class="inner">Background should be green.</div>
</div>
</div>
);

await snapshot();
});

it('margin', async () => {
document.head.appendChild(createStyle(`
.inner {
--x: red;
--y: green;
--z: 28px;
margin: var(--z);
background: red;
}
`));

document.body.appendChild(
<div class="outer">
<div class="inbetween">
<div class="inner">Background should be red with 28px margin.</div>
</div>
</div>
);

await snapshot();
});

it('padding', async () => {
document.head.appendChild(createStyle(`
.inner {
--x: red;
--y: green;
--z: 28px;
padding: var(--z);
background: red;
}
`));

document.body.appendChild(
<div class="outer">
<div class="inbetween">
<div class="inner">Background should be red with 28px padding.</div>
</div>
</div>
);

await snapshot();
});

it('border', async () => {
document.head.appendChild(createStyle(`
.inner {
--x: 4px;
--y: solid;
--z: green;
border: var(--x) var(--y) var(--z);
background: red;
}
`));

document.body.appendChild(
<div class="outer">
<div class="inbetween">
<div class="inner">Background should be red with 4px green solid border.</div>
</div>
</div>
);

await snapshot();
});
});

function createStyle(text) {
const style = document.createElement('style');
style.appendChild(document.createTextNode(text));
return style;
}
});
2 changes: 2 additions & 0 deletions kraken/lib/css.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export 'src/css/object_fit.dart';
export 'src/css/object_position.dart';
export 'src/css/sliver.dart';
export 'src/css/value.dart';
export 'src/css/variable.dart';
export 'src/css/keywords.dart';

// CSS Values
Expand All @@ -56,3 +57,4 @@ export 'src/css/values/position.dart';
export 'src/css/values/time.dart';
export 'src/css/values/percentage.dart';
export 'src/css/values/textual.dart';
export 'src/css/values/variable.dart';
8 changes: 4 additions & 4 deletions kraken/lib/src/bridge/to_native.dart
Original file line number Diff line number Diff line change
Expand Up @@ -366,8 +366,8 @@ List<UICommand> readNativeUICommandToDart(Pointer<Uint64> nativeCommandItems, in
// +-------+-------+
// | id | type |
// +-------+-------+
int id = typeIdCombine >> 32;
int type = typeIdCombine ^ (id << 32);
int id = (typeIdCombine >> 32).toSigned(32);
int type = (typeIdCombine ^ (id << 32)).toSigned(32);

command.type = UICommandType.values[type];
command.id = id;
Expand All @@ -382,8 +382,8 @@ List<UICommand> readNativeUICommandToDart(Pointer<Uint64> nativeCommandItems, in
if (args01And02Length == 0) {
args01Length = args02Length = 0;
} else {
args02Length = args01And02Length >> 32;
args01Length = args01And02Length ^ (args02Length << 32);
args02Length = (args01And02Length >> 32).toSigned(32);
args01Length = (args01And02Length ^ (args02Length << 32)).toSigned(32);
}

int args01StringMemory = rawMemory[i + args01StringMemOffset];
Expand Down
2 changes: 1 addition & 1 deletion kraken/lib/src/css/animation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ class KeyframeEffect extends AnimationEffect {

if (left == right) continue;

List? handlers = CSSTranstionHandlers[property];
List? handlers = CSSTransitionHandlers[property];
handlers ??= [_defaultParse, _defaultLerp];
Function parseProperty = handlers[0];

Expand Down
Loading