@webqit/oohtml 2.1.81 → 3.0.0

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.
package/package.json CHANGED
@@ -14,7 +14,7 @@
14
14
  "wicg-proposal"
15
15
  ],
16
16
  "homepage": "https://webqit.io/tooling/oohtml",
17
- "version": "2.1.81",
17
+ "version": "3.0.0",
18
18
  "license": "MIT",
19
19
  "repository": {
20
20
  "type": "git",
@@ -36,12 +36,13 @@
36
36
  },
37
37
  "dependencies": {
38
38
  "@webqit/observer": "^2.2.9",
39
+ "@webqit/quantum-js": "^4.0.0",
39
40
  "@webqit/realdom": "^2.1.19",
40
41
  "@webqit/stateful-js": "^3.0.27",
41
42
  "@webqit/util": "^0.8.11"
42
43
  },
43
44
  "devDependencies": {
44
- "@webqit/oohtml-ssr": "^1.2.19",
45
+ "@webqit/oohtml-ssr": "^2.0.0",
45
46
  "chai": "^4.3.4",
46
47
  "coveralls": "^3.1.1",
47
48
  "esbuild": "^0.14.43",
@@ -4,7 +4,7 @@
4
4
  */
5
5
  import Observer from '@webqit/observer';
6
6
  import _HTMLBindingsProvider from '../bindings-api/_HTMLBindingsProvider.js';
7
- import { StatefulAsyncFunction } from '@webqit/stateful-js/async';
7
+ import { QuantumAsyncFunction } from '@webqit/quantum-js/async';
8
8
  import { _, _init } from '../util.js';
9
9
 
10
10
  /**
@@ -132,7 +132,7 @@ async function mountDiscreteBindings( config, ...entries ) {
132
132
  source += `let content = ((${ template.expr }) ?? '') + '';`;
133
133
  source += `$set__(this, 'nodeValue', content);`;
134
134
  if ( anchorNode ) { source += `$set__($anchorNode__, 'nodeValue', \`${ config.tokens.tagStart }${ template.expr }${ config.tokens.stateStart }\` + content.length + \`${ config.tokens.stateEnd } ${ config.tokens.tagEnd }\`);`; }
135
- const compiled = new StatefulAsyncFunction( '$signals__', `$anchorNode__`, source, { env } );
135
+ const compiled = new QuantumAsyncFunction( '$signals__', `$anchorNode__`, source, { env } );
136
136
  const signals = [];
137
137
  bindings.set( textNode, { compiled, signals, state: await compiled.call( textNode, signals, anchorNode ), } );
138
138
  }
@@ -142,7 +142,7 @@ async function mountInlineBindings( config, ...entries ) {
142
142
  for ( const node of entries ) {
143
143
  const source = parseInlineBindings( config, node.getAttribute( config.attr.binding ) );
144
144
  const { scope: env, bindings } = createDynamicScope( config, node );
145
- const compiled = new StatefulAsyncFunction( '$signals__', source, { env } );
145
+ const compiled = new QuantumAsyncFunction( '$signals__', source, { env } );
146
146
  const signals = [];
147
147
  bindings.set( node, { compiled, signals, state: await compiled.call( node, signals ), } );
148
148
  }
@@ -154,28 +154,28 @@ function parseInlineBindings( config, str ) {
154
154
  const validation = {};
155
155
  const source = splitOuter( str, ';' ).map( str => {
156
156
  const [ left, right ] = splitOuter( str, ':' ).map( x => x.trim() );
157
- const token = left[ 0 ], param = left.slice( 1 ).trim();
158
- const $expr = `(${ right })`, $$expr = `(${ $expr } ?? '')`;
159
- if ( token === '&' ) return `this.style[\`${ param }\`] = ${ $$expr };`;
160
- if ( token === '%' ) return `this.classList.toggle(\`${ param }\`, !!${ $expr });`;
161
- if ( token === '~' ) {
162
- if ( param.endsWith( '?' ) ) return `this.toggleAttribute(\`${ param.substring( 0, -1 ).trim() }\`, !!${ $expr });`;
163
- return `this.setAttribute(\`${ param }\`, ${ $$expr });`;
157
+ const directive = left[ 0 ], param = left.slice( 1 ).trim();
158
+ const arg = `(${ right })`, $arg = `(${ arg } ?? '')`;
159
+ if ( directive === '&' ) return `this.style[\`${ param }\`] = ${ $arg };`;
160
+ if ( directive === '%' ) return `this.classList.toggle(\`${ param }\`, !!${ arg });`;
161
+ if ( directive === '~' ) {
162
+ if ( param.startsWith( '?' ) ) return `this.toggleAttribute(\`${ param.substring( 1 ).trim() }\`, !!${ arg });`;
163
+ return `this.setAttribute(\`${ param }\`, ${ $arg });`;
164
164
  }
165
- if ( token === '@' ) {
165
+ if ( directive === '@' ) {
166
166
  if ( validation[ param ] ) throw new Error( `Duplicate binding: ${ left }.` );
167
167
  validation[ param ] = true;
168
- if ( param === 'text' ) return `$set__(this, 'textContent', ${ $$expr });`;
169
- if ( param === 'html' ) return `this.setHTML(${ $$expr });`;
168
+ if ( param === 'text' ) return `$set__(this, 'textContent', ${ $arg });`;
169
+ if ( param === 'html' ) return `this.setHTML(${ $arg });`;
170
170
  if ( param === 'items' ) {
171
171
  const [ iterationSpec, importSpec ] = splitOuter( right, '/' );
172
- if ( !importSpec ) throw new Error( `Invalid ${ token }items spec: ${ str }; no import specifier.` );
172
+ if ( !importSpec ) throw new Error( `Invalid ${ directive }items spec: ${ str }; no import specifier.` );
173
173
  let [ raw, production, kind, iteratee ] = iterationSpec.trim().match( /(.*?[\)\s+])(of|in)([\(\{\[\s+].*)/i ) || [];
174
- if ( !raw ) throw new Error( `Invalid ${ token }items spec: ${ str }.` );
174
+ if ( !raw ) throw new Error( `Invalid ${ directive }items spec: ${ str }.` );
175
175
  if ( production.startsWith( '(' ) ) {
176
176
  production = production.trim().slice( 1, -1 ).split( ',' ).map( x => x.trim() );
177
177
  } else { production = [ production ]; }
178
- if ( production.length > ( kind === 'in' ? 3 : 2 ) ) throw new Error( `Invalid ${ token }items spec: ${ str }.` );
178
+ if ( production.length > ( kind === 'in' ? 3 : 2 ) ) throw new Error( `Invalid ${ directive }items spec: ${ str }.` );
179
179
  const indices = kind === 'in' ? production[ 2 ] : ( production[ 1 ] || '$index__' );
180
180
  return `
181
181
  let $iteratee__ = ${ iteratee };
@@ -3,15 +3,15 @@
3
3
  * @imports
4
4
  */
5
5
  import Observer from '@webqit/observer';
6
- import { resolveParams } from '@webqit/stateful-js/params';
7
- import { StatefulAsyncFunction, StatefulAsyncScript, StatefulModule, State } from '@webqit/stateful-js/async';
6
+ import { resolveParams } from '@webqit/quantum-js/params';
7
+ import { QuantumAsyncFunction, QuantumAsyncScript, QuantumModule, State } from '@webqit/quantum-js/async';
8
8
  import { _init } from '../util.js';
9
9
  import Hash from './Hash.js';
10
10
 
11
11
  export {
12
- StatefulAsyncFunction,
13
- StatefulAsyncScript,
14
- StatefulModule,
12
+ QuantumAsyncFunction,
13
+ QuantumAsyncScript,
14
+ QuantumModule,
15
15
  State,
16
16
  Observer,
17
17
  }
@@ -28,9 +28,9 @@ export default function init( { advanced = {}, ...$config } ) {
28
28
  } );
