Skip to content

Commit

Permalink
Merge branch 'css-build-dir' into behaviors-no-mixin
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinpschaaf committed Nov 14, 2018
2 parents ed5f7f2 + e00bf99 commit 6c93955
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
22 changes: 14 additions & 8 deletions lib/mixins/dir-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ const HOST_DIR_REPLACMENT = ':host([dir="$1"])';
const EL_DIR = /([\s\w-#\.\[\]\*]*):dir\((ltr|rtl)\)/g;
const EL_DIR_REPLACMENT = ':host([dir="$2"]) $1';

const DIR_CHECK = /:dir\((?:ltr|rtl)\)/;

const SHIM_SHADOW = Boolean(window['ShadyDOM'] && window['ShadyDOM']['inUse']);

/**
* @type {!Array<!Polymer_DirMixin>}
*/
Expand Down Expand Up @@ -80,10 +84,12 @@ function takeRecords() {
*/
export const DirMixin = dedupingMixin((base) => {

if (!observer) {
getRTL();
observer = new MutationObserver(updateDirection);
observer.observe(document.documentElement, {attributes: true, attributeFilter: ['dir']});
if (!SHIM_SHADOW) {
if (!observer) {
getRTL();
observer = new MutationObserver(updateDirection);
observer.observe(document.documentElement, {attributes: true, attributeFilter: ['dir']});
}
}

/**
Expand All @@ -107,7 +113,10 @@ export const DirMixin = dedupingMixin((base) => {
*/
static _processStyleText(cssText, baseURI) {
cssText = super._processStyleText(cssText, baseURI);
cssText = this._replaceDirInCssText(cssText);
if (!SHIM_SHADOW && DIR_CHECK.test(cssText)) {
cssText = this._replaceDirInCssText(cssText);
this.__activateDir = true;
}
return cssText;
}

Expand All @@ -121,9 +130,6 @@ export const DirMixin = dedupingMixin((base) => {
let replacedText = text;
replacedText = replacedText.replace(HOST_DIR, HOST_DIR_REPLACMENT);
replacedText = replacedText.replace(EL_DIR, EL_DIR_REPLACMENT);
if (text !== replacedText) {
this.__activateDir = true;
}
return replacedText;
}

Expand Down
8 changes: 6 additions & 2 deletions test/unit/dir.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
<script src="../../node_modules/@webcomponents/webcomponentsjs/webcomponents-bundle.js"></script>
<script src="wct-browser-config.js"></script>
<script src="../../node_modules/wct-browser-legacy/browser.js"></script>
<script type="module" src="../../polymer-legacy.js"></script>
<script type="module" src="../../lib/mixins/dir-mixin.js"></script>
</head>
<body>
<!--
Expand Down Expand Up @@ -219,6 +217,9 @@
});

test('elements with dir attribute explicitly set will not change', function() {
if (window.ShadyDOM && window.ShadyDOM.inUse) {
this.skip();
}
let inner = fixture('preset');
assert.equal(document.documentElement.getAttribute('dir'), 'rtl');
assertComputed(inner.shadowRoot.querySelector('.special > div'), 'rgb(255, 255, 255)', 'color');
Expand Down Expand Up @@ -247,6 +248,9 @@
});

test('complicated setup', function() {
if (window.ShadyDOM && window.ShadyDOM.inUse) {
this.skip();
}
let el = fixture('complicated');
assertComputed(el.$.direct, '10px');
assertComputed(el.$.indirect, '9px');
Expand Down

0 comments on commit 6c93955

Please sign in to comment.