@tamagui/react-native-media-driver 1.125.19 → 1.125.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tamagui/react-native-media-driver",
3
- "version": "1.125.19",
3
+ "version": "1.125.21",
4
4
  "sideEffects": false,
5
5
  "source": "src/index.ts",
6
6
  "main": "dist/cjs",
@@ -26,10 +26,10 @@
26
26
  }
27
27
  },
28
28
  "dependencies": {
29
- "@tamagui/web": "1.125.19"
29
+ "@tamagui/web": "1.125.21"
30
30
  },
31
31
  "devDependencies": {
32
- "@tamagui/build": "1.125.19",
32
+ "@tamagui/build": "1.125.21",
33
33
  "react-native": "^0.76.5"
34
34
  },
35
35
  "peerDependencies": {
@@ -1,13 +0,0 @@
1
- {
2
- "mappings": "AAAA,cAAc,wBAAwB,cAAc;;;;;AASpD,OAAO,iBAAS,YACd,UAAU,iBACO,iBAChB,GACDA,OAAO,IAAI",
3
- "names": [
4
- "media: A"
5
- ],
6
- "sources": [
7
- "src/createMedia.ts"
8
- ],
9
- "sourcesContent": [
10
- "import type { MediaQueryObject } from '@tamagui/web'\nimport { setupMatchMedia } from '@tamagui/web'\n\nimport { matchMedia } from './matchMedia'\n\n/**\n * @deprecated you no longer need to call createMedia or import @tamagui/react-native-media-driver at all.\n * Tamagui now automatically handles setting this up, you can just pass a plain object to createTamagui.\n */\nexport function createMedia<\n A extends {\n [key: string]: MediaQueryObject\n },\n>(media: A): A {\n // this should ideally return a diff object that is then passed to createTamagui\n // but works for now we dont really support swapping out media drivers\n setupMatchMedia(matchMedia)\n return media\n}\n"
11
- ],
12
- "version": 3
13
- }
@@ -1,11 +0,0 @@
1
- {
2
- "mappings": "AAAA,cAAc;AACd,cAAc",
3
- "names": [],
4
- "sources": [
5
- "src/index.ts"
6
- ],
7
- "sourcesContent": [
8
- "export * from './createMedia'\nexport * from './matchMedia'\n"
9
- ],
10
- "version": 3
11
- }
@@ -1,13 +0,0 @@
1
- {
2
- "mappings": "AAEA,cAAc,kBAAkB,cAAc;AAE9C,OAAO,cAAMA,YAAY",
3
- "names": [
4
- "matchMedia: MatchMedia"
5
- ],
6
- "sources": [
7
- "src/matchMedia.ts"
8
- ],
9
- "sourcesContent": [
10
- "// web-only use platform:\n\nimport type { MatchMedia } from '@tamagui/web'\n\nexport const matchMedia: MatchMedia = globalThis['matchMedia']\n"
11
- ],
12
- "version": 3
13
- }
@@ -1,13 +0,0 @@
1
- {
2
- "mappings": "AAAA,cAAc,kBAAkB,cAAc;AAI9C,OAAO,cAAMA,YAAY",
3
- "names": [
4
- "matchMedia: MatchMedia"
5
- ],
6
- "sources": [
7
- "src/matchMedia.native.ts"
8
- ],
9
- "sourcesContent": [
10
- "import type { MatchMedia } from '@tamagui/web'\n\nimport { NativeMediaQueryList } from './mediaQueryList'\n\nexport const matchMedia: MatchMedia = (query) => {\n return new NativeMediaQueryList(query)\n}\n"
11
- ],
12
- "version": 3
13
- }
@@ -1,14 +0,0 @@
1
- {
2
- "mappings": "AAcA,OAAO,iBAAS,WAAWA,oBAAoBC,QAAQ;AA0EvD,OAAO,iBAAS,WAAWD,sBAAsB;CAC/C;CACA;CACA,aAAa;EACX;EACA;EACA;CACD;AACF,IAAG",
3
- "names": [
4
- "mediaQuery: string",
5
- "values: Record<string, any>"
6
- ],
7
- "sources": [
8
- "src/matchQuery.ts"
9
- ],
10
- "sourcesContent": [
11
- "/*\nCopyright (c) 2014, Yahoo! Inc. All rights reserved.\nCopyrights licensed under the New BSD License.\nSee the accompanying LICENSE file for terms.\n*/\n\n// -----------------------------------------------------------------------------\n\nconst RE_MEDIA_QUERY = /(?:(only|not)?\\s*([^\\s\\(\\)]+)(?:\\s*and)?\\s*)?(.+)?/i\nconst RE_MQ_EXPRESSION = /\\(\\s*([^\\s\\:\\)]+)\\s*(?:\\:\\s*([^\\s\\)]+))?\\s*\\)/\nconst RE_MQ_FEATURE = /^(?:(min|max)-)?(.+)/\nconst RE_LENGTH_UNIT = /(em|rem|px|cm|mm|in|pt|pc)?$/\nconst RE_RESOLUTION_UNIT = /(dpi|dpcm|dppx)?$/\n\nexport function matchQuery(mediaQuery: string, values: Record<string, any>): boolean {\n return parseQuery(mediaQuery).some((query) => {\n if (!query) return\n\n const inverse = query.inverse\n\n // Either the parsed or specified `type` is \"all\", or the types must be\n // equal for a match.\n const typeMatch = query.type === 'all' || values.type === query.type\n\n // Quit early when `type` doesn't match, but take \"not\" into account.\n if ((typeMatch && inverse) || !(typeMatch || inverse)) {\n return false\n }\n\n const expressionsMatch = query.expressions.every((expression) => {\n const feature = expression.feature\n const modifier = expression.modifier\n let expValue = expression.value\n let value = values[feature]\n\n // Missing or falsy values don't match.\n if (!value) {\n return false\n }\n\n switch (feature) {\n case 'orientation':\n case 'scan':\n return value.toLowerCase() === expValue.toLowerCase()\n\n case 'width':\n case 'height':\n case 'device-width':\n case 'device-height':\n expValue = toPx(expValue)\n value = toPx(value)\n break\n\n case 'resolution':\n expValue = toDpi(expValue)\n value = toDpi(value)\n break\n\n case 'aspect-ratio':\n case 'device-aspect-ratio':\n case /* Deprecated */ 'device-pixel-ratio':\n expValue = toDecimal(expValue)\n value = toDecimal(value)\n break\n\n case 'grid':\n case 'color':\n case 'color-index':\n case 'monochrome':\n expValue = Number.parseInt(expValue, 10) || 1\n value = Number.parseInt(value, 10) || 0\n break\n }\n\n switch (modifier) {\n case 'min':\n return value >= expValue\n case 'max':\n return value <= expValue\n default:\n return value === expValue\n }\n })\n\n return (expressionsMatch && !inverse) || (!expressionsMatch && inverse)\n })\n}\n\nexport function parseQuery(mediaQuery: string): ({\n inverse: boolean\n type: string\n expressions: {\n modifier: any\n feature: any\n value: any\n }[]\n} | null)[] {\n return mediaQuery.split(',').map((query) => {\n query = query.trim()\n\n const captures = query.match(RE_MEDIA_QUERY)\n\n if (!captures) return null\n\n const modifier = captures[1]\n const type = captures[2]\n const expressionsCapture = captures[3] || ''\n // Split expressions into a list.\n const expressions = expressionsCapture.match(/\\([^\\)]+\\)/g) || []\n\n return {\n inverse: !!modifier && modifier.toLowerCase() === 'not',\n type: type ? type.toLowerCase() : 'all',\n expressions: expressions.map((expression) => {\n const captures = expression.match(RE_MQ_EXPRESSION)\n const feature = captures[1].toLowerCase().match(RE_MQ_FEATURE)\n return {\n modifier: feature[1],\n feature: feature[2],\n value: captures[2],\n }\n }),\n }\n })\n}\n\n// -- Utilities ----------------------------------------------------------------\n\nfunction toDecimal(ratio) {\n let decimal = Number(ratio)\n let numbers\n\n if (!decimal) {\n numbers = ratio.match(/^(\\d+)\\s*\\/\\s*(\\d+)$/)\n decimal = numbers[1] / numbers[2]\n }\n\n return decimal\n}\n\nfunction toDpi(resolution: string) {\n const value = Number.parseFloat(resolution)\n const units = String(resolution).match(RE_RESOLUTION_UNIT)?.[1]\n\n switch (units) {\n case 'dpcm':\n return value / 2.54\n case 'dppx':\n return value * 96\n default:\n return value\n }\n}\n\nfunction toPx(length: string) {\n const value = Number.parseFloat(length)\n const units = String(length).match(RE_LENGTH_UNIT)?.[1]\n switch (units) {\n case 'em':\n return value * 16\n case 'rem':\n return value * 16\n case 'cm':\n return (value * 96) / 2.54\n case 'mm':\n return (value * 96) / 2.54 / 10\n case 'in':\n return value * 96\n case 'pt':\n return value * 72\n case 'pc':\n return (value * 72) / 12\n default:\n return value\n }\n}\n"
12
- ],
13
- "version": 3
14
- }
@@ -1,15 +0,0 @@
1
- {
2
- "mappings": "AAAA,cAAc,sBAAsB,cAAc;KAK7C,cAAc,cAAc;KAE5B,YAAYA,aAAa;AAE9B,OAAO,cAAM,gCAAgC,eAAe;CAQ9C;CAPZ,QAAQ;CAER,YAAY;CAKZ,YAAoBC;CAOpB,QAAQ;CAMR,YAAYC,UAAU;CAItB,eAAeA,UAAU;CAKzB,MAAMD,eAAe,EAAE,OAAO,QAA2C,EAAjC;EAAE;EAAe;CAAgB;CASzE,IAAI;AAWL",
3
- "names": [
4
- "orientation: Orientation",
5
- "query: string",
6
- "listener: Listener"
7
- ],
8
- "sources": [
9
- "src/mediaQueryList.ts"
10
- ],
11
- "sourcesContent": [
12
- "import type { MediaQueryList } from '@tamagui/web'\nimport { Dimensions } from 'react-native'\n\nimport { matchQuery } from './matchQuery'\n\ntype Orientation = 'landscape' | 'portrait'\n\ntype Listener = (orientation: Orientation) => void\n\nexport class NativeMediaQueryList implements MediaQueryList {\n private listeners: Listener[] = []\n\n private get orientation(): Orientation {\n const windowDimensions = Dimensions.get('window')\n return windowDimensions.height > windowDimensions.width ? 'portrait' : 'landscape'\n }\n\n constructor(private query: string) {\n this.notify()\n Dimensions.addEventListener('change', () => {\n this.notify()\n })\n }\n\n private notify() {\n this.listeners.forEach((listener) => {\n listener(this.orientation)\n })\n }\n\n addListener(listener: Listener): void {\n this.listeners.push(listener)\n }\n\n removeListener(listener: Listener): void {\n const index = this.listeners.indexOf(listener)\n if (index !== -1) this.listeners.splice(index, 1)\n }\n\n match(query: string, { width, height }: { width: number; height: number }): boolean {\n return matchQuery(query, {\n type: 'screen',\n orientation: height > width ? 'portrait' : 'landscape',\n 'device-width': width,\n 'device-height': height,\n })\n }\n\n get matches(): boolean {\n const windowDimensions = Dimensions.get('window')\n const matches = matchQuery(this.query, {\n type: 'screen',\n orientation: this.orientation,\n ...windowDimensions,\n 'device-width': windowDimensions.width,\n 'device-height': windowDimensions.height,\n })\n return matches\n }\n}\n"
13
- ],
14
- "version": 3
15
- }