@mantou/gem 1.7.4 → 1.7.6
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/dist/gem.es.js +41 -19
- package/dist/gem.umd.js +22 -22
- package/elements/base/modal-factory.d.ts +1 -1
- package/elements/base/route.d.ts +3 -1
- package/elements/base/route.d.ts.map +1 -1
- package/elements/base/route.js +5 -2
- package/elements/base/route.js.map +1 -1
- package/elements/base/title.d.ts +8 -5
- package/elements/base/title.d.ts.map +1 -1
- package/elements/base/title.js +27 -17
- package/elements/base/title.js.map +1 -1
- package/lib/utils.d.ts +22 -4
- package/lib/utils.d.ts.map +1 -1
- package/lib/utils.js +100 -1
- package/lib/utils.js.map +1 -1
- package/lib/version.d.ts +1 -1
- package/lib/version.js +1 -1
- package/package.json +11 -7
- package/src/elements/base/route.ts +8 -3
- package/src/elements/base/title.ts +33 -20
- package/src/lib/utils.ts +114 -5
- package/src/lib/version.ts +1 -1
- package/src/test/utils.test.ts +24 -0
package/src/lib/utils.ts
CHANGED
|
@@ -91,6 +91,18 @@ export class LinkedList<T = any> extends EventTarget {
|
|
|
91
91
|
return this.#lastItem;
|
|
92
92
|
}
|
|
93
93
|
|
|
94
|
+
isSuperLinkOf(subLink: LinkedList<T>) {
|
|
95
|
+
let subItem = subLink.first;
|
|
96
|
+
if (!subItem) return true;
|
|
97
|
+
let item = this.find(subItem.value);
|
|
98
|
+
while (item && item.value === subItem.value) {
|
|
99
|
+
subItem = subItem.next;
|
|
100
|
+
if (!subItem) return true;
|
|
101
|
+
item = item.next;
|
|
102
|
+
}
|
|
103
|
+
return false;
|
|
104
|
+
}
|
|
105
|
+
|
|
94
106
|
find(value: T) {
|
|
95
107
|
return this.#map.get(value);
|
|
96
108
|
}
|
|
@@ -365,26 +377,123 @@ export function objectMapToString<T = any>(
|
|
|
365
377
|
return result;
|
|
366
378
|
}
|
|
367
379
|
|
|
368
|
-
|
|
380
|
+
// Wait: Typescript lib dom CSSStyleDeclaration anchor position
|
|
381
|
+
type StyleProp = keyof CSSStyleDeclaration | `--${string}` | 'anchorDefault' | 'anchorName';
|
|
369
382
|
|
|
370
|
-
export type StyleObject = Partial<Record<StyleProp, string | number | undefined>>;
|
|
383
|
+
export type StyleObject = Partial<Record<StyleProp, string | number | undefined | null>>;
|
|
371
384
|
|
|
372
385
|
// 不支持 webkit 属性
|
|
373
386
|
export function styleMap(object: StyleObject) {
|
|
374
387
|
return objectMapToString(object, ';', (key, value) =>
|
|
375
|
-
value !== undefined ? `${camelToKebabCase(key)}:${value}` : '',
|
|
388
|
+
value !== undefined && value !== null ? `${camelToKebabCase(key)}:${value}` : '',
|
|
376
389
|
);
|
|
377
390
|
}
|
|
378
391
|
|
|
379
|
-
export function classMap(object: Record<string, boolean | string | number | undefined>) {
|
|
392
|
+
export function classMap(object: Record<string, boolean | string | number | undefined | null>) {
|
|
380
393
|
return objectMapToString(object, ' ', (key, value) => (value ? key : ''));
|
|
381
394
|
}
|
|
382
395
|
|
|
383
396
|
export const partMap = classMap;
|
|
384
397
|
|
|
385
398
|
// https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/exportparts
|
|
386
|
-
export function exportPartsMap(object: Record<string, string | undefined |
|
|
399
|
+
export function exportPartsMap(object: Record<string, string | boolean | undefined | null>) {
|
|
387
400
|
return objectMapToString(object, ',', (key, value) =>
|
|
388
401
|
value === true || key === value ? key : value ? `${key}:${value}` : '',
|
|
389
402
|
);
|
|
390
403
|
}
|
|
404
|
+
|
|
405
|
+
declare global {
|
|
406
|
+
interface PropertyIndexedKeyframes extends StyleObject {}
|
|
407
|
+
interface Keyframe extends StyleObject {}
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
/**
|
|
411
|
+
* @example
|
|
412
|
+
* ```css
|
|
413
|
+
* animation: 150ms ease 0ms showMask;`
|
|
414
|
+
* @keyframes showMask {
|
|
415
|
+
* from {
|
|
416
|
+
* opacity: 0;
|
|
417
|
+
* }
|
|
418
|
+
* }
|
|
419
|
+
* ```
|
|
420
|
+
*/
|
|
421
|
+
// export function createCSSAnimation(
|
|
422
|
+
// keyframes: PropertyIndexedKeyframes | Keyframe[],
|
|
423
|
+
// options?: number | (KeyframeEffectOptions & { name: string }),
|
|
424
|
+
// ) {
|
|
425
|
+
// const frames = new Map<number, StyleObject>();
|
|
426
|
+
// if (Array.isArray(keyframes)) {
|
|
427
|
+
// keyframes.forEach((keyframe, index) => {
|
|
428
|
+
// const offset = keyframes.length === 1 ? 1 : keyframe.offset || index / (keyframes.length - 1);
|
|
429
|
+
// frames.set(offset, {
|
|
430
|
+
// ...keyframe,
|
|
431
|
+
// // https://developer.mozilla.org/en-US/docs/Web/API/Web_Animations_API/Keyframe_Formats#attributes
|
|
432
|
+
// cssOffset: undefined,
|
|
433
|
+
// offset: keyframe.cssOffset,
|
|
434
|
+
// composite: undefined,
|
|
435
|
+
// animationComposition: keyframe.composite,
|
|
436
|
+
// easing: undefined,
|
|
437
|
+
// animationTimingFunction: keyframe.easing,
|
|
438
|
+
// } as StyleObject);
|
|
439
|
+
// });
|
|
440
|
+
// } else {
|
|
441
|
+
// const offsetList: (number | null)[] = Array.isArray(keyframes.offset)
|
|
442
|
+
// ? keyframes.offset
|
|
443
|
+
// : keyframes.offset === undefined
|
|
444
|
+
// ? []
|
|
445
|
+
// : [keyframes.offset];
|
|
446
|
+
// if (offsetList.length && offsetList.at(-1) !== 1) offsetList.push(1);
|
|
447
|
+
|
|
448
|
+
// const setStyle = (offset: number, key: string, value: string | number | null | undefined) => {
|
|
449
|
+
// const style = frames.get(offset) || {};
|
|
450
|
+
// switch (key) {
|
|
451
|
+
// case 'offset':
|
|
452
|
+
// break;
|
|
453
|
+
// case 'cssOffset':
|
|
454
|
+
// Reflect.set(style, 'offset', value);
|
|
455
|
+
// break;
|
|
456
|
+
// case 'composite':
|
|
457
|
+
// Reflect.set(style, 'animationComposition', value);
|
|
458
|
+
// break;
|
|
459
|
+
// case 'easing':
|
|
460
|
+
// Reflect.set(style, 'animationTimingFunction', value);
|
|
461
|
+
// break;
|
|
462
|
+
// default:
|
|
463
|
+
// Reflect.set(style, key, value);
|
|
464
|
+
// }
|
|
465
|
+
// frames.set(offset, style);
|
|
466
|
+
// };
|
|
467
|
+
// for (const key in keyframes) {
|
|
468
|
+
// const framesValue = keyframes[key];
|
|
469
|
+
// !Array.isArray(framesValue)
|
|
470
|
+
// ? setStyle(1, key, framesValue)
|
|
471
|
+
// : framesValue.length === 1
|
|
472
|
+
// ? setStyle(1, key, framesValue[0])
|
|
473
|
+
// : framesValue.forEach((value, index) =>
|
|
474
|
+
// setStyle(offsetList[index] ?? index / (framesValue.length - 1), key, value),
|
|
475
|
+
// );
|
|
476
|
+
// }
|
|
477
|
+
// }
|
|
478
|
+
|
|
479
|
+
// let framesStr = '';
|
|
480
|
+
// frames.forEach((rules, offset) => {
|
|
481
|
+
// framesStr += `${(offset * 100).toFixed()}%{${styleMap(rules)}}`;
|
|
482
|
+
// });
|
|
483
|
+
|
|
484
|
+
// if (options) {
|
|
485
|
+
// const {
|
|
486
|
+
// // 只能使用 ms 数字
|
|
487
|
+
// duration = 0,
|
|
488
|
+
// easing = '',
|
|
489
|
+
// delay = 0,
|
|
490
|
+
// iterations = 1,
|
|
491
|
+
// direction = '',
|
|
492
|
+
// fill = '',
|
|
493
|
+
// name = `ani-${randomStr()}`,
|
|
494
|
+
// } = typeof options === 'number' ? ({ duration: options } as Exclude<typeof options, number>) : options;
|
|
495
|
+
// return `${duration}ms ${easing} ${delay}ms ${iterations} ${direction} ${fill} ${name};@keyframes ${name}{${framesStr}}`;
|
|
496
|
+
// }
|
|
497
|
+
|
|
498
|
+
// return framesStr;
|
|
499
|
+
// }
|
package/src/lib/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = '1.7.
|
|
1
|
+
export const version = '1.7.6';
|
package/src/test/utils.test.ts
CHANGED
|
@@ -110,4 +110,28 @@ describe('utils 测试', () => {
|
|
|
110
110
|
expect(exportPartsMap({ foo: 'bar', content: 'content', false: false })).to.equal(`,foo:bar,content,`);
|
|
111
111
|
expect(exportPartsMap({ foo: 'bar', content: true })).to.equal(`,foo:bar,content,`);
|
|
112
112
|
});
|
|
113
|
+
// it('createCSSAnimation', () => {
|
|
114
|
+
// expect(createCSSAnimation([{ opacity: 0 }])).to.equal('100%{;opacity:0;}');
|
|
115
|
+
// expect(createCSSAnimation([{ opacity: 1 }, { opacity: 0 }])).to.equal('0%{;opacity:1;}100%{;opacity:0;}');
|
|
116
|
+
// expect(createCSSAnimation([{ opacity: 1 }, { opacity: 0.1, offset: 0.7 }, { opacity: 0 }])).to.equal(
|
|
117
|
+
// '0%{;opacity:1;}70%{;opacity:0.1;}100%{;opacity:0;}',
|
|
118
|
+
// );
|
|
119
|
+
// expect(createCSSAnimation({ opacity: [0] })).to.equal('100%{;opacity:0;}');
|
|
120
|
+
// expect(createCSSAnimation({ opacity: [1, 0] })).to.equal('0%{;opacity:1;}100%{;opacity:0;}');
|
|
121
|
+
// expect(createCSSAnimation({ opacity: [1, 0], offset: [0, 0.7] })).to.equal(
|
|
122
|
+
// '0%{;opacity:1;}70%{;opacity:0;}100%{;}',
|
|
123
|
+
// );
|
|
124
|
+
// expect(createCSSAnimation({ opacity: [1, 0], backgroundColor: ['red', 'yellow', 'green'] })).to.equal(
|
|
125
|
+
// '0%{;opacity:1;background-color:red;}100%{;opacity:0;background-color:green;}50%{;background-color:yellow;}',
|
|
126
|
+
// );
|
|
127
|
+
// expect(
|
|
128
|
+
// createCSSAnimation({
|
|
129
|
+
// opacity: [1, 0],
|
|
130
|
+
// backgroundColor: ['red', 'yellow', 'green'],
|
|
131
|
+
// offset: [0, 0.7],
|
|
132
|
+
// }),
|
|
133
|
+
// ).to.equal(
|
|
134
|
+
// '0%{;opacity:1;background-color:red;}70%{;opacity:0;background-color:yellow;}100%{;background-color:green;}',
|
|
135
|
+
// );
|
|
136
|
+
// });
|
|
113
137
|
});
|