You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
251 lines
7.8 KiB
251 lines
7.8 KiB
'use strict';var plugin=require('tailwindcss/plugin');function linearInterpolateKeys(start, end, interval) {
|
|
let obj = {};
|
|
for (let i = start; i <= end; i += interval) {
|
|
obj[i] = i.toString();
|
|
}
|
|
return obj;
|
|
}function perspective({ matchUtilities, theme }) {
|
|
matchUtilities({
|
|
perspective: (value, x) => {
|
|
// Check if value is a number. If not pass it.
|
|
if (/[^0-9]/.test(value)) {
|
|
return {
|
|
perspective: `${value}`
|
|
};
|
|
}
|
|
return {
|
|
perspective: `${value}px`
|
|
};
|
|
}
|
|
}, {
|
|
supportsNegativeValues: false,
|
|
respectImportant: true,
|
|
type: ['length', 'number'],
|
|
values: theme('perspective')
|
|
});
|
|
}
|
|
const perspectiveDefaults = linearInterpolateKeys(0, 1600, 200);function extendWithTransform(obj) {
|
|
// return {
|
|
// ...obj,
|
|
// ...transform3dGpu
|
|
// };
|
|
return obj;
|
|
}function toUnit$2(value) {
|
|
return value;
|
|
}
|
|
function transformRotate(pluginAPI) {
|
|
pluginAPI.matchUtilities({
|
|
'rotate-x': function (value) {
|
|
return extendWithTransform({
|
|
'--tw-rotate-x': `${toUnit$2(value)}`
|
|
});
|
|
},
|
|
'rotate-y': function (value) {
|
|
return extendWithTransform({
|
|
'--tw-rotate-y': `${toUnit$2(value)}`
|
|
});
|
|
},
|
|
'rotate-z': function (value) {
|
|
// Default tw variable
|
|
return extendWithTransform({
|
|
'--tw-rotate': `${toUnit$2(value)}`
|
|
});
|
|
},
|
|
'rotate-3d': function (value) {
|
|
return extendWithTransform({
|
|
'--tw-rotate-3d': `${value}`
|
|
});
|
|
}
|
|
}, {
|
|
supportsNegativeValues: true,
|
|
values: pluginAPI.theme('rotate')
|
|
});
|
|
}function toUnit$1(value) {
|
|
value = value.trim();
|
|
if (value.indexOf('px') > -1) {
|
|
if (value === 'px') {
|
|
// For translate-x-px similar
|
|
return '1px';
|
|
}
|
|
return value;
|
|
}
|
|
if (value == 'full') {
|
|
return '100%';
|
|
}
|
|
return value;
|
|
}
|
|
function transformTranslate(pluginAPI) {
|
|
pluginAPI.matchUtilities({
|
|
'translate-z': function (value) {
|
|
return extendWithTransform({
|
|
'--tw-translate-z': `${toUnit$1(value)}`
|
|
});
|
|
},
|
|
'translate-3d': function (value) {
|
|
let items = value.split(',');
|
|
while (items.length < 3) {
|
|
items.push(items[0]);
|
|
}
|
|
return extendWithTransform({
|
|
'--tw-translate-x': `${toUnit$1(items[0])}`,
|
|
'--tw-translate-y': `${toUnit$1(items[1])}`,
|
|
'--tw-translate-z': `${toUnit$1(items[2])}`,
|
|
});
|
|
}
|
|
}, {
|
|
supportsNegativeValues: true,
|
|
values: pluginAPI.theme('translate')
|
|
});
|
|
}function toUnit(value) {
|
|
return value;
|
|
}
|
|
function transformScale(pluginAPI) {
|
|
pluginAPI.matchUtilities({
|
|
'scale-z': function (value) {
|
|
return extendWithTransform({
|
|
'--tw-scale-z': `${toUnit(value)}`
|
|
});
|
|
},
|
|
'scale-3d': function (value) {
|
|
let items = value.split(',');
|
|
while (items.length < 3) {
|
|
items.push(items[0]);
|
|
}
|
|
return extendWithTransform({
|
|
'--tw-scale-x': `${toUnit(items[0])}`,
|
|
'--tw-scale-y': `${toUnit(items[1])}`,
|
|
'--tw-scale-z': `${toUnit(items[2])}`,
|
|
});
|
|
}
|
|
}, {
|
|
supportsNegativeValues: true,
|
|
values: pluginAPI.theme('scale')
|
|
});
|
|
}const transform3dGpu = {
|
|
transform: `translate3d(var(--tw-translate-x), var(--tw-translate-y), var(--tw-translate-z)) rotateX(var(--tw-rotate-x)) rotateY(var(--tw-rotate-y)) rotateZ(var(--tw-rotate)) rotate3d(var(--tw-rotate-3d)) skewX(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scale3d(var(--tw-scale-x),var(--tw-scale-y),var(--tw-scale-z)) !important`
|
|
};
|
|
const transform3dCpu = {
|
|
transform: `translateX(var(--tw-translate-x)) translateY(var(--tw-translate-y)) translateZ(var(--tw-translate-z)) rotateX(var(--tw-rotate-x)) rotateY(var(--tw-rotate-y)) rotateZ(var(--tw-rotate)) rotate3d(var(--tw-rotate-3d)) skewX(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scale3d(var(--tw-scale-x),var(--tw-scale-y),var(--tw-scale-z)) !important`
|
|
};function transformOverride(pluginAPI) {
|
|
pluginAPI.addUtilities({
|
|
'.transform': transform3dGpu,
|
|
'.transform-cpu': transform3dCpu,
|
|
'.transform-gpu': transform3dGpu,
|
|
});
|
|
}function flip(pluginAPI) {
|
|
pluginAPI.addUtilities({
|
|
'.flip-x': {
|
|
'--tw-rotate': '180deg',
|
|
'--tw-rotate-y': '180deg'
|
|
},
|
|
'.flip-y': {
|
|
'--tw-rotate': '180deg',
|
|
'--tw-rotate-x': '180deg'
|
|
},
|
|
'.flip-z': {
|
|
'--tw-rotate-x': '180deg',
|
|
'--tw-rotate-y': '180deg'
|
|
}
|
|
});
|
|
}function backfaceVisibility(pluginAPI) {
|
|
pluginAPI.addUtilities({
|
|
'.backface-visible': {
|
|
backfaceVisibility: 'visible'
|
|
},
|
|
'.backface-hidden': {
|
|
backfaceVisibility: 'hidden'
|
|
},
|
|
'.backface-inherit': {
|
|
backfaceVisibility: 'inherit'
|
|
},
|
|
'.backface-unset': {
|
|
backfaceVisibility: 'unset'
|
|
}
|
|
});
|
|
}function transformBox(pluginAPI) {
|
|
pluginAPI.addUtilities({
|
|
'.transform-box-content': {
|
|
transformBox: 'content-box'
|
|
},
|
|
'.transform-box-border': {
|
|
transformBox: 'border-box'
|
|
},
|
|
'.transform-box-fill': {
|
|
transformBox: 'fill-box'
|
|
},
|
|
'.transform-box-stroke': {
|
|
transformBox: 'stroke-box'
|
|
},
|
|
'.transform-box-view': {
|
|
transformBox: 'view-box'
|
|
}
|
|
});
|
|
}function perspectiveOrigin(pluginAPI) {
|
|
pluginAPI.matchUtilities({
|
|
'perspective-origin': (value) => {
|
|
let target = value;
|
|
//if arbitrary value or default theme value with -
|
|
if ((value.indexOf('_') > -1) || (value.indexOf('-') > -1)) {
|
|
let items = value.split('_');
|
|
target = items[0];
|
|
if (items.length > 1) {
|
|
target += ' ' + items[1];
|
|
}
|
|
}
|
|
return {
|
|
'perspective-origin': target
|
|
};
|
|
}
|
|
}, {
|
|
values: pluginAPI.theme('transformOrigin')
|
|
});
|
|
}function transformStyle(pluginAPI) {
|
|
pluginAPI.addUtilities({
|
|
'.transform-style-flat': {
|
|
transformStyle: 'flat'
|
|
},
|
|
'.transform-style-3d': {
|
|
transformStyle: 'preserve-3d'
|
|
}
|
|
});
|
|
}const tailwind3dTransformPlugin = plugin((pluginAPI) => {
|
|
perspectiveOrigin(pluginAPI);
|
|
perspective(pluginAPI);
|
|
transformRotate(pluginAPI);
|
|
transformTranslate(pluginAPI);
|
|
transformScale(pluginAPI);
|
|
flip(pluginAPI);
|
|
transformOverride(pluginAPI);
|
|
backfaceVisibility(pluginAPI);
|
|
transformBox(pluginAPI);
|
|
transformStyle(pluginAPI);
|
|
pluginAPI.addBase({
|
|
':root': {
|
|
'--tw-rotate-x': '0',
|
|
'--tw-rotate-y': '0',
|
|
'--tw-translate-z': '0',
|
|
'--tw-scale-z': '1',
|
|
'--tw-rotate-3d': '0,0,0,0deg'
|
|
}
|
|
});
|
|
}, {
|
|
theme: {
|
|
extend: {
|
|
perspective: perspectiveDefaults,
|
|
rotate: {
|
|
30: '30deg',
|
|
60: '60deg',
|
|
135: '135deg',
|
|
120: '120deg',
|
|
270: '270deg'
|
|
}
|
|
},
|
|
variables: {
|
|
'--tw-rotate-x': '0',
|
|
'--tw-rotate-y': '0',
|
|
'--tw-rotate-3d': '0,0,0,0deg',
|
|
'--tw-scale-z': '1',
|
|
'--tw-translate-z': '0',
|
|
}
|
|
}
|
|
});module.exports=tailwind3dTransformPlugin; |