路泰科技体检小程序UI设计新版本
1
wwl
2025-07-30 61b58bd03d04d2eb50ac2d93a188c819fe67e01e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
/*
    MIT License http://www.opensource.org/licenses/mit-license.php
    Author Tobias Koppers @sokra
*/
 
"use strict";
 
const Source = require("./Source");
const streamAndGetSourceAndMap = require("./helpers/streamAndGetSourceAndMap");
const streamChunksOfRawSource = require("./helpers/streamChunksOfRawSource");
const streamChunksOfSourceMap = require("./helpers/streamChunksOfSourceMap");
const {
    isDualStringBufferCachingEnabled,
} = require("./helpers/stringBufferUtils");
 
/** @typedef {import("./Source").HashLike} HashLike */
/** @typedef {import("./Source").MapOptions} MapOptions */
/** @typedef {import("./Source").RawSourceMap} RawSourceMap */
/** @typedef {import("./Source").SourceAndMap} SourceAndMap */
/** @typedef {import("./Source").SourceValue} SourceValue */
/** @typedef {import("./helpers/getGeneratedSourceInfo").GeneratedSourceInfo} GeneratedSourceInfo */
/** @typedef {import("./helpers/streamChunks").OnChunk} OnChunk */
/** @typedef {import("./helpers/streamChunks").OnName} OnName */
/** @typedef {import("./helpers/streamChunks").OnSource} OnSource */
/** @typedef {import("./helpers/streamChunks").Options} Options */
 
/**
 * @typedef {object} BufferedMap
 * @property {number} version version
 * @property {string[]} sources sources
 * @property {string[]} names name
 * @property {string=} sourceRoot source root
 * @property {(Buffer | "")[]=} sourcesContent sources content
 * @property {Buffer=} mappings mappings
 * @property {string} file file
 */
 
/**
 * @param {null | RawSourceMap} map map
 * @returns {null | BufferedMap} buffered map
 */
const mapToBufferedMap = (map) => {
    if (typeof map !== "object" || !map) return map;
    const bufferedMap =
        /** @type {BufferedMap} */
        (/** @type {unknown} */ ({ ...map }));
    if (map.mappings) {
        bufferedMap.mappings = Buffer.from(map.mappings, "utf8");
    }
    if (map.sourcesContent) {
        bufferedMap.sourcesContent = map.sourcesContent.map(
            (str) => str && Buffer.from(str, "utf8"),
        );
    }
    return bufferedMap;
};
 
/**
 * @param {null | BufferedMap} bufferedMap buffered map
 * @returns {null | RawSourceMap} map
 */
const bufferedMapToMap = (bufferedMap) => {
    if (typeof bufferedMap !== "object" || !bufferedMap) return bufferedMap;
    const map =
        /** @type {RawSourceMap} */
        (/** @type {unknown} */ ({ ...bufferedMap }));
    if (bufferedMap.mappings) {
        map.mappings = bufferedMap.mappings.toString("utf8");
    }
    if (bufferedMap.sourcesContent) {
        map.sourcesContent = bufferedMap.sourcesContent.map(
            (buffer) => buffer && buffer.toString("utf8"),
        );
    }
    return map;
};
 
/** @typedef {{ map?: null | RawSourceMap, bufferedMap?: null | BufferedMap }} BufferEntry */
/** @typedef {Map<string, BufferEntry>} BufferedMaps */
 
/**
 * @typedef {object} CachedData
 * @property {boolean=} source source
 * @property {Buffer} buffer buffer
 * @property {number=} size size
 * @property {BufferedMaps} maps maps
 * @property {(string | Buffer)[]=} hash hash
 */
 
class CachedSource extends Source {
    /**
     * @param {Source | (() => Source)} source source
     * @param {CachedData=} cachedData cached data
     */
    constructor(source, cachedData) {
        super();
        this._source = source;
        this._cachedSourceType = cachedData ? cachedData.source : undefined;
        /**
         * @private
         * @type {undefined | string}
         */
        this._cachedSource = undefined;
        this._cachedBuffer = cachedData ? cachedData.buffer : undefined;
        this._cachedSize = cachedData ? cachedData.size : undefined;
        /**
         * @private
         * @type {BufferedMaps}
         */
        this._cachedMaps = cachedData ? cachedData.maps : new Map();
        this._cachedHashUpdate = cachedData ? cachedData.hash : undefined;
    }
 
