Skip to content

Commit

Permalink
refactor: add @ng-web-apis/platform
Browse files Browse the repository at this point in the history
  • Loading branch information
splincode committed Oct 10, 2024
1 parent b9ac68a commit 2dc9bfb
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 63 deletions.
99 changes: 55 additions & 44 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions projects/cdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"@angular/core": ">=16.0.0",
"@angular/forms": ">=16.0.0",
"@ng-web-apis/common": ">=4.8.0 <5",
"@ng-web-apis/platform": ">=4.8.0 <5",
"@ng-web-apis/mutation-observer": ">=4.8.0 <5",
"@ng-web-apis/resize-observer": ">=4.8.0 <5",
"@taiga-ui/event-plugins": ">=4.2.4 <5",
Expand Down
5 changes: 3 additions & 2 deletions projects/cdk/tokens/environment.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import {inject} from '@angular/core';
import {toSignal} from '@angular/core/rxjs-interop';
import {WA_NAVIGATOR, WA_USER_AGENT, WA_WINDOW} from '@ng-web-apis/common';
import {isIos} from '@ng-web-apis/platform';
import {TUI_FALSE_HANDLER} from '@taiga-ui/cdk/constants';
import {tuiCreateTokenFromFactory, tuiIsIos} from '@taiga-ui/cdk/utils';
import {tuiCreateTokenFromFactory} from '@taiga-ui/cdk/utils';
import {fromEvent, map} from 'rxjs';

// https://stackoverflow.com/a/11381730/2706426 http://detectmobilebrowsers.com/
Expand All @@ -19,7 +20,7 @@ export const TUI_IS_MOBILE = tuiCreateTokenFromFactory(
secondRegex.test(inject(WA_USER_AGENT).slice(0, 4).toLowerCase()),
);

export const TUI_IS_IOS = tuiCreateTokenFromFactory(() => tuiIsIos(inject(WA_NAVIGATOR)));
export const TUI_IS_IOS = tuiCreateTokenFromFactory(() => isIos(inject(WA_NAVIGATOR)));

export const TUI_IS_ANDROID = tuiCreateTokenFromFactory(
() => inject(TUI_IS_MOBILE) && !inject(TUI_IS_IOS),
Expand Down
15 changes: 6 additions & 9 deletions projects/cdk/utils/browser/is-ios.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import {tuiIsApple} from './is-apple';
import {isIos} from '@ng-web-apis/platform';

const IOS_REG_EXP = /ipad|iphone|ipod/;

export function tuiIsIos(navigator: Navigator): boolean {
return (
IOS_REG_EXP.test(navigator.userAgent.toLowerCase()) ||
(tuiIsApple(navigator) && navigator.maxTouchPoints > 1)
);
}
/**
* @deprecated: drop in v5, use import {isApple} from '@ng-web-apis/platform';
* @param navigator
*/
export const tuiIsIos = isIos;
4 changes: 2 additions & 2 deletions projects/legacy/tokens/is-apple.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import {inject} from '@angular/core';
import {WA_NAVIGATOR} from '@ng-web-apis/common';
import {isApple} from '@ng-web-apis/platform';
import {tuiCreateTokenFromFactory} from '@taiga-ui/cdk/utils/miscellaneous';
import {tuiIsApple} from '@taiga-ui/legacy/utils';

/**
* @deprecated: drop in v5.0
* Apple(safari/webkit) detection
*/
export const TUI_IS_APPLE = tuiCreateTokenFromFactory(() =>
tuiIsApple(inject(WA_NAVIGATOR)),
isApple(inject(WA_NAVIGATOR)),
);
8 changes: 2 additions & 6 deletions projects/legacy/utils/is-apple.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import {tuiIsIos} from '@taiga-ui/cdk/utils/browser';

const SAFARI_REG_EXP = /^((?!chrome|android).)*safari/i;
import {isApple} from '@ng-web-apis/platform';

/**
* @deprecated: drop in v5.0
*/
export function tuiIsApple(navigator: Navigator): boolean {
return tuiIsIos(navigator) || SAFARI_REG_EXP.test(navigator.userAgent.toLowerCase());
}
export const tuiIsApple = isApple;

0 comments on commit 2dc9bfb

Please sign in to comment.