Compare commits

..

6 Commits

Author SHA1 Message Date
16a213f536 1.0.22 2020-05-27 22:28:52 +00:00
9869b0c6aa fix(core): update 2020-05-27 22:28:52 +00:00
e63cb9669b 1.0.21 2020-05-27 22:06:06 +00:00
06766c6895 fix(core): update 2020-05-27 22:06:05 +00:00
48f1b02f0b 1.0.20 2020-05-27 21:59:28 +00:00
f41550fa22 fix(core): update 2020-05-27 21:59:28 +00:00
5 changed files with 34 additions and 18 deletions

2
package-lock.json generated
View File

@ -1,6 +1,6 @@
{
"name": "@designestate/dees-domtools",
"version": "1.0.19",
"version": "1.0.22",
"lockfileVersion": 1,
"requires": true,
"dependencies": {

View File

@ -1,6 +1,6 @@
{
"name": "@designestate/dees-domtools",
"version": "1.0.19",
"version": "1.0.22",
"private": false,
"description": "tools to simplify complex css structures",
"main": "dist_ts/index.js",

View File

@ -8,21 +8,24 @@ export const phone = 340;
export type TViewport = 'native' | 'desktop' | 'tablet' | 'phablet' | 'phone';
export const getEnvironment = async (): Promise<TViewport> => {
const domToolsInstance = await DomTools.setupDomTools();
return domToolsInstance.domToolsStatePart.getState().virtualViewport;
if (globalThis.deesDomTools && globalThis.deesDomTools.domToolsStatePart.getState().virtualViewport) {
return globalThis.deesDomTools.domToolsStatePart.getState().virtualViewport;
} else {
return 'native';
}
};
export const cssForTablet = async contentArg => {
if ((await getEnvironment()) === 'native' || (await getEnvironment()) === 'desktop') {
export const cssForTablet = async (contentArg) => {
if (getEnvironment() === 'native' || getEnvironment() === 'desktop') {
return `
@media (max-width: ${tablet}px) {
${contentArg}
}
`;
} else if (
(await getEnvironment()) === 'tablet' ||
(await getEnvironment()) === 'phablet' ||
(await getEnvironment()) === 'phone'
getEnvironment() === 'tablet' ||
getEnvironment() === 'phablet' ||
getEnvironment() === 'phone'
) {
return `
@media (min-width: 0px) {
@ -32,14 +35,14 @@ export const cssForTablet = async contentArg => {
}
};
export const cssForPhablet = async contentArg => {
if ((await getEnvironment()) === 'native' || (await getEnvironment()) === 'desktop') {
export const cssForPhablet = async (contentArg) => {
if (getEnvironment() === 'native' || getEnvironment() === 'desktop') {
return `
@media (max-width: ${phablet}px) {
${contentArg}
}
`;
} else if ((await getEnvironment()) === 'phablet' || (await getEnvironment()) === 'phone') {
} else if (getEnvironment() === 'phablet' || getEnvironment() === 'phone') {
return `
@media (min-width: 0px) {
${contentArg}
@ -48,14 +51,14 @@ export const cssForPhablet = async contentArg => {
}
};
export const cssForPhone = async contentArg => {
if ((await getEnvironment()) === 'native' || (await getEnvironment()) === 'desktop') {
export const cssForPhone = async (contentArg) => {
if (getEnvironment() === 'native' || getEnvironment() === 'desktop') {
return `
@media (max-width: ${phone}px) {
${contentArg}
}
`;
} else if ((await getEnvironment()) === 'phone') {
} else if (getEnvironment() === 'phone') {
return `
@media (min-width: 0px) {
${contentArg}

View File

@ -31,7 +31,15 @@ export class DomTools {
}
public smartstate = new plugins.smartstate.Smartstate();
public domToolsStatePart = this.smartstate.getStatePart<IDomToolsState>('domtools');
public domToolsStatePart = this.smartstate.getStatePart<IDomToolsState>('domtools', {
virtualViewport: 'native'
});
public actionSetVirtualViewport = this.domToolsStatePart.createAction<TViewport>(async (statePart, payload) => {
const currentState = statePart.getState();
currentState.virtualViewport = payload;
return currentState;
});
public domToolsReady = plugins.smartpromise.defer();
public domReady = plugins.smartpromise.defer();
@ -46,7 +54,9 @@ export class DomTools {
bodyElement: null
};
constructor() {}
constructor() {
}
public async setGlobalStyles(stylesText: string) {
await this.domReady.promise;
@ -82,5 +92,7 @@ export class DomTools {
);
}
setVirtualViewport() {}
setVirtualViewport(environmentArg: TViewport) {
this.domToolsStatePart.dispatchAction(this.actionSetVirtualViewport, environmentArg);
}
}

View File

@ -5,3 +5,4 @@ import * as breakpoints from './domtools.breakpoints';
import * as css from './domtools.css';
export { css, breakpoints, elementBasic };
export { DomTools } from './domtools.classes.domtools';