    /**
     * @returns {CachedData} cached data
     */
    getCachedData() {
        /** @type {BufferedMaps} */
        const bufferedMaps = new Map();
        for (const pair of this._cachedMaps) {
            const [, cacheEntry] = pair;
            if (cacheEntry.bufferedMap === undefined) {
                cacheEntry.bufferedMap = mapToBufferedMap(
                    this._getMapFromCacheEntry(cacheEntry),
                );
            }
            bufferedMaps.set(pair[0], {
                map: undefined,
                bufferedMap: cacheEntry.bufferedMap,
            });
        }
        return {
            // We don't want to cache strings
            // So if we have a caches sources
            // create a buffer from it and only store
            // if it was a Buffer or string
            buffer: this._cachedSource
                ? this.buffer()
                : /** @type {Buffer} */ (this._cachedBuffer),
            source:
                this._cachedSourceType !== undefined
                    ? this._cachedSourceType
                    : typeof this._cachedSource === "string"
                        ? true
                        : Buffer.isBuffer(this._cachedSource)
                            ? false
                            : undefined,
            size: this._cachedSize,
            maps: bufferedMaps,
            hash: this._cachedHashUpdate,
        };
    }
 
    originalLazy() {
        return this._source;
    }
 
    original() {
        if (typeof this._source === "function") this._source = this._source();
        return this._source;
    }
 
    /**
     * @returns {SourceValue} source
     */
    source() {
        const source = this._getCachedSource();
        if (source !== undefined) return source;
        return (this._cachedSource =
            /** @type {string} */
            (this.original().source()));
    }
 
    /**
     * @private
     * @param {BufferEntry} cacheEntry cache entry
     * @returns {null | RawSourceMap} raw source map
     */
    _getMapFromCacheEntry(cacheEntry) {
        if (cacheEntry.map !== undefined) {
            return cacheEntry.map;
        } else if (cacheEntry.bufferedMap !== undefined) {
            return (cacheEntry.map = bufferedMapToMap(cacheEntry.bufferedMap));
        }
 
        return null;
    }
 
    /**
     * @private
     * @returns {undefined | string} cached source
     */
    _getCachedSource() {
        if (this._cachedSource !== undefined) return this._cachedSource;
        if (this._cachedBuffer && this._cachedSourceType !== undefined) {
            const value = this._cachedSourceType
                ? this._cachedBuffer.toString("utf8")
                : this._cachedBuffer;
            if (isDualStringBufferCachingEnabled()) {
                this._cachedSource = /** @type {string} */ (value);
            }
            return /** @type {string} */ (value);
        }
    }
 
    /**
     * @returns {Buffer} buffer
     */
    buffer() {
        if (this._cachedBuffer !== undefined) return this._cachedBuffer;
        if (this._cachedSource !== undefined) {
            const value = Buffer.isBuffer(this._cachedSource)
                ? this._cachedSource
                : Buffer.from(this._cachedSource, "utf8");
            if (isDualStringBufferCachingEnabled()) {
                this._cachedBuffer = value;
            }
            return value;
        }
        if (typeof this.original().buffer === "function") {
            return (this._cachedBuffer = this.original().buffer());
        }
        const bufferOrString = this.source();
        if (Buffer.isBuffer(bufferOrString)) {
            return (this._cachedBuffer = bufferOrString);
        }
        const value = Buffer.from(bufferOrString, "utf8");
        if (isDualStringBufferCachingEnabled()) {
            this._cachedBuffer = value;
        }
        return value;
    }
 
    /**
     * @returns {number} size
     */
    size() {
        if (this._cachedSize !== undefined) return this._cachedSize;
        if (this._cachedBuffer !== undefined) {
            return (this._cachedSize = this._cachedBuffer.length);
        }
        const source = this._getCachedSource();
        if (source !== undefined) {
            return (this._cachedSize = Buffer.byteLength(source));
        }
        return (this._cachedSize = this.original().size());
    }
 
