@vonage/vvd-scheme
Advanced tools
Comparing version 0.6.0 to 0.7.0
@@ -1,9 +0,4 @@ | ||
# 0.6.0 (2020-09-08) | ||
# 0.7.0 (2020-09-15) | ||
### Features | ||
* **textarea:** textarea form association ([#300](https://github.com/vonage/vivid/issues/300)) ([19ebd4e](https://github.com/vonage/vivid/commit/19ebd4e5f694738d2687f2a9d2a24ef2fa9beb4b)) | ||
{ | ||
"name": "@vonage/vvd-scheme", | ||
"version": "0.6.0", | ||
"version": "0.7.0", | ||
"description": "> TODO: description", | ||
@@ -16,2 +16,3 @@ "author": "yinonov <yinon@hotmail.com>", | ||
"scripts": { | ||
"build": "yarn --cwd ../../ wca:json && node scripts/parseComponentsList.js", | ||
"test": "echo \"Error: run tests from root\" && exit 1" | ||
@@ -30,3 +31,3 @@ }, | ||
}, | ||
"gitHead": "d55fb00c43d48e3f8b0f3de170e4cb6949acbfd8" | ||
"gitHead": "7ea075c26f7d4224be96ce96efd8ad6d6f210cd3" | ||
} |
@@ -7,13 +7,13 @@ import { SchemeOption } from './vvd-scheme.js'; | ||
function tryCatchHandler( | ||
callback: (scheme: SchemeOption) => void, | ||
scheme: SchemeOption | ||
callback: (scheme: SchemeOption) => void, | ||
scheme: SchemeOption | ||
) { | ||
return tryCatch( | ||
() => { | ||
callback(scheme); | ||
}, | ||
(err) => { | ||
throw new Error(err); | ||
} | ||
); | ||
return tryCatch( | ||
() => { | ||
callback(scheme); | ||
}, | ||
(err) => { | ||
throw new Error(err); | ||
} | ||
); | ||
} | ||
@@ -23,23 +23,23 @@ | ||
const broadCastFn = (callback: (scheme: SchemeOption) => void) => | ||
(new BroadcastChannel(SCHEME_SELECT_EVENT_TYPE).onmessage = ({ | ||
data: scheme, | ||
}) => { | ||
tryCatchHandler(callback, scheme)(); | ||
}); | ||
(new BroadcastChannel(SCHEME_SELECT_EVENT_TYPE).onmessage = ({ | ||
data: scheme, | ||
}) => { | ||
tryCatchHandler(callback, scheme)(); | ||
}); | ||
// plain eventListener fallback | ||
const eventListenerFn = (callback: (scheme: SchemeOption) => void) => | ||
document.addEventListener( | ||
SCHEME_SELECT_EVENT_TYPE, | ||
(e) => { | ||
const { scheme } = (e as CustomEvent)?.detail; | ||
tryCatchHandler(callback, scheme)(); | ||
}, | ||
false | ||
); | ||
document.addEventListener( | ||
SCHEME_SELECT_EVENT_TYPE, | ||
(e) => { | ||
const { scheme } = (e as CustomEvent)?.detail; | ||
tryCatchHandler(callback, scheme)(); | ||
}, | ||
false | ||
); | ||
export function onSchemeChange(callback: (scheme: SchemeOption) => void): void { | ||
!globalThis.BroadcastChannel | ||
? broadCastFn(callback) | ||
: eventListenerFn(callback); | ||
!globalThis.BroadcastChannel | ||
? broadCastFn(callback) | ||
: eventListenerFn(callback); | ||
} |
import { CSSResult } from 'lit-element'; | ||
import { pipe } from 'ramda'; | ||
import { onSchemeChange } from './scheme-change-listener'; | ||
import { updateTagStyleCssText } from './vvd-scheme-style-tag-handler'; | ||
import { | ||
@@ -26,11 +28,2 @@ pcs, | ||
const style = mountStyle(); | ||
function mountStyle() { | ||
const style = document.createElement('style'); | ||
style.type = 'text/css'; | ||
document.head.appendChild(style); | ||
return style; | ||
} | ||
function schemeDefault(): SchemeOption { | ||
@@ -62,8 +55,4 @@ // if no scheme chosen try 'prefers-color-scheme' and if not supported just return 'light | ||
function updateStyleCssText(newCssText: CSSResult['cssText']) { | ||
style.innerHTML = newCssText || ''; | ||
} | ||
async function syncWithOSSettings() { | ||
updateStyleCssText( | ||
updateTagStyleCssText( | ||
await getSchemeCssText(getPreferedColorScheme() as SchemeOption) | ||
@@ -94,7 +83,7 @@ ); | ||
_selectedScheme = nextScheme; | ||
updateStyleCssText(await getSchemeCssText(nextScheme)); | ||
updateTagStyleCssText(await getSchemeCssText(nextScheme)); | ||
} | ||
export default Object.freeze({ | ||
set | ||
set, | ||
}); | ||
@@ -101,0 +90,0 @@ |
import { pipe } from 'ramda'; | ||
import { onSchemeChange } from './scheme-change-listener'; | ||
import { updateTagStyleCssText } from './vvd-scheme-style-tag-handler'; | ||
import { pcs, getPreferedColorScheme, prefersColorSchemeSupported, } from './os-sync.utils'; | ||
@@ -9,9 +10,2 @@ const getSchemeCssText = pipe(getSchemeModule, getStyleSheet, getCssText); | ||
export const getSelectedSchemeOption = () => _selectedSchemeOption; | ||
const style = mountStyle(); | ||
function mountStyle() { | ||
const style = document.createElement('style'); | ||
style.type = 'text/css'; | ||
document.head.appendChild(style); | ||
return style; | ||
} | ||
function schemeDefault() { | ||
@@ -37,7 +31,4 @@ // if no scheme chosen try 'prefers-color-scheme' and if not supported just return 'light | ||
} | ||
function updateStyleCssText(newCssText) { | ||
style.innerHTML = newCssText || ''; | ||
} | ||
async function syncWithOSSettings() { | ||
updateStyleCssText(await getSchemeCssText(getPreferedColorScheme())); | ||
updateTagStyleCssText(await getSchemeCssText(getPreferedColorScheme())); | ||
} | ||
@@ -64,6 +55,6 @@ function init() { | ||
_selectedScheme = nextScheme; | ||
updateStyleCssText(await getSchemeCssText(nextScheme)); | ||
updateTagStyleCssText(await getSchemeCssText(nextScheme)); | ||
} | ||
export default Object.freeze({ | ||
set | ||
set, | ||
}); | ||
@@ -70,0 +61,0 @@ init(); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
383572
36
310
0
1