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

Fix webkit properties #166

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions lib/CSSStyleDeclaration.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ var allExtraProperties = require('./allExtraProperties');
var implementedProperties = require('./implementedProperties');
var { dashedToCamelCase } = require('./parsers');
var getBasicPropertyDescriptor = require('./utils/getBasicPropertyDescriptor');
var getColorPropertyDescriptor = require('./utils/getColorPropertyDescriptor');

/**
* @constructor
Expand Down Expand Up @@ -251,9 +252,19 @@ allProperties.forEach(function (property) {

allExtraProperties.forEach(function (property) {
if (!implementedProperties.has(property)) {
var declaration = getBasicPropertyDescriptor(property);
var declaration = property.endsWith('-color')
? getColorPropertyDescriptor(property)
: getBasicPropertyDescriptor(property);
Object.defineProperty(CSSStyleDeclaration.prototype, property, declaration);
Object.defineProperty(CSSStyleDeclaration.prototype, dashedToCamelCase(property), declaration);
var camelCased = dashedToCamelCase(property);
Object.defineProperty(CSSStyleDeclaration.prototype, camelCased, declaration);
if (property.startsWith('-')) {
Object.defineProperty(
CSSStyleDeclaration.prototype,
camelCased.charAt(0).toLowerCase() + camelCased.slice(1),
declaration
);
}
}
});

Expand Down
36 changes: 36 additions & 0 deletions lib/CSSStyleDeclaration.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -553,4 +553,40 @@ describe('CSSStyleDeclaration', () => {
style.setProperty('width', 'calc(100% - 100px)');
expect(style.getPropertyValue('width')).toEqual('calc(100% - 100px)');
});

test('implements webkitTextFillColor', () => {
const style = new CSSStyleDeclaration();
style.setProperty('-webkit-text-fill-color', '#ffffff66');

expect(style.webkitTextFillColor).toEqual('rgba(255, 255, 255, 0.4)');
expect(style.WebkitTextFillColor).toEqual('rgba(255, 255, 255, 0.4)');
expect(style.cssText).toEqual('-webkit-text-fill-color: rgba(255, 255, 255, 0.4);');
});

test('vendor property with cssText', () => {
const style = new CSSStyleDeclaration();
style.cssText = '-webkit-line-clamp: 20';

expect(style.WebkitLineClamp).toEqual('20');
expect(style.webkitLineClamp).toEqual('20');
expect(style.getPropertyValue('-webkit-line-clamp')).toEqual('20');
});

test('-webkit-transform', () => {
const style = new CSSStyleDeclaration();
style.cssText = '-webkit-transform: scale(2);';

expect(style.WebkitTransform).toEqual('scale(2)');
expect(style.WebkitTransform).toEqual('scale(2)');
expect(style.getPropertyValue('-webkit-transform')).toEqual('scale(2)');
});

test('-webkit-text-stroke-width', () => {
const style = new CSSStyleDeclaration();
style.cssText = '-webkit-text-stroke-width: 0.5em;';

expect(style.WebkitTextStrokeWidth).toEqual('0.5em');
expect(style.webkitTextStrokeWidth).toEqual('0.5em');
expect(style.getPropertyValue('-webkit-text-stroke-width')).toEqual('0.5em');
});
});
1 change: 0 additions & 1 deletion lib/allProperties.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
*/

module.exports = new Set([
'-webkit-line-clamp',
'accent-color',
'align-content',
'align-items',
Expand Down
2 changes: 1 addition & 1 deletion lib/allWebkitProperties.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,4 +191,4 @@ module.exports = [
'wrap-through',
'writing-mode',
'zoom',
].map((prop) => 'webkit-' + prop);
].map((prop) => '-webkit-' + prop);
14 changes: 0 additions & 14 deletions lib/properties/webkitBorderAfterColor.js

This file was deleted.

14 changes: 0 additions & 14 deletions lib/properties/webkitBorderBeforeColor.js

This file was deleted.

14 changes: 0 additions & 14 deletions lib/properties/webkitBorderEndColor.js

This file was deleted.

14 changes: 0 additions & 14 deletions lib/properties/webkitBorderStartColor.js

This file was deleted.

14 changes: 0 additions & 14 deletions lib/properties/webkitColumnRuleColor.js

This file was deleted.

14 changes: 0 additions & 14 deletions lib/properties/webkitMatchNearestMailBlockquoteColor.js

This file was deleted.

14 changes: 0 additions & 14 deletions lib/properties/webkitTapHighlightColor.js

This file was deleted.

14 changes: 0 additions & 14 deletions lib/properties/webkitTextEmphasisColor.js

This file was deleted.

14 changes: 0 additions & 14 deletions lib/properties/webkitTextFillColor.js

This file was deleted.

14 changes: 0 additions & 14 deletions lib/properties/webkitTextStrokeColor.js

This file was deleted.

16 changes: 16 additions & 0 deletions lib/utils/getColorPropertyDescriptor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
'use strict';

var parseColor = require('../parsers').parseColor;

module.exports = function getColorPropertyDescriptor(name) {
return {
set: function (v) {
this._setProperty(name, parseColor(v));
},
get: function () {
return this.getPropertyValue(name);
},
enumerable: true,
configurable: true,
};
};
10 changes: 9 additions & 1 deletion scripts/generate_implemented_properties.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,15 @@ const camelToDashed = require('../lib/parsers').camelToDashed;
const dashedProperties = fs
.readdirSync(path.resolve(__dirname, '../lib/properties'))
.filter((propertyFile) => propertyFile.substr(-3) === '.js')
.map((propertyFile) => camelToDashed(propertyFile.replace('.js', '')));
.map((propertyFile) => camelToDashed(propertyFile.replace('.js', '')))
.map((property) => {
const isWebkit = /^-webkit-/.test(property);
if (isWebkit) {
return '-' + property;
} else {
return property;
}
});

const out_file = fs.createWriteStream(path.resolve(__dirname, '../lib/implementedProperties.js'), {
encoding: 'utf-8',
Expand Down
4 changes: 4 additions & 0 deletions scripts/generate_properties.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,10 @@ parsedFiles.forEach(function (file) {
var propertyDefinitions = [];
parsedFiles.forEach(function (file) {
var dashed = camelToDashed(file.property);
var isWebkit = /^-webkit-/.test(dashed);
if (isWebkit) {
dashed = '-' + dashed;
}
propertyDefinitions.push(
t.objectProperty(
t.identifier(file.property),
Expand Down