    /**
     * @param {MapOptions=} options map options
     * @returns {SourceAndMap} source and map
     */
    sourceAndMap(options) {
        const key = options ? JSON.stringify(options) : "{}";
        const cacheEntry = this._cachedMaps.get(key);
        // Look for a cached map
        if (cacheEntry !== undefined) {
            // We have a cached map in some representation
            const map = this._getMapFromCacheEntry(cacheEntry);
 
            // Either get the cached source or compute it
            return { source: this.source(), map };
        }
        // Look for a cached source
        let source = this._getCachedSource();
        // Compute the map
        let map;
        if (source !== undefined) {
            map = this.original().map(options);
        } else {
            // Compute the source and map together.
            const sourceAndMap = this.original().sourceAndMap(options);
            source = /** @type {string} */ (sourceAndMap.source);
            map = sourceAndMap.map;
            this._cachedSource = source;
        }
        this._cachedMaps.set(key, {
            map,
            bufferedMap: undefined,
        });
        return { source, map };
    }
 
    /**
     * @param {Options} options options
     * @param {OnChunk} onChunk called for each chunk of code
     * @param {OnSource} onSource called for each source
     * @param {OnName} onName called for each name
     * @returns {GeneratedSourceInfo} generated source info
     */
    streamChunks(options, onChunk, onSource, onName) {
        const key = options ? JSON.stringify(options) : "{}";
        if (
            this._cachedMaps.has(key) &&
            (this._cachedBuffer !== undefined || this._cachedSource !== undefined)
        ) {
            const { source, map } = this.sourceAndMap(options);
            if (map) {
                return streamChunksOfSourceMap(
                    /** @type {string} */
                    (source),
                    map,
                    onChunk,
                    onSource,
                    onName,
                    Boolean(options && options.finalSource),
                    true,
                );
            }
            return streamChunksOfRawSource(
                /** @type {string} */
                (source),
                onChunk,
                onSource,
                onName,
                Boolean(options && options.finalSource),
            );
        }
        const sourceAndMap = streamAndGetSourceAndMap(
            this.original(),
            options,
            onChunk,
            onSource,
            onName,
        );
        this._cachedSource = sourceAndMap.source;
        this._cachedMaps.set(key, {
            map: /** @type {RawSourceMap} */ (sourceAndMap.map),
            bufferedMap: undefined,
        });
        return sourceAndMap.result;
    }
 
    /**
     * @param {MapOptions=} options map options
     * @returns {RawSourceMap | null} map
     */
    map(options) {
        const key = options ? JSON.stringify(options) : "{}";
        const cacheEntry = this._cachedMaps.get(key);
        if (cacheEntry !== undefined) {
            return this._getMapFromCacheEntry(cacheEntry);
        }
        const map = this.original().map(options);
        this._cachedMaps.set(key, {
            map,
            bufferedMap: undefined,
        });
        return map;
    }
 
    /**
     * @param {HashLike} hash hash
     * @returns {void}
     */
    updateHash(hash) {
        if (this._cachedHashUpdate !== undefined) {
            for (const item of this._cachedHashUpdate) hash.update(item);
            return;
        }
        /** @type {(string | Buffer)[]} */
        const update = [];
        /** @type {string | undefined} */
        let currentString;
        const tracker = {
            /**
             * @param {string | Buffer} item item
             * @returns {void}
             */
            update: (item) => {
                if (typeof item === "string" && item.length < 10240) {
                    if (currentString === undefined) {
                        currentString = item;
                    } else {
                        currentString += item;
                        if (currentString.length > 102400) {
                            update.push(Buffer.from(currentString));
                            currentString = undefined;
                        }
                    }
                } else {
                    if (currentString !== undefined) {
                        update.push(Buffer.from(currentString));
                        currentString = undefined;
                    }
                    update.push(item);
                }
            },
        };
        this.original().updateHash(/** @type {HashLike} */ (tracker));
        if (currentString !== undefined) {
            update.push(Buffer.from(currentString));
        }
        for (const item of update) hash.update(item);
        this._cachedHashUpdate = update;
    }
}
 
module.exports = CachedSource;