Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code: Added new types package for TS #12301

Merged
merged 30 commits into from
Sep 19, 2022
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
2cb5450
Added base config for new type package
Sep 8, 2022
a40720a
Merge branch 'main' into code/12090-ts-package
Sep 12, 2022
962d704
Initial resources and elements
Sep 13, 2022
3516042
Adding remaining elements to types package
Sep 13, 2022
0311b64
Fixed errors in patterns package
Sep 13, 2022
737fcb4
Slightly improved font typings and renamed things
Sep 13, 2022
b95282f
Moved pattern types to new types package
Sep 13, 2022
ed60ddd
Updated lock file
Sep 13, 2022
84ca857
Fixed @gfc/types package version
Sep 13, 2022
a582d7b
Fixed some type imports
Sep 13, 2022
94f74f1
Moved resource types from media package to types package
Sep 13, 2022
67e6681
Moved element types from units package to types package
Sep 13, 2022
d911669
Merge branch 'main' into code/12090-ts-package
Sep 13, 2022
a017167
Renamed enum
Sep 13, 2022
accf92c
Renamed enum values and fixed some imports
Sep 13, 2022
543e490
Fixed terrible import
Sep 13, 2022
dc68e44
Fixed more terrible imports
Sep 13, 2022
a2f9c31
Fixed some resource typing and fixed resource-related tests
Sep 13, 2022
dc477bd
Merge branch 'main' into code/12090-ts-package
Sep 14, 2022
4095721
Merge branch 'main' into code/12090-ts-package
Sep 15, 2022
c1236b4
Merge branch 'main' into code/12090-ts-package
Sep 15, 2022
b6db799
Fixed some comments from PR
Sep 16, 2022
599c46a
Merge branch 'main' into code/12090-ts-package
Sep 16, 2022
e412807
Renamed resource type enum
Sep 16, 2022
b419321
Removed irrelevant properties
Sep 16, 2022
d53dfa0
Fixed some references in the rich text package
Sep 16, 2022
0a8dbd2
Added regular as an alternative for font style
Sep 16, 2022
374ca3c
Fixed tests
Sep 16, 2022
c82dd35
Added type for font metrics
Sep 19, 2022
f73c8dc
Merge branch 'main' into code/12090-ts-package
Sep 19, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 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 packages/media/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"dependencies": {
"@googleforcreators/react": "*",
"@googleforcreators/tracking": "*",
"@googleforcreators/types": "*",
"@googleforcreators/units": "*",
"mime": "^3.0.0",
"prop-types": "^15.8.1"
Expand Down
4 changes: 2 additions & 2 deletions packages/media/src/aspectRatiosApproximatelyMatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
*/

/**
* Internal dependencies
* External dependencies
*/
import type { Dimensions } from './types';
import type { Dimensions } from '@googleforcreators/types';

function aspectRatiosApproximatelyMatch(
obj1: Dimensions,
Expand Down
6 changes: 5 additions & 1 deletion packages/media/src/calculateSrcSet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,15 @@
* limitations under the License.
*/

/**
* External dependencies
*/
import type { Resource, ResourceSize } from '@googleforcreators/types';

/**
* Internal dependencies
*/
import aspectRatiosApproximatelyMatch from './aspectRatiosApproximatelyMatch';
import type { Resource, ResourceSize } from './types';

/**
* Encodes a text string as a valid Uniform Resource Identifier (URI)
Expand Down
75 changes: 61 additions & 14 deletions packages/media/src/createResource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,21 @@
*/

/**
* Internal dependencies
* External dependencies
*/
import getTypeFromMime from './getTypeFromMime';
import normalizeResourceSizes from './normalizeResourceSizes';
import type {
import {
GifResource,
Resource,
ResourceType,
VideoResource,
ResourceInput,
} from './types';
} from '@googleforcreators/types';

/**
* Internal dependencies
*/
import getTypeFromMime from './getTypeFromMime';
import normalizeResourceSizes from './normalizeResourceSizes';
import type { ResourceInput } from './types';

/**
* Creates a resource object.
Expand Down Expand Up @@ -57,6 +62,56 @@ function createResource({
trimData,
needsProxy = false,
}: ResourceInput): Resource | VideoResource | GifResource {
type = type || getTypeFromMime(mimeType);
if (type === ResourceType.VIDEO) {
miina marked this conversation as resolved.
Show resolved Hide resolved
return {
baseColor,
blurHash,
type,
mimeType,
creationDate,
src,
width: Number(width || 0),
height: Number(height || 0),
poster,
posterId,
id,
length,
lengthFormatted,
alt,
sizes: normalizeResourceSizes(sizes),
attribution,
isPlaceholder,
isOptimized,
isMuted,
isExternal,
trimData,
needsProxy,
};
}
if (type === ResourceType.GIF) {
return {
baseColor,
blurHash,
type,
mimeType,
creationDate,
src,
width: Number(width || 0),
height: Number(height || 0),
poster,
posterId,
id,
alt,
sizes: normalizeResourceSizes(sizes),
attribution,
output,
isPlaceholder,
isOptimized,
isExternal,
needsProxy,
};
}
return {
baseColor,
blurHash,
Expand All @@ -66,20 +121,12 @@ function createResource({
src,
width: Number(width || 0),
height: Number(height || 0),
poster,
posterId,
id,
length,
lengthFormatted,
alt,
sizes: normalizeResourceSizes(sizes),
attribution,
output,
isPlaceholder,
isOptimized,
isMuted,
isExternal,
trimData,
needsProxy,
};
}
Expand Down
6 changes: 5 additions & 1 deletion packages/media/src/generateVideoStrip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,17 @@
* limitations under the License.
*/

/**
* External dependencies
*/
import type { VideoResource } from '@googleforcreators/types';

/**
* Internal dependencies
*/
import getMediaSizePositionProps from './getMediaSizePositionProps';
import preloadVideo from './preloadVideo';
import seekVideo from './seekVideo';
import type { VideoResource } from './types';

const CACHE: Map<string, string> = new Map();

Expand Down
6 changes: 5 additions & 1 deletion packages/media/src/getImageDimensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,15 @@
* limitations under the License.
*/

/**
* External dependencies
*/
import type { Dimensions } from '@googleforcreators/types';

/**
* Internal dependencies
*/
import preloadImage from './preloadImage';
import type { Dimensions } from './types';

/**
* Get image dimensions from an image.
Expand Down
4 changes: 2 additions & 2 deletions packages/media/src/getMediaSizePositionProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
*/

/**
* Internal dependencies
* External dependencies
*/
import type { Resource } from './types';
import type { Resource } from '@googleforcreators/types';

interface MediaSizePositionProps {
width: number;
Expand Down
6 changes: 5 additions & 1 deletion packages/media/src/getSmallestUrlForWidth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,15 @@
* limitations under the License.
*/

/**
* External dependencies
*/
import type { Resource } from '@googleforcreators/types';

/**
* Internal dependencies
*/
import aspectRatiosApproximatelyMatch from './aspectRatiosApproximatelyMatch';
import type { Resource } from './types';

/**
* Choose the source URL of the smallest available size image / video wider than
Expand Down
4 changes: 2 additions & 2 deletions packages/media/src/getTypeFromMime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
*/

/**
* Internal dependencies
* External dependencies
*/
import type { ResourceType } from './types';
import type { ResourceType } from '@googleforcreators/types';

/**
* Infer element type from mime type of its resource
Expand Down
4 changes: 2 additions & 2 deletions packages/media/src/normalizeResourceSizes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
*/

/**
* Internal dependencies
* External dependencies
*/
import type { ResourceSize } from './types';
import type { ResourceSize } from '@googleforcreators/types';

interface ResourceSizeInput {
width: number | string;
Expand Down
4 changes: 2 additions & 2 deletions packages/media/src/resourceList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
*/

/**
* Internal dependencies
* External dependencies
*/
import type { ResourceId } from './types';
import type { ResourceId } from '@googleforcreators/types';

interface ResourceCacheEntry {
url: string;
Expand Down
Loading