Skip to content

Commit 4b2faff

Browse files
Merge pull request #1078 from pattern-lab/feature/uikit-refactor-and-enhancements
Major UIKit Rendering Performance Improvements, Logo Customization, & LitElement Migration
2 parents 59de7ac + e285e78 commit 4b2faff

File tree

98 files changed

+3963
-1402
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

98 files changed

+3963
-1402
lines changed

packages/uikit-polyfills/index.js

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/**
2+
@license
3+
Copyright (c) 2017 The Polymer Project Authors. All rights reserved.
4+
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
5+
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
6+
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
7+
Code distributed by Google as part of the polymer project is also
8+
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
9+
*/
10+
11+
/*
12+
* Polyfills loaded: HTML Imports, Custom Elements, platform polyfills, template
13+
* Used in: IE 11
14+
*/
15+
16+
import 'regenerator-runtime/runtime';
17+
import '@webcomponents/template/template.js';
18+
import 'core-js/modules/es.array.find';
19+
20+
import 'element-closest';
21+
import 'core-js/modules/es.string.includes';
22+
import 'core-js/modules/es.array.includes';
23+
// import 'core-js/modules/es.array.from';
24+
// import 'core-js/modules/es.object.assign';
25+
26+
import './platform/remove-polyfill.js';
27+
import './platform/es6-misc';
28+
import './platform/custom-event';
29+
import './platform/promise';
30+
import './platform/symbol';
31+
import './platform/flag-parser';
32+
// import '@webcomponents/custom-elements/src/custom-elements.js';
33+
34+
import '@webcomponents/custom-elements/src/custom-elements.js';
35+
36+
// import 'document-register-element';
37+
// by default, the second argument is 'auto'
38+
// but it could be also 'force'
39+
// which ignores feature detection and force
40+
// the polyfill version of CustomElements
41+
// installCE(global, 'auto');
42+
43+
import '@webcomponents/url/url.js';
44+
import './platform/baseuri';
45+
import './platform/unresolved';
46+
47+
import 'core-js/modules/es.array.for-each';
48+
49+
if (window.NodeList && !NodeList.prototype.forEach) {
50+
NodeList.prototype.forEach = Array.prototype.forEach;
51+
}
52+
53+
// import 'core-js/modules/es.string.trim-end';
54+
// import 'core-js/modules/es.string.trim-start';
55+
// import 'core-js/modules/es.string.code-point-at';
56+
// import 'core-js/modules/es.number.is-nan';

