@micro-zoe/micro-app 0.8.3 → 0.8.4
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/lib/index.d.ts +1 -0
- package/lib/index.esm.js +44 -43
- package/lib/index.esm.js.map +1 -1
- package/lib/index.min.js +1 -1
- package/lib/index.min.js.map +1 -1
- package/lib/index.umd.js +1 -1
- package/lib/index.umd.js.map +1 -1
- package/package.json +1 -1
package/lib/index.d.ts
CHANGED
package/lib/index.esm.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const version = '0.8.
|
|
1
|
+
const version = '0.8.4';
|
|
2
2
|
// do not use isUndefined
|
|
3
3
|
const isBrowser = typeof window !== 'undefined';
|
|
4
4
|
// do not use isUndefined
|
|
@@ -303,6 +303,9 @@ function getRootContainer(target) {
|
|
|
303
303
|
function trim(str) {
|
|
304
304
|
return str ? str.replace(/^\s+|\s+$/g, '') : '';
|
|
305
305
|
}
|
|
306
|
+
function isFireFox() {
|
|
307
|
+
return navigator.userAgent.indexOf('Firefox') > -1;
|
|
308
|
+
}
|
|
306
309
|
|
|
307
310
|
var ObservedAttrName;
|
|
308
311
|
(function (ObservedAttrName) {
|
|
@@ -403,7 +406,7 @@ class CSSParser {
|
|
|
403
406
|
this.baseURI = baseURI;
|
|
404
407
|
this.linkPath = linkPath || '';
|
|
405
408
|
this.matchRules();
|
|
406
|
-
return this.result;
|
|
409
|
+
return isFireFox() ? decodeURIComponent(this.result) : this.result;
|
|
407
410
|
}
|
|
408
411
|
reset() {
|
|
409
412
|
this.cssText = this.prefix = this.baseURI = this.linkPath = this.result = '';
|
|
@@ -422,17 +425,37 @@ class CSSParser {
|
|
|
422
425
|
}
|
|
423
426
|
// https://developer.mozilla.org/en-US/docs/Web/API/CSSStyleRule
|
|
424
427
|
matchStyleRule() {
|
|
425
|
-
const
|
|
428
|
+
const selectors = this.formatSelector(true);
|
|
426
429
|
// reset scopecssDisableNextLine
|
|
427
430
|
this.scopecssDisableNextLine = false;
|
|
428
|
-
if (!
|
|
431
|
+
if (!selectors)
|
|
429
432
|
return parseError('selector missing', this.linkPath);
|
|
430
|
-
this.
|
|
433
|
+
this.recordResult(selectors);
|
|
431
434
|
this.matchComments();
|
|
432
435
|
this.styleDeclarations();
|
|
433
436
|
this.matchLeadingSpaces();
|
|
434
437
|
return true;
|
|
435
438
|
}
|
|
439
|
+
formatSelector(skip) {
|
|
440
|
+
const m = this.commonMatch(/^([^{]+)/, skip);
|
|
441
|
+
if (!m)
|
|
442
|
+
return false;
|
|
443
|
+
return m[0].replace(/(^|,[\n\s]*)([^,]+)/g, (_, separator, selector) => {
|
|
444
|
+
selector = trim(selector);
|
|
445
|
+
if (!(this.scopecssDisableNextLine ||
|
|
446
|
+
(this.scopecssDisable && (!this.scopecssDisableSelectors.length ||
|
|
447
|
+
this.scopecssDisableSelectors.includes(selector))) ||
|
|
448
|
+
rootSelectorREG.test(selector))) {
|
|
449
|
+
if (bodySelectorREG.test(selector)) {
|
|
450
|
+
selector = selector.replace(bodySelectorREG, this.prefix + ' micro-app-body');
|
|
451
|
+
}
|
|
452
|
+
else {
|
|
453
|
+
selector = this.prefix + ' ' + selector;
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
return separator + selector;
|
|
457
|
+
});
|
|
458
|
+
}
|
|
436
459
|
// https://developer.mozilla.org/en-US/docs/Web/API/CSSStyleDeclaration
|
|
437
460
|
styleDeclarations() {
|
|
438
461
|
if (!this.matchOpenBrace())
|
|
@@ -458,7 +481,7 @@ class CSSParser {
|
|
|
458
481
|
return `url("${CompletionPath($1, this.baseURI)}")`;
|
|
459
482
|
});
|
|
460
483
|
}
|
|
461
|
-
this.
|
|
484
|
+
this.recordResult(cssValue);
|
|
462
485
|
}
|
|
463
486
|
// reset scopecssDisableNextLine
|
|
464
487
|
this.scopecssDisableNextLine = false;
|
|
@@ -473,39 +496,6 @@ class CSSParser {
|
|
|
473
496
|
}
|
|
474
497
|
return this.matchAllDeclarations();
|
|
475
498
|
}
|
|
476
|
-
formatSelector() {
|
|
477
|
-
const m = this.commonMatch(/^([^{]+)/, true);
|
|
478
|
-
if (!m)
|
|
479
|
-
return false;
|
|
480
|
-
return trim(m[0])
|
|
481
|
-
.replace(/\/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*\/+/g, '')
|
|
482
|
-
.replace(/"(?:\\"|[^"])*"|'(?:\\'|[^'])*'/g, (r) => {
|
|
483
|
-
return r.replace(/,/g, '\u200C');
|
|
484
|
-
})
|
|
485
|
-
.split(/\s*(?![^(]*\)),\s*/)
|
|
486
|
-
.map((s) => {
|
|
487
|
-
const selectorText = s.replace(/\u200C/g, ',');
|
|
488
|
-
if (this.scopecssDisableNextLine) {
|
|
489
|
-
return selectorText;
|
|
490
|
-
}
|
|
491
|
-
else if (this.scopecssDisable) {
|
|
492
|
-
if (!this.scopecssDisableSelectors.length ||
|
|
493
|
-
this.scopecssDisableSelectors.includes(selectorText)) {
|
|
494
|
-
return selectorText;
|
|
495
|
-
}
|
|
496
|
-
}
|
|
497
|
-
if (selectorText === '*') {
|
|
498
|
-
return this.prefix + ' *';
|
|
499
|
-
}
|
|
500
|
-
else if (bodySelectorREG.test(selectorText)) {
|
|
501
|
-
return selectorText.replace(bodySelectorREG, this.prefix + ' micro-app-body');
|
|
502
|
-
}
|
|
503
|
-
else if (rootSelectorREG.test(selectorText)) { // ignore root selector
|
|
504
|
-
return selectorText;
|
|
505
|
-
}
|
|
506
|
-
return this.prefix + ' ' + selectorText;
|
|
507
|
-
});
|
|
508
|
-
}
|
|
509
499
|
matchAtRule() {
|
|
510
500
|
if (this.cssText[0] !== '@')
|
|
511
501
|
return false;
|
|
@@ -565,7 +555,7 @@ class CSSParser {
|
|
|
565
555
|
pageRule() {
|
|
566
556
|
if (!this.commonMatch(/^@page */))
|
|
567
557
|
return false;
|
|
568
|
-
this.formatSelector();
|
|
558
|
+
this.formatSelector(false);
|
|
569
559
|
// reset scopecssDisableNextLine
|
|
570
560
|
this.scopecssDisableNextLine = false;
|
|
571
561
|
return this.commonHandlerForAtRuleWithSelfRule('page');
|
|
@@ -598,7 +588,7 @@ class CSSParser {
|
|
|
598
588
|
if (!this.commonMatch(reg))
|
|
599
589
|
return false;
|
|
600
590
|
this.matchLeadingSpaces();
|
|
601
|
-
return
|
|
591
|
+
return true;
|
|
602
592
|
};
|
|
603
593
|
}
|
|
604
594
|
// common handler for @font-face, @page
|
|
@@ -631,7 +621,7 @@ class CSSParser {
|
|
|
631
621
|
}
|
|
632
622
|
// get comment content
|
|
633
623
|
let commentText = this.cssText.slice(2, i - 2);
|
|
634
|
-
this.
|
|
624
|
+
this.recordResult(`/*${commentText}*/`);
|
|
635
625
|
commentText = trim(commentText.replace(/^\s*!/, ''));
|
|
636
626
|
// set ignore config
|
|
637
627
|
if (commentText === 'scopecss-disable-next-line') {
|
|
@@ -664,7 +654,7 @@ class CSSParser {
|
|
|
664
654
|
const matchStr = matchArray[0];
|
|
665
655
|
this.cssText = this.cssText.slice(matchStr.length);
|
|
666
656
|
if (!skip)
|
|
667
|
-
this.
|
|
657
|
+
this.recordResult(matchStr);
|
|
668
658
|
return matchArray;
|
|
669
659
|
}
|
|
670
660
|
matchOpenBrace() {
|
|
@@ -677,6 +667,16 @@ class CSSParser {
|
|
|
677
667
|
matchLeadingSpaces() {
|
|
678
668
|
this.commonMatch(/^\s*/);
|
|
679
669
|
}
|
|
670
|
+
// splice string
|
|
671
|
+
recordResult(strFragment) {
|
|
672
|
+
// Firefox is slow when string contain special characters, see https://github.com/micro-zoe/micro-app/issues/256
|
|
673
|
+
if (isFireFox()) {
|
|
674
|
+
this.result += encodeURIComponent(strFragment);
|
|
675
|
+
}
|
|
676
|
+
else {
|
|
677
|
+
this.result += strFragment;
|
|
678
|
+
}
|
|
679
|
+
}
|
|
680
680
|
}
|
|
681
681
|
/**
|
|
682
682
|
* common method of bind CSS
|
|
@@ -3503,6 +3503,7 @@ function getGlobalAssets(assets) {
|
|
|
3503
3503
|
});
|
|
3504
3504
|
}
|
|
3505
3505
|
}
|
|
3506
|
+
// TODO: requestIdleCallback for every file
|
|
3506
3507
|
function fetchGlobalResources(resources, suffix, cache) {
|
|
3507
3508
|
if (isArray(resources)) {
|
|
3508
3509
|
const effectiveResource = resources.filter((path) => isString(path) && path.includes(`.${suffix}`) && !cache.has(path));
|