yansu 0.0.0-beta.1

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.
Files changed (142) hide show
  1. package/README.md +1 -0
  2. package/bin.mjs +18 -0
  3. package/dist/cli.d.mts +2 -0
  4. package/dist/cli.mjs +68 -0
  5. package/dist/dirs.d.mts +4 -0
  6. package/dist/dirs.mjs +6 -0
  7. package/dist/index.d.mts +78 -0
  8. package/dist/index.mjs +121 -0
  9. package/dist/nitro.json +15 -0
  10. package/dist/public/_nuxt/BHIHUtPz.js +4 -0
  11. package/dist/public/_nuxt/CCgOhniq.js +1 -0
  12. package/dist/public/_nuxt/CR6vfq1R.js +1 -0
  13. package/dist/public/_nuxt/DmxzK6E8.js +1 -0
  14. package/dist/public/_nuxt/builds/latest.json +1 -0
  15. package/dist/public/_nuxt/builds/meta/e9079134-f314-434b-b3a7-092c4a1e187d.json +1 -0
  16. package/dist/public/_nuxt/entry.DJ3VOi_0.css +1 -0
  17. package/dist/public/_nuxt/error-404.lC6KBLNm.css +1 -0
  18. package/dist/public/_nuxt/error-500.NtBcR2wE.css +1 -0
  19. package/dist/server/chunks/_/error-500.mjs +9 -0
  20. package/dist/server/chunks/build/_plugin-vue_export-helper-DjsbPc54.mjs +29 -0
  21. package/dist/server/chunks/build/client.precomputed.mjs +3 -0
  22. package/dist/server/chunks/build/error-404-Du0ot2hm.mjs +369 -0
  23. package/dist/server/chunks/build/error-500-Y3RUV6n2.mjs +73 -0
  24. package/dist/server/chunks/build/server.mjs +727 -0
  25. package/dist/server/chunks/nitro/nitro.mjs +5176 -0
  26. package/dist/server/chunks/routes/api/metadata.json.mjs +147 -0
  27. package/dist/server/chunks/routes/api/platform.json.mjs +20 -0
  28. package/dist/server/chunks/routes/renderer.mjs +408 -0
  29. package/dist/server/chunks/virtual/_virtual_spa-template.mjs +3 -0
  30. package/dist/server/index.mjs +9 -0
  31. package/dist/server/node_modules/.nitro/@vue/shared@3.5.25/dist/shared.cjs.prod.js +604 -0
  32. package/dist/server/node_modules/.nitro/@vue/shared@3.5.25/package.json +47 -0
  33. package/dist/server/node_modules/.nitro/@vue/shared@3.5.26/dist/shared.cjs.prod.js +604 -0
  34. package/dist/server/node_modules/.nitro/@vue/shared@3.5.26/package.json +47 -0
  35. package/dist/server/node_modules/@babel/parser/lib/index.js +14662 -0
  36. package/dist/server/node_modules/@babel/parser/package.json +50 -0
  37. package/dist/server/node_modules/@vue/compiler-core/dist/compiler-core.cjs.prod.js +6763 -0
  38. package/dist/server/node_modules/@vue/compiler-core/package.json +58 -0
  39. package/dist/server/node_modules/@vue/compiler-dom/dist/compiler-dom.cjs.prod.js +689 -0
  40. package/dist/server/node_modules/@vue/compiler-dom/package.json +57 -0
  41. package/dist/server/node_modules/@vue/compiler-ssr/dist/compiler-ssr.cjs.js +1413 -0
  42. package/dist/server/node_modules/@vue/compiler-ssr/package.json +34 -0
  43. package/dist/server/node_modules/@vue/reactivity/dist/reactivity.cjs.prod.js +1853 -0
  44. package/dist/server/node_modules/@vue/reactivity/package.json +55 -0
  45. package/dist/server/node_modules/@vue/runtime-core/dist/runtime-core.cjs.prod.js +6770 -0
  46. package/dist/server/node_modules/@vue/runtime-core/package.json +52 -0
  47. package/dist/server/node_modules/@vue/runtime-dom/dist/runtime-dom.cjs.prod.js +1732 -0
  48. package/dist/server/node_modules/@vue/runtime-dom/package.json +60 -0
  49. package/dist/server/node_modules/@vue/server-renderer/dist/server-renderer.cjs.prod.js +879 -0
  50. package/dist/server/node_modules/@vue/server-renderer/package.json +55 -0
  51. package/dist/server/node_modules/ansis/index.cjs +1 -0
  52. package/dist/server/node_modules/ansis/index.mjs +1 -0
  53. package/dist/server/node_modules/ansis/package.json +25 -0
  54. package/dist/server/node_modules/birpc/dist/index.mjs +173 -0
  55. package/dist/server/node_modules/birpc/package.json +56 -0
  56. package/dist/server/node_modules/consola/dist/chunks/prompt.mjs +280 -0
  57. package/dist/server/node_modules/consola/dist/core.mjs +512 -0
  58. package/dist/server/node_modules/consola/dist/index.mjs +651 -0
  59. package/dist/server/node_modules/consola/dist/shared/consola.DRwqZj3T.mjs +72 -0
  60. package/dist/server/node_modules/consola/dist/shared/consola.DXBYu-KD.mjs +288 -0
  61. package/dist/server/node_modules/consola/package.json +136 -0
  62. package/dist/server/node_modules/devalue/index.js +4 -0
  63. package/dist/server/node_modules/devalue/package.json +37 -0
  64. package/dist/server/node_modules/devalue/src/base64.js +110 -0
  65. package/dist/server/node_modules/devalue/src/constants.js +6 -0
  66. package/dist/server/node_modules/devalue/src/parse.js +205 -0
  67. package/dist/server/node_modules/devalue/src/stringify.js +265 -0
  68. package/dist/server/node_modules/devalue/src/uneval.js +407 -0
  69. package/dist/server/node_modules/devalue/src/utils.js +118 -0
  70. package/dist/server/node_modules/entities/dist/commonjs/decode-codepoint.js +77 -0
  71. package/dist/server/node_modules/entities/dist/commonjs/decode.js +568 -0
  72. package/dist/server/node_modules/entities/dist/commonjs/generated/decode-data-html.js +7 -0
  73. package/dist/server/node_modules/entities/dist/commonjs/generated/decode-data-xml.js +7 -0
  74. package/dist/server/node_modules/entities/dist/commonjs/internal/bin-trie-flags.js +21 -0
  75. package/dist/server/node_modules/entities/dist/commonjs/internal/decode-shared.js +31 -0
  76. package/dist/server/node_modules/entities/dist/commonjs/package.json +3 -0
  77. package/dist/server/node_modules/entities/package.json +113 -0
  78. package/dist/server/node_modules/estree-walker/dist/umd/estree-walker.js +344 -0
  79. package/dist/server/node_modules/estree-walker/package.json +37 -0
  80. package/dist/server/node_modules/get-port-please/dist/index.mjs +430 -0
  81. package/dist/server/node_modules/get-port-please/package.json +39 -0
  82. package/dist/server/node_modules/hookable/dist/index.mjs +290 -0
  83. package/dist/server/node_modules/hookable/package.json +49 -0
  84. package/dist/server/node_modules/source-map-js/lib/array-set.js +121 -0
  85. package/dist/server/node_modules/source-map-js/lib/base64-vlq.js +140 -0
  86. package/dist/server/node_modules/source-map-js/lib/base64.js +67 -0
  87. package/dist/server/node_modules/source-map-js/lib/binary-search.js +111 -0
  88. package/dist/server/node_modules/source-map-js/lib/mapping-list.js +79 -0
  89. package/dist/server/node_modules/source-map-js/lib/quick-sort.js +132 -0
  90. package/dist/server/node_modules/source-map-js/lib/source-map-consumer.js +1188 -0
  91. package/dist/server/node_modules/source-map-js/lib/source-map-generator.js +444 -0
  92. package/dist/server/node_modules/source-map-js/lib/source-node.js +413 -0
  93. package/dist/server/node_modules/source-map-js/lib/util.js +594 -0
  94. package/dist/server/node_modules/source-map-js/package.json +71 -0
  95. package/dist/server/node_modules/source-map-js/source-map.js +8 -0
  96. package/dist/server/node_modules/structured-clone-es/dist/index.mjs +285 -0
  97. package/dist/server/node_modules/structured-clone-es/package.json +56 -0
  98. package/dist/server/node_modules/ufo/dist/index.mjs +638 -0
  99. package/dist/server/node_modules/ufo/package.json +47 -0
  100. package/dist/server/node_modules/unhead/dist/index.mjs +9 -0
  101. package/dist/server/node_modules/unhead/dist/parser.mjs +508 -0
  102. package/dist/server/node_modules/unhead/dist/plugins.mjs +101 -0
  103. package/dist/server/node_modules/unhead/dist/scripts.mjs +30 -0
  104. package/dist/server/node_modules/unhead/dist/server.mjs +182 -0
  105. package/dist/server/node_modules/unhead/dist/shared/unhead.B578PsDV.mjs +266 -0
  106. package/dist/server/node_modules/unhead/dist/shared/unhead.BPM0-cfG.mjs +44 -0
  107. package/dist/server/node_modules/unhead/dist/shared/unhead.BYvz9V1x.mjs +43 -0
  108. package/dist/server/node_modules/unhead/dist/shared/unhead.BpRRHAhY.mjs +194 -0
  109. package/dist/server/node_modules/unhead/dist/shared/unhead.CApf5sj3.mjs +148 -0
  110. package/dist/server/node_modules/unhead/dist/shared/unhead.DH45uomy.mjs +180 -0
  111. package/dist/server/node_modules/unhead/dist/shared/unhead.DQc16pHI.mjs +196 -0
  112. package/dist/server/node_modules/unhead/dist/shared/unhead.DZbvapt-.mjs +70 -0
  113. package/dist/server/node_modules/unhead/dist/shared/unhead.Djo8ep_Y.mjs +166 -0
  114. package/dist/server/node_modules/unhead/dist/shared/unhead.yem5I2v_.mjs +38 -0
  115. package/dist/server/node_modules/unhead/dist/utils.mjs +5 -0
  116. package/dist/server/node_modules/unhead/package.json +105 -0
  117. package/dist/server/node_modules/vue/dist/vue.cjs.js +80 -0
  118. package/dist/server/node_modules/vue/dist/vue.cjs.prod.js +66 -0
  119. package/dist/server/node_modules/vue/index.js +7 -0
  120. package/dist/server/node_modules/vue/index.mjs +1 -0
  121. package/dist/server/node_modules/vue/package.json +112 -0
  122. package/dist/server/node_modules/vue/server-renderer/index.mjs +1 -0
  123. package/dist/server/node_modules/vue-bundle-renderer/dist/runtime.mjs +301 -0
  124. package/dist/server/node_modules/vue-bundle-renderer/package.json +55 -0
  125. package/dist/server/node_modules/ws/lib/buffer-util.js +131 -0
  126. package/dist/server/node_modules/ws/lib/constants.js +19 -0
  127. package/dist/server/node_modules/ws/lib/event-target.js +292 -0
  128. package/dist/server/node_modules/ws/lib/extension.js +203 -0
  129. package/dist/server/node_modules/ws/lib/limiter.js +55 -0
  130. package/dist/server/node_modules/ws/lib/permessage-deflate.js +528 -0
  131. package/dist/server/node_modules/ws/lib/receiver.js +706 -0
  132. package/dist/server/node_modules/ws/lib/sender.js +602 -0
  133. package/dist/server/node_modules/ws/lib/stream.js +161 -0
  134. package/dist/server/node_modules/ws/lib/subprotocol.js +62 -0
  135. package/dist/server/node_modules/ws/lib/validation.js +152 -0
  136. package/dist/server/node_modules/ws/lib/websocket-server.js +554 -0
  137. package/dist/server/node_modules/ws/lib/websocket.js +1393 -0
  138. package/dist/server/node_modules/ws/package.json +69 -0
  139. package/dist/server/node_modules/ws/wrapper.mjs +8 -0
  140. package/dist/server/package.json +32 -0
  141. package/dist/shared/yansu.DmdNF4qf.mjs +151 -0
  142. package/package.json +50 -0