packages/uikit-polyfills/package.json

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"name": "@pattern-lab/uikit-polyfills",
3+
"version": "0.0.0",
4+
"description": "Web Component Polyfills used in Pattern Lab's UIKit",
5+
"main": "index.js",
6+
"author": "Salem Ghoweri <[email protected]>",
7+
"license": "MIT",
8+
"dependencies": {
9+
"@ungap/weakset": "^0.1.5",
10+
"@webcomponents/custom-elements": "^1.3.0",
11+
"@webcomponents/shadycss": "^1.9.2",
12+
"@webcomponents/shadydom": "^1.6.1",
13+
"@webcomponents/template": "^1.4.1",
14+
"@webcomponents/url": "^0.7.4",
15+
"@webcomponents/webcomponentsjs": "^2.3.0",
16+
"core-js": "^3.3.6",
17+
"custom-event-polyfill": "^1.0.7",
18+
"document-register-element": "^1.14.3",
19+
"es6-promise": "^4.2.8",
20+
"get-own-property-symbols": "^0.9.3",
21+
"promise-polyfill": "^8.0.0"
22+
},
23+
"publishConfig": {
24+
"access": "public"
25+
}
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/**
2+
@license
3+
Copyright (c) 2018 The Polymer Project Authors. All rights reserved.
4+
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
5+
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
6+
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
7+
Code distributed by Google as part of the polymer project is also
8+
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
9+
*/
10+
11+
export {};
12+
13+
// Implement Node.baseURI for IE 11
14+
// adapted from
15+
// https://github.com/webcomponents/html-imports/blob/v1.2.0/src/html-imports.js
16+
17+
/** @type {Object|undefined} */
18+
const nativeBaseURI = Object.getOwnPropertyDescriptor(
19+
Node.prototype,
20+
'baseURI'
21+
);
22+
if (!nativeBaseURI) {
23+
Object.defineProperty(Node.prototype, 'baseURI', {
24+
/**
25+
* @this {Node}
26+
* @return {string}
27+
*/
28+
get() {
29+
// this.ownerDocument is `null` for documents
30+
const doc = this.ownerDocument || this;
31+
const base = /** @type {HTMLBaseElement} */ (doc.querySelector(
32+
'base[href]'
33+
));
34+
return (base && base.href) || window.location.href;
35+
},
36+
configurable: true,
37+
enumerable: true,
38+
});
39+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
/**
2+
* @license
3+
* Copyright (c) 2016 The Polymer Project Authors. All rights reserved.
4+
* This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
5+
* The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
6+
* The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
7+
* Code distributed by Google as part of the polymer project is also
8+
* subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
9+
*/
10+
11+
(function() {
12+
// defaultPrevented is broken in IE.
13+
// https://connect.microsoft.com/IE/feedback/details/790389/event-defaultprevented-returns-false-after-preventdefault-was-called
14+
const workingDefaultPrevented = (function() {
15+
const e = document.createEvent('Event');
16+
e.initEvent('foo', true, true);
17+
e.preventDefault();
18+
return e.defaultPrevented;
19+
})();
20+
21+
if (!workingDefaultPrevented) {
22+
const origPreventDefault = Event.prototype.preventDefault;
23+
Event.prototype.preventDefault = function() {
24+
if (!this.cancelable) {
25+
return;
26+
}
27+
28+
origPreventDefault.call(this);
29+
30+
Object.defineProperty(this, 'defaultPrevented', {
31+
get() {
32+
return true;
33+
},
34+
configurable: true,
35+
});
36+
};
37+
}
38+
39+
const isIE = /Trident/.test(navigator.userAgent);
40+
41+
// Event constructor shim
42+
if (!window.Event || (isIE && typeof window.Event !== 'function')) {
43+
const origEvent = window.Event;
44+
/**
45+
* @param {!string} inType
46+
* @param {?(EventInit)=} params
47+
*/
48+
window.Event = function(inType, params) {
49+
params = params || {};
50+
const e = document.createEvent('Event');
51+
e.initEvent(inType, Boolean(params.bubbles), Boolean(params.cancelable));
52+
return e;
53+
};
54+
if (origEvent) {
55+
for (const i in origEvent) {
56+
window.Event[i] = origEvent[i];
57+
}
58+
window.Event.prototype = origEvent.prototype;
59+
}
60+
}
61+
62+
// CustomEvent constructor shim
63+
if (
64+
!window.CustomEvent ||
65+
(isIE && typeof window.CustomEvent !== 'function')
66+
) {
67+
/**
68+
* @template T
69+
* @param {!string} inType
70+
* @param {?(CustomEventInit<T>)=} params
71+
*/
72+
window.CustomEvent = function(inType, params) {
73+
params = params || {};
74+
const e = document.createEvent('CustomEvent');
75+
e.initCustomEvent(
76+
inType,
77+
Boolean(params.bubbles),
78+
Boolean(params.cancelable),
79+
params.detail
80+
);
81+
return e;
82+
};
83+
window.CustomEvent.prototype = window.Event.prototype;
84+
}
85+
86+
if (!window.MouseEvent || (isIE && typeof window.MouseEvent !== 'function')) {
87+
const origMouseEvent = window.MouseEvent;
88+
/**
89+
*
90+
* @param {!string} inType
91+
* @param {?(MouseEventInit)=} params
92+
*/
93+
window.MouseEvent = function(inType, params) {
94+
params = params || {};
95+
const e = document.createEvent('MouseEvent');
96+
e.initMouseEvent(
97+
inType,
98+
Boolean(params.bubbles),
99+
Boolean(params.cancelable),
100+
params.view || window,
101+
params.detail,
102+
params.screenX,
103+
params.screenY,
104+
params.clientX,
105+
params.clientY,
106+
params.ctrlKey,
107+
params.altKey,
108+
params.shiftKey,
109+
params.metaKey,
110+
params.button,
111+
params.relatedTarget
112+
);
113+
return e;
114+
};
115+
if (origMouseEvent) {
116+
for (const j in origMouseEvent) {
117+
window.MouseEvent[j] = origMouseEvent[j];
118+
}
119+
}
120+
window.MouseEvent.prototype = origMouseEvent.prototype;
121+
}
122+
})();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/**
2+
* @license
3+
* Copyright (c) 2016 The Polymer Project Authors. All rights reserved.
4+
* This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
5+
* The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
6+
* The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
7+
* Code distributed by Google as part of the polymer project is also
8+
* subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
9+
*/
10+
11+
(function() {
12+
if (!Array.from) {
13+
Array.from = function(object) {
14+
return [].slice.call(/** @type {IArrayLike} */ (object));
15+
};
16+
}
17+
18+
if (!Object.assign) {
19+
const assign = function(target, source) {
20+
const n$ = Object.getOwnPropertyNames(source);
21+
for (var i = 0, p; i < n$.length; i++) {
22+
p = n$[i];
23+
target[p] = source[p];
24+
}
25+
};
26+
27+
Object.assign = function(target) {
28+
const args = [].slice.call(arguments, 1);
29+
for (var i = 0, s; i < args.length; i++) {
30+
s = args[i];
31+
if (s) {
32+
assign(target, s);
33+
}
34+
}
35+
return target;
36+
};
37+
}
38+
})();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/* eslint-disable no-restricted-globals */
2+
/**
3+
* @license
4+
* Copyright (c) 2014 The Polymer Project Authors. All rights reserved.
5+
* This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
6+
* The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
7+
* The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
8+
* Code distributed by Google as part of the polymer project is also
9+
* subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
10+
*/
11+
12+
export {};
13+
14+
// Establish scope.
15+
window.WebComponents = window.WebComponents || { flags: {} };
16+
17+
// loading script
18+
const file = 'webcomponents-bundle';
19+
const script = document.querySelector(`script[src*="${file}"]`);
20+
const flagMatcher = /wc-(.+)/;
21+
22+
// Flags. Convert url arguments to flags
23+
const flags = {};
24+
if (!flags.noOpts) {
25+
// from url
26+
location.search
27+
.slice(1)
28+
.split('&')
29+
.forEach(option => {
30+
const parts = option.split('=');
31+
let match;
32+
if (parts[0] && (match = parts[0].match(flagMatcher))) {
33+
flags[match[1]] = parts[1] || true;
34+
}
35+
});
36+
// from script
37+
if (script) {
38+
for (let i = 0, a; (a = script.attributes[i]); i++) {
39+
if (a.name !== 'src') {
40+
flags[a.name] = a.value || true;
41+
}
42+
}
43+
}
44+
// log flags
45+
if (flags.log && flags.log.split) {
46+
const parts = flags.log.split(',');
47+
flags.log = {};
48+
parts.forEach(f => {
49+
flags.log[f] = true;
50+
});
51+
} else {
52+
flags.log = {};
53+
}
54+
}
55+
56+
// exports
57+
window.WebComponents.flags = flags;
58+
const forceShady = flags.shadydom;
59+
if (forceShady) {
60+
window.ShadyDOM = window.ShadyDOM || {};
61+
window.ShadyDOM.force = forceShady;
62+
const { noPatch } = flags;
63+
window.ShadyDOM.noPatch = noPatch === 'true' ? true : noPatch;
64+
}
65+
66+
const forceCE = flags.register || flags.ce;
67+
if (forceCE && window.customElements) {
68+
window.customElements.forcePolyfill = forceCE;
69+
}

0 commit comments

Comments
 (0)