spoint 0.1.0 → 0.1.11

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 (204) hide show
  1. package/README.md +134 -209
  2. package/SKILL.md +95 -0
  3. package/apps/environment/index.js +200 -1
  4. package/apps/environment/models/decorative/.gitkeep +0 -0
  5. package/apps/environment/models/hazards/.gitkeep +0 -0
  6. package/apps/environment/models/interactive/.gitkeep +0 -0
  7. package/apps/environment/models/structures/.gitkeep +0 -0
  8. package/apps/environment/smartObjects.js +114 -0
  9. package/apps/interactable/index.js +155 -0
  10. package/apps/physics-crate/index.js +15 -9
  11. package/apps/power-crate/index.js +18 -12
  12. package/apps/tps-game/$GDUPI.vrm +0 -0
  13. package/apps/tps-game/Cleetus.vrm +0 -0
  14. package/apps/tps-game/index.js +185 -27
  15. package/apps/world/index.js +68 -22
  16. package/bin/create-app.js +337 -0
  17. package/client/ARControls.js +301 -0
  18. package/client/LoadingManager.js +117 -0
  19. package/client/MobileControls.js +1122 -0
  20. package/client/anim-lib.glb +0 -0
  21. package/client/animation.js +306 -0
  22. package/client/app.js +1341 -65
  23. package/client/camera.js +191 -33
  24. package/client/createLoadingScreen.js +69 -0
  25. package/client/editor/bridge.js +113 -0
  26. package/client/editor/css/main.css +794 -0
  27. package/client/editor/images/rotate.svg +4 -0
  28. package/client/editor/images/scale.svg +4 -0
  29. package/client/editor/images/translate.svg +4 -0
  30. package/client/editor/index.html +103 -0
  31. package/client/editor/js/Command.js +41 -0
  32. package/client/editor/js/Config.js +81 -0
  33. package/client/editor/js/Editor.js +785 -0
  34. package/client/editor/js/EditorControls.js +438 -0
  35. package/client/editor/js/History.js +321 -0
  36. package/client/editor/js/Loader.js +987 -0
  37. package/client/editor/js/LoaderUtils.js +90 -0
  38. package/client/editor/js/Menubar.Add.js +510 -0
  39. package/client/editor/js/Menubar.Edit.js +145 -0
  40. package/client/editor/js/Menubar.File.js +466 -0
  41. package/client/editor/js/Menubar.Help.js +73 -0
  42. package/client/editor/js/Menubar.Status.js +51 -0
  43. package/client/editor/js/Menubar.View.js +183 -0
  44. package/client/editor/js/Menubar.js +27 -0
  45. package/client/editor/js/Player.js +53 -0
  46. package/client/editor/js/Resizer.js +58 -0
  47. package/client/editor/js/Script.js +503 -0
  48. package/client/editor/js/Selector.js +102 -0
  49. package/client/editor/js/Sidebar.Geometry.BoxGeometry.js +121 -0
  50. package/client/editor/js/Sidebar.Geometry.BufferGeometry.js +115 -0
  51. package/client/editor/js/Sidebar.Geometry.CapsuleGeometry.js +97 -0
  52. package/client/editor/js/Sidebar.Geometry.CircleGeometry.js +97 -0
  53. package/client/editor/js/Sidebar.Geometry.CylinderGeometry.js +121 -0
  54. package/client/editor/js/Sidebar.Geometry.DodecahedronGeometry.js +73 -0
  55. package/client/editor/js/Sidebar.Geometry.ExtrudeGeometry.js +196 -0
  56. package/client/editor/js/Sidebar.Geometry.IcosahedronGeometry.js +73 -0
  57. package/client/editor/js/Sidebar.Geometry.LatheGeometry.js +98 -0
  58. package/client/editor/js/Sidebar.Geometry.Modifiers.js +73 -0
  59. package/client/editor/js/Sidebar.Geometry.OctahedronGeometry.js +74 -0
  60. package/client/editor/js/Sidebar.Geometry.PlaneGeometry.js +97 -0
  61. package/client/editor/js/Sidebar.Geometry.RingGeometry.js +121 -0
  62. package/client/editor/js/Sidebar.Geometry.ShapeGeometry.js +76 -0
  63. package/client/editor/js/Sidebar.Geometry.SphereGeometry.js +133 -0
  64. package/client/editor/js/Sidebar.Geometry.TetrahedronGeometry.js +74 -0
  65. package/client/editor/js/Sidebar.Geometry.TorusGeometry.js +109 -0
  66. package/client/editor/js/Sidebar.Geometry.TorusKnotGeometry.js +121 -0
  67. package/client/editor/js/Sidebar.Geometry.TubeGeometry.js +135 -0
  68. package/client/editor/js/Sidebar.Geometry.js +332 -0
  69. package/client/editor/js/Sidebar.Material.BooleanProperty.js +60 -0
  70. package/client/editor/js/Sidebar.Material.ColorProperty.js +87 -0
  71. package/client/editor/js/Sidebar.Material.ConstantProperty.js +62 -0
  72. package/client/editor/js/Sidebar.Material.MapProperty.js +249 -0
  73. package/client/editor/js/Sidebar.Material.NumberProperty.js +60 -0
  74. package/client/editor/js/Sidebar.Material.Program.js +73 -0
  75. package/client/editor/js/Sidebar.Material.RangeValueProperty.js +63 -0
  76. package/client/editor/js/Sidebar.Material.js +751 -0
  77. package/client/editor/js/Sidebar.Object.Animation.js +102 -0
  78. package/client/editor/js/Sidebar.Object.js +898 -0
  79. package/client/editor/js/Sidebar.Project.App.js +165 -0
  80. package/client/editor/js/Sidebar.Project.Image.js +225 -0
  81. package/client/editor/js/Sidebar.Project.Materials.js +82 -0
  82. package/client/editor/js/Sidebar.Project.Renderer.js +144 -0
  83. package/client/editor/js/Sidebar.Project.Video.js +242 -0
  84. package/client/editor/js/Sidebar.Project.js +31 -0
  85. package/client/editor/js/Sidebar.Properties.js +73 -0
  86. package/client/editor/js/Sidebar.Scene.js +585 -0
  87. package/client/editor/js/Sidebar.Script.js +129 -0
  88. package/client/editor/js/Sidebar.Settings.History.js +146 -0
  89. package/client/editor/js/Sidebar.Settings.Shortcuts.js +175 -0
  90. package/client/editor/js/Sidebar.Settings.js +60 -0
  91. package/client/editor/js/Sidebar.js +41 -0
  92. package/client/editor/js/Storage.js +98 -0
  93. package/client/editor/js/Strings.js +2028 -0
  94. package/client/editor/js/Toolbar.js +84 -0
  95. package/client/editor/js/Viewport.Controls.js +92 -0
  96. package/client/editor/js/Viewport.Info.js +136 -0
  97. package/client/editor/js/Viewport.Pathtracer.js +91 -0
  98. package/client/editor/js/Viewport.ViewHelper.js +39 -0
  99. package/client/editor/js/Viewport.XR.js +222 -0
  100. package/client/editor/js/Viewport.js +900 -0
  101. package/client/editor/js/commands/AddObjectCommand.js +68 -0
  102. package/client/editor/js/commands/AddScriptCommand.js +75 -0
  103. package/client/editor/js/commands/Commands.js +23 -0
  104. package/client/editor/js/commands/MoveObjectCommand.js +111 -0
  105. package/client/editor/js/commands/MultiCmdsCommand.js +85 -0
  106. package/client/editor/js/commands/RemoveObjectCommand.js +88 -0
  107. package/client/editor/js/commands/RemoveScriptCommand.js +81 -0
  108. package/client/editor/js/commands/SetColorCommand.js +73 -0
  109. package/client/editor/js/commands/SetGeometryCommand.js +87 -0
  110. package/client/editor/js/commands/SetGeometryValueCommand.js +70 -0
  111. package/client/editor/js/commands/SetMaterialColorCommand.js +86 -0
  112. package/client/editor/js/commands/SetMaterialCommand.js +79 -0
  113. package/client/editor/js/commands/SetMaterialMapCommand.js +143 -0
  114. package/client/editor/js/commands/SetMaterialRangeCommand.js +91 -0
  115. package/client/editor/js/commands/SetMaterialValueCommand.js +90 -0
  116. package/client/editor/js/commands/SetMaterialVectorCommand.js +79 -0
  117. package/client/editor/js/commands/SetPositionCommand.js +84 -0
  118. package/client/editor/js/commands/SetRotationCommand.js +84 -0
  119. package/client/editor/js/commands/SetScaleCommand.js +84 -0
  120. package/client/editor/js/commands/SetSceneCommand.js +103 -0
  121. package/client/editor/js/commands/SetScriptValueCommand.js +80 -0
  122. package/client/editor/js/commands/SetShadowValueCommand.js +73 -0
  123. package/client/editor/js/commands/SetUuidCommand.js +70 -0
  124. package/client/editor/js/commands/SetValueCommand.js +75 -0
  125. package/client/editor/js/libs/acorn/acorn.js +3236 -0
  126. package/client/editor/js/libs/acorn/acorn_loose.js +1299 -0
  127. package/client/editor/js/libs/acorn/walk.js +344 -0
  128. package/client/editor/js/libs/app/index.html +57 -0
  129. package/client/editor/js/libs/app.js +251 -0
  130. package/client/editor/js/libs/codemirror/addon/dialog.css +32 -0
  131. package/client/editor/js/libs/codemirror/addon/dialog.js +163 -0
  132. package/client/editor/js/libs/codemirror/addon/show-hint.css +36 -0
  133. package/client/editor/js/libs/codemirror/addon/show-hint.js +529 -0
  134. package/client/editor/js/libs/codemirror/addon/tern.css +87 -0
  135. package/client/editor/js/libs/codemirror/addon/tern.js +750 -0
  136. package/client/editor/js/libs/codemirror/codemirror.css +344 -0
  137. package/client/editor/js/libs/codemirror/codemirror.js +9849 -0
  138. package/client/editor/js/libs/codemirror/mode/glsl.js +233 -0
  139. package/client/editor/js/libs/codemirror/mode/javascript.js +959 -0
  140. package/client/editor/js/libs/codemirror/theme/monokai.css +41 -0
  141. package/client/editor/js/libs/esprima.js +6401 -0
  142. package/client/editor/js/libs/jsonlint.js +453 -0
  143. package/client/editor/js/libs/signals.min.js +14 -0
  144. package/client/editor/js/libs/tern-threejs/threejs.js +5031 -0
  145. package/client/editor/js/libs/ternjs/comment.js +87 -0
  146. package/client/editor/js/libs/ternjs/def.js +588 -0
  147. package/client/editor/js/libs/ternjs/doc_comment.js +401 -0
  148. package/client/editor/js/libs/ternjs/infer.js +1635 -0
  149. package/client/editor/js/libs/ternjs/polyfill.js +80 -0
  150. package/client/editor/js/libs/ternjs/signal.js +26 -0
  151. package/client/editor/js/libs/ternjs/tern.js +993 -0
  152. package/client/editor/js/libs/ui.js +1346 -0
  153. package/client/editor/js/libs/ui.three.js +855 -0
  154. package/client/facial-animation.js +455 -0
  155. package/client/index.html +7 -4
  156. package/client/loading.css +147 -0
  157. package/client/loading.html +25 -0
  158. package/client/style.css +251 -0
  159. package/package.json +7 -3
  160. package/server.js +9 -1
  161. package/src/apps/AppContext.js +1 -1
  162. package/src/apps/AppLoader.js +50 -37
  163. package/src/apps/AppRuntime.js +32 -8
  164. package/src/client/InputHandler.js +233 -0
  165. package/src/client/JitterBuffer.js +207 -0
  166. package/src/client/KalmanFilter.js +125 -0
  167. package/src/client/MessageHandler.js +101 -0
  168. package/src/client/PhysicsNetworkClient.js +141 -68
  169. package/src/client/ReconnectManager.js +62 -0
  170. package/src/client/SmoothInterpolation.js +127 -0
  171. package/src/client/SnapshotProcessor.js +144 -0
  172. package/src/connection/ConnectionManager.js +21 -3
  173. package/src/connection/SessionStore.js +13 -3
  174. package/src/index.client.js +4 -6
  175. package/src/netcode/EventLog.js +29 -15
  176. package/src/netcode/LagCompensator.js +25 -26
  177. package/src/netcode/NetworkState.js +4 -1
  178. package/src/netcode/PhysicsIntegration.js +20 -6
  179. package/src/netcode/PlayerManager.js +10 -2
  180. package/src/netcode/SnapshotEncoder.js +66 -19
  181. package/src/netcode/TickSystem.js +13 -4
  182. package/src/physics/World.js +66 -13
  183. package/src/protocol/msgpack.js +90 -63
  184. package/src/sdk/ReloadHandlers.js +12 -2
  185. package/src/sdk/ReloadManager.js +5 -0
  186. package/src/sdk/ServerHandlers.js +50 -11
  187. package/src/sdk/StaticHandler.js +22 -6
  188. package/src/sdk/TickHandler.js +101 -34
  189. package/src/sdk/scaffold.js +31 -0
  190. package/src/sdk/server.js +59 -33
  191. package/src/shared/movement.js +2 -1
  192. package/src/spatial/Octree.js +5 -0
  193. package/apps/interactive-door/index.js +0 -33
  194. package/apps/patrol-npc/index.js +0 -37
  195. package/src/connection/QualityMonitor.js +0 -46
  196. package/src/debug/StateInspector.js +0 -42
  197. package/src/index.js +0 -1
  198. package/src/index.server.js +0 -27
  199. package/src/protocol/Codec.js +0 -60
  200. package/src/protocol/SequenceTracker.js +0 -71
  201. package/src/sdk/ClientMessageHandler.js +0 -80
  202. package/src/sdk/client.js +0 -122
  203. package/world/kaira.glb +0 -0
  204. package/world/schwust.glb +0 -0
