@charcoal-ui/styled 2.4.0 → 2.5.0
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/dist/builders/border.d.ts +10 -0
- package/dist/builders/border.d.ts.map +1 -0
- package/dist/builders/borderRadius.d.ts +7 -0
- package/dist/builders/borderRadius.d.ts.map +1 -0
- package/dist/builders/colors.d.ts +13 -0
- package/dist/builders/colors.d.ts.map +1 -0
- package/dist/builders/elementEffect.d.ts +7 -0
- package/dist/builders/elementEffect.d.ts.map +1 -0
- package/dist/builders/o.d.ts +115 -0
- package/dist/builders/o.d.ts.map +1 -0
- package/dist/builders/outline.d.ts +10 -0
- package/dist/builders/outline.d.ts.map +1 -0
- package/dist/builders/size.d.ts +23 -0
- package/dist/builders/size.d.ts.map +1 -0
- package/dist/builders/spacing.d.ts +15 -0
- package/dist/builders/spacing.d.ts.map +1 -0
- package/dist/builders/transition.d.ts +7 -0
- package/dist/builders/transition.d.ts.map +1 -0
- package/dist/builders/typography.d.ts +11 -0
- package/dist/builders/typography.d.ts.map +1 -0
- package/dist/{lib.d.ts → factories/lib.d.ts} +13 -14
- package/dist/factories/lib.d.ts.map +1 -0
- package/dist/index.cjs +764 -641
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +91 -30
- package/dist/index.d.ts.map +1 -1
- package/dist/index.modern.js +554 -391
- package/dist/index.modern.js.map +1 -1
- package/dist/index.module.js +764 -641
- package/dist/index.module.js.map +1 -1
- package/dist/index.story.d.ts +1 -0
- package/dist/index.story.d.ts.map +1 -1
- package/dist/index.test.d.ts +2 -0
- package/dist/index.test.d.ts.map +1 -0
- package/dist/internals/index.d.ts +42 -0
- package/dist/internals/index.d.ts.map +1 -0
- package/dist/util.d.ts +36 -2
- package/dist/util.d.ts.map +1 -1
- package/package.json +8 -5
- package/src/__snapshots__/index.test.tsx.snap +768 -0
- package/src/builders/border.ts +63 -0
- package/src/builders/borderRadius.ts +32 -0
- package/src/builders/colors.ts +198 -0
- package/src/builders/elementEffect.ts +54 -0
- package/src/builders/o.ts +43 -0
- package/src/builders/outline.ts +79 -0
- package/src/builders/size.ts +61 -0
- package/src/builders/spacing.ts +113 -0
- package/src/builders/transition.ts +32 -0
- package/src/builders/typography.ts +97 -0
- package/src/{lib.ts → factories/lib.ts} +30 -25
- package/src/index.story.tsx +2 -2
- package/src/index.test.tsx +24 -0
- package/src/index.ts +47 -696
- package/src/internals/index.ts +84 -0
- package/src/util.ts +46 -3
- package/dist/lib.d.ts.map +0 -1
package/dist/index.module.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { filterObject, flatMapObject, customPropertyToken, applyEffect, notDisabledSelector, disabledSelector, px, dur, gradient, applyEffectToGradient, halfLeading } from '@charcoal-ui/utils';
|
|
1
2
|
import warning from 'warning';
|
|
2
|
-
import { filterObject, flatMapObject, customPropertyToken, applyEffect, dur, gradient, applyEffectToGradient, notDisabledSelector, halfLeading, px, disabledSelector } from '@charcoal-ui/utils';
|
|
3
3
|
import { columnSystem } from '@charcoal-ui/foundation';
|
|
4
4
|
import React, { useEffect, useState, useMemo } from 'react';
|
|
5
5
|
import { createGlobalStyle, css } from 'styled-components';
|
|
@@ -46,9 +46,27 @@ var isPresent = function isPresent(value) {
|
|
|
46
46
|
function objectAssign() {
|
|
47
47
|
return Object.assign.apply(Object, [{}].concat([].slice.call(arguments)));
|
|
48
48
|
}
|
|
49
|
-
|
|
49
|
+
/**
|
|
50
|
+
* Object.keys の返り値の型を厳しめにしてくれるやつ。
|
|
51
|
+
*
|
|
52
|
+
* ジェネリクスは基本的に明示して使うことを推奨。
|
|
53
|
+
*
|
|
54
|
+
* このライブラリでは Theme オブジェクトのジェネリクスを引き回すケースが多く、
|
|
55
|
+
* ジェネリクスを省略するといつのまにか keys の返り値が `string | number | symbol` になりがちなので
|
|
56
|
+
*
|
|
57
|
+
* @param obj - キーを取りたいオブジェクト。ジェネリクスを省略したとき `never[]` のような使えない型が返って欲しい
|
|
58
|
+
*/
|
|
59
|
+
|
|
60
|
+
function keyof(obj) {
|
|
50
61
|
return Object.keys(obj);
|
|
51
62
|
}
|
|
63
|
+
/**
|
|
64
|
+
* 配列じゃなかったら配列にする
|
|
65
|
+
*/
|
|
66
|
+
|
|
67
|
+
function wrapArray(value) {
|
|
68
|
+
return Array.isArray(value) ? value : [value];
|
|
69
|
+
}
|
|
52
70
|
var noThemeProvider = new Error('`theme` is invalid. `<ThemeProvider>` is not likely mounted.');
|
|
53
71
|
/**
|
|
54
72
|
* 子孫要素で使われるカラーテーマの CSS Variables を上書きする
|
|
@@ -84,6 +102,84 @@ function defineThemeVariables(colorParams, effectParams) {
|
|
|
84
102
|
});
|
|
85
103
|
};
|
|
86
104
|
}
|
|
105
|
+
function isSupportedEffect(effect) {
|
|
106
|
+
return ['hover', 'press', 'disabled'].includes(effect);
|
|
107
|
+
}
|
|
108
|
+
var variable = function variable(value) {
|
|
109
|
+
return "var(" + value + ")";
|
|
110
|
+
};
|
|
111
|
+
function onEffectPseudo(effect, css) {
|
|
112
|
+
var _hover, _active, _ref4;
|
|
113
|
+
|
|
114
|
+
return effect === 'hover' ? {
|
|
115
|
+
'&:hover': (_hover = {}, _hover[notDisabledSelector] = css, _hover)
|
|
116
|
+
} : effect === 'press' ? {
|
|
117
|
+
'&:active': (_active = {}, _active[notDisabledSelector] = css, _active)
|
|
118
|
+
} : // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
119
|
+
effect === 'disabled' ? (_ref4 = {}, _ref4[disabledSelector] = css, _ref4) : unreachable(effect);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* 絶対にこれを export してはいけない
|
|
124
|
+
*
|
|
125
|
+
* さもないと `o.bg[internalSym]` みたいな叩き方が可能になってしまう(補完にも意図せず出てしまう)
|
|
126
|
+
*/
|
|
127
|
+
var internalSym = Symbol('internal');
|
|
128
|
+
/**
|
|
129
|
+
* CSSObject に変換可能なオブジェクトを作成する
|
|
130
|
+
*
|
|
131
|
+
* 実際に CSSObject に変換するには外部から `__DO_NOT_USE_GET_INTERNAL__` を使わなければならない
|
|
132
|
+
*
|
|
133
|
+
* これ以降メソッドチェーンが続いてもいいし、続かなくても良い
|
|
134
|
+
*/
|
|
135
|
+
|
|
136
|
+
function createInternal(_ref) {
|
|
137
|
+
var _ref2;
|
|
138
|
+
|
|
139
|
+
var toCSS = _ref.toCSS,
|
|
140
|
+
_ref$context = _ref.context,
|
|
141
|
+
context = _ref$context === void 0 ? {} : _ref$context;
|
|
142
|
+
return _ref2 = {}, _ref2[internalSym] = {
|
|
143
|
+
toCSS: toCSS,
|
|
144
|
+
context: context
|
|
145
|
+
}, _ref2;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
function __DO_NOT_USE_ACCESS_PRIVATE_PROPERTY__(internal) {
|
|
149
|
+
return internal[internalSym];
|
|
150
|
+
} // half-leadingをキャンセルするとき && 垂直方向のpaddingが無い時
|
|
151
|
+
// -> before/afterを入れる
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
var shouldCancelHalfLeading = function shouldCancelHalfLeading(_ref3) {
|
|
155
|
+
var cancelHalfLeadingPx = _ref3.cancelHalfLeadingPx,
|
|
156
|
+
_ref3$hasVerticalPadd = _ref3.hasVerticalPadding,
|
|
157
|
+
hasVerticalPadding = _ref3$hasVerticalPadd === void 0 ? false : _ref3$hasVerticalPadd;
|
|
158
|
+
return cancelHalfLeadingPx !== undefined && !hasVerticalPadding;
|
|
159
|
+
};
|
|
160
|
+
/**
|
|
161
|
+
* 個別の Internal( o.〇〇 の返り値 )が提出した context の中身を1つの context にまとめる
|
|
162
|
+
*/
|
|
163
|
+
|
|
164
|
+
function getContext(internals) {
|
|
165
|
+
return internals.reduce(function (context, internal) {
|
|
166
|
+
return _extends({}, context, __DO_NOT_USE_ACCESS_PRIVATE_PROPERTY__(internal).context);
|
|
167
|
+
}, {});
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* 全ユーザー定義からコンテキスト生成し、styled-components 向けに CSSObject を構築
|
|
171
|
+
*/
|
|
172
|
+
|
|
173
|
+
function toCSSObjects(internals) {
|
|
174
|
+
// 1パス目
|
|
175
|
+
// 全ユーザー定義を舐めて相互に影響し合う定義をチェックし、その結果(コンテキスト)を取得
|
|
176
|
+
var context = getContext(internals); // 2パス目
|
|
177
|
+
// コンテキストを見ながら最適化されたCSSを構築
|
|
178
|
+
|
|
179
|
+
return internals.map(function (v) {
|
|
180
|
+
return __DO_NOT_USE_ACCESS_PRIVATE_PROPERTY__(v).toCSS(context);
|
|
181
|
+
});
|
|
182
|
+
}
|
|
87
183
|
|
|
88
184
|
/**
|
|
89
185
|
* 配列で指定したプロパティを動的に生やす
|
|
@@ -101,7 +197,7 @@ function defineThemeVariables(colorParams, effectParams) {
|
|
|
101
197
|
* console.log(o.red) //=> #ff0000
|
|
102
198
|
*/
|
|
103
199
|
|
|
104
|
-
var
|
|
200
|
+
var defineProperties = function defineProperties(source, member, chain) {
|
|
105
201
|
return Object.defineProperties(source, Object.fromEntries(member.map(function (key) {
|
|
106
202
|
return [key, {
|
|
107
203
|
get: function get() {
|
|
@@ -121,14 +217,14 @@ var factory = function factory(source, member, chain) {
|
|
|
121
217
|
*
|
|
122
218
|
* @example
|
|
123
219
|
*
|
|
124
|
-
* const o =
|
|
220
|
+
* const o = defineMethods({}, ['red', 'blue'],
|
|
125
221
|
* (color, alpha: number) => hex(color, alpha)
|
|
126
222
|
* )
|
|
127
223
|
*
|
|
128
224
|
* console.log(o.red(0.5)) //=> #ff000077
|
|
129
225
|
*/
|
|
130
226
|
|
|
131
|
-
var
|
|
227
|
+
var defineMethods = function defineMethods(source, member, chain) {
|
|
132
228
|
return Object.defineProperties(source, Object.fromEntries(member.map(function (key) {
|
|
133
229
|
return [key, {
|
|
134
230
|
value: function value() {
|
|
@@ -147,7 +243,7 @@ var argumentedFactory = function argumentedFactory(source, member, chain) {
|
|
|
147
243
|
*
|
|
148
244
|
* @example
|
|
149
245
|
*
|
|
150
|
-
* const o =
|
|
246
|
+
* const o = defineConstantProperties({}, {
|
|
151
247
|
* red: '#f00',
|
|
152
248
|
* blue: '#00f',
|
|
153
249
|
* })
|
|
@@ -155,8 +251,8 @@ var argumentedFactory = function argumentedFactory(source, member, chain) {
|
|
|
155
251
|
* console.log(o.red) //=> #f00
|
|
156
252
|
*/
|
|
157
253
|
|
|
158
|
-
var
|
|
159
|
-
return
|
|
254
|
+
var defineConstantProperties = function defineConstantProperties(source, def) {
|
|
255
|
+
return defineProperties(source, Object.keys(def), function (key) {
|
|
160
256
|
return def[key];
|
|
161
257
|
});
|
|
162
258
|
};
|
|
@@ -168,20 +264,20 @@ var constFactory = function constFactory(source, def) {
|
|
|
168
264
|
*
|
|
169
265
|
* @example
|
|
170
266
|
*
|
|
171
|
-
* const o =
|
|
267
|
+
* const o = definePropertyChains(['red', 'blue'],
|
|
172
268
|
* modifiers => modifiers.map(color => hex(color)).join(',')
|
|
173
269
|
* )
|
|
174
270
|
*
|
|
175
271
|
* console.log(o.red.blue) => #f00,#00f
|
|
176
272
|
*/
|
|
177
273
|
|
|
178
|
-
var
|
|
179
|
-
return function
|
|
274
|
+
var definePropertyChains = function definePropertyChains(modifiers, source) {
|
|
275
|
+
return function definePropertiesRecursively(applied) {
|
|
180
276
|
var notApplied = modifiers.filter(function (v) {
|
|
181
277
|
return !applied.includes(v);
|
|
182
278
|
});
|
|
183
|
-
return
|
|
184
|
-
return notApplied.length === 0 ? unreachable() :
|
|
279
|
+
return defineProperties(source(applied), notApplied, function (modifier) {
|
|
280
|
+
return notApplied.length === 0 ? unreachable() : definePropertiesRecursively([].concat(applied, [modifier]));
|
|
185
281
|
});
|
|
186
282
|
}([]);
|
|
187
283
|
};
|
|
@@ -194,510 +290,289 @@ var modifiedFactory = function modifiedFactory(modifiers, source) {
|
|
|
194
290
|
*
|
|
195
291
|
* @example
|
|
196
292
|
*
|
|
197
|
-
* const o =
|
|
293
|
+
* const o = defineMethodChains(['red', 'blue'],
|
|
198
294
|
* modifiers => modifiers.map(([color, alpha]) => hex(color, alpha)).join(',')
|
|
199
295
|
* , {} as [number])
|
|
200
296
|
*
|
|
201
297
|
* console.log(o.red(0.5).blue(1)) => #ff000077,#0000ffff
|
|
202
298
|
*/
|
|
203
299
|
|
|
204
|
-
var
|
|
205
|
-
return function
|
|
300
|
+
var defineMethodChains = function defineMethodChains(modifiers, source) {
|
|
301
|
+
return function defineMethodsRecursively(applied) {
|
|
206
302
|
var notApplied = modifiers.filter(function (v) {
|
|
207
303
|
return !applied.map(function (_ref) {
|
|
208
304
|
var w = _ref[0];
|
|
209
305
|
return w;
|
|
210
306
|
}).includes(v);
|
|
211
307
|
});
|
|
212
|
-
return
|
|
213
|
-
return notApplied.length === 0 ? unreachable() :
|
|
308
|
+
return defineMethods(source(applied), notApplied, function (modifier) {
|
|
309
|
+
return notApplied.length === 0 ? unreachable() : defineMethodsRecursively([].concat(applied, [[modifier].concat([].slice.call(arguments, 1))]));
|
|
214
310
|
});
|
|
215
311
|
}([]);
|
|
216
312
|
};
|
|
217
|
-
var variable = function variable(value) {
|
|
218
|
-
return "var(" + value + ")";
|
|
219
|
-
};
|
|
220
313
|
|
|
221
|
-
var
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
return Object.entries(themeMap).map(function (_ref2) {
|
|
226
|
-
var key = _ref2[0],
|
|
227
|
-
theme = _ref2[1];
|
|
228
|
-
return key.startsWith('@media') ? css(_templateObject2 || (_templateObject2 = _taggedTemplateLiteralLoose(["\n ", " {\n :root {\n ", "\n ", "\n }\n }\n "])), key, background !== undefined && css(_templateObject3 || (_templateObject3 = _taggedTemplateLiteralLoose(["\n background-color: ", ";\n "])), theme.color[background]), defineColorVariableCSS(theme)) : css(_templateObject4 || (_templateObject4 = _taggedTemplateLiteralLoose(["\n /* stylelint-disable-next-line no-duplicate-selectors */\n ", " {\n ", "\n ", "\n }\n "])), key, background !== undefined && css(_templateObject5 || (_templateObject5 = _taggedTemplateLiteralLoose(["\n background-color: ", ";\n "])), theme.color[background]), defineColorVariableCSS(theme));
|
|
229
|
-
});
|
|
230
|
-
});
|
|
231
|
-
function TokenInjector(_ref3) {
|
|
232
|
-
var themeMap = _ref3.theme,
|
|
233
|
-
background = _ref3.background;
|
|
234
|
-
return /*#__PURE__*/React.createElement(GlobalStyle, {
|
|
235
|
-
themeMap: themeMap,
|
|
236
|
-
background: background
|
|
237
|
-
});
|
|
314
|
+
var borderDirections = ['top', 'right', 'bottom', 'left'];
|
|
315
|
+
|
|
316
|
+
function borderProperty(direction) {
|
|
317
|
+
return "border-" + direction;
|
|
238
318
|
}
|
|
239
319
|
|
|
240
|
-
|
|
241
|
-
return
|
|
242
|
-
|
|
243
|
-
})).map(function (_ref4) {
|
|
244
|
-
var varName = _ref4[0],
|
|
245
|
-
value = _ref4[1];
|
|
246
|
-
return variableDefinition(varName, value.toString());
|
|
247
|
-
}).join(';');
|
|
248
|
-
};
|
|
320
|
+
function borderShorthand(color) {
|
|
321
|
+
return "solid 1px " + color;
|
|
322
|
+
}
|
|
249
323
|
|
|
250
|
-
var
|
|
251
|
-
return
|
|
324
|
+
var createBorderCss = function createBorderCss(theme) {
|
|
325
|
+
return function (variant, directions) {
|
|
326
|
+
var all = directions.length === 0;
|
|
327
|
+
var value = borderShorthand(theme.border[variant].color);
|
|
328
|
+
return createInternal({
|
|
329
|
+
toCSS: function toCSS() {
|
|
330
|
+
return _extends({}, all ? {
|
|
331
|
+
border: value
|
|
332
|
+
} : directions.reduce(function (acc, direction) {
|
|
333
|
+
var _extends2;
|
|
334
|
+
|
|
335
|
+
return _extends({}, acc, (_extends2 = {}, _extends2[borderProperty(direction)] = value, _extends2));
|
|
336
|
+
}, {}));
|
|
337
|
+
}
|
|
338
|
+
});
|
|
339
|
+
};
|
|
252
340
|
};
|
|
253
|
-
|
|
254
|
-
var
|
|
255
|
-
var
|
|
256
|
-
var
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
throw new Error("Unexpected key :" + key + ", expect: /^(\\w|-)+$/");
|
|
265
|
-
}
|
|
341
|
+
function border(theme) {
|
|
342
|
+
var borderTypes = keyof(theme.border);
|
|
343
|
+
var borderCss = createBorderCss(theme);
|
|
344
|
+
var borderObject = defineConstantProperties({}, {
|
|
345
|
+
border: defineProperties({}, borderTypes, function (variant) {
|
|
346
|
+
return definePropertyChains(borderDirections, function (modifiers) {
|
|
347
|
+
return borderCss(variant, modifiers);
|
|
348
|
+
});
|
|
349
|
+
})
|
|
350
|
+
});
|
|
351
|
+
return borderObject;
|
|
266
352
|
}
|
|
267
|
-
/**
|
|
268
|
-
* `<html data-theme="dark">` のような設定を行うデフォルトのセッター
|
|
269
|
-
*/
|
|
270
|
-
|
|
271
|
-
var themeSetter = function themeSetter(attr) {
|
|
272
|
-
if (attr === void 0) {
|
|
273
|
-
attr = DEFAULT_ROOT_ATTRIBUTE;
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
return function (theme) {
|
|
277
|
-
assertKeyString(attr);
|
|
278
353
|
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
354
|
+
var createBorderRadiusCss = function createBorderRadiusCss(theme) {
|
|
355
|
+
return function (size) {
|
|
356
|
+
return createInternal({
|
|
357
|
+
toCSS: function toCSS() {
|
|
358
|
+
return {
|
|
359
|
+
borderRadius: px(theme.borderRadius[size])
|
|
360
|
+
};
|
|
361
|
+
}
|
|
362
|
+
});
|
|
284
363
|
};
|
|
285
364
|
};
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
function
|
|
291
|
-
|
|
365
|
+
function borderRadius(theme) {
|
|
366
|
+
// 角丸
|
|
367
|
+
var borderRadiusCss = createBorderRadiusCss(theme);
|
|
368
|
+
var borderRadiusObject = defineConstantProperties({}, {
|
|
369
|
+
borderRadius: function borderRadius(radius) {
|
|
370
|
+
return borderRadiusCss(radius);
|
|
371
|
+
}
|
|
372
|
+
});
|
|
373
|
+
return borderRadiusObject;
|
|
292
374
|
}
|
|
293
|
-
/**
|
|
294
|
-
* prefers-color-scheme を利用する media クエリを生成する
|
|
295
|
-
*/
|
|
296
375
|
|
|
297
|
-
|
|
298
|
-
return "@media (prefers-color-scheme: " + theme + ")";
|
|
299
|
-
}
|
|
376
|
+
var TRANSITION_DURATION = 0.2;
|
|
300
377
|
/**
|
|
301
|
-
*
|
|
378
|
+
* context の状態を元に transition を追加する。必ず一番最後に呼ぶ
|
|
302
379
|
*/
|
|
303
380
|
|
|
304
|
-
function
|
|
305
|
-
var
|
|
306
|
-
_ref$key = _ref.key,
|
|
307
|
-
key = _ref$key === void 0 ? LOCAL_STORAGE_KEY : _ref$key,
|
|
308
|
-
_ref$setter = _ref.setter,
|
|
309
|
-
setter = _ref$setter === void 0 ? themeSetter() : _ref$setter;
|
|
310
|
-
|
|
311
|
-
var _useTheme = useTheme(key),
|
|
312
|
-
theme = _useTheme[0],
|
|
313
|
-
system = _useTheme[2];
|
|
381
|
+
function transition(_theme) {
|
|
382
|
+
var duration = dur(TRANSITION_DURATION);
|
|
314
383
|
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
384
|
+
var transition = function transition(property) {
|
|
385
|
+
return {
|
|
386
|
+
transition: property.map(function (v) {
|
|
387
|
+
return duration + " " + v;
|
|
388
|
+
}).join(', ')
|
|
389
|
+
};
|
|
390
|
+
};
|
|
319
391
|
|
|
392
|
+
function toCSS(_ref) {
|
|
393
|
+
var _ref$colorTransition = _ref.colorTransition,
|
|
394
|
+
colorTransition = _ref$colorTransition === void 0 ? false : _ref$colorTransition,
|
|
395
|
+
_ref$backgroundColorT = _ref.backgroundColorTransition,
|
|
396
|
+
backgroundColorTransition = _ref$backgroundColorT === void 0 ? false : _ref$backgroundColorT,
|
|
397
|
+
_ref$boxShadowTransit = _ref.boxShadowTransition,
|
|
398
|
+
boxShadowTransition = _ref$boxShadowTransit === void 0 ? false : _ref$boxShadowTransit;
|
|
399
|
+
return transition([colorTransition ? 'color' : null, backgroundColorTransition ? 'background-color' : null, boxShadowTransition ? 'box-shadow' : null].filter(isPresent));
|
|
400
|
+
}
|
|
320
401
|
|
|
321
|
-
|
|
322
|
-
|
|
402
|
+
return createInternal({
|
|
403
|
+
toCSS: toCSS
|
|
404
|
+
});
|
|
323
405
|
}
|
|
324
|
-
/**
|
|
325
|
-
* 同期的にLocalStorageからテーマを取得するヘルパ
|
|
326
|
-
*/
|
|
327
|
-
|
|
328
|
-
function getThemeSync(key) {
|
|
329
|
-
if (key === void 0) {
|
|
330
|
-
key = LOCAL_STORAGE_KEY;
|
|
331
|
-
}
|
|
332
406
|
|
|
333
|
-
|
|
334
|
-
return
|
|
407
|
+
function targetProperty(target) {
|
|
408
|
+
return target === 'bg' ? 'background-color' : 'color';
|
|
335
409
|
}
|
|
336
|
-
/**
|
|
337
|
-
* LocalStorage, prefers-color-scheme からテーマの情報を取得して、現在のテーマを返すhooks
|
|
338
|
-
*
|
|
339
|
-
* `dark` `light` という名前だけは特別扱いされていて、prefers-color-schemeにマッチした場合に返ります
|
|
340
|
-
*/
|
|
341
410
|
|
|
342
|
-
var
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
411
|
+
var createColorCss = function createColorCss(_theme) {
|
|
412
|
+
return function (target, color, effects) {
|
|
413
|
+
if (effects === void 0) {
|
|
414
|
+
effects = [];
|
|
415
|
+
}
|
|
346
416
|
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
var media = isDark !== undefined ? isDark ? 'dark' : 'light' : undefined;
|
|
417
|
+
function toCSS() {
|
|
418
|
+
var _extends2;
|
|
350
419
|
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
setTheme = _useLocalStorage[1],
|
|
354
|
-
ready = _useLocalStorage[2];
|
|
420
|
+
return _extends((_extends2 = {}, _extends2[targetProperty(target)] = variable(customPropertyToken(color.toString())), _extends2), effects.filter(isSupportedEffect).reduce(function (acc, effect) {
|
|
421
|
+
var _onEffectPseudo;
|
|
355
422
|
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
423
|
+
return _extends({}, acc, onEffectPseudo(effect, (_onEffectPseudo = {}, _onEffectPseudo[targetProperty(target)] = variable(customPropertyToken(color.toString(), [effect])), _onEffectPseudo)));
|
|
424
|
+
}, {}));
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
return createInternal({
|
|
428
|
+
toCSS: toCSS,
|
|
429
|
+
context: effects.length > 0 ? target === 'font' ? {
|
|
430
|
+
colorTransition: true
|
|
431
|
+
} : {
|
|
432
|
+
backgroundColorTransition: true
|
|
433
|
+
} : {}
|
|
434
|
+
});
|
|
435
|
+
};
|
|
359
436
|
};
|
|
360
|
-
function
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
437
|
+
var createGradientColorCss = function createGradientColorCss(theme) {
|
|
438
|
+
return function (color, effects, direction) {
|
|
439
|
+
if (effects === void 0) {
|
|
440
|
+
effects = [];
|
|
441
|
+
}
|
|
364
442
|
|
|
365
|
-
|
|
366
|
-
state = _useState2[0],
|
|
367
|
-
setState = _useState2[1];
|
|
443
|
+
var toLinearGradient = gradient(direction);
|
|
368
444
|
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
useEffect(function () {
|
|
373
|
-
fetch();
|
|
374
|
-
window.addEventListener('storage', handleStorage);
|
|
375
|
-
return function () {
|
|
376
|
-
window.removeEventListener('storage', handleStorage);
|
|
377
|
-
};
|
|
378
|
-
});
|
|
379
|
-
|
|
380
|
-
var handleStorage = function handleStorage(e) {
|
|
381
|
-
if (e.storageArea !== localStorage) {
|
|
382
|
-
return;
|
|
383
|
-
}
|
|
384
|
-
|
|
385
|
-
if (e.key !== key) {
|
|
386
|
-
return;
|
|
387
|
-
}
|
|
388
|
-
|
|
389
|
-
fetch();
|
|
390
|
-
};
|
|
445
|
+
function toCSS(context) {
|
|
446
|
+
var optimized = !shouldCancelHalfLeading(context);
|
|
447
|
+
var duration = dur(TRANSITION_DURATION);
|
|
391
448
|
|
|
392
|
-
|
|
393
|
-
|
|
449
|
+
if (optimized && effects.length > 0) {
|
|
450
|
+
return _extends({
|
|
451
|
+
position: 'relative',
|
|
452
|
+
zIndex: 0,
|
|
453
|
+
overflow: 'hidden'
|
|
454
|
+
}, effects.filter(isSupportedEffect).reduce(function (acc, effect) {
|
|
455
|
+
var _theme$effect$effect;
|
|
394
456
|
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
457
|
+
return _extends({}, acc, {
|
|
458
|
+
'&::before': _extends({
|
|
459
|
+
zIndex: -1
|
|
460
|
+
}, overlayElement, {
|
|
461
|
+
transition: duration + " background-color"
|
|
462
|
+
}),
|
|
463
|
+
'&::after': _extends({
|
|
464
|
+
zIndex: -2
|
|
465
|
+
}, overlayElement, toLinearGradient(theme.gradientColor[color]))
|
|
466
|
+
}, onEffectPseudo(effect, {
|
|
467
|
+
'&::before': {
|
|
468
|
+
backgroundColor: applyEffect(null, (_theme$effect$effect = theme.effect[effect]) != null ? _theme$effect$effect : [])
|
|
469
|
+
}
|
|
470
|
+
}));
|
|
471
|
+
}, {}));
|
|
472
|
+
}
|
|
399
473
|
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
} else {
|
|
405
|
-
var raw = serialize(value);
|
|
406
|
-
localStorage.setItem(key, raw);
|
|
407
|
-
} // 同一ウィンドウではstorageイベントが発火しないので、手動で発火させる
|
|
474
|
+
warning(effects.length === 0, // eslint-disable-next-line max-len
|
|
475
|
+
"'Transition' will not be applied. You can get around this by specifying 'preserveHalfLeading' or both 'padding' and 'typograpy'.");
|
|
476
|
+
return _extends({}, toLinearGradient(theme.gradientColor[color]), effects.filter(isSupportedEffect).reduce(function (acc, effect) {
|
|
477
|
+
var _theme$effect$effect2;
|
|
408
478
|
|
|
479
|
+
return _extends({}, acc, onEffectPseudo(effect, _extends({}, toLinearGradient(applyEffectToGradient((_theme$effect$effect2 = theme.effect[effect]) != null ? _theme$effect$effect2 : [])(theme.gradientColor[color])))));
|
|
480
|
+
}, {}));
|
|
481
|
+
}
|
|
409
482
|
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
cancelable: false,
|
|
413
|
-
key: key,
|
|
414
|
-
url: location.href,
|
|
415
|
-
storageArea: localStorage
|
|
483
|
+
return createInternal({
|
|
484
|
+
toCSS: toCSS
|
|
416
485
|
});
|
|
417
|
-
dispatchEvent(event);
|
|
418
486
|
};
|
|
419
|
-
|
|
420
|
-
return [state != null ? state : defaultValueMemo, set, ready];
|
|
421
|
-
}
|
|
422
|
-
|
|
423
|
-
function deserialize(raw) {
|
|
424
|
-
try {
|
|
425
|
-
return JSON.parse(raw);
|
|
426
|
-
} catch (_unused) {
|
|
427
|
-
// syntax error はすべて文字列として扱う
|
|
428
|
-
return raw;
|
|
429
|
-
}
|
|
430
|
-
}
|
|
431
|
-
|
|
432
|
-
function serialize(value) {
|
|
433
|
-
if (typeof value === 'string') {
|
|
434
|
-
return value;
|
|
435
|
-
} else {
|
|
436
|
-
return JSON.stringify(value);
|
|
437
|
-
}
|
|
438
|
-
}
|
|
439
|
-
|
|
440
|
-
function useMedia(query) {
|
|
441
|
-
var _useState3 = useState(),
|
|
442
|
-
match = _useState3[0],
|
|
443
|
-
setState = _useState3[1];
|
|
444
|
-
|
|
445
|
-
useEffect(function () {
|
|
446
|
-
var matcher = window.matchMedia(query);
|
|
447
|
-
|
|
448
|
-
var onChange = function onChange() {
|
|
449
|
-
setState(matcher.matches);
|
|
450
|
-
};
|
|
451
|
-
|
|
452
|
-
matcher.addEventListener('change', onChange);
|
|
453
|
-
setState(matcher.matches);
|
|
454
|
-
return function () {
|
|
455
|
-
matcher.removeEventListener('change', onChange);
|
|
456
|
-
};
|
|
457
|
-
}, [query]);
|
|
458
|
-
return match;
|
|
459
|
-
}
|
|
460
|
-
|
|
461
|
-
/**
|
|
462
|
-
* 同期的にテーマをローカルストレージから取得してhtmlの属性に設定するコードを取得する
|
|
463
|
-
* @param props localStorageのキー、htmlのdataになる属性のキーを含むオブジェクト
|
|
464
|
-
* @returns ソースコードの文字列
|
|
465
|
-
*/
|
|
466
|
-
|
|
467
|
-
function makeSetThemeScriptCode(_temp) {
|
|
468
|
-
var _ref = _temp === void 0 ? defaultProps : _temp,
|
|
469
|
-
_ref$localStorageKey = _ref.localStorageKey,
|
|
470
|
-
localStorageKey = _ref$localStorageKey === void 0 ? defaultProps.localStorageKey : _ref$localStorageKey,
|
|
471
|
-
_ref$rootAttribute = _ref.rootAttribute,
|
|
472
|
-
rootAttribute = _ref$rootAttribute === void 0 ? defaultProps.rootAttribute : _ref$rootAttribute;
|
|
473
|
-
|
|
474
|
-
assertKeyString(localStorageKey);
|
|
475
|
-
assertKeyString(rootAttribute);
|
|
476
|
-
return "'use strict';\n(function () {\n var localStorageKey = '" + localStorageKey + "'\n var rootAttribute = '" + rootAttribute + "'\n var currentTheme = localStorage.getItem(localStorageKey);\n if (currentTheme) {\n document.documentElement.dataset[rootAttribute] = currentTheme;\n }\n})();\n";
|
|
477
|
-
}
|
|
478
|
-
/**
|
|
479
|
-
* 同期的にテーマをローカルストレージから取得してhtmlの属性に設定するスクリプトタグ
|
|
480
|
-
* @param props localStorageのキー、htmlのdataになる属性のキーを含むオブジェクト
|
|
481
|
-
* @returns
|
|
482
|
-
*/
|
|
483
|
-
|
|
484
|
-
function SetThemeScript(props) {
|
|
485
|
-
var src = makeSetThemeScriptCode(props);
|
|
486
|
-
return /*#__PURE__*/React.createElement("script", {
|
|
487
|
-
dangerouslySetInnerHTML: {
|
|
488
|
-
__html: src
|
|
489
|
-
}
|
|
490
|
-
});
|
|
491
|
-
}
|
|
492
|
-
var defaultProps = {
|
|
493
|
-
localStorageKey: LOCAL_STORAGE_KEY,
|
|
494
|
-
rootAttribute: DEFAULT_ROOT_ATTRIBUTE
|
|
495
487
|
};
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
*/
|
|
509
|
-
|
|
510
|
-
function builder(theme, isPhantom) {
|
|
511
|
-
if (isPhantom === void 0) {
|
|
512
|
-
isPhantom = false;
|
|
513
|
-
}
|
|
514
|
-
|
|
515
|
-
if (isPhantom) {
|
|
516
|
-
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
517
|
-
return {};
|
|
518
|
-
}
|
|
519
|
-
|
|
520
|
-
var colors = objectKeys(theme.color);
|
|
521
|
-
var effects = objectKeys(theme.effect); // 色
|
|
488
|
+
var overlayElement = {
|
|
489
|
+
content: "''",
|
|
490
|
+
display: 'block',
|
|
491
|
+
position: 'absolute',
|
|
492
|
+
width: '100%',
|
|
493
|
+
height: '100%',
|
|
494
|
+
top: 0,
|
|
495
|
+
left: 0
|
|
496
|
+
};
|
|
497
|
+
function colors(theme) {
|
|
498
|
+
var colors = keyof(theme.color);
|
|
499
|
+
var effects = keyof(theme.effect); // 色
|
|
522
500
|
|
|
523
|
-
var gradientColors =
|
|
501
|
+
var gradientColors = keyof(theme.gradientColor);
|
|
524
502
|
var colorCss = createColorCss();
|
|
525
503
|
var gradientColorCss = createGradientColorCss(theme);
|
|
526
|
-
var colorObject =
|
|
527
|
-
bg: objectAssign(
|
|
528
|
-
return
|
|
504
|
+
var colorObject = defineConstantProperties({}, {
|
|
505
|
+
bg: objectAssign(defineProperties({}, colors, function (color) {
|
|
506
|
+
return definePropertyChains(effects, function (modifiers) {
|
|
529
507
|
return colorCss('bg', color, modifiers);
|
|
530
508
|
});
|
|
531
|
-
}),
|
|
509
|
+
}), defineProperties({}, gradientColors, function (color) {
|
|
532
510
|
return function (direction) {
|
|
533
|
-
return
|
|
511
|
+
return definePropertyChains(effects, function (modifiers) {
|
|
534
512
|
return gradientColorCss(color, modifiers, direction);
|
|
535
513
|
});
|
|
536
514
|
};
|
|
537
515
|
})),
|
|
538
|
-
font:
|
|
539
|
-
return
|
|
516
|
+
font: defineProperties({}, colors, function (color) {
|
|
517
|
+
return definePropertyChains(effects, function (modifiers) {
|
|
540
518
|
return colorCss('font', color, modifiers);
|
|
541
519
|
});
|
|
542
520
|
})
|
|
543
|
-
}); // タイポグラフィ
|
|
544
|
-
|
|
545
|
-
var typographyModifiers = [// TODO
|
|
546
|
-
'monospace', 'bold', 'preserveHalfLeading'];
|
|
547
|
-
var typographyCss = createTypographyCss(theme);
|
|
548
|
-
var typographyObject = factory({}, ['typography'], function (_) {
|
|
549
|
-
return function (size) {
|
|
550
|
-
return modifiedFactory(typographyModifiers, function (modifiers) {
|
|
551
|
-
return typographyCss(size, {
|
|
552
|
-
preserveHalfLeading: modifiers.includes('preserveHalfLeading'),
|
|
553
|
-
monospace: modifiers.includes('monospace'),
|
|
554
|
-
bold: modifiers.includes('bold')
|
|
555
|
-
});
|
|
556
|
-
});
|
|
557
|
-
};
|
|
558
|
-
}); // スペーシング
|
|
559
|
-
|
|
560
|
-
var spacingCss = createSpacingCss(theme);
|
|
561
|
-
var spacingObject = factory({}, spacingProperties, function (spacingProperty) {
|
|
562
|
-
return modifiedArgumentedFactory(spacingDirections, function (modifiers) {
|
|
563
|
-
return spacingCss(spacingProperty, modifiers);
|
|
564
|
-
});
|
|
565
|
-
}); // 大きさ
|
|
566
|
-
|
|
567
|
-
var fixedPxCss = createFixedPxCss(theme);
|
|
568
|
-
var fixedColumnCss = createFixedColumnCss(theme);
|
|
569
|
-
var fixedRelativeCss = createFixedRelativeCss();
|
|
570
|
-
var fixedObject = factory({}, fixedProperties, function (property) {
|
|
571
|
-
return constFactory({}, {
|
|
572
|
-
px: function px(size) {
|
|
573
|
-
return fixedPxCss(property, size);
|
|
574
|
-
},
|
|
575
|
-
column: function column(span) {
|
|
576
|
-
return fixedColumnCss(property, span);
|
|
577
|
-
},
|
|
578
|
-
auto: fixedRelativeCss(property, 'auto'),
|
|
579
|
-
full: fixedRelativeCss(property, '100%')
|
|
580
|
-
});
|
|
581
|
-
}); // 要素へのエフェクト (etc: 透過)
|
|
582
|
-
|
|
583
|
-
var elementEffectCss = createElementEffectCss(theme);
|
|
584
|
-
var elementEffectObject = modifiedFactory(objectKeys(theme.elementEffect), function (modifiers) {
|
|
585
|
-
return elementEffectCss(modifiers);
|
|
586
|
-
}); // ボーダー
|
|
587
|
-
|
|
588
|
-
var borderCss = createBorderCss(theme);
|
|
589
|
-
var borderObject = constFactory({}, {
|
|
590
|
-
border: factory({}, objectKeys(theme.border), function (variant) {
|
|
591
|
-
return modifiedFactory(borderDirections, function (modifiers) {
|
|
592
|
-
return borderCss(variant, modifiers);
|
|
593
|
-
});
|
|
594
|
-
})
|
|
595
|
-
}); // 角丸
|
|
596
|
-
|
|
597
|
-
var borderRadiusCss = createBorderRadiusCss(theme);
|
|
598
|
-
var borderRadiusObject = constFactory({}, {
|
|
599
|
-
borderRadius: function borderRadius(radius) {
|
|
600
|
-
return borderRadiusCss(radius);
|
|
601
|
-
}
|
|
602
|
-
}); // アウトライン
|
|
603
|
-
|
|
604
|
-
var outlineCss = createOutlineColorCss(theme);
|
|
605
|
-
var outlineObject = constFactory({}, {
|
|
606
|
-
outline: factory({}, objectKeys(theme.outline), function (variant) {
|
|
607
|
-
return modifiedFactory(outlineType, function (modifiers) {
|
|
608
|
-
return outlineCss(variant, modifiers);
|
|
609
|
-
});
|
|
610
|
-
})
|
|
611
521
|
});
|
|
612
|
-
return
|
|
613
|
-
}
|
|
614
|
-
|
|
615
|
-
function targetProperty(target) {
|
|
616
|
-
return target === 'bg' ? 'background-color' : 'color';
|
|
617
|
-
}
|
|
618
|
-
|
|
619
|
-
function isSupportedEffect(effect) {
|
|
620
|
-
return ['hover', 'press', 'disabled'].includes(effect);
|
|
621
|
-
}
|
|
622
|
-
|
|
623
|
-
function onEffectPseudo(effect, css) {
|
|
624
|
-
var _hover, _active, _ref;
|
|
625
|
-
|
|
626
|
-
return effect === 'hover' ? {
|
|
627
|
-
'&:hover': (_hover = {}, _hover[notDisabledSelector] = css, _hover)
|
|
628
|
-
} : effect === 'press' ? {
|
|
629
|
-
'&:active': (_active = {}, _active[notDisabledSelector] = css, _active)
|
|
630
|
-
} : // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
631
|
-
effect === 'disabled' ? (_ref = {}, _ref[disabledSelector] = css, _ref) : unreachable(effect);
|
|
522
|
+
return colorObject;
|
|
632
523
|
}
|
|
633
524
|
|
|
634
|
-
var
|
|
635
|
-
return function (
|
|
525
|
+
var createElementEffectCss = function createElementEffectCss(theme) {
|
|
526
|
+
return function (effects) {
|
|
636
527
|
if (effects === void 0) {
|
|
637
528
|
effects = [];
|
|
638
529
|
}
|
|
639
530
|
|
|
640
|
-
return
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
var _onEffectPseudo;
|
|
531
|
+
return createInternal({
|
|
532
|
+
toCSS: function toCSS() {
|
|
533
|
+
return effects.filter(isSupportedEffect).reduce(function (acc, effect) {
|
|
534
|
+
var _theme$elementEffect$, _theme$elementEffect$2;
|
|
645
535
|
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
} : {});
|
|
536
|
+
return _extends({}, acc, onEffectPseudo(effect, {
|
|
537
|
+
opacity: !Array.isArray(theme.elementEffect[effect]) && ((_theme$elementEffect$ = theme.elementEffect[effect]) == null ? void 0 : _theme$elementEffect$.type) === 'opacity' ? (_theme$elementEffect$2 = theme.elementEffect[effect]) == null ? void 0 : _theme$elementEffect$2.opacity : unreachable()
|
|
538
|
+
}));
|
|
539
|
+
}, {});
|
|
540
|
+
}
|
|
541
|
+
});
|
|
653
542
|
};
|
|
654
|
-
};
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
var TRANSITION_DURATION = 0.2;
|
|
543
|
+
};
|
|
544
|
+
function elementEffect(theme) {
|
|
545
|
+
var effectTypes = keyof(theme.elementEffect); // 要素へのエフェクト (etc: 透過)
|
|
658
546
|
|
|
659
|
-
var
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
547
|
+
var elementEffectCss = createElementEffectCss(theme);
|
|
548
|
+
var elementEffectObject = definePropertyChains(effectTypes, function (modifiers) {
|
|
549
|
+
return elementEffectCss(modifiers);
|
|
550
|
+
});
|
|
551
|
+
return elementEffectObject;
|
|
552
|
+
}
|
|
664
553
|
|
|
665
|
-
|
|
666
|
-
return internal(function (context) {
|
|
667
|
-
var optimized = !useHalfLeadingCanceller(context);
|
|
668
|
-
var duration = dur(TRANSITION_DURATION);
|
|
554
|
+
var outlineType = ['focus'];
|
|
669
555
|
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
}, effects.filter(isSupportedEffect).reduce(function (acc, effect) {
|
|
676
|
-
var _theme$effect$effect;
|
|
556
|
+
var outlineCss = function outlineCss(weight, color) {
|
|
557
|
+
return {
|
|
558
|
+
boxShadow: "0 0 0 " + px(weight) + " " + color
|
|
559
|
+
};
|
|
560
|
+
};
|
|
677
561
|
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
zIndex: -2
|
|
686
|
-
}, overlayElement, toLinearGradient(theme.gradientColor[color]))
|
|
687
|
-
}, onEffectPseudo(effect, {
|
|
688
|
-
'&::before': {
|
|
689
|
-
backgroundColor: applyEffect(null, (_theme$effect$effect = theme.effect[effect]) != null ? _theme$effect$effect : [])
|
|
690
|
-
}
|
|
691
|
-
}));
|
|
692
|
-
}, {}));
|
|
693
|
-
} else {
|
|
694
|
-
warning(effects.length === 0, // eslint-disable-next-line max-len
|
|
695
|
-
"'Transition' will not be applied. You can get around this by specifying 'preserveHalfLeading' or both 'padding' and 'typograpy'.");
|
|
696
|
-
return _extends({}, toLinearGradient(theme.gradientColor[color]), effects.filter(isSupportedEffect).reduce(function (acc, effect) {
|
|
697
|
-
var _theme$effect$effect2;
|
|
562
|
+
var createOutlineColorCss = function createOutlineColorCss(theme) {
|
|
563
|
+
return function (variant, modifiers) {
|
|
564
|
+
var weight = theme.outline[variant].weight;
|
|
565
|
+
var color = theme.outline[variant].color;
|
|
566
|
+
return createInternal({
|
|
567
|
+
toCSS: function toCSS() {
|
|
568
|
+
var _;
|
|
698
569
|
|
|
699
|
-
|
|
700
|
-
|
|
570
|
+
return modifiers.includes('focus') ? onFocus(outlineCss(weight, color)) : {
|
|
571
|
+
'&&': (_ = {}, _[notDisabledSelector] = outlineCss(weight, color), _)
|
|
572
|
+
};
|
|
573
|
+
},
|
|
574
|
+
context: {
|
|
575
|
+
boxShadowTransition: true
|
|
701
576
|
}
|
|
702
577
|
});
|
|
703
578
|
};
|
|
@@ -706,11 +581,10 @@ var createGradientColorCss = function createGradientColorCss(theme) {
|
|
|
706
581
|
* @see https://developer.mozilla.org/ja/docs/Web/CSS/:focus-visible#selectively_showing_the_focus_indicator
|
|
707
582
|
*/
|
|
708
583
|
|
|
709
|
-
|
|
710
584
|
var onFocus = function onFocus(css) {
|
|
711
|
-
var
|
|
585
|
+
var _ref;
|
|
712
586
|
|
|
713
|
-
return
|
|
587
|
+
return _ref = {}, _ref[notDisabledSelector] = {
|
|
714
588
|
'&:focus, &:active': _extends({
|
|
715
589
|
outline: 'none'
|
|
716
590
|
}, css),
|
|
@@ -720,48 +594,136 @@ var onFocus = function onFocus(css) {
|
|
|
720
594
|
'&:focus-visible': _extends({
|
|
721
595
|
outline: 'none'
|
|
722
596
|
}, css)
|
|
723
|
-
},
|
|
597
|
+
}, _ref;
|
|
724
598
|
};
|
|
725
599
|
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
600
|
+
function outline(theme) {
|
|
601
|
+
var outlineCss = createOutlineColorCss(theme);
|
|
602
|
+
var outlineObject = defineConstantProperties({}, {
|
|
603
|
+
outline: defineProperties({}, keyof(theme.outline), function (variant) {
|
|
604
|
+
return definePropertyChains(outlineType, function (modifiers) {
|
|
605
|
+
return outlineCss(variant, modifiers);
|
|
606
|
+
});
|
|
607
|
+
})
|
|
608
|
+
});
|
|
609
|
+
return outlineObject;
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
var fixedProperties = ['width', 'height'];
|
|
613
|
+
var createFixedPxCss = function createFixedPxCss(theme) {
|
|
614
|
+
return function (property, size) {
|
|
615
|
+
return createInternal({
|
|
616
|
+
toCSS: function toCSS() {
|
|
617
|
+
var _ref;
|
|
618
|
+
|
|
619
|
+
return _ref = {}, _ref[property] = size === 'auto' ? 'auto' : px(theme.spacing[size]), _ref;
|
|
620
|
+
}
|
|
621
|
+
});
|
|
729
622
|
};
|
|
730
623
|
};
|
|
624
|
+
var createFixedRelativeCss = function createFixedRelativeCss(_theme) {
|
|
625
|
+
return function (property, amount) {
|
|
626
|
+
return createInternal({
|
|
627
|
+
toCSS: function toCSS() {
|
|
628
|
+
var _ref2;
|
|
731
629
|
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
630
|
+
return _ref2 = {}, _ref2[property] = amount, _ref2;
|
|
631
|
+
}
|
|
632
|
+
});
|
|
633
|
+
};
|
|
634
|
+
};
|
|
635
|
+
var createFixedColumnCss = function createFixedColumnCss(theme) {
|
|
636
|
+
return function (property, span) {
|
|
637
|
+
return createInternal({
|
|
638
|
+
toCSS: function toCSS() {
|
|
639
|
+
var _ref3;
|
|
738
640
|
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
};
|
|
742
|
-
}, {
|
|
743
|
-
boxShadowTransition: true
|
|
641
|
+
return _ref3 = {}, _ref3[property] = px(columnSystem(span, theme.grid.unit.column, theme.grid.unit.gutter)), _ref3;
|
|
642
|
+
}
|
|
744
643
|
});
|
|
745
644
|
};
|
|
746
645
|
};
|
|
646
|
+
function size(theme) {
|
|
647
|
+
var fixedPxCss = createFixedPxCss(theme);
|
|
648
|
+
var fixedColumnCss = createFixedColumnCss(theme);
|
|
649
|
+
var fixedRelativeCss = createFixedRelativeCss();
|
|
650
|
+
var fixedObject = defineProperties({}, fixedProperties, function (property) {
|
|
651
|
+
return defineConstantProperties({}, {
|
|
652
|
+
px: function px(size) {
|
|
653
|
+
return fixedPxCss(property, size);
|
|
654
|
+
},
|
|
655
|
+
column: function column(span) {
|
|
656
|
+
return fixedColumnCss(property, span);
|
|
657
|
+
},
|
|
658
|
+
auto: fixedRelativeCss(property, 'auto'),
|
|
659
|
+
full: fixedRelativeCss(property, '100%')
|
|
660
|
+
});
|
|
661
|
+
});
|
|
662
|
+
return fixedObject;
|
|
663
|
+
}
|
|
747
664
|
|
|
748
|
-
var
|
|
749
|
-
|
|
750
|
-
display: 'block',
|
|
751
|
-
position: 'absolute',
|
|
752
|
-
width: '100%',
|
|
753
|
-
height: '100%',
|
|
754
|
-
top: 0,
|
|
755
|
-
left: 0
|
|
756
|
-
}; // half-leadingをキャンセルするとき && 垂直方向のpaddingが無い時
|
|
757
|
-
// -> before/afterを入れる
|
|
665
|
+
var spacingProperties = ['margin', 'padding'];
|
|
666
|
+
var spacingDirections = ['top', 'right', 'bottom', 'left', 'vertical', 'horizontal', 'all'];
|
|
758
667
|
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
668
|
+
function spacingProperty(property, direction) {
|
|
669
|
+
return property + "-" + direction;
|
|
670
|
+
}
|
|
671
|
+
|
|
672
|
+
var createSpacingCss = function createSpacingCss(theme) {
|
|
673
|
+
return function (property, modifiers) {
|
|
674
|
+
var _modifiers$reduce = modifiers.reduce(function (acc, _ref) {
|
|
675
|
+
var direction = _ref[0],
|
|
676
|
+
size = _ref[1];
|
|
677
|
+
|
|
678
|
+
if (direction === 'all') {
|
|
679
|
+
acc.top = size;
|
|
680
|
+
acc.right = size;
|
|
681
|
+
acc.bottom = size;
|
|
682
|
+
acc.left = size;
|
|
683
|
+
} else if (direction === 'vertical') {
|
|
684
|
+
acc.top = size;
|
|
685
|
+
acc.bottom = size;
|
|
686
|
+
} else if (direction === 'horizontal') {
|
|
687
|
+
acc.right = size;
|
|
688
|
+
acc.left = size;
|
|
689
|
+
} else {
|
|
690
|
+
acc[direction] = size;
|
|
691
|
+
}
|
|
692
|
+
|
|
693
|
+
return acc;
|
|
694
|
+
}, {}),
|
|
695
|
+
top = _modifiers$reduce.top,
|
|
696
|
+
right = _modifiers$reduce.right,
|
|
697
|
+
bottom = _modifiers$reduce.bottom,
|
|
698
|
+
left = _modifiers$reduce.left;
|
|
699
|
+
|
|
700
|
+
var hasVerticalPadding = property === 'padding' && top !== undefined && bottom !== undefined && top !== 'auto' && bottom !== 'auto';
|
|
701
|
+
|
|
702
|
+
function toCSS(_ref2) {
|
|
703
|
+
var _ref3, _ref4, _ref5, _ref6;
|
|
704
|
+
|
|
705
|
+
var _ref2$cancelHalfLeadi = _ref2.cancelHalfLeadingPx,
|
|
706
|
+
cancelHalfLeadingPx = _ref2$cancelHalfLeadi === void 0 ? 0 : _ref2$cancelHalfLeadi;
|
|
707
|
+
return _extends({}, top !== undefined && (_ref3 = {}, _ref3[spacingProperty(property, 'top')] = top === 'auto' ? 'auto' : px(theme.spacing[top] + (hasVerticalPadding ? cancelHalfLeadingPx : 0)), _ref3), bottom !== undefined && (_ref4 = {}, _ref4[spacingProperty(property, 'bottom')] = bottom === 'auto' ? 'auto' : px(theme.spacing[bottom] + (hasVerticalPadding ? cancelHalfLeadingPx : 0)), _ref4), right !== undefined && (_ref5 = {}, _ref5[spacingProperty(property, 'right')] = right === 'auto' ? 'auto' : px(theme.spacing[right]), _ref5), left !== undefined && (_ref6 = {}, _ref6[spacingProperty(property, 'left')] = left === 'auto' ? 'auto' : px(theme.spacing[left]), _ref6));
|
|
708
|
+
}
|
|
709
|
+
|
|
710
|
+
return createInternal({
|
|
711
|
+
toCSS: toCSS,
|
|
712
|
+
context: hasVerticalPadding ? {
|
|
713
|
+
hasVerticalPadding: true
|
|
714
|
+
} : {}
|
|
715
|
+
});
|
|
716
|
+
};
|
|
764
717
|
};
|
|
718
|
+
function spacing(theme) {
|
|
719
|
+
var spacingCss = createSpacingCss(theme);
|
|
720
|
+
var spacingObject = defineProperties({}, spacingProperties, function (spacingProperty) {
|
|
721
|
+
return defineMethodChains(spacingDirections, function (modifiers) {
|
|
722
|
+
return spacingCss(spacingProperty, modifiers);
|
|
723
|
+
});
|
|
724
|
+
});
|
|
725
|
+
return spacingObject;
|
|
726
|
+
}
|
|
765
727
|
|
|
766
728
|
var createTypographyCss = function createTypographyCss(theme) {
|
|
767
729
|
return function (size, options) {
|
|
@@ -778,7 +740,8 @@ var createTypographyCss = function createTypographyCss(theme) {
|
|
|
778
740
|
bold = _options$bold === void 0 ? false : _options$bold;
|
|
779
741
|
var descriptor = theme.typography.size[size];
|
|
780
742
|
var margin = -halfLeading(descriptor);
|
|
781
|
-
|
|
743
|
+
|
|
744
|
+
function toCSS(context) {
|
|
782
745
|
return _extends({
|
|
783
746
|
fontSize: px(descriptor.fontSize),
|
|
784
747
|
lineHeight: px(descriptor.lineHeight)
|
|
@@ -786,7 +749,7 @@ var createTypographyCss = function createTypographyCss(theme) {
|
|
|
786
749
|
fontFamily: 'monospace'
|
|
787
750
|
}, bold && {
|
|
788
751
|
fontWeight: 'bold'
|
|
789
|
-
},
|
|
752
|
+
}, shouldCancelHalfLeading(context) && {
|
|
790
753
|
// prevent margin collapsing
|
|
791
754
|
display: 'flow-root',
|
|
792
755
|
// cancel half-leading with negative margin
|
|
@@ -797,182 +760,337 @@ var createTypographyCss = function createTypographyCss(theme) {
|
|
|
797
760
|
marginBottom: px(margin)
|
|
798
761
|
})
|
|
799
762
|
});
|
|
800
|
-
}
|
|
801
|
-
|
|
802
|
-
|
|
763
|
+
}
|
|
764
|
+
|
|
765
|
+
return createInternal({
|
|
766
|
+
toCSS: toCSS,
|
|
767
|
+
context: !preserveHalfLeading ? {
|
|
768
|
+
cancelHalfLeadingPx: margin
|
|
769
|
+
} : {}
|
|
770
|
+
});
|
|
803
771
|
};
|
|
804
772
|
};
|
|
773
|
+
var leadingCancel = {
|
|
774
|
+
display: 'block',
|
|
775
|
+
width: 0,
|
|
776
|
+
height: 0,
|
|
777
|
+
content: "''"
|
|
778
|
+
}; // タイポグラフィ
|
|
779
|
+
|
|
780
|
+
var typographyModifiers = [// TODO
|
|
781
|
+
'monospace', 'bold', 'preserveHalfLeading'];
|
|
782
|
+
function typography(theme) {
|
|
783
|
+
var typographyCss = createTypographyCss(theme);
|
|
784
|
+
var typographyObject = defineProperties({}, ['typography'], function (_) {
|
|
785
|
+
return function (size) {
|
|
786
|
+
return definePropertyChains(typographyModifiers, function (modifiers) {
|
|
787
|
+
return typographyCss(size, {
|
|
788
|
+
preserveHalfLeading: modifiers.includes('preserveHalfLeading'),
|
|
789
|
+
monospace: modifiers.includes('monospace'),
|
|
790
|
+
bold: modifiers.includes('bold')
|
|
791
|
+
});
|
|
792
|
+
});
|
|
793
|
+
};
|
|
794
|
+
});
|
|
795
|
+
return typographyObject;
|
|
796
|
+
}
|
|
797
|
+
|
|
798
|
+
/**
|
|
799
|
+
* `theme(o => [...])` の `o` の部分を構築する
|
|
800
|
+
*
|
|
801
|
+
* @param theme テーマオブジェクト
|
|
802
|
+
* @param DO_NOTHING_IT_IS_JUST_CALLED_FOR_TYPE_INFERENCE 型推論のためだけに使う場合にランタイムコストをゼロにするフラグ
|
|
803
|
+
*/
|
|
804
|
+
|
|
805
|
+
function createO(theme, DO_NOTHING_IT_IS_JUST_CALLED_FOR_TYPE_INFERENCE) {
|
|
806
|
+
if (DO_NOTHING_IT_IS_JUST_CALLED_FOR_TYPE_INFERENCE === void 0) {
|
|
807
|
+
DO_NOTHING_IT_IS_JUST_CALLED_FOR_TYPE_INFERENCE = false;
|
|
808
|
+
}
|
|
809
|
+
|
|
810
|
+
if (DO_NOTHING_IT_IS_JUST_CALLED_FOR_TYPE_INFERENCE) {
|
|
811
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
812
|
+
return {};
|
|
813
|
+
}
|
|
814
|
+
|
|
815
|
+
return objectAssign(colors(theme), typography(theme), spacing(theme), size(theme), elementEffect(theme), border(theme), borderRadius(theme), outline(theme));
|
|
816
|
+
}
|
|
817
|
+
|
|
818
|
+
var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5;
|
|
819
|
+
var GlobalStyle = createGlobalStyle(_templateObject || (_templateObject = _taggedTemplateLiteralLoose(["\n ", "\n"])), function (_ref) {
|
|
820
|
+
var themeMap = _ref.themeMap,
|
|
821
|
+
background = _ref.background;
|
|
822
|
+
return Object.entries(themeMap).map(function (_ref2) {
|
|
823
|
+
var key = _ref2[0],
|
|
824
|
+
theme = _ref2[1];
|
|
825
|
+
return key.startsWith('@media') ? css(_templateObject2 || (_templateObject2 = _taggedTemplateLiteralLoose(["\n ", " {\n :root {\n ", "\n ", "\n }\n }\n "])), key, background !== undefined && css(_templateObject3 || (_templateObject3 = _taggedTemplateLiteralLoose(["\n background-color: ", ";\n "])), theme.color[background]), defineColorVariableCSS(theme)) : css(_templateObject4 || (_templateObject4 = _taggedTemplateLiteralLoose(["\n /* stylelint-disable-next-line no-duplicate-selectors */\n ", " {\n ", "\n ", "\n }\n "])), key, background !== undefined && css(_templateObject5 || (_templateObject5 = _taggedTemplateLiteralLoose(["\n background-color: ", ";\n "])), theme.color[background]), defineColorVariableCSS(theme));
|
|
826
|
+
});
|
|
827
|
+
});
|
|
828
|
+
function TokenInjector(_ref3) {
|
|
829
|
+
var themeMap = _ref3.theme,
|
|
830
|
+
background = _ref3.background;
|
|
831
|
+
return /*#__PURE__*/React.createElement(GlobalStyle, {
|
|
832
|
+
themeMap: themeMap,
|
|
833
|
+
background: background
|
|
834
|
+
});
|
|
835
|
+
}
|
|
836
|
+
|
|
837
|
+
var defineColorVariableCSS = function defineColorVariableCSS(theme) {
|
|
838
|
+
return Object.entries(defineThemeVariables(theme.color)({
|
|
839
|
+
theme: theme
|
|
840
|
+
})).map(function (_ref4) {
|
|
841
|
+
var varName = _ref4[0],
|
|
842
|
+
value = _ref4[1];
|
|
843
|
+
return variableDefinition(varName, value.toString());
|
|
844
|
+
}).join(';');
|
|
845
|
+
};
|
|
846
|
+
|
|
847
|
+
var variableDefinition = function variableDefinition(prop, value) {
|
|
848
|
+
return prop + ": " + value;
|
|
849
|
+
};
|
|
850
|
+
|
|
851
|
+
var LOCAL_STORAGE_KEY = 'charcoal-theme';
|
|
852
|
+
var DEFAULT_ROOT_ATTRIBUTE = 'theme';
|
|
853
|
+
var keyStringRegExp = new RegExp(/^(\w|-)+$/);
|
|
854
|
+
/**
|
|
855
|
+
* 文字列が英数字_-のみで構成されているか検証する。不正な文字列ならエラーを投げる
|
|
856
|
+
* @param key 検証するキー
|
|
857
|
+
*/
|
|
858
|
+
|
|
859
|
+
function assertKeyString(key) {
|
|
860
|
+
if (!keyStringRegExp.test(key)) {
|
|
861
|
+
throw new Error("Unexpected key :" + key + ", expect: /^(\\w|-)+$/");
|
|
862
|
+
}
|
|
863
|
+
}
|
|
864
|
+
/**
|
|
865
|
+
* `<html data-theme="dark">` のような設定を行うデフォルトのセッター
|
|
866
|
+
*/
|
|
867
|
+
|
|
868
|
+
var themeSetter = function themeSetter(attr) {
|
|
869
|
+
if (attr === void 0) {
|
|
870
|
+
attr = DEFAULT_ROOT_ATTRIBUTE;
|
|
871
|
+
}
|
|
872
|
+
|
|
873
|
+
return function (theme) {
|
|
874
|
+
assertKeyString(attr);
|
|
875
|
+
|
|
876
|
+
if (theme !== undefined) {
|
|
877
|
+
document.documentElement.dataset[attr] = theme;
|
|
878
|
+
} else {
|
|
879
|
+
delete document.documentElement.dataset[attr];
|
|
880
|
+
}
|
|
881
|
+
};
|
|
882
|
+
};
|
|
883
|
+
/**
|
|
884
|
+
* `<html data-theme="dark">` にマッチするセレクタを生成する
|
|
885
|
+
*/
|
|
886
|
+
|
|
887
|
+
function themeSelector(theme, attr) {
|
|
888
|
+
return ":root[data-" + (attr != null ? attr : DEFAULT_ROOT_ATTRIBUTE) + "='" + theme + "']";
|
|
889
|
+
}
|
|
890
|
+
/**
|
|
891
|
+
* prefers-color-scheme を利用する media クエリを生成する
|
|
892
|
+
*/
|
|
805
893
|
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
894
|
+
function prefersColorScheme(theme) {
|
|
895
|
+
return "@media (prefers-color-scheme: " + theme + ")";
|
|
896
|
+
}
|
|
897
|
+
/**
|
|
898
|
+
* LocalStorageからテーマの情報を取得して、変化時にテーマをセットするhooks
|
|
899
|
+
*/
|
|
812
900
|
|
|
813
|
-
function
|
|
814
|
-
|
|
901
|
+
function useThemeSetter(_temp) {
|
|
902
|
+
var _ref = _temp === void 0 ? {} : _temp,
|
|
903
|
+
_ref$key = _ref.key,
|
|
904
|
+
key = _ref$key === void 0 ? LOCAL_STORAGE_KEY : _ref$key,
|
|
905
|
+
_ref$setter = _ref.setter,
|
|
906
|
+
setter = _ref$setter === void 0 ? themeSetter() : _ref$setter;
|
|
907
|
+
|
|
908
|
+
var _useTheme = useTheme(key),
|
|
909
|
+
theme = _useTheme[0],
|
|
910
|
+
system = _useTheme[2];
|
|
911
|
+
|
|
912
|
+
useEffect(function () {
|
|
913
|
+
if (theme === undefined) {
|
|
914
|
+
return;
|
|
915
|
+
} // prefers-color-scheme から値を取っている場合にはcssのみで処理したいのでアンセットする
|
|
916
|
+
|
|
917
|
+
|
|
918
|
+
setter(system ? undefined : theme);
|
|
919
|
+
}, [setter, system, theme]);
|
|
815
920
|
}
|
|
921
|
+
/**
|
|
922
|
+
* 同期的にLocalStorageからテーマを取得するヘルパ
|
|
923
|
+
*/
|
|
816
924
|
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
size = _ref4[1];
|
|
925
|
+
function getThemeSync(key) {
|
|
926
|
+
if (key === void 0) {
|
|
927
|
+
key = LOCAL_STORAGE_KEY;
|
|
928
|
+
}
|
|
822
929
|
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
} else if (direction === 'horizontal') {
|
|
832
|
-
acc.right = size;
|
|
833
|
-
acc.left = size;
|
|
834
|
-
} else {
|
|
835
|
-
acc[direction] = size;
|
|
836
|
-
}
|
|
930
|
+
var theme = localStorage.getItem(key);
|
|
931
|
+
return theme;
|
|
932
|
+
}
|
|
933
|
+
/**
|
|
934
|
+
* LocalStorage, prefers-color-scheme からテーマの情報を取得して、現在のテーマを返すhooks
|
|
935
|
+
*
|
|
936
|
+
* `dark` `light` という名前だけは特別扱いされていて、prefers-color-schemeにマッチした場合に返ります
|
|
937
|
+
*/
|
|
837
938
|
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
bottom = _modifiers$reduce.bottom,
|
|
843
|
-
left = _modifiers$reduce.left;
|
|
939
|
+
var useTheme = function useTheme(key) {
|
|
940
|
+
if (key === void 0) {
|
|
941
|
+
key = LOCAL_STORAGE_KEY;
|
|
942
|
+
}
|
|
844
943
|
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
var _ref5$cancelHalfLeadi = _ref5.cancelHalfLeadingPx,
|
|
850
|
-
cancelHalfLeadingPx = _ref5$cancelHalfLeadi === void 0 ? 0 : _ref5$cancelHalfLeadi;
|
|
851
|
-
return _extends({}, top !== undefined && (_ref6 = {}, _ref6[spacingProperty(property, 'top')] = top === 'auto' ? 'auto' : px(theme.spacing[top] + (hasVerticalPadding ? cancelHalfLeadingPx : 0)), _ref6), bottom !== undefined && (_ref7 = {}, _ref7[spacingProperty(property, 'bottom')] = bottom === 'auto' ? 'auto' : px(theme.spacing[bottom] + (hasVerticalPadding ? cancelHalfLeadingPx : 0)), _ref7), right !== undefined && (_ref8 = {}, _ref8[spacingProperty(property, 'right')] = right === 'auto' ? 'auto' : px(theme.spacing[right]), _ref8), left !== undefined && (_ref9 = {}, _ref9[spacingProperty(property, 'left')] = left === 'auto' ? 'auto' : px(theme.spacing[left]), _ref9));
|
|
852
|
-
}, hasVerticalPadding ? {
|
|
853
|
-
hasVerticalPadding: true
|
|
854
|
-
} : {});
|
|
855
|
-
};
|
|
856
|
-
};
|
|
944
|
+
assertKeyString(key);
|
|
945
|
+
var isDark = useMedia('(prefers-color-scheme: dark)');
|
|
946
|
+
var media = isDark !== undefined ? isDark ? 'dark' : 'light' : undefined;
|
|
857
947
|
|
|
858
|
-
var
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
948
|
+
var _useLocalStorage = useLocalStorage(key),
|
|
949
|
+
local = _useLocalStorage[0],
|
|
950
|
+
setTheme = _useLocalStorage[1],
|
|
951
|
+
ready = _useLocalStorage[2];
|
|
862
952
|
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
953
|
+
var theme = !ready || media === undefined ? undefined : local != null ? local : media;
|
|
954
|
+
var system = local === undefined;
|
|
955
|
+
return [theme, setTheme, system];
|
|
866
956
|
};
|
|
957
|
+
function useLocalStorage(key, defaultValue) {
|
|
958
|
+
var _useState = useState(false),
|
|
959
|
+
ready = _useState[0],
|
|
960
|
+
setReady = _useState[1];
|
|
867
961
|
|
|
868
|
-
var
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
var _ref11;
|
|
962
|
+
var _useState2 = useState(),
|
|
963
|
+
state = _useState2[0],
|
|
964
|
+
setState = _useState2[1];
|
|
872
965
|
|
|
873
|
-
|
|
874
|
-
|
|
966
|
+
var defaultValueMemo = useMemo(function () {
|
|
967
|
+
return defaultValue == null ? void 0 : defaultValue();
|
|
968
|
+
}, [defaultValue]);
|
|
969
|
+
useEffect(function () {
|
|
970
|
+
fetch();
|
|
971
|
+
window.addEventListener('storage', handleStorage);
|
|
972
|
+
return function () {
|
|
973
|
+
window.removeEventListener('storage', handleStorage);
|
|
974
|
+
};
|
|
975
|
+
});
|
|
976
|
+
|
|
977
|
+
var handleStorage = function handleStorage(e) {
|
|
978
|
+
if (e.storageArea !== localStorage) {
|
|
979
|
+
return;
|
|
980
|
+
}
|
|
981
|
+
|
|
982
|
+
if (e.key !== key) {
|
|
983
|
+
return;
|
|
984
|
+
}
|
|
985
|
+
|
|
986
|
+
fetch();
|
|
875
987
|
};
|
|
876
|
-
};
|
|
877
988
|
|
|
878
|
-
var
|
|
879
|
-
|
|
880
|
-
return internal(function () {
|
|
881
|
-
var _ref12;
|
|
989
|
+
var fetch = function fetch() {
|
|
990
|
+
var _ref2;
|
|
882
991
|
|
|
883
|
-
|
|
884
|
-
|
|
992
|
+
var raw = localStorage.getItem(key);
|
|
993
|
+
setState((_ref2 = raw !== null ? deserialize(raw) : null) != null ? _ref2 : defaultValueMemo);
|
|
994
|
+
setReady(true);
|
|
885
995
|
};
|
|
886
|
-
};
|
|
887
996
|
|
|
888
|
-
var
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
}
|
|
997
|
+
var set = function set(value) {
|
|
998
|
+
if (value === undefined) {
|
|
999
|
+
// undefinedがセットされる場合にはkeyごと削除
|
|
1000
|
+
localStorage.removeItem(key);
|
|
1001
|
+
} else {
|
|
1002
|
+
var raw = serialize(value);
|
|
1003
|
+
localStorage.setItem(key, raw);
|
|
1004
|
+
} // 同一ウィンドウではstorageイベントが発火しないので、手動で発火させる
|
|
893
1005
|
|
|
894
|
-
return internal(function () {
|
|
895
|
-
return effects.filter(isSupportedEffect).reduce(function (acc, effect) {
|
|
896
|
-
var _theme$elementEffect$, _theme$elementEffect$2;
|
|
897
1006
|
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
1007
|
+
var event = new StorageEvent('storage', {
|
|
1008
|
+
bubbles: true,
|
|
1009
|
+
cancelable: false,
|
|
1010
|
+
key: key,
|
|
1011
|
+
url: location.href,
|
|
1012
|
+
storageArea: localStorage
|
|
902
1013
|
});
|
|
1014
|
+
dispatchEvent(event);
|
|
903
1015
|
};
|
|
904
|
-
};
|
|
905
1016
|
|
|
906
|
-
|
|
907
|
-
return "border-" + direction;
|
|
1017
|
+
return [state != null ? state : defaultValueMemo, set, ready];
|
|
908
1018
|
}
|
|
909
1019
|
|
|
910
|
-
function
|
|
911
|
-
|
|
1020
|
+
function deserialize(raw) {
|
|
1021
|
+
try {
|
|
1022
|
+
return JSON.parse(raw);
|
|
1023
|
+
} catch (_unused) {
|
|
1024
|
+
// syntax error はすべて文字列として扱う
|
|
1025
|
+
return raw;
|
|
1026
|
+
}
|
|
912
1027
|
}
|
|
913
1028
|
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
return
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
} : directions.reduce(function (acc, direction) {
|
|
922
|
-
var _extends3;
|
|
923
|
-
|
|
924
|
-
return _extends({}, acc, (_extends3 = {}, _extends3[borderProperty(direction)] = value, _extends3));
|
|
925
|
-
}, {}));
|
|
926
|
-
});
|
|
927
|
-
};
|
|
928
|
-
};
|
|
1029
|
+
function serialize(value) {
|
|
1030
|
+
if (typeof value === 'string') {
|
|
1031
|
+
return value;
|
|
1032
|
+
} else {
|
|
1033
|
+
return JSON.stringify(value);
|
|
1034
|
+
}
|
|
1035
|
+
}
|
|
929
1036
|
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
borderRadius: px(theme.borderRadius[size])
|
|
935
|
-
};
|
|
936
|
-
});
|
|
937
|
-
};
|
|
938
|
-
};
|
|
1037
|
+
function useMedia(query) {
|
|
1038
|
+
var _useState3 = useState(),
|
|
1039
|
+
match = _useState3[0],
|
|
1040
|
+
setState = _useState3[1];
|
|
939
1041
|
|
|
940
|
-
|
|
941
|
-
|
|
1042
|
+
useEffect(function () {
|
|
1043
|
+
var matcher = window.matchMedia(query);
|
|
942
1044
|
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
transition: property.map(function (v) {
|
|
946
|
-
return duration + " " + v;
|
|
947
|
-
}).join(', ')
|
|
1045
|
+
var onChange = function onChange() {
|
|
1046
|
+
setState(matcher.matches);
|
|
948
1047
|
};
|
|
949
|
-
};
|
|
950
1048
|
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
});
|
|
960
|
-
};
|
|
1049
|
+
matcher.addEventListener('change', onChange);
|
|
1050
|
+
setState(matcher.matches);
|
|
1051
|
+
return function () {
|
|
1052
|
+
matcher.removeEventListener('change', onChange);
|
|
1053
|
+
};
|
|
1054
|
+
}, [query]);
|
|
1055
|
+
return match;
|
|
1056
|
+
}
|
|
961
1057
|
|
|
962
|
-
|
|
1058
|
+
/**
|
|
1059
|
+
* 同期的にテーマをローカルストレージから取得してhtmlの属性に設定するコードを取得する
|
|
1060
|
+
* @param props localStorageのキー、htmlのdataになる属性のキーを含むオブジェクト
|
|
1061
|
+
* @returns ソースコードの文字列
|
|
1062
|
+
*/
|
|
963
1063
|
|
|
964
|
-
function
|
|
965
|
-
var
|
|
1064
|
+
function makeSetThemeScriptCode(_temp) {
|
|
1065
|
+
var _ref = _temp === void 0 ? defaultProps : _temp,
|
|
1066
|
+
_ref$localStorageKey = _ref.localStorageKey,
|
|
1067
|
+
localStorageKey = _ref$localStorageKey === void 0 ? defaultProps.localStorageKey : _ref$localStorageKey,
|
|
1068
|
+
_ref$rootAttribute = _ref.rootAttribute,
|
|
1069
|
+
rootAttribute = _ref$rootAttribute === void 0 ? defaultProps.rootAttribute : _ref$rootAttribute;
|
|
966
1070
|
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
}
|
|
1071
|
+
assertKeyString(localStorageKey);
|
|
1072
|
+
assertKeyString(rootAttribute);
|
|
1073
|
+
return "'use strict';\n(function () {\n var localStorageKey = '" + localStorageKey + "'\n var rootAttribute = '" + rootAttribute + "'\n var currentTheme = localStorage.getItem(localStorageKey);\n if (currentTheme) {\n document.documentElement.dataset[rootAttribute] = currentTheme;\n }\n})();\n";
|
|
1074
|
+
}
|
|
1075
|
+
/**
|
|
1076
|
+
* 同期的にテーマをローカルストレージから取得してhtmlの属性に設定するスクリプトタグ
|
|
1077
|
+
* @param props localStorageのキー、htmlのdataになる属性のキーを含むオブジェクト
|
|
1078
|
+
* @returns
|
|
1079
|
+
*/
|
|
970
1080
|
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
1081
|
+
function SetThemeScript(props) {
|
|
1082
|
+
var src = makeSetThemeScriptCode(props);
|
|
1083
|
+
return /*#__PURE__*/React.createElement("script", {
|
|
1084
|
+
dangerouslySetInnerHTML: {
|
|
1085
|
+
__html: src
|
|
1086
|
+
}
|
|
1087
|
+
});
|
|
975
1088
|
}
|
|
1089
|
+
var defaultProps = {
|
|
1090
|
+
localStorageKey: LOCAL_STORAGE_KEY,
|
|
1091
|
+
rootAttribute: DEFAULT_ROOT_ATTRIBUTE
|
|
1092
|
+
};
|
|
1093
|
+
SetThemeScript.defaultProps = defaultProps;
|
|
976
1094
|
|
|
977
1095
|
var nonBlank = function nonBlank(value) {
|
|
978
1096
|
return isPresent(value) && value !== false;
|
|
@@ -980,7 +1098,7 @@ var nonBlank = function nonBlank(value) {
|
|
|
980
1098
|
/**
|
|
981
1099
|
* `theme(o => [...])` の `theme` ユーティリティを構築する
|
|
982
1100
|
*
|
|
983
|
-
* @param _styled styled-componnets の `styled`
|
|
1101
|
+
* @param _styled - DEPRECATED: styled-componnets の `styled` そのものを渡すとそれを元に型推論ができる。が、型引数を渡す方が型推論が高速になりやすい
|
|
984
1102
|
*
|
|
985
1103
|
* @example
|
|
986
1104
|
*
|
|
@@ -994,38 +1112,43 @@ var nonBlank = function nonBlank(value) {
|
|
|
994
1112
|
|
|
995
1113
|
|
|
996
1114
|
function createTheme(_styled) {
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1115
|
+
/**
|
|
1116
|
+
* 本当は `type Builder = ReturnType<createO<T>>` みたいな型を作って、それを o の型にしたい。
|
|
1117
|
+
* が、styled がつくられた時点の TypeScript ではこういうジェネリクスの使い方ができなかった
|
|
1118
|
+
* なので代わりに特に意味のない `createO` の呼び出しをやっている
|
|
1119
|
+
*/
|
|
1120
|
+
createO( // eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-explicit-any
|
|
1121
|
+
{},
|
|
1122
|
+
/** DO_NOTHING_IT_IS_JUST_CALLED_FOR_TYPE_INFERENCE = */
|
|
1123
|
+
true); // ランタイムの `theme(o => [...])` のインターフェースを構築する
|
|
1124
|
+
|
|
1125
|
+
return function theme(specFn) {
|
|
1126
|
+
// styled-components のテンプレートに埋め込める関数
|
|
1127
|
+
return function interpolate(_ref) {
|
|
1128
|
+
var theme = _ref.theme;
|
|
1007
1129
|
|
|
1008
1130
|
if (!isPresent(theme)) {
|
|
1009
1131
|
// テーマが入っていない場合は復旧不可能なのでエラーにする
|
|
1010
1132
|
throw noThemeProvider;
|
|
1011
|
-
}
|
|
1012
|
-
// さらに、ユーザー定義にbuilderが構築した`o`を食わせる
|
|
1013
|
-
// (`o`を一時変数に入れてしまうと型Tの具象化が行われるので関数合成を優先する)
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
var rawSpecDescriptor = spec(builder(theme)); // ユーザー定義の配列を整形
|
|
1017
|
-
|
|
1018
|
-
var specDescriptor = [].concat(Array.isArray(rawSpecDescriptor) ? rawSpecDescriptor : [rawSpecDescriptor], [commonSpec()]).filter(nonBlank); // 1パス目
|
|
1019
|
-
// 全ユーザー定義を舐めて相互に影響し合う定義をチェックし、その結果(コンテキスト)を取得
|
|
1020
|
-
|
|
1021
|
-
var context = specDescriptor.reduce(function (acc, v) {
|
|
1022
|
-
return _extends({}, acc, v[internalSym].context);
|
|
1023
|
-
}, {}); // 2パス目
|
|
1024
|
-
// コンテキストを見ながら最適化されたCSSを構築
|
|
1133
|
+
}
|
|
1025
1134
|
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1135
|
+
var internals = [].concat(wrapArray(
|
|
1136
|
+
/**
|
|
1137
|
+
* こう書いてはいけない
|
|
1138
|
+
*
|
|
1139
|
+
* ❌
|
|
1140
|
+
* ```ts
|
|
1141
|
+
* const o = createO(theme)
|
|
1142
|
+
* const declaration = spec(o)
|
|
1143
|
+
* ```
|
|
1144
|
+
*
|
|
1145
|
+
* `o` を一時変数に入れてしまうと型 `T` の具象化が行われるので関数内に書く
|
|
1146
|
+
*/
|
|
1147
|
+
specFn(
|
|
1148
|
+
/** o = */
|
|
1149
|
+
createO(theme))), [// 必ず挿入される共通のルール
|
|
1150
|
+
transition()]).filter(nonBlank);
|
|
1151
|
+
return toCSSObjects(internals);
|
|
1029
1152
|
};
|
|
1030
1153
|
};
|
|
1031
1154
|
}
|