@webqit/oohtml 2.1.34 → 2.1.35

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 (52) hide show
  1. package/.gitignore +3 -3
  2. package/LICENSE +20 -20
  3. package/README.md +733 -67
  4. package/dist/bindings-api.js +1 -1
  5. package/dist/bindings-api.js.map +3 -3
  6. package/dist/context-api.js +1 -1
  7. package/dist/context-api.js.map +3 -3
  8. package/dist/html-imports.js +1 -1
  9. package/dist/html-imports.js.map +3 -3
  10. package/dist/main.js +12 -12
  11. package/dist/main.js.map +3 -3
  12. package/dist/namespace-api.js +1 -1
  13. package/dist/namespace-api.js.map +3 -3
  14. package/dist/scoped-css.js +2 -2
  15. package/dist/scoped-css.js.map +3 -3
  16. package/dist/scoped-js.js +7 -7
  17. package/dist/scoped-js.js.map +3 -3
  18. package/package.json +76 -76
  19. package/src/bindings-api/index.js +83 -83
  20. package/src/bindings-api/targets.browser.js +10 -10
  21. package/src/context-api/HTMLContext.js +76 -157
  22. package/src/context-api/HTMLContextProvider.js +158 -0
  23. package/src/context-api/_ContextRequestEvent.js +25 -25
  24. package/src/context-api/index.js +51 -51
  25. package/src/context-api/targets.browser.js +9 -9
  26. package/src/{html-modules/HTMLExportsManager.js → html-imports/_HTMLExportsManager.js} +185 -199
  27. package/src/html-imports/_HTMLImportElement.js +211 -213
  28. package/src/{html-modules/_HTMLImportsContext.js → html-imports/_HTMLImportsProvider.js} +122 -114
  29. package/src/html-imports/index.js +197 -88
  30. package/src/html-imports/targets.browser.js +9 -9
  31. package/src/index.js +30 -32
  32. package/src/namespace-api/index.js +144 -144
  33. package/src/namespace-api/targets.browser.js +10 -10
  34. package/src/scoped-css/index.js +45 -45
  35. package/src/scoped-css/targets.browser.js +10 -10
  36. package/src/scoped-js/Compiler.js +297 -297
  37. package/src/scoped-js/index.js +112 -112
  38. package/src/scoped-js/targets.browser.js +10 -10
  39. package/src/targets.browser.js +9 -9
  40. package/src/util.js +34 -34
  41. package/test/bindings-api.test.js +42 -42
  42. package/test/imports.test.js +221 -221
  43. package/test/index.js +50 -50
  44. package/test/modules.test.js +200 -200
  45. package/test/namespace-api.test.js +51 -51
  46. package/test/scoped-css.test.js +31 -31
  47. package/test/scoped-js.test.js +29 -29
  48. package/dist/html-modules.js +0 -2
  49. package/dist/html-modules.js.map +0 -7
  50. package/src/context-api/HTMLContextManager.js +0 -77
  51. package/src/html-modules/index.js +0 -131
  52. package/src/html-modules/targets.browser.js +0 -10
