Compare commits
10 Commits
Author | SHA1 | Date | |
---|---|---|---|
2756a3cb68 | |||
acf0ea3874 | |||
284d2be0e3 | |||
dfb9175613 | |||
16a213f536 | |||
9869b0c6aa | |||
e63cb9669b | |||
06766c6895 | |||
48f1b02f0b | |||
f41550fa22 |
2
package-lock.json
generated
2
package-lock.json
generated
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@designestate/dees-domtools",
|
"name": "@designestate/dees-domtools",
|
||||||
"version": "1.0.19",
|
"version": "1.0.24",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@designestate/dees-domtools",
|
"name": "@designestate/dees-domtools",
|
||||||
"version": "1.0.19",
|
"version": "1.0.24",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "tools to simplify complex css structures",
|
"description": "tools to simplify complex css structures",
|
||||||
"main": "dist_ts/index.js",
|
"main": "dist_ts/index.js",
|
||||||
|
@ -7,22 +7,25 @@ export const phone = 340;
|
|||||||
|
|
||||||
export type TViewport = 'native' | 'desktop' | 'tablet' | 'phablet' | 'phone';
|
export type TViewport = 'native' | 'desktop' | 'tablet' | 'phablet' | 'phone';
|
||||||
|
|
||||||
export const getEnvironment = async (): Promise<TViewport> => {
|
export const getEnvironment = (): TViewport => {
|
||||||
const domToolsInstance = await DomTools.setupDomTools();
|
if (globalThis.deesDomTools && globalThis.deesDomTools.domToolsStatePart.getState().virtualViewport) {
|
||||||
return domToolsInstance.domToolsStatePart.getState().virtualViewport;
|
return globalThis.deesDomTools.domToolsStatePart.getState().virtualViewport;
|
||||||
|
} else {
|
||||||
|
return 'native';
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const cssForTablet = async contentArg => {
|
export const cssForTablet = (contentArg) => {
|
||||||
if ((await getEnvironment()) === 'native' || (await getEnvironment()) === 'desktop') {
|
if (getEnvironment() === 'native' || getEnvironment() === 'desktop') {
|
||||||
return `
|
return `
|
||||||
@media (max-width: ${tablet}px) {
|
@media (max-width: ${tablet}px) {
|
||||||
${contentArg}
|
${contentArg}
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
} else if (
|
} else if (
|
||||||
(await getEnvironment()) === 'tablet' ||
|
getEnvironment() === 'tablet' ||
|
||||||
(await getEnvironment()) === 'phablet' ||
|
getEnvironment() === 'phablet' ||
|
||||||
(await getEnvironment()) === 'phone'
|
getEnvironment() === 'phone'
|
||||||
) {
|
) {
|
||||||
return `
|
return `
|
||||||
@media (min-width: 0px) {
|
@media (min-width: 0px) {
|
||||||
@ -32,14 +35,14 @@ export const cssForTablet = async contentArg => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const cssForPhablet = async contentArg => {
|
export const cssForPhablet = (contentArg) => {
|
||||||
if ((await getEnvironment()) === 'native' || (await getEnvironment()) === 'desktop') {
|
if (getEnvironment() === 'native' || getEnvironment() === 'desktop') {
|
||||||
return `
|
return `
|
||||||
@media (max-width: ${phablet}px) {
|
@media (max-width: ${phablet}px) {
|
||||||
${contentArg}
|
${contentArg}
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
} else if ((await getEnvironment()) === 'phablet' || (await getEnvironment()) === 'phone') {
|
} else if (getEnvironment() === 'phablet' || getEnvironment() === 'phone') {
|
||||||
return `
|
return `
|
||||||
@media (min-width: 0px) {
|
@media (min-width: 0px) {
|
||||||
${contentArg}
|
${contentArg}
|
||||||
@ -48,14 +51,14 @@ export const cssForPhablet = async contentArg => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const cssForPhone = async contentArg => {
|
export const cssForPhone = (contentArg) => {
|
||||||
if ((await getEnvironment()) === 'native' || (await getEnvironment()) === 'desktop') {
|
if (getEnvironment() === 'native' || getEnvironment() === 'desktop') {
|
||||||
return `
|
return `
|
||||||
@media (max-width: ${phone}px) {
|
@media (max-width: ${phone}px) {
|
||||||
${contentArg}
|
${contentArg}
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
} else if ((await getEnvironment()) === 'phone') {
|
} else if (getEnvironment() === 'phone') {
|
||||||
return `
|
return `
|
||||||
@media (min-width: 0px) {
|
@media (min-width: 0px) {
|
||||||
${contentArg}
|
${contentArg}
|
||||||
|
@ -31,7 +31,15 @@ export class DomTools {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public smartstate = new plugins.smartstate.Smartstate();
|
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 domToolsReady = plugins.smartpromise.defer();
|
||||||
public domReady = plugins.smartpromise.defer();
|
public domReady = plugins.smartpromise.defer();
|
||||||
@ -46,7 +54,9 @@ export class DomTools {
|
|||||||
bodyElement: null
|
bodyElement: null
|
||||||
};
|
};
|
||||||
|
|
||||||
constructor() {}
|
constructor() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public async setGlobalStyles(stylesText: string) {
|
public async setGlobalStyles(stylesText: string) {
|
||||||
await this.domReady.promise;
|
await this.domReady.promise;
|
||||||
@ -82,5 +92,7 @@ export class DomTools {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
setVirtualViewport() {}
|
setVirtualViewport(environmentArg: TViewport) {
|
||||||
|
this.domToolsStatePart.dispatchAction(this.actionSetVirtualViewport, environmentArg);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,3 +5,4 @@ import * as breakpoints from './domtools.breakpoints';
|
|||||||
import * as css from './domtools.css';
|
import * as css from './domtools.css';
|
||||||
|
|
||||||
export { css, breakpoints, elementBasic };
|
export { css, breakpoints, elementBasic };
|
||||||
|
export { DomTools } from './domtools.classes.domtools';
|
||||||
|
Reference in New Issue
Block a user