29
29
  config.scriptSelector = ( Array.isArray( config.script.mimeType ) ? config.script.mimeType : [ config.script.mimeType ] ).reduce( ( selector, mm ) => {
30
30
  const qualifier = mm ? `[type=${ window.CSS.escape( mm ) }]` : '';
31
- return selector.concat( `script${ qualifier }[scoped],script${ qualifier }[stateful]` );
31
+ return selector.concat( `script${ qualifier }[scoped],script${ qualifier }[quantum]` );
32
32
  }, [] ).join( ',' );
33
- Object.assign( window.webqit, { StatefulAsyncFunction, StatefulAsyncScript, StatefulModule, State, Observer } );
33
+ Object.assign( window.webqit, { QuantumAsyncFunction, QuantumAsyncScript, QuantumModule, State, Observer } );
34
34
  window.webqit.oohtml.Script = {
35
35
  compileCache: [ new Map, new Map, ],
36
36
  execute: execute.bind( window, config ),
@@ -54,9 +54,9 @@ async function execute( config, execHash ) {
54
54
  }
55
55
  // Execute and save state
56
56
  const state = ( await compiledScript.bind( thisContext ) ).execute();
57
- if ( script.stateful ) { Object.defineProperty( script, 'state', { value: state } ); }
57
+ if ( script.quantum ) { Object.defineProperty( script, 'state', { value: state } ); }
58
58
  realdom.realtime( window.document ).observe( script, () => {
59
- if ( script.stateful ) { state.dispose(); }
59
+ if ( script.quantum ) { state.dispose(); }
60
60
  if ( script.scoped ) { thisContext.scripts.splice( thisContext.scripts.indexOf( script, 1 ) ); }
61
61
  }, { subtree: true, timing: 'sync', generation: 'exits' } );
62
62
  }
