diff --git a/dist/amd/src/clause.js b/dist/amd/src/clause.js new file mode 100644 index 0000000..1747a7d --- /dev/null +++ b/dist/amd/src/clause.js @@ -0,0 +1,20 @@ +/*can-set@1.3.0-pre.0#src/clause*/ +define(function (require, exports, module) { + var assign = require('can-util/js/assign'); + var each = require('can-util/js/each'); + var clause = {}; + module.exports = clause; + clause.TYPES = [ + 'where', + 'order', + 'paginate', + 'id' + ]; + each(clause.TYPES, function (type) { + var className = type.charAt(0).toUpperCase() + type.substr(1); + clause[className] = function (compare) { + assign(this, compare); + }; + clause[className].type = type; + }); +}); \ No newline at end of file diff --git a/dist/amd/src/compare.js b/dist/amd/src/compare.js new file mode 100644 index 0000000..09c2adf --- /dev/null +++ b/dist/amd/src/compare.js @@ -0,0 +1,455 @@ +/*can-set@1.3.0-pre.0#src/compare*/ +define(function (require, exports, module) { + var h = require('./helpers'); + var assign = require('can-util/js/assign'); + var each = require('can-util/js/each'); + var makeArray = require('can-util/js/make-array'); + var compareHelpers; + var loop = function (a, b, aParent, bParent, prop, compares, options) { + var checks = options.checks; + for (var i = 0; i < checks.length; i++) { + var res = checks[i](a, b, aParent, bParent, prop, compares || {}, options); + if (res !== undefined) { + return res; + } + } + return options['default']; + }; + var addIntersectedPropertyToResult = function (a, b, aParent, bParent, prop, compares, options) { + var subsetCheck; + if (!(prop in aParent)) { + subsetCheck = 'subsetB'; + } else if (prop in bParent) { + return false; + } + if (!(prop in bParent)) { + subsetCheck = 'subsetA'; + } + if (subsetCheck === 'subsetB') { + options.result[prop] = b; + } else { + options.result[prop] = a; + } + return undefined; + }; + var addToResult = function (fn, name) { + return function (a, b, aParent, bParent, prop, compares, options) { + var res = fn.apply(this, arguments); + if (res === true) { + if (prop !== undefined && !(prop in options.result)) { + options.result[prop] = a; + } + return true; + } else { + return res; + } + }; + }; + module.exports = compareHelpers = { + equal: function (a, b, aParent, bParent, prop, compares, options) { + options.checks = [ + compareHelpers.equalComparesType, + compareHelpers.equalBasicTypes, + compareHelpers.equalArrayLike, + compareHelpers.equalObject + ]; + options['default'] = false; + return loop(a, b, aParent, bParent, prop, compares, options); + }, + equalComparesType: function (a, b, aParent, bParent, prop, compares, options) { + if (typeof compares === 'function') { + var compareResult = compares(a, b, aParent, bParent, prop, options); + if (typeof compareResult === 'boolean') { + return compareResult; + } else if (compareResult && typeof compareResult === 'object') { + if ('intersection' in compareResult && !('difference' in compareResult)) { + var reverseResult = compares(b, a, bParent, aParent, prop, options); + return 'intersection' in reverseResult && !('difference' in reverseResult); + } + return false; + } + return compareResult; + } + }, + equalBasicTypes: function (a, b, aParent, bParent, prop, compares, options) { + if (a === null || b === null) { + return a === b; + } + if (a instanceof Date && b instanceof Date) { + return a.getTime() === b.getTime(); + } + if (options.deep === -1) { + return typeof a === 'object' || a === b; + } + if (typeof a !== typeof b || Array.isArray(a) !== Array.isArray(b)) { + return false; + } + if (a === b) { + return true; + } + }, + equalArrayLike: function (a, b, aParent, bParent, prop, compares, options) { + if (Array.isArray(a) && Array.isArray(b)) { + if (a.length !== b.length) { + return false; + } + for (var i = 0; i < a.length; i++) { + var compare = compares[i] === undefined ? compares['*'] : compares[i]; + if (!loop(a[i], b[i], a, b, i, compare, options)) { + return false; + } + } + return true; + } + }, + equalObject: function (a, b, aParent, bParent, parentProp, compares, options) { + var aType = typeof a; + if (aType === 'object' || aType === 'function') { + var bCopy = assign({}, b); + if (options.deep === false) { + options.deep = -1; + } + for (var prop in a) { + var compare = compares[prop] === undefined ? compares['*'] : compares[prop]; + if (!loop(a[prop], b[prop], a, b, prop, compare, options)) { + return false; + } + delete bCopy[prop]; + } + for (prop in bCopy) { + if (compares[prop] === undefined || !loop(undefined, b[prop], a, b, prop, compares[prop], options)) { + return false; + } + } + return true; + } + }, + subset: function (a, b, aParent, bParent, prop, compares, options) { + options.checks = [ + compareHelpers.subsetComparesType, + compareHelpers.equalBasicTypes, + compareHelpers.equalArrayLike, + compareHelpers.subsetObject + ]; + options.getSubsets = []; + options['default'] = false; + return loop(a, b, aParent, bParent, prop, compares, options); + }, + subsetObject: function (a, b, aParent, bParent, parentProp, compares, options) { + var aType = typeof a; + if (aType === 'object' || aType === 'function') { + return h.eachInUnique(a, function (a, b, aParent, bParent, prop) { + var compare = compares[prop] === undefined ? compares['*'] : compares[prop]; + if (!loop(a, b, aParent, bParent, prop, compare, options) && prop in bParent) { + return false; + } + }, b, function (a, b, aParent, bParent, prop) { + var compare = compares[prop] === undefined ? compares['*'] : compares[prop]; + if (!loop(a, b, aParent, bParent, prop, compare, options)) { + return false; + } + }, true); + } + }, + subsetComparesType: function (a, b, aParent, bParent, prop, compares, options) { + if (typeof compares === 'function') { + var compareResult = compares(a, b, aParent, bParent, prop, options); + if (typeof compareResult === 'boolean') { + return compareResult; + } else if (compareResult && typeof compareResult === 'object') { + if (compareResult.getSubset) { + if (h.indexOf.call(options.getSubsets, compareResult.getSubset) === -1) { + options.getSubsets.push(compareResult.getSubset); + } + } + if (compareResult.intersection === h.ignoreType || compareResult.difference === h.ignoreType) { + return true; + } + if ('intersection' in compareResult && !('difference' in compareResult)) { + var reverseResult = compares(b, a, bParent, aParent, prop, options); + return 'intersection' in reverseResult; + } + return false; + } + return compareResult; + } + }, + properSupersetObject: function (a, b, aParent, bParent, parentProp, compares, options) { + var bType = typeof b; + var hasAdditionalProp = false; + if (bType === 'object' || bType === 'function') { + var aCopy = assign({}, a); + if (options.deep === false) { + options.deep = -1; + } + for (var prop in b) { + var compare = compares[prop] === undefined ? compares['*'] : compares[prop]; + var compareResult = loop(a[prop], b[prop], a, b, prop, compare, options); + if (compareResult === h.ignoreType) { + } else if (!(prop in a) || options.performedDifference) { + hasAdditionalProp = true; + } else if (!compareResult) { + return false; + } + delete aCopy[prop]; + } + for (prop in aCopy) { + if (compares[prop] === undefined || !loop(a[prop], undefined, a, b, prop, compares[prop], options)) { + return false; + } + } + return hasAdditionalProp; + } + }, + properSubsetComparesType: function (a, b, aParent, bParent, prop, compares, options) { + if (typeof compares === 'function') { + var compareResult = compares(a, b, aParent, bParent, prop, options); + if (typeof compareResult === 'boolean') { + return compareResult; + } else if (compareResult && typeof compareResult === 'object') { + if ('intersection' in compareResult && !('difference' in compareResult)) { + var reverseResult = compares(b, a, bParent, aParent, prop, options); + return 'intersection' in reverseResult && 'difference' in reverseResult; + } + return false; + } + return compareResult; + } + }, + difference: function (a, b, aParent, bParent, prop, compares, options) { + options.result = {}; + options.performedDifference = 0; + options.checks = [ + compareHelpers.differenceComparesType, + addToResult(compareHelpers.equalBasicTypes, 'equalBasicTypes'), + addToResult(compareHelpers.equalArrayLike, 'equalArrayLike'), + addToResult(compareHelpers.properSupersetObject, 'properSubsetObject') + ]; + options['default'] = true; + var res = loop(a, b, aParent, bParent, prop, compares, options); + if (res === true && options.performedDifference) { + return options.result; + } + return res; + }, + differenceComparesType: function (a, b, aParent, bParent, prop, compares, options) { + if (typeof compares === 'function') { + var compareResult = compares(a, b, aParent, bParent, prop, options); + if (typeof compareResult === 'boolean') { + if (compareResult === true) { + options.result[prop] = a; + return true; + } else { + return compareResult; + } + } else if (compareResult && typeof compareResult === 'object') { + if ('difference' in compareResult) { + if (compareResult.difference === h.ignoreType) { + return h.ignoreType; + } else if (compareResult.difference != null) { + options.result[prop] = compareResult.difference; + options.performedDifference++; + return true; + } else { + return true; + } + } else { + if (compareHelpers.equalComparesType.apply(this, arguments)) { + options.performedDifference++; + options.result[prop] = compareResult.union; + } else { + return false; + } + } + } + } + }, + union: function (a, b, aParent, bParent, prop, compares, options) { + options.result = {}; + options.performedUnion = 0; + options.checks = [ + compareHelpers.unionComparesType, + addToResult(compareHelpers.equalBasicTypes, 'equalBasicTypes'), + addToResult(compareHelpers.unionArrayLike, 'unionArrayLike'), + addToResult(compareHelpers.unionObject, 'unionObject') + ]; + options.getUnions = []; + options['default'] = false; + var res = loop(a, b, aParent, bParent, prop, compares, options); + if (res === true) { + return options.result; + } + return false; + }, + unionComparesType: function (a, b, aParent, bParent, prop, compares, options) { + if (typeof compares === 'function') { + var compareResult = compares(a, b, aParent, bParent, prop, options); + if (typeof compareResult === 'boolean') { + if (compareResult === true) { + options.result[prop] = a; + return true; + } else { + return compareResult; + } + } else if (compareResult && typeof compareResult === 'object') { + if (compareResult.getUnion) { + if (h.indexOf.call(options.getUnions, compareResult.getUnion) === -1) { + options.getUnions.push(compareResult.getUnion); + } + } + if ('union' in compareResult) { + if (compareResult.union === h.ignoreType) { + return compareResult.union; + } + if (compareResult.union !== undefined) { + options.result[prop] = compareResult.union; + } + options.performedUnion++; + return true; + } + } + } + }, + unionObject: function (a, b, aParent, bParent, prop, compares, options) { + var subsetCompare = function (a, b, aParent, bParent, prop) { + var compare = compares[prop] === undefined ? compares['*'] : compares[prop]; + if (!loop(a, b, aParent, bParent, prop, compare, options)) { + var subsetCheck; + if (!(prop in aParent)) { + subsetCheck = 'subsetB'; + } + if (!(prop in bParent)) { + subsetCheck = 'subsetA'; + } + if (subsetCheck) { + if (!options.subset) { + options.subset = subsetCheck; + } + return options.subset === subsetCheck ? undefined : false; + } + return false; + } + }; + var aType = typeof a; + if (aType === 'object' || aType === 'function') { + return h.eachInUnique(a, subsetCompare, b, subsetCompare, true); + } + }, + unionArrayLike: function (a, b, aParent, bParent, prop, compares, options) { + if (Array.isArray(a) && Array.isArray(b)) { + var combined = makeArray(a).concat(makeArray(b)); + h.doubleLoop(combined, function (item, j, cur, i) { + var res = !compareHelpers.equal(cur, item, aParent, bParent, undefined, compares['*'], { 'default': false }); + return res; + }); + options.result[prop] = combined; + return true; + } + }, + count: function (a, b, aParent, bParent, prop, compares, options) { + options.checks = [ + compareHelpers.countComparesType, + compareHelpers.equalBasicTypes, + compareHelpers.equalArrayLike, + compareHelpers.loopObject + ]; + options['default'] = false; + loop(a, b, aParent, bParent, prop, compares, options); + if (typeof options.count === 'number') { + return options.count; + } + return Infinity; + }, + countComparesType: function (a, b, aParent, bParent, prop, compares, options) { + if (typeof compares === 'function') { + var compareResult = compares(a, b, aParent, bParent, prop, options); + if (typeof compareResult === 'boolean') { + return true; + } else if (compareResult && typeof compareResult === 'object') { + if (typeof compareResult.count === 'number') { + if (!('count' in options) || compareResult.count === options.count) { + options.count = compareResult.count; + } else { + options.count = Infinity; + } + } + return true; + } + } + }, + loopObject: function (a, b, aParent, bParent, prop, compares, options) { + var aType = typeof a; + if (aType === 'object' || aType === 'function') { + each(a, function (aValue, prop) { + var compare = compares[prop] === undefined ? compares['*'] : compares[prop]; + loop(aValue, b[prop], a, b, prop, compare, options); + }); + return true; + } + }, + intersection: function (a, b, aParent, bParent, prop, compares, options) { + options.result = {}; + options.performedIntersection = 0; + options.checks = [ + compareHelpers.intersectionComparesType, + addToResult(compareHelpers.equalBasicTypes, 'equalBasicTypes'), + addToResult(compareHelpers.intersectionArrayLike, 'intersectionArrayLike'), + compareHelpers.intersectionObject + ]; + options['default'] = false; + var res = loop(a, b, aParent, bParent, prop, compares, options); + if (res === true) { + return options.result; + } + return false; + }, + intersectionComparesType: function (a, b, aParent, bParent, prop, compares, options) { + if (typeof compares === 'function') { + var compareResult = compares(a, b, aParent, bParent, prop, options); + if (typeof compareResult === 'boolean') { + if (compareResult === true) { + options.result[prop] = a; + return true; + } else { + return compareResult; + } + } else if (compareResult && typeof compareResult === 'object') { + if ('intersection' in compareResult) { + if (compareResult.intersection !== undefined) { + options.result[prop] = compareResult.intersection; + } + options.performedIntersection++; + return true; + } + } + } + }, + intersectionObject: function (a, b, aParent, bParent, prop, compares, options) { + var subsetCompare = function (a, b, aParent, bParent, prop) { + var compare = compares[prop] === undefined ? compares['*'] : compares[prop]; + if (!loop(a, b, aParent, bParent, prop, compare, options)) { + return addIntersectedPropertyToResult(a, b, aParent, bParent, prop, compares, options); + } + }; + var aType = typeof a; + if (aType === 'object' || aType === 'function') { + return h.eachInUnique(a, subsetCompare, b, subsetCompare, true); + } + }, + intersectionArrayLike: function (a, b, aParent, bParent, prop, compares, options) { + if (Array.isArray(a) && Array.isArray(b)) { + var intersection = []; + each(makeArray(a), function (cur) { + for (var i = 0; i < b.length; i++) { + if (compareHelpers.equal(cur, b[i], aParent, bParent, undefined, compares['*'], { 'default': false })) { + intersection.push(cur); + break; + } + } + }); + options.result[prop] = intersection; + return true; + } + } + }; +}); \ No newline at end of file diff --git a/dist/amd/src/get.js b/dist/amd/src/get.js new file mode 100644 index 0000000..ffe058c --- /dev/null +++ b/dist/amd/src/get.js @@ -0,0 +1,35 @@ +/*can-set@1.3.0-pre.0#src/get*/ +define(function (require, exports, module) { + var compare = require('./compare'); + var h = require('./helpers'); + var each = require('can-util/js/each'); + var filterData = function (data, clause, props) { + return h.filter.call(data, function (item) { + var isSubset = compare.subset(item, clause, undefined, undefined, undefined, props, {}); + return isSubset; + }); + }; + module.exports = { + subsetData: function (a, b, bData, algebra) { + var aClauseProps = algebra.getClauseProperties(a); + var bClauseProps = algebra.getClauseProperties(b); + var options = {}; + var aData = filterData(bData, aClauseProps.where, algebra.clauses.where); + if (aData.length && (aClauseProps.enabled.order || bClauseProps.enabled.order)) { + options = {}; + var propName = h.firstProp(aClauseProps.order), compareOrder = algebra.clauses.order[propName]; + aData = aData.sort(function (aItem, bItem) { + return compareOrder(a[propName], aItem, bItem); + }); + } + if (aData.length && (aClauseProps.enabled.paginate || bClauseProps.enabled.paginate)) { + options = {}; + compare.subset(aClauseProps.paginate, bClauseProps.paginate, undefined, undefined, undefined, algebra.clauses.paginate, options); + each(options.getSubsets, function (filter) { + aData = filter(a, b, aData, algebra, options); + }); + } + return aData; + } + }; +}); \ No newline at end of file diff --git a/dist/amd/src/helpers.js b/dist/amd/src/helpers.js new file mode 100644 index 0000000..cbcd435 --- /dev/null +++ b/dist/amd/src/helpers.js @@ -0,0 +1,172 @@ +/*can-set@1.3.0-pre.0#src/helpers*/ +define(function (require, exports, module) { + var assign = require('can-util/js/assign'); + var each = require('can-util/js/each'); + var last = require('can-util/js/last'); + var IgnoreType = function () { + }; + var helpers; + module.exports = helpers = { + eachInUnique: function (a, acb, b, bcb, defaultReturn) { + var bCopy = assign({}, b), res; + for (var prop in a) { + res = acb(a[prop], b[prop], a, b, prop); + if (res !== undefined) { + return res; + } + delete bCopy[prop]; + } + for (prop in bCopy) { + res = bcb(undefined, b[prop], a, b, prop); + if (res !== undefined) { + return res; + } + } + return defaultReturn; + }, + doubleLoop: function (arr, callbacks) { + if (typeof callbacks === 'function') { + callbacks = { iterate: callbacks }; + } + var i = 0; + while (i < arr.length) { + if (callbacks.start) { + callbacks.start(arr[i]); + } + var j = i + 1; + while (j < arr.length) { + if (callbacks.iterate(arr[j], j, arr[i], i) === false) { + arr.splice(j, 1); + } else { + j++; + } + } + if (callbacks.end) { + callbacks.end(arr[i]); + } + i++; + } + }, + identityMap: function (arr) { + var map = {}; + each(arr, function (value) { + map[value] = 1; + }); + return map; + }, + arrayUnionIntersectionDifference: function (arr1, arr2) { + var map = {}; + var intersection = []; + var union = []; + var difference = arr1.slice(0); + each(arr1, function (value) { + map[value] = true; + union.push(value); + }); + each(arr2, function (value) { + if (map[value]) { + intersection.push(value); + var index = helpers.indexOf.call(difference, value); + if (index !== -1) { + difference.splice(index, 1); + } + } else { + union.push(value); + } + }); + return { + intersection: intersection, + union: union, + difference: difference + }; + }, + arraySame: function (arr1, arr2) { + if (arr1.length !== arr2.length) { + return false; + } + var map = helpers.identityMap(arr1); + for (var i = 0; i < arr2.length; i++) { + var val = map[arr2[i]]; + if (!val) { + return false; + } else if (val > 1) { + return false; + } else { + map[arr2[i]]++; + } + } + return true; + }, + indexOf: Array.prototype.indexOf || function (item) { + for (var i = 0, thisLen = this.length; i < thisLen; i++) { + if (this[i] === item) { + return i; + } + } + return -1; + }, + map: Array.prototype.map || function (cb) { + var out = []; + for (var i = 0, len = this.length; i < len; i++) { + out.push(cb(this[i], i, this)); + } + return out; + }, + filter: Array.prototype.filter || function (cb) { + var out = []; + for (var i = 0, len = this.length; i < len; i++) { + if (cb(this[i], i, this)) { + out.push(this[i]); + } + } + return out; + }, + ignoreType: new IgnoreType(), + firstProp: function (set) { + for (var prop in set) { + return prop; + } + }, + index: function (compare, items, props) { + if (!items || !items.length) { + return undefined; + } + if (compare(props, items[0]) === -1) { + return 0; + } else if (compare(props, last(items)) === 1) { + return items.length; + } + var low = 0, high = items.length; + while (low < high) { + var mid = low + high >>> 1, item = items[mid], computed = compare(props, item); + if (computed === -1) { + high = mid; + } else { + low = mid + 1; + } + } + return high; + }, + defaultSort: function (sortPropValue, item1, item2) { + var parts = sortPropValue.split(' '); + var sortProp = parts[0]; + var item1Value = item1[sortProp]; + var item2Value = item2[sortProp]; + var temp; + var desc = parts[1] || ''; + desc = desc.toLowerCase() === 'desc'; + if (desc) { + temp = item1Value; + item1Value = item2Value; + item2Value = temp; + } + if (item1Value < item2Value) { + return -1; + } + if (item1Value > item2Value) { + return 1; + } + return 0; + } + }; +}); \ No newline at end of file diff --git a/dist/amd/src/props.js b/dist/amd/src/props.js new file mode 100644 index 0000000..9e4c337 --- /dev/null +++ b/dist/amd/src/props.js @@ -0,0 +1,410 @@ +/*can-set@1.3.0-pre.0#src/props*/ +define(function (require, exports, module) { + var h = require('./helpers'); + var clause = require('./clause'); + var each = require('can-util/js/each'); + var within = function (value, range) { + return value >= range[0] && value <= range[1]; + }; + var numericProperties = function (setA, setB, property1, property2) { + return { + sAv1: +setA[property1], + sAv2: +setA[property2], + sBv1: +setB[property1], + sBv2: +setB[property2] + }; + }; + var diff = function (setA, setB, property1, property2) { + var numProps = numericProperties(setA, setB, property1, property2); + var sAv1 = numProps.sAv1, sAv2 = numProps.sAv2, sBv1 = numProps.sBv1, sBv2 = numProps.sBv2, count = sAv2 - sAv1 + 1; + var after = { + difference: [ + sBv2 + 1, + sAv2 + ], + intersection: [ + sAv1, + sBv2 + ], + union: [ + sBv1, + sAv2 + ], + count: count, + meta: 'after' + }; + var before = { + difference: [ + sAv1, + sBv1 - 1 + ], + intersection: [ + sBv1, + sAv2 + ], + union: [ + sAv1, + sBv2 + ], + count: count, + meta: 'before' + }; + if (sAv1 === sBv1 && sAv2 === sBv2) { + return { + intersection: [ + sAv1, + sAv2 + ], + union: [ + sAv1, + sAv2 + ], + count: count, + meta: 'equal' + }; + } else if (sAv1 === sBv1 && sBv2 < sAv2) { + return after; + } else if (sAv2 === sBv2 && sBv1 > sAv1) { + return before; + } else if (within(sAv1, [ + sBv1, + sBv2 + ]) && within(sAv2, [ + sBv1, + sBv2 + ])) { + return { + intersection: [ + sAv1, + sAv2 + ], + union: [ + sBv1, + sBv2 + ], + count: count, + meta: 'subset' + }; + } else if (within(sBv1, [ + sAv1, + sAv2 + ]) && within(sBv2, [ + sAv1, + sAv2 + ])) { + return { + intersection: [ + sBv1, + sBv2 + ], + difference: [ + null, + null + ], + union: [ + sAv1, + sAv2 + ], + count: count, + meta: 'superset' + }; + } else if (sAv1 < sBv1 && within(sAv2, [ + sBv1, + sBv2 + ])) { + return before; + } else if (sBv1 < sAv1 && within(sBv2, [ + sAv1, + sAv2 + ])) { + return after; + } else if (sAv2 === sBv1 - 1) { + return { + difference: [ + sAv1, + sAv2 + ], + union: [ + sAv1, + sBv2 + ], + count: count, + meta: 'disjoint-before' + }; + } else if (sBv2 === sAv1 - 1) { + return { + difference: [ + sAv1, + sAv2 + ], + union: [ + sBv1, + sAv2 + ], + count: count, + meta: 'disjoint-after' + }; + } + if (!isNaN(count)) { + return { + count: count, + meta: 'disjoint' + }; + } + }; + var cleanUp = function (value, enumData) { + if (!value) { + return enumData; + } + if (!Array.isArray(value)) { + value = [value]; + } + if (!value.length) { + return enumData; + } + return value; + }; + var stringConvert = { + '0': false, + 'false': false, + 'null': undefined, + 'undefined': undefined + }; + var convertToBoolean = function (value) { + if (typeof value === 'string') { + return value.toLowerCase() in stringConvert ? stringConvert[value.toLowerCase()] : true; + } + return value; + }; + var props = { + 'enum': function (prop, enumData) { + var compares = new clause.Where({}); + compares[prop] = function (vA, vB, A, B) { + vA = cleanUp(vA, enumData); + vB = cleanUp(vB, enumData); + var data = h.arrayUnionIntersectionDifference(vA, vB); + if (!data.difference.length) { + delete data.difference; + } + each(data, function (value, prop) { + if (Array.isArray(value)) { + if (h.arraySame(enumData, value)) { + data[prop] = undefined; + } else if (value.length === 1) { + data[prop] = value[0]; + } + } + }); + return data; + }; + return compares; + }, + paginate: function (propStart, propEnd, translateToStartEnd, reverseTranslate) { + var compares = {}; + var makeResult = function (result, index) { + var res = {}; + each([ + 'intersection', + 'difference', + 'union' + ], function (prop) { + if (result[prop]) { + var set = { + start: result[prop][0], + end: result[prop][1] + }; + res[prop] = reverseTranslate(set)[index === 0 ? propStart : propEnd]; + } + }); + if (result.count) { + res.count = result.count; + } + return res; + }; + compares[propStart] = function (vA, vB, A, B) { + if (vA === undefined) { + return; + } + var res = diff(translateToStartEnd(A), translateToStartEnd(B), 'start', 'end'); + var result = makeResult(res, 0); + result.getSubset = function (a, b, bItems, algebra, options) { + return bItems; + }; + result.getUnion = function (a, b, aItems, bItems, algebra, options) { + return [ + aItems, + bItems + ]; + }; + return result; + }; + compares[propEnd] = function (vA, vB, A, B) { + if (vA === undefined) { + return; + } + var data = diff(translateToStartEnd(A), translateToStartEnd(B), 'start', 'end'); + var res = makeResult(data, 1); + res.getSubset = function (a, b, bItems, algebra, options) { + var tA = translateToStartEnd(a); + var tB = translateToStartEnd(b); + var numProps = numericProperties(tA, tB, 'start', 'end'); + var aStartValue = numProps.sAv1, aEndValue = numProps.sAv2; + var bStartValue = numProps.sBv1; + if (!('end' in tB) || !('end' in tA)) { + return bItems.slice(aStartValue, aEndValue + 1); + } + return bItems.slice(aStartValue - bStartValue, aEndValue - bStartValue + 1); + }; + res.getUnion = function (a, b, aItems, bItems, algebra, options) { + var tA = translateToStartEnd(a); + var tB = translateToStartEnd(b); + if (data.meta.indexOf('after') >= 0) { + if (data.intersection) { + bItems = bItems.slice(0, data.intersection[0] - +tB.start); + } + return [ + bItems, + aItems + ]; + } + if (data.intersection) { + aItems = aItems.slice(0, data.intersection[0] - +tA.start); + } + return [ + aItems, + bItems + ]; + }; + return res; + }; + return new clause.Paginate(compares); + }, + 'boolean': function (propertyName) { + var compares = new clause.Where({}); + compares[propertyName] = function (propA, propB) { + propA = convertToBoolean(propA); + propB = convertToBoolean(propB); + var notA = !propA, notB = !propB; + if (propA === notB && propB === notA) { + return { + difference: !propB, + union: undefined + }; + } else if (propA === undefined) { + return { + difference: !propB, + intersection: propB, + union: undefined + }; + } else if (propA === propB) { + return true; + } + }; + return compares; + }, + 'sort': function (prop, sortFunc) { + if (!sortFunc) { + sortFunc = h.defaultSort; + } + var compares = {}; + compares[prop] = sortFunc; + return new clause.Order(compares); + }, + 'id': function (prop) { + var compares = {}; + compares[prop] = prop; + return new clause.Id(compares); + } + }; + var assignExcept = function (d, s, props) { + for (var prop in s) { + if (!props[prop]) { + d[prop] = s[prop]; + } + } + return d; + }; + var translateToOffsetLimit = function (set, offsetProp, limitProp) { + var newSet = assignExcept({}, set, { + start: 1, + end: 1 + }); + if ('start' in set) { + newSet[offsetProp] = set.start; + } + if ('end' in set) { + newSet[limitProp] = set.end - set.start + 1; + } + return newSet; + }; + var translateToStartEnd = function (set, offsetProp, limitProp) { + var except = {}; + except[offsetProp] = except[limitProp] = 1; + var newSet = assignExcept({}, set, except); + if (offsetProp in set) { + newSet.start = parseInt(set[offsetProp], 10); + } + if (limitProp in set) { + newSet.end = newSet.start + parseInt(set[limitProp]) - 1; + } + return newSet; + }; + props.offsetLimit = function (offsetProp, limitProp) { + offsetProp = offsetProp || 'offset'; + limitProp = limitProp || 'limit'; + return props.paginate(offsetProp, limitProp, function (set) { + return translateToStartEnd(set, offsetProp, limitProp); + }, function (set) { + return translateToOffsetLimit(set, offsetProp, limitProp); + }); + }; + props.rangeInclusive = function (startIndexProperty, endIndexProperty) { + startIndexProperty = startIndexProperty || 'start'; + endIndexProperty = endIndexProperty || 'end'; + return props.paginate(startIndexProperty, endIndexProperty, function (set) { + var except = {}; + except[startIndexProperty] = except[endIndexProperty] = 1; + var newSet = assignExcept({}, set, except); + if (startIndexProperty in set) { + newSet.start = set[startIndexProperty]; + } + if (endIndexProperty in set) { + newSet.end = set[endIndexProperty]; + } + return newSet; + }, function (set) { + var except = { + start: 1, + end: 1 + }; + var newSet = assignExcept({}, set, except); + newSet[startIndexProperty] = set.start; + newSet[endIndexProperty] = set.end; + return newSet; + }); + }; + var nestedLookup = function (obj, propNameArray) { + if (obj === undefined) { + return undefined; + } + if (propNameArray.length === 1) { + return obj[propNameArray[0]]; + } else { + return nestedLookup(obj[propNameArray[0]], propNameArray.slice(1)); + } + }; + props.dotNotation = function (dotProperty) { + var compares = new clause.Where({}); + compares[dotProperty] = function (aVal, bVal, a, b, propertyName) { + if (aVal === undefined) { + aVal = nestedLookup(a, propertyName.split('.')); + } + if (bVal === undefined) { + bVal = nestedLookup(b, propertyName.split('.')); + } + return aVal === bVal; + }; + return compares; + }; + module.exports = props; +}); \ No newline at end of file diff --git a/dist/amd/src/set-core.js b/dist/amd/src/set-core.js new file mode 100644 index 0000000..a88d501 --- /dev/null +++ b/dist/amd/src/set-core.js @@ -0,0 +1,319 @@ +/*can-set@1.3.0-pre.0#src/set-core*/ +define(function (require, exports, module) { + var h = require('./helpers'); + var clause = require('./clause'); + var compare = require('./compare'); + var get = require('./get'); + var assign = require('can-util/js/assign'); + var each = require('can-util/js/each'); + var makeArray = require('can-util/js/make-array'); + var isEmptyObject = require('can-util/js/is-empty-object'); + function Translate(clause, options) { + if (typeof options === 'string') { + var path = options; + options = { + fromSet: function (set, setRemainder) { + return set[path] || {}; + }, + toSet: function (set, wheres) { + set[path] = wheres; + return set; + } + }; + } + this.clause = clause; + assign(this, options); + } + var Algebra = function () { + var clauses = this.clauses = { + where: {}, + order: {}, + paginate: {}, + id: {} + }; + this.translators = { + where: new Translate('where', { + fromSet: function (set, setRemainder) { + return setRemainder; + }, + toSet: function (set, wheres) { + return assign(set, wheres); + } + }) + }; + var self = this; + each(arguments, function (arg) { + if (arg) { + if (arg instanceof Translate) { + self.translators[arg.clause] = arg; + } else { + assign(clauses[arg.constructor.type || 'where'], arg); + } + } + }); + }; + Algebra.make = function (compare, count) { + if (compare instanceof Algebra) { + return compare; + } else { + return new Algebra(compare, count); + } + }; + assign(Algebra.prototype, { + getClauseProperties: function (set, options) { + options = options || {}; + var setClone = assign({}, set); + var clauses = this.clauses; + var checkClauses = [ + 'order', + 'paginate', + 'id' + ]; + var clauseProps = { + enabled: { + where: true, + order: false, + paginate: false, + id: false + } + }; + if (options.omitClauses) { + checkClauses = h.arrayUnionIntersectionDifference(checkClauses, options.omitClauses).difference; + } + each(checkClauses, function (clauseName) { + var valuesForClause = {}; + var prop; + for (prop in clauses[clauseName]) { + if (prop in setClone) { + valuesForClause[prop] = setClone[prop]; + delete setClone[prop]; + } + } + clauseProps[clauseName] = valuesForClause; + clauseProps.enabled[clauseName] = !isEmptyObject(valuesForClause); + }); + clauseProps.where = options.isProperties ? setClone : this.translators.where.fromSet(set, setClone); + return clauseProps; + }, + getDifferentClauseTypes: function (aClauses, bClauses) { + var self = this; + var differentTypes = []; + each(clause.TYPES, function (type) { + if (!self.evaluateOperator(compare.equal, aClauses[type], bClauses[type], { isProperties: true }, { isProperties: true })) { + differentTypes.push(type); + } + }); + return differentTypes; + }, + updateSet: function (set, clause, result, useSet) { + if (result && typeof result === 'object' && useSet !== false) { + if (this.translators[clause]) { + set = this.translators.where.toSet(set, result); + } else { + set = assign(set, result); + } + return true; + } else if (result) { + return useSet === undefined ? undefined : false; + } else { + return false; + } + }, + evaluateOperator: function (operator, a, b, aOptions, bOptions, evaluateOptions) { + aOptions = aOptions || {}; + bOptions = bOptions || {}; + evaluateOptions = assign({ + evaluateWhere: operator, + evaluatePaginate: operator, + evaluateOrder: operator, + shouldEvaluatePaginate: function (aClauseProps, bClauseProps) { + return aClauseProps.enabled.paginate || bClauseProps.enabled.paginate; + }, + shouldEvaluateOrder: function (aClauseProps, bClauseProps) { + return aClauseProps.enabled.order && compare.equal(aClauseProps.order, bClauseProps.order, undefined, undefined, undefined, {}, {}); + } + }, evaluateOptions || {}); + var aClauseProps = this.getClauseProperties(a, aOptions), bClauseProps = this.getClauseProperties(b, bOptions), set = {}, useSet; + var result = evaluateOptions.evaluateWhere(aClauseProps.where, bClauseProps.where, undefined, undefined, undefined, this.clauses.where, {}); + useSet = this.updateSet(set, 'where', result, useSet); + if (result && evaluateOptions.shouldEvaluatePaginate(aClauseProps, bClauseProps)) { + if (evaluateOptions.shouldEvaluateOrder(aClauseProps, bClauseProps)) { + result = evaluateOptions.evaluateOrder(aClauseProps.order, bClauseProps.order, undefined, undefined, undefined, {}, {}); + useSet = this.updateSet(set, 'order', result, useSet); + } + if (result) { + result = evaluateOptions.evaluatePaginate(aClauseProps.paginate, bClauseProps.paginate, undefined, undefined, undefined, this.clauses.paginate, {}); + useSet = this.updateSet(set, 'paginate', result, useSet); + } + } else if (result && evaluateOptions.shouldEvaluateOrder(aClauseProps, bClauseProps)) { + result = operator(aClauseProps.order, bClauseProps.order, undefined, undefined, undefined, {}, {}); + useSet = this.updateSet(set, 'order', result, useSet); + } + return result && useSet ? set : result; + }, + equal: function (a, b) { + return this.evaluateOperator(compare.equal, a, b); + }, + subset: function (a, b) { + var aClauseProps = this.getClauseProperties(a); + var bClauseProps = this.getClauseProperties(b); + var compatibleSort = true; + var result; + if (bClauseProps.enabled.paginate && (aClauseProps.enabled.order || bClauseProps.enabled.order)) { + compatibleSort = compare.equal(aClauseProps.order, bClauseProps.order, undefined, undefined, undefined, {}, {}); + } + if (!compatibleSort) { + result = false; + } else { + result = this.evaluateOperator(compare.subset, a, b); + } + return result; + }, + properSubset: function (a, b) { + return this.subset(a, b) && !this.equal(a, b); + }, + difference: function (a, b) { + var aClauseProps = this.getClauseProperties(a); + var bClauseProps = this.getClauseProperties(b); + var differentClauses = this.getDifferentClauseTypes(aClauseProps, bClauseProps); + var result; + switch (differentClauses.length) { + case 0: { + result = false; + break; + } + case 1: { + var clause = differentClauses[0]; + result = compare.difference(aClauseProps[clause], bClauseProps[clause], undefined, undefined, undefined, this.clauses[clause], {}); + if (this.translators[clause] && typeof result === 'object') { + result = this.translators[clause].toSet({}, result); + } + break; + } + } + return result; + }, + union: function (a, b) { + return this.evaluateOperator(compare.union, a, b); + }, + intersection: function (a, b) { + return this.evaluateOperator(compare.intersection, a, b); + }, + count: function (set) { + return this.evaluateOperator(compare.count, set, {}); + }, + has: function (set, props) { + var aClauseProps = this.getClauseProperties(set); + var propsClauseProps = this.getClauseProperties(props, { isProperties: true }); + var compatibleSort = true; + var result; + if ((propsClauseProps.enabled.paginate || aClauseProps.enabled.paginate) && (propsClauseProps.enabled.order || aClauseProps.enabled.order)) { + compatibleSort = compare.equal(propsClauseProps.order, aClauseProps.order, undefined, undefined, undefined, {}, {}); + } + if (!compatibleSort) { + result = false; + } else { + result = this.evaluateOperator(compare.subset, props, set, { isProperties: true }, undefined); + } + return result; + }, + index: function (set, items, item) { + var aClauseProps = this.getClauseProperties(set); + var propName = h.firstProp(aClauseProps.order), compare, orderValue; + if (propName) { + compare = this.clauses.order[propName]; + orderValue = set[propName]; + return h.index(function (itemA, itemB) { + return compare(orderValue, itemA, itemB); + }, items, item); + } + propName = h.firstProp(this.clauses.id); + if (propName) { + compare = h.defaultSort; + orderValue = propName; + return h.index(function (itemA, itemB) { + return compare(orderValue, itemA, itemB); + }, items, item); + } + return; + }, + getSubset: function (a, b, bData) { + var aClauseProps = this.getClauseProperties(a); + var bClauseProps = this.getClauseProperties(b); + var isSubset = this.subset(assign({}, aClauseProps.where, aClauseProps.paginate), assign({}, bClauseProps.where, bClauseProps.paginate)); + if (isSubset) { + return get.subsetData(a, b, bData, this); + } + }, + getUnion: function (a, b, aItems, bItems) { + var aClauseProps = this.getClauseProperties(a); + var bClauseProps = this.getClauseProperties(b); + var algebra = this; + var options; + if (this.subset(a, b)) { + return bItems; + } else if (this.subset(b, a)) { + return aItems; + } + var combined; + if (aClauseProps.enabled.paginate || bClauseProps.enabled.paginate) { + options = {}; + var isUnion = compare.union(aClauseProps.paginate, bClauseProps.paginate, undefined, undefined, undefined, this.clauses.paginate, options); + if (!isUnion) { + return; + } else { + each(options.getUnions, function (filter) { + var items = filter(a, b, aItems, bItems, algebra, options); + aItems = items[0]; + bItems = items[1]; + }); + combined = aItems.concat(bItems); + } + } else { + combined = aItems.concat(bItems); + } + if (combined.length && aClauseProps.enabled.order && compare.equal(aClauseProps.order, bClauseProps.order, undefined, undefined, undefined, {}, {})) { + options = {}; + var propName = h.firstProp(aClauseProps.order), compareOrder = algebra.clauses.order[propName]; + combined = combined.sort(function (aItem, bItem) { + return compareOrder(a[propName], aItem, bItem); + }); + } + return combined; + }, + id: function (props) { + var keys = Object.keys(this.clauses.id); + if (keys.length === 1) { + return props[keys[0]]; + } else { + var id = {}; + keys.forEach(function (key) { + id[key] = props[key]; + }); + return JSON.stringify(id); + } + } + }); + var callOnAlgebra = function (methodName, algebraArgNumber) { + return function () { + var args = makeArray(arguments).slice(0, algebraArgNumber); + var algebra = Algebra.make(arguments[algebraArgNumber]); + return algebra[methodName].apply(algebra, args); + }; + }; + module.exports = { + Algebra: Algebra, + Translate: Translate, + difference: callOnAlgebra('difference', 2), + equal: callOnAlgebra('equal', 2), + subset: callOnAlgebra('subset', 2), + properSubset: callOnAlgebra('properSubset', 2), + union: callOnAlgebra('union', 2), + intersection: callOnAlgebra('intersection', 2), + count: callOnAlgebra('count', 1), + has: callOnAlgebra('has', 2), + index: callOnAlgebra('index', 3), + getSubset: callOnAlgebra('getSubset', 3), + getUnion: callOnAlgebra('getUnion', 4) + }; +}); \ No newline at end of file diff --git a/dist/amd/src/set.js b/dist/amd/src/set.js new file mode 100644 index 0000000..d79ce86 --- /dev/null +++ b/dist/amd/src/set.js @@ -0,0 +1,12 @@ +/*can-set@1.3.0-pre.0#src/set*/ +define(function (require, exports, module) { + var set = require('./set-core'); + var ns = require('can-namespace'); + var props = require('./props'); + var clause = require('./clause'); + set.comparators = props; + set.props = props; + set.helpers = require('./helpers'); + set.clause = clause; + module.exports = ns.set = set; +}); \ No newline at end of file diff --git a/dist/global/can-set.js b/dist/global/can-set.js new file mode 100644 index 0000000..2220515 --- /dev/null +++ b/dist/global/can-set.js @@ -0,0 +1,2286 @@ +/*[global-shim-start]*/ +(function(exports, global, doEval){ // jshint ignore:line + var origDefine = global.define; + + var get = function(name){ + var parts = name.split("."), + cur = global, + i; + for(i = 0 ; i < parts.length; i++){ + if(!cur) { + break; + } + cur = cur[parts[i]]; + } + return cur; + }; + var set = function(name, val){ + var parts = name.split("."), + cur = global, + i, part, next; + for(i = 0; i < parts.length - 1; i++) { + part = parts[i]; + next = cur[part]; + if(!next) { + next = cur[part] = {}; + } + cur = next; + } + part = parts[parts.length - 1]; + cur[part] = val; + }; + var useDefault = function(mod){ + if(!mod || !mod.__esModule) return false; + var esProps = { __esModule: true, "default": true }; + for(var p in mod) { + if(!esProps[p]) return false; + } + return true; + }; + var modules = (global.define && global.define.modules) || + (global._define && global._define.modules) || {}; + var ourDefine = global.define = function(moduleName, deps, callback){ + var module; + if(typeof deps === "function") { + callback = deps; + deps = []; + } + var args = [], + i; + for(i =0; i < deps.length; i++) { + args.push( exports[deps[i]] ? get(exports[deps[i]]) : ( modules[deps[i]] || get(deps[i]) ) ); + } + // CJS has no dependencies but 3 callback arguments + if(!deps.length && callback.length) { + module = { exports: {} }; + var require = function(name) { + return exports[name] ? get(exports[name]) : modules[name]; + }; + args.push(require, module.exports, module); + } + // Babel uses the exports and module object. + else if(!args[0] && deps[0] === "exports") { + module = { exports: {} }; + args[0] = module.exports; + if(deps[1] === "module") { + args[1] = module; + } + } else if(!args[0] && deps[0] === "module") { + args[0] = { id: moduleName }; + } + + global.define = origDefine; + var result = callback ? callback.apply(null, args) : undefined; + global.define = ourDefine; + + // Favor CJS module.exports over the return value + result = module && module.exports ? module.exports : result; + modules[moduleName] = result; + + // Set global exports + var globalExport = exports[moduleName]; + if(globalExport && !get(globalExport)) { + if(useDefault(result)) { + result = result["default"]; + } + set(globalExport, result); + } + }; + global.define.orig = origDefine; + global.define.modules = modules; + global.define.amd = true; + ourDefine("@loader", [], function(){ + // shim for @@global-helpers + var noop = function(){}; + return { + get: function(){ + return { prepareGlobal: noop, retrieveGlobal: noop }; + }, + global: global, + __exec: function(__load){ + doEval(__load.source, global); + } + }; + }); +} +)({},window,function(__$source__, __$global__) { // jshint ignore:line + eval("(function() { " + __$source__ + " \n }).call(__$global__);"); +} +) +/*can-util@3.9.0-pre.4#js/assign/assign*/ +define('set-can-util/js/assign/assign', function (require, exports, module) { + module.exports = function (d, s) { + for (var prop in s) { + d[prop] = s[prop]; + } + return d; + }; +}); +/*can-util@3.9.0-pre.4#js/is-array-like/is-array-like*/ +define('set-can-util/js/is-array-like/is-array-like', function (require, exports, module) { + 'use strict'; + function isArrayLike(obj) { + var type = typeof obj; + if (type === 'string') { + return true; + } else if (type === 'number') { + return false; + } + var length = obj && type !== 'boolean' && typeof obj !== 'number' && 'length' in obj && obj.length; + return typeof obj !== 'function' && (length === 0 || typeof length === 'number' && length > 0 && length - 1 in obj); + } + module.exports = isArrayLike; +}); +/*can-namespace@1.0.0#can-namespace*/ +define('can-namespace', function (require, exports, module) { + module.exports = {}; +}); +/*can-symbol@1.0.0-pre.0#can-symbol*/ +define('can-symbol', function (require, exports, module) { + (function (global) { + var CanSymbol; + if (typeof Symbol !== 'undefined') { + CanSymbol = Symbol; + } else { + var symbolNum = 0; + CanSymbol = function CanSymbolPolyfill(description) { + var symbolValue = '@@symbol' + symbolNum++ + description; + var symbol = {}; + Object.defineProperties(symbol, { + toString: { + value: function () { + return symbolValue; + } + } + }); + return symbol; + }; + var descriptionToSymbol = {}; + var symbolToDescription = {}; + CanSymbol.for = function (description) { + var symbol = descriptionToSymbol[description]; + if (!symbol) { + symbol = descriptionToSymbol[description] = CanSymbol(description); + symbolToDescription[symbol] = description; + } + return symbol; + }; + CanSymbol.keyFor = function (symbol) { + return symbolToDescription[symbol]; + }; + [ + 'hasInstance', + 'isConcatSpreadable', + 'iterator', + 'match', + 'prototype', + 'replace', + 'search', + 'species', + 'split', + 'toPrimitive', + 'toStringTag', + 'unscopables' + ].forEach(function (name) { + CanSymbol[name] = CanSymbol.for(name); + }); + } + [ + 'isMapLike', + 'isListLike', + 'isValueLike', + 'getOwnKeys', + 'getOwnKeyDescriptor', + 'proto', + 'getOwnEnumerableKeys', + 'hasOwnKey', + 'getValue', + 'setValue', + 'getKeyValue', + 'setKeyValue', + 'apply', + 'new', + 'onValue', + 'offValue', + 'onKeyValue', + 'offKeyValue', + 'getKeyDependencies', + 'getValueDependencies', + 'keyHasDependencies', + 'valueHasDependencies', + 'onKeys', + 'onKeysAdded', + 'onKeysRemoved' + ].forEach(function (name) { + CanSymbol.for('can.' + name); + }); + module.exports = CanSymbol; + }(function () { + return this; + }())); +}); +/*can-reflect@1.0.0-pre.2#reflections/type/type*/ +define('can-reflect/reflections/type/type', function (require, exports, module) { + var canSymbol = require('can-symbol'); + var check = function (symbols, obj) { + for (var i = 0, len = symbols.length; i < len; i++) { + var value = obj[canSymbol.for(symbols[i])]; + if (value !== undefined) { + return value; + } + } + }; + function isConstructorLike(func) { + var value = func[canSymbol.for('can.new')]; + if (value !== undefined) { + return value; + } + if (typeof func !== 'function') { + return false; + } + for (var prop in func.prototype) { + return true; + } + return false; + } + function isFunctionLike(obj) { + var result = check([ + 'can.new', + 'can.apply' + ], obj); + if (result !== undefined) { + return !!result; + } + return typeof obj === 'function'; + } + function isPrimitive(obj) { + var type = typeof obj; + if (obj == null || type !== 'function' && type !== 'object') { + return true; + } else { + return false; + } + } + function isValueLike(obj) { + var symbolValue; + if (isPrimitive(obj)) { + return true; + } + symbolValue = obj[canSymbol.for('can.isValueLike')]; + if (typeof symbolValue !== 'undefined') { + return symbolValue; + } + var value = obj[canSymbol.for('can.getValue')]; + if (value !== undefined) { + return !!value; + } + } + function isMapLike(obj) { + var symbolValue; + if (isPrimitive(obj)) { + return false; + } + symbolValue = obj[canSymbol.for('can.isMapLike')]; + if (typeof symbolValue !== 'undefined') { + return symbolValue; + } + var value = obj[canSymbol.for('can.getKeyValue')]; + if (value !== undefined) { + return !!value; + } + return true; + } + function isObservableLike(obj) { + if (isPrimitive(obj)) { + return false; + } + var result = check([ + 'can.onValue', + 'can.onKeyValue', + 'can.onKeys', + 'can.onKeysAdded' + ], obj); + if (result !== undefined) { + return !!result; + } + } + function isListLike(list) { + var symbolValue, type = typeof list; + if (type === 'string') { + return true; + } + if (isPrimitive(list)) { + return false; + } + symbolValue = list[canSymbol.for('can.isListLike')]; + if (typeof symbolValue !== 'undefined') { + return symbolValue; + } + var value = list[canSymbol.iterator]; + if (value !== undefined) { + return !!value; + } + if (Array.isArray(list)) { + return true; + } + var length = list && type !== 'boolean' && typeof list !== 'number' && 'length' in list && list.length; + return typeof list !== 'function' && (length === 0 || typeof length === 'number' && length > 0 && length - 1 in list); + } + var symbolStart = '@@symbol'; + function isSymbolLike(symbol) { + if (typeof symbol === 'symbol') { + return true; + } else { + return symbol.toString().substr(0, symbolStart.length) === symbolStart; + } + } + module.exports = { + isConstructorLike: isConstructorLike, + isFunctionLike: isFunctionLike, + isListLike: isListLike, + isMapLike: isMapLike, + isObservableLike: isObservableLike, + isPrimitive: isPrimitive, + isValueLike: isValueLike, + isSymbolLike: isSymbolLike, + isMoreListLikeThanMapLike: function (obj) { + if (Array.isArray(obj)) { + return true; + } + var value = obj[canSymbol.for('can.isMoreListLikeThanMapLike')]; + if (value !== undefined) { + return value; + } + var isListLike = this.isListLike(obj), isMapLike = this.isMapLike(obj); + if (isListLike && !isMapLike) { + return true; + } else if (!isListLike && isMapLike) { + return false; + } + }, + isIteratorLike: function (obj) { + return obj && typeof obj === 'object' && typeof obj.next === 'function' && obj.next.length === 0; + }, + isPromise: function (obj) { + return obj instanceof Promise || Object.prototype.toString.call(obj) === '[object Promise]'; + } + }; +}); +/*can-reflect@1.0.0-pre.2#reflections/call/call*/ +define('can-reflect/reflections/call/call', function (require, exports, module) { + var canSymbol = require('can-symbol'); + var typeReflections = require('../type/type'); + module.exports = { + call: function (func, context) { + var args = [].slice.call(arguments, 2); + var apply = func[canSymbol.for('can.apply')]; + if (apply) { + return apply.call(func, context, args); + } else { + return func.apply(context, args); + } + }, + apply: function (func, context, args) { + var apply = func[canSymbol.for('can.apply')]; + if (apply) { + return apply.call(func, context, args); + } else { + return func.apply(context, args); + } + }, + 'new': function (func) { + var args = [].slice.call(arguments, 1); + var makeNew = func[canSymbol.for('can.new')]; + if (makeNew) { + return makeNew.apply(func, args); + } else { + var context = Object.create(func.prototype); + var ret = func.apply(context, args); + if (typeReflections.isPrimitive(ret)) { + return context; + } else { + return ret; + } + } + } + }; +}); +/*can-reflect@1.0.0-pre.2#reflections/get-set/get-set*/ +define('can-reflect/reflections/get-set/get-set', function (require, exports, module) { + var canSymbol = require('can-symbol'); + var typeReflections = require('../type/type'); + var setKeyValueSymbol = canSymbol.for('can.setKeyValue'), getKeyValueSymbol = canSymbol.for('can.getKeyValue'), getValueSymbol = canSymbol.for('can.getValue'), setValueSymbol = canSymbol.for('can.setValue'); + var reflections = { + setKeyValue: function (obj, key, value) { + if (typeof key === 'symbol') { + obj[key] = value; + return; + } + var setKeyValue = obj[setKeyValueSymbol]; + if (setKeyValue) { + return setKeyValue.call(obj, key, value); + } else if (typeof key !== 'symbol' && typeReflections.isSymbolLike(key)) { + Object.defineProperty(obj, key, { + enumerable: false, + configurable: true, + value: value, + writable: true + }); + } else { + obj[key] = value; + } + }, + getKeyValue: function (obj, key) { + var getKeyValue = obj[getKeyValueSymbol]; + if (getKeyValue) { + return getKeyValue.call(obj, key); + } + return obj[key]; + }, + deleteKeyValue: function (obj, key) { + var deleteKeyValue = obj[canSymbol.for('can.deleteKeyValue')]; + if (deleteKeyValue) { + return deleteKeyValue.call(obj, key); + } + delete obj[key]; + }, + getValue: function (value) { + if (typeReflections.isPrimitive(value)) { + return value; + } + var getValue = value[getValueSymbol]; + if (getValue) { + return getValue.call(value); + } + return value; + }, + setValue: function (item, value) { + var setValue = item && item[setValueSymbol]; + if (setValue) { + return setValue.call(item, value); + } else { + throw new Error('can-reflect.setValue - Can not set value.'); + } + } + }; + reflections.get = reflections.getKeyValue; + reflections.set = reflections.setKeyValue; + reflections.delete = reflections.deleteKeyValue; + module.exports = reflections; +}); +/*can-reflect@1.0.0-pre.2#reflections/observe/observe*/ +define('can-reflect/reflections/observe/observe', function (require, exports, module) { + var canSymbol = require('can-symbol'); + var slice = [].slice; + function makeFallback(symbolName, fallbackName) { + return function (obj, event, handler) { + var method = obj[canSymbol.for(symbolName)]; + if (method !== undefined) { + return method.call(obj, event, handler); + } + return this[fallbackName].apply(this, arguments); + }; + } + function makeErrorIfMissing(symbolName, errorMessage) { + return function (obj, arg1, arg2) { + var method = obj[canSymbol.for(symbolName)]; + if (method !== undefined) { + return method.call(obj, arg1, arg2); + } + throw new Error(errorMessage); + }; + } + module.exports = { + onKeyValue: makeFallback('can.onKeyValue', 'onEvent'), + offKeyValue: makeFallback('can.offKeyValue', 'offEvent'), + onKeys: makeErrorIfMissing('can.onKeys', 'can-reflect: can not observe an onKeys event'), + onKeysAdded: makeErrorIfMissing('can.onKeysAdded', 'can-reflect: can not observe an onKeysAdded event'), + onKeysRemoved: makeErrorIfMissing('can.onKeysRemoved', 'can-reflect: can not unobserve an onKeysRemoved event'), + getKeyDependencies: makeErrorIfMissing('can.getKeyDependencies', 'can-reflect: can not determine dependencies'), + keyHasDependencies: makeErrorIfMissing('can.keyHasDependencies', 'can-reflect: can not determine if this has key dependencies'), + onValue: makeErrorIfMissing('can.onValue', 'can-reflect: can not observe value change'), + offValue: makeErrorIfMissing('can.offValue', 'can-reflect: can not unobserve value change'), + getValueDependencies: makeErrorIfMissing('can.getValueDependencies', 'can-reflect: can not determine dependencies'), + valueHasDependencies: makeErrorIfMissing('can.valueHasDependencies', 'can-reflect: can not determine if value has dependencies'), + onEvent: function (obj, eventName, callback) { + if (obj) { + var onEvent = obj[canSymbol.for('can.onEvent')]; + if (onEvent !== undefined) { + return onEvent.call(obj, eventName, callback); + } else if (obj.addEventListener) { + obj.addEventListener(eventName, callback); + } + } + }, + offEvent: function (obj, eventName, callback) { + if (obj) { + var offEvent = obj[canSymbol.for('can.offEvent')]; + if (offEvent !== undefined) { + return offEvent.call(obj, eventName, callback); + } else if (obj.removeEventListener) { + obj.removeEventListener(eventName, callback); + } + } + } + }; +}); +/*can-reflect@1.0.0-pre.2#reflections/shape/shape*/ +define('can-reflect/reflections/shape/shape', function (require, exports, module) { + var canSymbol = require('can-symbol'); + var getSetReflections = require('../get-set/get-set'); + var typeReflections = require('../type/type'); + var shapeReflections = { + each: function (obj, callback, context) { + if (typeReflections.isIteratorLike(obj) || typeReflections.isMoreListLikeThanMapLike(obj)) { + return this.eachIndex(obj, callback, context); + } else { + return this.eachKey(obj, callback, context); + } + }, + eachIndex: function (list, callback, context) { + var iter, iterator = list[canSymbol.iterator]; + if (Array.isArray(list)) { + } else if (typeReflections.isIteratorLike(list)) { + iter = list; + } else if (iterator) { + iter = iterator.call(list); + } + if (iter) { + var res, index = 0; + while (!(res = iter.next()).done) { + if (callback.call(context || list, res.value, index++, list) === false) { + break; + } + } + } else { + for (var i = 0, len = list.length; i < len; i++) { + var item = list[i]; + if (callback.call(context || item, item, i, list) === false) { + break; + } + } + } + return list; + }, + toArray: function (obj) { + var arr = []; + this.each(obj, function (value) { + arr.push(value); + }); + return arr; + }, + eachKey: function (obj, callback, context) { + var enumerableKeys = this.getOwnEnumerableKeys(obj); + return this.eachIndex(enumerableKeys, function (key) { + var value = getSetReflections.getKeyValue(obj, key); + return callback.call(context || obj, value, key, obj); + }); + }, + 'hasOwnKey': function (obj, key) { + var hasOwnKey = obj[canSymbol.for('can.hasOwnKey')]; + if (hasOwnKey) { + return hasOwnKey.call(obj, key); + } + var getOwnKeys = obj[canSymbol.for('can.getOwnKeys')]; + if (getOwnKeys) { + var found = false; + this.eachIndex(getOwnKeys.call(obj), function (objKey) { + if (objKey === key) { + found = true; + return false; + } + }); + return found; + } + return obj.hasOwnProperty(key); + }, + getOwnEnumerableKeys: function (obj) { + var getOwnEnumerableKeys = obj[canSymbol.for('can.getOwnEnumerableKeys')]; + if (getOwnEnumerableKeys) { + return getOwnEnumerableKeys.call(obj); + } + if (obj[canSymbol.for('can.getOwnKeys')] && obj[canSymbol.for('can.getOwnKeyDescriptor')]) { + var keys = []; + this.eachIndex(this.getOwnKeys(obj), function (key) { + var descriptor = this.getOwnKeyDescriptor(obj, key); + if (descriptor.enumerable) { + keys.push(key); + } + }, this); + return keys; + } else { + return Object.keys(obj); + } + }, + getOwnKeys: function (obj) { + var getOwnKeys = obj[canSymbol.for('can.getOwnKeys')]; + if (getOwnKeys) { + return getOwnKeys.call(obj); + } else { + return Object.getOwnPropertyNames(obj); + } + }, + getOwnKeyDescriptor: function (obj, key) { + var getOwnKeyDescriptor = obj[canSymbol.for('can.getOwnKeyDescriptor')]; + if (getOwnKeyDescriptor) { + return getOwnKeyDescriptor.call(obj, key); + } else { + return Object.getOwnPropertyDescriptor(obj, key); + } + }, + 'in': function () { + }, + getAllEnumerableKeys: function () { + }, + getAllKeys: function () { + } + }; + shapeReflections.keys = shapeReflections.getOwnEnumerableKeys; + module.exports = shapeReflections; +}); +/*can-reflect@1.0.0-pre.2#can-reflect*/ +define('can-reflect', function (require, exports, module) { + var functionReflections = require('./reflections/call/call'); + var getSet = require('./reflections/get-set/get-set'); + var observe = require('./reflections/observe/observe'); + var shape = require('./reflections/shape/shape'); + var type = require('./reflections/type/type'); + var reflect = {}; + [ + functionReflections, + getSet, + observe, + shape, + type + ].forEach(function (reflections) { + for (var prop in reflections) { + reflect[prop] = reflections[prop]; + } + }); + module.exports = reflect; +}); +/*can-util@3.9.0-pre.4#js/log/log*/ +define('set-can-util/js/log/log', function (require, exports, module) { + 'use strict'; + exports.warnTimeout = 5000; + exports.logLevel = 0; + exports.warn = function (out) { + var ll = this.logLevel; + if (ll < 2) { + Array.prototype.unshift.call(arguments, 'WARN:'); + if (typeof console !== 'undefined' && console.warn) { + this._logger('warn', Array.prototype.slice.call(arguments)); + } else if (typeof console !== 'undefined' && console.log) { + this._logger('log', Array.prototype.slice.call(arguments)); + } else if (window && window.opera && window.opera.postError) { + window.opera.postError('CanJS WARNING: ' + out); + } + } + }; + exports.log = function (out) { + var ll = this.logLevel; + if (ll < 1) { + if (typeof console !== 'undefined' && console.log) { + Array.prototype.unshift.call(arguments, 'INFO:'); + this._logger('log', Array.prototype.slice.call(arguments)); + } else if (window && window.opera && window.opera.postError) { + window.opera.postError('CanJS INFO: ' + out); + } + } + }; + exports.error = function (out) { + var ll = this.logLevel; + if (ll < 1) { + if (typeof console !== 'undefined' && console.error) { + Array.prototype.unshift.call(arguments, 'ERROR:'); + this._logger('error', Array.prototype.slice.call(arguments)); + } else if (window && window.opera && window.opera.postError) { + window.opera.postError('ERROR: ' + out); + } + } + }; + exports._logger = function (type, arr) { + try { + console[type].apply(console, arr); + } catch (e) { + console[type](arr); + } + }; +}); +/*can-util@3.9.0-pre.4#js/dev/dev*/ +define('set-can-util/js/dev/dev', function (require, exports, module) { + 'use strict'; + var canLog = require('set-can-util/js/log/log'); + module.exports = { + warnTimeout: 5000, + logLevel: 0, + stringify: function (value) { + var flagUndefined = function flagUndefined(key, value) { + return value === undefined ? '/* void(undefined) */' : value; + }; + return JSON.stringify(value, flagUndefined, ' ').replace(/"\/\* void\(undefined\) \*\/"/g, 'undefined'); + }, + warn: function () { + }, + log: function () { + }, + error: function () { + }, + _logger: canLog._logger + }; +}); +/*can-types@1.1.0-pre.2#can-types*/ +define('can-types', function (require, exports, module) { + var namespace = require('can-namespace'); + var canReflect = require('can-reflect'); + var canSymbol = require('can-symbol'); + var dev = require('set-can-util/js/dev/dev'); + var types = { + isMapLike: function (obj) { + return canReflect.isObservableLike(obj) && canReflect.isMapLike(obj); + }, + isListLike: function (obj) { + return canReflect.isObservableLike(obj) && canReflect.isListLike(obj); + }, + isPromise: function (obj) { + return canReflect.isPromise(obj); + }, + isConstructor: function (func) { + return canReflect.isConstructorLike(func); + }, + isCallableForValue: function (obj) { + return obj && obj[canSymbol.for('getValue')]; + }, + isCompute: function (obj) { + return obj && obj.isComputed; + }, + get iterator() { + return canSymbol.iterator || canSymbol.for('iterator'); + }, + DefaultMap: null, + DefaultList: null, + queueTask: function (task) { + var args = task[2] || []; + task[0].apply(task[1], args); + }, + wrapElement: function (element) { + return element; + }, + unwrapElement: function (element) { + return element; + } + }; + if (namespace.types) { + throw new Error('You can\'t have two versions of can-types, check your dependencies'); + } else { + module.exports = namespace.types = types; + } +}); +/*can-util@3.9.0-pre.4#js/is-iterable/is-iterable*/ +define('set-can-util/js/is-iterable/is-iterable', function (require, exports, module) { + 'use strict'; + var types = require('can-types'); + module.exports = function (obj) { + return obj && !!obj[types.iterator]; + }; +}); +/*can-util@3.9.0-pre.4#js/each/each*/ +define('set-can-util/js/each/each', function (require, exports, module) { + 'use strict'; + var isArrayLike = require('set-can-util/js/is-array-like/is-array-like'); + var has = Object.prototype.hasOwnProperty; + var isIterable = require('set-can-util/js/is-iterable/is-iterable'); + var types = require('can-types'); + function each(elements, callback, context) { + var i = 0, key, len, item; + if (elements) { + if (isArrayLike(elements)) { + for (len = elements.length; i < len; i++) { + item = elements[i]; + if (callback.call(context || item, item, i, elements) === false) { + break; + } + } + } else if (isIterable(elements)) { + var iter = elements[types.iterator](); + var res, value; + while (!(res = iter.next()).done) { + value = res.value; + callback.call(context || elements, Array.isArray(value) ? value[1] : value, value[0]); + } + } else if (typeof elements === 'object') { + for (key in elements) { + if (has.call(elements, key) && callback.call(context || elements[key], elements[key], key, elements) === false) { + break; + } + } + } + } + return elements; + } + module.exports = each; +}); +/*can-util@3.9.0-pre.4#js/last/last*/ +define('set-can-util/js/last/last', function (require, exports, module) { + 'use strict'; + module.exports = function (arr) { + return arr && arr[arr.length - 1]; + }; +}); +/*can-set@1.3.0-pre.0#src/helpers*/ +define('can-set/src/helpers', function (require, exports, module) { + var assign = require('set-can-util/js/assign/assign'); + var each = require('set-can-util/js/each/each'); + var last = require('set-can-util/js/last/last'); + var IgnoreType = function () { + }; + var helpers; + module.exports = helpers = { + eachInUnique: function (a, acb, b, bcb, defaultReturn) { + var bCopy = assign({}, b), res; + for (var prop in a) { + res = acb(a[prop], b[prop], a, b, prop); + if (res !== undefined) { + return res; + } + delete bCopy[prop]; + } + for (prop in bCopy) { + res = bcb(undefined, b[prop], a, b, prop); + if (res !== undefined) { + return res; + } + } + return defaultReturn; + }, + doubleLoop: function (arr, callbacks) { + if (typeof callbacks === 'function') { + callbacks = { iterate: callbacks }; + } + var i = 0; + while (i < arr.length) { + if (callbacks.start) { + callbacks.start(arr[i]); + } + var j = i + 1; + while (j < arr.length) { + if (callbacks.iterate(arr[j], j, arr[i], i) === false) { + arr.splice(j, 1); + } else { + j++; + } + } + if (callbacks.end) { + callbacks.end(arr[i]); + } + i++; + } + }, + identityMap: function (arr) { + var map = {}; + each(arr, function (value) { + map[value] = 1; + }); + return map; + }, + arrayUnionIntersectionDifference: function (arr1, arr2) { + var map = {}; + var intersection = []; + var union = []; + var difference = arr1.slice(0); + each(arr1, function (value) { + map[value] = true; + union.push(value); + }); + each(arr2, function (value) { + if (map[value]) { + intersection.push(value); + var index = helpers.indexOf.call(difference, value); + if (index !== -1) { + difference.splice(index, 1); + } + } else { + union.push(value); + } + }); + return { + intersection: intersection, + union: union, + difference: difference + }; + }, + arraySame: function (arr1, arr2) { + if (arr1.length !== arr2.length) { + return false; + } + var map = helpers.identityMap(arr1); + for (var i = 0; i < arr2.length; i++) { + var val = map[arr2[i]]; + if (!val) { + return false; + } else if (val > 1) { + return false; + } else { + map[arr2[i]]++; + } + } + return true; + }, + indexOf: Array.prototype.indexOf || function (item) { + for (var i = 0, thisLen = this.length; i < thisLen; i++) { + if (this[i] === item) { + return i; + } + } + return -1; + }, + map: Array.prototype.map || function (cb) { + var out = []; + for (var i = 0, len = this.length; i < len; i++) { + out.push(cb(this[i], i, this)); + } + return out; + }, + filter: Array.prototype.filter || function (cb) { + var out = []; + for (var i = 0, len = this.length; i < len; i++) { + if (cb(this[i], i, this)) { + out.push(this[i]); + } + } + return out; + }, + ignoreType: new IgnoreType(), + firstProp: function (set) { + for (var prop in set) { + return prop; + } + }, + index: function (compare, items, props) { + if (!items || !items.length) { + return undefined; + } + if (compare(props, items[0]) === -1) { + return 0; + } else if (compare(props, last(items)) === 1) { + return items.length; + } + var low = 0, high = items.length; + while (low < high) { + var mid = low + high >>> 1, item = items[mid], computed = compare(props, item); + if (computed === -1) { + high = mid; + } else { + low = mid + 1; + } + } + return high; + }, + defaultSort: function (sortPropValue, item1, item2) { + var parts = sortPropValue.split(' '); + var sortProp = parts[0]; + var item1Value = item1[sortProp]; + var item2Value = item2[sortProp]; + var temp; + var desc = parts[1] || ''; + desc = desc.toLowerCase() === 'desc'; + if (desc) { + temp = item1Value; + item1Value = item2Value; + item2Value = temp; + } + if (item1Value < item2Value) { + return -1; + } + if (item1Value > item2Value) { + return 1; + } + return 0; + } + }; +}); +/*can-set@1.3.0-pre.0#src/clause*/ +define('can-set/src/clause', function (require, exports, module) { + var assign = require('set-can-util/js/assign/assign'); + var each = require('set-can-util/js/each/each'); + var clause = {}; + module.exports = clause; + clause.TYPES = [ + 'where', + 'order', + 'paginate', + 'id' + ]; + each(clause.TYPES, function (type) { + var className = type.charAt(0).toUpperCase() + type.substr(1); + clause[className] = function (compare) { + assign(this, compare); + }; + clause[className].type = type; + }); +}); +/*can-util@3.9.0-pre.4#js/make-array/make-array*/ +define('set-can-util/js/make-array/make-array', function (require, exports, module) { + 'use strict'; + var each = require('set-can-util/js/each/each'); + var isArrayLike = require('set-can-util/js/is-array-like/is-array-like'); + function makeArray(element) { + var ret = []; + if (isArrayLike(element)) { + each(element, function (a, i) { + ret[i] = a; + }); + } else if (element === 0 || element) { + ret.push(element); + } + return ret; + } + module.exports = makeArray; +}); +/*can-set@1.3.0-pre.0#src/compare*/ +define('can-set/src/compare', function (require, exports, module) { + var h = require('can-set/src/helpers'); + var assign = require('set-can-util/js/assign/assign'); + var each = require('set-can-util/js/each/each'); + var makeArray = require('set-can-util/js/make-array/make-array'); + var compareHelpers; + var loop = function (a, b, aParent, bParent, prop, compares, options) { + var checks = options.checks; + for (var i = 0; i < checks.length; i++) { + var res = checks[i](a, b, aParent, bParent, prop, compares || {}, options); + if (res !== undefined) { + return res; + } + } + return options['default']; + }; + var addIntersectedPropertyToResult = function (a, b, aParent, bParent, prop, compares, options) { + var subsetCheck; + if (!(prop in aParent)) { + subsetCheck = 'subsetB'; + } else if (prop in bParent) { + return false; + } + if (!(prop in bParent)) { + subsetCheck = 'subsetA'; + } + if (subsetCheck === 'subsetB') { + options.result[prop] = b; + } else { + options.result[prop] = a; + } + return undefined; + }; + var addToResult = function (fn, name) { + return function (a, b, aParent, bParent, prop, compares, options) { + var res = fn.apply(this, arguments); + if (res === true) { + if (prop !== undefined && !(prop in options.result)) { + options.result[prop] = a; + } + return true; + } else { + return res; + } + }; + }; + module.exports = compareHelpers = { + equal: function (a, b, aParent, bParent, prop, compares, options) { + options.checks = [ + compareHelpers.equalComparesType, + compareHelpers.equalBasicTypes, + compareHelpers.equalArrayLike, + compareHelpers.equalObject + ]; + options['default'] = false; + return loop(a, b, aParent, bParent, prop, compares, options); + }, + equalComparesType: function (a, b, aParent, bParent, prop, compares, options) { + if (typeof compares === 'function') { + var compareResult = compares(a, b, aParent, bParent, prop, options); + if (typeof compareResult === 'boolean') { + return compareResult; + } else if (compareResult && typeof compareResult === 'object') { + if ('intersection' in compareResult && !('difference' in compareResult)) { + var reverseResult = compares(b, a, bParent, aParent, prop, options); + return 'intersection' in reverseResult && !('difference' in reverseResult); + } + return false; + } + return compareResult; + } + }, + equalBasicTypes: function (a, b, aParent, bParent, prop, compares, options) { + if (a === null || b === null) { + return a === b; + } + if (a instanceof Date && b instanceof Date) { + return a.getTime() === b.getTime(); + } + if (options.deep === -1) { + return typeof a === 'object' || a === b; + } + if (typeof a !== typeof b || Array.isArray(a) !== Array.isArray(b)) { + return false; + } + if (a === b) { + return true; + } + }, + equalArrayLike: function (a, b, aParent, bParent, prop, compares, options) { + if (Array.isArray(a) && Array.isArray(b)) { + if (a.length !== b.length) { + return false; + } + for (var i = 0; i < a.length; i++) { + var compare = compares[i] === undefined ? compares['*'] : compares[i]; + if (!loop(a[i], b[i], a, b, i, compare, options)) { + return false; + } + } + return true; + } + }, + equalObject: function (a, b, aParent, bParent, parentProp, compares, options) { + var aType = typeof a; + if (aType === 'object' || aType === 'function') { + var bCopy = assign({}, b); + if (options.deep === false) { + options.deep = -1; + } + for (var prop in a) { + var compare = compares[prop] === undefined ? compares['*'] : compares[prop]; + if (!loop(a[prop], b[prop], a, b, prop, compare, options)) { + return false; + } + delete bCopy[prop]; + } + for (prop in bCopy) { + if (compares[prop] === undefined || !loop(undefined, b[prop], a, b, prop, compares[prop], options)) { + return false; + } + } + return true; + } + }, + subset: function (a, b, aParent, bParent, prop, compares, options) { + options.checks = [ + compareHelpers.subsetComparesType, + compareHelpers.equalBasicTypes, + compareHelpers.equalArrayLike, + compareHelpers.subsetObject + ]; + options.getSubsets = []; + options['default'] = false; + return loop(a, b, aParent, bParent, prop, compares, options); + }, + subsetObject: function (a, b, aParent, bParent, parentProp, compares, options) { + var aType = typeof a; + if (aType === 'object' || aType === 'function') { + return h.eachInUnique(a, function (a, b, aParent, bParent, prop) { + var compare = compares[prop] === undefined ? compares['*'] : compares[prop]; + if (!loop(a, b, aParent, bParent, prop, compare, options) && prop in bParent) { + return false; + } + }, b, function (a, b, aParent, bParent, prop) { + var compare = compares[prop] === undefined ? compares['*'] : compares[prop]; + if (!loop(a, b, aParent, bParent, prop, compare, options)) { + return false; + } + }, true); + } + }, + subsetComparesType: function (a, b, aParent, bParent, prop, compares, options) { + if (typeof compares === 'function') { + var compareResult = compares(a, b, aParent, bParent, prop, options); + if (typeof compareResult === 'boolean') { + return compareResult; + } else if (compareResult && typeof compareResult === 'object') { + if (compareResult.getSubset) { + if (h.indexOf.call(options.getSubsets, compareResult.getSubset) === -1) { + options.getSubsets.push(compareResult.getSubset); + } + } + if (compareResult.intersection === h.ignoreType || compareResult.difference === h.ignoreType) { + return true; + } + if ('intersection' in compareResult && !('difference' in compareResult)) { + var reverseResult = compares(b, a, bParent, aParent, prop, options); + return 'intersection' in reverseResult; + } + return false; + } + return compareResult; + } + }, + properSupersetObject: function (a, b, aParent, bParent, parentProp, compares, options) { + var bType = typeof b; + var hasAdditionalProp = false; + if (bType === 'object' || bType === 'function') { + var aCopy = assign({}, a); + if (options.deep === false) { + options.deep = -1; + } + for (var prop in b) { + var compare = compares[prop] === undefined ? compares['*'] : compares[prop]; + var compareResult = loop(a[prop], b[prop], a, b, prop, compare, options); + if (compareResult === h.ignoreType) { + } else if (!(prop in a) || options.performedDifference) { + hasAdditionalProp = true; + } else if (!compareResult) { + return false; + } + delete aCopy[prop]; + } + for (prop in aCopy) { + if (compares[prop] === undefined || !loop(a[prop], undefined, a, b, prop, compares[prop], options)) { + return false; + } + } + return hasAdditionalProp; + } + }, + properSubsetComparesType: function (a, b, aParent, bParent, prop, compares, options) { + if (typeof compares === 'function') { + var compareResult = compares(a, b, aParent, bParent, prop, options); + if (typeof compareResult === 'boolean') { + return compareResult; + } else if (compareResult && typeof compareResult === 'object') { + if ('intersection' in compareResult && !('difference' in compareResult)) { + var reverseResult = compares(b, a, bParent, aParent, prop, options); + return 'intersection' in reverseResult && 'difference' in reverseResult; + } + return false; + } + return compareResult; + } + }, + difference: function (a, b, aParent, bParent, prop, compares, options) { + options.result = {}; + options.performedDifference = 0; + options.checks = [ + compareHelpers.differenceComparesType, + addToResult(compareHelpers.equalBasicTypes, 'equalBasicTypes'), + addToResult(compareHelpers.equalArrayLike, 'equalArrayLike'), + addToResult(compareHelpers.properSupersetObject, 'properSubsetObject') + ]; + options['default'] = true; + var res = loop(a, b, aParent, bParent, prop, compares, options); + if (res === true && options.performedDifference) { + return options.result; + } + return res; + }, + differenceComparesType: function (a, b, aParent, bParent, prop, compares, options) { + if (typeof compares === 'function') { + var compareResult = compares(a, b, aParent, bParent, prop, options); + if (typeof compareResult === 'boolean') { + if (compareResult === true) { + options.result[prop] = a; + return true; + } else { + return compareResult; + } + } else if (compareResult && typeof compareResult === 'object') { + if ('difference' in compareResult) { + if (compareResult.difference === h.ignoreType) { + return h.ignoreType; + } else if (compareResult.difference != null) { + options.result[prop] = compareResult.difference; + options.performedDifference++; + return true; + } else { + return true; + } + } else { + if (compareHelpers.equalComparesType.apply(this, arguments)) { + options.performedDifference++; + options.result[prop] = compareResult.union; + } else { + return false; + } + } + } + } + }, + union: function (a, b, aParent, bParent, prop, compares, options) { + options.result = {}; + options.performedUnion = 0; + options.checks = [ + compareHelpers.unionComparesType, + addToResult(compareHelpers.equalBasicTypes, 'equalBasicTypes'), + addToResult(compareHelpers.unionArrayLike, 'unionArrayLike'), + addToResult(compareHelpers.unionObject, 'unionObject') + ]; + options.getUnions = []; + options['default'] = false; + var res = loop(a, b, aParent, bParent, prop, compares, options); + if (res === true) { + return options.result; + } + return false; + }, + unionComparesType: function (a, b, aParent, bParent, prop, compares, options) { + if (typeof compares === 'function') { + var compareResult = compares(a, b, aParent, bParent, prop, options); + if (typeof compareResult === 'boolean') { + if (compareResult === true) { + options.result[prop] = a; + return true; + } else { + return compareResult; + } + } else if (compareResult && typeof compareResult === 'object') { + if (compareResult.getUnion) { + if (h.indexOf.call(options.getUnions, compareResult.getUnion) === -1) { + options.getUnions.push(compareResult.getUnion); + } + } + if ('union' in compareResult) { + if (compareResult.union === h.ignoreType) { + return compareResult.union; + } + if (compareResult.union !== undefined) { + options.result[prop] = compareResult.union; + } + options.performedUnion++; + return true; + } + } + } + }, + unionObject: function (a, b, aParent, bParent, prop, compares, options) { + var subsetCompare = function (a, b, aParent, bParent, prop) { + var compare = compares[prop] === undefined ? compares['*'] : compares[prop]; + if (!loop(a, b, aParent, bParent, prop, compare, options)) { + var subsetCheck; + if (!(prop in aParent)) { + subsetCheck = 'subsetB'; + } + if (!(prop in bParent)) { + subsetCheck = 'subsetA'; + } + if (subsetCheck) { + if (!options.subset) { + options.subset = subsetCheck; + } + return options.subset === subsetCheck ? undefined : false; + } + return false; + } + }; + var aType = typeof a; + if (aType === 'object' || aType === 'function') { + return h.eachInUnique(a, subsetCompare, b, subsetCompare, true); + } + }, + unionArrayLike: function (a, b, aParent, bParent, prop, compares, options) { + if (Array.isArray(a) && Array.isArray(b)) { + var combined = makeArray(a).concat(makeArray(b)); + h.doubleLoop(combined, function (item, j, cur, i) { + var res = !compareHelpers.equal(cur, item, aParent, bParent, undefined, compares['*'], { 'default': false }); + return res; + }); + options.result[prop] = combined; + return true; + } + }, + count: function (a, b, aParent, bParent, prop, compares, options) { + options.checks = [ + compareHelpers.countComparesType, + compareHelpers.equalBasicTypes, + compareHelpers.equalArrayLike, + compareHelpers.loopObject + ]; + options['default'] = false; + loop(a, b, aParent, bParent, prop, compares, options); + if (typeof options.count === 'number') { + return options.count; + } + return Infinity; + }, + countComparesType: function (a, b, aParent, bParent, prop, compares, options) { + if (typeof compares === 'function') { + var compareResult = compares(a, b, aParent, bParent, prop, options); + if (typeof compareResult === 'boolean') { + return true; + } else if (compareResult && typeof compareResult === 'object') { + if (typeof compareResult.count === 'number') { + if (!('count' in options) || compareResult.count === options.count) { + options.count = compareResult.count; + } else { + options.count = Infinity; + } + } + return true; + } + } + }, + loopObject: function (a, b, aParent, bParent, prop, compares, options) { + var aType = typeof a; + if (aType === 'object' || aType === 'function') { + each(a, function (aValue, prop) { + var compare = compares[prop] === undefined ? compares['*'] : compares[prop]; + loop(aValue, b[prop], a, b, prop, compare, options); + }); + return true; + } + }, + intersection: function (a, b, aParent, bParent, prop, compares, options) { + options.result = {}; + options.performedIntersection = 0; + options.checks = [ + compareHelpers.intersectionComparesType, + addToResult(compareHelpers.equalBasicTypes, 'equalBasicTypes'), + addToResult(compareHelpers.intersectionArrayLike, 'intersectionArrayLike'), + compareHelpers.intersectionObject + ]; + options['default'] = false; + var res = loop(a, b, aParent, bParent, prop, compares, options); + if (res === true) { + return options.result; + } + return false; + }, + intersectionComparesType: function (a, b, aParent, bParent, prop, compares, options) { + if (typeof compares === 'function') { + var compareResult = compares(a, b, aParent, bParent, prop, options); + if (typeof compareResult === 'boolean') { + if (compareResult === true) { + options.result[prop] = a; + return true; + } else { + return compareResult; + } + } else if (compareResult && typeof compareResult === 'object') { + if ('intersection' in compareResult) { + if (compareResult.intersection !== undefined) { + options.result[prop] = compareResult.intersection; + } + options.performedIntersection++; + return true; + } + } + } + }, + intersectionObject: function (a, b, aParent, bParent, prop, compares, options) { + var subsetCompare = function (a, b, aParent, bParent, prop) { + var compare = compares[prop] === undefined ? compares['*'] : compares[prop]; + if (!loop(a, b, aParent, bParent, prop, compare, options)) { + return addIntersectedPropertyToResult(a, b, aParent, bParent, prop, compares, options); + } + }; + var aType = typeof a; + if (aType === 'object' || aType === 'function') { + return h.eachInUnique(a, subsetCompare, b, subsetCompare, true); + } + }, + intersectionArrayLike: function (a, b, aParent, bParent, prop, compares, options) { + if (Array.isArray(a) && Array.isArray(b)) { + var intersection = []; + each(makeArray(a), function (cur) { + for (var i = 0; i < b.length; i++) { + if (compareHelpers.equal(cur, b[i], aParent, bParent, undefined, compares['*'], { 'default': false })) { + intersection.push(cur); + break; + } + } + }); + options.result[prop] = intersection; + return true; + } + } + }; +}); +/*can-set@1.3.0-pre.0#src/get*/ +define('can-set/src/get', function (require, exports, module) { + var compare = require('can-set/src/compare'); + var h = require('can-set/src/helpers'); + var each = require('set-can-util/js/each/each'); + var filterData = function (data, clause, props) { + return h.filter.call(data, function (item) { + var isSubset = compare.subset(item, clause, undefined, undefined, undefined, props, {}); + return isSubset; + }); + }; + module.exports = { + subsetData: function (a, b, bData, algebra) { + var aClauseProps = algebra.getClauseProperties(a); + var bClauseProps = algebra.getClauseProperties(b); + var options = {}; + var aData = filterData(bData, aClauseProps.where, algebra.clauses.where); + if (aData.length && (aClauseProps.enabled.order || bClauseProps.enabled.order)) { + options = {}; + var propName = h.firstProp(aClauseProps.order), compareOrder = algebra.clauses.order[propName]; + aData = aData.sort(function (aItem, bItem) { + return compareOrder(a[propName], aItem, bItem); + }); + } + if (aData.length && (aClauseProps.enabled.paginate || bClauseProps.enabled.paginate)) { + options = {}; + compare.subset(aClauseProps.paginate, bClauseProps.paginate, undefined, undefined, undefined, algebra.clauses.paginate, options); + each(options.getSubsets, function (filter) { + aData = filter(a, b, aData, algebra, options); + }); + } + return aData; + } + }; +}); +/*can-util@3.9.0-pre.4#js/is-empty-object/is-empty-object*/ +define('set-can-util/js/is-empty-object/is-empty-object', function (require, exports, module) { + 'use strict'; + module.exports = function (obj) { + for (var prop in obj) { + return false; + } + return true; + }; +}); +/*can-set@1.3.0-pre.0#src/set-core*/ +define('can-set/src/set-core', function (require, exports, module) { + var h = require('can-set/src/helpers'); + var clause = require('can-set/src/clause'); + var compare = require('can-set/src/compare'); + var get = require('can-set/src/get'); + var assign = require('set-can-util/js/assign/assign'); + var each = require('set-can-util/js/each/each'); + var makeArray = require('set-can-util/js/make-array/make-array'); + var isEmptyObject = require('set-can-util/js/is-empty-object/is-empty-object'); + function Translate(clause, options) { + if (typeof options === 'string') { + var path = options; + options = { + fromSet: function (set, setRemainder) { + return set[path] || {}; + }, + toSet: function (set, wheres) { + set[path] = wheres; + return set; + } + }; + } + this.clause = clause; + assign(this, options); + } + var Algebra = function () { + var clauses = this.clauses = { + where: {}, + order: {}, + paginate: {}, + id: {} + }; + this.translators = { + where: new Translate('where', { + fromSet: function (set, setRemainder) { + return setRemainder; + }, + toSet: function (set, wheres) { + return assign(set, wheres); + } + }) + }; + var self = this; + each(arguments, function (arg) { + if (arg) { + if (arg instanceof Translate) { + self.translators[arg.clause] = arg; + } else { + assign(clauses[arg.constructor.type || 'where'], arg); + } + } + }); + }; + Algebra.make = function (compare, count) { + if (compare instanceof Algebra) { + return compare; + } else { + return new Algebra(compare, count); + } + }; + assign(Algebra.prototype, { + getClauseProperties: function (set, options) { + options = options || {}; + var setClone = assign({}, set); + var clauses = this.clauses; + var checkClauses = [ + 'order', + 'paginate', + 'id' + ]; + var clauseProps = { + enabled: { + where: true, + order: false, + paginate: false, + id: false + } + }; + if (options.omitClauses) { + checkClauses = h.arrayUnionIntersectionDifference(checkClauses, options.omitClauses).difference; + } + each(checkClauses, function (clauseName) { + var valuesForClause = {}; + var prop; + for (prop in clauses[clauseName]) { + if (prop in setClone) { + valuesForClause[prop] = setClone[prop]; + delete setClone[prop]; + } + } + clauseProps[clauseName] = valuesForClause; + clauseProps.enabled[clauseName] = !isEmptyObject(valuesForClause); + }); + clauseProps.where = options.isProperties ? setClone : this.translators.where.fromSet(set, setClone); + return clauseProps; + }, + getDifferentClauseTypes: function (aClauses, bClauses) { + var self = this; + var differentTypes = []; + each(clause.TYPES, function (type) { + if (!self.evaluateOperator(compare.equal, aClauses[type], bClauses[type], { isProperties: true }, { isProperties: true })) { + differentTypes.push(type); + } + }); + return differentTypes; + }, + updateSet: function (set, clause, result, useSet) { + if (result && typeof result === 'object' && useSet !== false) { + if (this.translators[clause]) { + set = this.translators.where.toSet(set, result); + } else { + set = assign(set, result); + } + return true; + } else if (result) { + return useSet === undefined ? undefined : false; + } else { + return false; + } + }, + evaluateOperator: function (operator, a, b, aOptions, bOptions, evaluateOptions) { + aOptions = aOptions || {}; + bOptions = bOptions || {}; + evaluateOptions = assign({ + evaluateWhere: operator, + evaluatePaginate: operator, + evaluateOrder: operator, + shouldEvaluatePaginate: function (aClauseProps, bClauseProps) { + return aClauseProps.enabled.paginate || bClauseProps.enabled.paginate; + }, + shouldEvaluateOrder: function (aClauseProps, bClauseProps) { + return aClauseProps.enabled.order && compare.equal(aClauseProps.order, bClauseProps.order, undefined, undefined, undefined, {}, {}); + } + }, evaluateOptions || {}); + var aClauseProps = this.getClauseProperties(a, aOptions), bClauseProps = this.getClauseProperties(b, bOptions), set = {}, useSet; + var result = evaluateOptions.evaluateWhere(aClauseProps.where, bClauseProps.where, undefined, undefined, undefined, this.clauses.where, {}); + useSet = this.updateSet(set, 'where', result, useSet); + if (result && evaluateOptions.shouldEvaluatePaginate(aClauseProps, bClauseProps)) { + if (evaluateOptions.shouldEvaluateOrder(aClauseProps, bClauseProps)) { + result = evaluateOptions.evaluateOrder(aClauseProps.order, bClauseProps.order, undefined, undefined, undefined, {}, {}); + useSet = this.updateSet(set, 'order', result, useSet); + } + if (result) { + result = evaluateOptions.evaluatePaginate(aClauseProps.paginate, bClauseProps.paginate, undefined, undefined, undefined, this.clauses.paginate, {}); + useSet = this.updateSet(set, 'paginate', result, useSet); + } + } else if (result && evaluateOptions.shouldEvaluateOrder(aClauseProps, bClauseProps)) { + result = operator(aClauseProps.order, bClauseProps.order, undefined, undefined, undefined, {}, {}); + useSet = this.updateSet(set, 'order', result, useSet); + } + return result && useSet ? set : result; + }, + equal: function (a, b) { + return this.evaluateOperator(compare.equal, a, b); + }, + subset: function (a, b) { + var aClauseProps = this.getClauseProperties(a); + var bClauseProps = this.getClauseProperties(b); + var compatibleSort = true; + var result; + if (bClauseProps.enabled.paginate && (aClauseProps.enabled.order || bClauseProps.enabled.order)) { + compatibleSort = compare.equal(aClauseProps.order, bClauseProps.order, undefined, undefined, undefined, {}, {}); + } + if (!compatibleSort) { + result = false; + } else { + result = this.evaluateOperator(compare.subset, a, b); + } + return result; + }, + properSubset: function (a, b) { + return this.subset(a, b) && !this.equal(a, b); + }, + difference: function (a, b) { + var aClauseProps = this.getClauseProperties(a); + var bClauseProps = this.getClauseProperties(b); + var differentClauses = this.getDifferentClauseTypes(aClauseProps, bClauseProps); + var result; + switch (differentClauses.length) { + case 0: { + result = false; + break; + } + case 1: { + var clause = differentClauses[0]; + result = compare.difference(aClauseProps[clause], bClauseProps[clause], undefined, undefined, undefined, this.clauses[clause], {}); + if (this.translators[clause] && typeof result === 'object') { + result = this.translators[clause].toSet({}, result); + } + break; + } + } + return result; + }, + union: function (a, b) { + return this.evaluateOperator(compare.union, a, b); + }, + intersection: function (a, b) { + return this.evaluateOperator(compare.intersection, a, b); + }, + count: function (set) { + return this.evaluateOperator(compare.count, set, {}); + }, + has: function (set, props) { + var aClauseProps = this.getClauseProperties(set); + var propsClauseProps = this.getClauseProperties(props, { isProperties: true }); + var compatibleSort = true; + var result; + if ((propsClauseProps.enabled.paginate || aClauseProps.enabled.paginate) && (propsClauseProps.enabled.order || aClauseProps.enabled.order)) { + compatibleSort = compare.equal(propsClauseProps.order, aClauseProps.order, undefined, undefined, undefined, {}, {}); + } + if (!compatibleSort) { + result = false; + } else { + result = this.evaluateOperator(compare.subset, props, set, { isProperties: true }, undefined); + } + return result; + }, + index: function (set, items, item) { + var aClauseProps = this.getClauseProperties(set); + var propName = h.firstProp(aClauseProps.order), compare, orderValue; + if (propName) { + compare = this.clauses.order[propName]; + orderValue = set[propName]; + return h.index(function (itemA, itemB) { + return compare(orderValue, itemA, itemB); + }, items, item); + } + propName = h.firstProp(this.clauses.id); + if (propName) { + compare = h.defaultSort; + orderValue = propName; + return h.index(function (itemA, itemB) { + return compare(orderValue, itemA, itemB); + }, items, item); + } + return; + }, + getSubset: function (a, b, bData) { + var aClauseProps = this.getClauseProperties(a); + var bClauseProps = this.getClauseProperties(b); + var isSubset = this.subset(assign({}, aClauseProps.where, aClauseProps.paginate), assign({}, bClauseProps.where, bClauseProps.paginate)); + if (isSubset) { + return get.subsetData(a, b, bData, this); + } + }, + getUnion: function (a, b, aItems, bItems) { + var aClauseProps = this.getClauseProperties(a); + var bClauseProps = this.getClauseProperties(b); + var algebra = this; + var options; + if (this.subset(a, b)) { + return bItems; + } else if (this.subset(b, a)) { + return aItems; + } + var combined; + if (aClauseProps.enabled.paginate || bClauseProps.enabled.paginate) { + options = {}; + var isUnion = compare.union(aClauseProps.paginate, bClauseProps.paginate, undefined, undefined, undefined, this.clauses.paginate, options); + if (!isUnion) { + return; + } else { + each(options.getUnions, function (filter) { + var items = filter(a, b, aItems, bItems, algebra, options); + aItems = items[0]; + bItems = items[1]; + }); + combined = aItems.concat(bItems); + } + } else { + combined = aItems.concat(bItems); + } + if (combined.length && aClauseProps.enabled.order && compare.equal(aClauseProps.order, bClauseProps.order, undefined, undefined, undefined, {}, {})) { + options = {}; + var propName = h.firstProp(aClauseProps.order), compareOrder = algebra.clauses.order[propName]; + combined = combined.sort(function (aItem, bItem) { + return compareOrder(a[propName], aItem, bItem); + }); + } + return combined; + }, + id: function (props) { + var keys = Object.keys(this.clauses.id); + if (keys.length === 1) { + return props[keys[0]]; + } else { + var id = {}; + keys.forEach(function (key) { + id[key] = props[key]; + }); + return JSON.stringify(id); + } + } + }); + var callOnAlgebra = function (methodName, algebraArgNumber) { + return function () { + var args = makeArray(arguments).slice(0, algebraArgNumber); + var algebra = Algebra.make(arguments[algebraArgNumber]); + return algebra[methodName].apply(algebra, args); + }; + }; + module.exports = { + Algebra: Algebra, + Translate: Translate, + difference: callOnAlgebra('difference', 2), + equal: callOnAlgebra('equal', 2), + subset: callOnAlgebra('subset', 2), + properSubset: callOnAlgebra('properSubset', 2), + union: callOnAlgebra('union', 2), + intersection: callOnAlgebra('intersection', 2), + count: callOnAlgebra('count', 1), + has: callOnAlgebra('has', 2), + index: callOnAlgebra('index', 3), + getSubset: callOnAlgebra('getSubset', 3), + getUnion: callOnAlgebra('getUnion', 4) + }; +}); +/*can-set@1.3.0-pre.0#src/props*/ +define('can-set/src/props', function (require, exports, module) { + var h = require('can-set/src/helpers'); + var clause = require('can-set/src/clause'); + var each = require('set-can-util/js/each/each'); + var within = function (value, range) { + return value >= range[0] && value <= range[1]; + }; + var numericProperties = function (setA, setB, property1, property2) { + return { + sAv1: +setA[property1], + sAv2: +setA[property2], + sBv1: +setB[property1], + sBv2: +setB[property2] + }; + }; + var diff = function (setA, setB, property1, property2) { + var numProps = numericProperties(setA, setB, property1, property2); + var sAv1 = numProps.sAv1, sAv2 = numProps.sAv2, sBv1 = numProps.sBv1, sBv2 = numProps.sBv2, count = sAv2 - sAv1 + 1; + var after = { + difference: [ + sBv2 + 1, + sAv2 + ], + intersection: [ + sAv1, + sBv2 + ], + union: [ + sBv1, + sAv2 + ], + count: count, + meta: 'after' + }; + var before = { + difference: [ + sAv1, + sBv1 - 1 + ], + intersection: [ + sBv1, + sAv2 + ], + union: [ + sAv1, + sBv2 + ], + count: count, + meta: 'before' + }; + if (sAv1 === sBv1 && sAv2 === sBv2) { + return { + intersection: [ + sAv1, + sAv2 + ], + union: [ + sAv1, + sAv2 + ], + count: count, + meta: 'equal' + }; + } else if (sAv1 === sBv1 && sBv2 < sAv2) { + return after; + } else if (sAv2 === sBv2 && sBv1 > sAv1) { + return before; + } else if (within(sAv1, [ + sBv1, + sBv2 + ]) && within(sAv2, [ + sBv1, + sBv2 + ])) { + return { + intersection: [ + sAv1, + sAv2 + ], + union: [ + sBv1, + sBv2 + ], + count: count, + meta: 'subset' + }; + } else if (within(sBv1, [ + sAv1, + sAv2 + ]) && within(sBv2, [ + sAv1, + sAv2 + ])) { + return { + intersection: [ + sBv1, + sBv2 + ], + difference: [ + null, + null + ], + union: [ + sAv1, + sAv2 + ], + count: count, + meta: 'superset' + }; + } else if (sAv1 < sBv1 && within(sAv2, [ + sBv1, + sBv2 + ])) { + return before; + } else if (sBv1 < sAv1 && within(sBv2, [ + sAv1, + sAv2 + ])) { + return after; + } else if (sAv2 === sBv1 - 1) { + return { + difference: [ + sAv1, + sAv2 + ], + union: [ + sAv1, + sBv2 + ], + count: count, + meta: 'disjoint-before' + }; + } else if (sBv2 === sAv1 - 1) { + return { + difference: [ + sAv1, + sAv2 + ], + union: [ + sBv1, + sAv2 + ], + count: count, + meta: 'disjoint-after' + }; + } + if (!isNaN(count)) { + return { + count: count, + meta: 'disjoint' + }; + } + }; + var cleanUp = function (value, enumData) { + if (!value) { + return enumData; + } + if (!Array.isArray(value)) { + value = [value]; + } + if (!value.length) { + return enumData; + } + return value; + }; + var stringConvert = { + '0': false, + 'false': false, + 'null': undefined, + 'undefined': undefined + }; + var convertToBoolean = function (value) { + if (typeof value === 'string') { + return value.toLowerCase() in stringConvert ? stringConvert[value.toLowerCase()] : true; + } + return value; + }; + var props = { + 'enum': function (prop, enumData) { + var compares = new clause.Where({}); + compares[prop] = function (vA, vB, A, B) { + vA = cleanUp(vA, enumData); + vB = cleanUp(vB, enumData); + var data = h.arrayUnionIntersectionDifference(vA, vB); + if (!data.difference.length) { + delete data.difference; + } + each(data, function (value, prop) { + if (Array.isArray(value)) { + if (h.arraySame(enumData, value)) { + data[prop] = undefined; + } else if (value.length === 1) { + data[prop] = value[0]; + } + } + }); + return data; + }; + return compares; + }, + paginate: function (propStart, propEnd, translateToStartEnd, reverseTranslate) { + var compares = {}; + var makeResult = function (result, index) { + var res = {}; + each([ + 'intersection', + 'difference', + 'union' + ], function (prop) { + if (result[prop]) { + var set = { + start: result[prop][0], + end: result[prop][1] + }; + res[prop] = reverseTranslate(set)[index === 0 ? propStart : propEnd]; + } + }); + if (result.count) { + res.count = result.count; + } + return res; + }; + compares[propStart] = function (vA, vB, A, B) { + if (vA === undefined) { + return; + } + var res = diff(translateToStartEnd(A), translateToStartEnd(B), 'start', 'end'); + var result = makeResult(res, 0); + result.getSubset = function (a, b, bItems, algebra, options) { + return bItems; + }; + result.getUnion = function (a, b, aItems, bItems, algebra, options) { + return [ + aItems, + bItems + ]; + }; + return result; + }; + compares[propEnd] = function (vA, vB, A, B) { + if (vA === undefined) { + return; + } + var data = diff(translateToStartEnd(A), translateToStartEnd(B), 'start', 'end'); + var res = makeResult(data, 1); + res.getSubset = function (a, b, bItems, algebra, options) { + var tA = translateToStartEnd(a); + var tB = translateToStartEnd(b); + var numProps = numericProperties(tA, tB, 'start', 'end'); + var aStartValue = numProps.sAv1, aEndValue = numProps.sAv2; + var bStartValue = numProps.sBv1; + if (!('end' in tB) || !('end' in tA)) { + return bItems.slice(aStartValue, aEndValue + 1); + } + return bItems.slice(aStartValue - bStartValue, aEndValue - bStartValue + 1); + }; + res.getUnion = function (a, b, aItems, bItems, algebra, options) { + var tA = translateToStartEnd(a); + var tB = translateToStartEnd(b); + if (data.meta.indexOf('after') >= 0) { + if (data.intersection) { + bItems = bItems.slice(0, data.intersection[0] - +tB.start); + } + return [ + bItems, + aItems + ]; + } + if (data.intersection) { + aItems = aItems.slice(0, data.intersection[0] - +tA.start); + } + return [ + aItems, + bItems + ]; + }; + return res; + }; + return new clause.Paginate(compares); + }, + 'boolean': function (propertyName) { + var compares = new clause.Where({}); + compares[propertyName] = function (propA, propB) { + propA = convertToBoolean(propA); + propB = convertToBoolean(propB); + var notA = !propA, notB = !propB; + if (propA === notB && propB === notA) { + return { + difference: !propB, + union: undefined + }; + } else if (propA === undefined) { + return { + difference: !propB, + intersection: propB, + union: undefined + }; + } else if (propA === propB) { + return true; + } + }; + return compares; + }, + 'sort': function (prop, sortFunc) { + if (!sortFunc) { + sortFunc = h.defaultSort; + } + var compares = {}; + compares[prop] = sortFunc; + return new clause.Order(compares); + }, + 'id': function (prop) { + var compares = {}; + compares[prop] = prop; + return new clause.Id(compares); + } + }; + var assignExcept = function (d, s, props) { + for (var prop in s) { + if (!props[prop]) { + d[prop] = s[prop]; + } + } + return d; + }; + var translateToOffsetLimit = function (set, offsetProp, limitProp) { + var newSet = assignExcept({}, set, { + start: 1, + end: 1 + }); + if ('start' in set) { + newSet[offsetProp] = set.start; + } + if ('end' in set) { + newSet[limitProp] = set.end - set.start + 1; + } + return newSet; + }; + var translateToStartEnd = function (set, offsetProp, limitProp) { + var except = {}; + except[offsetProp] = except[limitProp] = 1; + var newSet = assignExcept({}, set, except); + if (offsetProp in set) { + newSet.start = parseInt(set[offsetProp], 10); + } + if (limitProp in set) { + newSet.end = newSet.start + parseInt(set[limitProp]) - 1; + } + return newSet; + }; + props.offsetLimit = function (offsetProp, limitProp) { + offsetProp = offsetProp || 'offset'; + limitProp = limitProp || 'limit'; + return props.paginate(offsetProp, limitProp, function (set) { + return translateToStartEnd(set, offsetProp, limitProp); + }, function (set) { + return translateToOffsetLimit(set, offsetProp, limitProp); + }); + }; + props.rangeInclusive = function (startIndexProperty, endIndexProperty) { + startIndexProperty = startIndexProperty || 'start'; + endIndexProperty = endIndexProperty || 'end'; + return props.paginate(startIndexProperty, endIndexProperty, function (set) { + var except = {}; + except[startIndexProperty] = except[endIndexProperty] = 1; + var newSet = assignExcept({}, set, except); + if (startIndexProperty in set) { + newSet.start = set[startIndexProperty]; + } + if (endIndexProperty in set) { + newSet.end = set[endIndexProperty]; + } + return newSet; + }, function (set) { + var except = { + start: 1, + end: 1 + }; + var newSet = assignExcept({}, set, except); + newSet[startIndexProperty] = set.start; + newSet[endIndexProperty] = set.end; + return newSet; + }); + }; + var nestedLookup = function (obj, propNameArray) { + if (obj === undefined) { + return undefined; + } + if (propNameArray.length === 1) { + return obj[propNameArray[0]]; + } else { + return nestedLookup(obj[propNameArray[0]], propNameArray.slice(1)); + } + }; + props.dotNotation = function (dotProperty) { + var compares = new clause.Where({}); + compares[dotProperty] = function (aVal, bVal, a, b, propertyName) { + if (aVal === undefined) { + aVal = nestedLookup(a, propertyName.split('.')); + } + if (bVal === undefined) { + bVal = nestedLookup(b, propertyName.split('.')); + } + return aVal === bVal; + }; + return compares; + }; + module.exports = props; +}); +/*can-set@1.3.0-pre.0#src/set*/ +define('can-set', function (require, exports, module) { + var set = require('can-set/src/set-core'); + var ns = require('can-namespace'); + var props = require('can-set/src/props'); + var clause = require('can-set/src/clause'); + set.comparators = props; + set.props = props; + set.helpers = require('can-set/src/helpers'); + set.clause = clause; + module.exports = ns.set = set; +}); +/*[global-shim-end]*/ +(function(){ // jshint ignore:line + window._define = window.define; + window.define = window.define.orig; +} +)(); \ No newline at end of file