执行过npm install命令的vue-element-admin源码
康凯
2022-05-20 aa4c235a8ca67ea8b731f90c951a465e92c0a865
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
"use strict";
 
const DOMException = require("domexception");
const OrderedSet = require("../helpers/ordered-set.js");
const { asciiLowercase } = require("../helpers/strings.js");
const idlUtils = require("../generated/utils.js");
 
const { getAttributeValue, setAttributeValue, hasAttributeByName } = require("../attributes.js");
 
function validateTokens(...tokens) {
  for (const token of tokens) {
    if (token === "") {
      throw new DOMException("The token provided must not be empty.", "SyntaxError");
    }
  }
  for (const token of tokens) {
    if (/[\t\n\f\r ]/.test(token)) {
      const whitespaceMsg = "The token provided contains HTML space characters, which are not valid in tokens.";
      throw new DOMException(whitespaceMsg, "InvalidCharacterError");
    }
  }
}
 
// https://dom.spec.whatwg.org/#domtokenlist
class DOMTokenListImpl {
  constructor(constructorArgs, privateData) {
    // _syncWithElement() must always be called before any _tokenSet access.
    this._tokenSet = new OrderedSet();
    this._element = privateData.element;
    this._attributeLocalName = privateData.attributeLocalName;
    this._supportedTokens = privateData.supportedTokens;
 
    // Needs synchronization with element if token set is to be accessed.
    this._dirty = true;
  }
 
  attrModified() {
    this._dirty = true;
  }
 
  _syncWithElement() {
    if (!this._dirty) {
      return;
    }
 
    const val = getAttributeValue(this._element, this._attributeLocalName);
    if (val === null) {
      this._tokenSet.empty();
    } else {
      this._tokenSet = OrderedSet.parse(val);
    }
 
    this._dirty = false;
  }
 
  _validationSteps(token) {
    if (!this._supportedTokens) {
      throw new TypeError(`${this._attributeLocalName} attribute has no supported tokens`);
    }
    const lowerToken = asciiLowercase(token);
    return this._supportedTokens.has(lowerToken);
  }
 
  _updateSteps() {
    if (!hasAttributeByName(this._element, this._attributeLocalName) && this._tokenSet.isEmpty()) {
      return;
    }
    setAttributeValue(this._element, this._attributeLocalName, this._tokenSet.serialize());
  }
 
  _serializeSteps() {
    return getAttributeValue(this._element, this._attributeLocalName);
  }
 
  // Used by other parts of jsdom
  get tokenSet() {
    this._syncWithElement();
    return this._tokenSet;
  }
 
  get length() {
    this._syncWithElement();
    return this._tokenSet.size;
  }
 
  get [idlUtils.supportedPropertyIndices]() {
    this._syncWithElement();
    return this._tokenSet.keys();
  }
 
  item(index) {
    this._syncWithElement();
    if (index >= this._tokenSet.size) {
      return null;
    }
    return this._tokenSet.get(index);
  }
 
  contains(token) {
    this._syncWithElement();
    return this._tokenSet.contains(token);
  }
 
  add(...tokens) {
    for (const token of tokens) {
      validateTokens(token);
    }
    this._syncWithElement();
    for (const token of tokens) {
      this._tokenSet.append(token);
    }
    this._updateSteps();
  }
 
  remove(...tokens) {
    for (const token of tokens) {
      validateTokens(token);
    }
    this._syncWithElement();
    this._tokenSet.remove(...tokens);
    this._updateSteps();
  }
 
  toggle(token, force = undefined) {
    validateTokens(token);
    this._syncWithElement();
    if (this._tokenSet.contains(token)) {
      if (force === undefined || force === false) {
        this._tokenSet.remove(token);
        this._updateSteps();
        return false;
      }
      return true;
    }
    if (force === undefined || force === true) {
      this._tokenSet.append(token);
      this._updateSteps();
      return true;
    }
    return false;
  }
 
  replace(token, newToken) {
    validateTokens(token, newToken);
    this._syncWithElement();
    if (!this._tokenSet.contains(token)) {
      return false;
    }
    this._tokenSet.replace(token, newToken);
    this._updateSteps();
    return true;
  }
 
  supports(token) {
    return this._validationSteps(token);
  }
 
  get value() {
    return this._serializeSteps();
  }
 
  set value(V) {
    setAttributeValue(this._element, this._attributeLocalName, V);
  }
}
 
exports.implementation = DOMTokenListImpl;