Skip to content

Commit ff0b5fb

Browse files
committed
feat: node 환경에서 import 하더라도 에러 나지 않도록 수정
1 parent 9840362 commit ff0b5fb

File tree

9 files changed

+36
-14
lines changed

9 files changed

+36
-14
lines changed

package.json

+4
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,9 @@
5656
"webpack-cli": "^4.9.1",
5757
"webpack-dev-middleware": "^5.2.1",
5858
"yargs": "^17.2.1"
59+
},
60+
"volta": {
61+
"node": "14.21.3",
62+
"npm": "7.24.2"
5963
}
6064
}

src/_internal/_browser.js

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export const document_wrapper = typeof document !== "undefined" ? document : {};
2+
export const navigator_wrapper = typeof navigator !== 'undefined' ? navigator : {}

src/_internal/_docWidth.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
const docEl = document.documentElement;
1+
import { document_wrapper } from "./_browser.js";
2+
3+
const docEl = document_wrapper.documentElement;
24

35
export default (isHeight, b = document.body) =>
46
isHeight

src/_internal/_matches.js

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
const docEl = document.documentElement;
2-
export default docEl.matches ||
3-
docEl.webkitMatchesSelector ||
4-
docEl.mozMatchesSelector ||
5-
docEl.msMatchesSelector;
1+
import { document_wrapper } from "./_browser.js";
2+
3+
const docEl = document_wrapper.documentElement;
4+
export default docEl?.matches ||
5+
docEl?.webkitMatchesSelector ||
6+
docEl?.mozMatchesSelector ||
7+
docEl?.msMatchesSelector;

src/elWidth.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ import css from "./css.js";
22
import cssF from "./_internal/_cssF.js";
33
import show from "./show.js";
44
import hide from "./hide.js";
5+
import { navigator_wrapper } from "./_internal/_browser.js";
56

6-
const isIE = /trident/i.test(navigator.userAgent);
7+
const isIE = /trident/i.test(navigator_wrapper.userAgent || '');
78

89
function getBorderBoxValue(Left, Right, el) {
910
return (

src/els.js

+11-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
import remove from "./remove.js";
22
import $each from "./each.js";
33

4-
const fragmentRE = /^\s*<(\w+|!)[^>]*>/,
5-
table = document.createElement("table"),
6-
tableRow = document.createElement("tr"),
7-
div = document.createElement("div"),
4+
const fragmentRE = /^\s*<(\w+|!)[^>]*>/;
5+
let table;
6+
let tableRow;
7+
let div;
8+
let containers;
9+
10+
if (typeof document !== "undefined") {
11+
table = document.createElement("table");
12+
tableRow = document.createElement("tr");
13+
div = document.createElement("div");
814
containers = {
915
tr: document.createElement("tbody"),
1016
tbody: table,
@@ -13,6 +19,7 @@ const fragmentRE = /^\s*<(\w+|!)[^>]*>/,
1319
td: tableRow,
1420
th: tableRow,
1521
};
22+
}
1623

1724
export default (html) => {
1825
html = html.trim();

src/offset.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
const docEl = document.documentElement;
1+
import { document_wrapper } from "./_internal/_browser.js";
2+
3+
const docEl = document_wrapper.documentElement;
24

35
export default (el) => {
46
const rect = el.getBoundingClientRect();

src/offsetParent.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import css from "./css.js";
2-
const docEl = document.documentElement;
2+
import { document_wrapper } from "./_internal/_browser.js";
3+
const docEl = document_wrapper.documentElement;
34

45
export default function offsetParent(el) {
56
let offsetParent = el;

src/position.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import css from "./css.js";
22
import offset from "./offset.js";
33
import offsetParent from "./offsetParent.js";
4+
import { document_wrapper } from "./_internal/_browser.js";
45

5-
const docEl = document.documentElement;
6+
const docEl = document_wrapper.documentElement;
67

78
const setPositionTopLeft = (el, { top, left }, { pTop = 0, pLeft = 0 }) => ({
89
top: top - pTop - parseFloat(css("marginTop", el)) + docEl.clientTop,

0 commit comments

Comments
 (0)