@webqit/oohtml 2.1.29 → 2.1.31

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.29",
17
+ "version": "2.1.31",
18
18
  "license": "MIT",
19
19
  "repository": {
20
20
  "type": "git",
@@ -32,7 +32,7 @@
32
32
  "scripts": {
33
33
  "test": "mocha --extension .test.js --exit",
34
34
  "test:coverage": "c8 --reporter=text-lcov npm run test | coveralls",
35
- "build": "esbuild main=src/targets.browser.js bindings-api=src/bindings-api/targets.browser.js context-api=src/context-api/targets.browser.js namespace-api=src/namespace-api/targets.browser.js html-modules=src/html-modules/targets.browser.js html-imports=src/html-imports/targets.browser.js scoped-js=src/scoped-js/targets.browser.js --bundle --minify --sourcemap --outdir=dist",
35
+ "build": "esbuild main=src/targets.browser.js bindings-api=src/bindings-api/targets.browser.js context-api=src/context-api/targets.browser.js namespace-api=src/namespace-api/targets.browser.js html-modules=src/html-modules/targets.browser.js html-imports=src/html-imports/targets.browser.js scoped-js=src/scoped-js/targets.browser.js scoped-css=src/scoped-css/targets.browser.js --bundle --minify --sourcemap --outdir=dist",
36
36
  "preversion": "npm run test && npm run build && git add -A dist",
37
37
  "postversion": "npm publish --tag next",
38
38
  "postpublish": "git push && git push --tags"
package/src/index.js CHANGED
@@ -8,6 +8,7 @@ import ContextAPI from './context-api/index.js';
8
8
  import NamespaceAPI from './namespace-api/index.js';
9
9
  import HTMLModules from './html-modules/index.js';
10
10
  import HTMLImports from './html-imports/index.js';
11
+ import ScopedCSS from './scoped-css/index.js';
11
12
  import ScopedJS from './scoped-js/index.js';
12
13
 
13
14
  /**
@@ -21,6 +22,7 @@ export default function init( configs = {} ) {
21
22
  NamespaceAPI.call( this, ( configs.NAMESPACE_API || {} ) );
22
23
  HTMLModules.call( this, ( configs.HTML_MODULES || {} ) );
23
24
  HTMLImports.call( this, ( configs.HTML_IMPORTS || {} ) );
25
+ ScopedCSS.call( this, ( configs.SCOPED_CSS || {} ) );
24
26
  ScopedJS.call( this, ( configs.SCOPED_JS || {} ) );
25
27
  // --------------
26
28
  }
@@ -12,7 +12,7 @@ import { _, _init } from '../util.js';
12
12
  */
13
13
  export default function init( $config = {} ) {
14
14
  const { config, window } = _init.call( this, 'namespace-api', $config, {
15
- attr: { namespace: 'namespace', id: ':id', },
15
+ attr: { namespace: 'namespace', id: 'id', },
16
16
  api: { namespace: 'namespace', },
17
17
  staticsensitivity: true,
18
18
  eagermode: true,
@@ -0,0 +1,45 @@
1
+
2
+ /**
3
+ * @imports
4
+ */
5
+ import { _init } from '../util.js';
6
+
7
+ /**
8
+ * @init
9
+ *
10
+ * @param Object $config
11
+ */
12
+ export default function init( { advanced = {}, ...$config } ) {
13
+ const { config, window } = _init.call( this, 'scoped-css', $config, {
14
+ style: { retention: 'retain', mimeType: '' },
15
+ } );
16
+ config.styleSelector = ( Array.isArray( config.style.mimeType ) ? config.style.mimeType : [ config.style.mimeType ] ).reduce( ( selector, mm ) => {
17
+ const qualifier = mm ? `[type=${ window.CSS.escape( mm ) }]` : '';
18
+ return selector.concat( `style${ qualifier }[scoped]` );
19
+ }, [] ).join( ',' );
20
+ realtime.call( window, config );
21
+ }
22
+
23
+ /**
24
+ * Performs realtime capture of elements and builds their relationships.
25
+ *
26
+ * @param Object config
27
+ *
28
+ * @return Void
29
+ */
30
+ function realtime( config ) {
31
+ const window = this, { realdom } = window.webqit;
32
+ if ( !window.HTMLScriptElement.supports ) { window.HTMLScriptElement.supports = () => false; }
33
+ realdom.realtime( window.document ).subtree/*instead of observe(); reason: jsdom timing*/( config.styleSelector, record => {
34
+ record.entrants.forEach( style => {
35
+ if ( 'scoped' in style ) return handled( style );
36
+ Object.defineProperty( style, 'scoped', { value: style.hasAttribute( 'scoped' ) } );
37
+ const uuid = `scoped${ uniqId() }`;
38
+ style.setAttribute( 'ref', uuid );
39
+ style.textContent = `@scope from (:has(> style[ref="${ uuid }"])) {\n${ style.textContent }\n}`;
40
+ } );
41
+ }, { live: true, timing: 'intercept', generation: 'entrants' } );
42
+ // ---
43
+ }
44
+
45
+ const uniqId = () => (0|Math.random()*9e6).toString(36);
@@ -0,0 +1,10 @@
1
+
2
+ /**
3
+ * @imports
4
+ */
5
+ import init from './index.js';
6
+
7
+ /**
8
+ * @init
9
+ */
10
+ init.call( window );
@@ -52,7 +52,7 @@ export function execute( compiledScript, thisContext, script ) {
52
52
  Object.defineProperty( script, 'rerender', { value: ( ...args ) => _await( returnValue, ( [ , rerender ] ) => rerender( ...args ) ) } );
53
53
  _await( script.properties, properties => {
54
54
  properties.processes = properties.dependencies.map( path => {
55
- const _env = { 'this': thisContext, 'globalThis': globalThis };
55
+ const _env = { 'this': thisContext, 'globalThis': globalThis, 'window': globalThis.window, 'self': globalThis.self };
56
56
  const getPaths = ( base, record_s ) => ( Array.isArray( record_s ) ? record_s : [ record_s ] ).map( record => [ ...base, ...( record.path || [ record.key ] ) ] );
57
57
  properties.processes = properties.dependencies.map( path => {
58
58
  if ( _isTypeObject( _env[ path[ 0 ] ] ) ) {
@@ -10,10 +10,10 @@ describe(`Namespaced HTML`, function() {
10
10
  describe( `Basic...`, async function() {
11
11
 
12
12
  const head = `
13
- <meta name="oohtml" content="attr.id=:id" />`;
13
+ <meta name="oohtml" content="attr.id=id" />`;
14
14
  const body = `
15
- <div :id="main" namespace>
16
- <div :id="child"></div>
15
+ <div id="main" namespace>
16
+ <div id="child"></div>
17
17
  </div>`;
18
18
  const { document, window } = createDocument( head, body );
19
19
  await delay( 60 );
@@ -30,7 +30,7 @@ describe(`Namespaced HTML`, function() {
30
30
  idReceived = records[ 0 ].key;
31
31
  } );
32
32
  const item = document.createElement( 'div' );
33
- item.setAttribute( ':id', 'some-id' );
33
+ item.setAttribute( 'id', 'some-id' );
34
34
  document.body.appendChild( item );
35
35
  expect( idReceived ).to.eq( 'some-id' );
36
36
  } );
@@ -0,0 +1,32 @@
1
+
2
+ /**
3
+ * @imports
4
+ */
5
+ import { expect } from 'chai';
6
+ import { createDocument, delay } from './index.js';
7
+
8
+ describe(`Test: Scoped CSS`, function() {
9
+
10
+ describe(`Styles`, function() {
11
+
12
+ it(`Should do basic rewrite`, async function() {
13
+ const head = '', body = `
14
+ <div>
15
+ <h1>Hello World!</h1>
16
+ <style scoped>
17
+ h1 {
18
+ color: red;
19
+ }
20
+ </style>
21
+ </div>`;
22
+
23
+ const window = createDocument( head, body );
24
+ await delay( 160 ); // Takes time to dynamically load Subscript compiler
25
+ const styleElement = window.document.querySelector( 'style' );
26
+
27
+ expect( styleElement.textContent.substring( 0, 13 ) ).to.eq( '@scope from (' );
28
+ });
29
+
30
+ });
31
+
32
+ });