@micro-zoe/micro-app 0.8.2 → 0.8.3
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.esm.js +33 -40
- 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.esm.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const version = '0.8.
|
|
1
|
+
const version = '0.8.3';
|
|
2
2
|
// do not use isUndefined
|
|
3
3
|
const isBrowser = typeof window !== 'undefined';
|
|
4
4
|
// do not use isUndefined
|
|
@@ -359,9 +359,8 @@ function fetchSource(url, appName = null, options = {}) {
|
|
|
359
359
|
// common reg
|
|
360
360
|
const rootSelectorREG = /(^|\s+)(html|:root)(?=[\s>~[.#:]+|$)/;
|
|
361
361
|
const bodySelectorREG = /(^|\s+)((html[\s>~]+body)|body)(?=[\s>~[.#:]+|$)/;
|
|
362
|
-
const cssUrlREG = /url\(["']?([^)"']+)["']?\)/gm;
|
|
363
362
|
function parseError(msg, linkPath) {
|
|
364
|
-
msg = linkPath ? `${linkPath}
|
|
363
|
+
msg = linkPath ? `${linkPath} ${msg}` : msg;
|
|
365
364
|
const err = new Error(msg);
|
|
366
365
|
err.reason = msg;
|
|
367
366
|
if (linkPath) {
|
|
@@ -438,44 +437,41 @@ class CSSParser {
|
|
|
438
437
|
styleDeclarations() {
|
|
439
438
|
if (!this.matchOpenBrace())
|
|
440
439
|
return parseError("Declaration missing '{'", this.linkPath);
|
|
441
|
-
this.
|
|
442
|
-
while (this.styleDeclaration()) {
|
|
443
|
-
this.matchComments();
|
|
444
|
-
}
|
|
440
|
+
this.matchAllDeclarations();
|
|
445
441
|
if (!this.matchCloseBrace())
|
|
446
442
|
return parseError("Declaration missing '}'", this.linkPath);
|
|
447
443
|
return true;
|
|
448
444
|
}
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
// ./a/b.png ../a/b.png a/b.png
|
|
467
|
-
if (/^((\.\.?\/)|[^/])/.test($1) && this.linkPath) {
|
|
468
|
-
this.baseURI = getLinkFileDir(this.linkPath);
|
|
469
|
-
}
|
|
470
|
-
return `url("${CompletionPath($1, this.baseURI)}")`;
|
|
471
|
-
});
|
|
445
|
+
matchAllDeclarations() {
|
|
446
|
+
let cssValue = this.commonMatch(/^(?:url\(["']?(?:[^)"'}]+)["']?\)|[^}/])*/, true)[0];
|
|
447
|
+
if (cssValue) {
|
|
448
|
+
if (!this.scopecssDisableNextLine &&
|
|
449
|
+
(!this.scopecssDisable || this.scopecssDisableSelectors.length)) {
|
|
450
|
+
cssValue = cssValue.replace(/url\(["']?([^)"']+)["']?\)/gm, (all, $1) => {
|
|
451
|
+
if (/^((data|blob):|#)/.test($1) || /^(https?:)?\/\//.test($1)) {
|
|
452
|
+
return all;
|
|
453
|
+
}
|
|
454
|
+
// ./a/b.png ../a/b.png a/b.png
|
|
455
|
+
if (/^((\.\.?\/)|[^/])/.test($1) && this.linkPath) {
|
|
456
|
+
this.baseURI = getLinkFileDir(this.linkPath);
|
|
457
|
+
}
|
|
458
|
+
return `url("${CompletionPath($1, this.baseURI)}")`;
|
|
459
|
+
});
|
|
460
|
+
}
|
|
461
|
+
this.result += cssValue;
|
|
472
462
|
}
|
|
473
463
|
// reset scopecssDisableNextLine
|
|
474
464
|
this.scopecssDisableNextLine = false;
|
|
475
|
-
this.
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
465
|
+
if (!this.cssText || this.cssText.charAt(0) === '}')
|
|
466
|
+
return;
|
|
467
|
+
// extract comments in declarations
|
|
468
|
+
if (this.cssText.charAt(0) === '/' && this.cssText.charAt(1) === '*') {
|
|
469
|
+
this.matchComments();
|
|
470
|
+
}
|
|
471
|
+
else {
|
|
472
|
+
this.commonMatch(/\/+/);
|
|
473
|
+
}
|
|
474
|
+
return this.matchAllDeclarations();
|
|
479
475
|
}
|
|
480
476
|
formatSelector() {
|
|
481
477
|
const m = this.commonMatch(/^([^{]+)/, true);
|
|
@@ -609,10 +605,7 @@ class CSSParser {
|
|
|
609
605
|
commonHandlerForAtRuleWithSelfRule(name) {
|
|
610
606
|
if (!this.matchOpenBrace())
|
|
611
607
|
return parseError(`@${name} missing '{'`, this.linkPath);
|
|
612
|
-
this.
|
|
613
|
-
while (this.styleDeclaration()) {
|
|
614
|
-
this.matchComments();
|
|
615
|
-
}
|
|
608
|
+
this.matchAllDeclarations();
|
|
616
609
|
if (!this.matchCloseBrace())
|
|
617
610
|
return parseError(`@${name} missing '}'`, this.linkPath);
|
|
618
611
|
this.matchLeadingSpaces();
|
|
@@ -698,7 +691,7 @@ function commonAction(styleElement, appName, prefix, baseURI, linkPath) {
|
|
|
698
691
|
}
|
|
699
692
|
catch (e) {
|
|
700
693
|
parser.reset();
|
|
701
|
-
logError('
|
|
694
|
+
logError('An error occurred while parsing CSS:\n', appName, e);
|
|
702
695
|
}
|
|
703
696
|
if (result)
|
|
704
697
|
styleElement.textContent = result;
|
|
@@ -1309,7 +1302,7 @@ function rejectMicroAppStyle() {
|
|
|
1309
1302
|
hasRejectMicroAppStyle = true;
|
|
1310
1303
|
const style = pureCreateElement('style');
|
|
1311
1304
|
globalEnv.rawSetAttribute.call(style, 'type', 'text/css');
|
|
1312
|
-
style.textContent = `\n${microApp.tagName}, micro-app-body { display: block;
|
|
1305
|
+
style.textContent = `\n${microApp.tagName}, micro-app-body { display: block; } \nmicro-app-head { display: none; }`;
|
|
1313
1306
|
globalEnv.rawDocument.head.appendChild(style);
|
|
1314
1307
|
}
|
|
1315
1308
|
}
|