1 | import {
|
2 | GraphQLInputObjectType,
|
3 | GraphQLBoolean,
|
4 | GraphQLString,
|
5 | GraphQLInt,
|
6 | GraphQLFloat,
|
7 | GraphQLEnumType,
|
8 | GraphQLNonNull,
|
9 | GraphQLInputFieldConfigMap,
|
10 | } from "gatsby/graphql"
|
11 | import { Potrace } from "potrace"
|
12 | import type Sharp from "sharp"
|
13 |
|
14 | const sharp: typeof Sharp = require(`./safe-sharp`)
|
15 | const DEFAULT_PNG_COMPRESSION_SPEED = 4
|
16 |
|
17 | export const ImageFormatType = new GraphQLEnumType({
|
18 | name: `ImageFormat`,
|
19 | values: {
|
20 | NO_CHANGE: { value: `` },
|
21 | AUTO: { value: `` },
|
22 | JPG: { value: `jpg` },
|
23 | PNG: { value: `png` },
|
24 | WEBP: { value: `webp` },
|
25 | },
|
26 | })
|
27 |
|
28 | export const ImageLayoutType = new GraphQLEnumType({
|
29 | name: `ImageLayout`,
|
30 | values: {
|
31 | FIXED: { value: `fixed` },
|
32 | FLUID: { value: `fluid` },
|
33 | CONSTRAINED: { value: `constrained` },
|
34 | },
|
35 | })
|
36 |
|
37 | export const ImagePlaceholderType = new GraphQLEnumType({
|
38 | name: `ImagePlaceholder`,
|
39 | values: {
|
40 | DOMINANT_COLOR: { value: `dominantColor` },
|
41 | TRACED_SVG: { value: `tracedSVG` },
|
42 | BLURRED: { value: `blurred` },
|
43 | NONE: { value: `none` },
|
44 | },
|
45 | })
|
46 |
|
47 | export const ImageFitType = new GraphQLEnumType({
|
48 | name: `ImageFit`,
|
49 | values: {
|
50 | COVER: { value: sharp.fit.cover },
|
51 | CONTAIN: { value: sharp.fit.contain },
|
52 | FILL: { value: sharp.fit.fill },
|
53 | INSIDE: { value: sharp.fit.inside },
|
54 | OUTSIDE: { value: sharp.fit.outside },
|
55 | },
|
56 | })
|
57 |
|
58 | export const ImageCropFocusType = new GraphQLEnumType({
|
59 | name: `ImageCropFocus`,
|
60 | values: {
|
61 | CENTER: { value: sharp.gravity.center },
|
62 | NORTH: { value: sharp.gravity.north },
|
63 | NORTHEAST: { value: sharp.gravity.northeast },
|
64 | EAST: { value: sharp.gravity.east },
|
65 | SOUTHEAST: { value: sharp.gravity.southeast },
|
66 | SOUTH: { value: sharp.gravity.south },
|
67 | SOUTHWEST: { value: sharp.gravity.southwest },
|
68 | WEST: { value: sharp.gravity.west },
|
69 | NORTHWEST: { value: sharp.gravity.northwest },
|
70 | ENTROPY: { value: sharp.strategy.entropy },
|
71 | ATTENTION: { value: sharp.strategy.attention },
|
72 | },
|
73 | })
|
74 |
|
75 | export const PNGOptionsType = new GraphQLInputObjectType({
|
76 | name: `PNGOptions`,
|
77 | fields: (): GraphQLInputFieldConfigMap => {
|
78 | return {
|
79 | quality: {
|
80 | type: GraphQLInt,
|
81 | },
|
82 | compressionSpeed: {
|
83 | type: GraphQLInt,
|
84 | defaultValue: DEFAULT_PNG_COMPRESSION_SPEED,
|
85 | },
|
86 | }
|
87 | },
|
88 | })
|
89 |
|
90 | export const JPGOptionsType = new GraphQLInputObjectType({
|
91 | name: `JPGOptions`,
|
92 | fields: (): GraphQLInputFieldConfigMap => {
|
93 | return {
|
94 | quality: {
|
95 | type: GraphQLInt,
|
96 | },
|
97 | progressive: {
|
98 | type: GraphQLBoolean,
|
99 | defaultValue: true,
|
100 | },
|
101 | }
|
102 | },
|
103 | })
|
104 |
|
105 | export const BlurredOptionsType = new GraphQLInputObjectType({
|
106 | name: `BlurredOptions`,
|
107 | fields: (): GraphQLInputFieldConfigMap => {
|
108 | return {
|
109 | width: {
|
110 | type: GraphQLInt,
|
111 | description: `Width of the generated low-res preview. Default is 20px`,
|
112 | },
|
113 | toFormat: {
|
114 | type: ImageFormatType,
|
115 | description: `Force the output format for the low-res preview. Default is to use the same format as the input. You should rarely need to change this`,
|
116 | },
|
117 | }
|
118 | },
|
119 | })
|
120 |
|
121 | export const WebPOptionsType = new GraphQLInputObjectType({
|
122 | name: `WebPOptions`,
|
123 | fields: (): GraphQLInputFieldConfigMap => {
|
124 | return {
|
125 | quality: {
|
126 | type: GraphQLInt,
|
127 | },
|
128 | }
|
129 | },
|
130 | })
|
131 |
|
132 | export const DuotoneGradientType = new GraphQLInputObjectType({
|
133 | name: `DuotoneGradient`,
|
134 | fields: (): GraphQLInputFieldConfigMap => {
|
135 | return {
|
136 | highlight: { type: new GraphQLNonNull(GraphQLString) },
|
137 | shadow: { type: new GraphQLNonNull(GraphQLString) },
|
138 | opacity: { type: GraphQLInt },
|
139 | }
|
140 | },
|
141 | })
|
142 |
|
143 | export const PotraceTurnPolicyType = new GraphQLEnumType({
|
144 | name: `PotraceTurnPolicy`,
|
145 | values: {
|
146 | TURNPOLICY_BLACK: { value: Potrace.TURNPOLICY_BLACK },
|
147 | TURNPOLICY_WHITE: { value: Potrace.TURNPOLICY_WHITE },
|
148 | TURNPOLICY_LEFT: { value: Potrace.TURNPOLICY_LEFT },
|
149 | TURNPOLICY_RIGHT: { value: Potrace.TURNPOLICY_RIGHT },
|
150 | TURNPOLICY_MINORITY: { value: Potrace.TURNPOLICY_MINORITY },
|
151 | TURNPOLICY_MAJORITY: { value: Potrace.TURNPOLICY_MAJORITY },
|
152 | },
|
153 | })
|
154 |
|
155 | export const PotraceType = new GraphQLInputObjectType({
|
156 | name: `Potrace`,
|
157 | fields: (): GraphQLInputFieldConfigMap => {
|
158 | return {
|
159 | turnPolicy: {
|
160 | type: PotraceTurnPolicyType,
|
161 | },
|
162 | turdSize: { type: GraphQLFloat },
|
163 | alphaMax: { type: GraphQLFloat },
|
164 | optCurve: { type: GraphQLBoolean },
|
165 | optTolerance: { type: GraphQLFloat },
|
166 | threshold: { type: GraphQLInt },
|
167 | blackOnWhite: { type: GraphQLBoolean },
|
168 | color: { type: GraphQLString },
|
169 | background: { type: GraphQLString },
|
170 | }
|
171 | },
|
172 | })
|
173 |
|
174 | export const TransformOptionsType = new GraphQLInputObjectType({
|
175 | name: `TransformOptions`,
|
176 | fields: (): GraphQLInputFieldConfigMap => {
|
177 | return {
|
178 | grayscale: {
|
179 | type: GraphQLBoolean,
|
180 | defaultValue: false,
|
181 | },
|
182 | duotone: {
|
183 | type: DuotoneGradientType,
|
184 | defaultValue: false,
|
185 | },
|
186 | rotate: {
|
187 | type: GraphQLInt,
|
188 | defaultValue: 0,
|
189 | },
|
190 | trim: {
|
191 | type: GraphQLFloat,
|
192 | defaultValue: false,
|
193 | },
|
194 | cropFocus: {
|
195 | type: ImageCropFocusType,
|
196 | defaultValue: sharp.strategy.attention,
|
197 | },
|
198 | fit: {
|
199 | type: ImageFitType,
|
200 | defaultValue: sharp.fit.cover,
|
201 | },
|
202 | }
|
203 | },
|
204 | })
|