@@ -0,0 +1,290 @@
1
+ function flatHooks(configHooks, hooks = {}, parentName) {
2
+ for (const key in configHooks) {
3
+ const subHook = configHooks[key];
4
+ const name = parentName ? `${parentName}:${key}` : key;
5
+ if (typeof subHook === "object" && subHook !== null) {
6
+ flatHooks(subHook, hooks, name);
7
+ } else if (typeof subHook === "function") {
8
+ hooks[name] = subHook;
9
+ }
10
+ }
11
+ return hooks;
12
+ }
13
+ function mergeHooks(...hooks) {
14
+ const finalHooks = {};
15
+ for (const hook of hooks) {
16
+ const flatenHook = flatHooks(hook);
17
+ for (const key in flatenHook) {
18
+ if (finalHooks[key]) {
19
+ finalHooks[key].push(flatenHook[key]);
20
+ } else {
21
+ finalHooks[key] = [flatenHook[key]];
22
+ }
23
+ }
24
+ }
25
+ for (const key in finalHooks) {
26
+ if (finalHooks[key].length > 1) {
27
+ const array = finalHooks[key];
28
+ finalHooks[key] = (...arguments_) => serial(array, (function_) => function_(...arguments_));
29
+ } else {
30
+ finalHooks[key] = finalHooks[key][0];
31
+ }
32
+ }
33
+ return finalHooks;
34
+ }
35
+ function serial(tasks, function_) {
36
+ return tasks.reduce(
37
+ (promise, task) => promise.then(() => function_(task)),
38
+ Promise.resolve()
39
+ );
40
+ }
41
+ const defaultTask = { run: (function_) => function_() };
42
+ const _createTask = () => defaultTask;
43
+ const createTask = typeof console.createTask !== "undefined" ? console.createTask : _createTask;
44
+ function serialTaskCaller(hooks, args) {
45
+ const name = args.shift();
46
+ const task = createTask(name);
47
+ return hooks.reduce(
48
+ (promise, hookFunction) => promise.then(() => task.run(() => hookFunction(...args))),
49
+ Promise.resolve()
50
+ );
51
+ }
52
+ function parallelTaskCaller(hooks, args) {
53
+ const name = args.shift();
54
+ const task = createTask(name);
55
+ return Promise.all(hooks.map((hook) => task.run(() => hook(...args))));
56
+ }
57
+ function serialCaller(hooks, arguments_) {
58
+ return hooks.reduce(
59
+ (promise, hookFunction) => promise.then(() => hookFunction(...arguments_ || [])),
60
+ Promise.resolve()
61
+ );
62
+ }
63
+ function parallelCaller(hooks, args) {
64
+ return Promise.all(hooks.map((hook) => hook(...args || [])));
65
+ }
66
+ function callEachWith(callbacks, arg0) {
67
+ for (const callback of [...callbacks]) {
68
+ callback(arg0);
69
+ }
70
+ }
71
+
72
+ class Hookable {
73
+ constructor() {
74
+ this._hooks = {};
75
+ this._before = void 0;
76
+ this._after = void 0;
77
+ this._deprecatedMessages = void 0;
78
+ this._deprecatedHooks = {};
79
+ this.hook = this.hook.bind(this);
80
+ this.callHook = this.callHook.bind(this);
81
+ this.callHookWith = this.callHookWith.bind(this);
82
+ }
83
+ hook(name, function_, options = {}) {
84
+ if (!name || typeof function_ !== "function") {
85
+ return () => {
86
+ };
87
+ }
88
+ const originalName = name;
89
+ let dep;
90
+ while (this._deprecatedHooks[name]) {
91
+ dep = this._deprecatedHooks[name];
92
+ name = dep.to;
93
+ }
94
+ if (dep && !options.allowDeprecated) {
95
+ let message = dep.message;
96
+ if (!message) {
97
+ message = `${originalName} hook has been deprecated` + (dep.to ? `, please use ${dep.to}` : "");
98
+ }
99
+ if (!this._deprecatedMessages) {
100
+ this._deprecatedMessages = /* @__PURE__ */ new Set();
101
+ }
102
+ if (!this._deprecatedMessages.has(message)) {
103
+ console.warn(message);
104
+ this._deprecatedMessages.add(message);
105
+ }
106
+ }
107
+ if (!function_.name) {
108
+ try {
109
+ Object.defineProperty(function_, "name", {
110
+ get: () => "_" + name.replace(/\W+/g, "_") + "_hook_cb",
111
+ configurable: true
112
+ });
113
+ } catch {
114
+ }
115
+ }
116
+ this._hooks[name] = this._hooks[name] || [];
117
+ this._hooks[name].push(function_);
118
+ return () => {
119
+ if (function_) {
120
+ this.removeHook(name, function_);
121
+ function_ = void 0;
122
+ }
123
+ };
124
+ }
125
+ hookOnce(name, function_) {
126
+ let _unreg;
127
+ let _function = (...arguments_) => {
128
+ if (typeof _unreg === "function") {
129
+ _unreg();
130
+ }
131
+ _unreg = void 0;
132
+ _function = void 0;
133
+ return function_(...arguments_);
134
+ };
135
+ _unreg = this.hook(name, _function);
136
+ return _unreg;
137
+ }
138
+ removeHook(name, function_) {
139
+ if (this._hooks[name]) {
140
+ const index = this._hooks[name].indexOf(function_);
141
+ if (index !== -1) {
142
+ this._hooks[name].splice(index, 1);
143
+ }
144
+ if (this._hooks[name].length === 0) {
145
+ delete this._hooks[name];
146
+ }
147
+ }
148
+ }
149
+ deprecateHook(name, deprecated) {
150
+ this._deprecatedHooks[name] = typeof deprecated === "string" ? { to: deprecated } : deprecated;
151
+ const _hooks = this._hooks[name] || [];
152
+ delete this._hooks[name];
153
+ for (const hook of _hooks) {
154
+ this.hook(name, hook);
155
+ }
156
+ }
157
+ deprecateHooks(deprecatedHooks) {
158
+ Object.assign(this._deprecatedHooks, deprecatedHooks);
159
+ for (const name in deprecatedHooks) {
160
+ this.deprecateHook(name, deprecatedHooks[name]);
161
+ }
162
+ }
163
+ addHooks(configHooks) {
164
+ const hooks = flatHooks(configHooks);
165
+ const removeFns = Object.keys(hooks).map(
166
+ (key) => this.hook(key, hooks[key])
167
+ );
168
+ return () => {
169
+ for (const unreg of removeFns.splice(0, removeFns.length)) {
170
+ unreg();
171
+ }
172
+ };
173
+ }
174
+ removeHooks(configHooks) {
175
+ const hooks = flatHooks(configHooks);
176
+ for (const key in hooks) {
177
+ this.removeHook(key, hooks[key]);
178
+ }
179
+ }
180
+ removeAllHooks() {
181
+ for (const key in this._hooks) {
182
+ delete this._hooks[key];
183
+ }
184
+ }
185
+ callHook(name, ...arguments_) {
186
+ arguments_.unshift(name);
187
+ return this.callHookWith(serialTaskCaller, name, ...arguments_);
188
+ }
189
+ callHookParallel(name, ...arguments_) {
190
+ arguments_.unshift(name);
191
+ return this.callHookWith(parallelTaskCaller, name, ...arguments_);
192
+ }
193
+ callHookWith(caller, name, ...arguments_) {
194
+ const event = this._before || this._after ? { name, args: arguments_, context: {} } : void 0;
195
+ if (this._before) {
196
+ callEachWith(this._before, event);
197
+ }
198
+ const result = caller(
199
+ name in this._hooks ? [...this._hooks[name]] : [],
200
+ arguments_
201
+ );
202
+ if (result instanceof Promise) {
203
+ return result.finally(() => {
204
+ if (this._after && event) {
205
+ callEachWith(this._after, event);
206
+ }
207
+ });
208
+ }
209
+ if (this._after && event) {
210
+ callEachWith(this._after, event);
211
+ }
212
+ return result;
213
+ }
214
+ beforeEach(function_) {
215
+ this._before = this._before || [];
216
+ this._before.push(function_);
217
+ return () => {
218
+ if (this._before !== void 0) {
219
+ const index = this._before.indexOf(function_);
220
+ if (index !== -1) {
221
+ this._before.splice(index, 1);
222
+ }
223
+ }
224
+ };
225
+ }
226
+ afterEach(function_) {
227
+ this._after = this._after || [];
228
+ this._after.push(function_);
229
+ return () => {
230
+ if (this._after !== void 0) {
231
+ const index = this._after.indexOf(function_);
232
+ if (index !== -1) {
233
+ this._after.splice(index, 1);
234
+ }
235
+ }
236
+ };
237
+ }
238
+ }
239
+ function createHooks() {
240
+ return new Hookable();
241
+ }
242
+
243
+ const isBrowser = typeof window !== "undefined";
244
+ function createDebugger(hooks, _options = {}) {
245
+ const options = {
246
+ inspect: isBrowser,
247
+ group: isBrowser,
248
+ filter: () => true,
249
+ ..._options
250
+ };
251
+ const _filter = options.filter;
252
+ const filter = typeof _filter === "string" ? (name) => name.startsWith(_filter) : _filter;
253
+ const _tag = options.tag ? `[${options.tag}] ` : "";
254
+ const logPrefix = (event) => _tag + event.name + "".padEnd(event._id, "\0");
255
+ const _idCtr = {};
256
+ const unsubscribeBefore = hooks.beforeEach((event) => {
257
+ if (filter !== void 0 && !filter(event.name)) {
258
+ return;
259
+ }
260
+ _idCtr[event.name] = _idCtr[event.name] || 0;
261
+ event._id = _idCtr[event.name]++;
262
+ console.time(logPrefix(event));
263
+ });
264
+ const unsubscribeAfter = hooks.afterEach((event) => {
265
+ if (filter !== void 0 && !filter(event.name)) {
266
+ return;
267
+ }
268
+ if (options.group) {
269
+ console.groupCollapsed(event.name);
270
+ }
271
+ if (options.inspect) {
272
+ console.timeLog(logPrefix(event), event.args);
273
+ } else {
274
+ console.timeEnd(logPrefix(event));
275
+ }
276
+ if (options.group) {
277
+ console.groupEnd();
278
+ }
279
+ _idCtr[event.name]--;
280
+ });
281
+ return {
282
+ /** Stop debugging and remove listeners */
283
+ close: () => {
284
+ unsubscribeBefore();
285
+ unsubscribeAfter();
286
+ }
287
+ };
288
+ }
289
+
290
+ export { Hookable, createDebugger, createHooks, flatHooks, mergeHooks, parallelCaller, serial, serialCaller };
@@ -0,0 +1,49 @@
1
+ {
2
+ "name": "hookable",
3
+ "version": "5.5.3",
4
+ "description": "Awaitable hook system",
5
+ "keywords": [
6
+ "hook",
7
+ "hookable",
8
+ "plugin",
9
+ "tapable",
10
+ "tappable"
11
+ ],
12
+ "repository": "unjs/hookable",
13
+ "license": "MIT",
14
+ "exports": {
15
+ "import": "./dist/index.mjs",
16
+ "types": "./dist/index.d.ts",
17
+ "require": "./dist/index.cjs"
18
+ },
19
+ "main": "./dist/index.cjs",
20
+ "module": "./dist/index.mjs",
21
+ "types": "./dist/index.d.ts",
22
+ "files": [
23
+ "dist"
24
+ ],
25
+ "devDependencies": {
26
+ "@types/node": "^18.15.11",
27
+ "@vitest/coverage-c8": "^0.29.8",
28
+ "changelogen": "^0.5.2",
29
+ "eslint": "^8.37.0",
30
+ "eslint-config-unjs": "^0.1.0",
31
+ "expect-type": "^0.15.0",
32
+ "prettier": "^2.8.7",
33
+ "typescript": "^5.0.2",
34
+ "unbuild": "^1.1.2",
35
+ "vite": "^4.2.1",
36
+ "vitest": "^0.29.8"
37
+ },
38
+ "packageManager": "pnpm@8.0.0",
39
+ "scripts": {
40
+ "build": "unbuild",
41
+ "dev": "vitest",
42
+ "lint": "eslint --cache --ext .ts,.js,.mjs,.cjs . && prettier -c src test",
43
+ "lint:fix": "eslint --cache --ext .ts,.js,.mjs,.cjs . --fix && prettier -c src test -w",
44
+ "prepublish": "pnpm build",
45
+ "release": "pnpm test && pnpm build && changelogen --release --push && pnpm publish",
46
+ "test": "pnpm lint && vitest run --coverage",
47
+ "test:types": "tsc --noEmit"
48
+ }
49
+ }
@@ -0,0 +1,121 @@
1
+ /* -*- Mode: js; js-indent-level: 2; -*- */
2
+ /*
3
+ * Copyright 2011 Mozilla Foundation and contributors
4
+ * Licensed under the New BSD license. See LICENSE or:
5
+ * http://opensource.org/licenses/BSD-3-Clause
6
+ */
7
+
8
+ var util = require('./util');
9
+ var has = Object.prototype.hasOwnProperty;
10
+ var hasNativeMap = typeof Map !== "undefined";
11
+
12
+ /**
13
+ * A data structure which is a combination of an array and a set. Adding a new
14
+ * member is O(1), testing for membership is O(1), and finding the index of an
15
+ * element is O(1). Removing elements from the set is not supported. Only
16
+ * strings are supported for membership.
17
+ */
18
+ function ArraySet() {
19
+ this._array = [];
20
+ this._set = hasNativeMap ? new Map() : Object.create(null);
21
+ }
22
+
23
+ /**
24
+ * Static method for creating ArraySet instances from an existing array.
25
+ */
26
+ ArraySet.fromArray = function ArraySet_fromArray(aArray, aAllowDuplicates) {
27
+ var set = new ArraySet();
28
+ for (var i = 0, len = aArray.length; i < len; i++) {
29
+ set.add(aArray[i], aAllowDuplicates);
30
+ }
31
+ return set;
32
+ };
33
+
34
+ /**
35
+ * Return how many unique items are in this ArraySet. If duplicates have been
36
+ * added, than those do not count towards the size.
37
+ *
38
+ * @returns Number
39
+ */
40
+ ArraySet.prototype.size = function ArraySet_size() {
41
+ return hasNativeMap ? this._set.size : Object.getOwnPropertyNames(this._set).length;
42
+ };
43
+
44
+ /**
45
+ * Add the given string to this set.
46
+ *
47
+ * @param String aStr
48
+ */
49
+ ArraySet.prototype.add = function ArraySet_add(aStr, aAllowDuplicates) {
50
+ var sStr = hasNativeMap ? aStr : util.toSetString(aStr);
51
+ var isDuplicate = hasNativeMap ? this.has(aStr) : has.call(this._set, sStr);
52
+ var idx = this._array.length;
53
+ if (!isDuplicate || aAllowDuplicates) {
54
+ this._array.push(aStr);
55
+ }
56
+ if (!isDuplicate) {
57
+ if (hasNativeMap) {
58
+ this._set.set(aStr, idx);
59
+ } else {
60
+ this._set[sStr] = idx;
61
+ }
62
+ }
63
+ };
64
+
65
+ /**
66
+ * Is the given string a member of this set?
67
+ *
68
+ * @param String aStr
69
+ */
70
+ ArraySet.prototype.has = function ArraySet_has(aStr) {
71
+ if (hasNativeMap) {
72
+ return this._set.has(aStr);
73
+ } else {
74
+ var sStr = util.toSetString(aStr);
75
+ return has.call(this._set, sStr);
76
+ }
77
+ };
78
+
79
+ /**
80
+ * What is the index of the given string in the array?
81
+ *
82
+ * @param String aStr
83
+ */
84
+ ArraySet.prototype.indexOf = function ArraySet_indexOf(aStr) {
85
+ if (hasNativeMap) {
86
+ var idx = this._set.get(aStr);
87
+ if (idx >= 0) {
88
+ return idx;
89
+ }
90
+ } else {
91
+ var sStr = util.toSetString(aStr);
92
+ if (has.call(this._set, sStr)) {
93
+ return this._set[sStr];
94
+ }
95
+ }
96
+
97
+ throw new Error('"' + aStr + '" is not in the set.');
98
+ };
99
+
100
+ /**
101
+ * What is the element at the given index?
102
+ *
103
+ * @param Number aIdx
104
+ */
105
+ ArraySet.prototype.at = function ArraySet_at(aIdx) {
106
+ if (aIdx >= 0 && aIdx < this._array.length) {
107
+ return this._array[aIdx];
108
+ }
109
+ throw new Error('No element indexed by ' + aIdx);
110
+ };
111
+
112
+ /**
113
+ * Returns the array representation of this set (which has the proper indices
114
+ * indicated by indexOf). Note that this is a copy of the internal array used
115
+ * for storing the members so that no one can mess with internal state.
116
+ */
117
+ ArraySet.prototype.toArray = function ArraySet_toArray() {
118
+ return this._array.slice();
119
+ };
120
+
121
+ exports.ArraySet = ArraySet;
@@ -0,0 +1,140 @@
1
+ /* -*- Mode: js; js-indent-level: 2; -*- */
2
+ /*
3
+ * Copyright 2011 Mozilla Foundation and contributors
4
+ * Licensed under the New BSD license. See LICENSE or:
5
+ * http://opensource.org/licenses/BSD-3-Clause
6
+ *
7
+ * Based on the Base 64 VLQ implementation in Closure Compiler:
8
+ * https://code.google.com/p/closure-compiler/source/browse/trunk/src/com/google/debugging/sourcemap/Base64VLQ.java
9
+ *
10
+ * Copyright 2011 The Closure Compiler Authors. All rights reserved.
11
+ * Redistribution and use in source and binary forms, with or without
12
+ * modification, are permitted provided that the following conditions are
13
+ * met:
14
+ *
15
+ * * Redistributions of source code must retain the above copyright
16
+ * notice, this list of conditions and the following disclaimer.
17
+ * * Redistributions in binary form must reproduce the above
18
+ * copyright notice, this list of conditions and the following
19
+ * disclaimer in the documentation and/or other materials provided
20
+ * with the distribution.
21
+ * * Neither the name of Google Inc. nor the names of its
22
+ * contributors may be used to endorse or promote products derived
23
+ * from this software without specific prior written permission.
24
+ *
25
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36
+ */
37
+
38
+ var base64 = require('./base64');
39
+
40
+ // A single base 64 digit can contain 6 bits of data. For the base 64 variable
41
+ // length quantities we use in the source map spec, the first bit is the sign,
42
+ // the next four bits are the actual value, and the 6th bit is the
43
+ // continuation bit. The continuation bit tells us whether there are more
44
+ // digits in this value following this digit.
45
+ //
46
+ // Continuation
47
+ // | Sign
48
+ // | |
49
+ // V V
50
+ // 101011
51
+
52
+ var VLQ_BASE_SHIFT = 5;
53
+
54
+ // binary: 100000
55
+ var VLQ_BASE = 1 << VLQ_BASE_SHIFT;
56
+
57
+ // binary: 011111
58
+ var VLQ_BASE_MASK = VLQ_BASE - 1;
59
+
60
+ // binary: 100000
61
+ var VLQ_CONTINUATION_BIT = VLQ_BASE;
62
+
63
+ /**
64
+ * Converts from a two-complement value to a value where the sign bit is
65
+ * placed in the least significant bit. For example, as decimals:
66
+ * 1 becomes 2 (10 binary), -1 becomes 3 (11 binary)
67
+ * 2 becomes 4 (100 binary), -2 becomes 5 (101 binary)
68
+ */
69
+ function toVLQSigned(aValue) {
70
+ return aValue < 0
71
+ ? ((-aValue) << 1) + 1
72
+ : (aValue << 1) + 0;
73
+ }
74
+
75
+ /**
76
+ * Converts to a two-complement value from a value where the sign bit is
77
+ * placed in the least significant bit. For example, as decimals:
78
+ * 2 (10 binary) becomes 1, 3 (11 binary) becomes -1
79
+ * 4 (100 binary) becomes 2, 5 (101 binary) becomes -2
80
+ */
81
+ function fromVLQSigned(aValue) {
82
+ var isNegative = (aValue & 1) === 1;
83
+ var shifted = aValue >> 1;
84
+ return isNegative
85
+ ? -shifted
86
+ : shifted;
87
+ }
88
+
89
+ /**
90
+ * Returns the base 64 VLQ encoded value.
91
+ */
92
+ exports.encode = function base64VLQ_encode(aValue) {
93
+ var encoded = "";
94
+ var digit;
95
+
96
+ var vlq = toVLQSigned(aValue);
97
+
98
+ do {
99
+ digit = vlq & VLQ_BASE_MASK;
100
+ vlq >>>= VLQ_BASE_SHIFT;
101
+ if (vlq > 0) {
102
+ // There are still more digits in this value, so we must make sure the
103
+ // continuation bit is marked.
104
+ digit |= VLQ_CONTINUATION_BIT;
105
+ }
106
+ encoded += base64.encode(digit);
107
+ } while (vlq > 0);
108
+
109
+ return encoded;
110
+ };
111
+
112
+ /**
113
+ * Decodes the next base 64 VLQ value from the given string and returns the
114
+ * value and the rest of the string via the out parameter.
115
+ */
116
+ exports.decode = function base64VLQ_decode(aStr, aIndex, aOutParam) {
117
+ var strLen = aStr.length;
118
+ var result = 0;
119
+ var shift = 0;
120
+ var continuation, digit;
121
+
122
+ do {
123
+ if (aIndex >= strLen) {
124
+ throw new Error("Expected more digits in base 64 VLQ value.");
125
+ }
126
+
127
+ digit = base64.decode(aStr.charCodeAt(aIndex++));
128
+ if (digit === -1) {
129
+ throw new Error("Invalid base64 digit: " + aStr.charAt(aIndex - 1));
130
+ }
131
+
132
+ continuation = !!(digit & VLQ_CONTINUATION_BIT);
133
+ digit &= VLQ_BASE_MASK;
134
+ result = result + (digit << shift);
135
+ shift += VLQ_BASE_SHIFT;
136
+ } while (continuation);
137
+
138
+ aOutParam.value = fromVLQSigned(result);
139
+ aOutParam.rest = aIndex;
140
+ };
@@ -0,0 +1,67 @@
1
+ /* -*- Mode: js; js-indent-level: 2; -*- */
2
+ /*
3
+ * Copyright 2011 Mozilla Foundation and contributors
4
+ * Licensed under the New BSD license. See LICENSE or:
5
+ * http://opensource.org/licenses/BSD-3-Clause
6
+ */
7
+
8
+ var intToCharMap = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'.split('');
9
+
10
+ /**
11
+ * Encode an integer in the range of 0 to 63 to a single base 64 digit.
12
+ */
13
+ exports.encode = function (number) {
14
+ if (0 <= number && number < intToCharMap.length) {
15
+ return intToCharMap[number];
16
+ }
17
+ throw new TypeError("Must be between 0 and 63: " + number);
18
+ };
19
+
20
+ /**
21
+ * Decode a single base 64 character code digit to an integer. Returns -1 on
22
+ * failure.
23
+ */
24
+ exports.decode = function (charCode) {
25
+ var bigA = 65; // 'A'
26
+ var bigZ = 90; // 'Z'
27
+
28
+ var littleA = 97; // 'a'
29
+ var littleZ = 122; // 'z'
30
+
31
+ var zero = 48; // '0'
32
+ var nine = 57; // '9'
33
+
34
+ var plus = 43; // '+'
35
+ var slash = 47; // '/'
36
+
37
+ var littleOffset = 26;
38
+ var numberOffset = 52;
39
+
40
+ // 0 - 25: ABCDEFGHIJKLMNOPQRSTUVWXYZ
41
+ if (bigA <= charCode && charCode <= bigZ) {
42
+ return (charCode - bigA);
43
+ }
44
+
45
+ // 26 - 51: abcdefghijklmnopqrstuvwxyz
46
+ if (littleA <= charCode && charCode <= littleZ) {
47
+ return (charCode - littleA + littleOffset);
48
+ }
49
+
50
+ // 52 - 61: 0123456789
51
+ if (zero <= charCode && charCode <= nine) {
52
+ return (charCode - zero + numberOffset);
53
+ }
54
+
55
+ // 62: +
56
+ if (charCode == plus) {
57
+ return 62;
58
+ }
59
+
60
+ // 63: /
61
+ if (charCode == slash) {
62
+ return 63;
63
+ }
64
+
65
+ // Invalid base64 digit.
66
+ return -1;
67
+ };