@maple-design/shared-vue 0.0.0-stage → 1.1.1

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/README.md CHANGED
@@ -1,3 +1,15 @@
1
- # Temporary Holding Version
1
+ # Shared foundation utilities
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Independent Cedar / Maple copies follow the same runtime and type contract in `design-ui/standards/shared-foundation.md`.
4
+
5
+ The package exposes 41 explicit runtime utilities and the `MotionState` type. Array, DOM, function, motion, namespace, number, object, predicate and string modules remain tree-shakeable. Import types with `import type`; no wholesale rattail export or deprecated compatibility aliases are retained before the first public release.
6
+
7
+ Run `pnpm check:shared` from the repository root to build ESM / CJS and declarations in a temporary directory and verify behavior and bundle limits. Run `pnpm check:foundations` in the adjacent design-ui repository for cross-library source and type parity. See `THIRD_PARTY_NOTICES` for retained license attribution.
8
+
9
+ ## Motion duration
10
+
11
+ `motion` defaults an omitted duration to 300ms. Finite nonnegative durations are supported. Zero, negative and nonfinite durations complete at the target on the next scheduled frame, with one finished notification and no continuing frame loop. Pausing/resetting before that frame cancels completion. `useMotion` preserves an explicit numeric zero rather than replacing it with the default.
12
+
13
+ ## Decimal floor
14
+
15
+ `floor(value, precision)` returns a number rounded toward negative infinity, including scientific notation. Precision is an integer clamped to [-292, 292]; fractional and nonfinite precision falls back to 0. Omitted precision is 0. Negative precision rounds at tens/hundreds and larger decimal places. The number result does not retain trailing zeros. Nonfinite values and signed zero retain Math.floor behavior. Decimal digits are truncated before constructing the result to avoid scaling overflow or subnormal underflow. IEEE-754 representability still applies to the returned number.
@@ -0,0 +1,26 @@
1
+ Portions of the local shared utilities are adapted from rattail 1.0.17.
2
+ The original license follows.
3
+
4
+ rattail@1.0.17
5
+
6
+ The MIT License (MIT)
7
+
8
+ Copyright (c) 2024 varletjs
9
+
10
+ Permission is hereby granted, free of charge, to any person obtaining a copy
11
+ of this software and associated documentation files (the "Software"), to deal
12
+ in the Software without restriction, including without limitation the rights
13
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
+ copies of the Software, and to permit persons to whom the Software is
15
+ furnished to do so, subject to the following conditions:
16
+
17
+ The above copyright notice and this permission notice shall be included in all
18
+ copies or substantial portions of the Software.
19
+
20
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
+ SOFTWARE.
package/lib/index.cjs ADDED
@@ -0,0 +1,559 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __defProps = Object.defineProperties;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
8
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
10
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
11
+ var __spreadValues = (a, b) => {
12
+ for (var prop in b || (b = {}))
13
+ if (__hasOwnProp.call(b, prop))
14
+ __defNormalProp(a, prop, b[prop]);
15
+ if (__getOwnPropSymbols)
16
+ for (var prop of __getOwnPropSymbols(b)) {
17
+ if (__propIsEnum.call(b, prop))
18
+ __defNormalProp(a, prop, b[prop]);
19
+ }
20
+ return a;
21
+ };
22
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
23
+ var __export = (target, all) => {
24
+ for (var name in all)
25
+ __defProp(target, name, { get: all[name], enumerable: true });
26
+ };
27
+ var __copyProps = (to, from, except, desc) => {
28
+ if (from && typeof from === "object" || typeof from === "function") {
29
+ for (let key of __getOwnPropNames(from))
30
+ if (!__hasOwnProp.call(to, key) && key !== except)
31
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
32
+ }
33
+ return to;
34
+ };
35
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
36
+
37
+ // src/index.ts
38
+ var src_exports = {};
39
+ __export(src_exports, {
40
+ assert: () => assert,
41
+ call: () => call,
42
+ camelize: () => camelize,
43
+ clamp: () => clamp,
44
+ clampArrayRange: () => clampArrayRange,
45
+ cloneDeep: () => cloneDeep,
46
+ createNamespaceFn: () => createNamespaceFn,
47
+ doubleRaf: () => doubleRaf,
48
+ error: () => error,
49
+ floor: () => floor,
50
+ getRect: () => getRect,
51
+ getScrollLeft: () => getScrollLeft,
52
+ getScrollTop: () => getScrollTop,
53
+ getStyle: () => getStyle,
54
+ hasOwn: () => hasOwn,
55
+ inBrowser: () => inBrowser,
56
+ inMobile: () => inMobile,
57
+ inViewport: () => inViewport,
58
+ isArray: () => isArray,
59
+ isBoolean: () => isBoolean,
60
+ isEmpty: () => isEmpty,
61
+ isFunction: () => isFunction,
62
+ isNumber: () => isNumber,
63
+ isNumeric: () => isNumeric,
64
+ isObject: () => isObject,
65
+ isPlainObject: () => isPlainObject,
66
+ isString: () => isString,
67
+ isWindow: () => isWindow,
68
+ kebabCase: () => kebabCase,
69
+ mergeWith: () => mergeWith,
70
+ motion: () => motion,
71
+ normalizeToArray: () => normalizeToArray,
72
+ pascalCase: () => pascalCase,
73
+ preventDefault: () => preventDefault,
74
+ raf: () => raf,
75
+ removeItem: () => removeItem,
76
+ slash: () => slash,
77
+ supportTouch: () => supportTouch,
78
+ throttle: () => throttle,
79
+ toNumber: () => toNumber,
80
+ uniq: () => uniq
81
+ });
82
+ module.exports = __toCommonJS(src_exports);
83
+
84
+ // src/predicates.ts
85
+ function inBrowser() {
86
+ return typeof window !== "undefined";
87
+ }
88
+ function inMobile() {
89
+ return inBrowser() && /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
90
+ }
91
+ function hasOwn(value, key) {
92
+ return Object.prototype.hasOwnProperty.call(value, key);
93
+ }
94
+ function isArray(value) {
95
+ return Array.isArray(value);
96
+ }
97
+ function isBoolean(value) {
98
+ return typeof value === "boolean";
99
+ }
100
+ function isFunction(value) {
101
+ return typeof value === "function";
102
+ }
103
+ function isNumber(value) {
104
+ return typeof value === "number";
105
+ }
106
+ function isString(value) {
107
+ return typeof value === "string";
108
+ }
109
+ function isNumeric(value) {
110
+ return typeof value === "number" || typeof value === "string" && /^[-+]?\d+$/.test(value);
111
+ }
112
+ function isObject(value) {
113
+ return typeof value === "object" && value !== null;
114
+ }
115
+ function toRawType(value) {
116
+ return Object.prototype.toString.call(value).slice(8, -1);
117
+ }
118
+ function isPlainObject(value) {
119
+ return Object.prototype.toString.call(value) === "[object Object]";
120
+ }
121
+ function isEmpty(value) {
122
+ return value === void 0 || value === null || value === "" || isArray(value) && !value.length;
123
+ }
124
+ function isWindow(value) {
125
+ return value === window;
126
+ }
127
+ function supportTouch() {
128
+ return inBrowser() && "ontouchstart" in window;
129
+ }
130
+
131
+ // src/array.ts
132
+ function removeItem(array, item) {
133
+ if (array.length) {
134
+ const index = array.indexOf(item);
135
+ if (index > -1) {
136
+ return array.splice(index, 1);
137
+ }
138
+ }
139
+ }
140
+ function uniq(array) {
141
+ return [...new Set(array)];
142
+ }
143
+ function normalizeToArray(value) {
144
+ return isArray(value) ? value : [value];
145
+ }
146
+
147
+ // src/dom.ts
148
+ function getGlobalThis() {
149
+ if (typeof globalThis !== "undefined") {
150
+ return globalThis;
151
+ }
152
+ if (inBrowser()) {
153
+ return window;
154
+ }
155
+ return typeof global !== "undefined" ? global : self;
156
+ }
157
+ function requestFrame(callback) {
158
+ const target = getGlobalThis();
159
+ return target.requestAnimationFrame ? target.requestAnimationFrame(callback) : target.setTimeout(callback);
160
+ }
161
+ function cancelFrame(handle) {
162
+ const target = getGlobalThis();
163
+ if (target.cancelAnimationFrame) {
164
+ target.cancelAnimationFrame(handle);
165
+ } else {
166
+ target.clearTimeout(handle);
167
+ }
168
+ }
169
+ function raf() {
170
+ return new Promise((resolve) => requestFrame(resolve));
171
+ }
172
+ function doubleRaf() {
173
+ return new Promise((resolve) => requestFrame(() => requestFrame(resolve)));
174
+ }
175
+ function getStyle(element) {
176
+ return window.getComputedStyle(element);
177
+ }
178
+ function getRect(element) {
179
+ if (isWindow(element)) {
180
+ const width = element.innerWidth;
181
+ const height = element.innerHeight;
182
+ const rect = { x: 0, y: 0, top: 0, left: 0, right: width, bottom: height, width, height };
183
+ return __spreadProps(__spreadValues({}, rect), { toJSON: () => rect });
184
+ }
185
+ return element.getBoundingClientRect();
186
+ }
187
+ function getScrollLeft(element) {
188
+ return Math.max("scrollLeft" in element ? element.scrollLeft : element.scrollX, 0);
189
+ }
190
+ function getScrollTop(element) {
191
+ return Math.max("scrollTop" in element ? element.scrollTop : element.scrollY, 0);
192
+ }
193
+ function inViewport(element) {
194
+ const { top, bottom, left, right } = getRect(element);
195
+ const { width, height } = getRect(window);
196
+ return left <= width && right >= 0 && top <= height && bottom >= 0;
197
+ }
198
+ function preventDefault(event) {
199
+ if (event.cancelable !== false) {
200
+ event.preventDefault();
201
+ }
202
+ }
203
+
204
+ // src/function.ts
205
+ function call(fn, ...args) {
206
+ if (isArray(fn)) {
207
+ return fn.map((callback) => callback(...args));
208
+ }
209
+ if (fn) {
210
+ return fn(...args);
211
+ }
212
+ }
213
+ function throttle(fn, delay = 200) {
214
+ let timer;
215
+ let start = 0;
216
+ return function loop(...args) {
217
+ const now = performance.now();
218
+ const elapsed = now - start;
219
+ if (!start) {
220
+ start = now;
221
+ }
222
+ if (timer) {
223
+ clearTimeout(timer);
224
+ }
225
+ if (elapsed >= delay) {
226
+ fn.apply(this, args);
227
+ start = now;
228
+ } else {
229
+ timer = setTimeout(() => loop.apply(this, args), delay - elapsed);
230
+ }
231
+ };
232
+ }
233
+
234
+ // src/number.ts
235
+ function clamp(value, min, max) {
236
+ return Math.min(max, Math.max(min, value));
237
+ }
238
+ function clampArrayRange(index, array) {
239
+ return clamp(index, 0, array.length - 1);
240
+ }
241
+ function toNumber(value) {
242
+ if (value == null) {
243
+ return 0;
244
+ }
245
+ if (isString(value)) {
246
+ const number = parseFloat(value);
247
+ return Number.isNaN(number) ? 0 : number;
248
+ }
249
+ return isBoolean(value) ? Number(value) : value;
250
+ }
251
+ function floor(value, precision = 0) {
252
+ precision = Number.isInteger(precision) ? clamp(precision, -292, 292) : 0;
253
+ if (!precision || !Number.isFinite(value) || value === 0) {
254
+ return Math.floor(value);
255
+ }
256
+ const [coefficient, exponent = "0"] = Math.abs(value).toString().split("e");
257
+ const point = coefficient.indexOf(".");
258
+ const digits = coefficient.replace(".", "");
259
+ const keep = (point < 0 ? coefficient.length : point) + Number(exponent) + precision;
260
+ if (keep >= digits.length) {
261
+ return value;
262
+ }
263
+ let integer = keep > 0 ? digits.slice(0, keep) : "0";
264
+ const remainder = keep > 0 ? digits.slice(keep) : digits;
265
+ if (value < 0 && /[1-9]/.test(remainder)) {
266
+ integer = incrementDecimalDigits(integer);
267
+ }
268
+ const result = Number(`${integer}e${-precision}`);
269
+ return value < 0 ? -result : result;
270
+ }
271
+ function incrementDecimalDigits(value) {
272
+ const digits = value.split("");
273
+ for (let index = digits.length - 1; index >= 0; index--) {
274
+ if (digits[index] !== "9") {
275
+ digits[index] = String(Number(digits[index]) + 1);
276
+ return digits.join("");
277
+ }
278
+ digits[index] = "0";
279
+ }
280
+ return `1${digits.join("")}`;
281
+ }
282
+
283
+ // src/motion.ts
284
+ function motion(options) {
285
+ const {
286
+ from,
287
+ to,
288
+ duration = 300,
289
+ frame = () => {
290
+ },
291
+ timingFunction = (value2) => value2,
292
+ onStateChange = () => {
293
+ }
294
+ } = options;
295
+ const safeDuration = Number.isFinite(duration) && duration >= 0 ? duration : 0;
296
+ let state = "pending";
297
+ let value = from;
298
+ const distance = to - from;
299
+ let ticker;
300
+ let startTime;
301
+ let pausedTime;
302
+ let sleepTime = 0;
303
+ function setState(next) {
304
+ state = next;
305
+ onStateChange(next);
306
+ }
307
+ function start() {
308
+ if (state === "running" || state === "finished") {
309
+ return;
310
+ }
311
+ setState("running");
312
+ const now = performance.now();
313
+ startTime = startTime != null ? startTime : now;
314
+ sleepTime += pausedTime != null ? now - pausedTime : 0;
315
+ pausedTime = void 0;
316
+ tick();
317
+ function tick() {
318
+ ticker = requestFrame(() => {
319
+ const elapsed = performance.now() - startTime - sleepTime;
320
+ const progress = safeDuration === 0 ? 1 : clamp(elapsed / safeDuration, 0, 1);
321
+ value = distance * timingFunction(progress) + from;
322
+ if (progress >= 1) {
323
+ setState("finished");
324
+ frame({ value: to, done: true });
325
+ return;
326
+ }
327
+ frame({ value, done: false });
328
+ tick();
329
+ });
330
+ }
331
+ }
332
+ function pause() {
333
+ if (state !== "running") {
334
+ return;
335
+ }
336
+ cancelFrame(ticker);
337
+ setState("paused");
338
+ pausedTime = performance.now();
339
+ }
340
+ function reset() {
341
+ cancelFrame(ticker);
342
+ setState("pending");
343
+ value = from;
344
+ ticker = void 0;
345
+ startTime = void 0;
346
+ pausedTime = void 0;
347
+ sleepTime = 0;
348
+ }
349
+ return { start, pause, reset, getState: () => state };
350
+ }
351
+
352
+ // src/string.ts
353
+ function camelize(value) {
354
+ return value.replace(/-(\w)/g, (_, character) => character.toUpperCase()).replace(/^./, (character) => character.toLowerCase());
355
+ }
356
+ function kebabCase(value) {
357
+ return value.replace(/([A-Z])/g, " $1").trim().split(" ").join("-").toLowerCase();
358
+ }
359
+ function pascalCase(value) {
360
+ const first = value.charAt(0);
361
+ return value.replace(/-(\w)/g, (_, character) => character.toUpperCase()).replace(/^./, (character) => character.toLowerCase()).replace(first, first.toUpperCase());
362
+ }
363
+ function slash(path) {
364
+ return path.startsWith("\\\\?\\") ? path : path.replace(/\\/g, "/");
365
+ }
366
+
367
+ // src/namespace.ts
368
+ function createNamespaceFn(namespace) {
369
+ return (name) => {
370
+ const componentName = `${namespace}-${name}`;
371
+ return {
372
+ name: pascalCase(componentName),
373
+ n(suffix) {
374
+ return !suffix ? componentName : suffix[0] === "$" ? suffix.replace("$", namespace) : suffix.startsWith("--") ? componentName + suffix : componentName + "__" + suffix;
375
+ },
376
+ classes(...names) {
377
+ return names.map((name2) => {
378
+ var _a;
379
+ if (Array.isArray(name2)) {
380
+ return name2[0] ? name2[1] : (_a = name2[2]) != null ? _a : null;
381
+ }
382
+ return name2;
383
+ });
384
+ }
385
+ };
386
+ };
387
+ }
388
+
389
+ // src/object.ts
390
+ function cloneDeep(value) {
391
+ const cache = /* @__PURE__ */ new WeakMap();
392
+ function clone(value2) {
393
+ if (!isObject(value2)) {
394
+ return value2;
395
+ }
396
+ if (cache.has(value2)) {
397
+ return cache.get(value2);
398
+ }
399
+ const type = toRawType(value2);
400
+ if (type === "Date") {
401
+ return new Date(value2);
402
+ }
403
+ if (type === "RegExp") {
404
+ return new RegExp(value2);
405
+ }
406
+ if (type === "Map") {
407
+ const result = /* @__PURE__ */ new Map();
408
+ cache.set(value2, result);
409
+ value2.forEach((entry, key) => result.set(clone(key), clone(entry)));
410
+ return result;
411
+ }
412
+ if (type === "Set") {
413
+ const result = /* @__PURE__ */ new Set();
414
+ cache.set(value2, result);
415
+ value2.forEach((entry) => result.add(clone(entry)));
416
+ return result;
417
+ }
418
+ if (type === "String" || type === "Number" || type === "Boolean") {
419
+ return newInstance(value2, value2.valueOf());
420
+ }
421
+ if (type === "WeakMap" || type === "WeakSet" || type === "Error" || type === "DOMException") {
422
+ return {};
423
+ }
424
+ if ([
425
+ "Int8Array",
426
+ "Uint8Array",
427
+ "Uint8ClampedArray",
428
+ "Int16Array",
429
+ "Uint16Array",
430
+ "Int32Array",
431
+ "Uint32Array",
432
+ "Float32Array",
433
+ "Float64Array",
434
+ "BigInt64Array",
435
+ "BigUint64Array"
436
+ ].includes(type)) {
437
+ return newInstance(value2, cloneBuffer(value2.buffer), value2.byteOffset, value2.length);
438
+ }
439
+ if (type === "DataView") {
440
+ return newInstance(value2, cloneBuffer(value2.buffer), value2.byteOffset, value2.byteLength);
441
+ }
442
+ if (type === "ArrayBuffer") {
443
+ return cloneBuffer(value2);
444
+ }
445
+ if (isArray(value2)) {
446
+ const result = [];
447
+ cache.set(value2, result);
448
+ value2.forEach((entry, index) => {
449
+ result[index] = clone(entry);
450
+ });
451
+ return result;
452
+ }
453
+ if (isPlainObject(value2)) {
454
+ const result = Object.create(Reflect.getPrototypeOf(value2));
455
+ cache.set(value2, result);
456
+ const keys = [...Object.keys(value2), ...Object.getOwnPropertySymbols(value2)];
457
+ keys.forEach((key) => {
458
+ result[key] = clone(value2[key]);
459
+ });
460
+ return result;
461
+ }
462
+ return value2;
463
+ }
464
+ function newInstance(value2, ...args) {
465
+ const Constructor = value2.constructor;
466
+ return new Constructor(...args);
467
+ }
468
+ function cloneBuffer(buffer) {
469
+ const result = new ArrayBuffer(buffer.byteLength);
470
+ new Uint8Array(result).set(new Uint8Array(buffer));
471
+ return result;
472
+ }
473
+ return clone(value);
474
+ }
475
+ function mergeWith(object, ...sources) {
476
+ const customizer = sources[sources.length - 1];
477
+ const targets = [object, ...sources.slice(0, -1)];
478
+ let index = targets.length - 1;
479
+ let result = targets[index];
480
+ while (index) {
481
+ result = mergeSource(targets[index - 1], result);
482
+ index--;
483
+ }
484
+ function mergeSource(object2, source) {
485
+ function merge(target, sourceValue) {
486
+ for (const key in sourceValue) {
487
+ if (hasOwn(sourceValue, key)) {
488
+ const value = sourceValue[key];
489
+ const previous = target[key];
490
+ const replacement = customizer(previous, value, key, object2, source);
491
+ if (replacement !== void 0) {
492
+ target[key] = replacement;
493
+ } else if (isObject(value)) {
494
+ target[key] = merge(isObject(previous) ? previous : isArray(value) ? [] : {}, value);
495
+ } else {
496
+ target[key] = value;
497
+ }
498
+ }
499
+ }
500
+ return target;
501
+ }
502
+ return merge(object2, source);
503
+ }
504
+ return result;
505
+ }
506
+
507
+ // src/index.ts
508
+ function assert(condition, source, message) {
509
+ if (!condition) {
510
+ throw new Error(`Maple [${source}]: ${message}`);
511
+ }
512
+ }
513
+ function error(source, message) {
514
+ console.error(`Maple [${source}]: ${message}`);
515
+ }
516
+ // Annotate the CommonJS export names for ESM import in node:
517
+ 0 && (module.exports = {
518
+ assert,
519
+ call,
520
+ camelize,
521
+ clamp,
522
+ clampArrayRange,
523
+ cloneDeep,
524
+ createNamespaceFn,
525
+ doubleRaf,
526
+ error,
527
+ floor,
528
+ getRect,
529
+ getScrollLeft,
530
+ getScrollTop,
531
+ getStyle,
532
+ hasOwn,
533
+ inBrowser,
534
+ inMobile,
535
+ inViewport,
536
+ isArray,
537
+ isBoolean,
538
+ isEmpty,
539
+ isFunction,
540
+ isNumber,
541
+ isNumeric,
542
+ isObject,
543
+ isPlainObject,
544
+ isString,
545
+ isWindow,
546
+ kebabCase,
547
+ mergeWith,
548
+ motion,
549
+ normalizeToArray,
550
+ pascalCase,
551
+ preventDefault,
552
+ raf,
553
+ removeItem,
554
+ slash,
555
+ supportTouch,
556
+ throttle,
557
+ toNumber,
558
+ uniq
559
+ });
@@ -0,0 +1,77 @@
1
+ declare function removeItem<T>(array: T[], item: T): T[] | undefined;
2
+ declare function uniq<T>(array: T[]): T[];
3
+ declare function normalizeToArray<T>(value: T | T[]): T[];
4
+
5
+ declare function raf(): Promise<unknown>;
6
+ declare function doubleRaf(): Promise<unknown>;
7
+ declare function getStyle(element: Element): CSSStyleDeclaration;
8
+ declare function getRect(element: Element | Window): DOMRect;
9
+ declare function getScrollLeft(element: Element | Window): number;
10
+ declare function getScrollTop(element: Element | Window): number;
11
+ declare function inViewport(element: HTMLElement): boolean;
12
+ declare function preventDefault(event: Event): void;
13
+
14
+ declare function call<P extends any[], R>(fn?: ((...args: P) => R) | ((...args: P) => R)[] | null, ...args: P): R | R[] | undefined;
15
+ declare function throttle<F extends (...args: any[]) => any>(fn: F, delay?: number): (this: unknown, ...args: Parameters<F>) => void;
16
+
17
+ type MotionState = 'running' | 'paused' | 'pending' | 'finished';
18
+ interface MotionOptions {
19
+ from: number;
20
+ to: number;
21
+ duration?: number;
22
+ frame?: (frame: {
23
+ value: number;
24
+ done: boolean;
25
+ }) => void;
26
+ timingFunction?: (progress: number) => number;
27
+ onStateChange?: (state: MotionState) => void;
28
+ }
29
+ declare function motion(options: MotionOptions): {
30
+ start: () => void;
31
+ pause: () => void;
32
+ reset: () => void;
33
+ getState: () => MotionState;
34
+ };
35
+
36
+ type ClassName = string | undefined | null;
37
+ type Classes = (ClassName | [any, ClassName, ClassName?])[];
38
+ type BEM<S extends string | undefined, N extends string, NC extends string> = S extends undefined ? NC : S extends `$--${infer CM}` ? `${N}--${CM}` : S extends `--${infer M}` ? `${NC}--${M}` : `${NC}__${S}`;
39
+ declare function createNamespaceFn<N extends string>(namespace: N): <C extends string>(name: C) => {
40
+ name: string;
41
+ n<S extends string | undefined = undefined>(suffix?: S | undefined): BEM<S, N, `${N}-${C}`>;
42
+ classes(...names: Classes): any[];
43
+ };
44
+
45
+ declare function clamp(value: number, min: number, max: number): number;
46
+ declare function clampArrayRange(index: number, array: unknown[]): number;
47
+ declare function toNumber(value: number | string | boolean | undefined | null): number;
48
+ declare function floor(value: number, precision?: number): number;
49
+
50
+ declare function cloneDeep<T>(value: T): T;
51
+ type MergeCustomizer = (targetValue: any, sourceValue: any, key: string | number | symbol, object?: any, source?: any) => any;
52
+ declare function mergeWith<T extends Record<string, any>, K extends Record<string, any>>(object: T, ...sources: [...K[], customizer: MergeCustomizer]): T & K;
53
+
54
+ declare function inBrowser(): boolean;
55
+ declare function inMobile(): boolean;
56
+ declare function hasOwn<T extends object>(value: T, key: PropertyKey): key is keyof T;
57
+ declare function isArray(value: unknown): value is any[];
58
+ declare function isBoolean(value: unknown): value is boolean;
59
+ declare function isFunction(value: unknown): value is (...args: any[]) => any;
60
+ declare function isNumber(value: unknown): value is number;
61
+ declare function isString(value: unknown): value is string;
62
+ declare function isNumeric(value: unknown): value is number | string;
63
+ declare function isObject(value: unknown): value is Record<string, any>;
64
+ declare function isPlainObject(value: unknown): value is Record<string, any>;
65
+ declare function isEmpty(value: unknown): boolean;
66
+ declare function isWindow(value: unknown): value is Window;
67
+ declare function supportTouch(): boolean;
68
+
69
+ declare function camelize(value: string): string;
70
+ declare function kebabCase(value: string): string;
71
+ declare function pascalCase(value: string): string;
72
+ declare function slash(path: string): string;
73
+
74
+ declare function assert(condition: boolean, source: string, message: string): asserts condition;
75
+ declare function error(source: string, message: string): void;
76
+
77
+ export { MotionState, assert, call, camelize, clamp, clampArrayRange, cloneDeep, createNamespaceFn, doubleRaf, error, floor, getRect, getScrollLeft, getScrollTop, getStyle, hasOwn, inBrowser, inMobile, inViewport, isArray, isBoolean, isEmpty, isFunction, isNumber, isNumeric, isObject, isPlainObject, isString, isWindow, kebabCase, mergeWith, motion, normalizeToArray, pascalCase, preventDefault, raf, removeItem, slash, supportTouch, throttle, toNumber, uniq };
package/lib/index.d.ts ADDED
@@ -0,0 +1,77 @@
1
+ declare function removeItem<T>(array: T[], item: T): T[] | undefined;
2
+ declare function uniq<T>(array: T[]): T[];
3
+ declare function normalizeToArray<T>(value: T | T[]): T[];
4
+
5
+ declare function raf(): Promise<unknown>;
6
+ declare function doubleRaf(): Promise<unknown>;
7
+ declare function getStyle(element: Element): CSSStyleDeclaration;
8
+ declare function getRect(element: Element | Window): DOMRect;
9
+ declare function getScrollLeft(element: Element | Window): number;
10
+ declare function getScrollTop(element: Element | Window): number;
11
+ declare function inViewport(element: HTMLElement): boolean;
12
+ declare function preventDefault(event: Event): void;
13
+
14
+ declare function call<P extends any[], R>(fn?: ((...args: P) => R) | ((...args: P) => R)[] | null, ...args: P): R | R[] | undefined;
15
+ declare function throttle<F extends (...args: any[]) => any>(fn: F, delay?: number): (this: unknown, ...args: Parameters<F>) => void;
16
+
17
+ type MotionState = 'running' | 'paused' | 'pending' | 'finished';
18
+ interface MotionOptions {
19
+ from: number;
20
+ to: number;
21
+ duration?: number;
22
+ frame?: (frame: {
23
+ value: number;
24
+ done: boolean;
25
+ }) => void;
26
+ timingFunction?: (progress: number) => number;
27
+ onStateChange?: (state: MotionState) => void;
28
+ }
29
+ declare function motion(options: MotionOptions): {
30
+ start: () => void;
31
+ pause: () => void;
32
+ reset: () => void;
33
+ getState: () => MotionState;
34
+ };
35
+
36
+ type ClassName = string | undefined | null;
37
+ type Classes = (ClassName | [any, ClassName, ClassName?])[];
38
+ type BEM<S extends string | undefined, N extends string, NC extends string> = S extends undefined ? NC : S extends `$--${infer CM}` ? `${N}--${CM}` : S extends `--${infer M}` ? `${NC}--${M}` : `${NC}__${S}`;
39
+ declare function createNamespaceFn<N extends string>(namespace: N): <C extends string>(name: C) => {
40
+ name: string;
41
+ n<S extends string | undefined = undefined>(suffix?: S | undefined): BEM<S, N, `${N}-${C}`>;
42
+ classes(...names: Classes): any[];
43
+ };
44
+
45
+ declare function clamp(value: number, min: number, max: number): number;
46
+ declare function clampArrayRange(index: number, array: unknown[]): number;
47
+ declare function toNumber(value: number | string | boolean | undefined | null): number;
48
+ declare function floor(value: number, precision?: number): number;
49
+
50
+ declare function cloneDeep<T>(value: T): T;
51
+ type MergeCustomizer = (targetValue: any, sourceValue: any, key: string | number | symbol, object?: any, source?: any) => any;
52
+ declare function mergeWith<T extends Record<string, any>, K extends Record<string, any>>(object: T, ...sources: [...K[], customizer: MergeCustomizer]): T & K;
53
+
54
+ declare function inBrowser(): boolean;
55
+ declare function inMobile(): boolean;
56
+ declare function hasOwn<T extends object>(value: T, key: PropertyKey): key is keyof T;
57
+ declare function isArray(value: unknown): value is any[];
58
+ declare function isBoolean(value: unknown): value is boolean;
59
+ declare function isFunction(value: unknown): value is (...args: any[]) => any;
60
+ declare function isNumber(value: unknown): value is number;
61
+ declare function isString(value: unknown): value is string;
62
+ declare function isNumeric(value: unknown): value is number | string;
63
+ declare function isObject(value: unknown): value is Record<string, any>;
64
+ declare function isPlainObject(value: unknown): value is Record<string, any>;
65
+ declare function isEmpty(value: unknown): boolean;
66
+ declare function isWindow(value: unknown): value is Window;
67
+ declare function supportTouch(): boolean;
68
+
69
+ declare function camelize(value: string): string;
70
+ declare function kebabCase(value: string): string;
71
+ declare function pascalCase(value: string): string;
72
+ declare function slash(path: string): string;
73
+
74
+ declare function assert(condition: boolean, source: string, message: string): asserts condition;
75
+ declare function error(source: string, message: string): void;
76
+
77
+ export { MotionState, assert, call, camelize, clamp, clampArrayRange, cloneDeep, createNamespaceFn, doubleRaf, error, floor, getRect, getScrollLeft, getScrollTop, getStyle, hasOwn, inBrowser, inMobile, inViewport, isArray, isBoolean, isEmpty, isFunction, isNumber, isNumeric, isObject, isPlainObject, isString, isWindow, kebabCase, mergeWith, motion, normalizeToArray, pascalCase, preventDefault, raf, removeItem, slash, supportTouch, throttle, toNumber, uniq };
package/lib/index.js ADDED
@@ -0,0 +1,495 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defProps = Object.defineProperties;
3
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
+ var __spreadValues = (a, b) => {
9
+ for (var prop in b || (b = {}))
10
+ if (__hasOwnProp.call(b, prop))
11
+ __defNormalProp(a, prop, b[prop]);
12
+ if (__getOwnPropSymbols)
13
+ for (var prop of __getOwnPropSymbols(b)) {
14
+ if (__propIsEnum.call(b, prop))
15
+ __defNormalProp(a, prop, b[prop]);
16
+ }
17
+ return a;
18
+ };
19
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
+
21
+ // src/predicates.ts
22
+ function inBrowser() {
23
+ return typeof window !== "undefined";
24
+ }
25
+ function inMobile() {
26
+ return inBrowser() && /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
27
+ }
28
+ function hasOwn(value, key) {
29
+ return Object.prototype.hasOwnProperty.call(value, key);
30
+ }
31
+ function isArray(value) {
32
+ return Array.isArray(value);
33
+ }
34
+ function isBoolean(value) {
35
+ return typeof value === "boolean";
36
+ }
37
+ function isFunction(value) {
38
+ return typeof value === "function";
39
+ }
40
+ function isNumber(value) {
41
+ return typeof value === "number";
42
+ }
43
+ function isString(value) {
44
+ return typeof value === "string";
45
+ }
46
+ function isNumeric(value) {
47
+ return typeof value === "number" || typeof value === "string" && /^[-+]?\d+$/.test(value);
48
+ }
49
+ function isObject(value) {
50
+ return typeof value === "object" && value !== null;
51
+ }
52
+ function toRawType(value) {
53
+ return Object.prototype.toString.call(value).slice(8, -1);
54
+ }
55
+ function isPlainObject(value) {
56
+ return Object.prototype.toString.call(value) === "[object Object]";
57
+ }
58
+ function isEmpty(value) {
59
+ return value === void 0 || value === null || value === "" || isArray(value) && !value.length;
60
+ }
61
+ function isWindow(value) {
62
+ return value === window;
63
+ }
64
+ function supportTouch() {
65
+ return inBrowser() && "ontouchstart" in window;
66
+ }
67
+
68
+ // src/array.ts
69
+ function removeItem(array, item) {
70
+ if (array.length) {
71
+ const index = array.indexOf(item);
72
+ if (index > -1) {
73
+ return array.splice(index, 1);
74
+ }
75
+ }
76
+ }
77
+ function uniq(array) {
78
+ return [...new Set(array)];
79
+ }
80
+ function normalizeToArray(value) {
81
+ return isArray(value) ? value : [value];
82
+ }
83
+
84
+ // src/dom.ts
85
+ function getGlobalThis() {
86
+ if (typeof globalThis !== "undefined") {
87
+ return globalThis;
88
+ }
89
+ if (inBrowser()) {
90
+ return window;
91
+ }
92
+ return typeof global !== "undefined" ? global : self;
93
+ }
94
+ function requestFrame(callback) {
95
+ const target = getGlobalThis();
96
+ return target.requestAnimationFrame ? target.requestAnimationFrame(callback) : target.setTimeout(callback);
97
+ }
98
+ function cancelFrame(handle) {
99
+ const target = getGlobalThis();
100
+ if (target.cancelAnimationFrame) {
101
+ target.cancelAnimationFrame(handle);
102
+ } else {
103
+ target.clearTimeout(handle);
104
+ }
105
+ }
106
+ function raf() {
107
+ return new Promise((resolve) => requestFrame(resolve));
108
+ }
109
+ function doubleRaf() {
110
+ return new Promise((resolve) => requestFrame(() => requestFrame(resolve)));
111
+ }
112
+ function getStyle(element) {
113
+ return window.getComputedStyle(element);
114
+ }
115
+ function getRect(element) {
116
+ if (isWindow(element)) {
117
+ const width = element.innerWidth;
118
+ const height = element.innerHeight;
119
+ const rect = { x: 0, y: 0, top: 0, left: 0, right: width, bottom: height, width, height };
120
+ return __spreadProps(__spreadValues({}, rect), { toJSON: () => rect });
121
+ }
122
+ return element.getBoundingClientRect();
123
+ }
124
+ function getScrollLeft(element) {
125
+ return Math.max("scrollLeft" in element ? element.scrollLeft : element.scrollX, 0);
126
+ }
127
+ function getScrollTop(element) {
128
+ return Math.max("scrollTop" in element ? element.scrollTop : element.scrollY, 0);
129
+ }
130
+ function inViewport(element) {
131
+ const { top, bottom, left, right } = getRect(element);
132
+ const { width, height } = getRect(window);
133
+ return left <= width && right >= 0 && top <= height && bottom >= 0;
134
+ }
135
+ function preventDefault(event) {
136
+ if (event.cancelable !== false) {
137
+ event.preventDefault();
138
+ }
139
+ }
140
+
141
+ // src/function.ts
142
+ function call(fn, ...args) {
143
+ if (isArray(fn)) {
144
+ return fn.map((callback) => callback(...args));
145
+ }
146
+ if (fn) {
147
+ return fn(...args);
148
+ }
149
+ }
150
+ function throttle(fn, delay = 200) {
151
+ let timer;
152
+ let start = 0;
153
+ return function loop(...args) {
154
+ const now = performance.now();
155
+ const elapsed = now - start;
156
+ if (!start) {
157
+ start = now;
158
+ }
159
+ if (timer) {
160
+ clearTimeout(timer);
161
+ }
162
+ if (elapsed >= delay) {
163
+ fn.apply(this, args);
164
+ start = now;
165
+ } else {
166
+ timer = setTimeout(() => loop.apply(this, args), delay - elapsed);
167
+ }
168
+ };
169
+ }
170
+
171
+ // src/number.ts
172
+ function clamp(value, min, max) {
173
+ return Math.min(max, Math.max(min, value));
174
+ }
175
+ function clampArrayRange(index, array) {
176
+ return clamp(index, 0, array.length - 1);
177
+ }
178
+ function toNumber(value) {
179
+ if (value == null) {
180
+ return 0;
181
+ }
182
+ if (isString(value)) {
183
+ const number = parseFloat(value);
184
+ return Number.isNaN(number) ? 0 : number;
185
+ }
186
+ return isBoolean(value) ? Number(value) : value;
187
+ }
188
+ function floor(value, precision = 0) {
189
+ precision = Number.isInteger(precision) ? clamp(precision, -292, 292) : 0;
190
+ if (!precision || !Number.isFinite(value) || value === 0) {
191
+ return Math.floor(value);
192
+ }
193
+ const [coefficient, exponent = "0"] = Math.abs(value).toString().split("e");
194
+ const point = coefficient.indexOf(".");
195
+ const digits = coefficient.replace(".", "");
196
+ const keep = (point < 0 ? coefficient.length : point) + Number(exponent) + precision;
197
+ if (keep >= digits.length) {
198
+ return value;
199
+ }
200
+ let integer = keep > 0 ? digits.slice(0, keep) : "0";
201
+ const remainder = keep > 0 ? digits.slice(keep) : digits;
202
+ if (value < 0 && /[1-9]/.test(remainder)) {
203
+ integer = incrementDecimalDigits(integer);
204
+ }
205
+ const result = Number(`${integer}e${-precision}`);
206
+ return value < 0 ? -result : result;
207
+ }
208
+ function incrementDecimalDigits(value) {
209
+ const digits = value.split("");
210
+ for (let index = digits.length - 1; index >= 0; index--) {
211
+ if (digits[index] !== "9") {
212
+ digits[index] = String(Number(digits[index]) + 1);
213
+ return digits.join("");
214
+ }
215
+ digits[index] = "0";
216
+ }
217
+ return `1${digits.join("")}`;
218
+ }
219
+
220
+ // src/motion.ts
221
+ function motion(options) {
222
+ const {
223
+ from,
224
+ to,
225
+ duration = 300,
226
+ frame = () => {
227
+ },
228
+ timingFunction = (value2) => value2,
229
+ onStateChange = () => {
230
+ }
231
+ } = options;
232
+ const safeDuration = Number.isFinite(duration) && duration >= 0 ? duration : 0;
233
+ let state = "pending";
234
+ let value = from;
235
+ const distance = to - from;
236
+ let ticker;
237
+ let startTime;
238
+ let pausedTime;
239
+ let sleepTime = 0;
240
+ function setState(next) {
241
+ state = next;
242
+ onStateChange(next);
243
+ }
244
+ function start() {
245
+ if (state === "running" || state === "finished") {
246
+ return;
247
+ }
248
+ setState("running");
249
+ const now = performance.now();
250
+ startTime = startTime != null ? startTime : now;
251
+ sleepTime += pausedTime != null ? now - pausedTime : 0;
252
+ pausedTime = void 0;
253
+ tick();
254
+ function tick() {
255
+ ticker = requestFrame(() => {
256
+ const elapsed = performance.now() - startTime - sleepTime;
257
+ const progress = safeDuration === 0 ? 1 : clamp(elapsed / safeDuration, 0, 1);
258
+ value = distance * timingFunction(progress) + from;
259
+ if (progress >= 1) {
260
+ setState("finished");
261
+ frame({ value: to, done: true });
262
+ return;
263
+ }
264
+ frame({ value, done: false });
265
+ tick();
266
+ });
267
+ }
268
+ }
269
+ function pause() {
270
+ if (state !== "running") {
271
+ return;
272
+ }
273
+ cancelFrame(ticker);
274
+ setState("paused");
275
+ pausedTime = performance.now();
276
+ }
277
+ function reset() {
278
+ cancelFrame(ticker);
279
+ setState("pending");
280
+ value = from;
281
+ ticker = void 0;
282
+ startTime = void 0;
283
+ pausedTime = void 0;
284
+ sleepTime = 0;
285
+ }
286
+ return { start, pause, reset, getState: () => state };
287
+ }
288
+
289
+ // src/string.ts
290
+ function camelize(value) {
291
+ return value.replace(/-(\w)/g, (_, character) => character.toUpperCase()).replace(/^./, (character) => character.toLowerCase());
292
+ }
293
+ function kebabCase(value) {
294
+ return value.replace(/([A-Z])/g, " $1").trim().split(" ").join("-").toLowerCase();
295
+ }
296
+ function pascalCase(value) {
297
+ const first = value.charAt(0);
298
+ return value.replace(/-(\w)/g, (_, character) => character.toUpperCase()).replace(/^./, (character) => character.toLowerCase()).replace(first, first.toUpperCase());
299
+ }
300
+ function slash(path) {
301
+ return path.startsWith("\\\\?\\") ? path : path.replace(/\\/g, "/");
302
+ }
303
+
304
+ // src/namespace.ts
305
+ function createNamespaceFn(namespace) {
306
+ return (name) => {
307
+ const componentName = `${namespace}-${name}`;
308
+ return {
309
+ name: pascalCase(componentName),
310
+ n(suffix) {
311
+ return !suffix ? componentName : suffix[0] === "$" ? suffix.replace("$", namespace) : suffix.startsWith("--") ? componentName + suffix : componentName + "__" + suffix;
312
+ },
313
+ classes(...names) {
314
+ return names.map((name2) => {
315
+ var _a;
316
+ if (Array.isArray(name2)) {
317
+ return name2[0] ? name2[1] : (_a = name2[2]) != null ? _a : null;
318
+ }
319
+ return name2;
320
+ });
321
+ }
322
+ };
323
+ };
324
+ }
325
+
326
+ // src/object.ts
327
+ function cloneDeep(value) {
328
+ const cache = /* @__PURE__ */ new WeakMap();
329
+ function clone(value2) {
330
+ if (!isObject(value2)) {
331
+ return value2;
332
+ }
333
+ if (cache.has(value2)) {
334
+ return cache.get(value2);
335
+ }
336
+ const type = toRawType(value2);
337
+ if (type === "Date") {
338
+ return new Date(value2);
339
+ }
340
+ if (type === "RegExp") {
341
+ return new RegExp(value2);
342
+ }
343
+ if (type === "Map") {
344
+ const result = /* @__PURE__ */ new Map();
345
+ cache.set(value2, result);
346
+ value2.forEach((entry, key) => result.set(clone(key), clone(entry)));
347
+ return result;
348
+ }
349
+ if (type === "Set") {
350
+ const result = /* @__PURE__ */ new Set();
351
+ cache.set(value2, result);
352
+ value2.forEach((entry) => result.add(clone(entry)));
353
+ return result;
354
+ }
355
+ if (type === "String" || type === "Number" || type === "Boolean") {
356
+ return newInstance(value2, value2.valueOf());
357
+ }
358
+ if (type === "WeakMap" || type === "WeakSet" || type === "Error" || type === "DOMException") {
359
+ return {};
360
+ }
361
+ if ([
362
+ "Int8Array",
363
+ "Uint8Array",
364
+ "Uint8ClampedArray",
365
+ "Int16Array",
366
+ "Uint16Array",
367
+ "Int32Array",
368
+ "Uint32Array",
369
+ "Float32Array",
370
+ "Float64Array",
371
+ "BigInt64Array",
372
+ "BigUint64Array"
373
+ ].includes(type)) {
374
+ return newInstance(value2, cloneBuffer(value2.buffer), value2.byteOffset, value2.length);
375
+ }
376
+ if (type === "DataView") {
377
+ return newInstance(value2, cloneBuffer(value2.buffer), value2.byteOffset, value2.byteLength);
378
+ }
379
+ if (type === "ArrayBuffer") {
380
+ return cloneBuffer(value2);
381
+ }
382
+ if (isArray(value2)) {
383
+ const result = [];
384
+ cache.set(value2, result);
385
+ value2.forEach((entry, index) => {
386
+ result[index] = clone(entry);
387
+ });
388
+ return result;
389
+ }
390
+ if (isPlainObject(value2)) {
391
+ const result = Object.create(Reflect.getPrototypeOf(value2));
392
+ cache.set(value2, result);
393
+ const keys = [...Object.keys(value2), ...Object.getOwnPropertySymbols(value2)];
394
+ keys.forEach((key) => {
395
+ result[key] = clone(value2[key]);
396
+ });
397
+ return result;
398
+ }
399
+ return value2;
400
+ }
401
+ function newInstance(value2, ...args) {
402
+ const Constructor = value2.constructor;
403
+ return new Constructor(...args);
404
+ }
405
+ function cloneBuffer(buffer) {
406
+ const result = new ArrayBuffer(buffer.byteLength);
407
+ new Uint8Array(result).set(new Uint8Array(buffer));
408
+ return result;
409
+ }
410
+ return clone(value);
411
+ }
412
+ function mergeWith(object, ...sources) {
413
+ const customizer = sources[sources.length - 1];
414
+ const targets = [object, ...sources.slice(0, -1)];
415
+ let index = targets.length - 1;
416
+ let result = targets[index];
417
+ while (index) {
418
+ result = mergeSource(targets[index - 1], result);
419
+ index--;
420
+ }
421
+ function mergeSource(object2, source) {
422
+ function merge(target, sourceValue) {
423
+ for (const key in sourceValue) {
424
+ if (hasOwn(sourceValue, key)) {
425
+ const value = sourceValue[key];
426
+ const previous = target[key];
427
+ const replacement = customizer(previous, value, key, object2, source);
428
+ if (replacement !== void 0) {
429
+ target[key] = replacement;
430
+ } else if (isObject(value)) {
431
+ target[key] = merge(isObject(previous) ? previous : isArray(value) ? [] : {}, value);
432
+ } else {
433
+ target[key] = value;
434
+ }
435
+ }
436
+ }
437
+ return target;
438
+ }
439
+ return merge(object2, source);
440
+ }
441
+ return result;
442
+ }
443
+
444
+ // src/index.ts
445
+ function assert(condition, source, message) {
446
+ if (!condition) {
447
+ throw new Error(`Maple [${source}]: ${message}`);
448
+ }
449
+ }
450
+ function error(source, message) {
451
+ console.error(`Maple [${source}]: ${message}`);
452
+ }
453
+ export {
454
+ assert,
455
+ call,
456
+ camelize,
457
+ clamp,
458
+ clampArrayRange,
459
+ cloneDeep,
460
+ createNamespaceFn,
461
+ doubleRaf,
462
+ error,
463
+ floor,
464
+ getRect,
465
+ getScrollLeft,
466
+ getScrollTop,
467
+ getStyle,
468
+ hasOwn,
469
+ inBrowser,
470
+ inMobile,
471
+ inViewport,
472
+ isArray,
473
+ isBoolean,
474
+ isEmpty,
475
+ isFunction,
476
+ isNumber,
477
+ isNumeric,
478
+ isObject,
479
+ isPlainObject,
480
+ isString,
481
+ isWindow,
482
+ kebabCase,
483
+ mergeWith,
484
+ motion,
485
+ normalizeToArray,
486
+ pascalCase,
487
+ preventDefault,
488
+ raf,
489
+ removeItem,
490
+ slash,
491
+ supportTouch,
492
+ throttle,
493
+ toNumber,
494
+ uniq
495
+ };
package/package.json CHANGED
@@ -1,6 +1,50 @@
1
1
  {
2
2
  "name": "@maple-design/shared-vue",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "1.1.1",
4
+ "description": "shared utils of maple",
5
+ "keywords": [
6
+ "shared",
7
+ "utils",
8
+ "maple"
9
+ ],
10
+ "bugs": {
11
+ "url": "https://github.com/loca-spirit/maple-design-mobile/issues"
12
+ },
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "git+https://github.com/loca-spirit/maple-design-mobile.git",
16
+ "directory": "packages/shared"
17
+ },
18
+ "license": "MIT",
19
+ "author": "shuai.meng",
20
+ "sideEffects": false,
21
+ "type": "module",
22
+ "exports": {
23
+ ".": {
24
+ "types": "./lib/index.d.ts",
25
+ "import": "./lib/index.js",
26
+ "require": "./lib/index.cjs"
27
+ }
28
+ },
29
+ "main": "lib/index.cjs",
30
+ "module": "lib/index.js",
31
+ "types": "lib/index.d.ts",
32
+ "files": [
33
+ "lib",
34
+ "THIRD_PARTY_NOTICES"
35
+ ],
36
+ "devDependencies": {
37
+ "@types/node": "^18.7.20",
38
+ "tsup": "7.2.0",
39
+ "typescript": "5.3.3"
40
+ },
41
+ "publishConfig": {
42
+ "access": "public",
43
+ "registry": "https://registry.npmjs.org/"
44
+ },
45
+ "scripts": {
46
+ "build": "tsup src/index.ts --format esm,cjs --out-dir=lib --dts --clean",
47
+ "dev": "tsup src/index.ts --format esm --out-dir=lib --watch --dts",
48
+ "test": "node --test ../../scripts/quality/shared-bundle.test.mjs"
49
+ }
6
50
  }