@@ -75,22 +75,22 @@ function realtime( config ) {
75
75
  realdom.realtime( window.document ).subtree/*instead of observe(); reason: jsdom timing*/( config.scriptSelector, record => {
76
76
  record.entrants.forEach( script => {
77
77
  if ( script.cloned ) return;
78
- if ( 'stateful' in script ) return handled( script );
79
- Object.defineProperty( script, 'stateful', { value: script.hasAttribute( 'stateful' ) } );
78
+ if ( 'quantum' in script ) return handled( script );
79
+ Object.defineProperty( script, 'quantum', { value: script.hasAttribute( 'quantum' ) } );
80
80
  if ( 'scoped' in script ) return handled( script );
81
81
  Object.defineProperty( script, 'scoped', { value: script.hasAttribute( 'scoped' ) } );
82
82
  // Do compilation
83
83
  const textContent = ( script._ = script.textContent.trim() ) && script._.startsWith( '/*@oohtml*/if(false){' ) && script._.endsWith( '}/*@oohtml*/' ) ? script._.slice( 21, -12 ) : script.textContent;
84
84
  const sourceHash = Hash.toHash( textContent );
85
- const compileCache = oohtml.Script.compileCache[ script.stateful ? 0 : 1 ];
85
+ const compileCache = oohtml.Script.compileCache[ script.quantum ? 0 : 1 ];
86
86
  let compiledScript;
87
87
  if ( !( compiledScript = compileCache.get( sourceHash ) ) ) {
88
88
  const { parserParams, compilerParams, runtimeParams } = config.advanced;
89
- compiledScript = new ( script.type === 'module' ? StatefulModule : StatefulAsyncScript )( textContent, {
89
+ compiledScript = new ( script.type === 'module' ? QuantumModule : QuantumAsyncScript )( textContent, {
90
90
  exportNamespace: `#${ script.id }`,
91
91
  fileName: window.document.url,
92
92
  parserParams,
93
- compilerParams: { ...compilerParams, startStatic: !script.stateful },
93
+ compilerParams: { ...compilerParams, startStatic: !script.quantum },
94
94
  runtimeParams,
95
95
  } );
96
96
  compileCache.set( sourceHash, compiledScript );
package/test/index.js CHANGED
@@ -21,7 +21,7 @@ export function createDocument( head = '', body = '', callback = null, ) {
21
21
  <!DOCTYPE html>
22
22
  <html>
23
23
  <head>
24
- <meta name="$f-compiler-url" content="../stateful-js/dist/compiler.js">
24
+ <meta name="$q-compiler-url" content="../quantum-js/dist/compiler.js">
25
25
  <script ssr src="/dist/main.js"></script>
26
26
  ${ head }
27
27
  </head>
@@ -12,7 +12,7 @@ describe(`Test: Scoped JS`, function() {
12
12
  it(`Should do basic observe`, async function() {
13
13
  const head = '', body = `
14
14
  <h1>Hello World!</h1>
15
- <script scoped stateful>
15
+ <script scoped quantum>
16
16
  testRecords.push( this );
17
17
  console.log('-------scoped JS here.', this);
18
18
  </script>`;