├── .eslintrc.json
├── .github
├── FUNDING.yml
└── workflows
│ └── deploy.yml
├── .gitignore
├── .husky
├── .gitignore
└── pre-commit
├── CHANGELOG.md
├── CODE_OF_CONDUCT.md
├── CONTRIBUTING.md
├── LICENSE.md
├── README.md
├── deploy.js
├── documentation
└── asset
│ ├── browserstack.png
│ ├── jetbrains.png
│ ├── logo-color-text.png
│ ├── logo-color-text.svg
│ ├── logo-color.png
│ └── logo-color.svg
├── file-content-injector.js
├── package-lock.json
├── package.json
├── polyfill-lib
├── @webcomponents
│ └── shadycss-experimental
│ │ ├── CHANGELOG.md
│ │ ├── LICENSE.md
│ │ ├── README.md
│ │ ├── apply-shim.html
│ │ ├── apply-shim.min.js
│ │ ├── custom-style-interface.html
│ │ ├── custom-style-interface.min.js
│ │ ├── entrypoints
│ │ ├── apply-shim.js
│ │ ├── custom-style-interface.js
│ │ └── scoping-shim.js
│ │ ├── externs
│ │ ├── shadycss-externs.js
│ │ └── shadycss.d.ts
│ │ ├── package.json
│ │ ├── scoping-shim.min.js
│ │ ├── src
│ │ ├── apply-shim-utils.js
│ │ ├── apply-shim.js
│ │ ├── calc-parse.js
│ │ ├── common-regex.js
│ │ ├── common-utils.js
│ │ ├── css-parse.js
│ │ ├── custom-style-interface.js
│ │ ├── document-wait.js
│ │ ├── document-watcher.js
│ │ ├── env.d.ts
│ │ ├── interface.d.ts
│ │ ├── interface.js
│ │ ├── scoping-shim.js
│ │ ├── style-cache.js
│ │ ├── style-info.js
│ │ ├── style-placeholder.js
│ │ ├── style-properties.js
│ │ ├── style-settings.js
│ │ ├── style-transformer.js
│ │ ├── style-util.js
│ │ ├── template-map.js
│ │ └── unscoped-style-handler.js
│ │ └── ts_src
│ │ └── interface.ts
├── broadcast-channel
│ └── broadcast-channel.js
├── class-list
│ └── class-list.js
├── dom-token-list
│ └── dom-token-list.js
├── fetch
│ └── fetch.js
├── intl
│ └── intl.js
├── proto
│ └── proto.js
└── resize-observer
│ └── resize-observer.js
├── rollup.config.ts
├── sandhog.config.js
├── scripts
├── markdown-format-feature-names.ts
└── tsconfig.json
├── src
├── api
│ ├── controller
│ │ ├── polyfill-api-controller.ts
│ │ └── static-api-controller.ts
│ ├── decorator
│ │ └── api-method
│ │ │ ├── api-method-decorator.ts
│ │ │ ├── get.ts
│ │ │ └── options.ts
│ ├── lib
│ │ └── api-error.ts
│ ├── middleware
│ │ ├── error-middleware.ts
│ │ └── setup-controllers.ts
│ ├── server
│ │ ├── i-server.ts
│ │ └── server.ts
│ ├── util.ts
│ └── util
│ │ └── util.ts
├── bl
│ ├── polyfill
│ │ ├── i-polyfill-bl.ts
│ │ └── polyfill-bl.ts
│ └── static
│ │ ├── i-static-bl.ts
│ │ └── static-bl.ts
├── build
│ ├── build-options.ts
│ ├── build-result.ts
│ ├── build.ts
│ ├── options
│ │ ├── brotli-options.ts
│ │ └── zlib-options.ts
│ ├── plugin
│ │ └── babel
│ │ │ └── plugin-transform-inline-regenerator.ts
│ └── util
│ │ └── encoding.ts
├── common
│ ├── lib
│ │ └── file-system
│ │ │ ├── file-system.ts
│ │ │ └── real-file-system.ts
│ └── type
│ │ └── type-util.ts
├── config
│ └── config.ts
├── constant
│ ├── constant.ts
│ ├── i-constant.ts
│ └── regenerator-source.ts
├── encoding
│ └── content-encoding-kind.ts
├── environment
│ ├── environment-defaults.ts
│ └── environment.ts
├── index.ts
├── polyfill
│ ├── polyfill-context.ts
│ ├── polyfill-dict.ts
│ ├── polyfill-feature.ts
│ ├── polyfill-name.ts
│ ├── polyfill-option-key-value-divider.ts
│ ├── polyfill-option-value-separator.ts
│ ├── polyfill-raw-divider.ts
│ ├── polyfill-raw-force-name.ts
│ ├── polyfill-raw-separator.ts
│ ├── polyfill-request.ts
│ └── polyfill-response.ts
├── service
│ ├── api
│ │ ├── api-service.ts
│ │ └── i-api-service.ts
│ ├── logger
│ │ ├── i-logger-service.ts
│ │ └── logger-service.ts
│ ├── metrics
│ │ ├── i-metrics-service.ts
│ │ ├── noop-metrics-service.ts
│ │ └── sentry-service.ts
│ ├── polyfill-builder
│ │ ├── i-compressed-polyfill-set-result.ts
│ │ ├── i-polyfill-builder-service.ts
│ │ └── polyfill-builder-service.ts
│ └── registry
│ │ ├── cache-registry
│ │ ├── cache-registry-service.ts
│ │ └── i-cache-registry-service.ts
│ │ └── polyfill-registry
│ │ ├── i-memory-registry-service.ts
│ │ ├── i-registry-get-result.ts
│ │ └── memory-registry-service.ts
├── services.ts
└── util
│ ├── html
│ └── generate-html.ts
│ ├── polyfill
│ └── polyfill-util.ts
│ └── type
│ ├── ecma-version.ts
│ ├── element-of.ts
│ └── string-tuple.ts
├── test
└── api
│ ├── api.test.ts
│ ├── setup.ts
│ └── util.ts
├── tsconfig.build.json
└── tsconfig.json
/.eslintrc.json:
--------------------------------------------------------------------------------
1 | {
2 | "env": {
3 | "es2020": true,
4 | "shared-node-browser": true,
5 | "node": true
6 | },
7 | "extends": "./node_modules/@wessberg/ts-config/.eslintrc.json"
8 | }
9 |
--------------------------------------------------------------------------------
/.github/FUNDING.yml:
--------------------------------------------------------------------------------
1 | github: wessberg
2 | patreon: wessberg
3 |
--------------------------------------------------------------------------------
/.github/workflows/deploy.yml:
--------------------------------------------------------------------------------
1 | name: "Deploy"
2 |
3 | on:
4 | push:
5 | branches:
6 | - development
7 |
8 | release:
9 | types: ["published", "edited"]
10 |
11 | jobs:
12 | deploy:
13 | name: "Deploy"
14 | runs-on: ubuntu-latest
15 |
16 | steps:
17 | - name: Checkout code
18 | uses: actions/checkout@master
19 |
20 | - name: Setup Node.js
21 | uses: actions/setup-node@master
22 | with:
23 | node-version: 19
24 |
25 | - name: Cache node modules
26 | uses: actions/cache@master
27 | env:
28 | cache-name: cache-node-modules
29 | with:
30 | path: ~/.npm
31 | key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
32 | restore-keys: |
33 | ${{ runner.os }}-build-${{ env.cache-name }}-
34 | ${{ runner.os }}-build-
35 | ${{ runner.os }}-
36 |
37 | - name: Install
38 | run: npm ci
39 |
40 | - name: Inject
41 | run: node file-content-injector.js
42 |
43 | - name: Test
44 | if: ${{ github.event_name == 'release' }}
45 | run: npm test
46 |
47 | - name: Build
48 | run: NODE_ENV=production npm run build
49 |
50 | - name: Deploy
51 | run: node deploy.js
52 | env:
53 | PRODUCTION: ${{ github.event_name == 'release' }}
54 | INTERNAL_HOST_DEVELOPMENT: ${{ secrets.INTERNAL_HOST_DEVELOPMENT }}
55 | INTERNAL_HOST_PRODUCTION: ${{ secrets.INTERNAL_HOST_PRODUCTION }}
56 | INTERNAL_PORT_DEVELOPMENT: ${{ secrets.INTERNAL_PORT_DEVELOPMENT }}
57 | INTERNAL_PORT_PRODUCTION: ${{ secrets.INTERNAL_PORT_PRODUCTION }}
58 | DOMAIN_NAMES_DEVELOPMENT: ${{ secrets.DOMAIN_NAMES_DEVELOPMENT }}
59 | DOMAIN_NAMES_PRODUCTION: ${{ secrets.DOMAIN_NAMES_PRODUCTION }}
60 | SENTRY_DSN_DEVELOPMENT: ${{ secrets.SENTRY_DSN_DEVELOPMENT }}
61 | SENTRY_DSN_PRODUCTION: ${{ secrets.SENTRY_DSN_PRODUCTION }}
62 | DEPLOY_HOST: ${{ secrets.DEPLOY_HOST }}
63 | DEPLOY_USER_NAME: ${{ secrets.DEPLOY_USER_NAME }}
64 | DEPLOY_KEY: ${{ secrets.DEPLOY_KEY }}
65 | VOLUMES: ${{ secrets.VOLUMES }}
66 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .nyc_output
2 | foo/
3 | /unlock-challenge/
4 | .idea/
5 | .vscode
6 | dist/
7 | .yarn/
8 | src/dist
9 | typings
10 | typings_backup/
11 | typings_backup.*
12 | /node_modules/
13 | *.js.map
14 | src/**/*.js
15 | test/**/*.js
16 | npm-debug.log
17 | coverage
18 | /compiled/
19 | npm-debug*
20 | /.rpt2_cache
21 | /.idea/
22 | /.cache/
23 | /.vscode/
24 | *.log
25 | /logs/
26 | npm-debug.log*
27 | /lib-cov/
28 | /coverage/
29 | /.nyc_output/
30 | /.grunt/
31 | *.7z
32 | *.dmg
33 | *.gz
34 | *.iso
35 | *.jar
36 | *.rar
37 | *.tar
38 | *.zip
39 | .tgz
40 | .env
41 | .DS_Store
42 | .DS_Store?
43 | ._*
44 | .Spotlight-V100
45 | .Trashes
46 | ehthumbs.db
47 | Thumbs.db
48 | *.pem
49 | *.p12
50 | *.crt
51 | *.csr
52 | /dist/
53 | .esm-cache
54 | /temp/
55 | ssh_key
--------------------------------------------------------------------------------
/.husky/.gitignore:
--------------------------------------------------------------------------------
1 | _
2 |
--------------------------------------------------------------------------------
/.husky/pre-commit:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | . "$(dirname "$0")/_/husky.sh"
3 |
4 | pretty-quick --staged
5 |
--------------------------------------------------------------------------------
/CODE_OF_CONDUCT.md:
--------------------------------------------------------------------------------
1 | Contributor Covenant Code of Conduct
2 |
3 | Our Pledge
4 |
5 | In the interest of fostering an open and welcoming environment, we as
6 | contributors and maintainers pledge to making participation in our project and
7 | our community a harassment-free experience for everyone, regardless of age, body
8 | size, disability, ethnicity, gender identity and expression, level of experience,
9 | nationality, personal appearance, race, religion, or sexual identity and
10 | orientation.
11 |
12 | Our Standards
13 |
14 | Examples of behavior that contributes to creating a positive environment
15 | include:
16 |
17 | - Using welcoming and inclusive language
18 | - Being respectful of differing viewpoints and experiences
19 | - Gracefully accepting constructive criticism
20 | - Focusing on what is best for the community
21 | - Showing empathy towards other community members
22 |
23 | Examples of unacceptable behavior by participants include:
24 |
25 | - The use of sexualized language or imagery and unwelcome sexual attention or
26 | advances
27 | - Trolling, insulting/derogatory comments, and personal or political attacks
28 | - Public or private harassment
29 | - Publishing others' private information, such as a physical or electronic
30 | address, without explicit permission
31 | - Other conduct which could reasonably be considered inappropriate in a
32 | professional setting
33 |
34 | Our Responsibilities
35 |
36 | Project maintainers are responsible for clarifying the standards of acceptable
37 | behavior and are expected to take appropriate and fair corrective action in
38 | response to any instances of unacceptable behavior.
39 |
40 | Project maintainers have the right and responsibility to remove, edit, or
41 | reject comments, commits, code, wiki edits, issues, and other contributions
42 | that are not aligned to this Code of Conduct, or to ban temporarily or
43 | permanently any contributor for other behaviors that they deem inappropriate,
44 | threatening, offensive, or harmful.
45 |
46 | Scope
47 |
48 | This Code of Conduct applies both within project spaces and in public spaces
49 | when an individual is representing the project or its community. Examples of
50 | representing a project or community include using an official project e-mail
51 | address, posting via an official social media account, or acting as an appointed
52 | representative at an online or offline event. Representation of a project may be
53 | further defined and clarified by project maintainers.
54 |
55 | Enforcement
56 |
57 | Instances of abusive, harassing, or otherwise unacceptable behavior may be
58 | reported by contacting any of the code of conduct enforcers: [Frederik Wessberg](mailto:frederikwessberg@hotmail.com) ([@FredWessberg](https://twitter.com/FredWessberg)) ([Website](https://github.com/wessberg)).
59 | All complaints will be reviewed and investigated and will result in a response that
60 | is deemed necessary and appropriate to the circumstances. The project team is
61 | obligated to maintain confidentiality with regard to the reporter of an incident.
62 | Further details of specific enforcement policies may be posted separately.
63 |
64 | Project maintainers who do not follow or enforce the Code of Conduct in good
65 | faith may face temporary or permanent repercussions as determined by other
66 | members of the project's leadership.
67 |
68 | Attribution
69 |
70 | This Code of Conduct is adapted from the Contributor Covenant, version 1.4,
71 | available at http://contributor-covenant.org/version/1/4/
72 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | You are more than welcome to contribute to `@wessberg/polyfiller` in any way you please, including:
2 |
3 | - Updating documentation.
4 | - Fixing spelling and grammar
5 | - Adding tests
6 | - Fixing issues and suggesting new features
7 | - Blogging, tweeting, and creating tutorials about `@wessberg/polyfiller`
8 | - Reaching out to [@FredWessberg](https://twitter.com/FredWessberg) on Twitter
9 | - Submit an issue or a Pull Request
10 |
--------------------------------------------------------------------------------
/LICENSE.md:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright © 2023 [Frederik Wessberg](mailto:frederikwessberg@hotmail.com) ([@FredWessberg](https://twitter.com/FredWessberg)) ([Website](https://github.com/wessberg))
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE
22 |
--------------------------------------------------------------------------------
/documentation/asset/browserstack.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wessberg/Polyfiller/d002cd0ba7125795d63f21556d2dd8624d7332e9/documentation/asset/browserstack.png
--------------------------------------------------------------------------------
/documentation/asset/jetbrains.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wessberg/Polyfiller/d002cd0ba7125795d63f21556d2dd8624d7332e9/documentation/asset/jetbrains.png
--------------------------------------------------------------------------------
/documentation/asset/logo-color-text.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wessberg/Polyfiller/d002cd0ba7125795d63f21556d2dd8624d7332e9/documentation/asset/logo-color-text.png
--------------------------------------------------------------------------------
/documentation/asset/logo-color-text.svg:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/documentation/asset/logo-color.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wessberg/Polyfiller/d002cd0ba7125795d63f21556d2dd8624d7332e9/documentation/asset/logo-color.png
--------------------------------------------------------------------------------
/documentation/asset/logo-color.svg:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@wessberg/polyfiller",
3 | "version": "0.2.3",
4 | "description": "Never worry about polyfills again.",
5 | "files": [
6 | "dist/**/*.*",
7 | "polyfill-lib/**/*.*"
8 | ],
9 | "scripts": {
10 | "prepare": "node ./file-content-injector.js",
11 | "start": "node ./dist/esm/index.js",
12 | "generate:sandhog": "sandhog all --yes",
13 | "generate:changelog": "standard-changelog --first-release",
14 | "generate:all": "npm run generate:sandhog && npm run generate:changelog",
15 | "clean": "rimraf dist",
16 | "lint": "tsc --noEmit && eslint \"src/**/*.ts\" --color",
17 | "lint:fix": "tsc --noEmit && eslint \"src/**/*.ts\" --color --fix",
18 | "prettier": "prettier --write \"{src,test,documentation}/**/*.{js,ts,json,html,xml,css,md}\"",
19 | "test": "ava",
20 | "prebuild": "npm run clean",
21 | "build": "npm run rollup",
22 | "watch": "npm run rollup -- --watch",
23 | "rollup": "rollup -c rollup.config.ts --configPlugin rollup-plugin-ts",
24 | "scripts:markdown-format-feature-names": "ts-node-esm --project scripts/tsconfig.json scripts/markdown-format-feature-names.ts",
25 | "preversion": "npm run build",
26 | "version": "npm run generate:all && git add .",
27 | "release": "np --no-cleanup --no-yarn --no-tests",
28 | "update:check": "npx npm-check-updates -x np --dep dev,prod",
29 | "update:commit": "npx npm-check-updates -u -x np,find-up --dep dev,prod && npm update && npm install"
30 | },
31 | "keywords": [
32 | "polyfills",
33 | "shim",
34 | "web",
35 | "webservice",
36 | "typescript",
37 | "polyfill-app",
38 | "polyfills-as-a-service"
39 | ],
40 | "devDependencies": {
41 | "@types/babel__core": "7.20.0",
42 | "@types/express": "4.17.13",
43 | "@types/mime": "2.0.3",
44 | "@types/morgan": "1.9.3",
45 | "@types/node": "18.11.18",
46 | "@types/semver": "7.3.13",
47 | "@typescript-eslint/eslint-plugin": "5.48.2",
48 | "@typescript-eslint/parser": "5.48.2",
49 | "@wessberg/di-compiler": "3.2.0",
50 | "@rollup/plugin-json": "6.0.0",
51 | "@wessberg/ts-config": "3.1.0",
52 | "@wessberg/prettier-config": "1.0.0",
53 | "ava": "5.1.1",
54 | "eslint": "8.32.0",
55 | "eslint-config-prettier": "8.6.0",
56 | "eslint-plugin-import": "2.27.5",
57 | "eslint-plugin-jsdoc": "39.6.7",
58 | "husky": "7.0.2",
59 | "node-ssh": "12.0.0",
60 | "np": "7.6.3",
61 | "prettier": "2.8.3",
62 | "pretty-quick": "3.1.3",
63 | "rimraf": "4.1.1",
64 | "rollup": "3.10.1",
65 | "rollup-plugin-ts": "3.2.0",
66 | "sandhog": "2.0.2",
67 | "standard-changelog": "2.0.27",
68 | "ts-node": "10.9.1",
69 | "typescript": "4.9.4",
70 | "useragent-generator": "^1.1.1-amkt-22079-finish.0"
71 | },
72 | "dependencies": {
73 | "@babel/core": "7.20.12",
74 | "@babel/preset-env": "7.20.2",
75 | "@babel/template": "7.20.7",
76 | "@formatjs/intl-datetimeformat": "5.0.2",
77 | "@formatjs/intl-displaynames": "5.4.3",
78 | "@formatjs/intl-getcanonicallocales": "1.9.2",
79 | "@formatjs/intl-listformat": "6.5.3",
80 | "@formatjs/intl-locale": "2.4.47",
81 | "@formatjs/intl-numberformat": "7.4.3",
82 | "@formatjs/intl-pluralrules": "4.3.3",
83 | "@formatjs/intl-relativetimeformat": "10.0.1",
84 | "@polyfiller/form-data": "0.0.40",
85 | "@polyfiller/object-fit": "0.0.39",
86 | "@sentry/node": "6.13.2",
87 | "@sentry/tracing": "6.13.2",
88 | "@swc/core": "1.3.27",
89 | "@webcomponents/custom-elements": "1.5.0",
90 | "@webcomponents/shadycss": "1.11.0",
91 | "@webcomponents/shadydom": "1.9.0",
92 | "@webcomponents/template": "1.5.0",
93 | "@wessberg/di": "2.1.0",
94 | "@wessberg/pointer-events": "1.0.9",
95 | "@wessberg/stringutil": "1.0.19",
96 | "lit": "2.6.1",
97 | "blob-polyfill": "5.0.20210201",
98 | "browserslist": "4.21.5",
99 | "browserslist-generator": "2.0.3",
100 | "chalk": "5.2.0",
101 | "console-polyfill": "0.3.0",
102 | "construct-style-sheets-polyfill": "3.0.1",
103 | "core-js": "3.27.2",
104 | "crosspath": "2.0.0",
105 | "esbuild": "0.17.4",
106 | "events-polyfill": "2.1.2",
107 | "express": "4.17.1",
108 | "find-up": "6.3.0",
109 | "focus-visible": "5.2.0",
110 | "http-status-codes": "2.1.4",
111 | "intersection-observer": "0.12.0",
112 | "mime": "2.5.2",
113 | "morgan": "1.10.0",
114 | "mutationobserver-shim": "0.3.7",
115 | "node.parentelement": "1.0.2",
116 | "perfnow": "0.2.0",
117 | "performance-now": "2.1.0",
118 | "pm2": "5.2.2",
119 | "polyfill-library": "3.108.0",
120 | "proxy-polyfill": "0.3.2",
121 | "regenerator-runtime": "0.13.11",
122 | "requestanimationframe": "0.0.23",
123 | "requestidlecallback": "0.3.0",
124 | "scroll-behavior-polyfill": "2.0.13",
125 | "semver": "7.3.8",
126 | "setimmediate": "1.0.5",
127 | "systemjs": "6.13.0",
128 | "temp-dir": "3.0.0",
129 | "toposort": "2.0.2",
130 | "tslib": "2.4.1",
131 | "url-polyfill": "1.1.12",
132 | "web-animations-js": "2.3.2",
133 | "xhr-polyfill": "0.1.8",
134 | "zone.js": "0.11.4"
135 | },
136 | "funding": {
137 | "type": "github",
138 | "url": "https://github.com/wessberg/polyfiller?sponsor=1"
139 | },
140 | "repository": {
141 | "type": "git",
142 | "url": "https://github.com/wessberg/polyfiller.git"
143 | },
144 | "bugs": {
145 | "url": "https://github.com/wessberg/polyfiller/issues"
146 | },
147 | "contributors": [
148 | {
149 | "name": "Frederik Wessberg",
150 | "email": "frederikwessberg@hotmail.com",
151 | "url": "https://github.com/wessberg",
152 | "imageUrl": "https://avatars2.githubusercontent.com/u/20454213?s=460&v=4",
153 | "github": "wessberg",
154 | "role": "Lead Developer",
155 | "twitter": "FredWessberg"
156 | }
157 | ],
158 | "license": "MIT",
159 | "exports": {
160 | "import": "./dist/esm/index.js",
161 | "require": "./dist/cjs/index.cjs",
162 | "types": "./dist/esm/index.d.ts"
163 | },
164 | "type": "module",
165 | "types": "./dist/esm/index.d.ts",
166 | "main": "./dist/cjs/index.cjs",
167 | "module": "./dist/esm/index.js",
168 | "engines": {
169 | "node": ">=16.15.1",
170 | "npm": ">=7.0.0",
171 | "yarn": ">=1.13",
172 | "pnpm": ">=3.2.0"
173 | },
174 | "prettier": "@wessberg/prettier-config",
175 | "ava": {
176 | "files": [
177 | "test/**/*.test.ts"
178 | ],
179 | "verbose": true,
180 | "timeout": "300s",
181 | "extensions": {
182 | "ts": "module"
183 | },
184 | "nodeArguments": [
185 | "--loader=@wessberg/di-compiler/loader",
186 | "--loader=ts-node/esm"
187 | ],
188 | "environmentVariables": {
189 | "FORCE_COLOR": "3",
190 | "NODE_OPTIONS": "--max_old_space_size=4096",
191 | "TESTING": "true",
192 | "CLEAR_CACHE": "true"
193 | }
194 | }
195 | }
196 |
--------------------------------------------------------------------------------
/polyfill-lib/@webcomponents/shadycss-experimental/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | # Changelog
2 |
3 | All notable changes to this project will be documented in this file.
4 |
5 | The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6 | and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7 |
8 |
9 |
10 | ## [1.11.0] - 2021-08.02
11 |
12 | - Add TS externs. ([#457](https://github.com/webcomponents/polyfills/pull/457))
13 |
14 | ## [1.10.2] - 2020-10-21
15 |
16 | - Maintenance release (no user-facing changes)
17 |
18 | ## [1.10.1] - 2020-07-20
19 |
20 | - Maintenance release (no user-facing changes)
21 |
22 | ## [1.10.0] - 2020-06-03
23 |
24 | - Add `@webcomponents/shadycss` module, an interface to ShadyCSS polyfills that
25 | is importable, type-safe, and easier to use than the `window.ShadyCSS`
26 | globals.
27 |
28 | ## [1.9.6] - 2020-03-16
29 |
30 | - Closure type annotation improvements ([#284](https://github.com/webcomponents/polyfills/pull/284), [#280](https://github.com/webcomponents/polyfills/pull/280))
31 |
32 | ## [1.9.5] - 2020-02-26
33 |
34 | - Maintenance release (no user-facing changes)
35 |
36 | ## [1.9.4] - 2020-01-08
37 |
38 | - Fix Edge bug where cloned style would not apply correctly
39 | ([#242](https://github.com/webcomponents/polyfills/pull/242))
40 |
41 | ## [1.9.3] - 2019-11-12
42 |
43 | - When the apply shim is loaded, update custom-styles even if none are currently
44 | enqueued ([#208](https://github.com/webcomponents/polyfills/pull/208))
45 |
--------------------------------------------------------------------------------
/polyfill-lib/@webcomponents/shadycss-experimental/LICENSE.md:
--------------------------------------------------------------------------------
1 | # License
2 |
3 | Everything in this repo is BSD style license unless otherwise specified.
4 |
5 | Copyright (c) 2015 The Polymer Authors. All rights reserved.
6 |
7 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
8 |
9 | * Redistributions of source code must retain the above copyright
10 | notice, this list of conditions and the following disclaimer.
11 | * Redistributions in binary form must reproduce the above
12 | copyright notice, this list of conditions and the following disclaimer
13 | in the documentation and/or other materials provided with the
14 | distribution.
15 | * Neither the name of Google Inc. nor the names of its
16 | contributors may be used to endorse or promote products derived from
17 | this software without specific prior written permission.
18 |
19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
--------------------------------------------------------------------------------
/polyfill-lib/@webcomponents/shadycss-experimental/apply-shim.html:
--------------------------------------------------------------------------------
1 |
10 |
11 |
--------------------------------------------------------------------------------
/polyfill-lib/@webcomponents/shadycss-experimental/apply-shim.min.js:
--------------------------------------------------------------------------------
1 | (function(){/*
2 |
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 | 'use strict';var k=!(window.ShadyDOM&&window.ShadyDOM.inUse),p;function r(a){p=a&&a.shimcssproperties?!1:k||!(navigator.userAgent.match(/AppleWebKit\/601|Edge\/15/)||!window.CSS||!CSS.supports||!CSS.supports("box-shadow","0 0 0 var(--foo)"))}var t;window.ShadyCSS&&void 0!==window.ShadyCSS.cssBuild&&(t=window.ShadyCSS.cssBuild);var aa=!(!window.ShadyCSS||!window.ShadyCSS.disableRuntime);
11 | window.ShadyCSS&&void 0!==window.ShadyCSS.nativeCss?p=window.ShadyCSS.nativeCss:window.ShadyCSS?(r(window.ShadyCSS),window.ShadyCSS=void 0):r(window.WebComponents&&window.WebComponents.flags);var u=p;function v(){this.end=this.start=0;this.rules=this.parent=this.previous=null;this.cssText=this.parsedCssText="";this.atRule=!1;this.type=0;this.parsedSelector=this.selector=this.keyframesName=""}
12 | function w(a){var b=a=a.replace(ba,"").replace(ca,""),c=new v;c.start=0;c.end=b.length;for(var d=c,e=0,f=b.length;e *")};function na(a,b,c){b=b.replace(E,function(d,e,f,g){return oa(a,d,e,f,g,c)});return S(a,b,c)}function pa(a,b){for(var c=b;c.parent;)c=c.parent;var d={},e=!1;L(c,function(f){(e=e||f===b)||f.selector===b.selector&&Object.assign(d,T(a,f.parsedCssText))});return d}
22 | function S(a,b,c){for(var d;d=H.exec(b);){var e=d[0],f=d[1];d=d.index;var g=b.slice(0,d+e.indexOf("@apply"));b=b.slice(d+e.length);var h=c?pa(a,c):{};Object.assign(h,T(a,g));e=void 0;var l=a;f=f.replace(la,"");var n=[];var m=l.g.get(f);m||(l.g.set(f,{}),m=l.g.get(f));if(m){l.i&&(m.o[l.i]=!0);var q=m.m;for(e in q)l=h&&h[e],m=[e,": var(",f,"_-_",e],l&&m.push(",",l.replace(O,"")),m.push(")"),O.test(q[e])&&m.push(" !important"),n.push(m.join(""))}e=n.join("; ");b=g+e+b;H.lastIndex=d+e.length}return b}
23 | function T(a,b,c){c=void 0===c?!1:c;b=b.split(";");for(var d,e,f={},g=0,h;g
10 |
11 |
--------------------------------------------------------------------------------
/polyfill-lib/@webcomponents/shadycss-experimental/custom-style-interface.min.js:
--------------------------------------------------------------------------------
1 | (function(){/*
2 |
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 | 'use strict';var c=null,f=window.HTMLImports&&window.HTMLImports.whenReady||null,g;function h(a){requestAnimationFrame(function(){f?f(a):(c||(c=new Promise(function(b){g=b}),"complete"===document.readyState?g():document.addEventListener("readystatechange",function(){"complete"===document.readyState&&g()})),c.then(function(){a&&a()}))})};var k=null,l=null;function m(){this.customStyles=[];this.enqueued=!1;h(function(){window.ShadyCSS.flushCustomStyles&&window.ShadyCSS.flushCustomStyles()})}function n(a){!a.enqueued&&l&&(a.enqueued=!0,h(l))}m.prototype.i=function(a){a.__seenByShadyCSS||(a.__seenByShadyCSS=!0,this.customStyles.push(a),n(this))};m.prototype.h=function(a){if(a.__shadyCSSCachedStyle)return a.__shadyCSSCachedStyle;var b;a.getStyle?b=a.getStyle():b=a;return b};
11 | m.prototype.g=function(){for(var a=this.customStyles,b=0;b {
41 | applyShim.transformCustomStyle(style);
42 | };
43 | this.customStyleInterface['validateCallback'] = () => {
44 | requestAnimationFrame(() => {
45 | if (this.customStyleInterface['enqueued']) {
46 | this.flushCustomStyles();
47 | }
48 | });
49 | };
50 | }
51 | }
52 | /**
53 | * @param {!HTMLTemplateElement} template
54 | * @param {string} elementName
55 | */
56 | prepareTemplate(template, elementName) {
57 | this.ensure();
58 | if (elementHasBuiltCss(template)) {
59 | return;
60 | }
61 | templateMap[elementName] = template;
62 | let ast = applyShim.transformTemplate(template, elementName);
63 | // save original style ast to use for revalidating instances
64 | template['_styleAst'] = ast;
65 | }
66 | flushCustomStyles() {
67 | this.ensure();
68 | if (!this.customStyleInterface) {
69 | return;
70 | }
71 | let styles = this.customStyleInterface['processStyles']();
72 | if (!this.customStyleInterface['enqueued']) {
73 | return;
74 | }
75 | for (let i = 0; i < styles.length; i++) {
76 | let cs = styles[i];
77 | let style = this.customStyleInterface['getStyleForCustomStyle'](cs);
78 | if (style) {
79 | applyShim.transformCustomStyle(style);
80 | }
81 | }
82 | this.customStyleInterface['enqueued'] = false;
83 | }
84 | /**
85 | * @param {HTMLElement} element
86 | * @param {Object=} properties
87 | */
88 | styleSubtree(element, properties) {
89 | this.ensure();
90 | if (properties) {
91 | updateNativeProperties(element, properties);
92 | }
93 | if (element.shadowRoot) {
94 | this.styleElement(element);
95 | let shadowChildren =
96 | /** @type {!ParentNode} */ (element.shadowRoot).children ||
97 | element.shadowRoot.childNodes;
98 | for (let i = 0; i < shadowChildren.length; i++) {
99 | this.styleSubtree(/** @type {HTMLElement} */ (shadowChildren[i]));
100 | }
101 | } else {
102 | let children = element.children || element.childNodes;
103 | for (let i = 0; i < children.length; i++) {
104 | this.styleSubtree(/** @type {HTMLElement} */ (children[i]));
105 | }
106 | }
107 | }
108 | /**
109 | * @param {HTMLElement} element
110 | */
111 | styleElement(element) {
112 | this.ensure();
113 | let {is} = getIsExtends(element);
114 | let template = templateMap[is];
115 | if (template && elementHasBuiltCss(template)) {
116 | return;
117 | }
118 | if (template && !ApplyShimUtils.templateIsValid(template)) {
119 | // only revalidate template once
120 | if (!ApplyShimUtils.templateIsValidating(template)) {
121 | this.prepareTemplate(template, is);
122 | ApplyShimUtils.startValidatingTemplate(template);
123 | }
124 | // update this element instance
125 | let root = element.shadowRoot;
126 | if (root) {
127 | let style = /** @type {HTMLStyleElement} */ (root.querySelector(
128 | 'style'
129 | ));
130 | if (style) {
131 | // reuse the template's style ast, it has all the original css text
132 | style['__cssRules'] = template['_styleAst'];
133 | style.textContent = toCssText(template['_styleAst']);
134 | }
135 | }
136 | }
137 | }
138 | /**
139 | * @param {Object=} properties
140 | */
141 | styleDocument(properties) {
142 | this.ensure();
143 | this.styleSubtree(document.body, properties);
144 | }
145 | }
146 |
147 | if (!window.ShadyCSS || !window.ShadyCSS.ScopingShim) {
148 | const applyShimInterface = new ApplyShimInterface();
149 | let CustomStyleInterface =
150 | window.ShadyCSS && window.ShadyCSS.CustomStyleInterface;
151 |
152 | /** @suppress {duplicate} */
153 | window.ShadyCSS = {
154 | /**
155 | * @param {!HTMLTemplateElement} template
156 | * @param {string} elementName
157 | * @param {string=} elementExtends
158 | */
159 | // eslint-disable-next-line @typescript-eslint/no-unused-vars
160 | prepareTemplate(template, elementName, elementExtends) {
161 | applyShimInterface.flushCustomStyles();
162 | applyShimInterface.prepareTemplate(template, elementName);
163 | },
164 |
165 | /**
166 | * @param {!HTMLTemplateElement} template
167 | * @param {string} elementName
168 | * @param {string=} elementExtends
169 | */
170 | prepareTemplateStyles(template, elementName, elementExtends) {
171 | window.ShadyCSS.prepareTemplate(template, elementName, elementExtends);
172 | },
173 |
174 | /**
175 | * @param {!HTMLTemplateElement} template
176 | * @param {string} elementName
177 | */
178 | prepareTemplateDom(template, elementName) {}, // eslint-disable-line @typescript-eslint/no-unused-vars
179 |
180 | /**
181 | * @param {!HTMLElement} element
182 | * @param {Object=} properties
183 | */
184 | styleSubtree(element, properties) {
185 | applyShimInterface.flushCustomStyles();
186 | applyShimInterface.styleSubtree(element, properties);
187 | },
188 |
189 | /**
190 | * @param {!HTMLElement} element
191 | */
192 | styleElement(element) {
193 | applyShimInterface.flushCustomStyles();
194 | applyShimInterface.styleElement(element);
195 | },
196 |
197 | /**
198 | * @param {Object=} properties
199 | */
200 | styleDocument(properties) {
201 | applyShimInterface.flushCustomStyles();
202 | applyShimInterface.styleDocument(properties);
203 | },
204 |
205 | /**
206 | * @param {Element} element
207 | * @param {string} property
208 | * @return {string}
209 | */
210 | getComputedStyleValue(element, property) {
211 | return getComputedStyleValue(element, property);
212 | },
213 |
214 | flushCustomStyles() {
215 | applyShimInterface.flushCustomStyles();
216 | },
217 |
218 | nativeCss: nativeCssVariables,
219 | nativeShadow: nativeShadow,
220 | cssBuild: cssBuild,
221 | disableRuntime: disableRuntime,
222 | };
223 |
224 | if (CustomStyleInterface) {
225 | window.ShadyCSS.CustomStyleInterface = CustomStyleInterface;
226 | }
227 | }
228 |
229 | window.ShadyCSS.ApplyShim = applyShim;
230 |
--------------------------------------------------------------------------------
/polyfill-lib/@webcomponents/shadycss-experimental/entrypoints/custom-style-interface.js:
--------------------------------------------------------------------------------
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 | 'use strict';
12 |
13 | import CustomStyleInterface from '../src/custom-style-interface.js';
14 | // prettier-ignore
15 | import {getComputedStyleValue, updateNativeProperties} from '../src/common-utils.js';
16 | // prettier-ignore
17 | import {nativeCssVariables, nativeShadow, cssBuild, disableRuntime} from '../src/style-settings.js';
18 |
19 | const customStyleInterface = new CustomStyleInterface();
20 |
21 | if (!window.ShadyCSS) {
22 | window.ShadyCSS = {
23 | /**
24 | * @param {!HTMLTemplateElement} template
25 | * @param {string} elementName
26 | * @param {string=} elementExtends
27 | */
28 | prepareTemplate(template, elementName, elementExtends) {}, // eslint-disable-line @typescript-eslint/no-unused-vars
29 |
30 | /**
31 | * @param {!HTMLTemplateElement} template
32 | * @param {string} elementName
33 | */
34 | prepareTemplateDom(template, elementName) {}, // eslint-disable-line @typescript-eslint/no-unused-vars
35 |
36 | /**
37 | * @param {!HTMLTemplateElement} template
38 | * @param {string} elementName
39 | * @param {string=} elementExtends
40 | */
41 | prepareTemplateStyles(template, elementName, elementExtends) {}, // eslint-disable-line @typescript-eslint/no-unused-vars
42 |
43 | /**
44 | * @param {Element} element
45 | * @param {Object=} properties
46 | */
47 | styleSubtree(element, properties) {
48 | customStyleInterface.processStyles();
49 | updateNativeProperties(element, properties);
50 | },
51 |
52 | /**
53 | * @param {Element} element
54 | */
55 | // eslint-disable-next-line @typescript-eslint/no-unused-vars
56 | styleElement(element) {
57 | customStyleInterface.processStyles();
58 | },
59 |
60 | /**
61 | * @param {Object=} properties
62 | */
63 | styleDocument(properties) {
64 | customStyleInterface.processStyles();
65 | updateNativeProperties(document.body, properties);
66 | },
67 |
68 | /**
69 | * @param {Element} element
70 | * @param {string} property
71 | * @return {string}
72 | */
73 | getComputedStyleValue(element, property) {
74 | return getComputedStyleValue(element, property);
75 | },
76 |
77 | flushCustomStyles() {},
78 | nativeCss: nativeCssVariables,
79 | nativeShadow: nativeShadow,
80 | cssBuild: cssBuild,
81 | disableRuntime: disableRuntime,
82 | };
83 | }
84 |
85 | window.ShadyCSS.CustomStyleInterface = customStyleInterface;
86 |
--------------------------------------------------------------------------------
/polyfill-lib/@webcomponents/shadycss-experimental/entrypoints/scoping-shim.js:
--------------------------------------------------------------------------------
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 | 'use strict';
12 |
13 | import ScopingShim from '../src/scoping-shim.js';
14 | // prettier-ignore
15 | import {nativeCssVariables, nativeShadow, cssBuild, disableRuntime} from '../src/style-settings.js';
16 |
17 | /** @const {ScopingShim} */
18 | const scopingShim = new ScopingShim();
19 |
20 | let ApplyShim, CustomStyleInterface;
21 |
22 | if (window['ShadyCSS']) {
23 | ApplyShim = window['ShadyCSS']['ApplyShim'];
24 | CustomStyleInterface = window['ShadyCSS']['CustomStyleInterface'];
25 | }
26 |
27 | window.ShadyCSS = {
28 | ScopingShim: scopingShim,
29 | /**
30 | * @param {!HTMLTemplateElement} template
31 | * @param {string} elementName
32 | * @param {string=} elementExtends
33 | */
34 | prepareTemplate(template, elementName, elementExtends) {
35 | scopingShim.flushCustomStyles();
36 | scopingShim.prepareTemplate(template, elementName, elementExtends);
37 | },
38 |
39 | /**
40 | * @param {!HTMLTemplateElement} template
41 | * @param {string} elementName
42 | */
43 | prepareTemplateDom(template, elementName) {
44 | scopingShim.prepareTemplateDom(template, elementName);
45 | },
46 |
47 | /**
48 | * @param {!HTMLTemplateElement} template
49 | * @param {string} elementName
50 | * @param {string=} elementExtends
51 | */
52 | prepareTemplateStyles(template, elementName, elementExtends) {
53 | scopingShim.flushCustomStyles();
54 | scopingShim.prepareTemplateStyles(template, elementName, elementExtends);
55 | },
56 | /**
57 | * @param {!HTMLElement} element
58 | * @param {Object=} properties
59 | */
60 | styleSubtree(element, properties) {
61 | scopingShim.flushCustomStyles();
62 | scopingShim.styleSubtree(element, properties);
63 | },
64 |
65 | /**
66 | * @param {!HTMLElement} element
67 | */
68 | styleElement(element) {
69 | scopingShim.flushCustomStyles();
70 | scopingShim.styleElement(element);
71 | },
72 |
73 | /**
74 | * @param {Object=} properties
75 | */
76 | styleDocument(properties) {
77 | scopingShim.flushCustomStyles();
78 | scopingShim.styleDocument(properties);
79 | },
80 |
81 | flushCustomStyles() {
82 | scopingShim.flushCustomStyles();
83 | },
84 |
85 | /**
86 | * @param {Element} element
87 | * @param {string} property
88 | * @return {string}
89 | */
90 | getComputedStyleValue(element, property) {
91 | return scopingShim.getComputedStyleValue(element, property);
92 | },
93 |
94 | nativeCss: nativeCssVariables,
95 |
96 | nativeShadow: nativeShadow,
97 |
98 | cssBuild: cssBuild,
99 |
100 | disableRuntime: disableRuntime,
101 | };
102 |
103 | if (ApplyShim) {
104 | window.ShadyCSS.ApplyShim = ApplyShim;
105 | }
106 |
107 | if (CustomStyleInterface) {
108 | window.ShadyCSS.CustomStyleInterface = CustomStyleInterface;
109 | }
110 |
--------------------------------------------------------------------------------
/polyfill-lib/@webcomponents/shadycss-experimental/externs/shadycss-externs.js:
--------------------------------------------------------------------------------
1 | /** @externs */
2 |
3 | /** @typedef {{
4 | * styleElement: function(!HTMLElement),
5 | * styleSubtree: function(!HTMLElement, Object=),
6 | * prepareTemplate: function(!HTMLTemplateElement, string, string=),
7 | * prepareTemplateStyles: function(!HTMLTemplateElement, string, string=),
8 | * prepareTemplateDom: function(!HTMLTemplateElement, string),
9 | * styleDocument: function(Object=),
10 | * flushCustomStyles: function(),
11 | * getComputedStyleValue: function(!Element, string): string,
12 | * ScopingShim: (Object|undefined),
13 | * ApplyShim: (Object|undefined),
14 | * CustomStyleInterface: (Object|undefined),
15 | * nativeCss: boolean,
16 | * nativeShadow: boolean,
17 | * cssBuild: (string | undefined),
18 | * disableRuntime: boolean,
19 | * }}
20 | */
21 | let ShadyCSSInterface;
22 |
23 | /**
24 | * @typedef {{
25 | * shimcssproperties: (boolean | undefined),
26 | * shimshadow: (boolean | undefined),
27 | * cssBuild: (string | undefined),
28 | * disableRuntime: (boolean | undefined),
29 | * }}
30 | */
31 | let ShadyCSSOptions;
32 |
33 | /** @type {(ShadyCSSInterface | ShadyCSSOptions | undefined)} */
34 | window.ShadyCSS;
35 |
36 | /** @type {string|undefined} */
37 | Element.prototype.extends;
38 |
39 | /** @type {?Element|undefined} */
40 | Element.prototype._element;
41 |
42 | /** @type {string|undefined} */
43 | Element.prototype.__cssBuild;
44 |
45 | /** @type {boolean|undefined} */
46 | HTMLTemplateElement.prototype._validating;
47 |
48 | /** @type {boolean|undefined} */
49 | HTMLTemplateElement.prototype._prepared;
50 |
51 | /** @type {boolean|undefined} */
52 | HTMLTemplateElement.prototype._domPrepared;
53 |
54 | /** @type {?DocumentFragment|undefined} */
55 | HTMLTemplateElement.prototype._content;
56 |
57 | /** @type {?HTMLStyleElement|undefined} */
58 | HTMLTemplateElement.prototype._gatheredStyle;
59 |
60 | /** @type {?HTMLStyleElement|undefined} */
61 | HTMLTemplateElement.prototype._style;
62 |
63 | /**
64 | * @type {string | undefined}
65 | */
66 | DOMTokenList.prototype.value;
67 |
--------------------------------------------------------------------------------
/polyfill-lib/@webcomponents/shadycss-experimental/externs/shadycss.d.ts:
--------------------------------------------------------------------------------
1 | /**
2 | * @license
3 | * Copyright (c) 2021 The Polymer Project Authors. All rights reserved. This
4 | * code may only be used under the BSD style license found at
5 | * http://polymer.github.io/LICENSE.txt The complete set of authors may be found
6 | * at http://polymer.github.io/AUTHORS.txt The complete set of contributors may
7 | * be found at http://polymer.github.io/CONTRIBUTORS.txt Code distributed by
8 | * Google as part of the polymer project is also subject to an additional IP
9 | * rights grant found at http://polymer.github.io/PATENTS.txt
10 | */
11 |
12 | // When building externally, this file is always assumed to be a module, but by
13 | // default it isn't when building internally, so we need this export statement.
14 | export {};
15 |
16 | declare global {
17 | interface ShadyCSSInterface {
18 | styleElement(element: HTMLElement): void;
19 | styleSubtree(
20 | element: HTMLElement,
21 | properties?: {[name: string]: string}
22 | ): void;
23 | prepareTemplate(
24 | template: HTMLTemplateElement,
25 | elementName: string,
26 | elementExtends?: string
27 | ): void;
28 | prepareTemplateStyles(
29 | template: HTMLTemplateElement,
30 | elementName: string,
31 | elementExtends?: string
32 | ): void;
33 | prepareTemplateDom(
34 | template: HTMLTemplateElement,
35 | elementName: string
36 | ): void;
37 | styleDocument(properties?: {[name: string]: string}): void;
38 | flushCustomStyles(): void;
39 | getComputedStyleValue(element: Element, property: string): string;
40 | ScopingShim?: {
41 | prepareAdoptedCssText(
42 | cssTextArray: Array,
43 | elementName: string
44 | ): void;
45 | flush(): void;
46 | };
47 | ApplyShim?: Object;
48 | CustomStyleInterface?: Object;
49 | nativeCss: boolean;
50 | nativeShadow: boolean;
51 | cssBuild?: string;
52 | disableRuntime: boolean;
53 | }
54 |
55 | interface ShadyCSSOptions {
56 | shimcssproperties?: boolean;
57 | shimshadow?: boolean;
58 | cssBuild?: boolean;
59 | disableRuntime?: boolean;
60 | }
61 |
62 | // This type alias exists because Tsickle will replace any type name used in the
63 | // type of something with the same name with `?`. (Maybe a Closure limitation?)
64 | // Making `ShadyCSS` an alias to an underlying type with a different name works
65 | // around this because Tsickle appears to resolve type aliases in its output: it
66 | // writes `undefined|ShadyCSSInterface` instead of `undefined|?` as the type for
67 | // the `ShadyCSS` global.
68 | type ShadyCSS = ShadyCSSInterface;
69 | // eslint-disable-next-line no-var
70 | var ShadyCSS: ShadyCSS | undefined;
71 | }
72 |
--------------------------------------------------------------------------------
/polyfill-lib/@webcomponents/shadycss-experimental/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@webcomponents/shadycss",
3 | "version": "1.11.0",
4 | "publishConfig": {
5 | "access": "public"
6 | },
7 | "description": "Polyfill for Scoped CSS",
8 | "license": "BSD-3-Clause",
9 | "repository": {
10 | "type": "git",
11 | "url": "https://github.com/webcomponents/polyfills.git",
12 | "directory": "packages/shadycss"
13 | },
14 | "author": "The Polymer Project Authors (https://polymer.github.io/AUTHORS.txt)",
15 | "homepage": "https://github.com/webcomponents/polyfills/tree/master/packages/shadycss",
16 | "bugs": "https://github.com/webcomponents/polyfills/issues?q=is%3Aissue+is%3Aopen+label%3A\"Package%3A+shadycss\"",
17 | "main": "src/interface.js",
18 | "module": "src/interface.js",
19 | "scripts": {
20 | "build": "npm run build:interface && gulp",
21 | "build:interface": "npm run clean:interface && tsc",
22 | "build:watch": "chokidar --initial 'src/**/*.js' 'ts_src/**/*.ts' --ignore 'src/interface.js' -c 'npm run build'",
23 | "clean:interface": "rimraf 'src/interface.*' .tsbuildinfo",
24 | "debug": "gulp debug",
25 | "prepack": "npm run build"
26 | },
27 | "files": [
28 | "apply-shim.html",
29 | "apply-shim.min.js*",
30 | "CHANGELOG.md",
31 | "custom-style-interface.html",
32 | "custom-style-interface.min.js*",
33 | "entrypoints/**/*.js",
34 | "externs/**/*.d.ts",
35 | "externs/**/*.js",
36 | "scoping-shim.min.js*",
37 | "src/**/*.d.ts",
38 | "src/**/*.js",
39 | "src/**/*.js.map",
40 | "ts_src/**/*.ts"
41 | ],
42 | "keywords": [
43 | "shady-css",
44 | "shadycss",
45 | "shadow-css",
46 | "shadowcss",
47 | "web-components",
48 | "webcomponents",
49 | "polyfill",
50 | "shim"
51 | ],
52 | "devDependencies": {
53 | "@typescript-eslint/eslint-plugin": "^2.31.0",
54 | "@typescript-eslint/parser": "^2.31.0",
55 | "rimraf": "^3.0.2",
56 | "rollup-stream": "=1.23.1",
57 | "vinyl-buffer": "^1.0.1",
58 | "vinyl-source-stream": "^2.0.0"
59 | },
60 | "gitHead": "966c28a79fcd46dedc4367be6b93404565ab9cf6"
61 | }
62 |
--------------------------------------------------------------------------------
/polyfill-lib/@webcomponents/shadycss-experimental/src/apply-shim-utils.js:
--------------------------------------------------------------------------------
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 | 'use strict';
12 | import templateMap from './template-map.js';
13 | import {StyleNode} from './css-parse.js'; // eslint-disable-line @typescript-eslint/no-unused-vars
14 |
15 | /*
16 | * Utilities for handling invalidating apply-shim mixins for a given template.
17 | *
18 | * The invalidation strategy involves keeping track of the "current" version of a template's mixins, and updating that count when a mixin is invalidated.
19 | * The template
20 | */
21 |
22 | /** @const {string} */
23 | const CURRENT_VERSION = '_applyShimCurrentVersion';
24 |
25 | /** @const {string} */
26 | const NEXT_VERSION = '_applyShimNextVersion';
27 |
28 | /** @const {string} */
29 | const VALIDATING_VERSION = '_applyShimValidatingVersion';
30 |
31 | /**
32 | * @const {Promise}
33 | */
34 | const promise = Promise.resolve();
35 |
36 | /**
37 | * @param {string} elementName
38 | */
39 | export function invalidate(elementName) {
40 | let template = templateMap[elementName];
41 | if (template) {
42 | invalidateTemplate(template);
43 | }
44 | }
45 |
46 | /**
47 | * This function can be called multiple times to mark a template invalid
48 | * and signal that the style inside must be regenerated.
49 | *
50 | * Use `startValidatingTemplate` to begin an asynchronous validation cycle.
51 | * During that cycle, call `templateIsValidating` to see if the template must
52 | * be revalidated
53 | * @param {HTMLTemplateElement} template
54 | */
55 | export function invalidateTemplate(template) {
56 | // default the current version to 0
57 | template[CURRENT_VERSION] = template[CURRENT_VERSION] || 0;
58 | // ensure the "validating for" flag exists
59 | template[VALIDATING_VERSION] = template[VALIDATING_VERSION] || 0;
60 | // increment the next version
61 | template[NEXT_VERSION] = (template[NEXT_VERSION] || 0) + 1;
62 | }
63 |
64 | /**
65 | * @param {string} elementName
66 | * @return {boolean}
67 | */
68 | export function isValid(elementName) {
69 | let template = templateMap[elementName];
70 | if (template) {
71 | return templateIsValid(template);
72 | }
73 | return true;
74 | }
75 |
76 | /**
77 | * @param {HTMLTemplateElement} template
78 | * @return {boolean}
79 | */
80 | export function templateIsValid(template) {
81 | return template[CURRENT_VERSION] === template[NEXT_VERSION];
82 | }
83 |
84 | /**
85 | * @param {string} elementName
86 | * @return {boolean}
87 | */
88 | export function isValidating(elementName) {
89 | let template = templateMap[elementName];
90 | if (template) {
91 | return templateIsValidating(template);
92 | }
93 | return false;
94 | }
95 |
96 | /**
97 | * Returns true if the template is currently invalid and `startValidating` has been called since the last invalidation.
98 | * If false, the template must be validated.
99 | * @param {HTMLTemplateElement} template
100 | * @return {boolean}
101 | */
102 | export function templateIsValidating(template) {
103 | return (
104 | !templateIsValid(template) &&
105 | template[VALIDATING_VERSION] === template[NEXT_VERSION]
106 | );
107 | }
108 |
109 | /**
110 | * the template is marked as `validating` for one microtask so that all instances
111 | * found in the tree crawl of `applyStyle` will update themselves,
112 | * but the template will only be updated once.
113 | * @param {string} elementName
114 | */
115 | export function startValidating(elementName) {
116 | let template = templateMap[elementName];
117 | startValidatingTemplate(template);
118 | }
119 |
120 | /**
121 | * Begin an asynchronous invalidation cycle.
122 | * This should be called after every validation of a template
123 | *
124 | * After one microtask, the template will be marked as valid until the next call to `invalidateTemplate`
125 | * @param {HTMLTemplateElement} template
126 | */
127 | export function startValidatingTemplate(template) {
128 | // remember that the current "next version" is the reason for this validation cycle
129 | template[VALIDATING_VERSION] = template[NEXT_VERSION];
130 | // however, there only needs to be one async task to clear the counters
131 | if (!template._validating) {
132 | template._validating = true;
133 | promise.then(function () {
134 | // sync the current version to let future invalidations cause a refresh cycle
135 | template[CURRENT_VERSION] = template[NEXT_VERSION];
136 | template._validating = false;
137 | });
138 | }
139 | }
140 |
141 | /**
142 | * @return {boolean}
143 | */
144 | export function elementsAreInvalid() {
145 | for (let elementName in templateMap) {
146 | let template = templateMap[elementName];
147 | if (!templateIsValid(template)) {
148 | return true;
149 | }
150 | }
151 | return false;
152 | }
153 |
--------------------------------------------------------------------------------
/polyfill-lib/@webcomponents/shadycss-experimental/src/calc-parse.js:
--------------------------------------------------------------------------------
1 | /**
2 | @license
3 | Copyright (c) 2019 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 | 'use strict';
12 |
13 | /** @enum {string} */
14 | const CssExpressionKind = {
15 | CssCalcExpression: 'CssCalcExpression',
16 | CssOtherExpression: 'CssOtherExpression'
17 | };
18 |
19 | /** @typedef {{pos: number, end: number}} */
20 | let TextSpan; // eslint-disable-line no-unused-vars
21 |
22 | /** @typedef {{kind: CssExpressionKind, text: string, span: Text}} */
23 | let CssOtherExpression; // eslint-disable-line no-unused-vars
24 |
25 | /** @typedef {{kind: CssExpressionKind, text: string, span: Text, children: Array}} */
26 | let CssCalcExpression; // eslint-disable-line no-unused-vars
27 |
28 | /** @typedef {CssOtherExpression|CssCalcExpression} */
29 | let CssExpression; // eslint-disable-line no-unused-vars
30 |
31 | /**
32 | * A Regular Expression that matches the string 'calc('
33 | * @const
34 | * @type {RegExp}
35 | */
36 | const CALC_REGEXP = /calc\(/g;
37 |
38 | /**
39 | * Visits and stringifies the given CssCalcExpression
40 | * @param {CssCalcExpression} expression
41 | * @param {number} depth
42 | * @returns {string}
43 | */
44 | function visitCssCalcExpression (expression, depth) {
45 | return depth === 0
46 | ? `calc(${visitCssExpressions(expression.children, depth + 1)})`
47 | : `(${visitCssExpressions(expression.children, depth + 1)})`;
48 | }
49 |
50 | /**
51 | * Visits and stringifies the given CSSOtherExpression
52 | * @param {CssOtherExpression} expression
53 | * @returns {string}
54 | */
55 | function visitCssOtherExpression (expression) {
56 | return expression.text;
57 | }
58 |
59 | /**
60 | * Visits and stringifies the given CSSExpression
61 | * @param {CssExpression} expression
62 | * @param {number} depth
63 | * @returns {string}
64 | */
65 | function visitCssExpression (expression, depth) {
66 | switch (expression.kind) {
67 | case CssExpressionKind.CssCalcExpression:
68 | return visitCssCalcExpression( /** @type {CssCalcExpression} */ (expression), depth);
69 | case CssExpressionKind.CssOtherExpression:
70 | return visitCssOtherExpression(/** @type {CssOtherExpression} */ (expression));
71 | default:
72 | return '';
73 | }
74 | }
75 |
76 | /**
77 | * Visits the given CSSExpressions and stringifies them
78 | * @param {Array} expressions
79 | * @param {number} [depth=0]
80 | * @returns {string}
81 | */
82 | function visitCssExpressions (expressions, depth = 0) {
83 | return expressions.map(exp => visitCssExpression(exp, /** @type {number} */ (depth))).join('');
84 | }
85 |
86 | /**
87 | * A minimal parser that checks CSS declaration values for 'calc' expressions and generates a syntax tree
88 | * @param {string} input
89 | * @param {TextSpan} offset
90 | * @returns {Array}
91 | */
92 | function parseCalc (input, offset = {pos: 0, end: input.length}) {
93 | let cursor = offset.pos + -1;
94 | const syntax = [];
95 |
96 | const isEOF = () => cursor >= input.length || cursor >= offset.end;
97 | const nextToken = () => input[++cursor];
98 | const peek = positions => input[cursor + positions];
99 |
100 | /** @type {Array} */
101 | let readBuffer = [];
102 | let readingStartCursor = cursor;
103 | let reading = false;
104 | let ignore = false;
105 |
106 | const startReading = () => {
107 | readingStartCursor = cursor;
108 | reading = true;
109 | };
110 |
111 | const flushReadBuffer = () => {
112 | reading = false;
113 | if (readBuffer.length > 0) {
114 | syntax.push({
115 | kind: CssExpressionKind.CssOtherExpression,
116 | span: {
117 | pos: readingStartCursor,
118 | end: cursor
119 | },
120 | text: input.slice(readingStartCursor, cursor)
121 | });
122 | }
123 | readBuffer = [];
124 | readingStartCursor = cursor;
125 | };
126 |
127 | while (!isEOF()) {
128 | const next = nextToken();
129 |
130 | let peekIndex = 0;
131 |
132 | // Check if the next token leads to a 'calc' expression
133 | if (
134 | !ignore &&
135 | next === 'c' &&
136 | peek(++peekIndex) === 'a' &&
137 | peek(++peekIndex) === 'l' &&
138 | peek(++peekIndex) === 'c' &&
139 | peek(++peekIndex) === '('
140 | ) {
141 | flushReadBuffer();
142 |
143 | let leftParensCount = 0;
144 | while (peekIndex < input.length) {
145 | const nextPeek = peek(peekIndex++);
146 | if (nextPeek === '(') {
147 | leftParensCount++;
148 | } else if (nextPeek === ')') {
149 | leftParensCount--;
150 |
151 | if (leftParensCount === 0) {
152 | break;
153 | }
154 | }
155 | }
156 |
157 | const span = {
158 | pos: cursor,
159 | end: cursor + peekIndex
160 | };
161 |
162 | const innerSpan = {
163 | pos: span.pos + 'calc('.length,
164 | end: span.end - 1
165 | };
166 |
167 | syntax.push({
168 | kind: CssExpressionKind.CssCalcExpression,
169 | span,
170 | text: input.slice(span.pos, span.end),
171 | children: parseCalc(input, innerSpan)
172 | });
173 |
174 | cursor = span.end;
175 | readingStartCursor = span.end;
176 | reading = true;
177 | } else {
178 | // The next char may be the beginning of a comment
179 | if (
180 | next === '/' &&
181 | peek(1) === '*'
182 | ) {
183 | ignore = true;
184 | }
185 |
186 | // The next char may be the beginning of the end of a comment
187 | else if (
188 | next === '*' &&
189 | peek(1) === '/'
190 | ) {
191 | ignore = false;
192 | }
193 |
194 | // Read the input and add to the read buffer
195 | if (!reading) {
196 | startReading();
197 | }
198 |
199 | if (next != null) {
200 | readBuffer.push(next);
201 | }
202 | }
203 | }
204 |
205 | // Stop reading
206 | flushReadBuffer();
207 | return syntax;
208 | }
209 |
210 | /**
211 | * Reduces 'calc(...)'s inside the given expression which can cssText, a CSS declaration, or a ruleset
212 | * @param {string} expression
213 | * @return {string}
214 | */
215 | export function reduceCalc (expression) {
216 | // This heuristic takes a fast path if possible
217 | const calcMatch = expression.match(CALC_REGEXP);
218 |
219 | // If the expression doesn't include 'calc' or if it only includes one, there's nothing to reduce here.
220 | if (calcMatch == null || calcMatch.length < 2) {
221 | return expression;
222 | }
223 |
224 | // Otherwise, parse the expression into a syntax tree before reducing it
225 | const parseResults = parseCalc(expression);
226 | return visitCssExpressions(parseResults);
227 | }
--------------------------------------------------------------------------------
/polyfill-lib/@webcomponents/shadycss-experimental/src/common-regex.js:
--------------------------------------------------------------------------------
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 | export const VAR_ASSIGN = /(?:^|[;\s{]\s*)(--[\w-]*?)\s*:\s*(?:((?:'(?:\\'|.)*?'|"(?:\\"|.)*?"|\([^)]*?\)|[^};{])+)|\{([^}]*)\}(?:(?=[;\s}])|$))/gi;
12 | export const MIXIN_MATCH = /(?:^|\W+)@apply\s*\(?([^);\n]*)\)?/gi;
13 | export const VAR_CONSUMED = /(--[\w-]+)\s*([:,;)]|$)/gi;
14 | export const ANIMATION_MATCH = /(animation\s*:)|(animation-name\s*:)/;
15 | export const MEDIA_MATCH = /@media\s(.*)/;
16 | export const IS_VAR = /^--/;
17 | export const BRACKETED = /\{[^}]*\}/g;
18 | export const HOST_PREFIX = '(?:^|[^.#[:])';
19 | export const HOST_SUFFIX = '($|[.:[\\s>+~])';
20 |
--------------------------------------------------------------------------------
/polyfill-lib/@webcomponents/shadycss-experimental/src/common-utils.js:
--------------------------------------------------------------------------------
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 | 'use strict';
12 |
13 | import {MIXIN_MATCH, VAR_ASSIGN} from './common-regex.js';
14 |
15 | /**
16 | * @param {Element} element
17 | * @param {Object=} properties
18 | */
19 | export function updateNativeProperties(element, properties) {
20 | // remove previous properties
21 | for (let p in properties) {
22 | // NOTE: for bc with shim, don't apply null values.
23 | if (p === null) {
24 | element.style.removeProperty(p);
25 | } else {
26 | element.style.setProperty(p, properties[p]);
27 | }
28 | }
29 | }
30 |
31 | /**
32 | * @param {Element} element
33 | * @param {string} property
34 | * @return {string}
35 | */
36 | export function getComputedStyleValue(element, property) {
37 | /**
38 | * @const {string}
39 | */
40 | const value = window.getComputedStyle(element).getPropertyValue(property);
41 | if (!value) {
42 | return '';
43 | } else {
44 | return value.trim();
45 | }
46 | }
47 |
48 | /**
49 | * return true if `cssText` contains a mixin definition or consumption
50 | * @param {string} cssText
51 | * @return {boolean}
52 | */
53 | export function detectMixin(cssText) {
54 | const has = MIXIN_MATCH.test(cssText) || VAR_ASSIGN.test(cssText);
55 | // reset state of the regexes
56 | MIXIN_MATCH.lastIndex = 0;
57 | VAR_ASSIGN.lastIndex = 0;
58 | return has;
59 | }
60 |
--------------------------------------------------------------------------------
/polyfill-lib/@webcomponents/shadycss-experimental/src/css-parse.js:
--------------------------------------------------------------------------------
1 | import {reduceCalc} from './calc-parse.js';
2 | /**
3 | @license
4 | Copyright (c) 2017 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 | /*
13 | Extremely simple css parser. Intended to be not more than what we need
14 | and definitely not necessarily correct =).
15 | */
16 |
17 | 'use strict';
18 |
19 | /** @unrestricted */
20 | class StyleNode {
21 | constructor() {
22 | /** @type {number} */
23 | this['start'] = 0;
24 | /** @type {number} */
25 | this['end'] = 0;
26 | /** @type {StyleNode} */
27 | this['previous'] = null;
28 | /** @type {StyleNode} */
29 | this['parent'] = null;
30 | /** @type {Array} */
31 | this['rules'] = null;
32 | /** @type {string} */
33 | this['parsedCssText'] = '';
34 | /** @type {string} */
35 | this['cssText'] = '';
36 | /** @type {boolean} */
37 | this['atRule'] = false;
38 | /** @type {number} */
39 | this['type'] = 0;
40 | /** @type {string} */
41 | this['keyframesName'] = '';
42 | /** @type {string} */
43 | this['selector'] = '';
44 | /** @type {string} */
45 | this['parsedSelector'] = '';
46 | }
47 | }
48 |
49 | export {StyleNode};
50 |
51 | // given a string of css, return a simple rule tree
52 | /**
53 | * @param {string} text
54 | * @return {StyleNode}
55 | */
56 | export function parse(text) {
57 | text = clean(text);
58 | return parseCss(lex(text), text);
59 | }
60 |
61 | // remove stuff we don't care about that may hinder parsing
62 | /**
63 | * @param {string} cssText
64 | * @return {string}
65 | */
66 | function clean(cssText) {
67 | return cssText.replace(RX.comments, '').replace(RX.port, '');
68 | }
69 |
70 | // super simple {...} lexer that returns a node tree
71 | /**
72 | * @param {string} text
73 | * @return {!StyleNode}
74 | */
75 | function lex(text) {
76 | let root = new StyleNode();
77 | root['start'] = 0;
78 | root['end'] = text.length;
79 | let n = root;
80 | for (let i = 0, l = text.length; i < l; i++) {
81 | if (text[i] === OPEN_BRACE) {
82 | if (!n['rules']) {
83 | n['rules'] = [];
84 | }
85 | let p = n;
86 | let previous = p['rules'][p['rules'].length - 1] || null;
87 | n = new StyleNode();
88 | n['start'] = i + 1;
89 | n['parent'] = p;
90 | n['previous'] = previous;
91 | p['rules'].push(n);
92 | } else if (text[i] === CLOSE_BRACE) {
93 | n['end'] = i + 1;
94 | n = n['parent'] || root;
95 | }
96 | }
97 | return root;
98 | }
99 |
100 | // add selectors/cssText to node tree
101 | /**
102 | * @param {StyleNode} node
103 | * @param {string} text
104 | * @return {!StyleNode}
105 | */
106 | function parseCss(node, text) {
107 | let t = text.substring(node['start'], node['end'] - 1);
108 | node['parsedCssText'] = node['cssText'] = t.trim();
109 | if (node['parent']) {
110 | let ss = node['previous']
111 | ? node['previous']['end']
112 | : node['parent']['start'];
113 | t = text.substring(ss, node['start'] - 1);
114 | t = _expandUnicodeEscapes(t);
115 | t = t.replace(RX.multipleSpaces, ' ');
116 | // TODO(sorvell): ad hoc; make selector include only after last ;
117 | // helps with mixin syntax
118 | t = t.substring(t.lastIndexOf(';') + 1);
119 | let s = (node['parsedSelector'] = node['selector'] = t.trim());
120 | node['atRule'] = s.indexOf(AT_START) === 0;
121 | // note, support a subset of rule types...
122 | if (node['atRule']) {
123 | if (s.indexOf(MEDIA_START) === 0) {
124 | node['type'] = types.MEDIA_RULE;
125 | } else if (s.match(RX.keyframesRule)) {
126 | node['type'] = types.KEYFRAMES_RULE;
127 | node['keyframesName'] = node['selector'].split(RX.multipleSpaces).pop();
128 | }
129 | } else {
130 | if (s.indexOf(VAR_START) === 0) {
131 | node['type'] = types.MIXIN_RULE;
132 | } else {
133 | node['type'] = types.STYLE_RULE;
134 | }
135 | }
136 | }
137 | let r$ = node['rules'];
138 | if (r$) {
139 | for (let i = 0, l = r$.length, r; i < l && (r = r$[i]); i++) {
140 | parseCss(r, text);
141 | }
142 | }
143 | return node;
144 | }
145 |
146 | /**
147 | * conversion of sort unicode escapes with spaces like `\33 ` (and longer) into
148 | * expanded form that doesn't require trailing space `\000033`
149 | * @param {string} s
150 | * @return {string}
151 | */
152 | function _expandUnicodeEscapes(s) {
153 | return s.replace(/\\([0-9a-f]{1,6})\s/gi, function () {
154 | let code = arguments[1],
155 | repeat = 6 - code.length;
156 | while (repeat--) {
157 | code = '0' + code;
158 | }
159 | return '\\' + code;
160 | });
161 | }
162 |
163 | /**
164 | * stringify parsed css.
165 | * @param {StyleNode} node
166 | * @param {boolean=} preserveProperties
167 | * @param {string=} text
168 | * @return {string}
169 | */
170 | export function stringify(node, preserveProperties, text = '') {
171 | // calc rule cssText
172 | let cssText = '';
173 | if (node['cssText'] || node['rules']) {
174 | let r$ = node['rules'];
175 | if (r$ && !_hasMixinRules(r$)) {
176 | for (let i = 0, l = r$.length, r; i < l && (r = r$[i]); i++) {
177 | cssText = stringify(r, preserveProperties, cssText);
178 | }
179 | } else {
180 | cssText = preserveProperties
181 | ? node['cssText']
182 | : reduceCalc(removeCustomProps(node['cssText']));
183 | cssText = cssText.trim();
184 | if (cssText) {
185 | cssText = ' ' + cssText + '\n';
186 | }
187 | }
188 | }
189 | // emit rule if there is cssText
190 | if (cssText) {
191 | if (node['selector']) {
192 | text += node['selector'] + ' ' + OPEN_BRACE + '\n';
193 | }
194 | text += cssText;
195 | if (node['selector']) {
196 | text += CLOSE_BRACE + '\n\n';
197 | }
198 | }
199 | return text;
200 | }
201 |
202 | /**
203 | * @param {Array} rules
204 | * @return {boolean}
205 | */
206 | function _hasMixinRules(rules) {
207 | let r = rules[0];
208 | return (
209 | Boolean(r) &&
210 | Boolean(r['selector']) &&
211 | r['selector'].indexOf(VAR_START) === 0
212 | );
213 | }
214 |
215 | /**
216 | * @param {string} cssText
217 | * @return {string}
218 | */
219 | function removeCustomProps(cssText) {
220 | cssText = removeCustomPropAssignment(cssText);
221 | return removeCustomPropApply(cssText);
222 | }
223 |
224 | /**
225 | * @param {string} cssText
226 | * @return {string}
227 | */
228 | export function removeCustomPropAssignment(cssText) {
229 | return cssText.replace(RX.customProp, '').replace(RX.mixinProp, '');
230 | }
231 |
232 | /**
233 | * @param {string} cssText
234 | * @return {string}
235 | */
236 | function removeCustomPropApply(cssText) {
237 | return cssText.replace(RX.mixinApply, '').replace(RX.varApply, '');
238 | }
239 |
240 | /** @enum {number} */
241 | export const types = {
242 | STYLE_RULE: 1,
243 | KEYFRAMES_RULE: 7,
244 | MEDIA_RULE: 4,
245 | MIXIN_RULE: 1000,
246 | };
247 |
248 | const OPEN_BRACE = '{';
249 | const CLOSE_BRACE = '}';
250 |
251 | // helper regexp's
252 | const RX = {
253 | comments: /\/\*[^*]*\*+([^/*][^*]*\*+)*\//gim,
254 | port: /@import[^;]*;/gim,
255 | customProp: /(?:^[^;\-\s}]+)?--[^;{}]*?:[^{};]*?(?:[;\n]|$)/gim,
256 | mixinProp: /(?:^[^;\-\s}]+)?--[^;{}]*?:[^{};]*?{[^}]*?}(?:[;\n]|$)?/gim,
257 | mixinApply: /@apply\s*\(?[^);]*\)?\s*(?:[;\n]|$)?/gim,
258 | varApply: /[^;:]*?:[^;]*?var\([^;]*\)(?:[;\n]|$)?/gim,
259 | keyframesRule: /^@[^\s]*keyframes/,
260 | multipleSpaces: /\s+/g,
261 | };
262 |
263 | const VAR_START = '--';
264 | const MEDIA_START = '@media';
265 | const AT_START = '@';
266 |
--------------------------------------------------------------------------------
/polyfill-lib/@webcomponents/shadycss-experimental/src/custom-style-interface.js:
--------------------------------------------------------------------------------
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 | 'use strict';
12 |
13 | import documentWait from './document-wait.js';
14 |
15 | /**
16 | * @typedef {HTMLStyleElement | {getStyle: function():HTMLStyleElement}}
17 | */
18 | export let CustomStyleProvider;
19 |
20 | const SEEN_MARKER = '__seenByShadyCSS';
21 | const CACHED_STYLE = '__shadyCSSCachedStyle';
22 |
23 | /** @type {?function(!HTMLStyleElement)} */
24 | let transformFn = null;
25 |
26 | /** @type {?function()} */
27 | let validateFn = null;
28 |
29 | /**
30 | This interface is provided to add document-level
21 |
22 |
23 | ${message}
24 |
25 |