sw.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. // r113
  2. const assets = [
  3. './',
  4. '../files/favicon.ico',
  5. '../build/three.module.js',
  6. '../examples/jsm/controls/TransformControls.js',
  7. '../examples/jsm/libs/chevrotain.module.min.js',
  8. '../examples/jsm/libs/inflate.module.min.js',
  9. '../examples/js/libs/jszip.min.js',
  10. '../examples/js/libs/draco/draco_decoder.js',
  11. '../examples/js/libs/draco/draco_decoder.wasm',
  12. '../examples/js/libs/draco/draco_wasm_wrapper.js',
  13. '../examples/jsm/loaders/AMFLoader.js',
  14. '../examples/jsm/loaders/ColladaLoader.js',
  15. '../examples/jsm/loaders/DRACOLoader.js',
  16. '../examples/jsm/loaders/FBXLoader.js',
  17. '../examples/jsm/loaders/GLTFLoader.js',
  18. '../examples/jsm/loaders/KMZLoader.js',
  19. '../examples/jsm/loaders/MD2Loader.js',
  20. '../examples/jsm/loaders/OBJLoader.js',
  21. '../examples/jsm/loaders/MTLLoader.js',
  22. '../examples/jsm/loaders/PLYLoader.js',
  23. '../examples/jsm/loaders/RGBELoader.js',
  24. '../examples/jsm/loaders/STLLoader.js',
  25. '../examples/jsm/loaders/SVGLoader.js',
  26. '../examples/jsm/loaders/TGALoader.js',
  27. '../examples/jsm/loaders/TDSLoader.js',
  28. '../examples/jsm/loaders/VRMLLoader.js',
  29. '../examples/jsm/loaders/VTKLoader.js',
  30. '../examples/jsm/curves/NURBSCurve.js',
  31. '../examples/jsm/curves/NURBSUtils.js',
  32. '../examples/jsm/exporters/ColladaExporter.js',
  33. '../examples/jsm/exporters/GLTFExporter.js',
  34. '../examples/jsm/exporters/OBJExporter.js',
  35. '../examples/jsm/exporters/PLYExporter.js',
  36. '../examples/jsm/exporters/STLExporter.js',
  37. '../examples/jsm/geometries/TeapotBufferGeometry.js',
  38. './manifest.json',
  39. './images/icon.png',
  40. './js/libs/codemirror/codemirror.css',
  41. './js/libs/codemirror/theme/monokai.css',
  42. './js/libs/codemirror/codemirror.js',
  43. './js/libs/codemirror/mode/javascript.js',
  44. './js/libs/codemirror/mode/glsl.js',
  45. './js/libs/esprima.js',
  46. './js/libs/jsonlint.js',
  47. './js/libs/glslprep.min.js',
  48. './js/libs/codemirror/addon/dialog.css',
  49. './js/libs/codemirror/addon/show-hint.css',
  50. './js/libs/codemirror/addon/tern.css',
  51. './js/libs/codemirror/addon/dialog.js',
  52. './js/libs/codemirror/addon/show-hint.js',
  53. './js/libs/codemirror/addon/tern.js',
  54. './js/libs/acorn/acorn.js',
  55. './js/libs/acorn/acorn_loose.js',
  56. './js/libs/acorn/walk.js',
  57. './js/libs/ternjs/polyfill.js',
  58. './js/libs/ternjs/signal.js',
  59. './js/libs/ternjs/tern.js',
  60. './js/libs/ternjs/def.js',
  61. './js/libs/ternjs/comment.js',
  62. './js/libs/ternjs/infer.js',
  63. './js/libs/ternjs/doc_comment.js',
  64. './js/libs/tern-threejs/threejs.js',
  65. './js/libs/signals.min.js',
  66. './js/libs/ui.js',
  67. './js/libs/ui.three.js',
  68. './js/libs/app.js',
  69. './js/Player.js',
  70. './js/Script.js',
  71. //
  72. './css/main.css',
  73. './js/EditorControls.js',
  74. './js/Storage.js',
  75. './js/Editor.js',
  76. './js/Config.js',
  77. './js/History.js',
  78. './js/Loader.js',
  79. './js/Menubar.js',
  80. './js/Menubar.File.js',
  81. './js/Menubar.Edit.js',
  82. './js/Menubar.Add.js',
  83. './js/Menubar.Play.js',
  84. './js/Menubar.Examples.js',
  85. './js/Menubar.Help.js',
  86. './js/Menubar.Status.js',
  87. './js/Sidebar.js',
  88. './js/Sidebar.Scene.js',
  89. './js/Sidebar.Project.js',
  90. './js/Sidebar.Settings.js',
  91. './js/Sidebar.Settings.Shortcuts.js',
  92. './js/Sidebar.Settings.Viewport.js',
  93. './js/Sidebar.Properties.js',
  94. './js/Sidebar.Object.js',
  95. './js/Sidebar.Geometry.js',
  96. './js/Sidebar.Geometry.Geometry.js',
  97. './js/Sidebar.Geometry.BufferGeometry.js',
  98. './js/Sidebar.Geometry.Modifiers.js',
  99. './js/Sidebar.Geometry.BoxGeometry.js',
  100. './js/Sidebar.Geometry.CircleGeometry.js',
  101. './js/Sidebar.Geometry.CylinderGeometry.js',
  102. './js/Sidebar.Geometry.DodecahedronGeometry.js',
  103. './js/Sidebar.Geometry.ExtrudeGeometry.js',
  104. './js/Sidebar.Geometry.IcosahedronGeometry.js',
  105. './js/Sidebar.Geometry.OctahedronGeometry.js',
  106. './js/Sidebar.Geometry.PlaneGeometry.js',
  107. './js/Sidebar.Geometry.RingGeometry.js',
  108. './js/Sidebar.Geometry.SphereGeometry.js',
  109. './js/Sidebar.Geometry.ShapeGeometry.js',
  110. './js/Sidebar.Geometry.TetrahedronGeometry.js',
  111. './js/Sidebar.Geometry.TorusGeometry.js',
  112. './js/Sidebar.Geometry.TorusKnotGeometry.js',
  113. './js/Sidebar.Geometry.TubeGeometry.js',
  114. './js/Sidebar.Geometry.TeapotBufferGeometry.js',
  115. './js/Sidebar.Geometry.LatheGeometry.js',
  116. './js/Sidebar.Material.js',
  117. './js/Sidebar.Animation.js',
  118. './js/Sidebar.Script.js',
  119. './js/Sidebar.History.js',
  120. './js/Strings.js',
  121. './js/Toolbar.js',
  122. './js/Viewport.js',
  123. './js/Viewport.Camera.js',
  124. './js/Viewport.Info.js',
  125. './js/Command.js',
  126. './js/commands/AddObjectCommand.js',
  127. './js/commands/RemoveObjectCommand.js',
  128. './js/commands/MoveObjectCommand.js',
  129. './js/commands/SetPositionCommand.js',
  130. './js/commands/SetRotationCommand.js',
  131. './js/commands/SetScaleCommand.js',
  132. './js/commands/SetValueCommand.js',
  133. './js/commands/SetUuidCommand.js',
  134. './js/commands/SetColorCommand.js',
  135. './js/commands/SetGeometryCommand.js',
  136. './js/commands/SetGeometryValueCommand.js',
  137. './js/commands/MultiCmdsCommand.js',
  138. './js/commands/AddScriptCommand.js',
  139. './js/commands/RemoveScriptCommand.js',
  140. './js/commands/SetScriptValueCommand.js',
  141. './js/commands/SetMaterialCommand.js',
  142. './js/commands/SetMaterialColorCommand.js',
  143. './js/commands/SetMaterialMapCommand.js',
  144. './js/commands/SetMaterialValueCommand.js',
  145. './js/commands/SetMaterialVectorCommand.js',
  146. './js/commands/SetSceneCommand.js',
  147. //
  148. './examples/arkanoid.app.json',
  149. './examples/camera.app.json',
  150. './examples/particles.app.json',
  151. './examples/pong.app.json',
  152. './examples/shaders.app.json'
  153. ];
  154. self.addEventListener( 'install', async function () {
  155. const cache = await caches.open( 'threejs-editor' );
  156. assets.forEach( function ( asset ) {
  157. cache.add( asset ).catch( function () {
  158. console.error( '[SW] Cound\'t cache:', asset );
  159. } );
  160. } );
  161. } );
  162. self.addEventListener( 'fetch', async function ( event ) {
  163. const request = event.request;
  164. event.respondWith( cacheFirst( request ) );
  165. } );
  166. async function cacheFirst( request ) {
  167. const cachedResponse = await caches.match( request );
  168. if ( cachedResponse === undefined ) {
  169. console.error( '[SW] Not cached:', request.url );
  170. return fetch( request );
  171. }
  172. return cachedResponse;
  173. }