@@ -1,131 +0,0 @@
1
-
2
- /**
3
- * @imports
4
- */
5
- import Observer from '@webqit/observer';
6
- import _HTMLImportsContext from './_HTMLImportsContext.js';
7
- import HTMLExportsManager from './HTMLExportsManager.js';
8
- import { _, _init } from '../util.js';
9
-
10
- /**
11
- * Initializes HTML Modules.
12
- *
13
- * @param Object $config
14
- *
15
- * @return Void
16
- */
17
- export default function init( $config = {} ) {
18
- const { config, window } = _init.call( this, 'html-modules', $config, {
19
- template: { attr: { exportid: 'exportid', extends: 'extends', inherits: 'inherits' }, api: { modules: 'modules', exportid: 'exportid' }, },
20
- context: { attr: { importscontext: 'importscontext', contextname: 'contextname' }, api: { modules: 'modules' }, },
21
- export: { attr: { exportid: 'exportid' }, },
22
- staticsensitivity: true,
23
- } );
24
- config.templateSelector = `template[${ window.CSS.escape( config.template.attr.exportid ) }]`;
25
- config.ownerContextSelector = [ config.context.attr.contextname, config.context.attr.importscontext ].map( a => `[${ window.CSS.escape( a ) }]` ).join( ',' );
26
- window.webqit.HTMLImportsContext = class extends _HTMLImportsContext {
27
- static get config() { return config; }
28
- };
29
- window.webqit.Observer = Observer;
30
- exposeModulesObjects.call( window, config );
31
- realtime.call( window, config );
32
- }
33
-
34
- export { Observer }
35
-
36
- /**
37
- * Returns the "exports" object associated with the given node.
38
- *
39
- * @param Element node
40
- * @param Bool autoCreate
41
- *
42
- * @return Object
43
- */
44
- export function getModulesObject( node, autoCreate = true ) {
45
- if ( !_( node ).has( 'modules' ) && autoCreate ) {
46
- const modulesObj = Object.create( null );
47
- Observer.intercept( modulesObj, 'set', ( event, receiver, next ) => {
48
- if ( !event.value || !event.key.startsWith( '#' ) || event.value instanceof Set ) return next();
49
- if ( !Array.isArray( event.value ) ) { event.value = [ event.value ]; }
50
- event.value = new Set( event.value );
51
- return next();
52
- } );
53
- _( node ).set( 'modules', modulesObj );
54
- }
55
- return _( node ).get( 'modules' );
56
- }
57
-
58
- /**
59
- * Exposes HTML Modules with native APIs.
60
- *
61
- * @param Object config
62
- *
63
- * @return Void
64
- */
65
- function exposeModulesObjects( config ) {
66
- const window = this;
67
- // Assertions
68
- if ( config.context.api.modules in window.document ) { throw new Error( `document already has a "${ config.context.api.modules }" property!` ); }
69
- if ( config.template.api.modules in window.HTMLElement.prototype ) { throw new Error( `The "HTMLElement" class already has a "${ config.template.api.modules }" property!` ); }
70
- if ( config.template.api.exportid in window.HTMLTemplateElement.prototype ) { throw new Error( `The "HTMLTemplateElement" class already has a "${ config.template.api.exportid }" property!` ); }
71
- // Definitions
72
- Object.defineProperty( window.document, config.context.api.modules, { get: function() {
73
- return getModulesObject( window.document );
74
- } } );
75
- Object.defineProperty( window.HTMLElement.prototype, config.template.api.modules, { get: function() {
76
- return getModulesObject( this );
77
- } } );
78
- Object.defineProperty( window.HTMLTemplateElement.prototype, config.template.api.exportid, { get: function() {
79
- return this.getAttribute( config.template.attr.exportid );
80
- } } );
81
- }
82
-
83
- /**
84
- * Performs realtime capture of elements and builds their contents graph.
85
- *
86
- * @param Object config
87
- *
88
- * @return Void
89
- */
90
- function realtime( config ) {
91
- const window = this, { realdom, HTMLImportsContext } = window.webqit;
92
- // ------------
93
- const attachImportsContext = host => {
94
- const contextId = HTMLImportsContext.createId( host );
95
- HTMLImportsContext.attachTo( host, contextId );
96
- };
97
- const detachImportsContext = ( host, force ) => {
98
- const contextId = HTMLImportsContext.createId( host );
99
- HTMLImportsContext.detachFrom( host, contextId, cx => {
100
- return force || host.matches && !host.matches( config.ownerContextSelector ) && !Object.keys( cx.modules ).length;
101
- } );
102
- };
103
- // ------------
104
- realdom.realtime( window.document ).subtree/*instead of observe(); reason: jsdom timing*/( [ config.templateSelector, config.ownerContextSelector ], record => {
105
- record.entrants.forEach( entry => {
106
- if ( entry.matches( config.templateSelector ) ) {
107
- Object.defineProperty( entry, 'scoped', { value: entry.hasAttribute( 'scoped' ) } );
108
- const moduleExport = new HTMLExportsManager( window, entry, config );
109
- moduleExport.ownerContext = entry.scoped ? record.target : window.document;
110
- const ownerContextModulesObj = getModulesObject( moduleExport.ownerContext );
111
- if ( moduleExport.exportId ) { Observer.set( ownerContextModulesObj, moduleExport.exportId, entry ); }
112
- // The ownerContext's modulesObj - ownerContextModulesObj - has to be populated
113
- // Before attaching a context instance to it, to give the just created context something to use for
114
- // fullfiling reclaimed requests.
115
- attachImportsContext( moduleExport.ownerContext );
116
- } else {
117
- attachImportsContext( entry );
118
- }
119
- } );
120
- record.exits.forEach( entry => {
121
- if ( entry.matches( config.templateSelector ) ) {
122
- const moduleExport = HTMLExportsManager.instance( window, entry, config );
123
- const ownerContextModulesObj = getModulesObject( moduleExport.ownerContext );
124
- if ( moduleExport.exportId ) { Observer.deleteProperty( ownerContextModulesObj, moduleExport.exportId ); }
125
- detachImportsContext( moduleExport.ownerContext );
126
- } else {
127
- detachImportsContext( entry, true );
128
- }
129
- } );
130
- }, { live: true, timing: 'sync', staticSensitivity: config.staticsensitivity } );
131
- }
@@ -1,10 +0,0 @@
1
-
2
- /**
3
- * @imports
4
- */
5
- import init from './index.js';
6
-
7
- /**
8
- * @init
9
- */
10
- init.call( window );