初始化fy
This commit is contained in:
10
uni_modules/UniDevTools/node_modules/@dcloudio/uni-cli-shared/dist/postcss/index.d.ts
generated
vendored
Normal file
10
uni_modules/UniDevTools/node_modules/@dcloudio/uni-cli-shared/dist/postcss/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
import type { Plugin } from 'postcss';
|
||||
import type { Options } from 'autoprefixer';
|
||||
import uniPostcssScopedPlugin from './plugins/stylePluginScoped';
|
||||
import uniPostcssPlugin, { UniAppCssProcessorOptions } from './plugins/uniapp';
|
||||
export { uniPostcssPlugin };
|
||||
export { uniPostcssScopedPlugin };
|
||||
export declare function initPostcssPlugin({ uniApp, autoprefixer, }?: {
|
||||
uniApp?: UniAppCssProcessorOptions;
|
||||
autoprefixer?: Options | false;
|
||||
}): Plugin[];
|
||||
19
uni_modules/UniDevTools/node_modules/@dcloudio/uni-cli-shared/dist/postcss/index.js
generated
vendored
Normal file
19
uni_modules/UniDevTools/node_modules/@dcloudio/uni-cli-shared/dist/postcss/index.js
generated
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.initPostcssPlugin = exports.uniPostcssScopedPlugin = exports.uniPostcssPlugin = void 0;
|
||||
const stylePluginScoped_1 = __importDefault(require("./plugins/stylePluginScoped"));
|
||||
exports.uniPostcssScopedPlugin = stylePluginScoped_1.default;
|
||||
const uniapp_1 = __importDefault(require("./plugins/uniapp"));
|
||||
exports.uniPostcssPlugin = uniapp_1.default;
|
||||
function initPostcssPlugin({ uniApp, autoprefixer, } = {}) {
|
||||
const plugins = [(0, uniapp_1.default)(uniApp)];
|
||||
// nvue 不需要 autoprefixer
|
||||
if (autoprefixer !== false) {
|
||||
plugins.push(require('autoprefixer')(autoprefixer));
|
||||
}
|
||||
return plugins;
|
||||
}
|
||||
exports.initPostcssPlugin = initPostcssPlugin;
|
||||
3
uni_modules/UniDevTools/node_modules/@dcloudio/uni-cli-shared/dist/postcss/plugins/stylePluginScoped.d.ts
generated
vendored
Normal file
3
uni_modules/UniDevTools/node_modules/@dcloudio/uni-cli-shared/dist/postcss/plugins/stylePluginScoped.d.ts
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
import type { PluginCreator } from 'postcss';
|
||||
declare const scopedPlugin: PluginCreator<string>;
|
||||
export default scopedPlugin;
|
||||
176
uni_modules/UniDevTools/node_modules/@dcloudio/uni-cli-shared/dist/postcss/plugins/stylePluginScoped.js
generated
vendored
Normal file
176
uni_modules/UniDevTools/node_modules/@dcloudio/uni-cli-shared/dist/postcss/plugins/stylePluginScoped.js
generated
vendored
Normal file
@@ -0,0 +1,176 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const postcss_selector_parser_1 = __importDefault(require("postcss-selector-parser"));
|
||||
const scopedPlugin = () => {
|
||||
return {
|
||||
postcssPlugin: 'uni-sfc-scoped',
|
||||
prepare({ processor: { plugins } }) {
|
||||
const hasVueSfcScoped = !!plugins.find((plugin) => plugin.postcssPlugin === 'vue-sfc-scoped');
|
||||
return {
|
||||
Rule(rule) {
|
||||
processRule(rule, hasVueSfcScoped);
|
||||
},
|
||||
};
|
||||
},
|
||||
};
|
||||
};
|
||||
const processedRules = new WeakSet();
|
||||
function processRule(rule, hasVueSfcScoped) {
|
||||
if (processedRules.has(rule) ||
|
||||
(rule.parent &&
|
||||
rule.parent.type === 'atrule' &&
|
||||
/-?keyframes$/.test(rule.parent.name))) {
|
||||
return;
|
||||
}
|
||||
processedRules.add(rule);
|
||||
rule.selector = (0, postcss_selector_parser_1.default)((selectorRoot) => {
|
||||
selectorRoot.each((selector) => {
|
||||
hasVueSfcScoped
|
||||
? rewriteDeprecatedSelector(selector)
|
||||
: rewriteSelector(selector, selectorRoot);
|
||||
});
|
||||
}).processSync(rule.selector);
|
||||
}
|
||||
/**
|
||||
* @param selector
|
||||
* @returns
|
||||
*/
|
||||
function rewriteDeprecatedSelector(selector) {
|
||||
const nodes = [];
|
||||
let deepNode;
|
||||
selector.each((n) => {
|
||||
if (deepNode) {
|
||||
nodes.push(n);
|
||||
selector.removeChild(n);
|
||||
}
|
||||
else {
|
||||
const { type, value } = n;
|
||||
if (type === 'pseudo' && value === '::v-deep') {
|
||||
deepNode = n;
|
||||
}
|
||||
else if (type === 'combinator' &&
|
||||
(value === '>>>' || value === '/deep/')) {
|
||||
deepNode = n;
|
||||
}
|
||||
}
|
||||
});
|
||||
if (!deepNode) {
|
||||
return;
|
||||
}
|
||||
if (deepNode.type === 'combinator') {
|
||||
const index = selector.index(deepNode);
|
||||
if (index > 0) {
|
||||
selector.insertBefore(deepNode, postcss_selector_parser_1.default.combinator({ value: ' ' }));
|
||||
}
|
||||
}
|
||||
// remove first combinator
|
||||
// ::v-deep a{color:red;} => :deep(a){color:red;}
|
||||
const firstNode = nodes[0];
|
||||
if (firstNode && firstNode.type === 'combinator' && firstNode.value === ' ') {
|
||||
nodes.shift();
|
||||
}
|
||||
selector.insertBefore(deepNode, postcss_selector_parser_1.default.pseudo({
|
||||
value: ':deep',
|
||||
nodes: [postcss_selector_parser_1.default.selector({ value: '', nodes })],
|
||||
}));
|
||||
selector.removeChild(deepNode);
|
||||
}
|
||||
function rewriteSelector(selector, selectorRoot) {
|
||||
let node = null;
|
||||
// find the last child node to insert attribute selector
|
||||
selector.each((n) => {
|
||||
// DEPRECATED ">>>" and "/deep/" combinator
|
||||
if (n.type === 'combinator' &&
|
||||
(n.value === '>>>' || n.value === '/deep/')) {
|
||||
n.value = ' ';
|
||||
n.spaces.before = n.spaces.after = '';
|
||||
// warn(
|
||||
// `the >>> and /deep/ combinators have been deprecated. ` +
|
||||
// `Use :deep() instead.`
|
||||
// )
|
||||
return false;
|
||||
}
|
||||
if (n.type === 'pseudo') {
|
||||
const { value } = n;
|
||||
// deep: inject [id] attribute at the node before the ::v-deep
|
||||
// combinator.
|
||||
if (value === ':deep' || value === '::v-deep') {
|
||||
if (n.nodes.length) {
|
||||
// .foo ::v-deep(.bar) -> .foo[xxxxxxx] .bar
|
||||
// replace the current node with ::v-deep's inner selector
|
||||
let last = n;
|
||||
n.nodes[0].each((ss) => {
|
||||
selector.insertAfter(last, ss);
|
||||
last = ss;
|
||||
});
|
||||
// insert a space combinator before if it doesn't already have one
|
||||
const prev = selector.at(selector.index(n) - 1);
|
||||
if (!prev || !isSpaceCombinator(prev)) {
|
||||
selector.insertAfter(n, postcss_selector_parser_1.default.combinator({
|
||||
value: ' ',
|
||||
}));
|
||||
}
|
||||
selector.removeChild(n);
|
||||
}
|
||||
else {
|
||||
// DEPRECATED usage
|
||||
// .foo ::v-deep .bar -> .foo[xxxxxxx] .bar
|
||||
// warn(
|
||||
// `::v-deep usage as a combinator has ` +
|
||||
// `been deprecated. Use :deep(<inner-selector>) instead.`
|
||||
// )
|
||||
const prev = selector.at(selector.index(n) - 1);
|
||||
if (prev && isSpaceCombinator(prev)) {
|
||||
selector.removeChild(prev);
|
||||
}
|
||||
selector.removeChild(n);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
// slot: use selector inside `::v-slotted` and inject [id + '-s']
|
||||
// instead.
|
||||
// ::v-slotted(.foo) -> .foo[xxxxxxx-s]
|
||||
if (value === ':slotted' || value === '::v-slotted') {
|
||||
rewriteSelector(n.nodes[0], selectorRoot);
|
||||
let last = n;
|
||||
n.nodes[0].each((ss) => {
|
||||
selector.insertAfter(last, ss);
|
||||
last = ss;
|
||||
});
|
||||
// selector.insertAfter(n, n.nodes[0])
|
||||
selector.removeChild(n);
|
||||
// since slotted attribute already scopes the selector there's no
|
||||
// need for the non-slot attribute.
|
||||
return false;
|
||||
}
|
||||
// global: replace with inner selector and do not inject [id].
|
||||
// ::v-global(.foo) -> .foo
|
||||
if (value === ':global' || value === '::v-global') {
|
||||
selectorRoot.insertAfter(selector, n.nodes[0]);
|
||||
selectorRoot.removeChild(selector);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (n.type !== 'pseudo' && n.type !== 'combinator') {
|
||||
node = n;
|
||||
}
|
||||
});
|
||||
if (node) {
|
||||
;
|
||||
node.spaces.after = '';
|
||||
}
|
||||
else {
|
||||
// For deep selectors & standalone pseudo selectors,
|
||||
// the attribute selectors are prepended rather than appended.
|
||||
// So all leading spaces must be eliminated to avoid problems.
|
||||
selector.first.spaces.before = '';
|
||||
}
|
||||
}
|
||||
function isSpaceCombinator(node) {
|
||||
return node.type === 'combinator' && /^\s+$/.test(node.value);
|
||||
}
|
||||
scopedPlugin.postcss = true;
|
||||
exports.default = scopedPlugin;
|
||||
12
uni_modules/UniDevTools/node_modules/@dcloudio/uni-cli-shared/dist/postcss/plugins/uniapp.d.ts
generated
vendored
Normal file
12
uni_modules/UniDevTools/node_modules/@dcloudio/uni-cli-shared/dist/postcss/plugins/uniapp.d.ts
generated
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
import type { Plugin, Root } from 'postcss';
|
||||
export interface UniAppCssProcessorOptions {
|
||||
unit?: string;
|
||||
unitRatio?: number;
|
||||
unitPrecision?: number;
|
||||
}
|
||||
export declare function filterPrefersColorScheme(root: Root, force?: boolean): void;
|
||||
declare const uniapp: {
|
||||
(opts?: UniAppCssProcessorOptions): Plugin;
|
||||
postcss: boolean;
|
||||
};
|
||||
export default uniapp;
|
||||
125
uni_modules/UniDevTools/node_modules/@dcloudio/uni-cli-shared/dist/postcss/plugins/uniapp.js
generated
vendored
Normal file
125
uni_modules/UniDevTools/node_modules/@dcloudio/uni-cli-shared/dist/postcss/plugins/uniapp.js
generated
vendored
Normal file
@@ -0,0 +1,125 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.filterPrefersColorScheme = void 0;
|
||||
const shared_1 = require("@vue/shared");
|
||||
const postcss_selector_parser_1 = __importDefault(require("postcss-selector-parser"));
|
||||
const uni_shared_1 = require("@dcloudio/uni-shared");
|
||||
const defaultUniAppCssProcessorOptions = (0, shared_1.extend)({}, uni_shared_1.defaultRpx2Unit);
|
||||
const BG_PROPS = [
|
||||
'background',
|
||||
'background-clip',
|
||||
'background-color',
|
||||
'background-image',
|
||||
'background-origin',
|
||||
'background-position',
|
||||
'background-repeat',
|
||||
'background-size',
|
||||
'background-attachment',
|
||||
];
|
||||
function transform(selector, state, { rewriteTag }) {
|
||||
if (selector.type !== 'tag') {
|
||||
return;
|
||||
}
|
||||
const { value } = selector;
|
||||
selector.value = rewriteTag(value);
|
||||
if (value === 'page' && selector.value === 'uni-page-body') {
|
||||
state.bg = true;
|
||||
}
|
||||
}
|
||||
function createBodyBackgroundRule(origRule) {
|
||||
const bgDecls = [];
|
||||
origRule.walkDecls((decl) => {
|
||||
if (BG_PROPS.indexOf(decl.prop) !== -1) {
|
||||
bgDecls.push(decl.clone());
|
||||
}
|
||||
});
|
||||
if (bgDecls.length) {
|
||||
const { rule } = require('postcss');
|
||||
origRule.after(rule({ selector: 'body' }).append(bgDecls));
|
||||
}
|
||||
}
|
||||
function walkRules(options) {
|
||||
return (rule) => {
|
||||
const state = { bg: false };
|
||||
rule.selector = (0, postcss_selector_parser_1.default)((selectors) => selectors.walk((selector) => transform(selector, state, options))).processSync(rule.selector);
|
||||
state.bg && createBodyBackgroundRule(rule);
|
||||
};
|
||||
}
|
||||
function walkDecls(rpx2unit) {
|
||||
return (decl) => {
|
||||
const { value } = decl;
|
||||
if (value.indexOf('rpx') === -1 && value.indexOf('upx') === -1) {
|
||||
return;
|
||||
}
|
||||
decl.value = rpx2unit(decl.value);
|
||||
};
|
||||
}
|
||||
function filterPrefersColorScheme(root, force = false) {
|
||||
if (process.env.VUE_APP_DARK_MODE !== 'true') {
|
||||
const filePath = root.source?.input.file;
|
||||
if (force || (filePath && filePath.includes('@dcloudio'))) {
|
||||
root.walkAtRules((rule) => {
|
||||
if (rule.params.includes('prefers-color-scheme')) {
|
||||
rule.remove();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
exports.filterPrefersColorScheme = filterPrefersColorScheme;
|
||||
const baiduTags = {
|
||||
navigator: 'nav',
|
||||
};
|
||||
function rewriteBaiduTags(tag) {
|
||||
return baiduTags[tag] || tag;
|
||||
}
|
||||
function rewriteUniH5Tags(tag) {
|
||||
if (tag === 'page') {
|
||||
return 'uni-page-body';
|
||||
}
|
||||
if ((0, uni_shared_1.isBuiltInComponent)(tag)) {
|
||||
return uni_shared_1.COMPONENT_SELECTOR_PREFIX + tag;
|
||||
}
|
||||
return tag;
|
||||
}
|
||||
function rewriteUniAppTags(tag) {
|
||||
if (tag === 'page') {
|
||||
return 'body';
|
||||
}
|
||||
if ((0, uni_shared_1.isBuiltInComponent)(tag)) {
|
||||
return uni_shared_1.COMPONENT_SELECTOR_PREFIX + tag;
|
||||
}
|
||||
return tag;
|
||||
}
|
||||
const transforms = {
|
||||
h5: rewriteUniH5Tags,
|
||||
app: rewriteUniAppTags,
|
||||
'mp-baidu': rewriteBaiduTags,
|
||||
};
|
||||
const uniapp = (opts) => {
|
||||
const platform = process.env.UNI_PLATFORM;
|
||||
const { unit, unitRatio, unitPrecision } = (0, shared_1.extend)({}, defaultUniAppCssProcessorOptions, opts);
|
||||
const rpx2unit = (0, uni_shared_1.createRpx2Unit)(unit, unitRatio, unitPrecision);
|
||||
return {
|
||||
postcssPlugin: 'uni-app',
|
||||
prepare() {
|
||||
return {
|
||||
OnceExit(root) {
|
||||
root.walkDecls(walkDecls(rpx2unit));
|
||||
const rewriteTag = transforms[platform];
|
||||
filterPrefersColorScheme(root);
|
||||
if (rewriteTag) {
|
||||
root.walkRules(walkRules({
|
||||
rewriteTag,
|
||||
}));
|
||||
}
|
||||
},
|
||||
};
|
||||
},
|
||||
};
|
||||
};
|
||||
uniapp.postcss = true;
|
||||
exports.default = uniapp;
|
||||
Reference in New Issue
Block a user