@@ -0,0 +1,529 @@
1
+ // CodeMirror, copyright (c) by Marijn Haverbeke and others
2
+ // Distributed under an MIT license: https://codemirror.net/LICENSE
3
+
4
+ // declare global: DOMRect
5
+
6
+ (function(mod) {
7
+ if (typeof exports == "object" && typeof module == "object") // CommonJS
8
+ mod(require("../../lib/codemirror"));
9
+ else if (typeof define == "function" && define.amd) // AMD
10
+ define(["../../lib/codemirror"], mod);
11
+ else // Plain browser env
12
+ mod(CodeMirror);
13
+ })(function(CodeMirror) {
14
+ "use strict";
15
+
16
+ var HINT_ELEMENT_CLASS = "CodeMirror-hint";
17
+ var ACTIVE_HINT_ELEMENT_CLASS = "CodeMirror-hint-active";
18
+
19
+ // This is the old interface, kept around for now to stay
20
+ // backwards-compatible.
21
+ CodeMirror.showHint = function(cm, getHints, options) {
22
+ if (!getHints) return cm.showHint(options);
23
+ if (options && options.async) getHints.async = true;
24
+ var newOpts = {hint: getHints};
25
+ if (options) for (var prop in options) newOpts[prop] = options[prop];
26
+ return cm.showHint(newOpts);
27
+ };
28
+
29
+ CodeMirror.defineExtension("showHint", function(options) {
30
+ options = parseOptions(this, this.getCursor("start"), options);
31
+ var selections = this.listSelections();
32
+ if (selections.length > 1) return;
33
+ // By default, don't allow completion when something is selected.
34
+ // A hint function can have a `supportsSelection` property to
35
+ // indicate that it can handle selections.
36
+ if (this.somethingSelected()) {
37
+ if (!options.hint.supportsSelection) return;
38
+ // Don't try with cross-line selections
39
+ for (var i = 0; i < selections.length; i++)
40
+ if (selections[i].head.line != selections[i].anchor.line) return;
41
+ }
42
+
43
+ if (this.state.completionActive) this.state.completionActive.close();
44
+ var completion = this.state.completionActive = new Completion(this, options);
45
+ if (!completion.options.hint) return;
46
+
47
+ CodeMirror.signal(this, "startCompletion", this);
48
+ completion.update(true);
49
+ });
50
+
51
+ CodeMirror.defineExtension("closeHint", function() {
52
+ if (this.state.completionActive) this.state.completionActive.close()
53
+ });
54
+
55
+ function Completion(cm, options) {
56
+ this.cm = cm;
57
+ this.options = options;
58
+ this.widget = null;
59
+ this.debounce = 0;
60
+ this.tick = 0;
61
+ this.startPos = this.cm.getCursor("start");
62
+ this.startLen = this.cm.getLine(this.startPos.line).length - this.cm.getSelection().length;
63
+
64
+ if (this.options.updateOnCursorActivity) {
65
+ var self = this;
66
+ cm.on("cursorActivity", this.activityFunc = function() { self.cursorActivity(); });
67
+ }
68
+ }
69
+
70
+ var requestAnimationFrame = window.requestAnimationFrame || function(fn) {
71
+ return setTimeout(fn, 1000/60);
72
+ };
73
+ var cancelAnimationFrame = window.cancelAnimationFrame || clearTimeout;
74
+
75
+ Completion.prototype = {
76
+ close: function() {
77
+ if (!this.active()) return;
78
+ this.cm.state.completionActive = null;
79
+ this.tick = null;
80
+ if (this.options.updateOnCursorActivity) {
81
+ this.cm.off("cursorActivity", this.activityFunc);
82
+ }
83
+
84
+ if (this.widget && this.data) CodeMirror.signal(this.data, "close");
85
+ if (this.widget) this.widget.close();
86
+ CodeMirror.signal(this.cm, "endCompletion", this.cm);
87
+ },
88
+
89
+ active: function() {
90
+ return this.cm.state.completionActive == this;
91
+ },
92
+
93
+ pick: function(data, i) {
94
+ var completion = data.list[i], self = this;
95
+ this.cm.operation(function() {
96
+ if (completion.hint)
97
+ completion.hint(self.cm, data, completion);
98
+ else
99
+ self.cm.replaceRange(getText(completion), completion.from || data.from,
100
+ completion.to || data.to, "complete");
101
+ CodeMirror.signal(data, "pick", completion);
102
+ self.cm.scrollIntoView();
103
+ });
104
+ if (this.options.closeOnPick) {
105
+ this.close();
106
+ }
107
+ },
108
+
109
+ cursorActivity: function() {
110
+ if (this.debounce) {
111
+ cancelAnimationFrame(this.debounce);
112
+ this.debounce = 0;
113
+ }
114
+
115
+ var identStart = this.startPos;
116
+ if(this.data) {
117
+ identStart = this.data.from;
118
+ }
119
+
120
+ var pos = this.cm.getCursor(), line = this.cm.getLine(pos.line);
121
+ if (pos.line != this.startPos.line || line.length - pos.ch != this.startLen - this.startPos.ch ||
122
+ pos.ch < identStart.ch || this.cm.somethingSelected() ||
123
+ (!pos.ch || this.options.closeCharacters.test(line.charAt(pos.ch - 1)))) {
124
+ this.close();
125
+ } else {
126
+ var self = this;
127
+ this.debounce = requestAnimationFrame(function() {self.update();});
128
+ if (this.widget) this.widget.disable();
129
+ }
130
+ },
131
+
132
+ update: function(first) {
133
+ if (this.tick == null) return
134
+ var self = this, myTick = ++this.tick
135
+ fetchHints(this.options.hint, this.cm, this.options, function(data) {
136
+ if (self.tick == myTick) self.finishUpdate(data, first)
137
+ })
138
+ },
139
+
140
+ finishUpdate: function(data, first) {
141
+ if (this.data) CodeMirror.signal(this.data, "update");
142
+
143
+ var picked = (this.widget && this.widget.picked) || (first && this.options.completeSingle);
144
+ if (this.widget) this.widget.close();
145
+
146
+ this.data = data;
147
+
148
+ if (data && data.list.length) {
149
+ if (picked && data.list.length == 1) {
150
+ this.pick(data, 0);
151
+ } else {
152
+ this.widget = new Widget(this, data);
153
+ CodeMirror.signal(data, "shown");
154
+ }
155
+ }
156
+ }
157
+ };
158
+
159
+ function parseOptions(cm, pos, options) {
160
+ var editor = cm.options.hintOptions;
161
+ var out = {};
162
+ for (var prop in defaultOptions) out[prop] = defaultOptions[prop];
163
+ if (editor) for (var prop in editor)
164
+ if (editor[prop] !== undefined) out[prop] = editor[prop];
165
+ if (options) for (var prop in options)
166
+ if (options[prop] !== undefined) out[prop] = options[prop];
167
+ if (out.hint.resolve) out.hint = out.hint.resolve(cm, pos)
168
+ return out;
169
+ }
170
+
171
+ function getText(completion) {
172
+ if (typeof completion == "string") return completion;
173
+ else return completion.text;
174
+ }
175
+
176
+ function buildKeyMap(completion, handle) {
177
+ var baseMap = {
178
+ Up: function() {handle.moveFocus(-1);},
179
+ Down: function() {handle.moveFocus(1);},
180
+ PageUp: function() {handle.moveFocus(-handle.menuSize() + 1, true);},
181
+ PageDown: function() {handle.moveFocus(handle.menuSize() - 1, true);},
182
+ Home: function() {handle.setFocus(0);},
183
+ End: function() {handle.setFocus(handle.length - 1);},
184
+ Enter: handle.pick,
185
+ Tab: handle.pick,
186
+ Esc: handle.close
187
+ };
188
+
189
+ var mac = /Mac/.test(navigator.platform);
190
+
191
+ if (mac) {
192
+ baseMap["Ctrl-P"] = function() {handle.moveFocus(-1);};
193
+ baseMap["Ctrl-N"] = function() {handle.moveFocus(1);};
194
+ }
195
+
196
+ var custom = completion.options.customKeys;
197
+ var ourMap = custom ? {} : baseMap;
198
+ function addBinding(key, val) {
199
+ var bound;
200
+ if (typeof val != "string")
201
+ bound = function(cm) { return val(cm, handle); };
202
+ // This mechanism is deprecated
203
+ else if (baseMap.hasOwnProperty(val))
204
+ bound = baseMap[val];
205
+ else
206
+ bound = val;
207
+ ourMap[key] = bound;
208
+ }
209
+ if (custom)
210
+ for (var key in custom) if (custom.hasOwnProperty(key))
211
+ addBinding(key, custom[key]);
212
+ var extra = completion.options.extraKeys;
213
+ if (extra)
214
+ for (var key in extra) if (extra.hasOwnProperty(key))
215
+ addBinding(key, extra[key]);
216
+ return ourMap;
217
+ }
218
+
219
+ function getHintElement(hintsElement, el) {
220
+ while (el && el != hintsElement) {
221
+ if (el.nodeName.toUpperCase() === "LI" && el.parentNode == hintsElement) return el;
222
+ el = el.parentNode;
223
+ }
224
+ }
225
+
226
+ function Widget(completion, data) {
227
+ this.id = "cm-complete-" + Math.floor(Math.random(1e6))
228
+ this.completion = completion;
229
+ this.data = data;
230
+ this.picked = false;
231
+ var widget = this, cm = completion.cm;
232
+ var ownerDocument = cm.getInputField().ownerDocument;
233
+ var parentWindow = ownerDocument.defaultView || ownerDocument.parentWindow;
234
+
235
+ var hints = this.hints = ownerDocument.createElement("ul");
236
+ hints.setAttribute("role", "listbox")
237
+ hints.setAttribute("aria-expanded", "true")
238
+ hints.id = this.id
239
+ var theme = completion.cm.options.theme;
240
+ hints.className = "CodeMirror-hints " + theme;
241
+ this.selectedHint = data.selectedHint || 0;
242
+
243
+ var completions = data.list;
244
+ for (var i = 0; i < completions.length; ++i) {
245
+ var elt = hints.appendChild(ownerDocument.createElement("li")), cur = completions[i];
246
+ var className = HINT_ELEMENT_CLASS + (i != this.selectedHint ? "" : " " + ACTIVE_HINT_ELEMENT_CLASS);
247
+ if (cur.className != null) className = cur.className + " " + className;
248
+ elt.className = className;
249
+ if (i == this.selectedHint) elt.setAttribute("aria-selected", "true")
250
+ elt.id = this.id + "-" + i
251
+ elt.setAttribute("role", "option")
252
+ if (cur.render) cur.render(elt, data, cur);
253
+ else elt.appendChild(ownerDocument.createTextNode(cur.displayText || getText(cur)));
254
+ elt.hintId = i;
255
+ }
256
+
257
+ var container = completion.options.container || ownerDocument.body;
258
+ var pos = cm.cursorCoords(completion.options.alignWithWord ? data.from : null);
259
+ var left = pos.left, top = pos.bottom, below = true;
260
+ var offsetLeft = 0, offsetTop = 0;
261
+ if (container !== ownerDocument.body) {
262
+ // We offset the cursor position because left and top are relative to the offsetParent's top left corner.
263
+ var isContainerPositioned = ['absolute', 'relative', 'fixed'].indexOf(parentWindow.getComputedStyle(container).position) !== -1;
264
+ var offsetParent = isContainerPositioned ? container : container.offsetParent;
265
+ var offsetParentPosition = offsetParent.getBoundingClientRect();
266
+ var bodyPosition = ownerDocument.body.getBoundingClientRect();
267
+ offsetLeft = (offsetParentPosition.left - bodyPosition.left - offsetParent.scrollLeft);
268
+ offsetTop = (offsetParentPosition.top - bodyPosition.top - offsetParent.scrollTop);
269
+ }
270
+ hints.style.left = (left - offsetLeft) + "px";
271
+ hints.style.top = (top - offsetTop) + "px";
272
+
273
+ // If we're at the edge of the screen, then we want the menu to appear on the left of the cursor.
274
+ var winW = parentWindow.innerWidth || Math.max(ownerDocument.body.offsetWidth, ownerDocument.documentElement.offsetWidth);
275
+ var winH = parentWindow.innerHeight || Math.max(ownerDocument.body.offsetHeight, ownerDocument.documentElement.offsetHeight);
276
+ container.appendChild(hints);
277
+ cm.getInputField().setAttribute("aria-autocomplete", "list")
278
+ cm.getInputField().setAttribute("aria-owns", this.id)
279
+ cm.getInputField().setAttribute("aria-activedescendant", this.id + "-" + this.selectedHint)
280
+
281
+ var box = completion.options.moveOnOverlap ? hints.getBoundingClientRect() : new DOMRect();
282
+ var scrolls = completion.options.paddingForScrollbar ? hints.scrollHeight > hints.clientHeight + 1 : false;
283
+
284
+ // Compute in the timeout to avoid reflow on init
285
+ var startScroll;
286
+ setTimeout(function() { startScroll = cm.getScrollInfo(); });
287
+
288
+ var overlapY = box.bottom - winH;
289
+ if (overlapY > 0) {
290
+ var height = box.bottom - box.top, curTop = pos.top - (pos.bottom - box.top);
291
+ if (curTop - height > 0) { // Fits above cursor
292
+ hints.style.top = (top = pos.top - height - offsetTop) + "px";
293
+ below = false;
294
+ } else if (height > winH) {
295
+ hints.style.height = (winH - 5) + "px";
296
+ hints.style.top = (top = pos.bottom - box.top - offsetTop) + "px";
297
+ var cursor = cm.getCursor();
298
+ if (data.from.ch != cursor.ch) {
299
+ pos = cm.cursorCoords(cursor);
300
+ hints.style.left = (left = pos.left - offsetLeft) + "px";
301
+ box = hints.getBoundingClientRect();
302
+ }
303
+ }
304
+ }
305
+ var overlapX = box.right - winW;
306
+ if (scrolls) overlapX += cm.display.nativeBarWidth;
307
+ if (overlapX > 0) {
308
+ if (box.right - box.left > winW) {
309
+ hints.style.width = (winW - 5) + "px";
310
+ overlapX -= (box.right - box.left) - winW;
311
+ }
312
+ hints.style.left = (left = pos.left - overlapX - offsetLeft) + "px";
313
+ }
314
+ if (scrolls) for (var node = hints.firstChild; node; node = node.nextSibling)
315
+ node.style.paddingRight = cm.display.nativeBarWidth + "px"
316
+
317
+ cm.addKeyMap(this.keyMap = buildKeyMap(completion, {
318
+ moveFocus: function(n, avoidWrap) { widget.changeActive(widget.selectedHint + n, avoidWrap); },
319
+ setFocus: function(n) { widget.changeActive(n); },
320
+ menuSize: function() { return widget.screenAmount(); },
321
+ length: completions.length,
322
+ close: function() { completion.close(); },
323
+ pick: function() { widget.pick(); },
324
+ data: data
325
+ }));
326
+
327
+ if (completion.options.closeOnUnfocus) {
328
+ var closingOnBlur;
329
+ cm.on("blur", this.onBlur = function() { closingOnBlur = setTimeout(function() { completion.close(); }, 100); });
330
+ cm.on("focus", this.onFocus = function() { clearTimeout(closingOnBlur); });
331
+ }
332
+
333
+ cm.on("scroll", this.onScroll = function() {
334
+ var curScroll = cm.getScrollInfo(), editor = cm.getWrapperElement().getBoundingClientRect();
335
+ if (!startScroll) startScroll = cm.getScrollInfo();
336
+ var newTop = top + startScroll.top - curScroll.top;
337
+ var point = newTop - (parentWindow.pageYOffset || (ownerDocument.documentElement || ownerDocument.body).scrollTop);
338
+ if (!below) point += hints.offsetHeight;
339
+ if (point <= editor.top || point >= editor.bottom) return completion.close();
340
+ hints.style.top = newTop + "px";
341
+ hints.style.left = (left + startScroll.left - curScroll.left) + "px";
342
+ });
343
+
344
+ CodeMirror.on(hints, "dblclick", function(e) {
345
+ var t = getHintElement(hints, e.target || e.srcElement);
346
+ if (t && t.hintId != null) {widget.changeActive(t.hintId); widget.pick();}
347
+ });
348
+
349
+ CodeMirror.on(hints, "click", function(e) {
350
+ var t = getHintElement(hints, e.target || e.srcElement);
351
+ if (t && t.hintId != null) {
352
+ widget.changeActive(t.hintId);
353
+ if (completion.options.completeOnSingleClick) widget.pick();
354
+ }
355
+ });
356
+
357
+ CodeMirror.on(hints, "mousedown", function() {
358
+ setTimeout(function(){cm.focus();}, 20);
359
+ });
360
+
361
+ // The first hint doesn't need to be scrolled to on init
362
+ var selectedHintRange = this.getSelectedHintRange();
363
+ if (selectedHintRange.from !== 0 || selectedHintRange.to !== 0) {
364
+ this.scrollToActive();
365
+ }
366
+
367
+ CodeMirror.signal(data, "select", completions[this.selectedHint], hints.childNodes[this.selectedHint]);
368
+ return true;
369
+ }
370
+
371
+ Widget.prototype = {
372
+ close: function() {
373
+ if (this.completion.widget != this) return;
374
+ this.completion.widget = null;
375
+ if (this.hints.parentNode) this.hints.parentNode.removeChild(this.hints);
376
+ this.completion.cm.removeKeyMap(this.keyMap);
377
+ var input = this.completion.cm.getInputField()
378
+ input.removeAttribute("aria-activedescendant")
379
+ input.removeAttribute("aria-owns")
380
+
381
+ var cm = this.completion.cm;
382
+ if (this.completion.options.closeOnUnfocus) {
383
+ cm.off("blur", this.onBlur);
384
+ cm.off("focus", this.onFocus);
385
+ }
386
+ cm.off("scroll", this.onScroll);
387
+ },
388
+
389
+ disable: function() {
390
+ this.completion.cm.removeKeyMap(this.keyMap);
391
+ var widget = this;
392
+ this.keyMap = {Enter: function() { widget.picked = true; }};
393
+ this.completion.cm.addKeyMap(this.keyMap);
394
+ },
395
+
396
+ pick: function() {
397
+ this.completion.pick(this.data, this.selectedHint);
398
+ },
399
+
400
+ changeActive: function(i, avoidWrap) {
401
+ if (i >= this.data.list.length)
402
+ i = avoidWrap ? this.data.list.length - 1 : 0;
403
+ else if (i < 0)
404
+ i = avoidWrap ? 0 : this.data.list.length - 1;
405
+ if (this.selectedHint == i) return;
406
+ var node = this.hints.childNodes[this.selectedHint];
407
+ if (node) {
408
+ node.className = node.className.replace(" " + ACTIVE_HINT_ELEMENT_CLASS, "");
409
+ node.removeAttribute("aria-selected")
410
+ }
411
+ node = this.hints.childNodes[this.selectedHint = i];
412
+ node.className += " " + ACTIVE_HINT_ELEMENT_CLASS;
413
+ node.setAttribute("aria-selected", "true")
414
+ this.completion.cm.getInputField().setAttribute("aria-activedescendant", node.id)
415
+ this.scrollToActive()
416
+ CodeMirror.signal(this.data, "select", this.data.list[this.selectedHint], node);
417
+ },
418
+
419
+ scrollToActive: function() {
420
+ var selectedHintRange = this.getSelectedHintRange();
421
+ var node1 = this.hints.childNodes[selectedHintRange.from];
422
+ var node2 = this.hints.childNodes[selectedHintRange.to];
423
+ var firstNode = this.hints.firstChild;
424
+ if (node1.offsetTop < this.hints.scrollTop)
425
+ this.hints.scrollTop = node1.offsetTop - firstNode.offsetTop;
426
+ else if (node2.offsetTop + node2.offsetHeight > this.hints.scrollTop + this.hints.clientHeight)
427
+ this.hints.scrollTop = node2.offsetTop + node2.offsetHeight - this.hints.clientHeight + firstNode.offsetTop;
428
+ },
429
+
430
+ screenAmount: function() {
431
+ return Math.floor(this.hints.clientHeight / this.hints.firstChild.offsetHeight) || 1;
432
+ },
433
+
434
+ getSelectedHintRange: function() {
435
+ var margin = this.completion.options.scrollMargin || 0;
436
+ return {
437
+ from: Math.max(0, this.selectedHint - margin),
438
+ to: Math.min(this.data.list.length - 1, this.selectedHint + margin),
439
+ };
440
+ }
441
+ };
442
+
443
+ function applicableHelpers(cm, helpers) {
444
+ if (!cm.somethingSelected()) return helpers
445
+ var result = []
446
+ for (var i = 0; i < helpers.length; i++)
447
+ if (helpers[i].supportsSelection) result.push(helpers[i])
448
+ return result
449
+ }
450
+
451
+ function fetchHints(hint, cm, options, callback) {
452
+ if (hint.async) {
453
+ hint(cm, callback, options)
454
+ } else {
455
+ var result = hint(cm, options)
456
+ if (result && result.then) result.then(callback)
457
+ else callback(result)
458
+ }
459
+ }
460
+
461
+ function resolveAutoHints(cm, pos) {
462
+ var helpers = cm.getHelpers(pos, "hint"), words
463
+ if (helpers.length) {
464
+ var resolved = function(cm, callback, options) {
465
+ var app = applicableHelpers(cm, helpers);
466
+ function run(i) {
467
+ if (i == app.length) return callback(null)
468
+ fetchHints(app[i], cm, options, function(result) {
469
+ if (result && result.list.length > 0) callback(result)
470
+ else run(i + 1)
471
+ })
472
+ }
473
+ run(0)
474
+ }
475
+ resolved.async = true
476
+ resolved.supportsSelection = true
477
+ return resolved
478
+ } else if (words = cm.getHelper(cm.getCursor(), "hintWords")) {
479
+ return function(cm) { return CodeMirror.hint.fromList(cm, {words: words}) }
480
+ } else if (CodeMirror.hint.anyword) {
481
+ return function(cm, options) { return CodeMirror.hint.anyword(cm, options) }
482
+ } else {
483
+ return function() {}
484
+ }
485
+ }
486
+
487
+ CodeMirror.registerHelper("hint", "auto", {
488
+ resolve: resolveAutoHints
489
+ });
490
+
491
+ CodeMirror.registerHelper("hint", "fromList", function(cm, options) {
492
+ var cur = cm.getCursor(), token = cm.getTokenAt(cur)
493
+ var term, from = CodeMirror.Pos(cur.line, token.start), to = cur
494
+ if (token.start < cur.ch && /\w/.test(token.string.charAt(cur.ch - token.start - 1))) {
495
+ term = token.string.substr(0, cur.ch - token.start)
496
+ } else {
497
+ term = ""
498
+ from = cur
499
+ }
500
+ var found = [];
501
+ for (var i = 0; i < options.words.length; i++) {
502
+ var word = options.words[i];
503
+ if (word.slice(0, term.length) == term)
504
+ found.push(word);
505
+ }
506
+
507
+ if (found.length) return {list: found, from: from, to: to};
508
+ });
509
+
510
+ CodeMirror.commands.autocomplete = CodeMirror.showHint;
511
+
512
+ var defaultOptions = {
513
+ hint: CodeMirror.hint.auto,
514
+ completeSingle: true,
515
+ alignWithWord: true,
516
+ closeCharacters: /[\s()\[\]{};:>,]/,
517
+ closeOnPick: true,
518
+ closeOnUnfocus: true,
519
+ updateOnCursorActivity: true,
520
+ completeOnSingleClick: true,
521
+ container: null,
522
+ customKeys: null,
523
+ extraKeys: null,
524
+ paddingForScrollbar: true,
525
+ moveOnOverlap: true,
526
+ };
527
+
528
+ CodeMirror.defineOption("hintOptions", null);
529
+ });
@@ -0,0 +1,87 @@
1
+ .CodeMirror-Tern-completion {
2
+ padding-left: 22px;
3
+ position: relative;
4
+ line-height: 1.5;
5
+ }
6
+ .CodeMirror-Tern-completion:before {
7
+ position: absolute;
8
+ left: 2px;
9
+ bottom: 2px;
10
+ border-radius: 50%;
11
+ font-size: 12px;
12
+ font-weight: bold;
13
+ height: 15px;
14
+ width: 15px;
15
+ line-height: 16px;
16
+ text-align: center;
17
+ color: white;
18
+ -moz-box-sizing: border-box;
19
+ box-sizing: border-box;
20
+ }
21
+ .CodeMirror-Tern-completion-unknown:before {
22
+ content: "?";
23
+ background: #4bb;
24
+ }
25
+ .CodeMirror-Tern-completion-object:before {
26
+ content: "O";
27
+ background: #77c;
28
+ }
29
+ .CodeMirror-Tern-completion-fn:before {
30
+ content: "F";
31
+ background: #7c7;
32
+ }
33
+ .CodeMirror-Tern-completion-array:before {
34
+ content: "A";
35
+ background: #c66;
36
+ }
37
+ .CodeMirror-Tern-completion-number:before {
38
+ content: "1";
39
+ background: #999;
40
+ }
41
+ .CodeMirror-Tern-completion-string:before {
42
+ content: "S";
43
+ background: #999;
44
+ }
45
+ .CodeMirror-Tern-completion-bool:before {
46
+ content: "B";
47
+ background: #999;
48
+ }
49
+
50
+ .CodeMirror-Tern-completion-guess {
51
+ color: #999;
52
+ }
53
+
54
+ .CodeMirror-Tern-tooltip {
55
+ border: 1px solid silver;
56
+ border-radius: 3px;
57
+ color: #444;
58
+ padding: 2px 5px;
59
+ font-size: 90%;
60
+ font-family: monospace;
61
+ background-color: white;
62
+ white-space: pre-wrap;
63
+
64
+ max-width: 40em;
65
+ position: absolute;
66
+ z-index: 10;
67
+ -webkit-box-shadow: 2px 3px 5px rgba(0,0,0,.2);
68
+ -moz-box-shadow: 2px 3px 5px rgba(0,0,0,.2);
69
+ box-shadow: 2px 3px 5px rgba(0,0,0,.2);
70
+
71
+ transition: opacity 1s;
72
+ -moz-transition: opacity 1s;
73
+ -webkit-transition: opacity 1s;
74
+ -o-transition: opacity 1s;
75
+ -ms-transition: opacity 1s;
76
+ }
77
+
78
+ .CodeMirror-Tern-hint-doc {
79
+ max-width: 25em;
80
+ margin-top: -3px;
81
+ }
82
+
83
+ .CodeMirror-Tern-fname { color: black; }
84
+ .CodeMirror-Tern-farg { color: #70a; }
85
+ .CodeMirror-Tern-farg-current { text-decoration: underline; }
86
+ .CodeMirror-Tern-type { color: #07c; }
87
+ .CodeMirror-Tern-fhint-guess { opacity: .7; }