1 | "use strict";
|
2 | var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
3 | if (k2 === undefined) k2 = k;
|
4 | var desc = Object.getOwnPropertyDescriptor(m, k);
|
5 | if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
6 | desc = { enumerable: true, get: function() { return m[k]; } };
|
7 | }
|
8 | Object.defineProperty(o, k2, desc);
|
9 | }) : (function(o, m, k, k2) {
|
10 | if (k2 === undefined) k2 = k;
|
11 | o[k2] = m[k];
|
12 | }));
|
13 | var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
14 | for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
15 | };
|
16 | Object.defineProperty(exports, "__esModule", { value: true });
|
17 | exports.parseHtmlScript = exports.parsePublicPath = exports.formatOpenHost = exports.addHtmlSuffix = exports.stripTrailingSlash = exports.stripBasename = exports.hasBasename = exports.addTrailingSlash = exports.addLeadingSlash = exports.getRootPath = exports.emptyTogglableObj = void 0;
|
18 | const os_1 = require("os");
|
19 | const path = require("path");
|
20 | exports.emptyTogglableObj = {
|
21 | enable: false,
|
22 | config: {}
|
23 | };
|
24 | const getRootPath = function () {
|
25 | return path.resolve(__dirname, '../../');
|
26 | };
|
27 | exports.getRootPath = getRootPath;
|
28 | const addLeadingSlash = (url = '') => (url.charAt(0) === '/' ? url : '/' + url);
|
29 | exports.addLeadingSlash = addLeadingSlash;
|
30 | const addTrailingSlash = (url = '') => (url.charAt(url.length - 1) === '/' ? url : url + '/');
|
31 | exports.addTrailingSlash = addTrailingSlash;
|
32 | const hasBasename = (path = '', prefix = '') => new RegExp('^' + prefix + '(\\/|\\?|#|$)', 'i').test(path) || path === prefix;
|
33 | exports.hasBasename = hasBasename;
|
34 | const stripBasename = (path = '', prefix = '') => (0, exports.hasBasename)(path, prefix) ? path.substr(prefix.length) : path;
|
35 | exports.stripBasename = stripBasename;
|
36 | const stripTrailingSlash = (path = '') => (path.charAt(path.length - 1) === '/' ? path.substring(0, path.length - 1) : path);
|
37 | exports.stripTrailingSlash = stripTrailingSlash;
|
38 | const addHtmlSuffix = (path = '') => `${path}.html`;
|
39 | exports.addHtmlSuffix = addHtmlSuffix;
|
40 | const formatOpenHost = host => {
|
41 | var _a;
|
42 | let result = host;
|
43 |
|
44 | if (result === '0.0.0.0') {
|
45 |
|
46 | result = 'localhost';
|
47 | const interfaces = (0, os_1.networkInterfaces)();
|
48 | for (const devName in interfaces) {
|
49 | const isEnd = (_a = interfaces[devName]) === null || _a === void 0 ? void 0 : _a.some(item => {
|
50 |
|
51 | if (['IPv4', 4, '4'].includes(item.family) && item.address !== '127.0.0.1' && !item.internal) {
|
52 | result = item.address;
|
53 | return true;
|
54 | }
|
55 | return false;
|
56 | });
|
57 |
|
58 | if (isEnd) {
|
59 | break;
|
60 | }
|
61 | }
|
62 | }
|
63 | return result;
|
64 | };
|
65 | exports.formatOpenHost = formatOpenHost;
|
66 | function parsePublicPath(publicPath = '/') {
|
67 | return ['', 'auto'].includes(publicPath) ? publicPath : (0, exports.addTrailingSlash)(publicPath);
|
68 | }
|
69 | exports.parsePublicPath = parsePublicPath;
|
70 | function parseHtmlScript(pxtransformOption = {}) {
|
71 | var _a, _b, _c;
|
72 | const options = (pxtransformOption === null || pxtransformOption === void 0 ? void 0 : pxtransformOption.config) || {};
|
73 | const max = (_a = options === null || options === void 0 ? void 0 : options.maxRootSize) !== null && _a !== void 0 ? _a : 40;
|
74 | const min = (_b = options === null || options === void 0 ? void 0 : options.minRootSize) !== null && _b !== void 0 ? _b : 20;
|
75 | const baseFontSize = (options === null || options === void 0 ? void 0 : options.baseFontSize) || (min > 1 ? min : 20);
|
76 | const designWidth = (input => typeof options.designWidth === 'function'
|
77 | ? options.designWidth(input)
|
78 | : options.designWidth)(baseFontSize);
|
79 | const rootValue = baseFontSize / options.deviceRatio[designWidth] * 2;
|
80 | if (((_c = options === null || options === void 0 ? void 0 : options.targetUnit) !== null && _c !== void 0 ? _c : 'rem') === 'rem') {
|
81 | return `!function(n){function f(){var e=n.document.documentElement,w=e.getBoundingClientRect().width,x=${rootValue}*w/${designWidth};e.style.fontSize=x>=${max}?"${max}px":x<=${min}?"${min}px":x+"px"}n.addEventListener("resize",(function(){f()})),f()}(window);`;
|
82 | }
|
83 | }
|
84 | exports.parseHtmlScript = parseHtmlScript;
|
85 | __exportStar(require("./app"), exports);
|
86 |
|
\ | No newline at end of file |